2 This file is part of systemd.
4 Copyright 2014 Susant Sahani
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "sd-netlink.h"
24 #include "conf-parser.h"
25 #include "alloc-util.h"
26 #include "extract-word.h"
27 #include "parse-util.h"
30 #include "networkd-link.h"
31 #include "networkd-netdev-vxlan.h"
33 static int netdev_vxlan_fill_message_create(NetDev
*netdev
, Link
*link
, sd_netlink_message
*m
) {
45 if (v
->id
<= VXLAN_VID_MAX
) {
46 r
= sd_netlink_message_append_u32(m
, IFLA_VXLAN_ID
, v
->id
);
48 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_ID attribute: %m");
51 r
= sd_netlink_message_append_in_addr(m
, IFLA_VXLAN_GROUP
, &v
->group
.in
);
53 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_GROUP attribute: %m");
55 r
= sd_netlink_message_append_u32(m
, IFLA_VXLAN_LINK
, link
->ifindex
);
57 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_LINK attribute: %m");
60 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_TTL
, v
->ttl
);
62 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_TTL attribute: %m");
66 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_TOS
, v
->tos
);
68 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_TOS attribute: %m");
71 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_LEARNING
, v
->learning
);
73 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_LEARNING attribute: %m");
75 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_RSC
, v
->route_short_circuit
);
77 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_RSC attribute: %m");
79 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_PROXY
, v
->arp_proxy
);
81 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_PROXY attribute: %m");
83 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_L2MISS
, v
->l2miss
);
85 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_L2MISS attribute: %m");
87 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_L3MISS
, v
->l3miss
);
89 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_L3MISS attribute: %m");
92 r
= sd_netlink_message_append_u32(m
, IFLA_VXLAN_AGEING
, v
->fdb_ageing
/ USEC_PER_SEC
);
94 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_AGEING attribute: %m");
98 r
= sd_netlink_message_append_u32(m
, IFLA_VXLAN_LIMIT
, v
->max_fdb
);
100 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_LIMIT attribute: %m");
103 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_UDP_CSUM
, v
->udpcsum
);
105 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_UDP_CSUM attribute: %m");
107 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_UDP_ZERO_CSUM6_TX
, v
->udp6zerocsumtx
);
109 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_TX attribute: %m");
111 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_UDP_ZERO_CSUM6_RX
, v
->udp6zerocsumrx
);
113 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_RX attribute: %m");
115 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_REMCSUM_TX
, v
->remote_csum_tx
);
117 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_REMCSUM_TX attribute: %m");
119 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_REMCSUM_RX
, v
->remote_csum_rx
);
121 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_REMCSUM_RX attribute: %m");
123 r
= sd_netlink_message_append_u16(m
, IFLA_VXLAN_PORT
, htobe16(v
->dest_port
));
125 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_PORT attribute: %m");
127 if (v
->port_range
.low
|| v
->port_range
.high
) {
128 struct ifla_vxlan_port_range port_range
;
130 port_range
.low
= htobe16(v
->port_range
.low
);
131 port_range
.high
= htobe16(v
->port_range
.high
);
133 r
= sd_netlink_message_append_data(m
, IFLA_VXLAN_PORT_RANGE
, &port_range
, sizeof(port_range
));
135 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_PORT_RANGE attribute: %m");
138 if (v
->group_policy
) {
139 r
= sd_netlink_message_append_flag(m
, IFLA_VXLAN_GBP
);
141 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_GBP attribute: %m");
147 int config_parse_vxlan_group_address(const char *unit
,
148 const char *filename
,
151 unsigned section_line
,
158 union in_addr_union
*addr
= data
, buffer
;
166 r
= in_addr_from_string_auto(rvalue
, &f
, &buffer
);
168 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "vxlan multicast group address is invalid, ignoring assignment: %s", rvalue
);
172 if (v
->family
!= AF_UNSPEC
&& v
->family
!= f
) {
173 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "vxlan multicast group incompatible, ignoring assignment: %s", rvalue
);
183 int config_parse_port_range(const char *unit
,
184 const char *filename
,
187 unsigned section_line
,
193 _cleanup_free_
char *word
= NULL
;
203 r
= extract_first_word(&rvalue
, &word
, NULL
, 0);
205 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract VXLAN port range, ignoring: %s", rvalue
);
212 r
= parse_range(word
, &low
, &high
);
214 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse VXLAN port range '%s'", word
);
218 if (low
<= 0 || low
> 65535 || high
<= 0 || high
> 65535) {
219 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
220 "Failed to parse VXLAN port range '%s'. Port should be greater than 0 and less than 65535.", word
);
225 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
226 "Failed to parse VXLAN port range '%s'. Port range %u .. %u not valid", word
, low
, high
);
230 v
->port_range
.low
= low
;
231 v
->port_range
.high
= high
;
236 int config_parse_destination_port(const char *unit
,
237 const char *filename
,
240 unsigned section_line
,
255 r
= safe_atou16(rvalue
, &port
);
256 if (r
< 0 || port
<= 0) {
257 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse VXLAN destination port '%s'.", rvalue
);
266 static int netdev_vxlan_verify(NetDev
*netdev
, const char *filename
) {
267 VxLan
*v
= VXLAN(netdev
);
273 if (v
->id
> VXLAN_VID_MAX
) {
274 log_warning("VXLAN without valid Id configured in %s. Ignoring", filename
);
281 static void vxlan_init(NetDev
*netdev
) {
290 v
->id
= VXLAN_VID_MAX
+ 1;
293 v
->udp6zerocsumtx
= false;
294 v
->udp6zerocsumrx
= false;
297 const NetDevVTable vxlan_vtable
= {
298 .object_size
= sizeof(VxLan
),
300 .sections
= "Match\0NetDev\0VXLAN\0",
301 .fill_message_create
= netdev_vxlan_fill_message_create
,
302 .create_type
= NETDEV_CREATE_STACKED
,
303 .config_verify
= netdev_vxlan_verify
,