Skip to content

Commit 0df03f1

Browse files
committed
if_tun: Add TUNGIFNAME ioctl to get the interface name
This ioctl helps to get the name of the network interface associated with the tun control device via its file descriptor. One generally obtains such a file descriptor by opening the tun autocloner (i.e., /dev/tun). While the devname(3) or fdevname(3) functions can be used to determine the name of the actually created tun device, but there is no easy way to get the name of the associated network interface, which is though initially the same as the device name but can be renamed. Bump __DragonFly_version and update tun.4 man page. See also the relevant Linux patch that added TUNGETIFF to tun: https://lists.linuxfoundation.org/pipermail/virtualization/2008-August/011546.html
1 parent a50e0e6 commit 0df03f1

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

share/man/man4/tun.4

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.\" $FreeBSD: src/share/man/man4/tun.4,v 1.9.2.4 2001/08/17 13:08:39 ru Exp $
33
.\" Based on PR#2411
44
.\"
5-
.Dd July 17, 2018
5+
.Dd July 31, 2018
66
.Dt TUN 4
77
.Os
88
.Sh NAME
@@ -221,6 +221,14 @@ is declared in
221221
The argument should be a pointer to an
222222
.Vt struct tuninfo ,
223223
where the current MTU, type, and baudrate will be stored.
224+
.It Dv TUNGIFNAME
225+
Retrieve the name of the network interface that is associated with the
226+
control device.
227+
The argument should be a pointer to a
228+
.Va struct ifreq .
229+
The interface name will be returned in the
230+
.Va ifr_name
231+
field.
224232
.It Dv TUNSIFMODE
225233
The argument should be a pointer to an
226234
.Vt int ;

sys/net/tun/if_tun.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ tunioctl(struct dev_ioctl_args *ap)
674674
caddr_t data = ap->a_data;
675675
struct tun_softc *sc = dev->si_drv1;
676676
struct ifnet *ifp = sc->tun_ifp;
677+
struct ifreq *ifr;
677678
struct tuninfo *tunp;
678679
int error = 0;
679680

@@ -695,6 +696,11 @@ tunioctl(struct dev_ioctl_args *ap)
695696
tunp->baudrate = ifp->if_baudrate;
696697
break;
697698

699+
case TUNGIFNAME:
700+
ifr = (struct ifreq *)data;
701+
strlcpy(ifr->ifr_name, ifp->if_xname, IFNAMSIZ);
702+
break;
703+
698704
case TUNSDEBUG:
699705
tundebug = *(int *)data;
700706
break;

sys/net/tun/if_tun.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ struct tuninfo {
4343

4444
#define TUNSLMODE _IOW('t', 93, int)
4545
#define TUNSIFMODE _IOW('t', 94, int)
46-
#define TUNSIFPID _IO('t', 95)
46+
#define TUNSIFPID _IO('t', 95)
4747
#define TUNSIFHEAD _IOW('t', 96, int)
4848
#define TUNGIFHEAD _IOR('t', 97, int)
4949

50+
/* get the network interface name */
51+
#define TUNGIFNAME _IOR('t', 98, struct ifreq)
52+
5053
#endif /* !_NET_IF_TUN_H_ */

sys/sys/param.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@
185185
* 500312 - OpenPAM Resedacea upgrade
186186
* 500313 - remove vmnet support from tap(4) (VMIO_* ioctls)
187187
* 500314 - add TAPGIFNAME to tap(4)
188+
* 500315 - add TUNGIFNAME to tun(4)
188189
*/
189190
#undef __DragonFly_version
190-
#define __DragonFly_version 500314 /* propagated to newvers */
191+
#define __DragonFly_version 500315 /* propagated to newvers */
191192

192193
#include <sys/_null.h>
193194

0 commit comments

Comments
 (0)