From e4ad8f8a9b35e7e5946da0565845b81a02e3f356 Mon Sep 17 00:00:00 2001 From: Vojtech Bubela Date: Wed, 16 Mar 2022 11:30:44 +0100 Subject: [PATCH] platform: Add change link functions to nm-platform Since updating options of bridge is now done with netlink we need support function for that in nm-platform. --- src/libnm-platform/nm-linux-platform.c | 16 +++++++++++ src/libnm-platform/nm-platform.c | 39 ++++++++++++++++++++++++++ src/libnm-platform/nm-platform.h | 12 ++++++++ 3 files changed, 67 insertions(+) diff --git a/src/libnm-platform/nm-linux-platform.c b/src/libnm-platform/nm-linux-platform.c index 00fa167d05..76e99d8513 100644 --- a/src/libnm-platform/nm-linux-platform.c +++ b/src/libnm-platform/nm-linux-platform.c @@ -7538,6 +7538,21 @@ out: return result; } +static int +link_change(NMPlatform *platform, NMLinkType type, int ifindex, gconstpointer extra_data) +{ + nm_auto_nlmsg struct nl_msg *nlmsg = NULL; + + nlmsg = _nl_msg_new_link(RTM_NEWLINK, 0, ifindex, 0); + if (!nlmsg) + return -NME_UNSPEC; + + if (!_nl_msg_new_link_set_linkinfo(nlmsg, type, extra_data)) + return -NME_UNSPEC; + + return do_change_link(platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL); +} + static int link_add(NMPlatform *platform, NMLinkType type, @@ -9920,6 +9935,7 @@ nm_linux_platform_class_init(NMLinuxPlatformClass *klass) platform_class->sysctl_get = sysctl_get; platform_class->link_add = link_add; + platform_class->link_change = link_change; platform_class->link_delete = link_delete; platform_class->link_refresh = link_refresh; diff --git a/src/libnm-platform/nm-platform.c b/src/libnm-platform/nm-platform.c index f6baa6404f..a6c07c33ae 100644 --- a/src/libnm-platform/nm-platform.c +++ b/src/libnm-platform/nm-platform.c @@ -1304,6 +1304,45 @@ nm_platform_link_add(NMPlatform *self, ->link_add(self, type, name, parent, address, address_len, mtu, extra_data, out_link); } +int +nm_platform_link_change(NMPlatform *self, NMLinkType type, int ifindex, gconstpointer extra_data) +{ + char buf[512]; + const char *name = nm_platform_link_get_name(self, ifindex); + + _CHECK_SELF(self, klass, -NME_BUG); + + _LOG2D("link: changing link: " + "%s " /* type */ + "\"%s\"" /* name */ + "%s" /* extra_data */ + "", + nm_link_type_to_string(type), + name, + ({ + char *buf_p = buf; + gsize buf_len = sizeof(buf); + + buf[0] = '\0'; + + switch (type) { + case NM_LINK_TYPE_BRIDGE: + nm_strbuf_append_str(&buf_p, &buf_len, ", "); + nm_platform_lnk_bridge_to_string((const NMPlatformLnkBridge *) extra_data, + buf_p, + buf_len); + break; + default: + nm_assert(!extra_data); + break; + } + + buf; + })); + + return klass->link_change(self, type, ifindex, extra_data); +} + /** * nm_platform_link_delete: * @self: platform instance diff --git a/src/libnm-platform/nm-platform.h b/src/libnm-platform/nm-platform.h index e10384d27a..d20b9e5543 100644 --- a/src/libnm-platform/nm-platform.h +++ b/src/libnm-platform/nm-platform.h @@ -1113,6 +1113,9 @@ typedef struct { guint32 mtu, gconstpointer extra_data, const NMPlatformLink **out_link); + + int (*link_change)(NMPlatform *self, NMLinkType type, int ifindex, gconstpointer extra_data); + gboolean (*link_delete)(NMPlatform *self, int ifindex); gboolean (*link_refresh)(NMPlatform *self, int ifindex); gboolean (*link_set_netns)(NMPlatform *self, int ifindex, int netns_fd); @@ -1586,6 +1589,9 @@ int nm_platform_link_add(NMPlatform *self, gconstpointer extra_data, const NMPlatformLink **out_link); +int +nm_platform_link_change(NMPlatform *self, NMLinkType type, int ifindex, gconstpointer extra_data); + static inline int nm_platform_link_veth_add(NMPlatform *self, const char *name, @@ -1621,6 +1627,12 @@ nm_platform_link_bridge_add(NMPlatform *self, out_link); } +static inline int +nm_platform_link_bridge_change(NMPlatform *self, int ifindex, const NMPlatformLnkBridge *props) +{ + return nm_platform_link_change(self, NM_LINK_TYPE_BRIDGE, ifindex, props); +} + static inline int nm_platform_link_bond_add(NMPlatform *self, const char *name, const NMPlatformLink **out_link) {