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