core: pass ifindex and address family when flushing routes

Use the interfaces kernel index when we can to avoid unecessary
iface->index lookups; and let callers figure out which address
family they really want to flush.
This commit is contained in:
Dan Williams
2010-05-04 20:23:09 -07:00
parent ad1017974b
commit 1c5236029c
5 changed files with 28 additions and 20 deletions

View File

@@ -661,7 +661,8 @@ real_deactivate_quickly (NMModem *self, NMDevice *device)
case MM_MODEM_IP_METHOD_STATIC: case MM_MODEM_IP_METHOD_STATIC:
case MM_MODEM_IP_METHOD_DHCP: case MM_MODEM_IP_METHOD_DHCP:
iface = nm_device_get_ip_iface (device); iface = nm_device_get_ip_iface (device);
nm_system_device_flush_routes_with_iface (iface); /* FIXME: use AF_UNSPEC here when we have IPv6 support */
nm_system_device_flush_routes_with_iface (iface, AF_INET);
nm_system_device_flush_addresses_with_iface (iface); nm_system_device_flush_addresses_with_iface (iface);
nm_system_device_set_up_down_with_iface (iface, FALSE, NULL); nm_system_device_set_up_down_with_iface (iface, FALSE, NULL);
break; break;

View File

@@ -2767,7 +2767,7 @@ nm_device_deactivate (NMDeviceInterface *device, NMDeviceStateReason reason)
nm_device_deactivate_quickly (self); nm_device_deactivate_quickly (self);
/* Take out any entries in the routing table and any IP address the device had. */ /* Take out any entries in the routing table and any IP address the device had. */
nm_system_device_flush_routes (self); nm_system_device_flush_routes (self, nm_device_get_ip6_config (self) ? AF_UNSPEC : AF_INET);
nm_system_device_flush_addresses (self); nm_system_device_flush_addresses (self);
nm_device_update_ip4_address (self); nm_device_update_ip4_address (self);

View File

@@ -1211,21 +1211,25 @@ check_one_route (struct nl_object *object, void *user_data)
} }
} }
static void flush_routes (const char *iface, gboolean ipv4_only) static void flush_routes (int ifindex, const char *iface, int family)
{ {
int iface_idx;
RouteCheckData check_data; RouteCheckData check_data;
g_return_if_fail (iface != NULL); g_return_if_fail (iface != NULL);
iface_idx = nm_netlink_iface_to_index (iface);
if (iface_idx >= 0) { if (ifindex < 0) {
ifindex = nm_netlink_iface_to_index (iface);
if (ifindex < 0) {
nm_log_dbg (LOGD_DEVICE, "(%s) failed to lookup interface index", iface);
return;
}
}
memset (&check_data, 0, sizeof (check_data)); memset (&check_data, 0, sizeof (check_data));
check_data.iface = iface; check_data.iface = iface;
check_data.iface_idx = iface_idx; check_data.iface_idx = ifindex;
check_data.family = ipv4_only ? AF_INET : 0; check_data.family = family;
foreach_route (check_one_route, &check_data); foreach_route (check_one_route, &check_data);
}
} }
/* /*
@@ -1234,23 +1238,25 @@ static void flush_routes (const char *iface, gboolean ipv4_only)
* Flush all network addresses associated with a network device * Flush all network addresses associated with a network device
* *
*/ */
void nm_system_device_flush_routes (NMDevice *dev) void nm_system_device_flush_routes (NMDevice *dev, int family)
{ {
g_return_if_fail (dev != NULL); g_return_if_fail (dev != NULL);
flush_routes (nm_device_get_ip_iface (dev), flush_routes (nm_device_get_ip_ifindex (dev),
nm_device_get_ip6_config (dev) == NULL); nm_device_get_ip_iface (dev),
family);
} }
/* /*
* nm_system_device_flush_routes_with_iface * nm_system_device_flush_routes_with_iface
* *
* Flush all routes associated with a network device * Flush all routes associated with a network device. 'family' is an
* address family, either AF_INET, AF_INET6, or AF_UNSPEC.
* *
*/ */
void nm_system_device_flush_routes_with_iface (const char *iface) void nm_system_device_flush_routes_with_iface (const char *iface, int family)
{ {
flush_routes (iface, FALSE); flush_routes (-1, iface, family);
} }
typedef struct { typedef struct {

View File

@@ -33,8 +33,8 @@
* implemented in the backend files in backends/ directory * implemented in the backend files in backends/ directory
*/ */
void nm_system_device_flush_routes (NMDevice *dev); void nm_system_device_flush_routes (NMDevice *dev, int family);
void nm_system_device_flush_routes_with_iface (const char *iface); void nm_system_device_flush_routes_with_iface (const char *iface, int family);
gboolean nm_system_replace_default_ip4_route (const char *iface, gboolean nm_system_replace_default_ip4_route (const char *iface,
guint32 gw, guint32 gw,

View File

@@ -878,7 +878,8 @@ vpn_cleanup (NMVPNConnection *connection)
if (priv->tundev) { if (priv->tundev) {
nm_system_device_set_up_down_with_iface (priv->tundev, FALSE, NULL); nm_system_device_set_up_down_with_iface (priv->tundev, FALSE, NULL);
nm_system_device_flush_routes_with_iface (priv->tundev); /* FIXME: use AF_UNSPEC here when we have IPv6 support */
nm_system_device_flush_routes_with_iface (priv->tundev, AF_INET);
nm_system_device_flush_addresses_with_iface (priv->tundev); nm_system_device_flush_addresses_with_iface (priv->tundev);
} }