]>
Commit | Line | Data |
---|---|---|
2d07dc79 JL |
1 | /* |
2 | * GENEVE: Generic Network Virtualization Encapsulation | |
3 | * | |
4 | * Copyright (c) 2015 Red Hat, Inc. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | */ | |
10 | ||
11 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
12 | ||
13 | #include <linux/kernel.h> | |
14 | #include <linux/module.h> | |
2d07dc79 JL |
15 | #include <linux/etherdevice.h> |
16 | #include <linux/hash.h> | |
e305ac6c | 17 | #include <net/dst_metadata.h> |
8e816df8 | 18 | #include <net/gro_cells.h> |
2d07dc79 JL |
19 | #include <net/rtnetlink.h> |
20 | #include <net/geneve.h> | |
371bd106 | 21 | #include <net/protocol.h> |
2d07dc79 JL |
22 | |
23 | #define GENEVE_NETDEV_VER "0.6" | |
24 | ||
25 | #define GENEVE_UDP_PORT 6081 | |
26 | ||
27 | #define GENEVE_N_VID (1u << 24) | |
28 | #define GENEVE_VID_MASK (GENEVE_N_VID - 1) | |
29 | ||
30 | #define VNI_HASH_BITS 10 | |
31 | #define VNI_HASH_SIZE (1<<VNI_HASH_BITS) | |
32 | ||
33 | static bool log_ecn_error = true; | |
34 | module_param(log_ecn_error, bool, 0644); | |
35 | MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN"); | |
36 | ||
371bd106 PS |
37 | #define GENEVE_VER 0 |
38 | #define GENEVE_BASE_HLEN (sizeof(struct udphdr) + sizeof(struct genevehdr)) | |
5edbea69 AK |
39 | #define GENEVE_IPV4_HLEN (ETH_HLEN + sizeof(struct iphdr) + GENEVE_BASE_HLEN) |
40 | #define GENEVE_IPV6_HLEN (ETH_HLEN + sizeof(struct ipv6hdr) + GENEVE_BASE_HLEN) | |
371bd106 | 41 | |
2d07dc79 JL |
42 | /* per-network namespace private data for this module */ |
43 | struct geneve_net { | |
371bd106 | 44 | struct list_head geneve_list; |
371bd106 | 45 | struct list_head sock_list; |
2d07dc79 JL |
46 | }; |
47 | ||
c7d03a00 | 48 | static unsigned int geneve_net_id; |
371bd106 | 49 | |
4b4c21fa JB |
50 | struct geneve_dev_node { |
51 | struct hlist_node hlist; | |
52 | struct geneve_dev *geneve; | |
53 | }; | |
54 | ||
2d07dc79 JL |
55 | /* Pseudo network device */ |
56 | struct geneve_dev { | |
4b4c21fa JB |
57 | struct geneve_dev_node hlist4; /* vni hash table for IPv4 socket */ |
58 | #if IS_ENABLED(CONFIG_IPV6) | |
59 | struct geneve_dev_node hlist6; /* vni hash table for IPv6 socket */ | |
60 | #endif | |
2d07dc79 JL |
61 | struct net *net; /* netns for packet i/o */ |
62 | struct net_device *dev; /* netdev for geneve tunnel */ | |
9b4437a5 | 63 | struct ip_tunnel_info info; |
fceb9c3e | 64 | struct geneve_sock __rcu *sock4; /* IPv4 socket used for geneve tunnel */ |
8ed66f0e | 65 | #if IS_ENABLED(CONFIG_IPV6) |
fceb9c3e | 66 | struct geneve_sock __rcu *sock6; /* IPv6 socket used for geneve tunnel */ |
8ed66f0e | 67 | #endif |
2d07dc79 | 68 | struct list_head next; /* geneve's per namespace list */ |
8e816df8 | 69 | struct gro_cells gro_cells; |
9b4437a5 | 70 | bool collect_md; |
71 | bool use_udp6_rx_checksums; | |
2d07dc79 JL |
72 | }; |
73 | ||
371bd106 PS |
74 | struct geneve_sock { |
75 | bool collect_md; | |
371bd106 PS |
76 | struct list_head list; |
77 | struct socket *sock; | |
78 | struct rcu_head rcu; | |
79 | int refcnt; | |
66d47003 | 80 | struct hlist_head vni_list[VNI_HASH_SIZE]; |
371bd106 | 81 | }; |
2d07dc79 JL |
82 | |
83 | static inline __u32 geneve_net_vni_hash(u8 vni[3]) | |
84 | { | |
85 | __u32 vnid; | |
86 | ||
87 | vnid = (vni[0] << 16) | (vni[1] << 8) | vni[2]; | |
88 | return hash_32(vnid, VNI_HASH_BITS); | |
89 | } | |
90 | ||
e305ac6c PS |
91 | static __be64 vni_to_tunnel_id(const __u8 *vni) |
92 | { | |
93 | #ifdef __BIG_ENDIAN | |
94 | return (vni[0] << 16) | (vni[1] << 8) | vni[2]; | |
95 | #else | |
96 | return (__force __be64)(((__force u64)vni[0] << 40) | | |
97 | ((__force u64)vni[1] << 48) | | |
98 | ((__force u64)vni[2] << 56)); | |
99 | #endif | |
100 | } | |
101 | ||
9b4437a5 | 102 | /* Convert 64 bit tunnel ID to 24 bit VNI. */ |
103 | static void tunnel_id_to_vni(__be64 tun_id, __u8 *vni) | |
104 | { | |
105 | #ifdef __BIG_ENDIAN | |
106 | vni[0] = (__force __u8)(tun_id >> 16); | |
107 | vni[1] = (__force __u8)(tun_id >> 8); | |
108 | vni[2] = (__force __u8)tun_id; | |
109 | #else | |
110 | vni[0] = (__force __u8)((__force u64)tun_id >> 40); | |
111 | vni[1] = (__force __u8)((__force u64)tun_id >> 48); | |
112 | vni[2] = (__force __u8)((__force u64)tun_id >> 56); | |
113 | #endif | |
114 | } | |
115 | ||
2e0b26e1 | 116 | static bool eq_tun_id_and_vni(u8 *tun_id, u8 *vni) |
117 | { | |
2e0b26e1 | 118 | return !memcmp(vni, &tun_id[5], 3); |
2e0b26e1 | 119 | } |
120 | ||
1e9f12ec JB |
121 | static sa_family_t geneve_get_sk_family(struct geneve_sock *gs) |
122 | { | |
123 | return gs->sock->sk->sk_family; | |
124 | } | |
125 | ||
66d47003 | 126 | static struct geneve_dev *geneve_lookup(struct geneve_sock *gs, |
371bd106 | 127 | __be32 addr, u8 vni[]) |
2d07dc79 | 128 | { |
2d07dc79 | 129 | struct hlist_head *vni_list_head; |
4b4c21fa | 130 | struct geneve_dev_node *node; |
2d07dc79 JL |
131 | __u32 hash; |
132 | ||
2d07dc79 | 133 | /* Find the device for this VNI */ |
371bd106 | 134 | hash = geneve_net_vni_hash(vni); |
66d47003 | 135 | vni_list_head = &gs->vni_list[hash]; |
4b4c21fa JB |
136 | hlist_for_each_entry_rcu(node, vni_list_head, hlist) { |
137 | if (eq_tun_id_and_vni((u8 *)&node->geneve->info.key.tun_id, vni) && | |
138 | addr == node->geneve->info.key.u.ipv4.dst) | |
139 | return node->geneve; | |
8ed66f0e JL |
140 | } |
141 | return NULL; | |
142 | } | |
143 | ||
144 | #if IS_ENABLED(CONFIG_IPV6) | |
145 | static struct geneve_dev *geneve6_lookup(struct geneve_sock *gs, | |
146 | struct in6_addr addr6, u8 vni[]) | |
147 | { | |
148 | struct hlist_head *vni_list_head; | |
4b4c21fa | 149 | struct geneve_dev_node *node; |
8ed66f0e JL |
150 | __u32 hash; |
151 | ||
152 | /* Find the device for this VNI */ | |
153 | hash = geneve_net_vni_hash(vni); | |
154 | vni_list_head = &gs->vni_list[hash]; | |
4b4c21fa JB |
155 | hlist_for_each_entry_rcu(node, vni_list_head, hlist) { |
156 | if (eq_tun_id_and_vni((u8 *)&node->geneve->info.key.tun_id, vni) && | |
157 | ipv6_addr_equal(&addr6, &node->geneve->info.key.u.ipv6.dst)) | |
158 | return node->geneve; | |
2d07dc79 | 159 | } |
e305ac6c PS |
160 | return NULL; |
161 | } | |
8ed66f0e | 162 | #endif |
e305ac6c | 163 | |
371bd106 PS |
164 | static inline struct genevehdr *geneve_hdr(const struct sk_buff *skb) |
165 | { | |
166 | return (struct genevehdr *)(udp_hdr(skb) + 1); | |
167 | } | |
168 | ||
9fc47545 JB |
169 | static struct geneve_dev *geneve_lookup_skb(struct geneve_sock *gs, |
170 | struct sk_buff *skb) | |
e305ac6c | 171 | { |
8ed66f0e | 172 | static u8 zero_vni[3]; |
9b4437a5 | 173 | u8 *vni; |
e305ac6c | 174 | |
1e9f12ec | 175 | if (geneve_get_sk_family(gs) == AF_INET) { |
9fc47545 | 176 | struct iphdr *iph; |
9b4437a5 | 177 | __be32 addr; |
9fc47545 | 178 | |
8ed66f0e | 179 | iph = ip_hdr(skb); /* outer IP header... */ |
371bd106 | 180 | |
8ed66f0e JL |
181 | if (gs->collect_md) { |
182 | vni = zero_vni; | |
183 | addr = 0; | |
184 | } else { | |
9fc47545 | 185 | vni = geneve_hdr(skb)->vni; |
8ed66f0e JL |
186 | addr = iph->saddr; |
187 | } | |
188 | ||
9fc47545 | 189 | return geneve_lookup(gs, addr, vni); |
8ed66f0e | 190 | #if IS_ENABLED(CONFIG_IPV6) |
1e9f12ec | 191 | } else if (geneve_get_sk_family(gs) == AF_INET6) { |
9b4437a5 | 192 | static struct in6_addr zero_addr6; |
9fc47545 JB |
193 | struct ipv6hdr *ip6h; |
194 | struct in6_addr addr6; | |
195 | ||
8ed66f0e | 196 | ip6h = ipv6_hdr(skb); /* outer IPv6 header... */ |
371bd106 | 197 | |
8ed66f0e JL |
198 | if (gs->collect_md) { |
199 | vni = zero_vni; | |
200 | addr6 = zero_addr6; | |
201 | } else { | |
9fc47545 | 202 | vni = geneve_hdr(skb)->vni; |
8ed66f0e JL |
203 | addr6 = ip6h->saddr; |
204 | } | |
205 | ||
9fc47545 | 206 | return geneve6_lookup(gs, addr6, vni); |
8ed66f0e JL |
207 | #endif |
208 | } | |
9fc47545 JB |
209 | return NULL; |
210 | } | |
211 | ||
212 | /* geneve receive/decap routine */ | |
213 | static void geneve_rx(struct geneve_dev *geneve, struct geneve_sock *gs, | |
214 | struct sk_buff *skb) | |
215 | { | |
216 | struct genevehdr *gnvh = geneve_hdr(skb); | |
217 | struct metadata_dst *tun_dst = NULL; | |
218 | struct pcpu_sw_netstats *stats; | |
fe741e23 | 219 | unsigned int len; |
9fc47545 JB |
220 | int err = 0; |
221 | void *oiph; | |
2d07dc79 | 222 | |
371bd106 | 223 | if (ip_tunnel_collect_metadata() || gs->collect_md) { |
e305ac6c | 224 | __be16 flags; |
e305ac6c PS |
225 | |
226 | flags = TUNNEL_KEY | TUNNEL_GENEVE_OPT | | |
227 | (gnvh->oam ? TUNNEL_OAM : 0) | | |
228 | (gnvh->critical ? TUNNEL_CRIT_OPT : 0); | |
229 | ||
1e9f12ec | 230 | tun_dst = udp_tun_rx_dst(skb, geneve_get_sk_family(gs), flags, |
e305ac6c PS |
231 | vni_to_tunnel_id(gnvh->vni), |
232 | gnvh->opt_len * 4); | |
fe741e23 GM |
233 | if (!tun_dst) { |
234 | geneve->dev->stats.rx_dropped++; | |
e305ac6c | 235 | goto drop; |
fe741e23 | 236 | } |
e305ac6c | 237 | /* Update tunnel dst according to Geneve options. */ |
4c222798 PS |
238 | ip_tunnel_info_opts_set(&tun_dst->u.tun_info, |
239 | gnvh->options, gnvh->opt_len * 4); | |
e305ac6c PS |
240 | } else { |
241 | /* Drop packets w/ critical options, | |
242 | * since we don't support any... | |
243 | */ | |
fe741e23 GM |
244 | if (gnvh->critical) { |
245 | geneve->dev->stats.rx_frame_errors++; | |
246 | geneve->dev->stats.rx_errors++; | |
e305ac6c | 247 | goto drop; |
fe741e23 | 248 | } |
e305ac6c | 249 | } |
2d07dc79 JL |
250 | |
251 | skb_reset_mac_header(skb); | |
2d07dc79 JL |
252 | skb->protocol = eth_type_trans(skb, geneve->dev); |
253 | skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN); | |
254 | ||
e305ac6c PS |
255 | if (tun_dst) |
256 | skb_dst_set(skb, &tun_dst->dst); | |
257 | ||
2d07dc79 | 258 | /* Ignore packet loops (and multicast echo) */ |
fe741e23 GM |
259 | if (ether_addr_equal(eth_hdr(skb)->h_source, geneve->dev->dev_addr)) { |
260 | geneve->dev->stats.rx_errors++; | |
2d07dc79 | 261 | goto drop; |
fe741e23 | 262 | } |
2d07dc79 | 263 | |
9fc47545 | 264 | oiph = skb_network_header(skb); |
2d07dc79 JL |
265 | skb_reset_network_header(skb); |
266 | ||
9fc47545 JB |
267 | if (geneve_get_sk_family(gs) == AF_INET) |
268 | err = IP_ECN_decapsulate(oiph, skb); | |
8ed66f0e | 269 | #if IS_ENABLED(CONFIG_IPV6) |
9fc47545 JB |
270 | else |
271 | err = IP6_ECN_decapsulate(oiph, skb); | |
8ed66f0e | 272 | #endif |
2d07dc79 JL |
273 | |
274 | if (unlikely(err)) { | |
8ed66f0e | 275 | if (log_ecn_error) { |
9fc47545 | 276 | if (geneve_get_sk_family(gs) == AF_INET) |
8ed66f0e JL |
277 | net_info_ratelimited("non-ECT from %pI4 " |
278 | "with TOS=%#x\n", | |
9fc47545 JB |
279 | &((struct iphdr *)oiph)->saddr, |
280 | ((struct iphdr *)oiph)->tos); | |
8ed66f0e | 281 | #if IS_ENABLED(CONFIG_IPV6) |
9fc47545 | 282 | else |
8ed66f0e | 283 | net_info_ratelimited("non-ECT from %pI6\n", |
9fc47545 | 284 | &((struct ipv6hdr *)oiph)->saddr); |
8ed66f0e JL |
285 | #endif |
286 | } | |
2d07dc79 JL |
287 | if (err > 1) { |
288 | ++geneve->dev->stats.rx_frame_errors; | |
289 | ++geneve->dev->stats.rx_errors; | |
290 | goto drop; | |
291 | } | |
292 | } | |
293 | ||
fe741e23 GM |
294 | len = skb->len; |
295 | err = gro_cells_receive(&geneve->gro_cells, skb); | |
296 | if (likely(err == NET_RX_SUCCESS)) { | |
297 | stats = this_cpu_ptr(geneve->dev->tstats); | |
298 | u64_stats_update_begin(&stats->syncp); | |
299 | stats->rx_packets++; | |
300 | stats->rx_bytes += len; | |
301 | u64_stats_update_end(&stats->syncp); | |
302 | } | |
2d07dc79 JL |
303 | return; |
304 | drop: | |
305 | /* Consume bad packet */ | |
306 | kfree_skb(skb); | |
307 | } | |
308 | ||
309 | /* Setup stats when device is created */ | |
310 | static int geneve_init(struct net_device *dev) | |
311 | { | |
8e816df8 JG |
312 | struct geneve_dev *geneve = netdev_priv(dev); |
313 | int err; | |
314 | ||
2d07dc79 JL |
315 | dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats); |
316 | if (!dev->tstats) | |
317 | return -ENOMEM; | |
8e816df8 JG |
318 | |
319 | err = gro_cells_init(&geneve->gro_cells, dev); | |
320 | if (err) { | |
321 | free_percpu(dev->tstats); | |
322 | return err; | |
323 | } | |
324 | ||
9b4437a5 | 325 | err = dst_cache_init(&geneve->info.dst_cache, GFP_KERNEL); |
468dfffc PA |
326 | if (err) { |
327 | free_percpu(dev->tstats); | |
328 | gro_cells_destroy(&geneve->gro_cells); | |
329 | return err; | |
330 | } | |
2d07dc79 JL |
331 | return 0; |
332 | } | |
333 | ||
334 | static void geneve_uninit(struct net_device *dev) | |
335 | { | |
8e816df8 JG |
336 | struct geneve_dev *geneve = netdev_priv(dev); |
337 | ||
9b4437a5 | 338 | dst_cache_destroy(&geneve->info.dst_cache); |
8e816df8 | 339 | gro_cells_destroy(&geneve->gro_cells); |
2d07dc79 JL |
340 | free_percpu(dev->tstats); |
341 | } | |
342 | ||
371bd106 PS |
343 | /* Callback from net/ipv4/udp.c to receive packets */ |
344 | static int geneve_udp_encap_recv(struct sock *sk, struct sk_buff *skb) | |
345 | { | |
346 | struct genevehdr *geneveh; | |
9fc47545 | 347 | struct geneve_dev *geneve; |
371bd106 PS |
348 | struct geneve_sock *gs; |
349 | int opts_len; | |
350 | ||
fe741e23 | 351 | /* Need UDP and Geneve header to be present */ |
371bd106 | 352 | if (unlikely(!pskb_may_pull(skb, GENEVE_BASE_HLEN))) |
e5aed006 | 353 | goto drop; |
371bd106 PS |
354 | |
355 | /* Return packets with reserved bits set */ | |
356 | geneveh = geneve_hdr(skb); | |
357 | if (unlikely(geneveh->ver != GENEVE_VER)) | |
e5aed006 | 358 | goto drop; |
371bd106 PS |
359 | |
360 | if (unlikely(geneveh->proto_type != htons(ETH_P_TEB))) | |
e5aed006 | 361 | goto drop; |
371bd106 | 362 | |
9fc47545 JB |
363 | gs = rcu_dereference_sk_user_data(sk); |
364 | if (!gs) | |
365 | goto drop; | |
366 | ||
367 | geneve = geneve_lookup_skb(gs, skb); | |
368 | if (!geneve) | |
369 | goto drop; | |
370 | ||
371bd106 PS |
371 | opts_len = geneveh->opt_len * 4; |
372 | if (iptunnel_pull_header(skb, GENEVE_BASE_HLEN + opts_len, | |
7f290c94 | 373 | htons(ETH_P_TEB), |
fe741e23 GM |
374 | !net_eq(geneve->net, dev_net(geneve->dev)))) { |
375 | geneve->dev->stats.rx_dropped++; | |
371bd106 | 376 | goto drop; |
fe741e23 | 377 | } |
371bd106 | 378 | |
9fc47545 | 379 | geneve_rx(geneve, gs, skb); |
371bd106 PS |
380 | return 0; |
381 | ||
382 | drop: | |
383 | /* Consume bad packet */ | |
384 | kfree_skb(skb); | |
385 | return 0; | |
371bd106 PS |
386 | } |
387 | ||
388 | static struct socket *geneve_create_sock(struct net *net, bool ipv6, | |
9b4437a5 | 389 | __be16 port, bool ipv6_rx_csum) |
371bd106 PS |
390 | { |
391 | struct socket *sock; | |
392 | struct udp_port_cfg udp_conf; | |
393 | int err; | |
394 | ||
395 | memset(&udp_conf, 0, sizeof(udp_conf)); | |
396 | ||
397 | if (ipv6) { | |
398 | udp_conf.family = AF_INET6; | |
8ed66f0e | 399 | udp_conf.ipv6_v6only = 1; |
9b4437a5 | 400 | udp_conf.use_udp6_rx_checksums = ipv6_rx_csum; |
371bd106 PS |
401 | } else { |
402 | udp_conf.family = AF_INET; | |
403 | udp_conf.local_ip.s_addr = htonl(INADDR_ANY); | |
404 | } | |
405 | ||
406 | udp_conf.local_udp_port = port; | |
407 | ||
408 | /* Open UDP socket */ | |
409 | err = udp_sock_create(net, &udp_conf, &sock); | |
410 | if (err < 0) | |
411 | return ERR_PTR(err); | |
412 | ||
413 | return sock; | |
414 | } | |
415 | ||
371bd106 PS |
416 | static int geneve_hlen(struct genevehdr *gh) |
417 | { | |
418 | return sizeof(*gh) + gh->opt_len * 4; | |
419 | } | |
420 | ||
d4546c25 DM |
421 | static struct sk_buff *geneve_gro_receive(struct sock *sk, |
422 | struct list_head *head, | |
423 | struct sk_buff *skb) | |
371bd106 | 424 | { |
d4546c25 DM |
425 | struct sk_buff *pp = NULL; |
426 | struct sk_buff *p; | |
371bd106 PS |
427 | struct genevehdr *gh, *gh2; |
428 | unsigned int hlen, gh_len, off_gnv; | |
429 | const struct packet_offload *ptype; | |
430 | __be16 type; | |
431 | int flush = 1; | |
432 | ||
433 | off_gnv = skb_gro_offset(skb); | |
434 | hlen = off_gnv + sizeof(*gh); | |
435 | gh = skb_gro_header_fast(skb, off_gnv); | |
436 | if (skb_gro_header_hard(skb, hlen)) { | |
437 | gh = skb_gro_header_slow(skb, hlen, off_gnv); | |
438 | if (unlikely(!gh)) | |
439 | goto out; | |
440 | } | |
441 | ||
442 | if (gh->ver != GENEVE_VER || gh->oam) | |
443 | goto out; | |
444 | gh_len = geneve_hlen(gh); | |
445 | ||
446 | hlen = off_gnv + gh_len; | |
447 | if (skb_gro_header_hard(skb, hlen)) { | |
448 | gh = skb_gro_header_slow(skb, hlen, off_gnv); | |
449 | if (unlikely(!gh)) | |
450 | goto out; | |
451 | } | |
452 | ||
d4546c25 | 453 | list_for_each_entry(p, head, list) { |
371bd106 PS |
454 | if (!NAPI_GRO_CB(p)->same_flow) |
455 | continue; | |
456 | ||
457 | gh2 = (struct genevehdr *)(p->data + off_gnv); | |
458 | if (gh->opt_len != gh2->opt_len || | |
459 | memcmp(gh, gh2, gh_len)) { | |
460 | NAPI_GRO_CB(p)->same_flow = 0; | |
461 | continue; | |
462 | } | |
463 | } | |
464 | ||
465 | type = gh->proto_type; | |
466 | ||
467 | rcu_read_lock(); | |
468 | ptype = gro_find_receive_by_type(type); | |
c194cf93 | 469 | if (!ptype) |
371bd106 | 470 | goto out_unlock; |
371bd106 PS |
471 | |
472 | skb_gro_pull(skb, gh_len); | |
473 | skb_gro_postpull_rcsum(skb, gh, gh_len); | |
fcd91dd4 | 474 | pp = call_gro_receive(ptype->callbacks.gro_receive, head, skb); |
c194cf93 | 475 | flush = 0; |
371bd106 PS |
476 | |
477 | out_unlock: | |
478 | rcu_read_unlock(); | |
479 | out: | |
480 | NAPI_GRO_CB(skb)->flush |= flush; | |
481 | ||
482 | return pp; | |
483 | } | |
484 | ||
4a0090a9 TH |
485 | static int geneve_gro_complete(struct sock *sk, struct sk_buff *skb, |
486 | int nhoff) | |
371bd106 PS |
487 | { |
488 | struct genevehdr *gh; | |
489 | struct packet_offload *ptype; | |
490 | __be16 type; | |
491 | int gh_len; | |
492 | int err = -ENOSYS; | |
493 | ||
371bd106 PS |
494 | gh = (struct genevehdr *)(skb->data + nhoff); |
495 | gh_len = geneve_hlen(gh); | |
496 | type = gh->proto_type; | |
497 | ||
498 | rcu_read_lock(); | |
499 | ptype = gro_find_complete_by_type(type); | |
500 | if (ptype) | |
501 | err = ptype->callbacks.gro_complete(skb, nhoff + gh_len); | |
502 | ||
503 | rcu_read_unlock(); | |
229740c6 JR |
504 | |
505 | skb_set_inner_mac_header(skb, nhoff + gh_len); | |
506 | ||
371bd106 PS |
507 | return err; |
508 | } | |
509 | ||
510 | /* Create new listen socket if needed */ | |
511 | static struct geneve_sock *geneve_socket_create(struct net *net, __be16 port, | |
9b4437a5 | 512 | bool ipv6, bool ipv6_rx_csum) |
371bd106 PS |
513 | { |
514 | struct geneve_net *gn = net_generic(net, geneve_net_id); | |
515 | struct geneve_sock *gs; | |
516 | struct socket *sock; | |
517 | struct udp_tunnel_sock_cfg tunnel_cfg; | |
66d47003 | 518 | int h; |
371bd106 PS |
519 | |
520 | gs = kzalloc(sizeof(*gs), GFP_KERNEL); | |
521 | if (!gs) | |
522 | return ERR_PTR(-ENOMEM); | |
523 | ||
9b4437a5 | 524 | sock = geneve_create_sock(net, ipv6, port, ipv6_rx_csum); |
371bd106 PS |
525 | if (IS_ERR(sock)) { |
526 | kfree(gs); | |
527 | return ERR_CAST(sock); | |
528 | } | |
529 | ||
530 | gs->sock = sock; | |
531 | gs->refcnt = 1; | |
66d47003 PS |
532 | for (h = 0; h < VNI_HASH_SIZE; ++h) |
533 | INIT_HLIST_HEAD(&gs->vni_list[h]); | |
371bd106 PS |
534 | |
535 | /* Initialize the geneve udp offloads structure */ | |
e7b3db5e | 536 | udp_tunnel_notify_add_rx_port(gs->sock, UDP_TUNNEL_TYPE_GENEVE); |
371bd106 PS |
537 | |
538 | /* Mark socket as an encapsulation socket */ | |
4a0090a9 | 539 | memset(&tunnel_cfg, 0, sizeof(tunnel_cfg)); |
371bd106 PS |
540 | tunnel_cfg.sk_user_data = gs; |
541 | tunnel_cfg.encap_type = 1; | |
4a0090a9 TH |
542 | tunnel_cfg.gro_receive = geneve_gro_receive; |
543 | tunnel_cfg.gro_complete = geneve_gro_complete; | |
371bd106 PS |
544 | tunnel_cfg.encap_rcv = geneve_udp_encap_recv; |
545 | tunnel_cfg.encap_destroy = NULL; | |
546 | setup_udp_tunnel_sock(net, sock, &tunnel_cfg); | |
371bd106 PS |
547 | list_add(&gs->list, &gn->sock_list); |
548 | return gs; | |
549 | } | |
550 | ||
8ed66f0e | 551 | static void __geneve_sock_release(struct geneve_sock *gs) |
371bd106 | 552 | { |
8ed66f0e | 553 | if (!gs || --gs->refcnt) |
371bd106 PS |
554 | return; |
555 | ||
556 | list_del(&gs->list); | |
e7b3db5e | 557 | udp_tunnel_notify_del_rx_port(gs->sock, UDP_TUNNEL_TYPE_GENEVE); |
371bd106 PS |
558 | udp_tunnel_sock_release(gs->sock); |
559 | kfree_rcu(gs, rcu); | |
560 | } | |
561 | ||
8ed66f0e JL |
562 | static void geneve_sock_release(struct geneve_dev *geneve) |
563 | { | |
fceb9c3e | 564 | struct geneve_sock *gs4 = rtnl_dereference(geneve->sock4); |
8ed66f0e | 565 | #if IS_ENABLED(CONFIG_IPV6) |
fceb9c3e | 566 | struct geneve_sock *gs6 = rtnl_dereference(geneve->sock6); |
567 | ||
568 | rcu_assign_pointer(geneve->sock6, NULL); | |
569 | #endif | |
570 | ||
571 | rcu_assign_pointer(geneve->sock4, NULL); | |
572 | synchronize_net(); | |
573 | ||
574 | __geneve_sock_release(gs4); | |
575 | #if IS_ENABLED(CONFIG_IPV6) | |
576 | __geneve_sock_release(gs6); | |
8ed66f0e JL |
577 | #endif |
578 | } | |
579 | ||
371bd106 | 580 | static struct geneve_sock *geneve_find_sock(struct geneve_net *gn, |
8ed66f0e | 581 | sa_family_t family, |
371bd106 PS |
582 | __be16 dst_port) |
583 | { | |
584 | struct geneve_sock *gs; | |
585 | ||
586 | list_for_each_entry(gs, &gn->sock_list, list) { | |
587 | if (inet_sk(gs->sock->sk)->inet_sport == dst_port && | |
1e9f12ec | 588 | geneve_get_sk_family(gs) == family) { |
371bd106 PS |
589 | return gs; |
590 | } | |
591 | } | |
592 | return NULL; | |
593 | } | |
594 | ||
8ed66f0e | 595 | static int geneve_sock_add(struct geneve_dev *geneve, bool ipv6) |
2d07dc79 | 596 | { |
2d07dc79 | 597 | struct net *net = geneve->net; |
371bd106 | 598 | struct geneve_net *gn = net_generic(net, geneve_net_id); |
4b4c21fa | 599 | struct geneve_dev_node *node; |
2d07dc79 | 600 | struct geneve_sock *gs; |
9b4437a5 | 601 | __u8 vni[3]; |
66d47003 | 602 | __u32 hash; |
2d07dc79 | 603 | |
9b4437a5 | 604 | gs = geneve_find_sock(gn, ipv6 ? AF_INET6 : AF_INET, geneve->info.key.tp_dst); |
371bd106 PS |
605 | if (gs) { |
606 | gs->refcnt++; | |
607 | goto out; | |
608 | } | |
609 | ||
9b4437a5 | 610 | gs = geneve_socket_create(net, geneve->info.key.tp_dst, ipv6, |
611 | geneve->use_udp6_rx_checksums); | |
2d07dc79 JL |
612 | if (IS_ERR(gs)) |
613 | return PTR_ERR(gs); | |
614 | ||
371bd106 PS |
615 | out: |
616 | gs->collect_md = geneve->collect_md; | |
8ed66f0e | 617 | #if IS_ENABLED(CONFIG_IPV6) |
4b4c21fa | 618 | if (ipv6) { |
fceb9c3e | 619 | rcu_assign_pointer(geneve->sock6, gs); |
4b4c21fa JB |
620 | node = &geneve->hlist6; |
621 | } else | |
8ed66f0e | 622 | #endif |
4b4c21fa | 623 | { |
fceb9c3e | 624 | rcu_assign_pointer(geneve->sock4, gs); |
4b4c21fa JB |
625 | node = &geneve->hlist4; |
626 | } | |
627 | node->geneve = geneve; | |
66d47003 | 628 | |
9b4437a5 | 629 | tunnel_id_to_vni(geneve->info.key.tun_id, vni); |
630 | hash = geneve_net_vni_hash(vni); | |
4b4c21fa | 631 | hlist_add_head_rcu(&node->hlist, &gs->vni_list[hash]); |
2d07dc79 JL |
632 | return 0; |
633 | } | |
634 | ||
8ed66f0e JL |
635 | static int geneve_open(struct net_device *dev) |
636 | { | |
637 | struct geneve_dev *geneve = netdev_priv(dev); | |
9b4437a5 | 638 | bool ipv6 = !!(geneve->info.mode & IP_TUNNEL_INFO_IPV6); |
8ed66f0e JL |
639 | bool metadata = geneve->collect_md; |
640 | int ret = 0; | |
641 | ||
8ed66f0e | 642 | #if IS_ENABLED(CONFIG_IPV6) |
8ed66f0e JL |
643 | if (ipv6 || metadata) |
644 | ret = geneve_sock_add(geneve, true); | |
645 | #endif | |
646 | if (!ret && (!ipv6 || metadata)) | |
647 | ret = geneve_sock_add(geneve, false); | |
648 | if (ret < 0) | |
649 | geneve_sock_release(geneve); | |
650 | ||
651 | return ret; | |
652 | } | |
653 | ||
2d07dc79 JL |
654 | static int geneve_stop(struct net_device *dev) |
655 | { | |
656 | struct geneve_dev *geneve = netdev_priv(dev); | |
2d07dc79 | 657 | |
4b4c21fa JB |
658 | hlist_del_init_rcu(&geneve->hlist4.hlist); |
659 | #if IS_ENABLED(CONFIG_IPV6) | |
660 | hlist_del_init_rcu(&geneve->hlist6.hlist); | |
661 | #endif | |
8ed66f0e | 662 | geneve_sock_release(geneve); |
371bd106 PS |
663 | return 0; |
664 | } | |
665 | ||
8ed66f0e | 666 | static void geneve_build_header(struct genevehdr *geneveh, |
c3ef5aa5 | 667 | const struct ip_tunnel_info *info) |
8ed66f0e JL |
668 | { |
669 | geneveh->ver = GENEVE_VER; | |
c3ef5aa5 | 670 | geneveh->opt_len = info->options_len / 4; |
671 | geneveh->oam = !!(info->key.tun_flags & TUNNEL_OAM); | |
672 | geneveh->critical = !!(info->key.tun_flags & TUNNEL_CRIT_OPT); | |
8ed66f0e | 673 | geneveh->rsvd1 = 0; |
c3ef5aa5 | 674 | tunnel_id_to_vni(info->key.tun_id, geneveh->vni); |
8ed66f0e JL |
675 | geneveh->proto_type = htons(ETH_P_TEB); |
676 | geneveh->rsvd2 = 0; | |
677 | ||
c3ef5aa5 | 678 | ip_tunnel_info_opts_get(geneveh->options, info); |
8ed66f0e JL |
679 | } |
680 | ||
c3ef5aa5 | 681 | static int geneve_build_skb(struct dst_entry *dst, struct sk_buff *skb, |
682 | const struct ip_tunnel_info *info, | |
683 | bool xnet, int ip_hdr_len) | |
371bd106 | 684 | { |
c3ef5aa5 | 685 | bool udp_sum = !!(info->key.tun_flags & TUNNEL_CSUM); |
8ed66f0e JL |
686 | struct genevehdr *gnvh; |
687 | int min_headroom; | |
688 | int err; | |
689 | ||
c3ef5aa5 | 690 | skb_reset_mac_header(skb); |
8ed66f0e JL |
691 | skb_scrub_packet(skb, xnet); |
692 | ||
c3ef5aa5 | 693 | min_headroom = LL_RESERVED_SPACE(dst->dev) + dst->header_len + |
694 | GENEVE_BASE_HLEN + info->options_len + ip_hdr_len; | |
8ed66f0e | 695 | err = skb_cow_head(skb, min_headroom); |
aed069df | 696 | if (unlikely(err)) |
8ed66f0e | 697 | goto free_dst; |
8ed66f0e | 698 | |
aed069df | 699 | err = udp_tunnel_handle_offloads(skb, udp_sum); |
1ba64fac | 700 | if (err) |
8ed66f0e | 701 | goto free_dst; |
8ed66f0e | 702 | |
d58ff351 | 703 | gnvh = __skb_push(skb, sizeof(*gnvh) + info->options_len); |
c3ef5aa5 | 704 | geneve_build_header(gnvh, info); |
8ed66f0e JL |
705 | skb_set_inner_protocol(skb, htons(ETH_P_TEB)); |
706 | return 0; | |
707 | ||
708 | free_dst: | |
709 | dst_release(dst); | |
710 | return err; | |
711 | } | |
8ed66f0e JL |
712 | |
713 | static struct rtable *geneve_get_v4_rt(struct sk_buff *skb, | |
714 | struct net_device *dev, | |
5b861f6b | 715 | struct geneve_sock *gs4, |
8ed66f0e | 716 | struct flowi4 *fl4, |
c3ef5aa5 | 717 | const struct ip_tunnel_info *info) |
e305ac6c | 718 | { |
db3c6139 | 719 | bool use_cache = ip_tunnel_dst_cache_usable(skb, info); |
e305ac6c | 720 | struct geneve_dev *geneve = netdev_priv(dev); |
468dfffc | 721 | struct dst_cache *dst_cache; |
e305ac6c PS |
722 | struct rtable *rt = NULL; |
723 | __u8 tos; | |
724 | ||
5b861f6b | 725 | if (!gs4) |
fceb9c3e | 726 | return ERR_PTR(-EIO); |
727 | ||
e305ac6c PS |
728 | memset(fl4, 0, sizeof(*fl4)); |
729 | fl4->flowi4_mark = skb->mark; | |
730 | fl4->flowi4_proto = IPPROTO_UDP; | |
9b4437a5 | 731 | fl4->daddr = info->key.u.ipv4.dst; |
732 | fl4->saddr = info->key.u.ipv4.src; | |
e305ac6c | 733 | |
9b4437a5 | 734 | tos = info->key.tos; |
735 | if ((tos == 1) && !geneve->collect_md) { | |
736 | tos = ip_tunnel_get_dsfield(ip_hdr(skb), skb); | |
737 | use_cache = false; | |
468dfffc | 738 | } |
9b4437a5 | 739 | fl4->flowi4_tos = RT_TOS(tos); |
468dfffc | 740 | |
c3ef5aa5 | 741 | dst_cache = (struct dst_cache *)&info->dst_cache; |
468dfffc PA |
742 | if (use_cache) { |
743 | rt = dst_cache_get_ip4(dst_cache, &fl4->saddr); | |
744 | if (rt) | |
745 | return rt; | |
e305ac6c | 746 | } |
e305ac6c PS |
747 | rt = ip_route_output_key(geneve->net, fl4); |
748 | if (IS_ERR(rt)) { | |
749 | netdev_dbg(dev, "no route to %pI4\n", &fl4->daddr); | |
fc4099f1 | 750 | return ERR_PTR(-ENETUNREACH); |
e305ac6c PS |
751 | } |
752 | if (rt->dst.dev == dev) { /* is this necessary? */ | |
753 | netdev_dbg(dev, "circular route to %pI4\n", &fl4->daddr); | |
e305ac6c | 754 | ip_rt_put(rt); |
fc4099f1 | 755 | return ERR_PTR(-ELOOP); |
e305ac6c | 756 | } |
468dfffc PA |
757 | if (use_cache) |
758 | dst_cache_set_ip4(dst_cache, &rt->dst, fl4->saddr); | |
e305ac6c PS |
759 | return rt; |
760 | } | |
761 | ||
8ed66f0e JL |
762 | #if IS_ENABLED(CONFIG_IPV6) |
763 | static struct dst_entry *geneve_get_v6_dst(struct sk_buff *skb, | |
764 | struct net_device *dev, | |
5b861f6b | 765 | struct geneve_sock *gs6, |
8ed66f0e | 766 | struct flowi6 *fl6, |
c3ef5aa5 | 767 | const struct ip_tunnel_info *info) |
8ed66f0e | 768 | { |
db3c6139 | 769 | bool use_cache = ip_tunnel_dst_cache_usable(skb, info); |
8ed66f0e | 770 | struct geneve_dev *geneve = netdev_priv(dev); |
8ed66f0e | 771 | struct dst_entry *dst = NULL; |
468dfffc | 772 | struct dst_cache *dst_cache; |
3a56f86f | 773 | __u8 prio; |
8ed66f0e | 774 | |
fceb9c3e | 775 | if (!gs6) |
776 | return ERR_PTR(-EIO); | |
777 | ||
8ed66f0e JL |
778 | memset(fl6, 0, sizeof(*fl6)); |
779 | fl6->flowi6_mark = skb->mark; | |
780 | fl6->flowi6_proto = IPPROTO_UDP; | |
9b4437a5 | 781 | fl6->daddr = info->key.u.ipv6.dst; |
782 | fl6->saddr = info->key.u.ipv6.src; | |
783 | prio = info->key.tos; | |
784 | if ((prio == 1) && !geneve->collect_md) { | |
785 | prio = ip_tunnel_get_dsfield(ip_hdr(skb), skb); | |
786 | use_cache = false; | |
468dfffc PA |
787 | } |
788 | ||
9b4437a5 | 789 | fl6->flowlabel = ip6_make_flowinfo(RT_TOS(prio), |
790 | info->key.label); | |
c3ef5aa5 | 791 | dst_cache = (struct dst_cache *)&info->dst_cache; |
468dfffc PA |
792 | if (use_cache) { |
793 | dst = dst_cache_get_ip6(dst_cache, &fl6->saddr); | |
794 | if (dst) | |
795 | return dst; | |
8ed66f0e | 796 | } |
8ed66f0e JL |
797 | if (ipv6_stub->ipv6_dst_lookup(geneve->net, gs6->sock->sk, &dst, fl6)) { |
798 | netdev_dbg(dev, "no route to %pI6\n", &fl6->daddr); | |
799 | return ERR_PTR(-ENETUNREACH); | |
800 | } | |
801 | if (dst->dev == dev) { /* is this necessary? */ | |
802 | netdev_dbg(dev, "circular route to %pI6\n", &fl6->daddr); | |
803 | dst_release(dst); | |
804 | return ERR_PTR(-ELOOP); | |
805 | } | |
806 | ||
468dfffc PA |
807 | if (use_cache) |
808 | dst_cache_set_ip6(dst_cache, dst, &fl6->saddr); | |
8ed66f0e JL |
809 | return dst; |
810 | } | |
811 | #endif | |
812 | ||
9b4437a5 | 813 | static int geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev, |
c3ef5aa5 | 814 | struct geneve_dev *geneve, |
815 | const struct ip_tunnel_info *info) | |
2d07dc79 | 816 | { |
9b4437a5 | 817 | bool xnet = !net_eq(geneve->net, dev_net(geneve->dev)); |
818 | struct geneve_sock *gs4 = rcu_dereference(geneve->sock4); | |
819 | const struct ip_tunnel_key *key = &info->key; | |
820 | struct rtable *rt; | |
2d07dc79 | 821 | struct flowi4 fl4; |
8760ce58 | 822 | __u8 tos, ttl; |
e305ac6c | 823 | __be16 sport; |
371bd106 | 824 | __be16 df; |
bcceeec3 | 825 | int err; |
980c394c | 826 | |
5b861f6b | 827 | rt = geneve_get_v4_rt(skb, dev, gs4, &fl4, info); |
9b4437a5 | 828 | if (IS_ERR(rt)) |
829 | return PTR_ERR(rt); | |
371bd106 | 830 | |
52a589d5 | 831 | if (skb_dst(skb)) { |
5edbea69 AK |
832 | int mtu = dst_mtu(&rt->dst) - GENEVE_IPV4_HLEN - |
833 | info->options_len; | |
52a589d5 | 834 | |
f15ca723 | 835 | skb_dst_update_pmtu(skb, mtu); |
52a589d5 XL |
836 | } |
837 | ||
371bd106 | 838 | sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true); |
9b4437a5 | 839 | if (geneve->collect_md) { |
840 | tos = ip_tunnel_ecn_encap(key->tos, ip_hdr(skb), skb); | |
371bd106 | 841 | ttl = key->ttl; |
e305ac6c | 842 | } else { |
9b4437a5 | 843 | tos = ip_tunnel_ecn_encap(fl4.flowi4_tos, ip_hdr(skb), skb); |
844 | ttl = key->ttl ? : ip4_dst_hoplimit(&rt->dst); | |
2d07dc79 | 845 | } |
9b4437a5 | 846 | df = key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0; |
2d07dc79 | 847 | |
c3ef5aa5 | 848 | err = geneve_build_skb(&rt->dst, skb, info, xnet, sizeof(struct iphdr)); |
9b4437a5 | 849 | if (unlikely(err)) |
850 | return err; | |
efeb2267 | 851 | |
9b4437a5 | 852 | udp_tunnel_xmit_skb(rt, gs4->sock->sk, skb, fl4.saddr, fl4.daddr, |
853 | tos, ttl, df, sport, geneve->info.key.tp_dst, | |
854 | !net_eq(geneve->net, dev_net(geneve->dev)), | |
855 | !(info->key.tun_flags & TUNNEL_CSUM)); | |
856 | return 0; | |
2d07dc79 JL |
857 | } |
858 | ||
8ed66f0e | 859 | #if IS_ENABLED(CONFIG_IPV6) |
9b4437a5 | 860 | static int geneve6_xmit_skb(struct sk_buff *skb, struct net_device *dev, |
c3ef5aa5 | 861 | struct geneve_dev *geneve, |
862 | const struct ip_tunnel_info *info) | |
8ed66f0e | 863 | { |
9b4437a5 | 864 | bool xnet = !net_eq(geneve->net, dev_net(geneve->dev)); |
865 | struct geneve_sock *gs6 = rcu_dereference(geneve->sock6); | |
866 | const struct ip_tunnel_key *key = &info->key; | |
8ed66f0e | 867 | struct dst_entry *dst = NULL; |
8ed66f0e | 868 | struct flowi6 fl6; |
3a56f86f | 869 | __u8 prio, ttl; |
8ed66f0e | 870 | __be16 sport; |
bcceeec3 | 871 | int err; |
8ed66f0e | 872 | |
5b861f6b | 873 | dst = geneve_get_v6_dst(skb, dev, gs6, &fl6, info); |
9b4437a5 | 874 | if (IS_ERR(dst)) |
875 | return PTR_ERR(dst); | |
8ed66f0e | 876 | |
52a589d5 | 877 | if (skb_dst(skb)) { |
5edbea69 | 878 | int mtu = dst_mtu(dst) - GENEVE_IPV6_HLEN - info->options_len; |
52a589d5 | 879 | |
f15ca723 | 880 | skb_dst_update_pmtu(skb, mtu); |
52a589d5 XL |
881 | } |
882 | ||
8ed66f0e | 883 | sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true); |
9b4437a5 | 884 | if (geneve->collect_md) { |
885 | prio = ip_tunnel_ecn_encap(key->tos, ip_hdr(skb), skb); | |
886 | ttl = key->ttl; | |
887 | } else { | |
888 | prio = ip_tunnel_ecn_encap(ip6_tclass(fl6.flowlabel), | |
889 | ip_hdr(skb), skb); | |
890 | ttl = key->ttl ? : ip6_dst_hoplimit(dst); | |
891 | } | |
31ac1c19 | 892 | err = geneve_build_skb(dst, skb, info, xnet, sizeof(struct ipv6hdr)); |
9b4437a5 | 893 | if (unlikely(err)) |
894 | return err; | |
8ed66f0e | 895 | |
9b4437a5 | 896 | udp_tunnel6_xmit_skb(dst, gs6->sock->sk, skb, dev, |
897 | &fl6.saddr, &fl6.daddr, prio, ttl, | |
898 | info->key.label, sport, geneve->info.key.tp_dst, | |
899 | !(info->key.tun_flags & TUNNEL_CSUM)); | |
900 | return 0; | |
901 | } | |
902 | #endif | |
8ed66f0e | 903 | |
9b4437a5 | 904 | static netdev_tx_t geneve_xmit(struct sk_buff *skb, struct net_device *dev) |
905 | { | |
906 | struct geneve_dev *geneve = netdev_priv(dev); | |
907 | struct ip_tunnel_info *info = NULL; | |
908 | int err; | |
abe492b4 | 909 | |
9b4437a5 | 910 | if (geneve->collect_md) { |
911 | info = skb_tunnel_info(skb); | |
912 | if (unlikely(!info || !(info->mode & IP_TUNNEL_INFO_TX))) { | |
913 | err = -EINVAL; | |
914 | netdev_dbg(dev, "no tunnel metadata\n"); | |
aed069df | 915 | goto tx_error; |
9b4437a5 | 916 | } |
8ed66f0e | 917 | } else { |
9b4437a5 | 918 | info = &geneve->info; |
8ed66f0e | 919 | } |
8eb3b995 | 920 | |
a717e3f7 | 921 | rcu_read_lock(); |
9b4437a5 | 922 | #if IS_ENABLED(CONFIG_IPV6) |
923 | if (info->mode & IP_TUNNEL_INFO_IPV6) | |
924 | err = geneve6_xmit_skb(skb, dev, geneve, info); | |
925 | else | |
926 | #endif | |
927 | err = geneve_xmit_skb(skb, dev, geneve, info); | |
a717e3f7 | 928 | rcu_read_unlock(); |
8ed66f0e | 929 | |
9b4437a5 | 930 | if (likely(!err)) |
931 | return NETDEV_TX_OK; | |
8ed66f0e JL |
932 | tx_error: |
933 | dev_kfree_skb(skb); | |
aed069df | 934 | |
8ed66f0e JL |
935 | if (err == -ELOOP) |
936 | dev->stats.collisions++; | |
937 | else if (err == -ENETUNREACH) | |
938 | dev->stats.tx_carrier_errors++; | |
efeb2267 HY |
939 | |
940 | dev->stats.tx_errors++; | |
8ed66f0e JL |
941 | return NETDEV_TX_OK; |
942 | } | |
8ed66f0e | 943 | |
91572088 | 944 | static int geneve_change_mtu(struct net_device *dev, int new_mtu) |
55e5bfb5 | 945 | { |
91572088 JW |
946 | if (new_mtu > dev->max_mtu) |
947 | new_mtu = dev->max_mtu; | |
321acc1c AK |
948 | else if (new_mtu < dev->min_mtu) |
949 | new_mtu = dev->min_mtu; | |
aeee0e66 | 950 | |
55e5bfb5 DW |
951 | dev->mtu = new_mtu; |
952 | return 0; | |
953 | } | |
954 | ||
fc4099f1 PS |
955 | static int geneve_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb) |
956 | { | |
957 | struct ip_tunnel_info *info = skb_tunnel_info(skb); | |
958 | struct geneve_dev *geneve = netdev_priv(dev); | |
fc4099f1 | 959 | |
b8812fa8 | 960 | if (ip_tunnel_info_af(info) == AF_INET) { |
9b4437a5 | 961 | struct rtable *rt; |
962 | struct flowi4 fl4; | |
5b861f6b | 963 | struct geneve_sock *gs4 = rcu_dereference(geneve->sock4); |
9b4437a5 | 964 | |
5b861f6b | 965 | rt = geneve_get_v4_rt(skb, dev, gs4, &fl4, info); |
b8812fa8 JL |
966 | if (IS_ERR(rt)) |
967 | return PTR_ERR(rt); | |
fc4099f1 | 968 | |
b8812fa8 JL |
969 | ip_rt_put(rt); |
970 | info->key.u.ipv4.src = fl4.saddr; | |
971 | #if IS_ENABLED(CONFIG_IPV6) | |
972 | } else if (ip_tunnel_info_af(info) == AF_INET6) { | |
9b4437a5 | 973 | struct dst_entry *dst; |
974 | struct flowi6 fl6; | |
5b861f6b | 975 | struct geneve_sock *gs6 = rcu_dereference(geneve->sock6); |
9b4437a5 | 976 | |
5b861f6b | 977 | dst = geneve_get_v6_dst(skb, dev, gs6, &fl6, info); |
b8812fa8 JL |
978 | if (IS_ERR(dst)) |
979 | return PTR_ERR(dst); | |
980 | ||
981 | dst_release(dst); | |
982 | info->key.u.ipv6.src = fl6.saddr; | |
983 | #endif | |
984 | } else { | |
985 | return -EINVAL; | |
986 | } | |
fc4099f1 | 987 | |
fc4099f1 PS |
988 | info->key.tp_src = udp_flow_src_port(geneve->net, skb, |
989 | 1, USHRT_MAX, true); | |
9b4437a5 | 990 | info->key.tp_dst = geneve->info.key.tp_dst; |
fc4099f1 PS |
991 | return 0; |
992 | } | |
993 | ||
2d07dc79 JL |
994 | static const struct net_device_ops geneve_netdev_ops = { |
995 | .ndo_init = geneve_init, | |
996 | .ndo_uninit = geneve_uninit, | |
997 | .ndo_open = geneve_open, | |
998 | .ndo_stop = geneve_stop, | |
999 | .ndo_start_xmit = geneve_xmit, | |
1000 | .ndo_get_stats64 = ip_tunnel_get_stats64, | |
55e5bfb5 | 1001 | .ndo_change_mtu = geneve_change_mtu, |
2d07dc79 JL |
1002 | .ndo_validate_addr = eth_validate_addr, |
1003 | .ndo_set_mac_address = eth_mac_addr, | |
fc4099f1 | 1004 | .ndo_fill_metadata_dst = geneve_fill_metadata_dst, |
2d07dc79 JL |
1005 | }; |
1006 | ||
1007 | static void geneve_get_drvinfo(struct net_device *dev, | |
1008 | struct ethtool_drvinfo *drvinfo) | |
1009 | { | |
1010 | strlcpy(drvinfo->version, GENEVE_NETDEV_VER, sizeof(drvinfo->version)); | |
1011 | strlcpy(drvinfo->driver, "geneve", sizeof(drvinfo->driver)); | |
1012 | } | |
1013 | ||
1014 | static const struct ethtool_ops geneve_ethtool_ops = { | |
1015 | .get_drvinfo = geneve_get_drvinfo, | |
1016 | .get_link = ethtool_op_get_link, | |
1017 | }; | |
1018 | ||
1019 | /* Info for udev, that this is a virtual tunnel endpoint */ | |
1020 | static struct device_type geneve_type = { | |
1021 | .name = "geneve", | |
1022 | }; | |
1023 | ||
e5de25dc | 1024 | /* Calls the ndo_udp_tunnel_add of the caller in order to |
05ca4029 | 1025 | * supply the listening GENEVE udp ports. Callers are expected |
e5de25dc | 1026 | * to implement the ndo_udp_tunnel_add. |
05ca4029 | 1027 | */ |
2d2b13fc | 1028 | static void geneve_offload_rx_ports(struct net_device *dev, bool push) |
05ca4029 SA |
1029 | { |
1030 | struct net *net = dev_net(dev); | |
1031 | struct geneve_net *gn = net_generic(net, geneve_net_id); | |
1032 | struct geneve_sock *gs; | |
681e683f | 1033 | |
05ca4029 | 1034 | rcu_read_lock(); |
2d2b13fc SD |
1035 | list_for_each_entry_rcu(gs, &gn->sock_list, list) { |
1036 | if (push) { | |
1037 | udp_tunnel_push_rx_port(dev, gs->sock, | |
1038 | UDP_TUNNEL_TYPE_GENEVE); | |
1039 | } else { | |
1040 | udp_tunnel_drop_rx_port(dev, gs->sock, | |
1041 | UDP_TUNNEL_TYPE_GENEVE); | |
1042 | } | |
1043 | } | |
05ca4029 SA |
1044 | rcu_read_unlock(); |
1045 | } | |
05ca4029 | 1046 | |
2d07dc79 JL |
1047 | /* Initialize the device structure. */ |
1048 | static void geneve_setup(struct net_device *dev) | |
1049 | { | |
1050 | ether_setup(dev); | |
1051 | ||
1052 | dev->netdev_ops = &geneve_netdev_ops; | |
1053 | dev->ethtool_ops = &geneve_ethtool_ops; | |
cf124db5 | 1054 | dev->needs_free_netdev = true; |
2d07dc79 JL |
1055 | |
1056 | SET_NETDEV_DEVTYPE(dev, &geneve_type); | |
1057 | ||
2d07dc79 JL |
1058 | dev->features |= NETIF_F_LLTX; |
1059 | dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM; | |
1060 | dev->features |= NETIF_F_RXCSUM; | |
1061 | dev->features |= NETIF_F_GSO_SOFTWARE; | |
1062 | ||
2d07dc79 JL |
1063 | dev->hw_features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_RXCSUM; |
1064 | dev->hw_features |= NETIF_F_GSO_SOFTWARE; | |
2d07dc79 | 1065 | |
91572088 JW |
1066 | /* MTU range: 68 - (something less than 65535) */ |
1067 | dev->min_mtu = ETH_MIN_MTU; | |
1068 | /* The max_mtu calculation does not take account of GENEVE | |
1069 | * options, to avoid excluding potentially valid | |
1070 | * configurations. This will be further reduced by IPvX hdr size. | |
1071 | */ | |
1072 | dev->max_mtu = IP_MAX_MTU - GENEVE_BASE_HLEN - dev->hard_header_len; | |
1073 | ||
2d07dc79 | 1074 | netif_keep_dst(dev); |
fc41cdb3 | 1075 | dev->priv_flags &= ~IFF_TX_SKB_SHARING; |
ed961ac2 | 1076 | dev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_NO_QUEUE; |
87cd3dca | 1077 | eth_hw_addr_random(dev); |
2d07dc79 JL |
1078 | } |
1079 | ||
1080 | static const struct nla_policy geneve_policy[IFLA_GENEVE_MAX + 1] = { | |
1081 | [IFLA_GENEVE_ID] = { .type = NLA_U32 }, | |
1082 | [IFLA_GENEVE_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) }, | |
8ed66f0e | 1083 | [IFLA_GENEVE_REMOTE6] = { .len = sizeof(struct in6_addr) }, |
8760ce58 | 1084 | [IFLA_GENEVE_TTL] = { .type = NLA_U8 }, |
d8951125 | 1085 | [IFLA_GENEVE_TOS] = { .type = NLA_U8 }, |
8eb3b995 | 1086 | [IFLA_GENEVE_LABEL] = { .type = NLA_U32 }, |
cd7918b3 | 1087 | [IFLA_GENEVE_PORT] = { .type = NLA_U16 }, |
e305ac6c | 1088 | [IFLA_GENEVE_COLLECT_METADATA] = { .type = NLA_FLAG }, |
abe492b4 TH |
1089 | [IFLA_GENEVE_UDP_CSUM] = { .type = NLA_U8 }, |
1090 | [IFLA_GENEVE_UDP_ZERO_CSUM6_TX] = { .type = NLA_U8 }, | |
1091 | [IFLA_GENEVE_UDP_ZERO_CSUM6_RX] = { .type = NLA_U8 }, | |
2d07dc79 JL |
1092 | }; |
1093 | ||
a8b8a889 MS |
1094 | static int geneve_validate(struct nlattr *tb[], struct nlattr *data[], |
1095 | struct netlink_ext_ack *extack) | |
2d07dc79 JL |
1096 | { |
1097 | if (tb[IFLA_ADDRESS]) { | |
c5ebc440 GM |
1098 | if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) { |
1099 | NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_ADDRESS], | |
1100 | "Provided link layer address is not Ethernet"); | |
2d07dc79 | 1101 | return -EINVAL; |
c5ebc440 | 1102 | } |
2d07dc79 | 1103 | |
c5ebc440 GM |
1104 | if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) { |
1105 | NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_ADDRESS], | |
1106 | "Provided Ethernet address is not unicast"); | |
2d07dc79 | 1107 | return -EADDRNOTAVAIL; |
c5ebc440 | 1108 | } |
2d07dc79 JL |
1109 | } |
1110 | ||
c5ebc440 GM |
1111 | if (!data) { |
1112 | NL_SET_ERR_MSG(extack, | |
1113 | "Not enough attributes provided to perform the operation"); | |
2d07dc79 | 1114 | return -EINVAL; |
c5ebc440 | 1115 | } |
2d07dc79 JL |
1116 | |
1117 | if (data[IFLA_GENEVE_ID]) { | |
1118 | __u32 vni = nla_get_u32(data[IFLA_GENEVE_ID]); | |
1119 | ||
c5ebc440 GM |
1120 | if (vni >= GENEVE_N_VID) { |
1121 | NL_SET_ERR_MSG_ATTR(extack, data[IFLA_GENEVE_ID], | |
1122 | "Geneve ID must be lower than 16777216"); | |
2d07dc79 | 1123 | return -ERANGE; |
c5ebc440 | 1124 | } |
2d07dc79 JL |
1125 | } |
1126 | ||
1127 | return 0; | |
1128 | } | |
1129 | ||
371bd106 | 1130 | static struct geneve_dev *geneve_find_dev(struct geneve_net *gn, |
9b4437a5 | 1131 | const struct ip_tunnel_info *info, |
371bd106 PS |
1132 | bool *tun_on_same_port, |
1133 | bool *tun_collect_md) | |
1134 | { | |
9b4437a5 | 1135 | struct geneve_dev *geneve, *t = NULL; |
371bd106 PS |
1136 | |
1137 | *tun_on_same_port = false; | |
1138 | *tun_collect_md = false; | |
371bd106 | 1139 | list_for_each_entry(geneve, &gn->geneve_list, next) { |
9b4437a5 | 1140 | if (info->key.tp_dst == geneve->info.key.tp_dst) { |
371bd106 PS |
1141 | *tun_collect_md = geneve->collect_md; |
1142 | *tun_on_same_port = true; | |
1143 | } | |
9b4437a5 | 1144 | if (info->key.tun_id == geneve->info.key.tun_id && |
1145 | info->key.tp_dst == geneve->info.key.tp_dst && | |
1146 | !memcmp(&info->key.u, &geneve->info.key.u, sizeof(info->key.u))) | |
371bd106 PS |
1147 | t = geneve; |
1148 | } | |
1149 | return t; | |
1150 | } | |
1151 | ||
9b4437a5 | 1152 | static bool is_tnl_info_zero(const struct ip_tunnel_info *info) |
1153 | { | |
3fa5f11d SB |
1154 | return !(info->key.tun_id || info->key.tun_flags || info->key.tos || |
1155 | info->key.ttl || info->key.label || info->key.tp_src || | |
1156 | memchr_inv(&info->key.u, 0, sizeof(info->key.u))); | |
9b4437a5 | 1157 | } |
1158 | ||
5b861f6b GM |
1159 | static bool geneve_dst_addr_equal(struct ip_tunnel_info *a, |
1160 | struct ip_tunnel_info *b) | |
1161 | { | |
1162 | if (ip_tunnel_info_af(a) == AF_INET) | |
1163 | return a->key.u.ipv4.dst == b->key.u.ipv4.dst; | |
1164 | else | |
1165 | return ipv6_addr_equal(&a->key.u.ipv6.dst, &b->key.u.ipv6.dst); | |
1166 | } | |
1167 | ||
e305ac6c | 1168 | static int geneve_configure(struct net *net, struct net_device *dev, |
c5ebc440 | 1169 | struct netlink_ext_ack *extack, |
9b4437a5 | 1170 | const struct ip_tunnel_info *info, |
1171 | bool metadata, bool ipv6_rx_csum) | |
2d07dc79 JL |
1172 | { |
1173 | struct geneve_net *gn = net_generic(net, geneve_net_id); | |
371bd106 PS |
1174 | struct geneve_dev *t, *geneve = netdev_priv(dev); |
1175 | bool tun_collect_md, tun_on_same_port; | |
184fc8b5 | 1176 | int err, encap_len; |
2d07dc79 | 1177 | |
c5ebc440 GM |
1178 | if (metadata && !is_tnl_info_zero(info)) { |
1179 | NL_SET_ERR_MSG(extack, | |
1180 | "Device is externally controlled, so attributes (VNI, Port, and so on) must not be specified"); | |
8ed66f0e | 1181 | return -EINVAL; |
c5ebc440 | 1182 | } |
2d07dc79 JL |
1183 | |
1184 | geneve->net = net; | |
1185 | geneve->dev = dev; | |
1186 | ||
9b4437a5 | 1187 | t = geneve_find_dev(gn, info, &tun_on_same_port, &tun_collect_md); |
371bd106 PS |
1188 | if (t) |
1189 | return -EBUSY; | |
1190 | ||
184fc8b5 PA |
1191 | /* make enough headroom for basic scenario */ |
1192 | encap_len = GENEVE_BASE_HLEN + ETH_HLEN; | |
9a1c44d9 | 1193 | if (!metadata && ip_tunnel_info_af(info) == AF_INET) { |
184fc8b5 | 1194 | encap_len += sizeof(struct iphdr); |
91572088 JW |
1195 | dev->max_mtu -= sizeof(struct iphdr); |
1196 | } else { | |
184fc8b5 | 1197 | encap_len += sizeof(struct ipv6hdr); |
91572088 JW |
1198 | dev->max_mtu -= sizeof(struct ipv6hdr); |
1199 | } | |
184fc8b5 PA |
1200 | dev->needed_headroom = encap_len + ETH_HLEN; |
1201 | ||
371bd106 | 1202 | if (metadata) { |
c5ebc440 GM |
1203 | if (tun_on_same_port) { |
1204 | NL_SET_ERR_MSG(extack, | |
1205 | "There can be only one externally controlled device on a destination port"); | |
371bd106 | 1206 | return -EPERM; |
c5ebc440 | 1207 | } |
371bd106 | 1208 | } else { |
c5ebc440 GM |
1209 | if (tun_collect_md) { |
1210 | NL_SET_ERR_MSG(extack, | |
1211 | "There already exists an externally controlled device on this destination port"); | |
371bd106 | 1212 | return -EPERM; |
c5ebc440 | 1213 | } |
371bd106 PS |
1214 | } |
1215 | ||
9b4437a5 | 1216 | dst_cache_reset(&geneve->info.dst_cache); |
1217 | geneve->info = *info; | |
1218 | geneve->collect_md = metadata; | |
1219 | geneve->use_udp6_rx_checksums = ipv6_rx_csum; | |
468dfffc | 1220 | |
2d07dc79 JL |
1221 | err = register_netdevice(dev); |
1222 | if (err) | |
1223 | return err; | |
1224 | ||
e305ac6c | 1225 | list_add(&geneve->next, &gn->geneve_list); |
e305ac6c PS |
1226 | return 0; |
1227 | } | |
1228 | ||
9b4437a5 | 1229 | static void init_tnl_info(struct ip_tunnel_info *info, __u16 dst_port) |
1230 | { | |
1231 | memset(info, 0, sizeof(*info)); | |
1232 | info->key.tp_dst = htons(dst_port); | |
1233 | } | |
1234 | ||
c5ebc440 GM |
1235 | static int geneve_nl2info(struct nlattr *tb[], struct nlattr *data[], |
1236 | struct netlink_ext_ack *extack, | |
1237 | struct ip_tunnel_info *info, bool *metadata, | |
1238 | bool *use_udp6_rx_checksums, bool changelink) | |
e305ac6c | 1239 | { |
c5ebc440 GM |
1240 | int attrtype; |
1241 | ||
1242 | if (data[IFLA_GENEVE_REMOTE] && data[IFLA_GENEVE_REMOTE6]) { | |
1243 | NL_SET_ERR_MSG(extack, | |
1244 | "Cannot specify both IPv4 and IPv6 Remote addresses"); | |
8ed66f0e | 1245 | return -EINVAL; |
c5ebc440 | 1246 | } |
8ed66f0e JL |
1247 | |
1248 | if (data[IFLA_GENEVE_REMOTE]) { | |
c5ebc440 GM |
1249 | if (changelink && (ip_tunnel_info_af(info) == AF_INET6)) { |
1250 | attrtype = IFLA_GENEVE_REMOTE; | |
1251 | goto change_notsup; | |
1252 | } | |
5b861f6b GM |
1253 | |
1254 | info->key.u.ipv4.dst = | |
8ed66f0e | 1255 | nla_get_in_addr(data[IFLA_GENEVE_REMOTE]); |
9b4437a5 | 1256 | |
5b861f6b | 1257 | if (IN_MULTICAST(ntohl(info->key.u.ipv4.dst))) { |
c5ebc440 GM |
1258 | NL_SET_ERR_MSG_ATTR(extack, data[IFLA_GENEVE_REMOTE], |
1259 | "Remote IPv4 address cannot be Multicast"); | |
9b4437a5 | 1260 | return -EINVAL; |
1261 | } | |
8ed66f0e JL |
1262 | } |
1263 | ||
1264 | if (data[IFLA_GENEVE_REMOTE6]) { | |
4c52a889 | 1265 | #if IS_ENABLED(CONFIG_IPV6) |
c5ebc440 GM |
1266 | if (changelink && (ip_tunnel_info_af(info) == AF_INET)) { |
1267 | attrtype = IFLA_GENEVE_REMOTE6; | |
1268 | goto change_notsup; | |
1269 | } | |
5b861f6b GM |
1270 | |
1271 | info->mode = IP_TUNNEL_INFO_IPV6; | |
1272 | info->key.u.ipv6.dst = | |
8ed66f0e JL |
1273 | nla_get_in6_addr(data[IFLA_GENEVE_REMOTE6]); |
1274 | ||
5b861f6b | 1275 | if (ipv6_addr_type(&info->key.u.ipv6.dst) & |
8ed66f0e | 1276 | IPV6_ADDR_LINKLOCAL) { |
c5ebc440 GM |
1277 | NL_SET_ERR_MSG_ATTR(extack, data[IFLA_GENEVE_REMOTE6], |
1278 | "Remote IPv6 address cannot be link-local"); | |
8ed66f0e JL |
1279 | return -EINVAL; |
1280 | } | |
5b861f6b | 1281 | if (ipv6_addr_is_multicast(&info->key.u.ipv6.dst)) { |
c5ebc440 GM |
1282 | NL_SET_ERR_MSG_ATTR(extack, data[IFLA_GENEVE_REMOTE6], |
1283 | "Remote IPv6 address cannot be Multicast"); | |
9b4437a5 | 1284 | return -EINVAL; |
1285 | } | |
5b861f6b GM |
1286 | info->key.tun_flags |= TUNNEL_CSUM; |
1287 | *use_udp6_rx_checksums = true; | |
9b4437a5 | 1288 | #else |
c5ebc440 GM |
1289 | NL_SET_ERR_MSG_ATTR(extack, data[IFLA_GENEVE_REMOTE6], |
1290 | "IPv6 support not enabled in the kernel"); | |
9b4437a5 | 1291 | return -EPFNOSUPPORT; |
1292 | #endif | |
8ed66f0e JL |
1293 | } |
1294 | ||
9b4437a5 | 1295 | if (data[IFLA_GENEVE_ID]) { |
1296 | __u32 vni; | |
1297 | __u8 tvni[3]; | |
5b861f6b | 1298 | __be64 tunid; |
9b4437a5 | 1299 | |
e277de5f | 1300 | vni = nla_get_u32(data[IFLA_GENEVE_ID]); |
9b4437a5 | 1301 | tvni[0] = (vni & 0x00ff0000) >> 16; |
1302 | tvni[1] = (vni & 0x0000ff00) >> 8; | |
1303 | tvni[2] = vni & 0x000000ff; | |
e305ac6c | 1304 | |
5b861f6b | 1305 | tunid = vni_to_tunnel_id(tvni); |
c5ebc440 GM |
1306 | if (changelink && (tunid != info->key.tun_id)) { |
1307 | attrtype = IFLA_GENEVE_ID; | |
1308 | goto change_notsup; | |
1309 | } | |
5b861f6b | 1310 | info->key.tun_id = tunid; |
9b4437a5 | 1311 | } |
5b861f6b | 1312 | |
8760ce58 | 1313 | if (data[IFLA_GENEVE_TTL]) |
5b861f6b | 1314 | info->key.ttl = nla_get_u8(data[IFLA_GENEVE_TTL]); |
8760ce58 | 1315 | |
d8951125 | 1316 | if (data[IFLA_GENEVE_TOS]) |
5b861f6b | 1317 | info->key.tos = nla_get_u8(data[IFLA_GENEVE_TOS]); |
d8951125 | 1318 | |
9b4437a5 | 1319 | if (data[IFLA_GENEVE_LABEL]) { |
5b861f6b | 1320 | info->key.label = nla_get_be32(data[IFLA_GENEVE_LABEL]) & |
9b4437a5 | 1321 | IPV6_FLOWLABEL_MASK; |
c5ebc440 GM |
1322 | if (info->key.label && (!(info->mode & IP_TUNNEL_INFO_IPV6))) { |
1323 | NL_SET_ERR_MSG_ATTR(extack, data[IFLA_GENEVE_LABEL], | |
1324 | "Label attribute only applies for IPv6 Geneve devices"); | |
9b4437a5 | 1325 | return -EINVAL; |
c5ebc440 | 1326 | } |
9b4437a5 | 1327 | } |
8eb3b995 | 1328 | |
5b861f6b | 1329 | if (data[IFLA_GENEVE_PORT]) { |
c5ebc440 GM |
1330 | if (changelink) { |
1331 | attrtype = IFLA_GENEVE_PORT; | |
1332 | goto change_notsup; | |
1333 | } | |
5b861f6b GM |
1334 | info->key.tp_dst = nla_get_be16(data[IFLA_GENEVE_PORT]); |
1335 | } | |
2d07dc79 | 1336 | |
5b861f6b | 1337 | if (data[IFLA_GENEVE_COLLECT_METADATA]) { |
c5ebc440 GM |
1338 | if (changelink) { |
1339 | attrtype = IFLA_GENEVE_COLLECT_METADATA; | |
1340 | goto change_notsup; | |
1341 | } | |
5b861f6b GM |
1342 | *metadata = true; |
1343 | } | |
2d07dc79 | 1344 | |
5b861f6b | 1345 | if (data[IFLA_GENEVE_UDP_CSUM]) { |
c5ebc440 GM |
1346 | if (changelink) { |
1347 | attrtype = IFLA_GENEVE_UDP_CSUM; | |
1348 | goto change_notsup; | |
1349 | } | |
5b861f6b GM |
1350 | if (nla_get_u8(data[IFLA_GENEVE_UDP_CSUM])) |
1351 | info->key.tun_flags |= TUNNEL_CSUM; | |
1352 | } | |
abe492b4 | 1353 | |
5b861f6b | 1354 | if (data[IFLA_GENEVE_UDP_ZERO_CSUM6_TX]) { |
f9094b76 | 1355 | #if IS_ENABLED(CONFIG_IPV6) |
c5ebc440 GM |
1356 | if (changelink) { |
1357 | attrtype = IFLA_GENEVE_UDP_ZERO_CSUM6_TX; | |
1358 | goto change_notsup; | |
1359 | } | |
5b861f6b GM |
1360 | if (nla_get_u8(data[IFLA_GENEVE_UDP_ZERO_CSUM6_TX])) |
1361 | info->key.tun_flags &= ~TUNNEL_CSUM; | |
f9094b76 HL |
1362 | #else |
1363 | NL_SET_ERR_MSG_ATTR(extack, data[IFLA_GENEVE_UDP_ZERO_CSUM6_TX], | |
1364 | "IPv6 support not enabled in the kernel"); | |
1365 | return -EPFNOSUPPORT; | |
1366 | #endif | |
5b861f6b | 1367 | } |
abe492b4 | 1368 | |
5b861f6b | 1369 | if (data[IFLA_GENEVE_UDP_ZERO_CSUM6_RX]) { |
f9094b76 | 1370 | #if IS_ENABLED(CONFIG_IPV6) |
c5ebc440 GM |
1371 | if (changelink) { |
1372 | attrtype = IFLA_GENEVE_UDP_ZERO_CSUM6_RX; | |
1373 | goto change_notsup; | |
1374 | } | |
5b861f6b GM |
1375 | if (nla_get_u8(data[IFLA_GENEVE_UDP_ZERO_CSUM6_RX])) |
1376 | *use_udp6_rx_checksums = false; | |
f9094b76 HL |
1377 | #else |
1378 | NL_SET_ERR_MSG_ATTR(extack, data[IFLA_GENEVE_UDP_ZERO_CSUM6_RX], | |
1379 | "IPv6 support not enabled in the kernel"); | |
1380 | return -EPFNOSUPPORT; | |
1381 | #endif | |
5b861f6b GM |
1382 | } |
1383 | ||
1384 | return 0; | |
c5ebc440 GM |
1385 | change_notsup: |
1386 | NL_SET_ERR_MSG_ATTR(extack, data[attrtype], | |
1387 | "Changing VNI, Port, endpoint IP address family, external, and UDP checksum attributes are not supported"); | |
1388 | return -EOPNOTSUPP; | |
5b861f6b GM |
1389 | } |
1390 | ||
c40e89fd AK |
1391 | static void geneve_link_config(struct net_device *dev, |
1392 | struct ip_tunnel_info *info, struct nlattr *tb[]) | |
1393 | { | |
1394 | struct geneve_dev *geneve = netdev_priv(dev); | |
1395 | int ldev_mtu = 0; | |
1396 | ||
1397 | if (tb[IFLA_MTU]) { | |
1398 | geneve_change_mtu(dev, nla_get_u32(tb[IFLA_MTU])); | |
1399 | return; | |
1400 | } | |
1401 | ||
1402 | switch (ip_tunnel_info_af(info)) { | |
1403 | case AF_INET: { | |
1404 | struct flowi4 fl4 = { .daddr = info->key.u.ipv4.dst }; | |
1405 | struct rtable *rt = ip_route_output_key(geneve->net, &fl4); | |
1406 | ||
1407 | if (!IS_ERR(rt) && rt->dst.dev) { | |
1408 | ldev_mtu = rt->dst.dev->mtu - GENEVE_IPV4_HLEN; | |
1409 | ip_rt_put(rt); | |
1410 | } | |
1411 | break; | |
1412 | } | |
1413 | #if IS_ENABLED(CONFIG_IPV6) | |
1414 | case AF_INET6: { | |
1415 | struct rt6_info *rt = rt6_lookup(geneve->net, | |
1416 | &info->key.u.ipv6.dst, NULL, 0, | |
1417 | NULL, 0); | |
1418 | ||
1419 | if (rt && rt->dst.dev) | |
1420 | ldev_mtu = rt->dst.dev->mtu - GENEVE_IPV6_HLEN; | |
1421 | ip6_rt_put(rt); | |
1422 | break; | |
1423 | } | |
1424 | #endif | |
1425 | } | |
1426 | ||
1427 | if (ldev_mtu <= 0) | |
1428 | return; | |
1429 | ||
1430 | geneve_change_mtu(dev, ldev_mtu - info->options_len); | |
1431 | } | |
1432 | ||
5b861f6b GM |
1433 | static int geneve_newlink(struct net *net, struct net_device *dev, |
1434 | struct nlattr *tb[], struct nlattr *data[], | |
1435 | struct netlink_ext_ack *extack) | |
1436 | { | |
1437 | bool use_udp6_rx_checksums = false; | |
1438 | struct ip_tunnel_info info; | |
1439 | bool metadata = false; | |
1440 | int err; | |
1441 | ||
1442 | init_tnl_info(&info, GENEVE_UDP_PORT); | |
c5ebc440 | 1443 | err = geneve_nl2info(tb, data, extack, &info, &metadata, |
5b861f6b GM |
1444 | &use_udp6_rx_checksums, false); |
1445 | if (err) | |
1446 | return err; | |
abe492b4 | 1447 | |
c40e89fd AK |
1448 | err = geneve_configure(net, dev, extack, &info, metadata, |
1449 | use_udp6_rx_checksums); | |
1450 | if (err) | |
1451 | return err; | |
1452 | ||
1453 | geneve_link_config(dev, &info, tb); | |
1454 | ||
1455 | return 0; | |
2d07dc79 JL |
1456 | } |
1457 | ||
5b861f6b GM |
1458 | /* Quiesces the geneve device data path for both TX and RX. |
1459 | * | |
1460 | * On transmit geneve checks for non-NULL geneve_sock before it proceeds. | |
1461 | * So, if we set that socket to NULL under RCU and wait for synchronize_net() | |
1462 | * to complete for the existing set of in-flight packets to be transmitted, | |
1463 | * then we would have quiesced the transmit data path. All the future packets | |
1464 | * will get dropped until we unquiesce the data path. | |
1465 | * | |
1466 | * On receive geneve dereference the geneve_sock stashed in the socket. So, | |
1467 | * if we set that to NULL under RCU and wait for synchronize_net() to | |
1468 | * complete, then we would have quiesced the receive data path. | |
1469 | */ | |
1470 | static void geneve_quiesce(struct geneve_dev *geneve, struct geneve_sock **gs4, | |
1471 | struct geneve_sock **gs6) | |
1472 | { | |
1473 | *gs4 = rtnl_dereference(geneve->sock4); | |
1474 | rcu_assign_pointer(geneve->sock4, NULL); | |
1475 | if (*gs4) | |
1476 | rcu_assign_sk_user_data((*gs4)->sock->sk, NULL); | |
1477 | #if IS_ENABLED(CONFIG_IPV6) | |
1478 | *gs6 = rtnl_dereference(geneve->sock6); | |
1479 | rcu_assign_pointer(geneve->sock6, NULL); | |
1480 | if (*gs6) | |
1481 | rcu_assign_sk_user_data((*gs6)->sock->sk, NULL); | |
1482 | #else | |
1483 | *gs6 = NULL; | |
1484 | #endif | |
1485 | synchronize_net(); | |
1486 | } | |
1487 | ||
1488 | /* Resumes the geneve device data path for both TX and RX. */ | |
1489 | static void geneve_unquiesce(struct geneve_dev *geneve, struct geneve_sock *gs4, | |
1490 | struct geneve_sock __maybe_unused *gs6) | |
1491 | { | |
1492 | rcu_assign_pointer(geneve->sock4, gs4); | |
1493 | if (gs4) | |
1494 | rcu_assign_sk_user_data(gs4->sock->sk, gs4); | |
1495 | #if IS_ENABLED(CONFIG_IPV6) | |
1496 | rcu_assign_pointer(geneve->sock6, gs6); | |
1497 | if (gs6) | |
1498 | rcu_assign_sk_user_data(gs6->sock->sk, gs6); | |
1499 | #endif | |
1500 | synchronize_net(); | |
1501 | } | |
1502 | ||
1503 | static int geneve_changelink(struct net_device *dev, struct nlattr *tb[], | |
1504 | struct nlattr *data[], | |
1505 | struct netlink_ext_ack *extack) | |
1506 | { | |
1507 | struct geneve_dev *geneve = netdev_priv(dev); | |
1508 | struct geneve_sock *gs4, *gs6; | |
1509 | struct ip_tunnel_info info; | |
1510 | bool metadata; | |
1511 | bool use_udp6_rx_checksums; | |
1512 | int err; | |
1513 | ||
1514 | /* If the geneve device is configured for metadata (or externally | |
1515 | * controlled, for example, OVS), then nothing can be changed. | |
1516 | */ | |
1517 | if (geneve->collect_md) | |
1518 | return -EOPNOTSUPP; | |
1519 | ||
1520 | /* Start with the existing info. */ | |
1521 | memcpy(&info, &geneve->info, sizeof(info)); | |
1522 | metadata = geneve->collect_md; | |
1523 | use_udp6_rx_checksums = geneve->use_udp6_rx_checksums; | |
c5ebc440 | 1524 | err = geneve_nl2info(tb, data, extack, &info, &metadata, |
5b861f6b GM |
1525 | &use_udp6_rx_checksums, true); |
1526 | if (err) | |
1527 | return err; | |
1528 | ||
c40e89fd | 1529 | if (!geneve_dst_addr_equal(&geneve->info, &info)) { |
5b861f6b | 1530 | dst_cache_reset(&info.dst_cache); |
c40e89fd AK |
1531 | geneve_link_config(dev, &info, tb); |
1532 | } | |
5b861f6b GM |
1533 | |
1534 | geneve_quiesce(geneve, &gs4, &gs6); | |
1535 | geneve->info = info; | |
1536 | geneve->collect_md = metadata; | |
1537 | geneve->use_udp6_rx_checksums = use_udp6_rx_checksums; | |
1538 | geneve_unquiesce(geneve, gs4, gs6); | |
1539 | ||
1540 | return 0; | |
1541 | } | |
1542 | ||
2d07dc79 JL |
1543 | static void geneve_dellink(struct net_device *dev, struct list_head *head) |
1544 | { | |
1545 | struct geneve_dev *geneve = netdev_priv(dev); | |
1546 | ||
2d07dc79 JL |
1547 | list_del(&geneve->next); |
1548 | unregister_netdevice_queue(dev, head); | |
1549 | } | |
1550 | ||
1551 | static size_t geneve_get_size(const struct net_device *dev) | |
1552 | { | |
1553 | return nla_total_size(sizeof(__u32)) + /* IFLA_GENEVE_ID */ | |
8ed66f0e | 1554 | nla_total_size(sizeof(struct in6_addr)) + /* IFLA_GENEVE_REMOTE{6} */ |
8760ce58 | 1555 | nla_total_size(sizeof(__u8)) + /* IFLA_GENEVE_TTL */ |
d8951125 | 1556 | nla_total_size(sizeof(__u8)) + /* IFLA_GENEVE_TOS */ |
8eb3b995 | 1557 | nla_total_size(sizeof(__be32)) + /* IFLA_GENEVE_LABEL */ |
7bbe33ff | 1558 | nla_total_size(sizeof(__be16)) + /* IFLA_GENEVE_PORT */ |
e305ac6c | 1559 | nla_total_size(0) + /* IFLA_GENEVE_COLLECT_METADATA */ |
abe492b4 TH |
1560 | nla_total_size(sizeof(__u8)) + /* IFLA_GENEVE_UDP_CSUM */ |
1561 | nla_total_size(sizeof(__u8)) + /* IFLA_GENEVE_UDP_ZERO_CSUM6_TX */ | |
1562 | nla_total_size(sizeof(__u8)) + /* IFLA_GENEVE_UDP_ZERO_CSUM6_RX */ | |
2d07dc79 JL |
1563 | 0; |
1564 | } | |
1565 | ||
1566 | static int geneve_fill_info(struct sk_buff *skb, const struct net_device *dev) | |
1567 | { | |
1568 | struct geneve_dev *geneve = netdev_priv(dev); | |
9b4437a5 | 1569 | struct ip_tunnel_info *info = &geneve->info; |
fd7eafd0 | 1570 | bool metadata = geneve->collect_md; |
9b4437a5 | 1571 | __u8 tmp_vni[3]; |
2d07dc79 JL |
1572 | __u32 vni; |
1573 | ||
9b4437a5 | 1574 | tunnel_id_to_vni(info->key.tun_id, tmp_vni); |
1575 | vni = (tmp_vni[0] << 16) | (tmp_vni[1] << 8) | tmp_vni[2]; | |
2d07dc79 JL |
1576 | if (nla_put_u32(skb, IFLA_GENEVE_ID, vni)) |
1577 | goto nla_put_failure; | |
1578 | ||
fd7eafd0 | 1579 | if (!metadata && ip_tunnel_info_af(info) == AF_INET) { |
8ed66f0e | 1580 | if (nla_put_in_addr(skb, IFLA_GENEVE_REMOTE, |
9b4437a5 | 1581 | info->key.u.ipv4.dst)) |
1582 | goto nla_put_failure; | |
9b4437a5 | 1583 | if (nla_put_u8(skb, IFLA_GENEVE_UDP_CSUM, |
1584 | !!(info->key.tun_flags & TUNNEL_CSUM))) | |
8ed66f0e | 1585 | goto nla_put_failure; |
9b4437a5 | 1586 | |
8ed66f0e | 1587 | #if IS_ENABLED(CONFIG_IPV6) |
fd7eafd0 | 1588 | } else if (!metadata) { |
8ed66f0e | 1589 | if (nla_put_in6_addr(skb, IFLA_GENEVE_REMOTE6, |
9b4437a5 | 1590 | &info->key.u.ipv6.dst)) |
1591 | goto nla_put_failure; | |
9b4437a5 | 1592 | if (nla_put_u8(skb, IFLA_GENEVE_UDP_ZERO_CSUM6_TX, |
1593 | !(info->key.tun_flags & TUNNEL_CSUM))) | |
1594 | goto nla_put_failure; | |
11387fe4 | 1595 | #endif |
fd7eafd0 | 1596 | } |
2d07dc79 | 1597 | |
9b4437a5 | 1598 | if (nla_put_u8(skb, IFLA_GENEVE_TTL, info->key.ttl) || |
1599 | nla_put_u8(skb, IFLA_GENEVE_TOS, info->key.tos) || | |
1600 | nla_put_be32(skb, IFLA_GENEVE_LABEL, info->key.label)) | |
8760ce58 JL |
1601 | goto nla_put_failure; |
1602 | ||
9b4437a5 | 1603 | if (nla_put_be16(skb, IFLA_GENEVE_PORT, info->key.tp_dst)) |
cd7918b3 PS |
1604 | goto nla_put_failure; |
1605 | ||
fd7eafd0 | 1606 | if (metadata && nla_put_flag(skb, IFLA_GENEVE_COLLECT_METADATA)) |
f9094b76 | 1607 | goto nla_put_failure; |
fd7eafd0 | 1608 | |
f9094b76 | 1609 | #if IS_ENABLED(CONFIG_IPV6) |
fd7eafd0 HL |
1610 | if (nla_put_u8(skb, IFLA_GENEVE_UDP_ZERO_CSUM6_RX, |
1611 | !geneve->use_udp6_rx_checksums)) | |
1612 | goto nla_put_failure; | |
f9094b76 | 1613 | #endif |
fd7eafd0 | 1614 | |
2d07dc79 JL |
1615 | return 0; |
1616 | ||
1617 | nla_put_failure: | |
1618 | return -EMSGSIZE; | |
1619 | } | |
1620 | ||
1621 | static struct rtnl_link_ops geneve_link_ops __read_mostly = { | |
1622 | .kind = "geneve", | |
1623 | .maxtype = IFLA_GENEVE_MAX, | |
1624 | .policy = geneve_policy, | |
1625 | .priv_size = sizeof(struct geneve_dev), | |
1626 | .setup = geneve_setup, | |
1627 | .validate = geneve_validate, | |
1628 | .newlink = geneve_newlink, | |
5b861f6b | 1629 | .changelink = geneve_changelink, |
2d07dc79 JL |
1630 | .dellink = geneve_dellink, |
1631 | .get_size = geneve_get_size, | |
1632 | .fill_info = geneve_fill_info, | |
1633 | }; | |
1634 | ||
e305ac6c PS |
1635 | struct net_device *geneve_dev_create_fb(struct net *net, const char *name, |
1636 | u8 name_assign_type, u16 dst_port) | |
1637 | { | |
1638 | struct nlattr *tb[IFLA_MAX + 1]; | |
9b4437a5 | 1639 | struct ip_tunnel_info info; |
e305ac6c | 1640 | struct net_device *dev; |
106da663 | 1641 | LIST_HEAD(list_kill); |
e305ac6c PS |
1642 | int err; |
1643 | ||
1644 | memset(tb, 0, sizeof(tb)); | |
1645 | dev = rtnl_create_link(net, name, name_assign_type, | |
1646 | &geneve_link_ops, tb); | |
1647 | if (IS_ERR(dev)) | |
1648 | return dev; | |
1649 | ||
9b4437a5 | 1650 | init_tnl_info(&info, dst_port); |
c5ebc440 | 1651 | err = geneve_configure(net, dev, NULL, &info, true, true); |
106da663 ND |
1652 | if (err) { |
1653 | free_netdev(dev); | |
1654 | return ERR_PTR(err); | |
1655 | } | |
7e059158 DW |
1656 | |
1657 | /* openvswitch users expect packet sizes to be unrestricted, | |
1658 | * so set the largest MTU we can. | |
1659 | */ | |
91572088 | 1660 | err = geneve_change_mtu(dev, IP_MAX_MTU); |
7e059158 DW |
1661 | if (err) |
1662 | goto err; | |
1663 | ||
41009481 ND |
1664 | err = rtnl_configure_link(dev, NULL); |
1665 | if (err < 0) | |
1666 | goto err; | |
1667 | ||
e305ac6c | 1668 | return dev; |
9b4437a5 | 1669 | err: |
106da663 ND |
1670 | geneve_dellink(dev, &list_kill); |
1671 | unregister_netdevice_many(&list_kill); | |
7e059158 | 1672 | return ERR_PTR(err); |
e305ac6c PS |
1673 | } |
1674 | EXPORT_SYMBOL_GPL(geneve_dev_create_fb); | |
1675 | ||
681e683f HFS |
1676 | static int geneve_netdevice_event(struct notifier_block *unused, |
1677 | unsigned long event, void *ptr) | |
1678 | { | |
1679 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); | |
1680 | ||
2d2b13fc | 1681 | if (event == NETDEV_UDP_TUNNEL_PUSH_INFO || |
04584957 | 1682 | event == NETDEV_UDP_TUNNEL_DROP_INFO) { |
2d2b13fc | 1683 | geneve_offload_rx_ports(dev, event == NETDEV_UDP_TUNNEL_PUSH_INFO); |
04584957 SD |
1684 | } else if (event == NETDEV_UNREGISTER) { |
1685 | geneve_offload_rx_ports(dev, false); | |
1686 | } else if (event == NETDEV_REGISTER) { | |
1687 | geneve_offload_rx_ports(dev, true); | |
1688 | } | |
681e683f HFS |
1689 | |
1690 | return NOTIFY_DONE; | |
1691 | } | |
1692 | ||
1693 | static struct notifier_block geneve_notifier_block __read_mostly = { | |
1694 | .notifier_call = geneve_netdevice_event, | |
1695 | }; | |
1696 | ||
2d07dc79 JL |
1697 | static __net_init int geneve_init_net(struct net *net) |
1698 | { | |
1699 | struct geneve_net *gn = net_generic(net, geneve_net_id); | |
2d07dc79 JL |
1700 | |
1701 | INIT_LIST_HEAD(&gn->geneve_list); | |
371bd106 | 1702 | INIT_LIST_HEAD(&gn->sock_list); |
2d07dc79 JL |
1703 | return 0; |
1704 | } | |
1705 | ||
2843a253 | 1706 | static void geneve_destroy_tunnels(struct net *net, struct list_head *head) |
2d07dc79 JL |
1707 | { |
1708 | struct geneve_net *gn = net_generic(net, geneve_net_id); | |
1709 | struct geneve_dev *geneve, *next; | |
1710 | struct net_device *dev, *aux; | |
2d07dc79 JL |
1711 | |
1712 | /* gather any geneve devices that were moved into this ns */ | |
1713 | for_each_netdev_safe(net, dev, aux) | |
1714 | if (dev->rtnl_link_ops == &geneve_link_ops) | |
2843a253 | 1715 | unregister_netdevice_queue(dev, head); |
2d07dc79 JL |
1716 | |
1717 | /* now gather any other geneve devices that were created in this ns */ | |
1718 | list_for_each_entry_safe(geneve, next, &gn->geneve_list, next) { | |
1719 | /* If geneve->dev is in the same netns, it was already added | |
1720 | * to the list by the previous loop. | |
1721 | */ | |
1722 | if (!net_eq(dev_net(geneve->dev), net)) | |
2843a253 | 1723 | unregister_netdevice_queue(geneve->dev, head); |
2d07dc79 JL |
1724 | } |
1725 | ||
2843a253 HY |
1726 | WARN_ON_ONCE(!list_empty(&gn->sock_list)); |
1727 | } | |
1728 | ||
1729 | static void __net_exit geneve_exit_batch_net(struct list_head *net_list) | |
1730 | { | |
1731 | struct net *net; | |
1732 | LIST_HEAD(list); | |
1733 | ||
1734 | rtnl_lock(); | |
1735 | list_for_each_entry(net, net_list, exit_list) | |
1736 | geneve_destroy_tunnels(net, &list); | |
1737 | ||
2d07dc79 JL |
1738 | /* unregister the devices gathered above */ |
1739 | unregister_netdevice_many(&list); | |
1740 | rtnl_unlock(); | |
1741 | } | |
1742 | ||
1743 | static struct pernet_operations geneve_net_ops = { | |
1744 | .init = geneve_init_net, | |
2843a253 | 1745 | .exit_batch = geneve_exit_batch_net, |
2d07dc79 JL |
1746 | .id = &geneve_net_id, |
1747 | .size = sizeof(struct geneve_net), | |
1748 | }; | |
1749 | ||
1750 | static int __init geneve_init_module(void) | |
1751 | { | |
1752 | int rc; | |
1753 | ||
1754 | rc = register_pernet_subsys(&geneve_net_ops); | |
1755 | if (rc) | |
1756 | goto out1; | |
1757 | ||
681e683f | 1758 | rc = register_netdevice_notifier(&geneve_notifier_block); |
2d07dc79 JL |
1759 | if (rc) |
1760 | goto out2; | |
1761 | ||
681e683f HFS |
1762 | rc = rtnl_link_register(&geneve_link_ops); |
1763 | if (rc) | |
1764 | goto out3; | |
1765 | ||
2d07dc79 | 1766 | return 0; |
681e683f HFS |
1767 | out3: |
1768 | unregister_netdevice_notifier(&geneve_notifier_block); | |
2d07dc79 JL |
1769 | out2: |
1770 | unregister_pernet_subsys(&geneve_net_ops); | |
1771 | out1: | |
1772 | return rc; | |
1773 | } | |
1774 | late_initcall(geneve_init_module); | |
1775 | ||
1776 | static void __exit geneve_cleanup_module(void) | |
1777 | { | |
1778 | rtnl_link_unregister(&geneve_link_ops); | |
681e683f | 1779 | unregister_netdevice_notifier(&geneve_notifier_block); |
2d07dc79 JL |
1780 | unregister_pernet_subsys(&geneve_net_ops); |
1781 | } | |
1782 | module_exit(geneve_cleanup_module); | |
1783 | ||
1784 | MODULE_LICENSE("GPL"); | |
1785 | MODULE_VERSION(GENEVE_NETDEV_VER); | |
1786 | MODULE_AUTHOR("John W. Linville <linville@tuxdriver.com>"); | |
1787 | MODULE_DESCRIPTION("Interface driver for GENEVE encapsulated traffic"); | |
1788 | MODULE_ALIAS_RTNL_LINK("geneve"); |