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 /* Copyright (c) 1990 Mentat Inc. */ 27 28 #ifndef _INET_IP_H 29 #define _INET_IP_H 30 31 #pragma ident "%Z%%M% %I% %E% SMI" 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 #include <sys/isa_defs.h> 38 #include <sys/types.h> 39 #include <inet/mib2.h> 40 #include <inet/nd.h> 41 #include <sys/atomic.h> 42 #include <net/if_dl.h> 43 #include <net/if.h> 44 #include <netinet/ip.h> 45 #include <netinet/igmp.h> 46 #include <sys/neti.h> 47 #include <sys/hook.h> 48 #include <sys/hook_event.h> 49 #include <sys/hook_impl.h> 50 #include <inet/ip_stack.h> 51 52 #ifdef _KERNEL 53 #include <netinet/ip6.h> 54 #include <sys/avl.h> 55 #include <sys/vmem.h> 56 #include <sys/squeue.h> 57 #include <net/route.h> 58 #include <sys/systm.h> 59 #include <sys/multidata.h> 60 #include <net/radix.h> 61 #include <sys/modhash.h> 62 63 #ifdef DEBUG 64 #define CONN_DEBUG 65 #endif 66 67 #define IP_DEBUG 68 /* 69 * The mt-streams(9F) flags for the IP module; put here so that other 70 * "drivers" that are actually IP (e.g., ICMP, UDP) can use the same set 71 * of flags. 72 */ 73 #define IP_DEVMTFLAGS D_MP 74 #endif /* _KERNEL */ 75 76 #define IP_MOD_NAME "ip" 77 #define IP_DEV_NAME "/dev/ip" 78 #define IP6_DEV_NAME "/dev/ip6" 79 80 #define UDP_MOD_NAME "udp" 81 #define UDP_DEV_NAME "/dev/udp" 82 #define UDP6_DEV_NAME "/dev/udp6" 83 84 #define TCP_MOD_NAME "tcp" 85 #define TCP_DEV_NAME "/dev/tcp" 86 #define TCP6_DEV_NAME "/dev/tcp6" 87 88 #define SCTP_MOD_NAME "sctp" 89 90 #ifndef _IPADDR_T 91 #define _IPADDR_T 92 typedef uint32_t ipaddr_t; 93 #endif 94 95 /* Number of bits in an address */ 96 #define IP_ABITS 32 97 #define IPV6_ABITS 128 98 99 #define IP_HOST_MASK (ipaddr_t)0xffffffffU 100 101 #define IP_CSUM(mp, off, sum) (~ip_cksum(mp, off, sum) & 0xFFFF) 102 #define IP_CSUM_PARTIAL(mp, off, sum) ip_cksum(mp, off, sum) 103 #define IP_BCSUM_PARTIAL(bp, len, sum) bcksum(bp, len, sum) 104 #define IP_MD_CSUM(pd, off, sum) (~ip_md_cksum(pd, off, sum) & 0xffff) 105 #define IP_MD_CSUM_PARTIAL(pd, off, sum) ip_md_cksum(pd, off, sum) 106 107 /* 108 * Flag to IP write side to indicate that the appln has sent in a pre-built 109 * IP header. Stored in ipha_ident (which is otherwise zero). 110 */ 111 #define IP_HDR_INCLUDED 0xFFFF 112 113 #define ILL_FRAG_HASH_TBL_COUNT ((unsigned int)64) 114 #define ILL_FRAG_HASH_TBL_SIZE (ILL_FRAG_HASH_TBL_COUNT * sizeof (ipfb_t)) 115 116 #define IPV4_ADDR_LEN 4 117 #define IP_ADDR_LEN IPV4_ADDR_LEN 118 #define IP_ARP_PROTO_TYPE 0x0800 119 120 #define IPV4_VERSION 4 121 #define IP_VERSION IPV4_VERSION 122 #define IP_SIMPLE_HDR_LENGTH_IN_WORDS 5 123 #define IP_SIMPLE_HDR_LENGTH 20 124 #define IP_MAX_HDR_LENGTH 60 125 126 #define IP_MAX_OPT_LENGTH (IP_MAX_HDR_LENGTH-IP_SIMPLE_HDR_LENGTH) 127 128 #define IP_MIN_MTU (IP_MAX_HDR_LENGTH + 8) /* 68 bytes */ 129 130 /* 131 * XXX IP_MAXPACKET is defined in <netinet/ip.h> as well. At some point the 132 * 2 files should be cleaned up to remove all redundant definitions. 133 */ 134 #define IP_MAXPACKET 65535 135 #define IP_SIMPLE_HDR_VERSION \ 136 ((IP_VERSION << 4) | IP_SIMPLE_HDR_LENGTH_IN_WORDS) 137 138 #define UDPH_SIZE 8 139 140 /* Leave room for ip_newroute to tack on the src and target addresses */ 141 #define OK_RESOLVER_MP(mp) \ 142 ((mp) && ((mp)->b_wptr - (mp)->b_rptr) >= (2 * IP_ADDR_LEN)) 143 144 /* 145 * Constants and type definitions to support IP IOCTL commands 146 */ 147 #define IP_IOCTL (('i'<<8)|'p') 148 #define IP_IOC_IRE_DELETE 4 149 #define IP_IOC_IRE_DELETE_NO_REPLY 5 150 #define IP_IOC_IRE_ADVISE_NO_REPLY 6 151 #define IP_IOC_RTS_REQUEST 7 152 153 /* Common definitions used by IP IOCTL data structures */ 154 typedef struct ipllcmd_s { 155 uint_t ipllc_cmd; 156 uint_t ipllc_name_offset; 157 uint_t ipllc_name_length; 158 } ipllc_t; 159 160 /* IP IRE Change Command Structure. */ 161 typedef struct ipic_s { 162 ipllc_t ipic_ipllc; 163 uint_t ipic_ire_type; 164 uint_t ipic_max_frag; 165 uint_t ipic_addr_offset; 166 uint_t ipic_addr_length; 167 uint_t ipic_mask_offset; 168 uint_t ipic_mask_length; 169 uint_t ipic_src_addr_offset; 170 uint_t ipic_src_addr_length; 171 uint_t ipic_ll_hdr_offset; 172 uint_t ipic_ll_hdr_length; 173 uint_t ipic_gateway_addr_offset; 174 uint_t ipic_gateway_addr_length; 175 clock_t ipic_rtt; 176 uint32_t ipic_ssthresh; 177 clock_t ipic_rtt_sd; 178 uchar_t ipic_ire_marks; 179 } ipic_t; 180 181 #define ipic_cmd ipic_ipllc.ipllc_cmd 182 #define ipic_ll_name_length ipic_ipllc.ipllc_name_length 183 #define ipic_ll_name_offset ipic_ipllc.ipllc_name_offset 184 185 /* IP IRE Delete Command Structure. */ 186 typedef struct ipid_s { 187 ipllc_t ipid_ipllc; 188 uint_t ipid_ire_type; 189 uint_t ipid_addr_offset; 190 uint_t ipid_addr_length; 191 uint_t ipid_mask_offset; 192 uint_t ipid_mask_length; 193 } ipid_t; 194 195 #define ipid_cmd ipid_ipllc.ipllc_cmd 196 197 #ifdef _KERNEL 198 /* 199 * Temporary state for ip options parser. 200 */ 201 typedef struct ipoptp_s 202 { 203 uint8_t *ipoptp_next; /* next option to look at */ 204 uint8_t *ipoptp_end; /* end of options */ 205 uint8_t *ipoptp_cur; /* start of current option */ 206 uint8_t ipoptp_len; /* length of current option */ 207 uint32_t ipoptp_flags; 208 } ipoptp_t; 209 210 /* 211 * Flag(s) for ipoptp_flags 212 */ 213 #define IPOPTP_ERROR 0x00000001 214 #endif /* _KERNEL */ 215 216 217 /* Controls forwarding of IP packets, set via ndd */ 218 #define IP_FORWARD_NEVER 0 219 #define IP_FORWARD_ALWAYS 1 220 221 #define WE_ARE_FORWARDING(ipst) ((ipst)->ips_ip_g_forward == IP_FORWARD_ALWAYS) 222 223 #define IPH_HDR_LENGTH(ipha) \ 224 ((int)(((ipha_t *)ipha)->ipha_version_and_hdr_length & 0xF) << 2) 225 226 #define IPH_HDR_VERSION(ipha) \ 227 ((int)(((ipha_t *)ipha)->ipha_version_and_hdr_length) >> 4) 228 229 #ifdef _KERNEL 230 /* 231 * IP reassembly macros. We hide starting and ending offsets in b_next and 232 * b_prev of messages on the reassembly queue. The messages are chained using 233 * b_cont. These macros are used in ip_reassemble() so we don't have to see 234 * the ugly casts and assignments. 235 * Note that the offsets are <= 64k i.e. a uint_t is sufficient to represent 236 * them. 237 */ 238 #define IP_REASS_START(mp) ((uint_t)(uintptr_t)((mp)->b_next)) 239 #define IP_REASS_SET_START(mp, u) \ 240 ((mp)->b_next = (mblk_t *)(uintptr_t)(u)) 241 #define IP_REASS_END(mp) ((uint_t)(uintptr_t)((mp)->b_prev)) 242 #define IP_REASS_SET_END(mp, u) \ 243 ((mp)->b_prev = (mblk_t *)(uintptr_t)(u)) 244 245 #define IP_REASS_COMPLETE 0x1 246 #define IP_REASS_PARTIAL 0x2 247 #define IP_REASS_FAILED 0x4 248 249 /* 250 * Test to determine whether this is a module instance of IP or a 251 * driver instance of IP. 252 */ 253 #define CONN_Q(q) (WR(q)->q_next == NULL) 254 255 #define Q_TO_CONN(q) ((conn_t *)(q)->q_ptr) 256 #define Q_TO_TCP(q) (Q_TO_CONN((q))->conn_tcp) 257 #define Q_TO_UDP(q) (Q_TO_CONN((q))->conn_udp) 258 #define Q_TO_ICMP(q) (Q_TO_CONN((q))->conn_icmp) 259 #define Q_TO_RTS(q) (Q_TO_CONN((q))->conn_rts) 260 261 /* 262 * The following two macros are used by IP to get the appropriate 263 * wq and rq for a conn. If it is a TCP conn, then we need 264 * tcp_wq/tcp_rq else, conn_wq/conn_rq. IP can use conn_wq and conn_rq 265 * from a conn directly if it knows that the conn is not TCP. 266 */ 267 #define CONNP_TO_WQ(connp) \ 268 (IPCL_IS_TCP(connp) ? (connp)->conn_tcp->tcp_wq : (connp)->conn_wq) 269 270 #define CONNP_TO_RQ(connp) RD(CONNP_TO_WQ(connp)) 271 272 #define GRAB_CONN_LOCK(q) { \ 273 if (q != NULL && CONN_Q(q)) \ 274 mutex_enter(&(Q_TO_CONN(q))->conn_lock); \ 275 } 276 277 #define RELEASE_CONN_LOCK(q) { \ 278 if (q != NULL && CONN_Q(q)) \ 279 mutex_exit(&(Q_TO_CONN(q))->conn_lock); \ 280 } 281 282 /* "Congestion controlled" protocol */ 283 #define IP_FLOW_CONTROLLED_ULP(p) ((p) == IPPROTO_TCP || (p) == IPPROTO_SCTP) 284 285 /* 286 * Complete the pending operation. Usually an ioctl. Can also 287 * be a bind or option management request that got enqueued 288 * in an ipsq_t. Called on completion of the operation. 289 */ 290 #define CONN_OPER_PENDING_DONE(connp) { \ 291 mutex_enter(&(connp)->conn_lock); \ 292 (connp)->conn_oper_pending_ill = NULL; \ 293 cv_broadcast(&(connp)->conn_refcv); \ 294 mutex_exit(&(connp)->conn_lock); \ 295 CONN_DEC_REF(connp); \ 296 } 297 298 /* Get the credential of an IP queue of unknown type */ 299 #define GET_QUEUE_CRED(wq) \ 300 ((wq)->q_next ? (((ill_t *)(wq)->q_ptr)->ill_credp) \ 301 : ((Q_TO_CONN((wq)))->conn_cred)) 302 303 /* 304 * Flags for the various ip_fanout_* routines. 305 */ 306 #define IP_FF_SEND_ICMP 0x01 /* Send an ICMP error */ 307 #define IP_FF_HDR_COMPLETE 0x02 /* Call ip_hdr_complete if error */ 308 #define IP_FF_CKSUM 0x04 /* Recompute ipha_cksum if error */ 309 #define IP_FF_RAWIP 0x08 /* Use rawip mib variable */ 310 #define IP_FF_SRC_QUENCH 0x10 /* OK to send ICMP_SOURCE_QUENCH */ 311 #define IP_FF_SYN_ADDIRE 0x20 /* Add IRE if TCP syn packet */ 312 #define IP_FF_IPINFO 0x80 /* Used for both V4 and V6 */ 313 #define IP_FF_SEND_SLLA 0x100 /* Send source link layer info ? */ 314 #define IPV6_REACHABILITY_CONFIRMATION 0x200 /* Flags for ip_xmit_v6 */ 315 #define IP_FF_NO_MCAST_LOOP 0x400 /* No multicasts for sending zone */ 316 317 /* 318 * Following flags are used by IPQoS to determine if policy processing is 319 * required. 320 */ 321 #define IP6_NO_IPPOLICY 0x800 /* Don't do IPQoS processing */ 322 #define IP6_IN_LLMCAST 0x1000 /* Multicast */ 323 324 #define IP_FF_LOOPBACK 0x2000 /* Loopback fanout */ 325 326 #ifndef IRE_DB_TYPE 327 #define IRE_DB_TYPE M_SIG 328 #endif 329 330 #ifndef IRE_DB_REQ_TYPE 331 #define IRE_DB_REQ_TYPE M_PCSIG 332 #endif 333 334 #ifndef IRE_ARPRESOLVE_TYPE 335 #define IRE_ARPRESOLVE_TYPE M_EVENT 336 #endif 337 338 /* 339 * Values for squeue switch: 340 */ 341 342 #define IP_SQUEUE_ENTER_NODRAIN 1 343 #define IP_SQUEUE_ENTER 2 344 /* 345 * This is part of the interface between Transport provider and 346 * IP which can be used to set policy information. This is usually 347 * accompanied with O_T_BIND_REQ/T_BIND_REQ.ip_bind assumes that 348 * only IPSEC_POLICY_SET is there when it is found in the chain. 349 * The information contained is an struct ipsec_req_t. On success 350 * or failure, either the T_BIND_ACK or the T_ERROR_ACK is returned. 351 * IPSEC_POLICY_SET is never returned. 352 */ 353 #define IPSEC_POLICY_SET M_SETOPTS 354 355 #define IRE_IS_LOCAL(ire) ((ire != NULL) && \ 356 ((ire)->ire_type & (IRE_LOCAL | IRE_LOOPBACK))) 357 358 #define IRE_IS_TARGET(ire) ((ire != NULL) && \ 359 ((ire)->ire_type != IRE_BROADCAST)) 360 361 /* IP Fragmentation Reassembly Header */ 362 typedef struct ipf_s { 363 struct ipf_s *ipf_hash_next; 364 struct ipf_s **ipf_ptphn; /* Pointer to previous hash next. */ 365 uint32_t ipf_ident; /* Ident to match. */ 366 uint8_t ipf_protocol; /* Protocol to match. */ 367 uchar_t ipf_last_frag_seen : 1; /* Last fragment seen ? */ 368 time_t ipf_timestamp; /* Reassembly start time. */ 369 mblk_t *ipf_mp; /* mblk we live in. */ 370 mblk_t *ipf_tail_mp; /* Frag queue tail pointer. */ 371 int ipf_hole_cnt; /* Number of holes (hard-case). */ 372 int ipf_end; /* Tail end offset (0 -> hard-case). */ 373 uint_t ipf_gen; /* Frag queue generation */ 374 size_t ipf_count; /* Count of bytes used by frag */ 375 uint_t ipf_nf_hdr_len; /* Length of nonfragmented header */ 376 in6_addr_t ipf_v6src; /* IPv6 source address */ 377 in6_addr_t ipf_v6dst; /* IPv6 dest address */ 378 uint_t ipf_prev_nexthdr_offset; /* Offset for nexthdr value */ 379 uint8_t ipf_ecn; /* ECN info for the fragments */ 380 uint8_t ipf_num_dups; /* Number of times dup frags recvd */ 381 uint16_t ipf_checksum_flags; /* Hardware checksum flags */ 382 uint32_t ipf_checksum; /* Partial checksum of fragment data */ 383 } ipf_t; 384 385 #define ipf_src V4_PART_OF_V6(ipf_v6src) 386 #define ipf_dst V4_PART_OF_V6(ipf_v6dst) 387 388 typedef enum { 389 IB_PKT = 0x01, 390 OB_PKT = 0x02 391 } ip_pkt_t; 392 393 #define UPDATE_IB_PKT_COUNT(ire)\ 394 { \ 395 (ire)->ire_ib_pkt_count++; \ 396 if ((ire)->ire_ipif != NULL) { \ 397 /* \ 398 * forwarding packet \ 399 */ \ 400 if ((ire)->ire_type & (IRE_LOCAL|IRE_BROADCAST)) \ 401 atomic_add_32(&(ire)->ire_ipif->ipif_ib_pkt_count, 1);\ 402 else \ 403 atomic_add_32(&(ire)->ire_ipif->ipif_fo_pkt_count, 1);\ 404 } \ 405 } 406 #define UPDATE_OB_PKT_COUNT(ire)\ 407 { \ 408 (ire)->ire_ob_pkt_count++;\ 409 if ((ire)->ire_ipif != NULL) { \ 410 atomic_add_32(&(ire)->ire_ipif->ipif_ob_pkt_count, 1); \ 411 } \ 412 } 413 414 415 #define IP_RPUT_LOCAL(q, mp, ipha, ire, recv_ill) \ 416 { \ 417 switch (ipha->ipha_protocol) { \ 418 case IPPROTO_UDP: \ 419 ip_udp_input(q, mp, ipha, ire, recv_ill); \ 420 break; \ 421 default: \ 422 ip_proto_input(q, mp, ipha, ire, recv_ill, B_FALSE); \ 423 break; \ 424 } \ 425 } 426 427 /* 428 * NCE_EXPIRED is TRUE when we have a non-permanent nce that was 429 * found to be REACHABLE more than ip_ire_arp_interval ms ago. 430 * This macro is used to age existing nce_t entries. The 431 * nce's will get cleaned up in the following circumstances: 432 * - ip_ire_trash_reclaim will free nce's using ndp_cache_reclaim 433 * when memory is low, 434 * - ip_arp_news, when updates are received. 435 * - if the nce is NCE_EXPIRED(), it will deleted, so that a new 436 * arp request will need to be triggered from an ND_INITIAL nce. 437 * 438 * Note that the nce state transition follows the pattern: 439 * ND_INITIAL -> ND_INCOMPLETE -> ND_REACHABLE 440 * after which the nce is deleted when it has expired. 441 * 442 * nce_last is the timestamp that indicates when the nce_res_mp in the 443 * nce_t was last updated to a valid link-layer address. nce_last gets 444 * modified/updated : 445 * - when the nce is created 446 * - every time we get a sane arp response for the nce. 447 */ 448 #define NCE_EXPIRED(nce, ipst) (nce->nce_last > 0 && \ 449 ((nce->nce_flags & NCE_F_PERMANENT) == 0) && \ 450 ((TICK_TO_MSEC(lbolt64) - nce->nce_last) > \ 451 (ipst)->ips_ip_ire_arp_interval)) 452 453 #endif /* _KERNEL */ 454 455 /* ICMP types */ 456 #define ICMP_ECHO_REPLY 0 457 #define ICMP_DEST_UNREACHABLE 3 458 #define ICMP_SOURCE_QUENCH 4 459 #define ICMP_REDIRECT 5 460 #define ICMP_ECHO_REQUEST 8 461 #define ICMP_ROUTER_ADVERTISEMENT 9 462 #define ICMP_ROUTER_SOLICITATION 10 463 #define ICMP_TIME_EXCEEDED 11 464 #define ICMP_PARAM_PROBLEM 12 465 #define ICMP_TIME_STAMP_REQUEST 13 466 #define ICMP_TIME_STAMP_REPLY 14 467 #define ICMP_INFO_REQUEST 15 468 #define ICMP_INFO_REPLY 16 469 #define ICMP_ADDRESS_MASK_REQUEST 17 470 #define ICMP_ADDRESS_MASK_REPLY 18 471 472 /* ICMP_TIME_EXCEEDED codes */ 473 #define ICMP_TTL_EXCEEDED 0 474 #define ICMP_REASSEMBLY_TIME_EXCEEDED 1 475 476 /* ICMP_DEST_UNREACHABLE codes */ 477 #define ICMP_NET_UNREACHABLE 0 478 #define ICMP_HOST_UNREACHABLE 1 479 #define ICMP_PROTOCOL_UNREACHABLE 2 480 #define ICMP_PORT_UNREACHABLE 3 481 #define ICMP_FRAGMENTATION_NEEDED 4 482 #define ICMP_SOURCE_ROUTE_FAILED 5 483 #define ICMP_DEST_NET_UNKNOWN 6 484 #define ICMP_DEST_HOST_UNKNOWN 7 485 #define ICMP_SRC_HOST_ISOLATED 8 486 #define ICMP_DEST_NET_UNREACH_ADMIN 9 487 #define ICMP_DEST_HOST_UNREACH_ADMIN 10 488 #define ICMP_DEST_NET_UNREACH_TOS 11 489 #define ICMP_DEST_HOST_UNREACH_TOS 12 490 491 /* ICMP Header Structure */ 492 typedef struct icmph_s { 493 uint8_t icmph_type; 494 uint8_t icmph_code; 495 uint16_t icmph_checksum; 496 union { 497 struct { /* ECHO request/response structure */ 498 uint16_t u_echo_ident; 499 uint16_t u_echo_seqnum; 500 } u_echo; 501 struct { /* Destination unreachable structure */ 502 uint16_t u_du_zero; 503 uint16_t u_du_mtu; 504 } u_du; 505 struct { /* Parameter problem structure */ 506 uint8_t u_pp_ptr; 507 uint8_t u_pp_rsvd[3]; 508 } u_pp; 509 struct { /* Redirect structure */ 510 ipaddr_t u_rd_gateway; 511 } u_rd; 512 } icmph_u; 513 } icmph_t; 514 515 #define icmph_echo_ident icmph_u.u_echo.u_echo_ident 516 #define icmph_echo_seqnum icmph_u.u_echo.u_echo_seqnum 517 #define icmph_du_zero icmph_u.u_du.u_du_zero 518 #define icmph_du_mtu icmph_u.u_du.u_du_mtu 519 #define icmph_pp_ptr icmph_u.u_pp.u_pp_ptr 520 #define icmph_rd_gateway icmph_u.u_rd.u_rd_gateway 521 522 #define ICMPH_SIZE 8 523 524 /* 525 * Minimum length of transport layer header included in an ICMP error 526 * message for it to be considered valid. 527 */ 528 #define ICMP_MIN_TP_HDR_LEN 8 529 530 /* Aligned IP header */ 531 typedef struct ipha_s { 532 uint8_t ipha_version_and_hdr_length; 533 uint8_t ipha_type_of_service; 534 uint16_t ipha_length; 535 uint16_t ipha_ident; 536 uint16_t ipha_fragment_offset_and_flags; 537 uint8_t ipha_ttl; 538 uint8_t ipha_protocol; 539 uint16_t ipha_hdr_checksum; 540 ipaddr_t ipha_src; 541 ipaddr_t ipha_dst; 542 } ipha_t; 543 544 #define IPH_DF 0x4000 /* Don't fragment */ 545 #define IPH_MF 0x2000 /* More fragments to come */ 546 #define IPH_OFFSET 0x1FFF /* Where the offset lives */ 547 #define IPH_FRAG_HDR 0x8000 /* IPv6 don't fragment bit */ 548 549 /* ECN code points for IPv4 TOS byte and IPv6 traffic class octet. */ 550 #define IPH_ECN_NECT 0x0 /* Not ECN-Capabable Transport */ 551 #define IPH_ECN_ECT1 0x1 /* ECN-Capable Transport, ECT(1) */ 552 #define IPH_ECN_ECT0 0x2 /* ECN-Capable Transport, ECT(0) */ 553 #define IPH_ECN_CE 0x3 /* ECN-Congestion Experienced (CE) */ 554 555 /* IP Mac info structure */ 556 typedef struct ip_m_s { 557 t_uscalar_t ip_m_mac_type; /* From <sys/dlpi.h> */ 558 int ip_m_type; /* From <net/if_types.h> */ 559 boolean_t (*ip_m_v4mapinfo)(uint_t, uint8_t *, uint8_t *, 560 uint32_t *, ipaddr_t *); 561 boolean_t (*ip_m_v6mapinfo)(uint_t, uint8_t *, uint8_t *, 562 uint32_t *, in6_addr_t *); 563 boolean_t (*ip_m_v6intfid)(uint_t, uint8_t *, in6_addr_t *); 564 } ip_m_t; 565 566 /* 567 * The following functions attempt to reduce the link layer dependency 568 * of the IP stack. The current set of link specific operations are: 569 * a. map from IPv4 class D (224.0/4) multicast address range to the link 570 * layer multicast address range. 571 * b. map from IPv6 multicast address range (ff00::/8) to the link 572 * layer multicast address range. 573 * c. derive the default IPv6 interface identifier from the link layer 574 * address. 575 */ 576 #define MEDIA_V4MINFO(ip_m, plen, bphys, maddr, hwxp, v4ptr) \ 577 (((ip_m)->ip_m_v4mapinfo != NULL) && \ 578 (*(ip_m)->ip_m_v4mapinfo)(plen, bphys, maddr, hwxp, v4ptr)) 579 #define MEDIA_V6INTFID(ip_m, plen, phys, v6ptr) \ 580 (((ip_m)->ip_m_v6intfid != NULL) && \ 581 (*(ip_m)->ip_m_v6intfid)(plen, phys, v6ptr)) 582 #define MEDIA_V6MINFO(ip_m, plen, bphys, maddr, hwxp, v6ptr) \ 583 (((ip_m)->ip_m_v6mapinfo != NULL) && \ 584 (*(ip_m)->ip_m_v6mapinfo)(plen, bphys, maddr, hwxp, v6ptr)) 585 586 /* Router entry types */ 587 #define IRE_BROADCAST 0x0001 /* Route entry for broadcast address */ 588 #define IRE_DEFAULT 0x0002 /* Route entry for default gateway */ 589 #define IRE_LOCAL 0x0004 /* Route entry for local address */ 590 #define IRE_LOOPBACK 0x0008 /* Route entry for loopback address */ 591 #define IRE_PREFIX 0x0010 /* Route entry for prefix routes */ 592 #define IRE_CACHE 0x0020 /* Cached Route entry */ 593 #define IRE_IF_NORESOLVER 0x0040 /* Route entry for local interface */ 594 /* net without any address mapping. */ 595 #define IRE_IF_RESOLVER 0x0080 /* Route entry for local interface */ 596 /* net with resolver. */ 597 #define IRE_HOST 0x0100 /* Host route entry */ 598 #define IRE_HOST_REDIRECT 0x0200 /* only used for T_SVR4_OPTMGMT_REQ */ 599 600 #define IRE_INTERFACE (IRE_IF_NORESOLVER | IRE_IF_RESOLVER) 601 #define IRE_OFFSUBNET (IRE_DEFAULT | IRE_PREFIX | IRE_HOST) 602 #define IRE_CACHETABLE (IRE_CACHE | IRE_BROADCAST | IRE_LOCAL | \ 603 IRE_LOOPBACK) 604 #define IRE_FORWARDTABLE (IRE_INTERFACE | IRE_OFFSUBNET) 605 606 /* 607 * If an IRE is marked with IRE_MARK_CONDEMNED, the last walker of 608 * the bucket should delete this IRE from this bucket. 609 */ 610 #define IRE_MARK_CONDEMNED 0x0001 611 /* 612 * If a broadcast IRE is marked with IRE_MARK_NORECV, ip_rput will drop the 613 * broadcast packets received on that interface. This is marked only 614 * on broadcast ires. Employed by IPMP, where we have multiple NICs on the 615 * same subnet receiving the same broadcast packet. 616 */ 617 #define IRE_MARK_NORECV 0x0002 618 /* 619 * IRE_CACHE marked this way won't be returned by ire_cache_lookup. Need 620 * to look specifically using MATCH_IRE_MARK_HIDDEN. Used by IPMP. 621 */ 622 #define IRE_MARK_HIDDEN 0x0004 /* Typically Used by in.mpathd */ 623 624 /* 625 * ire with IRE_MARK_NOADD is created in ip_newroute_ipif, when outgoing 626 * interface is specified by IP_XMIT_IF socket option. This ire is not 627 * added in IRE_CACHE. 628 */ 629 #define IRE_MARK_NOADD 0x0008 /* Mark not to add ire in cache */ 630 631 /* 632 * IRE marked with IRE_MARK_TEMPORARY means that this IRE has been used 633 * either for forwarding a packet or has not been used for sending 634 * traffic on TCP connections terminated on this system. In both 635 * cases, this IRE is the first to go when IRE is being cleaned up. 636 */ 637 #define IRE_MARK_TEMPORARY 0x0010 638 639 /* 640 * IRE marked with IRE_MARK_USESRC_CHECK means that while adding an IRE with 641 * this mark, additional atomic checks need to be performed. For eg: by the 642 * time an IRE_CACHE is created, sent up to ARP and then comes back to IP; the 643 * usesrc grouping could have changed in which case we want to fail adding 644 * the IRE_CACHE entry 645 */ 646 #define IRE_MARK_USESRC_CHECK 0x0020 647 648 /* 649 * IRE_MARK_PRIVATE_ADDR is used for IP_NEXTHOP. When IP_NEXTHOP is set, the 650 * routing table lookup for the destination is bypassed and the packet is 651 * sent directly to the specified nexthop. The associated IRE_CACHE entries 652 * should be marked with IRE_MARK_PRIVATE_ADDR flag so that they don't show up 653 * in regular ire cache lookups. 654 */ 655 #define IRE_MARK_PRIVATE_ADDR 0x0040 656 657 /* 658 * When we send an ARP resolution query for the nexthop gateway's ire, 659 * we use esballoc to create the ire_t in the AR_ENTRY_QUERY mblk 660 * chain, and mark its ire_marks with IRE_MARK_UNCACHED. This flag 661 * indicates that information from ARP has not been transferred to a 662 * permanent IRE_CACHE entry. The flag is reset only when the 663 * information is successfully transferred to an ire_cache entry (in 664 * ire_add()). Attempting to free the AR_ENTRY_QUERY mblk chain prior 665 * to ire_add (e.g., from arp, or from ip`ip_wput_nondata) will 666 * require that the resources (incomplete ire_cache and/or nce) must 667 * be cleaned up. The free callback routine (ire_freemblk()) checks 668 * for IRE_MARK_UNCACHED to see if any resources that are pinned down 669 * will need to be cleaned up or not. 670 */ 671 672 #define IRE_MARK_UNCACHED 0x0080 673 674 /* 675 * The comment below (and for other netstack_t references) refers 676 * to the fact that we only do netstack_hold in particular cases, 677 * such as the references from open streams (ill_t and conn_t's 678 * pointers). Internally within IP we rely on IP's ability to cleanup e.g. 679 * ire_t's when an ill goes away. 680 */ 681 typedef struct ire_expire_arg_s { 682 int iea_flush_flag; 683 ip_stack_t *iea_ipst; /* Does not have a netstack_hold */ 684 } ire_expire_arg_t; 685 686 /* Flags with ire_expire routine */ 687 #define FLUSH_ARP_TIME 0x0001 /* ARP info potentially stale timer */ 688 #define FLUSH_REDIRECT_TIME 0x0002 /* Redirects potentially stale */ 689 #define FLUSH_MTU_TIME 0x0004 /* Include path MTU per RFC 1191 */ 690 691 /* Arguments to ire_flush_cache() */ 692 #define IRE_FLUSH_DELETE 0 693 #define IRE_FLUSH_ADD 1 694 695 /* 696 * Open/close synchronization flags. 697 * These are kept in a separate field in the conn and the synchronization 698 * depends on the atomic 32 bit access to that field. 699 */ 700 #define CONN_CLOSING 0x01 /* ip_close waiting for ip_wsrv */ 701 #define CONN_IPSEC_LOAD_WAIT 0x02 /* waiting for load */ 702 #define CONN_CONDEMNED 0x04 /* conn is closing, no more refs */ 703 #define CONN_INCIPIENT 0x08 /* conn not yet visible, no refs */ 704 #define CONN_QUIESCED 0x10 /* conn is now quiescent */ 705 706 /* Used to check connection state flags before caching the IRE */ 707 #define CONN_CACHE_IRE(connp) \ 708 (!((connp)->conn_state_flags & (CONN_CLOSING|CONN_CONDEMNED))) 709 710 /* 711 * Parameter to ip_output giving the identity of the caller. 712 * IP_WSRV means the packet was enqueued in the STREAMS queue 713 * due to flow control and is now being reprocessed in the context of 714 * the STREAMS service procedure, consequent to flow control relief. 715 * IRE_SEND means the packet is being reprocessed consequent to an 716 * ire cache creation and addition and this may or may not be happening 717 * in the service procedure context. Anything other than the above 2 718 * cases is identified as IP_WPUT. Most commonly this is the case of 719 * packets coming down from the application. 720 */ 721 #ifdef _KERNEL 722 #define IP_WSRV 1 /* Called from ip_wsrv */ 723 #define IP_WPUT 2 /* Called from ip_wput */ 724 #define IRE_SEND 3 /* Called from ire_send */ 725 726 /* 727 * Extra structures need for per-src-addr filtering (IGMPv3/MLDv2) 728 */ 729 #define MAX_FILTER_SIZE 64 730 731 typedef struct slist_s { 732 int sl_numsrc; 733 in6_addr_t sl_addr[MAX_FILTER_SIZE]; 734 } slist_t; 735 736 /* 737 * Following struct is used to maintain retransmission state for 738 * a multicast group. One rtx_state_t struct is an in-line field 739 * of the ilm_t struct; the slist_ts in the rtx_state_t struct are 740 * alloc'd as needed. 741 */ 742 typedef struct rtx_state_s { 743 uint_t rtx_timer; /* retrans timer */ 744 int rtx_cnt; /* retrans count */ 745 int rtx_fmode_cnt; /* retrans count for fmode change */ 746 slist_t *rtx_allow; 747 slist_t *rtx_block; 748 } rtx_state_t; 749 750 /* 751 * Used to construct list of multicast address records that will be 752 * sent in a single listener report. 753 */ 754 typedef struct mrec_s { 755 struct mrec_s *mrec_next; 756 uint8_t mrec_type; 757 uint8_t mrec_auxlen; /* currently unused */ 758 in6_addr_t mrec_group; 759 slist_t mrec_srcs; 760 } mrec_t; 761 762 /* Group membership list per upper conn */ 763 /* 764 * XXX add ilg info for ifaddr/ifindex. 765 * XXX can we make ilg survive an ifconfig unplumb + plumb 766 * by setting the ipif/ill to NULL and recover that later? 767 * 768 * ilg_ipif is used by IPv4 as multicast groups are joined using an interface 769 * address (ipif). 770 * ilg_ill is used by IPv6 as multicast groups are joined using an interface 771 * index (phyint->phyint_ifindex). 772 * ilg_ill is NULL for IPv4 and ilg_ipif is NULL for IPv6. 773 * 774 * ilg records the state of multicast memberships of a socket end point. 775 * ilm records the state of multicast memberships with the driver and is 776 * maintained per interface. 777 * 778 * Notes : 779 * 780 * 1) There is no direct link between a given ilg and ilm. If the 781 * application has joined a group G with ifindex I, we will have 782 * an ilg with ilg_v6group and ilg_ill. There will be a corresponding 783 * ilm with ilm_ill/ilm_v6addr recording the multicast membership. 784 * To delete the membership, 785 * 786 * a) Search for ilg matching on G and I with ilg_v6group 787 * and ilg_ill. Delete ilg_ill. 788 * b) Search the corresponding ilm matching on G and I with 789 * ilm_v6addr and ilm_ill. Delete ilm. 790 * 791 * In IPv4, the only difference is, we look using ipifs instead of 792 * ills. 793 * 794 * 2) With IP multipathing, we want to keep receiving even after the 795 * interface has failed. We do this by moving multicast memberships 796 * to a new_ill within the group. This is acheived by sending 797 * DL_DISABMULTI_REQS on ilg_ill/ilm_ill and sending DL_ENABMULTIREQS 798 * on the new_ill and changing ilg_ill/ilm_ill to new_ill. But, we 799 * need to be able to delete memberships which will still come down 800 * with the ifindex of the old ill which is what the application 801 * knows of. Thus we store the ilm_/ilg_orig_ifindex to keep track 802 * of where we joined initially so that we can lookup even after we 803 * moved the membership. It is also used for moving back the membership 804 * when the old ill has been repaired. This is done by looking up for 805 * ilms with ilm_orig_ifindex matching on the old ill's ifindex. Only 806 * ilms actually move from old ill to new ill. ilgs don't move (just 807 * the ilg_ill is changed when it moves) as it just records the state 808 * of the application that has joined a group G where as ilm records 809 * the state joined with the driver. Thus when we send DL_XXXMULTI_REQs 810 * we also need to keep the ilm in the right ill. 811 * 812 * In IPv4, as ipifs move from old ill to new_ill, ilgs and ilms move 813 * implicitly as we use only ipifs in IPv4. Thus, one can always lookup 814 * a given ilm/ilg even after it fails without the support of 815 * orig_ifindex. We move ilms still to record the driver state as 816 * mentioned above. 817 */ 818 819 /* 820 * The ilg_t and ilm_t members are protected by ipsq. They can be changed only 821 * by a thread executing in the ipsq. In other words add/delete of a 822 * multicast group has to execute in the ipsq. 823 */ 824 #define ILG_DELETED 0x1 /* ilg_flags */ 825 typedef struct ilg_s { 826 in6_addr_t ilg_v6group; 827 struct ipif_s *ilg_ipif; /* Logical interface we are member on */ 828 struct ill_s *ilg_ill; /* Used by IPv6 */ 829 int ilg_orig_ifindex; /* Interface originally joined on */ 830 uint_t ilg_flags; 831 mcast_record_t ilg_fmode; /* MODE_IS_INCLUDE/MODE_IS_EXCLUDE */ 832 slist_t *ilg_filter; 833 } ilg_t; 834 835 836 /* 837 * Multicast address list entry for lower ill. 838 * ilm_ipif is used by IPv4 as multicast groups are joined using ipif. 839 * ilm_ill is used by IPv6 as multicast groups are joined using ill. 840 * ilm_ill is NULL for IPv4 and ilm_ipif is NULL for IPv6. 841 * 842 * The comment below (and for other netstack_t references) refers 843 * to the fact that we only do netstack_hold in particular cases, 844 * such as the references from open streams (ill_t and conn_t's 845 * pointers). Internally within IP we rely on IP's ability to cleanup e.g. 846 * ire_t's when an ill goes away. 847 */ 848 #define ILM_DELETED 0x1 /* ilm_flags */ 849 typedef struct ilm_s { 850 in6_addr_t ilm_v6addr; 851 int ilm_refcnt; 852 uint_t ilm_timer; /* IGMP/MLD query resp timer, in msec */ 853 struct ipif_s *ilm_ipif; /* Back pointer to ipif for IPv4 */ 854 struct ilm_s *ilm_next; /* Linked list for each ill */ 855 uint_t ilm_state; /* state of the membership */ 856 struct ill_s *ilm_ill; /* Back pointer to ill for IPv6 */ 857 int ilm_orig_ifindex; /* V6_MULTICAST_IF/ilm_ipif index */ 858 uint_t ilm_flags; 859 boolean_t ilm_is_new; /* new ilm */ 860 boolean_t ilm_notify_driver; /* Need to notify the driver */ 861 zoneid_t ilm_zoneid; 862 int ilm_no_ilg_cnt; /* number of joins w/ no ilg */ 863 mcast_record_t ilm_fmode; /* MODE_IS_INCLUDE/MODE_IS_EXCLUDE */ 864 slist_t *ilm_filter; /* source filter list */ 865 slist_t *ilm_pendsrcs; /* relevant src addrs for pending req */ 866 rtx_state_t ilm_rtx; /* SCR retransmission state */ 867 ip_stack_t *ilm_ipst; /* Does not have a netstack_hold */ 868 } ilm_t; 869 870 #define ilm_addr V4_PART_OF_V6(ilm_v6addr) 871 872 /* 873 * ilm_walker_cleanup needs to execute when the ilm_walker_cnt goes down to 874 * zero. In addition it needs to block new walkers while it is unlinking ilm's 875 * from the list. Thus simple atomics for the ill_ilm_walker_cnt don't suffice. 876 */ 877 #define ILM_WALKER_HOLD(ill) { \ 878 mutex_enter(&(ill)->ill_lock); \ 879 ill->ill_ilm_walker_cnt++; \ 880 mutex_exit(&(ill)->ill_lock); \ 881 } 882 883 #define ILM_WALKER_RELE(ill) { \ 884 mutex_enter(&(ill)->ill_lock); \ 885 (ill)->ill_ilm_walker_cnt--; \ 886 if ((ill)->ill_ilm_walker_cnt == 0 && (ill)->ill_ilm_cleanup_reqd) \ 887 ilm_walker_cleanup(ill); \ 888 mutex_exit(&(ill)->ill_lock); \ 889 } 890 891 /* 892 * Soft reference to an IPsec SA. 893 * 894 * On relative terms, conn's can be persistant (living as long as the 895 * processes which create them), while SA's are ephemeral (dying when 896 * they hit their time-based or byte-based lifetimes). 897 * 898 * We could hold a hard reference to an SA from an ipsec_latch_t, 899 * but this would cause expired SA's to linger for a potentially 900 * unbounded time. 901 * 902 * Instead, we remember the hash bucket number and bucket generation 903 * in addition to the pointer. The bucket generation is incremented on 904 * each deletion. 905 */ 906 typedef struct ipsa_ref_s 907 { 908 struct ipsa_s *ipsr_sa; 909 struct isaf_s *ipsr_bucket; 910 uint64_t ipsr_gen; 911 } ipsa_ref_t; 912 913 /* 914 * IPsec "latching" state. 915 * 916 * In the presence of IPsec policy, fully-bound conn's bind a connection 917 * to more than just the 5-tuple, but also a specific IPsec action and 918 * identity-pair. 919 * 920 * As an optimization, we also cache soft references to IPsec SA's 921 * here so that we can fast-path around most of the work needed for 922 * outbound IPsec SA selection. 923 * 924 * Were it not for TCP's detached connections, this state would be 925 * in-line in conn_t; instead, this is in a separate structure so it 926 * can be handed off to TCP when a connection is detached. 927 */ 928 typedef struct ipsec_latch_s 929 { 930 kmutex_t ipl_lock; 931 uint32_t ipl_refcnt; 932 933 uint64_t ipl_unique; 934 struct ipsec_policy_s *ipl_in_policy; /* latched policy (in) */ 935 struct ipsec_policy_s *ipl_out_policy; /* latched policy (out) */ 936 struct ipsec_action_s *ipl_in_action; /* latched action (in) */ 937 struct ipsec_action_s *ipl_out_action; /* latched action (out) */ 938 cred_t *ipl_local_id; 939 struct ipsid_s *ipl_local_cid; 940 struct ipsid_s *ipl_remote_cid; 941 unsigned int 942 ipl_out_action_latched : 1, 943 ipl_in_action_latched : 1, 944 ipl_out_policy_latched : 1, 945 ipl_in_policy_latched : 1, 946 947 ipl_ids_latched : 1, 948 949 ipl_pad_to_bit_31 : 27; 950 951 ipsa_ref_t ipl_ref[2]; /* 0: ESP, 1: AH */ 952 953 } ipsec_latch_t; 954 955 #define IPLATCH_REFHOLD(ipl) { \ 956 atomic_add_32(&(ipl)->ipl_refcnt, 1); \ 957 ASSERT((ipl)->ipl_refcnt != 0); \ 958 } 959 960 #define IPLATCH_REFRELE(ipl, ns) { \ 961 ASSERT((ipl)->ipl_refcnt != 0); \ 962 membar_exit(); \ 963 if (atomic_add_32_nv(&(ipl)->ipl_refcnt, -1) == 0) \ 964 iplatch_free(ipl, ns); \ 965 } 966 967 /* 968 * peer identity structure. 969 */ 970 971 typedef struct conn_s conn_t; 972 973 /* 974 * The old IP client structure "ipc_t" is gone. All the data is stored in the 975 * connection structure "conn_t" now. The mapping of old and new fields looks 976 * like this: 977 * 978 * ipc_ulp conn_ulp 979 * ipc_rq conn_rq 980 * ipc_wq conn_wq 981 * 982 * ipc_laddr conn_src 983 * ipc_faddr conn_rem 984 * ipc_v6laddr conn_srcv6 985 * ipc_v6faddr conn_remv6 986 * 987 * ipc_lport conn_lport 988 * ipc_fport conn_fport 989 * ipc_ports conn_ports 990 * 991 * ipc_policy conn_policy 992 * ipc_latch conn_latch 993 * 994 * ipc_irc_lock conn_lock 995 * ipc_ire_cache conn_ire_cache 996 * 997 * ipc_state_flags conn_state_flags 998 * ipc_outgoing_ill conn_outgoing_ill 999 * 1000 * ipc_dontroute conn_dontroute 1001 * ipc_loopback conn_loopback 1002 * ipc_broadcast conn_broadcast 1003 * ipc_reuseaddr conn_reuseaddr 1004 * 1005 * ipc_multicast_loop conn_multicast_loop 1006 * ipc_multi_router conn_multi_router 1007 * ipc_draining conn_draining 1008 * 1009 * ipc_did_putbq conn_did_putbq 1010 * ipc_unspec_src conn_unspec_src 1011 * ipc_policy_cached conn_policy_cached 1012 * 1013 * ipc_in_enforce_policy conn_in_enforce_policy 1014 * ipc_out_enforce_policy conn_out_enforce_policy 1015 * ipc_af_isv6 conn_af_isv6 1016 * ipc_pkt_isv6 conn_pkt_isv6 1017 * 1018 * ipc_ipv6_recvpktinfo conn_ipv6_recvpktinfo 1019 * 1020 * ipc_ipv6_recvhoplimit conn_ipv6_recvhoplimit 1021 * ipc_ipv6_recvhopopts conn_ipv6_recvhopopts 1022 * ipc_ipv6_recvdstopts conn_ipv6_recvdstopts 1023 * 1024 * ipc_ipv6_recvrthdr conn_ipv6_recvrthdr 1025 * ipc_ipv6_recvrtdstopts conn_ipv6_recvrtdstopts 1026 * ipc_fully_bound conn_fully_bound 1027 * 1028 * ipc_recvif conn_recvif 1029 * 1030 * ipc_recvslla conn_recvslla 1031 * ipc_acking_unbind conn_acking_unbind 1032 * ipc_pad_to_bit_31 conn_pad_to_bit_31 1033 * 1034 * ipc_xmit_if_ill conn_xmit_if_ill 1035 * ipc_nofailover_ill conn_nofailover_ill 1036 * 1037 * ipc_proto conn_proto 1038 * ipc_incoming_ill conn_incoming_ill 1039 * ipc_outgoing_pill conn_outgoing_pill 1040 * ipc_pending_ill conn_pending_ill 1041 * ipc_unbind_mp conn_unbind_mp 1042 * ipc_ilg conn_ilg 1043 * ipc_ilg_allocated conn_ilg_allocated 1044 * ipc_ilg_inuse conn_ilg_inuse 1045 * ipc_ilg_walker_cnt conn_ilg_walker_cnt 1046 * ipc_refcv conn_refcv 1047 * ipc_multicast_ipif conn_multicast_ipif 1048 * ipc_multicast_ill conn_multicast_ill 1049 * ipc_orig_bound_ifindex conn_orig_bound_ifindex 1050 * ipc_orig_multicast_ifindex conn_orig_multicast_ifindex 1051 * ipc_orig_xmit_ifindex conn_orig_xmit_ifindex 1052 * ipc_drain_next conn_drain_next 1053 * ipc_drain_prev conn_drain_prev 1054 * ipc_idl conn_idl 1055 */ 1056 1057 /* 1058 * This is used to match an inbound/outbound datagram with 1059 * policy. 1060 */ 1061 1062 typedef struct ipsec_selector { 1063 in6_addr_t ips_local_addr_v6; 1064 in6_addr_t ips_remote_addr_v6; 1065 uint16_t ips_local_port; 1066 uint16_t ips_remote_port; 1067 uint8_t ips_icmp_type; 1068 uint8_t ips_icmp_code; 1069 uint8_t ips_protocol; 1070 uint8_t ips_isv4 : 1, 1071 ips_is_icmp_inv_acq: 1; 1072 } ipsec_selector_t; 1073 1074 /* 1075 * Note that we put v4 addresses in the *first* 32-bit word of the 1076 * selector rather than the last to simplify the prefix match/mask code 1077 * in spd.c 1078 */ 1079 #define ips_local_addr_v4 ips_local_addr_v6.s6_addr32[0] 1080 #define ips_remote_addr_v4 ips_remote_addr_v6.s6_addr32[0] 1081 1082 /* Values used in IP by IPSEC Code */ 1083 #define IPSEC_OUTBOUND B_TRUE 1084 #define IPSEC_INBOUND B_FALSE 1085 1086 /* 1087 * There are two variants in policy failures. The packet may come in 1088 * secure when not needed (IPSEC_POLICY_???_NOT_NEEDED) or it may not 1089 * have the desired level of protection (IPSEC_POLICY_MISMATCH). 1090 */ 1091 #define IPSEC_POLICY_NOT_NEEDED 0 1092 #define IPSEC_POLICY_MISMATCH 1 1093 #define IPSEC_POLICY_AUTH_NOT_NEEDED 2 1094 #define IPSEC_POLICY_ENCR_NOT_NEEDED 3 1095 #define IPSEC_POLICY_SE_NOT_NEEDED 4 1096 #define IPSEC_POLICY_MAX 5 /* Always max + 1. */ 1097 1098 /* 1099 * Folowing macro is used whenever the code does not know whether there 1100 * is a M_CTL present in the front and it needs to examine the actual mp 1101 * i.e the IP header. As a M_CTL message could be in the front, this 1102 * extracts the packet into mp and the M_CTL mp into first_mp. If M_CTL 1103 * mp is not present, both first_mp and mp point to the same message. 1104 */ 1105 #define EXTRACT_PKT_MP(mp, first_mp, mctl_present) \ 1106 (first_mp) = (mp); \ 1107 if ((mp)->b_datap->db_type == M_CTL) { \ 1108 (mp) = (mp)->b_cont; \ 1109 (mctl_present) = B_TRUE; \ 1110 } else { \ 1111 (mctl_present) = B_FALSE; \ 1112 } 1113 1114 /* 1115 * Check with IPSEC inbound policy if 1116 * 1117 * 1) per-socket policy is present - indicated by conn_in_enforce_policy. 1118 * 2) Or if we have not cached policy on the conn and the global policy is 1119 * non-empty. 1120 */ 1121 #define CONN_INBOUND_POLICY_PRESENT(connp, ipss) \ 1122 ((connp)->conn_in_enforce_policy || \ 1123 (!((connp)->conn_policy_cached) && \ 1124 (ipss)->ipsec_inbound_v4_policy_present)) 1125 1126 #define CONN_INBOUND_POLICY_PRESENT_V6(connp, ipss) \ 1127 ((connp)->conn_in_enforce_policy || \ 1128 (!(connp)->conn_policy_cached && \ 1129 (ipss)->ipsec_inbound_v6_policy_present)) 1130 1131 #define CONN_OUTBOUND_POLICY_PRESENT(connp, ipss) \ 1132 ((connp)->conn_out_enforce_policy || \ 1133 (!((connp)->conn_policy_cached) && \ 1134 (ipss)->ipsec_outbound_v4_policy_present)) 1135 1136 #define CONN_OUTBOUND_POLICY_PRESENT_V6(connp, ipss) \ 1137 ((connp)->conn_out_enforce_policy || \ 1138 (!(connp)->conn_policy_cached && \ 1139 (ipss)->ipsec_outbound_v6_policy_present)) 1140 1141 /* 1142 * Information cached in IRE for upper layer protocol (ULP). 1143 * 1144 * Notice that ire_max_frag is not included in the iulp_t structure, which 1145 * it may seem that it should. But ire_max_frag cannot really be cached. It 1146 * is fixed for each interface. For MTU found by PMTUd, we may want to cache 1147 * it. But currently, we do not do that. 1148 */ 1149 typedef struct iulp_s { 1150 boolean_t iulp_set; /* Is any metric set? */ 1151 uint32_t iulp_ssthresh; /* Slow start threshold (TCP). */ 1152 clock_t iulp_rtt; /* Guestimate in millisecs. */ 1153 clock_t iulp_rtt_sd; /* Cached value of RTT variance. */ 1154 uint32_t iulp_spipe; /* Send pipe size. */ 1155 uint32_t iulp_rpipe; /* Receive pipe size. */ 1156 uint32_t iulp_rtomax; /* Max round trip timeout. */ 1157 uint32_t iulp_sack; /* Use SACK option (TCP)? */ 1158 uint32_t 1159 iulp_tstamp_ok : 1, /* Use timestamp option (TCP)? */ 1160 iulp_wscale_ok : 1, /* Use window scale option (TCP)? */ 1161 iulp_ecn_ok : 1, /* Enable ECN (for TCP)? */ 1162 iulp_pmtud_ok : 1, /* Enable PMTUd? */ 1163 1164 iulp_not_used : 28; 1165 } iulp_t; 1166 1167 /* Zero iulp_t. */ 1168 extern const iulp_t ire_uinfo_null; 1169 1170 /* 1171 * The conn drain list structure. 1172 * The list is protected by idl_lock. Each conn_t inserted in the list 1173 * points back at this idl_t using conn_idl. IP primes the draining of the 1174 * conns queued in these lists, by qenabling the 1st conn of each list. This 1175 * occurs when STREAMS backenables ip_wsrv on the IP module. Each conn instance 1176 * of ip_wsrv successively qenables the next conn in the list. 1177 * idl_lock protects all other members of idl_t and conn_drain_next 1178 * and conn_drain_prev of conn_t. The conn_lock protects IPCF_DRAIN_DISABLED 1179 * flag of the conn_t and conn_idl. 1180 */ 1181 typedef struct idl_s { 1182 conn_t *idl_conn; /* Head of drain list */ 1183 kmutex_t idl_lock; /* Lock for this list */ 1184 conn_t *idl_conn_draining; /* conn that is draining */ 1185 uint32_t 1186 idl_repeat : 1, /* Last conn must re-enable */ 1187 /* drain list again */ 1188 idl_unused : 31; 1189 } idl_t; 1190 1191 #define CONN_DRAIN_LIST_LOCK(connp) (&((connp)->conn_idl->idl_lock)) 1192 /* 1193 * Interface route structure which holds the necessary information to recreate 1194 * routes that are tied to an interface (namely where ire_ipif != NULL). 1195 * These routes which were initially created via a routing socket or via the 1196 * SIOCADDRT ioctl may be gateway routes (RTF_GATEWAY being set) or may be 1197 * traditional interface routes. When an interface comes back up after being 1198 * marked down, this information will be used to recreate the routes. These 1199 * are part of an mblk_t chain that hangs off of the IPIF (ipif_saved_ire_mp). 1200 */ 1201 typedef struct ifrt_s { 1202 ushort_t ifrt_type; /* Type of IRE */ 1203 in6_addr_t ifrt_v6addr; /* Address IRE represents. */ 1204 in6_addr_t ifrt_v6gateway_addr; /* Gateway if IRE_OFFSUBNET */ 1205 in6_addr_t ifrt_v6src_addr; /* Src addr if RTF_SETSRC */ 1206 in6_addr_t ifrt_v6mask; /* Mask for matching IRE. */ 1207 uint32_t ifrt_flags; /* flags related to route */ 1208 uint_t ifrt_max_frag; /* MTU (next hop or path). */ 1209 iulp_t ifrt_iulp_info; /* Cached IRE ULP info. */ 1210 } ifrt_t; 1211 1212 #define ifrt_addr V4_PART_OF_V6(ifrt_v6addr) 1213 #define ifrt_gateway_addr V4_PART_OF_V6(ifrt_v6gateway_addr) 1214 #define ifrt_src_addr V4_PART_OF_V6(ifrt_v6src_addr) 1215 #define ifrt_mask V4_PART_OF_V6(ifrt_v6mask) 1216 1217 /* Number of IP addresses that can be hosted on a physical interface */ 1218 #define MAX_ADDRS_PER_IF 8192 1219 /* 1220 * Number of Source addresses to be considered for source address 1221 * selection. Used by ipif_select_source[_v6]. 1222 */ 1223 #define MAX_IPIF_SELECT_SOURCE 50 1224 1225 #ifdef IP_DEBUG 1226 /* 1227 * Tracing refholds and refreleases for debugging. Existing tracing mechanisms 1228 * do not allow the granularity need to trace refrences to ipif/ill/ire's. This 1229 * mechanism should be revisited once dtrace is available. 1230 */ 1231 #define TR_STACK_DEPTH 14 1232 typedef struct tr_buf_s { 1233 int tr_depth; 1234 clock_t tr_time; 1235 pc_t tr_stack[TR_STACK_DEPTH]; 1236 } tr_buf_t; 1237 1238 typedef struct th_trace_s { 1239 int th_refcnt; 1240 uint_t th_trace_lastref; 1241 kthread_t *th_id; 1242 #define TR_BUF_MAX 38 1243 tr_buf_t th_trbuf[TR_BUF_MAX]; 1244 } th_trace_t; 1245 1246 typedef struct th_hash_s { 1247 list_node_t thh_link; 1248 mod_hash_t *thh_hash; 1249 ip_stack_t *thh_ipst; 1250 } th_hash_t; 1251 #endif 1252 1253 /* The following are ipif_state_flags */ 1254 #define IPIF_CONDEMNED 0x1 /* The ipif is being removed */ 1255 #define IPIF_CHANGING 0x2 /* A critcal ipif field is changing */ 1256 #define IPIF_MOVING 0x8 /* The ipif is being moved */ 1257 #define IPIF_SET_LINKLOCAL 0x10 /* transient flag during bringup */ 1258 #define IPIF_ZERO_SOURCE 0x20 /* transient flag during bringup */ 1259 1260 /* IP interface structure, one per local address */ 1261 typedef struct ipif_s { 1262 struct ipif_s *ipif_next; 1263 struct ill_s *ipif_ill; /* Back pointer to our ill */ 1264 int ipif_id; /* Logical unit number */ 1265 uint_t ipif_mtu; /* Starts at ipif_ill->ill_max_frag */ 1266 uint_t ipif_saved_mtu; /* Save of mtu during ipif_move() */ 1267 in6_addr_t ipif_v6lcl_addr; /* Local IP address for this if. */ 1268 in6_addr_t ipif_v6src_addr; /* Source IP address for this if. */ 1269 in6_addr_t ipif_v6subnet; /* Subnet prefix for this if. */ 1270 in6_addr_t ipif_v6net_mask; /* Net mask for this interface. */ 1271 in6_addr_t ipif_v6brd_addr; /* Broadcast addr for this interface. */ 1272 in6_addr_t ipif_v6pp_dst_addr; /* Point-to-point dest address. */ 1273 uint64_t ipif_flags; /* Interface flags. */ 1274 uint_t ipif_metric; /* BSD if metric, for compatibility. */ 1275 uint_t ipif_ire_type; /* IRE_LOCAL or IRE_LOOPBACK */ 1276 mblk_t *ipif_arp_del_mp; /* Allocated at time arp comes up, to */ 1277 /* prevent awkward out of mem */ 1278 /* condition later */ 1279 mblk_t *ipif_saved_ire_mp; /* Allocated for each extra */ 1280 /* IRE_IF_NORESOLVER/IRE_IF_RESOLVER */ 1281 /* on this interface so that they */ 1282 /* can survive ifconfig down. */ 1283 kmutex_t ipif_saved_ire_lock; /* Protects ipif_saved_ire_mp */ 1284 1285 mrec_t *ipif_igmp_rpt; /* List of group memberships which */ 1286 /* will be reported on. Used when */ 1287 /* handling an igmp timeout. */ 1288 1289 /* 1290 * The packet counts in the ipif contain the sum of the 1291 * packet counts in dead IREs that were affiliated with 1292 * this ipif. 1293 */ 1294 uint_t ipif_fo_pkt_count; /* Forwarded thru our dead IREs */ 1295 uint_t ipif_ib_pkt_count; /* Inbound packets for our dead IREs */ 1296 uint_t ipif_ob_pkt_count; /* Outbound packets to our dead IREs */ 1297 /* Exclusive bit fields, protected by ipsq_t */ 1298 unsigned int 1299 ipif_multicast_up : 1, /* We have joined the allhosts group */ 1300 ipif_replace_zero : 1, /* Replacement for zero */ 1301 ipif_was_up : 1, /* ipif was up before */ 1302 ipif_addr_ready : 1, /* DAD is done */ 1303 1304 ipif_was_dup : 1, /* DAD had failed */ 1305 ipif_pad_to_31 : 27; 1306 1307 int ipif_orig_ifindex; /* ifindex before SLIFFAILOVER */ 1308 uint_t ipif_seqid; /* unique index across all ills */ 1309 uint_t ipif_orig_ipifid; /* ipif_id before SLIFFAILOVER */ 1310 uint_t ipif_state_flags; /* See IPIF_* flag defs above */ 1311 uint_t ipif_refcnt; /* active consistent reader cnt */ 1312 uint_t ipif_ire_cnt; /* Number of ire's referencing ipif */ 1313 uint_t ipif_saved_ire_cnt; 1314 zoneid_t 1315 ipif_zoneid; /* zone ID number */ 1316 timeout_id_t ipif_recovery_id; /* Timer for DAD recovery */ 1317 boolean_t ipif_trace_disable; /* True when alloc fails */ 1318 } ipif_t; 1319 1320 /* 1321 * The following table lists the protection levels of the various members 1322 * of the ipif_t. The following notation is used. 1323 * 1324 * Write once - Written to only once at the time of bringing up 1325 * the interface and can be safely read after the bringup without any lock. 1326 * 1327 * ipsq - Need to execute in the ipsq to perform the indicated access. 1328 * 1329 * ill_lock - Need to hold this mutex to perform the indicated access. 1330 * 1331 * ill_g_lock - Need to hold this rw lock as reader/writer for read access or 1332 * write access respectively. 1333 * 1334 * down ill - Written to only when the ill is down (i.e all ipifs are down) 1335 * up ill - Read only when the ill is up (i.e. at least 1 ipif is up) 1336 * 1337 * Table of ipif_t members and their protection 1338 * 1339 * ipif_next ipsq + ill_lock + ipsq OR ill_lock OR 1340 * ill_g_lock ill_g_lock 1341 * ipif_ill ipsq + down ipif write once 1342 * ipif_id ipsq + down ipif write once 1343 * ipif_mtu ipsq 1344 * ipif_v6lcl_addr ipsq + down ipif up ipif 1345 * ipif_v6src_addr ipsq + down ipif up ipif 1346 * ipif_v6subnet ipsq + down ipif up ipif 1347 * ipif_v6net_mask ipsq + down ipif up ipif 1348 * 1349 * ipif_v6brd_addr 1350 * ipif_v6pp_dst_addr 1351 * ipif_flags ill_lock ill_lock 1352 * ipif_metric 1353 * ipif_ire_type ipsq + down ill up ill 1354 * 1355 * ipif_arp_del_mp ipsq ipsq 1356 * ipif_saved_ire_mp ipif_saved_ire_lock ipif_saved_ire_lock 1357 * ipif_igmp_rpt ipsq ipsq 1358 * 1359 * ipif_fo_pkt_count Approx 1360 * ipif_ib_pkt_count Approx 1361 * ipif_ob_pkt_count Approx 1362 * 1363 * bit fields ill_lock ill_lock 1364 * 1365 * ipif_orig_ifindex ipsq None 1366 * ipif_orig_ipifid ipsq None 1367 * ipif_seqid ipsq Write once 1368 * 1369 * ipif_state_flags ill_lock ill_lock 1370 * ipif_refcnt ill_lock ill_lock 1371 * ipif_ire_cnt ill_lock ill_lock 1372 * ipif_saved_ire_cnt 1373 */ 1374 1375 #define IP_TR_HASH(tid) ((((uintptr_t)tid) >> 6) & (IP_TR_HASH_MAX - 1)) 1376 1377 #ifdef DEBUG 1378 #define IPIF_TRACE_REF(ipif) ipif_trace_ref(ipif) 1379 #define ILL_TRACE_REF(ill) ill_trace_ref(ill) 1380 #define IPIF_UNTRACE_REF(ipif) ipif_untrace_ref(ipif) 1381 #define ILL_UNTRACE_REF(ill) ill_untrace_ref(ill) 1382 #else 1383 #define IPIF_TRACE_REF(ipif) 1384 #define ILL_TRACE_REF(ill) 1385 #define IPIF_UNTRACE_REF(ipif) 1386 #define ILL_UNTRACE_REF(ill) 1387 #endif 1388 1389 /* IPv4 compatability macros */ 1390 #define ipif_lcl_addr V4_PART_OF_V6(ipif_v6lcl_addr) 1391 #define ipif_src_addr V4_PART_OF_V6(ipif_v6src_addr) 1392 #define ipif_subnet V4_PART_OF_V6(ipif_v6subnet) 1393 #define ipif_net_mask V4_PART_OF_V6(ipif_v6net_mask) 1394 #define ipif_brd_addr V4_PART_OF_V6(ipif_v6brd_addr) 1395 #define ipif_pp_dst_addr V4_PART_OF_V6(ipif_v6pp_dst_addr) 1396 1397 /* Macros for easy backreferences to the ill. */ 1398 #define ipif_wq ipif_ill->ill_wq 1399 #define ipif_rq ipif_ill->ill_rq 1400 #define ipif_net_type ipif_ill->ill_net_type 1401 #define ipif_ipif_up_count ipif_ill->ill_ipif_up_count 1402 #define ipif_type ipif_ill->ill_type 1403 #define ipif_isv6 ipif_ill->ill_isv6 1404 1405 #define SIOCLIFADDR_NDX 112 /* ndx of SIOCLIFADDR in the ndx ioctl table */ 1406 1407 /* 1408 * mode value for ip_ioctl_finish for finishing an ioctl 1409 */ 1410 #define CONN_CLOSE 1 /* No mi_copy */ 1411 #define COPYOUT 2 /* do an mi_copyout if needed */ 1412 #define NO_COPYOUT 3 /* do an mi_copy_done */ 1413 #define IPI2MODE(ipi) ((ipi)->ipi_flags & IPI_GET_CMD ? COPYOUT : NO_COPYOUT) 1414 1415 /* 1416 * The IP-MT design revolves around the serialization object ipsq_t. 1417 * It is associated with an IPMP group. If IPMP is not enabled, there is 1418 * 1 ipsq_t per phyint. Eg. an ipsq_t would cover both hme0's IPv4 stream 1419 * 1420 * ipsq_lock protects 1421 * ipsq_reentry_cnt, ipsq_writer, ipsq_xopq_mphead, ipsq_xopq_mptail, 1422 * ipsq_mphead, ipsq_mptail, ipsq_split 1423 * 1424 * ipsq_pending_ipif, ipsq_current_ipif, ipsq_pending_mp, ipsq_flags, 1425 * ipsq_waitfor 1426 * 1427 * The fields in the last line above below are set mostly by a writer thread 1428 * But there is an exception in the last call to ipif_ill_refrele_tail which 1429 * could also race with a conn close which could be cleaning up the 1430 * fields. So we choose to protect using ipsq_lock instead of depending on 1431 * the property of the writer. 1432 * ill_g_lock protects 1433 * ipsq_refs, ipsq_phyint_list 1434 */ 1435 typedef struct ipsq_s { 1436 kmutex_t ipsq_lock; 1437 int ipsq_reentry_cnt; 1438 kthread_t *ipsq_writer; /* current owner (thread id) */ 1439 int ipsq_flags; 1440 mblk_t *ipsq_xopq_mphead; /* list of excl ops mostly ioctls */ 1441 mblk_t *ipsq_xopq_mptail; 1442 mblk_t *ipsq_mphead; /* msgs on ipsq linked thru b_next */ 1443 mblk_t *ipsq_mptail; /* msgs on ipsq linked thru b_next */ 1444 int ipsq_current_ioctl; /* current ioctl, or 0 if no ioctl */ 1445 ipif_t *ipsq_current_ipif; /* ipif associated with current op */ 1446 ipif_t *ipsq_pending_ipif; /* ipif associated w. ipsq_pending_mp */ 1447 mblk_t *ipsq_pending_mp; /* current ioctl mp while waiting for */ 1448 /* response from another module */ 1449 struct ipsq_s *ipsq_next; /* list of all syncq's (ipsq_g_list) */ 1450 uint_t ipsq_refs; /* Number of phyints on this ipsq */ 1451 struct phyint *ipsq_phyint_list; /* List of phyints on this ipsq */ 1452 boolean_t ipsq_split; /* ipsq may need to be split */ 1453 int ipsq_waitfor; /* Values encoded below */ 1454 char ipsq_name[LIFNAMSIZ+1]; /* same as phyint_groupname */ 1455 ip_stack_t *ipsq_ipst; /* Does not have a netstack_hold */ 1456 1457 #ifdef DEBUG 1458 int ipsq_depth; /* debugging aid */ 1459 #define IPSQ_STACK_DEPTH 15 1460 pc_t ipsq_stack[IPSQ_STACK_DEPTH]; /* debugging aid */ 1461 #endif 1462 } ipsq_t; 1463 1464 /* ipsq_flags */ 1465 #define IPSQ_GROUP 0x1 /* This ipsq belongs to an IPMP group */ 1466 1467 /* 1468 * ipsq_waitfor: 1469 * 1470 * IPIF_DOWN 1 ipif_down waiting for refcnts to drop 1471 * ILL_DOWN 2 ill_down waiting for refcnts to drop 1472 * IPIF_FREE 3 ipif_free waiting for refcnts to drop 1473 * ILL_FREE 4 ill unplumb waiting for refcnts to drop 1474 * ILL_MOVE_OK 5 failover waiting for refcnts to drop 1475 */ 1476 1477 enum { IPIF_DOWN = 1, ILL_DOWN, IPIF_FREE, ILL_FREE, ILL_MOVE_OK }; 1478 1479 /* Flags passed to ipsq_try_enter */ 1480 #define CUR_OP 0 /* Current ioctl continuing again */ 1481 #define NEW_OP 1 /* New ioctl starting afresh */ 1482 1483 /* 1484 * phyint represents state that is common to both IPv4 and IPv6 interfaces. 1485 * There is a separate ill_t representing IPv4 and IPv6 which has a 1486 * backpointer to the phyint structure for acessing common state. 1487 * 1488 * NOTE : It just stores the group name as there is only one name for 1489 * IPv4 and IPv6 i.e it is a underlying link property. Actually 1490 * IPv4 and IPv6 ill are grouped together when their phyints have 1491 * the same name. 1492 */ 1493 typedef struct phyint { 1494 struct ill_s *phyint_illv4; 1495 struct ill_s *phyint_illv6; 1496 uint_t phyint_ifindex; /* SIOCLSLIFINDEX */ 1497 char *phyint_groupname; /* SIOCSLIFGROUPNAME */ 1498 uint_t phyint_groupname_len; 1499 uint64_t phyint_flags; 1500 avl_node_t phyint_avl_by_index; /* avl tree by index */ 1501 avl_node_t phyint_avl_by_name; /* avl tree by name */ 1502 kmutex_t phyint_lock; 1503 struct ipsq_s *phyint_ipsq; /* back pointer to ipsq */ 1504 struct phyint *phyint_ipsq_next; /* phyint list on this ipsq */ 1505 /* Once Clearview IPMP is added the follow two fields can be removed */ 1506 uint_t phyint_group_ifindex; /* index assigned to group */ 1507 uint_t phyint_hook_ifindex; /* index used with neti/hook */ 1508 } phyint_t; 1509 1510 #define CACHE_ALIGN_SIZE 64 1511 1512 #define CACHE_ALIGN(align_struct) P2ROUNDUP(sizeof (struct align_struct),\ 1513 CACHE_ALIGN_SIZE) 1514 struct _phyint_list_s_ { 1515 avl_tree_t phyint_list_avl_by_index; /* avl tree by index */ 1516 avl_tree_t phyint_list_avl_by_name; /* avl tree by name */ 1517 }; 1518 1519 typedef union phyint_list_u { 1520 struct _phyint_list_s_ phyint_list_s; 1521 char phyint_list_filler[CACHE_ALIGN(_phyint_list_s_)]; 1522 } phyint_list_t; 1523 1524 #define phyint_list_avl_by_index phyint_list_s.phyint_list_avl_by_index 1525 #define phyint_list_avl_by_name phyint_list_s.phyint_list_avl_by_name 1526 /* 1527 * ILL groups. We group ills, 1528 * 1529 * - if the ills have the same group name. (New way) 1530 * 1531 * ill_group locking notes: 1532 * 1533 * illgrp_lock protects ill_grp_ill_schednext. 1534 * 1535 * ill_g_lock protects ill_grp_next, illgrp_ill, illgrp_ill_count. 1536 * Holding ill_g_lock freezes the memberships of ills in IPMP groups. 1537 * It also freezes the global list of ills and all ipifs in all ills. 1538 * 1539 * To remove an ipif from the linked list of ipifs of that ill ipif_free_tail 1540 * holds both ill_g_lock, and ill_lock. Similarly to remove an ill from the 1541 * global list of ills, ill_glist_delete() holds ill_g_lock as writer. 1542 * This simplifies things for ipif_select_source, illgrp_scheduler etc. 1543 * that need to walk the members of an illgrp. They just hold ill_g_lock 1544 * as reader to do the walk. 1545 * 1546 */ 1547 typedef struct ill_group { 1548 kmutex_t illgrp_lock; 1549 struct ill_group *illgrp_next; /* Next ill_group */ 1550 struct ill_s *illgrp_ill_schednext; /* Next ill to be scheduled */ 1551 struct ill_s *illgrp_ill; /* First ill in the group */ 1552 int illgrp_ill_count; 1553 } ill_group_t; 1554 1555 /* 1556 * Fragmentation hash bucket 1557 */ 1558 typedef struct ipfb_s { 1559 struct ipf_s *ipfb_ipf; /* List of ... */ 1560 size_t ipfb_count; /* Count of bytes used by frag(s) */ 1561 kmutex_t ipfb_lock; /* Protect all ipf in list */ 1562 uint_t ipfb_frag_pkts; /* num of distinct fragmented pkts */ 1563 } ipfb_t; 1564 1565 /* 1566 * IRE bucket structure. Usually there is an array of such structures, 1567 * each pointing to a linked list of ires. irb_refcnt counts the number 1568 * of walkers of a given hash bucket. Usually the reference count is 1569 * bumped up if the walker wants no IRES to be DELETED while walking the 1570 * list. Bumping up does not PREVENT ADDITION. This allows walking a given 1571 * hash bucket without stumbling up on a free pointer. 1572 * 1573 * irb_t structures in ip_ftable are dynamically allocated and freed. 1574 * In order to identify the irb_t structures that can be safely kmem_free'd 1575 * we need to ensure that 1576 * - the irb_refcnt is quiescent, indicating no other walkers, 1577 * - no other threads or ire's are holding references to the irb, 1578 * i.e., irb_nire == 0, 1579 * - there are no active ire's in the bucket, i.e., irb_ire_cnt == 0 1580 */ 1581 typedef struct irb { 1582 struct ire_s *irb_ire; /* First ire in this bucket */ 1583 /* Should be first in this struct */ 1584 krwlock_t irb_lock; /* Protect this bucket */ 1585 uint_t irb_refcnt; /* Protected by irb_lock */ 1586 uchar_t irb_marks; /* CONDEMNED ires in this bucket ? */ 1587 #define IRB_MARK_CONDEMNED 0x0001 1588 #define IRB_MARK_FTABLE 0x0002 1589 uint_t irb_ire_cnt; /* Num of active IRE in this bucket */ 1590 uint_t irb_tmp_ire_cnt; /* Num of temporary IRE */ 1591 struct ire_s *irb_rr_origin; /* origin for round-robin */ 1592 int irb_nire; /* Num of ftable ire's that ref irb */ 1593 ip_stack_t *irb_ipst; /* Does not have a netstack_hold */ 1594 } irb_t; 1595 1596 #define IRB2RT(irb) (rt_t *)((caddr_t)(irb) - offsetof(rt_t, rt_irb)) 1597 1598 /* The following are return values of ip_xmit_v4() */ 1599 typedef enum { 1600 SEND_PASSED = 0, /* sent packet out on wire */ 1601 SEND_FAILED, /* sending of packet failed */ 1602 LOOKUP_IN_PROGRESS, /* ire cache found, ARP resolution in progress */ 1603 LLHDR_RESLV_FAILED /* macaddr resl of onlink dst or nexthop failed */ 1604 } ipxmit_state_t; 1605 1606 #define IP_V4_G_HEAD 0 1607 #define IP_V6_G_HEAD 1 1608 1609 #define MAX_G_HEADS 2 1610 1611 /* 1612 * unpadded ill_if structure 1613 */ 1614 struct _ill_if_s_ { 1615 union ill_if_u *illif_next; 1616 union ill_if_u *illif_prev; 1617 avl_tree_t illif_avl_by_ppa; /* AVL tree sorted on ppa */ 1618 vmem_t *illif_ppa_arena; /* ppa index space */ 1619 uint16_t illif_mcast_v1; /* hints for */ 1620 uint16_t illif_mcast_v2; /* [igmp|mld]_slowtimo */ 1621 int illif_name_len; /* name length */ 1622 char illif_name[LIFNAMSIZ]; /* name of interface type */ 1623 }; 1624 1625 /* cache aligned ill_if structure */ 1626 typedef union ill_if_u { 1627 struct _ill_if_s_ ill_if_s; 1628 char illif_filler[CACHE_ALIGN(_ill_if_s_)]; 1629 } ill_if_t; 1630 1631 #define illif_next ill_if_s.illif_next 1632 #define illif_prev ill_if_s.illif_prev 1633 #define illif_avl_by_ppa ill_if_s.illif_avl_by_ppa 1634 #define illif_ppa_arena ill_if_s.illif_ppa_arena 1635 #define illif_mcast_v1 ill_if_s.illif_mcast_v1 1636 #define illif_mcast_v2 ill_if_s.illif_mcast_v2 1637 #define illif_name ill_if_s.illif_name 1638 #define illif_name_len ill_if_s.illif_name_len 1639 1640 typedef struct ill_walk_context_s { 1641 int ctx_current_list; /* current list being searched */ 1642 int ctx_last_list; /* last list to search */ 1643 } ill_walk_context_t; 1644 1645 /* 1646 * ill_g_heads structure, one for IPV4 and one for IPV6 1647 */ 1648 struct _ill_g_head_s_ { 1649 ill_if_t *ill_g_list_head; 1650 ill_if_t *ill_g_list_tail; 1651 }; 1652 1653 typedef union ill_g_head_u { 1654 struct _ill_g_head_s_ ill_g_head_s; 1655 char ill_g_head_filler[CACHE_ALIGN(_ill_g_head_s_)]; 1656 } ill_g_head_t; 1657 1658 #define ill_g_list_head ill_g_head_s.ill_g_list_head 1659 #define ill_g_list_tail ill_g_head_s.ill_g_list_tail 1660 1661 #define IP_V4_ILL_G_LIST(ipst) \ 1662 (ipst)->ips_ill_g_heads[IP_V4_G_HEAD].ill_g_list_head 1663 #define IP_V6_ILL_G_LIST(ipst) \ 1664 (ipst)->ips_ill_g_heads[IP_V6_G_HEAD].ill_g_list_head 1665 #define IP_VX_ILL_G_LIST(i, ipst) \ 1666 (ipst)->ips_ill_g_heads[i].ill_g_list_head 1667 1668 #define ILL_START_WALK_V4(ctx_ptr, ipst) \ 1669 ill_first(IP_V4_G_HEAD, IP_V4_G_HEAD, ctx_ptr, ipst) 1670 #define ILL_START_WALK_V6(ctx_ptr, ipst) \ 1671 ill_first(IP_V6_G_HEAD, IP_V6_G_HEAD, ctx_ptr, ipst) 1672 #define ILL_START_WALK_ALL(ctx_ptr, ipst) \ 1673 ill_first(MAX_G_HEADS, MAX_G_HEADS, ctx_ptr, ipst) 1674 1675 /* 1676 * Capabilities, possible flags for ill_capabilities. 1677 */ 1678 1679 #define ILL_CAPAB_AH 0x01 /* IPsec AH acceleration */ 1680 #define ILL_CAPAB_ESP 0x02 /* IPsec ESP acceleration */ 1681 #define ILL_CAPAB_MDT 0x04 /* Multidata Transmit */ 1682 #define ILL_CAPAB_HCKSUM 0x08 /* Hardware checksumming */ 1683 #define ILL_CAPAB_ZEROCOPY 0x10 /* Zero-copy */ 1684 #define ILL_CAPAB_POLL 0x20 /* Polling Toggle */ 1685 #define ILL_CAPAB_SOFT_RING 0x40 /* Soft_Ring capability */ 1686 #define ILL_CAPAB_LSO 0x80 /* Large Segment Offload */ 1687 1688 /* 1689 * Per-ill Multidata Transmit capabilities. 1690 */ 1691 typedef struct ill_mdt_capab_s ill_mdt_capab_t; 1692 1693 /* 1694 * Per-ill IPsec capabilities. 1695 */ 1696 typedef struct ill_ipsec_capab_s ill_ipsec_capab_t; 1697 1698 /* 1699 * Per-ill Hardware Checksumming capbilities. 1700 */ 1701 typedef struct ill_hcksum_capab_s ill_hcksum_capab_t; 1702 1703 /* 1704 * Per-ill Zero-copy capabilities. 1705 */ 1706 typedef struct ill_zerocopy_capab_s ill_zerocopy_capab_t; 1707 1708 /* 1709 * Per-ill Polling/soft ring capbilities. 1710 */ 1711 typedef struct ill_dls_capab_s ill_dls_capab_t; 1712 1713 /* 1714 * Per-ill polling resource map. 1715 */ 1716 typedef struct ill_rx_ring ill_rx_ring_t; 1717 1718 /* 1719 * Per-ill Large Segment Offload capabilities. 1720 */ 1721 typedef struct ill_lso_capab_s ill_lso_capab_t; 1722 1723 /* The following are ill_state_flags */ 1724 #define ILL_LL_SUBNET_PENDING 0x01 /* Waiting for DL_INFO_ACK from drv */ 1725 #define ILL_CONDEMNED 0x02 /* No more new ref's to the ILL */ 1726 #define ILL_CHANGING 0x04 /* ILL not globally visible */ 1727 #define ILL_DL_UNBIND_IN_PROGRESS 0x08 /* UNBIND_REQ is sent */ 1728 #define ILL_SOFT_RING_ASSIGN 0x10 /* Makeing soft ring assigment */ 1729 1730 /* Is this an ILL whose source address is used by other ILL's ? */ 1731 #define IS_USESRC_ILL(ill) \ 1732 (((ill)->ill_usesrc_ifindex == 0) && \ 1733 ((ill)->ill_usesrc_grp_next != NULL)) 1734 1735 /* Is this a client/consumer of the usesrc ILL ? */ 1736 #define IS_USESRC_CLI_ILL(ill) \ 1737 (((ill)->ill_usesrc_ifindex != 0) && \ 1738 ((ill)->ill_usesrc_grp_next != NULL)) 1739 1740 /* Is this an virtual network interface (vni) ILL ? */ 1741 #define IS_VNI(ill) \ 1742 (((ill) != NULL) && \ 1743 (((ill)->ill_phyint->phyint_flags & (PHYI_LOOPBACK|PHYI_VIRTUAL)) == \ 1744 PHYI_VIRTUAL)) 1745 1746 /* Is this a loopback ILL? */ 1747 #define IS_LOOPBACK(ill) \ 1748 ((ill)->ill_phyint->phyint_flags & PHYI_LOOPBACK) 1749 1750 /* 1751 * IP Lower level Structure. 1752 * Instance data structure in ip_open when there is a device below us. 1753 */ 1754 typedef struct ill_s { 1755 ill_if_t *ill_ifptr; /* pointer to interface type */ 1756 queue_t *ill_rq; /* Read queue. */ 1757 queue_t *ill_wq; /* Write queue. */ 1758 1759 int ill_error; /* Error value sent up by device. */ 1760 1761 ipif_t *ill_ipif; /* Interface chain for this ILL. */ 1762 1763 uint_t ill_ipif_up_count; /* Number of IPIFs currently up. */ 1764 uint_t ill_max_frag; /* Max IDU from DLPI. */ 1765 char *ill_name; /* Our name. */ 1766 uint_t ill_ipif_dup_count; /* Number of duplicate addresses. */ 1767 uint_t ill_name_length; /* Name length, incl. terminator. */ 1768 char *ill_ndd_name; /* Name + ":ip?_forwarding" for NDD. */ 1769 uint_t ill_net_type; /* IRE_IF_RESOLVER/IRE_IF_NORESOLVER. */ 1770 /* 1771 * Physical Point of Attachment num. If DLPI style 1 provider 1772 * then this is derived from the devname. 1773 */ 1774 uint_t ill_ppa; 1775 t_uscalar_t ill_sap; 1776 t_scalar_t ill_sap_length; /* Including sign (for position) */ 1777 uint_t ill_phys_addr_length; /* Excluding the sap. */ 1778 uint_t ill_bcast_addr_length; /* Only set when the DL provider */ 1779 /* supports broadcast. */ 1780 t_uscalar_t ill_mactype; 1781 uint8_t *ill_frag_ptr; /* Reassembly state. */ 1782 timeout_id_t ill_frag_timer_id; /* timeout id for the frag timer */ 1783 ipfb_t *ill_frag_hash_tbl; /* Fragment hash list head. */ 1784 ipif_t *ill_pending_ipif; /* IPIF waiting for DL operation. */ 1785 1786 ilm_t *ill_ilm; /* Multicast mebership for lower ill */ 1787 uint_t ill_global_timer; /* for IGMPv3/MLDv2 general queries */ 1788 int ill_mcast_type; /* type of router which is querier */ 1789 /* on this interface */ 1790 uint16_t ill_mcast_v1_time; /* # slow timeouts since last v1 qry */ 1791 uint16_t ill_mcast_v2_time; /* # slow timeouts since last v2 qry */ 1792 uint8_t ill_mcast_v1_tset; /* 1 => timer is set; 0 => not set */ 1793 uint8_t ill_mcast_v2_tset; /* 1 => timer is set; 0 => not set */ 1794 1795 uint8_t ill_mcast_rv; /* IGMPv3/MLDv2 robustness variable */ 1796 int ill_mcast_qi; /* IGMPv3/MLDv2 query interval var */ 1797 1798 mblk_t *ill_pending_mp; /* IOCTL/DLPI awaiting completion. */ 1799 /* 1800 * All non-NULL cells between 'ill_first_mp_to_free' and 1801 * 'ill_last_mp_to_free' are freed in ill_delete. 1802 */ 1803 #define ill_first_mp_to_free ill_bcast_mp 1804 mblk_t *ill_bcast_mp; /* DLPI header for broadcasts. */ 1805 mblk_t *ill_resolver_mp; /* Resolver template. */ 1806 mblk_t *ill_unbind_mp; /* unbind mp from ill_dl_up() */ 1807 mblk_t *ill_dlpi_deferred; /* b_next chain of control messages */ 1808 mblk_t *ill_phys_addr_mp; /* mblk which holds ill_phys_addr */ 1809 #define ill_last_mp_to_free ill_phys_addr_mp 1810 1811 cred_t *ill_credp; /* opener's credentials */ 1812 uint8_t *ill_phys_addr; /* ill_phys_addr_mp->b_rptr + off */ 1813 1814 uint_t ill_state_flags; /* see ILL_* flags above */ 1815 1816 /* Following bit fields protected by ipsq_t */ 1817 uint_t 1818 ill_needs_attach : 1, 1819 ill_reserved : 1, 1820 ill_isv6 : 1, 1821 ill_dlpi_style_set : 1, 1822 1823 ill_ifname_pending : 1, 1824 ill_move_in_progress : 1, /* FAILOVER/FAILBACK in progress */ 1825 ill_join_allmulti : 1, 1826 ill_logical_down : 1, 1827 1828 ill_is_6to4tun : 1, /* Interface is a 6to4 tunnel */ 1829 ill_promisc_on_phys : 1, /* phys interface in promisc mode */ 1830 ill_dl_up : 1, 1831 ill_up_ipifs : 1, 1832 1833 ill_note_link : 1, /* supports link-up notification */ 1834 ill_capab_reneg : 1, /* capability renegotiation to be done */ 1835 ill_pad_to_bit_31 : 18; 1836 1837 /* Following bit fields protected by ill_lock */ 1838 uint_t 1839 ill_fragtimer_executing : 1, 1840 ill_fragtimer_needrestart : 1, 1841 ill_ilm_cleanup_reqd : 1, 1842 ill_arp_closing : 1, 1843 1844 ill_arp_bringup_pending : 1, 1845 ill_mtu_userspecified : 1, /* SIOCSLNKINFO has set the mtu */ 1846 ill_arp_extend : 1, /* ARP has DAD extensions */ 1847 ill_pad_bit_31 : 25; 1848 1849 /* 1850 * Used in SIOCSIFMUXID and SIOCGIFMUXID for 'ifconfig unplumb'. 1851 */ 1852 int ill_arp_muxid; /* muxid returned from plink for arp */ 1853 int ill_ip_muxid; /* muxid returned from plink for ip */ 1854 1855 /* 1856 * NIC event information attached, to be used by nic event hooks. 1857 */ 1858 hook_nic_event_t *ill_nic_event_info; 1859 1860 /* 1861 * Used for IP frag reassembly throttling on a per ILL basis. 1862 * 1863 * Note: frag_count is approximate, its added to and subtracted from 1864 * without any locking, so simultaneous load/modify/stores can 1865 * collide, also ill_frag_purge() recalculates its value by 1866 * summing all the ipfb_count's without locking out updates 1867 * to the ipfb's. 1868 */ 1869 uint_t ill_ipf_gen; /* Generation of next fragment queue */ 1870 uint_t ill_frag_count; /* Approx count of all mblk bytes */ 1871 uint_t ill_frag_free_num_pkts; /* num of fragmented packets to free */ 1872 clock_t ill_last_frag_clean_time; /* time when frag's were pruned */ 1873 int ill_type; /* From <net/if_types.h> */ 1874 uint_t ill_dlpi_multicast_state; /* See below IDS_* */ 1875 uint_t ill_dlpi_fastpath_state; /* See below IDS_* */ 1876 1877 /* 1878 * Capabilities related fields. 1879 */ 1880 uint_t ill_dlpi_capab_state; /* State of capability query, IDS_* */ 1881 uint64_t ill_capabilities; /* Enabled capabilities, ILL_CAPAB_* */ 1882 ill_mdt_capab_t *ill_mdt_capab; /* Multidata Transmit capabilities */ 1883 ill_ipsec_capab_t *ill_ipsec_capab_ah; /* IPsec AH capabilities */ 1884 ill_ipsec_capab_t *ill_ipsec_capab_esp; /* IPsec ESP capabilities */ 1885 ill_hcksum_capab_t *ill_hcksum_capab; /* H/W cksumming capabilities */ 1886 ill_zerocopy_capab_t *ill_zerocopy_capab; /* Zero-copy capabilities */ 1887 ill_dls_capab_t *ill_dls_capab; /* Polling, soft ring capabilities */ 1888 ill_lso_capab_t *ill_lso_capab; /* Large Segment Offload capabilities */ 1889 1890 /* 1891 * New fields for IPv6 1892 */ 1893 uint8_t ill_max_hops; /* Maximum hops for any logical interface */ 1894 uint_t ill_max_mtu; /* Maximum MTU for any logical interface */ 1895 uint32_t ill_reachable_time; /* Value for ND algorithm in msec */ 1896 uint32_t ill_reachable_retrans_time; /* Value for ND algorithm msec */ 1897 uint_t ill_max_buf; /* Max # of req to buffer for ND */ 1898 in6_addr_t ill_token; 1899 uint_t ill_token_length; 1900 uint32_t ill_xmit_count; /* ndp max multicast xmits */ 1901 mib2_ipIfStatsEntry_t *ill_ip_mib; /* ver indep. interface mib */ 1902 mib2_ipv6IfIcmpEntry_t *ill_icmp6_mib; /* Per interface mib */ 1903 /* 1904 * Following two mblks are allocated common to all 1905 * the ipifs when the first interface is coming up. 1906 * It is sent up to arp when the last ipif is coming 1907 * down. 1908 */ 1909 mblk_t *ill_arp_down_mp; 1910 mblk_t *ill_arp_del_mapping_mp; 1911 /* 1912 * Used for implementing IFF_NOARP. As IFF_NOARP is used 1913 * to turn off for all the logicals, it is here instead 1914 * of the ipif. 1915 */ 1916 mblk_t *ill_arp_on_mp; 1917 /* Peer ill of an IPMP move operation */ 1918 struct ill_s *ill_move_peer; 1919 1920 phyint_t *ill_phyint; 1921 uint64_t ill_flags; 1922 ill_group_t *ill_group; 1923 struct ill_s *ill_group_next; 1924 1925 kmutex_t ill_lock; /* Please see table below */ 1926 /* 1927 * The ill_nd_lla* fields handle the link layer address option 1928 * from neighbor discovery. This is used for external IPv6 1929 * address resolution. 1930 */ 1931 mblk_t *ill_nd_lla_mp; /* mblk which holds ill_nd_lla */ 1932 uint8_t *ill_nd_lla; /* Link Layer Address */ 1933 uint_t ill_nd_lla_len; /* Link Layer Address length */ 1934 /* 1935 * We now have 3 phys_addr_req's sent down. This field keeps track 1936 * of which one is pending. 1937 */ 1938 t_uscalar_t ill_phys_addr_pend; /* which dl_phys_addr_req pending */ 1939 /* 1940 * Used to save errors that occur during plumbing 1941 */ 1942 uint_t ill_ifname_pending_err; 1943 avl_node_t ill_avl_byppa; /* avl node based on ppa */ 1944 void *ill_fastpath_list; /* both ire and nce hang off this */ 1945 uint_t ill_refcnt; /* active refcnt by threads */ 1946 uint_t ill_ire_cnt; /* ires associated with this ill */ 1947 kcondvar_t ill_cv; 1948 uint_t ill_ilm_walker_cnt; /* snmp ilm walkers */ 1949 uint_t ill_nce_cnt; /* nces associated with this ill */ 1950 uint_t ill_waiters; /* threads waiting in ipsq_enter */ 1951 /* 1952 * Contains the upper read queue pointer of the module immediately 1953 * beneath IP. This field allows IP to validate sub-capability 1954 * acknowledgments coming up from downstream. 1955 */ 1956 queue_t *ill_lmod_rq; /* read queue pointer of module below */ 1957 uint_t ill_lmod_cnt; /* number of modules beneath IP */ 1958 ip_m_t *ill_media; /* media specific params/functions */ 1959 t_uscalar_t ill_dlpi_pending; /* Last DLPI primitive issued */ 1960 uint_t ill_usesrc_ifindex; /* use src addr from this ILL */ 1961 struct ill_s *ill_usesrc_grp_next; /* Next ILL in the usesrc group */ 1962 boolean_t ill_trace_disable; /* True when alloc fails */ 1963 zoneid_t ill_zoneid; 1964 ip_stack_t *ill_ipst; /* Corresponds to a netstack_hold */ 1965 } ill_t; 1966 1967 /* 1968 * The following table lists the protection levels of the various members 1969 * of the ill_t. Same notation as that used for ipif_t above is used. 1970 * 1971 * Write Read 1972 * 1973 * ill_ifptr ill_g_lock + s Write once 1974 * ill_rq ipsq Write once 1975 * ill_wq ipsq Write once 1976 * 1977 * ill_error ipsq None 1978 * ill_ipif ill_g_lock + ipsq ill_g_lock OR ipsq 1979 * ill_ipif_up_count ill_lock + ipsq ill_lock OR ipsq 1980 * ill_max_frag ipsq Write once 1981 * 1982 * ill_name ill_g_lock + ipsq Write once 1983 * ill_name_length ill_g_lock + ipsq Write once 1984 * ill_ndd_name ipsq Write once 1985 * ill_net_type ipsq Write once 1986 * ill_ppa ill_g_lock + ipsq Write once 1987 * ill_sap ipsq + down ill Write once 1988 * ill_sap_length ipsq + down ill Write once 1989 * ill_phys_addr_length ipsq + down ill Write once 1990 * 1991 * ill_bcast_addr_length ipsq ipsq 1992 * ill_mactype ipsq ipsq 1993 * ill_frag_ptr ipsq ipsq 1994 * 1995 * ill_frag_timer_id ill_lock ill_lock 1996 * ill_frag_hash_tbl ipsq up ill 1997 * ill_ilm ipsq + ill_lock ill_lock 1998 * ill_mcast_type ill_lock ill_lock 1999 * ill_mcast_v1_time ill_lock ill_lock 2000 * ill_mcast_v2_time ill_lock ill_lock 2001 * ill_mcast_v1_tset ill_lock ill_lock 2002 * ill_mcast_v2_tset ill_lock ill_lock 2003 * ill_mcast_rv ill_lock ill_lock 2004 * ill_mcast_qi ill_lock ill_lock 2005 * ill_pending_mp ill_lock ill_lock 2006 * 2007 * ill_bcast_mp ipsq ipsq 2008 * ill_resolver_mp ipsq only when ill is up 2009 * ill_down_mp ipsq ipsq 2010 * ill_dlpi_deferred ill_lock ill_lock 2011 * ill_dlpi_pending ill_lock ill_lock 2012 * ill_phys_addr_mp ipsq + down ill only when ill is up 2013 * ill_phys_addr ipsq + down ill only when ill is up 2014 * 2015 * ill_state_flags ill_lock ill_lock 2016 * exclusive bit flags ipsq_t ipsq_t 2017 * shared bit flags ill_lock ill_lock 2018 * 2019 * ill_arp_muxid ipsq Not atomic 2020 * ill_ip_muxid ipsq Not atomic 2021 * 2022 * ill_ipf_gen Not atomic 2023 * ill_frag_count Approx. not protected 2024 * ill_type ipsq + down ill only when ill is up 2025 * ill_dlpi_multicast_state ill_lock ill_lock 2026 * ill_dlpi_fastpath_state ill_lock ill_lock 2027 * ill_max_hops ipsq Not atomic 2028 * 2029 * ill_max_mtu 2030 * 2031 * ill_reachable_time ipsq + ill_lock ill_lock 2032 * ill_reachable_retrans_time ipsq + ill_lock ill_lock 2033 * ill_max_buf ipsq + ill_lock ill_lock 2034 * 2035 * Next 2 fields need ill_lock because of the get ioctls. They should not 2036 * report partially updated results without executing in the ipsq. 2037 * ill_token ipsq + ill_lock ill_lock 2038 * ill_token_length ipsq + ill_lock ill_lock 2039 * ill_xmit_count ipsq + down ill write once 2040 * ill_ip6_mib ipsq + down ill only when ill is up 2041 * ill_icmp6_mib ipsq + down ill only when ill is up 2042 * ill_arp_down_mp ipsq ipsq 2043 * ill_arp_del_mapping_mp ipsq ipsq 2044 * ill_arp_on_mp ipsq ipsq 2045 * ill_move_peer ipsq ipsq 2046 * 2047 * ill_phyint ipsq, ill_g_lock, ill_lock Any of them 2048 * ill_flags ill_lock ill_lock 2049 * ill_group ipsq, ill_g_lock, ill_lock Any of them 2050 * ill_group_next ipsq, ill_g_lock, ill_lock Any of them 2051 * ill_nd_lla_mp ipsq + down ill only when ill is up 2052 * ill_nd_lla ipsq + down ill only when ill is up 2053 * ill_nd_lla_len ipsq + down ill only when ill is up 2054 * ill_phys_addr_pend ipsq + down ill only when ill is up 2055 * ill_ifname_pending_err ipsq ipsq 2056 * ill_avl_byppa ipsq, ill_g_lock write once 2057 * 2058 * ill_fastpath_list ill_lock ill_lock 2059 * ill_refcnt ill_lock ill_lock 2060 * ill_ire_cnt ill_lock ill_lock 2061 * ill_cv ill_lock ill_lock 2062 * ill_ilm_walker_cnt ill_lock ill_lock 2063 * ill_nce_cnt ill_lock ill_lock 2064 * ill_trace ill_lock ill_lock 2065 * ill_usesrc_grp_next ill_g_usesrc_lock ill_g_usesrc_lock 2066 */ 2067 2068 /* 2069 * For ioctl restart mechanism see ip_reprocess_ioctl() 2070 */ 2071 struct ip_ioctl_cmd_s; 2072 2073 typedef int (*ifunc_t)(ipif_t *, struct sockaddr_in *, queue_t *, mblk_t *, 2074 struct ip_ioctl_cmd_s *, void *); 2075 2076 typedef struct ip_ioctl_cmd_s { 2077 int ipi_cmd; 2078 size_t ipi_copyin_size; 2079 uint_t ipi_flags; 2080 uint_t ipi_cmd_type; 2081 ifunc_t ipi_func; 2082 ifunc_t ipi_func_restart; 2083 } ip_ioctl_cmd_t; 2084 2085 /* 2086 * ipi_cmd_type: 2087 * 2088 * IF_CMD 1 old style ifreq cmd 2089 * LIF_CMD 2 new style lifreq cmd 2090 * TUN_CMD 3 tunnel related 2091 * ARP_CMD 4 arpreq cmd 2092 * XARP_CMD 5 xarpreq cmd 2093 * MSFILT_CMD 6 multicast source filter cmd 2094 * MISC_CMD 7 misc cmd (not a more specific one above) 2095 */ 2096 2097 enum { IF_CMD = 1, LIF_CMD, TUN_CMD, ARP_CMD, XARP_CMD, MSFILT_CMD, MISC_CMD }; 2098 2099 #define IPI_DONTCARE 0 /* For ioctl encoded values that don't matter */ 2100 2101 /* Flag values in ipi_flags */ 2102 #define IPI_PRIV 0x1 /* Root only command */ 2103 #define IPI_MODOK 0x2 /* Permitted on mod instance of IP */ 2104 #define IPI_WR 0x4 /* Need to grab writer access */ 2105 #define IPI_GET_CMD 0x8 /* branch to mi_copyout on success */ 2106 #define IPI_REPL 0x10 /* valid for replacement ipif created in MOVE */ 2107 #define IPI_NULL_BCONT 0x20 /* ioctl has not data and hence no b_cont */ 2108 #define IPI_PASS_DOWN 0x40 /* pass this ioctl down when a module only */ 2109 2110 extern ip_ioctl_cmd_t ip_ndx_ioctl_table[]; 2111 extern ip_ioctl_cmd_t ip_misc_ioctl_table[]; 2112 extern int ip_ndx_ioctl_count; 2113 extern int ip_misc_ioctl_count; 2114 2115 #define ILL_CLEAR_MOVE(ill) { \ 2116 ill_t *peer_ill; \ 2117 \ 2118 peer_ill = (ill)->ill_move_peer; \ 2119 ASSERT(peer_ill != NULL); \ 2120 (ill)->ill_move_in_progress = B_FALSE; \ 2121 peer_ill->ill_move_in_progress = B_FALSE; \ 2122 (ill)->ill_move_peer = NULL; \ 2123 peer_ill->ill_move_peer = NULL; \ 2124 } 2125 2126 /* Passed down by ARP to IP during I_PLINK/I_PUNLINK */ 2127 typedef struct ipmx_s { 2128 char ipmx_name[LIFNAMSIZ]; /* if name */ 2129 uint_t 2130 ipmx_arpdev_stream : 1, /* This is the arp stream */ 2131 ipmx_notused : 31; 2132 } ipmx_t; 2133 2134 /* 2135 * State for detecting if a driver supports certain features. 2136 * Support for DL_ENABMULTI_REQ uses ill_dlpi_multicast_state. 2137 * Support for DLPI M_DATA fastpath uses ill_dlpi_fastpath_state. 2138 * Support for DL_CAPABILITY_REQ uses ill_dlpi_capab_state. 2139 */ 2140 #define IDS_UNKNOWN 0 /* No DLPI request sent */ 2141 #define IDS_INPROGRESS 1 /* DLPI request sent */ 2142 #define IDS_OK 2 /* DLPI request completed successfully */ 2143 #define IDS_FAILED 3 /* DLPI request failed */ 2144 2145 /* Named Dispatch Parameter Management Structure */ 2146 typedef struct ipparam_s { 2147 uint_t ip_param_min; 2148 uint_t ip_param_max; 2149 uint_t ip_param_value; 2150 char *ip_param_name; 2151 } ipparam_t; 2152 2153 /* Extended NDP Management Structure */ 2154 typedef struct ipndp_s { 2155 ndgetf_t ip_ndp_getf; 2156 ndsetf_t ip_ndp_setf; 2157 caddr_t ip_ndp_data; 2158 char *ip_ndp_name; 2159 } ipndp_t; 2160 2161 /* 2162 * The kernel stores security attributes of all gateways in a database made 2163 * up of one or more tsol_gcdb_t elements. Each tsol_gcdb_t contains the 2164 * security-related credentials of the gateway. More than one gateways may 2165 * share entries in the database. 2166 * 2167 * The tsol_gc_t structure represents the gateway to credential association, 2168 * and refers to an entry in the database. One or more tsol_gc_t entities are 2169 * grouped together to form one or more tsol_gcgrp_t, each representing the 2170 * list of security attributes specific to the gateway. A gateway may be 2171 * associated with at most one credentials group. 2172 */ 2173 struct tsol_gcgrp_s; 2174 2175 extern uchar_t ip6opt_ls; /* TX IPv6 enabler */ 2176 2177 /* 2178 * Gateway security credential record. 2179 */ 2180 typedef struct tsol_gcdb_s { 2181 uint_t gcdb_refcnt; /* reference count */ 2182 struct rtsa_s gcdb_attr; /* security attributes */ 2183 #define gcdb_mask gcdb_attr.rtsa_mask 2184 #define gcdb_doi gcdb_attr.rtsa_doi 2185 #define gcdb_slrange gcdb_attr.rtsa_slrange 2186 } tsol_gcdb_t; 2187 2188 /* 2189 * Gateway to credential association. 2190 */ 2191 typedef struct tsol_gc_s { 2192 uint_t gc_refcnt; /* reference count */ 2193 struct tsol_gcgrp_s *gc_grp; /* pointer to group */ 2194 struct tsol_gc_s *gc_prev; /* previous in list */ 2195 struct tsol_gc_s *gc_next; /* next in list */ 2196 tsol_gcdb_t *gc_db; /* pointer to actual credentials */ 2197 } tsol_gc_t; 2198 2199 /* 2200 * Gateway credentials group address. 2201 */ 2202 typedef struct tsol_gcgrp_addr_s { 2203 int ga_af; /* address family */ 2204 in6_addr_t ga_addr; /* IPv4 mapped or IPv6 address */ 2205 } tsol_gcgrp_addr_t; 2206 2207 /* 2208 * Gateway credentials group. 2209 */ 2210 typedef struct tsol_gcgrp_s { 2211 uint_t gcgrp_refcnt; /* reference count */ 2212 krwlock_t gcgrp_rwlock; /* lock to protect following */ 2213 uint_t gcgrp_count; /* number of credentials */ 2214 tsol_gc_t *gcgrp_head; /* first credential in list */ 2215 tsol_gc_t *gcgrp_tail; /* last credential in list */ 2216 tsol_gcgrp_addr_t gcgrp_addr; /* next-hop gateway address */ 2217 } tsol_gcgrp_t; 2218 2219 extern kmutex_t gcgrp_lock; 2220 2221 #define GC_REFRELE(p) { \ 2222 ASSERT((p)->gc_grp != NULL); \ 2223 rw_enter(&(p)->gc_grp->gcgrp_rwlock, RW_WRITER); \ 2224 ASSERT((p)->gc_refcnt > 0); \ 2225 if (--((p)->gc_refcnt) == 0) \ 2226 gc_inactive(p); \ 2227 else \ 2228 rw_exit(&(p)->gc_grp->gcgrp_rwlock); \ 2229 } 2230 2231 #define GCGRP_REFHOLD(p) { \ 2232 mutex_enter(&gcgrp_lock); \ 2233 ++((p)->gcgrp_refcnt); \ 2234 ASSERT((p)->gcgrp_refcnt != 0); \ 2235 mutex_exit(&gcgrp_lock); \ 2236 } 2237 2238 #define GCGRP_REFRELE(p) { \ 2239 mutex_enter(&gcgrp_lock); \ 2240 ASSERT((p)->gcgrp_refcnt > 0); \ 2241 if (--((p)->gcgrp_refcnt) == 0) \ 2242 gcgrp_inactive(p); \ 2243 ASSERT(MUTEX_HELD(&gcgrp_lock)); \ 2244 mutex_exit(&gcgrp_lock); \ 2245 } 2246 2247 /* 2248 * IRE gateway security attributes structure, pointed to by tsol_ire_gw_secattr 2249 */ 2250 struct tsol_tnrhc; 2251 2252 typedef struct tsol_ire_gw_secattr_s { 2253 kmutex_t igsa_lock; /* lock to protect following */ 2254 struct tsol_tnrhc *igsa_rhc; /* host entry for gateway */ 2255 tsol_gc_t *igsa_gc; /* for prefix IREs */ 2256 tsol_gcgrp_t *igsa_gcgrp; /* for cache IREs */ 2257 } tsol_ire_gw_secattr_t; 2258 2259 /* 2260 * Following are the macros to increment/decrement the reference 2261 * count of the IREs and IRBs (ire bucket). 2262 * 2263 * 1) We bump up the reference count of an IRE to make sure that 2264 * it does not get deleted and freed while we are using it. 2265 * Typically all the lookup functions hold the bucket lock, 2266 * and look for the IRE. If it finds an IRE, it bumps up the 2267 * reference count before dropping the lock. Sometimes we *may* want 2268 * to bump up the reference count after we *looked* up i.e without 2269 * holding the bucket lock. So, the IRE_REFHOLD macro does not assert 2270 * on the bucket lock being held. Any thread trying to delete from 2271 * the hash bucket can still do so but cannot free the IRE if 2272 * ire_refcnt is not 0. 2273 * 2274 * 2) We bump up the reference count on the bucket where the IRE resides 2275 * (IRB), when we want to prevent the IREs getting deleted from a given 2276 * hash bucket. This makes life easier for ire_walk type functions which 2277 * wants to walk the IRE list, call a function, but needs to drop 2278 * the bucket lock to prevent recursive rw_enters. While the 2279 * lock is dropped, the list could be changed by other threads or 2280 * the same thread could end up deleting the ire or the ire pointed by 2281 * ire_next. IRE_REFHOLDing the ire or ire_next is not sufficient as 2282 * a delete will still remove the ire from the bucket while we have 2283 * dropped the lock and hence the ire_next would be NULL. Thus, we 2284 * need a mechanism to prevent deletions from a given bucket. 2285 * 2286 * To prevent deletions, we bump up the reference count on the 2287 * bucket. If the bucket is held, ire_delete just marks IRE_MARK_CONDEMNED 2288 * both on the ire's ire_marks and the bucket's irb_marks. When the 2289 * reference count on the bucket drops to zero, all the CONDEMNED ires 2290 * are deleted. We don't have to bump up the reference count on the 2291 * bucket if we are walking the bucket and never have to drop the bucket 2292 * lock. Note that IRB_REFHOLD does not prevent addition of new ires 2293 * in the list. It is okay because addition of new ires will not cause 2294 * ire_next to point to freed memory. We do IRB_REFHOLD only when 2295 * all of the 3 conditions are true : 2296 * 2297 * 1) The code needs to walk the IRE bucket from start to end. 2298 * 2) It may have to drop the bucket lock sometimes while doing (1) 2299 * 3) It does not want any ires to be deleted meanwhile. 2300 */ 2301 2302 /* 2303 * Bump up the reference count on the IRE. We cannot assert that the 2304 * bucket lock is being held as it is legal to bump up the reference 2305 * count after the first lookup has returned the IRE without 2306 * holding the lock. Currently ip_wput does this for caching IRE_CACHEs. 2307 */ 2308 2309 #ifdef DEBUG 2310 #define IRE_UNTRACE_REF(ire) ire_untrace_ref(ire); 2311 #define IRE_TRACE_REF(ire) ire_trace_ref(ire); 2312 #else 2313 #define IRE_UNTRACE_REF(ire) 2314 #define IRE_TRACE_REF(ire) 2315 #endif 2316 2317 #define IRE_REFHOLD_NOTR(ire) { \ 2318 atomic_add_32(&(ire)->ire_refcnt, 1); \ 2319 ASSERT((ire)->ire_refcnt != 0); \ 2320 } 2321 2322 #define IRE_REFHOLD(ire) { \ 2323 IRE_REFHOLD_NOTR(ire); \ 2324 IRE_TRACE_REF(ire); \ 2325 } 2326 2327 #define IRE_REFHOLD_LOCKED(ire) { \ 2328 IRE_TRACE_REF(ire); \ 2329 (ire)->ire_refcnt++; \ 2330 } 2331 2332 /* 2333 * Decrement the reference count on the IRE. 2334 * In architectures e.g sun4u, where atomic_add_32_nv is just 2335 * a cas, we need to maintain the right memory barrier semantics 2336 * as that of mutex_exit i.e all the loads and stores should complete 2337 * before the cas is executed. membar_exit() does that here. 2338 * 2339 * NOTE : This macro is used only in places where we want performance. 2340 * To avoid bloating the code, we use the function "ire_refrele" 2341 * which essentially calls the macro. 2342 */ 2343 #define IRE_REFRELE_NOTR(ire) { \ 2344 ASSERT((ire)->ire_refcnt != 0); \ 2345 membar_exit(); \ 2346 if (atomic_add_32_nv(&(ire)->ire_refcnt, -1) == 0) \ 2347 ire_inactive(ire); \ 2348 } 2349 2350 #define IRE_REFRELE(ire) { \ 2351 if (ire->ire_bucket != NULL) { \ 2352 IRE_UNTRACE_REF(ire); \ 2353 } \ 2354 IRE_REFRELE_NOTR(ire); \ 2355 } 2356 2357 /* 2358 * Bump up the reference count on the hash bucket - IRB to 2359 * prevent ires from being deleted in this bucket. 2360 */ 2361 #define IRB_REFHOLD(irb) { \ 2362 rw_enter(&(irb)->irb_lock, RW_WRITER); \ 2363 (irb)->irb_refcnt++; \ 2364 ASSERT((irb)->irb_refcnt != 0); \ 2365 rw_exit(&(irb)->irb_lock); \ 2366 } 2367 #define IRB_REFHOLD_LOCKED(irb) { \ 2368 ASSERT(RW_WRITE_HELD(&(irb)->irb_lock)); \ 2369 (irb)->irb_refcnt++; \ 2370 ASSERT((irb)->irb_refcnt != 0); \ 2371 } 2372 2373 void irb_refrele_ftable(irb_t *); 2374 /* 2375 * Note: when IRB_MARK_FTABLE (i.e., IRE_CACHETABLE entry), the irb_t 2376 * is statically allocated, so that when the irb_refcnt goes to 0, 2377 * we simply clean up the ire list and continue. 2378 */ 2379 #define IRB_REFRELE(irb) { \ 2380 if ((irb)->irb_marks & IRB_MARK_FTABLE) { \ 2381 irb_refrele_ftable((irb)); \ 2382 } else { \ 2383 rw_enter(&(irb)->irb_lock, RW_WRITER); \ 2384 ASSERT((irb)->irb_refcnt != 0); \ 2385 if (--(irb)->irb_refcnt == 0 && \ 2386 ((irb)->irb_marks & IRE_MARK_CONDEMNED)) { \ 2387 ire_t *ire_list; \ 2388 \ 2389 ire_list = ire_unlink(irb); \ 2390 rw_exit(&(irb)->irb_lock); \ 2391 ASSERT(ire_list != NULL); \ 2392 ire_cleanup(ire_list); \ 2393 } else { \ 2394 rw_exit(&(irb)->irb_lock); \ 2395 } \ 2396 } \ 2397 } 2398 2399 extern struct kmem_cache *rt_entry_cache; 2400 2401 /* 2402 * Lock the fast path mp for access, since the fp_mp can be deleted 2403 * due a DL_NOTE_FASTPATH_FLUSH in the case of IRE_BROADCAST 2404 */ 2405 2406 #define LOCK_IRE_FP_MP(ire) { \ 2407 if ((ire)->ire_type == IRE_BROADCAST) \ 2408 mutex_enter(&ire->ire_nce->nce_lock); \ 2409 } 2410 #define UNLOCK_IRE_FP_MP(ire) { \ 2411 if ((ire)->ire_type == IRE_BROADCAST) \ 2412 mutex_exit(&ire->ire_nce->nce_lock); \ 2413 } 2414 2415 typedef struct ire4 { 2416 ipaddr_t ire4_src_addr; /* Source address to use. */ 2417 ipaddr_t ire4_mask; /* Mask for matching this IRE. */ 2418 ipaddr_t ire4_addr; /* Address this IRE represents. */ 2419 ipaddr_t ire4_gateway_addr; /* Gateway if IRE_CACHE/IRE_OFFSUBNET */ 2420 ipaddr_t ire4_cmask; /* Mask from parent prefix route */ 2421 } ire4_t; 2422 2423 typedef struct ire6 { 2424 in6_addr_t ire6_src_addr; /* Source address to use. */ 2425 in6_addr_t ire6_mask; /* Mask for matching this IRE. */ 2426 in6_addr_t ire6_addr; /* Address this IRE represents. */ 2427 in6_addr_t ire6_gateway_addr; /* Gateway if IRE_CACHE/IRE_OFFSUBNET */ 2428 in6_addr_t ire6_cmask; /* Mask from parent prefix route */ 2429 } ire6_t; 2430 2431 typedef union ire_addr { 2432 ire6_t ire6_u; 2433 ire4_t ire4_u; 2434 } ire_addr_u_t; 2435 2436 /* Internet Routing Entry */ 2437 typedef struct ire_s { 2438 struct ire_s *ire_next; /* The hash chain must be first. */ 2439 struct ire_s **ire_ptpn; /* Pointer to previous next. */ 2440 uint32_t ire_refcnt; /* Number of references */ 2441 mblk_t *ire_mp; /* Non-null if allocated as mblk */ 2442 queue_t *ire_rfq; /* recv from this queue */ 2443 queue_t *ire_stq; /* send to this queue */ 2444 union { 2445 uint_t *max_fragp; /* Used only during ire creation */ 2446 uint_t max_frag; /* MTU (next hop or path). */ 2447 } imf_u; 2448 #define ire_max_frag imf_u.max_frag 2449 #define ire_max_fragp imf_u.max_fragp 2450 uint32_t ire_frag_flag; /* IPH_DF or zero. */ 2451 uint32_t ire_ident; /* Per IRE IP ident. */ 2452 uint32_t ire_tire_mark; /* Used for reclaim of unused. */ 2453 uchar_t ire_ipversion; /* IPv4/IPv6 version */ 2454 uchar_t ire_marks; /* IRE_MARK_CONDEMNED etc. */ 2455 ushort_t ire_type; /* Type of IRE */ 2456 uint_t ire_ib_pkt_count; /* Inbound packets for ire_addr */ 2457 uint_t ire_ob_pkt_count; /* Outbound packets to ire_addr */ 2458 uint_t ire_ll_hdr_length; /* Non-zero if we do M_DATA prepends */ 2459 time_t ire_create_time; /* Time (in secs) IRE was created. */ 2460 uint32_t ire_phandle; /* Associate prefix IREs to cache */ 2461 uint32_t ire_ihandle; /* Associate interface IREs to cache */ 2462 ipif_t *ire_ipif; /* the interface that this ire uses */ 2463 uint32_t ire_flags; /* flags related to route (RTF_*) */ 2464 uint_t ire_ipsec_overhead; /* IPSEC overhead */ 2465 /* 2466 * Neighbor Cache Entry for IPv6; arp info for IPv4 2467 */ 2468 struct nce_s *ire_nce; 2469 uint_t ire_masklen; /* # bits in ire_mask{,_v6} */ 2470 ire_addr_u_t ire_u; /* IPv4/IPv6 address info. */ 2471 2472 irb_t *ire_bucket; /* Hash bucket when ire_ptphn is set */ 2473 iulp_t ire_uinfo; /* Upper layer protocol info. */ 2474 /* 2475 * Protects ire_uinfo, ire_max_frag, and ire_frag_flag. 2476 */ 2477 kmutex_t ire_lock; 2478 uint_t ire_ipif_seqid; /* ipif_seqid of ire_ipif */ 2479 clock_t ire_last_used_time; /* Last used time */ 2480 tsol_ire_gw_secattr_t *ire_gw_secattr; /* gateway security attributes */ 2481 zoneid_t ire_zoneid; /* for local address discrimination */ 2482 /* 2483 * ire's that are embedded inside mblk_t and sent to the external 2484 * resolver use the ire_stq_ifindex to track the ifindex of the 2485 * ire_stq, so that the ill (if it exists) can be correctly recovered 2486 * for cleanup in the esbfree routine when arp failure occurs 2487 */ 2488 uint_t ire_stq_ifindex; 2489 uint_t ire_defense_count; /* number of ARP conflicts */ 2490 uint_t ire_defense_time; /* last time defended (secs) */ 2491 boolean_t ire_trace_disable; /* True when alloc fails */ 2492 ip_stack_t *ire_ipst; /* Does not have a netstack_hold */ 2493 } ire_t; 2494 2495 /* IPv4 compatiblity macros */ 2496 #define ire_src_addr ire_u.ire4_u.ire4_src_addr 2497 #define ire_mask ire_u.ire4_u.ire4_mask 2498 #define ire_addr ire_u.ire4_u.ire4_addr 2499 #define ire_gateway_addr ire_u.ire4_u.ire4_gateway_addr 2500 #define ire_cmask ire_u.ire4_u.ire4_cmask 2501 2502 #define ire_src_addr_v6 ire_u.ire6_u.ire6_src_addr 2503 #define ire_mask_v6 ire_u.ire6_u.ire6_mask 2504 #define ire_addr_v6 ire_u.ire6_u.ire6_addr 2505 #define ire_gateway_addr_v6 ire_u.ire6_u.ire6_gateway_addr 2506 #define ire_cmask_v6 ire_u.ire6_u.ire6_cmask 2507 2508 /* Convenient typedefs for sockaddrs */ 2509 typedef struct sockaddr_in sin_t; 2510 typedef struct sockaddr_in6 sin6_t; 2511 2512 /* Address structure used for internal bind with IP */ 2513 typedef struct ipa_conn_s { 2514 ipaddr_t ac_laddr; 2515 ipaddr_t ac_faddr; 2516 uint16_t ac_fport; 2517 uint16_t ac_lport; 2518 } ipa_conn_t; 2519 2520 typedef struct ipa6_conn_s { 2521 in6_addr_t ac6_laddr; 2522 in6_addr_t ac6_faddr; 2523 uint16_t ac6_fport; 2524 uint16_t ac6_lport; 2525 } ipa6_conn_t; 2526 2527 /* 2528 * Using ipa_conn_x_t or ipa6_conn_x_t allows us to modify the behavior of IP's 2529 * bind handler. 2530 */ 2531 typedef struct ipa_conn_extended_s { 2532 uint64_t acx_flags; 2533 ipa_conn_t acx_conn; 2534 } ipa_conn_x_t; 2535 2536 typedef struct ipa6_conn_extended_s { 2537 uint64_t ac6x_flags; 2538 ipa6_conn_t ac6x_conn; 2539 } ipa6_conn_x_t; 2540 2541 /* flag values for ipa_conn_x_t and ipa6_conn_x_t. */ 2542 #define ACX_VERIFY_DST 0x1ULL /* verify destination address is reachable */ 2543 2544 /* Name/Value Descriptor. */ 2545 typedef struct nv_s { 2546 uint64_t nv_value; 2547 char *nv_name; 2548 } nv_t; 2549 2550 #define ILL_FRAG_HASH(s, i) \ 2551 ((ntohl(s) ^ ((i) ^ ((i) >> 8))) % ILL_FRAG_HASH_TBL_COUNT) 2552 2553 /* 2554 * The MAX number of allowed fragmented packets per hash bucket 2555 * calculation is based on the most common mtu size of 1500. This limit 2556 * will work well for other mtu sizes as well. 2557 */ 2558 #define COMMON_IP_MTU 1500 2559 #define MAX_FRAG_MIN 10 2560 #define MAX_FRAG_PKTS(ipst) \ 2561 MAX(MAX_FRAG_MIN, (2 * (ipst->ips_ip_reass_queue_bytes / \ 2562 (COMMON_IP_MTU * ILL_FRAG_HASH_TBL_COUNT)))) 2563 2564 /* 2565 * Maximum dups allowed per packet. 2566 */ 2567 extern uint_t ip_max_frag_dups; 2568 2569 /* 2570 * Per-packet information for received packets and transmitted. 2571 * Used by the transport protocols when converting between the packet 2572 * and ancillary data and socket options. 2573 * 2574 * Note: This private data structure and related IPPF_* constant 2575 * definitions are exposed to enable compilation of some debugging tools 2576 * like lsof which use struct tcp_t in <inet/tcp.h>. This is intended to be 2577 * a temporary hack and long term alternate interfaces should be defined 2578 * to support the needs of such tools and private definitions moved to 2579 * private headers. 2580 */ 2581 struct ip6_pkt_s { 2582 uint_t ipp_fields; /* Which fields are valid */ 2583 uint_t ipp_sticky_ignored; /* sticky fields to ignore */ 2584 uint_t ipp_ifindex; /* pktinfo ifindex */ 2585 in6_addr_t ipp_addr; /* pktinfo src/dst addr */ 2586 uint_t ipp_unicast_hops; /* IPV6_UNICAST_HOPS */ 2587 uint_t ipp_multicast_hops; /* IPV6_MULTICAST_HOPS */ 2588 uint_t ipp_hoplimit; /* IPV6_HOPLIMIT */ 2589 uint_t ipp_hopoptslen; 2590 uint_t ipp_rtdstoptslen; 2591 uint_t ipp_rthdrlen; 2592 uint_t ipp_dstoptslen; 2593 uint_t ipp_pathmtulen; 2594 uint_t ipp_fraghdrlen; 2595 ip6_hbh_t *ipp_hopopts; 2596 ip6_dest_t *ipp_rtdstopts; 2597 ip6_rthdr_t *ipp_rthdr; 2598 ip6_dest_t *ipp_dstopts; 2599 ip6_frag_t *ipp_fraghdr; 2600 struct ip6_mtuinfo *ipp_pathmtu; 2601 in6_addr_t ipp_nexthop; /* Transmit only */ 2602 uint8_t ipp_tclass; 2603 int8_t ipp_use_min_mtu; 2604 }; 2605 typedef struct ip6_pkt_s ip6_pkt_t; 2606 2607 extern void ip6_pkt_free(ip6_pkt_t *); /* free storage inside ip6_pkt_t */ 2608 2609 /* 2610 * This struct is used by ULP_opt_set() functions to return value of IPv4 2611 * ancillary options. Currently this is only used by udp and icmp and only 2612 * IP_PKTINFO option is supported. 2613 */ 2614 typedef struct ip4_pkt_s { 2615 uint_t ip4_ill_index; /* interface index */ 2616 ipaddr_t ip4_addr; /* source address */ 2617 } ip4_pkt_t; 2618 2619 /* 2620 * Used by ULP's to pass options info to ip_output 2621 * currently only IP_PKTINFO is supported. 2622 */ 2623 typedef struct ip_opt_info_s { 2624 uint_t ip_opt_ill_index; 2625 uint_t ip_opt_flags; 2626 } ip_opt_info_t; 2627 2628 /* 2629 * value for ip_opt_flags 2630 */ 2631 #define IP_VERIFY_SRC 0x1 2632 2633 /* 2634 * This structure is used to convey information from IP and the ULP. 2635 * Currently used for the IP_RECVSLLA, IP_RECVIF and IP_RECVPKTINFO options. 2636 * The type of information field is set to IN_PKTINFO (i.e inbound pkt info) 2637 */ 2638 typedef struct ip_pktinfo { 2639 uint32_t ip_pkt_ulp_type; /* type of info sent */ 2640 uint32_t ip_pkt_flags; /* what is sent up by IP */ 2641 uint32_t ip_pkt_ifindex; /* inbound interface index */ 2642 struct sockaddr_dl ip_pkt_slla; /* has source link layer addr */ 2643 struct in_addr ip_pkt_match_addr; /* matched address */ 2644 } ip_pktinfo_t; 2645 2646 /* 2647 * flags to tell UDP what IP is sending; in_pkt_flags 2648 */ 2649 #define IPF_RECVIF 0x01 /* inbound interface index */ 2650 #define IPF_RECVSLLA 0x02 /* source link layer address */ 2651 /* 2652 * Inbound interface index + matched address. 2653 * Used only by IPV4. 2654 */ 2655 #define IPF_RECVADDR 0x04 2656 2657 /* ipp_fields values */ 2658 #define IPPF_IFINDEX 0x0001 /* Part of in6_pktinfo: ifindex */ 2659 #define IPPF_ADDR 0x0002 /* Part of in6_pktinfo: src/dst addr */ 2660 #define IPPF_SCOPE_ID 0x0004 /* Add xmit ip6i_t for sin6_scope_id */ 2661 #define IPPF_NO_CKSUM 0x0008 /* Add xmit ip6i_t for IP6I_NO_*_CKSUM */ 2662 2663 #define IPPF_RAW_CKSUM 0x0010 /* Add xmit ip6i_t for IP6I_RAW_CHECKSUM */ 2664 #define IPPF_HOPLIMIT 0x0020 2665 #define IPPF_HOPOPTS 0x0040 2666 #define IPPF_RTHDR 0x0080 2667 2668 #define IPPF_RTDSTOPTS 0x0100 2669 #define IPPF_DSTOPTS 0x0200 2670 #define IPPF_NEXTHOP 0x0400 2671 #define IPPF_PATHMTU 0x0800 2672 2673 #define IPPF_TCLASS 0x1000 2674 #define IPPF_DONTFRAG 0x2000 2675 #define IPPF_USE_MIN_MTU 0x04000 2676 #define IPPF_MULTICAST_HOPS 0x08000 2677 2678 #define IPPF_UNICAST_HOPS 0x10000 2679 #define IPPF_FRAGHDR 0x20000 2680 2681 #define IPPF_HAS_IP6I \ 2682 (IPPF_IFINDEX|IPPF_ADDR|IPPF_NEXTHOP|IPPF_SCOPE_ID| \ 2683 IPPF_NO_CKSUM|IPPF_RAW_CKSUM|IPPF_HOPLIMIT|IPPF_DONTFRAG| \ 2684 IPPF_USE_MIN_MTU|IPPF_MULTICAST_HOPS|IPPF_UNICAST_HOPS) 2685 2686 #define TCP_PORTS_OFFSET 0 2687 #define UDP_PORTS_OFFSET 0 2688 2689 /* 2690 * lookups return the ill/ipif only if the flags are clear OR Iam writer. 2691 * ill / ipif lookup functions increment the refcnt on the ill / ipif only 2692 * after calling these macros. This ensures that the refcnt on the ipif or 2693 * ill will eventually drop down to zero. 2694 */ 2695 #define ILL_LOOKUP_FAILED 1 /* Used as error code */ 2696 #define IPIF_LOOKUP_FAILED 2 /* Used as error code */ 2697 2698 #define ILL_CAN_LOOKUP(ill) \ 2699 (!((ill)->ill_state_flags & (ILL_CONDEMNED | ILL_CHANGING)) || \ 2700 IAM_WRITER_ILL(ill)) 2701 2702 #define ILL_CAN_WAIT(ill, q) \ 2703 (((q) != NULL) && !((ill)->ill_state_flags & (ILL_CONDEMNED))) 2704 2705 #define ILL_CAN_LOOKUP_WALKER(ill) \ 2706 (!((ill)->ill_state_flags & ILL_CONDEMNED)) 2707 2708 #define IPIF_CAN_LOOKUP(ipif) \ 2709 (!((ipif)->ipif_state_flags & (IPIF_CONDEMNED | IPIF_CHANGING)) || \ 2710 IAM_WRITER_IPIF(ipif)) 2711 2712 /* 2713 * If the parameter 'q' is NULL, the caller is not interested in wait and 2714 * restart of the operation if the ILL or IPIF cannot be looked up when it is 2715 * marked as 'CHANGING'. Typically a thread that tries to send out data will 2716 * end up passing NULLs as the last 4 parameters to ill_lookup_on_ifindex and 2717 * in this case 'q' is NULL 2718 */ 2719 #define IPIF_CAN_WAIT(ipif, q) \ 2720 (((q) != NULL) && !((ipif)->ipif_state_flags & (IPIF_CONDEMNED))) 2721 2722 #define IPIF_CAN_LOOKUP_WALKER(ipif) \ 2723 (!((ipif)->ipif_state_flags & (IPIF_CONDEMNED)) || \ 2724 IAM_WRITER_IPIF(ipif)) 2725 2726 /* 2727 * These macros are used by critical set ioctls and failover ioctls to 2728 * mark the ipif appropriately before starting the operation and to clear the 2729 * marks after completing the operation. 2730 */ 2731 #define IPIF_UNMARK_MOVING(ipif) \ 2732 (ipif)->ipif_state_flags &= ~IPIF_MOVING & ~IPIF_CHANGING; 2733 2734 #define ILL_UNMARK_CHANGING(ill) \ 2735 (ill)->ill_state_flags &= ~ILL_CHANGING; 2736 2737 /* Macros used to assert that this thread is a writer */ 2738 #define IAM_WRITER_IPSQ(ipsq) ((ipsq)->ipsq_writer == curthread) 2739 #define IAM_WRITER_ILL(ill) \ 2740 ((ill)->ill_phyint->phyint_ipsq->ipsq_writer == curthread) 2741 #define IAM_WRITER_IPIF(ipif) \ 2742 ((ipif)->ipif_ill->ill_phyint->phyint_ipsq->ipsq_writer == curthread) 2743 2744 /* 2745 * Grab ill locks in the proper order. The order is highest addressed 2746 * ill is locked first. 2747 */ 2748 #define GRAB_ILL_LOCKS(ill_1, ill_2) \ 2749 { \ 2750 if ((ill_1) > (ill_2)) { \ 2751 if (ill_1 != NULL) \ 2752 mutex_enter(&(ill_1)->ill_lock); \ 2753 if (ill_2 != NULL) \ 2754 mutex_enter(&(ill_2)->ill_lock); \ 2755 } else { \ 2756 if (ill_2 != NULL) \ 2757 mutex_enter(&(ill_2)->ill_lock); \ 2758 if (ill_1 != NULL && ill_1 != ill_2) \ 2759 mutex_enter(&(ill_1)->ill_lock); \ 2760 } \ 2761 } 2762 2763 #define RELEASE_ILL_LOCKS(ill_1, ill_2) \ 2764 { \ 2765 if (ill_1 != NULL) \ 2766 mutex_exit(&(ill_1)->ill_lock); \ 2767 if (ill_2 != NULL && ill_2 != ill_1) \ 2768 mutex_exit(&(ill_2)->ill_lock); \ 2769 } 2770 2771 /* Get the other protocol instance ill */ 2772 #define ILL_OTHER(ill) \ 2773 ((ill)->ill_isv6 ? (ill)->ill_phyint->phyint_illv4 : \ 2774 (ill)->ill_phyint->phyint_illv6) 2775 2776 #define MATCH_V4_ONLY 0x1 2777 #define MATCH_V6_ONLY 0x2 2778 #define MATCH_ILL_ONLY 0x4 2779 2780 /* ioctl command info: Ioctl properties extracted and stored in here */ 2781 typedef struct cmd_info_s 2782 { 2783 char ci_groupname[LIFNAMSIZ + 1]; /* SIOCSLIFGROUPNAME */ 2784 ipif_t *ci_ipif; /* ipif associated with [l]ifreq ioctl's */ 2785 sin_t *ci_sin; /* the sin struct passed down */ 2786 sin6_t *ci_sin6; /* the sin6_t struct passed down */ 2787 struct lifreq *ci_lifr; /* the lifreq struct passed down */ 2788 } cmd_info_t; 2789 2790 /* 2791 * List of AH and ESP IPsec acceleration capable ills 2792 */ 2793 typedef struct ipsec_capab_ill_s { 2794 uint_t ill_index; 2795 boolean_t ill_isv6; 2796 struct ipsec_capab_ill_s *next; 2797 } ipsec_capab_ill_t; 2798 2799 extern struct kmem_cache *ire_cache; 2800 2801 extern ipaddr_t ip_g_all_ones; 2802 2803 extern uint_t ip_loopback_mtu; /* /etc/system */ 2804 2805 extern vmem_t *ip_minor_arena; 2806 2807 /* 2808 * ip_g_forward controls IP forwarding. It takes two values: 2809 * 0: IP_FORWARD_NEVER Don't forward packets ever. 2810 * 1: IP_FORWARD_ALWAYS Forward packets for elsewhere. 2811 * 2812 * RFC1122 says there must be a configuration switch to control forwarding, 2813 * but that the default MUST be to not forward packets ever. Implicit 2814 * control based on configuration of multiple interfaces MUST NOT be 2815 * implemented (Section 3.1). SunOS 4.1 did provide the "automatic" capability 2816 * and, in fact, it was the default. That capability is now provided in the 2817 * /etc/rc2.d/S69inet script. 2818 */ 2819 2820 #define ips_ip_respond_to_address_mask_broadcast ips_param_arr[0].ip_param_value 2821 #define ips_ip_g_resp_to_echo_bcast ips_param_arr[1].ip_param_value 2822 #define ips_ip_g_resp_to_echo_mcast ips_param_arr[2].ip_param_value 2823 #define ips_ip_g_resp_to_timestamp ips_param_arr[3].ip_param_value 2824 #define ips_ip_g_resp_to_timestamp_bcast ips_param_arr[4].ip_param_value 2825 #define ips_ip_g_send_redirects ips_param_arr[5].ip_param_value 2826 #define ips_ip_g_forward_directed_bcast ips_param_arr[6].ip_param_value 2827 #define ips_ip_debug ips_param_arr[7].ip_param_value 2828 #define ips_ip_mrtdebug ips_param_arr[8].ip_param_value 2829 #define ips_ip_timer_interval ips_param_arr[9].ip_param_value 2830 #define ips_ip_ire_arp_interval ips_param_arr[10].ip_param_value 2831 #define ips_ip_ire_redir_interval ips_param_arr[11].ip_param_value 2832 #define ips_ip_def_ttl ips_param_arr[12].ip_param_value 2833 #define ips_ip_forward_src_routed ips_param_arr[13].ip_param_value 2834 #define ips_ip_wroff_extra ips_param_arr[14].ip_param_value 2835 #define ips_ip_ire_pathmtu_interval ips_param_arr[15].ip_param_value 2836 #define ips_ip_icmp_return ips_param_arr[16].ip_param_value 2837 #define ips_ip_path_mtu_discovery ips_param_arr[17].ip_param_value 2838 #define ips_ip_ignore_delete_time ips_param_arr[18].ip_param_value 2839 #define ips_ip_ignore_redirect ips_param_arr[19].ip_param_value 2840 #define ips_ip_output_queue ips_param_arr[20].ip_param_value 2841 #define ips_ip_broadcast_ttl ips_param_arr[21].ip_param_value 2842 #define ips_ip_icmp_err_interval ips_param_arr[22].ip_param_value 2843 #define ips_ip_icmp_err_burst ips_param_arr[23].ip_param_value 2844 #define ips_ip_reass_queue_bytes ips_param_arr[24].ip_param_value 2845 #define ips_ip_strict_dst_multihoming ips_param_arr[25].ip_param_value 2846 #define ips_ip_addrs_per_if ips_param_arr[26].ip_param_value 2847 #define ips_ipsec_override_persocket_policy ips_param_arr[27].ip_param_value 2848 #define ips_icmp_accept_clear_messages ips_param_arr[28].ip_param_value 2849 #define ips_igmp_accept_clear_messages ips_param_arr[29].ip_param_value 2850 2851 /* IPv6 configuration knobs */ 2852 #define ips_delay_first_probe_time ips_param_arr[30].ip_param_value 2853 #define ips_max_unicast_solicit ips_param_arr[31].ip_param_value 2854 #define ips_ipv6_def_hops ips_param_arr[32].ip_param_value 2855 #define ips_ipv6_icmp_return ips_param_arr[33].ip_param_value 2856 #define ips_ipv6_forward_src_routed ips_param_arr[34].ip_param_value 2857 #define ips_ipv6_resp_echo_mcast ips_param_arr[35].ip_param_value 2858 #define ips_ipv6_send_redirects ips_param_arr[36].ip_param_value 2859 #define ips_ipv6_ignore_redirect ips_param_arr[37].ip_param_value 2860 #define ips_ipv6_strict_dst_multihoming ips_param_arr[38].ip_param_value 2861 #define ips_ip_ire_reclaim_fraction ips_param_arr[39].ip_param_value 2862 #define ips_ipsec_policy_log_interval ips_param_arr[40].ip_param_value 2863 #define ips_pim_accept_clear_messages ips_param_arr[41].ip_param_value 2864 #define ips_ip_ndp_unsolicit_interval ips_param_arr[42].ip_param_value 2865 #define ips_ip_ndp_unsolicit_count ips_param_arr[43].ip_param_value 2866 #define ips_ipv6_ignore_home_address_opt ips_param_arr[44].ip_param_value 2867 #define ips_ip_policy_mask ips_param_arr[45].ip_param_value 2868 #define ips_ip_multirt_resolution_interval ips_param_arr[46].ip_param_value 2869 #define ips_ip_multirt_ttl ips_param_arr[47].ip_param_value 2870 #define ips_ip_multidata_outbound ips_param_arr[48].ip_param_value 2871 #define ips_ip_ndp_defense_interval ips_param_arr[49].ip_param_value 2872 #define ips_ip_max_temp_idle ips_param_arr[50].ip_param_value 2873 #define ips_ip_max_temp_defend ips_param_arr[51].ip_param_value 2874 #define ips_ip_max_defend ips_param_arr[52].ip_param_value 2875 #define ips_ip_defend_interval ips_param_arr[53].ip_param_value 2876 #define ips_ip_dup_recovery ips_param_arr[54].ip_param_value 2877 #define ips_ip_restrict_interzone_loopback ips_param_arr[55].ip_param_value 2878 #define ips_ip_lso_outbound ips_param_arr[56].ip_param_value 2879 #define ips_igmp_max_version ips_param_arr[57].ip_param_value 2880 #define ips_mld_max_version ips_param_arr[58].ip_param_value 2881 #define ips_ipv6_drop_inbound_icmpv6 ips_param_arr[59].ip_param_value 2882 2883 extern int dohwcksum; /* use h/w cksum if supported by the h/w */ 2884 #ifdef ZC_TEST 2885 extern int noswcksum; 2886 #endif 2887 2888 extern char ipif_loopback_name[]; 2889 2890 extern nv_t *ire_nv_tbl; 2891 2892 extern struct module_info ip_mod_info; 2893 2894 #define HOOKS4_INTERESTED_PHYSICAL_IN(ipst) \ 2895 ((ipst)->ips_ip4_physical_in_event.he_interested) 2896 #define HOOKS6_INTERESTED_PHYSICAL_IN(ipst) \ 2897 ((ipst)->ips_ip6_physical_in_event.he_interested) 2898 #define HOOKS4_INTERESTED_PHYSICAL_OUT(ipst) \ 2899 ((ipst)->ips_ip4_physical_out_event.he_interested) 2900 #define HOOKS6_INTERESTED_PHYSICAL_OUT(ipst) \ 2901 ((ipst)->ips_ip6_physical_out_event.he_interested) 2902 #define HOOKS4_INTERESTED_FORWARDING(ipst) \ 2903 ((ipst)->ips_ip4_forwarding_event.he_interested) 2904 #define HOOKS6_INTERESTED_FORWARDING(ipst) \ 2905 ((ipst)->ips_ip6_forwarding_event.he_interested) 2906 #define HOOKS4_INTERESTED_LOOPBACK_IN(ipst) \ 2907 ((ipst)->ips_ip4_loopback_in_event.he_interested) 2908 #define HOOKS6_INTERESTED_LOOPBACK_IN(ipst) \ 2909 ((ipst)->ips_ip6_loopback_in_event.he_interested) 2910 #define HOOKS4_INTERESTED_LOOPBACK_OUT(ipst) \ 2911 ((ipst)->ips_ip4_loopback_out_event.he_interested) 2912 #define HOOKS6_INTERESTED_LOOPBACK_OUT(ipst) \ 2913 ((ipst)->ips_ip6_loopback_out_event.he_interested) 2914 2915 /* 2916 * Hooks marcos used inside of ip 2917 */ 2918 #define IPHA_VHL ipha_version_and_hdr_length 2919 2920 #define FW_HOOKS(_hook, _event, _ilp, _olp, _iph, _fm, _m, ipst) \ 2921 \ 2922 if ((_hook).he_interested) { \ 2923 hook_pkt_event_t info; \ 2924 \ 2925 _NOTE(CONSTCOND) \ 2926 ASSERT((_ilp != NULL) || (_olp != NULL)); \ 2927 \ 2928 _NOTE(CONSTCOND) \ 2929 if ((_ilp != NULL) && \ 2930 (((ill_t *)(_ilp))->ill_phyint != NULL)) \ 2931 info.hpe_ifp = (phy_if_t)((ill_t *) \ 2932 (_ilp))->ill_phyint->phyint_hook_ifindex; \ 2933 else \ 2934 info.hpe_ifp = 0; \ 2935 \ 2936 _NOTE(CONSTCOND) \ 2937 if ((_olp != NULL) && \ 2938 (((ill_t *)(_olp))->ill_phyint != NULL)) \ 2939 info.hpe_ofp = (phy_if_t)((ill_t *) \ 2940 (_olp))->ill_phyint->phyint_hook_ifindex; \ 2941 else \ 2942 info.hpe_ofp = 0; \ 2943 info.hpe_hdr = _iph; \ 2944 info.hpe_mp = &(_fm); \ 2945 info.hpe_mb = _m; \ 2946 if (hook_run(_event, (hook_data_t)&info, \ 2947 ipst->ips_netstack) != 0) { \ 2948 ip2dbg(("%s hook dropped mblk chain %p hdr %p\n",\ 2949 (_hook).he_name, (void *)_fm, (void *)_m)); \ 2950 if (_fm != NULL) { \ 2951 freemsg(_fm); \ 2952 _fm = NULL; \ 2953 } \ 2954 _iph = NULL; \ 2955 _m = NULL; \ 2956 } else { \ 2957 _iph = info.hpe_hdr; \ 2958 _m = info.hpe_mb; \ 2959 } \ 2960 } 2961 2962 #define FW_HOOKS6(_hook, _event, _ilp, _olp, _iph, _fm, _m, ipst) \ 2963 \ 2964 if ((_hook).he_interested) { \ 2965 hook_pkt_event_t info; \ 2966 \ 2967 _NOTE(CONSTCOND) \ 2968 ASSERT((_ilp != NULL) || (_olp != NULL)); \ 2969 \ 2970 _NOTE(CONSTCOND) \ 2971 if ((_ilp != NULL) && \ 2972 (((ill_t *)(_ilp))->ill_phyint != NULL)) \ 2973 info.hpe_ifp = (phy_if_t)((ill_t *) \ 2974 (_ilp))->ill_phyint->phyint_hook_ifindex; \ 2975 else \ 2976 info.hpe_ifp = 0; \ 2977 \ 2978 _NOTE(CONSTCOND) \ 2979 if ((_olp != NULL) && \ 2980 (((ill_t *)(_olp))->ill_phyint != NULL)) \ 2981 info.hpe_ofp = (phy_if_t)((ill_t *) \ 2982 (_olp))->ill_phyint->phyint_hook_ifindex; \ 2983 else \ 2984 info.hpe_ofp = 0; \ 2985 info.hpe_hdr = _iph; \ 2986 info.hpe_mp = &(_fm); \ 2987 info.hpe_mb = _m; \ 2988 if (hook_run(_event, (hook_data_t)&info, \ 2989 ipst->ips_netstack) != 0) { \ 2990 ip2dbg(("%s hook dropped mblk chain %p hdr %p\n",\ 2991 (_hook).he_name, (void *)_fm, (void *)_m)); \ 2992 if (_fm != NULL) { \ 2993 freemsg(_fm); \ 2994 _fm = NULL; \ 2995 } \ 2996 _iph = NULL; \ 2997 _m = NULL; \ 2998 } else { \ 2999 _iph = info.hpe_hdr; \ 3000 _m = info.hpe_mb; \ 3001 } \ 3002 } 3003 3004 /* 3005 * Network byte order macros 3006 */ 3007 #ifdef _BIG_ENDIAN 3008 #define N_IN_CLASSD_NET IN_CLASSD_NET 3009 #define N_INADDR_UNSPEC_GROUP INADDR_UNSPEC_GROUP 3010 #else /* _BIG_ENDIAN */ 3011 #define N_IN_CLASSD_NET (ipaddr_t)0x000000f0U 3012 #define N_INADDR_UNSPEC_GROUP (ipaddr_t)0x000000e0U 3013 #endif /* _BIG_ENDIAN */ 3014 #define CLASSD(addr) (((addr) & N_IN_CLASSD_NET) == N_INADDR_UNSPEC_GROUP) 3015 3016 #define IP_LOOPBACK_ADDR(addr) \ 3017 ((ntohl(addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) 3018 3019 #ifdef DEBUG 3020 /* IPsec HW acceleration debugging support */ 3021 3022 #define IPSECHW_CAPAB 0x0001 /* capability negotiation */ 3023 #define IPSECHW_SADB 0x0002 /* SADB exchange */ 3024 #define IPSECHW_PKT 0x0004 /* general packet flow */ 3025 #define IPSECHW_PKTIN 0x0008 /* driver in pkt processing details */ 3026 #define IPSECHW_PKTOUT 0x0010 /* driver out pkt processing details */ 3027 3028 #define IPSECHW_DEBUG(f, x) if (ipsechw_debug & (f)) { (void) printf x; } 3029 #define IPSECHW_CALL(f, r, x) if (ipsechw_debug & (f)) { (void) r x; } 3030 3031 extern uint32_t ipsechw_debug; 3032 #else 3033 #define IPSECHW_DEBUG(f, x) {} 3034 #define IPSECHW_CALL(f, r, x) {} 3035 #endif 3036 3037 extern int ip_debug; 3038 extern uint_t ip_thread_data; 3039 extern krwlock_t ip_thread_rwlock; 3040 extern list_t ip_thread_list; 3041 3042 #ifdef IP_DEBUG 3043 #include <sys/debug.h> 3044 #include <sys/promif.h> 3045 3046 #define ip0dbg(a) printf a 3047 #define ip1dbg(a) if (ip_debug > 2) printf a 3048 #define ip2dbg(a) if (ip_debug > 3) printf a 3049 #define ip3dbg(a) if (ip_debug > 4) printf a 3050 #else 3051 #define ip0dbg(a) /* */ 3052 #define ip1dbg(a) /* */ 3053 #define ip2dbg(a) /* */ 3054 #define ip3dbg(a) /* */ 3055 #endif /* IP_DEBUG */ 3056 3057 /* Default MAC-layer address string length for mac_colon_addr */ 3058 #define MAC_STR_LEN 128 3059 3060 struct ipsec_out_s; 3061 3062 struct mac_header_info_s; 3063 3064 extern boolean_t ip_assign_ifindex(uint_t *, ip_stack_t *); 3065 extern const char *dlpi_prim_str(int); 3066 extern const char *dlpi_err_str(int); 3067 extern void ill_frag_timer(void *); 3068 extern ill_t *ill_first(int, int, ill_walk_context_t *, ip_stack_t *); 3069 extern ill_t *ill_next(ill_walk_context_t *, ill_t *); 3070 extern void ill_frag_timer_start(ill_t *); 3071 extern void ill_nic_info_dispatch(ill_t *); 3072 extern void ill_nic_info_plumb(ill_t *, boolean_t); 3073 extern mblk_t *ip_carve_mp(mblk_t **, ssize_t); 3074 extern mblk_t *ip_dlpi_alloc(size_t, t_uscalar_t); 3075 extern char *ip_dot_addr(ipaddr_t, char *); 3076 extern const char *mac_colon_addr(const uint8_t *, size_t, char *, size_t); 3077 extern void ip_lwput(queue_t *, mblk_t *); 3078 extern boolean_t icmp_err_rate_limit(ip_stack_t *); 3079 extern void icmp_time_exceeded(queue_t *, mblk_t *, uint8_t, zoneid_t, 3080 ip_stack_t *); 3081 extern void icmp_unreachable(queue_t *, mblk_t *, uint8_t, zoneid_t, 3082 ip_stack_t *); 3083 extern mblk_t *ip_add_info(mblk_t *, ill_t *, uint_t, zoneid_t, ip_stack_t *); 3084 extern mblk_t *ip_bind_v4(queue_t *, mblk_t *, conn_t *); 3085 extern int ip_bind_connected(conn_t *, mblk_t *, ipaddr_t *, uint16_t, 3086 ipaddr_t, uint16_t, boolean_t, boolean_t, boolean_t, 3087 boolean_t); 3088 extern boolean_t ip_bind_ipsec_policy_set(conn_t *, mblk_t *); 3089 extern int ip_bind_laddr(conn_t *, mblk_t *, ipaddr_t, uint16_t, 3090 boolean_t, boolean_t, boolean_t); 3091 extern uint_t ip_cksum(mblk_t *, int, uint32_t); 3092 extern int ip_close(queue_t *, int); 3093 extern uint16_t ip_csum_hdr(ipha_t *); 3094 extern void ip_proto_not_sup(queue_t *, mblk_t *, uint_t, zoneid_t, 3095 ip_stack_t *); 3096 extern void ip_ire_g_fini(void); 3097 extern void ip_ire_g_init(void); 3098 extern void ip_ire_fini(ip_stack_t *); 3099 extern void ip_ire_init(ip_stack_t *); 3100 extern int ip_openv4(queue_t *q, dev_t *devp, int flag, int sflag, 3101 cred_t *credp); 3102 extern int ip_openv6(queue_t *q, dev_t *devp, int flag, int sflag, 3103 cred_t *credp); 3104 extern int ip_reassemble(mblk_t *, ipf_t *, uint_t, boolean_t, ill_t *, 3105 size_t); 3106 extern int ip_opt_set_ill(conn_t *, int, boolean_t, boolean_t, 3107 int, int, mblk_t *); 3108 extern void ip_rput(queue_t *, mblk_t *); 3109 extern void ip_input(ill_t *, ill_rx_ring_t *, mblk_t *, 3110 struct mac_header_info_s *); 3111 extern void ip_rput_dlpi(queue_t *, mblk_t *); 3112 extern void ip_rput_forward(ire_t *, ipha_t *, mblk_t *, ill_t *); 3113 extern void ip_rput_forward_multicast(ipaddr_t, mblk_t *, ipif_t *); 3114 3115 extern void ip_mib2_add_ip_stats(mib2_ipIfStatsEntry_t *, 3116 mib2_ipIfStatsEntry_t *); 3117 extern void ip_mib2_add_icmp6_stats(mib2_ipv6IfIcmpEntry_t *, 3118 mib2_ipv6IfIcmpEntry_t *); 3119 extern void ip_udp_input(queue_t *, mblk_t *, ipha_t *, ire_t *, ill_t *); 3120 extern void ip_proto_input(queue_t *, mblk_t *, ipha_t *, ire_t *, ill_t *, 3121 boolean_t); 3122 extern void ip_rput_other(ipsq_t *, queue_t *, mblk_t *, void *); 3123 extern ire_t *ip_check_multihome(void *, ire_t *, ill_t *); 3124 extern void ip_setpktversion(conn_t *, boolean_t, boolean_t, ip_stack_t *); 3125 extern void ip_trash_ire_reclaim(void *); 3126 extern void ip_trash_timer_expire(void *); 3127 extern void ip_wput(queue_t *, mblk_t *); 3128 extern void ip_output(void *, mblk_t *, void *, int); 3129 extern void ip_output_options(void *, mblk_t *, void *, int, 3130 ip_opt_info_t *); 3131 3132 extern void ip_wput_ire(queue_t *, mblk_t *, ire_t *, conn_t *, int, 3133 zoneid_t); 3134 extern void ip_wput_local(queue_t *, ill_t *, ipha_t *, mblk_t *, ire_t *, 3135 int, zoneid_t); 3136 extern void ip_wput_multicast(queue_t *, mblk_t *, ipif_t *, zoneid_t); 3137 extern void ip_wput_nondata(ipsq_t *, queue_t *, mblk_t *, void *); 3138 extern void ip_wsrv(queue_t *); 3139 extern char *ip_nv_lookup(nv_t *, int); 3140 extern boolean_t ip_local_addr_ok_v6(const in6_addr_t *, const in6_addr_t *); 3141 extern boolean_t ip_remote_addr_ok_v6(const in6_addr_t *, const in6_addr_t *); 3142 extern ipaddr_t ip_massage_options(ipha_t *, netstack_t *); 3143 extern ipaddr_t ip_net_mask(ipaddr_t); 3144 extern void ip_newroute(queue_t *, mblk_t *, ipaddr_t, conn_t *, zoneid_t, 3145 ip_stack_t *); 3146 extern ipxmit_state_t ip_xmit_v4(mblk_t *, ire_t *, struct ipsec_out_s *, 3147 boolean_t); 3148 extern int ip_hdr_complete(ipha_t *, zoneid_t, ip_stack_t *); 3149 3150 extern struct qinit iprinitv6; 3151 extern struct qinit ipwinitv6; 3152 3153 extern void conn_drain_insert(conn_t *connp); 3154 extern int conn_ipsec_length(conn_t *connp); 3155 extern void ip_wput_ipsec_out(queue_t *, mblk_t *, ipha_t *, ill_t *, 3156 ire_t *); 3157 extern ipaddr_t ip_get_dst(ipha_t *); 3158 extern int ipsec_out_extra_length(mblk_t *); 3159 extern int ipsec_in_extra_length(mblk_t *); 3160 extern mblk_t *ipsec_in_alloc(boolean_t, netstack_t *); 3161 extern boolean_t ipsec_in_is_secure(mblk_t *); 3162 extern void ipsec_out_process(queue_t *, mblk_t *, ire_t *, uint_t); 3163 extern void ipsec_out_to_in(mblk_t *); 3164 extern void ip_fanout_proto_again(mblk_t *, ill_t *, ill_t *, ire_t *); 3165 3166 extern void ire_cleanup(ire_t *); 3167 extern void ire_inactive(ire_t *); 3168 extern boolean_t irb_inactive(irb_t *); 3169 extern ire_t *ire_unlink(irb_t *); 3170 3171 #ifdef DEBUG 3172 extern boolean_t th_trace_ref(const void *, ip_stack_t *); 3173 extern void th_trace_unref(const void *); 3174 extern void th_trace_cleanup(const void *, boolean_t); 3175 extern void ire_trace_ref(ire_t *); 3176 extern void ire_untrace_ref(ire_t *); 3177 #endif 3178 3179 extern int ip_srcid_insert(const in6_addr_t *, zoneid_t, ip_stack_t *); 3180 extern int ip_srcid_remove(const in6_addr_t *, zoneid_t, ip_stack_t *); 3181 extern void ip_srcid_find_id(uint_t, in6_addr_t *, zoneid_t, netstack_t *); 3182 extern uint_t ip_srcid_find_addr(const in6_addr_t *, zoneid_t, netstack_t *); 3183 extern int ip_srcid_report(queue_t *, mblk_t *, caddr_t, cred_t *); 3184 3185 extern uint8_t ipoptp_next(ipoptp_t *); 3186 extern uint8_t ipoptp_first(ipoptp_t *, ipha_t *); 3187 extern int ip_opt_get_user(const ipha_t *, uchar_t *); 3188 extern ill_t *ip_grab_attach_ill(ill_t *, mblk_t *, int, boolean_t, 3189 ip_stack_t *); 3190 extern ire_t *conn_set_outgoing_ill(conn_t *, ire_t *, ill_t **); 3191 extern int ipsec_req_from_conn(conn_t *, ipsec_req_t *, int); 3192 extern int ip_snmp_get(queue_t *q, mblk_t *mctl, int level); 3193 extern int ip_snmp_set(queue_t *q, int, int, uchar_t *, int); 3194 extern void ip_process_ioctl(ipsq_t *, queue_t *, mblk_t *, void *); 3195 extern void ip_quiesce_conn(conn_t *); 3196 extern void ip_reprocess_ioctl(ipsq_t *, queue_t *, mblk_t *, void *); 3197 extern void ip_restart_optmgmt(ipsq_t *, queue_t *, mblk_t *, void *); 3198 extern void ip_ioctl_finish(queue_t *, mblk_t *, int, int, ipsq_t *); 3199 3200 extern boolean_t ip_cmpbuf(const void *, uint_t, boolean_t, const void *, 3201 uint_t); 3202 extern boolean_t ip_allocbuf(void **, uint_t *, boolean_t, const void *, 3203 uint_t); 3204 extern void ip_savebuf(void **, uint_t *, boolean_t, const void *, uint_t); 3205 3206 extern boolean_t ipsq_pending_mp_cleanup(ill_t *, conn_t *); 3207 extern void conn_ioctl_cleanup(conn_t *); 3208 extern ill_t *conn_get_held_ill(conn_t *, ill_t **, int *); 3209 extern ill_t *ip_newroute_get_dst_ill(ill_t *); 3210 3211 struct multidata_s; 3212 struct pdesc_s; 3213 3214 extern mblk_t *ip_mdinfo_alloc(ill_mdt_capab_t *); 3215 extern mblk_t *ip_mdinfo_return(ire_t *, conn_t *, char *, ill_mdt_capab_t *); 3216 extern mblk_t *ip_lsoinfo_alloc(ill_lso_capab_t *); 3217 extern mblk_t *ip_lsoinfo_return(ire_t *, conn_t *, char *, 3218 ill_lso_capab_t *); 3219 extern uint_t ip_md_cksum(struct pdesc_s *, int, uint_t); 3220 extern boolean_t ip_md_addr_attr(struct multidata_s *, struct pdesc_s *, 3221 const mblk_t *); 3222 extern boolean_t ip_md_hcksum_attr(struct multidata_s *, struct pdesc_s *, 3223 uint32_t, uint32_t, uint32_t, uint32_t); 3224 extern boolean_t ip_md_zcopy_attr(struct multidata_s *, struct pdesc_s *, 3225 uint_t); 3226 extern mblk_t *ip_unbind(queue_t *, mblk_t *); 3227 3228 extern phyint_t *phyint_lookup_group(char *, boolean_t, ip_stack_t *); 3229 extern phyint_t *phyint_lookup_group_ifindex(uint_t, ip_stack_t *); 3230 3231 extern void tnet_init(void); 3232 extern void tnet_fini(void); 3233 3234 /* Hooks for CGTP (multirt routes) filtering module */ 3235 #define CGTP_FILTER_REV_1 1 3236 #define CGTP_FILTER_REV_2 2 3237 #define CGTP_FILTER_REV_3 3 3238 #define CGTP_FILTER_REV CGTP_FILTER_REV_3 3239 3240 /* cfo_filter and cfo_filter_v6 hooks return values */ 3241 #define CGTP_IP_PKT_NOT_CGTP 0 3242 #define CGTP_IP_PKT_PREMIUM 1 3243 #define CGTP_IP_PKT_DUPLICATE 2 3244 3245 /* Version 3 of the filter interface */ 3246 typedef struct cgtp_filter_ops { 3247 int cfo_filter_rev; /* CGTP_FILTER_REV_3 */ 3248 int (*cfo_change_state)(netstackid_t, int); 3249 int (*cfo_add_dest_v4)(netstackid_t, ipaddr_t, ipaddr_t, 3250 ipaddr_t, ipaddr_t); 3251 int (*cfo_del_dest_v4)(netstackid_t, ipaddr_t, ipaddr_t); 3252 int (*cfo_add_dest_v6)(netstackid_t, in6_addr_t *, in6_addr_t *, 3253 in6_addr_t *, in6_addr_t *); 3254 int (*cfo_del_dest_v6)(netstackid_t, in6_addr_t *, in6_addr_t *); 3255 int (*cfo_filter)(netstackid_t, uint_t, mblk_t *); 3256 int (*cfo_filter_v6)(netstackid_t, uint_t, ip6_t *, 3257 ip6_frag_t *); 3258 } cgtp_filter_ops_t; 3259 3260 #define CGTP_MCAST_SUCCESS 1 3261 3262 /* 3263 * The separate CGTP module needs this global symbol so that it 3264 * can check the version and determine whether to use the old or the new 3265 * version of the filtering interface. 3266 */ 3267 extern int ip_cgtp_filter_rev; 3268 3269 extern int ip_cgtp_filter_supported(void); 3270 extern int ip_cgtp_filter_register(netstackid_t, cgtp_filter_ops_t *); 3271 extern int ip_cgtp_filter_unregister(netstackid_t); 3272 extern int ip_cgtp_filter_is_registered(netstackid_t); 3273 3274 /* Flags for ire_multirt_lookup() */ 3275 3276 #define MULTIRT_USESTAMP 0x0001 3277 #define MULTIRT_SETSTAMP 0x0002 3278 #define MULTIRT_CACHEGW 0x0004 3279 3280 /* Debug stuff for multirt route resolution. */ 3281 #if defined(DEBUG) && !defined(__lint) 3282 /* Our "don't send, rather drop" flag. */ 3283 #define MULTIRT_DEBUG_FLAG 0x8000 3284 3285 #define MULTIRT_TRACE(x) ip2dbg(x) 3286 3287 #define MULTIRT_DEBUG_TAG(mblk) \ 3288 do { \ 3289 ASSERT(mblk != NULL); \ 3290 MULTIRT_TRACE(("%s[%d]: tagging mblk %p, tag was %d\n", \ 3291 __FILE__, __LINE__, \ 3292 (void *)(mblk), (mblk)->b_flag & MULTIRT_DEBUG_FLAG)); \ 3293 (mblk)->b_flag |= MULTIRT_DEBUG_FLAG; \ 3294 } while (0) 3295 3296 #define MULTIRT_DEBUG_UNTAG(mblk) \ 3297 do { \ 3298 ASSERT(mblk != NULL); \ 3299 MULTIRT_TRACE(("%s[%d]: untagging mblk %p, tag was %d\n", \ 3300 __FILE__, __LINE__, \ 3301 (void *)(mblk), (mblk)->b_flag & MULTIRT_DEBUG_FLAG)); \ 3302 (mblk)->b_flag &= ~MULTIRT_DEBUG_FLAG; \ 3303 } while (0) 3304 3305 #define MULTIRT_DEBUG_TAGGED(mblk) \ 3306 (((mblk)->b_flag & MULTIRT_DEBUG_FLAG) ? B_TRUE : B_FALSE) 3307 #else 3308 #define MULTIRT_DEBUG_TAG(mblk) ASSERT(mblk != NULL) 3309 #define MULTIRT_DEBUG_UNTAG(mblk) ASSERT(mblk != NULL) 3310 #define MULTIRT_DEBUG_TAGGED(mblk) B_FALSE 3311 #endif 3312 3313 /* 3314 * Per-ILL Multidata Transmit capabilities. 3315 */ 3316 struct ill_mdt_capab_s { 3317 uint_t ill_mdt_version; /* interface version */ 3318 uint_t ill_mdt_on; /* on/off switch for MDT on this ILL */ 3319 uint_t ill_mdt_hdr_head; /* leading header fragment extra space */ 3320 uint_t ill_mdt_hdr_tail; /* trailing header fragment extra space */ 3321 uint_t ill_mdt_max_pld; /* maximum payload buffers per Multidata */ 3322 uint_t ill_mdt_span_limit; /* maximum payload span per packet */ 3323 }; 3324 3325 struct ill_hcksum_capab_s { 3326 uint_t ill_hcksum_version; /* interface version */ 3327 uint_t ill_hcksum_txflags; /* capabilities on transmit */ 3328 }; 3329 3330 struct ill_zerocopy_capab_s { 3331 uint_t ill_zerocopy_version; /* interface version */ 3332 uint_t ill_zerocopy_flags; /* capabilities */ 3333 }; 3334 3335 struct ill_lso_capab_s { 3336 uint_t ill_lso_version; /* interface version */ 3337 uint_t ill_lso_on; /* on/off switch for LSO on this ILL */ 3338 uint_t ill_lso_flags; /* capabilities */ 3339 uint_t ill_lso_max; /* maximum size of payload */ 3340 }; 3341 3342 /* Possible ill_states */ 3343 #define ILL_RING_INPROC 3 /* Being assigned to squeue */ 3344 #define ILL_RING_INUSE 2 /* Already Assigned to Rx Ring */ 3345 #define ILL_RING_BEING_FREED 1 /* Being Unassigned */ 3346 #define ILL_RING_FREE 0 /* Available to be assigned to Ring */ 3347 3348 #define ILL_MAX_RINGS 256 /* Max num of rx rings we can manage */ 3349 #define ILL_POLLING 0x01 /* Polling in use */ 3350 3351 /* 3352 * These functions pointer types are exported by the mac/dls layer. 3353 * we need to duplicate the definitions here because we cannot 3354 * include mac/dls header files here. 3355 */ 3356 typedef void (*ip_mac_blank_t)(void *, time_t, uint_t); 3357 typedef void (*ip_dld_tx_t)(void *, mblk_t *); 3358 3359 typedef void (*ip_dls_chg_soft_ring_t)(void *, int); 3360 typedef void (*ip_dls_bind_t)(void *, processorid_t); 3361 typedef void (*ip_dls_unbind_t)(void *); 3362 3363 struct ill_rx_ring { 3364 ip_mac_blank_t rr_blank; /* Driver interrupt blanking func */ 3365 void *rr_handle; /* Handle for Rx ring */ 3366 squeue_t *rr_sqp; /* Squeue the ring is bound to */ 3367 ill_t *rr_ill; /* back pointer to ill */ 3368 clock_t rr_poll_time; /* Last lbolt polling was used */ 3369 uint32_t rr_poll_state; /* polling state flags */ 3370 uint32_t rr_max_blank_time; /* Max interrupt blank */ 3371 uint32_t rr_min_blank_time; /* Min interrupt blank */ 3372 uint32_t rr_max_pkt_cnt; /* Max pkts before interrupt */ 3373 uint32_t rr_min_pkt_cnt; /* Mix pkts before interrupt */ 3374 uint32_t rr_normal_blank_time; /* Normal intr freq */ 3375 uint32_t rr_normal_pkt_cnt; /* Normal intr pkt cnt */ 3376 uint32_t rr_ring_state; /* State of this ring */ 3377 }; 3378 3379 struct ill_dls_capab_s { 3380 ip_dld_tx_t ill_tx; /* Driver Tx routine */ 3381 void *ill_tx_handle; /* Driver Tx handle */ 3382 ip_dls_chg_soft_ring_t ill_dls_change_status; 3383 /* change soft ring fanout */ 3384 ip_dls_bind_t ill_dls_bind; /* to add CPU affinity */ 3385 ip_dls_unbind_t ill_dls_unbind; /* remove CPU affinity */ 3386 ill_rx_ring_t *ill_ring_tbl; /* Ring to Sqp mapping table */ 3387 uint_t ill_dls_soft_ring_cnt; /* Number of soft ring */ 3388 conn_t *ill_unbind_conn; /* Conn used during unplumb */ 3389 }; 3390 3391 /* 3392 * IP squeues exports 3393 */ 3394 extern int ip_squeue_profile; 3395 extern int ip_squeue_bind; 3396 extern boolean_t ip_squeue_fanout; 3397 extern boolean_t ip_squeue_soft_ring; 3398 extern uint_t ip_threads_per_cpu; 3399 extern uint_t ip_squeues_per_cpu; 3400 extern uint_t ip_soft_rings_cnt; 3401 3402 typedef struct squeue_set_s { 3403 kmutex_t sqs_lock; 3404 struct squeue_s **sqs_list; 3405 int sqs_size; 3406 int sqs_max_size; 3407 processorid_t sqs_bind; 3408 } squeue_set_t; 3409 3410 #define IP_SQUEUE_GET(hint) \ 3411 ((!ip_squeue_fanout) ? (CPU->cpu_squeue_set->sqs_list[0]) : \ 3412 ip_squeue_random(hint)) 3413 3414 typedef void (*squeue_func_t)(squeue_t *, mblk_t *, sqproc_t, void *, uint8_t); 3415 3416 extern void ip_squeue_init(void (*)(squeue_t *)); 3417 extern squeue_t *ip_squeue_random(uint_t); 3418 extern squeue_t *ip_squeue_get(ill_rx_ring_t *); 3419 extern int ip_squeue_bind_set(queue_t *, mblk_t *, char *, caddr_t, cred_t *); 3420 extern void ip_squeue_clean_all(ill_t *); 3421 extern void ip_soft_ring_assignment(ill_t *, ill_rx_ring_t *, 3422 mblk_t *, struct mac_header_info_s *); 3423 3424 extern void ip_resume_tcp_bind(void *, mblk_t *, void *); 3425 extern void tcp_wput(queue_t *, mblk_t *); 3426 3427 extern int ip_fill_mtuinfo(struct in6_addr *, in_port_t, 3428 struct ip6_mtuinfo *, netstack_t *); 3429 extern ipif_t *conn_get_held_ipif(conn_t *, ipif_t **, int *); 3430 3431 typedef void (*ipsq_func_t)(ipsq_t *, queue_t *, mblk_t *, void *); 3432 3433 /* 3434 * Squeue tags. Tags only need to be unique when the callback function is the 3435 * same to distinguish between different calls, but we use unique tags for 3436 * convenience anyway. 3437 */ 3438 #define SQTAG_IP_INPUT 1 3439 #define SQTAG_TCP_INPUT_ICMP_ERR 2 3440 #define SQTAG_TCP6_INPUT_ICMP_ERR 3 3441 #define SQTAG_IP_TCP_INPUT 4 3442 #define SQTAG_IP6_TCP_INPUT 5 3443 #define SQTAG_IP_TCP_CLOSE 6 3444 #define SQTAG_TCP_OUTPUT 7 3445 #define SQTAG_TCP_TIMER 8 3446 #define SQTAG_TCP_TIMEWAIT 9 3447 #define SQTAG_TCP_ACCEPT_FINISH 10 3448 #define SQTAG_TCP_ACCEPT_FINISH_Q0 11 3449 #define SQTAG_TCP_ACCEPT_PENDING 12 3450 #define SQTAG_TCP_LISTEN_DISCON 13 3451 #define SQTAG_TCP_CONN_REQ_1 14 3452 #define SQTAG_TCP_EAGER_BLOWOFF 15 3453 #define SQTAG_TCP_EAGER_CLEANUP 16 3454 #define SQTAG_TCP_EAGER_CLEANUP_Q0 17 3455 #define SQTAG_TCP_CONN_IND 18 3456 #define SQTAG_TCP_RSRV 19 3457 #define SQTAG_TCP_ABORT_BUCKET 20 3458 #define SQTAG_TCP_REINPUT 21 3459 #define SQTAG_TCP_REINPUT_EAGER 22 3460 #define SQTAG_TCP_INPUT_MCTL 23 3461 #define SQTAG_TCP_RPUTOTHER 24 3462 #define SQTAG_IP_PROTO_AGAIN 25 3463 #define SQTAG_IP_FANOUT_TCP 26 3464 #define SQTAG_IPSQ_CLEAN_RING 27 3465 #define SQTAG_TCP_WPUT_OTHER 28 3466 #define SQTAG_TCP_CONN_REQ_UNBOUND 29 3467 #define SQTAG_TCP_SEND_PENDING 30 3468 #define SQTAG_BIND_RETRY 31 3469 #define SQTAG_UDP_FANOUT 32 3470 #define SQTAG_UDP_INPUT 33 3471 #define SQTAG_UDP_WPUT 34 3472 #define SQTAG_UDP_OUTPUT 35 3473 #define SQTAG_TCP_KSSL_INPUT 36 3474 #define SQTAG_TCP_DROP_Q0 37 3475 #define SQTAG_TCP_CONN_REQ_2 38 3476 3477 #define NOT_OVER_IP(ip_wq) \ 3478 (ip_wq->q_next != NULL || \ 3479 (ip_wq->q_qinfo->qi_minfo->mi_idname) == NULL || \ 3480 strcmp(ip_wq->q_qinfo->qi_minfo->mi_idname, \ 3481 IP_MOD_NAME) != 0 || \ 3482 ip_wq->q_qinfo->qi_minfo->mi_idnum != IP_MOD_ID) 3483 3484 #endif /* _KERNEL */ 3485 3486 #ifdef __cplusplus 3487 } 3488 #endif 3489 3490 #endif /* _INET_IP_H */ 3491