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 /* 2311042SErik.Nordmark@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 2411042SErik.Nordmark@Sun.COM * Use is subject to license terms. 2511042SErik.Nordmark@Sun.COM */ 2611042SErik.Nordmark@Sun.COM /* Copyright (c) 1990 Mentat Inc. */ 2711042SErik.Nordmark@Sun.COM 2811042SErik.Nordmark@Sun.COM #include <sys/types.h> 2911042SErik.Nordmark@Sun.COM #include <sys/stream.h> 3011042SErik.Nordmark@Sun.COM #include <sys/dlpi.h> 3111042SErik.Nordmark@Sun.COM #include <sys/stropts.h> 3211042SErik.Nordmark@Sun.COM #include <sys/sysmacros.h> 3311042SErik.Nordmark@Sun.COM #include <sys/strsubr.h> 3411042SErik.Nordmark@Sun.COM #include <sys/strlog.h> 3511042SErik.Nordmark@Sun.COM #include <sys/strsun.h> 3611042SErik.Nordmark@Sun.COM #include <sys/zone.h> 3711042SErik.Nordmark@Sun.COM #define _SUN_TPI_VERSION 2 3811042SErik.Nordmark@Sun.COM #include <sys/tihdr.h> 3911042SErik.Nordmark@Sun.COM #include <sys/xti_inet.h> 4011042SErik.Nordmark@Sun.COM #include <sys/ddi.h> 4111042SErik.Nordmark@Sun.COM #include <sys/sunddi.h> 4211042SErik.Nordmark@Sun.COM #include <sys/cmn_err.h> 4311042SErik.Nordmark@Sun.COM #include <sys/debug.h> 4411042SErik.Nordmark@Sun.COM #include <sys/kobj.h> 4511042SErik.Nordmark@Sun.COM #include <sys/modctl.h> 4611042SErik.Nordmark@Sun.COM #include <sys/atomic.h> 4711042SErik.Nordmark@Sun.COM #include <sys/policy.h> 4811042SErik.Nordmark@Sun.COM #include <sys/priv.h> 4911042SErik.Nordmark@Sun.COM 5011042SErik.Nordmark@Sun.COM #include <sys/systm.h> 5111042SErik.Nordmark@Sun.COM #include <sys/param.h> 5211042SErik.Nordmark@Sun.COM #include <sys/kmem.h> 5311042SErik.Nordmark@Sun.COM #include <sys/sdt.h> 5411042SErik.Nordmark@Sun.COM #include <sys/socket.h> 5511042SErik.Nordmark@Sun.COM #include <sys/vtrace.h> 5611042SErik.Nordmark@Sun.COM #include <sys/isa_defs.h> 5711042SErik.Nordmark@Sun.COM #include <sys/mac.h> 5811042SErik.Nordmark@Sun.COM #include <net/if.h> 5911042SErik.Nordmark@Sun.COM #include <net/if_arp.h> 6011042SErik.Nordmark@Sun.COM #include <net/route.h> 6111042SErik.Nordmark@Sun.COM #include <sys/sockio.h> 6211042SErik.Nordmark@Sun.COM #include <netinet/in.h> 6311042SErik.Nordmark@Sun.COM #include <net/if_dl.h> 6411042SErik.Nordmark@Sun.COM 6511042SErik.Nordmark@Sun.COM #include <inet/common.h> 6611042SErik.Nordmark@Sun.COM #include <inet/mi.h> 6711042SErik.Nordmark@Sun.COM #include <inet/mib2.h> 6811042SErik.Nordmark@Sun.COM #include <inet/nd.h> 6911042SErik.Nordmark@Sun.COM #include <inet/arp.h> 7011042SErik.Nordmark@Sun.COM #include <inet/snmpcom.h> 7111042SErik.Nordmark@Sun.COM #include <inet/kstatcom.h> 7211042SErik.Nordmark@Sun.COM 7311042SErik.Nordmark@Sun.COM #include <netinet/igmp_var.h> 7411042SErik.Nordmark@Sun.COM #include <netinet/ip6.h> 7511042SErik.Nordmark@Sun.COM #include <netinet/icmp6.h> 7611042SErik.Nordmark@Sun.COM #include <netinet/sctp.h> 7711042SErik.Nordmark@Sun.COM 7811042SErik.Nordmark@Sun.COM #include <inet/ip.h> 7911042SErik.Nordmark@Sun.COM #include <inet/ip_impl.h> 8011042SErik.Nordmark@Sun.COM #include <inet/ip6.h> 8111042SErik.Nordmark@Sun.COM #include <inet/ip6_asp.h> 8211042SErik.Nordmark@Sun.COM #include <inet/optcom.h> 8311042SErik.Nordmark@Sun.COM #include <inet/tcp.h> 8411042SErik.Nordmark@Sun.COM #include <inet/tcp_impl.h> 8511042SErik.Nordmark@Sun.COM #include <inet/ip_multi.h> 8611042SErik.Nordmark@Sun.COM #include <inet/ip_if.h> 8711042SErik.Nordmark@Sun.COM #include <inet/ip_ire.h> 8811042SErik.Nordmark@Sun.COM #include <inet/ip_ftable.h> 8911042SErik.Nordmark@Sun.COM #include <inet/ip_rts.h> 9011042SErik.Nordmark@Sun.COM #include <inet/ip_ndp.h> 9111042SErik.Nordmark@Sun.COM #include <inet/ip_listutils.h> 9211042SErik.Nordmark@Sun.COM #include <netinet/igmp.h> 9311042SErik.Nordmark@Sun.COM #include <netinet/ip_mroute.h> 9411042SErik.Nordmark@Sun.COM #include <inet/ipp_common.h> 9511042SErik.Nordmark@Sun.COM 9611042SErik.Nordmark@Sun.COM #include <net/pfkeyv2.h> 9711042SErik.Nordmark@Sun.COM #include <inet/sadb.h> 9811042SErik.Nordmark@Sun.COM #include <inet/ipsec_impl.h> 9911042SErik.Nordmark@Sun.COM #include <inet/ipdrop.h> 10011042SErik.Nordmark@Sun.COM #include <inet/ip_netinfo.h> 10111042SErik.Nordmark@Sun.COM #include <inet/ilb_ip.h> 10211042SErik.Nordmark@Sun.COM #include <sys/squeue_impl.h> 10311042SErik.Nordmark@Sun.COM #include <sys/squeue.h> 10411042SErik.Nordmark@Sun.COM 10511042SErik.Nordmark@Sun.COM #include <sys/ethernet.h> 10611042SErik.Nordmark@Sun.COM #include <net/if_types.h> 10711042SErik.Nordmark@Sun.COM #include <sys/cpuvar.h> 10811042SErik.Nordmark@Sun.COM 10911042SErik.Nordmark@Sun.COM #include <ipp/ipp.h> 11011042SErik.Nordmark@Sun.COM #include <ipp/ipp_impl.h> 11111042SErik.Nordmark@Sun.COM #include <ipp/ipgpc/ipgpc.h> 11211042SErik.Nordmark@Sun.COM 11311042SErik.Nordmark@Sun.COM #include <sys/pattr.h> 11411042SErik.Nordmark@Sun.COM #include <inet/ipclassifier.h> 11511042SErik.Nordmark@Sun.COM #include <inet/sctp_ip.h> 11611042SErik.Nordmark@Sun.COM #include <inet/sctp/sctp_impl.h> 11711042SErik.Nordmark@Sun.COM #include <inet/udp_impl.h> 11811042SErik.Nordmark@Sun.COM #include <sys/sunddi.h> 11911042SErik.Nordmark@Sun.COM 12011042SErik.Nordmark@Sun.COM #include <sys/tsol/label.h> 12111042SErik.Nordmark@Sun.COM #include <sys/tsol/tnet.h> 12211042SErik.Nordmark@Sun.COM 12311110SErik.Nordmark@Sun.COM #include <sys/clock_impl.h> /* For LBOLT_FASTPATH{,64} */ 12411042SErik.Nordmark@Sun.COM 12511042SErik.Nordmark@Sun.COM #ifdef DEBUG 12611042SErik.Nordmark@Sun.COM extern boolean_t skip_sctp_cksum; 12711042SErik.Nordmark@Sun.COM #endif 12811042SErik.Nordmark@Sun.COM 12911042SErik.Nordmark@Sun.COM static void ip_input_local_v4(ire_t *, mblk_t *, ipha_t *, 13011042SErik.Nordmark@Sun.COM ip_recv_attr_t *); 13111042SErik.Nordmark@Sun.COM 13211042SErik.Nordmark@Sun.COM static void ip_input_broadcast_v4(ire_t *, mblk_t *, ipha_t *, 13311042SErik.Nordmark@Sun.COM ip_recv_attr_t *); 13411042SErik.Nordmark@Sun.COM static void ip_input_multicast_v4(ire_t *, mblk_t *, ipha_t *, 13511042SErik.Nordmark@Sun.COM ip_recv_attr_t *); 13611042SErik.Nordmark@Sun.COM 13711042SErik.Nordmark@Sun.COM #pragma inline(ip_input_common_v4, ip_input_local_v4, ip_forward_xmit_v4) 13811042SErik.Nordmark@Sun.COM 13911042SErik.Nordmark@Sun.COM /* 14011042SErik.Nordmark@Sun.COM * Direct read side procedure capable of dealing with chains. GLDv3 based 14111042SErik.Nordmark@Sun.COM * drivers call this function directly with mblk chains while STREAMS 14211042SErik.Nordmark@Sun.COM * read side procedure ip_rput() calls this for single packet with ip_ring 14311042SErik.Nordmark@Sun.COM * set to NULL to process one packet at a time. 14411042SErik.Nordmark@Sun.COM * 14511042SErik.Nordmark@Sun.COM * The ill will always be valid if this function is called directly from 14611042SErik.Nordmark@Sun.COM * the driver. 14711042SErik.Nordmark@Sun.COM * 14811042SErik.Nordmark@Sun.COM * If ip_input() is called from GLDv3: 14911042SErik.Nordmark@Sun.COM * 15011042SErik.Nordmark@Sun.COM * - This must be a non-VLAN IP stream. 15111042SErik.Nordmark@Sun.COM * - 'mp' is either an untagged or a special priority-tagged packet. 15211042SErik.Nordmark@Sun.COM * - Any VLAN tag that was in the MAC header has been stripped. 15311042SErik.Nordmark@Sun.COM * 15411042SErik.Nordmark@Sun.COM * If the IP header in packet is not 32-bit aligned, every message in the 15511042SErik.Nordmark@Sun.COM * chain will be aligned before further operations. This is required on SPARC 15611042SErik.Nordmark@Sun.COM * platform. 15711042SErik.Nordmark@Sun.COM */ 15811042SErik.Nordmark@Sun.COM void 15911042SErik.Nordmark@Sun.COM ip_input(ill_t *ill, ill_rx_ring_t *ip_ring, mblk_t *mp_chain, 16011042SErik.Nordmark@Sun.COM struct mac_header_info_s *mhip) 16111042SErik.Nordmark@Sun.COM { 16211042SErik.Nordmark@Sun.COM (void) ip_input_common_v4(ill, ip_ring, mp_chain, mhip, NULL, NULL, 16311042SErik.Nordmark@Sun.COM NULL); 16411042SErik.Nordmark@Sun.COM } 16511042SErik.Nordmark@Sun.COM 16611042SErik.Nordmark@Sun.COM /* 16711042SErik.Nordmark@Sun.COM * ip_accept_tcp() - This function is called by the squeue when it retrieves 16811042SErik.Nordmark@Sun.COM * a chain of packets in the poll mode. The packets have gone through the 16911042SErik.Nordmark@Sun.COM * data link processing but not IP processing. For performance and latency 17011042SErik.Nordmark@Sun.COM * reasons, the squeue wants to process the chain in line instead of feeding 17111042SErik.Nordmark@Sun.COM * it back via ip_input path. 17211042SErik.Nordmark@Sun.COM * 17311042SErik.Nordmark@Sun.COM * We set up the ip_recv_attr_t with IRAF_TARGET_SQP to that ip_fanout_v4 17411042SErik.Nordmark@Sun.COM * will pass back any TCP packets matching the target sqp to 17511042SErik.Nordmark@Sun.COM * ip_input_common_v4 using ira_target_sqp_mp. Other packets are handled by 17611042SErik.Nordmark@Sun.COM * ip_input_v4 and ip_fanout_v4 as normal. 17711042SErik.Nordmark@Sun.COM * The TCP packets that match the target squeue are returned to the caller 17811042SErik.Nordmark@Sun.COM * as a b_next chain after each packet has been prepend with an mblk 17911042SErik.Nordmark@Sun.COM * from ip_recv_attr_to_mblk. 18011042SErik.Nordmark@Sun.COM */ 18111042SErik.Nordmark@Sun.COM mblk_t * 18211042SErik.Nordmark@Sun.COM ip_accept_tcp(ill_t *ill, ill_rx_ring_t *ip_ring, squeue_t *target_sqp, 18311042SErik.Nordmark@Sun.COM mblk_t *mp_chain, mblk_t **last, uint_t *cnt) 18411042SErik.Nordmark@Sun.COM { 18511042SErik.Nordmark@Sun.COM return (ip_input_common_v4(ill, ip_ring, mp_chain, NULL, target_sqp, 18611042SErik.Nordmark@Sun.COM last, cnt)); 18711042SErik.Nordmark@Sun.COM } 18811042SErik.Nordmark@Sun.COM 18911042SErik.Nordmark@Sun.COM /* 19011042SErik.Nordmark@Sun.COM * Used by ip_input and ip_accept_tcp 19111042SErik.Nordmark@Sun.COM * The last three arguments are only used by ip_accept_tcp, and mhip is 19211042SErik.Nordmark@Sun.COM * only used by ip_input. 19311042SErik.Nordmark@Sun.COM */ 19411042SErik.Nordmark@Sun.COM mblk_t * 19511042SErik.Nordmark@Sun.COM ip_input_common_v4(ill_t *ill, ill_rx_ring_t *ip_ring, mblk_t *mp_chain, 19611042SErik.Nordmark@Sun.COM struct mac_header_info_s *mhip, squeue_t *target_sqp, 19711042SErik.Nordmark@Sun.COM mblk_t **last, uint_t *cnt) 19811042SErik.Nordmark@Sun.COM { 19911042SErik.Nordmark@Sun.COM mblk_t *mp; 20011042SErik.Nordmark@Sun.COM ipha_t *ipha; 20111042SErik.Nordmark@Sun.COM ip_recv_attr_t iras; /* Receive attributes */ 20211042SErik.Nordmark@Sun.COM rtc_t rtc; 20311042SErik.Nordmark@Sun.COM iaflags_t chain_flags = 0; /* Fixed for chain */ 20411042SErik.Nordmark@Sun.COM mblk_t *ahead = NULL; /* Accepted head */ 20511042SErik.Nordmark@Sun.COM mblk_t *atail = NULL; /* Accepted tail */ 20611042SErik.Nordmark@Sun.COM uint_t acnt = 0; /* Accepted count */ 20711042SErik.Nordmark@Sun.COM 20811042SErik.Nordmark@Sun.COM ASSERT(mp_chain != NULL); 20911042SErik.Nordmark@Sun.COM ASSERT(ill != NULL); 21011042SErik.Nordmark@Sun.COM 21111042SErik.Nordmark@Sun.COM /* These ones do not change as we loop over packets */ 21211042SErik.Nordmark@Sun.COM iras.ira_ill = iras.ira_rill = ill; 21311042SErik.Nordmark@Sun.COM iras.ira_ruifindex = ill->ill_phyint->phyint_ifindex; 21411042SErik.Nordmark@Sun.COM iras.ira_rifindex = iras.ira_ruifindex; 21511042SErik.Nordmark@Sun.COM iras.ira_sqp = NULL; 21611042SErik.Nordmark@Sun.COM iras.ira_ring = ip_ring; 21711042SErik.Nordmark@Sun.COM /* For ECMP and outbound transmit ring selection */ 21811042SErik.Nordmark@Sun.COM iras.ira_xmit_hint = ILL_RING_TO_XMIT_HINT(ip_ring); 21911042SErik.Nordmark@Sun.COM 22011042SErik.Nordmark@Sun.COM iras.ira_target_sqp = target_sqp; 22111042SErik.Nordmark@Sun.COM iras.ira_target_sqp_mp = NULL; 22211042SErik.Nordmark@Sun.COM if (target_sqp != NULL) 22311042SErik.Nordmark@Sun.COM chain_flags |= IRAF_TARGET_SQP; 22411042SErik.Nordmark@Sun.COM 22511042SErik.Nordmark@Sun.COM /* 22611042SErik.Nordmark@Sun.COM * We try to have a mhip pointer when possible, but 22711042SErik.Nordmark@Sun.COM * it might be NULL in some cases. In those cases we 22811042SErik.Nordmark@Sun.COM * have to assume unicast. 22911042SErik.Nordmark@Sun.COM */ 23011042SErik.Nordmark@Sun.COM iras.ira_mhip = mhip; 23111042SErik.Nordmark@Sun.COM iras.ira_flags = 0; 23211042SErik.Nordmark@Sun.COM if (mhip != NULL) { 23311042SErik.Nordmark@Sun.COM switch (mhip->mhi_dsttype) { 23411042SErik.Nordmark@Sun.COM case MAC_ADDRTYPE_MULTICAST : 23511042SErik.Nordmark@Sun.COM chain_flags |= IRAF_L2DST_MULTICAST; 23611042SErik.Nordmark@Sun.COM break; 23711042SErik.Nordmark@Sun.COM case MAC_ADDRTYPE_BROADCAST : 23811042SErik.Nordmark@Sun.COM chain_flags |= IRAF_L2DST_BROADCAST; 23911042SErik.Nordmark@Sun.COM break; 24011042SErik.Nordmark@Sun.COM } 24111042SErik.Nordmark@Sun.COM } 24211042SErik.Nordmark@Sun.COM 24311042SErik.Nordmark@Sun.COM /* 24411042SErik.Nordmark@Sun.COM * Initialize the one-element route cache. 24511042SErik.Nordmark@Sun.COM * 24611042SErik.Nordmark@Sun.COM * We do ire caching from one iteration to 24711042SErik.Nordmark@Sun.COM * another. In the event the packet chain contains 24811042SErik.Nordmark@Sun.COM * all packets from the same dst, this caching saves 24911042SErik.Nordmark@Sun.COM * an ire_route_recursive for each of the succeeding 25011042SErik.Nordmark@Sun.COM * packets in a packet chain. 25111042SErik.Nordmark@Sun.COM */ 25211042SErik.Nordmark@Sun.COM rtc.rtc_ire = NULL; 25311042SErik.Nordmark@Sun.COM rtc.rtc_ipaddr = INADDR_ANY; 25411042SErik.Nordmark@Sun.COM 25511042SErik.Nordmark@Sun.COM /* Loop over b_next */ 25611042SErik.Nordmark@Sun.COM for (mp = mp_chain; mp != NULL; mp = mp_chain) { 25711042SErik.Nordmark@Sun.COM mp_chain = mp->b_next; 25811042SErik.Nordmark@Sun.COM mp->b_next = NULL; 25911042SErik.Nordmark@Sun.COM 26011042SErik.Nordmark@Sun.COM ASSERT(DB_TYPE(mp) == M_DATA); 26111042SErik.Nordmark@Sun.COM 26211042SErik.Nordmark@Sun.COM 26311042SErik.Nordmark@Sun.COM /* 26411042SErik.Nordmark@Sun.COM * if db_ref > 1 then copymsg and free original. Packet 26511042SErik.Nordmark@Sun.COM * may be changed and we do not want the other entity 26611042SErik.Nordmark@Sun.COM * who has a reference to this message to trip over the 26711042SErik.Nordmark@Sun.COM * changes. This is a blind change because trying to 26811042SErik.Nordmark@Sun.COM * catch all places that might change the packet is too 26911042SErik.Nordmark@Sun.COM * difficult. 27011042SErik.Nordmark@Sun.COM * 27111042SErik.Nordmark@Sun.COM * This corresponds to the fast path case, where we have 27211042SErik.Nordmark@Sun.COM * a chain of M_DATA mblks. We check the db_ref count 27311042SErik.Nordmark@Sun.COM * of only the 1st data block in the mblk chain. There 27411042SErik.Nordmark@Sun.COM * doesn't seem to be a reason why a device driver would 27511042SErik.Nordmark@Sun.COM * send up data with varying db_ref counts in the mblk 27611042SErik.Nordmark@Sun.COM * chain. In any case the Fast path is a private 27711042SErik.Nordmark@Sun.COM * interface, and our drivers don't do such a thing. 27811042SErik.Nordmark@Sun.COM * Given the above assumption, there is no need to walk 27911042SErik.Nordmark@Sun.COM * down the entire mblk chain (which could have a 28011042SErik.Nordmark@Sun.COM * potential performance problem) 28111042SErik.Nordmark@Sun.COM * 28211042SErik.Nordmark@Sun.COM * The "(DB_REF(mp) > 1)" check was moved from ip_rput() 28311042SErik.Nordmark@Sun.COM * to here because of exclusive ip stacks and vnics. 28411042SErik.Nordmark@Sun.COM * Packets transmitted from exclusive stack over vnic 28511042SErik.Nordmark@Sun.COM * can have db_ref > 1 and when it gets looped back to 28611042SErik.Nordmark@Sun.COM * another vnic in a different zone, you have ip_input() 28711042SErik.Nordmark@Sun.COM * getting dblks with db_ref > 1. So if someone 28811042SErik.Nordmark@Sun.COM * complains of TCP performance under this scenario, 28911042SErik.Nordmark@Sun.COM * take a serious look here on the impact of copymsg(). 29011042SErik.Nordmark@Sun.COM */ 29111042SErik.Nordmark@Sun.COM if (DB_REF(mp) > 1) { 29211042SErik.Nordmark@Sun.COM if ((mp = ip_fix_dbref(mp, &iras)) == NULL) { 29311042SErik.Nordmark@Sun.COM /* mhip might point into 1st packet in chain */ 29411042SErik.Nordmark@Sun.COM iras.ira_mhip = NULL; 29511042SErik.Nordmark@Sun.COM continue; 29611042SErik.Nordmark@Sun.COM } 29711042SErik.Nordmark@Sun.COM } 29811042SErik.Nordmark@Sun.COM 29911042SErik.Nordmark@Sun.COM /* 30011042SErik.Nordmark@Sun.COM * IP header ptr not aligned? 30111042SErik.Nordmark@Sun.COM * OR IP header not complete in first mblk 30211042SErik.Nordmark@Sun.COM */ 30311042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr; 30411042SErik.Nordmark@Sun.COM if (!OK_32PTR(ipha) || MBLKL(mp) < IP_SIMPLE_HDR_LENGTH) { 30511042SErik.Nordmark@Sun.COM mp = ip_check_and_align_header(mp, IP_SIMPLE_HDR_LENGTH, 30611042SErik.Nordmark@Sun.COM &iras); 30711042SErik.Nordmark@Sun.COM if (mp == NULL) { 30811042SErik.Nordmark@Sun.COM /* mhip might point into 1st packet in chain */ 30911042SErik.Nordmark@Sun.COM iras.ira_mhip = NULL; 31011042SErik.Nordmark@Sun.COM continue; 31111042SErik.Nordmark@Sun.COM } 31211042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr; 31311042SErik.Nordmark@Sun.COM } 31411042SErik.Nordmark@Sun.COM 31511042SErik.Nordmark@Sun.COM /* Protect against a mix of Ethertypes and IP versions */ 31611042SErik.Nordmark@Sun.COM if (IPH_HDR_VERSION(ipha) != IPV4_VERSION) { 31711042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInHdrErrors); 31811042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInHdrErrors", 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 /* 32611042SErik.Nordmark@Sun.COM * Check for Martian addrs; we have to explicitly 32711042SErik.Nordmark@Sun.COM * test for for zero dst since this is also used as 32811042SErik.Nordmark@Sun.COM * an indication that the rtc is not used. 32911042SErik.Nordmark@Sun.COM */ 33011042SErik.Nordmark@Sun.COM if (ipha->ipha_dst == INADDR_ANY) { 33111042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInAddrErrors); 33211042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInAddrErrors", mp, ill); 33311042SErik.Nordmark@Sun.COM freemsg(mp); 33411042SErik.Nordmark@Sun.COM /* mhip might point into 1st packet in the chain. */ 33511042SErik.Nordmark@Sun.COM iras.ira_mhip = NULL; 33611042SErik.Nordmark@Sun.COM continue; 33711042SErik.Nordmark@Sun.COM } 33811042SErik.Nordmark@Sun.COM 33911042SErik.Nordmark@Sun.COM /* 34011042SErik.Nordmark@Sun.COM * Keep L2SRC from a previous packet in chain since mhip 34111042SErik.Nordmark@Sun.COM * might point into an earlier packet in the chain. 34211042SErik.Nordmark@Sun.COM * Keep IRAF_VERIFIED_SRC to avoid redoing broadcast 34311042SErik.Nordmark@Sun.COM * source check in forwarding path. 34411042SErik.Nordmark@Sun.COM */ 34511042SErik.Nordmark@Sun.COM chain_flags |= (iras.ira_flags & 34611042SErik.Nordmark@Sun.COM (IRAF_L2SRC_SET|IRAF_VERIFIED_SRC)); 34711042SErik.Nordmark@Sun.COM 34811042SErik.Nordmark@Sun.COM iras.ira_flags = IRAF_IS_IPV4 | IRAF_VERIFY_IP_CKSUM | 34911042SErik.Nordmark@Sun.COM IRAF_VERIFY_ULP_CKSUM | chain_flags; 35011042SErik.Nordmark@Sun.COM iras.ira_free_flags = 0; 35111042SErik.Nordmark@Sun.COM iras.ira_cred = NULL; 35211042SErik.Nordmark@Sun.COM iras.ira_cpid = NOPID; 35311042SErik.Nordmark@Sun.COM iras.ira_tsl = NULL; 35411042SErik.Nordmark@Sun.COM iras.ira_zoneid = ALL_ZONES; /* Default for forwarding */ 35511042SErik.Nordmark@Sun.COM 35611042SErik.Nordmark@Sun.COM /* 35711042SErik.Nordmark@Sun.COM * We must count all incoming packets, even if they end 35811042SErik.Nordmark@Sun.COM * up being dropped later on. Defer counting bytes until 35911042SErik.Nordmark@Sun.COM * we have the whole IP header in first mblk. 36011042SErik.Nordmark@Sun.COM */ 36111042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInReceives); 36211042SErik.Nordmark@Sun.COM 36311042SErik.Nordmark@Sun.COM iras.ira_pktlen = ntohs(ipha->ipha_length); 36411042SErik.Nordmark@Sun.COM UPDATE_MIB(ill->ill_ip_mib, ipIfStatsHCInOctets, 36511042SErik.Nordmark@Sun.COM iras.ira_pktlen); 36611042SErik.Nordmark@Sun.COM 36711042SErik.Nordmark@Sun.COM /* 36811042SErik.Nordmark@Sun.COM * Call one of: 36911042SErik.Nordmark@Sun.COM * ill_input_full_v4 37011042SErik.Nordmark@Sun.COM * ill_input_short_v4 37111042SErik.Nordmark@Sun.COM * The former is used in unusual cases. See ill_set_inputfn(). 37211042SErik.Nordmark@Sun.COM */ 37311042SErik.Nordmark@Sun.COM (*ill->ill_inputfn)(mp, ipha, &ipha->ipha_dst, &iras, &rtc); 37411042SErik.Nordmark@Sun.COM 37511042SErik.Nordmark@Sun.COM /* Any references to clean up? No hold on ira_ill */ 37611042SErik.Nordmark@Sun.COM if (iras.ira_flags & (IRAF_IPSEC_SECURE|IRAF_SYSTEM_LABELED)) 37711042SErik.Nordmark@Sun.COM ira_cleanup(&iras, B_FALSE); 37811042SErik.Nordmark@Sun.COM 37911042SErik.Nordmark@Sun.COM if (iras.ira_target_sqp_mp != NULL) { 38011042SErik.Nordmark@Sun.COM /* Better be called from ip_accept_tcp */ 38111042SErik.Nordmark@Sun.COM ASSERT(target_sqp != NULL); 38211042SErik.Nordmark@Sun.COM 38311042SErik.Nordmark@Sun.COM /* Found one packet to accept */ 38411042SErik.Nordmark@Sun.COM mp = iras.ira_target_sqp_mp; 38511042SErik.Nordmark@Sun.COM iras.ira_target_sqp_mp = NULL; 38611042SErik.Nordmark@Sun.COM ASSERT(ip_recv_attr_is_mblk(mp)); 38711042SErik.Nordmark@Sun.COM 38811042SErik.Nordmark@Sun.COM if (atail != NULL) 38911042SErik.Nordmark@Sun.COM atail->b_next = mp; 39011042SErik.Nordmark@Sun.COM else 39111042SErik.Nordmark@Sun.COM ahead = mp; 39211042SErik.Nordmark@Sun.COM atail = mp; 39311042SErik.Nordmark@Sun.COM acnt++; 39411042SErik.Nordmark@Sun.COM mp = NULL; 39511042SErik.Nordmark@Sun.COM } 39611042SErik.Nordmark@Sun.COM /* mhip might point into 1st packet in the chain. */ 39711042SErik.Nordmark@Sun.COM iras.ira_mhip = NULL; 39811042SErik.Nordmark@Sun.COM } 39911042SErik.Nordmark@Sun.COM /* Any remaining references to the route cache? */ 40011042SErik.Nordmark@Sun.COM if (rtc.rtc_ire != NULL) { 40111042SErik.Nordmark@Sun.COM ASSERT(rtc.rtc_ipaddr != INADDR_ANY); 40211042SErik.Nordmark@Sun.COM ire_refrele(rtc.rtc_ire); 40311042SErik.Nordmark@Sun.COM } 40411042SErik.Nordmark@Sun.COM 40511042SErik.Nordmark@Sun.COM if (ahead != NULL) { 40611042SErik.Nordmark@Sun.COM /* Better be called from ip_accept_tcp */ 40711042SErik.Nordmark@Sun.COM ASSERT(target_sqp != NULL); 40811042SErik.Nordmark@Sun.COM *last = atail; 40911042SErik.Nordmark@Sun.COM *cnt = acnt; 41011042SErik.Nordmark@Sun.COM return (ahead); 41111042SErik.Nordmark@Sun.COM } 41211042SErik.Nordmark@Sun.COM 41311042SErik.Nordmark@Sun.COM return (NULL); 41411042SErik.Nordmark@Sun.COM } 41511042SErik.Nordmark@Sun.COM 41611042SErik.Nordmark@Sun.COM /* 41711042SErik.Nordmark@Sun.COM * This input function is used when 41811042SErik.Nordmark@Sun.COM * - is_system_labeled() 41911042SErik.Nordmark@Sun.COM * - CGTP filtering 42011042SErik.Nordmark@Sun.COM * - DHCP unicast before we have an IP address configured 42111042SErik.Nordmark@Sun.COM * - there is an listener for IPPROTO_RSVP 42211042SErik.Nordmark@Sun.COM */ 42311042SErik.Nordmark@Sun.COM void 42411042SErik.Nordmark@Sun.COM ill_input_full_v4(mblk_t *mp, void *iph_arg, void *nexthop_arg, 42511042SErik.Nordmark@Sun.COM ip_recv_attr_t *ira, rtc_t *rtc) 42611042SErik.Nordmark@Sun.COM { 42711042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)iph_arg; 42811042SErik.Nordmark@Sun.COM ipaddr_t nexthop = *(ipaddr_t *)nexthop_arg; 42911042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_ill; 43011042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ill->ill_ipst; 43111042SErik.Nordmark@Sun.COM int cgtp_flt_pkt; 43211042SErik.Nordmark@Sun.COM 43311042SErik.Nordmark@Sun.COM ASSERT(ira->ira_tsl == NULL); 43411042SErik.Nordmark@Sun.COM 43511042SErik.Nordmark@Sun.COM /* 43611042SErik.Nordmark@Sun.COM * Attach any necessary label information to 43711042SErik.Nordmark@Sun.COM * this packet 43811042SErik.Nordmark@Sun.COM */ 43911042SErik.Nordmark@Sun.COM if (is_system_labeled()) { 44011042SErik.Nordmark@Sun.COM ira->ira_flags |= IRAF_SYSTEM_LABELED; 44111042SErik.Nordmark@Sun.COM 44211042SErik.Nordmark@Sun.COM /* 44311042SErik.Nordmark@Sun.COM * This updates ira_cred, ira_tsl and ira_free_flags based 44411042SErik.Nordmark@Sun.COM * on the label. 44511042SErik.Nordmark@Sun.COM */ 44611042SErik.Nordmark@Sun.COM if (!tsol_get_pkt_label(mp, IPV4_VERSION, ira)) { 44711042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 44811042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 44911042SErik.Nordmark@Sun.COM freemsg(mp); 45011042SErik.Nordmark@Sun.COM return; 45111042SErik.Nordmark@Sun.COM } 45211042SErik.Nordmark@Sun.COM /* Note that ira_tsl can be NULL here. */ 45311042SErik.Nordmark@Sun.COM 45411042SErik.Nordmark@Sun.COM /* tsol_get_pkt_label sometimes does pullupmsg */ 45511042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr; 45611042SErik.Nordmark@Sun.COM } 45711042SErik.Nordmark@Sun.COM 45811042SErik.Nordmark@Sun.COM /* 45911042SErik.Nordmark@Sun.COM * Invoke the CGTP (multirouting) filtering module to process 46011042SErik.Nordmark@Sun.COM * the incoming packet. Packets identified as duplicates 46111042SErik.Nordmark@Sun.COM * must be discarded. Filtering is active only if the 46211042SErik.Nordmark@Sun.COM * the ip_cgtp_filter ndd variable is non-zero. 46311042SErik.Nordmark@Sun.COM */ 46411042SErik.Nordmark@Sun.COM cgtp_flt_pkt = CGTP_IP_PKT_NOT_CGTP; 46511042SErik.Nordmark@Sun.COM if (ipst->ips_ip_cgtp_filter && 46611042SErik.Nordmark@Sun.COM ipst->ips_ip_cgtp_filter_ops != NULL) { 46711042SErik.Nordmark@Sun.COM netstackid_t stackid; 46811042SErik.Nordmark@Sun.COM 46911042SErik.Nordmark@Sun.COM stackid = ipst->ips_netstack->netstack_stackid; 47011042SErik.Nordmark@Sun.COM /* 47111042SErik.Nordmark@Sun.COM * CGTP and IPMP are mutually exclusive so 47211042SErik.Nordmark@Sun.COM * phyint_ifindex is fine here. 47311042SErik.Nordmark@Sun.COM */ 47411042SErik.Nordmark@Sun.COM cgtp_flt_pkt = 47511042SErik.Nordmark@Sun.COM ipst->ips_ip_cgtp_filter_ops->cfo_filter(stackid, 47611042SErik.Nordmark@Sun.COM ill->ill_phyint->phyint_ifindex, mp); 47711042SErik.Nordmark@Sun.COM if (cgtp_flt_pkt == CGTP_IP_PKT_DUPLICATE) { 47811042SErik.Nordmark@Sun.COM ip_drop_input("CGTP_IP_PKT_DUPLICATE", mp, ill); 47911042SErik.Nordmark@Sun.COM freemsg(mp); 48011042SErik.Nordmark@Sun.COM return; 48111042SErik.Nordmark@Sun.COM } 48211042SErik.Nordmark@Sun.COM } 48311042SErik.Nordmark@Sun.COM 48411042SErik.Nordmark@Sun.COM /* 48511042SErik.Nordmark@Sun.COM * Brutal hack for DHCPv4 unicast: RFC2131 allows a DHCP 48611042SErik.Nordmark@Sun.COM * server to unicast DHCP packets to a DHCP client using the 48711042SErik.Nordmark@Sun.COM * IP address it is offering to the client. This can be 48811042SErik.Nordmark@Sun.COM * disabled through the "broadcast bit", but not all DHCP 48911042SErik.Nordmark@Sun.COM * servers honor that bit. Therefore, to interoperate with as 49011042SErik.Nordmark@Sun.COM * many DHCP servers as possible, the DHCP client allows the 49111042SErik.Nordmark@Sun.COM * server to unicast, but we treat those packets as broadcast 49211042SErik.Nordmark@Sun.COM * here. Note that we don't rewrite the packet itself since 49311042SErik.Nordmark@Sun.COM * (a) that would mess up the checksums and (b) the DHCP 49411042SErik.Nordmark@Sun.COM * client conn is bound to INADDR_ANY so ip_fanout_udp() will 49511042SErik.Nordmark@Sun.COM * hand it the packet regardless. 49611042SErik.Nordmark@Sun.COM */ 49711042SErik.Nordmark@Sun.COM if (ill->ill_dhcpinit != 0 && 49811042SErik.Nordmark@Sun.COM ipha->ipha_version_and_hdr_length == IP_SIMPLE_HDR_VERSION && 49911042SErik.Nordmark@Sun.COM ipha->ipha_protocol == IPPROTO_UDP) { 50011042SErik.Nordmark@Sun.COM udpha_t *udpha; 50111042SErik.Nordmark@Sun.COM 50211042SErik.Nordmark@Sun.COM ipha = ip_pullup(mp, sizeof (ipha_t) + sizeof (udpha_t), ira); 50311042SErik.Nordmark@Sun.COM if (ipha == NULL) { 50411042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 50511042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards - dhcp", mp, ill); 50611042SErik.Nordmark@Sun.COM freemsg(mp); 50711042SErik.Nordmark@Sun.COM return; 50811042SErik.Nordmark@Sun.COM } 50911042SErik.Nordmark@Sun.COM /* Reload since pullupmsg() can change b_rptr. */ 51011042SErik.Nordmark@Sun.COM udpha = (udpha_t *)&ipha[1]; 51111042SErik.Nordmark@Sun.COM 51211042SErik.Nordmark@Sun.COM if (ntohs(udpha->uha_dst_port) == IPPORT_BOOTPC) { 51311042SErik.Nordmark@Sun.COM DTRACE_PROBE2(ip4__dhcpinit__pkt, ill_t *, ill, 51411042SErik.Nordmark@Sun.COM mblk_t *, mp); 51511042SErik.Nordmark@Sun.COM /* 51611042SErik.Nordmark@Sun.COM * This assumes that we deliver to all conns for 51711042SErik.Nordmark@Sun.COM * multicast and broadcast packets. 51811042SErik.Nordmark@Sun.COM */ 51911042SErik.Nordmark@Sun.COM nexthop = INADDR_BROADCAST; 52011042SErik.Nordmark@Sun.COM ira->ira_flags |= IRAF_DHCP_UNICAST; 52111042SErik.Nordmark@Sun.COM } 52211042SErik.Nordmark@Sun.COM } 52311042SErik.Nordmark@Sun.COM 52411042SErik.Nordmark@Sun.COM /* 52511042SErik.Nordmark@Sun.COM * If rsvpd is running, let RSVP daemon handle its processing 52611042SErik.Nordmark@Sun.COM * and forwarding of RSVP multicast/unicast packets. 52711042SErik.Nordmark@Sun.COM * If rsvpd is not running but mrouted is running, RSVP 52811042SErik.Nordmark@Sun.COM * multicast packets are forwarded as multicast traffic 52911042SErik.Nordmark@Sun.COM * and RSVP unicast packets are forwarded by unicast router. 53011042SErik.Nordmark@Sun.COM * If neither rsvpd nor mrouted is running, RSVP multicast 53111042SErik.Nordmark@Sun.COM * packets are not forwarded, but the unicast packets are 53211042SErik.Nordmark@Sun.COM * forwarded like unicast traffic. 53311042SErik.Nordmark@Sun.COM */ 53411042SErik.Nordmark@Sun.COM if (ipha->ipha_protocol == IPPROTO_RSVP && 53511042SErik.Nordmark@Sun.COM ipst->ips_ipcl_proto_fanout_v4[IPPROTO_RSVP].connf_head != NULL) { 53611042SErik.Nordmark@Sun.COM /* RSVP packet and rsvpd running. Treat as ours */ 53711042SErik.Nordmark@Sun.COM ip2dbg(("ip_input: RSVP for us: 0x%x\n", ntohl(nexthop))); 53811042SErik.Nordmark@Sun.COM /* 53911042SErik.Nordmark@Sun.COM * We use a multicast address to get the packet to 54011042SErik.Nordmark@Sun.COM * ire_recv_multicast_v4. There will not be a membership 54111042SErik.Nordmark@Sun.COM * check since we set IRAF_RSVP 54211042SErik.Nordmark@Sun.COM */ 54311042SErik.Nordmark@Sun.COM nexthop = htonl(INADDR_UNSPEC_GROUP); 54411042SErik.Nordmark@Sun.COM ira->ira_flags |= IRAF_RSVP; 54511042SErik.Nordmark@Sun.COM } 54611042SErik.Nordmark@Sun.COM 54711042SErik.Nordmark@Sun.COM ill_input_short_v4(mp, ipha, &nexthop, ira, rtc); 54811042SErik.Nordmark@Sun.COM } 54911042SErik.Nordmark@Sun.COM 55011042SErik.Nordmark@Sun.COM /* 55111042SErik.Nordmark@Sun.COM * This is the tail-end of the full receive side packet handling. 55211042SErik.Nordmark@Sun.COM * It can be used directly when the configuration is simple. 55311042SErik.Nordmark@Sun.COM */ 55411042SErik.Nordmark@Sun.COM void 55511042SErik.Nordmark@Sun.COM ill_input_short_v4(mblk_t *mp, void *iph_arg, void *nexthop_arg, 55611042SErik.Nordmark@Sun.COM ip_recv_attr_t *ira, rtc_t *rtc) 55711042SErik.Nordmark@Sun.COM { 55811042SErik.Nordmark@Sun.COM ire_t *ire; 55911042SErik.Nordmark@Sun.COM uint_t opt_len; 56011042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_ill; 56111042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ill->ill_ipst; 56211042SErik.Nordmark@Sun.COM uint_t pkt_len; 56311042SErik.Nordmark@Sun.COM ssize_t len; 56411042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)iph_arg; 56511042SErik.Nordmark@Sun.COM ipaddr_t nexthop = *(ipaddr_t *)nexthop_arg; 56611042SErik.Nordmark@Sun.COM ilb_stack_t *ilbs = ipst->ips_netstack->netstack_ilb; 56711042SErik.Nordmark@Sun.COM #define rptr ((uchar_t *)ipha) 56811042SErik.Nordmark@Sun.COM 56911042SErik.Nordmark@Sun.COM ASSERT(DB_TYPE(mp) == M_DATA); 57011042SErik.Nordmark@Sun.COM 57111042SErik.Nordmark@Sun.COM /* 57211042SErik.Nordmark@Sun.COM * The following test for loopback is faster than 57311042SErik.Nordmark@Sun.COM * IP_LOOPBACK_ADDR(), because it avoids any bitwise 57411042SErik.Nordmark@Sun.COM * operations. 57511042SErik.Nordmark@Sun.COM * Note that these addresses are always in network byte order 57611042SErik.Nordmark@Sun.COM */ 57711042SErik.Nordmark@Sun.COM if (((*(uchar_t *)&ipha->ipha_dst) == 127) || 57811042SErik.Nordmark@Sun.COM ((*(uchar_t *)&ipha->ipha_src) == 127)) { 57911042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInAddrErrors); 58011042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInAddrErrors", mp, ill); 58111042SErik.Nordmark@Sun.COM freemsg(mp); 58211042SErik.Nordmark@Sun.COM return; 58311042SErik.Nordmark@Sun.COM } 58411042SErik.Nordmark@Sun.COM 58511042SErik.Nordmark@Sun.COM len = mp->b_wptr - rptr; 58611042SErik.Nordmark@Sun.COM pkt_len = ira->ira_pktlen; 58711042SErik.Nordmark@Sun.COM 58811042SErik.Nordmark@Sun.COM /* multiple mblk or too short */ 58911042SErik.Nordmark@Sun.COM len -= pkt_len; 59011042SErik.Nordmark@Sun.COM if (len != 0) { 59111042SErik.Nordmark@Sun.COM mp = ip_check_length(mp, rptr, len, pkt_len, 59211042SErik.Nordmark@Sun.COM IP_SIMPLE_HDR_LENGTH, ira); 59311042SErik.Nordmark@Sun.COM if (mp == NULL) 59411042SErik.Nordmark@Sun.COM return; 59511042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr; 59611042SErik.Nordmark@Sun.COM } 59711042SErik.Nordmark@Sun.COM 59811042SErik.Nordmark@Sun.COM DTRACE_IP7(receive, mblk_t *, mp, conn_t *, NULL, void_ip_t *, 59911042SErik.Nordmark@Sun.COM ipha, __dtrace_ipsr_ill_t *, ill, ipha_t *, ipha, ip6_t *, NULL, 60011042SErik.Nordmark@Sun.COM int, 0); 60111042SErik.Nordmark@Sun.COM 60211042SErik.Nordmark@Sun.COM /* 60311042SErik.Nordmark@Sun.COM * The event for packets being received from a 'physical' 60411042SErik.Nordmark@Sun.COM * interface is placed after validation of the source and/or 60511042SErik.Nordmark@Sun.COM * destination address as being local so that packets can be 60611042SErik.Nordmark@Sun.COM * redirected to loopback addresses using ipnat. 60711042SErik.Nordmark@Sun.COM */ 60811042SErik.Nordmark@Sun.COM DTRACE_PROBE4(ip4__physical__in__start, 60911042SErik.Nordmark@Sun.COM ill_t *, ill, ill_t *, NULL, 61011042SErik.Nordmark@Sun.COM ipha_t *, ipha, mblk_t *, mp); 61111042SErik.Nordmark@Sun.COM 61211042SErik.Nordmark@Sun.COM if (HOOKS4_INTERESTED_PHYSICAL_IN(ipst)) { 61311042SErik.Nordmark@Sun.COM int ll_multicast = 0; 61411042SErik.Nordmark@Sun.COM int error; 61511042SErik.Nordmark@Sun.COM ipaddr_t orig_dst = ipha->ipha_dst; 61611042SErik.Nordmark@Sun.COM 61711042SErik.Nordmark@Sun.COM if (ira->ira_flags & IRAF_L2DST_MULTICAST) 61811042SErik.Nordmark@Sun.COM ll_multicast = HPE_MULTICAST; 61911042SErik.Nordmark@Sun.COM else if (ira->ira_flags & IRAF_L2DST_BROADCAST) 62011042SErik.Nordmark@Sun.COM ll_multicast = HPE_BROADCAST; 62111042SErik.Nordmark@Sun.COM 62211042SErik.Nordmark@Sun.COM FW_HOOKS(ipst->ips_ip4_physical_in_event, 62311042SErik.Nordmark@Sun.COM ipst->ips_ipv4firewall_physical_in, 62411042SErik.Nordmark@Sun.COM ill, NULL, ipha, mp, mp, ll_multicast, ipst, error); 62511042SErik.Nordmark@Sun.COM 62611042SErik.Nordmark@Sun.COM DTRACE_PROBE1(ip4__physical__in__end, mblk_t *, mp); 62711042SErik.Nordmark@Sun.COM 62811042SErik.Nordmark@Sun.COM if (mp == NULL) 62911042SErik.Nordmark@Sun.COM return; 63011042SErik.Nordmark@Sun.COM /* The length could have changed */ 63111042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr; 63211042SErik.Nordmark@Sun.COM ira->ira_pktlen = ntohs(ipha->ipha_length); 63311042SErik.Nordmark@Sun.COM pkt_len = ira->ira_pktlen; 63411042SErik.Nordmark@Sun.COM 63511042SErik.Nordmark@Sun.COM /* 63611042SErik.Nordmark@Sun.COM * In case the destination changed we override any previous 63711042SErik.Nordmark@Sun.COM * change to nexthop. 63811042SErik.Nordmark@Sun.COM */ 63911042SErik.Nordmark@Sun.COM if (orig_dst != ipha->ipha_dst) 64011042SErik.Nordmark@Sun.COM nexthop = ipha->ipha_dst; 64111042SErik.Nordmark@Sun.COM if (nexthop == INADDR_ANY) { 64211042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInAddrErrors); 64311042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInAddrErrors", mp, ill); 64411042SErik.Nordmark@Sun.COM freemsg(mp); 64511042SErik.Nordmark@Sun.COM return; 64611042SErik.Nordmark@Sun.COM } 64711042SErik.Nordmark@Sun.COM } 64811042SErik.Nordmark@Sun.COM 64911042SErik.Nordmark@Sun.COM if (ipst->ips_ip4_observe.he_interested) { 65011042SErik.Nordmark@Sun.COM zoneid_t dzone; 65111042SErik.Nordmark@Sun.COM 65211042SErik.Nordmark@Sun.COM /* 65311042SErik.Nordmark@Sun.COM * On the inbound path the src zone will be unknown as 65411042SErik.Nordmark@Sun.COM * this packet has come from the wire. 65511042SErik.Nordmark@Sun.COM */ 65611042SErik.Nordmark@Sun.COM dzone = ip_get_zoneid_v4(nexthop, mp, ira, ALL_ZONES); 65711042SErik.Nordmark@Sun.COM ipobs_hook(mp, IPOBS_HOOK_INBOUND, ALL_ZONES, dzone, ill, ipst); 65811042SErik.Nordmark@Sun.COM } 65911042SErik.Nordmark@Sun.COM 66011042SErik.Nordmark@Sun.COM /* 66111042SErik.Nordmark@Sun.COM * If there is a good HW IP header checksum we clear the need 66211042SErik.Nordmark@Sun.COM * look at the IP header checksum. 66311042SErik.Nordmark@Sun.COM */ 66411042SErik.Nordmark@Sun.COM if ((DB_CKSUMFLAGS(mp) & HCK_IPV4_HDRCKSUM) && 66511042SErik.Nordmark@Sun.COM ILL_HCKSUM_CAPABLE(ill) && dohwcksum) { 66611042SErik.Nordmark@Sun.COM /* Header checksum was ok. Clear the flag */ 66711042SErik.Nordmark@Sun.COM DB_CKSUMFLAGS(mp) &= ~HCK_IPV4_HDRCKSUM; 66811042SErik.Nordmark@Sun.COM ira->ira_flags &= ~IRAF_VERIFY_IP_CKSUM; 66911042SErik.Nordmark@Sun.COM } 67011042SErik.Nordmark@Sun.COM 67111042SErik.Nordmark@Sun.COM /* 67211042SErik.Nordmark@Sun.COM * Here we check to see if we machine is setup as 67311042SErik.Nordmark@Sun.COM * L3 loadbalancer and if the incoming packet is for a VIP 67411042SErik.Nordmark@Sun.COM * 67511042SErik.Nordmark@Sun.COM * Check the following: 67611042SErik.Nordmark@Sun.COM * - there is at least a rule 67711042SErik.Nordmark@Sun.COM * - protocol of the packet is supported 67811042SErik.Nordmark@Sun.COM */ 67911042SErik.Nordmark@Sun.COM if (ilb_has_rules(ilbs) && ILB_SUPP_L4(ipha->ipha_protocol)) { 68011042SErik.Nordmark@Sun.COM ipaddr_t lb_dst; 68111042SErik.Nordmark@Sun.COM int lb_ret; 68211042SErik.Nordmark@Sun.COM 68311042SErik.Nordmark@Sun.COM /* For convenience, we pull up the mblk. */ 68411042SErik.Nordmark@Sun.COM if (mp->b_cont != NULL) { 68511042SErik.Nordmark@Sun.COM if (pullupmsg(mp, -1) == 0) { 68611042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 68711042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards - pullupmsg", 68811042SErik.Nordmark@Sun.COM mp, ill); 68911042SErik.Nordmark@Sun.COM freemsg(mp); 69011042SErik.Nordmark@Sun.COM return; 69111042SErik.Nordmark@Sun.COM } 69211042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr; 69311042SErik.Nordmark@Sun.COM } 69411042SErik.Nordmark@Sun.COM 69511042SErik.Nordmark@Sun.COM /* 69611042SErik.Nordmark@Sun.COM * We just drop all fragments going to any VIP, at 69711042SErik.Nordmark@Sun.COM * least for now.... 69811042SErik.Nordmark@Sun.COM */ 69911042SErik.Nordmark@Sun.COM if (ntohs(ipha->ipha_fragment_offset_and_flags) & 70011042SErik.Nordmark@Sun.COM (IPH_MF | IPH_OFFSET)) { 70111042SErik.Nordmark@Sun.COM if (!ilb_rule_match_vip_v4(ilbs, nexthop, NULL)) { 70211042SErik.Nordmark@Sun.COM goto after_ilb; 70311042SErik.Nordmark@Sun.COM } 70411042SErik.Nordmark@Sun.COM 70511042SErik.Nordmark@Sun.COM ILB_KSTAT_UPDATE(ilbs, ip_frag_in, 1); 70611042SErik.Nordmark@Sun.COM ILB_KSTAT_UPDATE(ilbs, ip_frag_dropped, 1); 70711042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 70811042SErik.Nordmark@Sun.COM ip_drop_input("ILB fragment", mp, ill); 70911042SErik.Nordmark@Sun.COM freemsg(mp); 71011042SErik.Nordmark@Sun.COM return; 71111042SErik.Nordmark@Sun.COM } 71211042SErik.Nordmark@Sun.COM lb_ret = ilb_check_v4(ilbs, ill, mp, ipha, ipha->ipha_protocol, 71311042SErik.Nordmark@Sun.COM (uint8_t *)ipha + IPH_HDR_LENGTH(ipha), &lb_dst); 71411042SErik.Nordmark@Sun.COM 71511042SErik.Nordmark@Sun.COM if (lb_ret == ILB_DROPPED) { 71611042SErik.Nordmark@Sun.COM /* Is this the right counter to increase? */ 71711042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 71811042SErik.Nordmark@Sun.COM ip_drop_input("ILB_DROPPED", mp, ill); 71911042SErik.Nordmark@Sun.COM freemsg(mp); 72011042SErik.Nordmark@Sun.COM return; 72111042SErik.Nordmark@Sun.COM } 72211042SErik.Nordmark@Sun.COM if (lb_ret == ILB_BALANCED) { 72311042SErik.Nordmark@Sun.COM /* Set the dst to that of the chosen server */ 72411042SErik.Nordmark@Sun.COM nexthop = lb_dst; 72511042SErik.Nordmark@Sun.COM DB_CKSUMFLAGS(mp) = 0; 72611042SErik.Nordmark@Sun.COM } 72711042SErik.Nordmark@Sun.COM } 72811042SErik.Nordmark@Sun.COM 72911042SErik.Nordmark@Sun.COM after_ilb: 73011042SErik.Nordmark@Sun.COM opt_len = ipha->ipha_version_and_hdr_length - IP_SIMPLE_HDR_VERSION; 73111042SErik.Nordmark@Sun.COM ira->ira_ip_hdr_length = IP_SIMPLE_HDR_LENGTH; 73211042SErik.Nordmark@Sun.COM if (opt_len != 0) { 73311042SErik.Nordmark@Sun.COM int error = 0; 73411042SErik.Nordmark@Sun.COM 73511042SErik.Nordmark@Sun.COM ira->ira_ip_hdr_length += (opt_len << 2); 73611042SErik.Nordmark@Sun.COM ira->ira_flags |= IRAF_IPV4_OPTIONS; 73711042SErik.Nordmark@Sun.COM 73811042SErik.Nordmark@Sun.COM /* IP Options present! Validate the length. */ 73911042SErik.Nordmark@Sun.COM mp = ip_check_optlen(mp, ipha, opt_len, pkt_len, ira); 74011042SErik.Nordmark@Sun.COM if (mp == NULL) 74111042SErik.Nordmark@Sun.COM return; 74211042SErik.Nordmark@Sun.COM 74311042SErik.Nordmark@Sun.COM /* Might have changed */ 74411042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr; 74511042SErik.Nordmark@Sun.COM 74611042SErik.Nordmark@Sun.COM /* Verify IP header checksum before parsing the options */ 74711042SErik.Nordmark@Sun.COM if ((ira->ira_flags & IRAF_VERIFY_IP_CKSUM) && 74811042SErik.Nordmark@Sun.COM ip_csum_hdr(ipha)) { 74911042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInCksumErrs); 75011042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInCksumErrs", mp, ill); 75111042SErik.Nordmark@Sun.COM freemsg(mp); 75211042SErik.Nordmark@Sun.COM return; 75311042SErik.Nordmark@Sun.COM } 75411042SErik.Nordmark@Sun.COM ira->ira_flags &= ~IRAF_VERIFY_IP_CKSUM; 75511042SErik.Nordmark@Sun.COM 75611042SErik.Nordmark@Sun.COM /* 75711042SErik.Nordmark@Sun.COM * Go off to ip_input_options which returns the next hop 75811042SErik.Nordmark@Sun.COM * destination address, which may have been affected 75911042SErik.Nordmark@Sun.COM * by source routing. 76011042SErik.Nordmark@Sun.COM */ 76111042SErik.Nordmark@Sun.COM IP_STAT(ipst, ip_opt); 76211042SErik.Nordmark@Sun.COM 76311042SErik.Nordmark@Sun.COM nexthop = ip_input_options(ipha, nexthop, mp, ira, &error); 76411042SErik.Nordmark@Sun.COM if (error != 0) { 76511042SErik.Nordmark@Sun.COM /* 76611042SErik.Nordmark@Sun.COM * An ICMP error has been sent and the packet has 76711042SErik.Nordmark@Sun.COM * been dropped. 76811042SErik.Nordmark@Sun.COM */ 76911042SErik.Nordmark@Sun.COM return; 77011042SErik.Nordmark@Sun.COM } 77111042SErik.Nordmark@Sun.COM } 77211042SErik.Nordmark@Sun.COM /* Can not use route cache with TX since the labels can differ */ 77311042SErik.Nordmark@Sun.COM if (ira->ira_flags & IRAF_SYSTEM_LABELED) { 77411042SErik.Nordmark@Sun.COM if (CLASSD(nexthop)) { 77511042SErik.Nordmark@Sun.COM ire = ire_multicast(ill); 77611042SErik.Nordmark@Sun.COM } else { 77711042SErik.Nordmark@Sun.COM /* Match destination and label */ 77811042SErik.Nordmark@Sun.COM ire = ire_route_recursive_v4(nexthop, 0, NULL, 77911042SErik.Nordmark@Sun.COM ALL_ZONES, ira->ira_tsl, MATCH_IRE_SECATTR, 78011042SErik.Nordmark@Sun.COM (ill->ill_flags & ILLF_ROUTER), 78111042SErik.Nordmark@Sun.COM ira->ira_xmit_hint, ipst, NULL, NULL, NULL); 78211042SErik.Nordmark@Sun.COM } 78311042SErik.Nordmark@Sun.COM /* Update the route cache so we do the ire_refrele */ 78411042SErik.Nordmark@Sun.COM ASSERT(ire != NULL); 78511042SErik.Nordmark@Sun.COM if (rtc->rtc_ire != NULL) 78611042SErik.Nordmark@Sun.COM ire_refrele(rtc->rtc_ire); 78711042SErik.Nordmark@Sun.COM rtc->rtc_ire = ire; 78811042SErik.Nordmark@Sun.COM rtc->rtc_ipaddr = nexthop; 78911042SErik.Nordmark@Sun.COM } else if (nexthop == rtc->rtc_ipaddr) { 79011042SErik.Nordmark@Sun.COM /* Use the route cache */ 79111042SErik.Nordmark@Sun.COM ASSERT(rtc->rtc_ire != NULL); 79211042SErik.Nordmark@Sun.COM ire = rtc->rtc_ire; 79311042SErik.Nordmark@Sun.COM } else { 79411042SErik.Nordmark@Sun.COM /* Update the route cache */ 79511042SErik.Nordmark@Sun.COM if (CLASSD(nexthop)) { 79611042SErik.Nordmark@Sun.COM ire = ire_multicast(ill); 79711042SErik.Nordmark@Sun.COM } else { 79811042SErik.Nordmark@Sun.COM /* Just match the destination */ 79911042SErik.Nordmark@Sun.COM ire = ire_route_recursive_dstonly_v4(nexthop, 80011042SErik.Nordmark@Sun.COM (ill->ill_flags & ILLF_ROUTER), ira->ira_xmit_hint, 80111042SErik.Nordmark@Sun.COM ipst); 80211042SErik.Nordmark@Sun.COM } 80311042SErik.Nordmark@Sun.COM ASSERT(ire != NULL); 80411042SErik.Nordmark@Sun.COM if (rtc->rtc_ire != NULL) 80511042SErik.Nordmark@Sun.COM ire_refrele(rtc->rtc_ire); 80611042SErik.Nordmark@Sun.COM rtc->rtc_ire = ire; 80711042SErik.Nordmark@Sun.COM rtc->rtc_ipaddr = nexthop; 80811042SErik.Nordmark@Sun.COM } 80911042SErik.Nordmark@Sun.COM 81011042SErik.Nordmark@Sun.COM ire->ire_ib_pkt_count++; 81111042SErik.Nordmark@Sun.COM 81211042SErik.Nordmark@Sun.COM /* 81311042SErik.Nordmark@Sun.COM * Based on ire_type and ire_flags call one of: 81411042SErik.Nordmark@Sun.COM * ire_recv_local_v4 - for IRE_LOCAL 81511042SErik.Nordmark@Sun.COM * ire_recv_loopback_v4 - for IRE_LOOPBACK 81611042SErik.Nordmark@Sun.COM * ire_recv_multirt_v4 - if RTF_MULTIRT 81711042SErik.Nordmark@Sun.COM * ire_recv_noroute_v4 - if RTF_REJECT or RTF_BLACHOLE 81811042SErik.Nordmark@Sun.COM * ire_recv_multicast_v4 - for IRE_MULTICAST 81911042SErik.Nordmark@Sun.COM * ire_recv_broadcast_v4 - for IRE_BROADCAST 82011042SErik.Nordmark@Sun.COM * ire_recv_noaccept_v4 - for ire_noaccept ones 82111042SErik.Nordmark@Sun.COM * ire_recv_forward_v4 - for the rest. 82211042SErik.Nordmark@Sun.COM */ 82311042SErik.Nordmark@Sun.COM (*ire->ire_recvfn)(ire, mp, ipha, ira); 82411042SErik.Nordmark@Sun.COM } 82511042SErik.Nordmark@Sun.COM #undef rptr 82611042SErik.Nordmark@Sun.COM 82711042SErik.Nordmark@Sun.COM /* 82811042SErik.Nordmark@Sun.COM * ire_recvfn for IREs that need forwarding 82911042SErik.Nordmark@Sun.COM */ 83011042SErik.Nordmark@Sun.COM void 83111042SErik.Nordmark@Sun.COM ire_recv_forward_v4(ire_t *ire, mblk_t *mp, void *iph_arg, ip_recv_attr_t *ira) 83211042SErik.Nordmark@Sun.COM { 83311042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)iph_arg; 83411042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_ill; 83511042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ill->ill_ipst; 83611042SErik.Nordmark@Sun.COM ill_t *dst_ill; 83711042SErik.Nordmark@Sun.COM nce_t *nce; 83811042SErik.Nordmark@Sun.COM ipaddr_t src = ipha->ipha_src; 83911042SErik.Nordmark@Sun.COM uint32_t added_tx_len; 84011042SErik.Nordmark@Sun.COM uint32_t mtu, iremtu; 84111042SErik.Nordmark@Sun.COM 84211042SErik.Nordmark@Sun.COM if (ira->ira_flags & (IRAF_L2DST_MULTICAST|IRAF_L2DST_BROADCAST)) { 84311042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits); 84411042SErik.Nordmark@Sun.COM ip_drop_input("l2 multicast not forwarded", mp, ill); 84511042SErik.Nordmark@Sun.COM freemsg(mp); 84611042SErik.Nordmark@Sun.COM return; 84711042SErik.Nordmark@Sun.COM } 84811042SErik.Nordmark@Sun.COM 84911042SErik.Nordmark@Sun.COM if (!(ill->ill_flags & ILLF_ROUTER) && !ip_source_routed(ipha, ipst)) { 85011042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits); 85111042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsForwProhibits", mp, ill); 85211042SErik.Nordmark@Sun.COM freemsg(mp); 85311042SErik.Nordmark@Sun.COM return; 85411042SErik.Nordmark@Sun.COM } 85511042SErik.Nordmark@Sun.COM 85611042SErik.Nordmark@Sun.COM /* 85711042SErik.Nordmark@Sun.COM * Either ire_nce_capable or ire_dep_parent would be set for the IRE 85811042SErik.Nordmark@Sun.COM * when it is found by ire_route_recursive, but that some other thread 85911042SErik.Nordmark@Sun.COM * could have changed the routes with the effect of clearing 86011042SErik.Nordmark@Sun.COM * ire_dep_parent. In that case we'd end up dropping the packet, or 86111042SErik.Nordmark@Sun.COM * finding a new nce below. 86211042SErik.Nordmark@Sun.COM * Get, allocate, or update the nce. 86311042SErik.Nordmark@Sun.COM * We get a refhold on ire_nce_cache as a result of this to avoid races 86411042SErik.Nordmark@Sun.COM * where ire_nce_cache is deleted. 86511042SErik.Nordmark@Sun.COM * 86611042SErik.Nordmark@Sun.COM * This ensures that we don't forward if the interface is down since 86711042SErik.Nordmark@Sun.COM * ipif_down removes all the nces. 86811042SErik.Nordmark@Sun.COM */ 86911042SErik.Nordmark@Sun.COM mutex_enter(&ire->ire_lock); 87011042SErik.Nordmark@Sun.COM nce = ire->ire_nce_cache; 87111042SErik.Nordmark@Sun.COM if (nce == NULL) { 87211042SErik.Nordmark@Sun.COM /* Not yet set up - try to set one up */ 87311042SErik.Nordmark@Sun.COM mutex_exit(&ire->ire_lock); 87411042SErik.Nordmark@Sun.COM (void) ire_revalidate_nce(ire); 87511042SErik.Nordmark@Sun.COM mutex_enter(&ire->ire_lock); 87611042SErik.Nordmark@Sun.COM nce = ire->ire_nce_cache; 87711042SErik.Nordmark@Sun.COM if (nce == NULL) { 87811042SErik.Nordmark@Sun.COM mutex_exit(&ire->ire_lock); 87911042SErik.Nordmark@Sun.COM /* The ire_dep_parent chain went bad, or no memory */ 88011042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 88111042SErik.Nordmark@Sun.COM ip_drop_input("No ire_dep_parent", mp, ill); 88211042SErik.Nordmark@Sun.COM freemsg(mp); 88311042SErik.Nordmark@Sun.COM return; 88411042SErik.Nordmark@Sun.COM } 88511042SErik.Nordmark@Sun.COM } 88611042SErik.Nordmark@Sun.COM nce_refhold(nce); 88711042SErik.Nordmark@Sun.COM mutex_exit(&ire->ire_lock); 88811042SErik.Nordmark@Sun.COM 88911042SErik.Nordmark@Sun.COM if (nce->nce_is_condemned) { 89011042SErik.Nordmark@Sun.COM nce_t *nce1; 89111042SErik.Nordmark@Sun.COM 89211042SErik.Nordmark@Sun.COM nce1 = ire_handle_condemned_nce(nce, ire, ipha, NULL, B_FALSE); 89311042SErik.Nordmark@Sun.COM nce_refrele(nce); 89411042SErik.Nordmark@Sun.COM if (nce1 == NULL) { 89511042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 89611042SErik.Nordmark@Sun.COM ip_drop_input("No nce", mp, ill); 89711042SErik.Nordmark@Sun.COM freemsg(mp); 89811042SErik.Nordmark@Sun.COM return; 89911042SErik.Nordmark@Sun.COM } 90011042SErik.Nordmark@Sun.COM nce = nce1; 90111042SErik.Nordmark@Sun.COM } 90211042SErik.Nordmark@Sun.COM dst_ill = nce->nce_ill; 90311042SErik.Nordmark@Sun.COM 90411042SErik.Nordmark@Sun.COM /* 90511042SErik.Nordmark@Sun.COM * Unless we are forwarding, drop the packet. 90611042SErik.Nordmark@Sun.COM * We have to let source routed packets through if they go out 90711042SErik.Nordmark@Sun.COM * the same interface i.e., they are 'ping -l' packets. 90811042SErik.Nordmark@Sun.COM */ 90911042SErik.Nordmark@Sun.COM if (!(dst_ill->ill_flags & ILLF_ROUTER) && 91011042SErik.Nordmark@Sun.COM !(ip_source_routed(ipha, ipst) && dst_ill == ill)) { 91111042SErik.Nordmark@Sun.COM if (ip_source_routed(ipha, ipst)) { 91211042SErik.Nordmark@Sun.COM ip_drop_input("ICMP_SOURCE_ROUTE_FAILED", mp, ill); 91311042SErik.Nordmark@Sun.COM icmp_unreachable(mp, ICMP_SOURCE_ROUTE_FAILED, ira); 91411042SErik.Nordmark@Sun.COM nce_refrele(nce); 91511042SErik.Nordmark@Sun.COM return; 91611042SErik.Nordmark@Sun.COM } 91711042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits); 91811042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsForwProhibits", mp, ill); 91911042SErik.Nordmark@Sun.COM freemsg(mp); 92011042SErik.Nordmark@Sun.COM nce_refrele(nce); 92111042SErik.Nordmark@Sun.COM return; 92211042SErik.Nordmark@Sun.COM } 92311042SErik.Nordmark@Sun.COM 92411042SErik.Nordmark@Sun.COM if (ire->ire_zoneid != GLOBAL_ZONEID && ire->ire_zoneid != ALL_ZONES) { 92511042SErik.Nordmark@Sun.COM ipaddr_t dst = ipha->ipha_dst; 92611042SErik.Nordmark@Sun.COM 92711042SErik.Nordmark@Sun.COM ire->ire_ib_pkt_count--; 92811042SErik.Nordmark@Sun.COM /* 92911042SErik.Nordmark@Sun.COM * Should only use IREs that are visible from the 93011042SErik.Nordmark@Sun.COM * global zone for forwarding. 93111042SErik.Nordmark@Sun.COM * Take a source route into account the same way as ip_input 93211042SErik.Nordmark@Sun.COM * did. 93311042SErik.Nordmark@Sun.COM */ 93411042SErik.Nordmark@Sun.COM if (ira->ira_flags & IRAF_IPV4_OPTIONS) { 93511042SErik.Nordmark@Sun.COM int error = 0; 93611042SErik.Nordmark@Sun.COM 93711042SErik.Nordmark@Sun.COM dst = ip_input_options(ipha, dst, mp, ira, &error); 93811042SErik.Nordmark@Sun.COM ASSERT(error == 0); /* ip_input checked */ 93911042SErik.Nordmark@Sun.COM } 94011042SErik.Nordmark@Sun.COM ire = ire_route_recursive_v4(dst, 0, NULL, GLOBAL_ZONEID, 94111042SErik.Nordmark@Sun.COM ira->ira_tsl, MATCH_IRE_SECATTR, 94211042SErik.Nordmark@Sun.COM (ill->ill_flags & ILLF_ROUTER), ira->ira_xmit_hint, ipst, 94311042SErik.Nordmark@Sun.COM NULL, NULL, NULL); 94411042SErik.Nordmark@Sun.COM ire->ire_ib_pkt_count++; 94511042SErik.Nordmark@Sun.COM (*ire->ire_recvfn)(ire, mp, ipha, ira); 94611042SErik.Nordmark@Sun.COM ire_refrele(ire); 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 * ipIfStatsHCInForwDatagrams should only be increment if there 95311042SErik.Nordmark@Sun.COM * will be an attempt to forward the packet, which is why we 95411042SErik.Nordmark@Sun.COM * increment after the above condition has been checked. 95511042SErik.Nordmark@Sun.COM */ 95611042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInForwDatagrams); 95711042SErik.Nordmark@Sun.COM 95811042SErik.Nordmark@Sun.COM /* Initiate Read side IPPF processing */ 95911042SErik.Nordmark@Sun.COM if (IPP_ENABLED(IPP_FWD_IN, ipst)) { 96011042SErik.Nordmark@Sun.COM /* ip_process translates an IS_UNDER_IPMP */ 96111042SErik.Nordmark@Sun.COM mp = ip_process(IPP_FWD_IN, mp, ill, ill); 96211042SErik.Nordmark@Sun.COM if (mp == NULL) { 96311042SErik.Nordmark@Sun.COM /* ip_drop_packet and MIB done */ 96411042SErik.Nordmark@Sun.COM ip2dbg(("ire_recv_forward_v4: pkt dropped/deferred " 96511042SErik.Nordmark@Sun.COM "during IPPF processing\n")); 96611042SErik.Nordmark@Sun.COM nce_refrele(nce); 96711042SErik.Nordmark@Sun.COM return; 96811042SErik.Nordmark@Sun.COM } 96911042SErik.Nordmark@Sun.COM } 97011042SErik.Nordmark@Sun.COM 97111042SErik.Nordmark@Sun.COM DTRACE_PROBE4(ip4__forwarding__start, 97211042SErik.Nordmark@Sun.COM ill_t *, ill, ill_t *, dst_ill, ipha_t *, ipha, mblk_t *, mp); 97311042SErik.Nordmark@Sun.COM 97411042SErik.Nordmark@Sun.COM if (HOOKS4_INTERESTED_FORWARDING(ipst)) { 97511042SErik.Nordmark@Sun.COM int error; 97611042SErik.Nordmark@Sun.COM 97711042SErik.Nordmark@Sun.COM FW_HOOKS(ipst->ips_ip4_forwarding_event, 97811042SErik.Nordmark@Sun.COM ipst->ips_ipv4firewall_forwarding, 97911042SErik.Nordmark@Sun.COM ill, dst_ill, ipha, mp, mp, 0, ipst, error); 98011042SErik.Nordmark@Sun.COM 98111042SErik.Nordmark@Sun.COM DTRACE_PROBE1(ip4__forwarding__end, mblk_t *, mp); 98211042SErik.Nordmark@Sun.COM 98311042SErik.Nordmark@Sun.COM if (mp == NULL) { 98411042SErik.Nordmark@Sun.COM nce_refrele(nce); 98511042SErik.Nordmark@Sun.COM return; 98611042SErik.Nordmark@Sun.COM } 98711042SErik.Nordmark@Sun.COM /* 98811042SErik.Nordmark@Sun.COM * Even if the destination was changed by the filter we use the 98911042SErik.Nordmark@Sun.COM * forwarding decision that was made based on the address 99011042SErik.Nordmark@Sun.COM * in ip_input. 99111042SErik.Nordmark@Sun.COM */ 99211042SErik.Nordmark@Sun.COM 99311042SErik.Nordmark@Sun.COM /* Might have changed */ 99411042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr; 99511042SErik.Nordmark@Sun.COM ira->ira_pktlen = ntohs(ipha->ipha_length); 99611042SErik.Nordmark@Sun.COM } 99711042SErik.Nordmark@Sun.COM 99811042SErik.Nordmark@Sun.COM /* Packet is being forwarded. Turning off hwcksum flag. */ 99911042SErik.Nordmark@Sun.COM DB_CKSUMFLAGS(mp) = 0; 100011042SErik.Nordmark@Sun.COM 100111042SErik.Nordmark@Sun.COM /* 100211042SErik.Nordmark@Sun.COM * Martian Address Filtering [RFC 1812, Section 5.3.7] 100311042SErik.Nordmark@Sun.COM * The loopback address check for both src and dst has already 100411042SErik.Nordmark@Sun.COM * been checked in ip_input 100511042SErik.Nordmark@Sun.COM * In the future one can envision adding RPF checks using number 3. 100611042SErik.Nordmark@Sun.COM * If we already checked the same source address we can skip this. 100711042SErik.Nordmark@Sun.COM */ 100811042SErik.Nordmark@Sun.COM if (!(ira->ira_flags & IRAF_VERIFIED_SRC) || 100911042SErik.Nordmark@Sun.COM src != ira->ira_verified_src) { 101011042SErik.Nordmark@Sun.COM switch (ipst->ips_src_check) { 101111042SErik.Nordmark@Sun.COM case 0: 101211042SErik.Nordmark@Sun.COM break; 101311042SErik.Nordmark@Sun.COM case 2: 101411042SErik.Nordmark@Sun.COM if (ip_type_v4(src, ipst) == IRE_BROADCAST) { 101511042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, 101611042SErik.Nordmark@Sun.COM ipIfStatsForwProhibits); 101711042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, 101811042SErik.Nordmark@Sun.COM 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 /* FALLTHRU */ 102511042SErik.Nordmark@Sun.COM 102611042SErik.Nordmark@Sun.COM case 1: 102711042SErik.Nordmark@Sun.COM if (CLASSD(src)) { 102811042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, 102911042SErik.Nordmark@Sun.COM ipIfStatsForwProhibits); 103011042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, 103111042SErik.Nordmark@Sun.COM ipIfStatsInAddrErrors); 103211042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInAddrErrors", mp, ill); 103311042SErik.Nordmark@Sun.COM freemsg(mp); 103411042SErik.Nordmark@Sun.COM nce_refrele(nce); 103511042SErik.Nordmark@Sun.COM return; 103611042SErik.Nordmark@Sun.COM } 103711042SErik.Nordmark@Sun.COM break; 103811042SErik.Nordmark@Sun.COM } 103911042SErik.Nordmark@Sun.COM /* Remember for next packet */ 104011042SErik.Nordmark@Sun.COM ira->ira_flags |= IRAF_VERIFIED_SRC; 104111042SErik.Nordmark@Sun.COM ira->ira_verified_src = src; 104211042SErik.Nordmark@Sun.COM } 104311042SErik.Nordmark@Sun.COM 104411042SErik.Nordmark@Sun.COM /* 104511042SErik.Nordmark@Sun.COM * Check if packet is going out the same link on which it arrived. 104611042SErik.Nordmark@Sun.COM * Means we might need to send a redirect. 104711042SErik.Nordmark@Sun.COM */ 104811042SErik.Nordmark@Sun.COM if (IS_ON_SAME_LAN(dst_ill, ill) && ipst->ips_ip_g_send_redirects) { 104911042SErik.Nordmark@Sun.COM ip_send_potential_redirect_v4(mp, ipha, ire, ira); 105011042SErik.Nordmark@Sun.COM } 105111042SErik.Nordmark@Sun.COM 105211042SErik.Nordmark@Sun.COM added_tx_len = 0; 105311042SErik.Nordmark@Sun.COM if (ira->ira_flags & IRAF_SYSTEM_LABELED) { 105411042SErik.Nordmark@Sun.COM mblk_t *mp1; 105511042SErik.Nordmark@Sun.COM uint32_t old_pkt_len = ira->ira_pktlen; 105611042SErik.Nordmark@Sun.COM 1057*11362SErik.Nordmark@Sun.COM /* Verify IP header checksum before adding/removing options */ 1058*11362SErik.Nordmark@Sun.COM if ((ira->ira_flags & IRAF_VERIFY_IP_CKSUM) && 1059*11362SErik.Nordmark@Sun.COM ip_csum_hdr(ipha)) { 1060*11362SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInCksumErrs); 1061*11362SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInCksumErrs", mp, ill); 1062*11362SErik.Nordmark@Sun.COM freemsg(mp); 1063*11362SErik.Nordmark@Sun.COM nce_refrele(nce); 1064*11362SErik.Nordmark@Sun.COM return; 1065*11362SErik.Nordmark@Sun.COM } 1066*11362SErik.Nordmark@Sun.COM ira->ira_flags &= ~IRAF_VERIFY_IP_CKSUM; 1067*11362SErik.Nordmark@Sun.COM 106811042SErik.Nordmark@Sun.COM /* 106911042SErik.Nordmark@Sun.COM * Check if it can be forwarded and add/remove 107011042SErik.Nordmark@Sun.COM * CIPSO options as needed. 107111042SErik.Nordmark@Sun.COM */ 107211042SErik.Nordmark@Sun.COM if ((mp1 = tsol_ip_forward(ire, mp, ira)) == NULL) { 107311042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits); 107411042SErik.Nordmark@Sun.COM ip_drop_input("tsol_ip_forward", mp, ill); 107511042SErik.Nordmark@Sun.COM freemsg(mp); 107611042SErik.Nordmark@Sun.COM nce_refrele(nce); 107711042SErik.Nordmark@Sun.COM return; 107811042SErik.Nordmark@Sun.COM } 107911042SErik.Nordmark@Sun.COM /* 108011042SErik.Nordmark@Sun.COM * Size may have changed. Remember amount added in case 108111042SErik.Nordmark@Sun.COM * IP needs to send an ICMP too big. 108211042SErik.Nordmark@Sun.COM */ 108311042SErik.Nordmark@Sun.COM mp = mp1; 108411042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr; 108511042SErik.Nordmark@Sun.COM ira->ira_pktlen = ntohs(ipha->ipha_length); 108611042SErik.Nordmark@Sun.COM ira->ira_ip_hdr_length = IPH_HDR_LENGTH(ipha); 108711042SErik.Nordmark@Sun.COM if (ira->ira_pktlen > old_pkt_len) 108811042SErik.Nordmark@Sun.COM added_tx_len = ira->ira_pktlen - old_pkt_len; 108911042SErik.Nordmark@Sun.COM 109011042SErik.Nordmark@Sun.COM /* Options can have been added or removed */ 109111042SErik.Nordmark@Sun.COM if (ira->ira_ip_hdr_length != IP_SIMPLE_HDR_LENGTH) 109211042SErik.Nordmark@Sun.COM ira->ira_flags |= IRAF_IPV4_OPTIONS; 109311042SErik.Nordmark@Sun.COM else 109411042SErik.Nordmark@Sun.COM ira->ira_flags &= ~IRAF_IPV4_OPTIONS; 109511042SErik.Nordmark@Sun.COM } 109611042SErik.Nordmark@Sun.COM 109711042SErik.Nordmark@Sun.COM mtu = dst_ill->ill_mtu; 109811042SErik.Nordmark@Sun.COM if ((iremtu = ire->ire_metrics.iulp_mtu) != 0 && iremtu < mtu) 109911042SErik.Nordmark@Sun.COM mtu = iremtu; 110011042SErik.Nordmark@Sun.COM ip_forward_xmit_v4(nce, ill, mp, ipha, ira, mtu, added_tx_len); 110111042SErik.Nordmark@Sun.COM nce_refrele(nce); 110211042SErik.Nordmark@Sun.COM } 110311042SErik.Nordmark@Sun.COM 110411042SErik.Nordmark@Sun.COM /* 110511042SErik.Nordmark@Sun.COM * Used for sending out unicast and multicast packets that are 110611042SErik.Nordmark@Sun.COM * forwarded. 110711042SErik.Nordmark@Sun.COM */ 110811042SErik.Nordmark@Sun.COM void 110911042SErik.Nordmark@Sun.COM ip_forward_xmit_v4(nce_t *nce, ill_t *ill, mblk_t *mp, ipha_t *ipha, 111011042SErik.Nordmark@Sun.COM ip_recv_attr_t *ira, uint32_t mtu, uint32_t added_tx_len) 111111042SErik.Nordmark@Sun.COM { 111211042SErik.Nordmark@Sun.COM ill_t *dst_ill = nce->nce_ill; 111311042SErik.Nordmark@Sun.COM uint32_t pkt_len; 111411042SErik.Nordmark@Sun.COM uint32_t sum; 111511042SErik.Nordmark@Sun.COM iaflags_t iraflags = ira->ira_flags; 111611042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ill->ill_ipst; 111711042SErik.Nordmark@Sun.COM iaflags_t ixaflags; 111811042SErik.Nordmark@Sun.COM 111911042SErik.Nordmark@Sun.COM if (ipha->ipha_ttl <= 1) { 112011042SErik.Nordmark@Sun.COM /* Perhaps the checksum was bad */ 112111042SErik.Nordmark@Sun.COM if ((iraflags & IRAF_VERIFY_IP_CKSUM) && ip_csum_hdr(ipha)) { 112211042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInCksumErrs); 112311042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInCksumErrs", mp, ill); 112411042SErik.Nordmark@Sun.COM freemsg(mp); 112511042SErik.Nordmark@Sun.COM return; 112611042SErik.Nordmark@Sun.COM } 112711042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 112811042SErik.Nordmark@Sun.COM ip_drop_input("ICMP_TTL_EXCEEDED", mp, ill); 112911042SErik.Nordmark@Sun.COM icmp_time_exceeded(mp, ICMP_TTL_EXCEEDED, ira); 113011042SErik.Nordmark@Sun.COM return; 113111042SErik.Nordmark@Sun.COM } 113211042SErik.Nordmark@Sun.COM ipha->ipha_ttl--; 113311042SErik.Nordmark@Sun.COM /* Adjust the checksum to reflect the ttl decrement. */ 113411042SErik.Nordmark@Sun.COM sum = (int)ipha->ipha_hdr_checksum + IP_HDR_CSUM_TTL_ADJUST; 113511042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = (uint16_t)(sum + (sum >> 16)); 113611042SErik.Nordmark@Sun.COM 113711042SErik.Nordmark@Sun.COM /* Check if there are options to update */ 113811042SErik.Nordmark@Sun.COM if (iraflags & IRAF_IPV4_OPTIONS) { 113911042SErik.Nordmark@Sun.COM ASSERT(ipha->ipha_version_and_hdr_length != 114011042SErik.Nordmark@Sun.COM IP_SIMPLE_HDR_VERSION); 114111042SErik.Nordmark@Sun.COM ASSERT(!(iraflags & IRAF_VERIFY_IP_CKSUM)); 114211042SErik.Nordmark@Sun.COM 114311042SErik.Nordmark@Sun.COM if (!ip_forward_options(mp, ipha, dst_ill, ira)) { 114411042SErik.Nordmark@Sun.COM /* ipIfStatsForwProhibits and ip_drop_input done */ 114511042SErik.Nordmark@Sun.COM return; 114611042SErik.Nordmark@Sun.COM } 114711042SErik.Nordmark@Sun.COM 114811042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = 0; 114911042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = ip_csum_hdr(ipha); 115011042SErik.Nordmark@Sun.COM } 115111042SErik.Nordmark@Sun.COM 115211042SErik.Nordmark@Sun.COM /* Initiate Write side IPPF processing before any fragmentation */ 115311042SErik.Nordmark@Sun.COM if (IPP_ENABLED(IPP_FWD_OUT, ipst)) { 115411042SErik.Nordmark@Sun.COM /* ip_process translates an IS_UNDER_IPMP */ 115511042SErik.Nordmark@Sun.COM mp = ip_process(IPP_FWD_OUT, mp, dst_ill, dst_ill); 115611042SErik.Nordmark@Sun.COM if (mp == NULL) { 115711042SErik.Nordmark@Sun.COM /* ip_drop_packet and MIB done */ 115811042SErik.Nordmark@Sun.COM ip2dbg(("ire_recv_forward_v4: pkt dropped/deferred" \ 115911042SErik.Nordmark@Sun.COM " during IPPF processing\n")); 116011042SErik.Nordmark@Sun.COM return; 116111042SErik.Nordmark@Sun.COM } 116211042SErik.Nordmark@Sun.COM } 116311042SErik.Nordmark@Sun.COM 116411042SErik.Nordmark@Sun.COM pkt_len = ira->ira_pktlen; 116511042SErik.Nordmark@Sun.COM 116611042SErik.Nordmark@Sun.COM BUMP_MIB(dst_ill->ill_ip_mib, ipIfStatsHCOutForwDatagrams); 116711042SErik.Nordmark@Sun.COM 116811042SErik.Nordmark@Sun.COM ixaflags = IXAF_IS_IPV4 | IXAF_NO_DEV_FLOW_CTL; 116911042SErik.Nordmark@Sun.COM 117011042SErik.Nordmark@Sun.COM if (pkt_len > mtu) { 117111042SErik.Nordmark@Sun.COM /* 117211042SErik.Nordmark@Sun.COM * It needs fragging on its way out. If we haven't 117311042SErik.Nordmark@Sun.COM * verified the header checksum yet we do it now since 117411042SErik.Nordmark@Sun.COM * are going to put a surely good checksum in the 117511042SErik.Nordmark@Sun.COM * outgoing header, we have to make sure that it 117611042SErik.Nordmark@Sun.COM * was good coming in. 117711042SErik.Nordmark@Sun.COM */ 117811042SErik.Nordmark@Sun.COM if ((iraflags & IRAF_VERIFY_IP_CKSUM) && ip_csum_hdr(ipha)) { 117911042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInCksumErrs); 118011042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInCksumErrs", mp, ill); 118111042SErik.Nordmark@Sun.COM freemsg(mp); 118211042SErik.Nordmark@Sun.COM return; 118311042SErik.Nordmark@Sun.COM } 118411042SErik.Nordmark@Sun.COM if (ipha->ipha_fragment_offset_and_flags & IPH_DF_HTONS) { 118511042SErik.Nordmark@Sun.COM BUMP_MIB(dst_ill->ill_ip_mib, ipIfStatsOutFragFails); 118611042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutFragFails", mp, dst_ill); 118711042SErik.Nordmark@Sun.COM if (iraflags & IRAF_SYSTEM_LABELED) { 118811042SErik.Nordmark@Sun.COM /* 118911042SErik.Nordmark@Sun.COM * Remove any CIPSO option added by 119011042SErik.Nordmark@Sun.COM * tsol_ip_forward, and make sure we report 119111042SErik.Nordmark@Sun.COM * a path MTU so that there 119211042SErik.Nordmark@Sun.COM * is room to add such a CIPSO option for future 119311042SErik.Nordmark@Sun.COM * packets. 119411042SErik.Nordmark@Sun.COM */ 119511042SErik.Nordmark@Sun.COM mtu = tsol_pmtu_adjust(mp, mtu, added_tx_len, 119611042SErik.Nordmark@Sun.COM AF_INET); 119711042SErik.Nordmark@Sun.COM } 119811042SErik.Nordmark@Sun.COM 119911042SErik.Nordmark@Sun.COM icmp_frag_needed(mp, mtu, ira); 120011042SErik.Nordmark@Sun.COM return; 120111042SErik.Nordmark@Sun.COM } 120211042SErik.Nordmark@Sun.COM 120311042SErik.Nordmark@Sun.COM (void) ip_fragment_v4(mp, nce, ixaflags, pkt_len, mtu, 120411042SErik.Nordmark@Sun.COM ira->ira_xmit_hint, GLOBAL_ZONEID, 0, ip_xmit, NULL); 120511042SErik.Nordmark@Sun.COM return; 120611042SErik.Nordmark@Sun.COM } 120711042SErik.Nordmark@Sun.COM 120811042SErik.Nordmark@Sun.COM ASSERT(pkt_len == ntohs(((ipha_t *)mp->b_rptr)->ipha_length)); 120911042SErik.Nordmark@Sun.COM if (iraflags & IRAF_LOOPBACK_COPY) { 121011042SErik.Nordmark@Sun.COM /* 121111042SErik.Nordmark@Sun.COM * IXAF_NO_LOOP_ZONEID is not set hence 7th arg 121211042SErik.Nordmark@Sun.COM * is don't care 121311042SErik.Nordmark@Sun.COM */ 121411042SErik.Nordmark@Sun.COM (void) ip_postfrag_loopcheck(mp, nce, 121511042SErik.Nordmark@Sun.COM ixaflags | IXAF_LOOPBACK_COPY, 121611042SErik.Nordmark@Sun.COM pkt_len, ira->ira_xmit_hint, GLOBAL_ZONEID, 0, NULL); 121711042SErik.Nordmark@Sun.COM } else { 121811042SErik.Nordmark@Sun.COM (void) ip_xmit(mp, nce, ixaflags, pkt_len, ira->ira_xmit_hint, 121911042SErik.Nordmark@Sun.COM GLOBAL_ZONEID, 0, NULL); 122011042SErik.Nordmark@Sun.COM } 122111042SErik.Nordmark@Sun.COM } 122211042SErik.Nordmark@Sun.COM 122311042SErik.Nordmark@Sun.COM /* 122411042SErik.Nordmark@Sun.COM * ire_recvfn for RTF_REJECT and RTF_BLACKHOLE routes, including IRE_NOROUTE, 122511042SErik.Nordmark@Sun.COM * which is what ire_route_recursive returns when there is no matching ire. 122611042SErik.Nordmark@Sun.COM * Send ICMP unreachable unless blackhole. 122711042SErik.Nordmark@Sun.COM */ 122811042SErik.Nordmark@Sun.COM void 122911042SErik.Nordmark@Sun.COM ire_recv_noroute_v4(ire_t *ire, mblk_t *mp, void *iph_arg, ip_recv_attr_t *ira) 123011042SErik.Nordmark@Sun.COM { 123111042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)iph_arg; 123211042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_ill; 123311042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ill->ill_ipst; 123411042SErik.Nordmark@Sun.COM 123511042SErik.Nordmark@Sun.COM /* Would we have forwarded this packet if we had a route? */ 123611042SErik.Nordmark@Sun.COM if (ira->ira_flags & (IRAF_L2DST_MULTICAST|IRAF_L2DST_BROADCAST)) { 123711042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits); 123811042SErik.Nordmark@Sun.COM ip_drop_input("l2 multicast not forwarded", mp, ill); 123911042SErik.Nordmark@Sun.COM freemsg(mp); 124011042SErik.Nordmark@Sun.COM return; 124111042SErik.Nordmark@Sun.COM } 124211042SErik.Nordmark@Sun.COM 124311042SErik.Nordmark@Sun.COM if (!(ill->ill_flags & ILLF_ROUTER)) { 124411042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits); 124511042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsForwProhibits", mp, ill); 124611042SErik.Nordmark@Sun.COM freemsg(mp); 124711042SErik.Nordmark@Sun.COM return; 124811042SErik.Nordmark@Sun.COM } 124911042SErik.Nordmark@Sun.COM /* 125011042SErik.Nordmark@Sun.COM * If we had a route this could have been forwarded. Count as such. 125111042SErik.Nordmark@Sun.COM * 125211042SErik.Nordmark@Sun.COM * ipIfStatsHCInForwDatagrams should only be increment if there 125311042SErik.Nordmark@Sun.COM * will be an attempt to forward the packet, which is why we 125411042SErik.Nordmark@Sun.COM * increment after the above condition has been checked. 125511042SErik.Nordmark@Sun.COM */ 125611042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInForwDatagrams); 125711042SErik.Nordmark@Sun.COM 125811042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInNoRoutes); 125911042SErik.Nordmark@Sun.COM 126011042SErik.Nordmark@Sun.COM ip_rts_change(RTM_MISS, ipha->ipha_dst, 0, 0, 0, 0, 0, 0, RTA_DST, 126111042SErik.Nordmark@Sun.COM ipst); 126211042SErik.Nordmark@Sun.COM 126311042SErik.Nordmark@Sun.COM if (ire->ire_flags & RTF_BLACKHOLE) { 126411042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInNoRoutes RTF_BLACKHOLE", mp, ill); 126511042SErik.Nordmark@Sun.COM freemsg(mp); 126611042SErik.Nordmark@Sun.COM } else { 126711042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInNoRoutes RTF_REJECT", mp, ill); 126811042SErik.Nordmark@Sun.COM 126911042SErik.Nordmark@Sun.COM if (ip_source_routed(ipha, ipst)) { 127011042SErik.Nordmark@Sun.COM icmp_unreachable(mp, ICMP_SOURCE_ROUTE_FAILED, ira); 127111042SErik.Nordmark@Sun.COM } else { 127211042SErik.Nordmark@Sun.COM icmp_unreachable(mp, ICMP_HOST_UNREACHABLE, ira); 127311042SErik.Nordmark@Sun.COM } 127411042SErik.Nordmark@Sun.COM } 127511042SErik.Nordmark@Sun.COM } 127611042SErik.Nordmark@Sun.COM 127711042SErik.Nordmark@Sun.COM /* 127811042SErik.Nordmark@Sun.COM * ire_recvfn for IRE_LOCALs marked with ire_noaccept. Such IREs are used for 127911042SErik.Nordmark@Sun.COM * VRRP when in noaccept mode. 128011042SErik.Nordmark@Sun.COM * We silently drop the packet. ARP handles packets even if noaccept is set. 128111042SErik.Nordmark@Sun.COM */ 128211042SErik.Nordmark@Sun.COM /* ARGSUSED */ 128311042SErik.Nordmark@Sun.COM void 128411042SErik.Nordmark@Sun.COM ire_recv_noaccept_v4(ire_t *ire, mblk_t *mp, void *iph_arg, 128511042SErik.Nordmark@Sun.COM ip_recv_attr_t *ira) 128611042SErik.Nordmark@Sun.COM { 128711042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_ill; 128811042SErik.Nordmark@Sun.COM 128911042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 129011042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards - noaccept", mp, ill); 129111042SErik.Nordmark@Sun.COM freemsg(mp); 129211042SErik.Nordmark@Sun.COM } 129311042SErik.Nordmark@Sun.COM 129411042SErik.Nordmark@Sun.COM /* 129511042SErik.Nordmark@Sun.COM * ire_recvfn for IRE_BROADCAST. 129611042SErik.Nordmark@Sun.COM */ 129711042SErik.Nordmark@Sun.COM void 129811042SErik.Nordmark@Sun.COM ire_recv_broadcast_v4(ire_t *ire, mblk_t *mp, void *iph_arg, 129911042SErik.Nordmark@Sun.COM ip_recv_attr_t *ira) 130011042SErik.Nordmark@Sun.COM { 130111042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)iph_arg; 130211042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_ill; 130311042SErik.Nordmark@Sun.COM ill_t *dst_ill = ire->ire_ill; 130411042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ill->ill_ipst; 130511042SErik.Nordmark@Sun.COM ire_t *alt_ire; 130611042SErik.Nordmark@Sun.COM nce_t *nce; 130711042SErik.Nordmark@Sun.COM ipaddr_t ipha_dst; 130811042SErik.Nordmark@Sun.COM 130911042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInBcastPkts); 131011042SErik.Nordmark@Sun.COM 131111042SErik.Nordmark@Sun.COM /* Tag for higher-level protocols */ 131211042SErik.Nordmark@Sun.COM ira->ira_flags |= IRAF_BROADCAST; 131311042SErik.Nordmark@Sun.COM 131411042SErik.Nordmark@Sun.COM /* 131511042SErik.Nordmark@Sun.COM * Whether local or directed broadcast forwarding: don't allow 131611042SErik.Nordmark@Sun.COM * for TCP. 131711042SErik.Nordmark@Sun.COM */ 131811042SErik.Nordmark@Sun.COM if (ipha->ipha_protocol == IPPROTO_TCP) { 131911042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 132011042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 132111042SErik.Nordmark@Sun.COM freemsg(mp); 132211042SErik.Nordmark@Sun.COM return; 132311042SErik.Nordmark@Sun.COM } 132411042SErik.Nordmark@Sun.COM 132511042SErik.Nordmark@Sun.COM /* 132611042SErik.Nordmark@Sun.COM * So that we don't end up with dups, only one ill an IPMP group is 132711042SErik.Nordmark@Sun.COM * nominated to receive broadcast traffic. 132811042SErik.Nordmark@Sun.COM * If we have no cast_ill we are liberal and accept everything. 132911042SErik.Nordmark@Sun.COM */ 133011042SErik.Nordmark@Sun.COM if (IS_UNDER_IPMP(ill)) { 133111042SErik.Nordmark@Sun.COM /* For an under ill_grp can change under lock */ 133211042SErik.Nordmark@Sun.COM rw_enter(&ipst->ips_ill_g_lock, RW_READER); 133311042SErik.Nordmark@Sun.COM if (!ill->ill_nom_cast && ill->ill_grp != NULL && 133411042SErik.Nordmark@Sun.COM ill->ill_grp->ig_cast_ill != NULL) { 133511042SErik.Nordmark@Sun.COM rw_exit(&ipst->ips_ill_g_lock); 133611042SErik.Nordmark@Sun.COM /* No MIB since this is normal operation */ 133711042SErik.Nordmark@Sun.COM ip_drop_input("not nom_cast", mp, ill); 133811042SErik.Nordmark@Sun.COM freemsg(mp); 133911042SErik.Nordmark@Sun.COM return; 134011042SErik.Nordmark@Sun.COM } 134111042SErik.Nordmark@Sun.COM rw_exit(&ipst->ips_ill_g_lock); 134211042SErik.Nordmark@Sun.COM 134311042SErik.Nordmark@Sun.COM ira->ira_ruifindex = ill_get_upper_ifindex(ill); 134411042SErik.Nordmark@Sun.COM } 134511042SErik.Nordmark@Sun.COM 134611042SErik.Nordmark@Sun.COM /* 134711042SErik.Nordmark@Sun.COM * After reassembly and IPsec we will need to duplicate the 134811042SErik.Nordmark@Sun.COM * broadcast packet for all matching zones on the ill. 134911042SErik.Nordmark@Sun.COM */ 135011042SErik.Nordmark@Sun.COM ira->ira_zoneid = ALL_ZONES; 135111042SErik.Nordmark@Sun.COM 135211042SErik.Nordmark@Sun.COM /* 135311042SErik.Nordmark@Sun.COM * Check for directed broadcast i.e. ire->ire_ill is different than 135411042SErik.Nordmark@Sun.COM * the incoming ill. 135511042SErik.Nordmark@Sun.COM * The same broadcast address can be assigned to multiple interfaces 135611042SErik.Nordmark@Sun.COM * so have to check explicitly for that case by looking up the alt_ire 135711042SErik.Nordmark@Sun.COM */ 135811042SErik.Nordmark@Sun.COM if (dst_ill == ill && !(ire->ire_flags & RTF_MULTIRT)) { 135911042SErik.Nordmark@Sun.COM /* Reassemble on the ill on which the packet arrived */ 136011042SErik.Nordmark@Sun.COM ip_input_local_v4(ire, mp, ipha, ira); 136111042SErik.Nordmark@Sun.COM /* Restore */ 136211042SErik.Nordmark@Sun.COM ira->ira_ruifindex = ill->ill_phyint->phyint_ifindex; 136311042SErik.Nordmark@Sun.COM return; 136411042SErik.Nordmark@Sun.COM } 136511042SErik.Nordmark@Sun.COM 136611042SErik.Nordmark@Sun.COM /* Is there an IRE_BROADCAST on the incoming ill? */ 136711042SErik.Nordmark@Sun.COM ipha_dst = ((ira->ira_flags & IRAF_DHCP_UNICAST) ? INADDR_BROADCAST : 136811042SErik.Nordmark@Sun.COM ipha->ipha_dst); 136911042SErik.Nordmark@Sun.COM alt_ire = ire_ftable_lookup_v4(ipha_dst, 0, 0, IRE_BROADCAST, ill, 137011042SErik.Nordmark@Sun.COM ALL_ZONES, ira->ira_tsl, 137111042SErik.Nordmark@Sun.COM MATCH_IRE_TYPE|MATCH_IRE_ILL|MATCH_IRE_SECATTR, 0, ipst, NULL); 137211042SErik.Nordmark@Sun.COM if (alt_ire != NULL) { 137311042SErik.Nordmark@Sun.COM /* Not a directed broadcast */ 137411042SErik.Nordmark@Sun.COM /* 137511042SErik.Nordmark@Sun.COM * In the special case of multirouted broadcast 137611042SErik.Nordmark@Sun.COM * packets, we unconditionally need to "gateway" 137711042SErik.Nordmark@Sun.COM * them to the appropriate interface here so that reassembly 137811042SErik.Nordmark@Sun.COM * works. We know that the IRE_BROADCAST on cgtp0 doesn't 137911042SErik.Nordmark@Sun.COM * have RTF_MULTIRT set so we look for such an IRE in the 138011042SErik.Nordmark@Sun.COM * bucket. 138111042SErik.Nordmark@Sun.COM */ 138211042SErik.Nordmark@Sun.COM if (alt_ire->ire_flags & RTF_MULTIRT) { 138311042SErik.Nordmark@Sun.COM irb_t *irb; 138411042SErik.Nordmark@Sun.COM ire_t *ire1; 138511042SErik.Nordmark@Sun.COM 138611042SErik.Nordmark@Sun.COM irb = ire->ire_bucket; 138711042SErik.Nordmark@Sun.COM irb_refhold(irb); 138811042SErik.Nordmark@Sun.COM for (ire1 = irb->irb_ire; ire1 != NULL; 138911042SErik.Nordmark@Sun.COM ire1 = ire1->ire_next) { 139011042SErik.Nordmark@Sun.COM if (IRE_IS_CONDEMNED(ire1)) 139111042SErik.Nordmark@Sun.COM continue; 139211042SErik.Nordmark@Sun.COM if (!(ire1->ire_type & IRE_BROADCAST) || 139311042SErik.Nordmark@Sun.COM (ire1->ire_flags & RTF_MULTIRT)) 139411042SErik.Nordmark@Sun.COM continue; 139511042SErik.Nordmark@Sun.COM ill = ire1->ire_ill; 139611042SErik.Nordmark@Sun.COM ill_refhold(ill); 139711042SErik.Nordmark@Sun.COM break; 139811042SErik.Nordmark@Sun.COM } 139911042SErik.Nordmark@Sun.COM irb_refrele(irb); 140011042SErik.Nordmark@Sun.COM if (ire1 != NULL) { 140111042SErik.Nordmark@Sun.COM ill_t *orig_ill = ira->ira_ill; 140211042SErik.Nordmark@Sun.COM 140311042SErik.Nordmark@Sun.COM ire_refrele(alt_ire); 140411042SErik.Nordmark@Sun.COM /* Reassemble on the new ill */ 140511042SErik.Nordmark@Sun.COM ira->ira_ill = ill; 140611042SErik.Nordmark@Sun.COM ip_input_local_v4(ire, mp, ipha, ira); 140711042SErik.Nordmark@Sun.COM ill_refrele(ill); 140811042SErik.Nordmark@Sun.COM /* Restore */ 140911042SErik.Nordmark@Sun.COM ira->ira_ill = orig_ill; 141011042SErik.Nordmark@Sun.COM ira->ira_ruifindex = 141111042SErik.Nordmark@Sun.COM orig_ill->ill_phyint->phyint_ifindex; 141211042SErik.Nordmark@Sun.COM return; 141311042SErik.Nordmark@Sun.COM } 141411042SErik.Nordmark@Sun.COM } 141511042SErik.Nordmark@Sun.COM ire_refrele(alt_ire); 141611042SErik.Nordmark@Sun.COM /* Reassemble on the ill on which the packet arrived */ 141711042SErik.Nordmark@Sun.COM ip_input_local_v4(ire, mp, ipha, ira); 141811042SErik.Nordmark@Sun.COM goto done; 141911042SErik.Nordmark@Sun.COM } 142011042SErik.Nordmark@Sun.COM 142111042SErik.Nordmark@Sun.COM /* 142211042SErik.Nordmark@Sun.COM * This is a directed broadcast 142311042SErik.Nordmark@Sun.COM * 142411042SErik.Nordmark@Sun.COM * If directed broadcast is allowed, then forward the packet out 142511042SErik.Nordmark@Sun.COM * the destination interface with IXAF_LOOPBACK_COPY set. That will 142611042SErik.Nordmark@Sun.COM * result in ip_input() receiving a copy of the packet on the 142711042SErik.Nordmark@Sun.COM * appropriate ill. (We could optimize this to avoid the extra trip 142811042SErik.Nordmark@Sun.COM * via ip_input(), but since directed broadcasts are normally disabled 142911042SErik.Nordmark@Sun.COM * it doesn't make sense to optimize it.) 143011042SErik.Nordmark@Sun.COM */ 143111042SErik.Nordmark@Sun.COM if (!ipst->ips_ip_g_forward_directed_bcast || 143211042SErik.Nordmark@Sun.COM (ira->ira_flags & (IRAF_L2DST_MULTICAST|IRAF_L2DST_BROADCAST))) { 143311042SErik.Nordmark@Sun.COM ip_drop_input("directed broadcast not allowed", mp, ill); 143411042SErik.Nordmark@Sun.COM freemsg(mp); 143511042SErik.Nordmark@Sun.COM goto done; 143611042SErik.Nordmark@Sun.COM } 143711042SErik.Nordmark@Sun.COM if ((ira->ira_flags & IRAF_VERIFY_IP_CKSUM) && ip_csum_hdr(ipha)) { 143811042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInCksumErrs); 143911042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInCksumErrs", mp, ill); 144011042SErik.Nordmark@Sun.COM freemsg(mp); 144111042SErik.Nordmark@Sun.COM goto done; 144211042SErik.Nordmark@Sun.COM } 144311042SErik.Nordmark@Sun.COM 144411042SErik.Nordmark@Sun.COM /* 144511042SErik.Nordmark@Sun.COM * Clear the indication that this may have hardware 144611042SErik.Nordmark@Sun.COM * checksum as we are not using it for forwarding. 144711042SErik.Nordmark@Sun.COM */ 144811042SErik.Nordmark@Sun.COM DB_CKSUMFLAGS(mp) = 0; 144911042SErik.Nordmark@Sun.COM 145011042SErik.Nordmark@Sun.COM /* 145111042SErik.Nordmark@Sun.COM * Adjust ttl to 2 (1+1 - the forward engine will decrement it by one. 145211042SErik.Nordmark@Sun.COM */ 145311042SErik.Nordmark@Sun.COM ipha->ipha_ttl = ipst->ips_ip_broadcast_ttl + 1; 145411042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = 0; 145511042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = ip_csum_hdr(ipha); 145611042SErik.Nordmark@Sun.COM 145711042SErik.Nordmark@Sun.COM /* 145811042SErik.Nordmark@Sun.COM * We use ip_forward_xmit to do any fragmentation. 145911042SErik.Nordmark@Sun.COM * and loopback copy on the outbound interface. 146011042SErik.Nordmark@Sun.COM * 146111042SErik.Nordmark@Sun.COM * Make it so that IXAF_LOOPBACK_COPY to be set on transmit side. 146211042SErik.Nordmark@Sun.COM */ 146311042SErik.Nordmark@Sun.COM ira->ira_flags |= IRAF_LOOPBACK_COPY; 146411042SErik.Nordmark@Sun.COM 146511042SErik.Nordmark@Sun.COM nce = arp_nce_init(dst_ill, ipha->ipha_dst, IRE_BROADCAST); 146611042SErik.Nordmark@Sun.COM if (nce == NULL) { 146711042SErik.Nordmark@Sun.COM BUMP_MIB(dst_ill->ill_ip_mib, ipIfStatsOutDiscards); 146811042SErik.Nordmark@Sun.COM ip_drop_output("No nce", mp, dst_ill); 146911042SErik.Nordmark@Sun.COM freemsg(mp); 147011042SErik.Nordmark@Sun.COM goto done; 147111042SErik.Nordmark@Sun.COM } 147211042SErik.Nordmark@Sun.COM 147311042SErik.Nordmark@Sun.COM ip_forward_xmit_v4(nce, ill, mp, ipha, ira, dst_ill->ill_mtu, 0); 147411042SErik.Nordmark@Sun.COM nce_refrele(nce); 147511042SErik.Nordmark@Sun.COM done: 147611042SErik.Nordmark@Sun.COM /* Restore */ 147711042SErik.Nordmark@Sun.COM ira->ira_ruifindex = ill->ill_phyint->phyint_ifindex; 147811042SErik.Nordmark@Sun.COM } 147911042SErik.Nordmark@Sun.COM 148011042SErik.Nordmark@Sun.COM /* 148111042SErik.Nordmark@Sun.COM * ire_recvfn for IRE_MULTICAST. 148211042SErik.Nordmark@Sun.COM */ 148311042SErik.Nordmark@Sun.COM void 148411042SErik.Nordmark@Sun.COM ire_recv_multicast_v4(ire_t *ire, mblk_t *mp, void *iph_arg, 148511042SErik.Nordmark@Sun.COM ip_recv_attr_t *ira) 148611042SErik.Nordmark@Sun.COM { 148711042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)iph_arg; 148811042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_ill; 148911042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ill->ill_ipst; 149011042SErik.Nordmark@Sun.COM 149111042SErik.Nordmark@Sun.COM ASSERT(ire->ire_ill == ira->ira_ill); 149211042SErik.Nordmark@Sun.COM 149311042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInMcastPkts); 149411042SErik.Nordmark@Sun.COM UPDATE_MIB(ill->ill_ip_mib, ipIfStatsHCInMcastOctets, ira->ira_pktlen); 149511042SErik.Nordmark@Sun.COM 149611042SErik.Nordmark@Sun.COM /* RSVP hook */ 149711042SErik.Nordmark@Sun.COM if (ira->ira_flags & IRAF_RSVP) 149811042SErik.Nordmark@Sun.COM goto forus; 149911042SErik.Nordmark@Sun.COM 150011042SErik.Nordmark@Sun.COM /* Tag for higher-level protocols */ 150111042SErik.Nordmark@Sun.COM ira->ira_flags |= IRAF_MULTICAST; 150211042SErik.Nordmark@Sun.COM 150311042SErik.Nordmark@Sun.COM /* 150411042SErik.Nordmark@Sun.COM * So that we don't end up with dups, only one ill an IPMP group is 150511042SErik.Nordmark@Sun.COM * nominated to receive multicast traffic. 150611042SErik.Nordmark@Sun.COM * If we have no cast_ill we are liberal and accept everything. 150711042SErik.Nordmark@Sun.COM */ 150811042SErik.Nordmark@Sun.COM if (IS_UNDER_IPMP(ill)) { 150911042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ill->ill_ipst; 151011042SErik.Nordmark@Sun.COM 151111042SErik.Nordmark@Sun.COM /* For an under ill_grp can change under lock */ 151211042SErik.Nordmark@Sun.COM rw_enter(&ipst->ips_ill_g_lock, RW_READER); 151311042SErik.Nordmark@Sun.COM if (!ill->ill_nom_cast && ill->ill_grp != NULL && 151411042SErik.Nordmark@Sun.COM ill->ill_grp->ig_cast_ill != NULL) { 151511042SErik.Nordmark@Sun.COM rw_exit(&ipst->ips_ill_g_lock); 151611042SErik.Nordmark@Sun.COM ip_drop_input("not on cast ill", mp, ill); 151711042SErik.Nordmark@Sun.COM freemsg(mp); 151811042SErik.Nordmark@Sun.COM return; 151911042SErik.Nordmark@Sun.COM } 152011042SErik.Nordmark@Sun.COM rw_exit(&ipst->ips_ill_g_lock); 152111042SErik.Nordmark@Sun.COM /* 152211042SErik.Nordmark@Sun.COM * We switch to the upper ill so that mrouter and hasmembers 152311042SErik.Nordmark@Sun.COM * can operate on upper here and in ip_input_multicast. 152411042SErik.Nordmark@Sun.COM */ 152511042SErik.Nordmark@Sun.COM ill = ipmp_ill_hold_ipmp_ill(ill); 152611042SErik.Nordmark@Sun.COM if (ill != NULL) { 152711042SErik.Nordmark@Sun.COM ASSERT(ill != ira->ira_ill); 152811042SErik.Nordmark@Sun.COM ASSERT(ire->ire_ill == ira->ira_ill); 152911042SErik.Nordmark@Sun.COM ira->ira_ill = ill; 153011042SErik.Nordmark@Sun.COM ira->ira_ruifindex = ill->ill_phyint->phyint_ifindex; 153111042SErik.Nordmark@Sun.COM } else { 153211042SErik.Nordmark@Sun.COM ill = ira->ira_ill; 153311042SErik.Nordmark@Sun.COM } 153411042SErik.Nordmark@Sun.COM } 153511042SErik.Nordmark@Sun.COM 153611042SErik.Nordmark@Sun.COM /* 153711042SErik.Nordmark@Sun.COM * Check if we are a multicast router - send ip_mforward a copy of 153811042SErik.Nordmark@Sun.COM * the packet. 153911042SErik.Nordmark@Sun.COM * Due to mroute_decap tunnels we consider forwarding packets even if 154011042SErik.Nordmark@Sun.COM * mrouted has not joined the allmulti group on this interface. 154111042SErik.Nordmark@Sun.COM */ 154211042SErik.Nordmark@Sun.COM if (ipst->ips_ip_g_mrouter) { 154311042SErik.Nordmark@Sun.COM int retval; 154411042SErik.Nordmark@Sun.COM 154511042SErik.Nordmark@Sun.COM /* 154611042SErik.Nordmark@Sun.COM * Clear the indication that this may have hardware 154711042SErik.Nordmark@Sun.COM * checksum as we are not using it for forwarding. 154811042SErik.Nordmark@Sun.COM */ 154911042SErik.Nordmark@Sun.COM DB_CKSUMFLAGS(mp) = 0; 155011042SErik.Nordmark@Sun.COM 155111042SErik.Nordmark@Sun.COM /* 155211042SErik.Nordmark@Sun.COM * ip_mforward helps us make these distinctions: If received 155311042SErik.Nordmark@Sun.COM * on tunnel and not IGMP, then drop. 155411042SErik.Nordmark@Sun.COM * If IGMP packet, then don't check membership 155511042SErik.Nordmark@Sun.COM * If received on a phyint and IGMP or PIM, then 155611042SErik.Nordmark@Sun.COM * don't check membership 155711042SErik.Nordmark@Sun.COM */ 155811042SErik.Nordmark@Sun.COM retval = ip_mforward(mp, ira); 155911042SErik.Nordmark@Sun.COM /* ip_mforward updates mib variables if needed */ 156011042SErik.Nordmark@Sun.COM 156111042SErik.Nordmark@Sun.COM switch (retval) { 156211042SErik.Nordmark@Sun.COM case 0: 156311042SErik.Nordmark@Sun.COM /* 156411042SErik.Nordmark@Sun.COM * pkt is okay and arrived on phyint. 156511042SErik.Nordmark@Sun.COM * 156611042SErik.Nordmark@Sun.COM * If we are running as a multicast router 156711042SErik.Nordmark@Sun.COM * we need to see all IGMP and/or PIM packets. 156811042SErik.Nordmark@Sun.COM */ 156911042SErik.Nordmark@Sun.COM if ((ipha->ipha_protocol == IPPROTO_IGMP) || 157011042SErik.Nordmark@Sun.COM (ipha->ipha_protocol == IPPROTO_PIM)) { 157111042SErik.Nordmark@Sun.COM goto forus; 157211042SErik.Nordmark@Sun.COM } 157311042SErik.Nordmark@Sun.COM break; 157411042SErik.Nordmark@Sun.COM case -1: 157511042SErik.Nordmark@Sun.COM /* pkt is mal-formed, toss it */ 157611042SErik.Nordmark@Sun.COM freemsg(mp); 157711042SErik.Nordmark@Sun.COM goto done; 157811042SErik.Nordmark@Sun.COM case 1: 157911042SErik.Nordmark@Sun.COM /* 158011042SErik.Nordmark@Sun.COM * pkt is okay and arrived on a tunnel 158111042SErik.Nordmark@Sun.COM * 158211042SErik.Nordmark@Sun.COM * If we are running a multicast router 158311042SErik.Nordmark@Sun.COM * we need to see all igmp packets. 158411042SErik.Nordmark@Sun.COM */ 158511042SErik.Nordmark@Sun.COM if (ipha->ipha_protocol == IPPROTO_IGMP) { 158611042SErik.Nordmark@Sun.COM goto forus; 158711042SErik.Nordmark@Sun.COM } 158811042SErik.Nordmark@Sun.COM ip_drop_input("Multicast on tunnel ignored", mp, ill); 158911042SErik.Nordmark@Sun.COM freemsg(mp); 159011042SErik.Nordmark@Sun.COM goto done; 159111042SErik.Nordmark@Sun.COM } 159211042SErik.Nordmark@Sun.COM } 159311042SErik.Nordmark@Sun.COM 159411042SErik.Nordmark@Sun.COM /* 159511042SErik.Nordmark@Sun.COM * Check if we have members on this ill. This is not necessary for 159611042SErik.Nordmark@Sun.COM * correctness because even if the NIC/GLD had a leaky filter, we 159711042SErik.Nordmark@Sun.COM * filter before passing to each conn_t. 159811042SErik.Nordmark@Sun.COM */ 159911042SErik.Nordmark@Sun.COM if (!ill_hasmembers_v4(ill, ipha->ipha_dst)) { 160011042SErik.Nordmark@Sun.COM /* 160111042SErik.Nordmark@Sun.COM * Nobody interested 160211042SErik.Nordmark@Sun.COM * 160311042SErik.Nordmark@Sun.COM * This might just be caused by the fact that 160411042SErik.Nordmark@Sun.COM * multiple IP Multicast addresses map to the same 160511042SErik.Nordmark@Sun.COM * link layer multicast - no need to increment counter! 160611042SErik.Nordmark@Sun.COM */ 160711042SErik.Nordmark@Sun.COM ip_drop_input("Multicast with no members", mp, ill); 160811042SErik.Nordmark@Sun.COM freemsg(mp); 160911042SErik.Nordmark@Sun.COM goto done; 161011042SErik.Nordmark@Sun.COM } 161111042SErik.Nordmark@Sun.COM forus: 161211042SErik.Nordmark@Sun.COM ip2dbg(("ire_recv_multicast_v4: multicast for us: 0x%x\n", 161311042SErik.Nordmark@Sun.COM ntohl(ipha->ipha_dst))); 161411042SErik.Nordmark@Sun.COM 161511042SErik.Nordmark@Sun.COM /* 161611042SErik.Nordmark@Sun.COM * After reassembly and IPsec we will need to duplicate the 161711042SErik.Nordmark@Sun.COM * multicast packet for all matching zones on the ill. 161811042SErik.Nordmark@Sun.COM */ 161911042SErik.Nordmark@Sun.COM ira->ira_zoneid = ALL_ZONES; 162011042SErik.Nordmark@Sun.COM 162111042SErik.Nordmark@Sun.COM /* Reassemble on the ill on which the packet arrived */ 162211042SErik.Nordmark@Sun.COM ip_input_local_v4(ire, mp, ipha, ira); 162311042SErik.Nordmark@Sun.COM done: 162411042SErik.Nordmark@Sun.COM if (ill != ire->ire_ill) { 162511042SErik.Nordmark@Sun.COM ill_refrele(ill); 162611042SErik.Nordmark@Sun.COM ira->ira_ill = ire->ire_ill; 162711042SErik.Nordmark@Sun.COM ira->ira_ruifindex = ira->ira_ill->ill_phyint->phyint_ifindex; 162811042SErik.Nordmark@Sun.COM } 162911042SErik.Nordmark@Sun.COM } 163011042SErik.Nordmark@Sun.COM 163111042SErik.Nordmark@Sun.COM /* 163211042SErik.Nordmark@Sun.COM * ire_recvfn for IRE_OFFLINK with RTF_MULTIRT. 163311042SErik.Nordmark@Sun.COM * Drop packets since we don't forward out multirt routes. 163411042SErik.Nordmark@Sun.COM */ 163511042SErik.Nordmark@Sun.COM /* ARGSUSED */ 163611042SErik.Nordmark@Sun.COM void 163711042SErik.Nordmark@Sun.COM ire_recv_multirt_v4(ire_t *ire, mblk_t *mp, void *iph_arg, ip_recv_attr_t *ira) 163811042SErik.Nordmark@Sun.COM { 163911042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_ill; 164011042SErik.Nordmark@Sun.COM 164111042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInNoRoutes); 164211042SErik.Nordmark@Sun.COM ip_drop_input("Not forwarding out MULTIRT", mp, ill); 164311042SErik.Nordmark@Sun.COM freemsg(mp); 164411042SErik.Nordmark@Sun.COM } 164511042SErik.Nordmark@Sun.COM 164611042SErik.Nordmark@Sun.COM /* 164711042SErik.Nordmark@Sun.COM * ire_recvfn for IRE_LOOPBACK. This is only used when a FW_HOOK 164811042SErik.Nordmark@Sun.COM * has rewritten the packet to have a loopback destination address (We 164911042SErik.Nordmark@Sun.COM * filter out packet with a loopback destination from arriving over the wire). 165011042SErik.Nordmark@Sun.COM * We don't know what zone to use, thus we always use the GLOBAL_ZONEID. 165111042SErik.Nordmark@Sun.COM */ 165211042SErik.Nordmark@Sun.COM void 165311042SErik.Nordmark@Sun.COM ire_recv_loopback_v4(ire_t *ire, mblk_t *mp, void *iph_arg, ip_recv_attr_t *ira) 165411042SErik.Nordmark@Sun.COM { 165511042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)iph_arg; 165611042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_ill; 165711042SErik.Nordmark@Sun.COM ill_t *ire_ill = ire->ire_ill; 165811042SErik.Nordmark@Sun.COM 165911042SErik.Nordmark@Sun.COM ira->ira_zoneid = GLOBAL_ZONEID; 166011042SErik.Nordmark@Sun.COM 166111042SErik.Nordmark@Sun.COM /* Switch to the lo0 ill for further processing */ 166211042SErik.Nordmark@Sun.COM if (ire_ill != ill) { 166311042SErik.Nordmark@Sun.COM /* 166411042SErik.Nordmark@Sun.COM * Update ira_ill to be the ILL on which the IP address 166511042SErik.Nordmark@Sun.COM * is hosted. 166611042SErik.Nordmark@Sun.COM * No need to hold the ill since we have a hold on the ire 166711042SErik.Nordmark@Sun.COM */ 166811042SErik.Nordmark@Sun.COM ASSERT(ira->ira_ill == ira->ira_rill); 166911042SErik.Nordmark@Sun.COM ira->ira_ill = ire_ill; 167011042SErik.Nordmark@Sun.COM 167111042SErik.Nordmark@Sun.COM ip_input_local_v4(ire, mp, ipha, ira); 167211042SErik.Nordmark@Sun.COM 167311042SErik.Nordmark@Sun.COM /* Restore */ 167411042SErik.Nordmark@Sun.COM ASSERT(ira->ira_ill == ire_ill); 167511042SErik.Nordmark@Sun.COM ira->ira_ill = ill; 167611042SErik.Nordmark@Sun.COM return; 167711042SErik.Nordmark@Sun.COM 167811042SErik.Nordmark@Sun.COM } 167911042SErik.Nordmark@Sun.COM ip_input_local_v4(ire, mp, ipha, ira); 168011042SErik.Nordmark@Sun.COM } 168111042SErik.Nordmark@Sun.COM 168211042SErik.Nordmark@Sun.COM /* 168311042SErik.Nordmark@Sun.COM * ire_recvfn for IRE_LOCAL. 168411042SErik.Nordmark@Sun.COM */ 168511042SErik.Nordmark@Sun.COM void 168611042SErik.Nordmark@Sun.COM ire_recv_local_v4(ire_t *ire, mblk_t *mp, void *iph_arg, ip_recv_attr_t *ira) 168711042SErik.Nordmark@Sun.COM { 168811042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)iph_arg; 168911042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_ill; 169011042SErik.Nordmark@Sun.COM ill_t *ire_ill = ire->ire_ill; 169111042SErik.Nordmark@Sun.COM 169211042SErik.Nordmark@Sun.COM /* Make a note for DAD that this address is in use */ 169311110SErik.Nordmark@Sun.COM ire->ire_last_used_time = LBOLT_FASTPATH; 169411042SErik.Nordmark@Sun.COM 169511042SErik.Nordmark@Sun.COM /* Only target the IRE_LOCAL with the right zoneid. */ 169611042SErik.Nordmark@Sun.COM ira->ira_zoneid = ire->ire_zoneid; 169711042SErik.Nordmark@Sun.COM 169811042SErik.Nordmark@Sun.COM /* 169911042SErik.Nordmark@Sun.COM * If the packet arrived on the wrong ill, we check that 170011042SErik.Nordmark@Sun.COM * this is ok. 170111042SErik.Nordmark@Sun.COM * If it is, then we ensure that we do the reassembly on 170211042SErik.Nordmark@Sun.COM * the ill on which the address is hosted. We keep ira_rill as 170311042SErik.Nordmark@Sun.COM * the one on which the packet arrived, so that IP_PKTINFO and 170411042SErik.Nordmark@Sun.COM * friends can report this. 170511042SErik.Nordmark@Sun.COM */ 170611042SErik.Nordmark@Sun.COM if (ire_ill != ill) { 170711042SErik.Nordmark@Sun.COM ire_t *new_ire; 170811042SErik.Nordmark@Sun.COM 170911042SErik.Nordmark@Sun.COM new_ire = ip_check_multihome(&ipha->ipha_dst, ire, ill); 171011042SErik.Nordmark@Sun.COM if (new_ire == NULL) { 171111042SErik.Nordmark@Sun.COM /* Drop packet */ 171211042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits); 171311042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInForwProhibits", mp, ill); 171411042SErik.Nordmark@Sun.COM freemsg(mp); 171511042SErik.Nordmark@Sun.COM return; 171611042SErik.Nordmark@Sun.COM } 171711042SErik.Nordmark@Sun.COM /* 171811042SErik.Nordmark@Sun.COM * Update ira_ill to be the ILL on which the IP address 171911042SErik.Nordmark@Sun.COM * is hosted. No need to hold the ill since we have a 172011042SErik.Nordmark@Sun.COM * hold on the ire. Note that we do the switch even if 172111042SErik.Nordmark@Sun.COM * new_ire == ire (for IPMP, ire would be the one corresponding 172211042SErik.Nordmark@Sun.COM * to the IPMP ill). 172311042SErik.Nordmark@Sun.COM */ 172411042SErik.Nordmark@Sun.COM ASSERT(ira->ira_ill == ira->ira_rill); 172511042SErik.Nordmark@Sun.COM ira->ira_ill = new_ire->ire_ill; 172611042SErik.Nordmark@Sun.COM 172711042SErik.Nordmark@Sun.COM /* ira_ruifindex tracks the upper for ira_rill */ 172811042SErik.Nordmark@Sun.COM if (IS_UNDER_IPMP(ill)) 172911042SErik.Nordmark@Sun.COM ira->ira_ruifindex = ill_get_upper_ifindex(ill); 173011042SErik.Nordmark@Sun.COM 173111042SErik.Nordmark@Sun.COM ip_input_local_v4(new_ire, mp, ipha, ira); 173211042SErik.Nordmark@Sun.COM 173311042SErik.Nordmark@Sun.COM /* Restore */ 173411042SErik.Nordmark@Sun.COM ASSERT(ira->ira_ill == new_ire->ire_ill); 173511042SErik.Nordmark@Sun.COM ira->ira_ill = ill; 173611042SErik.Nordmark@Sun.COM ira->ira_ruifindex = ill->ill_phyint->phyint_ifindex; 173711042SErik.Nordmark@Sun.COM 173811042SErik.Nordmark@Sun.COM if (new_ire != ire) 173911042SErik.Nordmark@Sun.COM ire_refrele(new_ire); 174011042SErik.Nordmark@Sun.COM return; 174111042SErik.Nordmark@Sun.COM } 174211042SErik.Nordmark@Sun.COM 174311042SErik.Nordmark@Sun.COM ip_input_local_v4(ire, mp, ipha, ira); 174411042SErik.Nordmark@Sun.COM } 174511042SErik.Nordmark@Sun.COM 174611042SErik.Nordmark@Sun.COM /* 174711042SErik.Nordmark@Sun.COM * Common function for packets arriving for the host. Handles 174811042SErik.Nordmark@Sun.COM * checksum verification, reassembly checks, etc. 174911042SErik.Nordmark@Sun.COM */ 175011042SErik.Nordmark@Sun.COM static void 175111042SErik.Nordmark@Sun.COM ip_input_local_v4(ire_t *ire, mblk_t *mp, ipha_t *ipha, ip_recv_attr_t *ira) 175211042SErik.Nordmark@Sun.COM { 175311042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_ill; 175411042SErik.Nordmark@Sun.COM iaflags_t iraflags = ira->ira_flags; 175511042SErik.Nordmark@Sun.COM 175611042SErik.Nordmark@Sun.COM /* 175711042SErik.Nordmark@Sun.COM * Verify IP header checksum. If the packet was AH or ESP then 175811042SErik.Nordmark@Sun.COM * this flag has already been cleared. Likewise if the packet 175911042SErik.Nordmark@Sun.COM * had a hardware checksum. 176011042SErik.Nordmark@Sun.COM */ 176111042SErik.Nordmark@Sun.COM if ((iraflags & IRAF_VERIFY_IP_CKSUM) && ip_csum_hdr(ipha)) { 176211042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInCksumErrs); 176311042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInCksumErrs", mp, ill); 176411042SErik.Nordmark@Sun.COM freemsg(mp); 176511042SErik.Nordmark@Sun.COM return; 176611042SErik.Nordmark@Sun.COM } 176711042SErik.Nordmark@Sun.COM 176811042SErik.Nordmark@Sun.COM if (iraflags & IRAF_IPV4_OPTIONS) { 176911042SErik.Nordmark@Sun.COM if (!ip_input_local_options(mp, ipha, ira)) { 177011042SErik.Nordmark@Sun.COM /* Error has been sent and mp consumed */ 177111042SErik.Nordmark@Sun.COM return; 177211042SErik.Nordmark@Sun.COM } 177311145SRoamer@Sun.COM /* 177411145SRoamer@Sun.COM * Some old hardware does partial checksum by including the 177511145SRoamer@Sun.COM * whole IP header, so the partial checksum value might have 177611145SRoamer@Sun.COM * become invalid if any option in the packet have been 177711145SRoamer@Sun.COM * updated. Always clear partial checksum flag here. 177811145SRoamer@Sun.COM */ 177911145SRoamer@Sun.COM DB_CKSUMFLAGS(mp) &= ~HCK_PARTIALCKSUM; 178011042SErik.Nordmark@Sun.COM } 178111042SErik.Nordmark@Sun.COM 178211042SErik.Nordmark@Sun.COM /* 178311042SErik.Nordmark@Sun.COM * Is packet part of fragmented IP packet? 178411042SErik.Nordmark@Sun.COM * We compare against defined values in network byte order 178511042SErik.Nordmark@Sun.COM */ 178611042SErik.Nordmark@Sun.COM if (ipha->ipha_fragment_offset_and_flags & 178711042SErik.Nordmark@Sun.COM (IPH_MF_HTONS | IPH_OFFSET_HTONS)) { 178811042SErik.Nordmark@Sun.COM /* 178911042SErik.Nordmark@Sun.COM * Make sure we have ira_l2src before we loose the original 179011042SErik.Nordmark@Sun.COM * mblk 179111042SErik.Nordmark@Sun.COM */ 179211042SErik.Nordmark@Sun.COM if (!(ira->ira_flags & IRAF_L2SRC_SET)) 179311042SErik.Nordmark@Sun.COM ip_setl2src(mp, ira, ira->ira_rill); 179411042SErik.Nordmark@Sun.COM 179511042SErik.Nordmark@Sun.COM mp = ip_input_fragment(mp, ipha, ira); 179611042SErik.Nordmark@Sun.COM if (mp == NULL) 179711042SErik.Nordmark@Sun.COM return; 179811042SErik.Nordmark@Sun.COM /* Completed reassembly */ 179911042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr; 180011042SErik.Nordmark@Sun.COM } 180111042SErik.Nordmark@Sun.COM 180211042SErik.Nordmark@Sun.COM /* 180311042SErik.Nordmark@Sun.COM * For broadcast and multicast we need some extra work before 180411042SErik.Nordmark@Sun.COM * we call ip_fanout_v4(), since in the case of shared-IP zones 180511042SErik.Nordmark@Sun.COM * we need to pretend that a packet arrived for each zoneid. 180611042SErik.Nordmark@Sun.COM */ 180711042SErik.Nordmark@Sun.COM if (iraflags & IRAF_MULTIBROADCAST) { 180811042SErik.Nordmark@Sun.COM if (iraflags & IRAF_BROADCAST) 180911042SErik.Nordmark@Sun.COM ip_input_broadcast_v4(ire, mp, ipha, ira); 181011042SErik.Nordmark@Sun.COM else 181111042SErik.Nordmark@Sun.COM ip_input_multicast_v4(ire, mp, ipha, ira); 181211042SErik.Nordmark@Sun.COM return; 181311042SErik.Nordmark@Sun.COM } 181411042SErik.Nordmark@Sun.COM ip_fanout_v4(mp, ipha, ira); 181511042SErik.Nordmark@Sun.COM } 181611042SErik.Nordmark@Sun.COM 181711042SErik.Nordmark@Sun.COM 181811042SErik.Nordmark@Sun.COM /* 181911042SErik.Nordmark@Sun.COM * Handle multiple zones which match the same broadcast address 182011042SErik.Nordmark@Sun.COM * and ill by delivering a packet to each of them. 182111042SErik.Nordmark@Sun.COM * Walk the bucket and look for different ire_zoneid but otherwise 182211042SErik.Nordmark@Sun.COM * the same IRE (same ill/addr/mask/type). 182311042SErik.Nordmark@Sun.COM * Note that ire_add() tracks IREs that are identical in all 182411042SErik.Nordmark@Sun.COM * fields (addr/mask/type/gw/ill/zoneid) within a single IRE by 182511042SErik.Nordmark@Sun.COM * increasing ire_identical_cnt. Thus we don't need to be concerned 182611042SErik.Nordmark@Sun.COM * about those. 182711042SErik.Nordmark@Sun.COM */ 182811042SErik.Nordmark@Sun.COM static void 182911042SErik.Nordmark@Sun.COM ip_input_broadcast_v4(ire_t *ire, mblk_t *mp, ipha_t *ipha, ip_recv_attr_t *ira) 183011042SErik.Nordmark@Sun.COM { 183111042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_ill; 183211042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ill->ill_ipst; 183311042SErik.Nordmark@Sun.COM netstack_t *ns = ipst->ips_netstack; 183411042SErik.Nordmark@Sun.COM irb_t *irb; 183511042SErik.Nordmark@Sun.COM ire_t *ire1; 183611042SErik.Nordmark@Sun.COM mblk_t *mp1; 183711042SErik.Nordmark@Sun.COM ipha_t *ipha1; 183811042SErik.Nordmark@Sun.COM 183911042SErik.Nordmark@Sun.COM irb = ire->ire_bucket; 184011042SErik.Nordmark@Sun.COM 184111042SErik.Nordmark@Sun.COM /* 184211042SErik.Nordmark@Sun.COM * If we don't have more than one shared-IP zone, or if 184311042SErik.Nordmark@Sun.COM * there can't be more than one IRE_BROADCAST for this 184411042SErik.Nordmark@Sun.COM * IP address, then just set the zoneid and proceed. 184511042SErik.Nordmark@Sun.COM */ 184611042SErik.Nordmark@Sun.COM if (ns->netstack_numzones == 1 || irb->irb_ire_cnt == 1) { 184711042SErik.Nordmark@Sun.COM ira->ira_zoneid = ire->ire_zoneid; 184811042SErik.Nordmark@Sun.COM 184911042SErik.Nordmark@Sun.COM ip_fanout_v4(mp, ipha, ira); 185011042SErik.Nordmark@Sun.COM return; 185111042SErik.Nordmark@Sun.COM } 185211042SErik.Nordmark@Sun.COM irb_refhold(irb); 185311042SErik.Nordmark@Sun.COM for (ire1 = irb->irb_ire; ire1 != NULL; ire1 = ire1->ire_next) { 185411042SErik.Nordmark@Sun.COM /* We do the main IRE after the end of the loop */ 185511042SErik.Nordmark@Sun.COM if (ire1 == ire) 185611042SErik.Nordmark@Sun.COM continue; 185711042SErik.Nordmark@Sun.COM 185811042SErik.Nordmark@Sun.COM /* 185911042SErik.Nordmark@Sun.COM * Only IREs for the same IP address should be in the same 186011042SErik.Nordmark@Sun.COM * bucket. 186111042SErik.Nordmark@Sun.COM * But could have IRE_HOSTs in the case of CGTP. 186211042SErik.Nordmark@Sun.COM */ 186311042SErik.Nordmark@Sun.COM ASSERT(ire1->ire_addr == ire->ire_addr); 186411042SErik.Nordmark@Sun.COM if (!(ire1->ire_type & IRE_BROADCAST)) 186511042SErik.Nordmark@Sun.COM continue; 186611042SErik.Nordmark@Sun.COM 186711042SErik.Nordmark@Sun.COM if (IRE_IS_CONDEMNED(ire1)) 186811042SErik.Nordmark@Sun.COM continue; 186911042SErik.Nordmark@Sun.COM 187011042SErik.Nordmark@Sun.COM mp1 = copymsg(mp); 187111042SErik.Nordmark@Sun.COM if (mp1 == NULL) { 187211042SErik.Nordmark@Sun.COM /* Failed to deliver to one zone */ 187311042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 187411042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 187511042SErik.Nordmark@Sun.COM continue; 187611042SErik.Nordmark@Sun.COM } 187711042SErik.Nordmark@Sun.COM ira->ira_zoneid = ire1->ire_zoneid; 187811042SErik.Nordmark@Sun.COM ipha1 = (ipha_t *)mp1->b_rptr; 187911042SErik.Nordmark@Sun.COM ip_fanout_v4(mp1, ipha1, ira); 188011042SErik.Nordmark@Sun.COM } 188111042SErik.Nordmark@Sun.COM irb_refrele(irb); 188211042SErik.Nordmark@Sun.COM /* Do the main ire */ 188311042SErik.Nordmark@Sun.COM ira->ira_zoneid = ire->ire_zoneid; 188411042SErik.Nordmark@Sun.COM ip_fanout_v4(mp, ipha, ira); 188511042SErik.Nordmark@Sun.COM } 188611042SErik.Nordmark@Sun.COM 188711042SErik.Nordmark@Sun.COM /* 188811042SErik.Nordmark@Sun.COM * Handle multiple zones which want to receive the same multicast packets 188911042SErik.Nordmark@Sun.COM * on this ill by delivering a packet to each of them. 189011042SErik.Nordmark@Sun.COM * 189111042SErik.Nordmark@Sun.COM * Note that for packets delivered to transports we could instead do this 189211042SErik.Nordmark@Sun.COM * as part of the fanout code, but since we need to handle icmp_inbound 189311042SErik.Nordmark@Sun.COM * it is simpler to have multicast work the same as broadcast. 189411042SErik.Nordmark@Sun.COM * 189511042SErik.Nordmark@Sun.COM * The ip_fanout matching for multicast matches based on ilm independent of 189611042SErik.Nordmark@Sun.COM * zoneid since the zoneid restriction is applied when joining a multicast 189711042SErik.Nordmark@Sun.COM * group. 189811042SErik.Nordmark@Sun.COM */ 189911042SErik.Nordmark@Sun.COM /* ARGSUSED */ 190011042SErik.Nordmark@Sun.COM static void 190111042SErik.Nordmark@Sun.COM ip_input_multicast_v4(ire_t *ire, mblk_t *mp, ipha_t *ipha, ip_recv_attr_t *ira) 190211042SErik.Nordmark@Sun.COM { 190311042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_ill; 190411042SErik.Nordmark@Sun.COM iaflags_t iraflags = ira->ira_flags; 190511042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ill->ill_ipst; 190611042SErik.Nordmark@Sun.COM netstack_t *ns = ipst->ips_netstack; 190711042SErik.Nordmark@Sun.COM zoneid_t zoneid; 190811042SErik.Nordmark@Sun.COM mblk_t *mp1; 190911042SErik.Nordmark@Sun.COM ipha_t *ipha1; 191011042SErik.Nordmark@Sun.COM 191111042SErik.Nordmark@Sun.COM /* ire_recv_multicast has switched to the upper ill for IPMP */ 191211042SErik.Nordmark@Sun.COM ASSERT(!IS_UNDER_IPMP(ill)); 191311042SErik.Nordmark@Sun.COM 191411042SErik.Nordmark@Sun.COM /* 191511042SErik.Nordmark@Sun.COM * If we don't have more than one shared-IP zone, or if 191611042SErik.Nordmark@Sun.COM * there are no members in anything but the global zone, 191711042SErik.Nordmark@Sun.COM * then just set the zoneid and proceed. 191811042SErik.Nordmark@Sun.COM */ 191911042SErik.Nordmark@Sun.COM if (ns->netstack_numzones == 1 || 192011042SErik.Nordmark@Sun.COM !ill_hasmembers_otherzones_v4(ill, ipha->ipha_dst, 192111042SErik.Nordmark@Sun.COM GLOBAL_ZONEID)) { 192211042SErik.Nordmark@Sun.COM ira->ira_zoneid = GLOBAL_ZONEID; 192311042SErik.Nordmark@Sun.COM 192411042SErik.Nordmark@Sun.COM /* If sender didn't want this zone to receive it, drop */ 192511042SErik.Nordmark@Sun.COM if ((iraflags & IRAF_NO_LOOP_ZONEID_SET) && 192611042SErik.Nordmark@Sun.COM ira->ira_no_loop_zoneid == ira->ira_zoneid) { 192711042SErik.Nordmark@Sun.COM ip_drop_input("Multicast but wrong zoneid", mp, ill); 192811042SErik.Nordmark@Sun.COM freemsg(mp); 192911042SErik.Nordmark@Sun.COM return; 193011042SErik.Nordmark@Sun.COM } 193111042SErik.Nordmark@Sun.COM ip_fanout_v4(mp, ipha, ira); 193211042SErik.Nordmark@Sun.COM return; 193311042SErik.Nordmark@Sun.COM } 193411042SErik.Nordmark@Sun.COM 193511042SErik.Nordmark@Sun.COM /* 193611042SErik.Nordmark@Sun.COM * Here we loop over all zoneids that have members in the group 193711042SErik.Nordmark@Sun.COM * and deliver a packet to ip_fanout for each zoneid. 193811042SErik.Nordmark@Sun.COM * 193911042SErik.Nordmark@Sun.COM * First find any members in the lowest numeric zoneid by looking for 194011042SErik.Nordmark@Sun.COM * first zoneid larger than -1 (ALL_ZONES). 194111042SErik.Nordmark@Sun.COM * We terminate the loop when we receive -1 (ALL_ZONES). 194211042SErik.Nordmark@Sun.COM */ 194311042SErik.Nordmark@Sun.COM zoneid = ill_hasmembers_nextzone_v4(ill, ipha->ipha_dst, ALL_ZONES); 194411042SErik.Nordmark@Sun.COM for (; zoneid != ALL_ZONES; 194511042SErik.Nordmark@Sun.COM zoneid = ill_hasmembers_nextzone_v4(ill, ipha->ipha_dst, zoneid)) { 194611042SErik.Nordmark@Sun.COM /* 194711042SErik.Nordmark@Sun.COM * Avoid an extra copymsg/freemsg by skipping global zone here 194811042SErik.Nordmark@Sun.COM * and doing that at the end. 194911042SErik.Nordmark@Sun.COM */ 195011042SErik.Nordmark@Sun.COM if (zoneid == GLOBAL_ZONEID) 195111042SErik.Nordmark@Sun.COM continue; 195211042SErik.Nordmark@Sun.COM 195311042SErik.Nordmark@Sun.COM ira->ira_zoneid = zoneid; 195411042SErik.Nordmark@Sun.COM 195511042SErik.Nordmark@Sun.COM /* If sender didn't want this zone to receive it, skip */ 195611042SErik.Nordmark@Sun.COM if ((iraflags & IRAF_NO_LOOP_ZONEID_SET) && 195711042SErik.Nordmark@Sun.COM ira->ira_no_loop_zoneid == ira->ira_zoneid) 195811042SErik.Nordmark@Sun.COM continue; 195911042SErik.Nordmark@Sun.COM 196011042SErik.Nordmark@Sun.COM mp1 = copymsg(mp); 196111042SErik.Nordmark@Sun.COM if (mp1 == NULL) { 196211042SErik.Nordmark@Sun.COM /* Failed to deliver to one zone */ 196311042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 196411042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 196511042SErik.Nordmark@Sun.COM continue; 196611042SErik.Nordmark@Sun.COM } 196711042SErik.Nordmark@Sun.COM ipha1 = (ipha_t *)mp1->b_rptr; 196811042SErik.Nordmark@Sun.COM ip_fanout_v4(mp1, ipha1, ira); 196911042SErik.Nordmark@Sun.COM } 197011042SErik.Nordmark@Sun.COM 197111042SErik.Nordmark@Sun.COM /* Do the main ire */ 197211042SErik.Nordmark@Sun.COM ira->ira_zoneid = GLOBAL_ZONEID; 197311042SErik.Nordmark@Sun.COM /* If sender didn't want this zone to receive it, drop */ 197411042SErik.Nordmark@Sun.COM if ((iraflags & IRAF_NO_LOOP_ZONEID_SET) && 197511042SErik.Nordmark@Sun.COM ira->ira_no_loop_zoneid == ira->ira_zoneid) { 197611042SErik.Nordmark@Sun.COM ip_drop_input("Multicast but wrong zoneid", mp, ill); 197711042SErik.Nordmark@Sun.COM freemsg(mp); 197811042SErik.Nordmark@Sun.COM } else { 197911042SErik.Nordmark@Sun.COM ip_fanout_v4(mp, ipha, ira); 198011042SErik.Nordmark@Sun.COM } 198111042SErik.Nordmark@Sun.COM } 198211042SErik.Nordmark@Sun.COM 198311042SErik.Nordmark@Sun.COM 198411042SErik.Nordmark@Sun.COM /* 198511042SErik.Nordmark@Sun.COM * Determine the zoneid and IRAF_TX_* flags if trusted extensions 198611042SErik.Nordmark@Sun.COM * is in use. Updates ira_zoneid and ira_flags as a result. 198711042SErik.Nordmark@Sun.COM */ 198811042SErik.Nordmark@Sun.COM static void 198911042SErik.Nordmark@Sun.COM ip_fanout_tx_v4(mblk_t *mp, ipha_t *ipha, uint8_t protocol, 199011042SErik.Nordmark@Sun.COM uint_t ip_hdr_length, ip_recv_attr_t *ira) 199111042SErik.Nordmark@Sun.COM { 199211042SErik.Nordmark@Sun.COM uint16_t *up; 199311042SErik.Nordmark@Sun.COM uint16_t lport; 199411042SErik.Nordmark@Sun.COM zoneid_t zoneid; 199511042SErik.Nordmark@Sun.COM 199611042SErik.Nordmark@Sun.COM ASSERT(ira->ira_flags & IRAF_SYSTEM_LABELED); 199711042SErik.Nordmark@Sun.COM 199811042SErik.Nordmark@Sun.COM /* 199911042SErik.Nordmark@Sun.COM * If the packet is unlabeled we might allow read-down 200011042SErik.Nordmark@Sun.COM * for MAC_EXEMPT. Below we clear this if it is a multi-level 200111042SErik.Nordmark@Sun.COM * port (MLP). 200211042SErik.Nordmark@Sun.COM * Note that ira_tsl can be NULL here. 200311042SErik.Nordmark@Sun.COM */ 200411042SErik.Nordmark@Sun.COM if (ira->ira_tsl != NULL && ira->ira_tsl->tsl_flags & TSLF_UNLABELED) 200511042SErik.Nordmark@Sun.COM ira->ira_flags |= IRAF_TX_MAC_EXEMPTABLE; 200611042SErik.Nordmark@Sun.COM 200711042SErik.Nordmark@Sun.COM if (ira->ira_zoneid != ALL_ZONES) 200811042SErik.Nordmark@Sun.COM return; 200911042SErik.Nordmark@Sun.COM 201011042SErik.Nordmark@Sun.COM ira->ira_flags |= IRAF_TX_SHARED_ADDR; 201111042SErik.Nordmark@Sun.COM 201211042SErik.Nordmark@Sun.COM up = (uint16_t *)((uchar_t *)ipha + ip_hdr_length); 201311042SErik.Nordmark@Sun.COM switch (protocol) { 201411042SErik.Nordmark@Sun.COM case IPPROTO_TCP: 201511042SErik.Nordmark@Sun.COM case IPPROTO_SCTP: 201611042SErik.Nordmark@Sun.COM case IPPROTO_UDP: 201711042SErik.Nordmark@Sun.COM /* Caller ensures this */ 201811042SErik.Nordmark@Sun.COM ASSERT(((uchar_t *)ipha) + ip_hdr_length +4 <= mp->b_wptr); 201911042SErik.Nordmark@Sun.COM 202011042SErik.Nordmark@Sun.COM /* 202111042SErik.Nordmark@Sun.COM * Only these transports support MLP. 202211042SErik.Nordmark@Sun.COM * We know their destination port numbers is in 202311042SErik.Nordmark@Sun.COM * the same place in the header. 202411042SErik.Nordmark@Sun.COM */ 202511042SErik.Nordmark@Sun.COM lport = up[1]; 202611042SErik.Nordmark@Sun.COM 202711042SErik.Nordmark@Sun.COM /* 202811042SErik.Nordmark@Sun.COM * No need to handle exclusive-stack zones 202911042SErik.Nordmark@Sun.COM * since ALL_ZONES only applies to the shared IP instance. 203011042SErik.Nordmark@Sun.COM */ 203111042SErik.Nordmark@Sun.COM zoneid = tsol_mlp_findzone(protocol, lport); 203211042SErik.Nordmark@Sun.COM /* 203311042SErik.Nordmark@Sun.COM * If no shared MLP is found, tsol_mlp_findzone returns 203411042SErik.Nordmark@Sun.COM * ALL_ZONES. In that case, we assume it's SLP, and 203511042SErik.Nordmark@Sun.COM * search for the zone based on the packet label. 203611042SErik.Nordmark@Sun.COM * 203711042SErik.Nordmark@Sun.COM * If there is such a zone, we prefer to find a 203811042SErik.Nordmark@Sun.COM * connection in it. Otherwise, we look for a 203911042SErik.Nordmark@Sun.COM * MAC-exempt connection in any zone whose label 204011042SErik.Nordmark@Sun.COM * dominates the default label on the packet. 204111042SErik.Nordmark@Sun.COM */ 204211042SErik.Nordmark@Sun.COM if (zoneid == ALL_ZONES) 204311042SErik.Nordmark@Sun.COM zoneid = tsol_attr_to_zoneid(ira); 204411042SErik.Nordmark@Sun.COM else 204511042SErik.Nordmark@Sun.COM ira->ira_flags &= ~IRAF_TX_MAC_EXEMPTABLE; 204611042SErik.Nordmark@Sun.COM break; 204711042SErik.Nordmark@Sun.COM default: 204811042SErik.Nordmark@Sun.COM /* Handle shared address for other protocols */ 204911042SErik.Nordmark@Sun.COM zoneid = tsol_attr_to_zoneid(ira); 205011042SErik.Nordmark@Sun.COM break; 205111042SErik.Nordmark@Sun.COM } 205211042SErik.Nordmark@Sun.COM ira->ira_zoneid = zoneid; 205311042SErik.Nordmark@Sun.COM } 205411042SErik.Nordmark@Sun.COM 205511042SErik.Nordmark@Sun.COM /* 205611042SErik.Nordmark@Sun.COM * Increment checksum failure statistics 205711042SErik.Nordmark@Sun.COM */ 205811042SErik.Nordmark@Sun.COM static void 205911042SErik.Nordmark@Sun.COM ip_input_cksum_err_v4(uint8_t protocol, uint16_t hck_flags, ill_t *ill) 206011042SErik.Nordmark@Sun.COM { 206111042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ill->ill_ipst; 206211042SErik.Nordmark@Sun.COM 206311042SErik.Nordmark@Sun.COM switch (protocol) { 206411042SErik.Nordmark@Sun.COM case IPPROTO_TCP: 206511042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, tcpIfStatsInErrs); 206611042SErik.Nordmark@Sun.COM 206711042SErik.Nordmark@Sun.COM if (hck_flags & HCK_FULLCKSUM) 206811042SErik.Nordmark@Sun.COM IP_STAT(ipst, ip_tcp_in_full_hw_cksum_err); 206911042SErik.Nordmark@Sun.COM else if (hck_flags & HCK_PARTIALCKSUM) 207011042SErik.Nordmark@Sun.COM IP_STAT(ipst, ip_tcp_in_part_hw_cksum_err); 207111042SErik.Nordmark@Sun.COM else 207211042SErik.Nordmark@Sun.COM IP_STAT(ipst, ip_tcp_in_sw_cksum_err); 207311042SErik.Nordmark@Sun.COM break; 207411042SErik.Nordmark@Sun.COM case IPPROTO_UDP: 207511042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, udpIfStatsInCksumErrs); 207611042SErik.Nordmark@Sun.COM if (hck_flags & HCK_FULLCKSUM) 207711042SErik.Nordmark@Sun.COM IP_STAT(ipst, ip_udp_in_full_hw_cksum_err); 207811042SErik.Nordmark@Sun.COM else if (hck_flags & HCK_PARTIALCKSUM) 207911042SErik.Nordmark@Sun.COM IP_STAT(ipst, ip_udp_in_part_hw_cksum_err); 208011042SErik.Nordmark@Sun.COM else 208111042SErik.Nordmark@Sun.COM IP_STAT(ipst, ip_udp_in_sw_cksum_err); 208211042SErik.Nordmark@Sun.COM break; 208311042SErik.Nordmark@Sun.COM case IPPROTO_ICMP: 208411042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_icmp_mib, icmpInCksumErrs); 208511042SErik.Nordmark@Sun.COM break; 208611042SErik.Nordmark@Sun.COM default: 208711042SErik.Nordmark@Sun.COM ASSERT(0); 208811042SErik.Nordmark@Sun.COM break; 208911042SErik.Nordmark@Sun.COM } 209011042SErik.Nordmark@Sun.COM } 209111042SErik.Nordmark@Sun.COM 209211042SErik.Nordmark@Sun.COM /* Calculate the IPv4 pseudo-header checksum */ 209311042SErik.Nordmark@Sun.COM uint32_t 209411042SErik.Nordmark@Sun.COM ip_input_cksum_pseudo_v4(ipha_t *ipha, ip_recv_attr_t *ira) 209511042SErik.Nordmark@Sun.COM { 209611042SErik.Nordmark@Sun.COM uint_t ulp_len; 209711042SErik.Nordmark@Sun.COM uint32_t cksum; 209811042SErik.Nordmark@Sun.COM uint8_t protocol = ira->ira_protocol; 209911042SErik.Nordmark@Sun.COM uint16_t ip_hdr_length = ira->ira_ip_hdr_length; 210011042SErik.Nordmark@Sun.COM 210111042SErik.Nordmark@Sun.COM #define iphs ((uint16_t *)ipha) 210211042SErik.Nordmark@Sun.COM 210311042SErik.Nordmark@Sun.COM switch (protocol) { 210411042SErik.Nordmark@Sun.COM case IPPROTO_TCP: 210511042SErik.Nordmark@Sun.COM ulp_len = ira->ira_pktlen - ip_hdr_length; 210611042SErik.Nordmark@Sun.COM 210711042SErik.Nordmark@Sun.COM /* Protocol and length */ 210811042SErik.Nordmark@Sun.COM cksum = htons(ulp_len) + IP_TCP_CSUM_COMP; 210911042SErik.Nordmark@Sun.COM /* IP addresses */ 211011042SErik.Nordmark@Sun.COM cksum += iphs[6] + iphs[7] + iphs[8] + iphs[9]; 211111042SErik.Nordmark@Sun.COM break; 211211042SErik.Nordmark@Sun.COM 211311042SErik.Nordmark@Sun.COM case IPPROTO_UDP: { 211411042SErik.Nordmark@Sun.COM udpha_t *udpha; 211511042SErik.Nordmark@Sun.COM 211611042SErik.Nordmark@Sun.COM udpha = (udpha_t *)((uchar_t *)ipha + ip_hdr_length); 211711042SErik.Nordmark@Sun.COM 211811042SErik.Nordmark@Sun.COM /* Protocol and length */ 211911042SErik.Nordmark@Sun.COM cksum = udpha->uha_length + IP_UDP_CSUM_COMP; 212011042SErik.Nordmark@Sun.COM /* IP addresses */ 212111042SErik.Nordmark@Sun.COM cksum += iphs[6] + iphs[7] + iphs[8] + iphs[9]; 212211042SErik.Nordmark@Sun.COM break; 212311042SErik.Nordmark@Sun.COM } 212411042SErik.Nordmark@Sun.COM 212511042SErik.Nordmark@Sun.COM default: 212611042SErik.Nordmark@Sun.COM cksum = 0; 212711042SErik.Nordmark@Sun.COM break; 212811042SErik.Nordmark@Sun.COM } 212911042SErik.Nordmark@Sun.COM #undef iphs 213011042SErik.Nordmark@Sun.COM return (cksum); 213111042SErik.Nordmark@Sun.COM } 213211042SErik.Nordmark@Sun.COM 213311042SErik.Nordmark@Sun.COM 213411042SErik.Nordmark@Sun.COM /* 213511042SErik.Nordmark@Sun.COM * Software verification of the ULP checksums. 213611042SErik.Nordmark@Sun.COM * Returns B_TRUE if ok. 213711042SErik.Nordmark@Sun.COM * Increments statistics of failed. 213811042SErik.Nordmark@Sun.COM */ 213911042SErik.Nordmark@Sun.COM static boolean_t 214011042SErik.Nordmark@Sun.COM ip_input_sw_cksum_v4(mblk_t *mp, ipha_t *ipha, ip_recv_attr_t *ira) 214111042SErik.Nordmark@Sun.COM { 214211042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ira->ira_ill->ill_ipst; 214311042SErik.Nordmark@Sun.COM uint32_t cksum; 214411042SErik.Nordmark@Sun.COM uint8_t protocol = ira->ira_protocol; 214511042SErik.Nordmark@Sun.COM uint16_t ip_hdr_length = ira->ira_ip_hdr_length; 214611042SErik.Nordmark@Sun.COM 214711042SErik.Nordmark@Sun.COM IP_STAT(ipst, ip_in_sw_cksum); 214811042SErik.Nordmark@Sun.COM 214911042SErik.Nordmark@Sun.COM ASSERT(protocol == IPPROTO_TCP || protocol == IPPROTO_UDP); 215011042SErik.Nordmark@Sun.COM 215111042SErik.Nordmark@Sun.COM cksum = ip_input_cksum_pseudo_v4(ipha, ira); 215211042SErik.Nordmark@Sun.COM cksum = IP_CSUM(mp, ip_hdr_length, cksum); 215311042SErik.Nordmark@Sun.COM if (cksum == 0) 215411042SErik.Nordmark@Sun.COM return (B_TRUE); 215511042SErik.Nordmark@Sun.COM 215611042SErik.Nordmark@Sun.COM ip_input_cksum_err_v4(protocol, 0, ira->ira_ill); 215711042SErik.Nordmark@Sun.COM return (B_FALSE); 215811042SErik.Nordmark@Sun.COM } 215911042SErik.Nordmark@Sun.COM 216011042SErik.Nordmark@Sun.COM /* 216111042SErik.Nordmark@Sun.COM * Verify the ULP checksums. 216211042SErik.Nordmark@Sun.COM * Returns B_TRUE if ok, or if the ULP doesn't have a well-defined checksum 216311042SErik.Nordmark@Sun.COM * algorithm. 216411042SErik.Nordmark@Sun.COM * Increments statistics if failed. 216511042SErik.Nordmark@Sun.COM */ 216611042SErik.Nordmark@Sun.COM static boolean_t 216711042SErik.Nordmark@Sun.COM ip_input_cksum_v4(iaflags_t iraflags, mblk_t *mp, ipha_t *ipha, 216811042SErik.Nordmark@Sun.COM ip_recv_attr_t *ira) 216911042SErik.Nordmark@Sun.COM { 217011042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_rill; 217111042SErik.Nordmark@Sun.COM uint16_t hck_flags; 217211042SErik.Nordmark@Sun.COM uint32_t cksum; 217311042SErik.Nordmark@Sun.COM mblk_t *mp1; 217411042SErik.Nordmark@Sun.COM int32_t len; 217511042SErik.Nordmark@Sun.COM uint8_t protocol = ira->ira_protocol; 217611042SErik.Nordmark@Sun.COM uint16_t ip_hdr_length = ira->ira_ip_hdr_length; 217711042SErik.Nordmark@Sun.COM 217811042SErik.Nordmark@Sun.COM 217911042SErik.Nordmark@Sun.COM switch (protocol) { 218011042SErik.Nordmark@Sun.COM case IPPROTO_TCP: 218111042SErik.Nordmark@Sun.COM break; 218211042SErik.Nordmark@Sun.COM 218311042SErik.Nordmark@Sun.COM case IPPROTO_UDP: { 218411042SErik.Nordmark@Sun.COM udpha_t *udpha; 218511042SErik.Nordmark@Sun.COM 218611042SErik.Nordmark@Sun.COM udpha = (udpha_t *)((uchar_t *)ipha + ip_hdr_length); 218711042SErik.Nordmark@Sun.COM if (udpha->uha_checksum == 0) { 218811042SErik.Nordmark@Sun.COM /* Packet doesn't have a UDP checksum */ 218911042SErik.Nordmark@Sun.COM return (B_TRUE); 219011042SErik.Nordmark@Sun.COM } 219111042SErik.Nordmark@Sun.COM break; 219211042SErik.Nordmark@Sun.COM } 219311042SErik.Nordmark@Sun.COM case IPPROTO_SCTP: { 219411042SErik.Nordmark@Sun.COM sctp_hdr_t *sctph; 219511042SErik.Nordmark@Sun.COM uint32_t pktsum; 219611042SErik.Nordmark@Sun.COM 219711042SErik.Nordmark@Sun.COM sctph = (sctp_hdr_t *)((uchar_t *)ipha + ip_hdr_length); 219811042SErik.Nordmark@Sun.COM #ifdef DEBUG 219911042SErik.Nordmark@Sun.COM if (skip_sctp_cksum) 220011042SErik.Nordmark@Sun.COM return (B_TRUE); 220111042SErik.Nordmark@Sun.COM #endif 220211042SErik.Nordmark@Sun.COM pktsum = sctph->sh_chksum; 220311042SErik.Nordmark@Sun.COM sctph->sh_chksum = 0; 220411042SErik.Nordmark@Sun.COM cksum = sctp_cksum(mp, ip_hdr_length); 220511042SErik.Nordmark@Sun.COM sctph->sh_chksum = pktsum; 220611042SErik.Nordmark@Sun.COM if (cksum == pktsum) 220711042SErik.Nordmark@Sun.COM return (B_TRUE); 220811042SErik.Nordmark@Sun.COM 220911042SErik.Nordmark@Sun.COM /* 221011042SErik.Nordmark@Sun.COM * Defer until later whether a bad checksum is ok 221111042SErik.Nordmark@Sun.COM * in order to allow RAW sockets to use Adler checksum 221211042SErik.Nordmark@Sun.COM * with SCTP. 221311042SErik.Nordmark@Sun.COM */ 221411042SErik.Nordmark@Sun.COM ira->ira_flags |= IRAF_SCTP_CSUM_ERR; 221511042SErik.Nordmark@Sun.COM return (B_TRUE); 221611042SErik.Nordmark@Sun.COM } 221711042SErik.Nordmark@Sun.COM 221811042SErik.Nordmark@Sun.COM default: 221911042SErik.Nordmark@Sun.COM /* No ULP checksum to verify. */ 222011042SErik.Nordmark@Sun.COM return (B_TRUE); 222111042SErik.Nordmark@Sun.COM } 222211042SErik.Nordmark@Sun.COM /* 222311042SErik.Nordmark@Sun.COM * Revert to software checksum calculation if the interface 222411042SErik.Nordmark@Sun.COM * isn't capable of checksum offload. 222511042SErik.Nordmark@Sun.COM * We clear DB_CKSUMFLAGS when going through IPsec in ip_fanout. 222611042SErik.Nordmark@Sun.COM * Note: IRAF_NO_HW_CKSUM is not currently used. 222711042SErik.Nordmark@Sun.COM */ 222811042SErik.Nordmark@Sun.COM ASSERT(!IS_IPMP(ill)); 222911042SErik.Nordmark@Sun.COM if ((iraflags & IRAF_NO_HW_CKSUM) || !ILL_HCKSUM_CAPABLE(ill) || 223011042SErik.Nordmark@Sun.COM !dohwcksum) { 223111042SErik.Nordmark@Sun.COM return (ip_input_sw_cksum_v4(mp, ipha, ira)); 223211042SErik.Nordmark@Sun.COM } 223311042SErik.Nordmark@Sun.COM 223411042SErik.Nordmark@Sun.COM /* 223511042SErik.Nordmark@Sun.COM * We apply this for all ULP protocols. Does the HW know to 223611042SErik.Nordmark@Sun.COM * not set the flags for SCTP and other protocols. 223711042SErik.Nordmark@Sun.COM */ 223811042SErik.Nordmark@Sun.COM 223911042SErik.Nordmark@Sun.COM hck_flags = DB_CKSUMFLAGS(mp); 224011042SErik.Nordmark@Sun.COM 224111042SErik.Nordmark@Sun.COM if (hck_flags & HCK_FULLCKSUM) { 224211042SErik.Nordmark@Sun.COM /* 224311042SErik.Nordmark@Sun.COM * Full checksum has been computed by the hardware 224411042SErik.Nordmark@Sun.COM * and has been attached. If the driver wants us to 224511042SErik.Nordmark@Sun.COM * verify the correctness of the attached value, in 224611042SErik.Nordmark@Sun.COM * order to protect against faulty hardware, compare 224711042SErik.Nordmark@Sun.COM * it against -0 (0xFFFF) to see if it's valid. 224811042SErik.Nordmark@Sun.COM */ 224911042SErik.Nordmark@Sun.COM if (hck_flags & HCK_FULLCKSUM_OK) 225011042SErik.Nordmark@Sun.COM return (B_TRUE); 225111042SErik.Nordmark@Sun.COM 225211042SErik.Nordmark@Sun.COM cksum = DB_CKSUM16(mp); 225311042SErik.Nordmark@Sun.COM if (cksum == 0xFFFF) 225411042SErik.Nordmark@Sun.COM return (B_TRUE); 225511042SErik.Nordmark@Sun.COM ip_input_cksum_err_v4(protocol, hck_flags, ira->ira_ill); 225611042SErik.Nordmark@Sun.COM return (B_FALSE); 225711042SErik.Nordmark@Sun.COM } 225811042SErik.Nordmark@Sun.COM 225911042SErik.Nordmark@Sun.COM mp1 = mp->b_cont; 226011042SErik.Nordmark@Sun.COM if ((hck_flags & HCK_PARTIALCKSUM) && 226111042SErik.Nordmark@Sun.COM (mp1 == NULL || mp1->b_cont == NULL) && 226211042SErik.Nordmark@Sun.COM ip_hdr_length >= DB_CKSUMSTART(mp) && 226311042SErik.Nordmark@Sun.COM ((len = ip_hdr_length - DB_CKSUMSTART(mp)) & 1) == 0) { 226411042SErik.Nordmark@Sun.COM uint32_t adj; 226511042SErik.Nordmark@Sun.COM uchar_t *cksum_start; 226611042SErik.Nordmark@Sun.COM 226711042SErik.Nordmark@Sun.COM cksum = ip_input_cksum_pseudo_v4(ipha, ira); 226811042SErik.Nordmark@Sun.COM 226911042SErik.Nordmark@Sun.COM cksum_start = ((uchar_t *)ipha + DB_CKSUMSTART(mp)); 227011042SErik.Nordmark@Sun.COM 227111042SErik.Nordmark@Sun.COM /* 227211042SErik.Nordmark@Sun.COM * Partial checksum has been calculated by hardware 227311042SErik.Nordmark@Sun.COM * and attached to the packet; in addition, any 227411042SErik.Nordmark@Sun.COM * prepended extraneous data is even byte aligned, 227511042SErik.Nordmark@Sun.COM * and there are at most two mblks associated with 227611042SErik.Nordmark@Sun.COM * the packet. If any such data exists, we adjust 227711042SErik.Nordmark@Sun.COM * the checksum; also take care any postpended data. 227811042SErik.Nordmark@Sun.COM */ 227911042SErik.Nordmark@Sun.COM IP_ADJCKSUM_PARTIAL(cksum_start, mp, mp1, len, adj); 228011042SErik.Nordmark@Sun.COM /* 228111042SErik.Nordmark@Sun.COM * One's complement subtract extraneous checksum 228211042SErik.Nordmark@Sun.COM */ 228311042SErik.Nordmark@Sun.COM cksum += DB_CKSUM16(mp); 228411042SErik.Nordmark@Sun.COM if (adj >= cksum) 228511042SErik.Nordmark@Sun.COM cksum = ~(adj - cksum) & 0xFFFF; 228611042SErik.Nordmark@Sun.COM else 228711042SErik.Nordmark@Sun.COM cksum -= adj; 228811042SErik.Nordmark@Sun.COM cksum = (cksum & 0xFFFF) + ((int)cksum >> 16); 228911042SErik.Nordmark@Sun.COM cksum = (cksum & 0xFFFF) + ((int)cksum >> 16); 229011042SErik.Nordmark@Sun.COM if (!(~cksum & 0xFFFF)) 229111042SErik.Nordmark@Sun.COM return (B_TRUE); 229211042SErik.Nordmark@Sun.COM 229311042SErik.Nordmark@Sun.COM ip_input_cksum_err_v4(protocol, hck_flags, ira->ira_ill); 229411042SErik.Nordmark@Sun.COM return (B_FALSE); 229511042SErik.Nordmark@Sun.COM } 229611042SErik.Nordmark@Sun.COM return (ip_input_sw_cksum_v4(mp, ipha, ira)); 229711042SErik.Nordmark@Sun.COM } 229811042SErik.Nordmark@Sun.COM 229911042SErik.Nordmark@Sun.COM 230011042SErik.Nordmark@Sun.COM /* 230111042SErik.Nordmark@Sun.COM * Handle fanout of received packets. 230211042SErik.Nordmark@Sun.COM * Unicast packets that are looped back (from ire_send_local_v4) and packets 230311042SErik.Nordmark@Sun.COM * from the wire are differentiated by checking IRAF_VERIFY_ULP_CKSUM. 230411042SErik.Nordmark@Sun.COM * 230511042SErik.Nordmark@Sun.COM * IPQoS Notes 230611042SErik.Nordmark@Sun.COM * Before sending it to the client, invoke IPPF processing. Policy processing 230711042SErik.Nordmark@Sun.COM * takes place only if the callout_position, IPP_LOCAL_IN, is enabled. 230811042SErik.Nordmark@Sun.COM */ 230911042SErik.Nordmark@Sun.COM void 231011042SErik.Nordmark@Sun.COM ip_fanout_v4(mblk_t *mp, ipha_t *ipha, ip_recv_attr_t *ira) 231111042SErik.Nordmark@Sun.COM { 231211042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_ill; 231311042SErik.Nordmark@Sun.COM iaflags_t iraflags = ira->ira_flags; 231411042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ill->ill_ipst; 231511042SErik.Nordmark@Sun.COM uint8_t protocol = ipha->ipha_protocol; 231611042SErik.Nordmark@Sun.COM conn_t *connp; 231711042SErik.Nordmark@Sun.COM #define rptr ((uchar_t *)ipha) 231811042SErik.Nordmark@Sun.COM uint_t ip_hdr_length; 231911042SErik.Nordmark@Sun.COM uint_t min_ulp_header_length; 232011042SErik.Nordmark@Sun.COM int offset; 232111042SErik.Nordmark@Sun.COM ssize_t len; 232211042SErik.Nordmark@Sun.COM netstack_t *ns = ipst->ips_netstack; 232311042SErik.Nordmark@Sun.COM ipsec_stack_t *ipss = ns->netstack_ipsec; 232411042SErik.Nordmark@Sun.COM ill_t *rill = ira->ira_rill; 232511042SErik.Nordmark@Sun.COM 232611042SErik.Nordmark@Sun.COM ASSERT(ira->ira_pktlen == ntohs(ipha->ipha_length)); 232711042SErik.Nordmark@Sun.COM 232811042SErik.Nordmark@Sun.COM ip_hdr_length = ira->ira_ip_hdr_length; 232911042SErik.Nordmark@Sun.COM ira->ira_protocol = protocol; 233011042SErik.Nordmark@Sun.COM 233111042SErik.Nordmark@Sun.COM /* 233211042SErik.Nordmark@Sun.COM * Time for IPP once we've done reassembly and IPsec. 233311042SErik.Nordmark@Sun.COM * We skip this for loopback packets since we don't do IPQoS 233411042SErik.Nordmark@Sun.COM * on loopback. 233511042SErik.Nordmark@Sun.COM */ 233611042SErik.Nordmark@Sun.COM if (IPP_ENABLED(IPP_LOCAL_IN, ipst) && 233711042SErik.Nordmark@Sun.COM !(iraflags & IRAF_LOOPBACK) && 233811042SErik.Nordmark@Sun.COM (protocol != IPPROTO_ESP || protocol != IPPROTO_AH)) { 233911042SErik.Nordmark@Sun.COM /* 234011042SErik.Nordmark@Sun.COM * Use the interface on which the packet arrived - not where 234111042SErik.Nordmark@Sun.COM * the IP address is hosted. 234211042SErik.Nordmark@Sun.COM */ 234311042SErik.Nordmark@Sun.COM /* ip_process translates an IS_UNDER_IPMP */ 234411042SErik.Nordmark@Sun.COM mp = ip_process(IPP_LOCAL_IN, mp, rill, ill); 234511042SErik.Nordmark@Sun.COM if (mp == NULL) { 234611042SErik.Nordmark@Sun.COM /* ip_drop_packet and MIB done */ 234711042SErik.Nordmark@Sun.COM return; 234811042SErik.Nordmark@Sun.COM } 234911042SErik.Nordmark@Sun.COM } 235011042SErik.Nordmark@Sun.COM 235111042SErik.Nordmark@Sun.COM /* Determine the minimum required size of the upper-layer header */ 235211042SErik.Nordmark@Sun.COM /* Need to do this for at least the set of ULPs that TX handles. */ 235311042SErik.Nordmark@Sun.COM switch (protocol) { 235411042SErik.Nordmark@Sun.COM case IPPROTO_TCP: 235511042SErik.Nordmark@Sun.COM min_ulp_header_length = TCP_MIN_HEADER_LENGTH; 235611042SErik.Nordmark@Sun.COM break; 235711042SErik.Nordmark@Sun.COM case IPPROTO_SCTP: 235811042SErik.Nordmark@Sun.COM min_ulp_header_length = SCTP_COMMON_HDR_LENGTH; 235911042SErik.Nordmark@Sun.COM break; 236011042SErik.Nordmark@Sun.COM case IPPROTO_UDP: 236111042SErik.Nordmark@Sun.COM min_ulp_header_length = UDPH_SIZE; 236211042SErik.Nordmark@Sun.COM break; 236311042SErik.Nordmark@Sun.COM case IPPROTO_ICMP: 236411042SErik.Nordmark@Sun.COM min_ulp_header_length = ICMPH_SIZE; 236511042SErik.Nordmark@Sun.COM break; 236611042SErik.Nordmark@Sun.COM default: 236711042SErik.Nordmark@Sun.COM min_ulp_header_length = 0; 236811042SErik.Nordmark@Sun.COM break; 236911042SErik.Nordmark@Sun.COM } 237011042SErik.Nordmark@Sun.COM /* Make sure we have the min ULP header length */ 237111042SErik.Nordmark@Sun.COM len = mp->b_wptr - rptr; 237211042SErik.Nordmark@Sun.COM if (len < ip_hdr_length + min_ulp_header_length) { 237311042SErik.Nordmark@Sun.COM if (ira->ira_pktlen < ip_hdr_length + min_ulp_header_length) { 237411042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInTruncatedPkts); 237511042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInTruncatedPkts", mp, ill); 237611042SErik.Nordmark@Sun.COM freemsg(mp); 237711042SErik.Nordmark@Sun.COM return; 237811042SErik.Nordmark@Sun.COM } 237911042SErik.Nordmark@Sun.COM IP_STAT(ipst, ip_recv_pullup); 238011042SErik.Nordmark@Sun.COM ipha = ip_pullup(mp, ip_hdr_length + min_ulp_header_length, 238111042SErik.Nordmark@Sun.COM ira); 238211042SErik.Nordmark@Sun.COM if (ipha == NULL) 238311042SErik.Nordmark@Sun.COM goto discard; 238411042SErik.Nordmark@Sun.COM len = mp->b_wptr - rptr; 238511042SErik.Nordmark@Sun.COM } 238611042SErik.Nordmark@Sun.COM 238711042SErik.Nordmark@Sun.COM /* 238811042SErik.Nordmark@Sun.COM * If trusted extensions then determine the zoneid and TX specific 238911042SErik.Nordmark@Sun.COM * ira_flags. 239011042SErik.Nordmark@Sun.COM */ 239111042SErik.Nordmark@Sun.COM if (iraflags & IRAF_SYSTEM_LABELED) { 239211042SErik.Nordmark@Sun.COM /* This can update ira->ira_flags and ira->ira_zoneid */ 239311042SErik.Nordmark@Sun.COM ip_fanout_tx_v4(mp, ipha, protocol, ip_hdr_length, ira); 239411042SErik.Nordmark@Sun.COM iraflags = ira->ira_flags; 239511042SErik.Nordmark@Sun.COM } 239611042SErik.Nordmark@Sun.COM 239711042SErik.Nordmark@Sun.COM 239811042SErik.Nordmark@Sun.COM /* Verify ULP checksum. Handles TCP, UDP, and SCTP */ 239911042SErik.Nordmark@Sun.COM if (iraflags & IRAF_VERIFY_ULP_CKSUM) { 240011042SErik.Nordmark@Sun.COM if (!ip_input_cksum_v4(iraflags, mp, ipha, ira)) { 240111042SErik.Nordmark@Sun.COM /* Bad checksum. Stats are already incremented */ 240211042SErik.Nordmark@Sun.COM ip_drop_input("Bad ULP checksum", mp, ill); 240311042SErik.Nordmark@Sun.COM freemsg(mp); 240411042SErik.Nordmark@Sun.COM return; 240511042SErik.Nordmark@Sun.COM } 240611042SErik.Nordmark@Sun.COM /* IRAF_SCTP_CSUM_ERR could have been set */ 240711042SErik.Nordmark@Sun.COM iraflags = ira->ira_flags; 240811042SErik.Nordmark@Sun.COM } 240911042SErik.Nordmark@Sun.COM switch (protocol) { 241011042SErik.Nordmark@Sun.COM case IPPROTO_TCP: 241111042SErik.Nordmark@Sun.COM /* For TCP, discard broadcast and multicast packets. */ 241211042SErik.Nordmark@Sun.COM if (iraflags & IRAF_MULTIBROADCAST) 241311042SErik.Nordmark@Sun.COM goto discard; 241411042SErik.Nordmark@Sun.COM 241511042SErik.Nordmark@Sun.COM /* First mblk contains IP+TCP headers per above check */ 241611042SErik.Nordmark@Sun.COM ASSERT(len >= ip_hdr_length + TCP_MIN_HEADER_LENGTH); 241711042SErik.Nordmark@Sun.COM 241811042SErik.Nordmark@Sun.COM /* TCP options present? */ 241911042SErik.Nordmark@Sun.COM offset = ((uchar_t *)ipha)[ip_hdr_length + 12] >> 4; 242011042SErik.Nordmark@Sun.COM if (offset != 5) { 242111042SErik.Nordmark@Sun.COM if (offset < 5) 242211042SErik.Nordmark@Sun.COM goto discard; 242311042SErik.Nordmark@Sun.COM 242411042SErik.Nordmark@Sun.COM /* 242511042SErik.Nordmark@Sun.COM * There must be TCP options. 242611042SErik.Nordmark@Sun.COM * Make sure we can grab them. 242711042SErik.Nordmark@Sun.COM */ 242811042SErik.Nordmark@Sun.COM offset <<= 2; 242911042SErik.Nordmark@Sun.COM offset += ip_hdr_length; 243011042SErik.Nordmark@Sun.COM if (len < offset) { 243111042SErik.Nordmark@Sun.COM if (ira->ira_pktlen < offset) { 243211042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, 243311042SErik.Nordmark@Sun.COM ipIfStatsInTruncatedPkts); 243411042SErik.Nordmark@Sun.COM ip_drop_input( 243511042SErik.Nordmark@Sun.COM "ipIfStatsInTruncatedPkts", 243611042SErik.Nordmark@Sun.COM mp, ill); 243711042SErik.Nordmark@Sun.COM freemsg(mp); 243811042SErik.Nordmark@Sun.COM return; 243911042SErik.Nordmark@Sun.COM } 244011042SErik.Nordmark@Sun.COM IP_STAT(ipst, ip_recv_pullup); 244111042SErik.Nordmark@Sun.COM ipha = ip_pullup(mp, offset, ira); 244211042SErik.Nordmark@Sun.COM if (ipha == NULL) 244311042SErik.Nordmark@Sun.COM goto discard; 244411042SErik.Nordmark@Sun.COM len = mp->b_wptr - rptr; 244511042SErik.Nordmark@Sun.COM } 244611042SErik.Nordmark@Sun.COM } 244711042SErik.Nordmark@Sun.COM 244811042SErik.Nordmark@Sun.COM /* 244911042SErik.Nordmark@Sun.COM * Pass up a squeue hint to tcp. 245011042SErik.Nordmark@Sun.COM * If ira_sqp is already set (this is loopback) we leave it 245111042SErik.Nordmark@Sun.COM * alone. 245211042SErik.Nordmark@Sun.COM */ 245311042SErik.Nordmark@Sun.COM if (ira->ira_sqp == NULL) { 245411042SErik.Nordmark@Sun.COM ira->ira_sqp = ip_squeue_get(ira->ira_ring); 245511042SErik.Nordmark@Sun.COM } 245611042SErik.Nordmark@Sun.COM 245711042SErik.Nordmark@Sun.COM /* Look for AF_INET or AF_INET6 that matches */ 245811042SErik.Nordmark@Sun.COM connp = ipcl_classify_v4(mp, IPPROTO_TCP, ip_hdr_length, 245911042SErik.Nordmark@Sun.COM ira, ipst); 246011042SErik.Nordmark@Sun.COM if (connp == NULL) { 246111042SErik.Nordmark@Sun.COM /* Send the TH_RST */ 246211042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers); 246311042SErik.Nordmark@Sun.COM tcp_xmit_listeners_reset(mp, ira, ipst, NULL); 246411042SErik.Nordmark@Sun.COM return; 246511042SErik.Nordmark@Sun.COM } 246611042SErik.Nordmark@Sun.COM if (connp->conn_incoming_ifindex != 0 && 246711042SErik.Nordmark@Sun.COM connp->conn_incoming_ifindex != ira->ira_ruifindex) { 246811042SErik.Nordmark@Sun.COM CONN_DEC_REF(connp); 246911042SErik.Nordmark@Sun.COM 247011042SErik.Nordmark@Sun.COM /* Send the TH_RST */ 247111042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers); 247211042SErik.Nordmark@Sun.COM tcp_xmit_listeners_reset(mp, ira, ipst, NULL); 247311042SErik.Nordmark@Sun.COM return; 247411042SErik.Nordmark@Sun.COM } 247511042SErik.Nordmark@Sun.COM if (CONN_INBOUND_POLICY_PRESENT(connp, ipss) || 247611042SErik.Nordmark@Sun.COM (iraflags & IRAF_IPSEC_SECURE)) { 247711042SErik.Nordmark@Sun.COM mp = ipsec_check_inbound_policy(mp, connp, 247811042SErik.Nordmark@Sun.COM ipha, NULL, ira); 247911042SErik.Nordmark@Sun.COM if (mp == NULL) { 248011042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 248111042SErik.Nordmark@Sun.COM /* Note that mp is NULL */ 248211042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 248311042SErik.Nordmark@Sun.COM CONN_DEC_REF(connp); 248411042SErik.Nordmark@Sun.COM return; 248511042SErik.Nordmark@Sun.COM } 248611042SErik.Nordmark@Sun.COM } 248711042SErik.Nordmark@Sun.COM /* Found a client; up it goes */ 248811042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers); 248911042SErik.Nordmark@Sun.COM ira->ira_ill = ira->ira_rill = NULL; 249011042SErik.Nordmark@Sun.COM if (!IPCL_IS_TCP(connp)) { 249111042SErik.Nordmark@Sun.COM /* Not TCP; must be SOCK_RAW, IPPROTO_TCP */ 249211042SErik.Nordmark@Sun.COM (connp->conn_recv)(connp, mp, NULL, ira); 249311042SErik.Nordmark@Sun.COM CONN_DEC_REF(connp); 249411042SErik.Nordmark@Sun.COM ira->ira_ill = ill; 249511042SErik.Nordmark@Sun.COM ira->ira_rill = rill; 249611042SErik.Nordmark@Sun.COM return; 249711042SErik.Nordmark@Sun.COM } 249811042SErik.Nordmark@Sun.COM 249911042SErik.Nordmark@Sun.COM /* 250011042SErik.Nordmark@Sun.COM * We do different processing whether called from 250111042SErik.Nordmark@Sun.COM * ip_accept_tcp and we match the target, don't match 250211042SErik.Nordmark@Sun.COM * the target, and when we are called by ip_input. 250311042SErik.Nordmark@Sun.COM */ 250411042SErik.Nordmark@Sun.COM if (iraflags & IRAF_TARGET_SQP) { 250511042SErik.Nordmark@Sun.COM if (ira->ira_target_sqp == connp->conn_sqp) { 250611042SErik.Nordmark@Sun.COM mblk_t *attrmp; 250711042SErik.Nordmark@Sun.COM 250811042SErik.Nordmark@Sun.COM attrmp = ip_recv_attr_to_mblk(ira); 250911042SErik.Nordmark@Sun.COM if (attrmp == NULL) { 251011042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, 251111042SErik.Nordmark@Sun.COM ipIfStatsInDiscards); 251211042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", 251311042SErik.Nordmark@Sun.COM mp, ill); 251411042SErik.Nordmark@Sun.COM freemsg(mp); 251511042SErik.Nordmark@Sun.COM CONN_DEC_REF(connp); 251611042SErik.Nordmark@Sun.COM } else { 251711042SErik.Nordmark@Sun.COM SET_SQUEUE(attrmp, connp->conn_recv, 251811042SErik.Nordmark@Sun.COM connp); 251911042SErik.Nordmark@Sun.COM attrmp->b_cont = mp; 252011042SErik.Nordmark@Sun.COM ASSERT(ira->ira_target_sqp_mp == NULL); 252111042SErik.Nordmark@Sun.COM ira->ira_target_sqp_mp = attrmp; 252211042SErik.Nordmark@Sun.COM /* 252311042SErik.Nordmark@Sun.COM * Conn ref release when drained from 252411042SErik.Nordmark@Sun.COM * the squeue. 252511042SErik.Nordmark@Sun.COM */ 252611042SErik.Nordmark@Sun.COM } 252711042SErik.Nordmark@Sun.COM } else { 252811042SErik.Nordmark@Sun.COM SQUEUE_ENTER_ONE(connp->conn_sqp, mp, 252911042SErik.Nordmark@Sun.COM connp->conn_recv, connp, ira, SQ_FILL, 253011042SErik.Nordmark@Sun.COM SQTAG_IP_TCP_INPUT); 253111042SErik.Nordmark@Sun.COM } 253211042SErik.Nordmark@Sun.COM } else { 253311042SErik.Nordmark@Sun.COM SQUEUE_ENTER_ONE(connp->conn_sqp, mp, connp->conn_recv, 253411042SErik.Nordmark@Sun.COM connp, ira, ip_squeue_flag, SQTAG_IP_TCP_INPUT); 253511042SErik.Nordmark@Sun.COM } 253611042SErik.Nordmark@Sun.COM ira->ira_ill = ill; 253711042SErik.Nordmark@Sun.COM ira->ira_rill = rill; 253811042SErik.Nordmark@Sun.COM return; 253911042SErik.Nordmark@Sun.COM 254011042SErik.Nordmark@Sun.COM case IPPROTO_SCTP: { 254111042SErik.Nordmark@Sun.COM sctp_hdr_t *sctph; 254211042SErik.Nordmark@Sun.COM in6_addr_t map_src, map_dst; 254311042SErik.Nordmark@Sun.COM uint32_t ports; /* Source and destination ports */ 254411042SErik.Nordmark@Sun.COM sctp_stack_t *sctps = ipst->ips_netstack->netstack_sctp; 254511042SErik.Nordmark@Sun.COM 254611042SErik.Nordmark@Sun.COM /* For SCTP, discard broadcast and multicast packets. */ 254711042SErik.Nordmark@Sun.COM if (iraflags & IRAF_MULTIBROADCAST) 254811042SErik.Nordmark@Sun.COM goto discard; 254911042SErik.Nordmark@Sun.COM 255011042SErik.Nordmark@Sun.COM /* 255111042SErik.Nordmark@Sun.COM * Since there is no SCTP h/w cksum support yet, just 255211042SErik.Nordmark@Sun.COM * clear the flag. 255311042SErik.Nordmark@Sun.COM */ 255411042SErik.Nordmark@Sun.COM DB_CKSUMFLAGS(mp) = 0; 255511042SErik.Nordmark@Sun.COM 255611042SErik.Nordmark@Sun.COM /* Length ensured above */ 255711042SErik.Nordmark@Sun.COM ASSERT(MBLKL(mp) >= ip_hdr_length + SCTP_COMMON_HDR_LENGTH); 255811042SErik.Nordmark@Sun.COM sctph = (sctp_hdr_t *)(rptr + ip_hdr_length); 255911042SErik.Nordmark@Sun.COM 256011042SErik.Nordmark@Sun.COM /* get the ports */ 256111042SErik.Nordmark@Sun.COM ports = *(uint32_t *)&sctph->sh_sport; 256211042SErik.Nordmark@Sun.COM 256311042SErik.Nordmark@Sun.COM IN6_IPADDR_TO_V4MAPPED(ipha->ipha_dst, &map_dst); 256411042SErik.Nordmark@Sun.COM IN6_IPADDR_TO_V4MAPPED(ipha->ipha_src, &map_src); 256511042SErik.Nordmark@Sun.COM if (iraflags & IRAF_SCTP_CSUM_ERR) { 256611042SErik.Nordmark@Sun.COM /* 256711042SErik.Nordmark@Sun.COM * No potential sctp checksum errors go to the Sun 256811042SErik.Nordmark@Sun.COM * sctp stack however they might be Adler-32 summed 256911042SErik.Nordmark@Sun.COM * packets a userland stack bound to a raw IP socket 257011042SErik.Nordmark@Sun.COM * could reasonably use. Note though that Adler-32 is 257111042SErik.Nordmark@Sun.COM * a long deprecated algorithm and customer sctp 257211042SErik.Nordmark@Sun.COM * networks should eventually migrate to CRC-32 at 257311042SErik.Nordmark@Sun.COM * which time this facility should be removed. 257411042SErik.Nordmark@Sun.COM */ 257511042SErik.Nordmark@Sun.COM ip_fanout_sctp_raw(mp, ipha, NULL, ports, ira); 257611042SErik.Nordmark@Sun.COM return; 257711042SErik.Nordmark@Sun.COM } 257811042SErik.Nordmark@Sun.COM connp = sctp_fanout(&map_src, &map_dst, ports, ira, mp, sctps); 257911042SErik.Nordmark@Sun.COM if (connp == NULL) { 258011042SErik.Nordmark@Sun.COM /* Check for raw socket or OOTB handling */ 258111042SErik.Nordmark@Sun.COM ip_fanout_sctp_raw(mp, ipha, NULL, ports, ira); 258211042SErik.Nordmark@Sun.COM return; 258311042SErik.Nordmark@Sun.COM } 258411042SErik.Nordmark@Sun.COM if (connp->conn_incoming_ifindex != 0 && 258511042SErik.Nordmark@Sun.COM connp->conn_incoming_ifindex != ira->ira_ruifindex) { 258611042SErik.Nordmark@Sun.COM CONN_DEC_REF(connp); 258711042SErik.Nordmark@Sun.COM /* Check for raw socket or OOTB handling */ 258811042SErik.Nordmark@Sun.COM ip_fanout_sctp_raw(mp, ipha, NULL, ports, ira); 258911042SErik.Nordmark@Sun.COM return; 259011042SErik.Nordmark@Sun.COM } 259111042SErik.Nordmark@Sun.COM 259211042SErik.Nordmark@Sun.COM /* Found a client; up it goes */ 259311042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers); 259411042SErik.Nordmark@Sun.COM sctp_input(connp, ipha, NULL, mp, ira); 259511042SErik.Nordmark@Sun.COM /* sctp_input does a rele of the sctp_t */ 259611042SErik.Nordmark@Sun.COM return; 259711042SErik.Nordmark@Sun.COM } 259811042SErik.Nordmark@Sun.COM 259911042SErik.Nordmark@Sun.COM case IPPROTO_UDP: 260011042SErik.Nordmark@Sun.COM /* First mblk contains IP+UDP headers as checked above */ 260111042SErik.Nordmark@Sun.COM ASSERT(MBLKL(mp) >= ip_hdr_length + UDPH_SIZE); 260211042SErik.Nordmark@Sun.COM 260311042SErik.Nordmark@Sun.COM if (iraflags & IRAF_MULTIBROADCAST) { 260411042SErik.Nordmark@Sun.COM uint16_t *up; /* Pointer to ports in ULP header */ 260511042SErik.Nordmark@Sun.COM 260611042SErik.Nordmark@Sun.COM up = (uint16_t *)((uchar_t *)ipha + ip_hdr_length); 260711042SErik.Nordmark@Sun.COM ip_fanout_udp_multi_v4(mp, ipha, up[1], up[0], ira); 260811042SErik.Nordmark@Sun.COM return; 260911042SErik.Nordmark@Sun.COM } 261011042SErik.Nordmark@Sun.COM 261111042SErik.Nordmark@Sun.COM /* Look for AF_INET or AF_INET6 that matches */ 261211042SErik.Nordmark@Sun.COM connp = ipcl_classify_v4(mp, IPPROTO_UDP, ip_hdr_length, 261311042SErik.Nordmark@Sun.COM ira, ipst); 261411042SErik.Nordmark@Sun.COM if (connp == NULL) { 261511042SErik.Nordmark@Sun.COM no_udp_match: 261611042SErik.Nordmark@Sun.COM if (ipst->ips_ipcl_proto_fanout_v4[IPPROTO_UDP]. 261711042SErik.Nordmark@Sun.COM connf_head != NULL) { 261811042SErik.Nordmark@Sun.COM ASSERT(ira->ira_protocol == IPPROTO_UDP); 261911042SErik.Nordmark@Sun.COM ip_fanout_proto_v4(mp, ipha, ira); 262011042SErik.Nordmark@Sun.COM } else { 262111042SErik.Nordmark@Sun.COM ip_fanout_send_icmp_v4(mp, 262211042SErik.Nordmark@Sun.COM ICMP_DEST_UNREACHABLE, 262311042SErik.Nordmark@Sun.COM ICMP_PORT_UNREACHABLE, ira); 262411042SErik.Nordmark@Sun.COM } 262511042SErik.Nordmark@Sun.COM return; 262611042SErik.Nordmark@Sun.COM 262711042SErik.Nordmark@Sun.COM } 262811042SErik.Nordmark@Sun.COM if (connp->conn_incoming_ifindex != 0 && 262911042SErik.Nordmark@Sun.COM connp->conn_incoming_ifindex != ira->ira_ruifindex) { 263011042SErik.Nordmark@Sun.COM CONN_DEC_REF(connp); 263111042SErik.Nordmark@Sun.COM goto no_udp_match; 263211042SErik.Nordmark@Sun.COM } 263311042SErik.Nordmark@Sun.COM if (IPCL_IS_NONSTR(connp) ? connp->conn_flow_cntrld : 263411042SErik.Nordmark@Sun.COM !canputnext(connp->conn_rq)) { 263511042SErik.Nordmark@Sun.COM CONN_DEC_REF(connp); 263611042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, udpIfStatsInOverflows); 263711042SErik.Nordmark@Sun.COM ip_drop_input("udpIfStatsInOverflows", mp, ill); 263811042SErik.Nordmark@Sun.COM freemsg(mp); 263911042SErik.Nordmark@Sun.COM return; 264011042SErik.Nordmark@Sun.COM } 264111042SErik.Nordmark@Sun.COM if (CONN_INBOUND_POLICY_PRESENT(connp, ipss) || 264211042SErik.Nordmark@Sun.COM (iraflags & IRAF_IPSEC_SECURE)) { 264311042SErik.Nordmark@Sun.COM mp = ipsec_check_inbound_policy(mp, connp, 264411042SErik.Nordmark@Sun.COM ipha, NULL, ira); 264511042SErik.Nordmark@Sun.COM if (mp == NULL) { 264611042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 264711042SErik.Nordmark@Sun.COM /* Note that mp is NULL */ 264811042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 264911042SErik.Nordmark@Sun.COM CONN_DEC_REF(connp); 265011042SErik.Nordmark@Sun.COM return; 265111042SErik.Nordmark@Sun.COM } 265211042SErik.Nordmark@Sun.COM } 265311042SErik.Nordmark@Sun.COM /* 265411042SErik.Nordmark@Sun.COM * Remove 0-spi if it's 0, or move everything behind 265511042SErik.Nordmark@Sun.COM * the UDP header over it and forward to ESP via 265611042SErik.Nordmark@Sun.COM * ip_fanout_v4(). 265711042SErik.Nordmark@Sun.COM */ 265811042SErik.Nordmark@Sun.COM if (connp->conn_udp->udp_nat_t_endpoint) { 265911042SErik.Nordmark@Sun.COM if (iraflags & IRAF_IPSEC_SECURE) { 266011042SErik.Nordmark@Sun.COM ip_drop_packet(mp, B_TRUE, ira->ira_ill, 266111042SErik.Nordmark@Sun.COM DROPPER(ipss, ipds_esp_nat_t_ipsec), 266211042SErik.Nordmark@Sun.COM &ipss->ipsec_dropper); 266311042SErik.Nordmark@Sun.COM CONN_DEC_REF(connp); 266411042SErik.Nordmark@Sun.COM return; 266511042SErik.Nordmark@Sun.COM } 266611042SErik.Nordmark@Sun.COM 266711042SErik.Nordmark@Sun.COM mp = zero_spi_check(mp, ira); 266811042SErik.Nordmark@Sun.COM if (mp == NULL) { 266911042SErik.Nordmark@Sun.COM /* 267011042SErik.Nordmark@Sun.COM * Packet was consumed - probably sent to 267111042SErik.Nordmark@Sun.COM * ip_fanout_v4. 267211042SErik.Nordmark@Sun.COM */ 267311042SErik.Nordmark@Sun.COM CONN_DEC_REF(connp); 267411042SErik.Nordmark@Sun.COM return; 267511042SErik.Nordmark@Sun.COM } 267611042SErik.Nordmark@Sun.COM /* Else continue like a normal UDP packet. */ 267711042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr; 267811042SErik.Nordmark@Sun.COM protocol = ipha->ipha_protocol; 267911042SErik.Nordmark@Sun.COM ira->ira_protocol = protocol; 268011042SErik.Nordmark@Sun.COM } 268111042SErik.Nordmark@Sun.COM /* Found a client; up it goes */ 268211042SErik.Nordmark@Sun.COM IP_STAT(ipst, ip_udp_fannorm); 268311042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers); 268411042SErik.Nordmark@Sun.COM ira->ira_ill = ira->ira_rill = NULL; 268511042SErik.Nordmark@Sun.COM (connp->conn_recv)(connp, mp, NULL, ira); 268611042SErik.Nordmark@Sun.COM CONN_DEC_REF(connp); 268711042SErik.Nordmark@Sun.COM ira->ira_ill = ill; 268811042SErik.Nordmark@Sun.COM ira->ira_rill = rill; 268911042SErik.Nordmark@Sun.COM return; 269011042SErik.Nordmark@Sun.COM default: 269111042SErik.Nordmark@Sun.COM break; 269211042SErik.Nordmark@Sun.COM } 269311042SErik.Nordmark@Sun.COM 269411042SErik.Nordmark@Sun.COM /* 269511042SErik.Nordmark@Sun.COM * Clear hardware checksumming flag as it is currently only 269611042SErik.Nordmark@Sun.COM * used by TCP and UDP. 269711042SErik.Nordmark@Sun.COM */ 269811042SErik.Nordmark@Sun.COM DB_CKSUMFLAGS(mp) = 0; 269911042SErik.Nordmark@Sun.COM 270011042SErik.Nordmark@Sun.COM switch (protocol) { 270111042SErik.Nordmark@Sun.COM case IPPROTO_ICMP: 270211042SErik.Nordmark@Sun.COM /* 270311042SErik.Nordmark@Sun.COM * We need to accomodate icmp messages coming in clear 270411042SErik.Nordmark@Sun.COM * until we get everything secure from the wire. If 270511042SErik.Nordmark@Sun.COM * icmp_accept_clear_messages is zero we check with 270611042SErik.Nordmark@Sun.COM * the global policy and act accordingly. If it is 270711042SErik.Nordmark@Sun.COM * non-zero, we accept the message without any checks. 270811042SErik.Nordmark@Sun.COM * But *this does not mean* that this will be delivered 270911042SErik.Nordmark@Sun.COM * to RAW socket clients. By accepting we might send 271011042SErik.Nordmark@Sun.COM * replies back, change our MTU value etc., 271111042SErik.Nordmark@Sun.COM * but delivery to the ULP/clients depends on their 271211042SErik.Nordmark@Sun.COM * policy dispositions. 271311042SErik.Nordmark@Sun.COM */ 271411042SErik.Nordmark@Sun.COM if (ipst->ips_icmp_accept_clear_messages == 0) { 271511042SErik.Nordmark@Sun.COM mp = ipsec_check_global_policy(mp, NULL, 271611042SErik.Nordmark@Sun.COM ipha, NULL, ira, ns); 271711042SErik.Nordmark@Sun.COM if (mp == NULL) 271811042SErik.Nordmark@Sun.COM return; 271911042SErik.Nordmark@Sun.COM } 272011042SErik.Nordmark@Sun.COM 272111042SErik.Nordmark@Sun.COM /* 272211042SErik.Nordmark@Sun.COM * On a labeled system, we have to check whether the zone 272311042SErik.Nordmark@Sun.COM * itself is permitted to receive raw traffic. 272411042SErik.Nordmark@Sun.COM */ 272511042SErik.Nordmark@Sun.COM if (ira->ira_flags & IRAF_SYSTEM_LABELED) { 272611042SErik.Nordmark@Sun.COM if (!tsol_can_accept_raw(mp, ira, B_FALSE)) { 272711042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_icmp_mib, icmpInErrors); 272811042SErik.Nordmark@Sun.COM ip_drop_input("tsol_can_accept_raw", mp, ill); 272911042SErik.Nordmark@Sun.COM freemsg(mp); 273011042SErik.Nordmark@Sun.COM return; 273111042SErik.Nordmark@Sun.COM } 273211042SErik.Nordmark@Sun.COM } 273311042SErik.Nordmark@Sun.COM 273411042SErik.Nordmark@Sun.COM /* 273511042SErik.Nordmark@Sun.COM * ICMP header checksum, including checksum field, 273611042SErik.Nordmark@Sun.COM * should be zero. 273711042SErik.Nordmark@Sun.COM */ 273811042SErik.Nordmark@Sun.COM if (IP_CSUM(mp, ip_hdr_length, 0)) { 273911042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_icmp_mib, icmpInCksumErrs); 274011042SErik.Nordmark@Sun.COM ip_drop_input("icmpInCksumErrs", mp, ill); 274111042SErik.Nordmark@Sun.COM freemsg(mp); 274211042SErik.Nordmark@Sun.COM return; 274311042SErik.Nordmark@Sun.COM } 274411042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers); 274511042SErik.Nordmark@Sun.COM mp = icmp_inbound_v4(mp, ira); 274611042SErik.Nordmark@Sun.COM if (mp == NULL) { 274711042SErik.Nordmark@Sun.COM /* No need to pass to RAW sockets */ 274811042SErik.Nordmark@Sun.COM return; 274911042SErik.Nordmark@Sun.COM } 275011042SErik.Nordmark@Sun.COM break; 275111042SErik.Nordmark@Sun.COM 275211042SErik.Nordmark@Sun.COM case IPPROTO_IGMP: 275311042SErik.Nordmark@Sun.COM /* 275411042SErik.Nordmark@Sun.COM * If we are not willing to accept IGMP packets in clear, 275511042SErik.Nordmark@Sun.COM * then check with global policy. 275611042SErik.Nordmark@Sun.COM */ 275711042SErik.Nordmark@Sun.COM if (ipst->ips_igmp_accept_clear_messages == 0) { 275811042SErik.Nordmark@Sun.COM mp = ipsec_check_global_policy(mp, NULL, 275911042SErik.Nordmark@Sun.COM ipha, NULL, ira, ns); 276011042SErik.Nordmark@Sun.COM if (mp == NULL) 276111042SErik.Nordmark@Sun.COM return; 276211042SErik.Nordmark@Sun.COM } 276311042SErik.Nordmark@Sun.COM if ((ira->ira_flags & IRAF_SYSTEM_LABELED) && 276411042SErik.Nordmark@Sun.COM !tsol_can_accept_raw(mp, ira, B_TRUE)) { 276511042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 276611042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 276711042SErik.Nordmark@Sun.COM freemsg(mp); 276811042SErik.Nordmark@Sun.COM return; 276911042SErik.Nordmark@Sun.COM } 277011042SErik.Nordmark@Sun.COM /* 277111042SErik.Nordmark@Sun.COM * Validate checksum 277211042SErik.Nordmark@Sun.COM */ 277311042SErik.Nordmark@Sun.COM if (IP_CSUM(mp, ip_hdr_length, 0)) { 277411042SErik.Nordmark@Sun.COM ++ipst->ips_igmpstat.igps_rcv_badsum; 277511042SErik.Nordmark@Sun.COM ip_drop_input("igps_rcv_badsum", mp, ill); 277611042SErik.Nordmark@Sun.COM freemsg(mp); 277711042SErik.Nordmark@Sun.COM return; 277811042SErik.Nordmark@Sun.COM } 277911042SErik.Nordmark@Sun.COM 278011042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers); 278111042SErik.Nordmark@Sun.COM mp = igmp_input(mp, ira); 278211042SErik.Nordmark@Sun.COM if (mp == NULL) { 278311042SErik.Nordmark@Sun.COM /* Bad packet - discarded by igmp_input */ 278411042SErik.Nordmark@Sun.COM return; 278511042SErik.Nordmark@Sun.COM } 278611042SErik.Nordmark@Sun.COM break; 278711042SErik.Nordmark@Sun.COM case IPPROTO_PIM: 278811042SErik.Nordmark@Sun.COM /* 278911042SErik.Nordmark@Sun.COM * If we are not willing to accept PIM packets in clear, 279011042SErik.Nordmark@Sun.COM * then check with global policy. 279111042SErik.Nordmark@Sun.COM */ 279211042SErik.Nordmark@Sun.COM if (ipst->ips_pim_accept_clear_messages == 0) { 279311042SErik.Nordmark@Sun.COM mp = ipsec_check_global_policy(mp, NULL, 279411042SErik.Nordmark@Sun.COM ipha, NULL, ira, ns); 279511042SErik.Nordmark@Sun.COM if (mp == NULL) 279611042SErik.Nordmark@Sun.COM return; 279711042SErik.Nordmark@Sun.COM } 279811042SErik.Nordmark@Sun.COM if ((ira->ira_flags & IRAF_SYSTEM_LABELED) && 279911042SErik.Nordmark@Sun.COM !tsol_can_accept_raw(mp, ira, B_TRUE)) { 280011042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 280111042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 280211042SErik.Nordmark@Sun.COM freemsg(mp); 280311042SErik.Nordmark@Sun.COM return; 280411042SErik.Nordmark@Sun.COM } 280511042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers); 280611042SErik.Nordmark@Sun.COM 280711042SErik.Nordmark@Sun.COM /* Checksum is verified in pim_input */ 280811042SErik.Nordmark@Sun.COM mp = pim_input(mp, ira); 280911042SErik.Nordmark@Sun.COM if (mp == NULL) { 281011042SErik.Nordmark@Sun.COM /* Bad packet - discarded by pim_input */ 281111042SErik.Nordmark@Sun.COM return; 281211042SErik.Nordmark@Sun.COM } 281311042SErik.Nordmark@Sun.COM break; 281411042SErik.Nordmark@Sun.COM case IPPROTO_AH: 281511042SErik.Nordmark@Sun.COM case IPPROTO_ESP: { 281611042SErik.Nordmark@Sun.COM /* 281711042SErik.Nordmark@Sun.COM * Fast path for AH/ESP. 281811042SErik.Nordmark@Sun.COM */ 281911042SErik.Nordmark@Sun.COM netstack_t *ns = ipst->ips_netstack; 282011042SErik.Nordmark@Sun.COM ipsec_stack_t *ipss = ns->netstack_ipsec; 282111042SErik.Nordmark@Sun.COM 282211042SErik.Nordmark@Sun.COM IP_STAT(ipst, ipsec_proto_ahesp); 282311042SErik.Nordmark@Sun.COM 282411042SErik.Nordmark@Sun.COM if (!ipsec_loaded(ipss)) { 282511042SErik.Nordmark@Sun.COM ip_proto_not_sup(mp, ira); 282611042SErik.Nordmark@Sun.COM return; 282711042SErik.Nordmark@Sun.COM } 282811042SErik.Nordmark@Sun.COM 282911042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers); 283011042SErik.Nordmark@Sun.COM /* select inbound SA and have IPsec process the pkt */ 283111042SErik.Nordmark@Sun.COM if (protocol == IPPROTO_ESP) { 283211042SErik.Nordmark@Sun.COM esph_t *esph; 283311042SErik.Nordmark@Sun.COM boolean_t esp_in_udp_sa; 283411042SErik.Nordmark@Sun.COM boolean_t esp_in_udp_packet; 283511042SErik.Nordmark@Sun.COM 283611042SErik.Nordmark@Sun.COM mp = ipsec_inbound_esp_sa(mp, ira, &esph); 283711042SErik.Nordmark@Sun.COM if (mp == NULL) 283811042SErik.Nordmark@Sun.COM return; 283911042SErik.Nordmark@Sun.COM 284011042SErik.Nordmark@Sun.COM ASSERT(esph != NULL); 284111042SErik.Nordmark@Sun.COM ASSERT(ira->ira_flags & IRAF_IPSEC_SECURE); 284211042SErik.Nordmark@Sun.COM ASSERT(ira->ira_ipsec_esp_sa != NULL); 284311042SErik.Nordmark@Sun.COM ASSERT(ira->ira_ipsec_esp_sa->ipsa_input_func != NULL); 284411042SErik.Nordmark@Sun.COM 284511042SErik.Nordmark@Sun.COM esp_in_udp_sa = ((ira->ira_ipsec_esp_sa->ipsa_flags & 284611042SErik.Nordmark@Sun.COM IPSA_F_NATT) != 0); 284711042SErik.Nordmark@Sun.COM esp_in_udp_packet = 284811042SErik.Nordmark@Sun.COM (ira->ira_flags & IRAF_ESP_UDP_PORTS) != 0; 284911042SErik.Nordmark@Sun.COM 285011042SErik.Nordmark@Sun.COM /* 285111042SErik.Nordmark@Sun.COM * The following is a fancy, but quick, way of saying: 285211042SErik.Nordmark@Sun.COM * ESP-in-UDP SA and Raw ESP packet --> drop 285311042SErik.Nordmark@Sun.COM * OR 285411042SErik.Nordmark@Sun.COM * ESP SA and ESP-in-UDP packet --> drop 285511042SErik.Nordmark@Sun.COM */ 285611042SErik.Nordmark@Sun.COM if (esp_in_udp_sa != esp_in_udp_packet) { 285711042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 285811042SErik.Nordmark@Sun.COM ip_drop_packet(mp, B_TRUE, ira->ira_ill, 285911042SErik.Nordmark@Sun.COM DROPPER(ipss, ipds_esp_no_sa), 286011042SErik.Nordmark@Sun.COM &ipss->ipsec_dropper); 286111042SErik.Nordmark@Sun.COM return; 286211042SErik.Nordmark@Sun.COM } 286311042SErik.Nordmark@Sun.COM mp = ira->ira_ipsec_esp_sa->ipsa_input_func(mp, esph, 286411042SErik.Nordmark@Sun.COM ira); 286511042SErik.Nordmark@Sun.COM } else { 286611042SErik.Nordmark@Sun.COM ah_t *ah; 286711042SErik.Nordmark@Sun.COM 286811042SErik.Nordmark@Sun.COM mp = ipsec_inbound_ah_sa(mp, ira, &ah); 286911042SErik.Nordmark@Sun.COM if (mp == NULL) 287011042SErik.Nordmark@Sun.COM return; 287111042SErik.Nordmark@Sun.COM 287211042SErik.Nordmark@Sun.COM ASSERT(ah != NULL); 287311042SErik.Nordmark@Sun.COM ASSERT(ira->ira_flags & IRAF_IPSEC_SECURE); 287411042SErik.Nordmark@Sun.COM ASSERT(ira->ira_ipsec_ah_sa != NULL); 287511042SErik.Nordmark@Sun.COM ASSERT(ira->ira_ipsec_ah_sa->ipsa_input_func != NULL); 287611042SErik.Nordmark@Sun.COM mp = ira->ira_ipsec_ah_sa->ipsa_input_func(mp, ah, 287711042SErik.Nordmark@Sun.COM ira); 287811042SErik.Nordmark@Sun.COM } 287911042SErik.Nordmark@Sun.COM 288011042SErik.Nordmark@Sun.COM if (mp == NULL) { 288111042SErik.Nordmark@Sun.COM /* 288211042SErik.Nordmark@Sun.COM * Either it failed or is pending. In the former case 288311042SErik.Nordmark@Sun.COM * ipIfStatsInDiscards was increased. 288411042SErik.Nordmark@Sun.COM */ 288511042SErik.Nordmark@Sun.COM return; 288611042SErik.Nordmark@Sun.COM } 288711042SErik.Nordmark@Sun.COM /* we're done with IPsec processing, send it up */ 288811042SErik.Nordmark@Sun.COM ip_input_post_ipsec(mp, ira); 288911042SErik.Nordmark@Sun.COM return; 289011042SErik.Nordmark@Sun.COM } 289111042SErik.Nordmark@Sun.COM case IPPROTO_ENCAP: { 289211042SErik.Nordmark@Sun.COM ipha_t *inner_ipha; 289311042SErik.Nordmark@Sun.COM 289411042SErik.Nordmark@Sun.COM /* 289511042SErik.Nordmark@Sun.COM * Handle self-encapsulated packets (IP-in-IP where 289611042SErik.Nordmark@Sun.COM * the inner addresses == the outer addresses). 289711042SErik.Nordmark@Sun.COM */ 289811042SErik.Nordmark@Sun.COM if ((uchar_t *)ipha + ip_hdr_length + sizeof (ipha_t) > 289911042SErik.Nordmark@Sun.COM mp->b_wptr) { 290011042SErik.Nordmark@Sun.COM if (ira->ira_pktlen < 290111042SErik.Nordmark@Sun.COM ip_hdr_length + sizeof (ipha_t)) { 290211042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, 290311042SErik.Nordmark@Sun.COM ipIfStatsInTruncatedPkts); 290411042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInTruncatedPkts", 290511042SErik.Nordmark@Sun.COM mp, ill); 290611042SErik.Nordmark@Sun.COM freemsg(mp); 290711042SErik.Nordmark@Sun.COM return; 290811042SErik.Nordmark@Sun.COM } 290911042SErik.Nordmark@Sun.COM ipha = ip_pullup(mp, (uchar_t *)ipha + ip_hdr_length + 291011042SErik.Nordmark@Sun.COM sizeof (ipha_t) - mp->b_rptr, ira); 291111042SErik.Nordmark@Sun.COM if (ipha == NULL) { 291211042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 291311042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 291411042SErik.Nordmark@Sun.COM freemsg(mp); 291511042SErik.Nordmark@Sun.COM return; 291611042SErik.Nordmark@Sun.COM } 291711042SErik.Nordmark@Sun.COM } 291811042SErik.Nordmark@Sun.COM inner_ipha = (ipha_t *)((uchar_t *)ipha + ip_hdr_length); 291911042SErik.Nordmark@Sun.COM /* 292011042SErik.Nordmark@Sun.COM * Check the sanity of the inner IP header. 292111042SErik.Nordmark@Sun.COM */ 292211042SErik.Nordmark@Sun.COM if ((IPH_HDR_VERSION(inner_ipha) != IPV4_VERSION)) { 292311042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 292411042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 292511042SErik.Nordmark@Sun.COM freemsg(mp); 292611042SErik.Nordmark@Sun.COM return; 292711042SErik.Nordmark@Sun.COM } 292811042SErik.Nordmark@Sun.COM if (IPH_HDR_LENGTH(inner_ipha) < sizeof (ipha_t)) { 292911042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 293011042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 293111042SErik.Nordmark@Sun.COM freemsg(mp); 293211042SErik.Nordmark@Sun.COM return; 293311042SErik.Nordmark@Sun.COM } 293411042SErik.Nordmark@Sun.COM if (inner_ipha->ipha_src != ipha->ipha_src || 293511042SErik.Nordmark@Sun.COM inner_ipha->ipha_dst != ipha->ipha_dst) { 293611042SErik.Nordmark@Sun.COM /* We fallthru to iptun fanout below */ 293711042SErik.Nordmark@Sun.COM goto iptun; 293811042SErik.Nordmark@Sun.COM } 293911042SErik.Nordmark@Sun.COM 294011042SErik.Nordmark@Sun.COM /* 294111042SErik.Nordmark@Sun.COM * Self-encapsulated tunnel packet. Remove 294211042SErik.Nordmark@Sun.COM * the outer IP header and fanout again. 294311042SErik.Nordmark@Sun.COM * We also need to make sure that the inner 294411042SErik.Nordmark@Sun.COM * header is pulled up until options. 294511042SErik.Nordmark@Sun.COM */ 294611042SErik.Nordmark@Sun.COM mp->b_rptr = (uchar_t *)inner_ipha; 294711042SErik.Nordmark@Sun.COM ipha = inner_ipha; 294811042SErik.Nordmark@Sun.COM ip_hdr_length = IPH_HDR_LENGTH(ipha); 294911042SErik.Nordmark@Sun.COM if ((uchar_t *)ipha + ip_hdr_length > mp->b_wptr) { 295011042SErik.Nordmark@Sun.COM if (ira->ira_pktlen < 295111042SErik.Nordmark@Sun.COM (uchar_t *)ipha + ip_hdr_length - mp->b_rptr) { 295211042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, 295311042SErik.Nordmark@Sun.COM ipIfStatsInTruncatedPkts); 295411042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInTruncatedPkts", 295511042SErik.Nordmark@Sun.COM mp, ill); 295611042SErik.Nordmark@Sun.COM freemsg(mp); 295711042SErik.Nordmark@Sun.COM return; 295811042SErik.Nordmark@Sun.COM } 295911042SErik.Nordmark@Sun.COM ipha = ip_pullup(mp, 296011042SErik.Nordmark@Sun.COM (uchar_t *)ipha + ip_hdr_length - mp->b_rptr, ira); 296111042SErik.Nordmark@Sun.COM if (ipha == NULL) { 296211042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 296311042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 296411042SErik.Nordmark@Sun.COM freemsg(mp); 296511042SErik.Nordmark@Sun.COM return; 296611042SErik.Nordmark@Sun.COM } 296711042SErik.Nordmark@Sun.COM } 296811042SErik.Nordmark@Sun.COM if (ip_hdr_length > sizeof (ipha_t)) { 296911042SErik.Nordmark@Sun.COM /* We got options on the inner packet. */ 297011042SErik.Nordmark@Sun.COM ipaddr_t dst = ipha->ipha_dst; 297111042SErik.Nordmark@Sun.COM int error = 0; 297211042SErik.Nordmark@Sun.COM 297311042SErik.Nordmark@Sun.COM dst = ip_input_options(ipha, dst, mp, ira, &error); 297411042SErik.Nordmark@Sun.COM if (error != 0) { 297511042SErik.Nordmark@Sun.COM /* 297611042SErik.Nordmark@Sun.COM * An ICMP error has been sent and the packet 297711042SErik.Nordmark@Sun.COM * has been dropped. 297811042SErik.Nordmark@Sun.COM */ 297911042SErik.Nordmark@Sun.COM return; 298011042SErik.Nordmark@Sun.COM } 298111042SErik.Nordmark@Sun.COM if (dst != ipha->ipha_dst) { 298211042SErik.Nordmark@Sun.COM /* 298311042SErik.Nordmark@Sun.COM * Someone put a source-route in 298411042SErik.Nordmark@Sun.COM * the inside header of a self- 298511042SErik.Nordmark@Sun.COM * encapsulated packet. Drop it 298611042SErik.Nordmark@Sun.COM * with extreme prejudice and let 298711042SErik.Nordmark@Sun.COM * the sender know. 298811042SErik.Nordmark@Sun.COM */ 298911042SErik.Nordmark@Sun.COM ip_drop_input("ICMP_SOURCE_ROUTE_FAILED", 299011042SErik.Nordmark@Sun.COM mp, ill); 299111042SErik.Nordmark@Sun.COM icmp_unreachable(mp, ICMP_SOURCE_ROUTE_FAILED, 299211042SErik.Nordmark@Sun.COM ira); 299311042SErik.Nordmark@Sun.COM return; 299411042SErik.Nordmark@Sun.COM } 299511042SErik.Nordmark@Sun.COM } 299611042SErik.Nordmark@Sun.COM if (!(ira->ira_flags & IRAF_IPSEC_SECURE)) { 299711042SErik.Nordmark@Sun.COM /* 299811042SErik.Nordmark@Sun.COM * This means that somebody is sending 299911042SErik.Nordmark@Sun.COM * Self-encapsualted packets without AH/ESP. 300011042SErik.Nordmark@Sun.COM * 300111042SErik.Nordmark@Sun.COM * Send this packet to find a tunnel endpoint. 300211042SErik.Nordmark@Sun.COM * if I can't find one, an ICMP 300311042SErik.Nordmark@Sun.COM * PROTOCOL_UNREACHABLE will get sent. 300411042SErik.Nordmark@Sun.COM */ 300511042SErik.Nordmark@Sun.COM protocol = ipha->ipha_protocol; 300611042SErik.Nordmark@Sun.COM ira->ira_protocol = protocol; 300711042SErik.Nordmark@Sun.COM goto iptun; 300811042SErik.Nordmark@Sun.COM } 300911042SErik.Nordmark@Sun.COM 301011042SErik.Nordmark@Sun.COM /* Update based on removed IP header */ 301111042SErik.Nordmark@Sun.COM ira->ira_ip_hdr_length = ip_hdr_length; 301211042SErik.Nordmark@Sun.COM ira->ira_pktlen = ntohs(ipha->ipha_length); 301311042SErik.Nordmark@Sun.COM 301411042SErik.Nordmark@Sun.COM if (ira->ira_flags & IRAF_IPSEC_DECAPS) { 301511042SErik.Nordmark@Sun.COM /* 301611042SErik.Nordmark@Sun.COM * This packet is self-encapsulated multiple 301711042SErik.Nordmark@Sun.COM * times. We don't want to recurse infinitely. 301811042SErik.Nordmark@Sun.COM * To keep it simple, drop the packet. 301911042SErik.Nordmark@Sun.COM */ 302011042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 302111042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 302211042SErik.Nordmark@Sun.COM freemsg(mp); 302311042SErik.Nordmark@Sun.COM return; 302411042SErik.Nordmark@Sun.COM } 302511042SErik.Nordmark@Sun.COM ASSERT(ira->ira_flags & IRAF_IPSEC_SECURE); 302611042SErik.Nordmark@Sun.COM ira->ira_flags |= IRAF_IPSEC_DECAPS; 302711042SErik.Nordmark@Sun.COM 302811042SErik.Nordmark@Sun.COM ip_input_post_ipsec(mp, ira); 302911042SErik.Nordmark@Sun.COM return; 303011042SErik.Nordmark@Sun.COM } 303111042SErik.Nordmark@Sun.COM 303211042SErik.Nordmark@Sun.COM iptun: /* IPPROTO_ENCAPS that is not self-encapsulated */ 303311042SErik.Nordmark@Sun.COM case IPPROTO_IPV6: 303411042SErik.Nordmark@Sun.COM /* iptun will verify trusted label */ 303511042SErik.Nordmark@Sun.COM connp = ipcl_classify_v4(mp, protocol, ip_hdr_length, 303611042SErik.Nordmark@Sun.COM ira, ipst); 303711042SErik.Nordmark@Sun.COM if (connp != NULL) { 303811042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers); 303911042SErik.Nordmark@Sun.COM ira->ira_ill = ira->ira_rill = NULL; 304011042SErik.Nordmark@Sun.COM (connp->conn_recv)(connp, mp, NULL, ira); 304111042SErik.Nordmark@Sun.COM CONN_DEC_REF(connp); 304211042SErik.Nordmark@Sun.COM ira->ira_ill = ill; 304311042SErik.Nordmark@Sun.COM ira->ira_rill = rill; 304411042SErik.Nordmark@Sun.COM return; 304511042SErik.Nordmark@Sun.COM } 304611042SErik.Nordmark@Sun.COM /* FALLTHRU */ 304711042SErik.Nordmark@Sun.COM default: 304811042SErik.Nordmark@Sun.COM /* 304911042SErik.Nordmark@Sun.COM * On a labeled system, we have to check whether the zone 305011042SErik.Nordmark@Sun.COM * itself is permitted to receive raw traffic. 305111042SErik.Nordmark@Sun.COM */ 305211042SErik.Nordmark@Sun.COM if (ira->ira_flags & IRAF_SYSTEM_LABELED) { 305311042SErik.Nordmark@Sun.COM if (!tsol_can_accept_raw(mp, ira, B_FALSE)) { 305411042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 305511042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 305611042SErik.Nordmark@Sun.COM freemsg(mp); 305711042SErik.Nordmark@Sun.COM return; 305811042SErik.Nordmark@Sun.COM } 305911042SErik.Nordmark@Sun.COM } 306011042SErik.Nordmark@Sun.COM break; 306111042SErik.Nordmark@Sun.COM } 306211042SErik.Nordmark@Sun.COM 306311042SErik.Nordmark@Sun.COM /* 306411042SErik.Nordmark@Sun.COM * The above input functions may have returned the pulled up message. 306511042SErik.Nordmark@Sun.COM * So ipha need to be reinitialized. 306611042SErik.Nordmark@Sun.COM */ 306711042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr; 306811042SErik.Nordmark@Sun.COM ira->ira_protocol = protocol = ipha->ipha_protocol; 306911042SErik.Nordmark@Sun.COM if (ipst->ips_ipcl_proto_fanout_v4[protocol].connf_head == NULL) { 307011042SErik.Nordmark@Sun.COM /* 307111042SErik.Nordmark@Sun.COM * No user-level listener for these packets packets. 307211042SErik.Nordmark@Sun.COM * Check for IPPROTO_ENCAP... 307311042SErik.Nordmark@Sun.COM */ 307411042SErik.Nordmark@Sun.COM if (protocol == IPPROTO_ENCAP && ipst->ips_ip_g_mrouter) { 307511042SErik.Nordmark@Sun.COM /* 307611042SErik.Nordmark@Sun.COM * Check policy here, 307711042SErik.Nordmark@Sun.COM * THEN ship off to ip_mroute_decap(). 307811042SErik.Nordmark@Sun.COM * 307911042SErik.Nordmark@Sun.COM * BTW, If I match a configured IP-in-IP 308011042SErik.Nordmark@Sun.COM * tunnel above, this path will not be reached, and 308111042SErik.Nordmark@Sun.COM * ip_mroute_decap will never be called. 308211042SErik.Nordmark@Sun.COM */ 308311042SErik.Nordmark@Sun.COM mp = ipsec_check_global_policy(mp, connp, 308411042SErik.Nordmark@Sun.COM ipha, NULL, ira, ns); 308511042SErik.Nordmark@Sun.COM if (mp != NULL) { 308611042SErik.Nordmark@Sun.COM ip_mroute_decap(mp, ira); 308711042SErik.Nordmark@Sun.COM } /* Else we already freed everything! */ 308811042SErik.Nordmark@Sun.COM } else { 308911042SErik.Nordmark@Sun.COM ip_proto_not_sup(mp, ira); 309011042SErik.Nordmark@Sun.COM } 309111042SErik.Nordmark@Sun.COM return; 309211042SErik.Nordmark@Sun.COM } 309311042SErik.Nordmark@Sun.COM 309411042SErik.Nordmark@Sun.COM /* 309511042SErik.Nordmark@Sun.COM * Handle fanout to raw sockets. There 309611042SErik.Nordmark@Sun.COM * can be more than one stream bound to a particular 309711042SErik.Nordmark@Sun.COM * protocol. When this is the case, each one gets a copy 309811042SErik.Nordmark@Sun.COM * of any incoming packets. 309911042SErik.Nordmark@Sun.COM */ 310011042SErik.Nordmark@Sun.COM ASSERT(ira->ira_protocol == ipha->ipha_protocol); 310111042SErik.Nordmark@Sun.COM ip_fanout_proto_v4(mp, ipha, ira); 310211042SErik.Nordmark@Sun.COM return; 310311042SErik.Nordmark@Sun.COM 310411042SErik.Nordmark@Sun.COM discard: 310511042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 310611042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 310711042SErik.Nordmark@Sun.COM freemsg(mp); 310811042SErik.Nordmark@Sun.COM #undef rptr 310911042SErik.Nordmark@Sun.COM } 3110