diff options
author | Thomas Haller <thaller@redhat.com> | 2015-10-16 17:53:33 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-11-02 13:57:01 +0100 |
commit | 7cdbc393a078f53ae8d45d3b794fa1fb199f7dd5 (patch) | |
tree | 9735e50864d940d6d4ccef247f48ba66e5b48797 | |
parent | dd1f4d89470a16a92d6feb6c6a056f1f4089503e (diff) | |
download | NetworkManager-7cdbc393a078f53ae8d45d3b794fa1fb199f7dd5.tar.gz |
platform: refactor nm_platform_veth_get_properties()
For recent kernels, the peer-ifindex of veths is reported as
parent (IFA_LINK). Prefer that over the ethtool lookup.
For one, this avoids the extra ethtool call which has the
downside of sidestepping the platform cache. Also, looking
up the peer-ifindex in ethtool does not report whether the
peer lifes in another netns (NM_PLATFORM_LINK_OTHER_NETNS).
Only use ethtool as fallback for older kernels.
-rw-r--r-- | src/devices/nm-device-veth.c | 7 | ||||
-rw-r--r-- | src/platform/nm-fake-platform.c | 8 | ||||
-rw-r--r-- | src/platform/nm-linux-platform.c | 22 | ||||
-rw-r--r-- | src/platform/nm-platform.c | 27 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 8 | ||||
-rw-r--r-- | src/platform/tests/platform.c | 16 |
6 files changed, 28 insertions, 60 deletions
diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c index d80624857e..9c22ad1e5c 100644 --- a/src/devices/nm-device-veth.c +++ b/src/devices/nm-device-veth.c @@ -76,17 +76,18 @@ get_peer (NMDeviceVeth *self) { NMDeviceVethPrivate *priv = NM_DEVICE_VETH_GET_PRIVATE (self); NMDevice *device = NM_DEVICE (self), *peer = NULL; - NMPlatformVethProperties props; + int peer_ifindex; if (priv->ever_had_peer) return priv->peer; - if (!nm_platform_veth_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &props)) { + if (!nm_platform_veth_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &peer_ifindex)) { _LOGW (LOGD_HW, "could not read veth properties"); return NULL; } - peer = nm_manager_get_device_by_ifindex (nm_manager_get (), props.peer); + if (peer_ifindex > 0) + peer = nm_manager_get_device_by_ifindex (nm_manager_get (), peer_ifindex); if (peer && NM_IS_DEVICE_VETH (peer)) { set_peer (self, peer); set_peer (NM_DEVICE_VETH (peer), device); diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index d77c217756..d5dae69915 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -702,12 +702,6 @@ infiniband_partition_add (NMPlatform *platform, int parent, int p_key, NMPlatfor } static gboolean -veth_get_properties (NMPlatform *platform, int ifindex, NMPlatformVethProperties *props) -{ - return FALSE; -} - -static gboolean wifi_get_capabilities (NMPlatform *platform, int ifindex, NMDeviceWifiCapabilities *caps) { NMFakePlatformLink *device = link_get (platform, ifindex); @@ -1438,8 +1432,6 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass) platform_class->infiniband_partition_add = infiniband_partition_add; - platform_class->veth_get_properties = veth_get_properties; - platform_class->wifi_get_capabilities = wifi_get_capabilities; platform_class->wifi_get_bssid = wifi_get_bssid; platform_class->wifi_get_ssid = wifi_get_ssid; diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 13c31ee7e9..2e148abc9c 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -3976,26 +3976,6 @@ infiniband_partition_add (NMPlatform *platform, int parent, int p_key, NMPlatfor /******************************************************************/ -static gboolean -veth_get_properties (NMPlatform *platform, int ifindex, NMPlatformVethProperties *props) -{ - const char *ifname; - int peer_ifindex; - - ifname = nm_platform_link_get_name (platform, ifindex); - if (!ifname) - return FALSE; - - peer_ifindex = nmp_utils_ethtool_get_peer_ifindex (ifname); - if (peer_ifindex <= 0) - return FALSE; - - props->peer = peer_ifindex; - return TRUE; -} - -/******************************************************************/ - static WifiData * wifi_get_wifi_data (NMPlatform *platform, int ifindex) { @@ -5223,8 +5203,6 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass) platform_class->infiniband_partition_add = infiniband_partition_add; - platform_class->veth_get_properties = veth_get_properties; - platform_class->wifi_get_capabilities = wifi_get_capabilities; platform_class->wifi_get_bssid = wifi_get_bssid; platform_class->wifi_get_frequency = wifi_get_frequency; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index fae0e2e707..8576b2ddff 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1688,14 +1688,33 @@ nm_platform_infiniband_get_info (NMPlatform *self, } gboolean -nm_platform_veth_get_properties (NMPlatform *self, int ifindex, NMPlatformVethProperties *props) +nm_platform_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_ifindex) { + const NMPlatformLink *plink; + int peer_ifindex; _CHECK_SELF (self, klass, FALSE); - g_return_val_if_fail (ifindex > 0, FALSE); - g_return_val_if_fail (props != NULL, FALSE); + plink = nm_platform_link_get (self, ifindex); - return klass->veth_get_properties (self, ifindex, props); + if (!plink) + return FALSE; + if (plink->type != NM_LINK_TYPE_VETH) + return FALSE; + + if (plink->parent != 0) { + NM_SET_OUT (out_peer_ifindex, plink->parent); + return TRUE; + } + + /* Pre-4.1 kernel did not expose the peer_ifindex as IFA_LINK. Lookup via ethtool. */ + if (out_peer_ifindex) { + peer_ifindex = nmp_utils_ethtool_get_peer_ifindex (plink->name); + if (peer_ifindex <= 0) + return FALSE; + + *out_peer_ifindex = peer_ifindex; + } + return TRUE; } gboolean diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 64e7d2b593..21581d73e9 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -351,10 +351,6 @@ typedef struct { } NMPlatformLnkVlan; typedef struct { - int peer; -} NMPlatformVethProperties; - -typedef struct { gint64 owner; gint64 group; const char *mode; @@ -504,8 +500,6 @@ typedef struct { gboolean (*infiniband_partition_add) (NMPlatform *, int parent, int p_key, NMPlatformLink *out_link); - gboolean (*veth_get_properties) (NMPlatform *, int ifindex, NMPlatformVethProperties *properties); - gboolean (*wifi_get_capabilities) (NMPlatform *, int ifindex, NMDeviceWifiCapabilities *caps); gboolean (*wifi_get_bssid) (NMPlatform *, int ifindex, guint8 *bssid); GByteArray *(*wifi_get_ssid) (NMPlatform *, int ifindex); @@ -701,7 +695,7 @@ gboolean nm_platform_vlan_set_egress_map (NMPlatform *self, int ifindex, int fro NMPlatformError nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, NMPlatformLink *out_link); gboolean nm_platform_infiniband_get_info (NMPlatform *self, int ifindex, int *parent, int *p_key, const char **mode); -gboolean nm_platform_veth_get_properties (NMPlatform *self, int ifindex, NMPlatformVethProperties *properties); +gboolean nm_platform_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_ifindex); gboolean nm_platform_tun_get_properties (NMPlatform *self, int ifindex, NMPlatformTunProperties *properties); gboolean nm_platform_tun_get_properties_ifname (NMPlatform *platform, const char *ifname, NMPlatformTunProperties *props); diff --git a/src/platform/tests/platform.c b/src/platform/tests/platform.c index 860717baed..e2596786db 100644 --- a/src/platform/tests/platform.c +++ b/src/platform/tests/platform.c @@ -357,20 +357,6 @@ do_vlan_set_egress_map (char **argv) } static gboolean -do_veth_get_properties (char **argv) -{ - int ifindex = parse_ifindex (*argv++); - NMPlatformVethProperties props; - - if (!nm_platform_veth_get_properties (NM_PLATFORM_GET, ifindex, &props)) - return FALSE; - - printf ("peer: %d\n", props.peer); - - return TRUE; -} - -static gboolean do_tun_get_properties (char **argv) { int ifindex = parse_ifindex (*argv++); @@ -825,8 +811,6 @@ static const command_t commands[] = { "<ifname/ifindex> <from> <to>" }, { "vlan-set-egress-map", "set vlan egress map", do_vlan_set_egress_map, 3, "<ifname/ifindex> <from> <to>" }, - { "veth-get-properties", "get veth properties", do_veth_get_properties, 1, - "<ifname/ifindex>" }, { "tun-get-properties", "get tun/tap properties", do_tun_get_properties, 1, "<ifname/ifindex>" }, { "macvlan-get-properties", "get macvlan properties", do_macvlan_get_properties, 1, |