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 at change of link state



details:   https://anonhg.NetBSD.org/src/rev/568cee0c694b
branches:  trunk
changeset: 1023867:568cee0c694b
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Thu Sep 30 03:23:48 2021 +0000

description:
Provide a hook point called at change of link state

diffstat:

 sys/net/if.c |  31 +++++++++++++++++++++++++++++--
 sys/net/if.h |   9 ++++++++-
 2 files changed, 37 insertions(+), 3 deletions(-)

diffs (119 lines):

diff -r a5f9ea23a9de -r 568cee0c694b sys/net/if.c
--- a/sys/net/if.c      Thu Sep 30 03:15:25 2021 +0000
+++ b/sys/net/if.c      Thu Sep 30 03:23:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.491 2021/09/30 03:15:25 yamaguchi Exp $       */
+/*     $NetBSD: if.c,v 1.492 2021/09/30 03:23:48 yamaguchi 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.491 2021/09/30 03:15:25 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.492 2021/09/30 03:23:48 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -122,6 +122,7 @@
 #include <sys/module_hook.h>
 #include <sys/compat_stub.h>
 #include <sys/msan.h>
+#include <sys/hook.h>
 
 #include <net/if.h>
 #include <net/if_dl.h>
@@ -631,8 +632,13 @@
 if_getindex(ifnet_t *ifp)
 {
        bool hitlimit = false;
+       char xnamebuf[HOOKNAMSIZ];
 
        ifp->if_index_gen = index_gen++;
+       snprintf(xnamebuf, sizeof(xnamebuf),
+           "%s-lshk", ifp->if_xname);
+       ifp->if_linkstate_hooks = simplehook_create(IPL_NET,
+           xnamebuf);
 
        ifp->if_index = if_index;
        if (ifindex2ifnet == NULL) {
@@ -1533,6 +1539,8 @@
        ifp->if_ioctl_lock = NULL;
        mutex_obj_free(ifp->if_snd.ifq_lock);
        if_stats_fini(ifp);
+       KASSERT(!simplehook_has_hooks(ifp->if_linkstate_hooks));
+       simplehook_destroy(ifp->if_linkstate_hooks);
 
        splx(s);
 
@@ -2412,6 +2420,8 @@
                lagg_linkstate_changed(ifp);
 #endif
 
+       simplehook_dohooks(ifp->if_linkstate_hooks);
+
        DOMAIN_FOREACH(dp) {
                if (dp->dom_if_link_state_change != NULL)
                        dp->dom_if_link_state_change(ifp, link_state);
@@ -2459,6 +2469,23 @@
        KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
+void *
+if_linkstate_change_establish(struct ifnet *ifp, void (*fn)(void *), void *arg)
+{
+       khook_t *hk;
+
+       hk = simplehook_establish(ifp->if_linkstate_hooks, fn, arg);
+
+       return (void *)hk;
+}
+
+void
+if_linkstate_change_disestablish(struct ifnet *ifp, void *vhook, kmutex_t *lock)
+{
+
+       simplehook_disestablish(ifp->if_linkstate_hooks, vhook, lock);
+}
+
 /*
  * Used to mark addresses on an interface as DETATCHED or TENTATIVE
  * and thus start Duplicate Address Detection without changing the
diff -r a5f9ea23a9de -r 568cee0c694b sys/net/if.h
--- a/sys/net/if.h      Thu Sep 30 03:15:25 2021 +0000
+++ b/sys/net/if.h      Thu Sep 30 03:23:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.h,v 1.293 2021/09/30 03:15:25 yamaguchi Exp $       */
+/*     $NetBSD: if.h,v 1.294 2021/09/30 03:23:48 yamaguchi Exp $       */
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -85,6 +85,7 @@
 #include <sys/socket.h>
 #include <sys/queue.h>
 #include <sys/mutex.h>
+#include <sys/hook.h>
 
 #include <net/dlt.h>
 #include <net/pfil.h>
@@ -432,6 +433,7 @@
        /* XXX should be protocol independent */
        LIST_HEAD(, in6_multi)
                        if_multiaddrs;  /* 6: */
+       khook_list_t    *if_linkstate_hooks;    /* :: */
 #endif
 } ifnet_t;
 
@@ -1243,6 +1245,11 @@
 int    looutput(struct ifnet *,
           struct mbuf *, const struct sockaddr *, const struct rtentry *);
 
+void * if_linkstate_change_establish(struct ifnet *,
+           void (*)(void *), void *);
+void   if_linkstate_change_disestablish(struct ifnet *,
+           void *, kmutex_t *);
+
 /*
  * These are exported because they're an easy way to tell if
  * an interface is going away without having to burn a flag.



Home | Main Index | Thread Index | Old Index