Subject: kern/32944: Tun doesn't support ipv6 in 'normal' mode
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <degroote@enseirb.fr>
List: netbsd-bugs
Date: 02/27/2006 18:50:00
>Number:         32944
>Category:       kern
>Synopsis:       Tun doesn't support ipv6 in 'normal' mode
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 27 18:50:00 +0000 2006
>Originator:     Arnaud Degroote
>Release:        current
>Organization:
>Environment:
NetBSD Hermes.at.home 3.99.15 NetBSD 3.99.15 (HERMES) #0: Sun Feb 26 15:55:21 CET 2006  zul@Hermes.at.home:/usr/build_tmp/objdir/sys/arch/i386/compile/HERMES i386
>Description:
NetBSD had some basic support for ipv6 in tunnel mode. This patch adds the support for ipv6 in  normal mode. It prepends the af_family at the begin of the packet ( as other bsd does ).  I have posted the patch a few day ago and rpaulo@ asks me to test the patch with teredo. I don't have any success with teredo but I suspect my isp to block teredo ( miredo doesn't work either with linux so I suspect my isp, not the code ).

I can provide patches for miredo if someone want to test it.
>How-To-Repeat:

>Fix:
See the patch

Index: if_tun.c
===================================================================
RCS file: /pub/NetBSD-CVS/src/sys/net/if_tun.c,v
retrieving revision 1.79
diff -r1.79 if_tun.c
54a55
> 
348,349c349,351
< #ifdef INET
<                               if (ifa->ifa_addr->sa_family == AF_INET) {
---
> #if defined(INET) || defined(INET6)
>                               if (ifa->ifa_addr->sa_family == AF_INET ||
>                                   ifa->ifa_addr->sa_family == AF_INET6) {
398a401,418
> #ifdef INET6
>         if (ifa->ifa_addr->sa_family == AF_INET6) {
>             struct sockaddr_in6 *sin;
> 
>             sin = (struct sockaddr_in6 *)ifa->ifa_addr;
>             if (!IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr))
>                 tp->tun_flags |= TUN_IASET;
> 
>             if (ifp->if_flags & IFF_POINTOPOINT) {
>                 sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr;
>                 if (sin &&
>                     !IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr))
>                     tp->tun_flags |= TUN_DSTADDR;
>             } else
>                 tp->tun_flags &= ~TUN_DSTADDR;
>         }
> #endif /* INET6 */
> 
449a470,473
> #ifdef INET6
>         case AF_INET6:
>             break;
> #endif
477c501
< #ifdef INET
---
> #if defined(INET) || defined(INET6)
478a503
>     uint32_t * af;
522c547,558
<               }
---
>               } else {
>        /* Prepend the adress family */
>             M_PREPEND(m0,sizeof(*af),M_DONTWAIT);
>             if (m0 == NULL) {
>                 IF_DROP(&ifp->if_snd);
>                 error = ENOBUFS;
>                 goto out;
>             }
>             af = mtod(m0,uint32_t *);
>             *af = htonl(dst->sa_family);
>        }
> 
755a792
>     uint32_t family;
790,792c827,832
< #ifdef INET
<               dst.sa_family = AF_INET;
< #endif
---
>             if (uio->uio_resid < sizeof(family)){
>                 error = EIO;
>                 goto out0;
>             }
>             error = uiomove((caddr_t)&family,sizeof(family), uio);
>             dst.sa_family = ntohl(family);
857c897
<               bpf_mtap_af(ifp->if_bpf, AF_INET, top);
---
>               bpf_mtap_af(ifp->if_bpf, dst.sa_family , top);