Exemple #1
0
void genIpv6FromIntf(const std::string& iface, QueryData& results) {
  Row r;
  int ifaceHlim = 0;
  int ifaceRtadv = 0;

  int fd = socket(AF_INET6, SOCK_DGRAM, 0);
  if (fd >= 0) {
    struct in6_ndireq nd;
    memcpy(nd.ifname, iface.c_str(), sizeof(nd.ifname));
    if (ioctl(fd, SIOCGIFINFO_IN6, &nd) >= 0) {
      ifaceHlim = nd.ndi.chlim;
      ifaceRtadv = nd.ndi.flags & ND6_IFF_ACCEPT_RTADV;
    } else {
      VLOG(1) << "Error getting information from intf: " << iface;
    }
    close(fd);
  } else {
    VLOG(1) << "Cannot open inet6 socket";
  }

  r["interface"] = iface;
  r["hop_limit"] =
      INTEGER(ifaceHlim ? ifaceHlim : getSysIpv6Config("hop_limit"));
  r["rtadv_accept"] =
      INTEGER(getSysIpv6Config("rtadv_accept") > 0 && ifaceRtadv);
  // FreeBSD does not support some of the configurations at the interface level
  for (const auto& attr : {"forwarding_enabled", "redirect_accept"}) {
    r[attr] = INTEGER(getSysIpv6Config(attr));
  }
  results.emplace_back(std::move(r));
}
Exemple #2
0
void genInterfaceAddress(const std::string& name,
                         const IP_ADAPTER_UNICAST_ADDRESS* ipaddr,
                         QueryData& results) {
  Row r;
  r["interface"] = name;

  switch (ipaddr->SuffixOrigin) {
  case IpSuffixOriginManual:
    r["type"] = "manual";
    break;
  case IpSuffixOriginDhcp:
    r["type"] = "dhcp";
    break;
  case IpSuffixOriginLinkLayerAddress:
  case IpSuffixOriginRandom:
    r["type"] = "auto";
    break;
  default:
    r["type"] = "unknown";
  }

  if (ipaddr->Address.lpSockaddr->sa_family == AF_INET) {
    ULONG mask;
    ConvertLengthToIpv4Mask(ipaddr->OnLinkPrefixLength, &mask);
    in_addr maskAddr;
    maskAddr.s_addr = mask;

    char addrBuff[INET_ADDRSTRLEN] = {0};
    inet_ntop(AF_INET, &maskAddr, addrBuff, INET_ADDRSTRLEN);
    r["mask"] = addrBuff;

    inet_ntop(
        AF_INET,
        &reinterpret_cast<sockaddr_in*>(ipaddr->Address.lpSockaddr)->sin_addr,
        addrBuff,
        INET_ADDRSTRLEN);
    r["address"] = addrBuff;
  } else if (ipaddr->Address.lpSockaddr->sa_family == AF_INET6) {
    in6_addr netmask;
    memset(&netmask, 0x0, sizeof(netmask));
    for (long i = ipaddr->OnLinkPrefixLength, j = 0; i > 0; i -= 8, ++j) {
      netmask.s6_addr[j] = i >= 8 ? 0xff : (ULONG)((0xffU << (8 - i)));
    }

    char addrBuff[INET6_ADDRSTRLEN] = {0};
    inet_ntop(AF_INET6, &netmask, addrBuff, INET6_ADDRSTRLEN);
    r["mask"] = addrBuff;

    inet_ntop(
        AF_INET6,
        &reinterpret_cast<sockaddr_in6*>(ipaddr->Address.lpSockaddr)->sin6_addr,
        addrBuff,
        INET6_ADDRSTRLEN);
    r["address"] = addrBuff;
  }
  results.emplace_back(r);
}