summaryrefslogtreecommitdiffstats
path: root/src/network/networkd-link.c
diff options
context:
space:
mode:
authorSusant Sahani <ssahani@vmware.com>2020-04-07 14:36:55 +0200
committerLennart Poettering <lennart@poettering.net>2020-05-15 15:27:07 +0200
commit89fe653544a310a9bbc2689c464a1cdd92bb71a2 (patch)
treead8402b8400b9b7d1d5708e26824fc13e3b229db /src/network/networkd-link.c
parentMerge pull request #15792 from poettering/repart-allocate (diff)
downloadsystemd-89fe653544a310a9bbc2689c464a1cdd92bb71a2.tar.xz
systemd-89fe653544a310a9bbc2689c464a1cdd92bb71a2.zip
network: Add support to group links.
Link groups are similar to port ranges found in managed switches. You can add network interfaces to a numbered group and perform operations on all the interfaces from that group at once.
Diffstat (limited to 'src/network/networkd-link.c')
-rw-r--r--src/network/networkd-link.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index e261473f6f..32fe86045d 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1825,6 +1825,53 @@ int link_down(Link *link, link_netlink_message_handler_t callback) {
return 0;
}
+static int link_group_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
+ int r;
+
+ assert(link);
+
+ if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
+ return 1;
+
+ r = sd_netlink_message_get_errno(m);
+ if (r < 0)
+ log_link_message_warning_errno(link, m, r, "Could not set group for the interface");
+
+ return 1;
+}
+
+static int link_set_group(Link *link) {
+ _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
+ int r;
+
+ assert(link);
+ assert(link->network);
+ assert(link->manager);
+ assert(link->manager->rtnl);
+
+ if (link->network->group <= 0)
+ return 0;
+
+ log_link_debug(link, "Setting group");
+
+ r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_SETLINK, link->ifindex);
+ if (r < 0)
+ return log_link_error_errno(link, r, "Could not allocate RTM_SETLINK message: %m");
+
+ r = sd_netlink_message_append_u32(req, IFLA_GROUP, link->network->group);
+ if (r < 0)
+ return log_link_error_errno(link, r, "Could not set link group: %m");
+
+ r = netlink_call_async(link->manager->rtnl, NULL, req, link_group_handler,
+ link_netlink_destroy_callback, link);
+ if (r < 0)
+ return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
+
+ link_ref(link);
+
+ return 0;
+}
+
static int link_handle_bound_to_list(Link *link) {
Link *l;
Iterator i;
@@ -2819,6 +2866,10 @@ static int link_configure(Link *link) {
if (r < 0)
return r;
+ r = link_set_group(link);
+ if (r < 0)
+ return r;
+
if (link_ipv4ll_enabled(link, ADDRESS_FAMILY_IPV4 | ADDRESS_FAMILY_FALLBACK_IPV4)) {
r = ipv4ll_configure(link);
if (r < 0)