xref: /onnv-gate/usr/src/uts/common/inet/ip/ip6_input.c (revision 12339:07dcda070d15)
111042SErik.Nordmark@Sun.COM /*
211042SErik.Nordmark@Sun.COM  * CDDL HEADER START
311042SErik.Nordmark@Sun.COM  *
411042SErik.Nordmark@Sun.COM  * The contents of this file are subject to the terms of the
511042SErik.Nordmark@Sun.COM  * Common Development and Distribution License (the "License").
611042SErik.Nordmark@Sun.COM  * You may not use this file except in compliance with the License.
711042SErik.Nordmark@Sun.COM  *
811042SErik.Nordmark@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
911042SErik.Nordmark@Sun.COM  * or http://www.opensolaris.org/os/licensing.
1011042SErik.Nordmark@Sun.COM  * See the License for the specific language governing permissions
1111042SErik.Nordmark@Sun.COM  * and limitations under the License.
1211042SErik.Nordmark@Sun.COM  *
1311042SErik.Nordmark@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
1411042SErik.Nordmark@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1511042SErik.Nordmark@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
1611042SErik.Nordmark@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
1711042SErik.Nordmark@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
1811042SErik.Nordmark@Sun.COM  *
1911042SErik.Nordmark@Sun.COM  * CDDL HEADER END
2011042SErik.Nordmark@Sun.COM  */
2111042SErik.Nordmark@Sun.COM 
2211042SErik.Nordmark@Sun.COM /*
23*12339Sanil.udupa@sun.com  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved
2411042SErik.Nordmark@Sun.COM  */
2511042SErik.Nordmark@Sun.COM /* Copyright (c) 1990 Mentat Inc. */
2611042SErik.Nordmark@Sun.COM 
2711042SErik.Nordmark@Sun.COM #include <sys/types.h>
2811042SErik.Nordmark@Sun.COM #include <sys/stream.h>
2911042SErik.Nordmark@Sun.COM #include <sys/dlpi.h>
3011042SErik.Nordmark@Sun.COM #include <sys/stropts.h>
3111042SErik.Nordmark@Sun.COM #include <sys/sysmacros.h>
3211042SErik.Nordmark@Sun.COM #include <sys/strsubr.h>
3311042SErik.Nordmark@Sun.COM #include <sys/strlog.h>
3411042SErik.Nordmark@Sun.COM #include <sys/strsun.h>
3511042SErik.Nordmark@Sun.COM #include <sys/zone.h>
3611042SErik.Nordmark@Sun.COM #define	_SUN_TPI_VERSION 2
3711042SErik.Nordmark@Sun.COM #include <sys/tihdr.h>
3811042SErik.Nordmark@Sun.COM #include <sys/xti_inet.h>
3911042SErik.Nordmark@Sun.COM #include <sys/ddi.h>
4011042SErik.Nordmark@Sun.COM #include <sys/sunddi.h>
4111042SErik.Nordmark@Sun.COM #include <sys/cmn_err.h>
4211042SErik.Nordmark@Sun.COM #include <sys/debug.h>
4311042SErik.Nordmark@Sun.COM #include <sys/kobj.h>
4411042SErik.Nordmark@Sun.COM #include <sys/modctl.h>
4511042SErik.Nordmark@Sun.COM #include <sys/atomic.h>
4611042SErik.Nordmark@Sun.COM #include <sys/policy.h>
4711042SErik.Nordmark@Sun.COM #include <sys/priv.h>
4811042SErik.Nordmark@Sun.COM 
4911042SErik.Nordmark@Sun.COM #include <sys/systm.h>
5011042SErik.Nordmark@Sun.COM #include <sys/param.h>
5111042SErik.Nordmark@Sun.COM #include <sys/kmem.h>
5211042SErik.Nordmark@Sun.COM #include <sys/sdt.h>
5311042SErik.Nordmark@Sun.COM #include <sys/socket.h>
5411042SErik.Nordmark@Sun.COM #include <sys/vtrace.h>
5511042SErik.Nordmark@Sun.COM #include <sys/isa_defs.h>
5611042SErik.Nordmark@Sun.COM #include <sys/mac.h>
5711042SErik.Nordmark@Sun.COM #include <net/if.h>
5811042SErik.Nordmark@Sun.COM #include <net/if_arp.h>
5911042SErik.Nordmark@Sun.COM #include <net/route.h>
6011042SErik.Nordmark@Sun.COM #include <sys/sockio.h>
6111042SErik.Nordmark@Sun.COM #include <netinet/in.h>
6211042SErik.Nordmark@Sun.COM #include <net/if_dl.h>
6311042SErik.Nordmark@Sun.COM 
6411042SErik.Nordmark@Sun.COM #include <inet/common.h>
6511042SErik.Nordmark@Sun.COM #include <inet/mi.h>
6611042SErik.Nordmark@Sun.COM #include <inet/mib2.h>
6711042SErik.Nordmark@Sun.COM #include <inet/nd.h>
6811042SErik.Nordmark@Sun.COM #include <inet/arp.h>
6911042SErik.Nordmark@Sun.COM #include <inet/snmpcom.h>
7011042SErik.Nordmark@Sun.COM #include <inet/kstatcom.h>
7111042SErik.Nordmark@Sun.COM 
7211042SErik.Nordmark@Sun.COM #include <netinet/igmp_var.h>
7311042SErik.Nordmark@Sun.COM #include <netinet/ip6.h>
7411042SErik.Nordmark@Sun.COM #include <netinet/icmp6.h>
7511042SErik.Nordmark@Sun.COM #include <netinet/sctp.h>
7611042SErik.Nordmark@Sun.COM 
7711042SErik.Nordmark@Sun.COM #include <inet/ip.h>
7811042SErik.Nordmark@Sun.COM #include <inet/ip_impl.h>
7911042SErik.Nordmark@Sun.COM #include <inet/ip6.h>
8011042SErik.Nordmark@Sun.COM #include <inet/ip6_asp.h>
8111042SErik.Nordmark@Sun.COM #include <inet/optcom.h>
8211042SErik.Nordmark@Sun.COM #include <inet/tcp.h>
8311042SErik.Nordmark@Sun.COM #include <inet/tcp_impl.h>
8411042SErik.Nordmark@Sun.COM #include <inet/ip_multi.h>
8511042SErik.Nordmark@Sun.COM #include <inet/ip_if.h>
8611042SErik.Nordmark@Sun.COM #include <inet/ip_ire.h>
8711042SErik.Nordmark@Sun.COM #include <inet/ip_ftable.h>
8811042SErik.Nordmark@Sun.COM #include <inet/ip_rts.h>
8911042SErik.Nordmark@Sun.COM #include <inet/ip_ndp.h>
9011042SErik.Nordmark@Sun.COM #include <inet/ip_listutils.h>
9111042SErik.Nordmark@Sun.COM #include <netinet/igmp.h>
9211042SErik.Nordmark@Sun.COM #include <netinet/ip_mroute.h>
9311042SErik.Nordmark@Sun.COM #include <inet/ipp_common.h>
9411042SErik.Nordmark@Sun.COM 
9511042SErik.Nordmark@Sun.COM #include <net/pfkeyv2.h>
9611042SErik.Nordmark@Sun.COM #include <inet/sadb.h>
9711042SErik.Nordmark@Sun.COM #include <inet/ipsec_impl.h>
9811042SErik.Nordmark@Sun.COM #include <inet/ipdrop.h>
9911042SErik.Nordmark@Sun.COM #include <inet/ip_netinfo.h>
10011042SErik.Nordmark@Sun.COM #include <inet/ilb_ip.h>
10111042SErik.Nordmark@Sun.COM #include <sys/squeue_impl.h>
10211042SErik.Nordmark@Sun.COM #include <sys/squeue.h>
10311042SErik.Nordmark@Sun.COM 
10411042SErik.Nordmark@Sun.COM #include <sys/ethernet.h>
10511042SErik.Nordmark@Sun.COM #include <net/if_types.h>
10611042SErik.Nordmark@Sun.COM #include <sys/cpuvar.h>
10711042SErik.Nordmark@Sun.COM 
10811042SErik.Nordmark@Sun.COM #include <ipp/ipp.h>
10911042SErik.Nordmark@Sun.COM #include <ipp/ipp_impl.h>
11011042SErik.Nordmark@Sun.COM #include <ipp/ipgpc/ipgpc.h>
11111042SErik.Nordmark@Sun.COM 
11211042SErik.Nordmark@Sun.COM #include <sys/pattr.h>
11311042SErik.Nordmark@Sun.COM #include <inet/ipclassifier.h>
11411042SErik.Nordmark@Sun.COM #include <inet/sctp_ip.h>
11511042SErik.Nordmark@Sun.COM #include <inet/sctp/sctp_impl.h>
11611042SErik.Nordmark@Sun.COM #include <inet/udp_impl.h>
11711042SErik.Nordmark@Sun.COM #include <sys/sunddi.h>
11811042SErik.Nordmark@Sun.COM 
11911042SErik.Nordmark@Sun.COM #include <sys/tsol/label.h>
12011042SErik.Nordmark@Sun.COM #include <sys/tsol/tnet.h>
12111042SErik.Nordmark@Sun.COM 
12211110SErik.Nordmark@Sun.COM #include <sys/clock_impl.h>	/* For LBOLT_FASTPATH{,64} */
12311042SErik.Nordmark@Sun.COM 
12411042SErik.Nordmark@Sun.COM #ifdef	DEBUG
12511042SErik.Nordmark@Sun.COM extern boolean_t skip_sctp_cksum;
12611042SErik.Nordmark@Sun.COM #endif
12711042SErik.Nordmark@Sun.COM 
12811042SErik.Nordmark@Sun.COM static void	ip_input_local_v6(ire_t *, mblk_t *, ip6_t *, ip_recv_attr_t *);
12911042SErik.Nordmark@Sun.COM 
13011042SErik.Nordmark@Sun.COM static void	ip_input_multicast_v6(ire_t *, mblk_t *, ip6_t *,
13111042SErik.Nordmark@Sun.COM     ip_recv_attr_t *);
13211042SErik.Nordmark@Sun.COM 
13311042SErik.Nordmark@Sun.COM #pragma inline(ip_input_common_v6, ip_input_local_v6, ip_forward_xmit_v6)
13411042SErik.Nordmark@Sun.COM 
13511042SErik.Nordmark@Sun.COM /*
13611042SErik.Nordmark@Sun.COM  * Direct read side procedure capable of dealing with chains. GLDv3 based
13711042SErik.Nordmark@Sun.COM  * drivers call this function directly with mblk chains while STREAMS
13811042SErik.Nordmark@Sun.COM  * read side procedure ip_rput() calls this for single packet with ip_ring
13911042SErik.Nordmark@Sun.COM  * set to NULL to process one packet at a time.
14011042SErik.Nordmark@Sun.COM  *
14111042SErik.Nordmark@Sun.COM  * The ill will always be valid if this function is called directly from
14211042SErik.Nordmark@Sun.COM  * the driver.
14311042SErik.Nordmark@Sun.COM  *
14411042SErik.Nordmark@Sun.COM  * If ip_input_v6() is called from GLDv3:
14511042SErik.Nordmark@Sun.COM  *
14611042SErik.Nordmark@Sun.COM  *   - This must be a non-VLAN IP stream.
14711042SErik.Nordmark@Sun.COM  *   - 'mp' is either an untagged or a special priority-tagged packet.
14811042SErik.Nordmark@Sun.COM  *   - Any VLAN tag that was in the MAC header has been stripped.
14911042SErik.Nordmark@Sun.COM  *
15011042SErik.Nordmark@Sun.COM  * If the IP header in packet is not 32-bit aligned, every message in the
15111042SErik.Nordmark@Sun.COM  * chain will be aligned before further operations. This is required on SPARC
15211042SErik.Nordmark@Sun.COM  * platform.
15311042SErik.Nordmark@Sun.COM  */
15411042SErik.Nordmark@Sun.COM void
ip_input_v6(ill_t * ill,ill_rx_ring_t * ip_ring,mblk_t * mp_chain,struct mac_header_info_s * mhip)15511042SErik.Nordmark@Sun.COM ip_input_v6(ill_t *ill, ill_rx_ring_t *ip_ring, mblk_t *mp_chain,
15611042SErik.Nordmark@Sun.COM     struct mac_header_info_s *mhip)
15711042SErik.Nordmark@Sun.COM {
15811042SErik.Nordmark@Sun.COM 	(void) ip_input_common_v6(ill, ip_ring, mp_chain, mhip, NULL, NULL,
15911042SErik.Nordmark@Sun.COM 	    NULL);
16011042SErik.Nordmark@Sun.COM }
16111042SErik.Nordmark@Sun.COM 
16211042SErik.Nordmark@Sun.COM /*
16311042SErik.Nordmark@Sun.COM  * ip_accept_tcp_v6() - This function is called by the squeue when it retrieves
16411042SErik.Nordmark@Sun.COM  * a chain of packets in the poll mode. The packets have gone through the
16511042SErik.Nordmark@Sun.COM  * data link processing but not IP processing. For performance and latency
16611042SErik.Nordmark@Sun.COM  * reasons, the squeue wants to process the chain in line instead of feeding
16711042SErik.Nordmark@Sun.COM  * it back via ip_input path.
16811042SErik.Nordmark@Sun.COM  *
16911042SErik.Nordmark@Sun.COM  * We set up the ip_recv_attr_t with IRAF_TARGET_SQP to that ip_fanout_v6
17011042SErik.Nordmark@Sun.COM  * will pass back any TCP packets matching the target sqp to
17111042SErik.Nordmark@Sun.COM  * ip_input_common_v6 using ira_target_sqp_mp. Other packets are handled by
17211042SErik.Nordmark@Sun.COM  * ip_input_v6 and ip_fanout_v6 as normal.
17311042SErik.Nordmark@Sun.COM  * The TCP packets that match the target squeue are returned to the caller
17411042SErik.Nordmark@Sun.COM  * as a b_next chain after each packet has been prepend with an mblk
17511042SErik.Nordmark@Sun.COM  * from ip_recv_attr_to_mblk.
17611042SErik.Nordmark@Sun.COM  */
17711042SErik.Nordmark@Sun.COM mblk_t *
ip_accept_tcp_v6(ill_t * ill,ill_rx_ring_t * ip_ring,squeue_t * target_sqp,mblk_t * mp_chain,mblk_t ** last,uint_t * cnt)17811042SErik.Nordmark@Sun.COM ip_accept_tcp_v6(ill_t *ill, ill_rx_ring_t *ip_ring, squeue_t *target_sqp,
17911042SErik.Nordmark@Sun.COM     mblk_t *mp_chain, mblk_t **last, uint_t *cnt)
18011042SErik.Nordmark@Sun.COM {
18111042SErik.Nordmark@Sun.COM 	return (ip_input_common_v6(ill, ip_ring, mp_chain, NULL, target_sqp,
18211042SErik.Nordmark@Sun.COM 	    last, cnt));
18311042SErik.Nordmark@Sun.COM }
18411042SErik.Nordmark@Sun.COM 
18511042SErik.Nordmark@Sun.COM /*
18611042SErik.Nordmark@Sun.COM  * Used by ip_input_v6 and ip_accept_tcp_v6
18711042SErik.Nordmark@Sun.COM  * The last three arguments are only used by ip_accept_tcp_v6, and mhip is
18811042SErik.Nordmark@Sun.COM  * only used by ip_input_v6.
18911042SErik.Nordmark@Sun.COM  */
19011042SErik.Nordmark@Sun.COM mblk_t *
ip_input_common_v6(ill_t * ill,ill_rx_ring_t * ip_ring,mblk_t * mp_chain,struct mac_header_info_s * mhip,squeue_t * target_sqp,mblk_t ** last,uint_t * cnt)19111042SErik.Nordmark@Sun.COM ip_input_common_v6(ill_t *ill, ill_rx_ring_t *ip_ring, mblk_t *mp_chain,
19211042SErik.Nordmark@Sun.COM     struct mac_header_info_s *mhip, squeue_t *target_sqp,
19311042SErik.Nordmark@Sun.COM     mblk_t **last, uint_t *cnt)
19411042SErik.Nordmark@Sun.COM {
19511042SErik.Nordmark@Sun.COM 	mblk_t		*mp;
19611042SErik.Nordmark@Sun.COM 	ip6_t		*ip6h;
19711042SErik.Nordmark@Sun.COM 	ip_recv_attr_t	iras;	/* Receive attributes */
19811042SErik.Nordmark@Sun.COM 	rtc_t		rtc;
19911042SErik.Nordmark@Sun.COM 	iaflags_t	chain_flags = 0;	/* Fixed for chain */
20011042SErik.Nordmark@Sun.COM 	mblk_t 		*ahead = NULL;	/* Accepted head */
20111042SErik.Nordmark@Sun.COM 	mblk_t		*atail = NULL;	/* Accepted tail */
20211042SErik.Nordmark@Sun.COM 	uint_t		acnt = 0;	/* Accepted count */
20311042SErik.Nordmark@Sun.COM 
20411042SErik.Nordmark@Sun.COM 	ASSERT(mp_chain != NULL);
20511042SErik.Nordmark@Sun.COM 	ASSERT(ill != NULL);
20611042SErik.Nordmark@Sun.COM 
20711042SErik.Nordmark@Sun.COM 	/* These ones do not change as we loop over packets */
20811042SErik.Nordmark@Sun.COM 	iras.ira_ill = iras.ira_rill = ill;
20911042SErik.Nordmark@Sun.COM 	iras.ira_ruifindex = ill->ill_phyint->phyint_ifindex;
21011042SErik.Nordmark@Sun.COM 	iras.ira_rifindex = iras.ira_ruifindex;
21111042SErik.Nordmark@Sun.COM 	iras.ira_sqp = NULL;
21211042SErik.Nordmark@Sun.COM 	iras.ira_ring = ip_ring;
21311042SErik.Nordmark@Sun.COM 	/* For ECMP and outbound transmit ring selection */
21411042SErik.Nordmark@Sun.COM 	iras.ira_xmit_hint = ILL_RING_TO_XMIT_HINT(ip_ring);
21511042SErik.Nordmark@Sun.COM 
21611042SErik.Nordmark@Sun.COM 	iras.ira_target_sqp = target_sqp;
21711042SErik.Nordmark@Sun.COM 	iras.ira_target_sqp_mp = NULL;
21811042SErik.Nordmark@Sun.COM 	if (target_sqp != NULL)
21911042SErik.Nordmark@Sun.COM 		chain_flags |= IRAF_TARGET_SQP;
22011042SErik.Nordmark@Sun.COM 
22111042SErik.Nordmark@Sun.COM 	/*
22211042SErik.Nordmark@Sun.COM 	 * We try to have a mhip pointer when possible, but
22311042SErik.Nordmark@Sun.COM 	 * it might be NULL in some cases. In those cases we
22411042SErik.Nordmark@Sun.COM 	 * have to assume unicast.
22511042SErik.Nordmark@Sun.COM 	 */
22611042SErik.Nordmark@Sun.COM 	iras.ira_mhip = mhip;
22711042SErik.Nordmark@Sun.COM 	iras.ira_flags = 0;
22811042SErik.Nordmark@Sun.COM 	if (mhip != NULL) {
22911042SErik.Nordmark@Sun.COM 		switch (mhip->mhi_dsttype) {
23011042SErik.Nordmark@Sun.COM 		case MAC_ADDRTYPE_MULTICAST :
23111042SErik.Nordmark@Sun.COM 			chain_flags |= IRAF_L2DST_MULTICAST;
23211042SErik.Nordmark@Sun.COM 			break;
23311042SErik.Nordmark@Sun.COM 		case MAC_ADDRTYPE_BROADCAST :
23411042SErik.Nordmark@Sun.COM 			chain_flags |= IRAF_L2DST_BROADCAST;
23511042SErik.Nordmark@Sun.COM 			break;
23611042SErik.Nordmark@Sun.COM 		}
23711042SErik.Nordmark@Sun.COM 	}
23811042SErik.Nordmark@Sun.COM 
23911042SErik.Nordmark@Sun.COM 	/*
24011042SErik.Nordmark@Sun.COM 	 * Initialize the one-element route cache.
24111042SErik.Nordmark@Sun.COM 	 *
24211042SErik.Nordmark@Sun.COM 	 * We do ire caching from one iteration to
24311042SErik.Nordmark@Sun.COM 	 * another. In the event the packet chain contains
24411042SErik.Nordmark@Sun.COM 	 * all packets from the same dst, this caching saves
24511042SErik.Nordmark@Sun.COM 	 * an ire_route_recursive for each of the succeeding
24611042SErik.Nordmark@Sun.COM 	 * packets in a packet chain.
24711042SErik.Nordmark@Sun.COM 	 */
24811042SErik.Nordmark@Sun.COM 	rtc.rtc_ire = NULL;
24911042SErik.Nordmark@Sun.COM 	rtc.rtc_ip6addr = ipv6_all_zeros;
25011042SErik.Nordmark@Sun.COM 
25111042SErik.Nordmark@Sun.COM 	/* Loop over b_next */
25211042SErik.Nordmark@Sun.COM 	for (mp = mp_chain; mp != NULL; mp = mp_chain) {
25311042SErik.Nordmark@Sun.COM 		mp_chain = mp->b_next;
25411042SErik.Nordmark@Sun.COM 		mp->b_next = NULL;
25511042SErik.Nordmark@Sun.COM 
25611042SErik.Nordmark@Sun.COM 		/*
25711042SErik.Nordmark@Sun.COM 		 * if db_ref > 1 then copymsg and free original. Packet
25811042SErik.Nordmark@Sun.COM 		 * may be changed and we do not want the other entity
25911042SErik.Nordmark@Sun.COM 		 * who has a reference to this message to trip over the
26011042SErik.Nordmark@Sun.COM 		 * changes. This is a blind change because trying to
26111042SErik.Nordmark@Sun.COM 		 * catch all places that might change the packet is too
26211042SErik.Nordmark@Sun.COM 		 * difficult.
26311042SErik.Nordmark@Sun.COM 		 *
26411042SErik.Nordmark@Sun.COM 		 * This corresponds to the fast path case, where we have
26511042SErik.Nordmark@Sun.COM 		 * a chain of M_DATA mblks.  We check the db_ref count
26611042SErik.Nordmark@Sun.COM 		 * of only the 1st data block in the mblk chain. There
26711042SErik.Nordmark@Sun.COM 		 * doesn't seem to be a reason why a device driver would
26811042SErik.Nordmark@Sun.COM 		 * send up data with varying db_ref counts in the mblk
26911042SErik.Nordmark@Sun.COM 		 * chain. In any case the Fast path is a private
27011042SErik.Nordmark@Sun.COM 		 * interface, and our drivers don't do such a thing.
27111042SErik.Nordmark@Sun.COM 		 * Given the above assumption, there is no need to walk
27211042SErik.Nordmark@Sun.COM 		 * down the entire mblk chain (which could have a
27311042SErik.Nordmark@Sun.COM 		 * potential performance problem)
27411042SErik.Nordmark@Sun.COM 		 *
27511042SErik.Nordmark@Sun.COM 		 * The "(DB_REF(mp) > 1)" check was moved from ip_rput()
27611042SErik.Nordmark@Sun.COM 		 * to here because of exclusive ip stacks and vnics.
27711042SErik.Nordmark@Sun.COM 		 * Packets transmitted from exclusive stack over vnic
27811042SErik.Nordmark@Sun.COM 		 * can have db_ref > 1 and when it gets looped back to
27911042SErik.Nordmark@Sun.COM 		 * another vnic in a different zone, you have ip_input()
28011042SErik.Nordmark@Sun.COM 		 * getting dblks with db_ref > 1. So if someone
28111042SErik.Nordmark@Sun.COM 		 * complains of TCP performance under this scenario,
28211042SErik.Nordmark@Sun.COM 		 * take a serious look here on the impact of copymsg().
28311042SErik.Nordmark@Sun.COM 		 */
28411042SErik.Nordmark@Sun.COM 		if (DB_REF(mp) > 1) {
28511042SErik.Nordmark@Sun.COM 			if ((mp = ip_fix_dbref(mp, &iras)) == NULL)
28611042SErik.Nordmark@Sun.COM 				continue;
28711042SErik.Nordmark@Sun.COM 		}
28811042SErik.Nordmark@Sun.COM 
28911042SErik.Nordmark@Sun.COM 		/*
29011042SErik.Nordmark@Sun.COM 		 * IP header ptr not aligned?
29111042SErik.Nordmark@Sun.COM 		 * OR IP header not complete in first mblk
29211042SErik.Nordmark@Sun.COM 		 */
29311042SErik.Nordmark@Sun.COM 		ip6h = (ip6_t *)mp->b_rptr;
29411042SErik.Nordmark@Sun.COM 		if (!OK_32PTR(ip6h) || MBLKL(mp) < IPV6_HDR_LEN) {
29511042SErik.Nordmark@Sun.COM 			mp = ip_check_and_align_header(mp, IPV6_HDR_LEN, &iras);
29611042SErik.Nordmark@Sun.COM 			if (mp == NULL)
29711042SErik.Nordmark@Sun.COM 				continue;
29811042SErik.Nordmark@Sun.COM 			ip6h = (ip6_t *)mp->b_rptr;
29911042SErik.Nordmark@Sun.COM 		}
30011042SErik.Nordmark@Sun.COM 
30111042SErik.Nordmark@Sun.COM 		/* Protect against a mix of Ethertypes and IP versions */
30211042SErik.Nordmark@Sun.COM 		if (IPH_HDR_VERSION(ip6h) != IPV6_VERSION) {
30311042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInHdrErrors);
30411042SErik.Nordmark@Sun.COM 			ip_drop_input("ipIfStatsInHdrErrors", mp, ill);
30511042SErik.Nordmark@Sun.COM 			freemsg(mp);
30611042SErik.Nordmark@Sun.COM 			/* mhip might point into 1st packet in the chain. */
30711042SErik.Nordmark@Sun.COM 			iras.ira_mhip = NULL;
30811042SErik.Nordmark@Sun.COM 			continue;
30911042SErik.Nordmark@Sun.COM 		}
31011042SErik.Nordmark@Sun.COM 
31111042SErik.Nordmark@Sun.COM 		/*
31211042SErik.Nordmark@Sun.COM 		 * Check for Martian addrs; we have to explicitly
31311042SErik.Nordmark@Sun.COM 		 * test for for zero dst since this is also used as
31411042SErik.Nordmark@Sun.COM 		 * an indication that the rtc is not used.
31511042SErik.Nordmark@Sun.COM 		 */
31611042SErik.Nordmark@Sun.COM 		if (IN6_IS_ADDR_UNSPECIFIED(&ip6h->ip6_dst)) {
31711042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInAddrErrors);
31811042SErik.Nordmark@Sun.COM 			ip_drop_input("ipIfStatsInAddrErrors", mp, ill);
31911042SErik.Nordmark@Sun.COM 			freemsg(mp);
32011042SErik.Nordmark@Sun.COM 			/* mhip might point into 1st packet in the chain. */
32111042SErik.Nordmark@Sun.COM 			iras.ira_mhip = NULL;
32211042SErik.Nordmark@Sun.COM 			continue;
32311042SErik.Nordmark@Sun.COM 		}
32411042SErik.Nordmark@Sun.COM 		/*
32511042SErik.Nordmark@Sun.COM 		 * Keep L2SRC from a previous packet in chain since mhip
32611042SErik.Nordmark@Sun.COM 		 * might point into an earlier packet in the chain.
32711042SErik.Nordmark@Sun.COM 		 */
32811042SErik.Nordmark@Sun.COM 		chain_flags |= (iras.ira_flags & IRAF_L2SRC_SET);
32911042SErik.Nordmark@Sun.COM 
33011042SErik.Nordmark@Sun.COM 		iras.ira_flags = IRAF_VERIFY_ULP_CKSUM | chain_flags;
33111042SErik.Nordmark@Sun.COM 		iras.ira_free_flags = 0;
33211042SErik.Nordmark@Sun.COM 		iras.ira_cred = NULL;
33311042SErik.Nordmark@Sun.COM 		iras.ira_cpid = NOPID;
33411042SErik.Nordmark@Sun.COM 		iras.ira_tsl = NULL;
33511042SErik.Nordmark@Sun.COM 		iras.ira_zoneid = ALL_ZONES;	/* Default for forwarding */
33611042SErik.Nordmark@Sun.COM 
33711042SErik.Nordmark@Sun.COM 		/*
33811042SErik.Nordmark@Sun.COM 		 * We must count all incoming packets, even if they end
33911042SErik.Nordmark@Sun.COM 		 * up being dropped later on. Defer counting bytes until
34011042SErik.Nordmark@Sun.COM 		 * we have the whole IP header in first mblk.
34111042SErik.Nordmark@Sun.COM 		 */
34211042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInReceives);
34311042SErik.Nordmark@Sun.COM 
34411042SErik.Nordmark@Sun.COM 		iras.ira_pktlen = ntohs(ip6h->ip6_plen) + IPV6_HDR_LEN;
34511042SErik.Nordmark@Sun.COM 		UPDATE_MIB(ill->ill_ip_mib, ipIfStatsHCInOctets,
34611042SErik.Nordmark@Sun.COM 		    iras.ira_pktlen);
34711042SErik.Nordmark@Sun.COM 
34811042SErik.Nordmark@Sun.COM 		/*
34911042SErik.Nordmark@Sun.COM 		 * Call one of:
35011042SErik.Nordmark@Sun.COM 		 * 	ill_input_full_v6
35111042SErik.Nordmark@Sun.COM 		 *	ill_input_short_v6
35211042SErik.Nordmark@Sun.COM 		 * The former is used in the case of TX. See ill_set_inputfn().
35311042SErik.Nordmark@Sun.COM 		 */
35411042SErik.Nordmark@Sun.COM 		(*ill->ill_inputfn)(mp, ip6h, &ip6h->ip6_dst, &iras, &rtc);
35511042SErik.Nordmark@Sun.COM 
35611042SErik.Nordmark@Sun.COM 		/* Any references to clean up? No hold on ira_ill */
35711042SErik.Nordmark@Sun.COM 		if (iras.ira_flags & (IRAF_IPSEC_SECURE|IRAF_SYSTEM_LABELED))
35811042SErik.Nordmark@Sun.COM 			ira_cleanup(&iras, B_FALSE);
35911042SErik.Nordmark@Sun.COM 
36011042SErik.Nordmark@Sun.COM 		if (iras.ira_target_sqp_mp != NULL) {
36111042SErik.Nordmark@Sun.COM 			/* Better be called from ip_accept_tcp */
36211042SErik.Nordmark@Sun.COM 			ASSERT(target_sqp != NULL);
36311042SErik.Nordmark@Sun.COM 
36411042SErik.Nordmark@Sun.COM 			/* Found one packet to accept */
36511042SErik.Nordmark@Sun.COM 			mp = iras.ira_target_sqp_mp;
36611042SErik.Nordmark@Sun.COM 			iras.ira_target_sqp_mp = NULL;
36711042SErik.Nordmark@Sun.COM 			ASSERT(ip_recv_attr_is_mblk(mp));
36811042SErik.Nordmark@Sun.COM 
36911042SErik.Nordmark@Sun.COM 			if (atail != NULL)
37011042SErik.Nordmark@Sun.COM 				atail->b_next = mp;
37111042SErik.Nordmark@Sun.COM 			else
37211042SErik.Nordmark@Sun.COM 				ahead = mp;
37311042SErik.Nordmark@Sun.COM 			atail = mp;
37411042SErik.Nordmark@Sun.COM 			acnt++;
37511042SErik.Nordmark@Sun.COM 			mp = NULL;
37611042SErik.Nordmark@Sun.COM 		}
37711042SErik.Nordmark@Sun.COM 		/* mhip might point into 1st packet in the chain. */
37811042SErik.Nordmark@Sun.COM 		iras.ira_mhip = NULL;
37911042SErik.Nordmark@Sun.COM 	}
38011042SErik.Nordmark@Sun.COM 	/* Any remaining references to the route cache? */
38111042SErik.Nordmark@Sun.COM 	if (rtc.rtc_ire != NULL) {
38211042SErik.Nordmark@Sun.COM 		ASSERT(!IN6_IS_ADDR_UNSPECIFIED(&rtc.rtc_ip6addr));
38311042SErik.Nordmark@Sun.COM 		ire_refrele(rtc.rtc_ire);
38411042SErik.Nordmark@Sun.COM 	}
38511042SErik.Nordmark@Sun.COM 
38611042SErik.Nordmark@Sun.COM 	if (ahead != NULL) {
38711042SErik.Nordmark@Sun.COM 		/* Better be called from ip_accept_tcp */
38811042SErik.Nordmark@Sun.COM 		ASSERT(target_sqp != NULL);
38911042SErik.Nordmark@Sun.COM 		*last = atail;
39011042SErik.Nordmark@Sun.COM 		*cnt = acnt;
39111042SErik.Nordmark@Sun.COM 		return (ahead);
39211042SErik.Nordmark@Sun.COM 	}
39311042SErik.Nordmark@Sun.COM 
39411042SErik.Nordmark@Sun.COM 	return (NULL);
39511042SErik.Nordmark@Sun.COM }
39611042SErik.Nordmark@Sun.COM 
39711042SErik.Nordmark@Sun.COM /*
39811042SErik.Nordmark@Sun.COM  * This input function is used when
39911042SErik.Nordmark@Sun.COM  *  - is_system_labeled()
40011042SErik.Nordmark@Sun.COM  *
40111042SErik.Nordmark@Sun.COM  * Note that for IPv6 CGTP filtering is handled only when receiving fragment
40211042SErik.Nordmark@Sun.COM  * headers, and RSVP uses router alert options, thus we don't need anything
40311042SErik.Nordmark@Sun.COM  * extra for them.
40411042SErik.Nordmark@Sun.COM  */
40511042SErik.Nordmark@Sun.COM void
ill_input_full_v6(mblk_t * mp,void * iph_arg,void * nexthop_arg,ip_recv_attr_t * ira,rtc_t * rtc)40611042SErik.Nordmark@Sun.COM ill_input_full_v6(mblk_t *mp, void *iph_arg, void *nexthop_arg,
40711042SErik.Nordmark@Sun.COM     ip_recv_attr_t *ira, rtc_t *rtc)
40811042SErik.Nordmark@Sun.COM {
40911042SErik.Nordmark@Sun.COM 	ip6_t		*ip6h = (ip6_t *)iph_arg;
41011042SErik.Nordmark@Sun.COM 	in6_addr_t	*nexthop = (in6_addr_t *)nexthop_arg;
41111042SErik.Nordmark@Sun.COM 	ill_t		*ill = ira->ira_ill;
41211042SErik.Nordmark@Sun.COM 
41311042SErik.Nordmark@Sun.COM 	ASSERT(ira->ira_tsl == NULL);
41411042SErik.Nordmark@Sun.COM 
41511042SErik.Nordmark@Sun.COM 	/*
41611042SErik.Nordmark@Sun.COM 	 * Attach any necessary label information to
41711042SErik.Nordmark@Sun.COM 	 * this packet
41811042SErik.Nordmark@Sun.COM 	 */
41911042SErik.Nordmark@Sun.COM 	if (is_system_labeled()) {
42011042SErik.Nordmark@Sun.COM 		ira->ira_flags |= IRAF_SYSTEM_LABELED;
42111042SErik.Nordmark@Sun.COM 
42211042SErik.Nordmark@Sun.COM 		/*
42311042SErik.Nordmark@Sun.COM 		 * This updates ira_cred, ira_tsl and ira_free_flags based
42411042SErik.Nordmark@Sun.COM 		 * on the label.
42511042SErik.Nordmark@Sun.COM 		 */
42611042SErik.Nordmark@Sun.COM 		if (!tsol_get_pkt_label(mp, IPV6_VERSION, ira)) {
42711042SErik.Nordmark@Sun.COM 			if (ip6opt_ls != 0)
42811042SErik.Nordmark@Sun.COM 				ip0dbg(("tsol_get_pkt_label v6 failed\n"));
42911042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
43011042SErik.Nordmark@Sun.COM 			ip_drop_input("ipIfStatsInDiscards", mp, ill);
43111042SErik.Nordmark@Sun.COM 			freemsg(mp);
43211042SErik.Nordmark@Sun.COM 			return;
43311042SErik.Nordmark@Sun.COM 		}
43411042SErik.Nordmark@Sun.COM 		/* Note that ira_tsl can be NULL here. */
43511042SErik.Nordmark@Sun.COM 
43611042SErik.Nordmark@Sun.COM 		/* tsol_get_pkt_label sometimes does pullupmsg */
43711042SErik.Nordmark@Sun.COM 		ip6h = (ip6_t *)mp->b_rptr;
43811042SErik.Nordmark@Sun.COM 	}
43911042SErik.Nordmark@Sun.COM 	ill_input_short_v6(mp, ip6h, nexthop, ira, rtc);
44011042SErik.Nordmark@Sun.COM }
44111042SErik.Nordmark@Sun.COM 
44211042SErik.Nordmark@Sun.COM /*
44311042SErik.Nordmark@Sun.COM  * Check for IPv6 addresses that should not appear on the wire
44411042SErik.Nordmark@Sun.COM  * as either source or destination.
44511042SErik.Nordmark@Sun.COM  * If we ever implement Stateless IPv6 Translators (SIIT) we'd have
44611042SErik.Nordmark@Sun.COM  * to revisit the IPv4-mapped part.
44711042SErik.Nordmark@Sun.COM  */
44811042SErik.Nordmark@Sun.COM static boolean_t
ip6_bad_address(in6_addr_t * addr,boolean_t is_src)44911042SErik.Nordmark@Sun.COM ip6_bad_address(in6_addr_t *addr, boolean_t is_src)
45011042SErik.Nordmark@Sun.COM {
45111042SErik.Nordmark@Sun.COM 	if (IN6_IS_ADDR_V4MAPPED(addr)) {
45211042SErik.Nordmark@Sun.COM 		ip1dbg(("ip_input_v6: pkt with IPv4-mapped addr"));
45311042SErik.Nordmark@Sun.COM 		return (B_TRUE);
45411042SErik.Nordmark@Sun.COM 	}
45511042SErik.Nordmark@Sun.COM 	if (IN6_IS_ADDR_LOOPBACK(addr)) {
45611042SErik.Nordmark@Sun.COM 		ip1dbg(("ip_input_v6: pkt with loopback addr"));
45711042SErik.Nordmark@Sun.COM 		return (B_TRUE);
45811042SErik.Nordmark@Sun.COM 	}
45911042SErik.Nordmark@Sun.COM 	if (!is_src && IN6_IS_ADDR_UNSPECIFIED(addr)) {
46011042SErik.Nordmark@Sun.COM 		/*
46111042SErik.Nordmark@Sun.COM 		 * having :: in the src is ok: it's used for DAD.
46211042SErik.Nordmark@Sun.COM 		 */
46311042SErik.Nordmark@Sun.COM 		ip1dbg(("ip_input_v6: pkt with unspecified addr"));
46411042SErik.Nordmark@Sun.COM 		return (B_TRUE);
46511042SErik.Nordmark@Sun.COM 	}
46611042SErik.Nordmark@Sun.COM 	return (B_FALSE);
46711042SErik.Nordmark@Sun.COM }
46811042SErik.Nordmark@Sun.COM 
46911042SErik.Nordmark@Sun.COM /*
47011042SErik.Nordmark@Sun.COM  * Routing lookup for IPv6 link-locals.
47111042SErik.Nordmark@Sun.COM  * First we look on the inbound interface, then we check for IPMP and
47211042SErik.Nordmark@Sun.COM  * look on the upper interface.
47311042SErik.Nordmark@Sun.COM  * We update ira_ruifindex if we find the IRE on the upper interface.
47411042SErik.Nordmark@Sun.COM  */
47511042SErik.Nordmark@Sun.COM static ire_t *
ire_linklocal(const in6_addr_t * nexthop,ill_t * ill,ip_recv_attr_t * ira,uint_t irr_flags,ip_stack_t * ipst)47611042SErik.Nordmark@Sun.COM ire_linklocal(const in6_addr_t *nexthop, ill_t *ill, ip_recv_attr_t *ira,
47711457SErik.Nordmark@Sun.COM     uint_t irr_flags, ip_stack_t *ipst)
47811042SErik.Nordmark@Sun.COM {
47911042SErik.Nordmark@Sun.COM 	int match_flags = MATCH_IRE_SECATTR | MATCH_IRE_ILL;
48011042SErik.Nordmark@Sun.COM 	ire_t *ire;
48111042SErik.Nordmark@Sun.COM 
48211042SErik.Nordmark@Sun.COM 	ASSERT(IN6_IS_ADDR_LINKLOCAL(nexthop));
48311042SErik.Nordmark@Sun.COM 	ire = ire_route_recursive_v6(nexthop, 0, ill, ALL_ZONES, ira->ira_tsl,
48411457SErik.Nordmark@Sun.COM 	    match_flags, irr_flags, ira->ira_xmit_hint, ipst, NULL, NULL, NULL);
48511042SErik.Nordmark@Sun.COM 	if (!(ire->ire_flags & (RTF_REJECT|RTF_BLACKHOLE)) ||
48611042SErik.Nordmark@Sun.COM 	    !IS_UNDER_IPMP(ill))
48711042SErik.Nordmark@Sun.COM 		return (ire);
48811042SErik.Nordmark@Sun.COM 
48911042SErik.Nordmark@Sun.COM 	/*
49011042SErik.Nordmark@Sun.COM 	 * When we are using IMP we need to look for an IRE on both the
49111042SErik.Nordmark@Sun.COM 	 * under and upper interfaces since there are different
49211042SErik.Nordmark@Sun.COM 	 * link-local addresses for the under and upper.
49311042SErik.Nordmark@Sun.COM 	 */
49411042SErik.Nordmark@Sun.COM 	ill = ipmp_ill_hold_ipmp_ill(ill);
49511042SErik.Nordmark@Sun.COM 	if (ill == NULL)
49611042SErik.Nordmark@Sun.COM 		return (ire);
49711042SErik.Nordmark@Sun.COM 
49811042SErik.Nordmark@Sun.COM 	ira->ira_ruifindex = ill->ill_phyint->phyint_ifindex;
49911042SErik.Nordmark@Sun.COM 
50011042SErik.Nordmark@Sun.COM 	ire_refrele(ire);
50111042SErik.Nordmark@Sun.COM 	ire = ire_route_recursive_v6(nexthop, 0, ill, ALL_ZONES, ira->ira_tsl,
50211457SErik.Nordmark@Sun.COM 	    match_flags, irr_flags, ira->ira_xmit_hint, ipst, NULL, NULL, NULL);
50311042SErik.Nordmark@Sun.COM 	ill_refrele(ill);
50411042SErik.Nordmark@Sun.COM 	return (ire);
50511042SErik.Nordmark@Sun.COM }
50611042SErik.Nordmark@Sun.COM 
50711042SErik.Nordmark@Sun.COM /*
50811042SErik.Nordmark@Sun.COM  * This is the tail-end of the full receive side packet handling.
50911042SErik.Nordmark@Sun.COM  * It can be used directly when the configuration is simple.
51011042SErik.Nordmark@Sun.COM  */
51111042SErik.Nordmark@Sun.COM void
ill_input_short_v6(mblk_t * mp,void * iph_arg,void * nexthop_arg,ip_recv_attr_t * ira,rtc_t * rtc)51211042SErik.Nordmark@Sun.COM ill_input_short_v6(mblk_t *mp, void *iph_arg, void *nexthop_arg,
51311042SErik.Nordmark@Sun.COM     ip_recv_attr_t *ira, rtc_t *rtc)
51411042SErik.Nordmark@Sun.COM {
51511042SErik.Nordmark@Sun.COM 	ire_t		*ire;
51611042SErik.Nordmark@Sun.COM 	ill_t		*ill = ira->ira_ill;
51711042SErik.Nordmark@Sun.COM 	ip_stack_t	*ipst = ill->ill_ipst;
51811042SErik.Nordmark@Sun.COM 	uint_t		pkt_len;
51911042SErik.Nordmark@Sun.COM 	ssize_t 	len;
52011042SErik.Nordmark@Sun.COM 	ip6_t		*ip6h = (ip6_t *)iph_arg;
52111042SErik.Nordmark@Sun.COM 	in6_addr_t	nexthop = *(in6_addr_t *)nexthop_arg;
52211042SErik.Nordmark@Sun.COM 	ilb_stack_t	*ilbs = ipst->ips_netstack->netstack_ilb;
52311457SErik.Nordmark@Sun.COM 	uint_t		irr_flags;
52411042SErik.Nordmark@Sun.COM #define	rptr	((uchar_t *)ip6h)
52511042SErik.Nordmark@Sun.COM 
52611042SErik.Nordmark@Sun.COM 	ASSERT(DB_TYPE(mp) == M_DATA);
52711042SErik.Nordmark@Sun.COM 
52811042SErik.Nordmark@Sun.COM 	/*
52911042SErik.Nordmark@Sun.COM 	 * Check for source/dest being a bad address: loopback, any, or
53011042SErik.Nordmark@Sun.COM 	 * v4mapped. All of them start with a 64 bits of zero.
53111042SErik.Nordmark@Sun.COM 	 */
53211042SErik.Nordmark@Sun.COM 	if (ip6h->ip6_src.s6_addr32[0] == 0 &&
53311042SErik.Nordmark@Sun.COM 	    ip6h->ip6_src.s6_addr32[1] == 0) {
53411042SErik.Nordmark@Sun.COM 		if (ip6_bad_address(&ip6h->ip6_src, B_TRUE)) {
53511042SErik.Nordmark@Sun.COM 			ip1dbg(("ip_input_v6: pkt with bad src addr\n"));
53611042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInAddrErrors);
53711042SErik.Nordmark@Sun.COM 			ip_drop_input("ipIfStatsInAddrErrors", mp, ill);
53811042SErik.Nordmark@Sun.COM 			freemsg(mp);
53911042SErik.Nordmark@Sun.COM 			return;
54011042SErik.Nordmark@Sun.COM 		}
54111042SErik.Nordmark@Sun.COM 	}
54211042SErik.Nordmark@Sun.COM 	if (ip6h->ip6_dst.s6_addr32[0] == 0 &&
54311042SErik.Nordmark@Sun.COM 	    ip6h->ip6_dst.s6_addr32[1] == 0) {
54411042SErik.Nordmark@Sun.COM 		if (ip6_bad_address(&ip6h->ip6_dst, B_FALSE)) {
54511042SErik.Nordmark@Sun.COM 			ip1dbg(("ip_input_v6: pkt with bad dst addr\n"));
54611042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInAddrErrors);
54711042SErik.Nordmark@Sun.COM 			ip_drop_input("ipIfStatsInAddrErrors", mp, ill);
54811042SErik.Nordmark@Sun.COM 			freemsg(mp);
54911042SErik.Nordmark@Sun.COM 			return;
55011042SErik.Nordmark@Sun.COM 		}
55111042SErik.Nordmark@Sun.COM 	}
55211042SErik.Nordmark@Sun.COM 
55311042SErik.Nordmark@Sun.COM 	len = mp->b_wptr - rptr;
55411042SErik.Nordmark@Sun.COM 	pkt_len = ira->ira_pktlen;
55511042SErik.Nordmark@Sun.COM 
55611042SErik.Nordmark@Sun.COM 	/* multiple mblk or too short */
55711042SErik.Nordmark@Sun.COM 	len -= pkt_len;
55811042SErik.Nordmark@Sun.COM 	if (len != 0) {
55911042SErik.Nordmark@Sun.COM 		mp = ip_check_length(mp, rptr, len, pkt_len, IPV6_HDR_LEN, ira);
56011042SErik.Nordmark@Sun.COM 		if (mp == NULL)
56111042SErik.Nordmark@Sun.COM 			return;
56211042SErik.Nordmark@Sun.COM 		ip6h = (ip6_t *)mp->b_rptr;
56311042SErik.Nordmark@Sun.COM 	}
56411042SErik.Nordmark@Sun.COM 
56511042SErik.Nordmark@Sun.COM 	DTRACE_IP7(receive, mblk_t *, mp, conn_t *, NULL, void_ip_t *,
56611042SErik.Nordmark@Sun.COM 	    ip6h, __dtrace_ipsr_ill_t *, ill, ipha_t *, NULL, ip6_t *, ip6h,
56711042SErik.Nordmark@Sun.COM 	    int, 0);
56811042SErik.Nordmark@Sun.COM 	/*
56911042SErik.Nordmark@Sun.COM 	 * The event for packets being received from a 'physical'
57011042SErik.Nordmark@Sun.COM 	 * interface is placed after validation of the source and/or
57111042SErik.Nordmark@Sun.COM 	 * destination address as being local so that packets can be
57211042SErik.Nordmark@Sun.COM 	 * redirected to loopback addresses using ipnat.
57311042SErik.Nordmark@Sun.COM 	 */
57411042SErik.Nordmark@Sun.COM 	DTRACE_PROBE4(ip6__physical__in__start,
57511042SErik.Nordmark@Sun.COM 	    ill_t *, ill, ill_t *, NULL,
57611042SErik.Nordmark@Sun.COM 	    ip6_t *, ip6h, mblk_t *, mp);
57711042SErik.Nordmark@Sun.COM 
57811042SErik.Nordmark@Sun.COM 	if (HOOKS6_INTERESTED_PHYSICAL_IN(ipst)) {
57911042SErik.Nordmark@Sun.COM 		int	ll_multicast = 0;
58011042SErik.Nordmark@Sun.COM 		int	error;
58111042SErik.Nordmark@Sun.COM 		in6_addr_t orig_dst = ip6h->ip6_dst;
58211042SErik.Nordmark@Sun.COM 
58311042SErik.Nordmark@Sun.COM 		if (ira->ira_flags & IRAF_L2DST_MULTICAST)
58411042SErik.Nordmark@Sun.COM 			ll_multicast = HPE_MULTICAST;
58511042SErik.Nordmark@Sun.COM 		else if (ira->ira_flags & IRAF_L2DST_BROADCAST)
58611042SErik.Nordmark@Sun.COM 			ll_multicast = HPE_BROADCAST;
58711042SErik.Nordmark@Sun.COM 
58811042SErik.Nordmark@Sun.COM 		FW_HOOKS6(ipst->ips_ip6_physical_in_event,
58911042SErik.Nordmark@Sun.COM 		    ipst->ips_ipv6firewall_physical_in,
59011042SErik.Nordmark@Sun.COM 		    ill, NULL, ip6h, mp, mp, ll_multicast, ipst, error);
59111042SErik.Nordmark@Sun.COM 
59211042SErik.Nordmark@Sun.COM 		DTRACE_PROBE1(ip6__physical__in__end, mblk_t *, mp);
59311042SErik.Nordmark@Sun.COM 
59411042SErik.Nordmark@Sun.COM 		if (mp == NULL)
59511042SErik.Nordmark@Sun.COM 			return;
59611042SErik.Nordmark@Sun.COM 
59711042SErik.Nordmark@Sun.COM 		/* The length could have changed */
59811042SErik.Nordmark@Sun.COM 		ip6h = (ip6_t *)mp->b_rptr;
59911042SErik.Nordmark@Sun.COM 		ira->ira_pktlen = ntohs(ip6h->ip6_plen) + IPV6_HDR_LEN;
60011042SErik.Nordmark@Sun.COM 		pkt_len = ira->ira_pktlen;
60111042SErik.Nordmark@Sun.COM 
60211042SErik.Nordmark@Sun.COM 		/*
60311042SErik.Nordmark@Sun.COM 		 * In case the destination changed we override any previous
60411042SErik.Nordmark@Sun.COM 		 * change to nexthop.
60511042SErik.Nordmark@Sun.COM 		 */
60611042SErik.Nordmark@Sun.COM 		if (!IN6_ARE_ADDR_EQUAL(&orig_dst, &ip6h->ip6_dst))
60711042SErik.Nordmark@Sun.COM 			nexthop = ip6h->ip6_dst;
60811042SErik.Nordmark@Sun.COM 
60911042SErik.Nordmark@Sun.COM 		if (IN6_IS_ADDR_UNSPECIFIED(&nexthop)) {
61011042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInAddrErrors);
61111042SErik.Nordmark@Sun.COM 			ip_drop_input("ipIfStatsInAddrErrors", mp, ill);
61211042SErik.Nordmark@Sun.COM 			freemsg(mp);
61311042SErik.Nordmark@Sun.COM 			return;
61411042SErik.Nordmark@Sun.COM 		}
61511042SErik.Nordmark@Sun.COM 
61611042SErik.Nordmark@Sun.COM 	}
61711042SErik.Nordmark@Sun.COM 
61811042SErik.Nordmark@Sun.COM 	if (ipst->ips_ip6_observe.he_interested) {
61911042SErik.Nordmark@Sun.COM 		zoneid_t dzone;
62011042SErik.Nordmark@Sun.COM 
62111042SErik.Nordmark@Sun.COM 		/*
62211042SErik.Nordmark@Sun.COM 		 * On the inbound path the src zone will be unknown as
62311042SErik.Nordmark@Sun.COM 		 * this packet has come from the wire.
62411042SErik.Nordmark@Sun.COM 		 */
62511042SErik.Nordmark@Sun.COM 		dzone = ip_get_zoneid_v6(&nexthop, mp, ill, ira, ALL_ZONES);
62611042SErik.Nordmark@Sun.COM 		ipobs_hook(mp, IPOBS_HOOK_INBOUND, ALL_ZONES, dzone, ill, ipst);
62711042SErik.Nordmark@Sun.COM 	}
62811042SErik.Nordmark@Sun.COM 
62911042SErik.Nordmark@Sun.COM 	if ((ip6h->ip6_vcf & IPV6_VERS_AND_FLOW_MASK) !=
63011042SErik.Nordmark@Sun.COM 	    IPV6_DEFAULT_VERS_AND_FLOW) {
63111042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsInHdrErrors);
63211042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsInWrongIPVersion);
63311042SErik.Nordmark@Sun.COM 		ip_drop_input("ipIfStatsInWrongIPVersion", mp, ill);
63411042SErik.Nordmark@Sun.COM 		freemsg(mp);
63511042SErik.Nordmark@Sun.COM 		return;
63611042SErik.Nordmark@Sun.COM 	}
63711042SErik.Nordmark@Sun.COM 
63811042SErik.Nordmark@Sun.COM 	/*
63911042SErik.Nordmark@Sun.COM 	 * For IPv6 we update ira_ip_hdr_length and ira_protocol as
64011042SErik.Nordmark@Sun.COM 	 * we parse the headers, starting with the hop-by-hop options header.
64111042SErik.Nordmark@Sun.COM 	 */
64211042SErik.Nordmark@Sun.COM 	ira->ira_ip_hdr_length = IPV6_HDR_LEN;
64311042SErik.Nordmark@Sun.COM 	if ((ira->ira_protocol = ip6h->ip6_nxt) == IPPROTO_HOPOPTS) {
64411042SErik.Nordmark@Sun.COM 		ip6_hbh_t	*hbhhdr;
64511042SErik.Nordmark@Sun.COM 		uint_t		ehdrlen;
64611042SErik.Nordmark@Sun.COM 		uint8_t		*optptr;
64711042SErik.Nordmark@Sun.COM 
64811042SErik.Nordmark@Sun.COM 		if (pkt_len < IPV6_HDR_LEN + MIN_EHDR_LEN) {
64911042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInTruncatedPkts);
65011042SErik.Nordmark@Sun.COM 			ip_drop_input("ipIfStatsInTruncatedPkts", mp, ill);
65111042SErik.Nordmark@Sun.COM 			freemsg(mp);
65211042SErik.Nordmark@Sun.COM 			return;
65311042SErik.Nordmark@Sun.COM 		}
65411042SErik.Nordmark@Sun.COM 		if (mp->b_cont != NULL &&
65511042SErik.Nordmark@Sun.COM 		    rptr + IPV6_HDR_LEN + MIN_EHDR_LEN > mp->b_wptr) {
65611042SErik.Nordmark@Sun.COM 			ip6h = ip_pullup(mp, IPV6_HDR_LEN + MIN_EHDR_LEN, ira);
65711042SErik.Nordmark@Sun.COM 			if (ip6h == NULL) {
65811042SErik.Nordmark@Sun.COM 				BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
65911042SErik.Nordmark@Sun.COM 				ip_drop_input("ipIfStatsInDiscards", mp, ill);
66011042SErik.Nordmark@Sun.COM 				freemsg(mp);
66111042SErik.Nordmark@Sun.COM 				return;
66211042SErik.Nordmark@Sun.COM 			}
66311042SErik.Nordmark@Sun.COM 		}
66411042SErik.Nordmark@Sun.COM 		hbhhdr = (ip6_hbh_t *)&ip6h[1];
66511042SErik.Nordmark@Sun.COM 		ehdrlen = 8 * (hbhhdr->ip6h_len + 1);
66611042SErik.Nordmark@Sun.COM 
66711042SErik.Nordmark@Sun.COM 		if (pkt_len < IPV6_HDR_LEN + ehdrlen) {
66811042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInTruncatedPkts);
66911042SErik.Nordmark@Sun.COM 			ip_drop_input("ipIfStatsInTruncatedPkts", mp, ill);
67011042SErik.Nordmark@Sun.COM 			freemsg(mp);
67111042SErik.Nordmark@Sun.COM 			return;
67211042SErik.Nordmark@Sun.COM 		}
67311042SErik.Nordmark@Sun.COM 		if (mp->b_cont != NULL &&
67411042SErik.Nordmark@Sun.COM 		    rptr + IPV6_HDR_LEN + ehdrlen > mp->b_wptr) {
67511042SErik.Nordmark@Sun.COM 			ip6h = ip_pullup(mp, IPV6_HDR_LEN + ehdrlen, ira);
67611042SErik.Nordmark@Sun.COM 			if (ip6h == NULL) {
67711042SErik.Nordmark@Sun.COM 				BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
67811042SErik.Nordmark@Sun.COM 				ip_drop_input("ipIfStatsInDiscards", mp, ill);
67911042SErik.Nordmark@Sun.COM 				freemsg(mp);
68011042SErik.Nordmark@Sun.COM 				return;
68111042SErik.Nordmark@Sun.COM 			}
68211042SErik.Nordmark@Sun.COM 			hbhhdr = (ip6_hbh_t *)&ip6h[1];
68311042SErik.Nordmark@Sun.COM 		}
68411042SErik.Nordmark@Sun.COM 
68511042SErik.Nordmark@Sun.COM 		/*
68611042SErik.Nordmark@Sun.COM 		 * Update ira_ip_hdr_length to skip the hop-by-hop header
68711042SErik.Nordmark@Sun.COM 		 * once we get to ip_fanout_v6
68811042SErik.Nordmark@Sun.COM 		 */
68911042SErik.Nordmark@Sun.COM 		ira->ira_ip_hdr_length += ehdrlen;
69011042SErik.Nordmark@Sun.COM 		ira->ira_protocol = hbhhdr->ip6h_nxt;
69111042SErik.Nordmark@Sun.COM 
69211042SErik.Nordmark@Sun.COM 		optptr = (uint8_t *)&hbhhdr[1];
69311042SErik.Nordmark@Sun.COM 		switch (ip_process_options_v6(mp, ip6h, optptr,
69411042SErik.Nordmark@Sun.COM 		    ehdrlen - 2, IPPROTO_HOPOPTS, ira)) {
69511042SErik.Nordmark@Sun.COM 		case -1:
69611042SErik.Nordmark@Sun.COM 			/*
69711042SErik.Nordmark@Sun.COM 			 * Packet has been consumed and any
69811042SErik.Nordmark@Sun.COM 			 * needed ICMP messages sent.
69911042SErik.Nordmark@Sun.COM 			 */
70011042SErik.Nordmark@Sun.COM 			return;
70111042SErik.Nordmark@Sun.COM 		case 0:
70211042SErik.Nordmark@Sun.COM 			/* no action needed */
70311042SErik.Nordmark@Sun.COM 			break;
70411042SErik.Nordmark@Sun.COM 		case 1:
70511042SErik.Nordmark@Sun.COM 			/*
70611042SErik.Nordmark@Sun.COM 			 * Known router alert. Make use handle it as local
70711042SErik.Nordmark@Sun.COM 			 * by setting the nexthop to be the all-host multicast
70811042SErik.Nordmark@Sun.COM 			 * address, and skip multicast membership filter by
70911042SErik.Nordmark@Sun.COM 			 * marking as a router alert.
71011042SErik.Nordmark@Sun.COM 			 */
71111042SErik.Nordmark@Sun.COM 			ira->ira_flags |= IRAF_ROUTER_ALERT;
71211042SErik.Nordmark@Sun.COM 			nexthop = ipv6_all_hosts_mcast;
71311042SErik.Nordmark@Sun.COM 			break;
71411042SErik.Nordmark@Sun.COM 		}
71511042SErik.Nordmark@Sun.COM 	}
71611042SErik.Nordmark@Sun.COM 
71711042SErik.Nordmark@Sun.COM 	/*
71811042SErik.Nordmark@Sun.COM 	 * Here we check to see if we machine is setup as
71911042SErik.Nordmark@Sun.COM 	 * L3 loadbalancer and if the incoming packet is for a VIP
72011042SErik.Nordmark@Sun.COM 	 *
72111042SErik.Nordmark@Sun.COM 	 * Check the following:
72211042SErik.Nordmark@Sun.COM 	 * - there is at least a rule
72311042SErik.Nordmark@Sun.COM 	 * - protocol of the packet is supported
72411042SErik.Nordmark@Sun.COM 	 *
72511042SErik.Nordmark@Sun.COM 	 * We don't load balance IPv6 link-locals.
72611042SErik.Nordmark@Sun.COM 	 */
72711042SErik.Nordmark@Sun.COM 	if (ilb_has_rules(ilbs) && ILB_SUPP_L4(ira->ira_protocol) &&
72811042SErik.Nordmark@Sun.COM 	    !IN6_IS_ADDR_LINKLOCAL(&nexthop)) {
72911042SErik.Nordmark@Sun.COM 		in6_addr_t	lb_dst;
73011042SErik.Nordmark@Sun.COM 		int		lb_ret;
73111042SErik.Nordmark@Sun.COM 
73211042SErik.Nordmark@Sun.COM 		/* For convenience, we just pull up the mblk. */
73311042SErik.Nordmark@Sun.COM 		if (mp->b_cont != NULL) {
73411042SErik.Nordmark@Sun.COM 			if (pullupmsg(mp, -1) == 0) {
73511042SErik.Nordmark@Sun.COM 				BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
73611042SErik.Nordmark@Sun.COM 				ip_drop_input("ipIfStatsInDiscards - pullupmsg",
73711042SErik.Nordmark@Sun.COM 				    mp, ill);
73811042SErik.Nordmark@Sun.COM 				freemsg(mp);
73911042SErik.Nordmark@Sun.COM 				return;
74011042SErik.Nordmark@Sun.COM 			}
74111042SErik.Nordmark@Sun.COM 			ip6h = (ip6_t *)mp->b_rptr;
74211042SErik.Nordmark@Sun.COM 		}
74311042SErik.Nordmark@Sun.COM 		lb_ret = ilb_check_v6(ilbs, ill, mp, ip6h, ira->ira_protocol,
74411042SErik.Nordmark@Sun.COM 		    (uint8_t *)ip6h + ira->ira_ip_hdr_length, &lb_dst);
74511042SErik.Nordmark@Sun.COM 		if (lb_ret == ILB_DROPPED) {
74611042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
74711042SErik.Nordmark@Sun.COM 			ip_drop_input("ILB_DROPPED", mp, ill);
74811042SErik.Nordmark@Sun.COM 			freemsg(mp);
74911042SErik.Nordmark@Sun.COM 			return;
75011042SErik.Nordmark@Sun.COM 		}
75111042SErik.Nordmark@Sun.COM 		if (lb_ret == ILB_BALANCED) {
75211042SErik.Nordmark@Sun.COM 			/* Set the dst to that of the chosen server */
75311042SErik.Nordmark@Sun.COM 			nexthop = lb_dst;
75411042SErik.Nordmark@Sun.COM 			DB_CKSUMFLAGS(mp) = 0;
75511042SErik.Nordmark@Sun.COM 		}
75611042SErik.Nordmark@Sun.COM 	}
75711042SErik.Nordmark@Sun.COM 
75811457SErik.Nordmark@Sun.COM 	if (ill->ill_flags & ILLF_ROUTER)
75911457SErik.Nordmark@Sun.COM 		irr_flags = IRR_ALLOCATE;
76011457SErik.Nordmark@Sun.COM 	else
76111457SErik.Nordmark@Sun.COM 		irr_flags = IRR_NONE;
76211457SErik.Nordmark@Sun.COM 
76311042SErik.Nordmark@Sun.COM 	/* Can not use route cache with TX since the labels can differ */
76411042SErik.Nordmark@Sun.COM 	if (ira->ira_flags & IRAF_SYSTEM_LABELED) {
76511042SErik.Nordmark@Sun.COM 		if (IN6_IS_ADDR_MULTICAST(&nexthop)) {
76611042SErik.Nordmark@Sun.COM 			ire = ire_multicast(ill);
76711042SErik.Nordmark@Sun.COM 		} else if (IN6_IS_ADDR_LINKLOCAL(&nexthop)) {
76811457SErik.Nordmark@Sun.COM 			ire = ire_linklocal(&nexthop, ill, ira, irr_flags,
76911457SErik.Nordmark@Sun.COM 			    ipst);
77011042SErik.Nordmark@Sun.COM 		} else {
77111042SErik.Nordmark@Sun.COM 			/* Match destination and label */
77211042SErik.Nordmark@Sun.COM 			ire = ire_route_recursive_v6(&nexthop, 0, NULL,
77311457SErik.Nordmark@Sun.COM 			    ALL_ZONES, ira->ira_tsl, MATCH_IRE_SECATTR,
77411457SErik.Nordmark@Sun.COM 			    irr_flags, ira->ira_xmit_hint, ipst, NULL, NULL,
77511457SErik.Nordmark@Sun.COM 			    NULL);
77611042SErik.Nordmark@Sun.COM 		}
77711042SErik.Nordmark@Sun.COM 		/* Update the route cache so we do the ire_refrele */
77811042SErik.Nordmark@Sun.COM 		ASSERT(ire != NULL);
77911042SErik.Nordmark@Sun.COM 		if (rtc->rtc_ire != NULL)
78011042SErik.Nordmark@Sun.COM 			ire_refrele(rtc->rtc_ire);
78111042SErik.Nordmark@Sun.COM 		rtc->rtc_ire = ire;
78211042SErik.Nordmark@Sun.COM 		rtc->rtc_ip6addr = nexthop;
78311042SErik.Nordmark@Sun.COM 	} else if (IN6_ARE_ADDR_EQUAL(&nexthop, &rtc->rtc_ip6addr)) {
78411042SErik.Nordmark@Sun.COM 		/* Use the route cache */
78511042SErik.Nordmark@Sun.COM 		ASSERT(rtc->rtc_ire != NULL);
78611042SErik.Nordmark@Sun.COM 		ire = rtc->rtc_ire;
78711042SErik.Nordmark@Sun.COM 	} else {
78811042SErik.Nordmark@Sun.COM 		/* Update the route cache */
78911042SErik.Nordmark@Sun.COM 		if (IN6_IS_ADDR_MULTICAST(&nexthop)) {
79011042SErik.Nordmark@Sun.COM 			ire = ire_multicast(ill);
79111042SErik.Nordmark@Sun.COM 		} else if (IN6_IS_ADDR_LINKLOCAL(&nexthop)) {
79211457SErik.Nordmark@Sun.COM 			ire = ire_linklocal(&nexthop, ill, ira, irr_flags,
79311457SErik.Nordmark@Sun.COM 			    ipst);
79411042SErik.Nordmark@Sun.COM 		} else {
79511042SErik.Nordmark@Sun.COM 			ire = ire_route_recursive_dstonly_v6(&nexthop,
79611457SErik.Nordmark@Sun.COM 			    irr_flags, ira->ira_xmit_hint, ipst);
79711042SErik.Nordmark@Sun.COM 		}
79811042SErik.Nordmark@Sun.COM 		ASSERT(ire != NULL);
79911042SErik.Nordmark@Sun.COM 		if (rtc->rtc_ire != NULL)
80011042SErik.Nordmark@Sun.COM 			ire_refrele(rtc->rtc_ire);
80111042SErik.Nordmark@Sun.COM 		rtc->rtc_ire = ire;
80211042SErik.Nordmark@Sun.COM 		rtc->rtc_ip6addr = nexthop;
80311042SErik.Nordmark@Sun.COM 	}
80411042SErik.Nordmark@Sun.COM 
80511042SErik.Nordmark@Sun.COM 	ire->ire_ib_pkt_count++;
80611042SErik.Nordmark@Sun.COM 
80711042SErik.Nordmark@Sun.COM 	/*
80811042SErik.Nordmark@Sun.COM 	 * Based on ire_type and ire_flags call one of:
80911042SErik.Nordmark@Sun.COM 	 *	ire_recv_local_v6 - for IRE_LOCAL
81011042SErik.Nordmark@Sun.COM 	 *	ire_recv_loopback_v6 - for IRE_LOOPBACK
81111042SErik.Nordmark@Sun.COM 	 *	ire_recv_multirt_v6 - if RTF_MULTIRT
81211042SErik.Nordmark@Sun.COM 	 *	ire_recv_noroute_v6 - if RTF_REJECT or RTF_BLACHOLE
81311042SErik.Nordmark@Sun.COM 	 *	ire_recv_multicast_v6 - for IRE_MULTICAST
81411042SErik.Nordmark@Sun.COM 	 *	ire_recv_noaccept_v6 - for ire_noaccept ones
81511042SErik.Nordmark@Sun.COM 	 *	ire_recv_forward_v6 - for the rest.
81611042SErik.Nordmark@Sun.COM 	 */
81711042SErik.Nordmark@Sun.COM 
81811042SErik.Nordmark@Sun.COM 	(*ire->ire_recvfn)(ire, mp, ip6h, ira);
81911042SErik.Nordmark@Sun.COM }
82011042SErik.Nordmark@Sun.COM #undef rptr
82111042SErik.Nordmark@Sun.COM 
82211042SErik.Nordmark@Sun.COM /*
82311042SErik.Nordmark@Sun.COM  * ire_recvfn for IREs that need forwarding
82411042SErik.Nordmark@Sun.COM  */
82511042SErik.Nordmark@Sun.COM void
ire_recv_forward_v6(ire_t * ire,mblk_t * mp,void * iph_arg,ip_recv_attr_t * ira)82611042SErik.Nordmark@Sun.COM ire_recv_forward_v6(ire_t *ire, mblk_t *mp, void *iph_arg, ip_recv_attr_t *ira)
82711042SErik.Nordmark@Sun.COM {
82811042SErik.Nordmark@Sun.COM 	ip6_t		*ip6h = (ip6_t *)iph_arg;
82911042SErik.Nordmark@Sun.COM 	ill_t		*ill = ira->ira_ill;
83011042SErik.Nordmark@Sun.COM 	ip_stack_t	*ipst = ill->ill_ipst;
83111042SErik.Nordmark@Sun.COM 	iaflags_t	iraflags = ira->ira_flags;
83211042SErik.Nordmark@Sun.COM 	ill_t		*dst_ill;
83311042SErik.Nordmark@Sun.COM 	nce_t		*nce;
83411042SErik.Nordmark@Sun.COM 	uint32_t	added_tx_len;
83511042SErik.Nordmark@Sun.COM 	uint32_t	mtu, iremtu;
83611042SErik.Nordmark@Sun.COM 
83711042SErik.Nordmark@Sun.COM 	if (iraflags & (IRAF_L2DST_MULTICAST|IRAF_L2DST_BROADCAST)) {
83811042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
83911042SErik.Nordmark@Sun.COM 		ip_drop_input("l2 multicast not forwarded", mp, ill);
84011042SErik.Nordmark@Sun.COM 		freemsg(mp);
84111042SErik.Nordmark@Sun.COM 		return;
84211042SErik.Nordmark@Sun.COM 	}
84311042SErik.Nordmark@Sun.COM 
84411042SErik.Nordmark@Sun.COM 	if (!(ill->ill_flags & ILLF_ROUTER)) {
84511042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
84611042SErik.Nordmark@Sun.COM 		ip_drop_input("ipIfStatsForwProhibits", mp, ill);
84711042SErik.Nordmark@Sun.COM 		freemsg(mp);
84811042SErik.Nordmark@Sun.COM 		return;
84911042SErik.Nordmark@Sun.COM 	}
85011042SErik.Nordmark@Sun.COM 
85111042SErik.Nordmark@Sun.COM 	/*
85211042SErik.Nordmark@Sun.COM 	 * Either ire_nce_capable or ire_dep_parent would be set for the IRE
85311042SErik.Nordmark@Sun.COM 	 * when it is found by ire_route_recursive, but that some other thread
85411042SErik.Nordmark@Sun.COM 	 * could have changed the routes with the effect of clearing
85511042SErik.Nordmark@Sun.COM 	 * ire_dep_parent. In that case we'd end up dropping the packet, or
85611042SErik.Nordmark@Sun.COM 	 * finding a new nce below.
85711042SErik.Nordmark@Sun.COM 	 * Get, allocate, or update the nce.
85811042SErik.Nordmark@Sun.COM 	 * We get a refhold on ire_nce_cache as a result of this to avoid races
85911042SErik.Nordmark@Sun.COM 	 * where ire_nce_cache is deleted.
86011042SErik.Nordmark@Sun.COM 	 *
86111042SErik.Nordmark@Sun.COM 	 * This ensures that we don't forward if the interface is down since
86211042SErik.Nordmark@Sun.COM 	 * ipif_down removes all the nces.
86311042SErik.Nordmark@Sun.COM 	 */
86411042SErik.Nordmark@Sun.COM 	mutex_enter(&ire->ire_lock);
86511042SErik.Nordmark@Sun.COM 	nce = ire->ire_nce_cache;
86611042SErik.Nordmark@Sun.COM 	if (nce == NULL) {
86711042SErik.Nordmark@Sun.COM 		/* Not yet set up - try to set one up */
86811042SErik.Nordmark@Sun.COM 		mutex_exit(&ire->ire_lock);
86911042SErik.Nordmark@Sun.COM 		(void) ire_revalidate_nce(ire);
87011042SErik.Nordmark@Sun.COM 		mutex_enter(&ire->ire_lock);
87111042SErik.Nordmark@Sun.COM 		nce = ire->ire_nce_cache;
87211042SErik.Nordmark@Sun.COM 		if (nce == NULL) {
87311042SErik.Nordmark@Sun.COM 			mutex_exit(&ire->ire_lock);
87411042SErik.Nordmark@Sun.COM 			/* The ire_dep_parent chain went bad, or no memory */
87511042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
87611042SErik.Nordmark@Sun.COM 			ip_drop_input("No ire_dep_parent", mp, ill);
87711042SErik.Nordmark@Sun.COM 			freemsg(mp);
87811042SErik.Nordmark@Sun.COM 			return;
87911042SErik.Nordmark@Sun.COM 		}
88011042SErik.Nordmark@Sun.COM 	}
88111042SErik.Nordmark@Sun.COM 	nce_refhold(nce);
88211042SErik.Nordmark@Sun.COM 	mutex_exit(&ire->ire_lock);
88311042SErik.Nordmark@Sun.COM 
88411042SErik.Nordmark@Sun.COM 	if (nce->nce_is_condemned) {
88511042SErik.Nordmark@Sun.COM 		nce_t *nce1;
88611042SErik.Nordmark@Sun.COM 
88711042SErik.Nordmark@Sun.COM 		nce1 = ire_handle_condemned_nce(nce, ire, NULL, ip6h, B_FALSE);
88811042SErik.Nordmark@Sun.COM 		nce_refrele(nce);
88911042SErik.Nordmark@Sun.COM 		if (nce1 == NULL) {
89011042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
89111042SErik.Nordmark@Sun.COM 			ip_drop_input("No nce", mp, ill);
89211042SErik.Nordmark@Sun.COM 			freemsg(mp);
89311042SErik.Nordmark@Sun.COM 			return;
89411042SErik.Nordmark@Sun.COM 		}
89511042SErik.Nordmark@Sun.COM 		nce = nce1;
89611042SErik.Nordmark@Sun.COM 	}
89711042SErik.Nordmark@Sun.COM 	dst_ill = nce->nce_ill;
89811042SErik.Nordmark@Sun.COM 
89911042SErik.Nordmark@Sun.COM 	/*
90011042SErik.Nordmark@Sun.COM 	 * Unless we are forwarding, drop the packet.
90111042SErik.Nordmark@Sun.COM 	 * Unlike IPv4 we don't allow source routed packets out the same
90211042SErik.Nordmark@Sun.COM 	 * interface when we are not a router.
90311042SErik.Nordmark@Sun.COM 	 * Note that ill_forward_set() will set the ILLF_ROUTER on
90411042SErik.Nordmark@Sun.COM 	 * all the group members when it gets an ipmp-ill or under-ill.
90511042SErik.Nordmark@Sun.COM 	 */
90611042SErik.Nordmark@Sun.COM 	if (!(dst_ill->ill_flags & ILLF_ROUTER)) {
90711042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
90811042SErik.Nordmark@Sun.COM 		ip_drop_input("ipIfStatsForwProhibits", mp, ill);
90911042SErik.Nordmark@Sun.COM 		freemsg(mp);
91011042SErik.Nordmark@Sun.COM 		nce_refrele(nce);
91111042SErik.Nordmark@Sun.COM 		return;
91211042SErik.Nordmark@Sun.COM 	}
91311042SErik.Nordmark@Sun.COM 
91411042SErik.Nordmark@Sun.COM 	if (ire->ire_zoneid != GLOBAL_ZONEID && ire->ire_zoneid != ALL_ZONES) {
91511042SErik.Nordmark@Sun.COM 		ire->ire_ib_pkt_count--;
91611042SErik.Nordmark@Sun.COM 		/*
91711042SErik.Nordmark@Sun.COM 		 * Should only use IREs that are visible from the
91811042SErik.Nordmark@Sun.COM 		 * global zone for forwarding.
91911042SErik.Nordmark@Sun.COM 		 * For IPv6 any source route would have already been
92011042SErik.Nordmark@Sun.COM 		 * advanced in ip_fanout_v6
92111042SErik.Nordmark@Sun.COM 		 */
92211042SErik.Nordmark@Sun.COM 		ire = ire_route_recursive_v6(&ip6h->ip6_dst, 0, NULL,
92311042SErik.Nordmark@Sun.COM 		    GLOBAL_ZONEID, ira->ira_tsl, MATCH_IRE_SECATTR,
92411457SErik.Nordmark@Sun.COM 		    (ill->ill_flags & ILLF_ROUTER) ? IRR_ALLOCATE : IRR_NONE,
92511457SErik.Nordmark@Sun.COM 		    ira->ira_xmit_hint, ipst, NULL, NULL, NULL);
92611042SErik.Nordmark@Sun.COM 		ire->ire_ib_pkt_count++;
92711042SErik.Nordmark@Sun.COM 		(*ire->ire_recvfn)(ire, mp, ip6h, ira);
92811042SErik.Nordmark@Sun.COM 		ire_refrele(ire);
92911042SErik.Nordmark@Sun.COM 		nce_refrele(nce);
93011042SErik.Nordmark@Sun.COM 		return;
93111042SErik.Nordmark@Sun.COM 	}
93211042SErik.Nordmark@Sun.COM 	/*
93311042SErik.Nordmark@Sun.COM 	 * ipIfStatsHCInForwDatagrams should only be increment if there
93411042SErik.Nordmark@Sun.COM 	 * will be an attempt to forward the packet, which is why we
93511042SErik.Nordmark@Sun.COM 	 * increment after the above condition has been checked.
93611042SErik.Nordmark@Sun.COM 	 */
93711042SErik.Nordmark@Sun.COM 	BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInForwDatagrams);
93811042SErik.Nordmark@Sun.COM 
93911042SErik.Nordmark@Sun.COM 	/* Initiate Read side IPPF processing */
94011042SErik.Nordmark@Sun.COM 	if (IPP_ENABLED(IPP_FWD_IN, ipst)) {
94111042SErik.Nordmark@Sun.COM 		/* ip_process translates an IS_UNDER_IPMP */
94211042SErik.Nordmark@Sun.COM 		mp = ip_process(IPP_FWD_IN, mp, ill, ill);
94311042SErik.Nordmark@Sun.COM 		if (mp == NULL) {
94411042SErik.Nordmark@Sun.COM 			/* ip_drop_packet and MIB done */
94511042SErik.Nordmark@Sun.COM 			ip2dbg(("ire_recv_forward_v6: pkt dropped/deferred "
94611042SErik.Nordmark@Sun.COM 			    "during IPPF processing\n"));
94711042SErik.Nordmark@Sun.COM 			nce_refrele(nce);
94811042SErik.Nordmark@Sun.COM 			return;
94911042SErik.Nordmark@Sun.COM 		}
95011042SErik.Nordmark@Sun.COM 	}
95111042SErik.Nordmark@Sun.COM 
95211042SErik.Nordmark@Sun.COM 	DTRACE_PROBE4(ip6__forwarding__start,
95311042SErik.Nordmark@Sun.COM 	    ill_t *, ill, ill_t *, dst_ill, ip6_t *, ip6h, mblk_t *, mp);
95411042SErik.Nordmark@Sun.COM 
95511042SErik.Nordmark@Sun.COM 	if (HOOKS6_INTERESTED_FORWARDING(ipst)) {
95611042SErik.Nordmark@Sun.COM 		int	error;
95711042SErik.Nordmark@Sun.COM 
95811042SErik.Nordmark@Sun.COM 		FW_HOOKS(ipst->ips_ip6_forwarding_event,
95911042SErik.Nordmark@Sun.COM 		    ipst->ips_ipv6firewall_forwarding,
96011042SErik.Nordmark@Sun.COM 		    ill, dst_ill, ip6h, mp, mp, 0, ipst, error);
96111042SErik.Nordmark@Sun.COM 
96211042SErik.Nordmark@Sun.COM 		DTRACE_PROBE1(ip6__forwarding__end, mblk_t *, mp);
96311042SErik.Nordmark@Sun.COM 
96411042SErik.Nordmark@Sun.COM 		if (mp == NULL) {
96511042SErik.Nordmark@Sun.COM 			nce_refrele(nce);
96611042SErik.Nordmark@Sun.COM 			return;
96711042SErik.Nordmark@Sun.COM 		}
96811042SErik.Nordmark@Sun.COM 		/*
96911042SErik.Nordmark@Sun.COM 		 * Even if the destination was changed by the filter we use the
97011042SErik.Nordmark@Sun.COM 		 * forwarding decision that was made based on the address
97111042SErik.Nordmark@Sun.COM 		 * in ip_input.
97211042SErik.Nordmark@Sun.COM 		 */
97311042SErik.Nordmark@Sun.COM 
97411042SErik.Nordmark@Sun.COM 		/* Might have changed */
97511042SErik.Nordmark@Sun.COM 		ip6h = (ip6_t *)mp->b_rptr;
97611042SErik.Nordmark@Sun.COM 		ira->ira_pktlen = ntohs(ip6h->ip6_plen) + IPV6_HDR_LEN;
97711042SErik.Nordmark@Sun.COM 	}
97811042SErik.Nordmark@Sun.COM 
97911042SErik.Nordmark@Sun.COM 	/* Packet is being forwarded. Turning off hwcksum flag. */
98011042SErik.Nordmark@Sun.COM 	DB_CKSUMFLAGS(mp) = 0;
98111042SErik.Nordmark@Sun.COM 
98211042SErik.Nordmark@Sun.COM 	/*
98311042SErik.Nordmark@Sun.COM 	 * Per RFC 3513 section 2.5.2, we must not forward packets with
98411042SErik.Nordmark@Sun.COM 	 * an unspecified source address.
98511042SErik.Nordmark@Sun.COM 	 * The loopback address check for both src and dst has already
98611042SErik.Nordmark@Sun.COM 	 * been checked in ip_input_v6
98711042SErik.Nordmark@Sun.COM 	 * In the future one can envision adding RPF checks using number 3.
98811042SErik.Nordmark@Sun.COM 	 */
98911042SErik.Nordmark@Sun.COM 	switch (ipst->ips_src_check) {
99011042SErik.Nordmark@Sun.COM 	case 0:
99111042SErik.Nordmark@Sun.COM 		break;
99211042SErik.Nordmark@Sun.COM 	case 1:
99311042SErik.Nordmark@Sun.COM 	case 2:
99411042SErik.Nordmark@Sun.COM 		if (IN6_IS_ADDR_UNSPECIFIED(&ip6h->ip6_src) ||
99511042SErik.Nordmark@Sun.COM 		    IN6_IS_ADDR_MULTICAST(&ip6h->ip6_src)) {
99611042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
99711042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInAddrErrors);
99811042SErik.Nordmark@Sun.COM 			ip_drop_input("ipIfStatsInAddrErrors", mp, ill);
99911042SErik.Nordmark@Sun.COM 			nce_refrele(nce);
100011042SErik.Nordmark@Sun.COM 			freemsg(mp);
100111042SErik.Nordmark@Sun.COM 			return;
100211042SErik.Nordmark@Sun.COM 		}
100311042SErik.Nordmark@Sun.COM 		break;
100411042SErik.Nordmark@Sun.COM 	}
100511042SErik.Nordmark@Sun.COM 
100611042SErik.Nordmark@Sun.COM 	/*
100711042SErik.Nordmark@Sun.COM 	 * Check to see if we're forwarding the packet to a
100811042SErik.Nordmark@Sun.COM 	 * different link from which it came.  If so, check the
100911042SErik.Nordmark@Sun.COM 	 * source and destination addresses since routers must not
101011042SErik.Nordmark@Sun.COM 	 * forward any packets with link-local source or
101111042SErik.Nordmark@Sun.COM 	 * destination addresses to other links.  Otherwise (if
101211042SErik.Nordmark@Sun.COM 	 * we're forwarding onto the same link), conditionally send
101311042SErik.Nordmark@Sun.COM 	 * a redirect message.
101411042SErik.Nordmark@Sun.COM 	 */
101511042SErik.Nordmark@Sun.COM 	if (!IS_ON_SAME_LAN(dst_ill, ill)) {
101611042SErik.Nordmark@Sun.COM 		if (IN6_IS_ADDR_LINKLOCAL(&ip6h->ip6_dst) ||
101711042SErik.Nordmark@Sun.COM 		    IN6_IS_ADDR_LINKLOCAL(&ip6h->ip6_src)) {
101811042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInAddrErrors);
101911042SErik.Nordmark@Sun.COM 			ip_drop_input("ipIfStatsInAddrErrors", mp, ill);
102011042SErik.Nordmark@Sun.COM 			freemsg(mp);
102111042SErik.Nordmark@Sun.COM 			nce_refrele(nce);
102211042SErik.Nordmark@Sun.COM 			return;
102311042SErik.Nordmark@Sun.COM 		}
102411042SErik.Nordmark@Sun.COM 		/* TBD add site-local check at site boundary? */
102511042SErik.Nordmark@Sun.COM 	} else if (ipst->ips_ipv6_send_redirects) {
102611042SErik.Nordmark@Sun.COM 		ip_send_potential_redirect_v6(mp, ip6h, ire, ira);
102711042SErik.Nordmark@Sun.COM 	}
102811042SErik.Nordmark@Sun.COM 
102911042SErik.Nordmark@Sun.COM 	added_tx_len = 0;
103011042SErik.Nordmark@Sun.COM 	if (iraflags & IRAF_SYSTEM_LABELED) {
103111042SErik.Nordmark@Sun.COM 		mblk_t		*mp1;
103211042SErik.Nordmark@Sun.COM 		uint32_t	old_pkt_len = ira->ira_pktlen;
103311042SErik.Nordmark@Sun.COM 
103411042SErik.Nordmark@Sun.COM 		/*
103511042SErik.Nordmark@Sun.COM 		 * Check if it can be forwarded and add/remove
103611042SErik.Nordmark@Sun.COM 		 * CIPSO options as needed.
103711042SErik.Nordmark@Sun.COM 		 */
103811042SErik.Nordmark@Sun.COM 		if ((mp1 = tsol_ip_forward(ire, mp, ira)) == NULL) {
103911042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
104011042SErik.Nordmark@Sun.COM 			ip_drop_input("tsol_ip_forward", mp, ill);
104111042SErik.Nordmark@Sun.COM 			freemsg(mp);
104211042SErik.Nordmark@Sun.COM 			nce_refrele(nce);
104311042SErik.Nordmark@Sun.COM 			return;
104411042SErik.Nordmark@Sun.COM 		}
104511042SErik.Nordmark@Sun.COM 		/*
104611042SErik.Nordmark@Sun.COM 		 * Size may have changed. Remember amount added in case
104711042SErik.Nordmark@Sun.COM 		 * ip_fragment needs to send an ICMP too big.
104811042SErik.Nordmark@Sun.COM 		 */
104911042SErik.Nordmark@Sun.COM 		mp = mp1;
105011042SErik.Nordmark@Sun.COM 		ip6h = (ip6_t *)mp->b_rptr;
105111042SErik.Nordmark@Sun.COM 		ira->ira_pktlen = ntohs(ip6h->ip6_plen) + IPV6_HDR_LEN;
105211042SErik.Nordmark@Sun.COM 		ira->ira_ip_hdr_length = IPV6_HDR_LEN;
105311042SErik.Nordmark@Sun.COM 		if (ira->ira_pktlen > old_pkt_len)
105411042SErik.Nordmark@Sun.COM 			added_tx_len = ira->ira_pktlen - old_pkt_len;
105511042SErik.Nordmark@Sun.COM 	}
105611042SErik.Nordmark@Sun.COM 
105711042SErik.Nordmark@Sun.COM 	mtu = dst_ill->ill_mtu;
105811042SErik.Nordmark@Sun.COM 	if ((iremtu = ire->ire_metrics.iulp_mtu) != 0 && iremtu < mtu)
105911042SErik.Nordmark@Sun.COM 		mtu = iremtu;
106011042SErik.Nordmark@Sun.COM 	ip_forward_xmit_v6(nce, mp, ip6h, ira, mtu, added_tx_len);
106111042SErik.Nordmark@Sun.COM 	nce_refrele(nce);
106211042SErik.Nordmark@Sun.COM 	return;
106311042SErik.Nordmark@Sun.COM 
106411042SErik.Nordmark@Sun.COM }
106511042SErik.Nordmark@Sun.COM 
106611042SErik.Nordmark@Sun.COM /*
106711042SErik.Nordmark@Sun.COM  * Used for sending out unicast and multicast packets that are
106811042SErik.Nordmark@Sun.COM  * forwarded.
106911042SErik.Nordmark@Sun.COM  */
107011042SErik.Nordmark@Sun.COM void
ip_forward_xmit_v6(nce_t * nce,mblk_t * mp,ip6_t * ip6h,ip_recv_attr_t * ira,uint32_t mtu,uint32_t added_tx_len)107111042SErik.Nordmark@Sun.COM ip_forward_xmit_v6(nce_t *nce, mblk_t *mp, ip6_t *ip6h, ip_recv_attr_t *ira,
107211042SErik.Nordmark@Sun.COM     uint32_t mtu, uint32_t added_tx_len)
107311042SErik.Nordmark@Sun.COM {
107411042SErik.Nordmark@Sun.COM 	ill_t		*dst_ill = nce->nce_ill;
107511042SErik.Nordmark@Sun.COM 	uint32_t	pkt_len;
107611042SErik.Nordmark@Sun.COM 	iaflags_t	iraflags = ira->ira_flags;
107711042SErik.Nordmark@Sun.COM 	ip_stack_t	*ipst = dst_ill->ill_ipst;
107811042SErik.Nordmark@Sun.COM 
107911042SErik.Nordmark@Sun.COM 	if (ip6h->ip6_hops-- <= 1) {
108011042SErik.Nordmark@Sun.COM 		BUMP_MIB(ira->ira_ill->ill_ip_mib, ipIfStatsInDiscards);
108111042SErik.Nordmark@Sun.COM 		ip_drop_input("ICMP6_TIME_EXCEED_TRANSIT", mp, ira->ira_ill);
108211042SErik.Nordmark@Sun.COM 		icmp_time_exceeded_v6(mp, ICMP6_TIME_EXCEED_TRANSIT, B_FALSE,
108311042SErik.Nordmark@Sun.COM 		    ira);
108411042SErik.Nordmark@Sun.COM 		return;
108511042SErik.Nordmark@Sun.COM 	}
108611042SErik.Nordmark@Sun.COM 
108711042SErik.Nordmark@Sun.COM 	/* Initiate Write side IPPF processing before any fragmentation */
108811042SErik.Nordmark@Sun.COM 	if (IPP_ENABLED(IPP_FWD_OUT, ipst)) {
108911042SErik.Nordmark@Sun.COM 		/* ip_process translates an IS_UNDER_IPMP */
109011042SErik.Nordmark@Sun.COM 		mp = ip_process(IPP_FWD_OUT, mp, dst_ill, dst_ill);
109111042SErik.Nordmark@Sun.COM 		if (mp == NULL) {
109211042SErik.Nordmark@Sun.COM 			/* ip_drop_packet and MIB done */
109311042SErik.Nordmark@Sun.COM 			ip2dbg(("ire_recv_forward_v6: pkt dropped/deferred" \
109411042SErik.Nordmark@Sun.COM 			    " during IPPF processing\n"));
109511042SErik.Nordmark@Sun.COM 			return;
109611042SErik.Nordmark@Sun.COM 		}
109711042SErik.Nordmark@Sun.COM 	}
109811042SErik.Nordmark@Sun.COM 
109911042SErik.Nordmark@Sun.COM 	pkt_len = ira->ira_pktlen;
110011042SErik.Nordmark@Sun.COM 
110111042SErik.Nordmark@Sun.COM 	BUMP_MIB(dst_ill->ill_ip_mib, ipIfStatsHCOutForwDatagrams);
110211042SErik.Nordmark@Sun.COM 
110311042SErik.Nordmark@Sun.COM 	if (pkt_len > mtu) {
110411042SErik.Nordmark@Sun.COM 		BUMP_MIB(dst_ill->ill_ip_mib, ipIfStatsOutFragFails);
110511042SErik.Nordmark@Sun.COM 		ip_drop_output("ipIfStatsOutFragFails", mp, dst_ill);
110611042SErik.Nordmark@Sun.COM 		if (iraflags & IRAF_SYSTEM_LABELED) {
110711042SErik.Nordmark@Sun.COM 			/*
110811042SErik.Nordmark@Sun.COM 			 * Remove any CIPSO option added by
110911042SErik.Nordmark@Sun.COM 			 * tsol_ip_forward, and make sure we report
111011042SErik.Nordmark@Sun.COM 			 * a path MTU so that there
111111042SErik.Nordmark@Sun.COM 			 * is room to add such a CIPSO option for future
111211042SErik.Nordmark@Sun.COM 			 * packets.
111311042SErik.Nordmark@Sun.COM 			 */
111411042SErik.Nordmark@Sun.COM 			mtu = tsol_pmtu_adjust(mp, mtu, added_tx_len, AF_INET6);
111511042SErik.Nordmark@Sun.COM 		}
111611042SErik.Nordmark@Sun.COM 		icmp_pkt2big_v6(mp, mtu, B_TRUE, ira);
111711042SErik.Nordmark@Sun.COM 		return;
111811042SErik.Nordmark@Sun.COM 	}
111911042SErik.Nordmark@Sun.COM 
112011042SErik.Nordmark@Sun.COM 	ASSERT(pkt_len ==
112111042SErik.Nordmark@Sun.COM 	    ntohs(((ip6_t *)mp->b_rptr)->ip6_plen) + IPV6_HDR_LEN);
112211042SErik.Nordmark@Sun.COM 
112311042SErik.Nordmark@Sun.COM 	if (iraflags & IRAF_LOOPBACK_COPY) {
112411042SErik.Nordmark@Sun.COM 		/*
112511042SErik.Nordmark@Sun.COM 		 * IXAF_NO_LOOP_ZONEID is not set hence 6th arg
112611042SErik.Nordmark@Sun.COM 		 * is don't care
112711042SErik.Nordmark@Sun.COM 		 */
112811042SErik.Nordmark@Sun.COM 		(void) ip_postfrag_loopcheck(mp, nce,
112911042SErik.Nordmark@Sun.COM 		    (IXAF_LOOPBACK_COPY | IXAF_NO_DEV_FLOW_CTL),
113011042SErik.Nordmark@Sun.COM 		    pkt_len, ira->ira_xmit_hint, GLOBAL_ZONEID, 0, NULL);
113111042SErik.Nordmark@Sun.COM 	} else {
113211042SErik.Nordmark@Sun.COM 		(void) ip_xmit(mp, nce, IXAF_NO_DEV_FLOW_CTL,
113311042SErik.Nordmark@Sun.COM 		    pkt_len, ira->ira_xmit_hint, GLOBAL_ZONEID, 0, NULL);
113411042SErik.Nordmark@Sun.COM 	}
113511042SErik.Nordmark@Sun.COM }
113611042SErik.Nordmark@Sun.COM 
113711042SErik.Nordmark@Sun.COM /*
113811042SErik.Nordmark@Sun.COM  * ire_recvfn for RTF_REJECT and RTF_BLACKHOLE routes, including IRE_NOROUTE,
113911042SErik.Nordmark@Sun.COM  * which is what ire_route_recursive returns when there is no matching ire.
114011042SErik.Nordmark@Sun.COM  * Send ICMP unreachable unless blackhole.
114111042SErik.Nordmark@Sun.COM  */
114211042SErik.Nordmark@Sun.COM void
ire_recv_noroute_v6(ire_t * ire,mblk_t * mp,void * iph_arg,ip_recv_attr_t * ira)114311042SErik.Nordmark@Sun.COM ire_recv_noroute_v6(ire_t *ire, mblk_t *mp, void *iph_arg, ip_recv_attr_t *ira)
114411042SErik.Nordmark@Sun.COM {
114511042SErik.Nordmark@Sun.COM 	ip6_t		*ip6h = (ip6_t *)iph_arg;
114611042SErik.Nordmark@Sun.COM 	ill_t		*ill = ira->ira_ill;
114711042SErik.Nordmark@Sun.COM 	ip_stack_t	*ipst = ill->ill_ipst;
114811042SErik.Nordmark@Sun.COM 
114911042SErik.Nordmark@Sun.COM 	/* Would we have forwarded this packet if we had a route? */
115011042SErik.Nordmark@Sun.COM 	if (ira->ira_flags & (IRAF_L2DST_MULTICAST|IRAF_L2DST_BROADCAST)) {
115111042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
115211042SErik.Nordmark@Sun.COM 		ip_drop_input("l2 multicast not forwarded", mp, ill);
115311042SErik.Nordmark@Sun.COM 		freemsg(mp);
115411042SErik.Nordmark@Sun.COM 		return;
115511042SErik.Nordmark@Sun.COM 	}
115611042SErik.Nordmark@Sun.COM 
115711042SErik.Nordmark@Sun.COM 	if (!(ill->ill_flags & ILLF_ROUTER)) {
115811042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
115911042SErik.Nordmark@Sun.COM 		ip_drop_input("ipIfStatsForwProhibits", mp, ill);
116011042SErik.Nordmark@Sun.COM 		freemsg(mp);
116111042SErik.Nordmark@Sun.COM 		return;
116211042SErik.Nordmark@Sun.COM 	}
116311042SErik.Nordmark@Sun.COM 	/*
116411042SErik.Nordmark@Sun.COM 	 * If we had a route this could have been forwarded. Count as such.
116511042SErik.Nordmark@Sun.COM 	 *
116611042SErik.Nordmark@Sun.COM 	 * ipIfStatsHCInForwDatagrams should only be increment if there
116711042SErik.Nordmark@Sun.COM 	 * will be an attempt to forward the packet, which is why we
116811042SErik.Nordmark@Sun.COM 	 * increment after the above condition has been checked.
116911042SErik.Nordmark@Sun.COM 	 */
117011042SErik.Nordmark@Sun.COM 	BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInForwDatagrams);
117111042SErik.Nordmark@Sun.COM 
117211042SErik.Nordmark@Sun.COM 	BUMP_MIB(ill->ill_ip_mib, ipIfStatsInNoRoutes);
117311042SErik.Nordmark@Sun.COM 
117411042SErik.Nordmark@Sun.COM 	ip_rts_change_v6(RTM_MISS, &ip6h->ip6_dst, 0, 0, 0, 0, 0, 0, RTA_DST,
117511042SErik.Nordmark@Sun.COM 	    ipst);
117611042SErik.Nordmark@Sun.COM 
117711042SErik.Nordmark@Sun.COM 	if (ire->ire_flags & RTF_BLACKHOLE) {
117811042SErik.Nordmark@Sun.COM 		ip_drop_input("ipIfStatsInNoRoutes RTF_BLACKHOLE", mp, ill);
117911042SErik.Nordmark@Sun.COM 		freemsg(mp);
118011042SErik.Nordmark@Sun.COM 	} else {
118111042SErik.Nordmark@Sun.COM 		ip_drop_input("ipIfStatsInNoRoutes RTF_REJECT", mp, ill);
118211042SErik.Nordmark@Sun.COM 
118311042SErik.Nordmark@Sun.COM 		icmp_unreachable_v6(mp, ICMP6_DST_UNREACH_NOROUTE, B_FALSE,
118411042SErik.Nordmark@Sun.COM 		    ira);
118511042SErik.Nordmark@Sun.COM 	}
118611042SErik.Nordmark@Sun.COM }
118711042SErik.Nordmark@Sun.COM 
118811042SErik.Nordmark@Sun.COM /*
118911042SErik.Nordmark@Sun.COM  * ire_recvfn for IRE_LOCALs marked with ire_noaccept. Such IREs are used for
119011042SErik.Nordmark@Sun.COM  * VRRP when in noaccept mode.
119111042SErik.Nordmark@Sun.COM  * We silently drop packets except for Neighbor Solicitations and
119211042SErik.Nordmark@Sun.COM  * Neighbor Advertisements.
119311042SErik.Nordmark@Sun.COM  */
119411042SErik.Nordmark@Sun.COM void
ire_recv_noaccept_v6(ire_t * ire,mblk_t * mp,void * iph_arg,ip_recv_attr_t * ira)119511042SErik.Nordmark@Sun.COM ire_recv_noaccept_v6(ire_t *ire, mblk_t *mp, void *iph_arg,
119611042SErik.Nordmark@Sun.COM     ip_recv_attr_t *ira)
119711042SErik.Nordmark@Sun.COM {
119811042SErik.Nordmark@Sun.COM 	ip6_t		*ip6h = (ip6_t *)iph_arg;
119911042SErik.Nordmark@Sun.COM 	ill_t		*ill = ira->ira_ill;
120011042SErik.Nordmark@Sun.COM 	icmp6_t		*icmp6;
120111042SErik.Nordmark@Sun.COM 	int		ip_hdr_length;
120211042SErik.Nordmark@Sun.COM 
120311042SErik.Nordmark@Sun.COM 	if (ip6h->ip6_nxt != IPPROTO_ICMPV6) {
120411042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
120511042SErik.Nordmark@Sun.COM 		ip_drop_input("ipIfStatsInDiscards - noaccept", mp, ill);
120611042SErik.Nordmark@Sun.COM 		freemsg(mp);
120711042SErik.Nordmark@Sun.COM 		return;
120811042SErik.Nordmark@Sun.COM 	}
120911042SErik.Nordmark@Sun.COM 	ip_hdr_length = ira->ira_ip_hdr_length;
121011042SErik.Nordmark@Sun.COM 	if ((mp->b_wptr - mp->b_rptr) < (ip_hdr_length + ICMP6_MINLEN)) {
121111042SErik.Nordmark@Sun.COM 		if (ira->ira_pktlen < (ip_hdr_length + ICMP6_MINLEN)) {
121211042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInTruncatedPkts);
121311042SErik.Nordmark@Sun.COM 			ip_drop_input("ipIfStatsInTruncatedPkts", mp, ill);
121411042SErik.Nordmark@Sun.COM 			freemsg(mp);
121511042SErik.Nordmark@Sun.COM 			return;
121611042SErik.Nordmark@Sun.COM 		}
121711042SErik.Nordmark@Sun.COM 		ip6h = ip_pullup(mp, ip_hdr_length + ICMP6_MINLEN, ira);
121811042SErik.Nordmark@Sun.COM 		if (ip6h == NULL) {
121911042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInErrors);
122011042SErik.Nordmark@Sun.COM 			freemsg(mp);
122111042SErik.Nordmark@Sun.COM 			return;
122211042SErik.Nordmark@Sun.COM 		}
122311042SErik.Nordmark@Sun.COM 	}
122411042SErik.Nordmark@Sun.COM 	icmp6 = (icmp6_t *)(&mp->b_rptr[ip_hdr_length]);
122511042SErik.Nordmark@Sun.COM 
122611042SErik.Nordmark@Sun.COM 	if (icmp6->icmp6_type != ND_NEIGHBOR_SOLICIT &&
122711042SErik.Nordmark@Sun.COM 	    icmp6->icmp6_type != ND_NEIGHBOR_ADVERT) {
122811042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
122911042SErik.Nordmark@Sun.COM 		ip_drop_input("ipIfStatsInDiscards - noaccept", mp, ill);
123011042SErik.Nordmark@Sun.COM 		freemsg(mp);
123111042SErik.Nordmark@Sun.COM 		return;
123211042SErik.Nordmark@Sun.COM 	}
123311042SErik.Nordmark@Sun.COM 	ire_recv_local_v6(ire, mp, ip6h, ira);
123411042SErik.Nordmark@Sun.COM }
123511042SErik.Nordmark@Sun.COM 
123611042SErik.Nordmark@Sun.COM /*
123711042SErik.Nordmark@Sun.COM  * ire_recvfn for IRE_MULTICAST.
123811042SErik.Nordmark@Sun.COM  */
123911042SErik.Nordmark@Sun.COM void
ire_recv_multicast_v6(ire_t * ire,mblk_t * mp,void * iph_arg,ip_recv_attr_t * ira)124011042SErik.Nordmark@Sun.COM ire_recv_multicast_v6(ire_t *ire, mblk_t *mp, void *iph_arg,
124111042SErik.Nordmark@Sun.COM     ip_recv_attr_t *ira)
124211042SErik.Nordmark@Sun.COM {
124311042SErik.Nordmark@Sun.COM 	ip6_t		*ip6h = (ip6_t *)iph_arg;
124411042SErik.Nordmark@Sun.COM 	ill_t		*ill = ira->ira_ill;
124511042SErik.Nordmark@Sun.COM 
124611042SErik.Nordmark@Sun.COM 	ASSERT(ire->ire_ill == ira->ira_ill);
124711042SErik.Nordmark@Sun.COM 
124811042SErik.Nordmark@Sun.COM 	BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInMcastPkts);
124911042SErik.Nordmark@Sun.COM 	UPDATE_MIB(ill->ill_ip_mib, ipIfStatsHCInMcastOctets, ira->ira_pktlen);
125011042SErik.Nordmark@Sun.COM 
125111042SErik.Nordmark@Sun.COM 	/* Tag for higher-level protocols */
125211042SErik.Nordmark@Sun.COM 	ira->ira_flags |= IRAF_MULTICAST;
125311042SErik.Nordmark@Sun.COM 
125411042SErik.Nordmark@Sun.COM 	/*
125511042SErik.Nordmark@Sun.COM 	 * So that we don't end up with dups, only one ill an IPMP group is
125611042SErik.Nordmark@Sun.COM 	 * nominated to receive multicast traffic.
125711042SErik.Nordmark@Sun.COM 	 * If we have no cast_ill we are liberal and accept everything.
125811042SErik.Nordmark@Sun.COM 	 */
125911042SErik.Nordmark@Sun.COM 	if (IS_UNDER_IPMP(ill)) {
126011042SErik.Nordmark@Sun.COM 		ip_stack_t	*ipst = ill->ill_ipst;
126111042SErik.Nordmark@Sun.COM 
126211042SErik.Nordmark@Sun.COM 		/* For an under ill_grp can change under lock */
126311042SErik.Nordmark@Sun.COM 		rw_enter(&ipst->ips_ill_g_lock, RW_READER);
126411042SErik.Nordmark@Sun.COM 		if (!ill->ill_nom_cast && ill->ill_grp != NULL &&
126511042SErik.Nordmark@Sun.COM 		    ill->ill_grp->ig_cast_ill != NULL) {
126611042SErik.Nordmark@Sun.COM 			rw_exit(&ipst->ips_ill_g_lock);
126711042SErik.Nordmark@Sun.COM 			ip_drop_input("not on cast ill", mp, ill);
126811042SErik.Nordmark@Sun.COM 			freemsg(mp);
126911042SErik.Nordmark@Sun.COM 			return;
127011042SErik.Nordmark@Sun.COM 		}
127111042SErik.Nordmark@Sun.COM 		rw_exit(&ipst->ips_ill_g_lock);
127211042SErik.Nordmark@Sun.COM 		/*
127311042SErik.Nordmark@Sun.COM 		 * We switch to the upper ill so that mrouter and hasmembers
127411042SErik.Nordmark@Sun.COM 		 * can operate on upper here and in ip_input_multicast.
127511042SErik.Nordmark@Sun.COM 		 */
127611042SErik.Nordmark@Sun.COM 		ill = ipmp_ill_hold_ipmp_ill(ill);
127711042SErik.Nordmark@Sun.COM 		if (ill != NULL) {
127811042SErik.Nordmark@Sun.COM 			ASSERT(ill != ira->ira_ill);
127911042SErik.Nordmark@Sun.COM 			ASSERT(ire->ire_ill == ira->ira_ill);
128011042SErik.Nordmark@Sun.COM 			ira->ira_ill = ill;
128111042SErik.Nordmark@Sun.COM 			ira->ira_ruifindex = ill->ill_phyint->phyint_ifindex;
128211042SErik.Nordmark@Sun.COM 		} else {
128311042SErik.Nordmark@Sun.COM 			ill = ira->ira_ill;
128411042SErik.Nordmark@Sun.COM 		}
128511042SErik.Nordmark@Sun.COM 	}
128611042SErik.Nordmark@Sun.COM 
128711042SErik.Nordmark@Sun.COM #ifdef notdef
128811042SErik.Nordmark@Sun.COM 	/*
128911042SErik.Nordmark@Sun.COM 	 * Check if we are a multicast router - send ip_mforward a copy of
129011042SErik.Nordmark@Sun.COM 	 * the packet.
129111042SErik.Nordmark@Sun.COM 	 * Due to mroute_decap tunnels we consider forwarding packets even if
129211042SErik.Nordmark@Sun.COM 	 * mrouted has not joined the allmulti group on this interface.
129311042SErik.Nordmark@Sun.COM 	 */
129411042SErik.Nordmark@Sun.COM 	if (ipst->ips_ip_g_mrouter) {
129511042SErik.Nordmark@Sun.COM 		int retval;
129611042SErik.Nordmark@Sun.COM 
129711042SErik.Nordmark@Sun.COM 		/*
129811042SErik.Nordmark@Sun.COM 		 * Clear the indication that this may have hardware
129911042SErik.Nordmark@Sun.COM 		 * checksum as we are not using it for forwarding.
130011042SErik.Nordmark@Sun.COM 		 */
130111042SErik.Nordmark@Sun.COM 		DB_CKSUMFLAGS(mp) = 0;
130211042SErik.Nordmark@Sun.COM 
130311042SErik.Nordmark@Sun.COM 		/*
130411042SErik.Nordmark@Sun.COM 		 * ip_mforward helps us make these distinctions: If received
130511042SErik.Nordmark@Sun.COM 		 * on tunnel and not IGMP, then drop.
130611042SErik.Nordmark@Sun.COM 		 * If IGMP packet, then don't check membership
130711042SErik.Nordmark@Sun.COM 		 * If received on a phyint and IGMP or PIM, then
130811042SErik.Nordmark@Sun.COM 		 * don't check membership
130911042SErik.Nordmark@Sun.COM 		 */
131011042SErik.Nordmark@Sun.COM 		retval = ip_mforward_v6(mp, ira);
131111042SErik.Nordmark@Sun.COM 		/* ip_mforward updates mib variables if needed */
131211042SErik.Nordmark@Sun.COM 
131311042SErik.Nordmark@Sun.COM 		switch (retval) {
131411042SErik.Nordmark@Sun.COM 		case 0:
131511042SErik.Nordmark@Sun.COM 			/*
131611042SErik.Nordmark@Sun.COM 			 * pkt is okay and arrived on phyint.
131711042SErik.Nordmark@Sun.COM 			 */
131811042SErik.Nordmark@Sun.COM 			break;
131911042SErik.Nordmark@Sun.COM 		case -1:
132011042SErik.Nordmark@Sun.COM 			/* pkt is mal-formed, toss it */
132111042SErik.Nordmark@Sun.COM 			freemsg(mp);
132211042SErik.Nordmark@Sun.COM 			goto done;
132311042SErik.Nordmark@Sun.COM 		case 1:
132411042SErik.Nordmark@Sun.COM 			/*
132511042SErik.Nordmark@Sun.COM 			 * pkt is okay and arrived on a tunnel
132611042SErik.Nordmark@Sun.COM 			 *
132711042SErik.Nordmark@Sun.COM 			 * If we are running a multicast router
132811042SErik.Nordmark@Sun.COM 			 * we need to see all mld packets, which
132911042SErik.Nordmark@Sun.COM 			 * are marked with router alerts.
133011042SErik.Nordmark@Sun.COM 			 */
133111042SErik.Nordmark@Sun.COM 			if (ira->ira_flags & IRAF_ROUTER_ALERT)
133211042SErik.Nordmark@Sun.COM 				goto forus;
133311042SErik.Nordmark@Sun.COM 			ip_drop_input("Multicast on tunnel ignored", mp, ill);
133411042SErik.Nordmark@Sun.COM 			freemsg(mp);
133511042SErik.Nordmark@Sun.COM 			goto done;
133611042SErik.Nordmark@Sun.COM 		}
133711042SErik.Nordmark@Sun.COM 	}
133811042SErik.Nordmark@Sun.COM #endif /* notdef */
133911042SErik.Nordmark@Sun.COM 
134011042SErik.Nordmark@Sun.COM 	/*
134111042SErik.Nordmark@Sun.COM 	 * If this was a router alert we skip the group membership check.
134211042SErik.Nordmark@Sun.COM 	 */
134311042SErik.Nordmark@Sun.COM 	if (ira->ira_flags & IRAF_ROUTER_ALERT)
134411042SErik.Nordmark@Sun.COM 		goto forus;
134511042SErik.Nordmark@Sun.COM 
134611042SErik.Nordmark@Sun.COM 	/*
134711042SErik.Nordmark@Sun.COM 	 * Check if we have members on this ill. This is not necessary for
134811042SErik.Nordmark@Sun.COM 	 * correctness because even if the NIC/GLD had a leaky filter, we
134911042SErik.Nordmark@Sun.COM 	 * filter before passing to each conn_t.
135011042SErik.Nordmark@Sun.COM 	 */
135111042SErik.Nordmark@Sun.COM 	if (!ill_hasmembers_v6(ill, &ip6h->ip6_dst)) {
135211042SErik.Nordmark@Sun.COM 		/*
135311042SErik.Nordmark@Sun.COM 		 * Nobody interested
135411042SErik.Nordmark@Sun.COM 		 *
135511042SErik.Nordmark@Sun.COM 		 * This might just be caused by the fact that
135611042SErik.Nordmark@Sun.COM 		 * multiple IP Multicast addresses map to the same
135711042SErik.Nordmark@Sun.COM 		 * link layer multicast - no need to increment counter!
135811042SErik.Nordmark@Sun.COM 		 */
135911042SErik.Nordmark@Sun.COM 		ip_drop_input("Multicast with no members", mp, ill);
136011042SErik.Nordmark@Sun.COM 		freemsg(mp);
136111042SErik.Nordmark@Sun.COM 		goto done;
136211042SErik.Nordmark@Sun.COM 	}
136311042SErik.Nordmark@Sun.COM forus:
136411042SErik.Nordmark@Sun.COM 	ip2dbg(("ire_recv_multicast_v6: multicast for us\n"));
136511042SErik.Nordmark@Sun.COM 
136611042SErik.Nordmark@Sun.COM 	/*
136711042SErik.Nordmark@Sun.COM 	 * After reassembly and IPsec we will need to duplicate the
136811042SErik.Nordmark@Sun.COM 	 * multicast packet for all matching zones on the ill.
136911042SErik.Nordmark@Sun.COM 	 */
137011042SErik.Nordmark@Sun.COM 	ira->ira_zoneid = ALL_ZONES;
137111042SErik.Nordmark@Sun.COM 
137211042SErik.Nordmark@Sun.COM 	/* Reassemble on the ill on which the packet arrived */
137311042SErik.Nordmark@Sun.COM 	ip_input_local_v6(ire, mp, ip6h, ira);
137411042SErik.Nordmark@Sun.COM done:
137511042SErik.Nordmark@Sun.COM 	if (ill != ire->ire_ill) {
137611042SErik.Nordmark@Sun.COM 		ill_refrele(ill);
137711042SErik.Nordmark@Sun.COM 		ira->ira_ill = ire->ire_ill;
137811042SErik.Nordmark@Sun.COM 		ira->ira_ruifindex = ira->ira_ill->ill_phyint->phyint_ifindex;
137911042SErik.Nordmark@Sun.COM 	}
138011042SErik.Nordmark@Sun.COM }
138111042SErik.Nordmark@Sun.COM 
138211042SErik.Nordmark@Sun.COM /*
138311042SErik.Nordmark@Sun.COM  * ire_recvfn for IRE_OFFLINK with RTF_MULTIRT.
138411042SErik.Nordmark@Sun.COM  * Drop packets since we don't forward out multirt routes.
138511042SErik.Nordmark@Sun.COM  */
138611042SErik.Nordmark@Sun.COM /* ARGSUSED */
138711042SErik.Nordmark@Sun.COM void
ire_recv_multirt_v6(ire_t * ire,mblk_t * mp,void * iph_arg,ip_recv_attr_t * ira)138811042SErik.Nordmark@Sun.COM ire_recv_multirt_v6(ire_t *ire, mblk_t *mp, void *iph_arg, ip_recv_attr_t *ira)
138911042SErik.Nordmark@Sun.COM {
139011042SErik.Nordmark@Sun.COM 	ill_t		*ill = ira->ira_ill;
139111042SErik.Nordmark@Sun.COM 
139211042SErik.Nordmark@Sun.COM 	BUMP_MIB(ill->ill_ip_mib, ipIfStatsInNoRoutes);
139311042SErik.Nordmark@Sun.COM 	ip_drop_input("Not forwarding out MULTIRT", mp, ill);
139411042SErik.Nordmark@Sun.COM 	freemsg(mp);
139511042SErik.Nordmark@Sun.COM }
139611042SErik.Nordmark@Sun.COM 
139711042SErik.Nordmark@Sun.COM /*
139811042SErik.Nordmark@Sun.COM  * ire_recvfn for IRE_LOOPBACK. This is only used when a FW_HOOK
139911042SErik.Nordmark@Sun.COM  * has rewritten the packet to have a loopback destination address (We
140011042SErik.Nordmark@Sun.COM  * filter out packet with a loopback destination from arriving over the wire).
140111042SErik.Nordmark@Sun.COM  * We don't know what zone to use, thus we always use the GLOBAL_ZONEID.
140211042SErik.Nordmark@Sun.COM  */
140311042SErik.Nordmark@Sun.COM void
ire_recv_loopback_v6(ire_t * ire,mblk_t * mp,void * iph_arg,ip_recv_attr_t * ira)140411042SErik.Nordmark@Sun.COM ire_recv_loopback_v6(ire_t *ire, mblk_t *mp, void *iph_arg, ip_recv_attr_t *ira)
140511042SErik.Nordmark@Sun.COM {
140611042SErik.Nordmark@Sun.COM 	ip6_t		*ip6h = (ip6_t *)iph_arg;
140711042SErik.Nordmark@Sun.COM 	ill_t		*ill = ira->ira_ill;
140811042SErik.Nordmark@Sun.COM 	ill_t		*ire_ill = ire->ire_ill;
140911042SErik.Nordmark@Sun.COM 
141011042SErik.Nordmark@Sun.COM 	ira->ira_zoneid = GLOBAL_ZONEID;
141111042SErik.Nordmark@Sun.COM 
141211042SErik.Nordmark@Sun.COM 	/* Switch to the lo0 ill for further processing  */
141311042SErik.Nordmark@Sun.COM 	if (ire_ill != ill) {
141411042SErik.Nordmark@Sun.COM 		/*
141511042SErik.Nordmark@Sun.COM 		 * Update ira_ill to be the ILL on which the IP address
141611042SErik.Nordmark@Sun.COM 		 * is hosted.
141711042SErik.Nordmark@Sun.COM 		 * No need to hold the ill since we have a hold on the ire
141811042SErik.Nordmark@Sun.COM 		 */
141911042SErik.Nordmark@Sun.COM 		ASSERT(ira->ira_ill == ira->ira_rill);
142011042SErik.Nordmark@Sun.COM 		ira->ira_ill = ire_ill;
142111042SErik.Nordmark@Sun.COM 
142211042SErik.Nordmark@Sun.COM 		ip_input_local_v6(ire, mp, ip6h, ira);
142311042SErik.Nordmark@Sun.COM 
142411042SErik.Nordmark@Sun.COM 		/* Restore */
142511042SErik.Nordmark@Sun.COM 		ASSERT(ira->ira_ill == ire_ill);
142611042SErik.Nordmark@Sun.COM 		ira->ira_ill = ill;
142711042SErik.Nordmark@Sun.COM 		return;
142811042SErik.Nordmark@Sun.COM 
142911042SErik.Nordmark@Sun.COM 	}
143011042SErik.Nordmark@Sun.COM 	ip_input_local_v6(ire, mp, ip6h, ira);
143111042SErik.Nordmark@Sun.COM }
143211042SErik.Nordmark@Sun.COM 
143311042SErik.Nordmark@Sun.COM /*
143411042SErik.Nordmark@Sun.COM  * ire_recvfn for IRE_LOCAL.
143511042SErik.Nordmark@Sun.COM  */
143611042SErik.Nordmark@Sun.COM void
ire_recv_local_v6(ire_t * ire,mblk_t * mp,void * iph_arg,ip_recv_attr_t * ira)143711042SErik.Nordmark@Sun.COM ire_recv_local_v6(ire_t *ire, mblk_t *mp, void *iph_arg, ip_recv_attr_t *ira)
143811042SErik.Nordmark@Sun.COM {
143911042SErik.Nordmark@Sun.COM 	ip6_t		*ip6h = (ip6_t *)iph_arg;
144011042SErik.Nordmark@Sun.COM 	ill_t		*ill = ira->ira_ill;
144111042SErik.Nordmark@Sun.COM 	ill_t		*ire_ill = ire->ire_ill;
144211042SErik.Nordmark@Sun.COM 
144311042SErik.Nordmark@Sun.COM 	/* Make a note for DAD that this address is in use */
144411110SErik.Nordmark@Sun.COM 	ire->ire_last_used_time = LBOLT_FASTPATH;
144511042SErik.Nordmark@Sun.COM 
144611042SErik.Nordmark@Sun.COM 	/* Only target the IRE_LOCAL with the right zoneid. */
144711042SErik.Nordmark@Sun.COM 	ira->ira_zoneid = ire->ire_zoneid;
144811042SErik.Nordmark@Sun.COM 
144911042SErik.Nordmark@Sun.COM 	/*
145011042SErik.Nordmark@Sun.COM 	 * If the packet arrived on the wrong ill, we check that
145111042SErik.Nordmark@Sun.COM 	 * this is ok.
145211042SErik.Nordmark@Sun.COM 	 * If it is, then we ensure that we do the reassembly on
145311042SErik.Nordmark@Sun.COM 	 * the ill on which the address is hosted. We keep ira_rill as
145411042SErik.Nordmark@Sun.COM 	 * the one on which the packet arrived, so that IP_PKTINFO and
145511042SErik.Nordmark@Sun.COM 	 * friends can report this.
145611042SErik.Nordmark@Sun.COM 	 */
145711042SErik.Nordmark@Sun.COM 	if (ire_ill != ill) {
145811042SErik.Nordmark@Sun.COM 		ire_t *new_ire;
145911042SErik.Nordmark@Sun.COM 
146011042SErik.Nordmark@Sun.COM 		new_ire = ip_check_multihome(&ip6h->ip6_dst, ire, ill);
146111042SErik.Nordmark@Sun.COM 		if (new_ire == NULL) {
146211042SErik.Nordmark@Sun.COM 			/* Drop packet */
146311042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
146411042SErik.Nordmark@Sun.COM 			ip_drop_input("ipIfStatsInForwProhibits", mp, ill);
146511042SErik.Nordmark@Sun.COM 			freemsg(mp);
146611042SErik.Nordmark@Sun.COM 			return;
146711042SErik.Nordmark@Sun.COM 		}
146811042SErik.Nordmark@Sun.COM 		/*
146911042SErik.Nordmark@Sun.COM 		 * Update ira_ill to be the ILL on which the IP address
147011042SErik.Nordmark@Sun.COM 		 * is hosted. No need to hold the ill since we have a
147111042SErik.Nordmark@Sun.COM 		 * hold on the ire. Note that we do the switch even if
147211042SErik.Nordmark@Sun.COM 		 * new_ire == ire (for IPMP, ire would be the one corresponding
147311042SErik.Nordmark@Sun.COM 		 * to the IPMP ill).
147411042SErik.Nordmark@Sun.COM 		 */
147511042SErik.Nordmark@Sun.COM 		ASSERT(ira->ira_ill == ira->ira_rill);
147611042SErik.Nordmark@Sun.COM 		ira->ira_ill = new_ire->ire_ill;
147711042SErik.Nordmark@Sun.COM 
147811042SErik.Nordmark@Sun.COM 		/* ira_ruifindex tracks the upper for ira_rill */
147911042SErik.Nordmark@Sun.COM 		if (IS_UNDER_IPMP(ill))
148011042SErik.Nordmark@Sun.COM 			ira->ira_ruifindex = ill_get_upper_ifindex(ill);
148111042SErik.Nordmark@Sun.COM 
148211042SErik.Nordmark@Sun.COM 		ip_input_local_v6(new_ire, mp, ip6h, ira);
148311042SErik.Nordmark@Sun.COM 
148411042SErik.Nordmark@Sun.COM 		/* Restore */
148511042SErik.Nordmark@Sun.COM 		ASSERT(ira->ira_ill == new_ire->ire_ill);
148611042SErik.Nordmark@Sun.COM 		ira->ira_ill = ill;
148711042SErik.Nordmark@Sun.COM 		ira->ira_ruifindex = ill->ill_phyint->phyint_ifindex;
148811042SErik.Nordmark@Sun.COM 
148911042SErik.Nordmark@Sun.COM 		if (new_ire != ire)
149011042SErik.Nordmark@Sun.COM 			ire_refrele(new_ire);
149111042SErik.Nordmark@Sun.COM 		return;
149211042SErik.Nordmark@Sun.COM 	}
149311042SErik.Nordmark@Sun.COM 
149411042SErik.Nordmark@Sun.COM 	ip_input_local_v6(ire, mp, ip6h, ira);
149511042SErik.Nordmark@Sun.COM }
149611042SErik.Nordmark@Sun.COM 
149711042SErik.Nordmark@Sun.COM /*
149811042SErik.Nordmark@Sun.COM  * Common function for packets arriving for the host. Handles
149911042SErik.Nordmark@Sun.COM  * checksum verification, reassembly checks, etc.
150011042SErik.Nordmark@Sun.COM  */
150111042SErik.Nordmark@Sun.COM static void
ip_input_local_v6(ire_t * ire,mblk_t * mp,ip6_t * ip6h,ip_recv_attr_t * ira)150211042SErik.Nordmark@Sun.COM ip_input_local_v6(ire_t *ire, mblk_t *mp, ip6_t *ip6h, ip_recv_attr_t *ira)
150311042SErik.Nordmark@Sun.COM {
150411042SErik.Nordmark@Sun.COM 	iaflags_t	iraflags = ira->ira_flags;
150511042SErik.Nordmark@Sun.COM 
150611042SErik.Nordmark@Sun.COM 	/*
150711042SErik.Nordmark@Sun.COM 	 * For multicast we need some extra work before
150811042SErik.Nordmark@Sun.COM 	 * we call ip_fanout_v6(), since in the case of shared-IP zones
150911042SErik.Nordmark@Sun.COM 	 * we need to pretend that a packet arrived for each zoneid.
151011042SErik.Nordmark@Sun.COM 	 */
151111042SErik.Nordmark@Sun.COM 	if (iraflags & IRAF_MULTICAST) {
151211042SErik.Nordmark@Sun.COM 		ip_input_multicast_v6(ire, mp, ip6h, ira);
151311042SErik.Nordmark@Sun.COM 		return;
151411042SErik.Nordmark@Sun.COM 	}
151511042SErik.Nordmark@Sun.COM 	ip_fanout_v6(mp, ip6h, ira);
151611042SErik.Nordmark@Sun.COM }
151711042SErik.Nordmark@Sun.COM 
151811042SErik.Nordmark@Sun.COM /*
151911042SErik.Nordmark@Sun.COM  * Handle multiple zones which want to receive the same multicast packets
152011042SErik.Nordmark@Sun.COM  * on this ill by delivering a packet to each of them.
152111042SErik.Nordmark@Sun.COM  *
152211042SErik.Nordmark@Sun.COM  * Note that for packets delivered to transports we could instead do this
152311042SErik.Nordmark@Sun.COM  * as part of the fanout code, but since we need to handle icmp_inbound
152411042SErik.Nordmark@Sun.COM  * it is simpler to have multicast work the same as IPv4 broadcast.
152511042SErik.Nordmark@Sun.COM  *
152611042SErik.Nordmark@Sun.COM  * The ip_fanout matching for multicast matches based on ilm independent of
152711042SErik.Nordmark@Sun.COM  * zoneid since the zoneid restriction is applied when joining a multicast
152811042SErik.Nordmark@Sun.COM  * group.
152911042SErik.Nordmark@Sun.COM  */
153011042SErik.Nordmark@Sun.COM /* ARGSUSED */
153111042SErik.Nordmark@Sun.COM static void
ip_input_multicast_v6(ire_t * ire,mblk_t * mp,ip6_t * ip6h,ip_recv_attr_t * ira)153211042SErik.Nordmark@Sun.COM ip_input_multicast_v6(ire_t *ire, mblk_t *mp, ip6_t *ip6h, ip_recv_attr_t *ira)
153311042SErik.Nordmark@Sun.COM {
153411042SErik.Nordmark@Sun.COM 	ill_t		*ill = ira->ira_ill;
153511042SErik.Nordmark@Sun.COM 	iaflags_t	iraflags = ira->ira_flags;
153611042SErik.Nordmark@Sun.COM 	ip_stack_t	*ipst = ill->ill_ipst;
153711042SErik.Nordmark@Sun.COM 	netstack_t	*ns = ipst->ips_netstack;
153811042SErik.Nordmark@Sun.COM 	zoneid_t	zoneid;
153911042SErik.Nordmark@Sun.COM 	mblk_t		*mp1;
154011042SErik.Nordmark@Sun.COM 	ip6_t		*ip6h1;
154111681SSowmini.Varadhan@Sun.COM 	uint_t		ira_pktlen = ira->ira_pktlen;
154211681SSowmini.Varadhan@Sun.COM 	uint16_t	ira_ip_hdr_length = ira->ira_ip_hdr_length;
154311042SErik.Nordmark@Sun.COM 
154411042SErik.Nordmark@Sun.COM 	/* ire_recv_multicast has switched to the upper ill for IPMP */
154511042SErik.Nordmark@Sun.COM 	ASSERT(!IS_UNDER_IPMP(ill));
154611042SErik.Nordmark@Sun.COM 
154711042SErik.Nordmark@Sun.COM 	/*
154811042SErik.Nordmark@Sun.COM 	 * If we don't have more than one shared-IP zone, or if
154911042SErik.Nordmark@Sun.COM 	 * there are no members in anything but the global zone,
155011042SErik.Nordmark@Sun.COM 	 * then just set the zoneid and proceed.
155111042SErik.Nordmark@Sun.COM 	 */
155211042SErik.Nordmark@Sun.COM 	if (ns->netstack_numzones == 1 ||
155311042SErik.Nordmark@Sun.COM 	    !ill_hasmembers_otherzones_v6(ill, &ip6h->ip6_dst,
155411042SErik.Nordmark@Sun.COM 	    GLOBAL_ZONEID)) {
155511042SErik.Nordmark@Sun.COM 		ira->ira_zoneid = GLOBAL_ZONEID;
155611042SErik.Nordmark@Sun.COM 
155711042SErik.Nordmark@Sun.COM 		/* If sender didn't want this zone to receive it, drop */
155811042SErik.Nordmark@Sun.COM 		if ((iraflags & IRAF_NO_LOOP_ZONEID_SET) &&
155911042SErik.Nordmark@Sun.COM 		    ira->ira_no_loop_zoneid == ira->ira_zoneid) {
156011042SErik.Nordmark@Sun.COM 			ip_drop_input("Multicast but wrong zoneid", mp, ill);
156111042SErik.Nordmark@Sun.COM 			freemsg(mp);
156211042SErik.Nordmark@Sun.COM 			return;
156311042SErik.Nordmark@Sun.COM 		}
156411042SErik.Nordmark@Sun.COM 		ip_fanout_v6(mp, ip6h, ira);
156511042SErik.Nordmark@Sun.COM 		return;
156611042SErik.Nordmark@Sun.COM 	}
156711042SErik.Nordmark@Sun.COM 
156811042SErik.Nordmark@Sun.COM 	/*
156911042SErik.Nordmark@Sun.COM 	 * Here we loop over all zoneids that have members in the group
157011042SErik.Nordmark@Sun.COM 	 * and deliver a packet to ip_fanout for each zoneid.
157111042SErik.Nordmark@Sun.COM 	 *
157211042SErik.Nordmark@Sun.COM 	 * First find any members in the lowest numeric zoneid by looking for
157311042SErik.Nordmark@Sun.COM 	 * first zoneid larger than -1 (ALL_ZONES).
157411042SErik.Nordmark@Sun.COM 	 * We terminate the loop when we receive -1 (ALL_ZONES).
157511042SErik.Nordmark@Sun.COM 	 */
157611042SErik.Nordmark@Sun.COM 	zoneid = ill_hasmembers_nextzone_v6(ill, &ip6h->ip6_dst, ALL_ZONES);
157711042SErik.Nordmark@Sun.COM 	for (; zoneid != ALL_ZONES;
157811042SErik.Nordmark@Sun.COM 	    zoneid = ill_hasmembers_nextzone_v6(ill, &ip6h->ip6_dst, zoneid)) {
157911042SErik.Nordmark@Sun.COM 		/*
158011042SErik.Nordmark@Sun.COM 		 * Avoid an extra copymsg/freemsg by skipping global zone here
158111042SErik.Nordmark@Sun.COM 		 * and doing that at the end.
158211042SErik.Nordmark@Sun.COM 		 */
158311042SErik.Nordmark@Sun.COM 		if (zoneid == GLOBAL_ZONEID)
158411042SErik.Nordmark@Sun.COM 			continue;
158511042SErik.Nordmark@Sun.COM 
158611042SErik.Nordmark@Sun.COM 		ira->ira_zoneid = zoneid;
158711042SErik.Nordmark@Sun.COM 
158811042SErik.Nordmark@Sun.COM 		/* If sender didn't want this zone to receive it, skip */
158911042SErik.Nordmark@Sun.COM 		if ((iraflags & IRAF_NO_LOOP_ZONEID_SET) &&
159011042SErik.Nordmark@Sun.COM 		    ira->ira_no_loop_zoneid == ira->ira_zoneid)
159111042SErik.Nordmark@Sun.COM 			continue;
159211042SErik.Nordmark@Sun.COM 
159311042SErik.Nordmark@Sun.COM 		mp1 = copymsg(mp);
159411042SErik.Nordmark@Sun.COM 		if (mp1 == NULL) {
159511042SErik.Nordmark@Sun.COM 			/* Failed to deliver to one zone */
159611042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
159711042SErik.Nordmark@Sun.COM 			ip_drop_input("ipIfStatsInDiscards", mp, ill);
159811042SErik.Nordmark@Sun.COM 			continue;
159911042SErik.Nordmark@Sun.COM 		}
160011042SErik.Nordmark@Sun.COM 		ip6h1 = (ip6_t *)mp1->b_rptr;
160111042SErik.Nordmark@Sun.COM 		ip_fanout_v6(mp1, ip6h1, ira);
160211681SSowmini.Varadhan@Sun.COM 		/*
160311681SSowmini.Varadhan@Sun.COM 		 * IPsec might have modified ira_pktlen and ira_ip_hdr_length
160411681SSowmini.Varadhan@Sun.COM 		 * so we restore them for a potential next iteration
160511681SSowmini.Varadhan@Sun.COM 		 */
160611681SSowmini.Varadhan@Sun.COM 		ira->ira_pktlen = ira_pktlen;
160711681SSowmini.Varadhan@Sun.COM 		ira->ira_ip_hdr_length = ira_ip_hdr_length;
160811042SErik.Nordmark@Sun.COM 	}
160911042SErik.Nordmark@Sun.COM 
161011042SErik.Nordmark@Sun.COM 	/* Do the main ire */
161111042SErik.Nordmark@Sun.COM 	ira->ira_zoneid = GLOBAL_ZONEID;
161211042SErik.Nordmark@Sun.COM 	/* If sender didn't want this zone to receive it, drop */
161311042SErik.Nordmark@Sun.COM 	if ((iraflags & IRAF_NO_LOOP_ZONEID_SET) &&
161411042SErik.Nordmark@Sun.COM 	    ira->ira_no_loop_zoneid == ira->ira_zoneid) {
161511042SErik.Nordmark@Sun.COM 		ip_drop_input("Multicast but wrong zoneid", mp, ill);
161611042SErik.Nordmark@Sun.COM 		freemsg(mp);
161711042SErik.Nordmark@Sun.COM 	} else {
161811042SErik.Nordmark@Sun.COM 		ip_fanout_v6(mp, ip6h, ira);
161911042SErik.Nordmark@Sun.COM 	}
162011042SErik.Nordmark@Sun.COM }
162111042SErik.Nordmark@Sun.COM 
162211042SErik.Nordmark@Sun.COM 
162311042SErik.Nordmark@Sun.COM /*
162411042SErik.Nordmark@Sun.COM  * Determine the zoneid and IRAF_TX_MAC_EXEMPTABLE if trusted extensions
162511042SErik.Nordmark@Sun.COM  * is in use. Updates ira_zoneid and ira_flags as a result.
162611042SErik.Nordmark@Sun.COM  */
162711042SErik.Nordmark@Sun.COM static void
ip_fanout_tx_v6(mblk_t * mp,ip6_t * ip6h,uint8_t protocol,uint_t ip_hdr_length,ip_recv_attr_t * ira)162811042SErik.Nordmark@Sun.COM ip_fanout_tx_v6(mblk_t *mp, ip6_t *ip6h, uint8_t protocol, uint_t ip_hdr_length,
162911042SErik.Nordmark@Sun.COM     ip_recv_attr_t *ira)
163011042SErik.Nordmark@Sun.COM {
163111042SErik.Nordmark@Sun.COM 	uint16_t	*up;
163211042SErik.Nordmark@Sun.COM 	uint16_t	lport;
163311042SErik.Nordmark@Sun.COM 	zoneid_t	zoneid;
163411042SErik.Nordmark@Sun.COM 
163511042SErik.Nordmark@Sun.COM 	ASSERT(ira->ira_flags & IRAF_SYSTEM_LABELED);
163611042SErik.Nordmark@Sun.COM 
163711042SErik.Nordmark@Sun.COM 	/*
163811042SErik.Nordmark@Sun.COM 	 * If the packet is unlabeled we might allow read-down
163911042SErik.Nordmark@Sun.COM 	 * for MAC_EXEMPT. Below we clear this if it is a multi-level
164011042SErik.Nordmark@Sun.COM 	 * port (MLP).
164111042SErik.Nordmark@Sun.COM 	 * Note that ira_tsl can be NULL here.
164211042SErik.Nordmark@Sun.COM 	 */
164311042SErik.Nordmark@Sun.COM 	if (ira->ira_tsl != NULL && ira->ira_tsl->tsl_flags & TSLF_UNLABELED)
164411042SErik.Nordmark@Sun.COM 		ira->ira_flags |= IRAF_TX_MAC_EXEMPTABLE;
164511042SErik.Nordmark@Sun.COM 
164611042SErik.Nordmark@Sun.COM 	if (ira->ira_zoneid != ALL_ZONES)
164711042SErik.Nordmark@Sun.COM 		return;
164811042SErik.Nordmark@Sun.COM 
164911042SErik.Nordmark@Sun.COM 	ira->ira_flags |= IRAF_TX_SHARED_ADDR;
165011042SErik.Nordmark@Sun.COM 
165111042SErik.Nordmark@Sun.COM 	up = (uint16_t *)((uchar_t *)ip6h + ip_hdr_length);
165211042SErik.Nordmark@Sun.COM 	switch (protocol) {
165311042SErik.Nordmark@Sun.COM 	case IPPROTO_TCP:
165411042SErik.Nordmark@Sun.COM 	case IPPROTO_SCTP:
165511042SErik.Nordmark@Sun.COM 	case IPPROTO_UDP:
165611042SErik.Nordmark@Sun.COM 		/* Caller ensures this */
165711042SErik.Nordmark@Sun.COM 		ASSERT(((uchar_t *)ip6h) + ip_hdr_length +4 <= mp->b_wptr);
165811042SErik.Nordmark@Sun.COM 
165911042SErik.Nordmark@Sun.COM 		/*
166011042SErik.Nordmark@Sun.COM 		 * Only these transports support MLP.
166111042SErik.Nordmark@Sun.COM 		 * We know their destination port numbers is in
166211042SErik.Nordmark@Sun.COM 		 * the same place in the header.
166311042SErik.Nordmark@Sun.COM 		 */
166411042SErik.Nordmark@Sun.COM 		lport = up[1];
166511042SErik.Nordmark@Sun.COM 
166611042SErik.Nordmark@Sun.COM 		/*
166711042SErik.Nordmark@Sun.COM 		 * No need to handle exclusive-stack zones
166811042SErik.Nordmark@Sun.COM 		 * since ALL_ZONES only applies to the shared IP instance.
166911042SErik.Nordmark@Sun.COM 		 */
167011042SErik.Nordmark@Sun.COM 		zoneid = tsol_mlp_findzone(protocol, lport);
167111042SErik.Nordmark@Sun.COM 		/*
167211042SErik.Nordmark@Sun.COM 		 * If no shared MLP is found, tsol_mlp_findzone returns
167311042SErik.Nordmark@Sun.COM 		 * ALL_ZONES.  In that case, we assume it's SLP, and
167411042SErik.Nordmark@Sun.COM 		 * search for the zone based on the packet label.
167511042SErik.Nordmark@Sun.COM 		 *
167611042SErik.Nordmark@Sun.COM 		 * If there is such a zone, we prefer to find a
167711042SErik.Nordmark@Sun.COM 		 * connection in it.  Otherwise, we look for a
167811042SErik.Nordmark@Sun.COM 		 * MAC-exempt connection in any zone whose label
167911042SErik.Nordmark@Sun.COM 		 * dominates the default label on the packet.
168011042SErik.Nordmark@Sun.COM 		 */
168111042SErik.Nordmark@Sun.COM 		if (zoneid == ALL_ZONES)
168211042SErik.Nordmark@Sun.COM 			zoneid = tsol_attr_to_zoneid(ira);
168311042SErik.Nordmark@Sun.COM 		else
168411042SErik.Nordmark@Sun.COM 			ira->ira_flags &= ~IRAF_TX_MAC_EXEMPTABLE;
168511042SErik.Nordmark@Sun.COM 		break;
168611042SErik.Nordmark@Sun.COM 	default:
168711042SErik.Nordmark@Sun.COM 		/* Handle shared address for other protocols */
168811042SErik.Nordmark@Sun.COM 		zoneid = tsol_attr_to_zoneid(ira);
168911042SErik.Nordmark@Sun.COM 		break;
169011042SErik.Nordmark@Sun.COM 	}
169111042SErik.Nordmark@Sun.COM 	ira->ira_zoneid = zoneid;
169211042SErik.Nordmark@Sun.COM }
169311042SErik.Nordmark@Sun.COM 
169411042SErik.Nordmark@Sun.COM /*
169511042SErik.Nordmark@Sun.COM  * Increment checksum failure statistics
169611042SErik.Nordmark@Sun.COM  */
169711042SErik.Nordmark@Sun.COM static void
ip_input_cksum_err_v6(uint8_t protocol,uint16_t hck_flags,ill_t * ill)169811042SErik.Nordmark@Sun.COM ip_input_cksum_err_v6(uint8_t protocol, uint16_t hck_flags, ill_t *ill)
169911042SErik.Nordmark@Sun.COM {
170011042SErik.Nordmark@Sun.COM 	ip_stack_t	*ipst = ill->ill_ipst;
170111042SErik.Nordmark@Sun.COM 
170211042SErik.Nordmark@Sun.COM 	switch (protocol) {
170311042SErik.Nordmark@Sun.COM 	case IPPROTO_TCP:
170411042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, tcpIfStatsInErrs);
170511042SErik.Nordmark@Sun.COM 
170611042SErik.Nordmark@Sun.COM 		if (hck_flags & HCK_FULLCKSUM)
170711042SErik.Nordmark@Sun.COM 			IP6_STAT(ipst, ip6_tcp_in_full_hw_cksum_err);
170811042SErik.Nordmark@Sun.COM 		else if (hck_flags & HCK_PARTIALCKSUM)
170911042SErik.Nordmark@Sun.COM 			IP6_STAT(ipst, ip6_tcp_in_part_hw_cksum_err);
171011042SErik.Nordmark@Sun.COM 		else
171111042SErik.Nordmark@Sun.COM 			IP6_STAT(ipst, ip6_tcp_in_sw_cksum_err);
171211042SErik.Nordmark@Sun.COM 		break;
171311042SErik.Nordmark@Sun.COM 	case IPPROTO_UDP:
171411042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, udpIfStatsInCksumErrs);
171511042SErik.Nordmark@Sun.COM 		if (hck_flags & HCK_FULLCKSUM)
171611042SErik.Nordmark@Sun.COM 			IP6_STAT(ipst, ip6_udp_in_full_hw_cksum_err);
171711042SErik.Nordmark@Sun.COM 		else if (hck_flags & HCK_PARTIALCKSUM)
171811042SErik.Nordmark@Sun.COM 			IP6_STAT(ipst, ip6_udp_in_part_hw_cksum_err);
171911042SErik.Nordmark@Sun.COM 		else
172011042SErik.Nordmark@Sun.COM 			IP6_STAT(ipst, ip6_udp_in_sw_cksum_err);
172111042SErik.Nordmark@Sun.COM 		break;
172211042SErik.Nordmark@Sun.COM 	case IPPROTO_ICMPV6:
172311042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInMsgs);
172411042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInErrors);
172511042SErik.Nordmark@Sun.COM 		break;
172611042SErik.Nordmark@Sun.COM 	default:
172711042SErik.Nordmark@Sun.COM 		ASSERT(0);
172811042SErik.Nordmark@Sun.COM 		break;
172911042SErik.Nordmark@Sun.COM 	}
173011042SErik.Nordmark@Sun.COM }
173111042SErik.Nordmark@Sun.COM 
173211042SErik.Nordmark@Sun.COM /* Calculate the IPv6 pseudo-header checksum for TCP, UDP, and ICMPV6 */
173311042SErik.Nordmark@Sun.COM uint32_t
ip_input_cksum_pseudo_v6(ip6_t * ip6h,ip_recv_attr_t * ira)173411042SErik.Nordmark@Sun.COM ip_input_cksum_pseudo_v6(ip6_t *ip6h, ip_recv_attr_t *ira)
173511042SErik.Nordmark@Sun.COM {
173611042SErik.Nordmark@Sun.COM 	uint_t		ulp_len;
173711042SErik.Nordmark@Sun.COM 	uint32_t	cksum;
173811042SErik.Nordmark@Sun.COM 	uint8_t		protocol = ira->ira_protocol;
173911042SErik.Nordmark@Sun.COM 	uint16_t	ip_hdr_length = ira->ira_ip_hdr_length;
174011042SErik.Nordmark@Sun.COM 
174111042SErik.Nordmark@Sun.COM #define	iphs    ((uint16_t *)ip6h)
174211042SErik.Nordmark@Sun.COM 
174311042SErik.Nordmark@Sun.COM 	switch (protocol) {
174411042SErik.Nordmark@Sun.COM 	case IPPROTO_TCP:
174511042SErik.Nordmark@Sun.COM 		ulp_len = ira->ira_pktlen - ip_hdr_length;
174611042SErik.Nordmark@Sun.COM 
174711042SErik.Nordmark@Sun.COM 		/* Protocol and length */
174811042SErik.Nordmark@Sun.COM 		cksum = htons(ulp_len) + IP_TCP_CSUM_COMP;
174911042SErik.Nordmark@Sun.COM 		/* IP addresses */
175011042SErik.Nordmark@Sun.COM 		cksum += iphs[4] + iphs[5] + iphs[6] + iphs[7] +
175111042SErik.Nordmark@Sun.COM 		    iphs[8] + iphs[9] + iphs[10] + iphs[11] +
175211042SErik.Nordmark@Sun.COM 		    iphs[12] + iphs[13] + iphs[14] + iphs[15] +
175311042SErik.Nordmark@Sun.COM 		    iphs[16] + iphs[17] + iphs[18] + iphs[19];
175411042SErik.Nordmark@Sun.COM 		break;
175511042SErik.Nordmark@Sun.COM 
175611042SErik.Nordmark@Sun.COM 	case IPPROTO_UDP: {
175711042SErik.Nordmark@Sun.COM 		udpha_t		*udpha;
175811042SErik.Nordmark@Sun.COM 
175911042SErik.Nordmark@Sun.COM 		udpha = (udpha_t  *)((uchar_t *)ip6h + ip_hdr_length);
176011042SErik.Nordmark@Sun.COM 
176111042SErik.Nordmark@Sun.COM 		/* Protocol and length */
176211042SErik.Nordmark@Sun.COM 		cksum = udpha->uha_length + IP_UDP_CSUM_COMP;
176311042SErik.Nordmark@Sun.COM 		/* IP addresses */
176411042SErik.Nordmark@Sun.COM 		cksum += iphs[4] + iphs[5] + iphs[6] + iphs[7] +
176511042SErik.Nordmark@Sun.COM 		    iphs[8] + iphs[9] + iphs[10] + iphs[11] +
176611042SErik.Nordmark@Sun.COM 		    iphs[12] + iphs[13] + iphs[14] + iphs[15] +
176711042SErik.Nordmark@Sun.COM 		    iphs[16] + iphs[17] + iphs[18] + iphs[19];
176811042SErik.Nordmark@Sun.COM 		break;
176911042SErik.Nordmark@Sun.COM 	}
177011042SErik.Nordmark@Sun.COM 	case IPPROTO_ICMPV6:
177111042SErik.Nordmark@Sun.COM 		ulp_len = ira->ira_pktlen - ip_hdr_length;
177211042SErik.Nordmark@Sun.COM 
177311042SErik.Nordmark@Sun.COM 		/* Protocol and length */
177411042SErik.Nordmark@Sun.COM 		cksum = htons(ulp_len) + IP_ICMPV6_CSUM_COMP;
177511042SErik.Nordmark@Sun.COM 		/* IP addresses */
177611042SErik.Nordmark@Sun.COM 		cksum += iphs[4] + iphs[5] + iphs[6] + iphs[7] +
177711042SErik.Nordmark@Sun.COM 		    iphs[8] + iphs[9] + iphs[10] + iphs[11] +
177811042SErik.Nordmark@Sun.COM 		    iphs[12] + iphs[13] + iphs[14] + iphs[15] +
177911042SErik.Nordmark@Sun.COM 		    iphs[16] + iphs[17] + iphs[18] + iphs[19];
178011042SErik.Nordmark@Sun.COM 		break;
178111042SErik.Nordmark@Sun.COM 	default:
178211042SErik.Nordmark@Sun.COM 		cksum = 0;
178311042SErik.Nordmark@Sun.COM 		break;
178411042SErik.Nordmark@Sun.COM 	}
178511042SErik.Nordmark@Sun.COM #undef	iphs
178611042SErik.Nordmark@Sun.COM 	return (cksum);
178711042SErik.Nordmark@Sun.COM }
178811042SErik.Nordmark@Sun.COM 
178911042SErik.Nordmark@Sun.COM 
179011042SErik.Nordmark@Sun.COM /*
179111042SErik.Nordmark@Sun.COM  * Software verification of the ULP checksums.
179211042SErik.Nordmark@Sun.COM  * Returns B_TRUE if ok.
179311042SErik.Nordmark@Sun.COM  * Increments statistics of failed.
179411042SErik.Nordmark@Sun.COM  */
179511042SErik.Nordmark@Sun.COM static boolean_t
ip_input_sw_cksum_v6(mblk_t * mp,ip6_t * ip6h,ip_recv_attr_t * ira)179611042SErik.Nordmark@Sun.COM ip_input_sw_cksum_v6(mblk_t *mp, ip6_t *ip6h, ip_recv_attr_t *ira)
179711042SErik.Nordmark@Sun.COM {
179811042SErik.Nordmark@Sun.COM 	ip_stack_t	*ipst = ira->ira_ill->ill_ipst;
179911042SErik.Nordmark@Sun.COM 	uint32_t	cksum;
180011042SErik.Nordmark@Sun.COM 	uint8_t		protocol = ira->ira_protocol;
180111042SErik.Nordmark@Sun.COM 	uint16_t	ip_hdr_length = ira->ira_ip_hdr_length;
180211042SErik.Nordmark@Sun.COM 
180311042SErik.Nordmark@Sun.COM 	IP6_STAT(ipst, ip6_in_sw_cksum);
180411042SErik.Nordmark@Sun.COM 
180511042SErik.Nordmark@Sun.COM 	ASSERT(protocol == IPPROTO_TCP || protocol == IPPROTO_UDP ||
180611042SErik.Nordmark@Sun.COM 	    protocol == IPPROTO_ICMPV6);
180711042SErik.Nordmark@Sun.COM 
180811042SErik.Nordmark@Sun.COM 	cksum = ip_input_cksum_pseudo_v6(ip6h, ira);
180911042SErik.Nordmark@Sun.COM 	cksum = IP_CSUM(mp, ip_hdr_length, cksum);
181011042SErik.Nordmark@Sun.COM 	if (cksum == 0)
181111042SErik.Nordmark@Sun.COM 		return (B_TRUE);
181211042SErik.Nordmark@Sun.COM 
181311042SErik.Nordmark@Sun.COM 	ip_input_cksum_err_v6(protocol, 0, ira->ira_ill);
181411042SErik.Nordmark@Sun.COM 	return (B_FALSE);
181511042SErik.Nordmark@Sun.COM }
181611042SErik.Nordmark@Sun.COM 
181711042SErik.Nordmark@Sun.COM /*
181811042SErik.Nordmark@Sun.COM  * Verify the ULP checksums.
181911042SErik.Nordmark@Sun.COM  * Returns B_TRUE if ok, or if the ULP doesn't have a well-defined checksum
182011042SErik.Nordmark@Sun.COM  * algorithm.
182111042SErik.Nordmark@Sun.COM  * Increments statistics if failed.
182211042SErik.Nordmark@Sun.COM  */
182311042SErik.Nordmark@Sun.COM static boolean_t
ip_input_cksum_v6(iaflags_t iraflags,mblk_t * mp,ip6_t * ip6h,ip_recv_attr_t * ira)182411042SErik.Nordmark@Sun.COM ip_input_cksum_v6(iaflags_t iraflags, mblk_t *mp, ip6_t *ip6h,
182511042SErik.Nordmark@Sun.COM     ip_recv_attr_t *ira)
182611042SErik.Nordmark@Sun.COM {
182711042SErik.Nordmark@Sun.COM 	ill_t		*ill = ira->ira_rill;
182811042SErik.Nordmark@Sun.COM 	uint16_t	hck_flags;
182911042SErik.Nordmark@Sun.COM 	uint32_t	cksum;
183011042SErik.Nordmark@Sun.COM 	mblk_t		*mp1;
183111042SErik.Nordmark@Sun.COM 	uint_t		len;
183211042SErik.Nordmark@Sun.COM 	uint8_t		protocol = ira->ira_protocol;
183311042SErik.Nordmark@Sun.COM 	uint16_t	ip_hdr_length = ira->ira_ip_hdr_length;
183411042SErik.Nordmark@Sun.COM 
183511042SErik.Nordmark@Sun.COM 
183611042SErik.Nordmark@Sun.COM 	switch (protocol) {
183711042SErik.Nordmark@Sun.COM 	case IPPROTO_TCP:
183811042SErik.Nordmark@Sun.COM 	case IPPROTO_ICMPV6:
183911042SErik.Nordmark@Sun.COM 		break;
184011042SErik.Nordmark@Sun.COM 
184111042SErik.Nordmark@Sun.COM 	case IPPROTO_UDP: {
184211042SErik.Nordmark@Sun.COM 		udpha_t		*udpha;
184311042SErik.Nordmark@Sun.COM 
184411042SErik.Nordmark@Sun.COM 		udpha = (udpha_t  *)((uchar_t *)ip6h + ip_hdr_length);
184511042SErik.Nordmark@Sun.COM 		/*
184611042SErik.Nordmark@Sun.COM 		 *  Before going through the regular checksum
184711042SErik.Nordmark@Sun.COM 		 *  calculation, make sure the received checksum
184811042SErik.Nordmark@Sun.COM 		 *  is non-zero. RFC 2460 says, a 0x0000 checksum
184911042SErik.Nordmark@Sun.COM 		 *  in a UDP packet (within IPv6 packet) is invalid
185011042SErik.Nordmark@Sun.COM 		 *  and should be replaced by 0xffff. This makes
185111042SErik.Nordmark@Sun.COM 		 *  sense as regular checksum calculation will
185211042SErik.Nordmark@Sun.COM 		 *  pass for both the cases i.e. 0x0000 and 0xffff.
185311042SErik.Nordmark@Sun.COM 		 *  Removing one of the case makes error detection
185411042SErik.Nordmark@Sun.COM 		 *  stronger.
185511042SErik.Nordmark@Sun.COM 		 */
185611042SErik.Nordmark@Sun.COM 		if (udpha->uha_checksum == 0) {
185711042SErik.Nordmark@Sun.COM 			/* 0x0000 checksum is invalid */
185811042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, udpIfStatsInCksumErrs);
185911042SErik.Nordmark@Sun.COM 			return (B_FALSE);
186011042SErik.Nordmark@Sun.COM 		}
186111042SErik.Nordmark@Sun.COM 		break;
186211042SErik.Nordmark@Sun.COM 	}
186311042SErik.Nordmark@Sun.COM 	case IPPROTO_SCTP: {
186411042SErik.Nordmark@Sun.COM 		sctp_hdr_t	*sctph;
186511042SErik.Nordmark@Sun.COM 		uint32_t	pktsum;
186611042SErik.Nordmark@Sun.COM 
186711042SErik.Nordmark@Sun.COM 		sctph = (sctp_hdr_t *)((uchar_t *)ip6h + ip_hdr_length);
186811042SErik.Nordmark@Sun.COM #ifdef	DEBUG
186911042SErik.Nordmark@Sun.COM 		if (skip_sctp_cksum)
187011042SErik.Nordmark@Sun.COM 			return (B_TRUE);
187111042SErik.Nordmark@Sun.COM #endif
187211042SErik.Nordmark@Sun.COM 		pktsum = sctph->sh_chksum;
187311042SErik.Nordmark@Sun.COM 		sctph->sh_chksum = 0;
187411042SErik.Nordmark@Sun.COM 		cksum = sctp_cksum(mp, ip_hdr_length);
187511042SErik.Nordmark@Sun.COM 		sctph->sh_chksum = pktsum;
187611042SErik.Nordmark@Sun.COM 		if (cksum == pktsum)
187711042SErik.Nordmark@Sun.COM 			return (B_TRUE);
187811042SErik.Nordmark@Sun.COM 
187911042SErik.Nordmark@Sun.COM 		/*
188011042SErik.Nordmark@Sun.COM 		 * Defer until later whether a bad checksum is ok
188111042SErik.Nordmark@Sun.COM 		 * in order to allow RAW sockets to use Adler checksum
188211042SErik.Nordmark@Sun.COM 		 * with SCTP.
188311042SErik.Nordmark@Sun.COM 		 */
188411042SErik.Nordmark@Sun.COM 		ira->ira_flags |= IRAF_SCTP_CSUM_ERR;
188511042SErik.Nordmark@Sun.COM 		return (B_TRUE);
188611042SErik.Nordmark@Sun.COM 	}
188711042SErik.Nordmark@Sun.COM 
188811042SErik.Nordmark@Sun.COM 	default:
188911042SErik.Nordmark@Sun.COM 		/* No ULP checksum to verify. */
189011042SErik.Nordmark@Sun.COM 		return (B_TRUE);
189111042SErik.Nordmark@Sun.COM 	}
189211042SErik.Nordmark@Sun.COM 
189311042SErik.Nordmark@Sun.COM 	/*
189411042SErik.Nordmark@Sun.COM 	 * Revert to software checksum calculation if the interface
189511042SErik.Nordmark@Sun.COM 	 * isn't capable of checksum offload.
189611042SErik.Nordmark@Sun.COM 	 * We clear DB_CKSUMFLAGS when going through IPsec in ip_fanout.
189711042SErik.Nordmark@Sun.COM 	 * Note: IRAF_NO_HW_CKSUM is not currently used.
189811042SErik.Nordmark@Sun.COM 	 */
189911042SErik.Nordmark@Sun.COM 	ASSERT(!IS_IPMP(ill));
190011042SErik.Nordmark@Sun.COM 	if ((iraflags & IRAF_NO_HW_CKSUM) || !ILL_HCKSUM_CAPABLE(ill) ||
190111042SErik.Nordmark@Sun.COM 	    !dohwcksum) {
190211042SErik.Nordmark@Sun.COM 		return (ip_input_sw_cksum_v6(mp, ip6h, ira));
190311042SErik.Nordmark@Sun.COM 	}
190411042SErik.Nordmark@Sun.COM 
190511042SErik.Nordmark@Sun.COM 	/*
190611042SErik.Nordmark@Sun.COM 	 * We apply this for all ULP protocols. Does the HW know to
190711042SErik.Nordmark@Sun.COM 	 * not set the flags for SCTP and other protocols.
190811042SErik.Nordmark@Sun.COM 	 */
190911042SErik.Nordmark@Sun.COM 
191011042SErik.Nordmark@Sun.COM 	hck_flags = DB_CKSUMFLAGS(mp);
191111042SErik.Nordmark@Sun.COM 
191211878SVenu.Iyer@Sun.COM 	if (hck_flags & HCK_FULLCKSUM_OK) {
191311878SVenu.Iyer@Sun.COM 		/*
191411878SVenu.Iyer@Sun.COM 		 * Hardware has already verified the checksum.
191511878SVenu.Iyer@Sun.COM 		 */
191611878SVenu.Iyer@Sun.COM 		return (B_TRUE);
191711878SVenu.Iyer@Sun.COM 	}
191811878SVenu.Iyer@Sun.COM 
191911042SErik.Nordmark@Sun.COM 	if (hck_flags & HCK_FULLCKSUM) {
192011042SErik.Nordmark@Sun.COM 		/*
192111042SErik.Nordmark@Sun.COM 		 * Full checksum has been computed by the hardware
192211042SErik.Nordmark@Sun.COM 		 * and has been attached.  If the driver wants us to
192311042SErik.Nordmark@Sun.COM 		 * verify the correctness of the attached value, in
192411042SErik.Nordmark@Sun.COM 		 * order to protect against faulty hardware, compare
192511042SErik.Nordmark@Sun.COM 		 * it against -0 (0xFFFF) to see if it's valid.
192611042SErik.Nordmark@Sun.COM 		 */
192711042SErik.Nordmark@Sun.COM 		cksum = DB_CKSUM16(mp);
192811042SErik.Nordmark@Sun.COM 		if (cksum == 0xFFFF)
192911042SErik.Nordmark@Sun.COM 			return (B_TRUE);
193011042SErik.Nordmark@Sun.COM 		ip_input_cksum_err_v6(protocol, hck_flags, ira->ira_ill);
193111042SErik.Nordmark@Sun.COM 		return (B_FALSE);
193211042SErik.Nordmark@Sun.COM 	}
193311042SErik.Nordmark@Sun.COM 
193411042SErik.Nordmark@Sun.COM 	mp1 = mp->b_cont;
193511042SErik.Nordmark@Sun.COM 	if ((hck_flags & HCK_PARTIALCKSUM) &&
193611042SErik.Nordmark@Sun.COM 	    (mp1 == NULL || mp1->b_cont == NULL) &&
193711042SErik.Nordmark@Sun.COM 	    ip_hdr_length >= DB_CKSUMSTART(mp) &&
193811042SErik.Nordmark@Sun.COM 	    ((len = ip_hdr_length - DB_CKSUMSTART(mp)) & 1) == 0) {
193911042SErik.Nordmark@Sun.COM 		uint32_t	adj;
194011042SErik.Nordmark@Sun.COM 		uchar_t		*cksum_start;
194111042SErik.Nordmark@Sun.COM 
194211042SErik.Nordmark@Sun.COM 		cksum = ip_input_cksum_pseudo_v6(ip6h, ira);
194311042SErik.Nordmark@Sun.COM 
194411042SErik.Nordmark@Sun.COM 		cksum_start = ((uchar_t *)ip6h + DB_CKSUMSTART(mp));
194511042SErik.Nordmark@Sun.COM 
194611042SErik.Nordmark@Sun.COM 		/*
194711042SErik.Nordmark@Sun.COM 		 * Partial checksum has been calculated by hardware
194811042SErik.Nordmark@Sun.COM 		 * and attached to the packet; in addition, any
194911042SErik.Nordmark@Sun.COM 		 * prepended extraneous data is even byte aligned,
195011042SErik.Nordmark@Sun.COM 		 * and there are at most two mblks associated with
195111042SErik.Nordmark@Sun.COM 		 * the packet.  If any such data exists, we adjust
195211042SErik.Nordmark@Sun.COM 		 * the checksum; also take care any postpended data.
195311042SErik.Nordmark@Sun.COM 		 */
195411042SErik.Nordmark@Sun.COM 		IP_ADJCKSUM_PARTIAL(cksum_start, mp, mp1, len, adj);
195511042SErik.Nordmark@Sun.COM 		/*
195611042SErik.Nordmark@Sun.COM 		 * One's complement subtract extraneous checksum
195711042SErik.Nordmark@Sun.COM 		 */
195811042SErik.Nordmark@Sun.COM 		cksum += DB_CKSUM16(mp);
195911042SErik.Nordmark@Sun.COM 		if (adj >= cksum)
196011042SErik.Nordmark@Sun.COM 			cksum = ~(adj - cksum) & 0xFFFF;
196111042SErik.Nordmark@Sun.COM 		else
196211042SErik.Nordmark@Sun.COM 			cksum -= adj;
196311042SErik.Nordmark@Sun.COM 		cksum = (cksum & 0xFFFF) + ((int)cksum >> 16);
196411042SErik.Nordmark@Sun.COM 		cksum = (cksum & 0xFFFF) + ((int)cksum >> 16);
196511042SErik.Nordmark@Sun.COM 		if (!(~cksum & 0xFFFF))
196611042SErik.Nordmark@Sun.COM 			return (B_TRUE);
196711042SErik.Nordmark@Sun.COM 
196811042SErik.Nordmark@Sun.COM 		ip_input_cksum_err_v6(protocol, hck_flags, ira->ira_ill);
196911042SErik.Nordmark@Sun.COM 		return (B_FALSE);
197011042SErik.Nordmark@Sun.COM 	}
197111042SErik.Nordmark@Sun.COM 	return (ip_input_sw_cksum_v6(mp, ip6h, ira));
197211042SErik.Nordmark@Sun.COM }
197311042SErik.Nordmark@Sun.COM 
197411042SErik.Nordmark@Sun.COM 
197511042SErik.Nordmark@Sun.COM /*
197611042SErik.Nordmark@Sun.COM  * Handle fanout of received packets.
197711042SErik.Nordmark@Sun.COM  * Unicast packets that are looped back (from ire_send_local_v6) and packets
197811042SErik.Nordmark@Sun.COM  * from the wire are differentiated by checking IRAF_VERIFY_ULP_CKSUM.
197911042SErik.Nordmark@Sun.COM  *
198011042SErik.Nordmark@Sun.COM  * IPQoS Notes
198111042SErik.Nordmark@Sun.COM  * Before sending it to the client, invoke IPPF processing. Policy processing
198211042SErik.Nordmark@Sun.COM  * takes place only if the callout_position, IPP_LOCAL_IN, is enabled.
198311042SErik.Nordmark@Sun.COM  */
198411042SErik.Nordmark@Sun.COM void
ip_fanout_v6(mblk_t * mp,ip6_t * ip6h,ip_recv_attr_t * ira)198511042SErik.Nordmark@Sun.COM ip_fanout_v6(mblk_t *mp, ip6_t *ip6h, ip_recv_attr_t *ira)
198611042SErik.Nordmark@Sun.COM {
198711042SErik.Nordmark@Sun.COM 	ill_t		*ill = ira->ira_ill;
198811042SErik.Nordmark@Sun.COM 	iaflags_t	iraflags = ira->ira_flags;
198911042SErik.Nordmark@Sun.COM 	ip_stack_t	*ipst = ill->ill_ipst;
199011042SErik.Nordmark@Sun.COM 	uint8_t		protocol;
199111042SErik.Nordmark@Sun.COM 	conn_t		*connp;
199211042SErik.Nordmark@Sun.COM #define	rptr	((uchar_t *)ip6h)
199311042SErik.Nordmark@Sun.COM 	uint_t		ip_hdr_length;
199411042SErik.Nordmark@Sun.COM 	uint_t		min_ulp_header_length;
199511042SErik.Nordmark@Sun.COM 	int		offset;
199611042SErik.Nordmark@Sun.COM 	ssize_t		len;
199711042SErik.Nordmark@Sun.COM 	netstack_t	*ns = ipst->ips_netstack;
199811042SErik.Nordmark@Sun.COM 	ipsec_stack_t	*ipss = ns->netstack_ipsec;
199911042SErik.Nordmark@Sun.COM 	ill_t		*rill = ira->ira_rill;
200011042SErik.Nordmark@Sun.COM 
200111042SErik.Nordmark@Sun.COM 	ASSERT(ira->ira_pktlen == ntohs(ip6h->ip6_plen) + IPV6_HDR_LEN);
200211042SErik.Nordmark@Sun.COM 
200311042SErik.Nordmark@Sun.COM 	/*
200411042SErik.Nordmark@Sun.COM 	 * We repeat this as we parse over destination options header and
200511042SErik.Nordmark@Sun.COM 	 * fragment headers (earlier we've handled any hop-by-hop options
200611042SErik.Nordmark@Sun.COM 	 * header.)
200711042SErik.Nordmark@Sun.COM 	 * We update ira_protocol and ira_ip_hdr_length as we skip past
200811042SErik.Nordmark@Sun.COM 	 * the intermediate headers; they already point past any
200911042SErik.Nordmark@Sun.COM 	 * hop-by-hop header.
201011042SErik.Nordmark@Sun.COM 	 */
201111042SErik.Nordmark@Sun.COM repeat:
201211042SErik.Nordmark@Sun.COM 	protocol = ira->ira_protocol;
201311042SErik.Nordmark@Sun.COM 	ip_hdr_length = ira->ira_ip_hdr_length;
201411042SErik.Nordmark@Sun.COM 
201511042SErik.Nordmark@Sun.COM 	/*
201611042SErik.Nordmark@Sun.COM 	 * Time for IPP once we've done reassembly and IPsec.
201711042SErik.Nordmark@Sun.COM 	 * We skip this for loopback packets since we don't do IPQoS
201811042SErik.Nordmark@Sun.COM 	 * on loopback.
201911042SErik.Nordmark@Sun.COM 	 */
202011042SErik.Nordmark@Sun.COM 	if (IPP_ENABLED(IPP_LOCAL_IN, ipst) &&
202111042SErik.Nordmark@Sun.COM 	    !(iraflags & IRAF_LOOPBACK) &&
202211042SErik.Nordmark@Sun.COM 	    (protocol != IPPROTO_ESP || protocol != IPPROTO_AH ||
202311042SErik.Nordmark@Sun.COM 	    protocol != IPPROTO_DSTOPTS || protocol != IPPROTO_ROUTING ||
202411042SErik.Nordmark@Sun.COM 	    protocol != IPPROTO_FRAGMENT)) {
202511042SErik.Nordmark@Sun.COM 		/*
202611042SErik.Nordmark@Sun.COM 		 * Use the interface on which the packet arrived - not where
202711042SErik.Nordmark@Sun.COM 		 * the IP address is hosted.
202811042SErik.Nordmark@Sun.COM 		 */
202911042SErik.Nordmark@Sun.COM 		/* ip_process translates an IS_UNDER_IPMP */
203011042SErik.Nordmark@Sun.COM 		mp = ip_process(IPP_LOCAL_IN, mp, rill, ill);
203111042SErik.Nordmark@Sun.COM 		if (mp == NULL) {
203211042SErik.Nordmark@Sun.COM 			/* ip_drop_packet and MIB done */
203311042SErik.Nordmark@Sun.COM 			return;
203411042SErik.Nordmark@Sun.COM 		}
203511042SErik.Nordmark@Sun.COM 	}
203611042SErik.Nordmark@Sun.COM 
203711042SErik.Nordmark@Sun.COM 	/* Determine the minimum required size of the upper-layer header */
203811042SErik.Nordmark@Sun.COM 	/* Need to do this for at least the set of ULPs that TX handles. */
203911042SErik.Nordmark@Sun.COM 	switch (protocol) {
204011042SErik.Nordmark@Sun.COM 	case IPPROTO_TCP:
204111042SErik.Nordmark@Sun.COM 		min_ulp_header_length = TCP_MIN_HEADER_LENGTH;
204211042SErik.Nordmark@Sun.COM 		break;
204311042SErik.Nordmark@Sun.COM 	case IPPROTO_SCTP:
204411042SErik.Nordmark@Sun.COM 		min_ulp_header_length = SCTP_COMMON_HDR_LENGTH;
204511042SErik.Nordmark@Sun.COM 		break;
204611042SErik.Nordmark@Sun.COM 	case IPPROTO_UDP:
204711042SErik.Nordmark@Sun.COM 		min_ulp_header_length = UDPH_SIZE;
204811042SErik.Nordmark@Sun.COM 		break;
204911042SErik.Nordmark@Sun.COM 	case IPPROTO_ICMP:
205011042SErik.Nordmark@Sun.COM 	case IPPROTO_ICMPV6:
205111042SErik.Nordmark@Sun.COM 		min_ulp_header_length = ICMPH_SIZE;
205211042SErik.Nordmark@Sun.COM 		break;
205311042SErik.Nordmark@Sun.COM 	case IPPROTO_FRAGMENT:
205411042SErik.Nordmark@Sun.COM 	case IPPROTO_DSTOPTS:
205511042SErik.Nordmark@Sun.COM 	case IPPROTO_ROUTING:
205611042SErik.Nordmark@Sun.COM 		min_ulp_header_length = MIN_EHDR_LEN;
205711042SErik.Nordmark@Sun.COM 		break;
205811042SErik.Nordmark@Sun.COM 	default:
205911042SErik.Nordmark@Sun.COM 		min_ulp_header_length = 0;
206011042SErik.Nordmark@Sun.COM 		break;
206111042SErik.Nordmark@Sun.COM 	}
206211042SErik.Nordmark@Sun.COM 	/* Make sure we have the min ULP header length */
206311042SErik.Nordmark@Sun.COM 	len = mp->b_wptr - rptr;
206411042SErik.Nordmark@Sun.COM 	if (len < ip_hdr_length + min_ulp_header_length) {
206511042SErik.Nordmark@Sun.COM 		if (ira->ira_pktlen < ip_hdr_length + min_ulp_header_length)
206611042SErik.Nordmark@Sun.COM 			goto pkt_too_short;
206711042SErik.Nordmark@Sun.COM 
206811042SErik.Nordmark@Sun.COM 		IP6_STAT(ipst, ip6_recv_pullup);
206911042SErik.Nordmark@Sun.COM 		ip6h = ip_pullup(mp, ip_hdr_length + min_ulp_header_length,
207011042SErik.Nordmark@Sun.COM 		    ira);
207111042SErik.Nordmark@Sun.COM 		if (ip6h == NULL)
207211042SErik.Nordmark@Sun.COM 			goto discard;
207311042SErik.Nordmark@Sun.COM 		len = mp->b_wptr - rptr;
207411042SErik.Nordmark@Sun.COM 	}
207511042SErik.Nordmark@Sun.COM 
207611042SErik.Nordmark@Sun.COM 	/*
207711042SErik.Nordmark@Sun.COM 	 * If trusted extensions then determine the zoneid and TX specific
207811042SErik.Nordmark@Sun.COM 	 * ira_flags.
207911042SErik.Nordmark@Sun.COM 	 */
208011042SErik.Nordmark@Sun.COM 	if (iraflags & IRAF_SYSTEM_LABELED) {
208111042SErik.Nordmark@Sun.COM 		/* This can update ira->ira_flags and ira->ira_zoneid */
208211042SErik.Nordmark@Sun.COM 		ip_fanout_tx_v6(mp, ip6h, protocol, ip_hdr_length, ira);
208311042SErik.Nordmark@Sun.COM 		iraflags = ira->ira_flags;
208411042SErik.Nordmark@Sun.COM 	}
208511042SErik.Nordmark@Sun.COM 
208611042SErik.Nordmark@Sun.COM 
208711042SErik.Nordmark@Sun.COM 	/* Verify ULP checksum. Handles TCP, UDP, and SCTP */
208811042SErik.Nordmark@Sun.COM 	if (iraflags & IRAF_VERIFY_ULP_CKSUM) {
208911042SErik.Nordmark@Sun.COM 		if (!ip_input_cksum_v6(iraflags, mp, ip6h, ira)) {
209011042SErik.Nordmark@Sun.COM 			/* Bad checksum. Stats are already incremented */
209111042SErik.Nordmark@Sun.COM 			ip_drop_input("Bad ULP checksum", mp, ill);
209211042SErik.Nordmark@Sun.COM 			freemsg(mp);
209311042SErik.Nordmark@Sun.COM 			return;
209411042SErik.Nordmark@Sun.COM 		}
209511042SErik.Nordmark@Sun.COM 		/* IRAF_SCTP_CSUM_ERR could have been set */
209611042SErik.Nordmark@Sun.COM 		iraflags = ira->ira_flags;
209711042SErik.Nordmark@Sun.COM 	}
209811042SErik.Nordmark@Sun.COM 	switch (protocol) {
209911042SErik.Nordmark@Sun.COM 	case IPPROTO_TCP:
210011042SErik.Nordmark@Sun.COM 		/* For TCP, discard multicast packets. */
210111042SErik.Nordmark@Sun.COM 		if (iraflags & IRAF_MULTIBROADCAST)
210211042SErik.Nordmark@Sun.COM 			goto discard;
210311042SErik.Nordmark@Sun.COM 
210411042SErik.Nordmark@Sun.COM 		/* First mblk contains IP+TCP headers per above check */
210511042SErik.Nordmark@Sun.COM 		ASSERT(len >= ip_hdr_length + TCP_MIN_HEADER_LENGTH);
210611042SErik.Nordmark@Sun.COM 
210711042SErik.Nordmark@Sun.COM 		/* TCP options present? */
210811042SErik.Nordmark@Sun.COM 		offset = ((uchar_t *)ip6h)[ip_hdr_length + 12] >> 4;
210911042SErik.Nordmark@Sun.COM 		if (offset != 5) {
211011042SErik.Nordmark@Sun.COM 			if (offset < 5)
211111042SErik.Nordmark@Sun.COM 				goto discard;
211211042SErik.Nordmark@Sun.COM 
211311042SErik.Nordmark@Sun.COM 			/*
211411042SErik.Nordmark@Sun.COM 			 * There must be TCP options.
211511042SErik.Nordmark@Sun.COM 			 * Make sure we can grab them.
211611042SErik.Nordmark@Sun.COM 			 */
211711042SErik.Nordmark@Sun.COM 			offset <<= 2;
211811042SErik.Nordmark@Sun.COM 			offset += ip_hdr_length;
211911042SErik.Nordmark@Sun.COM 			if (len < offset) {
212011042SErik.Nordmark@Sun.COM 				if (ira->ira_pktlen < offset)
212111042SErik.Nordmark@Sun.COM 					goto pkt_too_short;
212211042SErik.Nordmark@Sun.COM 
212311042SErik.Nordmark@Sun.COM 				IP6_STAT(ipst, ip6_recv_pullup);
212411042SErik.Nordmark@Sun.COM 				ip6h = ip_pullup(mp, offset, ira);
212511042SErik.Nordmark@Sun.COM 				if (ip6h == NULL)
212611042SErik.Nordmark@Sun.COM 					goto discard;
212711042SErik.Nordmark@Sun.COM 				len = mp->b_wptr - rptr;
212811042SErik.Nordmark@Sun.COM 			}
212911042SErik.Nordmark@Sun.COM 		}
213011042SErik.Nordmark@Sun.COM 
213111042SErik.Nordmark@Sun.COM 		/*
213211042SErik.Nordmark@Sun.COM 		 * Pass up a squeue hint to tcp.
213311042SErik.Nordmark@Sun.COM 		 * If ira_sqp is already set (this is loopback) we leave it
213411042SErik.Nordmark@Sun.COM 		 * alone.
213511042SErik.Nordmark@Sun.COM 		 */
213611042SErik.Nordmark@Sun.COM 		if (ira->ira_sqp == NULL) {
213711042SErik.Nordmark@Sun.COM 			ira->ira_sqp = ip_squeue_get(ira->ira_ring);
213811042SErik.Nordmark@Sun.COM 		}
213911042SErik.Nordmark@Sun.COM 
214011042SErik.Nordmark@Sun.COM 		/* Look for AF_INET or AF_INET6 that matches */
214111042SErik.Nordmark@Sun.COM 		connp = ipcl_classify_v6(mp, IPPROTO_TCP, ip_hdr_length,
214211042SErik.Nordmark@Sun.COM 		    ira, ipst);
214311042SErik.Nordmark@Sun.COM 		if (connp == NULL) {
214411042SErik.Nordmark@Sun.COM 			/* Send the TH_RST */
214511042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
214611042SErik.Nordmark@Sun.COM 			tcp_xmit_listeners_reset(mp, ira, ipst, NULL);
214711042SErik.Nordmark@Sun.COM 			return;
214811042SErik.Nordmark@Sun.COM 		}
214911042SErik.Nordmark@Sun.COM 		if (connp->conn_incoming_ifindex != 0 &&
215011042SErik.Nordmark@Sun.COM 		    connp->conn_incoming_ifindex != ira->ira_ruifindex) {
215111042SErik.Nordmark@Sun.COM 			CONN_DEC_REF(connp);
215211042SErik.Nordmark@Sun.COM 
215311042SErik.Nordmark@Sun.COM 			/* Send the TH_RST */
215411042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
215511042SErik.Nordmark@Sun.COM 			tcp_xmit_listeners_reset(mp, ira, ipst, NULL);
215611042SErik.Nordmark@Sun.COM 			return;
215711042SErik.Nordmark@Sun.COM 		}
215811042SErik.Nordmark@Sun.COM 		if (CONN_INBOUND_POLICY_PRESENT_V6(connp, ipss) ||
215911042SErik.Nordmark@Sun.COM 		    (iraflags & IRAF_IPSEC_SECURE)) {
216011042SErik.Nordmark@Sun.COM 			mp = ipsec_check_inbound_policy(mp, connp,
216111042SErik.Nordmark@Sun.COM 			    NULL, ip6h, ira);
216211042SErik.Nordmark@Sun.COM 			if (mp == NULL) {
216311042SErik.Nordmark@Sun.COM 				BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
216411042SErik.Nordmark@Sun.COM 				/* Note that mp is NULL */
216511042SErik.Nordmark@Sun.COM 				ip_drop_input("ipIfStatsInDiscards", mp, ill);
216611042SErik.Nordmark@Sun.COM 				CONN_DEC_REF(connp);
216711042SErik.Nordmark@Sun.COM 				return;
216811042SErik.Nordmark@Sun.COM 			}
216911042SErik.Nordmark@Sun.COM 		}
217011042SErik.Nordmark@Sun.COM 		/* Found a client; up it goes */
217111042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
217211042SErik.Nordmark@Sun.COM 		ira->ira_ill = ira->ira_rill = NULL;
217311042SErik.Nordmark@Sun.COM 		if (!IPCL_IS_TCP(connp)) {
217411042SErik.Nordmark@Sun.COM 			/* Not TCP; must be SOCK_RAW, IPPROTO_TCP */
217511042SErik.Nordmark@Sun.COM 			(connp->conn_recv)(connp, mp, NULL, ira);
217611042SErik.Nordmark@Sun.COM 			CONN_DEC_REF(connp);
217711042SErik.Nordmark@Sun.COM 			ira->ira_ill = ill;
217811042SErik.Nordmark@Sun.COM 			ira->ira_rill = rill;
217911042SErik.Nordmark@Sun.COM 			return;
218011042SErik.Nordmark@Sun.COM 		}
218111042SErik.Nordmark@Sun.COM 
218211042SErik.Nordmark@Sun.COM 		/*
218311042SErik.Nordmark@Sun.COM 		 * We do different processing whether called from
218411042SErik.Nordmark@Sun.COM 		 * ip_accept_tcp and we match the target, don't match
218511042SErik.Nordmark@Sun.COM 		 * the target, and when we are called by ip_input.
218611042SErik.Nordmark@Sun.COM 		 */
218711042SErik.Nordmark@Sun.COM 		if (iraflags & IRAF_TARGET_SQP) {
218811042SErik.Nordmark@Sun.COM 			if (ira->ira_target_sqp == connp->conn_sqp) {
218911042SErik.Nordmark@Sun.COM 				mblk_t	*attrmp;
219011042SErik.Nordmark@Sun.COM 
219111042SErik.Nordmark@Sun.COM 				attrmp = ip_recv_attr_to_mblk(ira);
219211042SErik.Nordmark@Sun.COM 				if (attrmp == NULL) {
219311042SErik.Nordmark@Sun.COM 					BUMP_MIB(ill->ill_ip_mib,
219411042SErik.Nordmark@Sun.COM 					    ipIfStatsInDiscards);
219511042SErik.Nordmark@Sun.COM 					ip_drop_input("ipIfStatsInDiscards",
219611042SErik.Nordmark@Sun.COM 					    mp, ill);
219711042SErik.Nordmark@Sun.COM 					freemsg(mp);
219811042SErik.Nordmark@Sun.COM 					CONN_DEC_REF(connp);
219911042SErik.Nordmark@Sun.COM 				} else {
220011042SErik.Nordmark@Sun.COM 					SET_SQUEUE(attrmp, connp->conn_recv,
220111042SErik.Nordmark@Sun.COM 					    connp);
220211042SErik.Nordmark@Sun.COM 					attrmp->b_cont = mp;
220311042SErik.Nordmark@Sun.COM 					ASSERT(ira->ira_target_sqp_mp == NULL);
220411042SErik.Nordmark@Sun.COM 					ira->ira_target_sqp_mp = attrmp;
220511042SErik.Nordmark@Sun.COM 					/*
220611042SErik.Nordmark@Sun.COM 					 * Conn ref release when drained from
220711042SErik.Nordmark@Sun.COM 					 * the squeue.
220811042SErik.Nordmark@Sun.COM 					 */
220911042SErik.Nordmark@Sun.COM 				}
221011042SErik.Nordmark@Sun.COM 			} else {
221111042SErik.Nordmark@Sun.COM 				SQUEUE_ENTER_ONE(connp->conn_sqp, mp,
221211042SErik.Nordmark@Sun.COM 				    connp->conn_recv, connp, ira, SQ_FILL,
221311042SErik.Nordmark@Sun.COM 				    SQTAG_IP6_TCP_INPUT);
221411042SErik.Nordmark@Sun.COM 			}
221511042SErik.Nordmark@Sun.COM 		} else {
221611042SErik.Nordmark@Sun.COM 			SQUEUE_ENTER_ONE(connp->conn_sqp, mp, connp->conn_recv,
221711042SErik.Nordmark@Sun.COM 			    connp, ira, ip_squeue_flag, SQTAG_IP6_TCP_INPUT);
221811042SErik.Nordmark@Sun.COM 		}
221911042SErik.Nordmark@Sun.COM 		ira->ira_ill = ill;
222011042SErik.Nordmark@Sun.COM 		ira->ira_rill = rill;
222111042SErik.Nordmark@Sun.COM 		return;
222211042SErik.Nordmark@Sun.COM 
222311042SErik.Nordmark@Sun.COM 	case IPPROTO_SCTP: {
222411042SErik.Nordmark@Sun.COM 		sctp_hdr_t	*sctph;
222511042SErik.Nordmark@Sun.COM 		uint32_t	ports;	/* Source and destination ports */
222611042SErik.Nordmark@Sun.COM 		sctp_stack_t	*sctps = ipst->ips_netstack->netstack_sctp;
222711042SErik.Nordmark@Sun.COM 
222811042SErik.Nordmark@Sun.COM 		/* For SCTP, discard multicast packets. */
222911042SErik.Nordmark@Sun.COM 		if (iraflags & IRAF_MULTIBROADCAST)
223011042SErik.Nordmark@Sun.COM 			goto discard;
223111042SErik.Nordmark@Sun.COM 
223211042SErik.Nordmark@Sun.COM 		/*
223311042SErik.Nordmark@Sun.COM 		 * Since there is no SCTP h/w cksum support yet, just
223411042SErik.Nordmark@Sun.COM 		 * clear the flag.
223511042SErik.Nordmark@Sun.COM 		 */
223611042SErik.Nordmark@Sun.COM 		DB_CKSUMFLAGS(mp) = 0;
223711042SErik.Nordmark@Sun.COM 
223811042SErik.Nordmark@Sun.COM 		/* Length ensured above */
223911042SErik.Nordmark@Sun.COM 		ASSERT(MBLKL(mp) >= ip_hdr_length + SCTP_COMMON_HDR_LENGTH);
224011042SErik.Nordmark@Sun.COM 		sctph = (sctp_hdr_t *)(rptr + ip_hdr_length);
224111042SErik.Nordmark@Sun.COM 
224211042SErik.Nordmark@Sun.COM 		/* get the ports */
224311042SErik.Nordmark@Sun.COM 		ports = *(uint32_t *)&sctph->sh_sport;
224411042SErik.Nordmark@Sun.COM 
224511042SErik.Nordmark@Sun.COM 		if (iraflags & IRAF_SCTP_CSUM_ERR) {
224611042SErik.Nordmark@Sun.COM 			/*
224711042SErik.Nordmark@Sun.COM 			 * No potential sctp checksum errors go to the Sun
224811042SErik.Nordmark@Sun.COM 			 * sctp stack however they might be Adler-32 summed
224911042SErik.Nordmark@Sun.COM 			 * packets a userland stack bound to a raw IP socket
225011042SErik.Nordmark@Sun.COM 			 * could reasonably use. Note though that Adler-32 is
225111042SErik.Nordmark@Sun.COM 			 * a long deprecated algorithm and customer sctp
225211042SErik.Nordmark@Sun.COM 			 * networks should eventually migrate to CRC-32 at
225311042SErik.Nordmark@Sun.COM 			 * which time this facility should be removed.
225411042SErik.Nordmark@Sun.COM 			 */
225511042SErik.Nordmark@Sun.COM 			ip_fanout_sctp_raw(mp, NULL, ip6h, ports, ira);
225611042SErik.Nordmark@Sun.COM 			return;
225711042SErik.Nordmark@Sun.COM 		}
225811042SErik.Nordmark@Sun.COM 		connp = sctp_fanout(&ip6h->ip6_src, &ip6h->ip6_dst, ports,
2259*12339Sanil.udupa@sun.com 		    ira, mp, sctps, sctph);
226011042SErik.Nordmark@Sun.COM 		if (connp == NULL) {
226111042SErik.Nordmark@Sun.COM 			/* Check for raw socket or OOTB handling */
226211042SErik.Nordmark@Sun.COM 			ip_fanout_sctp_raw(mp, NULL, ip6h, ports, ira);
226311042SErik.Nordmark@Sun.COM 			return;
226411042SErik.Nordmark@Sun.COM 		}
226511042SErik.Nordmark@Sun.COM 		if (connp->conn_incoming_ifindex != 0 &&
226611042SErik.Nordmark@Sun.COM 		    connp->conn_incoming_ifindex != ira->ira_ruifindex) {
226711042SErik.Nordmark@Sun.COM 			CONN_DEC_REF(connp);
226811042SErik.Nordmark@Sun.COM 
226911042SErik.Nordmark@Sun.COM 			/* Check for raw socket or OOTB handling */
227011042SErik.Nordmark@Sun.COM 			ip_fanout_sctp_raw(mp, NULL, ip6h, ports, ira);
227111042SErik.Nordmark@Sun.COM 			return;
227211042SErik.Nordmark@Sun.COM 		}
227311042SErik.Nordmark@Sun.COM 
227411042SErik.Nordmark@Sun.COM 		/* Found a client; up it goes */
227511042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
227611042SErik.Nordmark@Sun.COM 		sctp_input(connp, NULL, ip6h, mp, ira);
227711042SErik.Nordmark@Sun.COM 		/* sctp_input does a rele of the sctp_t */
227811042SErik.Nordmark@Sun.COM 		return;
227911042SErik.Nordmark@Sun.COM 	}
228011042SErik.Nordmark@Sun.COM 
228111042SErik.Nordmark@Sun.COM 	case IPPROTO_UDP:
228211042SErik.Nordmark@Sun.COM 		/* First mblk contains IP+UDP headers as checked above */
228311042SErik.Nordmark@Sun.COM 		ASSERT(MBLKL(mp) >= ip_hdr_length + UDPH_SIZE);
228411042SErik.Nordmark@Sun.COM 
228511042SErik.Nordmark@Sun.COM 		if (iraflags & IRAF_MULTIBROADCAST) {
228611042SErik.Nordmark@Sun.COM 			uint16_t *up;	/* Pointer to ports in ULP header */
228711042SErik.Nordmark@Sun.COM 
228811042SErik.Nordmark@Sun.COM 			up = (uint16_t *)((uchar_t *)ip6h + ip_hdr_length);
228911042SErik.Nordmark@Sun.COM 
229011042SErik.Nordmark@Sun.COM 			ip_fanout_udp_multi_v6(mp, ip6h, up[1], up[0], ira);
229111042SErik.Nordmark@Sun.COM 			return;
229211042SErik.Nordmark@Sun.COM 		}
229311042SErik.Nordmark@Sun.COM 
229411042SErik.Nordmark@Sun.COM 		/* Look for AF_INET or AF_INET6 that matches */
229511042SErik.Nordmark@Sun.COM 		connp = ipcl_classify_v6(mp, IPPROTO_UDP, ip_hdr_length,
229611042SErik.Nordmark@Sun.COM 		    ira, ipst);
229711042SErik.Nordmark@Sun.COM 		if (connp == NULL) {
229811042SErik.Nordmark@Sun.COM 	no_udp_match:
229911042SErik.Nordmark@Sun.COM 			if (ipst->ips_ipcl_proto_fanout_v6[IPPROTO_UDP].
230011042SErik.Nordmark@Sun.COM 			    connf_head != NULL) {
230111042SErik.Nordmark@Sun.COM 				ASSERT(ira->ira_protocol == IPPROTO_UDP);
230211042SErik.Nordmark@Sun.COM 				ip_fanout_proto_v6(mp, ip6h, ira);
230311042SErik.Nordmark@Sun.COM 			} else {
230411042SErik.Nordmark@Sun.COM 				ip_fanout_send_icmp_v6(mp, ICMP6_DST_UNREACH,
230511042SErik.Nordmark@Sun.COM 				    ICMP6_DST_UNREACH_NOPORT, ira);
230611042SErik.Nordmark@Sun.COM 			}
230711042SErik.Nordmark@Sun.COM 			return;
230811042SErik.Nordmark@Sun.COM 
230911042SErik.Nordmark@Sun.COM 		}
231011042SErik.Nordmark@Sun.COM 		if (connp->conn_incoming_ifindex != 0 &&
231111042SErik.Nordmark@Sun.COM 		    connp->conn_incoming_ifindex != ira->ira_ruifindex) {
231211042SErik.Nordmark@Sun.COM 			CONN_DEC_REF(connp);
231311042SErik.Nordmark@Sun.COM 			goto no_udp_match;
231411042SErik.Nordmark@Sun.COM 		}
231511042SErik.Nordmark@Sun.COM 		if (IPCL_IS_NONSTR(connp) ? connp->conn_flow_cntrld :
231611042SErik.Nordmark@Sun.COM 		    !canputnext(connp->conn_rq)) {
231711042SErik.Nordmark@Sun.COM 			CONN_DEC_REF(connp);
231811042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, udpIfStatsInOverflows);
231911042SErik.Nordmark@Sun.COM 			ip_drop_input("udpIfStatsInOverflows", mp, ill);
232011042SErik.Nordmark@Sun.COM 			freemsg(mp);
232111042SErik.Nordmark@Sun.COM 			return;
232211042SErik.Nordmark@Sun.COM 		}
232311042SErik.Nordmark@Sun.COM 		if (CONN_INBOUND_POLICY_PRESENT_V6(connp, ipss) ||
232411042SErik.Nordmark@Sun.COM 		    (iraflags & IRAF_IPSEC_SECURE)) {
232511042SErik.Nordmark@Sun.COM 			mp = ipsec_check_inbound_policy(mp, connp,
232611042SErik.Nordmark@Sun.COM 			    NULL, ip6h, ira);
232711042SErik.Nordmark@Sun.COM 			if (mp == NULL) {
232811042SErik.Nordmark@Sun.COM 				BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
232911042SErik.Nordmark@Sun.COM 				/* Note that mp is NULL */
233011042SErik.Nordmark@Sun.COM 				ip_drop_input("ipIfStatsInDiscards", mp, ill);
233111042SErik.Nordmark@Sun.COM 				CONN_DEC_REF(connp);
233211042SErik.Nordmark@Sun.COM 				return;
233311042SErik.Nordmark@Sun.COM 			}
233411042SErik.Nordmark@Sun.COM 		}
233511042SErik.Nordmark@Sun.COM 
233611042SErik.Nordmark@Sun.COM 		/* Found a client; up it goes */
233711042SErik.Nordmark@Sun.COM 		IP6_STAT(ipst, ip6_udp_fannorm);
233811042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
233911042SErik.Nordmark@Sun.COM 		ira->ira_ill = ira->ira_rill = NULL;
234011042SErik.Nordmark@Sun.COM 		(connp->conn_recv)(connp, mp, NULL, ira);
234111042SErik.Nordmark@Sun.COM 		CONN_DEC_REF(connp);
234211042SErik.Nordmark@Sun.COM 		ira->ira_ill = ill;
234311042SErik.Nordmark@Sun.COM 		ira->ira_rill = rill;
234411042SErik.Nordmark@Sun.COM 		return;
234511042SErik.Nordmark@Sun.COM 	default:
234611042SErik.Nordmark@Sun.COM 		break;
234711042SErik.Nordmark@Sun.COM 	}
234811042SErik.Nordmark@Sun.COM 
234911042SErik.Nordmark@Sun.COM 	/*
235011042SErik.Nordmark@Sun.COM 	 * Clear hardware checksumming flag as it is currently only
235111042SErik.Nordmark@Sun.COM 	 * used by TCP and UDP.
235211042SErik.Nordmark@Sun.COM 	 */
235311042SErik.Nordmark@Sun.COM 	DB_CKSUMFLAGS(mp) = 0;
235411042SErik.Nordmark@Sun.COM 
235511042SErik.Nordmark@Sun.COM 	switch (protocol) {
235611042SErik.Nordmark@Sun.COM 	case IPPROTO_ICMPV6:
235711042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInMsgs);
235811042SErik.Nordmark@Sun.COM 
235911042SErik.Nordmark@Sun.COM 		/* Check variable for testing applications */
236011042SErik.Nordmark@Sun.COM 		if (ipst->ips_ipv6_drop_inbound_icmpv6) {
236111042SErik.Nordmark@Sun.COM 			ip_drop_input("ipv6_drop_inbound_icmpv6", mp, ill);
236211042SErik.Nordmark@Sun.COM 			freemsg(mp);
236311042SErik.Nordmark@Sun.COM 			return;
236411042SErik.Nordmark@Sun.COM 		}
236511042SErik.Nordmark@Sun.COM 		/*
236611042SErik.Nordmark@Sun.COM 		 * We need to accomodate icmp messages coming in clear
236711042SErik.Nordmark@Sun.COM 		 * until we get everything secure from the wire. If
236811042SErik.Nordmark@Sun.COM 		 * icmp_accept_clear_messages is zero we check with
236911042SErik.Nordmark@Sun.COM 		 * the global policy and act accordingly. If it is
237011042SErik.Nordmark@Sun.COM 		 * non-zero, we accept the message without any checks.
237111042SErik.Nordmark@Sun.COM 		 * But *this does not mean* that this will be delivered
237211042SErik.Nordmark@Sun.COM 		 * to RAW socket clients. By accepting we might send
237311042SErik.Nordmark@Sun.COM 		 * replies back, change our MTU value etc.,
237411042SErik.Nordmark@Sun.COM 		 * but delivery to the ULP/clients depends on their
237511042SErik.Nordmark@Sun.COM 		 * policy dispositions.
237611042SErik.Nordmark@Sun.COM 		 */
237711042SErik.Nordmark@Sun.COM 		if (ipst->ips_icmp_accept_clear_messages == 0) {
237811042SErik.Nordmark@Sun.COM 			mp = ipsec_check_global_policy(mp, NULL,
237911042SErik.Nordmark@Sun.COM 			    NULL, ip6h, ira, ns);
238011042SErik.Nordmark@Sun.COM 			if (mp == NULL)
238111042SErik.Nordmark@Sun.COM 				return;
238211042SErik.Nordmark@Sun.COM 		}
238311042SErik.Nordmark@Sun.COM 
238411042SErik.Nordmark@Sun.COM 		/*
238511042SErik.Nordmark@Sun.COM 		 * On a labeled system, we have to check whether the zone
238611042SErik.Nordmark@Sun.COM 		 * itself is permitted to receive raw traffic.
238711042SErik.Nordmark@Sun.COM 		 */
238811042SErik.Nordmark@Sun.COM 		if (ira->ira_flags & IRAF_SYSTEM_LABELED) {
238911042SErik.Nordmark@Sun.COM 			if (!tsol_can_accept_raw(mp, ira, B_FALSE)) {
239011042SErik.Nordmark@Sun.COM 				BUMP_MIB(ill->ill_icmp6_mib,
239111042SErik.Nordmark@Sun.COM 				    ipv6IfIcmpInErrors);
239211042SErik.Nordmark@Sun.COM 				ip_drop_input("tsol_can_accept_raw", mp, ill);
239311042SErik.Nordmark@Sun.COM 				freemsg(mp);
239411042SErik.Nordmark@Sun.COM 				return;
239511042SErik.Nordmark@Sun.COM 			}
239611042SErik.Nordmark@Sun.COM 		}
239711042SErik.Nordmark@Sun.COM 
239811042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
239911042SErik.Nordmark@Sun.COM 		mp = icmp_inbound_v6(mp, ira);
240011042SErik.Nordmark@Sun.COM 		if (mp == NULL) {
240111042SErik.Nordmark@Sun.COM 			/* No need to pass to RAW sockets */
240211042SErik.Nordmark@Sun.COM 			return;
240311042SErik.Nordmark@Sun.COM 		}
240411042SErik.Nordmark@Sun.COM 		break;
240511042SErik.Nordmark@Sun.COM 
240611042SErik.Nordmark@Sun.COM 	case IPPROTO_DSTOPTS: {
240711042SErik.Nordmark@Sun.COM 		ip6_dest_t	*desthdr;
240811042SErik.Nordmark@Sun.COM 		uint_t		ehdrlen;
240911042SErik.Nordmark@Sun.COM 		uint8_t		*optptr;
241011042SErik.Nordmark@Sun.COM 
241111042SErik.Nordmark@Sun.COM 		/* We already check for MIN_EHDR_LEN above */
241211042SErik.Nordmark@Sun.COM 
241311042SErik.Nordmark@Sun.COM 		/* Check if AH is present and needs to be processed. */
241411042SErik.Nordmark@Sun.COM 		mp = ipsec_early_ah_v6(mp, ira);
241511042SErik.Nordmark@Sun.COM 		if (mp == NULL)
241611042SErik.Nordmark@Sun.COM 			return;
241711042SErik.Nordmark@Sun.COM 
241811042SErik.Nordmark@Sun.COM 		/*
241911042SErik.Nordmark@Sun.COM 		 * Reinitialize pointers, as ipsec_early_ah_v6() does
242011042SErik.Nordmark@Sun.COM 		 * complete pullups.  We don't have to do more pullups
242111042SErik.Nordmark@Sun.COM 		 * as a result.
242211042SErik.Nordmark@Sun.COM 		 */
242311042SErik.Nordmark@Sun.COM 		ip6h = (ip6_t *)mp->b_rptr;
242411042SErik.Nordmark@Sun.COM 
242511042SErik.Nordmark@Sun.COM 		if (ira->ira_pktlen - ip_hdr_length < MIN_EHDR_LEN)
242611042SErik.Nordmark@Sun.COM 			goto pkt_too_short;
242711042SErik.Nordmark@Sun.COM 
242811042SErik.Nordmark@Sun.COM 		if (mp->b_cont != NULL &&
242911042SErik.Nordmark@Sun.COM 		    rptr + ip_hdr_length + MIN_EHDR_LEN > mp->b_wptr) {
243011042SErik.Nordmark@Sun.COM 			ip6h = ip_pullup(mp, ip_hdr_length + MIN_EHDR_LEN, ira);
243111042SErik.Nordmark@Sun.COM 			if (ip6h == NULL)
243211042SErik.Nordmark@Sun.COM 				goto discard;
243311042SErik.Nordmark@Sun.COM 		}
243411042SErik.Nordmark@Sun.COM 		desthdr = (ip6_dest_t *)(rptr + ip_hdr_length);
243511042SErik.Nordmark@Sun.COM 		ehdrlen = 8 * (desthdr->ip6d_len + 1);
243611042SErik.Nordmark@Sun.COM 		if (ira->ira_pktlen - ip_hdr_length < ehdrlen)
243711042SErik.Nordmark@Sun.COM 			goto pkt_too_short;
243811042SErik.Nordmark@Sun.COM 		if (mp->b_cont != NULL &&
243911042SErik.Nordmark@Sun.COM 		    rptr + IPV6_HDR_LEN + ehdrlen > mp->b_wptr) {
244011042SErik.Nordmark@Sun.COM 			ip6h = ip_pullup(mp, IPV6_HDR_LEN + ehdrlen, ira);
244111042SErik.Nordmark@Sun.COM 			if (ip6h == NULL)
244211042SErik.Nordmark@Sun.COM 				goto discard;
244311042SErik.Nordmark@Sun.COM 
244411042SErik.Nordmark@Sun.COM 			desthdr = (ip6_dest_t *)(rptr + ip_hdr_length);
244511042SErik.Nordmark@Sun.COM 		}
244611042SErik.Nordmark@Sun.COM 		optptr = (uint8_t *)&desthdr[1];
244711042SErik.Nordmark@Sun.COM 
244811042SErik.Nordmark@Sun.COM 		/*
244911042SErik.Nordmark@Sun.COM 		 * Update ira_ip_hdr_length to skip the destination header
245011042SErik.Nordmark@Sun.COM 		 * when we repeat.
245111042SErik.Nordmark@Sun.COM 		 */
245211042SErik.Nordmark@Sun.COM 		ira->ira_ip_hdr_length += ehdrlen;
245311042SErik.Nordmark@Sun.COM 
245411042SErik.Nordmark@Sun.COM 		ira->ira_protocol = desthdr->ip6d_nxt;
245511042SErik.Nordmark@Sun.COM 
245611042SErik.Nordmark@Sun.COM 		/*
245711042SErik.Nordmark@Sun.COM 		 * Note: XXX This code does not seem to make
245811042SErik.Nordmark@Sun.COM 		 * distinction between Destination Options Header
245911042SErik.Nordmark@Sun.COM 		 * being before/after Routing Header which can
246011042SErik.Nordmark@Sun.COM 		 * happen if we are at the end of source route.
246111042SErik.Nordmark@Sun.COM 		 * This may become significant in future.
246211042SErik.Nordmark@Sun.COM 		 * (No real significant Destination Options are
246311042SErik.Nordmark@Sun.COM 		 * defined/implemented yet ).
246411042SErik.Nordmark@Sun.COM 		 */
246511042SErik.Nordmark@Sun.COM 		switch (ip_process_options_v6(mp, ip6h, optptr,
246611042SErik.Nordmark@Sun.COM 		    ehdrlen - 2, IPPROTO_DSTOPTS, ira)) {
246711042SErik.Nordmark@Sun.COM 		case -1:
246811042SErik.Nordmark@Sun.COM 			/*
246911042SErik.Nordmark@Sun.COM 			 * Packet has been consumed and any needed
247011042SErik.Nordmark@Sun.COM 			 * ICMP errors sent.
247111042SErik.Nordmark@Sun.COM 			 */
247211042SErik.Nordmark@Sun.COM 			return;
247311042SErik.Nordmark@Sun.COM 		case 0:
247411042SErik.Nordmark@Sun.COM 			/* No action needed  continue */
247511042SErik.Nordmark@Sun.COM 			break;
247611042SErik.Nordmark@Sun.COM 		case 1:
247711042SErik.Nordmark@Sun.COM 			/*
247811042SErik.Nordmark@Sun.COM 			 * Unnexpected return value
247911042SErik.Nordmark@Sun.COM 			 * (Router alert is a Hop-by-Hop option)
248011042SErik.Nordmark@Sun.COM 			 */
248111042SErik.Nordmark@Sun.COM #ifdef DEBUG
248211042SErik.Nordmark@Sun.COM 			panic("ip_fanout_v6: router "
248311042SErik.Nordmark@Sun.COM 			    "alert hbh opt indication in dest opt");
248411042SErik.Nordmark@Sun.COM 			/*NOTREACHED*/
248511042SErik.Nordmark@Sun.COM #else
248611042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
248711042SErik.Nordmark@Sun.COM 			ip_drop_input("ipIfStatsInDiscards", mp, ill);
248811042SErik.Nordmark@Sun.COM 			freemsg(mp);
248911042SErik.Nordmark@Sun.COM 			return;
249011042SErik.Nordmark@Sun.COM #endif
249111042SErik.Nordmark@Sun.COM 		}
249211042SErik.Nordmark@Sun.COM 		goto repeat;
249311042SErik.Nordmark@Sun.COM 	}
249411042SErik.Nordmark@Sun.COM 	case IPPROTO_FRAGMENT: {
249511042SErik.Nordmark@Sun.COM 		ip6_frag_t *fraghdr;
249611042SErik.Nordmark@Sun.COM 
249711042SErik.Nordmark@Sun.COM 		if (ira->ira_pktlen - ip_hdr_length < sizeof (ip6_frag_t))
249811042SErik.Nordmark@Sun.COM 			goto pkt_too_short;
249911042SErik.Nordmark@Sun.COM 
250011042SErik.Nordmark@Sun.COM 		if (mp->b_cont != NULL &&
250111042SErik.Nordmark@Sun.COM 		    rptr + ip_hdr_length + sizeof (ip6_frag_t) > mp->b_wptr) {
250211042SErik.Nordmark@Sun.COM 			ip6h = ip_pullup(mp,
250311042SErik.Nordmark@Sun.COM 			    ip_hdr_length + sizeof (ip6_frag_t), ira);
250411042SErik.Nordmark@Sun.COM 			if (ip6h == NULL)
250511042SErik.Nordmark@Sun.COM 				goto discard;
250611042SErik.Nordmark@Sun.COM 		}
250711042SErik.Nordmark@Sun.COM 
250811042SErik.Nordmark@Sun.COM 		fraghdr = (ip6_frag_t *)(rptr + ip_hdr_length);
250911042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsReasmReqds);
251011042SErik.Nordmark@Sun.COM 
251111042SErik.Nordmark@Sun.COM 		/*
251211042SErik.Nordmark@Sun.COM 		 * Invoke the CGTP (multirouting) filtering module to
251311042SErik.Nordmark@Sun.COM 		 * process the incoming packet. Packets identified as
251411042SErik.Nordmark@Sun.COM 		 * duplicates must be discarded. Filtering is active
251511042SErik.Nordmark@Sun.COM 		 * only if the ip_cgtp_filter ndd variable is
251611042SErik.Nordmark@Sun.COM 		 * non-zero.
251711042SErik.Nordmark@Sun.COM 		 */
251811042SErik.Nordmark@Sun.COM 		if (ipst->ips_ip_cgtp_filter &&
251911042SErik.Nordmark@Sun.COM 		    ipst->ips_ip_cgtp_filter_ops != NULL) {
252011042SErik.Nordmark@Sun.COM 			int cgtp_flt_pkt;
252111042SErik.Nordmark@Sun.COM 			netstackid_t stackid;
252211042SErik.Nordmark@Sun.COM 
252311042SErik.Nordmark@Sun.COM 			stackid = ipst->ips_netstack->netstack_stackid;
252411042SErik.Nordmark@Sun.COM 
252511042SErik.Nordmark@Sun.COM 			/*
252611042SErik.Nordmark@Sun.COM 			 * CGTP and IPMP are mutually exclusive so
252711042SErik.Nordmark@Sun.COM 			 * phyint_ifindex is fine here.
252811042SErik.Nordmark@Sun.COM 			 */
252911042SErik.Nordmark@Sun.COM 			cgtp_flt_pkt =
253011042SErik.Nordmark@Sun.COM 			    ipst->ips_ip_cgtp_filter_ops->cfo_filter_v6(
253111042SErik.Nordmark@Sun.COM 			    stackid, ill->ill_phyint->phyint_ifindex,
253211042SErik.Nordmark@Sun.COM 			    ip6h, fraghdr);
253311042SErik.Nordmark@Sun.COM 			if (cgtp_flt_pkt == CGTP_IP_PKT_DUPLICATE) {
253411042SErik.Nordmark@Sun.COM 				ip_drop_input("CGTP_IP_PKT_DUPLICATE", mp, ill);
253511042SErik.Nordmark@Sun.COM 				freemsg(mp);
253611042SErik.Nordmark@Sun.COM 				return;
253711042SErik.Nordmark@Sun.COM 			}
253811042SErik.Nordmark@Sun.COM 		}
253911042SErik.Nordmark@Sun.COM 
254011042SErik.Nordmark@Sun.COM 		/*
254111042SErik.Nordmark@Sun.COM 		 * Update ip_hdr_length to skip the frag header
254211042SErik.Nordmark@Sun.COM 		 * ip_input_fragment_v6 will determine the extension header
254311042SErik.Nordmark@Sun.COM 		 * prior to the fragment header and update its nexthdr value,
254411042SErik.Nordmark@Sun.COM 		 * and also set ira_protocol to the nexthdr that follows the
254511042SErik.Nordmark@Sun.COM 		 * completed fragment.
254611042SErik.Nordmark@Sun.COM 		 */
254711042SErik.Nordmark@Sun.COM 		ip_hdr_length += sizeof (ip6_frag_t);
254811042SErik.Nordmark@Sun.COM 
254911042SErik.Nordmark@Sun.COM 		/*
255011042SErik.Nordmark@Sun.COM 		 * Make sure we have ira_l2src before we loose the original
255111042SErik.Nordmark@Sun.COM 		 * mblk
255211042SErik.Nordmark@Sun.COM 		 */
255311042SErik.Nordmark@Sun.COM 		if (!(ira->ira_flags & IRAF_L2SRC_SET))
255411042SErik.Nordmark@Sun.COM 			ip_setl2src(mp, ira, ira->ira_rill);
255511042SErik.Nordmark@Sun.COM 
255611042SErik.Nordmark@Sun.COM 		mp = ip_input_fragment_v6(mp, ip6h, fraghdr,
255711042SErik.Nordmark@Sun.COM 		    ira->ira_pktlen - ip_hdr_length, ira);
255811042SErik.Nordmark@Sun.COM 		if (mp == NULL) {
255911042SErik.Nordmark@Sun.COM 			/* Reassembly is still pending */
256011042SErik.Nordmark@Sun.COM 			return;
256111042SErik.Nordmark@Sun.COM 		}
256211042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsReasmOKs);
256311042SErik.Nordmark@Sun.COM 
256411042SErik.Nordmark@Sun.COM 		/*
256511042SErik.Nordmark@Sun.COM 		 * The mblk chain has the frag header removed and
256611042SErik.Nordmark@Sun.COM 		 * ira_protocol, ira_pktlen, ira_ip_hdr_length as well as the
256711042SErik.Nordmark@Sun.COM 		 * IP header has been updated to refleact the result.
256811042SErik.Nordmark@Sun.COM 		 */
256911042SErik.Nordmark@Sun.COM 		ip6h = (ip6_t *)mp->b_rptr;
257011042SErik.Nordmark@Sun.COM 		ip_hdr_length = ira->ira_ip_hdr_length;
257111042SErik.Nordmark@Sun.COM 		goto repeat;
257211042SErik.Nordmark@Sun.COM 	}
257311042SErik.Nordmark@Sun.COM 	case IPPROTO_HOPOPTS:
257411042SErik.Nordmark@Sun.COM 		/*
257511042SErik.Nordmark@Sun.COM 		 * Illegal header sequence.
257611042SErik.Nordmark@Sun.COM 		 * (Hop-by-hop headers are processed above
257711042SErik.Nordmark@Sun.COM 		 *  and required to immediately follow IPv6 header)
257811042SErik.Nordmark@Sun.COM 		 */
257911042SErik.Nordmark@Sun.COM 		ip_drop_input("ICMP_PARAM_PROBLEM", mp, ill);
258011042SErik.Nordmark@Sun.COM 		icmp_param_problem_nexthdr_v6(mp, B_FALSE, ira);
258111042SErik.Nordmark@Sun.COM 		return;
258211042SErik.Nordmark@Sun.COM 
258311042SErik.Nordmark@Sun.COM 	case IPPROTO_ROUTING: {
258411042SErik.Nordmark@Sun.COM 		uint_t ehdrlen;
258511042SErik.Nordmark@Sun.COM 		ip6_rthdr_t *rthdr;
258611042SErik.Nordmark@Sun.COM 
258711042SErik.Nordmark@Sun.COM 		/* Check if AH is present and needs to be processed. */
258811042SErik.Nordmark@Sun.COM 		mp = ipsec_early_ah_v6(mp, ira);
258911042SErik.Nordmark@Sun.COM 		if (mp == NULL)
259011042SErik.Nordmark@Sun.COM 			return;
259111042SErik.Nordmark@Sun.COM 
259211042SErik.Nordmark@Sun.COM 		/*
259311042SErik.Nordmark@Sun.COM 		 * Reinitialize pointers, as ipsec_early_ah_v6() does
259411042SErik.Nordmark@Sun.COM 		 * complete pullups.  We don't have to do more pullups
259511042SErik.Nordmark@Sun.COM 		 * as a result.
259611042SErik.Nordmark@Sun.COM 		 */
259711042SErik.Nordmark@Sun.COM 		ip6h = (ip6_t *)mp->b_rptr;
259811042SErik.Nordmark@Sun.COM 
259911042SErik.Nordmark@Sun.COM 		if (ira->ira_pktlen - ip_hdr_length < MIN_EHDR_LEN)
260011042SErik.Nordmark@Sun.COM 			goto pkt_too_short;
260111042SErik.Nordmark@Sun.COM 
260211042SErik.Nordmark@Sun.COM 		if (mp->b_cont != NULL &&
260311042SErik.Nordmark@Sun.COM 		    rptr + ip_hdr_length + MIN_EHDR_LEN > mp->b_wptr) {
260411042SErik.Nordmark@Sun.COM 			ip6h = ip_pullup(mp, ip_hdr_length + MIN_EHDR_LEN, ira);
260511042SErik.Nordmark@Sun.COM 			if (ip6h == NULL)
260611042SErik.Nordmark@Sun.COM 				goto discard;
260711042SErik.Nordmark@Sun.COM 		}
260811042SErik.Nordmark@Sun.COM 		rthdr = (ip6_rthdr_t *)(rptr + ip_hdr_length);
260911042SErik.Nordmark@Sun.COM 		protocol = ira->ira_protocol = rthdr->ip6r_nxt;
261011042SErik.Nordmark@Sun.COM 		ehdrlen = 8 * (rthdr->ip6r_len + 1);
261111042SErik.Nordmark@Sun.COM 		if (ira->ira_pktlen - ip_hdr_length < ehdrlen)
261211042SErik.Nordmark@Sun.COM 			goto pkt_too_short;
261311042SErik.Nordmark@Sun.COM 		if (mp->b_cont != NULL &&
261411042SErik.Nordmark@Sun.COM 		    rptr + IPV6_HDR_LEN + ehdrlen > mp->b_wptr) {
261511042SErik.Nordmark@Sun.COM 			ip6h = ip_pullup(mp, IPV6_HDR_LEN + ehdrlen, ira);
261611042SErik.Nordmark@Sun.COM 			if (ip6h == NULL)
261711042SErik.Nordmark@Sun.COM 				goto discard;
261811042SErik.Nordmark@Sun.COM 			rthdr = (ip6_rthdr_t *)(rptr + ip_hdr_length);
261911042SErik.Nordmark@Sun.COM 		}
262011042SErik.Nordmark@Sun.COM 		if (rthdr->ip6r_segleft != 0) {
262111042SErik.Nordmark@Sun.COM 			/* Not end of source route */
262211042SErik.Nordmark@Sun.COM 			if (ira->ira_flags &
262311042SErik.Nordmark@Sun.COM 			    (IRAF_L2DST_MULTICAST|IRAF_L2DST_BROADCAST)) {
262411042SErik.Nordmark@Sun.COM 				BUMP_MIB(ill->ill_ip_mib,
262511042SErik.Nordmark@Sun.COM 				    ipIfStatsForwProhibits);
262611042SErik.Nordmark@Sun.COM 				ip_drop_input("ipIfStatsInForwProhibits",
262711042SErik.Nordmark@Sun.COM 				    mp, ill);
262811042SErik.Nordmark@Sun.COM 				freemsg(mp);
262911042SErik.Nordmark@Sun.COM 				return;
263011042SErik.Nordmark@Sun.COM 			}
263111042SErik.Nordmark@Sun.COM 			ip_process_rthdr(mp, ip6h, rthdr, ira);
263211042SErik.Nordmark@Sun.COM 			return;
263311042SErik.Nordmark@Sun.COM 		}
263411042SErik.Nordmark@Sun.COM 		ira->ira_ip_hdr_length += ehdrlen;
263511042SErik.Nordmark@Sun.COM 		goto repeat;
263611042SErik.Nordmark@Sun.COM 	}
263711042SErik.Nordmark@Sun.COM 
263811042SErik.Nordmark@Sun.COM 	case IPPROTO_AH:
263911042SErik.Nordmark@Sun.COM 	case IPPROTO_ESP: {
264011042SErik.Nordmark@Sun.COM 		/*
264111042SErik.Nordmark@Sun.COM 		 * Fast path for AH/ESP.
264211042SErik.Nordmark@Sun.COM 		 */
264311042SErik.Nordmark@Sun.COM 		netstack_t *ns = ipst->ips_netstack;
264411042SErik.Nordmark@Sun.COM 		ipsec_stack_t *ipss = ns->netstack_ipsec;
264511042SErik.Nordmark@Sun.COM 
264611042SErik.Nordmark@Sun.COM 		IP_STAT(ipst, ipsec_proto_ahesp);
264711042SErik.Nordmark@Sun.COM 
264811042SErik.Nordmark@Sun.COM 		if (!ipsec_loaded(ipss)) {
264911042SErik.Nordmark@Sun.COM 			ip_proto_not_sup(mp, ira);
265011042SErik.Nordmark@Sun.COM 			return;
265111042SErik.Nordmark@Sun.COM 		}
265211042SErik.Nordmark@Sun.COM 
265311042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
265411042SErik.Nordmark@Sun.COM 		/* select inbound SA and have IPsec process the pkt */
265511042SErik.Nordmark@Sun.COM 		if (protocol == IPPROTO_ESP) {
265611042SErik.Nordmark@Sun.COM 			esph_t *esph;
265711042SErik.Nordmark@Sun.COM 
265811042SErik.Nordmark@Sun.COM 			mp = ipsec_inbound_esp_sa(mp, ira, &esph);
265911042SErik.Nordmark@Sun.COM 			if (mp == NULL)
266011042SErik.Nordmark@Sun.COM 				return;
266111042SErik.Nordmark@Sun.COM 
266211042SErik.Nordmark@Sun.COM 			ASSERT(esph != NULL);
266311042SErik.Nordmark@Sun.COM 			ASSERT(ira->ira_flags & IRAF_IPSEC_SECURE);
266411042SErik.Nordmark@Sun.COM 			ASSERT(ira->ira_ipsec_esp_sa != NULL);
266511042SErik.Nordmark@Sun.COM 			ASSERT(ira->ira_ipsec_esp_sa->ipsa_input_func != NULL);
266611042SErik.Nordmark@Sun.COM 
266711042SErik.Nordmark@Sun.COM 			mp = ira->ira_ipsec_esp_sa->ipsa_input_func(mp, esph,
266811042SErik.Nordmark@Sun.COM 			    ira);
266911042SErik.Nordmark@Sun.COM 		} else {
267011042SErik.Nordmark@Sun.COM 			ah_t *ah;
267111042SErik.Nordmark@Sun.COM 
267211042SErik.Nordmark@Sun.COM 			mp = ipsec_inbound_ah_sa(mp, ira, &ah);
267311042SErik.Nordmark@Sun.COM 			if (mp == NULL)
267411042SErik.Nordmark@Sun.COM 				return;
267511042SErik.Nordmark@Sun.COM 
267611042SErik.Nordmark@Sun.COM 			ASSERT(ah != NULL);
267711042SErik.Nordmark@Sun.COM 			ASSERT(ira->ira_flags & IRAF_IPSEC_SECURE);
267811042SErik.Nordmark@Sun.COM 			ASSERT(ira->ira_ipsec_ah_sa != NULL);
267911042SErik.Nordmark@Sun.COM 			ASSERT(ira->ira_ipsec_ah_sa->ipsa_input_func != NULL);
268011042SErik.Nordmark@Sun.COM 			mp = ira->ira_ipsec_ah_sa->ipsa_input_func(mp, ah,
268111042SErik.Nordmark@Sun.COM 			    ira);
268211042SErik.Nordmark@Sun.COM 		}
268311042SErik.Nordmark@Sun.COM 
268411042SErik.Nordmark@Sun.COM 		if (mp == NULL) {
268511042SErik.Nordmark@Sun.COM 			/*
268611042SErik.Nordmark@Sun.COM 			 * Either it failed or is pending. In the former case
268711042SErik.Nordmark@Sun.COM 			 * ipIfStatsInDiscards was increased.
268811042SErik.Nordmark@Sun.COM 			 */
268911042SErik.Nordmark@Sun.COM 			return;
269011042SErik.Nordmark@Sun.COM 		}
269111042SErik.Nordmark@Sun.COM 		/* we're done with IPsec processing, send it up */
269211042SErik.Nordmark@Sun.COM 		ip_input_post_ipsec(mp, ira);
269311042SErik.Nordmark@Sun.COM 		return;
269411042SErik.Nordmark@Sun.COM 	}
269511042SErik.Nordmark@Sun.COM 	case IPPROTO_NONE:
269611042SErik.Nordmark@Sun.COM 		/* All processing is done. Count as "delivered". */
269711042SErik.Nordmark@Sun.COM 		freemsg(mp);
269811042SErik.Nordmark@Sun.COM 		BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
269911042SErik.Nordmark@Sun.COM 		return;
270011042SErik.Nordmark@Sun.COM 
270111042SErik.Nordmark@Sun.COM 	case IPPROTO_ENCAP:
270211042SErik.Nordmark@Sun.COM 	case IPPROTO_IPV6:
270311042SErik.Nordmark@Sun.COM 		/* iptun will verify trusted label */
270411042SErik.Nordmark@Sun.COM 		connp = ipcl_classify_v6(mp, protocol, ip_hdr_length,
270511042SErik.Nordmark@Sun.COM 		    ira, ipst);
270611042SErik.Nordmark@Sun.COM 		if (connp != NULL) {
270711042SErik.Nordmark@Sun.COM 			BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
270811042SErik.Nordmark@Sun.COM 			ira->ira_ill = ira->ira_rill = NULL;
270911042SErik.Nordmark@Sun.COM 			connp->conn_recv(connp, mp, NULL, ira);
271011042SErik.Nordmark@Sun.COM 			CONN_DEC_REF(connp);
271111042SErik.Nordmark@Sun.COM 			ira->ira_ill = ill;
271211042SErik.Nordmark@Sun.COM 			ira->ira_rill = rill;
271311042SErik.Nordmark@Sun.COM 			return;
271411042SErik.Nordmark@Sun.COM 		}
271511042SErik.Nordmark@Sun.COM 		/* FALLTHRU */
271611042SErik.Nordmark@Sun.COM 	default:
271711042SErik.Nordmark@Sun.COM 		/*
271811042SErik.Nordmark@Sun.COM 		 * On a labeled system, we have to check whether the zone
271911042SErik.Nordmark@Sun.COM 		 * itself is permitted to receive raw traffic.
272011042SErik.Nordmark@Sun.COM 		 */
272111042SErik.Nordmark@Sun.COM 		if (ira->ira_flags & IRAF_SYSTEM_LABELED) {
272211042SErik.Nordmark@Sun.COM 			if (!tsol_can_accept_raw(mp, ira, B_FALSE)) {
272311042SErik.Nordmark@Sun.COM 				BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
272411042SErik.Nordmark@Sun.COM 				ip_drop_input("ipIfStatsInDiscards", mp, ill);
272511042SErik.Nordmark@Sun.COM 				freemsg(mp);
272611042SErik.Nordmark@Sun.COM 				return;
272711042SErik.Nordmark@Sun.COM 			}
272811042SErik.Nordmark@Sun.COM 		}
272911042SErik.Nordmark@Sun.COM 		break;
273011042SErik.Nordmark@Sun.COM 	}
273111042SErik.Nordmark@Sun.COM 
273211042SErik.Nordmark@Sun.COM 	/*
273311042SErik.Nordmark@Sun.COM 	 * The above input functions may have returned the pulled up message.
273411042SErik.Nordmark@Sun.COM 	 * So ip6h need to be reinitialized.
273511042SErik.Nordmark@Sun.COM 	 */
273611042SErik.Nordmark@Sun.COM 	ip6h = (ip6_t *)mp->b_rptr;
273711042SErik.Nordmark@Sun.COM 	ira->ira_protocol = protocol;
273811042SErik.Nordmark@Sun.COM 	if (ipst->ips_ipcl_proto_fanout_v6[protocol].connf_head == NULL) {
273911042SErik.Nordmark@Sun.COM 		/* No user-level listener for these packets packets */
274011042SErik.Nordmark@Sun.COM 		ip_proto_not_sup(mp, ira);
274111042SErik.Nordmark@Sun.COM 		return;
274211042SErik.Nordmark@Sun.COM 	}
274311042SErik.Nordmark@Sun.COM 
274411042SErik.Nordmark@Sun.COM 	/*
274511042SErik.Nordmark@Sun.COM 	 * Handle fanout to raw sockets.  There
274611042SErik.Nordmark@Sun.COM 	 * can be more than one stream bound to a particular
274711042SErik.Nordmark@Sun.COM 	 * protocol.  When this is the case, each one gets a copy
274811042SErik.Nordmark@Sun.COM 	 * of any incoming packets.
274911042SErik.Nordmark@Sun.COM 	 */
275011042SErik.Nordmark@Sun.COM 	ASSERT(ira->ira_protocol == protocol);
275111042SErik.Nordmark@Sun.COM 	ip_fanout_proto_v6(mp, ip6h, ira);
275211042SErik.Nordmark@Sun.COM 	return;
275311042SErik.Nordmark@Sun.COM 
275411042SErik.Nordmark@Sun.COM pkt_too_short:
275511042SErik.Nordmark@Sun.COM 	BUMP_MIB(ill->ill_ip_mib, ipIfStatsInTruncatedPkts);
275611042SErik.Nordmark@Sun.COM 	ip_drop_input("ipIfStatsInTruncatedPkts", mp, ill);
275711042SErik.Nordmark@Sun.COM 	freemsg(mp);
275811042SErik.Nordmark@Sun.COM 	return;
275911042SErik.Nordmark@Sun.COM 
276011042SErik.Nordmark@Sun.COM discard:
276111042SErik.Nordmark@Sun.COM 	BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
276211042SErik.Nordmark@Sun.COM 	ip_drop_input("ipIfStatsInDiscards", mp, ill);
276311042SErik.Nordmark@Sun.COM 	freemsg(mp);
276411042SErik.Nordmark@Sun.COM #undef rptr
276511042SErik.Nordmark@Sun.COM }
2766