Add support for a network interface description.
ioctl(2): - Add SIOCGIFDESCR/SIOCSIFDESCR commands to get/set the description. This enables to make a memo for interface, like "Home network" or "Remote VPN". From t-kusaba@IIJ
This commit is contained in:
parent
339e525973
commit
aa0ca9e9b1
56
sys/net/if.c
56
sys/net/if.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: if.c,v 1.455 2019/05/21 09:18:37 msaitoh Exp $ */
|
||||
/* $NetBSD: if.c,v 1.456 2019/07/04 02:44:25 ozaki-r Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
|
||||
@ -90,7 +90,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.455 2019/05/21 09:18:37 msaitoh Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.456 2019/07/04 02:44:25 ozaki-r Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_inet.h"
|
||||
@ -3050,6 +3050,58 @@ ifioctl_common(struct ifnet *ifp, u_long cmd, void *data)
|
||||
KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
|
||||
#endif
|
||||
return ENETRESET;
|
||||
case SIOCSIFDESCR:
|
||||
{
|
||||
char *descrbuf;
|
||||
|
||||
ifr = data;
|
||||
|
||||
if (ifr->ifr_buflen > IFDESCRSIZE)
|
||||
return ENAMETOOLONG;
|
||||
|
||||
if (ifr->ifr_buf == NULL || ifr->ifr_buflen == 0) {
|
||||
/* unset description */
|
||||
descrbuf = NULL;
|
||||
} else {
|
||||
int error;
|
||||
|
||||
descrbuf = kmem_zalloc(IFDESCRSIZE, KM_SLEEP);
|
||||
/* copy (IFDESCRSIZE - 1) bytes to ensure terminating nul */
|
||||
error = copyin(ifr->ifr_buf, descrbuf, IFDESCRSIZE - 1);
|
||||
if (error) {
|
||||
kmem_free(descrbuf, IFDESCRSIZE);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
if (ifp->if_description != NULL)
|
||||
kmem_free(ifp->if_description, IFDESCRSIZE);
|
||||
|
||||
ifp->if_description = descrbuf;
|
||||
}
|
||||
break;
|
||||
|
||||
case SIOCGIFDESCR:
|
||||
{
|
||||
char *descr;
|
||||
|
||||
ifr = data;
|
||||
descr = ifp->if_description;
|
||||
|
||||
if (descr == NULL)
|
||||
return ENOMSG;
|
||||
|
||||
if (ifr->ifr_buflen < IFDESCRSIZE)
|
||||
return EINVAL;
|
||||
else {
|
||||
int error;
|
||||
error = copyout(descr, ifr->ifr_buf, IFDESCRSIZE);
|
||||
if (error)
|
||||
return error;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return ENOTTY;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: if.h,v 1.273 2019/06/24 06:24:33 skrll Exp $ */
|
||||
/* $NetBSD: if.h,v 1.274 2019/07/04 02:44:25 ozaki-r Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
|
||||
@ -75,6 +75,11 @@
|
||||
*/
|
||||
#define IF_NAMESIZE 16
|
||||
|
||||
/*
|
||||
* Length of interface description, including terminating '\0'.
|
||||
*/
|
||||
#define IFDESCRSIZE 64
|
||||
|
||||
#if defined(_NETBSD_SOURCE)
|
||||
|
||||
#include <sys/socket.h>
|
||||
@ -365,6 +370,7 @@ typedef struct ifnet {
|
||||
int (*if_setflags) /* :: */
|
||||
(struct ifnet *, const short);
|
||||
kmutex_t *if_ioctl_lock; /* :: */
|
||||
char *if_description; /* i: interface description */
|
||||
#ifdef _KERNEL /* XXX kvm(3) */
|
||||
struct callout *if_slowtimo_ch;/* :: */
|
||||
struct krwlock *if_afdata_lock;/* :: */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: sockio.h,v 1.37 2019/05/17 07:37:12 msaitoh Exp $ */
|
||||
/* $NetBSD: sockio.h,v 1.38 2019/07/04 02:44:25 ozaki-r Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1982, 1986, 1990, 1993, 1994
|
||||
@ -143,6 +143,9 @@
|
||||
#define SIOCGIFINDEX _IOWR('i', 140, struct ifreq) /* get ifnet index */
|
||||
#define SIOCSETHERCAP _IOW('i', 141, struct eccapreq) /* set ethercap */
|
||||
|
||||
#define SIOCSIFDESCR _IOW('i', 142, struct ifreq) /* set interface description */
|
||||
#define SIOCGIFDESCR _IOWR('i', 143, struct ifreq) /* get interface description */
|
||||
|
||||
#define SIOCGUMBINFO _IOWR('i', 190, struct ifreq) /* get MBIM info */
|
||||
#define SIOCSUMBPARAM _IOW('i', 191, struct ifreq) /* set MBIM param */
|
||||
#define SIOCGUMBPARAM _IOWR('i', 192, struct ifreq) /* get MBIM param */
|
||||
|
Loading…
Reference in New Issue
Block a user