Re: git: if_tun: Use pointer to ifnet in tun_softc struct

2018-07-19 Thread Aaron LI
OK, thanks.

I'll keep looking at the net code, and can improve it later.


On Fri, 20 Jul 2018 12:07:00 +0800
Sepherosa Ziehau  wrote:

> Well, I don't think if_alloc makes sense for Dfly.  But if you have
> already changed some code, then let it be.
> 
> On Fri, Jul 20, 2018 at 11:19 AM, Aaron LI  wrote:
> > On Fri, 20 Jul 2018 10:43:16 +0800
> > Sepherosa Ziehau  wrote:
> >  
> >> On Fri, Jul 20, 2018 at 10:19 AM, Aaron LI  wrote:  
> >> > On Fri, 20 Jul 2018 09:40:21 +0800
> >> > Sepherosa Ziehau  wrote:
> >> >  
> >> >> I am not quite sure why we want to use if_alloc() in the first
> >> >> place?  
> >> >
> >> > Since our if_alloc() is very simple, so there is no big benefit to use
> >> > it over the direct kmalloc().  But if_alloc() is easier to use and more
> >> > intuitive.  
> >>
> >> I mean why allocate in the first place?  What's wrong w/ embedding?  
> >
> > There is nothing wrong with embedding ifnet inside tun_softc.
> >
> > So do you think is it better to embed or not embed the ifnet?  I'll follow
> > your advice.  Thanks.
> >



pgpQitKq0b_9i.pgp
Description: OpenPGP digital signature


Re: git: if_tun: Use pointer to ifnet in tun_softc struct

2018-07-19 Thread Sepherosa Ziehau
Well, I don't think if_alloc makes sense for Dfly.  But if you have
already changed some code, then let it be.

On Fri, Jul 20, 2018 at 11:19 AM, Aaron LI  wrote:
> On Fri, 20 Jul 2018 10:43:16 +0800
> Sepherosa Ziehau  wrote:
>
>> On Fri, Jul 20, 2018 at 10:19 AM, Aaron LI  wrote:
>> > On Fri, 20 Jul 2018 09:40:21 +0800
>> > Sepherosa Ziehau  wrote:
>> >
>> >> I am not quite sure why we want to use if_alloc() in the first place?
>> >
>> > Since our if_alloc() is very simple, so there is no big benefit to use it
>> > over the direct kmalloc().  But if_alloc() is easier to use and more
>> > intuitive.
>>
>> I mean why allocate in the first place?  What's wrong w/ embedding?
>
> There is nothing wrong with embedding ifnet inside tun_softc.
>
> So do you think is it better to embed or not embed the ifnet?  I'll follow
> your advice.  Thanks.
>
>
> --
> Aaron



-- 
Tomorrow Will Never Die


Re: git: if_tun: Use pointer to ifnet in tun_softc struct

2018-07-19 Thread Aaron LI
On Fri, 20 Jul 2018 10:43:16 +0800
Sepherosa Ziehau  wrote:

> On Fri, Jul 20, 2018 at 10:19 AM, Aaron LI  wrote:
> > On Fri, 20 Jul 2018 09:40:21 +0800
> > Sepherosa Ziehau  wrote:
> >  
> >> I am not quite sure why we want to use if_alloc() in the first place?  
> >
> > Since our if_alloc() is very simple, so there is no big benefit to use it
> > over the direct kmalloc().  But if_alloc() is easier to use and more
> > intuitive.  
> 
> I mean why allocate in the first place?  What's wrong w/ embedding?

There is nothing wrong with embedding ifnet inside tun_softc.

So do you think is it better to embed or not embed the ifnet?  I'll follow
your advice.  Thanks.


-- 
Aaron


pgpQlhCi0J2El.pgp
Description: OpenPGP digital signature


Re: git: if_tun: Use pointer to ifnet in tun_softc struct

2018-07-19 Thread Sepherosa Ziehau
On Fri, Jul 20, 2018 at 10:19 AM, Aaron LI  wrote:
> On Fri, 20 Jul 2018 09:40:21 +0800
> Sepherosa Ziehau  wrote:
>
>> Most of the physical drivers are ethernet ones, so they need arpcom;
>> please do w/ care.
>
> Sure, I have to understand the drivers more before really touching them.
>
>> I am not quite sure why we want to use if_alloc() in the first place?
>
> Since our if_alloc() is very simple, so there is no big benefit to use it
> over the direct kmalloc().  But if_alloc() is easier to use and more
> intuitive.

