xref: /titanic_41/usr/src/uts/common/inet/ip_stack.h (revision 182c91496a82a606d31c680cedf9351196cc76e6)
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 2010 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 #include <sys/modhash.h>
37 
38 #ifdef _KERNEL
39 #include <sys/list.h>
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	ip_udp_fannorm;
51 	kstat_named_t	ip_udp_fanmb;
52 	kstat_named_t	ip_recv_pullup;
53 	kstat_named_t	ip_db_ref;
54 	kstat_named_t	ip_notaligned;
55 	kstat_named_t	ip_multimblk;
56 	kstat_named_t	ip_opt;
57 	kstat_named_t	ipsec_proto_ahesp;
58 	kstat_named_t	ip_conn_flputbq;
59 	kstat_named_t	ip_conn_walk_drain;
60 	kstat_named_t   ip_out_sw_cksum;
61 	kstat_named_t	ip_out_sw_cksum_bytes;
62 	kstat_named_t   ip_in_sw_cksum;
63 	kstat_named_t   ip_ire_reclaim_calls;
64 	kstat_named_t   ip_ire_reclaim_deleted;
65 	kstat_named_t   ip_nce_reclaim_calls;
66 	kstat_named_t   ip_nce_reclaim_deleted;
67 	kstat_named_t   ip_dce_reclaim_calls;
68 	kstat_named_t   ip_dce_reclaim_deleted;
69 	kstat_named_t	ip_tcp_in_full_hw_cksum_err;
70 	kstat_named_t	ip_tcp_in_part_hw_cksum_err;
71 	kstat_named_t	ip_tcp_in_sw_cksum_err;
72 	kstat_named_t	ip_udp_in_full_hw_cksum_err;
73 	kstat_named_t	ip_udp_in_part_hw_cksum_err;
74 	kstat_named_t	ip_udp_in_sw_cksum_err;
75 	kstat_named_t	conn_in_recvdstaddr;
76 	kstat_named_t	conn_in_recvopts;
77 	kstat_named_t	conn_in_recvif;
78 	kstat_named_t	conn_in_recvslla;
79 	kstat_named_t	conn_in_recvucred;
80 	kstat_named_t	conn_in_recvttl;
81 	kstat_named_t	conn_in_recvhopopts;
82 	kstat_named_t	conn_in_recvhoplimit;
83 	kstat_named_t	conn_in_recvdstopts;
84 	kstat_named_t	conn_in_recvrthdrdstopts;
85 	kstat_named_t	conn_in_recvrthdr;
86 	kstat_named_t	conn_in_recvpktinfo;
87 	kstat_named_t	conn_in_recvtclass;
88 	kstat_named_t	conn_in_timestamp;
89 } ip_stat_t;
90 
91 
92 /*
93  * IP6 statistics.
94  */
95 #define	IP6_STAT(ipst, x)	((ipst)->ips_ip6_statistics.x.value.ui64++)
96 #define	IP6_STAT_UPDATE(ipst, x, n)	\
97 	((ipst)->ips_ip6_statistics.x.value.ui64 += (n))
98 
99 typedef struct ip6_stat {
100 	kstat_named_t	ip6_udp_fannorm;
101 	kstat_named_t	ip6_udp_fanmb;
102 	kstat_named_t	ip6_recv_pullup;
103 	kstat_named_t	ip6_db_ref;
104 	kstat_named_t	ip6_notaligned;
105 	kstat_named_t	ip6_multimblk;
106 	kstat_named_t	ipsec_proto_ahesp;
107 	kstat_named_t   ip6_out_sw_cksum;
108 	kstat_named_t	ip6_out_sw_cksum_bytes;
109 	kstat_named_t   ip6_in_sw_cksum;
110 	kstat_named_t	ip6_tcp_in_full_hw_cksum_err;
111 	kstat_named_t	ip6_tcp_in_part_hw_cksum_err;
112 	kstat_named_t	ip6_tcp_in_sw_cksum_err;
113 	kstat_named_t	ip6_udp_in_full_hw_cksum_err;
114 	kstat_named_t	ip6_udp_in_part_hw_cksum_err;
115 	kstat_named_t	ip6_udp_in_sw_cksum_err;
116 } ip6_stat_t;
117 
118 typedef struct ire_stats {
119 	uint64_t ire_stats_alloced;	/* # of ires alloced */
120 	uint64_t ire_stats_freed;	/* # of ires freed */
121 	uint64_t ire_stats_inserted;	/* # of ires inserted in the bucket */
122 	uint64_t ire_stats_deleted;	/* # of ires deleted from the bucket */
123 } ire_stats_t;
124 
125 #define	TX_FANOUT_SIZE	128
126 #define	IDLHASHINDEX(X)	\
127 	((((uintptr_t)(X) >> 2) + ((uintptr_t)(X) >> 9)) & (TX_FANOUT_SIZE - 1))
128 
129 /* Data structure to represent addresses */
130 typedef struct srcid_map {
131 	struct srcid_map	*sm_next;
132 	in6_addr_t		sm_addr;	/* Local address */
133 	uint_t			sm_srcid;	/* source id */
134 	uint_t			sm_refcnt;	/* > 1 ipif with same addr? */
135 	zoneid_t		sm_zoneid;	/* zone id */
136 } srcid_map_t;
137 
138 /*
139  * IP stack instances
140  */
141 struct ip_stack {
142 	netstack_t	*ips_netstack;	/* Common netstack */
143 
144 	uint_t			ips_src_generation;	/* Both IPv4 and IPv6 */
145 
146 	struct mod_prop_info_s	*ips_propinfo_tbl; 	/* ip tunables table */
147 
148 	mib2_ipIfStatsEntry_t	ips_ip_mib;	/* SNMP fixed size info */
149 	mib2_icmp_t	ips_icmp_mib;
150 	/*
151 	 * IPv6 mibs when the interface (ill) is not known.
152 	 * When the ill is known the per-interface mib in the ill is used.
153 	 */
154 	mib2_ipIfStatsEntry_t	ips_ip6_mib;
155 	mib2_ipv6IfIcmpEntry_t	ips_icmp6_mib;
156 
157 	struct igmpstat		ips_igmpstat;
158 
159 	kstat_t		*ips_ip_mibkp;	/* kstat exporting ip_mib data */
160 	kstat_t		*ips_icmp_mibkp; /* kstat exporting icmp_mib data */
161 	kstat_t		*ips_ip_kstat;
162 	ip_stat_t	ips_ip_statistics;
163 	kstat_t		*ips_ip6_kstat;
164 	ip6_stat_t	ips_ip6_statistics;
165 
166 /* ip.c */
167 	kmutex_t	ips_igmp_timer_lock;
168 	kmutex_t	ips_mld_timer_lock;
169 	kmutex_t	ips_ip_mi_lock;
170 	kmutex_t	ips_ip_addr_avail_lock;
171 	krwlock_t	ips_ill_g_lock;
172 
173 	krwlock_t	ips_ill_g_usesrc_lock;
174 
175 	/* Taskq dispatcher for capability operations */
176 	kmutex_t	ips_capab_taskq_lock;
177 	kcondvar_t	ips_capab_taskq_cv;
178 	mblk_t		*ips_capab_taskq_head;
179 	mblk_t		*ips_capab_taskq_tail;
180 	kthread_t	*ips_capab_taskq_thread;
181 	boolean_t	ips_capab_taskq_quit;
182 
183 /* ipclassifier.c - keep in ip_stack_t */
184 	/* ipclassifier hash tables */
185 	struct connf_s	*ips_rts_clients;
186 	struct connf_s	*ips_ipcl_conn_fanout;
187 	struct connf_s	*ips_ipcl_bind_fanout;
188 	struct connf_s	*ips_ipcl_proto_fanout_v4;
189 	struct connf_s	*ips_ipcl_proto_fanout_v6;
190 	struct connf_s	*ips_ipcl_udp_fanout;
191 	struct connf_s	*ips_ipcl_raw_fanout;		/* RAW SCTP sockets */
192 	struct connf_s	*ips_ipcl_iptun_fanout;
193 	uint_t		ips_ipcl_conn_fanout_size;
194 	uint_t		ips_ipcl_bind_fanout_size;
195 	uint_t		ips_ipcl_udp_fanout_size;
196 	uint_t		ips_ipcl_raw_fanout_size;
197 	uint_t		ips_ipcl_iptun_fanout_size;
198 	struct connf_s	*ips_ipcl_globalhash_fanout;
199 	int		ips_conn_g_index;
200 
201 /* ip.c */
202 	/* Following protected by igmp_timer_lock */
203 	int 		ips_igmp_time_to_next;	/* Time since last timeout */
204 	int 		ips_igmp_timer_scheduled_last;
205 	int		ips_igmp_deferred_next;
206 	timeout_id_t	ips_igmp_timeout_id;
207 	boolean_t	ips_igmp_timer_setter_active;
208 
209 	/* Following protected by mld_timer_lock */
210 	int 		ips_mld_time_to_next;	/* Time since last timeout */
211 	int 		ips_mld_timer_scheduled_last;
212 	int		ips_mld_deferred_next;
213 	timeout_id_t	ips_mld_timeout_id;
214 	boolean_t	ips_mld_timer_setter_active;
215 
216 	/* Protected by igmp_slowtimeout_lock */
217 	timeout_id_t	ips_igmp_slowtimeout_id;
218 	kmutex_t	ips_igmp_slowtimeout_lock;
219 
220 	/* Protected by mld_slowtimeout_lock */
221 	timeout_id_t	ips_mld_slowtimeout_id;
222 	kmutex_t	ips_mld_slowtimeout_lock;
223 
224 	/* IPv4 forwarding table */
225 	struct radix_node_head *ips_ip_ftable;
226 
227 #define	IPV6_ABITS		128
228 #define	IP6_MASK_TABLE_SIZE	(IPV6_ABITS + 1)	/* 129 ptrs */
229 	struct irb	*ips_ip_forwarding_table_v6[IP6_MASK_TABLE_SIZE];
230 
231 	/*
232 	 * ire_ft_init_lock is used while initializing ip_forwarding_table
233 	 * dynamically in ire_add.
234 	 */
235 	kmutex_t	ips_ire_ft_init_lock;
236 
237 	/*
238 	 * This is the IPv6 counterpart of RADIX_NODE_HEAD_LOCK. It is used
239 	 * to prevent adds and deletes while we are doing a ftable_lookup
240 	 * and extracting the ire_generation.
241 	 */
242 	krwlock_t	ips_ip6_ire_head_lock;
243 
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 	/* Count how many condemned objects for kmem_cache callbacks */
250 	uint32_t	ips_num_ire_condemned;
251 	uint32_t	ips_num_nce_condemned;
252 	uint32_t	ips_num_dce_condemned;
253 
254 	struct ire_s	*ips_ire_reject_v4;	/* For unreachable dests */
255 	struct ire_s	*ips_ire_reject_v6;	/* For unreachable dests */
256 	struct ire_s	*ips_ire_blackhole_v4;	/* For temporary failures */
257 	struct ire_s	*ips_ire_blackhole_v6;	/* For temporary failures */
258 
259 	/* ips_ire_dep_lock protects ire_dep_* relationship between IREs */
260 	krwlock_t	ips_ire_dep_lock;
261 
262 	/* Destination Cache Entries */
263 	struct dce_s	*ips_dce_default;
264 	uint_t		ips_dce_hashsize;
265 	struct dcb_s	*ips_dce_hash_v4;
266 	struct dcb_s	*ips_dce_hash_v6;
267 	uint_t		ips_dce_reclaim_needed;
268 
269 	/* pending binds */
270 	mblk_t		*ips_ip6_asp_pending_ops;
271 	mblk_t		*ips_ip6_asp_pending_ops_tail;
272 
273 	/* Synchronize updates with table usage */
274 	mblk_t		*ips_ip6_asp_pending_update; /* pending table updates */
275 
276 	boolean_t	ips_ip6_asp_uip;	/* table update in progress */
277 	kmutex_t	ips_ip6_asp_lock;	/* protect all the above */
278 	uint32_t	ips_ip6_asp_refcnt;	/* outstanding references */
279 
280 	struct ip6_asp	*ips_ip6_asp_table;
281 	/* The number of policy entries in the table */
282 	uint_t		ips_ip6_asp_table_count;
283 
284 	struct conn_s	*ips_ip_g_mrouter;
285 
286 	/* Time since last icmp_pkt_err */
287 	clock_t		ips_icmp_pkt_err_last;
288 	/* Number of packets sent in burst */
289 	uint_t		ips_icmp_pkt_err_sent;
290 
291 	/* Protected by ip_mi_lock */
292 	void		*ips_ip_g_head;	/* IP Instance Data List Head */
293 	void		*ips_arp_g_head; /* ARP Instance Data List Head */
294 
295 	/* Multirouting stuff */
296 	/* Interval (in ms) between consecutive 'bad MTU' warnings */
297 	hrtime_t	ips_ip_multirt_log_interval;
298 	/* Time since last warning issued. */
299 	hrtime_t	ips_multirt_bad_mtu_last_time;
300 
301 	/*
302 	 * CGTP hooks. Enabling and disabling of hooks is controlled by an
303 	 * IP tunable 'ips_ip_cgtp_filter'.
304 	 */
305 	struct cgtp_filter_ops *ips_ip_cgtp_filter_ops;
306 
307 	struct ipsq_s	*ips_ipsq_g_head;
308 	uint_t		ips_ill_index;	/* Used to assign interface indicies */
309 	/* When set search for unused index */
310 	boolean_t	ips_ill_index_wrap;
311 
312 	uint_t		ips_loopback_packets;
313 
314 	/* NDP/NCE structures for IPv4 and IPv6 */
315 	struct ndp_g_s	*ips_ndp4;
316 	struct ndp_g_s	*ips_ndp6;
317 
318 	/* ip_mroute stuff */
319 	kmutex_t	ips_ip_g_mrouter_mutex;
320 
321 	struct mrtstat	*ips_mrtstat;	/* Stats for netstat */
322 	int		ips_saved_ip_forwarding;
323 
324 	/* numvifs is only a hint about the max interface being used. */
325 	ushort_t	ips_numvifs;
326 	kmutex_t	ips_numvifs_mutex;
327 
328 	struct vif	*ips_vifs;
329 	struct mfcb	*ips_mfcs;	/* kernel routing table	*/
330 	struct tbf	*ips_tbfs;
331 	/*
332 	 * One-back cache used to locate a tunnel's vif,
333 	 * given a datagram's src ip address.
334 	 */
335 	ipaddr_t	ips_last_encap_src;
336 	struct vif	*ips_last_encap_vif;
337 	kmutex_t	ips_last_encap_lock;	/* Protects the above */
338 
339 	/*
340 	 * reg_vif_num is protected by numvifs_mutex
341 	 */
342 	/* Whether or not special PIM assert processing is enabled. */
343 	ushort_t	ips_reg_vif_num; 	/* Index to Register vif */
344 	int		ips_pim_assert;
345 
346 	union ill_g_head_u *ips_ill_g_heads;   /* ILL List Head */
347 
348 	kstat_t		*ips_loopback_ksp;
349 
350 	/* Array of conn drain lists */
351 	struct idl_tx_list_s	*ips_idl_tx_list;
352 	uint_t		ips_conn_drain_list_cnt; /* Count of conn_drain_list */
353 
354 	/*
355 	 * ID used to assign next free one.
356 	 * Increases by one. Once it wraps we search for an unused ID.
357 	 */
358 	uint_t		ips_ip_src_id;
359 	boolean_t	ips_srcid_wrapped;
360 
361 	struct srcid_map *ips_srcid_head;
362 	krwlock_t	ips_srcid_lock;
363 
364 	uint64_t	ips_ipif_g_seqid;	/* Used only for sctp_addr.c */
365 	union phyint_list_u *ips_phyint_g_list;	/* start of phyint list */
366 
367 /* ip_netinfo.c */
368 	hook_family_t	ips_ipv4root;
369 	hook_family_t	ips_ipv6root;
370 	hook_family_t	ips_arproot;
371 
372 	net_handle_t		ips_ipv4_net_data;
373 	net_handle_t		ips_ipv6_net_data;
374 	net_handle_t		ips_arp_net_data;
375 
376 	/*
377 	 * Hooks for firewalling
378 	 */
379 	hook_event_t		ips_ip4_physical_in_event;
380 	hook_event_t		ips_ip4_physical_out_event;
381 	hook_event_t		ips_ip4_forwarding_event;
382 	hook_event_t		ips_ip4_loopback_in_event;
383 	hook_event_t		ips_ip4_loopback_out_event;
384 
385 	hook_event_t		ips_ip6_physical_in_event;
386 	hook_event_t		ips_ip6_physical_out_event;
387 	hook_event_t		ips_ip6_forwarding_event;
388 	hook_event_t		ips_ip6_loopback_in_event;
389 	hook_event_t		ips_ip6_loopback_out_event;
390 
391 	hook_event_t		ips_arp_physical_in_event;
392 	hook_event_t		ips_arp_physical_out_event;
393 	hook_event_t		ips_arp_nic_events;
394 
395 	hook_event_token_t	ips_ipv4firewall_physical_in;
396 	hook_event_token_t	ips_ipv4firewall_physical_out;
397 	hook_event_token_t	ips_ipv4firewall_forwarding;
398 	hook_event_token_t	ips_ipv4firewall_loopback_in;
399 	hook_event_token_t	ips_ipv4firewall_loopback_out;
400 
401 	hook_event_token_t	ips_ipv6firewall_physical_in;
402 	hook_event_token_t	ips_ipv6firewall_physical_out;
403 	hook_event_token_t	ips_ipv6firewall_forwarding;
404 	hook_event_token_t	ips_ipv6firewall_loopback_in;
405 	hook_event_token_t	ips_ipv6firewall_loopback_out;
406 
407 	hook_event_t		ips_ip4_nic_events;
408 	hook_event_t		ips_ip6_nic_events;
409 	hook_event_token_t	ips_ipv4nicevents;
410 	hook_event_token_t	ips_ipv6nicevents;
411 
412 	hook_event_token_t	ips_arp_physical_in;
413 	hook_event_token_t	ips_arp_physical_out;
414 	hook_event_token_t	ips_arpnicevents;
415 
416 	net_handle_t		ips_ip4_observe_pr;
417 	net_handle_t		ips_ip6_observe_pr;
418 	hook_event_t		ips_ip4_observe;
419 	hook_event_t		ips_ip6_observe;
420 	hook_event_token_t	ips_ipv4observing;
421 	hook_event_token_t	ips_ipv6observing;
422 
423 	struct __ldi_ident	*ips_ldi_ident;
424 
425 /* ipmp.c */
426 	krwlock_t		ips_ipmp_lock;
427 	mod_hash_t		*ips_ipmp_grp_hash;
428 
429 };
430 typedef struct ip_stack ip_stack_t;
431 
432 /* Finding an ip_stack_t */
433 #define	CONNQ_TO_IPST(_q)	(Q_TO_CONN(_q)->conn_netstack->netstack_ip)
434 #define	ILLQ_TO_IPST(_q)	(((ill_t *)(_q)->q_ptr)->ill_ipst)
435 #define	PHYINT_TO_IPST(phyi)	((phyi)->phyint_ipsq->ipsq_ipst)
436 
437 #else /* _KERNEL */
438 typedef int ip_stack_t;
439 #endif /* _KERNEL */
440 
441 #ifdef	__cplusplus
442 }
443 #endif
444 
445 #endif	/* _INET_IP_STACK_H */
446