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 "string-util.h"
29 #include "parse-util.h"
32 #include "networkd-link.h"
33 #include "netdev/vxlan.h"
35 static int netdev_vxlan_fill_message_create(NetDev
*netdev
, Link
*link
, sd_netlink_message
*m
) {
47 if (v
->id
<= VXLAN_VID_MAX
) {
48 r
= sd_netlink_message_append_u32(m
, IFLA_VXLAN_ID
, v
->id
);
50 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_ID attribute: %m");
53 if (!in_addr_is_null(v
->remote_family
, &v
->remote
)) {
55 if (v
->remote_family
== AF_INET
)
56 r
= sd_netlink_message_append_in_addr(m
, IFLA_VXLAN_GROUP
, &v
->remote
.in
);
58 r
= sd_netlink_message_append_in6_addr(m
, IFLA_VXLAN_GROUP6
, &v
->remote
.in6
);
61 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_GROUP attribute: %m");
65 if (!in_addr_is_null(v
->local_family
, &v
->local
)) {
67 if (v
->local_family
== AF_INET
)
68 r
= sd_netlink_message_append_in_addr(m
, IFLA_VXLAN_LOCAL
, &v
->local
.in
);
70 r
= sd_netlink_message_append_in6_addr(m
, IFLA_VXLAN_LOCAL6
, &v
->local
.in6
);
73 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_LOCAL attribute: %m");
77 r
= sd_netlink_message_append_u32(m
, IFLA_VXLAN_LINK
, link
->ifindex
);
79 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_LINK attribute: %m");
82 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_TTL
, v
->ttl
);
84 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_TTL attribute: %m");
88 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_TOS
, v
->tos
);
90 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_TOS attribute: %m");
93 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_LEARNING
, v
->learning
);
95 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_LEARNING attribute: %m");
97 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_RSC
, v
->route_short_circuit
);
99 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_RSC attribute: %m");
101 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_PROXY
, v
->arp_proxy
);
103 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_PROXY attribute: %m");
105 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_L2MISS
, v
->l2miss
);
107 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_L2MISS attribute: %m");
109 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_L3MISS
, v
->l3miss
);
111 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_L3MISS attribute: %m");
114 r
= sd_netlink_message_append_u32(m
, IFLA_VXLAN_AGEING
, v
->fdb_ageing
/ USEC_PER_SEC
);
116 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_AGEING attribute: %m");
120 r
= sd_netlink_message_append_u32(m
, IFLA_VXLAN_LIMIT
, v
->max_fdb
);
122 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_LIMIT attribute: %m");
125 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_UDP_CSUM
, v
->udpcsum
);
127 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_UDP_CSUM attribute: %m");
129 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_UDP_ZERO_CSUM6_TX
, v
->udp6zerocsumtx
);
131 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_TX attribute: %m");
133 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_UDP_ZERO_CSUM6_RX
, v
->udp6zerocsumrx
);
135 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_RX attribute: %m");
137 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_REMCSUM_TX
, v
->remote_csum_tx
);
139 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_REMCSUM_TX attribute: %m");
141 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_REMCSUM_RX
, v
->remote_csum_rx
);
143 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_REMCSUM_RX attribute: %m");
145 r
= sd_netlink_message_append_u16(m
, IFLA_VXLAN_PORT
, htobe16(v
->dest_port
));
147 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_PORT attribute: %m");
149 if (v
->port_range
.low
|| v
->port_range
.high
) {
150 struct ifla_vxlan_port_range port_range
;
152 port_range
.low
= htobe16(v
->port_range
.low
);
153 port_range
.high
= htobe16(v
->port_range
.high
);
155 r
= sd_netlink_message_append_data(m
, IFLA_VXLAN_PORT_RANGE
, &port_range
, sizeof(port_range
));
157 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_PORT_RANGE attribute: %m");
160 r
= sd_netlink_message_append_u32(m
, IFLA_VXLAN_LABEL
, htobe32(v
->flow_label
));
162 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_LABEL attribute: %m");
164 if (v
->group_policy
) {
165 r
= sd_netlink_message_append_flag(m
, IFLA_VXLAN_GBP
);
167 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_GBP attribute: %m");
173 int config_parse_vxlan_address(const char *unit
,
174 const char *filename
,
177 unsigned section_line
,
184 union in_addr_union
*addr
= data
, buffer
;
192 r
= in_addr_from_string_auto(rvalue
, &f
, &buffer
);
194 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "vxlan '%s' address is invalid, ignoring assignment: %s", lvalue
, rvalue
);
198 r
= in_addr_is_multicast(f
, &buffer
);
200 if (STR_IN_SET(lvalue
, "Group", "Remote")) {
202 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "vxlan invalid multicast '%s' address, ignoring assignment: %s", lvalue
, rvalue
);
206 v
->remote_family
= f
;
209 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "vxlan %s can not be multicast address, ignoring assignment: %s", lvalue
, rvalue
);
221 int config_parse_port_range(const char *unit
,
222 const char *filename
,
225 unsigned section_line
,
231 _cleanup_free_
char *word
= NULL
;
241 r
= extract_first_word(&rvalue
, &word
, NULL
, 0);
243 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract VXLAN port range, ignoring: %s", rvalue
);
250 r
= parse_range(word
, &low
, &high
);
252 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse VXLAN port range '%s'", word
);
256 if (low
<= 0 || low
> 65535 || high
<= 0 || high
> 65535) {
257 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
258 "Failed to parse VXLAN port range '%s'. Port should be greater than 0 and less than 65535.", word
);
263 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
264 "Failed to parse VXLAN port range '%s'. Port range %u .. %u not valid", word
, low
, high
);
268 v
->port_range
.low
= low
;
269 v
->port_range
.high
= high
;
274 int config_parse_flow_label(const char *unit
,
275 const char *filename
,
278 unsigned section_line
,
293 r
= safe_atou(rvalue
, &f
);
295 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse VXLAN flow label '%s'.", rvalue
);
299 if (f
& ~VXLAN_FLOW_LABEL_MAX_MASK
) {
300 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
301 "VXLAN flow label '%s' not valid. Flow label range should be [0-1048575].", rvalue
);
310 static int netdev_vxlan_verify(NetDev
*netdev
, const char *filename
) {
311 VxLan
*v
= VXLAN(netdev
);
317 if (v
->id
> VXLAN_VID_MAX
) {
318 log_warning("VXLAN without valid Id configured in %s. Ignoring", filename
);
325 static void vxlan_init(NetDev
*netdev
) {
334 v
->id
= VXLAN_VID_MAX
+ 1;
337 v
->udp6zerocsumtx
= false;
338 v
->udp6zerocsumrx
= false;
341 const NetDevVTable vxlan_vtable
= {
342 .object_size
= sizeof(VxLan
),
344 .sections
= "Match\0NetDev\0VXLAN\0",
345 .fill_message_create
= netdev_vxlan_fill_message_create
,
346 .create_type
= NETDEV_CREATE_STACKED
,
347 .config_verify
= netdev_vxlan_verify
,