2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-01 06:25:34 +00:00

[master] Fixing use of IfacePtr in iface_mgr_linux.cc and iface_mgr_sun.cc.

This is a fix after merge of #3715.
This commit is contained in:
Marcin Siodelski
2015-03-13 19:12:39 +01:00
parent 3b23408618
commit 5796c0f0e6
2 changed files with 28 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2011-2014 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
// //
// Permission to use, copy, modify, and/or distribute this software for any // Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above // purpose with or without fee is hereby granted, provided that the above
@@ -474,14 +474,14 @@ void IfaceMgr::detectIfaces() {
// into three separate steps for easier debugging. // into three separate steps for easier debugging.
const char* tmp = static_cast<const char*>(RTA_DATA(attribs_table[IFLA_IFNAME])); const char* tmp = static_cast<const char*>(RTA_DATA(attribs_table[IFLA_IFNAME]));
string iface_name(tmp); // <--- bogus valgrind warning here string iface_name(tmp); // <--- bogus valgrind warning here
Iface iface = Iface(iface_name, interface_info->ifi_index); IfacePtr iface(new Iface(iface_name, interface_info->ifi_index));
iface.setHWType(interface_info->ifi_type); iface->setHWType(interface_info->ifi_type);
iface.setFlags(interface_info->ifi_flags); iface->setFlags(interface_info->ifi_flags);
// Does interface have LL_ADDR? // Does interface have LL_ADDR?
if (attribs_table[IFLA_ADDRESS]) { if (attribs_table[IFLA_ADDRESS]) {
iface.setMac(static_cast<const uint8_t*>(RTA_DATA(attribs_table[IFLA_ADDRESS])), iface->setMac(static_cast<const uint8_t*>(RTA_DATA(attribs_table[IFLA_ADDRESS])),
RTA_PAYLOAD(attribs_table[IFLA_ADDRESS])); RTA_PAYLOAD(attribs_table[IFLA_ADDRESS]));
} }
else { else {
@@ -489,7 +489,7 @@ void IfaceMgr::detectIfaces() {
// try to dereference it in this manner // try to dereference it in this manner
} }
nl.ipaddrs_get(iface, addr_info); nl.ipaddrs_get(*iface, addr_info);
ifaces_.push_back(iface); ifaces_.push_back(iface);
} }

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2011, 2013-2014 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2011, 2013-2015 Internet Systems Consortium, Inc. ("ISC")
// //
// Permission to use, copy, modify, and/or distribute this software for any // Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above // purpose with or without fee is hereby granted, provided that the above
@@ -39,16 +39,17 @@ namespace dhcp {
/// only, as earlier versions did not support getifaddrs() API. /// only, as earlier versions did not support getifaddrs() API.
void void
IfaceMgr::detectIfaces() { IfaceMgr::detectIfaces() {
struct ifaddrs * iflist = 0, * ifptr = 0; struct ifaddrs* iflist = 0;// The whole interface list
struct ifaddrs* ifptr = 0; // The interface we're processing now
// Gets list of ifaddrs struct // Gets list of ifaddrs struct
if(getifaddrs(&iflist) != 0) { if(getifaddrs(&iflist) != 0) {
isc_throw(Unexpected, "Network interfaces detection failed."); isc_throw(Unexpected, "Network interfaces detection failed.");
} }
typedef std::map<string, Iface> ifaceLst; typedef map<string, IfacePtr> IfaceLst;
ifaceLst::iterator iface_iter; IfaceLst::iterator iface_iter;
ifaceLst ifaces; IfaceLst ifaces;
// First lookup for getting interfaces ... // First lookup for getting interfaces ...
for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) { for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) {
@@ -66,14 +67,13 @@ IfaceMgr::detectIfaces() {
continue; continue;
} }
Iface iface(ifname, ifindex); IfacePtr iface(new Iface(ifname, ifindex));
iface.setFlags(ifptr->ifa_flags); iface->setFlags(ifptr->ifa_flags);
ifaces.insert(pair<string, Iface>(ifname, iface)); ifaces.insert(pair<string, IfacePtr>(ifname, iface));
} }
// Second lookup to get MAC and IP addresses // Second lookup to get MAC and IP addresses
for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) { for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) {
iface_iter = ifaces.find(ifptr->ifa_name); iface_iter = ifaces.find(ifptr->ifa_name);
if (iface_iter == ifaces.end()) { if (iface_iter == ifaces.end()) {
continue; continue;
@@ -86,8 +86,8 @@ IfaceMgr::detectIfaces() {
reinterpret_cast<struct sockaddr_dl *>(ifptr->ifa_addr); reinterpret_cast<struct sockaddr_dl *>(ifptr->ifa_addr);
ptr = reinterpret_cast<uint8_t *>(LLADDR(ldata)); ptr = reinterpret_cast<uint8_t *>(LLADDR(ldata));
iface_iter->second.setHWType(ldata->sdl_type); iface_iter->second->setHWType(ldata->sdl_type);
iface_iter->second.setMac(ptr, ldata->sdl_alen); iface_iter->second->setMac(ptr, ldata->sdl_alen);
} else if(ifptr->ifa_addr->sa_family == AF_INET6) { } else if(ifptr->ifa_addr->sa_family == AF_INET6) {
// IPv6 Addr // IPv6 Addr
struct sockaddr_in6 * adata = struct sockaddr_in6 * adata =
@@ -95,7 +95,7 @@ IfaceMgr::detectIfaces() {
ptr = reinterpret_cast<uint8_t *>(&adata->sin6_addr); ptr = reinterpret_cast<uint8_t *>(&adata->sin6_addr);
IOAddress a = IOAddress::fromBytes(AF_INET6, ptr); IOAddress a = IOAddress::fromBytes(AF_INET6, ptr);
iface_iter->second.addAddress(a); iface_iter->second->addAddress(a);
} else { } else {
// IPv4 Addr // IPv4 Addr
struct sockaddr_in * adata = struct sockaddr_in * adata =
@@ -103,16 +103,16 @@ IfaceMgr::detectIfaces() {
ptr = reinterpret_cast<uint8_t *>(&adata->sin_addr); ptr = reinterpret_cast<uint8_t *>(&adata->sin_addr);
IOAddress a = IOAddress::fromBytes(AF_INET, ptr); IOAddress a = IOAddress::fromBytes(AF_INET, ptr);
iface_iter->second.addAddress(a); iface_iter->second->addAddress(a);
} }
} }
freeifaddrs(iflist); freeifaddrs(iflist);
// Interfaces registering // Interfaces registering
for (ifaceLst::const_iterator iface_iter = ifaces.begin(); for(IfaceLst::const_iterator iface_iter = ifaces.begin();
iface_iter != ifaces.end(); ++iface_iter) { iface_iter != ifaces.end(); ++iface_iter) {
ifaces_.push_back(iface_iter->second); addInterface(iface_iter->second);
} }
} }