2 * GRE over IPv6 protocol decoder.
4 * Authors: Dmitry Kozlov (xeb@mail.ru)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/capability.h>
16 #include <linux/module.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/slab.h>
20 #include <linux/uaccess.h>
21 #include <linux/skbuff.h>
22 #include <linux/netdevice.h>
24 #include <linux/tcp.h>
25 #include <linux/udp.h>
26 #include <linux/if_arp.h>
27 #include <linux/init.h>
28 #include <linux/in6.h>
29 #include <linux/inetdevice.h>
30 #include <linux/igmp.h>
31 #include <linux/netfilter_ipv4.h>
32 #include <linux/etherdevice.h>
33 #include <linux/if_ether.h>
34 #include <linux/hash.h>
35 #include <linux/if_tunnel.h>
36 #include <linux/ip6_tunnel.h>
40 #include <net/ip_tunnels.h>
42 #include <net/protocol.h>
43 #include <net/addrconf.h>
45 #include <net/checksum.h>
46 #include <net/dsfield.h>
47 #include <net/inet_ecn.h>
49 #include <net/net_namespace.h>
50 #include <net/netns/generic.h>
51 #include <net/rtnetlink.h>
54 #include <net/ip6_fib.h>
55 #include <net/ip6_route.h>
56 #include <net/ip6_tunnel.h>
58 #include <net/erspan.h>
59 #include <net/dst_metadata.h>
62 static bool log_ecn_error
= true;
63 module_param(log_ecn_error
, bool, 0644);
64 MODULE_PARM_DESC(log_ecn_error
, "Log packets received with corrupted ECN");
66 #define IP6_GRE_HASH_SIZE_SHIFT 5
67 #define IP6_GRE_HASH_SIZE (1 << IP6_GRE_HASH_SIZE_SHIFT)
69 static unsigned int ip6gre_net_id __read_mostly
;
71 struct ip6_tnl __rcu
*tunnels
[4][IP6_GRE_HASH_SIZE
];
73 struct ip6_tnl __rcu
*collect_md_tun
;
74 struct net_device
*fb_tunnel_dev
;
77 static struct rtnl_link_ops ip6gre_link_ops __read_mostly
;
78 static struct rtnl_link_ops ip6gre_tap_ops __read_mostly
;
79 static struct rtnl_link_ops ip6erspan_tap_ops __read_mostly
;
80 static int ip6gre_tunnel_init(struct net_device
*dev
);
81 static void ip6gre_tunnel_setup(struct net_device
*dev
);
82 static void ip6gre_tunnel_link(struct ip6gre_net
*ign
, struct ip6_tnl
*t
);
83 static void ip6gre_tnl_link_config(struct ip6_tnl
*t
, int set_mtu
);
85 /* Tunnel hash table */
95 We require exact key match i.e. if a key is present in packet
96 it will match only tunnel with the same key; if it is not present,
97 it will match only keyless tunnel.
99 All keysless packets, if not matched configured keyless tunnels
100 will match fallback tunnel.
103 #define HASH_KEY(key) (((__force u32)key^((__force u32)key>>4))&(IP6_GRE_HASH_SIZE - 1))
104 static u32
HASH_ADDR(const struct in6_addr
*addr
)
106 u32 hash
= ipv6_addr_hash(addr
);
108 return hash_32(hash
, IP6_GRE_HASH_SIZE_SHIFT
);
111 #define tunnels_r_l tunnels[3]
112 #define tunnels_r tunnels[2]
113 #define tunnels_l tunnels[1]
114 #define tunnels_wc tunnels[0]
116 /* Given src, dst and key, find appropriate for input tunnel. */
118 static struct ip6_tnl
*ip6gre_tunnel_lookup(struct net_device
*dev
,
119 const struct in6_addr
*remote
, const struct in6_addr
*local
,
120 __be32 key
, __be16 gre_proto
)
122 struct net
*net
= dev_net(dev
);
123 int link
= dev
->ifindex
;
124 unsigned int h0
= HASH_ADDR(remote
);
125 unsigned int h1
= HASH_KEY(key
);
126 struct ip6_tnl
*t
, *cand
= NULL
;
127 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
128 int dev_type
= (gre_proto
== htons(ETH_P_TEB
) ||
129 gre_proto
== htons(ETH_P_ERSPAN
) ||
130 gre_proto
== htons(ETH_P_ERSPAN2
)) ?
131 ARPHRD_ETHER
: ARPHRD_IP6GRE
;
132 int score
, cand_score
= 4;
134 for_each_ip_tunnel_rcu(t
, ign
->tunnels_r_l
[h0
^ h1
]) {
135 if (!ipv6_addr_equal(local
, &t
->parms
.laddr
) ||
136 !ipv6_addr_equal(remote
, &t
->parms
.raddr
) ||
137 key
!= t
->parms
.i_key
||
138 !(t
->dev
->flags
& IFF_UP
))
141 if (t
->dev
->type
!= ARPHRD_IP6GRE
&&
142 t
->dev
->type
!= dev_type
)
146 if (t
->parms
.link
!= link
)
148 if (t
->dev
->type
!= dev_type
)
153 if (score
< cand_score
) {
159 for_each_ip_tunnel_rcu(t
, ign
->tunnels_r
[h0
^ h1
]) {
160 if (!ipv6_addr_equal(remote
, &t
->parms
.raddr
) ||
161 key
!= t
->parms
.i_key
||
162 !(t
->dev
->flags
& IFF_UP
))
165 if (t
->dev
->type
!= ARPHRD_IP6GRE
&&
166 t
->dev
->type
!= dev_type
)
170 if (t
->parms
.link
!= link
)
172 if (t
->dev
->type
!= dev_type
)
177 if (score
< cand_score
) {
183 for_each_ip_tunnel_rcu(t
, ign
->tunnels_l
[h1
]) {
184 if ((!ipv6_addr_equal(local
, &t
->parms
.laddr
) &&
185 (!ipv6_addr_equal(local
, &t
->parms
.raddr
) ||
186 !ipv6_addr_is_multicast(local
))) ||
187 key
!= t
->parms
.i_key
||
188 !(t
->dev
->flags
& IFF_UP
))
191 if (t
->dev
->type
!= ARPHRD_IP6GRE
&&
192 t
->dev
->type
!= dev_type
)
196 if (t
->parms
.link
!= link
)
198 if (t
->dev
->type
!= dev_type
)
203 if (score
< cand_score
) {
209 for_each_ip_tunnel_rcu(t
, ign
->tunnels_wc
[h1
]) {
210 if (t
->parms
.i_key
!= key
||
211 !(t
->dev
->flags
& IFF_UP
))
214 if (t
->dev
->type
!= ARPHRD_IP6GRE
&&
215 t
->dev
->type
!= dev_type
)
219 if (t
->parms
.link
!= link
)
221 if (t
->dev
->type
!= dev_type
)
226 if (score
< cand_score
) {
235 t
= rcu_dereference(ign
->collect_md_tun
);
236 if (t
&& t
->dev
->flags
& IFF_UP
)
239 dev
= ign
->fb_tunnel_dev
;
240 if (dev
&& dev
->flags
& IFF_UP
)
241 return netdev_priv(dev
);
246 static struct ip6_tnl __rcu
**__ip6gre_bucket(struct ip6gre_net
*ign
,
247 const struct __ip6_tnl_parm
*p
)
249 const struct in6_addr
*remote
= &p
->raddr
;
250 const struct in6_addr
*local
= &p
->laddr
;
251 unsigned int h
= HASH_KEY(p
->i_key
);
254 if (!ipv6_addr_any(local
))
256 if (!ipv6_addr_any(remote
) && !ipv6_addr_is_multicast(remote
)) {
258 h
^= HASH_ADDR(remote
);
261 return &ign
->tunnels
[prio
][h
];
264 static inline struct ip6_tnl __rcu
**ip6gre_bucket(struct ip6gre_net
*ign
,
265 const struct ip6_tnl
*t
)
267 return __ip6gre_bucket(ign
, &t
->parms
);
270 static void ip6gre_tunnel_link(struct ip6gre_net
*ign
, struct ip6_tnl
*t
)
272 struct ip6_tnl __rcu
**tp
= ip6gre_bucket(ign
, t
);
274 if (t
->parms
.collect_md
)
275 rcu_assign_pointer(ign
->collect_md_tun
, t
);
277 rcu_assign_pointer(t
->next
, rtnl_dereference(*tp
));
278 rcu_assign_pointer(*tp
, t
);
281 static void ip6gre_tunnel_unlink(struct ip6gre_net
*ign
, struct ip6_tnl
*t
)
283 struct ip6_tnl __rcu
**tp
;
284 struct ip6_tnl
*iter
;
286 if (t
->parms
.collect_md
)
287 rcu_assign_pointer(ign
->collect_md_tun
, NULL
);
289 for (tp
= ip6gre_bucket(ign
, t
);
290 (iter
= rtnl_dereference(*tp
)) != NULL
;
293 rcu_assign_pointer(*tp
, t
->next
);
299 static struct ip6_tnl
*ip6gre_tunnel_find(struct net
*net
,
300 const struct __ip6_tnl_parm
*parms
,
303 const struct in6_addr
*remote
= &parms
->raddr
;
304 const struct in6_addr
*local
= &parms
->laddr
;
305 __be32 key
= parms
->i_key
;
306 int link
= parms
->link
;
308 struct ip6_tnl __rcu
**tp
;
309 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
311 for (tp
= __ip6gre_bucket(ign
, parms
);
312 (t
= rtnl_dereference(*tp
)) != NULL
;
314 if (ipv6_addr_equal(local
, &t
->parms
.laddr
) &&
315 ipv6_addr_equal(remote
, &t
->parms
.raddr
) &&
316 key
== t
->parms
.i_key
&&
317 link
== t
->parms
.link
&&
318 type
== t
->dev
->type
)
324 static struct ip6_tnl
*ip6gre_tunnel_locate(struct net
*net
,
325 const struct __ip6_tnl_parm
*parms
, int create
)
327 struct ip6_tnl
*t
, *nt
;
328 struct net_device
*dev
;
330 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
332 t
= ip6gre_tunnel_find(net
, parms
, ARPHRD_IP6GRE
);
338 if (parms
->name
[0]) {
339 if (!dev_valid_name(parms
->name
))
341 strlcpy(name
, parms
->name
, IFNAMSIZ
);
343 strcpy(name
, "ip6gre%d");
345 dev
= alloc_netdev(sizeof(*t
), name
, NET_NAME_UNKNOWN
,
346 ip6gre_tunnel_setup
);
350 dev_net_set(dev
, net
);
352 nt
= netdev_priv(dev
);
354 dev
->rtnl_link_ops
= &ip6gre_link_ops
;
357 nt
->net
= dev_net(dev
);
359 if (register_netdevice(dev
) < 0)
362 ip6gre_tnl_link_config(nt
, 1);
364 /* Can use a lockless transmit, unless we generate output sequences */
365 if (!(nt
->parms
.o_flags
& TUNNEL_SEQ
))
366 dev
->features
|= NETIF_F_LLTX
;
369 ip6gre_tunnel_link(ign
, nt
);
377 static void ip6gre_tunnel_uninit(struct net_device
*dev
)
379 struct ip6_tnl
*t
= netdev_priv(dev
);
380 struct ip6gre_net
*ign
= net_generic(t
->net
, ip6gre_net_id
);
382 ip6gre_tunnel_unlink(ign
, t
);
383 dst_cache_reset(&t
->dst_cache
);
388 static void ip6gre_err(struct sk_buff
*skb
, struct inet6_skb_parm
*opt
,
389 u8 type
, u8 code
, int offset
, __be32 info
)
391 struct net
*net
= dev_net(skb
->dev
);
392 const struct gre_base_hdr
*greh
;
393 const struct ipv6hdr
*ipv6h
;
394 int grehlen
= sizeof(*greh
);
400 if (!pskb_may_pull(skb
, offset
+ grehlen
))
402 greh
= (const struct gre_base_hdr
*)(skb
->data
+ offset
);
404 if (flags
& (GRE_VERSION
| GRE_ROUTING
))
406 if (flags
& GRE_CSUM
)
408 if (flags
& GRE_KEY
) {
409 key_off
= grehlen
+ offset
;
413 if (!pskb_may_pull(skb
, offset
+ grehlen
))
415 ipv6h
= (const struct ipv6hdr
*)skb
->data
;
416 greh
= (const struct gre_base_hdr
*)(skb
->data
+ offset
);
417 key
= key_off
? *(__be32
*)(skb
->data
+ key_off
) : 0;
419 t
= ip6gre_tunnel_lookup(skb
->dev
, &ipv6h
->daddr
, &ipv6h
->saddr
,
420 key
, greh
->protocol
);
425 struct ipv6_tlv_tnl_enc_lim
*tel
;
427 case ICMPV6_DEST_UNREACH
:
428 net_dbg_ratelimited("%s: Path to destination invalid or inactive!\n",
430 if (code
!= ICMPV6_PORT_UNREACH
)
433 case ICMPV6_TIME_EXCEED
:
434 if (code
== ICMPV6_EXC_HOPLIMIT
) {
435 net_dbg_ratelimited("%s: Too small hop limit or routing loop in tunnel!\n",
440 case ICMPV6_PARAMPROB
:
442 if (code
== ICMPV6_HDR_FIELD
)
443 teli
= ip6_tnl_parse_tlv_enc_lim(skb
, skb
->data
);
445 if (teli
&& teli
== be32_to_cpu(info
) - 2) {
446 tel
= (struct ipv6_tlv_tnl_enc_lim
*) &skb
->data
[teli
];
447 if (tel
->encap_limit
== 0) {
448 net_dbg_ratelimited("%s: Too small encapsulation limit or routing loop in tunnel!\n",
452 net_dbg_ratelimited("%s: Recipient unable to parse tunneled packet!\n",
456 case ICMPV6_PKT_TOOBIG
:
457 ip6_update_pmtu(skb
, net
, info
, 0, 0, sock_net_uid(net
, NULL
));
460 ip6_redirect(skb
, net
, skb
->dev
->ifindex
, 0,
461 sock_net_uid(net
, NULL
));
465 if (time_before(jiffies
, t
->err_time
+ IP6TUNNEL_ERR_TIMEO
))
469 t
->err_time
= jiffies
;
472 static int ip6gre_rcv(struct sk_buff
*skb
, const struct tnl_ptk_info
*tpi
)
474 const struct ipv6hdr
*ipv6h
;
475 struct ip6_tnl
*tunnel
;
477 ipv6h
= ipv6_hdr(skb
);
478 tunnel
= ip6gre_tunnel_lookup(skb
->dev
,
479 &ipv6h
->saddr
, &ipv6h
->daddr
, tpi
->key
,
482 if (tunnel
->parms
.collect_md
) {
483 struct metadata_dst
*tun_dst
;
488 tun_id
= key32_to_tunnel_id(tpi
->key
);
490 tun_dst
= ipv6_tun_rx_dst(skb
, flags
, tun_id
, 0);
492 return PACKET_REJECT
;
494 ip6_tnl_rcv(tunnel
, skb
, tpi
, tun_dst
, log_ecn_error
);
496 ip6_tnl_rcv(tunnel
, skb
, tpi
, NULL
, log_ecn_error
);
502 return PACKET_REJECT
;
505 static int ip6erspan_rcv(struct sk_buff
*skb
, int gre_hdr_len
,
506 struct tnl_ptk_info
*tpi
)
508 struct erspan_base_hdr
*ershdr
;
509 struct erspan_metadata
*pkt_md
;
510 const struct ipv6hdr
*ipv6h
;
511 struct erspan_md2
*md2
;
512 struct ip6_tnl
*tunnel
;
515 if (unlikely(!pskb_may_pull(skb
, sizeof(*ershdr
))))
516 return PACKET_REJECT
;
518 ipv6h
= ipv6_hdr(skb
);
519 ershdr
= (struct erspan_base_hdr
*)skb
->data
;
521 tpi
->key
= cpu_to_be32(get_session_id(ershdr
));
523 tunnel
= ip6gre_tunnel_lookup(skb
->dev
,
524 &ipv6h
->saddr
, &ipv6h
->daddr
, tpi
->key
,
527 int len
= erspan_hdr_len(ver
);
529 if (unlikely(!pskb_may_pull(skb
, len
)))
530 return PACKET_REJECT
;
532 ershdr
= (struct erspan_base_hdr
*)skb
->data
;
533 pkt_md
= (struct erspan_metadata
*)(ershdr
+ 1);
535 if (__iptunnel_pull_header(skb
, len
,
538 return PACKET_REJECT
;
540 if (tunnel
->parms
.collect_md
) {
541 struct metadata_dst
*tun_dst
;
542 struct ip_tunnel_info
*info
;
543 struct erspan_metadata
*md
;
547 tpi
->flags
|= TUNNEL_KEY
;
549 tun_id
= key32_to_tunnel_id(tpi
->key
);
551 tun_dst
= ipv6_tun_rx_dst(skb
, flags
, tun_id
,
554 return PACKET_REJECT
;
556 info
= &tun_dst
->u
.tun_info
;
557 md
= ip_tunnel_info_opts(info
);
560 memcpy(md2
, pkt_md
, ver
== 1 ? ERSPAN_V1_MDSIZE
:
562 info
->key
.tun_flags
|= TUNNEL_ERSPAN_OPT
;
563 info
->options_len
= sizeof(*md
);
565 ip6_tnl_rcv(tunnel
, skb
, tpi
, tun_dst
, log_ecn_error
);
568 ip6_tnl_rcv(tunnel
, skb
, tpi
, NULL
, log_ecn_error
);
574 return PACKET_REJECT
;
577 static int gre_rcv(struct sk_buff
*skb
)
579 struct tnl_ptk_info tpi
;
580 bool csum_err
= false;
583 hdr_len
= gre_parse_header(skb
, &tpi
, &csum_err
, htons(ETH_P_IPV6
), 0);
587 if (iptunnel_pull_header(skb
, hdr_len
, tpi
.proto
, false))
590 if (unlikely(tpi
.proto
== htons(ETH_P_ERSPAN
) ||
591 tpi
.proto
== htons(ETH_P_ERSPAN2
))) {
592 if (ip6erspan_rcv(skb
, hdr_len
, &tpi
) == PACKET_RCVD
)
597 if (ip6gre_rcv(skb
, &tpi
) == PACKET_RCVD
)
601 icmpv6_send(skb
, ICMPV6_DEST_UNREACH
, ICMPV6_PORT_UNREACH
, 0);
607 static int gre_handle_offloads(struct sk_buff
*skb
, bool csum
)
609 return iptunnel_handle_offloads(skb
,
610 csum
? SKB_GSO_GRE_CSUM
: SKB_GSO_GRE
);
613 static void prepare_ip6gre_xmit_ipv4(struct sk_buff
*skb
,
614 struct net_device
*dev
,
615 struct flowi6
*fl6
, __u8
*dsfield
,
618 const struct iphdr
*iph
= ip_hdr(skb
);
619 struct ip6_tnl
*t
= netdev_priv(dev
);
621 if (!(t
->parms
.flags
& IP6_TNL_F_IGN_ENCAP_LIMIT
))
622 *encap_limit
= t
->parms
.encap_limit
;
624 memcpy(fl6
, &t
->fl
.u
.ip6
, sizeof(*fl6
));
626 if (t
->parms
.flags
& IP6_TNL_F_USE_ORIG_TCLASS
)
627 *dsfield
= ipv4_get_dsfield(iph
);
629 *dsfield
= ip6_tclass(t
->parms
.flowinfo
);
631 if (t
->parms
.flags
& IP6_TNL_F_USE_ORIG_FWMARK
)
632 fl6
->flowi6_mark
= skb
->mark
;
634 fl6
->flowi6_mark
= t
->parms
.fwmark
;
636 fl6
->flowi6_uid
= sock_net_uid(dev_net(dev
), NULL
);
639 static int prepare_ip6gre_xmit_ipv6(struct sk_buff
*skb
,
640 struct net_device
*dev
,
641 struct flowi6
*fl6
, __u8
*dsfield
,
644 struct ipv6hdr
*ipv6h
= ipv6_hdr(skb
);
645 struct ip6_tnl
*t
= netdev_priv(dev
);
648 offset
= ip6_tnl_parse_tlv_enc_lim(skb
, skb_network_header(skb
));
649 /* ip6_tnl_parse_tlv_enc_lim() might have reallocated skb->head */
652 struct ipv6_tlv_tnl_enc_lim
*tel
;
654 tel
= (struct ipv6_tlv_tnl_enc_lim
*)&skb_network_header(skb
)[offset
];
655 if (tel
->encap_limit
== 0) {
656 icmpv6_send(skb
, ICMPV6_PARAMPROB
,
657 ICMPV6_HDR_FIELD
, offset
+ 2);
660 *encap_limit
= tel
->encap_limit
- 1;
661 } else if (!(t
->parms
.flags
& IP6_TNL_F_IGN_ENCAP_LIMIT
)) {
662 *encap_limit
= t
->parms
.encap_limit
;
665 memcpy(fl6
, &t
->fl
.u
.ip6
, sizeof(*fl6
));
667 if (t
->parms
.flags
& IP6_TNL_F_USE_ORIG_TCLASS
)
668 *dsfield
= ipv6_get_dsfield(ipv6h
);
670 *dsfield
= ip6_tclass(t
->parms
.flowinfo
);
672 if (t
->parms
.flags
& IP6_TNL_F_USE_ORIG_FLOWLABEL
)
673 fl6
->flowlabel
|= ip6_flowlabel(ipv6h
);
675 if (t
->parms
.flags
& IP6_TNL_F_USE_ORIG_FWMARK
)
676 fl6
->flowi6_mark
= skb
->mark
;
678 fl6
->flowi6_mark
= t
->parms
.fwmark
;
680 fl6
->flowi6_uid
= sock_net_uid(dev_net(dev
), NULL
);
685 static netdev_tx_t
__gre6_xmit(struct sk_buff
*skb
,
686 struct net_device
*dev
, __u8 dsfield
,
687 struct flowi6
*fl6
, int encap_limit
,
688 __u32
*pmtu
, __be16 proto
)
690 struct ip6_tnl
*tunnel
= netdev_priv(dev
);
693 if (dev
->type
== ARPHRD_ETHER
)
694 IPCB(skb
)->flags
= 0;
696 if (dev
->header_ops
&& dev
->type
== ARPHRD_IP6GRE
)
697 fl6
->daddr
= ((struct ipv6hdr
*)skb
->data
)->daddr
;
699 fl6
->daddr
= tunnel
->parms
.raddr
;
701 /* Push GRE header. */
702 protocol
= (dev
->type
== ARPHRD_ETHER
) ? htons(ETH_P_TEB
) : proto
;
704 if (tunnel
->parms
.collect_md
) {
705 struct ip_tunnel_info
*tun_info
;
706 const struct ip_tunnel_key
*key
;
709 tun_info
= skb_tunnel_info(skb
);
710 if (unlikely(!tun_info
||
711 !(tun_info
->mode
& IP_TUNNEL_INFO_TX
) ||
712 ip_tunnel_info_af(tun_info
) != AF_INET6
))
715 key
= &tun_info
->key
;
716 memset(fl6
, 0, sizeof(*fl6
));
717 fl6
->flowi6_proto
= IPPROTO_GRE
;
718 fl6
->daddr
= key
->u
.ipv6
.dst
;
719 fl6
->flowlabel
= key
->label
;
720 fl6
->flowi6_uid
= sock_net_uid(dev_net(dev
), NULL
);
723 flags
= key
->tun_flags
&
724 (TUNNEL_CSUM
| TUNNEL_KEY
| TUNNEL_SEQ
);
725 tunnel
->tun_hlen
= gre_calc_hlen(flags
);
727 gre_build_header(skb
, tunnel
->tun_hlen
,
729 tunnel_id_to_key32(tun_info
->key
.tun_id
),
730 (flags
& TUNNEL_SEQ
) ? htonl(tunnel
->o_seqno
++)
734 if (tunnel
->parms
.o_flags
& TUNNEL_SEQ
)
737 gre_build_header(skb
, tunnel
->tun_hlen
, tunnel
->parms
.o_flags
,
738 protocol
, tunnel
->parms
.o_key
,
739 htonl(tunnel
->o_seqno
));
742 return ip6_tnl_xmit(skb
, dev
, dsfield
, fl6
, encap_limit
, pmtu
,
746 static inline int ip6gre_xmit_ipv4(struct sk_buff
*skb
, struct net_device
*dev
)
748 struct ip6_tnl
*t
= netdev_priv(dev
);
749 int encap_limit
= -1;
755 memset(&(IPCB(skb
)->opt
), 0, sizeof(IPCB(skb
)->opt
));
757 if (!t
->parms
.collect_md
)
758 prepare_ip6gre_xmit_ipv4(skb
, dev
, &fl6
,
759 &dsfield
, &encap_limit
);
761 err
= gre_handle_offloads(skb
, !!(t
->parms
.o_flags
& TUNNEL_CSUM
));
765 err
= __gre6_xmit(skb
, dev
, dsfield
, &fl6
, encap_limit
, &mtu
,
768 /* XXX: send ICMP error even if DF is not set. */
769 if (err
== -EMSGSIZE
)
770 icmp_send(skb
, ICMP_DEST_UNREACH
, ICMP_FRAG_NEEDED
,
778 static inline int ip6gre_xmit_ipv6(struct sk_buff
*skb
, struct net_device
*dev
)
780 struct ip6_tnl
*t
= netdev_priv(dev
);
781 struct ipv6hdr
*ipv6h
= ipv6_hdr(skb
);
782 int encap_limit
= -1;
788 if (ipv6_addr_equal(&t
->parms
.raddr
, &ipv6h
->saddr
))
791 if (!t
->parms
.collect_md
&&
792 prepare_ip6gre_xmit_ipv6(skb
, dev
, &fl6
, &dsfield
, &encap_limit
))
795 if (gre_handle_offloads(skb
, !!(t
->parms
.o_flags
& TUNNEL_CSUM
)))
798 err
= __gre6_xmit(skb
, dev
, dsfield
, &fl6
, encap_limit
,
799 &mtu
, skb
->protocol
);
801 if (err
== -EMSGSIZE
)
802 icmpv6_send(skb
, ICMPV6_PKT_TOOBIG
, 0, mtu
);
810 * ip6_tnl_addr_conflict - compare packet addresses to tunnel's own
811 * @t: the outgoing tunnel device
812 * @hdr: IPv6 header from the incoming packet
815 * Avoid trivial tunneling loop by checking that tunnel exit-point
816 * doesn't match source of incoming packet.
823 static inline bool ip6gre_tnl_addr_conflict(const struct ip6_tnl
*t
,
824 const struct ipv6hdr
*hdr
)
826 return ipv6_addr_equal(&t
->parms
.raddr
, &hdr
->saddr
);
829 static int ip6gre_xmit_other(struct sk_buff
*skb
, struct net_device
*dev
)
831 struct ip6_tnl
*t
= netdev_priv(dev
);
832 int encap_limit
= -1;
837 if (!(t
->parms
.flags
& IP6_TNL_F_IGN_ENCAP_LIMIT
))
838 encap_limit
= t
->parms
.encap_limit
;
840 if (!t
->parms
.collect_md
)
841 memcpy(&fl6
, &t
->fl
.u
.ip6
, sizeof(fl6
));
843 err
= gre_handle_offloads(skb
, !!(t
->parms
.o_flags
& TUNNEL_CSUM
));
847 err
= __gre6_xmit(skb
, dev
, 0, &fl6
, encap_limit
, &mtu
, skb
->protocol
);
852 static netdev_tx_t
ip6gre_tunnel_xmit(struct sk_buff
*skb
,
853 struct net_device
*dev
)
855 struct ip6_tnl
*t
= netdev_priv(dev
);
856 struct net_device_stats
*stats
= &t
->dev
->stats
;
859 if (!ip6_tnl_xmit_ctl(t
, &t
->parms
.laddr
, &t
->parms
.raddr
))
862 switch (skb
->protocol
) {
863 case htons(ETH_P_IP
):
864 ret
= ip6gre_xmit_ipv4(skb
, dev
);
866 case htons(ETH_P_IPV6
):
867 ret
= ip6gre_xmit_ipv6(skb
, dev
);
870 ret
= ip6gre_xmit_other(skb
, dev
);
886 static netdev_tx_t
ip6erspan_tunnel_xmit(struct sk_buff
*skb
,
887 struct net_device
*dev
)
889 struct ipv6hdr
*ipv6h
= ipv6_hdr(skb
);
890 struct ip6_tnl
*t
= netdev_priv(dev
);
891 struct dst_entry
*dst
= skb_dst(skb
);
892 struct net_device_stats
*stats
;
893 bool truncate
= false;
894 int encap_limit
= -1;
895 __u8 dsfield
= false;
900 if (!ip6_tnl_xmit_ctl(t
, &t
->parms
.laddr
, &t
->parms
.raddr
))
903 if (gre_handle_offloads(skb
, false))
906 if (skb
->len
> dev
->mtu
+ dev
->hard_header_len
) {
907 pskb_trim(skb
, dev
->mtu
+ dev
->hard_header_len
);
911 if (skb_cow_head(skb
, dev
->needed_headroom
))
914 t
->parms
.o_flags
&= ~TUNNEL_KEY
;
915 IPCB(skb
)->flags
= 0;
917 /* For collect_md mode, derive fl6 from the tunnel key,
918 * for native mode, call prepare_ip6gre_xmit_{ipv4,ipv6}.
920 if (t
->parms
.collect_md
) {
921 struct ip_tunnel_info
*tun_info
;
922 const struct ip_tunnel_key
*key
;
923 struct erspan_metadata
*md
;
926 tun_info
= skb_tunnel_info(skb
);
927 if (unlikely(!tun_info
||
928 !(tun_info
->mode
& IP_TUNNEL_INFO_TX
) ||
929 ip_tunnel_info_af(tun_info
) != AF_INET6
))
932 key
= &tun_info
->key
;
933 memset(&fl6
, 0, sizeof(fl6
));
934 fl6
.flowi6_proto
= IPPROTO_GRE
;
935 fl6
.daddr
= key
->u
.ipv6
.dst
;
936 fl6
.flowlabel
= key
->label
;
937 fl6
.flowi6_uid
= sock_net_uid(dev_net(dev
), NULL
);
940 md
= ip_tunnel_info_opts(tun_info
);
944 tun_id
= tunnel_id_to_key32(key
->tun_id
);
945 if (md
->version
== 1) {
946 erspan_build_header(skb
,
948 ntohl(md
->u
.index
), truncate
,
950 } else if (md
->version
== 2) {
951 erspan_build_header_v2(skb
,
954 get_hwid(&md
->u
.md2
),
960 switch (skb
->protocol
) {
961 case htons(ETH_P_IP
):
962 memset(&(IPCB(skb
)->opt
), 0, sizeof(IPCB(skb
)->opt
));
963 prepare_ip6gre_xmit_ipv4(skb
, dev
, &fl6
,
964 &dsfield
, &encap_limit
);
966 case htons(ETH_P_IPV6
):
967 if (ipv6_addr_equal(&t
->parms
.raddr
, &ipv6h
->saddr
))
969 if (prepare_ip6gre_xmit_ipv6(skb
, dev
, &fl6
,
970 &dsfield
, &encap_limit
))
974 memcpy(&fl6
, &t
->fl
.u
.ip6
, sizeof(fl6
));
978 if (t
->parms
.erspan_ver
== 1)
979 erspan_build_header(skb
, ntohl(t
->parms
.o_key
),
983 erspan_build_header_v2(skb
, ntohl(t
->parms
.o_key
),
987 fl6
.daddr
= t
->parms
.raddr
;
990 /* Push GRE header. */
991 gre_build_header(skb
, 8, TUNNEL_SEQ
,
992 htons(ETH_P_ERSPAN
), 0, htonl(t
->o_seqno
++));
994 /* TooBig packet may have updated dst->dev's mtu */
995 if (!t
->parms
.collect_md
&& dst
&& dst_mtu(dst
) > dst
->dev
->mtu
)
996 dst
->ops
->update_pmtu(dst
, NULL
, skb
, dst
->dev
->mtu
);
998 err
= ip6_tnl_xmit(skb
, dev
, dsfield
, &fl6
, encap_limit
, &mtu
,
1001 /* XXX: send ICMP error even if DF is not set. */
1002 if (err
== -EMSGSIZE
) {
1003 if (skb
->protocol
== htons(ETH_P_IP
))
1004 icmp_send(skb
, ICMP_DEST_UNREACH
,
1005 ICMP_FRAG_NEEDED
, htonl(mtu
));
1007 icmpv6_send(skb
, ICMPV6_PKT_TOOBIG
, 0, mtu
);
1012 return NETDEV_TX_OK
;
1015 stats
= &t
->dev
->stats
;
1017 stats
->tx_dropped
++;
1019 return NETDEV_TX_OK
;
1022 static void ip6gre_tnl_link_config(struct ip6_tnl
*t
, int set_mtu
)
1024 struct net_device
*dev
= t
->dev
;
1025 struct __ip6_tnl_parm
*p
= &t
->parms
;
1026 struct flowi6
*fl6
= &t
->fl
.u
.ip6
;
1029 if (dev
->type
!= ARPHRD_ETHER
) {
1030 memcpy(dev
->dev_addr
, &p
->laddr
, sizeof(struct in6_addr
));
1031 memcpy(dev
->broadcast
, &p
->raddr
, sizeof(struct in6_addr
));
1034 /* Set up flowi template */
1035 fl6
->saddr
= p
->laddr
;
1036 fl6
->daddr
= p
->raddr
;
1037 fl6
->flowi6_oif
= p
->link
;
1039 fl6
->flowi6_proto
= IPPROTO_GRE
;
1041 if (!(p
->flags
&IP6_TNL_F_USE_ORIG_TCLASS
))
1042 fl6
->flowlabel
|= IPV6_TCLASS_MASK
& p
->flowinfo
;
1043 if (!(p
->flags
&IP6_TNL_F_USE_ORIG_FLOWLABEL
))
1044 fl6
->flowlabel
|= IPV6_FLOWLABEL_MASK
& p
->flowinfo
;
1046 p
->flags
&= ~(IP6_TNL_F_CAP_XMIT
|IP6_TNL_F_CAP_RCV
|IP6_TNL_F_CAP_PER_PACKET
);
1047 p
->flags
|= ip6_tnl_get_cap(t
, &p
->laddr
, &p
->raddr
);
1049 if (p
->flags
&IP6_TNL_F_CAP_XMIT
&&
1050 p
->flags
&IP6_TNL_F_CAP_RCV
&& dev
->type
!= ARPHRD_ETHER
)
1051 dev
->flags
|= IFF_POINTOPOINT
;
1053 dev
->flags
&= ~IFF_POINTOPOINT
;
1055 t
->tun_hlen
= gre_calc_hlen(t
->parms
.o_flags
);
1057 t
->hlen
= t
->encap_hlen
+ t
->tun_hlen
;
1059 t_hlen
= t
->hlen
+ sizeof(struct ipv6hdr
);
1061 if (p
->flags
& IP6_TNL_F_CAP_XMIT
) {
1062 int strict
= (ipv6_addr_type(&p
->raddr
) &
1063 (IPV6_ADDR_MULTICAST
|IPV6_ADDR_LINKLOCAL
));
1065 struct rt6_info
*rt
= rt6_lookup(t
->net
,
1066 &p
->raddr
, &p
->laddr
,
1067 p
->link
, NULL
, strict
);
1073 dev
->hard_header_len
= rt
->dst
.dev
->hard_header_len
+
1077 dev
->mtu
= rt
->dst
.dev
->mtu
- t_hlen
;
1078 if (!(t
->parms
.flags
& IP6_TNL_F_IGN_ENCAP_LIMIT
))
1080 if (dev
->type
== ARPHRD_ETHER
)
1081 dev
->mtu
-= ETH_HLEN
;
1083 if (dev
->mtu
< IPV6_MIN_MTU
)
1084 dev
->mtu
= IPV6_MIN_MTU
;
1091 static int ip6gre_tnl_change(struct ip6_tnl
*t
,
1092 const struct __ip6_tnl_parm
*p
, int set_mtu
)
1094 t
->parms
.laddr
= p
->laddr
;
1095 t
->parms
.raddr
= p
->raddr
;
1096 t
->parms
.flags
= p
->flags
;
1097 t
->parms
.hop_limit
= p
->hop_limit
;
1098 t
->parms
.encap_limit
= p
->encap_limit
;
1099 t
->parms
.flowinfo
= p
->flowinfo
;
1100 t
->parms
.link
= p
->link
;
1101 t
->parms
.proto
= p
->proto
;
1102 t
->parms
.i_key
= p
->i_key
;
1103 t
->parms
.o_key
= p
->o_key
;
1104 t
->parms
.i_flags
= p
->i_flags
;
1105 t
->parms
.o_flags
= p
->o_flags
;
1106 t
->parms
.fwmark
= p
->fwmark
;
1107 dst_cache_reset(&t
->dst_cache
);
1108 ip6gre_tnl_link_config(t
, set_mtu
);
1112 static void ip6gre_tnl_parm_from_user(struct __ip6_tnl_parm
*p
,
1113 const struct ip6_tnl_parm2
*u
)
1115 p
->laddr
= u
->laddr
;
1116 p
->raddr
= u
->raddr
;
1117 p
->flags
= u
->flags
;
1118 p
->hop_limit
= u
->hop_limit
;
1119 p
->encap_limit
= u
->encap_limit
;
1120 p
->flowinfo
= u
->flowinfo
;
1122 p
->i_key
= u
->i_key
;
1123 p
->o_key
= u
->o_key
;
1124 p
->i_flags
= gre_flags_to_tnl_flags(u
->i_flags
);
1125 p
->o_flags
= gre_flags_to_tnl_flags(u
->o_flags
);
1126 memcpy(p
->name
, u
->name
, sizeof(u
->name
));
1129 static void ip6gre_tnl_parm_to_user(struct ip6_tnl_parm2
*u
,
1130 const struct __ip6_tnl_parm
*p
)
1132 u
->proto
= IPPROTO_GRE
;
1133 u
->laddr
= p
->laddr
;
1134 u
->raddr
= p
->raddr
;
1135 u
->flags
= p
->flags
;
1136 u
->hop_limit
= p
->hop_limit
;
1137 u
->encap_limit
= p
->encap_limit
;
1138 u
->flowinfo
= p
->flowinfo
;
1140 u
->i_key
= p
->i_key
;
1141 u
->o_key
= p
->o_key
;
1142 u
->i_flags
= gre_tnl_flags_to_gre_flags(p
->i_flags
);
1143 u
->o_flags
= gre_tnl_flags_to_gre_flags(p
->o_flags
);
1144 memcpy(u
->name
, p
->name
, sizeof(u
->name
));
1147 static int ip6gre_tunnel_ioctl(struct net_device
*dev
,
1148 struct ifreq
*ifr
, int cmd
)
1151 struct ip6_tnl_parm2 p
;
1152 struct __ip6_tnl_parm p1
;
1153 struct ip6_tnl
*t
= netdev_priv(dev
);
1154 struct net
*net
= t
->net
;
1155 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
1157 memset(&p1
, 0, sizeof(p1
));
1161 if (dev
== ign
->fb_tunnel_dev
) {
1162 if (copy_from_user(&p
, ifr
->ifr_ifru
.ifru_data
, sizeof(p
))) {
1166 ip6gre_tnl_parm_from_user(&p1
, &p
);
1167 t
= ip6gre_tunnel_locate(net
, &p1
, 0);
1169 t
= netdev_priv(dev
);
1171 memset(&p
, 0, sizeof(p
));
1172 ip6gre_tnl_parm_to_user(&p
, &t
->parms
);
1173 if (copy_to_user(ifr
->ifr_ifru
.ifru_data
, &p
, sizeof(p
)))
1180 if (!ns_capable(net
->user_ns
, CAP_NET_ADMIN
))
1184 if (copy_from_user(&p
, ifr
->ifr_ifru
.ifru_data
, sizeof(p
)))
1188 if ((p
.i_flags
|p
.o_flags
)&(GRE_VERSION
|GRE_ROUTING
))
1191 if (!(p
.i_flags
&GRE_KEY
))
1193 if (!(p
.o_flags
&GRE_KEY
))
1196 ip6gre_tnl_parm_from_user(&p1
, &p
);
1197 t
= ip6gre_tunnel_locate(net
, &p1
, cmd
== SIOCADDTUNNEL
);
1199 if (dev
!= ign
->fb_tunnel_dev
&& cmd
== SIOCCHGTUNNEL
) {
1201 if (t
->dev
!= dev
) {
1206 t
= netdev_priv(dev
);
1208 ip6gre_tunnel_unlink(ign
, t
);
1210 ip6gre_tnl_change(t
, &p1
, 1);
1211 ip6gre_tunnel_link(ign
, t
);
1212 netdev_state_change(dev
);
1219 memset(&p
, 0, sizeof(p
));
1220 ip6gre_tnl_parm_to_user(&p
, &t
->parms
);
1221 if (copy_to_user(ifr
->ifr_ifru
.ifru_data
, &p
, sizeof(p
)))
1224 err
= (cmd
== SIOCADDTUNNEL
? -ENOBUFS
: -ENOENT
);
1229 if (!ns_capable(net
->user_ns
, CAP_NET_ADMIN
))
1232 if (dev
== ign
->fb_tunnel_dev
) {
1234 if (copy_from_user(&p
, ifr
->ifr_ifru
.ifru_data
, sizeof(p
)))
1237 ip6gre_tnl_parm_from_user(&p1
, &p
);
1238 t
= ip6gre_tunnel_locate(net
, &p1
, 0);
1242 if (t
== netdev_priv(ign
->fb_tunnel_dev
))
1246 unregister_netdevice(dev
);
1258 static int ip6gre_header(struct sk_buff
*skb
, struct net_device
*dev
,
1259 unsigned short type
, const void *daddr
,
1260 const void *saddr
, unsigned int len
)
1262 struct ip6_tnl
*t
= netdev_priv(dev
);
1263 struct ipv6hdr
*ipv6h
;
1266 ipv6h
= skb_push(skb
, t
->hlen
+ sizeof(*ipv6h
));
1267 ip6_flow_hdr(ipv6h
, 0, ip6_make_flowlabel(dev_net(dev
), skb
,
1268 t
->fl
.u
.ip6
.flowlabel
,
1269 true, &t
->fl
.u
.ip6
));
1270 ipv6h
->hop_limit
= t
->parms
.hop_limit
;
1271 ipv6h
->nexthdr
= NEXTHDR_GRE
;
1272 ipv6h
->saddr
= t
->parms
.laddr
;
1273 ipv6h
->daddr
= t
->parms
.raddr
;
1275 p
= (__be16
*)(ipv6h
+ 1);
1276 p
[0] = t
->parms
.o_flags
;
1280 * Set the source hardware address.
1284 memcpy(&ipv6h
->saddr
, saddr
, sizeof(struct in6_addr
));
1286 memcpy(&ipv6h
->daddr
, daddr
, sizeof(struct in6_addr
));
1287 if (!ipv6_addr_any(&ipv6h
->daddr
))
1293 static const struct header_ops ip6gre_header_ops
= {
1294 .create
= ip6gre_header
,
1297 static const struct net_device_ops ip6gre_netdev_ops
= {
1298 .ndo_init
= ip6gre_tunnel_init
,
1299 .ndo_uninit
= ip6gre_tunnel_uninit
,
1300 .ndo_start_xmit
= ip6gre_tunnel_xmit
,
1301 .ndo_do_ioctl
= ip6gre_tunnel_ioctl
,
1302 .ndo_change_mtu
= ip6_tnl_change_mtu
,
1303 .ndo_get_stats64
= ip_tunnel_get_stats64
,
1304 .ndo_get_iflink
= ip6_tnl_get_iflink
,
1307 static void ip6gre_dev_free(struct net_device
*dev
)
1309 struct ip6_tnl
*t
= netdev_priv(dev
);
1311 dst_cache_destroy(&t
->dst_cache
);
1312 free_percpu(dev
->tstats
);
1315 static void ip6gre_tunnel_setup(struct net_device
*dev
)
1317 dev
->netdev_ops
= &ip6gre_netdev_ops
;
1318 dev
->needs_free_netdev
= true;
1319 dev
->priv_destructor
= ip6gre_dev_free
;
1321 dev
->type
= ARPHRD_IP6GRE
;
1323 dev
->flags
|= IFF_NOARP
;
1324 dev
->addr_len
= sizeof(struct in6_addr
);
1325 netif_keep_dst(dev
);
1326 /* This perm addr will be used as interface identifier by IPv6 */
1327 dev
->addr_assign_type
= NET_ADDR_RANDOM
;
1328 eth_random_addr(dev
->perm_addr
);
1331 #define GRE6_FEATURES (NETIF_F_SG | \
1332 NETIF_F_FRAGLIST | \
1336 static void ip6gre_tnl_init_features(struct net_device
*dev
)
1338 struct ip6_tnl
*nt
= netdev_priv(dev
);
1340 dev
->features
|= GRE6_FEATURES
;
1341 dev
->hw_features
|= GRE6_FEATURES
;
1343 if (!(nt
->parms
.o_flags
& TUNNEL_SEQ
)) {
1344 /* TCP offload with GRE SEQ is not supported, nor
1345 * can we support 2 levels of outer headers requiring
1348 if (!(nt
->parms
.o_flags
& TUNNEL_CSUM
) ||
1349 nt
->encap
.type
== TUNNEL_ENCAP_NONE
) {
1350 dev
->features
|= NETIF_F_GSO_SOFTWARE
;
1351 dev
->hw_features
|= NETIF_F_GSO_SOFTWARE
;
1354 /* Can use a lockless transmit, unless we generate
1357 dev
->features
|= NETIF_F_LLTX
;
1361 static int ip6gre_tunnel_init_common(struct net_device
*dev
)
1363 struct ip6_tnl
*tunnel
;
1367 tunnel
= netdev_priv(dev
);
1370 tunnel
->net
= dev_net(dev
);
1371 strcpy(tunnel
->parms
.name
, dev
->name
);
1373 dev
->tstats
= netdev_alloc_pcpu_stats(struct pcpu_sw_netstats
);
1377 ret
= dst_cache_init(&tunnel
->dst_cache
, GFP_KERNEL
);
1379 free_percpu(dev
->tstats
);
1384 tunnel
->tun_hlen
= gre_calc_hlen(tunnel
->parms
.o_flags
);
1385 tunnel
->hlen
= tunnel
->tun_hlen
+ tunnel
->encap_hlen
;
1386 t_hlen
= tunnel
->hlen
+ sizeof(struct ipv6hdr
);
1388 dev
->hard_header_len
= LL_MAX_HEADER
+ t_hlen
;
1389 dev
->mtu
= ETH_DATA_LEN
- t_hlen
;
1390 if (dev
->type
== ARPHRD_ETHER
)
1391 dev
->mtu
-= ETH_HLEN
;
1392 if (!(tunnel
->parms
.flags
& IP6_TNL_F_IGN_ENCAP_LIMIT
))
1395 if (tunnel
->parms
.collect_md
) {
1396 dev
->features
|= NETIF_F_NETNS_LOCAL
;
1397 netif_keep_dst(dev
);
1399 ip6gre_tnl_init_features(dev
);
1404 static int ip6gre_tunnel_init(struct net_device
*dev
)
1406 struct ip6_tnl
*tunnel
;
1409 ret
= ip6gre_tunnel_init_common(dev
);
1413 tunnel
= netdev_priv(dev
);
1415 if (tunnel
->parms
.collect_md
)
1418 memcpy(dev
->dev_addr
, &tunnel
->parms
.laddr
, sizeof(struct in6_addr
));
1419 memcpy(dev
->broadcast
, &tunnel
->parms
.raddr
, sizeof(struct in6_addr
));
1421 if (ipv6_addr_any(&tunnel
->parms
.raddr
))
1422 dev
->header_ops
= &ip6gre_header_ops
;
1427 static void ip6gre_fb_tunnel_init(struct net_device
*dev
)
1429 struct ip6_tnl
*tunnel
= netdev_priv(dev
);
1432 tunnel
->net
= dev_net(dev
);
1433 strcpy(tunnel
->parms
.name
, dev
->name
);
1435 tunnel
->hlen
= sizeof(struct ipv6hdr
) + 4;
1440 static struct inet6_protocol ip6gre_protocol __read_mostly
= {
1442 .err_handler
= ip6gre_err
,
1443 .flags
= INET6_PROTO_NOPOLICY
|INET6_PROTO_FINAL
,
1446 static void ip6gre_destroy_tunnels(struct net
*net
, struct list_head
*head
)
1448 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
1449 struct net_device
*dev
, *aux
;
1452 for_each_netdev_safe(net
, dev
, aux
)
1453 if (dev
->rtnl_link_ops
== &ip6gre_link_ops
||
1454 dev
->rtnl_link_ops
== &ip6gre_tap_ops
||
1455 dev
->rtnl_link_ops
== &ip6erspan_tap_ops
)
1456 unregister_netdevice_queue(dev
, head
);
1458 for (prio
= 0; prio
< 4; prio
++) {
1460 for (h
= 0; h
< IP6_GRE_HASH_SIZE
; h
++) {
1463 t
= rtnl_dereference(ign
->tunnels
[prio
][h
]);
1466 /* If dev is in the same netns, it has already
1467 * been added to the list by the previous loop.
1469 if (!net_eq(dev_net(t
->dev
), net
))
1470 unregister_netdevice_queue(t
->dev
,
1472 t
= rtnl_dereference(t
->next
);
1478 static int __net_init
ip6gre_init_net(struct net
*net
)
1480 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
1483 if (!net_has_fallback_tunnels(net
))
1485 ign
->fb_tunnel_dev
= alloc_netdev(sizeof(struct ip6_tnl
), "ip6gre0",
1487 ip6gre_tunnel_setup
);
1488 if (!ign
->fb_tunnel_dev
) {
1492 dev_net_set(ign
->fb_tunnel_dev
, net
);
1493 /* FB netdevice is special: we have one, and only one per netns.
1494 * Allowing to move it to another netns is clearly unsafe.
1496 ign
->fb_tunnel_dev
->features
|= NETIF_F_NETNS_LOCAL
;
1499 ip6gre_fb_tunnel_init(ign
->fb_tunnel_dev
);
1500 ign
->fb_tunnel_dev
->rtnl_link_ops
= &ip6gre_link_ops
;
1502 err
= register_netdev(ign
->fb_tunnel_dev
);
1506 rcu_assign_pointer(ign
->tunnels_wc
[0],
1507 netdev_priv(ign
->fb_tunnel_dev
));
1511 free_netdev(ign
->fb_tunnel_dev
);
1516 static void __net_exit
ip6gre_exit_batch_net(struct list_head
*net_list
)
1522 list_for_each_entry(net
, net_list
, exit_list
)
1523 ip6gre_destroy_tunnels(net
, &list
);
1524 unregister_netdevice_many(&list
);
1528 static struct pernet_operations ip6gre_net_ops
= {
1529 .init
= ip6gre_init_net
,
1530 .exit_batch
= ip6gre_exit_batch_net
,
1531 .id
= &ip6gre_net_id
,
1532 .size
= sizeof(struct ip6gre_net
),
1535 static int ip6gre_tunnel_validate(struct nlattr
*tb
[], struct nlattr
*data
[],
1536 struct netlink_ext_ack
*extack
)
1544 if (data
[IFLA_GRE_IFLAGS
])
1545 flags
|= nla_get_be16(data
[IFLA_GRE_IFLAGS
]);
1546 if (data
[IFLA_GRE_OFLAGS
])
1547 flags
|= nla_get_be16(data
[IFLA_GRE_OFLAGS
]);
1548 if (flags
& (GRE_VERSION
|GRE_ROUTING
))
1554 static int ip6gre_tap_validate(struct nlattr
*tb
[], struct nlattr
*data
[],
1555 struct netlink_ext_ack
*extack
)
1557 struct in6_addr daddr
;
1559 if (tb
[IFLA_ADDRESS
]) {
1560 if (nla_len(tb
[IFLA_ADDRESS
]) != ETH_ALEN
)
1562 if (!is_valid_ether_addr(nla_data(tb
[IFLA_ADDRESS
])))
1563 return -EADDRNOTAVAIL
;
1569 if (data
[IFLA_GRE_REMOTE
]) {
1570 daddr
= nla_get_in6_addr(data
[IFLA_GRE_REMOTE
]);
1571 if (ipv6_addr_any(&daddr
))
1576 return ip6gre_tunnel_validate(tb
, data
, extack
);
1579 static int ip6erspan_tap_validate(struct nlattr
*tb
[], struct nlattr
*data
[],
1580 struct netlink_ext_ack
*extack
)
1588 ret
= ip6gre_tap_validate(tb
, data
, extack
);
1592 /* ERSPAN should only have GRE sequence and key flag */
1593 if (data
[IFLA_GRE_OFLAGS
])
1594 flags
|= nla_get_be16(data
[IFLA_GRE_OFLAGS
]);
1595 if (data
[IFLA_GRE_IFLAGS
])
1596 flags
|= nla_get_be16(data
[IFLA_GRE_IFLAGS
]);
1597 if (!data
[IFLA_GRE_COLLECT_METADATA
] &&
1598 flags
!= (GRE_SEQ
| GRE_KEY
))
1601 /* ERSPAN Session ID only has 10-bit. Since we reuse
1602 * 32-bit key field as ID, check it's range.
1604 if (data
[IFLA_GRE_IKEY
] &&
1605 (ntohl(nla_get_be32(data
[IFLA_GRE_IKEY
])) & ~ID_MASK
))
1608 if (data
[IFLA_GRE_OKEY
] &&
1609 (ntohl(nla_get_be32(data
[IFLA_GRE_OKEY
])) & ~ID_MASK
))
1612 if (data
[IFLA_GRE_ERSPAN_VER
]) {
1613 ver
= nla_get_u8(data
[IFLA_GRE_ERSPAN_VER
]);
1614 if (ver
!= 1 && ver
!= 2)
1619 if (data
[IFLA_GRE_ERSPAN_INDEX
]) {
1620 u32 index
= nla_get_u32(data
[IFLA_GRE_ERSPAN_INDEX
]);
1622 if (index
& ~INDEX_MASK
)
1625 } else if (ver
== 2) {
1626 if (data
[IFLA_GRE_ERSPAN_DIR
]) {
1627 u16 dir
= nla_get_u8(data
[IFLA_GRE_ERSPAN_DIR
]);
1629 if (dir
& ~(DIR_MASK
>> DIR_OFFSET
))
1633 if (data
[IFLA_GRE_ERSPAN_HWID
]) {
1634 u16 hwid
= nla_get_u16(data
[IFLA_GRE_ERSPAN_HWID
]);
1636 if (hwid
& ~(HWID_MASK
>> HWID_OFFSET
))
1644 static void ip6gre_netlink_parms(struct nlattr
*data
[],
1645 struct __ip6_tnl_parm
*parms
)
1647 memset(parms
, 0, sizeof(*parms
));
1652 if (data
[IFLA_GRE_LINK
])
1653 parms
->link
= nla_get_u32(data
[IFLA_GRE_LINK
]);
1655 if (data
[IFLA_GRE_IFLAGS
])
1656 parms
->i_flags
= gre_flags_to_tnl_flags(
1657 nla_get_be16(data
[IFLA_GRE_IFLAGS
]));
1659 if (data
[IFLA_GRE_OFLAGS
])
1660 parms
->o_flags
= gre_flags_to_tnl_flags(
1661 nla_get_be16(data
[IFLA_GRE_OFLAGS
]));
1663 if (data
[IFLA_GRE_IKEY
])
1664 parms
->i_key
= nla_get_be32(data
[IFLA_GRE_IKEY
]);
1666 if (data
[IFLA_GRE_OKEY
])
1667 parms
->o_key
= nla_get_be32(data
[IFLA_GRE_OKEY
]);
1669 if (data
[IFLA_GRE_LOCAL
])
1670 parms
->laddr
= nla_get_in6_addr(data
[IFLA_GRE_LOCAL
]);
1672 if (data
[IFLA_GRE_REMOTE
])
1673 parms
->raddr
= nla_get_in6_addr(data
[IFLA_GRE_REMOTE
]);
1675 if (data
[IFLA_GRE_TTL
])
1676 parms
->hop_limit
= nla_get_u8(data
[IFLA_GRE_TTL
]);
1678 if (data
[IFLA_GRE_ENCAP_LIMIT
])
1679 parms
->encap_limit
= nla_get_u8(data
[IFLA_GRE_ENCAP_LIMIT
]);
1681 if (data
[IFLA_GRE_FLOWINFO
])
1682 parms
->flowinfo
= nla_get_be32(data
[IFLA_GRE_FLOWINFO
]);
1684 if (data
[IFLA_GRE_FLAGS
])
1685 parms
->flags
= nla_get_u32(data
[IFLA_GRE_FLAGS
]);
1687 if (data
[IFLA_GRE_FWMARK
])
1688 parms
->fwmark
= nla_get_u32(data
[IFLA_GRE_FWMARK
]);
1690 if (data
[IFLA_GRE_COLLECT_METADATA
])
1691 parms
->collect_md
= true;
1693 if (data
[IFLA_GRE_ERSPAN_VER
])
1694 parms
->erspan_ver
= nla_get_u8(data
[IFLA_GRE_ERSPAN_VER
]);
1696 if (parms
->erspan_ver
== 1) {
1697 if (data
[IFLA_GRE_ERSPAN_INDEX
])
1698 parms
->index
= nla_get_u32(data
[IFLA_GRE_ERSPAN_INDEX
]);
1699 } else if (parms
->erspan_ver
== 2) {
1700 if (data
[IFLA_GRE_ERSPAN_DIR
])
1701 parms
->dir
= nla_get_u8(data
[IFLA_GRE_ERSPAN_DIR
]);
1702 if (data
[IFLA_GRE_ERSPAN_HWID
])
1703 parms
->hwid
= nla_get_u16(data
[IFLA_GRE_ERSPAN_HWID
]);
1707 static int ip6gre_tap_init(struct net_device
*dev
)
1711 ret
= ip6gre_tunnel_init_common(dev
);
1715 dev
->priv_flags
|= IFF_LIVE_ADDR_CHANGE
;
1720 static const struct net_device_ops ip6gre_tap_netdev_ops
= {
1721 .ndo_init
= ip6gre_tap_init
,
1722 .ndo_uninit
= ip6gre_tunnel_uninit
,
1723 .ndo_start_xmit
= ip6gre_tunnel_xmit
,
1724 .ndo_set_mac_address
= eth_mac_addr
,
1725 .ndo_validate_addr
= eth_validate_addr
,
1726 .ndo_change_mtu
= ip6_tnl_change_mtu
,
1727 .ndo_get_stats64
= ip_tunnel_get_stats64
,
1728 .ndo_get_iflink
= ip6_tnl_get_iflink
,
1731 static int ip6erspan_tap_init(struct net_device
*dev
)
1733 struct ip6_tnl
*tunnel
;
1737 tunnel
= netdev_priv(dev
);
1740 tunnel
->net
= dev_net(dev
);
1741 strcpy(tunnel
->parms
.name
, dev
->name
);
1743 dev
->tstats
= netdev_alloc_pcpu_stats(struct pcpu_sw_netstats
);
1747 ret
= dst_cache_init(&tunnel
->dst_cache
, GFP_KERNEL
);
1749 free_percpu(dev
->tstats
);
1754 tunnel
->tun_hlen
= 8;
1755 tunnel
->hlen
= tunnel
->tun_hlen
+ tunnel
->encap_hlen
+
1756 erspan_hdr_len(tunnel
->parms
.erspan_ver
);
1757 t_hlen
= tunnel
->hlen
+ sizeof(struct ipv6hdr
);
1759 dev
->hard_header_len
= LL_MAX_HEADER
+ t_hlen
;
1760 dev
->mtu
= ETH_DATA_LEN
- t_hlen
;
1761 if (dev
->type
== ARPHRD_ETHER
)
1762 dev
->mtu
-= ETH_HLEN
;
1763 if (!(tunnel
->parms
.flags
& IP6_TNL_F_IGN_ENCAP_LIMIT
))
1766 dev
->priv_flags
|= IFF_LIVE_ADDR_CHANGE
;
1767 ip6gre_tnl_link_config(tunnel
, 1);
1772 static const struct net_device_ops ip6erspan_netdev_ops
= {
1773 .ndo_init
= ip6erspan_tap_init
,
1774 .ndo_uninit
= ip6gre_tunnel_uninit
,
1775 .ndo_start_xmit
= ip6erspan_tunnel_xmit
,
1776 .ndo_set_mac_address
= eth_mac_addr
,
1777 .ndo_validate_addr
= eth_validate_addr
,
1778 .ndo_change_mtu
= ip6_tnl_change_mtu
,
1779 .ndo_get_stats64
= ip_tunnel_get_stats64
,
1780 .ndo_get_iflink
= ip6_tnl_get_iflink
,
1783 static void ip6gre_tap_setup(struct net_device
*dev
)
1789 dev
->netdev_ops
= &ip6gre_tap_netdev_ops
;
1790 dev
->needs_free_netdev
= true;
1791 dev
->priv_destructor
= ip6gre_dev_free
;
1793 dev
->features
|= NETIF_F_NETNS_LOCAL
;
1794 dev
->priv_flags
&= ~IFF_TX_SKB_SHARING
;
1795 dev
->priv_flags
|= IFF_LIVE_ADDR_CHANGE
;
1796 netif_keep_dst(dev
);
1799 bool is_ip6gretap_dev(const struct net_device
*dev
)
1801 return dev
->netdev_ops
== &ip6gre_tap_netdev_ops
;
1803 EXPORT_SYMBOL_GPL(is_ip6gretap_dev
);
1805 static bool ip6gre_netlink_encap_parms(struct nlattr
*data
[],
1806 struct ip_tunnel_encap
*ipencap
)
1810 memset(ipencap
, 0, sizeof(*ipencap
));
1815 if (data
[IFLA_GRE_ENCAP_TYPE
]) {
1817 ipencap
->type
= nla_get_u16(data
[IFLA_GRE_ENCAP_TYPE
]);
1820 if (data
[IFLA_GRE_ENCAP_FLAGS
]) {
1822 ipencap
->flags
= nla_get_u16(data
[IFLA_GRE_ENCAP_FLAGS
]);
1825 if (data
[IFLA_GRE_ENCAP_SPORT
]) {
1827 ipencap
->sport
= nla_get_be16(data
[IFLA_GRE_ENCAP_SPORT
]);
1830 if (data
[IFLA_GRE_ENCAP_DPORT
]) {
1832 ipencap
->dport
= nla_get_be16(data
[IFLA_GRE_ENCAP_DPORT
]);
1838 static int ip6gre_newlink(struct net
*src_net
, struct net_device
*dev
,
1839 struct nlattr
*tb
[], struct nlattr
*data
[],
1840 struct netlink_ext_ack
*extack
)
1843 struct net
*net
= dev_net(dev
);
1844 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
1845 struct ip_tunnel_encap ipencap
;
1848 nt
= netdev_priv(dev
);
1850 if (ip6gre_netlink_encap_parms(data
, &ipencap
)) {
1851 int err
= ip6_tnl_encap_setup(nt
, &ipencap
);
1857 ip6gre_netlink_parms(data
, &nt
->parms
);
1859 if (nt
->parms
.collect_md
) {
1860 if (rtnl_dereference(ign
->collect_md_tun
))
1863 if (ip6gre_tunnel_find(net
, &nt
->parms
, dev
->type
))
1867 if (dev
->type
== ARPHRD_ETHER
&& !tb
[IFLA_ADDRESS
])
1868 eth_hw_addr_random(dev
);
1871 nt
->net
= dev_net(dev
);
1873 err
= register_netdevice(dev
);
1877 ip6gre_tnl_link_config(nt
, !tb
[IFLA_MTU
]);
1880 ip6_tnl_change_mtu(dev
, nla_get_u32(tb
[IFLA_MTU
]));
1883 ip6gre_tunnel_link(ign
, nt
);
1889 static int ip6gre_changelink(struct net_device
*dev
, struct nlattr
*tb
[],
1890 struct nlattr
*data
[],
1891 struct netlink_ext_ack
*extack
)
1893 struct ip6_tnl
*t
, *nt
= netdev_priv(dev
);
1894 struct net
*net
= nt
->net
;
1895 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
1896 struct __ip6_tnl_parm p
;
1897 struct ip_tunnel_encap ipencap
;
1899 if (dev
== ign
->fb_tunnel_dev
)
1902 if (ip6gre_netlink_encap_parms(data
, &ipencap
)) {
1903 int err
= ip6_tnl_encap_setup(nt
, &ipencap
);
1909 ip6gre_netlink_parms(data
, &p
);
1911 t
= ip6gre_tunnel_locate(net
, &p
, 0);
1920 ip6gre_tunnel_unlink(ign
, t
);
1921 ip6gre_tnl_change(t
, &p
, !tb
[IFLA_MTU
]);
1922 ip6gre_tunnel_link(ign
, t
);
1926 static void ip6gre_dellink(struct net_device
*dev
, struct list_head
*head
)
1928 struct net
*net
= dev_net(dev
);
1929 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
1931 if (dev
!= ign
->fb_tunnel_dev
)
1932 unregister_netdevice_queue(dev
, head
);
1935 static size_t ip6gre_get_size(const struct net_device
*dev
)
1940 /* IFLA_GRE_IFLAGS */
1942 /* IFLA_GRE_OFLAGS */
1948 /* IFLA_GRE_LOCAL */
1949 nla_total_size(sizeof(struct in6_addr
)) +
1950 /* IFLA_GRE_REMOTE */
1951 nla_total_size(sizeof(struct in6_addr
)) +
1954 /* IFLA_GRE_ENCAP_LIMIT */
1956 /* IFLA_GRE_FLOWINFO */
1958 /* IFLA_GRE_FLAGS */
1960 /* IFLA_GRE_ENCAP_TYPE */
1962 /* IFLA_GRE_ENCAP_FLAGS */
1964 /* IFLA_GRE_ENCAP_SPORT */
1966 /* IFLA_GRE_ENCAP_DPORT */
1968 /* IFLA_GRE_COLLECT_METADATA */
1970 /* IFLA_GRE_FWMARK */
1972 /* IFLA_GRE_ERSPAN_INDEX */
1977 static int ip6gre_fill_info(struct sk_buff
*skb
, const struct net_device
*dev
)
1979 struct ip6_tnl
*t
= netdev_priv(dev
);
1980 struct __ip6_tnl_parm
*p
= &t
->parms
;
1982 if (nla_put_u32(skb
, IFLA_GRE_LINK
, p
->link
) ||
1983 nla_put_be16(skb
, IFLA_GRE_IFLAGS
,
1984 gre_tnl_flags_to_gre_flags(p
->i_flags
)) ||
1985 nla_put_be16(skb
, IFLA_GRE_OFLAGS
,
1986 gre_tnl_flags_to_gre_flags(p
->o_flags
)) ||
1987 nla_put_be32(skb
, IFLA_GRE_IKEY
, p
->i_key
) ||
1988 nla_put_be32(skb
, IFLA_GRE_OKEY
, p
->o_key
) ||
1989 nla_put_in6_addr(skb
, IFLA_GRE_LOCAL
, &p
->laddr
) ||
1990 nla_put_in6_addr(skb
, IFLA_GRE_REMOTE
, &p
->raddr
) ||
1991 nla_put_u8(skb
, IFLA_GRE_TTL
, p
->hop_limit
) ||
1992 nla_put_u8(skb
, IFLA_GRE_ENCAP_LIMIT
, p
->encap_limit
) ||
1993 nla_put_be32(skb
, IFLA_GRE_FLOWINFO
, p
->flowinfo
) ||
1994 nla_put_u32(skb
, IFLA_GRE_FLAGS
, p
->flags
) ||
1995 nla_put_u32(skb
, IFLA_GRE_FWMARK
, p
->fwmark
) ||
1996 nla_put_u32(skb
, IFLA_GRE_ERSPAN_INDEX
, p
->index
))
1997 goto nla_put_failure
;
1999 if (nla_put_u16(skb
, IFLA_GRE_ENCAP_TYPE
,
2001 nla_put_be16(skb
, IFLA_GRE_ENCAP_SPORT
,
2003 nla_put_be16(skb
, IFLA_GRE_ENCAP_DPORT
,
2005 nla_put_u16(skb
, IFLA_GRE_ENCAP_FLAGS
,
2007 goto nla_put_failure
;
2009 if (p
->collect_md
) {
2010 if (nla_put_flag(skb
, IFLA_GRE_COLLECT_METADATA
))
2011 goto nla_put_failure
;
2014 if (nla_put_u8(skb
, IFLA_GRE_ERSPAN_VER
, p
->erspan_ver
))
2015 goto nla_put_failure
;
2017 if (p
->erspan_ver
== 1) {
2018 if (nla_put_u32(skb
, IFLA_GRE_ERSPAN_INDEX
, p
->index
))
2019 goto nla_put_failure
;
2020 } else if (p
->erspan_ver
== 2) {
2021 if (nla_put_u8(skb
, IFLA_GRE_ERSPAN_DIR
, p
->dir
))
2022 goto nla_put_failure
;
2023 if (nla_put_u16(skb
, IFLA_GRE_ERSPAN_HWID
, p
->hwid
))
2024 goto nla_put_failure
;
2033 static const struct nla_policy ip6gre_policy
[IFLA_GRE_MAX
+ 1] = {
2034 [IFLA_GRE_LINK
] = { .type
= NLA_U32
},
2035 [IFLA_GRE_IFLAGS
] = { .type
= NLA_U16
},
2036 [IFLA_GRE_OFLAGS
] = { .type
= NLA_U16
},
2037 [IFLA_GRE_IKEY
] = { .type
= NLA_U32
},
2038 [IFLA_GRE_OKEY
] = { .type
= NLA_U32
},
2039 [IFLA_GRE_LOCAL
] = { .len
= FIELD_SIZEOF(struct ipv6hdr
, saddr
) },
2040 [IFLA_GRE_REMOTE
] = { .len
= FIELD_SIZEOF(struct ipv6hdr
, daddr
) },
2041 [IFLA_GRE_TTL
] = { .type
= NLA_U8
},
2042 [IFLA_GRE_ENCAP_LIMIT
] = { .type
= NLA_U8
},
2043 [IFLA_GRE_FLOWINFO
] = { .type
= NLA_U32
},
2044 [IFLA_GRE_FLAGS
] = { .type
= NLA_U32
},
2045 [IFLA_GRE_ENCAP_TYPE
] = { .type
= NLA_U16
},
2046 [IFLA_GRE_ENCAP_FLAGS
] = { .type
= NLA_U16
},
2047 [IFLA_GRE_ENCAP_SPORT
] = { .type
= NLA_U16
},
2048 [IFLA_GRE_ENCAP_DPORT
] = { .type
= NLA_U16
},
2049 [IFLA_GRE_COLLECT_METADATA
] = { .type
= NLA_FLAG
},
2050 [IFLA_GRE_FWMARK
] = { .type
= NLA_U32
},
2051 [IFLA_GRE_ERSPAN_INDEX
] = { .type
= NLA_U32
},
2052 [IFLA_GRE_ERSPAN_VER
] = { .type
= NLA_U8
},
2053 [IFLA_GRE_ERSPAN_DIR
] = { .type
= NLA_U8
},
2054 [IFLA_GRE_ERSPAN_HWID
] = { .type
= NLA_U16
},
2057 static void ip6erspan_tap_setup(struct net_device
*dev
)
2061 dev
->netdev_ops
= &ip6erspan_netdev_ops
;
2062 dev
->needs_free_netdev
= true;
2063 dev
->priv_destructor
= ip6gre_dev_free
;
2065 dev
->features
|= NETIF_F_NETNS_LOCAL
;
2066 dev
->priv_flags
&= ~IFF_TX_SKB_SHARING
;
2067 dev
->priv_flags
|= IFF_LIVE_ADDR_CHANGE
;
2068 netif_keep_dst(dev
);
2071 static struct rtnl_link_ops ip6gre_link_ops __read_mostly
= {
2073 .maxtype
= IFLA_GRE_MAX
,
2074 .policy
= ip6gre_policy
,
2075 .priv_size
= sizeof(struct ip6_tnl
),
2076 .setup
= ip6gre_tunnel_setup
,
2077 .validate
= ip6gre_tunnel_validate
,
2078 .newlink
= ip6gre_newlink
,
2079 .changelink
= ip6gre_changelink
,
2080 .dellink
= ip6gre_dellink
,
2081 .get_size
= ip6gre_get_size
,
2082 .fill_info
= ip6gre_fill_info
,
2083 .get_link_net
= ip6_tnl_get_link_net
,
2086 static struct rtnl_link_ops ip6gre_tap_ops __read_mostly
= {
2087 .kind
= "ip6gretap",
2088 .maxtype
= IFLA_GRE_MAX
,
2089 .policy
= ip6gre_policy
,
2090 .priv_size
= sizeof(struct ip6_tnl
),
2091 .setup
= ip6gre_tap_setup
,
2092 .validate
= ip6gre_tap_validate
,
2093 .newlink
= ip6gre_newlink
,
2094 .changelink
= ip6gre_changelink
,
2095 .get_size
= ip6gre_get_size
,
2096 .fill_info
= ip6gre_fill_info
,
2097 .get_link_net
= ip6_tnl_get_link_net
,
2100 static struct rtnl_link_ops ip6erspan_tap_ops __read_mostly
= {
2101 .kind
= "ip6erspan",
2102 .maxtype
= IFLA_GRE_MAX
,
2103 .policy
= ip6gre_policy
,
2104 .priv_size
= sizeof(struct ip6_tnl
),
2105 .setup
= ip6erspan_tap_setup
,
2106 .validate
= ip6erspan_tap_validate
,
2107 .newlink
= ip6gre_newlink
,
2108 .changelink
= ip6gre_changelink
,
2109 .get_size
= ip6gre_get_size
,
2110 .fill_info
= ip6gre_fill_info
,
2111 .get_link_net
= ip6_tnl_get_link_net
,
2115 * And now the modules code and kernel interface.
2118 static int __init
ip6gre_init(void)
2122 pr_info("GRE over IPv6 tunneling driver\n");
2124 err
= register_pernet_device(&ip6gre_net_ops
);
2128 err
= inet6_add_protocol(&ip6gre_protocol
, IPPROTO_GRE
);
2130 pr_info("%s: can't add protocol\n", __func__
);
2131 goto add_proto_failed
;
2134 err
= rtnl_link_register(&ip6gre_link_ops
);
2136 goto rtnl_link_failed
;
2138 err
= rtnl_link_register(&ip6gre_tap_ops
);
2140 goto tap_ops_failed
;
2142 err
= rtnl_link_register(&ip6erspan_tap_ops
);
2144 goto erspan_link_failed
;
2150 rtnl_link_unregister(&ip6gre_tap_ops
);
2152 rtnl_link_unregister(&ip6gre_link_ops
);
2154 inet6_del_protocol(&ip6gre_protocol
, IPPROTO_GRE
);
2156 unregister_pernet_device(&ip6gre_net_ops
);
2160 static void __exit
ip6gre_fini(void)
2162 rtnl_link_unregister(&ip6gre_tap_ops
);
2163 rtnl_link_unregister(&ip6gre_link_ops
);
2164 rtnl_link_unregister(&ip6erspan_tap_ops
);
2165 inet6_del_protocol(&ip6gre_protocol
, IPPROTO_GRE
);
2166 unregister_pernet_device(&ip6gre_net_ops
);
2169 module_init(ip6gre_init
);
2170 module_exit(ip6gre_fini
);
2171 MODULE_LICENSE("GPL");
2172 MODULE_AUTHOR("D. Kozlov (xeb@mail.ru)");
2173 MODULE_DESCRIPTION("GRE over IPv6 tunneling device");
2174 MODULE_ALIAS_RTNL_LINK("ip6gre");
2175 MODULE_ALIAS_RTNL_LINK("ip6gretap");
2176 MODULE_ALIAS_RTNL_LINK("ip6erspan");
2177 MODULE_ALIAS_NETDEV("ip6gre0");