X Tutup
Skip to content

Commit 4df4df5

Browse files
rubensfigpoettering
authored andcommitted
network: allow setting VLAN protocol on bridges
Signed-off-by: Rubens Figueiredo <rubens.figueiredo@bisdn.de>
1 parent cf217a0 commit 4df4df5

File tree

7 files changed

+52
-0
lines changed

7 files changed

+52
-0
lines changed

man/systemd.netdev.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,15 @@
408408
</para>
409409
</listitem>
410410
</varlistentry>
411+
<varlistentry>
412+
<term><varname>VLANProtocol=</varname></term>
413+
<listitem>
414+
<para>Allows setting the protocol used for VLAN filtering. Takes
415+
<option>802.1q</option> or,
416+
<option>802.1ad</option>, and defaults to unset and kernel's default is used.
417+
</para>
418+
</listitem>
419+
</varlistentry>
411420
<varlistentry>
412421
<term><varname>STP=</varname></term>
413422
<listitem>

src/network/netdev/bridge.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ static int netdev_bridge_post_create(NetDev *netdev, Link *link, sd_netlink_mess
126126
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_VLAN_FILTERING attribute: %m");
127127
}
128128

129+
if (b->vlan_protocol >= 0) {
130+
r = sd_netlink_message_append_u16(req, IFLA_BR_VLAN_PROTOCOL, b->vlan_protocol);
131+
if (r < 0)
132+
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_VLAN_PROTOCOL attribute: %m");
133+
}
134+
129135
if (b->stp >= 0) {
130136
r = sd_netlink_message_append_u32(req, IFLA_BR_STP_STATE, b->stp);
131137
if (r < 0)
@@ -346,6 +352,7 @@ static void bridge_init(NetDev *n) {
346352
b->mcast_querier = -1;
347353
b->mcast_snooping = -1;
348354
b->vlan_filtering = -1;
355+
b->vlan_protocol = -1;
349356
b->stp = -1;
350357
b->default_pvid = VLANID_INVALID;
351358
b->forward_delay = USEC_INFINITY;

src/network/netdev/bridge.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ typedef struct Bridge {
1313
int mcast_querier;
1414
int mcast_snooping;
1515
int vlan_filtering;
16+
int vlan_protocol;
1617
int stp;
1718
uint16_t priority;
1819
uint16_t group_fwd_mask;

src/network/netdev/netdev-gperf.gperf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ Bridge.DefaultPVID, config_parse_default_port_vlanid,
206206
Bridge.MulticastQuerier, config_parse_tristate, 0, offsetof(Bridge, mcast_querier)
207207
Bridge.MulticastSnooping, config_parse_tristate, 0, offsetof(Bridge, mcast_snooping)
208208
Bridge.VLANFiltering, config_parse_tristate, 0, offsetof(Bridge, vlan_filtering)
209+
Bridge.VLANProtocol, config_parse_vlanprotocol, 0, offsetof(Bridge, vlan_protocol)
209210
Bridge.STP, config_parse_tristate, 0, offsetof(Bridge, stp)
210211
Bridge.MulticastIGMPVersion, config_parse_uint8, 0, offsetof(Bridge, igmp_version)
211212
VRF.TableId, config_parse_uint32, 0, offsetof(Vrf, table) /* deprecated */

src/shared/conf-parser.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,3 +1187,35 @@ int config_parse_permille(const char* unit,
11871187

11881188
return 0;
11891189
}
1190+
1191+
int config_parse_vlanprotocol(const char* unit,
1192+
const char *filename,
1193+
unsigned line,
1194+
const char *section,
1195+
unsigned section_line,
1196+
const char *lvalue,
1197+
int ltype,
1198+
const char *rvalue,
1199+
void *data,
1200+
void *userdata) {
1201+
int *vlan_protocol = data;
1202+
assert(filename);
1203+
assert(lvalue);
1204+
1205+
if (isempty(rvalue)) {
1206+
*vlan_protocol = -1;
1207+
return 0;
1208+
}
1209+
1210+
if (STR_IN_SET(rvalue, "802.1ad", "802.1AD"))
1211+
*vlan_protocol = ETH_P_8021AD;
1212+
else if (STR_IN_SET(rvalue, "802.1q", "802.1Q"))
1213+
*vlan_protocol = ETH_P_8021Q;
1214+
else {
1215+
log_syntax(unit, LOG_ERR, filename, line, 0,
1216+
"Failed to parse VLAN protocol value, ignoring: %s", rvalue);
1217+
return 0;
1218+
}
1219+
1220+
return 0;
1221+
}

src/shared/conf-parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_ifnames);
142142
CONFIG_PARSER_PROTOTYPE(config_parse_ip_port);
143143
CONFIG_PARSER_PROTOTYPE(config_parse_mtu);
144144
CONFIG_PARSER_PROTOTYPE(config_parse_rlimit);
145+
CONFIG_PARSER_PROTOTYPE(config_parse_vlanprotocol);
145146

146147
typedef enum Disabled {
147148
DISABLED_CONFIGURATION,

test/fuzz/fuzz-netdev-parser/directives.netdev

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ AgeingTimeSec=
4545
Priority=
4646
GroupForwardMask=
4747
VLANFiltering=
48+
VLANProtocol=
4849
MulticastIGMPVersion=
4950
[VRF]
5051
TableId=

0 commit comments

Comments
 (0)
X Tutup