Source-Changes-HG archive

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

[src/trunk]: src/sys/net Provide a hook point called when ether_ifdetach is c...



details:   https://anonhg.NetBSD.org/src/rev/3605dabe9718
branches:  trunk
changeset: 987510:3605dabe9718
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Thu Sep 30 03:54:04 2021 +0000

description:
Provide a hook point called when ether_ifdetach is called

diffstat:

 sys/net/if_ether.h     |   8 +++++++-
 sys/net/if_ethersubr.c |  43 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 48 insertions(+), 3 deletions(-)

diffs (121 lines):

diff -r c5f0127e8402 -r 3605dabe9718 sys/net/if_ether.h
--- a/sys/net/if_ether.h        Thu Sep 30 03:51:05 2021 +0000
+++ b/sys/net/if_ether.h        Thu Sep 30 03:54:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ether.h,v 1.86 2021/02/14 19:35:37 roy Exp $        */
+/*     $NetBSD: if_ether.h,v 1.87 2021/09/30 03:54:04 yamaguchi Exp $  */
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -198,6 +198,8 @@
         * being added or removed.
         */
        ether_vlancb_t                          ec_vlan_cb;
+       /* Hooks called at the beginning of detach of this interface */
+       khook_list_t                            *ec_ifdetach_hooks;
        kmutex_t                                *ec_lock;
        /* Flags used only by the kernel */
        int                                     ec_flags;
@@ -385,6 +387,10 @@
 void   ether_ifdetach(struct ifnet *);
 int    ether_mediachange(struct ifnet *);
 void   ether_mediastatus(struct ifnet *, struct ifmediareq *);
+void * ether_ifdetachhook_establish(struct ifnet *,
+           void (*)(void *), void *arg);
+void   ether_ifdetachhook_disestablish(struct ifnet *,
+           void *, kmutex_t *);
 
 char   *ether_sprintf(const uint8_t *);
 char   *ether_snprintf(char *, size_t, const uint8_t *);
diff -r c5f0127e8402 -r 3605dabe9718 sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c    Thu Sep 30 03:51:05 2021 +0000
+++ b/sys/net/if_ethersubr.c    Thu Sep 30 03:54:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ethersubr.c,v 1.296 2021/09/30 03:51:05 yamaguchi Exp $     */
+/*     $NetBSD: if_ethersubr.c,v 1.297 2021/09/30 03:54:04 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.296 2021/09/30 03:51:05 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.297 2021/09/30 03:54:04 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -90,6 +90,7 @@
 #include <sys/rndsource.h>
 #include <sys/cpu.h>
 #include <sys/kmem.h>
+#include <sys/hook.h>
 
 #include <net/if.h>
 #include <net/netisr.h>
@@ -1012,6 +1013,7 @@
 ether_ifattach(struct ifnet *ifp, const uint8_t *lla)
 {
        struct ethercom *ec = (struct ethercom *)ifp;
+       char xnamebuf[HOOKNAMSIZ];
 
        ifp->if_type = IFT_ETHER;
        ifp->if_hdrlen = ETHER_HDR_LEN;
@@ -1031,6 +1033,9 @@
        ec->ec_flags = 0;
        ifp->if_broadcastaddr = etherbroadcastaddr;
        bpf_attach(ifp, DLT_EN10MB, sizeof(struct ether_header));
+       snprintf(xnamebuf, sizeof(xnamebuf),
+           "%s-ether_ifdetachhooks", ifp->if_xname);
+       ec->ec_ifdetach_hooks = simplehook_create(IPL_NET, xnamebuf);
 #ifdef MBUFTRACE
        mowner_init_owner(&ec->ec_tx_mowner, ifp->if_xname, "tx");
        mowner_init_owner(&ec->ec_rx_mowner, ifp->if_xname, "rx");
@@ -1057,6 +1062,10 @@
        ifp->if_ioctl = __FPTRCAST(int (*)(struct ifnet *, u_long, void *),
            enxio);
 
+       simplehook_dohooks(ec->ec_ifdetach_hooks);
+       KASSERT(!simplehook_has_hooks(ec->ec_ifdetach_hooks));
+       simplehook_destroy(ec->ec_ifdetach_hooks);
+
 #if NBRIDGE > 0
        if (ifp->if_bridge)
                bridge_ifdetach(ifp);
@@ -1089,6 +1098,36 @@
        MOWNER_DETACH(&ec->ec_tx_mowner);
 }
 
+void *
+ether_ifdetachhook_establish(struct ifnet *ifp,
+    void (*fn)(void *), void *arg)
+{
+       struct ethercom *ec;
+       khook_t *hk;
+
+       if (ifp->if_type != IFT_ETHER)
+               return NULL;
+
+       ec = (struct ethercom *)ifp;
+       hk = simplehook_establish(ec->ec_ifdetach_hooks,
+           fn, arg);
+
+       return (void *)hk;
+}
+
+void
+ether_ifdetachhook_disestablish(struct ifnet *ifp,
+    void *vhook, kmutex_t *lock)
+{
+       struct ethercom *ec;
+
+       if (vhook == NULL)
+               return;
+
+       ec = (struct ethercom *)ifp;
+       simplehook_disestablish(ec->ec_ifdetach_hooks, vhook, lock);
+}
+
 #if 0
 /*
  * This is for reference.  We have a table-driven version



Home | Main Index | Thread Index | Old Index