15115240jeff/*-
25115240jeff * Copyright (c) 2010 Isilon Systems, Inc.
35115240jeff * Copyright (c) 2010 iX Systems, Inc.
45115240jeff * Copyright (c) 2010 Panasas, Inc.
582b7572hselasky * Copyright (c) 2013-2017 Mellanox Technologies, Ltd.
65115240jeff * All rights reserved.
75115240jeff *
85115240jeff * Redistribution and use in source and binary forms, with or without
95115240jeff * modification, are permitted provided that the following conditions
105115240jeff * are met:
115115240jeff * 1. Redistributions of source code must retain the above copyright
125115240jeff *    notice unmodified, this list of conditions, and the following
135115240jeff *    disclaimer.
145115240jeff * 2. Redistributions in binary form must reproduce the above copyright
155115240jeff *    notice, this list of conditions and the following disclaimer in the
165115240jeff *    documentation and/or other materials provided with the distribution.
175115240jeff *
185115240jeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
195115240jeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
205115240jeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
215115240jeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
225115240jeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
235115240jeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
245115240jeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
255115240jeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
265115240jeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
275115240jeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28623abddhselasky *
29623abddhselasky * $FreeBSD$
305115240jeff */
315115240jeff#ifndef	_LINUX_INETDEVICE_H_
325115240jeff#define	_LINUX_INETDEVICE_H_
335115240jeff
345115240jeff#include <linux/netdevice.h>
355115240jeff
365115240jeffstatic inline struct net_device *
37f9c6d3fhselaskyip_dev_find(struct vnet *vnet, uint32_t addr)
385115240jeff{
395115240jeff	struct sockaddr_in sin;
406d8cc19glebius	struct epoch_tracker et;
415115240jeff	struct ifaddr *ifa;
425115240jeff	struct ifnet *ifp;
435115240jeff
445115240jeff	memset(&sin, 0, sizeof(sin));
455115240jeff	sin.sin_addr.s_addr = addr;
465115240jeff	sin.sin_len = sizeof(sin);
475115240jeff	sin.sin_family = AF_INET;
486d8cc19glebius	NET_EPOCH_ENTER(et);
49f9c6d3fhselasky	CURVNET_SET_QUIET(vnet);
505115240jeff	ifa = ifa_ifwithaddr((struct sockaddr *)&sin);
51f9c6d3fhselasky	CURVNET_RESTORE();
525115240jeff	if (ifa) {
535115240jeff		ifp = ifa->ifa_ifp;
545115240jeff		if_ref(ifp);
55f9c6d3fhselasky	} else {
56f9c6d3fhselasky		ifp = NULL;
575115240jeff	}
586d8cc19glebius	NET_EPOCH_EXIT(et);
595115240jeff	return (ifp);
605115240jeff}
615115240jeff
6282b7572hselaskystatic inline struct net_device *
635413daaslavaship6_dev_find(struct vnet *vnet, struct in6_addr addr, uint16_t scope_id)
6482b7572hselasky{
6582b7572hselasky	struct sockaddr_in6 sin6;
666d8cc19glebius	struct epoch_tracker et;
675413daaslavash	struct ifaddr *ifa;
685413daaslavash	struct ifnet *ifp;
6982b7572hselasky
7082b7572hselasky	memset(&sin6, 0, sizeof(sin6));
7182b7572hselasky	sin6.sin6_addr = addr;
7282b7572hselasky	sin6.sin6_len = sizeof(sin6);
7382b7572hselasky	sin6.sin6_family = AF_INET6;
745bc2b51hselasky	if (IN6_IS_SCOPE_LINKLOCAL(&addr) ||
755bc2b51hselasky	    IN6_IS_ADDR_MC_INTFACELOCAL(&addr)) {
765413daaslavash		/* embed the IPv6 scope ID */
775413daaslavash		sin6.sin6_addr.s6_addr16[1] = htons(scope_id);
785bc2b51hselasky	}
796d8cc19glebius	NET_EPOCH_ENTER(et);
805413daaslavash	CURVNET_SET_QUIET(vnet);
815413daaslavash	ifa = ifa_ifwithaddr((struct sockaddr *)&sin6);
825413daaslavash	CURVNET_RESTORE();
835bc2b51hselasky	if (ifa != NULL) {
845bc2b51hselasky		ifp = ifa->ifa_ifp;
855bc2b51hselasky		if_ref(ifp);
865413daaslavash	} else {
875413daaslavash		ifp = NULL;
8882b7572hselasky	}
896d8cc19glebius	NET_EPOCH_EXIT(et);
9082b7572hselasky	return (ifp);
9182b7572hselasky}
9282b7572hselasky
935115240jeff#endif	/* _LINUX_INETDEVICE_H_ */
94