Getting /dev entry by interface name
Roman Bogorodskiy
novel at FreeBSD.org
Sat Apr 7 02:58:19 UTC 2018
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
-------------- 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/20180407/5ca01985/attachment.sig>
More information about the freebsd-hackers
mailing list