2 * IPv6 over IPv4 tunnel device - Simple Internet Transition (SIT)
3 * Linux INET6 implementation
6 * Pedro Roque <roque@di.fc.ul.pt>
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
9 * $Id: sit.c,v 1.53 2001/09/25 05:09:53 davem Exp $
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
17 * Roger Venning <r.venning@telstra.com>: 6to4 support
18 * Nate Thompson <nate@thebog.net>: 6to4 support
19 * Fred Templin <fred.l.templin@boeing.com>: isatap support
22 #include <linux/module.h>
23 #include <linux/capability.h>
24 #include <linux/errno.h>
25 #include <linux/types.h>
26 #include <linux/socket.h>
27 #include <linux/sockios.h>
28 #include <linux/net.h>
29 #include <linux/in6.h>
30 #include <linux/netdevice.h>
31 #include <linux/if_arp.h>
32 #include <linux/icmp.h>
33 #include <asm/uaccess.h>
34 #include <linux/init.h>
35 #include <linux/netfilter_ipv4.h>
36 #include <linux/if_ether.h>
42 #include <net/protocol.h>
43 #include <net/transp_v6.h>
44 #include <net/ip6_fib.h>
45 #include <net/ip6_route.h>
46 #include <net/ndisc.h>
47 #include <net/addrconf.h>
52 #include <net/inet_ecn.h>
54 #include <net/dsfield.h>
57 This version of net/ipv6/sit.c is cloned of net/ipv4/ip_gre.c
59 For comments look at net/ipv4/ip_gre.c --ANK
63 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF)
65 static int ipip6_fb_tunnel_init(struct net_device
*dev
);
66 static int ipip6_tunnel_init(struct net_device
*dev
);
67 static void ipip6_tunnel_setup(struct net_device
*dev
);
69 static struct net_device
*ipip6_fb_tunnel_dev
;
71 static struct ip_tunnel
*tunnels_r_l
[HASH_SIZE
];
72 static struct ip_tunnel
*tunnels_r
[HASH_SIZE
];
73 static struct ip_tunnel
*tunnels_l
[HASH_SIZE
];
74 static struct ip_tunnel
*tunnels_wc
[1];
75 static struct ip_tunnel
**tunnels
[4] = { tunnels_wc
, tunnels_l
, tunnels_r
, tunnels_r_l
};
77 static DEFINE_RWLOCK(ipip6_lock
);
79 static struct ip_tunnel
* ipip6_tunnel_lookup(__be32 remote
, __be32 local
)
81 unsigned h0
= HASH(remote
);
82 unsigned h1
= HASH(local
);
85 for (t
= tunnels_r_l
[h0
^h1
]; t
; t
= t
->next
) {
86 if (local
== t
->parms
.iph
.saddr
&&
87 remote
== t
->parms
.iph
.daddr
&& (t
->dev
->flags
&IFF_UP
))
90 for (t
= tunnels_r
[h0
]; t
; t
= t
->next
) {
91 if (remote
== t
->parms
.iph
.daddr
&& (t
->dev
->flags
&IFF_UP
))
94 for (t
= tunnels_l
[h1
]; t
; t
= t
->next
) {
95 if (local
== t
->parms
.iph
.saddr
&& (t
->dev
->flags
&IFF_UP
))
98 if ((t
= tunnels_wc
[0]) != NULL
&& (t
->dev
->flags
&IFF_UP
))
103 static struct ip_tunnel
**__ipip6_bucket(struct ip_tunnel_parm
*parms
)
105 __be32 remote
= parms
->iph
.daddr
;
106 __be32 local
= parms
->iph
.saddr
;
118 return &tunnels
[prio
][h
];
121 static inline struct ip_tunnel
**ipip6_bucket(struct ip_tunnel
*t
)
123 return __ipip6_bucket(&t
->parms
);
126 static void ipip6_tunnel_unlink(struct ip_tunnel
*t
)
128 struct ip_tunnel
**tp
;
130 for (tp
= ipip6_bucket(t
); *tp
; tp
= &(*tp
)->next
) {
132 write_lock_bh(&ipip6_lock
);
134 write_unlock_bh(&ipip6_lock
);
140 static void ipip6_tunnel_link(struct ip_tunnel
*t
)
142 struct ip_tunnel
**tp
= ipip6_bucket(t
);
145 write_lock_bh(&ipip6_lock
);
147 write_unlock_bh(&ipip6_lock
);
150 static struct ip_tunnel
* ipip6_tunnel_locate(struct ip_tunnel_parm
*parms
, int create
)
152 __be32 remote
= parms
->iph
.daddr
;
153 __be32 local
= parms
->iph
.saddr
;
154 struct ip_tunnel
*t
, **tp
, *nt
;
155 struct net_device
*dev
;
158 for (tp
= __ipip6_bucket(parms
); (t
= *tp
) != NULL
; tp
= &t
->next
) {
159 if (local
== t
->parms
.iph
.saddr
&& remote
== t
->parms
.iph
.daddr
)
166 strlcpy(name
, parms
->name
, IFNAMSIZ
);
168 sprintf(name
, "sit%%d");
170 dev
= alloc_netdev(sizeof(*t
), name
, ipip6_tunnel_setup
);
174 if (strchr(name
, '%')) {
175 if (dev_alloc_name(dev
, name
) < 0)
179 nt
= netdev_priv(dev
);
180 dev
->init
= ipip6_tunnel_init
;
183 if (parms
->i_flags
& SIT_ISATAP
)
184 dev
->priv_flags
|= IFF_ISATAP
;
186 if (register_netdevice(dev
) < 0)
191 ipip6_tunnel_link(nt
);
200 static struct ip_tunnel_prl_entry
*
201 __ipip6_tunnel_locate_prl(struct ip_tunnel
*t
, __be32 addr
)
203 struct ip_tunnel_prl_entry
*p
= (struct ip_tunnel_prl_entry
*)NULL
;
205 for (p
= t
->prl
; p
; p
= p
->next
)
206 if (p
->entry
.addr
== addr
)
213 ipip6_tunnel_add_prl(struct ip_tunnel
*t
, struct ip_tunnel_prl
*a
, int chg
)
215 struct ip_tunnel_prl_entry
*p
;
218 write_lock(&ipip6_lock
);
220 for (p
= t
->prl
; p
; p
= p
->next
) {
221 if (p
->entry
.addr
== a
->addr
) {
234 p
= kzalloc(sizeof(struct ip_tunnel_prl_entry
), GFP_KERNEL
);
245 write_unlock(&ipip6_lock
);
250 ipip6_tunnel_del_prl(struct ip_tunnel
*t
, struct ip_tunnel_prl
*a
)
252 struct ip_tunnel_prl_entry
*x
, **p
;
255 write_lock(&ipip6_lock
);
258 for (p
= &t
->prl
; *p
; p
= &(*p
)->next
) {
259 if ((*p
)->entry
.addr
== a
->addr
) {
270 t
->prl
= t
->prl
->next
;
275 write_unlock(&ipip6_lock
);
279 /* copied directly from anycast.c */
281 ipip6_onlink(struct in6_addr
*addr
, struct net_device
*dev
)
283 struct inet6_dev
*idev
;
284 struct inet6_ifaddr
*ifa
;
289 idev
= __in6_dev_get(dev
);
291 read_lock_bh(&idev
->lock
);
292 for (ifa
=idev
->addr_list
; ifa
; ifa
=ifa
->if_next
) {
293 onlink
= ipv6_prefix_equal(addr
, &ifa
->addr
,
298 read_unlock_bh(&idev
->lock
);
305 isatap_chksrc(struct sk_buff
*skb
, struct iphdr
*iph
, struct ip_tunnel
*t
)
307 struct ip_tunnel_prl_entry
*p
;
310 read_lock(&ipip6_lock
);
311 p
= __ipip6_tunnel_locate_prl(t
, iph
->saddr
);
313 if (p
->entry
.flags
& PRL_DEFAULT
)
314 skb
->ndisc_nodetype
= NDISC_NODETYPE_DEFAULT
;
316 skb
->ndisc_nodetype
= NDISC_NODETYPE_NODEFAULT
;
318 struct in6_addr
*addr6
= &ipv6_hdr(skb
)->saddr
;
319 if (ipv6_addr_is_isatap(addr6
) &&
320 (addr6
->s6_addr32
[3] == iph
->saddr
) &&
321 ipip6_onlink(addr6
, t
->dev
))
322 skb
->ndisc_nodetype
= NDISC_NODETYPE_HOST
;
326 read_unlock(&ipip6_lock
);
330 static void ipip6_tunnel_uninit(struct net_device
*dev
)
332 if (dev
== ipip6_fb_tunnel_dev
) {
333 write_lock_bh(&ipip6_lock
);
334 tunnels_wc
[0] = NULL
;
335 write_unlock_bh(&ipip6_lock
);
338 ipip6_tunnel_unlink(netdev_priv(dev
));
339 ipip6_tunnel_del_prl(netdev_priv(dev
), 0);
345 static int ipip6_err(struct sk_buff
*skb
, u32 info
)
347 #ifndef I_WISH_WORLD_WERE_PERFECT
349 /* It is not :-( All the routers (except for Linux) return only
350 8 bytes of packet payload. It means, that precise relaying of
351 ICMP in the real Internet is absolutely infeasible.
353 struct iphdr
*iph
= (struct iphdr
*)skb
->data
;
354 const int type
= icmp_hdr(skb
)->type
;
355 const int code
= icmp_hdr(skb
)->code
;
361 case ICMP_PARAMETERPROB
:
364 case ICMP_DEST_UNREACH
:
367 case ICMP_PORT_UNREACH
:
368 /* Impossible event. */
370 case ICMP_FRAG_NEEDED
:
371 /* Soft state for pmtu is maintained by IP core. */
374 /* All others are translated to HOST_UNREACH.
375 rfc2003 contains "deep thoughts" about NET_UNREACH,
376 I believe they are just ether pollution. --ANK
381 case ICMP_TIME_EXCEEDED
:
382 if (code
!= ICMP_EXC_TTL
)
389 read_lock(&ipip6_lock
);
390 t
= ipip6_tunnel_lookup(iph
->daddr
, iph
->saddr
);
391 if (t
== NULL
|| t
->parms
.iph
.daddr
== 0)
395 if (t
->parms
.iph
.ttl
== 0 && type
== ICMP_TIME_EXCEEDED
)
398 if (jiffies
- t
->err_time
< IPTUNNEL_ERR_TIMEO
)
402 t
->err_time
= jiffies
;
404 read_unlock(&ipip6_lock
);
407 struct iphdr
*iph
= (struct iphdr
*)dp
;
408 int hlen
= iph
->ihl
<<2;
409 struct ipv6hdr
*iph6
;
410 const int type
= icmp_hdr(skb
)->type
;
411 const int code
= icmp_hdr(skb
)->code
;
415 struct sk_buff
*skb2
;
416 struct rt6_info
*rt6i
;
418 if (len
< hlen
+ sizeof(struct ipv6hdr
))
420 iph6
= (struct ipv6hdr
*)(dp
+ hlen
);
425 case ICMP_PARAMETERPROB
:
426 if (icmp_hdr(skb
)->un
.gateway
< hlen
)
429 /* So... This guy found something strange INSIDE encapsulated
430 packet. Well, he is fool, but what can we do ?
432 rel_type
= ICMPV6_PARAMPROB
;
433 rel_info
= icmp_hdr(skb
)->un
.gateway
- hlen
;
436 case ICMP_DEST_UNREACH
:
439 case ICMP_PORT_UNREACH
:
440 /* Impossible event. */
442 case ICMP_FRAG_NEEDED
:
443 /* Too complicated case ... */
446 /* All others are translated to HOST_UNREACH.
447 rfc2003 contains "deep thoughts" about NET_UNREACH,
448 I believe, it is just ether pollution. --ANK
450 rel_type
= ICMPV6_DEST_UNREACH
;
451 rel_code
= ICMPV6_ADDR_UNREACH
;
455 case ICMP_TIME_EXCEEDED
:
456 if (code
!= ICMP_EXC_TTL
)
458 rel_type
= ICMPV6_TIME_EXCEED
;
459 rel_code
= ICMPV6_EXC_HOPLIMIT
;
463 /* Prepare fake skb to feed it to icmpv6_send */
464 skb2
= skb_clone(skb
, GFP_ATOMIC
);
467 dst_release(skb2
->dst
);
469 skb_pull(skb2
, skb
->data
- (u8
*)iph6
);
470 skb_reset_network_header(skb2
);
472 /* Try to guess incoming interface */
473 rt6i
= rt6_lookup(&init_net
, &iph6
->saddr
, NULL
, NULL
, 0);
474 if (rt6i
&& rt6i
->rt6i_dev
) {
475 skb2
->dev
= rt6i
->rt6i_dev
;
477 rt6i
= rt6_lookup(&init_net
, &iph6
->daddr
, &iph6
->saddr
, NULL
, 0);
479 if (rt6i
&& rt6i
->rt6i_dev
&& rt6i
->rt6i_dev
->type
== ARPHRD_SIT
) {
480 struct ip_tunnel
*t
= netdev_priv(rt6i
->rt6i_dev
);
481 if (rel_type
== ICMPV6_TIME_EXCEED
&& t
->parms
.iph
.ttl
) {
482 rel_type
= ICMPV6_DEST_UNREACH
;
483 rel_code
= ICMPV6_ADDR_UNREACH
;
485 icmpv6_send(skb2
, rel_type
, rel_code
, rel_info
, skb2
->dev
);
493 static inline void ipip6_ecn_decapsulate(struct iphdr
*iph
, struct sk_buff
*skb
)
495 if (INET_ECN_is_ce(iph
->tos
))
496 IP6_ECN_set_ce(ipv6_hdr(skb
));
499 static int ipip6_rcv(struct sk_buff
*skb
)
502 struct ip_tunnel
*tunnel
;
504 if (!pskb_may_pull(skb
, sizeof(struct ipv6hdr
)))
509 read_lock(&ipip6_lock
);
510 if ((tunnel
= ipip6_tunnel_lookup(iph
->saddr
, iph
->daddr
)) != NULL
) {
512 skb
->mac_header
= skb
->network_header
;
513 skb_reset_network_header(skb
);
514 IPCB(skb
)->flags
= 0;
515 skb
->protocol
= htons(ETH_P_IPV6
);
516 skb
->pkt_type
= PACKET_HOST
;
518 if ((tunnel
->dev
->priv_flags
& IFF_ISATAP
) &&
519 !isatap_chksrc(skb
, iph
, tunnel
)) {
520 tunnel
->stat
.rx_errors
++;
521 read_unlock(&ipip6_lock
);
525 tunnel
->stat
.rx_packets
++;
526 tunnel
->stat
.rx_bytes
+= skb
->len
;
527 skb
->dev
= tunnel
->dev
;
528 dst_release(skb
->dst
);
531 ipip6_ecn_decapsulate(iph
, skb
);
533 read_unlock(&ipip6_lock
);
537 icmp_send(skb
, ICMP_DEST_UNREACH
, ICMP_PORT_UNREACH
, 0);
539 read_unlock(&ipip6_lock
);
544 /* Returns the embedded IPv4 address if the IPv6 address
545 comes from 6to4 (RFC 3056) addr space */
547 static inline __be32
try_6to4(struct in6_addr
*v6dst
)
551 if (v6dst
->s6_addr16
[0] == htons(0x2002)) {
552 /* 6to4 v6 addr has 16 bits prefix, 32 v4addr, 16 SLA, ... */
553 memcpy(&dst
, &v6dst
->s6_addr16
[1], 4);
559 * This function assumes it is being called from dev_queue_xmit()
560 * and that skb is filled properly by that function.
563 static int ipip6_tunnel_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
565 struct ip_tunnel
*tunnel
= netdev_priv(dev
);
566 struct net_device_stats
*stats
= &tunnel
->stat
;
567 struct iphdr
*tiph
= &tunnel
->parms
.iph
;
568 struct ipv6hdr
*iph6
= ipv6_hdr(skb
);
569 u8 tos
= tunnel
->parms
.iph
.tos
;
570 struct rtable
*rt
; /* Route to the other host */
571 struct net_device
*tdev
; /* Device to other host */
572 struct iphdr
*iph
; /* Our new IP header */
573 unsigned int max_headroom
; /* The extra header space needed */
574 __be32 dst
= tiph
->daddr
;
576 struct in6_addr
*addr6
;
579 if (tunnel
->recursion
++) {
580 tunnel
->stat
.collisions
++;
584 if (skb
->protocol
!= htons(ETH_P_IPV6
))
587 /* ISATAP (RFC4214) - must come before 6to4 */
588 if (dev
->priv_flags
& IFF_ISATAP
) {
589 struct neighbour
*neigh
= NULL
;
592 neigh
= skb
->dst
->neighbour
;
596 printk(KERN_DEBUG
"sit: nexthop == NULL\n");
600 addr6
= (struct in6_addr
*)&neigh
->primary_key
;
601 addr_type
= ipv6_addr_type(addr6
);
603 if ((addr_type
& IPV6_ADDR_UNICAST
) &&
604 ipv6_addr_is_isatap(addr6
))
605 dst
= addr6
->s6_addr32
[3];
611 dst
= try_6to4(&iph6
->daddr
);
614 struct neighbour
*neigh
= NULL
;
617 neigh
= skb
->dst
->neighbour
;
621 printk(KERN_DEBUG
"sit: nexthop == NULL\n");
625 addr6
= (struct in6_addr
*)&neigh
->primary_key
;
626 addr_type
= ipv6_addr_type(addr6
);
628 if (addr_type
== IPV6_ADDR_ANY
) {
629 addr6
= &ipv6_hdr(skb
)->daddr
;
630 addr_type
= ipv6_addr_type(addr6
);
633 if ((addr_type
& IPV6_ADDR_COMPATv4
) == 0)
636 dst
= addr6
->s6_addr32
[3];
640 struct flowi fl
= { .nl_u
= { .ip4_u
=
642 .saddr
= tiph
->saddr
,
643 .tos
= RT_TOS(tos
) } },
644 .oif
= tunnel
->parms
.link
,
645 .proto
= IPPROTO_IPV6
};
646 if (ip_route_output_key(&init_net
, &rt
, &fl
)) {
647 tunnel
->stat
.tx_carrier_errors
++;
651 if (rt
->rt_type
!= RTN_UNICAST
) {
653 tunnel
->stat
.tx_carrier_errors
++;
656 tdev
= rt
->u
.dst
.dev
;
660 tunnel
->stat
.collisions
++;
665 mtu
= dst_mtu(&rt
->u
.dst
) - sizeof(struct iphdr
);
667 mtu
= skb
->dst
? dst_mtu(skb
->dst
) : dev
->mtu
;
670 tunnel
->stat
.collisions
++;
674 if (mtu
< IPV6_MIN_MTU
)
676 if (tunnel
->parms
.iph
.daddr
&& skb
->dst
)
677 skb
->dst
->ops
->update_pmtu(skb
->dst
, mtu
);
679 if (skb
->len
> mtu
) {
680 icmpv6_send(skb
, ICMPV6_PKT_TOOBIG
, 0, mtu
, dev
);
685 if (tunnel
->err_count
> 0) {
686 if (jiffies
- tunnel
->err_time
< IPTUNNEL_ERR_TIMEO
) {
688 dst_link_failure(skb
);
690 tunnel
->err_count
= 0;
694 * Okay, now see if we can stuff it in the buffer as-is.
696 max_headroom
= LL_RESERVED_SPACE(tdev
)+sizeof(struct iphdr
);
698 if (skb_headroom(skb
) < max_headroom
|| skb_shared(skb
) ||
699 (skb_cloned(skb
) && !skb_clone_writable(skb
, 0))) {
700 struct sk_buff
*new_skb
= skb_realloc_headroom(skb
, max_headroom
);
709 skb_set_owner_w(new_skb
, skb
->sk
);
712 iph6
= ipv6_hdr(skb
);
715 skb
->transport_header
= skb
->network_header
;
716 skb_push(skb
, sizeof(struct iphdr
));
717 skb_reset_network_header(skb
);
718 memset(&(IPCB(skb
)->opt
), 0, sizeof(IPCB(skb
)->opt
));
719 IPCB(skb
)->flags
= 0;
720 dst_release(skb
->dst
);
721 skb
->dst
= &rt
->u
.dst
;
724 * Push down and install the IPIP header.
729 iph
->ihl
= sizeof(struct iphdr
)>>2;
730 if (mtu
> IPV6_MIN_MTU
)
731 iph
->frag_off
= htons(IP_DF
);
735 iph
->protocol
= IPPROTO_IPV6
;
736 iph
->tos
= INET_ECN_encapsulate(tos
, ipv6_get_dsfield(iph6
));
737 iph
->daddr
= rt
->rt_dst
;
738 iph
->saddr
= rt
->rt_src
;
740 if ((iph
->ttl
= tiph
->ttl
) == 0)
741 iph
->ttl
= iph6
->hop_limit
;
750 dst_link_failure(skb
);
758 static void ipip6_tunnel_bind_dev(struct net_device
*dev
)
760 struct net_device
*tdev
= NULL
;
761 struct ip_tunnel
*tunnel
;
764 tunnel
= netdev_priv(dev
);
765 iph
= &tunnel
->parms
.iph
;
768 struct flowi fl
= { .nl_u
= { .ip4_u
=
769 { .daddr
= iph
->daddr
,
771 .tos
= RT_TOS(iph
->tos
) } },
772 .oif
= tunnel
->parms
.link
,
773 .proto
= IPPROTO_IPV6
};
775 if (!ip_route_output_key(&init_net
, &rt
, &fl
)) {
776 tdev
= rt
->u
.dst
.dev
;
779 dev
->flags
|= IFF_POINTOPOINT
;
782 if (!tdev
&& tunnel
->parms
.link
)
783 tdev
= __dev_get_by_index(&init_net
, tunnel
->parms
.link
);
786 dev
->hard_header_len
= tdev
->hard_header_len
+ sizeof(struct iphdr
);
787 dev
->mtu
= tdev
->mtu
- sizeof(struct iphdr
);
788 if (dev
->mtu
< IPV6_MIN_MTU
)
789 dev
->mtu
= IPV6_MIN_MTU
;
791 dev
->iflink
= tunnel
->parms
.link
;
795 ipip6_tunnel_ioctl (struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
798 struct ip_tunnel_parm p
;
799 struct ip_tunnel_prl prl
;
805 if (dev
== ipip6_fb_tunnel_dev
) {
806 if (copy_from_user(&p
, ifr
->ifr_ifru
.ifru_data
, sizeof(p
))) {
810 t
= ipip6_tunnel_locate(&p
, 0);
813 t
= netdev_priv(dev
);
814 memcpy(&p
, &t
->parms
, sizeof(p
));
815 if (copy_to_user(ifr
->ifr_ifru
.ifru_data
, &p
, sizeof(p
)))
822 if (!capable(CAP_NET_ADMIN
))
826 if (copy_from_user(&p
, ifr
->ifr_ifru
.ifru_data
, sizeof(p
)))
830 if (p
.iph
.version
!= 4 || p
.iph
.protocol
!= IPPROTO_IPV6
||
831 p
.iph
.ihl
!= 5 || (p
.iph
.frag_off
&htons(~IP_DF
)))
834 p
.iph
.frag_off
|= htons(IP_DF
);
836 t
= ipip6_tunnel_locate(&p
, cmd
== SIOCADDTUNNEL
);
838 if (dev
!= ipip6_fb_tunnel_dev
&& cmd
== SIOCCHGTUNNEL
) {
845 if (((dev
->flags
&IFF_POINTOPOINT
) && !p
.iph
.daddr
) ||
846 (!(dev
->flags
&IFF_POINTOPOINT
) && p
.iph
.daddr
)) {
850 t
= netdev_priv(dev
);
851 ipip6_tunnel_unlink(t
);
852 t
->parms
.iph
.saddr
= p
.iph
.saddr
;
853 t
->parms
.iph
.daddr
= p
.iph
.daddr
;
854 memcpy(dev
->dev_addr
, &p
.iph
.saddr
, 4);
855 memcpy(dev
->broadcast
, &p
.iph
.daddr
, 4);
856 ipip6_tunnel_link(t
);
857 netdev_state_change(dev
);
863 if (cmd
== SIOCCHGTUNNEL
) {
864 t
->parms
.iph
.ttl
= p
.iph
.ttl
;
865 t
->parms
.iph
.tos
= p
.iph
.tos
;
866 if (t
->parms
.link
!= p
.link
) {
867 t
->parms
.link
= p
.link
;
868 ipip6_tunnel_bind_dev(dev
);
869 netdev_state_change(dev
);
872 if (copy_to_user(ifr
->ifr_ifru
.ifru_data
, &t
->parms
, sizeof(p
)))
875 err
= (cmd
== SIOCADDTUNNEL
? -ENOBUFS
: -ENOENT
);
880 if (!capable(CAP_NET_ADMIN
))
883 if (dev
== ipip6_fb_tunnel_dev
) {
885 if (copy_from_user(&p
, ifr
->ifr_ifru
.ifru_data
, sizeof(p
)))
888 if ((t
= ipip6_tunnel_locate(&p
, 0)) == NULL
)
891 if (t
== netdev_priv(ipip6_fb_tunnel_dev
))
895 unregister_netdevice(dev
);
903 if (!capable(CAP_NET_ADMIN
))
906 if (dev
== ipip6_fb_tunnel_dev
)
909 if (copy_from_user(&prl
, ifr
->ifr_ifru
.ifru_data
, sizeof(prl
)))
912 if (!(t
= netdev_priv(dev
)))
915 if (cmd
== SIOCDELPRL
)
916 err
= ipip6_tunnel_del_prl(t
, &prl
);
918 err
= ipip6_tunnel_add_prl(t
, &prl
, cmd
== SIOCCHGPRL
);
919 netdev_state_change(dev
);
930 static struct net_device_stats
*ipip6_tunnel_get_stats(struct net_device
*dev
)
932 return &(((struct ip_tunnel
*)netdev_priv(dev
))->stat
);
935 static int ipip6_tunnel_change_mtu(struct net_device
*dev
, int new_mtu
)
937 if (new_mtu
< IPV6_MIN_MTU
|| new_mtu
> 0xFFF8 - sizeof(struct iphdr
))
943 static void ipip6_tunnel_setup(struct net_device
*dev
)
945 dev
->uninit
= ipip6_tunnel_uninit
;
946 dev
->destructor
= free_netdev
;
947 dev
->hard_start_xmit
= ipip6_tunnel_xmit
;
948 dev
->get_stats
= ipip6_tunnel_get_stats
;
949 dev
->do_ioctl
= ipip6_tunnel_ioctl
;
950 dev
->change_mtu
= ipip6_tunnel_change_mtu
;
952 dev
->type
= ARPHRD_SIT
;
953 dev
->hard_header_len
= LL_MAX_HEADER
+ sizeof(struct iphdr
);
954 dev
->mtu
= ETH_DATA_LEN
- sizeof(struct iphdr
);
955 dev
->flags
= IFF_NOARP
;
960 static int ipip6_tunnel_init(struct net_device
*dev
)
962 struct ip_tunnel
*tunnel
;
964 tunnel
= netdev_priv(dev
);
967 strcpy(tunnel
->parms
.name
, dev
->name
);
969 memcpy(dev
->dev_addr
, &tunnel
->parms
.iph
.saddr
, 4);
970 memcpy(dev
->broadcast
, &tunnel
->parms
.iph
.daddr
, 4);
972 ipip6_tunnel_bind_dev(dev
);
977 static int __init
ipip6_fb_tunnel_init(struct net_device
*dev
)
979 struct ip_tunnel
*tunnel
= netdev_priv(dev
);
980 struct iphdr
*iph
= &tunnel
->parms
.iph
;
983 strcpy(tunnel
->parms
.name
, dev
->name
);
986 iph
->protocol
= IPPROTO_IPV6
;
991 tunnels_wc
[0] = tunnel
;
995 static struct xfrm_tunnel sit_handler
= {
996 .handler
= ipip6_rcv
,
997 .err_handler
= ipip6_err
,
1001 static void __exit
sit_destroy_tunnels(void)
1005 for (prio
= 1; prio
< 4; prio
++) {
1007 for (h
= 0; h
< HASH_SIZE
; h
++) {
1008 struct ip_tunnel
*t
;
1009 while ((t
= tunnels
[prio
][h
]) != NULL
)
1010 unregister_netdevice(t
->dev
);
1015 static void __exit
sit_cleanup(void)
1017 xfrm4_tunnel_deregister(&sit_handler
, AF_INET6
);
1020 sit_destroy_tunnels();
1021 unregister_netdevice(ipip6_fb_tunnel_dev
);
1025 static int __init
sit_init(void)
1029 printk(KERN_INFO
"IPv6 over IPv4 tunneling driver\n");
1031 if (xfrm4_tunnel_register(&sit_handler
, AF_INET6
) < 0) {
1032 printk(KERN_INFO
"sit init: Can't add protocol\n");
1036 ipip6_fb_tunnel_dev
= alloc_netdev(sizeof(struct ip_tunnel
), "sit0",
1037 ipip6_tunnel_setup
);
1038 if (!ipip6_fb_tunnel_dev
) {
1043 ipip6_fb_tunnel_dev
->init
= ipip6_fb_tunnel_init
;
1045 if ((err
= register_netdev(ipip6_fb_tunnel_dev
)))
1051 free_netdev(ipip6_fb_tunnel_dev
);
1053 xfrm4_tunnel_deregister(&sit_handler
, AF_INET6
);
1057 module_init(sit_init
);
1058 module_exit(sit_cleanup
);
1059 MODULE_LICENSE("GPL");
1060 MODULE_ALIAS("sit0");