Source-Changes-HG archive

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

[src/trunk]: src/sys/net Introduce if_get_bylla to find an interface with the...



details:   https://anonhg.NetBSD.org/src/rev/ae45a9666e8e
branches:  trunk
changeset: 354740:ae45a9666e8e
user:      roy <roy%NetBSD.org@localhost>
date:      Tue Jun 27 12:17:27 2017 +0000

description:
Introduce if_get_bylla to find an interface with the active
local link address.

diffstat:

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

diffs (76 lines):

diff -r a46b69bd77a0 -r ae45a9666e8e sys/net/if.c
--- a/sys/net/if.c      Tue Jun 27 11:55:07 2017 +0000
+++ b/sys/net/if.c      Tue Jun 27 12:17:27 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.394 2017/06/01 02:45:14 chs Exp $     */
+/*     $NetBSD: if.c,v 1.395 2017/06/27 12:17:27 roy 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.394 2017/06/01 02:45:14 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.395 2017/06/27 12:17:27 roy Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2599,8 +2599,8 @@
 }
 
 /*
- * Release a reference of an ifnet object given by if_get or
- * if_get_byindex.
+ * Release a reference of an ifnet object given by if_get, if_get_byindex
+ * or if_get_bylla.
  */
 void
 if_put(const struct ifnet *ifp, struct psref *psref)
@@ -2643,6 +2643,29 @@
        return ifp;
 }
 
+ifnet_t *
+if_get_bylla(const void *lla, unsigned char lla_len, struct psref *psref)
+{
+       ifnet_t *ifp;
+       int s;
+
+       s = pserialize_read_enter();
+       IFNET_READER_FOREACH(ifp) {
+               if (if_is_deactivated(ifp))
+                       continue;
+               if (ifp->if_addrlen != lla_len)
+                       continue;
+               if (memcmp(lla, CLLADDR(ifp->if_sadl), lla_len) == 0) {
+                       psref_acquire(psref, &ifp->if_psref,
+                           ifnet_psref_class);
+                       break;
+               }
+       }
+       pserialize_read_exit(s);
+
+       return ifp;
+}
+
 /*
  * Note that it's safe only if the passed ifp is guaranteed to not be freed,
  * for example using pserialize or the ifp is already held or some other
diff -r a46b69bd77a0 -r ae45a9666e8e sys/net/if.h
--- a/sys/net/if.h      Tue Jun 27 11:55:07 2017 +0000
+++ b/sys/net/if.h      Tue Jun 27 12:17:27 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.h,v 1.239 2017/05/19 08:53:51 ozaki-r Exp $ */
+/*     $NetBSD: if.h,v 1.240 2017/06/27 12:17:27 roy Exp $     */
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -974,6 +974,7 @@
 struct ifnet *if_get(const char *, struct psref *);
 ifnet_t *if_byindex(u_int);
 ifnet_t *if_get_byindex(u_int, struct psref *);
+ifnet_t *if_get_bylla(const void *, unsigned char, struct psref *);
 void   if_put(const struct ifnet *, struct psref *);
 void   if_acquire(struct ifnet *, struct psref *);
 #define        if_release      if_put



Home | Main Index | Thread Index | Old Index