From c42bebbdd1ab596db6ade9bd27589b0045d0a4d1 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Thu, 8 Aug 2019 17:38:21 +0100 Subject: [PATCH] net/if: introduce if_bylla to find an interface by hardware address --- sys/net/if.c | 25 +++++++++++++++++++++++++ sys/net/if_var.h | 1 + 2 files changed, 26 insertions(+) diff --git a/sys/net/if.c b/sys/net/if.c index be6670c63a..d82d23f620 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -2815,6 +2815,31 @@ if_setlladdr(struct ifnet *ifp, const u_char *lladdr, int len) return (0); } + +/* + * Locate an interface based on a complete address. + */ +struct ifnet * +if_bylla(const void *lla, unsigned char lla_len) +{ + const struct ifnet_array *arr; + struct ifnet *ifp; + struct sockaddr_dl *sdl; + int i; + + arr = ifnet_array_get(); + for (i = 0; i < arr->ifnet_count; ++i) { + ifp = arr->ifnet_arr[i]; + if (ifp->if_addrlen != lla_len) + continue; + + sdl = IF_LLSOCKADDR(ifp); + if (memcmp(lla, LLADDR(sdl), lla_len) == 0) + return (ifp); + } + return (NULL); +} + struct ifmultiaddr * ifmaof_ifpforaddr(struct sockaddr *sa, struct ifnet *ifp) { diff --git a/sys/net/if_var.h b/sys/net/if_var.h index 4e2c7ca14d..1f26883568 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -945,6 +945,7 @@ struct ifnet *if_alloc(uint8_t); void if_free(struct ifnet *); void if_route(struct ifnet *, int flag, int fam); int if_setlladdr(struct ifnet *, const u_char *, int); +struct ifnet *if_bylla(const void *, unsigned char); void if_unroute(struct ifnet *, int flag, int fam); void if_up(struct ifnet *); /*void ifinit(void);*/ /* declared in systm.h for main() */ -- 2.41.0