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_fired_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_fired_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 /* This is dynamically allocated in ire_add_mrtun */ 246 struct irb *ips_ip_mrtun_table; 247 248 #define IPV6_ABITS 128 249 #define IP6_MASK_TABLE_SIZE (IPV6_ABITS + 1) /* 129 ptrs */ 250 251 struct irb *ips_ip_forwarding_table_v6[IP6_MASK_TABLE_SIZE]; 252 /* This is dynamically allocated in ip_ire_init */ 253 struct irb *ips_ip_cache_table_v6; 254 255 uint32_t ips_ire_handle; 256 /* 257 * ire_ft_init_lock is used while initializing ip_forwarding_table 258 * dynamically in ire_add. 259 */ 260 kmutex_t ips_ire_ft_init_lock; 261 kmutex_t ips_ire_mrtun_lock; /* Protects mrtun table and count */ 262 kmutex_t ips_ire_srcif_table_lock; /* Same as above */ 263 /* 264 * The following counts are used to determine whether a walk is 265 * needed through the reverse tunnel table or through ills 266 */ 267 kmutex_t ips_ire_handle_lock; /* Protects ire_handle */ 268 269 /* # of ires in reverse tun table */ 270 uint_t ips_ire_mrtun_count; 271 272 /* # of ires in all srcif tables */ 273 uint_t ips_ire_srcif_table_count; 274 275 uint32_t ips_ip_cache_table_size; 276 uint32_t ips_ip6_cache_table_size; 277 uint32_t ips_ip6_ftable_hash_size; 278 279 ire_stats_t ips_ire_stats_v4; /* IPv4 ire statistics */ 280 ire_stats_t ips_ire_stats_v6; /* IPv6 ire statistics */ 281 282 /* pending binds */ 283 mblk_t *ips_ip6_asp_pending_ops; 284 mblk_t *ips_ip6_asp_pending_ops_tail; 285 286 /* Synchronize updates with table usage */ 287 mblk_t *ips_ip6_asp_pending_update; /* pending table updates */ 288 289 boolean_t ips_ip6_asp_uip; /* table update in progress */ 290 kmutex_t ips_ip6_asp_lock; /* protect all the above */ 291 uint32_t ips_ip6_asp_refcnt; /* outstanding references */ 292 293 struct ip6_asp *ips_ip6_asp_table; 294 /* The number of policy entries in the table */ 295 uint_t ips_ip6_asp_table_count; 296 297 int ips_ip_g_forward; 298 int ips_ipv6_forward; 299 300 time_t ips_ip_g_frag_timeout; 301 clock_t ips_ip_g_frag_timo_ms; 302 303 queue_t *ips_ip_g_mrouter; 304 305 /* Time since last icmp_pkt_err */ 306 clock_t ips_icmp_pkt_err_last; 307 /* Number of packets sent in burst */ 308 uint_t ips_icmp_pkt_err_sent; 309 /* Used by icmp_send_redirect_v6 for picking random src. */ 310 uint_t ips_icmp_redirect_v6_src_index; 311 312 /* Protected by ip_mi_lock */ 313 void *ips_ip_g_head; /* Instance Data List Head */ 314 315 caddr_t ips_ip_g_nd; /* Named Dispatch List Head */ 316 317 /* Multirouting stuff */ 318 /* Interval (in ms) between consecutive 'bad MTU' warnings */ 319 hrtime_t ips_ip_multirt_log_interval; 320 /* Time since last warning issued. */ 321 hrtime_t ips_multirt_bad_mtu_last_time; 322 323 kmutex_t ips_ip_trash_timer_lock; 324 timeout_id_t ips_ip_ire_expire_id; /* IRE expiration timer. */ 325 struct ipsq_s *ips_ipsq_g_head; 326 uint_t ips_ill_index; /* Used to assign interface indicies */ 327 /* When set search for unused index */ 328 boolean_t ips_ill_index_wrap; 329 330 clock_t ips_ip_ire_arp_time_elapsed; 331 /* Time since IRE cache last flushed */ 332 clock_t ips_ip_ire_rd_time_elapsed; 333 /* ... redirect IREs last flushed */ 334 clock_t ips_ip_ire_pmtu_time_elapsed; 335 /* Time since path mtu increase */ 336 337 uint_t ips_ip_redirect_cnt; 338 /* Num of redirect routes in ftable */ 339 uint_t ips_ipv6_ire_default_count; 340 /* Number of IPv6 IRE_DEFAULT entries */ 341 uint_t ips_ipv6_ire_default_index; 342 /* Walking IPv6 index used to mod in */ 343 344 uint_t ips_loopback_packets; 345 346 /* NDP/NCE structures for IPv4 and IPv6 */ 347 struct ndp_g_s *ips_ndp4; 348 struct ndp_g_s *ips_ndp6; 349 350 /* ip_mroute stuff */ 351 kmutex_t ips_ip_g_mrouter_mutex; 352 353 struct mrtstat *ips_mrtstat; /* Stats for netstat */ 354 int ips_saved_ip_g_forward; 355 356 /* numvifs is only a hint about the max interface being used. */ 357 ushort_t ips_numvifs; 358 kmutex_t ips_numvifs_mutex; 359 360 struct vif *ips_vifs; 361 struct mfcb *ips_mfcs; /* kernel routing table */ 362 struct tbf *ips_tbfs; 363 /* 364 * One-back cache used to locate a tunnel's vif, 365 * given a datagram's src ip address. 366 */ 367 ipaddr_t ips_last_encap_src; 368 struct vif *ips_last_encap_vif; 369 kmutex_t ips_last_encap_lock; /* Protects the above */ 370 371 /* 372 * reg_vif_num is protected by numvifs_mutex 373 */ 374 /* Whether or not special PIM assert processing is enabled. */ 375 ushort_t ips_reg_vif_num; /* Index to Register vif */ 376 int ips_pim_assert; 377 378 union ill_g_head_u *ips_ill_g_heads; /* ILL List Head */ 379 380 kstat_t *ips_loopback_ksp; 381 382 uint_t ips_ipif_src_random; 383 384 struct idl_s *ips_conn_drain_list; /* Array of conn drain lists */ 385 uint_t ips_conn_drain_list_cnt; /* Count of conn_drain_list */ 386 int ips_conn_drain_list_index; /* Next drain_list */ 387 388 /* 389 * ID used to assign next free one. 390 * Increases by one. Once it wraps we search for an unused ID. 391 */ 392 uint_t ips_ip_src_id; 393 boolean_t ips_srcid_wrapped; 394 395 struct srcid_map *ips_srcid_head; 396 krwlock_t ips_srcid_lock; 397 398 uint64_t ips_ipif_g_seqid; 399 union phyint_list_u *ips_phyint_g_list; /* start of phyint list */ 400 401 /* 402 * Reflects value of FAILBACK variable in IPMP config file 403 * /etc/default/mpathd. Default value is B_TRUE. 404 * Set to B_FALSE if user disabled failback by configuring 405 * "FAILBACK=no" in.mpathd uses SIOCSIPMPFAILBACK ioctl to pass this 406 * information to kernel. 407 */ 408 boolean_t ips_ipmp_enable_failback; 409 410 /* ip_neti.c */ 411 hook_family_t ips_ipv4root; 412 hook_family_t ips_ipv6root; 413 414 /* 415 * Hooks for firewalling 416 */ 417 hook_event_t ips_ip4_physical_in_event; 418 hook_event_t ips_ip4_physical_out_event; 419 hook_event_t ips_ip4_forwarding_event; 420 hook_event_t ips_ip4_loopback_in_event; 421 hook_event_t ips_ip4_loopback_out_event; 422 hook_event_t ips_ip4_nic_events; 423 hook_event_t ips_ip6_physical_in_event; 424 hook_event_t ips_ip6_physical_out_event; 425 hook_event_t ips_ip6_forwarding_event; 426 hook_event_t ips_ip6_loopback_in_event; 427 hook_event_t ips_ip6_loopback_out_event; 428 hook_event_t ips_ip6_nic_events; 429 430 hook_event_token_t ips_ipv4firewall_physical_in; 431 hook_event_token_t ips_ipv4firewall_physical_out; 432 hook_event_token_t ips_ipv4firewall_forwarding; 433 hook_event_token_t ips_ipv4firewall_loopback_in; 434 hook_event_token_t ips_ipv4firewall_loopback_out; 435 hook_event_token_t ips_ipv4nicevents; 436 hook_event_token_t ips_ipv6firewall_physical_in; 437 hook_event_token_t ips_ipv6firewall_physical_out; 438 hook_event_token_t ips_ipv6firewall_forwarding; 439 hook_event_token_t ips_ipv6firewall_loopback_in; 440 hook_event_token_t ips_ipv6firewall_loopback_out; 441 hook_event_token_t ips_ipv6nicevents; 442 443 net_data_t ips_ipv4_net_data; 444 net_data_t ips_ipv6_net_data; 445 }; 446 typedef struct ip_stack ip_stack_t; 447 448 /* Finding an ip_stack_t */ 449 #define CONNQ_TO_IPST(_q) (Q_TO_CONN(_q)->conn_netstack->netstack_ip) 450 #define ILLQ_TO_IPST(_q) (((ill_t *)(_q)->q_ptr)->ill_ipst) 451 452 #else /* _KERNEL */ 453 typedef int ip_stack_t; 454 #endif /* _KERNEL */ 455 456 #ifdef __cplusplus 457 } 458 #endif 459 460 #endif /* _INET_IP_STACK_H */ 461