Add helper function similar to ip_dev_find() to the LinuxKPI to lookup

a network device by its IPv6 address in the given VNET.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
This commit is contained in:
Hans Petter Selasky 2017-03-16 10:02:45 +00:00
parent 404027276b
commit 8300fb13dd

View File

@ -2,7 +2,7 @@
* Copyright (c) 2010 Isilon Systems, Inc.
* Copyright (c) 2010 iX Systems, Inc.
* Copyright (c) 2010 Panasas, Inc.
* Copyright (c) 2013 Mellanox Technologies, Ltd.
* Copyright (c) 2013-2017 Mellanox Technologies, Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -57,4 +57,28 @@ ip_dev_find(struct vnet *vnet, uint32_t addr)
return (ifp);
}
static inline struct net_device *
ip6_dev_find(struct vnet *vnet, struct in6_addr addr)
{
struct sockaddr_in6 sin6;
struct ifaddr *ifa;
struct ifnet *ifp;
memset(&sin6, 0, sizeof(sin6));
sin6.sin6_addr = addr;
sin6.sin6_len = sizeof(sin6);
sin6.sin6_family = AF_INET6;
CURVNET_SET_QUIET(vnet);
ifa = ifa_ifwithaddr((struct sockaddr *)&sin6);
CURVNET_RESTORE();
if (ifa) {
ifp = ifa->ifa_ifp;
if_ref(ifp);
ifa_free(ifa);
} else {
ifp = NULL;
}
return (ifp);
}
#endif /* _LINUX_INETDEVICE_H_ */