chiark / gitweb /
networkctl: properly format MAC 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 "missing.h"
29
30 static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_message *m) {
31         VxLan *v = VXLAN(netdev);
32         int r;
33
34         assert(netdev);
35         assert(v);
36         assert(link);
37         assert(m);
38
39
40         if (v->id <= VXLAN_VID_MAX) {
41                 r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_ID, v->id);
42                 if (r < 0) {
43                         log_error_netdev(netdev,
44                                          "Could not append IFLA_VXLAN_ID attribute: %s",
45                                          strerror(-r));
46                         return r;
47                 }
48         }
49
50         r = sd_rtnl_message_append_in_addr(m, IFLA_VXLAN_GROUP, &v->group.in);
51         if (r < 0) {
52                 log_error_netdev(netdev,
53                                  "Could not append IFLA_VXLAN_GROUP attribute: %s",
54                                  strerror(-r));
55                 return r;
56         }
57
58         r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_LINK, link->ifindex);
59         if (r < 0) {
60                 log_error_netdev(netdev,
61                                  "Could not append IFLA_VXLAN_LINK attribute: %s",
62                                  strerror(-r));
63                 return r;
64         }
65
66         if(v->ttl) {
67                 r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_TTL, v->ttl);
68                 if (r < 0) {
69                         log_error_netdev(netdev,
70                                          "Could not append IFLA_VXLAN_TTL attribute: %s",
71                                          strerror(-r));
72                         return r;
73                 }
74         }
75
76         if(v->tos) {
77                 r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_TOS, v->tos);
78                 if (r < 0) {
79                         log_error_netdev(netdev,
80                                          "Could not append IFLA_VXLAN_TOS attribute: %s",
81                                          strerror(-r));
82                         return r;
83                 }
84         }
85
86         r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_LEARNING, v->learning);
87         if (r < 0) {
88                 log_error_netdev(netdev,
89                                  "Could not append IFLA_VXLAN_LEARNING attribute: %s",
90                                  strerror(-r));
91                 return r;
92         }
93
94         return r;
95 }
96
97 static int netdev_vxlan_verify(NetDev *netdev, const char *filename) {
98         VxLan *v = VXLAN(netdev);
99
100         assert(netdev);
101         assert(v);
102         assert(filename);
103
104         if (v->id > VXLAN_VID_MAX) {
105                 log_warning("VXLAN without valid Id configured in %s. Ignoring", filename);
106                 return -EINVAL;
107         }
108
109         return 0;
110 }
111
112 static void vxlan_init(NetDev *netdev) {
113         VxLan *v = VXLAN(netdev);
114
115         assert(netdev);
116         assert(v);
117
118         v->id = VXLAN_VID_MAX + 1;
119         v->learning = true;
120 }
121
122 const NetDevVTable vxlan_vtable = {
123         .object_size = sizeof(VxLan),
124         .init = vxlan_init,
125         .sections = "Match\0NetDev\0VXLAN\0",
126         .fill_message_create = netdev_vxlan_fill_message_create,
127         .create_type = NETDEV_CREATE_STACKED,
128         .config_verify = netdev_vxlan_verify,
129 };