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