1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2013 Nicira, Inc.
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8 #include <linux/types.h>
9 #include <linux/kernel.h>
10 #include <linux/skbuff.h>
11 #include <linux/netdevice.h>
13 #include <linux/if_arp.h>
14 #include <linux/init.h>
15 #include <linux/in6.h>
16 #include <linux/inetdevice.h>
17 #include <linux/netfilter_ipv4.h>
18 #include <linux/etherdevice.h>
19 #include <linux/if_ether.h>
20 #include <linux/if_vlan.h>
21 #include <linux/static_key.h>
25 #include <net/protocol.h>
26 #include <net/ip_tunnels.h>
27 #include <net/ip6_tunnel.h>
29 #include <net/checksum.h>
30 #include <net/dsfield.h>
31 #include <net/inet_ecn.h>
33 #include <net/net_namespace.h>
34 #include <net/netns/generic.h>
35 #include <net/rtnetlink.h>
36 #include <net/dst_metadata.h>
37 #include <net/geneve.h>
38 #include <net/vxlan.h>
40 const struct ip_tunnel_encap_ops __rcu *
41 iptun_encaps[MAX_IPTUN_ENCAP_OPS] __read_mostly;
42 EXPORT_SYMBOL(iptun_encaps);
44 const struct ip6_tnl_encap_ops __rcu *
45 ip6tun_encaps[MAX_IPTUN_ENCAP_OPS] __read_mostly;
46 EXPORT_SYMBOL(ip6tun_encaps);
48 void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
49 __be32 src, __be32 dst, __u8 proto,
50 __u8 tos, __u8 ttl, __be16 df, bool xnet)
52 int pkt_len = skb->len - skb_inner_network_offset(skb);
53 struct net *net = dev_net(rt->dst.dev);
54 struct net_device *dev = skb->dev;
58 skb_scrub_packet(skb, xnet);
60 skb_clear_hash_if_not_l4(skb);
61 skb_dst_set(skb, &rt->dst);
62 memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
64 /* Push down and install the IP header. */
65 skb_push(skb, sizeof(struct iphdr));
66 skb_reset_network_header(skb);
71 iph->ihl = sizeof(struct iphdr) >> 2;
72 iph->frag_off = ip_mtu_locked(&rt->dst) ? 0 : df;
73 iph->protocol = proto;
78 __ip_select_ident(net, iph, skb_shinfo(skb)->gso_segs ?: 1);
80 err = ip_local_out(net, sk, skb);
83 if (unlikely(net_xmit_eval(err)))
85 iptunnel_xmit_stats(dev, pkt_len);
88 EXPORT_SYMBOL_GPL(iptunnel_xmit);
90 int __iptunnel_pull_header(struct sk_buff *skb, int hdr_len,
91 __be16 inner_proto, bool raw_proto, bool xnet)
93 if (unlikely(!pskb_may_pull(skb, hdr_len)))
96 skb_pull_rcsum(skb, hdr_len);
98 if (!raw_proto && inner_proto == htons(ETH_P_TEB)) {
101 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
104 eh = (struct ethhdr *)skb->data;
105 if (likely(eth_proto_is_802_3(eh->h_proto)))
106 skb->protocol = eh->h_proto;
108 skb->protocol = htons(ETH_P_802_2);
111 skb->protocol = inner_proto;
114 skb_clear_hash_if_not_l4(skb);
115 __vlan_hwaccel_clear_tag(skb);
116 skb_set_queue_mapping(skb, 0);
117 skb_scrub_packet(skb, xnet);
119 return iptunnel_pull_offloads(skb);
121 EXPORT_SYMBOL_GPL(__iptunnel_pull_header);
123 struct metadata_dst *iptunnel_metadata_reply(struct metadata_dst *md,
126 struct metadata_dst *res;
127 struct ip_tunnel_info *dst, *src;
129 if (!md || md->type != METADATA_IP_TUNNEL ||
130 md->u.tun_info.mode & IP_TUNNEL_INFO_TX)
133 src = &md->u.tun_info;
134 res = metadata_dst_alloc(src->options_len, METADATA_IP_TUNNEL, flags);
138 dst = &res->u.tun_info;
139 dst->key.tun_id = src->key.tun_id;
140 if (src->mode & IP_TUNNEL_INFO_IPV6)
141 memcpy(&dst->key.u.ipv6.dst, &src->key.u.ipv6.src,
142 sizeof(struct in6_addr));
144 dst->key.u.ipv4.dst = src->key.u.ipv4.src;
145 dst->key.tun_flags = src->key.tun_flags;
146 dst->mode = src->mode | IP_TUNNEL_INFO_TX;
147 ip_tunnel_info_opts_set(dst, ip_tunnel_info_opts(src),
148 src->options_len, 0);
152 EXPORT_SYMBOL_GPL(iptunnel_metadata_reply);
154 int iptunnel_handle_offloads(struct sk_buff *skb,
159 if (likely(!skb->encapsulation)) {
160 skb_reset_inner_headers(skb);
161 skb->encapsulation = 1;
164 if (skb_is_gso(skb)) {
165 err = skb_header_unclone(skb, GFP_ATOMIC);
168 skb_shinfo(skb)->gso_type |= gso_type_mask;
172 if (skb->ip_summed != CHECKSUM_PARTIAL) {
173 skb->ip_summed = CHECKSUM_NONE;
174 /* We clear encapsulation here to prevent badly-written
175 * drivers potentially deciding to offload an inner checksum
176 * if we set CHECKSUM_PARTIAL on the outer header.
177 * This should go away when the drivers are all fixed.
179 skb->encapsulation = 0;
184 EXPORT_SYMBOL_GPL(iptunnel_handle_offloads);
186 /* Often modified stats are per cpu, other are shared (netdev->stats) */
187 void ip_tunnel_get_stats64(struct net_device *dev,
188 struct rtnl_link_stats64 *tot)
192 netdev_stats_to_stats64(tot, &dev->stats);
194 for_each_possible_cpu(i) {
195 const struct pcpu_sw_netstats *tstats =
196 per_cpu_ptr(dev->tstats, i);
197 u64 rx_packets, rx_bytes, tx_packets, tx_bytes;
201 start = u64_stats_fetch_begin_irq(&tstats->syncp);
202 rx_packets = tstats->rx_packets;
203 tx_packets = tstats->tx_packets;
204 rx_bytes = tstats->rx_bytes;
205 tx_bytes = tstats->tx_bytes;
206 } while (u64_stats_fetch_retry_irq(&tstats->syncp, start));
208 tot->rx_packets += rx_packets;
209 tot->tx_packets += tx_packets;
210 tot->rx_bytes += rx_bytes;
211 tot->tx_bytes += tx_bytes;
214 EXPORT_SYMBOL_GPL(ip_tunnel_get_stats64);
216 static const struct nla_policy ip_tun_policy[LWTUNNEL_IP_MAX + 1] = {
217 [LWTUNNEL_IP_ID] = { .type = NLA_U64 },
218 [LWTUNNEL_IP_DST] = { .type = NLA_U32 },
219 [LWTUNNEL_IP_SRC] = { .type = NLA_U32 },
220 [LWTUNNEL_IP_TTL] = { .type = NLA_U8 },
221 [LWTUNNEL_IP_TOS] = { .type = NLA_U8 },
222 [LWTUNNEL_IP_FLAGS] = { .type = NLA_U16 },
223 [LWTUNNEL_IP_OPTS] = { .type = NLA_NESTED },
226 static const struct nla_policy ip_opts_policy[LWTUNNEL_IP_OPTS_MAX + 1] = {
227 [LWTUNNEL_IP_OPTS_GENEVE] = { .type = NLA_NESTED },
228 [LWTUNNEL_IP_OPTS_VXLAN] = { .type = NLA_NESTED },
231 static const struct nla_policy
232 geneve_opt_policy[LWTUNNEL_IP_OPT_GENEVE_MAX + 1] = {
233 [LWTUNNEL_IP_OPT_GENEVE_CLASS] = { .type = NLA_U16 },
234 [LWTUNNEL_IP_OPT_GENEVE_TYPE] = { .type = NLA_U8 },
235 [LWTUNNEL_IP_OPT_GENEVE_DATA] = { .type = NLA_BINARY, .len = 128 },
238 static const struct nla_policy
239 vxlan_opt_policy[LWTUNNEL_IP_OPT_VXLAN_MAX + 1] = {
240 [LWTUNNEL_IP_OPT_VXLAN_GBP] = { .type = NLA_U32 },
243 static int ip_tun_parse_opts_geneve(struct nlattr *attr,
244 struct ip_tunnel_info *info,
245 struct netlink_ext_ack *extack)
247 struct nlattr *tb[LWTUNNEL_IP_OPT_GENEVE_MAX + 1];
250 err = nla_parse_nested_deprecated(tb, LWTUNNEL_IP_OPT_GENEVE_MAX,
251 attr, geneve_opt_policy, extack);
255 if (!tb[LWTUNNEL_IP_OPT_GENEVE_CLASS] ||
256 !tb[LWTUNNEL_IP_OPT_GENEVE_TYPE] ||
257 !tb[LWTUNNEL_IP_OPT_GENEVE_DATA])
260 attr = tb[LWTUNNEL_IP_OPT_GENEVE_DATA];
261 data_len = nla_len(attr);
266 struct geneve_opt *opt = ip_tunnel_info_opts(info);
268 memcpy(opt->opt_data, nla_data(attr), data_len);
269 opt->length = data_len / 4;
270 attr = tb[LWTUNNEL_IP_OPT_GENEVE_CLASS];
271 opt->opt_class = nla_get_be16(attr);
272 attr = tb[LWTUNNEL_IP_OPT_GENEVE_TYPE];
273 opt->type = nla_get_u8(attr);
274 info->key.tun_flags |= TUNNEL_GENEVE_OPT;
277 return sizeof(struct geneve_opt) + data_len;
280 static int ip_tun_parse_opts_vxlan(struct nlattr *attr,
281 struct ip_tunnel_info *info,
282 struct netlink_ext_ack *extack)
284 struct nlattr *tb[LWTUNNEL_IP_OPT_VXLAN_MAX + 1];
287 err = nla_parse_nested_deprecated(tb, LWTUNNEL_IP_OPT_VXLAN_MAX,
288 attr, vxlan_opt_policy, extack);
292 if (!tb[LWTUNNEL_IP_OPT_VXLAN_GBP])
296 struct vxlan_metadata *md = ip_tunnel_info_opts(info);
298 attr = tb[LWTUNNEL_IP_OPT_VXLAN_GBP];
299 md->gbp = nla_get_u32(attr);
300 info->key.tun_flags |= TUNNEL_VXLAN_OPT;
303 return sizeof(struct vxlan_metadata);
306 static int ip_tun_parse_opts(struct nlattr *attr, struct ip_tunnel_info *info,
307 struct netlink_ext_ack *extack)
309 struct nlattr *tb[LWTUNNEL_IP_OPTS_MAX + 1];
315 err = nla_parse_nested_deprecated(tb, LWTUNNEL_IP_OPTS_MAX, attr,
316 ip_opts_policy, extack);
320 if (tb[LWTUNNEL_IP_OPTS_GENEVE])
321 err = ip_tun_parse_opts_geneve(tb[LWTUNNEL_IP_OPTS_GENEVE],
323 else if (tb[LWTUNNEL_IP_OPTS_VXLAN])
324 err = ip_tun_parse_opts_vxlan(tb[LWTUNNEL_IP_OPTS_VXLAN],
332 static int ip_tun_get_optlen(struct nlattr *attr,
333 struct netlink_ext_ack *extack)
335 return ip_tun_parse_opts(attr, NULL, extack);
338 static int ip_tun_set_opts(struct nlattr *attr, struct ip_tunnel_info *info,
339 struct netlink_ext_ack *extack)
341 return ip_tun_parse_opts(attr, info, extack);
344 static int ip_tun_build_state(struct nlattr *attr,
345 unsigned int family, const void *cfg,
346 struct lwtunnel_state **ts,
347 struct netlink_ext_ack *extack)
349 struct nlattr *tb[LWTUNNEL_IP_MAX + 1];
350 struct lwtunnel_state *new_state;
351 struct ip_tunnel_info *tun_info;
354 err = nla_parse_nested_deprecated(tb, LWTUNNEL_IP_MAX, attr,
355 ip_tun_policy, extack);
359 opt_len = ip_tun_get_optlen(tb[LWTUNNEL_IP_OPTS], extack);
363 new_state = lwtunnel_state_alloc(sizeof(*tun_info) + opt_len);
367 new_state->type = LWTUNNEL_ENCAP_IP;
369 tun_info = lwt_tun_info(new_state);
371 err = ip_tun_set_opts(tb[LWTUNNEL_IP_OPTS], tun_info, extack);
373 lwtstate_free(new_state);
377 #ifdef CONFIG_DST_CACHE
378 err = dst_cache_init(&tun_info->dst_cache, GFP_KERNEL);
380 lwtstate_free(new_state);
385 if (tb[LWTUNNEL_IP_ID])
386 tun_info->key.tun_id = nla_get_be64(tb[LWTUNNEL_IP_ID]);
388 if (tb[LWTUNNEL_IP_DST])
389 tun_info->key.u.ipv4.dst = nla_get_in_addr(tb[LWTUNNEL_IP_DST]);
391 if (tb[LWTUNNEL_IP_SRC])
392 tun_info->key.u.ipv4.src = nla_get_in_addr(tb[LWTUNNEL_IP_SRC]);
394 if (tb[LWTUNNEL_IP_TTL])
395 tun_info->key.ttl = nla_get_u8(tb[LWTUNNEL_IP_TTL]);
397 if (tb[LWTUNNEL_IP_TOS])
398 tun_info->key.tos = nla_get_u8(tb[LWTUNNEL_IP_TOS]);
400 if (tb[LWTUNNEL_IP_FLAGS])
401 tun_info->key.tun_flags |= nla_get_be16(tb[LWTUNNEL_IP_FLAGS]);
403 tun_info->mode = IP_TUNNEL_INFO_TX;
404 tun_info->options_len = opt_len;
411 static void ip_tun_destroy_state(struct lwtunnel_state *lwtstate)
413 #ifdef CONFIG_DST_CACHE
414 struct ip_tunnel_info *tun_info = lwt_tun_info(lwtstate);
416 dst_cache_destroy(&tun_info->dst_cache);
420 static int ip_tun_fill_encap_opts_geneve(struct sk_buff *skb,
421 struct ip_tunnel_info *tun_info)
423 struct geneve_opt *opt;
426 nest = nla_nest_start_noflag(skb, LWTUNNEL_IP_OPTS_GENEVE);
430 opt = ip_tunnel_info_opts(tun_info);
431 if (nla_put_be16(skb, LWTUNNEL_IP_OPT_GENEVE_CLASS, opt->opt_class) ||
432 nla_put_u8(skb, LWTUNNEL_IP_OPT_GENEVE_TYPE, opt->type) ||
433 nla_put(skb, LWTUNNEL_IP_OPT_GENEVE_DATA, opt->length * 4,
435 nla_nest_cancel(skb, nest);
439 nla_nest_end(skb, nest);
443 static int ip_tun_fill_encap_opts_vxlan(struct sk_buff *skb,
444 struct ip_tunnel_info *tun_info)
446 struct vxlan_metadata *md;
449 nest = nla_nest_start_noflag(skb, LWTUNNEL_IP_OPTS_VXLAN);
453 md = ip_tunnel_info_opts(tun_info);
454 if (nla_put_u32(skb, LWTUNNEL_IP_OPT_VXLAN_GBP, md->gbp)) {
455 nla_nest_cancel(skb, nest);
459 nla_nest_end(skb, nest);
463 static int ip_tun_fill_encap_opts(struct sk_buff *skb, int type,
464 struct ip_tunnel_info *tun_info)
469 if (!(tun_info->key.tun_flags &
470 (TUNNEL_GENEVE_OPT | TUNNEL_VXLAN_OPT)))
473 nest = nla_nest_start_noflag(skb, type);
477 if (tun_info->key.tun_flags & TUNNEL_GENEVE_OPT)
478 err = ip_tun_fill_encap_opts_geneve(skb, tun_info);
479 else if (tun_info->key.tun_flags & TUNNEL_VXLAN_OPT)
480 err = ip_tun_fill_encap_opts_vxlan(skb, tun_info);
483 nla_nest_cancel(skb, nest);
487 nla_nest_end(skb, nest);
491 static int ip_tun_fill_encap_info(struct sk_buff *skb,
492 struct lwtunnel_state *lwtstate)
494 struct ip_tunnel_info *tun_info = lwt_tun_info(lwtstate);
496 if (nla_put_be64(skb, LWTUNNEL_IP_ID, tun_info->key.tun_id,
498 nla_put_in_addr(skb, LWTUNNEL_IP_DST, tun_info->key.u.ipv4.dst) ||
499 nla_put_in_addr(skb, LWTUNNEL_IP_SRC, tun_info->key.u.ipv4.src) ||
500 nla_put_u8(skb, LWTUNNEL_IP_TOS, tun_info->key.tos) ||
501 nla_put_u8(skb, LWTUNNEL_IP_TTL, tun_info->key.ttl) ||
502 nla_put_be16(skb, LWTUNNEL_IP_FLAGS, tun_info->key.tun_flags) ||
503 ip_tun_fill_encap_opts(skb, LWTUNNEL_IP_OPTS, tun_info))
509 static int ip_tun_opts_nlsize(struct ip_tunnel_info *info)
513 if (!(info->key.tun_flags &
514 (TUNNEL_GENEVE_OPT | TUNNEL_VXLAN_OPT)))
517 opt_len = nla_total_size(0); /* LWTUNNEL_IP_OPTS */
518 if (info->key.tun_flags & TUNNEL_GENEVE_OPT) {
519 struct geneve_opt *opt = ip_tunnel_info_opts(info);
521 opt_len += nla_total_size(0) /* LWTUNNEL_IP_OPTS_GENEVE */
522 + nla_total_size(2) /* OPT_GENEVE_CLASS */
523 + nla_total_size(1) /* OPT_GENEVE_TYPE */
524 + nla_total_size(opt->length * 4);
525 /* OPT_GENEVE_DATA */
526 } else if (info->key.tun_flags & TUNNEL_VXLAN_OPT) {
527 opt_len += nla_total_size(0) /* LWTUNNEL_IP_OPTS_VXLAN */
528 + nla_total_size(4); /* OPT_VXLAN_GBP */
534 static int ip_tun_encap_nlsize(struct lwtunnel_state *lwtstate)
536 return nla_total_size_64bit(8) /* LWTUNNEL_IP_ID */
537 + nla_total_size(4) /* LWTUNNEL_IP_DST */
538 + nla_total_size(4) /* LWTUNNEL_IP_SRC */
539 + nla_total_size(1) /* LWTUNNEL_IP_TOS */
540 + nla_total_size(1) /* LWTUNNEL_IP_TTL */
541 + nla_total_size(2) /* LWTUNNEL_IP_FLAGS */
542 + ip_tun_opts_nlsize(lwt_tun_info(lwtstate));
543 /* LWTUNNEL_IP_OPTS */
546 static int ip_tun_cmp_encap(struct lwtunnel_state *a, struct lwtunnel_state *b)
548 struct ip_tunnel_info *info_a = lwt_tun_info(a);
549 struct ip_tunnel_info *info_b = lwt_tun_info(b);
551 return memcmp(info_a, info_b, sizeof(info_a->key)) ||
552 info_a->mode != info_b->mode ||
553 info_a->options_len != info_b->options_len ||
554 memcmp(ip_tunnel_info_opts(info_a),
555 ip_tunnel_info_opts(info_b), info_a->options_len);
558 static const struct lwtunnel_encap_ops ip_tun_lwt_ops = {
559 .build_state = ip_tun_build_state,
560 .destroy_state = ip_tun_destroy_state,
561 .fill_encap = ip_tun_fill_encap_info,
562 .get_encap_size = ip_tun_encap_nlsize,
563 .cmp_encap = ip_tun_cmp_encap,
564 .owner = THIS_MODULE,
567 static const struct nla_policy ip6_tun_policy[LWTUNNEL_IP6_MAX + 1] = {
568 [LWTUNNEL_IP6_ID] = { .type = NLA_U64 },
569 [LWTUNNEL_IP6_DST] = { .len = sizeof(struct in6_addr) },
570 [LWTUNNEL_IP6_SRC] = { .len = sizeof(struct in6_addr) },
571 [LWTUNNEL_IP6_HOPLIMIT] = { .type = NLA_U8 },
572 [LWTUNNEL_IP6_TC] = { .type = NLA_U8 },
573 [LWTUNNEL_IP6_FLAGS] = { .type = NLA_U16 },
576 static int ip6_tun_build_state(struct nlattr *attr,
577 unsigned int family, const void *cfg,
578 struct lwtunnel_state **ts,
579 struct netlink_ext_ack *extack)
581 struct nlattr *tb[LWTUNNEL_IP6_MAX + 1];
582 struct lwtunnel_state *new_state;
583 struct ip_tunnel_info *tun_info;
586 err = nla_parse_nested_deprecated(tb, LWTUNNEL_IP6_MAX, attr,
587 ip6_tun_policy, extack);
591 opt_len = ip_tun_get_optlen(tb[LWTUNNEL_IP6_OPTS], extack);
595 new_state = lwtunnel_state_alloc(sizeof(*tun_info) + opt_len);
599 new_state->type = LWTUNNEL_ENCAP_IP6;
601 tun_info = lwt_tun_info(new_state);
603 err = ip_tun_set_opts(tb[LWTUNNEL_IP6_OPTS], tun_info, extack);
605 lwtstate_free(new_state);
609 if (tb[LWTUNNEL_IP6_ID])
610 tun_info->key.tun_id = nla_get_be64(tb[LWTUNNEL_IP6_ID]);
612 if (tb[LWTUNNEL_IP6_DST])
613 tun_info->key.u.ipv6.dst = nla_get_in6_addr(tb[LWTUNNEL_IP6_DST]);
615 if (tb[LWTUNNEL_IP6_SRC])
616 tun_info->key.u.ipv6.src = nla_get_in6_addr(tb[LWTUNNEL_IP6_SRC]);
618 if (tb[LWTUNNEL_IP6_HOPLIMIT])
619 tun_info->key.ttl = nla_get_u8(tb[LWTUNNEL_IP6_HOPLIMIT]);
621 if (tb[LWTUNNEL_IP6_TC])
622 tun_info->key.tos = nla_get_u8(tb[LWTUNNEL_IP6_TC]);
624 if (tb[LWTUNNEL_IP6_FLAGS])
625 tun_info->key.tun_flags |= nla_get_be16(tb[LWTUNNEL_IP6_FLAGS]);
627 tun_info->mode = IP_TUNNEL_INFO_TX | IP_TUNNEL_INFO_IPV6;
628 tun_info->options_len = opt_len;
635 static int ip6_tun_fill_encap_info(struct sk_buff *skb,
636 struct lwtunnel_state *lwtstate)
638 struct ip_tunnel_info *tun_info = lwt_tun_info(lwtstate);
640 if (nla_put_be64(skb, LWTUNNEL_IP6_ID, tun_info->key.tun_id,
642 nla_put_in6_addr(skb, LWTUNNEL_IP6_DST, &tun_info->key.u.ipv6.dst) ||
643 nla_put_in6_addr(skb, LWTUNNEL_IP6_SRC, &tun_info->key.u.ipv6.src) ||
644 nla_put_u8(skb, LWTUNNEL_IP6_TC, tun_info->key.tos) ||
645 nla_put_u8(skb, LWTUNNEL_IP6_HOPLIMIT, tun_info->key.ttl) ||
646 nla_put_be16(skb, LWTUNNEL_IP6_FLAGS, tun_info->key.tun_flags) ||
647 ip_tun_fill_encap_opts(skb, LWTUNNEL_IP6_OPTS, tun_info))
653 static int ip6_tun_encap_nlsize(struct lwtunnel_state *lwtstate)
655 return nla_total_size_64bit(8) /* LWTUNNEL_IP6_ID */
656 + nla_total_size(16) /* LWTUNNEL_IP6_DST */
657 + nla_total_size(16) /* LWTUNNEL_IP6_SRC */
658 + nla_total_size(1) /* LWTUNNEL_IP6_HOPLIMIT */
659 + nla_total_size(1) /* LWTUNNEL_IP6_TC */
660 + nla_total_size(2) /* LWTUNNEL_IP6_FLAGS */
661 + ip_tun_opts_nlsize(lwt_tun_info(lwtstate));
662 /* LWTUNNEL_IP6_OPTS */
665 static const struct lwtunnel_encap_ops ip6_tun_lwt_ops = {
666 .build_state = ip6_tun_build_state,
667 .fill_encap = ip6_tun_fill_encap_info,
668 .get_encap_size = ip6_tun_encap_nlsize,
669 .cmp_encap = ip_tun_cmp_encap,
670 .owner = THIS_MODULE,
673 void __init ip_tunnel_core_init(void)
675 /* If you land here, make sure whether increasing ip_tunnel_info's
676 * options_len is a reasonable choice with its usage in front ends
677 * (f.e., it's part of flow keys, etc).
679 BUILD_BUG_ON(IP_TUNNEL_OPTS_MAX != 255);
681 lwtunnel_encap_add_ops(&ip_tun_lwt_ops, LWTUNNEL_ENCAP_IP);
682 lwtunnel_encap_add_ops(&ip6_tun_lwt_ops, LWTUNNEL_ENCAP_IP6);
685 DEFINE_STATIC_KEY_FALSE(ip_tunnel_metadata_cnt);
686 EXPORT_SYMBOL(ip_tunnel_metadata_cnt);
688 void ip_tunnel_need_metadata(void)
690 static_branch_inc(&ip_tunnel_metadata_cnt);
692 EXPORT_SYMBOL_GPL(ip_tunnel_need_metadata);
694 void ip_tunnel_unneed_metadata(void)
696 static_branch_dec(&ip_tunnel_metadata_cnt);
698 EXPORT_SYMBOL_GPL(ip_tunnel_unneed_metadata);