I mean why allocate in the first place?  What's wrong w/ embedding?

>
>> We don't have the synchronization issue if_alloc() tries to address
>> in FreeBSD.
>
> Cool!
>
>
> Cheers,
> --
> Aaron



-- 
Tomorrow Will Never Die


Re: git: if_tun: Use pointer to ifnet in tun_softc struct

2018-07-19 Thread Aaron LI
On Fri, 20 Jul 2018 09:40:21 +0800
Sepherosa Ziehau  wrote:

> Most of the physical drivers are ethernet ones, so they need arpcom;
> please do w/ care.

Sure, I have to understand the drivers more before really touching them.

> I am not quite sure why we want to use if_alloc() in the first place?

Since our if_alloc() is very simple, so there is no big benefit to use it
over the direct kmalloc().  But if_alloc() is easier to use and more
intuitive.

> We don't have the synchronization issue if_alloc() tries to address
> in FreeBSD.

Cool!


Cheers,
-- 
Aaron


pgpLus5jRHfkV.pgp
Description: OpenPGP digital signature


Re: git: if_tun: Use pointer to ifnet in tun_softc struct

2018-07-19 Thread Sepherosa Ziehau
Most of the physical drivers are ethernet ones, so they need arpcom;
please do w/ care.  I am not quite sure why we want to use if_alloc()
in the first place?  We don't have the synchronization issue
if_alloc() tries to address in FreeBSD.

On Fri, Jul 20, 2018 at 9:29 AM, Aaron LI  wrote:
> On Fri, 20 Jul 2018 09:09:07 +0800
> Sepherosa Ziehau  wrote:
>
>> Just panic if_com_alloc[type]() fails.
>>
>
> Ok, I'll do it.  I'll also look at the drivers to make them use if_alloc()
> and if_free() when appropriate.
>
>
> Cheers,
> --
> Aaron



-- 
Tomorrow Will Never Die


Re: git: if_tun: Use pointer to ifnet in tun_softc struct

2018-07-19 Thread Aaron LI
On Fri, 20 Jul 2018 09:09:07 +0800
Sepherosa Ziehau  wrote:

> Just panic if_com_alloc[type]() fails.
> 

Ok, I'll do it.  I'll also look at the drivers to make them use if_alloc()
and if_free() when appropriate.


Cheers,
-- 
Aaron


pgppTtS70LbYz.pgp
Description: OpenPGP digital signature


Re: git: if_tun: Use pointer to ifnet in tun_softc struct

2018-07-19 Thread Sepherosa Ziehau
Just panic if_com_alloc[type]() fails.

On Thu, Jul 19, 2018 at 5:20 PM, Aaron LI  wrote:
> On Thu, 19 Jul 2018 17:00:44 +0800
> Sepherosa Ziehau  wrote:
>
>> How about move the following logic into if_alloc():
>>
>> +   ifp = sc->tun_ifp = if_alloc(IFT_PPP);
>> +   if (ifp == NULL)
>> +   /* XXX: should return an error */
>> +   panic("%s%d: failed to if_alloc() interface", TUN,
>> minor(dev));
>>
>> i.e. if_alloc never fails.
>
> But the if_alloc() can return NULL if if_com_alloc[type]() fails, so does
> if_alloc() need some work?
>
> On the other hand, the code ported from FreeBSD all uses if_alloc() but
> checks its return value.  By making if_alloc() never fail will simplify its
> use.
>
> What do you think on improving the if_alloc()-related code?
>
>
> Cheers,
> --
> Aaron



-- 
Tomorrow Will Never Die


Re: git: if_tun: Use pointer to ifnet in tun_softc struct

2018-07-19 Thread Sepherosa Ziehau
How about move the following logic into if_alloc():

+   ifp = sc->tun_ifp = if_alloc(IFT_PPP);
+   if (ifp == NULL)
+   /* XXX: should return an error */
+   panic("%s%d: failed to if_alloc() interface", TUN, minor(dev));

i.e. if_alloc never fails.


