Module Name: src
Committed By: roy
Date: Tue Jun 27 12:17:27 UTC 2017
Modified Files:
src/sys/net: if.c if.h
Log Message:
Introduce if_get_bylla to find an interface with the active
local link address.
To generate a diff of this commit:
cvs rdiff -u -r1.394 -r1.395 src/sys/net/if.c
cvs rdiff -u -r1.239 -r1.240 src/sys/net/if.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.394 src/sys/net/if.c:1.395
--- src/sys/net/if.c:1.394 Thu Jun 1 02:45:14 2017
+++ src/sys/net/if.c Tue Jun 27 12:17:27 2017
@@ -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 @@ out:
}
/*
- * 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 @@ if_get_byindex(u_int idx, struct psref *
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
Index: src/sys/net/if.h
diff -u src/sys/net/if.h:1.239 src/sys/net/if.h:1.240
--- src/sys/net/if.h:1.239 Fri May 19 08:53:51 2017
+++ src/sys/net/if.h Tue Jun 27 12:17:27 2017
@@ -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 *ifunit(const char *);
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