111042SErik.Nordmark@Sun.COM /*
211042SErik.Nordmark@Sun.COM * CDDL HEADER START
311042SErik.Nordmark@Sun.COM *
411042SErik.Nordmark@Sun.COM * The contents of this file are subject to the terms of the
511042SErik.Nordmark@Sun.COM * Common Development and Distribution License (the "License").
611042SErik.Nordmark@Sun.COM * You may not use this file except in compliance with the License.
711042SErik.Nordmark@Sun.COM *
811042SErik.Nordmark@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
911042SErik.Nordmark@Sun.COM * or http://www.opensolaris.org/os/licensing.
1011042SErik.Nordmark@Sun.COM * See the License for the specific language governing permissions
1111042SErik.Nordmark@Sun.COM * and limitations under the License.
1211042SErik.Nordmark@Sun.COM *
1311042SErik.Nordmark@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
1411042SErik.Nordmark@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1511042SErik.Nordmark@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
1611042SErik.Nordmark@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
1711042SErik.Nordmark@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
1811042SErik.Nordmark@Sun.COM *
1911042SErik.Nordmark@Sun.COM * CDDL HEADER END
2011042SErik.Nordmark@Sun.COM */
2111042SErik.Nordmark@Sun.COM
2211042SErik.Nordmark@Sun.COM /*
23*13123SErik.Nordmark@Sun.COM * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
2411042SErik.Nordmark@Sun.COM */
2511042SErik.Nordmark@Sun.COM /* Copyright (c) 1990 Mentat Inc. */
2611042SErik.Nordmark@Sun.COM
2711042SErik.Nordmark@Sun.COM #include <sys/types.h>
2811042SErik.Nordmark@Sun.COM #include <sys/stream.h>
2911042SErik.Nordmark@Sun.COM #include <sys/strsubr.h>
3011042SErik.Nordmark@Sun.COM #include <sys/dlpi.h>
3111042SErik.Nordmark@Sun.COM #include <sys/strsun.h>
3211042SErik.Nordmark@Sun.COM #include <sys/zone.h>
3311042SErik.Nordmark@Sun.COM #include <sys/ddi.h>
3411042SErik.Nordmark@Sun.COM #include <sys/sunddi.h>
3511042SErik.Nordmark@Sun.COM #include <sys/cmn_err.h>
3611042SErik.Nordmark@Sun.COM #include <sys/debug.h>
3711042SErik.Nordmark@Sun.COM #include <sys/atomic.h>
3811042SErik.Nordmark@Sun.COM
3911042SErik.Nordmark@Sun.COM #include <sys/systm.h>
4011042SErik.Nordmark@Sun.COM #include <sys/param.h>
4111042SErik.Nordmark@Sun.COM #include <sys/kmem.h>
4211042SErik.Nordmark@Sun.COM #include <sys/sdt.h>
4311042SErik.Nordmark@Sun.COM #include <sys/socket.h>
4411042SErik.Nordmark@Sun.COM #include <sys/mac.h>
4511042SErik.Nordmark@Sun.COM #include <net/if.h>
4611042SErik.Nordmark@Sun.COM #include <net/if_arp.h>
4711042SErik.Nordmark@Sun.COM #include <net/route.h>
4811042SErik.Nordmark@Sun.COM #include <sys/sockio.h>
4911042SErik.Nordmark@Sun.COM #include <netinet/in.h>
5011042SErik.Nordmark@Sun.COM #include <net/if_dl.h>
5111042SErik.Nordmark@Sun.COM
5211042SErik.Nordmark@Sun.COM #include <inet/common.h>
5311042SErik.Nordmark@Sun.COM #include <inet/mi.h>
5411042SErik.Nordmark@Sun.COM #include <inet/mib2.h>
5511042SErik.Nordmark@Sun.COM #include <inet/nd.h>
5611042SErik.Nordmark@Sun.COM #include <inet/arp.h>
5711042SErik.Nordmark@Sun.COM #include <inet/snmpcom.h>
5811042SErik.Nordmark@Sun.COM #include <inet/kstatcom.h>
5911042SErik.Nordmark@Sun.COM
6011042SErik.Nordmark@Sun.COM #include <netinet/igmp_var.h>
6111042SErik.Nordmark@Sun.COM #include <netinet/ip6.h>
6211042SErik.Nordmark@Sun.COM #include <netinet/icmp6.h>
6311042SErik.Nordmark@Sun.COM #include <netinet/sctp.h>
6411042SErik.Nordmark@Sun.COM
6511042SErik.Nordmark@Sun.COM #include <inet/ip.h>
6611042SErik.Nordmark@Sun.COM #include <inet/ip_impl.h>
6711042SErik.Nordmark@Sun.COM #include <inet/ip6.h>
6811042SErik.Nordmark@Sun.COM #include <inet/ip6_asp.h>
6911042SErik.Nordmark@Sun.COM #include <inet/tcp.h>
7011042SErik.Nordmark@Sun.COM #include <inet/ip_multi.h>
7111042SErik.Nordmark@Sun.COM #include <inet/ip_if.h>
7211042SErik.Nordmark@Sun.COM #include <inet/ip_ire.h>
7311042SErik.Nordmark@Sun.COM #include <inet/ip_ftable.h>
7411042SErik.Nordmark@Sun.COM #include <inet/ip_rts.h>
7511042SErik.Nordmark@Sun.COM #include <inet/optcom.h>
7611042SErik.Nordmark@Sun.COM #include <inet/ip_ndp.h>
7711042SErik.Nordmark@Sun.COM #include <inet/ip_listutils.h>
7811042SErik.Nordmark@Sun.COM #include <netinet/igmp.h>
7911042SErik.Nordmark@Sun.COM #include <netinet/ip_mroute.h>
8011042SErik.Nordmark@Sun.COM #include <inet/ipp_common.h>
8111042SErik.Nordmark@Sun.COM
8211042SErik.Nordmark@Sun.COM #include <net/pfkeyv2.h>
8311042SErik.Nordmark@Sun.COM #include <inet/sadb.h>
8411042SErik.Nordmark@Sun.COM #include <inet/ipsec_impl.h>
8511042SErik.Nordmark@Sun.COM #include <inet/ipdrop.h>
8611042SErik.Nordmark@Sun.COM #include <inet/ip_netinfo.h>
8711042SErik.Nordmark@Sun.COM
8811042SErik.Nordmark@Sun.COM #include <sys/pattr.h>
8911042SErik.Nordmark@Sun.COM #include <inet/ipclassifier.h>
9011042SErik.Nordmark@Sun.COM #include <inet/sctp_ip.h>
9111042SErik.Nordmark@Sun.COM #include <inet/sctp/sctp_impl.h>
9211042SErik.Nordmark@Sun.COM #include <inet/udp_impl.h>
9311042SErik.Nordmark@Sun.COM #include <sys/sunddi.h>
9411042SErik.Nordmark@Sun.COM
9511042SErik.Nordmark@Sun.COM #include <sys/tsol/label.h>
9611042SErik.Nordmark@Sun.COM #include <sys/tsol/tnet.h>
9711042SErik.Nordmark@Sun.COM
9811110SErik.Nordmark@Sun.COM #include <sys/clock_impl.h> /* For LBOLT_FASTPATH{,64} */
9911110SErik.Nordmark@Sun.COM
10011042SErik.Nordmark@Sun.COM #ifdef DEBUG
10111042SErik.Nordmark@Sun.COM extern boolean_t skip_sctp_cksum;
10211042SErik.Nordmark@Sun.COM #endif
10311042SErik.Nordmark@Sun.COM
10411042SErik.Nordmark@Sun.COM static int ip_verify_nce(mblk_t *, ip_xmit_attr_t *);
10511042SErik.Nordmark@Sun.COM static int ip_verify_dce(mblk_t *, ip_xmit_attr_t *);
10611042SErik.Nordmark@Sun.COM static boolean_t ip_verify_lso(ill_t *, ip_xmit_attr_t *);
10711042SErik.Nordmark@Sun.COM static boolean_t ip_verify_zcopy(ill_t *, ip_xmit_attr_t *);
10811042SErik.Nordmark@Sun.COM static void ip_output_simple_broadcast(ip_xmit_attr_t *, mblk_t *);
10911042SErik.Nordmark@Sun.COM
11011042SErik.Nordmark@Sun.COM /*
11111042SErik.Nordmark@Sun.COM * There are two types of output functions for IP used for different
11211042SErik.Nordmark@Sun.COM * purposes:
11311042SErik.Nordmark@Sun.COM * - ip_output_simple() is when sending ICMP errors, TCP resets, etc when there
11411042SErik.Nordmark@Sun.COM * is no context in the form of a conn_t. However, there is a
11511042SErik.Nordmark@Sun.COM * ip_xmit_attr_t that the callers use to influence interface selection
11611042SErik.Nordmark@Sun.COM * (needed for ICMP echo as well as IPv6 link-locals) and IPsec.
11711042SErik.Nordmark@Sun.COM *
11811042SErik.Nordmark@Sun.COM * - conn_ip_output() is used when sending packets with a conn_t and
11911042SErik.Nordmark@Sun.COM * ip_set_destination has been called to cache information. In that case
12011042SErik.Nordmark@Sun.COM * various socket options are recorded in the ip_xmit_attr_t and should
12111042SErik.Nordmark@Sun.COM * be taken into account.
12211042SErik.Nordmark@Sun.COM */
12311042SErik.Nordmark@Sun.COM
12411042SErik.Nordmark@Sun.COM /*
12511042SErik.Nordmark@Sun.COM * The caller *must* have called conn_connect() or ip_attr_connect()
12611042SErik.Nordmark@Sun.COM * before calling conn_ip_output(). The caller needs to redo that each time
12711042SErik.Nordmark@Sun.COM * the destination IP address or port changes, as well as each time there is
12811042SErik.Nordmark@Sun.COM * a change to any socket option that would modify how packets are routed out
12911042SErik.Nordmark@Sun.COM * of the box (e.g., SO_DONTROUTE, IP_NEXTHOP, IP_BOUND_IF).
13011042SErik.Nordmark@Sun.COM *
13111042SErik.Nordmark@Sun.COM * The ULP caller has to serialize the use of a single ip_xmit_attr_t.
13211042SErik.Nordmark@Sun.COM * We assert for that here.
13311042SErik.Nordmark@Sun.COM */
13411042SErik.Nordmark@Sun.COM int
conn_ip_output(mblk_t * mp,ip_xmit_attr_t * ixa)13511042SErik.Nordmark@Sun.COM conn_ip_output(mblk_t *mp, ip_xmit_attr_t *ixa)
13611042SErik.Nordmark@Sun.COM {
13711042SErik.Nordmark@Sun.COM iaflags_t ixaflags = ixa->ixa_flags;
13811042SErik.Nordmark@Sun.COM ire_t *ire;
13911042SErik.Nordmark@Sun.COM nce_t *nce;
14011042SErik.Nordmark@Sun.COM dce_t *dce;
14111042SErik.Nordmark@Sun.COM ill_t *ill;
14211042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ixa->ixa_ipst;
14311042SErik.Nordmark@Sun.COM int error;
14411042SErik.Nordmark@Sun.COM
14511042SErik.Nordmark@Sun.COM /* We defer ipIfStatsHCOutRequests until an error or we have an ill */
14611042SErik.Nordmark@Sun.COM
14711042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_ire != NULL);
14811042SErik.Nordmark@Sun.COM /* Note there is no ixa_nce when reject and blackhole routes */
14911042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_dce != NULL); /* Could be default dce */
15011042SErik.Nordmark@Sun.COM
15111042SErik.Nordmark@Sun.COM #ifdef DEBUG
15211042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_curthread == NULL);
15311042SErik.Nordmark@Sun.COM ixa->ixa_curthread = curthread;
15411042SErik.Nordmark@Sun.COM #endif
15511042SErik.Nordmark@Sun.COM
15611042SErik.Nordmark@Sun.COM /*
15711042SErik.Nordmark@Sun.COM * Even on labeled systems we can have a NULL ixa_tsl e.g.,
15811042SErik.Nordmark@Sun.COM * for IGMP/MLD traffic.
15911042SErik.Nordmark@Sun.COM */
16011042SErik.Nordmark@Sun.COM
16111042SErik.Nordmark@Sun.COM ire = ixa->ixa_ire;
16211042SErik.Nordmark@Sun.COM
16311042SErik.Nordmark@Sun.COM /*
16411042SErik.Nordmark@Sun.COM * If the ULP says the (old) IRE resulted in reachability we
16511042SErik.Nordmark@Sun.COM * record this before determine whether to use a new IRE.
16611042SErik.Nordmark@Sun.COM * No locking for performance reasons.
16711042SErik.Nordmark@Sun.COM */
16811042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_REACH_CONF)
16911042SErik.Nordmark@Sun.COM ire->ire_badcnt = 0;
17011042SErik.Nordmark@Sun.COM
17111042SErik.Nordmark@Sun.COM /*
17211042SErik.Nordmark@Sun.COM * Has routing changed since we cached the results of the lookup?
17311042SErik.Nordmark@Sun.COM *
17411042SErik.Nordmark@Sun.COM * This check captures all of:
17511042SErik.Nordmark@Sun.COM * - the cached ire being deleted (by means of the special
17611042SErik.Nordmark@Sun.COM * IRE_GENERATION_CONDEMNED)
17711042SErik.Nordmark@Sun.COM * - A potentially better ire being added (ire_generation being
17811042SErik.Nordmark@Sun.COM * increased)
17911042SErik.Nordmark@Sun.COM * - A deletion of the nexthop ire that was used when we did the
18011042SErik.Nordmark@Sun.COM * lookup.
18111042SErik.Nordmark@Sun.COM * - An addition of a potentially better nexthop ire.
18211042SErik.Nordmark@Sun.COM * The last two are handled by walking and increasing the generation
18311042SErik.Nordmark@Sun.COM * number on all dependant IREs in ire_flush_cache().
18411042SErik.Nordmark@Sun.COM *
18511042SErik.Nordmark@Sun.COM * The check also handles all cases of RTF_REJECT and RTF_BLACKHOLE
18611042SErik.Nordmark@Sun.COM * since we ensure that each time we set ixa_ire to such an IRE we
18711042SErik.Nordmark@Sun.COM * make sure the ixa_ire_generation does not match (by using
18811042SErik.Nordmark@Sun.COM * IRE_GENERATION_VERIFY).
18911042SErik.Nordmark@Sun.COM */
19011042SErik.Nordmark@Sun.COM if (ire->ire_generation != ixa->ixa_ire_generation) {
19111042SErik.Nordmark@Sun.COM error = ip_verify_ire(mp, ixa);
19211042SErik.Nordmark@Sun.COM if (error != 0) {
19311042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards - verify ire",
19411042SErik.Nordmark@Sun.COM mp, NULL);
19511042SErik.Nordmark@Sun.COM goto drop;
19611042SErik.Nordmark@Sun.COM }
19711042SErik.Nordmark@Sun.COM ire = ixa->ixa_ire;
19811042SErik.Nordmark@Sun.COM ASSERT(ire != NULL);
19911042SErik.Nordmark@Sun.COM if (ire->ire_flags & (RTF_REJECT|RTF_BLACKHOLE)) {
20011042SErik.Nordmark@Sun.COM #ifdef DEBUG
20111042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_curthread == curthread);
20211042SErik.Nordmark@Sun.COM ixa->ixa_curthread = NULL;
20311042SErik.Nordmark@Sun.COM #endif
20411042SErik.Nordmark@Sun.COM ire->ire_ob_pkt_count++;
20511042SErik.Nordmark@Sun.COM /* ixa_dce might be condemned; use default one */
20611042SErik.Nordmark@Sun.COM return ((ire->ire_sendfn)(ire, mp, mp->b_rptr, ixa,
20711042SErik.Nordmark@Sun.COM &ipst->ips_dce_default->dce_ident));
20811042SErik.Nordmark@Sun.COM }
20911042SErik.Nordmark@Sun.COM /*
21011042SErik.Nordmark@Sun.COM * If the ncec changed then ip_verify_ire already set
21111042SErik.Nordmark@Sun.COM * ixa->ixa_dce_generation = DCE_GENERATION_VERIFY;
21211042SErik.Nordmark@Sun.COM * so we can recheck the interface mtu.
21311042SErik.Nordmark@Sun.COM */
21411042SErik.Nordmark@Sun.COM
21511042SErik.Nordmark@Sun.COM /*
21611042SErik.Nordmark@Sun.COM * Note that ire->ire_generation could already have changed.
21711042SErik.Nordmark@Sun.COM * We catch that next time we send a packet.
21811042SErik.Nordmark@Sun.COM */
21911042SErik.Nordmark@Sun.COM }
22011042SErik.Nordmark@Sun.COM
22111042SErik.Nordmark@Sun.COM /*
22211042SErik.Nordmark@Sun.COM * No need to lock access to ixa_nce since the ip_xmit_attr usage
22311042SErik.Nordmark@Sun.COM * is single threaded.
22411042SErik.Nordmark@Sun.COM */
22511042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_nce != NULL);
22611042SErik.Nordmark@Sun.COM nce = ixa->ixa_nce;
22711042SErik.Nordmark@Sun.COM if (nce->nce_is_condemned) {
22811042SErik.Nordmark@Sun.COM error = ip_verify_nce(mp, ixa);
22911042SErik.Nordmark@Sun.COM /*
23011042SErik.Nordmark@Sun.COM * In case ZEROCOPY capability become not available, we
23111042SErik.Nordmark@Sun.COM * copy the message and free the original one. We might
23211042SErik.Nordmark@Sun.COM * be copying more data than needed but it doesn't hurt
23311042SErik.Nordmark@Sun.COM * since such change rarely happens.
23411042SErik.Nordmark@Sun.COM */
23511042SErik.Nordmark@Sun.COM switch (error) {
23611042SErik.Nordmark@Sun.COM case 0:
23711042SErik.Nordmark@Sun.COM break;
23811042SErik.Nordmark@Sun.COM case ENOTSUP: { /* ZEROCOPY */
23911042SErik.Nordmark@Sun.COM mblk_t *nmp;
24011042SErik.Nordmark@Sun.COM
24111042SErik.Nordmark@Sun.COM if ((nmp = copymsg(mp)) != NULL) {
24211042SErik.Nordmark@Sun.COM freemsg(mp);
24311042SErik.Nordmark@Sun.COM mp = nmp;
24411042SErik.Nordmark@Sun.COM
24511042SErik.Nordmark@Sun.COM break;
24611042SErik.Nordmark@Sun.COM }
24711042SErik.Nordmark@Sun.COM /* FALLTHROUGH */
24811042SErik.Nordmark@Sun.COM }
24911042SErik.Nordmark@Sun.COM default:
25011042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards - verify nce",
25111042SErik.Nordmark@Sun.COM mp, NULL);
25211042SErik.Nordmark@Sun.COM goto drop;
25311042SErik.Nordmark@Sun.COM }
25411042SErik.Nordmark@Sun.COM ire = ixa->ixa_ire;
25511042SErik.Nordmark@Sun.COM ASSERT(ire != NULL);
25611042SErik.Nordmark@Sun.COM if (ire->ire_flags & (RTF_REJECT|RTF_BLACKHOLE)) {
25711042SErik.Nordmark@Sun.COM #ifdef DEBUG
25811042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_curthread == curthread);
25911042SErik.Nordmark@Sun.COM ixa->ixa_curthread = NULL;
26011042SErik.Nordmark@Sun.COM #endif
26111042SErik.Nordmark@Sun.COM ire->ire_ob_pkt_count++;
26211042SErik.Nordmark@Sun.COM /* ixa_dce might be condemned; use default one */
26311042SErik.Nordmark@Sun.COM return ((ire->ire_sendfn)(ire, mp, mp->b_rptr,
26411042SErik.Nordmark@Sun.COM ixa, &ipst->ips_dce_default->dce_ident));
26511042SErik.Nordmark@Sun.COM }
26611042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_nce != NULL);
26711042SErik.Nordmark@Sun.COM nce = ixa->ixa_nce;
26811042SErik.Nordmark@Sun.COM
26911042SErik.Nordmark@Sun.COM /*
27011042SErik.Nordmark@Sun.COM * Note that some other event could already have made
27111042SErik.Nordmark@Sun.COM * the new nce condemned. We catch that next time we
27211042SErik.Nordmark@Sun.COM * try to send a packet.
27311042SErik.Nordmark@Sun.COM */
27411042SErik.Nordmark@Sun.COM }
27511042SErik.Nordmark@Sun.COM /*
27611042SErik.Nordmark@Sun.COM * If there is no per-destination dce_t then we have a reference to
27711042SErik.Nordmark@Sun.COM * the default dce_t (which merely contains the dce_ipid).
27811042SErik.Nordmark@Sun.COM * The generation check captures both the introduction of a
27911042SErik.Nordmark@Sun.COM * per-destination dce_t (e.g., due to ICMP packet too big) and
28011042SErik.Nordmark@Sun.COM * any change to the per-destination dce (including it becoming
28111042SErik.Nordmark@Sun.COM * condemned by use of the special DCE_GENERATION_CONDEMNED).
28211042SErik.Nordmark@Sun.COM */
28311042SErik.Nordmark@Sun.COM dce = ixa->ixa_dce;
28411042SErik.Nordmark@Sun.COM
28511042SErik.Nordmark@Sun.COM /*
28611042SErik.Nordmark@Sun.COM * To avoid a periodic timer to increase the path MTU we
28711042SErik.Nordmark@Sun.COM * look at dce_last_change_time each time we send a packet.
28811042SErik.Nordmark@Sun.COM */
28911110SErik.Nordmark@Sun.COM if (dce->dce_flags & DCEF_PMTU) {
29011110SErik.Nordmark@Sun.COM int64_t now = LBOLT_FASTPATH64;
29111110SErik.Nordmark@Sun.COM
29211110SErik.Nordmark@Sun.COM if ((TICK_TO_SEC(now) - dce->dce_last_change_time >
29311110SErik.Nordmark@Sun.COM ipst->ips_ip_pathmtu_interval)) {
29411110SErik.Nordmark@Sun.COM /*
29511110SErik.Nordmark@Sun.COM * Older than 20 minutes. Drop the path MTU information.
29611110SErik.Nordmark@Sun.COM * Since the path MTU changes as a result of this,
29711110SErik.Nordmark@Sun.COM * twiddle ixa_dce_generation to make us go through the
29811110SErik.Nordmark@Sun.COM * dce verification code in conn_ip_output.
29911110SErik.Nordmark@Sun.COM */
30011110SErik.Nordmark@Sun.COM mutex_enter(&dce->dce_lock);
30111110SErik.Nordmark@Sun.COM dce->dce_flags &= ~(DCEF_PMTU|DCEF_TOO_SMALL_PMTU);
30211110SErik.Nordmark@Sun.COM dce->dce_last_change_time = TICK_TO_SEC(now);
30311110SErik.Nordmark@Sun.COM mutex_exit(&dce->dce_lock);
30411110SErik.Nordmark@Sun.COM dce_increment_generation(dce);
30511110SErik.Nordmark@Sun.COM }
30611042SErik.Nordmark@Sun.COM }
30711042SErik.Nordmark@Sun.COM
30811042SErik.Nordmark@Sun.COM if (dce->dce_generation != ixa->ixa_dce_generation) {
30911042SErik.Nordmark@Sun.COM error = ip_verify_dce(mp, ixa);
31011042SErik.Nordmark@Sun.COM if (error != 0) {
31111042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards - verify dce",
31211042SErik.Nordmark@Sun.COM mp, NULL);
31311042SErik.Nordmark@Sun.COM goto drop;
31411042SErik.Nordmark@Sun.COM }
31511042SErik.Nordmark@Sun.COM dce = ixa->ixa_dce;
31611042SErik.Nordmark@Sun.COM
31711042SErik.Nordmark@Sun.COM /*
31811042SErik.Nordmark@Sun.COM * Note that some other event could already have made the
31911042SErik.Nordmark@Sun.COM * new dce's generation number change.
32011042SErik.Nordmark@Sun.COM * We catch that next time we try to send a packet.
32111042SErik.Nordmark@Sun.COM */
32211042SErik.Nordmark@Sun.COM }
32311042SErik.Nordmark@Sun.COM
32411042SErik.Nordmark@Sun.COM ill = nce->nce_ill;
32511042SErik.Nordmark@Sun.COM
32611042SErik.Nordmark@Sun.COM /*
32711042SErik.Nordmark@Sun.COM * An initial ixa_fragsize was set in ip_set_destination
32811042SErik.Nordmark@Sun.COM * and we update it if any routing changes above.
32911042SErik.Nordmark@Sun.COM * A change to ill_mtu with ifconfig will increase all dce_generation
330*13123SErik.Nordmark@Sun.COM * so that we will detect that with the generation check. Ditto for
331*13123SErik.Nordmark@Sun.COM * ill_mc_mtu.
33211042SErik.Nordmark@Sun.COM */
33311042SErik.Nordmark@Sun.COM
33411042SErik.Nordmark@Sun.COM /*
33511042SErik.Nordmark@Sun.COM * Caller needs to make sure IXAF_VERIFY_SRC is not set if
33611042SErik.Nordmark@Sun.COM * conn_unspec_src.
33711042SErik.Nordmark@Sun.COM */
33811042SErik.Nordmark@Sun.COM if ((ixaflags & IXAF_VERIFY_SOURCE) &&
33911042SErik.Nordmark@Sun.COM ixa->ixa_src_generation != ipst->ips_src_generation) {
34011042SErik.Nordmark@Sun.COM /* Check if the IP source is still assigned to the host. */
34111042SErik.Nordmark@Sun.COM uint_t gen;
34211042SErik.Nordmark@Sun.COM
34311042SErik.Nordmark@Sun.COM if (!ip_verify_src(mp, ixa, &gen)) {
34411042SErik.Nordmark@Sun.COM /* Don't send a packet with a source that isn't ours */
34511042SErik.Nordmark@Sun.COM error = EADDRNOTAVAIL;
34611042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards - invalid src",
34711042SErik.Nordmark@Sun.COM mp, NULL);
34811042SErik.Nordmark@Sun.COM goto drop;
34911042SErik.Nordmark@Sun.COM }
35011042SErik.Nordmark@Sun.COM /* The source is still valid - update the generation number */
35111042SErik.Nordmark@Sun.COM ixa->ixa_src_generation = gen;
35211042SErik.Nordmark@Sun.COM }
35311042SErik.Nordmark@Sun.COM
35411042SErik.Nordmark@Sun.COM /*
35511042SErik.Nordmark@Sun.COM * We don't have an IRE when we fragment, hence ire_ob_pkt_count
35611042SErik.Nordmark@Sun.COM * can only count the use prior to fragmentation. However the MIB
35711042SErik.Nordmark@Sun.COM * counters on the ill will be incremented in post fragmentation.
35811042SErik.Nordmark@Sun.COM */
35911042SErik.Nordmark@Sun.COM ire->ire_ob_pkt_count++;
36011042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCOutRequests);
36111042SErik.Nordmark@Sun.COM
36211042SErik.Nordmark@Sun.COM /*
36311042SErik.Nordmark@Sun.COM * Based on ire_type and ire_flags call one of:
36411042SErik.Nordmark@Sun.COM * ire_send_local_v* - for IRE_LOCAL and IRE_LOOPBACK
36511042SErik.Nordmark@Sun.COM * ire_send_multirt_v* - if RTF_MULTIRT
36611042SErik.Nordmark@Sun.COM * ire_send_noroute_v* - if RTF_REJECT or RTF_BLACHOLE
36711042SErik.Nordmark@Sun.COM * ire_send_multicast_v* - for IRE_MULTICAST
36811042SErik.Nordmark@Sun.COM * ire_send_broadcast_v4 - for IRE_BROADCAST
36911042SErik.Nordmark@Sun.COM * ire_send_wire_v* - for the rest.
37011042SErik.Nordmark@Sun.COM */
37111042SErik.Nordmark@Sun.COM #ifdef DEBUG
37211042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_curthread == curthread);
37311042SErik.Nordmark@Sun.COM ixa->ixa_curthread = NULL;
37411042SErik.Nordmark@Sun.COM #endif
37511042SErik.Nordmark@Sun.COM return ((ire->ire_sendfn)(ire, mp, mp->b_rptr, ixa, &dce->dce_ident));
37611042SErik.Nordmark@Sun.COM
37711042SErik.Nordmark@Sun.COM drop:
37811042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_IS_IPV4) {
37911042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsHCOutRequests);
38011042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsOutDiscards);
38111042SErik.Nordmark@Sun.COM } else {
38211042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip6_mib, ipIfStatsHCOutRequests);
38311042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip6_mib, ipIfStatsOutDiscards);
38411042SErik.Nordmark@Sun.COM }
38511042SErik.Nordmark@Sun.COM freemsg(mp);
38611042SErik.Nordmark@Sun.COM #ifdef DEBUG
38711042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_curthread == curthread);
38811042SErik.Nordmark@Sun.COM ixa->ixa_curthread = NULL;
38911042SErik.Nordmark@Sun.COM #endif
39011042SErik.Nordmark@Sun.COM return (error);
39111042SErik.Nordmark@Sun.COM }
39211042SErik.Nordmark@Sun.COM
39311042SErik.Nordmark@Sun.COM /*
39411042SErik.Nordmark@Sun.COM * Handle both IPv4 and IPv6. Sets the generation number
39511042SErik.Nordmark@Sun.COM * to allow the caller to know when to call us again.
39611042SErik.Nordmark@Sun.COM * Returns true if the source address in the packet is a valid source.
39711042SErik.Nordmark@Sun.COM * We handle callers which try to send with a zero address (since we only
39811042SErik.Nordmark@Sun.COM * get here if UNSPEC_SRC is not set).
39911042SErik.Nordmark@Sun.COM */
40011042SErik.Nordmark@Sun.COM boolean_t
ip_verify_src(mblk_t * mp,ip_xmit_attr_t * ixa,uint_t * generationp)40111042SErik.Nordmark@Sun.COM ip_verify_src(mblk_t *mp, ip_xmit_attr_t *ixa, uint_t *generationp)
40211042SErik.Nordmark@Sun.COM {
40311042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ixa->ixa_ipst;
40411042SErik.Nordmark@Sun.COM
40511042SErik.Nordmark@Sun.COM /*
40611042SErik.Nordmark@Sun.COM * Need to grab the generation number before we check to
40711042SErik.Nordmark@Sun.COM * avoid a race with a change to the set of local addresses.
40811042SErik.Nordmark@Sun.COM * No lock needed since the thread which updates the set of local
40911042SErik.Nordmark@Sun.COM * addresses use ipif/ill locks and exit those (hence a store memory
41011042SErik.Nordmark@Sun.COM * barrier) before doing the atomic increase of ips_src_generation.
41111042SErik.Nordmark@Sun.COM */
41211042SErik.Nordmark@Sun.COM if (generationp != NULL)
41311042SErik.Nordmark@Sun.COM *generationp = ipst->ips_src_generation;
41411042SErik.Nordmark@Sun.COM
41511042SErik.Nordmark@Sun.COM if (ixa->ixa_flags & IXAF_IS_IPV4) {
41611042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)mp->b_rptr;
41711042SErik.Nordmark@Sun.COM
41811042SErik.Nordmark@Sun.COM if (ipha->ipha_src == INADDR_ANY)
41911042SErik.Nordmark@Sun.COM return (B_FALSE);
42011042SErik.Nordmark@Sun.COM
42111042SErik.Nordmark@Sun.COM return (ip_laddr_verify_v4(ipha->ipha_src, ixa->ixa_zoneid,
42211042SErik.Nordmark@Sun.COM ipst, B_FALSE) != IPVL_BAD);
42311042SErik.Nordmark@Sun.COM } else {
42411042SErik.Nordmark@Sun.COM ip6_t *ip6h = (ip6_t *)mp->b_rptr;
42511042SErik.Nordmark@Sun.COM uint_t scopeid;
42611042SErik.Nordmark@Sun.COM
42711042SErik.Nordmark@Sun.COM if (IN6_IS_ADDR_UNSPECIFIED(&ip6h->ip6_src))
42811042SErik.Nordmark@Sun.COM return (B_FALSE);
42911042SErik.Nordmark@Sun.COM
43011042SErik.Nordmark@Sun.COM if (ixa->ixa_flags & IXAF_SCOPEID_SET)
43111042SErik.Nordmark@Sun.COM scopeid = ixa->ixa_scopeid;
43211042SErik.Nordmark@Sun.COM else
43311042SErik.Nordmark@Sun.COM scopeid = 0;
43411042SErik.Nordmark@Sun.COM
43511042SErik.Nordmark@Sun.COM return (ip_laddr_verify_v6(&ip6h->ip6_src, ixa->ixa_zoneid,
43611042SErik.Nordmark@Sun.COM ipst, B_FALSE, scopeid) != IPVL_BAD);
43711042SErik.Nordmark@Sun.COM }
43811042SErik.Nordmark@Sun.COM }
43911042SErik.Nordmark@Sun.COM
44011042SErik.Nordmark@Sun.COM /*
44111042SErik.Nordmark@Sun.COM * Handle both IPv4 and IPv6. Reverify/recalculate the IRE to use.
44211042SErik.Nordmark@Sun.COM */
44311042SErik.Nordmark@Sun.COM int
ip_verify_ire(mblk_t * mp,ip_xmit_attr_t * ixa)44411042SErik.Nordmark@Sun.COM ip_verify_ire(mblk_t *mp, ip_xmit_attr_t *ixa)
44511042SErik.Nordmark@Sun.COM {
44611042SErik.Nordmark@Sun.COM uint_t gen;
44711042SErik.Nordmark@Sun.COM ire_t *ire;
44811042SErik.Nordmark@Sun.COM nce_t *nce;
44911042SErik.Nordmark@Sun.COM int error;
45011042SErik.Nordmark@Sun.COM boolean_t multirt = B_FALSE;
45111042SErik.Nordmark@Sun.COM
45211042SErik.Nordmark@Sun.COM /*
45311042SErik.Nordmark@Sun.COM * Redo ip_select_route.
45411042SErik.Nordmark@Sun.COM * Need to grab generation number as part of the lookup to
45511042SErik.Nordmark@Sun.COM * avoid race.
45611042SErik.Nordmark@Sun.COM */
45711042SErik.Nordmark@Sun.COM error = 0;
45811042SErik.Nordmark@Sun.COM ire = ip_select_route_pkt(mp, ixa, &gen, &error, &multirt);
45911042SErik.Nordmark@Sun.COM ASSERT(ire != NULL); /* IRE_NOROUTE if none found */
46011042SErik.Nordmark@Sun.COM if (error != 0) {
46111042SErik.Nordmark@Sun.COM ire_refrele(ire);
46211042SErik.Nordmark@Sun.COM return (error);
46311042SErik.Nordmark@Sun.COM }
46411042SErik.Nordmark@Sun.COM
46511042SErik.Nordmark@Sun.COM if (ixa->ixa_ire != NULL)
46611042SErik.Nordmark@Sun.COM ire_refrele_notr(ixa->ixa_ire);
46711042SErik.Nordmark@Sun.COM #ifdef DEBUG
46811042SErik.Nordmark@Sun.COM ire_refhold_notr(ire);
46911042SErik.Nordmark@Sun.COM ire_refrele(ire);
47011042SErik.Nordmark@Sun.COM #endif
47111042SErik.Nordmark@Sun.COM ixa->ixa_ire = ire;
47211042SErik.Nordmark@Sun.COM ixa->ixa_ire_generation = gen;
47311042SErik.Nordmark@Sun.COM if (multirt) {
47411042SErik.Nordmark@Sun.COM if (ixa->ixa_flags & IXAF_IS_IPV4)
47511042SErik.Nordmark@Sun.COM ixa->ixa_postfragfn = ip_postfrag_multirt_v4;
47611042SErik.Nordmark@Sun.COM else
47711042SErik.Nordmark@Sun.COM ixa->ixa_postfragfn = ip_postfrag_multirt_v6;
47811042SErik.Nordmark@Sun.COM ixa->ixa_flags |= IXAF_MULTIRT_MULTICAST;
47911042SErik.Nordmark@Sun.COM } else {
48011042SErik.Nordmark@Sun.COM ixa->ixa_postfragfn = ire->ire_postfragfn;
48111042SErik.Nordmark@Sun.COM ixa->ixa_flags &= ~IXAF_MULTIRT_MULTICAST;
48211042SErik.Nordmark@Sun.COM }
48311042SErik.Nordmark@Sun.COM
48411042SErik.Nordmark@Sun.COM /*
48511042SErik.Nordmark@Sun.COM * Don't look for an nce for reject or blackhole.
48611042SErik.Nordmark@Sun.COM * They have ire_generation set to IRE_GENERATION_VERIFY which
48711042SErik.Nordmark@Sun.COM * makes conn_ip_output avoid references to ixa_nce.
48811042SErik.Nordmark@Sun.COM */
48911042SErik.Nordmark@Sun.COM if (ire->ire_flags & (RTF_REJECT|RTF_BLACKHOLE)) {
49011042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_ire_generation == IRE_GENERATION_VERIFY);
49111042SErik.Nordmark@Sun.COM ixa->ixa_dce_generation = DCE_GENERATION_VERIFY;
49211042SErik.Nordmark@Sun.COM return (0);
49311042SErik.Nordmark@Sun.COM }
49411042SErik.Nordmark@Sun.COM
49511042SErik.Nordmark@Sun.COM /* The NCE could now be different */
49611042SErik.Nordmark@Sun.COM nce = ire_to_nce_pkt(ire, mp);
49711042SErik.Nordmark@Sun.COM if (nce == NULL) {
49811042SErik.Nordmark@Sun.COM /*
49911042SErik.Nordmark@Sun.COM * Allocation failure. Make sure we redo ire/nce selection
50011042SErik.Nordmark@Sun.COM * next time we send.
50111042SErik.Nordmark@Sun.COM */
50211042SErik.Nordmark@Sun.COM ixa->ixa_ire_generation = IRE_GENERATION_VERIFY;
50311042SErik.Nordmark@Sun.COM ixa->ixa_dce_generation = DCE_GENERATION_VERIFY;
50411042SErik.Nordmark@Sun.COM return (ENOBUFS);
50511042SErik.Nordmark@Sun.COM }
50611042SErik.Nordmark@Sun.COM if (nce == ixa->ixa_nce) {
50711042SErik.Nordmark@Sun.COM /* No change */
50811042SErik.Nordmark@Sun.COM nce_refrele(nce);
50911042SErik.Nordmark@Sun.COM return (0);
51011042SErik.Nordmark@Sun.COM }
51111042SErik.Nordmark@Sun.COM
51211042SErik.Nordmark@Sun.COM /*
51311042SErik.Nordmark@Sun.COM * Since the path MTU might change as a result of this
51411042SErik.Nordmark@Sun.COM * route change, we twiddle ixa_dce_generation to
51511042SErik.Nordmark@Sun.COM * make conn_ip_output go through the ip_verify_dce code.
51611042SErik.Nordmark@Sun.COM */
51711042SErik.Nordmark@Sun.COM ixa->ixa_dce_generation = DCE_GENERATION_VERIFY;
51811042SErik.Nordmark@Sun.COM
51911042SErik.Nordmark@Sun.COM if (ixa->ixa_nce != NULL)
52011042SErik.Nordmark@Sun.COM nce_refrele(ixa->ixa_nce);
52111042SErik.Nordmark@Sun.COM ixa->ixa_nce = nce;
52211042SErik.Nordmark@Sun.COM return (0);
52311042SErik.Nordmark@Sun.COM }
52411042SErik.Nordmark@Sun.COM
52511042SErik.Nordmark@Sun.COM /*
52611042SErik.Nordmark@Sun.COM * Handle both IPv4 and IPv6. Reverify/recalculate the NCE to use.
52711042SErik.Nordmark@Sun.COM */
52811042SErik.Nordmark@Sun.COM static int
ip_verify_nce(mblk_t * mp,ip_xmit_attr_t * ixa)52911042SErik.Nordmark@Sun.COM ip_verify_nce(mblk_t *mp, ip_xmit_attr_t *ixa)
53011042SErik.Nordmark@Sun.COM {
53111042SErik.Nordmark@Sun.COM ire_t *ire = ixa->ixa_ire;
53211042SErik.Nordmark@Sun.COM nce_t *nce;
53311042SErik.Nordmark@Sun.COM int error = 0;
53411042SErik.Nordmark@Sun.COM ipha_t *ipha = NULL;
53511042SErik.Nordmark@Sun.COM ip6_t *ip6h = NULL;
53611042SErik.Nordmark@Sun.COM
53711042SErik.Nordmark@Sun.COM if (ire->ire_ipversion == IPV4_VERSION)
53811042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr;
53911042SErik.Nordmark@Sun.COM else
54011042SErik.Nordmark@Sun.COM ip6h = (ip6_t *)mp->b_rptr;
54111042SErik.Nordmark@Sun.COM
54211042SErik.Nordmark@Sun.COM nce = ire_handle_condemned_nce(ixa->ixa_nce, ire, ipha, ip6h, B_TRUE);
54311042SErik.Nordmark@Sun.COM if (nce == NULL) {
54411042SErik.Nordmark@Sun.COM /* Try to find a better ire */
54511042SErik.Nordmark@Sun.COM return (ip_verify_ire(mp, ixa));
54611042SErik.Nordmark@Sun.COM }
54711042SErik.Nordmark@Sun.COM
54811042SErik.Nordmark@Sun.COM /*
54911042SErik.Nordmark@Sun.COM * The hardware offloading capabilities, for example LSO, of the
55011042SErik.Nordmark@Sun.COM * interface might have changed, so do sanity verification here.
55111042SErik.Nordmark@Sun.COM */
55211042SErik.Nordmark@Sun.COM if (ixa->ixa_flags & IXAF_VERIFY_LSO) {
55311042SErik.Nordmark@Sun.COM if (!ip_verify_lso(nce->nce_ill, ixa)) {
55411042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_notify != NULL);
55511042SErik.Nordmark@Sun.COM ixa->ixa_notify(ixa->ixa_notify_cookie, ixa,
55611042SErik.Nordmark@Sun.COM IXAN_LSO, 0);
55711042SErik.Nordmark@Sun.COM error = ENOTSUP;
55811042SErik.Nordmark@Sun.COM }
55911042SErik.Nordmark@Sun.COM }
56011042SErik.Nordmark@Sun.COM
56111042SErik.Nordmark@Sun.COM /*
56211042SErik.Nordmark@Sun.COM * Verify ZEROCOPY capability of underlying ill. Notify the ULP with
56311042SErik.Nordmark@Sun.COM * any ZEROCOPY changes. In case ZEROCOPY capability is not available
56411042SErik.Nordmark@Sun.COM * any more, return error so that conn_ip_output() can take care of
56511042SErik.Nordmark@Sun.COM * the ZEROCOPY message properly. It's safe to continue send the
56611042SErik.Nordmark@Sun.COM * message when ZEROCOPY newly become available.
56711042SErik.Nordmark@Sun.COM */
56811042SErik.Nordmark@Sun.COM if (ixa->ixa_flags & IXAF_VERIFY_ZCOPY) {
56911042SErik.Nordmark@Sun.COM if (!ip_verify_zcopy(nce->nce_ill, ixa)) {
57011042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_notify != NULL);
57111042SErik.Nordmark@Sun.COM ixa->ixa_notify(ixa->ixa_notify_cookie, ixa,
57211042SErik.Nordmark@Sun.COM IXAN_ZCOPY, 0);
57311042SErik.Nordmark@Sun.COM if ((ixa->ixa_flags & IXAF_ZCOPY_CAPAB) == 0)
57411042SErik.Nordmark@Sun.COM error = ENOTSUP;
57511042SErik.Nordmark@Sun.COM }
57611042SErik.Nordmark@Sun.COM }
57711042SErik.Nordmark@Sun.COM
57811042SErik.Nordmark@Sun.COM /*
57911042SErik.Nordmark@Sun.COM * Since the path MTU might change as a result of this
58011042SErik.Nordmark@Sun.COM * change, we twiddle ixa_dce_generation to
58111042SErik.Nordmark@Sun.COM * make conn_ip_output go through the ip_verify_dce code.
58211042SErik.Nordmark@Sun.COM */
58311042SErik.Nordmark@Sun.COM ixa->ixa_dce_generation = DCE_GENERATION_VERIFY;
58411042SErik.Nordmark@Sun.COM
58511042SErik.Nordmark@Sun.COM nce_refrele(ixa->ixa_nce);
58611042SErik.Nordmark@Sun.COM ixa->ixa_nce = nce;
58711042SErik.Nordmark@Sun.COM return (error);
58811042SErik.Nordmark@Sun.COM }
58911042SErik.Nordmark@Sun.COM
59011042SErik.Nordmark@Sun.COM /*
59111042SErik.Nordmark@Sun.COM * Handle both IPv4 and IPv6. Reverify/recalculate the DCE to use.
59211042SErik.Nordmark@Sun.COM */
59311042SErik.Nordmark@Sun.COM static int
ip_verify_dce(mblk_t * mp,ip_xmit_attr_t * ixa)59411042SErik.Nordmark@Sun.COM ip_verify_dce(mblk_t *mp, ip_xmit_attr_t *ixa)
59511042SErik.Nordmark@Sun.COM {
59611042SErik.Nordmark@Sun.COM dce_t *dce;
59711042SErik.Nordmark@Sun.COM uint_t gen;
59811042SErik.Nordmark@Sun.COM uint_t pmtu;
59911042SErik.Nordmark@Sun.COM
60011042SErik.Nordmark@Sun.COM dce = dce_lookup_pkt(mp, ixa, &gen);
60111042SErik.Nordmark@Sun.COM ASSERT(dce != NULL);
60211042SErik.Nordmark@Sun.COM
60311042SErik.Nordmark@Sun.COM dce_refrele_notr(ixa->ixa_dce);
60411042SErik.Nordmark@Sun.COM #ifdef DEBUG
60511042SErik.Nordmark@Sun.COM dce_refhold_notr(dce);
60611042SErik.Nordmark@Sun.COM dce_refrele(dce);
60711042SErik.Nordmark@Sun.COM #endif
60811042SErik.Nordmark@Sun.COM ixa->ixa_dce = dce;
60911042SErik.Nordmark@Sun.COM ixa->ixa_dce_generation = gen;
61011042SErik.Nordmark@Sun.COM
61111042SErik.Nordmark@Sun.COM /* Extract the (path) mtu from the dce, ncec_ill etc */
61211042SErik.Nordmark@Sun.COM pmtu = ip_get_pmtu(ixa);
61311042SErik.Nordmark@Sun.COM
61411042SErik.Nordmark@Sun.COM /*
61511042SErik.Nordmark@Sun.COM * Tell ULP about PMTU changes - increase or decrease - by returning
61611042SErik.Nordmark@Sun.COM * an error if IXAF_VERIFY_PMTU is set. In such case, ULP should update
61711042SErik.Nordmark@Sun.COM * both ixa_pmtu and ixa_fragsize appropriately.
61811042SErik.Nordmark@Sun.COM *
61911042SErik.Nordmark@Sun.COM * If ULP doesn't set that flag then we need to update ixa_fragsize
62011042SErik.Nordmark@Sun.COM * since routing could have changed the ill after after ixa_fragsize
62111042SErik.Nordmark@Sun.COM * was set previously in the conn_ip_output path or in
62211042SErik.Nordmark@Sun.COM * ip_set_destination.
62311042SErik.Nordmark@Sun.COM *
62411042SErik.Nordmark@Sun.COM * In case of LSO, ixa_fragsize might be greater than ixa_pmtu.
62511042SErik.Nordmark@Sun.COM *
62611042SErik.Nordmark@Sun.COM * In the case of a path MTU increase we send the packet after the
62711042SErik.Nordmark@Sun.COM * notify to the ULP.
62811042SErik.Nordmark@Sun.COM */
62911042SErik.Nordmark@Sun.COM if (ixa->ixa_flags & IXAF_VERIFY_PMTU) {
63011042SErik.Nordmark@Sun.COM if (ixa->ixa_pmtu != pmtu) {
63111042SErik.Nordmark@Sun.COM uint_t oldmtu = ixa->ixa_pmtu;
63211042SErik.Nordmark@Sun.COM
63311042SErik.Nordmark@Sun.COM DTRACE_PROBE2(verify_pmtu, uint32_t, pmtu,
63411042SErik.Nordmark@Sun.COM uint32_t, ixa->ixa_pmtu);
63511042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_notify != NULL);
63611042SErik.Nordmark@Sun.COM ixa->ixa_notify(ixa->ixa_notify_cookie, ixa,
63711042SErik.Nordmark@Sun.COM IXAN_PMTU, pmtu);
63811042SErik.Nordmark@Sun.COM if (pmtu < oldmtu)
63911042SErik.Nordmark@Sun.COM return (EMSGSIZE);
64011042SErik.Nordmark@Sun.COM }
64111042SErik.Nordmark@Sun.COM } else {
64211042SErik.Nordmark@Sun.COM ixa->ixa_fragsize = pmtu;
64311042SErik.Nordmark@Sun.COM }
64411042SErik.Nordmark@Sun.COM return (0);
64511042SErik.Nordmark@Sun.COM }
64611042SErik.Nordmark@Sun.COM
64711042SErik.Nordmark@Sun.COM /*
64811042SErik.Nordmark@Sun.COM * Verify LSO usability. Keep the return value simple to indicate whether
64911042SErik.Nordmark@Sun.COM * the LSO capability has changed. Handle both IPv4 and IPv6.
65011042SErik.Nordmark@Sun.COM */
65111042SErik.Nordmark@Sun.COM static boolean_t
ip_verify_lso(ill_t * ill,ip_xmit_attr_t * ixa)65211042SErik.Nordmark@Sun.COM ip_verify_lso(ill_t *ill, ip_xmit_attr_t *ixa)
65311042SErik.Nordmark@Sun.COM {
65411042SErik.Nordmark@Sun.COM ill_lso_capab_t *lsoc = &ixa->ixa_lso_capab;
65511042SErik.Nordmark@Sun.COM ill_lso_capab_t *new_lsoc = ill->ill_lso_capab;
65611042SErik.Nordmark@Sun.COM
65711042SErik.Nordmark@Sun.COM if (ixa->ixa_flags & IXAF_LSO_CAPAB) {
65811042SErik.Nordmark@Sun.COM /*
65911042SErik.Nordmark@Sun.COM * Not unsable any more.
66011042SErik.Nordmark@Sun.COM */
66111042SErik.Nordmark@Sun.COM if ((ixa->ixa_flags & IXAF_IPSEC_SECURE) ||
66211042SErik.Nordmark@Sun.COM (ixa->ixa_ire->ire_type & (IRE_LOCAL | IRE_LOOPBACK)) ||
66311042SErik.Nordmark@Sun.COM (ixa->ixa_ire->ire_flags & RTF_MULTIRT) ||
66411042SErik.Nordmark@Sun.COM ((ixa->ixa_flags & IXAF_IS_IPV4) ?
66511042SErik.Nordmark@Sun.COM !ILL_LSO_TCP_IPV4_USABLE(ill) :
66611042SErik.Nordmark@Sun.COM !ILL_LSO_TCP_IPV6_USABLE(ill))) {
66711042SErik.Nordmark@Sun.COM ixa->ixa_flags &= ~IXAF_LSO_CAPAB;
66811042SErik.Nordmark@Sun.COM
66911042SErik.Nordmark@Sun.COM return (B_FALSE);
67011042SErik.Nordmark@Sun.COM }
67111042SErik.Nordmark@Sun.COM
67211042SErik.Nordmark@Sun.COM /*
67311042SErik.Nordmark@Sun.COM * Capability has changed, refresh the copy in ixa.
67411042SErik.Nordmark@Sun.COM */
67511042SErik.Nordmark@Sun.COM if (lsoc->ill_lso_max != new_lsoc->ill_lso_max) {
67611042SErik.Nordmark@Sun.COM *lsoc = *new_lsoc;
67711042SErik.Nordmark@Sun.COM
67811042SErik.Nordmark@Sun.COM return (B_FALSE);
67911042SErik.Nordmark@Sun.COM }
68011042SErik.Nordmark@Sun.COM } else { /* Was not usable */
68111042SErik.Nordmark@Sun.COM if (!(ixa->ixa_flags & IXAF_IPSEC_SECURE) &&
68211042SErik.Nordmark@Sun.COM !(ixa->ixa_ire->ire_type & (IRE_LOCAL | IRE_LOOPBACK)) &&
68311042SErik.Nordmark@Sun.COM !(ixa->ixa_ire->ire_flags & RTF_MULTIRT) &&
68411042SErik.Nordmark@Sun.COM ((ixa->ixa_flags & IXAF_IS_IPV4) ?
68511042SErik.Nordmark@Sun.COM ILL_LSO_TCP_IPV4_USABLE(ill) :
68611042SErik.Nordmark@Sun.COM ILL_LSO_TCP_IPV6_USABLE(ill))) {
68711042SErik.Nordmark@Sun.COM *lsoc = *new_lsoc;
68811042SErik.Nordmark@Sun.COM ixa->ixa_flags |= IXAF_LSO_CAPAB;
68911042SErik.Nordmark@Sun.COM
69011042SErik.Nordmark@Sun.COM return (B_FALSE);
69111042SErik.Nordmark@Sun.COM }
69211042SErik.Nordmark@Sun.COM }
69311042SErik.Nordmark@Sun.COM
69411042SErik.Nordmark@Sun.COM return (B_TRUE);
69511042SErik.Nordmark@Sun.COM }
69611042SErik.Nordmark@Sun.COM
69711042SErik.Nordmark@Sun.COM /*
69811042SErik.Nordmark@Sun.COM * Verify ZEROCOPY usability. Keep the return value simple to indicate whether
69911042SErik.Nordmark@Sun.COM * the ZEROCOPY capability has changed. Handle both IPv4 and IPv6.
70011042SErik.Nordmark@Sun.COM */
70111042SErik.Nordmark@Sun.COM static boolean_t
ip_verify_zcopy(ill_t * ill,ip_xmit_attr_t * ixa)70211042SErik.Nordmark@Sun.COM ip_verify_zcopy(ill_t *ill, ip_xmit_attr_t *ixa)
70311042SErik.Nordmark@Sun.COM {
70411042SErik.Nordmark@Sun.COM if (ixa->ixa_flags & IXAF_ZCOPY_CAPAB) {
70511042SErik.Nordmark@Sun.COM /*
70611042SErik.Nordmark@Sun.COM * Not unsable any more.
70711042SErik.Nordmark@Sun.COM */
70811042SErik.Nordmark@Sun.COM if ((ixa->ixa_flags & IXAF_IPSEC_SECURE) ||
70911042SErik.Nordmark@Sun.COM (ixa->ixa_ire->ire_type & (IRE_LOCAL | IRE_LOOPBACK)) ||
71011042SErik.Nordmark@Sun.COM (ixa->ixa_ire->ire_flags & RTF_MULTIRT) ||
71111042SErik.Nordmark@Sun.COM !ILL_ZCOPY_USABLE(ill)) {
71211042SErik.Nordmark@Sun.COM ixa->ixa_flags &= ~IXAF_ZCOPY_CAPAB;
71311042SErik.Nordmark@Sun.COM
71411042SErik.Nordmark@Sun.COM return (B_FALSE);
71511042SErik.Nordmark@Sun.COM }
71611042SErik.Nordmark@Sun.COM } else { /* Was not usable */
71711042SErik.Nordmark@Sun.COM if (!(ixa->ixa_flags & IXAF_IPSEC_SECURE) &&
71811042SErik.Nordmark@Sun.COM !(ixa->ixa_ire->ire_type & (IRE_LOCAL | IRE_LOOPBACK)) &&
71911042SErik.Nordmark@Sun.COM !(ixa->ixa_ire->ire_flags & RTF_MULTIRT) &&
72011042SErik.Nordmark@Sun.COM ILL_ZCOPY_USABLE(ill)) {
72111042SErik.Nordmark@Sun.COM ixa->ixa_flags |= IXAF_ZCOPY_CAPAB;
72211042SErik.Nordmark@Sun.COM
72311042SErik.Nordmark@Sun.COM return (B_FALSE);
72411042SErik.Nordmark@Sun.COM }
72511042SErik.Nordmark@Sun.COM }
72611042SErik.Nordmark@Sun.COM
72711042SErik.Nordmark@Sun.COM return (B_TRUE);
72811042SErik.Nordmark@Sun.COM }
72911042SErik.Nordmark@Sun.COM
73011042SErik.Nordmark@Sun.COM
73111042SErik.Nordmark@Sun.COM /*
73211042SErik.Nordmark@Sun.COM * When there is no conn_t context, this will send a packet.
73311042SErik.Nordmark@Sun.COM * The caller must *not* have called conn_connect() or ip_attr_connect()
73411042SErik.Nordmark@Sun.COM * before calling ip_output_simple().
73511042SErik.Nordmark@Sun.COM * Handles IPv4 and IPv6. Returns zero or an errno such as ENETUNREACH.
73611042SErik.Nordmark@Sun.COM * Honors IXAF_SET_SOURCE.
73711042SErik.Nordmark@Sun.COM *
73811042SErik.Nordmark@Sun.COM * We acquire the ire and after calling ire_sendfn we release
73911042SErik.Nordmark@Sun.COM * the hold on the ire. Ditto for the nce and dce.
74011042SErik.Nordmark@Sun.COM *
74111042SErik.Nordmark@Sun.COM * This assumes that the caller has set the following in ip_xmit_attr_t:
74211042SErik.Nordmark@Sun.COM * ixa_tsl, ixa_zoneid, and ixa_ipst must always be set.
74311042SErik.Nordmark@Sun.COM * If ixa_ifindex is non-zero it means send out that ill. (If it is
74411042SErik.Nordmark@Sun.COM * an upper IPMP ill we load balance across the group; if a lower we send
74511042SErik.Nordmark@Sun.COM * on that lower ill without load balancing.)
74611042SErik.Nordmark@Sun.COM * IXAF_IS_IPV4 must be set correctly.
74711042SErik.Nordmark@Sun.COM * If IXAF_IPSEC_SECURE is set then the ixa_ipsec_* fields must be set.
74811042SErik.Nordmark@Sun.COM * If IXAF_NO_IPSEC is set we'd skip IPsec policy lookup.
74911042SErik.Nordmark@Sun.COM * If neither of those two are set we do an IPsec policy lookup.
75011042SErik.Nordmark@Sun.COM *
75111042SErik.Nordmark@Sun.COM * We handle setting things like
75211042SErik.Nordmark@Sun.COM * ixa_pktlen
75311042SErik.Nordmark@Sun.COM * ixa_ip_hdr_length
75411042SErik.Nordmark@Sun.COM * ixa->ixa_protocol
75511042SErik.Nordmark@Sun.COM *
75611042SErik.Nordmark@Sun.COM * The caller may set ixa_xmit_hint, which is used for ECMP selection and
75711042SErik.Nordmark@Sun.COM * transmit ring selecting in GLD.
75811042SErik.Nordmark@Sun.COM *
75911042SErik.Nordmark@Sun.COM * The caller must do an ixa_cleanup() to release any IPsec references
76011042SErik.Nordmark@Sun.COM * after we return.
76111042SErik.Nordmark@Sun.COM */
76211042SErik.Nordmark@Sun.COM int
ip_output_simple(mblk_t * mp,ip_xmit_attr_t * ixa)76311042SErik.Nordmark@Sun.COM ip_output_simple(mblk_t *mp, ip_xmit_attr_t *ixa)
76411042SErik.Nordmark@Sun.COM {
76511042SErik.Nordmark@Sun.COM ts_label_t *effective_tsl = NULL;
76611042SErik.Nordmark@Sun.COM int err;
76711042SErik.Nordmark@Sun.COM
76811042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_ipst != NULL);
76911042SErik.Nordmark@Sun.COM
77011042SErik.Nordmark@Sun.COM if (is_system_labeled()) {
77111042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ixa->ixa_ipst;
77211042SErik.Nordmark@Sun.COM
77311042SErik.Nordmark@Sun.COM if (ixa->ixa_flags & IXAF_IS_IPV4) {
77411042SErik.Nordmark@Sun.COM err = tsol_check_label_v4(ixa->ixa_tsl, ixa->ixa_zoneid,
77511042SErik.Nordmark@Sun.COM &mp, CONN_MAC_DEFAULT, B_FALSE, ixa->ixa_ipst,
77611042SErik.Nordmark@Sun.COM &effective_tsl);
77711042SErik.Nordmark@Sun.COM } else {
77811042SErik.Nordmark@Sun.COM err = tsol_check_label_v6(ixa->ixa_tsl, ixa->ixa_zoneid,
77911042SErik.Nordmark@Sun.COM &mp, CONN_MAC_DEFAULT, B_FALSE, ixa->ixa_ipst,
78011042SErik.Nordmark@Sun.COM &effective_tsl);
78111042SErik.Nordmark@Sun.COM }
78211042SErik.Nordmark@Sun.COM if (err != 0) {
78311042SErik.Nordmark@Sun.COM ip2dbg(("tsol_check: label check failed (%d)\n", err));
78411042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsHCOutRequests);
78511042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsOutDiscards);
78611042SErik.Nordmark@Sun.COM ip_drop_output("tsol_check_label", mp, NULL);
78711042SErik.Nordmark@Sun.COM freemsg(mp);
78811042SErik.Nordmark@Sun.COM return (err);
78911042SErik.Nordmark@Sun.COM }
79011042SErik.Nordmark@Sun.COM if (effective_tsl != NULL) {
79111042SErik.Nordmark@Sun.COM /* Update the label */
79211042SErik.Nordmark@Sun.COM ip_xmit_attr_replace_tsl(ixa, effective_tsl);
79311042SErik.Nordmark@Sun.COM }
79411042SErik.Nordmark@Sun.COM }
79511042SErik.Nordmark@Sun.COM
79611042SErik.Nordmark@Sun.COM if (ixa->ixa_flags & IXAF_IS_IPV4)
79711042SErik.Nordmark@Sun.COM return (ip_output_simple_v4(mp, ixa));
79811042SErik.Nordmark@Sun.COM else
79911042SErik.Nordmark@Sun.COM return (ip_output_simple_v6(mp, ixa));
80011042SErik.Nordmark@Sun.COM }
80111042SErik.Nordmark@Sun.COM
80211042SErik.Nordmark@Sun.COM int
ip_output_simple_v4(mblk_t * mp,ip_xmit_attr_t * ixa)80311042SErik.Nordmark@Sun.COM ip_output_simple_v4(mblk_t *mp, ip_xmit_attr_t *ixa)
80411042SErik.Nordmark@Sun.COM {
80511042SErik.Nordmark@Sun.COM ipha_t *ipha;
80611042SErik.Nordmark@Sun.COM ipaddr_t firsthop; /* In IP header */
80711042SErik.Nordmark@Sun.COM ipaddr_t dst; /* End of source route, or ipha_dst if none */
80811042SErik.Nordmark@Sun.COM ire_t *ire;
80911042SErik.Nordmark@Sun.COM ipaddr_t setsrc; /* RTF_SETSRC */
81011042SErik.Nordmark@Sun.COM int error;
81111042SErik.Nordmark@Sun.COM ill_t *ill = NULL;
81211042SErik.Nordmark@Sun.COM dce_t *dce = NULL;
81311042SErik.Nordmark@Sun.COM nce_t *nce;
81411042SErik.Nordmark@Sun.COM iaflags_t ixaflags = ixa->ixa_flags;
81511042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ixa->ixa_ipst;
81611042SErik.Nordmark@Sun.COM boolean_t repeat = B_FALSE;
81711042SErik.Nordmark@Sun.COM boolean_t multirt = B_FALSE;
81811066Srafael.vanoni@sun.com int64_t now;
81911042SErik.Nordmark@Sun.COM
82011042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr;
82111042SErik.Nordmark@Sun.COM ASSERT(IPH_HDR_VERSION(ipha) == IPV4_VERSION);
82211042SErik.Nordmark@Sun.COM
82311042SErik.Nordmark@Sun.COM /*
82411042SErik.Nordmark@Sun.COM * Even on labeled systems we can have a NULL ixa_tsl e.g.,
82511042SErik.Nordmark@Sun.COM * for IGMP/MLD traffic.
82611042SErik.Nordmark@Sun.COM */
82711042SErik.Nordmark@Sun.COM
82811042SErik.Nordmark@Sun.COM /* Caller already set flags */
82911042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_flags & IXAF_IS_IPV4);
83011042SErik.Nordmark@Sun.COM
83111042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_nce == NULL);
83211042SErik.Nordmark@Sun.COM
83311042SErik.Nordmark@Sun.COM ixa->ixa_pktlen = ntohs(ipha->ipha_length);
83411042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_pktlen == msgdsize(mp));
83511042SErik.Nordmark@Sun.COM ixa->ixa_ip_hdr_length = IPH_HDR_LENGTH(ipha);
83611042SErik.Nordmark@Sun.COM ixa->ixa_protocol = ipha->ipha_protocol;
83711042SErik.Nordmark@Sun.COM
83811042SErik.Nordmark@Sun.COM /*
83911042SErik.Nordmark@Sun.COM * Assumes that source routed packets have already been massaged by
84011042SErik.Nordmark@Sun.COM * the ULP (ip_massage_options) and as a result ipha_dst is the next
84111042SErik.Nordmark@Sun.COM * hop in the source route. The final destination is used for IPsec
84211042SErik.Nordmark@Sun.COM * policy and DCE lookup.
84311042SErik.Nordmark@Sun.COM */
84411042SErik.Nordmark@Sun.COM firsthop = ipha->ipha_dst;
84511042SErik.Nordmark@Sun.COM dst = ip_get_dst(ipha);
84611042SErik.Nordmark@Sun.COM
84711042SErik.Nordmark@Sun.COM repeat_ire:
84811042SErik.Nordmark@Sun.COM error = 0;
84911042SErik.Nordmark@Sun.COM setsrc = INADDR_ANY;
85011681SSowmini.Varadhan@Sun.COM ire = ip_select_route_v4(firsthop, ipha->ipha_src, ixa, NULL,
85111681SSowmini.Varadhan@Sun.COM &setsrc, &error, &multirt);
85211042SErik.Nordmark@Sun.COM ASSERT(ire != NULL); /* IRE_NOROUTE if none found */
85311042SErik.Nordmark@Sun.COM if (error != 0) {
85411042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsHCOutRequests);
85511042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsOutDiscards);
85611042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards - select route", mp, NULL);
85711042SErik.Nordmark@Sun.COM freemsg(mp);
85811042SErik.Nordmark@Sun.COM goto done;
85911042SErik.Nordmark@Sun.COM }
86011042SErik.Nordmark@Sun.COM
86111042SErik.Nordmark@Sun.COM if (ire->ire_flags & (RTF_BLACKHOLE|RTF_REJECT)) {
86211042SErik.Nordmark@Sun.COM /* ire_ill might be NULL hence need to skip some code */
86311042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_SET_SOURCE)
86411042SErik.Nordmark@Sun.COM ipha->ipha_src = htonl(INADDR_LOOPBACK);
86511042SErik.Nordmark@Sun.COM ixa->ixa_fragsize = IP_MAXPACKET;
86611042SErik.Nordmark@Sun.COM ill = NULL;
86711042SErik.Nordmark@Sun.COM nce = NULL;
86811042SErik.Nordmark@Sun.COM ire->ire_ob_pkt_count++;
86911042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsHCOutRequests);
87011042SErik.Nordmark@Sun.COM /* No dce yet; use default one */
87111042SErik.Nordmark@Sun.COM error = (ire->ire_sendfn)(ire, mp, ipha, ixa,
87211042SErik.Nordmark@Sun.COM &ipst->ips_dce_default->dce_ident);
87311042SErik.Nordmark@Sun.COM goto done;
87411042SErik.Nordmark@Sun.COM }
87511042SErik.Nordmark@Sun.COM
87611042SErik.Nordmark@Sun.COM /* Note that ipha_dst is only used for IRE_MULTICAST */
87711042SErik.Nordmark@Sun.COM nce = ire_to_nce(ire, ipha->ipha_dst, NULL);
87811042SErik.Nordmark@Sun.COM if (nce == NULL) {
87911042SErik.Nordmark@Sun.COM /* Allocation failure? */
88011042SErik.Nordmark@Sun.COM ip_drop_output("ire_to_nce", mp, ill);
88111042SErik.Nordmark@Sun.COM freemsg(mp);
88211042SErik.Nordmark@Sun.COM error = ENOBUFS;
88311042SErik.Nordmark@Sun.COM goto done;
88411042SErik.Nordmark@Sun.COM }
88511042SErik.Nordmark@Sun.COM if (nce->nce_is_condemned) {
88611042SErik.Nordmark@Sun.COM nce_t *nce1;
88711042SErik.Nordmark@Sun.COM
88811042SErik.Nordmark@Sun.COM nce1 = ire_handle_condemned_nce(nce, ire, ipha, NULL, B_TRUE);
88911042SErik.Nordmark@Sun.COM nce_refrele(nce);
89011042SErik.Nordmark@Sun.COM if (nce1 == NULL) {
89111042SErik.Nordmark@Sun.COM if (!repeat) {
89211042SErik.Nordmark@Sun.COM /* Try finding a better IRE */
89311042SErik.Nordmark@Sun.COM repeat = B_TRUE;
89411042SErik.Nordmark@Sun.COM ire_refrele(ire);
89511042SErik.Nordmark@Sun.COM goto repeat_ire;
89611042SErik.Nordmark@Sun.COM }
89711042SErik.Nordmark@Sun.COM /* Tried twice - drop packet */
89811042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsOutDiscards);
89911042SErik.Nordmark@Sun.COM ip_drop_output("No nce", mp, ill);
90011042SErik.Nordmark@Sun.COM freemsg(mp);
90111042SErik.Nordmark@Sun.COM error = ENOBUFS;
90211042SErik.Nordmark@Sun.COM goto done;
90311042SErik.Nordmark@Sun.COM }
90411042SErik.Nordmark@Sun.COM nce = nce1;
90511042SErik.Nordmark@Sun.COM }
90611042SErik.Nordmark@Sun.COM
90711042SErik.Nordmark@Sun.COM /*
90811042SErik.Nordmark@Sun.COM * For multicast with multirt we have a flag passed back from
90911042SErik.Nordmark@Sun.COM * ire_lookup_multi_ill_v4 since we don't have an IRE for each
91011042SErik.Nordmark@Sun.COM * possible multicast address.
91111042SErik.Nordmark@Sun.COM * We also need a flag for multicast since we can't check
91211042SErik.Nordmark@Sun.COM * whether RTF_MULTIRT is set in ixa_ire for multicast.
91311042SErik.Nordmark@Sun.COM */
91411042SErik.Nordmark@Sun.COM if (multirt) {
91511042SErik.Nordmark@Sun.COM ixa->ixa_postfragfn = ip_postfrag_multirt_v4;
91611042SErik.Nordmark@Sun.COM ixa->ixa_flags |= IXAF_MULTIRT_MULTICAST;
91711042SErik.Nordmark@Sun.COM } else {
91811042SErik.Nordmark@Sun.COM ixa->ixa_postfragfn = ire->ire_postfragfn;
91911042SErik.Nordmark@Sun.COM ixa->ixa_flags &= ~IXAF_MULTIRT_MULTICAST;
92011042SErik.Nordmark@Sun.COM }
92111042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_nce == NULL);
92211042SErik.Nordmark@Sun.COM ixa->ixa_nce = nce;
92311042SErik.Nordmark@Sun.COM
92411042SErik.Nordmark@Sun.COM /*
92511042SErik.Nordmark@Sun.COM * Check for a dce_t with a path mtu.
92611042SErik.Nordmark@Sun.COM */
92711042SErik.Nordmark@Sun.COM dce = dce_lookup_v4(dst, ipst, NULL);
92811042SErik.Nordmark@Sun.COM ASSERT(dce != NULL);
92911042SErik.Nordmark@Sun.COM
93011042SErik.Nordmark@Sun.COM if (!(ixaflags & IXAF_PMTU_DISCOVERY)) {
93111042SErik.Nordmark@Sun.COM ixa->ixa_fragsize = ip_get_base_mtu(nce->nce_ill, ire);
93211042SErik.Nordmark@Sun.COM } else if (dce->dce_flags & DCEF_PMTU) {
93311042SErik.Nordmark@Sun.COM /*
93411042SErik.Nordmark@Sun.COM * To avoid a periodic timer to increase the path MTU we
93511042SErik.Nordmark@Sun.COM * look at dce_last_change_time each time we send a packet.
93611042SErik.Nordmark@Sun.COM */
93711066Srafael.vanoni@sun.com now = ddi_get_lbolt64();
93811066Srafael.vanoni@sun.com if (TICK_TO_SEC(now) - dce->dce_last_change_time >
93911042SErik.Nordmark@Sun.COM ipst->ips_ip_pathmtu_interval) {
94011042SErik.Nordmark@Sun.COM /*
94111042SErik.Nordmark@Sun.COM * Older than 20 minutes. Drop the path MTU information.
94211042SErik.Nordmark@Sun.COM */
94311042SErik.Nordmark@Sun.COM mutex_enter(&dce->dce_lock);
94411042SErik.Nordmark@Sun.COM dce->dce_flags &= ~(DCEF_PMTU|DCEF_TOO_SMALL_PMTU);
94511066Srafael.vanoni@sun.com dce->dce_last_change_time = TICK_TO_SEC(now);
94611042SErik.Nordmark@Sun.COM mutex_exit(&dce->dce_lock);
94711042SErik.Nordmark@Sun.COM dce_increment_generation(dce);
94811042SErik.Nordmark@Sun.COM ixa->ixa_fragsize = ip_get_base_mtu(nce->nce_ill, ire);
94911042SErik.Nordmark@Sun.COM } else {
95011042SErik.Nordmark@Sun.COM uint_t fragsize;
95111042SErik.Nordmark@Sun.COM
95211042SErik.Nordmark@Sun.COM fragsize = ip_get_base_mtu(nce->nce_ill, ire);
95311042SErik.Nordmark@Sun.COM if (fragsize > dce->dce_pmtu)
95411042SErik.Nordmark@Sun.COM fragsize = dce->dce_pmtu;
95511042SErik.Nordmark@Sun.COM ixa->ixa_fragsize = fragsize;
95611042SErik.Nordmark@Sun.COM }
95711042SErik.Nordmark@Sun.COM } else {
95811042SErik.Nordmark@Sun.COM ixa->ixa_fragsize = ip_get_base_mtu(nce->nce_ill, ire);
95911042SErik.Nordmark@Sun.COM }
96011042SErik.Nordmark@Sun.COM
96111042SErik.Nordmark@Sun.COM /*
96211042SErik.Nordmark@Sun.COM * We use use ire_nexthop_ill (and not ncec_ill) to avoid the under ipmp
96311042SErik.Nordmark@Sun.COM * interface for source address selection.
96411042SErik.Nordmark@Sun.COM */
96511042SErik.Nordmark@Sun.COM ill = ire_nexthop_ill(ire);
96611042SErik.Nordmark@Sun.COM
96711042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_SET_SOURCE) {
96811042SErik.Nordmark@Sun.COM ipaddr_t src;
96911042SErik.Nordmark@Sun.COM
97011042SErik.Nordmark@Sun.COM /*
97111042SErik.Nordmark@Sun.COM * We use the final destination to get
97211042SErik.Nordmark@Sun.COM * correct selection for source routed packets
97311042SErik.Nordmark@Sun.COM */
97411042SErik.Nordmark@Sun.COM
97511042SErik.Nordmark@Sun.COM /* If unreachable we have no ill but need some source */
97611042SErik.Nordmark@Sun.COM if (ill == NULL) {
97711042SErik.Nordmark@Sun.COM src = htonl(INADDR_LOOPBACK);
97811042SErik.Nordmark@Sun.COM error = 0;
97911042SErik.Nordmark@Sun.COM } else {
98011042SErik.Nordmark@Sun.COM error = ip_select_source_v4(ill, setsrc, dst,
98111042SErik.Nordmark@Sun.COM ixa->ixa_multicast_ifaddr, ixa->ixa_zoneid, ipst,
98211042SErik.Nordmark@Sun.COM &src, NULL, NULL);
98311042SErik.Nordmark@Sun.COM }
98411042SErik.Nordmark@Sun.COM if (error != 0) {
98511042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCOutRequests);
98611042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsOutDiscards);
98711042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards - no source",
98811042SErik.Nordmark@Sun.COM mp, ill);
98911042SErik.Nordmark@Sun.COM freemsg(mp);
99011042SErik.Nordmark@Sun.COM goto done;
99111042SErik.Nordmark@Sun.COM }
99211042SErik.Nordmark@Sun.COM ipha->ipha_src = src;
99311042SErik.Nordmark@Sun.COM } else if (ixaflags & IXAF_VERIFY_SOURCE) {
99411042SErik.Nordmark@Sun.COM /* Check if the IP source is assigned to the host. */
99511042SErik.Nordmark@Sun.COM if (!ip_verify_src(mp, ixa, NULL)) {
99611042SErik.Nordmark@Sun.COM /* Don't send a packet with a source that isn't ours */
99711042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsHCOutRequests);
99811042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsOutDiscards);
99911042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards - invalid source",
100011042SErik.Nordmark@Sun.COM mp, ill);
100111042SErik.Nordmark@Sun.COM freemsg(mp);
100211042SErik.Nordmark@Sun.COM error = EADDRNOTAVAIL;
100311042SErik.Nordmark@Sun.COM goto done;
100411042SErik.Nordmark@Sun.COM }
100511042SErik.Nordmark@Sun.COM }
100611042SErik.Nordmark@Sun.COM
100711042SErik.Nordmark@Sun.COM
100811042SErik.Nordmark@Sun.COM /*
100911042SErik.Nordmark@Sun.COM * Check against global IPsec policy to set the AH/ESP attributes.
101011042SErik.Nordmark@Sun.COM * IPsec will set IXAF_IPSEC_* and ixa_ipsec_* as appropriate.
101111042SErik.Nordmark@Sun.COM */
101211042SErik.Nordmark@Sun.COM if (!(ixaflags & (IXAF_NO_IPSEC|IXAF_IPSEC_SECURE))) {
101311042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_ipsec_policy == NULL);
101411042SErik.Nordmark@Sun.COM mp = ip_output_attach_policy(mp, ipha, NULL, NULL, ixa);
101511042SErik.Nordmark@Sun.COM if (mp == NULL) {
101611042SErik.Nordmark@Sun.COM /* MIB and ip_drop_packet already done */
101711042SErik.Nordmark@Sun.COM return (EHOSTUNREACH); /* IPsec policy failure */
101811042SErik.Nordmark@Sun.COM }
101911042SErik.Nordmark@Sun.COM }
102011042SErik.Nordmark@Sun.COM
102111042SErik.Nordmark@Sun.COM if (ill != NULL) {
102211042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCOutRequests);
102311042SErik.Nordmark@Sun.COM } else {
102411042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsHCOutRequests);
102511042SErik.Nordmark@Sun.COM }
102611042SErik.Nordmark@Sun.COM
102711042SErik.Nordmark@Sun.COM /*
102811042SErik.Nordmark@Sun.COM * We update the statistics on the most specific IRE i.e., the first
102911042SErik.Nordmark@Sun.COM * one we found.
103011042SErik.Nordmark@Sun.COM * We don't have an IRE when we fragment, hence ire_ob_pkt_count
103111042SErik.Nordmark@Sun.COM * can only count the use prior to fragmentation. However the MIB
103211042SErik.Nordmark@Sun.COM * counters on the ill will be incremented in post fragmentation.
103311042SErik.Nordmark@Sun.COM */
103411042SErik.Nordmark@Sun.COM ire->ire_ob_pkt_count++;
103511042SErik.Nordmark@Sun.COM
103611042SErik.Nordmark@Sun.COM /*
103711042SErik.Nordmark@Sun.COM * Based on ire_type and ire_flags call one of:
103811042SErik.Nordmark@Sun.COM * ire_send_local_v4 - for IRE_LOCAL and IRE_LOOPBACK
103911042SErik.Nordmark@Sun.COM * ire_send_multirt_v4 - if RTF_MULTIRT
104011042SErik.Nordmark@Sun.COM * ire_send_noroute_v4 - if RTF_REJECT or RTF_BLACHOLE
104111042SErik.Nordmark@Sun.COM * ire_send_multicast_v4 - for IRE_MULTICAST
104211042SErik.Nordmark@Sun.COM * ire_send_broadcast_v4 - for IRE_BROADCAST
104311042SErik.Nordmark@Sun.COM * ire_send_wire_v4 - for the rest.
104411042SErik.Nordmark@Sun.COM */
104511042SErik.Nordmark@Sun.COM error = (ire->ire_sendfn)(ire, mp, ipha, ixa, &dce->dce_ident);
104611042SErik.Nordmark@Sun.COM done:
104711042SErik.Nordmark@Sun.COM ire_refrele(ire);
104811042SErik.Nordmark@Sun.COM if (dce != NULL)
104911042SErik.Nordmark@Sun.COM dce_refrele(dce);
105011042SErik.Nordmark@Sun.COM if (ill != NULL)
105111042SErik.Nordmark@Sun.COM ill_refrele(ill);
105211042SErik.Nordmark@Sun.COM if (ixa->ixa_nce != NULL)
105311042SErik.Nordmark@Sun.COM nce_refrele(ixa->ixa_nce);
105411042SErik.Nordmark@Sun.COM ixa->ixa_nce = NULL;
105511042SErik.Nordmark@Sun.COM return (error);
105611042SErik.Nordmark@Sun.COM }
105711042SErik.Nordmark@Sun.COM
105811042SErik.Nordmark@Sun.COM /*
105911042SErik.Nordmark@Sun.COM * ire_sendfn() functions.
106011042SErik.Nordmark@Sun.COM * These functions use the following xmit_attr:
106111042SErik.Nordmark@Sun.COM * - ixa_fragsize - read to determine whether or not to fragment
106211042SErik.Nordmark@Sun.COM * - IXAF_IPSEC_SECURE - to determine whether or not to invoke IPsec
106311042SErik.Nordmark@Sun.COM * - ixa_ipsec_* are used inside IPsec
106411042SErik.Nordmark@Sun.COM * - IXAF_SET_SOURCE - replace IP source in broadcast case.
106511042SErik.Nordmark@Sun.COM * - IXAF_LOOPBACK_COPY - for multicast and broadcast
106611042SErik.Nordmark@Sun.COM */
106711042SErik.Nordmark@Sun.COM
106811042SErik.Nordmark@Sun.COM
106911042SErik.Nordmark@Sun.COM /*
107011042SErik.Nordmark@Sun.COM * ire_sendfn for IRE_LOCAL and IRE_LOOPBACK
107111042SErik.Nordmark@Sun.COM *
107211042SErik.Nordmark@Sun.COM * The checks for restrict_interzone_loopback are done in ire_route_recursive.
107311042SErik.Nordmark@Sun.COM */
107411042SErik.Nordmark@Sun.COM /* ARGSUSED4 */
107511042SErik.Nordmark@Sun.COM int
ire_send_local_v4(ire_t * ire,mblk_t * mp,void * iph_arg,ip_xmit_attr_t * ixa,uint32_t * identp)107611042SErik.Nordmark@Sun.COM ire_send_local_v4(ire_t *ire, mblk_t *mp, void *iph_arg,
107711042SErik.Nordmark@Sun.COM ip_xmit_attr_t *ixa, uint32_t *identp)
107811042SErik.Nordmark@Sun.COM {
107911042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)iph_arg;
108011042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ixa->ixa_ipst;
108111042SErik.Nordmark@Sun.COM ill_t *ill = ire->ire_ill;
108211042SErik.Nordmark@Sun.COM ip_recv_attr_t iras; /* NOTE: No bzero for performance */
108311042SErik.Nordmark@Sun.COM uint_t pktlen = ixa->ixa_pktlen;
108411042SErik.Nordmark@Sun.COM
108511042SErik.Nordmark@Sun.COM /*
108611042SErik.Nordmark@Sun.COM * No fragmentation, no nce, no application of IPsec,
108711042SErik.Nordmark@Sun.COM * and no ipha_ident assignment.
108811042SErik.Nordmark@Sun.COM *
108911042SErik.Nordmark@Sun.COM * Note different order between IP provider and FW_HOOKS than in
109011042SErik.Nordmark@Sun.COM * send_wire case.
109111042SErik.Nordmark@Sun.COM */
109211042SErik.Nordmark@Sun.COM
109311042SErik.Nordmark@Sun.COM /*
109411042SErik.Nordmark@Sun.COM * DTrace this as ip:::send. A packet blocked by FW_HOOKS will fire the
109511042SErik.Nordmark@Sun.COM * send probe, but not the receive probe.
109611042SErik.Nordmark@Sun.COM */
109711042SErik.Nordmark@Sun.COM DTRACE_IP7(send, mblk_t *, mp, conn_t *, NULL, void_ip_t *,
109811042SErik.Nordmark@Sun.COM ipha, __dtrace_ipsr_ill_t *, ill, ipha_t *, ipha, ip6_t *, NULL,
109911042SErik.Nordmark@Sun.COM int, 1);
110011042SErik.Nordmark@Sun.COM
110111042SErik.Nordmark@Sun.COM if (HOOKS4_INTERESTED_LOOPBACK_OUT(ipst)) {
110211042SErik.Nordmark@Sun.COM int error;
110311042SErik.Nordmark@Sun.COM
110411042SErik.Nordmark@Sun.COM DTRACE_PROBE4(ip4__loopback__out__start, ill_t *, NULL,
110511042SErik.Nordmark@Sun.COM ill_t *, ill, ipha_t *, ipha, mblk_t *, mp);
110611042SErik.Nordmark@Sun.COM FW_HOOKS(ipst->ips_ip4_loopback_out_event,
110711042SErik.Nordmark@Sun.COM ipst->ips_ipv4firewall_loopback_out,
110811042SErik.Nordmark@Sun.COM NULL, ill, ipha, mp, mp, 0, ipst, error);
110911042SErik.Nordmark@Sun.COM DTRACE_PROBE1(ip4__loopback__out__end, mblk_t *, mp);
111011042SErik.Nordmark@Sun.COM if (mp == NULL)
111111042SErik.Nordmark@Sun.COM return (error);
111211042SErik.Nordmark@Sun.COM
111311042SErik.Nordmark@Sun.COM /*
111411042SErik.Nordmark@Sun.COM * Even if the destination was changed by the filter we use the
111511042SErik.Nordmark@Sun.COM * forwarding decision that was made based on the address
111611042SErik.Nordmark@Sun.COM * in ip_output/ip_set_destination.
111711042SErik.Nordmark@Sun.COM */
111811042SErik.Nordmark@Sun.COM /* Length could be different */
111911042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr;
112011042SErik.Nordmark@Sun.COM pktlen = ntohs(ipha->ipha_length);
112111042SErik.Nordmark@Sun.COM }
112211042SErik.Nordmark@Sun.COM
112311042SErik.Nordmark@Sun.COM /*
112411042SErik.Nordmark@Sun.COM * If a callback is enabled then we need to know the
112511042SErik.Nordmark@Sun.COM * source and destination zoneids for the packet. We already
112611042SErik.Nordmark@Sun.COM * have those handy.
112711042SErik.Nordmark@Sun.COM */
112811042SErik.Nordmark@Sun.COM if (ipst->ips_ip4_observe.he_interested) {
112911042SErik.Nordmark@Sun.COM zoneid_t szone, dzone;
113011042SErik.Nordmark@Sun.COM zoneid_t stackzoneid;
113111042SErik.Nordmark@Sun.COM
113211042SErik.Nordmark@Sun.COM stackzoneid = netstackid_to_zoneid(
113311042SErik.Nordmark@Sun.COM ipst->ips_netstack->netstack_stackid);
113411042SErik.Nordmark@Sun.COM
113511042SErik.Nordmark@Sun.COM if (stackzoneid == GLOBAL_ZONEID) {
113611042SErik.Nordmark@Sun.COM /* Shared-IP zone */
113711042SErik.Nordmark@Sun.COM dzone = ire->ire_zoneid;
113811042SErik.Nordmark@Sun.COM szone = ixa->ixa_zoneid;
113911042SErik.Nordmark@Sun.COM } else {
114011042SErik.Nordmark@Sun.COM szone = dzone = stackzoneid;
114111042SErik.Nordmark@Sun.COM }
114211042SErik.Nordmark@Sun.COM ipobs_hook(mp, IPOBS_HOOK_LOCAL, szone, dzone, ill, ipst);
114311042SErik.Nordmark@Sun.COM }
114411042SErik.Nordmark@Sun.COM
114511042SErik.Nordmark@Sun.COM /* Handle lo0 stats */
114611042SErik.Nordmark@Sun.COM ipst->ips_loopback_packets++;
114711042SErik.Nordmark@Sun.COM
114811042SErik.Nordmark@Sun.COM /* Map ixa to ira including IPsec policies */
114911042SErik.Nordmark@Sun.COM ipsec_out_to_in(ixa, ill, &iras);
115011042SErik.Nordmark@Sun.COM iras.ira_pktlen = pktlen;
115111042SErik.Nordmark@Sun.COM
115211042SErik.Nordmark@Sun.COM if (!IS_SIMPLE_IPH(ipha)) {
115311042SErik.Nordmark@Sun.COM ip_output_local_options(ipha, ipst);
115411042SErik.Nordmark@Sun.COM iras.ira_flags |= IRAF_IPV4_OPTIONS;
115511042SErik.Nordmark@Sun.COM }
115611042SErik.Nordmark@Sun.COM
115711042SErik.Nordmark@Sun.COM if (HOOKS4_INTERESTED_LOOPBACK_IN(ipst)) {
115811042SErik.Nordmark@Sun.COM int error;
115911042SErik.Nordmark@Sun.COM
116011042SErik.Nordmark@Sun.COM DTRACE_PROBE4(ip4__loopback__in__start, ill_t *, ill,
116111042SErik.Nordmark@Sun.COM ill_t *, NULL, ipha_t *, ipha, mblk_t *, mp);
116211042SErik.Nordmark@Sun.COM FW_HOOKS(ipst->ips_ip4_loopback_in_event,
116311042SErik.Nordmark@Sun.COM ipst->ips_ipv4firewall_loopback_in,
116411042SErik.Nordmark@Sun.COM ill, NULL, ipha, mp, mp, 0, ipst, error);
116511042SErik.Nordmark@Sun.COM
116611042SErik.Nordmark@Sun.COM DTRACE_PROBE1(ip4__loopback__in__end, mblk_t *, mp);
116711042SErik.Nordmark@Sun.COM if (mp == NULL) {
116811042SErik.Nordmark@Sun.COM ira_cleanup(&iras, B_FALSE);
116911042SErik.Nordmark@Sun.COM return (error);
117011042SErik.Nordmark@Sun.COM }
117111042SErik.Nordmark@Sun.COM /*
117211042SErik.Nordmark@Sun.COM * Even if the destination was changed by the filter we use the
117311042SErik.Nordmark@Sun.COM * forwarding decision that was made based on the address
117411042SErik.Nordmark@Sun.COM * in ip_output/ip_set_destination.
117511042SErik.Nordmark@Sun.COM */
117611042SErik.Nordmark@Sun.COM /* Length could be different */
117711042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr;
117811042SErik.Nordmark@Sun.COM pktlen = iras.ira_pktlen = ntohs(ipha->ipha_length);
117911042SErik.Nordmark@Sun.COM }
118011042SErik.Nordmark@Sun.COM
118111042SErik.Nordmark@Sun.COM DTRACE_IP7(receive, mblk_t *, mp, conn_t *, NULL, void_ip_t *,
118211042SErik.Nordmark@Sun.COM ipha, __dtrace_ipsr_ill_t *, ill, ipha_t *, ipha, ip6_t *, NULL,
118311042SErik.Nordmark@Sun.COM int, 1);
118411042SErik.Nordmark@Sun.COM
118511042SErik.Nordmark@Sun.COM ire->ire_ib_pkt_count++;
118611042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInReceives);
118711042SErik.Nordmark@Sun.COM UPDATE_MIB(ill->ill_ip_mib, ipIfStatsHCInOctets, pktlen);
118811042SErik.Nordmark@Sun.COM
118911042SErik.Nordmark@Sun.COM /* Destined to ire_zoneid - use that for fanout */
119011042SErik.Nordmark@Sun.COM iras.ira_zoneid = ire->ire_zoneid;
119111042SErik.Nordmark@Sun.COM
119211042SErik.Nordmark@Sun.COM if (is_system_labeled()) {
119311042SErik.Nordmark@Sun.COM iras.ira_flags |= IRAF_SYSTEM_LABELED;
119411042SErik.Nordmark@Sun.COM
119511042SErik.Nordmark@Sun.COM /*
119611042SErik.Nordmark@Sun.COM * This updates ira_cred, ira_tsl and ira_free_flags based
119711042SErik.Nordmark@Sun.COM * on the label. We don't expect this to ever fail for
119811042SErik.Nordmark@Sun.COM * loopback packets, so we silently drop the packet should it
119911042SErik.Nordmark@Sun.COM * fail.
120011042SErik.Nordmark@Sun.COM */
120111042SErik.Nordmark@Sun.COM if (!tsol_get_pkt_label(mp, IPV4_VERSION, &iras)) {
120211042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
120311042SErik.Nordmark@Sun.COM ip_drop_input("tsol_get_pkt_label", mp, ill);
120411042SErik.Nordmark@Sun.COM freemsg(mp);
120511042SErik.Nordmark@Sun.COM return (0);
120611042SErik.Nordmark@Sun.COM }
120711042SErik.Nordmark@Sun.COM ASSERT(iras.ira_tsl != NULL);
120811042SErik.Nordmark@Sun.COM
120911042SErik.Nordmark@Sun.COM /* tsol_get_pkt_label sometimes does pullupmsg */
121011042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr;
121111042SErik.Nordmark@Sun.COM }
121211042SErik.Nordmark@Sun.COM
121311042SErik.Nordmark@Sun.COM ip_fanout_v4(mp, ipha, &iras);
121411042SErik.Nordmark@Sun.COM
121511042SErik.Nordmark@Sun.COM /* We moved any IPsec refs from ixa to iras */
121611042SErik.Nordmark@Sun.COM ira_cleanup(&iras, B_FALSE);
121711042SErik.Nordmark@Sun.COM return (0);
121811042SErik.Nordmark@Sun.COM }
121911042SErik.Nordmark@Sun.COM
122011042SErik.Nordmark@Sun.COM /*
122111042SErik.Nordmark@Sun.COM * ire_sendfn for IRE_BROADCAST
122211042SErik.Nordmark@Sun.COM * If the broadcast address is present on multiple ills and ixa_ifindex
122311042SErik.Nordmark@Sun.COM * isn't set, then we generate
122411042SErik.Nordmark@Sun.COM * a separate datagram (potentially with different source address) for
122511042SErik.Nordmark@Sun.COM * those ills. In any case, only one copy is looped back to ip_input_v4.
122611042SErik.Nordmark@Sun.COM */
122711042SErik.Nordmark@Sun.COM int
ire_send_broadcast_v4(ire_t * ire,mblk_t * mp,void * iph_arg,ip_xmit_attr_t * ixa,uint32_t * identp)122811042SErik.Nordmark@Sun.COM ire_send_broadcast_v4(ire_t *ire, mblk_t *mp, void *iph_arg,
122911042SErik.Nordmark@Sun.COM ip_xmit_attr_t *ixa, uint32_t *identp)
123011042SErik.Nordmark@Sun.COM {
123111042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)iph_arg;
123211042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ixa->ixa_ipst;
123311042SErik.Nordmark@Sun.COM irb_t *irb = ire->ire_bucket;
123411042SErik.Nordmark@Sun.COM ire_t *ire1;
123511042SErik.Nordmark@Sun.COM mblk_t *mp1;
123611042SErik.Nordmark@Sun.COM ipha_t *ipha1;
123711042SErik.Nordmark@Sun.COM iaflags_t ixaflags = ixa->ixa_flags;
123811042SErik.Nordmark@Sun.COM nce_t *nce1, *nce_orig;
123911042SErik.Nordmark@Sun.COM
124011042SErik.Nordmark@Sun.COM /*
124111042SErik.Nordmark@Sun.COM * Unless ire_send_multirt_v4 already set a ttl, force the
124211042SErik.Nordmark@Sun.COM * ttl to a smallish value.
124311042SErik.Nordmark@Sun.COM */
124411042SErik.Nordmark@Sun.COM if (!(ixa->ixa_flags & IXAF_NO_TTL_CHANGE)) {
124511042SErik.Nordmark@Sun.COM /*
124611042SErik.Nordmark@Sun.COM * To avoid broadcast storms, we usually set the TTL to 1 for
124711042SErik.Nordmark@Sun.COM * broadcasts. This can
124811042SErik.Nordmark@Sun.COM * be overridden stack-wide through the ip_broadcast_ttl
124911042SErik.Nordmark@Sun.COM * ndd tunable, or on a per-connection basis through the
125011042SErik.Nordmark@Sun.COM * IP_BROADCAST_TTL socket option.
125111042SErik.Nordmark@Sun.COM *
125211042SErik.Nordmark@Sun.COM * If SO_DONTROUTE/IXAF_DONTROUTE is set, then ire_send_wire_v4
125311042SErik.Nordmark@Sun.COM * will force ttl to one after we've set this.
125411042SErik.Nordmark@Sun.COM */
125511042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_BROADCAST_TTL_SET)
125611042SErik.Nordmark@Sun.COM ipha->ipha_ttl = ixa->ixa_broadcast_ttl;
125711042SErik.Nordmark@Sun.COM else
125811042SErik.Nordmark@Sun.COM ipha->ipha_ttl = ipst->ips_ip_broadcast_ttl;
125911042SErik.Nordmark@Sun.COM }
126011042SErik.Nordmark@Sun.COM /*
126111042SErik.Nordmark@Sun.COM * Make sure we get a loopback copy (after IPsec and frag)
126211042SErik.Nordmark@Sun.COM * Skip hardware checksum so that loopback copy is checksumed.
126311042SErik.Nordmark@Sun.COM */
126411042SErik.Nordmark@Sun.COM ixa->ixa_flags |= IXAF_LOOPBACK_COPY | IXAF_NO_HW_CKSUM;
126511042SErik.Nordmark@Sun.COM
126611042SErik.Nordmark@Sun.COM /* Do we need to potentially generate multiple copies? */
126711042SErik.Nordmark@Sun.COM if (irb->irb_ire_cnt == 1 || ixa->ixa_ifindex != 0)
126811042SErik.Nordmark@Sun.COM return (ire_send_wire_v4(ire, mp, ipha, ixa, identp));
126911042SErik.Nordmark@Sun.COM
127011042SErik.Nordmark@Sun.COM /*
127111042SErik.Nordmark@Sun.COM * Loop over all IRE_BROADCAST in the bucket (might only be one).
127211042SErik.Nordmark@Sun.COM * Note that everything in the bucket has the same destination address.
127311042SErik.Nordmark@Sun.COM */
127411042SErik.Nordmark@Sun.COM irb_refhold(irb);
127511042SErik.Nordmark@Sun.COM for (ire1 = irb->irb_ire; ire1 != NULL; ire1 = ire1->ire_next) {
127611042SErik.Nordmark@Sun.COM /* We do the main IRE after the end of the loop */
127711042SErik.Nordmark@Sun.COM if (ire1 == ire)
127811042SErik.Nordmark@Sun.COM continue;
127911042SErik.Nordmark@Sun.COM
128011042SErik.Nordmark@Sun.COM /*
128111042SErik.Nordmark@Sun.COM * Only IREs for the same IP address should be in the same
128211042SErik.Nordmark@Sun.COM * bucket.
128311042SErik.Nordmark@Sun.COM * But could have IRE_HOSTs in the case of CGTP.
128411042SErik.Nordmark@Sun.COM * If we find any multirt routes we bail out of the loop
128511042SErik.Nordmark@Sun.COM * and just do the single packet at the end; ip_postfrag_multirt
128611042SErik.Nordmark@Sun.COM * will duplicate the packet.
128711042SErik.Nordmark@Sun.COM */
128811042SErik.Nordmark@Sun.COM ASSERT(ire1->ire_addr == ire->ire_addr);
128911042SErik.Nordmark@Sun.COM if (!(ire1->ire_type & IRE_BROADCAST))
129011042SErik.Nordmark@Sun.COM continue;
129111042SErik.Nordmark@Sun.COM
129211042SErik.Nordmark@Sun.COM if (IRE_IS_CONDEMNED(ire1))
129311042SErik.Nordmark@Sun.COM continue;
129411042SErik.Nordmark@Sun.COM
129511042SErik.Nordmark@Sun.COM if (ixa->ixa_zoneid != ALL_ZONES &&
129611042SErik.Nordmark@Sun.COM ire->ire_zoneid != ire1->ire_zoneid)
129711042SErik.Nordmark@Sun.COM continue;
129811042SErik.Nordmark@Sun.COM
129911042SErik.Nordmark@Sun.COM ASSERT(ire->ire_ill != ire1->ire_ill && ire1->ire_ill != NULL);
130011042SErik.Nordmark@Sun.COM
130111042SErik.Nordmark@Sun.COM if (ire1->ire_flags & RTF_MULTIRT)
130211042SErik.Nordmark@Sun.COM break;
130311042SErik.Nordmark@Sun.COM
130411042SErik.Nordmark@Sun.COM /*
130511042SErik.Nordmark@Sun.COM * For IPMP we only send for the ipmp_ill. arp_nce_init() will
130611042SErik.Nordmark@Sun.COM * ensure that this goes out on the cast_ill.
130711042SErik.Nordmark@Sun.COM */
130811042SErik.Nordmark@Sun.COM if (IS_UNDER_IPMP(ire1->ire_ill))
130911042SErik.Nordmark@Sun.COM continue;
131011042SErik.Nordmark@Sun.COM
131111042SErik.Nordmark@Sun.COM mp1 = copymsg(mp);
131211042SErik.Nordmark@Sun.COM if (mp1 == NULL) {
131311042SErik.Nordmark@Sun.COM BUMP_MIB(ire1->ire_ill->ill_ip_mib,
131411042SErik.Nordmark@Sun.COM ipIfStatsOutDiscards);
131511042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards",
131611042SErik.Nordmark@Sun.COM mp, ire1->ire_ill);
131711042SErik.Nordmark@Sun.COM continue;
131811042SErik.Nordmark@Sun.COM }
131911042SErik.Nordmark@Sun.COM
132011042SErik.Nordmark@Sun.COM ipha1 = (ipha_t *)mp1->b_rptr;
132111042SErik.Nordmark@Sun.COM if (ixa->ixa_flags & IXAF_SET_SOURCE) {
132211042SErik.Nordmark@Sun.COM /*
132311042SErik.Nordmark@Sun.COM * Need to pick a different source address for each
132411042SErik.Nordmark@Sun.COM * interface. If we have a global IPsec policy and
132511042SErik.Nordmark@Sun.COM * no per-socket policy then we punt to
132611042SErik.Nordmark@Sun.COM * ip_output_simple_v4 using a separate ip_xmit_attr_t.
132711042SErik.Nordmark@Sun.COM */
132811042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_IPSEC_GLOBAL_POLICY) {
132911042SErik.Nordmark@Sun.COM ip_output_simple_broadcast(ixa, mp1);
133011042SErik.Nordmark@Sun.COM continue;
133111042SErik.Nordmark@Sun.COM }
133211042SErik.Nordmark@Sun.COM /* Pick a new source address for each interface */
133311042SErik.Nordmark@Sun.COM if (ip_select_source_v4(ire1->ire_ill, INADDR_ANY,
133411042SErik.Nordmark@Sun.COM ipha1->ipha_dst, INADDR_ANY, ixa->ixa_zoneid, ipst,
133511042SErik.Nordmark@Sun.COM &ipha1->ipha_src, NULL, NULL) != 0) {
133611042SErik.Nordmark@Sun.COM BUMP_MIB(ire1->ire_ill->ill_ip_mib,
133711042SErik.Nordmark@Sun.COM ipIfStatsOutDiscards);
133811042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards - select "
133911042SErik.Nordmark@Sun.COM "broadcast source", mp1, ire1->ire_ill);
134011042SErik.Nordmark@Sun.COM freemsg(mp1);
134111042SErik.Nordmark@Sun.COM continue;
134211042SErik.Nordmark@Sun.COM }
134311042SErik.Nordmark@Sun.COM /*
134411042SErik.Nordmark@Sun.COM * Check against global IPsec policy to set the AH/ESP
134511042SErik.Nordmark@Sun.COM * attributes. IPsec will set IXAF_IPSEC_* and
134611042SErik.Nordmark@Sun.COM * ixa_ipsec_* as appropriate.
134711042SErik.Nordmark@Sun.COM */
134811042SErik.Nordmark@Sun.COM if (!(ixaflags & (IXAF_NO_IPSEC|IXAF_IPSEC_SECURE))) {
134911042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_ipsec_policy == NULL);
135011042SErik.Nordmark@Sun.COM mp1 = ip_output_attach_policy(mp1, ipha, NULL,
135111042SErik.Nordmark@Sun.COM NULL, ixa);
135211042SErik.Nordmark@Sun.COM if (mp1 == NULL) {
135311042SErik.Nordmark@Sun.COM /*
135411042SErik.Nordmark@Sun.COM * MIB and ip_drop_packet already
135511042SErik.Nordmark@Sun.COM * done
135611042SErik.Nordmark@Sun.COM */
135711042SErik.Nordmark@Sun.COM continue;
135811042SErik.Nordmark@Sun.COM }
135911042SErik.Nordmark@Sun.COM }
136011042SErik.Nordmark@Sun.COM }
136111042SErik.Nordmark@Sun.COM /* Make sure we have an NCE on this ill */
136211042SErik.Nordmark@Sun.COM nce1 = arp_nce_init(ire1->ire_ill, ire1->ire_addr,
136311042SErik.Nordmark@Sun.COM ire1->ire_type);
136411042SErik.Nordmark@Sun.COM if (nce1 == NULL) {
136511042SErik.Nordmark@Sun.COM BUMP_MIB(ire1->ire_ill->ill_ip_mib,
136611042SErik.Nordmark@Sun.COM ipIfStatsOutDiscards);
136711042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards - broadcast nce",
136811042SErik.Nordmark@Sun.COM mp1, ire1->ire_ill);
136911042SErik.Nordmark@Sun.COM freemsg(mp1);
137011042SErik.Nordmark@Sun.COM continue;
137111042SErik.Nordmark@Sun.COM }
137211042SErik.Nordmark@Sun.COM nce_orig = ixa->ixa_nce;
137311042SErik.Nordmark@Sun.COM ixa->ixa_nce = nce1;
137411042SErik.Nordmark@Sun.COM
137511042SErik.Nordmark@Sun.COM ire_refhold(ire1);
137611042SErik.Nordmark@Sun.COM /*
137711042SErik.Nordmark@Sun.COM * Ignore any errors here. We just collect the errno for
137811042SErik.Nordmark@Sun.COM * the main ire below
137911042SErik.Nordmark@Sun.COM */
138011042SErik.Nordmark@Sun.COM (void) ire_send_wire_v4(ire1, mp1, ipha1, ixa, identp);
138111042SErik.Nordmark@Sun.COM ire_refrele(ire1);
138211042SErik.Nordmark@Sun.COM
138311042SErik.Nordmark@Sun.COM ixa->ixa_nce = nce_orig;
138411042SErik.Nordmark@Sun.COM nce_refrele(nce1);
138511042SErik.Nordmark@Sun.COM
138611042SErik.Nordmark@Sun.COM ixa->ixa_flags &= ~IXAF_LOOPBACK_COPY;
138711042SErik.Nordmark@Sun.COM }
138811042SErik.Nordmark@Sun.COM irb_refrele(irb);
138911042SErik.Nordmark@Sun.COM /* Finally, the main one */
139011042SErik.Nordmark@Sun.COM
139111042SErik.Nordmark@Sun.COM /*
139211042SErik.Nordmark@Sun.COM * For IPMP we only send broadcasts on the ipmp_ill.
139311042SErik.Nordmark@Sun.COM */
139411042SErik.Nordmark@Sun.COM if (IS_UNDER_IPMP(ire->ire_ill)) {
139511042SErik.Nordmark@Sun.COM freemsg(mp);
139611042SErik.Nordmark@Sun.COM return (0);
139711042SErik.Nordmark@Sun.COM }
139811042SErik.Nordmark@Sun.COM
139911042SErik.Nordmark@Sun.COM return (ire_send_wire_v4(ire, mp, ipha, ixa, identp));
140011042SErik.Nordmark@Sun.COM }
140111042SErik.Nordmark@Sun.COM
140211042SErik.Nordmark@Sun.COM /*
140311042SErik.Nordmark@Sun.COM * Send a packet using a different source address and different
140411042SErik.Nordmark@Sun.COM * IPsec policy.
140511042SErik.Nordmark@Sun.COM */
140611042SErik.Nordmark@Sun.COM static void
ip_output_simple_broadcast(ip_xmit_attr_t * ixa,mblk_t * mp)140711042SErik.Nordmark@Sun.COM ip_output_simple_broadcast(ip_xmit_attr_t *ixa, mblk_t *mp)
140811042SErik.Nordmark@Sun.COM {
140911042SErik.Nordmark@Sun.COM ip_xmit_attr_t ixas;
141011042SErik.Nordmark@Sun.COM
141111042SErik.Nordmark@Sun.COM bzero(&ixas, sizeof (ixas));
141211042SErik.Nordmark@Sun.COM ixas.ixa_flags = IXAF_BASIC_SIMPLE_V4;
141311042SErik.Nordmark@Sun.COM ixas.ixa_zoneid = ixa->ixa_zoneid;
141411042SErik.Nordmark@Sun.COM ixas.ixa_ifindex = 0;
141511042SErik.Nordmark@Sun.COM ixas.ixa_ipst = ixa->ixa_ipst;
141611042SErik.Nordmark@Sun.COM ixas.ixa_cred = ixa->ixa_cred;
141711042SErik.Nordmark@Sun.COM ixas.ixa_cpid = ixa->ixa_cpid;
141811042SErik.Nordmark@Sun.COM ixas.ixa_tsl = ixa->ixa_tsl;
141911042SErik.Nordmark@Sun.COM ixas.ixa_multicast_ttl = IP_DEFAULT_MULTICAST_TTL;
142011042SErik.Nordmark@Sun.COM
142111042SErik.Nordmark@Sun.COM (void) ip_output_simple(mp, &ixas);
142211042SErik.Nordmark@Sun.COM ixa_cleanup(&ixas);
142311042SErik.Nordmark@Sun.COM }
142411042SErik.Nordmark@Sun.COM
142511042SErik.Nordmark@Sun.COM
142611042SErik.Nordmark@Sun.COM static void
multirt_check_v4(ire_t * ire,ipha_t * ipha,ip_xmit_attr_t * ixa)142711042SErik.Nordmark@Sun.COM multirt_check_v4(ire_t *ire, ipha_t *ipha, ip_xmit_attr_t *ixa)
142811042SErik.Nordmark@Sun.COM {
142911042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ixa->ixa_ipst;
143011042SErik.Nordmark@Sun.COM
143111042SErik.Nordmark@Sun.COM /* Limit the TTL on multirt packets */
143211042SErik.Nordmark@Sun.COM if (ire->ire_type & IRE_MULTICAST) {
143311042SErik.Nordmark@Sun.COM if (ipha->ipha_ttl > 1) {
143411042SErik.Nordmark@Sun.COM ip2dbg(("ire_send_multirt_v4: forcing multicast "
143511042SErik.Nordmark@Sun.COM "multirt TTL to 1 (was %d), dst 0x%08x\n",
143611042SErik.Nordmark@Sun.COM ipha->ipha_ttl, ntohl(ire->ire_addr)));
143711042SErik.Nordmark@Sun.COM ipha->ipha_ttl = 1;
143811042SErik.Nordmark@Sun.COM }
143911042SErik.Nordmark@Sun.COM ixa->ixa_flags |= IXAF_NO_TTL_CHANGE;
144011042SErik.Nordmark@Sun.COM } else if ((ipst->ips_ip_multirt_ttl > 0) &&
144111042SErik.Nordmark@Sun.COM (ipha->ipha_ttl > ipst->ips_ip_multirt_ttl)) {
144211042SErik.Nordmark@Sun.COM ipha->ipha_ttl = ipst->ips_ip_multirt_ttl;
144311042SErik.Nordmark@Sun.COM /*
144411042SErik.Nordmark@Sun.COM * Need to ensure we don't increase the ttl should we go through
144511042SErik.Nordmark@Sun.COM * ire_send_broadcast or multicast.
144611042SErik.Nordmark@Sun.COM */
144711042SErik.Nordmark@Sun.COM ixa->ixa_flags |= IXAF_NO_TTL_CHANGE;
144811042SErik.Nordmark@Sun.COM }
144911042SErik.Nordmark@Sun.COM }
145011042SErik.Nordmark@Sun.COM
145111042SErik.Nordmark@Sun.COM /*
145211042SErik.Nordmark@Sun.COM * ire_sendfn for IRE_MULTICAST
145311042SErik.Nordmark@Sun.COM */
145411042SErik.Nordmark@Sun.COM int
ire_send_multicast_v4(ire_t * ire,mblk_t * mp,void * iph_arg,ip_xmit_attr_t * ixa,uint32_t * identp)145511042SErik.Nordmark@Sun.COM ire_send_multicast_v4(ire_t *ire, mblk_t *mp, void *iph_arg,
145611042SErik.Nordmark@Sun.COM ip_xmit_attr_t *ixa, uint32_t *identp)
145711042SErik.Nordmark@Sun.COM {
145811042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)iph_arg;
145911042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ixa->ixa_ipst;
146011042SErik.Nordmark@Sun.COM ill_t *ill = ire->ire_ill;
146111042SErik.Nordmark@Sun.COM iaflags_t ixaflags = ixa->ixa_flags;
146211042SErik.Nordmark@Sun.COM
146311042SErik.Nordmark@Sun.COM /*
146411042SErik.Nordmark@Sun.COM * The IRE_MULTICAST is the same whether or not multirt is in use.
146511042SErik.Nordmark@Sun.COM * Hence we need special-case code.
146611042SErik.Nordmark@Sun.COM */
146711042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_MULTIRT_MULTICAST)
146811042SErik.Nordmark@Sun.COM multirt_check_v4(ire, ipha, ixa);
146911042SErik.Nordmark@Sun.COM
147011042SErik.Nordmark@Sun.COM /*
147111042SErik.Nordmark@Sun.COM * Check if anything in ip_input_v4 wants a copy of the transmitted
147211042SErik.Nordmark@Sun.COM * packet (after IPsec and fragmentation)
147311042SErik.Nordmark@Sun.COM *
147411042SErik.Nordmark@Sun.COM * 1. Multicast routers always need a copy unless SO_DONTROUTE is set
147511042SErik.Nordmark@Sun.COM * RSVP and the rsvp daemon is an example of a
147611042SErik.Nordmark@Sun.COM * protocol and user level process that
147711042SErik.Nordmark@Sun.COM * handles it's own routing. Hence, it uses the
147811042SErik.Nordmark@Sun.COM * SO_DONTROUTE option to accomplish this.
147911042SErik.Nordmark@Sun.COM * 2. If the sender has set IP_MULTICAST_LOOP, then we just
148011042SErik.Nordmark@Sun.COM * check whether there are any receivers for the group on the ill
148111042SErik.Nordmark@Sun.COM * (ignoring the zoneid).
148211042SErik.Nordmark@Sun.COM * 3. If IP_MULTICAST_LOOP is not set, then we check if there are
148311042SErik.Nordmark@Sun.COM * any members in other shared-IP zones.
148411042SErik.Nordmark@Sun.COM * If such members exist, then we indicate that the sending zone
148511042SErik.Nordmark@Sun.COM * shouldn't get a loopback copy to preserve the IP_MULTICAST_LOOP
148611042SErik.Nordmark@Sun.COM * behavior.
148711042SErik.Nordmark@Sun.COM *
148811042SErik.Nordmark@Sun.COM * When we loopback we skip hardware checksum to make sure loopback
148911042SErik.Nordmark@Sun.COM * copy is checksumed.
149011042SErik.Nordmark@Sun.COM *
149111042SErik.Nordmark@Sun.COM * Note that ire_ill is the upper in the case of IPMP.
149211042SErik.Nordmark@Sun.COM */
149311042SErik.Nordmark@Sun.COM ixa->ixa_flags &= ~(IXAF_LOOPBACK_COPY | IXAF_NO_HW_CKSUM);
149411042SErik.Nordmark@Sun.COM if (ipst->ips_ip_g_mrouter && ill->ill_mrouter_cnt > 0 &&
149511042SErik.Nordmark@Sun.COM !(ixaflags & IXAF_DONTROUTE)) {
149611042SErik.Nordmark@Sun.COM ixa->ixa_flags |= IXAF_LOOPBACK_COPY | IXAF_NO_HW_CKSUM;
149711042SErik.Nordmark@Sun.COM } else if (ixaflags & IXAF_MULTICAST_LOOP) {
149811042SErik.Nordmark@Sun.COM /*
149911042SErik.Nordmark@Sun.COM * If this zone or any other zone has members then loopback
150011042SErik.Nordmark@Sun.COM * a copy.
150111042SErik.Nordmark@Sun.COM */
150211042SErik.Nordmark@Sun.COM if (ill_hasmembers_v4(ill, ipha->ipha_dst))
150311042SErik.Nordmark@Sun.COM ixa->ixa_flags |= IXAF_LOOPBACK_COPY | IXAF_NO_HW_CKSUM;
150411042SErik.Nordmark@Sun.COM } else if (ipst->ips_netstack->netstack_numzones > 1) {
150511042SErik.Nordmark@Sun.COM /*
150611042SErik.Nordmark@Sun.COM * This zone should not have a copy. But there are some other
150711042SErik.Nordmark@Sun.COM * zones which might have members.
150811042SErik.Nordmark@Sun.COM */
150911042SErik.Nordmark@Sun.COM if (ill_hasmembers_otherzones_v4(ill, ipha->ipha_dst,
151011042SErik.Nordmark@Sun.COM ixa->ixa_zoneid)) {
151111042SErik.Nordmark@Sun.COM ixa->ixa_flags |= IXAF_NO_LOOP_ZONEID_SET;
151211042SErik.Nordmark@Sun.COM ixa->ixa_no_loop_zoneid = ixa->ixa_zoneid;
151311042SErik.Nordmark@Sun.COM ixa->ixa_flags |= IXAF_LOOPBACK_COPY | IXAF_NO_HW_CKSUM;
151411042SErik.Nordmark@Sun.COM }
151511042SErik.Nordmark@Sun.COM }
151611042SErik.Nordmark@Sun.COM
151711042SErik.Nordmark@Sun.COM /*
151811042SErik.Nordmark@Sun.COM * Unless ire_send_multirt_v4 or icmp_output_hdrincl already set a ttl,
151911042SErik.Nordmark@Sun.COM * force the ttl to the IP_MULTICAST_TTL value
152011042SErik.Nordmark@Sun.COM */
152111042SErik.Nordmark@Sun.COM if (!(ixaflags & IXAF_NO_TTL_CHANGE)) {
152211042SErik.Nordmark@Sun.COM ipha->ipha_ttl = ixa->ixa_multicast_ttl;
152311042SErik.Nordmark@Sun.COM }
152411042SErik.Nordmark@Sun.COM
152511042SErik.Nordmark@Sun.COM return (ire_send_wire_v4(ire, mp, ipha, ixa, identp));
152611042SErik.Nordmark@Sun.COM }
152711042SErik.Nordmark@Sun.COM
152811042SErik.Nordmark@Sun.COM /*
152911042SErik.Nordmark@Sun.COM * ire_sendfn for IREs with RTF_MULTIRT
153011042SErik.Nordmark@Sun.COM */
153111042SErik.Nordmark@Sun.COM int
ire_send_multirt_v4(ire_t * ire,mblk_t * mp,void * iph_arg,ip_xmit_attr_t * ixa,uint32_t * identp)153211042SErik.Nordmark@Sun.COM ire_send_multirt_v4(ire_t *ire, mblk_t *mp, void *iph_arg,
153311042SErik.Nordmark@Sun.COM ip_xmit_attr_t *ixa, uint32_t *identp)
153411042SErik.Nordmark@Sun.COM {
153511042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)iph_arg;
153611042SErik.Nordmark@Sun.COM
153711042SErik.Nordmark@Sun.COM multirt_check_v4(ire, ipha, ixa);
153811042SErik.Nordmark@Sun.COM
153911042SErik.Nordmark@Sun.COM if (ire->ire_type & IRE_MULTICAST)
154011042SErik.Nordmark@Sun.COM return (ire_send_multicast_v4(ire, mp, ipha, ixa, identp));
154111042SErik.Nordmark@Sun.COM else if (ire->ire_type & IRE_BROADCAST)
154211042SErik.Nordmark@Sun.COM return (ire_send_broadcast_v4(ire, mp, ipha, ixa, identp));
154311042SErik.Nordmark@Sun.COM else
154411042SErik.Nordmark@Sun.COM return (ire_send_wire_v4(ire, mp, ipha, ixa, identp));
154511042SErik.Nordmark@Sun.COM }
154611042SErik.Nordmark@Sun.COM
154711042SErik.Nordmark@Sun.COM /*
154811042SErik.Nordmark@Sun.COM * ire_sendfn for IREs with RTF_REJECT/RTF_BLACKHOLE, including IRE_NOROUTE
154911042SErik.Nordmark@Sun.COM */
155011042SErik.Nordmark@Sun.COM int
ire_send_noroute_v4(ire_t * ire,mblk_t * mp,void * iph_arg,ip_xmit_attr_t * ixa,uint32_t * identp)155111042SErik.Nordmark@Sun.COM ire_send_noroute_v4(ire_t *ire, mblk_t *mp, void *iph_arg,
155211042SErik.Nordmark@Sun.COM ip_xmit_attr_t *ixa, uint32_t *identp)
155311042SErik.Nordmark@Sun.COM {
155411042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ixa->ixa_ipst;
155511042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)iph_arg;
155611042SErik.Nordmark@Sun.COM ill_t *ill;
155711042SErik.Nordmark@Sun.COM ip_recv_attr_t iras;
155811042SErik.Nordmark@Sun.COM boolean_t dummy;
155911042SErik.Nordmark@Sun.COM
156011042SErik.Nordmark@Sun.COM /* We assign an IP ident for nice errors */
156111042SErik.Nordmark@Sun.COM ipha->ipha_ident = atomic_add_32_nv(identp, 1);
156211042SErik.Nordmark@Sun.COM
156311042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsOutNoRoutes);
156411042SErik.Nordmark@Sun.COM
156511042SErik.Nordmark@Sun.COM if (ire->ire_type & IRE_NOROUTE) {
156611042SErik.Nordmark@Sun.COM /* A lack of a route as opposed to RTF_REJECT|BLACKHOLE */
156711042SErik.Nordmark@Sun.COM ip_rts_change(RTM_MISS, ipha->ipha_dst, 0, 0, 0, 0, 0, 0,
156811042SErik.Nordmark@Sun.COM RTA_DST, ipst);
156911042SErik.Nordmark@Sun.COM }
157011042SErik.Nordmark@Sun.COM
157111042SErik.Nordmark@Sun.COM if (ire->ire_flags & RTF_BLACKHOLE) {
157211042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutNoRoutes RTF_BLACKHOLE", mp, NULL);
157311042SErik.Nordmark@Sun.COM freemsg(mp);
157411042SErik.Nordmark@Sun.COM /* No error even for local senders - silent blackhole */
157511042SErik.Nordmark@Sun.COM return (0);
157611042SErik.Nordmark@Sun.COM }
157711042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutNoRoutes RTF_REJECT", mp, NULL);
157811042SErik.Nordmark@Sun.COM
157911042SErik.Nordmark@Sun.COM /*
158011042SErik.Nordmark@Sun.COM * We need an ill_t for the ip_recv_attr_t even though this packet
158111042SErik.Nordmark@Sun.COM * was never received and icmp_unreachable doesn't currently use
158211042SErik.Nordmark@Sun.COM * ira_ill.
158311042SErik.Nordmark@Sun.COM */
158411042SErik.Nordmark@Sun.COM ill = ill_lookup_on_name("lo0", B_FALSE,
158511042SErik.Nordmark@Sun.COM !(ixa->ixa_flags & IRAF_IS_IPV4), &dummy, ipst);
158611042SErik.Nordmark@Sun.COM if (ill == NULL) {
158711042SErik.Nordmark@Sun.COM freemsg(mp);
158811042SErik.Nordmark@Sun.COM return (EHOSTUNREACH);
158911042SErik.Nordmark@Sun.COM }
159011042SErik.Nordmark@Sun.COM
159111042SErik.Nordmark@Sun.COM bzero(&iras, sizeof (iras));
159211042SErik.Nordmark@Sun.COM /* Map ixa to ira including IPsec policies */
159311042SErik.Nordmark@Sun.COM ipsec_out_to_in(ixa, ill, &iras);
159411042SErik.Nordmark@Sun.COM
159511042SErik.Nordmark@Sun.COM if (ip_source_routed(ipha, ipst)) {
159611042SErik.Nordmark@Sun.COM icmp_unreachable(mp, ICMP_SOURCE_ROUTE_FAILED, &iras);
159711042SErik.Nordmark@Sun.COM } else {
159811042SErik.Nordmark@Sun.COM icmp_unreachable(mp, ICMP_HOST_UNREACHABLE, &iras);
159911042SErik.Nordmark@Sun.COM }
160011042SErik.Nordmark@Sun.COM /* We moved any IPsec refs from ixa to iras */
160111042SErik.Nordmark@Sun.COM ira_cleanup(&iras, B_FALSE);
160211042SErik.Nordmark@Sun.COM ill_refrele(ill);
160311042SErik.Nordmark@Sun.COM return (EHOSTUNREACH);
160411042SErik.Nordmark@Sun.COM }
160511042SErik.Nordmark@Sun.COM
160611042SErik.Nordmark@Sun.COM /*
160711042SErik.Nordmark@Sun.COM * Calculate a checksum ignoring any hardware capabilities
160811042SErik.Nordmark@Sun.COM *
160911042SErik.Nordmark@Sun.COM * Returns B_FALSE if the packet was too short for the checksum. Caller
161011042SErik.Nordmark@Sun.COM * should free and do stats.
161111042SErik.Nordmark@Sun.COM */
161211042SErik.Nordmark@Sun.COM static boolean_t
ip_output_sw_cksum_v4(mblk_t * mp,ipha_t * ipha,ip_xmit_attr_t * ixa)161311042SErik.Nordmark@Sun.COM ip_output_sw_cksum_v4(mblk_t *mp, ipha_t *ipha, ip_xmit_attr_t *ixa)
161411042SErik.Nordmark@Sun.COM {
161511042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ixa->ixa_ipst;
161611042SErik.Nordmark@Sun.COM uint_t pktlen = ixa->ixa_pktlen;
161711042SErik.Nordmark@Sun.COM uint16_t *cksump;
161811042SErik.Nordmark@Sun.COM uint32_t cksum;
161911042SErik.Nordmark@Sun.COM uint8_t protocol = ixa->ixa_protocol;
162011042SErik.Nordmark@Sun.COM uint16_t ip_hdr_length = ixa->ixa_ip_hdr_length;
162111042SErik.Nordmark@Sun.COM ipaddr_t dst = ipha->ipha_dst;
162211042SErik.Nordmark@Sun.COM ipaddr_t src = ipha->ipha_src;
162311042SErik.Nordmark@Sun.COM
162411042SErik.Nordmark@Sun.COM /* Just in case it contained garbage */
162511042SErik.Nordmark@Sun.COM DB_CKSUMFLAGS(mp) &= ~HCK_FLAGS;
162611042SErik.Nordmark@Sun.COM
162711042SErik.Nordmark@Sun.COM /*
162811042SErik.Nordmark@Sun.COM * Calculate ULP checksum
162911042SErik.Nordmark@Sun.COM */
163011042SErik.Nordmark@Sun.COM if (protocol == IPPROTO_TCP) {
163111042SErik.Nordmark@Sun.COM cksump = IPH_TCPH_CHECKSUMP(ipha, ip_hdr_length);
163211042SErik.Nordmark@Sun.COM cksum = IP_TCP_CSUM_COMP;
163311042SErik.Nordmark@Sun.COM } else if (protocol == IPPROTO_UDP) {
163411042SErik.Nordmark@Sun.COM cksump = IPH_UDPH_CHECKSUMP(ipha, ip_hdr_length);
163511042SErik.Nordmark@Sun.COM cksum = IP_UDP_CSUM_COMP;
163611042SErik.Nordmark@Sun.COM } else if (protocol == IPPROTO_SCTP) {
163711042SErik.Nordmark@Sun.COM sctp_hdr_t *sctph;
163811042SErik.Nordmark@Sun.COM
163911042SErik.Nordmark@Sun.COM ASSERT(MBLKL(mp) >= (ip_hdr_length + sizeof (*sctph)));
164011042SErik.Nordmark@Sun.COM sctph = (sctp_hdr_t *)(mp->b_rptr + ip_hdr_length);
164111042SErik.Nordmark@Sun.COM /*
164211042SErik.Nordmark@Sun.COM * Zero out the checksum field to ensure proper
164311042SErik.Nordmark@Sun.COM * checksum calculation.
164411042SErik.Nordmark@Sun.COM */
164511042SErik.Nordmark@Sun.COM sctph->sh_chksum = 0;
164611042SErik.Nordmark@Sun.COM #ifdef DEBUG
164711042SErik.Nordmark@Sun.COM if (!skip_sctp_cksum)
164811042SErik.Nordmark@Sun.COM #endif
164911042SErik.Nordmark@Sun.COM sctph->sh_chksum = sctp_cksum(mp, ip_hdr_length);
165011042SErik.Nordmark@Sun.COM goto ip_hdr_cksum;
165111042SErik.Nordmark@Sun.COM } else {
165211042SErik.Nordmark@Sun.COM goto ip_hdr_cksum;
165311042SErik.Nordmark@Sun.COM }
165411042SErik.Nordmark@Sun.COM
165511042SErik.Nordmark@Sun.COM /* ULP puts the checksum field is in the first mblk */
165611042SErik.Nordmark@Sun.COM ASSERT(((uchar_t *)cksump) + sizeof (uint16_t) <= mp->b_wptr);
165711042SErik.Nordmark@Sun.COM
165811042SErik.Nordmark@Sun.COM /*
165911042SErik.Nordmark@Sun.COM * We accumulate the pseudo header checksum in cksum.
166011042SErik.Nordmark@Sun.COM * This is pretty hairy code, so watch close. One
166111042SErik.Nordmark@Sun.COM * thing to keep in mind is that UDP and TCP have
166211042SErik.Nordmark@Sun.COM * stored their respective datagram lengths in their
166311042SErik.Nordmark@Sun.COM * checksum fields. This lines things up real nice.
166411042SErik.Nordmark@Sun.COM */
166511042SErik.Nordmark@Sun.COM cksum += (dst >> 16) + (dst & 0xFFFF) + (src >> 16) + (src & 0xFFFF);
166611042SErik.Nordmark@Sun.COM
166711042SErik.Nordmark@Sun.COM cksum = IP_CSUM(mp, ip_hdr_length, cksum);
166811042SErik.Nordmark@Sun.COM /*
166911042SErik.Nordmark@Sun.COM * For UDP/IPv4 a zero means that the packets wasn't checksummed.
167011042SErik.Nordmark@Sun.COM * Change to 0xffff
167111042SErik.Nordmark@Sun.COM */
167211042SErik.Nordmark@Sun.COM if (protocol == IPPROTO_UDP && cksum == 0)
167311042SErik.Nordmark@Sun.COM *cksump = ~cksum;
167411042SErik.Nordmark@Sun.COM else
167511042SErik.Nordmark@Sun.COM *cksump = cksum;
167611042SErik.Nordmark@Sun.COM
167711042SErik.Nordmark@Sun.COM IP_STAT(ipst, ip_out_sw_cksum);
167811042SErik.Nordmark@Sun.COM IP_STAT_UPDATE(ipst, ip_out_sw_cksum_bytes, pktlen);
167911042SErik.Nordmark@Sun.COM
168011042SErik.Nordmark@Sun.COM ip_hdr_cksum:
168111042SErik.Nordmark@Sun.COM /* Calculate IPv4 header checksum */
168211042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = 0;
168311042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = ip_csum_hdr(ipha);
168411042SErik.Nordmark@Sun.COM return (B_TRUE);
168511042SErik.Nordmark@Sun.COM }
168611042SErik.Nordmark@Sun.COM
168711042SErik.Nordmark@Sun.COM /*
168811042SErik.Nordmark@Sun.COM * Calculate the ULP checksum - try to use hardware.
168911042SErik.Nordmark@Sun.COM * In the case of MULTIRT, broadcast or multicast the
169011042SErik.Nordmark@Sun.COM * IXAF_NO_HW_CKSUM is set in which case we use software.
169111042SErik.Nordmark@Sun.COM *
169211042SErik.Nordmark@Sun.COM * If the hardware supports IP header checksum offload; then clear the
169311042SErik.Nordmark@Sun.COM * contents of IP header checksum field as expected by NIC.
169411042SErik.Nordmark@Sun.COM * Do this only if we offloaded either full or partial sum.
169511042SErik.Nordmark@Sun.COM *
169611042SErik.Nordmark@Sun.COM * Returns B_FALSE if the packet was too short for the checksum. Caller
169711042SErik.Nordmark@Sun.COM * should free and do stats.
169811042SErik.Nordmark@Sun.COM */
169911042SErik.Nordmark@Sun.COM static boolean_t
ip_output_cksum_v4(iaflags_t ixaflags,mblk_t * mp,ipha_t * ipha,ip_xmit_attr_t * ixa,ill_t * ill)170011042SErik.Nordmark@Sun.COM ip_output_cksum_v4(iaflags_t ixaflags, mblk_t *mp, ipha_t *ipha,
170111042SErik.Nordmark@Sun.COM ip_xmit_attr_t *ixa, ill_t *ill)
170211042SErik.Nordmark@Sun.COM {
170311042SErik.Nordmark@Sun.COM uint_t pktlen = ixa->ixa_pktlen;
170411042SErik.Nordmark@Sun.COM uint16_t *cksump;
170511042SErik.Nordmark@Sun.COM uint16_t hck_flags;
170611042SErik.Nordmark@Sun.COM uint32_t cksum;
170711042SErik.Nordmark@Sun.COM uint8_t protocol = ixa->ixa_protocol;
170811042SErik.Nordmark@Sun.COM uint16_t ip_hdr_length = ixa->ixa_ip_hdr_length;
170911042SErik.Nordmark@Sun.COM
171011042SErik.Nordmark@Sun.COM if ((ixaflags & IXAF_NO_HW_CKSUM) || !ILL_HCKSUM_CAPABLE(ill) ||
171111042SErik.Nordmark@Sun.COM !dohwcksum) {
171211042SErik.Nordmark@Sun.COM return (ip_output_sw_cksum_v4(mp, ipha, ixa));
171311042SErik.Nordmark@Sun.COM }
171411042SErik.Nordmark@Sun.COM
171511042SErik.Nordmark@Sun.COM /*
171611042SErik.Nordmark@Sun.COM * Calculate ULP checksum. Note that we don't use cksump and cksum
171711042SErik.Nordmark@Sun.COM * if the ill has FULL support.
171811042SErik.Nordmark@Sun.COM */
171911042SErik.Nordmark@Sun.COM if (protocol == IPPROTO_TCP) {
172011042SErik.Nordmark@Sun.COM cksump = IPH_TCPH_CHECKSUMP(ipha, ip_hdr_length);
172111042SErik.Nordmark@Sun.COM cksum = IP_TCP_CSUM_COMP; /* Pseudo-header cksum */
172211042SErik.Nordmark@Sun.COM } else if (protocol == IPPROTO_UDP) {
172311042SErik.Nordmark@Sun.COM cksump = IPH_UDPH_CHECKSUMP(ipha, ip_hdr_length);
172411042SErik.Nordmark@Sun.COM cksum = IP_UDP_CSUM_COMP; /* Pseudo-header cksum */
172511042SErik.Nordmark@Sun.COM } else if (protocol == IPPROTO_SCTP) {
172611042SErik.Nordmark@Sun.COM sctp_hdr_t *sctph;
172711042SErik.Nordmark@Sun.COM
172811042SErik.Nordmark@Sun.COM ASSERT(MBLKL(mp) >= (ip_hdr_length + sizeof (*sctph)));
172911042SErik.Nordmark@Sun.COM sctph = (sctp_hdr_t *)(mp->b_rptr + ip_hdr_length);
173011042SErik.Nordmark@Sun.COM /*
173111042SErik.Nordmark@Sun.COM * Zero out the checksum field to ensure proper
173211042SErik.Nordmark@Sun.COM * checksum calculation.
173311042SErik.Nordmark@Sun.COM */
173411042SErik.Nordmark@Sun.COM sctph->sh_chksum = 0;
173511042SErik.Nordmark@Sun.COM #ifdef DEBUG
173611042SErik.Nordmark@Sun.COM if (!skip_sctp_cksum)
173711042SErik.Nordmark@Sun.COM #endif
173811042SErik.Nordmark@Sun.COM sctph->sh_chksum = sctp_cksum(mp, ip_hdr_length);
173911042SErik.Nordmark@Sun.COM goto ip_hdr_cksum;
174011042SErik.Nordmark@Sun.COM } else {
174111042SErik.Nordmark@Sun.COM ip_hdr_cksum:
174211042SErik.Nordmark@Sun.COM /* Calculate IPv4 header checksum */
174311042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = 0;
174411042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = ip_csum_hdr(ipha);
174511042SErik.Nordmark@Sun.COM return (B_TRUE);
174611042SErik.Nordmark@Sun.COM }
174711042SErik.Nordmark@Sun.COM
174811042SErik.Nordmark@Sun.COM /* ULP puts the checksum field is in the first mblk */
174911042SErik.Nordmark@Sun.COM ASSERT(((uchar_t *)cksump) + sizeof (uint16_t) <= mp->b_wptr);
175011042SErik.Nordmark@Sun.COM
175111042SErik.Nordmark@Sun.COM /*
175211042SErik.Nordmark@Sun.COM * Underlying interface supports hardware checksum offload for
175311042SErik.Nordmark@Sun.COM * the payload; leave the payload checksum for the hardware to
175411042SErik.Nordmark@Sun.COM * calculate. N.B: We only need to set up checksum info on the
175511042SErik.Nordmark@Sun.COM * first mblk.
175611042SErik.Nordmark@Sun.COM */
175711042SErik.Nordmark@Sun.COM hck_flags = ill->ill_hcksum_capab->ill_hcksum_txflags;
175811042SErik.Nordmark@Sun.COM
175911042SErik.Nordmark@Sun.COM DB_CKSUMFLAGS(mp) &= ~HCK_FLAGS;
176011042SErik.Nordmark@Sun.COM if (hck_flags & HCKSUM_INET_FULL_V4) {
176111042SErik.Nordmark@Sun.COM /*
176211042SErik.Nordmark@Sun.COM * Hardware calculates pseudo-header, header and the
176311042SErik.Nordmark@Sun.COM * payload checksums, so clear the checksum field in
176411042SErik.Nordmark@Sun.COM * the protocol header.
176511042SErik.Nordmark@Sun.COM */
176611042SErik.Nordmark@Sun.COM *cksump = 0;
176711042SErik.Nordmark@Sun.COM DB_CKSUMFLAGS(mp) |= HCK_FULLCKSUM;
176811042SErik.Nordmark@Sun.COM
176911042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = 0;
177011042SErik.Nordmark@Sun.COM if (hck_flags & HCKSUM_IPHDRCKSUM) {
177111042SErik.Nordmark@Sun.COM DB_CKSUMFLAGS(mp) |= HCK_IPV4_HDRCKSUM;
177211042SErik.Nordmark@Sun.COM } else {
177311042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = ip_csum_hdr(ipha);
177411042SErik.Nordmark@Sun.COM }
177511042SErik.Nordmark@Sun.COM return (B_TRUE);
177611042SErik.Nordmark@Sun.COM }
177711042SErik.Nordmark@Sun.COM if ((hck_flags) & HCKSUM_INET_PARTIAL) {
177811042SErik.Nordmark@Sun.COM ipaddr_t dst = ipha->ipha_dst;
177911042SErik.Nordmark@Sun.COM ipaddr_t src = ipha->ipha_src;
178011042SErik.Nordmark@Sun.COM /*
178111042SErik.Nordmark@Sun.COM * Partial checksum offload has been enabled. Fill
178211042SErik.Nordmark@Sun.COM * the checksum field in the protocol header with the
178311042SErik.Nordmark@Sun.COM * pseudo-header checksum value.
178411042SErik.Nordmark@Sun.COM *
178511042SErik.Nordmark@Sun.COM * We accumulate the pseudo header checksum in cksum.
178611042SErik.Nordmark@Sun.COM * This is pretty hairy code, so watch close. One
178711042SErik.Nordmark@Sun.COM * thing to keep in mind is that UDP and TCP have
178811042SErik.Nordmark@Sun.COM * stored their respective datagram lengths in their
178911042SErik.Nordmark@Sun.COM * checksum fields. This lines things up real nice.
179011042SErik.Nordmark@Sun.COM */
179111042SErik.Nordmark@Sun.COM cksum += (dst >> 16) + (dst & 0xFFFF) +
179211042SErik.Nordmark@Sun.COM (src >> 16) + (src & 0xFFFF);
179311042SErik.Nordmark@Sun.COM cksum += *(cksump);
179411042SErik.Nordmark@Sun.COM cksum = (cksum & 0xFFFF) + (cksum >> 16);
179511042SErik.Nordmark@Sun.COM *(cksump) = (cksum & 0xFFFF) + (cksum >> 16);
179611042SErik.Nordmark@Sun.COM
179711042SErik.Nordmark@Sun.COM /*
179811042SErik.Nordmark@Sun.COM * Offsets are relative to beginning of IP header.
179911042SErik.Nordmark@Sun.COM */
180011042SErik.Nordmark@Sun.COM DB_CKSUMSTART(mp) = ip_hdr_length;
180111042SErik.Nordmark@Sun.COM DB_CKSUMSTUFF(mp) = (uint8_t *)cksump - (uint8_t *)ipha;
180211042SErik.Nordmark@Sun.COM DB_CKSUMEND(mp) = pktlen;
180311042SErik.Nordmark@Sun.COM DB_CKSUMFLAGS(mp) |= HCK_PARTIALCKSUM;
180411042SErik.Nordmark@Sun.COM
180511042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = 0;
180611042SErik.Nordmark@Sun.COM if (hck_flags & HCKSUM_IPHDRCKSUM) {
180711042SErik.Nordmark@Sun.COM DB_CKSUMFLAGS(mp) |= HCK_IPV4_HDRCKSUM;
180811042SErik.Nordmark@Sun.COM } else {
180911042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = ip_csum_hdr(ipha);
181011042SErik.Nordmark@Sun.COM }
181111042SErik.Nordmark@Sun.COM return (B_TRUE);
181211042SErik.Nordmark@Sun.COM }
181311042SErik.Nordmark@Sun.COM /* Hardware capabilities include neither full nor partial IPv4 */
181411042SErik.Nordmark@Sun.COM return (ip_output_sw_cksum_v4(mp, ipha, ixa));
181511042SErik.Nordmark@Sun.COM }
181611042SErik.Nordmark@Sun.COM
181711042SErik.Nordmark@Sun.COM /*
181811042SErik.Nordmark@Sun.COM * ire_sendfn for offlink and onlink destinations.
181911042SErik.Nordmark@Sun.COM * Also called from the multicast, broadcast, multirt send functions.
182011042SErik.Nordmark@Sun.COM *
182111042SErik.Nordmark@Sun.COM * Assumes that the caller has a hold on the ire.
182211042SErik.Nordmark@Sun.COM *
182311042SErik.Nordmark@Sun.COM * This function doesn't care if the IRE just became condemned since that
182411042SErik.Nordmark@Sun.COM * can happen at any time.
182511042SErik.Nordmark@Sun.COM */
182611042SErik.Nordmark@Sun.COM /* ARGSUSED */
182711042SErik.Nordmark@Sun.COM int
ire_send_wire_v4(ire_t * ire,mblk_t * mp,void * iph_arg,ip_xmit_attr_t * ixa,uint32_t * identp)182811042SErik.Nordmark@Sun.COM ire_send_wire_v4(ire_t *ire, mblk_t *mp, void *iph_arg,
182911042SErik.Nordmark@Sun.COM ip_xmit_attr_t *ixa, uint32_t *identp)
183011042SErik.Nordmark@Sun.COM {
183111042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ixa->ixa_ipst;
183211042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)iph_arg;
183311042SErik.Nordmark@Sun.COM iaflags_t ixaflags = ixa->ixa_flags;
183411042SErik.Nordmark@Sun.COM ill_t *ill;
183511042SErik.Nordmark@Sun.COM
183611042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_nce != NULL);
183711042SErik.Nordmark@Sun.COM ill = ixa->ixa_nce->nce_ill;
183811042SErik.Nordmark@Sun.COM
183911042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_DONTROUTE)
184011042SErik.Nordmark@Sun.COM ipha->ipha_ttl = 1;
184111042SErik.Nordmark@Sun.COM
184211042SErik.Nordmark@Sun.COM /*
184311042SErik.Nordmark@Sun.COM * Assign an ident value for this packet. There could be other
184411042SErik.Nordmark@Sun.COM * threads targeting the same destination, so we have to arrange
184511042SErik.Nordmark@Sun.COM * for a atomic increment. Note that we use a 32-bit atomic add
184611042SErik.Nordmark@Sun.COM * because it has better performance than its 16-bit sibling.
184711042SErik.Nordmark@Sun.COM *
184811042SErik.Nordmark@Sun.COM * Normally ixa_extra_ident is 0, but in the case of LSO it will
184911042SErik.Nordmark@Sun.COM * be the number of TCP segments that the driver/hardware will
185011042SErik.Nordmark@Sun.COM * extraly construct.
185111042SErik.Nordmark@Sun.COM *
185211042SErik.Nordmark@Sun.COM * If running in cluster mode and if the source address
185311042SErik.Nordmark@Sun.COM * belongs to a replicated service then vector through
185411042SErik.Nordmark@Sun.COM * cl_inet_ipident vector to allocate ip identifier
185511042SErik.Nordmark@Sun.COM * NOTE: This is a contract private interface with the
185611042SErik.Nordmark@Sun.COM * clustering group.
185711042SErik.Nordmark@Sun.COM */
185811042SErik.Nordmark@Sun.COM if (cl_inet_ipident != NULL) {
185911042SErik.Nordmark@Sun.COM ipaddr_t src = ipha->ipha_src;
186011042SErik.Nordmark@Sun.COM ipaddr_t dst = ipha->ipha_dst;
186111042SErik.Nordmark@Sun.COM netstackid_t stack_id = ipst->ips_netstack->netstack_stackid;
186211042SErik.Nordmark@Sun.COM
186311042SErik.Nordmark@Sun.COM ASSERT(cl_inet_isclusterwide != NULL);
186411042SErik.Nordmark@Sun.COM if ((*cl_inet_isclusterwide)(stack_id, IPPROTO_IP,
186511042SErik.Nordmark@Sun.COM AF_INET, (uint8_t *)(uintptr_t)src, NULL)) {
186611042SErik.Nordmark@Sun.COM /*
186711042SErik.Nordmark@Sun.COM * Note: not correct with LSO since we can't allocate
186811042SErik.Nordmark@Sun.COM * ixa_extra_ident+1 consecutive values.
186911042SErik.Nordmark@Sun.COM */
187011042SErik.Nordmark@Sun.COM ipha->ipha_ident = (*cl_inet_ipident)(stack_id,
187111042SErik.Nordmark@Sun.COM IPPROTO_IP, AF_INET, (uint8_t *)(uintptr_t)src,
187211042SErik.Nordmark@Sun.COM (uint8_t *)(uintptr_t)dst, NULL);
187311042SErik.Nordmark@Sun.COM } else {
187411042SErik.Nordmark@Sun.COM ipha->ipha_ident = atomic_add_32_nv(identp,
187511042SErik.Nordmark@Sun.COM ixa->ixa_extra_ident + 1);
187611042SErik.Nordmark@Sun.COM }
187711042SErik.Nordmark@Sun.COM } else {
187811042SErik.Nordmark@Sun.COM ipha->ipha_ident = atomic_add_32_nv(identp,
187911042SErik.Nordmark@Sun.COM ixa->ixa_extra_ident + 1);
188011042SErik.Nordmark@Sun.COM }
188111042SErik.Nordmark@Sun.COM #ifndef _BIG_ENDIAN
188211042SErik.Nordmark@Sun.COM ipha->ipha_ident = htons(ipha->ipha_ident);
188311042SErik.Nordmark@Sun.COM #endif
188411042SErik.Nordmark@Sun.COM
188511042SErik.Nordmark@Sun.COM /*
188611042SErik.Nordmark@Sun.COM * This might set b_band, thus the IPsec and fragmentation
188711042SErik.Nordmark@Sun.COM * code in IP ensures that b_band is updated in the first mblk.
188811042SErik.Nordmark@Sun.COM */
188911042SErik.Nordmark@Sun.COM if (IPP_ENABLED(IPP_LOCAL_OUT, ipst)) {
189011042SErik.Nordmark@Sun.COM /* ip_process translates an IS_UNDER_IPMP */
189111042SErik.Nordmark@Sun.COM mp = ip_process(IPP_LOCAL_OUT, mp, ill, ill);
189211042SErik.Nordmark@Sun.COM if (mp == NULL) {
189311042SErik.Nordmark@Sun.COM /* ip_drop_packet and MIB done */
189411042SErik.Nordmark@Sun.COM return (0); /* Might just be delayed */
189511042SErik.Nordmark@Sun.COM }
189611042SErik.Nordmark@Sun.COM }
189711042SErik.Nordmark@Sun.COM
189811042SErik.Nordmark@Sun.COM /*
189911042SErik.Nordmark@Sun.COM * Verify any IPv4 options.
190011042SErik.Nordmark@Sun.COM *
190111042SErik.Nordmark@Sun.COM * The presense of IP options also forces the network stack to
190211042SErik.Nordmark@Sun.COM * calculate the checksum in software. This is because:
190311042SErik.Nordmark@Sun.COM *
190411042SErik.Nordmark@Sun.COM * Wrap around: certain partial-checksum NICs (eri, ce) limit
190511042SErik.Nordmark@Sun.COM * the size of "start offset" width to 6-bit. This effectively
190611042SErik.Nordmark@Sun.COM * sets the largest value of the offset to 64-bytes, starting
190711042SErik.Nordmark@Sun.COM * from the MAC header. When the cumulative MAC and IP headers
190811042SErik.Nordmark@Sun.COM * exceed such limit, the offset will wrap around. This causes
190911042SErik.Nordmark@Sun.COM * the checksum to be calculated at the wrong place.
191011042SErik.Nordmark@Sun.COM *
191111042SErik.Nordmark@Sun.COM * IPv4 source routing: none of the full-checksum capable NICs
191211042SErik.Nordmark@Sun.COM * is capable of correctly handling the IPv4 source-routing
191311042SErik.Nordmark@Sun.COM * option for purposes of calculating the pseudo-header; the
191411042SErik.Nordmark@Sun.COM * actual destination is different from the destination in the
191511042SErik.Nordmark@Sun.COM * header which is that of the next-hop. (This case may not be
191611042SErik.Nordmark@Sun.COM * true for NICs which can parse IPv6 extension headers, but
191711042SErik.Nordmark@Sun.COM * we choose to simplify the implementation by not offloading
191811042SErik.Nordmark@Sun.COM * checksum when they are present.)
191911042SErik.Nordmark@Sun.COM */
192011042SErik.Nordmark@Sun.COM if (!IS_SIMPLE_IPH(ipha)) {
192111042SErik.Nordmark@Sun.COM ixaflags = ixa->ixa_flags |= IXAF_NO_HW_CKSUM;
192211042SErik.Nordmark@Sun.COM /* An IS_UNDER_IPMP ill is ok here */
192311042SErik.Nordmark@Sun.COM if (ip_output_options(mp, ipha, ixa, ill)) {
192411042SErik.Nordmark@Sun.COM /* Packet has been consumed and ICMP error sent */
192511042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsOutDiscards);
192611042SErik.Nordmark@Sun.COM return (EINVAL);
192711042SErik.Nordmark@Sun.COM }
192811042SErik.Nordmark@Sun.COM }
192911042SErik.Nordmark@Sun.COM
193011042SErik.Nordmark@Sun.COM /*
193111042SErik.Nordmark@Sun.COM * To handle IPsec/iptun's labeling needs we need to tag packets
193211042SErik.Nordmark@Sun.COM * while we still have ixa_tsl
193311042SErik.Nordmark@Sun.COM */
193411042SErik.Nordmark@Sun.COM if (is_system_labeled() && ixa->ixa_tsl != NULL &&
193511042SErik.Nordmark@Sun.COM (ill->ill_mactype == DL_6TO4 || ill->ill_mactype == DL_IPV4 ||
193611042SErik.Nordmark@Sun.COM ill->ill_mactype == DL_IPV6)) {
193711042SErik.Nordmark@Sun.COM cred_t *newcr;
193811042SErik.Nordmark@Sun.COM
193911042SErik.Nordmark@Sun.COM newcr = copycred_from_tslabel(ixa->ixa_cred, ixa->ixa_tsl,
194011042SErik.Nordmark@Sun.COM KM_NOSLEEP);
194111042SErik.Nordmark@Sun.COM if (newcr == NULL) {
194211042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsOutDiscards);
194311042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards - newcr",
194411042SErik.Nordmark@Sun.COM mp, ill);
194511042SErik.Nordmark@Sun.COM freemsg(mp);
194611042SErik.Nordmark@Sun.COM return (ENOBUFS);
194711042SErik.Nordmark@Sun.COM }
194811042SErik.Nordmark@Sun.COM mblk_setcred(mp, newcr, NOPID);
194911042SErik.Nordmark@Sun.COM crfree(newcr); /* mblk_setcred did its own crhold */
195011042SErik.Nordmark@Sun.COM }
195111042SErik.Nordmark@Sun.COM
195211042SErik.Nordmark@Sun.COM if (ixa->ixa_pktlen > ixa->ixa_fragsize ||
195311042SErik.Nordmark@Sun.COM (ixaflags & IXAF_IPSEC_SECURE)) {
195411042SErik.Nordmark@Sun.COM uint32_t pktlen;
195511042SErik.Nordmark@Sun.COM
195611042SErik.Nordmark@Sun.COM pktlen = ixa->ixa_pktlen;
195711042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_IPSEC_SECURE)
195811042SErik.Nordmark@Sun.COM pktlen += ipsec_out_extra_length(ixa);
195911042SErik.Nordmark@Sun.COM
196011042SErik.Nordmark@Sun.COM if (pktlen > IP_MAXPACKET)
196111042SErik.Nordmark@Sun.COM return (EMSGSIZE);
196211042SErik.Nordmark@Sun.COM
196311042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_SET_ULP_CKSUM) {
196411042SErik.Nordmark@Sun.COM /*
196511042SErik.Nordmark@Sun.COM * Compute ULP checksum and IP header checksum
196611042SErik.Nordmark@Sun.COM * using software
196711042SErik.Nordmark@Sun.COM */
196811042SErik.Nordmark@Sun.COM if (!ip_output_sw_cksum_v4(mp, ipha, ixa)) {
196911042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsOutDiscards);
197011042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards", mp, ill);
197111042SErik.Nordmark@Sun.COM freemsg(mp);
197211042SErik.Nordmark@Sun.COM return (EINVAL);
197311042SErik.Nordmark@Sun.COM }
197411042SErik.Nordmark@Sun.COM } else {
197511042SErik.Nordmark@Sun.COM /* Calculate IPv4 header checksum */
197611042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = 0;
197711042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = ip_csum_hdr(ipha);
197811042SErik.Nordmark@Sun.COM }
197911042SErik.Nordmark@Sun.COM
198011042SErik.Nordmark@Sun.COM /*
198111042SErik.Nordmark@Sun.COM * If this packet would generate a icmp_frag_needed
198211042SErik.Nordmark@Sun.COM * message, we need to handle it before we do the IPsec
198311042SErik.Nordmark@Sun.COM * processing. Otherwise, we need to strip the IPsec
198411042SErik.Nordmark@Sun.COM * headers before we send up the message to the ULPs
198511042SErik.Nordmark@Sun.COM * which becomes messy and difficult.
198611042SErik.Nordmark@Sun.COM *
198711042SErik.Nordmark@Sun.COM * We check using IXAF_DONTFRAG. The DF bit in the header
198811042SErik.Nordmark@Sun.COM * is not inspected - it will be copied to any generated
198911042SErik.Nordmark@Sun.COM * fragments.
199011042SErik.Nordmark@Sun.COM */
199111042SErik.Nordmark@Sun.COM if ((pktlen > ixa->ixa_fragsize) &&
199211042SErik.Nordmark@Sun.COM (ixaflags & IXAF_DONTFRAG)) {
199311042SErik.Nordmark@Sun.COM /* Generate ICMP and return error */
199411042SErik.Nordmark@Sun.COM ip_recv_attr_t iras;
199511042SErik.Nordmark@Sun.COM
199611042SErik.Nordmark@Sun.COM DTRACE_PROBE4(ip4__fragsize__fail, uint_t, pktlen,
199711042SErik.Nordmark@Sun.COM uint_t, ixa->ixa_fragsize, uint_t, ixa->ixa_pktlen,
199811042SErik.Nordmark@Sun.COM uint_t, ixa->ixa_pmtu);
199911042SErik.Nordmark@Sun.COM
200011042SErik.Nordmark@Sun.COM bzero(&iras, sizeof (iras));
200111042SErik.Nordmark@Sun.COM /* Map ixa to ira including IPsec policies */
200211042SErik.Nordmark@Sun.COM ipsec_out_to_in(ixa, ill, &iras);
200311042SErik.Nordmark@Sun.COM
200411042SErik.Nordmark@Sun.COM ip_drop_output("ICMP_FRAG_NEEDED", mp, ill);
200511042SErik.Nordmark@Sun.COM icmp_frag_needed(mp, ixa->ixa_fragsize, &iras);
200611042SErik.Nordmark@Sun.COM /* We moved any IPsec refs from ixa to iras */
200711042SErik.Nordmark@Sun.COM ira_cleanup(&iras, B_FALSE);
200811042SErik.Nordmark@Sun.COM return (EMSGSIZE);
200911042SErik.Nordmark@Sun.COM }
201011042SErik.Nordmark@Sun.COM DTRACE_PROBE4(ip4__fragsize__ok, uint_t, pktlen,
201111042SErik.Nordmark@Sun.COM uint_t, ixa->ixa_fragsize, uint_t, ixa->ixa_pktlen,
201211042SErik.Nordmark@Sun.COM uint_t, ixa->ixa_pmtu);
201311042SErik.Nordmark@Sun.COM
201411042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_IPSEC_SECURE) {
201511042SErik.Nordmark@Sun.COM /*
201611042SErik.Nordmark@Sun.COM * Pass in sufficient information so that
201711042SErik.Nordmark@Sun.COM * IPsec can determine whether to fragment, and
201811042SErik.Nordmark@Sun.COM * which function to call after fragmentation.
201911042SErik.Nordmark@Sun.COM */
202011042SErik.Nordmark@Sun.COM return (ipsec_out_process(mp, ixa));
202111042SErik.Nordmark@Sun.COM }
202211042SErik.Nordmark@Sun.COM return (ip_fragment_v4(mp, ixa->ixa_nce, ixaflags,
202311042SErik.Nordmark@Sun.COM ixa->ixa_pktlen, ixa->ixa_fragsize, ixa->ixa_xmit_hint,
202411042SErik.Nordmark@Sun.COM ixa->ixa_zoneid, ixa->ixa_no_loop_zoneid,
202511042SErik.Nordmark@Sun.COM ixa->ixa_postfragfn, &ixa->ixa_cookie));
202611042SErik.Nordmark@Sun.COM }
202711042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_SET_ULP_CKSUM) {
202811042SErik.Nordmark@Sun.COM /* Compute ULP checksum and IP header checksum */
202911042SErik.Nordmark@Sun.COM /* An IS_UNDER_IPMP ill is ok here */
203011042SErik.Nordmark@Sun.COM if (!ip_output_cksum_v4(ixaflags, mp, ipha, ixa, ill)) {
203111042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsOutDiscards);
203211042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards", mp, ill);
203311042SErik.Nordmark@Sun.COM freemsg(mp);
203411042SErik.Nordmark@Sun.COM return (EINVAL);
203511042SErik.Nordmark@Sun.COM }
203611042SErik.Nordmark@Sun.COM } else {
203711042SErik.Nordmark@Sun.COM /* Calculate IPv4 header checksum */
203811042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = 0;
203911042SErik.Nordmark@Sun.COM ipha->ipha_hdr_checksum = ip_csum_hdr(ipha);
204011042SErik.Nordmark@Sun.COM }
204111042SErik.Nordmark@Sun.COM return ((ixa->ixa_postfragfn)(mp, ixa->ixa_nce, ixaflags,
204211042SErik.Nordmark@Sun.COM ixa->ixa_pktlen, ixa->ixa_xmit_hint, ixa->ixa_zoneid,
204311042SErik.Nordmark@Sun.COM ixa->ixa_no_loop_zoneid, &ixa->ixa_cookie));
204411042SErik.Nordmark@Sun.COM }
204511042SErik.Nordmark@Sun.COM
204611042SErik.Nordmark@Sun.COM /*
204711042SErik.Nordmark@Sun.COM * Send mp into ip_input
204811042SErik.Nordmark@Sun.COM * Common for IPv4 and IPv6
204911042SErik.Nordmark@Sun.COM */
205011042SErik.Nordmark@Sun.COM void
ip_postfrag_loopback(mblk_t * mp,nce_t * nce,iaflags_t ixaflags,uint_t pkt_len,zoneid_t nolzid)205111042SErik.Nordmark@Sun.COM ip_postfrag_loopback(mblk_t *mp, nce_t *nce, iaflags_t ixaflags,
205211042SErik.Nordmark@Sun.COM uint_t pkt_len, zoneid_t nolzid)
205311042SErik.Nordmark@Sun.COM {
205411042SErik.Nordmark@Sun.COM rtc_t rtc;
205511042SErik.Nordmark@Sun.COM ill_t *ill = nce->nce_ill;
205611042SErik.Nordmark@Sun.COM ip_recv_attr_t iras; /* NOTE: No bzero for performance */
205711042SErik.Nordmark@Sun.COM ncec_t *ncec;
205811042SErik.Nordmark@Sun.COM
205911042SErik.Nordmark@Sun.COM ncec = nce->nce_common;
206011042SErik.Nordmark@Sun.COM iras.ira_flags = IRAF_VERIFY_IP_CKSUM | IRAF_VERIFY_ULP_CKSUM |
206111042SErik.Nordmark@Sun.COM IRAF_LOOPBACK | IRAF_L2SRC_LOOPBACK;
206211042SErik.Nordmark@Sun.COM if (ncec->ncec_flags & NCE_F_BCAST)
206311042SErik.Nordmark@Sun.COM iras.ira_flags |= IRAF_L2DST_BROADCAST;
206411042SErik.Nordmark@Sun.COM else if (ncec->ncec_flags & NCE_F_MCAST)
206511042SErik.Nordmark@Sun.COM iras.ira_flags |= IRAF_L2DST_MULTICAST;
206611042SErik.Nordmark@Sun.COM
206711042SErik.Nordmark@Sun.COM iras.ira_free_flags = 0;
206811042SErik.Nordmark@Sun.COM iras.ira_cred = NULL;
206911042SErik.Nordmark@Sun.COM iras.ira_cpid = NOPID;
207011042SErik.Nordmark@Sun.COM iras.ira_tsl = NULL;
207111042SErik.Nordmark@Sun.COM iras.ira_zoneid = ALL_ZONES;
207211042SErik.Nordmark@Sun.COM iras.ira_pktlen = pkt_len;
207311042SErik.Nordmark@Sun.COM UPDATE_MIB(ill->ill_ip_mib, ipIfStatsHCInOctets, iras.ira_pktlen);
207411042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsHCInReceives);
207511042SErik.Nordmark@Sun.COM
207611042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_IS_IPV4)
207711042SErik.Nordmark@Sun.COM iras.ira_flags |= IRAF_IS_IPV4;
207811042SErik.Nordmark@Sun.COM
207911042SErik.Nordmark@Sun.COM iras.ira_ill = iras.ira_rill = ill;
208011042SErik.Nordmark@Sun.COM iras.ira_ruifindex = ill->ill_phyint->phyint_ifindex;
208111042SErik.Nordmark@Sun.COM iras.ira_rifindex = iras.ira_ruifindex;
208211042SErik.Nordmark@Sun.COM iras.ira_mhip = NULL;
208311042SErik.Nordmark@Sun.COM
208411042SErik.Nordmark@Sun.COM iras.ira_flags |= ixaflags & IAF_MASK;
208511042SErik.Nordmark@Sun.COM iras.ira_no_loop_zoneid = nolzid;
208611042SErik.Nordmark@Sun.COM
208711042SErik.Nordmark@Sun.COM /* Broadcast and multicast doesn't care about the squeue */
208811042SErik.Nordmark@Sun.COM iras.ira_sqp = NULL;
208911042SErik.Nordmark@Sun.COM
209011042SErik.Nordmark@Sun.COM rtc.rtc_ire = NULL;
209111042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_IS_IPV4) {
209211042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)mp->b_rptr;
209311042SErik.Nordmark@Sun.COM
209411042SErik.Nordmark@Sun.COM rtc.rtc_ipaddr = INADDR_ANY;
209511042SErik.Nordmark@Sun.COM
209611042SErik.Nordmark@Sun.COM (*ill->ill_inputfn)(mp, ipha, &ipha->ipha_dst, &iras, &rtc);
209711042SErik.Nordmark@Sun.COM if (rtc.rtc_ire != NULL) {
209811042SErik.Nordmark@Sun.COM ASSERT(rtc.rtc_ipaddr != INADDR_ANY);
209911042SErik.Nordmark@Sun.COM ire_refrele(rtc.rtc_ire);
210011042SErik.Nordmark@Sun.COM }
210111042SErik.Nordmark@Sun.COM } else {
210211042SErik.Nordmark@Sun.COM ip6_t *ip6h = (ip6_t *)mp->b_rptr;
210311042SErik.Nordmark@Sun.COM
210411042SErik.Nordmark@Sun.COM rtc.rtc_ip6addr = ipv6_all_zeros;
210511042SErik.Nordmark@Sun.COM
210611042SErik.Nordmark@Sun.COM (*ill->ill_inputfn)(mp, ip6h, &ip6h->ip6_dst, &iras, &rtc);
210711042SErik.Nordmark@Sun.COM if (rtc.rtc_ire != NULL) {
210811042SErik.Nordmark@Sun.COM ASSERT(!IN6_IS_ADDR_UNSPECIFIED(&rtc.rtc_ip6addr));
210911042SErik.Nordmark@Sun.COM ire_refrele(rtc.rtc_ire);
211011042SErik.Nordmark@Sun.COM }
211111042SErik.Nordmark@Sun.COM }
211211042SErik.Nordmark@Sun.COM /* Any references to clean up? No hold on ira */
211311042SErik.Nordmark@Sun.COM if (iras.ira_flags & (IRAF_IPSEC_SECURE|IRAF_SYSTEM_LABELED))
211411042SErik.Nordmark@Sun.COM ira_cleanup(&iras, B_FALSE);
211511042SErik.Nordmark@Sun.COM }
211611042SErik.Nordmark@Sun.COM
211711042SErik.Nordmark@Sun.COM /*
211811042SErik.Nordmark@Sun.COM * Post fragmentation function for IRE_MULTICAST and IRE_BROADCAST which
211911042SErik.Nordmark@Sun.COM * looks at the IXAF_LOOPBACK_COPY flag.
212011042SErik.Nordmark@Sun.COM * Common for IPv4 and IPv6.
212111042SErik.Nordmark@Sun.COM *
212211042SErik.Nordmark@Sun.COM * If the loopback copy fails (due to no memory) but we send the packet out
212311042SErik.Nordmark@Sun.COM * on the wire we return no failure. Only in the case we supress the wire
212411042SErik.Nordmark@Sun.COM * sending do we take the loopback failure into account.
212511042SErik.Nordmark@Sun.COM *
212611042SErik.Nordmark@Sun.COM * Note that we do not perform DTRACE_IP7 and FW_HOOKS for the looped back copy.
212711042SErik.Nordmark@Sun.COM * Those operations are performed on this packet in ip_xmit() and it would
212811042SErik.Nordmark@Sun.COM * be odd to do it twice for the same packet.
212911042SErik.Nordmark@Sun.COM */
213011042SErik.Nordmark@Sun.COM int
ip_postfrag_loopcheck(mblk_t * mp,nce_t * nce,iaflags_t ixaflags,uint_t pkt_len,uint32_t xmit_hint,zoneid_t szone,zoneid_t nolzid,uintptr_t * ixacookie)213111042SErik.Nordmark@Sun.COM ip_postfrag_loopcheck(mblk_t *mp, nce_t *nce, iaflags_t ixaflags,
213211042SErik.Nordmark@Sun.COM uint_t pkt_len, uint32_t xmit_hint, zoneid_t szone, zoneid_t nolzid,
213311042SErik.Nordmark@Sun.COM uintptr_t *ixacookie)
213411042SErik.Nordmark@Sun.COM {
213511042SErik.Nordmark@Sun.COM ill_t *ill = nce->nce_ill;
213611042SErik.Nordmark@Sun.COM int error = 0;
213711042SErik.Nordmark@Sun.COM
213811042SErik.Nordmark@Sun.COM /*
213911042SErik.Nordmark@Sun.COM * Check for IXAF_LOOPBACK_COPY - send a copy to ip as if the driver
214011042SErik.Nordmark@Sun.COM * had looped it back
214111042SErik.Nordmark@Sun.COM */
214211042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_LOOPBACK_COPY) {
214311042SErik.Nordmark@Sun.COM mblk_t *mp1;
214411042SErik.Nordmark@Sun.COM
214511042SErik.Nordmark@Sun.COM mp1 = copymsg(mp);
214611042SErik.Nordmark@Sun.COM if (mp1 == NULL) {
214711042SErik.Nordmark@Sun.COM /* Failed to deliver the loopback copy. */
214811042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsOutDiscards);
214911042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards", mp, ill);
215011042SErik.Nordmark@Sun.COM error = ENOBUFS;
215111042SErik.Nordmark@Sun.COM } else {
215211042SErik.Nordmark@Sun.COM ip_postfrag_loopback(mp1, nce, ixaflags, pkt_len,
215311042SErik.Nordmark@Sun.COM nolzid);
215411042SErik.Nordmark@Sun.COM }
215511042SErik.Nordmark@Sun.COM }
215611042SErik.Nordmark@Sun.COM
215711042SErik.Nordmark@Sun.COM /*
215811042SErik.Nordmark@Sun.COM * If TTL = 0 then only do the loopback to this host i.e. we are
215911042SErik.Nordmark@Sun.COM * done. We are also done if this was the
216011042SErik.Nordmark@Sun.COM * loopback interface since it is sufficient
216111042SErik.Nordmark@Sun.COM * to loopback one copy of a multicast packet.
216211042SErik.Nordmark@Sun.COM */
216311042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_IS_IPV4) {
216411042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)mp->b_rptr;
216511042SErik.Nordmark@Sun.COM
216611042SErik.Nordmark@Sun.COM if (ipha->ipha_ttl == 0) {
216711042SErik.Nordmark@Sun.COM ip_drop_output("multicast ipha_ttl not sent to wire",
216811042SErik.Nordmark@Sun.COM mp, ill);
216911042SErik.Nordmark@Sun.COM freemsg(mp);
217011042SErik.Nordmark@Sun.COM return (error);
217111042SErik.Nordmark@Sun.COM }
217211042SErik.Nordmark@Sun.COM } else {
217311042SErik.Nordmark@Sun.COM ip6_t *ip6h = (ip6_t *)mp->b_rptr;
217411042SErik.Nordmark@Sun.COM
217511042SErik.Nordmark@Sun.COM if (ip6h->ip6_hops == 0) {
217611042SErik.Nordmark@Sun.COM ip_drop_output("multicast ipha_ttl not sent to wire",
217711042SErik.Nordmark@Sun.COM mp, ill);
217811042SErik.Nordmark@Sun.COM freemsg(mp);
217911042SErik.Nordmark@Sun.COM return (error);
218011042SErik.Nordmark@Sun.COM }
218111042SErik.Nordmark@Sun.COM }
218211042SErik.Nordmark@Sun.COM if (nce->nce_ill->ill_wq == NULL) {
218311042SErik.Nordmark@Sun.COM /* Loopback interface */
218411042SErik.Nordmark@Sun.COM ip_drop_output("multicast on lo0 not sent to wire", mp, ill);
218511042SErik.Nordmark@Sun.COM freemsg(mp);
218611042SErik.Nordmark@Sun.COM return (error);
218711042SErik.Nordmark@Sun.COM }
218811042SErik.Nordmark@Sun.COM
218911042SErik.Nordmark@Sun.COM return (ip_xmit(mp, nce, ixaflags, pkt_len, xmit_hint, szone, 0,
219011042SErik.Nordmark@Sun.COM ixacookie));
219111042SErik.Nordmark@Sun.COM }
219211042SErik.Nordmark@Sun.COM
219311042SErik.Nordmark@Sun.COM /*
219411042SErik.Nordmark@Sun.COM * Post fragmentation function for RTF_MULTIRT routes.
219511042SErik.Nordmark@Sun.COM * Since IRE_BROADCASTs can have RTF_MULTIRT, this function
219611042SErik.Nordmark@Sun.COM * checks IXAF_LOOPBACK_COPY.
219711042SErik.Nordmark@Sun.COM *
219811042SErik.Nordmark@Sun.COM * If no packet is sent due to failures then we return an errno, but if at
219911042SErik.Nordmark@Sun.COM * least one succeeded we return zero.
220011042SErik.Nordmark@Sun.COM */
220111042SErik.Nordmark@Sun.COM int
ip_postfrag_multirt_v4(mblk_t * mp,nce_t * nce,iaflags_t ixaflags,uint_t pkt_len,uint32_t xmit_hint,zoneid_t szone,zoneid_t nolzid,uintptr_t * ixacookie)220211042SErik.Nordmark@Sun.COM ip_postfrag_multirt_v4(mblk_t *mp, nce_t *nce, iaflags_t ixaflags,
220311042SErik.Nordmark@Sun.COM uint_t pkt_len, uint32_t xmit_hint, zoneid_t szone, zoneid_t nolzid,
220411042SErik.Nordmark@Sun.COM uintptr_t *ixacookie)
220511042SErik.Nordmark@Sun.COM {
220611042SErik.Nordmark@Sun.COM irb_t *irb;
220711042SErik.Nordmark@Sun.COM ipha_t *ipha = (ipha_t *)mp->b_rptr;
220811042SErik.Nordmark@Sun.COM ire_t *ire;
220911042SErik.Nordmark@Sun.COM ire_t *ire1;
221011042SErik.Nordmark@Sun.COM mblk_t *mp1;
221111042SErik.Nordmark@Sun.COM nce_t *nce1;
221211042SErik.Nordmark@Sun.COM ill_t *ill = nce->nce_ill;
221311042SErik.Nordmark@Sun.COM ill_t *ill1;
221411042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ill->ill_ipst;
221511042SErik.Nordmark@Sun.COM int error = 0;
221611042SErik.Nordmark@Sun.COM int num_sent = 0;
221711042SErik.Nordmark@Sun.COM int err;
221811042SErik.Nordmark@Sun.COM uint_t ire_type;
221911042SErik.Nordmark@Sun.COM ipaddr_t nexthop;
222011042SErik.Nordmark@Sun.COM
222111042SErik.Nordmark@Sun.COM ASSERT(ixaflags & IXAF_IS_IPV4);
222211042SErik.Nordmark@Sun.COM
222311042SErik.Nordmark@Sun.COM /* Check for IXAF_LOOPBACK_COPY */
222411042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_LOOPBACK_COPY) {
222511042SErik.Nordmark@Sun.COM mblk_t *mp1;
222611042SErik.Nordmark@Sun.COM
222711042SErik.Nordmark@Sun.COM mp1 = copymsg(mp);
222811042SErik.Nordmark@Sun.COM if (mp1 == NULL) {
222911042SErik.Nordmark@Sun.COM /* Failed to deliver the loopback copy. */
223011042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsOutDiscards);
223111042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards", mp, ill);
223211042SErik.Nordmark@Sun.COM error = ENOBUFS;
223311042SErik.Nordmark@Sun.COM } else {
223411042SErik.Nordmark@Sun.COM ip_postfrag_loopback(mp1, nce, ixaflags, pkt_len,
223511042SErik.Nordmark@Sun.COM nolzid);
223611042SErik.Nordmark@Sun.COM }
223711042SErik.Nordmark@Sun.COM }
223811042SErik.Nordmark@Sun.COM
223911042SErik.Nordmark@Sun.COM /*
224011042SErik.Nordmark@Sun.COM * Loop over RTF_MULTIRT for ipha_dst in the same bucket. Send
224111042SErik.Nordmark@Sun.COM * a copy to each one.
224211042SErik.Nordmark@Sun.COM * Use the nce (nexthop) and ipha_dst to find the ire.
224311042SErik.Nordmark@Sun.COM *
224411042SErik.Nordmark@Sun.COM * MULTIRT is not designed to work with shared-IP zones thus we don't
224511042SErik.Nordmark@Sun.COM * need to pass a zoneid or a label to the IRE lookup.
224611042SErik.Nordmark@Sun.COM */
224711042SErik.Nordmark@Sun.COM if (V4_PART_OF_V6(nce->nce_addr) == ipha->ipha_dst) {
224811042SErik.Nordmark@Sun.COM /* Broadcast and multicast case */
224911042SErik.Nordmark@Sun.COM ire = ire_ftable_lookup_v4(ipha->ipha_dst, 0, 0, 0,
225011042SErik.Nordmark@Sun.COM NULL, ALL_ZONES, NULL, MATCH_IRE_DSTONLY, 0, ipst, NULL);
225111042SErik.Nordmark@Sun.COM } else {
225211042SErik.Nordmark@Sun.COM ipaddr_t v4addr = V4_PART_OF_V6(nce->nce_addr);
225311042SErik.Nordmark@Sun.COM
225411042SErik.Nordmark@Sun.COM /* Unicast case */
225511042SErik.Nordmark@Sun.COM ire = ire_ftable_lookup_v4(ipha->ipha_dst, 0, v4addr, 0,
225611042SErik.Nordmark@Sun.COM NULL, ALL_ZONES, NULL, MATCH_IRE_GW, 0, ipst, NULL);
225711042SErik.Nordmark@Sun.COM }
225811042SErik.Nordmark@Sun.COM
225911042SErik.Nordmark@Sun.COM if (ire == NULL ||
226011042SErik.Nordmark@Sun.COM (ire->ire_flags & (RTF_REJECT|RTF_BLACKHOLE)) ||
226111042SErik.Nordmark@Sun.COM !(ire->ire_flags & RTF_MULTIRT)) {
226211042SErik.Nordmark@Sun.COM /* Drop */
226311042SErik.Nordmark@Sun.COM ip_drop_output("ip_postfrag_multirt didn't find route",
226411042SErik.Nordmark@Sun.COM mp, nce->nce_ill);
226511042SErik.Nordmark@Sun.COM if (ire != NULL)
226611042SErik.Nordmark@Sun.COM ire_refrele(ire);
226711042SErik.Nordmark@Sun.COM return (ENETUNREACH);
226811042SErik.Nordmark@Sun.COM }
226911042SErik.Nordmark@Sun.COM
227011042SErik.Nordmark@Sun.COM irb = ire->ire_bucket;
227111042SErik.Nordmark@Sun.COM irb_refhold(irb);
227211042SErik.Nordmark@Sun.COM for (ire1 = irb->irb_ire; ire1 != NULL; ire1 = ire1->ire_next) {
227311042SErik.Nordmark@Sun.COM /*
227411042SErik.Nordmark@Sun.COM * For broadcast we can have a mixture of IRE_BROADCAST and
227511042SErik.Nordmark@Sun.COM * IRE_HOST due to the manually added IRE_HOSTs that are used
227611042SErik.Nordmark@Sun.COM * to trigger the creation of the special CGTP broadcast routes.
227711042SErik.Nordmark@Sun.COM * Thus we have to skip if ire_type doesn't match the original.
227811042SErik.Nordmark@Sun.COM */
227911042SErik.Nordmark@Sun.COM if (IRE_IS_CONDEMNED(ire1) ||
228011042SErik.Nordmark@Sun.COM !(ire1->ire_flags & RTF_MULTIRT) ||
228111042SErik.Nordmark@Sun.COM ire1->ire_type != ire->ire_type)
228211042SErik.Nordmark@Sun.COM continue;
228311042SErik.Nordmark@Sun.COM
228411042SErik.Nordmark@Sun.COM /* Do the ire argument one after the loop */
228511042SErik.Nordmark@Sun.COM if (ire1 == ire)
228611042SErik.Nordmark@Sun.COM continue;
228711042SErik.Nordmark@Sun.COM
228811042SErik.Nordmark@Sun.COM ill1 = ire_nexthop_ill(ire1);
228911042SErik.Nordmark@Sun.COM if (ill1 == NULL) {
229011042SErik.Nordmark@Sun.COM /*
229111042SErik.Nordmark@Sun.COM * This ire might not have been picked by
229211042SErik.Nordmark@Sun.COM * ire_route_recursive, in which case ire_dep might
229311042SErik.Nordmark@Sun.COM * not have been setup yet.
229411042SErik.Nordmark@Sun.COM * We kick ire_route_recursive to try to resolve
229511042SErik.Nordmark@Sun.COM * starting at ire1.
229611042SErik.Nordmark@Sun.COM */
229711042SErik.Nordmark@Sun.COM ire_t *ire2;
229811681SSowmini.Varadhan@Sun.COM uint_t match_flags = MATCH_IRE_DSTONLY;
229911042SErik.Nordmark@Sun.COM
230011681SSowmini.Varadhan@Sun.COM if (ire1->ire_ill != NULL)
230111681SSowmini.Varadhan@Sun.COM match_flags |= MATCH_IRE_ILL;
230211042SErik.Nordmark@Sun.COM ire2 = ire_route_recursive_impl_v4(ire1,
230311042SErik.Nordmark@Sun.COM ire1->ire_addr, ire1->ire_type, ire1->ire_ill,
230411681SSowmini.Varadhan@Sun.COM ire1->ire_zoneid, NULL, match_flags,
230511457SErik.Nordmark@Sun.COM IRR_ALLOCATE, 0, ipst, NULL, NULL, NULL);
230611042SErik.Nordmark@Sun.COM if (ire2 != NULL)
230711042SErik.Nordmark@Sun.COM ire_refrele(ire2);
230811042SErik.Nordmark@Sun.COM ill1 = ire_nexthop_ill(ire1);
230911042SErik.Nordmark@Sun.COM }
231011042SErik.Nordmark@Sun.COM
231111042SErik.Nordmark@Sun.COM if (ill1 == NULL) {
231211042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsOutDiscards);
231311042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards - no ill",
231411042SErik.Nordmark@Sun.COM mp, ill);
231511042SErik.Nordmark@Sun.COM error = ENETUNREACH;
231611042SErik.Nordmark@Sun.COM continue;
231711042SErik.Nordmark@Sun.COM }
231811042SErik.Nordmark@Sun.COM
231911042SErik.Nordmark@Sun.COM /* Pick the addr and type to use for arp_nce_init */
232011042SErik.Nordmark@Sun.COM if (nce->nce_common->ncec_flags & NCE_F_BCAST) {
232111042SErik.Nordmark@Sun.COM ire_type = IRE_BROADCAST;
232211042SErik.Nordmark@Sun.COM nexthop = ire1->ire_gateway_addr;
232311042SErik.Nordmark@Sun.COM } else if (nce->nce_common->ncec_flags & NCE_F_MCAST) {
232411042SErik.Nordmark@Sun.COM ire_type = IRE_MULTICAST;
232511042SErik.Nordmark@Sun.COM nexthop = ipha->ipha_dst;
232611042SErik.Nordmark@Sun.COM } else {
232711042SErik.Nordmark@Sun.COM ire_type = ire1->ire_type; /* Doesn't matter */
232811042SErik.Nordmark@Sun.COM nexthop = ire1->ire_gateway_addr;
232911042SErik.Nordmark@Sun.COM }
233011042SErik.Nordmark@Sun.COM
233111042SErik.Nordmark@Sun.COM /* If IPMP meta or under, then we just drop */
233211042SErik.Nordmark@Sun.COM if (ill1->ill_grp != NULL) {
233311042SErik.Nordmark@Sun.COM BUMP_MIB(ill1->ill_ip_mib, ipIfStatsOutDiscards);
233411042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards - IPMP",
233511042SErik.Nordmark@Sun.COM mp, ill1);
233611042SErik.Nordmark@Sun.COM ill_refrele(ill1);
233711042SErik.Nordmark@Sun.COM error = ENETUNREACH;
233811042SErik.Nordmark@Sun.COM continue;
233911042SErik.Nordmark@Sun.COM }
234011042SErik.Nordmark@Sun.COM
234111042SErik.Nordmark@Sun.COM nce1 = arp_nce_init(ill1, nexthop, ire_type);
234211042SErik.Nordmark@Sun.COM if (nce1 == NULL) {
234311042SErik.Nordmark@Sun.COM BUMP_MIB(ill1->ill_ip_mib, ipIfStatsOutDiscards);
234411042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards - no nce",
234511042SErik.Nordmark@Sun.COM mp, ill1);
234611042SErik.Nordmark@Sun.COM ill_refrele(ill1);
234711042SErik.Nordmark@Sun.COM error = ENETUNREACH;
234811042SErik.Nordmark@Sun.COM continue;
234911042SErik.Nordmark@Sun.COM }
235011042SErik.Nordmark@Sun.COM mp1 = copymsg(mp);
235111042SErik.Nordmark@Sun.COM if (mp1 == NULL) {
235211042SErik.Nordmark@Sun.COM BUMP_MIB(ill1->ill_ip_mib, ipIfStatsOutDiscards);
235311042SErik.Nordmark@Sun.COM ip_drop_output("ipIfStatsOutDiscards", mp, ill1);
235411042SErik.Nordmark@Sun.COM nce_refrele(nce1);
235511042SErik.Nordmark@Sun.COM ill_refrele(ill1);
235611042SErik.Nordmark@Sun.COM error = ENOBUFS;
235711042SErik.Nordmark@Sun.COM continue;
235811042SErik.Nordmark@Sun.COM }
235911042SErik.Nordmark@Sun.COM /* Preserve HW checksum for this copy */
236011042SErik.Nordmark@Sun.COM DB_CKSUMSTART(mp1) = DB_CKSUMSTART(mp);
236111042SErik.Nordmark@Sun.COM DB_CKSUMSTUFF(mp1) = DB_CKSUMSTUFF(mp);
236211042SErik.Nordmark@Sun.COM DB_CKSUMEND(mp1) = DB_CKSUMEND(mp);
236311042SErik.Nordmark@Sun.COM DB_CKSUMFLAGS(mp1) = DB_CKSUMFLAGS(mp);
236411042SErik.Nordmark@Sun.COM DB_LSOMSS(mp1) = DB_LSOMSS(mp);
236511042SErik.Nordmark@Sun.COM
236611042SErik.Nordmark@Sun.COM ire1->ire_ob_pkt_count++;
236711042SErik.Nordmark@Sun.COM err = ip_xmit(mp1, nce1, ixaflags, pkt_len, xmit_hint, szone,
236811042SErik.Nordmark@Sun.COM 0, ixacookie);
236911042SErik.Nordmark@Sun.COM if (err == 0)
237011042SErik.Nordmark@Sun.COM num_sent++;
237111042SErik.Nordmark@Sun.COM else
237211042SErik.Nordmark@Sun.COM error = err;
237311042SErik.Nordmark@Sun.COM nce_refrele(nce1);
237411042SErik.Nordmark@Sun.COM ill_refrele(ill1);
237511042SErik.Nordmark@Sun.COM }
237611042SErik.Nordmark@Sun.COM irb_refrele(irb);
237711042SErik.Nordmark@Sun.COM ire_refrele(ire);
237811042SErik.Nordmark@Sun.COM /* Finally, the main one */
237911042SErik.Nordmark@Sun.COM err = ip_xmit(mp, nce, ixaflags, pkt_len, xmit_hint, szone, 0,
238011042SErik.Nordmark@Sun.COM ixacookie);
238111042SErik.Nordmark@Sun.COM if (err == 0)
238211042SErik.Nordmark@Sun.COM num_sent++;
238311042SErik.Nordmark@Sun.COM else
238411042SErik.Nordmark@Sun.COM error = err;
238511042SErik.Nordmark@Sun.COM if (num_sent > 0)
238611042SErik.Nordmark@Sun.COM return (0);
238711042SErik.Nordmark@Sun.COM else
238811042SErik.Nordmark@Sun.COM return (error);
238911042SErik.Nordmark@Sun.COM }
239011042SErik.Nordmark@Sun.COM
239111042SErik.Nordmark@Sun.COM /*
239211042SErik.Nordmark@Sun.COM * Verify local connectivity. This check is called by ULP fusion code.
239311042SErik.Nordmark@Sun.COM * The generation number on an IRE_LOCAL or IRE_LOOPBACK only changes if
239411042SErik.Nordmark@Sun.COM * the interface is brought down and back up. So we simply fail the local
239511042SErik.Nordmark@Sun.COM * process. The caller, TCP Fusion, should unfuse the connection.
239611042SErik.Nordmark@Sun.COM */
239711042SErik.Nordmark@Sun.COM boolean_t
ip_output_verify_local(ip_xmit_attr_t * ixa)239811042SErik.Nordmark@Sun.COM ip_output_verify_local(ip_xmit_attr_t *ixa)
239911042SErik.Nordmark@Sun.COM {
240011042SErik.Nordmark@Sun.COM ire_t *ire = ixa->ixa_ire;
240111042SErik.Nordmark@Sun.COM
240211042SErik.Nordmark@Sun.COM if (!(ire->ire_type & (IRE_LOCAL | IRE_LOOPBACK)))
240311042SErik.Nordmark@Sun.COM return (B_FALSE);
240411042SErik.Nordmark@Sun.COM
240511042SErik.Nordmark@Sun.COM return (ixa->ixa_ire->ire_generation == ixa->ixa_ire_generation);
240611042SErik.Nordmark@Sun.COM }
240711042SErik.Nordmark@Sun.COM
240811042SErik.Nordmark@Sun.COM /*
240911042SErik.Nordmark@Sun.COM * Local process for ULP loopback, TCP Fusion. Handle both IPv4 and IPv6.
241011042SErik.Nordmark@Sun.COM *
241111042SErik.Nordmark@Sun.COM * The caller must call ip_output_verify_local() first. This function handles
241211042SErik.Nordmark@Sun.COM * IPobs, FW_HOOKS, and/or IPsec cases sequentially.
241311042SErik.Nordmark@Sun.COM */
241411042SErik.Nordmark@Sun.COM mblk_t *
ip_output_process_local(mblk_t * mp,ip_xmit_attr_t * ixa,boolean_t hooks_out,boolean_t hooks_in,conn_t * peer_connp)241511042SErik.Nordmark@Sun.COM ip_output_process_local(mblk_t *mp, ip_xmit_attr_t *ixa, boolean_t hooks_out,
241611042SErik.Nordmark@Sun.COM boolean_t hooks_in, conn_t *peer_connp)
241711042SErik.Nordmark@Sun.COM {
241811042SErik.Nordmark@Sun.COM ill_t *ill = ixa->ixa_ire->ire_ill;
241911042SErik.Nordmark@Sun.COM ipha_t *ipha = NULL;
242011042SErik.Nordmark@Sun.COM ip6_t *ip6h = NULL;
242111042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ixa->ixa_ipst;
242211042SErik.Nordmark@Sun.COM iaflags_t ixaflags = ixa->ixa_flags;
242311042SErik.Nordmark@Sun.COM ip_recv_attr_t iras;
242411042SErik.Nordmark@Sun.COM int error;
242511042SErik.Nordmark@Sun.COM
242611042SErik.Nordmark@Sun.COM ASSERT(mp != NULL);
242711042SErik.Nordmark@Sun.COM
242811042SErik.Nordmark@Sun.COM if (ixaflags & IXAF_IS_IPV4) {
242911042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr;
243011042SErik.Nordmark@Sun.COM
243111042SErik.Nordmark@Sun.COM /*
243211042SErik.Nordmark@Sun.COM * If a callback is enabled then we need to know the
243311042SErik.Nordmark@Sun.COM * source and destination zoneids for the packet. We already
243411042SErik.Nordmark@Sun.COM * have those handy.
243511042SErik.Nordmark@Sun.COM */
243611042SErik.Nordmark@Sun.COM if (ipst->ips_ip4_observe.he_interested) {
243711042SErik.Nordmark@Sun.COM zoneid_t szone, dzone;
243811042SErik.Nordmark@Sun.COM zoneid_t stackzoneid;
243911042SErik.Nordmark@Sun.COM
244011042SErik.Nordmark@Sun.COM stackzoneid = netstackid_to_zoneid(
244111042SErik.Nordmark@Sun.COM ipst->ips_netstack->netstack_stackid);
244211042SErik.Nordmark@Sun.COM
244311042SErik.Nordmark@Sun.COM if (stackzoneid == GLOBAL_ZONEID) {
244411042SErik.Nordmark@Sun.COM /* Shared-IP zone */
244511042SErik.Nordmark@Sun.COM dzone = ixa->ixa_ire->ire_zoneid;
244611042SErik.Nordmark@Sun.COM szone = ixa->ixa_zoneid;
244711042SErik.Nordmark@Sun.COM } else {
244811042SErik.Nordmark@Sun.COM szone = dzone = stackzoneid;
244911042SErik.Nordmark@Sun.COM }
245011042SErik.Nordmark@Sun.COM ipobs_hook(mp, IPOBS_HOOK_LOCAL, szone, dzone, ill,
245111042SErik.Nordmark@Sun.COM ipst);
245211042SErik.Nordmark@Sun.COM }
245311042SErik.Nordmark@Sun.COM DTRACE_IP7(send, mblk_t *, mp, conn_t *, NULL, void_ip_t *,
245411042SErik.Nordmark@Sun.COM ipha, __dtrace_ipsr_ill_t *, ill, ipha_t *, ipha, ip6_t *,
245511042SErik.Nordmark@Sun.COM NULL, int, 1);
245611042SErik.Nordmark@Sun.COM
245711042SErik.Nordmark@Sun.COM /* FW_HOOKS: LOOPBACK_OUT */
245811042SErik.Nordmark@Sun.COM if (hooks_out) {
245911042SErik.Nordmark@Sun.COM DTRACE_PROBE4(ip4__loopback__out__start, ill_t *, NULL,
246011042SErik.Nordmark@Sun.COM ill_t *, ill, ipha_t *, ipha, mblk_t *, mp);
246111042SErik.Nordmark@Sun.COM FW_HOOKS(ipst->ips_ip4_loopback_out_event,
246211042SErik.Nordmark@Sun.COM ipst->ips_ipv4firewall_loopback_out,
246311042SErik.Nordmark@Sun.COM NULL, ill, ipha, mp, mp, 0, ipst, error);
246411042SErik.Nordmark@Sun.COM DTRACE_PROBE1(ip4__loopback__out__end, mblk_t *, mp);
246511042SErik.Nordmark@Sun.COM }
246611042SErik.Nordmark@Sun.COM if (mp == NULL)
246711042SErik.Nordmark@Sun.COM return (NULL);
246811042SErik.Nordmark@Sun.COM
246911042SErik.Nordmark@Sun.COM /* FW_HOOKS: LOOPBACK_IN */
247011042SErik.Nordmark@Sun.COM if (hooks_in) {
247111042SErik.Nordmark@Sun.COM DTRACE_PROBE4(ip4__loopback__in__start, ill_t *, ill,
247211042SErik.Nordmark@Sun.COM ill_t *, NULL, ipha_t *, ipha, mblk_t *, mp);
247311042SErik.Nordmark@Sun.COM FW_HOOKS(ipst->ips_ip4_loopback_in_event,
247411042SErik.Nordmark@Sun.COM ipst->ips_ipv4firewall_loopback_in,
247511042SErik.Nordmark@Sun.COM ill, NULL, ipha, mp, mp, 0, ipst, error);
247611042SErik.Nordmark@Sun.COM DTRACE_PROBE1(ip4__loopback__in__end, mblk_t *, mp);
247711042SErik.Nordmark@Sun.COM }
247811042SErik.Nordmark@Sun.COM if (mp == NULL)
247911042SErik.Nordmark@Sun.COM return (NULL);
248011042SErik.Nordmark@Sun.COM
248111042SErik.Nordmark@Sun.COM DTRACE_IP7(receive, mblk_t *, mp, conn_t *, NULL, void_ip_t *,
248211042SErik.Nordmark@Sun.COM ipha, __dtrace_ipsr_ill_t *, ill, ipha_t *, ipha, ip6_t *,
248311042SErik.Nordmark@Sun.COM NULL, int, 1);
248411042SErik.Nordmark@Sun.COM
248511042SErik.Nordmark@Sun.COM /* Inbound IPsec polocies */
248611042SErik.Nordmark@Sun.COM if (peer_connp != NULL) {
248711042SErik.Nordmark@Sun.COM /* Map ixa to ira including IPsec policies. */
248811042SErik.Nordmark@Sun.COM ipsec_out_to_in(ixa, ill, &iras);
248911042SErik.Nordmark@Sun.COM mp = ipsec_check_inbound_policy(mp, peer_connp, ipha,
249011042SErik.Nordmark@Sun.COM NULL, &iras);
249111042SErik.Nordmark@Sun.COM }
249211042SErik.Nordmark@Sun.COM } else {
249311042SErik.Nordmark@Sun.COM ip6h = (ip6_t *)mp->b_rptr;
249411042SErik.Nordmark@Sun.COM
249511042SErik.Nordmark@Sun.COM /*
249611042SErik.Nordmark@Sun.COM * If a callback is enabled then we need to know the
249711042SErik.Nordmark@Sun.COM * source and destination zoneids for the packet. We already
249811042SErik.Nordmark@Sun.COM * have those handy.
249911042SErik.Nordmark@Sun.COM */
250011042SErik.Nordmark@Sun.COM if (ipst->ips_ip6_observe.he_interested) {
250111042SErik.Nordmark@Sun.COM zoneid_t szone, dzone;
250211042SErik.Nordmark@Sun.COM zoneid_t stackzoneid;
250311042SErik.Nordmark@Sun.COM
250411042SErik.Nordmark@Sun.COM stackzoneid = netstackid_to_zoneid(
250511042SErik.Nordmark@Sun.COM ipst->ips_netstack->netstack_stackid);
250611042SErik.Nordmark@Sun.COM
250711042SErik.Nordmark@Sun.COM if (stackzoneid == GLOBAL_ZONEID) {
250811042SErik.Nordmark@Sun.COM /* Shared-IP zone */
250911042SErik.Nordmark@Sun.COM dzone = ixa->ixa_ire->ire_zoneid;
251011042SErik.Nordmark@Sun.COM szone = ixa->ixa_zoneid;
251111042SErik.Nordmark@Sun.COM } else {
251211042SErik.Nordmark@Sun.COM szone = dzone = stackzoneid;
251311042SErik.Nordmark@Sun.COM }
251411042SErik.Nordmark@Sun.COM ipobs_hook(mp, IPOBS_HOOK_LOCAL, szone, dzone, ill,
251511042SErik.Nordmark@Sun.COM ipst);
251611042SErik.Nordmark@Sun.COM }
251711042SErik.Nordmark@Sun.COM DTRACE_IP7(send, mblk_t *, mp, conn_t *, NULL, void_ip_t *,
251811042SErik.Nordmark@Sun.COM ip6h, __dtrace_ipsr_ill_t *, ill, ipha_t *, NULL, ip6_t *,
251911042SErik.Nordmark@Sun.COM ip6h, int, 1);
252011042SErik.Nordmark@Sun.COM
252111042SErik.Nordmark@Sun.COM /* FW_HOOKS: LOOPBACK_OUT */
252211042SErik.Nordmark@Sun.COM if (hooks_out) {
252311042SErik.Nordmark@Sun.COM DTRACE_PROBE4(ip6__loopback__out__start, ill_t *, NULL,
252411042SErik.Nordmark@Sun.COM ill_t *, ill, ip6_t *, ip6h, mblk_t *, mp);
252511042SErik.Nordmark@Sun.COM FW_HOOKS6(ipst->ips_ip6_loopback_out_event,
252611042SErik.Nordmark@Sun.COM ipst->ips_ipv6firewall_loopback_out,
252711042SErik.Nordmark@Sun.COM NULL, ill, ip6h, mp, mp, 0, ipst, error);
252811042SErik.Nordmark@Sun.COM DTRACE_PROBE1(ip6__loopback__out__end, mblk_t *, mp);
252911042SErik.Nordmark@Sun.COM }
253011042SErik.Nordmark@Sun.COM if (mp == NULL)
253111042SErik.Nordmark@Sun.COM return (NULL);
253211042SErik.Nordmark@Sun.COM
253311042SErik.Nordmark@Sun.COM /* FW_HOOKS: LOOPBACK_IN */
253411042SErik.Nordmark@Sun.COM if (hooks_in) {
253511042SErik.Nordmark@Sun.COM DTRACE_PROBE4(ip6__loopback__in__start, ill_t *, ill,
253611042SErik.Nordmark@Sun.COM ill_t *, NULL, ip6_t *, ip6h, mblk_t *, mp);
253711042SErik.Nordmark@Sun.COM FW_HOOKS6(ipst->ips_ip6_loopback_in_event,
253811042SErik.Nordmark@Sun.COM ipst->ips_ipv6firewall_loopback_in,
253911042SErik.Nordmark@Sun.COM ill, NULL, ip6h, mp, mp, 0, ipst, error);
254011042SErik.Nordmark@Sun.COM DTRACE_PROBE1(ip6__loopback__in__end, mblk_t *, mp);
254111042SErik.Nordmark@Sun.COM }
254211042SErik.Nordmark@Sun.COM if (mp == NULL)
254311042SErik.Nordmark@Sun.COM return (NULL);
254411042SErik.Nordmark@Sun.COM
254511042SErik.Nordmark@Sun.COM DTRACE_IP7(receive, mblk_t *, mp, conn_t *, NULL, void_ip_t *,
254611042SErik.Nordmark@Sun.COM ip6h, __dtrace_ipsr_ill_t *, ill, ipha_t *, NULL, ip6_t *,
254711042SErik.Nordmark@Sun.COM ip6h, int, 1);
254811042SErik.Nordmark@Sun.COM
254911042SErik.Nordmark@Sun.COM /* Inbound IPsec polocies */
255011042SErik.Nordmark@Sun.COM if (peer_connp != NULL) {
255111042SErik.Nordmark@Sun.COM /* Map ixa to ira including IPsec policies. */
255211042SErik.Nordmark@Sun.COM ipsec_out_to_in(ixa, ill, &iras);
255311042SErik.Nordmark@Sun.COM mp = ipsec_check_inbound_policy(mp, peer_connp, NULL,
255411042SErik.Nordmark@Sun.COM ip6h, &iras);
255511042SErik.Nordmark@Sun.COM }
255611042SErik.Nordmark@Sun.COM }
255711042SErik.Nordmark@Sun.COM
255811042SErik.Nordmark@Sun.COM if (mp == NULL) {
255911042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards);
256011042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", NULL, ill);
256111042SErik.Nordmark@Sun.COM }
256211042SErik.Nordmark@Sun.COM
256311042SErik.Nordmark@Sun.COM return (mp);
256411042SErik.Nordmark@Sun.COM }
2565