10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51289Sja97890 * Common Development and Distribution License (the "License"). 61289Sja97890 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 221289Sja97890 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate /* Copyright (c) 1990 Mentat Inc. */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate 280Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 290Sstevel@tonic-gate 300Sstevel@tonic-gate #include <sys/types.h> 310Sstevel@tonic-gate #include <sys/stream.h> 320Sstevel@tonic-gate #include <sys/stropts.h> 330Sstevel@tonic-gate #include <sys/strlog.h> 340Sstevel@tonic-gate #include <sys/strsun.h> 350Sstevel@tonic-gate #define _SUN_TPI_VERSION 2 360Sstevel@tonic-gate #include <sys/tihdr.h> 370Sstevel@tonic-gate #include <sys/timod.h> 380Sstevel@tonic-gate #include <sys/ddi.h> 390Sstevel@tonic-gate #include <sys/sunddi.h> 401676Sjpk #include <sys/strsubr.h> 410Sstevel@tonic-gate #include <sys/cmn_err.h> 420Sstevel@tonic-gate #include <sys/debug.h> 430Sstevel@tonic-gate #include <sys/kmem.h> 440Sstevel@tonic-gate #include <sys/policy.h> 451676Sjpk #include <sys/priv.h> 460Sstevel@tonic-gate #include <sys/zone.h> 471673Sgt145670 #include <sys/time.h> 480Sstevel@tonic-gate 490Sstevel@tonic-gate #include <sys/socket.h> 500Sstevel@tonic-gate #include <sys/isa_defs.h> 510Sstevel@tonic-gate #include <sys/suntpi.h> 520Sstevel@tonic-gate #include <sys/xti_inet.h> 530Sstevel@tonic-gate 540Sstevel@tonic-gate #include <net/route.h> 550Sstevel@tonic-gate #include <net/if.h> 560Sstevel@tonic-gate 570Sstevel@tonic-gate #include <netinet/in.h> 580Sstevel@tonic-gate #include <netinet/ip6.h> 590Sstevel@tonic-gate #include <netinet/icmp6.h> 600Sstevel@tonic-gate #include <inet/common.h> 610Sstevel@tonic-gate #include <inet/ip.h> 620Sstevel@tonic-gate #include <inet/ip6.h> 630Sstevel@tonic-gate #include <inet/mi.h> 640Sstevel@tonic-gate #include <inet/nd.h> 650Sstevel@tonic-gate #include <inet/optcom.h> 660Sstevel@tonic-gate #include <inet/snmpcom.h> 670Sstevel@tonic-gate #include <inet/kstatcom.h> 680Sstevel@tonic-gate #include <inet/rawip_impl.h> 690Sstevel@tonic-gate 700Sstevel@tonic-gate #include <netinet/ip_mroute.h> 710Sstevel@tonic-gate #include <inet/tcp.h> 720Sstevel@tonic-gate #include <net/pfkeyv2.h> 730Sstevel@tonic-gate #include <inet/ipsec_info.h> 740Sstevel@tonic-gate #include <inet/ipclassifier.h> 750Sstevel@tonic-gate 761676Sjpk #include <sys/tsol/label.h> 771676Sjpk #include <sys/tsol/tnet.h> 781676Sjpk 79*3318Srshoaib #include <inet/ip_ire.h> 80*3318Srshoaib #include <inet/ip_if.h> 81*3318Srshoaib 82*3318Srshoaib #include <inet/ip_impl.h> 83*3318Srshoaib 840Sstevel@tonic-gate #define ICMP6 "icmp6" 850Sstevel@tonic-gate major_t ICMP6_MAJ; 860Sstevel@tonic-gate 870Sstevel@tonic-gate /* 880Sstevel@tonic-gate * Object to represent database of options to search passed to 890Sstevel@tonic-gate * {sock,tpi}optcom_req() interface routine to take care of option 900Sstevel@tonic-gate * management and associated methods. 910Sstevel@tonic-gate * XXX These and other extern's should really move to a icmp header. 920Sstevel@tonic-gate */ 930Sstevel@tonic-gate extern optdb_obj_t icmp_opt_obj; 940Sstevel@tonic-gate extern uint_t icmp_max_optsize; 950Sstevel@tonic-gate 960Sstevel@tonic-gate /* 970Sstevel@tonic-gate * Synchronization notes: 980Sstevel@tonic-gate * 990Sstevel@tonic-gate * At all points in this code where exclusive access is required, we 1000Sstevel@tonic-gate * pass a message to a subroutine by invoking qwriter(..., PERIM_OUTER) 1010Sstevel@tonic-gate * which will arrange to call the routine only after all threads have 1020Sstevel@tonic-gate * exited the shared resource. 1030Sstevel@tonic-gate */ 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate /* Named Dispatch Parameter Management Structure */ 1060Sstevel@tonic-gate typedef struct icmpparam_s { 1070Sstevel@tonic-gate uint_t icmp_param_min; 1080Sstevel@tonic-gate uint_t icmp_param_max; 1090Sstevel@tonic-gate uint_t icmp_param_value; 1100Sstevel@tonic-gate char *icmp_param_name; 1110Sstevel@tonic-gate } icmpparam_t; 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate static void icmp_addr_req(queue_t *q, mblk_t *mp); 1140Sstevel@tonic-gate static void icmp_bind(queue_t *q, mblk_t *mp); 1150Sstevel@tonic-gate static void icmp_bind_proto(queue_t *q); 1160Sstevel@tonic-gate static int icmp_build_hdrs(queue_t *q, icmp_t *icmp); 1170Sstevel@tonic-gate static void icmp_capability_req(queue_t *q, mblk_t *mp); 1180Sstevel@tonic-gate static int icmp_close(queue_t *q); 1190Sstevel@tonic-gate static void icmp_connect(queue_t *q, mblk_t *mp); 1200Sstevel@tonic-gate static void icmp_disconnect(queue_t *q, mblk_t *mp); 1210Sstevel@tonic-gate static void icmp_err_ack(queue_t *q, mblk_t *mp, t_scalar_t t_error, 1220Sstevel@tonic-gate int sys_error); 1230Sstevel@tonic-gate static void icmp_err_ack_prim(queue_t *q, mblk_t *mp, t_scalar_t primitive, 1240Sstevel@tonic-gate t_scalar_t t_error, int sys_error); 1250Sstevel@tonic-gate static void icmp_icmp_error(queue_t *q, mblk_t *mp); 1260Sstevel@tonic-gate static void icmp_icmp_error_ipv6(queue_t *q, mblk_t *mp); 1270Sstevel@tonic-gate static void icmp_info_req(queue_t *q, mblk_t *mp); 1280Sstevel@tonic-gate static mblk_t *icmp_ip_bind_mp(icmp_t *icmp, t_scalar_t bind_prim, 1290Sstevel@tonic-gate t_scalar_t addr_length, in_port_t); 1300Sstevel@tonic-gate static int icmp_open(queue_t *q, dev_t *devp, int flag, 1310Sstevel@tonic-gate int sflag, cred_t *credp); 1320Sstevel@tonic-gate static int icmp_unitdata_opt_process(queue_t *q, mblk_t *mp, 1330Sstevel@tonic-gate int *errorp, void *thisdg_attrs); 1340Sstevel@tonic-gate static boolean_t icmp_opt_allow_udr_set(t_scalar_t level, t_scalar_t name); 1350Sstevel@tonic-gate int icmp_opt_set(queue_t *q, uint_t optset_context, 1360Sstevel@tonic-gate int level, int name, uint_t inlen, 1370Sstevel@tonic-gate uchar_t *invalp, uint_t *outlenp, uchar_t *outvalp, 1380Sstevel@tonic-gate void *thisdg_attrs, cred_t *cr, mblk_t *mblk); 1390Sstevel@tonic-gate int icmp_opt_get(queue_t *q, int level, int name, 1400Sstevel@tonic-gate uchar_t *ptr); 1410Sstevel@tonic-gate static int icmp_param_get(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr); 1420Sstevel@tonic-gate static boolean_t icmp_param_register(icmpparam_t *icmppa, int cnt); 1430Sstevel@tonic-gate static int icmp_param_set(queue_t *q, mblk_t *mp, char *value, 1440Sstevel@tonic-gate caddr_t cp, cred_t *cr); 1450Sstevel@tonic-gate static void icmp_rput(queue_t *q, mblk_t *mp); 1460Sstevel@tonic-gate static void icmp_rput_bind_ack(queue_t *q, mblk_t *mp); 1470Sstevel@tonic-gate static int icmp_snmp_get(queue_t *q, mblk_t *mpctl); 1480Sstevel@tonic-gate static int icmp_snmp_set(queue_t *q, t_scalar_t level, t_scalar_t name, 1490Sstevel@tonic-gate uchar_t *ptr, int len); 1500Sstevel@tonic-gate static int icmp_status_report(queue_t *q, mblk_t *mp, caddr_t cp, 1510Sstevel@tonic-gate cred_t *cr); 1520Sstevel@tonic-gate static void icmp_ud_err(queue_t *q, mblk_t *mp, t_scalar_t err); 1530Sstevel@tonic-gate static void icmp_unbind(queue_t *q, mblk_t *mp); 1540Sstevel@tonic-gate static void icmp_wput(queue_t *q, mblk_t *mp); 1550Sstevel@tonic-gate static void icmp_wput_ipv6(queue_t *q, mblk_t *mp, sin6_t *sin6, 1560Sstevel@tonic-gate t_scalar_t tudr_optlen); 1570Sstevel@tonic-gate static void icmp_wput_other(queue_t *q, mblk_t *mp); 1580Sstevel@tonic-gate static void icmp_wput_iocdata(queue_t *q, mblk_t *mp); 1590Sstevel@tonic-gate static void icmp_wput_restricted(queue_t *q, mblk_t *mp); 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate static void rawip_kstat_init(void); 1620Sstevel@tonic-gate static void rawip_kstat_fini(void); 1630Sstevel@tonic-gate static int rawip_kstat_update(kstat_t *kp, int rw); 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate static struct module_info info = { 1670Sstevel@tonic-gate 5707, "icmp", 1, INFPSZ, 512, 128 1680Sstevel@tonic-gate }; 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate static struct qinit rinit = { 1710Sstevel@tonic-gate (pfi_t)icmp_rput, NULL, icmp_open, icmp_close, NULL, &info 1720Sstevel@tonic-gate }; 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate static struct qinit winit = { 1750Sstevel@tonic-gate (pfi_t)icmp_wput, NULL, NULL, NULL, NULL, &info 1760Sstevel@tonic-gate }; 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate struct streamtab icmpinfo = { 1790Sstevel@tonic-gate &rinit, &winit 1800Sstevel@tonic-gate }; 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate static sin_t sin_null; /* Zero address for quick clears */ 1830Sstevel@tonic-gate static sin6_t sin6_null; /* Zero address for quick clears */ 1840Sstevel@tonic-gate static void *icmp_g_head; /* Head for list of open icmp streams. */ 1850Sstevel@tonic-gate static IDP icmp_g_nd; /* Points to table of ICMP ND variables. */ 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate /* MIB-2 stuff for SNMP */ 1880Sstevel@tonic-gate static mib2_rawip_t rawip_mib; /* SNMP fixed size info */ 1890Sstevel@tonic-gate static kstat_t *rawip_mibkp; /* kstat exporting rawip_mib data */ 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate /* Default structure copied into T_INFO_ACK messages */ 1920Sstevel@tonic-gate static struct T_info_ack icmp_g_t_info_ack = { 1930Sstevel@tonic-gate T_INFO_ACK, 1940Sstevel@tonic-gate IP_MAXPACKET, /* TSDU_size. icmp allows maximum size messages. */ 1950Sstevel@tonic-gate T_INVALID, /* ETSDU_size. icmp does not support expedited data. */ 1960Sstevel@tonic-gate T_INVALID, /* CDATA_size. icmp does not support connect data. */ 1970Sstevel@tonic-gate T_INVALID, /* DDATA_size. icmp does not support disconnect data. */ 1980Sstevel@tonic-gate 0, /* ADDR_size - filled in later. */ 1990Sstevel@tonic-gate 0, /* OPT_size - not initialized here */ 2000Sstevel@tonic-gate IP_MAXPACKET, /* TIDU_size. icmp allows maximum size messages. */ 2010Sstevel@tonic-gate T_CLTS, /* SERV_type. icmp supports connection-less. */ 2020Sstevel@tonic-gate TS_UNBND, /* CURRENT_state. This is set from icmp_state. */ 2030Sstevel@tonic-gate (XPG4_1|SENDZERO) /* PROVIDER_flag */ 2040Sstevel@tonic-gate }; 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate /* 2070Sstevel@tonic-gate * Table of ND variables supported by icmp. These are loaded into icmp_g_nd 2080Sstevel@tonic-gate * in icmp_open. 2090Sstevel@tonic-gate * All of these are alterable, within the min/max values given, at run time. 2100Sstevel@tonic-gate */ 2110Sstevel@tonic-gate static icmpparam_t icmp_param_arr[] = { 2120Sstevel@tonic-gate /* min max value name */ 2130Sstevel@tonic-gate { 0, 128, 32, "icmp_wroff_extra" }, 2140Sstevel@tonic-gate { 1, 255, 255, "icmp_ipv4_ttl" }, 2150Sstevel@tonic-gate { 0, IPV6_MAX_HOPS, IPV6_DEFAULT_HOPS, "icmp_ipv6_hoplimit"}, 2160Sstevel@tonic-gate { 0, 1, 1, "icmp_bsd_compat" }, 2170Sstevel@tonic-gate { 4096, 65536, 8192, "icmp_xmit_hiwat"}, 2180Sstevel@tonic-gate { 0, 65536, 1024, "icmp_xmit_lowat"}, 2190Sstevel@tonic-gate { 4096, 65536, 8192, "icmp_recv_hiwat"}, 2200Sstevel@tonic-gate { 65536, 1024*1024*1024, 256*1024, "icmp_max_buf"}, 2210Sstevel@tonic-gate }; 2220Sstevel@tonic-gate #define icmp_wroff_extra icmp_param_arr[0].icmp_param_value 2230Sstevel@tonic-gate #define icmp_ipv4_ttl icmp_param_arr[1].icmp_param_value 2240Sstevel@tonic-gate #define icmp_ipv6_hoplimit icmp_param_arr[2].icmp_param_value 2250Sstevel@tonic-gate #define icmp_bsd_compat icmp_param_arr[3].icmp_param_value 2260Sstevel@tonic-gate #define icmp_xmit_hiwat icmp_param_arr[4].icmp_param_value 2270Sstevel@tonic-gate #define icmp_xmit_lowat icmp_param_arr[5].icmp_param_value 2280Sstevel@tonic-gate #define icmp_recv_hiwat icmp_param_arr[6].icmp_param_value 2290Sstevel@tonic-gate #define icmp_max_buf icmp_param_arr[7].icmp_param_value 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate /* 2320Sstevel@tonic-gate * This routine is called to handle each O_T_BIND_REQ/T_BIND_REQ message 2330Sstevel@tonic-gate * passed to icmp_wput. 2340Sstevel@tonic-gate * The O_T_BIND_REQ/T_BIND_REQ is passed downstream to ip with the ICMP 2350Sstevel@tonic-gate * protocol type placed in the message following the address. A T_BIND_ACK 2360Sstevel@tonic-gate * message is passed upstream when ip acknowledges the request. 2370Sstevel@tonic-gate * (Called as writer.) 2380Sstevel@tonic-gate */ 2390Sstevel@tonic-gate static void 2400Sstevel@tonic-gate icmp_bind(queue_t *q, mblk_t *mp) 2410Sstevel@tonic-gate { 2420Sstevel@tonic-gate sin_t *sin; 2430Sstevel@tonic-gate sin6_t *sin6; 2440Sstevel@tonic-gate mblk_t *mp1; 2450Sstevel@tonic-gate struct T_bind_req *tbr; 2460Sstevel@tonic-gate icmp_t *icmp; 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate icmp = (icmp_t *)q->q_ptr; 2490Sstevel@tonic-gate if ((mp->b_wptr - mp->b_rptr) < sizeof (*tbr)) { 2500Sstevel@tonic-gate (void) mi_strlog(q, 1, SL_ERROR|SL_TRACE, 2510Sstevel@tonic-gate "icmp_bind: bad req, len %u", 2520Sstevel@tonic-gate (uint_t)(mp->b_wptr - mp->b_rptr)); 2530Sstevel@tonic-gate icmp_err_ack(q, mp, TPROTO, 0); 2540Sstevel@tonic-gate return; 2550Sstevel@tonic-gate } 2560Sstevel@tonic-gate if (icmp->icmp_state != TS_UNBND) { 2570Sstevel@tonic-gate (void) mi_strlog(q, 1, SL_ERROR|SL_TRACE, 2580Sstevel@tonic-gate "icmp_bind: bad state, %d", icmp->icmp_state); 2590Sstevel@tonic-gate icmp_err_ack(q, mp, TOUTSTATE, 0); 2600Sstevel@tonic-gate return; 2610Sstevel@tonic-gate } 2620Sstevel@tonic-gate /* 2630Sstevel@tonic-gate * Reallocate the message to make sure we have enough room for an 2640Sstevel@tonic-gate * address and the protocol type. 2650Sstevel@tonic-gate */ 2660Sstevel@tonic-gate mp1 = reallocb(mp, sizeof (struct T_bind_ack) + sizeof (sin6_t) + 1, 1); 2670Sstevel@tonic-gate if (!mp1) { 2680Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, ENOMEM); 2690Sstevel@tonic-gate return; 2700Sstevel@tonic-gate } 2710Sstevel@tonic-gate mp = mp1; 2720Sstevel@tonic-gate tbr = (struct T_bind_req *)mp->b_rptr; 2730Sstevel@tonic-gate switch (tbr->ADDR_length) { 2740Sstevel@tonic-gate case 0: /* Generic request */ 2750Sstevel@tonic-gate tbr->ADDR_offset = sizeof (struct T_bind_req); 2760Sstevel@tonic-gate if (icmp->icmp_family == AF_INET) { 2770Sstevel@tonic-gate tbr->ADDR_length = sizeof (sin_t); 2780Sstevel@tonic-gate sin = (sin_t *)&tbr[1]; 2790Sstevel@tonic-gate *sin = sin_null; 2800Sstevel@tonic-gate sin->sin_family = AF_INET; 2810Sstevel@tonic-gate mp->b_wptr = (uchar_t *)&sin[1]; 2820Sstevel@tonic-gate } else { 2830Sstevel@tonic-gate ASSERT(icmp->icmp_family == AF_INET6); 2840Sstevel@tonic-gate tbr->ADDR_length = sizeof (sin6_t); 2850Sstevel@tonic-gate sin6 = (sin6_t *)&tbr[1]; 2860Sstevel@tonic-gate *sin6 = sin6_null; 2870Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 2880Sstevel@tonic-gate mp->b_wptr = (uchar_t *)&sin6[1]; 2890Sstevel@tonic-gate } 2900Sstevel@tonic-gate break; 2910Sstevel@tonic-gate case sizeof (sin_t): /* Complete IP address */ 2920Sstevel@tonic-gate sin = (sin_t *)mi_offset_param(mp, tbr->ADDR_offset, 2930Sstevel@tonic-gate sizeof (sin_t)); 2940Sstevel@tonic-gate if (sin == NULL || !OK_32PTR((char *)sin)) { 2950Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, EINVAL); 2960Sstevel@tonic-gate return; 2970Sstevel@tonic-gate } 2980Sstevel@tonic-gate if (icmp->icmp_family != AF_INET || 2990Sstevel@tonic-gate sin->sin_family != AF_INET) { 3000Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, EAFNOSUPPORT); 3010Sstevel@tonic-gate return; 3020Sstevel@tonic-gate } 3030Sstevel@tonic-gate break; 3040Sstevel@tonic-gate case sizeof (sin6_t): /* Complete IP address */ 3050Sstevel@tonic-gate sin6 = (sin6_t *)mi_offset_param(mp, tbr->ADDR_offset, 3060Sstevel@tonic-gate sizeof (sin6_t)); 3070Sstevel@tonic-gate if (sin6 == NULL || !OK_32PTR((char *)sin6)) { 3080Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, EINVAL); 3090Sstevel@tonic-gate return; 3100Sstevel@tonic-gate } 3110Sstevel@tonic-gate if (icmp->icmp_family != AF_INET6 || 3120Sstevel@tonic-gate sin6->sin6_family != AF_INET6) { 3130Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, EAFNOSUPPORT); 3140Sstevel@tonic-gate return; 3150Sstevel@tonic-gate } 3160Sstevel@tonic-gate /* No support for mapped addresses on raw sockets */ 3170Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { 3180Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, EADDRNOTAVAIL); 3190Sstevel@tonic-gate return; 3200Sstevel@tonic-gate } 3210Sstevel@tonic-gate break; 3220Sstevel@tonic-gate default: 3230Sstevel@tonic-gate (void) mi_strlog(q, 1, SL_ERROR|SL_TRACE, 3240Sstevel@tonic-gate "icmp_bind: bad ADDR_length %d", tbr->ADDR_length); 3250Sstevel@tonic-gate icmp_err_ack(q, mp, TBADADDR, 0); 3260Sstevel@tonic-gate return; 3270Sstevel@tonic-gate } 3280Sstevel@tonic-gate /* 3290Sstevel@tonic-gate * Copy the source address into our icmp structure. This address 3300Sstevel@tonic-gate * may still be zero; if so, ip will fill in the correct address 3310Sstevel@tonic-gate * each time an outbound packet is passed to it. 3320Sstevel@tonic-gate * If we are binding to a broadcast or multicast address icmp_rput 3330Sstevel@tonic-gate * will clear the source address when it receives the T_BIND_ACK. 3340Sstevel@tonic-gate */ 3350Sstevel@tonic-gate icmp->icmp_state = TS_IDLE; 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate if (icmp->icmp_family == AF_INET) { 3380Sstevel@tonic-gate ASSERT(sin != NULL); 3390Sstevel@tonic-gate ASSERT(icmp->icmp_ipversion == IPV4_VERSION); 3400Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(sin->sin_addr.s_addr, 3410Sstevel@tonic-gate &icmp->icmp_v6src); 3420Sstevel@tonic-gate icmp->icmp_max_hdr_len = IP_SIMPLE_HDR_LENGTH + 3430Sstevel@tonic-gate icmp->icmp_ip_snd_options_len; 3440Sstevel@tonic-gate icmp->icmp_bound_v6src = icmp->icmp_v6src; 3450Sstevel@tonic-gate } else { 3460Sstevel@tonic-gate int error; 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate ASSERT(sin6 != NULL); 3490Sstevel@tonic-gate ASSERT(icmp->icmp_ipversion == IPV6_VERSION); 3500Sstevel@tonic-gate icmp->icmp_v6src = sin6->sin6_addr; 3510Sstevel@tonic-gate icmp->icmp_max_hdr_len = icmp->icmp_sticky_hdrs_len; 3520Sstevel@tonic-gate icmp->icmp_bound_v6src = icmp->icmp_v6src; 3530Sstevel@tonic-gate 3540Sstevel@tonic-gate /* Rebuild the header template */ 3550Sstevel@tonic-gate error = icmp_build_hdrs(q, icmp); 3560Sstevel@tonic-gate if (error != 0) { 3570Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, error); 3580Sstevel@tonic-gate return; 3590Sstevel@tonic-gate } 3600Sstevel@tonic-gate } 3610Sstevel@tonic-gate /* 3620Sstevel@tonic-gate * Place protocol type in the O_T_BIND_REQ/T_BIND_REQ following 3630Sstevel@tonic-gate * the address. 3640Sstevel@tonic-gate */ 3650Sstevel@tonic-gate *mp->b_wptr++ = icmp->icmp_proto; 3660Sstevel@tonic-gate if (!(V6_OR_V4_INADDR_ANY(icmp->icmp_v6src))) { 3670Sstevel@tonic-gate /* 3680Sstevel@tonic-gate * Append a request for an IRE if src not 0 (INADDR_ANY) 3690Sstevel@tonic-gate */ 3700Sstevel@tonic-gate mp->b_cont = allocb(sizeof (ire_t), BPRI_HI); 3710Sstevel@tonic-gate if (!mp->b_cont) { 3720Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, ENOMEM); 3730Sstevel@tonic-gate return; 3740Sstevel@tonic-gate } 3750Sstevel@tonic-gate mp->b_cont->b_wptr += sizeof (ire_t); 3760Sstevel@tonic-gate mp->b_cont->b_datap->db_type = IRE_DB_REQ_TYPE; 3770Sstevel@tonic-gate } 3780Sstevel@tonic-gate 3790Sstevel@tonic-gate /* Pass the O_T_BIND_REQ/T_BIND_REQ to ip. */ 3800Sstevel@tonic-gate putnext(q, mp); 3810Sstevel@tonic-gate } 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate /* 3840Sstevel@tonic-gate * Send message to IP to just bind to the protocol. 3850Sstevel@tonic-gate */ 3860Sstevel@tonic-gate static void 3870Sstevel@tonic-gate icmp_bind_proto(queue_t *q) 3880Sstevel@tonic-gate { 3890Sstevel@tonic-gate mblk_t *mp; 3900Sstevel@tonic-gate struct T_bind_req *tbr; 3910Sstevel@tonic-gate icmp_t *icmp; 3920Sstevel@tonic-gate 3930Sstevel@tonic-gate icmp = (icmp_t *)q->q_ptr; 3940Sstevel@tonic-gate mp = allocb(sizeof (struct T_bind_req) + sizeof (sin6_t) + 1, 3950Sstevel@tonic-gate BPRI_MED); 3960Sstevel@tonic-gate if (!mp) { 3970Sstevel@tonic-gate return; 3980Sstevel@tonic-gate } 3990Sstevel@tonic-gate mp->b_datap->db_type = M_PROTO; 4000Sstevel@tonic-gate tbr = (struct T_bind_req *)mp->b_rptr; 4010Sstevel@tonic-gate tbr->PRIM_type = O_T_BIND_REQ; /* change to T_BIND_REQ ? */ 4020Sstevel@tonic-gate tbr->ADDR_offset = sizeof (struct T_bind_req); 4030Sstevel@tonic-gate if (icmp->icmp_ipversion == IPV4_VERSION) { 4040Sstevel@tonic-gate sin_t *sin; 4050Sstevel@tonic-gate 4060Sstevel@tonic-gate tbr->ADDR_length = sizeof (sin_t); 4070Sstevel@tonic-gate sin = (sin_t *)&tbr[1]; 4080Sstevel@tonic-gate *sin = sin_null; 4090Sstevel@tonic-gate sin->sin_family = AF_INET; 4100Sstevel@tonic-gate mp->b_wptr = (uchar_t *)&sin[1]; 4110Sstevel@tonic-gate } else { 4120Sstevel@tonic-gate sin6_t *sin6; 4130Sstevel@tonic-gate 4140Sstevel@tonic-gate ASSERT(icmp->icmp_ipversion == IPV6_VERSION); 4150Sstevel@tonic-gate tbr->ADDR_length = sizeof (sin6_t); 4160Sstevel@tonic-gate sin6 = (sin6_t *)&tbr[1]; 4170Sstevel@tonic-gate *sin6 = sin6_null; 4180Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 4190Sstevel@tonic-gate mp->b_wptr = (uchar_t *)&sin6[1]; 4200Sstevel@tonic-gate } 4210Sstevel@tonic-gate 4220Sstevel@tonic-gate /* Place protocol type in the O_T_BIND_REQ following the address. */ 4230Sstevel@tonic-gate *mp->b_wptr++ = icmp->icmp_proto; 4240Sstevel@tonic-gate 4250Sstevel@tonic-gate /* Pass the O_T_BIND_REQ to ip. */ 4260Sstevel@tonic-gate putnext(q, mp); 4270Sstevel@tonic-gate } 4280Sstevel@tonic-gate 4290Sstevel@tonic-gate /* 4300Sstevel@tonic-gate * This routine handles each T_CONN_REQ message passed to icmp. It 4310Sstevel@tonic-gate * associates a default destination address with the stream. 4320Sstevel@tonic-gate * 4330Sstevel@tonic-gate * This routine sends down a T_BIND_REQ to IP with the following mblks: 4340Sstevel@tonic-gate * T_BIND_REQ - specifying local and remote address. 4350Sstevel@tonic-gate * IRE_DB_REQ_TYPE - to get an IRE back containing ire_type and src 4360Sstevel@tonic-gate * T_OK_ACK - for the T_CONN_REQ 4370Sstevel@tonic-gate * T_CONN_CON - to keep the TPI user happy 4380Sstevel@tonic-gate * 4390Sstevel@tonic-gate * The connect completes in icmp_rput. 4400Sstevel@tonic-gate * When a T_BIND_ACK is received information is extracted from the IRE 4410Sstevel@tonic-gate * and the two appended messages are sent to the TPI user. 4420Sstevel@tonic-gate * Should icmp_rput receive T_ERROR_ACK for the T_BIND_REQ it will convert 4430Sstevel@tonic-gate * it to an error ack for the appropriate primitive. 4440Sstevel@tonic-gate */ 4450Sstevel@tonic-gate static void 4460Sstevel@tonic-gate icmp_connect(queue_t *q, mblk_t *mp) 4470Sstevel@tonic-gate { 4480Sstevel@tonic-gate sin_t *sin; 4490Sstevel@tonic-gate sin6_t *sin6; 4500Sstevel@tonic-gate mblk_t *mp1, *mp2; 4510Sstevel@tonic-gate struct T_conn_req *tcr; 4520Sstevel@tonic-gate icmp_t *icmp; 4530Sstevel@tonic-gate ipaddr_t v4dst; 4540Sstevel@tonic-gate in6_addr_t v6dst; 4550Sstevel@tonic-gate uint32_t flowinfo; 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate icmp = (icmp_t *)q->q_ptr; 4580Sstevel@tonic-gate tcr = (struct T_conn_req *)mp->b_rptr; 4590Sstevel@tonic-gate /* Sanity checks */ 4600Sstevel@tonic-gate if ((mp->b_wptr - mp->b_rptr < sizeof (struct T_conn_req))) { 4610Sstevel@tonic-gate icmp_err_ack(q, mp, TPROTO, 0); 4620Sstevel@tonic-gate return; 4630Sstevel@tonic-gate } 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate if (icmp->icmp_state == TS_DATA_XFER) { 4660Sstevel@tonic-gate /* Already connected - clear out state */ 4670Sstevel@tonic-gate icmp->icmp_v6src = icmp->icmp_bound_v6src; 4680Sstevel@tonic-gate icmp->icmp_state = TS_IDLE; 4690Sstevel@tonic-gate } 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate if (tcr->OPT_length != 0) { 4730Sstevel@tonic-gate icmp_err_ack(q, mp, TBADOPT, 0); 4740Sstevel@tonic-gate return; 4750Sstevel@tonic-gate } 4760Sstevel@tonic-gate switch (tcr->DEST_length) { 4770Sstevel@tonic-gate default: 4780Sstevel@tonic-gate icmp_err_ack(q, mp, TBADADDR, 0); 4790Sstevel@tonic-gate return; 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate case sizeof (sin_t): 4820Sstevel@tonic-gate sin = (sin_t *)mi_offset_param(mp, tcr->DEST_offset, 4830Sstevel@tonic-gate sizeof (sin_t)); 4840Sstevel@tonic-gate if (sin == NULL || !OK_32PTR((char *)sin)) { 4850Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, EINVAL); 4860Sstevel@tonic-gate return; 4870Sstevel@tonic-gate } 4880Sstevel@tonic-gate if (icmp->icmp_family != AF_INET || 4890Sstevel@tonic-gate sin->sin_family != AF_INET) { 4900Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, EAFNOSUPPORT); 4910Sstevel@tonic-gate return; 4920Sstevel@tonic-gate } 4930Sstevel@tonic-gate v4dst = sin->sin_addr.s_addr; 4940Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(v4dst, &v6dst); 4950Sstevel@tonic-gate ASSERT(icmp->icmp_ipversion == IPV4_VERSION); 4960Sstevel@tonic-gate icmp->icmp_max_hdr_len = IP_SIMPLE_HDR_LENGTH + 4970Sstevel@tonic-gate icmp->icmp_ip_snd_options_len; 4980Sstevel@tonic-gate break; 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate case sizeof (sin6_t): 5010Sstevel@tonic-gate sin6 = (sin6_t *)mi_offset_param(mp, tcr->DEST_offset, 5020Sstevel@tonic-gate sizeof (sin6_t)); 5030Sstevel@tonic-gate if (sin6 == NULL || !OK_32PTR((char *)sin6)) { 5040Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, EINVAL); 5050Sstevel@tonic-gate return; 5060Sstevel@tonic-gate } 5070Sstevel@tonic-gate if (icmp->icmp_family != AF_INET6 || 5080Sstevel@tonic-gate sin6->sin6_family != AF_INET6) { 5090Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, EAFNOSUPPORT); 5100Sstevel@tonic-gate return; 5110Sstevel@tonic-gate } 5120Sstevel@tonic-gate /* No support for mapped addresses on raw sockets */ 5130Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { 5140Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, EADDRNOTAVAIL); 5150Sstevel@tonic-gate return; 5160Sstevel@tonic-gate } 5170Sstevel@tonic-gate v6dst = sin6->sin6_addr; 5180Sstevel@tonic-gate ASSERT(icmp->icmp_ipversion == IPV6_VERSION); 5190Sstevel@tonic-gate icmp->icmp_max_hdr_len = icmp->icmp_sticky_hdrs_len; 5200Sstevel@tonic-gate flowinfo = sin6->sin6_flowinfo; 5210Sstevel@tonic-gate break; 5220Sstevel@tonic-gate } 5230Sstevel@tonic-gate if (icmp->icmp_ipversion == IPV4_VERSION) { 5240Sstevel@tonic-gate /* 5250Sstevel@tonic-gate * Interpret a zero destination to mean loopback. 5260Sstevel@tonic-gate * Update the T_CONN_REQ (sin/sin6) since it is used to 5270Sstevel@tonic-gate * generate the T_CONN_CON. 5280Sstevel@tonic-gate */ 5290Sstevel@tonic-gate if (v4dst == INADDR_ANY) { 5300Sstevel@tonic-gate v4dst = htonl(INADDR_LOOPBACK); 5310Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(v4dst, &v6dst); 5320Sstevel@tonic-gate if (icmp->icmp_family == AF_INET) { 5330Sstevel@tonic-gate sin->sin_addr.s_addr = v4dst; 5340Sstevel@tonic-gate } else { 5350Sstevel@tonic-gate sin6->sin6_addr = v6dst; 5360Sstevel@tonic-gate } 5370Sstevel@tonic-gate } 5380Sstevel@tonic-gate icmp->icmp_v6dst = v6dst; 5390Sstevel@tonic-gate icmp->icmp_flowinfo = 0; 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate /* 5420Sstevel@tonic-gate * If the destination address is multicast and 5430Sstevel@tonic-gate * an outgoing multicast interface has been set, 5440Sstevel@tonic-gate * use the address of that interface as our 5450Sstevel@tonic-gate * source address if no source address has been set. 5460Sstevel@tonic-gate */ 5470Sstevel@tonic-gate if (V4_PART_OF_V6(icmp->icmp_v6src) == INADDR_ANY && 5480Sstevel@tonic-gate CLASSD(v4dst) && 5490Sstevel@tonic-gate icmp->icmp_multicast_if_addr != INADDR_ANY) { 5500Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(icmp->icmp_multicast_if_addr, 5510Sstevel@tonic-gate &icmp->icmp_v6src); 5520Sstevel@tonic-gate } 5530Sstevel@tonic-gate } else { 5540Sstevel@tonic-gate ASSERT(icmp->icmp_ipversion == IPV6_VERSION); 5550Sstevel@tonic-gate /* 5560Sstevel@tonic-gate * Interpret a zero destination to mean loopback. 5570Sstevel@tonic-gate * Update the T_CONN_REQ (sin/sin6) since it is used to 5580Sstevel@tonic-gate * generate the T_CONN_CON. 5590Sstevel@tonic-gate */ 5600Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(&v6dst)) { 5610Sstevel@tonic-gate v6dst = ipv6_loopback; 5620Sstevel@tonic-gate sin6->sin6_addr = v6dst; 5630Sstevel@tonic-gate } 5640Sstevel@tonic-gate icmp->icmp_v6dst = v6dst; 5650Sstevel@tonic-gate icmp->icmp_flowinfo = flowinfo; 5660Sstevel@tonic-gate /* 5670Sstevel@tonic-gate * If the destination address is multicast and 5680Sstevel@tonic-gate * an outgoing multicast interface has been set, 5690Sstevel@tonic-gate * then the ip bind logic will pick the correct source 5700Sstevel@tonic-gate * address (i.e. matching the outgoing multicast interface). 5710Sstevel@tonic-gate */ 5720Sstevel@tonic-gate } 5730Sstevel@tonic-gate 5740Sstevel@tonic-gate /* 5750Sstevel@tonic-gate * Send down bind to IP to verify that there is a route 5760Sstevel@tonic-gate * and to determine the source address. 5770Sstevel@tonic-gate * This will come back as T_BIND_ACK with an IRE_DB_TYPE in rput. 5780Sstevel@tonic-gate */ 5790Sstevel@tonic-gate if (icmp->icmp_family == AF_INET) { 5800Sstevel@tonic-gate mp1 = icmp_ip_bind_mp(icmp, O_T_BIND_REQ, sizeof (ipa_conn_t), 5810Sstevel@tonic-gate sin->sin_port); 5820Sstevel@tonic-gate } else { 5830Sstevel@tonic-gate ASSERT(icmp->icmp_family == AF_INET6); 5840Sstevel@tonic-gate mp1 = icmp_ip_bind_mp(icmp, O_T_BIND_REQ, sizeof (ipa6_conn_t), 5850Sstevel@tonic-gate sin6->sin6_port); 5860Sstevel@tonic-gate } 5870Sstevel@tonic-gate if (mp1 == NULL) { 5880Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, ENOMEM); 5890Sstevel@tonic-gate return; 5900Sstevel@tonic-gate } 5910Sstevel@tonic-gate 5920Sstevel@tonic-gate /* 5930Sstevel@tonic-gate * We also have to send a connection confirmation to 5940Sstevel@tonic-gate * keep TLI happy. Prepare it for icmp_rput. 5950Sstevel@tonic-gate */ 5960Sstevel@tonic-gate if (icmp->icmp_family == AF_INET) { 5970Sstevel@tonic-gate mp2 = mi_tpi_conn_con(NULL, (char *)sin, sizeof (*sin), NULL, 5980Sstevel@tonic-gate 0); 5990Sstevel@tonic-gate } else { 6000Sstevel@tonic-gate ASSERT(icmp->icmp_family == AF_INET6); 6010Sstevel@tonic-gate mp2 = mi_tpi_conn_con(NULL, (char *)sin6, sizeof (*sin6), NULL, 6020Sstevel@tonic-gate 0); 6030Sstevel@tonic-gate } 6040Sstevel@tonic-gate if (mp2 == NULL) { 6050Sstevel@tonic-gate freemsg(mp1); 6060Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, ENOMEM); 6070Sstevel@tonic-gate return; 6080Sstevel@tonic-gate } 6090Sstevel@tonic-gate 6100Sstevel@tonic-gate mp = mi_tpi_ok_ack_alloc(mp); 6110Sstevel@tonic-gate if (mp == NULL) { 6120Sstevel@tonic-gate /* Unable to reuse the T_CONN_REQ for the ack. */ 6130Sstevel@tonic-gate freemsg(mp2); 6140Sstevel@tonic-gate icmp_err_ack_prim(q, mp1, T_CONN_REQ, TSYSERR, ENOMEM); 6150Sstevel@tonic-gate return; 6160Sstevel@tonic-gate } 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate icmp->icmp_state = TS_DATA_XFER; 6190Sstevel@tonic-gate 6200Sstevel@tonic-gate /* Hang onto the T_OK_ACK and T_CONN_CON for later. */ 6210Sstevel@tonic-gate linkb(mp1, mp); 6220Sstevel@tonic-gate linkb(mp1, mp2); 6230Sstevel@tonic-gate 6241676Sjpk mblk_setcred(mp1, icmp->icmp_credp); 6250Sstevel@tonic-gate putnext(q, mp1); 6260Sstevel@tonic-gate } 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate static int 6290Sstevel@tonic-gate icmp_close(queue_t *q) 6300Sstevel@tonic-gate { 6310Sstevel@tonic-gate icmp_t *icmp = (icmp_t *)q->q_ptr; 6320Sstevel@tonic-gate int i1; 6330Sstevel@tonic-gate 6341676Sjpk /* tell IP that if we're not here, he can't trust labels */ 6351676Sjpk if (is_system_labeled()) 6361676Sjpk putnext(WR(q), icmp->icmp_delabel); 6371676Sjpk 6380Sstevel@tonic-gate qprocsoff(q); 6390Sstevel@tonic-gate 6400Sstevel@tonic-gate /* If there are any options associated with the stream, free them. */ 6410Sstevel@tonic-gate if (icmp->icmp_ip_snd_options) 6420Sstevel@tonic-gate mi_free((char *)icmp->icmp_ip_snd_options); 6430Sstevel@tonic-gate 6440Sstevel@tonic-gate if (icmp->icmp_filter != NULL) 6450Sstevel@tonic-gate kmem_free(icmp->icmp_filter, sizeof (icmp6_filter_t)); 6460Sstevel@tonic-gate 6470Sstevel@tonic-gate /* Free memory associated with sticky options */ 6480Sstevel@tonic-gate if (icmp->icmp_sticky_hdrs_len != 0) { 6490Sstevel@tonic-gate kmem_free(icmp->icmp_sticky_hdrs, 6500Sstevel@tonic-gate icmp->icmp_sticky_hdrs_len); 6510Sstevel@tonic-gate icmp->icmp_sticky_hdrs = NULL; 6520Sstevel@tonic-gate icmp->icmp_sticky_hdrs_len = 0; 6530Sstevel@tonic-gate } 6541676Sjpk 6551676Sjpk ip6_pkt_free(&icmp->icmp_sticky_ipp); 6560Sstevel@tonic-gate 6570Sstevel@tonic-gate crfree(icmp->icmp_credp); 6580Sstevel@tonic-gate 6590Sstevel@tonic-gate /* Free the icmp structure and release the minor device number. */ 6600Sstevel@tonic-gate i1 = mi_close_comm(&icmp_g_head, q); 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate return (i1); 6630Sstevel@tonic-gate } 6640Sstevel@tonic-gate 6650Sstevel@tonic-gate /* 6660Sstevel@tonic-gate * This routine handles each T_DISCON_REQ message passed to icmp 6670Sstevel@tonic-gate * as an indicating that ICMP is no longer connected. This results 6680Sstevel@tonic-gate * in sending a T_BIND_REQ to IP to restore the binding to just 6690Sstevel@tonic-gate * the local address. 6700Sstevel@tonic-gate * 6710Sstevel@tonic-gate * This routine sends down a T_BIND_REQ to IP with the following mblks: 6720Sstevel@tonic-gate * T_BIND_REQ - specifying just the local address. 6730Sstevel@tonic-gate * T_OK_ACK - for the T_DISCON_REQ 6740Sstevel@tonic-gate * 6750Sstevel@tonic-gate * The disconnect completes in icmp_rput. 6760Sstevel@tonic-gate * When a T_BIND_ACK is received the appended T_OK_ACK is sent to the TPI user. 6770Sstevel@tonic-gate * Should icmp_rput receive T_ERROR_ACK for the T_BIND_REQ it will convert 6780Sstevel@tonic-gate * it to an error ack for the appropriate primitive. 6790Sstevel@tonic-gate */ 6800Sstevel@tonic-gate static void 6810Sstevel@tonic-gate icmp_disconnect(queue_t *q, mblk_t *mp) 6820Sstevel@tonic-gate { 6830Sstevel@tonic-gate icmp_t *icmp; 6840Sstevel@tonic-gate mblk_t *mp1; 6850Sstevel@tonic-gate 6860Sstevel@tonic-gate icmp = (icmp_t *)q->q_ptr; 6870Sstevel@tonic-gate 6880Sstevel@tonic-gate if (icmp->icmp_state != TS_DATA_XFER) { 6890Sstevel@tonic-gate (void) mi_strlog(q, 1, SL_ERROR|SL_TRACE, 6900Sstevel@tonic-gate "icmp_disconnect: bad state, %d", icmp->icmp_state); 6910Sstevel@tonic-gate icmp_err_ack(q, mp, TOUTSTATE, 0); 6920Sstevel@tonic-gate return; 6930Sstevel@tonic-gate } 6940Sstevel@tonic-gate icmp->icmp_v6src = icmp->icmp_bound_v6src; 6950Sstevel@tonic-gate icmp->icmp_state = TS_IDLE; 6960Sstevel@tonic-gate 6970Sstevel@tonic-gate /* 6980Sstevel@tonic-gate * Send down bind to IP to remove the full binding and revert 6990Sstevel@tonic-gate * to the local address binding. 7000Sstevel@tonic-gate */ 7010Sstevel@tonic-gate if (icmp->icmp_family == AF_INET) { 7020Sstevel@tonic-gate mp1 = icmp_ip_bind_mp(icmp, O_T_BIND_REQ, sizeof (sin_t), 0); 7030Sstevel@tonic-gate } else { 7040Sstevel@tonic-gate ASSERT(icmp->icmp_family == AF_INET6); 7050Sstevel@tonic-gate mp1 = icmp_ip_bind_mp(icmp, O_T_BIND_REQ, sizeof (sin6_t), 0); 7060Sstevel@tonic-gate } 7070Sstevel@tonic-gate if (mp1 == NULL) { 7080Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, ENOMEM); 7090Sstevel@tonic-gate return; 7100Sstevel@tonic-gate } 7110Sstevel@tonic-gate mp = mi_tpi_ok_ack_alloc(mp); 7120Sstevel@tonic-gate if (mp == NULL) { 7130Sstevel@tonic-gate /* Unable to reuse the T_DISCON_REQ for the ack. */ 7140Sstevel@tonic-gate icmp_err_ack_prim(q, mp1, T_DISCON_REQ, TSYSERR, ENOMEM); 7150Sstevel@tonic-gate return; 7160Sstevel@tonic-gate } 7170Sstevel@tonic-gate 7180Sstevel@tonic-gate if (icmp->icmp_family == AF_INET6) { 7190Sstevel@tonic-gate int error; 7200Sstevel@tonic-gate 7210Sstevel@tonic-gate /* Rebuild the header template */ 7220Sstevel@tonic-gate error = icmp_build_hdrs(q, icmp); 7230Sstevel@tonic-gate if (error != 0) { 7240Sstevel@tonic-gate icmp_err_ack_prim(q, mp, T_DISCON_REQ, TSYSERR, error); 7250Sstevel@tonic-gate freemsg(mp1); 7260Sstevel@tonic-gate return; 7270Sstevel@tonic-gate } 7280Sstevel@tonic-gate } 7290Sstevel@tonic-gate icmp->icmp_discon_pending = 1; 7300Sstevel@tonic-gate 7310Sstevel@tonic-gate /* Append the T_OK_ACK to the T_BIND_REQ for icmp_rput */ 7320Sstevel@tonic-gate linkb(mp1, mp); 7330Sstevel@tonic-gate putnext(q, mp1); 7340Sstevel@tonic-gate } 7350Sstevel@tonic-gate 7360Sstevel@tonic-gate /* This routine creates a T_ERROR_ACK message and passes it upstream. */ 7370Sstevel@tonic-gate static void 7380Sstevel@tonic-gate icmp_err_ack(queue_t *q, mblk_t *mp, t_scalar_t t_error, int sys_error) 7390Sstevel@tonic-gate { 7400Sstevel@tonic-gate if ((mp = mi_tpi_err_ack_alloc(mp, t_error, sys_error)) != NULL) 7410Sstevel@tonic-gate qreply(q, mp); 7420Sstevel@tonic-gate } 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate /* Shorthand to generate and send TPI error acks to our client */ 7450Sstevel@tonic-gate static void 7460Sstevel@tonic-gate icmp_err_ack_prim(queue_t *q, mblk_t *mp, t_scalar_t primitive, 7470Sstevel@tonic-gate t_scalar_t t_error, int sys_error) 7480Sstevel@tonic-gate { 7490Sstevel@tonic-gate struct T_error_ack *teackp; 7500Sstevel@tonic-gate 7510Sstevel@tonic-gate if ((mp = tpi_ack_alloc(mp, sizeof (struct T_error_ack), 7520Sstevel@tonic-gate M_PCPROTO, T_ERROR_ACK)) != NULL) { 7530Sstevel@tonic-gate teackp = (struct T_error_ack *)mp->b_rptr; 7540Sstevel@tonic-gate teackp->ERROR_prim = primitive; 7550Sstevel@tonic-gate teackp->TLI_error = t_error; 7560Sstevel@tonic-gate teackp->UNIX_error = sys_error; 7570Sstevel@tonic-gate qreply(q, mp); 7580Sstevel@tonic-gate } 7590Sstevel@tonic-gate } 7600Sstevel@tonic-gate 7610Sstevel@tonic-gate /* 7620Sstevel@tonic-gate * icmp_icmp_error is called by icmp_rput to process ICMP 7630Sstevel@tonic-gate * messages passed up by IP. 7640Sstevel@tonic-gate * Generates the appropriate T_UDERROR_IND for permanent 7650Sstevel@tonic-gate * (non-transient) errors. 7660Sstevel@tonic-gate * Assumes that IP has pulled up everything up to and including 7670Sstevel@tonic-gate * the ICMP header. 7680Sstevel@tonic-gate */ 7690Sstevel@tonic-gate static void 7700Sstevel@tonic-gate icmp_icmp_error(queue_t *q, mblk_t *mp) 7710Sstevel@tonic-gate { 7720Sstevel@tonic-gate icmph_t *icmph; 7730Sstevel@tonic-gate ipha_t *ipha; 7740Sstevel@tonic-gate int iph_hdr_length; 7750Sstevel@tonic-gate sin_t sin; 7760Sstevel@tonic-gate sin6_t sin6; 7770Sstevel@tonic-gate mblk_t *mp1; 7780Sstevel@tonic-gate int error = 0; 7790Sstevel@tonic-gate icmp_t *icmp = (icmp_t *)q->q_ptr; 7800Sstevel@tonic-gate 7810Sstevel@tonic-gate /* 7820Sstevel@tonic-gate * Deliver T_UDERROR_IND when the application has asked for it. 7830Sstevel@tonic-gate * The socket layer enables this automatically when connected. 7840Sstevel@tonic-gate */ 7850Sstevel@tonic-gate if (!icmp->icmp_dgram_errind) { 7860Sstevel@tonic-gate freemsg(mp); 7870Sstevel@tonic-gate return; 7880Sstevel@tonic-gate } 7890Sstevel@tonic-gate 7900Sstevel@tonic-gate ipha = (ipha_t *)mp->b_rptr; 7910Sstevel@tonic-gate 7920Sstevel@tonic-gate if (IPH_HDR_VERSION(ipha) != IPV4_VERSION) { 7930Sstevel@tonic-gate ASSERT(IPH_HDR_VERSION(ipha) == IPV6_VERSION); 7940Sstevel@tonic-gate icmp_icmp_error_ipv6(q, mp); 7950Sstevel@tonic-gate return; 7960Sstevel@tonic-gate } 7970Sstevel@tonic-gate ASSERT(IPH_HDR_VERSION(ipha) == IPV4_VERSION); 7980Sstevel@tonic-gate 7990Sstevel@tonic-gate iph_hdr_length = IPH_HDR_LENGTH(ipha); 8000Sstevel@tonic-gate icmph = (icmph_t *)(&mp->b_rptr[iph_hdr_length]); 8010Sstevel@tonic-gate ipha = (ipha_t *)&icmph[1]; 8020Sstevel@tonic-gate iph_hdr_length = IPH_HDR_LENGTH(ipha); 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate switch (icmph->icmph_type) { 8050Sstevel@tonic-gate case ICMP_DEST_UNREACHABLE: 8060Sstevel@tonic-gate switch (icmph->icmph_code) { 8070Sstevel@tonic-gate case ICMP_FRAGMENTATION_NEEDED: 8080Sstevel@tonic-gate /* 8090Sstevel@tonic-gate * IP has already adjusted the path MTU. 8100Sstevel@tonic-gate * XXX Somehow pass MTU indication to application? 8110Sstevel@tonic-gate */ 8120Sstevel@tonic-gate break; 8130Sstevel@tonic-gate case ICMP_PORT_UNREACHABLE: 8140Sstevel@tonic-gate case ICMP_PROTOCOL_UNREACHABLE: 8150Sstevel@tonic-gate error = ECONNREFUSED; 8160Sstevel@tonic-gate break; 8170Sstevel@tonic-gate default: 8180Sstevel@tonic-gate /* Transient errors */ 8190Sstevel@tonic-gate break; 8200Sstevel@tonic-gate } 8210Sstevel@tonic-gate break; 8220Sstevel@tonic-gate default: 8230Sstevel@tonic-gate /* Transient errors */ 8240Sstevel@tonic-gate break; 8250Sstevel@tonic-gate } 8260Sstevel@tonic-gate if (error == 0) { 8270Sstevel@tonic-gate freemsg(mp); 8280Sstevel@tonic-gate return; 8290Sstevel@tonic-gate } 8300Sstevel@tonic-gate 8310Sstevel@tonic-gate switch (icmp->icmp_family) { 8320Sstevel@tonic-gate case AF_INET: 8330Sstevel@tonic-gate sin = sin_null; 8340Sstevel@tonic-gate sin.sin_family = AF_INET; 8350Sstevel@tonic-gate sin.sin_addr.s_addr = ipha->ipha_dst; 8360Sstevel@tonic-gate mp1 = mi_tpi_uderror_ind((char *)&sin, sizeof (sin_t), NULL, 0, 8370Sstevel@tonic-gate error); 8380Sstevel@tonic-gate break; 8390Sstevel@tonic-gate case AF_INET6: 8400Sstevel@tonic-gate sin6 = sin6_null; 8410Sstevel@tonic-gate sin6.sin6_family = AF_INET6; 8420Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(ipha->ipha_dst, &sin6.sin6_addr); 8430Sstevel@tonic-gate 8440Sstevel@tonic-gate mp1 = mi_tpi_uderror_ind((char *)&sin6, sizeof (sin6_t), 8450Sstevel@tonic-gate NULL, 0, error); 8460Sstevel@tonic-gate break; 8470Sstevel@tonic-gate } 8480Sstevel@tonic-gate if (mp1) 8490Sstevel@tonic-gate putnext(q, mp1); 8500Sstevel@tonic-gate freemsg(mp); 8510Sstevel@tonic-gate } 8520Sstevel@tonic-gate 8530Sstevel@tonic-gate /* 8540Sstevel@tonic-gate * icmp_icmp_error_ipv6 is called by icmp_icmp_error to process ICMPv6 8550Sstevel@tonic-gate * for IPv6 packets. 8560Sstevel@tonic-gate * Send permanent (non-transient) errors upstream. 8570Sstevel@tonic-gate * Assumes that IP has pulled up all the extension headers as well 8580Sstevel@tonic-gate * as the ICMPv6 header. 8590Sstevel@tonic-gate */ 8600Sstevel@tonic-gate static void 8610Sstevel@tonic-gate icmp_icmp_error_ipv6(queue_t *q, mblk_t *mp) 8620Sstevel@tonic-gate { 8630Sstevel@tonic-gate icmp6_t *icmp6; 8640Sstevel@tonic-gate ip6_t *ip6h, *outer_ip6h; 8650Sstevel@tonic-gate uint16_t iph_hdr_length; 8660Sstevel@tonic-gate uint8_t *nexthdrp; 8670Sstevel@tonic-gate sin6_t sin6; 8680Sstevel@tonic-gate mblk_t *mp1; 8690Sstevel@tonic-gate int error = 0; 8700Sstevel@tonic-gate icmp_t *icmp = (icmp_t *)q->q_ptr; 8710Sstevel@tonic-gate 8720Sstevel@tonic-gate outer_ip6h = (ip6_t *)mp->b_rptr; 8730Sstevel@tonic-gate if (outer_ip6h->ip6_nxt != IPPROTO_ICMPV6) 8740Sstevel@tonic-gate iph_hdr_length = ip_hdr_length_v6(mp, outer_ip6h); 8750Sstevel@tonic-gate else 8760Sstevel@tonic-gate iph_hdr_length = IPV6_HDR_LEN; 8770Sstevel@tonic-gate 8780Sstevel@tonic-gate icmp6 = (icmp6_t *)&mp->b_rptr[iph_hdr_length]; 8790Sstevel@tonic-gate ip6h = (ip6_t *)&icmp6[1]; 8800Sstevel@tonic-gate if (!ip_hdr_length_nexthdr_v6(mp, ip6h, &iph_hdr_length, &nexthdrp)) { 8810Sstevel@tonic-gate freemsg(mp); 8820Sstevel@tonic-gate return; 8830Sstevel@tonic-gate } 8840Sstevel@tonic-gate if (*nexthdrp != icmp->icmp_proto) { 8850Sstevel@tonic-gate /* 8860Sstevel@tonic-gate * Could have switched icmp_proto after while ip did fanout of 8870Sstevel@tonic-gate * this message 8880Sstevel@tonic-gate */ 8890Sstevel@tonic-gate freemsg(mp); 8900Sstevel@tonic-gate return; 8910Sstevel@tonic-gate } 8920Sstevel@tonic-gate switch (icmp6->icmp6_type) { 8930Sstevel@tonic-gate case ICMP6_DST_UNREACH: 8940Sstevel@tonic-gate switch (icmp6->icmp6_code) { 8950Sstevel@tonic-gate case ICMP6_DST_UNREACH_NOPORT: 8960Sstevel@tonic-gate error = ECONNREFUSED; 8970Sstevel@tonic-gate break; 8980Sstevel@tonic-gate case ICMP6_DST_UNREACH_ADMIN: 8990Sstevel@tonic-gate case ICMP6_DST_UNREACH_NOROUTE: 9000Sstevel@tonic-gate case ICMP6_DST_UNREACH_BEYONDSCOPE: 9010Sstevel@tonic-gate case ICMP6_DST_UNREACH_ADDR: 9020Sstevel@tonic-gate /* Transient errors */ 9030Sstevel@tonic-gate break; 9040Sstevel@tonic-gate default: 9050Sstevel@tonic-gate break; 9060Sstevel@tonic-gate } 9070Sstevel@tonic-gate break; 9080Sstevel@tonic-gate case ICMP6_PACKET_TOO_BIG: { 9090Sstevel@tonic-gate struct T_unitdata_ind *tudi; 9100Sstevel@tonic-gate struct T_opthdr *toh; 9110Sstevel@tonic-gate size_t udi_size; 9120Sstevel@tonic-gate mblk_t *newmp; 9130Sstevel@tonic-gate t_scalar_t opt_length = sizeof (struct T_opthdr) + 9140Sstevel@tonic-gate sizeof (struct ip6_mtuinfo); 9150Sstevel@tonic-gate sin6_t *sin6; 9160Sstevel@tonic-gate struct ip6_mtuinfo *mtuinfo; 9170Sstevel@tonic-gate 9180Sstevel@tonic-gate /* 9190Sstevel@tonic-gate * If the application has requested to receive path mtu 9200Sstevel@tonic-gate * information, send up an empty message containing an 9210Sstevel@tonic-gate * IPV6_PATHMTU ancillary data item. 9220Sstevel@tonic-gate */ 9230Sstevel@tonic-gate if (!icmp->icmp_ipv6_recvpathmtu) 9240Sstevel@tonic-gate break; 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate udi_size = sizeof (struct T_unitdata_ind) + sizeof (sin6_t) + 9270Sstevel@tonic-gate opt_length; 9280Sstevel@tonic-gate if ((newmp = allocb(udi_size, BPRI_MED)) == NULL) { 9290Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipInErrors); 9300Sstevel@tonic-gate break; 9310Sstevel@tonic-gate } 9320Sstevel@tonic-gate 9330Sstevel@tonic-gate /* 9340Sstevel@tonic-gate * newmp->b_cont is left to NULL on purpose. This is an 9350Sstevel@tonic-gate * empty message containing only ancillary data. 9360Sstevel@tonic-gate */ 9370Sstevel@tonic-gate newmp->b_datap->db_type = M_PROTO; 9380Sstevel@tonic-gate tudi = (struct T_unitdata_ind *)newmp->b_rptr; 9390Sstevel@tonic-gate newmp->b_wptr = (uchar_t *)tudi + udi_size; 9400Sstevel@tonic-gate tudi->PRIM_type = T_UNITDATA_IND; 9410Sstevel@tonic-gate tudi->SRC_length = sizeof (sin6_t); 9420Sstevel@tonic-gate tudi->SRC_offset = sizeof (struct T_unitdata_ind); 9430Sstevel@tonic-gate tudi->OPT_offset = tudi->SRC_offset + sizeof (sin6_t); 9440Sstevel@tonic-gate tudi->OPT_length = opt_length; 9450Sstevel@tonic-gate 9460Sstevel@tonic-gate sin6 = (sin6_t *)&tudi[1]; 9470Sstevel@tonic-gate bzero(sin6, sizeof (sin6_t)); 9480Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 9490Sstevel@tonic-gate sin6->sin6_addr = icmp->icmp_v6dst; 9500Sstevel@tonic-gate 9510Sstevel@tonic-gate toh = (struct T_opthdr *)&sin6[1]; 9520Sstevel@tonic-gate toh->level = IPPROTO_IPV6; 9530Sstevel@tonic-gate toh->name = IPV6_PATHMTU; 9540Sstevel@tonic-gate toh->len = opt_length; 9550Sstevel@tonic-gate toh->status = 0; 9560Sstevel@tonic-gate 9570Sstevel@tonic-gate mtuinfo = (struct ip6_mtuinfo *)&toh[1]; 9580Sstevel@tonic-gate bzero(mtuinfo, sizeof (struct ip6_mtuinfo)); 9590Sstevel@tonic-gate mtuinfo->ip6m_addr.sin6_family = AF_INET6; 9600Sstevel@tonic-gate mtuinfo->ip6m_addr.sin6_addr = ip6h->ip6_dst; 9610Sstevel@tonic-gate mtuinfo->ip6m_mtu = icmp6->icmp6_mtu; 9620Sstevel@tonic-gate /* 9630Sstevel@tonic-gate * We've consumed everything we need from the original 9640Sstevel@tonic-gate * message. Free it, then send our empty message. 9650Sstevel@tonic-gate */ 9660Sstevel@tonic-gate freemsg(mp); 9670Sstevel@tonic-gate putnext(q, newmp); 9680Sstevel@tonic-gate return; 9690Sstevel@tonic-gate } 9700Sstevel@tonic-gate case ICMP6_TIME_EXCEEDED: 9710Sstevel@tonic-gate /* Transient errors */ 9720Sstevel@tonic-gate break; 9730Sstevel@tonic-gate case ICMP6_PARAM_PROB: 9740Sstevel@tonic-gate /* If this corresponds to an ICMP_PROTOCOL_UNREACHABLE */ 9750Sstevel@tonic-gate if (icmp6->icmp6_code == ICMP6_PARAMPROB_NEXTHEADER && 9760Sstevel@tonic-gate (uchar_t *)ip6h + icmp6->icmp6_pptr == 9770Sstevel@tonic-gate (uchar_t *)nexthdrp) { 9780Sstevel@tonic-gate error = ECONNREFUSED; 9790Sstevel@tonic-gate break; 9800Sstevel@tonic-gate } 9810Sstevel@tonic-gate break; 9820Sstevel@tonic-gate } 9830Sstevel@tonic-gate if (error == 0) { 9840Sstevel@tonic-gate freemsg(mp); 9850Sstevel@tonic-gate return; 9860Sstevel@tonic-gate } 9870Sstevel@tonic-gate 9880Sstevel@tonic-gate sin6 = sin6_null; 9890Sstevel@tonic-gate sin6.sin6_family = AF_INET6; 9900Sstevel@tonic-gate sin6.sin6_addr = ip6h->ip6_dst; 9910Sstevel@tonic-gate sin6.sin6_flowinfo = ip6h->ip6_vcf & ~IPV6_VERS_AND_FLOW_MASK; 9920Sstevel@tonic-gate 9930Sstevel@tonic-gate mp1 = mi_tpi_uderror_ind((char *)&sin6, sizeof (sin6_t), NULL, 0, 9940Sstevel@tonic-gate error); 9950Sstevel@tonic-gate if (mp1) 9960Sstevel@tonic-gate putnext(q, mp1); 9970Sstevel@tonic-gate freemsg(mp); 9980Sstevel@tonic-gate } 9990Sstevel@tonic-gate 10000Sstevel@tonic-gate /* 10010Sstevel@tonic-gate * This routine responds to T_ADDR_REQ messages. It is called by icmp_wput. 10020Sstevel@tonic-gate * The local address is filled in if endpoint is bound. The remote address 10030Sstevel@tonic-gate * is filled in if remote address has been precified ("connected endpoint") 10040Sstevel@tonic-gate * (The concept of connected CLTS sockets is alien to published TPI 10050Sstevel@tonic-gate * but we support it anyway). 10060Sstevel@tonic-gate */ 10070Sstevel@tonic-gate static void 10080Sstevel@tonic-gate icmp_addr_req(queue_t *q, mblk_t *mp) 10090Sstevel@tonic-gate { 10100Sstevel@tonic-gate icmp_t *icmp = (icmp_t *)q->q_ptr; 10110Sstevel@tonic-gate mblk_t *ackmp; 10120Sstevel@tonic-gate struct T_addr_ack *taa; 10130Sstevel@tonic-gate 10140Sstevel@tonic-gate /* Make it large enough for worst case */ 10150Sstevel@tonic-gate ackmp = reallocb(mp, sizeof (struct T_addr_ack) + 10160Sstevel@tonic-gate 2 * sizeof (sin6_t), 1); 10170Sstevel@tonic-gate if (ackmp == NULL) { 10180Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, ENOMEM); 10190Sstevel@tonic-gate return; 10200Sstevel@tonic-gate } 10210Sstevel@tonic-gate taa = (struct T_addr_ack *)ackmp->b_rptr; 10220Sstevel@tonic-gate 10230Sstevel@tonic-gate bzero(taa, sizeof (struct T_addr_ack)); 10240Sstevel@tonic-gate ackmp->b_wptr = (uchar_t *)&taa[1]; 10250Sstevel@tonic-gate 10260Sstevel@tonic-gate taa->PRIM_type = T_ADDR_ACK; 10270Sstevel@tonic-gate ackmp->b_datap->db_type = M_PCPROTO; 10280Sstevel@tonic-gate 10290Sstevel@tonic-gate /* 10300Sstevel@tonic-gate * Note: Following code assumes 32 bit alignment of basic 10310Sstevel@tonic-gate * data structures like sin_t and struct T_addr_ack. 10320Sstevel@tonic-gate */ 10330Sstevel@tonic-gate if (icmp->icmp_state != TS_UNBND) { 10340Sstevel@tonic-gate /* 10350Sstevel@tonic-gate * Fill in local address 10360Sstevel@tonic-gate */ 10370Sstevel@tonic-gate taa->LOCADDR_offset = sizeof (*taa); 10380Sstevel@tonic-gate if (icmp->icmp_family == AF_INET) { 10390Sstevel@tonic-gate sin_t *sin; 10400Sstevel@tonic-gate 10410Sstevel@tonic-gate taa->LOCADDR_length = sizeof (sin_t); 10420Sstevel@tonic-gate sin = (sin_t *)&taa[1]; 10430Sstevel@tonic-gate /* Fill zeroes and then intialize non-zero fields */ 10440Sstevel@tonic-gate *sin = sin_null; 10450Sstevel@tonic-gate sin->sin_family = AF_INET; 10460Sstevel@tonic-gate if (!IN6_IS_ADDR_V4MAPPED_ANY(&icmp->icmp_v6src) && 10470Sstevel@tonic-gate !IN6_IS_ADDR_UNSPECIFIED(&icmp->icmp_v6src)) { 10480Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&icmp->icmp_v6src, 10490Sstevel@tonic-gate sin->sin_addr.s_addr); 10500Sstevel@tonic-gate } else { 10510Sstevel@tonic-gate /* 10520Sstevel@tonic-gate * INADDR_ANY 10530Sstevel@tonic-gate * icmp_v6src is not set, we might be bound to 10540Sstevel@tonic-gate * broadcast/multicast. Use icmp_bound_v6src as 10550Sstevel@tonic-gate * local address instead (that could 10560Sstevel@tonic-gate * also still be INADDR_ANY) 10570Sstevel@tonic-gate */ 10580Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&icmp->icmp_bound_v6src, 10590Sstevel@tonic-gate sin->sin_addr.s_addr); 10600Sstevel@tonic-gate } 10610Sstevel@tonic-gate ackmp->b_wptr = (uchar_t *)&sin[1]; 10620Sstevel@tonic-gate } else { 10630Sstevel@tonic-gate sin6_t *sin6; 10640Sstevel@tonic-gate 10650Sstevel@tonic-gate ASSERT(icmp->icmp_family == AF_INET6); 10660Sstevel@tonic-gate taa->LOCADDR_length = sizeof (sin6_t); 10670Sstevel@tonic-gate sin6 = (sin6_t *)&taa[1]; 10680Sstevel@tonic-gate /* Fill zeroes and then intialize non-zero fields */ 10690Sstevel@tonic-gate *sin6 = sin6_null; 10700Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 10710Sstevel@tonic-gate if (!IN6_IS_ADDR_UNSPECIFIED(&icmp->icmp_v6src)) { 10720Sstevel@tonic-gate sin6->sin6_addr = icmp->icmp_v6src; 10730Sstevel@tonic-gate } else { 10740Sstevel@tonic-gate /* 10750Sstevel@tonic-gate * UNSPECIFIED 10760Sstevel@tonic-gate * icmp_v6src is not set, we might be bound to 10770Sstevel@tonic-gate * broadcast/multicast. Use icmp_bound_v6src as 10780Sstevel@tonic-gate * local address instead (that could 10790Sstevel@tonic-gate * also still be UNSPECIFIED) 10800Sstevel@tonic-gate */ 10810Sstevel@tonic-gate sin6->sin6_addr = icmp->icmp_bound_v6src; 10820Sstevel@tonic-gate } 10830Sstevel@tonic-gate ackmp->b_wptr = (uchar_t *)&sin6[1]; 10840Sstevel@tonic-gate } 10850Sstevel@tonic-gate } 10860Sstevel@tonic-gate ASSERT(ackmp->b_wptr <= ackmp->b_datap->db_lim); 10870Sstevel@tonic-gate qreply(q, ackmp); 10880Sstevel@tonic-gate } 10890Sstevel@tonic-gate 10900Sstevel@tonic-gate static void 10910Sstevel@tonic-gate icmp_copy_info(struct T_info_ack *tap, icmp_t *icmp) 10920Sstevel@tonic-gate { 10930Sstevel@tonic-gate *tap = icmp_g_t_info_ack; 10940Sstevel@tonic-gate 10950Sstevel@tonic-gate if (icmp->icmp_family == AF_INET6) 10960Sstevel@tonic-gate tap->ADDR_size = sizeof (sin6_t); 10970Sstevel@tonic-gate else 10980Sstevel@tonic-gate tap->ADDR_size = sizeof (sin_t); 10990Sstevel@tonic-gate tap->CURRENT_state = icmp->icmp_state; 11000Sstevel@tonic-gate tap->OPT_size = icmp_max_optsize; 11010Sstevel@tonic-gate } 11020Sstevel@tonic-gate 11030Sstevel@tonic-gate /* 11040Sstevel@tonic-gate * This routine responds to T_CAPABILITY_REQ messages. It is called by 11050Sstevel@tonic-gate * icmp_wput. Much of the T_CAPABILITY_ACK information is copied from 11060Sstevel@tonic-gate * icmp_g_t_info_ack. The current state of the stream is copied from 11070Sstevel@tonic-gate * icmp_state. 11080Sstevel@tonic-gate */ 11090Sstevel@tonic-gate static void 11100Sstevel@tonic-gate icmp_capability_req(queue_t *q, mblk_t *mp) 11110Sstevel@tonic-gate { 11120Sstevel@tonic-gate icmp_t *icmp = (icmp_t *)q->q_ptr; 11130Sstevel@tonic-gate t_uscalar_t cap_bits1; 11140Sstevel@tonic-gate struct T_capability_ack *tcap; 11150Sstevel@tonic-gate 11160Sstevel@tonic-gate cap_bits1 = ((struct T_capability_req *)mp->b_rptr)->CAP_bits1; 11170Sstevel@tonic-gate 11180Sstevel@tonic-gate mp = tpi_ack_alloc(mp, sizeof (struct T_capability_ack), 11190Sstevel@tonic-gate mp->b_datap->db_type, T_CAPABILITY_ACK); 11200Sstevel@tonic-gate if (!mp) 11210Sstevel@tonic-gate return; 11220Sstevel@tonic-gate 11230Sstevel@tonic-gate tcap = (struct T_capability_ack *)mp->b_rptr; 11240Sstevel@tonic-gate tcap->CAP_bits1 = 0; 11250Sstevel@tonic-gate 11260Sstevel@tonic-gate if (cap_bits1 & TC1_INFO) { 11270Sstevel@tonic-gate icmp_copy_info(&tcap->INFO_ack, icmp); 11280Sstevel@tonic-gate tcap->CAP_bits1 |= TC1_INFO; 11290Sstevel@tonic-gate } 11300Sstevel@tonic-gate 11310Sstevel@tonic-gate qreply(q, mp); 11320Sstevel@tonic-gate } 11330Sstevel@tonic-gate 11340Sstevel@tonic-gate /* 11350Sstevel@tonic-gate * This routine responds to T_INFO_REQ messages. It is called by icmp_wput. 11360Sstevel@tonic-gate * Most of the T_INFO_ACK information is copied from icmp_g_t_info_ack. 11370Sstevel@tonic-gate * The current state of the stream is copied from icmp_state. 11380Sstevel@tonic-gate */ 11390Sstevel@tonic-gate static void 11400Sstevel@tonic-gate icmp_info_req(queue_t *q, mblk_t *mp) 11410Sstevel@tonic-gate { 11420Sstevel@tonic-gate icmp_t *icmp = (icmp_t *)q->q_ptr; 11430Sstevel@tonic-gate 11440Sstevel@tonic-gate mp = tpi_ack_alloc(mp, sizeof (struct T_info_ack), M_PCPROTO, 11450Sstevel@tonic-gate T_INFO_ACK); 11460Sstevel@tonic-gate if (!mp) 11470Sstevel@tonic-gate return; 11480Sstevel@tonic-gate icmp_copy_info((struct T_info_ack *)mp->b_rptr, icmp); 11490Sstevel@tonic-gate qreply(q, mp); 11500Sstevel@tonic-gate } 11510Sstevel@tonic-gate 11520Sstevel@tonic-gate /* 11530Sstevel@tonic-gate * IP recognizes seven kinds of bind requests: 11540Sstevel@tonic-gate * 11550Sstevel@tonic-gate * - A zero-length address binds only to the protocol number. 11560Sstevel@tonic-gate * 11570Sstevel@tonic-gate * - A 4-byte address is treated as a request to 11580Sstevel@tonic-gate * validate that the address is a valid local IPv4 11590Sstevel@tonic-gate * address, appropriate for an application to bind to. 11600Sstevel@tonic-gate * IP does the verification, but does not make any note 11610Sstevel@tonic-gate * of the address at this time. 11620Sstevel@tonic-gate * 11630Sstevel@tonic-gate * - A 16-byte address contains is treated as a request 11640Sstevel@tonic-gate * to validate a local IPv6 address, as the 4-byte 11650Sstevel@tonic-gate * address case above. 11660Sstevel@tonic-gate * 11670Sstevel@tonic-gate * - A 16-byte sockaddr_in to validate the local IPv4 address and also 11680Sstevel@tonic-gate * use it for the inbound fanout of packets. 11690Sstevel@tonic-gate * 11700Sstevel@tonic-gate * - A 24-byte sockaddr_in6 to validate the local IPv6 address and also 11710Sstevel@tonic-gate * use it for the inbound fanout of packets. 11720Sstevel@tonic-gate * 11730Sstevel@tonic-gate * - A 12-byte address (ipa_conn_t) containing complete IPv4 fanout 11740Sstevel@tonic-gate * information consisting of local and remote addresses 11750Sstevel@tonic-gate * and ports (unused for raw sockets). In this case, the addresses are both 11760Sstevel@tonic-gate * validated as appropriate for this operation, and, if 11770Sstevel@tonic-gate * so, the information is retained for use in the 11780Sstevel@tonic-gate * inbound fanout. 11790Sstevel@tonic-gate * 11800Sstevel@tonic-gate * - A 36-byte address address (ipa6_conn_t) containing complete IPv6 11810Sstevel@tonic-gate * fanout information, like the 12-byte case above. 11820Sstevel@tonic-gate * 11830Sstevel@tonic-gate * IP will also fill in the IRE request mblk with information 11840Sstevel@tonic-gate * regarding our peer. In all cases, we notify IP of our protocol 11850Sstevel@tonic-gate * type by appending a single protocol byte to the bind request. 11860Sstevel@tonic-gate */ 11870Sstevel@tonic-gate static mblk_t * 11880Sstevel@tonic-gate icmp_ip_bind_mp(icmp_t *icmp, t_scalar_t bind_prim, t_scalar_t addr_length, 11890Sstevel@tonic-gate in_port_t fport) 11900Sstevel@tonic-gate { 11910Sstevel@tonic-gate char *cp; 11920Sstevel@tonic-gate mblk_t *mp; 11930Sstevel@tonic-gate struct T_bind_req *tbr; 11940Sstevel@tonic-gate ipa_conn_t *ac; 11950Sstevel@tonic-gate ipa6_conn_t *ac6; 11960Sstevel@tonic-gate sin_t *sin; 11970Sstevel@tonic-gate sin6_t *sin6; 11980Sstevel@tonic-gate 11990Sstevel@tonic-gate ASSERT(bind_prim == O_T_BIND_REQ || bind_prim == T_BIND_REQ); 12000Sstevel@tonic-gate 12010Sstevel@tonic-gate mp = allocb(sizeof (*tbr) + addr_length + 1, BPRI_HI); 12020Sstevel@tonic-gate if (mp == NULL) 12030Sstevel@tonic-gate return (NULL); 12040Sstevel@tonic-gate mp->b_datap->db_type = M_PROTO; 12050Sstevel@tonic-gate tbr = (struct T_bind_req *)mp->b_rptr; 12060Sstevel@tonic-gate tbr->PRIM_type = bind_prim; 12070Sstevel@tonic-gate tbr->ADDR_offset = sizeof (*tbr); 12080Sstevel@tonic-gate tbr->CONIND_number = 0; 12090Sstevel@tonic-gate tbr->ADDR_length = addr_length; 12100Sstevel@tonic-gate cp = (char *)&tbr[1]; 12110Sstevel@tonic-gate switch (addr_length) { 12120Sstevel@tonic-gate case sizeof (ipa_conn_t): 12130Sstevel@tonic-gate ASSERT(icmp->icmp_family == AF_INET); 12140Sstevel@tonic-gate /* Append a request for an IRE */ 12150Sstevel@tonic-gate mp->b_cont = allocb(sizeof (ire_t), BPRI_HI); 12160Sstevel@tonic-gate if (mp->b_cont == NULL) { 12170Sstevel@tonic-gate freemsg(mp); 12180Sstevel@tonic-gate return (NULL); 12190Sstevel@tonic-gate } 12200Sstevel@tonic-gate mp->b_cont->b_wptr += sizeof (ire_t); 12210Sstevel@tonic-gate mp->b_cont->b_datap->db_type = IRE_DB_REQ_TYPE; 12220Sstevel@tonic-gate 12230Sstevel@tonic-gate /* cp known to be 32 bit aligned */ 12240Sstevel@tonic-gate ac = (ipa_conn_t *)cp; 12250Sstevel@tonic-gate ac->ac_laddr = V4_PART_OF_V6(icmp->icmp_v6src); 12260Sstevel@tonic-gate ac->ac_faddr = V4_PART_OF_V6(icmp->icmp_v6dst); 12270Sstevel@tonic-gate ac->ac_fport = fport; 12280Sstevel@tonic-gate ac->ac_lport = 0; 12290Sstevel@tonic-gate break; 12300Sstevel@tonic-gate 12310Sstevel@tonic-gate case sizeof (ipa6_conn_t): 12320Sstevel@tonic-gate ASSERT(icmp->icmp_family == AF_INET6); 12330Sstevel@tonic-gate /* Append a request for an IRE */ 12340Sstevel@tonic-gate mp->b_cont = allocb(sizeof (ire_t), BPRI_HI); 12350Sstevel@tonic-gate if (mp->b_cont == NULL) { 12360Sstevel@tonic-gate freemsg(mp); 12370Sstevel@tonic-gate return (NULL); 12380Sstevel@tonic-gate } 12390Sstevel@tonic-gate mp->b_cont->b_wptr += sizeof (ire_t); 12400Sstevel@tonic-gate mp->b_cont->b_datap->db_type = IRE_DB_REQ_TYPE; 12410Sstevel@tonic-gate 12420Sstevel@tonic-gate /* cp known to be 32 bit aligned */ 12430Sstevel@tonic-gate ac6 = (ipa6_conn_t *)cp; 12440Sstevel@tonic-gate ac6->ac6_laddr = icmp->icmp_v6src; 12450Sstevel@tonic-gate ac6->ac6_faddr = icmp->icmp_v6dst; 12460Sstevel@tonic-gate ac6->ac6_fport = fport; 12470Sstevel@tonic-gate ac6->ac6_lport = 0; 12480Sstevel@tonic-gate break; 12490Sstevel@tonic-gate 12500Sstevel@tonic-gate case sizeof (sin_t): 12510Sstevel@tonic-gate ASSERT(icmp->icmp_family == AF_INET); 12520Sstevel@tonic-gate /* Append a request for an IRE */ 12530Sstevel@tonic-gate mp->b_cont = allocb(sizeof (ire_t), BPRI_HI); 12540Sstevel@tonic-gate if (!mp->b_cont) { 12550Sstevel@tonic-gate freemsg(mp); 12560Sstevel@tonic-gate return (NULL); 12570Sstevel@tonic-gate } 12580Sstevel@tonic-gate mp->b_cont->b_wptr += sizeof (ire_t); 12590Sstevel@tonic-gate mp->b_cont->b_datap->db_type = IRE_DB_REQ_TYPE; 12600Sstevel@tonic-gate 12610Sstevel@tonic-gate sin = (sin_t *)cp; 12620Sstevel@tonic-gate *sin = sin_null; 12630Sstevel@tonic-gate sin->sin_family = AF_INET; 12640Sstevel@tonic-gate sin->sin_addr.s_addr = V4_PART_OF_V6(icmp->icmp_bound_v6src); 12650Sstevel@tonic-gate break; 12660Sstevel@tonic-gate 12670Sstevel@tonic-gate case sizeof (sin6_t): 12680Sstevel@tonic-gate ASSERT(icmp->icmp_family == AF_INET6); 12690Sstevel@tonic-gate /* Append a request for an IRE */ 12700Sstevel@tonic-gate mp->b_cont = allocb(sizeof (ire_t), BPRI_HI); 12710Sstevel@tonic-gate if (!mp->b_cont) { 12720Sstevel@tonic-gate freemsg(mp); 12730Sstevel@tonic-gate return (NULL); 12740Sstevel@tonic-gate } 12750Sstevel@tonic-gate mp->b_cont->b_wptr += sizeof (ire_t); 12760Sstevel@tonic-gate mp->b_cont->b_datap->db_type = IRE_DB_REQ_TYPE; 12770Sstevel@tonic-gate 12780Sstevel@tonic-gate sin6 = (sin6_t *)cp; 12790Sstevel@tonic-gate *sin6 = sin6_null; 12800Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 12810Sstevel@tonic-gate sin6->sin6_addr = icmp->icmp_bound_v6src; 12820Sstevel@tonic-gate break; 12830Sstevel@tonic-gate } 12840Sstevel@tonic-gate /* Add protocol number to end */ 12850Sstevel@tonic-gate cp[addr_length] = icmp->icmp_proto; 12860Sstevel@tonic-gate mp->b_wptr = (uchar_t *)&cp[addr_length + 1]; 12870Sstevel@tonic-gate return (mp); 12880Sstevel@tonic-gate } 12890Sstevel@tonic-gate 12901676Sjpk /* ARGSUSED */ 12911676Sjpk static void 12921676Sjpk dummy_func(void *arg) 12931676Sjpk { 12941676Sjpk } 12951676Sjpk 12961676Sjpk static mblk_t * 12971676Sjpk alloc_wait(queue_t *q, size_t len, int pri, int *errp) 12981676Sjpk { 12991676Sjpk mblk_t *mp; 13001676Sjpk bufcall_id_t id; 13011676Sjpk int retv; 13021676Sjpk 13031676Sjpk while ((mp = allocb(len, pri)) == NULL) { 13041676Sjpk id = qbufcall(q, len, pri, dummy_func, NULL); 13051676Sjpk if (id == 0) { 13061676Sjpk *errp = ENOMEM; 13071676Sjpk break; 13081676Sjpk } 13091676Sjpk retv = qwait_sig(q); 13101676Sjpk qunbufcall(q, id); 13111676Sjpk if (retv == 0) { 13121676Sjpk *errp = EINTR; 13131676Sjpk break; 13141676Sjpk } 13151676Sjpk } 13161676Sjpk if (mp != NULL) 13171676Sjpk mp->b_wptr += len; 13181676Sjpk return (mp); 13191676Sjpk } 13201676Sjpk 13210Sstevel@tonic-gate /* 13220Sstevel@tonic-gate * This is the open routine for icmp. It allocates a icmp_t structure for 13230Sstevel@tonic-gate * the stream and, on the first open of the module, creates an ND table. 13240Sstevel@tonic-gate */ 13250Sstevel@tonic-gate static int 13260Sstevel@tonic-gate icmp_open(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *credp) 13270Sstevel@tonic-gate { 13280Sstevel@tonic-gate int err; 13290Sstevel@tonic-gate icmp_t *icmp; 13301676Sjpk mblk_t *mp; 13311676Sjpk out_labeled_t *olp; 13320Sstevel@tonic-gate 13330Sstevel@tonic-gate /* If the stream is already open, return immediately. */ 13340Sstevel@tonic-gate if (q->q_ptr != NULL) 13350Sstevel@tonic-gate return (0); 13360Sstevel@tonic-gate 13370Sstevel@tonic-gate /* If this is not a push of icmp as a module, fail. */ 13380Sstevel@tonic-gate if (sflag != MODOPEN) 13390Sstevel@tonic-gate return (EINVAL); 13400Sstevel@tonic-gate 13410Sstevel@tonic-gate /* 13420Sstevel@tonic-gate * Defer the qprocson until everything is initialized since 13430Sstevel@tonic-gate * we are D_MTPERQ and after qprocson the rput routine can 13440Sstevel@tonic-gate * run. (Could do qprocson earlier since icmp currently 13450Sstevel@tonic-gate * has an outer perimeter.) 13460Sstevel@tonic-gate */ 13470Sstevel@tonic-gate 13480Sstevel@tonic-gate /* 13490Sstevel@tonic-gate * Create a icmp_t structure for this stream and link into the 13500Sstevel@tonic-gate * list of open streams. 13510Sstevel@tonic-gate */ 13520Sstevel@tonic-gate err = mi_open_comm(&icmp_g_head, sizeof (icmp_t), q, devp, 13530Sstevel@tonic-gate flag, sflag, credp); 13541676Sjpk if (err != 0) 13550Sstevel@tonic-gate return (err); 13560Sstevel@tonic-gate 13570Sstevel@tonic-gate /* 13580Sstevel@tonic-gate * The receive hiwat is only looked at on the stream head queue. 13590Sstevel@tonic-gate * Store in q_hiwat in order to return on SO_RCVBUF getsockopts. 13600Sstevel@tonic-gate */ 13610Sstevel@tonic-gate q->q_hiwat = icmp_recv_hiwat; 13620Sstevel@tonic-gate 13630Sstevel@tonic-gate /* Set the initial state of the stream and the privilege status. */ 13640Sstevel@tonic-gate icmp = (icmp_t *)q->q_ptr; 13650Sstevel@tonic-gate icmp->icmp_state = TS_UNBND; 13660Sstevel@tonic-gate icmp->icmp_multicast_ttl = IP_DEFAULT_MULTICAST_TTL; 13670Sstevel@tonic-gate icmp->icmp_multicast_loop = IP_DEFAULT_MULTICAST_LOOP; 13680Sstevel@tonic-gate icmp->icmp_filter = NULL; 13690Sstevel@tonic-gate 13700Sstevel@tonic-gate icmp->icmp_credp = credp; 13710Sstevel@tonic-gate crhold(credp); 13720Sstevel@tonic-gate 13731676Sjpk /* 13741676Sjpk * If the caller has the process-wide flag set, then default to MAC 13751676Sjpk * exempt mode. This allows read-down to unlabeled hosts. 13761676Sjpk */ 13771676Sjpk if (getpflags(NET_MAC_AWARE, credp) != 0) 13781676Sjpk icmp->icmp_mac_exempt = B_TRUE; 13791676Sjpk 13800Sstevel@tonic-gate icmp->icmp_zoneid = getzoneid(); 13810Sstevel@tonic-gate 13820Sstevel@tonic-gate if (getmajor(*devp) == (major_t)ICMP6_MAJ) { 13830Sstevel@tonic-gate icmp->icmp_ipversion = IPV6_VERSION; 13840Sstevel@tonic-gate icmp->icmp_family = AF_INET6; 13850Sstevel@tonic-gate /* May be changed by a SO_PROTOTYPE socket option. */ 13860Sstevel@tonic-gate icmp->icmp_proto = IPPROTO_ICMPV6; 13870Sstevel@tonic-gate icmp->icmp_checksum_off = 2; /* Offset for icmp6_cksum */ 13880Sstevel@tonic-gate icmp->icmp_max_hdr_len = IPV6_HDR_LEN; 13890Sstevel@tonic-gate icmp->icmp_ttl = (uint8_t)icmp_ipv6_hoplimit; 13900Sstevel@tonic-gate } else { 13910Sstevel@tonic-gate icmp->icmp_ipversion = IPV4_VERSION; 13920Sstevel@tonic-gate icmp->icmp_family = AF_INET; 13930Sstevel@tonic-gate /* May be changed by a SO_PROTOTYPE socket option. */ 13940Sstevel@tonic-gate icmp->icmp_proto = IPPROTO_ICMP; 13950Sstevel@tonic-gate icmp->icmp_max_hdr_len = IP_SIMPLE_HDR_LENGTH; 13960Sstevel@tonic-gate icmp->icmp_ttl = (uint8_t)icmp_ipv4_ttl; 13970Sstevel@tonic-gate } 13980Sstevel@tonic-gate qprocson(q); 13990Sstevel@tonic-gate 14000Sstevel@tonic-gate /* 14010Sstevel@tonic-gate * Check if icmp is being I_PUSHed by a non-privileged user. 14020Sstevel@tonic-gate * If so, we set icmp_restricted to indicate that only MIB 14030Sstevel@tonic-gate * traffic may pass. 14040Sstevel@tonic-gate */ 14050Sstevel@tonic-gate if (secpolicy_net_icmpaccess(credp) != 0) { 14060Sstevel@tonic-gate icmp->icmp_restricted = 1; 14070Sstevel@tonic-gate } 14080Sstevel@tonic-gate 14090Sstevel@tonic-gate /* 14100Sstevel@tonic-gate * The transmit hiwat is only looked at on IP's queue. 14110Sstevel@tonic-gate * Store in q_hiwat in order to return on SO_SNDBUF 14120Sstevel@tonic-gate * getsockopts. 14130Sstevel@tonic-gate */ 14140Sstevel@tonic-gate WR(q)->q_hiwat = icmp_xmit_hiwat; 14150Sstevel@tonic-gate WR(q)->q_next->q_hiwat = WR(q)->q_hiwat; 14160Sstevel@tonic-gate WR(q)->q_lowat = icmp_xmit_lowat; 14170Sstevel@tonic-gate WR(q)->q_next->q_lowat = WR(q)->q_lowat; 14180Sstevel@tonic-gate 14190Sstevel@tonic-gate if (icmp->icmp_family == AF_INET6) { 14200Sstevel@tonic-gate /* Build initial header template for transmit */ 14211676Sjpk err = icmp_build_hdrs(q, icmp); 14221676Sjpk if (err != 0) 14231676Sjpk goto open_error; 14240Sstevel@tonic-gate } 14250Sstevel@tonic-gate /* Set the Stream head write offset. */ 14260Sstevel@tonic-gate (void) mi_set_sth_wroff(q, icmp->icmp_max_hdr_len + icmp_wroff_extra); 14270Sstevel@tonic-gate (void) mi_set_sth_hiwat(q, q->q_hiwat); 14280Sstevel@tonic-gate 14291676Sjpk if (is_system_labeled()) { 14301676Sjpk /* notify IP that we know about labeling */ 14311676Sjpk mp = alloc_wait(q, sizeof (*olp), BPRI_MED, &err); 14321676Sjpk if (mp == NULL) 14331676Sjpk goto open_error; 14341676Sjpk mp->b_datap->db_type = M_CTL; 14351676Sjpk olp = (out_labeled_t *)mp->b_rptr; 14361676Sjpk olp->out_labeled_type = IP_ULP_OUT_LABELED; 14371676Sjpk olp->out_qnext = WR(q)->q_next; 14381676Sjpk putnext(WR(q), mp); 14391676Sjpk 14401676Sjpk /* save off a copy for closing */ 14411676Sjpk mp = alloc_wait(q, sizeof (*olp), BPRI_MED, &err); 14421676Sjpk if (mp == NULL) 14431676Sjpk goto open_error; 14441676Sjpk mp->b_datap->db_type = M_CTL; 14451676Sjpk olp = (out_labeled_t *)mp->b_rptr; 14461676Sjpk olp->out_labeled_type = IP_ULP_OUT_LABELED; 14471676Sjpk olp->out_qnext = NULL; 14481676Sjpk icmp->icmp_delabel = mp; 14491676Sjpk } 14501676Sjpk 14510Sstevel@tonic-gate return (0); 14521676Sjpk 14531676Sjpk open_error: 14541676Sjpk qprocsoff(q); 14551676Sjpk crfree(credp); 14561676Sjpk (void) mi_close_comm(&icmp_g_head, q); 14571676Sjpk return (err); 14580Sstevel@tonic-gate } 14590Sstevel@tonic-gate 14600Sstevel@tonic-gate /* 14610Sstevel@tonic-gate * Which ICMP options OK to set through T_UNITDATA_REQ... 14620Sstevel@tonic-gate */ 14630Sstevel@tonic-gate /* ARGSUSED */ 14640Sstevel@tonic-gate static boolean_t 14650Sstevel@tonic-gate icmp_opt_allow_udr_set(t_scalar_t level, t_scalar_t name) 14660Sstevel@tonic-gate { 14670Sstevel@tonic-gate return (B_TRUE); 14680Sstevel@tonic-gate } 14690Sstevel@tonic-gate 14700Sstevel@tonic-gate /* 14710Sstevel@tonic-gate * This routine gets default values of certain options whose default 14720Sstevel@tonic-gate * values are maintained by protcol specific code 14730Sstevel@tonic-gate */ 14740Sstevel@tonic-gate /* ARGSUSED */ 14750Sstevel@tonic-gate int 14760Sstevel@tonic-gate icmp_opt_default(queue_t *q, int level, int name, uchar_t *ptr) 14770Sstevel@tonic-gate { 14780Sstevel@tonic-gate int *i1 = (int *)ptr; 14790Sstevel@tonic-gate 14800Sstevel@tonic-gate switch (level) { 14810Sstevel@tonic-gate case IPPROTO_IP: 14820Sstevel@tonic-gate switch (name) { 14830Sstevel@tonic-gate case IP_MULTICAST_TTL: 14840Sstevel@tonic-gate *ptr = (uchar_t)IP_DEFAULT_MULTICAST_TTL; 14850Sstevel@tonic-gate return (sizeof (uchar_t)); 14860Sstevel@tonic-gate case IP_MULTICAST_LOOP: 14870Sstevel@tonic-gate *ptr = (uchar_t)IP_DEFAULT_MULTICAST_LOOP; 14880Sstevel@tonic-gate return (sizeof (uchar_t)); 14890Sstevel@tonic-gate } 14900Sstevel@tonic-gate break; 14910Sstevel@tonic-gate case IPPROTO_IPV6: 14920Sstevel@tonic-gate switch (name) { 14930Sstevel@tonic-gate case IPV6_MULTICAST_HOPS: 14940Sstevel@tonic-gate *i1 = IP_DEFAULT_MULTICAST_TTL; 14950Sstevel@tonic-gate return (sizeof (int)); 14960Sstevel@tonic-gate case IPV6_MULTICAST_LOOP: 14970Sstevel@tonic-gate *i1 = IP_DEFAULT_MULTICAST_LOOP; 14980Sstevel@tonic-gate return (sizeof (int)); 14990Sstevel@tonic-gate case IPV6_UNICAST_HOPS: 15000Sstevel@tonic-gate *i1 = icmp_ipv6_hoplimit; 15010Sstevel@tonic-gate return (sizeof (int)); 15020Sstevel@tonic-gate } 15030Sstevel@tonic-gate break; 15040Sstevel@tonic-gate case IPPROTO_ICMPV6: 15050Sstevel@tonic-gate switch (name) { 15060Sstevel@tonic-gate case ICMP6_FILTER: 15070Sstevel@tonic-gate /* Make it look like "pass all" */ 15080Sstevel@tonic-gate ICMP6_FILTER_SETPASSALL((icmp6_filter_t *)ptr); 15090Sstevel@tonic-gate return (sizeof (icmp6_filter_t)); 15100Sstevel@tonic-gate } 15110Sstevel@tonic-gate break; 15120Sstevel@tonic-gate } 15130Sstevel@tonic-gate return (-1); 15140Sstevel@tonic-gate } 15150Sstevel@tonic-gate 15160Sstevel@tonic-gate /* 15170Sstevel@tonic-gate * This routine retrieves the current status of socket options. 15180Sstevel@tonic-gate * It returns the size of the option retrieved. 15190Sstevel@tonic-gate */ 15200Sstevel@tonic-gate int 15210Sstevel@tonic-gate icmp_opt_get(queue_t *q, int level, int name, uchar_t *ptr) 15220Sstevel@tonic-gate { 15230Sstevel@tonic-gate icmp_t *icmp = (icmp_t *)q->q_ptr; 15240Sstevel@tonic-gate int *i1 = (int *)ptr; 15250Sstevel@tonic-gate ip6_pkt_t *ipp = &icmp->icmp_sticky_ipp; 15260Sstevel@tonic-gate 15270Sstevel@tonic-gate switch (level) { 15280Sstevel@tonic-gate case SOL_SOCKET: 15290Sstevel@tonic-gate switch (name) { 15300Sstevel@tonic-gate case SO_DEBUG: 15310Sstevel@tonic-gate *i1 = icmp->icmp_debug; 15320Sstevel@tonic-gate break; 15330Sstevel@tonic-gate case SO_TYPE: 15340Sstevel@tonic-gate *i1 = SOCK_RAW; 15350Sstevel@tonic-gate break; 15360Sstevel@tonic-gate case SO_PROTOTYPE: 15370Sstevel@tonic-gate *i1 = icmp->icmp_proto; 15380Sstevel@tonic-gate break; 15390Sstevel@tonic-gate case SO_REUSEADDR: 15400Sstevel@tonic-gate *i1 = icmp->icmp_reuseaddr; 15410Sstevel@tonic-gate break; 15420Sstevel@tonic-gate 15430Sstevel@tonic-gate /* 15440Sstevel@tonic-gate * The following three items are available here, 15450Sstevel@tonic-gate * but are only meaningful to IP. 15460Sstevel@tonic-gate */ 15470Sstevel@tonic-gate case SO_DONTROUTE: 15480Sstevel@tonic-gate *i1 = icmp->icmp_dontroute; 15490Sstevel@tonic-gate break; 15500Sstevel@tonic-gate case SO_USELOOPBACK: 15510Sstevel@tonic-gate *i1 = icmp->icmp_useloopback; 15520Sstevel@tonic-gate break; 15530Sstevel@tonic-gate case SO_BROADCAST: 15540Sstevel@tonic-gate *i1 = icmp->icmp_broadcast; 15550Sstevel@tonic-gate break; 15560Sstevel@tonic-gate 15570Sstevel@tonic-gate case SO_SNDBUF: 15580Sstevel@tonic-gate ASSERT(q->q_hiwat <= INT_MAX); 15590Sstevel@tonic-gate *i1 = (int)q->q_hiwat; 15600Sstevel@tonic-gate break; 15610Sstevel@tonic-gate case SO_RCVBUF: 15620Sstevel@tonic-gate ASSERT(RD(q)->q_hiwat <= INT_MAX); 15630Sstevel@tonic-gate *i1 = (int)RD(q)->q_hiwat; 15640Sstevel@tonic-gate break; 15650Sstevel@tonic-gate case SO_DGRAM_ERRIND: 15660Sstevel@tonic-gate *i1 = icmp->icmp_dgram_errind; 15670Sstevel@tonic-gate break; 15681673Sgt145670 case SO_TIMESTAMP: 15691673Sgt145670 *i1 = icmp->icmp_timestamp; 15701673Sgt145670 break; 15711676Sjpk case SO_MAC_EXEMPT: 15721676Sjpk *i1 = icmp->icmp_mac_exempt; 15731676Sjpk break; 15740Sstevel@tonic-gate /* 15752263Ssommerfe * Following four not meaningful for icmp 15760Sstevel@tonic-gate * Action is same as "default" to which we fallthrough 15770Sstevel@tonic-gate * so we keep them in comments. 15780Sstevel@tonic-gate * case SO_LINGER: 15790Sstevel@tonic-gate * case SO_KEEPALIVE: 15800Sstevel@tonic-gate * case SO_OOBINLINE: 15812263Ssommerfe * case SO_ALLZONES: 15820Sstevel@tonic-gate */ 15830Sstevel@tonic-gate default: 15840Sstevel@tonic-gate return (-1); 15850Sstevel@tonic-gate } 15860Sstevel@tonic-gate break; 15870Sstevel@tonic-gate case IPPROTO_IP: 15880Sstevel@tonic-gate /* 15890Sstevel@tonic-gate * Only allow IPv4 option processing on IPv4 sockets. 15900Sstevel@tonic-gate */ 15910Sstevel@tonic-gate if (icmp->icmp_family != AF_INET) 15920Sstevel@tonic-gate return (-1); 15930Sstevel@tonic-gate 15940Sstevel@tonic-gate switch (name) { 15950Sstevel@tonic-gate case IP_OPTIONS: 15960Sstevel@tonic-gate case T_IP_OPTIONS: 15970Sstevel@tonic-gate /* Options are passed up with each packet */ 15980Sstevel@tonic-gate return (0); 15990Sstevel@tonic-gate case IP_HDRINCL: 16000Sstevel@tonic-gate *i1 = (int)icmp->icmp_hdrincl; 16010Sstevel@tonic-gate break; 16020Sstevel@tonic-gate case IP_TOS: 16030Sstevel@tonic-gate case T_IP_TOS: 16040Sstevel@tonic-gate *i1 = (int)icmp->icmp_type_of_service; 16050Sstevel@tonic-gate break; 16060Sstevel@tonic-gate case IP_TTL: 16070Sstevel@tonic-gate *i1 = (int)icmp->icmp_ttl; 16080Sstevel@tonic-gate break; 16090Sstevel@tonic-gate case IP_MULTICAST_IF: 16100Sstevel@tonic-gate /* 0 address if not set */ 16110Sstevel@tonic-gate *(ipaddr_t *)ptr = icmp->icmp_multicast_if_addr; 16120Sstevel@tonic-gate return (sizeof (ipaddr_t)); 16130Sstevel@tonic-gate case IP_MULTICAST_TTL: 16140Sstevel@tonic-gate *(uchar_t *)ptr = icmp->icmp_multicast_ttl; 16150Sstevel@tonic-gate return (sizeof (uchar_t)); 16160Sstevel@tonic-gate case IP_MULTICAST_LOOP: 16170Sstevel@tonic-gate *ptr = icmp->icmp_multicast_loop; 16180Sstevel@tonic-gate return (sizeof (uint8_t)); 16190Sstevel@tonic-gate case IP_BOUND_IF: 16200Sstevel@tonic-gate /* Zero if not set */ 16210Sstevel@tonic-gate *i1 = icmp->icmp_bound_if; 16220Sstevel@tonic-gate break; /* goto sizeof (int) option return */ 16230Sstevel@tonic-gate case IP_UNSPEC_SRC: 16240Sstevel@tonic-gate *ptr = icmp->icmp_unspec_source; 16250Sstevel@tonic-gate break; /* goto sizeof (int) option return */ 16260Sstevel@tonic-gate case IP_XMIT_IF: 16270Sstevel@tonic-gate *i1 = icmp->icmp_xmit_if; 16280Sstevel@tonic-gate break; /* goto sizeof (int) option return */ 16290Sstevel@tonic-gate case IP_RECVIF: 16300Sstevel@tonic-gate *ptr = icmp->icmp_recvif; 16310Sstevel@tonic-gate break; /* goto sizeof (int) option return */ 1632*3318Srshoaib case IP_RECVPKTINFO: 1633*3318Srshoaib /* 1634*3318Srshoaib * This also handles IP_PKTINFO. 1635*3318Srshoaib * IP_PKTINFO and IP_RECVPKTINFO have the same value. 1636*3318Srshoaib * Differentiation is based on the size of the argument 1637*3318Srshoaib * passed in. 1638*3318Srshoaib * This option is handled in IP which will return an 1639*3318Srshoaib * error for IP_PKTINFO as it's not supported as a 1640*3318Srshoaib * sticky option. 1641*3318Srshoaib */ 1642*3318Srshoaib return (-EINVAL); 16430Sstevel@tonic-gate /* 16440Sstevel@tonic-gate * Cannot "get" the value of following options 16450Sstevel@tonic-gate * at this level. Action is same as "default" to 16460Sstevel@tonic-gate * which we fallthrough so we keep them in comments. 16470Sstevel@tonic-gate * 16480Sstevel@tonic-gate * case IP_ADD_MEMBERSHIP: 16490Sstevel@tonic-gate * case IP_DROP_MEMBERSHIP: 16500Sstevel@tonic-gate * case IP_BLOCK_SOURCE: 16510Sstevel@tonic-gate * case IP_UNBLOCK_SOURCE: 16520Sstevel@tonic-gate * case IP_ADD_SOURCE_MEMBERSHIP: 16530Sstevel@tonic-gate * case IP_DROP_SOURCE_MEMBERSHIP: 16540Sstevel@tonic-gate * case MCAST_JOIN_GROUP: 16550Sstevel@tonic-gate * case MCAST_LEAVE_GROUP: 16560Sstevel@tonic-gate * case MCAST_BLOCK_SOURCE: 16570Sstevel@tonic-gate * case MCAST_UNBLOCK_SOURCE: 16580Sstevel@tonic-gate * case MCAST_JOIN_SOURCE_GROUP: 16590Sstevel@tonic-gate * case MCAST_LEAVE_SOURCE_GROUP: 16600Sstevel@tonic-gate * case MRT_INIT: 16610Sstevel@tonic-gate * case MRT_DONE: 16620Sstevel@tonic-gate * case MRT_ADD_VIF: 16630Sstevel@tonic-gate * case MRT_DEL_VIF: 16640Sstevel@tonic-gate * case MRT_ADD_MFC: 16650Sstevel@tonic-gate * case MRT_DEL_MFC: 16660Sstevel@tonic-gate * case MRT_VERSION: 16670Sstevel@tonic-gate * case MRT_ASSERT: 16680Sstevel@tonic-gate * case IP_SEC_OPT: 16690Sstevel@tonic-gate * case IP_DONTFAILOVER_IF: 16701663Spriyanka * case IP_NEXTHOP: 16710Sstevel@tonic-gate */ 16720Sstevel@tonic-gate default: 16730Sstevel@tonic-gate return (-1); 16740Sstevel@tonic-gate } 16750Sstevel@tonic-gate break; 16760Sstevel@tonic-gate case IPPROTO_IPV6: 16770Sstevel@tonic-gate /* 16780Sstevel@tonic-gate * Only allow IPv6 option processing on native IPv6 sockets. 16790Sstevel@tonic-gate */ 16800Sstevel@tonic-gate if (icmp->icmp_family != AF_INET6) 16810Sstevel@tonic-gate return (-1); 16820Sstevel@tonic-gate switch (name) { 16830Sstevel@tonic-gate case IPV6_UNICAST_HOPS: 16840Sstevel@tonic-gate *i1 = (unsigned int)icmp->icmp_ttl; 16850Sstevel@tonic-gate break; 16860Sstevel@tonic-gate case IPV6_MULTICAST_IF: 16870Sstevel@tonic-gate /* 0 index if not set */ 16880Sstevel@tonic-gate *i1 = icmp->icmp_multicast_if_index; 16890Sstevel@tonic-gate break; 16900Sstevel@tonic-gate case IPV6_MULTICAST_HOPS: 16910Sstevel@tonic-gate *i1 = icmp->icmp_multicast_ttl; 16920Sstevel@tonic-gate break; 16930Sstevel@tonic-gate case IPV6_MULTICAST_LOOP: 16940Sstevel@tonic-gate *i1 = icmp->icmp_multicast_loop; 16950Sstevel@tonic-gate break; 16960Sstevel@tonic-gate case IPV6_BOUND_IF: 16970Sstevel@tonic-gate /* Zero if not set */ 16980Sstevel@tonic-gate *i1 = icmp->icmp_bound_if; 16990Sstevel@tonic-gate break; 17000Sstevel@tonic-gate case IPV6_UNSPEC_SRC: 17010Sstevel@tonic-gate *i1 = icmp->icmp_unspec_source; 17020Sstevel@tonic-gate break; 17030Sstevel@tonic-gate case IPV6_CHECKSUM: 17040Sstevel@tonic-gate /* 17050Sstevel@tonic-gate * Return offset or -1 if no checksum offset. 17060Sstevel@tonic-gate * Does not apply to IPPROTO_ICMPV6 17070Sstevel@tonic-gate */ 17080Sstevel@tonic-gate if (icmp->icmp_proto == IPPROTO_ICMPV6) 17090Sstevel@tonic-gate return (-1); 17100Sstevel@tonic-gate 17110Sstevel@tonic-gate if (icmp->icmp_raw_checksum) { 17120Sstevel@tonic-gate *i1 = icmp->icmp_checksum_off; 17130Sstevel@tonic-gate } else { 17140Sstevel@tonic-gate *i1 = -1; 17150Sstevel@tonic-gate } 17160Sstevel@tonic-gate break; 17170Sstevel@tonic-gate case IPV6_JOIN_GROUP: 17180Sstevel@tonic-gate case IPV6_LEAVE_GROUP: 17190Sstevel@tonic-gate case MCAST_JOIN_GROUP: 17200Sstevel@tonic-gate case MCAST_LEAVE_GROUP: 17210Sstevel@tonic-gate case MCAST_BLOCK_SOURCE: 17220Sstevel@tonic-gate case MCAST_UNBLOCK_SOURCE: 17230Sstevel@tonic-gate case MCAST_JOIN_SOURCE_GROUP: 17240Sstevel@tonic-gate case MCAST_LEAVE_SOURCE_GROUP: 17250Sstevel@tonic-gate /* cannot "get" the value for these */ 17260Sstevel@tonic-gate return (-1); 17270Sstevel@tonic-gate case IPV6_RECVPKTINFO: 1728*3318Srshoaib *i1 = icmp->icmp_ip_recvpktinfo; 17290Sstevel@tonic-gate break; 17300Sstevel@tonic-gate case IPV6_RECVTCLASS: 17310Sstevel@tonic-gate *i1 = icmp->icmp_ipv6_recvtclass; 17320Sstevel@tonic-gate break; 17330Sstevel@tonic-gate case IPV6_RECVPATHMTU: 17340Sstevel@tonic-gate *i1 = icmp->icmp_ipv6_recvpathmtu; 17350Sstevel@tonic-gate break; 17360Sstevel@tonic-gate case IPV6_V6ONLY: 17370Sstevel@tonic-gate *i1 = 1; 17380Sstevel@tonic-gate break; 17390Sstevel@tonic-gate case IPV6_RECVHOPLIMIT: 17400Sstevel@tonic-gate *i1 = icmp->icmp_ipv6_recvhoplimit; 17410Sstevel@tonic-gate break; 17420Sstevel@tonic-gate case IPV6_RECVHOPOPTS: 17430Sstevel@tonic-gate *i1 = icmp->icmp_ipv6_recvhopopts; 17440Sstevel@tonic-gate break; 17450Sstevel@tonic-gate case IPV6_RECVDSTOPTS: 17460Sstevel@tonic-gate *i1 = icmp->icmp_ipv6_recvdstopts; 17470Sstevel@tonic-gate break; 17480Sstevel@tonic-gate case _OLD_IPV6_RECVDSTOPTS: 17490Sstevel@tonic-gate *i1 = icmp->icmp_old_ipv6_recvdstopts; 17500Sstevel@tonic-gate break; 17510Sstevel@tonic-gate case IPV6_RECVRTHDRDSTOPTS: 17520Sstevel@tonic-gate *i1 = icmp->icmp_ipv6_recvrtdstopts; 17530Sstevel@tonic-gate break; 17540Sstevel@tonic-gate case IPV6_RECVRTHDR: 17550Sstevel@tonic-gate *i1 = icmp->icmp_ipv6_recvrthdr; 17560Sstevel@tonic-gate break; 17570Sstevel@tonic-gate case IPV6_PKTINFO: { 17580Sstevel@tonic-gate /* XXX assumes that caller has room for max size! */ 17590Sstevel@tonic-gate struct in6_pktinfo *pkti; 17600Sstevel@tonic-gate 17610Sstevel@tonic-gate pkti = (struct in6_pktinfo *)ptr; 17620Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_IFINDEX) 17630Sstevel@tonic-gate pkti->ipi6_ifindex = ipp->ipp_ifindex; 17640Sstevel@tonic-gate else 17650Sstevel@tonic-gate pkti->ipi6_ifindex = 0; 17660Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_ADDR) 17670Sstevel@tonic-gate pkti->ipi6_addr = ipp->ipp_addr; 17680Sstevel@tonic-gate else 17690Sstevel@tonic-gate pkti->ipi6_addr = ipv6_all_zeros; 17700Sstevel@tonic-gate return (sizeof (struct in6_pktinfo)); 17710Sstevel@tonic-gate } 17720Sstevel@tonic-gate case IPV6_NEXTHOP: { 17730Sstevel@tonic-gate sin6_t *sin6 = (sin6_t *)ptr; 17740Sstevel@tonic-gate 17750Sstevel@tonic-gate if (!(ipp->ipp_fields & IPPF_NEXTHOP)) 17760Sstevel@tonic-gate return (0); 17770Sstevel@tonic-gate *sin6 = sin6_null; 17780Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 17790Sstevel@tonic-gate sin6->sin6_addr = ipp->ipp_nexthop; 17800Sstevel@tonic-gate return (sizeof (sin6_t)); 17810Sstevel@tonic-gate } 17820Sstevel@tonic-gate case IPV6_HOPOPTS: 17830Sstevel@tonic-gate if (!(ipp->ipp_fields & IPPF_HOPOPTS)) 17840Sstevel@tonic-gate return (0); 17851676Sjpk if (ipp->ipp_hopoptslen <= icmp->icmp_label_len_v6) 17861676Sjpk return (0); 17871676Sjpk bcopy((char *)ipp->ipp_hopopts + 17881676Sjpk icmp->icmp_label_len_v6, ptr, 17891676Sjpk ipp->ipp_hopoptslen - icmp->icmp_label_len_v6); 17901676Sjpk if (icmp->icmp_label_len_v6 > 0) { 17911676Sjpk ptr[0] = ((char *)ipp->ipp_hopopts)[0]; 17921676Sjpk ptr[1] = (ipp->ipp_hopoptslen - 17931676Sjpk icmp->icmp_label_len_v6 + 7) / 8 - 1; 17941676Sjpk } 17951676Sjpk return (ipp->ipp_hopoptslen - icmp->icmp_label_len_v6); 17960Sstevel@tonic-gate case IPV6_RTHDRDSTOPTS: 17970Sstevel@tonic-gate if (!(ipp->ipp_fields & IPPF_RTDSTOPTS)) 17980Sstevel@tonic-gate return (0); 17990Sstevel@tonic-gate bcopy(ipp->ipp_rtdstopts, ptr, ipp->ipp_rtdstoptslen); 18000Sstevel@tonic-gate return (ipp->ipp_rtdstoptslen); 18010Sstevel@tonic-gate case IPV6_RTHDR: 18020Sstevel@tonic-gate if (!(ipp->ipp_fields & IPPF_RTHDR)) 18030Sstevel@tonic-gate return (0); 18040Sstevel@tonic-gate bcopy(ipp->ipp_rthdr, ptr, ipp->ipp_rthdrlen); 18050Sstevel@tonic-gate return (ipp->ipp_rthdrlen); 18060Sstevel@tonic-gate case IPV6_DSTOPTS: 18070Sstevel@tonic-gate if (!(ipp->ipp_fields & IPPF_DSTOPTS)) 18080Sstevel@tonic-gate return (0); 18090Sstevel@tonic-gate bcopy(ipp->ipp_dstopts, ptr, ipp->ipp_dstoptslen); 18100Sstevel@tonic-gate return (ipp->ipp_dstoptslen); 18110Sstevel@tonic-gate case IPV6_PATHMTU: 18120Sstevel@tonic-gate if (!(ipp->ipp_fields & IPPF_PATHMTU)) 18130Sstevel@tonic-gate return (0); 18140Sstevel@tonic-gate 18150Sstevel@tonic-gate return (ip_fill_mtuinfo(&icmp->icmp_v6dst, 0, 18160Sstevel@tonic-gate (struct ip6_mtuinfo *)ptr)); 18170Sstevel@tonic-gate case IPV6_TCLASS: 18180Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_TCLASS) 18190Sstevel@tonic-gate *i1 = ipp->ipp_tclass; 18200Sstevel@tonic-gate else 18210Sstevel@tonic-gate *i1 = IPV6_FLOW_TCLASS( 18220Sstevel@tonic-gate IPV6_DEFAULT_VERS_AND_FLOW); 18230Sstevel@tonic-gate break; 18240Sstevel@tonic-gate default: 18250Sstevel@tonic-gate return (-1); 18260Sstevel@tonic-gate } 18270Sstevel@tonic-gate break; 18280Sstevel@tonic-gate case IPPROTO_ICMPV6: 18290Sstevel@tonic-gate /* 18300Sstevel@tonic-gate * Only allow IPv6 option processing on native IPv6 sockets. 18310Sstevel@tonic-gate */ 18320Sstevel@tonic-gate if (icmp->icmp_family != AF_INET6) 18330Sstevel@tonic-gate return (-1); 18340Sstevel@tonic-gate 18350Sstevel@tonic-gate if (icmp->icmp_proto != IPPROTO_ICMPV6) 18360Sstevel@tonic-gate return (-1); 18370Sstevel@tonic-gate 18380Sstevel@tonic-gate switch (name) { 18390Sstevel@tonic-gate case ICMP6_FILTER: 18400Sstevel@tonic-gate if (icmp->icmp_filter == NULL) { 18410Sstevel@tonic-gate /* Make it look like "pass all" */ 18420Sstevel@tonic-gate ICMP6_FILTER_SETPASSALL((icmp6_filter_t *)ptr); 18430Sstevel@tonic-gate } else { 18440Sstevel@tonic-gate (void) bcopy(icmp->icmp_filter, ptr, 18450Sstevel@tonic-gate sizeof (icmp6_filter_t)); 18460Sstevel@tonic-gate } 18470Sstevel@tonic-gate return (sizeof (icmp6_filter_t)); 18480Sstevel@tonic-gate default: 18490Sstevel@tonic-gate return (-1); 18500Sstevel@tonic-gate } 18510Sstevel@tonic-gate default: 18520Sstevel@tonic-gate return (-1); 18530Sstevel@tonic-gate } 18540Sstevel@tonic-gate return (sizeof (int)); 18550Sstevel@tonic-gate } 18560Sstevel@tonic-gate 18570Sstevel@tonic-gate /* This routine sets socket options. */ 18580Sstevel@tonic-gate /* ARGSUSED */ 18590Sstevel@tonic-gate int 18600Sstevel@tonic-gate icmp_opt_set(queue_t *q, uint_t optset_context, int level, int name, 18610Sstevel@tonic-gate uint_t inlen, uchar_t *invalp, uint_t *outlenp, uchar_t *outvalp, 18620Sstevel@tonic-gate void *thisdg_attrs, cred_t *cr, mblk_t *mblk) 18630Sstevel@tonic-gate { 18640Sstevel@tonic-gate icmp_t *icmp = (icmp_t *)q->q_ptr; 18650Sstevel@tonic-gate int *i1 = (int *)invalp; 18660Sstevel@tonic-gate boolean_t onoff = (*i1 == 0) ? 0 : 1; 18670Sstevel@tonic-gate boolean_t checkonly; 18680Sstevel@tonic-gate int error; 18690Sstevel@tonic-gate 18700Sstevel@tonic-gate switch (optset_context) { 18710Sstevel@tonic-gate case SETFN_OPTCOM_CHECKONLY: 18720Sstevel@tonic-gate checkonly = B_TRUE; 18730Sstevel@tonic-gate /* 18740Sstevel@tonic-gate * Note: Implies T_CHECK semantics for T_OPTCOM_REQ 18750Sstevel@tonic-gate * inlen != 0 implies value supplied and 18760Sstevel@tonic-gate * we have to "pretend" to set it. 18770Sstevel@tonic-gate * inlen == 0 implies that there is no 18780Sstevel@tonic-gate * value part in T_CHECK request and just validation 18790Sstevel@tonic-gate * done elsewhere should be enough, we just return here. 18800Sstevel@tonic-gate */ 18810Sstevel@tonic-gate if (inlen == 0) { 18820Sstevel@tonic-gate *outlenp = 0; 18830Sstevel@tonic-gate return (0); 18840Sstevel@tonic-gate } 18850Sstevel@tonic-gate break; 18860Sstevel@tonic-gate case SETFN_OPTCOM_NEGOTIATE: 18870Sstevel@tonic-gate checkonly = B_FALSE; 18880Sstevel@tonic-gate break; 18890Sstevel@tonic-gate case SETFN_UD_NEGOTIATE: 18900Sstevel@tonic-gate case SETFN_CONN_NEGOTIATE: 18910Sstevel@tonic-gate checkonly = B_FALSE; 18920Sstevel@tonic-gate /* 18930Sstevel@tonic-gate * Negotiating local and "association-related" options 18940Sstevel@tonic-gate * through T_UNITDATA_REQ. 18950Sstevel@tonic-gate * 18960Sstevel@tonic-gate * Following routine can filter out ones we do not 18970Sstevel@tonic-gate * want to be "set" this way. 18980Sstevel@tonic-gate */ 18990Sstevel@tonic-gate if (!icmp_opt_allow_udr_set(level, name)) { 19000Sstevel@tonic-gate *outlenp = 0; 19010Sstevel@tonic-gate return (EINVAL); 19020Sstevel@tonic-gate } 19030Sstevel@tonic-gate break; 19040Sstevel@tonic-gate default: 19050Sstevel@tonic-gate /* 19060Sstevel@tonic-gate * We should never get here 19070Sstevel@tonic-gate */ 19080Sstevel@tonic-gate *outlenp = 0; 19090Sstevel@tonic-gate return (EINVAL); 19100Sstevel@tonic-gate } 19110Sstevel@tonic-gate 19120Sstevel@tonic-gate ASSERT((optset_context != SETFN_OPTCOM_CHECKONLY) || 19130Sstevel@tonic-gate (optset_context == SETFN_OPTCOM_CHECKONLY && inlen != 0)); 19140Sstevel@tonic-gate 19150Sstevel@tonic-gate /* 19160Sstevel@tonic-gate * For fixed length options, no sanity check 19170Sstevel@tonic-gate * of passed in length is done. It is assumed *_optcom_req() 19180Sstevel@tonic-gate * routines do the right thing. 19190Sstevel@tonic-gate */ 19200Sstevel@tonic-gate 19210Sstevel@tonic-gate switch (level) { 19220Sstevel@tonic-gate case SOL_SOCKET: 19230Sstevel@tonic-gate switch (name) { 19240Sstevel@tonic-gate case SO_DEBUG: 19250Sstevel@tonic-gate if (!checkonly) 19260Sstevel@tonic-gate icmp->icmp_debug = onoff; 19270Sstevel@tonic-gate break; 19280Sstevel@tonic-gate case SO_PROTOTYPE: 19290Sstevel@tonic-gate if ((*i1 & 0xFF) != IPPROTO_ICMP && 19300Sstevel@tonic-gate (*i1 & 0xFF) != IPPROTO_ICMPV6 && 19310Sstevel@tonic-gate secpolicy_net_rawaccess(cr) != 0) { 19320Sstevel@tonic-gate *outlenp = 0; 19330Sstevel@tonic-gate return (EACCES); 19340Sstevel@tonic-gate } 19350Sstevel@tonic-gate /* Can't use IPPROTO_RAW with IPv6 */ 19360Sstevel@tonic-gate if ((*i1 & 0xFF) == IPPROTO_RAW && 19370Sstevel@tonic-gate icmp->icmp_family == AF_INET6) { 19380Sstevel@tonic-gate *outlenp = 0; 19390Sstevel@tonic-gate return (EPROTONOSUPPORT); 19400Sstevel@tonic-gate } 19410Sstevel@tonic-gate if (checkonly) { 19420Sstevel@tonic-gate /* T_CHECK case */ 19430Sstevel@tonic-gate *(int *)outvalp = (*i1 & 0xFF); 19440Sstevel@tonic-gate break; 19450Sstevel@tonic-gate } 19460Sstevel@tonic-gate icmp->icmp_proto = *i1 & 0xFF; 19470Sstevel@tonic-gate if ((icmp->icmp_proto == IPPROTO_RAW || 19480Sstevel@tonic-gate icmp->icmp_proto == IPPROTO_IGMP) && 19490Sstevel@tonic-gate icmp->icmp_family == AF_INET) 19500Sstevel@tonic-gate icmp->icmp_hdrincl = 1; 19510Sstevel@tonic-gate else 19520Sstevel@tonic-gate icmp->icmp_hdrincl = 0; 19530Sstevel@tonic-gate 19540Sstevel@tonic-gate if (icmp->icmp_family == AF_INET6 && 19550Sstevel@tonic-gate icmp->icmp_proto == IPPROTO_ICMPV6) { 19560Sstevel@tonic-gate /* Set offset for icmp6_cksum */ 19570Sstevel@tonic-gate icmp->icmp_raw_checksum = 0; 19580Sstevel@tonic-gate icmp->icmp_checksum_off = 2; 19590Sstevel@tonic-gate } 19600Sstevel@tonic-gate if (icmp->icmp_proto == IPPROTO_UDP || 19610Sstevel@tonic-gate icmp->icmp_proto == IPPROTO_TCP || 19620Sstevel@tonic-gate icmp->icmp_proto == IPPROTO_SCTP) { 19630Sstevel@tonic-gate icmp->icmp_no_tp_cksum = 1; 19640Sstevel@tonic-gate icmp->icmp_sticky_ipp.ipp_fields |= 19650Sstevel@tonic-gate IPPF_NO_CKSUM; 19660Sstevel@tonic-gate } else { 19670Sstevel@tonic-gate icmp->icmp_no_tp_cksum = 0; 19680Sstevel@tonic-gate icmp->icmp_sticky_ipp.ipp_fields &= 19690Sstevel@tonic-gate ~IPPF_NO_CKSUM; 19700Sstevel@tonic-gate } 19710Sstevel@tonic-gate 19720Sstevel@tonic-gate if (icmp->icmp_filter != NULL && 19730Sstevel@tonic-gate icmp->icmp_proto != IPPROTO_ICMPV6) { 19740Sstevel@tonic-gate kmem_free(icmp->icmp_filter, 19750Sstevel@tonic-gate sizeof (icmp6_filter_t)); 19760Sstevel@tonic-gate icmp->icmp_filter = NULL; 19770Sstevel@tonic-gate } 19780Sstevel@tonic-gate 19790Sstevel@tonic-gate /* Rebuild the header template */ 19800Sstevel@tonic-gate error = icmp_build_hdrs(q, icmp); 19810Sstevel@tonic-gate if (error != 0) { 19820Sstevel@tonic-gate *outlenp = 0; 19830Sstevel@tonic-gate return (error); 19840Sstevel@tonic-gate } 19850Sstevel@tonic-gate 1986409Skcpoon /* 1987409Skcpoon * For SCTP, we don't use icmp_bind_proto() for 1988409Skcpoon * raw socket binding. Note that we do not need 1989409Skcpoon * to set *outlenp. 1990409Skcpoon */ 1991409Skcpoon if (icmp->icmp_proto == IPPROTO_SCTP) 1992409Skcpoon return (0); 1993409Skcpoon 19940Sstevel@tonic-gate icmp_bind_proto(q); 19950Sstevel@tonic-gate *outlenp = sizeof (int); 19960Sstevel@tonic-gate *(int *)outvalp = *i1 & 0xFF; 19970Sstevel@tonic-gate return (0); 19980Sstevel@tonic-gate case SO_REUSEADDR: 19990Sstevel@tonic-gate if (!checkonly) 20000Sstevel@tonic-gate icmp->icmp_reuseaddr = onoff; 20010Sstevel@tonic-gate break; 20020Sstevel@tonic-gate 20030Sstevel@tonic-gate /* 20040Sstevel@tonic-gate * The following three items are available here, 20050Sstevel@tonic-gate * but are only meaningful to IP. 20060Sstevel@tonic-gate */ 20070Sstevel@tonic-gate case SO_DONTROUTE: 20080Sstevel@tonic-gate if (!checkonly) 20090Sstevel@tonic-gate icmp->icmp_dontroute = onoff; 20100Sstevel@tonic-gate break; 20110Sstevel@tonic-gate case SO_USELOOPBACK: 20120Sstevel@tonic-gate if (!checkonly) 20130Sstevel@tonic-gate icmp->icmp_useloopback = onoff; 20140Sstevel@tonic-gate break; 20150Sstevel@tonic-gate case SO_BROADCAST: 20160Sstevel@tonic-gate if (!checkonly) 20170Sstevel@tonic-gate icmp->icmp_broadcast = onoff; 20180Sstevel@tonic-gate break; 20190Sstevel@tonic-gate 20200Sstevel@tonic-gate case SO_SNDBUF: 20210Sstevel@tonic-gate if (*i1 > icmp_max_buf) { 20220Sstevel@tonic-gate *outlenp = 0; 20230Sstevel@tonic-gate return (ENOBUFS); 20240Sstevel@tonic-gate } 20250Sstevel@tonic-gate if (!checkonly) { 20260Sstevel@tonic-gate q->q_hiwat = *i1; 20270Sstevel@tonic-gate q->q_next->q_hiwat = *i1; 20280Sstevel@tonic-gate } 20290Sstevel@tonic-gate break; 20300Sstevel@tonic-gate case SO_RCVBUF: 20310Sstevel@tonic-gate if (*i1 > icmp_max_buf) { 20320Sstevel@tonic-gate *outlenp = 0; 20330Sstevel@tonic-gate return (ENOBUFS); 20340Sstevel@tonic-gate } 20350Sstevel@tonic-gate if (!checkonly) { 20360Sstevel@tonic-gate RD(q)->q_hiwat = *i1; 20370Sstevel@tonic-gate (void) mi_set_sth_hiwat(RD(q), *i1); 20380Sstevel@tonic-gate } 20390Sstevel@tonic-gate break; 20400Sstevel@tonic-gate case SO_DGRAM_ERRIND: 20410Sstevel@tonic-gate if (!checkonly) 20420Sstevel@tonic-gate icmp->icmp_dgram_errind = onoff; 20430Sstevel@tonic-gate break; 20442263Ssommerfe case SO_ALLZONES: 20452263Ssommerfe /* 20462263Ssommerfe * "soft" error (negative) 20472263Ssommerfe * option not handled at this level 20482263Ssommerfe * Note: Do not modify *outlenp 20492263Ssommerfe */ 20502263Ssommerfe return (-EINVAL); 20511673Sgt145670 case SO_TIMESTAMP: 20521673Sgt145670 if (!checkonly) { 20531673Sgt145670 icmp->icmp_timestamp = onoff; 20541673Sgt145670 } 20551673Sgt145670 break; 20561676Sjpk case SO_MAC_EXEMPT: 20571676Sjpk if (secpolicy_net_mac_aware(cr) != 0 || 20581676Sjpk icmp->icmp_state != TS_UNBND) 20591676Sjpk return (EACCES); 20601676Sjpk if (!checkonly) 20611676Sjpk icmp->icmp_mac_exempt = onoff; 20621676Sjpk break; 20630Sstevel@tonic-gate /* 20640Sstevel@tonic-gate * Following three not meaningful for icmp 20650Sstevel@tonic-gate * Action is same as "default" so we keep them 20660Sstevel@tonic-gate * in comments. 20670Sstevel@tonic-gate * case SO_LINGER: 20680Sstevel@tonic-gate * case SO_KEEPALIVE: 20690Sstevel@tonic-gate * case SO_OOBINLINE: 20700Sstevel@tonic-gate */ 20710Sstevel@tonic-gate default: 20720Sstevel@tonic-gate *outlenp = 0; 20730Sstevel@tonic-gate return (EINVAL); 20740Sstevel@tonic-gate } 20750Sstevel@tonic-gate break; 20760Sstevel@tonic-gate case IPPROTO_IP: 20770Sstevel@tonic-gate /* 20780Sstevel@tonic-gate * Only allow IPv4 option processing on IPv4 sockets. 20790Sstevel@tonic-gate */ 20800Sstevel@tonic-gate if (icmp->icmp_family != AF_INET) { 20810Sstevel@tonic-gate *outlenp = 0; 20820Sstevel@tonic-gate return (ENOPROTOOPT); 20830Sstevel@tonic-gate } 20840Sstevel@tonic-gate switch (name) { 20850Sstevel@tonic-gate case IP_OPTIONS: 20860Sstevel@tonic-gate case T_IP_OPTIONS: 20870Sstevel@tonic-gate /* Save options for use by IP. */ 20881676Sjpk if ((inlen & 0x3) || 20891676Sjpk inlen + icmp->icmp_label_len > IP_MAX_OPT_LENGTH) { 20900Sstevel@tonic-gate *outlenp = 0; 20910Sstevel@tonic-gate return (EINVAL); 20920Sstevel@tonic-gate } 20930Sstevel@tonic-gate if (checkonly) 20940Sstevel@tonic-gate break; 20950Sstevel@tonic-gate 20961676Sjpk if (!tsol_option_set(&icmp->icmp_ip_snd_options, 20971676Sjpk &icmp->icmp_ip_snd_options_len, 20981676Sjpk icmp->icmp_label_len, invalp, inlen)) { 20991676Sjpk *outlenp = 0; 21001676Sjpk return (ENOMEM); 21010Sstevel@tonic-gate } 21021676Sjpk 21030Sstevel@tonic-gate icmp->icmp_max_hdr_len = IP_SIMPLE_HDR_LENGTH + 21040Sstevel@tonic-gate icmp->icmp_ip_snd_options_len; 21050Sstevel@tonic-gate (void) mi_set_sth_wroff(RD(q), icmp->icmp_max_hdr_len + 21060Sstevel@tonic-gate icmp_wroff_extra); 21070Sstevel@tonic-gate break; 21080Sstevel@tonic-gate case IP_HDRINCL: 21090Sstevel@tonic-gate if (!checkonly) 21100Sstevel@tonic-gate icmp->icmp_hdrincl = onoff; 21110Sstevel@tonic-gate break; 21120Sstevel@tonic-gate case IP_TOS: 21130Sstevel@tonic-gate case T_IP_TOS: 21140Sstevel@tonic-gate if (!checkonly) { 21150Sstevel@tonic-gate icmp->icmp_type_of_service = (uint8_t)*i1; 21160Sstevel@tonic-gate } 21170Sstevel@tonic-gate break; 21180Sstevel@tonic-gate case IP_TTL: 21190Sstevel@tonic-gate if (!checkonly) { 21200Sstevel@tonic-gate icmp->icmp_ttl = (uint8_t)*i1; 21210Sstevel@tonic-gate } 21220Sstevel@tonic-gate break; 21230Sstevel@tonic-gate case IP_MULTICAST_IF: 21240Sstevel@tonic-gate /* 21250Sstevel@tonic-gate * TODO should check OPTMGMT reply and undo this if 21260Sstevel@tonic-gate * there is an error. 21270Sstevel@tonic-gate */ 21280Sstevel@tonic-gate if (!checkonly) 21290Sstevel@tonic-gate icmp->icmp_multicast_if_addr = *i1; 21300Sstevel@tonic-gate break; 21310Sstevel@tonic-gate case IP_MULTICAST_TTL: 21320Sstevel@tonic-gate if (!checkonly) 21330Sstevel@tonic-gate icmp->icmp_multicast_ttl = *invalp; 21340Sstevel@tonic-gate break; 21350Sstevel@tonic-gate case IP_MULTICAST_LOOP: 21360Sstevel@tonic-gate if (!checkonly) { 21370Sstevel@tonic-gate icmp->icmp_multicast_loop = 21380Sstevel@tonic-gate (*invalp == 0) ? 0 : 1; 21390Sstevel@tonic-gate } 21400Sstevel@tonic-gate break; 21410Sstevel@tonic-gate case IP_BOUND_IF: 21420Sstevel@tonic-gate if (!checkonly) 21430Sstevel@tonic-gate icmp->icmp_bound_if = *i1; 21440Sstevel@tonic-gate break; 21450Sstevel@tonic-gate case IP_UNSPEC_SRC: 21460Sstevel@tonic-gate if (!checkonly) 21470Sstevel@tonic-gate icmp->icmp_unspec_source = onoff; 21480Sstevel@tonic-gate break; 21490Sstevel@tonic-gate case IP_XMIT_IF: 21500Sstevel@tonic-gate if (!checkonly) 21510Sstevel@tonic-gate icmp->icmp_xmit_if = *i1; 21520Sstevel@tonic-gate break; 21530Sstevel@tonic-gate case IP_RECVIF: 21540Sstevel@tonic-gate if (!checkonly) 21550Sstevel@tonic-gate icmp->icmp_recvif = onoff; 21560Sstevel@tonic-gate break; 2157*3318Srshoaib 2158*3318Srshoaib case IP_PKTINFO: { 2159*3318Srshoaib /* 2160*3318Srshoaib * This also handles IP_RECVPKTINFO. 2161*3318Srshoaib * IP_PKTINFO and IP_RECVPKTINFO have the same value. 2162*3318Srshoaib * Differentiation is based on the size of the argument 2163*3318Srshoaib * passed in. 2164*3318Srshoaib */ 2165*3318Srshoaib struct in_pktinfo *pktinfop; 2166*3318Srshoaib ip4_pkt_t *attr_pktinfop; 2167*3318Srshoaib 2168*3318Srshoaib if (checkonly) 2169*3318Srshoaib break; 2170*3318Srshoaib 2171*3318Srshoaib if (inlen == sizeof (int)) { 2172*3318Srshoaib /* 2173*3318Srshoaib * This is IP_RECVPKTINFO option. 2174*3318Srshoaib * Keep a local copy of wether this option is 2175*3318Srshoaib * set or not and pass it down to IP for 2176*3318Srshoaib * processing. 2177*3318Srshoaib */ 2178*3318Srshoaib icmp->icmp_ip_recvpktinfo = onoff; 2179*3318Srshoaib return (-EINVAL); 2180*3318Srshoaib } 2181*3318Srshoaib 2182*3318Srshoaib 2183*3318Srshoaib if (inlen != sizeof (struct in_pktinfo)) 2184*3318Srshoaib return (EINVAL); 2185*3318Srshoaib 2186*3318Srshoaib if ((attr_pktinfop = (ip4_pkt_t *)thisdg_attrs) 2187*3318Srshoaib == NULL) { 2188*3318Srshoaib /* 2189*3318Srshoaib * sticky option is not supported 2190*3318Srshoaib */ 2191*3318Srshoaib return (EINVAL); 2192*3318Srshoaib } 2193*3318Srshoaib 2194*3318Srshoaib pktinfop = (struct in_pktinfo *)invalp; 2195*3318Srshoaib 2196*3318Srshoaib /* 2197*3318Srshoaib * Atleast one of the values should be specified 2198*3318Srshoaib */ 2199*3318Srshoaib if (pktinfop->ipi_ifindex == 0 && 2200*3318Srshoaib pktinfop->ipi_spec_dst.s_addr == INADDR_ANY) { 2201*3318Srshoaib return (EINVAL); 2202*3318Srshoaib } 2203*3318Srshoaib 2204*3318Srshoaib attr_pktinfop->ip4_addr = pktinfop->ipi_spec_dst.s_addr; 2205*3318Srshoaib attr_pktinfop->ip4_ill_index = pktinfop->ipi_ifindex; 2206*3318Srshoaib } 2207*3318Srshoaib break; 22080Sstevel@tonic-gate case IP_ADD_MEMBERSHIP: 22090Sstevel@tonic-gate case IP_DROP_MEMBERSHIP: 22100Sstevel@tonic-gate case IP_BLOCK_SOURCE: 22110Sstevel@tonic-gate case IP_UNBLOCK_SOURCE: 22120Sstevel@tonic-gate case IP_ADD_SOURCE_MEMBERSHIP: 22130Sstevel@tonic-gate case IP_DROP_SOURCE_MEMBERSHIP: 22140Sstevel@tonic-gate case MCAST_JOIN_GROUP: 22150Sstevel@tonic-gate case MCAST_LEAVE_GROUP: 22160Sstevel@tonic-gate case MCAST_BLOCK_SOURCE: 22170Sstevel@tonic-gate case MCAST_UNBLOCK_SOURCE: 22180Sstevel@tonic-gate case MCAST_JOIN_SOURCE_GROUP: 22190Sstevel@tonic-gate case MCAST_LEAVE_SOURCE_GROUP: 22200Sstevel@tonic-gate case MRT_INIT: 22210Sstevel@tonic-gate case MRT_DONE: 22220Sstevel@tonic-gate case MRT_ADD_VIF: 22230Sstevel@tonic-gate case MRT_DEL_VIF: 22240Sstevel@tonic-gate case MRT_ADD_MFC: 22250Sstevel@tonic-gate case MRT_DEL_MFC: 22260Sstevel@tonic-gate case MRT_VERSION: 22270Sstevel@tonic-gate case MRT_ASSERT: 22280Sstevel@tonic-gate case IP_SEC_OPT: 22290Sstevel@tonic-gate case IP_DONTFAILOVER_IF: 22301663Spriyanka case IP_NEXTHOP: 22310Sstevel@tonic-gate /* 22320Sstevel@tonic-gate * "soft" error (negative) 22330Sstevel@tonic-gate * option not handled at this level 22340Sstevel@tonic-gate * Note: Do not modify *outlenp 22350Sstevel@tonic-gate */ 22360Sstevel@tonic-gate return (-EINVAL); 22370Sstevel@tonic-gate default: 22380Sstevel@tonic-gate *outlenp = 0; 22390Sstevel@tonic-gate return (EINVAL); 22400Sstevel@tonic-gate } 22410Sstevel@tonic-gate break; 22420Sstevel@tonic-gate case IPPROTO_IPV6: { 22430Sstevel@tonic-gate ip6_pkt_t *ipp; 22440Sstevel@tonic-gate boolean_t sticky; 22450Sstevel@tonic-gate 22460Sstevel@tonic-gate if (icmp->icmp_family != AF_INET6) { 22470Sstevel@tonic-gate *outlenp = 0; 22480Sstevel@tonic-gate return (ENOPROTOOPT); 22490Sstevel@tonic-gate } 22500Sstevel@tonic-gate /* 22510Sstevel@tonic-gate * Deal with both sticky options and ancillary data 22520Sstevel@tonic-gate */ 22530Sstevel@tonic-gate if (thisdg_attrs == NULL) { 22540Sstevel@tonic-gate /* sticky options, or none */ 22550Sstevel@tonic-gate ipp = &icmp->icmp_sticky_ipp; 22560Sstevel@tonic-gate sticky = B_TRUE; 22570Sstevel@tonic-gate } else { 22580Sstevel@tonic-gate /* ancillary data */ 22590Sstevel@tonic-gate ipp = (ip6_pkt_t *)thisdg_attrs; 22600Sstevel@tonic-gate sticky = B_FALSE; 22610Sstevel@tonic-gate } 22620Sstevel@tonic-gate 22630Sstevel@tonic-gate switch (name) { 22640Sstevel@tonic-gate case IPV6_MULTICAST_IF: 22650Sstevel@tonic-gate if (!checkonly) 22660Sstevel@tonic-gate icmp->icmp_multicast_if_index = *i1; 22670Sstevel@tonic-gate break; 22680Sstevel@tonic-gate case IPV6_UNICAST_HOPS: 22690Sstevel@tonic-gate /* -1 means use default */ 22700Sstevel@tonic-gate if (*i1 < -1 || *i1 > IPV6_MAX_HOPS) { 22710Sstevel@tonic-gate *outlenp = 0; 22720Sstevel@tonic-gate return (EINVAL); 22730Sstevel@tonic-gate } 22740Sstevel@tonic-gate if (!checkonly) { 22750Sstevel@tonic-gate if (*i1 == -1) { 2276679Sseb icmp->icmp_ttl = ipp->ipp_unicast_hops = 22770Sstevel@tonic-gate icmp_ipv6_hoplimit; 2278679Sseb ipp->ipp_fields &= ~IPPF_UNICAST_HOPS; 22790Sstevel@tonic-gate /* Pass modified value to IP. */ 22800Sstevel@tonic-gate *i1 = ipp->ipp_hoplimit; 22810Sstevel@tonic-gate } else { 2282679Sseb icmp->icmp_ttl = ipp->ipp_unicast_hops = 22830Sstevel@tonic-gate (uint8_t)*i1; 2284679Sseb ipp->ipp_fields |= IPPF_UNICAST_HOPS; 22850Sstevel@tonic-gate } 22860Sstevel@tonic-gate /* Rebuild the header template */ 22870Sstevel@tonic-gate error = icmp_build_hdrs(q, icmp); 22880Sstevel@tonic-gate if (error != 0) { 22890Sstevel@tonic-gate *outlenp = 0; 22900Sstevel@tonic-gate return (error); 22910Sstevel@tonic-gate } 22920Sstevel@tonic-gate } 22930Sstevel@tonic-gate break; 22940Sstevel@tonic-gate case IPV6_MULTICAST_HOPS: 22950Sstevel@tonic-gate /* -1 means use default */ 22960Sstevel@tonic-gate if (*i1 < -1 || *i1 > IPV6_MAX_HOPS) { 22970Sstevel@tonic-gate *outlenp = 0; 22980Sstevel@tonic-gate return (EINVAL); 22990Sstevel@tonic-gate } 23000Sstevel@tonic-gate if (!checkonly) { 23010Sstevel@tonic-gate if (*i1 == -1) { 23020Sstevel@tonic-gate icmp->icmp_multicast_ttl = 2303679Sseb ipp->ipp_multicast_hops = 23040Sstevel@tonic-gate IP_DEFAULT_MULTICAST_TTL; 2305679Sseb ipp->ipp_fields &= ~IPPF_MULTICAST_HOPS; 23060Sstevel@tonic-gate /* Pass modified value to IP. */ 2307679Sseb *i1 = icmp->icmp_multicast_ttl; 23080Sstevel@tonic-gate } else { 23090Sstevel@tonic-gate icmp->icmp_multicast_ttl = 2310679Sseb ipp->ipp_multicast_hops = 23110Sstevel@tonic-gate (uint8_t)*i1; 2312679Sseb ipp->ipp_fields |= IPPF_MULTICAST_HOPS; 23130Sstevel@tonic-gate } 23140Sstevel@tonic-gate } 23150Sstevel@tonic-gate break; 23160Sstevel@tonic-gate case IPV6_MULTICAST_LOOP: 23170Sstevel@tonic-gate if (*i1 != 0 && *i1 != 1) { 23180Sstevel@tonic-gate *outlenp = 0; 23190Sstevel@tonic-gate return (EINVAL); 23200Sstevel@tonic-gate } 23210Sstevel@tonic-gate if (!checkonly) 23220Sstevel@tonic-gate icmp->icmp_multicast_loop = *i1; 23230Sstevel@tonic-gate break; 23240Sstevel@tonic-gate case IPV6_CHECKSUM: 23250Sstevel@tonic-gate /* 23260Sstevel@tonic-gate * Integer offset into the user data of where the 23270Sstevel@tonic-gate * checksum is located. 23280Sstevel@tonic-gate * Offset of -1 disables option. 23290Sstevel@tonic-gate * Does not apply to IPPROTO_ICMPV6. 23300Sstevel@tonic-gate */ 23310Sstevel@tonic-gate if (icmp->icmp_proto == IPPROTO_ICMPV6 || !sticky) { 23320Sstevel@tonic-gate *outlenp = 0; 23330Sstevel@tonic-gate return (EINVAL); 23340Sstevel@tonic-gate } 23350Sstevel@tonic-gate if ((*i1 != -1) && ((*i1 < 0) || (*i1 & 0x1) != 0)) { 23360Sstevel@tonic-gate /* Negative or not 16 bit aligned offset */ 23370Sstevel@tonic-gate *outlenp = 0; 23380Sstevel@tonic-gate return (EINVAL); 23390Sstevel@tonic-gate } 23400Sstevel@tonic-gate if (checkonly) 23410Sstevel@tonic-gate break; 23420Sstevel@tonic-gate 23430Sstevel@tonic-gate if (*i1 == -1) { 23440Sstevel@tonic-gate icmp->icmp_raw_checksum = 0; 23450Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_RAW_CKSUM; 23460Sstevel@tonic-gate } else { 23470Sstevel@tonic-gate icmp->icmp_raw_checksum = 1; 23480Sstevel@tonic-gate icmp->icmp_checksum_off = *i1; 23490Sstevel@tonic-gate ipp->ipp_fields |= IPPF_RAW_CKSUM; 23500Sstevel@tonic-gate } 23510Sstevel@tonic-gate /* Rebuild the header template */ 23520Sstevel@tonic-gate error = icmp_build_hdrs(q, icmp); 23530Sstevel@tonic-gate if (error != 0) { 23540Sstevel@tonic-gate *outlenp = 0; 23550Sstevel@tonic-gate return (error); 23560Sstevel@tonic-gate } 23570Sstevel@tonic-gate break; 23580Sstevel@tonic-gate case IPV6_JOIN_GROUP: 23590Sstevel@tonic-gate case IPV6_LEAVE_GROUP: 23600Sstevel@tonic-gate case MCAST_JOIN_GROUP: 23610Sstevel@tonic-gate case MCAST_LEAVE_GROUP: 23620Sstevel@tonic-gate case MCAST_BLOCK_SOURCE: 23630Sstevel@tonic-gate case MCAST_UNBLOCK_SOURCE: 23640Sstevel@tonic-gate case MCAST_JOIN_SOURCE_GROUP: 23650Sstevel@tonic-gate case MCAST_LEAVE_SOURCE_GROUP: 23660Sstevel@tonic-gate /* 23670Sstevel@tonic-gate * "soft" error (negative) 23680Sstevel@tonic-gate * option not handled at this level 23690Sstevel@tonic-gate * Note: Do not modify *outlenp 23700Sstevel@tonic-gate */ 23710Sstevel@tonic-gate return (-EINVAL); 23720Sstevel@tonic-gate case IPV6_BOUND_IF: 23730Sstevel@tonic-gate if (!checkonly) 23740Sstevel@tonic-gate icmp->icmp_bound_if = *i1; 23750Sstevel@tonic-gate break; 23760Sstevel@tonic-gate case IPV6_UNSPEC_SRC: 23770Sstevel@tonic-gate if (!checkonly) 23780Sstevel@tonic-gate icmp->icmp_unspec_source = onoff; 23790Sstevel@tonic-gate break; 23800Sstevel@tonic-gate case IPV6_RECVTCLASS: 23810Sstevel@tonic-gate if (!checkonly) 23820Sstevel@tonic-gate icmp->icmp_ipv6_recvtclass = onoff; 23830Sstevel@tonic-gate break; 23840Sstevel@tonic-gate /* 23850Sstevel@tonic-gate * Set boolean switches for ancillary data delivery 23860Sstevel@tonic-gate */ 23870Sstevel@tonic-gate case IPV6_RECVPKTINFO: 23880Sstevel@tonic-gate if (!checkonly) 2389*3318Srshoaib icmp->icmp_ip_recvpktinfo = onoff; 23900Sstevel@tonic-gate break; 23910Sstevel@tonic-gate case IPV6_RECVPATHMTU: 23920Sstevel@tonic-gate if (!checkonly) 23930Sstevel@tonic-gate icmp->icmp_ipv6_recvpathmtu = onoff; 23940Sstevel@tonic-gate break; 23950Sstevel@tonic-gate case IPV6_RECVHOPLIMIT: 23960Sstevel@tonic-gate if (!checkonly) 23970Sstevel@tonic-gate icmp->icmp_ipv6_recvhoplimit = onoff; 23980Sstevel@tonic-gate break; 23990Sstevel@tonic-gate case IPV6_RECVHOPOPTS: 24000Sstevel@tonic-gate if (!checkonly) 24010Sstevel@tonic-gate icmp->icmp_ipv6_recvhopopts = onoff; 24020Sstevel@tonic-gate break; 24030Sstevel@tonic-gate case IPV6_RECVDSTOPTS: 24040Sstevel@tonic-gate if (!checkonly) 24050Sstevel@tonic-gate icmp->icmp_ipv6_recvdstopts = onoff; 24060Sstevel@tonic-gate break; 24070Sstevel@tonic-gate case _OLD_IPV6_RECVDSTOPTS: 24080Sstevel@tonic-gate if (!checkonly) 24090Sstevel@tonic-gate icmp->icmp_old_ipv6_recvdstopts = onoff; 24100Sstevel@tonic-gate break; 24110Sstevel@tonic-gate case IPV6_RECVRTHDRDSTOPTS: 24120Sstevel@tonic-gate if (!checkonly) 24130Sstevel@tonic-gate icmp->icmp_ipv6_recvrtdstopts = onoff; 24140Sstevel@tonic-gate break; 24150Sstevel@tonic-gate case IPV6_RECVRTHDR: 24160Sstevel@tonic-gate if (!checkonly) 24170Sstevel@tonic-gate icmp->icmp_ipv6_recvrthdr = onoff; 24180Sstevel@tonic-gate break; 24190Sstevel@tonic-gate /* 24200Sstevel@tonic-gate * Set sticky options or ancillary data. 24210Sstevel@tonic-gate * If sticky options, (re)build any extension headers 24220Sstevel@tonic-gate * that might be needed as a result. 24230Sstevel@tonic-gate */ 24240Sstevel@tonic-gate case IPV6_PKTINFO: 24250Sstevel@tonic-gate /* 24260Sstevel@tonic-gate * The source address and ifindex are verified 24270Sstevel@tonic-gate * in ip_opt_set(). For ancillary data the 24280Sstevel@tonic-gate * source address is checked in ip_wput_v6. 24290Sstevel@tonic-gate */ 24300Sstevel@tonic-gate if (inlen != 0 && inlen != sizeof (struct in6_pktinfo)) 24310Sstevel@tonic-gate return (EINVAL); 24320Sstevel@tonic-gate if (checkonly) 24330Sstevel@tonic-gate break; 24340Sstevel@tonic-gate 24350Sstevel@tonic-gate if (inlen == 0) { 24360Sstevel@tonic-gate ipp->ipp_fields &= ~(IPPF_IFINDEX|IPPF_ADDR); 24370Sstevel@tonic-gate ipp->ipp_sticky_ignored |= 24380Sstevel@tonic-gate (IPPF_IFINDEX|IPPF_ADDR); 24390Sstevel@tonic-gate } else { 24400Sstevel@tonic-gate struct in6_pktinfo *pkti; 24410Sstevel@tonic-gate 24420Sstevel@tonic-gate pkti = (struct in6_pktinfo *)invalp; 24430Sstevel@tonic-gate ipp->ipp_ifindex = pkti->ipi6_ifindex; 24440Sstevel@tonic-gate ipp->ipp_addr = pkti->ipi6_addr; 24450Sstevel@tonic-gate if (ipp->ipp_ifindex != 0) 24460Sstevel@tonic-gate ipp->ipp_fields |= IPPF_IFINDEX; 24470Sstevel@tonic-gate else 24480Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_IFINDEX; 24490Sstevel@tonic-gate if (!IN6_IS_ADDR_UNSPECIFIED( 24500Sstevel@tonic-gate &ipp->ipp_addr)) 24510Sstevel@tonic-gate ipp->ipp_fields |= IPPF_ADDR; 24520Sstevel@tonic-gate else 24530Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_ADDR; 24540Sstevel@tonic-gate } 24550Sstevel@tonic-gate if (sticky) { 24560Sstevel@tonic-gate error = icmp_build_hdrs(q, icmp); 24570Sstevel@tonic-gate if (error != 0) 24580Sstevel@tonic-gate return (error); 24590Sstevel@tonic-gate } 24600Sstevel@tonic-gate break; 24610Sstevel@tonic-gate case IPV6_HOPLIMIT: 2462679Sseb /* This option can only be used as ancillary data. */ 2463679Sseb if (sticky) 2464679Sseb return (EINVAL); 24650Sstevel@tonic-gate if (inlen != 0 && inlen != sizeof (int)) 24660Sstevel@tonic-gate return (EINVAL); 24670Sstevel@tonic-gate if (checkonly) 24680Sstevel@tonic-gate break; 24690Sstevel@tonic-gate 24700Sstevel@tonic-gate if (inlen == 0) { 24710Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_HOPLIMIT; 24720Sstevel@tonic-gate ipp->ipp_sticky_ignored |= IPPF_HOPLIMIT; 24730Sstevel@tonic-gate } else { 24740Sstevel@tonic-gate if (*i1 > 255 || *i1 < -1) 24750Sstevel@tonic-gate return (EINVAL); 24760Sstevel@tonic-gate if (*i1 == -1) 24770Sstevel@tonic-gate ipp->ipp_hoplimit = icmp_ipv6_hoplimit; 24780Sstevel@tonic-gate else 24790Sstevel@tonic-gate ipp->ipp_hoplimit = *i1; 24800Sstevel@tonic-gate ipp->ipp_fields |= IPPF_HOPLIMIT; 24810Sstevel@tonic-gate } 24820Sstevel@tonic-gate break; 24830Sstevel@tonic-gate case IPV6_TCLASS: 24840Sstevel@tonic-gate /* 24850Sstevel@tonic-gate * IPV6_RECVTCLASS accepts -1 as use kernel default 24860Sstevel@tonic-gate * and [0, 255] as the actualy traffic class. 24870Sstevel@tonic-gate */ 24880Sstevel@tonic-gate if (inlen != 0 && inlen != sizeof (int)) 24890Sstevel@tonic-gate return (EINVAL); 24900Sstevel@tonic-gate if (checkonly) 24910Sstevel@tonic-gate break; 24920Sstevel@tonic-gate 24930Sstevel@tonic-gate if (inlen == 0) { 24940Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_TCLASS; 24950Sstevel@tonic-gate ipp->ipp_sticky_ignored |= IPPF_TCLASS; 24960Sstevel@tonic-gate } else { 24970Sstevel@tonic-gate if (*i1 >= 256 || *i1 < -1) 24980Sstevel@tonic-gate return (EINVAL); 24990Sstevel@tonic-gate if (*i1 == -1) { 25000Sstevel@tonic-gate ipp->ipp_tclass = 25010Sstevel@tonic-gate IPV6_FLOW_TCLASS( 25020Sstevel@tonic-gate IPV6_DEFAULT_VERS_AND_FLOW); 25030Sstevel@tonic-gate } else { 25040Sstevel@tonic-gate ipp->ipp_tclass = *i1; 25050Sstevel@tonic-gate } 25060Sstevel@tonic-gate ipp->ipp_fields |= IPPF_TCLASS; 25070Sstevel@tonic-gate } 25080Sstevel@tonic-gate if (sticky) { 25090Sstevel@tonic-gate error = icmp_build_hdrs(q, icmp); 25100Sstevel@tonic-gate if (error != 0) 25110Sstevel@tonic-gate return (error); 25120Sstevel@tonic-gate } 25130Sstevel@tonic-gate break; 25140Sstevel@tonic-gate case IPV6_NEXTHOP: 25150Sstevel@tonic-gate /* 25160Sstevel@tonic-gate * IP will verify that the nexthop is reachable 25170Sstevel@tonic-gate * and fail for sticky options. 25180Sstevel@tonic-gate */ 25190Sstevel@tonic-gate if (inlen != 0 && inlen != sizeof (sin6_t)) 25200Sstevel@tonic-gate return (EINVAL); 25210Sstevel@tonic-gate if (checkonly) 25220Sstevel@tonic-gate break; 25230Sstevel@tonic-gate 25240Sstevel@tonic-gate if (inlen == 0) { 25250Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_NEXTHOP; 25260Sstevel@tonic-gate ipp->ipp_sticky_ignored |= IPPF_NEXTHOP; 25270Sstevel@tonic-gate } else { 25280Sstevel@tonic-gate sin6_t *sin6 = (sin6_t *)invalp; 25290Sstevel@tonic-gate 25300Sstevel@tonic-gate if (sin6->sin6_family != AF_INET6) 25310Sstevel@tonic-gate return (EAFNOSUPPORT); 25320Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) 25330Sstevel@tonic-gate return (EADDRNOTAVAIL); 25340Sstevel@tonic-gate ipp->ipp_nexthop = sin6->sin6_addr; 25350Sstevel@tonic-gate if (!IN6_IS_ADDR_UNSPECIFIED( 25360Sstevel@tonic-gate &ipp->ipp_nexthop)) 25370Sstevel@tonic-gate ipp->ipp_fields |= IPPF_NEXTHOP; 25380Sstevel@tonic-gate else 25390Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_NEXTHOP; 25400Sstevel@tonic-gate } 25410Sstevel@tonic-gate if (sticky) { 25420Sstevel@tonic-gate error = icmp_build_hdrs(q, icmp); 25430Sstevel@tonic-gate if (error != 0) 25440Sstevel@tonic-gate return (error); 25450Sstevel@tonic-gate } 25460Sstevel@tonic-gate break; 25470Sstevel@tonic-gate case IPV6_HOPOPTS: { 25480Sstevel@tonic-gate ip6_hbh_t *hopts = (ip6_hbh_t *)invalp; 25490Sstevel@tonic-gate /* 25500Sstevel@tonic-gate * Sanity checks - minimum size, size a multiple of 25510Sstevel@tonic-gate * eight bytes, and matching size passed in. 25520Sstevel@tonic-gate */ 25530Sstevel@tonic-gate if (inlen != 0 && 25540Sstevel@tonic-gate inlen != (8 * (hopts->ip6h_len + 1))) 25550Sstevel@tonic-gate return (EINVAL); 25560Sstevel@tonic-gate 25570Sstevel@tonic-gate if (checkonly) 25580Sstevel@tonic-gate break; 25591676Sjpk error = optcom_pkt_set(invalp, inlen, sticky, 25601676Sjpk (uchar_t **)&ipp->ipp_hopopts, 25611676Sjpk &ipp->ipp_hopoptslen, 25621676Sjpk sticky ? icmp->icmp_label_len_v6 : 0); 25631676Sjpk if (error != 0) 25641676Sjpk return (error); 25651676Sjpk if (ipp->ipp_hopoptslen == 0) { 25660Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_HOPOPTS; 25670Sstevel@tonic-gate ipp->ipp_sticky_ignored |= IPPF_HOPOPTS; 25680Sstevel@tonic-gate } else { 25690Sstevel@tonic-gate ipp->ipp_fields |= IPPF_HOPOPTS; 25700Sstevel@tonic-gate } 25710Sstevel@tonic-gate if (sticky) { 25720Sstevel@tonic-gate error = icmp_build_hdrs(q, icmp); 25730Sstevel@tonic-gate if (error != 0) 25740Sstevel@tonic-gate return (error); 25750Sstevel@tonic-gate } 25760Sstevel@tonic-gate break; 25770Sstevel@tonic-gate } 25780Sstevel@tonic-gate case IPV6_RTHDRDSTOPTS: { 25790Sstevel@tonic-gate ip6_dest_t *dopts = (ip6_dest_t *)invalp; 25800Sstevel@tonic-gate 25810Sstevel@tonic-gate /* 25820Sstevel@tonic-gate * Sanity checks - minimum size, size a multiple of 25830Sstevel@tonic-gate * eight bytes, and matching size passed in. 25840Sstevel@tonic-gate */ 25850Sstevel@tonic-gate if (inlen != 0 && 25860Sstevel@tonic-gate inlen != (8 * (dopts->ip6d_len + 1))) 25870Sstevel@tonic-gate return (EINVAL); 25880Sstevel@tonic-gate 25890Sstevel@tonic-gate if (checkonly) 25900Sstevel@tonic-gate break; 25910Sstevel@tonic-gate 25920Sstevel@tonic-gate if (inlen == 0) { 25930Sstevel@tonic-gate if (sticky && 25940Sstevel@tonic-gate (ipp->ipp_fields & IPPF_RTDSTOPTS) != 0) { 25950Sstevel@tonic-gate kmem_free(ipp->ipp_rtdstopts, 25960Sstevel@tonic-gate ipp->ipp_rtdstoptslen); 25970Sstevel@tonic-gate ipp->ipp_rtdstopts = NULL; 25980Sstevel@tonic-gate ipp->ipp_rtdstoptslen = 0; 25990Sstevel@tonic-gate } 26000Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_RTDSTOPTS; 26010Sstevel@tonic-gate ipp->ipp_sticky_ignored |= IPPF_RTDSTOPTS; 26020Sstevel@tonic-gate } else { 26031676Sjpk error = optcom_pkt_set(invalp, inlen, sticky, 26040Sstevel@tonic-gate (uchar_t **)&ipp->ipp_rtdstopts, 26051676Sjpk &ipp->ipp_rtdstoptslen, 0); 26060Sstevel@tonic-gate if (error != 0) 26070Sstevel@tonic-gate return (error); 26080Sstevel@tonic-gate ipp->ipp_fields |= IPPF_RTDSTOPTS; 26090Sstevel@tonic-gate } 26100Sstevel@tonic-gate if (sticky) { 26110Sstevel@tonic-gate error = icmp_build_hdrs(q, icmp); 26120Sstevel@tonic-gate if (error != 0) 26130Sstevel@tonic-gate return (error); 26140Sstevel@tonic-gate } 26150Sstevel@tonic-gate break; 26160Sstevel@tonic-gate } 26170Sstevel@tonic-gate case IPV6_DSTOPTS: { 26180Sstevel@tonic-gate ip6_dest_t *dopts = (ip6_dest_t *)invalp; 26190Sstevel@tonic-gate 26200Sstevel@tonic-gate /* 26210Sstevel@tonic-gate * Sanity checks - minimum size, size a multiple of 26220Sstevel@tonic-gate * eight bytes, and matching size passed in. 26230Sstevel@tonic-gate */ 26240Sstevel@tonic-gate if (inlen != 0 && 26250Sstevel@tonic-gate inlen != (8 * (dopts->ip6d_len + 1))) 26260Sstevel@tonic-gate return (EINVAL); 26270Sstevel@tonic-gate 26280Sstevel@tonic-gate if (checkonly) 26290Sstevel@tonic-gate break; 26300Sstevel@tonic-gate 26310Sstevel@tonic-gate if (inlen == 0) { 26320Sstevel@tonic-gate if (sticky && 26330Sstevel@tonic-gate (ipp->ipp_fields & IPPF_DSTOPTS) != 0) { 26340Sstevel@tonic-gate kmem_free(ipp->ipp_dstopts, 26350Sstevel@tonic-gate ipp->ipp_dstoptslen); 26360Sstevel@tonic-gate ipp->ipp_dstopts = NULL; 26370Sstevel@tonic-gate ipp->ipp_dstoptslen = 0; 26380Sstevel@tonic-gate } 26390Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_DSTOPTS; 26400Sstevel@tonic-gate ipp->ipp_sticky_ignored |= IPPF_DSTOPTS; 26410Sstevel@tonic-gate } else { 26421676Sjpk error = optcom_pkt_set(invalp, inlen, sticky, 26430Sstevel@tonic-gate (uchar_t **)&ipp->ipp_dstopts, 26441676Sjpk &ipp->ipp_dstoptslen, 0); 26450Sstevel@tonic-gate if (error != 0) 26460Sstevel@tonic-gate return (error); 26470Sstevel@tonic-gate ipp->ipp_fields |= IPPF_DSTOPTS; 26480Sstevel@tonic-gate } 26490Sstevel@tonic-gate if (sticky) { 26500Sstevel@tonic-gate error = icmp_build_hdrs(q, icmp); 26510Sstevel@tonic-gate if (error != 0) 26520Sstevel@tonic-gate return (error); 26530Sstevel@tonic-gate } 26540Sstevel@tonic-gate break; 26550Sstevel@tonic-gate } 26560Sstevel@tonic-gate case IPV6_RTHDR: { 26570Sstevel@tonic-gate ip6_rthdr_t *rt = (ip6_rthdr_t *)invalp; 26580Sstevel@tonic-gate 26590Sstevel@tonic-gate /* 26600Sstevel@tonic-gate * Sanity checks - minimum size, size a multiple of 26610Sstevel@tonic-gate * eight bytes, and matching size passed in. 26620Sstevel@tonic-gate */ 26630Sstevel@tonic-gate if (inlen != 0 && 26640Sstevel@tonic-gate inlen != (8 * (rt->ip6r_len + 1))) 26650Sstevel@tonic-gate return (EINVAL); 26660Sstevel@tonic-gate 26670Sstevel@tonic-gate if (checkonly) 26680Sstevel@tonic-gate break; 26690Sstevel@tonic-gate 26700Sstevel@tonic-gate if (inlen == 0) { 26710Sstevel@tonic-gate if (sticky && 26720Sstevel@tonic-gate (ipp->ipp_fields & IPPF_RTHDR) != 0) { 26730Sstevel@tonic-gate kmem_free(ipp->ipp_rthdr, 26740Sstevel@tonic-gate ipp->ipp_rthdrlen); 26750Sstevel@tonic-gate ipp->ipp_rthdr = NULL; 26760Sstevel@tonic-gate ipp->ipp_rthdrlen = 0; 26770Sstevel@tonic-gate } 26780Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_RTHDR; 26790Sstevel@tonic-gate ipp->ipp_sticky_ignored |= IPPF_RTHDR; 26800Sstevel@tonic-gate } else { 26811676Sjpk error = optcom_pkt_set(invalp, inlen, sticky, 26820Sstevel@tonic-gate (uchar_t **)&ipp->ipp_rthdr, 26831676Sjpk &ipp->ipp_rthdrlen, 0); 26840Sstevel@tonic-gate if (error != 0) 26850Sstevel@tonic-gate return (error); 26860Sstevel@tonic-gate ipp->ipp_fields |= IPPF_RTHDR; 26870Sstevel@tonic-gate } 26880Sstevel@tonic-gate if (sticky) { 26890Sstevel@tonic-gate error = icmp_build_hdrs(q, icmp); 26900Sstevel@tonic-gate if (error != 0) 26910Sstevel@tonic-gate return (error); 26920Sstevel@tonic-gate } 26930Sstevel@tonic-gate break; 26940Sstevel@tonic-gate } 26950Sstevel@tonic-gate 26960Sstevel@tonic-gate case IPV6_DONTFRAG: 26970Sstevel@tonic-gate if (checkonly) 26980Sstevel@tonic-gate break; 26990Sstevel@tonic-gate 27000Sstevel@tonic-gate if (onoff) { 27010Sstevel@tonic-gate ipp->ipp_fields |= IPPF_DONTFRAG; 27020Sstevel@tonic-gate } else { 27030Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_DONTFRAG; 27040Sstevel@tonic-gate } 27050Sstevel@tonic-gate break; 27060Sstevel@tonic-gate 27070Sstevel@tonic-gate case IPV6_USE_MIN_MTU: 27080Sstevel@tonic-gate if (inlen != sizeof (int)) 27090Sstevel@tonic-gate return (EINVAL); 27100Sstevel@tonic-gate 27110Sstevel@tonic-gate if (*i1 < -1 || *i1 > 1) 27120Sstevel@tonic-gate return (EINVAL); 27130Sstevel@tonic-gate 27140Sstevel@tonic-gate if (checkonly) 27150Sstevel@tonic-gate break; 27160Sstevel@tonic-gate 27170Sstevel@tonic-gate ipp->ipp_fields |= IPPF_USE_MIN_MTU; 27180Sstevel@tonic-gate ipp->ipp_use_min_mtu = *i1; 27190Sstevel@tonic-gate break; 27200Sstevel@tonic-gate 27210Sstevel@tonic-gate /* 27220Sstevel@tonic-gate * This option can't be set. Its only returned via 27230Sstevel@tonic-gate * getsockopt() or ancillary data. 27240Sstevel@tonic-gate */ 27250Sstevel@tonic-gate case IPV6_PATHMTU: 27260Sstevel@tonic-gate return (EINVAL); 27270Sstevel@tonic-gate 27280Sstevel@tonic-gate case IPV6_BOUND_PIF: 27290Sstevel@tonic-gate case IPV6_SEC_OPT: 27300Sstevel@tonic-gate case IPV6_DONTFAILOVER_IF: 27310Sstevel@tonic-gate case IPV6_SRC_PREFERENCES: 27320Sstevel@tonic-gate case IPV6_V6ONLY: 27330Sstevel@tonic-gate /* Handled at IP level */ 27340Sstevel@tonic-gate return (-EINVAL); 27350Sstevel@tonic-gate default: 27360Sstevel@tonic-gate *outlenp = 0; 27370Sstevel@tonic-gate return (EINVAL); 27380Sstevel@tonic-gate } 27390Sstevel@tonic-gate break; 27400Sstevel@tonic-gate } /* end IPPROTO_IPV6 */ 27410Sstevel@tonic-gate 27420Sstevel@tonic-gate case IPPROTO_ICMPV6: 27430Sstevel@tonic-gate /* 27440Sstevel@tonic-gate * Only allow IPv6 option processing on IPv6 sockets. 27450Sstevel@tonic-gate */ 27460Sstevel@tonic-gate if (icmp->icmp_family != AF_INET6) { 27470Sstevel@tonic-gate *outlenp = 0; 27480Sstevel@tonic-gate return (ENOPROTOOPT); 27490Sstevel@tonic-gate } 27500Sstevel@tonic-gate if (icmp->icmp_proto != IPPROTO_ICMPV6) { 27510Sstevel@tonic-gate *outlenp = 0; 27520Sstevel@tonic-gate return (ENOPROTOOPT); 27530Sstevel@tonic-gate } 27540Sstevel@tonic-gate switch (name) { 27550Sstevel@tonic-gate case ICMP6_FILTER: 27560Sstevel@tonic-gate if (!checkonly) { 27570Sstevel@tonic-gate if ((inlen != 0) && 27580Sstevel@tonic-gate (inlen != sizeof (icmp6_filter_t))) 27590Sstevel@tonic-gate return (EINVAL); 27600Sstevel@tonic-gate 27610Sstevel@tonic-gate if (inlen == 0) { 27620Sstevel@tonic-gate if (icmp->icmp_filter != NULL) { 27630Sstevel@tonic-gate kmem_free(icmp->icmp_filter, 27640Sstevel@tonic-gate sizeof (icmp6_filter_t)); 27650Sstevel@tonic-gate icmp->icmp_filter = NULL; 27660Sstevel@tonic-gate } 27670Sstevel@tonic-gate } else { 27680Sstevel@tonic-gate if (icmp->icmp_filter == NULL) { 27690Sstevel@tonic-gate icmp->icmp_filter = kmem_alloc( 27700Sstevel@tonic-gate sizeof (icmp6_filter_t), 27710Sstevel@tonic-gate KM_NOSLEEP); 27720Sstevel@tonic-gate if (icmp->icmp_filter == NULL) { 27730Sstevel@tonic-gate *outlenp = 0; 27740Sstevel@tonic-gate return (ENOBUFS); 27750Sstevel@tonic-gate } 27760Sstevel@tonic-gate } 27770Sstevel@tonic-gate (void) bcopy(invalp, icmp->icmp_filter, 27780Sstevel@tonic-gate inlen); 27790Sstevel@tonic-gate } 27800Sstevel@tonic-gate } 27810Sstevel@tonic-gate break; 27820Sstevel@tonic-gate 27830Sstevel@tonic-gate default: 27840Sstevel@tonic-gate *outlenp = 0; 27850Sstevel@tonic-gate return (EINVAL); 27860Sstevel@tonic-gate } 27870Sstevel@tonic-gate break; 27880Sstevel@tonic-gate default: 27890Sstevel@tonic-gate *outlenp = 0; 27900Sstevel@tonic-gate return (EINVAL); 27910Sstevel@tonic-gate } 27920Sstevel@tonic-gate /* 27930Sstevel@tonic-gate * Common case of OK return with outval same as inval. 27940Sstevel@tonic-gate */ 27950Sstevel@tonic-gate if (invalp != outvalp) { 27960Sstevel@tonic-gate /* don't trust bcopy for identical src/dst */ 27970Sstevel@tonic-gate (void) bcopy(invalp, outvalp, inlen); 27980Sstevel@tonic-gate } 27990Sstevel@tonic-gate *outlenp = inlen; 28000Sstevel@tonic-gate return (0); 28010Sstevel@tonic-gate } 28020Sstevel@tonic-gate 28030Sstevel@tonic-gate /* 28040Sstevel@tonic-gate * Update icmp_sticky_hdrs based on icmp_sticky_ipp, icmp_v6src, icmp_ttl, 28050Sstevel@tonic-gate * icmp_proto, icmp_raw_checksum and icmp_no_tp_cksum. 28060Sstevel@tonic-gate * The headers include ip6i_t (if needed), ip6_t, and any sticky extension 28070Sstevel@tonic-gate * headers. 28080Sstevel@tonic-gate * Returns failure if can't allocate memory. 28090Sstevel@tonic-gate */ 28100Sstevel@tonic-gate static int 28110Sstevel@tonic-gate icmp_build_hdrs(queue_t *q, icmp_t *icmp) 28120Sstevel@tonic-gate { 28130Sstevel@tonic-gate uchar_t *hdrs; 28140Sstevel@tonic-gate uint_t hdrs_len; 28150Sstevel@tonic-gate ip6_t *ip6h; 28160Sstevel@tonic-gate ip6i_t *ip6i; 28170Sstevel@tonic-gate ip6_pkt_t *ipp = &icmp->icmp_sticky_ipp; 28180Sstevel@tonic-gate 28190Sstevel@tonic-gate hdrs_len = ip_total_hdrs_len_v6(ipp); 28200Sstevel@tonic-gate ASSERT(hdrs_len != 0); 28210Sstevel@tonic-gate if (hdrs_len != icmp->icmp_sticky_hdrs_len) { 28220Sstevel@tonic-gate /* Need to reallocate */ 28230Sstevel@tonic-gate if (hdrs_len != 0) { 28240Sstevel@tonic-gate hdrs = kmem_alloc(hdrs_len, KM_NOSLEEP); 28250Sstevel@tonic-gate if (hdrs == NULL) 28260Sstevel@tonic-gate return (ENOMEM); 28270Sstevel@tonic-gate } else { 28280Sstevel@tonic-gate hdrs = NULL; 28290Sstevel@tonic-gate } 28300Sstevel@tonic-gate if (icmp->icmp_sticky_hdrs_len != 0) { 28310Sstevel@tonic-gate kmem_free(icmp->icmp_sticky_hdrs, 28320Sstevel@tonic-gate icmp->icmp_sticky_hdrs_len); 28330Sstevel@tonic-gate } 28340Sstevel@tonic-gate icmp->icmp_sticky_hdrs = hdrs; 28350Sstevel@tonic-gate icmp->icmp_sticky_hdrs_len = hdrs_len; 28360Sstevel@tonic-gate } 28370Sstevel@tonic-gate ip_build_hdrs_v6(icmp->icmp_sticky_hdrs, 28380Sstevel@tonic-gate icmp->icmp_sticky_hdrs_len, ipp, icmp->icmp_proto); 28390Sstevel@tonic-gate 28400Sstevel@tonic-gate /* Set header fields not in ipp */ 28410Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_HAS_IP6I) { 28420Sstevel@tonic-gate ip6i = (ip6i_t *)icmp->icmp_sticky_hdrs; 28430Sstevel@tonic-gate ip6h = (ip6_t *)&ip6i[1]; 28440Sstevel@tonic-gate 28450Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_RAW_CKSUM) { 28460Sstevel@tonic-gate ip6i->ip6i_flags |= IP6I_RAW_CHECKSUM; 28470Sstevel@tonic-gate ip6i->ip6i_checksum_off = icmp->icmp_checksum_off; 28480Sstevel@tonic-gate } 28490Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_NO_CKSUM) { 28500Sstevel@tonic-gate ip6i->ip6i_flags |= IP6I_NO_ULP_CKSUM; 28510Sstevel@tonic-gate } 28520Sstevel@tonic-gate } else { 28530Sstevel@tonic-gate ip6h = (ip6_t *)icmp->icmp_sticky_hdrs; 28540Sstevel@tonic-gate } 28550Sstevel@tonic-gate 28560Sstevel@tonic-gate if (!(ipp->ipp_fields & IPPF_ADDR)) 28570Sstevel@tonic-gate ip6h->ip6_src = icmp->icmp_v6src; 28580Sstevel@tonic-gate 28590Sstevel@tonic-gate /* Try to get everything in a single mblk */ 28600Sstevel@tonic-gate if (hdrs_len > icmp->icmp_max_hdr_len) { 28610Sstevel@tonic-gate icmp->icmp_max_hdr_len = hdrs_len; 28620Sstevel@tonic-gate (void) mi_set_sth_wroff(RD(q), icmp->icmp_max_hdr_len + 28630Sstevel@tonic-gate icmp_wroff_extra); 28640Sstevel@tonic-gate } 28650Sstevel@tonic-gate return (0); 28660Sstevel@tonic-gate } 28670Sstevel@tonic-gate 28680Sstevel@tonic-gate /* 28690Sstevel@tonic-gate * This routine retrieves the value of an ND variable in a icmpparam_t 28700Sstevel@tonic-gate * structure. It is called through nd_getset when a user reads the 28710Sstevel@tonic-gate * variable. 28720Sstevel@tonic-gate */ 28730Sstevel@tonic-gate /* ARGSUSED */ 28740Sstevel@tonic-gate static int 28750Sstevel@tonic-gate icmp_param_get(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr) 28760Sstevel@tonic-gate { 28770Sstevel@tonic-gate icmpparam_t *icmppa = (icmpparam_t *)cp; 28780Sstevel@tonic-gate 28790Sstevel@tonic-gate (void) mi_mpprintf(mp, "%d", icmppa->icmp_param_value); 28800Sstevel@tonic-gate return (0); 28810Sstevel@tonic-gate } 28820Sstevel@tonic-gate 28830Sstevel@tonic-gate /* 28840Sstevel@tonic-gate * Walk through the param array specified registering each element with the 28850Sstevel@tonic-gate * named dispatch (ND) handler. 28860Sstevel@tonic-gate */ 28870Sstevel@tonic-gate static boolean_t 28880Sstevel@tonic-gate icmp_param_register(icmpparam_t *icmppa, int cnt) 28890Sstevel@tonic-gate { 28900Sstevel@tonic-gate for (; cnt-- > 0; icmppa++) { 28910Sstevel@tonic-gate if (icmppa->icmp_param_name && icmppa->icmp_param_name[0]) { 28920Sstevel@tonic-gate if (!nd_load(&icmp_g_nd, icmppa->icmp_param_name, 28930Sstevel@tonic-gate icmp_param_get, icmp_param_set, 28940Sstevel@tonic-gate (caddr_t)icmppa)) { 28950Sstevel@tonic-gate nd_free(&icmp_g_nd); 28960Sstevel@tonic-gate return (B_FALSE); 28970Sstevel@tonic-gate } 28980Sstevel@tonic-gate } 28990Sstevel@tonic-gate } 29000Sstevel@tonic-gate if (!nd_load(&icmp_g_nd, "icmp_status", icmp_status_report, NULL, 29010Sstevel@tonic-gate NULL)) { 29020Sstevel@tonic-gate nd_free(&icmp_g_nd); 29030Sstevel@tonic-gate return (B_FALSE); 29040Sstevel@tonic-gate } 29050Sstevel@tonic-gate return (B_TRUE); 29060Sstevel@tonic-gate } 29070Sstevel@tonic-gate 29080Sstevel@tonic-gate /* This routine sets an ND variable in a icmpparam_t structure. */ 29090Sstevel@tonic-gate /* ARGSUSED */ 29100Sstevel@tonic-gate static int 29110Sstevel@tonic-gate icmp_param_set(queue_t *q, mblk_t *mp, char *value, caddr_t cp, cred_t *cr) 29120Sstevel@tonic-gate { 29130Sstevel@tonic-gate long new_value; 29140Sstevel@tonic-gate icmpparam_t *icmppa = (icmpparam_t *)cp; 29150Sstevel@tonic-gate 29160Sstevel@tonic-gate /* 29170Sstevel@tonic-gate * Fail the request if the new value does not lie within the 29180Sstevel@tonic-gate * required bounds. 29190Sstevel@tonic-gate */ 29200Sstevel@tonic-gate if (ddi_strtol(value, NULL, 10, &new_value) != 0 || 29210Sstevel@tonic-gate new_value < icmppa->icmp_param_min || 29220Sstevel@tonic-gate new_value > icmppa->icmp_param_max) { 29230Sstevel@tonic-gate return (EINVAL); 29240Sstevel@tonic-gate } 29250Sstevel@tonic-gate /* Set the new value */ 29260Sstevel@tonic-gate icmppa->icmp_param_value = new_value; 29270Sstevel@tonic-gate return (0); 29280Sstevel@tonic-gate } 29290Sstevel@tonic-gate 29300Sstevel@tonic-gate static void 29310Sstevel@tonic-gate icmp_rput(queue_t *q, mblk_t *mp) 29320Sstevel@tonic-gate { 29330Sstevel@tonic-gate struct T_unitdata_ind *tudi; 29340Sstevel@tonic-gate uchar_t *rptr; 29350Sstevel@tonic-gate struct T_error_ack *tea; 29360Sstevel@tonic-gate icmp_t *icmp; 29370Sstevel@tonic-gate sin_t *sin; 29380Sstevel@tonic-gate sin6_t *sin6; 29390Sstevel@tonic-gate ip6_t *ip6h; 29400Sstevel@tonic-gate ip6i_t *ip6i; 29410Sstevel@tonic-gate mblk_t *mp1; 29420Sstevel@tonic-gate int hdr_len; 29430Sstevel@tonic-gate ipha_t *ipha; 29440Sstevel@tonic-gate int udi_size; /* Size of T_unitdata_ind */ 29450Sstevel@tonic-gate uint_t ipvers; 29460Sstevel@tonic-gate ip6_pkt_t ipp; 29470Sstevel@tonic-gate uint8_t nexthdr; 29480Sstevel@tonic-gate boolean_t recvif = B_FALSE; 2949*3318Srshoaib ip_pktinfo_t *pinfo = NULL; 29500Sstevel@tonic-gate mblk_t *options_mp = NULL; 29510Sstevel@tonic-gate uint_t icmp_opt = 0; 29520Sstevel@tonic-gate boolean_t icmp_ipv6_recvhoplimit = B_FALSE; 29531676Sjpk uint_t hopstrip; 29540Sstevel@tonic-gate 29550Sstevel@tonic-gate icmp = (icmp_t *)q->q_ptr; 29560Sstevel@tonic-gate if (icmp->icmp_restricted) { 29570Sstevel@tonic-gate putnext(q, mp); 29580Sstevel@tonic-gate return; 29590Sstevel@tonic-gate } 29600Sstevel@tonic-gate 29610Sstevel@tonic-gate if (mp->b_datap->db_type == M_CTL) { 29620Sstevel@tonic-gate /* 29630Sstevel@tonic-gate * IP sends up the IPSEC_IN message for handling IPSEC 29640Sstevel@tonic-gate * policy at the TCP level. We don't need it here. 29650Sstevel@tonic-gate */ 29660Sstevel@tonic-gate if (*(uint32_t *)(mp->b_rptr) == IPSEC_IN) { 29670Sstevel@tonic-gate mp1 = mp->b_cont; 29680Sstevel@tonic-gate freeb(mp); 29690Sstevel@tonic-gate mp = mp1; 29700Sstevel@tonic-gate } else { 2971*3318Srshoaib pinfo = (ip_pktinfo_t *)mp->b_rptr; 2972*3318Srshoaib if ((icmp->icmp_recvif != 0 || 2973*3318Srshoaib icmp->icmp_ip_recvpktinfo) && 2974*3318Srshoaib (pinfo->ip_pkt_ulp_type == IN_PKTINFO)) { 29750Sstevel@tonic-gate /* 29760Sstevel@tonic-gate * IP has passed the options in mp and the 29770Sstevel@tonic-gate * actual data is in b_cont. 29780Sstevel@tonic-gate */ 29790Sstevel@tonic-gate recvif = B_TRUE; 29800Sstevel@tonic-gate /* 29810Sstevel@tonic-gate * We are here bcos IP_RECVIF is set so we need 29820Sstevel@tonic-gate * to extract the options mblk and adjust the 29830Sstevel@tonic-gate * rptr 29840Sstevel@tonic-gate */ 29850Sstevel@tonic-gate options_mp = mp; 29860Sstevel@tonic-gate mp = mp->b_cont; 29870Sstevel@tonic-gate } 29880Sstevel@tonic-gate } 29890Sstevel@tonic-gate } 29900Sstevel@tonic-gate 29910Sstevel@tonic-gate rptr = mp->b_rptr; 29920Sstevel@tonic-gate switch (mp->b_datap->db_type) { 29930Sstevel@tonic-gate case M_DATA: 29940Sstevel@tonic-gate /* 29950Sstevel@tonic-gate * M_DATA messages contain IP packets. They are handled 29960Sstevel@tonic-gate * following the switch. 29970Sstevel@tonic-gate */ 29980Sstevel@tonic-gate break; 29990Sstevel@tonic-gate case M_PROTO: 30000Sstevel@tonic-gate case M_PCPROTO: 30010Sstevel@tonic-gate /* M_PROTO messages contain some type of TPI message. */ 30020Sstevel@tonic-gate if ((mp->b_wptr - rptr) < sizeof (t_scalar_t)) { 30030Sstevel@tonic-gate freemsg(mp); 30040Sstevel@tonic-gate return; 30050Sstevel@tonic-gate } 30060Sstevel@tonic-gate tea = (struct T_error_ack *)rptr; 30070Sstevel@tonic-gate switch (tea->PRIM_type) { 30080Sstevel@tonic-gate case T_ERROR_ACK: 30090Sstevel@tonic-gate switch (tea->ERROR_prim) { 30100Sstevel@tonic-gate case O_T_BIND_REQ: 30110Sstevel@tonic-gate case T_BIND_REQ: 30120Sstevel@tonic-gate /* 30130Sstevel@tonic-gate * If our O_T_BIND_REQ/T_BIND_REQ fails, 30140Sstevel@tonic-gate * clear out the source address before 30150Sstevel@tonic-gate * passing the message upstream. 30160Sstevel@tonic-gate * If this was caused by a T_CONN_REQ 30170Sstevel@tonic-gate * revert back to bound state. 30180Sstevel@tonic-gate */ 30190Sstevel@tonic-gate if (icmp->icmp_state == TS_UNBND) { 30200Sstevel@tonic-gate /* 30210Sstevel@tonic-gate * TPI has not yet bound - bind sent by 30220Sstevel@tonic-gate * icmp_bind_proto. 30230Sstevel@tonic-gate */ 30240Sstevel@tonic-gate freemsg(mp); 30250Sstevel@tonic-gate return; 30260Sstevel@tonic-gate } 30270Sstevel@tonic-gate if (icmp->icmp_state == TS_DATA_XFER) { 30280Sstevel@tonic-gate /* Connect failed */ 30290Sstevel@tonic-gate tea->ERROR_prim = T_CONN_REQ; 30300Sstevel@tonic-gate icmp->icmp_v6src = 30310Sstevel@tonic-gate icmp->icmp_bound_v6src; 30320Sstevel@tonic-gate icmp->icmp_state = TS_IDLE; 30330Sstevel@tonic-gate if (icmp->icmp_family == AF_INET6) 30340Sstevel@tonic-gate (void) icmp_build_hdrs(q, icmp); 30350Sstevel@tonic-gate break; 30360Sstevel@tonic-gate } 30370Sstevel@tonic-gate 30380Sstevel@tonic-gate if (icmp->icmp_discon_pending) { 30390Sstevel@tonic-gate tea->ERROR_prim = T_DISCON_REQ; 30400Sstevel@tonic-gate icmp->icmp_discon_pending = 0; 30410Sstevel@tonic-gate } 30420Sstevel@tonic-gate V6_SET_ZERO(icmp->icmp_v6src); 30430Sstevel@tonic-gate V6_SET_ZERO(icmp->icmp_bound_v6src); 30440Sstevel@tonic-gate icmp->icmp_state = TS_UNBND; 30450Sstevel@tonic-gate if (icmp->icmp_family == AF_INET6) 30460Sstevel@tonic-gate (void) icmp_build_hdrs(q, icmp); 30470Sstevel@tonic-gate break; 30480Sstevel@tonic-gate default: 30490Sstevel@tonic-gate break; 30500Sstevel@tonic-gate } 30510Sstevel@tonic-gate break; 30520Sstevel@tonic-gate case T_BIND_ACK: 30530Sstevel@tonic-gate icmp_rput_bind_ack(q, mp); 30540Sstevel@tonic-gate return; 30550Sstevel@tonic-gate 30560Sstevel@tonic-gate case T_OPTMGMT_ACK: 30570Sstevel@tonic-gate case T_OK_ACK: 30580Sstevel@tonic-gate if (tea->PRIM_type == T_OK_ACK) { 30590Sstevel@tonic-gate struct T_ok_ack *toa; 30600Sstevel@tonic-gate toa = (struct T_ok_ack *)rptr; 30610Sstevel@tonic-gate if (toa->CORRECT_prim == T_UNBIND_REQ) { 30620Sstevel@tonic-gate /* 30630Sstevel@tonic-gate * If somebody sets IPSEC options, IP 30640Sstevel@tonic-gate * sends some IPSEC info which is used 30650Sstevel@tonic-gate * by the TCP for detached connections. 30660Sstevel@tonic-gate * We don't need it here. 30670Sstevel@tonic-gate */ 30680Sstevel@tonic-gate if ((mp1 = mp->b_cont) != NULL) { 30690Sstevel@tonic-gate freemsg(mp1); 30700Sstevel@tonic-gate mp->b_cont = NULL; 30710Sstevel@tonic-gate } 30720Sstevel@tonic-gate } 30730Sstevel@tonic-gate } 30740Sstevel@tonic-gate break; 30750Sstevel@tonic-gate default: 30760Sstevel@tonic-gate freemsg(mp); 30770Sstevel@tonic-gate return; 30780Sstevel@tonic-gate } 30790Sstevel@tonic-gate putnext(q, mp); 30800Sstevel@tonic-gate return; 30810Sstevel@tonic-gate case M_CTL: 30820Sstevel@tonic-gate if (recvif) { 30830Sstevel@tonic-gate /* 30840Sstevel@tonic-gate * IP has passed the options in mp and the actual data 30850Sstevel@tonic-gate * is in b_cont. Jump to normal data processing. 30860Sstevel@tonic-gate */ 30870Sstevel@tonic-gate break; 30880Sstevel@tonic-gate } 30890Sstevel@tonic-gate 30900Sstevel@tonic-gate /* Contains ICMP packet from IP */ 30910Sstevel@tonic-gate icmp_icmp_error(q, mp); 30920Sstevel@tonic-gate return; 30930Sstevel@tonic-gate default: 30940Sstevel@tonic-gate putnext(q, mp); 30950Sstevel@tonic-gate return; 30960Sstevel@tonic-gate } 30970Sstevel@tonic-gate 30980Sstevel@tonic-gate /* 30990Sstevel@tonic-gate * Discard message if it is misaligned or smaller than the IP header. 31000Sstevel@tonic-gate */ 31010Sstevel@tonic-gate if (!OK_32PTR(rptr) || (mp->b_wptr - rptr) < sizeof (ipha_t)) { 31020Sstevel@tonic-gate freemsg(mp); 31030Sstevel@tonic-gate if (options_mp != NULL) 31040Sstevel@tonic-gate freeb(options_mp); 31050Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipInErrors); 31060Sstevel@tonic-gate return; 31070Sstevel@tonic-gate } 31080Sstevel@tonic-gate ipvers = IPH_HDR_VERSION((ipha_t *)rptr); 31090Sstevel@tonic-gate 31100Sstevel@tonic-gate /* Handle M_DATA messages containing IP packets messages */ 31110Sstevel@tonic-gate if (ipvers == IPV4_VERSION) { 31120Sstevel@tonic-gate /* 31130Sstevel@tonic-gate * Special case where IP attaches 31140Sstevel@tonic-gate * the IRE needs to be handled so that we don't send up 31150Sstevel@tonic-gate * IRE to the user land. 31160Sstevel@tonic-gate */ 31170Sstevel@tonic-gate ipha = (ipha_t *)rptr; 31180Sstevel@tonic-gate hdr_len = IPH_HDR_LENGTH(ipha); 31190Sstevel@tonic-gate 31200Sstevel@tonic-gate if (ipha->ipha_protocol == IPPROTO_TCP) { 31210Sstevel@tonic-gate tcph_t *tcph = (tcph_t *)&mp->b_rptr[hdr_len]; 31220Sstevel@tonic-gate 31230Sstevel@tonic-gate if (((tcph->th_flags[0] & (TH_SYN|TH_ACK)) == 31240Sstevel@tonic-gate TH_SYN) && mp->b_cont != NULL) { 31250Sstevel@tonic-gate mp1 = mp->b_cont; 31260Sstevel@tonic-gate if (mp1->b_datap->db_type == IRE_DB_TYPE) { 31270Sstevel@tonic-gate freeb(mp1); 31280Sstevel@tonic-gate mp->b_cont = NULL; 31290Sstevel@tonic-gate } 31300Sstevel@tonic-gate } 31310Sstevel@tonic-gate } 31320Sstevel@tonic-gate if (icmp_bsd_compat) { 31330Sstevel@tonic-gate ushort_t len; 31340Sstevel@tonic-gate len = ntohs(ipha->ipha_length); 31350Sstevel@tonic-gate 31360Sstevel@tonic-gate if (mp->b_datap->db_ref > 1) { 31370Sstevel@tonic-gate /* 31380Sstevel@tonic-gate * Allocate a new IP header so that we can 31390Sstevel@tonic-gate * modify ipha_length. 31400Sstevel@tonic-gate */ 31410Sstevel@tonic-gate mblk_t *mp1; 31420Sstevel@tonic-gate 31430Sstevel@tonic-gate mp1 = allocb(hdr_len, BPRI_MED); 31440Sstevel@tonic-gate if (!mp1) { 31450Sstevel@tonic-gate freemsg(mp); 31460Sstevel@tonic-gate if (options_mp != NULL) 31470Sstevel@tonic-gate freeb(options_mp); 31480Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipInErrors); 31490Sstevel@tonic-gate return; 31500Sstevel@tonic-gate } 31510Sstevel@tonic-gate bcopy(rptr, mp1->b_rptr, hdr_len); 31520Sstevel@tonic-gate mp->b_rptr = rptr + hdr_len; 31530Sstevel@tonic-gate rptr = mp1->b_rptr; 31540Sstevel@tonic-gate ipha = (ipha_t *)rptr; 31550Sstevel@tonic-gate mp1->b_cont = mp; 31560Sstevel@tonic-gate mp1->b_wptr = rptr + hdr_len; 31570Sstevel@tonic-gate mp = mp1; 31580Sstevel@tonic-gate } 31590Sstevel@tonic-gate len -= hdr_len; 31600Sstevel@tonic-gate ipha->ipha_length = htons(len); 31610Sstevel@tonic-gate } 31620Sstevel@tonic-gate } 31630Sstevel@tonic-gate 31640Sstevel@tonic-gate /* 31650Sstevel@tonic-gate * This is the inbound data path. Packets are passed upstream as 31660Sstevel@tonic-gate * T_UNITDATA_IND messages with full IP headers still attached. 31670Sstevel@tonic-gate */ 31680Sstevel@tonic-gate if (icmp->icmp_family == AF_INET) { 31690Sstevel@tonic-gate ASSERT(ipvers == IPV4_VERSION); 31700Sstevel@tonic-gate udi_size = sizeof (struct T_unitdata_ind) + sizeof (sin_t); 3171*3318Srshoaib if (icmp->icmp_recvif && recvif && 3172*3318Srshoaib (pinfo->ip_pkt_flags & IPF_RECVIF)) { 31730Sstevel@tonic-gate udi_size += sizeof (struct T_opthdr) + 31740Sstevel@tonic-gate sizeof (uint_t); 31750Sstevel@tonic-gate } 3176*3318Srshoaib 3177*3318Srshoaib if (icmp->icmp_ip_recvpktinfo && recvif && 3178*3318Srshoaib (pinfo->ip_pkt_flags & IPF_RECVADDR)) { 3179*3318Srshoaib udi_size += sizeof (struct T_opthdr) + 3180*3318Srshoaib sizeof (struct in_pktinfo); 3181*3318Srshoaib } 3182*3318Srshoaib 31831673Sgt145670 /* 31841673Sgt145670 * If SO_TIMESTAMP is set allocate the appropriate sized 31851673Sgt145670 * buffer. Since gethrestime() expects a pointer aligned 31861673Sgt145670 * argument, we allocate space necessary for extra 31871673Sgt145670 * alignment (even though it might not be used). 31881673Sgt145670 */ 31891673Sgt145670 if (icmp->icmp_timestamp) { 31901673Sgt145670 udi_size += sizeof (struct T_opthdr) + 31911673Sgt145670 sizeof (timestruc_t) + _POINTER_ALIGNMENT; 31921673Sgt145670 } 31930Sstevel@tonic-gate mp1 = allocb(udi_size, BPRI_MED); 31940Sstevel@tonic-gate if (mp1 == NULL) { 31950Sstevel@tonic-gate freemsg(mp); 31960Sstevel@tonic-gate if (options_mp != NULL) 31970Sstevel@tonic-gate freeb(options_mp); 31980Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipInErrors); 31990Sstevel@tonic-gate return; 32000Sstevel@tonic-gate } 32010Sstevel@tonic-gate mp1->b_cont = mp; 32020Sstevel@tonic-gate mp = mp1; 32030Sstevel@tonic-gate tudi = (struct T_unitdata_ind *)mp->b_rptr; 32040Sstevel@tonic-gate mp->b_datap->db_type = M_PROTO; 32050Sstevel@tonic-gate mp->b_wptr = (uchar_t *)tudi + udi_size; 32060Sstevel@tonic-gate tudi->PRIM_type = T_UNITDATA_IND; 32070Sstevel@tonic-gate tudi->SRC_length = sizeof (sin_t); 32080Sstevel@tonic-gate tudi->SRC_offset = sizeof (struct T_unitdata_ind); 32090Sstevel@tonic-gate sin = (sin_t *)&tudi[1]; 32100Sstevel@tonic-gate *sin = sin_null; 32110Sstevel@tonic-gate sin->sin_family = AF_INET; 32120Sstevel@tonic-gate sin->sin_addr.s_addr = ipha->ipha_src; 32130Sstevel@tonic-gate tudi->OPT_offset = sizeof (struct T_unitdata_ind) + 32140Sstevel@tonic-gate sizeof (sin_t); 32150Sstevel@tonic-gate udi_size -= (sizeof (struct T_unitdata_ind) + sizeof (sin_t)); 32160Sstevel@tonic-gate tudi->OPT_length = udi_size; 32170Sstevel@tonic-gate 32180Sstevel@tonic-gate /* 32190Sstevel@tonic-gate * Add options if IP_RECVIF is set 32200Sstevel@tonic-gate */ 32210Sstevel@tonic-gate if (udi_size != 0) { 32220Sstevel@tonic-gate char *dstopt; 32230Sstevel@tonic-gate 32240Sstevel@tonic-gate dstopt = (char *)&sin[1]; 3225*3318Srshoaib if (icmp->icmp_recvif && recvif && 3226*3318Srshoaib (pinfo->ip_pkt_flags & IPF_RECVIF)) { 32270Sstevel@tonic-gate 32280Sstevel@tonic-gate struct T_opthdr *toh; 32290Sstevel@tonic-gate uint_t *dstptr; 32300Sstevel@tonic-gate 32310Sstevel@tonic-gate toh = (struct T_opthdr *)dstopt; 32320Sstevel@tonic-gate toh->level = IPPROTO_IP; 32330Sstevel@tonic-gate toh->name = IP_RECVIF; 32340Sstevel@tonic-gate toh->len = sizeof (struct T_opthdr) + 32350Sstevel@tonic-gate sizeof (uint_t); 32360Sstevel@tonic-gate toh->status = 0; 32370Sstevel@tonic-gate dstopt += sizeof (struct T_opthdr); 32380Sstevel@tonic-gate dstptr = (uint_t *)dstopt; 3239*3318Srshoaib *dstptr = pinfo->ip_pkt_ifindex; 32400Sstevel@tonic-gate dstopt += sizeof (uint_t); 32410Sstevel@tonic-gate freeb(options_mp); 32420Sstevel@tonic-gate udi_size -= toh->len; 32430Sstevel@tonic-gate } 32441673Sgt145670 if (icmp->icmp_timestamp) { 32451673Sgt145670 struct T_opthdr *toh; 32461673Sgt145670 32471673Sgt145670 toh = (struct T_opthdr *)dstopt; 32481673Sgt145670 toh->level = SOL_SOCKET; 32491673Sgt145670 toh->name = SCM_TIMESTAMP; 32501673Sgt145670 toh->len = sizeof (struct T_opthdr) + 32511673Sgt145670 sizeof (timestruc_t) + _POINTER_ALIGNMENT; 32521673Sgt145670 toh->status = 0; 32531673Sgt145670 dstopt += sizeof (struct T_opthdr); 32541673Sgt145670 /* Align for gethrestime() */ 32551673Sgt145670 dstopt = (char *)P2ROUNDUP((intptr_t)dstopt, 32561673Sgt145670 sizeof (intptr_t)); 32571673Sgt145670 gethrestime((timestruc_t *)dstopt); 3258*3318Srshoaib dstopt = (char *)toh + toh->len; 3259*3318Srshoaib udi_size -= toh->len; 3260*3318Srshoaib } 3261*3318Srshoaib if (icmp->icmp_ip_recvpktinfo && recvif && 3262*3318Srshoaib (pinfo->ip_pkt_flags & IPF_RECVADDR)) { 3263*3318Srshoaib struct T_opthdr *toh; 3264*3318Srshoaib struct in_pktinfo *pktinfop; 3265*3318Srshoaib 3266*3318Srshoaib toh = (struct T_opthdr *)dstopt; 3267*3318Srshoaib toh->level = IPPROTO_IP; 3268*3318Srshoaib toh->name = IP_PKTINFO; 3269*3318Srshoaib toh->len = sizeof (struct T_opthdr) + 3270*3318Srshoaib sizeof (in_pktinfo_t); 3271*3318Srshoaib toh->status = 0; 3272*3318Srshoaib dstopt += sizeof (struct T_opthdr); 3273*3318Srshoaib pktinfop = (struct in_pktinfo *)dstopt; 3274*3318Srshoaib pktinfop->ipi_ifindex = pinfo->ip_pkt_ifindex; 3275*3318Srshoaib pktinfop->ipi_spec_dst = 3276*3318Srshoaib pinfo->ip_pkt_match_addr; 3277*3318Srshoaib 3278*3318Srshoaib pktinfop->ipi_addr.s_addr = ipha->ipha_dst; 3279*3318Srshoaib 3280*3318Srshoaib dstopt += sizeof (struct in_pktinfo); 32811673Sgt145670 udi_size -= toh->len; 32821673Sgt145670 } 32830Sstevel@tonic-gate 32840Sstevel@tonic-gate /* Consumed all of allocated space */ 32850Sstevel@tonic-gate ASSERT(udi_size == 0); 32860Sstevel@tonic-gate } 32870Sstevel@tonic-gate 32880Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipInDatagrams); 32890Sstevel@tonic-gate putnext(q, mp); 32900Sstevel@tonic-gate return; 32910Sstevel@tonic-gate } 32920Sstevel@tonic-gate 32930Sstevel@tonic-gate /* 32940Sstevel@tonic-gate * We don't need options_mp in the IPv6 path. 32950Sstevel@tonic-gate */ 32960Sstevel@tonic-gate if (options_mp != NULL) { 32970Sstevel@tonic-gate freeb(options_mp); 32980Sstevel@tonic-gate options_mp = NULL; 32990Sstevel@tonic-gate } 33000Sstevel@tonic-gate 33010Sstevel@tonic-gate /* 33020Sstevel@tonic-gate * Discard message if it is smaller than the IPv6 header 33030Sstevel@tonic-gate * or if the header is malformed. 33040Sstevel@tonic-gate */ 33050Sstevel@tonic-gate if ((mp->b_wptr - rptr) < sizeof (ip6_t) || 33060Sstevel@tonic-gate IPH_HDR_VERSION((ipha_t *)rptr) != IPV6_VERSION || 33070Sstevel@tonic-gate icmp->icmp_family != AF_INET6) { 33080Sstevel@tonic-gate freemsg(mp); 33090Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipInErrors); 33100Sstevel@tonic-gate return; 33110Sstevel@tonic-gate } 33120Sstevel@tonic-gate 33130Sstevel@tonic-gate /* Initialize */ 33140Sstevel@tonic-gate ipp.ipp_fields = 0; 33151676Sjpk hopstrip = 0; 33160Sstevel@tonic-gate 33170Sstevel@tonic-gate ip6h = (ip6_t *)rptr; 33180Sstevel@tonic-gate /* 33190Sstevel@tonic-gate * Call on ip_find_hdr_v6 which gets the total hdr len 33200Sstevel@tonic-gate * as well as individual lenghts of ext hdrs (and ptrs to 33210Sstevel@tonic-gate * them). 33220Sstevel@tonic-gate */ 33230Sstevel@tonic-gate if (ip6h->ip6_nxt != icmp->icmp_proto) { 33240Sstevel@tonic-gate /* Look for ifindex information */ 33250Sstevel@tonic-gate if (ip6h->ip6_nxt == IPPROTO_RAW) { 33260Sstevel@tonic-gate ip6i = (ip6i_t *)ip6h; 33270Sstevel@tonic-gate if (ip6i->ip6i_flags & IP6I_IFINDEX) { 33280Sstevel@tonic-gate ASSERT(ip6i->ip6i_ifindex != 0); 33290Sstevel@tonic-gate ipp.ipp_fields |= IPPF_IFINDEX; 33300Sstevel@tonic-gate ipp.ipp_ifindex = ip6i->ip6i_ifindex; 33310Sstevel@tonic-gate } 33320Sstevel@tonic-gate rptr = (uchar_t *)&ip6i[1]; 33330Sstevel@tonic-gate mp->b_rptr = rptr; 33340Sstevel@tonic-gate if (rptr == mp->b_wptr) { 33350Sstevel@tonic-gate mp1 = mp->b_cont; 33360Sstevel@tonic-gate freeb(mp); 33370Sstevel@tonic-gate mp = mp1; 33380Sstevel@tonic-gate rptr = mp->b_rptr; 33390Sstevel@tonic-gate } 33400Sstevel@tonic-gate ASSERT(mp->b_wptr - rptr >= IPV6_HDR_LEN); 33410Sstevel@tonic-gate ip6h = (ip6_t *)rptr; 33420Sstevel@tonic-gate } 33430Sstevel@tonic-gate hdr_len = ip_find_hdr_v6(mp, ip6h, &ipp, &nexthdr); 33441676Sjpk 33451676Sjpk /* 33461676Sjpk * We need to lie a bit to the user because users inside 33471676Sjpk * labeled compartments should not see their own labels. We 33481676Sjpk * assume that in all other respects IP has checked the label, 33491676Sjpk * and that the label is always first among the options. (If 33501676Sjpk * it's not first, then this code won't see it, and the option 33511676Sjpk * will be passed along to the user.) 33521676Sjpk * 33531676Sjpk * If we had multilevel ICMP sockets, then the following code 33541676Sjpk * should be skipped for them to allow the user to see the 33551676Sjpk * label. 33561676Sjpk * 33571676Sjpk * Alignment restrictions in the definition of IP options 33581676Sjpk * (namely, the requirement that the 4-octet DOI goes on a 33591676Sjpk * 4-octet boundary) mean that we know exactly where the option 33601676Sjpk * should start, but we're lenient for other hosts. 33611676Sjpk * 33621676Sjpk * Note that there are no multilevel ICMP or raw IP sockets 33631676Sjpk * yet, thus nobody ever sees the IP6OPT_LS option. 33641676Sjpk */ 33651676Sjpk if ((ipp.ipp_fields & IPPF_HOPOPTS) && 33661676Sjpk ipp.ipp_hopoptslen > 5 && is_system_labeled()) { 33671676Sjpk const uchar_t *ucp = 33681676Sjpk (const uchar_t *)ipp.ipp_hopopts + 2; 33691676Sjpk int remlen = ipp.ipp_hopoptslen - 2; 33701676Sjpk 33711676Sjpk while (remlen > 0) { 33721676Sjpk if (*ucp == IP6OPT_PAD1) { 33731676Sjpk remlen--; 33741676Sjpk ucp++; 33751676Sjpk } else if (*ucp == IP6OPT_PADN) { 33761676Sjpk remlen -= ucp[1] + 2; 33771676Sjpk ucp += ucp[1] + 2; 33781676Sjpk } else if (*ucp == ip6opt_ls) { 33791676Sjpk hopstrip = (ucp - 33801676Sjpk (const uchar_t *)ipp.ipp_hopopts) + 33811676Sjpk ucp[1] + 2; 33821676Sjpk hopstrip = (hopstrip + 7) & ~7; 33831676Sjpk break; 33841676Sjpk } else { 33851676Sjpk /* label option must be first */ 33861676Sjpk break; 33871676Sjpk } 33881676Sjpk } 33891676Sjpk } 33900Sstevel@tonic-gate } else { 33910Sstevel@tonic-gate hdr_len = IPV6_HDR_LEN; 33920Sstevel@tonic-gate ip6i = NULL; 33930Sstevel@tonic-gate nexthdr = ip6h->ip6_nxt; 33940Sstevel@tonic-gate } 33950Sstevel@tonic-gate /* 33960Sstevel@tonic-gate * One special case where IP attaches the IRE needs to 33970Sstevel@tonic-gate * be handled so that we don't send up IRE to the user land. 33980Sstevel@tonic-gate */ 33990Sstevel@tonic-gate if (nexthdr == IPPROTO_TCP) { 34000Sstevel@tonic-gate tcph_t *tcph = (tcph_t *)&mp->b_rptr[hdr_len]; 34010Sstevel@tonic-gate 34020Sstevel@tonic-gate if (((tcph->th_flags[0] & (TH_SYN|TH_ACK)) == TH_SYN) && 34030Sstevel@tonic-gate mp->b_cont != NULL) { 34040Sstevel@tonic-gate mp1 = mp->b_cont; 34050Sstevel@tonic-gate if (mp1->b_datap->db_type == IRE_DB_TYPE) { 34060Sstevel@tonic-gate freeb(mp1); 34070Sstevel@tonic-gate mp->b_cont = NULL; 34080Sstevel@tonic-gate } 34090Sstevel@tonic-gate } 34100Sstevel@tonic-gate } 34110Sstevel@tonic-gate /* 34120Sstevel@tonic-gate * Check a filter for ICMPv6 types if needed. 34130Sstevel@tonic-gate * Verify raw checksums if needed. 34140Sstevel@tonic-gate */ 34150Sstevel@tonic-gate if (icmp->icmp_filter != NULL || icmp->icmp_raw_checksum) { 34160Sstevel@tonic-gate if (icmp->icmp_filter != NULL) { 34170Sstevel@tonic-gate int type; 34180Sstevel@tonic-gate 34190Sstevel@tonic-gate /* Assumes that IP has done the pullupmsg */ 34200Sstevel@tonic-gate type = mp->b_rptr[hdr_len]; 34210Sstevel@tonic-gate 34220Sstevel@tonic-gate ASSERT(mp->b_rptr + hdr_len <= mp->b_wptr); 34230Sstevel@tonic-gate if (ICMP6_FILTER_WILLBLOCK(type, icmp->icmp_filter)) { 34240Sstevel@tonic-gate freemsg(mp); 34250Sstevel@tonic-gate return; 34260Sstevel@tonic-gate } 34270Sstevel@tonic-gate } else { 34280Sstevel@tonic-gate /* Checksum */ 34290Sstevel@tonic-gate uint16_t *up; 34300Sstevel@tonic-gate uint32_t sum; 34310Sstevel@tonic-gate int remlen; 34320Sstevel@tonic-gate 34330Sstevel@tonic-gate up = (uint16_t *)&ip6h->ip6_src; 34340Sstevel@tonic-gate 34350Sstevel@tonic-gate remlen = msgdsize(mp) - hdr_len; 34360Sstevel@tonic-gate sum = htons(icmp->icmp_proto + remlen) 34370Sstevel@tonic-gate + up[0] + up[1] + up[2] + up[3] 34380Sstevel@tonic-gate + up[4] + up[5] + up[6] + up[7] 34390Sstevel@tonic-gate + up[8] + up[9] + up[10] + up[11] 34400Sstevel@tonic-gate + up[12] + up[13] + up[14] + up[15]; 34410Sstevel@tonic-gate sum = (sum & 0xffff) + (sum >> 16); 34420Sstevel@tonic-gate sum = IP_CSUM(mp, hdr_len, sum); 34430Sstevel@tonic-gate if (sum != 0) { 34440Sstevel@tonic-gate /* IPv6 RAW checksum failed */ 34450Sstevel@tonic-gate ip0dbg(("icmp_rput: RAW checksum " 34460Sstevel@tonic-gate "failed %x\n", sum)); 34470Sstevel@tonic-gate freemsg(mp); 34480Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipInCksumErrs); 34490Sstevel@tonic-gate return; 34500Sstevel@tonic-gate } 34510Sstevel@tonic-gate } 34520Sstevel@tonic-gate } 34530Sstevel@tonic-gate /* Skip all the IPv6 headers per API */ 34540Sstevel@tonic-gate mp->b_rptr += hdr_len; 34550Sstevel@tonic-gate 34560Sstevel@tonic-gate udi_size = sizeof (struct T_unitdata_ind) + sizeof (sin6_t); 34570Sstevel@tonic-gate 34580Sstevel@tonic-gate /* 34590Sstevel@tonic-gate * We use local variables icmp_opt and icmp_ipv6_recvhoplimit to 34600Sstevel@tonic-gate * maintain state information, instead of relying on icmp_t 34610Sstevel@tonic-gate * structure, since there arent any locks protecting these members 34620Sstevel@tonic-gate * and there is a window where there might be a race between a 34630Sstevel@tonic-gate * thread setting options on the write side and a thread reading 34640Sstevel@tonic-gate * these options on the read size. 34650Sstevel@tonic-gate */ 34660Sstevel@tonic-gate if (ipp.ipp_fields & (IPPF_HOPOPTS|IPPF_DSTOPTS|IPPF_RTDSTOPTS| 34670Sstevel@tonic-gate IPPF_RTHDR|IPPF_IFINDEX)) { 34680Sstevel@tonic-gate if (icmp->icmp_ipv6_recvhopopts && 34691676Sjpk (ipp.ipp_fields & IPPF_HOPOPTS) && 34701676Sjpk ipp.ipp_hopoptslen > hopstrip) { 34710Sstevel@tonic-gate udi_size += sizeof (struct T_opthdr) + 34721676Sjpk ipp.ipp_hopoptslen - hopstrip; 34730Sstevel@tonic-gate icmp_opt |= IPPF_HOPOPTS; 34740Sstevel@tonic-gate } 34750Sstevel@tonic-gate if ((icmp->icmp_ipv6_recvdstopts || 34760Sstevel@tonic-gate icmp->icmp_old_ipv6_recvdstopts) && 34770Sstevel@tonic-gate (ipp.ipp_fields & IPPF_DSTOPTS)) { 34780Sstevel@tonic-gate udi_size += sizeof (struct T_opthdr) + 34790Sstevel@tonic-gate ipp.ipp_dstoptslen; 34800Sstevel@tonic-gate icmp_opt |= IPPF_DSTOPTS; 34810Sstevel@tonic-gate } 34820Sstevel@tonic-gate if (((icmp->icmp_ipv6_recvdstopts && 34830Sstevel@tonic-gate icmp->icmp_ipv6_recvrthdr && 34840Sstevel@tonic-gate (ipp.ipp_fields & IPPF_RTHDR)) || 34850Sstevel@tonic-gate icmp->icmp_ipv6_recvrtdstopts) && 34860Sstevel@tonic-gate (ipp.ipp_fields & IPPF_RTDSTOPTS)) { 34870Sstevel@tonic-gate udi_size += sizeof (struct T_opthdr) + 34880Sstevel@tonic-gate ipp.ipp_rtdstoptslen; 34890Sstevel@tonic-gate icmp_opt |= IPPF_RTDSTOPTS; 34900Sstevel@tonic-gate } 34910Sstevel@tonic-gate if (icmp->icmp_ipv6_recvrthdr && 34920Sstevel@tonic-gate (ipp.ipp_fields & IPPF_RTHDR)) { 34930Sstevel@tonic-gate udi_size += sizeof (struct T_opthdr) + 34940Sstevel@tonic-gate ipp.ipp_rthdrlen; 34950Sstevel@tonic-gate icmp_opt |= IPPF_RTHDR; 34960Sstevel@tonic-gate } 3497*3318Srshoaib if (icmp->icmp_ip_recvpktinfo && 34980Sstevel@tonic-gate (ipp.ipp_fields & IPPF_IFINDEX)) { 34990Sstevel@tonic-gate udi_size += sizeof (struct T_opthdr) + 35000Sstevel@tonic-gate sizeof (struct in6_pktinfo); 35010Sstevel@tonic-gate icmp_opt |= IPPF_IFINDEX; 35020Sstevel@tonic-gate } 35030Sstevel@tonic-gate } 35040Sstevel@tonic-gate if (icmp->icmp_ipv6_recvhoplimit) { 35050Sstevel@tonic-gate udi_size += sizeof (struct T_opthdr) + sizeof (int); 35060Sstevel@tonic-gate icmp_ipv6_recvhoplimit = B_TRUE; 35070Sstevel@tonic-gate } 35080Sstevel@tonic-gate 35090Sstevel@tonic-gate if (icmp->icmp_ipv6_recvtclass) 35100Sstevel@tonic-gate udi_size += sizeof (struct T_opthdr) + sizeof (int); 35110Sstevel@tonic-gate 35120Sstevel@tonic-gate mp1 = allocb(udi_size, BPRI_MED); 35130Sstevel@tonic-gate if (mp1 == NULL) { 35140Sstevel@tonic-gate freemsg(mp); 35150Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipInErrors); 35160Sstevel@tonic-gate return; 35170Sstevel@tonic-gate } 35180Sstevel@tonic-gate mp1->b_cont = mp; 35190Sstevel@tonic-gate mp = mp1; 35200Sstevel@tonic-gate mp->b_datap->db_type = M_PROTO; 35210Sstevel@tonic-gate tudi = (struct T_unitdata_ind *)mp->b_rptr; 35220Sstevel@tonic-gate mp->b_wptr = (uchar_t *)tudi + udi_size; 35230Sstevel@tonic-gate tudi->PRIM_type = T_UNITDATA_IND; 35240Sstevel@tonic-gate tudi->SRC_length = sizeof (sin6_t); 35250Sstevel@tonic-gate tudi->SRC_offset = sizeof (struct T_unitdata_ind); 35260Sstevel@tonic-gate tudi->OPT_offset = sizeof (struct T_unitdata_ind) + sizeof (sin6_t); 35270Sstevel@tonic-gate udi_size -= (sizeof (struct T_unitdata_ind) + sizeof (sin6_t)); 35280Sstevel@tonic-gate tudi->OPT_length = udi_size; 35290Sstevel@tonic-gate sin6 = (sin6_t *)&tudi[1]; 35300Sstevel@tonic-gate sin6->sin6_port = 0; 35310Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 35320Sstevel@tonic-gate 35330Sstevel@tonic-gate sin6->sin6_addr = ip6h->ip6_src; 35340Sstevel@tonic-gate /* No sin6_flowinfo per API */ 35350Sstevel@tonic-gate sin6->sin6_flowinfo = 0; 35360Sstevel@tonic-gate /* For link-scope source pass up scope id */ 35370Sstevel@tonic-gate if ((ipp.ipp_fields & IPPF_IFINDEX) && 35380Sstevel@tonic-gate IN6_IS_ADDR_LINKSCOPE(&ip6h->ip6_src)) 35390Sstevel@tonic-gate sin6->sin6_scope_id = ipp.ipp_ifindex; 35400Sstevel@tonic-gate else 35410Sstevel@tonic-gate sin6->sin6_scope_id = 0; 35420Sstevel@tonic-gate 35430Sstevel@tonic-gate sin6->__sin6_src_id = ip_srcid_find_addr(&ip6h->ip6_dst, 35440Sstevel@tonic-gate icmp->icmp_zoneid); 35450Sstevel@tonic-gate 35460Sstevel@tonic-gate if (udi_size != 0) { 35470Sstevel@tonic-gate uchar_t *dstopt; 35480Sstevel@tonic-gate 35490Sstevel@tonic-gate dstopt = (uchar_t *)&sin6[1]; 35500Sstevel@tonic-gate if (icmp_opt & IPPF_IFINDEX) { 35510Sstevel@tonic-gate struct T_opthdr *toh; 35520Sstevel@tonic-gate struct in6_pktinfo *pkti; 35530Sstevel@tonic-gate 35540Sstevel@tonic-gate toh = (struct T_opthdr *)dstopt; 35550Sstevel@tonic-gate toh->level = IPPROTO_IPV6; 35560Sstevel@tonic-gate toh->name = IPV6_PKTINFO; 35570Sstevel@tonic-gate toh->len = sizeof (struct T_opthdr) + 35580Sstevel@tonic-gate sizeof (*pkti); 35590Sstevel@tonic-gate toh->status = 0; 35600Sstevel@tonic-gate dstopt += sizeof (struct T_opthdr); 35610Sstevel@tonic-gate pkti = (struct in6_pktinfo *)dstopt; 35620Sstevel@tonic-gate pkti->ipi6_addr = ip6h->ip6_dst; 35630Sstevel@tonic-gate pkti->ipi6_ifindex = ipp.ipp_ifindex; 35640Sstevel@tonic-gate dstopt += sizeof (*pkti); 35650Sstevel@tonic-gate udi_size -= toh->len; 35660Sstevel@tonic-gate } 35670Sstevel@tonic-gate if (icmp_ipv6_recvhoplimit) { 35680Sstevel@tonic-gate struct T_opthdr *toh; 35690Sstevel@tonic-gate 35700Sstevel@tonic-gate toh = (struct T_opthdr *)dstopt; 35710Sstevel@tonic-gate toh->level = IPPROTO_IPV6; 35720Sstevel@tonic-gate toh->name = IPV6_HOPLIMIT; 35730Sstevel@tonic-gate toh->len = sizeof (struct T_opthdr) + 35740Sstevel@tonic-gate sizeof (uint_t); 35750Sstevel@tonic-gate toh->status = 0; 35760Sstevel@tonic-gate dstopt += sizeof (struct T_opthdr); 35770Sstevel@tonic-gate *(uint_t *)dstopt = ip6h->ip6_hops; 35780Sstevel@tonic-gate dstopt += sizeof (uint_t); 35790Sstevel@tonic-gate udi_size -= toh->len; 35800Sstevel@tonic-gate } 35810Sstevel@tonic-gate if (icmp->icmp_ipv6_recvtclass) { 35820Sstevel@tonic-gate struct T_opthdr *toh; 35830Sstevel@tonic-gate 35840Sstevel@tonic-gate toh = (struct T_opthdr *)dstopt; 35850Sstevel@tonic-gate toh->level = IPPROTO_IPV6; 35860Sstevel@tonic-gate toh->name = IPV6_TCLASS; 35870Sstevel@tonic-gate toh->len = sizeof (struct T_opthdr) + 35880Sstevel@tonic-gate sizeof (uint_t); 35890Sstevel@tonic-gate toh->status = 0; 35900Sstevel@tonic-gate dstopt += sizeof (struct T_opthdr); 35910Sstevel@tonic-gate *(uint_t *)dstopt = IPV6_FLOW_TCLASS(ip6h->ip6_flow); 35920Sstevel@tonic-gate dstopt += sizeof (uint_t); 35930Sstevel@tonic-gate udi_size -= toh->len; 35940Sstevel@tonic-gate } 35950Sstevel@tonic-gate if (icmp_opt & IPPF_HOPOPTS) { 35960Sstevel@tonic-gate struct T_opthdr *toh; 35970Sstevel@tonic-gate 35980Sstevel@tonic-gate toh = (struct T_opthdr *)dstopt; 35990Sstevel@tonic-gate toh->level = IPPROTO_IPV6; 36000Sstevel@tonic-gate toh->name = IPV6_HOPOPTS; 36010Sstevel@tonic-gate toh->len = sizeof (struct T_opthdr) + 36021676Sjpk ipp.ipp_hopoptslen - hopstrip; 36030Sstevel@tonic-gate toh->status = 0; 36040Sstevel@tonic-gate dstopt += sizeof (struct T_opthdr); 36051676Sjpk bcopy((char *)ipp.ipp_hopopts + hopstrip, dstopt, 36061676Sjpk ipp.ipp_hopoptslen - hopstrip); 36071676Sjpk if (hopstrip > 0) { 36081676Sjpk /* copy next header value and fake length */ 36091676Sjpk dstopt[0] = ((uchar_t *)ipp.ipp_hopopts)[0]; 36101676Sjpk dstopt[1] = ((uchar_t *)ipp.ipp_hopopts)[1] - 36111676Sjpk hopstrip / 8; 36121676Sjpk } 36131676Sjpk dstopt += ipp.ipp_hopoptslen - hopstrip; 36140Sstevel@tonic-gate udi_size -= toh->len; 36150Sstevel@tonic-gate } 36160Sstevel@tonic-gate if (icmp_opt & IPPF_RTDSTOPTS) { 36170Sstevel@tonic-gate struct T_opthdr *toh; 36180Sstevel@tonic-gate 36190Sstevel@tonic-gate toh = (struct T_opthdr *)dstopt; 36200Sstevel@tonic-gate toh->level = IPPROTO_IPV6; 36210Sstevel@tonic-gate toh->name = IPV6_DSTOPTS; 36220Sstevel@tonic-gate toh->len = sizeof (struct T_opthdr) + 36230Sstevel@tonic-gate ipp.ipp_rtdstoptslen; 36240Sstevel@tonic-gate toh->status = 0; 36250Sstevel@tonic-gate dstopt += sizeof (struct T_opthdr); 36260Sstevel@tonic-gate bcopy(ipp.ipp_rtdstopts, dstopt, 36270Sstevel@tonic-gate ipp.ipp_rtdstoptslen); 36280Sstevel@tonic-gate dstopt += ipp.ipp_rtdstoptslen; 36290Sstevel@tonic-gate udi_size -= toh->len; 36300Sstevel@tonic-gate } 36310Sstevel@tonic-gate if (icmp_opt & IPPF_RTHDR) { 36320Sstevel@tonic-gate struct T_opthdr *toh; 36330Sstevel@tonic-gate 36340Sstevel@tonic-gate toh = (struct T_opthdr *)dstopt; 36350Sstevel@tonic-gate toh->level = IPPROTO_IPV6; 36360Sstevel@tonic-gate toh->name = IPV6_RTHDR; 36370Sstevel@tonic-gate toh->len = sizeof (struct T_opthdr) + 36380Sstevel@tonic-gate ipp.ipp_rthdrlen; 36390Sstevel@tonic-gate toh->status = 0; 36400Sstevel@tonic-gate dstopt += sizeof (struct T_opthdr); 36410Sstevel@tonic-gate bcopy(ipp.ipp_rthdr, dstopt, ipp.ipp_rthdrlen); 36420Sstevel@tonic-gate dstopt += ipp.ipp_rthdrlen; 36430Sstevel@tonic-gate udi_size -= toh->len; 36440Sstevel@tonic-gate } 36450Sstevel@tonic-gate if (icmp_opt & IPPF_DSTOPTS) { 36460Sstevel@tonic-gate struct T_opthdr *toh; 36470Sstevel@tonic-gate 36480Sstevel@tonic-gate toh = (struct T_opthdr *)dstopt; 36490Sstevel@tonic-gate toh->level = IPPROTO_IPV6; 36500Sstevel@tonic-gate toh->name = IPV6_DSTOPTS; 36510Sstevel@tonic-gate toh->len = sizeof (struct T_opthdr) + 36520Sstevel@tonic-gate ipp.ipp_dstoptslen; 36530Sstevel@tonic-gate toh->status = 0; 36540Sstevel@tonic-gate dstopt += sizeof (struct T_opthdr); 36550Sstevel@tonic-gate bcopy(ipp.ipp_dstopts, dstopt, 36560Sstevel@tonic-gate ipp.ipp_dstoptslen); 36570Sstevel@tonic-gate dstopt += ipp.ipp_dstoptslen; 36580Sstevel@tonic-gate udi_size -= toh->len; 36590Sstevel@tonic-gate } 36600Sstevel@tonic-gate /* Consumed all of allocated space */ 36610Sstevel@tonic-gate ASSERT(udi_size == 0); 36620Sstevel@tonic-gate } 36630Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipInDatagrams); 36640Sstevel@tonic-gate putnext(q, mp); 36650Sstevel@tonic-gate } 36660Sstevel@tonic-gate 36670Sstevel@tonic-gate /* 36680Sstevel@tonic-gate * Process a T_BIND_ACK 36690Sstevel@tonic-gate */ 36700Sstevel@tonic-gate static void 36710Sstevel@tonic-gate icmp_rput_bind_ack(queue_t *q, mblk_t *mp) 36720Sstevel@tonic-gate { 36730Sstevel@tonic-gate icmp_t *icmp = (icmp_t *)q->q_ptr; 36740Sstevel@tonic-gate mblk_t *mp1; 36750Sstevel@tonic-gate ire_t *ire; 36760Sstevel@tonic-gate struct T_bind_ack *tba; 36770Sstevel@tonic-gate uchar_t *addrp; 36780Sstevel@tonic-gate ipa_conn_t *ac; 36790Sstevel@tonic-gate ipa6_conn_t *ac6; 36800Sstevel@tonic-gate 36810Sstevel@tonic-gate /* 36820Sstevel@tonic-gate * We know if headers are included or not so we can 36830Sstevel@tonic-gate * safely do this. 36840Sstevel@tonic-gate */ 36850Sstevel@tonic-gate if (icmp->icmp_state == TS_UNBND) { 36860Sstevel@tonic-gate /* 36870Sstevel@tonic-gate * TPI has not yet bound - bind sent by 36880Sstevel@tonic-gate * icmp_bind_proto. 36890Sstevel@tonic-gate */ 36900Sstevel@tonic-gate freemsg(mp); 36910Sstevel@tonic-gate return; 36920Sstevel@tonic-gate } 36930Sstevel@tonic-gate if (icmp->icmp_discon_pending) 36940Sstevel@tonic-gate icmp->icmp_discon_pending = 0; 36950Sstevel@tonic-gate 36960Sstevel@tonic-gate /* 36970Sstevel@tonic-gate * If a broadcast/multicast address was bound set 36980Sstevel@tonic-gate * the source address to 0. 36990Sstevel@tonic-gate * This ensures no datagrams with broadcast address 37000Sstevel@tonic-gate * as source address are emitted (which would violate 37010Sstevel@tonic-gate * RFC1122 - Hosts requirements) 37020Sstevel@tonic-gate * 37030Sstevel@tonic-gate * Note that when connecting the returned IRE is 37040Sstevel@tonic-gate * for the destination address and we only perform 37050Sstevel@tonic-gate * the broadcast check for the source address (it 37060Sstevel@tonic-gate * is OK to connect to a broadcast/multicast address.) 37070Sstevel@tonic-gate */ 37080Sstevel@tonic-gate mp1 = mp->b_cont; 37090Sstevel@tonic-gate if (mp1 != NULL && mp1->b_datap->db_type == IRE_DB_TYPE) { 37100Sstevel@tonic-gate ire = (ire_t *)mp1->b_rptr; 37110Sstevel@tonic-gate 37120Sstevel@tonic-gate /* 37130Sstevel@tonic-gate * Note: we get IRE_BROADCAST for IPv6 to "mark" a multicast 37140Sstevel@tonic-gate * local address. 37150Sstevel@tonic-gate */ 37160Sstevel@tonic-gate if (ire->ire_type == IRE_BROADCAST && 37170Sstevel@tonic-gate icmp->icmp_state != TS_DATA_XFER) { 37180Sstevel@tonic-gate /* This was just a local bind to a MC/broadcast addr */ 37190Sstevel@tonic-gate V6_SET_ZERO(icmp->icmp_v6src); 37200Sstevel@tonic-gate if (icmp->icmp_family == AF_INET6) 37210Sstevel@tonic-gate (void) icmp_build_hdrs(q, icmp); 37220Sstevel@tonic-gate } else if (V6_OR_V4_INADDR_ANY(icmp->icmp_v6src)) { 37230Sstevel@tonic-gate /* 37240Sstevel@tonic-gate * Local address not yet set - pick it from the 37250Sstevel@tonic-gate * T_bind_ack 37260Sstevel@tonic-gate */ 37270Sstevel@tonic-gate tba = (struct T_bind_ack *)mp->b_rptr; 37280Sstevel@tonic-gate addrp = &mp->b_rptr[tba->ADDR_offset]; 37290Sstevel@tonic-gate switch (icmp->icmp_family) { 37300Sstevel@tonic-gate case AF_INET: 37310Sstevel@tonic-gate if (tba->ADDR_length == sizeof (ipa_conn_t)) { 37320Sstevel@tonic-gate ac = (ipa_conn_t *)addrp; 37330Sstevel@tonic-gate } else { 37340Sstevel@tonic-gate ASSERT(tba->ADDR_length == 37350Sstevel@tonic-gate sizeof (ipa_conn_x_t)); 37360Sstevel@tonic-gate ac = &((ipa_conn_x_t *)addrp)->acx_conn; 37370Sstevel@tonic-gate } 37380Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(ac->ac_laddr, 37390Sstevel@tonic-gate &icmp->icmp_v6src); 37400Sstevel@tonic-gate break; 37410Sstevel@tonic-gate case AF_INET6: 37420Sstevel@tonic-gate if (tba->ADDR_length == sizeof (ipa6_conn_t)) { 37430Sstevel@tonic-gate ac6 = (ipa6_conn_t *)addrp; 37440Sstevel@tonic-gate } else { 37450Sstevel@tonic-gate ASSERT(tba->ADDR_length == 37460Sstevel@tonic-gate sizeof (ipa6_conn_x_t)); 37470Sstevel@tonic-gate ac6 = &((ipa6_conn_x_t *) 37480Sstevel@tonic-gate addrp)->ac6x_conn; 37490Sstevel@tonic-gate } 37500Sstevel@tonic-gate icmp->icmp_v6src = ac6->ac6_laddr; 37510Sstevel@tonic-gate (void) icmp_build_hdrs(q, icmp); 37520Sstevel@tonic-gate } 37530Sstevel@tonic-gate } 37540Sstevel@tonic-gate mp1 = mp1->b_cont; 37550Sstevel@tonic-gate } 37560Sstevel@tonic-gate /* 37570Sstevel@tonic-gate * Look for one or more appended ACK message added by 37580Sstevel@tonic-gate * icmp_connect or icmp_disconnect. 37590Sstevel@tonic-gate * If none found just send up the T_BIND_ACK. 37600Sstevel@tonic-gate * icmp_connect has appended a T_OK_ACK and a 37610Sstevel@tonic-gate * T_CONN_CON. 37620Sstevel@tonic-gate * icmp_disconnect has appended a T_OK_ACK. 37630Sstevel@tonic-gate */ 37640Sstevel@tonic-gate if (mp1 != NULL) { 37650Sstevel@tonic-gate if (mp->b_cont == mp1) 37660Sstevel@tonic-gate mp->b_cont = NULL; 37670Sstevel@tonic-gate else { 37680Sstevel@tonic-gate ASSERT(mp->b_cont->b_cont == mp1); 37690Sstevel@tonic-gate mp->b_cont->b_cont = NULL; 37700Sstevel@tonic-gate } 37710Sstevel@tonic-gate freemsg(mp); 37720Sstevel@tonic-gate mp = mp1; 37730Sstevel@tonic-gate while (mp != NULL) { 37740Sstevel@tonic-gate mp1 = mp->b_cont; 37750Sstevel@tonic-gate mp->b_cont = NULL; 37760Sstevel@tonic-gate putnext(q, mp); 37770Sstevel@tonic-gate mp = mp1; 37780Sstevel@tonic-gate } 37790Sstevel@tonic-gate return; 37800Sstevel@tonic-gate } 37810Sstevel@tonic-gate freemsg(mp->b_cont); 37820Sstevel@tonic-gate mp->b_cont = NULL; 37830Sstevel@tonic-gate putnext(q, mp); 37840Sstevel@tonic-gate } 37850Sstevel@tonic-gate 37860Sstevel@tonic-gate /* 37870Sstevel@tonic-gate * return SNMP stuff in buffer in mpdata 37880Sstevel@tonic-gate */ 37890Sstevel@tonic-gate static int 37900Sstevel@tonic-gate icmp_snmp_get(queue_t *q, mblk_t *mpctl) 37910Sstevel@tonic-gate { 37920Sstevel@tonic-gate mblk_t *mpdata; 37930Sstevel@tonic-gate struct opthdr *optp; 37940Sstevel@tonic-gate 37950Sstevel@tonic-gate if (mpctl == NULL || 37960Sstevel@tonic-gate (mpdata = mpctl->b_cont) == NULL) { 37970Sstevel@tonic-gate return (0); 37980Sstevel@tonic-gate } 37990Sstevel@tonic-gate 38000Sstevel@tonic-gate /* fixed length structure for IPv4 and IPv6 counters */ 38010Sstevel@tonic-gate optp = (struct opthdr *)&mpctl->b_rptr[sizeof (struct T_optmgmt_ack)]; 38020Sstevel@tonic-gate optp->level = EXPER_RAWIP; 38030Sstevel@tonic-gate optp->name = 0; 38040Sstevel@tonic-gate (void) snmp_append_data(mpdata, (char *)&rawip_mib, sizeof (rawip_mib)); 38050Sstevel@tonic-gate optp->len = msgdsize(mpdata); 38060Sstevel@tonic-gate qreply(q, mpctl); 38070Sstevel@tonic-gate 38080Sstevel@tonic-gate return (1); 38090Sstevel@tonic-gate } 38100Sstevel@tonic-gate 38110Sstevel@tonic-gate /* 38120Sstevel@tonic-gate * Return 0 if invalid set request, 1 otherwise, including non-rawip requests. 38130Sstevel@tonic-gate * TODO: If this ever actually tries to set anything, it needs to be 38140Sstevel@tonic-gate * to do the appropriate locking. 38150Sstevel@tonic-gate */ 38160Sstevel@tonic-gate /* ARGSUSED */ 38170Sstevel@tonic-gate static int 38180Sstevel@tonic-gate icmp_snmp_set(queue_t *q, t_scalar_t level, t_scalar_t name, 38190Sstevel@tonic-gate uchar_t *ptr, int len) 38200Sstevel@tonic-gate { 38210Sstevel@tonic-gate switch (level) { 38220Sstevel@tonic-gate case EXPER_RAWIP: 38230Sstevel@tonic-gate return (0); 38240Sstevel@tonic-gate default: 38250Sstevel@tonic-gate return (1); 38260Sstevel@tonic-gate } 38270Sstevel@tonic-gate } 38280Sstevel@tonic-gate 38290Sstevel@tonic-gate /* Report for ndd "icmp_status" */ 38300Sstevel@tonic-gate /* ARGSUSED */ 38310Sstevel@tonic-gate static int 38320Sstevel@tonic-gate icmp_status_report(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr) 38330Sstevel@tonic-gate { 38340Sstevel@tonic-gate IDP idp; 38350Sstevel@tonic-gate icmp_t *icmp; 38360Sstevel@tonic-gate char *state; 38370Sstevel@tonic-gate char laddrbuf[INET6_ADDRSTRLEN]; 38380Sstevel@tonic-gate char faddrbuf[INET6_ADDRSTRLEN]; 38390Sstevel@tonic-gate 38400Sstevel@tonic-gate (void) mi_mpprintf(mp, 38410Sstevel@tonic-gate "RAWIP " MI_COL_HDRPAD_STR 38420Sstevel@tonic-gate /* 01234567[89ABCDEF] */ 38430Sstevel@tonic-gate " src addr dest addr state"); 38440Sstevel@tonic-gate /* xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx UNBOUND */ 38450Sstevel@tonic-gate 38460Sstevel@tonic-gate 38470Sstevel@tonic-gate for (idp = mi_first_ptr(&icmp_g_head); 38480Sstevel@tonic-gate (icmp = (icmp_t *)idp) != NULL; 38490Sstevel@tonic-gate idp = mi_next_ptr(&icmp_g_head, idp)) { 38500Sstevel@tonic-gate if (icmp->icmp_state == TS_UNBND) 38510Sstevel@tonic-gate state = "UNBOUND"; 38520Sstevel@tonic-gate else if (icmp->icmp_state == TS_IDLE) 38530Sstevel@tonic-gate state = "IDLE"; 38540Sstevel@tonic-gate else if (icmp->icmp_state == TS_DATA_XFER) 38550Sstevel@tonic-gate state = "CONNECTED"; 38560Sstevel@tonic-gate else 38570Sstevel@tonic-gate state = "UnkState"; 38580Sstevel@tonic-gate 38590Sstevel@tonic-gate (void) mi_mpprintf(mp, 38600Sstevel@tonic-gate MI_COL_PTRFMT_STR "%s %s %s", 38610Sstevel@tonic-gate (void *)icmp, 38620Sstevel@tonic-gate inet_ntop(AF_INET6, &icmp->icmp_v6dst, faddrbuf, 38630Sstevel@tonic-gate sizeof (faddrbuf)), 38640Sstevel@tonic-gate inet_ntop(AF_INET6, &icmp->icmp_v6src, laddrbuf, 38650Sstevel@tonic-gate sizeof (laddrbuf)), 38660Sstevel@tonic-gate state); 38670Sstevel@tonic-gate } 38680Sstevel@tonic-gate return (0); 38690Sstevel@tonic-gate } 38700Sstevel@tonic-gate 38710Sstevel@tonic-gate /* 38720Sstevel@tonic-gate * This routine creates a T_UDERROR_IND message and passes it upstream. 38730Sstevel@tonic-gate * The address and options are copied from the T_UNITDATA_REQ message 38740Sstevel@tonic-gate * passed in mp. This message is freed. 38750Sstevel@tonic-gate */ 38760Sstevel@tonic-gate static void 38770Sstevel@tonic-gate icmp_ud_err(queue_t *q, mblk_t *mp, t_scalar_t err) 38780Sstevel@tonic-gate { 38790Sstevel@tonic-gate mblk_t *mp1; 38800Sstevel@tonic-gate uchar_t *rptr = mp->b_rptr; 38810Sstevel@tonic-gate struct T_unitdata_req *tudr = (struct T_unitdata_req *)rptr; 38820Sstevel@tonic-gate 38830Sstevel@tonic-gate mp1 = mi_tpi_uderror_ind((char *)&rptr[tudr->DEST_offset], 38840Sstevel@tonic-gate tudr->DEST_length, (char *)&rptr[tudr->OPT_offset], 38850Sstevel@tonic-gate tudr->OPT_length, err); 38860Sstevel@tonic-gate if (mp1) 38870Sstevel@tonic-gate qreply(q, mp1); 38880Sstevel@tonic-gate freemsg(mp); 38890Sstevel@tonic-gate } 38900Sstevel@tonic-gate 38910Sstevel@tonic-gate /* 38920Sstevel@tonic-gate * This routine is called by icmp_wput to handle T_UNBIND_REQ messages. 38930Sstevel@tonic-gate * After some error checking, the message is passed downstream to ip. 38940Sstevel@tonic-gate */ 38950Sstevel@tonic-gate static void 38960Sstevel@tonic-gate icmp_unbind(queue_t *q, mblk_t *mp) 38970Sstevel@tonic-gate { 38980Sstevel@tonic-gate icmp_t *icmp = (icmp_t *)q->q_ptr; 38990Sstevel@tonic-gate 39000Sstevel@tonic-gate /* If a bind has not been done, we can't unbind. */ 39010Sstevel@tonic-gate if (icmp->icmp_state == TS_UNBND) { 39020Sstevel@tonic-gate icmp_err_ack(q, mp, TOUTSTATE, 0); 39030Sstevel@tonic-gate return; 39040Sstevel@tonic-gate } 39050Sstevel@tonic-gate V6_SET_ZERO(icmp->icmp_v6src); 39060Sstevel@tonic-gate V6_SET_ZERO(icmp->icmp_bound_v6src); 39070Sstevel@tonic-gate icmp->icmp_state = TS_UNBND; 39080Sstevel@tonic-gate 39090Sstevel@tonic-gate if (icmp->icmp_family == AF_INET6) { 39100Sstevel@tonic-gate int error; 39110Sstevel@tonic-gate 39120Sstevel@tonic-gate /* Rebuild the header template */ 39130Sstevel@tonic-gate error = icmp_build_hdrs(q, icmp); 39140Sstevel@tonic-gate if (error != 0) { 39150Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, error); 39160Sstevel@tonic-gate return; 39170Sstevel@tonic-gate } 39180Sstevel@tonic-gate } 39190Sstevel@tonic-gate /* Pass the unbind to IP. */ 39200Sstevel@tonic-gate putnext(q, mp); 39210Sstevel@tonic-gate } 39220Sstevel@tonic-gate 39230Sstevel@tonic-gate /* 39240Sstevel@tonic-gate * Process IPv4 packets that already include an IP header. 39250Sstevel@tonic-gate * Used when IP_HDRINCL has been set (implicit for IPPROTO_RAW and 39260Sstevel@tonic-gate * IPPROTO_IGMP). 39270Sstevel@tonic-gate */ 39280Sstevel@tonic-gate static void 3929*3318Srshoaib icmp_wput_hdrincl(queue_t *q, mblk_t *mp, icmp_t *icmp, ip4_pkt_t *pktinfop, 3930*3318Srshoaib boolean_t use_putnext) 39310Sstevel@tonic-gate { 39320Sstevel@tonic-gate ipha_t *ipha; 39330Sstevel@tonic-gate int ip_hdr_length; 39340Sstevel@tonic-gate int tp_hdr_len; 39350Sstevel@tonic-gate mblk_t *mp1; 39360Sstevel@tonic-gate uint_t pkt_len; 3937*3318Srshoaib ip_opt_info_t optinfo; 3938*3318Srshoaib 3939*3318Srshoaib optinfo.ip_opt_flags = 0; 3940*3318Srshoaib optinfo.ip_opt_ill_index = 0; 39410Sstevel@tonic-gate ipha = (ipha_t *)mp->b_rptr; 39420Sstevel@tonic-gate ip_hdr_length = IP_SIMPLE_HDR_LENGTH + icmp->icmp_ip_snd_options_len; 39430Sstevel@tonic-gate if ((mp->b_wptr - mp->b_rptr) < IP_SIMPLE_HDR_LENGTH) { 39440Sstevel@tonic-gate if (!pullupmsg(mp, IP_SIMPLE_HDR_LENGTH)) { 39450Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 39460Sstevel@tonic-gate freemsg(mp); 39470Sstevel@tonic-gate return; 39480Sstevel@tonic-gate } 39490Sstevel@tonic-gate ipha = (ipha_t *)mp->b_rptr; 39500Sstevel@tonic-gate } 39510Sstevel@tonic-gate ipha->ipha_version_and_hdr_length = 39520Sstevel@tonic-gate (IP_VERSION<<4) | (ip_hdr_length>>2); 39530Sstevel@tonic-gate 39540Sstevel@tonic-gate /* 39550Sstevel@tonic-gate * For the socket of SOCK_RAW type, the checksum is provided in the 39560Sstevel@tonic-gate * pre-built packet. We set the ipha_ident field to IP_HDR_INCLUDED to 39570Sstevel@tonic-gate * tell IP that the application has sent a complete IP header and not 39580Sstevel@tonic-gate * to compute the transport checksum nor change the DF flag. 39590Sstevel@tonic-gate */ 39600Sstevel@tonic-gate ipha->ipha_ident = IP_HDR_INCLUDED; 39610Sstevel@tonic-gate ipha->ipha_hdr_checksum = 0; 39620Sstevel@tonic-gate ipha->ipha_fragment_offset_and_flags &= htons(IPH_DF); 39630Sstevel@tonic-gate /* Insert options if any */ 39640Sstevel@tonic-gate if (ip_hdr_length > IP_SIMPLE_HDR_LENGTH) { 39650Sstevel@tonic-gate /* 39660Sstevel@tonic-gate * Put the IP header plus any transport header that is 39670Sstevel@tonic-gate * checksumed by ip_wput into the first mblk. (ip_wput assumes 39680Sstevel@tonic-gate * that at least the checksum field is in the first mblk.) 39690Sstevel@tonic-gate */ 39700Sstevel@tonic-gate switch (ipha->ipha_protocol) { 39710Sstevel@tonic-gate case IPPROTO_UDP: 39720Sstevel@tonic-gate tp_hdr_len = 8; 39730Sstevel@tonic-gate break; 39740Sstevel@tonic-gate case IPPROTO_TCP: 39750Sstevel@tonic-gate tp_hdr_len = 20; 39760Sstevel@tonic-gate break; 39770Sstevel@tonic-gate default: 39780Sstevel@tonic-gate tp_hdr_len = 0; 39790Sstevel@tonic-gate break; 39800Sstevel@tonic-gate } 39810Sstevel@tonic-gate /* 39820Sstevel@tonic-gate * The code below assumes that IP_SIMPLE_HDR_LENGTH plus 39830Sstevel@tonic-gate * tp_hdr_len bytes will be in a single mblk. 39840Sstevel@tonic-gate */ 39850Sstevel@tonic-gate if ((mp->b_wptr - mp->b_rptr) < (IP_SIMPLE_HDR_LENGTH + 39860Sstevel@tonic-gate tp_hdr_len)) { 39870Sstevel@tonic-gate if (!pullupmsg(mp, IP_SIMPLE_HDR_LENGTH + 39880Sstevel@tonic-gate tp_hdr_len)) { 39890Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 39900Sstevel@tonic-gate freemsg(mp); 39910Sstevel@tonic-gate return; 39920Sstevel@tonic-gate } 39930Sstevel@tonic-gate ipha = (ipha_t *)mp->b_rptr; 39940Sstevel@tonic-gate } 39950Sstevel@tonic-gate 39960Sstevel@tonic-gate /* 39970Sstevel@tonic-gate * if the length is larger then the max allowed IP packet, 39980Sstevel@tonic-gate * then send an error and abort the processing. 39990Sstevel@tonic-gate */ 40000Sstevel@tonic-gate pkt_len = ntohs(ipha->ipha_length) 40010Sstevel@tonic-gate + icmp->icmp_ip_snd_options_len; 40020Sstevel@tonic-gate if (pkt_len > IP_MAXPACKET) { 40030Sstevel@tonic-gate icmp_ud_err(q, mp, EMSGSIZE); 40040Sstevel@tonic-gate return; 40050Sstevel@tonic-gate } 40060Sstevel@tonic-gate if (!(mp1 = allocb(ip_hdr_length + icmp_wroff_extra + 40070Sstevel@tonic-gate tp_hdr_len, BPRI_LO))) { 40080Sstevel@tonic-gate icmp_ud_err(q, mp, ENOMEM); 40090Sstevel@tonic-gate return; 40100Sstevel@tonic-gate } 40110Sstevel@tonic-gate mp1->b_rptr += icmp_wroff_extra; 40120Sstevel@tonic-gate mp1->b_wptr = mp1->b_rptr + ip_hdr_length; 40130Sstevel@tonic-gate 40140Sstevel@tonic-gate ipha->ipha_length = htons((uint16_t)pkt_len); 40150Sstevel@tonic-gate bcopy(ipha, mp1->b_rptr, IP_SIMPLE_HDR_LENGTH); 40160Sstevel@tonic-gate 40170Sstevel@tonic-gate /* Copy transport header if any */ 40180Sstevel@tonic-gate bcopy(&ipha[1], mp1->b_wptr, tp_hdr_len); 40190Sstevel@tonic-gate mp1->b_wptr += tp_hdr_len; 40200Sstevel@tonic-gate 40210Sstevel@tonic-gate /* Add options */ 40220Sstevel@tonic-gate ipha = (ipha_t *)mp1->b_rptr; 40230Sstevel@tonic-gate bcopy(icmp->icmp_ip_snd_options, &ipha[1], 40240Sstevel@tonic-gate icmp->icmp_ip_snd_options_len); 40250Sstevel@tonic-gate 40260Sstevel@tonic-gate /* Drop IP header and transport header from original */ 40270Sstevel@tonic-gate (void) adjmsg(mp, IP_SIMPLE_HDR_LENGTH + tp_hdr_len); 40280Sstevel@tonic-gate 40290Sstevel@tonic-gate mp1->b_cont = mp; 40300Sstevel@tonic-gate mp = mp1; 40310Sstevel@tonic-gate /* 40320Sstevel@tonic-gate * Massage source route putting first source 40330Sstevel@tonic-gate * route in ipha_dst. 40340Sstevel@tonic-gate */ 40350Sstevel@tonic-gate (void) ip_massage_options(ipha); 40360Sstevel@tonic-gate } 4037*3318Srshoaib 4038*3318Srshoaib if (pktinfop != NULL) { 4039*3318Srshoaib /* 4040*3318Srshoaib * Over write the source address provided in the header 4041*3318Srshoaib */ 4042*3318Srshoaib if (pktinfop->ip4_addr != INADDR_ANY) { 4043*3318Srshoaib ipha->ipha_src = pktinfop->ip4_addr; 4044*3318Srshoaib optinfo.ip_opt_flags = IP_VERIFY_SRC; 4045*3318Srshoaib ASSERT(use_putnext == B_FALSE); 4046*3318Srshoaib } 4047*3318Srshoaib 4048*3318Srshoaib if (pktinfop->ip4_ill_index != 0) { 4049*3318Srshoaib optinfo.ip_opt_ill_index = pktinfop->ip4_ill_index; 4050*3318Srshoaib ASSERT(use_putnext == B_FALSE); 4051*3318Srshoaib } 4052*3318Srshoaib } 4053*3318Srshoaib 40541676Sjpk mblk_setcred(mp, icmp->icmp_credp); 4055*3318Srshoaib if (use_putnext) { 4056*3318Srshoaib putnext(q, mp); 4057*3318Srshoaib } else { 4058*3318Srshoaib ip_output_options(Q_TO_CONN(q->q_next), mp, q->q_next, IP_WPUT, 4059*3318Srshoaib &optinfo); 4060*3318Srshoaib } 40610Sstevel@tonic-gate } 40620Sstevel@tonic-gate 40631676Sjpk static boolean_t 40641676Sjpk icmp_update_label(queue_t *q, icmp_t *icmp, mblk_t *mp, ipaddr_t dst) 40651676Sjpk { 40661676Sjpk int err; 40671676Sjpk uchar_t opt_storage[IP_MAX_OPT_LENGTH]; 40681676Sjpk 40691676Sjpk err = tsol_compute_label(DB_CREDDEF(mp, icmp->icmp_credp), dst, 40701676Sjpk opt_storage, icmp->icmp_mac_exempt); 40711676Sjpk if (err == 0) { 40721676Sjpk err = tsol_update_options(&icmp->icmp_ip_snd_options, 40731676Sjpk &icmp->icmp_ip_snd_options_len, &icmp->icmp_label_len, 40741676Sjpk opt_storage); 40751676Sjpk } 40761676Sjpk if (err != 0) { 40771676Sjpk BUMP_MIB(&rawip_mib, rawipOutErrors); 40781676Sjpk DTRACE_PROBE4( 40791676Sjpk tx__ip__log__drop__updatelabel__icmp, 40801676Sjpk char *, "queue(1) failed to update options(2) on mp(3)", 40811676Sjpk queue_t *, q, char *, opt_storage, mblk_t *, mp); 40821676Sjpk icmp_ud_err(q, mp, err); 40831676Sjpk return (B_FALSE); 40841676Sjpk } 40851676Sjpk IN6_IPADDR_TO_V4MAPPED(dst, &icmp->icmp_v6lastdst); 40861676Sjpk return (B_TRUE); 40871676Sjpk } 40881676Sjpk 40890Sstevel@tonic-gate /* 40900Sstevel@tonic-gate * This routine handles all messages passed downstream. It either 40910Sstevel@tonic-gate * consumes the message or passes it downstream; it never queues a 40920Sstevel@tonic-gate * a message. 40930Sstevel@tonic-gate */ 40940Sstevel@tonic-gate static void 40950Sstevel@tonic-gate icmp_wput(queue_t *q, mblk_t *mp) 40960Sstevel@tonic-gate { 40970Sstevel@tonic-gate uchar_t *rptr = mp->b_rptr; 40980Sstevel@tonic-gate ipha_t *ipha; 40990Sstevel@tonic-gate mblk_t *mp1; 41000Sstevel@tonic-gate int ip_hdr_length; 41010Sstevel@tonic-gate #define tudr ((struct T_unitdata_req *)rptr) 41020Sstevel@tonic-gate size_t ip_len; 41030Sstevel@tonic-gate icmp_t *icmp; 41040Sstevel@tonic-gate sin6_t *sin6; 41050Sstevel@tonic-gate sin_t *sin; 41060Sstevel@tonic-gate ipaddr_t v4dst; 4107*3318Srshoaib ip4_pkt_t pktinfo; 4108*3318Srshoaib ip4_pkt_t *pktinfop = &pktinfo; 4109*3318Srshoaib ip_opt_info_t optinfo; 4110*3318Srshoaib queue_t *ip_wq; 4111*3318Srshoaib boolean_t use_putnext = B_TRUE; 41120Sstevel@tonic-gate 41130Sstevel@tonic-gate icmp = (icmp_t *)q->q_ptr; 41140Sstevel@tonic-gate if (icmp->icmp_restricted) { 41150Sstevel@tonic-gate icmp_wput_restricted(q, mp); 41160Sstevel@tonic-gate return; 41170Sstevel@tonic-gate } 41180Sstevel@tonic-gate 41190Sstevel@tonic-gate switch (mp->b_datap->db_type) { 41200Sstevel@tonic-gate case M_DATA: 41210Sstevel@tonic-gate if (icmp->icmp_hdrincl) { 41220Sstevel@tonic-gate ASSERT(icmp->icmp_ipversion == IPV4_VERSION); 41231676Sjpk ipha = (ipha_t *)mp->b_rptr; 41241676Sjpk if (mp->b_wptr - mp->b_rptr < IP_SIMPLE_HDR_LENGTH) { 41251676Sjpk if (!pullupmsg(mp, IP_SIMPLE_HDR_LENGTH)) { 41261676Sjpk BUMP_MIB(&rawip_mib, rawipOutErrors); 41271676Sjpk freemsg(mp); 41281676Sjpk return; 41291676Sjpk } 41301676Sjpk ipha = (ipha_t *)mp->b_rptr; 41311676Sjpk } 41321676Sjpk /* 41331676Sjpk * If this connection was used for v6 (inconceivable!) 41341676Sjpk * or if we have a new destination, then it's time to 41351676Sjpk * figure a new label. 41361676Sjpk */ 41371676Sjpk if (is_system_labeled() && 41381676Sjpk (!IN6_IS_ADDR_V4MAPPED(&icmp->icmp_v6lastdst) || 41391676Sjpk V4_PART_OF_V6(icmp->icmp_v6lastdst) != 41401676Sjpk ipha->ipha_dst) && 41411676Sjpk !icmp_update_label(q, icmp, mp, ipha->ipha_dst)) { 41421676Sjpk return; 41431676Sjpk } 4144*3318Srshoaib icmp_wput_hdrincl(q, mp, icmp, NULL, use_putnext); 41450Sstevel@tonic-gate return; 41460Sstevel@tonic-gate } 41470Sstevel@tonic-gate freemsg(mp); 41480Sstevel@tonic-gate return; 41490Sstevel@tonic-gate case M_PROTO: 41500Sstevel@tonic-gate case M_PCPROTO: 41510Sstevel@tonic-gate ip_len = mp->b_wptr - rptr; 41520Sstevel@tonic-gate if (ip_len >= sizeof (struct T_unitdata_req)) { 41530Sstevel@tonic-gate /* Expedite valid T_UNITDATA_REQ to below the switch */ 41540Sstevel@tonic-gate if (((union T_primitives *)rptr)->type 41550Sstevel@tonic-gate == T_UNITDATA_REQ) 41560Sstevel@tonic-gate break; 41570Sstevel@tonic-gate } 41580Sstevel@tonic-gate /* FALLTHRU */ 41590Sstevel@tonic-gate default: 41600Sstevel@tonic-gate icmp_wput_other(q, mp); 41610Sstevel@tonic-gate return; 41620Sstevel@tonic-gate } 41630Sstevel@tonic-gate 41640Sstevel@tonic-gate /* Handle T_UNITDATA_REQ messages here. */ 41650Sstevel@tonic-gate 4166*3318Srshoaib 4167*3318Srshoaib 41680Sstevel@tonic-gate if (icmp->icmp_state == TS_UNBND) { 41690Sstevel@tonic-gate /* If a port has not been bound to the stream, fail. */ 41700Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 41710Sstevel@tonic-gate icmp_ud_err(q, mp, EPROTO); 41720Sstevel@tonic-gate return; 41730Sstevel@tonic-gate } 41740Sstevel@tonic-gate mp1 = mp->b_cont; 41750Sstevel@tonic-gate if (mp1 == NULL) { 41760Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 41770Sstevel@tonic-gate icmp_ud_err(q, mp, EPROTO); 41780Sstevel@tonic-gate return; 41790Sstevel@tonic-gate } 41800Sstevel@tonic-gate 41810Sstevel@tonic-gate if ((rptr + tudr->DEST_offset + tudr->DEST_length) > mp->b_wptr) { 41820Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 41830Sstevel@tonic-gate icmp_ud_err(q, mp, EADDRNOTAVAIL); 41840Sstevel@tonic-gate return; 41850Sstevel@tonic-gate } 41860Sstevel@tonic-gate 41870Sstevel@tonic-gate switch (icmp->icmp_family) { 41880Sstevel@tonic-gate case AF_INET6: 41890Sstevel@tonic-gate sin6 = (sin6_t *)&rptr[tudr->DEST_offset]; 41900Sstevel@tonic-gate if (!OK_32PTR((char *)sin6) || 41910Sstevel@tonic-gate tudr->DEST_length != sizeof (sin6_t) || 41920Sstevel@tonic-gate sin6->sin6_family != AF_INET6) { 41930Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 41940Sstevel@tonic-gate icmp_ud_err(q, mp, EADDRNOTAVAIL); 41950Sstevel@tonic-gate return; 41960Sstevel@tonic-gate } 41970Sstevel@tonic-gate 41980Sstevel@tonic-gate /* No support for mapped addresses on raw sockets */ 41990Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { 42000Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 42010Sstevel@tonic-gate icmp_ud_err(q, mp, EADDRNOTAVAIL); 42020Sstevel@tonic-gate return; 42030Sstevel@tonic-gate } 42040Sstevel@tonic-gate 42050Sstevel@tonic-gate /* 42060Sstevel@tonic-gate * Destination is a native IPv6 address. 42070Sstevel@tonic-gate * Send out an IPv6 format packet. 42080Sstevel@tonic-gate */ 42090Sstevel@tonic-gate icmp_wput_ipv6(q, mp, sin6, tudr->OPT_length); 42100Sstevel@tonic-gate return; 42110Sstevel@tonic-gate 42120Sstevel@tonic-gate case AF_INET: 42130Sstevel@tonic-gate sin = (sin_t *)&rptr[tudr->DEST_offset]; 42140Sstevel@tonic-gate if (!OK_32PTR((char *)sin) || 42150Sstevel@tonic-gate tudr->DEST_length != sizeof (sin_t) || 42160Sstevel@tonic-gate sin->sin_family != AF_INET) { 42170Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 42180Sstevel@tonic-gate icmp_ud_err(q, mp, EADDRNOTAVAIL); 42190Sstevel@tonic-gate return; 42200Sstevel@tonic-gate } 42210Sstevel@tonic-gate /* Extract and ipaddr */ 42220Sstevel@tonic-gate v4dst = sin->sin_addr.s_addr; 42230Sstevel@tonic-gate break; 42241676Sjpk 42251676Sjpk default: 42261676Sjpk ASSERT(0); 42270Sstevel@tonic-gate } 42280Sstevel@tonic-gate 4229*3318Srshoaib pktinfop->ip4_ill_index = 0; 4230*3318Srshoaib pktinfop->ip4_addr = INADDR_ANY; 4231*3318Srshoaib optinfo.ip_opt_flags = 0; 4232*3318Srshoaib optinfo.ip_opt_ill_index = 0; 4233*3318Srshoaib 4234*3318Srshoaib 42350Sstevel@tonic-gate /* 42360Sstevel@tonic-gate * If options passed in, feed it for verification and handling 42370Sstevel@tonic-gate */ 42380Sstevel@tonic-gate if (tudr->OPT_length != 0) { 42390Sstevel@tonic-gate int error; 42400Sstevel@tonic-gate 4241*3318Srshoaib error = 0; 42420Sstevel@tonic-gate if (icmp_unitdata_opt_process(q, mp, &error, 4243*3318Srshoaib (void *)pktinfop) < 0) { 42440Sstevel@tonic-gate /* failure */ 42450Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 42460Sstevel@tonic-gate icmp_ud_err(q, mp, error); 42470Sstevel@tonic-gate return; 42480Sstevel@tonic-gate } 4249*3318Srshoaib ASSERT(error == 0); 42500Sstevel@tonic-gate /* 42510Sstevel@tonic-gate * Note: Success in processing options. 42520Sstevel@tonic-gate * mp option buffer represented by 42530Sstevel@tonic-gate * OPT_length/offset now potentially modified 42540Sstevel@tonic-gate * and contain option setting results 42550Sstevel@tonic-gate */ 4256*3318Srshoaib 4257*3318Srshoaib if (pktinfop->ip4_ill_index != 0 || 4258*3318Srshoaib pktinfop->ip4_addr != INADDR_ANY) { 4259*3318Srshoaib /* 4260*3318Srshoaib * PKTINFO option is supported only when ICMP is 4261*3318Srshoaib * over IP. 4262*3318Srshoaib */ 4263*3318Srshoaib ip_wq = WR(q)->q_next; 4264*3318Srshoaib if (NOT_OVER_IP(ip_wq)) { 4265*3318Srshoaib icmp_ud_err(q, mp, EINVAL); 4266*3318Srshoaib return; 4267*3318Srshoaib } 4268*3318Srshoaib use_putnext = B_FALSE; 4269*3318Srshoaib } 42700Sstevel@tonic-gate } 42710Sstevel@tonic-gate 42721676Sjpk if (v4dst == INADDR_ANY) 42731676Sjpk v4dst = htonl(INADDR_LOOPBACK); 42741676Sjpk 42751676Sjpk /* Check if our saved options are valid; update if not */ 42761676Sjpk if (is_system_labeled() && 42771676Sjpk (!IN6_IS_ADDR_V4MAPPED(&icmp->icmp_v6lastdst) || 42781676Sjpk V4_PART_OF_V6(icmp->icmp_v6lastdst) != v4dst) && 42791676Sjpk !icmp_update_label(q, icmp, mp, v4dst)) { 42801676Sjpk return; 42811676Sjpk } 42821676Sjpk 42830Sstevel@tonic-gate /* Protocol 255 contains full IP headers */ 42840Sstevel@tonic-gate if (icmp->icmp_hdrincl) { 42850Sstevel@tonic-gate freeb(mp); 4286*3318Srshoaib icmp_wput_hdrincl(q, mp1, icmp, pktinfop, use_putnext); 42870Sstevel@tonic-gate return; 42880Sstevel@tonic-gate } 42891676Sjpk 4290*3318Srshoaib 42910Sstevel@tonic-gate /* Add an IP header */ 42920Sstevel@tonic-gate ip_hdr_length = IP_SIMPLE_HDR_LENGTH + icmp->icmp_ip_snd_options_len; 42930Sstevel@tonic-gate ipha = (ipha_t *)&mp1->b_rptr[-ip_hdr_length]; 42940Sstevel@tonic-gate if ((uchar_t *)ipha < mp1->b_datap->db_base || 42950Sstevel@tonic-gate mp1->b_datap->db_ref != 1 || 42960Sstevel@tonic-gate !OK_32PTR(ipha)) { 42970Sstevel@tonic-gate if (!(mp1 = allocb(ip_hdr_length + icmp_wroff_extra, 42980Sstevel@tonic-gate BPRI_LO))) { 42990Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 43001289Sja97890 icmp_ud_err(q, mp, ENOMEM); 43010Sstevel@tonic-gate return; 43020Sstevel@tonic-gate } 43030Sstevel@tonic-gate mp1->b_cont = mp->b_cont; 43040Sstevel@tonic-gate ipha = (ipha_t *)mp1->b_datap->db_lim; 43050Sstevel@tonic-gate mp1->b_wptr = (uchar_t *)ipha; 43060Sstevel@tonic-gate ipha = (ipha_t *)((uchar_t *)ipha - ip_hdr_length); 43070Sstevel@tonic-gate } 43080Sstevel@tonic-gate #ifdef _BIG_ENDIAN 43090Sstevel@tonic-gate /* Set version, header length, and tos */ 43100Sstevel@tonic-gate *(uint16_t *)&ipha->ipha_version_and_hdr_length = 43110Sstevel@tonic-gate ((((IP_VERSION << 4) | (ip_hdr_length>>2)) << 8) | 43120Sstevel@tonic-gate icmp->icmp_type_of_service); 43130Sstevel@tonic-gate /* Set ttl and protocol */ 43140Sstevel@tonic-gate *(uint16_t *)&ipha->ipha_ttl = (icmp->icmp_ttl << 8) | icmp->icmp_proto; 43150Sstevel@tonic-gate #else 43160Sstevel@tonic-gate /* Set version, header length, and tos */ 43170Sstevel@tonic-gate *(uint16_t *)&ipha->ipha_version_and_hdr_length = 43180Sstevel@tonic-gate ((icmp->icmp_type_of_service << 8) | 43190Sstevel@tonic-gate ((IP_VERSION << 4) | (ip_hdr_length>>2))); 43200Sstevel@tonic-gate /* Set ttl and protocol */ 43210Sstevel@tonic-gate *(uint16_t *)&ipha->ipha_ttl = (icmp->icmp_proto << 8) | icmp->icmp_ttl; 43220Sstevel@tonic-gate #endif 4323*3318Srshoaib if (pktinfop->ip4_addr != INADDR_ANY) { 4324*3318Srshoaib ASSERT(use_putnext == B_FALSE); 4325*3318Srshoaib ipha->ipha_src = pktinfop->ip4_addr; 4326*3318Srshoaib optinfo.ip_opt_flags = IP_VERIFY_SRC; 4327*3318Srshoaib } else { 4328*3318Srshoaib 4329*3318Srshoaib /* 4330*3318Srshoaib * Copy our address into the packet. If this is zero, 4331*3318Srshoaib * ip will fill in the real source address. 4332*3318Srshoaib */ 4333*3318Srshoaib IN6_V4MAPPED_TO_IPADDR(&icmp->icmp_v6src, ipha->ipha_src); 4334*3318Srshoaib } 4335*3318Srshoaib 43360Sstevel@tonic-gate ipha->ipha_fragment_offset_and_flags = 0; 43370Sstevel@tonic-gate 4338*3318Srshoaib if (pktinfop->ip4_ill_index != 0) { 4339*3318Srshoaib optinfo.ip_opt_ill_index = pktinfop->ip4_ill_index; 4340*3318Srshoaib ASSERT(use_putnext == B_FALSE); 4341*3318Srshoaib } 4342*3318Srshoaib 4343*3318Srshoaib 43440Sstevel@tonic-gate /* 43450Sstevel@tonic-gate * For the socket of SOCK_RAW type, the checksum is provided in the 43460Sstevel@tonic-gate * pre-built packet. We set the ipha_ident field to IP_HDR_INCLUDED to 43470Sstevel@tonic-gate * tell IP that the application has sent a complete IP header and not 43480Sstevel@tonic-gate * to compute the transport checksum nor change the DF flag. 43490Sstevel@tonic-gate */ 43500Sstevel@tonic-gate ipha->ipha_ident = IP_HDR_INCLUDED; 43510Sstevel@tonic-gate 43520Sstevel@tonic-gate /* Finish common formatting of the packet. */ 43530Sstevel@tonic-gate mp1->b_rptr = (uchar_t *)ipha; 43540Sstevel@tonic-gate 43550Sstevel@tonic-gate ip_len = mp1->b_wptr - (uchar_t *)ipha; 43560Sstevel@tonic-gate if (mp1->b_cont != NULL) 43570Sstevel@tonic-gate ip_len += msgdsize(mp1->b_cont); 43580Sstevel@tonic-gate 43590Sstevel@tonic-gate /* 43600Sstevel@tonic-gate * Set the length into the IP header. 43610Sstevel@tonic-gate * If the length is greater than the maximum allowed by IP, 43620Sstevel@tonic-gate * then free the message and return. Do not try and send it 43630Sstevel@tonic-gate * as this can cause problems in layers below. 43640Sstevel@tonic-gate */ 43650Sstevel@tonic-gate if (ip_len > IP_MAXPACKET) { 43660Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 43670Sstevel@tonic-gate icmp_ud_err(q, mp, EMSGSIZE); 43680Sstevel@tonic-gate return; 43690Sstevel@tonic-gate } 43700Sstevel@tonic-gate ipha->ipha_length = htons((uint16_t)ip_len); 43710Sstevel@tonic-gate /* 43720Sstevel@tonic-gate * Copy in the destination address from the T_UNITDATA 43730Sstevel@tonic-gate * request 43740Sstevel@tonic-gate */ 43751676Sjpk ipha->ipha_dst = v4dst; 43760Sstevel@tonic-gate 43770Sstevel@tonic-gate /* 43780Sstevel@tonic-gate * Set ttl based on IP_MULTICAST_TTL to match IPv6 logic. 43790Sstevel@tonic-gate */ 43800Sstevel@tonic-gate if (CLASSD(v4dst)) 43810Sstevel@tonic-gate ipha->ipha_ttl = icmp->icmp_multicast_ttl; 43820Sstevel@tonic-gate 43830Sstevel@tonic-gate /* Copy in options if any */ 43840Sstevel@tonic-gate if (ip_hdr_length > IP_SIMPLE_HDR_LENGTH) { 43850Sstevel@tonic-gate bcopy(icmp->icmp_ip_snd_options, 43860Sstevel@tonic-gate &ipha[1], icmp->icmp_ip_snd_options_len); 43870Sstevel@tonic-gate /* 43880Sstevel@tonic-gate * Massage source route putting first source route in ipha_dst. 43890Sstevel@tonic-gate * Ignore the destination in the T_unitdata_req. 43900Sstevel@tonic-gate */ 43910Sstevel@tonic-gate (void) ip_massage_options(ipha); 43920Sstevel@tonic-gate } 4393*3318Srshoaib 43940Sstevel@tonic-gate freeb(mp); 43950Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutDatagrams); 43961676Sjpk mblk_setcred(mp1, icmp->icmp_credp); 4397*3318Srshoaib if (use_putnext) { 4398*3318Srshoaib putnext(q, mp1); 4399*3318Srshoaib } else { 4400*3318Srshoaib ip_output_options(Q_TO_CONN(q->q_next), mp1, q->q_next, IP_WPUT, 4401*3318Srshoaib &optinfo); 4402*3318Srshoaib } 44030Sstevel@tonic-gate #undef ipha 44040Sstevel@tonic-gate #undef tudr 44050Sstevel@tonic-gate } 44060Sstevel@tonic-gate 44071676Sjpk static boolean_t 44081676Sjpk icmp_update_label_v6(queue_t *wq, icmp_t *icmp, mblk_t *mp, in6_addr_t *dst) 44091676Sjpk { 44101676Sjpk int err; 44111676Sjpk uchar_t opt_storage[TSOL_MAX_IPV6_OPTION]; 44121676Sjpk 44131676Sjpk err = tsol_compute_label_v6(DB_CREDDEF(mp, icmp->icmp_credp), dst, 44141676Sjpk opt_storage, icmp->icmp_mac_exempt); 44151676Sjpk if (err == 0) { 44161676Sjpk err = tsol_update_sticky(&icmp->icmp_sticky_ipp, 44171676Sjpk &icmp->icmp_label_len_v6, opt_storage); 44181676Sjpk } 44191676Sjpk if (err != 0) { 44201676Sjpk BUMP_MIB(&rawip_mib, rawipOutErrors); 44211676Sjpk DTRACE_PROBE4( 44221676Sjpk tx__ip__log__drop__updatelabel__icmp6, 44231676Sjpk char *, "queue(1) failed to update options(2) on mp(3)", 44241676Sjpk queue_t *, wq, char *, opt_storage, mblk_t *, mp); 44251676Sjpk icmp_ud_err(wq, mp, err); 44261676Sjpk return (B_FALSE); 44271676Sjpk } 44281676Sjpk 44291676Sjpk icmp->icmp_v6lastdst = *dst; 44301676Sjpk return (B_TRUE); 44311676Sjpk } 44321676Sjpk 44330Sstevel@tonic-gate /* 44340Sstevel@tonic-gate * icmp_wput_ipv6(): 44350Sstevel@tonic-gate * Assumes that icmp_wput did some sanity checking on the destination 44361676Sjpk * address, but that the label may not yet be correct. 44370Sstevel@tonic-gate */ 44380Sstevel@tonic-gate void 44390Sstevel@tonic-gate icmp_wput_ipv6(queue_t *q, mblk_t *mp, sin6_t *sin6, t_scalar_t tudr_optlen) 44400Sstevel@tonic-gate { 44410Sstevel@tonic-gate ip6_t *ip6h; 44420Sstevel@tonic-gate ip6i_t *ip6i; /* mp1->b_rptr even if no ip6i_t */ 44430Sstevel@tonic-gate mblk_t *mp1; 44440Sstevel@tonic-gate int ip_hdr_len = IPV6_HDR_LEN; 44450Sstevel@tonic-gate size_t ip_len; 44460Sstevel@tonic-gate icmp_t *icmp; 44470Sstevel@tonic-gate ip6_pkt_t ipp_s; /* For ancillary data options */ 44480Sstevel@tonic-gate ip6_pkt_t *ipp = &ipp_s; 44490Sstevel@tonic-gate ip6_pkt_t *tipp; 44500Sstevel@tonic-gate uint32_t csum = 0; 44510Sstevel@tonic-gate uint_t ignore = 0; 44520Sstevel@tonic-gate uint_t option_exists = 0, is_sticky = 0; 44530Sstevel@tonic-gate uint8_t *cp; 44540Sstevel@tonic-gate uint8_t *nxthdr_ptr; 44551676Sjpk in6_addr_t ip6_dst; 44560Sstevel@tonic-gate 44570Sstevel@tonic-gate icmp = (icmp_t *)q->q_ptr; 44580Sstevel@tonic-gate 44590Sstevel@tonic-gate /* 44600Sstevel@tonic-gate * If the local address is a mapped address return 44610Sstevel@tonic-gate * an error. 44620Sstevel@tonic-gate * It would be possible to send an IPv6 packet but the 44630Sstevel@tonic-gate * response would never make it back to the application 44640Sstevel@tonic-gate * since it is bound to a mapped address. 44650Sstevel@tonic-gate */ 44660Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&icmp->icmp_v6src)) { 44670Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 44680Sstevel@tonic-gate icmp_ud_err(q, mp, EADDRNOTAVAIL); 44690Sstevel@tonic-gate return; 44700Sstevel@tonic-gate } 44710Sstevel@tonic-gate 44720Sstevel@tonic-gate ipp->ipp_fields = 0; 44730Sstevel@tonic-gate ipp->ipp_sticky_ignored = 0; 44740Sstevel@tonic-gate 44750Sstevel@tonic-gate /* 44760Sstevel@tonic-gate * If TPI options passed in, feed it for verification and handling 44770Sstevel@tonic-gate */ 44780Sstevel@tonic-gate if (tudr_optlen != 0) { 44790Sstevel@tonic-gate int error; 44800Sstevel@tonic-gate 44810Sstevel@tonic-gate if (icmp_unitdata_opt_process(q, mp, &error, 44820Sstevel@tonic-gate (void *)ipp) < 0) { 44830Sstevel@tonic-gate /* failure */ 44840Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 44850Sstevel@tonic-gate icmp_ud_err(q, mp, error); 44860Sstevel@tonic-gate return; 44870Sstevel@tonic-gate } 44880Sstevel@tonic-gate ignore = ipp->ipp_sticky_ignored; 44890Sstevel@tonic-gate ASSERT(error == 0); 44900Sstevel@tonic-gate } 44910Sstevel@tonic-gate 44920Sstevel@tonic-gate if (sin6->sin6_scope_id != 0 && 44930Sstevel@tonic-gate IN6_IS_ADDR_LINKSCOPE(&sin6->sin6_addr)) { 44940Sstevel@tonic-gate /* 44950Sstevel@tonic-gate * IPPF_SCOPE_ID is special. It's neither a sticky 44960Sstevel@tonic-gate * option nor ancillary data. It needs to be 44970Sstevel@tonic-gate * explicitly set in options_exists. 44980Sstevel@tonic-gate */ 44990Sstevel@tonic-gate option_exists |= IPPF_SCOPE_ID; 45000Sstevel@tonic-gate } 45010Sstevel@tonic-gate 45021676Sjpk /* 45031676Sjpk * Compute the destination address 45041676Sjpk */ 45051676Sjpk ip6_dst = sin6->sin6_addr; 45061676Sjpk if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) 45071676Sjpk ip6_dst = ipv6_loopback; 45081676Sjpk 45091676Sjpk /* 45101676Sjpk * If we're not going to the same destination as last time, then 45111676Sjpk * recompute the label required. This is done in a separate routine to 45121676Sjpk * avoid blowing up our stack here. 45131676Sjpk */ 45141676Sjpk if (is_system_labeled() && 45151676Sjpk !IN6_ARE_ADDR_EQUAL(&icmp->icmp_v6lastdst, &ip6_dst) && 45161676Sjpk !icmp_update_label_v6(q, icmp, mp, &ip6_dst)) { 45171676Sjpk return; 45181676Sjpk } 45191676Sjpk 45201676Sjpk /* 45211676Sjpk * If there's a security label here, then we ignore any options the 45221676Sjpk * user may try to set. We keep the peer's label as a hidden sticky 45231676Sjpk * option. 45241676Sjpk */ 45251676Sjpk if (icmp->icmp_label_len_v6 > 0) { 45261676Sjpk ignore &= ~IPPF_HOPOPTS; 45271676Sjpk ipp->ipp_fields &= ~IPPF_HOPOPTS; 45281676Sjpk } 45291676Sjpk 45300Sstevel@tonic-gate if ((icmp->icmp_sticky_ipp.ipp_fields == 0) && 45310Sstevel@tonic-gate (ipp->ipp_fields == 0)) { 45320Sstevel@tonic-gate /* No sticky options nor ancillary data. */ 45330Sstevel@tonic-gate goto no_options; 45340Sstevel@tonic-gate } 45350Sstevel@tonic-gate 45360Sstevel@tonic-gate /* 45370Sstevel@tonic-gate * Go through the options figuring out where each is going to 45380Sstevel@tonic-gate * come from and build two masks. The first mask indicates if 45390Sstevel@tonic-gate * the option exists at all. The second mask indicates if the 45400Sstevel@tonic-gate * option is sticky or ancillary. 45410Sstevel@tonic-gate */ 45420Sstevel@tonic-gate if (!(ignore & IPPF_HOPOPTS)) { 45430Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_HOPOPTS) { 45440Sstevel@tonic-gate option_exists |= IPPF_HOPOPTS; 45450Sstevel@tonic-gate ip_hdr_len += ipp->ipp_hopoptslen; 45460Sstevel@tonic-gate } else if (icmp->icmp_sticky_ipp.ipp_fields & IPPF_HOPOPTS) { 45470Sstevel@tonic-gate option_exists |= IPPF_HOPOPTS; 45480Sstevel@tonic-gate is_sticky |= IPPF_HOPOPTS; 45490Sstevel@tonic-gate ip_hdr_len += icmp->icmp_sticky_ipp.ipp_hopoptslen; 45500Sstevel@tonic-gate } 45510Sstevel@tonic-gate } 45520Sstevel@tonic-gate 45530Sstevel@tonic-gate if (!(ignore & IPPF_RTHDR)) { 45540Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_RTHDR) { 45550Sstevel@tonic-gate option_exists |= IPPF_RTHDR; 45560Sstevel@tonic-gate ip_hdr_len += ipp->ipp_rthdrlen; 45570Sstevel@tonic-gate } else if (icmp->icmp_sticky_ipp.ipp_fields & IPPF_RTHDR) { 45580Sstevel@tonic-gate option_exists |= IPPF_RTHDR; 45590Sstevel@tonic-gate is_sticky |= IPPF_RTHDR; 45600Sstevel@tonic-gate ip_hdr_len += icmp->icmp_sticky_ipp.ipp_rthdrlen; 45610Sstevel@tonic-gate } 45620Sstevel@tonic-gate } 45630Sstevel@tonic-gate 45640Sstevel@tonic-gate if (!(ignore & IPPF_RTDSTOPTS) && (option_exists & IPPF_RTHDR)) { 45650Sstevel@tonic-gate /* 45660Sstevel@tonic-gate * Need to have a router header to use these. 45670Sstevel@tonic-gate */ 45680Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_RTDSTOPTS) { 45690Sstevel@tonic-gate option_exists |= IPPF_RTDSTOPTS; 45700Sstevel@tonic-gate ip_hdr_len += ipp->ipp_rtdstoptslen; 45710Sstevel@tonic-gate } else if (icmp->icmp_sticky_ipp.ipp_fields & IPPF_RTDSTOPTS) { 45720Sstevel@tonic-gate option_exists |= IPPF_RTDSTOPTS; 45730Sstevel@tonic-gate is_sticky |= IPPF_RTDSTOPTS; 45740Sstevel@tonic-gate ip_hdr_len += 45750Sstevel@tonic-gate icmp->icmp_sticky_ipp.ipp_rtdstoptslen; 45760Sstevel@tonic-gate } 45770Sstevel@tonic-gate } 45780Sstevel@tonic-gate 45790Sstevel@tonic-gate if (!(ignore & IPPF_DSTOPTS)) { 45800Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_DSTOPTS) { 45810Sstevel@tonic-gate option_exists |= IPPF_DSTOPTS; 45820Sstevel@tonic-gate ip_hdr_len += ipp->ipp_dstoptslen; 45830Sstevel@tonic-gate } else if (icmp->icmp_sticky_ipp.ipp_fields & IPPF_DSTOPTS) { 45840Sstevel@tonic-gate option_exists |= IPPF_DSTOPTS; 45850Sstevel@tonic-gate is_sticky |= IPPF_DSTOPTS; 45860Sstevel@tonic-gate ip_hdr_len += icmp->icmp_sticky_ipp.ipp_dstoptslen; 45870Sstevel@tonic-gate } 45880Sstevel@tonic-gate } 45890Sstevel@tonic-gate 45900Sstevel@tonic-gate if (!(ignore & IPPF_IFINDEX)) { 45910Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_IFINDEX) { 45920Sstevel@tonic-gate option_exists |= IPPF_IFINDEX; 45930Sstevel@tonic-gate } else if (icmp->icmp_sticky_ipp.ipp_fields & IPPF_IFINDEX) { 45940Sstevel@tonic-gate option_exists |= IPPF_IFINDEX; 45950Sstevel@tonic-gate is_sticky |= IPPF_IFINDEX; 45960Sstevel@tonic-gate } 45970Sstevel@tonic-gate } 45980Sstevel@tonic-gate 45990Sstevel@tonic-gate if (!(ignore & IPPF_ADDR)) { 46000Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_ADDR) { 46010Sstevel@tonic-gate option_exists |= IPPF_ADDR; 46020Sstevel@tonic-gate } else if (icmp->icmp_sticky_ipp.ipp_fields & IPPF_ADDR) { 46030Sstevel@tonic-gate option_exists |= IPPF_ADDR; 46040Sstevel@tonic-gate is_sticky |= IPPF_ADDR; 46050Sstevel@tonic-gate } 46060Sstevel@tonic-gate } 46070Sstevel@tonic-gate 46080Sstevel@tonic-gate if (!(ignore & IPPF_DONTFRAG)) { 46090Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_DONTFRAG) { 46100Sstevel@tonic-gate option_exists |= IPPF_DONTFRAG; 46110Sstevel@tonic-gate } else if (icmp->icmp_sticky_ipp.ipp_fields & IPPF_DONTFRAG) { 46120Sstevel@tonic-gate option_exists |= IPPF_DONTFRAG; 46130Sstevel@tonic-gate is_sticky |= IPPF_DONTFRAG; 46140Sstevel@tonic-gate } 46150Sstevel@tonic-gate } 46160Sstevel@tonic-gate 46170Sstevel@tonic-gate if (!(ignore & IPPF_USE_MIN_MTU)) { 46180Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_USE_MIN_MTU) { 46190Sstevel@tonic-gate option_exists |= IPPF_USE_MIN_MTU; 46200Sstevel@tonic-gate } else if (icmp->icmp_sticky_ipp.ipp_fields & 46210Sstevel@tonic-gate IPPF_USE_MIN_MTU) { 46220Sstevel@tonic-gate option_exists |= IPPF_USE_MIN_MTU; 46230Sstevel@tonic-gate is_sticky |= IPPF_USE_MIN_MTU; 46240Sstevel@tonic-gate } 46250Sstevel@tonic-gate } 46260Sstevel@tonic-gate 46270Sstevel@tonic-gate if (!(ignore & IPPF_NEXTHOP)) { 46280Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_NEXTHOP) { 46290Sstevel@tonic-gate option_exists |= IPPF_NEXTHOP; 46300Sstevel@tonic-gate } else if (icmp->icmp_sticky_ipp.ipp_fields & IPPF_NEXTHOP) { 46310Sstevel@tonic-gate option_exists |= IPPF_NEXTHOP; 46320Sstevel@tonic-gate is_sticky |= IPPF_NEXTHOP; 46330Sstevel@tonic-gate } 46340Sstevel@tonic-gate } 46350Sstevel@tonic-gate 4636679Sseb if (!(ignore & IPPF_HOPLIMIT) && (ipp->ipp_fields & IPPF_HOPLIMIT)) 4637679Sseb option_exists |= IPPF_HOPLIMIT; 4638679Sseb /* IPV6_HOPLIMIT can never be sticky */ 4639679Sseb ASSERT(!(icmp->icmp_sticky_ipp.ipp_fields & IPPF_HOPLIMIT)); 4640679Sseb 4641679Sseb if (!(ignore & IPPF_UNICAST_HOPS) && 4642679Sseb (icmp->icmp_sticky_ipp.ipp_fields & IPPF_UNICAST_HOPS)) { 4643679Sseb option_exists |= IPPF_UNICAST_HOPS; 4644679Sseb is_sticky |= IPPF_UNICAST_HOPS; 4645679Sseb } 4646679Sseb 4647679Sseb if (!(ignore & IPPF_MULTICAST_HOPS) && 4648679Sseb (icmp->icmp_sticky_ipp.ipp_fields & IPPF_MULTICAST_HOPS)) { 4649679Sseb option_exists |= IPPF_MULTICAST_HOPS; 4650679Sseb is_sticky |= IPPF_MULTICAST_HOPS; 46510Sstevel@tonic-gate } 46520Sstevel@tonic-gate 46530Sstevel@tonic-gate if (icmp->icmp_sticky_ipp.ipp_fields & IPPF_NO_CKSUM) { 46540Sstevel@tonic-gate /* This is a sticky socket option only */ 46550Sstevel@tonic-gate option_exists |= IPPF_NO_CKSUM; 46560Sstevel@tonic-gate is_sticky |= IPPF_NO_CKSUM; 46570Sstevel@tonic-gate } 46580Sstevel@tonic-gate 46590Sstevel@tonic-gate if (icmp->icmp_sticky_ipp.ipp_fields & IPPF_RAW_CKSUM) { 46600Sstevel@tonic-gate /* This is a sticky socket option only */ 46610Sstevel@tonic-gate option_exists |= IPPF_RAW_CKSUM; 46620Sstevel@tonic-gate is_sticky |= IPPF_RAW_CKSUM; 46630Sstevel@tonic-gate } 46640Sstevel@tonic-gate 46650Sstevel@tonic-gate if (!(ignore & IPPF_TCLASS)) { 46660Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_TCLASS) { 46670Sstevel@tonic-gate option_exists |= IPPF_TCLASS; 46680Sstevel@tonic-gate } else if (icmp->icmp_sticky_ipp.ipp_fields & IPPF_TCLASS) { 46690Sstevel@tonic-gate option_exists |= IPPF_TCLASS; 46700Sstevel@tonic-gate is_sticky |= IPPF_TCLASS; 46710Sstevel@tonic-gate } 46720Sstevel@tonic-gate } 46730Sstevel@tonic-gate 46740Sstevel@tonic-gate no_options: 46750Sstevel@tonic-gate 46760Sstevel@tonic-gate /* 46770Sstevel@tonic-gate * If any options carried in the ip6i_t were specified, we 46780Sstevel@tonic-gate * need to account for the ip6i_t in the data we'll be sending 46790Sstevel@tonic-gate * down. 46800Sstevel@tonic-gate */ 46810Sstevel@tonic-gate if (option_exists & IPPF_HAS_IP6I) 46820Sstevel@tonic-gate ip_hdr_len += sizeof (ip6i_t); 46830Sstevel@tonic-gate 46840Sstevel@tonic-gate /* check/fix buffer config, setup pointers into it */ 46850Sstevel@tonic-gate mp1 = mp->b_cont; 46860Sstevel@tonic-gate ip6h = (ip6_t *)&mp1->b_rptr[-ip_hdr_len]; 46870Sstevel@tonic-gate if ((mp1->b_datap->db_ref != 1) || 46880Sstevel@tonic-gate ((unsigned char *)ip6h < mp1->b_datap->db_base) || 46890Sstevel@tonic-gate !OK_32PTR(ip6h)) { 46900Sstevel@tonic-gate /* Try to get everything in a single mblk next time */ 46910Sstevel@tonic-gate if (ip_hdr_len > icmp->icmp_max_hdr_len) { 46920Sstevel@tonic-gate icmp->icmp_max_hdr_len = ip_hdr_len; 46930Sstevel@tonic-gate (void) mi_set_sth_wroff(RD(q), 46940Sstevel@tonic-gate icmp->icmp_max_hdr_len + icmp_wroff_extra); 46950Sstevel@tonic-gate } 46960Sstevel@tonic-gate mp1 = allocb(ip_hdr_len + icmp_wroff_extra, BPRI_LO); 46970Sstevel@tonic-gate if (!mp1) { 46980Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 46990Sstevel@tonic-gate icmp_ud_err(q, mp, ENOMEM); 47000Sstevel@tonic-gate return; 47010Sstevel@tonic-gate } 47020Sstevel@tonic-gate mp1->b_cont = mp->b_cont; 47030Sstevel@tonic-gate mp1->b_wptr = mp1->b_datap->db_lim; 47040Sstevel@tonic-gate ip6h = (ip6_t *)(mp1->b_wptr - ip_hdr_len); 47050Sstevel@tonic-gate } 47060Sstevel@tonic-gate mp1->b_rptr = (unsigned char *)ip6h; 47070Sstevel@tonic-gate ip6i = (ip6i_t *)ip6h; 47080Sstevel@tonic-gate 47090Sstevel@tonic-gate #define ANCIL_OR_STICKY_PTR(f) ((is_sticky & f) ? &icmp->icmp_sticky_ipp : ipp) 47100Sstevel@tonic-gate if (option_exists & IPPF_HAS_IP6I) { 47110Sstevel@tonic-gate ip6h = (ip6_t *)&ip6i[1]; 47120Sstevel@tonic-gate ip6i->ip6i_flags = 0; 47130Sstevel@tonic-gate ip6i->ip6i_vcf = IPV6_DEFAULT_VERS_AND_FLOW; 47140Sstevel@tonic-gate 47150Sstevel@tonic-gate /* sin6_scope_id takes precendence over IPPF_IFINDEX */ 47160Sstevel@tonic-gate if (option_exists & IPPF_SCOPE_ID) { 47170Sstevel@tonic-gate ip6i->ip6i_flags |= IP6I_IFINDEX; 47180Sstevel@tonic-gate ip6i->ip6i_ifindex = sin6->sin6_scope_id; 47190Sstevel@tonic-gate } else if (option_exists & IPPF_IFINDEX) { 47200Sstevel@tonic-gate tipp = ANCIL_OR_STICKY_PTR(IPPF_IFINDEX); 47210Sstevel@tonic-gate ASSERT(tipp->ipp_ifindex != 0); 47220Sstevel@tonic-gate ip6i->ip6i_flags |= IP6I_IFINDEX; 47230Sstevel@tonic-gate ip6i->ip6i_ifindex = tipp->ipp_ifindex; 47240Sstevel@tonic-gate } 47250Sstevel@tonic-gate 47260Sstevel@tonic-gate if (option_exists & IPPF_RAW_CKSUM) { 47270Sstevel@tonic-gate ip6i->ip6i_flags |= IP6I_RAW_CHECKSUM; 47280Sstevel@tonic-gate ip6i->ip6i_checksum_off = icmp->icmp_checksum_off; 47290Sstevel@tonic-gate } 47300Sstevel@tonic-gate 47310Sstevel@tonic-gate if (option_exists & IPPF_NO_CKSUM) { 47320Sstevel@tonic-gate ip6i->ip6i_flags |= IP6I_NO_ULP_CKSUM; 47330Sstevel@tonic-gate } 47340Sstevel@tonic-gate 47350Sstevel@tonic-gate if (option_exists & IPPF_ADDR) { 47360Sstevel@tonic-gate /* 47370Sstevel@tonic-gate * Enable per-packet source address verification if 47380Sstevel@tonic-gate * IPV6_PKTINFO specified the source address. 47390Sstevel@tonic-gate * ip6_src is set in the transport's _wput function. 47400Sstevel@tonic-gate */ 47410Sstevel@tonic-gate ip6i->ip6i_flags |= IP6I_VERIFY_SRC; 47420Sstevel@tonic-gate } 47430Sstevel@tonic-gate 47440Sstevel@tonic-gate if (option_exists & IPPF_DONTFRAG) { 47450Sstevel@tonic-gate ip6i->ip6i_flags |= IP6I_DONTFRAG; 47460Sstevel@tonic-gate } 47470Sstevel@tonic-gate 47480Sstevel@tonic-gate if (option_exists & IPPF_USE_MIN_MTU) { 47490Sstevel@tonic-gate ip6i->ip6i_flags = IP6I_API_USE_MIN_MTU( 47500Sstevel@tonic-gate ip6i->ip6i_flags, ipp->ipp_use_min_mtu); 47510Sstevel@tonic-gate } 47520Sstevel@tonic-gate 47530Sstevel@tonic-gate if (option_exists & IPPF_NEXTHOP) { 47540Sstevel@tonic-gate tipp = ANCIL_OR_STICKY_PTR(IPPF_NEXTHOP); 47550Sstevel@tonic-gate ASSERT(!IN6_IS_ADDR_UNSPECIFIED(&tipp->ipp_nexthop)); 47560Sstevel@tonic-gate ip6i->ip6i_flags |= IP6I_NEXTHOP; 47570Sstevel@tonic-gate ip6i->ip6i_nexthop = tipp->ipp_nexthop; 47580Sstevel@tonic-gate } 47590Sstevel@tonic-gate 47600Sstevel@tonic-gate /* 47610Sstevel@tonic-gate * tell IP this is an ip6i_t private header 47620Sstevel@tonic-gate */ 47630Sstevel@tonic-gate ip6i->ip6i_nxt = IPPROTO_RAW; 47640Sstevel@tonic-gate } 47650Sstevel@tonic-gate 47660Sstevel@tonic-gate /* Initialize IPv6 header */ 47670Sstevel@tonic-gate ip6h->ip6_vcf = IPV6_DEFAULT_VERS_AND_FLOW; 47680Sstevel@tonic-gate bzero(&ip6h->ip6_src, sizeof (ip6h->ip6_src)); 47690Sstevel@tonic-gate 4770679Sseb /* Set the hoplimit of the outgoing packet. */ 47710Sstevel@tonic-gate if (option_exists & IPPF_HOPLIMIT) { 4772679Sseb /* IPV6_HOPLIMIT ancillary data overrides all other settings. */ 4773679Sseb ip6h->ip6_hops = ipp->ipp_hoplimit; 4774679Sseb ip6i->ip6i_flags |= IP6I_HOPLIMIT; 4775679Sseb } else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) { 47760Sstevel@tonic-gate ip6h->ip6_hops = icmp->icmp_multicast_ttl; 4777679Sseb if (option_exists & IPPF_MULTICAST_HOPS) 4778679Sseb ip6i->ip6i_flags |= IP6I_HOPLIMIT; 47790Sstevel@tonic-gate } else { 47800Sstevel@tonic-gate ip6h->ip6_hops = icmp->icmp_ttl; 4781679Sseb if (option_exists & IPPF_UNICAST_HOPS) 4782679Sseb ip6i->ip6i_flags |= IP6I_HOPLIMIT; 47830Sstevel@tonic-gate } 47840Sstevel@tonic-gate 47850Sstevel@tonic-gate if (option_exists & IPPF_ADDR) { 47860Sstevel@tonic-gate tipp = ANCIL_OR_STICKY_PTR(IPPF_ADDR); 47870Sstevel@tonic-gate ASSERT(!IN6_IS_ADDR_UNSPECIFIED(&tipp->ipp_addr)); 47880Sstevel@tonic-gate ip6h->ip6_src = tipp->ipp_addr; 47890Sstevel@tonic-gate } else { 47900Sstevel@tonic-gate /* 47910Sstevel@tonic-gate * The source address was not set using IPV6_PKTINFO. 47920Sstevel@tonic-gate * First look at the bound source. 47930Sstevel@tonic-gate * If unspecified fallback to __sin6_src_id. 47940Sstevel@tonic-gate */ 47950Sstevel@tonic-gate ip6h->ip6_src = icmp->icmp_v6src; 47960Sstevel@tonic-gate if (sin6->__sin6_src_id != 0 && 47970Sstevel@tonic-gate IN6_IS_ADDR_UNSPECIFIED(&ip6h->ip6_src)) { 47980Sstevel@tonic-gate ip_srcid_find_id(sin6->__sin6_src_id, 47990Sstevel@tonic-gate &ip6h->ip6_src, icmp->icmp_zoneid); 48000Sstevel@tonic-gate } 48010Sstevel@tonic-gate } 48020Sstevel@tonic-gate 48030Sstevel@tonic-gate nxthdr_ptr = (uint8_t *)&ip6h->ip6_nxt; 48040Sstevel@tonic-gate cp = (uint8_t *)&ip6h[1]; 48050Sstevel@tonic-gate 48060Sstevel@tonic-gate /* 48070Sstevel@tonic-gate * Here's where we have to start stringing together 48080Sstevel@tonic-gate * any extension headers in the right order: 48090Sstevel@tonic-gate * Hop-by-hop, destination, routing, and final destination opts. 48100Sstevel@tonic-gate */ 48110Sstevel@tonic-gate if (option_exists & IPPF_HOPOPTS) { 48120Sstevel@tonic-gate /* Hop-by-hop options */ 48130Sstevel@tonic-gate ip6_hbh_t *hbh = (ip6_hbh_t *)cp; 48140Sstevel@tonic-gate tipp = ANCIL_OR_STICKY_PTR(IPPF_HOPOPTS); 48150Sstevel@tonic-gate 48160Sstevel@tonic-gate *nxthdr_ptr = IPPROTO_HOPOPTS; 48170Sstevel@tonic-gate nxthdr_ptr = &hbh->ip6h_nxt; 48180Sstevel@tonic-gate 48190Sstevel@tonic-gate bcopy(tipp->ipp_hopopts, cp, tipp->ipp_hopoptslen); 48200Sstevel@tonic-gate cp += tipp->ipp_hopoptslen; 48210Sstevel@tonic-gate } 48220Sstevel@tonic-gate /* 48230Sstevel@tonic-gate * En-route destination options 48240Sstevel@tonic-gate * Only do them if there's a routing header as well 48250Sstevel@tonic-gate */ 48260Sstevel@tonic-gate if (option_exists & IPPF_RTDSTOPTS) { 48270Sstevel@tonic-gate ip6_dest_t *dst = (ip6_dest_t *)cp; 48280Sstevel@tonic-gate tipp = ANCIL_OR_STICKY_PTR(IPPF_RTDSTOPTS); 48290Sstevel@tonic-gate 48300Sstevel@tonic-gate *nxthdr_ptr = IPPROTO_DSTOPTS; 48310Sstevel@tonic-gate nxthdr_ptr = &dst->ip6d_nxt; 48320Sstevel@tonic-gate 48330Sstevel@tonic-gate bcopy(tipp->ipp_rtdstopts, cp, tipp->ipp_rtdstoptslen); 48340Sstevel@tonic-gate cp += tipp->ipp_rtdstoptslen; 48350Sstevel@tonic-gate } 48360Sstevel@tonic-gate /* 48370Sstevel@tonic-gate * Routing header next 48380Sstevel@tonic-gate */ 48390Sstevel@tonic-gate if (option_exists & IPPF_RTHDR) { 48400Sstevel@tonic-gate ip6_rthdr_t *rt = (ip6_rthdr_t *)cp; 48410Sstevel@tonic-gate tipp = ANCIL_OR_STICKY_PTR(IPPF_RTHDR); 48420Sstevel@tonic-gate 48430Sstevel@tonic-gate *nxthdr_ptr = IPPROTO_ROUTING; 48440Sstevel@tonic-gate nxthdr_ptr = &rt->ip6r_nxt; 48450Sstevel@tonic-gate 48460Sstevel@tonic-gate bcopy(tipp->ipp_rthdr, cp, tipp->ipp_rthdrlen); 48470Sstevel@tonic-gate cp += tipp->ipp_rthdrlen; 48480Sstevel@tonic-gate } 48490Sstevel@tonic-gate /* 48500Sstevel@tonic-gate * Do ultimate destination options 48510Sstevel@tonic-gate */ 48520Sstevel@tonic-gate if (option_exists & IPPF_DSTOPTS) { 48530Sstevel@tonic-gate ip6_dest_t *dest = (ip6_dest_t *)cp; 48540Sstevel@tonic-gate tipp = ANCIL_OR_STICKY_PTR(IPPF_DSTOPTS); 48550Sstevel@tonic-gate 48560Sstevel@tonic-gate *nxthdr_ptr = IPPROTO_DSTOPTS; 48570Sstevel@tonic-gate nxthdr_ptr = &dest->ip6d_nxt; 48580Sstevel@tonic-gate 48590Sstevel@tonic-gate bcopy(tipp->ipp_dstopts, cp, tipp->ipp_dstoptslen); 48600Sstevel@tonic-gate cp += tipp->ipp_dstoptslen; 48610Sstevel@tonic-gate } 48620Sstevel@tonic-gate 48630Sstevel@tonic-gate /* 48640Sstevel@tonic-gate * Now set the last header pointer to the proto passed in 48650Sstevel@tonic-gate */ 48660Sstevel@tonic-gate ASSERT((int)(cp - (uint8_t *)ip6i) == ip_hdr_len); 48670Sstevel@tonic-gate *nxthdr_ptr = icmp->icmp_proto; 48680Sstevel@tonic-gate 48690Sstevel@tonic-gate /* 48700Sstevel@tonic-gate * Copy in the destination address 48710Sstevel@tonic-gate */ 48721676Sjpk ip6h->ip6_dst = ip6_dst; 48730Sstevel@tonic-gate 48740Sstevel@tonic-gate ip6h->ip6_vcf = 48750Sstevel@tonic-gate (IPV6_DEFAULT_VERS_AND_FLOW & IPV6_VERS_AND_FLOW_MASK) | 48760Sstevel@tonic-gate (sin6->sin6_flowinfo & ~IPV6_VERS_AND_FLOW_MASK); 48770Sstevel@tonic-gate 48780Sstevel@tonic-gate if (option_exists & IPPF_TCLASS) { 48790Sstevel@tonic-gate tipp = ANCIL_OR_STICKY_PTR(IPPF_TCLASS); 48800Sstevel@tonic-gate ip6h->ip6_vcf = IPV6_TCLASS_FLOW(ip6h->ip6_vcf, 48810Sstevel@tonic-gate tipp->ipp_tclass); 48820Sstevel@tonic-gate } 48830Sstevel@tonic-gate if (option_exists & IPPF_RTHDR) { 48840Sstevel@tonic-gate ip6_rthdr_t *rth; 48850Sstevel@tonic-gate 48860Sstevel@tonic-gate /* 48870Sstevel@tonic-gate * Perform any processing needed for source routing. 48880Sstevel@tonic-gate * We know that all extension headers will be in the same mblk 48890Sstevel@tonic-gate * as the IPv6 header. 48900Sstevel@tonic-gate */ 48910Sstevel@tonic-gate rth = ip_find_rthdr_v6(ip6h, mp1->b_wptr); 48920Sstevel@tonic-gate if (rth != NULL && rth->ip6r_segleft != 0) { 48930Sstevel@tonic-gate if (rth->ip6r_type != IPV6_RTHDR_TYPE_0) { 48940Sstevel@tonic-gate /* 48950Sstevel@tonic-gate * Drop packet - only support Type 0 routing. 48960Sstevel@tonic-gate * Notify the application as well. 48970Sstevel@tonic-gate */ 48980Sstevel@tonic-gate icmp_ud_err(q, mp, EPROTO); 48990Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 49000Sstevel@tonic-gate return; 49010Sstevel@tonic-gate } 49020Sstevel@tonic-gate /* 49030Sstevel@tonic-gate * rth->ip6r_len is twice the number of 49040Sstevel@tonic-gate * addresses in the header 49050Sstevel@tonic-gate */ 49060Sstevel@tonic-gate if (rth->ip6r_len & 0x1) { 49070Sstevel@tonic-gate icmp_ud_err(q, mp, EPROTO); 49080Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 49090Sstevel@tonic-gate return; 49100Sstevel@tonic-gate } 49110Sstevel@tonic-gate /* 49120Sstevel@tonic-gate * Shuffle the routing header and ip6_dst 49130Sstevel@tonic-gate * addresses, and get the checksum difference 49140Sstevel@tonic-gate * between the first hop (in ip6_dst) and 49150Sstevel@tonic-gate * the destination (in the last routing hdr entry). 49160Sstevel@tonic-gate */ 49170Sstevel@tonic-gate csum = ip_massage_options_v6(ip6h, rth); 49180Sstevel@tonic-gate /* 49190Sstevel@tonic-gate * Verify that the first hop isn't a mapped address. 49200Sstevel@tonic-gate * Routers along the path need to do this verification 49210Sstevel@tonic-gate * for subsequent hops. 49220Sstevel@tonic-gate */ 49230Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&ip6h->ip6_dst)) { 49240Sstevel@tonic-gate icmp_ud_err(q, mp, EADDRNOTAVAIL); 49250Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 49260Sstevel@tonic-gate return; 49270Sstevel@tonic-gate } 49280Sstevel@tonic-gate } 49290Sstevel@tonic-gate } 49300Sstevel@tonic-gate 49310Sstevel@tonic-gate ip_len = mp1->b_wptr - (uchar_t *)ip6h - IPV6_HDR_LEN; 49320Sstevel@tonic-gate if (mp1->b_cont != NULL) 49330Sstevel@tonic-gate ip_len += msgdsize(mp1->b_cont); 49340Sstevel@tonic-gate 49350Sstevel@tonic-gate /* 49360Sstevel@tonic-gate * Set the length into the IP header. 49370Sstevel@tonic-gate * If the length is greater than the maximum allowed by IP, 49380Sstevel@tonic-gate * then free the message and return. Do not try and send it 49390Sstevel@tonic-gate * as this can cause problems in layers below. 49400Sstevel@tonic-gate */ 49410Sstevel@tonic-gate if (ip_len > IP_MAXPACKET) { 49420Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 49431289Sja97890 icmp_ud_err(q, mp, EMSGSIZE); 49440Sstevel@tonic-gate return; 49450Sstevel@tonic-gate } 49460Sstevel@tonic-gate if (icmp->icmp_proto == IPPROTO_ICMPV6 || icmp->icmp_raw_checksum) { 49470Sstevel@tonic-gate uint_t cksum_off; /* From ip6i == mp1->b_rptr */ 49480Sstevel@tonic-gate uint16_t *cksum_ptr; 49490Sstevel@tonic-gate uint_t ext_hdrs_len; 49500Sstevel@tonic-gate 49510Sstevel@tonic-gate /* ICMPv6 must have an offset matching icmp6_cksum offset */ 49520Sstevel@tonic-gate ASSERT(icmp->icmp_proto != IPPROTO_ICMPV6 || 49530Sstevel@tonic-gate icmp->icmp_checksum_off == 2); 49540Sstevel@tonic-gate 49550Sstevel@tonic-gate /* 49560Sstevel@tonic-gate * We make it easy for IP to include our pseudo header 49570Sstevel@tonic-gate * by putting our length in uh_checksum, modified (if 49580Sstevel@tonic-gate * we have a routing header) by the checksum difference 49590Sstevel@tonic-gate * between the ultimate destination and first hop addresses. 49600Sstevel@tonic-gate * Note: ICMPv6 must always checksum the packet. 49610Sstevel@tonic-gate */ 49620Sstevel@tonic-gate cksum_off = ip_hdr_len + icmp->icmp_checksum_off; 49630Sstevel@tonic-gate if (cksum_off + sizeof (uint16_t) > mp1->b_wptr - mp1->b_rptr) { 49640Sstevel@tonic-gate if (!pullupmsg(mp1, cksum_off + sizeof (uint16_t))) { 49650Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutErrors); 49660Sstevel@tonic-gate freemsg(mp); 49670Sstevel@tonic-gate return; 49680Sstevel@tonic-gate } 49690Sstevel@tonic-gate ip6i = (ip6i_t *)mp1->b_rptr; 49700Sstevel@tonic-gate if (ip6i->ip6i_nxt == IPPROTO_RAW) 49710Sstevel@tonic-gate ip6h = (ip6_t *)&ip6i[1]; 49720Sstevel@tonic-gate else 49730Sstevel@tonic-gate ip6h = (ip6_t *)ip6i; 49740Sstevel@tonic-gate } 49750Sstevel@tonic-gate /* Add payload length to checksum */ 49760Sstevel@tonic-gate ext_hdrs_len = ip_hdr_len - IPV6_HDR_LEN - 49770Sstevel@tonic-gate (int)((uchar_t *)ip6h - (uchar_t *)ip6i); 49780Sstevel@tonic-gate csum += htons(ip_len - ext_hdrs_len); 49790Sstevel@tonic-gate 49800Sstevel@tonic-gate cksum_ptr = (uint16_t *)((uchar_t *)ip6i + cksum_off); 49810Sstevel@tonic-gate csum = (csum & 0xFFFF) + (csum >> 16); 49820Sstevel@tonic-gate *cksum_ptr = (uint16_t)csum; 49830Sstevel@tonic-gate } 49840Sstevel@tonic-gate 49850Sstevel@tonic-gate #ifdef _LITTLE_ENDIAN 49860Sstevel@tonic-gate ip_len = htons(ip_len); 49870Sstevel@tonic-gate #endif 49880Sstevel@tonic-gate ip6h->ip6_plen = (uint16_t)ip_len; 49890Sstevel@tonic-gate 49900Sstevel@tonic-gate freeb(mp); 49910Sstevel@tonic-gate 49920Sstevel@tonic-gate /* We're done. Pass the packet to IP */ 49930Sstevel@tonic-gate BUMP_MIB(&rawip_mib, rawipOutDatagrams); 49941676Sjpk mblk_setcred(mp1, icmp->icmp_credp); 49950Sstevel@tonic-gate putnext(q, mp1); 49960Sstevel@tonic-gate } 49970Sstevel@tonic-gate 49980Sstevel@tonic-gate static void 49990Sstevel@tonic-gate icmp_wput_other(queue_t *q, mblk_t *mp) 50000Sstevel@tonic-gate { 50010Sstevel@tonic-gate uchar_t *rptr = mp->b_rptr; 50020Sstevel@tonic-gate struct iocblk *iocp; 50030Sstevel@tonic-gate #define tudr ((struct T_unitdata_req *)rptr) 50040Sstevel@tonic-gate icmp_t *icmp; 50050Sstevel@tonic-gate cred_t *cr; 50060Sstevel@tonic-gate 50070Sstevel@tonic-gate icmp = (icmp_t *)q->q_ptr; 50080Sstevel@tonic-gate 50090Sstevel@tonic-gate cr = DB_CREDDEF(mp, icmp->icmp_credp); 50100Sstevel@tonic-gate 50110Sstevel@tonic-gate switch (mp->b_datap->db_type) { 50120Sstevel@tonic-gate case M_PROTO: 50130Sstevel@tonic-gate case M_PCPROTO: 50140Sstevel@tonic-gate if (mp->b_wptr - rptr < sizeof (t_scalar_t)) { 50150Sstevel@tonic-gate /* 50160Sstevel@tonic-gate * If the message does not contain a PRIM_type, 50170Sstevel@tonic-gate * throw it away. 50180Sstevel@tonic-gate */ 50190Sstevel@tonic-gate freemsg(mp); 50200Sstevel@tonic-gate return; 50210Sstevel@tonic-gate } 50220Sstevel@tonic-gate switch (((union T_primitives *)rptr)->type) { 50230Sstevel@tonic-gate case T_ADDR_REQ: 50240Sstevel@tonic-gate icmp_addr_req(q, mp); 50250Sstevel@tonic-gate return; 50260Sstevel@tonic-gate case O_T_BIND_REQ: 50270Sstevel@tonic-gate case T_BIND_REQ: 50280Sstevel@tonic-gate qwriter(q, mp, icmp_bind, PERIM_OUTER); 50290Sstevel@tonic-gate return; 50300Sstevel@tonic-gate case T_CONN_REQ: 50310Sstevel@tonic-gate icmp_connect(q, mp); 50320Sstevel@tonic-gate return; 50330Sstevel@tonic-gate case T_CAPABILITY_REQ: 50340Sstevel@tonic-gate icmp_capability_req(q, mp); 50350Sstevel@tonic-gate return; 50360Sstevel@tonic-gate case T_INFO_REQ: 50370Sstevel@tonic-gate icmp_info_req(q, mp); 50380Sstevel@tonic-gate return; 50390Sstevel@tonic-gate case T_UNITDATA_REQ: 50400Sstevel@tonic-gate /* 50410Sstevel@tonic-gate * If a T_UNITDATA_REQ gets here, the address must 50420Sstevel@tonic-gate * be bad. Valid T_UNITDATA_REQs are found above 50430Sstevel@tonic-gate * and break to below this switch. 50440Sstevel@tonic-gate */ 50450Sstevel@tonic-gate icmp_ud_err(q, mp, EADDRNOTAVAIL); 50460Sstevel@tonic-gate return; 50470Sstevel@tonic-gate case T_UNBIND_REQ: 50480Sstevel@tonic-gate icmp_unbind(q, mp); 50490Sstevel@tonic-gate return; 50500Sstevel@tonic-gate 50510Sstevel@tonic-gate case T_SVR4_OPTMGMT_REQ: 50520Sstevel@tonic-gate if (!snmpcom_req(q, mp, icmp_snmp_set, icmp_snmp_get, 50530Sstevel@tonic-gate cr)) 50540Sstevel@tonic-gate /* Only IP can return anything meaningful */ 50550Sstevel@tonic-gate (void) svr4_optcom_req(q, mp, cr, 50560Sstevel@tonic-gate &icmp_opt_obj); 50570Sstevel@tonic-gate return; 50580Sstevel@tonic-gate 50590Sstevel@tonic-gate case T_OPTMGMT_REQ: 50600Sstevel@tonic-gate /* Only IP can return anything meaningful */ 50610Sstevel@tonic-gate (void) tpi_optcom_req(q, mp, cr, &icmp_opt_obj); 50620Sstevel@tonic-gate return; 50630Sstevel@tonic-gate 50640Sstevel@tonic-gate case T_DISCON_REQ: 50650Sstevel@tonic-gate icmp_disconnect(q, mp); 50660Sstevel@tonic-gate return; 50670Sstevel@tonic-gate 50680Sstevel@tonic-gate /* The following TPI message is not supported by icmp. */ 50690Sstevel@tonic-gate case O_T_CONN_RES: 50700Sstevel@tonic-gate case T_CONN_RES: 50710Sstevel@tonic-gate icmp_err_ack(q, mp, TNOTSUPPORT, 0); 50720Sstevel@tonic-gate return; 50730Sstevel@tonic-gate 50740Sstevel@tonic-gate /* The following 3 TPI requests are illegal for icmp. */ 50750Sstevel@tonic-gate case T_DATA_REQ: 50760Sstevel@tonic-gate case T_EXDATA_REQ: 50770Sstevel@tonic-gate case T_ORDREL_REQ: 50780Sstevel@tonic-gate freemsg(mp); 50790Sstevel@tonic-gate (void) putctl1(RD(q), M_ERROR, EPROTO); 50800Sstevel@tonic-gate return; 50810Sstevel@tonic-gate default: 50820Sstevel@tonic-gate break; 50830Sstevel@tonic-gate } 50840Sstevel@tonic-gate break; 50850Sstevel@tonic-gate case M_IOCTL: 50860Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr; 50870Sstevel@tonic-gate switch (iocp->ioc_cmd) { 50880Sstevel@tonic-gate case TI_GETPEERNAME: 50890Sstevel@tonic-gate if (icmp->icmp_state != TS_DATA_XFER) { 50900Sstevel@tonic-gate /* 50910Sstevel@tonic-gate * If a default destination address has not 50920Sstevel@tonic-gate * been associated with the stream, then we 50930Sstevel@tonic-gate * don't know the peer's name. 50940Sstevel@tonic-gate */ 50950Sstevel@tonic-gate iocp->ioc_error = ENOTCONN; 50960Sstevel@tonic-gate err_ret:; 50970Sstevel@tonic-gate iocp->ioc_count = 0; 50980Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 50990Sstevel@tonic-gate qreply(q, mp); 51000Sstevel@tonic-gate return; 51010Sstevel@tonic-gate } 51020Sstevel@tonic-gate /* FALLTHRU */ 51030Sstevel@tonic-gate case TI_GETMYNAME: 51040Sstevel@tonic-gate /* 51050Sstevel@tonic-gate * For TI_GETPEERNAME and TI_GETMYNAME, we first 51060Sstevel@tonic-gate * need to copyin the user's strbuf structure. 51070Sstevel@tonic-gate * Processing will continue in the M_IOCDATA case 51080Sstevel@tonic-gate * below. 51090Sstevel@tonic-gate */ 51100Sstevel@tonic-gate mi_copyin(q, mp, NULL, 51110Sstevel@tonic-gate SIZEOF_STRUCT(strbuf, iocp->ioc_flag)); 51120Sstevel@tonic-gate return; 51130Sstevel@tonic-gate case ND_SET: 51140Sstevel@tonic-gate /* nd_getset performs the necessary error checking */ 51150Sstevel@tonic-gate case ND_GET: 51160Sstevel@tonic-gate if (nd_getset(q, icmp_g_nd, mp)) { 51170Sstevel@tonic-gate qreply(q, mp); 51180Sstevel@tonic-gate return; 51190Sstevel@tonic-gate } 51200Sstevel@tonic-gate break; 51210Sstevel@tonic-gate default: 51220Sstevel@tonic-gate break; 51230Sstevel@tonic-gate } 51240Sstevel@tonic-gate break; 51250Sstevel@tonic-gate case M_IOCDATA: 51260Sstevel@tonic-gate icmp_wput_iocdata(q, mp); 51270Sstevel@tonic-gate return; 51280Sstevel@tonic-gate default: 51290Sstevel@tonic-gate break; 51300Sstevel@tonic-gate } 51310Sstevel@tonic-gate putnext(q, mp); 51320Sstevel@tonic-gate } 51330Sstevel@tonic-gate 51340Sstevel@tonic-gate /* 51350Sstevel@tonic-gate * icmp_wput_iocdata is called by icmp_wput_slow to handle all M_IOCDATA 51360Sstevel@tonic-gate * messages. 51370Sstevel@tonic-gate */ 51380Sstevel@tonic-gate static void 51390Sstevel@tonic-gate icmp_wput_iocdata(queue_t *q, mblk_t *mp) 51400Sstevel@tonic-gate { 51410Sstevel@tonic-gate mblk_t *mp1; 51420Sstevel@tonic-gate STRUCT_HANDLE(strbuf, sb); 51430Sstevel@tonic-gate icmp_t *icmp; 51440Sstevel@tonic-gate in6_addr_t v6addr; 51450Sstevel@tonic-gate ipaddr_t v4addr; 51460Sstevel@tonic-gate uint32_t flowinfo = 0; 51470Sstevel@tonic-gate int addrlen; 51480Sstevel@tonic-gate 51490Sstevel@tonic-gate /* Make sure it is one of ours. */ 51500Sstevel@tonic-gate switch (((struct iocblk *)mp->b_rptr)->ioc_cmd) { 51510Sstevel@tonic-gate case TI_GETMYNAME: 51520Sstevel@tonic-gate case TI_GETPEERNAME: 51530Sstevel@tonic-gate break; 51540Sstevel@tonic-gate default: 51550Sstevel@tonic-gate putnext(q, mp); 51560Sstevel@tonic-gate return; 51570Sstevel@tonic-gate } 51580Sstevel@tonic-gate switch (mi_copy_state(q, mp, &mp1)) { 51590Sstevel@tonic-gate case -1: 51600Sstevel@tonic-gate return; 51610Sstevel@tonic-gate case MI_COPY_CASE(MI_COPY_IN, 1): 51620Sstevel@tonic-gate break; 51630Sstevel@tonic-gate case MI_COPY_CASE(MI_COPY_OUT, 1): 51640Sstevel@tonic-gate /* 51650Sstevel@tonic-gate * The address has been copied out, so now 51660Sstevel@tonic-gate * copyout the strbuf. 51670Sstevel@tonic-gate */ 51680Sstevel@tonic-gate mi_copyout(q, mp); 51690Sstevel@tonic-gate return; 51700Sstevel@tonic-gate case MI_COPY_CASE(MI_COPY_OUT, 2): 51710Sstevel@tonic-gate /* 51720Sstevel@tonic-gate * The address and strbuf have been copied out. 51730Sstevel@tonic-gate * We're done, so just acknowledge the original 51740Sstevel@tonic-gate * M_IOCTL. 51750Sstevel@tonic-gate */ 51760Sstevel@tonic-gate mi_copy_done(q, mp, 0); 51770Sstevel@tonic-gate return; 51780Sstevel@tonic-gate default: 51790Sstevel@tonic-gate /* 51800Sstevel@tonic-gate * Something strange has happened, so acknowledge 51810Sstevel@tonic-gate * the original M_IOCTL with an EPROTO error. 51820Sstevel@tonic-gate */ 51830Sstevel@tonic-gate mi_copy_done(q, mp, EPROTO); 51840Sstevel@tonic-gate return; 51850Sstevel@tonic-gate } 51860Sstevel@tonic-gate /* 51870Sstevel@tonic-gate * Now we have the strbuf structure for TI_GETMYNAME 51880Sstevel@tonic-gate * and TI_GETPEERNAME. Next we copyout the requested 51890Sstevel@tonic-gate * address and then we'll copyout the strbuf. 51900Sstevel@tonic-gate */ 51910Sstevel@tonic-gate STRUCT_SET_HANDLE(sb, ((struct iocblk *)mp->b_rptr)->ioc_flag, 51920Sstevel@tonic-gate (void *)mp1->b_rptr); 51930Sstevel@tonic-gate icmp = (icmp_t *)q->q_ptr; 51940Sstevel@tonic-gate if (icmp->icmp_family == AF_INET) 51950Sstevel@tonic-gate addrlen = sizeof (sin_t); 51960Sstevel@tonic-gate else 51970Sstevel@tonic-gate addrlen = sizeof (sin6_t); 51980Sstevel@tonic-gate 51990Sstevel@tonic-gate if (STRUCT_FGET(sb, maxlen) < addrlen) { 52000Sstevel@tonic-gate mi_copy_done(q, mp, EINVAL); 52010Sstevel@tonic-gate return; 52020Sstevel@tonic-gate } 52030Sstevel@tonic-gate switch (((struct iocblk *)mp->b_rptr)->ioc_cmd) { 52040Sstevel@tonic-gate case TI_GETMYNAME: 52050Sstevel@tonic-gate if (icmp->icmp_family == AF_INET) { 52060Sstevel@tonic-gate ASSERT(icmp->icmp_ipversion == IPV4_VERSION); 52070Sstevel@tonic-gate if (!IN6_IS_ADDR_V4MAPPED_ANY(&icmp->icmp_v6src) && 52080Sstevel@tonic-gate !IN6_IS_ADDR_UNSPECIFIED(&icmp->icmp_v6src)) { 52090Sstevel@tonic-gate v4addr = V4_PART_OF_V6(icmp->icmp_v6src); 52100Sstevel@tonic-gate } else { 52110Sstevel@tonic-gate /* 52120Sstevel@tonic-gate * INADDR_ANY 52130Sstevel@tonic-gate * icmp_v6src is not set, we might be bound to 52140Sstevel@tonic-gate * broadcast/multicast. Use icmp_bound_v6src as 52150Sstevel@tonic-gate * local address instead (that could 52160Sstevel@tonic-gate * also still be INADDR_ANY) 52170Sstevel@tonic-gate */ 52180Sstevel@tonic-gate v4addr = V4_PART_OF_V6(icmp->icmp_bound_v6src); 52190Sstevel@tonic-gate } 52200Sstevel@tonic-gate } else { 52210Sstevel@tonic-gate /* icmp->icmp_family == AF_INET6 */ 52220Sstevel@tonic-gate if (!IN6_IS_ADDR_UNSPECIFIED(&icmp->icmp_v6src)) { 52230Sstevel@tonic-gate v6addr = icmp->icmp_v6src; 52240Sstevel@tonic-gate } else { 52250Sstevel@tonic-gate /* 52260Sstevel@tonic-gate * UNSPECIFIED 52270Sstevel@tonic-gate * icmp_v6src is not set, we might be bound to 52280Sstevel@tonic-gate * broadcast/multicast. Use icmp_bound_v6src as 52290Sstevel@tonic-gate * local address instead (that could 52300Sstevel@tonic-gate * also still be UNSPECIFIED) 52310Sstevel@tonic-gate */ 52320Sstevel@tonic-gate v6addr = icmp->icmp_bound_v6src; 52330Sstevel@tonic-gate } 52340Sstevel@tonic-gate } 52350Sstevel@tonic-gate break; 52360Sstevel@tonic-gate case TI_GETPEERNAME: 52370Sstevel@tonic-gate if (icmp->icmp_family == AF_INET) { 52380Sstevel@tonic-gate ASSERT(icmp->icmp_ipversion == IPV4_VERSION); 52390Sstevel@tonic-gate v4addr = V4_PART_OF_V6(icmp->icmp_v6dst); 52400Sstevel@tonic-gate } else { 52410Sstevel@tonic-gate /* icmp->icmp_family == AF_INET6) */ 52420Sstevel@tonic-gate v6addr = icmp->icmp_v6dst; 52430Sstevel@tonic-gate flowinfo = icmp->icmp_flowinfo; 52440Sstevel@tonic-gate } 52450Sstevel@tonic-gate break; 52460Sstevel@tonic-gate default: 52470Sstevel@tonic-gate mi_copy_done(q, mp, EPROTO); 52480Sstevel@tonic-gate return; 52490Sstevel@tonic-gate } 52500Sstevel@tonic-gate mp1 = mi_copyout_alloc(q, mp, STRUCT_FGETP(sb, buf), addrlen, B_TRUE); 52510Sstevel@tonic-gate if (!mp1) 52520Sstevel@tonic-gate return; 52530Sstevel@tonic-gate 52540Sstevel@tonic-gate if (icmp->icmp_family == AF_INET) { 52550Sstevel@tonic-gate sin_t *sin; 52560Sstevel@tonic-gate 52570Sstevel@tonic-gate STRUCT_FSET(sb, len, (int)sizeof (sin_t)); 52580Sstevel@tonic-gate sin = (sin_t *)mp1->b_rptr; 52590Sstevel@tonic-gate mp1->b_wptr = (uchar_t *)&sin[1]; 52600Sstevel@tonic-gate *sin = sin_null; 52610Sstevel@tonic-gate sin->sin_family = AF_INET; 52620Sstevel@tonic-gate sin->sin_addr.s_addr = v4addr; 52630Sstevel@tonic-gate } else { 52640Sstevel@tonic-gate /* icmp->icmp_family == AF_INET6 */ 52650Sstevel@tonic-gate sin6_t *sin6; 52660Sstevel@tonic-gate 52670Sstevel@tonic-gate ASSERT(icmp->icmp_family == AF_INET6); 52680Sstevel@tonic-gate STRUCT_FSET(sb, len, (int)sizeof (sin6_t)); 52690Sstevel@tonic-gate sin6 = (sin6_t *)mp1->b_rptr; 52700Sstevel@tonic-gate mp1->b_wptr = (uchar_t *)&sin6[1]; 52710Sstevel@tonic-gate *sin6 = sin6_null; 52720Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 52730Sstevel@tonic-gate sin6->sin6_flowinfo = flowinfo; 52740Sstevel@tonic-gate sin6->sin6_addr = v6addr; 52750Sstevel@tonic-gate } 52760Sstevel@tonic-gate /* Copy out the address */ 52770Sstevel@tonic-gate mi_copyout(q, mp); 52780Sstevel@tonic-gate } 52790Sstevel@tonic-gate 52800Sstevel@tonic-gate /* 52810Sstevel@tonic-gate * Only allow MIB requests and M_FLUSHes to pass. 52820Sstevel@tonic-gate * All other messages are nacked or dropped. 52830Sstevel@tonic-gate */ 52840Sstevel@tonic-gate static void 52850Sstevel@tonic-gate icmp_wput_restricted(queue_t *q, mblk_t *mp) 52860Sstevel@tonic-gate { 52870Sstevel@tonic-gate cred_t *cr; 52880Sstevel@tonic-gate icmp_t *icmp; 52890Sstevel@tonic-gate 52900Sstevel@tonic-gate switch (DB_TYPE(mp)) { 52910Sstevel@tonic-gate case M_PROTO: 52920Sstevel@tonic-gate case M_PCPROTO: 52930Sstevel@tonic-gate if (MBLKL(mp) < sizeof (t_scalar_t)) { 52940Sstevel@tonic-gate freemsg(mp); 52950Sstevel@tonic-gate return; 52960Sstevel@tonic-gate } 52970Sstevel@tonic-gate icmp = (icmp_t *)q->q_ptr; 52980Sstevel@tonic-gate cr = DB_CREDDEF(mp, icmp->icmp_credp); 52990Sstevel@tonic-gate 53000Sstevel@tonic-gate switch (((union T_primitives *)mp->b_rptr)->type) { 53010Sstevel@tonic-gate case T_SVR4_OPTMGMT_REQ: 53020Sstevel@tonic-gate if (!snmpcom_req(q, mp, 53030Sstevel@tonic-gate icmp_snmp_set, icmp_snmp_get, cr)) 53040Sstevel@tonic-gate (void) svr4_optcom_req(q, mp, cr, 53050Sstevel@tonic-gate &icmp_opt_obj); 53060Sstevel@tonic-gate return; 53070Sstevel@tonic-gate case T_OPTMGMT_REQ: 53080Sstevel@tonic-gate (void) tpi_optcom_req(q, mp, cr, &icmp_opt_obj); 53090Sstevel@tonic-gate return; 53100Sstevel@tonic-gate default: 53110Sstevel@tonic-gate icmp_err_ack(q, mp, TSYSERR, ENOTSUP); 53120Sstevel@tonic-gate return; 53130Sstevel@tonic-gate } 53140Sstevel@tonic-gate /* NOTREACHED */ 53150Sstevel@tonic-gate case M_IOCTL: 53160Sstevel@tonic-gate miocnak(q, mp, 0, ENOTSUP); 53170Sstevel@tonic-gate break; 53180Sstevel@tonic-gate case M_FLUSH: 53190Sstevel@tonic-gate putnext(q, mp); 53200Sstevel@tonic-gate break; 53210Sstevel@tonic-gate default: 53220Sstevel@tonic-gate freemsg(mp); 53230Sstevel@tonic-gate break; 53240Sstevel@tonic-gate } 53250Sstevel@tonic-gate } 53260Sstevel@tonic-gate 53270Sstevel@tonic-gate static int 53280Sstevel@tonic-gate icmp_unitdata_opt_process(queue_t *q, mblk_t *mp, int *errorp, 53290Sstevel@tonic-gate void *thisdg_attrs) 53300Sstevel@tonic-gate { 53310Sstevel@tonic-gate icmp_t *icmp; 53320Sstevel@tonic-gate struct T_unitdata_req *udreqp; 53330Sstevel@tonic-gate int is_absreq_failure; 53340Sstevel@tonic-gate cred_t *cr; 53350Sstevel@tonic-gate 53360Sstevel@tonic-gate icmp = (icmp_t *)q->q_ptr; 53370Sstevel@tonic-gate 53380Sstevel@tonic-gate udreqp = (struct T_unitdata_req *)mp->b_rptr; 53390Sstevel@tonic-gate *errorp = 0; 53400Sstevel@tonic-gate 53410Sstevel@tonic-gate cr = DB_CREDDEF(mp, icmp->icmp_credp); 53420Sstevel@tonic-gate 53430Sstevel@tonic-gate *errorp = tpi_optcom_buf(q, mp, &udreqp->OPT_length, 53440Sstevel@tonic-gate udreqp->OPT_offset, cr, &icmp_opt_obj, 53450Sstevel@tonic-gate thisdg_attrs, &is_absreq_failure); 53460Sstevel@tonic-gate 53470Sstevel@tonic-gate if (*errorp != 0) { 53480Sstevel@tonic-gate /* 53490Sstevel@tonic-gate * Note: No special action needed in this 53500Sstevel@tonic-gate * module for "is_absreq_failure" 53510Sstevel@tonic-gate */ 53520Sstevel@tonic-gate return (-1); /* failure */ 53530Sstevel@tonic-gate } 53540Sstevel@tonic-gate ASSERT(is_absreq_failure == 0); 53550Sstevel@tonic-gate return (0); /* success */ 53560Sstevel@tonic-gate } 53570Sstevel@tonic-gate 53580Sstevel@tonic-gate void 53590Sstevel@tonic-gate icmp_ddi_init(void) 53600Sstevel@tonic-gate { 53610Sstevel@tonic-gate ICMP6_MAJ = ddi_name_to_major(ICMP6); 53620Sstevel@tonic-gate icmp_max_optsize = 53630Sstevel@tonic-gate optcom_max_optsize(icmp_opt_obj.odb_opt_des_arr, 53640Sstevel@tonic-gate icmp_opt_obj.odb_opt_arr_cnt); 53650Sstevel@tonic-gate 53660Sstevel@tonic-gate (void) icmp_param_register(icmp_param_arr, A_CNT(icmp_param_arr)); 53670Sstevel@tonic-gate 53680Sstevel@tonic-gate rawip_kstat_init(); 53690Sstevel@tonic-gate } 53700Sstevel@tonic-gate 53710Sstevel@tonic-gate void 53720Sstevel@tonic-gate icmp_ddi_destroy(void) 53730Sstevel@tonic-gate { 53740Sstevel@tonic-gate nd_free(&icmp_g_nd); 53750Sstevel@tonic-gate 53760Sstevel@tonic-gate rawip_kstat_fini(); 53770Sstevel@tonic-gate } 53780Sstevel@tonic-gate 53790Sstevel@tonic-gate static void 53800Sstevel@tonic-gate rawip_kstat_init(void) { 53810Sstevel@tonic-gate 53820Sstevel@tonic-gate rawip_named_kstat_t template = { 53830Sstevel@tonic-gate { "inDatagrams", KSTAT_DATA_UINT32, 0 }, 53840Sstevel@tonic-gate { "inCksumErrs", KSTAT_DATA_UINT32, 0 }, 53850Sstevel@tonic-gate { "inErrors", KSTAT_DATA_UINT32, 0 }, 53860Sstevel@tonic-gate { "outDatagrams", KSTAT_DATA_UINT32, 0 }, 53870Sstevel@tonic-gate { "outErrors", KSTAT_DATA_UINT32, 0 }, 53880Sstevel@tonic-gate }; 53890Sstevel@tonic-gate 53900Sstevel@tonic-gate rawip_mibkp = kstat_create("icmp", 0, "rawip", "mib2", 53910Sstevel@tonic-gate KSTAT_TYPE_NAMED, 53920Sstevel@tonic-gate NUM_OF_FIELDS(rawip_named_kstat_t), 53930Sstevel@tonic-gate 0); 53940Sstevel@tonic-gate if (rawip_mibkp == NULL) 53950Sstevel@tonic-gate return; 53960Sstevel@tonic-gate 53970Sstevel@tonic-gate bcopy(&template, rawip_mibkp->ks_data, sizeof (template)); 53980Sstevel@tonic-gate 53990Sstevel@tonic-gate rawip_mibkp->ks_update = rawip_kstat_update; 54000Sstevel@tonic-gate 54010Sstevel@tonic-gate kstat_install(rawip_mibkp); 54020Sstevel@tonic-gate } 54030Sstevel@tonic-gate 54040Sstevel@tonic-gate static void 54050Sstevel@tonic-gate rawip_kstat_fini(void) { 54060Sstevel@tonic-gate if (rawip_mibkp) { 54070Sstevel@tonic-gate kstat_delete(rawip_mibkp); 54080Sstevel@tonic-gate rawip_mibkp = NULL; 54090Sstevel@tonic-gate } 54100Sstevel@tonic-gate } 54110Sstevel@tonic-gate 54120Sstevel@tonic-gate static int 54130Sstevel@tonic-gate rawip_kstat_update(kstat_t *kp, int rw) { 54140Sstevel@tonic-gate rawip_named_kstat_t *rawipkp; 54150Sstevel@tonic-gate 54160Sstevel@tonic-gate if ((kp == NULL) || (kp->ks_data == NULL)) 54170Sstevel@tonic-gate return (EIO); 54180Sstevel@tonic-gate 54190Sstevel@tonic-gate if (rw == KSTAT_WRITE) 54200Sstevel@tonic-gate return (EACCES); 54210Sstevel@tonic-gate 54220Sstevel@tonic-gate rawipkp = (rawip_named_kstat_t *)kp->ks_data; 54230Sstevel@tonic-gate 54240Sstevel@tonic-gate rawipkp->inDatagrams.value.ui32 = rawip_mib.rawipInDatagrams; 54250Sstevel@tonic-gate rawipkp->inCksumErrs.value.ui32 = rawip_mib.rawipInCksumErrs; 54260Sstevel@tonic-gate rawipkp->inErrors.value.ui32 = rawip_mib.rawipInErrors; 54270Sstevel@tonic-gate rawipkp->outDatagrams.value.ui32 = rawip_mib.rawipOutDatagrams; 54280Sstevel@tonic-gate rawipkp->outErrors.value.ui32 = rawip_mib.rawipOutErrors; 54290Sstevel@tonic-gate 54300Sstevel@tonic-gate return (0); 54310Sstevel@tonic-gate } 5432