Getting /dev entry by interface name

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting /dev entry by interface name

Roman Bogorodskiy-3
Hi,

I have the following scenario:

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.

The question is: given that I didn't save the original name before
renaming, what are the ways to map 'testif' to its /dev entry (/dev/tap2
in our example)?

The only way I found so far is to iterate over /dev/tap*, calling
TAPGIFNAME and checking if result matches the name I'm trying to look
up. This approach doesn't look good for a number of reasons, main are:

1. It's inefficient, esp. if there are many tap(4) devices,
2. It has annoying side effects, such as if the interface was up, after
opening it it will be down (unless net.link.tap.up_on_open is set to 1,
which I don't want to rely on).

Is there a cleaner way maybe? I wasn't able to get this information via
data returned by getifaddrs(3) for example, but probably I'm missing
something.

Roman Bogorodskiy

signature.asc (465 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Getting /dev entry by interface name

Poul-Henning Kamp
--------
In message <20180407025807.GA18883@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

--
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
[hidden email]         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Getting /dev entry by interface name

Stefan Blachmann
Does FreeBSD have anything comparable to the udev rules which are
available on the systemd-ized Linuces?
Afaiu such could achieve what the OP intended.

On 4/7/18, Poul-Henning Kamp <[hidden email]> wrote:

> --------
> In message <20180407025807.GA18883@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
>
> --
> Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
> [hidden email]         | TCP/IP since RFC 956
> FreeBSD committer       | BSD since 4.3-tahoe
> Never attribute to malice what can adequately be explained by incompetence.
> _______________________________________________
> [hidden email] mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "[hidden email]"
>
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Getting /dev entry by interface name

Poul-Henning Kamp
--------
In message <[hidden email]>, Stefan Blachmann writes:

>Does FreeBSD have anything comparable to the udev rules which are

Se devd(8)

I use it, amongst other things, to add symlinks to USB-serial adapters
based on serial numbers.

--
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
[hidden email]         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Getting /dev entry by interface name

Roman Bogorodskiy-3
In reply to this post by Poul-Henning Kamp
  Poul-Henning Kamp wrote:

> --------
> In message <20180407025807.GA18883@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

signature.asc (465 bytes) Download Attachment