chiark / gitweb /
networkd: log when finished enumerating links and addresses
[elogind.git] / src / network / networkd-netdev-vxlan.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4     This file is part of systemd.
5
6     Copyright 2014 Susant Sahani <susant@redhat.com>
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 <netinet/ether.h>
23 #include <arpa/inet.h>
24 #include <net/if.h>
25
26 #include "sd-rtnl.h"
27 #include "networkd-netdev-vxlan.h"
28 #include "networkd-link.h"
29 #include "conf-parser.h"
30 #include "missing.h"
31
32 static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_message *m) {
33         VxLan *v = VXLAN(netdev);
34         int r;
35
36         assert(netdev);
37         assert(v);
38         assert(link);
39         assert(m);
40
41
42         if (v->id <= VXLAN_VID_MAX) {
43                 r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_ID, v->id);
44                 if (r < 0) {
45                         log_netdev_error(netdev,
46                                          "Could not append IFLA_VXLAN_ID attribute: %s",
47                                          strerror(-r));
48                         return r;
49                 }
50         }
51
52         r = sd_rtnl_message_append_in_addr(m, IFLA_VXLAN_GROUP, &v->group.in);
53         if (r < 0) {
54                 log_netdev_error(netdev,
55                                  "Could not append IFLA_VXLAN_GROUP attribute: %s",
56                                  strerror(-r));
57                 return r;
58         }
59
60         r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_LINK, link->ifindex);
61         if (r < 0) {
62                 log_netdev_error(netdev,
63                                  "Could not append IFLA_VXLAN_LINK attribute: %s",
64                                  strerror(-r));
65                 return r;
66         }
67
68         if(v->ttl) {
69                 r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_TTL, v->ttl);
70                 if (r < 0) {
71                         log_netdev_error(netdev,
72                                          "Could not append IFLA_VXLAN_TTL attribute: %s",
73                                          strerror(-r));
74                         return r;
75                 }
76         }
77
78         if(v->tos) {
79                 r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_TOS, v->tos);
80                 if (r < 0) {
81                         log_netdev_error(netdev,
82                                          "Could not append IFLA_VXLAN_TOS attribute: %s",
83                                          strerror(-r));
84                         return r;
85                 }
86         }
87
88         r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_LEARNING, v->learning);
89         if (r < 0) {
90                 log_netdev_error(netdev,
91                                  "Could not append IFLA_VXLAN_LEARNING attribute: %s",
92                                  strerror(-r));
93                 return r;
94         }
95
96         r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_RSC, v->route_short_circuit);
97         if (r < 0) {
98                 log_netdev_error(netdev,
99                                  "Could not append IFLA_VXLAN_RSC attribute: %s",
100                                  strerror(-r));
101                 return r;
102         }
103
104         r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_PROXY, v->arp_proxy);
105         if (r < 0) {
106                 log_netdev_error(netdev,
107                                  "Could not append IFLA_VXLAN_PROXY attribute: %s",
108                                  strerror(-r));
109                 return r;
110         }
111
112         r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_L2MISS, v->l2miss);
113         if (r < 0) {
114                 log_netdev_error(netdev,
115                                  "Could not append IFLA_VXLAN_L2MISS attribute: %s",
116                                  strerror(-r));
117                 return r;
118         }
119
120         r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_L3MISS, v->l3miss);
121         if (r < 0) {
122                 log_netdev_error(netdev,
123                                  "Could not append IFLA_VXLAN_L3MISS attribute: %s",
124                                  strerror(-r));
125                 return r;
126         }
127
128         if(v->fdb_ageing) {
129                 r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_AGEING, v->fdb_ageing / USEC_PER_SEC);
130                 if (r < 0) {
131                         log_netdev_error(netdev,
132                                          "Could not append IFLA_VXLAN_AGEING attribute: %s",
133                                          strerror(-r));
134                         return r;
135                 }
136         }
137
138         return r;
139 }
140
141 int config_parse_vxlan_group_address(const char *unit,
142                                      const char *filename,
143                                      unsigned line,
144                                      const char *section,
145                                      unsigned section_line,
146                                      const char *lvalue,
147                                      int ltype,
148                                      const char *rvalue,
149                                      void *data,
150                                      void *userdata) {
151         VxLan *v = userdata;
152         union in_addr_union *addr = data, buffer;
153         int r, f;
154
155         assert(filename);
156         assert(lvalue);
157         assert(rvalue);
158         assert(data);
159
160         r = in_addr_from_string_auto(rvalue, &f, &buffer);
161         if (r < 0) {
162                 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
163                            "vxlan multicast group address is invalid, ignoring assignment: %s", rvalue);
164                 return 0;
165         }
166
167         if(v->family != AF_UNSPEC && v->family != f) {
168                 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
169                            "vxlan multicast group incompatible, ignoring assignment: %s", rvalue);
170                 return 0;
171         }
172
173         v->family = f;
174         *addr = buffer;
175
176         return 0;
177 }
178
179 static int netdev_vxlan_verify(NetDev *netdev, const char *filename) {
180         VxLan *v = VXLAN(netdev);
181
182         assert(netdev);
183         assert(v);
184         assert(filename);
185
186         if (v->id > VXLAN_VID_MAX) {
187                 log_warning("VXLAN without valid Id configured in %s. Ignoring", filename);
188                 return -EINVAL;
189         }
190
191         return 0;
192 }
193
194 static void vxlan_init(NetDev *netdev) {
195         VxLan *v = VXLAN(netdev);
196
197         assert(netdev);
198         assert(v);
199
200         v->id = VXLAN_VID_MAX + 1;
201         v->learning = true;
202 }
203
204 const NetDevVTable vxlan_vtable = {
205         .object_size = sizeof(VxLan),
206         .init = vxlan_init,
207         .sections = "Match\0NetDev\0VXLAN\0",
208         .fill_message_create = netdev_vxlan_fill_message_create,
209         .create_type = NETDEV_CREATE_STACKED,
210         .config_verify = netdev_vxlan_verify,
211 };