Line data Source code
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 0 : static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
27 0 : VLan *v = VLAN(netdev);
28 : int r;
29 :
30 0 : assert(netdev);
31 0 : assert(v);
32 0 : assert(link);
33 0 : assert(req);
34 :
35 0 : if (v->id <= VLANID_MAX) {
36 0 : r = sd_netlink_message_append_u16(req, IFLA_VLAN_ID, v->id);
37 0 : if (r < 0)
38 0 : return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_ID attribute: %m");
39 : }
40 :
41 0 : return 0;
42 : }
43 :
44 0 : static int netdev_vlan_verify(NetDev *netdev, const char *filename) {
45 0 : VLan *v = VLAN(netdev);
46 :
47 0 : assert(netdev);
48 0 : assert(v);
49 0 : assert(filename);
50 :
51 0 : if (v->id > VLANID_MAX) {
52 0 : log_warning("VLAN without valid Id (%"PRIu64") configured in %s. Ignoring", v->id, filename);
53 0 : return -EINVAL;
54 : }
55 :
56 0 : return 0;
57 : }
58 :
59 0 : static void vlan_init(NetDev *netdev) {
60 0 : VLan *v = VLAN(netdev);
61 :
62 0 : assert(netdev);
63 0 : assert(v);
64 :
65 0 : v->id = VLANID_MAX + 1;
66 0 : }
67 :
68 : const NetDevVTable vlan_vtable = {
69 : .object_size = sizeof(VLan),
70 : .init = vlan_init,
71 : .sections = "Match\0NetDev\0VLAN\0",
72 : .fill_message_create = netdev_vlan_fill_message_create,
73 : .create_type = NETDEV_CREATE_STACKED,
74 : .config_verify = netdev_vlan_verify,
75 : };
|