]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-netdev-vxlan.c
networkd: vxlan add option to set FDB entries
[thirdparty/systemd.git] / src / network / networkd-netdev-vxlan.c
CommitLineData
326cb406
SS
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
ea84fd5c 6 Copyright 2014 Susant Sahani
326cb406
SS
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
326cb406
SS
22#include <net/if.h>
23
1c4baffc 24#include "sd-netlink.h"
3be1d7e0 25#include "networkd-netdev-vxlan.h"
0b1831c2 26#include "networkd-link.h"
85a8eeee 27#include "conf-parser.h"
81577dc2 28#include "missing.h"
326cb406 29
1c4baffc 30static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
c2353b2f 31 VxLan *v;
326cb406
SS
32 int r;
33
3be1d7e0 34 assert(netdev);
326cb406 35 assert(link);
326cb406
SS
36 assert(m);
37
c2353b2f
SS
38 v = VXLAN(netdev);
39
40 assert(v);
326cb406 41
aa9f1140 42 if (v->id <= VXLAN_VID_MAX) {
1c4baffc 43 r = sd_netlink_message_append_u32(m, IFLA_VXLAN_ID, v->id);
f545680e
SS
44 if (r < 0)
45 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_ID attribute: %m");
326cb406
SS
46 }
47
1c4baffc 48 r = sd_netlink_message_append_in_addr(m, IFLA_VXLAN_GROUP, &v->group.in);
f545680e
SS
49 if (r < 0)
50 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_GROUP attribute: %m");
326cb406 51
1c4baffc 52 r = sd_netlink_message_append_u32(m, IFLA_VXLAN_LINK, link->ifindex);
f545680e
SS
53 if (r < 0)
54 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_LINK attribute: %m");
326cb406 55
aa9f1140 56 if(v->ttl) {
1c4baffc 57 r = sd_netlink_message_append_u8(m, IFLA_VXLAN_TTL, v->ttl);
f545680e
SS
58 if (r < 0)
59 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_TTL attribute: %m");
326cb406
SS
60 }
61
aa9f1140 62 if(v->tos) {
1c4baffc 63 r = sd_netlink_message_append_u8(m, IFLA_VXLAN_TOS, v->tos);
f545680e
SS
64 if (r < 0)
65 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_TOS attribute: %m");
326cb406
SS
66 }
67
1c4baffc 68 r = sd_netlink_message_append_u8(m, IFLA_VXLAN_LEARNING, v->learning);
f545680e
SS
69 if (r < 0)
70 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_LEARNING attribute: %m");
326cb406 71
1c4baffc 72 r = sd_netlink_message_append_u8(m, IFLA_VXLAN_RSC, v->route_short_circuit);
f545680e
SS
73 if (r < 0)
74 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_RSC attribute: %m");
85a8eeee 75
1c4baffc 76 r = sd_netlink_message_append_u8(m, IFLA_VXLAN_PROXY, v->arp_proxy);
f545680e
SS
77 if (r < 0)
78 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_PROXY attribute: %m");
85a8eeee 79
1c4baffc 80 r = sd_netlink_message_append_u8(m, IFLA_VXLAN_L2MISS, v->l2miss);
f545680e
SS
81 if (r < 0)
82 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_L2MISS attribute: %m");
85a8eeee 83
1c4baffc 84 r = sd_netlink_message_append_u8(m, IFLA_VXLAN_L3MISS, v->l3miss);
f545680e
SS
85 if (r < 0)
86 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_L3MISS attribute: %m");
85a8eeee
SS
87
88 if(v->fdb_ageing) {
1c4baffc 89 r = sd_netlink_message_append_u32(m, IFLA_VXLAN_AGEING, v->fdb_ageing / USEC_PER_SEC);
f545680e
SS
90 if (r < 0)
91 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_AGEING attribute: %m");
85a8eeee
SS
92 }
93
3dbcf579
SS
94 if (v->max_fdb) {
95 r = sd_netlink_message_append_u32(m, IFLA_VXLAN_LIMIT, v->max_fdb);
96 if (r < 0)
97 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_LIMIT attribute: %m");
98 }
99
1c4baffc 100 r = sd_netlink_message_append_u8(m, IFLA_VXLAN_UDP_CSUM, v->udpcsum);
f545680e
SS
101 if (r < 0)
102 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_UDP_CSUM attribute: %m");
cffacc74 103
1c4baffc 104 r = sd_netlink_message_append_u8(m, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, v->udp6zerocsumtx);
f545680e
SS
105 if (r < 0)
106 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_TX attribute: %m");
cffacc74 107
1c4baffc 108 r = sd_netlink_message_append_u8(m, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, v->udp6zerocsumrx);
f545680e
SS
109 if (r < 0)
110 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_RX attribute: %m");
cffacc74 111
ea84fd5c
SS
112 if (v->group_policy) {
113 r = sd_netlink_message_append_flag(m, IFLA_VXLAN_GBP);
114 if (r < 0)
115 return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_GBP attribute: %m");
116 }
117
326cb406
SS
118 return r;
119}
120
85a8eeee
SS
121int config_parse_vxlan_group_address(const char *unit,
122 const char *filename,
123 unsigned line,
124 const char *section,
125 unsigned section_line,
126 const char *lvalue,
127 int ltype,
128 const char *rvalue,
129 void *data,
130 void *userdata) {
131 VxLan *v = userdata;
132 union in_addr_union *addr = data, buffer;
133 int r, f;
134
135 assert(filename);
136 assert(lvalue);
137 assert(rvalue);
138 assert(data);
139
140 r = in_addr_from_string_auto(rvalue, &f, &buffer);
141 if (r < 0) {
12ca818f 142 log_syntax(unit, LOG_ERR, filename, line, r, "vxlan multicast group address is invalid, ignoring assignment: %s", rvalue);
85a8eeee
SS
143 return 0;
144 }
145
12ca818f
LP
146 if (v->family != AF_UNSPEC && v->family != f) {
147 log_syntax(unit, LOG_ERR, filename, line, 0, "vxlan multicast group incompatible, ignoring assignment: %s", rvalue);
85a8eeee
SS
148 return 0;
149 }
150
151 v->family = f;
152 *addr = buffer;
153
154 return 0;
155}
156
3be1d7e0 157static int netdev_vxlan_verify(NetDev *netdev, const char *filename) {
aa9f1140
TG
158 VxLan *v = VXLAN(netdev);
159
326cb406 160 assert(netdev);
aa9f1140 161 assert(v);
3be1d7e0 162 assert(filename);
326cb406 163
aa9f1140 164 if (v->id > VXLAN_VID_MAX) {
3be1d7e0
TG
165 log_warning("VXLAN without valid Id configured in %s. Ignoring", filename);
166 return -EINVAL;
326cb406
SS
167 }
168
326cb406
SS
169 return 0;
170}
3be1d7e0 171
aa9f1140 172static void vxlan_init(NetDev *netdev) {
c2353b2f 173 VxLan *v;
aa9f1140
TG
174
175 assert(netdev);
c2353b2f
SS
176
177 v = VXLAN(netdev);
178
aa9f1140
TG
179 assert(v);
180
181 v->id = VXLAN_VID_MAX + 1;
182 v->learning = true;
cffacc74
SS
183 v->udpcsum = false;
184 v->udp6zerocsumtx = false;
185 v->udp6zerocsumrx = false;
aa9f1140
TG
186}
187
3be1d7e0 188const NetDevVTable vxlan_vtable = {
aa9f1140
TG
189 .object_size = sizeof(VxLan),
190 .init = vxlan_init,
191 .sections = "Match\0NetDev\0VXLAN\0",
192 .fill_message_create = netdev_vxlan_fill_message_create,
193 .create_type = NETDEV_CREATE_STACKED,
3be1d7e0
TG
194 .config_verify = netdev_vxlan_verify,
195};