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 ARPHRD_ETHER
: ARPHRD_IP6GRE
;
131 int score
, cand_score
= 4;
133 for_each_ip_tunnel_rcu(t
, ign
->tunnels_r_l
[h0
^ h1
]) {
134 if (!ipv6_addr_equal(local
, &t
->parms
.laddr
) ||
135 !ipv6_addr_equal(remote
, &t
->parms
.raddr
) ||
136 key
!= t
->parms
.i_key
||
137 !(t
->dev
->flags
& IFF_UP
))
140 if (t
->dev
->type
!= ARPHRD_IP6GRE
&&
141 t
->dev
->type
!= dev_type
)
145 if (t
->parms
.link
!= link
)
147 if (t
->dev
->type
!= dev_type
)
152 if (score
< cand_score
) {
158 for_each_ip_tunnel_rcu(t
, ign
->tunnels_r
[h0
^ h1
]) {
159 if (!ipv6_addr_equal(remote
, &t
->parms
.raddr
) ||
160 key
!= t
->parms
.i_key
||
161 !(t
->dev
->flags
& IFF_UP
))
164 if (t
->dev
->type
!= ARPHRD_IP6GRE
&&
165 t
->dev
->type
!= dev_type
)
169 if (t
->parms
.link
!= link
)
171 if (t
->dev
->type
!= dev_type
)
176 if (score
< cand_score
) {
182 for_each_ip_tunnel_rcu(t
, ign
->tunnels_l
[h1
]) {
183 if ((!ipv6_addr_equal(local
, &t
->parms
.laddr
) &&
184 (!ipv6_addr_equal(local
, &t
->parms
.raddr
) ||
185 !ipv6_addr_is_multicast(local
))) ||
186 key
!= t
->parms
.i_key
||
187 !(t
->dev
->flags
& IFF_UP
))
190 if (t
->dev
->type
!= ARPHRD_IP6GRE
&&
191 t
->dev
->type
!= dev_type
)
195 if (t
->parms
.link
!= link
)
197 if (t
->dev
->type
!= dev_type
)
202 if (score
< cand_score
) {
208 for_each_ip_tunnel_rcu(t
, ign
->tunnels_wc
[h1
]) {
209 if (t
->parms
.i_key
!= key
||
210 !(t
->dev
->flags
& IFF_UP
))
213 if (t
->dev
->type
!= ARPHRD_IP6GRE
&&
214 t
->dev
->type
!= dev_type
)
218 if (t
->parms
.link
!= link
)
220 if (t
->dev
->type
!= dev_type
)
225 if (score
< cand_score
) {
234 t
= rcu_dereference(ign
->collect_md_tun
);
235 if (t
&& t
->dev
->flags
& IFF_UP
)
238 dev
= ign
->fb_tunnel_dev
;
239 if (dev
->flags
& IFF_UP
)
240 return netdev_priv(dev
);
245 static struct ip6_tnl __rcu
**__ip6gre_bucket(struct ip6gre_net
*ign
,
246 const struct __ip6_tnl_parm
*p
)
248 const struct in6_addr
*remote
= &p
->raddr
;
249 const struct in6_addr
*local
= &p
->laddr
;
250 unsigned int h
= HASH_KEY(p
->i_key
);
253 if (!ipv6_addr_any(local
))
255 if (!ipv6_addr_any(remote
) && !ipv6_addr_is_multicast(remote
)) {
257 h
^= HASH_ADDR(remote
);
260 return &ign
->tunnels
[prio
][h
];
263 static inline struct ip6_tnl __rcu
**ip6gre_bucket(struct ip6gre_net
*ign
,
264 const struct ip6_tnl
*t
)
266 return __ip6gre_bucket(ign
, &t
->parms
);
269 static void ip6gre_tunnel_link(struct ip6gre_net
*ign
, struct ip6_tnl
*t
)
271 struct ip6_tnl __rcu
**tp
= ip6gre_bucket(ign
, t
);
273 if (t
->parms
.collect_md
)
274 rcu_assign_pointer(ign
->collect_md_tun
, t
);
276 rcu_assign_pointer(t
->next
, rtnl_dereference(*tp
));
277 rcu_assign_pointer(*tp
, t
);
280 static void ip6gre_tunnel_unlink(struct ip6gre_net
*ign
, struct ip6_tnl
*t
)
282 struct ip6_tnl __rcu
**tp
;
283 struct ip6_tnl
*iter
;
285 if (t
->parms
.collect_md
)
286 rcu_assign_pointer(ign
->collect_md_tun
, NULL
);
288 for (tp
= ip6gre_bucket(ign
, t
);
289 (iter
= rtnl_dereference(*tp
)) != NULL
;
292 rcu_assign_pointer(*tp
, t
->next
);
298 static struct ip6_tnl
*ip6gre_tunnel_find(struct net
*net
,
299 const struct __ip6_tnl_parm
*parms
,
302 const struct in6_addr
*remote
= &parms
->raddr
;
303 const struct in6_addr
*local
= &parms
->laddr
;
304 __be32 key
= parms
->i_key
;
305 int link
= parms
->link
;
307 struct ip6_tnl __rcu
**tp
;
308 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
310 for (tp
= __ip6gre_bucket(ign
, parms
);
311 (t
= rtnl_dereference(*tp
)) != NULL
;
313 if (ipv6_addr_equal(local
, &t
->parms
.laddr
) &&
314 ipv6_addr_equal(remote
, &t
->parms
.raddr
) &&
315 key
== t
->parms
.i_key
&&
316 link
== t
->parms
.link
&&
317 type
== t
->dev
->type
)
323 static struct ip6_tnl
*ip6gre_tunnel_locate(struct net
*net
,
324 const struct __ip6_tnl_parm
*parms
, int create
)
326 struct ip6_tnl
*t
, *nt
;
327 struct net_device
*dev
;
329 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
331 t
= ip6gre_tunnel_find(net
, parms
, ARPHRD_IP6GRE
);
338 strlcpy(name
, parms
->name
, IFNAMSIZ
);
340 strcpy(name
, "ip6gre%d");
342 dev
= alloc_netdev(sizeof(*t
), name
, NET_NAME_UNKNOWN
,
343 ip6gre_tunnel_setup
);
347 dev_net_set(dev
, net
);
349 nt
= netdev_priv(dev
);
351 dev
->rtnl_link_ops
= &ip6gre_link_ops
;
354 nt
->net
= dev_net(dev
);
356 if (register_netdevice(dev
) < 0)
359 ip6gre_tnl_link_config(nt
, 1);
361 /* Can use a lockless transmit, unless we generate output sequences */
362 if (!(nt
->parms
.o_flags
& TUNNEL_SEQ
))
363 dev
->features
|= NETIF_F_LLTX
;
366 ip6gre_tunnel_link(ign
, nt
);
374 static void ip6gre_tunnel_uninit(struct net_device
*dev
)
376 struct ip6_tnl
*t
= netdev_priv(dev
);
377 struct ip6gre_net
*ign
= net_generic(t
->net
, ip6gre_net_id
);
379 ip6gre_tunnel_unlink(ign
, t
);
380 dst_cache_reset(&t
->dst_cache
);
385 static void ip6gre_err(struct sk_buff
*skb
, struct inet6_skb_parm
*opt
,
386 u8 type
, u8 code
, int offset
, __be32 info
)
388 struct net
*net
= dev_net(skb
->dev
);
389 const struct gre_base_hdr
*greh
;
390 const struct ipv6hdr
*ipv6h
;
391 int grehlen
= sizeof(*greh
);
397 if (!pskb_may_pull(skb
, offset
+ grehlen
))
399 greh
= (const struct gre_base_hdr
*)(skb
->data
+ offset
);
401 if (flags
& (GRE_VERSION
| GRE_ROUTING
))
403 if (flags
& GRE_CSUM
)
405 if (flags
& GRE_KEY
) {
406 key_off
= grehlen
+ offset
;
410 if (!pskb_may_pull(skb
, offset
+ grehlen
))
412 ipv6h
= (const struct ipv6hdr
*)skb
->data
;
413 greh
= (const struct gre_base_hdr
*)(skb
->data
+ offset
);
414 key
= key_off
? *(__be32
*)(skb
->data
+ key_off
) : 0;
416 t
= ip6gre_tunnel_lookup(skb
->dev
, &ipv6h
->daddr
, &ipv6h
->saddr
,
417 key
, greh
->protocol
);
422 struct ipv6_tlv_tnl_enc_lim
*tel
;
424 case ICMPV6_DEST_UNREACH
:
425 net_dbg_ratelimited("%s: Path to destination invalid or inactive!\n",
427 if (code
!= ICMPV6_PORT_UNREACH
)
430 case ICMPV6_TIME_EXCEED
:
431 if (code
== ICMPV6_EXC_HOPLIMIT
) {
432 net_dbg_ratelimited("%s: Too small hop limit or routing loop in tunnel!\n",
437 case ICMPV6_PARAMPROB
:
439 if (code
== ICMPV6_HDR_FIELD
)
440 teli
= ip6_tnl_parse_tlv_enc_lim(skb
, skb
->data
);
442 if (teli
&& teli
== be32_to_cpu(info
) - 2) {
443 tel
= (struct ipv6_tlv_tnl_enc_lim
*) &skb
->data
[teli
];
444 if (tel
->encap_limit
== 0) {
445 net_dbg_ratelimited("%s: Too small encapsulation limit or routing loop in tunnel!\n",
449 net_dbg_ratelimited("%s: Recipient unable to parse tunneled packet!\n",
453 case ICMPV6_PKT_TOOBIG
:
454 ip6_update_pmtu(skb
, net
, info
, 0, 0, sock_net_uid(net
, NULL
));
457 ip6_redirect(skb
, net
, skb
->dev
->ifindex
, 0,
458 sock_net_uid(net
, NULL
));
462 if (time_before(jiffies
, t
->err_time
+ IP6TUNNEL_ERR_TIMEO
))
466 t
->err_time
= jiffies
;
469 static int ip6gre_rcv(struct sk_buff
*skb
, const struct tnl_ptk_info
*tpi
)
471 const struct ipv6hdr
*ipv6h
;
472 struct ip6_tnl
*tunnel
;
474 ipv6h
= ipv6_hdr(skb
);
475 tunnel
= ip6gre_tunnel_lookup(skb
->dev
,
476 &ipv6h
->saddr
, &ipv6h
->daddr
, tpi
->key
,
479 if (tunnel
->parms
.collect_md
) {
480 struct metadata_dst
*tun_dst
;
485 tun_id
= key32_to_tunnel_id(tpi
->key
);
487 tun_dst
= ipv6_tun_rx_dst(skb
, flags
, tun_id
, 0);
489 return PACKET_REJECT
;
491 ip6_tnl_rcv(tunnel
, skb
, tpi
, tun_dst
, log_ecn_error
);
493 ip6_tnl_rcv(tunnel
, skb
, tpi
, NULL
, log_ecn_error
);
499 return PACKET_REJECT
;
502 static int ip6erspan_rcv(struct sk_buff
*skb
, int gre_hdr_len
,
503 struct tnl_ptk_info
*tpi
)
505 struct erspan_base_hdr
*ershdr
;
506 struct erspan_metadata
*pkt_md
;
507 const struct ipv6hdr
*ipv6h
;
508 struct erspan_md2
*md2
;
509 struct ip6_tnl
*tunnel
;
512 if (unlikely(!pskb_may_pull(skb
, sizeof(*ershdr
))))
513 return PACKET_REJECT
;
515 ipv6h
= ipv6_hdr(skb
);
516 ershdr
= (struct erspan_base_hdr
*)skb
->data
;
518 tpi
->key
= cpu_to_be32(get_session_id(ershdr
));
520 tunnel
= ip6gre_tunnel_lookup(skb
->dev
,
521 &ipv6h
->saddr
, &ipv6h
->daddr
, tpi
->key
,
524 int len
= erspan_hdr_len(ver
);
526 if (unlikely(!pskb_may_pull(skb
, len
)))
527 return PACKET_REJECT
;
529 ershdr
= (struct erspan_base_hdr
*)skb
->data
;
530 pkt_md
= (struct erspan_metadata
*)(ershdr
+ 1);
532 if (__iptunnel_pull_header(skb
, len
,
535 return PACKET_REJECT
;
537 if (tunnel
->parms
.collect_md
) {
538 struct metadata_dst
*tun_dst
;
539 struct ip_tunnel_info
*info
;
540 struct erspan_metadata
*md
;
544 tpi
->flags
|= TUNNEL_KEY
;
546 tun_id
= key32_to_tunnel_id(tpi
->key
);
548 tun_dst
= ipv6_tun_rx_dst(skb
, flags
, tun_id
,
551 return PACKET_REJECT
;
553 info
= &tun_dst
->u
.tun_info
;
554 md
= ip_tunnel_info_opts(info
);
557 memcpy(md2
, pkt_md
, ver
== 1 ? ERSPAN_V1_MDSIZE
:
559 info
->key
.tun_flags
|= TUNNEL_ERSPAN_OPT
;
560 info
->options_len
= sizeof(*md
);
562 ip6_tnl_rcv(tunnel
, skb
, tpi
, tun_dst
, log_ecn_error
);
565 ip6_tnl_rcv(tunnel
, skb
, tpi
, NULL
, log_ecn_error
);
571 return PACKET_REJECT
;
574 static int gre_rcv(struct sk_buff
*skb
)
576 struct tnl_ptk_info tpi
;
577 bool csum_err
= false;
580 hdr_len
= gre_parse_header(skb
, &tpi
, &csum_err
, htons(ETH_P_IPV6
), 0);
584 if (iptunnel_pull_header(skb
, hdr_len
, tpi
.proto
, false))
587 if (unlikely(tpi
.proto
== htons(ETH_P_ERSPAN
) ||
588 tpi
.proto
== htons(ETH_P_ERSPAN2
))) {
589 if (ip6erspan_rcv(skb
, hdr_len
, &tpi
) == PACKET_RCVD
)
594 if (ip6gre_rcv(skb
, &tpi
) == PACKET_RCVD
)
598 icmpv6_send(skb
, ICMPV6_DEST_UNREACH
, ICMPV6_PORT_UNREACH
, 0);
604 static int gre_handle_offloads(struct sk_buff
*skb
, bool csum
)
606 return iptunnel_handle_offloads(skb
,
607 csum
? SKB_GSO_GRE_CSUM
: SKB_GSO_GRE
);
610 static void prepare_ip6gre_xmit_ipv4(struct sk_buff
*skb
,
611 struct net_device
*dev
,
612 struct flowi6
*fl6
, __u8
*dsfield
,
615 const struct iphdr
*iph
= ip_hdr(skb
);
616 struct ip6_tnl
*t
= netdev_priv(dev
);
618 if (!(t
->parms
.flags
& IP6_TNL_F_IGN_ENCAP_LIMIT
))
619 *encap_limit
= t
->parms
.encap_limit
;
621 memcpy(fl6
, &t
->fl
.u
.ip6
, sizeof(*fl6
));
623 if (t
->parms
.flags
& IP6_TNL_F_USE_ORIG_TCLASS
)
624 *dsfield
= ipv4_get_dsfield(iph
);
626 *dsfield
= ip6_tclass(t
->parms
.flowinfo
);
628 if (t
->parms
.flags
& IP6_TNL_F_USE_ORIG_FWMARK
)
629 fl6
->flowi6_mark
= skb
->mark
;
631 fl6
->flowi6_mark
= t
->parms
.fwmark
;
633 fl6
->flowi6_uid
= sock_net_uid(dev_net(dev
), NULL
);
636 static int prepare_ip6gre_xmit_ipv6(struct sk_buff
*skb
,
637 struct net_device
*dev
,
638 struct flowi6
*fl6
, __u8
*dsfield
,
641 struct ipv6hdr
*ipv6h
= ipv6_hdr(skb
);
642 struct ip6_tnl
*t
= netdev_priv(dev
);
645 offset
= ip6_tnl_parse_tlv_enc_lim(skb
, skb_network_header(skb
));
646 /* ip6_tnl_parse_tlv_enc_lim() might have reallocated skb->head */
649 struct ipv6_tlv_tnl_enc_lim
*tel
;
651 tel
= (struct ipv6_tlv_tnl_enc_lim
*)&skb_network_header(skb
)[offset
];
652 if (tel
->encap_limit
== 0) {
653 icmpv6_send(skb
, ICMPV6_PARAMPROB
,
654 ICMPV6_HDR_FIELD
, offset
+ 2);
657 *encap_limit
= tel
->encap_limit
- 1;
658 } else if (!(t
->parms
.flags
& IP6_TNL_F_IGN_ENCAP_LIMIT
)) {
659 *encap_limit
= t
->parms
.encap_limit
;
662 memcpy(fl6
, &t
->fl
.u
.ip6
, sizeof(*fl6
));
664 if (t
->parms
.flags
& IP6_TNL_F_USE_ORIG_TCLASS
)
665 *dsfield
= ipv6_get_dsfield(ipv6h
);
667 *dsfield
= ip6_tclass(t
->parms
.flowinfo
);
669 if (t
->parms
.flags
& IP6_TNL_F_USE_ORIG_FLOWLABEL
)
670 fl6
->flowlabel
|= ip6_flowlabel(ipv6h
);
672 if (t
->parms
.flags
& IP6_TNL_F_USE_ORIG_FWMARK
)
673 fl6
->flowi6_mark
= skb
->mark
;
675 fl6
->flowi6_mark
= t
->parms
.fwmark
;
677 fl6
->flowi6_uid
= sock_net_uid(dev_net(dev
), NULL
);
682 static netdev_tx_t
__gre6_xmit(struct sk_buff
*skb
,
683 struct net_device
*dev
, __u8 dsfield
,
684 struct flowi6
*fl6
, int encap_limit
,
685 __u32
*pmtu
, __be16 proto
)
687 struct ip6_tnl
*tunnel
= netdev_priv(dev
);
690 if (dev
->type
== ARPHRD_ETHER
)
691 IPCB(skb
)->flags
= 0;
693 if (dev
->header_ops
&& dev
->type
== ARPHRD_IP6GRE
)
694 fl6
->daddr
= ((struct ipv6hdr
*)skb
->data
)->daddr
;
696 fl6
->daddr
= tunnel
->parms
.raddr
;
698 if (tunnel
->parms
.o_flags
& TUNNEL_SEQ
)
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
& (TUNNEL_CSUM
| TUNNEL_KEY
);
724 tunnel
->tun_hlen
= gre_calc_hlen(flags
);
726 gre_build_header(skb
, tunnel
->tun_hlen
,
728 tunnel_id_to_key32(tun_info
->key
.tun_id
), 0);
731 gre_build_header(skb
, tunnel
->tun_hlen
, tunnel
->parms
.o_flags
,
732 protocol
, tunnel
->parms
.o_key
,
733 htonl(tunnel
->o_seqno
));
736 return ip6_tnl_xmit(skb
, dev
, dsfield
, fl6
, encap_limit
, pmtu
,
740 static inline int ip6gre_xmit_ipv4(struct sk_buff
*skb
, struct net_device
*dev
)
742 struct ip6_tnl
*t
= netdev_priv(dev
);
743 int encap_limit
= -1;
749 memset(&(IPCB(skb
)->opt
), 0, sizeof(IPCB(skb
)->opt
));
751 if (!t
->parms
.collect_md
)
752 prepare_ip6gre_xmit_ipv4(skb
, dev
, &fl6
,
753 &dsfield
, &encap_limit
);
755 err
= gre_handle_offloads(skb
, !!(t
->parms
.o_flags
& TUNNEL_CSUM
));
759 err
= __gre6_xmit(skb
, dev
, dsfield
, &fl6
, encap_limit
, &mtu
,
762 /* XXX: send ICMP error even if DF is not set. */
763 if (err
== -EMSGSIZE
)
764 icmp_send(skb
, ICMP_DEST_UNREACH
, ICMP_FRAG_NEEDED
,
772 static inline int ip6gre_xmit_ipv6(struct sk_buff
*skb
, struct net_device
*dev
)
774 struct ip6_tnl
*t
= netdev_priv(dev
);
775 struct ipv6hdr
*ipv6h
= ipv6_hdr(skb
);
776 int encap_limit
= -1;
782 if (ipv6_addr_equal(&t
->parms
.raddr
, &ipv6h
->saddr
))
785 if (!t
->parms
.collect_md
&&
786 prepare_ip6gre_xmit_ipv6(skb
, dev
, &fl6
, &dsfield
, &encap_limit
))
789 if (gre_handle_offloads(skb
, !!(t
->parms
.o_flags
& TUNNEL_CSUM
)))
792 err
= __gre6_xmit(skb
, dev
, dsfield
, &fl6
, encap_limit
,
793 &mtu
, skb
->protocol
);
795 if (err
== -EMSGSIZE
)
796 icmpv6_send(skb
, ICMPV6_PKT_TOOBIG
, 0, mtu
);
804 * ip6_tnl_addr_conflict - compare packet addresses to tunnel's own
805 * @t: the outgoing tunnel device
806 * @hdr: IPv6 header from the incoming packet
809 * Avoid trivial tunneling loop by checking that tunnel exit-point
810 * doesn't match source of incoming packet.
817 static inline bool ip6gre_tnl_addr_conflict(const struct ip6_tnl
*t
,
818 const struct ipv6hdr
*hdr
)
820 return ipv6_addr_equal(&t
->parms
.raddr
, &hdr
->saddr
);
823 static int ip6gre_xmit_other(struct sk_buff
*skb
, struct net_device
*dev
)
825 struct ip6_tnl
*t
= netdev_priv(dev
);
826 int encap_limit
= -1;
831 if (!(t
->parms
.flags
& IP6_TNL_F_IGN_ENCAP_LIMIT
))
832 encap_limit
= t
->parms
.encap_limit
;
834 if (!t
->parms
.collect_md
)
835 memcpy(&fl6
, &t
->fl
.u
.ip6
, sizeof(fl6
));
837 err
= gre_handle_offloads(skb
, !!(t
->parms
.o_flags
& TUNNEL_CSUM
));
841 err
= __gre6_xmit(skb
, dev
, 0, &fl6
, encap_limit
, &mtu
, skb
->protocol
);
846 static netdev_tx_t
ip6gre_tunnel_xmit(struct sk_buff
*skb
,
847 struct net_device
*dev
)
849 struct ip6_tnl
*t
= netdev_priv(dev
);
850 struct net_device_stats
*stats
= &t
->dev
->stats
;
853 if (!ip6_tnl_xmit_ctl(t
, &t
->parms
.laddr
, &t
->parms
.raddr
))
856 switch (skb
->protocol
) {
857 case htons(ETH_P_IP
):
858 ret
= ip6gre_xmit_ipv4(skb
, dev
);
860 case htons(ETH_P_IPV6
):
861 ret
= ip6gre_xmit_ipv6(skb
, dev
);
864 ret
= ip6gre_xmit_other(skb
, dev
);
880 static netdev_tx_t
ip6erspan_tunnel_xmit(struct sk_buff
*skb
,
881 struct net_device
*dev
)
883 struct ipv6hdr
*ipv6h
= ipv6_hdr(skb
);
884 struct ip6_tnl
*t
= netdev_priv(dev
);
885 struct dst_entry
*dst
= skb_dst(skb
);
886 struct net_device_stats
*stats
;
887 bool truncate
= false;
888 int encap_limit
= -1;
889 __u8 dsfield
= false;
894 if (!ip6_tnl_xmit_ctl(t
, &t
->parms
.laddr
, &t
->parms
.raddr
))
897 if (gre_handle_offloads(skb
, false))
900 if (skb
->len
> dev
->mtu
+ dev
->hard_header_len
) {
901 pskb_trim(skb
, dev
->mtu
+ dev
->hard_header_len
);
905 t
->parms
.o_flags
&= ~TUNNEL_KEY
;
906 IPCB(skb
)->flags
= 0;
908 /* For collect_md mode, derive fl6 from the tunnel key,
909 * for native mode, call prepare_ip6gre_xmit_{ipv4,ipv6}.
911 if (t
->parms
.collect_md
) {
912 struct ip_tunnel_info
*tun_info
;
913 const struct ip_tunnel_key
*key
;
914 struct erspan_metadata
*md
;
917 tun_info
= skb_tunnel_info(skb
);
918 if (unlikely(!tun_info
||
919 !(tun_info
->mode
& IP_TUNNEL_INFO_TX
) ||
920 ip_tunnel_info_af(tun_info
) != AF_INET6
))
923 key
= &tun_info
->key
;
924 memset(&fl6
, 0, sizeof(fl6
));
925 fl6
.flowi6_proto
= IPPROTO_GRE
;
926 fl6
.daddr
= key
->u
.ipv6
.dst
;
927 fl6
.flowlabel
= key
->label
;
928 fl6
.flowi6_uid
= sock_net_uid(dev_net(dev
), NULL
);
931 md
= ip_tunnel_info_opts(tun_info
);
935 tun_id
= tunnel_id_to_key32(key
->tun_id
);
936 if (md
->version
== 1) {
937 erspan_build_header(skb
,
939 ntohl(md
->u
.index
), truncate
,
941 } else if (md
->version
== 2) {
942 erspan_build_header_v2(skb
,
945 get_hwid(&md
->u
.md2
),
949 switch (skb
->protocol
) {
950 case htons(ETH_P_IP
):
951 memset(&(IPCB(skb
)->opt
), 0, sizeof(IPCB(skb
)->opt
));
952 prepare_ip6gre_xmit_ipv4(skb
, dev
, &fl6
,
953 &dsfield
, &encap_limit
);
955 case htons(ETH_P_IPV6
):
956 if (ipv6_addr_equal(&t
->parms
.raddr
, &ipv6h
->saddr
))
958 if (prepare_ip6gre_xmit_ipv6(skb
, dev
, &fl6
,
959 &dsfield
, &encap_limit
))
963 memcpy(&fl6
, &t
->fl
.u
.ip6
, sizeof(fl6
));
967 if (t
->parms
.erspan_ver
== 1)
968 erspan_build_header(skb
, ntohl(t
->parms
.o_key
),
972 erspan_build_header_v2(skb
, ntohl(t
->parms
.o_key
),
976 fl6
.daddr
= t
->parms
.raddr
;
979 /* Push GRE header. */
980 gre_build_header(skb
, 8, TUNNEL_SEQ
,
981 htons(ETH_P_ERSPAN
), 0, htonl(t
->o_seqno
++));
983 /* TooBig packet may have updated dst->dev's mtu */
984 if (!t
->parms
.collect_md
&& dst
&& dst_mtu(dst
) > dst
->dev
->mtu
)
985 dst
->ops
->update_pmtu(dst
, NULL
, skb
, dst
->dev
->mtu
);
987 err
= ip6_tnl_xmit(skb
, dev
, dsfield
, &fl6
, encap_limit
, &mtu
,
990 /* XXX: send ICMP error even if DF is not set. */
991 if (err
== -EMSGSIZE
) {
992 if (skb
->protocol
== htons(ETH_P_IP
))
993 icmp_send(skb
, ICMP_DEST_UNREACH
,
994 ICMP_FRAG_NEEDED
, htonl(mtu
));
996 icmpv6_send(skb
, ICMPV6_PKT_TOOBIG
, 0, mtu
);
1001 return NETDEV_TX_OK
;
1004 stats
= &t
->dev
->stats
;
1006 stats
->tx_dropped
++;
1008 return NETDEV_TX_OK
;
1011 static void ip6gre_tnl_link_config(struct ip6_tnl
*t
, int set_mtu
)
1013 struct net_device
*dev
= t
->dev
;
1014 struct __ip6_tnl_parm
*p
= &t
->parms
;
1015 struct flowi6
*fl6
= &t
->fl
.u
.ip6
;
1018 if (dev
->type
!= ARPHRD_ETHER
) {
1019 memcpy(dev
->dev_addr
, &p
->laddr
, sizeof(struct in6_addr
));
1020 memcpy(dev
->broadcast
, &p
->raddr
, sizeof(struct in6_addr
));
1023 /* Set up flowi template */
1024 fl6
->saddr
= p
->laddr
;
1025 fl6
->daddr
= p
->raddr
;
1026 fl6
->flowi6_oif
= p
->link
;
1028 fl6
->flowi6_proto
= IPPROTO_GRE
;
1030 if (!(p
->flags
&IP6_TNL_F_USE_ORIG_TCLASS
))
1031 fl6
->flowlabel
|= IPV6_TCLASS_MASK
& p
->flowinfo
;
1032 if (!(p
->flags
&IP6_TNL_F_USE_ORIG_FLOWLABEL
))
1033 fl6
->flowlabel
|= IPV6_FLOWLABEL_MASK
& p
->flowinfo
;
1035 p
->flags
&= ~(IP6_TNL_F_CAP_XMIT
|IP6_TNL_F_CAP_RCV
|IP6_TNL_F_CAP_PER_PACKET
);
1036 p
->flags
|= ip6_tnl_get_cap(t
, &p
->laddr
, &p
->raddr
);
1038 if (p
->flags
&IP6_TNL_F_CAP_XMIT
&&
1039 p
->flags
&IP6_TNL_F_CAP_RCV
&& dev
->type
!= ARPHRD_ETHER
)
1040 dev
->flags
|= IFF_POINTOPOINT
;
1042 dev
->flags
&= ~IFF_POINTOPOINT
;
1044 t
->tun_hlen
= gre_calc_hlen(t
->parms
.o_flags
);
1046 t
->hlen
= t
->encap_hlen
+ t
->tun_hlen
;
1048 t_hlen
= t
->hlen
+ sizeof(struct ipv6hdr
);
1050 if (p
->flags
& IP6_TNL_F_CAP_XMIT
) {
1051 int strict
= (ipv6_addr_type(&p
->raddr
) &
1052 (IPV6_ADDR_MULTICAST
|IPV6_ADDR_LINKLOCAL
));
1054 struct rt6_info
*rt
= rt6_lookup(t
->net
,
1055 &p
->raddr
, &p
->laddr
,
1062 dev
->hard_header_len
= rt
->dst
.dev
->hard_header_len
+
1066 dev
->mtu
= rt
->dst
.dev
->mtu
- t_hlen
;
1067 if (!(t
->parms
.flags
& IP6_TNL_F_IGN_ENCAP_LIMIT
))
1069 if (dev
->type
== ARPHRD_ETHER
)
1070 dev
->mtu
-= ETH_HLEN
;
1072 if (dev
->mtu
< IPV6_MIN_MTU
)
1073 dev
->mtu
= IPV6_MIN_MTU
;
1080 static int ip6gre_tnl_change(struct ip6_tnl
*t
,
1081 const struct __ip6_tnl_parm
*p
, int set_mtu
)
1083 t
->parms
.laddr
= p
->laddr
;
1084 t
->parms
.raddr
= p
->raddr
;
1085 t
->parms
.flags
= p
->flags
;
1086 t
->parms
.hop_limit
= p
->hop_limit
;
1087 t
->parms
.encap_limit
= p
->encap_limit
;
1088 t
->parms
.flowinfo
= p
->flowinfo
;
1089 t
->parms
.link
= p
->link
;
1090 t
->parms
.proto
= p
->proto
;
1091 t
->parms
.i_key
= p
->i_key
;
1092 t
->parms
.o_key
= p
->o_key
;
1093 t
->parms
.i_flags
= p
->i_flags
;
1094 t
->parms
.o_flags
= p
->o_flags
;
1095 t
->parms
.fwmark
= p
->fwmark
;
1096 dst_cache_reset(&t
->dst_cache
);
1097 ip6gre_tnl_link_config(t
, set_mtu
);
1101 static void ip6gre_tnl_parm_from_user(struct __ip6_tnl_parm
*p
,
1102 const struct ip6_tnl_parm2
*u
)
1104 p
->laddr
= u
->laddr
;
1105 p
->raddr
= u
->raddr
;
1106 p
->flags
= u
->flags
;
1107 p
->hop_limit
= u
->hop_limit
;
1108 p
->encap_limit
= u
->encap_limit
;
1109 p
->flowinfo
= u
->flowinfo
;
1111 p
->i_key
= u
->i_key
;
1112 p
->o_key
= u
->o_key
;
1113 p
->i_flags
= gre_flags_to_tnl_flags(u
->i_flags
);
1114 p
->o_flags
= gre_flags_to_tnl_flags(u
->o_flags
);
1115 memcpy(p
->name
, u
->name
, sizeof(u
->name
));
1118 static void ip6gre_tnl_parm_to_user(struct ip6_tnl_parm2
*u
,
1119 const struct __ip6_tnl_parm
*p
)
1121 u
->proto
= IPPROTO_GRE
;
1122 u
->laddr
= p
->laddr
;
1123 u
->raddr
= p
->raddr
;
1124 u
->flags
= p
->flags
;
1125 u
->hop_limit
= p
->hop_limit
;
1126 u
->encap_limit
= p
->encap_limit
;
1127 u
->flowinfo
= p
->flowinfo
;
1129 u
->i_key
= p
->i_key
;
1130 u
->o_key
= p
->o_key
;
1131 u
->i_flags
= gre_tnl_flags_to_gre_flags(p
->i_flags
);
1132 u
->o_flags
= gre_tnl_flags_to_gre_flags(p
->o_flags
);
1133 memcpy(u
->name
, p
->name
, sizeof(u
->name
));
1136 static int ip6gre_tunnel_ioctl(struct net_device
*dev
,
1137 struct ifreq
*ifr
, int cmd
)
1140 struct ip6_tnl_parm2 p
;
1141 struct __ip6_tnl_parm p1
;
1142 struct ip6_tnl
*t
= netdev_priv(dev
);
1143 struct net
*net
= t
->net
;
1144 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
1146 memset(&p1
, 0, sizeof(p1
));
1150 if (dev
== ign
->fb_tunnel_dev
) {
1151 if (copy_from_user(&p
, ifr
->ifr_ifru
.ifru_data
, sizeof(p
))) {
1155 ip6gre_tnl_parm_from_user(&p1
, &p
);
1156 t
= ip6gre_tunnel_locate(net
, &p1
, 0);
1158 t
= netdev_priv(dev
);
1160 memset(&p
, 0, sizeof(p
));
1161 ip6gre_tnl_parm_to_user(&p
, &t
->parms
);
1162 if (copy_to_user(ifr
->ifr_ifru
.ifru_data
, &p
, sizeof(p
)))
1169 if (!ns_capable(net
->user_ns
, CAP_NET_ADMIN
))
1173 if (copy_from_user(&p
, ifr
->ifr_ifru
.ifru_data
, sizeof(p
)))
1177 if ((p
.i_flags
|p
.o_flags
)&(GRE_VERSION
|GRE_ROUTING
))
1180 if (!(p
.i_flags
&GRE_KEY
))
1182 if (!(p
.o_flags
&GRE_KEY
))
1185 ip6gre_tnl_parm_from_user(&p1
, &p
);
1186 t
= ip6gre_tunnel_locate(net
, &p1
, cmd
== SIOCADDTUNNEL
);
1188 if (dev
!= ign
->fb_tunnel_dev
&& cmd
== SIOCCHGTUNNEL
) {
1190 if (t
->dev
!= dev
) {
1195 t
= netdev_priv(dev
);
1197 ip6gre_tunnel_unlink(ign
, t
);
1199 ip6gre_tnl_change(t
, &p1
, 1);
1200 ip6gre_tunnel_link(ign
, t
);
1201 netdev_state_change(dev
);
1208 memset(&p
, 0, sizeof(p
));
1209 ip6gre_tnl_parm_to_user(&p
, &t
->parms
);
1210 if (copy_to_user(ifr
->ifr_ifru
.ifru_data
, &p
, sizeof(p
)))
1213 err
= (cmd
== SIOCADDTUNNEL
? -ENOBUFS
: -ENOENT
);
1218 if (!ns_capable(net
->user_ns
, CAP_NET_ADMIN
))
1221 if (dev
== ign
->fb_tunnel_dev
) {
1223 if (copy_from_user(&p
, ifr
->ifr_ifru
.ifru_data
, sizeof(p
)))
1226 ip6gre_tnl_parm_from_user(&p1
, &p
);
1227 t
= ip6gre_tunnel_locate(net
, &p1
, 0);
1231 if (t
== netdev_priv(ign
->fb_tunnel_dev
))
1235 unregister_netdevice(dev
);
1247 static int ip6gre_header(struct sk_buff
*skb
, struct net_device
*dev
,
1248 unsigned short type
, const void *daddr
,
1249 const void *saddr
, unsigned int len
)
1251 struct ip6_tnl
*t
= netdev_priv(dev
);
1252 struct ipv6hdr
*ipv6h
;
1255 ipv6h
= skb_push(skb
, t
->hlen
+ sizeof(*ipv6h
));
1256 ip6_flow_hdr(ipv6h
, 0, ip6_make_flowlabel(dev_net(dev
), skb
,
1257 t
->fl
.u
.ip6
.flowlabel
,
1258 true, &t
->fl
.u
.ip6
));
1259 ipv6h
->hop_limit
= t
->parms
.hop_limit
;
1260 ipv6h
->nexthdr
= NEXTHDR_GRE
;
1261 ipv6h
->saddr
= t
->parms
.laddr
;
1262 ipv6h
->daddr
= t
->parms
.raddr
;
1264 p
= (__be16
*)(ipv6h
+ 1);
1265 p
[0] = t
->parms
.o_flags
;
1269 * Set the source hardware address.
1273 memcpy(&ipv6h
->saddr
, saddr
, sizeof(struct in6_addr
));
1275 memcpy(&ipv6h
->daddr
, daddr
, sizeof(struct in6_addr
));
1276 if (!ipv6_addr_any(&ipv6h
->daddr
))
1282 static const struct header_ops ip6gre_header_ops
= {
1283 .create
= ip6gre_header
,
1286 static const struct net_device_ops ip6gre_netdev_ops
= {
1287 .ndo_init
= ip6gre_tunnel_init
,
1288 .ndo_uninit
= ip6gre_tunnel_uninit
,
1289 .ndo_start_xmit
= ip6gre_tunnel_xmit
,
1290 .ndo_do_ioctl
= ip6gre_tunnel_ioctl
,
1291 .ndo_change_mtu
= ip6_tnl_change_mtu
,
1292 .ndo_get_stats64
= ip_tunnel_get_stats64
,
1293 .ndo_get_iflink
= ip6_tnl_get_iflink
,
1296 static void ip6gre_dev_free(struct net_device
*dev
)
1298 struct ip6_tnl
*t
= netdev_priv(dev
);
1300 dst_cache_destroy(&t
->dst_cache
);
1301 free_percpu(dev
->tstats
);
1304 static void ip6gre_tunnel_setup(struct net_device
*dev
)
1306 dev
->netdev_ops
= &ip6gre_netdev_ops
;
1307 dev
->needs_free_netdev
= true;
1308 dev
->priv_destructor
= ip6gre_dev_free
;
1310 dev
->type
= ARPHRD_IP6GRE
;
1312 dev
->flags
|= IFF_NOARP
;
1313 dev
->addr_len
= sizeof(struct in6_addr
);
1314 netif_keep_dst(dev
);
1315 /* This perm addr will be used as interface identifier by IPv6 */
1316 dev
->addr_assign_type
= NET_ADDR_RANDOM
;
1317 eth_random_addr(dev
->perm_addr
);
1320 #define GRE6_FEATURES (NETIF_F_SG | \
1321 NETIF_F_FRAGLIST | \
1325 static void ip6gre_tnl_init_features(struct net_device
*dev
)
1327 struct ip6_tnl
*nt
= netdev_priv(dev
);
1329 dev
->features
|= GRE6_FEATURES
;
1330 dev
->hw_features
|= GRE6_FEATURES
;
1332 if (!(nt
->parms
.o_flags
& TUNNEL_SEQ
)) {
1333 /* TCP offload with GRE SEQ is not supported, nor
1334 * can we support 2 levels of outer headers requiring
1337 if (!(nt
->parms
.o_flags
& TUNNEL_CSUM
) ||
1338 nt
->encap
.type
== TUNNEL_ENCAP_NONE
) {
1339 dev
->features
|= NETIF_F_GSO_SOFTWARE
;
1340 dev
->hw_features
|= NETIF_F_GSO_SOFTWARE
;
1343 /* Can use a lockless transmit, unless we generate
1346 dev
->features
|= NETIF_F_LLTX
;
1350 static int ip6gre_tunnel_init_common(struct net_device
*dev
)
1352 struct ip6_tnl
*tunnel
;
1356 tunnel
= netdev_priv(dev
);
1359 tunnel
->net
= dev_net(dev
);
1360 strcpy(tunnel
->parms
.name
, dev
->name
);
1362 dev
->tstats
= netdev_alloc_pcpu_stats(struct pcpu_sw_netstats
);
1366 ret
= dst_cache_init(&tunnel
->dst_cache
, GFP_KERNEL
);
1368 free_percpu(dev
->tstats
);
1373 tunnel
->tun_hlen
= gre_calc_hlen(tunnel
->parms
.o_flags
);
1374 tunnel
->hlen
= tunnel
->tun_hlen
+ tunnel
->encap_hlen
;
1375 t_hlen
= tunnel
->hlen
+ sizeof(struct ipv6hdr
);
1377 dev
->hard_header_len
= LL_MAX_HEADER
+ t_hlen
;
1378 dev
->mtu
= ETH_DATA_LEN
- t_hlen
;
1379 if (dev
->type
== ARPHRD_ETHER
)
1380 dev
->mtu
-= ETH_HLEN
;
1381 if (!(tunnel
->parms
.flags
& IP6_TNL_F_IGN_ENCAP_LIMIT
))
1384 if (tunnel
->parms
.collect_md
) {
1385 dev
->features
|= NETIF_F_NETNS_LOCAL
;
1386 netif_keep_dst(dev
);
1388 ip6gre_tnl_init_features(dev
);
1393 static int ip6gre_tunnel_init(struct net_device
*dev
)
1395 struct ip6_tnl
*tunnel
;
1398 ret
= ip6gre_tunnel_init_common(dev
);
1402 tunnel
= netdev_priv(dev
);
1404 if (tunnel
->parms
.collect_md
)
1407 memcpy(dev
->dev_addr
, &tunnel
->parms
.laddr
, sizeof(struct in6_addr
));
1408 memcpy(dev
->broadcast
, &tunnel
->parms
.raddr
, sizeof(struct in6_addr
));
1410 if (ipv6_addr_any(&tunnel
->parms
.raddr
))
1411 dev
->header_ops
= &ip6gre_header_ops
;
1416 static void ip6gre_fb_tunnel_init(struct net_device
*dev
)
1418 struct ip6_tnl
*tunnel
= netdev_priv(dev
);
1421 tunnel
->net
= dev_net(dev
);
1422 strcpy(tunnel
->parms
.name
, dev
->name
);
1424 tunnel
->hlen
= sizeof(struct ipv6hdr
) + 4;
1429 static struct inet6_protocol ip6gre_protocol __read_mostly
= {
1431 .err_handler
= ip6gre_err
,
1432 .flags
= INET6_PROTO_NOPOLICY
|INET6_PROTO_FINAL
,
1435 static void ip6gre_destroy_tunnels(struct net
*net
, struct list_head
*head
)
1437 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
1438 struct net_device
*dev
, *aux
;
1441 for_each_netdev_safe(net
, dev
, aux
)
1442 if (dev
->rtnl_link_ops
== &ip6gre_link_ops
||
1443 dev
->rtnl_link_ops
== &ip6gre_tap_ops
||
1444 dev
->rtnl_link_ops
== &ip6erspan_tap_ops
)
1445 unregister_netdevice_queue(dev
, head
);
1447 for (prio
= 0; prio
< 4; prio
++) {
1449 for (h
= 0; h
< IP6_GRE_HASH_SIZE
; h
++) {
1452 t
= rtnl_dereference(ign
->tunnels
[prio
][h
]);
1455 /* If dev is in the same netns, it has already
1456 * been added to the list by the previous loop.
1458 if (!net_eq(dev_net(t
->dev
), net
))
1459 unregister_netdevice_queue(t
->dev
,
1461 t
= rtnl_dereference(t
->next
);
1467 static int __net_init
ip6gre_init_net(struct net
*net
)
1469 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
1472 ign
->fb_tunnel_dev
= alloc_netdev(sizeof(struct ip6_tnl
), "ip6gre0",
1474 ip6gre_tunnel_setup
);
1475 if (!ign
->fb_tunnel_dev
) {
1479 dev_net_set(ign
->fb_tunnel_dev
, net
);
1480 /* FB netdevice is special: we have one, and only one per netns.
1481 * Allowing to move it to another netns is clearly unsafe.
1483 ign
->fb_tunnel_dev
->features
|= NETIF_F_NETNS_LOCAL
;
1486 ip6gre_fb_tunnel_init(ign
->fb_tunnel_dev
);
1487 ign
->fb_tunnel_dev
->rtnl_link_ops
= &ip6gre_link_ops
;
1489 err
= register_netdev(ign
->fb_tunnel_dev
);
1493 rcu_assign_pointer(ign
->tunnels_wc
[0],
1494 netdev_priv(ign
->fb_tunnel_dev
));
1498 free_netdev(ign
->fb_tunnel_dev
);
1503 static void __net_exit
ip6gre_exit_batch_net(struct list_head
*net_list
)
1509 list_for_each_entry(net
, net_list
, exit_list
)
1510 ip6gre_destroy_tunnels(net
, &list
);
1511 unregister_netdevice_many(&list
);
1515 static struct pernet_operations ip6gre_net_ops
= {
1516 .init
= ip6gre_init_net
,
1517 .exit_batch
= ip6gre_exit_batch_net
,
1518 .id
= &ip6gre_net_id
,
1519 .size
= sizeof(struct ip6gre_net
),
1522 static int ip6gre_tunnel_validate(struct nlattr
*tb
[], struct nlattr
*data
[],
1523 struct netlink_ext_ack
*extack
)
1531 if (data
[IFLA_GRE_IFLAGS
])
1532 flags
|= nla_get_be16(data
[IFLA_GRE_IFLAGS
]);
1533 if (data
[IFLA_GRE_OFLAGS
])
1534 flags
|= nla_get_be16(data
[IFLA_GRE_OFLAGS
]);
1535 if (flags
& (GRE_VERSION
|GRE_ROUTING
))
1541 static int ip6gre_tap_validate(struct nlattr
*tb
[], struct nlattr
*data
[],
1542 struct netlink_ext_ack
*extack
)
1544 struct in6_addr daddr
;
1546 if (tb
[IFLA_ADDRESS
]) {
1547 if (nla_len(tb
[IFLA_ADDRESS
]) != ETH_ALEN
)
1549 if (!is_valid_ether_addr(nla_data(tb
[IFLA_ADDRESS
])))
1550 return -EADDRNOTAVAIL
;
1556 if (data
[IFLA_GRE_REMOTE
]) {
1557 daddr
= nla_get_in6_addr(data
[IFLA_GRE_REMOTE
]);
1558 if (ipv6_addr_any(&daddr
))
1563 return ip6gre_tunnel_validate(tb
, data
, extack
);
1566 static int ip6erspan_tap_validate(struct nlattr
*tb
[], struct nlattr
*data
[],
1567 struct netlink_ext_ack
*extack
)
1575 ret
= ip6gre_tap_validate(tb
, data
, extack
);
1579 /* ERSPAN should only have GRE sequence and key flag */
1580 if (data
[IFLA_GRE_OFLAGS
])
1581 flags
|= nla_get_be16(data
[IFLA_GRE_OFLAGS
]);
1582 if (data
[IFLA_GRE_IFLAGS
])
1583 flags
|= nla_get_be16(data
[IFLA_GRE_IFLAGS
]);
1584 if (!data
[IFLA_GRE_COLLECT_METADATA
] &&
1585 flags
!= (GRE_SEQ
| GRE_KEY
))
1588 /* ERSPAN Session ID only has 10-bit. Since we reuse
1589 * 32-bit key field as ID, check it's range.
1591 if (data
[IFLA_GRE_IKEY
] &&
1592 (ntohl(nla_get_be32(data
[IFLA_GRE_IKEY
])) & ~ID_MASK
))
1595 if (data
[IFLA_GRE_OKEY
] &&
1596 (ntohl(nla_get_be32(data
[IFLA_GRE_OKEY
])) & ~ID_MASK
))
1599 if (data
[IFLA_GRE_ERSPAN_VER
]) {
1600 ver
= nla_get_u8(data
[IFLA_GRE_ERSPAN_VER
]);
1601 if (ver
!= 1 && ver
!= 2)
1606 if (data
[IFLA_GRE_ERSPAN_INDEX
]) {
1607 u32 index
= nla_get_u32(data
[IFLA_GRE_ERSPAN_INDEX
]);
1609 if (index
& ~INDEX_MASK
)
1612 } else if (ver
== 2) {
1613 if (data
[IFLA_GRE_ERSPAN_DIR
]) {
1614 u16 dir
= nla_get_u8(data
[IFLA_GRE_ERSPAN_DIR
]);
1616 if (dir
& ~(DIR_MASK
>> DIR_OFFSET
))
1620 if (data
[IFLA_GRE_ERSPAN_HWID
]) {
1621 u16 hwid
= nla_get_u16(data
[IFLA_GRE_ERSPAN_HWID
]);
1623 if (hwid
& ~(HWID_MASK
>> HWID_OFFSET
))
1631 static void ip6gre_netlink_parms(struct nlattr
*data
[],
1632 struct __ip6_tnl_parm
*parms
)
1634 memset(parms
, 0, sizeof(*parms
));
1639 if (data
[IFLA_GRE_LINK
])
1640 parms
->link
= nla_get_u32(data
[IFLA_GRE_LINK
]);
1642 if (data
[IFLA_GRE_IFLAGS
])
1643 parms
->i_flags
= gre_flags_to_tnl_flags(
1644 nla_get_be16(data
[IFLA_GRE_IFLAGS
]));
1646 if (data
[IFLA_GRE_OFLAGS
])
1647 parms
->o_flags
= gre_flags_to_tnl_flags(
1648 nla_get_be16(data
[IFLA_GRE_OFLAGS
]));
1650 if (data
[IFLA_GRE_IKEY
])
1651 parms
->i_key
= nla_get_be32(data
[IFLA_GRE_IKEY
]);
1653 if (data
[IFLA_GRE_OKEY
])
1654 parms
->o_key
= nla_get_be32(data
[IFLA_GRE_OKEY
]);
1656 if (data
[IFLA_GRE_LOCAL
])
1657 parms
->laddr
= nla_get_in6_addr(data
[IFLA_GRE_LOCAL
]);
1659 if (data
[IFLA_GRE_REMOTE
])
1660 parms
->raddr
= nla_get_in6_addr(data
[IFLA_GRE_REMOTE
]);
1662 if (data
[IFLA_GRE_TTL
])
1663 parms
->hop_limit
= nla_get_u8(data
[IFLA_GRE_TTL
]);
1665 if (data
[IFLA_GRE_ENCAP_LIMIT
])
1666 parms
->encap_limit
= nla_get_u8(data
[IFLA_GRE_ENCAP_LIMIT
]);
1668 if (data
[IFLA_GRE_FLOWINFO
])
1669 parms
->flowinfo
= nla_get_be32(data
[IFLA_GRE_FLOWINFO
]);
1671 if (data
[IFLA_GRE_FLAGS
])
1672 parms
->flags
= nla_get_u32(data
[IFLA_GRE_FLAGS
]);
1674 if (data
[IFLA_GRE_FWMARK
])
1675 parms
->fwmark
= nla_get_u32(data
[IFLA_GRE_FWMARK
]);
1677 if (data
[IFLA_GRE_COLLECT_METADATA
])
1678 parms
->collect_md
= true;
1680 if (data
[IFLA_GRE_ERSPAN_VER
])
1681 parms
->erspan_ver
= nla_get_u8(data
[IFLA_GRE_ERSPAN_VER
]);
1683 if (parms
->erspan_ver
== 1) {
1684 if (data
[IFLA_GRE_ERSPAN_INDEX
])
1685 parms
->index
= nla_get_u32(data
[IFLA_GRE_ERSPAN_INDEX
]);
1686 } else if (parms
->erspan_ver
== 2) {
1687 if (data
[IFLA_GRE_ERSPAN_DIR
])
1688 parms
->dir
= nla_get_u8(data
[IFLA_GRE_ERSPAN_DIR
]);
1689 if (data
[IFLA_GRE_ERSPAN_HWID
])
1690 parms
->hwid
= nla_get_u16(data
[IFLA_GRE_ERSPAN_HWID
]);
1694 static int ip6gre_tap_init(struct net_device
*dev
)
1698 ret
= ip6gre_tunnel_init_common(dev
);
1702 dev
->priv_flags
|= IFF_LIVE_ADDR_CHANGE
;
1707 static const struct net_device_ops ip6gre_tap_netdev_ops
= {
1708 .ndo_init
= ip6gre_tap_init
,
1709 .ndo_uninit
= ip6gre_tunnel_uninit
,
1710 .ndo_start_xmit
= ip6gre_tunnel_xmit
,
1711 .ndo_set_mac_address
= eth_mac_addr
,
1712 .ndo_validate_addr
= eth_validate_addr
,
1713 .ndo_change_mtu
= ip6_tnl_change_mtu
,
1714 .ndo_get_stats64
= ip_tunnel_get_stats64
,
1715 .ndo_get_iflink
= ip6_tnl_get_iflink
,
1718 static int ip6erspan_tap_init(struct net_device
*dev
)
1720 struct ip6_tnl
*tunnel
;
1724 tunnel
= netdev_priv(dev
);
1727 tunnel
->net
= dev_net(dev
);
1728 strcpy(tunnel
->parms
.name
, dev
->name
);
1730 dev
->tstats
= netdev_alloc_pcpu_stats(struct pcpu_sw_netstats
);
1734 ret
= dst_cache_init(&tunnel
->dst_cache
, GFP_KERNEL
);
1736 free_percpu(dev
->tstats
);
1741 tunnel
->tun_hlen
= 8;
1742 tunnel
->hlen
= tunnel
->tun_hlen
+ tunnel
->encap_hlen
+
1743 erspan_hdr_len(tunnel
->parms
.erspan_ver
);
1744 t_hlen
= tunnel
->hlen
+ sizeof(struct ipv6hdr
);
1746 dev
->hard_header_len
= LL_MAX_HEADER
+ t_hlen
;
1747 dev
->mtu
= ETH_DATA_LEN
- t_hlen
;
1748 if (dev
->type
== ARPHRD_ETHER
)
1749 dev
->mtu
-= ETH_HLEN
;
1750 if (!(tunnel
->parms
.flags
& IP6_TNL_F_IGN_ENCAP_LIMIT
))
1753 dev
->priv_flags
|= IFF_LIVE_ADDR_CHANGE
;
1754 tunnel
= netdev_priv(dev
);
1755 ip6gre_tnl_link_config(tunnel
, 1);
1760 static const struct net_device_ops ip6erspan_netdev_ops
= {
1761 .ndo_init
= ip6erspan_tap_init
,
1762 .ndo_uninit
= ip6gre_tunnel_uninit
,
1763 .ndo_start_xmit
= ip6erspan_tunnel_xmit
,
1764 .ndo_set_mac_address
= eth_mac_addr
,
1765 .ndo_validate_addr
= eth_validate_addr
,
1766 .ndo_change_mtu
= ip6_tnl_change_mtu
,
1767 .ndo_get_stats64
= ip_tunnel_get_stats64
,
1768 .ndo_get_iflink
= ip6_tnl_get_iflink
,
1771 static void ip6gre_tap_setup(struct net_device
*dev
)
1777 dev
->netdev_ops
= &ip6gre_tap_netdev_ops
;
1778 dev
->needs_free_netdev
= true;
1779 dev
->priv_destructor
= ip6gre_dev_free
;
1781 dev
->features
|= NETIF_F_NETNS_LOCAL
;
1782 dev
->priv_flags
&= ~IFF_TX_SKB_SHARING
;
1783 dev
->priv_flags
|= IFF_LIVE_ADDR_CHANGE
;
1784 netif_keep_dst(dev
);
1787 static bool ip6gre_netlink_encap_parms(struct nlattr
*data
[],
1788 struct ip_tunnel_encap
*ipencap
)
1792 memset(ipencap
, 0, sizeof(*ipencap
));
1797 if (data
[IFLA_GRE_ENCAP_TYPE
]) {
1799 ipencap
->type
= nla_get_u16(data
[IFLA_GRE_ENCAP_TYPE
]);
1802 if (data
[IFLA_GRE_ENCAP_FLAGS
]) {
1804 ipencap
->flags
= nla_get_u16(data
[IFLA_GRE_ENCAP_FLAGS
]);
1807 if (data
[IFLA_GRE_ENCAP_SPORT
]) {
1809 ipencap
->sport
= nla_get_be16(data
[IFLA_GRE_ENCAP_SPORT
]);
1812 if (data
[IFLA_GRE_ENCAP_DPORT
]) {
1814 ipencap
->dport
= nla_get_be16(data
[IFLA_GRE_ENCAP_DPORT
]);
1820 static int ip6gre_newlink(struct net
*src_net
, struct net_device
*dev
,
1821 struct nlattr
*tb
[], struct nlattr
*data
[],
1822 struct netlink_ext_ack
*extack
)
1825 struct net
*net
= dev_net(dev
);
1826 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
1827 struct ip_tunnel_encap ipencap
;
1830 nt
= netdev_priv(dev
);
1832 if (ip6gre_netlink_encap_parms(data
, &ipencap
)) {
1833 int err
= ip6_tnl_encap_setup(nt
, &ipencap
);
1839 ip6gre_netlink_parms(data
, &nt
->parms
);
1841 if (nt
->parms
.collect_md
) {
1842 if (rtnl_dereference(ign
->collect_md_tun
))
1845 if (ip6gre_tunnel_find(net
, &nt
->parms
, dev
->type
))
1849 if (dev
->type
== ARPHRD_ETHER
&& !tb
[IFLA_ADDRESS
])
1850 eth_hw_addr_random(dev
);
1853 nt
->net
= dev_net(dev
);
1855 err
= register_netdevice(dev
);
1859 ip6gre_tnl_link_config(nt
, !tb
[IFLA_MTU
]);
1862 ip6_tnl_change_mtu(dev
, nla_get_u32(tb
[IFLA_MTU
]));
1865 ip6gre_tunnel_link(ign
, nt
);
1871 static int ip6gre_changelink(struct net_device
*dev
, struct nlattr
*tb
[],
1872 struct nlattr
*data
[],
1873 struct netlink_ext_ack
*extack
)
1875 struct ip6_tnl
*t
, *nt
= netdev_priv(dev
);
1876 struct net
*net
= nt
->net
;
1877 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
1878 struct __ip6_tnl_parm p
;
1879 struct ip_tunnel_encap ipencap
;
1881 if (dev
== ign
->fb_tunnel_dev
)
1884 if (ip6gre_netlink_encap_parms(data
, &ipencap
)) {
1885 int err
= ip6_tnl_encap_setup(nt
, &ipencap
);
1891 ip6gre_netlink_parms(data
, &p
);
1893 t
= ip6gre_tunnel_locate(net
, &p
, 0);
1902 ip6gre_tunnel_unlink(ign
, t
);
1903 ip6gre_tnl_change(t
, &p
, !tb
[IFLA_MTU
]);
1904 ip6gre_tunnel_link(ign
, t
);
1908 static void ip6gre_dellink(struct net_device
*dev
, struct list_head
*head
)
1910 struct net
*net
= dev_net(dev
);
1911 struct ip6gre_net
*ign
= net_generic(net
, ip6gre_net_id
);
1913 if (dev
!= ign
->fb_tunnel_dev
)
1914 unregister_netdevice_queue(dev
, head
);
1917 static size_t ip6gre_get_size(const struct net_device
*dev
)
1922 /* IFLA_GRE_IFLAGS */
1924 /* IFLA_GRE_OFLAGS */
1930 /* IFLA_GRE_LOCAL */
1931 nla_total_size(sizeof(struct in6_addr
)) +
1932 /* IFLA_GRE_REMOTE */
1933 nla_total_size(sizeof(struct in6_addr
)) +
1936 /* IFLA_GRE_ENCAP_LIMIT */
1938 /* IFLA_GRE_FLOWINFO */
1940 /* IFLA_GRE_FLAGS */
1942 /* IFLA_GRE_ENCAP_TYPE */
1944 /* IFLA_GRE_ENCAP_FLAGS */
1946 /* IFLA_GRE_ENCAP_SPORT */
1948 /* IFLA_GRE_ENCAP_DPORT */
1950 /* IFLA_GRE_COLLECT_METADATA */
1952 /* IFLA_GRE_FWMARK */
1954 /* IFLA_GRE_ERSPAN_INDEX */
1959 static int ip6gre_fill_info(struct sk_buff
*skb
, const struct net_device
*dev
)
1961 struct ip6_tnl
*t
= netdev_priv(dev
);
1962 struct __ip6_tnl_parm
*p
= &t
->parms
;
1964 if (nla_put_u32(skb
, IFLA_GRE_LINK
, p
->link
) ||
1965 nla_put_be16(skb
, IFLA_GRE_IFLAGS
,
1966 gre_tnl_flags_to_gre_flags(p
->i_flags
)) ||
1967 nla_put_be16(skb
, IFLA_GRE_OFLAGS
,
1968 gre_tnl_flags_to_gre_flags(p
->o_flags
)) ||
1969 nla_put_be32(skb
, IFLA_GRE_IKEY
, p
->i_key
) ||
1970 nla_put_be32(skb
, IFLA_GRE_OKEY
, p
->o_key
) ||
1971 nla_put_in6_addr(skb
, IFLA_GRE_LOCAL
, &p
->laddr
) ||
1972 nla_put_in6_addr(skb
, IFLA_GRE_REMOTE
, &p
->raddr
) ||
1973 nla_put_u8(skb
, IFLA_GRE_TTL
, p
->hop_limit
) ||
1974 nla_put_u8(skb
, IFLA_GRE_ENCAP_LIMIT
, p
->encap_limit
) ||
1975 nla_put_be32(skb
, IFLA_GRE_FLOWINFO
, p
->flowinfo
) ||
1976 nla_put_u32(skb
, IFLA_GRE_FLAGS
, p
->flags
) ||
1977 nla_put_u32(skb
, IFLA_GRE_FWMARK
, p
->fwmark
) ||
1978 nla_put_u32(skb
, IFLA_GRE_ERSPAN_INDEX
, p
->index
))
1979 goto nla_put_failure
;
1981 if (nla_put_u16(skb
, IFLA_GRE_ENCAP_TYPE
,
1983 nla_put_be16(skb
, IFLA_GRE_ENCAP_SPORT
,
1985 nla_put_be16(skb
, IFLA_GRE_ENCAP_DPORT
,
1987 nla_put_u16(skb
, IFLA_GRE_ENCAP_FLAGS
,
1989 goto nla_put_failure
;
1991 if (p
->collect_md
) {
1992 if (nla_put_flag(skb
, IFLA_GRE_COLLECT_METADATA
))
1993 goto nla_put_failure
;
1996 if (nla_put_u8(skb
, IFLA_GRE_ERSPAN_VER
, p
->erspan_ver
))
1997 goto nla_put_failure
;
1999 if (p
->erspan_ver
== 1) {
2000 if (nla_put_u32(skb
, IFLA_GRE_ERSPAN_INDEX
, p
->index
))
2001 goto nla_put_failure
;
2002 } else if (p
->erspan_ver
== 2) {
2003 if (nla_put_u8(skb
, IFLA_GRE_ERSPAN_DIR
, p
->dir
))
2004 goto nla_put_failure
;
2005 if (nla_put_u16(skb
, IFLA_GRE_ERSPAN_HWID
, p
->hwid
))
2006 goto nla_put_failure
;
2015 static const struct nla_policy ip6gre_policy
[IFLA_GRE_MAX
+ 1] = {
2016 [IFLA_GRE_LINK
] = { .type
= NLA_U32
},
2017 [IFLA_GRE_IFLAGS
] = { .type
= NLA_U16
},
2018 [IFLA_GRE_OFLAGS
] = { .type
= NLA_U16
},
2019 [IFLA_GRE_IKEY
] = { .type
= NLA_U32
},
2020 [IFLA_GRE_OKEY
] = { .type
= NLA_U32
},
2021 [IFLA_GRE_LOCAL
] = { .len
= FIELD_SIZEOF(struct ipv6hdr
, saddr
) },
2022 [IFLA_GRE_REMOTE
] = { .len
= FIELD_SIZEOF(struct ipv6hdr
, daddr
) },
2023 [IFLA_GRE_TTL
] = { .type
= NLA_U8
},
2024 [IFLA_GRE_ENCAP_LIMIT
] = { .type
= NLA_U8
},
2025 [IFLA_GRE_FLOWINFO
] = { .type
= NLA_U32
},
2026 [IFLA_GRE_FLAGS
] = { .type
= NLA_U32
},
2027 [IFLA_GRE_ENCAP_TYPE
] = { .type
= NLA_U16
},
2028 [IFLA_GRE_ENCAP_FLAGS
] = { .type
= NLA_U16
},
2029 [IFLA_GRE_ENCAP_SPORT
] = { .type
= NLA_U16
},
2030 [IFLA_GRE_ENCAP_DPORT
] = { .type
= NLA_U16
},
2031 [IFLA_GRE_COLLECT_METADATA
] = { .type
= NLA_FLAG
},
2032 [IFLA_GRE_FWMARK
] = { .type
= NLA_U32
},
2033 [IFLA_GRE_ERSPAN_INDEX
] = { .type
= NLA_U32
},
2034 [IFLA_GRE_ERSPAN_VER
] = { .type
= NLA_U8
},
2035 [IFLA_GRE_ERSPAN_DIR
] = { .type
= NLA_U8
},
2036 [IFLA_GRE_ERSPAN_HWID
] = { .type
= NLA_U16
},
2039 static void ip6erspan_tap_setup(struct net_device
*dev
)
2043 dev
->netdev_ops
= &ip6erspan_netdev_ops
;
2044 dev
->needs_free_netdev
= true;
2045 dev
->priv_destructor
= ip6gre_dev_free
;
2047 dev
->features
|= NETIF_F_NETNS_LOCAL
;
2048 dev
->priv_flags
&= ~IFF_TX_SKB_SHARING
;
2049 dev
->priv_flags
|= IFF_LIVE_ADDR_CHANGE
;
2050 netif_keep_dst(dev
);
2053 static struct rtnl_link_ops ip6gre_link_ops __read_mostly
= {
2055 .maxtype
= IFLA_GRE_MAX
,
2056 .policy
= ip6gre_policy
,
2057 .priv_size
= sizeof(struct ip6_tnl
),
2058 .setup
= ip6gre_tunnel_setup
,
2059 .validate
= ip6gre_tunnel_validate
,
2060 .newlink
= ip6gre_newlink
,
2061 .changelink
= ip6gre_changelink
,
2062 .dellink
= ip6gre_dellink
,
2063 .get_size
= ip6gre_get_size
,
2064 .fill_info
= ip6gre_fill_info
,
2065 .get_link_net
= ip6_tnl_get_link_net
,
2068 static struct rtnl_link_ops ip6gre_tap_ops __read_mostly
= {
2069 .kind
= "ip6gretap",
2070 .maxtype
= IFLA_GRE_MAX
,
2071 .policy
= ip6gre_policy
,
2072 .priv_size
= sizeof(struct ip6_tnl
),
2073 .setup
= ip6gre_tap_setup
,
2074 .validate
= ip6gre_tap_validate
,
2075 .newlink
= ip6gre_newlink
,
2076 .changelink
= ip6gre_changelink
,
2077 .get_size
= ip6gre_get_size
,
2078 .fill_info
= ip6gre_fill_info
,
2079 .get_link_net
= ip6_tnl_get_link_net
,
2082 static struct rtnl_link_ops ip6erspan_tap_ops __read_mostly
= {
2083 .kind
= "ip6erspan",
2084 .maxtype
= IFLA_GRE_MAX
,
2085 .policy
= ip6gre_policy
,
2086 .priv_size
= sizeof(struct ip6_tnl
),
2087 .setup
= ip6erspan_tap_setup
,
2088 .validate
= ip6erspan_tap_validate
,
2089 .newlink
= ip6gre_newlink
,
2090 .changelink
= ip6gre_changelink
,
2091 .get_size
= ip6gre_get_size
,
2092 .fill_info
= ip6gre_fill_info
,
2093 .get_link_net
= ip6_tnl_get_link_net
,
2097 * And now the modules code and kernel interface.
2100 static int __init
ip6gre_init(void)
2104 pr_info("GRE over IPv6 tunneling driver\n");
2106 err
= register_pernet_device(&ip6gre_net_ops
);
2110 err
= inet6_add_protocol(&ip6gre_protocol
, IPPROTO_GRE
);
2112 pr_info("%s: can't add protocol\n", __func__
);
2113 goto add_proto_failed
;
2116 err
= rtnl_link_register(&ip6gre_link_ops
);
2118 goto rtnl_link_failed
;
2120 err
= rtnl_link_register(&ip6gre_tap_ops
);
2122 goto tap_ops_failed
;
2124 err
= rtnl_link_register(&ip6erspan_tap_ops
);
2126 goto erspan_link_failed
;
2132 rtnl_link_unregister(&ip6gre_tap_ops
);
2134 rtnl_link_unregister(&ip6gre_link_ops
);
2136 inet6_del_protocol(&ip6gre_protocol
, IPPROTO_GRE
);
2138 unregister_pernet_device(&ip6gre_net_ops
);
2142 static void __exit
ip6gre_fini(void)
2144 rtnl_link_unregister(&ip6gre_tap_ops
);
2145 rtnl_link_unregister(&ip6gre_link_ops
);
2146 rtnl_link_unregister(&ip6erspan_tap_ops
);
2147 inet6_del_protocol(&ip6gre_protocol
, IPPROTO_GRE
);
2148 unregister_pernet_device(&ip6gre_net_ops
);
2151 module_init(ip6gre_init
);
2152 module_exit(ip6gre_fini
);
2153 MODULE_LICENSE("GPL");
2154 MODULE_AUTHOR("D. Kozlov (xeb@mail.ru)");
2155 MODULE_DESCRIPTION("GRE over IPv6 tunneling device");
2156 MODULE_ALIAS_RTNL_LINK("ip6gre");
2157 MODULE_ALIAS_RTNL_LINK("ip6gretap");
2158 MODULE_ALIAS_RTNL_LINK("ip6erspan");
2159 MODULE_ALIAS_NETDEV("ip6gre0");