xref: /titanic_41/usr/src/uts/common/inet/ip_stack.h (revision 78894ffc7b2ee149add8332a811ec7f43fd945c1)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_INET_IP_STACK_H
28 #define	_INET_IP_STACK_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/isa_defs.h>
37 #include <sys/md5.h>
38 #include <sys/types.h>
39 #include <inet/mib2.h>
40 #include <inet/nd.h>
41 #include <sys/atomic.h>
42 #include <sys/socket.h>
43 #include <sys/netstack.h>
44 #include <net/if_dl.h>
45 #include <net/if.h>
46 #include <netinet/ip.h>
47 #include <netinet/igmp_var.h>
48 #include <inet/ip.h>
49 #include <sys/taskq.h>
50 
51 #ifdef _KERNEL
52 #include <netinet/ip6.h>
53 #include <sys/avl.h>
54 #include <sys/vmem.h>
55 #include <sys/squeue.h>
56 #endif	/* _KERNEL */
57 
58 #ifdef _KERNEL
59 
60 
61 /*
62  * IP statistics.
63  */
64 #define	IP_STAT(ipst, x)	((ipst)->ips_ip_statistics.x.value.ui64++)
65 #define	IP_STAT_UPDATE(ipst, x, n) \
66 		((ipst)->ips_ip_statistics.x.value.ui64 += (n))
67 
68 typedef struct ip_stat {
69 	kstat_named_t	ipsec_fanout_proto;
70 	kstat_named_t	ip_udp_fannorm;
71 	kstat_named_t	ip_udp_fanmb;
72 	kstat_named_t	ip_udp_fanothers;
73 	kstat_named_t	ip_udp_fast_path;
74 	kstat_named_t	ip_udp_slow_path;
75 	kstat_named_t	ip_udp_input_err;
76 	kstat_named_t	ip_tcppullup;
77 	kstat_named_t	ip_tcpoptions;
78 	kstat_named_t	ip_multipkttcp;
79 	kstat_named_t	ip_tcp_fast_path;
80 	kstat_named_t	ip_tcp_slow_path;
81 	kstat_named_t	ip_tcp_input_error;
82 	kstat_named_t	ip_db_ref;
83 	kstat_named_t	ip_notaligned1;
84 	kstat_named_t	ip_notaligned2;
85 	kstat_named_t	ip_multimblk3;
86 	kstat_named_t	ip_multimblk4;
87 	kstat_named_t	ip_ipoptions;
88 	kstat_named_t	ip_classify_fail;
89 	kstat_named_t	ip_opt;
90 	kstat_named_t	ip_udp_rput_local;
91 	kstat_named_t	ipsec_proto_ahesp;
92 	kstat_named_t	ip_conn_flputbq;
93 	kstat_named_t	ip_conn_walk_drain;
94 	kstat_named_t   ip_out_sw_cksum;
95 	kstat_named_t   ip_in_sw_cksum;
96 	kstat_named_t   ip_trash_ire_reclaim_calls;
97 	kstat_named_t   ip_trash_ire_reclaim_success;
98 	kstat_named_t   ip_ire_arp_timer_expired;
99 	kstat_named_t   ip_ire_redirect_timer_expired;
100 	kstat_named_t	ip_ire_pmtu_timer_expired;
101 	kstat_named_t	ip_input_multi_squeue;
102 	kstat_named_t	ip_tcp_in_full_hw_cksum_err;
103 	kstat_named_t	ip_tcp_in_part_hw_cksum_err;
104 	kstat_named_t	ip_tcp_in_sw_cksum_err;
105 	kstat_named_t	ip_tcp_out_sw_cksum_bytes;
106 	kstat_named_t	ip_udp_in_full_hw_cksum_err;
107 	kstat_named_t	ip_udp_in_part_hw_cksum_err;
108 	kstat_named_t	ip_udp_in_sw_cksum_err;
109 	kstat_named_t	ip_udp_out_sw_cksum_bytes;
110 	kstat_named_t	ip_frag_mdt_pkt_out;
111 	kstat_named_t	ip_frag_mdt_discarded;
112 	kstat_named_t	ip_frag_mdt_allocfail;
113 	kstat_named_t	ip_frag_mdt_addpdescfail;
114 	kstat_named_t	ip_frag_mdt_allocd;
115 } ip_stat_t;
116 
117 
118 /*
119  * IP6 statistics.
120  */
121 #define	IP6_STAT(ipst, x)	((ipst)->ips_ip6_statistics.x.value.ui64++)
122 #define	IP6_STAT_UPDATE(ipst, x, n)	\
123 	((ipst)->ips_ip6_statistics.x.value.ui64 += (n))
124 
125 typedef struct ip6_stat {
126 	kstat_named_t	ip6_udp_fast_path;
127 	kstat_named_t	ip6_udp_slow_path;
128 	kstat_named_t	ip6_udp_fannorm;
129 	kstat_named_t	ip6_udp_fanmb;
130 	kstat_named_t   ip6_out_sw_cksum;
131 	kstat_named_t   ip6_in_sw_cksum;
132 	kstat_named_t	ip6_tcp_in_full_hw_cksum_err;
133 	kstat_named_t	ip6_tcp_in_part_hw_cksum_err;
134 	kstat_named_t	ip6_tcp_in_sw_cksum_err;
135 	kstat_named_t	ip6_tcp_out_sw_cksum_bytes;
136 	kstat_named_t	ip6_udp_in_full_hw_cksum_err;
137 	kstat_named_t	ip6_udp_in_part_hw_cksum_err;
138 	kstat_named_t	ip6_udp_in_sw_cksum_err;
139 	kstat_named_t	ip6_udp_out_sw_cksum_bytes;
140 	kstat_named_t	ip6_frag_mdt_pkt_out;
141 	kstat_named_t	ip6_frag_mdt_discarded;
142 	kstat_named_t	ip6_frag_mdt_allocfail;
143 	kstat_named_t	ip6_frag_mdt_addpdescfail;
144 	kstat_named_t	ip6_frag_mdt_allocd;
145 } ip6_stat_t;
146 
147 typedef struct ire_stats {
148 	uint64_t ire_stats_alloced;	/* # of ires alloced */
149 	uint64_t ire_stats_freed;	/* # of ires freed */
150 	uint64_t ire_stats_inserted;	/* # of ires inserted in the bucket */
151 	uint64_t ire_stats_deleted;	/* # of ires deleted from the bucket */
152 } ire_stats_t;
153 
154 
155 /*
156  * IP stack instances
157  */
158 struct ip_stack {
159 	netstack_t	*ips_netstack;	/* Common netstack */
160 
161 	struct ipparam_s	*ips_param_arr; 	/* ndd variable table */
162 	struct ipndp_s		*ips_ndp_arr;
163 
164 	mib2_ipIfStatsEntry_t	ips_ip_mib;	/* SNMP fixed size info */
165 	mib2_icmp_t	ips_icmp_mib;
166 	/*
167 	 * IPv6 mibs when the interface (ill) is not known.
168 	 * When the ill is known the per-interface mib in the ill is used.
169 	 */
170 	mib2_ipIfStatsEntry_t	ips_ip6_mib;
171 	mib2_ipv6IfIcmpEntry_t	ips_icmp6_mib;
172 
173 	struct igmpstat		ips_igmpstat;
174 
175 	kstat_t		*ips_ip_mibkp;	/* kstat exporting ip_mib data */
176 	kstat_t		*ips_icmp_mibkp; /* kstat exporting icmp_mib data */
177 	kstat_t		*ips_ip_kstat;
178 	ip_stat_t	ips_ip_statistics;
179 	kstat_t		*ips_ip6_kstat;
180 	ip6_stat_t	ips_ip6_statistics;
181 
182 /* ip.c */
183 	krwlock_t	ips_ip_g_nd_lock;
184 	kmutex_t	ips_igmp_timer_lock;
185 	kmutex_t	ips_mld_timer_lock;
186 	kmutex_t	ips_ip_mi_lock;
187 	kmutex_t	ips_ip_addr_avail_lock;
188 	krwlock_t	ips_ill_g_lock;
189 	krwlock_t	ips_ipsec_capab_ills_lock;
190 				/* protects the list of IPsec capable ills */
191 	struct ipsec_capab_ill_s *ips_ipsec_capab_ills_ah;
192 	struct ipsec_capab_ill_s *ips_ipsec_capab_ills_esp;
193 
194 	krwlock_t	ips_ill_g_usesrc_lock;
195 
196 	struct ill_group *ips_illgrp_head_v4;	/* Head of IPv4 ill groups */
197 	struct ill_group *ips_illgrp_head_v6;	/* Head of IPv6 ill groups */
198 
199 /* ipclassifier.c - keep in ip_stack_t */
200 	/* ipclassifier hash tables */
201 	struct connf_s	*ips_rts_clients;
202 	struct connf_s	*ips_ipcl_conn_fanout;
203 	struct connf_s	*ips_ipcl_bind_fanout;
204 	struct connf_s	*ips_ipcl_proto_fanout;
205 	struct connf_s	*ips_ipcl_proto_fanout_v6;
206 	struct connf_s	*ips_ipcl_udp_fanout;
207 	struct connf_s	*ips_ipcl_raw_fanout;
208 	uint_t		ips_ipcl_conn_fanout_size;
209 	uint_t		ips_ipcl_bind_fanout_size;
210 	uint_t		ips_ipcl_udp_fanout_size;
211 	uint_t		ips_ipcl_raw_fanout_size;
212 	struct connf_s	*ips_ipcl_globalhash_fanout;
213 	int		ips_conn_g_index;
214 
215 /* ip.c */
216 	/* Following protected by ips_igmp_timer_lock */
217 	int 		ips_igmp_time_to_next;	/* Time since last timeout */
218 	int 		ips_igmp_timer_scheduled_last;
219 	int		ips_igmp_deferred_next;
220 	timeout_id_t	ips_igmp_timeout_id;
221 	/* Protected by igmp_timer_lock */
222 	boolean_t	ips_igmp_timer_setter_active;
223 
224 	/* Following protected by mld_timer_lock */
225 	int 		ips_mld_time_to_next;	/* Time since last timeout */
226 	int 		ips_mld_timer_scheduled_last;
227 	int		ips_mld_deferred_next;
228 	timeout_id_t	ips_mld_timeout_id;
229 	/* Protected by mld_timer_lock */
230 	boolean_t	ips_mld_timer_setter_active;
231 
232 	/* Protected by igmp_slowtimeout_lock */
233 	timeout_id_t	ips_igmp_slowtimeout_id;
234 	kmutex_t	ips_igmp_slowtimeout_lock;
235 
236 	/* Protected by mld_slowtimeout_lock */
237 	timeout_id_t	ips_mld_slowtimeout_id;
238 	kmutex_t	ips_mld_slowtimeout_lock;
239 
240 	/* IPv4 forwarding table */
241 	struct radix_node_head *ips_ip_ftable;
242 
243 	/* This is dynamically allocated in ip_ire_init */
244 	struct irb	 *ips_ip_cache_table;
245 
246 #define	IPV6_ABITS		128
247 #define	IP6_MASK_TABLE_SIZE	(IPV6_ABITS + 1)	/* 129 ptrs */
248 
249 	struct irb	*ips_ip_forwarding_table_v6[IP6_MASK_TABLE_SIZE];
250 	/* This is dynamically allocated in ip_ire_init */
251 	struct irb	*ips_ip_cache_table_v6;
252 
253 	uint32_t	ips_ire_handle;
254 	/*
255 	 * ire_ft_init_lock is used while initializing ip_forwarding_table
256 	 * dynamically in ire_add.
257 	 */
258 	kmutex_t	ips_ire_ft_init_lock;
259 	kmutex_t	ips_ire_handle_lock;	/* Protects ire_handle */
260 
261 	uint32_t	ips_ip_cache_table_size;
262 	uint32_t	ips_ip6_cache_table_size;
263 	uint32_t	ips_ip6_ftable_hash_size;
264 
265 	ire_stats_t 	ips_ire_stats_v4;	/* IPv4 ire statistics */
266 	ire_stats_t 	ips_ire_stats_v6;	/* IPv6 ire statistics */
267 
268 	/* pending binds */
269 	mblk_t		*ips_ip6_asp_pending_ops;
270 	mblk_t		*ips_ip6_asp_pending_ops_tail;
271 
272 	/* Synchronize updates with table usage */
273 	mblk_t		*ips_ip6_asp_pending_update; /* pending table updates */
274 
275 	boolean_t	ips_ip6_asp_uip;	/* table update in progress */
276 	kmutex_t	ips_ip6_asp_lock;	/* protect all the above */
277 	uint32_t	ips_ip6_asp_refcnt;	/* outstanding references */
278 
279 	struct ip6_asp	*ips_ip6_asp_table;
280 	/* The number of policy entries in the table */
281 	uint_t		ips_ip6_asp_table_count;
282 
283 	int		ips_ip_g_forward;
284 	int		ips_ipv6_forward;
285 
286 	int		ips_ipmp_hook_emulation; /* ndd variable */
287 
288 	time_t		ips_ip_g_frag_timeout;
289 	clock_t		ips_ip_g_frag_timo_ms;
290 
291 	struct conn_s	*ips_ip_g_mrouter;
292 
293 	/* Time since last icmp_pkt_err */
294 	clock_t		ips_icmp_pkt_err_last;
295 	/* Number of packets sent in burst */
296 	uint_t		ips_icmp_pkt_err_sent;
297 	/* Used by icmp_send_redirect_v6 for picking random src. */
298 	uint_t		ips_icmp_redirect_v6_src_index;
299 
300 	/* Protected by ip_mi_lock */
301 	void		*ips_ip_g_head;		/* Instance Data List Head */
302 
303 	caddr_t		ips_ip_g_nd;		/* Named Dispatch List Head */
304 
305 	/* Multirouting stuff */
306 	/* Interval (in ms) between consecutive 'bad MTU' warnings */
307 	hrtime_t	ips_ip_multirt_log_interval;
308 	/* Time since last warning issued. */
309 	hrtime_t	ips_multirt_bad_mtu_last_time;
310 
311 	struct cgtp_filter_ops *ips_ip_cgtp_filter_ops;	/* CGTP hooks */
312 	boolean_t	ips_ip_cgtp_filter;	/* Enable/disable CGTP hooks */
313 
314 	kmutex_t	ips_ip_trash_timer_lock;
315 	timeout_id_t	ips_ip_ire_expire_id;	/* IRE expiration timer. */
316 	struct ipsq_s	*ips_ipsq_g_head;
317 	uint_t		ips_ill_index;	/* Used to assign interface indicies */
318 	/* When set search for unused index */
319 	boolean_t	ips_ill_index_wrap;
320 
321 	clock_t		ips_ip_ire_arp_time_elapsed;
322 			/* Time since IRE cache last flushed */
323 	clock_t		ips_ip_ire_rd_time_elapsed;
324 			/* ... redirect IREs last flushed */
325 	clock_t		ips_ip_ire_pmtu_time_elapsed;
326 			/* Time since path mtu increase */
327 
328 	uint_t		ips_ip_redirect_cnt;
329 			/* Num of redirect routes in ftable */
330 	uint_t		ips_ipv6_ire_default_count;
331 			/* Number of IPv6 IRE_DEFAULT entries */
332 	uint_t		ips_ipv6_ire_default_index;
333 			/* Walking IPv6 index used to mod in */
334 
335 	uint_t		ips_loopback_packets;
336 
337 	/* NDP/NCE structures for IPv4 and IPv6 */
338 	struct ndp_g_s	*ips_ndp4;
339 	struct ndp_g_s	*ips_ndp6;
340 
341 	/* ip_mroute stuff */
342 	kmutex_t	ips_ip_g_mrouter_mutex;
343 
344 	struct mrtstat	*ips_mrtstat;	/* Stats for netstat */
345 	int		ips_saved_ip_g_forward;
346 
347 	/* numvifs is only a hint about the max interface being used. */
348 	ushort_t	ips_numvifs;
349 	kmutex_t	ips_numvifs_mutex;
350 
351 	struct vif	*ips_vifs;
352 	struct mfcb	*ips_mfcs;	/* kernel routing table	*/
353 	struct tbf	*ips_tbfs;
354 	/*
355 	 * One-back cache used to locate a tunnel's vif,
356 	 * given a datagram's src ip address.
357 	 */
358 	ipaddr_t	ips_last_encap_src;
359 	struct vif	*ips_last_encap_vif;
360 	kmutex_t	ips_last_encap_lock;	/* Protects the above */
361 
362 	/*
363 	 * reg_vif_num is protected by numvifs_mutex
364 	 */
365 	/* Whether or not special PIM assert processing is enabled. */
366 	ushort_t	ips_reg_vif_num; 	/* Index to Register vif */
367 	int		ips_pim_assert;
368 
369 	union ill_g_head_u *ips_ill_g_heads;   /* ILL List Head */
370 
371 	kstat_t		*ips_loopback_ksp;
372 
373 	uint_t		ips_ipif_src_random;
374 
375 	struct idl_s	*ips_conn_drain_list;	/* Array of conn drain lists */
376 	uint_t		ips_conn_drain_list_cnt; /* Count of conn_drain_list */
377 	int		ips_conn_drain_list_index; /* Next drain_list */
378 
379 	/*
380 	 * ID used to assign next free one.
381 	 * Increases by one. Once it wraps we search for an unused ID.
382 	 */
383 	uint_t		ips_ip_src_id;
384 	boolean_t	ips_srcid_wrapped;
385 
386 	struct srcid_map *ips_srcid_head;
387 	krwlock_t	ips_srcid_lock;
388 
389 	uint64_t	ips_ipif_g_seqid;
390 	union phyint_list_u *ips_phyint_g_list;	/* start of phyint list */
391 
392 	/*
393 	 * Reflects value of FAILBACK variable in IPMP config file
394 	 * /etc/default/mpathd. Default value is B_TRUE.
395 	 * Set to B_FALSE if user disabled failback by configuring
396 	 * "FAILBACK=no" in.mpathd uses SIOCSIPMPFAILBACK ioctl to pass this
397 	 * information to kernel.
398 	 */
399 	boolean_t ips_ipmp_enable_failback;
400 
401 /* ip_neti.c */
402 	hook_family_t	ips_ipv4root;
403 	hook_family_t	ips_ipv6root;
404 
405 	/*
406 	 * Hooks for firewalling
407 	 */
408 	hook_event_t		ips_ip4_physical_in_event;
409 	hook_event_t		ips_ip4_physical_out_event;
410 	hook_event_t		ips_ip4_forwarding_event;
411 	hook_event_t		ips_ip4_loopback_in_event;
412 	hook_event_t		ips_ip4_loopback_out_event;
413 	hook_event_t		ips_ip4_nic_events;
414 	hook_event_t		ips_ip6_physical_in_event;
415 	hook_event_t		ips_ip6_physical_out_event;
416 	hook_event_t		ips_ip6_forwarding_event;
417 	hook_event_t		ips_ip6_loopback_in_event;
418 	hook_event_t		ips_ip6_loopback_out_event;
419 	hook_event_t		ips_ip6_nic_events;
420 
421 	hook_event_token_t	ips_ipv4firewall_physical_in;
422 	hook_event_token_t	ips_ipv4firewall_physical_out;
423 	hook_event_token_t	ips_ipv4firewall_forwarding;
424 	hook_event_token_t	ips_ipv4firewall_loopback_in;
425 	hook_event_token_t	ips_ipv4firewall_loopback_out;
426 	hook_event_token_t	ips_ipv4nicevents;
427 	hook_event_token_t	ips_ipv6firewall_physical_in;
428 	hook_event_token_t	ips_ipv6firewall_physical_out;
429 	hook_event_token_t	ips_ipv6firewall_forwarding;
430 	hook_event_token_t	ips_ipv6firewall_loopback_in;
431 	hook_event_token_t	ips_ipv6firewall_loopback_out;
432 	hook_event_token_t	ips_ipv6nicevents;
433 
434 	net_data_t		ips_ipv4_net_data;
435 	net_data_t		ips_ipv6_net_data;
436 };
437 typedef struct ip_stack ip_stack_t;
438 
439 /* Finding an ip_stack_t */
440 #define	CONNQ_TO_IPST(_q)	(Q_TO_CONN(_q)->conn_netstack->netstack_ip)
441 #define	ILLQ_TO_IPST(_q)	(((ill_t *)(_q)->q_ptr)->ill_ipst)
442 
443 #else /* _KERNEL */
444 typedef int ip_stack_t;
445 #endif /* _KERNEL */
446 
447 #ifdef	__cplusplus
448 }
449 #endif
450 
451 #endif	/* _INET_IP_STACK_H */
452