From 2d453f3597b009c52800bae3f801629c4d9a9b45 Mon Sep 17 00:00:00 2001
From: walbit-de <61383730+walbit-de@users.noreply.github.com>
Date: Wed, 2 Dec 2020 14:58:02 +0100
Subject: [PATCH] network: add Protocol= to vlan netdev (#17794)
---
man/systemd.netdev.xml | 7 +++++++
src/network/netdev/netdev-gperf.gperf | 1 +
src/network/netdev/vlan.c | 7 +++++++
src/network/netdev/vlan.h | 1 +
test/fuzz/fuzz-netdev-parser/directives.netdev | 1 +
5 files changed, 17 insertions(+)
diff --git a/man/systemd.netdev.xml b/man/systemd.netdev.xml
index f8a5c6dc863..fffef93aa23 100644
--- a/man/systemd.netdev.xml
+++ b/man/systemd.netdev.xml
@@ -450,6 +450,13 @@
This setting is compulsory.
+
+ Protocol=
+
+ Allows setting the protocol used for the VLAN interface. Takes 802.1q or,
+ 802.1ad, and defaults to unset and kernel's default is used.
+
+
GVRP=
diff --git a/src/network/netdev/netdev-gperf.gperf b/src/network/netdev/netdev-gperf.gperf
index 35cd01ef0d8..fc577f493c6 100644
--- a/src/network/netdev/netdev-gperf.gperf
+++ b/src/network/netdev/netdev-gperf.gperf
@@ -48,6 +48,7 @@ NetDev.Kind, config_parse_netdev_kind,
NetDev.MTUBytes, config_parse_mtu, AF_UNSPEC, offsetof(NetDev, mtu)
NetDev.MACAddress, config_parse_hwaddr, 0, offsetof(NetDev, mac)
VLAN.Id, config_parse_vlanid, 0, offsetof(VLan, id)
+VLAN.Protocol, config_parse_vlanprotocol, 0, offsetof(VLan, protocol)
VLAN.GVRP, config_parse_tristate, 0, offsetof(VLan, gvrp)
VLAN.MVRP, config_parse_tristate, 0, offsetof(VLan, mvrp)
VLAN.LooseBinding, config_parse_tristate, 0, offsetof(VLan, loose_binding)
diff --git a/src/network/netdev/vlan.c b/src/network/netdev/vlan.c
index e7f03f06f0f..751a037c91a 100644
--- a/src/network/netdev/vlan.c
+++ b/src/network/netdev/vlan.c
@@ -24,6 +24,12 @@ static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_netlin
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_ID attribute: %m");
+ if (v->protocol >= 0) {
+ r = sd_netlink_message_append_u16(req, IFLA_VLAN_PROTOCOL, htobe16(v->protocol));
+ if (r < 0)
+ return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_PROTOCOL attribute: %m");
+ }
+
if (v->gvrp != -1) {
flags.mask |= VLAN_FLAG_GVRP;
SET_FLAG(flags.flags, VLAN_FLAG_GVRP, v->gvrp);
@@ -76,6 +82,7 @@ static void vlan_init(NetDev *netdev) {
assert(v);
v->id = VLANID_INVALID;
+ v->protocol = -1;
v->gvrp = -1;
v->mvrp = -1;
v->loose_binding = -1;
diff --git a/src/network/netdev/vlan.h b/src/network/netdev/vlan.h
index 9dff924cd05..fbaad5a538c 100644
--- a/src/network/netdev/vlan.h
+++ b/src/network/netdev/vlan.h
@@ -9,6 +9,7 @@ struct VLan {
NetDev meta;
uint16_t id;
+ int protocol;
int gvrp;
int mvrp;
diff --git a/test/fuzz/fuzz-netdev-parser/directives.netdev b/test/fuzz/fuzz-netdev-parser/directives.netdev
index a7aa76f4985..f1813400738 100644
--- a/test/fuzz/fuzz-netdev-parser/directives.netdev
+++ b/test/fuzz/fuzz-netdev-parser/directives.netdev
@@ -4,6 +4,7 @@ LooseBinding=
ReorderHeader=
Id=
GVRP=
+Protocol=
[MACVLAN]
Mode=
SourceMACAddress=