1*42e22086SApple OSS Distributions /* 2*42e22086SApple OSS Distributions * Copyright (c) 2011-2020 Apple Inc. All rights reserved. 3*42e22086SApple OSS Distributions * 4*42e22086SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*42e22086SApple OSS Distributions * 6*42e22086SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*42e22086SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*42e22086SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*42e22086SApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*42e22086SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*42e22086SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*42e22086SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*42e22086SApple OSS Distributions * terms of an Apple operating system software license agreement. 14*42e22086SApple OSS Distributions * 15*42e22086SApple OSS Distributions * Please obtain a copy of the License at 16*42e22086SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*42e22086SApple OSS Distributions * 18*42e22086SApple OSS Distributions * The Original Code and all software distributed under the License are 19*42e22086SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*42e22086SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*42e22086SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*42e22086SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*42e22086SApple OSS Distributions * Please see the License for the specific language governing rights and 24*42e22086SApple OSS Distributions * limitations under the License. 25*42e22086SApple OSS Distributions * 26*42e22086SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*42e22086SApple OSS Distributions */ 28*42e22086SApple OSS Distributions 29*42e22086SApple OSS Distributions #ifndef _NET_IF_LLREACH_H_ 30*42e22086SApple OSS Distributions #define _NET_IF_LLREACH_H_ 31*42e22086SApple OSS Distributions 32*42e22086SApple OSS Distributions #ifdef PRIVATE 33*42e22086SApple OSS Distributions #ifdef __cplusplus 34*42e22086SApple OSS Distributions extern "C" { 35*42e22086SApple OSS Distributions #endif 36*42e22086SApple OSS Distributions 37*42e22086SApple OSS Distributions #include <sys/types.h> 38*42e22086SApple OSS Distributions 39*42e22086SApple OSS Distributions /* 40*42e22086SApple OSS Distributions * Per-interface link-layer reachability information (private). 41*42e22086SApple OSS Distributions */ 42*42e22086SApple OSS Distributions #define IF_LLREACHINFO_ADDRLEN 64 /* max ll addr len */ 43*42e22086SApple OSS Distributions #define IF_LLREACHINFO_RESERVED2 16 /* more reserved bits */ 44*42e22086SApple OSS Distributions 45*42e22086SApple OSS Distributions struct if_llreach_info { 46*42e22086SApple OSS Distributions u_int32_t lri_refcnt; /* reference count */ 47*42e22086SApple OSS Distributions u_int32_t lri_ifindex; /* interface index */ 48*42e22086SApple OSS Distributions u_int64_t lri_expire; /* expiration (calendar) time */ 49*42e22086SApple OSS Distributions u_int32_t lri_probes; /* total # of probes */ 50*42e22086SApple OSS Distributions u_int16_t lri_reserved; /* for future use */ 51*42e22086SApple OSS Distributions u_int16_t lri_proto; /* ll proto */ 52*42e22086SApple OSS Distributions u_int8_t lri_addr[IF_LLREACHINFO_ADDRLEN]; /* ll addr */ 53*42e22086SApple OSS Distributions int32_t lri_rssi; /* received signal strength */ 54*42e22086SApple OSS Distributions int32_t lri_lqm; /* link quality metric */ 55*42e22086SApple OSS Distributions int32_t lri_npm; /* node proximity metric */ 56*42e22086SApple OSS Distributions u_int8_t lri_reserved2[IF_LLREACHINFO_RESERVED2]; 57*42e22086SApple OSS Distributions }; 58*42e22086SApple OSS Distributions 59*42e22086SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE 60*42e22086SApple OSS Distributions #include <sys/tree.h> 61*42e22086SApple OSS Distributions #include <kern/locks.h> 62*42e22086SApple OSS Distributions #include <net/ethernet.h> 63*42e22086SApple OSS Distributions #include <netinet/in.h> 64*42e22086SApple OSS Distributions #include <netinet6/in6_var.h> 65*42e22086SApple OSS Distributions #include <netinet6/nd6.h> 66*42e22086SApple OSS Distributions 67*42e22086SApple OSS Distributions /* 68*42e22086SApple OSS Distributions * Per-interface link-layer reachability. (Currently only for ARP/NDP/Ethernet.) 69*42e22086SApple OSS Distributions */ 70*42e22086SApple OSS Distributions #define IF_LLREACH_MAXLEN ETHER_ADDR_LEN 71*42e22086SApple OSS Distributions 72*42e22086SApple OSS Distributions struct if_llreach { 73*42e22086SApple OSS Distributions decl_lck_mtx_data(, lr_lock); 74*42e22086SApple OSS Distributions RB_ENTRY(if_llreach) lr_link; /* RB tree links */ 75*42e22086SApple OSS Distributions struct ifnet *lr_ifp; /* back pointer to ifnet */ 76*42e22086SApple OSS Distributions u_int32_t lr_refcnt; /* reference count */ 77*42e22086SApple OSS Distributions u_int32_t lr_reqcnt; /* RB tree request count */ 78*42e22086SApple OSS Distributions u_int32_t lr_debug; /* see ifa_debug flags */ 79*42e22086SApple OSS Distributions u_int32_t lr_probes; /* number of probes so far */ 80*42e22086SApple OSS Distributions u_int64_t lr_basecal; /* base calendar time */ 81*42e22086SApple OSS Distributions u_int64_t lr_baseup; /* base uptime */ 82*42e22086SApple OSS Distributions u_int64_t lr_lastrcvd; /* last-heard-of timestamp */ 83*42e22086SApple OSS Distributions u_int32_t lr_basereachable; /* baseline time */ 84*42e22086SApple OSS Distributions u_int32_t lr_reachable; /* reachable time */ 85*42e22086SApple OSS Distributions struct lr_key_s { 86*42e22086SApple OSS Distributions u_int16_t proto; /* ll proto */ 87*42e22086SApple OSS Distributions u_int8_t addr[IF_LLREACH_MAXLEN]; /* ll addr */ 88*42e22086SApple OSS Distributions } lr_key; 89*42e22086SApple OSS Distributions int32_t lr_rssi; /* received signal strength */ 90*42e22086SApple OSS Distributions int32_t lr_lqm; /* link quality metric */ 91*42e22086SApple OSS Distributions int32_t lr_npm; /* node proximity metric */ 92*42e22086SApple OSS Distributions }; 93*42e22086SApple OSS Distributions 94*42e22086SApple OSS Distributions RB_PROTOTYPE_SC_PREV(__private_extern__, ll_reach_tree, if_llreach, 95*42e22086SApple OSS Distributions ls_link, ifllr_cmp); 96*42e22086SApple OSS Distributions 97*42e22086SApple OSS Distributions #define IFLR_LOCK_ASSERT_HELD(_iflr) \ 98*42e22086SApple OSS Distributions LCK_MTX_ASSERT(&(_iflr)->lr_lock, LCK_MTX_ASSERT_OWNED) 99*42e22086SApple OSS Distributions 100*42e22086SApple OSS Distributions #define IFLR_LOCK_ASSERT_NOTHELD(_iflr) \ 101*42e22086SApple OSS Distributions LCK_MTX_ASSERT(&(_iflr)->lr_lock, LCK_MTX_ASSERT_NOTOWNED) 102*42e22086SApple OSS Distributions 103*42e22086SApple OSS Distributions #define IFLR_LOCK(_iflr) \ 104*42e22086SApple OSS Distributions lck_mtx_lock(&(_iflr)->lr_lock) 105*42e22086SApple OSS Distributions 106*42e22086SApple OSS Distributions #define IFLR_LOCK_SPIN(_iflr) \ 107*42e22086SApple OSS Distributions lck_mtx_lock_spin(&(_iflr)->lr_lock) 108*42e22086SApple OSS Distributions 109*42e22086SApple OSS Distributions #define IFLR_CONVERT_LOCK(_iflr) do { \ 110*42e22086SApple OSS Distributions IFLR_LOCK_ASSERT_HELD(_iflr); \ 111*42e22086SApple OSS Distributions lck_mtx_convert_spin(&(_iflr)->lr_lock); \ 112*42e22086SApple OSS Distributions } while (0) 113*42e22086SApple OSS Distributions 114*42e22086SApple OSS Distributions #define IFLR_UNLOCK(_iflr) \ 115*42e22086SApple OSS Distributions lck_mtx_unlock(&(_iflr)->lr_lock) 116*42e22086SApple OSS Distributions 117*42e22086SApple OSS Distributions #define IFLR_ADDREF(_iflr) \ 118*42e22086SApple OSS Distributions iflr_addref(_iflr, 0) 119*42e22086SApple OSS Distributions 120*42e22086SApple OSS Distributions #define IFLR_ADDREF_LOCKED(_iflr) \ 121*42e22086SApple OSS Distributions iflr_addref(_iflr, 1) 122*42e22086SApple OSS Distributions 123*42e22086SApple OSS Distributions #define IFLR_REMREF(_iflr) \ 124*42e22086SApple OSS Distributions iflr_remref(_iflr) 125*42e22086SApple OSS Distributions 126*42e22086SApple OSS Distributions struct ifnet_llreach_info; /* forward declaration */ 127*42e22086SApple OSS Distributions 128*42e22086SApple OSS Distributions extern void ifnet_llreach_ifattach(struct ifnet *, boolean_t); 129*42e22086SApple OSS Distributions extern void ifnet_llreach_ifdetach(struct ifnet *); 130*42e22086SApple OSS Distributions extern struct if_llreach *ifnet_llreach_alloc(struct ifnet *, u_int16_t, void *, 131*42e22086SApple OSS Distributions unsigned int, u_int32_t); 132*42e22086SApple OSS Distributions extern void ifnet_llreach_free(struct if_llreach *); 133*42e22086SApple OSS Distributions extern int ifnet_llreach_reachable(struct if_llreach *); 134*42e22086SApple OSS Distributions extern int ifnet_llreach_reachable_delta(struct if_llreach *, u_int64_t); 135*42e22086SApple OSS Distributions extern void ifnet_llreach_set_reachable(struct ifnet *, u_int16_t, void *, 136*42e22086SApple OSS Distributions unsigned int); 137*42e22086SApple OSS Distributions extern u_int64_t ifnet_llreach_up2calexp(struct if_llreach *, u_int64_t); 138*42e22086SApple OSS Distributions extern u_int64_t ifnet_llreach_up2upexp(struct if_llreach *, u_int64_t); 139*42e22086SApple OSS Distributions extern int ifnet_llreach_get_defrouter(struct ifnet *, sa_family_t, 140*42e22086SApple OSS Distributions struct ifnet_llreach_info *); 141*42e22086SApple OSS Distributions extern void ifnet_lr2ri(struct if_llreach *, struct rt_reach_info *); 142*42e22086SApple OSS Distributions extern void ifnet_lr2iflri(struct if_llreach *, struct ifnet_llreach_info *); 143*42e22086SApple OSS Distributions extern void ifnet_lr2lri(struct if_llreach *, struct if_llreach_info *); 144*42e22086SApple OSS Distributions extern void iflr_addref(struct if_llreach *, int); 145*42e22086SApple OSS Distributions extern void iflr_remref(struct if_llreach *); 146*42e22086SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */ 147*42e22086SApple OSS Distributions 148*42e22086SApple OSS Distributions #ifdef __cplusplus 149*42e22086SApple OSS Distributions } 150*42e22086SApple OSS Distributions #endif 151*42e22086SApple OSS Distributions #endif /* PRIVATE */ 152*42e22086SApple OSS Distributions #endif /* !_NET_IF_LLREACH_H_ */ 153