Source-Changes-HG archive

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

[src-draft/trunk]: src/sys Allow cloning interfaces to require "constructor" ...



details:   https://anonhg.NetBSD.org/src-all/rev/cefce5a5f1f3
branches:  trunk
changeset: 371488:cefce5a5f1f3
user:      Martin Husemann <martin%NetBSD.org@localhost>
date:      Fri Sep 25 19:40:03 2020 +0200

description:
Allow cloning interfaces to require "constructor" arguments.

diffstat:

 sys/net/if.c     |  32 ++++++++++++++++++++++++++------
 sys/net/if.h     |  15 ++++++++++++++-
 sys/sys/sockio.h |   4 ++++
 3 files changed, 44 insertions(+), 7 deletions(-)

diffs (127 lines):

diff -r 3b0c7740174e -r cefce5a5f1f3 sys/net/if.c
--- a/sys/net/if.c      Fri Sep 25 19:38:49 2020 +0200
+++ b/sys/net/if.c      Fri Sep 25 19:40:03 2020 +0200
@@ -228,7 +228,7 @@
 static void if_attachdomain1(struct ifnet *);
 static int ifconf(u_long, void *);
 static int if_transmit(struct ifnet *, struct mbuf *);
-static int if_clone_create(const char *);
+static int if_clone_create(const char *, size_t, void*);
 static int if_clone_destroy(const char *);
 static void if_link_state_change_work(struct work *, void *);
 static void if_up_locked(struct ifnet *);
@@ -1564,7 +1564,7 @@
  * Create a clone network interface.
  */
 static int
-if_clone_create(const char *name)
+if_clone_create(const char *name, size_t arg_size, void *args)
 {
        struct if_clone *ifc;
        int unit;
@@ -1583,7 +1583,10 @@
                return EEXIST;
        }
 
-       return (*ifc->ifc_create)(ifc, unit);
+       if (ifc->ifc_create_with_args != NULL)
+               return (*ifc->ifc_create_with_args)(ifc, unit, arg_size, args);
+       else
+               return (*ifc->ifc_create)(ifc, unit);
 }
 
 /*
@@ -3483,6 +3486,7 @@
 
        switch (cmd) {
        case SIOCIFCREATE:
+       case SIOCIFCREATEARGS:
        case SIOCIFDESTROY: {
                const int bound = curlwp_bind();
                if (l != NULL) {
@@ -3500,9 +3504,25 @@
                }
                KERNEL_LOCK_UNLESS_NET_MPSAFE();
                mutex_enter(&if_clone_mtx);
-               r = (cmd == SIOCIFCREATE) ?
-                       if_clone_create(ifr->ifr_name) :
-                       if_clone_destroy(ifr->ifr_name);
+               switch (cmd) {
+               case SIOCIFCREATE:
+                       r = if_clone_create(ifr->ifr_name, 0, NULL);
+                       break;
+               case SIOCIFDESTROY:
+                       r = if_clone_destroy(ifr->ifr_name);
+                       break;
+               case SIOCIFCREATEARGS:
+                       {
+                               struct if_cclonearg *req =
+                                   (struct if_cclonearg *)data;
+                               r = if_clone_create(req->ifr_name,
+                                   req->ifc_arg_size, req->ifc_args);
+                       }
+                       break;
+               default:
+                       r = ENXIO;
+                       break;
+               }
                mutex_exit(&if_clone_mtx);
                KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
                curlwp_bindx(bound);
diff -r 3b0c7740174e -r cefce5a5f1f3 sys/net/if.h
--- a/sys/net/if.h      Fri Sep 25 19:38:49 2020 +0200
+++ b/sys/net/if.h      Fri Sep 25 19:40:03 2020 +0200
@@ -156,11 +156,15 @@
        size_t ifc_namelen;             /* length of name */
 
        int     (*ifc_create)(struct if_clone *, int);
+       int     (*ifc_create_with_args)(struct if_clone *, int, size_t, void*);
        int     (*ifc_destroy)(struct ifnet *);
 };
 
 #define        IF_CLONE_INITIALIZER(name, create, destroy)                     \
-       { { NULL, NULL }, name, sizeof(name) - 1, create, destroy }
+       { { NULL, NULL }, name, sizeof(name) - 1, create, NULL, destroy }
+
+#define        IF_CLONE_WITH_ARGS_INITIALIZER(name, create, destroy)           \
+       { { NULL, NULL }, name, sizeof(name) - 1, NULL, create, destroy }
 
 /*
  * Structure used to query names of interface cloners.
@@ -719,6 +723,8 @@
 #ifndef IFQ_MAXLEN
 #define        IFQ_MAXLEN      256
 #endif
+extern int ifqmaxlen;
+
 #define        IFNET_SLOWHZ    1               /* granularity is 1 second */
 
 /*
@@ -956,6 +962,13 @@
        struct sockaddr_storage ifap_addr;              /* in/out */
 };
 
+/* create an interface clone with initial arguments */
+struct if_cclonearg {
+       char    ifr_name[IFNAMSIZ];     /* if name, e.g. "en0" */
+       size_t  ifc_arg_size;           /* lenght of additional args */
+       void    *ifc_args;              /* pointer to creation arguments */
+};
+
 #include <net/if_arp.h>
 
 #endif /* _NETBSD_SOURCE */
diff -r 3b0c7740174e -r cefce5a5f1f3 sys/sys/sockio.h
--- a/sys/sys/sockio.h  Fri Sep 25 19:38:49 2020 +0200
+++ b/sys/sys/sockio.h  Fri Sep 25 19:40:03 2020 +0200
@@ -146,6 +146,10 @@
 #define SIOCSIFDESCR   _IOW('i', 142, struct ifreq)    /* set interface description */
 #define SIOCGIFDESCR   _IOWR('i', 143, struct ifreq)   /* get interface description */
 
+#define        SIOCIFCREATEARGS _IOW('i', 144, struct if_cclonearg)    /* create
+                                                        * clone if with
+                                                        * additional parameters */
+
 #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