4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 * Copyright (c) 1990 Mentat Inc.
29 #include <sys/types.h>
30 #include <sys/stream.h>
32 #include <sys/stropts.h>
33 #include <sys/sysmacros.h>
34 #include <sys/strsun.h>
35 #include <sys/strlog.h>
36 #include <sys/strsubr.h>
37 #define _SUN_TPI_VERSION 2
38 #include <sys/tihdr.h>
40 #include <sys/sunddi.h>
41 #include <sys/cmn_err.h>
42 #include <sys/debug.h>
50 #include <sys/systm.h>
51 #include <sys/param.h>
52 #include <sys/socket.h>
53 #include <sys/vtrace.h>
54 #include <sys/isa_defs.h>
55 #include <sys/atomic.h>
56 #include <sys/iphada.h>
57 #include <sys/policy.h>
59 #include <net/if_types.h>
60 #include <net/route.h>
61 #include <net/if_dl.h>
62 #include <sys/sockio.h>
63 #include <netinet/in.h>
64 #include <netinet/ip6.h>
65 #include <netinet/icmp6.h>
66 #include <netinet/sctp.h>
68 #include <inet/common.h>
70 #include <inet/optcom.h>
71 #include <inet/mib2.h>
76 #include <inet/ip_impl.h>
78 #include <inet/ip6_asp.h>
80 #include <inet/tcp_impl.h>
81 #include <inet/udp_impl.h>
82 #include <inet/ipp_common.h>
84 #include <inet/ip_multi.h>
85 #include <inet/ip_if.h>
86 #include <inet/ip_ire.h>
87 #include <inet/ip_rts.h>
88 #include <inet/ip_ndp.h>
89 #include <net/pfkeyv2.h>
90 #include <inet/ipsec_info.h>
91 #include <inet/sadb.h>
92 #include <inet/ipsec_impl.h>
94 #include <inet/sctp_ip.h>
95 #include <sys/pattr.h>
96 #include <inet/ipclassifier.h>
97 #include <inet/ipsecah.h>
98 #include <inet/rawip_impl.h>
99 #include <inet/rts_impl.h>
100 #include <sys/squeue_impl.h>
101 #include <sys/squeue.h>
103 #include <sys/tsol/label.h>
104 #include <sys/tsol/tnet.h>
106 #include <rpc/pmap_prot.h>
108 /* Temporary; for CR 6451644 work-around */
109 #include <sys/ethernet.h>
111 extern int ip_squeue_flag
;
114 * Naming conventions:
115 * These rules should be judiciously applied
116 * if there is a need to identify something as IPv6 versus IPv4
117 * IPv6 funcions will end with _v6 in the ip module.
118 * IPv6 funcions will end with _ipv6 in the transport modules.
120 * Some macros end with _V6; e.g. ILL_FRAG_HASH_V6
121 * Some macros start with V6_; e.g. V6_OR_V4_INADDR_ANY
122 * And then there are ..V4_PART_OF_V6.
123 * The intent is that macros in the ip module end with _V6.
124 * IPv6 global variables will start with ipv6_
125 * IPv6 structures will start with ipv6
126 * IPv6 defined constants should start with IPV6_
127 * (but then there are NDP_DEFAULT_VERS_PRI_AND_FLOW, etc)
131 * ip6opt_ls is used to enable IPv6 (via /etc/system on TX systems).
132 * We need to do this because we didn't obtain the IP6OPT_LS (0x0a)
133 * from IANA. This mechanism will remain in effect until an official
134 * number is obtained.
138 const in6_addr_t ipv6_all_ones
=
139 { 0xffffffffU
, 0xffffffffU
, 0xffffffffU
, 0xffffffffU
};
140 const in6_addr_t ipv6_all_zeros
= { 0, 0, 0, 0 };
143 const in6_addr_t ipv6_unspecified_group
= { 0xff000000U
, 0, 0, 0 };
144 #else /* _BIG_ENDIAN */
145 const in6_addr_t ipv6_unspecified_group
= { 0x000000ffU
, 0, 0, 0 };
146 #endif /* _BIG_ENDIAN */
149 const in6_addr_t ipv6_loopback
= { 0, 0, 0, 0x00000001U
};
150 #else /* _BIG_ENDIAN */
151 const in6_addr_t ipv6_loopback
= { 0, 0, 0, 0x01000000U
};
152 #endif /* _BIG_ENDIAN */
155 const in6_addr_t ipv6_all_hosts_mcast
= { 0xff020000U
, 0, 0, 0x00000001U
};
156 #else /* _BIG_ENDIAN */
157 const in6_addr_t ipv6_all_hosts_mcast
= { 0x000002ffU
, 0, 0, 0x01000000U
};
158 #endif /* _BIG_ENDIAN */
161 const in6_addr_t ipv6_all_rtrs_mcast
= { 0xff020000U
, 0, 0, 0x00000002U
};
162 #else /* _BIG_ENDIAN */
163 const in6_addr_t ipv6_all_rtrs_mcast
= { 0x000002ffU
, 0, 0, 0x02000000U
};
164 #endif /* _BIG_ENDIAN */
167 const in6_addr_t ipv6_all_v2rtrs_mcast
= { 0xff020000U
, 0, 0, 0x00000016U
};
168 #else /* _BIG_ENDIAN */
169 const in6_addr_t ipv6_all_v2rtrs_mcast
= { 0x000002ffU
, 0, 0, 0x16000000U
};
170 #endif /* _BIG_ENDIAN */
173 const in6_addr_t ipv6_solicited_node_mcast
=
174 { 0xff020000U
, 0, 0x00000001U
, 0xff000000U
};
175 #else /* _BIG_ENDIAN */
176 const in6_addr_t ipv6_solicited_node_mcast
=
177 { 0x000002ffU
, 0, 0x01000000U
, 0x000000ffU
};
178 #endif /* _BIG_ENDIAN */
180 /* Leave room for ip_newroute to tack on the src and target addresses */
181 #define OK_RESOLVER_MP_V6(mp) \
182 ((mp) && ((mp)->b_wptr - (mp)->b_rptr) >= (2 * IPV6_ADDR_LEN))
184 #define IP6_MBLK_OK 0
185 #define IP6_MBLK_HDR_ERR 1
186 #define IP6_MBLK_LEN_ERR 2
188 static void icmp_inbound_too_big_v6(queue_t
*, mblk_t
*, ill_t
*, ill_t
*,
189 boolean_t
, zoneid_t
);
190 static void icmp_pkt_v6(queue_t
*, mblk_t
*, void *, size_t,
191 const in6_addr_t
*, boolean_t
, zoneid_t
, ip_stack_t
*);
192 static void icmp_redirect_v6(queue_t
*, mblk_t
*, ill_t
*ill
);
193 static int ip_bind_connected_v6(conn_t
*, mblk_t
**, uint8_t, in6_addr_t
*,
194 uint16_t, const in6_addr_t
*, ip6_pkt_t
*, uint16_t,
195 boolean_t
, boolean_t
, cred_t
*);
196 static boolean_t
ip_bind_get_ire_v6(mblk_t
**, ire_t
*, const in6_addr_t
*,
197 iulp_t
*, ip_stack_t
*);
198 static void ip_bind_post_handling_v6(conn_t
*, mblk_t
*, boolean_t
,
199 boolean_t
, ip_stack_t
*);
200 static int ip_bind_laddr_v6(conn_t
*, mblk_t
**, uint8_t,
201 const in6_addr_t
*, uint16_t, boolean_t
);
202 static void ip_fanout_proto_v6(queue_t
*, mblk_t
*, ip6_t
*, ill_t
*,
203 ill_t
*, uint8_t, uint_t
, uint_t
, boolean_t
, zoneid_t
);
204 static void ip_fanout_tcp_v6(queue_t
*, mblk_t
*, ip6_t
*, ill_t
*,
205 ill_t
*, uint_t
, uint_t
, boolean_t
, zoneid_t
);
206 static void ip_fanout_udp_v6(queue_t
*, mblk_t
*, ip6_t
*, uint32_t,
207 ill_t
*, ill_t
*, uint_t
, boolean_t
, zoneid_t
);
208 static int ip_process_options_v6(queue_t
*, mblk_t
*, ip6_t
*,
209 uint8_t *, uint_t
, uint8_t, ip_stack_t
*);
210 static mblk_t
*ip_rput_frag_v6(ill_t
*, ill_t
*, mblk_t
*, ip6_t
*,
211 ip6_frag_t
*, uint_t
, uint_t
*, uint32_t *, uint16_t *);
212 static boolean_t
ip_source_routed_v6(ip6_t
*, mblk_t
*, ip_stack_t
*);
213 static void ip_wput_ire_v6(queue_t
*, mblk_t
*, ire_t
*, int, int,
214 conn_t
*, int, int, zoneid_t
);
215 static boolean_t
ipif_lookup_testaddr_v6(ill_t
*, const in6_addr_t
*,
219 * A template for an IPv6 AR_ENTRY_QUERY
221 static areq_t ipv6_areq_template
= {
222 AR_ENTRY_QUERY
, /* cmd */
223 sizeof (areq_t
)+(2*IPV6_ADDR_LEN
), /* name offset */
224 sizeof (areq_t
), /* name len (filled by ill_arp_alloc) */
225 IP6_DL_SAP
, /* protocol, from arps perspective */
226 sizeof (areq_t
), /* target addr offset */
227 IPV6_ADDR_LEN
, /* target addr_length */
229 sizeof (areq_t
) + IPV6_ADDR_LEN
, /* sender addr offset */
230 IPV6_ADDR_LEN
, /* sender addr length */
232 1000, /* (re)xmit_interval in milliseconds */
233 4 /* max # of requests to buffer */
234 /* anything else filled in by the code */
238 * Handle IPv6 ICMP packets sent to us. Consume the mblk passed in.
239 * The message has already been checksummed and if needed,
240 * a copy has been made to be sent any interested ICMP client (conn)
241 * Note that this is different than icmp_inbound() which does the fanout
242 * to conn's as well as local processing of the ICMP packets.
244 * All error messages are passed to the matching transport stream.
247 * The packet is only processed in the context of the specified zone: typically
248 * only this zone will reply to an echo request. This means that the caller must
249 * call icmp_inbound_v6() for each relevant zone.
252 icmp_inbound_v6(queue_t
*q
, mblk_t
*mp
, ill_t
*ill
, ill_t
*inill
,
253 uint_t hdr_length
, boolean_t mctl_present
, uint_t flags
, zoneid_t zoneid
,
258 boolean_t interested
;
262 ip_stack_t
*ipst
= ill
->ill_ipst
;
267 mp
= first_mp
->b_cont
;
270 ii
= (ipsec_in_t
*)first_mp
->b_rptr
;
271 ASSERT(ii
->ipsec_in_type
== IPSEC_IN
);
274 ip6h
= (ip6_t
*)mp
->b_rptr
;
276 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInMsgs
);
278 if ((mp
->b_wptr
- mp
->b_rptr
) < (hdr_length
+ ICMP6_MINLEN
)) {
279 if (!pullupmsg(mp
, hdr_length
+ ICMP6_MINLEN
)) {
280 ip1dbg(("icmp_inbound_v6: pullupmsg failed\n"));
281 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInErrors
);
285 ip6h
= (ip6_t
*)mp
->b_rptr
;
287 if (ipst
->ips_icmp_accept_clear_messages
== 0) {
288 first_mp
= ipsec_check_global_policy(first_mp
, NULL
,
289 NULL
, ip6h
, mctl_present
, ipst
->ips_netstack
);
290 if (first_mp
== NULL
)
295 * On a labeled system, we have to check whether the zone itself is
296 * permitted to receive raw traffic.
298 if (is_system_labeled()) {
299 if (zoneid
== ALL_ZONES
)
300 zoneid
= tsol_packet_to_zoneid(mp
);
301 if (!tsol_can_accept_raw(mp
, B_FALSE
)) {
302 ip1dbg(("icmp_inbound_v6: zone %d can't receive raw",
304 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInErrors
);
310 icmp6
= (icmp6_t
*)(&mp
->b_rptr
[hdr_length
]);
311 ip2dbg(("icmp_inbound_v6: type %d code %d\n", icmp6
->icmp6_type
,
313 interested
= !(icmp6
->icmp6_type
& ICMP6_INFOMSG_MASK
);
315 /* Initiate IPPF processing here */
316 if (IP6_IN_IPP(flags
, ipst
)) {
319 * If the ifindex changes due to SIOCSLIFINDEX
320 * packet may return to IP on the wrong ill.
322 ip_process(IPP_LOCAL_IN
, &mp
, ill
->ill_phyint
->phyint_ifindex
);
331 switch (icmp6
->icmp6_type
) {
332 case ICMP6_DST_UNREACH
:
333 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInDestUnreachs
);
334 if (icmp6
->icmp6_code
== ICMP6_DST_UNREACH_ADMIN
)
335 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInAdminProhibs
);
338 case ICMP6_TIME_EXCEEDED
:
339 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInTimeExcds
);
342 case ICMP6_PARAM_PROB
:
343 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInParmProblems
);
346 case ICMP6_PACKET_TOO_BIG
:
347 icmp_inbound_too_big_v6(q
, first_mp
, ill
, inill
, mctl_present
,
350 case ICMP6_ECHO_REQUEST
:
351 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInEchos
);
352 if (IN6_IS_ADDR_MULTICAST(&ip6h
->ip6_dst
) &&
353 !ipst
->ips_ipv6_resp_echo_mcast
)
357 * We must have exclusive use of the mblk to convert it to
359 * If not, we copy it.
361 if (mp
->b_datap
->db_ref
> 1) {
367 BUMP_MIB(ill
->ill_icmp6_mib
,
374 ip6h
= (ip6_t
*)mp
->b_rptr
;
375 icmp6
= (icmp6_t
*)(&mp
->b_rptr
[hdr_length
]);
377 first_mp
->b_cont
= mp
;
383 * Turn the echo into an echo reply.
384 * Remove any extension headers (do not reverse a source route)
385 * and clear the flow id (keep traffic class for now).
387 if (hdr_length
!= IPV6_HDR_LEN
) {
390 for (i
= 0; i
< IPV6_HDR_LEN
; i
++)
391 mp
->b_rptr
[hdr_length
- i
- 1] =
392 mp
->b_rptr
[IPV6_HDR_LEN
- i
- 1];
393 mp
->b_rptr
+= (hdr_length
- IPV6_HDR_LEN
);
394 ip6h
= (ip6_t
*)mp
->b_rptr
;
395 ip6h
->ip6_nxt
= IPPROTO_ICMPV6
;
396 hdr_length
= IPV6_HDR_LEN
;
398 ip6h
->ip6_vcf
&= ~IPV6_FLOWINFO_FLOWLABEL
;
399 icmp6
->icmp6_type
= ICMP6_ECHO_REPLY
;
402 htons((uint16_t)(msgdsize(mp
) - IPV6_HDR_LEN
));
403 origsrc
= ip6h
->ip6_src
;
405 * Reverse the source and destination addresses.
406 * If the return address is a multicast, zero out the source
407 * (ip_wput_v6 will set an address).
409 if (IN6_IS_ADDR_MULTICAST(&ip6h
->ip6_dst
)) {
410 ip6h
->ip6_src
= ipv6_all_zeros
;
411 ip6h
->ip6_dst
= origsrc
;
413 ip6h
->ip6_src
= ip6h
->ip6_dst
;
414 ip6h
->ip6_dst
= origsrc
;
417 /* set the hop limit */
418 ip6h
->ip6_hops
= ipst
->ips_ipv6_def_hops
;
421 * Prepare for checksum by putting icmp length in the icmp
422 * checksum field. The checksum is calculated in ip_wput_v6.
424 icmp6
->icmp6_cksum
= ip6h
->ip6_plen
;
428 * This packet should go out the same way as it
429 * came in i.e in clear. To make sure that global
430 * policy will not be applied to this in ip_wput,
431 * we attach a IPSEC_IN mp and clear ipsec_in_secure.
433 ASSERT(first_mp
== mp
);
434 first_mp
= ipsec_in_alloc(B_FALSE
, ipst
->ips_netstack
);
435 if (first_mp
== NULL
) {
436 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
440 ii
= (ipsec_in_t
*)first_mp
->b_rptr
;
442 /* This is not a secure packet */
443 ii
->ipsec_in_secure
= B_FALSE
;
444 first_mp
->b_cont
= mp
;
446 ii
->ipsec_in_zoneid
= zoneid
;
447 ASSERT(zoneid
!= ALL_ZONES
);
448 if (!ipsec_in_to_out(first_mp
, NULL
, ip6h
)) {
449 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
452 put(WR(q
), first_mp
);
455 case ICMP6_ECHO_REPLY
:
456 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInEchoReplies
);
459 case ND_ROUTER_SOLICIT
:
460 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInRouterSolicits
);
463 case ND_ROUTER_ADVERT
:
464 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInRouterAdvertisements
);
467 case ND_NEIGHBOR_SOLICIT
:
468 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInNeighborSolicits
);
471 /* XXX may wish to pass first_mp up to ndp_input someday. */
472 ndp_input(inill
, mp
, dl_mp
);
475 case ND_NEIGHBOR_ADVERT
:
476 BUMP_MIB(ill
->ill_icmp6_mib
,
477 ipv6IfIcmpInNeighborAdvertisements
);
480 /* XXX may wish to pass first_mp up to ndp_input someday. */
481 ndp_input(inill
, mp
, dl_mp
);
485 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInRedirects
);
487 if (ipst
->ips_ipv6_ignore_redirect
)
491 * As there is no upper client to deliver, we don't
492 * need the first_mp any more.
496 if (!pullupmsg(mp
, -1)) {
497 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInBadRedirects
);
500 icmp_redirect_v6(q
, mp
, ill
);
505 * The next three icmp messages will be handled by MLD.
506 * Pass all valid MLD packets up to any process(es)
507 * listening on a raw ICMP socket. MLD messages are
508 * freed by mld_input function.
510 case MLD_LISTENER_QUERY
:
511 case MLD_LISTENER_REPORT
:
512 case MLD_LISTENER_REDUCTION
:
515 mld_input(q
, mp
, ill
);
521 icmp_inbound_error_fanout_v6(q
, first_mp
, ip6h
, icmp6
, ill
,
522 inill
, mctl_present
, zoneid
);
529 * Process received IPv6 ICMP Packet too big.
530 * After updating any IRE it does the fanout to any matching transport streams.
531 * Assumes the IPv6 plus ICMPv6 headers have been pulled up but nothing else.
535 icmp_inbound_too_big_v6(queue_t
*q
, mblk_t
*mp
, ill_t
*ill
, ill_t
*inill
,
536 boolean_t mctl_present
, zoneid_t zoneid
)
543 ire_t
*ire
, *first_ire
;
545 ip_stack_t
*ipst
= ill
->ill_ipst
;
549 mp
= first_mp
->b_cont
;
551 * We must have exclusive use of the mblk to update the MTU
553 * If not, we copy it.
555 * If there's an M_CTL present, we know that allocated first_mp
556 * earlier in this function, so we know first_mp has refcnt of one.
558 ASSERT(!mctl_present
|| first_mp
->b_datap
->db_ref
== 1);
559 if (mp
->b_datap
->db_ref
> 1) {
565 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
572 first_mp
->b_cont
= mp
;
576 ip6h
= (ip6_t
*)mp
->b_rptr
;
577 if (ip6h
->ip6_nxt
!= IPPROTO_ICMPV6
)
578 hdr_length
= ip_hdr_length_v6(mp
, ip6h
);
580 hdr_length
= IPV6_HDR_LEN
;
582 icmp6
= (icmp6_t
*)(&mp
->b_rptr
[hdr_length
]);
583 ASSERT((size_t)(mp
->b_wptr
- mp
->b_rptr
) >= hdr_length
+ ICMP6_MINLEN
);
584 inner_ip6h
= (ip6_t
*)&icmp6
[1]; /* Packet in error */
585 if ((uchar_t
*)&inner_ip6h
[1] > mp
->b_wptr
) {
586 if (!pullupmsg(mp
, (uchar_t
*)&inner_ip6h
[1] - mp
->b_rptr
)) {
587 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
591 ip6h
= (ip6_t
*)mp
->b_rptr
;
592 icmp6
= (icmp6_t
*)&mp
->b_rptr
[hdr_length
];
593 inner_ip6h
= (ip6_t
*)&icmp6
[1];
597 * For link local destinations matching simply on IRE type is not
598 * sufficient. Same link local addresses for different ILL's is
601 if (IN6_IS_ADDR_LINKLOCAL(&inner_ip6h
->ip6_dst
)) {
602 first_ire
= ire_ctable_lookup_v6(&inner_ip6h
->ip6_dst
, NULL
,
603 IRE_CACHE
, ill
->ill_ipif
, ALL_ZONES
, NULL
,
604 MATCH_IRE_TYPE
| MATCH_IRE_ILL
, ipst
);
606 if (first_ire
== NULL
) {
609 pr_addr_dbg("icmp_inbound_too_big_v6:"
610 "no ire for dst %s\n", AF_INET6
,
611 &inner_ip6h
->ip6_dst
);
617 mtu
= ntohl(icmp6
->icmp6_mtu
);
618 rw_enter(&first_ire
->ire_bucket
->irb_lock
, RW_READER
);
619 for (ire
= first_ire
; ire
!= NULL
&&
620 IN6_ARE_ADDR_EQUAL(&ire
->ire_addr_v6
, &inner_ip6h
->ip6_dst
);
621 ire
= ire
->ire_next
) {
622 mutex_enter(&ire
->ire_lock
);
623 if (mtu
< IPV6_MIN_MTU
) {
624 ip1dbg(("Received mtu less than IPv6 "
625 "min mtu %d: %d\n", IPV6_MIN_MTU
, mtu
));
628 * If an mtu less than IPv6 min mtu is received,
629 * we must include a fragment header in
630 * subsequent packets.
632 ire
->ire_frag_flag
|= IPH_FRAG_HDR
;
634 ip1dbg(("Received mtu from router: %d\n", mtu
));
635 ire
->ire_max_frag
= MIN(ire
->ire_max_frag
, mtu
);
636 /* Record the new max frag size for the ULP. */
637 if (ire
->ire_frag_flag
& IPH_FRAG_HDR
) {
639 * If we need a fragment header in every packet
640 * (above case or multirouting), make sure the
641 * ULP takes it into account when computing the
644 icmp6
->icmp6_mtu
= htonl(ire
->ire_max_frag
-
645 sizeof (ip6_frag_t
));
647 icmp6
->icmp6_mtu
= htonl(ire
->ire_max_frag
);
649 mutex_exit(&ire
->ire_lock
);
651 rw_exit(&first_ire
->ire_bucket
->irb_lock
);
652 ire_refrele(first_ire
);
656 * for non-link local destinations we match only on the IRE type
658 ire
= ire_ctable_lookup_v6(&inner_ip6h
->ip6_dst
, NULL
,
659 IRE_CACHE
, ill
->ill_ipif
, ALL_ZONES
, NULL
, MATCH_IRE_TYPE
,
664 pr_addr_dbg("icmp_inbound_too_big_v6:"
665 "no ire for dst %s\n",
666 AF_INET6
, &inner_ip6h
->ip6_dst
);
671 irb
= ire
->ire_bucket
;
673 rw_enter(&irb
->irb_lock
, RW_READER
);
674 for (ire
= irb
->irb_ire
; ire
!= NULL
; ire
= ire
->ire_next
) {
675 if (IN6_ARE_ADDR_EQUAL(&ire
->ire_addr_v6
,
676 &inner_ip6h
->ip6_dst
)) {
677 mtu
= ntohl(icmp6
->icmp6_mtu
);
678 mutex_enter(&ire
->ire_lock
);
679 if (mtu
< IPV6_MIN_MTU
) {
680 ip1dbg(("Received mtu less than IPv6"
685 * If an mtu less than IPv6 min mtu is
686 * received, we must include a fragment
687 * header in subsequent packets.
689 ire
->ire_frag_flag
|= IPH_FRAG_HDR
;
692 ip1dbg(("Received mtu from router: %d\n", mtu
));
693 ire
->ire_max_frag
= MIN(ire
->ire_max_frag
, mtu
);
694 /* Record the new max frag size for the ULP. */
695 if (ire
->ire_frag_flag
& IPH_FRAG_HDR
) {
697 * If we need a fragment header in
698 * every packet (above case or
699 * multirouting), make sure the ULP
700 * takes it into account when computing
704 htonl(ire
->ire_max_frag
-
705 sizeof (ip6_frag_t
));
708 htonl(ire
->ire_max_frag
);
710 mutex_exit(&ire
->ire_lock
);
713 rw_exit(&irb
->irb_lock
);
715 icmp_inbound_error_fanout_v6(q
, first_mp
, ip6h
, icmp6
, ill
, inill
,
716 mctl_present
, zoneid
);
720 * Fanout received ICMPv6 error packets to the transports.
721 * Assumes the IPv6 plus ICMPv6 headers have been pulled up but nothing else.
724 icmp_inbound_error_fanout_v6(queue_t
*q
, mblk_t
*mp
, ip6_t
*ip6h
,
725 icmp6_t
*icmp6
, ill_t
*ill
, ill_t
*inill
, boolean_t mctl_present
,
728 uint16_t *up
; /* Pointer to ports in ULP header */
729 uint32_t ports
; /* reversed ports for fanout */
730 ip6_t rip6h
; /* With reversed addresses */
738 ip_stack_t
*ipst
= ill
->ill_ipst
;
742 mp
= first_mp
->b_cont
;
745 ii
= (ipsec_in_t
*)first_mp
->b_rptr
;
746 ASSERT(ii
->ipsec_in_type
== IPSEC_IN
);
751 hdr_length
= (uint16_t)((uchar_t
*)icmp6
- (uchar_t
*)ip6h
);
752 ASSERT((size_t)(mp
->b_wptr
- (uchar_t
*)icmp6
) >= ICMP6_MINLEN
);
755 * Need to pullup everything in order to use
756 * ip_hdr_length_nexthdr_v6()
758 if (mp
->b_cont
!= NULL
) {
759 if (!pullupmsg(mp
, -1)) {
760 ip1dbg(("icmp_inbound_error_fanout_v6: "
761 "pullupmsg failed\n"));
764 ip6h
= (ip6_t
*)mp
->b_rptr
;
765 icmp6
= (icmp6_t
*)(&mp
->b_rptr
[hdr_length
]);
768 ip6h
= (ip6_t
*)&icmp6
[1]; /* Packet in error */
769 if ((uchar_t
*)&ip6h
[1] > mp
->b_wptr
)
772 if (!ip_hdr_length_nexthdr_v6(mp
, ip6h
, &hdr_length
, &nexthdrp
))
776 /* Set message type, must be done after pullups */
777 mp
->b_datap
->db_type
= M_CTL
;
779 /* Try to pass the ICMP message to clients who need it */
783 * Verify we have at least ICMP_MIN_TP_HDR_LEN bytes of
784 * UDP header to get the port information.
786 if ((uchar_t
*)ip6h
+ hdr_length
+ ICMP_MIN_TP_HDR_LEN
>
791 * Attempt to find a client stream based on port.
792 * Note that we do a reverse lookup since the header is
793 * in the form we sent it out.
794 * The rip6h header is only used for the IPCL_UDP_MATCH_V6
795 * and we only set the src and dst addresses and nexthdr.
797 up
= (uint16_t *)((uchar_t
*)ip6h
+ hdr_length
);
798 rip6h
.ip6_src
= ip6h
->ip6_dst
;
799 rip6h
.ip6_dst
= ip6h
->ip6_src
;
800 rip6h
.ip6_nxt
= nexthdr
;
801 ((uint16_t *)&ports
)[0] = up
[1];
802 ((uint16_t *)&ports
)[1] = up
[0];
804 ip_fanout_udp_v6(q
, first_mp
, &rip6h
, ports
, ill
, inill
,
805 IP6_NO_IPPOLICY
, mctl_present
, zoneid
);
810 * Verify we have at least ICMP_MIN_TP_HDR_LEN bytes of
811 * the TCP header to get the port information.
813 if ((uchar_t
*)ip6h
+ hdr_length
+ ICMP_MIN_TP_HDR_LEN
>
819 * Attempt to find a client stream based on port.
820 * Note that we do a reverse lookup since the header is
821 * in the form we sent it out.
822 * The rip6h header is only used for the IP_TCP_*MATCH_V6 and
823 * we only set the src and dst addresses and nexthdr.
826 tcpha
= (tcpha_t
*)((char *)ip6h
+ hdr_length
);
827 connp
= ipcl_tcp_lookup_reversed_ipv6(ip6h
, tcpha
,
828 TCPS_LISTEN
, ill
->ill_phyint
->phyint_ifindex
, ipst
);
833 SQUEUE_ENTER_ONE(connp
->conn_sqp
, first_mp
, tcp_input
, connp
,
834 SQ_FILL
, SQTAG_TCP6_INPUT_ICMP_ERR
);
840 * Verify we have at least ICMP_MIN_TP_HDR_LEN bytes of
841 * the SCTP header to get the port information.
843 if ((uchar_t
*)ip6h
+ hdr_length
+ ICMP_MIN_TP_HDR_LEN
>
848 up
= (uint16_t *)((uchar_t
*)ip6h
+ hdr_length
);
849 ((uint16_t *)&ports
)[0] = up
[1];
850 ((uint16_t *)&ports
)[1] = up
[0];
851 ip_fanout_sctp(first_mp
, inill
, (ipha_t
*)ip6h
, ports
, 0,
852 mctl_present
, IP6_NO_IPPOLICY
, zoneid
);
857 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
860 * We need a IPSEC_IN in the front to fanout to AH/ESP.
861 * We will re-use the IPSEC_IN if it is already present as
862 * AH/ESP will not affect any fields in the IPSEC_IN for
863 * ICMP errors. If there is no IPSEC_IN, allocate a new
864 * one and attach it in the front.
868 * ip_fanout_proto_again converts the ICMP errors
869 * that come back from AH/ESP to M_DATA so that
870 * if it is non-AH/ESP and we do a pullupmsg in
871 * this function, it would work. Convert it back
872 * to M_CTL before we send up as this is a ICMP
873 * error. This could have been generated locally or
874 * by some router. Validate the inner IPSEC
877 * NOTE : ill_index is used by ip_fanout_proto_again
881 ii
->ipsec_in_ill_index
=
882 ill
->ill_phyint
->phyint_ifindex
;
883 ii
->ipsec_in_rill_index
=
884 inill
->ill_phyint
->phyint_ifindex
;
885 first_mp
->b_cont
->b_datap
->db_type
= M_CTL
;
888 * IPSEC_IN is not present. We attach a ipsec_in
889 * message and send up to IPSEC for validating
890 * and removing the IPSEC headers. Clear
891 * ipsec_in_secure so that when we return
892 * from IPSEC, we don't mistakenly think that this
893 * is a secure packet came from the network.
895 * NOTE : ill_index is used by ip_fanout_proto_again
898 ASSERT(first_mp
== mp
);
899 first_mp
= ipsec_in_alloc(B_FALSE
, ipst
->ips_netstack
);
901 if (first_mp
== NULL
) {
903 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
906 ii
= (ipsec_in_t
*)first_mp
->b_rptr
;
908 /* This is not a secure packet */
909 ii
->ipsec_in_secure
= B_FALSE
;
910 first_mp
->b_cont
= mp
;
911 mp
->b_datap
->db_type
= M_CTL
;
912 ii
->ipsec_in_ill_index
=
913 ill
->ill_phyint
->phyint_ifindex
;
914 ii
->ipsec_in_rill_index
=
915 inill
->ill_phyint
->phyint_ifindex
;
918 if (!ipsec_loaded(ipss
)) {
919 ip_proto_not_sup(q
, first_mp
, 0, zoneid
, ipst
);
923 if (nexthdr
== IPPROTO_ESP
)
924 ipsec_rc
= ipsecesp_icmp_error(first_mp
);
926 ipsec_rc
= ipsecah_icmp_error(first_mp
);
927 if (ipsec_rc
== IPSEC_STATUS_FAILED
)
930 ip_fanout_proto_again(first_mp
, ill
, inill
, NULL
);
935 if ((uint8_t *)ip6h
+ hdr_length
+
936 (nexthdr
== IPPROTO_ENCAP
? sizeof (ipha_t
) :
937 sizeof (ip6_t
)) > mp
->b_wptr
) {
941 if (nexthdr
== IPPROTO_ENCAP
||
943 &((ip6_t
*)(((uint8_t *)ip6h
) + hdr_length
))->ip6_src
,
946 &((ip6_t
*)(((uint8_t *)ip6h
) + hdr_length
))->ip6_dst
,
949 * For tunnels that have used IPsec protection,
950 * we need to adjust the MTU to take into account
951 * the IPsec overhead.
954 icmp6
->icmp6_mtu
= htonl(
955 ntohl(icmp6
->icmp6_mtu
) -
956 ipsec_in_extra_length(first_mp
));
959 * Self-encapsulated case. As in the ipv4 case,
960 * we need to strip the 2nd IP header. Since mp
961 * is already pulled-up, we can simply bcopy
962 * the 3rd header + data over the 2nd header.
965 ip6_t
*inner_ip6h
= (ip6_t
*)
966 ((uchar_t
*)ip6h
+ hdr_length
);
969 * Make sure we don't do recursion more than once.
971 if (!ip_hdr_length_nexthdr_v6(mp
, inner_ip6h
,
972 &unused_len
, &nexthdrp
) ||
973 *nexthdrp
== IPPROTO_IPV6
) {
978 * We are about to modify the packet. Make a copy if
979 * someone else has a reference to it.
981 if (DB_REF(mp
) > 1) {
983 uint16_t icmp6_offset
;
989 icmp6_offset
= (uint16_t)
990 ((uchar_t
*)icmp6
- mp
->b_rptr
);
994 icmp6
= (icmp6_t
*)(mp
->b_rptr
+ icmp6_offset
);
995 ip6h
= (ip6_t
*)&icmp6
[1];
996 inner_ip6h
= (ip6_t
*)
997 ((uchar_t
*)ip6h
+ hdr_length
);
1000 first_mp
->b_cont
= mp
;
1006 * Need to set db_type back to M_DATA before
1007 * refeeding mp into this function.
1009 DB_TYPE(mp
) = M_DATA
;
1012 * Copy the 3rd header + remaining data on top
1013 * of the 2nd header.
1015 bcopy(inner_ip6h
, ip6h
,
1016 mp
->b_wptr
- (uchar_t
*)inner_ip6h
);
1019 * Subtract length of the 2nd header.
1021 mp
->b_wptr
-= hdr_length
;
1024 * Now recurse, and see what I _really_ should be
1027 icmp_inbound_error_fanout_v6(q
, first_mp
,
1028 (ip6_t
*)mp
->b_rptr
, icmp6
, ill
, inill
,
1029 mctl_present
, zoneid
);
1035 * The rip6h header is only used for the lookup and we
1036 * only set the src and dst addresses and nexthdr.
1038 rip6h
.ip6_src
= ip6h
->ip6_dst
;
1039 rip6h
.ip6_dst
= ip6h
->ip6_src
;
1040 rip6h
.ip6_nxt
= nexthdr
;
1041 ip_fanout_proto_v6(q
, first_mp
, &rip6h
, ill
, inill
, nexthdr
, 0,
1042 IP6_NO_IPPOLICY
, mctl_present
, zoneid
);
1047 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInErrors
);
1048 ip1dbg(("icmp_inbound_error_fanout_v6: drop pkt\n"));
1053 * Process received IPv6 ICMP Redirect messages.
1057 icmp_redirect_v6(queue_t
*q
, mblk_t
*mp
, ill_t
*ill
)
1060 uint16_t hdr_length
;
1065 in6_addr_t
*src
, *dst
, *gateway
;
1070 boolean_t redirect_to_router
= B_FALSE
;
1073 iulp_t ulp_info
= { 0 };
1074 ill_t
*prev_ire_ill
;
1076 ip_stack_t
*ipst
= ill
->ill_ipst
;
1078 ip6h
= (ip6_t
*)mp
->b_rptr
;
1079 if (ip6h
->ip6_nxt
!= IPPROTO_ICMPV6
)
1080 hdr_length
= ip_hdr_length_v6(mp
, ip6h
);
1082 hdr_length
= IPV6_HDR_LEN
;
1084 rd
= (nd_redirect_t
*)&mp
->b_rptr
[hdr_length
];
1085 len
= mp
->b_wptr
- mp
->b_rptr
- hdr_length
;
1086 src
= &ip6h
->ip6_src
;
1087 dst
= &rd
->nd_rd_dst
;
1088 gateway
= &rd
->nd_rd_target
;
1090 /* Verify if it is a valid redirect */
1091 if (!IN6_IS_ADDR_LINKLOCAL(src
) ||
1092 (ip6h
->ip6_hops
!= IPV6_MAX_HOPS
) ||
1093 (rd
->nd_rd_code
!= 0) ||
1094 (len
< sizeof (nd_redirect_t
)) ||
1095 (IN6_IS_ADDR_V4MAPPED(dst
)) ||
1096 (IN6_IS_ADDR_MULTICAST(dst
))) {
1097 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInBadRedirects
);
1102 if (!(IN6_IS_ADDR_LINKLOCAL(gateway
) ||
1103 IN6_ARE_ADDR_EQUAL(gateway
, dst
))) {
1104 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInBadRedirects
);
1109 if (len
> sizeof (nd_redirect_t
)) {
1110 if (!ndp_verify_optlen((nd_opt_hdr_t
*)&rd
[1],
1111 len
- sizeof (nd_redirect_t
))) {
1112 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInBadRedirects
);
1118 if (!IN6_ARE_ADDR_EQUAL(gateway
, dst
)) {
1119 redirect_to_router
= B_TRUE
;
1120 nce_flags
|= NCE_F_ISROUTER
;
1123 /* ipif will be refreleased afterwards */
1124 ipif
= ipif_get_next_ipif(NULL
, ill
);
1131 * Verify that the IP source address of the redirect is
1132 * the same as the current first-hop router for the specified
1133 * ICMP destination address.
1134 * Also, Make sure we had a route for the dest in question and
1135 * that route was pointing to the old gateway (the source of the
1139 prev_ire
= ire_route_lookup_v6(dst
, 0, src
, 0, ipif
, NULL
, ALL_ZONES
,
1140 NULL
, MATCH_IRE_GW
| MATCH_IRE_ILL
| MATCH_IRE_DEFAULT
, ipst
);
1144 * the redirect was not from ourselves
1145 * old gateway is still directly reachable
1147 if (prev_ire
== NULL
||
1148 prev_ire
->ire_type
== IRE_LOCAL
) {
1149 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInBadRedirects
);
1153 prev_ire_ill
= ire_to_ill(prev_ire
);
1154 ASSERT(prev_ire_ill
!= NULL
);
1155 if (prev_ire_ill
->ill_flags
& ILLF_NONUD
)
1156 nce_flags
|= NCE_F_NONUD
;
1159 * Should we use the old ULP info to create the new gateway? From
1160 * a user's perspective, we should inherit the info so that it
1161 * is a "smooth" transition. If we do not do that, then new
1162 * connections going thru the new gateway will have no route metrics,
1163 * which is counter-intuitive to user. From a network point of
1164 * view, this may or may not make sense even though the new gateway
1165 * is still directly connected to us so the route metrics should not
1168 * But if the old ire_uinfo is not initialized, we do another
1169 * recursive lookup on the dest using the new gateway. There may
1170 * be a route to that. If so, use it to initialize the redirect
1173 if (prev_ire
->ire_uinfo
.iulp_set
) {
1174 bcopy(&prev_ire
->ire_uinfo
, &ulp_info
, sizeof (iulp_t
));
1175 } else if (redirect_to_router
) {
1177 * Only do the following if the redirection is really to
1183 tmp_ire
= ire_ftable_lookup_v6(dst
, 0, gateway
, 0, NULL
, &sire
,
1185 (MATCH_IRE_RECURSIVE
| MATCH_IRE_GW
| MATCH_IRE_DEFAULT
),
1188 bcopy(&sire
->ire_uinfo
, &ulp_info
, sizeof (iulp_t
));
1189 ASSERT(tmp_ire
!= NULL
);
1190 ire_refrele(tmp_ire
);
1192 } else if (tmp_ire
!= NULL
) {
1193 bcopy(&tmp_ire
->ire_uinfo
, &ulp_info
,
1195 ire_refrele(tmp_ire
);
1199 optlen
= mp
->b_wptr
- mp
->b_rptr
- hdr_length
- sizeof (nd_redirect_t
);
1200 opt
= (nd_opt_hdr_t
*)&rd
[1];
1201 opt
= ndp_get_option(opt
, optlen
, ND_OPT_TARGET_LINKADDR
);
1203 err
= ndp_lookup_then_add_v6(ill
,
1204 B_FALSE
, /* don't match across illgrp */
1205 (uchar_t
*)&opt
[1], /* Link layer address */
1207 &ipv6_all_ones
, /* prefix mask */
1208 &ipv6_all_zeros
, /* Mapping mask */
1219 * Check to see if link layer address has changed and
1220 * process the nce_state accordingly.
1222 ndp_process(nce
, (uchar_t
*)&opt
[1], 0, B_FALSE
);
1226 ip1dbg(("icmp_redirect_v6: NCE create failed %d\n",
1232 if (redirect_to_router
) {
1233 /* icmp_redirect_ok_v6() must have already verified this */
1234 ASSERT(IN6_IS_ADDR_LINKLOCAL(gateway
));
1237 * Create a Route Association. This will allow us to remember
1238 * a router told us to use the particular gateway.
1240 ire
= ire_create_v6(
1242 &ipv6_all_ones
, /* mask */
1243 &prev_ire
->ire_src_addr_v6
, /* source addr */
1244 gateway
, /* gateway addr */
1245 &prev_ire
->ire_max_frag
, /* max frag */
1246 NULL
, /* no src nce */
1254 (RTF_DYNAMIC
| RTF_GATEWAY
| RTF_HOST
),
1262 stq
= (ipif
->ipif_net_type
== IRE_IF_RESOLVER
)
1263 ? ipif
->ipif_rq
: ipif
->ipif_wq
;
1266 * Just create an on link entry, i.e. interface route.
1268 ire
= ire_create_v6(
1269 dst
, /* gateway == dst */
1270 &ipv6_all_ones
, /* mask */
1271 &prev_ire
->ire_src_addr_v6
, /* source addr */
1272 &ipv6_all_zeros
, /* gateway addr */
1273 &prev_ire
->ire_max_frag
, /* max frag */
1274 NULL
, /* no src nce */
1277 ipif
->ipif_net_type
, /* IF_[NO]RESOLVER */
1282 (RTF_DYNAMIC
| RTF_HOST
),
1289 /* Release reference from earlier ipif_get_next_ipif() */
1295 if (ire_add(&ire
, NULL
, NULL
, NULL
, B_FALSE
) == 0) {
1297 /* tell routing sockets that we received a redirect */
1298 ip_rts_change_v6(RTM_REDIRECT
,
1301 &ipv6_all_ones
, 0, &ire
->ire_src_addr_v6
,
1302 (RTF_DYNAMIC
| RTF_GATEWAY
| RTF_HOST
), 0,
1303 (RTA_DST
| RTA_GATEWAY
| RTA_NETMASK
| RTA_AUTHOR
), ipst
);
1306 * Delete any existing IRE_HOST type ires for this destination.
1307 * This together with the added IRE has the effect of
1308 * modifying an existing redirect.
1310 redir_ire
= ire_ftable_lookup_v6(dst
, 0, src
, IRE_HOST
,
1311 ire
->ire_ipif
, NULL
, ALL_ZONES
, 0, NULL
,
1312 (MATCH_IRE_GW
| MATCH_IRE_TYPE
| MATCH_IRE_ILL
), ipst
);
1314 ire_refrele(ire
); /* Held in ire_add_v6 */
1316 if (redir_ire
!= NULL
) {
1317 if (redir_ire
->ire_flags
& RTF_DYNAMIC
)
1318 ire_delete(redir_ire
);
1319 ire_refrele(redir_ire
);
1323 if (prev_ire
->ire_type
== IRE_CACHE
)
1324 ire_delete(prev_ire
);
1325 ire_refrele(prev_ire
);
1329 if (prev_ire
!= NULL
)
1330 ire_refrele(prev_ire
);
1335 ip_queue_to_ill_v6(queue_t
*q
, ip_stack_t
*ipst
)
1341 if (q
->q_next
!= NULL
) {
1342 ill
= (ill_t
*)q
->q_ptr
;
1343 if (ILL_CAN_LOOKUP(ill
))
1348 ill
= ill_lookup_on_name(ipif_loopback_name
, B_FALSE
, B_TRUE
,
1349 NULL
, NULL
, NULL
, NULL
, NULL
, ipst
);
1352 ip0dbg(("ip_queue_to_ill_v6: no ill\n"));
1357 * Assigns an appropriate source address to the packet.
1358 * If origdst is one of our IP addresses that use it as the source.
1359 * If the queue is an ill queue then select a source from that ill.
1360 * Otherwise pick a source based on a route lookup back to the origsrc.
1362 * src is the return parameter. Returns a pointer to src or NULL if failure.
1365 icmp_pick_source_v6(queue_t
*wq
, in6_addr_t
*origsrc
, in6_addr_t
*origdst
,
1366 in6_addr_t
*src
, zoneid_t zoneid
, ip_stack_t
*ipst
)
1372 ASSERT(!(wq
->q_flag
& QREADR
));
1373 if (wq
->q_next
!= NULL
) {
1374 ill
= (ill_t
*)wq
->q_ptr
;
1379 ire
= ire_route_lookup_v6(origdst
, 0, 0, (IRE_LOCAL
|IRE_LOOPBACK
),
1380 NULL
, NULL
, zoneid
, NULL
, (MATCH_IRE_TYPE
|MATCH_IRE_ZONEONLY
),
1383 /* Destined to one of our addresses */
1393 /* What is the route back to the original source? */
1394 ire
= ire_route_lookup_v6(origsrc
, 0, 0, 0,
1395 NULL
, NULL
, zoneid
, NULL
,
1396 (MATCH_IRE_DEFAULT
|MATCH_IRE_RECURSIVE
), ipst
);
1398 BUMP_MIB(&ipst
->ips_ip6_mib
, ipIfStatsOutNoRoutes
);
1401 ASSERT(ire
->ire_ipif
!= NULL
);
1402 ill
= ire
->ire_ipif
->ipif_ill
;
1405 ipif
= ipif_select_source_v6(ill
, origsrc
, B_FALSE
,
1406 IPV6_PREFER_SRC_DEFAULT
, zoneid
);
1408 *src
= ipif
->ipif_v6src_addr
;
1413 * Unusual case - can't find a usable source address to reach the
1414 * original source. Use what in the route to the source.
1416 ire
= ire_route_lookup_v6(origsrc
, 0, 0, 0,
1417 NULL
, NULL
, zoneid
, NULL
,
1418 (MATCH_IRE_DEFAULT
|MATCH_IRE_RECURSIVE
), ipst
);
1420 BUMP_MIB(&ipst
->ips_ip6_mib
, ipIfStatsOutNoRoutes
);
1423 ASSERT(ire
!= NULL
);
1424 *src
= ire
->ire_src_addr_v6
;
1430 * Build and ship an IPv6 ICMP message using the packet data in mp,
1431 * and the ICMP header pointed to by "stuff". (May be called as
1433 * Note: assumes that icmp_pkt_err_ok_v6 has been called to
1434 * verify that an icmp error packet can be sent.
1436 * If q is an ill write side queue (which is the case when packets
1437 * arrive from ip_rput) then ip_wput code will ensure that packets to
1438 * link-local destinations are sent out that ill.
1440 * If v6src_ptr is set use it as a source. Otherwise select a reasonable
1441 * source address (see above function).
1444 icmp_pkt_v6(queue_t
*q
, mblk_t
*mp
, void *stuff
, size_t len
,
1445 const in6_addr_t
*v6src_ptr
, boolean_t mctl_present
, zoneid_t zoneid
,
1459 ill
= ip_queue_to_ill_v6(q
, ipst
);
1469 * 1) a IPSEC_OUT, then this is caused by outbound
1470 * datagram originating on this host. IPSEC processing
1471 * may or may not have been done. Refer to comments above
1472 * icmp_inbound_error_fanout for details.
1474 * 2) a IPSEC_IN if we are generating a icmp_message
1475 * for an incoming datagram destined for us i.e called
1476 * from ip_fanout_send_icmp.
1481 mp
= ipsec_mp
->b_cont
;
1483 in
= (ipsec_info_t
*)ipsec_mp
->b_rptr
;
1484 ip6h
= (ip6_t
*)mp
->b_rptr
;
1486 ASSERT(in
->ipsec_info_type
== IPSEC_OUT
||
1487 in
->ipsec_info_type
== IPSEC_IN
);
1489 if (in
->ipsec_info_type
== IPSEC_IN
) {
1491 * Convert the IPSEC_IN to IPSEC_OUT.
1493 if (!ipsec_in_to_out(ipsec_mp
, NULL
, ip6h
)) {
1494 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
1499 ASSERT(in
->ipsec_info_type
== IPSEC_OUT
);
1500 io
= (ipsec_out_t
*)in
;
1502 * Clear out ipsec_out_proc_begin, so we do a fresh
1505 io
->ipsec_out_proc_begin
= B_FALSE
;
1509 * This is in clear. The icmp message we are building
1510 * here should go out in clear.
1513 ASSERT(mp
->b_datap
->db_type
== M_DATA
);
1514 ipsec_mp
= ipsec_in_alloc(B_FALSE
, ipst
->ips_netstack
);
1515 if (ipsec_mp
== NULL
) {
1517 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
1521 ii
= (ipsec_in_t
*)ipsec_mp
->b_rptr
;
1523 /* This is not a secure packet */
1524 ii
->ipsec_in_secure
= B_FALSE
;
1526 * For trusted extensions using a shared IP address we can
1527 * send using any zoneid.
1529 if (zoneid
== ALL_ZONES
)
1530 ii
->ipsec_in_zoneid
= GLOBAL_ZONEID
;
1532 ii
->ipsec_in_zoneid
= zoneid
;
1533 ipsec_mp
->b_cont
= mp
;
1534 ip6h
= (ip6_t
*)mp
->b_rptr
;
1536 * Convert the IPSEC_IN to IPSEC_OUT.
1538 if (!ipsec_in_to_out(ipsec_mp
, NULL
, ip6h
)) {
1539 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
1544 io
= (ipsec_out_t
*)ipsec_mp
->b_rptr
;
1546 if (v6src_ptr
!= NULL
) {
1549 if (icmp_pick_source_v6(q
, &ip6h
->ip6_src
, &ip6h
->ip6_dst
,
1550 &v6src
, zoneid
, ipst
) == NULL
) {
1556 v6dst
= ip6h
->ip6_src
;
1557 len_needed
= ipst
->ips_ipv6_icmp_return
- IPV6_HDR_LEN
- len
;
1558 msg_len
= msgdsize(mp
);
1559 if (msg_len
> len_needed
) {
1560 if (!adjmsg(mp
, len_needed
- msg_len
)) {
1561 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutErrors
);
1566 msg_len
= len_needed
;
1568 mp1
= allocb_tmpl(IPV6_HDR_LEN
+ len
, mp
);
1570 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutErrors
);
1578 ASSERT(ipsec_mp
->b_datap
->db_type
== M_CTL
&&
1579 io
->ipsec_out_type
== IPSEC_OUT
);
1580 ipsec_mp
->b_cont
= mp
;
1583 * Set ipsec_out_icmp_loopback so we can let the ICMP messages this
1584 * node generates be accepted in peace by all on-host destinations.
1585 * If we do NOT assume that all on-host destinations trust
1586 * self-generated ICMP messages, then rework here, ip.c, and spd.c.
1587 * (Look for ipsec_out_icmp_loopback).
1589 io
->ipsec_out_icmp_loopback
= B_TRUE
;
1591 ip6h
= (ip6_t
*)mp
->b_rptr
;
1592 mp1
->b_wptr
= (uchar_t
*)ip6h
+ (IPV6_HDR_LEN
+ len
);
1594 ip6h
->ip6_vcf
= IPV6_DEFAULT_VERS_AND_FLOW
;
1595 ip6h
->ip6_nxt
= IPPROTO_ICMPV6
;
1596 ip6h
->ip6_hops
= ipst
->ips_ipv6_def_hops
;
1597 ip6h
->ip6_dst
= v6dst
;
1598 ip6h
->ip6_src
= v6src
;
1599 msg_len
+= IPV6_HDR_LEN
+ len
;
1600 if (msg_len
> IP_MAXPACKET
+ IPV6_HDR_LEN
) {
1601 (void) adjmsg(mp
, IP_MAXPACKET
+ IPV6_HDR_LEN
- msg_len
);
1602 msg_len
= IP_MAXPACKET
+ IPV6_HDR_LEN
;
1604 ip6h
->ip6_plen
= htons((uint16_t)(msgdsize(mp
) - IPV6_HDR_LEN
));
1605 icmp6
= (icmp6_t
*)&ip6h
[1];
1606 bcopy(stuff
, (char *)icmp6
, len
);
1608 * Prepare for checksum by putting icmp length in the icmp
1609 * checksum field. The checksum is calculated in ip_wput_v6.
1611 icmp6
->icmp6_cksum
= ip6h
->ip6_plen
;
1612 if (icmp6
->icmp6_type
== ND_REDIRECT
) {
1613 ip6h
->ip6_hops
= IPV6_MAX_HOPS
;
1615 /* Send to V6 writeside put routine */
1620 * Update the output mib when ICMPv6 packets are sent.
1623 icmp_update_out_mib_v6(ill_t
*ill
, icmp6_t
*icmp6
)
1625 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutMsgs
);
1627 switch (icmp6
->icmp6_type
) {
1628 case ICMP6_DST_UNREACH
:
1629 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutDestUnreachs
);
1630 if (icmp6
->icmp6_code
== ICMP6_DST_UNREACH_ADMIN
)
1631 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutAdminProhibs
);
1634 case ICMP6_TIME_EXCEEDED
:
1635 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutTimeExcds
);
1638 case ICMP6_PARAM_PROB
:
1639 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutParmProblems
);
1642 case ICMP6_PACKET_TOO_BIG
:
1643 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutPktTooBigs
);
1646 case ICMP6_ECHO_REQUEST
:
1647 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutEchos
);
1650 case ICMP6_ECHO_REPLY
:
1651 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutEchoReplies
);
1654 case ND_ROUTER_SOLICIT
:
1655 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutRouterSolicits
);
1658 case ND_ROUTER_ADVERT
:
1659 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutRouterAdvertisements
);
1662 case ND_NEIGHBOR_SOLICIT
:
1663 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutNeighborSolicits
);
1666 case ND_NEIGHBOR_ADVERT
:
1667 BUMP_MIB(ill
->ill_icmp6_mib
,
1668 ipv6IfIcmpOutNeighborAdvertisements
);
1672 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutRedirects
);
1675 case MLD_LISTENER_QUERY
:
1676 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutGroupMembQueries
);
1679 case MLD_LISTENER_REPORT
:
1680 case MLD_V2_LISTENER_REPORT
:
1681 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutGroupMembResponses
);
1684 case MLD_LISTENER_REDUCTION
:
1685 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpOutGroupMembReductions
);
1691 * Check if it is ok to send an ICMPv6 error packet in
1692 * response to the IP packet in mp.
1693 * Free the message and return null if no
1694 * ICMP error packet should be sent.
1697 icmp_pkt_err_ok_v6(queue_t
*q
, mblk_t
*mp
,
1698 boolean_t llbcast
, boolean_t mcast_ok
, ip_stack_t
*ipst
)
1705 ip6h
= (ip6_t
*)mp
->b_rptr
;
1707 /* Check if source address uniquely identifies the host */
1709 if (IN6_IS_ADDR_MULTICAST(&ip6h
->ip6_src
) ||
1710 IN6_IS_ADDR_V4MAPPED(&ip6h
->ip6_src
) ||
1711 IN6_IS_ADDR_UNSPECIFIED(&ip6h
->ip6_src
)) {
1716 if (ip6h
->ip6_nxt
== IPPROTO_ICMPV6
) {
1717 size_t len_needed
= IPV6_HDR_LEN
+ ICMP6_MINLEN
;
1720 if (mp
->b_wptr
- mp
->b_rptr
< len_needed
) {
1721 if (!pullupmsg(mp
, len_needed
)) {
1724 ill
= ip_queue_to_ill_v6(q
, ipst
);
1726 BUMP_MIB(&ipst
->ips_icmp6_mib
,
1727 ipv6IfIcmpInErrors
);
1729 BUMP_MIB(ill
->ill_icmp6_mib
,
1730 ipv6IfIcmpInErrors
);
1736 ip6h
= (ip6_t
*)mp
->b_rptr
;
1738 icmp6
= (icmp6_t
*)&ip6h
[1];
1739 /* Explicitly do not generate errors in response to redirects */
1740 if (ICMP6_IS_ERROR(icmp6
->icmp6_type
) ||
1741 icmp6
->icmp6_type
== ND_REDIRECT
) {
1747 * Check that the destination is not multicast and that the packet
1748 * was not sent on link layer broadcast or multicast. (Exception
1749 * is Packet too big message as per the draft - when mcast_ok is set.)
1752 (llbcast
|| IN6_IS_ADDR_MULTICAST(&ip6h
->ip6_dst
))) {
1756 if (icmp_err_rate_limit(ipst
)) {
1758 * Only send ICMP error packets every so often.
1759 * This should be done on a per port/source basis,
1760 * but for now this will suffice.
1769 * Generate an ICMPv6 redirect message.
1770 * Include target link layer address option if it exits.
1771 * Always include redirect header.
1774 icmp_send_redirect_v6(queue_t
*q
, mblk_t
*mp
, in6_addr_t
*targetp
,
1775 in6_addr_t
*dest
, ill_t
*ill
, boolean_t llbcast
)
1778 nd_opt_rd_hdr_t
*rdh
;
1784 int max_redir_hdr_data_len
;
1787 ip_stack_t
*ipst
= ill
->ill_ipst
;
1790 * We are called from ip_rput where we could
1791 * not have attached an IPSEC_IN.
1793 ASSERT(mp
->b_datap
->db_type
== M_DATA
);
1795 mp
= icmp_pkt_err_ok_v6(q
, mp
, llbcast
, B_FALSE
, ipst
);
1798 nce
= ndp_lookup_v6(ill
, B_TRUE
, targetp
, B_FALSE
);
1799 if (nce
!= NULL
&& nce
->nce_state
!= ND_INCOMPLETE
) {
1800 ll_opt_len
= (sizeof (nd_opt_hdr_t
) +
1801 ill
->ill_phys_addr_length
+ 7)/8 * 8;
1803 len
= sizeof (nd_redirect_t
) + sizeof (nd_opt_rd_hdr_t
) + ll_opt_len
;
1804 ASSERT(len
% 4 == 0);
1805 buf
= kmem_alloc(len
, KM_NOSLEEP
);
1813 rd
= (nd_redirect_t
*)buf
;
1814 rd
->nd_rd_type
= (uint8_t)ND_REDIRECT
;
1816 rd
->nd_rd_reserved
= 0;
1817 rd
->nd_rd_target
= *targetp
;
1818 rd
->nd_rd_dst
= *dest
;
1820 opt
= (nd_opt_hdr_t
*)(buf
+ sizeof (nd_redirect_t
));
1821 if (nce
!= NULL
&& ll_opt_len
!= 0) {
1822 opt
->nd_opt_type
= ND_OPT_TARGET_LINKADDR
;
1823 opt
->nd_opt_len
= ll_opt_len
/8;
1824 bcopy((char *)nce
->nce_res_mp
->b_rptr
+
1825 NCE_LL_ADDR_OFFSET(ill
), &opt
[1],
1826 ill
->ill_phys_addr_length
);
1830 rdh
= (nd_opt_rd_hdr_t
*)(buf
+ sizeof (nd_redirect_t
) + ll_opt_len
);
1831 rdh
->nd_opt_rh_type
= (uint8_t)ND_OPT_REDIRECTED_HEADER
;
1832 /* max_redir_hdr_data_len and nd_opt_rh_len must be multiple of 8 */
1833 max_redir_hdr_data_len
=
1834 (ipst
->ips_ipv6_icmp_return
- IPV6_HDR_LEN
- len
)/8*8;
1835 pkt_len
= msgdsize(mp
);
1836 /* Make sure mp is 8 byte aligned */
1837 if (pkt_len
> max_redir_hdr_data_len
) {
1838 rdh
->nd_opt_rh_len
= (max_redir_hdr_data_len
+
1839 sizeof (nd_opt_rd_hdr_t
))/8;
1840 (void) adjmsg(mp
, max_redir_hdr_data_len
- pkt_len
);
1842 rdh
->nd_opt_rh_len
= (pkt_len
+ sizeof (nd_opt_rd_hdr_t
))/8;
1843 (void) adjmsg(mp
, -(pkt_len
% 8));
1845 rdh
->nd_opt_rh_reserved1
= 0;
1846 rdh
->nd_opt_rh_reserved2
= 0;
1847 /* ipif_v6src_addr contains the link-local source address */
1848 srcp
= &ill
->ill_ipif
->ipif_v6src_addr
;
1850 /* Redirects sent by router, and router is global zone */
1851 icmp_pkt_v6(q
, mp
, buf
, len
, srcp
, B_FALSE
, GLOBAL_ZONEID
, ipst
);
1852 kmem_free(buf
, len
);
1856 /* Generate an ICMP time exceeded message. (May be called as writer.) */
1858 icmp_time_exceeded_v6(queue_t
*q
, mblk_t
*mp
, uint8_t code
,
1859 boolean_t llbcast
, boolean_t mcast_ok
, zoneid_t zoneid
,
1863 boolean_t mctl_present
;
1866 EXTRACT_PKT_MP(mp
, first_mp
, mctl_present
);
1868 mp
= icmp_pkt_err_ok_v6(q
, mp
, llbcast
, mcast_ok
, ipst
);
1874 bzero(&icmp6
, sizeof (icmp6_t
));
1875 icmp6
.icmp6_type
= ICMP6_TIME_EXCEEDED
;
1876 icmp6
.icmp6_code
= code
;
1877 icmp_pkt_v6(q
, first_mp
, &icmp6
, sizeof (icmp6_t
), NULL
, mctl_present
,
1882 * Generate an ICMP unreachable message.
1885 icmp_unreachable_v6(queue_t
*q
, mblk_t
*mp
, uint8_t code
,
1886 boolean_t llbcast
, boolean_t mcast_ok
, zoneid_t zoneid
,
1890 boolean_t mctl_present
;
1893 EXTRACT_PKT_MP(mp
, first_mp
, mctl_present
);
1895 mp
= icmp_pkt_err_ok_v6(q
, mp
, llbcast
, mcast_ok
, ipst
);
1901 bzero(&icmp6
, sizeof (icmp6_t
));
1902 icmp6
.icmp6_type
= ICMP6_DST_UNREACH
;
1903 icmp6
.icmp6_code
= code
;
1904 icmp_pkt_v6(q
, first_mp
, &icmp6
, sizeof (icmp6_t
), NULL
, mctl_present
,
1909 * Generate an ICMP pkt too big message.
1912 icmp_pkt2big_v6(queue_t
*q
, mblk_t
*mp
, uint32_t mtu
,
1913 boolean_t llbcast
, boolean_t mcast_ok
, zoneid_t zoneid
, ip_stack_t
*ipst
)
1917 boolean_t mctl_present
;
1919 EXTRACT_PKT_MP(mp
, first_mp
, mctl_present
);
1921 mp
= icmp_pkt_err_ok_v6(q
, mp
, llbcast
, mcast_ok
, ipst
);
1927 bzero(&icmp6
, sizeof (icmp6_t
));
1928 icmp6
.icmp6_type
= ICMP6_PACKET_TOO_BIG
;
1929 icmp6
.icmp6_code
= 0;
1930 icmp6
.icmp6_mtu
= htonl(mtu
);
1932 icmp_pkt_v6(q
, first_mp
, &icmp6
, sizeof (icmp6_t
), NULL
, mctl_present
,
1937 * Generate an ICMP parameter problem message. (May be called as writer.)
1938 * 'offset' is the offset from the beginning of the packet in error.
1941 icmp_param_problem_v6(queue_t
*q
, mblk_t
*mp
, uint8_t code
,
1942 uint32_t offset
, boolean_t llbcast
, boolean_t mcast_ok
, zoneid_t zoneid
,
1946 boolean_t mctl_present
;
1949 EXTRACT_PKT_MP(mp
, first_mp
, mctl_present
);
1951 mp
= icmp_pkt_err_ok_v6(q
, mp
, llbcast
, mcast_ok
, ipst
);
1957 bzero((char *)&icmp6
, sizeof (icmp6_t
));
1958 icmp6
.icmp6_type
= ICMP6_PARAM_PROB
;
1959 icmp6
.icmp6_code
= code
;
1960 icmp6
.icmp6_pptr
= htonl(offset
);
1961 icmp_pkt_v6(q
, first_mp
, &icmp6
, sizeof (icmp6_t
), NULL
, mctl_present
,
1966 * This code will need to take into account the possibility of binding
1967 * to a link local address on a multi-homed host, in which case the
1968 * outgoing interface (from the conn) will need to be used when getting
1969 * an ire for the dst. Going through proper outgoing interface and
1970 * choosing the source address corresponding to the outgoing interface
1971 * is necessary when the destination address is a link-local address and
1972 * IPV6_BOUND_IF or IPV6_PKTINFO or scope_id has been set.
1973 * This can happen when active connection is setup; thus ipp pointer
1974 * is passed here from tcp_connect_*() routines, in non-TCP cases NULL
1975 * pointer is passed as ipp pointer.
1978 ip_bind_v6(queue_t
*q
, mblk_t
*mp
, conn_t
*connp
, ip6_pkt_t
*ipp
)
1982 struct T_bind_req
*tbr
;
1991 boolean_t local_bind
;
1992 ipa6_conn_x_t
*acx6
;
1993 boolean_t verify_dst
;
1994 ip_stack_t
*ipst
= connp
->conn_netstack
->netstack_ip
;
1998 * All Solaris components should pass a db_credp
1999 * for this TPI message, hence we ASSERT.
2000 * But in case there is some other M_PROTO that looks
2001 * like a TPI message sent by some other kernel
2002 * component, we check and return an error.
2004 cr
= msg_getcred(mp
, NULL
);
2011 ASSERT(connp
->conn_af_isv6
);
2012 len
= mp
->b_wptr
- mp
->b_rptr
;
2013 if (len
< (sizeof (*tbr
) + 1)) {
2014 (void) mi_strlog(q
, 1, SL_ERROR
|SL_TRACE
,
2015 "ip_bind_v6: bogus msg, len %ld", len
);
2018 /* Back up and extract the protocol identifier. */
2020 tbr
= (struct T_bind_req
*)mp
->b_rptr
;
2021 /* Reset the message type in preparation for shipping it back. */
2022 mp
->b_datap
->db_type
= M_PCPROTO
;
2024 protocol
= *mp
->b_wptr
& 0xFF;
2025 connp
->conn_ulp
= (uint8_t)protocol
;
2028 * Check for a zero length address. This is from a protocol that
2029 * wants to register to receive all packets of its type.
2031 if (tbr
->ADDR_length
== 0) {
2032 if ((protocol
== IPPROTO_TCP
|| protocol
== IPPROTO_SCTP
||
2033 protocol
== IPPROTO_ESP
|| protocol
== IPPROTO_AH
) &&
2034 ipst
->ips_ipcl_proto_fanout_v6
[protocol
].connf_head
!=
2037 * TCP, SCTP, AH, and ESP have single protocol fanouts.
2038 * Do not allow others to bind to these.
2045 * The udp module never sends down a zero-length address,
2046 * and allowing this on a labeled system will break MLP
2049 if (is_system_labeled() && protocol
== IPPROTO_UDP
)
2052 /* Allow ipsec plumbing */
2053 if (connp
->conn_mac_exempt
&& protocol
!= IPPROTO_AH
&&
2054 protocol
!= IPPROTO_ESP
)
2057 connp
->conn_srcv6
= ipv6_all_zeros
;
2058 ipcl_proto_insert_v6(connp
, protocol
);
2060 tbr
->PRIM_type
= T_BIND_ACK
;
2064 /* Extract the address pointer from the message. */
2065 ucp
= (uchar_t
*)mi_offset_param(mp
, tbr
->ADDR_offset
,
2068 ip1dbg(("ip_bind_v6: no address\n"));
2071 if (!OK_32PTR(ucp
)) {
2072 ip1dbg(("ip_bind_v6: unaligned address\n"));
2076 switch (tbr
->ADDR_length
) {
2078 ip1dbg(("ip_bind_v6: bad address length %d\n",
2079 (int)tbr
->ADDR_length
));
2083 /* Verification of local address only */
2084 v6srcp
= (in6_addr_t
*)ucp
;
2086 local_bind
= B_TRUE
;
2089 case sizeof (sin6_t
):
2090 sin6
= (sin6_t
*)ucp
;
2091 v6srcp
= &sin6
->sin6_addr
;
2092 lport
= sin6
->sin6_port
;
2093 local_bind
= B_TRUE
;
2096 case sizeof (ipa6_conn_t
):
2098 * Verify that both the source and destination addresses
2101 ac6
= (ipa6_conn_t
*)ucp
;
2102 v6srcp
= &ac6
->ac6_laddr
;
2103 v6dstp
= &ac6
->ac6_faddr
;
2104 fport
= ac6
->ac6_fport
;
2105 /* For raw socket, the local port is not set. */
2106 lport
= ac6
->ac6_lport
!= 0 ? ac6
->ac6_lport
:
2108 local_bind
= B_FALSE
;
2109 /* Always verify destination reachability. */
2110 verify_dst
= B_TRUE
;
2113 case sizeof (ipa6_conn_x_t
):
2115 * Verify that the source address is valid.
2117 acx6
= (ipa6_conn_x_t
*)ucp
;
2118 ac6
= &acx6
->ac6x_conn
;
2119 v6srcp
= &ac6
->ac6_laddr
;
2120 v6dstp
= &ac6
->ac6_faddr
;
2121 fport
= ac6
->ac6_fport
;
2122 lport
= ac6
->ac6_lport
;
2123 local_bind
= B_FALSE
;
2125 * Client that passed ipa6_conn_x_t to us specifies whether to
2126 * verify destination reachability.
2128 verify_dst
= (acx6
->ac6x_flags
& ACX_VERIFY_DST
) != 0;
2132 error
= ip_proto_bind_laddr_v6(connp
, &mp
->b_cont
, protocol
,
2133 v6srcp
, lport
, tbr
->ADDR_length
!= IPV6_ADDR_LEN
);
2135 error
= ip_proto_bind_connected_v6(connp
, &mp
->b_cont
, protocol
,
2136 v6srcp
, lport
, v6dstp
, ipp
, fport
, B_TRUE
, verify_dst
, cr
);
2141 mp
->b_datap
->db_type
= M_PCPROTO
;
2142 tbr
->PRIM_type
= T_BIND_ACK
;
2147 ASSERT(error
!= EINPROGRESS
);
2149 mp
= mi_tpi_err_ack_alloc(mp
, TSYSERR
, error
);
2151 mp
= mi_tpi_err_ack_alloc(mp
, TBADADDR
, 0);
2156 ip_bind_post_handling_v6(conn_t
*connp
, mblk_t
*mp
,
2157 boolean_t version_changed
, boolean_t ire_requested
, ip_stack_t
*ipst
)
2159 /* Update conn_send and pktversion if v4/v6 changed */
2160 if (version_changed
) {
2161 ip_setpktversion(connp
, connp
->conn_pkt_isv6
, B_TRUE
, ipst
);
2165 * Pass the IPSEC headers size in ire_ipsec_overhead.
2166 * We can't do this in ip_bind_insert_ire because the policy
2167 * may not have been inherited at that point in time and hence
2168 * conn_out_enforce_policy may not be set.
2170 if (ire_requested
&& connp
->conn_out_enforce_policy
&&
2171 mp
!= NULL
&& DB_TYPE(mp
) == IRE_DB_REQ_TYPE
) {
2172 ire_t
*ire
= (ire_t
*)mp
->b_rptr
;
2173 ASSERT(MBLKL(mp
) >= sizeof (ire_t
));
2174 ire
->ire_ipsec_overhead
= (conn_ipsec_length(connp
));
2179 * Here address is verified to be a valid local address.
2180 * If the IRE_DB_REQ_TYPE mp is present, a multicast
2181 * address is also considered a valid local address.
2182 * In the case of a multicast address, however, the
2183 * upper protocol is expected to reset the src address
2184 * to 0 if it sees an ire with IN6_IS_ADDR_MULTICAST returned so that
2185 * no packets are emitted with multicast address as
2187 * The addresses valid for bind are:
2189 * (2) - IP address of an UP interface
2190 * (3) - IP address of a DOWN interface
2191 * (4) - a multicast address. In this case
2192 * the conn will only receive packets destined to
2193 * the specified multicast address. Note: the
2194 * application still has to issue an
2195 * IPV6_JOIN_GROUP socket option.
2197 * In all the above cases, the bound address must be valid in the current zone.
2198 * When the address is loopback or multicast, there might be many matching IREs
2199 * so bind has to look up based on the zone.
2202 * Verify the local IP address. Does not change the conn_t except
2203 * conn_fully_bound and conn_policy_cached.
2206 ip_bind_laddr_v6(conn_t
*connp
, mblk_t
**mpp
, uint8_t protocol
,
2207 const in6_addr_t
*v6src
, uint16_t lport
, boolean_t fanout_insert
)
2210 ire_t
*src_ire
= NULL
;
2213 boolean_t ire_requested
;
2214 boolean_t ipsec_policy_set
;
2215 ip_stack_t
*ipst
= connp
->conn_netstack
->netstack_ip
;
2220 ire_requested
= (mp
!= NULL
&& DB_TYPE(mp
) == IRE_DB_REQ_TYPE
);
2221 ipsec_policy_set
= (mp
!= NULL
&& DB_TYPE(mp
) == IPSEC_POLICY_SET
);
2224 * If it was previously connected, conn_fully_bound would have
2227 connp
->conn_fully_bound
= B_FALSE
;
2229 zoneid
= connp
->conn_zoneid
;
2231 if (!IN6_IS_ADDR_UNSPECIFIED(v6src
)) {
2232 src_ire
= ire_route_lookup_v6(v6src
, 0, 0,
2233 0, NULL
, NULL
, zoneid
, NULL
, MATCH_IRE_ZONEONLY
, ipst
);
2235 * If an address other than in6addr_any is requested,
2236 * we verify that it is a valid address for bind
2237 * Note: Following code is in if-else-if form for
2238 * readability compared to a condition check.
2240 ASSERT(src_ire
== NULL
|| !(src_ire
->ire_type
& IRE_BROADCAST
));
2241 /* LINTED - statement has no consequent */
2242 if (IRE_IS_LOCAL(src_ire
)) {
2244 * (2) Bind to address of local UP interface
2246 } else if (IN6_IS_ADDR_MULTICAST(v6src
)) {
2247 ipif_t
*multi_ipif
= NULL
;
2250 * (4) bind to multicast address.
2251 * Fake out the IRE returned to upper
2252 * layer to be a broadcast IRE in
2253 * ip_bind_insert_ire_v6().
2254 * Pass other information that matches
2255 * the ipif (e.g. the source address).
2256 * conn_multicast_ill is only used for
2259 mutex_enter(&connp
->conn_lock
);
2260 if (connp
->conn_multicast_ill
!= NULL
) {
2261 (void) ipif_lookup_zoneid(
2262 connp
->conn_multicast_ill
, zoneid
, 0,
2266 * Look for default like
2269 multi_ipif
= ipif_lookup_group_v6(
2270 &ipv6_unspecified_group
, zoneid
, ipst
);
2272 mutex_exit(&connp
->conn_lock
);
2275 if (multi_ipif
== NULL
|| !ire_requested
||
2276 (src_ire
= ipif_to_ire_v6(multi_ipif
)) == NULL
) {
2278 error
= EADDRNOTAVAIL
;
2280 ASSERT(src_ire
!= NULL
);
2281 if (save_ire
!= NULL
)
2282 ire_refrele(save_ire
);
2284 if (multi_ipif
!= NULL
)
2285 ipif_refrele(multi_ipif
);
2287 if (!ip_addr_exists_v6(v6src
, zoneid
, ipst
)) {
2289 * Not a valid address for bind
2291 error
= EADDRNOTAVAIL
;
2296 /* Red Alert! Attempting to be a bogon! */
2299 pr_addr_dbg("ip_bind_laddr_v6: bad src"
2300 " address %s\n", AF_INET6
, v6src
);
2307 * Allow setting new policies. For example, disconnects come
2308 * down as ipa_t bind. As we would have set conn_policy_cached
2309 * to B_TRUE before, we should set it to B_FALSE, so that policy
2310 * can change after the disconnect.
2312 connp
->conn_policy_cached
= B_FALSE
;
2314 /* If not fanout_insert this was just an address verification */
2315 if (fanout_insert
) {
2317 * The addresses have been verified. Time to insert in
2318 * the correct fanout list.
2320 connp
->conn_srcv6
= *v6src
;
2321 connp
->conn_remv6
= ipv6_all_zeros
;
2322 connp
->conn_lport
= lport
;
2323 connp
->conn_fport
= 0;
2324 error
= ipcl_bind_insert_v6(connp
, protocol
, v6src
, lport
);
2327 if (ire_requested
) {
2328 if (!ip_bind_get_ire_v6(mpp
, src_ire
, v6src
, NULL
,
2334 } else if (ipsec_policy_set
) {
2335 if (!ip_bind_ipsec_policy_set(connp
, mp
)) {
2343 if (connp
->conn_anon_port
) {
2344 (void) tsol_mlp_anon(crgetzone(connp
->conn_cred
),
2345 connp
->conn_mlp_type
, connp
->conn_ulp
, ntohs(lport
),
2348 connp
->conn_mlp_type
= mlptSingle
;
2351 if (src_ire
!= NULL
)
2352 ire_refrele(src_ire
);
2354 if (ipsec_policy_set
) {
2358 * As of now assume that nothing else accompanies
2367 ip_proto_bind_laddr_v6(conn_t
*connp
, mblk_t
**mpp
, uint8_t protocol
,
2368 const in6_addr_t
*v6srcp
, uint16_t lport
, boolean_t fanout_insert
)
2371 boolean_t ire_requested
;
2373 boolean_t orig_pkt_isv6
= connp
->conn_pkt_isv6
;
2374 ip_stack_t
*ipst
= connp
->conn_netstack
->netstack_ip
;
2377 * Note that we allow connect to broadcast and multicast
2378 * address when ire_requested is set. Thus the ULP
2379 * has to check for IRE_BROADCAST and multicast.
2383 ire_requested
= (mp
&& DB_TYPE(mp
) == IRE_DB_REQ_TYPE
);
2385 ASSERT(connp
->conn_af_isv6
);
2386 connp
->conn_ulp
= protocol
;
2388 if (IN6_IS_ADDR_V4MAPPED(v6srcp
) && !connp
->conn_ipv6_v6only
) {
2389 /* Bind to IPv4 address */
2392 IN6_V4MAPPED_TO_IPADDR(v6srcp
, v4src
);
2394 error
= ip_bind_laddr_v4(connp
, mpp
, protocol
, v4src
, lport
,
2398 connp
->conn_pkt_isv6
= B_FALSE
;
2400 if (IN6_IS_ADDR_V4MAPPED(v6srcp
)) {
2404 error
= ip_bind_laddr_v6(connp
, mpp
, protocol
, v6srcp
,
2405 lport
, fanout_insert
);
2408 connp
->conn_pkt_isv6
= B_TRUE
;
2411 ip_bind_post_handling_v6(connp
, mpp
? *mpp
: NULL
,
2412 orig_pkt_isv6
!= connp
->conn_pkt_isv6
, ire_requested
, ipst
);
2422 * Verify that both the source and destination addresses
2423 * are valid. If verify_dst, then destination address must also be reachable,
2424 * i.e. have a route. Protocols like TCP want this. Tunnels do not.
2425 * It takes ip6_pkt_t * as one of the arguments to determine correct
2426 * source address when IPV6_PKTINFO or scope_id is set along with a link-local
2427 * destination address. Note that parameter ipp is only useful for TCP connect
2428 * when scope_id is set or IPV6_PKTINFO option is set with an ifindex. For all
2429 * non-TCP cases, it is NULL and for all other tcp cases it is not useful.
2433 ip_bind_connected_v6(conn_t
*connp
, mblk_t
**mpp
, uint8_t protocol
,
2434 in6_addr_t
*v6src
, uint16_t lport
, const in6_addr_t
*v6dst
,
2435 ip6_pkt_t
*ipp
, uint16_t fport
, boolean_t fanout_insert
,
2436 boolean_t verify_dst
, cred_t
*cr
)
2442 ire_t
*md_dst_ire
= NULL
;
2443 ill_t
*md_ill
= NULL
;
2444 ill_t
*dst_ill
= NULL
;
2445 ipif_t
*src_ipif
= NULL
;
2447 boolean_t ill_held
= B_FALSE
;
2449 boolean_t ire_requested
= B_FALSE
;
2450 boolean_t ipsec_policy_set
= B_FALSE
;
2451 ip_stack_t
*ipst
= connp
->conn_netstack
->netstack_ip
;
2452 ts_label_t
*tsl
= NULL
;
2458 ire_requested
= (DB_TYPE(mp
) == IRE_DB_REQ_TYPE
);
2459 ipsec_policy_set
= (DB_TYPE(mp
) == IPSEC_POLICY_SET
);
2462 tsl
= crgetlabel(cr
);
2464 src_ire
= dst_ire
= NULL
;
2466 * If we never got a disconnect before, clear it now.
2468 connp
->conn_fully_bound
= B_FALSE
;
2470 zoneid
= connp
->conn_zoneid
;
2472 if (IN6_IS_ADDR_MULTICAST(v6dst
)) {
2476 * Use an "emulated" IRE_BROADCAST to tell the transport it
2478 * Pass other information that matches
2479 * the ipif (e.g. the source address).
2481 * conn_multicast_ill is only used for IPv6 packets
2483 mutex_enter(&connp
->conn_lock
);
2484 if (connp
->conn_multicast_ill
!= NULL
) {
2485 (void) ipif_lookup_zoneid(connp
->conn_multicast_ill
,
2488 /* Look for default like ip_wput_v6 */
2489 ipif
= ipif_lookup_group_v6(v6dst
, zoneid
, ipst
);
2491 mutex_exit(&connp
->conn_lock
);
2492 if (ipif
== NULL
|| ire_requested
||
2493 (dst_ire
= ipif_to_ire_v6(ipif
)) == NULL
) {
2498 pr_addr_dbg("ip_bind_connected_v6: bad "
2499 "connected multicast %s\n", AF_INET6
,
2502 error
= ENETUNREACH
;
2508 dst_ire
= ire_route_lookup_v6(v6dst
, NULL
, NULL
, 0,
2509 NULL
, &sire
, zoneid
, tsl
,
2510 MATCH_IRE_RECURSIVE
| MATCH_IRE_DEFAULT
|
2511 MATCH_IRE_PARENT
| MATCH_IRE_RJ_BHOLE
| MATCH_IRE_SECATTR
,
2514 * We also prevent ire's with src address INADDR_ANY to
2515 * be used, which are created temporarily for
2516 * sending out packets from endpoints that have
2517 * conn_unspec_src set.
2519 if (dst_ire
== NULL
||
2520 (dst_ire
->ire_flags
& (RTF_REJECT
|RTF_BLACKHOLE
)) ||
2521 IN6_IS_ADDR_UNSPECIFIED(&dst_ire
->ire_src_addr_v6
)) {
2523 * When verifying destination reachability, we always
2526 * When not verifying destination reachability but we
2527 * found an IRE, i.e. the destination is reachable,
2528 * then the other tests still apply and we complain.
2530 if (verify_dst
|| (dst_ire
!= NULL
)) {
2533 pr_addr_dbg("ip_bind_connected_v6: bad"
2534 " connected dst %s\n", AF_INET6
,
2537 if (dst_ire
== NULL
||
2538 !(dst_ire
->ire_type
& IRE_HOST
)) {
2539 error
= ENETUNREACH
;
2541 error
= EHOSTUNREACH
;
2549 * We now know that routing will allow us to reach the destination.
2550 * Check whether Trusted Solaris policy allows communication with this
2551 * host, and pretend that the destination is unreachable if not.
2553 * This is never a problem for TCP, since that transport is known to
2554 * compute the label properly as part of the tcp_rput_other T_BIND_ACK
2555 * handling. If the remote is unreachable, it will be detected at that
2556 * point, so there's no reason to check it here.
2558 * Note that for sendto (and other datagram-oriented friends), this
2559 * check is done as part of the data path label computation instead.
2560 * The check here is just to make non-TCP connect() report the right
2563 if (dst_ire
!= NULL
&& is_system_labeled() &&
2564 !IPCL_IS_TCP(connp
) &&
2565 tsol_compute_label_v6(cr
, v6dst
, NULL
,
2566 connp
->conn_mac_exempt
, ipst
) != 0) {
2567 error
= EHOSTUNREACH
;
2569 pr_addr_dbg("ip_bind_connected: no label for dst %s\n",
2576 * If the app does a connect(), it means that it will most likely
2577 * send more than 1 packet to the destination. It makes sense
2578 * to clear the temporary flag.
2580 if (dst_ire
!= NULL
&& dst_ire
->ire_type
== IRE_CACHE
&&
2581 (dst_ire
->ire_marks
& IRE_MARK_TEMPORARY
)) {
2582 irb_t
*irb
= dst_ire
->ire_bucket
;
2584 rw_enter(&irb
->irb_lock
, RW_WRITER
);
2586 * We need to recheck for IRE_MARK_TEMPORARY after acquiring
2587 * the lock in order to guarantee irb_tmp_ire_cnt.
2589 if (dst_ire
->ire_marks
& IRE_MARK_TEMPORARY
) {
2590 dst_ire
->ire_marks
&= ~IRE_MARK_TEMPORARY
;
2591 irb
->irb_tmp_ire_cnt
--;
2593 rw_exit(&irb
->irb_lock
);
2596 ASSERT(dst_ire
== NULL
|| dst_ire
->ire_ipversion
== IPV6_VERSION
);
2599 * See if we should notify ULP about MDT; we do this whether or not
2600 * ire_requested is TRUE, in order to handle active connects; MDT
2601 * eligibility tests for passive connects are handled separately
2602 * through tcp_adapt_ire(). We do this before the source address
2603 * selection, because dst_ire may change after a call to
2604 * ipif_select_source_v6(). This is a best-effort check, as the
2605 * packet for this connection may not actually go through
2606 * dst_ire->ire_stq, and the exact IRE can only be known after
2607 * calling ip_newroute_v6(). This is why we further check on the
2608 * IRE during Multidata packet transmission in tcp_multisend().
2610 if (ipst
->ips_ip_multidata_outbound
&& !ipsec_policy_set
&&
2612 !(dst_ire
->ire_type
& (IRE_LOCAL
| IRE_LOOPBACK
| IRE_BROADCAST
)) &&
2613 (md_ill
= ire_to_ill(dst_ire
), md_ill
!= NULL
) &&
2614 ILL_MDT_CAPABLE(md_ill
)) {
2615 md_dst_ire
= dst_ire
;
2616 IRE_REFHOLD(md_dst_ire
);
2619 if (dst_ire
!= NULL
&&
2620 dst_ire
->ire_type
== IRE_LOCAL
&&
2621 dst_ire
->ire_zoneid
!= zoneid
&&
2622 dst_ire
->ire_zoneid
!= ALL_ZONES
) {
2623 src_ire
= ire_ftable_lookup_v6(v6dst
, 0, 0, 0, NULL
, NULL
,
2625 MATCH_IRE_RECURSIVE
| MATCH_IRE_DEFAULT
|
2626 MATCH_IRE_RJ_BHOLE
, ipst
);
2627 if (src_ire
== NULL
) {
2628 error
= EHOSTUNREACH
;
2630 } else if (src_ire
->ire_flags
& (RTF_REJECT
|RTF_BLACKHOLE
)) {
2631 if (!(src_ire
->ire_type
& IRE_HOST
))
2632 error
= ENETUNREACH
;
2634 error
= EHOSTUNREACH
;
2637 if (IN6_IS_ADDR_UNSPECIFIED(v6src
)) {
2638 src_ipif
= src_ire
->ire_ipif
;
2639 ipif_refhold(src_ipif
);
2640 *v6src
= src_ipif
->ipif_v6lcl_addr
;
2642 ire_refrele(src_ire
);
2644 } else if (IN6_IS_ADDR_UNSPECIFIED(v6src
) && dst_ire
!= NULL
) {
2645 if ((sire
!= NULL
) && (sire
->ire_flags
& RTF_SETSRC
)) {
2646 *v6src
= sire
->ire_src_addr_v6
;
2647 ire_refrele(dst_ire
);
2650 } else if (dst_ire
->ire_type
== IRE_CACHE
&&
2651 (dst_ire
->ire_flags
& RTF_SETSRC
)) {
2652 ASSERT(dst_ire
->ire_zoneid
== zoneid
||
2653 dst_ire
->ire_zoneid
== ALL_ZONES
);
2654 *v6src
= dst_ire
->ire_src_addr_v6
;
2657 * Pick a source address so that a proper inbound load
2658 * spreading would happen. Use dst_ill specified by the
2659 * app. when socket option or scopeid is set.
2663 if (ipp
!= NULL
&& ipp
->ipp_ifindex
!= 0) {
2667 * Scope id or IPV6_PKTINFO
2670 if_index
= ipp
->ipp_ifindex
;
2671 dst_ill
= ill_lookup_on_ifindex(
2672 if_index
, B_TRUE
, NULL
, NULL
, NULL
, NULL
,
2674 if (dst_ill
== NULL
) {
2675 ip1dbg(("ip_bind_connected_v6:"
2676 " bad ifindex %d\n", if_index
));
2677 error
= EADDRNOTAVAIL
;
2681 } else if (connp
->conn_outgoing_ill
!= NULL
) {
2683 * For IPV6_BOUND_IF socket option,
2684 * conn_outgoing_ill should be set
2685 * already in TCP or UDP/ICMP.
2687 dst_ill
= conn_get_held_ill(connp
,
2688 &connp
->conn_outgoing_ill
, &err
);
2689 if (err
== ILL_LOOKUP_FAILED
) {
2690 ip1dbg(("ip_bind_connected_v6:"
2691 "no ill for bound_if\n"));
2692 error
= EADDRNOTAVAIL
;
2696 } else if (dst_ire
->ire_stq
!= NULL
) {
2697 /* No need to hold ill here */
2698 dst_ill
= (ill_t
*)dst_ire
->ire_stq
->q_ptr
;
2700 /* No need to hold ill here */
2701 dst_ill
= dst_ire
->ire_ipif
->ipif_ill
;
2703 if (ip6_asp_can_lookup(ipst
)) {
2704 src_ipif
= ipif_select_source_v6(dst_ill
,
2705 v6dst
, B_FALSE
, connp
->conn_src_preferences
,
2707 ip6_asp_table_refrele(ipst
);
2708 if (src_ipif
== NULL
) {
2709 pr_addr_dbg("ip_bind_connected_v6: "
2710 "no usable source address for "
2711 "connection to %s\n",
2713 error
= EADDRNOTAVAIL
;
2716 *v6src
= src_ipif
->ipif_v6lcl_addr
;
2718 error
= EADDRNOTAVAIL
;
2725 * We do ire_route_lookup_v6() here (and not an interface lookup)
2726 * as we assert that v6src should only come from an
2727 * UP interface for hard binding.
2729 src_ire
= ire_route_lookup_v6(v6src
, 0, 0, 0, NULL
,
2730 NULL
, zoneid
, NULL
, MATCH_IRE_ZONEONLY
, ipst
);
2732 /* src_ire must be a local|loopback */
2733 if (!IRE_IS_LOCAL(src_ire
)) {
2736 pr_addr_dbg("ip_bind_connected_v6: bad "
2737 "connected src %s\n", AF_INET6
, v6src
);
2739 error
= EADDRNOTAVAIL
;
2744 * If the source address is a loopback address, the
2745 * destination had best be local or multicast.
2746 * The transports that can't handle multicast will reject
2749 if (src_ire
->ire_type
== IRE_LOOPBACK
&&
2750 !(IRE_IS_LOCAL(dst_ire
) || IN6_IS_ADDR_MULTICAST(v6dst
) ||
2751 IN6_IS_ADDR_V4MAPPED_CLASSD(v6dst
))) {
2752 ip1dbg(("ip_bind_connected_v6: bad connected loopback\n"));
2757 * Allow setting new policies. For example, disconnects come
2758 * down as ipa_t bind. As we would have set conn_policy_cached
2759 * to B_TRUE before, we should set it to B_FALSE, so that policy
2760 * can change after the disconnect.
2762 connp
->conn_policy_cached
= B_FALSE
;
2765 * The addresses have been verified. Initialize the conn
2766 * before calling the policy as they expect the conns
2769 connp
->conn_srcv6
= *v6src
;
2770 connp
->conn_remv6
= *v6dst
;
2771 connp
->conn_lport
= lport
;
2772 connp
->conn_fport
= fport
;
2774 ASSERT(!(ipsec_policy_set
&& ire_requested
));
2775 if (ire_requested
) {
2776 iulp_t
*ulp_info
= NULL
;
2779 * Note that sire will not be NULL if this is an off-link
2780 * connection and there is not cache for that dest yet.
2782 * XXX Because of an existing bug, if there are multiple
2783 * default routes, the IRE returned now may not be the actual
2784 * default route used (default routes are chosen in a
2785 * round robin fashion). So if the metrics for different
2786 * default routes are different, we may return the wrong
2787 * metrics. This will not be a problem if the existing
2791 ulp_info
= &(sire
->ire_uinfo
);
2793 if (!ip_bind_get_ire_v6(mpp
, dst_ire
, v6dst
, ulp_info
,
2798 } else if (ipsec_policy_set
) {
2799 if (!ip_bind_ipsec_policy_set(connp
, mp
)) {
2806 * Cache IPsec policy in this conn. If we have per-socket policy,
2807 * we'll cache that. If we don't, we'll inherit global policy.
2809 * We can't insert until the conn reflects the policy. Note that
2810 * conn_policy_cached is set by ipsec_conn_cache_policy() even for
2811 * connections where we don't have a policy. This is to prevent
2812 * global policy lookups in the inbound path.
2814 * If we insert before we set conn_policy_cached,
2815 * CONN_INBOUND_POLICY_PRESENT_V6() check can still evaluate true
2816 * because global policy cound be non-empty. We normally call
2817 * ipsec_check_policy() for conn_policy_cached connections only if
2818 * conn_in_enforce_policy is set. But in this case,
2819 * conn_policy_cached can get set anytime since we made the
2820 * CONN_INBOUND_POLICY_PRESENT_V6() check and ipsec_check_policy()
2821 * is called, which will make the above assumption false. Thus, we
2822 * need to insert after we set conn_policy_cached.
2824 if ((error
= ipsec_conn_cache_policy(connp
, B_FALSE
)) != 0)
2827 /* If not fanout_insert this was just an address verification */
2828 if (fanout_insert
) {
2830 * The addresses have been verified. Time to insert in
2831 * the correct fanout list.
2833 error
= ipcl_conn_insert_v6(connp
, protocol
, v6src
, v6dst
,
2835 IPCL_IS_TCP(connp
) ? connp
->conn_tcp
->tcp_bound_if
: 0);
2838 connp
->conn_fully_bound
= B_TRUE
;
2840 * Our initial checks for MDT have passed; the IRE is not
2841 * LOCAL/LOOPBACK/BROADCAST, and the link layer seems to
2842 * be supporting MDT. Pass the IRE, IPC and ILL into
2843 * ip_mdinfo_return(), which performs further checks
2844 * against them and upon success, returns the MDT info
2845 * mblk which we will attach to the bind acknowledgment.
2847 if (md_dst_ire
!= NULL
) {
2850 ASSERT(md_ill
!= NULL
);
2851 ASSERT(md_ill
->ill_mdt_capab
!= NULL
);
2852 if ((mdinfo_mp
= ip_mdinfo_return(md_dst_ire
, connp
,
2853 md_ill
->ill_name
, md_ill
->ill_mdt_capab
)) != NULL
) {
2857 linkb(mp
, mdinfo_mp
);
2863 if (ipsec_policy_set
) {
2867 * As of now assume that nothing else accompanies
2873 if (src_ire
!= NULL
)
2874 IRE_REFRELE(src_ire
);
2875 if (dst_ire
!= NULL
)
2876 IRE_REFRELE(dst_ire
);
2879 if (src_ipif
!= NULL
)
2880 ipif_refrele(src_ipif
);
2881 if (md_dst_ire
!= NULL
)
2882 IRE_REFRELE(md_dst_ire
);
2883 if (ill_held
&& dst_ill
!= NULL
)
2884 ill_refrele(dst_ill
);
2890 ip_proto_bind_connected_v6(conn_t
*connp
, mblk_t
**mpp
, uint8_t protocol
,
2891 in6_addr_t
*v6srcp
, uint16_t lport
, const in6_addr_t
*v6dstp
,
2892 ip6_pkt_t
*ipp
, uint16_t fport
, boolean_t fanout_insert
,
2893 boolean_t verify_dst
, cred_t
*cr
)
2896 boolean_t orig_pkt_isv6
= connp
->conn_pkt_isv6
;
2897 boolean_t ire_requested
;
2898 ip_stack_t
*ipst
= connp
->conn_netstack
->netstack_ip
;
2901 * Note that we allow connect to broadcast and multicast
2902 * address when ire_requested is set. Thus the ULP
2903 * has to check for IRE_BROADCAST and multicast.
2905 ASSERT(mpp
!= NULL
);
2906 ire_requested
= (*mpp
!= NULL
&& DB_TYPE(*mpp
) == IRE_DB_REQ_TYPE
);
2908 ASSERT(connp
->conn_af_isv6
);
2909 connp
->conn_ulp
= protocol
;
2911 /* For raw socket, the local port is not set. */
2912 lport
= lport
!= 0 ? lport
: connp
->conn_lport
;
2915 * Bind to local and remote address. Local might be
2916 * unspecified in which case it will be extracted from
2919 if (IN6_IS_ADDR_V4MAPPED(v6dstp
) && !connp
->conn_ipv6_v6only
) {
2920 /* Connect to IPv4 address */
2924 /* Is the source unspecified or mapped? */
2925 if (!IN6_IS_ADDR_V4MAPPED(v6srcp
) &&
2926 !IN6_IS_ADDR_UNSPECIFIED(v6srcp
)) {
2927 ip1dbg(("ip_proto_bind_connected_v6: "
2928 "dst is mapped, but not the src\n"));
2931 IN6_V4MAPPED_TO_IPADDR(v6srcp
, v4src
);
2932 IN6_V4MAPPED_TO_IPADDR(v6dstp
, v4dst
);
2934 /* Always verify destination reachability. */
2935 error
= ip_bind_connected_v4(connp
, mpp
, protocol
, &v4src
,
2936 lport
, v4dst
, fport
, B_TRUE
, B_TRUE
, cr
);
2939 IN6_IPADDR_TO_V4MAPPED(v4src
, v6srcp
);
2940 connp
->conn_pkt_isv6
= B_FALSE
;
2941 } else if (IN6_IS_ADDR_V4MAPPED(v6srcp
)) {
2942 ip1dbg(("ip_proto_bind_connected_v6: "
2943 "src is mapped, but not the dst\n"));
2946 error
= ip_bind_connected_v6(connp
, mpp
, protocol
, v6srcp
,
2947 lport
, v6dstp
, ipp
, fport
, B_TRUE
, verify_dst
, cr
);
2950 connp
->conn_pkt_isv6
= B_TRUE
;
2953 ip_bind_post_handling_v6(connp
, mpp
? *mpp
: NULL
,
2954 orig_pkt_isv6
!= connp
->conn_pkt_isv6
, ire_requested
, ipst
);
2966 * Get the ire in *mpp. Returns false if it fails (due to lack of space).
2967 * Makes the IRE be IRE_BROADCAST if dst is a multicast address.
2971 ip_bind_get_ire_v6(mblk_t
**mpp
, ire_t
*ire
, const in6_addr_t
*dst
,
2972 iulp_t
*ulp_info
, ip_stack_t
*ipst
)
2981 * mp initialized above to IRE_DB_REQ_TYPE
2982 * appended mblk. Its <upper protocol>'s
2983 * job to make sure there is room.
2985 if ((mp
->b_datap
->db_lim
- mp
->b_rptr
) < sizeof (ire_t
))
2988 mp
->b_datap
->db_type
= IRE_DB_TYPE
;
2989 mp
->b_wptr
= mp
->b_rptr
+ sizeof (ire_t
);
2990 bcopy(ire
, mp
->b_rptr
, sizeof (ire_t
));
2991 ret_ire
= (ire_t
*)mp
->b_rptr
;
2992 if (IN6_IS_ADDR_MULTICAST(dst
) ||
2993 IN6_IS_ADDR_V4MAPPED_CLASSD(dst
)) {
2994 ret_ire
->ire_type
= IRE_BROADCAST
;
2995 ret_ire
->ire_addr_v6
= *dst
;
2997 if (ulp_info
!= NULL
) {
2998 bcopy(ulp_info
, &(ret_ire
->ire_uinfo
),
3001 ret_ire
->ire_mp
= mp
;
3004 * No IRE was found. Remove IRE mblk.
3013 * Add an ip6i_t header to the front of the mblk.
3014 * Inline if possible else allocate a separate mblk containing only the ip6i_t.
3015 * Returns NULL if allocation fails (and frees original message).
3016 * Used in outgoing path when going through ip_newroute_*v6().
3017 * Used in incoming path to pass ifindex to transports.
3020 ip_add_info_v6(mblk_t
*mp
, ill_t
*ill
, const in6_addr_t
*dst
)
3026 ip6h
= (ip6_t
*)mp
->b_rptr
;
3027 ip6i
= (ip6i_t
*)(mp
->b_rptr
- sizeof (ip6i_t
));
3028 if ((uchar_t
*)ip6i
< mp
->b_datap
->db_base
||
3029 mp
->b_datap
->db_ref
> 1) {
3030 mp1
= allocb(sizeof (ip6i_t
), BPRI_MED
);
3035 mp1
->b_wptr
= mp1
->b_rptr
= mp1
->b_datap
->db_lim
;
3038 ip6i
= (ip6i_t
*)(mp
->b_rptr
- sizeof (ip6i_t
));
3040 mp
->b_rptr
= (uchar_t
*)ip6i
;
3041 ip6i
->ip6i_vcf
= ip6h
->ip6_vcf
;
3042 ip6i
->ip6i_nxt
= IPPROTO_RAW
;
3044 ip6i
->ip6i_flags
= IP6I_IFINDEX
;
3046 * If `ill' is in an IPMP group, make sure we use the IPMP
3047 * interface index so that e.g. IPV6_RECVPKTINFO will get the
3048 * IPMP interface index and not an underlying interface index.
3050 if (IS_UNDER_IPMP(ill
))
3051 ip6i
->ip6i_ifindex
= ipmp_ill_get_ipmp_ifindex(ill
);
3053 ip6i
->ip6i_ifindex
= ill
->ill_phyint
->phyint_ifindex
;
3055 ip6i
->ip6i_flags
= 0;
3057 ip6i
->ip6i_nexthop
= *dst
;
3062 * Handle protocols with which IP is less intimate. There
3063 * can be more than one stream bound to a particular
3064 * protocol. When this is the case, normally each one gets a copy
3065 * of any incoming packets.
3066 * However, if the packet was tunneled and not multicast we only send to it
3070 * Packets will be distributed to streams in all zones. This is really only
3071 * useful for ICMPv6 as only applications in the global zone can create raw
3072 * sockets for other protocols.
3075 ip_fanout_proto_v6(queue_t
*q
, mblk_t
*mp
, ip6_t
*ip6h
, ill_t
*ill
,
3076 ill_t
*inill
, uint8_t nexthdr
, uint_t nexthdr_offset
, uint_t flags
,
3077 boolean_t mctl_present
, zoneid_t zoneid
)
3080 mblk_t
*mp1
, *first_mp1
;
3081 in6_addr_t dst
= ip6h
->ip6_dst
;
3082 in6_addr_t src
= ip6h
->ip6_src
;
3084 mblk_t
*first_mp
= mp
;
3085 boolean_t secure
, shared_addr
;
3086 conn_t
*connp
, *first_connp
, *next_connp
;
3088 ip_stack_t
*ipst
= inill
->ill_ipst
;
3089 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
3092 mp
= first_mp
->b_cont
;
3093 secure
= ipsec_in_is_secure(first_mp
);
3100 * If the packet was tunneled and not multicast we only send to it
3103 one_only
= ((nexthdr
== IPPROTO_ENCAP
|| nexthdr
== IPPROTO_IPV6
) &&
3104 !IN6_IS_ADDR_MULTICAST(&dst
));
3106 shared_addr
= (zoneid
== ALL_ZONES
);
3109 * We don't allow multilevel ports for raw IP, so no need to
3110 * check for that here.
3112 zoneid
= tsol_packet_to_zoneid(mp
);
3115 connfp
= &ipst
->ips_ipcl_proto_fanout_v6
[nexthdr
];
3116 mutex_enter(&connfp
->connf_lock
);
3117 connp
= connfp
->connf_head
;
3118 for (connp
= connfp
->connf_head
; connp
!= NULL
;
3119 connp
= connp
->conn_next
) {
3120 if (IPCL_PROTO_MATCH_V6(connp
, nexthdr
, ip6h
, ill
, flags
,
3122 (!is_system_labeled() ||
3123 tsol_receive_local(mp
, &dst
, IPV6_VERSION
, shared_addr
,
3128 if (connp
== NULL
) {
3130 * No one bound to this port. Is
3131 * there a client that wants all
3132 * unclaimed datagrams?
3134 mutex_exit(&connfp
->connf_lock
);
3135 if (ip_fanout_send_icmp_v6(q
, first_mp
, flags
,
3136 ICMP6_PARAM_PROB
, ICMP6_PARAMPROB_NEXTHEADER
,
3137 nexthdr_offset
, mctl_present
, zoneid
, ipst
)) {
3138 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInUnknownProtos
);
3144 ASSERT(IPCL_IS_NONSTR(connp
) || connp
->conn_upq
!= NULL
);
3146 CONN_INC_REF(connp
);
3147 first_connp
= connp
;
3150 * XXX: Fix the multiple protocol listeners case. We should not
3151 * be walking the conn->next list here.
3155 * Only send message to one tunnel driver by immediately
3156 * terminating the loop.
3160 connp
= connp
->conn_next
;
3164 while (connp
!= NULL
) {
3165 if (IPCL_PROTO_MATCH_V6(connp
, nexthdr
, ip6h
, ill
,
3167 (!is_system_labeled() ||
3168 tsol_receive_local(mp
, &dst
, IPV6_VERSION
,
3169 shared_addr
, connp
)))
3171 connp
= connp
->conn_next
;
3175 * Just copy the data part alone. The mctl part is
3176 * needed just for verifying policy and it is never
3179 if (connp
== NULL
||
3180 (((first_mp1
= dupmsg(first_mp
)) == NULL
) &&
3181 ((first_mp1
= ip_copymsg(first_mp
)) == NULL
))) {
3183 * No more intested clients or memory
3186 connp
= first_connp
;
3189 ASSERT(IPCL_IS_NONSTR(connp
) || connp
->conn_rq
!= NULL
);
3190 mp1
= mctl_present
? first_mp1
->b_cont
: first_mp1
;
3191 CONN_INC_REF(connp
);
3192 mutex_exit(&connfp
->connf_lock
);
3193 rq
= connp
->conn_rq
;
3195 * For link-local always add ifindex so that transport can set
3196 * sin6_scope_id. Avoid it for ICMP error fanout.
3198 if ((connp
->conn_ip_recvpktinfo
||
3199 IN6_IS_ADDR_LINKLOCAL(&src
)) &&
3200 (flags
& IP_FF_IPINFO
)) {
3202 mp1
= ip_add_info_v6(mp1
, inill
, &dst
);
3205 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
3207 (IPCL_IS_NONSTR(connp
) && PROTO_FLOW_CNTRLD(connp
)) ||
3208 (!IPCL_IS_NONSTR(connp
) && !canputnext(rq
))) {
3209 if (flags
& IP_FF_RAWIP
) {
3210 BUMP_MIB(ill
->ill_ip_mib
,
3211 rawipIfStatsInOverflows
);
3213 BUMP_MIB(ill
->ill_icmp6_mib
,
3214 ipv6IfIcmpInOverflows
);
3220 * Don't enforce here if we're a tunnel - let "tun" do
3223 if (!IPCL_IS_IPTUN(connp
) &&
3224 (CONN_INBOUND_POLICY_PRESENT_V6(connp
, ipss
) ||
3226 first_mp1
= ipsec_check_inbound_policy(
3227 first_mp1
, connp
, NULL
, ip6h
, mctl_present
);
3229 if (first_mp1
!= NULL
) {
3232 BUMP_MIB(ill
->ill_ip_mib
,
3233 ipIfStatsHCInDelivers
);
3234 (connp
->conn_recv
)(connp
, mp1
, NULL
);
3237 mutex_enter(&connfp
->connf_lock
);
3238 /* Follow the next pointer before releasing the conn. */
3239 next_connp
= connp
->conn_next
;
3240 CONN_DEC_REF(connp
);
3244 /* Last one. Send it upstream. */
3245 mutex_exit(&connfp
->connf_lock
);
3247 /* Initiate IPPF processing */
3248 if (IP6_IN_IPP(flags
, ipst
)) {
3251 mutex_enter(&ill
->ill_lock
);
3252 ifindex
= ill
->ill_phyint
->phyint_ifindex
;
3253 mutex_exit(&ill
->ill_lock
);
3254 ip_process(IPP_LOCAL_IN
, &mp
, ifindex
);
3256 CONN_DEC_REF(connp
);
3264 * For link-local always add ifindex so that transport can set
3265 * sin6_scope_id. Avoid it for ICMP error fanout.
3267 if ((connp
->conn_ip_recvpktinfo
|| IN6_IS_ADDR_LINKLOCAL(&src
)) &&
3268 (flags
& IP_FF_IPINFO
)) {
3270 mp
= ip_add_info_v6(mp
, inill
, &dst
);
3272 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
3273 CONN_DEC_REF(connp
);
3277 } else if (mctl_present
) {
3278 first_mp
->b_cont
= mp
;
3284 rq
= connp
->conn_rq
;
3285 if ((IPCL_IS_NONSTR(connp
) && PROTO_FLOW_CNTRLD(connp
)) ||
3286 (!IPCL_IS_NONSTR(connp
) && !canputnext(rq
))) {
3288 if (flags
& IP_FF_RAWIP
) {
3289 BUMP_MIB(ill
->ill_ip_mib
, rawipIfStatsInOverflows
);
3291 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInOverflows
);
3296 if (IPCL_IS_IPTUN(connp
)) {
3298 * Tunneled packet. We enforce policy in the tunnel
3301 * Send the WHOLE packet up (incl. IPSEC_IN) without
3304 putnext(rq
, first_mp
);
3305 CONN_DEC_REF(connp
);
3309 * Don't enforce here if we're a tunnel - let "tun" do
3312 if (nexthdr
!= IPPROTO_ENCAP
&& nexthdr
!= IPPROTO_IPV6
&&
3313 (CONN_INBOUND_POLICY_PRESENT(connp
, ipss
) || secure
)) {
3314 first_mp
= ipsec_check_inbound_policy(first_mp
, connp
,
3315 NULL
, ip6h
, mctl_present
);
3316 if (first_mp
== NULL
) {
3317 CONN_DEC_REF(connp
);
3321 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInDelivers
);
3322 (connp
->conn_recv
)(connp
, mp
, NULL
);
3326 CONN_DEC_REF(connp
);
3330 * Send an ICMP error after patching up the packet appropriately. Returns
3331 * non-zero if the appropriate MIB should be bumped; zero otherwise.
3334 ip_fanout_send_icmp_v6(queue_t
*q
, mblk_t
*mp
, uint_t flags
,
3335 uint_t icmp_type
, uint8_t icmp_code
, uint_t nexthdr_offset
,
3336 boolean_t mctl_present
, zoneid_t zoneid
, ip_stack_t
*ipst
)
3341 unsigned char db_type
;
3342 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
3347 secure
= ipsec_in_is_secure(first_mp
);
3351 * If this is an ICMP error being reported - which goes
3352 * up as M_CTLs, we need to convert them to M_DATA till
3353 * we finish checking with global policy because
3354 * ipsec_check_global_policy() assumes M_DATA as clear
3355 * and M_CTL as secure.
3357 db_type
= mp
->b_datap
->db_type
;
3358 mp
->b_datap
->db_type
= M_DATA
;
3362 * We are generating an icmp error for some inbound packet.
3363 * Called from all ip_fanout_(udp, tcp, proto) functions.
3364 * Before we generate an error, check with global policy
3365 * to see whether this is allowed to enter the system. As
3366 * there is no "conn", we are checking with global policy.
3368 ip6h
= (ip6_t
*)mp
->b_rptr
;
3369 if (secure
|| ipss
->ipsec_inbound_v6_policy_present
) {
3370 first_mp
= ipsec_check_global_policy(first_mp
, NULL
,
3371 NULL
, ip6h
, mctl_present
, ipst
->ips_netstack
);
3372 if (first_mp
== NULL
)
3377 mp
->b_datap
->db_type
= db_type
;
3379 if (flags
& IP_FF_SEND_ICMP
) {
3380 if (flags
& IP_FF_HDR_COMPLETE
) {
3381 if (ip_hdr_complete_v6(ip6h
, zoneid
, ipst
)) {
3386 switch (icmp_type
) {
3387 case ICMP6_DST_UNREACH
:
3388 icmp_unreachable_v6(WR(q
), first_mp
, icmp_code
,
3389 B_FALSE
, B_FALSE
, zoneid
, ipst
);
3391 case ICMP6_PARAM_PROB
:
3392 icmp_param_problem_v6(WR(q
), first_mp
, icmp_code
,
3393 nexthdr_offset
, B_FALSE
, B_FALSE
, zoneid
, ipst
);
3397 panic("ip_fanout_send_icmp_v6: wrong type");
3414 * Fanout for TCP packets
3415 * The caller puts <fport, lport> in the ports parameter.
3418 ip_fanout_tcp_v6(queue_t
*q
, mblk_t
*mp
, ip6_t
*ip6h
, ill_t
*ill
, ill_t
*inill
,
3419 uint_t flags
, uint_t hdr_len
, boolean_t mctl_present
, zoneid_t zoneid
)
3425 boolean_t syn_present
= B_FALSE
;
3426 ip_stack_t
*ipst
= inill
->ill_ipst
;
3427 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
3431 mp
= first_mp
->b_cont
;
3432 secure
= ipsec_in_is_secure(first_mp
);
3438 connp
= ipcl_classify_v6(mp
, IPPROTO_TCP
, hdr_len
, zoneid
, ipst
);
3440 if (connp
== NULL
||
3441 !conn_wantpacket_v6(connp
, ill
, ip6h
, flags
, zoneid
)) {
3443 * No hard-bound match. Send Reset.
3445 dblk_t
*dp
= mp
->b_datap
;
3448 ASSERT((dp
->db_struioflag
& STRUIO_IP
) == 0);
3450 /* Initiate IPPf processing, if needed. */
3451 if (IPP_ENABLED(IPP_LOCAL_IN
, ipst
) &&
3452 (flags
& IP6_NO_IPPOLICY
)) {
3453 ill_index
= ill
->ill_phyint
->phyint_ifindex
;
3454 ip_process(IPP_LOCAL_IN
, &first_mp
, ill_index
);
3455 if (first_mp
== NULL
) {
3457 CONN_DEC_REF(connp
);
3461 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInDelivers
);
3462 tcp_xmit_listeners_reset(first_mp
, hdr_len
, zoneid
,
3463 ipst
->ips_netstack
->netstack_tcp
, connp
);
3465 CONN_DEC_REF(connp
);
3469 tcph
= (tcph_t
*)&mp
->b_rptr
[hdr_len
];
3470 if ((tcph
->th_flags
[0] & (TH_SYN
|TH_ACK
|TH_RST
|TH_URG
)) == TH_SYN
) {
3471 if (connp
->conn_flags
& IPCL_TCP
) {
3475 * For fused tcp loopback, assign the eager's
3476 * squeue to be that of the active connect's.
3478 if ((flags
& IP_FF_LOOPBACK
) && do_tcp_fusion
&&
3479 !CONN_INBOUND_POLICY_PRESENT_V6(connp
, ipss
) &&
3481 !IP6_IN_IPP(flags
, ipst
)) {
3482 ASSERT(Q_TO_CONN(q
) != NULL
);
3483 sqp
= Q_TO_CONN(q
)->conn_sqp
;
3485 sqp
= IP_SQUEUE_GET(lbolt
);
3488 mp
->b_datap
->db_struioflag
|= STRUIO_EAGER
;
3489 DB_CKSUMSTART(mp
) = (intptr_t)sqp
;
3492 * db_cksumstuff is unused in the incoming
3493 * path; Thus store the ifindex here. It will
3494 * be cleared in tcp_conn_create_v6().
3497 (intptr_t)ill
->ill_phyint
->phyint_ifindex
;
3498 syn_present
= B_TRUE
;
3502 if (IPCL_IS_TCP(connp
) && IPCL_IS_BOUND(connp
) && !syn_present
) {
3503 uint_t flags
= (unsigned int)tcph
->th_flags
[0] & 0xFF;
3504 if ((flags
& TH_RST
) || (flags
& TH_URG
)) {
3505 CONN_DEC_REF(connp
);
3509 if (flags
& TH_ACK
) {
3510 tcp_xmit_listeners_reset(first_mp
, hdr_len
, zoneid
,
3511 ipst
->ips_netstack
->netstack_tcp
, connp
);
3512 CONN_DEC_REF(connp
);
3516 CONN_DEC_REF(connp
);
3521 if (CONN_INBOUND_POLICY_PRESENT_V6(connp
, ipss
) || secure
) {
3522 first_mp
= ipsec_check_inbound_policy(first_mp
, connp
,
3523 NULL
, ip6h
, mctl_present
);
3524 if (first_mp
== NULL
) {
3525 CONN_DEC_REF(connp
);
3528 if (IPCL_IS_TCP(connp
) && IPCL_IS_BOUND(connp
)) {
3529 ASSERT(syn_present
);
3531 ASSERT(first_mp
!= mp
);
3532 first_mp
->b_datap
->db_struioflag
|=
3535 ASSERT(first_mp
== mp
);
3536 mp
->b_datap
->db_struioflag
&=
3538 mp
->b_datap
->db_struioflag
|=
3543 * Discard first_mp early since we're dealing with a
3544 * fully-connected conn_t and tcp doesn't do policy in
3545 * this case. Also, if someone is bound to IPPROTO_TCP
3546 * over raw IP, they don't expect to see a M_CTL.
3550 mctl_present
= B_FALSE
;
3556 /* Initiate IPPF processing */
3557 if (IP6_IN_IPP(flags
, ipst
)) {
3560 mutex_enter(&ill
->ill_lock
);
3561 ifindex
= ill
->ill_phyint
->phyint_ifindex
;
3562 mutex_exit(&ill
->ill_lock
);
3563 ip_process(IPP_LOCAL_IN
, &mp
, ifindex
);
3565 CONN_DEC_REF(connp
);
3570 } else if (mctl_present
) {
3572 * ip_add_info_v6 might return a new mp.
3574 ASSERT(first_mp
!= mp
);
3575 first_mp
->b_cont
= mp
;
3582 * For link-local always add ifindex so that TCP can bind to that
3583 * interface. Avoid it for ICMP error fanout.
3585 if (!syn_present
&& ((connp
->conn_ip_recvpktinfo
||
3586 IN6_IS_ADDR_LINKLOCAL(&ip6h
->ip6_src
)) &&
3587 (flags
& IP_FF_IPINFO
))) {
3589 mp
= ip_add_info_v6(mp
, inill
, &ip6h
->ip6_dst
);
3591 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
3592 CONN_DEC_REF(connp
);
3596 } else if (mctl_present
) {
3597 ASSERT(first_mp
!= mp
);
3598 first_mp
->b_cont
= mp
;
3604 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInDelivers
);
3605 if (IPCL_IS_TCP(connp
)) {
3606 SQUEUE_ENTER_ONE(connp
->conn_sqp
, first_mp
, connp
->conn_recv
,
3607 connp
, ip_squeue_flag
, SQTAG_IP6_TCP_INPUT
);
3609 /* SOCK_RAW, IPPROTO_TCP case */
3610 (connp
->conn_recv
)(connp
, first_mp
, NULL
);
3611 CONN_DEC_REF(connp
);
3616 * Fanout for UDP packets.
3617 * The caller puts <fport, lport> in the ports parameter.
3618 * ire_type must be IRE_BROADCAST for multicast and broadcast packets.
3620 * If SO_REUSEADDR is set all multicast and broadcast packets
3621 * will be delivered to all streams bound to the same port.
3624 * Multicast packets will be distributed to streams in all zones.
3627 ip_fanout_udp_v6(queue_t
*q
, mblk_t
*mp
, ip6_t
*ip6h
, uint32_t ports
,
3628 ill_t
*ill
, ill_t
*inill
, uint_t flags
, boolean_t mctl_present
,
3631 uint32_t dstport
, srcport
;
3639 mblk_t
*mp1
, *first_mp1
;
3641 boolean_t shared_addr
;
3642 ip_stack_t
*ipst
= inill
->ill_ipst
;
3643 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
3647 mp
= first_mp
->b_cont
;
3648 secure
= ipsec_in_is_secure(first_mp
);
3654 /* Extract ports in net byte order */
3655 dstport
= htons(ntohl(ports
) & 0xFFFF);
3656 srcport
= htons(ntohl(ports
) >> 16);
3657 dst
= ip6h
->ip6_dst
;
3658 src
= ip6h
->ip6_src
;
3660 shared_addr
= (zoneid
== ALL_ZONES
);
3663 * No need to handle exclusive-stack zones since ALL_ZONES
3664 * only applies to the shared stack.
3666 zoneid
= tsol_mlp_findzone(IPPROTO_UDP
, dstport
);
3668 * If no shared MLP is found, tsol_mlp_findzone returns
3669 * ALL_ZONES. In that case, we assume it's SLP, and
3670 * search for the zone based on the packet label.
3671 * That will also return ALL_ZONES on failure, but
3672 * we never allow conn_zoneid to be set to ALL_ZONES.
3674 if (zoneid
== ALL_ZONES
)
3675 zoneid
= tsol_packet_to_zoneid(mp
);
3678 /* Attempt to find a client stream based on destination port. */
3679 connfp
= &ipst
->ips_ipcl_udp_fanout
[IPCL_UDP_HASH(dstport
, ipst
)];
3680 mutex_enter(&connfp
->connf_lock
);
3681 connp
= connfp
->connf_head
;
3682 if (!IN6_IS_ADDR_MULTICAST(&dst
)) {
3684 * Not multicast. Send to the one (first) client we find.
3686 while (connp
!= NULL
) {
3687 if (IPCL_UDP_MATCH_V6(connp
, dstport
, dst
, srcport
,
3688 src
) && IPCL_ZONE_MATCH(connp
, zoneid
) &&
3689 conn_wantpacket_v6(connp
, ill
, ip6h
,
3693 connp
= connp
->conn_next
;
3695 if (connp
== NULL
|| connp
->conn_upq
== NULL
)
3698 if (is_system_labeled() &&
3699 !tsol_receive_local(mp
, &dst
, IPV6_VERSION
, shared_addr
,
3703 /* Found a client */
3704 CONN_INC_REF(connp
);
3705 mutex_exit(&connfp
->connf_lock
);
3707 if ((IPCL_IS_NONSTR(connp
) && PROTO_FLOW_CNTRLD(connp
)) ||
3708 (!IPCL_IS_NONSTR(connp
) && CONN_UDP_FLOWCTLD(connp
))) {
3710 CONN_DEC_REF(connp
);
3713 if (CONN_INBOUND_POLICY_PRESENT_V6(connp
, ipss
) || secure
) {
3714 first_mp
= ipsec_check_inbound_policy(first_mp
,
3715 connp
, NULL
, ip6h
, mctl_present
);
3716 if (first_mp
== NULL
) {
3717 CONN_DEC_REF(connp
);
3721 /* Initiate IPPF processing */
3722 if (IP6_IN_IPP(flags
, ipst
)) {
3725 mutex_enter(&ill
->ill_lock
);
3726 ifindex
= ill
->ill_phyint
->phyint_ifindex
;
3727 mutex_exit(&ill
->ill_lock
);
3728 ip_process(IPP_LOCAL_IN
, &mp
, ifindex
);
3730 CONN_DEC_REF(connp
);
3737 * For link-local always add ifindex so that
3738 * transport can set sin6_scope_id. Avoid it for
3739 * ICMP error fanout.
3741 if ((connp
->conn_ip_recvpktinfo
||
3742 IN6_IS_ADDR_LINKLOCAL(&src
)) &&
3743 (flags
& IP_FF_IPINFO
)) {
3745 mp
= ip_add_info_v6(mp
, inill
, &dst
);
3747 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
3748 CONN_DEC_REF(connp
);
3752 } else if (mctl_present
) {
3753 first_mp
->b_cont
= mp
;
3758 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInDelivers
);
3760 /* Send it upstream */
3761 (connp
->conn_recv
)(connp
, mp
, NULL
);
3763 IP6_STAT(ipst
, ip6_udp_fannorm
);
3764 CONN_DEC_REF(connp
);
3770 while (connp
!= NULL
) {
3771 if ((IPCL_UDP_MATCH_V6(connp
, dstport
, dst
, srcport
, src
)) &&
3772 conn_wantpacket_v6(connp
, ill
, ip6h
, flags
, zoneid
) &&
3773 (!is_system_labeled() ||
3774 tsol_receive_local(mp
, &dst
, IPV6_VERSION
, shared_addr
,
3777 connp
= connp
->conn_next
;
3780 if (connp
== NULL
|| connp
->conn_upq
== NULL
)
3785 CONN_INC_REF(connp
);
3786 connp
= connp
->conn_next
;
3788 while (connp
!= NULL
) {
3789 if (IPCL_UDP_MATCH_V6(connp
, dstport
, dst
, srcport
,
3790 src
) && conn_wantpacket_v6(connp
, ill
, ip6h
,
3792 (!is_system_labeled() ||
3793 tsol_receive_local(mp
, &dst
, IPV6_VERSION
,
3794 shared_addr
, connp
)))
3796 connp
= connp
->conn_next
;
3799 * Just copy the data part alone. The mctl part is
3800 * needed just for verifying policy and it is never
3803 if (connp
== NULL
||
3804 (((first_mp1
= dupmsg(first_mp
)) == NULL
) &&
3805 ((first_mp1
= ip_copymsg(first_mp
)) == NULL
))) {
3807 * No more interested clients or memory
3813 mp1
= mctl_present
? first_mp1
->b_cont
: first_mp1
;
3814 CONN_INC_REF(connp
);
3815 mutex_exit(&connfp
->connf_lock
);
3817 * For link-local always add ifindex so that transport
3818 * can set sin6_scope_id. Avoid it for ICMP error
3821 if ((connp
->conn_ip_recvpktinfo
||
3822 IN6_IS_ADDR_LINKLOCAL(&src
)) &&
3823 (flags
& IP_FF_IPINFO
)) {
3825 mp1
= ip_add_info_v6(mp1
, inill
, &dst
);
3827 /* mp1 could have changed */
3829 first_mp1
->b_cont
= mp1
;
3835 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
3838 if ((IPCL_IS_NONSTR(connp
) && PROTO_FLOW_CNTRLD(connp
)) ||
3839 (!IPCL_IS_NONSTR(connp
) && CONN_UDP_FLOWCTLD(connp
))) {
3840 BUMP_MIB(ill
->ill_ip_mib
, udpIfStatsInOverflows
);
3845 if (CONN_INBOUND_POLICY_PRESENT_V6(connp
, ipss
) || secure
) {
3846 first_mp1
= ipsec_check_inbound_policy
3847 (first_mp1
, connp
, NULL
, ip6h
,
3850 if (first_mp1
!= NULL
) {
3853 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInDelivers
);
3855 /* Send it upstream */
3856 (connp
->conn_recv
)(connp
, mp1
, NULL
);
3859 mutex_enter(&connfp
->connf_lock
);
3860 /* Follow the next pointer before releasing the conn. */
3861 next_conn
= connp
->conn_next
;
3862 IP6_STAT(ipst
, ip6_udp_fanmb
);
3863 CONN_DEC_REF(connp
);
3867 /* Last one. Send it upstream. */
3868 mutex_exit(&connfp
->connf_lock
);
3870 /* Initiate IPPF processing */
3871 if (IP6_IN_IPP(flags
, ipst
)) {
3874 mutex_enter(&ill
->ill_lock
);
3875 ifindex
= ill
->ill_phyint
->phyint_ifindex
;
3876 mutex_exit(&ill
->ill_lock
);
3877 ip_process(IPP_LOCAL_IN
, &mp
, ifindex
);
3879 CONN_DEC_REF(connp
);
3888 * For link-local always add ifindex so that transport can set
3889 * sin6_scope_id. Avoid it for ICMP error fanout.
3891 if ((connp
->conn_ip_recvpktinfo
||
3892 IN6_IS_ADDR_LINKLOCAL(&src
)) && (flags
& IP_FF_IPINFO
)) {
3894 mp
= ip_add_info_v6(mp
, inill
, &dst
);
3896 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
3897 CONN_DEC_REF(connp
);
3901 } else if (mctl_present
) {
3902 first_mp
->b_cont
= mp
;
3907 if ((IPCL_IS_NONSTR(connp
) && PROTO_FLOW_CNTRLD(connp
)) ||
3908 (!IPCL_IS_NONSTR(connp
) && CONN_UDP_FLOWCTLD(connp
))) {
3909 BUMP_MIB(ill
->ill_ip_mib
, udpIfStatsInOverflows
);
3912 if (CONN_INBOUND_POLICY_PRESENT_V6(connp
, ipss
) || secure
) {
3913 first_mp
= ipsec_check_inbound_policy(first_mp
,
3914 connp
, NULL
, ip6h
, mctl_present
);
3915 if (first_mp
== NULL
) {
3916 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
3917 CONN_DEC_REF(connp
);
3921 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInDelivers
);
3923 /* Send it upstream */
3924 (connp
->conn_recv
)(connp
, mp
, NULL
);
3926 IP6_STAT(ipst
, ip6_udp_fanmb
);
3927 CONN_DEC_REF(connp
);
3933 mutex_exit(&connfp
->connf_lock
);
3935 * No one bound to this port. Is
3936 * there a client that wants all
3937 * unclaimed datagrams?
3939 if (ipst
->ips_ipcl_proto_fanout_v6
[IPPROTO_UDP
].connf_head
!= NULL
) {
3940 ip_fanout_proto_v6(q
, first_mp
, ip6h
, ill
, inill
, IPPROTO_UDP
,
3941 0, flags
| IP_FF_RAWIP
| IP_FF_IPINFO
, mctl_present
,
3944 if (ip_fanout_send_icmp_v6(q
, first_mp
, flags
,
3945 ICMP6_DST_UNREACH
, ICMP6_DST_UNREACH_NOPORT
, 0,
3946 mctl_present
, zoneid
, ipst
)) {
3947 BUMP_MIB(ill
->ill_ip_mib
, udpIfStatsNoPorts
);
3953 * int ip_find_hdr_v6()
3955 * This routine is used by the upper layer protocols and the IP tunnel
3957 * - Set extension header pointers to appropriate locations
3958 * - Determine IPv6 header length and return it
3959 * - Return a pointer to the last nexthdr value
3961 * The caller must initialize ipp_fields.
3963 * NOTE: If multiple extension headers of the same type are present,
3964 * ip_find_hdr_v6() will set the respective extension header pointers
3965 * to the first one that it encounters in the IPv6 header. It also
3966 * skips fragment headers. This routine deals with malformed packets
3967 * of various sorts in which case the returned length is up to the
3971 ip_find_hdr_v6(mblk_t
*mp
, ip6_t
*ip6h
, ip6_pkt_t
*ipp
, uint8_t *nexthdrp
)
3973 uint_t length
, ehdrlen
;
3975 uint8_t *whereptr
, *endptr
;
3976 ip6_dest_t
*tmpdstopts
;
3977 ip6_rthdr_t
*tmprthdr
;
3978 ip6_hbh_t
*tmphopopts
;
3979 ip6_frag_t
*tmpfraghdr
;
3981 length
= IPV6_HDR_LEN
;
3982 whereptr
= ((uint8_t *)&ip6h
[1]); /* point to next hdr */
3983 endptr
= mp
->b_wptr
;
3985 nexthdr
= ip6h
->ip6_nxt
;
3986 while (whereptr
< endptr
) {
3987 /* Is there enough left for len + nexthdr? */
3988 if (whereptr
+ MIN_EHDR_LEN
> endptr
)
3992 case IPPROTO_HOPOPTS
:
3993 tmphopopts
= (ip6_hbh_t
*)whereptr
;
3994 ehdrlen
= 8 * (tmphopopts
->ip6h_len
+ 1);
3995 if ((uchar_t
*)tmphopopts
+ ehdrlen
> endptr
)
3997 nexthdr
= tmphopopts
->ip6h_nxt
;
3998 /* return only 1st hbh */
3999 if (!(ipp
->ipp_fields
& IPPF_HOPOPTS
)) {
4000 ipp
->ipp_fields
|= IPPF_HOPOPTS
;
4001 ipp
->ipp_hopopts
= tmphopopts
;
4002 ipp
->ipp_hopoptslen
= ehdrlen
;
4005 case IPPROTO_DSTOPTS
:
4006 tmpdstopts
= (ip6_dest_t
*)whereptr
;
4007 ehdrlen
= 8 * (tmpdstopts
->ip6d_len
+ 1);
4008 if ((uchar_t
*)tmpdstopts
+ ehdrlen
> endptr
)
4010 nexthdr
= tmpdstopts
->ip6d_nxt
;
4012 * ipp_dstopts is set to the destination header after a
4014 * Assume it is a post-rthdr destination header
4015 * and adjust when we find an rthdr.
4017 if (!(ipp
->ipp_fields
& IPPF_DSTOPTS
)) {
4018 ipp
->ipp_fields
|= IPPF_DSTOPTS
;
4019 ipp
->ipp_dstopts
= tmpdstopts
;
4020 ipp
->ipp_dstoptslen
= ehdrlen
;
4023 case IPPROTO_ROUTING
:
4024 tmprthdr
= (ip6_rthdr_t
*)whereptr
;
4025 ehdrlen
= 8 * (tmprthdr
->ip6r_len
+ 1);
4026 if ((uchar_t
*)tmprthdr
+ ehdrlen
> endptr
)
4028 nexthdr
= tmprthdr
->ip6r_nxt
;
4029 /* return only 1st rthdr */
4030 if (!(ipp
->ipp_fields
& IPPF_RTHDR
)) {
4031 ipp
->ipp_fields
|= IPPF_RTHDR
;
4032 ipp
->ipp_rthdr
= tmprthdr
;
4033 ipp
->ipp_rthdrlen
= ehdrlen
;
4036 * Make any destination header we've seen be a
4037 * pre-rthdr destination header.
4039 if (ipp
->ipp_fields
& IPPF_DSTOPTS
) {
4040 ipp
->ipp_fields
&= ~IPPF_DSTOPTS
;
4041 ipp
->ipp_fields
|= IPPF_RTDSTOPTS
;
4042 ipp
->ipp_rtdstopts
= ipp
->ipp_dstopts
;
4043 ipp
->ipp_dstopts
= NULL
;
4044 ipp
->ipp_rtdstoptslen
= ipp
->ipp_dstoptslen
;
4045 ipp
->ipp_dstoptslen
= 0;
4048 case IPPROTO_FRAGMENT
:
4049 tmpfraghdr
= (ip6_frag_t
*)whereptr
;
4050 ehdrlen
= sizeof (ip6_frag_t
);
4051 if ((uchar_t
*)tmpfraghdr
+ ehdrlen
> endptr
)
4053 nexthdr
= tmpfraghdr
->ip6f_nxt
;
4054 if (!(ipp
->ipp_fields
& IPPF_FRAGHDR
)) {
4055 ipp
->ipp_fields
|= IPPF_FRAGHDR
;
4056 ipp
->ipp_fraghdr
= tmpfraghdr
;
4057 ipp
->ipp_fraghdrlen
= ehdrlen
;
4065 whereptr
+= ehdrlen
;
4068 if (nexthdrp
!= NULL
)
4069 *nexthdrp
= nexthdr
;
4074 ip_hdr_complete_v6(ip6_t
*ip6h
, zoneid_t zoneid
, ip_stack_t
*ipst
)
4078 if (IN6_IS_ADDR_UNSPECIFIED(&ip6h
->ip6_src
)) {
4079 ire
= ire_lookup_local_v6(zoneid
, ipst
);
4081 ip1dbg(("ip_hdr_complete_v6: no source IRE\n"));
4084 ip6h
->ip6_src
= ire
->ire_addr_v6
;
4087 ip6h
->ip6_vcf
= IPV6_DEFAULT_VERS_AND_FLOW
;
4088 ip6h
->ip6_hops
= ipst
->ips_ipv6_def_hops
;
4093 * Try to determine where and what are the IPv6 header length and
4094 * pointer to nexthdr value for the upper layer protocol (or an
4095 * unknown next hdr).
4097 * Parameters returns a pointer to the nexthdr value;
4098 * Must handle malformed packets of various sorts.
4099 * Function returns failure for malformed cases.
4102 ip_hdr_length_nexthdr_v6(mblk_t
*mp
, ip6_t
*ip6h
, uint16_t *hdr_length_ptr
,
4103 uint8_t **nexthdrpp
)
4110 ip6_dest_t
*desthdr
;
4112 ip6_frag_t
*fraghdr
;
4114 ASSERT((IPH_HDR_VERSION(ip6h
) & ~IP_FORWARD_PROG_BIT
) == IPV6_VERSION
);
4115 length
= IPV6_HDR_LEN
;
4116 whereptr
= ((uint8_t *)&ip6h
[1]); /* point to next hdr */
4117 endptr
= mp
->b_wptr
;
4119 nexthdrp
= &ip6h
->ip6_nxt
;
4120 while (whereptr
< endptr
) {
4121 /* Is there enough left for len + nexthdr? */
4122 if (whereptr
+ MIN_EHDR_LEN
> endptr
)
4125 switch (*nexthdrp
) {
4126 case IPPROTO_HOPOPTS
:
4127 case IPPROTO_DSTOPTS
:
4128 /* Assumes the headers are identical for hbh and dst */
4129 desthdr
= (ip6_dest_t
*)whereptr
;
4130 ehdrlen
= 8 * (desthdr
->ip6d_len
+ 1);
4131 if ((uchar_t
*)desthdr
+ ehdrlen
> endptr
)
4133 nexthdrp
= &desthdr
->ip6d_nxt
;
4135 case IPPROTO_ROUTING
:
4136 rthdr
= (ip6_rthdr_t
*)whereptr
;
4137 ehdrlen
= 8 * (rthdr
->ip6r_len
+ 1);
4138 if ((uchar_t
*)rthdr
+ ehdrlen
> endptr
)
4140 nexthdrp
= &rthdr
->ip6r_nxt
;
4142 case IPPROTO_FRAGMENT
:
4143 fraghdr
= (ip6_frag_t
*)whereptr
;
4144 ehdrlen
= sizeof (ip6_frag_t
);
4145 if ((uchar_t
*)&fraghdr
[1] > endptr
)
4147 nexthdrp
= &fraghdr
->ip6f_nxt
;
4150 /* No next header means we're finished */
4152 *hdr_length_ptr
= length
;
4153 *nexthdrpp
= nexthdrp
;
4157 whereptr
+= ehdrlen
;
4158 *hdr_length_ptr
= length
;
4159 *nexthdrpp
= nexthdrp
;
4161 switch (*nexthdrp
) {
4162 case IPPROTO_HOPOPTS
:
4163 case IPPROTO_DSTOPTS
:
4164 case IPPROTO_ROUTING
:
4165 case IPPROTO_FRAGMENT
:
4167 * If any know extension headers are still to be processed,
4168 * the packet's malformed (or at least all the IP header(s) are
4169 * not in the same mblk - and that should never happen.
4175 * If we get here, we know that all of the IP headers were in
4176 * the same mblk, even if the ULP header is in the next mblk.
4178 *hdr_length_ptr
= length
;
4179 *nexthdrpp
= nexthdrp
;
4185 * Return the length of the IPv6 related headers (including extension headers)
4186 * Returns a length even if the packet is malformed.
4189 ip_hdr_length_v6(mblk_t
*mp
, ip6_t
*ip6h
)
4194 (void) ip_hdr_length_nexthdr_v6(mp
, ip6h
, &hdr_len
, &nexthdrp
);
4200 * ip_newroute_v6 is called by ip_rput_data_v6 or ip_wput_v6 whenever we need
4201 * to send out a packet to a destination address for which we do not have
4202 * specific routing information.
4204 * Handle non-multicast packets. If ill is non-NULL the match is done
4207 * When a specific ill is specified (using IPV6_PKTINFO,
4208 * IPV6_MULTICAST_IF, or IPV6_BOUND_IF) we will only match
4209 * on routing entries (ftable and ctable) that have a matching
4210 * ire->ire_ipif->ipif_ill. Thus this can only be used
4211 * for destinations that are on-link for the specific ill
4212 * and that can appear on multiple links. Thus it is useful
4213 * for multicast destinations, link-local destinations, and
4214 * at some point perhaps for site-local destinations (if the
4215 * node sits at a site boundary).
4216 * We create the cache entries in the regular ctable since
4217 * it can not "confuse" things for other destinations.
4219 * NOTE : These are the scopes of some of the variables that point at IRE,
4220 * which needs to be followed while making any future modifications
4221 * to avoid memory leaks.
4223 * - ire and sire are the entries looked up initially by
4224 * ire_ftable_lookup_v6.
4225 * - ipif_ire is used to hold the interface ire associated with
4226 * the new cache ire. But it's scope is limited, so we always REFRELE
4227 * it before branching out to error paths.
4228 * - save_ire is initialized before ire_create, so that ire returned
4229 * by ire_create will not over-write the ire. We REFRELE save_ire
4230 * before breaking out of the switch.
4232 * Thus on failures, we have to REFRELE only ire and sire, if they
4237 ip_newroute_v6(queue_t
*q
, mblk_t
*mp
, const in6_addr_t
*v6dstp
,
4238 const in6_addr_t
*v6srcp
, ill_t
*ill
, zoneid_t zoneid
, ip_stack_t
*ipst
)
4243 ipif_t
*src_ipif
= NULL
;
4244 ill_t
*dst_ill
= NULL
;
4251 ushort_t ire_marks
= 0;
4253 ire_t
*first_sire
= NULL
;
4254 mblk_t
*copy_mp
= NULL
;
4255 mblk_t
*xmit_mp
= NULL
;
4256 in6_addr_t save_dst
;
4257 uint32_t multirt_flags
=
4258 MULTIRT_CACHEGW
| MULTIRT_USESTAMP
| MULTIRT_SETSTAMP
;
4259 boolean_t multirt_is_resolvable
;
4260 boolean_t multirt_resolve_next
;
4261 boolean_t need_rele
= B_FALSE
;
4262 boolean_t ip6_asp_table_held
= B_FALSE
;
4263 tsol_ire_gw_secattr_t
*attrp
= NULL
;
4264 tsol_gcgrp_t
*gcgrp
= NULL
;
4265 tsol_gcgrp_addr_t ga
;
4267 ASSERT(!IN6_IS_ADDR_MULTICAST(v6dstp
));
4270 if (mp
->b_datap
->db_type
== M_CTL
) {
4272 io
= (ipsec_out_t
*)first_mp
->b_rptr
;
4273 ASSERT(io
->ipsec_out_type
== IPSEC_OUT
);
4278 ip6h
= (ip6_t
*)mp
->b_rptr
;
4280 if (IN6_IS_ADDR_LOOPBACK(v6dstp
)) {
4281 ip1dbg(("ip_newroute_v6: dst with loopback addr\n"));
4283 } else if (IN6_IS_ADDR_LOOPBACK(v6srcp
)) {
4284 ip1dbg(("ip_newroute_v6: src with loopback addr\n"));
4289 * If this IRE is created for forwarding or it is not for
4290 * TCP traffic, mark it as temporary.
4292 * Is it sufficient just to check the next header??
4294 if (mp
->b_prev
!= NULL
|| !IP_FLOW_CONTROLLED_ULP(ip6h
->ip6_nxt
))
4295 ire_marks
|= IRE_MARK_TEMPORARY
;
4298 * Get what we can from ire_ftable_lookup_v6 which will follow an IRE
4299 * chain until it gets the most specific information available.
4300 * For example, we know that there is no IRE_CACHE for this dest,
4301 * but there may be an IRE_OFFSUBNET which specifies a gateway.
4302 * ire_ftable_lookup_v6 will look up the gateway, etc.
4306 match_flags
= MATCH_IRE_RECURSIVE
| MATCH_IRE_DEFAULT
|
4307 MATCH_IRE_PARENT
| MATCH_IRE_RJ_BHOLE
| MATCH_IRE_SECATTR
;
4308 ire
= ire_ftable_lookup_v6(v6dstp
, 0, 0, 0,
4309 NULL
, &sire
, zoneid
, 0, msg_getlabel(mp
),
4312 match_flags
= MATCH_IRE_RECURSIVE
| MATCH_IRE_DEFAULT
|
4313 MATCH_IRE_RJ_BHOLE
| MATCH_IRE_ILL
;
4314 match_flags
|= MATCH_IRE_PARENT
| MATCH_IRE_SECATTR
;
4317 * Because nce_xmit() calls ip_output_v6() and NCEs are always
4318 * tied to an underlying interface, IS_UNDER_IPMP() may be
4319 * true even when building IREs that will be used for data
4320 * traffic. As such, use the packet's source address to
4321 * determine whether the traffic is test traffic, and set
4322 * MATCH_IRE_MARK_TESTHIDDEN if so.
4324 if (IS_UNDER_IPMP(ill
) && !IN6_IS_ADDR_UNSPECIFIED(v6srcp
)) {
4325 if (ipif_lookup_testaddr_v6(ill
, v6srcp
, NULL
))
4326 match_flags
|= MATCH_IRE_MARK_TESTHIDDEN
;
4329 ire
= ire_ftable_lookup_v6(v6dstp
, NULL
, NULL
, 0, ill
->ill_ipif
,
4330 &sire
, zoneid
, 0, msg_getlabel(mp
), match_flags
, ipst
);
4333 ip3dbg(("ip_newroute_v6: ire_ftable_lookup_v6() "
4334 "returned ire %p, sire %p\n", (void *)ire
, (void *)sire
));
4337 * We enter a loop that will be run only once in most cases.
4338 * The loop is re-entered in the case where the destination
4339 * can be reached through multiple RTF_MULTIRT-flagged routes.
4340 * The intention is to compute multiple routes to a single
4341 * destination in a single ip_newroute_v6 call.
4342 * The information is contained in sire->ire_flags.
4345 multirt_resolve_next
= B_FALSE
;
4347 if (dst_ill
!= NULL
) {
4348 ill_refrele(dst_ill
);
4351 if (src_ipif
!= NULL
) {
4352 ipif_refrele(src_ipif
);
4355 if ((sire
!= NULL
) && sire
->ire_flags
& RTF_MULTIRT
) {
4356 ip3dbg(("ip_newroute_v6: starting new resolution "
4357 "with first_mp %p, tag %d\n",
4358 (void *)first_mp
, MULTIRT_DEBUG_TAGGED(first_mp
)));
4361 * We check if there are trailing unresolved routes for
4362 * the destination contained in sire.
4364 multirt_is_resolvable
= ire_multirt_lookup_v6(&ire
,
4365 &sire
, multirt_flags
, msg_getlabel(mp
), ipst
);
4367 ip3dbg(("ip_newroute_v6: multirt_is_resolvable %d, "
4368 "ire %p, sire %p\n",
4369 multirt_is_resolvable
, (void *)ire
, (void *)sire
));
4371 if (!multirt_is_resolvable
) {
4373 * No more multirt routes to resolve; give up
4374 * (all routes resolved or no more resolvable
4382 ASSERT(sire
!= NULL
);
4383 ASSERT(ire
!= NULL
);
4385 * We simply use first_sire as a flag that
4386 * indicates if a resolvable multirt route has
4387 * already been found during the preceding
4388 * loops. If it is not the case, we may have
4389 * to send an ICMP error to report that the
4390 * destination is unreachable. We do not
4391 * IRE_REFHOLD first_sire.
4393 if (first_sire
== NULL
) {
4398 if ((ire
== NULL
) || (ire
== sire
)) {
4400 * either ire == NULL (the destination cannot be
4401 * resolved) or ire == sire (the gateway cannot be
4402 * resolved). At this point, there are no more routes
4403 * to resolve for the destination, thus we exit.
4407 pr_addr_dbg("ip_newroute_v6: "
4408 "can't resolve %s\n", AF_INET6
, v6dstp
);
4410 ip3dbg(("ip_newroute_v6: "
4411 "ire %p, sire %p, first_sire %p\n",
4412 (void *)ire
, (void *)sire
, (void *)first_sire
));
4419 if (first_sire
!= NULL
) {
4421 * At least one multirt route has been found
4422 * in the same ip_newroute() call; there is no
4423 * need to report an ICMP error.
4424 * first_sire was not IRE_REFHOLDed.
4426 MULTIRT_DEBUG_UNTAG(first_mp
);
4430 ip_rts_change_v6(RTM_MISS
, v6dstp
, 0, 0, 0, 0, 0, 0,
4435 ASSERT(ire
->ire_ipversion
== IPV6_VERSION
);
4438 * Verify that the returned IRE does not have either the
4439 * RTF_REJECT or RTF_BLACKHOLE flags set and that the IRE is
4440 * either an IRE_CACHE, IRE_IF_NORESOLVER or IRE_IF_RESOLVER.
4442 if ((ire
->ire_flags
& (RTF_REJECT
| RTF_BLACKHOLE
)) ||
4443 (ire
->ire_type
& (IRE_CACHE
| IRE_INTERFACE
)) == 0)
4447 * Increment the ire_ob_pkt_count field for ire if it is an
4448 * INTERFACE (IF_RESOLVER or IF_NORESOLVER) IRE type, and
4449 * increment the same for the parent IRE, sire, if it is some
4450 * sort of prefix IRE (which includes DEFAULT, PREFIX, and HOST)
4452 if ((ire
->ire_type
& IRE_INTERFACE
) != 0) {
4453 UPDATE_OB_PKT_COUNT(ire
);
4454 ire
->ire_last_used_time
= lbolt
;
4458 mutex_enter(&sire
->ire_lock
);
4459 v6gw
= sire
->ire_gateway_addr_v6
;
4460 mutex_exit(&sire
->ire_lock
);
4461 ASSERT((sire
->ire_type
& (IRE_CACHETABLE
|
4462 IRE_INTERFACE
)) == 0);
4463 UPDATE_OB_PKT_COUNT(sire
);
4464 sire
->ire_last_used_time
= lbolt
;
4466 v6gw
= ipv6_all_zeros
;
4470 * We have a route to reach the destination. Find the
4471 * appropriate ill, then get a source address that matches the
4472 * right scope via ipif_select_source_v6().
4474 * If we are here trying to create an IRE_CACHE for an offlink
4475 * destination and have an IRE_CACHE entry for VNI, then use
4476 * ire_stq instead since VNI's queue is a black hole.
4478 * Note: While we pick a dst_ill we are really only interested
4479 * in the ill for load spreading. The source ipif is
4480 * determined by source address selection below.
4482 if ((ire
->ire_type
== IRE_CACHE
) &&
4483 IS_VNI(ire
->ire_ipif
->ipif_ill
)) {
4484 dst_ill
= ire
->ire_stq
->q_ptr
;
4485 ill_refhold(dst_ill
);
4487 ill_t
*ill
= ire
->ire_ipif
->ipif_ill
;
4491 ipmp_illgrp_hold_next_ill(ill
->ill_grp
);
4494 ill_refhold(dst_ill
);
4498 if (dst_ill
== NULL
) {
4500 pr_addr_dbg("ip_newroute_v6 : no dst "
4501 "ill for dst %s\n", AF_INET6
, v6dstp
);
4506 if (ill
!= NULL
&& dst_ill
!= ill
&&
4507 !IS_IN_SAME_ILLGRP(dst_ill
, ill
)) {
4509 * We should have found a route matching "ill"
4510 * as we called ire_ftable_lookup_v6 with
4511 * MATCH_IRE_ILL. Rather than asserting when
4512 * there is a mismatch, we just drop the packet.
4514 ip0dbg(("ip_newroute_v6: BOUND_IF failed: "
4515 "dst_ill %s ill %s\n", dst_ill
->ill_name
,
4521 * Pick a source address which matches the scope of the
4522 * destination address.
4523 * For RTF_SETSRC routes, the source address is imposed by the
4524 * parent ire (sire).
4526 ASSERT(src_ipif
== NULL
);
4529 * Because nce_xmit() calls ip_output_v6() and NCEs are always
4530 * tied to the underlying interface, IS_UNDER_IPMP() may be
4531 * true even when building IREs that will be used for data
4532 * traffic. As such, see if the packet's source address is a
4533 * test address, and if so use that test address's ipif for
4534 * the IRE so that the logic that sets IRE_MARK_TESTHIDDEN in
4535 * ire_add_v6() can work properly.
4537 if (ill
!= NULL
&& IS_UNDER_IPMP(ill
))
4538 (void) ipif_lookup_testaddr_v6(ill
, v6srcp
, &src_ipif
);
4540 if (src_ipif
== NULL
&& ire
->ire_type
== IRE_IF_RESOLVER
&&
4541 !IN6_IS_ADDR_UNSPECIFIED(&v6gw
) &&
4542 ip6_asp_can_lookup(ipst
)) {
4544 * The ire cache entry we're adding is for the
4545 * gateway itself. The source address in this case
4546 * is relative to the gateway's address.
4548 ip6_asp_table_held
= B_TRUE
;
4549 src_ipif
= ipif_select_source_v6(dst_ill
, &v6gw
,
4550 B_TRUE
, IPV6_PREFER_SRC_DEFAULT
, zoneid
);
4551 if (src_ipif
!= NULL
)
4552 ire_marks
|= IRE_MARK_USESRC_CHECK
;
4553 } else if (src_ipif
== NULL
) {
4554 if ((sire
!= NULL
) && (sire
->ire_flags
& RTF_SETSRC
)) {
4556 * Check that the ipif matching the requested
4557 * source address still exists.
4559 src_ipif
= ipif_lookup_addr_v6(
4560 &sire
->ire_src_addr_v6
, NULL
, zoneid
,
4561 NULL
, NULL
, NULL
, NULL
, ipst
);
4563 if (src_ipif
== NULL
&& ip6_asp_can_lookup(ipst
)) {
4564 ip6_asp_table_held
= B_TRUE
;
4565 src_ipif
= ipif_select_source_v6(dst_ill
,
4567 IPV6_PREFER_SRC_DEFAULT
, zoneid
);
4568 if (src_ipif
!= NULL
)
4569 ire_marks
|= IRE_MARK_USESRC_CHECK
;
4573 if (src_ipif
== NULL
) {
4576 pr_addr_dbg("ip_newroute_v6: no src for "
4577 "dst %s\n", AF_INET6
, v6dstp
);
4578 printf("ip_newroute_v6: interface name %s\n",
4586 pr_addr_dbg("ip_newroute_v6: first hop %s\n",
4589 ip2dbg(("\tire type %s (%d)\n",
4590 ip_nv_lookup(ire_nv_tbl
, ire
->ire_type
), ire
->ire_type
));
4593 * At this point in ip_newroute_v6(), ire is either the
4594 * IRE_CACHE of the next-hop gateway for an off-subnet
4595 * destination or an IRE_INTERFACE type that should be used
4596 * to resolve an on-subnet destination or an on-subnet
4599 * In the IRE_CACHE case, we have the following :
4601 * 1) src_ipif - used for getting a source address.
4603 * 2) dst_ill - from which we derive ire_stq/ire_rfq. This
4604 * means packets using this IRE_CACHE will go out on dst_ill.
4606 * 3) The IRE sire will point to the prefix that is the longest
4607 * matching route for the destination. These prefix types
4608 * include IRE_DEFAULT, IRE_PREFIX, IRE_HOST.
4610 * The newly created IRE_CACHE entry for the off-subnet
4611 * destination is tied to both the prefix route and the
4612 * interface route used to resolve the next-hop gateway
4613 * via the ire_phandle and ire_ihandle fields, respectively.
4615 * In the IRE_INTERFACE case, we have the following :
4617 * 1) src_ipif - used for getting a source address.
4619 * 2) dst_ill - from which we derive ire_stq/ire_rfq. This
4620 * means packets using the IRE_CACHE that we will build
4621 * here will go out on dst_ill.
4623 * 3) sire may or may not be NULL. But, the IRE_CACHE that is
4624 * to be created will only be tied to the IRE_INTERFACE that
4625 * was derived from the ire_ihandle field.
4627 * If sire is non-NULL, it means the destination is off-link
4628 * and we will first create the IRE_CACHE for the gateway.
4629 * Next time through ip_newroute_v6, we will create the
4630 * IRE_CACHE for the final destination as described above.
4633 switch (ire
->ire_type
) {
4637 ASSERT(sire
!= NULL
);
4638 if (IN6_IS_ADDR_UNSPECIFIED(&v6gw
)) {
4639 mutex_enter(&ire
->ire_lock
);
4640 v6gw
= ire
->ire_gateway_addr_v6
;
4641 mutex_exit(&ire
->ire_lock
);
4644 * We need 3 ire's to create a new cache ire for an
4645 * off-link destination from the cache ire of the
4648 * 1. The prefix ire 'sire'
4649 * 2. The cache ire of the gateway 'ire'
4650 * 3. The interface ire 'ipif_ire'
4652 * We have (1) and (2). We lookup (3) below.
4654 * If there is no interface route to the gateway,
4655 * it is a race condition, where we found the cache
4656 * but the inteface route has been deleted.
4658 ipif_ire
= ire_ihandle_lookup_offlink_v6(ire
, sire
);
4659 if (ipif_ire
== NULL
) {
4660 ip1dbg(("ip_newroute_v6:"
4661 "ire_ihandle_lookup_offlink_v6 failed\n"));
4666 * Note: the new ire inherits RTF_SETSRC
4667 * and RTF_MULTIRT to propagate these flags from prefix
4672 * Check cached gateway IRE for any security
4673 * attributes; if found, associate the gateway
4674 * credentials group to the destination IRE.
4676 if ((attrp
= save_ire
->ire_gw_secattr
) != NULL
) {
4677 mutex_enter(&attrp
->igsa_lock
);
4678 if ((gcgrp
= attrp
->igsa_gcgrp
) != NULL
)
4679 GCGRP_REFHOLD(gcgrp
);
4680 mutex_exit(&attrp
->igsa_lock
);
4683 ire
= ire_create_v6(
4684 v6dstp
, /* dest address */
4685 &ipv6_all_ones
, /* mask */
4686 &src_ipif
->ipif_v6src_addr
, /* source address */
4687 &v6gw
, /* gateway address */
4688 &save_ire
->ire_max_frag
,
4690 dst_ill
->ill_rq
, /* recv-from queue */
4691 dst_ill
->ill_wq
, /* send-to queue */
4694 &sire
->ire_mask_v6
, /* Parent mask */
4695 sire
->ire_phandle
, /* Parent handle */
4696 ipif_ire
->ire_ihandle
, /* Interface handle */
4697 sire
->ire_flags
& /* flags if any */
4698 (RTF_SETSRC
| RTF_MULTIRT
),
4705 if (gcgrp
!= NULL
) {
4706 GCGRP_REFRELE(gcgrp
);
4709 ire_refrele(save_ire
);
4710 ire_refrele(ipif_ire
);
4714 /* reference now held by IRE */
4717 ire
->ire_marks
|= ire_marks
;
4720 * Prevent sire and ipif_ire from getting deleted. The
4721 * newly created ire is tied to both of them via the
4722 * phandle and ihandle respectively.
4724 IRB_REFHOLD(sire
->ire_bucket
);
4725 /* Has it been removed already ? */
4726 if (sire
->ire_marks
& IRE_MARK_CONDEMNED
) {
4727 IRB_REFRELE(sire
->ire_bucket
);
4728 ire_refrele(ipif_ire
);
4729 ire_refrele(save_ire
);
4733 IRB_REFHOLD(ipif_ire
->ire_bucket
);
4734 /* Has it been removed already ? */
4735 if (ipif_ire
->ire_marks
& IRE_MARK_CONDEMNED
) {
4736 IRB_REFRELE(ipif_ire
->ire_bucket
);
4737 IRB_REFRELE(sire
->ire_bucket
);
4738 ire_refrele(ipif_ire
);
4739 ire_refrele(save_ire
);
4744 if (ire
->ire_flags
& RTF_MULTIRT
) {
4745 copy_mp
= copymsg(first_mp
);
4746 if (copy_mp
!= NULL
) {
4748 MULTIRT_DEBUG_TAG(first_mp
);
4751 ire_add_then_send(q
, ire
, xmit_mp
);
4752 if (ip6_asp_table_held
) {
4753 ip6_asp_table_refrele(ipst
);
4754 ip6_asp_table_held
= B_FALSE
;
4756 ire_refrele(save_ire
);
4758 /* Assert that sire is not deleted yet. */
4759 ASSERT(sire
->ire_ptpn
!= NULL
);
4760 IRB_REFRELE(sire
->ire_bucket
);
4762 /* Assert that ipif_ire is not deleted yet. */
4763 ASSERT(ipif_ire
->ire_ptpn
!= NULL
);
4764 IRB_REFRELE(ipif_ire
->ire_bucket
);
4765 ire_refrele(ipif_ire
);
4767 if (copy_mp
!= NULL
) {
4769 * Search for the next unresolved
4775 /* re-enter the loop */
4776 multirt_resolve_next
= B_TRUE
;
4780 ill_refrele(dst_ill
);
4781 ipif_refrele(src_ipif
);
4784 case IRE_IF_NORESOLVER
:
4786 * We have what we need to build an IRE_CACHE.
4788 * handle the Gated case, where we create
4789 * a NORESOLVER route for loopback.
4791 if (dst_ill
->ill_net_type
!= IRE_IF_NORESOLVER
)
4794 * TSol note: We are creating the ire cache for the
4795 * destination 'dst'. If 'dst' is offlink, going
4796 * through the first hop 'gw', the security attributes
4797 * of 'dst' must be set to point to the gateway
4798 * credentials of gateway 'gw'. If 'dst' is onlink, it
4799 * is possible that 'dst' is a potential gateway that is
4800 * referenced by some route that has some security
4801 * attributes. Thus in the former case, we need to do a
4802 * gcgrp_lookup of 'gw' while in the latter case we
4803 * need to do gcgrp_lookup of 'dst' itself.
4805 ga
.ga_af
= AF_INET6
;
4806 if (!IN6_IS_ADDR_UNSPECIFIED(&v6gw
))
4809 ga
.ga_addr
= *v6dstp
;
4810 gcgrp
= gcgrp_lookup(&ga
, B_FALSE
);
4813 * Note: the new ire inherits sire flags RTF_SETSRC
4814 * and RTF_MULTIRT to propagate those rules from prefix
4817 ire
= ire_create_v6(
4818 v6dstp
, /* dest address */
4819 &ipv6_all_ones
, /* mask */
4820 &src_ipif
->ipif_v6src_addr
, /* source address */
4821 &v6gw
, /* gateway address */
4822 &save_ire
->ire_max_frag
,
4823 NULL
, /* no src nce */
4824 dst_ill
->ill_rq
, /* recv-from queue */
4825 dst_ill
->ill_wq
, /* send-to queue */
4828 &save_ire
->ire_mask_v6
, /* Parent mask */
4829 (sire
!= NULL
) ? /* Parent handle */
4830 sire
->ire_phandle
: 0,
4831 save_ire
->ire_ihandle
, /* Interface handle */
4832 (sire
!= NULL
) ? /* flags if any */
4834 (RTF_SETSRC
| RTF_MULTIRT
) : 0,
4835 &(save_ire
->ire_uinfo
),
4841 if (gcgrp
!= NULL
) {
4842 GCGRP_REFRELE(gcgrp
);
4845 ire_refrele(save_ire
);
4849 /* reference now held by IRE */
4852 ire
->ire_marks
|= ire_marks
;
4854 if (!IN6_IS_ADDR_UNSPECIFIED(&v6gw
))
4858 err
= ndp_noresolver(dst_ill
, &dst
);
4860 ire_refrele(save_ire
);
4864 /* Prevent save_ire from getting deleted */
4865 IRB_REFHOLD(save_ire
->ire_bucket
);
4866 /* Has it been removed already ? */
4867 if (save_ire
->ire_marks
& IRE_MARK_CONDEMNED
) {
4868 IRB_REFRELE(save_ire
->ire_bucket
);
4869 ire_refrele(save_ire
);
4875 * In case of MULTIRT, a copy of the current packet
4876 * to send is made to further re-enter the
4877 * loop and attempt another route resolution
4879 if ((sire
!= NULL
) && sire
->ire_flags
& RTF_MULTIRT
) {
4880 copy_mp
= copymsg(first_mp
);
4881 if (copy_mp
!= NULL
) {
4883 MULTIRT_DEBUG_TAG(first_mp
);
4886 ire_add_then_send(q
, ire
, xmit_mp
);
4887 if (ip6_asp_table_held
) {
4888 ip6_asp_table_refrele(ipst
);
4889 ip6_asp_table_held
= B_FALSE
;
4892 /* Assert that it is not deleted yet. */
4893 ASSERT(save_ire
->ire_ptpn
!= NULL
);
4894 IRB_REFRELE(save_ire
->ire_bucket
);
4895 ire_refrele(save_ire
);
4897 if (copy_mp
!= NULL
) {
4899 * If we found a (no)resolver, we ignore any
4900 * trailing top priority IRE_CACHE in
4901 * further loops. This ensures that we do not
4902 * omit any (no)resolver despite the priority
4904 * IRE_CACHE, if any, will be processed
4905 * by another thread entering ip_newroute(),
4906 * (on resolver response, for example).
4907 * We use this to force multiple parallel
4908 * resolution as soon as a packet needs to be
4909 * sent. The result is, after one packet
4910 * emission all reachable routes are generally
4912 * Otherwise, complete resolution of MULTIRT
4913 * routes would require several emissions as
4916 multirt_flags
&= ~MULTIRT_CACHEGW
;
4919 * Search for the next unresolved multirt
4925 /* re-enter the loop */
4926 multirt_resolve_next
= B_TRUE
;
4930 /* Don't need sire anymore */
4933 ill_refrele(dst_ill
);
4934 ipif_refrele(src_ipif
);
4937 case IRE_IF_RESOLVER
:
4939 * We can't build an IRE_CACHE yet, but at least we
4940 * found a resolver that can help.
4945 * To be at this point in the code with a non-zero gw
4946 * means that dst is reachable through a gateway that
4947 * we have never resolved. By changing dst to the gw
4948 * addr we resolve the gateway first. When
4949 * ire_add_then_send() tries to put the IP dg to dst,
4950 * it will reenter ip_newroute() at which time we will
4951 * find the IRE_CACHE for the gw and create another
4952 * IRE_CACHE above (for dst itself).
4954 if (!IN6_IS_ADDR_UNSPECIFIED(&v6gw
)) {
4957 v6gw
= ipv6_all_zeros
;
4959 if (dst_ill
->ill_flags
& ILLF_XRESOLV
) {
4961 * Ask the external resolver to do its thing.
4962 * Make an mblk chain in the following form:
4963 * ARQ_REQ_MBLK-->IRE_MBLK-->packet
4970 ip1dbg(("ip_newroute_v6:ILLF_XRESOLV\n"));
4971 if (ip6_asp_table_held
) {
4972 ip6_asp_table_refrele(ipst
);
4973 ip6_asp_table_held
= B_FALSE
;
4975 ire
= ire_create_mp_v6(
4976 &dst
, /* dest address */
4977 &ipv6_all_ones
, /* mask */
4978 &src_ipif
->ipif_v6src_addr
,
4979 /* source address */
4980 &v6gw
, /* gateway address */
4981 NULL
, /* no src nce */
4982 dst_ill
->ill_rq
, /* recv-from queue */
4983 dst_ill
->ill_wq
, /* send-to queue */
4986 &save_ire
->ire_mask_v6
, /* Parent mask */
4988 save_ire
->ire_ihandle
,
4989 /* Interface handle */
4990 0, /* flags if any */
4991 &(save_ire
->ire_uinfo
),
4996 ire_refrele(save_ire
);
4998 ip1dbg(("ip_newroute_v6:"
5003 if ((sire
!= NULL
) &&
5004 (sire
->ire_flags
& RTF_MULTIRT
)) {
5006 * processing a copy of the packet to
5007 * send for further resolution loops
5009 copy_mp
= copymsg(first_mp
);
5010 if (copy_mp
!= NULL
)
5011 MULTIRT_DEBUG_TAG(copy_mp
);
5013 ire
->ire_marks
|= ire_marks
;
5014 ire_mp
= ire
->ire_mp
;
5016 * Now create or find an nce for this interface.
5017 * The hw addr will need to to be set from
5018 * the reply to the AR_ENTRY_QUERY that
5019 * we're about to send. This will be done in
5022 err
= ndp_resolver(dst_ill
, &dst
, mp
, zoneid
);
5026 * New cache entry created.
5027 * Break, then ask the external
5033 * Resolution in progress;
5034 * packet has been queued by
5040 * Check if another multirt
5041 * route must be resolved.
5043 if (copy_mp
!= NULL
) {
5045 * If we found a resolver, we
5046 * ignore any trailing top
5047 * priority IRE_CACHE in
5048 * further loops. The reason is
5049 * the same as for noresolver.
5054 * Search for the next
5055 * unresolved multirt route.
5060 if (mp
->b_datap
->db_type
==
5064 ASSERT(sire
!= NULL
);
5069 multirt_resolve_next
=
5076 ill_refrele(dst_ill
);
5077 ipif_refrele(src_ipif
);
5081 * Transient error; packet will be
5091 * Now set up the AR_ENTRY_QUERY and send it.
5093 areq_mp
= ill_arp_alloc(dst_ill
,
5094 (uchar_t
*)&ipv6_areq_template
,
5096 if (areq_mp
== NULL
) {
5097 ip1dbg(("ip_newroute_v6:"
5098 "areq_mp is NULL\n"));
5102 areq
= (areq_t
*)areq_mp
->b_rptr
;
5103 addrp
= (in6_addr_t
*)((char *)areq
+
5104 areq
->areq_target_addr_offset
);
5106 addrp
= (in6_addr_t
*)((char *)areq
+
5107 areq
->areq_sender_addr_offset
);
5108 *addrp
= src_ipif
->ipif_v6src_addr
;
5110 * link the chain, then send up to the resolver.
5112 linkb(areq_mp
, ire_mp
);
5114 ip1dbg(("ip_newroute_v6:"
5115 "putnext to resolver\n"));
5116 putnext(dst_ill
->ill_rq
, areq_mp
);
5118 * Check if another multirt route
5122 if (copy_mp
!= NULL
) {
5124 * If we find a resolver, we ignore any
5125 * trailing top priority IRE_CACHE in
5126 * further loops. The reason is the
5127 * same as for noresolver.
5129 multirt_flags
&= ~MULTIRT_CACHEGW
;
5131 * Search for the next unresolved
5137 if (mp
->b_datap
->db_type
== M_CTL
) {
5140 ASSERT(sire
!= NULL
);
5145 multirt_resolve_next
= B_TRUE
;
5151 ill_refrele(dst_ill
);
5152 ipif_refrele(src_ipif
);
5156 * Non-external resolver case.
5158 * TSol note: Please see the note above the
5159 * IRE_IF_NORESOLVER case.
5161 ga
.ga_af
= AF_INET6
;
5163 gcgrp
= gcgrp_lookup(&ga
, B_FALSE
);
5165 ire
= ire_create_v6(
5166 &dst
, /* dest address */
5167 &ipv6_all_ones
, /* mask */
5168 &src_ipif
->ipif_v6src_addr
, /* source address */
5169 &v6gw
, /* gateway address */
5170 &save_ire
->ire_max_frag
,
5171 NULL
, /* no src nce */
5172 dst_ill
->ill_rq
, /* recv-from queue */
5173 dst_ill
->ill_wq
, /* send-to queue */
5176 &save_ire
->ire_mask_v6
, /* Parent mask */
5178 save_ire
->ire_ihandle
, /* Interface handle */
5179 0, /* flags if any */
5180 &(save_ire
->ire_uinfo
),
5186 if (gcgrp
!= NULL
) {
5187 GCGRP_REFRELE(gcgrp
);
5190 ire_refrele(save_ire
);
5194 /* reference now held by IRE */
5197 if ((sire
!= NULL
) &&
5198 (sire
->ire_flags
& RTF_MULTIRT
)) {
5199 copy_mp
= copymsg(first_mp
);
5200 if (copy_mp
!= NULL
)
5201 MULTIRT_DEBUG_TAG(copy_mp
);
5204 ire
->ire_marks
|= ire_marks
;
5205 err
= ndp_resolver(dst_ill
, &dst
, first_mp
, zoneid
);
5208 /* Prevent save_ire from getting deleted */
5209 IRB_REFHOLD(save_ire
->ire_bucket
);
5210 /* Has it been removed already ? */
5211 if (save_ire
->ire_marks
& IRE_MARK_CONDEMNED
) {
5212 IRB_REFRELE(save_ire
->ire_bucket
);
5213 ire_refrele(save_ire
);
5218 * We have a resolved cache entry,
5221 ire_add_then_send(q
, ire
, first_mp
);
5222 if (ip6_asp_table_held
) {
5223 ip6_asp_table_refrele(ipst
);
5224 ip6_asp_table_held
= B_FALSE
;
5227 /* Assert that it is not deleted yet. */
5228 ASSERT(save_ire
->ire_ptpn
!= NULL
);
5229 IRB_REFRELE(save_ire
->ire_bucket
);
5230 ire_refrele(save_ire
);
5232 * Check if another multirt route
5236 if (copy_mp
!= NULL
) {
5238 * If we find a resolver, we ignore any
5239 * trailing top priority IRE_CACHE in
5240 * further loops. The reason is the
5241 * same as for noresolver.
5243 multirt_flags
&= ~MULTIRT_CACHEGW
;
5245 * Search for the next unresolved
5251 if (mp
->b_datap
->db_type
== M_CTL
) {
5254 ASSERT(sire
!= NULL
);
5259 multirt_resolve_next
= B_TRUE
;
5265 ill_refrele(dst_ill
);
5266 ipif_refrele(src_ipif
);
5271 * mp was consumed - presumably queued.
5272 * No need for ire, presumably resolution is
5273 * in progress, and ire will be added when the
5274 * address is resolved.
5276 if (ip6_asp_table_held
) {
5277 ip6_asp_table_refrele(ipst
);
5278 ip6_asp_table_held
= B_FALSE
;
5280 ASSERT(ire
->ire_nce
== NULL
);
5282 ire_refrele(save_ire
);
5284 * Check if another multirt route
5288 if (copy_mp
!= NULL
) {
5290 * If we find a resolver, we ignore any
5291 * trailing top priority IRE_CACHE in
5292 * further loops. The reason is the
5293 * same as for noresolver.
5295 multirt_flags
&= ~MULTIRT_CACHEGW
;
5297 * Search for the next unresolved
5303 if (mp
->b_datap
->db_type
== M_CTL
) {
5306 ASSERT(sire
!= NULL
);
5311 multirt_resolve_next
= B_TRUE
;
5316 ill_refrele(dst_ill
);
5317 ipif_refrele(src_ipif
);
5320 /* Some transient error */
5321 ASSERT(ire
->ire_nce
== NULL
);
5322 ire_refrele(save_ire
);
5329 if (ip6_asp_table_held
) {
5330 ip6_asp_table_refrele(ipst
);
5331 ip6_asp_table_held
= B_FALSE
;
5333 } while (multirt_resolve_next
);
5336 ip1dbg(("ip_newroute_v6: dropped\n"));
5337 if (src_ipif
!= NULL
)
5338 ipif_refrele(src_ipif
);
5339 if (dst_ill
!= NULL
) {
5344 if (mp
->b_prev
!= NULL
) {
5345 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
5347 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
5353 if (mp
->b_prev
!= NULL
) {
5354 BUMP_MIB(&ipst
->ips_ip6_mib
, ipIfStatsInDiscards
);
5356 BUMP_MIB(&ipst
->ips_ip6_mib
, ipIfStatsOutDiscards
);
5359 /* Did this packet originate externally? */
5364 if (copy_mp
!= NULL
) {
5365 MULTIRT_DEBUG_UNTAG(copy_mp
);
5368 MULTIRT_DEBUG_UNTAG(first_mp
);
5377 if (ip6_asp_table_held
)
5378 ip6_asp_table_refrele(ipst
);
5379 if (src_ipif
!= NULL
)
5380 ipif_refrele(src_ipif
);
5381 if (dst_ill
!= NULL
) {
5385 ip1dbg(("ip_newroute_v6: no route\n"));
5389 * We need to set sire to NULL to avoid double freeing if we
5390 * ever goto err_ret from below.
5393 ip6h
= (ip6_t
*)mp
->b_rptr
;
5394 /* Skip ip6i_t header if present */
5395 if (ip6h
->ip6_nxt
== IPPROTO_RAW
) {
5396 /* Make sure the IPv6 header is present */
5397 if ((mp
->b_wptr
- (uchar_t
*)ip6h
) <
5398 sizeof (ip6i_t
) + IPV6_HDR_LEN
) {
5399 if (!pullupmsg(mp
, sizeof (ip6i_t
) + IPV6_HDR_LEN
)) {
5400 ip1dbg(("ip_newroute_v6: pullupmsg failed\n"));
5404 mp
->b_rptr
+= sizeof (ip6i_t
);
5405 ip6h
= (ip6_t
*)mp
->b_rptr
;
5407 /* Did this packet originate externally? */
5410 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInNoRoutes
);
5412 BUMP_MIB(&ipst
->ips_ip6_mib
, ipIfStatsInNoRoutes
);
5419 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutNoRoutes
);
5421 BUMP_MIB(&ipst
->ips_ip6_mib
, ipIfStatsOutNoRoutes
);
5423 if (ip_hdr_complete_v6(ip6h
, zoneid
, ipst
)) {
5425 if (copy_mp
!= NULL
) {
5426 MULTIRT_DEBUG_UNTAG(copy_mp
);
5429 MULTIRT_DEBUG_UNTAG(first_mp
);
5443 * At this point we will have ire only if RTF_BLACKHOLE
5444 * or RTF_REJECT flags are set on the IRE. It will not
5445 * generate ICMP6_DST_UNREACH_NOROUTE if RTF_BLACKHOLE is set.
5448 if (ire
->ire_flags
& RTF_BLACKHOLE
) {
5450 if (copy_mp
!= NULL
) {
5451 MULTIRT_DEBUG_UNTAG(copy_mp
);
5454 MULTIRT_DEBUG_UNTAG(first_mp
);
5462 pr_addr_dbg("ip_newroute_v6: no route to %s\n",
5465 icmp_unreachable_v6(WR(q
), first_mp
, ICMP6_DST_UNREACH_NOROUTE
,
5466 B_FALSE
, B_FALSE
, zoneid
, ipst
);
5470 * ip_newroute_ipif_v6 is called by ip_wput_v6 and ip_wput_ipsec_out_v6 whenever
5471 * we need to send out a packet to a destination address for which we do not
5472 * have specific routing information. It is only used for multicast packets.
5474 * If unspec_src we allow creating an IRE with source address zero.
5475 * ire_send_v6() will delete it after the packet is sent.
5478 ip_newroute_ipif_v6(queue_t
*q
, mblk_t
*mp
, ipif_t
*ipif
,
5479 const in6_addr_t
*v6dstp
, const in6_addr_t
*v6srcp
, int unspec_src
,
5483 ipif_t
*src_ipif
= NULL
;
5485 ill_t
*dst_ill
= NULL
;
5491 mblk_t
*copy_mp
= NULL
;
5492 const in6_addr_t
*ire_v6srcp
;
5493 boolean_t probe
= B_FALSE
;
5494 boolean_t multirt_resolve_next
;
5495 boolean_t ipif_held
= B_FALSE
;
5496 boolean_t ill_held
= B_FALSE
;
5497 boolean_t ip6_asp_table_held
= B_FALSE
;
5498 ip_stack_t
*ipst
= ipif
->ipif_ill
->ill_ipst
;
5501 * This loop is run only once in most cases.
5502 * We loop to resolve further routes only when the destination
5503 * can be reached through multiple RTF_MULTIRT-flagged ires.
5506 multirt_resolve_next
= B_FALSE
;
5507 if (dst_ill
!= NULL
) {
5508 ill_refrele(dst_ill
);
5512 if (src_ipif
!= NULL
) {
5513 ipif_refrele(src_ipif
);
5516 ASSERT(ipif
!= NULL
);
5517 ill
= ipif
->ipif_ill
;
5519 ASSERT(!IN6_IS_ADDR_V4MAPPED(v6dstp
));
5522 pr_addr_dbg("ip_newroute_ipif_v6: v6dst %s\n",
5524 printf("ip_newroute_ipif_v6: if %s, v6 %d\n",
5525 ill
->ill_name
, ipif
->ipif_isv6
);
5529 if (mp
->b_datap
->db_type
== M_CTL
) {
5531 io
= (ipsec_out_t
*)first_mp
->b_rptr
;
5532 ASSERT(io
->ipsec_out_type
== IPSEC_OUT
);
5538 * If the interface is a pt-pt interface we look for an
5539 * IRE_IF_RESOLVER or IRE_IF_NORESOLVER that matches both the
5540 * local_address and the pt-pt destination address.
5541 * Otherwise we just match the local address.
5543 if (!(ill
->ill_flags
& ILLF_MULTICAST
)) {
5548 * We check if an IRE_OFFSUBNET for the addr that goes through
5549 * ipif exists. We need it to determine if the RTF_SETSRC and/or
5550 * RTF_MULTIRT flags must be honored.
5552 fire
= ipif_lookup_multi_ire_v6(ipif
, v6dstp
);
5553 ip2dbg(("ip_newroute_ipif_v6: "
5554 "ipif_lookup_multi_ire_v6("
5555 "ipif %p, dst %08x) = fire %p\n",
5556 (void *)ipif
, ntohl(V4_PART_OF_V6((*v6dstp
))),
5559 ASSERT(src_ipif
== NULL
);
5562 * Because nce_xmit() calls ip_output_v6() and NCEs are always
5563 * tied to the underlying interface, IS_UNDER_IPMP() may be
5564 * true even when building IREs that will be used for data
5565 * traffic. As such, see if the packet's source address is a
5566 * test address, and if so use that test address's ipif for
5567 * the IRE so that the logic that sets IRE_MARK_TESTHIDDEN in
5568 * ire_add_v6() can work properly.
5570 if (IS_UNDER_IPMP(ill
))
5571 probe
= ipif_lookup_testaddr_v6(ill
, v6srcp
, &src_ipif
);
5574 * Determine the outbound (destination) ill for this route.
5575 * If IPMP is not in use, that's the same as our ill. If IPMP
5576 * is in-use and we're on the IPMP interface, or we're on an
5577 * underlying ill but sending data traffic, use a suitable
5578 * destination ill from the group. The latter case covers a
5579 * subtle edge condition with multicast: when we bring up an
5580 * IPv6 data address, we will create an NCE on an underlying
5581 * interface, and send solitications to ff02::1, which would
5582 * take us through here, and cause us to create an IRE for
5583 * ff02::1. To meet our defined semantics for multicast (and
5584 * ensure there aren't unexpected echoes), that IRE needs to
5585 * use the IPMP group's nominated multicast interface.
5587 * Note: the source ipif is determined by source address
5590 if (IS_IPMP(ill
) || (IS_UNDER_IPMP(ill
) && !probe
)) {
5592 ipmp_illgrp_t
*illg
;
5594 if (IS_UNDER_IPMP(ill
)) {
5595 ipmp_ill
= ipmp_ill_hold_ipmp_ill(ill
);
5598 ill_refhold(ipmp_ill
); /* for symmetry */
5601 if (ipmp_ill
== NULL
)
5604 illg
= ipmp_ill
->ill_grp
;
5605 if (IN6_IS_ADDR_MULTICAST(v6dstp
))
5606 dst_ill
= ipmp_illgrp_hold_cast_ill(illg
);
5608 dst_ill
= ipmp_illgrp_hold_next_ill(illg
);
5610 ill_refrele(ipmp_ill
);
5613 ill_refhold(dst_ill
); /* for symmetry */
5616 if (dst_ill
== NULL
) {
5618 pr_addr_dbg("ip_newroute_ipif_v6: "
5619 "no dst ill for dst %s\n",
5626 * Pick a source address which matches the scope of the
5627 * destination address.
5628 * For RTF_SETSRC routes, the source address is imposed by the
5629 * parent ire (fire).
5632 if (src_ipif
== NULL
&& fire
!= NULL
&&
5633 (fire
->ire_flags
& RTF_SETSRC
)) {
5635 * Check that the ipif matching the requested source
5636 * address still exists.
5638 src_ipif
= ipif_lookup_addr_v6(&fire
->ire_src_addr_v6
,
5639 NULL
, zoneid
, NULL
, NULL
, NULL
, NULL
, ipst
);
5642 if (src_ipif
== NULL
&& ip6_asp_can_lookup(ipst
)) {
5643 ip6_asp_table_held
= B_TRUE
;
5644 src_ipif
= ipif_select_source_v6(dst_ill
, v6dstp
,
5645 B_FALSE
, IPV6_PREFER_SRC_DEFAULT
, zoneid
);
5648 if (src_ipif
== NULL
) {
5652 pr_addr_dbg("ip_newroute_ipif_v6: "
5653 "no src for dst %s\n",
5655 printf(" through interface %s\n",
5660 ire_v6srcp
= &ipv6_all_zeros
;
5662 ipif_refhold(src_ipif
);
5664 ire_v6srcp
= &src_ipif
->ipif_v6src_addr
;
5667 ire
= ipif_to_ire_v6(ipif
);
5671 pr_addr_dbg("ip_newroute_ipif_v6: v6src %s\n",
5672 AF_INET6
, &ipif
->ipif_v6lcl_addr
);
5673 printf("ip_newroute_ipif_v6: "
5674 "if %s\n", dst_ill
->ill_name
);
5678 if (ire
->ire_flags
& (RTF_REJECT
| RTF_BLACKHOLE
))
5681 ASSERT(ire
->ire_ipversion
== IPV6_VERSION
);
5683 ip1dbg(("ip_newroute_ipif_v6: interface type %s (%d),",
5684 ip_nv_lookup(ire_nv_tbl
, ire
->ire_type
), ire
->ire_type
));
5687 pr_addr_dbg(" address %s\n",
5688 AF_INET6
, &ire
->ire_src_addr_v6
);
5691 ip2dbg(("ip_newroute_ipif: ire %p, ipif %p\n",
5692 (void *)ire
, (void *)ipif
));
5694 if ((fire
!= NULL
) && (fire
->ire_flags
& RTF_MULTIRT
)) {
5696 * an IRE_OFFSUBET was looked up
5697 * on that interface.
5698 * this ire has RTF_MULTIRT flag,
5699 * so the resolution loop
5700 * will be re-entered to resolve
5701 * additional routes on other
5702 * interfaces. For that purpose,
5703 * a copy of the packet is
5704 * made at this point.
5706 fire
->ire_last_used_time
= lbolt
;
5707 copy_mp
= copymsg(first_mp
);
5709 MULTIRT_DEBUG_TAG(copy_mp
);
5713 switch (ire
->ire_type
) {
5714 case IRE_IF_NORESOLVER
: {
5716 * We have what we need to build an IRE_CACHE.
5718 * handle the Gated case, where we create
5719 * a NORESOLVER route for loopback.
5721 if (dst_ill
->ill_net_type
!= IRE_IF_NORESOLVER
)
5724 * The newly created ire will inherit the flags of the
5725 * parent ire, if any.
5727 ire
= ire_create_v6(
5728 v6dstp
, /* dest address */
5729 &ipv6_all_ones
, /* mask */
5730 ire_v6srcp
, /* source address */
5731 NULL
, /* gateway address */
5732 &save_ire
->ire_max_frag
,
5733 NULL
, /* no src nce */
5734 dst_ill
->ill_rq
, /* recv-from queue */
5735 dst_ill
->ill_wq
, /* send-to queue */
5739 (fire
!= NULL
) ? /* Parent handle */
5740 fire
->ire_phandle
: 0,
5741 save_ire
->ire_ihandle
, /* Interface handle */
5743 (fire
->ire_flags
& (RTF_SETSRC
| RTF_MULTIRT
)) :
5751 ire_refrele(save_ire
);
5755 err
= ndp_noresolver(dst_ill
, v6dstp
);
5757 ire_refrele(save_ire
);
5761 /* Prevent save_ire from getting deleted */
5762 IRB_REFHOLD(save_ire
->ire_bucket
);
5763 /* Has it been removed already ? */
5764 if (save_ire
->ire_marks
& IRE_MARK_CONDEMNED
) {
5765 IRB_REFRELE(save_ire
->ire_bucket
);
5766 ire_refrele(save_ire
);
5770 ire_add_then_send(q
, ire
, first_mp
);
5771 if (ip6_asp_table_held
) {
5772 ip6_asp_table_refrele(ipst
);
5773 ip6_asp_table_held
= B_FALSE
;
5776 /* Assert that it is not deleted yet. */
5777 ASSERT(save_ire
->ire_ptpn
!= NULL
);
5778 IRB_REFRELE(save_ire
->ire_bucket
);
5779 ire_refrele(save_ire
);
5786 * The resolution loop is re-entered if we
5787 * actually are in a multirouting case.
5789 if (copy_mp
!= NULL
) {
5790 boolean_t need_resolve
=
5791 ire_multirt_need_resolve_v6(v6dstp
,
5792 msg_getlabel(copy_mp
), ipst
);
5793 if (!need_resolve
) {
5794 MULTIRT_DEBUG_UNTAG(copy_mp
);
5799 * ipif_lookup_group_v6() calls
5800 * ire_lookup_multi_v6() that uses
5801 * ire_ftable_lookup_v6() to find
5802 * an IRE_INTERFACE for the group.
5803 * In the multirt case,
5804 * ire_lookup_multi_v6() then invokes
5805 * ire_multirt_lookup_v6() to find
5806 * the next resolvable ire.
5807 * As a result, we obtain a new
5808 * interface, derived from the
5813 ipif_held
= B_FALSE
;
5815 ipif
= ipif_lookup_group_v6(v6dstp
,
5817 ip2dbg(("ip_newroute_ipif: "
5818 "multirt dst %08x, ipif %p\n",
5819 ntohl(V4_PART_OF_V6((*v6dstp
))),
5825 multirt_resolve_next
=
5833 ill_refrele(dst_ill
);
5836 ipif_held
= B_FALSE
;
5838 if (src_ipif
!= NULL
)
5839 ipif_refrele(src_ipif
);
5842 case IRE_IF_RESOLVER
: {
5844 ASSERT(dst_ill
->ill_isv6
);
5847 * We obtain a partial IRE_CACHE which we will pass
5848 * along with the resolver query. When the response
5849 * comes back it will be there ready for us to add.
5852 * the newly created ire will inherit the flags of the
5853 * parent ire, if any.
5855 ire
= ire_create_v6(
5856 v6dstp
, /* dest address */
5857 &ipv6_all_ones
, /* mask */
5858 ire_v6srcp
, /* source address */
5859 NULL
, /* gateway address */
5860 &save_ire
->ire_max_frag
,
5862 dst_ill
->ill_rq
, /* recv-from queue */
5863 dst_ill
->ill_wq
, /* send-to queue */
5867 (fire
!= NULL
) ? /* Parent handle */
5868 fire
->ire_phandle
: 0,
5869 save_ire
->ire_ihandle
, /* Interface handle */
5871 (fire
->ire_flags
& (RTF_SETSRC
| RTF_MULTIRT
)) :
5879 ire_refrele(save_ire
);
5883 /* Resolve and add ire to the ctable */
5884 err
= ndp_resolver(dst_ill
, v6dstp
, first_mp
, zoneid
);
5887 /* Prevent save_ire from getting deleted */
5888 IRB_REFHOLD(save_ire
->ire_bucket
);
5889 /* Has it been removed already ? */
5890 if (save_ire
->ire_marks
& IRE_MARK_CONDEMNED
) {
5891 IRB_REFRELE(save_ire
->ire_bucket
);
5892 ire_refrele(save_ire
);
5896 * We have a resolved cache entry,
5899 ire_add_then_send(q
, ire
, first_mp
);
5900 if (ip6_asp_table_held
) {
5901 ip6_asp_table_refrele(ipst
);
5902 ip6_asp_table_held
= B_FALSE
;
5905 /* Assert that it is not deleted yet. */
5906 ASSERT(save_ire
->ire_ptpn
!= NULL
);
5907 IRB_REFRELE(save_ire
->ire_bucket
);
5908 ire_refrele(save_ire
);
5915 * The resolution loop is re-entered if we
5916 * actually are in a multirouting case.
5918 if (copy_mp
!= NULL
) {
5919 boolean_t need_resolve
=
5920 ire_multirt_need_resolve_v6(v6dstp
,
5921 msg_getlabel(copy_mp
), ipst
);
5922 if (!need_resolve
) {
5923 MULTIRT_DEBUG_UNTAG(copy_mp
);
5928 * ipif_lookup_group_v6() calls
5929 * ire_lookup_multi_v6() that
5930 * uses ire_ftable_lookup_v6()
5931 * to find an IRE_INTERFACE for
5932 * the group. In the multirt
5933 * case, ire_lookup_multi_v6()
5935 * ire_multirt_lookup_v6() to
5936 * find the next resolvable ire.
5937 * As a result, we obtain a new
5938 * interface, derived from the
5943 ipif_held
= B_FALSE
;
5945 ipif
= ipif_lookup_group_v6(
5946 v6dstp
, zoneid
, ipst
);
5947 ip2dbg(("ip_newroute_ipif: "
5948 "multirt dst %08x, "
5950 ntohl(V4_PART_OF_V6(
5957 multirt_resolve_next
=
5965 ill_refrele(dst_ill
);
5968 ipif_held
= B_FALSE
;
5970 if (src_ipif
!= NULL
)
5971 ipif_refrele(src_ipif
);
5976 * mp was consumed - presumably queued.
5977 * No need for ire, presumably resolution is
5978 * in progress, and ire will be added when the
5979 * address is resolved.
5981 if (ip6_asp_table_held
) {
5982 ip6_asp_table_refrele(ipst
);
5983 ip6_asp_table_held
= B_FALSE
;
5986 ire_refrele(save_ire
);
5993 * The resolution loop is re-entered if we
5994 * actually are in a multirouting case.
5996 if (copy_mp
!= NULL
) {
5997 boolean_t need_resolve
=
5998 ire_multirt_need_resolve_v6(v6dstp
,
5999 msg_getlabel(copy_mp
), ipst
);
6000 if (!need_resolve
) {
6001 MULTIRT_DEBUG_UNTAG(copy_mp
);
6006 * ipif_lookup_group_v6() calls
6007 * ire_lookup_multi_v6() that
6008 * uses ire_ftable_lookup_v6()
6009 * to find an IRE_INTERFACE for
6010 * the group. In the multirt
6011 * case, ire_lookup_multi_v6()
6013 * ire_multirt_lookup_v6() to
6014 * find the next resolvable ire.
6015 * As a result, we obtain a new
6016 * interface, derived from the
6021 ipif_held
= B_FALSE
;
6023 ipif
= ipif_lookup_group_v6(
6024 v6dstp
, zoneid
, ipst
);
6025 ip2dbg(("ip_newroute_ipif: "
6026 "multirt dst %08x, "
6028 ntohl(V4_PART_OF_V6(
6035 multirt_resolve_next
=
6043 ill_refrele(dst_ill
);
6046 ipif_held
= B_FALSE
;
6048 if (src_ipif
!= NULL
)
6049 ipif_refrele(src_ipif
);
6052 /* Some transient error */
6053 ire_refrele(save_ire
);
6061 if (ip6_asp_table_held
) {
6062 ip6_asp_table_refrele(ipst
);
6063 ip6_asp_table_held
= B_FALSE
;
6065 } while (multirt_resolve_next
);
6068 if (ip6_asp_table_held
)
6069 ip6_asp_table_refrele(ipst
);
6074 if (ipif
!= NULL
&& ipif_held
)
6076 if (src_ipif
!= NULL
)
6077 ipif_refrele(src_ipif
);
6079 /* Multicast - no point in trying to generate ICMP error */
6080 if (dst_ill
!= NULL
) {
6084 if (mp
->b_prev
|| mp
->b_next
) {
6085 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
6087 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
6089 ip1dbg(("ip_newroute_ipif_v6: dropped\n"));
6098 * Parse and process any hop-by-hop or destination options.
6100 * Assumes that q is an ill read queue so that ICMP errors for link-local
6101 * destinations are sent out the correct interface.
6103 * Returns -1 if there was an error and mp has been consumed.
6104 * Returns 0 if no special action is needed.
6105 * Returns 1 if the packet contained a router alert option for this node
6106 * which is verified to be "interesting/known" for our implementation.
6108 * XXX Note: In future as more hbh or dest options are defined,
6109 * it may be better to have different routines for hbh and dest
6110 * options as opt_type fields other than IP6OPT_PAD1 and IP6OPT_PADN
6111 * may have same value in different namespaces. Or is it same namespace ??
6112 * Current code checks for each opt_type (other than pads) if it is in
6113 * the expected nexthdr (hbh or dest)
6116 ip_process_options_v6(queue_t
*q
, mblk_t
*mp
, ip6_t
*ip6h
,
6117 uint8_t *optptr
, uint_t optlen
, uint8_t hdr_type
, ip_stack_t
*ipst
)
6123 const char *errtype
;
6125 ill_t
*ill
= q
->q_ptr
;
6129 if (mp
->b_datap
->db_type
== M_CTL
) {
6133 while (optlen
!= 0) {
6135 if (opt_type
== IP6OPT_PAD1
) {
6140 errtype
= "malformed";
6141 if (opt_type
== ip6opt_ls
) {
6142 optused
= 2 + optptr
[1];
6143 if (optused
> optlen
)
6145 } else switch (opt_type
) {
6148 * Note:We don't verify that (N-2) pad octets
6149 * are zero as required by spec. Adhere to
6150 * "be liberal in what you accept..." part of
6151 * implementation philosophy (RFC791,RFC1122)
6153 optused
= 2 + optptr
[1];
6154 if (optused
> optlen
)
6159 if (hdr_type
!= IPPROTO_HOPOPTS
)
6161 goto opt_error
; /* XXX Not implemented! */
6163 case IP6OPT_ROUTER_ALERT
: {
6164 struct ip6_opt_router
*or;
6166 if (hdr_type
!= IPPROTO_HOPOPTS
)
6168 optused
= 2 + optptr
[1];
6169 if (optused
> optlen
)
6171 or = (struct ip6_opt_router
*)optptr
;
6172 /* Check total length and alignment */
6173 if (optused
!= sizeof (*or) ||
6174 ((uintptr_t)or->ip6or_value
& 0x1) != 0)
6177 switch (*((uint16_t *)or->ip6or_value
)) {
6179 case IP6_ALERT_RSVP
:
6184 case IP6OPT_HOME_ADDRESS
: {
6186 * Minimal support for the home address option
6187 * (which is required by all IPv6 nodes).
6188 * Implement by just swapping the home address
6189 * and source address.
6190 * XXX Note: this has IPsec implications since
6191 * AH needs to take this into account.
6192 * Also, when IPsec is used we need to ensure
6193 * that this is only processed once
6194 * in the received packet (to avoid swapping
6196 * NOTE:This option processing is considered
6197 * to be unsafe and prone to a denial of
6199 * The current processing is not safe even with
6200 * IPsec secured IP packets. Since the home
6201 * address option processing requirement still
6202 * is in the IETF draft and in the process of
6203 * being redefined for its usage, it has been
6204 * decided to turn off the option by default.
6205 * If this section of code needs to be executed,
6206 * ndd variable ip6_ignore_home_address_opt
6207 * should be set to 0 at the user's own risk.
6209 struct ip6_opt_home_address
*oh
;
6212 if (ipst
->ips_ipv6_ignore_home_address_opt
)
6215 if (hdr_type
!= IPPROTO_DSTOPTS
)
6217 optused
= 2 + optptr
[1];
6218 if (optused
> optlen
)
6222 * We did this dest. opt the first time
6223 * around (i.e. before AH processing).
6224 * If we've done AH... stop now.
6226 if (first_mp
!= mp
) {
6229 ii
= (ipsec_in_t
*)first_mp
->b_rptr
;
6230 if (ii
->ipsec_in_ah_sa
!= NULL
)
6234 oh
= (struct ip6_opt_home_address
*)optptr
;
6235 /* Check total length and alignment */
6236 if (optused
< sizeof (*oh
) ||
6237 ((uintptr_t)oh
->ip6oh_addr
& 0x7) != 0)
6239 /* Swap ip6_src and the home address */
6240 tmp
= ip6h
->ip6_src
;
6241 /* XXX Note: only 8 byte alignment option */
6242 ip6h
->ip6_src
= *(in6_addr_t
*)oh
->ip6oh_addr
;
6243 *(in6_addr_t
*)oh
->ip6oh_addr
= tmp
;
6247 case IP6OPT_TUNNEL_LIMIT
:
6248 if (hdr_type
!= IPPROTO_DSTOPTS
) {
6251 optused
= 2 + optptr
[1];
6252 if (optused
> optlen
) {
6261 errtype
= "unknown";
6264 /* Determine which zone should send error */
6265 zoneid
= ipif_lookup_addr_zoneid_v6(
6266 &ip6h
->ip6_dst
, ill
, ipst
);
6267 switch (IP6OPT_TYPE(opt_type
)) {
6268 case IP6OPT_TYPE_SKIP
:
6269 optused
= 2 + optptr
[1];
6270 if (optused
> optlen
)
6272 ip1dbg(("ip_process_options_v6: %s "
6273 "opt 0x%x skipped\n",
6274 errtype
, opt_type
));
6276 case IP6OPT_TYPE_DISCARD
:
6277 ip1dbg(("ip_process_options_v6: %s "
6278 "opt 0x%x; packet dropped\n",
6279 errtype
, opt_type
));
6282 case IP6OPT_TYPE_ICMP
:
6283 if (zoneid
== ALL_ZONES
) {
6287 icmp_param_problem_v6(WR(q
), first_mp
,
6288 ICMP6_PARAMPROB_OPTION
,
6291 B_FALSE
, B_FALSE
, zoneid
, ipst
);
6293 case IP6OPT_TYPE_FORCEICMP
:
6295 * If we don't have a zone and the dst
6296 * addr is multicast, then pick a zone
6297 * based on the inbound interface.
6299 if (zoneid
== ALL_ZONES
&&
6300 IN6_IS_ADDR_MULTICAST(
6302 ipif
= ipif_select_source_v6(
6303 ill
, &ip6h
->ip6_src
,
6305 IPV6_PREFER_SRC_DEFAULT
,
6313 if (zoneid
== ALL_ZONES
) {
6317 icmp_param_problem_v6(WR(q
), first_mp
,
6318 ICMP6_PARAMPROB_OPTION
,
6321 B_FALSE
, B_TRUE
, zoneid
, ipst
);
6334 /* Determine which zone should send error */
6335 zoneid
= ipif_lookup_addr_zoneid_v6(&ip6h
->ip6_dst
, ill
, ipst
);
6336 if (zoneid
== ALL_ZONES
) {
6339 icmp_param_problem_v6(WR(q
), first_mp
, ICMP6_PARAMPROB_OPTION
,
6340 (uint32_t)(optptr
- (uint8_t *)ip6h
),
6341 B_FALSE
, B_FALSE
, zoneid
, ipst
);
6347 * Process a routing header that is not yet empty.
6348 * Only handles type 0 routing headers.
6351 ip_process_rthdr(queue_t
*q
, mblk_t
*mp
, ip6_t
*ip6h
, ip6_rthdr_t
*rth
,
6352 ill_t
*ill
, uint_t flags
, mblk_t
*hada_mp
, mblk_t
*dl_mp
)
6354 ip6_rthdr0_t
*rthdr
;
6357 in6_addr_t
*addrptr
;
6359 ip_stack_t
*ipst
= ill
->ill_ipst
;
6361 ASSERT(rth
->ip6r_segleft
!= 0);
6363 if (!ipst
->ips_ipv6_forward_src_routed
) {
6364 /* XXX Check for source routed out same interface? */
6365 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsForwProhibits
);
6366 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInAddrErrors
);
6372 if (rth
->ip6r_type
!= 0) {
6373 if (hada_mp
!= NULL
)
6375 /* Sent by forwarding path, and router is global zone */
6376 icmp_param_problem_v6(WR(q
), mp
,
6377 ICMP6_PARAMPROB_HEADER
,
6378 (uint32_t)((uchar_t
*)&rth
->ip6r_type
- (uchar_t
*)ip6h
),
6379 B_FALSE
, B_FALSE
, GLOBAL_ZONEID
, ipst
);
6382 rthdr
= (ip6_rthdr0_t
*)rth
;
6383 ehdrlen
= 8 * (rthdr
->ip6r0_len
+ 1);
6384 ASSERT(mp
->b_rptr
+ ehdrlen
<= mp
->b_wptr
);
6385 addrptr
= (in6_addr_t
*)((char *)rthdr
+ sizeof (*rthdr
));
6386 /* rthdr->ip6r0_len is twice the number of addresses in the header */
6387 if (rthdr
->ip6r0_len
& 0x1) {
6388 /* An odd length is impossible */
6389 if (hada_mp
!= NULL
)
6391 /* Sent by forwarding path, and router is global zone */
6392 icmp_param_problem_v6(WR(q
), mp
,
6393 ICMP6_PARAMPROB_HEADER
,
6394 (uint32_t)((uchar_t
*)&rthdr
->ip6r0_len
- (uchar_t
*)ip6h
),
6395 B_FALSE
, B_FALSE
, GLOBAL_ZONEID
, ipst
);
6398 numaddr
= rthdr
->ip6r0_len
/ 2;
6399 if (rthdr
->ip6r0_segleft
> numaddr
) {
6400 /* segleft exceeds number of addresses in routing header */
6401 if (hada_mp
!= NULL
)
6403 /* Sent by forwarding path, and router is global zone */
6404 icmp_param_problem_v6(WR(q
), mp
,
6405 ICMP6_PARAMPROB_HEADER
,
6406 (uint32_t)((uchar_t
*)&rthdr
->ip6r0_segleft
-
6408 B_FALSE
, B_FALSE
, GLOBAL_ZONEID
, ipst
);
6411 addrptr
+= (numaddr
- rthdr
->ip6r0_segleft
);
6412 if (IN6_IS_ADDR_MULTICAST(&ip6h
->ip6_dst
) ||
6413 IN6_IS_ADDR_MULTICAST(addrptr
)) {
6414 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
6421 *addrptr
= ip6h
->ip6_dst
;
6422 ip6h
->ip6_dst
= tmp
;
6423 rthdr
->ip6r0_segleft
--;
6424 /* Don't allow any mapped addresses - ip_wput_v6 can't handle them */
6425 if (IN6_IS_ADDR_V4MAPPED(&ip6h
->ip6_dst
)) {
6426 if (hada_mp
!= NULL
)
6428 /* Sent by forwarding path, and router is global zone */
6429 icmp_unreachable_v6(WR(q
), mp
, ICMP6_DST_UNREACH_NOROUTE
,
6430 B_FALSE
, B_FALSE
, GLOBAL_ZONEID
, ipst
);
6433 if (ip_check_v6_mblk(mp
, ill
) == IP6_MBLK_OK
) {
6434 ip6h
= (ip6_t
*)mp
->b_rptr
;
6435 ip_rput_data_v6(q
, ill
, mp
, ip6h
, flags
, hada_mp
, dl_mp
);
6441 /* IPsec kstats: bean counter? */
6447 * Read side put procedure for IPv6 module.
6450 ip_rput_v6(queue_t
*q
, mblk_t
*mp
)
6453 mblk_t
*hada_mp
= NULL
;
6455 boolean_t ll_multicast
= B_FALSE
;
6456 boolean_t mctl_present
= B_FALSE
;
6458 struct iocblk
*iocp
;
6464 ill
= (ill_t
*)q
->q_ptr
;
6465 ipst
= ill
->ill_ipst
;
6466 if (ill
->ill_state_flags
& ILL_CONDEMNED
) {
6467 union DL_primitives
*dl
;
6469 dl
= (union DL_primitives
*)mp
->b_rptr
;
6471 * Things are opening or closing - only accept DLPI
6472 * ack messages. If the stream is closing and ip_wsrv
6473 * has completed, ip_close is out of the qwait, but has
6474 * not yet completed qprocsoff. Don't proceed any further
6475 * because the ill has been cleaned up and things hanging
6476 * off the ill have been freed.
6478 if ((mp
->b_datap
->db_type
!= M_PCPROTO
) ||
6479 (dl
->dl_primitive
== DL_UNITDATA_IND
)) {
6486 switch (mp
->b_datap
->db_type
) {
6490 struct ether_header
*eh
;
6491 dl_unitdata_ind_t
*dui
;
6494 * This is a work-around for CR 6451644, a bug in Nemo. It
6495 * should be removed when that problem is fixed.
6497 if (ill
->ill_mactype
== DL_ETHER
&&
6498 (hlen
= MBLKHEAD(mp
)) >= sizeof (struct ether_header
) &&
6499 (ucp
= mp
->b_rptr
)[-1] == (IP6_DL_SAP
& 0xFF) &&
6500 ucp
[-2] == (IP6_DL_SAP
>> 8)) {
6501 if (hlen
>= sizeof (struct ether_vlan_header
) &&
6502 ucp
[-5] == 0 && ucp
[-6] == 0x81)
6503 ucp
-= sizeof (struct ether_vlan_header
);
6505 ucp
-= sizeof (struct ether_header
);
6507 * If it's a group address, then fabricate a
6508 * DL_UNITDATA_IND message.
6510 if ((ll_multicast
= (ucp
[0] & 1)) != 0 &&
6511 (dl_mp
= allocb(DL_UNITDATA_IND_SIZE
+ 16,
6512 BPRI_HI
)) != NULL
) {
6513 eh
= (struct ether_header
*)ucp
;
6514 dui
= (dl_unitdata_ind_t
*)dl_mp
->b_rptr
;
6515 DB_TYPE(dl_mp
) = M_PROTO
;
6516 dl_mp
->b_wptr
= (uchar_t
*)(dui
+ 1) + 16;
6517 dui
->dl_primitive
= DL_UNITDATA_IND
;
6518 dui
->dl_dest_addr_length
= 8;
6519 dui
->dl_dest_addr_offset
= DL_UNITDATA_IND_SIZE
;
6520 dui
->dl_src_addr_length
= 8;
6521 dui
->dl_src_addr_offset
= DL_UNITDATA_IND_SIZE
+
6523 dui
->dl_group_address
= 1;
6524 ucp
= (uchar_t
*)(dui
+ 1);
6525 if (ill
->ill_sap_length
> 0)
6526 ucp
+= ill
->ill_sap_length
;
6527 bcopy(&eh
->ether_dhost
, ucp
, 6);
6528 bcopy(&eh
->ether_shost
, ucp
+ 8, 6);
6529 ucp
= (uchar_t
*)(dui
+ 1);
6530 if (ill
->ill_sap_length
< 0)
6531 ucp
+= 8 + ill
->ill_sap_length
;
6532 bcopy(&eh
->ether_type
, ucp
, 2);
6533 bcopy(&eh
->ether_type
, ucp
+ 8, 2);
6541 if (((dl_unitdata_ind_t
*)mp
->b_rptr
)->dl_primitive
!=
6543 /* Go handle anything other than data elsewhere. */
6544 ip_rput_dlpi(q
, mp
);
6547 ll_multicast
= ip_get_dlpi_mbcast(ill
, mp
);
6549 /* Save the DLPI header. */
6552 dl_mp
->b_cont
= NULL
;
6555 panic("ip_rput_v6: got an M_BREAK");
6558 iocp
= (struct iocblk
*)mp
->b_rptr
;
6559 switch (iocp
->ioc_cmd
) {
6560 case DL_IOC_HDR_INFO
:
6561 ill
= (ill_t
*)q
->q_ptr
;
6562 ill_fastpath_ack(ill
, mp
);
6566 case OSIOCGTUNPARAM
:
6567 ip_rput_other(NULL
, q
, mp
, NULL
);
6571 case OSIOCSTUNPARAM
:
6572 /* Go through qwriter */
6581 mutex_enter(&ill
->ill_lock
);
6582 if (ill
->ill_state_flags
& ILL_CONDEMNED
) {
6583 mutex_exit(&ill
->ill_lock
);
6587 ill_refhold_locked(ill
);
6588 mutex_exit(&ill
->ill_lock
);
6589 qwriter_ip(ill
, q
, mp
, ip_rput_other
, CUR_OP
, B_FALSE
);
6592 if ((MBLKL(mp
) > sizeof (int)) &&
6593 ((da_ipsec_t
*)mp
->b_rptr
)->da_type
== IPHADA_M_CTL
) {
6594 ASSERT(MBLKL(mp
) >= sizeof (da_ipsec_t
));
6595 mctl_present
= B_TRUE
;
6601 iocp
= (struct iocblk
*)mp
->b_rptr
;
6602 switch (iocp
->ioc_cmd
) {
6603 case DL_IOC_HDR_INFO
:
6605 case OSIOCGTUNPARAM
:
6606 ip_rput_other(NULL
, q
, mp
, NULL
);
6610 case OSIOCSTUNPARAM
:
6611 mutex_enter(&ill
->ill_lock
);
6612 if (ill
->ill_state_flags
& ILL_CONDEMNED
) {
6613 mutex_exit(&ill
->ill_lock
);
6617 ill_refhold_locked(ill
);
6618 mutex_exit(&ill
->ill_lock
);
6619 qwriter_ip(ill
, q
, mp
, ip_rput_other
, CUR_OP
, B_FALSE
);
6629 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInReceives
);
6630 UPDATE_MIB(ill
->ill_ip_mib
, ipIfStatsHCInOctets
,
6631 (mp
->b_cont
== NULL
) ? MBLKL(mp
) : msgdsize(mp
));
6633 * if db_ref > 1 then copymsg and free original. Packet may be
6634 * changed and do not want other entity who has a reference to this
6635 * message to trip over the changes. This is a blind change because
6636 * trying to catch all places that might change packet is too
6637 * difficult (since it may be a module above this one).
6639 if (mp
->b_datap
->db_ref
> 1) {
6653 mp
= first_mp
->b_cont
;
6656 if ((check
= ip_check_v6_mblk(mp
, ill
)) == IP6_MBLK_HDR_ERR
) {
6661 ip6h
= (ip6_t
*)mp
->b_rptr
;
6664 * ip:::receive must see ipv6 packets with a full header,
6665 * and so is placed after the IP6_MBLK_HDR_ERR check.
6667 DTRACE_IP7(receive
, mblk_t
*, first_mp
, conn_t
*, NULL
, void_ip_t
*,
6668 ip6h
, __dtrace_ipsr_ill_t
*, ill
, ipha_t
*, NULL
, ip6_t
*, ip6h
,
6671 if (check
!= IP6_MBLK_OK
) {
6676 DTRACE_PROBE4(ip6__physical__in__start
,
6677 ill_t
*, ill
, ill_t
*, NULL
,
6678 ip6_t
*, ip6h
, mblk_t
*, first_mp
);
6680 FW_HOOKS6(ipst
->ips_ip6_physical_in_event
,
6681 ipst
->ips_ipv6firewall_physical_in
,
6682 ill
, NULL
, ip6h
, first_mp
, mp
, ll_multicast
, ipst
);
6684 DTRACE_PROBE1(ip6__physical__in__end
, mblk_t
*, first_mp
);
6686 if (first_mp
== NULL
)
6690 * Attach any necessary label information to this packet.
6692 if (is_system_labeled() && !tsol_get_pkt_label(mp
, IPV6_VERSION
)) {
6694 ip0dbg(("tsol_get_pkt_label v6 failed\n"));
6695 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
6699 /* IP observability hook. */
6700 if (ipst
->ips_ipobs_enabled
) {
6703 dzone
= ip_get_zoneid_v6(&ip6h
->ip6_dst
, mp
, ill
, ipst
,
6705 ipobs_hook(mp
, IPOBS_HOOK_INBOUND
, ALL_ZONES
, dzone
, ill
,
6706 IPV6_VERSION
, 0, ipst
);
6709 if ((ip6h
->ip6_vcf
& IPV6_VERS_AND_FLOW_MASK
) ==
6710 IPV6_DEFAULT_VERS_AND_FLOW
) {
6712 * It may be a bit too expensive to do this mapped address
6713 * check here, but in the interest of robustness, it seems
6714 * like the correct place.
6715 * TODO: Avoid this check for e.g. connected TCP sockets
6717 if (IN6_IS_ADDR_V4MAPPED(&ip6h
->ip6_src
)) {
6718 ip1dbg(("ip_rput_v6: pkt with mapped src addr\n"));
6722 if (IN6_IS_ADDR_LOOPBACK(&ip6h
->ip6_src
)) {
6723 ip1dbg(("ip_rput_v6: pkt with loopback src"));
6725 } else if (IN6_IS_ADDR_LOOPBACK(&ip6h
->ip6_dst
)) {
6726 ip1dbg(("ip_rput_v6: pkt with loopback dst"));
6730 flags
|= (ll_multicast
? IP6_IN_LLMCAST
: 0);
6731 ip_rput_data_v6(q
, ill
, mp
, ip6h
, flags
, hada_mp
, dl_mp
);
6733 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInWrongIPVersion
);
6743 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
6747 * Walk through the IPv6 packet in mp and see if there's an AH header
6748 * in it. See if the AH header needs to get done before other headers in
6749 * the packet. (Worker function for ipsec_early_ah_v6().)
6751 #define IPSEC_HDR_DONT_PROCESS 0
6752 #define IPSEC_HDR_PROCESS 1
6753 #define IPSEC_MEMORY_ERROR 2 /* or malformed packet */
6755 ipsec_needs_processing_v6(mblk_t
*mp
, uint8_t *nexthdr
)
6762 ip6_dest_t
*desthdr
;
6767 * For now just pullup everything. In general, the less pullups,
6768 * the better, but there's so much squirrelling through anyway,
6769 * it's just easier this way.
6771 if (!pullupmsg(mp
, -1)) {
6772 return (IPSEC_MEMORY_ERROR
);
6775 ip6h
= (ip6_t
*)mp
->b_rptr
;
6776 length
= IPV6_HDR_LEN
;
6777 whereptr
= ((uint8_t *)&ip6h
[1]); /* point to next hdr */
6778 endptr
= mp
->b_wptr
;
6781 * We can't just use the argument nexthdr in the place
6782 * of nexthdrp becaue we don't dereference nexthdrp
6783 * till we confirm whether it is a valid address.
6785 nexthdrp
= &ip6h
->ip6_nxt
;
6786 while (whereptr
< endptr
) {
6787 /* Is there enough left for len + nexthdr? */
6788 if (whereptr
+ MIN_EHDR_LEN
> endptr
)
6789 return (IPSEC_MEMORY_ERROR
);
6791 switch (*nexthdrp
) {
6792 case IPPROTO_HOPOPTS
:
6793 case IPPROTO_DSTOPTS
:
6794 /* Assumes the headers are identical for hbh and dst */
6795 desthdr
= (ip6_dest_t
*)whereptr
;
6796 ehdrlen
= 8 * (desthdr
->ip6d_len
+ 1);
6797 if ((uchar_t
*)desthdr
+ ehdrlen
> endptr
)
6798 return (IPSEC_MEMORY_ERROR
);
6800 * Return DONT_PROCESS because the destination
6801 * options header may be for each hop in a
6802 * routing-header, and we only want AH if we're
6803 * finished with routing headers.
6805 if (*nexthdrp
== IPPROTO_DSTOPTS
)
6806 return (IPSEC_HDR_DONT_PROCESS
);
6807 nexthdrp
= &desthdr
->ip6d_nxt
;
6809 case IPPROTO_ROUTING
:
6810 rthdr
= (ip6_rthdr_t
*)whereptr
;
6813 * If there's more hops left on the routing header,
6814 * return now with DON'T PROCESS.
6816 if (rthdr
->ip6r_segleft
> 0)
6817 return (IPSEC_HDR_DONT_PROCESS
);
6819 ehdrlen
= 8 * (rthdr
->ip6r_len
+ 1);
6820 if ((uchar_t
*)rthdr
+ ehdrlen
> endptr
)
6821 return (IPSEC_MEMORY_ERROR
);
6822 nexthdrp
= &rthdr
->ip6r_nxt
;
6824 case IPPROTO_FRAGMENT
:
6825 /* Wait for reassembly */
6826 return (IPSEC_HDR_DONT_PROCESS
);
6828 *nexthdr
= IPPROTO_AH
;
6829 return (IPSEC_HDR_PROCESS
);
6831 /* No next header means we're finished */
6833 return (IPSEC_HDR_DONT_PROCESS
);
6836 whereptr
+= ehdrlen
;
6839 * Malformed/truncated packet.
6841 return (IPSEC_MEMORY_ERROR
);
6845 * Path for AH if options are present. If this is the first time we are
6846 * sending a datagram to AH, allocate a IPSEC_IN message and prepend it.
6847 * Otherwise, just fanout. Return value answers the boolean question:
6848 * "Did I consume the mblk you sent me?"
6850 * Sometimes AH needs to be done before other IPv6 headers for security
6851 * reasons. This function (and its ipsec_needs_processing_v6() above)
6852 * indicates if that is so, and fans out to the appropriate IPsec protocol
6853 * for the datagram passed in.
6856 ipsec_early_ah_v6(queue_t
*q
, mblk_t
*first_mp
, boolean_t mctl_present
,
6857 ill_t
*ill
, ill_t
*inill
, mblk_t
*hada_mp
, zoneid_t zoneid
)
6861 ipsec_in_t
*ii
= NULL
;
6863 ipsec_status_t ipsec_rc
;
6864 ip_stack_t
*ipst
= ill
->ill_ipst
;
6865 netstack_t
*ns
= ipst
->ips_netstack
;
6866 ipsec_stack_t
*ipss
= ns
->netstack_ipsec
;
6868 ASSERT((hada_mp
== NULL
) || (!mctl_present
));
6870 switch (ipsec_needs_processing_v6(
6871 (mctl_present
? first_mp
->b_cont
: first_mp
), &nexthdr
)) {
6872 case IPSEC_MEMORY_ERROR
:
6873 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
6877 case IPSEC_HDR_DONT_PROCESS
:
6881 /* Default means send it to AH! */
6882 ASSERT(nexthdr
== IPPROTO_AH
);
6883 if (!mctl_present
) {
6885 first_mp
= ipsec_in_alloc(B_FALSE
, ipst
->ips_netstack
);
6886 if (first_mp
== NULL
) {
6887 ip1dbg(("ipsec_early_ah_v6: IPSEC_IN "
6888 "allocation failure.\n"));
6889 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
6895 * Store the ill_index so that when we come back
6896 * from IPSEC we ride on the same queue.
6898 ii
= (ipsec_in_t
*)first_mp
->b_rptr
;
6899 ii
->ipsec_in_ill_index
= ill
->ill_phyint
->phyint_ifindex
;
6900 ii
->ipsec_in_rill_index
= inill
->ill_phyint
->phyint_ifindex
;
6901 first_mp
->b_cont
= mp
;
6904 * Cache hardware acceleration info.
6906 if (hada_mp
!= NULL
) {
6908 IPSECHW_DEBUG(IPSECHW_PKT
, ("ipsec_early_ah_v6: "
6909 "caching data attr.\n"));
6910 ii
->ipsec_in_accelerated
= B_TRUE
;
6911 ii
->ipsec_in_da
= hada_mp
;
6914 if (!ipsec_loaded(ipss
)) {
6915 ip_proto_not_sup(q
, first_mp
, IP_FF_SEND_ICMP
, zoneid
, ipst
);
6919 ah
= ipsec_inbound_ah_sa(first_mp
, ns
);
6922 ASSERT(ii
->ipsec_in_ah_sa
!= NULL
);
6923 ASSERT(ii
->ipsec_in_ah_sa
->ipsa_input_func
!= NULL
);
6924 ipsec_rc
= ii
->ipsec_in_ah_sa
->ipsa_input_func(first_mp
, ah
);
6927 case IPSEC_STATUS_SUCCESS
:
6928 /* we're done with IPsec processing, send it up */
6929 ip_fanout_proto_again(first_mp
, ill
, inill
, NULL
);
6931 case IPSEC_STATUS_FAILED
:
6932 BUMP_MIB(&ipst
->ips_ip6_mib
, ipIfStatsInDiscards
);
6934 case IPSEC_STATUS_PENDING
:
6935 /* no action needed */
6942 * Validate the IPv6 mblk for alignment.
6945 ip_check_v6_mblk(mblk_t
*mp
, ill_t
*ill
)
6947 int pkt_len
, ip6_len
;
6948 ip6_t
*ip6h
= (ip6_t
*)mp
->b_rptr
;
6950 /* check for alignment and full IPv6 header */
6951 if (!OK_32PTR((uchar_t
*)ip6h
) ||
6952 (mp
->b_wptr
- (uchar_t
*)ip6h
) < IPV6_HDR_LEN
) {
6953 if (!pullupmsg(mp
, IPV6_HDR_LEN
)) {
6954 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
6955 ip1dbg(("ip_rput_v6: pullupmsg failed\n"));
6956 return (IP6_MBLK_HDR_ERR
);
6958 ip6h
= (ip6_t
*)mp
->b_rptr
;
6961 ASSERT(OK_32PTR((uchar_t
*)ip6h
) &&
6962 (mp
->b_wptr
- (uchar_t
*)ip6h
) >= IPV6_HDR_LEN
);
6964 if (mp
->b_cont
== NULL
)
6965 pkt_len
= mp
->b_wptr
- mp
->b_rptr
;
6967 pkt_len
= msgdsize(mp
);
6968 ip6_len
= ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
;
6971 * Check for bogus (too short packet) and packet which
6972 * was padded by the link layer.
6974 if (ip6_len
!= pkt_len
) {
6977 if (ip6_len
> pkt_len
) {
6978 ip1dbg(("ip_rput_data_v6: packet too short %d %d\n",
6980 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInTruncatedPkts
);
6981 return (IP6_MBLK_LEN_ERR
);
6983 diff
= (ssize_t
)(pkt_len
- ip6_len
);
6985 if (!adjmsg(mp
, -diff
)) {
6986 ip1dbg(("ip_rput_data_v6: adjmsg failed\n"));
6987 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
6988 return (IP6_MBLK_LEN_ERR
);
6991 return (IP6_MBLK_OK
);
6995 * ip_rput_data_v6 -- received IPv6 packets in M_DATA messages show up here.
6996 * ip_rput_v6 has already verified alignment, the min length, the version,
6999 * The ill passed in (the arg named inill) is the ill that the packet
7000 * actually arrived on. We need to remember this when saving the
7001 * input interface index into potential IPV6_PKTINFO data in
7004 * This routine doesn't free dl_mp; that's the caller's responsibility on
7005 * return. (Note that the callers are complex enough that there's no tail
7006 * recursion here anyway.)
7009 ip_rput_data_v6(queue_t
*q
, ill_t
*inill
, mblk_t
*mp
, ip6_t
*ip6h
,
7010 uint_t flags
, mblk_t
*hada_mp
, mblk_t
*dl_mp
)
7019 uint_t prev_nexthdr_offset
;
7025 boolean_t mctl_present
;
7028 boolean_t no_forward
;
7030 boolean_t ll_multicast
= (flags
& IP6_IN_LLMCAST
);
7033 zoneid_t zoneid
= GLOBAL_ZONEID
;
7034 uint16_t hck_flags
, reass_hck_flags
;
7036 boolean_t cksum_err
;
7038 ip_stack_t
*ipst
= inill
->ill_ipst
;
7040 EXTRACT_PKT_MP(mp
, first_mp
, mctl_present
);
7042 if (hada_mp
!= NULL
) {
7044 * It's an IPsec accelerated packet.
7045 * Keep a pointer to the data attributes around until
7046 * we allocate the ipsecinfo structure.
7048 IPSECHW_DEBUG(IPSECHW_PKT
,
7049 ("ip_rput_data_v6: inbound HW accelerated IPsec pkt\n"));
7050 hada_mp
->b_cont
= NULL
;
7052 * Since it is accelerated, it came directly from
7055 ASSERT(mctl_present
== B_FALSE
);
7056 ASSERT(mp
->b_datap
->db_type
!= M_CTL
);
7059 ip6h
= (ip6_t
*)mp
->b_rptr
;
7060 ip6_len
= ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
;
7061 old_pkt_len
= pkt_len
= ip6_len
;
7063 if (ILL_HCKSUM_CAPABLE(ill
) && !mctl_present
&& dohwcksum
)
7064 hck_flags
= DB_CKSUMFLAGS(mp
);
7068 /* Clear checksum flags in case we need to forward */
7069 DB_CKSUMFLAGS(mp
) = 0;
7070 reass_sum
= reass_hck_flags
= 0;
7072 nexthdr
= ip6h
->ip6_nxt
;
7074 prev_nexthdr_offset
= (uint_t
)((uchar_t
*)&ip6h
->ip6_nxt
-
7076 whereptr
= (uint8_t *)&ip6h
[1];
7077 remlen
= pkt_len
- IPV6_HDR_LEN
; /* Track how much is left */
7079 /* Process hop by hop header options */
7080 if (nexthdr
== IPPROTO_HOPOPTS
) {
7084 if (remlen
< MIN_EHDR_LEN
)
7086 if (mp
->b_cont
!= NULL
&&
7087 whereptr
+ MIN_EHDR_LEN
> mp
->b_wptr
) {
7088 if (!pullupmsg(mp
, IPV6_HDR_LEN
+ MIN_EHDR_LEN
)) {
7089 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
7094 ip6h
= (ip6_t
*)mp
->b_rptr
;
7095 whereptr
= (uint8_t *)ip6h
+ pkt_len
- remlen
;
7097 hbhhdr
= (ip6_hbh_t
*)whereptr
;
7098 nexthdr
= hbhhdr
->ip6h_nxt
;
7099 prev_nexthdr_offset
= (uint_t
)(whereptr
- (uint8_t *)ip6h
);
7100 ehdrlen
= 8 * (hbhhdr
->ip6h_len
+ 1);
7102 if (remlen
< ehdrlen
)
7104 if (mp
->b_cont
!= NULL
&&
7105 whereptr
+ ehdrlen
> mp
->b_wptr
) {
7106 if (!pullupmsg(mp
, IPV6_HDR_LEN
+ ehdrlen
)) {
7107 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
7112 ip6h
= (ip6_t
*)mp
->b_rptr
;
7113 whereptr
= (uint8_t *)ip6h
+ pkt_len
- remlen
;
7114 hbhhdr
= (ip6_hbh_t
*)whereptr
;
7117 optptr
= whereptr
+ 2;
7118 whereptr
+= ehdrlen
;
7120 switch (ip_process_options_v6(q
, first_mp
, ip6h
, optptr
,
7121 ehdrlen
- 2, IPPROTO_HOPOPTS
, ipst
)) {
7124 * Packet has been consumed and any
7125 * needed ICMP messages sent.
7127 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7131 /* no action needed */
7134 /* Known router alert */
7140 * On incoming v6 multicast packets we will bypass the ire table,
7141 * and assume that the read queue corresponds to the targetted
7144 * The effect of this is the same as the IPv4 original code, but is
7145 * much cleaner I think. See ip_rput for how that was done.
7147 if (IN6_IS_ADDR_MULTICAST(&ip6h
->ip6_dst
)) {
7148 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInMcastPkts
);
7149 UPDATE_MIB(ill
->ill_ip_mib
, ipIfStatsHCInMcastOctets
, pkt_len
);
7152 * So that we don't end up with dups, only one ill in an IPMP
7153 * group is nominated to receive multicast data traffic.
7154 * However, link-locals on any underlying interfaces will have
7155 * joined their solicited-node multicast addresses and we must
7156 * accept those packets. (We don't attempt to precisely
7157 * filter out duplicate solicited-node multicast packets since
7158 * e.g. an IPMP interface and underlying interface may have
7159 * the same solicited-node multicast address.) Note that we
7160 * won't generally have duplicates because we only issue a
7161 * DL_ENABMULTI_REQ on one interface in a group; the exception
7162 * is when PHYI_MULTI_BCAST is set.
7164 if (IS_UNDER_IPMP(ill
) && !ill
->ill_nom_cast
&&
7165 !IN6_IS_ADDR_MC_SOLICITEDNODE(&ip6h
->ip6_dst
)) {
7170 * XXX TODO Give to mrouted to for multicast forwarding.
7172 if (ilm_lookup_ill_v6(ill
, &ip6h
->ip6_dst
, B_FALSE
,
7173 ALL_ZONES
) == NULL
) {
7176 pr_addr_dbg("ip_rput_data_v6: got mcast packet"
7177 " which is not for us: %s\n", AF_INET6
,
7180 drop_pkt
: BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
7187 pr_addr_dbg("ip_rput_data_v6: multicast for us: %s\n",
7188 AF_INET6
, &ip6h
->ip6_dst
);
7190 zoneid
= GLOBAL_ZONEID
;
7194 ipif
= ill
->ill_ipif
;
7197 * If a packet was received on an interface that is a 6to4 tunnel,
7198 * incoming IPv6 packets, with a 6to4 addressed IPv6 destination, must
7199 * be checked to have a 6to4 prefix (2002:V4ADDR::/48) that is equal to
7200 * the 6to4 prefix of the address configured on the receiving interface.
7201 * Otherwise, the packet was delivered to this interface in error and
7202 * the packet must be dropped.
7204 if ((ill
->ill_is_6to4tun
) && IN6_IS_ADDR_6TO4(&ip6h
->ip6_dst
)) {
7206 if (!IN6_ARE_6TO4_PREFIX_EQUAL(&ipif
->ipif_v6lcl_addr
,
7210 pr_addr_dbg("ip_rput_data_v6: received 6to4 "
7211 "addressed packet which is not for us: "
7212 "%s\n", AF_INET6
, &ip6h
->ip6_dst
);
7214 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
7221 * Find an ire that matches destination. For link-local addresses
7222 * we have to match the ill.
7223 * TBD for site local addresses.
7225 if (IN6_IS_ADDR_LINKLOCAL(&ip6h
->ip6_dst
)) {
7226 ire
= ire_ctable_lookup_v6(&ip6h
->ip6_dst
, NULL
,
7227 IRE_CACHE
|IRE_LOCAL
, ill
->ill_ipif
, ALL_ZONES
, NULL
,
7228 MATCH_IRE_TYPE
| MATCH_IRE_ILL
, ipst
);
7230 ire
= ire_cache_lookup_v6(&ip6h
->ip6_dst
, ALL_ZONES
,
7231 msg_getlabel(mp
), ipst
);
7233 if (ire
!= NULL
&& ire
->ire_stq
!= NULL
&&
7234 ire
->ire_zoneid
!= GLOBAL_ZONEID
&&
7235 ire
->ire_zoneid
!= ALL_ZONES
) {
7237 * Should only use IREs that are visible from the
7238 * global zone for forwarding.
7241 ire
= ire_cache_lookup_v6(&ip6h
->ip6_dst
,
7242 GLOBAL_ZONEID
, msg_getlabel(mp
), ipst
);
7248 * No matching IRE found. Mark this packet as having
7249 * originated externally.
7251 if (!(ill
->ill_flags
& ILLF_ROUTER
) || ll_multicast
) {
7252 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsForwProhibits
);
7253 if (!(ill
->ill_flags
& ILLF_ROUTER
)) {
7254 BUMP_MIB(ill
->ill_ip_mib
,
7255 ipIfStatsInAddrErrors
);
7261 if (ip6h
->ip6_hops
<= 1) {
7262 if (hada_mp
!= NULL
)
7264 /* Sent by forwarding path, and router is global zone */
7265 icmp_time_exceeded_v6(WR(q
), first_mp
,
7266 ICMP6_TIME_EXCEED_TRANSIT
, ll_multicast
, B_FALSE
,
7267 GLOBAL_ZONEID
, ipst
);
7271 * Per RFC 3513 section 2.5.2, we must not forward packets with
7272 * an unspecified source address.
7274 if (IN6_IS_ADDR_UNSPECIFIED(&ip6h
->ip6_src
)) {
7275 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsForwProhibits
);
7280 mp
->b_prev
= (mblk_t
*)(uintptr_t)
7281 ill
->ill_phyint
->phyint_ifindex
;
7282 ip_newroute_v6(q
, mp
, &ip6h
->ip6_dst
, &ip6h
->ip6_src
,
7283 IN6_IS_ADDR_LINKLOCAL(&ip6h
->ip6_dst
) ? ill
: NULL
,
7284 GLOBAL_ZONEID
, ipst
);
7287 /* we have a matching IRE */
7288 if (ire
->ire_stq
!= NULL
) {
7290 * To be quicker, we may wish not to chase pointers
7291 * (ire->ire_ipif->ipif_ill...) and instead store the
7292 * forwarding policy in the ire. An unfortunate side-
7293 * effect of this would be requiring an ire flush whenever
7294 * the ILLF_ROUTER flag changes. For now, chase pointers
7295 * once and store in the boolean no_forward.
7297 * This appears twice to keep it out of the non-forwarding,
7298 * yes-it's-for-us-on-the-right-interface case.
7300 no_forward
= ((ill
->ill_flags
&
7301 ire
->ire_ipif
->ipif_ill
->ill_flags
& ILLF_ROUTER
) == 0);
7303 ASSERT(first_mp
== mp
);
7305 * This ire has a send-to queue - forward the packet.
7307 if (no_forward
|| ll_multicast
|| (hada_mp
!= NULL
)) {
7309 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsForwProhibits
);
7311 BUMP_MIB(ill
->ill_ip_mib
,
7312 ipIfStatsInAddrErrors
);
7319 * ipIfStatsHCInForwDatagrams should only be increment if there
7320 * will be an attempt to forward the packet, which is why we
7321 * increment after the above condition has been checked.
7323 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInForwDatagrams
);
7324 if (ip6h
->ip6_hops
<= 1) {
7325 ip1dbg(("ip_rput_data_v6: hop limit expired.\n"));
7326 /* Sent by forwarding path, and router is global zone */
7327 icmp_time_exceeded_v6(WR(q
), mp
,
7328 ICMP6_TIME_EXCEED_TRANSIT
, ll_multicast
, B_FALSE
,
7329 GLOBAL_ZONEID
, ipst
);
7334 * Per RFC 3513 section 2.5.2, we must not forward packets with
7335 * an unspecified source address.
7337 if (IN6_IS_ADDR_UNSPECIFIED(&ip6h
->ip6_src
)) {
7338 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsForwProhibits
);
7344 if (is_system_labeled()) {
7347 if ((mp1
= tsol_ip_forward(ire
, mp
)) == NULL
) {
7348 BUMP_MIB(ill
->ill_ip_mib
,
7349 ipIfStatsForwProhibits
);
7354 /* Size may have changed */
7356 ip6h
= (ip6_t
*)mp
->b_rptr
;
7357 pkt_len
= msgdsize(mp
);
7360 if (pkt_len
> ire
->ire_max_frag
) {
7361 int max_frag
= ire
->ire_max_frag
;
7362 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInTooBigErrors
);
7364 * Handle labeled packet resizing.
7366 if (is_system_labeled()) {
7367 max_frag
= tsol_pmtu_adjust(mp
, max_frag
,
7368 pkt_len
- old_pkt_len
, AF_INET6
);
7371 /* Sent by forwarding path, and router is global zone */
7372 icmp_pkt2big_v6(WR(q
), mp
, max_frag
,
7373 ll_multicast
, B_TRUE
, GLOBAL_ZONEID
, ipst
);
7379 * Check to see if we're forwarding the packet to a
7380 * different link from which it came. If so, check the
7381 * source and destination addresses since routers must not
7382 * forward any packets with link-local source or
7383 * destination addresses to other links. Otherwise (if
7384 * we're forwarding onto the same link), conditionally send
7385 * a redirect message.
7387 if (ire
->ire_rfq
!= q
&&
7388 !IS_IN_SAME_ILLGRP(ill
, (ill_t
*)ire
->ire_rfq
->q_ptr
)) {
7389 if (IN6_IS_ADDR_LINKLOCAL(&ip6h
->ip6_dst
) ||
7390 IN6_IS_ADDR_LINKLOCAL(&ip6h
->ip6_src
)) {
7391 BUMP_MIB(ill
->ill_ip_mib
,
7392 ipIfStatsInAddrErrors
);
7397 /* TBD add site-local check at site boundary? */
7398 } else if (ipst
->ips_ipv6_send_redirects
) {
7400 in6_addr_t gw_addr_v6
;
7401 ire_t
*src_ire_v6
= NULL
;
7404 * Don't send a redirect when forwarding a source
7407 if (ip_source_routed_v6(ip6h
, mp
, ipst
))
7410 mutex_enter(&ire
->ire_lock
);
7411 gw_addr_v6
= ire
->ire_gateway_addr_v6
;
7412 mutex_exit(&ire
->ire_lock
);
7413 if (!IN6_IS_ADDR_UNSPECIFIED(&gw_addr_v6
)) {
7414 v6targ
= &gw_addr_v6
;
7416 * We won't send redirects to a router
7417 * that doesn't have a link local
7418 * address, but will forward.
7420 if (!IN6_IS_ADDR_LINKLOCAL(v6targ
)) {
7421 BUMP_MIB(ill
->ill_ip_mib
,
7422 ipIfStatsInAddrErrors
);
7426 v6targ
= &ip6h
->ip6_dst
;
7429 src_ire_v6
= ire_ftable_lookup_v6(&ip6h
->ip6_src
,
7430 NULL
, NULL
, IRE_INTERFACE
, ire
->ire_ipif
, NULL
,
7431 GLOBAL_ZONEID
, 0, NULL
,
7432 MATCH_IRE_IPIF
| MATCH_IRE_TYPE
,
7435 if (src_ire_v6
!= NULL
) {
7437 * The source is directly connected.
7441 icmp_send_redirect_v6(WR(q
),
7442 mp1
, v6targ
, &ip6h
->ip6_dst
,
7445 ire_refrele(src_ire_v6
);
7450 /* Hoplimit verified above */
7453 outill
= ire
->ire_ipif
->ipif_ill
;
7455 DTRACE_PROBE4(ip6__forwarding__start
,
7456 ill_t
*, inill
, ill_t
*, outill
,
7457 ip6_t
*, ip6h
, mblk_t
*, mp
);
7459 FW_HOOKS6(ipst
->ips_ip6_forwarding_event
,
7460 ipst
->ips_ipv6firewall_forwarding
,
7461 inill
, outill
, ip6h
, mp
, mp
, 0, ipst
);
7463 DTRACE_PROBE1(ip6__forwarding__end
, mblk_t
*, mp
);
7466 UPDATE_IB_PKT_COUNT(ire
);
7467 ire
->ire_last_used_time
= lbolt
;
7468 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCOutForwDatagrams
);
7469 ip_xmit_v6(mp
, ire
, 0, NULL
, B_FALSE
, NULL
);
7476 * Need to put on correct queue for reassembly to find it.
7477 * No need to use put() since reassembly has its own locks.
7478 * Note: multicast packets and packets destined to addresses
7479 * assigned to loopback (ire_rfq is NULL) will be reassembled on
7480 * the arriving ill. Unlike the IPv4 case, enabling strict
7481 * destination multihoming will prevent accepting packets
7482 * addressed to an IRE_LOCAL on lo0.
7484 if (ire
->ire_rfq
!= q
) {
7485 if ((ire
= ip_check_multihome(&ip6h
->ip6_dst
, ire
, ill
))
7487 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsForwProhibits
);
7492 if (ire
->ire_rfq
!= NULL
) {
7494 ill
= (ill_t
*)q
->q_ptr
;
7495 ASSERT(ill
!= NULL
);
7499 zoneid
= ire
->ire_zoneid
;
7500 UPDATE_IB_PKT_COUNT(ire
);
7501 ire
->ire_last_used_time
= lbolt
;
7502 /* Don't use the ire after this point, we'll NULL it out to be sure. */
7507 * Looks like this packet is for us one way or another.
7508 * This is where we'll process destination headers etc.
7517 hdr_len
= pkt_len
- remlen
;
7519 if (hada_mp
!= NULL
) {
7520 ip0dbg(("tcp hada drop\n"));
7525 /* TCP needs all of the TCP header */
7526 if (remlen
< TCP_MIN_HEADER_LENGTH
)
7528 if (mp
->b_cont
!= NULL
&&
7529 whereptr
+ TCP_MIN_HEADER_LENGTH
> mp
->b_wptr
) {
7531 hdr_len
+ TCP_MIN_HEADER_LENGTH
)) {
7532 BUMP_MIB(ill
->ill_ip_mib
,
7533 ipIfStatsInDiscards
);
7538 ip6h
= (ip6_t
*)mp
->b_rptr
;
7539 whereptr
= (uint8_t *)ip6h
+ hdr_len
;
7542 * Extract the offset field from the TCP header.
7544 offset
= ((uchar_t
*)ip6h
)[hdr_len
+ 12] >> 4;
7547 ip1dbg(("ip_rput_data_v6: short "
7548 "TCP data offset"));
7549 BUMP_MIB(ill
->ill_ip_mib
,
7550 ipIfStatsInDiscards
);
7555 * There must be TCP options.
7556 * Make sure we can grab them.
7559 if (remlen
< offset
)
7561 if (mp
->b_cont
!= NULL
&&
7562 whereptr
+ offset
> mp
->b_wptr
) {
7564 hdr_len
+ offset
)) {
7565 BUMP_MIB(ill
->ill_ip_mib
,
7566 ipIfStatsInDiscards
);
7571 ip6h
= (ip6_t
*)mp
->b_rptr
;
7572 whereptr
= (uint8_t *)ip6h
+ hdr_len
;
7576 up
= (uint16_t *)&ip6h
->ip6_src
;
7578 * TCP checksum calculation. First sum up the
7579 * pseudo-header fields:
7580 * - Source IPv6 address
7581 * - Destination IPv6 address
7582 * - TCP payload length
7585 sum
= htons(IPPROTO_TCP
+ remlen
) +
7586 up
[0] + up
[1] + up
[2] + up
[3] +
7587 up
[4] + up
[5] + up
[6] + up
[7] +
7588 up
[8] + up
[9] + up
[10] + up
[11] +
7589 up
[12] + up
[13] + up
[14] + up
[15];
7591 /* Fold initial sum */
7592 sum
= (sum
& 0xffff) + (sum
>> 16);
7596 if ((hck_flags
& (HCK_FULLCKSUM
|HCK_PARTIALCKSUM
)) == 0)
7597 IP6_STAT(ipst
, ip6_in_sw_cksum
);
7599 IP_CKSUM_RECV(hck_flags
, sum
, (uchar_t
*)
7600 ((uchar_t
*)mp
->b_rptr
+ DB_CKSUMSTART(mp
)),
7601 (int32_t)(whereptr
- (uchar_t
*)mp
->b_rptr
),
7602 mp
, mp1
, cksum_err
);
7605 BUMP_MIB(ill
->ill_ip_mib
, tcpIfStatsInErrs
);
7607 if (hck_flags
& HCK_FULLCKSUM
) {
7609 ip6_tcp_in_full_hw_cksum_err
);
7610 } else if (hck_flags
& HCK_PARTIALCKSUM
) {
7612 ip6_tcp_in_part_hw_cksum_err
);
7614 IP6_STAT(ipst
, ip6_tcp_in_sw_cksum_err
);
7620 ip_fanout_tcp_v6(q
, first_mp
, ip6h
, ill
, inill
,
7621 (flags
|IP_FF_SEND_ICMP
|IP_FF_SYN_ADDIRE
|
7622 IP_FF_IPINFO
), hdr_len
, mctl_present
, zoneid
);
7628 uint32_t calcsum
, pktsum
;
7629 uint_t hdr_len
= pkt_len
- remlen
;
7630 sctp_stack_t
*sctps
;
7632 sctps
= inill
->ill_ipst
->ips_netstack
->netstack_sctp
;
7634 /* SCTP needs all of the SCTP header */
7635 if (remlen
< sizeof (*sctph
)) {
7638 if (whereptr
+ sizeof (*sctph
) > mp
->b_wptr
) {
7639 ASSERT(mp
->b_cont
!= NULL
);
7640 if (!pullupmsg(mp
, hdr_len
+ sizeof (*sctph
))) {
7641 BUMP_MIB(ill
->ill_ip_mib
,
7642 ipIfStatsInDiscards
);
7646 ip6h
= (ip6_t
*)mp
->b_rptr
;
7647 whereptr
= (uint8_t *)ip6h
+ hdr_len
;
7650 sctph
= (sctp_hdr_t
*)(mp
->b_rptr
+ hdr_len
);
7652 pktsum
= sctph
->sh_chksum
;
7653 sctph
->sh_chksum
= 0;
7654 calcsum
= sctp_cksum(mp
, hdr_len
);
7655 if (calcsum
!= pktsum
) {
7656 BUMP_MIB(&sctps
->sctps_mib
, sctpChecksumError
);
7660 sctph
->sh_chksum
= pktsum
;
7661 ports
= *(uint32_t *)(mp
->b_rptr
+ hdr_len
);
7662 if ((connp
= sctp_fanout(&ip6h
->ip6_src
, &ip6h
->ip6_dst
,
7663 ports
, zoneid
, mp
, sctps
)) == NULL
) {
7664 ip_fanout_sctp_raw(first_mp
, ill
,
7665 (ipha_t
*)ip6h
, B_FALSE
, ports
,
7667 (flags
|IP_FF_SEND_ICMP
|IP_FF_IPINFO
),
7671 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInDelivers
);
7672 sctp_input(connp
, (ipha_t
*)ip6h
, mp
, first_mp
, ill
,
7673 B_FALSE
, mctl_present
);
7680 hdr_len
= pkt_len
- remlen
;
7682 if (hada_mp
!= NULL
) {
7683 ip0dbg(("udp hada drop\n"));
7687 /* Verify that at least the ports are present */
7688 if (remlen
< UDPH_SIZE
)
7690 if (mp
->b_cont
!= NULL
&&
7691 whereptr
+ UDPH_SIZE
> mp
->b_wptr
) {
7692 if (!pullupmsg(mp
, hdr_len
+ UDPH_SIZE
)) {
7693 BUMP_MIB(ill
->ill_ip_mib
,
7694 ipIfStatsInDiscards
);
7699 ip6h
= (ip6_t
*)mp
->b_rptr
;
7700 whereptr
= (uint8_t *)ip6h
+ hdr_len
;
7704 * Before going through the regular checksum
7705 * calculation, make sure the received checksum
7706 * is non-zero. RFC 2460 says, a 0x0000 checksum
7707 * in a UDP packet (within IPv6 packet) is invalid
7708 * and should be replaced by 0xffff. This makes
7709 * sense as regular checksum calculation will
7710 * pass for both the cases i.e. 0x0000 and 0xffff.
7711 * Removing one of the case makes error detection
7715 if (((udpha_t
*)whereptr
)->uha_checksum
== 0) {
7716 /* 0x0000 checksum is invalid */
7717 ip1dbg(("ip_rput_data_v6: Invalid UDP "
7718 "checksum value 0x0000\n"));
7719 BUMP_MIB(ill
->ill_ip_mib
,
7720 udpIfStatsInCksumErrs
);
7725 up
= (uint16_t *)&ip6h
->ip6_src
;
7728 * UDP checksum calculation. First sum up the
7729 * pseudo-header fields:
7730 * - Source IPv6 address
7731 * - Destination IPv6 address
7732 * - UDP payload length
7736 sum
= htons(IPPROTO_UDP
+ remlen
) +
7737 up
[0] + up
[1] + up
[2] + up
[3] +
7738 up
[4] + up
[5] + up
[6] + up
[7] +
7739 up
[8] + up
[9] + up
[10] + up
[11] +
7740 up
[12] + up
[13] + up
[14] + up
[15];
7742 /* Fold initial sum */
7743 sum
= (sum
& 0xffff) + (sum
>> 16);
7745 if (reass_hck_flags
!= 0) {
7746 hck_flags
= reass_hck_flags
;
7748 IP_CKSUM_RECV_REASS(hck_flags
,
7749 (int32_t)(whereptr
- (uchar_t
*)mp
->b_rptr
),
7750 sum
, reass_sum
, cksum_err
);
7754 IP_CKSUM_RECV(hck_flags
, sum
, (uchar_t
*)
7755 ((uchar_t
*)mp
->b_rptr
+ DB_CKSUMSTART(mp
)),
7756 (int32_t)(whereptr
- (uchar_t
*)mp
->b_rptr
),
7757 mp
, mp1
, cksum_err
);
7760 if ((hck_flags
& (HCK_FULLCKSUM
|HCK_PARTIALCKSUM
)) == 0)
7761 IP6_STAT(ipst
, ip6_in_sw_cksum
);
7764 BUMP_MIB(ill
->ill_ip_mib
,
7765 udpIfStatsInCksumErrs
);
7767 if (hck_flags
& HCK_FULLCKSUM
)
7769 ip6_udp_in_full_hw_cksum_err
);
7770 else if (hck_flags
& HCK_PARTIALCKSUM
)
7772 ip6_udp_in_part_hw_cksum_err
);
7774 IP6_STAT(ipst
, ip6_udp_in_sw_cksum_err
);
7781 case IPPROTO_ICMPV6
: {
7784 uint_t hdr_len
= pkt_len
- remlen
;
7786 if (hada_mp
!= NULL
) {
7787 ip0dbg(("icmp hada drop\n"));
7791 up
= (uint16_t *)&ip6h
->ip6_src
;
7792 sum
= htons(IPPROTO_ICMPV6
+ remlen
) +
7793 up
[0] + up
[1] + up
[2] + up
[3] +
7794 up
[4] + up
[5] + up
[6] + up
[7] +
7795 up
[8] + up
[9] + up
[10] + up
[11] +
7796 up
[12] + up
[13] + up
[14] + up
[15];
7797 sum
= (sum
& 0xffff) + (sum
>> 16);
7798 sum
= IP_CSUM(mp
, hdr_len
, sum
);
7800 /* IPv6 ICMP checksum failed */
7801 ip1dbg(("ip_rput_data_v6: ICMPv6 checksum "
7804 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInMsgs
);
7805 BUMP_MIB(ill
->ill_icmp6_mib
,
7806 ipv6IfIcmpInErrors
);
7812 /* Check variable for testing applications */
7813 if (ipst
->ips_ipv6_drop_inbound_icmpv6
) {
7818 * Assume that there is always at least one conn for
7819 * ICMPv6 (in.ndpd) i.e. don't optimize the case
7820 * where there is no conn.
7822 if (IN6_IS_ADDR_MULTICAST(&ip6h
->ip6_dst
)) {
7826 ASSERT(!IS_LOOPBACK(ill
));
7828 * In the multicast case, applications may have
7829 * joined the group from different zones, so we
7830 * need to deliver the packet to each of them.
7831 * Loop through the multicast memberships
7832 * structures (ilm) on the receive ill and send
7833 * a copy of the packet up each matching one.
7835 ilm
= ilm_walker_start(&ilw
, inill
);
7837 ilm
= ilm_walker_step(&ilw
, ilm
)) {
7838 if (!IN6_ARE_ADDR_EQUAL(
7839 &ilm
->ilm_v6addr
, &ip6h
->ip6_dst
))
7841 if (!ipif_lookup_zoneid(
7842 ilw
.ilw_walk_ill
, ilm
->ilm_zoneid
,
7846 first_mp1
= ip_copymsg(first_mp
);
7847 if (first_mp1
== NULL
)
7849 icmp_inbound_v6(q
, first_mp1
,
7850 ilw
.ilw_walk_ill
, inill
,
7851 hdr_len
, mctl_present
, 0,
7852 ilm
->ilm_zoneid
, dl_mp
);
7854 ilm_walker_finish(&ilw
);
7856 first_mp1
= ip_copymsg(first_mp
);
7857 if (first_mp1
!= NULL
)
7858 icmp_inbound_v6(q
, first_mp1
, ill
,
7859 inill
, hdr_len
, mctl_present
, 0,
7866 * Handle protocols with which IPv6 is less intimate.
7868 uint_t proto_flags
= IP_FF_RAWIP
|IP_FF_IPINFO
;
7870 if (hada_mp
!= NULL
) {
7871 ip0dbg(("default hada drop\n"));
7876 * Enable sending ICMP for "Unknown" nexthdr
7877 * case. i.e. where we did not FALLTHRU from
7878 * IPPROTO_ICMPV6 processing case above.
7879 * If we did FALLTHRU, then the packet has already been
7880 * processed for IPPF, don't process it again in
7881 * ip_fanout_proto_v6; set IP6_NO_IPPOLICY in the
7884 if (nexthdr
!= IPPROTO_ICMPV6
)
7885 proto_flags
|= IP_FF_SEND_ICMP
;
7887 proto_flags
|= IP6_NO_IPPOLICY
;
7889 ip_fanout_proto_v6(q
, first_mp
, ip6h
, ill
, inill
,
7890 nexthdr
, prev_nexthdr_offset
, (flags
|proto_flags
),
7891 mctl_present
, zoneid
);
7895 case IPPROTO_DSTOPTS
: {
7898 ip6_dest_t
*desthdr
;
7900 /* If packet is too short, look no further */
7901 if (remlen
< MIN_EHDR_LEN
)
7904 /* Check if AH is present. */
7905 if (ipsec_early_ah_v6(q
, first_mp
, mctl_present
, ill
,
7906 inill
, hada_mp
, zoneid
)) {
7911 * Reinitialize pointers, as ipsec_early_ah_v6() does
7912 * complete pullups. We don't have to do more pullups
7915 whereptr
= (uint8_t *)((uintptr_t)mp
->b_rptr
+
7916 (uintptr_t)(whereptr
- ((uint8_t *)ip6h
)));
7917 ip6h
= (ip6_t
*)mp
->b_rptr
;
7919 desthdr
= (ip6_dest_t
*)whereptr
;
7920 nexthdr
= desthdr
->ip6d_nxt
;
7921 prev_nexthdr_offset
= (uint_t
)(whereptr
-
7923 ehdrlen
= 8 * (desthdr
->ip6d_len
+ 1);
7924 if (remlen
< ehdrlen
)
7926 optptr
= whereptr
+ 2;
7928 * Note: XXX This code does not seem to make
7929 * distinction between Destination Options Header
7930 * being before/after Routing Header which can
7931 * happen if we are at the end of source route.
7932 * This may become significant in future.
7933 * (No real significant Destination Options are
7934 * defined/implemented yet ).
7936 switch (ip_process_options_v6(q
, first_mp
, ip6h
, optptr
,
7937 ehdrlen
- 2, IPPROTO_DSTOPTS
, ipst
)) {
7940 * Packet has been consumed and any needed
7943 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7947 /* No action needed continue */
7951 * Unnexpected return value
7952 * (Router alert is a Hop-by-Hop option)
7955 panic("ip_rput_data_v6: router "
7956 "alert hbh opt indication in dest opt");
7961 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
7968 case IPPROTO_FRAGMENT
: {
7969 ip6_frag_t
*fraghdr
;
7970 size_t no_frag_hdr_len
;
7972 if (hada_mp
!= NULL
) {
7973 ip0dbg(("frag hada drop\n"));
7977 ASSERT(first_mp
== mp
);
7978 if (remlen
< sizeof (ip6_frag_t
))
7981 if (mp
->b_cont
!= NULL
&&
7982 whereptr
+ sizeof (ip6_frag_t
) > mp
->b_wptr
) {
7984 pkt_len
- remlen
+ sizeof (ip6_frag_t
))) {
7985 BUMP_MIB(ill
->ill_ip_mib
,
7986 ipIfStatsInDiscards
);
7991 ip6h
= (ip6_t
*)mp
->b_rptr
;
7992 whereptr
= (uint8_t *)ip6h
+ pkt_len
- remlen
;
7995 fraghdr
= (ip6_frag_t
*)whereptr
;
7996 used
= (uint_t
)sizeof (ip6_frag_t
);
7997 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsReasmReqds
);
8000 * Invoke the CGTP (multirouting) filtering module to
8001 * process the incoming packet. Packets identified as
8002 * duplicates must be discarded. Filtering is active
8003 * only if the the ip_cgtp_filter ndd variable is
8006 if (ipst
->ips_ip_cgtp_filter
&&
8007 ipst
->ips_ip_cgtp_filter_ops
!= NULL
) {
8009 netstackid_t stackid
;
8011 stackid
= ipst
->ips_netstack
->netstack_stackid
;
8014 ipst
->ips_ip_cgtp_filter_ops
->cfo_filter_v6(
8015 stackid
, inill
->ill_phyint
->phyint_ifindex
,
8017 if (cgtp_flt_pkt
== CGTP_IP_PKT_DUPLICATE
) {
8023 /* Restore the flags */
8024 DB_CKSUMFLAGS(mp
) = hck_flags
;
8026 mp
= ip_rput_frag_v6(ill
, inill
, mp
, ip6h
, fraghdr
,
8027 remlen
- used
, &prev_nexthdr_offset
,
8028 &reass_sum
, &reass_hck_flags
);
8030 /* Reassembly is still pending */
8033 /* The first mblk are the headers before the frag hdr */
8034 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsReasmOKs
);
8036 first_mp
= mp
; /* mp has most likely changed! */
8037 no_frag_hdr_len
= mp
->b_wptr
- mp
->b_rptr
;
8038 ip6h
= (ip6_t
*)mp
->b_rptr
;
8039 nexthdr
= ((char *)ip6h
)[prev_nexthdr_offset
];
8040 whereptr
= mp
->b_rptr
+ no_frag_hdr_len
;
8041 remlen
= ntohs(ip6h
->ip6_plen
) +
8042 (uint16_t)(IPV6_HDR_LEN
- no_frag_hdr_len
);
8043 pkt_len
= msgdsize(mp
);
8047 case IPPROTO_HOPOPTS
: {
8048 if (hada_mp
!= NULL
) {
8049 ip0dbg(("hop hada drop\n"));
8053 * Illegal header sequence.
8054 * (Hop-by-hop headers are processed above
8055 * and required to immediately follow IPv6 header)
8057 icmp_param_problem_v6(WR(q
), first_mp
,
8058 ICMP6_PARAMPROB_NEXTHEADER
,
8059 prev_nexthdr_offset
,
8060 B_FALSE
, B_FALSE
, zoneid
, ipst
);
8063 case IPPROTO_ROUTING
: {
8067 /* If packet is too short, look no further */
8068 if (remlen
< MIN_EHDR_LEN
)
8071 /* Check if AH is present. */
8072 if (ipsec_early_ah_v6(q
, first_mp
, mctl_present
, ill
,
8073 inill
, hada_mp
, zoneid
)) {
8078 * Reinitialize pointers, as ipsec_early_ah_v6() does
8079 * complete pullups. We don't have to do more pullups
8082 whereptr
= (uint8_t *)((uintptr_t)mp
->b_rptr
+
8083 (uintptr_t)(whereptr
- ((uint8_t *)ip6h
)));
8084 ip6h
= (ip6_t
*)mp
->b_rptr
;
8086 rthdr
= (ip6_rthdr_t
*)whereptr
;
8087 nexthdr
= rthdr
->ip6r_nxt
;
8088 prev_nexthdr_offset
= (uint_t
)(whereptr
-
8090 ehdrlen
= 8 * (rthdr
->ip6r_len
+ 1);
8091 if (remlen
< ehdrlen
)
8093 if (rthdr
->ip6r_segleft
!= 0) {
8094 /* Not end of source route */
8096 BUMP_MIB(ill
->ill_ip_mib
,
8097 ipIfStatsForwProhibits
);
8102 ip_process_rthdr(q
, mp
, ip6h
, rthdr
, ill
,
8103 flags
, hada_mp
, dl_mp
);
8112 * Fast path for AH/ESP. If this is the first time
8113 * we are sending a datagram to AH/ESP, allocate
8114 * a IPSEC_IN message and prepend it. Otherwise,
8120 ipsec_stack_t
*ipss
;
8122 ipss
= ipst
->ips_netstack
->netstack_ipsec
;
8123 if (!mctl_present
) {
8124 ASSERT(first_mp
== mp
);
8125 first_mp
= ipsec_in_alloc(B_FALSE
,
8126 ipst
->ips_netstack
);
8127 if (first_mp
== NULL
) {
8128 ip1dbg(("ip_rput_data_v6: IPSEC_IN "
8129 "allocation failure.\n"));
8130 BUMP_MIB(ill
->ill_ip_mib
,
8131 ipIfStatsInDiscards
);
8136 * Store the ill_index so that when we come back
8137 * from IPSEC we ride on the same queue.
8139 ii
= (ipsec_in_t
*)first_mp
->b_rptr
;
8140 ii
->ipsec_in_ill_index
=
8141 ill
->ill_phyint
->phyint_ifindex
;
8142 ii
->ipsec_in_rill_index
=
8143 inill
->ill_phyint
->phyint_ifindex
;
8144 first_mp
->b_cont
= mp
;
8146 * Cache hardware acceleration info.
8148 if (hada_mp
!= NULL
) {
8149 IPSECHW_DEBUG(IPSECHW_PKT
,
8150 ("ip_rput_data_v6: "
8151 "caching data attr.\n"));
8152 ii
->ipsec_in_accelerated
= B_TRUE
;
8153 ii
->ipsec_in_da
= hada_mp
;
8157 ii
= (ipsec_in_t
*)first_mp
->b_rptr
;
8160 if (!ipsec_loaded(ipss
)) {
8161 ip_proto_not_sup(q
, first_mp
, IP_FF_SEND_ICMP
,
8166 /* select inbound SA and have IPsec process the pkt */
8167 if (nexthdr
== IPPROTO_ESP
) {
8168 esph_t
*esph
= ipsec_inbound_esp_sa(first_mp
,
8169 ipst
->ips_netstack
);
8172 ASSERT(ii
->ipsec_in_esp_sa
!= NULL
);
8173 ASSERT(ii
->ipsec_in_esp_sa
->ipsa_input_func
!=
8175 ipsec_rc
= ii
->ipsec_in_esp_sa
->ipsa_input_func(
8178 ah_t
*ah
= ipsec_inbound_ah_sa(first_mp
,
8179 ipst
->ips_netstack
);
8182 ASSERT(ii
->ipsec_in_ah_sa
!= NULL
);
8183 ASSERT(ii
->ipsec_in_ah_sa
->ipsa_input_func
!=
8185 ipsec_rc
= ii
->ipsec_in_ah_sa
->ipsa_input_func(
8190 case IPSEC_STATUS_SUCCESS
:
8192 case IPSEC_STATUS_FAILED
:
8193 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
8195 case IPSEC_STATUS_PENDING
:
8198 /* we're done with IPsec processing, send it up */
8199 ip_fanout_proto_again(first_mp
, ill
, inill
, NULL
);
8203 /* All processing is done. Count as "delivered". */
8206 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInDelivers
);
8210 ASSERT(remlen
>= used
);
8216 ip1dbg(("ip_rput_data_v6: packet too short %d %lu %d\n",
8217 ip6_len
, pkt_len
, remlen
));
8218 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInTruncatedPkts
);
8223 if (mctl_present
|| IN6_IS_ADDR_MULTICAST(&ip6h
->ip6_dst
)) {
8226 connp
= ipcl_classify_v6(mp
, IPPROTO_UDP
, hdr_len
, zoneid
,
8228 if ((connp
!= NULL
) && (connp
->conn_upq
== NULL
)) {
8229 CONN_DEC_REF(connp
);
8234 if (connp
== NULL
) {
8237 ports
= *(uint32_t *)(mp
->b_rptr
+ hdr_len
+
8239 IP6_STAT(ipst
, ip6_udp_slow_path
);
8240 ip_fanout_udp_v6(q
, first_mp
, ip6h
, ports
, ill
, inill
,
8241 (flags
|IP_FF_SEND_ICMP
|IP_FF_IPINFO
), mctl_present
,
8246 if ((IPCL_IS_NONSTR(connp
) && PROTO_FLOW_CNTRLD(connp
)) ||
8247 (!IPCL_IS_NONSTR(connp
) && CONN_UDP_FLOWCTLD(connp
))) {
8249 BUMP_MIB(ill
->ill_ip_mib
, udpIfStatsInOverflows
);
8250 CONN_DEC_REF(connp
);
8254 /* Initiate IPPF processing */
8255 if (IP6_IN_IPP(flags
, ipst
)) {
8256 ip_process(IPP_LOCAL_IN
, &mp
, ill
->ill_phyint
->phyint_ifindex
);
8258 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
8259 CONN_DEC_REF(connp
);
8264 if (connp
->conn_ip_recvpktinfo
||
8265 IN6_IS_ADDR_LINKLOCAL(&ip6h
->ip6_src
)) {
8266 mp
= ip_add_info_v6(mp
, inill
, &ip6h
->ip6_dst
);
8268 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
8269 CONN_DEC_REF(connp
);
8274 IP6_STAT(ipst
, ip6_udp_fast_path
);
8275 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInDelivers
);
8277 /* Send it upstream */
8278 (connp
->conn_recv
)(connp
, mp
, NULL
);
8280 CONN_DEC_REF(connp
);
8285 ip1dbg(("ip_rput_data_v6: malformed accelerated packet\n"));
8286 /* IPsec kstats: bump counter here */
8292 * Reassemble fragment.
8293 * When it returns a completed message the first mblk will only contain
8294 * the headers prior to the fragment header.
8296 * prev_nexthdr_offset is an offset indication of where the nexthdr field is
8297 * of the preceding header. This is needed to patch the previous header's
8298 * nexthdr field when reassembly completes.
8301 ip_rput_frag_v6(ill_t
*ill
, ill_t
*inill
, mblk_t
*mp
, ip6_t
*ip6h
,
8302 ip6_frag_t
*fraghdr
, uint_t remlen
, uint_t
*prev_nexthdr_offset
,
8303 uint32_t *cksum_val
, uint16_t *cksum_flags
)
8305 uint32_t ident
= ntohl(fraghdr
->ip6f_ident
);
8307 boolean_t more_frags
;
8308 uint8_t nexthdr
= fraghdr
->ip6f_nxt
;
8309 in6_addr_t
*v6dst_ptr
;
8310 in6_addr_t
*v6src_ptr
;
8318 uint8_t ecn_info
= 0;
8322 boolean_t pruned
= B_FALSE
;
8325 ip_stack_t
*ipst
= ill
->ill_ipst
;
8327 if (cksum_val
!= NULL
)
8329 if (cksum_flags
!= NULL
)
8333 * We utilize hardware computed checksum info only for UDP since
8334 * IP fragmentation is a normal occurence for the protocol. In
8335 * addition, checksum offload support for IP fragments carrying
8336 * UDP payload is commonly implemented across network adapters.
8338 ASSERT(inill
!= NULL
);
8339 if (nexthdr
== IPPROTO_UDP
&& dohwcksum
&& ILL_HCKSUM_CAPABLE(inill
) &&
8340 (DB_CKSUMFLAGS(mp
) & (HCK_FULLCKSUM
| HCK_PARTIALCKSUM
))) {
8341 mblk_t
*mp1
= mp
->b_cont
;
8344 /* Record checksum information from the packet */
8345 sum_val
= (uint32_t)DB_CKSUM16(mp
);
8346 sum_flags
= DB_CKSUMFLAGS(mp
);
8348 /* fragmented payload offset from beginning of mblk */
8349 offset
= (uint16_t)((uchar_t
*)&fraghdr
[1] - mp
->b_rptr
);
8351 if ((sum_flags
& HCK_PARTIALCKSUM
) &&
8352 (mp1
== NULL
|| mp1
->b_cont
== NULL
) &&
8353 offset
>= (uint16_t)DB_CKSUMSTART(mp
) &&
8354 ((len
= offset
- (uint16_t)DB_CKSUMSTART(mp
)) & 1) == 0) {
8357 * Partial checksum has been calculated by hardware
8358 * and attached to the packet; in addition, any
8359 * prepended extraneous data is even byte aligned.
8360 * If any such data exists, we adjust the checksum;
8361 * this would also handle any postpended data.
8363 IP_ADJCKSUM_PARTIAL(mp
->b_rptr
+ DB_CKSUMSTART(mp
),
8366 /* One's complement subtract extraneous checksum */
8368 sum_val
= ~(adj
- sum_val
) & 0xFFFF;
8377 /* Clear hardware checksumming flag */
8378 DB_CKSUMFLAGS(mp
) = 0;
8381 * Note: Fragment offset in header is in 8-octet units.
8382 * Clearing least significant 3 bits not only extracts
8383 * it but also gets it in units of octets.
8385 offset
= ntohs(fraghdr
->ip6f_offlg
) & ~7;
8386 more_frags
= (fraghdr
->ip6f_offlg
& IP6F_MORE_FRAG
);
8389 * Is the more frags flag on and the payload length not a multiple
8392 if (more_frags
&& (ntohs(ip6h
->ip6_plen
) & 7)) {
8395 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
8396 zoneid
= ipif_lookup_addr_zoneid_v6(&ip6h
->ip6_dst
, ill
, ipst
);
8397 if (zoneid
== ALL_ZONES
) {
8401 icmp_param_problem_v6(ill
->ill_wq
, mp
, ICMP6_PARAMPROB_HEADER
,
8402 (uint32_t)((char *)&ip6h
->ip6_plen
-
8403 (char *)ip6h
), B_FALSE
, B_FALSE
, zoneid
, ipst
);
8407 v6src_ptr
= &ip6h
->ip6_src
;
8408 v6dst_ptr
= &ip6h
->ip6_dst
;
8411 hdr_length
= (uint_t
)((char *)&fraghdr
[1] - (char *)ip6h
);
8415 * Would fragment cause reassembled packet to have a payload length
8416 * greater than IP_MAXPACKET - the max payload size?
8418 if (end
> IP_MAXPACKET
) {
8421 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
8422 zoneid
= ipif_lookup_addr_zoneid_v6(&ip6h
->ip6_dst
, ill
, ipst
);
8423 if (zoneid
== ALL_ZONES
) {
8427 icmp_param_problem_v6(ill
->ill_wq
, mp
, ICMP6_PARAMPROB_HEADER
,
8428 (uint32_t)((char *)&fraghdr
->ip6f_offlg
-
8429 (char *)ip6h
), B_FALSE
, B_FALSE
, zoneid
, ipst
);
8434 * This packet just has one fragment. Reassembly not
8437 if (!more_frags
&& offset
== 0) {
8442 * Drop the fragmented as early as possible, if
8443 * we don't have resource(s) to re-assemble.
8445 if (ipst
->ips_ip_reass_queue_bytes
== 0) {
8450 /* Record the ECN field info. */
8451 ecn_info
= (uint8_t)(ntohl(ip6h
->ip6_vcf
& htonl(~0xFFCFFFFF)) >> 20);
8453 * If this is not the first fragment, dump the unfragmentable
8454 * portion of the packet.
8457 mp
->b_rptr
= (uchar_t
*)&fraghdr
[1];
8460 * Fragmentation reassembly. Each ILL has a hash table for
8461 * queueing packets undergoing reassembly for all IPIFs
8462 * associated with the ILL. The hash is based on the packet
8463 * IP ident field. The ILL frag hash table was allocated
8464 * as a timer block at the time the ILL was created. Whenever
8465 * there is anything on the reassembly queue, the timer will
8468 msg_len
= MBLKSIZE(mp
);
8470 while (tail_mp
->b_cont
!= NULL
) {
8471 tail_mp
= tail_mp
->b_cont
;
8472 msg_len
+= MBLKSIZE(tail_mp
);
8475 * If the reassembly list for this ILL will get too big
8479 if ((msg_len
+ sizeof (*ipf
) + ill
->ill_frag_count
) >=
8480 ipst
->ips_ip_reass_queue_bytes
) {
8482 (ipst
->ips_ip_reass_queue_bytes
< msg_len
) ? 0 :
8483 (ipst
->ips_ip_reass_queue_bytes
- msg_len
));
8487 ipfb
= &ill
->ill_frag_hash_tbl
[ILL_FRAG_HASH_V6(*v6src_ptr
, ident
)];
8488 mutex_enter(&ipfb
->ipfb_lock
);
8490 ipfp
= &ipfb
->ipfb_ipf
;
8491 /* Try to find an existing fragment queue for this packet. */
8496 * It has to match on ident, source address, and
8499 if (ipf
->ipf_ident
== ident
&&
8500 IN6_ARE_ADDR_EQUAL(&ipf
->ipf_v6src
, v6src_ptr
) &&
8501 IN6_ARE_ADDR_EQUAL(&ipf
->ipf_v6dst
, v6dst_ptr
)) {
8504 * If we have received too many
8505 * duplicate fragments for this packet
8508 if (ipf
->ipf_num_dups
> ip_max_frag_dups
) {
8509 ill_frag_free_pkts(ill
, ipfb
, ipf
, 1);
8511 mutex_exit(&ipfb
->ipfb_lock
);
8517 ipfp
= &ipf
->ipf_hash_next
;
8523 * If we pruned the list, do we want to store this new
8524 * fragment?. We apply an optimization here based on the
8525 * fact that most fragments will be received in order.
8526 * So if the offset of this incoming fragment is zero,
8527 * it is the first fragment of a new packet. We will
8528 * keep it. Otherwise drop the fragment, as we have
8529 * probably pruned the packet already (since the
8530 * packet cannot be found).
8533 if (pruned
&& offset
!= 0) {
8534 mutex_exit(&ipfb
->ipfb_lock
);
8539 /* New guy. Allocate a frag message. */
8540 mp1
= allocb(sizeof (*ipf
), BPRI_MED
);
8542 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
8545 mutex_exit(&ipfb
->ipfb_lock
);
8549 if (ipfb
->ipfb_frag_pkts
>= MAX_FRAG_PKTS(ipst
)) {
8551 * Too many fragmented packets in this hash bucket.
8554 ill_frag_free_pkts(ill
, ipfb
, ipfb
->ipfb_ipf
, 1);
8559 /* Initialize the fragment header. */
8560 ipf
= (ipf_t
*)mp1
->b_rptr
;
8562 ipf
->ipf_ptphn
= ipfp
;
8564 ipf
->ipf_hash_next
= NULL
;
8565 ipf
->ipf_ident
= ident
;
8566 ipf
->ipf_v6src
= *v6src_ptr
;
8567 ipf
->ipf_v6dst
= *v6dst_ptr
;
8568 /* Record reassembly start time. */
8569 ipf
->ipf_timestamp
= gethrestime_sec();
8570 /* Record ipf generation and account for frag header */
8571 ipf
->ipf_gen
= ill
->ill_ipf_gen
++;
8572 ipf
->ipf_count
= MBLKSIZE(mp1
);
8573 ipf
->ipf_protocol
= nexthdr
;
8574 ipf
->ipf_nf_hdr_len
= 0;
8575 ipf
->ipf_prev_nexthdr_offset
= 0;
8576 ipf
->ipf_last_frag_seen
= B_FALSE
;
8577 ipf
->ipf_ecn
= ecn_info
;
8578 ipf
->ipf_num_dups
= 0;
8579 ipfb
->ipfb_frag_pkts
++;
8580 ipf
->ipf_checksum
= 0;
8581 ipf
->ipf_checksum_flags
= 0;
8583 /* Store checksum value in fragment header */
8584 if (sum_flags
!= 0) {
8585 sum_val
= (sum_val
& 0xFFFF) + (sum_val
>> 16);
8586 sum_val
= (sum_val
& 0xFFFF) + (sum_val
>> 16);
8587 ipf
->ipf_checksum
= sum_val
;
8588 ipf
->ipf_checksum_flags
= sum_flags
;
8592 * We handle reassembly two ways. In the easy case,
8593 * where all the fragments show up in order, we do
8594 * minimal bookkeeping, and just clip new pieces on
8595 * the end. If we ever see a hole, then we go off
8596 * to ip_reassemble which has to mark the pieces and
8597 * keep track of the number of holes, etc. Obviously,
8598 * the point of having both mechanisms is so we can
8599 * handle the easy case as efficiently as possible.
8602 /* Easy case, in-order reassembly so far. */
8603 /* Update the byte count */
8604 ipf
->ipf_count
+= msg_len
;
8605 ipf
->ipf_tail_mp
= tail_mp
;
8607 * Keep track of next expected offset in
8611 ipf
->ipf_nf_hdr_len
= hdr_length
;
8612 ipf
->ipf_prev_nexthdr_offset
= *prev_nexthdr_offset
;
8614 /* Hard case, hole at the beginning. */
8615 ipf
->ipf_tail_mp
= NULL
;
8617 * ipf_end == 0 means that we have given up
8618 * on easy reassembly.
8622 /* Forget checksum offload from now on */
8623 ipf
->ipf_checksum_flags
= 0;
8626 * ipf_hole_cnt is set by ip_reassemble.
8627 * ipf_count is updated by ip_reassemble.
8628 * No need to check for return value here
8629 * as we don't expect reassembly to complete or
8630 * fail for the first fragment itself.
8632 (void) ip_reassemble(mp
, ipf
, offset
, more_frags
, ill
,
8635 /* Update per ipfb and ill byte counts */
8636 ipfb
->ipfb_count
+= ipf
->ipf_count
;
8637 ASSERT(ipfb
->ipfb_count
> 0); /* Wraparound */
8638 atomic_add_32(&ill
->ill_frag_count
, ipf
->ipf_count
);
8639 /* If the frag timer wasn't already going, start it. */
8640 mutex_enter(&ill
->ill_lock
);
8641 ill_frag_timer_start(ill
);
8642 mutex_exit(&ill
->ill_lock
);
8643 goto partial_reass_done
;
8647 * If the packet's flag has changed (it could be coming up
8648 * from an interface different than the previous, therefore
8649 * possibly different checksum capability), then forget about
8650 * any stored checksum states. Otherwise add the value to
8651 * the existing one stored in the fragment header.
8653 if (sum_flags
!= 0 && sum_flags
== ipf
->ipf_checksum_flags
) {
8654 sum_val
+= ipf
->ipf_checksum
;
8655 sum_val
= (sum_val
& 0xFFFF) + (sum_val
>> 16);
8656 sum_val
= (sum_val
& 0xFFFF) + (sum_val
>> 16);
8657 ipf
->ipf_checksum
= sum_val
;
8658 } else if (ipf
->ipf_checksum_flags
!= 0) {
8659 /* Forget checksum offload from now on */
8660 ipf
->ipf_checksum_flags
= 0;
8664 * We have a new piece of a datagram which is already being
8665 * reassembled. Update the ECN info if all IP fragments
8666 * are ECN capable. If there is one which is not, clear
8667 * all the info. If there is at least one which has CE
8668 * code point, IP needs to report that up to transport.
8670 if (ecn_info
!= IPH_ECN_NECT
&& ipf
->ipf_ecn
!= IPH_ECN_NECT
) {
8671 if (ecn_info
== IPH_ECN_CE
)
8672 ipf
->ipf_ecn
= IPH_ECN_CE
;
8674 ipf
->ipf_ecn
= IPH_ECN_NECT
;
8677 if (offset
&& ipf
->ipf_end
== offset
) {
8678 /* The new fragment fits at the end */
8679 ipf
->ipf_tail_mp
->b_cont
= mp
;
8680 /* Update the byte count */
8681 ipf
->ipf_count
+= msg_len
;
8682 /* Update per ipfb and ill byte counts */
8683 ipfb
->ipfb_count
+= msg_len
;
8684 ASSERT(ipfb
->ipfb_count
> 0); /* Wraparound */
8685 atomic_add_32(&ill
->ill_frag_count
, msg_len
);
8689 ipf
->ipf_tail_mp
= tail_mp
;
8690 goto partial_reass_done
;
8694 * Go do the hard cases.
8695 * Call ip_reassemble().
8700 if (ipf
->ipf_prev_nexthdr_offset
== 0) {
8701 ipf
->ipf_nf_hdr_len
= hdr_length
;
8702 ipf
->ipf_prev_nexthdr_offset
=
8703 *prev_nexthdr_offset
;
8706 /* Save current byte count */
8707 count
= ipf
->ipf_count
;
8708 ret
= ip_reassemble(mp
, ipf
, offset
, more_frags
, ill
, msg_len
);
8710 /* Count of bytes added and subtracted (freeb()ed) */
8711 count
= ipf
->ipf_count
- count
;
8713 /* Update per ipfb and ill byte counts */
8714 ipfb
->ipfb_count
+= count
;
8715 ASSERT(ipfb
->ipfb_count
> 0); /* Wraparound */
8716 atomic_add_32(&ill
->ill_frag_count
, count
);
8718 if (ret
== IP_REASS_PARTIAL
) {
8719 goto partial_reass_done
;
8720 } else if (ret
== IP_REASS_FAILED
) {
8721 /* Reassembly failed. Free up all resources */
8722 ill_frag_free_pkts(ill
, ipfb
, ipf
, 1);
8723 for (t_mp
= mp
; t_mp
!= NULL
; t_mp
= t_mp
->b_cont
) {
8724 IP_REASS_SET_START(t_mp
, 0);
8725 IP_REASS_SET_END(t_mp
, 0);
8728 goto partial_reass_done
;
8731 /* We will reach here iff 'ret' is IP_REASS_COMPLETE */
8734 * We have completed reassembly. Unhook the frag header from
8735 * the reassembly list.
8737 * Grab the unfragmentable header length next header value out
8738 * of the first fragment
8740 ASSERT(ipf
->ipf_nf_hdr_len
!= 0);
8741 hdr_length
= ipf
->ipf_nf_hdr_len
;
8744 * Before we free the frag header, record the ECN info
8745 * to report back to the transport.
8747 ecn_info
= ipf
->ipf_ecn
;
8750 * Store the nextheader field in the header preceding the fragment
8753 nexthdr
= ipf
->ipf_protocol
;
8754 *prev_nexthdr_offset
= ipf
->ipf_prev_nexthdr_offset
;
8755 ipfp
= ipf
->ipf_ptphn
;
8757 /* We need to supply these to caller */
8758 if ((sum_flags
= ipf
->ipf_checksum_flags
) != 0)
8759 sum_val
= ipf
->ipf_checksum
;
8764 count
= ipf
->ipf_count
;
8765 ipf
= ipf
->ipf_hash_next
;
8767 ipf
->ipf_ptphn
= ipfp
;
8769 atomic_add_32(&ill
->ill_frag_count
, -count
);
8770 ASSERT(ipfb
->ipfb_count
>= count
);
8771 ipfb
->ipfb_count
-= count
;
8772 ipfb
->ipfb_frag_pkts
--;
8773 mutex_exit(&ipfb
->ipfb_lock
);
8774 /* Ditch the frag header. */
8779 * Make sure the packet is good by doing some sanity
8780 * check. If bad we can silentely drop the packet.
8783 if (hdr_length
< sizeof (ip6_frag_t
)) {
8784 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
8785 ip1dbg(("ip_rput_frag_v6: bad packet\n"));
8791 * Remove the fragment header from the initial header by
8792 * splitting the mblk into the non-fragmentable header and
8793 * everthing after the fragment extension header. This has the
8794 * side effect of putting all the headers that need destination
8795 * processing into the b_cont block-- on return this fact is
8796 * used in order to avoid having to look at the extensions
8797 * already processed.
8799 * Note that this code assumes that the unfragmentable portion
8800 * of the header is in the first mblk and increments
8801 * the read pointer past it. If this assumption is broken
8802 * this code fails badly.
8804 if (mp
->b_rptr
+ hdr_length
!= mp
->b_wptr
) {
8807 if (!(nmp
= dupb(mp
))) {
8808 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
8809 ip1dbg(("ip_rput_frag_v6: dupb failed\n"));
8813 nmp
->b_cont
= mp
->b_cont
;
8815 nmp
->b_rptr
+= hdr_length
;
8817 mp
->b_wptr
= mp
->b_rptr
+ hdr_length
- sizeof (ip6_frag_t
);
8819 ip6h
= (ip6_t
*)mp
->b_rptr
;
8820 ((char *)ip6h
)[*prev_nexthdr_offset
] = nexthdr
;
8822 /* Restore original IP length in header. */
8823 ip6h
->ip6_plen
= htons((uint16_t)(msgdsize(mp
) - IPV6_HDR_LEN
));
8824 /* Record the ECN info. */
8825 ip6h
->ip6_vcf
&= htonl(0xFFCFFFFF);
8826 ip6h
->ip6_vcf
|= htonl(ecn_info
<< 20);
8828 /* Reassembly is successful; return checksum information if needed */
8829 if (cksum_val
!= NULL
)
8830 *cksum_val
= sum_val
;
8831 if (cksum_flags
!= NULL
)
8832 *cksum_flags
= sum_flags
;
8838 * Given an mblk and a ptr, find the destination address in an IPv6 routing
8842 pluck_out_dst(mblk_t
*mp
, uint8_t *whereptr
, in6_addr_t oldrv
)
8845 int segleft
, numaddr
;
8846 in6_addr_t
*ap
, rv
= oldrv
;
8848 rt0
= (ip6_rthdr0_t
*)whereptr
;
8849 if (rt0
->ip6r0_type
!= 0 && rt0
->ip6r0_type
!= 2) {
8850 DTRACE_PROBE2(pluck_out_dst_unknown_type
, mblk_t
*, mp
,
8851 uint8_t *, whereptr
);
8854 segleft
= rt0
->ip6r0_segleft
;
8855 numaddr
= rt0
->ip6r0_len
/ 2;
8857 if ((rt0
->ip6r0_len
& 0x1) ||
8858 whereptr
+ (rt0
->ip6r0_len
+ 1) * 8 > mp
->b_wptr
||
8859 (segleft
> rt0
->ip6r0_len
/ 2)) {
8861 * Corrupt packet. Either the routing header length is odd
8862 * (can't happen) or mismatched compared to the packet, or the
8863 * number of addresses is. Return what we can. This will
8864 * only be a problem on forwarded packets that get squeezed
8865 * through an outbound tunnel enforcing IPsec Tunnel Mode.
8867 DTRACE_PROBE2(pluck_out_dst_badpkt
, mblk_t
*, mp
, uint8_t *,
8873 ap
= (in6_addr_t
*)((char *)rt0
+ sizeof (*rt0
));
8874 rv
= ap
[numaddr
- 1];
8881 * Walk through the options to see if there is a routing header.
8882 * If present get the destination which is the last address of
8886 ip_get_dst_v6(ip6_t
*ip6h
, mblk_t
*mp
, boolean_t
*is_fragment
)
8888 mblk_t
*current_mp
= mp
;
8894 whereptr
= (uint8_t *)ip6h
;
8895 ehdrlen
= sizeof (ip6_t
);
8897 /* We assume at least the IPv6 base header is within one mblk. */
8898 ASSERT(mp
->b_rptr
<= whereptr
&& mp
->b_wptr
>= whereptr
+ ehdrlen
);
8901 nexthdr
= ip6h
->ip6_nxt
;
8902 if (is_fragment
!= NULL
)
8903 *is_fragment
= B_FALSE
;
8906 * We also assume (thanks to ipsec_tun_outbound()'s pullup) that
8907 * no extension headers will be split across mblks.
8910 while (nexthdr
== IPPROTO_HOPOPTS
|| nexthdr
== IPPROTO_DSTOPTS
||
8911 nexthdr
== IPPROTO_ROUTING
) {
8912 if (nexthdr
== IPPROTO_ROUTING
)
8913 rv
= pluck_out_dst(current_mp
, whereptr
, rv
);
8916 * All IPv6 extension headers have the next-header in byte
8917 * 0, and the (length - 8) in 8-byte-words.
8919 while (whereptr
+ ehdrlen
>= current_mp
->b_wptr
) {
8920 ehdrlen
-= (current_mp
->b_wptr
- whereptr
);
8921 current_mp
= current_mp
->b_cont
;
8922 if (current_mp
== NULL
) {
8923 /* Bad packet. Return what we can. */
8924 DTRACE_PROBE3(ip_get_dst_v6_badpkt
, mblk_t
*,
8925 mp
, mblk_t
*, current_mp
, ip6_t
*, ip6h
);
8928 whereptr
= current_mp
->b_rptr
;
8930 whereptr
+= ehdrlen
;
8932 nexthdr
= *whereptr
;
8933 ASSERT(whereptr
+ 1 < current_mp
->b_wptr
);
8934 ehdrlen
= (*(whereptr
+ 1) + 1) * 8;
8938 if (nexthdr
== IPPROTO_FRAGMENT
&& is_fragment
!= NULL
)
8939 *is_fragment
= B_TRUE
;
8944 * ip_source_routed_v6:
8945 * This function is called by redirect code in ip_rput_data_v6 to
8946 * know whether this packet is source routed through this node i.e
8947 * whether this node (router) is part of the journey. This
8948 * function is called under two cases :
8950 * case 1 : Routing header was processed by this node and
8951 * ip_process_rthdr replaced ip6_dst with the next hop
8952 * and we are forwarding the packet to the next hop.
8954 * case 2 : Routing header was not processed by this node and we
8955 * are just forwarding the packet.
8957 * For case (1) we don't want to send redirects. For case(2) we
8958 * want to send redirects.
8961 ip_source_routed_v6(ip6_t
*ip6h
, mblk_t
*mp
, ip_stack_t
*ipst
)
8964 in6_addr_t
*addrptr
;
8965 ip6_rthdr0_t
*rthdr
;
8971 ip2dbg(("ip_source_routed_v6\n"));
8972 nexthdr
= ip6h
->ip6_nxt
;
8973 ehdrlen
= IPV6_HDR_LEN
;
8975 /* if a routing hdr is preceeded by HOPOPT or DSTOPT */
8976 while (nexthdr
== IPPROTO_HOPOPTS
||
8977 nexthdr
== IPPROTO_DSTOPTS
) {
8978 byteptr
= (uint8_t *)ip6h
+ ehdrlen
;
8980 * Check if we have already processed
8981 * packets or we are just a forwarding
8982 * router which only pulled up msgs up
8983 * to IPV6HDR and one HBH ext header
8985 if (byteptr
+ MIN_EHDR_LEN
> mp
->b_wptr
) {
8986 ip2dbg(("ip_source_routed_v6: Extension"
8987 " headers not processed\n"));
8990 hbhhdr
= (ip6_hbh_t
*)byteptr
;
8991 nexthdr
= hbhhdr
->ip6h_nxt
;
8992 ehdrlen
= ehdrlen
+ 8 * (hbhhdr
->ip6h_len
+ 1);
8995 case IPPROTO_ROUTING
:
8996 byteptr
= (uint8_t *)ip6h
+ ehdrlen
;
8998 * If for some reason, we haven't pulled up
8999 * the routing hdr data mblk, then we must
9000 * not have processed it at all. So for sure
9001 * we are not part of the source routed journey.
9003 if (byteptr
+ MIN_EHDR_LEN
> mp
->b_wptr
) {
9004 ip2dbg(("ip_source_routed_v6: Routing"
9005 " header not processed\n"));
9008 rthdr
= (ip6_rthdr0_t
*)byteptr
;
9010 * Either we are an intermediate router or the
9011 * last hop before destination and we have
9012 * already processed the routing header.
9013 * If segment_left is greater than or equal to zero,
9014 * then we must be the (numaddr - segleft) entry
9015 * of the routing header. Although ip6r0_segleft
9016 * is a unit8_t variable, we still check for zero
9017 * or greater value, if in case the data type
9018 * is changed someday in future.
9020 if (rthdr
->ip6r0_segleft
> 0 ||
9021 rthdr
->ip6r0_segleft
== 0) {
9024 numaddr
= rthdr
->ip6r0_len
/ 2;
9025 addrptr
= (in6_addr_t
*)((char *)rthdr
+
9027 addrptr
+= (numaddr
- (rthdr
->ip6r0_segleft
+ 1));
9028 if (addrptr
!= NULL
) {
9029 ire
= ire_ctable_lookup_v6(addrptr
, NULL
,
9030 IRE_LOCAL
, NULL
, ALL_ZONES
, NULL
,
9037 ip1dbg(("ip_source_routed_v6: No ire found\n"));
9042 ip2dbg(("ip_source_routed_v6: Not source routed here\n"));
9048 * ip_wput_v6 -- Packets sent down from transport modules show up here.
9049 * Assumes that the following set of headers appear in the first
9051 * ip6i_t (if present) CAN also appear as a separate mblk.
9053 * Any extension headers
9054 * TCP/UDP/SCTP header (if present)
9055 * The routine can handle an ICMPv6 header that is not in the first mblk.
9057 * The order to determine the outgoing interface is as follows:
9058 * 1. If an ip6i_t with IP6I_IFINDEX set then use that ill.
9059 * 2. If q is an ill queue and (link local or multicast destination) then
9061 * 3. If IPV6_BOUND_IF has been set use that ill.
9062 * 4. For multicast: if IPV6_MULTICAST_IF has been set use it. Otherwise
9063 * look for the best IRE match for the unspecified group to determine
9065 * 5. For unicast: Just do an IRE lookup for the best match.
9067 * arg2 is always a queue_t *.
9068 * When that queue is an ill_t (i.e. q_next != NULL), then arg must be
9070 * When that queue is not an ill_t, then arg must be a conn_t pointer.
9073 ip_output_v6(void *arg
, mblk_t
*mp
, void *arg2
, int caller
)
9075 conn_t
*connp
= NULL
;
9076 queue_t
*q
= (queue_t
*)arg2
;
9078 ire_t
*sctp_ire
= NULL
;
9084 int cksum_request
; /* -1 => normal. */
9085 /* 1 => Skip TCP/UDP/SCTP checksum */
9086 /* Otherwise contains insert offset for checksum */
9088 boolean_t do_outrequests
; /* Increment OutRequests? */
9089 mib2_ipIfStatsEntry_t
*mibptr
;
9090 int match_flags
= MATCH_IRE_ILL
;
9092 boolean_t mctl_present
;
9094 boolean_t multirt_need_resolve
= B_FALSE
;
9095 mblk_t
*copy_mp
= NULL
;
9099 ill_t
*saved_ill
= NULL
;
9100 boolean_t conn_lock_held
;
9101 boolean_t need_decref
= B_FALSE
;
9104 if (q
->q_next
!= NULL
) {
9105 ill
= (ill_t
*)q
->q_ptr
;
9106 ipst
= ill
->ill_ipst
;
9108 connp
= (conn_t
*)arg
;
9109 ASSERT(connp
!= NULL
);
9110 ipst
= connp
->conn_netstack
->netstack_ip
;
9114 * Highest bit in version field is Reachability Confirmation bit
9115 * used by NUD in ip_xmit_v6().
9118 #define IPVER(ip6h) ((((uint32_t *)ip6h)[0] >> 28) & 0x7)
9120 #define IPVER(ip6h) ((((uint32_t *)ip6h)[0] >> 4) & 0x7)
9124 * M_CTL comes from 6 places
9126 * 1) TCP sends down IPSEC_OUT(M_CTL) for detached connections
9127 * both V4 and V6 datagrams.
9129 * 2) AH/ESP sends down M_CTL after doing their job with both
9130 * V4 and V6 datagrams.
9132 * 3) NDP callbacks when nce is resolved and IPSEC_OUT has been
9135 * 4) Notifications from an external resolver (for XRESOLV ifs)
9137 * 5) AH/ESP send down IPSEC_CTL(M_CTL) to be relayed to hardware for
9138 * IPsec hardware acceleration support.
9142 * We need to handle (1)'s IPv6 case and (3) here. For the
9143 * IPv4 case in (1), and (2), IPSEC processing has already
9144 * started. The code in ip_wput() already knows how to handle
9145 * continuing IPSEC processing (for IPv4 and IPv6). All other
9146 * M_CTLs (including case (4)) are passed on to ip_wput_nondata()
9150 mctl_present
= B_FALSE
;
9153 /* Multidata transmit? */
9154 if (DB_TYPE(mp
) == M_MULTIDATA
) {
9156 * We should never get here, since all Multidata messages
9157 * originating from tcp should have been directed over to
9158 * tcp_multisend() in the first place.
9160 BUMP_MIB(&ipst
->ips_ip6_mib
, ipIfStatsOutDiscards
);
9163 } else if (DB_TYPE(mp
) == M_CTL
) {
9164 uint32_t mctltype
= 0;
9165 uint32_t mlen
= MBLKL(first_mp
);
9168 mctl_present
= B_TRUE
;
9169 io
= (ipsec_out_t
*)first_mp
->b_rptr
;
9172 * Validate this M_CTL message. The only three types of
9173 * M_CTL messages we expect to see in this code path are
9174 * ipsec_out_t or ipsec_in_t structures (allocated as
9175 * ipsec_info_t unions), or ipsec_ctl_t structures.
9176 * The ipsec_out_type and ipsec_in_type overlap in the two
9177 * data structures, and they are either set to IPSEC_OUT
9178 * or IPSEC_IN depending on which data structure it is.
9179 * ipsec_ctl_t is an IPSEC_CTL.
9181 * All other M_CTL messages are sent to ip_wput_nondata()
9184 if (mlen
>= sizeof (io
->ipsec_out_type
))
9185 mctltype
= io
->ipsec_out_type
;
9187 if ((mlen
== sizeof (ipsec_ctl_t
)) &&
9188 (mctltype
== IPSEC_CTL
)) {
9189 ip_output(arg
, first_mp
, arg2
, caller
);
9193 if ((mlen
< sizeof (ipsec_info_t
)) ||
9194 (mctltype
!= IPSEC_OUT
&& mctltype
!= IPSEC_IN
) ||
9196 ip_wput_nondata(NULL
, q
, first_mp
, NULL
);
9199 /* NDP callbacks have q_next non-NULL. That's case #3. */
9200 if (q
->q_next
== NULL
) {
9201 ip6h
= (ip6_t
*)mp
->b_rptr
;
9203 * For a freshly-generated TCP dgram that needs IPV6
9204 * processing, don't call ip_wput immediately. We can
9205 * tell this by the ipsec_out_proc_begin. In-progress
9206 * IPSEC_OUT messages have proc_begin set to TRUE,
9207 * and we want to send all IPSEC_IN messages to
9208 * ip_wput() for IPsec processing or finishing.
9210 if (mctltype
== IPSEC_IN
||
9211 IPVER(ip6h
) != IPV6_VERSION
||
9212 io
->ipsec_out_proc_begin
) {
9213 mibptr
= &ipst
->ips_ip6_mib
;
9217 } else if (DB_TYPE(mp
) != M_DATA
) {
9218 ip_wput_nondata(NULL
, q
, mp
, NULL
);
9222 ip6h
= (ip6_t
*)mp
->b_rptr
;
9224 if (IPVER(ip6h
) != IPV6_VERSION
) {
9225 mibptr
= &ipst
->ips_ip6_mib
;
9229 if (is_system_labeled() && DB_TYPE(mp
) == M_DATA
&&
9230 (connp
== NULL
|| !connp
->conn_ulp_labeled
)) {
9233 if (connp
!= NULL
) {
9234 ASSERT(CONN_CRED(connp
) != NULL
);
9235 err
= tsol_check_label_v6(BEST_CRED(mp
, connp
),
9236 &mp
, connp
->conn_mac_exempt
, ipst
);
9237 } else if ((cr
= msg_getcred(mp
, NULL
)) != NULL
) {
9238 err
= tsol_check_label_v6(cr
, &mp
, B_FALSE
, ipst
);
9241 first_mp
->b_cont
= mp
;
9246 tsol_ip_log_drop_checklabel_ip6
, char *,
9247 "conn(1), failed to check/update mp(2)",
9248 conn_t
, connp
, mblk_t
, mp
);
9252 ip6h
= (ip6_t
*)mp
->b_rptr
;
9254 if (q
->q_next
!= NULL
) {
9256 * We don't know if this ill will be used for IPv6
9257 * until the ILLF_IPV6 flag is set via SIOCSLIFNAME.
9258 * ipif_set_values() sets the ill_isv6 flag to true if
9259 * ILLF_IPV6 is set. If the ill_isv6 flag isn't true,
9260 * just drop the packet.
9262 if (!ill
->ill_isv6
) {
9263 ip1dbg(("ip_wput_v6: Received an IPv6 packet before "
9264 "ILLF_IPV6 was set\n"));
9268 /* For uniformity do a refhold */
9269 mutex_enter(&ill
->ill_lock
);
9270 if (!ILL_CAN_LOOKUP(ill
)) {
9271 mutex_exit(&ill
->ill_lock
);
9275 ill_refhold_locked(ill
);
9276 mutex_exit(&ill
->ill_lock
);
9277 mibptr
= ill
->ill_ip_mib
;
9279 ASSERT(mibptr
!= NULL
);
9281 BUMP_MIB(mibptr
, ipIfStatsHCOutRequests
);
9282 do_outrequests
= B_FALSE
;
9283 zoneid
= (zoneid_t
)(uintptr_t)arg
;
9285 ASSERT(connp
!= NULL
);
9286 zoneid
= connp
->conn_zoneid
;
9288 /* is queue flow controlled? */
9289 if ((q
->q_first
|| connp
->conn_draining
) &&
9290 (caller
== IP_WPUT
)) {
9292 * 1) TCP sends down M_CTL for detached connections.
9293 * 2) AH/ESP sends down M_CTL.
9295 * We don't flow control either of the above. Only
9296 * UDP and others are flow controlled for which we
9297 * can't have a M_CTL.
9299 ASSERT(first_mp
== mp
);
9303 mibptr
= &ipst
->ips_ip6_mib
;
9304 unspec_src
= connp
->conn_unspec_src
;
9305 do_outrequests
= B_TRUE
;
9306 if (mp
->b_flag
& MSGHASREF
) {
9307 mp
->b_flag
&= ~MSGHASREF
;
9308 ASSERT(connp
->conn_ulp
== IPPROTO_SCTP
);
9309 SCTP_EXTRACT_IPINFO(mp
, sctp_ire
);
9310 need_decref
= B_TRUE
;
9314 * If there is a policy, try to attach an ipsec_out in
9315 * the front. At the end, first_mp either points to a
9316 * M_DATA message or IPSEC_OUT message linked to a
9317 * M_DATA message. We have to do it now as we might
9318 * lose the "conn" if we go through ip_newroute.
9320 if (!mctl_present
&&
9321 (connp
->conn_out_enforce_policy
||
9322 connp
->conn_latch
!= NULL
)) {
9323 ASSERT(first_mp
== mp
);
9324 /* XXX Any better way to get the protocol fast ? */
9325 if (((mp
= ipsec_attach_ipsec_out(&mp
, connp
, NULL
,
9326 connp
->conn_ulp
, ipst
->ips_netstack
)) == NULL
)) {
9327 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
9329 CONN_DEC_REF(connp
);
9332 ASSERT(mp
->b_datap
->db_type
== M_CTL
);
9335 mctl_present
= B_TRUE
;
9336 io
= (ipsec_out_t
*)first_mp
->b_rptr
;
9341 /* check for alignment and full IPv6 header */
9342 if (!OK_32PTR((uchar_t
*)ip6h
) ||
9343 (mp
->b_wptr
- (uchar_t
*)ip6h
) < IPV6_HDR_LEN
) {
9344 ip0dbg(("ip_wput_v6: bad alignment or length\n"));
9346 BUMP_MIB(mibptr
, ipIfStatsHCOutRequests
);
9347 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
9352 CONN_DEC_REF(connp
);
9355 v6dstp
= &ip6h
->ip6_dst
;
9360 * Once neighbor discovery has completed, ndp_process() will provide
9361 * locally generated packets for which processing can be reattempted.
9362 * In these cases, connp is NULL and the original zone is part of a
9363 * prepended ipsec_out_t.
9367 * When coming from icmp_input_v6, the zoneid might not match
9368 * for the loopback case, because inside icmp_input_v6 the
9369 * queue_t is a conn queue from the sending side.
9371 zoneid
= io
->ipsec_out_zoneid
;
9372 ASSERT(zoneid
!= ALL_ZONES
);
9375 if (ip6h
->ip6_nxt
== IPPROTO_RAW
) {
9377 * This is an ip6i_t header followed by an ip6_hdr.
9378 * Check which fields are set.
9380 * When the packet comes from a transport we should have
9381 * all needed headers in the first mblk. However, when
9382 * going through ip_newroute*_v6 the ip6i might be in
9383 * a separate mblk when we return here. In that case
9384 * we pullup everything to ensure that extension and transport
9385 * headers "stay" in the first mblk.
9387 ip6i
= (ip6i_t
*)ip6h
;
9388 ip6i_flags
= ip6i
->ip6i_flags
;
9390 ASSERT((mp
->b_wptr
- (uchar_t
*)ip6i
) == sizeof (ip6i_t
) ||
9391 ((mp
->b_wptr
- (uchar_t
*)ip6i
) >=
9392 sizeof (ip6i_t
) + IPV6_HDR_LEN
));
9394 if ((mp
->b_wptr
- (uchar_t
*)ip6i
) == sizeof (ip6i_t
)) {
9395 if (!pullupmsg(mp
, -1)) {
9396 ip1dbg(("ip_wput_v6: pullupmsg failed\n"));
9397 if (do_outrequests
) {
9399 ipIfStatsHCOutRequests
);
9401 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
9406 CONN_DEC_REF(connp
);
9409 ip6h
= (ip6_t
*)mp
->b_rptr
;
9410 v6dstp
= &ip6h
->ip6_dst
;
9411 ip6i
= (ip6i_t
*)ip6h
;
9413 ip6h
= (ip6_t
*)&ip6i
[1];
9416 * Advance rptr past the ip6i_t to get ready for
9417 * transmitting the packet. However, if the packet gets
9418 * passed to ip_newroute*_v6 then rptr is moved back so
9419 * that the ip6i_t header can be inspected when the
9420 * packet comes back here after passing through
9421 * ire_add_then_send.
9423 mp
->b_rptr
= (uchar_t
*)ip6h
;
9425 if (ip6i
->ip6i_flags
& IP6I_IFINDEX
) {
9426 ASSERT(ip6i
->ip6i_ifindex
!= 0);
9429 ill
= ill_lookup_on_ifindex(ip6i
->ip6i_ifindex
, 1,
9430 NULL
, NULL
, NULL
, NULL
, ipst
);
9432 if (do_outrequests
) {
9434 ipIfStatsHCOutRequests
);
9436 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
9437 ip1dbg(("ip_wput_v6: bad ifindex %d\n",
9438 ip6i
->ip6i_ifindex
));
9440 CONN_DEC_REF(connp
);
9444 mibptr
= ill
->ill_ip_mib
;
9446 * Preserve the index so that when we return from
9447 * IPSEC processing, we know where to send the packet.
9451 io
->ipsec_out_ill_index
= ip6i
->ip6i_ifindex
;
9454 if (ip6i
->ip6i_flags
& IP6I_VERIFY_SRC
) {
9455 cred_t
*cr
= msg_getcred(mp
, NULL
);
9457 ASSERT(!IN6_IS_ADDR_UNSPECIFIED(&ip6h
->ip6_src
));
9458 if (secpolicy_net_rawaccess(cr
) != 0) {
9460 * Use IPCL_ZONEID to honor SO_ALLZONES.
9462 ire
= ire_route_lookup_v6(&ip6h
->ip6_src
,
9463 0, 0, (IRE_LOCAL
|IRE_LOOPBACK
), NULL
,
9464 NULL
, connp
!= NULL
?
9465 IPCL_ZONEID(connp
) : zoneid
, NULL
,
9466 MATCH_IRE_TYPE
| MATCH_IRE_ZONEONLY
, ipst
);
9470 ipIfStatsHCOutRequests
);
9471 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
9472 ip1dbg(("ip_wput_v6: bad source "
9478 CONN_DEC_REF(connp
);
9483 /* No need to verify again when using ip_newroute */
9484 ip6i
->ip6i_flags
&= ~IP6I_VERIFY_SRC
;
9486 if (!(ip6i
->ip6i_flags
& IP6I_NEXTHOP
)) {
9488 * Make sure they match since ip_newroute*_v6 etc might
9489 * (unknown to them) inspect ip6i_nexthop when
9490 * they think they access ip6_dst.
9492 ip6i
->ip6i_nexthop
= ip6h
->ip6_dst
;
9494 if (ip6i
->ip6i_flags
& IP6I_NO_ULP_CKSUM
)
9496 if (ip6i
->ip6i_flags
& IP6I_RAW_CHECKSUM
)
9497 cksum_request
= ip6i
->ip6i_checksum_off
;
9498 if (ip6i
->ip6i_flags
& IP6I_UNSPEC_SRC
)
9501 if (do_outrequests
&& ill
!= NULL
) {
9502 BUMP_MIB(mibptr
, ipIfStatsHCOutRequests
);
9503 do_outrequests
= B_FALSE
;
9506 * Store ip6i_t info that we need after we come back
9507 * from IPSEC processing.
9511 io
->ipsec_out_unspec_src
= unspec_src
;
9514 if (connp
!= NULL
&& connp
->conn_dontroute
)
9517 if (IN6_IS_ADDR_MULTICAST(v6dstp
))
9520 /* 1. If an ip6i_t with IP6I_IFINDEX set then use that ill. */
9521 if (ip6i
!= NULL
&& (ip6i
->ip6i_flags
& IP6I_IFINDEX
)) {
9522 ASSERT(ill
!= NULL
);
9527 * 2. If q is an ill queue and there's a link-local destination
9528 * then use that ill.
9530 if (ill
!= NULL
&& IN6_IS_ADDR_LINKLOCAL(v6dstp
))
9533 /* 3. If IPV6_BOUND_IF has been set use that ill. */
9534 if (connp
!= NULL
&& connp
->conn_outgoing_ill
!= NULL
) {
9535 ill_t
*conn_outgoing_ill
;
9537 conn_outgoing_ill
= conn_get_held_ill(connp
,
9538 &connp
->conn_outgoing_ill
, &err
);
9539 if (err
== ILL_LOOKUP_FAILED
) {
9543 CONN_DEC_REF(connp
);
9549 ill
= conn_outgoing_ill
;
9550 mibptr
= ill
->ill_ip_mib
;
9555 * 4. For unicast: Just do an IRE lookup for the best match.
9556 * If we get here for a link-local address it is rather random
9557 * what interface we pick on a multihomed host.
9558 * *If* there is an IRE_CACHE (and the link-local address
9559 * isn't duplicated on multi links) this will find the IRE_CACHE.
9560 * Otherwise it will use one of the matching IRE_INTERFACE routes
9561 * for the link-local prefix. Hence, applications
9562 * *should* be encouraged to specify an outgoing interface when sending
9563 * to a link local address.
9565 if (connp
== NULL
|| (IP_FLOW_CONTROLLED_ULP(connp
->conn_ulp
) &&
9566 !connp
->conn_fully_bound
)) {
9568 * We cache IRE_CACHEs to avoid lookups. We don't do
9569 * this for the tcp global queue and listen end point
9570 * as it does not really have a real destination to
9573 ire
= ire_cache_lookup_v6(v6dstp
, zoneid
, msg_getlabel(mp
),
9577 * IRE_MARK_CONDEMNED is marked in ire_delete. We don't
9578 * grab a lock here to check for CONDEMNED as it is okay
9579 * to send a packet or two with the IRE_CACHE that is going
9582 mutex_enter(&connp
->conn_lock
);
9583 ire
= sctp_ire
!= NULL
? sctp_ire
: connp
->conn_ire_cache
;
9585 IN6_ARE_ADDR_EQUAL(&ire
->ire_addr_v6
, v6dstp
) &&
9586 !(ire
->ire_marks
& IRE_MARK_CONDEMNED
)) {
9589 mutex_exit(&connp
->conn_lock
);
9592 boolean_t cached
= B_FALSE
;
9594 connp
->conn_ire_cache
= NULL
;
9595 mutex_exit(&connp
->conn_lock
);
9596 /* Release the old ire */
9597 if (ire
!= NULL
&& sctp_ire
== NULL
)
9598 IRE_REFRELE_NOTR(ire
);
9600 ire
= ire_cache_lookup_v6(v6dstp
, zoneid
,
9601 msg_getlabel(mp
), ipst
);
9603 IRE_REFHOLD_NOTR(ire
);
9605 mutex_enter(&connp
->conn_lock
);
9606 if (CONN_CACHE_IRE(connp
) &&
9607 (connp
->conn_ire_cache
== NULL
)) {
9608 rw_enter(&ire
->ire_bucket
->irb_lock
,
9610 if (!(ire
->ire_marks
&
9611 IRE_MARK_CONDEMNED
)) {
9612 connp
->conn_ire_cache
= ire
;
9615 rw_exit(&ire
->ire_bucket
->irb_lock
);
9617 mutex_exit(&connp
->conn_lock
);
9620 * We can continue to use the ire but since it
9621 * was not cached, we should drop the extra
9625 IRE_REFRELE_NOTR(ire
);
9631 if (do_outrequests
) {
9632 /* Handle IRE_LOCAL's that might appear here */
9633 if (ire
->ire_type
== IRE_CACHE
) {
9634 mibptr
= ((ill_t
*)ire
->ire_stq
->q_ptr
)->
9637 mibptr
= ire
->ire_ipif
->ipif_ill
->ill_ip_mib
;
9639 BUMP_MIB(mibptr
, ipIfStatsHCOutRequests
);
9643 * Check if the ire has the RTF_MULTIRT flag, inherited
9644 * from an IRE_OFFSUBNET ire entry in ip_newroute().
9646 if (ire
->ire_flags
& RTF_MULTIRT
) {
9648 * Force hop limit of multirouted packets if required.
9649 * The hop limit of such packets is bounded by the
9650 * ip_multirt_ttl ndd variable.
9651 * NDP packets must have a hop limit of 255; don't
9652 * change the hop limit in that case.
9654 if ((ipst
->ips_ip_multirt_ttl
> 0) &&
9655 (ip6h
->ip6_hops
> ipst
->ips_ip_multirt_ttl
) &&
9656 (ip6h
->ip6_hops
!= IPV6_MAX_HOPS
)) {
9658 ip2dbg(("ip_wput_v6: forcing multirt "
9659 "hop limit to %d (was %d) ",
9660 ipst
->ips_ip_multirt_ttl
,
9662 pr_addr_dbg("v6dst %s\n", AF_INET6
,
9665 ip6h
->ip6_hops
= ipst
->ips_ip_multirt_ttl
;
9669 * We look at this point if there are pending
9670 * unresolved routes. ire_multirt_need_resolve_v6()
9671 * checks in O(n) that all IRE_OFFSUBNET ire
9672 * entries for the packet's destination and
9673 * flagged RTF_MULTIRT are currently resolved.
9674 * If some remain unresolved, we do a copy
9675 * of the current message. It will be used
9676 * to initiate additional route resolutions.
9678 multirt_need_resolve
=
9679 ire_multirt_need_resolve_v6(&ire
->ire_addr_v6
,
9680 msg_getlabel(first_mp
), ipst
);
9681 ip2dbg(("ip_wput_v6: ire %p, "
9682 "multirt_need_resolve %d, first_mp %p\n",
9683 (void *)ire
, multirt_need_resolve
,
9685 if (multirt_need_resolve
) {
9686 copy_mp
= copymsg(first_mp
);
9687 if (copy_mp
!= NULL
) {
9688 MULTIRT_DEBUG_TAG(copy_mp
);
9692 ip_wput_ire_v6(q
, first_mp
, ire
, unspec_src
, cksum_request
,
9693 connp
, caller
, ip6i_flags
, zoneid
);
9695 CONN_DEC_REF(connp
);
9701 * Try to resolve another multiroute if
9702 * ire_multirt_need_resolve_v6() deemed it necessary.
9703 * copy_mp will be consumed (sent or freed) by
9706 if (copy_mp
!= NULL
) {
9708 ip6h
= (ip6_t
*)copy_mp
->b_cont
->b_rptr
;
9710 ip6h
= (ip6_t
*)copy_mp
->b_rptr
;
9712 ip_newroute_v6(q
, copy_mp
, &ip6h
->ip6_dst
,
9713 &ip6h
->ip6_src
, NULL
, zoneid
, ipst
);
9721 * No full IRE for this destination. Send it to
9722 * ip_newroute_v6 to see if anything else matches.
9723 * Mark this packet as having originated on this
9725 * Update rptr if there was an ip6i_t header.
9730 mp
->b_rptr
-= sizeof (ip6i_t
);
9735 * Add ip6i_t header to carry unspec_src
9736 * until the packet comes back in ip_wput_v6.
9738 mp
= ip_add_info_v6(mp
, NULL
, v6dstp
);
9742 ipIfStatsHCOutRequests
);
9743 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
9749 CONN_DEC_REF(connp
);
9752 ip6i
= (ip6i_t
*)mp
->b_rptr
;
9755 ASSERT(first_mp
!= mp
);
9756 first_mp
->b_cont
= mp
;
9761 if ((mp
->b_wptr
- (uchar_t
*)ip6i
) ==
9764 * ndp_resolver called from ip_newroute_v6
9765 * expects pulled up message.
9767 if (!pullupmsg(mp
, -1)) {
9768 ip1dbg(("ip_wput_v6: pullupmsg"
9770 if (do_outrequests
) {
9772 ipIfStatsHCOutRequests
);
9774 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
9779 CONN_DEC_REF(connp
);
9782 ip6i
= (ip6i_t
*)mp
->b_rptr
;
9784 ip6h
= (ip6_t
*)&ip6i
[1];
9785 v6dstp
= &ip6h
->ip6_dst
;
9787 ip6i
->ip6i_flags
|= IP6I_UNSPEC_SRC
;
9790 io
->ipsec_out_unspec_src
= unspec_src
;
9794 BUMP_MIB(mibptr
, ipIfStatsHCOutRequests
);
9796 CONN_DEC_REF(connp
);
9797 ip_newroute_v6(q
, first_mp
, v6dstp
, &ip6h
->ip6_src
, NULL
, zoneid
, ipst
);
9804 * Handle multicast packets with or without an conn.
9805 * Assumes that the transports set ip6_hops taking
9806 * IPV6_MULTICAST_HOPS (and the other ways to set the hoplimit)
9810 ip2dbg(("ip_wput_v6: multicast\n"));
9813 * Hold the conn_lock till we refhold the ill of interest that is
9814 * pointed to from the conn. Since we cannot do an ill/ipif_refrele
9815 * while holding any locks, postpone the refrele until after the
9816 * conn_lock is dropped.
9818 if (connp
!= NULL
) {
9819 mutex_enter(&connp
->conn_lock
);
9820 conn_lock_held
= B_TRUE
;
9822 conn_lock_held
= B_FALSE
;
9824 if (ip6i
!= NULL
&& (ip6i
->ip6i_flags
& IP6I_IFINDEX
)) {
9825 /* 1. If an ip6i_t with IP6I_IFINDEX set then use that ill. */
9826 ASSERT(ill
!= NULL
);
9827 } else if (ill
!= NULL
) {
9829 * 2. If q is an ill queue and (link local or multicast
9830 * destination) then use that ill.
9831 * We don't need the ipif initialization here.
9832 * This useless assert below is just to prevent lint from
9833 * reporting a null body if statement.
9835 ASSERT(ill
!= NULL
);
9836 } else if (connp
!= NULL
) {
9838 * 3. If IPV6_BOUND_IF has been set use that ill.
9840 * 4. For multicast: if IPV6_MULTICAST_IF has been set use it.
9841 * Otherwise look for the best IRE match for the unspecified
9842 * group to determine the ill.
9844 * conn_multicast_ill is used for only IPv6 packets.
9845 * conn_multicast_ipif is used for only IPv4 packets.
9846 * Thus a PF_INET6 socket send both IPv4 and IPv6
9847 * multicast packets using different IP*_MULTICAST_IF
9850 if (connp
->conn_outgoing_ill
!= NULL
) {
9851 err
= ill_check_and_refhold(connp
->conn_outgoing_ill
);
9852 if (err
== ILL_LOOKUP_FAILED
) {
9853 ip1dbg(("ip_output_v6: multicast"
9854 " conn_outgoing_ill no ipif\n"));
9856 ASSERT(saved_ill
== NULL
);
9858 mutex_exit(&connp
->conn_lock
);
9863 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
9865 CONN_DEC_REF(connp
);
9868 ill
= connp
->conn_outgoing_ill
;
9869 } else if (connp
->conn_multicast_ill
!= NULL
) {
9870 err
= ill_check_and_refhold(connp
->conn_multicast_ill
);
9871 if (err
== ILL_LOOKUP_FAILED
) {
9872 ip1dbg(("ip_output_v6: multicast"
9873 " conn_multicast_ill no ipif\n"));
9874 goto multicast_discard
;
9876 ill
= connp
->conn_multicast_ill
;
9878 mutex_exit(&connp
->conn_lock
);
9879 conn_lock_held
= B_FALSE
;
9880 ipif
= ipif_lookup_group_v6(v6dstp
, zoneid
, ipst
);
9882 ip1dbg(("ip_output_v6: multicast no ipif\n"));
9883 goto multicast_discard
;
9886 * We have a ref to this ipif, so we can safely
9889 ill
= ipif
->ipif_ill
;
9890 mutex_enter(&ill
->ill_lock
);
9891 if (!ILL_CAN_LOOKUP(ill
)) {
9892 mutex_exit(&ill
->ill_lock
);
9895 ip1dbg(("ip_output_v6: multicast no ipif\n"));
9896 goto multicast_discard
;
9898 ill_refhold_locked(ill
);
9899 mutex_exit(&ill
->ill_lock
);
9902 * Save binding until IPV6_MULTICAST_IF
9905 mutex_enter(&connp
->conn_lock
);
9906 connp
->conn_multicast_ill
= ill
;
9907 mutex_exit(&connp
->conn_lock
);
9911 mutex_exit(&connp
->conn_lock
);
9913 if (saved_ill
!= NULL
)
9914 ill_refrele(saved_ill
);
9916 ASSERT(ill
!= NULL
);
9918 * For multicast loopback interfaces replace the multicast address
9919 * with a unicast address for the ire lookup.
9921 if (IS_LOOPBACK(ill
))
9922 v6dstp
= &ill
->ill_ipif
->ipif_v6lcl_addr
;
9924 mibptr
= ill
->ill_ip_mib
;
9925 if (do_outrequests
) {
9926 BUMP_MIB(mibptr
, ipIfStatsHCOutRequests
);
9927 do_outrequests
= B_FALSE
;
9929 BUMP_MIB(mibptr
, ipIfStatsHCOutMcastPkts
);
9930 UPDATE_MIB(mibptr
, ipIfStatsHCOutMcastOctets
,
9931 ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
);
9934 * As we may lose the conn by the time we reach ip_wput_ire_v6
9935 * we copy conn_multicast_loop and conn_dontroute on to an
9936 * ipsec_out. In case if this datagram goes out secure,
9937 * we need the ill_index also. Copy that also into the
9941 io
= (ipsec_out_t
*)first_mp
->b_rptr
;
9942 ASSERT(first_mp
->b_datap
->db_type
== M_CTL
);
9943 ASSERT(io
->ipsec_out_type
== IPSEC_OUT
);
9945 ASSERT(mp
== first_mp
);
9946 if ((first_mp
= ipsec_alloc_ipsec_out(ipst
->ips_netstack
)) ==
9948 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
9953 CONN_DEC_REF(connp
);
9956 io
= (ipsec_out_t
*)first_mp
->b_rptr
;
9957 /* This is not a secure packet */
9958 io
->ipsec_out_secure
= B_FALSE
;
9959 io
->ipsec_out_use_global_policy
= B_TRUE
;
9960 io
->ipsec_out_zoneid
=
9961 (zoneid
!= ALL_ZONES
? zoneid
: GLOBAL_ZONEID
);
9962 first_mp
->b_cont
= mp
;
9963 mctl_present
= B_TRUE
;
9965 io
->ipsec_out_ill_index
= ill
->ill_phyint
->phyint_ifindex
;
9966 io
->ipsec_out_unspec_src
= unspec_src
;
9968 io
->ipsec_out_dontroute
= connp
->conn_dontroute
;
9971 ASSERT(ill
!= NULL
);
9972 ASSERT(mibptr
== ill
->ill_ip_mib
);
9974 if (do_outrequests
) {
9975 BUMP_MIB(mibptr
, ipIfStatsHCOutRequests
);
9976 do_outrequests
= B_FALSE
;
9980 * Because nce_xmit() calls ip_output_v6() and NCEs are always tied to
9981 * an underlying interface, IS_UNDER_IPMP() may be true even when
9982 * building IREs that will be used for data traffic. As such, use the
9983 * packet's source address to determine whether the traffic is test
9984 * traffic, and set MATCH_IRE_MARK_TESTHIDDEN if so.
9986 * Separately, we also need to mark probe packets so that ND can
9987 * process them specially; see the comments in nce_queue_mp_common().
9989 if (IS_UNDER_IPMP(ill
) && !IN6_IS_ADDR_UNSPECIFIED(&ip6h
->ip6_src
) &&
9990 ipif_lookup_testaddr_v6(ill
, &ip6h
->ip6_src
, NULL
)) {
9992 if ((mp
= ip_add_info_v6(mp
, NULL
, v6dstp
)) == NULL
) {
9999 first_mp
->b_cont
= mp
;
10003 /* ndp_resolver() expects a pulled-up message */
10004 if (MBLKL(mp
) == sizeof (ip6i_t
) &&
10005 pullupmsg(mp
, -1) == 0) {
10006 ip1dbg(("ip_output_v6: pullupmsg failed\n"));
10007 discard
: BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
10010 CONN_DEC_REF(connp
);
10013 ip6i
= (ip6i_t
*)mp
->b_rptr
;
10014 ip6h
= (ip6_t
*)&ip6i
[1];
10015 v6dstp
= &ip6h
->ip6_dst
;
10016 mp
->b_rptr
= (uchar_t
*)ip6h
; /* rewound below */
10018 ip6i
->ip6i_flags
|= IP6I_IPMP_PROBE
;
10019 match_flags
|= MATCH_IRE_MARK_TESTHIDDEN
;
10023 io
->ipsec_out_ill_index
= ill
->ill_phyint
->phyint_ifindex
;
10026 * When a specific ill is specified (using IPV6_PKTINFO,
10027 * IPV6_MULTICAST_IF, or IPV6_BOUND_IF) we will only match
10028 * on routing entries (ftable and ctable) that have a matching
10029 * ire->ire_ipif->ipif_ill. Thus this can only be used
10030 * for destinations that are on-link for the specific ill
10031 * and that can appear on multiple links. Thus it is useful
10032 * for multicast destinations, link-local destinations, and
10033 * at some point perhaps for site-local destinations (if the
10034 * node sits at a site boundary).
10035 * We create the cache entries in the regular ctable since
10036 * it can not "confuse" things for other destinations.
10039 * NOTE : conn_ire_cache is not used for caching ire_ctable_lookups.
10040 * It is used only when ire_cache_lookup is used above.
10042 ire
= ire_ctable_lookup_v6(v6dstp
, 0, 0, ill
->ill_ipif
,
10043 zoneid
, msg_getlabel(mp
), match_flags
, ipst
);
10046 * Check if the ire has the RTF_MULTIRT flag, inherited
10047 * from an IRE_OFFSUBNET ire entry in ip_newroute().
10049 if (ire
->ire_flags
& RTF_MULTIRT
) {
10051 * Force hop limit of multirouted packets if required.
10052 * The hop limit of such packets is bounded by the
10053 * ip_multirt_ttl ndd variable.
10054 * NDP packets must have a hop limit of 255; don't
10055 * change the hop limit in that case.
10057 if ((ipst
->ips_ip_multirt_ttl
> 0) &&
10058 (ip6h
->ip6_hops
> ipst
->ips_ip_multirt_ttl
) &&
10059 (ip6h
->ip6_hops
!= IPV6_MAX_HOPS
)) {
10060 if (ip_debug
> 3) {
10061 ip2dbg(("ip_wput_v6: forcing multirt "
10062 "hop limit to %d (was %d) ",
10063 ipst
->ips_ip_multirt_ttl
,
10065 pr_addr_dbg("v6dst %s\n", AF_INET6
,
10066 &ire
->ire_addr_v6
);
10068 ip6h
->ip6_hops
= ipst
->ips_ip_multirt_ttl
;
10072 * We look at this point if there are pending
10073 * unresolved routes. ire_multirt_need_resolve_v6()
10074 * checks in O(n) that all IRE_OFFSUBNET ire
10075 * entries for the packet's destination and
10076 * flagged RTF_MULTIRT are currently resolved.
10077 * If some remain unresolved, we make a copy
10078 * of the current message. It will be used
10079 * to initiate additional route resolutions.
10081 multirt_need_resolve
=
10082 ire_multirt_need_resolve_v6(&ire
->ire_addr_v6
,
10083 msg_getlabel(first_mp
), ipst
);
10084 ip2dbg(("ip_wput_v6[send_from_ill]: ire %p, "
10085 "multirt_need_resolve %d, first_mp %p\n",
10086 (void *)ire
, multirt_need_resolve
,
10087 (void *)first_mp
));
10088 if (multirt_need_resolve
) {
10089 copy_mp
= copymsg(first_mp
);
10090 if (copy_mp
!= NULL
) {
10091 MULTIRT_DEBUG_TAG(copy_mp
);
10096 ip1dbg(("ip_wput_v6: send on %s, ire = %p, ill index = %d\n",
10097 ill
->ill_name
, (void *)ire
,
10098 ill
->ill_phyint
->phyint_ifindex
));
10099 ip_wput_ire_v6(q
, first_mp
, ire
, unspec_src
, cksum_request
,
10100 connp
, caller
, ip6i_flags
, zoneid
);
10103 CONN_DEC_REF(connp
);
10108 * Try to resolve another multiroute if
10109 * ire_multirt_need_resolve_v6() deemed it necessary.
10110 * copy_mp will be consumed (sent or freed) by
10111 * ip_newroute_[ipif_]v6().
10113 if (copy_mp
!= NULL
) {
10114 if (mctl_present
) {
10115 ip6h
= (ip6_t
*)copy_mp
->b_cont
->b_rptr
;
10117 ip6h
= (ip6_t
*)copy_mp
->b_rptr
;
10119 if (IN6_IS_ADDR_MULTICAST(&ip6h
->ip6_dst
)) {
10120 ipif
= ipif_lookup_group_v6(&ip6h
->ip6_dst
,
10122 if (ipif
== NULL
) {
10123 ip1dbg(("ip_wput_v6: No ipif for "
10125 MULTIRT_DEBUG_UNTAG(copy_mp
);
10129 ip_newroute_ipif_v6(q
, copy_mp
, ipif
,
10130 &ip6h
->ip6_dst
, &ip6h
->ip6_src
, unspec_src
,
10132 ipif_refrele(ipif
);
10134 ip_newroute_v6(q
, copy_mp
, &ip6h
->ip6_dst
,
10135 &ip6h
->ip6_src
, ill
, zoneid
, ipst
);
10142 CONN_DEC_REF(connp
);
10146 /* Update rptr if there was an ip6i_t header. */
10148 mp
->b_rptr
-= sizeof (ip6i_t
);
10150 if (ip6i
== NULL
) {
10152 * Add ip6i_t header to carry unspec_src
10153 * until the packet comes back in ip_wput_v6.
10155 if (mctl_present
) {
10157 ip_add_info_v6(mp
, NULL
, v6dstp
);
10158 mp
= first_mp
->b_cont
;
10162 first_mp
= mp
= ip_add_info_v6(mp
, NULL
,
10166 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
10170 ip6i
= (ip6i_t
*)mp
->b_rptr
;
10171 if ((mp
->b_wptr
- (uchar_t
*)ip6i
) ==
10174 * ndp_resolver called from ip_newroute_v6
10175 * expects a pulled up message.
10177 if (!pullupmsg(mp
, -1)) {
10178 ip1dbg(("ip_wput_v6: pullupmsg"
10180 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
10184 ip6i
= (ip6i_t
*)mp
->b_rptr
;
10186 ip6h
= (ip6_t
*)&ip6i
[1];
10187 v6dstp
= &ip6h
->ip6_dst
;
10189 ip6i
->ip6i_flags
|= IP6I_UNSPEC_SRC
;
10190 if (mctl_present
) {
10191 ASSERT(io
!= NULL
);
10192 io
->ipsec_out_unspec_src
= unspec_src
;
10195 if (IN6_IS_ADDR_MULTICAST(v6dstp
)) {
10196 ip_newroute_ipif_v6(q
, first_mp
, ill
->ill_ipif
, v6dstp
,
10197 &ip6h
->ip6_src
, unspec_src
, zoneid
);
10199 ip_newroute_v6(q
, first_mp
, v6dstp
, &ip6h
->ip6_src
, ill
,
10206 /* FIXME?: assume the caller calls the right version of ip_output? */
10207 if (q
->q_next
== NULL
) {
10208 connp
= Q_TO_CONN(q
);
10211 * We can change conn_send for all types of conn, even
10212 * though only TCP uses it right now.
10213 * FIXME: sctp could use conn_send but doesn't currently.
10215 ip_setpktversion(connp
, B_FALSE
, B_TRUE
, ipst
);
10217 BUMP_MIB(mibptr
, ipIfStatsOutWrongIPVersion
);
10218 (void) ip_output(arg
, first_mp
, arg2
, caller
);
10224 * If this is a conn_t queue, then we pass in the conn. This includes the
10226 * Otherwise, this is a message for an ill_t queue,
10227 * in which case we use the global zoneid since those are all part of
10231 ip_wput_v6(queue_t
*q
, mblk_t
*mp
)
10234 ip_output_v6(Q_TO_CONN(q
), mp
, q
, IP_WPUT
);
10236 ip_output_v6(GLOBAL_ZONEID
, mp
, q
, IP_WPUT
);
10240 * NULL send-to queue - packet is to be delivered locally.
10243 ip_wput_local_v6(queue_t
*q
, ill_t
*ill
, ip6_t
*ip6h
, mblk_t
*first_mp
,
10244 ire_t
*ire
, int fanout_flags
, zoneid_t zoneid
)
10247 mblk_t
*mp
= first_mp
, *first_mp1
;
10248 boolean_t mctl_present
;
10250 uint16_t hdr_length
;
10252 mib2_ipIfStatsEntry_t
*mibptr
;
10254 uint_t nexthdr_offset
;
10255 ip_stack_t
*ipst
= ill
->ill_ipst
;
10257 if (DB_TYPE(mp
) == M_CTL
) {
10258 io
= (ipsec_out_t
*)mp
->b_rptr
;
10259 if (!io
->ipsec_out_secure
) {
10263 mctl_present
= B_FALSE
;
10265 mctl_present
= B_TRUE
;
10266 mp
= first_mp
->b_cont
;
10267 ipsec_out_to_in(first_mp
);
10270 mctl_present
= B_FALSE
;
10274 * Remove reachability confirmation bit from version field
10275 * before passing the packet on to any firewall hooks or
10276 * looping back the packet.
10278 if (ip6h
->ip6_vcf
& IP_FORWARD_PROG
)
10279 ip6h
->ip6_vcf
&= ~IP_FORWARD_PROG
;
10281 DTRACE_PROBE4(ip6__loopback__in__start
,
10282 ill_t
*, ill
, ill_t
*, NULL
,
10283 ip6_t
*, ip6h
, mblk_t
*, first_mp
);
10285 FW_HOOKS6(ipst
->ips_ip6_loopback_in_event
,
10286 ipst
->ips_ipv6firewall_loopback_in
,
10287 ill
, NULL
, ip6h
, first_mp
, mp
, 0, ipst
);
10289 DTRACE_PROBE1(ip6__loopback__in__end
, mblk_t
*, first_mp
);
10291 if (first_mp
== NULL
)
10294 if (ipst
->ips_ipobs_enabled
) {
10295 zoneid_t szone
, dzone
, lookup_zoneid
= ALL_ZONES
;
10296 zoneid_t stackzoneid
= netstackid_to_zoneid(
10297 ipst
->ips_netstack
->netstack_stackid
);
10299 szone
= (stackzoneid
== GLOBAL_ZONEID
) ? zoneid
: stackzoneid
;
10301 * ::1 is special, as we cannot lookup its zoneid by
10302 * address. For this case, restrict the lookup to the
10305 if (IN6_IS_ADDR_LOOPBACK(&ip6h
->ip6_dst
))
10306 lookup_zoneid
= zoneid
;
10307 dzone
= ip_get_zoneid_v6(&ip6h
->ip6_dst
, mp
, ill
, ipst
,
10309 ipobs_hook(mp
, IPOBS_HOOK_LOCAL
, szone
, dzone
, ill
,
10310 IPV6_VERSION
, 0, ipst
);
10313 DTRACE_IP7(receive
, mblk_t
*, first_mp
, conn_t
*, NULL
, void_ip_t
*,
10314 ip6h
, __dtrace_ipsr_ill_t
*, ill
, ipha_t
*, NULL
, ip6_t
*, ip6h
,
10317 nexthdr
= ip6h
->ip6_nxt
;
10318 mibptr
= ill
->ill_ip_mib
;
10324 case IPPROTO_ICMPV6
:
10326 hdr_length
= IPV6_HDR_LEN
;
10327 nexthdr_offset
= (uint_t
)((uchar_t
*)&ip6h
->ip6_nxt
-
10333 if (!ip_hdr_length_nexthdr_v6(mp
, ip6h
,
10334 &hdr_length
, &nexthdrp
)) {
10335 /* Malformed packet */
10336 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
10340 nexthdr
= *nexthdrp
;
10341 nexthdr_offset
= nexthdrp
- (uint8_t *)ip6h
;
10346 UPDATE_OB_PKT_COUNT(ire
);
10347 ire
->ire_last_used_time
= lbolt
;
10351 if (DB_TYPE(mp
) == M_DATA
) {
10353 * M_DATA mblk, so init mblk (chain) for
10359 mp1
->b_datap
->db_struioflag
= 0;
10360 } while ((mp1
= mp1
->b_cont
) != NULL
);
10362 ports
= *(uint32_t *)(mp
->b_rptr
+ hdr_length
+
10364 ip_fanout_tcp_v6(q
, first_mp
, ip6h
, ill
, ill
,
10365 fanout_flags
|IP_FF_SEND_ICMP
|IP_FF_SYN_ADDIRE
|
10366 IP_FF_IPINFO
|IP6_NO_IPPOLICY
|IP_FF_LOOPBACK
,
10367 hdr_length
, mctl_present
, ire
->ire_zoneid
);
10371 ports
= *(uint32_t *)(mp
->b_rptr
+ hdr_length
+
10373 ip_fanout_udp_v6(q
, first_mp
, ip6h
, ports
, ill
, ill
,
10374 fanout_flags
|IP_FF_SEND_ICMP
|IP_FF_IPINFO
|
10375 IP6_NO_IPPOLICY
, mctl_present
, ire
->ire_zoneid
);
10380 ports
= *(uint32_t *)(mp
->b_rptr
+ hdr_length
);
10381 ip_fanout_sctp(first_mp
, ill
, (ipha_t
*)ip6h
, ports
,
10382 fanout_flags
|IP_FF_SEND_ICMP
|IP_FF_IPINFO
,
10383 mctl_present
, IP6_NO_IPPOLICY
, ire
->ire_zoneid
);
10386 case IPPROTO_ICMPV6
: {
10389 /* check for full IPv6+ICMPv6 header */
10390 if ((mp
->b_wptr
- mp
->b_rptr
) <
10391 (hdr_length
+ ICMP6_MINLEN
)) {
10392 if (!pullupmsg(mp
, hdr_length
+ ICMP6_MINLEN
)) {
10393 ip1dbg(("ip_wput_v6: ICMP hdr pullupmsg"
10395 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
10399 ip6h
= (ip6_t
*)mp
->b_rptr
;
10401 icmp6
= (icmp6_t
*)((uchar_t
*)ip6h
+ hdr_length
);
10403 /* Update output mib stats */
10404 icmp_update_out_mib_v6(ill
, icmp6
);
10406 /* Check variable for testing applications */
10407 if (ipst
->ips_ipv6_drop_inbound_icmpv6
) {
10412 * Assume that there is always at least one conn for
10413 * ICMPv6 (in.ndpd) i.e. don't optimize the case
10414 * where there is no conn.
10416 if (IN6_IS_ADDR_MULTICAST(&ip6h
->ip6_dst
) &&
10417 !IS_LOOPBACK(ill
)) {
10421 * In the multicast case, applications may have
10422 * joined the group from different zones, so we
10423 * need to deliver the packet to each of them.
10424 * Loop through the multicast memberships
10425 * structures (ilm) on the receive ill and send
10426 * a copy of the packet up each matching one.
10427 * However, we don't do this for multicasts sent
10428 * on the loopback interface (PHYI_LOOPBACK flag
10429 * set) as they must stay in the sender's zone.
10431 ilm
= ilm_walker_start(&ilw
, ill
);
10432 for (; ilm
!= NULL
;
10433 ilm
= ilm_walker_step(&ilw
, ilm
)) {
10434 if (!IN6_ARE_ADDR_EQUAL(
10435 &ilm
->ilm_v6addr
, &ip6h
->ip6_dst
))
10437 if ((fanout_flags
&
10438 IP_FF_NO_MCAST_LOOP
) &&
10439 ilm
->ilm_zoneid
== ire
->ire_zoneid
)
10441 if (!ipif_lookup_zoneid(
10442 ilw
.ilw_walk_ill
, ilm
->ilm_zoneid
,
10446 first_mp1
= ip_copymsg(first_mp
);
10447 if (first_mp1
== NULL
)
10449 icmp_inbound_v6(q
, first_mp1
,
10450 ilw
.ilw_walk_ill
, ill
, hdr_length
,
10451 mctl_present
, IP6_NO_IPPOLICY
,
10452 ilm
->ilm_zoneid
, NULL
);
10454 ilm_walker_finish(&ilw
);
10456 first_mp1
= ip_copymsg(first_mp
);
10457 if (first_mp1
!= NULL
)
10458 icmp_inbound_v6(q
, first_mp1
, ill
, ill
,
10459 hdr_length
, mctl_present
,
10460 IP6_NO_IPPOLICY
, ire
->ire_zoneid
,
10467 * Handle protocols with which IPv6 is less intimate.
10469 fanout_flags
|= IP_FF_RAWIP
|IP_FF_IPINFO
;
10472 * Enable sending ICMP for "Unknown" nexthdr
10473 * case. i.e. where we did not FALLTHRU from
10474 * IPPROTO_ICMPV6 processing case above.
10476 if (nexthdr
!= IPPROTO_ICMPV6
)
10477 fanout_flags
|= IP_FF_SEND_ICMP
;
10479 * Note: There can be more than one stream bound
10480 * to a particular protocol. When this is the case,
10481 * each one gets a copy of any incoming packets.
10483 ip_fanout_proto_v6(q
, first_mp
, ip6h
, ill
, ill
, nexthdr
,
10484 nexthdr_offset
, fanout_flags
|IP6_NO_IPPOLICY
,
10485 mctl_present
, ire
->ire_zoneid
);
10492 * Send packet using IRE.
10493 * Checksumming is controlled by cksum_request:
10494 * -1 => normal i.e. TCP/UDP/SCTP/ICMPv6 are checksummed and nothing else.
10495 * 1 => Skip TCP/UDP/SCTP checksum
10496 * Otherwise => checksum_request contains insert offset for checksum
10498 * Assumes that the following set of headers appear in the first
10501 * Any extension headers
10502 * TCP/UDP/SCTP header (if present)
10503 * The routine can handle an ICMPv6 header that is not in the first mblk.
10505 * NOTE : This function does not ire_refrele the ire passed in as the
10506 * argument unlike ip_wput_ire where the REFRELE is done.
10507 * Refer to ip_wput_ire for more on this.
10510 ip_wput_ire_v6(queue_t
*q
, mblk_t
*mp
, ire_t
*ire
, int unspec_src
,
10511 int cksum_request
, conn_t
*connp
, int caller
, int flags
, zoneid_t zoneid
)
10515 uint16_t hdr_length
;
10516 uint_t reachable
= 0x0;
10518 mib2_ipIfStatsEntry_t
*mibptr
;
10520 boolean_t mctl_present
;
10522 boolean_t conn_dontroute
; /* conn value for multicast */
10523 boolean_t conn_multicast_loop
; /* conn value for multicast */
10524 boolean_t multicast_forward
; /* Should we forward ? */
10526 ip_stack_t
*ipst
= ire
->ire_ipst
;
10527 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
10529 ill
= ire_to_ill(ire
);
10531 multicast_forward
= B_FALSE
;
10533 if (mp
->b_datap
->db_type
!= M_CTL
) {
10534 ip6h
= (ip6_t
*)first_mp
->b_rptr
;
10536 io
= (ipsec_out_t
*)first_mp
->b_rptr
;
10537 ASSERT(io
->ipsec_out_type
== IPSEC_OUT
);
10539 * Grab the zone id now because the M_CTL can be discarded by
10540 * ip_wput_ire_parse_ipsec_out() below.
10542 ASSERT(zoneid
== io
->ipsec_out_zoneid
);
10543 ASSERT(zoneid
!= ALL_ZONES
);
10544 ip6h
= (ip6_t
*)first_mp
->b_cont
->b_rptr
;
10546 * For the multicast case, ipsec_out carries conn_dontroute and
10547 * conn_multicast_loop as conn may not be available here. We
10548 * need this for multicast loopback and forwarding which is done
10549 * later in the code.
10551 if (IN6_IS_ADDR_MULTICAST(&ip6h
->ip6_dst
)) {
10552 conn_dontroute
= io
->ipsec_out_dontroute
;
10553 conn_multicast_loop
= io
->ipsec_out_multicast_loop
;
10555 * If conn_dontroute is not set or conn_multicast_loop
10556 * is set, we need to do forwarding/loopback. For
10557 * datagrams from ip_wput_multicast, conn_dontroute is
10558 * set to B_TRUE and conn_multicast_loop is set to
10559 * B_FALSE so that we neither do forwarding nor
10562 if (!conn_dontroute
|| conn_multicast_loop
)
10563 multicast_forward
= B_TRUE
;
10568 * If the sender didn't supply the hop limit and there is a default
10569 * unicast hop limit associated with the output interface, we use
10570 * that if the packet is unicast. Interface specific unicast hop
10571 * limits as set via the SIOCSLIFLNKINFO ioctl.
10573 if (ill
->ill_max_hops
!= 0 && !(flags
& IP6I_HOPLIMIT
) &&
10574 !(IN6_IS_ADDR_MULTICAST(&ip6h
->ip6_dst
))) {
10575 ip6h
->ip6_hops
= ill
->ill_max_hops
;
10578 if (ire
->ire_type
== IRE_LOCAL
&& ire
->ire_zoneid
!= zoneid
&&
10579 ire
->ire_zoneid
!= ALL_ZONES
) {
10581 * When a zone sends a packet to another zone, we try to deliver
10582 * the packet under the same conditions as if the destination
10583 * was a real node on the network. To do so, we look for a
10584 * matching route in the forwarding table.
10585 * RTF_REJECT and RTF_BLACKHOLE are handled just like
10586 * ip_newroute_v6() does.
10587 * Note that IRE_LOCAL are special, since they are used
10588 * when the zoneid doesn't match in some cases. This means that
10589 * we need to handle ipha_src differently since ire_src_addr
10590 * belongs to the receiving zone instead of the sending zone.
10591 * When ip_restrict_interzone_loopback is set, then
10592 * ire_cache_lookup_v6() ensures that IRE_LOCAL are only used
10593 * for loopback between zones when the logical "Ethernet" would
10594 * have looped them back.
10598 src_ire
= ire_ftable_lookup_v6(&ip6h
->ip6_dst
, 0, 0, 0,
10599 NULL
, NULL
, zoneid
, 0, NULL
, (MATCH_IRE_RECURSIVE
|
10600 MATCH_IRE_DEFAULT
| MATCH_IRE_RJ_BHOLE
), ipst
);
10601 if (src_ire
!= NULL
&&
10602 !(src_ire
->ire_flags
& (RTF_REJECT
| RTF_BLACKHOLE
)) &&
10603 (!ipst
->ips_ip_restrict_interzone_loopback
||
10604 ire_local_same_lan(ire
, src_ire
))) {
10605 if (IN6_IS_ADDR_UNSPECIFIED(&ip6h
->ip6_src
) &&
10607 ip6h
->ip6_src
= src_ire
->ire_src_addr_v6
;
10609 ire_refrele(src_ire
);
10611 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutNoRoutes
);
10612 if (src_ire
!= NULL
) {
10613 if (src_ire
->ire_flags
& RTF_BLACKHOLE
) {
10614 ire_refrele(src_ire
);
10618 ire_refrele(src_ire
);
10620 if (ip_hdr_complete_v6(ip6h
, zoneid
, ipst
)) {
10625 icmp_unreachable_v6(q
, first_mp
,
10626 ICMP6_DST_UNREACH_NOROUTE
, B_FALSE
, B_FALSE
,
10632 if (mp
->b_datap
->db_type
== M_CTL
||
10633 ipss
->ipsec_outbound_v6_policy_present
) {
10634 mp
= ip_wput_ire_parse_ipsec_out(first_mp
, NULL
, ip6h
, ire
,
10635 connp
, unspec_src
, zoneid
);
10642 if (mp
->b_datap
->db_type
== M_CTL
) {
10643 io
= (ipsec_out_t
*)mp
->b_rptr
;
10644 ASSERT(io
->ipsec_out_type
== IPSEC_OUT
);
10646 mctl_present
= B_TRUE
;
10648 mctl_present
= B_FALSE
;
10651 ip6h
= (ip6_t
*)mp
->b_rptr
;
10652 nexthdr
= ip6h
->ip6_nxt
;
10653 mibptr
= ill
->ill_ip_mib
;
10655 if (IN6_IS_ADDR_UNSPECIFIED(&ip6h
->ip6_src
) && !unspec_src
) {
10659 * Select the source address using ipif_select_source_v6.
10661 ipif
= ipif_select_source_v6(ill
, &ip6h
->ip6_dst
, B_FALSE
,
10662 IPV6_PREFER_SRC_DEFAULT
, zoneid
);
10663 if (ipif
== NULL
) {
10664 if (ip_debug
> 2) {
10666 pr_addr_dbg("ip_wput_ire_v6: no src for "
10667 "dst %s\n", AF_INET6
, &ip6h
->ip6_dst
);
10668 printf("through interface %s\n", ill
->ill_name
);
10673 ip6h
->ip6_src
= ipif
->ipif_v6src_addr
;
10674 ipif_refrele(ipif
);
10676 if (IN6_IS_ADDR_MULTICAST(&ip6h
->ip6_dst
)) {
10677 if ((connp
!= NULL
&& connp
->conn_multicast_loop
) ||
10678 !IS_LOOPBACK(ill
)) {
10679 if (ilm_lookup_ill_v6(ill
, &ip6h
->ip6_dst
, B_FALSE
,
10680 ALL_ZONES
) != NULL
) {
10682 int fanout_flags
= 0;
10684 if (connp
!= NULL
&&
10685 !connp
->conn_multicast_loop
) {
10686 fanout_flags
|= IP_FF_NO_MCAST_LOOP
;
10688 ip1dbg(("ip_wput_ire_v6: "
10689 "Loopback multicast\n"));
10690 nmp
= ip_copymsg(first_mp
);
10695 if (mctl_present
) {
10697 nmp
->b_cont
->b_rptr
;
10698 mp_ip6h
= nmp
->b_cont
;
10700 nip6h
= (ip6_t
*)nmp
->b_rptr
;
10705 ip6__loopback__out__start
,
10712 ipst
->ips_ip6_loopback_out_event
,
10713 ipst
->ips_ipv6firewall_loopback_out
,
10714 NULL
, ill
, nip6h
, nmp
, mp_ip6h
,
10718 ip6__loopback__out__end
,
10722 * DTrace this as ip:::send. A blocked
10723 * packet will fire the send probe, but
10724 * not the receive probe.
10726 DTRACE_IP7(send
, mblk_t
*, nmp
,
10727 conn_t
*, NULL
, void_ip_t
*, nip6h
,
10728 __dtrace_ipsr_ill_t
*, ill
,
10729 ipha_t
*, NULL
, ip6_t
*, nip6h
,
10734 * Deliver locally and to
10735 * every local zone, except
10736 * the sending zone when
10737 * IPV6_MULTICAST_LOOP is
10740 ip_wput_local_v6(RD(q
), ill
,
10742 fanout_flags
, zoneid
);
10745 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
10746 ip1dbg(("ip_wput_ire_v6: "
10747 "copymsg failed\n"));
10751 if (ip6h
->ip6_hops
== 0 ||
10752 IN6_IS_ADDR_MC_NODELOCAL(&ip6h
->ip6_dst
) ||
10753 IS_LOOPBACK(ill
)) {
10755 * Local multicast or just loopback on loopback
10758 BUMP_MIB(mibptr
, ipIfStatsHCOutMcastPkts
);
10759 UPDATE_MIB(mibptr
, ipIfStatsHCOutMcastOctets
,
10760 ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
);
10761 ip1dbg(("ip_wput_ire_v6: local multicast only\n"));
10767 if (ire
->ire_stq
!= NULL
) {
10769 uint_t ill_index
= ((ill_t
*)ire
->ire_stq
->q_ptr
)->
10770 ill_phyint
->phyint_ifindex
;
10771 queue_t
*dev_q
= ire
->ire_stq
->q_next
;
10774 * non-NULL send-to queue - packet is to be sent
10775 * out an interface.
10778 /* Driver is flow-controlling? */
10779 if (!IP_FLOW_CONTROLLED_ULP(nexthdr
) &&
10780 DEV_Q_FLOW_BLOCKED(dev_q
)) {
10782 * Queue packet if we have an conn to give back
10783 * pressure. We can't queue packets intended for
10784 * hardware acceleration since we've tossed that
10785 * state already. If the packet is being fed back
10786 * from ire_send_v6, we don't know the position in
10787 * the queue to enqueue the packet and we discard
10790 if (ipst
->ips_ip_output_queue
&& connp
!= NULL
&&
10791 !mctl_present
&& caller
!= IRE_SEND
) {
10792 if (caller
== IP_WSRV
) {
10793 idl_tx_list_t
*idl_txl
;
10795 idl_txl
= &ipst
->ips_idl_tx_list
[0];
10796 connp
->conn_did_putbq
= 1;
10797 (void) putbq(connp
->conn_wq
, mp
);
10798 conn_drain_insert(connp
, idl_txl
);
10800 * caller == IP_WSRV implies we are
10801 * the service thread, and the
10802 * queue is already noenabled.
10803 * The check for canput and
10804 * the putbq is not atomic.
10805 * So we need to check again.
10808 connp
->conn_did_putbq
= 0;
10810 (void) putq(connp
->conn_wq
, mp
);
10814 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
10820 * Look for reachability confirmations from the transport.
10822 if (ip6h
->ip6_vcf
& IP_FORWARD_PROG
) {
10823 reachable
|= IPV6_REACHABILITY_CONFIRMATION
;
10824 ip6h
->ip6_vcf
&= ~IP_FORWARD_PROG
;
10826 io
->ipsec_out_reachable
= B_TRUE
;
10832 case IPPROTO_ICMPV6
:
10834 hdr_length
= IPV6_HDR_LEN
;
10839 if (!ip_hdr_length_nexthdr_v6(mp
, ip6h
,
10840 &hdr_length
, &nexthdrp
)) {
10841 /* Malformed packet */
10842 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
10846 nexthdr
= *nexthdrp
;
10851 if (cksum_request
!= -1 && nexthdr
!= IPPROTO_ICMPV6
) {
10856 * The packet header is processed once for all, even
10857 * in the multirouting case. We disable hardware
10858 * checksum if the packet is multirouted, as it will be
10859 * replicated via several interfaces, and not all of
10860 * them may have this capability.
10862 if (cksum_request
== 1 &&
10863 !(ire
->ire_flags
& RTF_MULTIRT
)) {
10864 /* Skip the transport checksum */
10868 * Do user-configured raw checksum.
10869 * Compute checksum and insert at offset "cksum_request"
10872 /* check for enough headers for checksum */
10873 cksum_request
+= hdr_length
; /* offset from rptr */
10874 if ((mp
->b_wptr
- mp
->b_rptr
) <
10875 (cksum_request
+ sizeof (int16_t))) {
10877 cksum_request
+ sizeof (int16_t))) {
10878 ip1dbg(("ip_wput_v6: ICMP hdr pullupmsg"
10880 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
10884 ip6h
= (ip6_t
*)mp
->b_rptr
;
10886 insp
= (uint16_t *)((uchar_t
*)ip6h
+ cksum_request
);
10887 ASSERT(((uintptr_t)insp
& 0x1) == 0);
10888 up
= (uint16_t *)&ip6h
->ip6_src
;
10890 * icmp has placed length and routing
10891 * header adjustment in *insp.
10893 sum
= htons(nexthdr
) +
10894 up
[0] + up
[1] + up
[2] + up
[3] +
10895 up
[4] + up
[5] + up
[6] + up
[7] +
10896 up
[8] + up
[9] + up
[10] + up
[11] +
10897 up
[12] + up
[13] + up
[14] + up
[15];
10898 sum
= (sum
& 0xffff) + (sum
>> 16);
10899 *insp
= IP_CSUM(mp
, hdr_length
, sum
);
10900 } else if (nexthdr
== IPPROTO_TCP
) {
10904 * Check for full IPv6 header + enough TCP header
10905 * to get at the checksum field.
10907 if ((mp
->b_wptr
- mp
->b_rptr
) <
10908 (hdr_length
+ TCP_CHECKSUM_OFFSET
+
10909 TCP_CHECKSUM_SIZE
)) {
10910 if (!pullupmsg(mp
, hdr_length
+
10911 TCP_CHECKSUM_OFFSET
+ TCP_CHECKSUM_SIZE
)) {
10912 ip1dbg(("ip_wput_v6: TCP hdr pullupmsg"
10914 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
10918 ip6h
= (ip6_t
*)mp
->b_rptr
;
10921 up
= (uint16_t *)&ip6h
->ip6_src
;
10923 * Note: The TCP module has stored the length value
10924 * into the tcp checksum field, so we don't
10925 * need to explicitly sum it in here.
10927 sum
= up
[0] + up
[1] + up
[2] + up
[3] +
10928 up
[4] + up
[5] + up
[6] + up
[7] +
10929 up
[8] + up
[9] + up
[10] + up
[11] +
10930 up
[12] + up
[13] + up
[14] + up
[15];
10932 /* Fold the initial sum */
10933 sum
= (sum
& 0xffff) + (sum
>> 16);
10935 up
= (uint16_t *)(((uchar_t
*)ip6h
) +
10936 hdr_length
+ TCP_CHECKSUM_OFFSET
);
10938 IP_CKSUM_XMIT(ill
, ire
, mp
, ip6h
, up
, IPPROTO_TCP
,
10939 hdr_length
, ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
,
10940 ire
->ire_max_frag
, mctl_present
, sum
);
10942 /* Software checksum? */
10943 if (DB_CKSUMFLAGS(mp
) == 0) {
10944 IP6_STAT(ipst
, ip6_out_sw_cksum
);
10945 IP6_STAT_UPDATE(ipst
,
10946 ip6_tcp_out_sw_cksum_bytes
,
10947 (ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
) -
10950 } else if (nexthdr
== IPPROTO_UDP
) {
10954 * check for full IPv6 header + enough UDP header
10955 * to get at the UDP checksum field
10957 if ((mp
->b_wptr
- mp
->b_rptr
) < (hdr_length
+
10958 UDP_CHECKSUM_OFFSET
+ UDP_CHECKSUM_SIZE
)) {
10959 if (!pullupmsg(mp
, hdr_length
+
10960 UDP_CHECKSUM_OFFSET
+ UDP_CHECKSUM_SIZE
)) {
10961 ip1dbg(("ip_wput_v6: UDP hdr pullupmsg"
10963 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
10967 ip6h
= (ip6_t
*)mp
->b_rptr
;
10969 up
= (uint16_t *)&ip6h
->ip6_src
;
10971 * Note: The UDP module has stored the length value
10972 * into the udp checksum field, so we don't
10973 * need to explicitly sum it in here.
10975 sum
= up
[0] + up
[1] + up
[2] + up
[3] +
10976 up
[4] + up
[5] + up
[6] + up
[7] +
10977 up
[8] + up
[9] + up
[10] + up
[11] +
10978 up
[12] + up
[13] + up
[14] + up
[15];
10980 /* Fold the initial sum */
10981 sum
= (sum
& 0xffff) + (sum
>> 16);
10983 up
= (uint16_t *)(((uchar_t
*)ip6h
) +
10984 hdr_length
+ UDP_CHECKSUM_OFFSET
);
10986 IP_CKSUM_XMIT(ill
, ire
, mp
, ip6h
, up
, IPPROTO_UDP
,
10987 hdr_length
, ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
,
10988 ire
->ire_max_frag
, mctl_present
, sum
);
10990 /* Software checksum? */
10991 if (DB_CKSUMFLAGS(mp
) == 0) {
10992 IP6_STAT(ipst
, ip6_out_sw_cksum
);
10993 IP6_STAT_UPDATE(ipst
,
10994 ip6_udp_out_sw_cksum_bytes
,
10995 (ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
) -
10998 } else if (nexthdr
== IPPROTO_ICMPV6
) {
11002 /* check for full IPv6+ICMPv6 header */
11003 if ((mp
->b_wptr
- mp
->b_rptr
) <
11004 (hdr_length
+ ICMP6_MINLEN
)) {
11005 if (!pullupmsg(mp
, hdr_length
+ ICMP6_MINLEN
)) {
11006 ip1dbg(("ip_wput_v6: ICMP hdr pullupmsg"
11008 BUMP_MIB(mibptr
, ipIfStatsOutDiscards
);
11012 ip6h
= (ip6_t
*)mp
->b_rptr
;
11014 icmp6
= (icmp6_t
*)((uchar_t
*)ip6h
+ hdr_length
);
11015 up
= (uint16_t *)&ip6h
->ip6_src
;
11017 * icmp has placed length and routing
11018 * header adjustment in icmp6_cksum.
11020 sum
= htons(IPPROTO_ICMPV6
) +
11021 up
[0] + up
[1] + up
[2] + up
[3] +
11022 up
[4] + up
[5] + up
[6] + up
[7] +
11023 up
[8] + up
[9] + up
[10] + up
[11] +
11024 up
[12] + up
[13] + up
[14] + up
[15];
11025 sum
= (sum
& 0xffff) + (sum
>> 16);
11026 icmp6
->icmp6_cksum
= IP_CSUM(mp
, hdr_length
, sum
);
11028 /* Update output mib stats */
11029 icmp_update_out_mib_v6(ill
, icmp6
);
11030 } else if (nexthdr
== IPPROTO_SCTP
) {
11033 if (MBLKL(mp
) < (hdr_length
+ sizeof (*sctph
))) {
11034 if (!pullupmsg(mp
, hdr_length
+
11035 sizeof (*sctph
))) {
11036 ip1dbg(("ip_wput_v6: SCTP hdr pullupmsg"
11038 BUMP_MIB(ill
->ill_ip_mib
,
11039 ipIfStatsOutDiscards
);
11043 ip6h
= (ip6_t
*)mp
->b_rptr
;
11045 sctph
= (sctp_hdr_t
*)(mp
->b_rptr
+ hdr_length
);
11046 sctph
->sh_chksum
= 0;
11047 sctph
->sh_chksum
= sctp_cksum(mp
, hdr_length
);
11052 * We force the insertion of a fragment header using the
11053 * IPH_FRAG_HDR flag in two cases:
11054 * - after reception of an ICMPv6 "packet too big" message
11055 * with a MTU < 1280 (cf. RFC 2460 section 5)
11056 * - for multirouted IPv6 packets, so that the receiver can
11057 * discard duplicates according to their fragment identifier
11059 * Two flags modifed from the API can modify this behavior.
11060 * The first is IPV6_USE_MIN_MTU. With this API the user
11061 * can specify how to manage PMTUD for unicast and multicast.
11063 * IPV6_DONTFRAG disallows fragmentation.
11065 max_frag
= ire
->ire_max_frag
;
11066 switch (IP6I_USE_MIN_MTU_API(flags
)) {
11067 case IPV6_USE_MIN_MTU_DEFAULT
:
11068 case IPV6_USE_MIN_MTU_UNICAST
:
11069 if (IN6_IS_ADDR_MULTICAST(&ip6h
->ip6_dst
)) {
11070 max_frag
= IPV6_MIN_MTU
;
11074 case IPV6_USE_MIN_MTU_NEVER
:
11075 max_frag
= IPV6_MIN_MTU
;
11078 if (ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
> max_frag
||
11079 (ire
->ire_frag_flag
& IPH_FRAG_HDR
)) {
11080 if (connp
!= NULL
&& (flags
& IP6I_DONTFRAG
)) {
11081 icmp_pkt2big_v6(ire
->ire_stq
, first_mp
,
11082 max_frag
, B_FALSE
, B_TRUE
, zoneid
, ipst
);
11086 if (ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
!=
11087 (mp
->b_cont
? msgdsize(mp
) :
11088 mp
->b_wptr
- (uchar_t
*)ip6h
)) {
11089 ip0dbg(("Packet length mismatch: %d, %ld\n",
11090 ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
,
11095 /* Do IPSEC processing first */
11096 if (mctl_present
) {
11097 ipsec_out_process(q
, first_mp
, ire
, ill_index
);
11100 ASSERT(mp
->b_prev
== NULL
);
11101 ip2dbg(("Fragmenting Size = %d, mtu = %d\n",
11102 ntohs(ip6h
->ip6_plen
) +
11103 IPV6_HDR_LEN
, max_frag
));
11104 ASSERT(mp
== first_mp
);
11105 /* Initiate IPPF processing */
11106 if (IPP_ENABLED(IPP_LOCAL_OUT
, ipst
)) {
11107 ip_process(IPP_LOCAL_OUT
, &mp
, ill_index
);
11112 ip_wput_frag_v6(mp
, ire
, reachable
, connp
,
11116 /* Do IPSEC processing first */
11117 if (mctl_present
) {
11118 int extra_len
= ipsec_out_extra_length(first_mp
);
11120 if (ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
+ extra_len
>
11123 * IPsec headers will push the packet over the
11124 * MTU limit. Issue an ICMPv6 Packet Too Big
11125 * message for this packet if the upper-layer
11126 * that issued this packet will be able to
11127 * react to the icmp_pkt2big_v6() that we'll
11130 icmp_pkt2big_v6(ire
->ire_stq
, first_mp
,
11131 max_frag
, B_FALSE
, B_TRUE
, zoneid
, ipst
);
11134 ipsec_out_process(q
, first_mp
, ire
, ill_index
);
11138 * XXX multicast: add ip_mforward_v6() here.
11139 * Check conn_dontroute
11143 * XXX The only purpose of this statement is to avoid lint
11144 * errors. See the above "XXX multicast". When that gets
11145 * fixed, remove this whole #ifdef lint section.
11147 ip3dbg(("multicast forward is %s.\n",
11148 (multicast_forward
? "TRUE" : "FALSE")));
11151 UPDATE_OB_PKT_COUNT(ire
);
11152 ire
->ire_last_used_time
= lbolt
;
11153 ASSERT(mp
== first_mp
);
11154 ip_xmit_v6(mp
, ire
, reachable
, connp
, caller
, NULL
);
11157 * DTrace this as ip:::send. A blocked packet will fire the
11158 * send probe, but not the receive probe.
11160 DTRACE_IP7(send
, mblk_t
*, first_mp
, conn_t
*, NULL
,
11161 void_ip_t
*, ip6h
, __dtrace_ipsr_ill_t
*, ill
, ipha_t
*,
11162 NULL
, ip6_t
*, ip6h
, int, 1);
11163 DTRACE_PROBE4(ip6__loopback__out__start
,
11164 ill_t
*, NULL
, ill_t
*, ill
,
11165 ip6_t
*, ip6h
, mblk_t
*, first_mp
);
11166 FW_HOOKS6(ipst
->ips_ip6_loopback_out_event
,
11167 ipst
->ips_ipv6firewall_loopback_out
,
11168 NULL
, ill
, ip6h
, first_mp
, mp
, 0, ipst
);
11169 DTRACE_PROBE1(ip6__loopback__out__end
, mblk_t
*, first_mp
);
11170 if (first_mp
!= NULL
) {
11171 ip_wput_local_v6(RD(q
), ill
, ip6h
, first_mp
, ire
, 0,
11178 * Outbound IPv6 fragmentation routine using MDT.
11181 ip_wput_frag_mdt_v6(mblk_t
*mp
, ire_t
*ire
, size_t max_chunk
,
11182 size_t unfragmentable_len
, uint8_t nexthdr
, uint_t prev_nexthdr_offset
)
11184 ip6_t
*ip6h
= (ip6_t
*)mp
->b_rptr
;
11185 uint_t pkts
, wroff
, hdr_chunk_len
, pbuf_idx
;
11186 mblk_t
*hdr_mp
, *md_mp
= NULL
;
11189 unsigned char *hdr_ptr
, *pld_ptr
;
11190 ip_pdescinfo_t pdi
;
11194 queue_t
*stq
= ire
->ire_stq
;
11195 ill_t
*ill
= (ill_t
*)stq
->q_ptr
;
11196 ip_stack_t
*ipst
= ill
->ill_ipst
;
11198 ASSERT(DB_TYPE(mp
) == M_DATA
);
11199 ASSERT(MBLKL(mp
) > unfragmentable_len
);
11202 * Move read ptr past unfragmentable portion, we don't want this part
11203 * of the data in our fragments.
11205 mp
->b_rptr
+= unfragmentable_len
;
11207 /* Calculate how many packets we will send out */
11208 i1
= (mp
->b_cont
== NULL
) ? MBLKL(mp
) : msgsize(mp
);
11209 pkts
= (i1
+ max_chunk
- 1) / max_chunk
;
11212 /* Allocate a message block which will hold all the IP Headers. */
11213 wroff
= ipst
->ips_ip_wroff_extra
;
11214 hdr_chunk_len
= wroff
+ unfragmentable_len
+ sizeof (ip6_frag_t
);
11216 i1
= pkts
* hdr_chunk_len
;
11218 * Create the header buffer, Multidata and destination address
11219 * and SAP attribute that should be associated with it.
11221 if ((hdr_mp
= allocb(i1
, BPRI_HI
)) == NULL
||
11222 ((hdr_mp
->b_wptr
+= i1
),
11223 (mmd
= mmd_alloc(hdr_mp
, &md_mp
, KM_NOSLEEP
)) == NULL
) ||
11224 !ip_md_addr_attr(mmd
, NULL
, ire
->ire_nce
->nce_res_mp
)) {
11226 if (md_mp
== NULL
) {
11229 free_mmd
: IP6_STAT(ipst
, ip6_frag_mdt_discarded
);
11232 IP6_STAT(ipst
, ip6_frag_mdt_allocfail
);
11233 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11236 IP6_STAT(ipst
, ip6_frag_mdt_allocd
);
11239 * Add a payload buffer to the Multidata; this operation must not
11240 * fail, or otherwise our logic in this routine is broken. There
11241 * is no memory allocation done by the routine, so any returned
11242 * failure simply tells us that we've done something wrong.
11244 * A failure tells us that either we're adding the same payload
11245 * buffer more than once, or we're trying to add more buffers than
11246 * allowed. None of the above cases should happen, and we panic
11247 * because either there's horrible heap corruption, and/or
11248 * programming mistake.
11250 if ((pbuf_idx
= mmd_addpldbuf(mmd
, mp
)) < 0) {
11254 hdr_ptr
= hdr_mp
->b_rptr
;
11255 pld_ptr
= mp
->b_rptr
;
11257 pdi
.flags
= PDESC_HBUF_REF
| PDESC_PBUF_REF
;
11259 ident
= htonl(atomic_add_32_nv(&ire
->ire_ident
, 1));
11262 * len is the total length of the fragmentable data in this
11263 * datagram. For each fragment sent, we will decrement len
11264 * by the amount of fragmentable data sent in that fragment
11265 * until len reaches zero.
11267 len
= ntohs(ip6h
->ip6_plen
) - (unfragmentable_len
- IPV6_HDR_LEN
);
11270 prev_nexthdr_offset
+= wroff
;
11275 ip6_frag_t
*fraghdr
;
11278 ASSERT((hdr_ptr
+ hdr_chunk_len
) <= hdr_mp
->b_wptr
);
11279 mlen
= MIN(len
, max_chunk
);
11282 fip6h
= (ip6_t
*)(hdr_ptr
+ wroff
);
11283 ASSERT(OK_32PTR(fip6h
));
11284 bcopy(ip6h
, fip6h
, unfragmentable_len
);
11285 hdr_ptr
[prev_nexthdr_offset
] = IPPROTO_FRAGMENT
;
11287 fip6h
->ip6_plen
= htons((uint16_t)(mlen
+
11288 unfragmentable_len
- IPV6_HDR_LEN
+ sizeof (ip6_frag_t
)));
11290 fraghdr
= (ip6_frag_t
*)((unsigned char *)fip6h
+
11291 unfragmentable_len
);
11292 fraghdr
->ip6f_nxt
= nexthdr
;
11293 fraghdr
->ip6f_reserved
= 0;
11294 fraghdr
->ip6f_offlg
= htons(offset
) |
11295 ((len
!= 0) ? IP6F_MORE_FRAG
: 0);
11296 fraghdr
->ip6f_ident
= ident
;
11299 * Record offset and size of header and data of the next packet
11300 * in the multidata message.
11302 PDESC_HDR_ADD(&pdi
, hdr_ptr
, wroff
,
11303 unfragmentable_len
+ sizeof (ip6_frag_t
), 0);
11304 PDESC_PLD_INIT(&pdi
);
11305 i1
= MIN(mp
->b_wptr
- pld_ptr
, mlen
);
11307 PDESC_PLD_SPAN_ADD(&pdi
, pbuf_idx
, pld_ptr
, i1
);
11313 ASSERT(mp
!= NULL
);
11314 ASSERT(MBLKL(mp
) >= i1
);
11316 * Attach the next payload message block to the
11317 * multidata message.
11319 if ((pbuf_idx
= mmd_addpldbuf(mmd
, mp
)) < 0)
11321 PDESC_PLD_SPAN_ADD(&pdi
, pbuf_idx
, mp
->b_rptr
, i1
);
11322 pld_ptr
= mp
->b_rptr
+ i1
;
11325 if ((mmd_addpdesc(mmd
, (pdescinfo_t
*)&pdi
, &error
,
11326 KM_NOSLEEP
)) == NULL
) {
11328 * Any failure other than ENOMEM indicates that we
11329 * have passed in invalid pdesc info or parameters
11330 * to mmd_addpdesc, which must not happen.
11332 * EINVAL is a result of failure on boundary checks
11333 * against the pdesc info contents. It should not
11334 * happen, and we panic because either there's
11335 * horrible heap corruption, and/or programming
11338 if (error
!= ENOMEM
) {
11339 cmn_err(CE_PANIC
, "ip_wput_frag_mdt_v6: "
11340 "pdesc logic error detected for "
11341 "mmd %p pinfo %p (%d)\n",
11342 (void *)mmd
, (void *)&pdi
, error
);
11345 IP6_STAT(ipst
, ip6_frag_mdt_addpdescfail
);
11346 /* Free unattached payload message blocks as well */
11347 md_mp
->b_cont
= mp
->b_cont
;
11351 /* Advance fragment offset. */
11354 /* Advance to location for next header in the buffer. */
11355 hdr_ptr
+= hdr_chunk_len
;
11357 /* Did we reach the next payload message block? */
11358 if (pld_ptr
== mp
->b_wptr
&& mp
->b_cont
!= NULL
) {
11361 * Attach the next message block with payload
11362 * data to the multidata message.
11364 if ((pbuf_idx
= mmd_addpldbuf(mmd
, mp
)) < 0)
11366 pld_ptr
= mp
->b_rptr
;
11370 ASSERT(hdr_mp
->b_wptr
== hdr_ptr
);
11371 ASSERT(mp
->b_wptr
== pld_ptr
);
11373 /* Update IP statistics */
11374 UPDATE_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragCreates
, pkts
);
11375 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragOKs
);
11376 UPDATE_MIB(ill
->ill_ip_mib
, ipIfStatsHCOutTransmits
, pkts
);
11378 * The ipv6 header len is accounted for in unfragmentable_len so
11379 * when calculating the fragmentation overhead just add the frag
11382 UPDATE_MIB(ill
->ill_ip_mib
, ipIfStatsHCOutOctets
,
11383 (ntohs(ip6h
->ip6_plen
) - (unfragmentable_len
- IPV6_HDR_LEN
)) +
11384 pkts
* (unfragmentable_len
+ sizeof (ip6_frag_t
)));
11385 IP6_STAT_UPDATE(ipst
, ip6_frag_mdt_pkt_out
, pkts
);
11387 ire
->ire_ob_pkt_count
+= pkts
;
11388 if (ire
->ire_ipif
!= NULL
)
11389 atomic_add_32(&ire
->ire_ipif
->ipif_ob_pkt_count
, pkts
);
11391 ire
->ire_last_used_time
= lbolt
;
11393 putnext(stq
, md_mp
);
11397 cmn_err(CE_PANIC
, "ip_wput_frag_mdt_v6: payload buffer logic "
11398 "error for mmd %p pbuf %p (%d)", (void *)mmd
, (void *)mp
,
11404 * IPv6 fragmentation. Essentially the same as IPv4 fragmentation.
11405 * We have not optimized this in terms of number of mblks
11406 * allocated. For instance, for each fragment sent we always allocate a
11407 * mblk to hold the IPv6 header and fragment header.
11409 * Assumes that all the extension headers are contained in the first mblk.
11411 * The fragment header is inserted after an hop-by-hop options header
11412 * and after [an optional destinations header followed by] a routing header.
11414 * NOTE : This function does not ire_refrele the ire passed in as
11418 ip_wput_frag_v6(mblk_t
*mp
, ire_t
*ire
, uint_t reachable
, conn_t
*connp
,
11419 int caller
, int max_frag
)
11421 ip6_t
*ip6h
= (ip6_t
*)mp
->b_rptr
;
11426 ip6_frag_t
*fraghdr
;
11427 size_t unfragmentable_len
;
11432 uint16_t off_flags
;
11433 uint16_t offset
= 0;
11436 uint_t prev_nexthdr_offset
;
11438 ip_stack_t
*ipst
= ire
->ire_ipst
;
11440 ASSERT(ire
->ire_type
== IRE_CACHE
);
11441 ill
= (ill_t
*)ire
->ire_stq
->q_ptr
;
11443 if (max_frag
<= 0) {
11444 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11448 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragReqds
);
11451 * Determine the length of the unfragmentable portion of this
11452 * datagram. This consists of the IPv6 header, a potential
11453 * hop-by-hop options header, a potential pre-routing-header
11454 * destination options header, and a potential routing header.
11456 nexthdr
= ip6h
->ip6_nxt
;
11457 prev_nexthdr_offset
= (uint8_t *)&ip6h
->ip6_nxt
- (uint8_t *)ip6h
;
11458 ptr
= (uint8_t *)&ip6h
[1];
11460 if (nexthdr
== IPPROTO_HOPOPTS
) {
11461 ip6_hbh_t
*hbh_hdr
;
11464 hbh_hdr
= (ip6_hbh_t
*)ptr
;
11465 hdr_len
= 8 * (hbh_hdr
->ip6h_len
+ 1);
11466 nexthdr
= hbh_hdr
->ip6h_nxt
;
11467 prev_nexthdr_offset
= (uint8_t *)&hbh_hdr
->ip6h_nxt
11471 if (nexthdr
== IPPROTO_DSTOPTS
) {
11472 ip6_dest_t
*dest_hdr
;
11475 dest_hdr
= (ip6_dest_t
*)ptr
;
11476 if (dest_hdr
->ip6d_nxt
== IPPROTO_ROUTING
) {
11477 hdr_len
= 8 * (dest_hdr
->ip6d_len
+ 1);
11478 nexthdr
= dest_hdr
->ip6d_nxt
;
11479 prev_nexthdr_offset
= (uint8_t *)&dest_hdr
->ip6d_nxt
11484 if (nexthdr
== IPPROTO_ROUTING
) {
11485 ip6_rthdr_t
*rthdr
;
11488 rthdr
= (ip6_rthdr_t
*)ptr
;
11489 nexthdr
= rthdr
->ip6r_nxt
;
11490 prev_nexthdr_offset
= (uint8_t *)&rthdr
->ip6r_nxt
11492 hdr_len
= 8 * (rthdr
->ip6r_len
+ 1);
11495 unfragmentable_len
= (uint_t
)(ptr
- (uint8_t *)ip6h
);
11497 max_chunk
= (min(max_frag
, ire
->ire_max_frag
) - unfragmentable_len
-
11498 sizeof (ip6_frag_t
)) & ~7;
11500 /* Check if we can use MDT to send out the frags. */
11501 ASSERT(!IRE_IS_LOCAL(ire
));
11502 if (ipst
->ips_ip_multidata_outbound
&& reachable
== 0 &&
11503 !(ire
->ire_flags
& RTF_MULTIRT
) && ILL_MDT_CAPABLE(ill
) &&
11504 IP_CAN_FRAG_MDT(mp
, unfragmentable_len
, max_chunk
)) {
11505 ip_wput_frag_mdt_v6(mp
, ire
, max_chunk
, unfragmentable_len
,
11506 nexthdr
, prev_nexthdr_offset
);
11511 * Allocate an mblk with enough room for the link-layer
11512 * header, the unfragmentable part of the datagram, and the
11513 * fragment header. This (or a copy) will be used as the
11514 * first mblk for each fragment we send.
11516 hmp
= allocb_tmpl(unfragmentable_len
+ sizeof (ip6_frag_t
) +
11517 ipst
->ips_ip_wroff_extra
, mp
);
11519 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11523 hmp
->b_rptr
+= ipst
->ips_ip_wroff_extra
;
11524 hmp
->b_wptr
= hmp
->b_rptr
+ unfragmentable_len
+ sizeof (ip6_frag_t
);
11526 fip6h
= (ip6_t
*)hmp
->b_rptr
;
11527 fraghdr
= (ip6_frag_t
*)(hmp
->b_rptr
+ unfragmentable_len
);
11529 bcopy(ip6h
, fip6h
, unfragmentable_len
);
11530 hmp
->b_rptr
[prev_nexthdr_offset
] = IPPROTO_FRAGMENT
;
11532 ident
= atomic_add_32_nv(&ire
->ire_ident
, 1);
11534 fraghdr
->ip6f_nxt
= nexthdr
;
11535 fraghdr
->ip6f_reserved
= 0;
11536 fraghdr
->ip6f_offlg
= 0;
11537 fraghdr
->ip6f_ident
= htonl(ident
);
11540 * len is the total length of the fragmentable data in this
11541 * datagram. For each fragment sent, we will decrement len
11542 * by the amount of fragmentable data sent in that fragment
11543 * until len reaches zero.
11545 len
= ntohs(ip6h
->ip6_plen
) - (unfragmentable_len
- IPV6_HDR_LEN
);
11548 * Move read ptr past unfragmentable portion, we don't want this part
11549 * of the data in our fragments.
11551 mp
->b_rptr
+= unfragmentable_len
;
11554 mlen
= MIN(len
, max_chunk
);
11559 if (hmp0
== NULL
) {
11562 BUMP_MIB(ill
->ill_ip_mib
,
11563 ipIfStatsOutFragFails
);
11564 ip1dbg(("ip_wput_frag_v6: copyb failed\n"));
11567 off_flags
= IP6F_MORE_FRAG
;
11569 /* Last fragment */
11574 fip6h
= (ip6_t
*)(hmp0
->b_rptr
);
11575 fraghdr
= (ip6_frag_t
*)(hmp0
->b_rptr
+ unfragmentable_len
);
11577 fip6h
->ip6_plen
= htons((uint16_t)(mlen
+
11578 unfragmentable_len
- IPV6_HDR_LEN
+ sizeof (ip6_frag_t
)));
11580 * Note: Optimization alert.
11581 * In IPv6 (and IPv4) protocol header, Fragment Offset
11582 * ("offset") is 13 bits wide and in 8-octet units.
11583 * In IPv6 protocol header (unlike IPv4) in a 16 bit field,
11584 * it occupies the most significant 13 bits.
11585 * (least significant 13 bits in IPv4).
11586 * We do not do any shifts here. Not shifting is same effect
11587 * as taking offset value in octet units, dividing by 8 and
11588 * then shifting 3 bits left to line it up in place in proper
11589 * place protocol header.
11591 fraghdr
->ip6f_offlg
= htons(offset
) | off_flags
;
11593 if (!(dmp
= ip_carve_mp(&mp
, mlen
))) {
11594 /* mp has already been freed by ip_carve_mp() */
11598 ip1dbg(("ip_carve_mp: failed\n"));
11599 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11602 hmp0
->b_cont
= dmp
;
11603 /* Get the priority marking, if any */
11604 hmp0
->b_band
= dmp
->b_band
;
11605 UPDATE_OB_PKT_COUNT(ire
);
11606 ire
->ire_last_used_time
= lbolt
;
11607 ip_xmit_v6(hmp0
, ire
, reachable
| IP6_NO_IPPOLICY
, connp
,
11609 reachable
= 0; /* No need to redo state machine in loop */
11610 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragCreates
);
11613 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragOKs
);
11617 * Determine if the ill and multicast aspects of that packets
11618 * "matches" the conn.
11621 conn_wantpacket_v6(conn_t
*connp
, ill_t
*ill
, ip6_t
*ip6h
, int fanout_flags
,
11625 boolean_t wantpacket
;
11626 in6_addr_t
*v6dst_ptr
= &ip6h
->ip6_dst
;
11627 in6_addr_t
*v6src_ptr
= &ip6h
->ip6_src
;
11630 * conn_incoming_ill is set by IPV6_BOUND_IF which limits
11631 * unicast and multicast reception to conn_incoming_ill.
11632 * conn_wantpacket_v6 is called both for unicast and
11635 bound_ill
= connp
->conn_incoming_ill
;
11636 if (bound_ill
!= NULL
) {
11637 if (IS_IPMP(bound_ill
)) {
11638 if (bound_ill
->ill_grp
!= ill
->ill_grp
)
11641 if (bound_ill
!= ill
)
11646 if (connp
->conn_multi_router
)
11649 if (!IN6_IS_ADDR_MULTICAST(v6dst_ptr
) &&
11650 !IN6_IS_ADDR_V4MAPPED_CLASSD(v6dst_ptr
)) {
11652 * Unicast case: we match the conn only if it's in the specified
11655 return (IPCL_ZONE_MATCH(connp
, zoneid
));
11658 if ((fanout_flags
& IP_FF_NO_MCAST_LOOP
) &&
11659 (connp
->conn_zoneid
== zoneid
|| zoneid
== ALL_ZONES
)) {
11661 * Loopback case: the sending endpoint has IP_MULTICAST_LOOP
11662 * disabled, therefore we don't dispatch the multicast packet to
11663 * the sending zone.
11668 if (IS_LOOPBACK(ill
) && connp
->conn_zoneid
!= zoneid
&&
11669 zoneid
!= ALL_ZONES
) {
11671 * Multicast packet on the loopback interface: we only match
11672 * conns who joined the group in the specified zone.
11677 mutex_enter(&connp
->conn_lock
);
11679 ilg_lookup_ill_withsrc_v6(connp
, v6dst_ptr
, v6src_ptr
, ill
) != NULL
;
11680 mutex_exit(&connp
->conn_lock
);
11682 return (wantpacket
);
11687 * Transmit a packet and update any NUD state based on the flags
11688 * XXX need to "recover" any ip6i_t when doing putq!
11690 * NOTE : This function does not ire_refrele the ire passed in as the
11694 ip_xmit_v6(mblk_t
*mp
, ire_t
*ire
, uint_t flags
, conn_t
*connp
,
11695 int caller
, ipsec_out_t
*io
)
11698 nce_t
*nce
= ire
->ire_nce
;
11703 queue_t
*stq
= ire
->ire_stq
;
11704 ire_t
*ire1
= NULL
;
11705 ire_t
*save_ire
= ire
;
11706 boolean_t multirt_send
= B_FALSE
;
11707 mblk_t
*next_mp
= NULL
;
11708 ip_stack_t
*ipst
= ire
->ire_ipst
;
11709 boolean_t fp_prepend
= B_FALSE
;
11712 ip6h
= (ip6_t
*)mp
->b_rptr
;
11713 ASSERT(!IN6_IS_ADDR_V4MAPPED(&ire
->ire_addr_v6
));
11714 ASSERT(ire
->ire_ipversion
== IPV6_VERSION
);
11715 ASSERT(nce
!= NULL
);
11716 ASSERT(mp
->b_datap
->db_type
== M_DATA
);
11717 ASSERT(stq
!= NULL
);
11719 ill
= ire_to_ill(ire
);
11721 ip0dbg(("ip_xmit_v6: ire_to_ill failed\n"));
11727 * If a packet is to be sent out an interface that is a 6to4
11728 * tunnel, outgoing IPv6 packets, with a 6to4 addressed IPv6
11729 * destination, must be checked to have a 6to4 prefix
11730 * (2002:V4ADDR::/48) that is NOT equal to the 6to4 prefix of
11731 * address configured on the sending interface. Otherwise,
11732 * the packet was delivered to this interface in error and the
11733 * packet must be dropped.
11735 if ((ill
->ill_is_6to4tun
) && IN6_IS_ADDR_6TO4(&ip6h
->ip6_dst
)) {
11736 ipif_t
*ipif
= ill
->ill_ipif
;
11738 if (IN6_ARE_6TO4_PREFIX_EQUAL(&ipif
->ipif_v6lcl_addr
,
11740 if (ip_debug
> 2) {
11742 pr_addr_dbg("ip_xmit_v6: attempting to "
11743 "send 6to4 addressed IPv6 "
11744 "destination (%s) out the wrong "
11745 "interface.\n", AF_INET6
,
11748 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
11754 /* Flow-control check has been done in ip_wput_ire_v6 */
11755 if (IP_FLOW_CONTROLLED_ULP(ip6h
->ip6_nxt
) || caller
== IP_WPUT
||
11756 caller
== IP_WSRV
|| canput(stq
->q_next
)) {
11757 uint32_t ill_index
;
11760 * In most cases, the emission loop below is entered only
11761 * once. Only in the case where the ire holds the
11762 * RTF_MULTIRT flag, do we loop to process all RTF_MULTIRT
11763 * flagged ires in the bucket, and send the packet
11764 * through all crossed RTF_MULTIRT routes.
11766 if (ire
->ire_flags
& RTF_MULTIRT
) {
11768 * Multirouting case. The bucket where ire is stored
11769 * probably holds other RTF_MULTIRT flagged ires
11770 * to the destination. In this call to ip_xmit_v6,
11771 * we attempt to send the packet through all
11772 * those ires. Thus, we first ensure that ire is the
11773 * first RTF_MULTIRT ire in the bucket,
11774 * before walking the ire list.
11777 irb_t
*irb
= ire
->ire_bucket
;
11778 ASSERT(irb
!= NULL
);
11779 multirt_send
= B_TRUE
;
11781 /* Make sure we do not omit any multiroute ire. */
11783 for (first_ire
= irb
->irb_ire
;
11785 first_ire
= first_ire
->ire_next
) {
11786 if ((first_ire
->ire_flags
& RTF_MULTIRT
) &&
11787 (IN6_ARE_ADDR_EQUAL(&first_ire
->ire_addr_v6
,
11788 &ire
->ire_addr_v6
)) &&
11789 !(first_ire
->ire_marks
&
11790 (IRE_MARK_CONDEMNED
| IRE_MARK_TESTHIDDEN
)))
11794 if ((first_ire
!= NULL
) && (first_ire
!= ire
)) {
11795 IRE_REFHOLD(first_ire
);
11796 /* ire will be released by the caller */
11798 nce
= ire
->ire_nce
;
11799 stq
= ire
->ire_stq
;
11800 ill
= ire_to_ill(ire
);
11803 } else if (connp
!= NULL
&& IPCL_IS_TCP(connp
) &&
11804 connp
->conn_mdt_ok
&& !connp
->conn_tcp
->tcp_mdt
&&
11805 ILL_MDT_USABLE(ill
)) {
11807 * This tcp connection was marked as MDT-capable, but
11808 * it has been turned off due changes in the interface.
11809 * Now that the interface support is back, turn it on
11810 * by notifying tcp. We don't directly modify tcp_mdt,
11811 * since we leave all the details to the tcp code that
11814 mblk_t
*mdimp
= ip_mdinfo_alloc(ill
->ill_mdt_capab
);
11816 if (mdimp
== NULL
) {
11817 ip0dbg(("ip_xmit_v6: can't re-enable MDT for "
11818 "connp %p (ENOMEM)\n", (void *)connp
));
11820 CONN_INC_REF(connp
);
11821 SQUEUE_ENTER_ONE(connp
->conn_sqp
, mdimp
,
11822 tcp_input
, connp
, SQ_FILL
,
11823 SQTAG_TCP_INPUT_MCTL
);
11830 if (multirt_send
) {
11833 * We are in a multiple send case, need to get
11834 * the next ire and make a duplicate of the
11835 * packet. ire1 holds here the next ire to
11836 * process in the bucket. If multirouting is
11837 * expected, any non-RTF_MULTIRT ire that has
11838 * the right destination address is ignored.
11840 irb
= ire
->ire_bucket
;
11841 ASSERT(irb
!= NULL
);
11844 for (ire1
= ire
->ire_next
;
11846 ire1
= ire1
->ire_next
) {
11847 if (!(ire1
->ire_flags
& RTF_MULTIRT
))
11849 if (!IN6_ARE_ADDR_EQUAL(
11850 &ire1
->ire_addr_v6
,
11851 &ire
->ire_addr_v6
))
11853 if (ire1
->ire_marks
&
11854 IRE_MARK_CONDEMNED
)
11858 if (ire1
!= save_ire
) {
11865 if (ire1
!= NULL
) {
11866 next_mp
= copyb(mp
);
11867 if ((next_mp
== NULL
) ||
11868 ((mp
->b_cont
!= NULL
) &&
11869 ((next_mp
->b_cont
=
11870 dupmsg(mp
->b_cont
)) == NULL
))) {
11878 /* Last multiroute ire; don't loop anymore. */
11879 if (ire1
== NULL
) {
11880 multirt_send
= B_FALSE
;
11885 ((ill_t
*)stq
->q_ptr
)->ill_phyint
->phyint_ifindex
;
11887 /* Initiate IPPF processing */
11888 if (IP6_OUT_IPP(flags
, ipst
)) {
11889 ip_process(IPP_LOCAL_OUT
, &mp
, ill_index
);
11891 BUMP_MIB(ill
->ill_ip_mib
,
11892 ipIfStatsOutDiscards
);
11893 if (next_mp
!= NULL
)
11895 if (ire
!= save_ire
) {
11900 ip6h
= (ip6_t
*)mp
->b_rptr
;
11905 * Check for fastpath, we need to hold nce_lock to
11906 * prevent fastpath update from chaining nce_fp_mp.
11909 ASSERT(nce
->nce_ipversion
!= IPV4_VERSION
);
11910 mutex_enter(&nce
->nce_lock
);
11911 if ((mp1
= nce
->nce_fp_mp
) != NULL
) {
11915 rptr
= mp
->b_rptr
- hlen
;
11917 * make sure there is room for the fastpath
11920 if (rptr
< mp
->b_datap
->db_base
) {
11922 mutex_exit(&nce
->nce_lock
);
11924 BUMP_MIB(ill
->ill_ip_mib
,
11925 ipIfStatsOutDiscards
);
11927 if (next_mp
!= NULL
)
11929 if (ire
!= save_ire
) {
11936 /* Get the priority marking, if any */
11937 mp1
->b_band
= mp
->b_band
;
11942 * fastpath - pre-pend datalink
11945 bcopy(mp1
->b_rptr
, rptr
, hlen
);
11946 mutex_exit(&nce
->nce_lock
);
11947 fp_prepend
= B_TRUE
;
11951 * Get the DL_UNITDATA_REQ.
11953 mp1
= nce
->nce_res_mp
;
11955 mutex_exit(&nce
->nce_lock
);
11956 ip1dbg(("ip_xmit_v6: No resolution "
11957 "block ire = %p\n", (void *)ire
));
11959 if (next_mp
!= NULL
)
11961 if (ire
!= save_ire
) {
11967 * Prepend the DL_UNITDATA_REQ.
11970 mutex_exit(&nce
->nce_lock
);
11972 BUMP_MIB(ill
->ill_ip_mib
,
11973 ipIfStatsOutDiscards
);
11975 if (next_mp
!= NULL
)
11977 if (ire
!= save_ire
) {
11984 /* Get the priority marking, if any */
11985 mp1
->b_band
= mp
->b_band
;
11989 out_ill
= (ill_t
*)stq
->q_ptr
;
11991 DTRACE_PROBE4(ip6__physical__out__start
,
11992 ill_t
*, NULL
, ill_t
*, out_ill
,
11993 ip6_t
*, ip6h
, mblk_t
*, mp
);
11995 FW_HOOKS6(ipst
->ips_ip6_physical_out_event
,
11996 ipst
->ips_ipv6firewall_physical_out
,
11997 NULL
, out_ill
, ip6h
, mp
, mp_ip6h
, 0, ipst
);
11999 DTRACE_PROBE1(ip6__physical__out__end
, mblk_t
*, mp
);
12002 if (multirt_send
) {
12003 ASSERT(ire1
!= NULL
);
12004 if (ire
!= save_ire
) {
12008 * Proceed with the next RTF_MULTIRT
12009 * ire, also set up the send-to queue
12014 stq
= ire
->ire_stq
;
12015 nce
= ire
->ire_nce
;
12016 ill
= ire_to_ill(ire
);
12021 ASSERT(next_mp
== NULL
);
12022 ASSERT(ire1
== NULL
);
12027 if (ipst
->ips_ipobs_enabled
) {
12030 szone
= ip_get_zoneid_v6(&ip6h
->ip6_src
,
12031 mp_ip6h
, out_ill
, ipst
, ALL_ZONES
);
12032 ipobs_hook(mp_ip6h
, IPOBS_HOOK_OUTBOUND
, szone
,
12033 ALL_ZONES
, out_ill
, IPV6_VERSION
,
12034 fp_prepend
? hlen
: 0, ipst
);
12038 * Update ire and MIB counters; for save_ire, this has
12039 * been done by the caller.
12041 if (ire
!= save_ire
) {
12042 UPDATE_OB_PKT_COUNT(ire
);
12043 ire
->ire_last_used_time
= lbolt
;
12045 if (IN6_IS_ADDR_MULTICAST(&ip6h
->ip6_dst
)) {
12046 BUMP_MIB(ill
->ill_ip_mib
,
12047 ipIfStatsHCOutMcastPkts
);
12048 UPDATE_MIB(ill
->ill_ip_mib
,
12049 ipIfStatsHCOutMcastOctets
,
12050 ntohs(ip6h
->ip6_plen
) +
12056 * Send it down. XXX Do we want to flow control AH/ESP
12057 * packets that carry TCP payloads? We don't flow
12058 * control TCP packets, but we should also not
12059 * flow-control TCP packets that have been protected.
12060 * We don't have an easy way to find out if an AH/ESP
12061 * packet was originally TCP or not currently.
12064 BUMP_MIB(ill
->ill_ip_mib
,
12065 ipIfStatsHCOutTransmits
);
12066 UPDATE_MIB(ill
->ill_ip_mib
,
12067 ipIfStatsHCOutOctets
,
12068 ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
);
12069 DTRACE_IP7(send
, mblk_t
*, mp
, conn_t
*, NULL
,
12070 void_ip_t
*, ip6h
, __dtrace_ipsr_ill_t
*,
12071 out_ill
, ipha_t
*, NULL
, ip6_t
*, ip6h
,
12077 * Safety Pup says: make sure this is
12078 * going to the right interface!
12080 if (io
->ipsec_out_capab_ill_index
!=
12082 /* IPsec kstats: bump lose counter */
12085 BUMP_MIB(ill
->ill_ip_mib
,
12086 ipIfStatsHCOutTransmits
);
12087 UPDATE_MIB(ill
->ill_ip_mib
,
12088 ipIfStatsHCOutOctets
,
12089 ntohs(ip6h
->ip6_plen
) +
12091 DTRACE_IP7(send
, mblk_t
*, mp
,
12092 conn_t
*, NULL
, void_ip_t
*, ip6h
,
12093 __dtrace_ipsr_ill_t
*, out_ill
,
12094 ipha_t
*, NULL
, ip6_t
*, ip6h
, int,
12096 ipsec_hw_putnext(stq
, mp
);
12100 if (nce
->nce_flags
& (NCE_F_NONUD
|NCE_F_PERMANENT
)) {
12101 if (ire
!= save_ire
) {
12104 if (multirt_send
) {
12105 ASSERT(ire1
!= NULL
);
12107 * Proceed with the next RTF_MULTIRT
12108 * ire, also set up the send-to queue
12113 stq
= ire
->ire_stq
;
12114 nce
= ire
->ire_nce
;
12115 ill
= ire_to_ill(ire
);
12120 ASSERT(next_mp
== NULL
);
12121 ASSERT(ire1
== NULL
);
12125 ASSERT(nce
->nce_state
!= ND_INCOMPLETE
);
12128 * Check for upper layer advice
12130 if (flags
& IPV6_REACHABILITY_CONFIRMATION
) {
12132 * It should be o.k. to check the state without
12133 * a lock here, at most we lose an advice.
12135 nce
->nce_last
= TICK_TO_MSEC(lbolt64
);
12136 if (nce
->nce_state
!= ND_REACHABLE
) {
12138 mutex_enter(&nce
->nce_lock
);
12139 nce
->nce_state
= ND_REACHABLE
;
12140 nce
->nce_pcnt
= ND_MAX_UNICAST_SOLICIT
;
12141 mutex_exit(&nce
->nce_lock
);
12142 (void) untimeout(nce
->nce_timeout_id
);
12143 if (ip_debug
> 2) {
12145 pr_addr_dbg("ip_xmit_v6: state"
12146 " for %s changed to"
12147 " REACHABLE\n", AF_INET6
,
12148 &ire
->ire_addr_v6
);
12151 if (ire
!= save_ire
) {
12154 if (multirt_send
) {
12155 ASSERT(ire1
!= NULL
);
12157 * Proceed with the next RTF_MULTIRT
12158 * ire, also set up the send-to queue
12163 stq
= ire
->ire_stq
;
12164 nce
= ire
->ire_nce
;
12165 ill
= ire_to_ill(ire
);
12170 ASSERT(next_mp
== NULL
);
12171 ASSERT(ire1
== NULL
);
12175 delta
= TICK_TO_MSEC(lbolt64
) - nce
->nce_last
;
12176 ip1dbg(("ip_xmit_v6: delta = %" PRId64
12177 " ill_reachable_time = %d \n", delta
,
12178 ill
->ill_reachable_time
));
12179 if (delta
> (uint64_t)ill
->ill_reachable_time
) {
12180 nce
= ire
->ire_nce
;
12181 mutex_enter(&nce
->nce_lock
);
12182 switch (nce
->nce_state
) {
12186 * ND_REACHABLE is identical to
12187 * ND_STALE in this specific case. If
12188 * reachable time has expired for this
12189 * neighbor (delta is greater than
12190 * reachable time), conceptually, the
12191 * neighbor cache is no longer in
12192 * REACHABLE state, but already in
12193 * STALE state. So the correct
12194 * transition here is to ND_DELAY.
12196 nce
->nce_state
= ND_DELAY
;
12197 mutex_exit(&nce
->nce_lock
);
12198 NDP_RESTART_TIMER(nce
,
12199 ipst
->ips_delay_first_probe_time
);
12200 if (ip_debug
> 3) {
12202 pr_addr_dbg("ip_xmit_v6: state"
12203 " for %s changed to"
12204 " DELAY\n", AF_INET6
,
12205 &ire
->ire_addr_v6
);
12210 mutex_exit(&nce
->nce_lock
);
12211 /* Timers have already started */
12213 case ND_UNREACHABLE
:
12215 * ndp timer has detected that this nce
12216 * is unreachable and initiated deleting
12217 * this nce and all its associated IREs.
12218 * This is a race where we found the
12219 * ire before it was deleted and have
12220 * just sent out a packet using this
12223 mutex_exit(&nce
->nce_lock
);
12230 if (multirt_send
) {
12231 ASSERT(ire1
!= NULL
);
12233 * Proceed with the next RTF_MULTIRT ire,
12234 * Also set up the send-to queue accordingly.
12236 if (ire
!= save_ire
) {
12241 stq
= ire
->ire_stq
;
12242 nce
= ire
->ire_nce
;
12243 ill
= ire_to_ill(ire
);
12247 } while (multirt_send
);
12249 * In the multirouting case, release the last ire used for
12250 * emission. save_ire will be released by the caller.
12252 if (ire
!= save_ire
) {
12257 * Can't apply backpressure, just discard the packet.
12259 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
12266 * pr_addr_dbg function provides the needed buffer space to call
12267 * inet_ntop() function's 3rd argument. This function should be
12268 * used by any kernel routine which wants to save INET6_ADDRSTRLEN
12269 * stack buffer space in it's own stack frame. This function uses
12270 * a buffer from it's own stack and prints the information.
12271 * Example: pr_addr_dbg("func: no route for %s\n ", AF_INET, addr)
12273 * Note: This function can call inet_ntop() once.
12276 pr_addr_dbg(char *fmt1
, int af
, const void *addr
)
12278 char buf
[INET6_ADDRSTRLEN
];
12280 if (fmt1
== NULL
) {
12281 ip0dbg(("pr_addr_dbg: Wrong arguments\n"));
12286 * This does not compare debug level and just prints
12287 * out. Thus it is the responsibility of the caller
12288 * to check the appropriate debug-level before calling
12291 if (ip_debug
> 0) {
12292 printf(fmt1
, inet_ntop(af
, addr
, buf
, sizeof (buf
)));
12300 * Return the length in bytes of the IPv6 headers (base header, ip6i_t
12301 * if needed and extension headers) that will be needed based on the
12302 * ip6_pkt_t structure passed by the caller.
12304 * The returned length does not include the length of the upper level
12305 * protocol (ULP) header.
12308 ip_total_hdrs_len_v6(ip6_pkt_t
*ipp
)
12312 len
= IPV6_HDR_LEN
;
12313 if (ipp
->ipp_fields
& IPPF_HAS_IP6I
)
12314 len
+= sizeof (ip6i_t
);
12315 if (ipp
->ipp_fields
& IPPF_HOPOPTS
) {
12316 ASSERT(ipp
->ipp_hopoptslen
!= 0);
12317 len
+= ipp
->ipp_hopoptslen
;
12319 if (ipp
->ipp_fields
& IPPF_RTHDR
) {
12320 ASSERT(ipp
->ipp_rthdrlen
!= 0);
12321 len
+= ipp
->ipp_rthdrlen
;
12324 * En-route destination options
12325 * Only do them if there's a routing header as well
12327 if ((ipp
->ipp_fields
& (IPPF_RTDSTOPTS
|IPPF_RTHDR
)) ==
12328 (IPPF_RTDSTOPTS
|IPPF_RTHDR
)) {
12329 ASSERT(ipp
->ipp_rtdstoptslen
!= 0);
12330 len
+= ipp
->ipp_rtdstoptslen
;
12332 if (ipp
->ipp_fields
& IPPF_DSTOPTS
) {
12333 ASSERT(ipp
->ipp_dstoptslen
!= 0);
12334 len
+= ipp
->ipp_dstoptslen
;
12340 * All-purpose routine to build a header chain of an IPv6 header
12341 * followed by any required extension headers and a proto header,
12342 * preceeded (where necessary) by an ip6i_t private header.
12344 * The fields of the IPv6 header that are derived from the ip6_pkt_t
12345 * will be filled in appropriately.
12346 * Thus the caller must fill in the rest of the IPv6 header, such as
12347 * traffic class/flowid, source address (if not set here), hoplimit (if not
12348 * set here) and destination address.
12350 * The extension headers and ip6i_t header will all be fully filled in.
12353 ip_build_hdrs_v6(uchar_t
*ext_hdrs
, uint_t ext_hdrs_len
,
12354 ip6_pkt_t
*ipp
, uint8_t protocol
)
12356 uint8_t *nxthdr_ptr
;
12359 ip6_t
*ip6h
= (ip6_t
*)ext_hdrs
;
12362 * If sending private ip6i_t header down (checksum info, nexthop,
12363 * or ifindex), adjust ip header pointer and set ip6i_t header pointer,
12364 * then fill it in. (The checksum info will be filled in by icmp).
12366 if (ipp
->ipp_fields
& IPPF_HAS_IP6I
) {
12367 ip6i
= (ip6i_t
*)ip6h
;
12368 ip6h
= (ip6_t
*)&ip6i
[1];
12370 ip6i
->ip6i_flags
= 0;
12371 ip6i
->ip6i_vcf
= IPV6_DEFAULT_VERS_AND_FLOW
;
12372 if (ipp
->ipp_fields
& IPPF_IFINDEX
||
12373 ipp
->ipp_fields
& IPPF_SCOPE_ID
) {
12374 ASSERT(ipp
->ipp_ifindex
!= 0);
12375 ip6i
->ip6i_flags
|= IP6I_IFINDEX
;
12376 ip6i
->ip6i_ifindex
= ipp
->ipp_ifindex
;
12378 if (ipp
->ipp_fields
& IPPF_ADDR
) {
12380 * Enable per-packet source address verification if
12381 * IPV6_PKTINFO specified the source address.
12382 * ip6_src is set in the transport's _wput function.
12384 ASSERT(!IN6_IS_ADDR_UNSPECIFIED(
12386 ip6i
->ip6i_flags
|= IP6I_VERIFY_SRC
;
12388 if (ipp
->ipp_fields
& IPPF_UNICAST_HOPS
) {
12389 ip6h
->ip6_hops
= ipp
->ipp_unicast_hops
;
12391 * We need to set this flag so that IP doesn't
12392 * rewrite the IPv6 header's hoplimit with the
12393 * current default value.
12395 ip6i
->ip6i_flags
|= IP6I_HOPLIMIT
;
12397 if (ipp
->ipp_fields
& IPPF_NEXTHOP
) {
12398 ASSERT(!IN6_IS_ADDR_UNSPECIFIED(
12399 &ipp
->ipp_nexthop
));
12400 ip6i
->ip6i_flags
|= IP6I_NEXTHOP
;
12401 ip6i
->ip6i_nexthop
= ipp
->ipp_nexthop
;
12404 * tell IP this is an ip6i_t private header
12406 ip6i
->ip6i_nxt
= IPPROTO_RAW
;
12408 /* Initialize IPv6 header */
12409 ip6h
->ip6_vcf
= IPV6_DEFAULT_VERS_AND_FLOW
;
12410 if (ipp
->ipp_fields
& IPPF_TCLASS
) {
12411 ip6h
->ip6_vcf
= (ip6h
->ip6_vcf
& ~IPV6_FLOWINFO_TCLASS
) |
12412 (ipp
->ipp_tclass
<< 20);
12414 if (ipp
->ipp_fields
& IPPF_ADDR
)
12415 ip6h
->ip6_src
= ipp
->ipp_addr
;
12417 nxthdr_ptr
= (uint8_t *)&ip6h
->ip6_nxt
;
12418 cp
= (uint8_t *)&ip6h
[1];
12420 * Here's where we have to start stringing together
12421 * any extension headers in the right order:
12422 * Hop-by-hop, destination, routing, and final destination opts.
12424 if (ipp
->ipp_fields
& IPPF_HOPOPTS
) {
12425 /* Hop-by-hop options */
12426 ip6_hbh_t
*hbh
= (ip6_hbh_t
*)cp
;
12428 *nxthdr_ptr
= IPPROTO_HOPOPTS
;
12429 nxthdr_ptr
= &hbh
->ip6h_nxt
;
12431 bcopy(ipp
->ipp_hopopts
, cp
, ipp
->ipp_hopoptslen
);
12432 cp
+= ipp
->ipp_hopoptslen
;
12435 * En-route destination options
12436 * Only do them if there's a routing header as well
12438 if ((ipp
->ipp_fields
& (IPPF_RTDSTOPTS
|IPPF_RTHDR
)) ==
12439 (IPPF_RTDSTOPTS
|IPPF_RTHDR
)) {
12440 ip6_dest_t
*dst
= (ip6_dest_t
*)cp
;
12442 *nxthdr_ptr
= IPPROTO_DSTOPTS
;
12443 nxthdr_ptr
= &dst
->ip6d_nxt
;
12445 bcopy(ipp
->ipp_rtdstopts
, cp
, ipp
->ipp_rtdstoptslen
);
12446 cp
+= ipp
->ipp_rtdstoptslen
;
12449 * Routing header next
12451 if (ipp
->ipp_fields
& IPPF_RTHDR
) {
12452 ip6_rthdr_t
*rt
= (ip6_rthdr_t
*)cp
;
12454 *nxthdr_ptr
= IPPROTO_ROUTING
;
12455 nxthdr_ptr
= &rt
->ip6r_nxt
;
12457 bcopy(ipp
->ipp_rthdr
, cp
, ipp
->ipp_rthdrlen
);
12458 cp
+= ipp
->ipp_rthdrlen
;
12461 * Do ultimate destination options
12463 if (ipp
->ipp_fields
& IPPF_DSTOPTS
) {
12464 ip6_dest_t
*dest
= (ip6_dest_t
*)cp
;
12466 *nxthdr_ptr
= IPPROTO_DSTOPTS
;
12467 nxthdr_ptr
= &dest
->ip6d_nxt
;
12469 bcopy(ipp
->ipp_dstopts
, cp
, ipp
->ipp_dstoptslen
);
12470 cp
+= ipp
->ipp_dstoptslen
;
12473 * Now set the last header pointer to the proto passed in
12475 *nxthdr_ptr
= protocol
;
12476 ASSERT((int)(cp
- ext_hdrs
) == ext_hdrs_len
);
12480 * Return a pointer to the routing header extension header
12481 * in the IPv6 header(s) chain passed in.
12482 * If none found, return NULL
12483 * Assumes that all extension headers are in same mblk as the v6 header
12486 ip_find_rthdr_v6(ip6_t
*ip6h
, uint8_t *endptr
)
12488 ip6_dest_t
*desthdr
;
12489 ip6_frag_t
*fraghdr
;
12492 uint8_t *ptr
= (uint8_t *)&ip6h
[1];
12494 if (ip6h
->ip6_nxt
== IPPROTO_ROUTING
)
12495 return ((ip6_rthdr_t
*)ptr
);
12498 * The routing header will precede all extension headers
12499 * other than the hop-by-hop and destination options
12500 * extension headers, so if we see anything other than those,
12501 * we're done and didn't find it.
12502 * We could see a destination options header alone but no
12503 * routing header, in which case we'll return NULL as soon as
12504 * we see anything after that.
12505 * Hop-by-hop and destination option headers are identical,
12506 * so we can use either one we want as a template.
12508 nexthdr
= ip6h
->ip6_nxt
;
12509 while (ptr
< endptr
) {
12510 /* Is there enough left for len + nexthdr? */
12511 if (ptr
+ MIN_EHDR_LEN
> endptr
)
12515 case IPPROTO_HOPOPTS
:
12516 case IPPROTO_DSTOPTS
:
12517 /* Assumes the headers are identical for hbh and dst */
12518 desthdr
= (ip6_dest_t
*)ptr
;
12519 hdrlen
= 8 * (desthdr
->ip6d_len
+ 1);
12520 nexthdr
= desthdr
->ip6d_nxt
;
12523 case IPPROTO_ROUTING
:
12524 return ((ip6_rthdr_t
*)ptr
);
12526 case IPPROTO_FRAGMENT
:
12527 fraghdr
= (ip6_frag_t
*)ptr
;
12528 hdrlen
= sizeof (ip6_frag_t
);
12529 nexthdr
= fraghdr
->ip6f_nxt
;
12541 * Called for source-routed packets originating on this node.
12542 * Manipulates the original routing header by moving every entry up
12543 * one slot, placing the first entry in the v6 header's v6_dst field,
12544 * and placing the ultimate destination in the routing header's last
12547 * Returns the checksum diference between the ultimate destination
12548 * (last hop in the routing header when the packet is sent) and
12549 * the first hop (ip6_dst when the packet is sent)
12553 ip_massage_options_v6(ip6_t
*ip6h
, ip6_rthdr_t
*rth
, netstack_t
*ns
)
12557 in6_addr_t
*addrptr
;
12559 ip6_rthdr0_t
*rthdr
= (ip6_rthdr0_t
*)rth
;
12561 uint32_t addrsum
= 0;
12565 * Perform any processing needed for source routing.
12566 * We know that all extension headers will be in the same mblk
12567 * as the IPv6 header.
12571 * If no segments left in header, or the header length field is zero,
12572 * don't move hop addresses around;
12573 * Checksum difference is zero.
12575 if ((rthdr
->ip6r0_segleft
== 0) || (rthdr
->ip6r0_len
== 0))
12578 ptr
= (uint16_t *)&ip6h
->ip6_dst
;
12580 for (i
= 0; i
< (sizeof (in6_addr_t
) / sizeof (uint16_t)); i
++) {
12583 cksm
= (cksm
& 0xFFFF) + (cksm
>> 16);
12586 * Here's where the fun begins - we have to
12587 * move all addresses up one spot, take the
12588 * first hop and make it our first ip6_dst,
12589 * and place the ultimate destination in the
12590 * newly-opened last slot.
12592 addrptr
= (in6_addr_t
*)((char *)rthdr
+ sizeof (*rthdr
));
12593 numaddr
= rthdr
->ip6r0_len
/ 2;
12595 for (i
= 0; i
< (numaddr
- 1); addrptr
++, i
++) {
12596 *addrptr
= addrptr
[1];
12598 *addrptr
= ip6h
->ip6_dst
;
12599 ip6h
->ip6_dst
= tmp
;
12602 * From the checksummed ultimate destination subtract the checksummed
12603 * current ip6_dst (the first hop address). Return that number.
12604 * (In the v4 case, the second part of this is done in each routine
12605 * that calls ip_massage_options(). We do it all in this one place
12608 ptr
= (uint16_t *)&ip6h
->ip6_dst
;
12609 for (i
= 0; i
< (sizeof (in6_addr_t
) / sizeof (uint16_t)); i
++) {
12612 cksm
-= ((addrsum
>> 16) + (addrsum
& 0xFFFF));
12615 cksm
= (cksm
& 0xFFFF) + (cksm
>> 16);
12621 * Propagate a multicast group membership operation (join/leave) (*fn) on
12622 * all interfaces crossed by the related multirt routes.
12623 * The call is considered successful if the operation succeeds
12624 * on at least one interface.
12625 * The function is called if the destination address in the packet to send
12629 ip_multirt_apply_membership_v6(int (*fn
)(conn_t
*, boolean_t
,
12630 const in6_addr_t
*, int, mcast_record_t
, const in6_addr_t
*, mblk_t
*),
12631 ire_t
*ire
, conn_t
*connp
, boolean_t checkonly
, const in6_addr_t
*v6grp
,
12632 mcast_record_t fmode
, const in6_addr_t
*v6src
, mblk_t
*first_mp
)
12636 int index
, error
= 0;
12638 ip_stack_t
*ipst
= ire
->ire_ipst
;
12640 irb
= ire
->ire_bucket
;
12641 ASSERT(irb
!= NULL
);
12643 ASSERT(DB_TYPE(first_mp
) == M_CTL
);
12644 or = (opt_restart_t
*)first_mp
->b_rptr
;
12647 for (; ire
!= NULL
; ire
= ire
->ire_next
) {
12648 if ((ire
->ire_flags
& RTF_MULTIRT
) == 0)
12650 if (!IN6_ARE_ADDR_EQUAL(&ire
->ire_addr_v6
, v6grp
))
12653 ire_gw
= ire_ftable_lookup_v6(&ire
->ire_gateway_addr_v6
, 0, 0,
12654 IRE_INTERFACE
, NULL
, NULL
, ALL_ZONES
, 0, NULL
,
12655 MATCH_IRE_RECURSIVE
| MATCH_IRE_TYPE
, ipst
);
12656 /* No resolver exists for the gateway; skip this ire. */
12657 if (ire_gw
== NULL
)
12659 index
= ire_gw
->ire_ipif
->ipif_ill
->ill_phyint
->phyint_ifindex
;
12661 * A resolver exists: we can get the interface on which we have
12662 * to apply the operation.
12664 error
= fn(connp
, checkonly
, v6grp
, index
, fmode
, v6src
,
12667 or->or_private
= CGTP_MCAST_SUCCESS
;
12669 if (ip_debug
> 0) {
12673 ksym
= kobj_getsymname((uintptr_t)fn
, &off
);
12674 ip2dbg(("ip_multirt_apply_membership_v6: "
12675 "called %s, multirt group 0x%08x via itf 0x%08x, "
12676 "error %d [success %u]\n",
12678 ntohl(V4_PART_OF_V6((*v6grp
))),
12679 ntohl(V4_PART_OF_V6(ire_gw
->ire_src_addr_v6
)),
12680 error
, or->or_private
));
12683 ire_refrele(ire_gw
);
12684 if (error
== EINPROGRESS
) {
12691 * Consider the call as successful if we succeeded on at least
12692 * one interface. Otherwise, return the last encountered error.
12694 return (or->or_private
== CGTP_MCAST_SUCCESS
? 0 : error
);
12698 *ip6_kstat_init(netstackid_t stackid
, ip6_stat_t
*ip6_statisticsp
)
12702 ip6_stat_t
template = {
12703 { "ip6_udp_fast_path", KSTAT_DATA_UINT64
},
12704 { "ip6_udp_slow_path", KSTAT_DATA_UINT64
},
12705 { "ip6_udp_fannorm", KSTAT_DATA_UINT64
},
12706 { "ip6_udp_fanmb", KSTAT_DATA_UINT64
},
12707 { "ip6_out_sw_cksum", KSTAT_DATA_UINT64
},
12708 { "ip6_in_sw_cksum", KSTAT_DATA_UINT64
},
12709 { "ip6_tcp_in_full_hw_cksum_err", KSTAT_DATA_UINT64
},
12710 { "ip6_tcp_in_part_hw_cksum_err", KSTAT_DATA_UINT64
},
12711 { "ip6_tcp_in_sw_cksum_err", KSTAT_DATA_UINT64
},
12712 { "ip6_tcp_out_sw_cksum_bytes", KSTAT_DATA_UINT64
},
12713 { "ip6_udp_in_full_hw_cksum_err", KSTAT_DATA_UINT64
},
12714 { "ip6_udp_in_part_hw_cksum_err", KSTAT_DATA_UINT64
},
12715 { "ip6_udp_in_sw_cksum_err", KSTAT_DATA_UINT64
},
12716 { "ip6_udp_out_sw_cksum_bytes", KSTAT_DATA_UINT64
},
12717 { "ip6_frag_mdt_pkt_out", KSTAT_DATA_UINT64
},
12718 { "ip6_frag_mdt_discarded", KSTAT_DATA_UINT64
},
12719 { "ip6_frag_mdt_allocfail", KSTAT_DATA_UINT64
},
12720 { "ip6_frag_mdt_addpdescfail", KSTAT_DATA_UINT64
},
12721 { "ip6_frag_mdt_allocd", KSTAT_DATA_UINT64
},
12723 ksp
= kstat_create_netstack("ip", 0, "ip6stat", "net",
12724 KSTAT_TYPE_NAMED
, sizeof (template) / sizeof (kstat_named_t
),
12725 KSTAT_FLAG_VIRTUAL
, stackid
);
12730 bcopy(&template, ip6_statisticsp
, sizeof (template));
12731 ksp
->ks_data
= (void *)ip6_statisticsp
;
12732 ksp
->ks_private
= (void *)(uintptr_t)stackid
;
12734 kstat_install(ksp
);
12739 ip6_kstat_fini(netstackid_t stackid
, kstat_t
*ksp
)
12742 ASSERT(stackid
== (netstackid_t
)(uintptr_t)ksp
->ks_private
);
12743 kstat_delete_netstack(ksp
, stackid
);
12748 * The following two functions set and get the value for the
12749 * IPV6_SRC_PREFERENCES socket option.
12752 ip6_set_src_preferences(conn_t
*connp
, uint32_t prefs
)
12755 * We only support preferences that are covered by
12756 * IPV6_PREFER_SRC_MASK.
12758 if (prefs
& ~IPV6_PREFER_SRC_MASK
)
12762 * Look for conflicting preferences or default preferences. If
12763 * both bits of a related pair are clear, the application wants the
12764 * system's default value for that pair. Both bits in a pair can't
12767 if ((prefs
& IPV6_PREFER_SRC_MIPMASK
) == 0) {
12768 prefs
|= IPV6_PREFER_SRC_MIPDEFAULT
;
12769 } else if ((prefs
& IPV6_PREFER_SRC_MIPMASK
) ==
12770 IPV6_PREFER_SRC_MIPMASK
) {
12773 if ((prefs
& IPV6_PREFER_SRC_TMPMASK
) == 0) {
12774 prefs
|= IPV6_PREFER_SRC_TMPDEFAULT
;
12775 } else if ((prefs
& IPV6_PREFER_SRC_TMPMASK
) ==
12776 IPV6_PREFER_SRC_TMPMASK
) {
12779 if ((prefs
& IPV6_PREFER_SRC_CGAMASK
) == 0) {
12780 prefs
|= IPV6_PREFER_SRC_CGADEFAULT
;
12781 } else if ((prefs
& IPV6_PREFER_SRC_CGAMASK
) ==
12782 IPV6_PREFER_SRC_CGAMASK
) {
12786 connp
->conn_src_preferences
= prefs
;
12791 ip6_get_src_preferences(conn_t
*connp
, uint32_t *val
)
12793 *val
= connp
->conn_src_preferences
;
12794 return (sizeof (connp
->conn_src_preferences
));
12798 ip6_set_pktinfo(cred_t
*cr
, conn_t
*connp
, struct in6_pktinfo
*pkti
)
12801 ip_stack_t
*ipst
= connp
->conn_netstack
->netstack_ip
;
12804 * Verify the source address and ifindex. Privileged users can use
12805 * any source address. For ancillary data the source address is
12806 * checked in ip_wput_v6.
12808 if (pkti
->ipi6_ifindex
!= 0) {
12809 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
12810 if (!phyint_exists(pkti
->ipi6_ifindex
, ipst
)) {
12811 rw_exit(&ipst
->ips_ill_g_lock
);
12814 rw_exit(&ipst
->ips_ill_g_lock
);
12816 if (!IN6_IS_ADDR_UNSPECIFIED(&pkti
->ipi6_addr
) &&
12817 secpolicy_net_rawaccess(cr
) != 0) {
12818 ire
= ire_route_lookup_v6(&pkti
->ipi6_addr
, 0, 0,
12819 (IRE_LOCAL
|IRE_LOOPBACK
), NULL
, NULL
,
12820 connp
->conn_zoneid
, NULL
, MATCH_IRE_TYPE
, ipst
);
12830 * Get the size of the IP options (including the IP headers size)
12831 * without including the AH header's size. If till_ah is B_FALSE,
12832 * and if AH header is present, dest options beyond AH header will
12833 * also be included in the returned size.
12836 ipsec_ah_get_hdr_size_v6(mblk_t
*mp
, boolean_t till_ah
)
12842 ip6_dest_t
*dsthdr
;
12843 ip6_rthdr_t
*rthdr
;
12848 ip6h
= (ip6_t
*)mp
->b_rptr
;
12849 size
= IPV6_HDR_LEN
;
12850 nexthdr
= ip6h
->ip6_nxt
;
12851 whereptr
= (uint8_t *)&ip6h
[1];
12853 /* Assume IP has already stripped it */
12854 ASSERT(nexthdr
!= IPPROTO_FRAGMENT
&& nexthdr
!= IPPROTO_RAW
);
12856 case IPPROTO_HOPOPTS
:
12857 hbhhdr
= (ip6_hbh_t
*)whereptr
;
12858 nexthdr
= hbhhdr
->ip6h_nxt
;
12859 ehdrlen
= 8 * (hbhhdr
->ip6h_len
+ 1);
12861 case IPPROTO_DSTOPTS
:
12862 dsthdr
= (ip6_dest_t
*)whereptr
;
12863 nexthdr
= dsthdr
->ip6d_nxt
;
12864 ehdrlen
= 8 * (dsthdr
->ip6d_len
+ 1);
12866 case IPPROTO_ROUTING
:
12867 rthdr
= (ip6_rthdr_t
*)whereptr
;
12868 nexthdr
= rthdr
->ip6r_nxt
;
12869 ehdrlen
= 8 * (rthdr
->ip6r_len
+ 1);
12873 ASSERT(nexthdr
== IPPROTO_AH
);
12877 * If we don't have a AH header to traverse,
12878 * return now. This happens normally for
12879 * outbound datagrams where we have not inserted
12882 if (nexthdr
!= IPPROTO_AH
) {
12887 * We don't include the AH header's size
12888 * to be symmetrical with other cases where
12889 * we either don't have a AH header (outbound)
12890 * or peek into the AH header yet (inbound and
12891 * not pulled up yet).
12893 ah
= (ah_t
*)whereptr
;
12894 nexthdr
= ah
->ah_nexthdr
;
12895 ehdrlen
= (ah
->ah_length
<< 2) + 8;
12897 if (nexthdr
== IPPROTO_DSTOPTS
) {
12898 if (whereptr
+ ehdrlen
>= mp
->b_wptr
) {
12900 * The destination options header
12901 * is not part of the first mblk.
12903 whereptr
= mp
->b_cont
->b_rptr
;
12905 whereptr
+= ehdrlen
;
12908 dsthdr
= (ip6_dest_t
*)whereptr
;
12909 ehdrlen
= 8 * (dsthdr
->ip6d_len
+ 1);
12914 whereptr
+= ehdrlen
;
12920 * Utility routine that checks if `v6srcp' is a valid address on underlying
12921 * interface `ill'. If `ipifp' is non-NULL, it's set to a held ipif
12922 * associated with `v6srcp' on success. NOTE: if this is not called from
12923 * inside the IPSQ (ill_g_lock is not held), `ill' may be removed from the
12924 * group during or after this lookup.
12927 ipif_lookup_testaddr_v6(ill_t
*ill
, const in6_addr_t
*v6srcp
, ipif_t
**ipifp
)
12931 ipif
= ipif_lookup_addr_exact_v6(v6srcp
, ill
, ill
->ill_ipst
);
12932 if (ipif
!= NULL
) {
12936 ipif_refrele(ipif
);
12940 if (ip_debug
> 2) {
12941 pr_addr_dbg("ipif_lookup_testaddr_v6: cannot find ipif for "
12942 "src %s\n", AF_INET6
, v6srcp
);