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