Bug 17873

Summary: Can not routing IPV6 packet with tun-device
Product: Base System Reporter: greg <greg>
Component: kernAssignee: Brian Somers <brian>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.0-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
if_tun.c.diff none

Description greg 2000-04-09 06:20:01 UTC
        V6 enviroment was completed. And after setting up tun device
for V6. creating a static routeing information by

        od -h /dev/tun0 &
        route add -inet6 default -interface tun0

And execute

        ping6 -I tun0 fe80::1

At normal case. V6 packet was routed into interface tun0. But packet was
rejected before tun device.
        So problem dose exist on initializing routine. if tun device
is staticaly network interface, Seem to be no problem. But it is not.
Must execute a initializing routine "in6_ifattach" directly.

Fix: This is a diffs for net/if_tun.c
How-To-Repeat:         Open and configure some tun for v6. And send some v6 packet
which is routed into tun device.
Comment 1 Brian Somers 2000-04-09 11:30:38 UTC
> 
> >Number:         17873
> >Category:       kern
> >Synopsis:       Can not routing IPV6 packet with tun-device
[.....]
> This is a diffs for net/if_tun.c

This breaks the if_tun module.  If the module is built with INET6 
defined, it'll fail to load on a non-INET6 kernel.  If it's not, 
it can't call in6_ifattach.

if_tun.c is already broken by calling if_attach() here.

We need to abstract the interface creation in a way similar to the 
way data's dispatched via sys/net/intrq.c.  Maybe there should be a 
all_ifattach() that's unconditionally built into the kernel and does 
something like

#ifdef INET
	if_attach(ifp);
#endif
#ifdef INET6
	in6_ifattach(ifp, IN6_IFT_P2P, 0, 0);
#endif

and so on ?  There'd need to be a more generic way of telling it to 
use IN6_IFT_P2P, and I'm not sure why the if_type = IFT_RS232 bit is 
necessary....
-- 
Brian <brian@Awfulhak.org>                        <brian@[uk.]FreeBSD.org>
      <http://www.Awfulhak.org>                   <brian@[uk.]OpenBSD.org>
Don't _EVER_ lose your sense of humour !
Comment 2 Brian Somers freebsd_committer freebsd_triage 2000-04-09 11:46:09 UTC
Responsible Changed
From-To: freebsd-bugs->brian

I've got an interest in keeping if_tun.ko as functional as the built in version. 

Comment 3 Brian Somers 2000-04-13 14:33:20 UTC
> <200004091030.LAA02368@hak.lan.Awfulhak.org>$B$N5-;v$K$*$$$F(B
> brian@Awfulhak.org$B$5$s$O=q$-$^$7$?!#(B
> 
> >This breaks the if_tun module.
> 
> Oh, Sorry, this is kernel built-in case.

if_tun is built as a module too.  Any changes to it should work for 
/sys/modules.

> >                                If the module is built with INET6 
> >defined, it'll fail to load on a non-INET6 kernel.  If it's not, 
> 
> In this case. tun device was staticaly linked in the kernel.
> 
> >if_tun.c is already broken by calling if_attach() here.
> 
> Where do I call in6_ifattach() collectly ? In if_attach() ?
> I think it seems to be not wrong.
> 
> >all_ifattach() that's unconditionally built into the kernel and does 
> >something like
> 
> Look like little dirty, if all_ifattach called at opening tun device.
> But these code has no problem basicly for me.

The idea here is to move the ``#ifdef INET6'' decisions out of 
if_tun.c as this decision cannot be made at module build time.  if 
there was a global all_ifattach() function that if_tun calls at softc 
creation time, it would make the problem go away.

> >#ifdef INET
> >	if_attach(ifp);
> >#endif
> >#ifdef INET6
> >	in6_ifattach(ifp, IN6_IFT_P2P, 0, 0);
> >#endif
> 
> So, if quated lines will be changed like this.
> 
> 	in6_ifattach(ifp, ifp->if_type, 0, 0);
> 
> and insert into some where.

Ok, but that still needs to be done somewhere in *every* compiled 
kernel so that the module doesn't get built with #ifdefs that will 
fail in some environments.

> ---
> Fingerprint16 = 4F CC 44 F8 54 BE 45 3A  4F 9F 1C 4E 5E 3B 91 E9
> Fingerprint20 = 12CA 6B2D DC50 8248 A636  992B 0292 F548 D65F 4D5B
> -----------------+-----------------------------------$BA}ED!!7r:n(B---+
> $B;0!&O;$r<i$m$&!*(B | greg@greg.rim.or.jp                            |
> $B!!$*2H$X5"$m$&!*(B |   greg@fxis.fujixerox.co.jp                    |
>                  |     http://www.st.rim.or.jp/~greg/             |
> -----------------+------------------------------------------------+

-- 
Brian <brian@Awfulhak.org>                        <brian@[uk.]FreeBSD.org>
      <http://www.Awfulhak.org>                   <brian@[uk.]OpenBSD.org>
Don't _EVER_ lose your sense of humour !
Comment 4 Brian Somers freebsd_committer freebsd_triage 2000-07-13 14:33:12 UTC
State Changed
From-To: open->feedback

Could the submitter confirm if just setting ifp->if_type in if_tun.c 
solves the problem (as discussed in April) ?
Comment 5 Brian Somers freebsd_committer freebsd_triage 2000-07-18 00:23:22 UTC
State Changed
From-To: feedback->closed

if_type set in if_tun.c as per discussions. 
I'll MFC on Wednesday