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>
60 static bool log_ecn_error = true;
61 module_param(log_ecn_error, bool, 0644);
62 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
64 #define IP6_GRE_HASH_SIZE_SHIFT 5
65 #define IP6_GRE_HASH_SIZE (1 << IP6_GRE_HASH_SIZE_SHIFT)
67 static unsigned int ip6gre_net_id __read_mostly;
69 struct ip6_tnl __rcu *tunnels[4][IP6_GRE_HASH_SIZE];
71 struct net_device *fb_tunnel_dev;
74 static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
75 static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
76 static int ip6gre_tunnel_init(struct net_device *dev);
77 static void ip6gre_tunnel_setup(struct net_device *dev);
78 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
79 static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu);
81 /* Tunnel hash table */
91 We require exact key match i.e. if a key is present in packet
92 it will match only tunnel with the same key; if it is not present,
93 it will match only keyless tunnel.
95 All keysless packets, if not matched configured keyless tunnels
96 will match fallback tunnel.
99 #define HASH_KEY(key) (((__force u32)key^((__force u32)key>>4))&(IP6_GRE_HASH_SIZE - 1))
100 static u32 HASH_ADDR(const struct in6_addr *addr)
102 u32 hash = ipv6_addr_hash(addr);
104 return hash_32(hash, IP6_GRE_HASH_SIZE_SHIFT);
107 #define tunnels_r_l tunnels[3]
108 #define tunnels_r tunnels[2]
109 #define tunnels_l tunnels[1]
110 #define tunnels_wc tunnels[0]
112 /* Given src, dst and key, find appropriate for input tunnel. */
114 static struct ip6_tnl *ip6gre_tunnel_lookup(struct net_device *dev,
115 const struct in6_addr *remote, const struct in6_addr *local,
116 __be32 key, __be16 gre_proto)
118 struct net *net = dev_net(dev);
119 int link = dev->ifindex;
120 unsigned int h0 = HASH_ADDR(remote);
121 unsigned int h1 = HASH_KEY(key);
122 struct ip6_tnl *t, *cand = NULL;
123 struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
124 int dev_type = (gre_proto == htons(ETH_P_TEB)) ?
125 ARPHRD_ETHER : ARPHRD_IP6GRE;
126 int score, cand_score = 4;
127 struct net_device *ndev;
129 for_each_ip_tunnel_rcu(t, ign->tunnels_r_l[h0 ^ h1]) {
130 if (!ipv6_addr_equal(local, &t->parms.laddr) ||
131 !ipv6_addr_equal(remote, &t->parms.raddr) ||
132 key != t->parms.i_key ||
133 !(t->dev->flags & IFF_UP))
136 if (t->dev->type != ARPHRD_IP6GRE &&
137 t->dev->type != dev_type)
141 if (t->parms.link != link)
143 if (t->dev->type != dev_type)
148 if (score < cand_score) {
154 for_each_ip_tunnel_rcu(t, ign->tunnels_r[h0 ^ h1]) {
155 if (!ipv6_addr_equal(remote, &t->parms.raddr) ||
156 key != t->parms.i_key ||
157 !(t->dev->flags & IFF_UP))
160 if (t->dev->type != ARPHRD_IP6GRE &&
161 t->dev->type != dev_type)
165 if (t->parms.link != link)
167 if (t->dev->type != dev_type)
172 if (score < cand_score) {
178 for_each_ip_tunnel_rcu(t, ign->tunnels_l[h1]) {
179 if ((!ipv6_addr_equal(local, &t->parms.laddr) &&
180 (!ipv6_addr_equal(local, &t->parms.raddr) ||
181 !ipv6_addr_is_multicast(local))) ||
182 key != t->parms.i_key ||
183 !(t->dev->flags & IFF_UP))
186 if (t->dev->type != ARPHRD_IP6GRE &&
187 t->dev->type != dev_type)
191 if (t->parms.link != link)
193 if (t->dev->type != dev_type)
198 if (score < cand_score) {
204 for_each_ip_tunnel_rcu(t, ign->tunnels_wc[h1]) {
205 if (t->parms.i_key != key ||
206 !(t->dev->flags & IFF_UP))
209 if (t->dev->type != ARPHRD_IP6GRE &&
210 t->dev->type != dev_type)
214 if (t->parms.link != link)
216 if (t->dev->type != dev_type)
221 if (score < cand_score) {
230 ndev = READ_ONCE(ign->fb_tunnel_dev);
231 if (ndev && ndev->flags & IFF_UP)
232 return netdev_priv(ndev);
237 static struct ip6_tnl __rcu **__ip6gre_bucket(struct ip6gre_net *ign,
238 const struct __ip6_tnl_parm *p)
240 const struct in6_addr *remote = &p->raddr;
241 const struct in6_addr *local = &p->laddr;
242 unsigned int h = HASH_KEY(p->i_key);
245 if (!ipv6_addr_any(local))
247 if (!ipv6_addr_any(remote) && !ipv6_addr_is_multicast(remote)) {
249 h ^= HASH_ADDR(remote);
252 return &ign->tunnels[prio][h];
255 static inline struct ip6_tnl __rcu **ip6gre_bucket(struct ip6gre_net *ign,
256 const struct ip6_tnl *t)
258 return __ip6gre_bucket(ign, &t->parms);
261 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t)
263 struct ip6_tnl __rcu **tp = ip6gre_bucket(ign, t);
265 rcu_assign_pointer(t->next, rtnl_dereference(*tp));
266 rcu_assign_pointer(*tp, t);
269 static void ip6gre_tunnel_unlink(struct ip6gre_net *ign, struct ip6_tnl *t)
271 struct ip6_tnl __rcu **tp;
272 struct ip6_tnl *iter;
274 for (tp = ip6gre_bucket(ign, t);
275 (iter = rtnl_dereference(*tp)) != NULL;
278 rcu_assign_pointer(*tp, t->next);
284 static struct ip6_tnl *ip6gre_tunnel_find(struct net *net,
285 const struct __ip6_tnl_parm *parms,
288 const struct in6_addr *remote = &parms->raddr;
289 const struct in6_addr *local = &parms->laddr;
290 __be32 key = parms->i_key;
291 int link = parms->link;
293 struct ip6_tnl __rcu **tp;
294 struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
296 for (tp = __ip6gre_bucket(ign, parms);
297 (t = rtnl_dereference(*tp)) != NULL;
299 if (ipv6_addr_equal(local, &t->parms.laddr) &&
300 ipv6_addr_equal(remote, &t->parms.raddr) &&
301 key == t->parms.i_key &&
302 link == t->parms.link &&
303 type == t->dev->type)
309 static struct ip6_tnl *ip6gre_tunnel_locate(struct net *net,
310 const struct __ip6_tnl_parm *parms, int create)
312 struct ip6_tnl *t, *nt;
313 struct net_device *dev;
315 struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
317 t = ip6gre_tunnel_find(net, parms, ARPHRD_IP6GRE);
323 if (parms->name[0]) {
324 if (!dev_valid_name(parms->name))
326 strlcpy(name, parms->name, IFNAMSIZ);
328 strcpy(name, "ip6gre%d");
330 dev = alloc_netdev(sizeof(*t), name, NET_NAME_UNKNOWN,
331 ip6gre_tunnel_setup);
335 dev_net_set(dev, net);
337 nt = netdev_priv(dev);
339 dev->rtnl_link_ops = &ip6gre_link_ops;
342 nt->net = dev_net(dev);
344 if (register_netdevice(dev) < 0)
347 ip6gre_tnl_link_config(nt, 1);
349 /* Can use a lockless transmit, unless we generate output sequences */
350 if (!(nt->parms.o_flags & TUNNEL_SEQ))
351 dev->features |= NETIF_F_LLTX;
353 ip6gre_tunnel_link(ign, nt);
361 static void ip6gre_tunnel_uninit(struct net_device *dev)
363 struct ip6_tnl *t = netdev_priv(dev);
364 struct ip6gre_net *ign = net_generic(t->net, ip6gre_net_id);
366 ip6gre_tunnel_unlink(ign, t);
367 if (ign->fb_tunnel_dev == dev)
368 WRITE_ONCE(ign->fb_tunnel_dev, NULL);
369 dst_cache_reset(&t->dst_cache);
374 static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
375 u8 type, u8 code, int offset, __be32 info)
377 const struct gre_base_hdr *greh;
378 const struct ipv6hdr *ipv6h;
379 int grehlen = sizeof(*greh);
385 if (!pskb_may_pull(skb, offset + grehlen))
387 greh = (const struct gre_base_hdr *)(skb->data + offset);
389 if (flags & (GRE_VERSION | GRE_ROUTING))
391 if (flags & GRE_CSUM)
393 if (flags & GRE_KEY) {
394 key_off = grehlen + offset;
398 if (!pskb_may_pull(skb, offset + grehlen))
400 ipv6h = (const struct ipv6hdr *)skb->data;
401 greh = (const struct gre_base_hdr *)(skb->data + offset);
402 key = key_off ? *(__be32 *)(skb->data + key_off) : 0;
404 t = ip6gre_tunnel_lookup(skb->dev, &ipv6h->daddr, &ipv6h->saddr,
405 key, greh->protocol);
411 struct ipv6_tlv_tnl_enc_lim *tel;
413 case ICMPV6_DEST_UNREACH:
414 net_dbg_ratelimited("%s: Path to destination invalid or inactive!\n",
416 if (code != ICMPV6_PORT_UNREACH)
419 case ICMPV6_TIME_EXCEED:
420 if (code == ICMPV6_EXC_HOPLIMIT) {
421 net_dbg_ratelimited("%s: Too small hop limit or routing loop in tunnel!\n",
426 case ICMPV6_PARAMPROB:
428 if (code == ICMPV6_HDR_FIELD)
429 teli = ip6_tnl_parse_tlv_enc_lim(skb, skb->data);
431 if (teli && teli == be32_to_cpu(info) - 2) {
432 tel = (struct ipv6_tlv_tnl_enc_lim *) &skb->data[teli];
433 if (tel->encap_limit == 0) {
434 net_dbg_ratelimited("%s: Too small encapsulation limit or routing loop in tunnel!\n",
438 net_dbg_ratelimited("%s: Recipient unable to parse tunneled packet!\n",
442 case ICMPV6_PKT_TOOBIG:
443 mtu = be32_to_cpu(info) - offset - t->tun_hlen;
444 if (t->dev->type == ARPHRD_ETHER)
446 if (mtu < IPV6_MIN_MTU)
452 if (time_before(jiffies, t->err_time + IP6TUNNEL_ERR_TIMEO))
456 t->err_time = jiffies;
459 static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)
461 const struct ipv6hdr *ipv6h;
462 struct ip6_tnl *tunnel;
464 ipv6h = ipv6_hdr(skb);
465 tunnel = ip6gre_tunnel_lookup(skb->dev,
466 &ipv6h->saddr, &ipv6h->daddr, tpi->key,
469 ip6_tnl_rcv(tunnel, skb, tpi, NULL, log_ecn_error);
474 return PACKET_REJECT;
477 static int gre_rcv(struct sk_buff *skb)
479 struct tnl_ptk_info tpi;
480 bool csum_err = false;
483 hdr_len = gre_parse_header(skb, &tpi, &csum_err, htons(ETH_P_IPV6), 0);
487 if (iptunnel_pull_header(skb, hdr_len, tpi.proto, false))
490 if (ip6gre_rcv(skb, &tpi) == PACKET_RCVD)
493 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
499 static int gre_handle_offloads(struct sk_buff *skb, bool csum)
501 return iptunnel_handle_offloads(skb,
502 csum ? SKB_GSO_GRE_CSUM : SKB_GSO_GRE);
505 static netdev_tx_t __gre6_xmit(struct sk_buff *skb,
506 struct net_device *dev, __u8 dsfield,
507 struct flowi6 *fl6, int encap_limit,
508 __u32 *pmtu, __be16 proto)
510 struct ip6_tnl *tunnel = netdev_priv(dev);
511 struct dst_entry *dst = skb_dst(skb);
514 if (dev->type == ARPHRD_ETHER)
515 IPCB(skb)->flags = 0;
517 if (dev->header_ops && dev->type == ARPHRD_IP6GRE)
518 fl6->daddr = ((struct ipv6hdr *)skb->data)->daddr;
520 fl6->daddr = tunnel->parms.raddr;
522 if (tunnel->parms.o_flags & TUNNEL_SEQ)
525 /* Push GRE header. */
526 protocol = (dev->type == ARPHRD_ETHER) ? htons(ETH_P_TEB) : proto;
527 gre_build_header(skb, tunnel->tun_hlen, tunnel->parms.o_flags,
528 protocol, tunnel->parms.o_key, htonl(tunnel->o_seqno));
530 /* TooBig packet may have updated dst->dev's mtu */
531 if (dst && dst_mtu(dst) > dst->dev->mtu)
532 dst->ops->update_pmtu(dst, NULL, skb, dst->dev->mtu, false);
534 return ip6_tnl_xmit(skb, dev, dsfield, fl6, encap_limit, pmtu,
538 static inline int ip6gre_xmit_ipv4(struct sk_buff *skb, struct net_device *dev)
540 struct ip6_tnl *t = netdev_priv(dev);
541 const struct iphdr *iph = ip_hdr(skb);
542 int encap_limit = -1;
548 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
550 if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
551 encap_limit = t->parms.encap_limit;
553 memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
555 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
556 dsfield = ipv4_get_dsfield(iph);
558 dsfield = ip6_tclass(t->parms.flowinfo);
559 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
560 fl6.flowi6_mark = skb->mark;
562 fl6.flowi6_mark = t->parms.fwmark;
564 fl6.flowi6_uid = sock_net_uid(dev_net(dev), NULL);
566 err = gre_handle_offloads(skb, !!(t->parms.o_flags & TUNNEL_CSUM));
570 err = __gre6_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
573 /* XXX: send ICMP error even if DF is not set. */
574 if (err == -EMSGSIZE)
575 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
583 static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev)
585 struct ip6_tnl *t = netdev_priv(dev);
586 struct ipv6hdr *ipv6h = ipv6_hdr(skb);
587 int encap_limit = -1;
594 if (ipv6_addr_equal(&t->parms.raddr, &ipv6h->saddr))
597 offset = ip6_tnl_parse_tlv_enc_lim(skb, skb_network_header(skb));
598 /* ip6_tnl_parse_tlv_enc_lim() might have reallocated skb->head */
599 ipv6h = ipv6_hdr(skb);
602 struct ipv6_tlv_tnl_enc_lim *tel;
603 tel = (struct ipv6_tlv_tnl_enc_lim *)&skb_network_header(skb)[offset];
604 if (tel->encap_limit == 0) {
605 icmpv6_send(skb, ICMPV6_PARAMPROB,
606 ICMPV6_HDR_FIELD, offset + 2);
609 encap_limit = tel->encap_limit - 1;
610 } else if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
611 encap_limit = t->parms.encap_limit;
613 memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
615 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
616 dsfield = ipv6_get_dsfield(ipv6h);
618 dsfield = ip6_tclass(t->parms.flowinfo);
620 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
621 fl6.flowlabel |= ip6_flowlabel(ipv6h);
622 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
623 fl6.flowi6_mark = skb->mark;
625 fl6.flowi6_mark = t->parms.fwmark;
627 fl6.flowi6_uid = sock_net_uid(dev_net(dev), NULL);
629 if (gre_handle_offloads(skb, !!(t->parms.o_flags & TUNNEL_CSUM)))
632 err = __gre6_xmit(skb, dev, dsfield, &fl6, encap_limit,
633 &mtu, skb->protocol);
635 if (err == -EMSGSIZE)
636 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
644 * ip6_tnl_addr_conflict - compare packet addresses to tunnel's own
645 * @t: the outgoing tunnel device
646 * @hdr: IPv6 header from the incoming packet
649 * Avoid trivial tunneling loop by checking that tunnel exit-point
650 * doesn't match source of incoming packet.
657 static inline bool ip6gre_tnl_addr_conflict(const struct ip6_tnl *t,
658 const struct ipv6hdr *hdr)
660 return ipv6_addr_equal(&t->parms.raddr, &hdr->saddr);
663 static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev)
665 struct ip6_tnl *t = netdev_priv(dev);
666 int encap_limit = -1;
671 if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
672 encap_limit = t->parms.encap_limit;
674 memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
676 err = gre_handle_offloads(skb, !!(t->parms.o_flags & TUNNEL_CSUM));
680 err = __gre6_xmit(skb, dev, 0, &fl6, encap_limit, &mtu, skb->protocol);
685 static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,
686 struct net_device *dev)
688 struct ip6_tnl *t = netdev_priv(dev);
689 struct net_device_stats *stats = &t->dev->stats;
692 if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr))
695 switch (skb->protocol) {
696 case htons(ETH_P_IP):
697 ret = ip6gre_xmit_ipv4(skb, dev);
699 case htons(ETH_P_IPV6):
700 ret = ip6gre_xmit_ipv6(skb, dev);
703 ret = ip6gre_xmit_other(skb, dev);
719 static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
721 struct net_device *dev = t->dev;
722 struct __ip6_tnl_parm *p = &t->parms;
723 struct flowi6 *fl6 = &t->fl.u.ip6;
726 if (dev->type != ARPHRD_ETHER) {
727 memcpy(dev->dev_addr, &p->laddr, sizeof(struct in6_addr));
728 memcpy(dev->broadcast, &p->raddr, sizeof(struct in6_addr));
731 /* Set up flowi template */
732 fl6->saddr = p->laddr;
733 fl6->daddr = p->raddr;
734 fl6->flowi6_oif = p->link;
736 fl6->flowi6_proto = IPPROTO_GRE;
738 if (!(p->flags&IP6_TNL_F_USE_ORIG_TCLASS))
739 fl6->flowlabel |= IPV6_TCLASS_MASK & p->flowinfo;
740 if (!(p->flags&IP6_TNL_F_USE_ORIG_FLOWLABEL))
741 fl6->flowlabel |= IPV6_FLOWLABEL_MASK & p->flowinfo;
743 p->flags &= ~(IP6_TNL_F_CAP_XMIT|IP6_TNL_F_CAP_RCV|IP6_TNL_F_CAP_PER_PACKET);
744 p->flags |= ip6_tnl_get_cap(t, &p->laddr, &p->raddr);
746 if (p->flags&IP6_TNL_F_CAP_XMIT &&
747 p->flags&IP6_TNL_F_CAP_RCV && dev->type != ARPHRD_ETHER)
748 dev->flags |= IFF_POINTOPOINT;
750 dev->flags &= ~IFF_POINTOPOINT;
752 t->tun_hlen = gre_calc_hlen(t->parms.o_flags);
754 t->hlen = t->encap_hlen + t->tun_hlen;
756 t_hlen = t->hlen + sizeof(struct ipv6hdr);
758 if (p->flags & IP6_TNL_F_CAP_XMIT) {
759 int strict = (ipv6_addr_type(&p->raddr) &
760 (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL));
762 struct rt6_info *rt = rt6_lookup(t->net,
763 &p->raddr, &p->laddr,
770 dev->hard_header_len = rt->dst.dev->hard_header_len +
774 int mtu = rt->dst.dev->mtu - t_hlen;
776 if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
778 if (dev->type == ARPHRD_ETHER)
781 if (mtu < IPV6_MIN_MTU)
783 WRITE_ONCE(dev->mtu, mtu);
790 static int ip6gre_tnl_change(struct ip6_tnl *t,
791 const struct __ip6_tnl_parm *p, int set_mtu)
793 t->parms.laddr = p->laddr;
794 t->parms.raddr = p->raddr;
795 t->parms.flags = p->flags;
796 t->parms.hop_limit = p->hop_limit;
797 t->parms.encap_limit = p->encap_limit;
798 t->parms.flowinfo = p->flowinfo;
799 t->parms.link = p->link;
800 t->parms.proto = p->proto;
801 t->parms.i_key = p->i_key;
802 t->parms.o_key = p->o_key;
803 t->parms.i_flags = p->i_flags;
804 t->parms.o_flags = p->o_flags;
805 t->parms.fwmark = p->fwmark;
806 dst_cache_reset(&t->dst_cache);
807 ip6gre_tnl_link_config(t, set_mtu);
811 static void ip6gre_tnl_parm_from_user(struct __ip6_tnl_parm *p,
812 const struct ip6_tnl_parm2 *u)
817 p->hop_limit = u->hop_limit;
818 p->encap_limit = u->encap_limit;
819 p->flowinfo = u->flowinfo;
823 p->i_flags = gre_flags_to_tnl_flags(u->i_flags);
824 p->o_flags = gre_flags_to_tnl_flags(u->o_flags);
825 memcpy(p->name, u->name, sizeof(u->name));
828 static void ip6gre_tnl_parm_to_user(struct ip6_tnl_parm2 *u,
829 const struct __ip6_tnl_parm *p)
831 u->proto = IPPROTO_GRE;
835 u->hop_limit = p->hop_limit;
836 u->encap_limit = p->encap_limit;
837 u->flowinfo = p->flowinfo;
841 u->i_flags = gre_tnl_flags_to_gre_flags(p->i_flags);
842 u->o_flags = gre_tnl_flags_to_gre_flags(p->o_flags);
843 memcpy(u->name, p->name, sizeof(u->name));
846 static int ip6gre_tunnel_ioctl(struct net_device *dev,
847 struct ifreq *ifr, int cmd)
850 struct ip6_tnl_parm2 p;
851 struct __ip6_tnl_parm p1;
852 struct ip6_tnl *t = netdev_priv(dev);
853 struct net *net = t->net;
854 struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
856 memset(&p1, 0, sizeof(p1));
860 if (dev == ign->fb_tunnel_dev) {
861 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) {
865 ip6gre_tnl_parm_from_user(&p1, &p);
866 t = ip6gre_tunnel_locate(net, &p1, 0);
868 t = netdev_priv(dev);
870 memset(&p, 0, sizeof(p));
871 ip6gre_tnl_parm_to_user(&p, &t->parms);
872 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
879 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
883 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
887 if ((p.i_flags|p.o_flags)&(GRE_VERSION|GRE_ROUTING))
890 if (!(p.i_flags&GRE_KEY))
892 if (!(p.o_flags&GRE_KEY))
895 ip6gre_tnl_parm_from_user(&p1, &p);
896 t = ip6gre_tunnel_locate(net, &p1, cmd == SIOCADDTUNNEL);
898 if (dev != ign->fb_tunnel_dev && cmd == SIOCCHGTUNNEL) {
905 t = netdev_priv(dev);
907 ip6gre_tunnel_unlink(ign, t);
909 ip6gre_tnl_change(t, &p1, 1);
910 ip6gre_tunnel_link(ign, t);
911 netdev_state_change(dev);
918 memset(&p, 0, sizeof(p));
919 ip6gre_tnl_parm_to_user(&p, &t->parms);
920 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
923 err = (cmd == SIOCADDTUNNEL ? -ENOBUFS : -ENOENT);
928 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
931 if (dev == ign->fb_tunnel_dev) {
933 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
936 ip6gre_tnl_parm_from_user(&p1, &p);
937 t = ip6gre_tunnel_locate(net, &p1, 0);
941 if (t == netdev_priv(ign->fb_tunnel_dev))
945 unregister_netdevice(dev);
957 static int ip6gre_header(struct sk_buff *skb, struct net_device *dev,
958 unsigned short type, const void *daddr,
959 const void *saddr, unsigned int len)
961 struct ip6_tnl *t = netdev_priv(dev);
962 struct ipv6hdr *ipv6h;
965 ipv6h = skb_push(skb, t->hlen + sizeof(*ipv6h));
966 ip6_flow_hdr(ipv6h, 0, ip6_make_flowlabel(dev_net(dev), skb,
967 t->fl.u.ip6.flowlabel,
968 true, &t->fl.u.ip6));
969 ipv6h->hop_limit = t->parms.hop_limit;
970 ipv6h->nexthdr = NEXTHDR_GRE;
971 ipv6h->saddr = t->parms.laddr;
972 ipv6h->daddr = t->parms.raddr;
974 p = (__be16 *)(ipv6h + 1);
975 p[0] = t->parms.o_flags;
979 * Set the source hardware address.
983 memcpy(&ipv6h->saddr, saddr, sizeof(struct in6_addr));
985 memcpy(&ipv6h->daddr, daddr, sizeof(struct in6_addr));
986 if (!ipv6_addr_any(&ipv6h->daddr))
992 static const struct header_ops ip6gre_header_ops = {
993 .create = ip6gre_header,
996 static const struct net_device_ops ip6gre_netdev_ops = {
997 .ndo_init = ip6gre_tunnel_init,
998 .ndo_uninit = ip6gre_tunnel_uninit,
999 .ndo_start_xmit = ip6gre_tunnel_xmit,
1000 .ndo_do_ioctl = ip6gre_tunnel_ioctl,
1001 .ndo_change_mtu = ip6_tnl_change_mtu,
1002 .ndo_get_stats64 = ip_tunnel_get_stats64,
1003 .ndo_get_iflink = ip6_tnl_get_iflink,
1006 static void ip6gre_dev_free(struct net_device *dev)
1008 struct ip6_tnl *t = netdev_priv(dev);
1010 dst_cache_destroy(&t->dst_cache);
1011 free_percpu(dev->tstats);
1014 static void ip6gre_tunnel_setup(struct net_device *dev)
1016 dev->netdev_ops = &ip6gre_netdev_ops;
1017 dev->needs_free_netdev = true;
1018 dev->priv_destructor = ip6gre_dev_free;
1020 dev->type = ARPHRD_IP6GRE;
1022 dev->flags |= IFF_NOARP;
1023 dev->addr_len = sizeof(struct in6_addr);
1024 netif_keep_dst(dev);
1025 /* This perm addr will be used as interface identifier by IPv6 */
1026 dev->addr_assign_type = NET_ADDR_RANDOM;
1027 eth_random_addr(dev->perm_addr);
1030 #define GRE6_FEATURES (NETIF_F_SG | \
1031 NETIF_F_FRAGLIST | \
1035 static void ip6gre_tnl_init_features(struct net_device *dev)
1037 struct ip6_tnl *nt = netdev_priv(dev);
1039 dev->features |= GRE6_FEATURES;
1040 dev->hw_features |= GRE6_FEATURES;
1042 if (!(nt->parms.o_flags & TUNNEL_SEQ)) {
1043 /* TCP offload with GRE SEQ is not supported, nor
1044 * can we support 2 levels of outer headers requiring
1047 if (!(nt->parms.o_flags & TUNNEL_CSUM) ||
1048 nt->encap.type == TUNNEL_ENCAP_NONE) {
1049 dev->features |= NETIF_F_GSO_SOFTWARE;
1050 dev->hw_features |= NETIF_F_GSO_SOFTWARE;
1053 /* Can use a lockless transmit, unless we generate
1056 dev->features |= NETIF_F_LLTX;
1060 static int ip6gre_tunnel_init_common(struct net_device *dev)
1062 struct ip6_tnl *tunnel;
1066 tunnel = netdev_priv(dev);
1069 tunnel->net = dev_net(dev);
1070 strcpy(tunnel->parms.name, dev->name);
1072 dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
1076 ret = dst_cache_init(&tunnel->dst_cache, GFP_KERNEL);
1078 free_percpu(dev->tstats);
1083 tunnel->tun_hlen = gre_calc_hlen(tunnel->parms.o_flags);
1084 tunnel->hlen = tunnel->tun_hlen + tunnel->encap_hlen;
1085 t_hlen = tunnel->hlen + sizeof(struct ipv6hdr);
1087 dev->hard_header_len = LL_MAX_HEADER + t_hlen;
1088 dev->mtu = ETH_DATA_LEN - t_hlen;
1089 if (dev->type == ARPHRD_ETHER)
1090 dev->mtu -= ETH_HLEN;
1091 if (!(tunnel->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
1094 ip6gre_tnl_init_features(dev);
1099 static int ip6gre_tunnel_init(struct net_device *dev)
1101 struct ip6_tnl *tunnel;
1104 ret = ip6gre_tunnel_init_common(dev);
1108 tunnel = netdev_priv(dev);
1110 memcpy(dev->dev_addr, &tunnel->parms.laddr, sizeof(struct in6_addr));
1111 memcpy(dev->broadcast, &tunnel->parms.raddr, sizeof(struct in6_addr));
1113 if (ipv6_addr_any(&tunnel->parms.raddr))
1114 dev->header_ops = &ip6gre_header_ops;
1119 static void ip6gre_fb_tunnel_init(struct net_device *dev)
1121 struct ip6_tnl *tunnel = netdev_priv(dev);
1124 tunnel->net = dev_net(dev);
1125 strcpy(tunnel->parms.name, dev->name);
1127 tunnel->hlen = sizeof(struct ipv6hdr) + 4;
1131 static struct inet6_protocol ip6gre_protocol __read_mostly = {
1133 .err_handler = ip6gre_err,
1134 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
1137 static void ip6gre_destroy_tunnels(struct net *net, struct list_head *head)
1139 struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
1140 struct net_device *dev, *aux;
1143 for_each_netdev_safe(net, dev, aux)
1144 if (dev->rtnl_link_ops == &ip6gre_link_ops ||
1145 dev->rtnl_link_ops == &ip6gre_tap_ops)
1146 unregister_netdevice_queue(dev, head);
1148 for (prio = 0; prio < 4; prio++) {
1150 for (h = 0; h < IP6_GRE_HASH_SIZE; h++) {
1153 t = rtnl_dereference(ign->tunnels[prio][h]);
1156 /* If dev is in the same netns, it has already
1157 * been added to the list by the previous loop.
1159 if (!net_eq(dev_net(t->dev), net))
1160 unregister_netdevice_queue(t->dev,
1162 t = rtnl_dereference(t->next);
1168 static int __net_init ip6gre_init_net(struct net *net)
1170 struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
1171 struct net_device *ndev;
1174 ndev = alloc_netdev(sizeof(struct ip6_tnl), "ip6gre0",
1175 NET_NAME_UNKNOWN, ip6gre_tunnel_setup);
1180 ign->fb_tunnel_dev = ndev;
1181 dev_net_set(ign->fb_tunnel_dev, net);
1182 /* FB netdevice is special: we have one, and only one per netns.
1183 * Allowing to move it to another netns is clearly unsafe.
1185 ign->fb_tunnel_dev->features |= NETIF_F_NETNS_LOCAL;
1188 ip6gre_fb_tunnel_init(ign->fb_tunnel_dev);
1189 ign->fb_tunnel_dev->rtnl_link_ops = &ip6gre_link_ops;
1191 err = register_netdev(ign->fb_tunnel_dev);
1195 rcu_assign_pointer(ign->tunnels_wc[0],
1196 netdev_priv(ign->fb_tunnel_dev));
1205 static void __net_exit ip6gre_exit_net(struct net *net)
1210 ip6gre_destroy_tunnels(net, &list);
1211 unregister_netdevice_many(&list);
1215 static struct pernet_operations ip6gre_net_ops = {
1216 .init = ip6gre_init_net,
1217 .exit = ip6gre_exit_net,
1218 .id = &ip6gre_net_id,
1219 .size = sizeof(struct ip6gre_net),
1222 static int ip6gre_tunnel_validate(struct nlattr *tb[], struct nlattr *data[],
1223 struct netlink_ext_ack *extack)
1231 if (data[IFLA_GRE_IFLAGS])
1232 flags |= nla_get_be16(data[IFLA_GRE_IFLAGS]);
1233 if (data[IFLA_GRE_OFLAGS])
1234 flags |= nla_get_be16(data[IFLA_GRE_OFLAGS]);
1235 if (flags & (GRE_VERSION|GRE_ROUTING))
1241 static int ip6gre_tap_validate(struct nlattr *tb[], struct nlattr *data[],
1242 struct netlink_ext_ack *extack)
1244 struct in6_addr daddr;
1246 if (tb[IFLA_ADDRESS]) {
1247 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
1249 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
1250 return -EADDRNOTAVAIL;
1256 if (data[IFLA_GRE_REMOTE]) {
1257 daddr = nla_get_in6_addr(data[IFLA_GRE_REMOTE]);
1258 if (ipv6_addr_any(&daddr))
1263 return ip6gre_tunnel_validate(tb, data, extack);
1267 static void ip6gre_netlink_parms(struct nlattr *data[],
1268 struct __ip6_tnl_parm *parms)
1270 memset(parms, 0, sizeof(*parms));
1275 if (data[IFLA_GRE_LINK])
1276 parms->link = nla_get_u32(data[IFLA_GRE_LINK]);
1278 if (data[IFLA_GRE_IFLAGS])
1279 parms->i_flags = gre_flags_to_tnl_flags(
1280 nla_get_be16(data[IFLA_GRE_IFLAGS]));
1282 if (data[IFLA_GRE_OFLAGS])
1283 parms->o_flags = gre_flags_to_tnl_flags(
1284 nla_get_be16(data[IFLA_GRE_OFLAGS]));
1286 if (data[IFLA_GRE_IKEY])
1287 parms->i_key = nla_get_be32(data[IFLA_GRE_IKEY]);
1289 if (data[IFLA_GRE_OKEY])
1290 parms->o_key = nla_get_be32(data[IFLA_GRE_OKEY]);
1292 if (data[IFLA_GRE_LOCAL])
1293 parms->laddr = nla_get_in6_addr(data[IFLA_GRE_LOCAL]);
1295 if (data[IFLA_GRE_REMOTE])
1296 parms->raddr = nla_get_in6_addr(data[IFLA_GRE_REMOTE]);
1298 if (data[IFLA_GRE_TTL])
1299 parms->hop_limit = nla_get_u8(data[IFLA_GRE_TTL]);
1301 if (data[IFLA_GRE_ENCAP_LIMIT])
1302 parms->encap_limit = nla_get_u8(data[IFLA_GRE_ENCAP_LIMIT]);
1304 if (data[IFLA_GRE_FLOWINFO])
1305 parms->flowinfo = nla_get_be32(data[IFLA_GRE_FLOWINFO]);
1307 if (data[IFLA_GRE_FLAGS])
1308 parms->flags = nla_get_u32(data[IFLA_GRE_FLAGS]);
1310 if (data[IFLA_GRE_FWMARK])
1311 parms->fwmark = nla_get_u32(data[IFLA_GRE_FWMARK]);
1314 static int ip6gre_tap_init(struct net_device *dev)
1318 ret = ip6gre_tunnel_init_common(dev);
1322 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
1327 static const struct net_device_ops ip6gre_tap_netdev_ops = {
1328 .ndo_init = ip6gre_tap_init,
1329 .ndo_uninit = ip6gre_tunnel_uninit,
1330 .ndo_start_xmit = ip6gre_tunnel_xmit,
1331 .ndo_set_mac_address = eth_mac_addr,
1332 .ndo_validate_addr = eth_validate_addr,
1333 .ndo_change_mtu = ip6_tnl_change_mtu,
1334 .ndo_get_stats64 = ip_tunnel_get_stats64,
1335 .ndo_get_iflink = ip6_tnl_get_iflink,
1338 static void ip6gre_tap_setup(struct net_device *dev)
1344 dev->netdev_ops = &ip6gre_tap_netdev_ops;
1345 dev->needs_free_netdev = true;
1346 dev->priv_destructor = ip6gre_dev_free;
1348 dev->features |= NETIF_F_NETNS_LOCAL;
1349 dev->priv_flags &= ~IFF_TX_SKB_SHARING;
1350 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
1351 netif_keep_dst(dev);
1354 static bool ip6gre_netlink_encap_parms(struct nlattr *data[],
1355 struct ip_tunnel_encap *ipencap)
1359 memset(ipencap, 0, sizeof(*ipencap));
1364 if (data[IFLA_GRE_ENCAP_TYPE]) {
1366 ipencap->type = nla_get_u16(data[IFLA_GRE_ENCAP_TYPE]);
1369 if (data[IFLA_GRE_ENCAP_FLAGS]) {
1371 ipencap->flags = nla_get_u16(data[IFLA_GRE_ENCAP_FLAGS]);
1374 if (data[IFLA_GRE_ENCAP_SPORT]) {
1376 ipencap->sport = nla_get_be16(data[IFLA_GRE_ENCAP_SPORT]);
1379 if (data[IFLA_GRE_ENCAP_DPORT]) {
1381 ipencap->dport = nla_get_be16(data[IFLA_GRE_ENCAP_DPORT]);
1387 static int ip6gre_newlink(struct net *src_net, struct net_device *dev,
1388 struct nlattr *tb[], struct nlattr *data[],
1389 struct netlink_ext_ack *extack)
1392 struct net *net = dev_net(dev);
1393 struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
1394 struct ip_tunnel_encap ipencap;
1397 nt = netdev_priv(dev);
1399 if (ip6gre_netlink_encap_parms(data, &ipencap)) {
1400 int err = ip6_tnl_encap_setup(nt, &ipencap);
1406 ip6gre_netlink_parms(data, &nt->parms);
1408 if (ip6gre_tunnel_find(net, &nt->parms, dev->type))
1411 if (dev->type == ARPHRD_ETHER && !tb[IFLA_ADDRESS])
1412 eth_hw_addr_random(dev);
1415 nt->net = dev_net(dev);
1417 err = register_netdevice(dev);
1421 ip6gre_tnl_link_config(nt, !tb[IFLA_MTU]);
1424 ip6_tnl_change_mtu(dev, nla_get_u32(tb[IFLA_MTU]));
1427 ip6gre_tunnel_link(ign, nt);
1433 static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[],
1434 struct nlattr *data[],
1435 struct netlink_ext_ack *extack)
1437 struct ip6_tnl *t, *nt = netdev_priv(dev);
1438 struct net *net = nt->net;
1439 struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
1440 struct __ip6_tnl_parm p;
1441 struct ip_tunnel_encap ipencap;
1443 if (dev == ign->fb_tunnel_dev)
1446 if (ip6gre_netlink_encap_parms(data, &ipencap)) {
1447 int err = ip6_tnl_encap_setup(nt, &ipencap);
1453 ip6gre_netlink_parms(data, &p);
1455 t = ip6gre_tunnel_locate(net, &p, 0);
1464 ip6gre_tunnel_unlink(ign, t);
1465 ip6gre_tnl_change(t, &p, !tb[IFLA_MTU]);
1466 ip6gre_tunnel_link(ign, t);
1470 static void ip6gre_dellink(struct net_device *dev, struct list_head *head)
1472 struct net *net = dev_net(dev);
1473 struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
1475 if (dev != ign->fb_tunnel_dev)
1476 unregister_netdevice_queue(dev, head);
1479 static size_t ip6gre_get_size(const struct net_device *dev)
1484 /* IFLA_GRE_IFLAGS */
1486 /* IFLA_GRE_OFLAGS */
1492 /* IFLA_GRE_LOCAL */
1493 nla_total_size(sizeof(struct in6_addr)) +
1494 /* IFLA_GRE_REMOTE */
1495 nla_total_size(sizeof(struct in6_addr)) +
1498 /* IFLA_GRE_ENCAP_LIMIT */
1500 /* IFLA_GRE_FLOWINFO */
1502 /* IFLA_GRE_FLAGS */
1504 /* IFLA_GRE_ENCAP_TYPE */
1506 /* IFLA_GRE_ENCAP_FLAGS */
1508 /* IFLA_GRE_ENCAP_SPORT */
1510 /* IFLA_GRE_ENCAP_DPORT */
1512 /* IFLA_GRE_FWMARK */
1517 static int ip6gre_fill_info(struct sk_buff *skb, const struct net_device *dev)
1519 struct ip6_tnl *t = netdev_priv(dev);
1520 struct __ip6_tnl_parm *p = &t->parms;
1522 if (nla_put_u32(skb, IFLA_GRE_LINK, p->link) ||
1523 nla_put_be16(skb, IFLA_GRE_IFLAGS,
1524 gre_tnl_flags_to_gre_flags(p->i_flags)) ||
1525 nla_put_be16(skb, IFLA_GRE_OFLAGS,
1526 gre_tnl_flags_to_gre_flags(p->o_flags)) ||
1527 nla_put_be32(skb, IFLA_GRE_IKEY, p->i_key) ||
1528 nla_put_be32(skb, IFLA_GRE_OKEY, p->o_key) ||
1529 nla_put_in6_addr(skb, IFLA_GRE_LOCAL, &p->laddr) ||
1530 nla_put_in6_addr(skb, IFLA_GRE_REMOTE, &p->raddr) ||
1531 nla_put_u8(skb, IFLA_GRE_TTL, p->hop_limit) ||
1532 nla_put_u8(skb, IFLA_GRE_ENCAP_LIMIT, p->encap_limit) ||
1533 nla_put_be32(skb, IFLA_GRE_FLOWINFO, p->flowinfo) ||
1534 nla_put_u32(skb, IFLA_GRE_FLAGS, p->flags) ||
1535 nla_put_u32(skb, IFLA_GRE_FWMARK, p->fwmark))
1536 goto nla_put_failure;
1538 if (nla_put_u16(skb, IFLA_GRE_ENCAP_TYPE,
1540 nla_put_be16(skb, IFLA_GRE_ENCAP_SPORT,
1542 nla_put_be16(skb, IFLA_GRE_ENCAP_DPORT,
1544 nla_put_u16(skb, IFLA_GRE_ENCAP_FLAGS,
1546 goto nla_put_failure;
1554 static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
1555 [IFLA_GRE_LINK] = { .type = NLA_U32 },
1556 [IFLA_GRE_IFLAGS] = { .type = NLA_U16 },
1557 [IFLA_GRE_OFLAGS] = { .type = NLA_U16 },
1558 [IFLA_GRE_IKEY] = { .type = NLA_U32 },
1559 [IFLA_GRE_OKEY] = { .type = NLA_U32 },
1560 [IFLA_GRE_LOCAL] = { .len = FIELD_SIZEOF(struct ipv6hdr, saddr) },
1561 [IFLA_GRE_REMOTE] = { .len = FIELD_SIZEOF(struct ipv6hdr, daddr) },
1562 [IFLA_GRE_TTL] = { .type = NLA_U8 },
1563 [IFLA_GRE_ENCAP_LIMIT] = { .type = NLA_U8 },
1564 [IFLA_GRE_FLOWINFO] = { .type = NLA_U32 },
1565 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
1566 [IFLA_GRE_ENCAP_TYPE] = { .type = NLA_U16 },
1567 [IFLA_GRE_ENCAP_FLAGS] = { .type = NLA_U16 },
1568 [IFLA_GRE_ENCAP_SPORT] = { .type = NLA_U16 },
1569 [IFLA_GRE_ENCAP_DPORT] = { .type = NLA_U16 },
1570 [IFLA_GRE_FWMARK] = { .type = NLA_U32 },
1573 static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
1575 .maxtype = IFLA_GRE_MAX,
1576 .policy = ip6gre_policy,
1577 .priv_size = sizeof(struct ip6_tnl),
1578 .setup = ip6gre_tunnel_setup,
1579 .validate = ip6gre_tunnel_validate,
1580 .newlink = ip6gre_newlink,
1581 .changelink = ip6gre_changelink,
1582 .dellink = ip6gre_dellink,
1583 .get_size = ip6gre_get_size,
1584 .fill_info = ip6gre_fill_info,
1585 .get_link_net = ip6_tnl_get_link_net,
1588 static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
1589 .kind = "ip6gretap",
1590 .maxtype = IFLA_GRE_MAX,
1591 .policy = ip6gre_policy,
1592 .priv_size = sizeof(struct ip6_tnl),
1593 .setup = ip6gre_tap_setup,
1594 .validate = ip6gre_tap_validate,
1595 .newlink = ip6gre_newlink,
1596 .changelink = ip6gre_changelink,
1597 .get_size = ip6gre_get_size,
1598 .fill_info = ip6gre_fill_info,
1599 .get_link_net = ip6_tnl_get_link_net,
1603 * And now the modules code and kernel interface.
1606 static int __init ip6gre_init(void)
1610 pr_info("GRE over IPv6 tunneling driver\n");
1612 err = register_pernet_device(&ip6gre_net_ops);
1616 err = inet6_add_protocol(&ip6gre_protocol, IPPROTO_GRE);
1618 pr_info("%s: can't add protocol\n", __func__);
1619 goto add_proto_failed;
1622 err = rtnl_link_register(&ip6gre_link_ops);
1624 goto rtnl_link_failed;
1626 err = rtnl_link_register(&ip6gre_tap_ops);
1628 goto tap_ops_failed;
1634 rtnl_link_unregister(&ip6gre_link_ops);
1636 inet6_del_protocol(&ip6gre_protocol, IPPROTO_GRE);
1638 unregister_pernet_device(&ip6gre_net_ops);
1642 static void __exit ip6gre_fini(void)
1644 rtnl_link_unregister(&ip6gre_tap_ops);
1645 rtnl_link_unregister(&ip6gre_link_ops);
1646 inet6_del_protocol(&ip6gre_protocol, IPPROTO_GRE);
1647 unregister_pernet_device(&ip6gre_net_ops);
1650 module_init(ip6gre_init);
1651 module_exit(ip6gre_fini);
1652 MODULE_LICENSE("GPL");
1653 MODULE_AUTHOR("D. Kozlov (xeb@mail.ru)");
1654 MODULE_DESCRIPTION("GRE over IPv6 tunneling device");
1655 MODULE_ALIAS_RTNL_LINK("ip6gre");
1656 MODULE_ALIAS_RTNL_LINK("ip6gretap");
1657 MODULE_ALIAS_NETDEV("ip6gre0");