Print this page
    
OS-7184 prototype
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/uts/common/inet/ip.h
          +++ new/usr/src/uts/common/inet/ip.h
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  11   11   * and limitations under the License.
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 1990 Mentat Inc.
  24   24   * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
  25   25   * Copyright 2017 Nexenta Systems, Inc.
  26   26   * Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved.
  27   27   * Copyright 2019, Joyent, Inc.
  28   28   */
  29   29  
  30   30  #ifndef _INET_IP_H
  31   31  #define _INET_IP_H
  32   32  
  33   33  #ifdef  __cplusplus
  34   34  extern "C" {
  35   35  #endif
  36   36  
  37   37  #include <sys/isa_defs.h>
  38   38  #include <sys/types.h>
  39   39  #include <inet/mib2.h>
  40   40  #include <inet/nd.h>
  41   41  #include <sys/atomic.h>
  42   42  #include <net/if_dl.h>
  43   43  #include <net/if.h>
  44   44  #include <netinet/ip.h>
  45   45  #include <netinet/igmp.h>
  46   46  #include <sys/neti.h>
  47   47  #include <sys/hook.h>
  48   48  #include <sys/hook_event.h>
  49   49  #include <sys/hook_impl.h>
  50   50  #include <inet/ip_stack.h>
  51   51  
  52   52  #ifdef _KERNEL
  53   53  #include <netinet/ip6.h>
  54   54  #include <sys/avl.h>
  55   55  #include <sys/list.h>
  56   56  #include <sys/vmem.h>
  57   57  #include <sys/squeue.h>
  58   58  #include <net/route.h>
  59   59  #include <sys/systm.h>
  60   60  #include <net/radix.h>
  61   61  #include <sys/modhash.h>
  62   62  
  63   63  #ifdef DEBUG
  64   64  #define CONN_DEBUG
  65   65  #endif
  66   66  
  67   67  #define IP_DEBUG
  68   68  /*
  69   69   * The mt-streams(9F) flags for the IP module; put here so that other
  70   70   * "drivers" that are actually IP (e.g., ICMP, UDP) can use the same set
  71   71   * of flags.
  72   72   */
  73   73  #define IP_DEVMTFLAGS D_MP
  74   74  #endif  /* _KERNEL */
  75   75  
  76   76  #define IP_MOD_NAME     "ip"
  77   77  #define IP_DEV_NAME     "/dev/ip"
  78   78  #define IP6_DEV_NAME    "/dev/ip6"
  79   79  
  80   80  #define UDP_MOD_NAME    "udp"
  81   81  #define UDP_DEV_NAME    "/dev/udp"
  82   82  #define UDP6_DEV_NAME   "/dev/udp6"
  83   83  
  84   84  #define TCP_MOD_NAME    "tcp"
  85   85  #define TCP_DEV_NAME    "/dev/tcp"
  86   86  #define TCP6_DEV_NAME   "/dev/tcp6"
  87   87  
  88   88  #define SCTP_MOD_NAME   "sctp"
  89   89  
  90   90  #ifndef _IPADDR_T
  91   91  #define _IPADDR_T
  92   92  typedef uint32_t ipaddr_t;
  93   93  #endif
  94   94  
  95   95  /* Number of bits in an address */
  96   96  #define IP_ABITS                32
  97   97  #define IPV4_ABITS              IP_ABITS
  98   98  #define IPV6_ABITS              128
  99   99  #define IP_MAX_HW_LEN   40
 100  100  
 101  101  #define IP_HOST_MASK            (ipaddr_t)0xffffffffU
 102  102  
 103  103  #define IP_CSUM(mp, off, sum)           (~ip_cksum(mp, off, sum) & 0xFFFF)
 104  104  #define IP_CSUM_PARTIAL(mp, off, sum)   ip_cksum(mp, off, sum)
 105  105  #define IP_BCSUM_PARTIAL(bp, len, sum)  bcksum(bp, len, sum)
 106  106  
 107  107  #define ILL_FRAG_HASH_TBL_COUNT ((unsigned int)64)
 108  108  #define ILL_FRAG_HASH_TBL_SIZE  (ILL_FRAG_HASH_TBL_COUNT * sizeof (ipfb_t))
 109  109  
 110  110  #define IPV4_ADDR_LEN                   4
 111  111  #define IP_ADDR_LEN                     IPV4_ADDR_LEN
 112  112  #define IP_ARP_PROTO_TYPE               0x0800
 113  113  
 114  114  #define IPV4_VERSION                    4
 115  115  #define IP_VERSION                      IPV4_VERSION
 116  116  #define IP_SIMPLE_HDR_LENGTH_IN_WORDS   5
 117  117  #define IP_SIMPLE_HDR_LENGTH            20
 118  118  #define IP_MAX_HDR_LENGTH               60
 119  119  
 120  120  #define IP_MAX_OPT_LENGTH (IP_MAX_HDR_LENGTH-IP_SIMPLE_HDR_LENGTH)
 121  121  
 122  122  #define IP_MIN_MTU                      (IP_MAX_HDR_LENGTH + 8) /* 68 bytes */
 123  123  
 124  124  /*
 125  125   * XXX IP_MAXPACKET is defined in <netinet/ip.h> as well. At some point the
 126  126   * 2 files should be cleaned up to remove all redundant definitions.
 127  127   */
 128  128  #define IP_MAXPACKET                    65535
 129  129  #define IP_SIMPLE_HDR_VERSION \
 130  130          ((IP_VERSION << 4) | IP_SIMPLE_HDR_LENGTH_IN_WORDS)
 131  131  
 132  132  #define UDPH_SIZE                       8
 133  133  
 134  134  /*
 135  135   * Constants and type definitions to support IP IOCTL commands
 136  136   */
 137  137  #define IP_IOCTL                        (('i'<<8)|'p')
 138  138  #define IP_IOC_IRE_DELETE               4
 139  139  #define IP_IOC_IRE_DELETE_NO_REPLY      5
 140  140  #define IP_IOC_RTS_REQUEST              7
 141  141  
 142  142  /* Common definitions used by IP IOCTL data structures */
 143  143  typedef struct ipllcmd_s {
 144  144          uint_t  ipllc_cmd;
 145  145          uint_t  ipllc_name_offset;
 146  146          uint_t  ipllc_name_length;
 147  147  } ipllc_t;
 148  148  
 149  149  /* IP IRE Delete Command Structure. */
 150  150  typedef struct ipid_s {
 151  151          ipllc_t ipid_ipllc;
 152  152          uint_t  ipid_ire_type;
 153  153          uint_t  ipid_addr_offset;
 154  154          uint_t  ipid_addr_length;
 155  155          uint_t  ipid_mask_offset;
 156  156          uint_t  ipid_mask_length;
 157  157  } ipid_t;
 158  158  
 159  159  #define ipid_cmd                ipid_ipllc.ipllc_cmd
 160  160  
 161  161  #ifdef _KERNEL
 162  162  /*
 163  163   * Temporary state for ip options parser.
 164  164   */
 165  165  typedef struct ipoptp_s
 166  166  {
 167  167          uint8_t         *ipoptp_next;   /* next option to look at */
 168  168          uint8_t         *ipoptp_end;    /* end of options */
 169  169          uint8_t         *ipoptp_cur;    /* start of current option */
 170  170          uint8_t         ipoptp_len;     /* length of current option */
 171  171          uint32_t        ipoptp_flags;
 172  172  } ipoptp_t;
 173  173  
 174  174  /*
 175  175   * Flag(s) for ipoptp_flags
 176  176   */
 177  177  #define IPOPTP_ERROR    0x00000001
 178  178  #endif  /* _KERNEL */
 179  179  
 180  180  /* Controls forwarding of IP packets, set via ipadm(1M)/ndd(1M) */
 181  181  #define IP_FORWARD_NEVER        0
 182  182  #define IP_FORWARD_ALWAYS       1
 183  183  
 184  184  #define WE_ARE_FORWARDING(ipst) ((ipst)->ips_ip_forwarding == IP_FORWARD_ALWAYS)
 185  185  
 186  186  #define IPH_HDR_LENGTH(ipha)                                            \
 187  187          ((int)(((ipha_t *)ipha)->ipha_version_and_hdr_length & 0xF) << 2)
 188  188  
 189  189  #define IPH_HDR_VERSION(ipha)                                           \
 190  190          ((int)(((ipha_t *)ipha)->ipha_version_and_hdr_length) >> 4)
 191  191  
 192  192  #ifdef _KERNEL
 193  193  /*
 194  194   * IP reassembly macros.  We hide starting and ending offsets in b_next and
 195  195   * b_prev of messages on the reassembly queue.  The messages are chained using
 196  196   * b_cont.  These macros are used in ip_reassemble() so we don't have to see
 197  197   * the ugly casts and assignments.
 198  198   * Note that the offsets are <= 64k i.e. a uint_t is sufficient to represent
 199  199   * them.
 200  200   */
 201  201  #define IP_REASS_START(mp)              ((uint_t)(uintptr_t)((mp)->b_next))
 202  202  #define IP_REASS_SET_START(mp, u)       \
 203  203          ((mp)->b_next = (mblk_t *)(uintptr_t)(u))
 204  204  #define IP_REASS_END(mp)                ((uint_t)(uintptr_t)((mp)->b_prev))
 205  205  #define IP_REASS_SET_END(mp, u)         \
 206  206          ((mp)->b_prev = (mblk_t *)(uintptr_t)(u))
 207  207  
 208  208  #define IP_REASS_COMPLETE       0x1
 209  209  #define IP_REASS_PARTIAL        0x2
 210  210  #define IP_REASS_FAILED         0x4
 211  211  
 212  212  /*
 213  213   * Test to determine whether this is a module instance of IP or a
 214  214   * driver instance of IP.
 215  215   */
 216  216  #define CONN_Q(q)       (WR(q)->q_next == NULL)
 217  217  
 218  218  #define Q_TO_CONN(q)    ((conn_t *)(q)->q_ptr)
 219  219  #define Q_TO_TCP(q)     (Q_TO_CONN((q))->conn_tcp)
 220  220  #define Q_TO_UDP(q)     (Q_TO_CONN((q))->conn_udp)
 221  221  #define Q_TO_ICMP(q)    (Q_TO_CONN((q))->conn_icmp)
 222  222  #define Q_TO_RTS(q)     (Q_TO_CONN((q))->conn_rts)
 223  223  
 224  224  #define CONNP_TO_WQ(connp)      ((connp)->conn_wq)
 225  225  #define CONNP_TO_RQ(connp)      ((connp)->conn_rq)
 226  226  
 227  227  #define GRAB_CONN_LOCK(q)       {                               \
 228  228          if (q != NULL && CONN_Q(q))                             \
 229  229                  mutex_enter(&(Q_TO_CONN(q))->conn_lock);        \
 230  230  }
 231  231  
 232  232  #define RELEASE_CONN_LOCK(q)    {                               \
 233  233          if (q != NULL && CONN_Q(q))                             \
 234  234                  mutex_exit(&(Q_TO_CONN(q))->conn_lock);         \
 235  235  }
 236  236  
 237  237  /*
 238  238   * Ref counter macros for ioctls. This provides a guard for TCP to stop
 239  239   * tcp_close from removing the rq/wq whilst an ioctl is still in flight on the
 240  240   * stream. The ioctl could have been queued on e.g. an ipsq. tcp_close will wait
 241  241   * until the ioctlref count is zero before proceeding.
 242  242   * Ideally conn_oper_pending_ill would be used for this purpose. However, in the
 243  243   * case where an ioctl is aborted or interrupted, it can be cleared prematurely.
 244  244   * There are also some race possibilities between ip and the stream head which
 245  245   * can also end up with conn_oper_pending_ill being cleared prematurely. So, to
 246  246   * avoid these situations, we use a dedicated ref counter for ioctls which is
 247  247   * used in addition to and in parallel with the normal conn_ref count.
 248  248   */
 249  249  #define CONN_INC_IOCTLREF_LOCKED(connp) {                       \
 250  250          ASSERT(MUTEX_HELD(&(connp)->conn_lock));                \
 251  251          DTRACE_PROBE1(conn__inc__ioctlref, conn_t *, (connp));  \
 252  252          (connp)->conn_ioctlref++;                               \
 253  253          mutex_exit(&(connp)->conn_lock);                        \
 254  254  }
 255  255  
 256  256  #define CONN_INC_IOCTLREF(connp)        {                       \
 257  257          mutex_enter(&(connp)->conn_lock);                       \
 258  258          CONN_INC_IOCTLREF_LOCKED(connp);                        \
 259  259  }
 260  260  
 261  261  #define CONN_DEC_IOCTLREF(connp)        {                       \
 262  262          mutex_enter(&(connp)->conn_lock);                       \
 263  263          DTRACE_PROBE1(conn__dec__ioctlref, conn_t *, (connp));  \
 264  264          /* Make sure conn_ioctlref will not underflow. */       \
 265  265          ASSERT((connp)->conn_ioctlref != 0);                    \
 266  266          if ((--(connp)->conn_ioctlref == 0) &&                  \
 267  267              ((connp)->conn_state_flags & CONN_CLOSING)) {       \
 268  268                  cv_broadcast(&(connp)->conn_cv);                \
 269  269          }                                                       \
 270  270          mutex_exit(&(connp)->conn_lock);                        \
 271  271  }
 272  272  
 273  273  
 274  274  /*
 275  275   * Complete the pending operation. Usually an ioctl. Can also
 276  276   * be a bind or option management request that got enqueued
 277  277   * in an ipsq_t. Called on completion of the operation.
 278  278   */
 279  279  #define CONN_OPER_PENDING_DONE(connp)   {                       \
 280  280          mutex_enter(&(connp)->conn_lock);                       \
 281  281          (connp)->conn_oper_pending_ill = NULL;                  \
 282  282          cv_broadcast(&(connp)->conn_refcv);                     \
 283  283          mutex_exit(&(connp)->conn_lock);                        \
 284  284          CONN_DEC_REF(connp);                                    \
 285  285  }
 286  286  
 287  287  /*
 288  288   * Values for squeue switch:
 289  289   */
 290  290  #define IP_SQUEUE_ENTER_NODRAIN 1
 291  291  #define IP_SQUEUE_ENTER 2
 292  292  #define IP_SQUEUE_FILL 3
 293  293  
 294  294  extern int ip_squeue_flag;
 295  295  
 296  296  /* IP Fragmentation Reassembly Header */
 297  297  typedef struct ipf_s {
 298  298          struct ipf_s    *ipf_hash_next;
 299  299          struct ipf_s    **ipf_ptphn;    /* Pointer to previous hash next. */
 300  300          uint32_t        ipf_ident;      /* Ident to match. */
 301  301          uint8_t         ipf_protocol;   /* Protocol to match. */
 302  302          uchar_t         ipf_last_frag_seen : 1; /* Last fragment seen ? */
 303  303          time_t          ipf_timestamp;  /* Reassembly start time. */
 304  304          mblk_t          *ipf_mp;        /* mblk we live in. */
 305  305          mblk_t          *ipf_tail_mp;   /* Frag queue tail pointer. */
 306  306          int             ipf_hole_cnt;   /* Number of holes (hard-case). */
 307  307          int             ipf_end;        /* Tail end offset (0 -> hard-case). */
 308  308          uint_t          ipf_gen;        /* Frag queue generation */
 309  309          size_t          ipf_count;      /* Count of bytes used by frag */
 310  310          uint_t          ipf_nf_hdr_len; /* Length of nonfragmented header */
 311  311          in6_addr_t      ipf_v6src;      /* IPv6 source address */
 312  312          in6_addr_t      ipf_v6dst;      /* IPv6 dest address */
 313  313          uint_t          ipf_prev_nexthdr_offset; /* Offset for nexthdr value */
 314  314          uint8_t         ipf_ecn;        /* ECN info for the fragments */
 315  315          uint8_t         ipf_num_dups;   /* Number of times dup frags recvd */
 316  316          uint16_t        ipf_checksum_flags; /* Hardware checksum flags */
 317  317          uint32_t        ipf_checksum;   /* Partial checksum of fragment data */
 318  318  } ipf_t;
 319  319  
 320  320  /*
 321  321   * IPv4 Fragments
 322  322   */
 323  323  #define IS_V4_FRAGMENT(ipha_fragment_offset_and_flags)                  \
 324  324          (((ntohs(ipha_fragment_offset_and_flags) & IPH_OFFSET) != 0) || \
 325  325          ((ntohs(ipha_fragment_offset_and_flags) & IPH_MF) != 0))
 326  326  
 327  327  #define ipf_src V4_PART_OF_V6(ipf_v6src)
 328  328  #define ipf_dst V4_PART_OF_V6(ipf_v6dst)
 329  329  
 330  330  #endif /* _KERNEL */
 331  331  
 332  332  /* ICMP types */
 333  333  #define ICMP_ECHO_REPLY                 0
 334  334  #define ICMP_DEST_UNREACHABLE           3
 335  335  #define ICMP_SOURCE_QUENCH              4
 336  336  #define ICMP_REDIRECT                   5
 337  337  #define ICMP_ECHO_REQUEST               8
 338  338  #define ICMP_ROUTER_ADVERTISEMENT       9
 339  339  #define ICMP_ROUTER_SOLICITATION        10
 340  340  #define ICMP_TIME_EXCEEDED              11
 341  341  #define ICMP_PARAM_PROBLEM              12
 342  342  #define ICMP_TIME_STAMP_REQUEST         13
 343  343  #define ICMP_TIME_STAMP_REPLY           14
 344  344  #define ICMP_INFO_REQUEST               15
 345  345  #define ICMP_INFO_REPLY                 16
 346  346  #define ICMP_ADDRESS_MASK_REQUEST       17
 347  347  #define ICMP_ADDRESS_MASK_REPLY         18
 348  348  
 349  349  /* Evaluates to true if the ICMP type is an ICMP error */
 350  350  #define ICMP_IS_ERROR(type)     (               \
 351  351          (type) == ICMP_DEST_UNREACHABLE ||      \
 352  352          (type) == ICMP_SOURCE_QUENCH ||         \
 353  353          (type) == ICMP_TIME_EXCEEDED ||         \
 354  354          (type) == ICMP_PARAM_PROBLEM)
 355  355  
 356  356  /* ICMP_TIME_EXCEEDED codes */
 357  357  #define ICMP_TTL_EXCEEDED               0
 358  358  #define ICMP_REASSEMBLY_TIME_EXCEEDED   1
 359  359  
 360  360  /* ICMP_DEST_UNREACHABLE codes */
 361  361  #define ICMP_NET_UNREACHABLE            0
 362  362  #define ICMP_HOST_UNREACHABLE           1
 363  363  #define ICMP_PROTOCOL_UNREACHABLE       2
 364  364  #define ICMP_PORT_UNREACHABLE           3
 365  365  #define ICMP_FRAGMENTATION_NEEDED       4
 366  366  #define ICMP_SOURCE_ROUTE_FAILED        5
 367  367  #define ICMP_DEST_NET_UNKNOWN           6
 368  368  #define ICMP_DEST_HOST_UNKNOWN          7
 369  369  #define ICMP_SRC_HOST_ISOLATED          8
 370  370  #define ICMP_DEST_NET_UNREACH_ADMIN     9
 371  371  #define ICMP_DEST_HOST_UNREACH_ADMIN    10
 372  372  #define ICMP_DEST_NET_UNREACH_TOS       11
 373  373  #define ICMP_DEST_HOST_UNREACH_TOS      12
 374  374  
 375  375  /* ICMP Header Structure */
 376  376  typedef struct icmph_s {
 377  377          uint8_t         icmph_type;
 378  378          uint8_t         icmph_code;
 379  379          uint16_t        icmph_checksum;
 380  380          union {
 381  381                  struct { /* ECHO request/response structure */
 382  382                          uint16_t        u_echo_ident;
 383  383                          uint16_t        u_echo_seqnum;
 384  384                  } u_echo;
 385  385                  struct { /* Destination unreachable structure */
 386  386                          uint16_t        u_du_zero;
 387  387                          uint16_t        u_du_mtu;
 388  388                  } u_du;
 389  389                  struct { /* Parameter problem structure */
 390  390                          uint8_t         u_pp_ptr;
 391  391                          uint8_t         u_pp_rsvd[3];
 392  392                  } u_pp;
 393  393                  struct { /* Redirect structure */
 394  394                          ipaddr_t        u_rd_gateway;
 395  395                  } u_rd;
 396  396          } icmph_u;
 397  397  } icmph_t;
 398  398  
 399  399  #define icmph_echo_ident        icmph_u.u_echo.u_echo_ident
 400  400  #define icmph_echo_seqnum       icmph_u.u_echo.u_echo_seqnum
 401  401  #define icmph_du_zero           icmph_u.u_du.u_du_zero
 402  402  #define icmph_du_mtu            icmph_u.u_du.u_du_mtu
 403  403  #define icmph_pp_ptr            icmph_u.u_pp.u_pp_ptr
 404  404  #define icmph_rd_gateway        icmph_u.u_rd.u_rd_gateway
 405  405  
 406  406  #define ICMPH_SIZE      8
 407  407  
 408  408  /*
 409  409   * Minimum length of transport layer header included in an ICMP error
 410  410   * message for it to be considered valid.
 411  411   */
 412  412  #define ICMP_MIN_TP_HDR_LEN     8
 413  413  
 414  414  /* Aligned IP header */
 415  415  typedef struct ipha_s {
 416  416          uint8_t         ipha_version_and_hdr_length;
 417  417          uint8_t         ipha_type_of_service;
 418  418          uint16_t        ipha_length;
 419  419          uint16_t        ipha_ident;
 420  420          uint16_t        ipha_fragment_offset_and_flags;
 421  421          uint8_t         ipha_ttl;
 422  422          uint8_t         ipha_protocol;
 423  423          uint16_t        ipha_hdr_checksum;
 424  424          ipaddr_t        ipha_src;
 425  425          ipaddr_t        ipha_dst;
 426  426  } ipha_t;
 427  427  
 428  428  /*
 429  429   * IP Flags
 430  430   *
 431  431   * Some of these constant names are copied for the DTrace IP provider in
 432  432   * usr/src/lib/libdtrace/common/{ip.d.in, ip.sed.in}, which should be kept
 433  433   * in sync.
 434  434   */
 435  435  #define IPH_DF          0x4000  /* Don't fragment */
 436  436  #define IPH_MF          0x2000  /* More fragments to come */
 437  437  #define IPH_OFFSET      0x1FFF  /* Where the offset lives */
 438  438  
 439  439  /* Byte-order specific values */
 440  440  #ifdef  _BIG_ENDIAN
 441  441  #define IPH_DF_HTONS    0x4000  /* Don't fragment */
 442  442  #define IPH_MF_HTONS    0x2000  /* More fragments to come */
 443  443  #define IPH_OFFSET_HTONS 0x1FFF /* Where the offset lives */
 444  444  #else
 445  445  #define IPH_DF_HTONS    0x0040  /* Don't fragment */
 446  446  #define IPH_MF_HTONS    0x0020  /* More fragments to come */
 447  447  #define IPH_OFFSET_HTONS 0xFF1F /* Where the offset lives */
 448  448  #endif
 449  449  
 450  450  /* ECN code points for IPv4 TOS byte and IPv6 traffic class octet. */
 451  451  #define IPH_ECN_NECT    0x0     /* Not ECN-Capable Transport */
 452  452  #define IPH_ECN_ECT1    0x1     /* ECN-Capable Transport, ECT(1) */
 453  453  #define IPH_ECN_ECT0    0x2     /* ECN-Capable Transport, ECT(0) */
 454  454  #define IPH_ECN_CE      0x3     /* ECN-Congestion Experienced (CE) */
 455  455  
 456  456  struct ill_s;
 457  457  
 458  458  typedef void ip_v6intfid_func_t(struct ill_s *, in6_addr_t *);
 459  459  typedef void ip_v6mapinfo_func_t(struct ill_s *, uchar_t *, uchar_t *);
 460  460  typedef void ip_v4mapinfo_func_t(struct ill_s *, uchar_t *, uchar_t *);
 461  461  
 462  462  /* IP Mac info structure */
 463  463  typedef struct ip_m_s {
 464  464          t_uscalar_t             ip_m_mac_type;  /* From <sys/dlpi.h> */
 465  465          int                     ip_m_type;      /* From <net/if_types.h> */
 466  466          t_uscalar_t             ip_m_ipv4sap;
 467  467          t_uscalar_t             ip_m_ipv6sap;
 468  468          ip_v4mapinfo_func_t     *ip_m_v4mapping;
 469  469          ip_v6mapinfo_func_t     *ip_m_v6mapping;
 470  470          ip_v6intfid_func_t      *ip_m_v6intfid;
 471  471          ip_v6intfid_func_t      *ip_m_v6destintfid;
 472  472  } ip_m_t;
 473  473  
 474  474  /*
 475  475   * The following functions attempt to reduce the link layer dependency
 476  476   * of the IP stack. The current set of link specific operations are:
 477  477   * a. map from IPv4 class D (224.0/4) multicast address range or the
 478  478   * IPv6 multicast address range (ff00::/8) to the link layer multicast
 479  479   * address.
 480  480   * b. derive the default IPv6 interface identifier from the interface.
 481  481   * c. derive the default IPv6 destination interface identifier from
 482  482   * the interface (point-to-point only).
 483  483   */
 484  484  extern  void ip_mcast_mapping(struct ill_s *, uchar_t *, uchar_t *);
 485  485  /* ip_m_v6*intfid return void and are never NULL */
 486  486  #define MEDIA_V6INTFID(ip_m, ill, v6ptr) (ip_m)->ip_m_v6intfid(ill, v6ptr)
 487  487  #define MEDIA_V6DESTINTFID(ip_m, ill, v6ptr) \
 488  488          (ip_m)->ip_m_v6destintfid(ill, v6ptr)
 489  489  
 490  490  /* Router entry types */
 491  491  #define IRE_BROADCAST           0x0001  /* Route entry for broadcast address */
 492  492  #define IRE_DEFAULT             0x0002  /* Route entry for default gateway */
 493  493  #define IRE_LOCAL               0x0004  /* Route entry for local address */
 494  494  #define IRE_LOOPBACK            0x0008  /* Route entry for loopback address */
 495  495  #define IRE_PREFIX              0x0010  /* Route entry for prefix routes */
 496  496  #ifndef _KERNEL
 497  497  /* Keep so user-level still compiles */
 498  498  #define IRE_CACHE               0x0020  /* Cached Route entry */
 499  499  #endif
 500  500  #define IRE_IF_NORESOLVER       0x0040  /* Route entry for local interface */
 501  501                                          /* net without any address mapping. */
 502  502  #define IRE_IF_RESOLVER         0x0080  /* Route entry for local interface */
 503  503                                          /* net with resolver. */
 504  504  #define IRE_HOST                0x0100  /* Host route entry */
 505  505  /* Keep so user-level still compiles */
 506  506  #define IRE_HOST_REDIRECT       0x0200  /* only used for T_SVR4_OPTMGMT_REQ */
 507  507  #define IRE_IF_CLONE            0x0400  /* Per host clone of IRE_IF */
 508  508  #define IRE_MULTICAST           0x0800  /* Special - not in table */
 509  509  #define IRE_NOROUTE             0x1000  /* Special - not in table */
 510  510  
 511  511  #define IRE_INTERFACE           (IRE_IF_NORESOLVER | IRE_IF_RESOLVER)
 512  512  
 513  513  #define IRE_IF_ALL              (IRE_IF_NORESOLVER | IRE_IF_RESOLVER | \
 514  514                                      IRE_IF_CLONE)
 515  515  #define IRE_OFFSUBNET           (IRE_DEFAULT | IRE_PREFIX | IRE_HOST)
 516  516  #define IRE_OFFLINK             IRE_OFFSUBNET
 517  517  /*
 518  518   * Note that we view IRE_NOROUTE as ONLINK since we can "send" to them without
 519  519   * going through a router; the result of sending will be an error/icmp error.
 520  520   */
 521  521  #define IRE_ONLINK              (IRE_IF_ALL|IRE_LOCAL|IRE_LOOPBACK| \
 522  522                                      IRE_BROADCAST|IRE_MULTICAST|IRE_NOROUTE)
 523  523  
 524  524  /* Arguments to ire_flush_cache() */
 525  525  #define IRE_FLUSH_DELETE        0
 526  526  #define IRE_FLUSH_ADD           1
 527  527  #define IRE_FLUSH_GWCHANGE      2
 528  528  
 529  529  /*
 530  530   * Flags to ire_route_recursive
 531  531   */
 532  532  #define IRR_NONE                0
 533  533  #define IRR_ALLOCATE            1       /* OK to allocate IRE_IF_CLONE */
 534  534  #define IRR_INCOMPLETE          2       /* OK to return incomplete chain */
 535  535  
 536  536  /*
 537  537   * Open/close synchronization flags.
 538  538   * These are kept in a separate field in the conn and the synchronization
 539  539   * depends on the atomic 32 bit access to that field.
 540  540   */
 541  541  #define CONN_CLOSING            0x01    /* ip_close waiting for ip_wsrv */
 542  542  #define CONN_CONDEMNED          0x02    /* conn is closing, no more refs */
 543  543  #define CONN_INCIPIENT          0x04    /* conn not yet visible, no refs */
 544  544  #define CONN_QUIESCED           0x08    /* conn is now quiescent */
 545  545  #define CONN_UPDATE_ILL         0x10    /* conn_update_ill in progress */
 546  546  
 547  547  /*
 548  548   * Flags for dce_flags field. Specifies which information has been set.
 549  549   * dce_ident is always present, but the other ones are identified by the flags.
 550  550   */
 551  551  #define DCEF_DEFAULT            0x0001  /* Default DCE - no pmtu or uinfo */
 552  552  #define DCEF_PMTU               0x0002  /* Different than interface MTU */
 553  553  #define DCEF_UINFO              0x0004  /* dce_uinfo set */
 554  554  #define DCEF_TOO_SMALL_PMTU     0x0008  /* Smaller than IPv4 MIN */
 555  555  
 556  556  #ifdef _KERNEL
 557  557  /*
 558  558   * Extra structures need for per-src-addr filtering (IGMPv3/MLDv2)
 559  559   */
 560  560  #define MAX_FILTER_SIZE 64
 561  561  
 562  562  typedef struct slist_s {
 563  563          int             sl_numsrc;
 564  564          in6_addr_t      sl_addr[MAX_FILTER_SIZE];
 565  565  } slist_t;
 566  566  
 567  567  /*
 568  568   * Following struct is used to maintain retransmission state for
 569  569   * a multicast group.  One rtx_state_t struct is an in-line field
 570  570   * of the ilm_t struct; the slist_ts in the rtx_state_t struct are
 571  571   * alloc'd as needed.
 572  572   */
 573  573  typedef struct rtx_state_s {
 574  574          uint_t          rtx_timer;      /* retrans timer */
 575  575          int             rtx_cnt;        /* retrans count */
 576  576          int             rtx_fmode_cnt;  /* retrans count for fmode change */
 577  577          slist_t         *rtx_allow;
 578  578          slist_t         *rtx_block;
 579  579  } rtx_state_t;
 580  580  
 581  581  /*
 582  582   * Used to construct list of multicast address records that will be
 583  583   * sent in a single listener report.
 584  584   */
 585  585  typedef struct mrec_s {
 586  586          struct mrec_s   *mrec_next;
 587  587          uint8_t         mrec_type;
 588  588          uint8_t         mrec_auxlen;    /* currently unused */
 589  589          in6_addr_t      mrec_group;
 590  590          slist_t         mrec_srcs;
 591  591  } mrec_t;
 592  592  
 593  593  /* Group membership list per upper conn */
 594  594  
 595  595  /*
 596  596   * We record the multicast information from the socket option in
 597  597   * ilg_ifaddr/ilg_ifindex. This allows rejoining the group in the case when
 598  598   * the ifaddr (or ifindex) disappears and later reappears, potentially on
 599  599   * a different ill. The IPv6 multicast socket options and ioctls all specify
 600  600   * the interface using an ifindex. For IPv4 some socket options/ioctls use
 601  601   * the interface address and others use the index. We record here the method
 602  602   * that was actually used (and leave the other of ilg_ifaddr or ilg_ifindex)
 603  603   * at zero so that we can rejoin the way the application intended.
 604  604   *
 605  605   * We track the ill on which we will or already have joined an ilm using
 606  606   * ilg_ill. When we have succeeded joining the ilm and have a refhold on it
 607  607   * then we set ilg_ilm. Thus intentionally there is a window where ilg_ill is
 608  608   * set and ilg_ilm is not set. This allows clearing ilg_ill as a signal that
 609  609   * the ill is being unplumbed and the ilm should be discarded.
 610  610   *
 611  611   * ilg records the state of multicast memberships of a socket end point.
 612  612   * ilm records the state of multicast memberships with the driver and is
 613  613   * maintained per interface.
 614  614   *
 615  615   * The ilg state is protected by conn_ilg_lock.
 616  616   * The ilg will not be freed until ilg_refcnt drops to zero.
 617  617   */
 618  618  typedef struct ilg_s {
 619  619          struct ilg_s    *ilg_next;
 620  620          struct ilg_s    **ilg_ptpn;
 621  621          struct conn_s   *ilg_connp;     /* Back pointer to get lock */
 622  622          in6_addr_t      ilg_v6group;
 623  623          ipaddr_t        ilg_ifaddr;     /* For some IPv4 cases */
 624  624          uint_t          ilg_ifindex;    /* IPv6 and some other IPv4 cases */
 625  625          struct ill_s    *ilg_ill;       /* Where ilm is joined. No refhold */
 626  626          struct ilm_s    *ilg_ilm;       /* With ilm_refhold */
 627  627          uint_t          ilg_refcnt;
 628  628          mcast_record_t  ilg_fmode;      /* MODE_IS_INCLUDE/MODE_IS_EXCLUDE */
 629  629          slist_t         *ilg_filter;
 630  630          boolean_t       ilg_condemned;  /* Conceptually deleted */
 631  631  } ilg_t;
 632  632  
 633  633  /*
 634  634   * Multicast address list entry for ill.
 635  635   * ilm_ill is used by IPv4 and IPv6
 636  636   *
 637  637   * The ilm state (and other multicast state on the ill) is protected by
 638  638   * ill_mcast_lock. Operations that change state on both an ilg and ilm
 639  639   * in addition use ill_mcast_serializer to ensure that we can't have
 640  640   * interleaving between e.g., add and delete operations for the same conn_t,
 641  641   * group, and ill. The ill_mcast_serializer is also used to ensure that
 642  642   * multicast group joins do not occur on an interface that is in the process
 643  643   * of joining an IPMP group.
 644  644   *
 645  645   * The comment below (and for other netstack_t references) refers
 646  646   * to the fact that we only do netstack_hold in particular cases,
 647  647   * such as the references from open endpoints (ill_t and conn_t's
 648  648   * pointers). Internally within IP we rely on IP's ability to cleanup e.g.
 649  649   * ire_t's when an ill goes away.
 650  650   */
 651  651  typedef struct ilm_s {
 652  652          in6_addr_t      ilm_v6addr;
 653  653          int             ilm_refcnt;
 654  654          uint_t          ilm_timer;      /* IGMP/MLD query resp timer, in msec */
 655  655          struct ilm_s    *ilm_next;      /* Linked list for each ill */
 656  656          uint_t          ilm_state;      /* state of the membership */
 657  657          struct ill_s    *ilm_ill;       /* Back pointer to ill - ill_ilm_cnt */
 658  658          zoneid_t        ilm_zoneid;
 659  659          int             ilm_no_ilg_cnt; /* number of joins w/ no ilg */
 660  660          mcast_record_t  ilm_fmode;      /* MODE_IS_INCLUDE/MODE_IS_EXCLUDE */
 661  661          slist_t         *ilm_filter;    /* source filter list */
 662  662          slist_t         *ilm_pendsrcs;  /* relevant src addrs for pending req */
 663  663          rtx_state_t     ilm_rtx;        /* SCR retransmission state */
 664  664          ipaddr_t        ilm_ifaddr;     /* For IPv4 netstat */
 665  665          ip_stack_t      *ilm_ipst;      /* Does not have a netstack_hold */
 666  666  } ilm_t;
 667  667  
 668  668  #define ilm_addr        V4_PART_OF_V6(ilm_v6addr)
 669  669  
 670  670  /*
 671  671   * Soft reference to an IPsec SA.
 672  672   *
 673  673   * On relative terms, conn's can be persistent (living as long as the
 674  674   * processes which create them), while SA's are ephemeral (dying when
 675  675   * they hit their time-based or byte-based lifetimes).
 676  676   *
 677  677   * We could hold a hard reference to an SA from an ipsec_latch_t,
 678  678   * but this would cause expired SA's to linger for a potentially
 679  679   * unbounded time.
 680  680   *
 681  681   * Instead, we remember the hash bucket number and bucket generation
 682  682   * in addition to the pointer.  The bucket generation is incremented on
 683  683   * each deletion.
 684  684   */
 685  685  typedef struct ipsa_ref_s
 686  686  {
 687  687          struct ipsa_s   *ipsr_sa;
 688  688          struct isaf_s   *ipsr_bucket;
 689  689          uint64_t        ipsr_gen;
 690  690  } ipsa_ref_t;
 691  691  
 692  692  /*
 693  693   * IPsec "latching" state.
 694  694   *
 695  695   * In the presence of IPsec policy, fully-bound conn's bind a connection
 696  696   * to more than just the 5-tuple, but also a specific IPsec action and
 697  697   * identity-pair.
 698  698   * The identity pair is accessed from both the receive and transmit side
 699  699   * hence it is maintained in the ipsec_latch_t structure. conn_latch and
 700  700   * ixa_ipsec_latch points to it.
 701  701   * The policy and actions are stored in conn_latch_in_policy and
 702  702   * conn_latch_in_action for the inbound side, and in ixa_ipsec_policy and
 703  703   * ixa_ipsec_action for the transmit side.
 704  704   *
 705  705   * As an optimization, we also cache soft references to IPsec SA's in
 706  706   * ip_xmit_attr_t so that we can fast-path around most of the work needed for
 707  707   * outbound IPsec SA selection.
 708  708   */
 709  709  typedef struct ipsec_latch_s
 710  710  {
 711  711          kmutex_t        ipl_lock;
 712  712          uint32_t        ipl_refcnt;
 713  713  
 714  714          struct ipsid_s  *ipl_local_cid;
 715  715          struct ipsid_s  *ipl_remote_cid;
 716  716          unsigned int
 717  717                          ipl_ids_latched : 1,
 718  718  
 719  719                          ipl_pad_to_bit_31 : 31;
 720  720  } ipsec_latch_t;
 721  721  
 722  722  #define IPLATCH_REFHOLD(ipl) { \
 723  723          atomic_inc_32(&(ipl)->ipl_refcnt);              \
 724  724          ASSERT((ipl)->ipl_refcnt != 0);                 \
 725  725  }
 726  726  
 727  727  #define IPLATCH_REFRELE(ipl) {                          \
 728  728          ASSERT((ipl)->ipl_refcnt != 0);                         \
 729  729          membar_exit();                                          \
 730  730          if (atomic_dec_32_nv(&(ipl)->ipl_refcnt) == 0)  \
 731  731                  iplatch_free(ipl);                              \
 732  732  }
 733  733  
 734  734  /*
 735  735   * peer identity structure.
 736  736   */
 737  737  typedef struct conn_s conn_t;
 738  738  
 739  739  /*
 740  740   * This is used to match an inbound/outbound datagram with policy.
 741  741   */
 742  742  typedef struct ipsec_selector {
 743  743          in6_addr_t      ips_local_addr_v6;
 744  744          in6_addr_t      ips_remote_addr_v6;
 745  745          uint16_t        ips_local_port;
 746  746          uint16_t        ips_remote_port;
 747  747          uint8_t         ips_icmp_type;
 748  748          uint8_t         ips_icmp_code;
 749  749          uint8_t         ips_protocol;
 750  750          uint8_t         ips_isv4 : 1,
 751  751                          ips_is_icmp_inv_acq: 1;
 752  752  } ipsec_selector_t;
 753  753  
 754  754  /*
 755  755   * Note that we put v4 addresses in the *first* 32-bit word of the
 756  756   * selector rather than the last to simplify the prefix match/mask code
 757  757   * in spd.c
 758  758   */
 759  759  #define ips_local_addr_v4 ips_local_addr_v6.s6_addr32[0]
 760  760  #define ips_remote_addr_v4 ips_remote_addr_v6.s6_addr32[0]
 761  761  
 762  762  /* Values used in IP by IPSEC Code */
 763  763  #define         IPSEC_OUTBOUND          B_TRUE
 764  764  #define         IPSEC_INBOUND           B_FALSE
 765  765  
 766  766  /*
 767  767   * There are two variants in policy failures. The packet may come in
 768  768   * secure when not needed (IPSEC_POLICY_???_NOT_NEEDED) or it may not
 769  769   * have the desired level of protection (IPSEC_POLICY_MISMATCH).
 770  770   */
 771  771  #define IPSEC_POLICY_NOT_NEEDED         0
 772  772  #define IPSEC_POLICY_MISMATCH           1
 773  773  #define IPSEC_POLICY_AUTH_NOT_NEEDED    2
 774  774  #define IPSEC_POLICY_ENCR_NOT_NEEDED    3
 775  775  #define IPSEC_POLICY_SE_NOT_NEEDED      4
 776  776  #define IPSEC_POLICY_MAX                5       /* Always max + 1. */
 777  777  
 778  778  /*
 779  779   * Check with IPSEC inbound policy if
 780  780   *
 781  781   * 1) per-socket policy is present - indicated by conn_in_enforce_policy.
 782  782   * 2) Or if we have not cached policy on the conn and the global policy is
 783  783   *    non-empty.
 784  784   */
 785  785  #define CONN_INBOUND_POLICY_PRESENT(connp, ipss)        \
 786  786          ((connp)->conn_in_enforce_policy ||             \
 787  787          (!((connp)->conn_policy_cached) &&              \
 788  788          (ipss)->ipsec_inbound_v4_policy_present))
 789  789  
 790  790  #define CONN_INBOUND_POLICY_PRESENT_V6(connp, ipss)     \
 791  791          ((connp)->conn_in_enforce_policy ||             \
 792  792          (!(connp)->conn_policy_cached &&                \
 793  793          (ipss)->ipsec_inbound_v6_policy_present))
 794  794  
 795  795  #define CONN_OUTBOUND_POLICY_PRESENT(connp, ipss)       \
 796  796          ((connp)->conn_out_enforce_policy ||            \
 797  797          (!((connp)->conn_policy_cached) &&              \
 798  798          (ipss)->ipsec_outbound_v4_policy_present))
 799  799  
 800  800  #define CONN_OUTBOUND_POLICY_PRESENT_V6(connp, ipss)    \
 801  801          ((connp)->conn_out_enforce_policy ||            \
 802  802          (!(connp)->conn_policy_cached &&                \
 803  803          (ipss)->ipsec_outbound_v6_policy_present))
 804  804  
 805  805  /*
 806  806   * Information cached in IRE for upper layer protocol (ULP).
 807  807   */
 808  808  typedef struct iulp_s {
 809  809          boolean_t       iulp_set;       /* Is any metric set? */
 810  810          uint32_t        iulp_ssthresh;  /* Slow start threshold (TCP). */
 811  811          clock_t         iulp_rtt;       /* Guestimate in millisecs. */
 812  812          clock_t         iulp_rtt_sd;    /* Cached value of RTT variance. */
 813  813          uint32_t        iulp_spipe;     /* Send pipe size. */
 814  814          uint32_t        iulp_rpipe;     /* Receive pipe size. */
 815  815          uint32_t        iulp_rtomax;    /* Max round trip timeout. */
 816  816          uint32_t        iulp_sack;      /* Use SACK option (TCP)? */
 817  817          uint32_t        iulp_mtu;       /* Setable with routing sockets */
 818  818  
 819  819          uint32_t
 820  820                  iulp_tstamp_ok : 1,     /* Use timestamp option (TCP)? */
 821  821                  iulp_wscale_ok : 1,     /* Use window scale option (TCP)? */
 822  822                  iulp_ecn_ok : 1,        /* Enable ECN (for TCP)? */
 823  823                  iulp_pmtud_ok : 1,      /* Enable PMTUd? */
 824  824  
 825  825                  /* These three are passed out by ip_set_destination */
 826  826                  iulp_localnet: 1,       /* IRE_ONLINK */
 827  827                  iulp_loopback: 1,       /* IRE_LOOPBACK */
 828  828                  iulp_local: 1,          /* IRE_LOCAL */
 829  829  
 830  830                  iulp_not_used : 25;
 831  831  } iulp_t;
 832  832  
 833  833  /*
 834  834   * The conn drain list structure (idl_t), protected by idl_lock.  Each conn_t
 835  835   * inserted in the list points back at this idl_t using conn_idl, and is
 836  836   * chained by conn_drain_next and conn_drain_prev, which are also protected by
 837  837   * idl_lock.  When flow control is relieved, either ip_wsrv() (STREAMS) or
 838  838   * ill_flow_enable() (non-STREAMS) will call conn_drain().
 839  839   *
 840  840   * The conn drain list, idl_t, itself is part of tx cookie list structure.
 841  841   * A tx cookie list points to a blocked Tx ring and contains the list of
 842  842   * all conn's that are blocked due to the flow-controlled Tx ring (via
 843  843   * the idl drain list). Note that a link can have multiple Tx rings. The
 844  844   * drain list will store the conn's blocked due to Tx ring being flow
 845  845   * controlled.
 846  846   */
 847  847  
 848  848  typedef uintptr_t ip_mac_tx_cookie_t;
 849  849  typedef struct idl_s idl_t;
 850  850  typedef struct idl_tx_list_s idl_tx_list_t;
 851  851  
 852  852  struct idl_tx_list_s {
 853  853          ip_mac_tx_cookie_t      txl_cookie;
 854  854          kmutex_t                txl_lock;       /* Lock for this list */
 855  855          idl_t                   *txl_drain_list;
 856  856          int                     txl_drain_index;
 857  857  };
 858  858  
 859  859  struct idl_s {
 860  860          conn_t          *idl_conn;              /* Head of drain list */
 861  861          kmutex_t        idl_lock;               /* Lock for this list */
 862  862          idl_tx_list_t   *idl_itl;
 863  863  };
 864  864  
 865  865  /*
 866  866   * Interface route structure which holds the necessary information to recreate
 867  867   * routes that are tied to an interface i.e. have ire_ill set.
 868  868   *
 869  869   * These routes which were initially created via a routing socket or via the
 870  870   * SIOCADDRT ioctl may be gateway routes (RTF_GATEWAY being set) or may be
 871  871   * traditional interface routes.  When an ill comes back up after being
 872  872   * down, this information will be used to recreate the routes.  These
 873  873   * are part of an mblk_t chain that hangs off of the ILL (ill_saved_ire_mp).
 874  874   */
 875  875  typedef struct ifrt_s {
 876  876          ushort_t        ifrt_type;              /* Type of IRE */
 877  877          in6_addr_t      ifrt_v6addr;            /* Address IRE represents. */
 878  878          in6_addr_t      ifrt_v6gateway_addr;    /* Gateway if IRE_OFFLINK */
 879  879          in6_addr_t      ifrt_v6setsrc_addr;     /* Src addr if RTF_SETSRC */
 880  880          in6_addr_t      ifrt_v6mask;            /* Mask for matching IRE. */
 881  881          uint32_t        ifrt_flags;             /* flags related to route */
 882  882          iulp_t          ifrt_metrics;           /* Routing socket metrics */
 883  883          zoneid_t        ifrt_zoneid;            /* zoneid for route */
 884  884  } ifrt_t;
 885  885  
 886  886  #define ifrt_addr               V4_PART_OF_V6(ifrt_v6addr)
 887  887  #define ifrt_gateway_addr       V4_PART_OF_V6(ifrt_v6gateway_addr)
 888  888  #define ifrt_mask               V4_PART_OF_V6(ifrt_v6mask)
 889  889  #define ifrt_setsrc_addr        V4_PART_OF_V6(ifrt_v6setsrc_addr)
 890  890  
 891  891  /* Number of IP addresses that can be hosted on a physical interface */
 892  892  #define MAX_ADDRS_PER_IF        8192
 893  893  /*
 894  894   * Number of Source addresses to be considered for source address
 895  895   * selection. Used by ipif_select_source_v4/v6.
 896  896   */
 897  897  #define MAX_IPIF_SELECT_SOURCE  50
 898  898  
 899  899  #ifdef IP_DEBUG
 900  900  /*
 901  901   * Trace refholds and refreles for debugging.
 902  902   */
 903  903  #define TR_STACK_DEPTH  14
 904  904  typedef struct tr_buf_s {
 905  905          int     tr_depth;
 906  906          clock_t tr_time;
 907  907          pc_t    tr_stack[TR_STACK_DEPTH];
 908  908  } tr_buf_t;
 909  909  
 910  910  typedef struct th_trace_s {
 911  911          int             th_refcnt;
 912  912          uint_t          th_trace_lastref;
 913  913          kthread_t       *th_id;
 914  914  #define TR_BUF_MAX      38
 915  915          tr_buf_t        th_trbuf[TR_BUF_MAX];
 916  916  } th_trace_t;
 917  917  
 918  918  typedef struct th_hash_s {
 919  919          list_node_t     thh_link;
 920  920          mod_hash_t      *thh_hash;
 921  921          ip_stack_t      *thh_ipst;
 922  922  } th_hash_t;
 923  923  #endif
 924  924  
 925  925  /* The following are ipif_state_flags */
 926  926  #define IPIF_CONDEMNED          0x1     /* The ipif is being removed */
 927  927  #define IPIF_CHANGING           0x2     /* A critcal ipif field is changing */
 928  928  #define IPIF_SET_LINKLOCAL      0x10    /* transient flag during bringup */
 929  929  
 930  930  /* IP interface structure, one per local address */
 931  931  typedef struct ipif_s {
 932  932          struct  ipif_s  *ipif_next;
 933  933          struct  ill_s   *ipif_ill;      /* Back pointer to our ill */
 934  934          int     ipif_id;                /* Logical unit number */
 935  935          in6_addr_t ipif_v6lcl_addr;     /* Local IP address for this if. */
 936  936          in6_addr_t ipif_v6subnet;       /* Subnet prefix for this if. */
 937  937          in6_addr_t ipif_v6net_mask;     /* Net mask for this interface. */
 938  938          in6_addr_t ipif_v6brd_addr;     /* Broadcast addr for this interface. */
 939  939          in6_addr_t ipif_v6pp_dst_addr;  /* Point-to-point dest address. */
 940  940          uint64_t ipif_flags;            /* Interface flags. */
 941  941          uint_t  ipif_ire_type;          /* IRE_LOCAL or IRE_LOOPBACK */
 942  942  
 943  943          /*
 944  944           * The packet count in the ipif contain the sum of the
 945  945           * packet counts in dead IRE_LOCAL/LOOPBACK for this ipif.
 946  946           */
 947  947          uint_t  ipif_ib_pkt_count;      /* Inbound packets for our dead IREs */
 948  948  
 949  949          /* Exclusive bit fields, protected by ipsq_t */
 950  950          unsigned int
 951  951                  ipif_was_up : 1,        /* ipif was up before */
 952  952                  ipif_addr_ready : 1,    /* DAD is done */
 953  953                  ipif_was_dup : 1,       /* DAD had failed */
 954  954                  ipif_added_nce : 1,     /* nce added for local address */
 955  955  
 956  956                  ipif_pad_to_31 : 28;
 957  957  
 958  958          ilm_t   *ipif_allhosts_ilm;     /* For all-nodes join */
 959  959          ilm_t   *ipif_solmulti_ilm;     /* For IPv6 solicited multicast join */
 960  960  
 961  961          uint_t  ipif_seqid;             /* unique index across all ills */
 962  962          uint_t  ipif_state_flags;       /* See IPIF_* flag defs above */
 963  963          uint_t  ipif_refcnt;            /* active consistent reader cnt */
 964  964  
 965  965          zoneid_t ipif_zoneid;           /* zone ID number */
 966  966          timeout_id_t ipif_recovery_id;  /* Timer for DAD recovery */
 967  967          boolean_t ipif_trace_disable;   /* True when alloc fails */
 968  968          /*
 969  969           * For an IPMP interface, ipif_bound_ill tracks the ill whose hardware
 970  970           * information this ipif is associated with via ARP/NDP.  We can use
 971  971           * an ill pointer (rather than an index) because only ills that are
 972  972           * part of a group will be pointed to, and an ill cannot disappear
 973  973           * while it's in a group.
 974  974           */
 975  975          struct ill_s    *ipif_bound_ill;
 976  976          struct ipif_s   *ipif_bound_next; /* bound ipif chain */
 977  977          boolean_t       ipif_bound;     /* B_TRUE if we successfully bound */
 978  978  
 979  979          struct ire_s    *ipif_ire_local; /* Our IRE_LOCAL or LOOPBACK */
 980  980          struct ire_s    *ipif_ire_if;    /* Our IRE_INTERFACE */
 981  981  } ipif_t;
 982  982  
 983  983  /*
 984  984   * The following table lists the protection levels of the various members
 985  985   * of the ipif_t. The following notation is used.
 986  986   *
 987  987   * Write once - Written to only once at the time of bringing up
 988  988   * the interface and can be safely read after the bringup without any lock.
 989  989   *
 990  990   * ipsq - Need to execute in the ipsq to perform the indicated access.
 991  991   *
 992  992   * ill_lock - Need to hold this mutex to perform the indicated access.
 993  993   *
 994  994   * ill_g_lock - Need to hold this rw lock as reader/writer for read access or
 995  995   * write access respectively.
 996  996   *
 997  997   * down ill - Written to only when the ill is down (i.e all ipifs are down)
 998  998   * up ill - Read only when the ill is up (i.e. at least 1 ipif is up)
 999  999   *
1000 1000   *               Table of ipif_t members and their protection
1001 1001   *
1002 1002   * ipif_next            ipsq + ill_lock +       ipsq OR ill_lock OR
1003 1003   *                      ill_g_lock              ill_g_lock
1004 1004   * ipif_ill             ipsq + down ipif        write once
1005 1005   * ipif_id              ipsq + down ipif        write once
1006 1006   * ipif_v6lcl_addr      ipsq + down ipif        up ipif
1007 1007   * ipif_v6subnet        ipsq + down ipif        up ipif
1008 1008   * ipif_v6net_mask      ipsq + down ipif        up ipif
1009 1009   *
1010 1010   * ipif_v6brd_addr
1011 1011   * ipif_v6pp_dst_addr
1012 1012   * ipif_flags           ill_lock                ill_lock
1013 1013   * ipif_ire_type        ipsq + down ill         up ill
1014 1014   *
1015 1015   * ipif_ib_pkt_count    Approx
1016 1016   *
1017 1017   * bit fields           ill_lock                ill_lock
1018 1018   *
1019 1019   * ipif_allhosts_ilm    ipsq                    ipsq
1020 1020   * ipif_solmulti_ilm    ipsq                    ipsq
1021 1021   *
1022 1022   * ipif_seqid           ipsq                    Write once
1023 1023   *
1024 1024   * ipif_state_flags     ill_lock                ill_lock
1025 1025   * ipif_refcnt          ill_lock                ill_lock
1026 1026   * ipif_bound_ill       ipsq + ipmp_lock        ipsq OR ipmp_lock
1027 1027   * ipif_bound_next      ipsq                    ipsq
1028 1028   * ipif_bound           ipsq                    ipsq
1029 1029   *
1030 1030   * ipif_ire_local       ipsq + ips_ill_g_lock   ipsq OR ips_ill_g_lock
1031 1031   * ipif_ire_if          ipsq + ips_ill_g_lock   ipsq OR ips_ill_g_lock
1032 1032   */
1033 1033  
1034 1034  /*
1035 1035   * Return values from ip_laddr_verify_{v4,v6}
1036 1036   */
1037 1037  typedef enum { IPVL_UNICAST_UP, IPVL_UNICAST_DOWN, IPVL_MCAST, IPVL_BCAST,
1038 1038              IPVL_BAD} ip_laddr_t;
1039 1039  
1040 1040  
1041 1041  #define IP_TR_HASH(tid) ((((uintptr_t)tid) >> 6) & (IP_TR_HASH_MAX - 1))
1042 1042  
1043 1043  #ifdef DEBUG
1044 1044  #define IPIF_TRACE_REF(ipif)    ipif_trace_ref(ipif)
1045 1045  #define ILL_TRACE_REF(ill)      ill_trace_ref(ill)
1046 1046  #define IPIF_UNTRACE_REF(ipif)  ipif_untrace_ref(ipif)
1047 1047  #define ILL_UNTRACE_REF(ill)    ill_untrace_ref(ill)
1048 1048  #else
1049 1049  #define IPIF_TRACE_REF(ipif)
1050 1050  #define ILL_TRACE_REF(ill)
1051 1051  #define IPIF_UNTRACE_REF(ipif)
1052 1052  #define ILL_UNTRACE_REF(ill)
1053 1053  #endif
1054 1054  
1055 1055  /* IPv4 compatibility macros */
1056 1056  #define ipif_lcl_addr           V4_PART_OF_V6(ipif_v6lcl_addr)
1057 1057  #define ipif_subnet             V4_PART_OF_V6(ipif_v6subnet)
1058 1058  #define ipif_net_mask           V4_PART_OF_V6(ipif_v6net_mask)
1059 1059  #define ipif_brd_addr           V4_PART_OF_V6(ipif_v6brd_addr)
1060 1060  #define ipif_pp_dst_addr        V4_PART_OF_V6(ipif_v6pp_dst_addr)
1061 1061  
1062 1062  /* Macros for easy backreferences to the ill. */
1063 1063  #define ipif_isv6               ipif_ill->ill_isv6
1064 1064  
1065 1065  #define SIOCLIFADDR_NDX 112     /* ndx of SIOCLIFADDR in the ndx ioctl table */
1066 1066  
1067 1067  /*
1068 1068   * mode value for ip_ioctl_finish for finishing an ioctl
1069 1069   */
1070 1070  #define CONN_CLOSE      1               /* No mi_copy */
1071 1071  #define COPYOUT         2               /* do an mi_copyout if needed */
1072 1072  #define NO_COPYOUT      3               /* do an mi_copy_done */
1073 1073  #define IPI2MODE(ipi)   ((ipi)->ipi_flags & IPI_GET_CMD ? COPYOUT : NO_COPYOUT)
1074 1074  
1075 1075  /*
1076 1076   * The IP-MT design revolves around the serialization objects ipsq_t (IPSQ)
1077 1077   * and ipxop_t (exclusive operation or "xop").  Becoming "writer" on an IPSQ
1078 1078   * ensures that no other threads can become "writer" on any IPSQs sharing that
1079 1079   * IPSQ's xop until the writer thread is done.
1080 1080   *
1081 1081   * Each phyint points to one IPSQ that remains fixed over the phyint's life.
1082 1082   * Each IPSQ points to one xop that can change over the IPSQ's life.  If a
1083 1083   * phyint is *not* in an IPMP group, then its IPSQ will refer to the IPSQ's
1084 1084   * "own" xop (ipsq_ownxop).  If a phyint *is* part of an IPMP group, then its
1085 1085   * IPSQ will refer to the "group" xop, which is shorthand for the xop of the
1086 1086   * IPSQ of the IPMP meta-interface's phyint.  Thus, all phyints that are part
1087 1087   * of the same IPMP group will have their IPSQ's point to the group xop, and
1088 1088   * thus becoming "writer" on any phyint in the group will prevent any other
1089 1089   * writer on any other phyint in the group.  All IPSQs sharing the same xop
1090 1090   * are chained together through ipsq_next (in the degenerate common case,
1091 1091   * ipsq_next simply refers to itself).  Note that the group xop is guaranteed
1092 1092   * to exist at least as long as there are members in the group, since the IPMP
1093 1093   * meta-interface can only be destroyed if the group is empty.
1094 1094   *
1095 1095   * Incoming exclusive operation requests are enqueued on the IPSQ they arrived
1096 1096   * on rather than the xop.  This makes switching xop's (as would happen when a
1097 1097   * phyint leaves an IPMP group) simple, because after the phyint leaves the
1098 1098   * group, any operations enqueued on its IPSQ can be safely processed with
1099 1099   * respect to its new xop, and any operations enqueued on the IPSQs of its
1100 1100   * former group can be processed with respect to their existing group xop.
1101 1101   * Even so, switching xops is a subtle dance; see ipsq_dq() for details.
1102 1102   *
1103 1103   * An IPSQ's "own" xop is embedded within the IPSQ itself since they have have
1104 1104   * identical lifetimes, and because doing so simplifies pointer management.
1105 1105   * While each phyint and IPSQ point to each other, it is not possible to free
1106 1106   * the IPSQ when the phyint is freed, since we may still *inside* the IPSQ
1107 1107   * when the phyint is being freed.  Thus, ipsq_phyint is set to NULL when the
1108 1108   * phyint is freed, and the IPSQ free is later done in ipsq_exit().
1109 1109   *
1110 1110   * ipsq_t synchronization:      read                    write
1111 1111   *
1112 1112   *      ipsq_xopq_mphead        ipx_lock                ipx_lock
1113 1113   *      ipsq_xopq_mptail        ipx_lock                ipx_lock
1114 1114   *      ipsq_xop_switch_mp      ipsq_lock               ipsq_lock
1115 1115   *      ipsq_phyint             write once              write once
1116 1116   *      ipsq_next               RW_READER ill_g_lock    RW_WRITER ill_g_lock
1117 1117   *      ipsq_xop                ipsq_lock or ipsq       ipsq_lock + ipsq
1118 1118   *      ipsq_swxop              ipsq                    ipsq
1119 1119   *      ipsq_ownxop             see ipxop_t             see ipxop_t
1120 1120   *      ipsq_ipst               write once              write once
1121 1121   *
1122 1122   * ipxop_t synchronization:     read                    write
1123 1123   *
1124 1124   *      ipx_writer              ipx_lock                ipx_lock
1125 1125   *      ipx_xop_queued          ipx_lock                ipx_lock
1126 1126   *      ipx_mphead              ipx_lock                ipx_lock
1127 1127   *      ipx_mptail              ipx_lock                ipx_lock
1128 1128   *      ipx_ipsq                write once              write once
1129 1129   *      ips_ipsq_queued         ipx_lock                ipx_lock
1130 1130   *      ipx_waitfor             ipsq or ipx_lock        ipsq + ipx_lock
1131 1131   *      ipx_reentry_cnt         ipsq or ipx_lock        ipsq + ipx_lock
1132 1132   *      ipx_current_done        ipsq                    ipsq
1133 1133   *      ipx_current_ioctl       ipsq                    ipsq
1134 1134   *      ipx_current_ipif        ipsq or ipx_lock        ipsq + ipx_lock
1135 1135   *      ipx_pending_ipif        ipsq or ipx_lock        ipsq + ipx_lock
1136 1136   *      ipx_pending_mp          ipsq or ipx_lock        ipsq + ipx_lock
1137 1137   *      ipx_forced              ipsq                    ipsq
1138 1138   *      ipx_depth               ipsq                    ipsq
1139 1139   *      ipx_stack               ipsq                    ipsq
1140 1140   */
1141 1141  typedef struct ipxop_s {
1142 1142          kmutex_t        ipx_lock;       /* see above */
1143 1143          kthread_t       *ipx_writer;    /* current owner */
1144 1144          mblk_t          *ipx_mphead;    /* messages tied to this op */
1145 1145          mblk_t          *ipx_mptail;
1146 1146          struct ipsq_s   *ipx_ipsq;      /* associated ipsq */
1147 1147          boolean_t       ipx_ipsq_queued; /* ipsq using xop has queued op */
1148 1148          int             ipx_waitfor;    /* waiting; values encoded below */
1149 1149          int             ipx_reentry_cnt;
1150 1150          boolean_t       ipx_current_done;  /* is the current operation done? */
1151 1151          int             ipx_current_ioctl; /* current ioctl, or 0 if no ioctl */
1152 1152          ipif_t          *ipx_current_ipif; /* ipif for current op */
1153 1153          ipif_t          *ipx_pending_ipif; /* ipif for ipx_pending_mp */
1154 1154          mblk_t          *ipx_pending_mp; /* current ioctl mp while waiting */
1155 1155          boolean_t       ipx_forced;                     /* debugging aid */
1156 1156  #ifdef DEBUG
1157 1157          int             ipx_depth;                      /* debugging aid */
1158 1158  #define IPX_STACK_DEPTH 15
1159 1159          pc_t            ipx_stack[IPX_STACK_DEPTH];     /* debugging aid */
1160 1160  #endif
1161 1161  } ipxop_t;
1162 1162  
1163 1163  typedef struct ipsq_s {
1164 1164          kmutex_t ipsq_lock;             /* see above */
1165 1165          mblk_t  *ipsq_switch_mp;        /* op to handle right after switch */
1166 1166          mblk_t  *ipsq_xopq_mphead;      /* list of excl ops (mostly ioctls) */
1167 1167          mblk_t  *ipsq_xopq_mptail;
1168 1168          struct phyint   *ipsq_phyint;   /* associated phyint */
1169 1169          struct ipsq_s   *ipsq_next;     /* next ipsq sharing ipsq_xop */
1170 1170          struct ipxop_s  *ipsq_xop;      /* current xop synchronization info */
1171 1171          struct ipxop_s  *ipsq_swxop;    /* switch xop to on ipsq_exit() */
1172 1172          struct ipxop_s  ipsq_ownxop;    /* our own xop (may not be in-use) */
1173 1173          ip_stack_t      *ipsq_ipst;     /* does not have a netstack_hold */
1174 1174  } ipsq_t;
1175 1175  
1176 1176  /*
1177 1177   * ipx_waitfor values:
1178 1178   */
1179 1179  enum {
1180 1180          IPIF_DOWN = 1,  /* ipif_down() waiting for refcnts to drop */
1181 1181          ILL_DOWN,       /* ill_down() waiting for refcnts to drop */
1182 1182          IPIF_FREE,      /* ipif_free() waiting for refcnts to drop */
1183 1183          ILL_FREE        /* ill unplumb waiting for refcnts to drop */
1184 1184  };
1185 1185  
1186 1186  /* Operation types for ipsq_try_enter() */
1187 1187  #define CUR_OP 0        /* request writer within current operation */
1188 1188  #define NEW_OP 1        /* request writer for a new operation */
1189 1189  #define SWITCH_OP 2     /* request writer once IPSQ XOP switches */
1190 1190  
1191 1191  /*
1192 1192   * Kstats tracked on each IPMP meta-interface.  Order here must match
1193 1193   * ipmp_kstats[] in ip/ipmp.c.
1194 1194   */
1195 1195  enum {
1196 1196          IPMP_KSTAT_OBYTES,      IPMP_KSTAT_OBYTES64,    IPMP_KSTAT_RBYTES,
1197 1197          IPMP_KSTAT_RBYTES64,    IPMP_KSTAT_OPACKETS,    IPMP_KSTAT_OPACKETS64,
1198 1198          IPMP_KSTAT_OERRORS,     IPMP_KSTAT_IPACKETS,    IPMP_KSTAT_IPACKETS64,
1199 1199          IPMP_KSTAT_IERRORS,     IPMP_KSTAT_MULTIRCV,    IPMP_KSTAT_MULTIXMT,
1200 1200          IPMP_KSTAT_BRDCSTRCV,   IPMP_KSTAT_BRDCSTXMT,   IPMP_KSTAT_LINK_UP,
1201 1201          IPMP_KSTAT_MAX          /* keep last */
1202 1202  };
1203 1203  
1204 1204  /*
1205 1205   * phyint represents state that is common to both IPv4 and IPv6 interfaces.
1206 1206   * There is a separate ill_t representing IPv4 and IPv6 which has a
1207 1207   * backpointer to the phyint structure for accessing common state.
1208 1208   */
1209 1209  typedef struct phyint {
1210 1210          struct ill_s    *phyint_illv4;
1211 1211          struct ill_s    *phyint_illv6;
1212 1212          uint_t          phyint_ifindex;         /* SIOCSLIFINDEX */
1213 1213          uint64_t        phyint_flags;
1214 1214          avl_node_t      phyint_avl_by_index;    /* avl tree by index */
1215 1215          avl_node_t      phyint_avl_by_name;     /* avl tree by name */
1216 1216          kmutex_t        phyint_lock;
1217 1217          struct ipsq_s   *phyint_ipsq;           /* back pointer to ipsq */
1218 1218          struct ipmp_grp_s *phyint_grp;          /* associated IPMP group */
1219 1219          char            phyint_name[LIFNAMSIZ]; /* physical interface name */
1220 1220          uint64_t        phyint_kstats0[IPMP_KSTAT_MAX]; /* baseline kstats */
1221 1221  } phyint_t;
1222 1222  
1223 1223  #define CACHE_ALIGN_SIZE 64
1224 1224  #define CACHE_ALIGN(align_struct)       P2ROUNDUP(sizeof (struct align_struct),\
1225 1225                                                          CACHE_ALIGN_SIZE)
1226 1226  struct _phyint_list_s_ {
1227 1227          avl_tree_t      phyint_list_avl_by_index;       /* avl tree by index */
1228 1228          avl_tree_t      phyint_list_avl_by_name;        /* avl tree by name */
1229 1229  };
1230 1230  
1231 1231  typedef union phyint_list_u {
1232 1232          struct  _phyint_list_s_ phyint_list_s;
1233 1233          char    phyint_list_filler[CACHE_ALIGN(_phyint_list_s_)];
1234 1234  } phyint_list_t;
1235 1235  
1236 1236  #define phyint_list_avl_by_index        phyint_list_s.phyint_list_avl_by_index
1237 1237  #define phyint_list_avl_by_name         phyint_list_s.phyint_list_avl_by_name
1238 1238  
1239 1239  /*
1240 1240   * Fragmentation hash bucket
1241 1241   */
1242 1242  typedef struct ipfb_s {
1243 1243          struct ipf_s    *ipfb_ipf;      /* List of ... */
1244 1244          size_t          ipfb_count;     /* Count of bytes used by frag(s) */
1245 1245          kmutex_t        ipfb_lock;      /* Protect all ipf in list */
1246 1246          uint_t          ipfb_frag_pkts; /* num of distinct fragmented pkts */
1247 1247  } ipfb_t;
1248 1248  
1249 1249  /*
1250 1250   * IRE bucket structure. Usually there is an array of such structures,
1251 1251   * each pointing to a linked list of ires. irb_refcnt counts the number
1252 1252   * of walkers of a given hash bucket. Usually the reference count is
1253 1253   * bumped up if the walker wants no IRES to be DELETED while walking the
1254 1254   * list. Bumping up does not PREVENT ADDITION. This allows walking a given
1255 1255   * hash bucket without stumbling up on a free pointer.
1256 1256   *
1257 1257   * irb_t structures in ip_ftable are dynamically allocated and freed.
1258 1258   * In order to identify the irb_t structures that can be safely kmem_free'd
1259 1259   * we need to ensure that
1260 1260   *  - the irb_refcnt is quiescent, indicating no other walkers,
1261 1261   *  - no other threads or ire's are holding references to the irb,
1262 1262   *      i.e., irb_nire == 0,
1263 1263   *  - there are no active ire's in the bucket, i.e., irb_ire_cnt == 0
1264 1264   */
1265 1265  typedef struct irb {
1266 1266          struct ire_s    *irb_ire;       /* First ire in this bucket */
1267 1267                                          /* Should be first in this struct */
1268 1268          krwlock_t       irb_lock;       /* Protect this bucket */
1269 1269          uint_t          irb_refcnt;     /* Protected by irb_lock */
1270 1270          uchar_t         irb_marks;      /* CONDEMNED ires in this bucket ? */
1271 1271  #define IRB_MARK_CONDEMNED      0x0001  /* Contains some IRE_IS_CONDEMNED */
1272 1272  #define IRB_MARK_DYNAMIC        0x0002  /* Dynamically allocated */
1273 1273          /* Once IPv6 uses radix then IRB_MARK_DYNAMIC will be always be set */
1274 1274          uint_t          irb_ire_cnt;    /* Num of active IRE in this bucket */
1275 1275          int             irb_nire;       /* Num of ftable ire's that ref irb */
1276 1276          ip_stack_t      *irb_ipst;      /* Does not have a netstack_hold */
1277 1277  } irb_t;
1278 1278  
1279 1279  /*
1280 1280   * This is the structure used to store the multicast physical addresses
1281 1281   * that an interface has joined.
1282 1282   * The refcnt keeps track of the number of multicast IP addresses mapping
1283 1283   * to a physical multicast address.
1284 1284   */
1285 1285  typedef struct multiphysaddr_s {
1286 1286          struct  multiphysaddr_s  *mpa_next;
1287 1287          char    mpa_addr[IP_MAX_HW_LEN];
1288 1288          int     mpa_refcnt;
1289 1289  } multiphysaddr_t;
1290 1290  
1291 1291  #define IRB2RT(irb)     (rt_t *)((caddr_t)(irb) - offsetof(rt_t, rt_irb))
1292 1292  
1293 1293  /* Forward declarations */
1294 1294  struct dce_s;
1295 1295  typedef struct dce_s dce_t;
1296 1296  struct ire_s;
1297 1297  typedef struct ire_s ire_t;
1298 1298  struct ncec_s;
1299 1299  typedef struct ncec_s ncec_t;
1300 1300  struct nce_s;
1301 1301  typedef struct nce_s nce_t;
1302 1302  struct ip_recv_attr_s;
1303 1303  typedef struct ip_recv_attr_s ip_recv_attr_t;
1304 1304  struct ip_xmit_attr_s;
1305 1305  typedef struct ip_xmit_attr_s ip_xmit_attr_t;
1306 1306  
1307 1307  struct tsol_ire_gw_secattr_s;
1308 1308  typedef struct tsol_ire_gw_secattr_s tsol_ire_gw_secattr_t;
1309 1309  
1310 1310  /*
1311 1311   * This is a structure for a one-element route cache that is passed
1312 1312   * by reference between ip_input and ill_inputfn.
1313 1313   */
1314 1314  typedef struct {
1315 1315          ire_t           *rtc_ire;
1316 1316          ipaddr_t        rtc_ipaddr;
1317 1317          in6_addr_t      rtc_ip6addr;
1318 1318  } rtc_t;
1319 1319  
1320 1320  /*
1321 1321   * Note: Temporarily use 64 bits, and will probably go back to 32 bits after
1322 1322   * more cleanup work is done.
1323 1323   */
1324 1324  typedef uint64_t iaflags_t;
1325 1325  
1326 1326  /* The ill input function pointer type */
1327 1327  typedef void (*pfillinput_t)(mblk_t *, void *, void *, ip_recv_attr_t *,
1328 1328      rtc_t *);
1329 1329  
1330 1330  /* The ire receive function pointer type */
1331 1331  typedef void (*pfirerecv_t)(ire_t *, mblk_t *, void *, ip_recv_attr_t *);
1332 1332  
1333 1333  /* The ire send and postfrag function pointer types */
1334 1334  typedef int (*pfiresend_t)(ire_t *, mblk_t *, void *,
1335 1335      ip_xmit_attr_t *, uint32_t *);
1336 1336  typedef int (*pfirepostfrag_t)(mblk_t *, nce_t *, iaflags_t, uint_t, uint32_t,
1337 1337      zoneid_t, zoneid_t, uintptr_t *);
1338 1338  
1339 1339  
1340 1340  #define IP_V4_G_HEAD    0
1341 1341  #define IP_V6_G_HEAD    1
1342 1342  
1343 1343  #define MAX_G_HEADS     2
1344 1344  
1345 1345  /*
1346 1346   * unpadded ill_if structure
1347 1347   */
1348 1348  struct  _ill_if_s_ {
1349 1349          union ill_if_u  *illif_next;
1350 1350          union ill_if_u  *illif_prev;
1351 1351          avl_tree_t      illif_avl_by_ppa;       /* AVL tree sorted on ppa */
1352 1352          vmem_t          *illif_ppa_arena;       /* ppa index space */
1353 1353          uint16_t        illif_mcast_v1;         /* hints for              */
1354 1354          uint16_t        illif_mcast_v2;         /* [igmp|mld]_slowtimo    */
1355 1355          int             illif_name_len;         /* name length */
1356 1356          char            illif_name[LIFNAMSIZ];  /* name of interface type */
1357 1357  };
1358 1358  
1359 1359  /* cache aligned ill_if structure */
1360 1360  typedef union   ill_if_u {
1361 1361          struct  _ill_if_s_ ill_if_s;
1362 1362          char    illif_filler[CACHE_ALIGN(_ill_if_s_)];
1363 1363  } ill_if_t;
1364 1364  
1365 1365  #define illif_next              ill_if_s.illif_next
1366 1366  #define illif_prev              ill_if_s.illif_prev
1367 1367  #define illif_avl_by_ppa        ill_if_s.illif_avl_by_ppa
1368 1368  #define illif_ppa_arena         ill_if_s.illif_ppa_arena
1369 1369  #define illif_mcast_v1          ill_if_s.illif_mcast_v1
1370 1370  #define illif_mcast_v2          ill_if_s.illif_mcast_v2
1371 1371  #define illif_name              ill_if_s.illif_name
1372 1372  #define illif_name_len          ill_if_s.illif_name_len
1373 1373  
1374 1374  typedef struct ill_walk_context_s {
1375 1375          int     ctx_current_list; /* current list being searched */
1376 1376          int     ctx_last_list;   /* last list to search */
1377 1377  } ill_walk_context_t;
1378 1378  
1379 1379  /*
1380 1380   * ill_g_heads structure, one for IPV4 and one for IPV6
1381 1381   */
1382 1382  struct _ill_g_head_s_ {
1383 1383          ill_if_t        *ill_g_list_head;
1384 1384          ill_if_t        *ill_g_list_tail;
1385 1385  };
1386 1386  
1387 1387  typedef union ill_g_head_u {
1388 1388          struct _ill_g_head_s_ ill_g_head_s;
1389 1389          char    ill_g_head_filler[CACHE_ALIGN(_ill_g_head_s_)];
1390 1390  } ill_g_head_t;
1391 1391  
1392 1392  #define ill_g_list_head ill_g_head_s.ill_g_list_head
1393 1393  #define ill_g_list_tail ill_g_head_s.ill_g_list_tail
1394 1394  
1395 1395  #define IP_V4_ILL_G_LIST(ipst)  \
1396 1396          (ipst)->ips_ill_g_heads[IP_V4_G_HEAD].ill_g_list_head
1397 1397  #define IP_V6_ILL_G_LIST(ipst)  \
1398 1398          (ipst)->ips_ill_g_heads[IP_V6_G_HEAD].ill_g_list_head
1399 1399  #define IP_VX_ILL_G_LIST(i, ipst)       \
1400 1400          (ipst)->ips_ill_g_heads[i].ill_g_list_head
1401 1401  
1402 1402  #define ILL_START_WALK_V4(ctx_ptr, ipst)        \
1403 1403          ill_first(IP_V4_G_HEAD, IP_V4_G_HEAD, ctx_ptr, ipst)
1404 1404  #define ILL_START_WALK_V6(ctx_ptr, ipst)        \
1405 1405          ill_first(IP_V6_G_HEAD, IP_V6_G_HEAD, ctx_ptr, ipst)
1406 1406  #define ILL_START_WALK_ALL(ctx_ptr, ipst)       \
1407 1407          ill_first(MAX_G_HEADS, MAX_G_HEADS, ctx_ptr, ipst)
1408 1408  
1409 1409  /*
1410 1410   * Capabilities, possible flags for ill_capabilities.
1411 1411   */
1412 1412  #define ILL_CAPAB_LSO           0x04            /* Large Send Offload */
1413 1413  #define ILL_CAPAB_HCKSUM        0x08            /* Hardware checksumming */
1414 1414  #define ILL_CAPAB_ZEROCOPY      0x10            /* Zero-copy */
1415 1415  #define ILL_CAPAB_DLD           0x20            /* DLD capabilities */
1416 1416  #define ILL_CAPAB_DLD_POLL      0x40            /* Polling */
1417 1417  #define ILL_CAPAB_DLD_DIRECT    0x80            /* Direct function call */
1418 1418  #define ILL_CAPAB_DLD_IPCHECK   0x100           /* Check if IPs are permitted */
1419 1419  
1420 1420  /*
1421 1421   * Per-ill Hardware Checksumming capbilities.
1422 1422   */
1423 1423  typedef struct ill_hcksum_capab_s ill_hcksum_capab_t;
1424 1424  
1425 1425  /*
1426 1426   * Per-ill Zero-copy capabilities.
1427 1427   */
1428 1428  typedef struct ill_zerocopy_capab_s ill_zerocopy_capab_t;
1429 1429  
1430 1430  /*
1431 1431   * DLD capbilities.
1432 1432   */
1433 1433  typedef struct ill_dld_capab_s ill_dld_capab_t;
1434 1434  
1435 1435  /*
1436 1436   * Per-ill polling resource map.
1437 1437   */
1438 1438  typedef struct ill_rx_ring ill_rx_ring_t;
1439 1439  
1440 1440  /*
1441 1441   * Per-ill Large Send Offload capabilities.
1442 1442   */
1443 1443  typedef struct ill_lso_capab_s ill_lso_capab_t;
1444 1444  
1445 1445  /* The following are ill_state_flags */
1446 1446  #define ILL_LL_SUBNET_PENDING   0x01    /* Waiting for DL_INFO_ACK from drv */
1447 1447  #define ILL_CONDEMNED           0x02    /* No more new ref's to the ILL */
1448 1448  #define ILL_DL_UNBIND_IN_PROGRESS       0x04    /* UNBIND_REQ is sent */
1449 1449  /*
1450 1450   * ILL_DOWN_IN_PROGRESS is set to ensure the following:
1451 1451   * - no packets are sent to the driver after the DL_UNBIND_REQ is sent,
1452 1452   * - no longstanding references will be acquired on objects that are being
1453 1453   *   brought down.
1454 1454   */
1455 1455  #define ILL_DOWN_IN_PROGRESS    0x08
1456 1456  
1457 1457  /* Is this an ILL whose source address is used by other ILL's ? */
1458 1458  #define IS_USESRC_ILL(ill)                      \
1459 1459          (((ill)->ill_usesrc_ifindex == 0) &&    \
1460 1460          ((ill)->ill_usesrc_grp_next != NULL))
1461 1461  
1462 1462  /* Is this a client/consumer of the usesrc ILL ? */
1463 1463  #define IS_USESRC_CLI_ILL(ill)                  \
1464 1464          (((ill)->ill_usesrc_ifindex != 0) &&    \
1465 1465          ((ill)->ill_usesrc_grp_next != NULL))
1466 1466  
1467 1467  /* Is this an virtual network interface (vni) ILL ? */
1468 1468  #define IS_VNI(ill)                                                     \
1469 1469          (((ill)->ill_phyint->phyint_flags & (PHYI_LOOPBACK|PHYI_VIRTUAL)) == \
1470 1470          PHYI_VIRTUAL)
1471 1471  
1472 1472  /* Is this a loopback ILL? */
1473 1473  #define IS_LOOPBACK(ill) \
1474 1474          ((ill)->ill_phyint->phyint_flags & PHYI_LOOPBACK)
1475 1475  
1476 1476  /* Is this an IPMP meta-interface ILL? */
1477 1477  #define IS_IPMP(ill)                                                    \
1478 1478          ((ill)->ill_phyint->phyint_flags & PHYI_IPMP)
1479 1479  
1480 1480  /* Is this ILL under an IPMP meta-interface? (aka "in a group?") */
1481 1481  #define IS_UNDER_IPMP(ill)                                              \
1482 1482          ((ill)->ill_grp != NULL && !IS_IPMP(ill))
1483 1483  
1484 1484  /* Is ill1 in the same illgrp as ill2? */
1485 1485  #define IS_IN_SAME_ILLGRP(ill1, ill2)                                   \
1486 1486          ((ill1)->ill_grp != NULL && ((ill1)->ill_grp == (ill2)->ill_grp))
1487 1487  
1488 1488  /* Is ill1 on the same LAN as ill2? */
1489 1489  #define IS_ON_SAME_LAN(ill1, ill2)                                      \
1490 1490          ((ill1) == (ill2) || IS_IN_SAME_ILLGRP(ill1, ill2))
1491 1491  
1492 1492  #define ILL_OTHER(ill)                                                  \
1493 1493          ((ill)->ill_isv6 ? (ill)->ill_phyint->phyint_illv4 :            \
1494 1494              (ill)->ill_phyint->phyint_illv6)
1495 1495  
1496 1496  /*
1497 1497   * IPMP group ILL state structure -- up to two per IPMP group (V4 and V6).
1498 1498   * Created when the V4 and/or V6 IPMP meta-interface is I_PLINK'd.  It is
1499 1499   * guaranteed to persist while there are interfaces of that type in the group.
1500 1500   * In general, most fields are accessed outside of the IPSQ (e.g., in the
1501 1501   * datapath), and thus use locks in addition to the IPSQ for protection.
1502 1502   *
1503 1503   * synchronization:             read                    write
1504 1504   *
1505 1505   *      ig_if                   ipsq or ill_g_lock      ipsq and ill_g_lock
1506 1506   *      ig_actif                ipsq or ipmp_lock       ipsq and ipmp_lock
1507 1507   *      ig_nactif               ipsq or ipmp_lock       ipsq and ipmp_lock
1508 1508   *      ig_next_ill             ipsq or ipmp_lock       ipsq and ipmp_lock
1509 1509   *      ig_ipmp_ill             write once              write once
1510 1510   *      ig_cast_ill             ipsq or ipmp_lock       ipsq and ipmp_lock
1511 1511   *      ig_arpent               ipsq                    ipsq
1512 1512   *      ig_mtu                  ipsq                    ipsq
1513 1513   *      ig_mc_mtu               ipsq                    ipsq
1514 1514   */
1515 1515  typedef struct ipmp_illgrp_s {
1516 1516          list_t          ig_if;          /* list of all interfaces */
1517 1517          list_t          ig_actif;       /* list of active interfaces */
1518 1518          uint_t          ig_nactif;      /* number of active interfaces */
1519 1519          struct ill_s    *ig_next_ill;   /* next active interface to use */
1520 1520          struct ill_s    *ig_ipmp_ill;   /* backpointer to IPMP meta-interface */
1521 1521          struct ill_s    *ig_cast_ill;   /* nominated ill for multi/broadcast */
1522 1522          list_t          ig_arpent;      /* list of ARP entries */
1523 1523          uint_t          ig_mtu;         /* ig_ipmp_ill->ill_mtu */
1524 1524          uint_t          ig_mc_mtu;      /* ig_ipmp_ill->ill_mc_mtu */
1525 1525  } ipmp_illgrp_t;
1526 1526  
1527 1527  /*
1528 1528   * IPMP group state structure -- one per IPMP group.  Created when the
1529 1529   * IPMP meta-interface is plumbed; it is guaranteed to persist while there
1530 1530   * are interfaces in it.
1531 1531   *
1532 1532   * ipmp_grp_t synchronization:          read                    write
1533 1533   *
1534 1534   *      gr_name                         ipmp_lock               ipmp_lock
1535 1535   *      gr_ifname                       write once              write once
1536 1536   *      gr_mactype                      ipmp_lock               ipmp_lock
1537 1537   *      gr_phyint                       write once              write once
1538 1538   *      gr_nif                          ipmp_lock               ipmp_lock
1539 1539   *      gr_nactif                       ipsq                    ipsq
1540 1540   *      gr_v4                           ipmp_lock               ipmp_lock
1541 1541   *      gr_v6                           ipmp_lock               ipmp_lock
1542 1542   *      gr_nv4                          ipmp_lock               ipmp_lock
1543 1543   *      gr_nv6                          ipmp_lock               ipmp_lock
1544 1544   *      gr_pendv4                       ipmp_lock               ipmp_lock
1545 1545   *      gr_pendv6                       ipmp_lock               ipmp_lock
1546 1546   *      gr_linkdownmp                   ipsq                    ipsq
1547 1547   *      gr_ksp                          ipmp_lock               ipmp_lock
1548 1548   *      gr_kstats0                      atomic                  atomic
1549 1549   */
1550 1550  typedef struct ipmp_grp_s {
1551 1551          char            gr_name[LIFGRNAMSIZ];   /* group name */
1552 1552          char            gr_ifname[LIFNAMSIZ];   /* interface name */
1553 1553          t_uscalar_t     gr_mactype;     /* DLPI mactype of group */
1554 1554          phyint_t        *gr_phyint;     /* IPMP group phyint */
1555 1555          uint_t          gr_nif;         /* number of interfaces in group */
1556 1556          uint_t          gr_nactif;      /* number of active interfaces */
1557 1557          ipmp_illgrp_t   *gr_v4;         /* V4 group information */
1558 1558          ipmp_illgrp_t   *gr_v6;         /* V6 group information */
1559 1559          uint_t          gr_nv4;         /* number of ills in V4 group */
1560 1560          uint_t          gr_nv6;         /* number of ills in V6 group */
1561 1561          uint_t          gr_pendv4;      /* number of pending ills in V4 group */
1562 1562          uint_t          gr_pendv6;      /* number of pending ills in V6 group */
1563 1563          mblk_t          *gr_linkdownmp; /* message used to bring link down */
1564 1564          kstat_t         *gr_ksp;        /* group kstat pointer */
1565 1565          uint64_t        gr_kstats0[IPMP_KSTAT_MAX]; /* baseline group kstats */
1566 1566  } ipmp_grp_t;
1567 1567  
1568 1568  /*
1569 1569   * IPMP ARP entry -- one per SIOCS*ARP entry tied to the group.  Used to keep
1570 1570   * ARP up-to-date as the active set of interfaces in the group changes.
1571 1571   */
1572 1572  typedef struct ipmp_arpent_s {
1573 1573          ipaddr_t        ia_ipaddr;      /* IP address for this entry */
1574 1574          boolean_t       ia_proxyarp;    /* proxy ARP entry? */
1575 1575          boolean_t       ia_notified;    /* ARP notified about this entry? */
1576 1576          list_node_t     ia_node;        /* next ARP entry in list */
1577 1577          uint16_t        ia_flags;       /* nce_flags for the address */
1578 1578          size_t          ia_lladdr_len;
1579 1579          uchar_t         *ia_lladdr;
1580 1580  } ipmp_arpent_t;
1581 1581  
1582 1582  struct arl_s;
1583 1583  
1584 1584  /*
1585 1585   * Per-ill capabilities.
1586 1586   */
1587 1587  struct ill_hcksum_capab_s {
1588 1588          uint_t  ill_hcksum_version;     /* interface version */
1589 1589          uint_t  ill_hcksum_txflags;     /* capabilities on transmit */
1590 1590  };
1591 1591  
1592 1592  struct ill_zerocopy_capab_s {
1593 1593          uint_t  ill_zerocopy_version;   /* interface version */
1594 1594          uint_t  ill_zerocopy_flags;     /* capabilities */
1595 1595  };
1596 1596  
1597 1597  struct ill_lso_capab_s {
1598 1598          uint_t  ill_lso_flags;          /* capabilities */
1599 1599          uint_t  ill_lso_max;            /* maximum size of payload */
1600 1600  };
1601 1601  
1602 1602  /*
1603 1603   * IP Lower level Structure.
1604 1604   * Instance data structure in ip_open when there is a device below us.
1605 1605   */
1606 1606  typedef struct ill_s {
1607 1607          pfillinput_t ill_inputfn;       /* Fast input function selector */
1608 1608          ill_if_t *ill_ifptr;            /* pointer to interface type */
1609 1609          queue_t *ill_rq;                /* Read queue. */
1610 1610          queue_t *ill_wq;                /* Write queue. */
1611 1611  
1612 1612          int     ill_error;              /* Error value sent up by device. */
1613 1613  
1614 1614          ipif_t  *ill_ipif;              /* Interface chain for this ILL. */
1615 1615  
1616 1616          uint_t  ill_ipif_up_count;      /* Number of IPIFs currently up. */
1617 1617          uint_t  ill_max_frag;           /* Max IDU from DLPI. */
1618 1618          uint_t  ill_current_frag;       /* Current IDU from DLPI. */
1619 1619          uint_t  ill_mtu;                /* User-specified MTU; SIOCSLIFMTU */
1620 1620          uint_t  ill_mc_mtu;             /* MTU for multi/broadcast */
1621 1621          uint_t  ill_metric;             /* BSD if metric, for compatibility. */
1622 1622          char    *ill_name;              /* Our name. */
1623 1623          uint_t  ill_ipif_dup_count;     /* Number of duplicate addresses. */
1624 1624          uint_t  ill_name_length;        /* Name length, incl. terminator. */
1625 1625          uint_t  ill_net_type;           /* IRE_IF_RESOLVER/IRE_IF_NORESOLVER. */
1626 1626          /*
1627 1627           * Physical Point of Attachment num.  If DLPI style 1 provider
1628 1628           * then this is derived from the devname.
1629 1629           */
1630 1630          uint_t  ill_ppa;
1631 1631          t_uscalar_t     ill_sap;
1632 1632          t_scalar_t      ill_sap_length; /* Including sign (for position) */
1633 1633          uint_t  ill_phys_addr_length;   /* Excluding the sap. */
1634 1634          uint_t  ill_bcast_addr_length;  /* Only set when the DL provider */
1635 1635                                          /* supports broadcast. */
1636 1636          t_uscalar_t     ill_mactype;
1637 1637          uint8_t *ill_frag_ptr;          /* Reassembly state. */
1638 1638          timeout_id_t ill_frag_timer_id; /* timeout id for the frag timer */
1639 1639          ipfb_t  *ill_frag_hash_tbl;     /* Fragment hash list head. */
1640 1640  
1641 1641          krwlock_t ill_mcast_lock;       /* Protects multicast state */
1642 1642          kmutex_t ill_mcast_serializer;  /* Serialize across ilg and ilm state */
1643 1643          ilm_t   *ill_ilm;               /* Multicast membership for ill */
1644 1644          uint_t  ill_global_timer;       /* for IGMPv3/MLDv2 general queries */
1645 1645          int     ill_mcast_type;         /* type of router which is querier */
1646 1646                                          /* on this interface */
1647 1647          uint16_t ill_mcast_v1_time;     /* # slow timeouts since last v1 qry */
1648 1648          uint16_t ill_mcast_v2_time;     /* # slow timeouts since last v2 qry */
1649 1649          uint8_t ill_mcast_v1_tset;      /* 1 => timer is set; 0 => not set */
1650 1650          uint8_t ill_mcast_v2_tset;      /* 1 => timer is set; 0 => not set */
1651 1651  
1652 1652          uint8_t ill_mcast_rv;           /* IGMPv3/MLDv2 robustness variable */
1653 1653          int     ill_mcast_qi;           /* IGMPv3/MLDv2 query interval var */
1654 1654  
1655 1655          /*
1656 1656           * All non-NULL cells between 'ill_first_mp_to_free' and
1657 1657           * 'ill_last_mp_to_free' are freed in ill_delete.
1658 1658           */
1659 1659  #define ill_first_mp_to_free    ill_bcast_mp
1660 1660          mblk_t  *ill_bcast_mp;          /* DLPI header for broadcasts. */
1661 1661          mblk_t  *ill_unbind_mp;         /* unbind mp from ill_dl_up() */
1662 1662          mblk_t  *ill_promiscoff_mp;     /* for ill_leave_allmulti() */
1663 1663          mblk_t  *ill_dlpi_deferred;     /* b_next chain of control messages */
1664 1664          mblk_t  *ill_dest_addr_mp;      /* mblk which holds ill_dest_addr */
1665 1665          mblk_t  *ill_replumb_mp;        /* replumb mp from ill_replumb() */
1666 1666          mblk_t  *ill_phys_addr_mp;      /* mblk which holds ill_phys_addr */
1667 1667          mblk_t  *ill_mcast_deferred;    /* b_next chain of IGMP/MLD packets */
1668 1668  #define ill_last_mp_to_free     ill_mcast_deferred
1669 1669  
1670 1670          cred_t  *ill_credp;             /* opener's credentials */
1671 1671          uint8_t *ill_phys_addr;         /* ill_phys_addr_mp->b_rptr + off */
1672 1672          uint8_t *ill_dest_addr;         /* ill_dest_addr_mp->b_rptr + off */
1673 1673  
1674 1674          uint_t  ill_state_flags;        /* see ILL_* flags above */
1675 1675  
1676 1676          /* Following bit fields protected by ipsq_t */
1677 1677          uint_t
1678 1678                  ill_needs_attach : 1,
1679 1679                  ill_reserved : 1,
1680 1680                  ill_isv6 : 1,
1681 1681                  ill_dlpi_style_set : 1,
1682 1682  
1683 1683                  ill_ifname_pending : 1,
1684 1684                  ill_logical_down : 1,
1685 1685                  ill_dl_up : 1,
1686 1686                  ill_up_ipifs : 1,
1687 1687  
1688 1688                  ill_note_link : 1,      /* supports link-up notification */
1689 1689                  ill_capab_reneg : 1, /* capability renegotiation to be done */
1690 1690                  ill_dld_capab_inprog : 1, /* direct dld capab call in prog */
1691 1691                  ill_need_recover_multicast : 1,
1692 1692  
1693 1693                  ill_replumbing : 1,
1694 1694                  ill_arl_dlpi_pending : 1,
1695 1695                  ill_grp_pending : 1,
1696 1696  
1697 1697                  ill_pad_to_bit_31 : 17;
1698 1698  
1699 1699          /* Following bit fields protected by ill_lock */
1700 1700          uint_t
1701 1701                  ill_fragtimer_executing : 1,
1702 1702                  ill_fragtimer_needrestart : 1,
1703 1703                  ill_manual_token : 1,   /* system won't override ill_token */
1704 1704                  /*
1705 1705                   * ill_manual_linklocal : system will not change the
1706 1706                   * linklocal whenever ill_token changes.
1707 1707                   */
1708 1708                  ill_manual_linklocal : 1,
1709 1709  
1710 1710                  ill_manual_dst_linklocal : 1, /* same for pt-pt dst linklocal */
1711 1711  
1712 1712                  ill_mcast_ncec_cleanup : 1,     /* Reaping mcast ncecs. */
1713 1713                  ill_pad_bit_31 : 26;
1714 1714  
1715 1715          /*
1716 1716           * Used in SIOCSIFMUXID and SIOCGIFMUXID for 'ifconfig unplumb'.
1717 1717           */
1718 1718          int     ill_muxid;              /* muxid returned from plink */
1719 1719  
1720 1720          /* Used for IP frag reassembly throttling on a per ILL basis.  */
1721 1721          uint_t  ill_ipf_gen;            /* Generation of next fragment queue */
1722 1722          uint_t  ill_frag_count;         /* Count of all reassembly mblk bytes */
  
    | 
      ↓ open down ↓ | 
    1722 lines elided | 
    
      ↑ open up ↑ | 
  
1723 1723          uint_t  ill_frag_free_num_pkts;  /* num of fragmented packets to free */
1724 1724          clock_t ill_last_frag_clean_time; /* time when frag's were pruned */
1725 1725          int     ill_type;               /* From <net/if_types.h> */
1726 1726          uint_t  ill_dlpi_multicast_state;       /* See below IDS_* */
1727 1727          uint_t  ill_dlpi_fastpath_state;        /* See below IDS_* */
1728 1728  
1729 1729          /*
1730 1730           * Capabilities related fields.
1731 1731           */
1732 1732          uint_t  ill_dlpi_capab_state;   /* State of capability query, IDCS_* */
1733      -        kcondvar_t ill_dlpi_capab_cv;   /* CV for broadcasting state changes */
1734      -        kmutex_t ill_dlpi_capab_lock;   /* Lock for accessing above Cond Var */
1735 1733          uint_t  ill_capab_pending_cnt;
1736 1734          uint64_t ill_capabilities;      /* Enabled capabilities, ILL_CAPAB_* */
1737 1735          ill_hcksum_capab_t *ill_hcksum_capab; /* H/W cksumming capabilities */
1738 1736          ill_zerocopy_capab_t *ill_zerocopy_capab; /* Zero-copy capabilities */
1739 1737          ill_dld_capab_t *ill_dld_capab; /* DLD capabilities */
1740 1738          ill_lso_capab_t *ill_lso_capab; /* Large Segment Offload capabilities */
1741 1739          mblk_t  *ill_capab_reset_mp;    /* Preallocated mblk for capab reset */
1742 1740  
1743 1741          uint8_t ill_max_hops;   /* Maximum hops for any logical interface */
1744 1742          uint_t  ill_user_mtu;   /* User-specified MTU via SIOCSLIFLNKINFO */
1745 1743          uint32_t ill_reachable_time;    /* Value for ND algorithm in msec */
1746 1744          uint32_t ill_reachable_retrans_time; /* Value for ND algorithm msec */
1747 1745          uint_t  ill_max_buf;            /* Max # of req to buffer for ND */
1748 1746          in6_addr_t      ill_token;      /* IPv6 interface id */
1749 1747          in6_addr_t      ill_dest_token; /* Destination IPv6 interface id */
1750 1748          uint_t          ill_token_length;
1751 1749          uint32_t        ill_xmit_count;         /* ndp max multicast xmits */
1752 1750          mib2_ipIfStatsEntry_t   *ill_ip_mib;    /* ver indep. interface mib */
1753 1751          mib2_ipv6IfIcmpEntry_t  *ill_icmp6_mib; /* Per interface mib */
1754 1752  
1755 1753          phyint_t                *ill_phyint;
1756 1754          uint64_t                ill_flags;
1757 1755  
1758 1756          kmutex_t        ill_lock;       /* Please see table below */
1759 1757          /*
1760 1758           * The ill_nd_lla* fields handle the link layer address option
1761 1759           * from neighbor discovery. This is used for external IPv6
1762 1760           * address resolution.
1763 1761           */
1764 1762          mblk_t          *ill_nd_lla_mp; /* mblk which holds ill_nd_lla */
1765 1763          uint8_t         *ill_nd_lla;    /* Link Layer Address */
1766 1764          uint_t          ill_nd_lla_len; /* Link Layer Address length */
1767 1765          /*
1768 1766           * We have 4 phys_addr_req's sent down. This field keeps track
1769 1767           * of which one is pending.
1770 1768           */
1771 1769          t_uscalar_t     ill_phys_addr_pend; /* which dl_phys_addr_req pending */
1772 1770          /*
1773 1771           * Used to save errors that occur during plumbing
1774 1772           */
1775 1773          uint_t          ill_ifname_pending_err;
1776 1774          /*
1777 1775           * Used to save errors that occur during binding
1778 1776           */
1779 1777          uint_t          ill_dl_bind_err;
1780 1778          avl_node_t      ill_avl_byppa; /* avl node based on ppa */
1781 1779          uint_t          ill_mcast_nces; /* Number of NCEs that are multicast. */
1782 1780          list_t          ill_nce; /* pointer to nce_s list */
1783 1781          uint_t          ill_refcnt;     /* active refcnt by threads */
1784 1782          uint_t          ill_ire_cnt;    /* ires associated with this ill */
1785 1783          kcondvar_t      ill_cv;
1786 1784          uint_t          ill_ncec_cnt;   /* ncecs associated with this ill */
1787 1785          uint_t          ill_nce_cnt;    /* nces associated with this ill */
1788 1786          uint_t          ill_waiters;    /* threads waiting in ipsq_enter */
1789 1787          /*
1790 1788           * Contains the upper read queue pointer of the module immediately
1791 1789           * beneath IP.  This field allows IP to validate sub-capability
1792 1790           * acknowledgments coming up from downstream.
1793 1791           */
1794 1792          queue_t         *ill_lmod_rq;   /* read queue pointer of module below */
1795 1793          uint_t          ill_lmod_cnt;   /* number of modules beneath IP */
1796 1794          ip_m_t          *ill_media;     /* media specific params/functions */
1797 1795          t_uscalar_t     ill_dlpi_pending; /* Last DLPI primitive issued */
1798 1796          uint_t          ill_usesrc_ifindex; /* use src addr from this ILL */
1799 1797          struct ill_s    *ill_usesrc_grp_next; /* Next ILL in the usesrc group */
1800 1798          boolean_t       ill_trace_disable;      /* True when alloc fails */
1801 1799          zoneid_t        ill_zoneid;
1802 1800          ip_stack_t      *ill_ipst;      /* Corresponds to a netstack_hold */
1803 1801          uint32_t        ill_dhcpinit;   /* IP_DHCPINIT_IFs for ill */
1804 1802          void            *ill_flownotify_mh; /* Tx flow ctl, mac cb handle */
1805 1803          uint_t          ill_ilm_cnt;    /* ilms referencing this ill */
1806 1804          uint_t          ill_ipallmulti_cnt; /* ip_join_allmulti() calls */
1807 1805          ilm_t           *ill_ipallmulti_ilm;
1808 1806  
1809 1807          mblk_t          *ill_saved_ire_mp; /* Allocated for each extra IRE */
1810 1808                                          /* with ire_ill set so they can */
1811 1809                                          /* survive the ill going down and up. */
1812 1810          kmutex_t        ill_saved_ire_lock; /* Protects ill_saved_ire_mp, cnt */
1813 1811          uint_t          ill_saved_ire_cnt;      /* # entries */
1814 1812          struct arl_ill_common_s    *ill_common;
1815 1813          ire_t           *ill_ire_multicast; /* IRE_MULTICAST for ill */
1816 1814          clock_t         ill_defend_start;   /* start of 1 hour period */
1817 1815          uint_t          ill_defend_count;   /* # of announce/defends per ill */
1818 1816          /*
1819 1817           * IPMP fields.
1820 1818           */
1821 1819          ipmp_illgrp_t   *ill_grp;       /* IPMP group information */
1822 1820          list_node_t     ill_actnode;    /* next active ill in group */
1823 1821          list_node_t     ill_grpnode;    /* next ill in group */
1824 1822          ipif_t          *ill_src_ipif;  /* source address selection rotor */
1825 1823          ipif_t          *ill_move_ipif; /* ipif awaiting move to new ill */
1826 1824          boolean_t       ill_nom_cast;   /* nominated for mcast/bcast */
1827 1825          uint_t          ill_bound_cnt;  /* # of data addresses bound to ill */
1828 1826          ipif_t          *ill_bound_ipif; /* ipif chain bound to ill */
1829 1827          timeout_id_t    ill_refresh_tid; /* ill refresh retry timeout id */
1830 1828  
1831 1829          uint32_t        ill_mrouter_cnt; /* mrouter allmulti joins */
1832 1830          uint32_t        ill_allowed_ips_cnt;
1833 1831          in6_addr_t      *ill_allowed_ips;
1834 1832  
1835 1833          /* list of multicast physical addresses joined on this ill */
1836 1834          multiphysaddr_t *ill_mphysaddr_list;
1837 1835  } ill_t;
1838 1836  
1839 1837  /*
1840 1838   * ILL_FREE_OK() means that there are no incoming pointer references
1841 1839   * to the ill.
1842 1840   */
1843 1841  #define ILL_FREE_OK(ill)                                        \
1844 1842          ((ill)->ill_ire_cnt == 0 && (ill)->ill_ilm_cnt == 0 &&  \
1845 1843          (ill)->ill_ncec_cnt == 0 && (ill)->ill_nce_cnt == 0)
1846 1844  
1847 1845  /*
1848 1846   * An ipif/ill can be marked down only when the ire and ncec references
1849 1847   * to that ipif/ill goes to zero. ILL_DOWN_OK() is a necessary condition
1850 1848   * quiescence checks. See comments above IPIF_DOWN_OK for details
1851 1849   * on why ires and nces are selectively considered for this macro.
1852 1850   */
1853 1851  #define ILL_DOWN_OK(ill)                                        \
1854 1852          (ill->ill_ire_cnt == 0 && ill->ill_ncec_cnt == 0 &&     \
1855 1853          ill->ill_nce_cnt == 0)
1856 1854  
1857 1855  /*
1858 1856   * The following table lists the protection levels of the various members
1859 1857   * of the ill_t. Same notation as that used for ipif_t above is used.
1860 1858   *
1861 1859   *                              Write                   Read
1862 1860   *
1863 1861   * ill_ifptr                    ill_g_lock + s          Write once
1864 1862   * ill_rq                       ipsq                    Write once
1865 1863   * ill_wq                       ipsq                    Write once
1866 1864   *
1867 1865   * ill_error                    ipsq                    None
1868 1866   * ill_ipif                     ill_g_lock + ipsq       ill_g_lock OR ipsq
1869 1867   * ill_ipif_up_count            ill_lock + ipsq         ill_lock OR ipsq
1870 1868   * ill_max_frag                 ill_lock                ill_lock
1871 1869   * ill_current_frag             ill_lock                ill_lock
1872 1870   *
1873 1871   * ill_name                     ill_g_lock + ipsq       Write once
1874 1872   * ill_name_length              ill_g_lock + ipsq       Write once
1875 1873   * ill_ndd_name                 ipsq                    Write once
1876 1874   * ill_net_type                 ipsq                    Write once
1877 1875   * ill_ppa                      ill_g_lock + ipsq       Write once
1878 1876   * ill_sap                      ipsq + down ill         Write once
1879 1877   * ill_sap_length               ipsq + down ill         Write once
1880 1878   * ill_phys_addr_length         ipsq + down ill         Write once
1881 1879   *
1882 1880   * ill_bcast_addr_length        ipsq                    ipsq
1883 1881   * ill_mactype                  ipsq                    ipsq
1884 1882   * ill_frag_ptr                 ipsq                    ipsq
1885 1883   *
1886 1884   * ill_frag_timer_id            ill_lock                ill_lock
1887 1885   * ill_frag_hash_tbl            ipsq                    up ill
1888 1886   * ill_ilm                      ill_mcast_lock(WRITER)  ill_mcast_lock(READER)
1889 1887   * ill_global_timer             ill_mcast_lock(WRITER)  ill_mcast_lock(READER)
1890 1888   * ill_mcast_type               ill_mcast_lock(WRITER)  ill_mcast_lock(READER)
1891 1889   * ill_mcast_v1_time            ill_mcast_lock(WRITER)  ill_mcast_lock(READER)
1892 1890   * ill_mcast_v2_time            ill_mcast_lock(WRITER)  ill_mcast_lock(READER)
1893 1891   * ill_mcast_v1_tset            ill_mcast_lock(WRITER)  ill_mcast_lock(READER)
1894 1892   * ill_mcast_v2_tset            ill_mcast_lock(WRITER)  ill_mcast_lock(READER)
1895 1893   * ill_mcast_rv                 ill_mcast_lock(WRITER)  ill_mcast_lock(READER)
1896 1894   * ill_mcast_qi                 ill_mcast_lock(WRITER)  ill_mcast_lock(READER)
1897 1895   *
1898 1896   * ill_down_mp                  ipsq                    ipsq
1899 1897   * ill_dlpi_deferred            ill_lock                ill_lock
1900 1898   * ill_dlpi_pending             ipsq + ill_lock         ipsq or ill_lock or
1901 1899   *                                                      absence of ipsq writer.
1902 1900   * ill_phys_addr_mp             ipsq + down ill         only when ill is up
1903 1901   * ill_mcast_deferred           ill_lock                ill_lock
1904 1902   * ill_phys_addr                ipsq + down ill         only when ill is up
1905 1903   * ill_dest_addr_mp             ipsq + down ill         only when ill is up
1906 1904   * ill_dest_addr                ipsq + down ill         only when ill is up
1907 1905   *
1908 1906   * ill_state_flags              ill_lock                ill_lock
1909 1907   * exclusive bit flags          ipsq_t                  ipsq_t
1910 1908   * shared bit flags             ill_lock                ill_lock
1911 1909   *
1912 1910   * ill_muxid                    ipsq                    Not atomic
1913 1911   *
1914 1912   * ill_ipf_gen                  Not atomic
1915 1913   * ill_frag_count               atomics                 atomics
1916 1914   * ill_type                     ipsq + down ill         only when ill is up
1917 1915   * ill_dlpi_multicast_state     ill_lock                ill_lock
1918 1916   * ill_dlpi_fastpath_state      ill_lock                ill_lock
1919 1917   * ill_dlpi_capab_state         ipsq                    ipsq
1920 1918   * ill_max_hops                 ipsq                    Not atomic
1921 1919   *
1922 1920   * ill_mtu                      ill_lock                None
1923 1921   * ill_mc_mtu                   ill_lock                None
1924 1922   *
1925 1923   * ill_user_mtu                 ipsq + ill_lock         ill_lock
1926 1924   * ill_reachable_time           ipsq + ill_lock         ill_lock
1927 1925   * ill_reachable_retrans_time   ipsq + ill_lock         ill_lock
1928 1926   * ill_max_buf                  ipsq + ill_lock         ill_lock
1929 1927   *
1930 1928   * Next 2 fields need ill_lock because of the get ioctls. They should not
1931 1929   * report partially updated results without executing in the ipsq.
1932 1930   * ill_token                    ipsq + ill_lock         ill_lock
1933 1931   * ill_token_length             ipsq + ill_lock         ill_lock
1934 1932   * ill_dest_token               ipsq + down ill         only when ill is up
1935 1933   * ill_xmit_count               ipsq + down ill         write once
1936 1934   * ill_ip6_mib                  ipsq + down ill         only when ill is up
1937 1935   * ill_icmp6_mib                ipsq + down ill         only when ill is up
1938 1936   *
1939 1937   * ill_phyint                   ipsq, ill_g_lock, ill_lock      Any of them
1940 1938   * ill_flags                    ill_lock                ill_lock
1941 1939   * ill_nd_lla_mp                ipsq + down ill         only when ill is up
1942 1940   * ill_nd_lla                   ipsq + down ill         only when ill is up
1943 1941   * ill_nd_lla_len               ipsq + down ill         only when ill is up
1944 1942   * ill_phys_addr_pend           ipsq + down ill         only when ill is up
1945 1943   * ill_ifname_pending_err       ipsq                    ipsq
1946 1944   * ill_dl_bind_err              ipsq                    ipsq
1947 1945   * ill_avl_byppa                ipsq, ill_g_lock        write once
1948 1946   *
1949 1947   * ill_fastpath_list            ill_lock                ill_lock
1950 1948   * ill_refcnt                   ill_lock                ill_lock
1951 1949   * ill_ire_cnt                  ill_lock                ill_lock
1952 1950   * ill_cv                       ill_lock                ill_lock
1953 1951   * ill_mcast_nces               ill_lock                ill_lock
1954 1952   * ill_ncec_cnt                 ill_lock                ill_lock
1955 1953   * ill_nce_cnt                  ill_lock                ill_lock
1956 1954   * ill_ilm_cnt                  ill_lock                ill_lock
1957 1955   * ill_src_ipif                 ill_g_lock              ill_g_lock
1958 1956   * ill_trace                    ill_lock                ill_lock
1959 1957   * ill_usesrc_grp_next          ill_g_usesrc_lock       ill_g_usesrc_lock
1960 1958   * ill_dhcpinit                 atomics                 atomics
1961 1959   * ill_flownotify_mh            write once              write once
1962 1960   * ill_capab_pending_cnt        ipsq                    ipsq
1963 1961   * ill_ipallmulti_cnt           ill_lock                ill_lock
1964 1962   * ill_ipallmulti_ilm           ill_lock                ill_lock
1965 1963   * ill_saved_ire_mp             ill_saved_ire_lock      ill_saved_ire_lock
1966 1964   * ill_saved_ire_cnt            ill_saved_ire_lock      ill_saved_ire_lock
1967 1965   * ill_arl                      ???                     ???
1968 1966   * ill_ire_multicast            ipsq + quiescent        none
1969 1967   * ill_bound_ipif               ipsq                    ipsq
1970 1968   * ill_actnode                  ipsq + ipmp_lock        ipsq OR ipmp_lock
1971 1969   * ill_grpnode                  ipsq + ill_g_lock       ipsq OR ill_g_lock
1972 1970   * ill_src_ipif                 ill_g_lock              ill_g_lock
1973 1971   * ill_move_ipif                ipsq                    ipsq
1974 1972   * ill_nom_cast                 ipsq                    ipsq OR advisory
1975 1973   * ill_refresh_tid              ill_lock                ill_lock
1976 1974   * ill_grp (for IPMP ill)       write once              write once
1977 1975   * ill_grp (for underlying ill) ipsq + ill_g_lock       ipsq OR ill_g_lock
1978 1976   * ill_grp_pending              ill_mcast_serializer    ill_mcast_serializer
1979 1977   * ill_mrouter_cnt              atomics                 atomics
1980 1978   * ill_mphysaddr_list   ill_lock                ill_lock
1981 1979   *
1982 1980   * NOTE: It's OK to make heuristic decisions on an underlying interface
1983 1981   *       by using IS_UNDER_IPMP() or comparing ill_grp's raw pointer value.
1984 1982   */
1985 1983  
1986 1984  /*
1987 1985   * For ioctl restart mechanism see ip_reprocess_ioctl()
1988 1986   */
1989 1987  struct ip_ioctl_cmd_s;
1990 1988  
1991 1989  typedef int (*ifunc_t)(ipif_t *, struct sockaddr_in *, queue_t *, mblk_t *,
1992 1990      struct ip_ioctl_cmd_s *, void *);
1993 1991  
1994 1992  typedef struct ip_ioctl_cmd_s {
1995 1993          int     ipi_cmd;
1996 1994          size_t  ipi_copyin_size;
1997 1995          uint_t  ipi_flags;
1998 1996          uint_t  ipi_cmd_type;
1999 1997          ifunc_t ipi_func;
2000 1998          ifunc_t ipi_func_restart;
2001 1999  } ip_ioctl_cmd_t;
2002 2000  
2003 2001  /*
2004 2002   * ipi_cmd_type:
2005 2003   *
2006 2004   * IF_CMD               1       old style ifreq cmd
2007 2005   * LIF_CMD              2       new style lifreq cmd
2008 2006   * ARP_CMD              3       arpreq cmd
2009 2007   * XARP_CMD             4       xarpreq cmd
2010 2008   * MSFILT_CMD           5       multicast source filter cmd
2011 2009   * MISC_CMD             6       misc cmd (not a more specific one above)
2012 2010   */
2013 2011  
2014 2012  enum { IF_CMD = 1, LIF_CMD, ARP_CMD, XARP_CMD, MSFILT_CMD, MISC_CMD };
2015 2013  
2016 2014  #define IPI_DONTCARE    0       /* For ioctl encoded values that don't matter */
2017 2015  
2018 2016  /* Flag values in ipi_flags */
2019 2017  #define IPI_PRIV        0x1     /* Root only command */
2020 2018  #define IPI_MODOK       0x2     /* Permitted on mod instance of IP */
2021 2019  #define IPI_WR          0x4     /* Need to grab writer access */
2022 2020  #define IPI_GET_CMD     0x8     /* branch to mi_copyout on success */
2023 2021  /*      unused          0x10    */
2024 2022  #define IPI_NULL_BCONT  0x20    /* ioctl has not data and hence no b_cont */
2025 2023  
2026 2024  extern ip_ioctl_cmd_t   ip_ndx_ioctl_table[];
2027 2025  extern ip_ioctl_cmd_t   ip_misc_ioctl_table[];
2028 2026  extern int ip_ndx_ioctl_count;
2029 2027  extern int ip_misc_ioctl_count;
2030 2028  
2031 2029  /* Passed down by ARP to IP during I_PLINK/I_PUNLINK */
2032 2030  typedef struct ipmx_s {
2033 2031          char    ipmx_name[LIFNAMSIZ];           /* if name */
2034 2032          uint_t
2035 2033                  ipmx_arpdev_stream : 1,         /* This is the arp stream */
2036 2034                  ipmx_notused : 31;
2037 2035  } ipmx_t;
2038 2036  
2039 2037  /*
2040 2038   * State for detecting if a driver supports certain features.
2041 2039   * Support for DL_ENABMULTI_REQ uses ill_dlpi_multicast_state.
2042 2040   * Support for DLPI M_DATA fastpath uses ill_dlpi_fastpath_state.
2043 2041   */
2044 2042  #define IDS_UNKNOWN     0       /* No DLPI request sent */
2045 2043  #define IDS_INPROGRESS  1       /* DLPI request sent */
2046 2044  #define IDS_OK          2       /* DLPI request completed successfully */
2047 2045  #define IDS_FAILED      3       /* DLPI request failed */
2048 2046  
2049 2047  /* Support for DL_CAPABILITY_REQ uses ill_dlpi_capab_state. */
2050 2048  enum {
2051 2049          IDCS_UNKNOWN,
2052 2050          IDCS_PROBE_SENT,
2053 2051          IDCS_OK,
2054 2052          IDCS_RESET_SENT,
2055 2053          IDCS_RENEG,
2056 2054          IDCS_FAILED
2057 2055  };
2058 2056  
2059 2057  /* Extended NDP Management Structure */
2060 2058  typedef struct ipndp_s {
2061 2059          ndgetf_t        ip_ndp_getf;
2062 2060          ndsetf_t        ip_ndp_setf;
2063 2061          caddr_t         ip_ndp_data;
2064 2062          char            *ip_ndp_name;
2065 2063  } ipndp_t;
2066 2064  
2067 2065  /* IXA Notification types */
2068 2066  typedef enum {
2069 2067          IXAN_LSO,       /* LSO capability change */
2070 2068          IXAN_PMTU,      /* PMTU change */
2071 2069          IXAN_ZCOPY      /* ZEROCOPY capability change */
2072 2070  } ixa_notify_type_t;
2073 2071  
2074 2072  typedef uint_t ixa_notify_arg_t;
2075 2073  
2076 2074  typedef void    (*ixa_notify_t)(void *, ip_xmit_attr_t *ixa, ixa_notify_type_t,
2077 2075      ixa_notify_arg_t);
2078 2076  
2079 2077  /*
2080 2078   * Attribute flags that are common to the transmit and receive attributes
2081 2079   */
2082 2080  #define IAF_IS_IPV4             0x80000000      /* ipsec_*_v4 */
2083 2081  #define IAF_TRUSTED_ICMP        0x40000000      /* ipsec_*_icmp_loopback */
2084 2082  #define IAF_NO_LOOP_ZONEID_SET  0x20000000      /* Zone that shouldn't have */
2085 2083                                                  /* a copy */
2086 2084  #define IAF_LOOPBACK_COPY       0x10000000      /* For multi and broadcast */
2087 2085  
2088 2086  #define IAF_MASK                0xf0000000      /* Flags that are common */
2089 2087  
2090 2088  /*
2091 2089   * Transmit side attributes used between the transport protocols and IP as
2092 2090   * well as inside IP. It is also used to cache information in the conn_t i.e.
2093 2091   * replaces conn_ire and the IPsec caching in the conn_t.
2094 2092   */
2095 2093  struct ip_xmit_attr_s {
2096 2094          iaflags_t       ixa_flags;      /* IXAF_*. See below */
2097 2095  
2098 2096          uint32_t        ixa_free_flags; /* IXA_FREE_*. See below */
2099 2097          uint32_t        ixa_refcnt;     /* Using atomics */
2100 2098  
2101 2099          /*
2102 2100           * Always initialized independently of ixa_flags settings.
2103 2101           * Used by ip_xmit so we keep them up front for cache locality.
2104 2102           */
2105 2103          uint32_t        ixa_xmit_hint;  /* For ECMP and GLD TX ring fanout */
2106 2104          uint_t          ixa_pktlen;     /* Always set. For frag and stats */
2107 2105          zoneid_t        ixa_zoneid;     /* Assumed always set */
2108 2106  
2109 2107          /* Always set for conn_ip_output(); might be stale */
2110 2108          /*
2111 2109           * Since TCP keeps the conn_t around past the process going away
2112 2110           * we need to use the "notr" (e.g, ire_refhold_notr) for ixa_ire,
2113 2111           * ixa_nce, and ixa_dce.
2114 2112           */
2115 2113          ire_t           *ixa_ire;       /* Forwarding table entry */
2116 2114          uint_t          ixa_ire_generation;
2117 2115          nce_t           *ixa_nce;       /* Neighbor cache entry */
2118 2116          dce_t           *ixa_dce;       /* Destination cache entry */
2119 2117          uint_t          ixa_dce_generation;
2120 2118          uint_t          ixa_src_generation;     /* If IXAF_VERIFY_SOURCE */
2121 2119  
2122 2120          uint32_t        ixa_src_preferences;    /* prefs for src addr select */
2123 2121          uint32_t        ixa_pmtu;               /* IXAF_VERIFY_PMTU */
2124 2122  
2125 2123          /* Set by ULP if IXAF_VERIFY_PMTU; otherwise set by IP */
2126 2124          uint32_t        ixa_fragsize;
2127 2125  
2128 2126          int8_t          ixa_use_min_mtu;        /* IXAF_USE_MIN_MTU values */
2129 2127  
2130 2128          pfirepostfrag_t ixa_postfragfn;         /* Set internally in IP */
2131 2129  
2132 2130          in6_addr_t      ixa_nexthop_v6;         /* IXAF_NEXTHOP_SET */
2133 2131  #define ixa_nexthop_v4  V4_PART_OF_V6(ixa_nexthop_v6)
2134 2132  
2135 2133          zoneid_t        ixa_no_loop_zoneid;     /* IXAF_NO_LOOP_ZONEID_SET */
2136 2134  
2137 2135          uint_t          ixa_scopeid;            /* For IPv6 link-locals */
2138 2136  
2139 2137          uint_t          ixa_broadcast_ttl;      /* IXAF_BROACAST_TTL_SET */
2140 2138  
2141 2139          uint_t          ixa_multicast_ttl;      /* Assumed set for multicast */
2142 2140          uint_t          ixa_multicast_ifindex;  /* Assumed set for multicast */
2143 2141          ipaddr_t        ixa_multicast_ifaddr;   /* Assumed set for multicast */
2144 2142  
2145 2143          int             ixa_raw_cksum_offset;   /* If IXAF_SET_RAW_CKSUM */
2146 2144  
2147 2145          uint32_t        ixa_ident;              /* For IPv6 fragment header */
2148 2146  
2149 2147          uint64_t        ixa_conn_id;            /* Used by DTrace */
2150 2148          /*
2151 2149           * Cached LSO information.
2152 2150           */
2153 2151          ill_lso_capab_t ixa_lso_capab;          /* Valid when IXAF_LSO_CAPAB */
2154 2152  
2155 2153          uint64_t        ixa_ipsec_policy_gen;   /* Generation from iph_gen */
2156 2154          /*
2157 2155           * The following IPsec fields are only initialized when
2158 2156           * IXAF_IPSEC_SECURE is set. Otherwise they contain garbage.
2159 2157           */
2160 2158          ipsec_latch_t   *ixa_ipsec_latch;       /* Just the ids */
2161 2159          struct ipsa_s   *ixa_ipsec_ah_sa;       /* Hard reference SA for AH */
2162 2160          struct ipsa_s   *ixa_ipsec_esp_sa;      /* Hard reference SA for ESP */
2163 2161          struct ipsec_policy_s   *ixa_ipsec_policy; /* why are we here? */
2164 2162          struct ipsec_action_s   *ixa_ipsec_action; /* For reflected packets */
2165 2163          ipsa_ref_t      ixa_ipsec_ref[2];       /* Soft reference to SA */
2166 2164                                                  /* 0: ESP, 1: AH */
2167 2165  
2168 2166          /*
2169 2167           * The selectors here are potentially different than the SPD rule's
2170 2168           * selectors, and we need to have both available for IKEv2.
2171 2169           *
2172 2170           * NOTE: "Source" and "Dest" are w.r.t. outbound datagrams.  Ports can
2173 2171           *       be zero, and the protocol number is needed to make the ports
2174 2172           *       significant.
2175 2173           */
2176 2174          uint16_t ixa_ipsec_src_port;    /* Source port number of d-gram. */
2177 2175          uint16_t ixa_ipsec_dst_port;    /* Destination port number of d-gram. */
2178 2176          uint8_t  ixa_ipsec_icmp_type;   /* ICMP type of d-gram */
2179 2177          uint8_t  ixa_ipsec_icmp_code;   /* ICMP code of d-gram */
2180 2178  
2181 2179          sa_family_t ixa_ipsec_inaf;     /* Inner address family */
2182 2180  #define IXA_MAX_ADDRLEN 4       /* Max addr len. (in 32-bit words) */
2183 2181          uint32_t ixa_ipsec_insrc[IXA_MAX_ADDRLEN];      /* Inner src address */
2184 2182          uint32_t ixa_ipsec_indst[IXA_MAX_ADDRLEN];      /* Inner dest address */
2185 2183          uint8_t  ixa_ipsec_insrcpfx;    /* Inner source prefix */
2186 2184          uint8_t  ixa_ipsec_indstpfx;    /* Inner destination prefix */
2187 2185  
2188 2186          uint8_t ixa_ipsec_proto;        /* IP protocol number for d-gram. */
2189 2187  
2190 2188          /* Always initialized independently of ixa_flags settings */
2191 2189          uint_t          ixa_ifindex;    /* Assumed always set */
2192 2190          uint16_t        ixa_ip_hdr_length; /* Points to ULP header */
2193 2191          uint8_t         ixa_protocol;   /* Protocol number for ULP cksum */
2194 2192          ts_label_t      *ixa_tsl;       /* Always set. NULL if not TX */
2195 2193          ip_stack_t      *ixa_ipst;      /* Always set */
2196 2194          uint32_t        ixa_extra_ident; /* Set if LSO */
2197 2195          cred_t          *ixa_cred;      /* For getpeerucred */
2198 2196          pid_t           ixa_cpid;       /* For getpeerucred */
2199 2197  
2200 2198  #ifdef DEBUG
2201 2199          kthread_t       *ixa_curthread; /* For serialization assert */
2202 2200  #endif
2203 2201          squeue_t        *ixa_sqp;       /* Set from conn_sqp as a hint */
2204 2202          uintptr_t       ixa_cookie;     /* cookie to use for tx flow control */
2205 2203  
2206 2204          /*
2207 2205           * Must be set by ULP if any of IXAF_VERIFY_LSO, IXAF_VERIFY_PMTU,
2208 2206           * or IXAF_VERIFY_ZCOPY is set.
2209 2207           */
2210 2208          ixa_notify_t    ixa_notify;     /* Registered upcall notify function */
2211 2209          void            *ixa_notify_cookie; /* ULP cookie for ixa_notify */
2212 2210  
2213 2211          uint_t          ixa_tcpcleanup; /* Used by conn_ixa_cleanup */
2214 2212  };
2215 2213  
2216 2214  /*
2217 2215   * Flags to indicate which transmit attributes are set.
2218 2216   * Split into "xxx_SET" ones which indicate that the "xxx" field it set, and
2219 2217   * single flags.
2220 2218   */
2221 2219  #define IXAF_REACH_CONF         0x00000001      /* Reachability confirmation */
2222 2220  #define IXAF_BROADCAST_TTL_SET  0x00000002      /* ixa_broadcast_ttl valid */
2223 2221  #define IXAF_SET_SOURCE         0x00000004      /* Replace if broadcast */
2224 2222  #define IXAF_USE_MIN_MTU        0x00000008      /* IPV6_USE_MIN_MTU */
2225 2223  
2226 2224  #define IXAF_DONTFRAG           0x00000010      /* IP*_DONTFRAG */
2227 2225  #define IXAF_VERIFY_PMTU        0x00000020      /* ixa_pmtu/ixa_fragsize set */
2228 2226  #define IXAF_PMTU_DISCOVERY     0x00000040      /* Create/use PMTU state */
2229 2227  #define IXAF_MULTICAST_LOOP     0x00000080      /* IP_MULTICAST_LOOP */
2230 2228  
2231 2229  #define IXAF_IPSEC_SECURE       0x00000100      /* Need IPsec processing */
2232 2230  #define IXAF_UCRED_TSL          0x00000200      /* ixa_tsl from SCM_UCRED */
2233 2231  #define IXAF_DONTROUTE          0x00000400      /* SO_DONTROUTE */
2234 2232  #define IXAF_NO_IPSEC           0x00000800      /* Ignore policy */
2235 2233  
2236 2234  #define IXAF_PMTU_TOO_SMALL     0x00001000      /* PMTU too small */
2237 2235  #define IXAF_SET_ULP_CKSUM      0x00002000      /* Calculate ULP checksum */
2238 2236  #define IXAF_VERIFY_SOURCE      0x00004000      /* Check that source is ok */
2239 2237  #define IXAF_NEXTHOP_SET        0x00008000      /* ixa_nexthop set */
2240 2238  
2241 2239  #define IXAF_PMTU_IPV4_DF       0x00010000      /* Set IPv4 DF */
2242 2240  #define IXAF_NO_DEV_FLOW_CTL    0x00020000      /* Protocol needs no flow ctl */
2243 2241  #define IXAF_NO_TTL_CHANGE      0x00040000      /* Internal to IP */
2244 2242  #define IXAF_IPV6_ADD_FRAGHDR   0x00080000      /* Add fragment header */
2245 2243  
2246 2244  #define IXAF_IPSEC_TUNNEL       0x00100000      /* Tunnel mode */
2247 2245  #define IXAF_NO_PFHOOK          0x00200000      /* Skip xmit pfhook */
2248 2246  #define IXAF_NO_TRACE           0x00400000      /* When back from ARP/ND */
2249 2247  #define IXAF_SCOPEID_SET        0x00800000      /* ixa_scopeid set */
2250 2248  
2251 2249  #define IXAF_MULTIRT_MULTICAST  0x01000000      /* MULTIRT for multicast */
2252 2250  #define IXAF_NO_HW_CKSUM        0x02000000      /* Force software cksum */
2253 2251  #define IXAF_SET_RAW_CKSUM      0x04000000      /* Use ixa_raw_cksum_offset */
2254 2252  #define IXAF_IPSEC_GLOBAL_POLICY 0x08000000     /* Policy came from global */
2255 2253  
2256 2254  /* Note the following uses bits 0x10000000 through 0x80000000 */
2257 2255  #define IXAF_IS_IPV4            IAF_IS_IPV4
2258 2256  #define IXAF_TRUSTED_ICMP       IAF_TRUSTED_ICMP
2259 2257  #define IXAF_NO_LOOP_ZONEID_SET IAF_NO_LOOP_ZONEID_SET
2260 2258  #define IXAF_LOOPBACK_COPY      IAF_LOOPBACK_COPY
2261 2259  
2262 2260  /* Note: use the upper 32 bits */
2263 2261  #define IXAF_VERIFY_LSO         0x100000000     /* Check LSO capability */
2264 2262  #define IXAF_LSO_CAPAB          0x200000000     /* Capable of LSO */
2265 2263  #define IXAF_VERIFY_ZCOPY       0x400000000     /* Check Zero Copy capability */
2266 2264  #define IXAF_ZCOPY_CAPAB        0x800000000     /* Capable of ZEROCOPY */
2267 2265  
2268 2266  /*
2269 2267   * The normal flags for sending packets e.g., icmp errors
2270 2268   */
2271 2269  #define IXAF_BASIC_SIMPLE_V4    \
2272 2270          (IXAF_SET_ULP_CKSUM | IXAF_IS_IPV4 | IXAF_VERIFY_SOURCE)
2273 2271  #define IXAF_BASIC_SIMPLE_V6    (IXAF_SET_ULP_CKSUM | IXAF_VERIFY_SOURCE)
2274 2272  
2275 2273  /*
2276 2274   * Normally these fields do not have a hold. But in some cases they do, for
2277 2275   * instance when we've gone through ip_*_attr_to/from_mblk.
2278 2276   * We use ixa_free_flags to indicate that they have a hold and need to be
2279 2277   * released on cleanup.
2280 2278   */
2281 2279  #define IXA_FREE_CRED           0x00000001      /* ixa_cred needs to be rele */
2282 2280  #define IXA_FREE_TSL            0x00000002      /* ixa_tsl needs to be rele */
2283 2281  
2284 2282  /*
2285 2283   * Trivial state machine used to synchronize IXA cleanup for TCP connections.
2286 2284   * See conn_ixa_cleanup().
2287 2285   */
2288 2286  #define IXATC_IDLE              0x00000000
2289 2287  #define IXATC_INPROGRESS        0x00000001
2290 2288  #define IXATC_COMPLETE          0x00000002
2291 2289  
2292 2290  /*
2293 2291   * Simplistic way to set the ixa_xmit_hint for locally generated traffic
2294 2292   * and forwarded traffic. The shift amount are based on the size of the
2295 2293   * structs to discard the low order bits which don't have much if any variation
2296 2294   * (coloring in kmem_cache_alloc might provide some variation).
2297 2295   *
2298 2296   * Basing the locally generated hint on the address of the conn_t means that
2299 2297   * the packets from the same socket/connection do not get reordered.
2300 2298   * Basing the hint for forwarded traffic on the ill_ring_t means that
2301 2299   * packets from the same NIC+ring are likely to use the same outbound ring
2302 2300   * hence we get low contention on the ring in the transmitting driver.
2303 2301   */
2304 2302  #define CONN_TO_XMIT_HINT(connp)        ((uint32_t)(((uintptr_t)connp) >> 11))
2305 2303  #define ILL_RING_TO_XMIT_HINT(ring)     ((uint32_t)(((uintptr_t)ring) >> 7))
2306 2304  
2307 2305  /*
2308 2306   * IP set Destination Flags used by function ip_set_destination,
2309 2307   * ip_attr_connect, and conn_connect.
2310 2308   */
2311 2309  #define IPDF_ALLOW_MCBC         0x1     /* Allow multi/broadcast */
2312 2310  #define IPDF_VERIFY_DST         0x2     /* Verify destination addr */
2313 2311  #define IPDF_SELECT_SRC         0x4     /* Select source address */
2314 2312  #define IPDF_LSO                0x8     /* Try LSO */
2315 2313  #define IPDF_IPSEC              0x10    /* Set IPsec policy */
2316 2314  #define IPDF_ZONE_IS_GLOBAL     0x20    /* From conn_zone_is_global */
2317 2315  #define IPDF_ZCOPY              0x40    /* Try ZEROCOPY */
2318 2316  #define IPDF_UNIQUE_DCE         0x80    /* Get a per-destination DCE */
2319 2317  
2320 2318  /*
2321 2319   * Receive side attributes used between the transport protocols and IP as
2322 2320   * well as inside IP.
2323 2321   */
2324 2322  struct ip_recv_attr_s {
2325 2323          iaflags_t       ira_flags;      /* See below */
2326 2324  
2327 2325          uint32_t        ira_free_flags; /* IRA_FREE_*. See below */
2328 2326  
2329 2327          /*
2330 2328           * This is a hint for TCP SYN packets.
2331 2329           * Always initialized independently of ira_flags settings
2332 2330           */
2333 2331          squeue_t        *ira_sqp;
2334 2332          ill_rx_ring_t   *ira_ring;      /* Internal to IP */
2335 2333  
2336 2334          /* For ip_accept_tcp when IRAF_TARGET_SQP is set */
2337 2335          squeue_t        *ira_target_sqp;
2338 2336          mblk_t          *ira_target_sqp_mp;
2339 2337  
2340 2338          /* Always initialized independently of ira_flags settings */
2341 2339          uint32_t        ira_xmit_hint;  /* For ECMP and GLD TX ring fanout */
2342 2340          zoneid_t        ira_zoneid;     /* ALL_ZONES unless local delivery */
2343 2341          uint_t          ira_pktlen;     /* Always set. For frag and stats */
2344 2342          uint16_t        ira_ip_hdr_length; /* Points to ULP header */
2345 2343          uint8_t         ira_protocol;   /* Protocol number for ULP cksum */
2346 2344          uint_t          ira_rifindex;   /* Received ifindex */
2347 2345          uint_t          ira_ruifindex;  /* Received upper ifindex */
2348 2346          ts_label_t      *ira_tsl;       /* Always set. NULL if not TX */
2349 2347          /*
2350 2348           * ira_rill and ira_ill is set inside IP, but not when conn_recv is
2351 2349           * called; ULPs should use ira_ruifindex instead.
2352 2350           */
2353 2351          ill_t           *ira_rill;      /* ill where packet came */
2354 2352          ill_t           *ira_ill;       /* ill where IP address hosted */
2355 2353          cred_t          *ira_cred;      /* For getpeerucred */
2356 2354          pid_t           ira_cpid;       /* For getpeerucred */
2357 2355  
2358 2356          /* Used when IRAF_VERIFIED_SRC is set; this source was ok */
2359 2357          ipaddr_t        ira_verified_src;
2360 2358  
2361 2359          /*
2362 2360           * The following IPsec fields are only initialized when
2363 2361           * IRAF_IPSEC_SECURE is set. Otherwise they contain garbage.
2364 2362           */
2365 2363          struct ipsec_action_s *ira_ipsec_action; /* how we made it in.. */
2366 2364          struct ipsa_s   *ira_ipsec_ah_sa;       /* SA for AH */
2367 2365          struct ipsa_s   *ira_ipsec_esp_sa;      /* SA for ESP */
2368 2366  
2369 2367          ipaddr_t        ira_mroute_tunnel;      /* IRAF_MROUTE_TUNNEL_SET */
2370 2368  
2371 2369          zoneid_t        ira_no_loop_zoneid;     /* IRAF_NO_LOOP_ZONEID_SET */
2372 2370  
2373 2371          uint32_t        ira_esp_udp_ports;      /* IRAF_ESP_UDP_PORTS */
2374 2372  
2375 2373          /*
2376 2374           * For IP_RECVSLLA and ip_ndp_conflict/find_solicitation.
2377 2375           * Same size as max for sockaddr_dl
2378 2376           */
2379 2377  #define IRA_L2SRC_SIZE  244
2380 2378          uint8_t         ira_l2src[IRA_L2SRC_SIZE];      /* If IRAF_L2SRC_SET */
2381 2379  
2382 2380          /*
2383 2381           * Local handle that we use to do lazy setting of ira_l2src.
2384 2382           * We defer setting l2src until needed but we do before any
2385 2383           * ip_input pullupmsg or copymsg.
2386 2384           */
2387 2385          struct mac_header_info_s *ira_mhip;     /* Could be NULL */
2388 2386  };
2389 2387  
2390 2388  /*
2391 2389   * Flags to indicate which receive attributes are set.
2392 2390   */
2393 2391  #define IRAF_SYSTEM_LABELED     0x00000001      /* is_system_labeled() */
2394 2392  #define IRAF_IPV4_OPTIONS       0x00000002      /* Performance */
2395 2393  #define IRAF_MULTICAST          0x00000004      /* Was multicast at L3 */
2396 2394  #define IRAF_BROADCAST          0x00000008      /* Was broadcast at L3 */
2397 2395  #define IRAF_MULTIBROADCAST     (IRAF_MULTICAST|IRAF_BROADCAST)
2398 2396  
2399 2397  #define IRAF_LOOPBACK           0x00000010      /* Looped back by IP */
2400 2398  #define IRAF_VERIFY_IP_CKSUM    0x00000020      /* Need to verify IP */
2401 2399  #define IRAF_VERIFY_ULP_CKSUM   0x00000040      /* Need to verify TCP,UDP,etc */
2402 2400  #define IRAF_SCTP_CSUM_ERR      0x00000080      /* sctp pkt has failed chksum */
2403 2401  
2404 2402  #define IRAF_IPSEC_SECURE       0x00000100      /* Passed AH and/or ESP */
2405 2403  #define IRAF_DHCP_UNICAST       0x00000200
2406 2404  #define IRAF_IPSEC_DECAPS       0x00000400      /* Was packet decapsulated */
2407 2405                                          /* from a matching inner packet? */
2408 2406  #define IRAF_TARGET_SQP         0x00000800      /* ira_target_sqp is set */
2409 2407  #define IRAF_VERIFIED_SRC       0x00001000      /* ira_verified_src set */
2410 2408  #define IRAF_RSVP               0x00002000      /* RSVP packet for rsvpd */
2411 2409  #define IRAF_MROUTE_TUNNEL_SET  0x00004000      /* From ip_mroute_decap */
2412 2410  #define IRAF_PIM_REGISTER       0x00008000      /* From register_mforward */
2413 2411  
2414 2412  #define IRAF_TX_MAC_EXEMPTABLE  0x00010000      /* Allow MAC_EXEMPT readdown */
2415 2413  #define IRAF_TX_SHARED_ADDR     0x00020000      /* Arrived on ALL_ZONES addr */
2416 2414  #define IRAF_ESP_UDP_PORTS      0x00040000      /* NAT-traversal packet */
2417 2415  #define IRAF_NO_HW_CKSUM        0x00080000      /* Force software cksum */
2418 2416  
2419 2417  #define IRAF_ICMP_ERROR         0x00100000      /* Send to conn_recvicmp */
2420 2418  #define IRAF_ROUTER_ALERT       0x00200000      /* IPv6 router alert */
2421 2419  #define IRAF_L2SRC_SET          0x00400000      /* ira_l2src has been set */
2422 2420  #define IRAF_L2SRC_LOOPBACK     0x00800000      /* Came from us */
2423 2421  
2424 2422  #define IRAF_L2DST_MULTICAST    0x01000000      /* Multicast at L2 */
2425 2423  #define IRAF_L2DST_BROADCAST    0x02000000      /* Broadcast at L2 */
2426 2424  /* Unused 0x04000000 */
2427 2425  /* Unused 0x08000000 */
2428 2426  
2429 2427  /* Below starts with 0x10000000 */
2430 2428  #define IRAF_IS_IPV4            IAF_IS_IPV4
2431 2429  #define IRAF_TRUSTED_ICMP       IAF_TRUSTED_ICMP
2432 2430  #define IRAF_NO_LOOP_ZONEID_SET IAF_NO_LOOP_ZONEID_SET
2433 2431  #define IRAF_LOOPBACK_COPY      IAF_LOOPBACK_COPY
2434 2432  
2435 2433  /*
2436 2434   * Normally these fields do not have a hold. But in some cases they do, for
2437 2435   * instance when we've gone through ip_*_attr_to/from_mblk.
2438 2436   * We use ira_free_flags to indicate that they have a hold and need to be
2439 2437   * released on cleanup.
2440 2438   */
2441 2439  #define IRA_FREE_CRED           0x00000001      /* ira_cred needs to be rele */
2442 2440  #define IRA_FREE_TSL            0x00000002      /* ira_tsl needs to be rele */
2443 2441  
2444 2442  /*
2445 2443   * Optional destination cache entry for path MTU information,
2446 2444   * and ULP metrics.
2447 2445   */
2448 2446  struct dce_s {
2449 2447          uint_t          dce_generation; /* Changed since cached? */
2450 2448          uint_t          dce_flags;      /* See below */
2451 2449          uint_t          dce_ipversion;  /* IPv4/IPv6 version */
2452 2450          uint32_t        dce_pmtu;       /* Path MTU if DCEF_PMTU */
2453 2451          uint32_t        dce_ident;      /* Per destination IP ident. */
2454 2452          iulp_t          dce_uinfo;      /* Metrics if DCEF_UINFO */
2455 2453  
2456 2454          struct dce_s    *dce_next;
2457 2455          struct dce_s    **dce_ptpn;
2458 2456          struct dcb_s    *dce_bucket;
2459 2457  
2460 2458          union {
2461 2459                  in6_addr_t      dceu_v6addr;
2462 2460                  ipaddr_t        dceu_v4addr;
2463 2461          } dce_u;
2464 2462  #define dce_v4addr      dce_u.dceu_v4addr
2465 2463  #define dce_v6addr      dce_u.dceu_v6addr
2466 2464          /* Note that for IPv6+IPMP we use the ifindex for the upper interface */
2467 2465          uint_t          dce_ifindex;    /* For IPv6 link-locals */
2468 2466  
2469 2467          kmutex_t        dce_lock;
2470 2468          uint_t          dce_refcnt;
2471 2469          uint64_t        dce_last_change_time;   /* Path MTU. In seconds */
2472 2470  
2473 2471          ip_stack_t      *dce_ipst;      /* Does not have a netstack_hold */
2474 2472  };
2475 2473  
2476 2474  /*
2477 2475   * Values for dce_generation.
2478 2476   *
2479 2477   * If a DCE has DCE_GENERATION_CONDEMNED, the last dce_refrele should delete
2480 2478   * it.
2481 2479   *
2482 2480   * DCE_GENERATION_VERIFY is never stored in dce_generation but it is
2483 2481   * stored in places that cache DCE (such as ixa_dce_generation).
2484 2482   * It is used as a signal that the cache is stale and needs to be reverified.
2485 2483   */
2486 2484  #define DCE_GENERATION_CONDEMNED        0
2487 2485  #define DCE_GENERATION_VERIFY           1
2488 2486  #define DCE_GENERATION_INITIAL          2
2489 2487  #define DCE_IS_CONDEMNED(dce) \
2490 2488          ((dce)->dce_generation == DCE_GENERATION_CONDEMNED)
2491 2489  
2492 2490  
2493 2491  /*
2494 2492   * Values for ips_src_generation.
2495 2493   *
2496 2494   * SRC_GENERATION_VERIFY is never stored in ips_src_generation but it is
2497 2495   * stored in places that cache IREs (ixa_src_generation). It is used as a
2498 2496   * signal that the cache is stale and needs to be reverified.
2499 2497   */
2500 2498  #define SRC_GENERATION_VERIFY           0
2501 2499  #define SRC_GENERATION_INITIAL          1
2502 2500  
2503 2501  /*
2504 2502   * The kernel stores security attributes of all gateways in a database made
2505 2503   * up of one or more tsol_gcdb_t elements.  Each tsol_gcdb_t contains the
2506 2504   * security-related credentials of the gateway.  More than one gateways may
2507 2505   * share entries in the database.
2508 2506   *
2509 2507   * The tsol_gc_t structure represents the gateway to credential association,
2510 2508   * and refers to an entry in the database.  One or more tsol_gc_t entities are
2511 2509   * grouped together to form one or more tsol_gcgrp_t, each representing the
2512 2510   * list of security attributes specific to the gateway.  A gateway may be
2513 2511   * associated with at most one credentials group.
2514 2512   */
2515 2513  struct tsol_gcgrp_s;
2516 2514  
2517 2515  extern uchar_t  ip6opt_ls;      /* TX IPv6 enabler */
2518 2516  
2519 2517  /*
2520 2518   * Gateway security credential record.
2521 2519   */
2522 2520  typedef struct tsol_gcdb_s {
2523 2521          uint_t          gcdb_refcnt;    /* reference count */
2524 2522          struct rtsa_s   gcdb_attr;      /* security attributes */
2525 2523  #define gcdb_mask       gcdb_attr.rtsa_mask
2526 2524  #define gcdb_doi        gcdb_attr.rtsa_doi
2527 2525  #define gcdb_slrange    gcdb_attr.rtsa_slrange
2528 2526  } tsol_gcdb_t;
2529 2527  
2530 2528  /*
2531 2529   * Gateway to credential association.
2532 2530   */
2533 2531  typedef struct tsol_gc_s {
2534 2532          uint_t          gc_refcnt;      /* reference count */
2535 2533          struct tsol_gcgrp_s *gc_grp;    /* pointer to group */
2536 2534          struct tsol_gc_s *gc_prev;      /* previous in list */
2537 2535          struct tsol_gc_s *gc_next;      /* next in list */
2538 2536          tsol_gcdb_t     *gc_db;         /* pointer to actual credentials */
2539 2537  } tsol_gc_t;
2540 2538  
2541 2539  /*
2542 2540   * Gateway credentials group address.
2543 2541   */
2544 2542  typedef struct tsol_gcgrp_addr_s {
2545 2543          int             ga_af;          /* address family */
2546 2544          in6_addr_t      ga_addr;        /* IPv4 mapped or IPv6 address */
2547 2545  } tsol_gcgrp_addr_t;
2548 2546  
2549 2547  /*
2550 2548   * Gateway credentials group.
2551 2549   */
2552 2550  typedef struct tsol_gcgrp_s {
2553 2551          uint_t          gcgrp_refcnt;   /* reference count */
2554 2552          krwlock_t       gcgrp_rwlock;   /* lock to protect following */
2555 2553          uint_t          gcgrp_count;    /* number of credentials */
2556 2554          tsol_gc_t       *gcgrp_head;    /* first credential in list */
2557 2555          tsol_gc_t       *gcgrp_tail;    /* last credential in list */
2558 2556          tsol_gcgrp_addr_t gcgrp_addr;   /* next-hop gateway address */
2559 2557  } tsol_gcgrp_t;
2560 2558  
2561 2559  extern kmutex_t gcgrp_lock;
2562 2560  
2563 2561  #define GC_REFRELE(p) {                         \
2564 2562          ASSERT((p)->gc_grp != NULL);            \
2565 2563          rw_enter(&(p)->gc_grp->gcgrp_rwlock, RW_WRITER); \
2566 2564          ASSERT((p)->gc_refcnt > 0);             \
2567 2565          if (--((p)->gc_refcnt) == 0)            \
2568 2566                  gc_inactive(p);                 \
2569 2567          else                                    \
2570 2568                  rw_exit(&(p)->gc_grp->gcgrp_rwlock); \
2571 2569  }
2572 2570  
2573 2571  #define GCGRP_REFHOLD(p) {                      \
2574 2572          mutex_enter(&gcgrp_lock);               \
2575 2573          ++((p)->gcgrp_refcnt);                  \
2576 2574          ASSERT((p)->gcgrp_refcnt != 0);         \
2577 2575          mutex_exit(&gcgrp_lock);                \
2578 2576  }
2579 2577  
2580 2578  #define GCGRP_REFRELE(p) {                      \
2581 2579          mutex_enter(&gcgrp_lock);               \
2582 2580          ASSERT((p)->gcgrp_refcnt > 0);          \
2583 2581          if (--((p)->gcgrp_refcnt) == 0)         \
2584 2582                  gcgrp_inactive(p);              \
2585 2583          ASSERT(MUTEX_HELD(&gcgrp_lock));        \
2586 2584          mutex_exit(&gcgrp_lock);                \
2587 2585  }
2588 2586  
2589 2587  /*
2590 2588   * IRE gateway security attributes structure, pointed to by tsol_ire_gw_secattr
2591 2589   */
2592 2590  struct tsol_tnrhc;
2593 2591  
2594 2592  struct tsol_ire_gw_secattr_s {
2595 2593          kmutex_t        igsa_lock;      /* lock to protect following */
2596 2594          struct tsol_tnrhc *igsa_rhc;    /* host entry for gateway */
2597 2595          tsol_gc_t       *igsa_gc;       /* for prefix IREs */
2598 2596  };
2599 2597  
2600 2598  void irb_refrele_ftable(irb_t *);
2601 2599  
2602 2600  extern struct kmem_cache *rt_entry_cache;
2603 2601  
2604 2602  typedef struct ire4 {
2605 2603          ipaddr_t ire4_mask;             /* Mask for matching this IRE. */
2606 2604          ipaddr_t ire4_addr;             /* Address this IRE represents. */
2607 2605          ipaddr_t ire4_gateway_addr;     /* Gateway including for IRE_ONLINK */
2608 2606          ipaddr_t ire4_setsrc_addr;      /* RTF_SETSRC */
2609 2607  } ire4_t;
2610 2608  
2611 2609  typedef struct ire6 {
2612 2610          in6_addr_t ire6_mask;           /* Mask for matching this IRE. */
2613 2611          in6_addr_t ire6_addr;           /* Address this IRE represents. */
2614 2612          in6_addr_t ire6_gateway_addr;   /* Gateway including for IRE_ONLINK */
2615 2613          in6_addr_t ire6_setsrc_addr;    /* RTF_SETSRC */
2616 2614  } ire6_t;
2617 2615  
2618 2616  typedef union ire_addr {
2619 2617          ire6_t  ire6_u;
2620 2618          ire4_t  ire4_u;
2621 2619  } ire_addr_u_t;
2622 2620  
2623 2621  /*
2624 2622   * Internet Routing Entry
2625 2623   * When we have multiple identical IREs we logically add them by manipulating
2626 2624   * ire_identical_ref and ire_delete first decrements
2627 2625   * that and when it reaches 1 we know it is the last IRE.
2628 2626   * "identical" is defined as being the same for:
2629 2627   * ire_addr, ire_netmask, ire_gateway, ire_ill, ire_zoneid, and ire_type
2630 2628   * For instance, multiple IRE_BROADCASTs for the same subnet number are
2631 2629   * viewed as identical, and so are the IRE_INTERFACEs when there are
2632 2630   * multiple logical interfaces (on the same ill) with the same subnet prefix.
2633 2631   */
2634 2632  struct ire_s {
2635 2633          struct  ire_s   *ire_next;      /* The hash chain must be first. */
2636 2634          struct  ire_s   **ire_ptpn;     /* Pointer to previous next. */
2637 2635          uint32_t        ire_refcnt;     /* Number of references */
2638 2636          ill_t           *ire_ill;
2639 2637          uint32_t        ire_identical_ref; /* IRE_INTERFACE, IRE_BROADCAST */
2640 2638          uchar_t         ire_ipversion;  /* IPv4/IPv6 version */
2641 2639          ushort_t        ire_type;       /* Type of IRE */
2642 2640          uint_t          ire_generation; /* Generation including CONDEMNED */
2643 2641          uint_t  ire_ib_pkt_count;       /* Inbound packets for ire_addr */
2644 2642          uint_t  ire_ob_pkt_count;       /* Outbound packets to ire_addr */
2645 2643          time_t  ire_create_time;        /* Time (in secs) IRE was created. */
2646 2644          uint32_t        ire_flags;      /* flags related to route (RTF_*) */
2647 2645          /*
2648 2646           * ire_testhidden is TRUE for INTERFACE IREs of IS_UNDER_IPMP(ill)
2649 2647           * interfaces
2650 2648           */
2651 2649          boolean_t       ire_testhidden;
2652 2650          pfirerecv_t     ire_recvfn;     /* Receive side handling */
2653 2651          pfiresend_t     ire_sendfn;     /* Send side handling */
2654 2652          pfirepostfrag_t ire_postfragfn; /* Bottom end of send handling */
2655 2653  
2656 2654          uint_t          ire_masklen;    /* # bits in ire_mask{,_v6} */
2657 2655          ire_addr_u_t    ire_u;          /* IPv4/IPv6 address info. */
2658 2656  
2659 2657          irb_t           *ire_bucket;    /* Hash bucket when ire_ptphn is set */
2660 2658          kmutex_t        ire_lock;
2661 2659          clock_t         ire_last_used_time;     /* For IRE_LOCAL reception */
2662 2660          tsol_ire_gw_secattr_t *ire_gw_secattr; /* gateway security attributes */
2663 2661          zoneid_t        ire_zoneid;
2664 2662  
2665 2663          /*
2666 2664           * Cached information of where to send packets that match this route.
2667 2665           * The ire_dep_* information is used to determine when ire_nce_cache
2668 2666           * needs to be updated.
2669 2667           * ire_nce_cache is the fastpath for the Neighbor Cache Entry
2670 2668           * for IPv6; arp info for IPv4
2671 2669           * Since this is a cache setup and torn down independently of
2672 2670           * applications we need to use nce_ref{rele,hold}_notr for it.
2673 2671           */
2674 2672          nce_t           *ire_nce_cache;
2675 2673  
2676 2674          /*
2677 2675           * Quick check whether the ire_type and ire_masklen indicates
2678 2676           * that the IRE can have ire_nce_cache set i.e., whether it is
2679 2677           * IRE_ONLINK and for a single destination.
2680 2678           */
2681 2679          boolean_t       ire_nce_capable;
2682 2680  
2683 2681          /*
2684 2682           * Dependency tracking so we can safely cache IRE and NCE pointers
2685 2683           * in offlink and onlink IREs.
2686 2684           * These are locked under the ips_ire_dep_lock rwlock. Write held
2687 2685           * when modifying the linkage.
2688 2686           * ire_dep_parent (Also chain towards IRE for nexthop)
2689 2687           * ire_dep_parent_generation: ire_generation of ire_dep_parent
2690 2688           * ire_dep_children (From parent to first child)
2691 2689           * ire_dep_sib_next (linked list of siblings)
2692 2690           * ire_dep_sib_ptpn (linked list of siblings)
2693 2691           *
2694 2692           * The parent has a ire_refhold on each child, and each child has
2695 2693           * an ire_refhold on its parent.
2696 2694           * Since ire_dep_parent is a cache setup and torn down independently of
2697 2695           * applications we need to use ire_ref{rele,hold}_notr for it.
2698 2696           */
2699 2697          ire_t           *ire_dep_parent;
2700 2698          ire_t           *ire_dep_children;
2701 2699          ire_t           *ire_dep_sib_next;
2702 2700          ire_t           **ire_dep_sib_ptpn;     /* Pointer to previous next */
2703 2701          uint_t          ire_dep_parent_generation;
2704 2702  
2705 2703          uint_t          ire_badcnt;     /* Number of times ND_UNREACHABLE */
2706 2704          uint64_t        ire_last_badcnt;        /* In seconds */
2707 2705  
2708 2706          /* ire_defense* and ire_last_used_time are only used on IRE_LOCALs */
2709 2707          uint_t          ire_defense_count;      /* number of ARP conflicts */
2710 2708          uint_t          ire_defense_time;       /* last time defended (secs) */
2711 2709  
2712 2710          boolean_t       ire_trace_disable;      /* True when alloc fails */
2713 2711          ip_stack_t      *ire_ipst;      /* Does not have a netstack_hold */
2714 2712          iulp_t          ire_metrics;
2715 2713          /*
2716 2714           * default and prefix routes that are added without explicitly
2717 2715           * specifying the interface are termed "unbound" routes, and will
2718 2716           * have ire_unbound set to true.
2719 2717           */
2720 2718          boolean_t       ire_unbound;
2721 2719  };
2722 2720  
2723 2721  /* IPv4 compatibility macros */
2724 2722  #define ire_mask                ire_u.ire4_u.ire4_mask
2725 2723  #define ire_addr                ire_u.ire4_u.ire4_addr
2726 2724  #define ire_gateway_addr        ire_u.ire4_u.ire4_gateway_addr
2727 2725  #define ire_setsrc_addr         ire_u.ire4_u.ire4_setsrc_addr
2728 2726  
2729 2727  #define ire_mask_v6             ire_u.ire6_u.ire6_mask
2730 2728  #define ire_addr_v6             ire_u.ire6_u.ire6_addr
2731 2729  #define ire_gateway_addr_v6     ire_u.ire6_u.ire6_gateway_addr
2732 2730  #define ire_setsrc_addr_v6      ire_u.ire6_u.ire6_setsrc_addr
2733 2731  
2734 2732  /*
2735 2733   * Values for ire_generation.
2736 2734   *
2737 2735   * If an IRE is marked with IRE_IS_CONDEMNED, the last walker of
2738 2736   * the bucket should delete this IRE from this bucket.
2739 2737   *
2740 2738   * IRE_GENERATION_VERIFY is never stored in ire_generation but it is
2741 2739   * stored in places that cache IREs (such as ixa_ire_generation and
2742 2740   * ire_dep_parent_generation). It is used as a signal that the cache is
2743 2741   * stale and needs to be reverified.
2744 2742   */
2745 2743  #define IRE_GENERATION_CONDEMNED        0
2746 2744  #define IRE_GENERATION_VERIFY           1
2747 2745  #define IRE_GENERATION_INITIAL          2
2748 2746  #define IRE_IS_CONDEMNED(ire) \
2749 2747          ((ire)->ire_generation == IRE_GENERATION_CONDEMNED)
2750 2748  
2751 2749  /* Convenient typedefs for sockaddrs */
2752 2750  typedef struct sockaddr_in      sin_t;
2753 2751  typedef struct sockaddr_in6     sin6_t;
2754 2752  
2755 2753  /* Name/Value Descriptor. */
2756 2754  typedef struct nv_s {
2757 2755          uint64_t nv_value;
2758 2756          char    *nv_name;
2759 2757  } nv_t;
2760 2758  
2761 2759  #define ILL_FRAG_HASH(s, i) \
2762 2760          ((ntohl(s) ^ ((i) ^ ((i) >> 8))) % ILL_FRAG_HASH_TBL_COUNT)
2763 2761  
2764 2762  /*
2765 2763   * The MAX number of allowed fragmented packets per hash bucket
2766 2764   * calculation is based on the most common mtu size of 1500. This limit
2767 2765   * will work well for other mtu sizes as well.
2768 2766   */
2769 2767  #define COMMON_IP_MTU 1500
2770 2768  #define MAX_FRAG_MIN 10
2771 2769  #define MAX_FRAG_PKTS(ipst)     \
2772 2770          MAX(MAX_FRAG_MIN, (2 * (ipst->ips_ip_reass_queue_bytes / \
2773 2771              (COMMON_IP_MTU * ILL_FRAG_HASH_TBL_COUNT))))
2774 2772  
2775 2773  /*
2776 2774   * Maximum dups allowed per packet.
2777 2775   */
2778 2776  extern uint_t ip_max_frag_dups;
2779 2777  
2780 2778  /*
2781 2779   * Per-packet information for received packets and transmitted.
2782 2780   * Used by the transport protocols when converting between the packet
2783 2781   * and ancillary data and socket options.
2784 2782   *
2785 2783   * Note: This private data structure and related IPPF_* constant
2786 2784   * definitions are exposed to enable compilation of some debugging tools
2787 2785   * like lsof which use struct tcp_t in <inet/tcp.h>. This is intended to be
2788 2786   * a temporary hack and long term alternate interfaces should be defined
2789 2787   * to support the needs of such tools and private definitions moved to
2790 2788   * private headers.
2791 2789   */
2792 2790  struct ip_pkt_s {
2793 2791          uint_t          ipp_fields;             /* Which fields are valid */
2794 2792          in6_addr_t      ipp_addr;               /* pktinfo src/dst addr */
2795 2793  #define ipp_addr_v4     V4_PART_OF_V6(ipp_addr)
2796 2794          uint_t          ipp_unicast_hops;       /* IPV6_UNICAST_HOPS, IP_TTL */
2797 2795          uint_t          ipp_hoplimit;           /* IPV6_HOPLIMIT */
2798 2796          uint_t          ipp_hopoptslen;
2799 2797          uint_t          ipp_rthdrdstoptslen;
2800 2798          uint_t          ipp_rthdrlen;
2801 2799          uint_t          ipp_dstoptslen;
2802 2800          uint_t          ipp_fraghdrlen;
2803 2801          ip6_hbh_t       *ipp_hopopts;
2804 2802          ip6_dest_t      *ipp_rthdrdstopts;
2805 2803          ip6_rthdr_t     *ipp_rthdr;
2806 2804          ip6_dest_t      *ipp_dstopts;
2807 2805          ip6_frag_t      *ipp_fraghdr;
2808 2806          uint8_t         ipp_tclass;             /* IPV6_TCLASS */
2809 2807          uint8_t         ipp_type_of_service;    /* IP_TOS */
2810 2808          uint_t          ipp_ipv4_options_len;   /* Len of IPv4 options */
2811 2809          uint8_t         *ipp_ipv4_options;      /* Ptr to IPv4 options */
2812 2810          uint_t          ipp_label_len_v4;       /* Len of TX label for IPv4 */
2813 2811          uint8_t         *ipp_label_v4;          /* TX label for IPv4 */
2814 2812          uint_t          ipp_label_len_v6;       /* Len of TX label for IPv6 */
2815 2813          uint8_t         *ipp_label_v6;          /* TX label for IPv6 */
2816 2814  };
2817 2815  typedef struct ip_pkt_s ip_pkt_t;
2818 2816  
2819 2817  extern void ip_pkt_free(ip_pkt_t *);    /* free storage inside ip_pkt_t */
2820 2818  extern ipaddr_t ip_pkt_source_route_v4(const ip_pkt_t *);
2821 2819  extern in6_addr_t *ip_pkt_source_route_v6(const ip_pkt_t *);
2822 2820  extern int ip_pkt_copy(ip_pkt_t *, ip_pkt_t *, int);
2823 2821  extern void ip_pkt_source_route_reverse_v4(ip_pkt_t *);
2824 2822  
2825 2823  /* ipp_fields values */
2826 2824  #define IPPF_ADDR               0x0001  /* Part of in6_pktinfo: src/dst addr */
2827 2825  #define IPPF_HOPLIMIT           0x0002  /* Overrides unicast and multicast */
2828 2826  #define IPPF_TCLASS             0x0004  /* Overrides class in sin6_flowinfo */
2829 2827  
2830 2828  #define IPPF_HOPOPTS            0x0010  /* ipp_hopopts set */
2831 2829  #define IPPF_RTHDR              0x0020  /* ipp_rthdr set */
2832 2830  #define IPPF_RTHDRDSTOPTS       0x0040  /* ipp_rthdrdstopts set */
2833 2831  #define IPPF_DSTOPTS            0x0080  /* ipp_dstopts set */
2834 2832  
2835 2833  #define IPPF_IPV4_OPTIONS       0x0100  /* ipp_ipv4_options set */
2836 2834  #define IPPF_LABEL_V4           0x0200  /* ipp_label_v4 set */
2837 2835  #define IPPF_LABEL_V6           0x0400  /* ipp_label_v6 set */
2838 2836  
2839 2837  #define IPPF_FRAGHDR            0x0800  /* Used for IPsec receive side */
2840 2838  
2841 2839  /*
2842 2840   * Data structure which is passed to conn_opt_get/set.
2843 2841   * The conn_t is included even though it can be inferred from queue_t.
2844 2842   * setsockopt and getsockopt use conn_ixa and conn_xmit_ipp. However,
2845 2843   * when handling ancillary data we use separate ixa and ipps.
2846 2844   */
2847 2845  typedef struct conn_opt_arg_s {
2848 2846          conn_t          *coa_connp;
2849 2847          ip_xmit_attr_t  *coa_ixa;
2850 2848          ip_pkt_t        *coa_ipp;
2851 2849          boolean_t       coa_ancillary;  /* Ancillary data and not setsockopt */
2852 2850          uint_t          coa_changed;    /* See below */
2853 2851  } conn_opt_arg_t;
2854 2852  
2855 2853  /*
2856 2854   * Flags for what changed.
2857 2855   * If we want to be more efficient in the future we can have more fine
2858 2856   * grained flags e.g., a flag for just IP_TOS changing.
2859 2857   * For now we either call ip_set_destination (for "route changed")
2860 2858   * and/or conn_build_hdr_template/conn_prepend_hdr (for "header changed").
2861 2859   */
2862 2860  #define COA_HEADER_CHANGED      0x0001
2863 2861  #define COA_ROUTE_CHANGED       0x0002
2864 2862  #define COA_RCVBUF_CHANGED      0x0004  /* SO_RCVBUF */
2865 2863  #define COA_SNDBUF_CHANGED      0x0008  /* SO_SNDBUF */
2866 2864  #define COA_WROFF_CHANGED       0x0010  /* Header size changed */
2867 2865  #define COA_ICMP_BIND_NEEDED    0x0020
2868 2866  #define COA_OOBINLINE_CHANGED   0x0040
2869 2867  
2870 2868  #define TCP_PORTS_OFFSET        0
2871 2869  #define UDP_PORTS_OFFSET        0
2872 2870  
2873 2871  /*
2874 2872   * lookups return the ill/ipif only if the flags are clear OR Iam writer.
2875 2873   * ill / ipif lookup functions increment the refcnt on the ill / ipif only
2876 2874   * after calling these macros. This ensures that the refcnt on the ipif or
2877 2875   * ill will eventually drop down to zero.
2878 2876   */
2879 2877  #define ILL_LOOKUP_FAILED       1       /* Used as error code */
2880 2878  #define IPIF_LOOKUP_FAILED      2       /* Used as error code */
2881 2879  
2882 2880  #define ILL_CAN_LOOKUP(ill)                                             \
2883 2881          (!((ill)->ill_state_flags & ILL_CONDEMNED) ||                   \
2884 2882          IAM_WRITER_ILL(ill))
2885 2883  
2886 2884  #define ILL_IS_CONDEMNED(ill)   \
2887 2885          ((ill)->ill_state_flags & ILL_CONDEMNED)
2888 2886  
2889 2887  #define IPIF_CAN_LOOKUP(ipif)   \
2890 2888          (!((ipif)->ipif_state_flags & IPIF_CONDEMNED) || \
2891 2889          IAM_WRITER_IPIF(ipif))
2892 2890  
2893 2891  #define IPIF_IS_CONDEMNED(ipif) \
2894 2892          ((ipif)->ipif_state_flags & IPIF_CONDEMNED)
2895 2893  
2896 2894  #define IPIF_IS_CHANGING(ipif)  \
2897 2895          ((ipif)->ipif_state_flags & IPIF_CHANGING)
2898 2896  
2899 2897  /* Macros used to assert that this thread is a writer */
2900 2898  #define IAM_WRITER_IPSQ(ipsq)   ((ipsq)->ipsq_xop->ipx_writer == curthread)
2901 2899  #define IAM_WRITER_ILL(ill)     IAM_WRITER_IPSQ((ill)->ill_phyint->phyint_ipsq)
2902 2900  #define IAM_WRITER_IPIF(ipif)   IAM_WRITER_ILL((ipif)->ipif_ill)
2903 2901  
2904 2902  /*
2905 2903   * Grab ill locks in the proper order. The order is highest addressed
2906 2904   * ill is locked first.
2907 2905   */
2908 2906  #define GRAB_ILL_LOCKS(ill_1, ill_2)                            \
2909 2907  {                                                               \
2910 2908          if ((ill_1) > (ill_2)) {                                \
2911 2909                  if (ill_1 != NULL)                              \
2912 2910                          mutex_enter(&(ill_1)->ill_lock);        \
2913 2911                  if (ill_2 != NULL)                              \
2914 2912                          mutex_enter(&(ill_2)->ill_lock);        \
2915 2913          } else {                                                \
2916 2914                  if (ill_2 != NULL)                              \
2917 2915                          mutex_enter(&(ill_2)->ill_lock);        \
2918 2916                  if (ill_1 != NULL && ill_1 != ill_2)            \
2919 2917                          mutex_enter(&(ill_1)->ill_lock);        \
2920 2918          }                                                       \
2921 2919  }
2922 2920  
2923 2921  #define RELEASE_ILL_LOCKS(ill_1, ill_2)         \
2924 2922  {                                               \
2925 2923          if (ill_1 != NULL)                      \
2926 2924                  mutex_exit(&(ill_1)->ill_lock); \
2927 2925          if (ill_2 != NULL && ill_2 != ill_1)    \
2928 2926                  mutex_exit(&(ill_2)->ill_lock); \
2929 2927  }
2930 2928  
2931 2929  /* Get the other protocol instance ill */
2932 2930  #define ILL_OTHER(ill)                                          \
2933 2931          ((ill)->ill_isv6 ? (ill)->ill_phyint->phyint_illv4 :    \
2934 2932              (ill)->ill_phyint->phyint_illv6)
2935 2933  
2936 2934  /* ioctl command info: Ioctl properties extracted and stored in here */
2937 2935  typedef struct cmd_info_s
2938 2936  {
2939 2937          ipif_t  *ci_ipif;       /* ipif associated with [l]ifreq ioctl's */
2940 2938          sin_t   *ci_sin;        /* the sin struct passed down */
2941 2939          sin6_t  *ci_sin6;       /* the sin6_t struct passed down */
2942 2940          struct lifreq *ci_lifr; /* the lifreq struct passed down */
2943 2941  } cmd_info_t;
2944 2942  
2945 2943  extern struct kmem_cache *ire_cache;
2946 2944  
2947 2945  extern ipaddr_t ip_g_all_ones;
2948 2946  
2949 2947  extern uint_t   ip_loopback_mtu;        /* /etc/system */
2950 2948  extern uint_t   ip_loopback_mtuplus;
2951 2949  extern uint_t   ip_loopback_mtu_v6plus;
2952 2950  
2953 2951  extern vmem_t *ip_minor_arena_sa;
2954 2952  extern vmem_t *ip_minor_arena_la;
2955 2953  
2956 2954  /*
2957 2955   * ip_g_forward controls IP forwarding.  It takes two values:
2958 2956   *      0: IP_FORWARD_NEVER     Don't forward packets ever.
2959 2957   *      1: IP_FORWARD_ALWAYS    Forward packets for elsewhere.
2960 2958   *
2961 2959   * RFC1122 says there must be a configuration switch to control forwarding,
2962 2960   * but that the default MUST be to not forward packets ever.  Implicit
2963 2961   * control based on configuration of multiple interfaces MUST NOT be
2964 2962   * implemented (Section 3.1).  SunOS 4.1 did provide the "automatic" capability
2965 2963   * and, in fact, it was the default.  That capability is now provided in the
2966 2964   * /etc/rc2.d/S69inet script.
2967 2965   */
2968 2966  
2969 2967  #define ips_ip_respond_to_address_mask_broadcast \
2970 2968                                          ips_propinfo_tbl[0].prop_cur_bval
2971 2969  #define ips_ip_g_resp_to_echo_bcast     ips_propinfo_tbl[1].prop_cur_bval
2972 2970  #define ips_ip_g_resp_to_echo_mcast     ips_propinfo_tbl[2].prop_cur_bval
2973 2971  #define ips_ip_g_resp_to_timestamp      ips_propinfo_tbl[3].prop_cur_bval
2974 2972  #define ips_ip_g_resp_to_timestamp_bcast ips_propinfo_tbl[4].prop_cur_bval
2975 2973  #define ips_ip_g_send_redirects         ips_propinfo_tbl[5].prop_cur_bval
2976 2974  #define ips_ip_g_forward_directed_bcast ips_propinfo_tbl[6].prop_cur_bval
2977 2975  #define ips_ip_mrtdebug                 ips_propinfo_tbl[7].prop_cur_uval
2978 2976  #define ips_ip_ire_reclaim_fraction     ips_propinfo_tbl[8].prop_cur_uval
2979 2977  #define ips_ip_nce_reclaim_fraction     ips_propinfo_tbl[9].prop_cur_uval
2980 2978  #define ips_ip_dce_reclaim_fraction     ips_propinfo_tbl[10].prop_cur_uval
2981 2979  #define ips_ip_def_ttl                  ips_propinfo_tbl[11].prop_cur_uval
2982 2980  #define ips_ip_forward_src_routed       ips_propinfo_tbl[12].prop_cur_bval
2983 2981  #define ips_ip_wroff_extra              ips_propinfo_tbl[13].prop_cur_uval
2984 2982  #define ips_ip_pathmtu_interval         ips_propinfo_tbl[14].prop_cur_uval
2985 2983  #define ips_ip_icmp_return              ips_propinfo_tbl[15].prop_cur_uval
2986 2984  #define ips_ip_path_mtu_discovery       ips_propinfo_tbl[16].prop_cur_bval
2987 2985  #define ips_ip_pmtu_min                 ips_propinfo_tbl[17].prop_cur_uval
2988 2986  #define ips_ip_ignore_redirect          ips_propinfo_tbl[18].prop_cur_bval
2989 2987  #define ips_ip_arp_icmp_error           ips_propinfo_tbl[19].prop_cur_bval
2990 2988  #define ips_ip_broadcast_ttl            ips_propinfo_tbl[20].prop_cur_uval
2991 2989  #define ips_ip_icmp_err_interval        ips_propinfo_tbl[21].prop_cur_uval
2992 2990  #define ips_ip_icmp_err_burst           ips_propinfo_tbl[22].prop_cur_uval
2993 2991  #define ips_ip_reass_queue_bytes        ips_propinfo_tbl[23].prop_cur_uval
2994 2992  #define ips_ip_strict_dst_multihoming   ips_propinfo_tbl[24].prop_cur_uval
2995 2993  #define ips_ip_addrs_per_if             ips_propinfo_tbl[25].prop_cur_uval
2996 2994  #define ips_ipsec_override_persocket_policy ips_propinfo_tbl[26].prop_cur_bval
2997 2995  #define ips_icmp_accept_clear_messages  ips_propinfo_tbl[27].prop_cur_bval
2998 2996  #define ips_igmp_accept_clear_messages  ips_propinfo_tbl[28].prop_cur_bval
2999 2997  
3000 2998  /* IPv6 configuration knobs */
3001 2999  #define ips_delay_first_probe_time      ips_propinfo_tbl[29].prop_cur_uval
3002 3000  #define ips_max_unicast_solicit         ips_propinfo_tbl[30].prop_cur_uval
3003 3001  #define ips_ipv6_def_hops               ips_propinfo_tbl[31].prop_cur_uval
3004 3002  #define ips_ipv6_icmp_return            ips_propinfo_tbl[32].prop_cur_uval
3005 3003  #define ips_ipv6_forward_src_routed     ips_propinfo_tbl[33].prop_cur_bval
3006 3004  #define ips_ipv6_resp_echo_mcast        ips_propinfo_tbl[34].prop_cur_bval
3007 3005  #define ips_ipv6_send_redirects         ips_propinfo_tbl[35].prop_cur_bval
3008 3006  #define ips_ipv6_ignore_redirect        ips_propinfo_tbl[36].prop_cur_bval
3009 3007  #define ips_ipv6_strict_dst_multihoming ips_propinfo_tbl[37].prop_cur_uval
3010 3008  #define ips_src_check                   ips_propinfo_tbl[38].prop_cur_uval
3011 3009  #define ips_ipsec_policy_log_interval   ips_propinfo_tbl[39].prop_cur_uval
3012 3010  #define ips_pim_accept_clear_messages   ips_propinfo_tbl[40].prop_cur_bval
3013 3011  #define ips_ip_ndp_unsolicit_interval   ips_propinfo_tbl[41].prop_cur_uval
3014 3012  #define ips_ip_ndp_unsolicit_count      ips_propinfo_tbl[42].prop_cur_uval
3015 3013  #define ips_ipv6_ignore_home_address_opt ips_propinfo_tbl[43].prop_cur_bval
3016 3014  
3017 3015  /* Misc IP configuration knobs */
3018 3016  #define ips_ip_policy_mask              ips_propinfo_tbl[44].prop_cur_uval
3019 3017  #define ips_ip_ecmp_behavior            ips_propinfo_tbl[45].prop_cur_uval
3020 3018  #define ips_ip_multirt_ttl              ips_propinfo_tbl[46].prop_cur_uval
3021 3019  #define ips_ip_ire_badcnt_lifetime      ips_propinfo_tbl[47].prop_cur_uval
3022 3020  #define ips_ip_max_temp_idle            ips_propinfo_tbl[48].prop_cur_uval
3023 3021  #define ips_ip_max_temp_defend          ips_propinfo_tbl[49].prop_cur_uval
3024 3022  #define ips_ip_max_defend               ips_propinfo_tbl[50].prop_cur_uval
3025 3023  #define ips_ip_defend_interval          ips_propinfo_tbl[51].prop_cur_uval
3026 3024  #define ips_ip_dup_recovery             ips_propinfo_tbl[52].prop_cur_uval
3027 3025  #define ips_ip_restrict_interzone_loopback ips_propinfo_tbl[53].prop_cur_bval
3028 3026  #define ips_ip_lso_outbound             ips_propinfo_tbl[54].prop_cur_bval
3029 3027  #define ips_igmp_max_version            ips_propinfo_tbl[55].prop_cur_uval
3030 3028  #define ips_mld_max_version             ips_propinfo_tbl[56].prop_cur_uval
3031 3029  #define ips_ip_forwarding               ips_propinfo_tbl[57].prop_cur_bval
3032 3030  #define ips_ipv6_forwarding             ips_propinfo_tbl[58].prop_cur_bval
3033 3031  #define ips_ip_reassembly_timeout       ips_propinfo_tbl[59].prop_cur_uval
3034 3032  #define ips_ipv6_reassembly_timeout     ips_propinfo_tbl[60].prop_cur_uval
3035 3033  #define ips_ip_cgtp_filter              ips_propinfo_tbl[61].prop_cur_bval
3036 3034  #define ips_arp_probe_delay             ips_propinfo_tbl[62].prop_cur_uval
3037 3035  #define ips_arp_fastprobe_delay         ips_propinfo_tbl[63].prop_cur_uval
3038 3036  #define ips_arp_probe_interval          ips_propinfo_tbl[64].prop_cur_uval
3039 3037  #define ips_arp_fastprobe_interval      ips_propinfo_tbl[65].prop_cur_uval
3040 3038  #define ips_arp_probe_count             ips_propinfo_tbl[66].prop_cur_uval
3041 3039  #define ips_arp_fastprobe_count         ips_propinfo_tbl[67].prop_cur_uval
3042 3040  #define ips_ipv4_dad_announce_interval  ips_propinfo_tbl[68].prop_cur_uval
3043 3041  #define ips_ipv6_dad_announce_interval  ips_propinfo_tbl[69].prop_cur_uval
3044 3042  #define ips_arp_defend_interval         ips_propinfo_tbl[70].prop_cur_uval
3045 3043  #define ips_arp_defend_rate             ips_propinfo_tbl[71].prop_cur_uval
3046 3044  #define ips_ndp_defend_interval         ips_propinfo_tbl[72].prop_cur_uval
3047 3045  #define ips_ndp_defend_rate             ips_propinfo_tbl[73].prop_cur_uval
3048 3046  #define ips_arp_defend_period           ips_propinfo_tbl[74].prop_cur_uval
3049 3047  #define ips_ndp_defend_period           ips_propinfo_tbl[75].prop_cur_uval
3050 3048  #define ips_ipv4_icmp_return_pmtu       ips_propinfo_tbl[76].prop_cur_bval
3051 3049  #define ips_ipv6_icmp_return_pmtu       ips_propinfo_tbl[77].prop_cur_bval
3052 3050  #define ips_ip_arp_publish_count        ips_propinfo_tbl[78].prop_cur_uval
3053 3051  #define ips_ip_arp_publish_interval     ips_propinfo_tbl[79].prop_cur_uval
3054 3052  #define ips_ip_strict_src_multihoming   ips_propinfo_tbl[80].prop_cur_uval
3055 3053  #define ips_ipv6_strict_src_multihoming ips_propinfo_tbl[81].prop_cur_uval
3056 3054  #define ips_ipv6_drop_inbound_icmpv6    ips_propinfo_tbl[82].prop_cur_bval
3057 3055  #define ips_ip_dce_reclaim_threshold    ips_propinfo_tbl[83].prop_cur_uval
3058 3056  
3059 3057  extern int      dohwcksum;      /* use h/w cksum if supported by the h/w */
3060 3058  #ifdef ZC_TEST
3061 3059  extern int      noswcksum;
3062 3060  #endif
3063 3061  
3064 3062  extern char     ipif_loopback_name[];
3065 3063  
3066 3064  extern nv_t     *ire_nv_tbl;
3067 3065  
3068 3066  extern struct module_info ip_mod_info;
3069 3067  
3070 3068  #define HOOKS4_INTERESTED_PHYSICAL_IN(ipst)     \
3071 3069          ((ipst)->ips_ip4_physical_in_event.he_interested)
3072 3070  #define HOOKS6_INTERESTED_PHYSICAL_IN(ipst)     \
3073 3071          ((ipst)->ips_ip6_physical_in_event.he_interested)
3074 3072  #define HOOKS4_INTERESTED_PHYSICAL_OUT(ipst)    \
3075 3073          ((ipst)->ips_ip4_physical_out_event.he_interested)
3076 3074  #define HOOKS6_INTERESTED_PHYSICAL_OUT(ipst)    \
3077 3075          ((ipst)->ips_ip6_physical_out_event.he_interested)
3078 3076  #define HOOKS4_INTERESTED_FORWARDING(ipst)      \
3079 3077          ((ipst)->ips_ip4_forwarding_event.he_interested)
3080 3078  #define HOOKS6_INTERESTED_FORWARDING(ipst)      \
3081 3079          ((ipst)->ips_ip6_forwarding_event.he_interested)
3082 3080  #define HOOKS4_INTERESTED_LOOPBACK_IN(ipst)     \
3083 3081          ((ipst)->ips_ip4_loopback_in_event.he_interested)
3084 3082  #define HOOKS6_INTERESTED_LOOPBACK_IN(ipst)     \
3085 3083          ((ipst)->ips_ip6_loopback_in_event.he_interested)
3086 3084  #define HOOKS4_INTERESTED_LOOPBACK_OUT(ipst)    \
3087 3085          ((ipst)->ips_ip4_loopback_out_event.he_interested)
3088 3086  #define HOOKS6_INTERESTED_LOOPBACK_OUT(ipst)    \
3089 3087          ((ipst)->ips_ip6_loopback_out_event.he_interested)
3090 3088  /*
3091 3089   * Hooks marcos used inside of ip
3092 3090   * The callers use the above INTERESTED macros first, hence
3093 3091   * the he_interested check is superflous.
3094 3092   */
3095 3093  #define FW_HOOKS(_hook, _event, _ilp, _olp, _iph, _fm, _m, _llm, ipst, _err) \
3096 3094          if ((_hook).he_interested) {                                    \
3097 3095                  hook_pkt_event_t info;                                  \
3098 3096                                                                          \
3099 3097                  _NOTE(CONSTCOND)                                        \
3100 3098                  ASSERT((_ilp != NULL) || (_olp != NULL));               \
3101 3099                                                                          \
3102 3100                  FW_SET_ILL_INDEX(info.hpe_ifp, (ill_t *)_ilp);          \
3103 3101                  FW_SET_ILL_INDEX(info.hpe_ofp, (ill_t *)_olp);          \
3104 3102                  info.hpe_protocol = ipst->ips_ipv4_net_data;            \
3105 3103                  info.hpe_hdr = _iph;                                    \
3106 3104                  info.hpe_mp = &(_fm);                                   \
3107 3105                  info.hpe_mb = _m;                                       \
3108 3106                  info.hpe_flags = _llm;                                  \
3109 3107                  _err = hook_run(ipst->ips_ipv4_net_data->netd_hooks,    \
3110 3108                      _event, (hook_data_t)&info);                        \
3111 3109                  if (_err != 0) {                                        \
3112 3110                          ip2dbg(("%s hook dropped mblk chain %p hdr %p\n",\
3113 3111                              (_hook).he_name, (void *)_fm, (void *)_m)); \
3114 3112                          if (_fm != NULL) {                              \
3115 3113                                  freemsg(_fm);                           \
3116 3114                                  _fm = NULL;                             \
3117 3115                          }                                               \
3118 3116                          _iph = NULL;                                    \
3119 3117                          _m = NULL;                                      \
3120 3118                  } else {                                                \
3121 3119                          _iph = info.hpe_hdr;                            \
3122 3120                          _m = info.hpe_mb;                               \
3123 3121                  }                                                       \
3124 3122          }
3125 3123  
3126 3124  #define FW_HOOKS6(_hook, _event, _ilp, _olp, _iph, _fm, _m, _llm, ipst, _err) \
3127 3125          if ((_hook).he_interested) {                                    \
3128 3126                  hook_pkt_event_t info;                                  \
3129 3127                                                                          \
3130 3128                  _NOTE(CONSTCOND)                                        \
3131 3129                  ASSERT((_ilp != NULL) || (_olp != NULL));               \
3132 3130                                                                          \
3133 3131                  FW_SET_ILL_INDEX(info.hpe_ifp, (ill_t *)_ilp);          \
3134 3132                  FW_SET_ILL_INDEX(info.hpe_ofp, (ill_t *)_olp);          \
3135 3133                  info.hpe_protocol = ipst->ips_ipv6_net_data;            \
3136 3134                  info.hpe_hdr = _iph;                                    \
3137 3135                  info.hpe_mp = &(_fm);                                   \
3138 3136                  info.hpe_mb = _m;                                       \
3139 3137                  info.hpe_flags = _llm;                                  \
3140 3138                  _err = hook_run(ipst->ips_ipv6_net_data->netd_hooks,    \
3141 3139                      _event, (hook_data_t)&info);                        \
3142 3140                  if (_err != 0) {                                        \
3143 3141                          ip2dbg(("%s hook dropped mblk chain %p hdr %p\n",\
3144 3142                              (_hook).he_name, (void *)_fm, (void *)_m)); \
3145 3143                          if (_fm != NULL) {                              \
3146 3144                                  freemsg(_fm);                           \
3147 3145                                  _fm = NULL;                             \
3148 3146                          }                                               \
3149 3147                          _iph = NULL;                                    \
3150 3148                          _m = NULL;                                      \
3151 3149                  } else {                                                \
3152 3150                          _iph = info.hpe_hdr;                            \
3153 3151                          _m = info.hpe_mb;                               \
3154 3152                  }                                                       \
3155 3153          }
3156 3154  
3157 3155  #define FW_SET_ILL_INDEX(fp, ill)                                       \
3158 3156          _NOTE(CONSTCOND)                                                \
3159 3157          if ((ill) == NULL || (ill)->ill_phyint == NULL) {               \
3160 3158                  (fp) = 0;                                               \
3161 3159                  _NOTE(CONSTCOND)                                        \
3162 3160          } else if (IS_UNDER_IPMP(ill)) {                                \
3163 3161                  (fp) = ipmp_ill_get_ipmp_ifindex(ill);                  \
3164 3162          } else {                                                        \
3165 3163                  (fp) = (ill)->ill_phyint->phyint_ifindex;               \
3166 3164          }
3167 3165  
3168 3166  /*
3169 3167   * Network byte order macros
3170 3168   */
3171 3169  #ifdef  _BIG_ENDIAN
3172 3170  #define N_IN_CLASSA_NET         IN_CLASSA_NET
3173 3171  #define N_IN_CLASSD_NET         IN_CLASSD_NET
3174 3172  #define N_INADDR_UNSPEC_GROUP   INADDR_UNSPEC_GROUP
3175 3173  #define N_IN_LOOPBACK_NET       (ipaddr_t)0x7f000000U
3176 3174  #else /* _BIG_ENDIAN */
3177 3175  #define N_IN_CLASSA_NET         (ipaddr_t)0x000000ffU
3178 3176  #define N_IN_CLASSD_NET         (ipaddr_t)0x000000f0U
3179 3177  #define N_INADDR_UNSPEC_GROUP   (ipaddr_t)0x000000e0U
3180 3178  #define N_IN_LOOPBACK_NET       (ipaddr_t)0x0000007fU
3181 3179  #endif /* _BIG_ENDIAN */
3182 3180  #define CLASSD(addr)    (((addr) & N_IN_CLASSD_NET) == N_INADDR_UNSPEC_GROUP)
3183 3181  #define CLASSE(addr)    (((addr) & N_IN_CLASSD_NET) == N_IN_CLASSD_NET)
3184 3182  #define IP_LOOPBACK_ADDR(addr)                  \
3185 3183          (((addr) & N_IN_CLASSA_NET == N_IN_LOOPBACK_NET))
3186 3184  
3187 3185  extern int      ip_debug;
3188 3186  extern uint_t   ip_thread_data;
3189 3187  extern krwlock_t ip_thread_rwlock;
3190 3188  extern list_t   ip_thread_list;
3191 3189  
3192 3190  #ifdef IP_DEBUG
3193 3191  #include <sys/debug.h>
3194 3192  #include <sys/promif.h>
3195 3193  
3196 3194  #define ip0dbg(a)       printf a
3197 3195  #define ip1dbg(a)       if (ip_debug > 2) printf a
3198 3196  #define ip2dbg(a)       if (ip_debug > 3) printf a
3199 3197  #define ip3dbg(a)       if (ip_debug > 4) printf a
3200 3198  #else
3201 3199  #define ip0dbg(a)       /* */
3202 3200  #define ip1dbg(a)       /* */
3203 3201  #define ip2dbg(a)       /* */
3204 3202  #define ip3dbg(a)       /* */
3205 3203  #endif  /* IP_DEBUG */
3206 3204  
3207 3205  /* Default MAC-layer address string length for mac_colon_addr */
3208 3206  #define MAC_STR_LEN     128
3209 3207  
3210 3208  struct  mac_header_info_s;
3211 3209  
3212 3210  extern void     ill_frag_timer(void *);
3213 3211  extern ill_t    *ill_first(int, int, ill_walk_context_t *, ip_stack_t *);
3214 3212  extern ill_t    *ill_next(ill_walk_context_t *, ill_t *);
3215 3213  extern void     ill_frag_timer_start(ill_t *);
3216 3214  extern void     ill_nic_event_dispatch(ill_t *, lif_if_t, nic_event_t,
3217 3215      nic_event_data_t, size_t);
3218 3216  extern mblk_t   *ip_carve_mp(mblk_t **, ssize_t);
3219 3217  extern mblk_t   *ip_dlpi_alloc(size_t, t_uscalar_t);
3220 3218  extern mblk_t   *ip_dlnotify_alloc(uint_t, uint_t);
3221 3219  extern mblk_t   *ip_dlnotify_alloc2(uint_t, uint_t, uint_t);
3222 3220  extern char     *ip_dot_addr(ipaddr_t, char *);
3223 3221  extern const char *mac_colon_addr(const uint8_t *, size_t, char *, size_t);
3224 3222  extern int      ip_lwput(queue_t *, mblk_t *);
3225 3223  extern boolean_t icmp_err_rate_limit(ip_stack_t *);
3226 3224  extern void     icmp_frag_needed(mblk_t *, int, ip_recv_attr_t *);
3227 3225  extern mblk_t   *icmp_inbound_v4(mblk_t *, ip_recv_attr_t *);
3228 3226  extern void     icmp_time_exceeded(mblk_t *, uint8_t, ip_recv_attr_t *);
3229 3227  extern void     icmp_unreachable(mblk_t *, uint8_t, ip_recv_attr_t *);
3230 3228  extern boolean_t ip_ipsec_policy_inherit(conn_t *, conn_t *, ip_recv_attr_t *);
3231 3229  extern void     *ip_pullup(mblk_t *, ssize_t, ip_recv_attr_t *);
3232 3230  extern void     ip_setl2src(mblk_t *, ip_recv_attr_t *, ill_t *);
3233 3231  extern mblk_t   *ip_check_and_align_header(mblk_t *, uint_t, ip_recv_attr_t *);
3234 3232  extern mblk_t   *ip_check_length(mblk_t *, uchar_t *, ssize_t, uint_t, uint_t,
3235 3233      ip_recv_attr_t *);
3236 3234  extern mblk_t   *ip_check_optlen(mblk_t *, ipha_t *, uint_t, uint_t,
3237 3235      ip_recv_attr_t *);
3238 3236  extern mblk_t   *ip_fix_dbref(mblk_t *, ip_recv_attr_t *);
3239 3237  extern uint_t   ip_cksum(mblk_t *, int, uint32_t);
3240 3238  extern int      ip_close(queue_t *, int, cred_t *);
3241 3239  extern uint16_t ip_csum_hdr(ipha_t *);
3242 3240  extern void     ip_forward_xmit_v4(nce_t *, ill_t *, mblk_t *, ipha_t *,
3243 3241      ip_recv_attr_t *, uint32_t, uint32_t);
3244 3242  extern boolean_t ip_forward_options(mblk_t *, ipha_t *, ill_t *,
3245 3243      ip_recv_attr_t *);
3246 3244  extern int      ip_fragment_v4(mblk_t *, nce_t *, iaflags_t, uint_t, uint32_t,
3247 3245      uint32_t, zoneid_t, zoneid_t, pfirepostfrag_t postfragfn,
3248 3246      uintptr_t *cookie);
3249 3247  extern void     ip_proto_not_sup(mblk_t *, ip_recv_attr_t *);
3250 3248  extern void     ip_ire_g_fini(void);
3251 3249  extern void     ip_ire_g_init(void);
3252 3250  extern void     ip_ire_fini(ip_stack_t *);
3253 3251  extern void     ip_ire_init(ip_stack_t *);
3254 3252  extern void     ip_mdata_to_mhi(ill_t *, mblk_t *, struct mac_header_info_s *);
3255 3253  extern int      ip_openv4(queue_t *q, dev_t *devp, int flag, int sflag,
3256 3254                      cred_t *credp);
3257 3255  extern int      ip_openv6(queue_t *q, dev_t *devp, int flag, int sflag,
3258 3256                      cred_t *credp);
3259 3257  extern int      ip_reassemble(mblk_t *, ipf_t *, uint_t, boolean_t, ill_t *,
3260 3258      size_t);
3261 3259  extern int      ip_rput(queue_t *, mblk_t *);
3262 3260  extern void     ip_input(ill_t *, ill_rx_ring_t *, mblk_t *,
3263 3261      struct mac_header_info_s *);
3264 3262  extern void     ip_input_v6(ill_t *, ill_rx_ring_t *, mblk_t *,
3265 3263      struct mac_header_info_s *);
3266 3264  extern mblk_t   *ip_input_common_v4(ill_t *, ill_rx_ring_t *, mblk_t *,
3267 3265      struct mac_header_info_s *, squeue_t *, mblk_t **, uint_t *);
3268 3266  extern mblk_t   *ip_input_common_v6(ill_t *, ill_rx_ring_t *, mblk_t *,
3269 3267      struct mac_header_info_s *, squeue_t *, mblk_t **, uint_t *);
3270 3268  extern void     ill_input_full_v4(mblk_t *, void *, void *,
3271 3269      ip_recv_attr_t *, rtc_t *);
3272 3270  extern void     ill_input_short_v4(mblk_t *, void *, void *,
3273 3271      ip_recv_attr_t *, rtc_t *);
3274 3272  extern void     ill_input_full_v6(mblk_t *, void *, void *,
3275 3273      ip_recv_attr_t *, rtc_t *);
3276 3274  extern void     ill_input_short_v6(mblk_t *, void *, void *,
3277 3275      ip_recv_attr_t *, rtc_t *);
3278 3276  extern ipaddr_t ip_input_options(ipha_t *, ipaddr_t, mblk_t *,
3279 3277      ip_recv_attr_t *, int *);
3280 3278  extern boolean_t ip_input_local_options(mblk_t *, ipha_t *, ip_recv_attr_t *);
3281 3279  extern mblk_t   *ip_input_fragment(mblk_t *, ipha_t *, ip_recv_attr_t *);
3282 3280  extern mblk_t   *ip_input_fragment_v6(mblk_t *, ip6_t *, ip6_frag_t *, uint_t,
3283 3281      ip_recv_attr_t *);
3284 3282  extern void     ip_input_post_ipsec(mblk_t *, ip_recv_attr_t *);
3285 3283  extern void     ip_fanout_v4(mblk_t *, ipha_t *, ip_recv_attr_t *);
3286 3284  extern void     ip_fanout_v6(mblk_t *, ip6_t *, ip_recv_attr_t *);
3287 3285  extern void     ip_fanout_proto_conn(conn_t *, mblk_t *, ipha_t *, ip6_t *,
3288 3286      ip_recv_attr_t *);
3289 3287  extern void     ip_fanout_proto_v4(mblk_t *, ipha_t *, ip_recv_attr_t *);
3290 3288  extern void     ip_fanout_send_icmp_v4(mblk_t *, uint_t, uint_t,
3291 3289      ip_recv_attr_t *);
3292 3290  extern void     ip_fanout_udp_conn(conn_t *, mblk_t *, ipha_t *, ip6_t *,
3293 3291      ip_recv_attr_t *);
3294 3292  extern void     ip_fanout_udp_multi_v4(mblk_t *, ipha_t *, uint16_t, uint16_t,
3295 3293      ip_recv_attr_t *);
3296 3294  extern mblk_t   *zero_spi_check(mblk_t *, ip_recv_attr_t *);
3297 3295  extern void     ip_build_hdrs_v4(uchar_t *, uint_t, const ip_pkt_t *, uint8_t);
3298 3296  extern int      ip_find_hdr_v4(ipha_t *, ip_pkt_t *, boolean_t);
3299 3297  extern int      ip_total_hdrs_len_v4(const ip_pkt_t *);
3300 3298  
3301 3299  extern mblk_t   *ip_accept_tcp(ill_t *, ill_rx_ring_t *, squeue_t *,
3302 3300      mblk_t *, mblk_t **, uint_t *cnt);
3303 3301  extern void     ip_rput_dlpi(ill_t *, mblk_t *);
3304 3302  extern void     ip_rput_notdata(ill_t *, mblk_t *);
3305 3303  
3306 3304  extern void     ip_mib2_add_ip_stats(mib2_ipIfStatsEntry_t *,
3307 3305                      mib2_ipIfStatsEntry_t *);
3308 3306  extern void     ip_mib2_add_icmp6_stats(mib2_ipv6IfIcmpEntry_t *,
3309 3307                      mib2_ipv6IfIcmpEntry_t *);
3310 3308  extern void     ip_rput_other(ipsq_t *, queue_t *, mblk_t *, void *);
3311 3309  extern ire_t    *ip_check_multihome(void *, ire_t *, ill_t *);
3312 3310  extern void     ip_send_potential_redirect_v4(mblk_t *, ipha_t *, ire_t *,
3313 3311      ip_recv_attr_t *);
3314 3312  extern int      ip_set_destination_v4(ipaddr_t *, ipaddr_t, ipaddr_t,
3315 3313      ip_xmit_attr_t *, iulp_t *, uint32_t, uint_t);
3316 3314  extern int      ip_set_destination_v6(in6_addr_t *, const in6_addr_t *,
3317 3315      const in6_addr_t *, ip_xmit_attr_t *, iulp_t *, uint32_t, uint_t);
3318 3316  
3319 3317  extern int      ip_output_simple(mblk_t *, ip_xmit_attr_t *);
3320 3318  extern int      ip_output_simple_v4(mblk_t *, ip_xmit_attr_t *);
3321 3319  extern int      ip_output_simple_v6(mblk_t *, ip_xmit_attr_t *);
3322 3320  extern int      ip_output_options(mblk_t *, ipha_t *, ip_xmit_attr_t *,
3323 3321      ill_t *);
3324 3322  extern void     ip_output_local_options(ipha_t *, ip_stack_t *);
3325 3323  
3326 3324  extern ip_xmit_attr_t *conn_get_ixa(conn_t *, boolean_t);
3327 3325  extern ip_xmit_attr_t *conn_get_ixa_tryhard(conn_t *, boolean_t);
3328 3326  extern ip_xmit_attr_t *conn_replace_ixa(conn_t *, ip_xmit_attr_t *);
3329 3327  extern ip_xmit_attr_t *conn_get_ixa_exclusive(conn_t *);
3330 3328  extern ip_xmit_attr_t *ip_xmit_attr_duplicate(ip_xmit_attr_t *);
3331 3329  extern void     ip_xmit_attr_replace_tsl(ip_xmit_attr_t *, ts_label_t *);
3332 3330  extern void     ip_xmit_attr_restore_tsl(ip_xmit_attr_t *, cred_t *);
3333 3331  boolean_t       ip_recv_attr_replace_label(ip_recv_attr_t *, ts_label_t *);
3334 3332  extern void     ixa_inactive(ip_xmit_attr_t *);
3335 3333  extern void     ixa_refrele(ip_xmit_attr_t *);
3336 3334  extern boolean_t ixa_check_drain_insert(conn_t *, ip_xmit_attr_t *);
3337 3335  extern void     ixa_cleanup(ip_xmit_attr_t *);
3338 3336  extern void     ira_cleanup(ip_recv_attr_t *, boolean_t);
3339 3337  extern void     ixa_safe_copy(ip_xmit_attr_t *, ip_xmit_attr_t *);
3340 3338  
3341 3339  extern int      conn_ip_output(mblk_t *, ip_xmit_attr_t *);
3342 3340  extern boolean_t ip_output_verify_local(ip_xmit_attr_t *);
3343 3341  extern mblk_t   *ip_output_process_local(mblk_t *, ip_xmit_attr_t *, boolean_t,
3344 3342      boolean_t, conn_t *);
3345 3343  
3346 3344  extern int      conn_opt_get(conn_opt_arg_t *, t_scalar_t, t_scalar_t,
3347 3345      uchar_t *);
3348 3346  extern int      conn_opt_set(conn_opt_arg_t *, t_scalar_t, t_scalar_t, uint_t,
3349 3347      uchar_t *, boolean_t, cred_t *);
3350 3348  extern boolean_t        conn_same_as_last_v4(conn_t *, sin_t *);
3351 3349  extern boolean_t        conn_same_as_last_v6(conn_t *, sin6_t *);
3352 3350  extern int      conn_update_label(const conn_t *, const ip_xmit_attr_t *,
3353 3351      const in6_addr_t *, ip_pkt_t *);
3354 3352  
3355 3353  extern int      ip_opt_set_multicast_group(conn_t *, t_scalar_t,
3356 3354      uchar_t *, boolean_t, boolean_t);
3357 3355  extern int      ip_opt_set_multicast_sources(conn_t *, t_scalar_t,
3358 3356      uchar_t *, boolean_t, boolean_t);
3359 3357  extern int      conn_getsockname(conn_t *, struct sockaddr *, uint_t *);
3360 3358  extern int      conn_getpeername(conn_t *, struct sockaddr *, uint_t *);
3361 3359  
3362 3360  extern int      conn_build_hdr_template(conn_t *, uint_t, uint_t,
3363 3361      const in6_addr_t *, const in6_addr_t *, uint32_t);
3364 3362  extern mblk_t   *conn_prepend_hdr(ip_xmit_attr_t *, const ip_pkt_t *,
3365 3363      const in6_addr_t *, const in6_addr_t *, uint8_t, uint32_t, uint_t,
3366 3364      mblk_t *, uint_t, uint_t, uint32_t *, int *);
3367 3365  extern void     ip_attr_newdst(ip_xmit_attr_t *);
3368 3366  extern void     ip_attr_nexthop(const ip_pkt_t *, const ip_xmit_attr_t *,
3369 3367      const in6_addr_t *, in6_addr_t *);
3370 3368  extern int      conn_connect(conn_t *, iulp_t *, uint32_t);
3371 3369  extern int      ip_attr_connect(const conn_t *, ip_xmit_attr_t *,
3372 3370      const in6_addr_t *, const in6_addr_t *, const in6_addr_t *, in_port_t,
3373 3371      in6_addr_t *, iulp_t *, uint32_t);
3374 3372  extern int      conn_inherit_parent(conn_t *, conn_t *);
3375 3373  
3376 3374  extern void     conn_ixa_cleanup(conn_t *connp, void *arg);
3377 3375  
3378 3376  extern boolean_t conn_wantpacket(conn_t *, ip_recv_attr_t *, ipha_t *);
3379 3377  extern uint_t   ip_type_v4(ipaddr_t, ip_stack_t *);
3380 3378  extern uint_t   ip_type_v6(const in6_addr_t *, ip_stack_t *);
3381 3379  
3382 3380  extern int      ip_wput_nondata(queue_t *, mblk_t *);
3383 3381  extern int      ip_wsrv(queue_t *);
3384 3382  extern char     *ip_nv_lookup(nv_t *, int);
3385 3383  extern boolean_t ip_local_addr_ok_v6(const in6_addr_t *, const in6_addr_t *);
3386 3384  extern boolean_t ip_remote_addr_ok_v6(const in6_addr_t *, const in6_addr_t *);
3387 3385  extern ipaddr_t ip_massage_options(ipha_t *, netstack_t *);
3388 3386  extern ipaddr_t ip_net_mask(ipaddr_t);
3389 3387  extern void     arp_bringup_done(ill_t *, int);
3390 3388  extern void     arp_replumb_done(ill_t *, int);
3391 3389  
3392 3390  extern struct qinit iprinitv6;
3393 3391  
3394 3392  extern void     ipmp_init(ip_stack_t *);
3395 3393  extern void     ipmp_destroy(ip_stack_t *);
3396 3394  extern ipmp_grp_t *ipmp_grp_create(const char *, phyint_t *);
3397 3395  extern void     ipmp_grp_destroy(ipmp_grp_t *);
3398 3396  extern void     ipmp_grp_info(const ipmp_grp_t *, lifgroupinfo_t *);
3399 3397  extern int      ipmp_grp_rename(ipmp_grp_t *, const char *);
3400 3398  extern ipmp_grp_t *ipmp_grp_lookup(const char *, ip_stack_t *);
3401 3399  extern int      ipmp_grp_vet_phyint(ipmp_grp_t *, phyint_t *);
3402 3400  extern ipmp_illgrp_t *ipmp_illgrp_create(ill_t *);
3403 3401  extern void     ipmp_illgrp_destroy(ipmp_illgrp_t *);
3404 3402  extern ill_t    *ipmp_illgrp_add_ipif(ipmp_illgrp_t *, ipif_t *);
3405 3403  extern void     ipmp_illgrp_del_ipif(ipmp_illgrp_t *, ipif_t *);
3406 3404  extern ill_t    *ipmp_illgrp_next_ill(ipmp_illgrp_t *);
3407 3405  extern ill_t    *ipmp_illgrp_hold_next_ill(ipmp_illgrp_t *);
3408 3406  extern ill_t    *ipmp_illgrp_hold_cast_ill(ipmp_illgrp_t *);
3409 3407  extern ill_t    *ipmp_illgrp_ipmp_ill(ipmp_illgrp_t *);
3410 3408  extern void     ipmp_illgrp_refresh_mtu(ipmp_illgrp_t *);
3411 3409  extern ipmp_arpent_t *ipmp_illgrp_create_arpent(ipmp_illgrp_t *,
3412 3410      boolean_t, ipaddr_t, uchar_t *, size_t, uint16_t);
3413 3411  extern void     ipmp_illgrp_destroy_arpent(ipmp_illgrp_t *, ipmp_arpent_t *);
3414 3412  extern ipmp_arpent_t *ipmp_illgrp_lookup_arpent(ipmp_illgrp_t *, ipaddr_t *);
3415 3413  extern void     ipmp_illgrp_refresh_arpent(ipmp_illgrp_t *);
3416 3414  extern void     ipmp_illgrp_mark_arpent(ipmp_illgrp_t *, ipmp_arpent_t *);
3417 3415  extern ill_t    *ipmp_illgrp_find_ill(ipmp_illgrp_t *, uchar_t *, uint_t);
3418 3416  extern void     ipmp_illgrp_link_grp(ipmp_illgrp_t *, ipmp_grp_t *);
3419 3417  extern int      ipmp_illgrp_unlink_grp(ipmp_illgrp_t *);
3420 3418  extern uint_t   ipmp_ill_get_ipmp_ifindex(const ill_t *);
3421 3419  extern void     ipmp_ill_join_illgrp(ill_t *, ipmp_illgrp_t *);
3422 3420  extern void     ipmp_ill_leave_illgrp(ill_t *);
3423 3421  extern ill_t    *ipmp_ill_hold_ipmp_ill(ill_t *);
3424 3422  extern ill_t    *ipmp_ill_hold_xmit_ill(ill_t *, boolean_t);
3425 3423  extern boolean_t ipmp_ill_is_active(ill_t *);
3426 3424  extern void     ipmp_ill_refresh_active(ill_t *);
3427 3425  extern void     ipmp_phyint_join_grp(phyint_t *, ipmp_grp_t *);
3428 3426  extern void     ipmp_phyint_leave_grp(phyint_t *);
3429 3427  extern void     ipmp_phyint_refresh_active(phyint_t *);
3430 3428  extern ill_t    *ipmp_ipif_bound_ill(const ipif_t *);
3431 3429  extern ill_t    *ipmp_ipif_hold_bound_ill(const ipif_t *);
3432 3430  extern boolean_t ipmp_ipif_is_dataaddr(const ipif_t *);
3433 3431  extern boolean_t ipmp_ipif_is_stubaddr(const ipif_t *);
3434 3432  extern boolean_t ipmp_packet_is_probe(mblk_t *, ill_t *);
3435 3433  extern void     ipmp_ncec_delete_nce(ncec_t *);
3436 3434  extern void     ipmp_ncec_refresh_nce(ncec_t *);
3437 3435  
3438 3436  extern void     conn_drain_insert(conn_t *, idl_tx_list_t *);
3439 3437  extern void     conn_setqfull(conn_t *, boolean_t *);
3440 3438  extern void     conn_clrqfull(conn_t *, boolean_t *);
3441 3439  extern int      conn_ipsec_length(conn_t *);
3442 3440  extern ipaddr_t ip_get_dst(ipha_t *);
3443 3441  extern uint_t   ip_get_pmtu(ip_xmit_attr_t *);
3444 3442  extern uint_t   ip_get_base_mtu(ill_t *, ire_t *);
3445 3443  extern mblk_t *ip_output_attach_policy(mblk_t *, ipha_t *, ip6_t *,
3446 3444      const conn_t *, ip_xmit_attr_t *);
3447 3445  extern int      ipsec_out_extra_length(ip_xmit_attr_t *);
3448 3446  extern int      ipsec_out_process(mblk_t *, ip_xmit_attr_t *);
3449 3447  extern int      ip_output_post_ipsec(mblk_t *, ip_xmit_attr_t *);
3450 3448  extern void     ipsec_out_to_in(ip_xmit_attr_t *, ill_t *ill,
3451 3449      ip_recv_attr_t *);
3452 3450  
3453 3451  extern void     ire_cleanup(ire_t *);
3454 3452  extern void     ire_inactive(ire_t *);
3455 3453  extern boolean_t irb_inactive(irb_t *);
3456 3454  extern ire_t    *ire_unlink(irb_t *);
3457 3455  
3458 3456  #ifdef DEBUG
3459 3457  extern  boolean_t th_trace_ref(const void *, ip_stack_t *);
3460 3458  extern  void    th_trace_unref(const void *);
3461 3459  extern  void    th_trace_cleanup(const void *, boolean_t);
3462 3460  extern  void    ire_trace_ref(ire_t *);
3463 3461  extern  void    ire_untrace_ref(ire_t *);
3464 3462  #endif
3465 3463  
3466 3464  extern int      ip_srcid_insert(const in6_addr_t *, zoneid_t, ip_stack_t *);
3467 3465  extern int      ip_srcid_remove(const in6_addr_t *, zoneid_t, ip_stack_t *);
3468 3466  extern boolean_t ip_srcid_find_id(uint_t, in6_addr_t *, zoneid_t, boolean_t,
3469 3467      netstack_t *);
3470 3468  extern uint_t   ip_srcid_find_addr(const in6_addr_t *, zoneid_t, netstack_t *);
3471 3469  
3472 3470  extern uint8_t  ipoptp_next(ipoptp_t *);
3473 3471  extern uint8_t  ipoptp_first(ipoptp_t *, ipha_t *);
3474 3472  extern int      ip_opt_get_user(conn_t *, uchar_t *);
3475 3473  extern int      ipsec_req_from_conn(conn_t *, ipsec_req_t *, int);
3476 3474  extern int      ip_snmp_get(queue_t *q, mblk_t *mctl, int level, boolean_t);
3477 3475  extern int      ip_snmp_set(queue_t *q, int, int, uchar_t *, int);
3478 3476  extern void     ip_process_ioctl(ipsq_t *, queue_t *, mblk_t *, void *);
3479 3477  extern void     ip_quiesce_conn(conn_t *);
3480 3478  extern  void    ip_reprocess_ioctl(ipsq_t *, queue_t *, mblk_t *, void *);
3481 3479  extern void     ip_ioctl_finish(queue_t *, mblk_t *, int, int, ipsq_t *);
3482 3480  
3483 3481  extern boolean_t ip_cmpbuf(const void *, uint_t, boolean_t, const void *,
3484 3482      uint_t);
3485 3483  extern boolean_t ip_allocbuf(void **, uint_t *, boolean_t, const void *,
3486 3484      uint_t);
3487 3485  extern void     ip_savebuf(void **, uint_t *, boolean_t, const void *, uint_t);
3488 3486  
3489 3487  extern boolean_t        ipsq_pending_mp_cleanup(ill_t *, conn_t *);
3490 3488  extern void     conn_ioctl_cleanup(conn_t *);
3491 3489  
3492 3490  extern void     ip_unbind(conn_t *);
3493 3491  
3494 3492  extern void tnet_init(void);
3495 3493  extern void tnet_fini(void);
3496 3494  
3497 3495  /*
3498 3496   * Hook functions to enable cluster networking
3499 3497   * On non-clustered systems these vectors must always be NULL.
3500 3498   */
3501 3499  extern int (*cl_inet_isclusterwide)(netstackid_t stack_id, uint8_t protocol,
3502 3500      sa_family_t addr_family, uint8_t *laddrp, void *args);
3503 3501  extern uint32_t (*cl_inet_ipident)(netstackid_t stack_id, uint8_t protocol,
3504 3502      sa_family_t addr_family, uint8_t *laddrp, uint8_t *faddrp,
3505 3503      void *args);
3506 3504  extern int (*cl_inet_connect2)(netstackid_t stack_id, uint8_t protocol,
3507 3505      boolean_t is_outgoing, sa_family_t addr_family, uint8_t *laddrp,
3508 3506      in_port_t lport, uint8_t *faddrp, in_port_t fport, void *args);
3509 3507  extern void (*cl_inet_getspi)(netstackid_t, uint8_t, uint8_t *, size_t,
3510 3508      void *);
3511 3509  extern void (*cl_inet_getspi)(netstackid_t stack_id, uint8_t protocol,
3512 3510      uint8_t *ptr, size_t len, void *args);
3513 3511  extern int (*cl_inet_checkspi)(netstackid_t stack_id, uint8_t protocol,
3514 3512      uint32_t spi, void *args);
3515 3513  extern void (*cl_inet_deletespi)(netstackid_t stack_id, uint8_t protocol,
3516 3514      uint32_t spi, void *args);
3517 3515  extern void (*cl_inet_idlesa)(netstackid_t, uint8_t, uint32_t,
3518 3516      sa_family_t, in6_addr_t, in6_addr_t, void *);
3519 3517  
3520 3518  
3521 3519  /* Hooks for CGTP (multirt routes) filtering module */
3522 3520  #define CGTP_FILTER_REV_1       1
3523 3521  #define CGTP_FILTER_REV_2       2
3524 3522  #define CGTP_FILTER_REV_3       3
3525 3523  #define CGTP_FILTER_REV         CGTP_FILTER_REV_3
3526 3524  
3527 3525  /* cfo_filter and cfo_filter_v6 hooks return values */
3528 3526  #define CGTP_IP_PKT_NOT_CGTP    0
3529 3527  #define CGTP_IP_PKT_PREMIUM     1
3530 3528  #define CGTP_IP_PKT_DUPLICATE   2
3531 3529  
3532 3530  /* Version 3 of the filter interface */
3533 3531  typedef struct cgtp_filter_ops {
3534 3532          int     cfo_filter_rev;                 /* CGTP_FILTER_REV_3 */
3535 3533          int     (*cfo_change_state)(netstackid_t, int);
3536 3534          int     (*cfo_add_dest_v4)(netstackid_t, ipaddr_t, ipaddr_t,
3537 3535                      ipaddr_t, ipaddr_t);
3538 3536          int     (*cfo_del_dest_v4)(netstackid_t, ipaddr_t, ipaddr_t);
3539 3537          int     (*cfo_add_dest_v6)(netstackid_t, in6_addr_t *, in6_addr_t *,
3540 3538                      in6_addr_t *, in6_addr_t *);
3541 3539          int     (*cfo_del_dest_v6)(netstackid_t, in6_addr_t *, in6_addr_t *);
3542 3540          int     (*cfo_filter)(netstackid_t, uint_t, mblk_t *);
3543 3541          int     (*cfo_filter_v6)(netstackid_t, uint_t, ip6_t *,
3544 3542                      ip6_frag_t *);
3545 3543  } cgtp_filter_ops_t;
3546 3544  
3547 3545  #define CGTP_MCAST_SUCCESS      1
3548 3546  
3549 3547  /*
3550 3548   * The separate CGTP module needs this global symbol so that it
3551 3549   * can check the version and determine whether to use the old or the new
3552 3550   * version of the filtering interface.
3553 3551   */
3554 3552  extern int      ip_cgtp_filter_rev;
3555 3553  
3556 3554  extern int      ip_cgtp_filter_supported(void);
3557 3555  extern int      ip_cgtp_filter_register(netstackid_t, cgtp_filter_ops_t *);
3558 3556  extern int      ip_cgtp_filter_unregister(netstackid_t);
3559 3557  extern int      ip_cgtp_filter_is_registered(netstackid_t);
3560 3558  
3561 3559  /*
3562 3560   * rr_ring_state cycles in the order shown below from RR_FREE through
3563 3561   * RR_FREE_IN_PROG and  back to RR_FREE.
3564 3562   */
3565 3563  typedef enum {
3566 3564          RR_FREE,                        /* Free slot */
3567 3565          RR_SQUEUE_UNBOUND,              /* Ring's squeue is unbound */
3568 3566          RR_SQUEUE_BIND_INPROG,          /* Ring's squeue bind in progress */
3569 3567          RR_SQUEUE_BOUND,                /* Ring's squeue bound to cpu */
3570 3568          RR_FREE_INPROG                  /* Ring is being freed */
3571 3569  } ip_ring_state_t;
3572 3570  
3573 3571  #define ILL_MAX_RINGS           256     /* Max num of rx rings we can manage */
3574 3572  #define ILL_POLLING             0x01    /* Polling in use */
3575 3573  
3576 3574  /*
3577 3575   * These functions pointer types are exported by the mac/dls layer.
3578 3576   * we need to duplicate the definitions here because we cannot
3579 3577   * include mac/dls header files here.
3580 3578   */
3581 3579  typedef boolean_t               (*ip_mac_intr_disable_t)(void *);
3582 3580  typedef int                     (*ip_mac_intr_enable_t)(void *);
3583 3581  typedef ip_mac_tx_cookie_t      (*ip_dld_tx_t)(void *, mblk_t *,
3584 3582      uint64_t, uint16_t);
3585 3583  typedef void                    (*ip_flow_enable_t)(void *, ip_mac_tx_cookie_t);
3586 3584  typedef void                    *(*ip_dld_callb_t)(void *,
3587 3585      ip_flow_enable_t, void *);
3588 3586  typedef boolean_t               (*ip_dld_fctl_t)(void *, ip_mac_tx_cookie_t);
3589 3587  typedef boolean_t               (*ip_mac_ipcheck_t)(void *, boolean_t,
3590 3588      in6_addr_t *);
3591 3589  typedef int                     (*ip_capab_func_t)(void *, uint_t,
3592 3590      void *, uint_t);
3593 3591  
3594 3592  /*
3595 3593   * POLLING README
3596 3594   * sq_get_pkts() is called to pick packets from softring in poll mode. It
3597 3595   * calls rr_rx to get the chain and process it with rr_ip_accept.
3598 3596   * rr_rx = mac_soft_ring_poll() to pick packets
3599 3597   * rr_ip_accept = ip_accept_tcp() to process packets
3600 3598   */
3601 3599  
3602 3600  /*
3603 3601   * XXX: With protocol, service specific squeues, they will have
3604 3602   * specific acceptor functions.
3605 3603   */
3606 3604  typedef mblk_t *(*ip_mac_rx_t)(void *, size_t);
3607 3605  typedef mblk_t *(*ip_accept_t)(ill_t *, ill_rx_ring_t *,
3608 3606      squeue_t *, mblk_t *, mblk_t **, uint_t *);
3609 3607  
3610 3608  /*
3611 3609   * rr_intr_enable, rr_intr_disable, rr_rx_handle, rr_rx:
3612 3610   * May be accessed while in the squeue AND after checking that SQS_POLL_CAPAB
3613 3611   * is set.
3614 3612   *
3615 3613   * rr_ring_state: Protected by ill_lock.
3616 3614   */
3617 3615  struct ill_rx_ring {
3618 3616          ip_mac_intr_disable_t   rr_intr_disable; /* Interrupt disabling func */
3619 3617          ip_mac_intr_enable_t    rr_intr_enable; /* Interrupt enabling func */
3620 3618          void                    *rr_intr_handle; /* Handle interrupt funcs */
3621 3619          ip_mac_rx_t             rr_rx;          /* Driver receive function */
3622 3620          ip_accept_t             rr_ip_accept;   /* IP accept function */
3623 3621          void                    *rr_rx_handle;  /* Handle for Rx ring */
3624 3622          squeue_t                *rr_sqp; /* Squeue the ring is bound to */
3625 3623          ill_t                   *rr_ill;        /* back pointer to ill */
3626 3624          ip_ring_state_t         rr_ring_state;  /* State of this ring */
3627 3625  };
3628 3626  
3629 3627  /*
3630 3628   * IP - DLD direct function call capability
3631 3629   * Suffixes, df - dld function, dh - dld handle,
3632 3630   * cf - client (IP) function, ch - client handle
3633 3631   */
3634 3632  typedef struct ill_dld_direct_s {               /* DLD provided driver Tx */
3635 3633          ip_dld_tx_t             idd_tx_df;      /* str_mdata_fastpath_put */
3636 3634          void                    *idd_tx_dh;     /* dld_str_t *dsp */
3637 3635          ip_dld_callb_t          idd_tx_cb_df;   /* mac_tx_srs_notify */
3638 3636          void                    *idd_tx_cb_dh;  /* mac_client_handle_t *mch */
3639 3637          ip_dld_fctl_t           idd_tx_fctl_df; /* mac_tx_is_flow_blocked */
3640 3638          void                    *idd_tx_fctl_dh;        /* mac_client_handle */
3641 3639  } ill_dld_direct_t;
3642 3640  
3643 3641  /* IP - DLD direct function call to check if an IP is allowed */
3644 3642  typedef struct ill_dld_ipcheck_s {
3645 3643          ip_mac_ipcheck_t        idi_allowed_df;
3646 3644          void                    *idi_allowed_dh;
3647 3645  } ill_dld_ipcheck_t;
3648 3646  
3649 3647  /* IP - DLD polling capability */
3650 3648  typedef struct ill_dld_poll_s {
3651 3649          ill_rx_ring_t           idp_ring_tbl[ILL_MAX_RINGS];
3652 3650  } ill_dld_poll_t;
3653 3651  
3654 3652  /* Describes ill->ill_dld_capab */
3655 3653  struct ill_dld_capab_s {
3656 3654          ip_capab_func_t         idc_capab_df;   /* dld_capab_func */
3657 3655          void                    *idc_capab_dh;  /* dld_str_t *dsp */
3658 3656          ill_dld_direct_t        idc_direct;
3659 3657          ill_dld_poll_t          idc_poll;
3660 3658          ill_dld_ipcheck_t       idc_ipcheck;
3661 3659  };
3662 3660  
3663 3661  /*
3664 3662   * IP squeues exports
3665 3663   */
3666 3664  extern boolean_t        ip_squeue_fanout;
3667 3665  
3668 3666  #define IP_SQUEUE_GET(hint) ip_squeue_random(hint)
3669 3667  
3670 3668  extern void ip_squeue_init(void (*)(squeue_t *));
3671 3669  extern squeue_t *ip_squeue_random(uint_t);
3672 3670  extern squeue_t *ip_squeue_get(ill_rx_ring_t *);
3673 3671  extern squeue_t *ip_squeue_getfree(pri_t);
3674 3672  extern int ip_squeue_cpu_move(squeue_t *, processorid_t);
3675 3673  extern void *ip_squeue_add_ring(ill_t *, void *);
3676 3674  extern void ip_squeue_bind_ring(ill_t *, ill_rx_ring_t *, processorid_t);
3677 3675  extern void ip_squeue_clean_ring(ill_t *, ill_rx_ring_t *);
3678 3676  extern void ip_squeue_quiesce_ring(ill_t *, ill_rx_ring_t *);
3679 3677  extern void ip_squeue_restart_ring(ill_t *, ill_rx_ring_t *);
3680 3678  extern void ip_squeue_clean_all(ill_t *);
3681 3679  extern boolean_t        ip_source_routed(ipha_t *, ip_stack_t *);
3682 3680  
3683 3681  extern int tcp_wput(queue_t *, mblk_t *);
3684 3682  
3685 3683  extern int      ip_fill_mtuinfo(conn_t *, ip_xmit_attr_t *,
3686 3684      struct ip6_mtuinfo *);
3687 3685  extern hook_t *ipobs_register_hook(netstack_t *, pfv_t);
3688 3686  extern void ipobs_unregister_hook(netstack_t *, hook_t *);
3689 3687  extern void ipobs_hook(mblk_t *, int, zoneid_t, zoneid_t, const ill_t *,
3690 3688      ip_stack_t *);
3691 3689  typedef void    (*ipsq_func_t)(ipsq_t *, queue_t *, mblk_t *, void *);
3692 3690  
3693 3691  extern void     dce_g_init(void);
3694 3692  extern void     dce_g_destroy(void);
3695 3693  extern void     dce_stack_init(ip_stack_t *);
3696 3694  extern void     dce_stack_destroy(ip_stack_t *);
3697 3695  extern void     dce_cleanup(uint_t, ip_stack_t *);
3698 3696  extern dce_t    *dce_get_default(ip_stack_t *);
3699 3697  extern dce_t    *dce_lookup_pkt(mblk_t *, ip_xmit_attr_t *, uint_t *);
3700 3698  extern dce_t    *dce_lookup_v4(ipaddr_t, ip_stack_t *, uint_t *);
3701 3699  extern dce_t    *dce_lookup_v6(const in6_addr_t *, uint_t, ip_stack_t *,
3702 3700      uint_t *);
3703 3701  extern dce_t    *dce_lookup_and_add_v4(ipaddr_t, ip_stack_t *);
3704 3702  extern dce_t    *dce_lookup_and_add_v6(const in6_addr_t *, uint_t,
3705 3703      ip_stack_t *);
3706 3704  extern int      dce_update_uinfo_v4(ipaddr_t, iulp_t *, ip_stack_t *);
3707 3705  extern int      dce_update_uinfo_v6(const in6_addr_t *, uint_t, iulp_t *,
3708 3706      ip_stack_t *);
3709 3707  extern int      dce_update_uinfo(const in6_addr_t *, uint_t, iulp_t *,
3710 3708      ip_stack_t *);
3711 3709  extern void     dce_increment_generation(dce_t *);
3712 3710  extern void     dce_increment_all_generations(boolean_t, ip_stack_t *);
3713 3711  extern void     dce_refrele(dce_t *);
3714 3712  extern void     dce_refhold(dce_t *);
3715 3713  extern void     dce_refrele_notr(dce_t *);
3716 3714  extern void     dce_refhold_notr(dce_t *);
3717 3715  mblk_t          *ip_snmp_get_mib2_ip_dce(queue_t *, mblk_t *, ip_stack_t *ipst);
3718 3716  
3719 3717  extern ip_laddr_t ip_laddr_verify_v4(ipaddr_t, zoneid_t,
3720 3718      ip_stack_t *, boolean_t);
3721 3719  extern ip_laddr_t ip_laddr_verify_v6(const in6_addr_t *, zoneid_t,
3722 3720      ip_stack_t *, boolean_t, uint_t);
3723 3721  extern int      ip_laddr_fanout_insert(conn_t *);
3724 3722  
3725 3723  extern boolean_t ip_verify_src(mblk_t *, ip_xmit_attr_t *, uint_t *);
3726 3724  extern int      ip_verify_ire(mblk_t *, ip_xmit_attr_t *);
3727 3725  
3728 3726  extern mblk_t   *ip_xmit_attr_to_mblk(ip_xmit_attr_t *);
3729 3727  extern boolean_t ip_xmit_attr_from_mblk(mblk_t *, ip_xmit_attr_t *);
3730 3728  extern mblk_t   *ip_xmit_attr_free_mblk(mblk_t *);
3731 3729  extern mblk_t   *ip_recv_attr_to_mblk(ip_recv_attr_t *);
3732 3730  extern boolean_t ip_recv_attr_from_mblk(mblk_t *, ip_recv_attr_t *);
3733 3731  extern mblk_t   *ip_recv_attr_free_mblk(mblk_t *);
3734 3732  extern boolean_t ip_recv_attr_is_mblk(mblk_t *);
3735 3733  
3736 3734  #ifdef  __PRAGMA_REDEFINE_EXTNAME
3737 3735  #pragma redefine_extname inet_ntop _inet_ntop
3738 3736  #pragma redefine_extname inet_pton _inet_pton
3739 3737  #else
3740 3738  #define inet_ntop _inet_ntop
3741 3739  #define inet_pton _inet_pton
3742 3740  #endif  /* __PRAGMA_REDEFINE_EXTNAME */
3743 3741  
3744 3742  extern char     *inet_ntop(int, const void *, char *, int);
3745 3743  extern int      inet_pton(int, char *, void *);
3746 3744  
3747 3745  /*
3748 3746   * Squeue tags. Tags only need to be unique when the callback function is the
3749 3747   * same to distinguish between different calls, but we use unique tags for
3750 3748   * convenience anyway.
3751 3749   */
3752 3750  #define SQTAG_IP_INPUT                  1
3753 3751  #define SQTAG_TCP_INPUT_ICMP_ERR        2
3754 3752  #define SQTAG_TCP6_INPUT_ICMP_ERR       3
3755 3753  #define SQTAG_IP_TCP_INPUT              4
3756 3754  #define SQTAG_IP6_TCP_INPUT             5
3757 3755  #define SQTAG_IP_TCP_CLOSE              6
3758 3756  #define SQTAG_TCP_OUTPUT                7
3759 3757  #define SQTAG_TCP_TIMER                 8
3760 3758  #define SQTAG_TCP_TIMEWAIT              9
3761 3759  #define SQTAG_TCP_ACCEPT_FINISH         10
3762 3760  #define SQTAG_TCP_ACCEPT_FINISH_Q0      11
3763 3761  #define SQTAG_TCP_ACCEPT_PENDING        12
3764 3762  #define SQTAG_TCP_LISTEN_DISCON         13
3765 3763  #define SQTAG_TCP_CONN_REQ_1            14
3766 3764  #define SQTAG_TCP_EAGER_BLOWOFF         15
3767 3765  #define SQTAG_TCP_EAGER_CLEANUP         16
3768 3766  #define SQTAG_TCP_EAGER_CLEANUP_Q0      17
3769 3767  #define SQTAG_TCP_CONN_IND              18
3770 3768  #define SQTAG_TCP_RSRV                  19
3771 3769  #define SQTAG_TCP_ABORT_BUCKET          20
3772 3770  #define SQTAG_TCP_REINPUT               21
3773 3771  #define SQTAG_TCP_REINPUT_EAGER         22
3774 3772  #define SQTAG_TCP_INPUT_MCTL            23
3775 3773  #define SQTAG_TCP_RPUTOTHER             24
3776 3774  #define SQTAG_IP_PROTO_AGAIN            25
3777 3775  #define SQTAG_IP_FANOUT_TCP             26
3778 3776  #define SQTAG_IPSQ_CLEAN_RING           27
3779 3777  #define SQTAG_TCP_WPUT_OTHER            28
3780 3778  #define SQTAG_TCP_CONN_REQ_UNBOUND      29
3781 3779  #define SQTAG_TCP_SEND_PENDING          30
3782 3780  #define SQTAG_BIND_RETRY                31
3783 3781  #define SQTAG_UDP_FANOUT                32
3784 3782  #define SQTAG_UDP_INPUT                 33
3785 3783  #define SQTAG_UDP_WPUT                  34
3786 3784  #define SQTAG_UDP_OUTPUT                35
3787 3785  #define SQTAG_TCP_KSSL_INPUT            36
3788 3786  #define SQTAG_TCP_DROP_Q0               37
3789 3787  #define SQTAG_TCP_CONN_REQ_2            38
3790 3788  #define SQTAG_IP_INPUT_RX_RING          39
3791 3789  #define SQTAG_SQUEUE_CHANGE             40
3792 3790  #define SQTAG_CONNECT_FINISH            41
3793 3791  #define SQTAG_SYNCHRONOUS_OP            42
3794 3792  #define SQTAG_TCP_SHUTDOWN_OUTPUT       43
3795 3793  #define SQTAG_TCP_IXA_CLEANUP           44
3796 3794  #define SQTAG_TCP_SEND_SYNACK           45
3797 3795  
3798 3796  extern sin_t    sin_null;       /* Zero address for quick clears */
3799 3797  extern sin6_t   sin6_null;      /* Zero address for quick clears */
3800 3798  
3801 3799  #endif  /* _KERNEL */
3802 3800  
3803 3801  #ifdef  __cplusplus
3804 3802  }
3805 3803  #endif
3806 3804  
3807 3805  #endif  /* _INET_IP_H */
  
    | 
      ↓ open down ↓ | 
    2063 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX