Source-Changes-HG archive

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

[src/trunk]: src/sys/net introduced APIs to configure VLAN TAG to ethernet de...



details:   https://anonhg.NetBSD.org/src/rev/0459535d18ab
branches:  trunk
changeset: 1026260:0459535d18ab
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Mon Nov 15 07:07:05 2021 +0000

description:
introduced APIs to configure VLAN TAG to ethernet devices

diffstat:

 sys/net/if_ether.h     |    4 +-
 sys/net/if_ethersubr.c |  102 +++++++++++++++++++++++++++++++++++++++++++++-
 sys/net/if_vlan.c      |   93 ++++++++---------------------------------
 sys/net/lagg/if_lagg.c |  107 ++----------------------------------------------
 4 files changed, 128 insertions(+), 178 deletions(-)

diffs (truncated from 411 to 300 lines):

diff -r 606322f2ffb7 -r 0459535d18ab sys/net/if_ether.h
--- a/sys/net/if_ether.h        Mon Nov 15 06:34:05 2021 +0000
+++ b/sys/net/if_ether.h        Mon Nov 15 07:07:05 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ether.h,v 1.87 2021/09/30 03:54:04 yamaguchi Exp $  */
+/*     $NetBSD: if_ether.h,v 1.88 2021/11/15 07:07:05 yamaguchi Exp $  */
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -401,6 +401,8 @@
 int    ether_aton_r(u_char *, size_t, const char *);
 int    ether_enable_vlan_mtu(struct ifnet *);
 int    ether_disable_vlan_mtu(struct ifnet *);
+int    ether_add_vlantag(struct ifnet *, uint16_t, bool *);
+int    ether_del_vlantag(struct ifnet *, uint16_t);
 #else
 /*
  * Prototype ethers(3) functions.
diff -r 606322f2ffb7 -r 0459535d18ab sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c    Mon Nov 15 06:34:05 2021 +0000
+++ b/sys/net/if_ethersubr.c    Mon Nov 15 07:07:05 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ethersubr.c,v 1.303 2021/11/08 16:50:05 christos Exp $      */
+/*     $NetBSD: if_ethersubr.c,v 1.304 2021/11/15 07:07:05 yamaguchi Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.303 2021/11/08 16:50:05 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.304 2021/11/15 07:07:05 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1659,6 +1659,104 @@
        return error;
 }
 
+/*
+ * Add and delete VLAN TAG
+ */
+int
+ether_add_vlantag(struct ifnet *ifp, uint16_t vtag, bool *vlanmtu_status)
+{
+       struct ethercom *ec = (void *)ifp;
+       struct vlanid_list *vidp;
+       bool vlanmtu_enabled;
+       uint16_t vid = EVL_VLANOFTAG(vtag);
+       int error;
+
+       vlanmtu_enabled = false;
+
+       /* Add a vid to the list */
+       vidp = kmem_alloc(sizeof(*vidp), KM_SLEEP);
+       vidp->vid = vid;
+
+       ETHER_LOCK(ec);
+       ec->ec_nvlans++;
+       SIMPLEQ_INSERT_TAIL(&ec->ec_vids, vidp, vid_list);
+       ETHER_UNLOCK(ec);
+
+       if (ec->ec_nvlans == 1) {
+               IFNET_LOCK(ifp);
+               error = ether_enable_vlan_mtu(ifp);
+               IFNET_UNLOCK(ifp);
+
+               if (error == 0) {
+                       vlanmtu_enabled = true;
+               } else if (error != -1) {
+                       goto fail;
+               }
+       }
+
+       if (ec->ec_vlan_cb != NULL) {
+               error = (*ec->ec_vlan_cb)(ec, vid, true);
+               if (error != 0)
+                       goto fail;
+       }
+
+       if (vlanmtu_status != NULL)
+               *vlanmtu_status = vlanmtu_enabled;
+
+       return 0;
+fail:
+       ETHER_LOCK(ec);
+       ec->ec_nvlans--;
+       SIMPLEQ_REMOVE(&ec->ec_vids, vidp, vlanid_list, vid_list);
+       ETHER_UNLOCK(ec);
+
+       if (vlanmtu_enabled) {
+               IFNET_LOCK(ifp);
+               (void)ether_disable_vlan_mtu(ifp);
+               IFNET_UNLOCK(ifp);
+       }
+
+       kmem_free(vidp, sizeof(*vidp));
+
+       return error;
+}
+
+int
+ether_del_vlantag(struct ifnet *ifp, uint16_t vtag)
+{
+       struct ethercom *ec = (void *)ifp;
+       struct vlanid_list *vidp;
+       uint16_t vid = EVL_VLANOFTAG(vtag);
+
+       ETHER_LOCK(ec);
+       SIMPLEQ_FOREACH(vidp, &ec->ec_vids, vid_list) {
+               if (vidp->vid == vid) {
+                       SIMPLEQ_REMOVE(&ec->ec_vids, vidp,
+                           vlanid_list, vid_list);
+                       ec->ec_nvlans--;
+                       break;
+               }
+       }
+       ETHER_UNLOCK(ec);
+
+       if (vidp == NULL)
+               return ENOENT;
+
+       if (ec->ec_vlan_cb != NULL) {
+               (void)(*ec->ec_vlan_cb)(ec, vidp->vid, false);
+       }
+
+       if (ec->ec_nvlans == 0) {
+               IFNET_LOCK(ifp);
+               (void)ether_disable_vlan_mtu(ifp);
+               IFNET_UNLOCK(ifp);
+       }
+
+       kmem_free(vidp, sizeof(*vidp));
+
+       return 0;
+}
+
 static int
 ether_multicast_sysctl(SYSCTLFN_ARGS)
 {
diff -r 606322f2ffb7 -r 0459535d18ab sys/net/if_vlan.c
--- a/sys/net/if_vlan.c Mon Nov 15 06:34:05 2021 +0000
+++ b/sys/net/if_vlan.c Mon Nov 15 07:07:05 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_vlan.c,v 1.164 2021/10/05 04:09:49 yamaguchi Exp $  */
+/*     $NetBSD: if_vlan.c,v 1.165 2021/11/15 07:07:05 yamaguchi Exp $  */
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.164 2021/10/05 04:09:49 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.165 2021/11/15 07:07:05 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -434,57 +434,29 @@
        case IFT_ETHER:
            {
                struct ethercom *ec = (void *)p;
-               struct vlanid_list *vidmem;
+               bool vlanmtu_enabled;
 
                nmib->ifvm_msw = &vlan_ether_multisw;
                nmib->ifvm_encaplen = ETHER_VLAN_ENCAP_LEN;
                nmib->ifvm_mintu = ETHERMIN;
 
-               if (ec->ec_nvlans++ == 0) {
-                       IFNET_LOCK(p);
-                       error = ether_enable_vlan_mtu(p);
-                       IFNET_UNLOCK(p);
-                       if (error >= 0) {
-                               if (error) {
-                                       ec->ec_nvlans--;
-                                       goto done;
-                               }
-                               nmib->ifvm_mtufudge = 0;
-                       } else {
-                               /*
-                                * Fudge the MTU by the encapsulation size. This
-                                * makes us incompatible with strictly compliant
-                                * 802.1Q implementations, but allows us to use
-                                * the feature with other NetBSD
-                                * implementations, which might still be useful.
-                                */
-                               nmib->ifvm_mtufudge = nmib->ifvm_encaplen;
-                       }
-                       error = 0;
+               error = ether_add_vlantag(p, tag, &vlanmtu_enabled);
+               if (error != 0)
+                       goto done;
+
+               if (vlanmtu_enabled) {
+                       nmib->ifvm_mtufudge = 0;
+               } else {
+                       /*
+                        * Fudge the MTU by the encapsulation size. This
+                        * makes us incompatible with strictly compliant
+                        * 802.1Q implementations, but allows us to use
+                        * the feature with other NetBSD
+                        * implementations, which might still be useful.
+                        */
+                       nmib->ifvm_mtufudge = nmib->ifvm_encaplen;
                }
-               /* Add a vid to the list */
-               vidmem = kmem_alloc(sizeof(struct vlanid_list), KM_SLEEP);
-               vidmem->vid = vid;
-               ETHER_LOCK(ec);
-               SIMPLEQ_INSERT_TAIL(&ec->ec_vids, vidmem, vid_list);
-               ETHER_UNLOCK(ec);
 
-               if (ec->ec_vlan_cb != NULL) {
-                       /*
-                        * Call ec_vlan_cb(). It will setup VLAN HW filter or
-                        * HW tagging function.
-                        */
-                       error = (*ec->ec_vlan_cb)(ec, vid, true);
-                       if (error) {
-                               ec->ec_nvlans--;
-                               if (ec->ec_nvlans == 0) {
-                                       IFNET_LOCK(p);
-                                       (void)ether_disable_vlan_mtu(p);
-                                       IFNET_UNLOCK(p);
-                               }
-                               goto done;
-                       }
-               }
                /*
                 * If the parent interface can do hardware-assisted
                 * VLAN encapsulation, then propagate its hardware-
@@ -624,34 +596,7 @@
        switch (p->if_type) {
        case IFT_ETHER:
            {
-               struct ethercom *ec = (void *)p;
-               struct vlanid_list *vlanidp;
-               uint16_t vid = EVL_VLANOFTAG(nmib->ifvm_tag);
-
-               ETHER_LOCK(ec);
-               SIMPLEQ_FOREACH(vlanidp, &ec->ec_vids, vid_list) {
-                       if (vlanidp->vid == vid) {
-                               SIMPLEQ_REMOVE(&ec->ec_vids, vlanidp,
-                                   vlanid_list, vid_list);
-                               break;
-                       }
-               }
-               ETHER_UNLOCK(ec);
-               if (vlanidp != NULL)
-                       kmem_free(vlanidp, sizeof(*vlanidp));
-
-               if (ec->ec_vlan_cb != NULL) {
-                       /*
-                        * Call ec_vlan_cb(). It will setup VLAN HW filter or
-                        * HW tagging function.
-                        */
-                       (void)(*ec->ec_vlan_cb)(ec, vid, false);
-               }
-               if (--ec->ec_nvlans == 0) {
-                       IFNET_LOCK(p);
-                       (void)ether_disable_vlan_mtu(p);
-                       IFNET_UNLOCK(p);
-               }
+               (void)ether_del_vlantag(p, nmib->ifvm_tag);
 
                /* XXX ether_ifdetach must not be called with IFNET_LOCK */
                ifv->ifv_stopping = true;
diff -r 606322f2ffb7 -r 0459535d18ab sys/net/lagg/if_lagg.c
--- a/sys/net/lagg/if_lagg.c    Mon Nov 15 06:34:05 2021 +0000
+++ b/sys/net/lagg/if_lagg.c    Mon Nov 15 07:07:05 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_lagg.c,v 1.25 2021/11/12 05:56:54 yamaguchi Exp $   */
+/*     $NetBSD: if_lagg.c,v 1.26 2021/11/15 07:07:05 yamaguchi Exp $   */
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter <reyk%openbsd.org@localhost>
@@ -20,7 +20,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.25 2021/11/12 05:56:54 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.26 2021/11/15 07:07:05 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1198,106 +1198,10 @@
 }
 
 static int
-lagg_register_vid(struct ethercom *ec, uint16_t vid)
-{
-       struct ifnet *ifp;
-       struct vlanid_list *vidmem;
-       bool vlanmtu_enabled;
-       int error;
-
-       ifp = (struct ifnet *)ec;
-       vlanmtu_enabled = false;



Home | Main Index | Thread Index | Old Index