1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 Susant Sahani <susant@redhat.com>
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.
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.
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/>.
24 #include "sd-netlink.h"
25 #include "networkd-netdev-vxlan.h"
26 #include "networkd-link.h"
27 #include "conf-parser.h"
30 static int netdev_vxlan_fill_message_create(NetDev
*netdev
, Link
*link
, sd_netlink_message
*m
) {
31 VxLan
*v
= VXLAN(netdev
);
40 if (v
->id
<= VXLAN_VID_MAX
) {
41 r
= sd_netlink_message_append_u32(m
, IFLA_VXLAN_ID
, v
->id
);
43 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_ID attribute: %m");
46 r
= sd_netlink_message_append_in_addr(m
, IFLA_VXLAN_GROUP
, &v
->group
.in
);
48 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_GROUP attribute: %m");
50 r
= sd_netlink_message_append_u32(m
, IFLA_VXLAN_LINK
, link
->ifindex
);
52 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_LINK attribute: %m");
55 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_TTL
, v
->ttl
);
57 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_TTL attribute: %m");
61 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_TOS
, v
->tos
);
63 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_TOS attribute: %m");
66 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_LEARNING
, v
->learning
);
68 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_LEARNING attribute: %m");
70 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_RSC
, v
->route_short_circuit
);
72 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_RSC attribute: %m");
74 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_PROXY
, v
->arp_proxy
);
76 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_PROXY attribute: %m");
78 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_L2MISS
, v
->l2miss
);
80 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_L2MISS attribute: %m");
82 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_L3MISS
, v
->l3miss
);
84 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_L3MISS attribute: %m");
87 r
= sd_netlink_message_append_u32(m
, IFLA_VXLAN_AGEING
, v
->fdb_ageing
/ USEC_PER_SEC
);
89 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_AGEING attribute: %m");
92 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_UDP_CSUM
, v
->udpcsum
);
94 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_UDP_CSUM attribute: %m");
96 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_UDP_ZERO_CSUM6_TX
, v
->udp6zerocsumtx
);
98 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_TX attribute: %m");
100 r
= sd_netlink_message_append_u8(m
, IFLA_VXLAN_UDP_ZERO_CSUM6_RX
, v
->udp6zerocsumrx
);
102 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_RX attribute: %m");
107 int config_parse_vxlan_group_address(const char *unit
,
108 const char *filename
,
111 unsigned section_line
,
118 union in_addr_union
*addr
= data
, buffer
;
126 r
= in_addr_from_string_auto(rvalue
, &f
, &buffer
);
128 log_syntax(unit
, LOG_ERR
, filename
, line
, EINVAL
,
129 "vxlan multicast group address is invalid, ignoring assignment: %s", rvalue
);
133 if(v
->family
!= AF_UNSPEC
&& v
->family
!= f
) {
134 log_syntax(unit
, LOG_ERR
, filename
, line
, EINVAL
,
135 "vxlan multicast group incompatible, ignoring assignment: %s", rvalue
);
145 static int netdev_vxlan_verify(NetDev
*netdev
, const char *filename
) {
146 VxLan
*v
= VXLAN(netdev
);
152 if (v
->id
> VXLAN_VID_MAX
) {
153 log_warning("VXLAN without valid Id configured in %s. Ignoring", filename
);
160 static void vxlan_init(NetDev
*netdev
) {
161 VxLan
*v
= VXLAN(netdev
);
166 v
->id
= VXLAN_VID_MAX
+ 1;
169 v
->udp6zerocsumtx
= false;
170 v
->udp6zerocsumrx
= false;
173 const NetDevVTable vxlan_vtable
= {
174 .object_size
= sizeof(VxLan
),
176 .sections
= "Match\0NetDev\0VXLAN\0",
177 .fill_message_create
= netdev_vxlan_fill_message_create
,
178 .create_type
= NETDEV_CREATE_STACKED
,
179 .config_verify
= netdev_vxlan_verify
,