Path: blob/main/sys/ofed/include/rdma/ib_addr_freebsd.h
39482 views
/*-1* Copyright (c) 2010 Isilon Systems, Inc.2* Copyright (c) 2010 iX Systems, Inc.3* Copyright (c) 2010 Panasas, Inc.4* Copyright (c) 2013-2017 Mellanox Technologies, Ltd.5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice unmodified, this list of conditions, and the following12* disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in the15* documentation and/or other materials provided with the distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR18* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES19* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.20* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,21* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT22* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF26* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27*/28#ifndef _RDMA_IB_ADDR_FREEBSD_H29#define _RDMA_IB_ADDR_FREEBSD_H3031#ifdef INET32static inline if_t33ip_ifp_find(struct vnet *vnet, uint32_t addr)34{35struct sockaddr_in sin;36struct epoch_tracker et;37struct ifaddr *ifa;38if_t ifp;3940memset(&sin, 0, sizeof(sin));41sin.sin_addr.s_addr = addr;42sin.sin_len = sizeof(sin);43sin.sin_family = AF_INET;44NET_EPOCH_ENTER(et);45CURVNET_SET_QUIET(vnet);46ifa = ifa_ifwithaddr((struct sockaddr *)&sin);47CURVNET_RESTORE();48if (ifa) {49ifp = ifa->ifa_ifp;50if_ref(ifp);51} else {52ifp = NULL;53}54NET_EPOCH_EXIT(et);55return (ifp);56}57#endif5859#ifdef INET660static inline if_t61ip6_ifp_find(struct vnet *vnet, struct in6_addr addr, uint16_t scope_id)62{63struct sockaddr_in6 sin6;64struct epoch_tracker et;65struct ifaddr *ifa;66if_t ifp;6768memset(&sin6, 0, sizeof(sin6));69sin6.sin6_addr = addr;70sin6.sin6_len = sizeof(sin6);71sin6.sin6_family = AF_INET6;72if (IN6_IS_SCOPE_LINKLOCAL(&addr) ||73IN6_IS_ADDR_MC_INTFACELOCAL(&addr)) {74/* embed the IPv6 scope ID */75sin6.sin6_addr.s6_addr16[1] = htons(scope_id);76}77NET_EPOCH_ENTER(et);78CURVNET_SET_QUIET(vnet);79ifa = ifa_ifwithaddr((struct sockaddr *)&sin6);80CURVNET_RESTORE();81if (ifa != NULL) {82ifp = ifa->ifa_ifp;83if_ref(ifp);84} else {85ifp = NULL;86}87NET_EPOCH_EXIT(et);88return (ifp);89}90#endif9192static inline if_t93dev_get_by_index(struct vnet *vnet, int if_index)94{95struct epoch_tracker et;96if_t retval;9798NET_EPOCH_ENTER(et);99CURVNET_SET(vnet);100retval = ifnet_byindex_ref(if_index);101CURVNET_RESTORE();102NET_EPOCH_EXIT(et);103104return (retval);105}106107#endif /* _RDMA_IB_ADDR_FREEBSD_H */108109110