Skip to content

Commit

Permalink
if_tun: Add TUNGIFNAME ioctl to get the interface name
Browse files Browse the repository at this point in the history
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
  • Loading branch information
liweitianux committed Jul 31, 2018
1 parent a50e0e6 commit 0df03f1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
10 changes: 9 additions & 1 deletion share/man/man4/tun.4
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.\" $FreeBSD: src/share/man/man4/tun.4,v 1.9.2.4 2001/08/17 13:08:39 ru Exp $
.\" Based on PR#2411
.\"
.Dd July 17, 2018
.Dd July 31, 2018
.Dt TUN 4
.Os
.Sh NAME
Expand Down Expand Up @@ -221,6 +221,14 @@ is declared in
The argument should be a pointer to an
.Vt struct tuninfo ,
where the current MTU, type, and baudrate will be stored.
.It Dv TUNGIFNAME
Retrieve the name of the network interface that is associated with the
control device.
The argument should be a pointer to a
.Va struct ifreq .
The interface name will be returned in the
.Va ifr_name
field.
.It Dv TUNSIFMODE
The argument should be a pointer to an
.Vt int ;
Expand Down
6 changes: 6 additions & 0 deletions sys/net/tun/if_tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ tunioctl(struct dev_ioctl_args *ap)
caddr_t data = ap->a_data;
struct tun_softc *sc = dev->si_drv1;
struct ifnet *ifp = sc->tun_ifp;
struct ifreq *ifr;
struct tuninfo *tunp;
int error = 0;

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

case TUNGIFNAME:
ifr = (struct ifreq *)data;
strlcpy(ifr->ifr_name, ifp->if_xname, IFNAMSIZ);
break;

case TUNSDEBUG:
tundebug = *(int *)data;
break;
Expand Down
5 changes: 4 additions & 1 deletion sys/net/tun/if_tun.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ struct tuninfo {

#define TUNSLMODE _IOW('t', 93, int)
#define TUNSIFMODE _IOW('t', 94, int)
#define TUNSIFPID _IO('t', 95)
#define TUNSIFPID _IO('t', 95)
#define TUNSIFHEAD _IOW('t', 96, int)
#define TUNGIFHEAD _IOR('t', 97, int)

/* get the network interface name */
#define TUNGIFNAME _IOR('t', 98, struct ifreq)

#endif /* !_NET_IF_TUN_H_ */
3 changes: 2 additions & 1 deletion sys/sys/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@
* 500312 - OpenPAM Resedacea upgrade
* 500313 - remove vmnet support from tap(4) (VMIO_* ioctls)
* 500314 - add TAPGIFNAME to tap(4)
* 500315 - add TUNGIFNAME to tun(4)
*/
#undef __DragonFly_version
#define __DragonFly_version 500314 /* propagated to newvers */
#define __DragonFly_version 500315 /* propagated to newvers */

#include <sys/_null.h>

Expand Down

0 comments on commit 0df03f1

Please sign in to comment.