]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/netdev/vlan.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / network / netdev / vlan.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
0372cb2b
TG
2/***
3 This file is part of systemd.
4
5 Copyright 2013 Tom Gundersen <teg@jklm.no>
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19***/
20
c8b21184 21#include <linux/if_vlan.h>
0372cb2b
TG
22#include <net/if.h>
23
441e9ae4 24#include "netdev/vlan.h"
267fabd2 25#include "vlan-util.h"
0372cb2b 26
1c4baffc 27static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
c8b21184 28 struct ifla_vlan_flags flags = {};
2645f07d 29 VLan *v;
0372cb2b
TG
30 int r;
31
32 assert(netdev);
0372cb2b 33 assert(link);
3be1d7e0 34 assert(req);
0372cb2b 35
2645f07d
SS
36 v = VLAN(netdev);
37
38 assert(v);
39
267fabd2
LP
40 r = sd_netlink_message_append_u16(req, IFLA_VLAN_ID, v->id);
41 if (r < 0)
42 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_ID attribute: %m");
0372cb2b 43
c8b21184
SS
44 if (v->gvrp != -1) {
45 flags.mask |= VLAN_FLAG_GVRP;
ab8ee0f2 46 SET_FLAG(flags.flags, VLAN_FLAG_GVRP, v->gvrp);
c8b21184
SS
47 }
48
6c1ff21b
SS
49 if (v->mvrp != -1) {
50 flags.mask |= VLAN_FLAG_MVRP;
51 SET_FLAG(flags.flags, VLAN_FLAG_MVRP, v->mvrp);
52 }
53
54 if (v->reorder_hdr != -1) {
55 flags.mask |= VLAN_FLAG_REORDER_HDR;
56 SET_FLAG(flags.flags, VLAN_FLAG_REORDER_HDR, v->reorder_hdr);
57 }
58
59 if (v->loose_binding != -1) {
60 flags.mask |= VLAN_FLAG_LOOSE_BINDING;
61 SET_FLAG(flags.flags, VLAN_FLAG_LOOSE_BINDING, v->loose_binding);
62 }
63
c8b21184
SS
64 r = sd_netlink_message_append_data(req, IFLA_VLAN_FLAGS, &flags, sizeof(struct ifla_vlan_flags));
65 if (r < 0)
66 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_FLAGS attribute: %m");
67
3be1d7e0
TG
68 return 0;
69}
e04468de 70
3be1d7e0 71static int netdev_vlan_verify(NetDev *netdev, const char *filename) {
2645f07d 72 VLan *v;
aa9f1140 73
3be1d7e0
TG
74 assert(netdev);
75 assert(filename);
0372cb2b 76
2645f07d
SS
77 v = VLAN(netdev);
78
79 assert(v);
80
267fabd2
LP
81 if (v->id == VLANID_INVALID) {
82 log_warning("VLAN without valid Id (%"PRIu16") configured in %s.", v->id, filename);
3be1d7e0
TG
83 return -EINVAL;
84 }
0372cb2b
TG
85
86 return 0;
87}
3be1d7e0 88
aa9f1140
TG
89static void vlan_init(NetDev *netdev) {
90 VLan *v = VLAN(netdev);
91
92 assert(netdev);
93 assert(v);
94
267fabd2 95 v->id = VLANID_INVALID;
c8b21184 96 v->gvrp = -1;
6c1ff21b
SS
97 v->mvrp = -1;
98 v->loose_binding = -1;
99 v->reorder_hdr = -1;
aa9f1140
TG
100}
101
3be1d7e0 102const NetDevVTable vlan_vtable = {
aa9f1140
TG
103 .object_size = sizeof(VLan),
104 .init = vlan_init,
105 .sections = "Match\0NetDev\0VLAN\0",
106 .fill_message_create = netdev_vlan_fill_message_create,
107 .create_type = NETDEV_CREATE_STACKED,
3be1d7e0
TG
108 .config_verify = netdev_vlan_verify,
109};