puname: do not support modifying arbitrary processes
[unleashed.git] / include / inet / ip_ire.h
blob00062dd1e0b819f1b14a1b66df7acad467c50063
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
24 /* Copyright (c) 1990 Mentat Inc. */
26 #ifndef _INET_IP_IRE_H
27 #define _INET_IP_IRE_H
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
33 #define IPV6_LL_PREFIXLEN 10 /* Number of bits in link-local pref */
35 #define IP_CACHE_TABLE_SIZE 256
36 #define IP_MASK_TABLE_SIZE (IP_ABITS + 1) /* 33 ptrs */
38 #define IP6_FTABLE_HASH_SIZE 32 /* size of each hash table in ptrs */
39 #define IP6_CACHE_TABLE_SIZE 256
40 #define IP6_MASK_TABLE_SIZE (IPV6_ABITS + 1) /* 129 ptrs */
43 * We use the common modulo hash function. In ip_ire_init(), we make
44 * sure that the cache table size is always a power of 2. That's why
45 * we can use & instead of %. Also note that we try hard to make sure
46 * the lower bits of an address capture most info from the whole address.
47 * The reason being that since our hash table is probably a lot smaller
48 * than 2^32 buckets so the lower bits are the most important.
50 #define IRE_ADDR_HASH(addr, table_size) \
51 (((addr) ^ ((addr) >> 8) ^ ((addr) >> 16) ^ ((addr) >> 24)) & \
52 ((table_size) - 1))
55 * To make a byte-order neutral hash for IPv6, just take all the
56 * bytes in the bottom 32 bits into account.
58 #define IRE_ADDR_HASH_V6(addr, table_size) \
59 IRE_ADDR_HASH((addr).s6_addr32[3], table_size)
62 * This assumes that the ftable size is a power of 2.
63 * We include some high-order bytes to avoid all IRE_LOCALs in the same
64 * bucket for performance reasons.
66 #define IRE_ADDR_MASK_HASH_V6(addr, mask, table_size) \
67 ((((addr).s6_addr8[0] & (mask).s6_addr8[0]) ^ \
68 ((addr).s6_addr8[1] & (mask).s6_addr8[1]) ^ \
69 ((addr).s6_addr8[6] & (mask).s6_addr8[6]) ^ \
70 ((addr).s6_addr8[7] & (mask).s6_addr8[7]) ^ \
71 ((addr).s6_addr8[8] & (mask).s6_addr8[8]) ^ \
72 ((addr).s6_addr8[9] & (mask).s6_addr8[9]) ^ \
73 ((addr).s6_addr8[10] & (mask).s6_addr8[10]) ^ \
74 ((addr).s6_addr8[13] & (mask).s6_addr8[13]) ^ \
75 ((addr).s6_addr8[14] & (mask).s6_addr8[14]) ^ \
76 ((addr).s6_addr8[15] & (mask).s6_addr8[15])) & ((table_size) - 1))
78 #define IRE_HIDDEN_TYPE(ire_type) ((ire_type) & \
79 (IRE_HOST | IRE_PREFIX | IRE_DEFAULT | IRE_IF_ALL | IRE_BROADCAST))
82 * match parameter definitions for IRE lookup routines.
84 #define MATCH_IRE_DSTONLY 0x0000 /* Match just the address */
85 #define MATCH_IRE_TYPE 0x0001 /* Match IRE type */
86 #define MATCH_IRE_MASK 0x0002 /* Match IRE mask */
87 #define MATCH_IRE_SHORTERMASK 0x0004 /* A mask shorter than the argument */
88 #define MATCH_IRE_GW 0x0008 /* Match IRE gateway */
89 #define MATCH_IRE_ILL 0x0010 /* Match IRE on the ill */
90 #define MATCH_IRE_ZONEONLY 0x0020 /* Match IREs in specified zone, ie */
91 /* don't match IRE_LOCALs from other */
92 /* zones or shared IREs */
93 #define MATCH_IRE_TESTHIDDEN 0x0080 /* Match ire_testhidden IREs */
94 #define MATCH_IRE_SRC_ILL 0x0100 /* ire_ill uses a src address on ill */
95 #define MATCH_IRE_DIRECT 0x0200 /* Don't match indirect routes */
97 #define MAX_IRE_RECURSION 4 /* Max IREs in ire_route_recursive */
101 * We use atomics so that we get an accurate accounting on the ires.
102 * Otherwise we can't determine leaks correctly.
104 #define BUMP_IRE_STATS(ire_stats, x) atomic_inc_64(&(ire_stats).x)
106 #ifdef _KERNEL
107 struct nce_s;
109 * structure for passing args between ire_ftable_lookup and ire_find_best_route
111 typedef struct ire_ftable_args_s {
112 in6_addr_t ift_addr_v6;
113 in6_addr_t ift_mask_v6;
114 in6_addr_t ift_gateway_v6;
115 #define ift_addr V4_PART_OF_V6(ift_addr_v6)
116 #define ift_mask V4_PART_OF_V6(ift_mask_v6)
117 #define ift_gateway V4_PART_OF_V6(ift_gateway_v6)
118 int ift_type;
119 const ill_t *ift_ill;
120 zoneid_t ift_zoneid;
121 int ift_flags;
122 ire_t *ift_best_ire;
123 } ire_ftable_args_t;
125 extern ipaddr_t ip_plen_to_mask(uint_t);
126 extern in6_addr_t *ip_plen_to_mask_v6(uint_t, in6_addr_t *);
128 extern int ip_ire_advise(queue_t *, mblk_t *, cred_t *);
129 extern int ip_ire_delete(queue_t *, mblk_t *, cred_t *);
130 extern void ip_ire_reclaim(void *);
132 extern int ip_mask_to_plen(ipaddr_t);
133 extern int ip_mask_to_plen_v6(const in6_addr_t *);
135 extern ire_t *ire_add(ire_t *);
136 extern ire_t *ire_add_v6(ire_t *);
137 extern int ire_atomic_start(irb_t *irb_ptr, ire_t *ire);
138 extern void ire_atomic_end(irb_t *irb_ptr, ire_t *ire);
140 extern ire_t *ire_create(uchar_t *, uchar_t *, uchar_t *,
141 ushort_t, ill_t *, zoneid_t, uint_t, ip_stack_t *);
143 extern ire_t **ire_create_bcast(ill_t *, ipaddr_t, zoneid_t, ire_t **);
144 extern ire_t *ire_create_if_clone(ire_t *, const in6_addr_t *, uint_t *);
145 extern ire_t *ire_lookup_bcast(ill_t *, ipaddr_t, zoneid_t);
146 extern int ire_init_v4(ire_t *, uchar_t *, uchar_t *, uchar_t *,
147 ushort_t, ill_t *, zoneid_t, uint_t, ip_stack_t *);
148 extern int ire_init_v6(ire_t *, const in6_addr_t *, const in6_addr_t *,
149 const in6_addr_t *, ushort_t, ill_t *, zoneid_t, uint_t,
150 ip_stack_t *);
152 extern int ire_init_common(ire_t *, ushort_t, ill_t *, zoneid_t, uint_t,
153 uchar_t, ip_stack_t *);
155 extern ire_t *ire_create_v6(const in6_addr_t *, const in6_addr_t *,
156 const in6_addr_t *, ushort_t, ill_t *, zoneid_t, uint_t,
157 ip_stack_t *);
159 extern void ire_delete(ire_t *);
160 extern void ire_delete_v6(ire_t *);
162 extern boolean_t ire_dep_build(ire_t *[], uint_t [], uint_t);
163 extern void ire_dep_delete_if_clone(ire_t *);
164 extern void ire_dep_incr_generation(ire_t *);
165 extern void ire_dep_remove(ire_t *);
166 extern void ire_dep_unbuild(ire_t *[], uint_t);
167 extern uint_t ire_dep_validate_generations(ire_t *);
168 extern void ire_dep_invalidate_generations(ire_t *);
169 extern boolean_t ire_determine_nce_capable(ire_t *);
171 extern void ire_flush_cache_v4(ire_t *, int);
172 extern void ire_flush_cache_v6(ire_t *, int);
174 extern ire_t *ire_ftable_lookup_v4(ipaddr_t, ipaddr_t, ipaddr_t, int,
175 const ill_t *, zoneid_t, int, uint32_t, ip_stack_t *, uint_t *);
176 extern ire_t *ire_ftable_lookup_v6(const in6_addr_t *, const in6_addr_t *,
177 const in6_addr_t *, int, const ill_t *, zoneid_t, int, uint32_t,
178 ip_stack_t *, uint_t *);
180 extern ire_t *ire_ftable_lookup_simple_v4(ipaddr_t, uint32_t, ip_stack_t *,
181 uint_t *);
182 extern ire_t *ire_ftable_lookup_simple_v6(const in6_addr_t *, uint32_t,
183 ip_stack_t *, uint_t *);
185 extern boolean_t ire_gateway_ok_zone_v4(ipaddr_t, zoneid_t, ill_t *,
186 ip_stack_t *, boolean_t);
187 extern boolean_t ire_gateway_ok_zone_v6(const in6_addr_t *, zoneid_t, ill_t *,
188 ip_stack_t *, boolean_t);
190 extern ire_t *ire_alt_local(ire_t *, zoneid_t, const ill_t *, uint_t *);
192 extern ill_t *ire_lookup_multi_ill_v4(ipaddr_t, zoneid_t, ip_stack_t *,
193 ipaddr_t *);
194 extern ill_t *ire_lookup_multi_ill_v6(const in6_addr_t *, zoneid_t,
195 ip_stack_t *, in6_addr_t *);
197 extern ire_t *ire_nexthop(ire_t *);
198 extern ill_t *ire_nexthop_ill(ire_t *);
199 extern ill_t *ire_nce_ill(ire_t *);
201 extern ire_t *ire_reject(ip_stack_t *, boolean_t);
202 extern ire_t *ire_blackhole(ip_stack_t *, boolean_t);
203 extern ire_t *ire_multicast(ill_t *);
205 /* The different ire_recvfn functions */
206 extern void ire_recv_forward_v4(ire_t *, mblk_t *, void *,
207 ip_recv_attr_t *);
208 extern void ire_recv_noroute_v4(ire_t *, mblk_t *, void *,
209 ip_recv_attr_t *);
210 extern void ire_recv_broadcast_v4(ire_t *, mblk_t *, void *,
211 ip_recv_attr_t *);
212 extern void ire_recv_multicast_v4(ire_t *, mblk_t *, void *,
213 ip_recv_attr_t *);
214 extern void ire_recv_loopback_v4(ire_t *, mblk_t *, void *,
215 ip_recv_attr_t *);
216 extern void ire_recv_local_v4(ire_t *, mblk_t *, void *,
217 ip_recv_attr_t *);
218 extern void ire_recv_noaccept_v4(ire_t *, mblk_t *, void *,
219 ip_recv_attr_t *);
221 extern void ire_recv_forward_v6(ire_t *, mblk_t *, void *,
222 ip_recv_attr_t *);
223 extern void ire_recv_noroute_v6(ire_t *, mblk_t *, void *,
224 ip_recv_attr_t *);
225 extern void ire_recv_multicast_v6(ire_t *, mblk_t *, void *,
226 ip_recv_attr_t *);
227 extern void ire_recv_loopback_v6(ire_t *, mblk_t *, void *,
228 ip_recv_attr_t *);
229 extern void ire_recv_local_v6(ire_t *, mblk_t *, void *, ip_recv_attr_t *);
230 extern void ire_recv_noaccept_v6(ire_t *, mblk_t *, void *,
231 ip_recv_attr_t *);
233 extern void irb_refhold(irb_t *);
234 extern void irb_refhold_locked(irb_t *);
235 extern void irb_refrele(irb_t *);
236 extern void irb_increment_generation(irb_t *);
238 extern void ire_refhold(ire_t *);
239 extern void ire_refhold_notr(ire_t *);
240 extern void ire_refhold_locked(ire_t *);
241 extern void ire_refrele(ire_t *);
242 extern void ire_refrele_notr(ire_t *);
243 extern void ire_make_condemned(ire_t *);
244 extern boolean_t ire_no_good(ire_t *);
245 extern nce_t *ire_handle_condemned_nce(nce_t *, ire_t *, ipha_t *, ip6_t *,
246 boolean_t);
248 extern ire_t *ire_round_robin(irb_t *, ire_ftable_args_t *, uint_t,
249 ire_t *, ip_stack_t *);
251 extern ire_t *ire_route_recursive_v4(ipaddr_t, uint_t, const ill_t *,
252 zoneid_t, uint_t, uint_t, uint32_t, ip_stack_t *, ipaddr_t *, uint_t *);
253 extern ire_t *ire_route_recursive_v6(const in6_addr_t *, uint_t,
254 const ill_t *, zoneid_t, uint_t, uint_t, uint32_t, ip_stack_t *,
255 in6_addr_t *, uint_t *);
256 extern ire_t *ire_route_recursive_dstonly_v4(ipaddr_t, uint_t,
257 uint32_t, ip_stack_t *);
258 extern ire_t *ire_route_recursive_dstonly_v6(const in6_addr_t *, uint_t,
259 uint32_t, ip_stack_t *);
260 extern ire_t *ire_route_recursive_impl_v4(ire_t *ire, ipaddr_t, uint_t,
261 const ill_t *, zoneid_t, uint_t, uint_t, uint32_t, ip_stack_t *,
262 ipaddr_t *, uint_t *);
263 extern ire_t *ire_route_recursive_impl_v6(ire_t *ire, const in6_addr_t *,
264 uint_t, const ill_t *, zoneid_t, uint_t, uint_t, uint32_t, ip_stack_t *,
265 in6_addr_t *, uint_t *);
267 /* The different ire_sendfn functions */
268 extern int ire_send_local_v4(ire_t *, mblk_t *, void *,
269 ip_xmit_attr_t *, uint32_t *);
270 extern int ire_send_noroute_v4(ire_t *, mblk_t *, void *,
271 ip_xmit_attr_t *, uint32_t *);
272 extern int ire_send_multicast_v4(ire_t *, mblk_t *, void *,
273 ip_xmit_attr_t *, uint32_t *);
274 extern int ire_send_broadcast_v4(ire_t *, mblk_t *, void *,
275 ip_xmit_attr_t *, uint32_t *);
276 extern int ire_send_wire_v4(ire_t *, mblk_t *, void *,
277 ip_xmit_attr_t *, uint32_t *);
278 extern int ire_send_local_v6(ire_t *, mblk_t *, void *,
279 ip_xmit_attr_t *, uint32_t *);
280 extern int ire_send_noroute_v6(ire_t *, mblk_t *, void *,
281 ip_xmit_attr_t *, uint32_t *);
282 extern int ire_send_multicast_v6(ire_t *, mblk_t *, void *,
283 ip_xmit_attr_t *, uint32_t *);
284 extern int ire_send_wire_v6(ire_t *, mblk_t *, void *,
285 ip_xmit_attr_t *, uint32_t *);
287 extern nce_t *ire_to_nce_pkt(ire_t *, mblk_t *);
288 extern nce_t *ire_to_nce(ire_t *, ipaddr_t, const in6_addr_t *);
290 /* Different ire_postfragfn functions */
291 extern int ip_xmit(mblk_t *, struct nce_s *,
292 iaflags_t, uint_t, uint32_t, zoneid_t, zoneid_t, uintptr_t *);
293 extern int ip_postfrag_loopcheck(mblk_t *, struct nce_s *,
294 iaflags_t, uint_t, uint32_t, zoneid_t, zoneid_t, uintptr_t *);
296 extern void ip_postfrag_loopback(mblk_t *, struct nce_s *,
297 iaflags_t, uint_t, zoneid_t);
298 extern int ire_revalidate_nce(ire_t *);
300 extern ire_t *ip_select_route_pkt(mblk_t *, ip_xmit_attr_t *,
301 uint_t *, int *);
302 extern ire_t *ip_select_route(const in6_addr_t *, const in6_addr_t,
303 ip_xmit_attr_t *, uint_t *, in6_addr_t *, int *);
304 extern ire_t *ip_select_route_v4(ipaddr_t, ipaddr_t, ip_xmit_attr_t *,
305 uint_t *, ipaddr_t *, int *);
306 extern ire_t *ip_select_route_v6(const in6_addr_t *, const in6_addr_t,
307 ip_xmit_attr_t *, uint_t *, in6_addr_t *, int *);
309 extern void ire_walk(pfv_t, void *, ip_stack_t *);
310 extern void ire_walk_ill(uint_t, uint_t, pfv_t, void *, ill_t *);
311 extern void ire_walk_v4(pfv_t, void *, zoneid_t, ip_stack_t *);
312 extern void ire_walk_ill_tables(uint_t match_flags, uint_t ire_type,
313 pfv_t func, void *arg, size_t ftbl_sz, size_t htbl_sz,
314 irb_t **ipftbl, ill_t *ill,
315 zoneid_t zoneid, ip_stack_t *);
316 extern void ire_walk_v6(pfv_t, void *, zoneid_t, ip_stack_t *);
318 extern boolean_t ire_match_args(ire_t *, ipaddr_t, ipaddr_t, ipaddr_t,
319 int, const ill_t *, zoneid_t, int);
320 extern boolean_t ire_match_args_v6(ire_t *, const in6_addr_t *,
321 const in6_addr_t *, const in6_addr_t *, int, const ill_t *, zoneid_t,
322 int);
324 extern struct nce_s *arp_nce_init(ill_t *, in_addr_t, int);
325 extern boolean_t ire_walk_ill_match(uint_t, uint_t, ire_t *, ill_t *,
326 zoneid_t, ip_stack_t *);
327 extern void ire_increment_generation(ire_t *);
328 extern void ire_increment_multicast_generation(ip_stack_t *, boolean_t);
329 extern void ire_rebind(ire_t *);
330 extern boolean_t ire_clone_verify(ire_t *);
332 #endif /* _KERNEL */
334 #ifdef __cplusplus
336 #endif
338 #endif /* _INET_IP_IRE_H */