From 0d6c68eba3188c3fea9731ba0828f04416ab7c04 Mon Sep 17 00:00:00 2001 From: Tobias Jungel Date: Mon, 29 May 2017 17:20:01 +0200 Subject: [PATCH] network: bridge vlan without PVID (#5899) this patch makes it possible to configure a vlan aware bridge without the PVID. To configure no PVID set DefaultPVID=none in the [BridgeVLAN] section. fixes #5716 --- man/systemd.netdev.xml | 3 ++- src/network/netdev/bridge.c | 4 +++- src/network/netdev/netdev-gperf.gperf | 2 +- src/shared/vlan-util.c | 31 +++++++++++++++++++++++++++++-- src/shared/vlan-util.h | 1 + 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/man/systemd.netdev.xml b/man/systemd.netdev.xml index 71cf2f2..e925b30 100644 --- a/man/systemd.netdev.xml +++ b/man/systemd.netdev.xml @@ -344,7 +344,8 @@ DefaultPVID= - This specifies the default port VLAN ID of a newly attached bridge port. + This specifies the default port VLAN ID of a newly attached bridge port. + Set this to an integer in the range 1–4094 or none to disable the PVID. diff --git a/src/network/netdev/bridge.c b/src/network/netdev/bridge.c index 9fdcb55..cf6c591 100644 --- a/src/network/netdev/bridge.c +++ b/src/network/netdev/bridge.c @@ -24,6 +24,7 @@ #include "netlink-util.h" #include "netdev/bridge.h" #include "networkd-manager.h" +#include "vlan-util.h" /* callback for brige netdev's parameter set */ static int netdev_bridge_set_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { @@ -102,7 +103,7 @@ static int netdev_bridge_post_create(NetDev *netdev, Link *link, sd_netlink_mess return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_PRIORITY attribute: %m"); } - if (b->default_pvid > 0) { + if (b->default_pvid != VLANID_INVALID) { r = sd_netlink_message_append_u16(req, IFLA_BR_VLAN_DEFAULT_PVID, b->default_pvid); if (r < 0) return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_VLAN_DEFAULT_PVID attribute: %m"); @@ -160,6 +161,7 @@ static void bridge_init(NetDev *n) { b->mcast_snooping = -1; b->vlan_filtering = -1; b->stp = -1; + b->default_pvid = VLANID_INVALID; b->forward_delay = USEC_INFINITY; } diff --git a/src/network/netdev/netdev-gperf.gperf b/src/network/netdev/netdev-gperf.gperf index 766e7cf..8b235a4 100644 --- a/src/network/netdev/netdev-gperf.gperf +++ b/src/network/netdev/netdev-gperf.gperf @@ -128,7 +128,7 @@ Bridge.MaxAgeSec, config_parse_sec, 0, Bridge.AgeingTimeSec, config_parse_sec, 0, offsetof(Bridge, ageing_time) Bridge.ForwardDelaySec, config_parse_sec, 0, offsetof(Bridge, forward_delay) Bridge.Priority, config_parse_uint16, 0, offsetof(Bridge, priority) -Bridge.DefaultPVID, config_parse_vlanid, 0, offsetof(Bridge, default_pvid) +Bridge.DefaultPVID, config_parse_default_port_vlanid, 0, offsetof(Bridge, default_pvid) Bridge.MulticastQuerier, config_parse_tristate, 0, offsetof(Bridge, mcast_querier) Bridge.MulticastSnooping, config_parse_tristate, 0, offsetof(Bridge, mcast_snooping) Bridge.VLANFiltering, config_parse_tristate, 0, offsetof(Bridge, vlan_filtering) diff --git a/src/shared/vlan-util.c b/src/shared/vlan-util.c index 78d66dd..1edd96f 100644 --- a/src/shared/vlan-util.c +++ b/src/shared/vlan-util.c @@ -17,9 +17,10 @@ along with systemd; If not, see . ***/ -#include "vlan-util.h" -#include "parse-util.h" #include "conf-parser.h" +#include "parse-util.h" +#include "string-util.h" +#include "vlan-util.h" int parse_vlanid(const char *p, uint16_t *ret) { uint16_t id; @@ -35,6 +36,32 @@ int parse_vlanid(const char *p, uint16_t *ret) { return 0; } +int config_parse_default_port_vlanid( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + uint16_t *id = data; + + assert(lvalue); + assert(rvalue); + assert(data); + + if (streq(rvalue, "none")) { + *id = 0; + return 0; + } + + return config_parse_vlanid(unit, filename, line, section, section_line, + lvalue, ltype, rvalue, data, userdata); +} + int config_parse_vlanid( const char *unit, const char *filename, diff --git a/src/shared/vlan-util.h b/src/shared/vlan-util.h index ce6763b..365ed14 100644 --- a/src/shared/vlan-util.h +++ b/src/shared/vlan-util.h @@ -32,4 +32,5 @@ static inline bool vlanid_is_valid(uint16_t id) { int parse_vlanid(const char *p, uint16_t *ret); +int config_parse_default_port_vlanid(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_vlanid(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -- 2.7.4