]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/network/netdev/bridge.c
tree-wide: make sure net/if.h is included before any linux/ header
[thirdparty/systemd.git] / src / network / netdev / bridge.c
index 7c38708121b6c6cbaa5cdadbb973cd41ab3550f2..d426c0c5019f03e4118cadc05feb8e1bc4e2b518 100644 (file)
@@ -1,9 +1,10 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
-#include <netinet/in.h>
 #include <linux/if_arp.h>
 #include <linux/if_bridge.h>
+#include <netinet/in.h>
 
 #include "bridge.h"
 #include "netlink-util.h"
@@ -46,11 +47,9 @@ static int netdev_bridge_set_handler(sd_netlink *rtnl, sd_netlink_message *m, Ne
 }
 
 static int netdev_bridge_post_create_message(NetDev *netdev, sd_netlink_message *req) {
-        Bridge *b;
+        Bridge *b = BRIDGE(netdev);
         int r;
 
-        assert_se(b = BRIDGE(netdev));
-
         r = sd_netlink_message_open_container(req, IFLA_LINKINFO);
         if (r < 0)
                 return r;
@@ -121,7 +120,7 @@ static int netdev_bridge_post_create_message(NetDev *netdev, sd_netlink_message
         }
 
         if (b->vlan_protocol >= 0) {
-                r = sd_netlink_message_append_u16(req, IFLA_BR_VLAN_PROTOCOL, b->vlan_protocol);
+                r = sd_netlink_message_append_u16(req, IFLA_BR_VLAN_PROTOCOL, htobe16(b->vlan_protocol));
                 if (r < 0)
                         return r;
         }
@@ -149,7 +148,7 @@ static int netdev_bridge_post_create_message(NetDev *netdev, sd_netlink_message
         return 0;
 }
 
-static int netdev_bridge_post_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
+static int netdev_bridge_post_create(NetDev *netdev, Link *link) {
         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
         int r;
 
@@ -189,36 +188,22 @@ int config_parse_bridge_igmp_version(
                 void *data,
                 void *userdata) {
 
-        Bridge *b = userdata;
-        uint8_t u;
-        int r;
-
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
+        Bridge *b = ASSERT_PTR(userdata);
+
         if (isempty(rvalue)) {
                 b->igmp_version = 0; /* 0 means unset. */
                 return 0;
         }
 
-        r = safe_atou8(rvalue, &u);
-        if (r < 0) {
-                log_syntax(unit, LOG_WARNING, filename, line, r,
-                           "Failed to parse bridge's multicast IGMP version number '%s', ignoring assignment: %m",
-                           rvalue);
-                return 0;
-        }
-        if (!IN_SET(u, 2, 3)) {
-                log_syntax(unit, LOG_WARNING, filename, line, 0,
-                           "Invalid bridge's multicast IGMP version number '%s', ignoring assignment.", rvalue);
-                return 0;
-        }
-
-        b->igmp_version = u;
-
-        return 0;
+        return config_parse_uint8_bounded(
+                        unit, filename, line, section, section_line, lvalue, rvalue,
+                        2, 3, true,
+                        &b->igmp_version);
 }
 
 int config_parse_bridge_port_priority(
@@ -233,41 +218,20 @@ int config_parse_bridge_port_priority(
                 void *data,
                 void *userdata) {
 
-        uint16_t i;
-        int r;
-
         assert(filename);
         assert(lvalue);
         assert(rvalue);
-        assert(data);
-
-        /* This is used in networkd-network-gperf.gperf. */
-
-        r = safe_atou16(rvalue, &i);
-        if (r < 0) {
-                log_syntax(unit, LOG_WARNING, filename, line, r,
-                           "Failed to parse bridge port priority, ignoring: %s", rvalue);
-                return 0;
-        }
-
-        if (i > LINK_BRIDGE_PORT_PRIORITY_MAX) {
-                log_syntax(unit, LOG_WARNING, filename, line, 0,
-                           "Bridge port priority is larger than maximum %u, ignoring: %s",
-                           LINK_BRIDGE_PORT_PRIORITY_MAX, rvalue);
-                return 0;
-        }
 
-        *((uint16_t *)data) = i;
+        uint16_t *prio = ASSERT_PTR(data);
 
-        return 0;
+        return config_parse_uint16_bounded(
+                        unit, filename, line, section, section_line, lvalue, rvalue,
+                        0, LINK_BRIDGE_PORT_PRIORITY_MAX, true,
+                        prio);
 }
 
-static void bridge_init(NetDev *n) {
-        Bridge *b;
-
-        b = BRIDGE(n);
-
-        assert(b);
+static void bridge_init(NetDev *netdev) {
+        Bridge *b = BRIDGE(netdev);
 
         b->mcast_querier = -1;
         b->mcast_snooping = -1;
@@ -284,7 +248,7 @@ const NetDevVTable bridge_vtable = {
         .init = bridge_init,
         .sections = NETDEV_COMMON_SECTIONS "Bridge\0",
         .post_create = netdev_bridge_post_create,
-        .create_type = NETDEV_CREATE_MASTER,
+        .create_type = NETDEV_CREATE_INDEPENDENT,
         .iftype = ARPHRD_ETHER,
         .generate_mac = true,
 };