Getting /dev entry by interface name

Roman Bogorodskiy novel at FreeBSD.org
Sun Apr 8 08:31:15 UTC 2018


  Poul-Henning Kamp wrote:

> --------
> In message <20180407025807.GA18883 at kloomba>, Roman Bogorodskiy writes:
> 
> >1. Create tap(4) like that:
> >
> ># ifconfig tap create
> >tap2
> >#
> >
> >2. Rename it
> >
> ># ifconfig tap2 name testif
> >testif
> >
> >Now I can do 'ifconfig testif' and there'll be no signs that it was
> >named 'tap2' previously, however, in /dev it's still /dev/tap2.
> 
> I would argue that is an error.
> 
> The /dev entry should also be renamed, or maybe better, a symlink
> with the new name should be created, pointing to the /dev/tap%d
> entry.
> 
> However, I dont know if that is actually possible, is the device
> driver even even told about the new interface name ?
> 
> There is also a name-space validation issue to think about:
> 
> 	ifconfig tap2 name ../etc

I'm not sure if that's possible (or a reasonable thing to do) either.
Not only stuff like '../etc' needs to be validated as you mentioned, but
also we need to make sure not to clash with other devices. For example,
now it's possible to rename tap device to 'null' which will not be
possible if we create a symlink.

Back to the original question, julian@ suggested to take a look at
sysctl, and there's indeed one that reports this information.

There's even some sample code in tools/ available:

https://svnweb.freebsd.org/base/head/tools/tools/ifinfo/ifinfo.c?view=markup#l123

This sysctl is not easy to find unless you know what you're looking for.

Roman Bogorodskiy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20180408/d3f49d92/attachment.sig>


More information about the freebsd-hackers mailing list