ip6_input.c revision a5407c02d5ed61b29481b9b71f1307d7ebec9e5c
2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved
2N/A */
2N/A/* Copyright (c) 1990 Mentat Inc. */
2N/A
2N/A#include <sys/types.h>
2N/A#include <sys/stream.h>
2N/A#include <sys/dlpi.h>
2N/A#include <sys/stropts.h>
2N/A#include <sys/sysmacros.h>
2N/A#include <sys/strsubr.h>
2N/A#include <sys/strlog.h>
2N/A#include <sys/strsun.h>
2N/A#include <sys/zone.h>
2N/A#define _SUN_TPI_VERSION 2
2N/A#include <sys/tihdr.h>
2N/A#include <sys/xti_inet.h>
2N/A#include <sys/ddi.h>
2N/A#include <sys/sunddi.h>
2N/A#include <sys/cmn_err.h>
2N/A#include <sys/debug.h>
2N/A#include <sys/kobj.h>
2N/A#include <sys/modctl.h>
2N/A#include <sys/atomic.h>
2N/A#include <sys/policy.h>
2N/A#include <sys/priv.h>
2N/A
2N/A#include <sys/systm.h>
2N/A#include <sys/param.h>
2N/A#include <sys/kmem.h>
2N/A#include <sys/sdt.h>
2N/A#include <sys/socket.h>
2N/A#include <sys/vtrace.h>
2N/A#include <sys/isa_defs.h>
2N/A#include <sys/mac.h>
2N/A#include <net/if.h>
2N/A#include <net/if_arp.h>
2N/A#include <net/route.h>
2N/A#include <sys/sockio.h>
2N/A#include <netinet/in.h>
2N/A#include <net/if_dl.h>
2N/A
2N/A#include <inet/common.h>
2N/A#include <inet/mi.h>
2N/A#include <inet/mib2.h>
2N/A#include <inet/nd.h>
2N/A#include <inet/arp.h>
2N/A#include <inet/snmpcom.h>
2N/A#include <inet/kstatcom.h>
2N/A
2N/A#include <netinet/igmp_var.h>
2N/A#include <netinet/ip6.h>
2N/A#include <netinet/icmp6.h>
2N/A#include <netinet/sctp.h>
2N/A
2N/A#include <inet/ip.h>
2N/A#include <inet/ip_impl.h>
2N/A#include <inet/ip6.h>
2N/A#include <inet/ip6_asp.h>
2N/A#include <inet/optcom.h>
2N/A#include <inet/tcp.h>
2N/A#include <inet/tcp_impl.h>
2N/A#include <inet/ip_multi.h>
2N/A#include <inet/ip_if.h>
2N/A#include <inet/ip_ire.h>
2N/A#include <inet/ip_ftable.h>
2N/A#include <inet/ip_rts.h>
2N/A#include <inet/ip_ndp.h>
2N/A#include <inet/ip_listutils.h>
2N/A#include <netinet/igmp.h>
2N/A#include <netinet/ip_mroute.h>
2N/A#include <inet/ipp_common.h>
2N/A
2N/A#include <net/pfkeyv2.h>
2N/A#include <inet/sadb.h>
2N/A#include <inet/ipsec_impl.h>
2N/A#include <inet/ipdrop.h>
2N/A#include <inet/ip_netinfo.h>
2N/A#include <inet/ilb_ip.h>
2N/A#include <sys/squeue_impl.h>
2N/A#include <sys/squeue.h>
2N/A
2N/A#include <sys/ethernet.h>
2N/A#include <net/if_types.h>
2N/A#include <sys/cpuvar.h>
2N/A
2N/A#include <ipp/ipp.h>
2N/A#include <ipp/ipp_impl.h>
2N/A#include <ipp/ipgpc/ipgpc.h>
2N/A
2N/A#include <sys/pattr.h>
2N/A#include <inet/ipclassifier.h>
2N/A#include <inet/sctp_ip.h>
2N/A#include <inet/sctp/sctp_impl.h>
2N/A#include <inet/udp_impl.h>
2N/A#include <sys/sunddi.h>
2N/A
2N/A#include <sys/tsol/label.h>
2N/A#include <sys/tsol/tnet.h>
2N/A
2N/A#include <sys/clock_impl.h> /* For LBOLT_FASTPATH{,64} */
2N/A
2N/A#ifdef DEBUG
2N/Aextern boolean_t skip_sctp_cksum;
2N/A#endif
2N/A
2N/Astatic void ip_input_local_v6(ire_t *, mblk_t *, ip6_t *, ip_recv_attr_t *);
2N/A
2N/Astatic void ip_input_multicast_v6(ire_t *, mblk_t *, ip6_t *,
2N/A ip_recv_attr_t *);
2N/A
2N/A#pragma inline(ip_input_common_v6, ip_input_local_v6, ip_forward_xmit_v6)
2N/A
2N/A/*
2N/A * Direct read side procedure capable of dealing with chains. GLDv3 based
2N/A * drivers call this function directly with mblk chains while STREAMS
2N/A * read side procedure ip_rput() calls this for single packet with ip_ring
2N/A * set to NULL to process one packet at a time.
2N/A *
2N/A * The ill will always be valid if this function is called directly from
2N/A * the driver.
2N/A *
2N/A * If ip_input_v6() is called from GLDv3:
2N/A *
2N/A * - This must be a non-VLAN IP stream.
2N/A * - 'mp' is either an untagged or a special priority-tagged packet.
2N/A * - Any VLAN tag that was in the MAC header has been stripped.
2N/A *
2N/A * If the IP header in packet is not 32-bit aligned, every message in the
2N/A * chain will be aligned before further operations. This is required on SPARC
2N/A * platform.
2N/A */
2N/Avoid
2N/Aip_input_v6(ill_t *ill, ill_rx_ring_t *ip_ring, mblk_t *mp_chain,
2N/A struct mac_header_info_s *mhip)
2N/A{
2N/A (void) ip_input_common_v6(ill, ip_ring, mp_chain, mhip, NULL, NULL,
2N/A NULL);
2N/A}
2N/A
2N/A/*
2N/A * ip_accept_tcp_v6() - This function is called by the squeue when it retrieves
2N/A * a chain of packets in the poll mode. The packets have gone through the
2N/A * data link processing but not IP processing. For performance and latency
2N/A * reasons, the squeue wants to process the chain in line instead of feeding
2N/A * it back via ip_input path.
2N/A *
2N/A * We set up the ip_recv_attr_t with IRAF_TARGET_SQP to that ip_fanout_v6
2N/A * will pass back any TCP packets matching the target sqp to
2N/A * ip_input_common_v6 using ira_target_sqp_mp. Other packets are handled by
2N/A * ip_input_v6 and ip_fanout_v6 as normal.
2N/A * The TCP packets that match the target squeue are returned to the caller
2N/A * as a b_next chain after each packet has been prepend with an mblk
2N/A * from ip_recv_attr_to_mblk.
2N/A */
2N/Amblk_t *
2N/Aip_accept_tcp_v6(ill_t *ill, ill_rx_ring_t *ip_ring, squeue_t *target_sqp,
2N/A mblk_t *mp_chain, mblk_t **last, uint_t *cnt)
2N/A{
2N/A return (ip_input_common_v6(ill, ip_ring, mp_chain, NULL, target_sqp,
2N/A last, cnt));
2N/A}
2N/A
2N/A/*
2N/A * Used by ip_input_v6 and ip_accept_tcp_v6
2N/A * The last three arguments are only used by ip_accept_tcp_v6, and mhip is
2N/A * only used by ip_input_v6.
2N/A */
2N/Amblk_t *
2N/Aip_input_common_v6(ill_t *ill, ill_rx_ring_t *ip_ring, mblk_t *mp_chain,
2N/A struct mac_header_info_s *mhip, squeue_t *target_sqp,
2N/A mblk_t **last, uint_t *cnt)
2N/A{
2N/A mblk_t *mp;
2N/A ip6_t *ip6h;
2N/A ip_recv_attr_t iras; /* Receive attributes */
2N/A rtc_t rtc;
2N/A iaflags_t chain_flags = 0; /* Fixed for chain */
2N/A mblk_t *ahead = NULL; /* Accepted head */
2N/A mblk_t *atail = NULL; /* Accepted tail */
2N/A uint_t acnt = 0; /* Accepted count */
2N/A
2N/A ASSERT(mp_chain != NULL);
2N/A ASSERT(ill != NULL);
2N/A
2N/A /* These ones do not change as we loop over packets */
2N/A iras.ira_ill = iras.ira_rill = ill;
2N/A iras.ira_ruifindex = ill->ill_phyint->phyint_ifindex;
2N/A iras.ira_rifindex = iras.ira_ruifindex;
2N/A iras.ira_sqp = NULL;
2N/A iras.ira_ring = ip_ring;
2N/A /* For ECMP and outbound transmit ring selection */
2N/A iras.ira_xmit_hint = ILL_RING_TO_XMIT_HINT(ip_ring);
2N/A
2N/A iras.ira_target_sqp = target_sqp;
2N/A iras.ira_target_sqp_mp = NULL;
2N/A if (target_sqp != NULL)
2N/A chain_flags |= IRAF_TARGET_SQP;
2N/A
2N/A /*
2N/A * We try to have a mhip pointer when possible, but
2N/A * it might be NULL in some cases. In those cases we
2N/A * have to assume unicast.
2N/A */
2N/A iras.ira_mhip = mhip;
2N/A iras.ira_flags = 0;
2N/A if (mhip != NULL) {
2N/A switch (mhip->mhi_dsttype) {
2N/A case MAC_ADDRTYPE_MULTICAST :
2N/A chain_flags |= IRAF_L2DST_MULTICAST;
2N/A break;
2N/A case MAC_ADDRTYPE_BROADCAST :
2N/A chain_flags |= IRAF_L2DST_BROADCAST;
2N/A break;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Initialize the one-element route cache.
2N/A *
2N/A * We do ire caching from one iteration to
2N/A * another. In the event the packet chain contains
2N/A * all packets from the same dst, this caching saves
2N/A * an ire_route_recursive for each of the succeeding
2N/A * packets in a packet chain.
2N/A */
2N/A rtc.rtc_ire = NULL;
2N/A rtc.rtc_ip6addr = ipv6_all_zeros;
2N/A
2N/A /* Loop over b_next */
2N/A for (mp = mp_chain; mp != NULL; mp = mp_chain) {
2N/A mp_chain = mp->b_next;
2N/A mp->b_next = NULL;
2N/A
2N/A /*
2N/A * if db_ref > 1 then copymsg and free original. Packet
2N/A * may be changed and we do not want the other entity
2N/A * who has a reference to this message to trip over the
2N/A * changes. This is a blind change because trying to
2N/A * catch all places that might change the packet is too
2N/A * difficult.
2N/A *
2N/A * This corresponds to the fast path case, where we have
2N/A * a chain of M_DATA mblks. We check the db_ref count
2N/A * of only the 1st data block in the mblk chain. There
2N/A * doesn't seem to be a reason why a device driver would
2N/A * send up data with varying db_ref counts in the mblk
2N/A * chain. In any case the Fast path is a private
2N/A * interface, and our drivers don't do such a thing.
2N/A * Given the above assumption, there is no need to walk
2N/A * down the entire mblk chain (which could have a
2N/A * potential performance problem)
2N/A *
2N/A * The "(DB_REF(mp) > 1)" check was moved from ip_rput()
2N/A * to here because of exclusive ip stacks and vnics.
2N/A * Packets transmitted from exclusive stack over vnic
2N/A * can have db_ref > 1 and when it gets looped back to
2N/A * another vnic in a different zone, you have ip_input()
2N/A * getting dblks with db_ref > 1. So if someone
2N/A * complains of TCP performance under this scenario,
2N/A * take a serious look here on the impact of copymsg().
2N/A */
2N/A if (DB_REF(mp) > 1) {
2N/A if ((mp = ip_fix_dbref(mp, &iras)) == NULL)
2N/A continue;
2N/A }
2N/A
2N/A /*
2N/A * IP header ptr not aligned?
2N/A * OR IP header not complete in first mblk
2N/A */
2N/A ip6h = (ip6_t *)mp->b_rptr;
2N/A if (!OK_32PTR(ip6h) || MBLKL(mp) < IPV6_HDR_LEN) {
2N/A mp = ip_check_and_align_header(mp, IPV6_HDR_LEN, &iras);
2N/A if (mp == NULL)
2N/A continue;
2N/A ip6h = (ip6_t *)mp->b_rptr;
2N/A }
2N/A
2N/A /* Protect against a mix of Ethertypes and IP versions */
2N/A if (IPH_HDR_VERSION(ip6h) != IPV6_VERSION) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInHdrErrors);
2N/A ip_drop_input("ipIfStatsInHdrErrors", mp, ill);
2N/A freemsg(mp);
2N/A /* mhip might point into 1st packet in the chain. */
2N/A iras.ira_mhip = NULL;
2N/A continue;
2N/A }
2N/A
2N/A /*
2N/A * Check for Martian addrs; we have to explicitly
2N/A * test for for zero dst since this is also used as
2N/A * an indication that the rtc is not used.
2N/A */
2N/A if (IN6_IS_ADDR_UNSPECIFIED(&ip6h->ip6_dst)) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInAddrErrors);
2N/A ip_drop_input("ipIfStatsInAddrErrors", mp, ill);
2N/A freemsg(mp);
2N/A /* mhip might point into 1st packet in the chain. */
2N/A iras.ira_mhip = NULL;
2N/A continue;
2N/A }
2N/A /*
2N/A * Keep L2SRC from a previous packet in chain since mhip
2N/A * might point into an earlier packet in the chain.
2N/A */
2N/A chain_flags |= (iras.ira_flags & IRAF_L2SRC_SET);
2N/A
2N/A iras.ira_flags = IRAF_VERIFY_ULP_CKSUM | chain_flags;
2N/A iras.ira_free_flags = 0;
2N/A iras.ira_cred = NULL;
2N/A iras.ira_cpid = NOPID;
2N/A iras.ira_tsl = NULL;
2N/A iras.ira_zoneid = ALL_ZONES; /* Default for forwarding */
2N/A
2N/A /*
2N/A * We must count all incoming packets, even if they end
2N/A * up being dropped later on. Defer counting bytes until
2N/A * we have the whole IP header in first mblk.
2N/A */
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInReceives);
2N/A
2N/A iras.ira_pktlen = ntohs(ip6h->ip6_plen) + IPV6_HDR_LEN;
2N/A UPDATE_MIB(ill->ill_ip_mib, ipIfStatsHCInOctets,
2N/A iras.ira_pktlen);
2N/A
2N/A /*
2N/A * Call one of:
2N/A * ill_input_full_v6
2N/A * ill_input_short_v6
2N/A * The former is used in the case of TX. See ill_set_inputfn().
2N/A */
2N/A (*ill->ill_inputfn)(mp, ip6h, &ip6h->ip6_dst, &iras, &rtc);
2N/A
2N/A /* Any references to clean up? No hold on ira_ill */
2N/A if (iras.ira_flags & (IRAF_IPSEC_SECURE|IRAF_SYSTEM_LABELED))
2N/A ira_cleanup(&iras, B_FALSE);
2N/A
2N/A if (iras.ira_target_sqp_mp != NULL) {
2N/A /* Better be called from ip_accept_tcp */
2N/A ASSERT(target_sqp != NULL);
2N/A
2N/A /* Found one packet to accept */
2N/A mp = iras.ira_target_sqp_mp;
2N/A iras.ira_target_sqp_mp = NULL;
2N/A ASSERT(ip_recv_attr_is_mblk(mp));
2N/A
2N/A if (atail != NULL)
2N/A atail->b_next = mp;
2N/A else
2N/A ahead = mp;
2N/A atail = mp;
2N/A acnt++;
2N/A mp = NULL;
2N/A }
2N/A /* mhip might point into 1st packet in the chain. */
2N/A iras.ira_mhip = NULL;
2N/A }
2N/A /* Any remaining references to the route cache? */
2N/A if (rtc.rtc_ire != NULL) {
2N/A ASSERT(!IN6_IS_ADDR_UNSPECIFIED(&rtc.rtc_ip6addr));
2N/A ire_refrele(rtc.rtc_ire);
2N/A }
2N/A
2N/A if (ahead != NULL) {
2N/A /* Better be called from ip_accept_tcp */
2N/A ASSERT(target_sqp != NULL);
2N/A *last = atail;
2N/A *cnt = acnt;
2N/A return (ahead);
2N/A }
2N/A
2N/A return (NULL);
2N/A}
2N/A
2N/A/*
2N/A * This input function is used when
2N/A * - is_system_labeled()
2N/A *
2N/A * Note that for IPv6 CGTP filtering is handled only when receiving fragment
2N/A * headers, and RSVP uses router alert options, thus we don't need anything
2N/A * extra for them.
2N/A */
2N/Avoid
2N/Aill_input_full_v6(mblk_t *mp, void *iph_arg, void *nexthop_arg,
2N/A ip_recv_attr_t *ira, rtc_t *rtc)
2N/A{
2N/A ip6_t *ip6h = (ip6_t *)iph_arg;
2N/A in6_addr_t *nexthop = (in6_addr_t *)nexthop_arg;
2N/A ill_t *ill = ira->ira_ill;
2N/A
2N/A ASSERT(ira->ira_tsl == NULL);
2N/A
2N/A /*
2N/A * Attach any necessary label information to
2N/A * this packet
2N/A */
2N/A if (is_system_labeled()) {
2N/A ira->ira_flags |= IRAF_SYSTEM_LABELED;
2N/A
2N/A /*
2N/A * This updates ira_cred, ira_tsl and ira_free_flags based
2N/A * on the label.
2N/A */
2N/A if (!tsol_get_pkt_label(mp, IPV6_VERSION, ira)) {
2N/A if (ip6opt_ls != 0)
2N/A ip0dbg(("tsol_get_pkt_label v6 failed\n"));
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
2N/A ip_drop_input("ipIfStatsInDiscards", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A /* Note that ira_tsl can be NULL here. */
2N/A
2N/A /* tsol_get_pkt_label sometimes does pullupmsg */
2N/A ip6h = (ip6_t *)mp->b_rptr;
2N/A }
2N/A ill_input_short_v6(mp, ip6h, nexthop, ira, rtc);
2N/A}
2N/A
2N/A/*
2N/A * Check for IPv6 addresses that should not appear on the wire
2N/A * as either source or destination.
2N/A * If we ever implement Stateless IPv6 Translators (SIIT) we'd have
2N/A * to revisit the IPv4-mapped part.
2N/A */
2N/Astatic boolean_t
2N/Aip6_bad_address(in6_addr_t *addr, boolean_t is_src)
2N/A{
2N/A if (IN6_IS_ADDR_V4MAPPED(addr)) {
2N/A ip1dbg(("ip_input_v6: pkt with IPv4-mapped addr"));
2N/A return (B_TRUE);
2N/A }
2N/A if (IN6_IS_ADDR_LOOPBACK(addr)) {
2N/A ip1dbg(("ip_input_v6: pkt with loopback addr"));
2N/A return (B_TRUE);
2N/A }
2N/A if (!is_src && IN6_IS_ADDR_UNSPECIFIED(addr)) {
2N/A /*
2N/A * having :: in the src is ok: it's used for DAD.
2N/A */
2N/A ip1dbg(("ip_input_v6: pkt with unspecified addr"));
2N/A return (B_TRUE);
2N/A }
2N/A return (B_FALSE);
2N/A}
2N/A
2N/A/*
2N/A * Routing lookup for IPv6 link-locals.
2N/A * First we look on the inbound interface, then we check for IPMP and
2N/A * look on the upper interface.
2N/A * We update ira_ruifindex if we find the IRE on the upper interface.
2N/A */
2N/Astatic ire_t *
2N/Aire_linklocal(const in6_addr_t *nexthop, ill_t *ill, ip_recv_attr_t *ira,
2N/A uint_t irr_flags, ip_stack_t *ipst)
2N/A{
2N/A int match_flags = MATCH_IRE_SECATTR | MATCH_IRE_ILL;
2N/A ire_t *ire;
2N/A
2N/A ASSERT(IN6_IS_ADDR_LINKLOCAL(nexthop));
2N/A ire = ire_route_recursive_v6(nexthop, 0, ill, ALL_ZONES, ira->ira_tsl,
2N/A match_flags, irr_flags, ira->ira_xmit_hint, ipst, NULL, NULL, NULL);
2N/A if (!(ire->ire_flags & (RTF_REJECT|RTF_BLACKHOLE)) ||
2N/A !IS_UNDER_IPMP(ill))
2N/A return (ire);
2N/A
2N/A /*
2N/A * When we are using IMP we need to look for an IRE on both the
2N/A * under and upper interfaces since there are different
2N/A * link-local addresses for the under and upper.
2N/A */
2N/A ill = ipmp_ill_hold_ipmp_ill(ill);
2N/A if (ill == NULL)
2N/A return (ire);
2N/A
2N/A ira->ira_ruifindex = ill->ill_phyint->phyint_ifindex;
2N/A
2N/A ire_refrele(ire);
2N/A ire = ire_route_recursive_v6(nexthop, 0, ill, ALL_ZONES, ira->ira_tsl,
2N/A match_flags, irr_flags, ira->ira_xmit_hint, ipst, NULL, NULL, NULL);
2N/A ill_refrele(ill);
2N/A return (ire);
2N/A}
2N/A
2N/A/*
2N/A * This is the tail-end of the full receive side packet handling.
2N/A * It can be used directly when the configuration is simple.
2N/A */
2N/Avoid
2N/Aill_input_short_v6(mblk_t *mp, void *iph_arg, void *nexthop_arg,
2N/A ip_recv_attr_t *ira, rtc_t *rtc)
2N/A{
2N/A ire_t *ire;
2N/A ill_t *ill = ira->ira_ill;
2N/A ip_stack_t *ipst = ill->ill_ipst;
2N/A uint_t pkt_len;
2N/A ssize_t len;
2N/A ip6_t *ip6h = (ip6_t *)iph_arg;
2N/A in6_addr_t nexthop = *(in6_addr_t *)nexthop_arg;
2N/A ilb_stack_t *ilbs = ipst->ips_netstack->netstack_ilb;
2N/A uint_t irr_flags;
2N/A#define rptr ((uchar_t *)ip6h)
2N/A
2N/A ASSERT(DB_TYPE(mp) == M_DATA);
2N/A
2N/A /*
2N/A * Check for source/dest being a bad address: loopback, any, or
2N/A * v4mapped. All of them start with a 64 bits of zero.
2N/A */
2N/A if (ip6h->ip6_src.s6_addr32[0] == 0 &&
2N/A ip6h->ip6_src.s6_addr32[1] == 0) {
2N/A if (ip6_bad_address(&ip6h->ip6_src, B_TRUE)) {
2N/A ip1dbg(("ip_input_v6: pkt with bad src addr\n"));
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInAddrErrors);
2N/A ip_drop_input("ipIfStatsInAddrErrors", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A }
2N/A if (ip6h->ip6_dst.s6_addr32[0] == 0 &&
2N/A ip6h->ip6_dst.s6_addr32[1] == 0) {
2N/A if (ip6_bad_address(&ip6h->ip6_dst, B_FALSE)) {
2N/A ip1dbg(("ip_input_v6: pkt with bad dst addr\n"));
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInAddrErrors);
2N/A ip_drop_input("ipIfStatsInAddrErrors", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A }
2N/A
2N/A len = mp->b_wptr - rptr;
2N/A pkt_len = ira->ira_pktlen;
2N/A
2N/A /* multiple mblk or too short */
2N/A len -= pkt_len;
2N/A if (len != 0) {
2N/A mp = ip_check_length(mp, rptr, len, pkt_len, IPV6_HDR_LEN, ira);
2N/A if (mp == NULL)
2N/A return;
2N/A ip6h = (ip6_t *)mp->b_rptr;
2N/A }
2N/A
2N/A DTRACE_IP7(receive, mblk_t *, mp, conn_t *, NULL, void_ip_t *,
2N/A ip6h, __dtrace_ipsr_ill_t *, ill, ipha_t *, NULL, ip6_t *, ip6h,
2N/A int, 0);
2N/A /*
2N/A * The event for packets being received from a 'physical'
2N/A * interface is placed after validation of the source and/or
2N/A * destination address as being local so that packets can be
2N/A * redirected to loopback addresses using ipnat.
2N/A */
2N/A DTRACE_PROBE4(ip6__physical__in__start,
2N/A ill_t *, ill, ill_t *, NULL,
2N/A ip6_t *, ip6h, mblk_t *, mp);
2N/A
2N/A if (HOOKS6_INTERESTED_PHYSICAL_IN(ipst)) {
2N/A int ll_multicast = 0;
2N/A int error;
2N/A in6_addr_t orig_dst = ip6h->ip6_dst;
2N/A
2N/A if (ira->ira_flags & IRAF_L2DST_MULTICAST)
2N/A ll_multicast = HPE_MULTICAST;
2N/A else if (ira->ira_flags & IRAF_L2DST_BROADCAST)
2N/A ll_multicast = HPE_BROADCAST;
2N/A
2N/A FW_HOOKS6(ipst->ips_ip6_physical_in_event,
2N/A ipst->ips_ipv6firewall_physical_in,
2N/A ill, NULL, ip6h, mp, mp, ll_multicast, ipst, error);
2N/A
2N/A DTRACE_PROBE1(ip6__physical__in__end, mblk_t *, mp);
2N/A
2N/A if (mp == NULL)
2N/A return;
2N/A
2N/A /* The length could have changed */
2N/A ip6h = (ip6_t *)mp->b_rptr;
2N/A ira->ira_pktlen = ntohs(ip6h->ip6_plen) + IPV6_HDR_LEN;
2N/A pkt_len = ira->ira_pktlen;
2N/A
2N/A /*
2N/A * In case the destination changed we override any previous
2N/A * change to nexthop.
2N/A */
2N/A if (!IN6_ARE_ADDR_EQUAL(&orig_dst, &ip6h->ip6_dst))
2N/A nexthop = ip6h->ip6_dst;
2N/A
2N/A if (IN6_IS_ADDR_UNSPECIFIED(&nexthop)) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInAddrErrors);
2N/A ip_drop_input("ipIfStatsInAddrErrors", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A
2N/A }
2N/A
2N/A if (ipst->ips_ip6_observe.he_interested) {
2N/A zoneid_t dzone;
2N/A
2N/A /*
2N/A * On the inbound path the src zone will be unknown as
2N/A * this packet has come from the wire.
2N/A */
2N/A dzone = ip_get_zoneid_v6(&nexthop, mp, ill, ira, ALL_ZONES);
2N/A ipobs_hook(mp, IPOBS_HOOK_INBOUND, ALL_ZONES, dzone, ill, ipst);
2N/A }
2N/A
2N/A if ((ip6h->ip6_vcf & IPV6_VERS_AND_FLOW_MASK) !=
2N/A IPV6_DEFAULT_VERS_AND_FLOW) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInHdrErrors);
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInWrongIPVersion);
2N/A ip_drop_input("ipIfStatsInWrongIPVersion", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A
2N/A /*
2N/A * For IPv6 we update ira_ip_hdr_length and ira_protocol as
2N/A * we parse the headers, starting with the hop-by-hop options header.
2N/A */
2N/A ira->ira_ip_hdr_length = IPV6_HDR_LEN;
2N/A if ((ira->ira_protocol = ip6h->ip6_nxt) == IPPROTO_HOPOPTS) {
2N/A ip6_hbh_t *hbhhdr;
2N/A uint_t ehdrlen;
2N/A uint8_t *optptr;
2N/A
2N/A if (pkt_len < IPV6_HDR_LEN + MIN_EHDR_LEN) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInTruncatedPkts);
2N/A ip_drop_input("ipIfStatsInTruncatedPkts", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A if (mp->b_cont != NULL &&
2N/A rptr + IPV6_HDR_LEN + MIN_EHDR_LEN > mp->b_wptr) {
2N/A ip6h = ip_pullup(mp, IPV6_HDR_LEN + MIN_EHDR_LEN, ira);
2N/A if (ip6h == NULL) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
2N/A ip_drop_input("ipIfStatsInDiscards", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A }
2N/A hbhhdr = (ip6_hbh_t *)&ip6h[1];
2N/A ehdrlen = 8 * (hbhhdr->ip6h_len + 1);
2N/A
2N/A if (pkt_len < IPV6_HDR_LEN + ehdrlen) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInTruncatedPkts);
2N/A ip_drop_input("ipIfStatsInTruncatedPkts", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A if (mp->b_cont != NULL &&
2N/A rptr + IPV6_HDR_LEN + ehdrlen > mp->b_wptr) {
2N/A ip6h = ip_pullup(mp, IPV6_HDR_LEN + ehdrlen, ira);
2N/A if (ip6h == NULL) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
2N/A ip_drop_input("ipIfStatsInDiscards", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A hbhhdr = (ip6_hbh_t *)&ip6h[1];
2N/A }
2N/A
2N/A /*
2N/A * Update ira_ip_hdr_length to skip the hop-by-hop header
2N/A * once we get to ip_fanout_v6
2N/A */
2N/A ira->ira_ip_hdr_length += ehdrlen;
2N/A ira->ira_protocol = hbhhdr->ip6h_nxt;
2N/A
2N/A optptr = (uint8_t *)&hbhhdr[1];
2N/A switch (ip_process_options_v6(mp, ip6h, optptr,
2N/A ehdrlen - 2, IPPROTO_HOPOPTS, ira)) {
2N/A case -1:
2N/A /*
2N/A * Packet has been consumed and any
2N/A * needed ICMP messages sent.
2N/A */
2N/A return;
2N/A case 0:
2N/A /* no action needed */
2N/A break;
2N/A case 1:
2N/A /*
2N/A * Known router alert. Make use handle it as local
2N/A * by setting the nexthop to be the all-host multicast
2N/A * address, and skip multicast membership filter by
2N/A * marking as a router alert.
2N/A */
2N/A ira->ira_flags |= IRAF_ROUTER_ALERT;
2N/A nexthop = ipv6_all_hosts_mcast;
2N/A break;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Here we check to see if we machine is setup as
2N/A * L3 loadbalancer and if the incoming packet is for a VIP
2N/A *
2N/A * Check the following:
2N/A * - there is at least a rule
2N/A * - protocol of the packet is supported
2N/A *
2N/A * We don't load balance IPv6 link-locals.
2N/A */
2N/A if (ilb_has_rules(ilbs) && ILB_SUPP_L4(ira->ira_protocol) &&
2N/A !IN6_IS_ADDR_LINKLOCAL(&nexthop)) {
2N/A in6_addr_t lb_dst;
2N/A int lb_ret;
2N/A
2N/A /* For convenience, we just pull up the mblk. */
2N/A if (mp->b_cont != NULL) {
2N/A if (pullupmsg(mp, -1) == 0) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
2N/A ip_drop_input("ipIfStatsInDiscards - pullupmsg",
2N/A mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A ip6h = (ip6_t *)mp->b_rptr;
2N/A }
2N/A lb_ret = ilb_check_v6(ilbs, ill, mp, ip6h, ira->ira_protocol,
2N/A (uint8_t *)ip6h + ira->ira_ip_hdr_length, &lb_dst);
2N/A if (lb_ret == ILB_DROPPED) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
2N/A ip_drop_input("ILB_DROPPED", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A if (lb_ret == ILB_BALANCED) {
2N/A /* Set the dst to that of the chosen server */
2N/A nexthop = lb_dst;
2N/A DB_CKSUMFLAGS(mp) = 0;
2N/A }
2N/A }
2N/A
2N/A if (ill->ill_flags & ILLF_ROUTER)
2N/A irr_flags = IRR_ALLOCATE;
2N/A else
2N/A irr_flags = IRR_NONE;
2N/A
2N/A /* Can not use route cache with TX since the labels can differ */
2N/A if (ira->ira_flags & IRAF_SYSTEM_LABELED) {
2N/A if (IN6_IS_ADDR_MULTICAST(&nexthop)) {
2N/A ire = ire_multicast(ill);
2N/A } else if (IN6_IS_ADDR_LINKLOCAL(&nexthop)) {
2N/A ire = ire_linklocal(&nexthop, ill, ira, irr_flags,
2N/A ipst);
2N/A } else {
2N/A /* Match destination and label */
2N/A ire = ire_route_recursive_v6(&nexthop, 0, NULL,
2N/A ALL_ZONES, ira->ira_tsl, MATCH_IRE_SECATTR,
2N/A irr_flags, ira->ira_xmit_hint, ipst, NULL, NULL,
2N/A NULL);
2N/A }
2N/A /* Update the route cache so we do the ire_refrele */
2N/A ASSERT(ire != NULL);
2N/A if (rtc->rtc_ire != NULL)
2N/A ire_refrele(rtc->rtc_ire);
2N/A rtc->rtc_ire = ire;
2N/A rtc->rtc_ip6addr = nexthop;
2N/A } else if (IN6_ARE_ADDR_EQUAL(&nexthop, &rtc->rtc_ip6addr)) {
2N/A /* Use the route cache */
2N/A ASSERT(rtc->rtc_ire != NULL);
2N/A ire = rtc->rtc_ire;
2N/A } else {
2N/A /* Update the route cache */
2N/A if (IN6_IS_ADDR_MULTICAST(&nexthop)) {
2N/A ire = ire_multicast(ill);
2N/A } else if (IN6_IS_ADDR_LINKLOCAL(&nexthop)) {
2N/A ire = ire_linklocal(&nexthop, ill, ira, irr_flags,
2N/A ipst);
2N/A } else {
2N/A ire = ire_route_recursive_dstonly_v6(&nexthop,
2N/A irr_flags, ira->ira_xmit_hint, ipst);
2N/A }
2N/A ASSERT(ire != NULL);
2N/A if (rtc->rtc_ire != NULL)
2N/A ire_refrele(rtc->rtc_ire);
2N/A rtc->rtc_ire = ire;
2N/A rtc->rtc_ip6addr = nexthop;
2N/A }
2N/A
2N/A ire->ire_ib_pkt_count++;
2N/A
2N/A /*
2N/A * Based on ire_type and ire_flags call one of:
2N/A * ire_recv_local_v6 - for IRE_LOCAL
2N/A * ire_recv_loopback_v6 - for IRE_LOOPBACK
2N/A * ire_recv_multirt_v6 - if RTF_MULTIRT
2N/A * ire_recv_noroute_v6 - if RTF_REJECT or RTF_BLACHOLE
2N/A * ire_recv_multicast_v6 - for IRE_MULTICAST
2N/A * ire_recv_noaccept_v6 - for ire_noaccept ones
2N/A * ire_recv_forward_v6 - for the rest.
2N/A */
2N/A
2N/A (*ire->ire_recvfn)(ire, mp, ip6h, ira);
2N/A}
2N/A#undef rptr
2N/A
2N/A/*
2N/A * ire_recvfn for IREs that need forwarding
2N/A */
2N/Avoid
2N/Aire_recv_forward_v6(ire_t *ire, mblk_t *mp, void *iph_arg, ip_recv_attr_t *ira)
2N/A{
2N/A ip6_t *ip6h = (ip6_t *)iph_arg;
2N/A ill_t *ill = ira->ira_ill;
2N/A ip_stack_t *ipst = ill->ill_ipst;
2N/A iaflags_t iraflags = ira->ira_flags;
2N/A ill_t *dst_ill;
2N/A nce_t *nce;
2N/A uint32_t added_tx_len;
2N/A uint32_t mtu, iremtu;
2N/A
2N/A if (iraflags & (IRAF_L2DST_MULTICAST|IRAF_L2DST_BROADCAST)) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
2N/A ip_drop_input("l2 multicast not forwarded", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A
2N/A if (!(ill->ill_flags & ILLF_ROUTER)) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
2N/A ip_drop_input("ipIfStatsForwProhibits", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A
2N/A /*
2N/A * Either ire_nce_capable or ire_dep_parent would be set for the IRE
2N/A * when it is found by ire_route_recursive, but that some other thread
2N/A * could have changed the routes with the effect of clearing
2N/A * ire_dep_parent. In that case we'd end up dropping the packet, or
2N/A * finding a new nce below.
2N/A * Get, allocate, or update the nce.
2N/A * We get a refhold on ire_nce_cache as a result of this to avoid races
2N/A * where ire_nce_cache is deleted.
2N/A *
2N/A * This ensures that we don't forward if the interface is down since
2N/A * ipif_down removes all the nces.
2N/A */
2N/A mutex_enter(&ire->ire_lock);
2N/A nce = ire->ire_nce_cache;
2N/A if (nce == NULL) {
2N/A /* Not yet set up - try to set one up */
2N/A mutex_exit(&ire->ire_lock);
2N/A (void) ire_revalidate_nce(ire);
2N/A mutex_enter(&ire->ire_lock);
2N/A nce = ire->ire_nce_cache;
2N/A if (nce == NULL) {
2N/A mutex_exit(&ire->ire_lock);
2N/A /* The ire_dep_parent chain went bad, or no memory */
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
2N/A ip_drop_input("No ire_dep_parent", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A }
2N/A nce_refhold(nce);
2N/A mutex_exit(&ire->ire_lock);
2N/A
2N/A if (nce->nce_is_condemned) {
2N/A nce_t *nce1;
2N/A
2N/A nce1 = ire_handle_condemned_nce(nce, ire, NULL, ip6h, B_FALSE);
2N/A nce_refrele(nce);
2N/A if (nce1 == NULL) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
2N/A ip_drop_input("No nce", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A nce = nce1;
2N/A }
2N/A dst_ill = nce->nce_ill;
2N/A
2N/A /*
2N/A * Unless we are forwarding, drop the packet.
2N/A * Unlike IPv4 we don't allow source routed packets out the same
2N/A * interface when we are not a router.
2N/A * Note that ill_forward_set() will set the ILLF_ROUTER on
2N/A * all the group members when it gets an ipmp-ill or under-ill.
2N/A */
2N/A if (!(dst_ill->ill_flags & ILLF_ROUTER)) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
2N/A ip_drop_input("ipIfStatsForwProhibits", mp, ill);
2N/A freemsg(mp);
2N/A nce_refrele(nce);
2N/A return;
2N/A }
2N/A
2N/A if (ire->ire_zoneid != GLOBAL_ZONEID && ire->ire_zoneid != ALL_ZONES) {
2N/A ire->ire_ib_pkt_count--;
2N/A /*
2N/A * Should only use IREs that are visible from the
2N/A * global zone for forwarding.
2N/A * For IPv6 any source route would have already been
2N/A * advanced in ip_fanout_v6
2N/A */
2N/A ire = ire_route_recursive_v6(&ip6h->ip6_dst, 0, NULL,
2N/A GLOBAL_ZONEID, ira->ira_tsl, MATCH_IRE_SECATTR,
2N/A (ill->ill_flags & ILLF_ROUTER) ? IRR_ALLOCATE : IRR_NONE,
2N/A ira->ira_xmit_hint, ipst, NULL, NULL, NULL);
2N/A ire->ire_ib_pkt_count++;
2N/A (*ire->ire_recvfn)(ire, mp, ip6h, ira);
2N/A ire_refrele(ire);
2N/A nce_refrele(nce);
2N/A return;
2N/A }
2N/A /*
2N/A * ipIfStatsHCInForwDatagrams should only be increment if there
2N/A * will be an attempt to forward the packet, which is why we
2N/A * increment after the above condition has been checked.
2N/A */
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInForwDatagrams);
2N/A
2N/A /* Initiate Read side IPPF processing */
2N/A if (IPP_ENABLED(IPP_FWD_IN, ipst)) {
2N/A /* ip_process translates an IS_UNDER_IPMP */
2N/A mp = ip_process(IPP_FWD_IN, mp, ill, ill);
2N/A if (mp == NULL) {
2N/A /* ip_drop_packet and MIB done */
2N/A ip2dbg(("ire_recv_forward_v6: pkt dropped/deferred "
2N/A "during IPPF processing\n"));
2N/A nce_refrele(nce);
2N/A return;
2N/A }
2N/A }
2N/A
2N/A DTRACE_PROBE4(ip6__forwarding__start,
2N/A ill_t *, ill, ill_t *, dst_ill, ip6_t *, ip6h, mblk_t *, mp);
2N/A
2N/A if (HOOKS6_INTERESTED_FORWARDING(ipst)) {
2N/A int error;
2N/A
2N/A FW_HOOKS(ipst->ips_ip6_forwarding_event,
2N/A ipst->ips_ipv6firewall_forwarding,
2N/A ill, dst_ill, ip6h, mp, mp, 0, ipst, error);
2N/A
2N/A DTRACE_PROBE1(ip6__forwarding__end, mblk_t *, mp);
2N/A
2N/A if (mp == NULL) {
2N/A nce_refrele(nce);
2N/A return;
2N/A }
2N/A /*
2N/A * Even if the destination was changed by the filter we use the
2N/A * forwarding decision that was made based on the address
2N/A * in ip_input.
2N/A */
2N/A
2N/A /* Might have changed */
2N/A ip6h = (ip6_t *)mp->b_rptr;
2N/A ira->ira_pktlen = ntohs(ip6h->ip6_plen) + IPV6_HDR_LEN;
2N/A }
2N/A
2N/A /* Packet is being forwarded. Turning off hwcksum flag. */
2N/A DB_CKSUMFLAGS(mp) = 0;
2N/A
2N/A /*
2N/A * Per RFC 3513 section 2.5.2, we must not forward packets with
2N/A * an unspecified source address.
2N/A * The loopback address check for both src and dst has already
2N/A * been checked in ip_input_v6
2N/A * In the future one can envision adding RPF checks using number 3.
2N/A */
2N/A switch (ipst->ips_src_check) {
2N/A case 0:
2N/A break;
2N/A case 1:
2N/A case 2:
2N/A if (IN6_IS_ADDR_UNSPECIFIED(&ip6h->ip6_src) ||
2N/A IN6_IS_ADDR_MULTICAST(&ip6h->ip6_src)) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInAddrErrors);
2N/A ip_drop_input("ipIfStatsInAddrErrors", mp, ill);
2N/A nce_refrele(nce);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A break;
2N/A }
2N/A
2N/A /*
2N/A * Check to see if we're forwarding the packet to a
2N/A * different link from which it came. If so, check the
2N/A * source and destination addresses since routers must not
2N/A * forward any packets with link-local source or
2N/A * destination addresses to other links. Otherwise (if
2N/A * we're forwarding onto the same link), conditionally send
2N/A * a redirect message.
2N/A */
2N/A if (!IS_ON_SAME_LAN(dst_ill, ill)) {
2N/A if (IN6_IS_ADDR_LINKLOCAL(&ip6h->ip6_dst) ||
2N/A IN6_IS_ADDR_LINKLOCAL(&ip6h->ip6_src)) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInAddrErrors);
2N/A ip_drop_input("ipIfStatsInAddrErrors", mp, ill);
2N/A freemsg(mp);
2N/A nce_refrele(nce);
2N/A return;
2N/A }
2N/A /* TBD add site-local check at site boundary? */
2N/A } else if (ipst->ips_ipv6_send_redirects) {
2N/A ip_send_potential_redirect_v6(mp, ip6h, ire, ira);
2N/A }
2N/A
2N/A added_tx_len = 0;
2N/A if (iraflags & IRAF_SYSTEM_LABELED) {
2N/A mblk_t *mp1;
2N/A uint32_t old_pkt_len = ira->ira_pktlen;
2N/A
2N/A /*
2N/A * Check if it can be forwarded and add/remove
2N/A * CIPSO options as needed.
2N/A */
2N/A if ((mp1 = tsol_ip_forward(ire, mp, ira)) == NULL) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
2N/A ip_drop_input("tsol_ip_forward", mp, ill);
2N/A freemsg(mp);
2N/A nce_refrele(nce);
2N/A return;
2N/A }
2N/A /*
2N/A * Size may have changed. Remember amount added in case
2N/A * ip_fragment needs to send an ICMP too big.
2N/A */
2N/A mp = mp1;
2N/A ip6h = (ip6_t *)mp->b_rptr;
2N/A ira->ira_pktlen = ntohs(ip6h->ip6_plen) + IPV6_HDR_LEN;
2N/A ira->ira_ip_hdr_length = IPV6_HDR_LEN;
2N/A if (ira->ira_pktlen > old_pkt_len)
2N/A added_tx_len = ira->ira_pktlen - old_pkt_len;
2N/A }
2N/A
2N/A mtu = dst_ill->ill_mtu;
2N/A if ((iremtu = ire->ire_metrics.iulp_mtu) != 0 && iremtu < mtu)
2N/A mtu = iremtu;
2N/A ip_forward_xmit_v6(nce, mp, ip6h, ira, mtu, added_tx_len);
2N/A nce_refrele(nce);
2N/A return;
2N/A
2N/A}
2N/A
2N/A/*
2N/A * Used for sending out unicast and multicast packets that are
2N/A * forwarded.
2N/A */
2N/Avoid
2N/Aip_forward_xmit_v6(nce_t *nce, mblk_t *mp, ip6_t *ip6h, ip_recv_attr_t *ira,
2N/A uint32_t mtu, uint32_t added_tx_len)
2N/A{
2N/A ill_t *dst_ill = nce->nce_ill;
2N/A uint32_t pkt_len;
2N/A iaflags_t iraflags = ira->ira_flags;
2N/A ip_stack_t *ipst = dst_ill->ill_ipst;
2N/A
2N/A if (ip6h->ip6_hops-- <= 1) {
2N/A BUMP_MIB(ira->ira_ill->ill_ip_mib, ipIfStatsInDiscards);
2N/A ip_drop_input("ICMP6_TIME_EXCEED_TRANSIT", mp, ira->ira_ill);
2N/A icmp_time_exceeded_v6(mp, ICMP6_TIME_EXCEED_TRANSIT, B_FALSE,
2N/A ira);
2N/A return;
2N/A }
2N/A
2N/A /* Initiate Write side IPPF processing before any fragmentation */
2N/A if (IPP_ENABLED(IPP_FWD_OUT, ipst)) {
2N/A /* ip_process translates an IS_UNDER_IPMP */
2N/A mp = ip_process(IPP_FWD_OUT, mp, dst_ill, dst_ill);
2N/A if (mp == NULL) {
2N/A /* ip_drop_packet and MIB done */
2N/A ip2dbg(("ire_recv_forward_v6: pkt dropped/deferred" \
2N/A " during IPPF processing\n"));
2N/A return;
2N/A }
2N/A }
2N/A
2N/A pkt_len = ira->ira_pktlen;
2N/A
2N/A BUMP_MIB(dst_ill->ill_ip_mib, ipIfStatsHCOutForwDatagrams);
2N/A
2N/A if (pkt_len > mtu) {
2N/A BUMP_MIB(dst_ill->ill_ip_mib, ipIfStatsOutFragFails);
2N/A ip_drop_output("ipIfStatsOutFragFails", mp, dst_ill);
2N/A if (iraflags & IRAF_SYSTEM_LABELED) {
2N/A /*
2N/A * Remove any CIPSO option added by
2N/A * tsol_ip_forward, and make sure we report
2N/A * a path MTU so that there
2N/A * is room to add such a CIPSO option for future
2N/A * packets.
2N/A */
2N/A mtu = tsol_pmtu_adjust(mp, mtu, added_tx_len, AF_INET6);
2N/A }
2N/A icmp_pkt2big_v6(mp, mtu, B_TRUE, ira);
2N/A return;
2N/A }
2N/A
2N/A ASSERT(pkt_len ==
2N/A ntohs(((ip6_t *)mp->b_rptr)->ip6_plen) + IPV6_HDR_LEN);
2N/A
2N/A if (iraflags & IRAF_LOOPBACK_COPY) {
2N/A /*
2N/A * IXAF_NO_LOOP_ZONEID is not set hence 6th arg
2N/A * is don't care
2N/A */
2N/A (void) ip_postfrag_loopcheck(mp, nce,
2N/A (IXAF_LOOPBACK_COPY | IXAF_NO_DEV_FLOW_CTL),
2N/A pkt_len, ira->ira_xmit_hint, GLOBAL_ZONEID, 0, NULL);
2N/A } else {
2N/A (void) ip_xmit(mp, nce, IXAF_NO_DEV_FLOW_CTL,
2N/A pkt_len, ira->ira_xmit_hint, GLOBAL_ZONEID, 0, NULL);
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * ire_recvfn for RTF_REJECT and RTF_BLACKHOLE routes, including IRE_NOROUTE,
2N/A * which is what ire_route_recursive returns when there is no matching ire.
2N/A * Send ICMP unreachable unless blackhole.
2N/A */
2N/Avoid
2N/Aire_recv_noroute_v6(ire_t *ire, mblk_t *mp, void *iph_arg, ip_recv_attr_t *ira)
2N/A{
2N/A ip6_t *ip6h = (ip6_t *)iph_arg;
2N/A ill_t *ill = ira->ira_ill;
2N/A ip_stack_t *ipst = ill->ill_ipst;
2N/A
2N/A /* Would we have forwarded this packet if we had a route? */
2N/A if (ira->ira_flags & (IRAF_L2DST_MULTICAST|IRAF_L2DST_BROADCAST)) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
2N/A ip_drop_input("l2 multicast not forwarded", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A
2N/A if (!(ill->ill_flags & ILLF_ROUTER)) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
2N/A ip_drop_input("ipIfStatsForwProhibits", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A /*
2N/A * If we had a route this could have been forwarded. Count as such.
2N/A *
2N/A * ipIfStatsHCInForwDatagrams should only be increment if there
2N/A * will be an attempt to forward the packet, which is why we
2N/A * increment after the above condition has been checked.
2N/A */
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInForwDatagrams);
2N/A
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInNoRoutes);
2N/A
2N/A ip_rts_change_v6(RTM_MISS, &ip6h->ip6_dst, 0, 0, 0, 0, 0, 0, RTA_DST,
2N/A ipst);
2N/A
2N/A if (ire->ire_flags & RTF_BLACKHOLE) {
2N/A ip_drop_input("ipIfStatsInNoRoutes RTF_BLACKHOLE", mp, ill);
2N/A freemsg(mp);
2N/A } else {
2N/A ip_drop_input("ipIfStatsInNoRoutes RTF_REJECT", mp, ill);
2N/A
2N/A icmp_unreachable_v6(mp, ICMP6_DST_UNREACH_NOROUTE, B_FALSE,
2N/A ira);
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * ire_recvfn for IRE_LOCALs marked with ire_noaccept. Such IREs are used for
2N/A * VRRP when in noaccept mode.
2N/A * We silently drop packets except for Neighbor Solicitations and
2N/A * Neighbor Advertisements.
2N/A */
2N/Avoid
2N/Aire_recv_noaccept_v6(ire_t *ire, mblk_t *mp, void *iph_arg,
2N/A ip_recv_attr_t *ira)
2N/A{
2N/A ip6_t *ip6h = (ip6_t *)iph_arg;
2N/A ill_t *ill = ira->ira_ill;
2N/A icmp6_t *icmp6;
2N/A int ip_hdr_length;
2N/A
2N/A if (ip6h->ip6_nxt != IPPROTO_ICMPV6) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
2N/A ip_drop_input("ipIfStatsInDiscards - noaccept", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A ip_hdr_length = ira->ira_ip_hdr_length;
2N/A if ((mp->b_wptr - mp->b_rptr) < (ip_hdr_length + ICMP6_MINLEN)) {
2N/A if (ira->ira_pktlen < (ip_hdr_length + ICMP6_MINLEN)) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInTruncatedPkts);
2N/A ip_drop_input("ipIfStatsInTruncatedPkts", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A ip6h = ip_pullup(mp, ip_hdr_length + ICMP6_MINLEN, ira);
2N/A if (ip6h == NULL) {
2N/A BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInErrors);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A }
2N/A icmp6 = (icmp6_t *)(&mp->b_rptr[ip_hdr_length]);
2N/A
2N/A if (icmp6->icmp6_type != ND_NEIGHBOR_SOLICIT &&
2N/A icmp6->icmp6_type != ND_NEIGHBOR_ADVERT) {
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
2N/A ip_drop_input("ipIfStatsInDiscards - noaccept", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A ire_recv_local_v6(ire, mp, ip6h, ira);
2N/A}
2N/A
2N/A/*
2N/A * ire_recvfn for IRE_MULTICAST.
2N/A */
2N/Avoid
2N/Aire_recv_multicast_v6(ire_t *ire, mblk_t *mp, void *iph_arg,
2N/A ip_recv_attr_t *ira)
2N/A{
2N/A ip6_t *ip6h = (ip6_t *)iph_arg;
2N/A ill_t *ill = ira->ira_ill;
2N/A
2N/A ASSERT(ire->ire_ill == ira->ira_ill);
2N/A
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInMcastPkts);
2N/A UPDATE_MIB(ill->ill_ip_mib, ipIfStatsHCInMcastOctets, ira->ira_pktlen);
2N/A
2N/A /* Tag for higher-level protocols */
2N/A ira->ira_flags |= IRAF_MULTICAST;
2N/A
2N/A /*
2N/A * So that we don't end up with dups, only one ill an IPMP group is
2N/A * nominated to receive multicast traffic.
2N/A * If we have no cast_ill we are liberal and accept everything.
2N/A */
2N/A if (IS_UNDER_IPMP(ill)) {
2N/A ip_stack_t *ipst = ill->ill_ipst;
2N/A
2N/A /* For an under ill_grp can change under lock */
2N/A rw_enter(&ipst->ips_ill_g_lock, RW_READER);
2N/A if (!ill->ill_nom_cast && ill->ill_grp != NULL &&
2N/A ill->ill_grp->ig_cast_ill != NULL) {
2N/A rw_exit(&ipst->ips_ill_g_lock);
2N/A ip_drop_input("not on cast ill", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A rw_exit(&ipst->ips_ill_g_lock);
2N/A /*
2N/A * We switch to the upper ill so that mrouter and hasmembers
2N/A * can operate on upper here and in ip_input_multicast.
2N/A */
2N/A ill = ipmp_ill_hold_ipmp_ill(ill);
2N/A if (ill != NULL) {
2N/A ASSERT(ill != ira->ira_ill);
2N/A ASSERT(ire->ire_ill == ira->ira_ill);
2N/A ira->ira_ill = ill;
2N/A ira->ira_ruifindex = ill->ill_phyint->phyint_ifindex;
2N/A } else {
2N/A ill = ira->ira_ill;
2N/A }
2N/A }
2N/A
2N/A#ifdef notdef
2N/A /*
2N/A * Check if we are a multicast router - send ip_mforward a copy of
2N/A * the packet.
2N/A * Due to mroute_decap tunnels we consider forwarding packets even if
2N/A * mrouted has not joined the allmulti group on this interface.
2N/A */
2N/A if (ipst->ips_ip_g_mrouter) {
2N/A int retval;
2N/A
2N/A /*
2N/A * Clear the indication that this may have hardware
2N/A * checksum as we are not using it for forwarding.
2N/A */
2N/A DB_CKSUMFLAGS(mp) = 0;
2N/A
2N/A /*
2N/A * ip_mforward helps us make these distinctions: If received
2N/A * on tunnel and not IGMP, then drop.
2N/A * If IGMP packet, then don't check membership
2N/A * If received on a phyint and IGMP or PIM, then
2N/A * don't check membership
2N/A */
2N/A retval = ip_mforward_v6(mp, ira);
2N/A /* ip_mforward updates mib variables if needed */
2N/A
2N/A switch (retval) {
2N/A case 0:
2N/A /*
2N/A * pkt is okay and arrived on phyint.
2N/A */
2N/A break;
2N/A case -1:
2N/A /* pkt is mal-formed, toss it */
2N/A freemsg(mp);
2N/A goto done;
2N/A case 1:
2N/A /*
2N/A * pkt is okay and arrived on a tunnel
2N/A *
2N/A * If we are running a multicast router
2N/A * we need to see all mld packets, which
2N/A * are marked with router alerts.
2N/A */
2N/A if (ira->ira_flags & IRAF_ROUTER_ALERT)
2N/A goto forus;
2N/A ip_drop_input("Multicast on tunnel ignored", mp, ill);
2N/A freemsg(mp);
2N/A goto done;
2N/A }
2N/A }
2N/A#endif /* notdef */
2N/A
2N/A /*
2N/A * If this was a router alert we skip the group membership check.
2N/A */
2N/A if (ira->ira_flags & IRAF_ROUTER_ALERT)
2N/A goto forus;
2N/A
2N/A /*
2N/A * Check if we have members on this ill. This is not necessary for
2N/A * correctness because even if the NIC/GLD had a leaky filter, we
2N/A * filter before passing to each conn_t.
2N/A */
2N/A if (!ill_hasmembers_v6(ill, &ip6h->ip6_dst)) {
2N/A /*
2N/A * Nobody interested
2N/A *
2N/A * This might just be caused by the fact that
2N/A * multiple IP Multicast addresses map to the same
2N/A * link layer multicast - no need to increment counter!
2N/A */
2N/A ip_drop_input("Multicast with no members", mp, ill);
2N/A freemsg(mp);
2N/A goto done;
2N/A }
2N/Aforus:
2N/A ip2dbg(("ire_recv_multicast_v6: multicast for us\n"));
2N/A
2N/A /*
2N/A * After reassembly and IPsec we will need to duplicate the
2N/A * multicast packet for all matching zones on the ill.
2N/A */
2N/A ira->ira_zoneid = ALL_ZONES;
2N/A
2N/A /* Reassemble on the ill on which the packet arrived */
2N/A ip_input_local_v6(ire, mp, ip6h, ira);
2N/Adone:
2N/A if (ill != ire->ire_ill) {
2N/A ill_refrele(ill);
2N/A ira->ira_ill = ire->ire_ill;
2N/A ira->ira_ruifindex = ira->ira_ill->ill_phyint->phyint_ifindex;
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * ire_recvfn for IRE_OFFLINK with RTF_MULTIRT.
2N/A * Drop packets since we don't forward out multirt routes.
2N/A */
2N/A/* ARGSUSED */
2N/Avoid
2N/Aire_recv_multirt_v6(ire_t *ire, mblk_t *mp, void *iph_arg, ip_recv_attr_t *ira)
2N/A{
2N/A ill_t *ill = ira->ira_ill;
2N/A
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInNoRoutes);
2N/A ip_drop_input("Not forwarding out MULTIRT", mp, ill);
2N/A freemsg(mp);
2N/A}
2N/A
2N/A/*
2N/A * ire_recvfn for IRE_LOOPBACK. This is only used when a FW_HOOK
2N/A * has rewritten the packet to have a loopback destination address (We
2N/A * filter out packet with a loopback destination from arriving over the wire).
2N/A * We don't know what zone to use, thus we always use the GLOBAL_ZONEID.
2N/A */
2N/Avoid
2N/Aire_recv_loopback_v6(ire_t *ire, mblk_t *mp, void *iph_arg, ip_recv_attr_t *ira)
2N/A{
2N/A ip6_t *ip6h = (ip6_t *)iph_arg;
2N/A ill_t *ill = ira->ira_ill;
2N/A ill_t *ire_ill = ire->ire_ill;
2N/A
2N/A ira->ira_zoneid = GLOBAL_ZONEID;
2N/A
2N/A /* Switch to the lo0 ill for further processing */
2N/A if (ire_ill != ill) {
2N/A /*
2N/A * Update ira_ill to be the ILL on which the IP address
2N/A * is hosted.
2N/A * No need to hold the ill since we have a hold on the ire
2N/A */
2N/A ASSERT(ira->ira_ill == ira->ira_rill);
2N/A ira->ira_ill = ire_ill;
2N/A
2N/A ip_input_local_v6(ire, mp, ip6h, ira);
2N/A
2N/A /* Restore */
2N/A ASSERT(ira->ira_ill == ire_ill);
2N/A ira->ira_ill = ill;
2N/A return;
2N/A
2N/A }
2N/A ip_input_local_v6(ire, mp, ip6h, ira);
2N/A}
2N/A
2N/A/*
2N/A * ire_recvfn for IRE_LOCAL.
2N/A */
2N/Avoid
2N/Aire_recv_local_v6(ire_t *ire, mblk_t *mp, void *iph_arg, ip_recv_attr_t *ira)
2N/A{
2N/A ip6_t *ip6h = (ip6_t *)iph_arg;
2N/A ill_t *ill = ira->ira_ill;
2N/A ill_t *ire_ill = ire->ire_ill;
2N/A
2N/A /* Make a note for DAD that this address is in use */
2N/A ire->ire_last_used_time = LBOLT_FASTPATH;
2N/A
2N/A /* Only target the IRE_LOCAL with the right zoneid. */
2N/A ira->ira_zoneid = ire->ire_zoneid;
2N/A
2N/A /*
2N/A * If the packet arrived on the wrong ill, we check that
2N/A * this is ok.
2N/A * If it is, then we ensure that we do the reassembly on
2N/A * the ill on which the address is hosted. We keep ira_rill as
2N/A * the one on which the packet arrived, so that IP_PKTINFO and
2N/A * friends can report this.
2N/A */
2N/A if (ire_ill != ill) {
2N/A ire_t *new_ire;
2N/A
2N/A new_ire = ip_check_multihome(&ip6h->ip6_dst, ire, ill);
2N/A if (new_ire == NULL) {
2N/A /* Drop packet */
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsForwProhibits);
2N/A ip_drop_input("ipIfStatsInForwProhibits", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A /*
2N/A * Update ira_ill to be the ILL on which the IP address
2N/A * is hosted. No need to hold the ill since we have a
2N/A * hold on the ire. Note that we do the switch even if
2N/A * new_ire == ire (for IPMP, ire would be the one corresponding
2N/A * to the IPMP ill).
2N/A */
2N/A ASSERT(ira->ira_ill == ira->ira_rill);
2N/A ira->ira_ill = new_ire->ire_ill;
2N/A
2N/A /* ira_ruifindex tracks the upper for ira_rill */
2N/A if (IS_UNDER_IPMP(ill))
2N/A ira->ira_ruifindex = ill_get_upper_ifindex(ill);
2N/A
2N/A ip_input_local_v6(new_ire, mp, ip6h, ira);
2N/A
2N/A /* Restore */
2N/A ASSERT(ira->ira_ill == new_ire->ire_ill);
2N/A ira->ira_ill = ill;
2N/A ira->ira_ruifindex = ill->ill_phyint->phyint_ifindex;
2N/A
2N/A if (new_ire != ire)
2N/A ire_refrele(new_ire);
2N/A return;
2N/A }
2N/A
2N/A ip_input_local_v6(ire, mp, ip6h, ira);
2N/A}
2N/A
2N/A/*
2N/A * Common function for packets arriving for the host. Handles
2N/A * checksum verification, reassembly checks, etc.
2N/A */
2N/Astatic void
2N/Aip_input_local_v6(ire_t *ire, mblk_t *mp, ip6_t *ip6h, ip_recv_attr_t *ira)
2N/A{
2N/A iaflags_t iraflags = ira->ira_flags;
2N/A
2N/A /*
2N/A * For multicast we need some extra work before
2N/A * we call ip_fanout_v6(), since in the case of shared-IP zones
2N/A * we need to pretend that a packet arrived for each zoneid.
2N/A */
2N/A if (iraflags & IRAF_MULTICAST) {
2N/A ip_input_multicast_v6(ire, mp, ip6h, ira);
2N/A return;
2N/A }
2N/A ip_fanout_v6(mp, ip6h, ira);
2N/A}
2N/A
2N/A/*
2N/A * Handle multiple zones which want to receive the same multicast packets
2N/A * on this ill by delivering a packet to each of them.
2N/A *
2N/A * Note that for packets delivered to transports we could instead do this
2N/A * as part of the fanout code, but since we need to handle icmp_inbound
2N/A * it is simpler to have multicast work the same as IPv4 broadcast.
2N/A *
2N/A * The ip_fanout matching for multicast matches based on ilm independent of
2N/A * zoneid since the zoneid restriction is applied when joining a multicast
2N/A * group.
2N/A */
2N/A/* ARGSUSED */
2N/Astatic void
2N/Aip_input_multicast_v6(ire_t *ire, mblk_t *mp, ip6_t *ip6h, ip_recv_attr_t *ira)
2N/A{
2N/A ill_t *ill = ira->ira_ill;
2N/A iaflags_t iraflags = ira->ira_flags;
2N/A ip_stack_t *ipst = ill->ill_ipst;
2N/A netstack_t *ns = ipst->ips_netstack;
2N/A zoneid_t zoneid;
2N/A mblk_t *mp1;
2N/A ip6_t *ip6h1;
2N/A uint_t ira_pktlen = ira->ira_pktlen;
2N/A uint16_t ira_ip_hdr_length = ira->ira_ip_hdr_length;
2N/A
2N/A /* ire_recv_multicast has switched to the upper ill for IPMP */
2N/A ASSERT(!IS_UNDER_IPMP(ill));
2N/A
2N/A /*
2N/A * If we don't have more than one shared-IP zone, or if
2N/A * there are no members in anything but the global zone,
2N/A * then just set the zoneid and proceed.
2N/A */
2N/A if (ns->netstack_numzones == 1 ||
2N/A !ill_hasmembers_otherzones_v6(ill, &ip6h->ip6_dst,
2N/A GLOBAL_ZONEID)) {
2N/A ira->ira_zoneid = GLOBAL_ZONEID;
2N/A
2N/A /* If sender didn't want this zone to receive it, drop */
2N/A if ((iraflags & IRAF_NO_LOOP_ZONEID_SET) &&
2N/A ira->ira_no_loop_zoneid == ira->ira_zoneid) {
2N/A ip_drop_input("Multicast but wrong zoneid", mp, ill);
2N/A freemsg(mp);
2N/A return;
2N/A }
2N/A ip_fanout_v6(mp, ip6h, ira);
2N/A return;
2N/A }
2N/A
2N/A /*
2N/A * Here we loop over all zoneids that have members in the group
2N/A * and deliver a packet to ip_fanout for each zoneid.
2N/A *
2N/A * First find any members in the lowest numeric zoneid by looking for
2N/A * first zoneid larger than -1 (ALL_ZONES).
2N/A * We terminate the loop when we receive -1 (ALL_ZONES).
2N/A */
2N/A zoneid = ill_hasmembers_nextzone_v6(ill, &ip6h->ip6_dst, ALL_ZONES);
2N/A for (; zoneid != ALL_ZONES;
2N/A zoneid = ill_hasmembers_nextzone_v6(ill, &ip6h->ip6_dst, zoneid)) {
2N/A /*
2N/A * Avoid an extra copymsg/freemsg by skipping global zone here
2N/A * and doing that at the end.
2N/A */
2N/A if (zoneid == GLOBAL_ZONEID)
2N/A continue;
2N/A
2N/A ira->ira_zoneid = zoneid;
2N/A
2N/A /* If sender didn't want this zone to receive it, skip */
2N/A if ((iraflags & IRAF_NO_LOOP_ZONEID_SET) &&
2N/A ira->ira_no_loop_zoneid == ira->ira_zoneid)
2N/A continue;
2N/A
2N/A mp1 = copymsg(mp);
2N/A if (mp1 == NULL) {
2N/A /* Failed to deliver to one zone */
2N/A BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
2N/A ip_drop_input("ipIfStatsInDiscards", mp, ill);
2N/A continue;
2N/A }
2N/A ip6h1 = (ip6_t *)mp1->b_rptr;
2N/A ip_fanout_v6(mp1, ip6h1, ira);
2N/A /*
2N/A * IPsec might have modified ira_pktlen and ira_ip_hdr_length
2N/A * so we restore them for a potential next iteration
2N/A */
2N/A ira->ira_pktlen = ira_pktlen;
2N/A ira->ira_ip_hdr_length = ira_ip_hdr_length;
2N/A }
2N/A
2N/A /* Do the main ire */
2N/A ira->ira_zoneid = GLOBAL_ZONEID;
2N/A /* If sender didn't want this zone to receive it, drop */
2N/A if ((iraflags & IRAF_NO_LOOP_ZONEID_SET) &&
2N/A ira->ira_no_loop_zoneid == ira->ira_zoneid) {
2N/A ip_drop_input("Multicast but wrong zoneid", mp, ill);
2N/A freemsg(mp);
2N/A } else {
2N/A ip_fanout_v6(mp, ip6h, ira);
2N/A }
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Determine the zoneid and IRAF_TX_MAC_EXEMPTABLE if trusted extensions
2N/A * is in use. Updates ira_zoneid and ira_flags as a result.
2N/A */
2N/Astatic void
2N/Aip_fanout_tx_v6(mblk_t *mp, ip6_t *ip6h, uint8_t protocol, uint_t ip_hdr_length,
2N/A ip_recv_attr_t *ira)
2N/A{
2N/A uint16_t *up;
2N/A uint16_t lport;
2N/A zoneid_t zoneid;
2N/A
2N/A ASSERT(ira->ira_flags & IRAF_SYSTEM_LABELED);
2N/A
2N/A /*
2N/A * If the packet is unlabeled we might allow read-down
2N/A * for MAC_EXEMPT. Below we clear this if it is a multi-level
2N/A * port (MLP).
2N/A * Note that ira_tsl can be NULL here.
2N/A */
2N/A if (ira->ira_tsl != NULL && ira->ira_tsl->tsl_flags & TSLF_UNLABELED)
2N/A ira->ira_flags |= IRAF_TX_MAC_EXEMPTABLE;
2N/A
2N/A if (ira->ira_zoneid != ALL_ZONES)
2N/A return;
2N/A
2N/A ira->ira_flags |= IRAF_TX_SHARED_ADDR;
2N/A
2N/A up = (uint16_t *)((uchar_t *)ip6h + ip_hdr_length);
2N/A switch (protocol) {
2N/A case IPPROTO_TCP:
2N/A case IPPROTO_SCTP:
2N/A case IPPROTO_UDP:
2N/A /* Caller ensures this */
2N/A ASSERT(((uchar_t *)ip6h) + ip_hdr_length +4 <= mp->b_wptr);
2N/A
2N/A /*
2N/A * Only these transports support MLP.
2N/A * We know their destination port numbers is in
2N/A * the same place in the header.
2N/A */
2N/A lport = up[1];
2N/A
2N/A /*
2N/A * No need to handle exclusive-stack zones
2N/A * since ALL_ZONES only applies to the shared IP instance.
2N/A */
2N/A zoneid = tsol_mlp_findzone(protocol, lport);
2N/A /*
2N/A * If no shared MLP is found, tsol_mlp_findzone returns
2N/A * ALL_ZONES. In that case, we assume it's SLP, and
2N/A * search for the zone based on the packet label.
2N/A *
2N/A * If there is such a zone, we prefer to find a
2N/A * connection in it. Otherwise, we look for a
2N/A * MAC-exempt connection in any zone whose label
2N/A * dominates the default label on the packet.
2N/A */
2N/A if (zoneid == ALL_ZONES)
2N/A zoneid = tsol_attr_to_zoneid(ira);
2N/A else
2N/A ira->ira_flags &= ~IRAF_TX_MAC_EXEMPTABLE;
2N/A break;
2N/A default:
2N/A /* Handle shared address for other protocols */
2N/A zoneid = tsol_attr_to_zoneid(ira);
2N/A break;
2N/A }
2N/A ira->ira_zoneid = zoneid;
2N/A}
2N/A
2N/A/*
2N/A * Increment checksum failure statistics
2N/A */
2N/Astatic void
2N/Aip_input_cksum_err_v6(uint8_t protocol, uint16_t hck_flags, ill_t *ill)
2N/A{
2N/A ip_stack_t *ipst = ill->ill_ipst;
2N/A
2N/A switch (protocol) {
2N/A case IPPROTO_TCP:
2N/A BUMP_MIB(ill->ill_ip_mib, tcpIfStatsInErrs);
2N/A
2N/A if (hck_flags & HCK_FULLCKSUM)
2N/A IP6_STAT(ipst, ip6_tcp_in_full_hw_cksum_err);
2N/A else if (hck_flags & HCK_PARTIALCKSUM)
2N/A IP6_STAT(ipst, ip6_tcp_in_part_hw_cksum_err);
2N/A else
2N/A IP6_STAT(ipst, ip6_tcp_in_sw_cksum_err);
2N/A break;
2N/A case IPPROTO_UDP:
2N/A BUMP_MIB(ill->ill_ip_mib, udpIfStatsInCksumErrs);
2N/A if (hck_flags & HCK_FULLCKSUM)
2N/A IP6_STAT(ipst, ip6_udp_in_full_hw_cksum_err);
2N/A else if (hck_flags & HCK_PARTIALCKSUM)
2N/A IP6_STAT(ipst, ip6_udp_in_part_hw_cksum_err);
2N/A else
2N/A IP6_STAT(ipst, ip6_udp_in_sw_cksum_err);
2N/A break;
2N/A case IPPROTO_ICMPV6:
2N/A BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInMsgs);
2N/A BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInErrors);
2N/A break;
2N/A default:
2N/A ASSERT(0);
2N/A break;
2N/A }
2N/A}
2N/A
2N/A/* Calculate the IPv6 pseudo-header checksum for TCP, UDP, and ICMPV6 */
2N/Auint32_t
2N/Aip_input_cksum_pseudo_v6(ip6_t *ip6h, ip_recv_attr_t *ira)
2N/A{
2N/A uint_t ulp_len;
2N/A uint32_t cksum;
2N/A uint8_t protocol = ira->ira_protocol;
2N/A uint16_t ip_hdr_length = ira->ira_ip_hdr_length;
2N/A
2N/A#define iphs ((uint16_t *)ip6h)
2N/A
2N/A switch (protocol) {
2N/A case IPPROTO_TCP:
2N/A ulp_len = ira->ira_pktlen - ip_hdr_length;
2N/A
2N/A /* Protocol and length */
2N/A cksum = htons(ulp_len) + IP_TCP_CSUM_COMP;
2N/A /* IP addresses */
2N/A cksum += iphs[4] + iphs[5] + iphs[6] + iphs[7] +
2N/A iphs[8] + iphs[9] + iphs[10] + iphs[11] +
2N/A iphs[12] + iphs[13] + iphs[14] + iphs[15] +
2N/A iphs[16] + iphs[17] + iphs[18] + iphs[19];
2N/A break;
2N/A
2N/A case IPPROTO_UDP: {
2N/A udpha_t *udpha;
2N/A
2N/A udpha = (udpha_t *)((uchar_t *)ip6h + ip_hdr_length);
2N/A
2N/A /* Protocol and length */
2N/A cksum = udpha->uha_length + IP_UDP_CSUM_COMP;
2N/A /* IP addresses */
2N/A cksum += iphs[4] + iphs[5] + iphs[6] + iphs[7] +
2N/A iphs[8] + iphs[9] + iphs[10] + iphs[11] +
2N/A iphs[12] + iphs[13] + iphs[14] + iphs[15] +
2N/A iphs[16] + iphs[17] + iphs[18] + iphs[19];
2N/A break;
2N/A }
2N/A case IPPROTO_ICMPV6:
2N/A ulp_len = ira->ira_pktlen - ip_hdr_length;
2N/A
2N/A /* Protocol and length */
2N/A cksum = htons(ulp_len) + IP_ICMPV6_CSUM_COMP;
2N/A /* IP addresses */
2N/A cksum += iphs[4] + iphs[5] + iphs[6] + iphs[7] +
2N/A iphs[8] + iphs[9] + iphs[10] + iphs[11] +
2N/A iphs[12] + iphs[13] + iphs[14] + iphs[15] +
2N/A iphs[16] + iphs[17] + iphs[18] + iphs[19];
2N/A break;
2N/A default:
2N/A cksum = 0;
2N/A break;
2N/A }
2N/A#undef iphs
2N/A return (cksum);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Software verification of the ULP checksums.
2N/A * Returns B_TRUE if ok.
2N/A * Increments statistics of failed.
2N/A */
2N/Astatic boolean_t
2N/Aip_input_sw_cksum_v6(mblk_t *mp, ip6_t *ip6h, ip_recv_attr_t *ira)
2N/A{
2N/A ip_stack_t *ipst = ira->ira_ill->ill_ipst;
2N/A uint32_t cksum;
2N/A uint8_t protocol = ira->ira_protocol;
2N/A uint16_t ip_hdr_length = ira->ira_ip_hdr_length;
2N/A
2N/A IP6_STAT(ipst, ip6_in_sw_cksum);
2N/A
2N/A ASSERT(protocol == IPPROTO_TCP || protocol == IPPROTO_UDP ||
2N/A protocol == IPPROTO_ICMPV6);
2N/A
2N/A cksum = ip_input_cksum_pseudo_v6(ip6h, ira);
2N/A cksum = IP_CSUM(mp, ip_hdr_length, cksum);
2N/A if (cksum == 0)
2N/A return (B_TRUE);
2N/A
2N/A ip_input_cksum_err_v6(protocol, 0, ira->ira_ill);
2N/A return (B_FALSE);
2N/A}
2N/A
2N/A/*
2N/A * Verify the ULP checksums.
2N/A * Returns B_TRUE if ok, or if the ULP doesn't have a well-defined checksum
2N/A * algorithm.
2N/A * Increments statistics if failed.
2N/A */
2N/Astatic boolean_t
2N/Aip_input_cksum_v6(iaflags_t iraflags, mblk_t *mp, ip6_t *ip6h,
2N/A ip_recv_attr_t *ira)
2N/A{
2N/A ill_t *ill = ira->ira_rill;
2N/A uint16_t hck_flags;
2N/A uint32_t cksum;
2N/A mblk_t *mp1;
2N/A uint_t len;
2N/A uint8_t protocol = ira->ira_protocol;
2N/A uint16_t ip_hdr_length = ira->ira_ip_hdr_length;
2N/A
2N/A
2N/A switch (protocol) {
2N/A case IPPROTO_TCP:
2N/A case IPPROTO_ICMPV6:
2N/A break;
2N/A
2N/A case IPPROTO_UDP: {
2N/A udpha_t *udpha;
2N/A
2N/A udpha = (udpha_t *)((uchar_t *)ip6h + ip_hdr_length);
2N/A /*
2N/A * Before going through the regular checksum
2N/A * calculation, make sure the received checksum
2N/A * is non-zero. RFC 2460 says, a 0x0000 checksum
2N/A * in a UDP packet (within IPv6 packet) is invalid
2N/A * and should be replaced by 0xffff. This makes
2N/A * sense as regular checksum calculation will
2N/A * pass for both the cases i.e. 0x0000 and 0xffff.
2N/A * Removing one of the case makes error detection
2N/A * stronger.
2N/A */
2N/A if (udpha->uha_checksum == 0) {
2N/A /* 0x0000 checksum is invalid */
2N/A BUMP_MIB(ill->ill_ip_mib, udpIfStatsInCksumErrs);
2N/A return (B_FALSE);
2N/A }
2N/A break;
2N/A }
2N/A case IPPROTO_SCTP: {
2N/A sctp_hdr_t *sctph;
2N/A uint32_t pktsum;
2N/A
2N/A sctph = (sctp_hdr_t *)((uchar_t *)ip6h + ip_hdr_length);
2N/A#ifdef DEBUG
2N/A if (skip_sctp_cksum)
2N/A return (B_TRUE);
2N/A#endif
2N/A pktsum = sctph->sh_chksum;
2N/A sctph->sh_chksum = 0;
2N/A cksum = sctp_cksum(mp, ip_hdr_length);
2N/A sctph->sh_chksum = pktsum;
2N/A if (cksum == pktsum)
2N/A return (B_TRUE);
2N/A
2N/A /*
2N/A * Defer until later whether a bad checksum is ok
2N/A * in order to allow RAW sockets to use Adler checksum
2N/A * with SCTP.
2N/A */
2N/A ira->ira_flags |= IRAF_SCTP_CSUM_ERR;
2N/A return (B_TRUE);
2N/A }
2N/A
2N/A default:
2N/A /* No ULP checksum to verify. */
2N/A return (B_TRUE);
2N/A }
2N/A
2N/A /*
2N/A * Revert to software checksum calculation if the interface
2N/A * isn't capable of checksum offload.
2N/A * We clear DB_CKSUMFLAGS when going through IPsec in ip_fanout.
2N/A * Note: IRAF_NO_HW_CKSUM is not currently used.
2N/A */
2N/A ASSERT(!IS_IPMP(ill));
2N/A if ((iraflags & IRAF_NO_HW_CKSUM) || !ILL_HCKSUM_CAPABLE(ill) ||
2N/A !dohwcksum) {
2N/A return (ip_input_sw_cksum_v6(mp, ip6h, ira));
2N/A }
2N/A
2N/A /*
2N/A * We apply this for all ULP protocols. Does the HW know to
2N/A * not set the flags for SCTP and other protocols.
2N/A */
2N/A
2N/A hck_flags = DB_CKSUMFLAGS(mp);
2N/A
2N/A if (hck_flags & HCK_FULLCKSUM_OK) {
2N/A /*
2N/A * Hardware has already verified the checksum.
2N/A */
2N/A return (B_TRUE);
2N/A }
2N/A
2N/A if (hck_flags & HCK_FULLCKSUM) {
2N/A /*
2N/A * Full checksum has been computed by the hardware
2N/A * and has been attached. If the driver wants us to
2N/A * verify the correctness of the attached value, in
2N/A * order to protect against faulty hardware, compare
2N/A * it against -0 (0xFFFF) to see if it's valid.
2N/A */
2N/A cksum = DB_CKSUM16(mp);
2N/A if (cksum == 0xFFFF)
2N/A return (B_TRUE);
2N/A ip_input_cksum_err_v6(protocol, hck_flags, ira->ira_ill);
2N/A return (B_FALSE);
2N/A }
2N/A
2N/A mp1 = mp->b_cont;
2N/A if ((hck_flags & HCK_PARTIALCKSUM) &&
2N/A (mp1 == NULL || mp1->b_cont == NULL) &&
2N/A ip_hdr_length >= DB_CKSUMSTART(mp) &&
2N/A ((len = ip_hdr_length - DB_CKSUMSTART(mp)) & 1) == 0) {
2N/A uint32_t adj;
2N/A uchar_t *cksum_start;
2N/A
2N/A cksum = ip_input_cksum_pseudo_v6(ip6h, ira);
2N/A
2N/A cksum_start = ((uchar_t *)ip6h + DB_CKSUMSTART(mp));
2N/A
2N/A /*
2N/A * Partial checksum has been calculated by hardware
2N/A * and attached to the packet; in addition, any
2N/A * prepended extraneous data is even byte aligned,
2N/A * and there are at most two mblks associated with
2N/A * the packet. If any such data exists, we adjust
2N/A * the checksum; also take care any postpended data.
2N/A */
2N/A IP_ADJCKSUM_PARTIAL(cksum_start, mp, mp1, len, adj);
2N/A /*
2N/A * One's complement subtract extraneous checksum
2N/A */
2N/A cksum += DB_CKSUM16(mp);
2N/A if (adj >= cksum)
2N/A cksum = ~(adj - cksum) & 0xFFFF;
2N/A else
2N/A cksum -= adj;
2N/A cksum = (cksum & 0xFFFF) + ((int)cksum >> 16);
2N/A cksum = (cksum & 0xFFFF) + ((int)cksum >> 16);
2N/A if (!(~cksum & 0xFFFF))
2N/A return (B_TRUE);
ip_input_cksum_err_v6(protocol, hck_flags, ira->ira_ill);
return (B_FALSE);
}
return (ip_input_sw_cksum_v6(mp, ip6h, ira));
}
/*
* Handle fanout of received packets.
* Unicast packets that are looped back (from ire_send_local_v6) and packets
* from the wire are differentiated by checking IRAF_VERIFY_ULP_CKSUM.
*
* IPQoS Notes
* Before sending it to the client, invoke IPPF processing. Policy processing
* takes place only if the callout_position, IPP_LOCAL_IN, is enabled.
*/
void
ip_fanout_v6(mblk_t *mp, ip6_t *ip6h, ip_recv_attr_t *ira)
{
ill_t *ill = ira->ira_ill;
iaflags_t iraflags = ira->ira_flags;
ip_stack_t *ipst = ill->ill_ipst;
uint8_t protocol;
conn_t *connp;
#define rptr ((uchar_t *)ip6h)
uint_t ip_hdr_length;
uint_t min_ulp_header_length;
int offset;
ssize_t len;
netstack_t *ns = ipst->ips_netstack;
ipsec_stack_t *ipss = ns->netstack_ipsec;
ill_t *rill = ira->ira_rill;
ASSERT(ira->ira_pktlen == ntohs(ip6h->ip6_plen) + IPV6_HDR_LEN);
/*
* We repeat this as we parse over destination options header and
* fragment headers (earlier we've handled any hop-by-hop options
* header.)
* We update ira_protocol and ira_ip_hdr_length as we skip past
* the intermediate headers; they already point past any
* hop-by-hop header.
*/
repeat:
protocol = ira->ira_protocol;
ip_hdr_length = ira->ira_ip_hdr_length;
/*
* Time for IPP once we've done reassembly and IPsec.
* We skip this for loopback packets since we don't do IPQoS
* on loopback.
*/
if (IPP_ENABLED(IPP_LOCAL_IN, ipst) &&
!(iraflags & IRAF_LOOPBACK) &&
(protocol != IPPROTO_ESP || protocol != IPPROTO_AH ||
protocol != IPPROTO_DSTOPTS || protocol != IPPROTO_ROUTING ||
protocol != IPPROTO_FRAGMENT)) {
/*
* Use the interface on which the packet arrived - not where
* the IP address is hosted.
*/
/* ip_process translates an IS_UNDER_IPMP */
mp = ip_process(IPP_LOCAL_IN, mp, rill, ill);
if (mp == NULL) {
/* ip_drop_packet and MIB done */
return;
}
}
/* Determine the minimum required size of the upper-layer header */
/* Need to do this for at least the set of ULPs that TX handles. */
switch (protocol) {
case IPPROTO_TCP:
min_ulp_header_length = TCP_MIN_HEADER_LENGTH;
break;
case IPPROTO_SCTP:
min_ulp_header_length = SCTP_COMMON_HDR_LENGTH;
break;
case IPPROTO_UDP:
min_ulp_header_length = UDPH_SIZE;
break;
case IPPROTO_ICMP:
case IPPROTO_ICMPV6:
min_ulp_header_length = ICMPH_SIZE;
break;
case IPPROTO_FRAGMENT:
case IPPROTO_DSTOPTS:
case IPPROTO_ROUTING:
min_ulp_header_length = MIN_EHDR_LEN;
break;
default:
min_ulp_header_length = 0;
break;
}
/* Make sure we have the min ULP header length */
len = mp->b_wptr - rptr;
if (len < ip_hdr_length + min_ulp_header_length) {
if (ira->ira_pktlen < ip_hdr_length + min_ulp_header_length)
goto pkt_too_short;
IP6_STAT(ipst, ip6_recv_pullup);
ip6h = ip_pullup(mp, ip_hdr_length + min_ulp_header_length,
ira);
if (ip6h == NULL)
goto discard;
len = mp->b_wptr - rptr;
}
/*
* If trusted extensions then determine the zoneid and TX specific
* ira_flags.
*/
if (iraflags & IRAF_SYSTEM_LABELED) {
/* This can update ira->ira_flags and ira->ira_zoneid */
ip_fanout_tx_v6(mp, ip6h, protocol, ip_hdr_length, ira);
iraflags = ira->ira_flags;
}
/* Verify ULP checksum. Handles TCP, UDP, and SCTP */
if (iraflags & IRAF_VERIFY_ULP_CKSUM) {
if (!ip_input_cksum_v6(iraflags, mp, ip6h, ira)) {
/* Bad checksum. Stats are already incremented */
ip_drop_input("Bad ULP checksum", mp, ill);
freemsg(mp);
return;
}
/* IRAF_SCTP_CSUM_ERR could have been set */
iraflags = ira->ira_flags;
}
switch (protocol) {
case IPPROTO_TCP:
/* For TCP, discard multicast packets. */
if (iraflags & IRAF_MULTIBROADCAST)
goto discard;
/* First mblk contains IP+TCP headers per above check */
ASSERT(len >= ip_hdr_length + TCP_MIN_HEADER_LENGTH);
/* TCP options present? */
offset = ((uchar_t *)ip6h)[ip_hdr_length + 12] >> 4;
if (offset != 5) {
if (offset < 5)
goto discard;
/*
* There must be TCP options.
* Make sure we can grab them.
*/
offset <<= 2;
offset += ip_hdr_length;
if (len < offset) {
if (ira->ira_pktlen < offset)
goto pkt_too_short;
IP6_STAT(ipst, ip6_recv_pullup);
ip6h = ip_pullup(mp, offset, ira);
if (ip6h == NULL)
goto discard;
len = mp->b_wptr - rptr;
}
}
/*
* Pass up a squeue hint to tcp.
* If ira_sqp is already set (this is loopback) we leave it
* alone.
*/
if (ira->ira_sqp == NULL) {
ira->ira_sqp = ip_squeue_get(ira->ira_ring);
}
/* Look for AF_INET or AF_INET6 that matches */
connp = ipcl_classify_v6(mp, IPPROTO_TCP, ip_hdr_length,
ira, ipst);
if (connp == NULL) {
/* Send the TH_RST */
BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
tcp_xmit_listeners_reset(mp, ira, ipst, NULL);
return;
}
if (connp->conn_incoming_ifindex != 0 &&
connp->conn_incoming_ifindex != ira->ira_ruifindex) {
CONN_DEC_REF(connp);
/* Send the TH_RST */
BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
tcp_xmit_listeners_reset(mp, ira, ipst, NULL);
return;
}
if (CONN_INBOUND_POLICY_PRESENT_V6(connp, ipss) ||
(iraflags & IRAF_IPSEC_SECURE)) {
mp = ipsec_check_inbound_policy(mp, connp,
NULL, ip6h, ira);
if (mp == NULL) {
BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
/* Note that mp is NULL */
ip_drop_input("ipIfStatsInDiscards", mp, ill);
CONN_DEC_REF(connp);
return;
}
}
/* Found a client; up it goes */
BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
ira->ira_ill = ira->ira_rill = NULL;
if (!IPCL_IS_TCP(connp)) {
/* Not TCP; must be SOCK_RAW, IPPROTO_TCP */
(connp->conn_recv)(connp, mp, NULL, ira);
CONN_DEC_REF(connp);
ira->ira_ill = ill;
ira->ira_rill = rill;
return;
}
/*
* We do different processing whether called from
* ip_accept_tcp and we match the target, don't match
* the target, and when we are called by ip_input.
*/
if (iraflags & IRAF_TARGET_SQP) {
if (ira->ira_target_sqp == connp->conn_sqp) {
mblk_t *attrmp;
attrmp = ip_recv_attr_to_mblk(ira);
if (attrmp == NULL) {
BUMP_MIB(ill->ill_ip_mib,
ipIfStatsInDiscards);
ip_drop_input("ipIfStatsInDiscards",
mp, ill);
freemsg(mp);
CONN_DEC_REF(connp);
} else {
SET_SQUEUE(attrmp, connp->conn_recv,
connp);
attrmp->b_cont = mp;
ASSERT(ira->ira_target_sqp_mp == NULL);
ira->ira_target_sqp_mp = attrmp;
/*
* Conn ref release when drained from
* the squeue.
*/
}
} else {
SQUEUE_ENTER_ONE(connp->conn_sqp, mp,
connp->conn_recv, connp, ira, SQ_FILL,
SQTAG_IP6_TCP_INPUT);
}
} else {
SQUEUE_ENTER_ONE(connp->conn_sqp, mp, connp->conn_recv,
connp, ira, ip_squeue_flag, SQTAG_IP6_TCP_INPUT);
}
ira->ira_ill = ill;
ira->ira_rill = rill;
return;
case IPPROTO_SCTP: {
sctp_hdr_t *sctph;
uint32_t ports; /* Source and destination ports */
sctp_stack_t *sctps = ipst->ips_netstack->netstack_sctp;
/* For SCTP, discard multicast packets. */
if (iraflags & IRAF_MULTIBROADCAST)
goto discard;
/*
* Since there is no SCTP h/w cksum support yet, just
* clear the flag.
*/
DB_CKSUMFLAGS(mp) = 0;
/* Length ensured above */
ASSERT(MBLKL(mp) >= ip_hdr_length + SCTP_COMMON_HDR_LENGTH);
sctph = (sctp_hdr_t *)(rptr + ip_hdr_length);
/* get the ports */
ports = *(uint32_t *)&sctph->sh_sport;
if (iraflags & IRAF_SCTP_CSUM_ERR) {
/*
* No potential sctp checksum errors go to the Sun
* sctp stack however they might be Adler-32 summed
* packets a userland stack bound to a raw IP socket
* could reasonably use. Note though that Adler-32 is
* a long deprecated algorithm and customer sctp
* networks should eventually migrate to CRC-32 at
* which time this facility should be removed.
*/
ip_fanout_sctp_raw(mp, NULL, ip6h, ports, ira);
return;
}
connp = sctp_fanout(&ip6h->ip6_src, &ip6h->ip6_dst, ports,
ira, mp, sctps, sctph);
if (connp == NULL) {
/* Check for raw socket or OOTB handling */
ip_fanout_sctp_raw(mp, NULL, ip6h, ports, ira);
return;
}
if (connp->conn_incoming_ifindex != 0 &&
connp->conn_incoming_ifindex != ira->ira_ruifindex) {
CONN_DEC_REF(connp);
/* Check for raw socket or OOTB handling */
ip_fanout_sctp_raw(mp, NULL, ip6h, ports, ira);
return;
}
/* Found a client; up it goes */
BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
sctp_input(connp, NULL, ip6h, mp, ira);
/* sctp_input does a rele of the sctp_t */
return;
}
case IPPROTO_UDP:
/* First mblk contains IP+UDP headers as checked above */
ASSERT(MBLKL(mp) >= ip_hdr_length + UDPH_SIZE);
if (iraflags & IRAF_MULTIBROADCAST) {
uint16_t *up; /* Pointer to ports in ULP header */
up = (uint16_t *)((uchar_t *)ip6h + ip_hdr_length);
ip_fanout_udp_multi_v6(mp, ip6h, up[1], up[0], ira);
return;
}
/* Look for AF_INET or AF_INET6 that matches */
connp = ipcl_classify_v6(mp, IPPROTO_UDP, ip_hdr_length,
ira, ipst);
if (connp == NULL) {
no_udp_match:
if (ipst->ips_ipcl_proto_fanout_v6[IPPROTO_UDP].
connf_head != NULL) {
ASSERT(ira->ira_protocol == IPPROTO_UDP);
ip_fanout_proto_v6(mp, ip6h, ira);
} else {
ip_fanout_send_icmp_v6(mp, ICMP6_DST_UNREACH,
ICMP6_DST_UNREACH_NOPORT, ira);
}
return;
}
if (connp->conn_incoming_ifindex != 0 &&
connp->conn_incoming_ifindex != ira->ira_ruifindex) {
CONN_DEC_REF(connp);
goto no_udp_match;
}
if (IPCL_IS_NONSTR(connp) ? connp->conn_flow_cntrld :
!canputnext(connp->conn_rq)) {
CONN_DEC_REF(connp);
BUMP_MIB(ill->ill_ip_mib, udpIfStatsInOverflows);
ip_drop_input("udpIfStatsInOverflows", mp, ill);
freemsg(mp);
return;
}
if (CONN_INBOUND_POLICY_PRESENT_V6(connp, ipss) ||
(iraflags & IRAF_IPSEC_SECURE)) {
mp = ipsec_check_inbound_policy(mp, connp,
NULL, ip6h, ira);
if (mp == NULL) {
BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
/* Note that mp is NULL */
ip_drop_input("ipIfStatsInDiscards", mp, ill);
CONN_DEC_REF(connp);
return;
}
}
/* Found a client; up it goes */
IP6_STAT(ipst, ip6_udp_fannorm);
BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
ira->ira_ill = ira->ira_rill = NULL;
(connp->conn_recv)(connp, mp, NULL, ira);
CONN_DEC_REF(connp);
ira->ira_ill = ill;
ira->ira_rill = rill;
return;
default:
break;
}
/*
* Clear hardware checksumming flag as it is currently only
* used by TCP and UDP.
*/
DB_CKSUMFLAGS(mp) = 0;
switch (protocol) {
case IPPROTO_ICMPV6:
BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInMsgs);
/* Check variable for testing applications */
if (ipst->ips_ipv6_drop_inbound_icmpv6) {
ip_drop_input("ipv6_drop_inbound_icmpv6", mp, ill);
freemsg(mp);
return;
}
/*
* We need to accomodate icmp messages coming in clear
* until we get everything secure from the wire. If
* icmp_accept_clear_messages is zero we check with
* the global policy and act accordingly. If it is
* non-zero, we accept the message without any checks.
* But *this does not mean* that this will be delivered
* to RAW socket clients. By accepting we might send
* replies back, change our MTU value etc.,
* but delivery to the ULP/clients depends on their
* policy dispositions.
*/
if (ipst->ips_icmp_accept_clear_messages == 0) {
mp = ipsec_check_global_policy(mp, NULL,
NULL, ip6h, ira, ns);
if (mp == NULL)
return;
}
/*
* On a labeled system, we have to check whether the zone
* itself is permitted to receive raw traffic.
*/
if (ira->ira_flags & IRAF_SYSTEM_LABELED) {
if (!tsol_can_accept_raw(mp, ira, B_FALSE)) {
BUMP_MIB(ill->ill_icmp6_mib,
ipv6IfIcmpInErrors);
ip_drop_input("tsol_can_accept_raw", mp, ill);
freemsg(mp);
return;
}
}
BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
mp = icmp_inbound_v6(mp, ira);
if (mp == NULL) {
/* No need to pass to RAW sockets */
return;
}
break;
case IPPROTO_DSTOPTS: {
ip6_dest_t *desthdr;
uint_t ehdrlen;
uint8_t *optptr;
/* We already check for MIN_EHDR_LEN above */
/* Check if AH is present and needs to be processed. */
mp = ipsec_early_ah_v6(mp, ira);
if (mp == NULL)
return;
/*
* Reinitialize pointers, as ipsec_early_ah_v6() does
* complete pullups. We don't have to do more pullups
* as a result.
*/
ip6h = (ip6_t *)mp->b_rptr;
if (ira->ira_pktlen - ip_hdr_length < MIN_EHDR_LEN)
goto pkt_too_short;
if (mp->b_cont != NULL &&
rptr + ip_hdr_length + MIN_EHDR_LEN > mp->b_wptr) {
ip6h = ip_pullup(mp, ip_hdr_length + MIN_EHDR_LEN, ira);
if (ip6h == NULL)
goto discard;
}
desthdr = (ip6_dest_t *)(rptr + ip_hdr_length);
ehdrlen = 8 * (desthdr->ip6d_len + 1);
if (ira->ira_pktlen - ip_hdr_length < ehdrlen)
goto pkt_too_short;
if (mp->b_cont != NULL &&
rptr + IPV6_HDR_LEN + ehdrlen > mp->b_wptr) {
ip6h = ip_pullup(mp, IPV6_HDR_LEN + ehdrlen, ira);
if (ip6h == NULL)
goto discard;
desthdr = (ip6_dest_t *)(rptr + ip_hdr_length);
}
optptr = (uint8_t *)&desthdr[1];
/*
* Update ira_ip_hdr_length to skip the destination header
* when we repeat.
*/
ira->ira_ip_hdr_length += ehdrlen;
ira->ira_protocol = desthdr->ip6d_nxt;
/*
* Note: XXX This code does not seem to make
* distinction between Destination Options Header
* being before/after Routing Header which can
* happen if we are at the end of source route.
* This may become significant in future.
* (No real significant Destination Options are
* defined/implemented yet ).
*/
switch (ip_process_options_v6(mp, ip6h, optptr,
ehdrlen - 2, IPPROTO_DSTOPTS, ira)) {
case -1:
/*
* Packet has been consumed and any needed
* ICMP errors sent.
*/
return;
case 0:
/* No action needed continue */
break;
case 1:
/*
* Unnexpected return value
* (Router alert is a Hop-by-Hop option)
*/
#ifdef DEBUG
panic("ip_fanout_v6: router "
"alert hbh opt indication in dest opt");
/*NOTREACHED*/
#else
BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
ip_drop_input("ipIfStatsInDiscards", mp, ill);
freemsg(mp);
return;
#endif
}
goto repeat;
}
case IPPROTO_FRAGMENT: {
ip6_frag_t *fraghdr;
if (ira->ira_pktlen - ip_hdr_length < sizeof (ip6_frag_t))
goto pkt_too_short;
if (mp->b_cont != NULL &&
rptr + ip_hdr_length + sizeof (ip6_frag_t) > mp->b_wptr) {
ip6h = ip_pullup(mp,
ip_hdr_length + sizeof (ip6_frag_t), ira);
if (ip6h == NULL)
goto discard;
}
fraghdr = (ip6_frag_t *)(rptr + ip_hdr_length);
BUMP_MIB(ill->ill_ip_mib, ipIfStatsReasmReqds);
/*
* Invoke the CGTP (multirouting) filtering module to
* process the incoming packet. Packets identified as
* duplicates must be discarded. Filtering is active
* only if the ip_cgtp_filter ndd variable is
* non-zero.
*/
if (ipst->ips_ip_cgtp_filter &&
ipst->ips_ip_cgtp_filter_ops != NULL) {
int cgtp_flt_pkt;
netstackid_t stackid;
stackid = ipst->ips_netstack->netstack_stackid;
/*
* CGTP and IPMP are mutually exclusive so
* phyint_ifindex is fine here.
*/
cgtp_flt_pkt =
ipst->ips_ip_cgtp_filter_ops->cfo_filter_v6(
stackid, ill->ill_phyint->phyint_ifindex,
ip6h, fraghdr);
if (cgtp_flt_pkt == CGTP_IP_PKT_DUPLICATE) {
ip_drop_input("CGTP_IP_PKT_DUPLICATE", mp, ill);
freemsg(mp);
return;
}
}
/*
* Update ip_hdr_length to skip the frag header
* ip_input_fragment_v6 will determine the extension header
* prior to the fragment header and update its nexthdr value,
* and also set ira_protocol to the nexthdr that follows the
* completed fragment.
*/
ip_hdr_length += sizeof (ip6_frag_t);
/*
* Make sure we have ira_l2src before we loose the original
* mblk
*/
if (!(ira->ira_flags & IRAF_L2SRC_SET))
ip_setl2src(mp, ira, ira->ira_rill);
mp = ip_input_fragment_v6(mp, ip6h, fraghdr,
ira->ira_pktlen - ip_hdr_length, ira);
if (mp == NULL) {
/* Reassembly is still pending */
return;
}
BUMP_MIB(ill->ill_ip_mib, ipIfStatsReasmOKs);
/*
* The mblk chain has the frag header removed and
* ira_protocol, ira_pktlen, ira_ip_hdr_length as well as the
* IP header has been updated to refleact the result.
*/
ip6h = (ip6_t *)mp->b_rptr;
ip_hdr_length = ira->ira_ip_hdr_length;
goto repeat;
}
case IPPROTO_HOPOPTS:
/*
* Illegal header sequence.
* (Hop-by-hop headers are processed above
* and required to immediately follow IPv6 header)
*/
ip_drop_input("ICMP_PARAM_PROBLEM", mp, ill);
icmp_param_problem_nexthdr_v6(mp, B_FALSE, ira);
return;
case IPPROTO_ROUTING: {
uint_t ehdrlen;
ip6_rthdr_t *rthdr;
/* Check if AH is present and needs to be processed. */
mp = ipsec_early_ah_v6(mp, ira);
if (mp == NULL)
return;
/*
* Reinitialize pointers, as ipsec_early_ah_v6() does
* complete pullups. We don't have to do more pullups
* as a result.
*/
ip6h = (ip6_t *)mp->b_rptr;
if (ira->ira_pktlen - ip_hdr_length < MIN_EHDR_LEN)
goto pkt_too_short;
if (mp->b_cont != NULL &&
rptr + ip_hdr_length + MIN_EHDR_LEN > mp->b_wptr) {
ip6h = ip_pullup(mp, ip_hdr_length + MIN_EHDR_LEN, ira);
if (ip6h == NULL)
goto discard;
}
rthdr = (ip6_rthdr_t *)(rptr + ip_hdr_length);
protocol = ira->ira_protocol = rthdr->ip6r_nxt;
ehdrlen = 8 * (rthdr->ip6r_len + 1);
if (ira->ira_pktlen - ip_hdr_length < ehdrlen)
goto pkt_too_short;
if (mp->b_cont != NULL &&
rptr + IPV6_HDR_LEN + ehdrlen > mp->b_wptr) {
ip6h = ip_pullup(mp, IPV6_HDR_LEN + ehdrlen, ira);
if (ip6h == NULL)
goto discard;
rthdr = (ip6_rthdr_t *)(rptr + ip_hdr_length);
}
if (rthdr->ip6r_segleft != 0) {
/* Not end of source route */
if (ira->ira_flags &
(IRAF_L2DST_MULTICAST|IRAF_L2DST_BROADCAST)) {
BUMP_MIB(ill->ill_ip_mib,
ipIfStatsForwProhibits);
ip_drop_input("ipIfStatsInForwProhibits",
mp, ill);
freemsg(mp);
return;
}
ip_process_rthdr(mp, ip6h, rthdr, ira);
return;
}
ira->ira_ip_hdr_length += ehdrlen;
goto repeat;
}
case IPPROTO_AH:
case IPPROTO_ESP: {
/*
* Fast path for AH/ESP.
*/
netstack_t *ns = ipst->ips_netstack;
ipsec_stack_t *ipss = ns->netstack_ipsec;
IP_STAT(ipst, ipsec_proto_ahesp);
if (!ipsec_loaded(ipss)) {
ip_proto_not_sup(mp, ira);
return;
}
BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
/* select inbound SA and have IPsec process the pkt */
if (protocol == IPPROTO_ESP) {
esph_t *esph;
mp = ipsec_inbound_esp_sa(mp, ira, &esph);
if (mp == NULL)
return;
ASSERT(esph != NULL);
ASSERT(ira->ira_flags & IRAF_IPSEC_SECURE);
ASSERT(ira->ira_ipsec_esp_sa != NULL);
ASSERT(ira->ira_ipsec_esp_sa->ipsa_input_func != NULL);
mp = ira->ira_ipsec_esp_sa->ipsa_input_func(mp, esph,
ira);
} else {
ah_t *ah;
mp = ipsec_inbound_ah_sa(mp, ira, &ah);
if (mp == NULL)
return;
ASSERT(ah != NULL);
ASSERT(ira->ira_flags & IRAF_IPSEC_SECURE);
ASSERT(ira->ira_ipsec_ah_sa != NULL);
ASSERT(ira->ira_ipsec_ah_sa->ipsa_input_func != NULL);
mp = ira->ira_ipsec_ah_sa->ipsa_input_func(mp, ah,
ira);
}
if (mp == NULL) {
/*
* Either it failed or is pending. In the former case
* ipIfStatsInDiscards was increased.
*/
return;
}
/* we're done with IPsec processing, send it up */
ip_input_post_ipsec(mp, ira);
return;
}
case IPPROTO_NONE:
/* All processing is done. Count as "delivered". */
freemsg(mp);
BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
return;
case IPPROTO_ENCAP:
case IPPROTO_IPV6:
/* iptun will verify trusted label */
connp = ipcl_classify_v6(mp, protocol, ip_hdr_length,
ira, ipst);
if (connp != NULL) {
BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInDelivers);
ira->ira_ill = ira->ira_rill = NULL;
connp->conn_recv(connp, mp, NULL, ira);
CONN_DEC_REF(connp);
ira->ira_ill = ill;
ira->ira_rill = rill;
return;
}
/* FALLTHRU */
default:
/*
* On a labeled system, we have to check whether the zone
* itself is permitted to receive raw traffic.
*/
if (ira->ira_flags & IRAF_SYSTEM_LABELED) {
if (!tsol_can_accept_raw(mp, ira, B_FALSE)) {
BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
ip_drop_input("ipIfStatsInDiscards", mp, ill);
freemsg(mp);
return;
}
}
break;
}
/*
* The above input functions may have returned the pulled up message.
* So ip6h need to be reinitialized.
*/
ip6h = (ip6_t *)mp->b_rptr;
ira->ira_protocol = protocol;
if (ipst->ips_ipcl_proto_fanout_v6[protocol].connf_head == NULL) {
/* No user-level listener for these packets packets */
ip_proto_not_sup(mp, ira);
return;
}
/*
* Handle fanout to raw sockets. There
* can be more than one stream bound to a particular
* protocol. When this is the case, each one gets a copy
* of any incoming packets.
*/
ASSERT(ira->ira_protocol == protocol);
ip_fanout_proto_v6(mp, ip6h, ira);
return;
pkt_too_short:
BUMP_MIB(ill->ill_ip_mib, ipIfStatsInTruncatedPkts);
ip_drop_input("ipIfStatsInTruncatedPkts", mp, ill);
freemsg(mp);
return;
discard:
BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
ip_drop_input("ipIfStatsInDiscards", mp, ill);
freemsg(mp);
#undef rptr
}