]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: introduce link_request_to_set_bridge_vlan()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 25 May 2021 08:32:28 +0000 (17:32 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 7 Jun 2021 21:35:45 +0000 (06:35 +0900)
This will be used in later commits.

src/network/networkd-setlink.c
src/network/networkd-setlink.h

index 3a96fc9d7b24210721297e2c4343fc88f94d1ee7..65aed05d9d62788a89bd6e3ad37050d380066597 100644 (file)
@@ -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);
index 910fbb64fe27d3bb9e91a4f30a3bb0981adef1fd..7c28fff259103b34e42e10bdb8b2f610de886645 100644 (file)
@@ -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);