chiark / gitweb /
networkd: fix colud typo
[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         int r;
30
31         assert(netdev);
32         assert(netdev->ifname);
33         assert(netdev->kind == NETDEV_KIND_VLAN);
34         assert(link);
35         assert(req);
36
37         r = sd_rtnl_message_append_u32(req, IFLA_LINK, link->ifindex);
38         if (r < 0) {
39                 log_error_netdev(netdev,
40                                  "Could not append IFLA_LINK attribute: %s",
41                                  strerror(-r));
42                 return r;
43         }
44
45         r = sd_rtnl_message_append_string(req, IFLA_IFNAME, netdev->ifname);
46         if (r < 0) {
47                 log_error_netdev(netdev,
48                                  "Could not append IFLA_IFNAME attribute: %s",
49                                  strerror(-r));
50                 return r;
51         }
52
53         if (netdev->mtu) {
54                 r = sd_rtnl_message_append_u32(req, IFLA_MTU, netdev->mtu);
55                 if (r < 0) {
56                         log_error_netdev(netdev,
57                                          "Could not append IFLA_MTU attribute: %s",
58                                          strerror(-r));
59                         return r;
60                 }
61         }
62
63         if (netdev->mac) {
64                 r = sd_rtnl_message_append_ether_addr(req, IFLA_ADDRESS, netdev->mac);
65                 if (r < 0) {
66                         log_error_netdev(netdev,
67                                          "Could not append IFLA_ADDRESS attribute: %s",
68                                          strerror(-r));
69                     return r;
70                 }
71         }
72
73         r = sd_rtnl_message_open_container(req, IFLA_LINKINFO);
74         if (r < 0) {
75                 log_error_netdev(netdev,
76                                  "Could not open IFLA_LINKINFO container: %s",
77                                  strerror(-r));
78                 return r;
79         }
80
81         r = sd_rtnl_message_open_container_union(req, IFLA_INFO_DATA, "vlan");
82         if (r < 0) {
83                 log_error_netdev(netdev,
84                                  "Could not open IFLA_INFO_DATA container: %s",
85                                   strerror(-r));
86                 return r;
87         }
88
89         if (netdev->vlanid <= VLANID_MAX) {
90                 r = sd_rtnl_message_append_u16(req, IFLA_VLAN_ID, netdev->vlanid);
91                 if (r < 0) {
92                         log_error_netdev(netdev,
93                                          "Could not append IFLA_VLAN_ID attribute: %s",
94                                          strerror(-r));
95                         return r;
96                 }
97         }
98
99         r = sd_rtnl_message_close_container(req);
100         if (r < 0) {
101                 log_error_netdev(netdev,
102                                  "Could not close IFLA_INFO_DATA container %s",
103                                  strerror(-r));
104                 return r;
105         }
106
107         r = sd_rtnl_message_close_container(req);
108         if (r < 0) {
109                 log_error_netdev(netdev,
110                                  "Could not close IFLA_LINKINFO container %s",
111                                  strerror(-r));
112                 return r;
113         }
114
115         return 0;
116 }
117
118 static int netdev_vlan_verify(NetDev *netdev, const char *filename) {
119         assert(netdev);
120         assert(filename);
121
122         if (netdev->vlanid > VLANID_MAX) {
123                 log_warning("VLAN without valid Id configured in %s. Ignoring", filename);
124                 return -EINVAL;
125         }
126
127         return 0;
128 }
129
130 const NetDevVTable vlan_vtable = {
131         .fill_message_create_on_link = netdev_vlan_fill_message_create,
132         .config_verify = netdev_vlan_verify,
133 };