Source-Changes-HG archive

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

[src/trunk]: src/sys Add a SIOCGIFCLONERS ioctl, which fetches a list of network



details:   https://anonhg.NetBSD.org/src/rev/24dcb205c90a
branches:  trunk
changeset: 495061:24dcb205c90a
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu Jul 20 18:40:26 2000 +0000

description:
Add a SIOCGIFCLONERS ioctl, which fetches a list of network
interface cloners from the kernel.

diffstat:

 sys/net/if.c     |  44 +++++++++++++++++++++++++++++++++++++++++++-
 sys/net/if.h     |  25 +++++++++++++++++--------
 sys/sys/sockio.h |   3 ++-
 3 files changed, 62 insertions(+), 10 deletions(-)

diffs (150 lines):

diff -r d9e4ce834e36 -r 24dcb205c90a sys/net/if.c
--- a/sys/net/if.c      Thu Jul 20 18:33:40 2000 +0000
+++ b/sys/net/if.c      Thu Jul 20 18:40:26 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.66 2000/07/19 06:00:39 onoe Exp $     */
+/*     $NetBSD: if.c,v 1.67 2000/07/20 18:40:27 thorpej Exp $  */
 
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@@ -150,8 +150,10 @@
 int    if_rt_walktree __P((struct radix_node *, void *));
 
 struct if_clone *if_clone_lookup __P((const char *, int *));
+int if_clone_list __P((struct if_clonereq *));
 
 LIST_HEAD(, if_clone) if_cloners = LIST_HEAD_INITIALIZER(if_cloners);
+int if_cloners_count;
 
 /*
  * Network interface utility routines.
@@ -578,6 +580,7 @@
 {
 
        LIST_INSERT_HEAD(&if_cloners, ifc, ifc_list);
+       if_cloners_count++;
 }
 
 /*
@@ -589,6 +592,42 @@
 {
 
        LIST_REMOVE(ifc, ifc_list);
+       if_cloners_count--;
+}
+
+/*
+ * Provide list of interface cloners to userspace.
+ */
+int
+if_clone_list(ifcr)
+       struct if_clonereq *ifcr;
+{
+       char outbuf[IFNAMSIZ], *dst;
+       struct if_clone *ifc;
+       int count, error = 0;
+
+       ifcr->ifcr_total = if_cloners_count;
+       if ((dst = ifcr->ifcr_buffer) == NULL) {
+               /* Just asking how many there are. */
+               return (0);
+       }
+
+       if (ifcr->ifcr_count < 0)
+               return (EINVAL);
+
+       count = (if_cloners_count < ifcr->ifcr_count) ?
+           if_cloners_count : ifcr->ifcr_count;
+
+       for (ifc = LIST_FIRST(&if_cloners); ifc != NULL && count != 0;
+            ifc = LIST_NEXT(ifc, ifc_list), count--, dst += IFNAMSIZ) {
+               strncpy(outbuf, ifc->ifc_name, IFNAMSIZ);
+               outbuf[IFNAMSIZ - 1] = '\0';    /* sanity */
+               error = copyout(outbuf, dst, IFNAMSIZ);
+               if (error)
+                       break;
+       }
+
+       return (error);
 }
 
 /*
@@ -1032,6 +1071,9 @@
                return ((cmd == SIOCIFCREATE) ?
                        if_clone_create(ifr->ifr_name) :
                        if_clone_destroy(ifr->ifr_name));
+
+       case SIOCIFGCLONERS:
+               return (if_clone_list((struct if_clonereq *)data));
        }
 
        ifp = ifunit(ifr->ifr_name);
diff -r d9e4ce834e36 -r 24dcb205c90a sys/net/if.h
--- a/sys/net/if.h      Thu Jul 20 18:33:40 2000 +0000
+++ b/sys/net/if.h      Thu Jul 20 18:40:26 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.h,v 1.52 2000/07/04 19:09:17 thorpej Exp $  */
+/*     $NetBSD: if.h,v 1.53 2000/07/20 18:40:27 thorpej Exp $  */
 
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@@ -117,6 +117,13 @@
 struct ifnet;
 
 /*
+ * Length of interface external name, including terminating '\0'.
+ * Note: this is the same size as a generic device's external name.
+ */
+#define        IFNAMSIZ        16
+#define        IF_NAMESIZE     IFNAMSIZ
+
+/*
  * Structure describing a `cloning' interface.
  */
 struct if_clone {
@@ -132,6 +139,15 @@
        { { 0 }, name, sizeof(name) - 1, create, destroy }
 
 /*
+ * Structure used to query names of interface cloners.
+ */
+struct if_clonereq {
+       int     ifcr_total;             /* total cloners (out) */
+       int     ifcr_count;             /* room for this many in user buffer */
+       char    *ifcr_buffer;           /* buffer for cloner names */
+};
+
+/*
  * Structure defining statistics and other data kept regarding a network
  * interface.
  */
@@ -199,13 +215,6 @@
  */
 TAILQ_HEAD(ifnet_head, ifnet);         /* the actual queue head */
 
-/*
- * Length of interface external name, including terminating '\0'.
- * Note: this is the same size as a generic device's external name.
- */
-#define        IFNAMSIZ        16
-#define        IF_NAMESIZE     IFNAMSIZ
-
 struct ifnet {                         /* and the entries */
        void    *if_softc;              /* lower-level data for this if */
        TAILQ_ENTRY(ifnet) if_list;     /* all struct ifnets are chained */
diff -r d9e4ce834e36 -r 24dcb205c90a sys/sys/sockio.h
--- a/sys/sys/sockio.h  Thu Jul 20 18:33:40 2000 +0000
+++ b/sys/sys/sockio.h  Thu Jul 20 18:40:26 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sockio.h,v 1.12 2000/07/02 00:20:49 thorpej Exp $      */
+/*     $NetBSD: sockio.h,v 1.13 2000/07/20 18:40:26 thorpej Exp $      */
 
 /*-
  * Copyright (c) 1982, 1986, 1990, 1993, 1994
@@ -101,5 +101,6 @@
                                                           parameters */
 #define        SIOCIFCREATE     _IOW('i', 122, struct ifreq)   /* create clone if */
 #define        SIOCIFDESTROY    _IOW('i', 121, struct ifreq)   /* destroy clone if */
+#define        SIOCIFGCLONERS  _IOWR('i', 120, struct if_clonereq) /* get cloners */
 
 #endif /* !_SYS_SOCKIO_H_ */



Home | Main Index | Thread Index | Old Index