]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-netdev-vlan.c
sd-netlink: rename from sd-rtnl
[thirdparty/systemd.git] / src / network / networkd-netdev-vlan.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2013 Tom Gundersen <teg@jklm.no>
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <net/if.h>
23
24 #include "networkd-netdev-vlan.h"
25
26 static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
27 VLan *v = VLAN(netdev);
28 int r;
29
30 assert(netdev);
31 assert(v);
32 assert(link);
33 assert(req);
34
35 if (v->id <= VLANID_MAX) {
36 r = sd_netlink_message_append_u16(req, IFLA_VLAN_ID, v->id);
37 if (r < 0) {
38 log_netdev_error(netdev,
39 "Could not append IFLA_VLAN_ID attribute: %s",
40 strerror(-r));
41 return r;
42 }
43 }
44
45 return 0;
46 }
47
48 static int netdev_vlan_verify(NetDev *netdev, const char *filename) {
49 VLan *v = VLAN(netdev);
50
51 assert(netdev);
52 assert(v);
53 assert(filename);
54
55 if (v->id > VLANID_MAX) {
56 log_warning("VLAN without valid Id (%"PRIu64") configured in %s. Ignoring", v->id, filename);
57 return -EINVAL;
58 }
59
60 return 0;
61 }
62
63 static void vlan_init(NetDev *netdev) {
64 VLan *v = VLAN(netdev);
65
66 assert(netdev);
67 assert(v);
68
69 v->id = VLANID_MAX + 1;
70 }
71
72 const NetDevVTable vlan_vtable = {
73 .object_size = sizeof(VLan),
74 .init = vlan_init,
75 .sections = "Match\0NetDev\0VLAN\0",
76 .fill_message_create = netdev_vlan_fill_message_create,
77 .create_type = NETDEV_CREATE_STACKED,
78 .config_verify = netdev_vlan_verify,
79 };