On Thu, Jul 19, 2018 at 4:15 PM, Aaron LI  wrote:
>
> commit 6f90efb8f9ac6785b04c25efb90c432dcdb142af
> Author: Aaron LI 
> Date:   Sat Jul 7 23:16:19 2018 +0800
>
> if_tun: Use pointer to ifnet in tun_softc struct
>
> Use a pointer to the ifnet struct in the tun_softc struct, instead of
> embedding a full ifnet struct in it.  (similar to FreeBSD's)
>
> Use if_alloc() to allocate the ifnet struct.
>
> Summary of changes:
>  sys/net/tun/if_tun.c| 20 
>  sys/net/tun/if_tunvar.h |  2 +-
>  2 files changed, 13 insertions(+), 9 deletions(-)
>
> http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/6f90efb8f9ac6785b04c25efb90c432dcdb142af
>
>
> --
> DragonFly BSD source repository



-- 
Tomorrow Will Never Die


git: if_tun: Allow IP packets of length TUNMRU with TUNSIFHEAD set

2018-07-19 Thread Aaron LI


commit b6f0123246e7c8525d2f5a5ff4f3014d1f5f8b66
Author: Aaron LI 
Date:   Tue Jul 17 19:57:55 2018 +0800

if_tun: Allow IP packets of length TUNMRU with TUNSIFHEAD set

Obtained-from: FreeBSD (revision 300205)

Summary of changes:
 sys/net/tun/if_tun.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/b6f0123246e7c8525d2f5a5ff4f3014d1f5f8b66


-- 
DragonFly BSD source repository


git: if_tun: Add "cdev_t tun_dev" to tun_softc struct

2018-07-19 Thread Aaron LI


commit 860e305a4e6cc899b09479646ac55eaca5b142f1
Author: Aaron LI 
Date:   Sat Jul 7 23:21:18 2018 +0800

if_tun: Add "cdev_t tun_dev" to tun_softc struct

Similar to if_tap, save the tun device in the tun_softc struct.

Summary of changes:
 sys/net/tun/if_tun.c| 3 +++
 sys/net/tun/if_tunvar.h | 2 ++
 2 files changed, 5 insertions(+)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/860e305a4e6cc899b09479646ac55eaca5b142f1


-- 
DragonFly BSD source repository


git: if_tun: Better name interface-related functions

2018-07-19 Thread Aaron LI


commit a6b12a18cc0bfcc7350772075da413d16a3f67f1
Author: Aaron LI 
Date:   Sun Jul 8 19:55:36 2018 +0800

if_tun: Better name interface-related functions

Rename interface-related functions to be 'tunifxxx', and reorder a
bit to better group them.

Tweak the styles and improve debug messages a bit.

Summary of changes:
 sys/net/tun/if_tun.c | 124 +++
 1 file changed, 65 insertions(+), 59 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/a6b12a18cc0bfcc7350772075da413d16a3f67f1


-- 
DragonFly BSD source repository


git: if_tun: Add sysctl net.link.tun.{refcnt,debug}

2018-07-19 Thread Aaron LI


commit 98e874e52520ad50c29307adf4754a2465666477
Author: Aaron LI 
Date:   Sun Jul 8 10:17:20 2018 +0800

if_tun: Add sysctl net.link.tun.{refcnt,debug}

Add read-only sysctl net.link.tun.refcnt to show the number of opened
devices.

Add sysctl net.link.tun.debug to be a alias to debug.if_tun_debug.

Summary of changes:
 sys/net/tun/if_tun.c | 7 +++
 1 file changed, 7 insertions(+)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/98e874e52520ad50c29307adf4754a2465666477


-- 
DragonFly BSD source repository


git: if_tun: Raise maximum MTU to be 65535 bytes

2018-07-19 Thread Aaron LI


commit 9abf54c01ae57593a8ff5ee7381adca8a67005cb
Author: Aaron LI 
Date:   Thu Jul 5 14:08:43 2018 +0800

if_tun: Raise maximum MTU to be 65535 bytes

This is used, for example, by packetdrill to test with MTU's up to the
maximum value.

Taken-from: FreeBSD (revision 300603)

Summary of changes:
 sys/net/tun/if_tun.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/9abf54c01ae57593a8ff5ee7381adca8a67005cb


-- 
DragonFly BSD source repository


git: if_tun: Implement interface clone support

2018-07-19 Thread Aaron LI


commit 925b0cbfbfed7123f1222f6b5650b7747937015d
Author: Aaron LI 
Date:   Sun Jul 8 21:07:20 2018 +0800

if_tun: Implement interface clone support

Now 'ifconfig tunX create' and 'ifconfig tunX destroy' work.

The tun device will be automatically destroyed when being closed,
except for the manually created tun device/interface by
'ifconfig tunX create', similar to the tap(4) device.

This interface clone support is based on the if_tap device.

Summary of changes:
 share/man/man4/tun.4|  19 +-
 sys/net/tun/if_tun.c| 154 +---
 sys/net/tun/if_tunvar.h |   2 +
 3 files changed, 152 insertions(+), 23 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/925b0cbfbfed7123f1222f6b5650b7747937015d


-- 
DragonFly BSD source repository


git: if_tun: Use pointer to ifnet in tun_softc struct

2018-07-19 Thread Aaron LI


commit 6f90efb8f9ac6785b04c25efb90c432dcdb142af
Author: Aaron LI 
Date:   Sat Jul 7 23:16:19 2018 +0800

if_tun: Use pointer to ifnet in tun_softc struct

Use a pointer to the ifnet struct in the tun_softc struct, instead of
embedding a full ifnet struct in it.  (similar to FreeBSD's)

Use if_alloc() to allocate the ifnet struct.

Summary of changes:
 sys/net/tun/if_tun.c| 20 
 sys/net/tun/if_tunvar.h |  2 +-
 2 files changed, 13 insertions(+), 9 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/6f90efb8f9ac6785b04c25efb90c432dcdb142af


-- 
DragonFly BSD source repository


git: if_tun: Update tun.4 man page to match the code

2018-07-19 Thread Aaron LI


commit b24712baecd0d6a60456e438a12293241e320636
Author: Aaron LI 
Date:   Tue Jul 17 19:04:12 2018 +0800

if_tun: Update tun.4 man page to match the code

Mainly follow FreeBSD's tun.4, refer to NetBSD's tun.4, and with my own
minor adjustments.

Summary of changes:
 share/man/man4/tun.4 | 122 +++
 1 file changed, 83 insertions(+), 39 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/b24712baecd0d6a60456e438a12293241e320636


-- 
DragonFly BSD source repository


git: if_tun: Some small tweaks and cleanups

2018-07-19 Thread Aaron LI


commit 0db5ecf136b9c767d1b577710a0fb9bcc838b2f3
Author: Aaron LI 
Date:   Sat Jul 7 20:49:04 2018 +0800

if_tun: Some small tweaks and cleanups

* Consistently use the TUN define instead of "tun".

* Use variable "sc" instead of "tp" to refer to "struct tun_softc".

* Use variable "ifp" (struct ifnet *) to make code more readable.

* Static the bitmap variable.

* Various style tweaks.

Summary of changes:
 sys/net/tun/if_tun.c| 416 ++--
 sys/net/tun/if_tun.h|  17 +-
 sys/net/tun/if_tunvar.h |  16 +-
 3 files changed, 238 insertions(+), 211 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/0db5ecf136b9c767d1b577710a0fb9bcc838b2f3


-- 
DragonFly BSD source repository


git: if_tun: Support module load and unload

2018-07-19 Thread Aaron LI


commit e9ff9cbbb2f67488b832b985884330539eb236cf
Author: Aaron LI 
Date:   Sun Jul 8 09:43:12 2018 +0800

if_tun: Support module load and unload

Track the created tun devices in a list, and record the number of opened
tun devices.  Destroy all tun devices when unloading the module.

Mainly based on if_tap.

Summary of changes:
 share/man/man4/tun.4|  7 
 sys/net/tun/if_tun.c| 99 +
 sys/net/tun/if_tunvar.h |  2 +
 3 files changed, 92 insertions(+), 16 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/e9ff9cbbb2f67488b832b985884330539eb236cf


-- 
DragonFly BSD source repository


git: if_tap: Restore SIOCGIFFLAGS, SIOC[GS]IFADDR ioctls for tapioctl()

2018-07-19 Thread Aaron LI


commit d4daa541d3579963aea225dace938f1bf58edd27
Author: Aaron LI 
Date:   Thu Jul 19 15:04:35 2018 +0800

if_tap: Restore SIOCGIFFLAGS, SIOC[GS]IFADDR ioctls for tapioctl()

These ioctls allow basic control of the network interface via the device
file (/dev/tapX).  For example, our vke(4) device currently uses the
'SIOCGIFADDR' ioctl.

Summary of changes:
 share/man/man4/tap.4 | 23 ++-
 sys/net/tap/if_tap.c | 17 +
 2 files changed, 39 insertions(+), 1 deletion(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/d4daa541d3579963aea225dace938f1bf58edd27


-- 
DragonFly BSD source repository