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