chiark / gitweb /
networkd: allow specification of DHCP route metric
[elogind.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 #include "network-internal.h"
26 #include "list.h"
27
28 static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_message *req) {
29         VLan *v = VLAN(netdev);
30         int r;
31
32         assert(netdev);
33         assert(v);
34         assert(link);
35         assert(req);
36
37         if (v->id <= VLANID_MAX) {
38                 r = sd_rtnl_message_append_u16(req, IFLA_VLAN_ID, v->id);
39                 if (r < 0) {
40                         log_error_netdev(netdev,
41                                          "Could not append IFLA_VLAN_ID attribute: %s",
42                                          strerror(-r));
43                         return r;
44                 }
45         }
46
47         return 0;
48 }
49
50 static int netdev_vlan_verify(NetDev *netdev, const char *filename) {
51         VLan *v = VLAN(netdev);
52
53         assert(netdev);
54         assert(v);
55         assert(filename);
56
57         if (v->id > VLANID_MAX) {
58                 log_warning("VLAN without valid Id (%"PRIu64") configured in %s. Ignoring", v->id, filename);
59                 return -EINVAL;
60         }
61
62         return 0;
63 }
64
65 static void vlan_init(NetDev *netdev) {
66         VLan *v = VLAN(netdev);
67
68         assert(netdev);
69         assert(v);
70
71         v->id = VLANID_MAX + 1;
72 }
73
74 const NetDevVTable vlan_vtable = {
75         .object_size = sizeof(VLan),
76         .init = vlan_init,
77         .sections = "Match\0NetDev\0VLAN\0",
78         .fill_message_create = netdev_vlan_fill_message_create,
79         .create_type = NETDEV_CREATE_STACKED,
80         .config_verify = netdev_vlan_verify,
81 };