From: Yu Watanabe Date: Tue, 25 May 2021 08:32:28 +0000 (+0900) Subject: network: introduce link_request_to_set_bridge_vlan() X-Git-Tag: v249-rc1~76^2~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8252fb4439cb834b4cae3573821cc7d8a69530e0;p=thirdparty%2Fsystemd.git network: introduce link_request_to_set_bridge_vlan() This will be used in later commits. --- diff --git a/src/network/networkd-setlink.c b/src/network/networkd-setlink.c index 3a96fc9d7b2..65aed05d9d6 100644 --- a/src/network/networkd-setlink.c +++ b/src/network/networkd-setlink.c @@ -15,6 +15,7 @@ static const char *const set_link_operation_table[_SET_LINK_OPERATION_MAX] = { [SET_LINK_ADDRESS_GENERATION_MODE] = "IPv6LL address generation mode", [SET_LINK_BOND] = "bond configurations", [SET_LINK_BRIDGE] = "bridge configurations", + [SET_LINK_BRIDGE_VLAN] = "bridge VLAN configurations", [SET_LINK_FLAGS] = "link flags", [SET_LINK_GROUP] = "interface group", [SET_LINK_MAC] = "MAC address", @@ -77,6 +78,10 @@ static int link_set_bridge_handler(sd_netlink *rtnl, sd_netlink_message *m, Link return set_link_handler_internal(rtnl, m, link, SET_LINK_BRIDGE, true); } +static int link_set_bridge_vlan_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { + return set_link_handler_internal(rtnl, m, link, SET_LINK_BRIDGE_VLAN, true); +} + static int link_set_flags_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { return set_link_handler_internal(rtnl, m, link, SET_LINK_FLAGS, true); } @@ -296,6 +301,31 @@ static int link_configure( if (r < 0) return log_link_debug_errno(link, r, "Could not close IFLA_PROTINFO container: %m"); break; + case SET_LINK_BRIDGE_VLAN: + r = sd_rtnl_message_link_set_family(req, AF_BRIDGE); + if (r < 0) + return log_link_debug_errno(link, r, "Could not set message family: %m"); + + r = sd_netlink_message_open_container(req, IFLA_AF_SPEC); + if (r < 0) + return log_link_debug_errno(link, r, "Could not open IFLA_AF_SPEC container: %m"); + + if (!link->network->bridge) { + /* master needs BRIDGE_FLAGS_SELF flag*/ + r = sd_netlink_message_append_u16(req, IFLA_BRIDGE_FLAGS, BRIDGE_FLAGS_SELF); + if (r < 0) + return log_link_debug_errno(link, r, "Could not append IFLA_BRIDGE_FLAGS attribute: %m"); + } + + r = bridge_vlan_append_info(link, req, link->network->pvid, link->network->br_vid_bitmap, link->network->br_untagged_bitmap); + if (r < 0) + return log_link_debug_errno(link, r, "Could not append VLANs: %m"); + + r = sd_netlink_message_close_container(req); + if (r < 0) + return log_link_debug_errno(link, r, "Could not close IFLA_AF_SPEC container: %m"); + + break; case SET_LINK_FLAGS: { unsigned ifi_change = 0, ifi_flags = 0; @@ -527,6 +557,19 @@ int link_request_to_set_bridge(Link *link) { return link_request_set_link(link, SET_LINK_BRIDGE, link_set_bridge_handler, NULL); } +int link_request_to_set_bridge_vlan(Link *link) { + assert(link); + assert(link->network); + + if (!link->network->use_br_vlan) + return 0; + + if (!link->network->bridge && !streq_ptr(link->kind, "bridge")) + return 0; + + return link_request_set_link(link, SET_LINK_BRIDGE_VLAN, link_set_bridge_vlan_handler, NULL); +} + int link_request_to_set_flags(Link *link) { assert(link); assert(link->network); diff --git a/src/network/networkd-setlink.h b/src/network/networkd-setlink.h index 910fbb64fe2..7c28fff2591 100644 --- a/src/network/networkd-setlink.h +++ b/src/network/networkd-setlink.h @@ -10,6 +10,7 @@ typedef enum SetLinkOperation { SET_LINK_ADDRESS_GENERATION_MODE, /* Setting IPv6LL address generation mode. */ SET_LINK_BOND, /* Setting bond configs. */ SET_LINK_BRIDGE, /* Setting bridge configs. */ + SET_LINK_BRIDGE_VLAN, /* Setting bridge vlan configs. */ SET_LINK_FLAGS, /* Setting IFF_NOARP or friends. */ SET_LINK_GROUP, /* Setting interface group. */ SET_LINK_MAC, /* Setting MAC address. */ @@ -22,6 +23,7 @@ typedef enum SetLinkOperation { int link_request_to_set_addrgen_mode(Link *link); int link_request_to_set_bond(Link *link); int link_request_to_set_bridge(Link *link); +int link_request_to_set_bridge_vlan(Link *link); int link_request_to_set_flags(Link *link); int link_request_to_set_group(Link *link); int link_request_to_set_mac(Link *link);