Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 7 Apr 2018 06:58:09 +0400
From:      Roman Bogorodskiy <novel@FreeBSD.org>
To:        freebsd-hackers@freebsd.org
Subject:   Getting /dev entry by interface name
Message-ID:  <20180407025807.GA18883@kloomba>

next in thread | raw e-mail | index | archive | help

--rwEMma7ioTxnRzrJ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

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

--rwEMma7ioTxnRzrJ
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQEcBAEBAgAGBQJayDO/AAoJEMltX/4IwiJqAa8IAKibUjov9RQtCjT77H2jYXI7
OcnLt+GDIBB/dIHTwL1defUBI/lkyXLoyVfaUKDGOMXXxvdZ0qG1fhAAMRtguUHM
rl7P6nEF+EnZZmbnbrcWY0L7ViY2o+w5RbLtUy1YBi669I6PDNWXl1MJf9bMJBg4
ydO1QQDN6jSj8GAT3yVhRSW3pVqkibtPeUneA4X5RnGtCYNR0NfoqioMEorDRRyG
CYATAl6t8ReqrIULsp5FQqDbwmjL/y5dbp5sPnP6C2/dMPjz65NAhqn6vSv5IQ5D
WC0vtt1AToPJH5/8Cb546RoYdVyrWzTH3l27I4hG4etE0BCvZD22mx8xkvPMyrA=
=nFLX
-----END PGP SIGNATURE-----

--rwEMma7ioTxnRzrJ--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20180407025807.GA18883>