diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c index d80624857..9c22ad1e5 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 d77c21775..d5dae6991 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -701,12 +701,6 @@ infiniband_partition_add (NMPlatform *platform, int parent, int p_key, NMPlatfor return TRUE; } -static gboolean -veth_get_properties (NMPlatform *platform, int ifindex, NMPlatformVethProperties *props) -{ - return FALSE; -} - static gboolean wifi_get_capabilities (NMPlatform *platform, int ifindex, NMDeviceWifiCapabilities *caps) { @@ -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 13c31ee7e..2e148abc9 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 fae0e2e70..8576b2ddf 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 64e7d2b59..21581d73e 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -350,10 +350,6 @@ typedef struct { guint16 id; } NMPlatformLnkVlan; -typedef struct { - int peer; -} NMPlatformVethProperties; - typedef struct { gint64 owner; gint64 group; @@ -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 860717bae..e2596786d 100644 --- a/src/platform/tests/platform.c +++ b/src/platform/tests/platform.c @@ -356,20 +356,6 @@ do_vlan_set_egress_map (char **argv) return nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, ifindex, from, to); } -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) { @@ -825,8 +811,6 @@ static const command_t commands[] = { " " }, { "vlan-set-egress-map", "set vlan egress map", do_vlan_set_egress_map, 3, " " }, - { "veth-get-properties", "get veth properties", do_veth_get_properties, 1, - "" }, { "tun-get-properties", "get tun/tap properties", do_tun_get_properties, 1, "" }, { "macvlan-get-properties", "get macvlan properties", do_macvlan_get_properties, 1,