diff options
author | Thomas Haller <thaller@redhat.com> | 2019-12-31 11:47:33 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-01-09 10:42:31 +0100 |
commit | 792118558c804009cc5f50079ccfaee7967004d3 (patch) | |
tree | e0301c2b5f2a5a7af641f6fcda0e2444cd779960 | |
parent | 9763d9f8a969cd4d4b210abf4028d6ee263e2287 (diff) | |
download | NetworkManager-792118558c804009cc5f50079ccfaee7967004d3.tar.gz |
platform: add parent argument to nm_platform_link_add()
This is to set the IFLA_LINK parameter.
-rw-r--r-- | src/platform/nm-fake-platform.c | 14 | ||||
-rw-r--r-- | src/platform/nm-linux-platform.c | 4 | ||||
-rw-r--r-- | src/platform/nm-platform.c | 9 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 14 |
4 files changed, 27 insertions, 14 deletions
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index 6271ee997c..5a18368e39 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -278,6 +278,7 @@ static int link_add (NMPlatform *platform, NMLinkType type, const char *name, + int parent, const void *address, size_t address_len, gconstpointer extra_data, @@ -295,6 +296,8 @@ link_add (NMPlatform *platform, device = link_add_pre (platform, name, type, address, address_len); + g_assert (parent == 0); + switch (type) { case NM_LINK_TYPE_VETH: veth_peer = extra_data; @@ -1360,13 +1363,10 @@ nm_fake_platform_setup (void) nm_platform_setup (platform); - /* add loopback interface */ - link_add (platform, NM_LINK_TYPE_LOOPBACK, "lo", NULL, 0, NULL, NULL); - - /* add some ethernets */ - link_add (platform, NM_LINK_TYPE_ETHERNET, "eth0", NULL, 0, NULL, NULL); - link_add (platform, NM_LINK_TYPE_ETHERNET, "eth1", NULL, 0, NULL, NULL); - link_add (platform, NM_LINK_TYPE_ETHERNET, "eth2", NULL, 0, NULL, NULL); + link_add (platform, NM_LINK_TYPE_LOOPBACK, "lo", 0, NULL, 0, NULL, NULL); + link_add (platform, NM_LINK_TYPE_ETHERNET, "eth0", 0, NULL, 0, NULL, NULL); + link_add (platform, NM_LINK_TYPE_ETHERNET, "eth1", 0, NULL, 0, NULL, NULL); + link_add (platform, NM_LINK_TYPE_ETHERNET, "eth2", 0, NULL, 0, NULL, NULL); } static void diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 586f1dc556..0d219adad8 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -6504,6 +6504,7 @@ static int link_add (NMPlatform *platform, NMLinkType type, const char *name, + int parent, const void *address, size_t address_len, gconstpointer extra_data, @@ -6530,6 +6531,9 @@ link_add (NMPlatform *platform, if (!nlmsg) return -NME_UNSPEC; + if (parent > 0) + NLA_PUT_U32 (nlmsg, IFLA_LINK, parent); + if (address && address_len) NLA_PUT (nlmsg, IFLA_ADDRESS, address_len, address); diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 1e8e5514f1..23df7dd561 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1152,6 +1152,7 @@ _link_add_check_existing (NMPlatform *self, const char *name, NMLinkType type, c * @self: platform instance * @type: Interface type * @name: Interface name + * @parent: the IFLA_LINK parameter or 0. * @address: (allow-none): set the mac address of the link * @address_len: the length of the @address * @extra_data: depending on @type, additional data. @@ -1171,6 +1172,7 @@ int nm_platform_link_add (NMPlatform *self, NMLinkType type, const char *name, + int parent, const void *address, size_t address_len, gconstpointer extra_data, @@ -1178,6 +1180,7 @@ nm_platform_link_add (NMPlatform *self, { int r; char addr_buf[NM_UTILS_HWADDR_LEN_MAX * 3]; + char parent_buf[64]; char buf[512]; _CHECK_SELF (self, klass, -NME_BUG); @@ -1185,6 +1188,7 @@ nm_platform_link_add (NMPlatform *self, g_return_val_if_fail (name, -NME_BUG); g_return_val_if_fail ((address != NULL) ^ (address_len == 0) , -NME_BUG); g_return_val_if_fail (address_len <= NM_UTILS_HWADDR_LEN_MAX, -NME_BUG); + g_return_val_if_fail (parent >= 0, -NME_BUG); r = _link_add_check_existing (self, name, type, out_link); if (r < 0) @@ -1193,11 +1197,14 @@ nm_platform_link_add (NMPlatform *self, _LOG2D ("link: adding link: " "%s " /* type */ "\"%s\"" /* name */ + "%s%s" /* parent */ "%s%s" /* address */ "%s" /* extra_data */ "", nm_link_type_to_string (type), name, + parent > 0 ? ", parent " : "", + parent > 0 ? nm_sprintf_buf (parent_buf, "%d", parent) : "", address ? ", address: " : "", address ? nm_utils_hwaddr_ntoa_buf (address, address_len, FALSE, addr_buf, sizeof (addr_buf)) : "", ({ @@ -1214,7 +1221,7 @@ nm_platform_link_add (NMPlatform *self, str; })); - return klass->link_add (self, type, name, address, address_len, extra_data, out_link); + return klass->link_add (self, type, name, parent, address, address_len, extra_data, out_link); } /** diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 05fd164fbe..9db6874adb 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -967,6 +967,7 @@ typedef struct { int (*link_add) (NMPlatform *self, NMLinkType type, const char *name, + int parent, const void *address, size_t address_len, gconstpointer extra_data, @@ -1367,6 +1368,7 @@ GPtrArray *nm_platform_link_get_all (NMPlatform *self, gboolean sort_by_name); int nm_platform_link_add (NMPlatform *self, NMLinkType type, const char *name, + int parent, const void *address, size_t address_len, gconstpointer extra_data, @@ -1378,7 +1380,7 @@ nm_platform_link_veth_add (NMPlatform *self, const char *peer, const NMPlatformLink **out_link) { - return nm_platform_link_add (self, NM_LINK_TYPE_VETH, name, NULL, 0, peer, out_link); + return nm_platform_link_add (self, NM_LINK_TYPE_VETH, name, 0, NULL, 0, peer, out_link); } static inline int @@ -1386,7 +1388,7 @@ nm_platform_link_dummy_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link) { - return nm_platform_link_add (self, NM_LINK_TYPE_DUMMY, name, NULL, 0, NULL, out_link); + return nm_platform_link_add (self, NM_LINK_TYPE_DUMMY, name, 0, NULL, 0, NULL, out_link); } static inline int @@ -1396,7 +1398,7 @@ nm_platform_link_bridge_add (NMPlatform *self, size_t address_len, const NMPlatformLink **out_link) { - return nm_platform_link_add (self, NM_LINK_TYPE_BRIDGE, name, address, address_len, NULL, out_link); + return nm_platform_link_add (self, NM_LINK_TYPE_BRIDGE, name, 0, address, address_len, NULL, out_link); } static inline int @@ -1404,7 +1406,7 @@ nm_platform_link_bond_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link) { - return nm_platform_link_add (self, NM_LINK_TYPE_BOND, name, NULL, 0, NULL, out_link); + return nm_platform_link_add (self, NM_LINK_TYPE_BOND, name, 0, NULL, 0, NULL, out_link); } static inline int @@ -1412,7 +1414,7 @@ nm_platform_link_team_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link) { - return nm_platform_link_add (self, NM_LINK_TYPE_TEAM, name, NULL, 0, NULL, out_link); + return nm_platform_link_add (self, NM_LINK_TYPE_TEAM, name, 0, NULL, 0, NULL, out_link); } static inline int @@ -1420,7 +1422,7 @@ nm_platform_link_wireguard_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link) { - return nm_platform_link_add (self, NM_LINK_TYPE_WIREGUARD, name, NULL, 0, NULL, out_link); + return nm_platform_link_add (self, NM_LINK_TYPE_WIREGUARD, name, 0, NULL, 0, NULL, out_link); } gboolean nm_platform_link_delete (NMPlatform *self, int ifindex); |