]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/netdev/vlan.c
cf32710e398e6b617570a95910e4afaf865dc36b
[thirdparty/systemd.git] / src / network / netdev / vlan.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 This file is part of systemd.
4
5 Copyright 2013 Tom Gundersen <teg@jklm.no>
6 ***/
7
8 #include <errno.h>
9 #include <linux/if_vlan.h>
10 #include <net/if.h>
11
12 #include "netdev/vlan.h"
13 #include "vlan-util.h"
14
15 static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
16 struct ifla_vlan_flags flags = {};
17 VLan *v;
18 int r;
19
20 assert(netdev);
21 assert(link);
22 assert(req);
23
24 v = VLAN(netdev);
25
26 assert(v);
27
28 r = sd_netlink_message_append_u16(req, IFLA_VLAN_ID, v->id);
29 if (r < 0)
30 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_ID attribute: %m");
31
32 if (v->gvrp != -1) {
33 flags.mask |= VLAN_FLAG_GVRP;
34 SET_FLAG(flags.flags, VLAN_FLAG_GVRP, v->gvrp);
35 }
36
37 if (v->mvrp != -1) {
38 flags.mask |= VLAN_FLAG_MVRP;
39 SET_FLAG(flags.flags, VLAN_FLAG_MVRP, v->mvrp);
40 }
41
42 if (v->reorder_hdr != -1) {
43 flags.mask |= VLAN_FLAG_REORDER_HDR;
44 SET_FLAG(flags.flags, VLAN_FLAG_REORDER_HDR, v->reorder_hdr);
45 }
46
47 if (v->loose_binding != -1) {
48 flags.mask |= VLAN_FLAG_LOOSE_BINDING;
49 SET_FLAG(flags.flags, VLAN_FLAG_LOOSE_BINDING, v->loose_binding);
50 }
51
52 r = sd_netlink_message_append_data(req, IFLA_VLAN_FLAGS, &flags, sizeof(struct ifla_vlan_flags));
53 if (r < 0)
54 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_FLAGS attribute: %m");
55
56 return 0;
57 }
58
59 static int netdev_vlan_verify(NetDev *netdev, const char *filename) {
60 VLan *v;
61
62 assert(netdev);
63 assert(filename);
64
65 v = VLAN(netdev);
66
67 assert(v);
68
69 if (v->id == VLANID_INVALID) {
70 log_warning("VLAN without valid Id (%"PRIu16") configured in %s.", v->id, filename);
71 return -EINVAL;
72 }
73
74 return 0;
75 }
76
77 static void vlan_init(NetDev *netdev) {
78 VLan *v = VLAN(netdev);
79
80 assert(netdev);
81 assert(v);
82
83 v->id = VLANID_INVALID;
84 v->gvrp = -1;
85 v->mvrp = -1;
86 v->loose_binding = -1;
87 v->reorder_hdr = -1;
88 }
89
90 const NetDevVTable vlan_vtable = {
91 .object_size = sizeof(VLan),
92 .init = vlan_init,
93 .sections = "Match\0NetDev\0VLAN\0",
94 .fill_message_create = netdev_vlan_fill_message_create,
95 .create_type = NETDEV_CREATE_STACKED,
96 .config_verify = netdev_vlan_verify,
97 };