Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Add support for a network interface description.



details:   https://anonhg.NetBSD.org/src/rev/9289dcf430c5
branches:  trunk
changeset: 461741:9289dcf430c5
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Thu Jul 04 02:44:25 2019 +0000

description:
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

diffstat:

 sys/net/if.c     |  56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 sys/net/if.h     |   8 +++++++-
 sys/sys/sockio.h |   5 ++++-
 3 files changed, 65 insertions(+), 4 deletions(-)

diffs (125 lines):

diff -r d8d33760ef48 -r 9289dcf430c5 sys/net/if.c
--- a/sys/net/if.c      Wed Jul 03 23:10:43 2019 +0000
+++ b/sys/net/if.c      Thu Jul 04 02:44:25 2019 +0000
@@ -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 @@
                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;
        }
diff -r d8d33760ef48 -r 9289dcf430c5 sys/net/if.h
--- a/sys/net/if.h      Wed Jul 03 23:10:43 2019 +0000
+++ b/sys/net/if.h      Thu Jul 04 02:44:25 2019 +0000
@@ -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 @@
        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;/* :: */
diff -r d8d33760ef48 -r 9289dcf430c5 sys/sys/sockio.h
--- a/sys/sys/sockio.h  Wed Jul 03 23:10:43 2019 +0000
+++ b/sys/sys/sockio.h  Thu Jul 04 02:44:25 2019 +0000
@@ -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 */



Home | Main Index | Thread Index | Old Index