/* 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"
}
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;
}
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;
}
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;
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(
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;
.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,
};