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.
30 * This file contains the interface control functions for IPv6.
33 #include <sys/types.h>
34 #include <sys/sysmacros.h>
35 #include <sys/stream.h>
37 #include <sys/stropts.h>
39 #include <sys/cmn_err.h>
40 #include <sys/kstat.h>
41 #include <sys/debug.h>
43 #include <sys/policy.h>
45 #include <sys/systm.h>
46 #include <sys/param.h>
47 #include <sys/socket.h>
48 #include <sys/isa_defs.h>
50 #include <net/if_dl.h>
51 #include <net/route.h>
52 #include <netinet/in.h>
53 #include <netinet/igmp_var.h>
54 #include <netinet/ip6.h>
55 #include <netinet/icmp6.h>
57 #include <inet/common.h>
59 #include <inet/mib2.h>
62 #include <inet/ip_multi.h>
63 #include <inet/ip_ire.h>
64 #include <inet/ip_rts.h>
65 #include <inet/ip_ndp.h>
66 #include <inet/ip_if.h>
67 #include <inet/ip6_asp.h>
68 #include <inet/ipclassifier.h>
69 #include <inet/sctp_ip.h>
71 #include <sys/tsol/tndb.h>
72 #include <sys/tsol/tnet.h>
74 static in6_addr_t ipv6_ll_template
=
75 {(uint32_t)V6_LINKLOCAL
, 0x0, 0x0, 0x0};
78 ipif_lookup_interface_v6(const in6_addr_t
*if_addr
, const in6_addr_t
*dst
,
79 queue_t
*q
, mblk_t
*mp
, ipsq_func_t func
, int *error
, ip_stack_t
*ipst
);
82 * These two functions, ipif_lookup_group_v6() and ill_lookup_group_v6(),
83 * are called when an application does not specify an interface to be
84 * used for multicast traffic. It calls ire_lookup_multi_v6() to look
85 * for an interface route for the specified multicast group. Doing
86 * this allows the administrator to add prefix routes for multicast to
87 * indicate which interface to be used for multicast traffic in the above
88 * scenario. The route could be for all multicast (ff00::/8), for a single
89 * multicast group (a /128 route) or anything in between. If there is no
90 * such multicast route, we just find any multicast capable interface and
94 ipif_lookup_group_v6(const in6_addr_t
*group
, zoneid_t zoneid
, ip_stack_t
*ipst
)
99 ire
= ire_lookup_multi_v6(group
, zoneid
, ipst
);
101 ipif
= ire
->ire_ipif
;
107 return (ipif_lookup_multicast(ipst
, zoneid
, B_TRUE
));
111 ill_lookup_group_v6(const in6_addr_t
*group
, zoneid_t zoneid
, ip_stack_t
*ipst
)
117 ire
= ire_lookup_multi_v6(group
, zoneid
, ipst
);
119 ill
= ire
->ire_ipif
->ipif_ill
;
125 ipif
= ipif_lookup_multicast(ipst
, zoneid
, B_TRUE
);
129 ill
= ipif
->ipif_ill
;
136 * Look for an ipif with the specified interface address and destination.
137 * The destination address is used only for matching point-to-point interfaces.
140 ipif_lookup_interface_v6(const in6_addr_t
*if_addr
, const in6_addr_t
*dst
,
141 queue_t
*q
, mblk_t
*mp
, ipsq_func_t func
, int *error
, ip_stack_t
*ipst
)
146 ill_walk_context_t ctx
;
152 * First match all the point-to-point interfaces
153 * before looking at non-point-to-point interfaces.
154 * This is done to avoid returning non-point-to-point
155 * ipif instead of unnumbered point-to-point ipif.
157 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
158 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
159 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
161 mutex_enter(&ill
->ill_lock
);
162 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
163 ipif
= ipif
->ipif_next
) {
164 /* Allow the ipif to be down */
165 if ((ipif
->ipif_flags
& IPIF_POINTOPOINT
) &&
166 (IN6_ARE_ADDR_EQUAL(&ipif
->ipif_v6lcl_addr
,
168 (IN6_ARE_ADDR_EQUAL(&ipif
->ipif_v6pp_dst_addr
,
170 if (IPIF_CAN_LOOKUP(ipif
)) {
171 ipif_refhold_locked(ipif
);
172 mutex_exit(&ill
->ill_lock
);
173 RELEASE_CONN_LOCK(q
);
174 rw_exit(&ipst
->ips_ill_g_lock
);
176 } else if (IPIF_CAN_WAIT(ipif
, q
)) {
177 ipsq
= ill
->ill_phyint
->phyint_ipsq
;
178 mutex_enter(&ipsq
->ipsq_lock
);
179 mutex_enter(&ipsq
->ipsq_xop
->ipx_lock
);
180 mutex_exit(&ill
->ill_lock
);
181 rw_exit(&ipst
->ips_ill_g_lock
);
182 ipsq_enq(ipsq
, q
, mp
, func
, NEW_OP
,
184 mutex_exit(&ipsq
->ipsq_xop
->ipx_lock
);
185 mutex_exit(&ipsq
->ipsq_lock
);
186 RELEASE_CONN_LOCK(q
);
188 *error
= EINPROGRESS
;
193 mutex_exit(&ill
->ill_lock
);
194 RELEASE_CONN_LOCK(q
);
196 rw_exit(&ipst
->ips_ill_g_lock
);
197 /* lookup the ipif based on interface address */
198 ipif
= ipif_lookup_addr_v6(if_addr
, NULL
, ALL_ZONES
, q
, mp
, func
,
200 ASSERT(ipif
== NULL
|| ipif
->ipif_isv6
);
205 * Common function for ipif_lookup_addr_v6() and ipif_lookup_addr_exact_v6().
208 ipif_lookup_addr_common_v6(const in6_addr_t
*addr
, ill_t
*match_ill
,
209 boolean_t match_illgrp
, zoneid_t zoneid
, queue_t
*q
, mblk_t
*mp
,
210 ipsq_func_t func
, int *error
, ip_stack_t
*ipst
)
214 boolean_t ptp
= B_FALSE
;
216 ill_walk_context_t ctx
;
221 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
223 * Repeat twice, first based on local addresses and
224 * next time for pointopoint.
227 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
228 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
229 if (match_ill
!= NULL
&& ill
!= match_ill
&&
230 (!match_illgrp
|| !IS_IN_SAME_ILLGRP(ill
, match_ill
))) {
234 mutex_enter(&ill
->ill_lock
);
235 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
236 ipif
= ipif
->ipif_next
) {
237 if (zoneid
!= ALL_ZONES
&&
238 ipif
->ipif_zoneid
!= zoneid
&&
239 ipif
->ipif_zoneid
!= ALL_ZONES
)
241 /* Allow the ipif to be down */
242 if ((!ptp
&& (IN6_ARE_ADDR_EQUAL(
243 &ipif
->ipif_v6lcl_addr
, addr
) &&
244 (ipif
->ipif_flags
& IPIF_UNNUMBERED
) == 0)) ||
245 (ptp
&& (ipif
->ipif_flags
& IPIF_POINTOPOINT
) &&
246 IN6_ARE_ADDR_EQUAL(&ipif
->ipif_v6pp_dst_addr
,
248 if (IPIF_CAN_LOOKUP(ipif
)) {
249 ipif_refhold_locked(ipif
);
250 mutex_exit(&ill
->ill_lock
);
251 RELEASE_CONN_LOCK(q
);
252 rw_exit(&ipst
->ips_ill_g_lock
);
254 } else if (IPIF_CAN_WAIT(ipif
, q
)) {
255 ipsq
= ill
->ill_phyint
->phyint_ipsq
;
256 mutex_enter(&ipsq
->ipsq_lock
);
257 mutex_enter(&ipsq
->ipsq_xop
->ipx_lock
);
258 mutex_exit(&ill
->ill_lock
);
259 rw_exit(&ipst
->ips_ill_g_lock
);
260 ipsq_enq(ipsq
, q
, mp
, func
, NEW_OP
,
262 mutex_exit(&ipsq
->ipsq_xop
->ipx_lock
);
263 mutex_exit(&ipsq
->ipsq_lock
);
264 RELEASE_CONN_LOCK(q
);
266 *error
= EINPROGRESS
;
271 mutex_exit(&ill
->ill_lock
);
272 RELEASE_CONN_LOCK(q
);
275 /* If we already did the ptp case, then we are done */
277 rw_exit(&ipst
->ips_ill_g_lock
);
287 ip_addr_exists_v6(const in6_addr_t
*addr
, zoneid_t zoneid
,
292 ill_walk_context_t ctx
;
294 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
296 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
297 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
298 mutex_enter(&ill
->ill_lock
);
299 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
300 ipif
= ipif
->ipif_next
) {
301 if (zoneid
!= ALL_ZONES
&&
302 ipif
->ipif_zoneid
!= zoneid
&&
303 ipif
->ipif_zoneid
!= ALL_ZONES
)
305 /* Allow the ipif to be down */
306 if (((IN6_ARE_ADDR_EQUAL(&ipif
->ipif_v6lcl_addr
,
308 (ipif
->ipif_flags
& IPIF_UNNUMBERED
) == 0)) ||
309 ((ipif
->ipif_flags
& IPIF_POINTOPOINT
) &&
310 IN6_ARE_ADDR_EQUAL(&ipif
->ipif_v6pp_dst_addr
,
312 mutex_exit(&ill
->ill_lock
);
313 rw_exit(&ipst
->ips_ill_g_lock
);
317 mutex_exit(&ill
->ill_lock
);
320 rw_exit(&ipst
->ips_ill_g_lock
);
325 * Lookup an ipif with the specified address. For point-to-point links we
326 * look for matches on either the destination address or the local address,
327 * but we skip the local address check if IPIF_UNNUMBERED is set. If the
328 * `match_ill' argument is non-NULL, the lookup is restricted to that ill
329 * (or illgrp if `match_ill' is in an IPMP group).
332 ipif_lookup_addr_v6(const in6_addr_t
*addr
, ill_t
*match_ill
, zoneid_t zoneid
,
333 queue_t
*q
, mblk_t
*mp
, ipsq_func_t func
, int *error
, ip_stack_t
*ipst
)
335 return (ipif_lookup_addr_common_v6(addr
, match_ill
, B_TRUE
, zoneid
, q
,
336 mp
, func
, error
, ipst
));
340 * Special abbreviated version of ipif_lookup_addr_v6() that doesn't match
341 * `match_ill' across the IPMP group. This function is only needed in some
342 * corner-cases; almost everything should use ipif_lookup_addr_v6().
345 ipif_lookup_addr_exact_v6(const in6_addr_t
*addr
, ill_t
*match_ill
,
348 ASSERT(match_ill
!= NULL
);
349 return (ipif_lookup_addr_common_v6(addr
, match_ill
, B_FALSE
, ALL_ZONES
,
350 NULL
, NULL
, NULL
, NULL
, ipst
));
354 * Look for an ipif with the specified address. For point-point links
355 * we look for matches on either the destination address and the local
356 * address, but we ignore the check on the local address if IPIF_UNNUMBERED
358 * If the `match_ill' argument is non-NULL, the lookup is restricted to that
359 * ill (or illgrp if `match_ill' is in an IPMP group).
360 * Return the zoneid for the ipif. ALL_ZONES if none found.
363 ipif_lookup_addr_zoneid_v6(const in6_addr_t
*addr
, ill_t
*match_ill
,
368 boolean_t ptp
= B_FALSE
;
369 ill_walk_context_t ctx
;
372 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
374 * Repeat twice, first based on local addresses and
375 * next time for pointopoint.
378 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
379 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
380 if (match_ill
!= NULL
&& ill
!= match_ill
&&
381 !IS_IN_SAME_ILLGRP(ill
, match_ill
)) {
384 mutex_enter(&ill
->ill_lock
);
385 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
386 ipif
= ipif
->ipif_next
) {
387 /* Allow the ipif to be down */
388 if ((!ptp
&& (IN6_ARE_ADDR_EQUAL(
389 &ipif
->ipif_v6lcl_addr
, addr
) &&
390 (ipif
->ipif_flags
& IPIF_UNNUMBERED
) == 0)) ||
391 (ptp
&& (ipif
->ipif_flags
& IPIF_POINTOPOINT
) &&
392 IN6_ARE_ADDR_EQUAL(&ipif
->ipif_v6pp_dst_addr
,
394 !(ipif
->ipif_state_flags
& IPIF_CONDEMNED
)) {
395 zoneid
= ipif
->ipif_zoneid
;
396 mutex_exit(&ill
->ill_lock
);
397 rw_exit(&ipst
->ips_ill_g_lock
);
399 * If ipif_zoneid was ALL_ZONES then we have
400 * a trusted extensions shared IP address.
401 * In that case GLOBAL_ZONEID works to send.
403 if (zoneid
== ALL_ZONES
)
404 zoneid
= GLOBAL_ZONEID
;
408 mutex_exit(&ill
->ill_lock
);
411 /* If we already did the ptp case, then we are done */
413 rw_exit(&ipst
->ips_ill_g_lock
);
421 * Perform various checks to verify that an address would make sense as a local
422 * interface address. This is currently only called when an attempt is made
423 * to set a local address.
425 * Does not allow a v4-mapped address, an address that equals the subnet
426 * anycast address, ... a multicast address, ...
429 ip_local_addr_ok_v6(const in6_addr_t
*addr
, const in6_addr_t
*subnet_mask
)
433 if (IN6_IS_ADDR_UNSPECIFIED(addr
))
434 return (B_TRUE
); /* Allow all zeros */
437 * Don't allow all zeroes or host part, but allow
440 V6_MASK_COPY(*addr
, *subnet_mask
, subnet
);
441 if (IN6_IS_ADDR_V4MAPPED(addr
) ||
442 (IN6_ARE_ADDR_EQUAL(addr
, &subnet
) &&
443 !IN6_ARE_ADDR_EQUAL(subnet_mask
, &ipv6_all_ones
)) ||
444 (IN6_IS_ADDR_V4COMPAT(addr
) && CLASSD(V4_PART_OF_V6((*addr
)))) ||
445 IN6_IS_ADDR_MULTICAST(addr
))
452 * Perform various checks to verify that an address would make sense as a
453 * remote/subnet interface address.
456 ip_remote_addr_ok_v6(const in6_addr_t
*addr
, const in6_addr_t
*subnet_mask
)
460 if (IN6_IS_ADDR_UNSPECIFIED(addr
))
461 return (B_TRUE
); /* Allow all zeros */
463 V6_MASK_COPY(*addr
, *subnet_mask
, subnet
);
464 if (IN6_IS_ADDR_V4MAPPED(addr
) ||
465 (IN6_ARE_ADDR_EQUAL(addr
, &subnet
) &&
466 !IN6_ARE_ADDR_EQUAL(subnet_mask
, &ipv6_all_ones
)) ||
467 IN6_IS_ADDR_MULTICAST(addr
) ||
468 (IN6_IS_ADDR_V4COMPAT(addr
) && CLASSD(V4_PART_OF_V6((*addr
)))))
475 * ip_rt_add_v6 is called to add an IPv6 route to the forwarding table.
476 * ipif_arg is passed in to associate it with the correct interface
477 * (for link-local destinations and gateways).
481 ip_rt_add_v6(const in6_addr_t
*dst_addr
, const in6_addr_t
*mask
,
482 const in6_addr_t
*gw_addr
, const in6_addr_t
*src_addr
, int flags
,
483 ipif_t
*ipif_arg
, ire_t
**ire_arg
, queue_t
*q
, mblk_t
*mp
, ipsq_func_t func
,
484 struct rtsa_s
*sp
, ip_stack_t
*ipst
)
487 ire_t
*gw_ire
= NULL
;
489 boolean_t ipif_refheld
= B_FALSE
;
491 int match_flags
= MATCH_IRE_TYPE
;
493 tsol_gc_t
*gc
= NULL
;
494 tsol_gcgrp_t
*gcgrp
= NULL
;
495 boolean_t gcgrp_xtraref
= B_FALSE
;
501 * Prevent routes with a zero gateway from being created (since
502 * interfaces can currently be plumbed and brought up with no assigned
505 if (IN6_IS_ADDR_UNSPECIFIED(gw_addr
))
506 return (ENETUNREACH
);
509 * If this is the case of RTF_HOST being set, then we set the netmask
510 * to all ones (regardless if one was supplied).
512 if (flags
& RTF_HOST
)
513 mask
= &ipv6_all_ones
;
516 * Get the ipif, if any, corresponding to the gw_addr
518 ipif
= ipif_lookup_interface_v6(gw_addr
, dst_addr
, q
, mp
, func
,
521 ipif_refheld
= B_TRUE
;
522 else if (error
== EINPROGRESS
) {
523 ip1dbg(("ip_rt_add_v6: null and EINPROGRESS"));
528 * GateD will attempt to create routes with a loopback interface
529 * address as the gateway and with RTF_GATEWAY set. We allow
530 * these routes to be added, but create them as interface routes
531 * since the gateway is an interface address.
533 if ((ipif
!= NULL
) && (ipif
->ipif_ire_type
== IRE_LOOPBACK
)) {
534 flags
&= ~RTF_GATEWAY
;
535 if (IN6_ARE_ADDR_EQUAL(gw_addr
, &ipv6_loopback
) &&
536 IN6_ARE_ADDR_EQUAL(dst_addr
, &ipv6_loopback
) &&
537 IN6_ARE_ADDR_EQUAL(mask
, &ipv6_all_ones
)) {
538 ire
= ire_ctable_lookup_v6(dst_addr
, 0, IRE_LOOPBACK
,
539 ipif
, ALL_ZONES
, NULL
, match_flags
, ipst
);
546 ip1dbg(("ipif_up_done: 0x%p creating IRE 0x%x"
547 "for 0x%x\n", (void *)ipif
,
549 ntohl(ipif
->ipif_lcl_addr
)));
553 &ipif
->ipif_v6src_addr
,
574 error
= ire_add(&ire
, q
, mp
, func
, B_FALSE
);
578 * In the result of failure, ire_add() will have already
579 * deleted the ire in question, so there is no need to
589 * Traditionally, interface routes are ones where RTF_GATEWAY isn't set
590 * and the gateway address provided is one of the system's interface
591 * addresses. By using the routing socket interface and supplying an
592 * RTA_IFP sockaddr with an interface index, an alternate method of
593 * specifying an interface route to be created is available which uses
594 * the interface index that specifies the outgoing interface rather than
595 * the address of an outgoing interface (which may not be able to
596 * uniquely identify an interface). When coupled with the RTF_GATEWAY
597 * flag, routes can be specified which not only specify the next-hop to
598 * be used when routing to a certain prefix, but also which outgoing
599 * interface should be used.
601 * Previously, interfaces would have unique addresses assigned to them
602 * and so the address assigned to a particular interface could be used
603 * to identify a particular interface. One exception to this was the
604 * case of an unnumbered interface (where IPIF_UNNUMBERED was set).
606 * With the advent of IPv6 and its link-local addresses, this
607 * restriction was relaxed and interfaces could share addresses between
608 * themselves. In fact, typically all of the link-local interfaces on
609 * an IPv6 node or router will have the same link-local address. In
610 * order to differentiate between these interfaces, the use of an
611 * interface index is necessary and this index can be carried inside a
612 * RTA_IFP sockaddr (which is actually a sockaddr_dl). One restriction
613 * of using the interface index, however, is that all of the ipif's that
614 * are part of an ill have the same index and so the RTA_IFP sockaddr
615 * cannot be used to differentiate between ipif's (or logical
616 * interfaces) that belong to the same ill (physical interface).
618 * For example, in the following case involving IPv4 interfaces and
621 * 192.0.2.32 255.255.255.224 192.0.2.33 U if0
622 * 192.0.2.32 255.255.255.224 192.0.2.34 U if0:1
623 * 192.0.2.32 255.255.255.224 192.0.2.35 U if0:2
625 * the ipif's corresponding to each of these interface routes can be
626 * uniquely identified by the "gateway" (actually interface address).
628 * In this case involving multiple IPv6 default routes to a particular
629 * link-local gateway, the use of RTA_IFP is necessary to specify which
630 * default route is of interest:
632 * default fe80::123:4567:89ab:cdef U if0
633 * default fe80::123:4567:89ab:cdef U if1
636 /* RTF_GATEWAY not set */
637 if (!(flags
& RTF_GATEWAY
)) {
641 ip2dbg(("ip_rt_add_v6: gateway security attributes "
642 "cannot be set with interface route\n"));
649 * As the interface index specified with the RTA_IFP sockaddr is
650 * the same for all ipif's off of an ill, the matching logic
651 * below uses MATCH_IRE_ILL if such an index was specified.
652 * This means that routes sharing the same prefix when added
653 * using a RTA_IFP sockaddr must have distinct interface
654 * indices (namely, they must be on distinct ill's).
656 * On the other hand, since the gateway address will usually be
657 * different for each ipif on the system, the matching logic
658 * uses MATCH_IRE_IPIF in the case of a traditional interface
659 * route. This means that interface routes for the same prefix
660 * can be created if they belong to distinct ipif's and if a
661 * RTA_IFP sockaddr is not present.
663 if (ipif_arg
!= NULL
) {
666 ipif_refheld
= B_FALSE
;
669 match_flags
|= MATCH_IRE_ILL
;
672 * Check the ipif corresponding to the gw_addr
675 return (ENETUNREACH
);
676 match_flags
|= MATCH_IRE_IPIF
;
679 ASSERT(ipif
!= NULL
);
681 * We check for an existing entry at this point.
683 match_flags
|= MATCH_IRE_MASK
;
684 ire
= ire_ftable_lookup_v6(dst_addr
, mask
, 0, IRE_INTERFACE
,
685 ipif
, NULL
, ALL_ZONES
, 0, NULL
, match_flags
, ipst
);
693 stq
= (ipif
->ipif_net_type
== IRE_IF_RESOLVER
)
694 ? ipif
->ipif_rq
: ipif
->ipif_wq
;
697 * Create a copy of the IRE_LOOPBACK, IRE_IF_NORESOLVER or
698 * IRE_IF_RESOLVER with the modified address and netmask.
703 &ipif
->ipif_v6src_addr
,
726 * Some software (for example, GateD and Sun Cluster) attempts
727 * to create (what amount to) IRE_PREFIX routes with the
728 * loopback address as the gateway. This is primarily done to
729 * set up prefixes with the RTF_REJECT flag set (for example,
730 * when generating aggregate routes). We also OR in the
731 * RTF_BLACKHOLE flag as these interface routes, by
732 * definition, can only be that.
734 * If the IRE type (as defined by ipif->ipif_net_type) is
735 * IRE_LOOPBACK, then we map the request into a
738 * Needless to say, the real IRE_LOOPBACK is NOT created by this
739 * routine, but rather using ire_create_v6() directly.
741 if (ipif
->ipif_net_type
== IRE_LOOPBACK
) {
742 ire
->ire_type
= IRE_IF_NORESOLVER
;
743 ire
->ire_flags
|= RTF_BLACKHOLE
;
745 error
= ire_add(&ire
, q
, mp
, func
, B_FALSE
);
749 * In the result of failure, ire_add() will have already
750 * deleted the ire in question, so there is no need to
759 ipif_refheld
= B_FALSE
;
763 * Get an interface IRE for the specified gateway.
764 * If we don't have an IRE_IF_NORESOLVER or IRE_IF_RESOLVER for the
765 * gateway, it is currently unreachable and we fail the request
769 if (ipif_arg
!= NULL
)
770 match_flags
|= MATCH_IRE_ILL
;
771 gw_ire
= ire_ftable_lookup_v6(gw_addr
, 0, 0, IRE_INTERFACE
, ipif_arg
,
772 NULL
, ALL_ZONES
, 0, NULL
, match_flags
, ipst
);
774 return (ENETUNREACH
);
777 * We create one of three types of IREs as a result of this request
778 * based on the netmask. A netmask of all ones (which is automatically
779 * assumed when RTF_HOST is set) results in an IRE_HOST being created.
780 * An all zeroes netmask implies a default route so an IRE_DEFAULT is
781 * created. Otherwise, an IRE_PREFIX route is created for the
782 * destination prefix.
784 if (IN6_ARE_ADDR_EQUAL(mask
, &ipv6_all_ones
))
786 else if (IN6_IS_ADDR_UNSPECIFIED(mask
))
791 /* check for a duplicate entry */
792 ire
= ire_ftable_lookup_v6(dst_addr
, mask
, gw_addr
, type
, ipif_arg
,
793 NULL
, ALL_ZONES
, 0, NULL
,
794 match_flags
| MATCH_IRE_MASK
| MATCH_IRE_GW
, ipst
);
801 /* Security attribute exists */
803 tsol_gcgrp_addr_t ga
;
805 /* find or create the gateway credentials group */
807 ga
.ga_addr
= *gw_addr
;
809 /* we hold reference to it upon success */
810 gcgrp
= gcgrp_lookup(&ga
, B_TRUE
);
817 * Create and add the security attribute to the group; a
818 * reference to the group is made upon allocating a new
819 * entry successfully. If it finds an already-existing
820 * entry for the security attribute in the group, it simply
821 * returns it and no new reference is made to the group.
823 gc
= gc_create(sp
, gcgrp
, &gcgrp_xtraref
);
825 /* release reference held by gcgrp_lookup */
826 GCGRP_REFRELE(gcgrp
);
832 /* Create the IRE. */
834 dst_addr
, /* dest address */
836 /* src address assigned by the caller? */
837 (((flags
& RTF_SETSRC
) && !IN6_IS_ADDR_UNSPECIFIED(src_addr
)) ?
839 gw_addr
, /* gateway address */
840 &gw_ire
->ire_max_frag
,
841 NULL
, /* no src nce */
842 NULL
, /* no recv-from queue */
843 NULL
, /* no send-to queue */
844 (ushort_t
)type
, /* IRE type */
850 &gw_ire
->ire_uinfo
, /* Inherit ULP info from gw */
851 gc
, /* security attribute */
856 * The ire holds a reference to the 'gc' and the 'gc' holds a
857 * reference to the 'gcgrp'. We can now release the extra reference
858 * the 'gcgrp' acquired in the gcgrp_lookup, if it was not used.
861 GCGRP_REFRELE(gcgrp
);
870 * POLICY: should we allow an RTF_HOST with address INADDR_ANY?
871 * SUN/OS socket stuff does but do we really want to allow ::0 ?
874 /* Add the new IRE. */
875 error
= ire_add(&ire
, q
, mp
, func
, B_FALSE
);
877 * In the result of failure, ire_add() will have already
878 * deleted the ire in question, so there is no need to
886 if (flags
& RTF_MULTIRT
) {
888 * Invoke the CGTP (multirouting) filtering module
889 * to add the dst address in the filtering database.
890 * Replicated inbound packets coming from that address
891 * will be filtered to discard the duplicates.
892 * It is not necessary to call the CGTP filter hook
893 * when the dst address is a multicast, because an
894 * IP source address cannot be a multicast.
896 if (ipst
->ips_ip_cgtp_filter_ops
!= NULL
&&
897 !IN6_IS_ADDR_MULTICAST(&(ire
->ire_addr_v6
))) {
900 res
= ipst
->ips_ip_cgtp_filter_ops
->cfo_add_dest_v6(
901 ipst
->ips_netstack
->netstack_stackid
,
903 &ire
->ire_gateway_addr_v6
,
904 &ire
->ire_src_addr_v6
,
905 &gw_ire
->ire_src_addr_v6
);
915 * Now that the prefix IRE entry has been created, delete any
916 * existing gateway IRE cache entries as well as any IRE caches
917 * using the gateway, and force them to be created through
921 ASSERT(gcgrp
!= NULL
);
922 ire_clookup_delete_cache_gw_v6(gw_addr
, ALL_ZONES
, ipst
);
926 if (gw_ire
!= NULL
) {
933 * Save enough information so that we can recreate the IRE if
934 * the interface goes down and then up. The metrics associated
935 * with the route will be saved as well when rts_setmetrics() is
936 * called after the IRE has been created. In the case where
937 * memory cannot be allocated, none of this information will be
940 save_mp
= allocb(sizeof (ifrt_t
), BPRI_MED
);
941 if (save_mp
!= NULL
) {
944 save_mp
->b_wptr
+= sizeof (ifrt_t
);
945 ifrt
= (ifrt_t
*)save_mp
->b_rptr
;
946 bzero(ifrt
, sizeof (ifrt_t
));
947 ifrt
->ifrt_type
= ire
->ire_type
;
948 ifrt
->ifrt_v6addr
= ire
->ire_addr_v6
;
949 mutex_enter(&ire
->ire_lock
);
950 ifrt
->ifrt_v6gateway_addr
= ire
->ire_gateway_addr_v6
;
951 ifrt
->ifrt_v6src_addr
= ire
->ire_src_addr_v6
;
952 mutex_exit(&ire
->ire_lock
);
953 ifrt
->ifrt_v6mask
= ire
->ire_mask_v6
;
954 ifrt
->ifrt_flags
= ire
->ire_flags
;
955 ifrt
->ifrt_max_frag
= ire
->ire_max_frag
;
956 mutex_enter(&ipif
->ipif_saved_ire_lock
);
957 save_mp
->b_cont
= ipif
->ipif_saved_ire_mp
;
958 ipif
->ipif_saved_ire_mp
= save_mp
;
959 ipif
->ipif_saved_ire_cnt
++;
960 mutex_exit(&ipif
->ipif_saved_ire_lock
);
963 if (ire_arg
!= NULL
) {
965 * Store the ire that was successfully added into where ire_arg
966 * points to so that callers don't have to look it up
967 * themselves (but they are responsible for ire_refrele()ing
968 * the ire when they are finished with it).
972 ire_refrele(ire
); /* Held in ire_add */
980 * ip_rt_delete_v6 is called to delete an IPv6 route.
981 * ipif_arg is passed in to associate it with the correct interface
982 * (for link-local destinations and gateways).
986 ip_rt_delete_v6(const in6_addr_t
*dst_addr
, const in6_addr_t
*mask
,
987 const in6_addr_t
*gw_addr
, uint_t rtm_addrs
, int flags
, ipif_t
*ipif_arg
,
988 queue_t
*q
, mblk_t
*mp
, ipsq_func_t func
, ip_stack_t
*ipst
)
993 uint_t match_flags
= MATCH_IRE_TYPE
;
995 boolean_t ipif_refheld
= B_FALSE
;
998 * If this is the case of RTF_HOST being set, then we set the netmask
999 * to all ones. Otherwise, we use the netmask if one was supplied.
1001 if (flags
& RTF_HOST
) {
1002 mask
= &ipv6_all_ones
;
1003 match_flags
|= MATCH_IRE_MASK
;
1004 } else if (rtm_addrs
& RTA_NETMASK
) {
1005 match_flags
|= MATCH_IRE_MASK
;
1009 * Note that RTF_GATEWAY is never set on a delete, therefore
1010 * we check if the gateway address is one of our interfaces first,
1011 * and fall back on RTF_GATEWAY routes.
1013 * This makes it possible to delete an original
1014 * IRE_IF_NORESOLVER/IRE_IF_RESOLVER - consistent with SunOS 4.1.
1016 * As the interface index specified with the RTA_IFP sockaddr is the
1017 * same for all ipif's off of an ill, the matching logic below uses
1018 * MATCH_IRE_ILL if such an index was specified. This means a route
1019 * sharing the same prefix and interface index as the the route
1020 * intended to be deleted might be deleted instead if a RTA_IFP sockaddr
1021 * is specified in the request.
1023 * On the other hand, since the gateway address will usually be
1024 * different for each ipif on the system, the matching logic
1025 * uses MATCH_IRE_IPIF in the case of a traditional interface
1026 * route. This means that interface routes for the same prefix can be
1027 * uniquely identified if they belong to distinct ipif's and if a
1028 * RTA_IFP sockaddr is not present.
1030 * For more detail on specifying routes by gateway address and by
1031 * interface index, see the comments in ip_rt_add_v6().
1033 ipif
= ipif_lookup_interface_v6(gw_addr
, dst_addr
, q
, mp
, func
, &err
,
1036 ipif_refheld
= B_TRUE
;
1037 if (ipif_arg
!= NULL
) {
1039 ipif_refheld
= B_FALSE
;
1041 match_flags
|= MATCH_IRE_ILL
;
1043 match_flags
|= MATCH_IRE_IPIF
;
1046 if (ipif
->ipif_ire_type
== IRE_LOOPBACK
)
1047 ire
= ire_ctable_lookup_v6(dst_addr
, 0, IRE_LOOPBACK
,
1048 ipif
, ALL_ZONES
, NULL
, match_flags
, ipst
);
1050 ire
= ire_ftable_lookup_v6(dst_addr
, mask
, 0,
1051 IRE_INTERFACE
, ipif
, NULL
, ALL_ZONES
, 0, NULL
,
1053 } else if (err
== EINPROGRESS
) {
1060 * At this point, the gateway address is not one of our own
1061 * addresses or a matching interface route was not found. We
1062 * set the IRE type to lookup based on whether
1063 * this is a host route, a default route or just a prefix.
1065 * If an ipif_arg was passed in, then the lookup is based on an
1066 * interface index so MATCH_IRE_ILL is added to match_flags.
1067 * In any case, MATCH_IRE_IPIF is cleared and MATCH_IRE_GW is
1068 * set as the route being looked up is not a traditional
1071 match_flags
&= ~MATCH_IRE_IPIF
;
1072 match_flags
|= MATCH_IRE_GW
;
1073 if (ipif_arg
!= NULL
)
1074 match_flags
|= MATCH_IRE_ILL
;
1075 if (IN6_ARE_ADDR_EQUAL(mask
, &ipv6_all_ones
))
1077 else if (IN6_IS_ADDR_UNSPECIFIED(mask
))
1081 ire
= ire_ftable_lookup_v6(dst_addr
, mask
, gw_addr
, type
,
1082 ipif_arg
, NULL
, ALL_ZONES
, 0, NULL
, match_flags
, ipst
);
1087 ipif_refheld
= B_FALSE
;
1092 if (ire
->ire_flags
& RTF_MULTIRT
) {
1094 * Invoke the CGTP (multirouting) filtering module
1095 * to remove the dst address from the filtering database.
1096 * Packets coming from that address will no longer be
1097 * filtered to remove duplicates.
1099 if (ipst
->ips_ip_cgtp_filter_ops
!= NULL
) {
1100 err
= ipst
->ips_ip_cgtp_filter_ops
->cfo_del_dest_v6(
1101 ipst
->ips_netstack
->netstack_stackid
,
1102 &ire
->ire_addr_v6
, &ire
->ire_gateway_addr_v6
);
1106 ipif
= ire
->ire_ipif
;
1111 in6_addr_t gw_addr_v6
;
1113 /* Remove from ipif_saved_ire_mp list if it is there */
1114 mutex_enter(&ire
->ire_lock
);
1115 gw_addr_v6
= ire
->ire_gateway_addr_v6
;
1116 mutex_exit(&ire
->ire_lock
);
1117 mutex_enter(&ipif
->ipif_saved_ire_lock
);
1118 for (mpp
= &ipif
->ipif_saved_ire_mp
; *mpp
!= NULL
;
1119 mpp
= &(*mpp
)->b_cont
) {
1121 * On a given ipif, the triple of address, gateway and
1122 * mask is unique for each saved IRE (in the case of
1123 * ordinary interface routes, the gateway address is
1127 ifrt
= (ifrt_t
*)mp
->b_rptr
;
1128 if (IN6_ARE_ADDR_EQUAL(&ifrt
->ifrt_v6addr
,
1129 &ire
->ire_addr_v6
) &&
1130 IN6_ARE_ADDR_EQUAL(&ifrt
->ifrt_v6gateway_addr
,
1132 IN6_ARE_ADDR_EQUAL(&ifrt
->ifrt_v6mask
,
1133 &ire
->ire_mask_v6
)) {
1135 ipif
->ipif_saved_ire_cnt
--;
1140 mutex_exit(&ipif
->ipif_saved_ire_lock
);
1148 * Derive an interface id from the link layer address.
1151 ill_setdefaulttoken(ill_t
*ill
)
1153 if (!ill
->ill_manual_token
&& ill
->ill_phys_addr_length
!= 0) {
1154 bzero(&ill
->ill_token
, sizeof (ill
->ill_token
));
1155 MEDIA_V6INTFID(ill
->ill_media
, ill
, &ill
->ill_token
);
1156 ill
->ill_token_length
= IPV6_TOKEN_LEN
;
1161 ill_setdesttoken(ill_t
*ill
)
1163 bzero(&ill
->ill_dest_token
, sizeof (ill
->ill_dest_token
));
1164 MEDIA_V6DESTINTFID(ill
->ill_media
, ill
, &ill
->ill_dest_token
);
1168 * Create a link-local address from a token.
1171 ipif_get_linklocal(in6_addr_t
*dest
, const in6_addr_t
*token
)
1175 for (i
= 0; i
< 4; i
++) {
1176 dest
->s6_addr32
[i
] =
1177 token
->s6_addr32
[i
] | ipv6_ll_template
.s6_addr32
[i
];
1182 * Set a default IPv6 address for a 6to4 tunnel interface 2002:<tsrc>::1/16
1185 ipif_set6to4addr(ipif_t
*ipif
)
1187 ill_t
*ill
= ipif
->ipif_ill
;
1188 struct in_addr v4phys
;
1190 ASSERT(ill
->ill_mactype
== DL_6TO4
);
1191 ASSERT(ill
->ill_phys_addr_length
== sizeof (struct in_addr
));
1192 ASSERT(ipif
->ipif_isv6
);
1194 if (ipif
->ipif_flags
& IPIF_UP
)
1197 (void) ip_plen_to_mask_v6(16, &ipif
->ipif_v6net_mask
);
1198 bcopy(ill
->ill_phys_addr
, &v4phys
, sizeof (struct in_addr
));
1199 IN6_V4ADDR_TO_6TO4(&v4phys
, &ipif
->ipif_v6lcl_addr
);
1200 ipif
->ipif_v6src_addr
= ipif
->ipif_v6lcl_addr
;
1201 V6_MASK_COPY(ipif
->ipif_v6lcl_addr
, ipif
->ipif_v6net_mask
,
1202 ipif
->ipif_v6subnet
);
1206 * Is it not possible to set the link local address?
1207 * The address can be set if the token is set, and the token
1209 * Return B_TRUE if the address can't be set, or B_FALSE if it can.
1212 ipif_cant_setlinklocal(ipif_t
*ipif
)
1214 ill_t
*ill
= ipif
->ipif_ill
;
1216 if (IN6_IS_ADDR_UNSPECIFIED(&ill
->ill_token
) ||
1217 ill
->ill_token_length
> IPV6_ABITS
- IPV6_LL_PREFIXLEN
)
1224 * Generate a link-local address from the token.
1227 ipif_setlinklocal(ipif_t
*ipif
)
1229 ill_t
*ill
= ipif
->ipif_ill
;
1232 ASSERT(IAM_WRITER_ILL(ill
));
1235 * ill_manual_linklocal is set when the link-local address was
1236 * manually configured.
1238 if (ill
->ill_manual_linklocal
)
1242 * IPv6 interfaces over 6to4 tunnels are special. They do not have
1243 * link-local addresses, but instead have a single automatically
1244 * generated global address.
1246 if (ill
->ill_mactype
== DL_6TO4
) {
1247 ipif_set6to4addr(ipif
);
1251 if (ipif_cant_setlinklocal(ipif
))
1254 ov6addr
= ipif
->ipif_v6lcl_addr
;
1255 ipif_get_linklocal(&ipif
->ipif_v6lcl_addr
, &ill
->ill_token
);
1256 sctp_update_ipif_addr(ipif
, ov6addr
);
1257 (void) ip_plen_to_mask_v6(IPV6_LL_PREFIXLEN
, &ipif
->ipif_v6net_mask
);
1258 if (IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6pp_dst_addr
)) {
1259 V6_MASK_COPY(ipif
->ipif_v6lcl_addr
, ipif
->ipif_v6net_mask
,
1260 ipif
->ipif_v6subnet
);
1263 if (ipif
->ipif_flags
& IPIF_NOLOCAL
) {
1264 ipif
->ipif_v6src_addr
= ipv6_all_zeros
;
1266 ipif
->ipif_v6src_addr
= ipif
->ipif_v6lcl_addr
;
1271 * Set the destination link-local address for a point-to-point IPv6
1272 * interface with a destination interface id (IP tunnels are such
1276 ipif_setdestlinklocal(ipif_t
*ipif
)
1278 ill_t
*ill
= ipif
->ipif_ill
;
1280 ASSERT(IAM_WRITER_ILL(ill
));
1281 if (IN6_IS_ADDR_UNSPECIFIED(&ill
->ill_dest_token
))
1283 ipif_get_linklocal(&ipif
->ipif_v6pp_dst_addr
, &ill
->ill_dest_token
);
1284 ipif
->ipif_v6subnet
= ipif
->ipif_v6pp_dst_addr
;
1288 * This function sets up the multicast mappings in NDP.
1289 * Unlike ARP, there are no mapping_mps here. We delete the
1290 * mapping nces and add a new one.
1292 * Returns non-zero on error and 0 on success.
1295 ipif_ndp_setup_multicast(ipif_t
*ipif
, nce_t
**ret_nce
)
1297 ill_t
*ill
= ipif
->ipif_ill
;
1298 in6_addr_t v6_mcast_addr
= {(uint32_t)V6_MCAST
, 0, 0, 0};
1299 in6_addr_t v6_mcast_mask
= {(uint32_t)V6_MCAST
, 0, 0, 0};
1300 in6_addr_t v6_extract_mask
;
1301 uchar_t
*phys_addr
, *bphys_addr
, *alloc_phys
;
1304 phyint_t
*phyi
= ill
->ill_phyint
;
1305 uint32_t hw_extract_start
;
1306 dl_unitdata_req_t
*dlur
;
1307 ip_stack_t
*ipst
= ill
->ill_ipst
;
1309 if (ret_nce
!= NULL
)
1312 if (ipif
->ipif_flags
& IPIF_POINTOPOINT
)
1316 * IPMP meta-interfaces don't have any inherent multicast mappings,
1317 * and instead use the ones on the underlying interfaces.
1323 * Delete the mapping nce. Normally these should not exist
1324 * as a previous ipif_down -> ipif_ndp_down should have deleted
1325 * all the nces. But they can exist if ip_rput_dlpi_writer
1326 * calls this when PHYI_MULTI_BCAST is set. Mappings are always
1327 * tied to the underlying ill, so don't match across the illgrp.
1329 mnce
= ndp_lookup_v6(ill
, B_FALSE
, &v6_mcast_addr
, B_FALSE
);
1337 * Get media specific v6 mapping information. Note that
1338 * nd_lla_len can be 0 for tunnels.
1340 alloc_phys
= kmem_alloc(ill
->ill_nd_lla_len
, KM_NOSLEEP
);
1341 if ((alloc_phys
== NULL
) && (ill
->ill_nd_lla_len
!= 0))
1344 * Determine the broadcast address.
1346 dlur
= (dl_unitdata_req_t
*)ill
->ill_bcast_mp
->b_rptr
;
1347 if (ill
->ill_sap_length
< 0)
1348 bphys_addr
= (uchar_t
*)dlur
+ dlur
->dl_dest_addr_offset
;
1350 bphys_addr
= (uchar_t
*)dlur
+
1351 dlur
->dl_dest_addr_offset
+ ill
->ill_sap_length
;
1354 * Check PHYI_MULTI_BCAST and possible length of physical
1355 * address to determine if we use the mapping or the
1356 * broadcast address.
1358 if ((phyi
->phyint_flags
& PHYI_MULTI_BCAST
) ||
1359 (!MEDIA_V6MINFO(ill
->ill_media
, ill
->ill_nd_lla_len
,
1360 bphys_addr
, alloc_phys
, &hw_extract_start
,
1361 &v6_extract_mask
))) {
1362 if (ill
->ill_phys_addr_length
> IP_MAX_HW_LEN
) {
1363 kmem_free(alloc_phys
, ill
->ill_nd_lla_len
);
1366 /* Use the link-layer broadcast address for MULTI_BCAST */
1367 phys_addr
= bphys_addr
;
1368 bzero(&v6_extract_mask
, sizeof (v6_extract_mask
));
1369 hw_extract_start
= ill
->ill_nd_lla_len
;
1371 phys_addr
= alloc_phys
;
1373 if ((ipif
->ipif_flags
& IPIF_BROADCAST
) ||
1374 (ill
->ill_flags
& ILLF_MULTICAST
) ||
1375 (phyi
->phyint_flags
& PHYI_MULTI_BCAST
)) {
1376 mutex_enter(&ipst
->ips_ndp6
->ndp_g_lock
);
1377 err
= ndp_add_v6(ill
,
1379 &v6_mcast_addr
, /* v6 address */
1380 &v6_mcast_mask
, /* v6 mask */
1383 NCE_F_MAPPING
| NCE_F_PERMANENT
| NCE_F_NONUD
,
1386 mutex_exit(&ipst
->ips_ndp6
->ndp_g_lock
);
1388 if (ret_nce
!= NULL
) {
1395 kmem_free(alloc_phys
, ill
->ill_nd_lla_len
);
1400 * Get the resolver set up for a new ipif. (Always called as writer.)
1403 ipif_ndp_up(ipif_t
*ipif
, boolean_t initial
)
1405 ill_t
*ill
= ipif
->ipif_ill
;
1409 boolean_t added_ipif
= B_FALSE
;
1411 ASSERT(IAM_WRITER_ILL(ill
));
1412 ip1dbg(("ipif_ndp_up(%s:%u)\n", ill
->ill_name
, ipif
->ipif_id
));
1415 * ND not supported on XRESOLV interfaces. If ND support (multicast)
1416 * added later, take out this check.
1418 if ((ill
->ill_flags
& ILLF_XRESOLV
) ||
1419 IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6lcl_addr
) ||
1420 (!(ill
->ill_net_type
& IRE_INTERFACE
))) {
1421 ipif
->ipif_addr_ready
= 1;
1426 * Need to setup multicast mapping only when the first
1427 * interface is coming UP.
1429 if (ill
->ill_ipif_up_count
== 0 &&
1430 (ill
->ill_flags
& ILLF_MULTICAST
)) {
1432 * We set the multicast before setting up the mapping for
1433 * local address because ipif_ndp_setup_multicast does
1434 * ndp_walk to delete nces which will delete the mapping
1435 * for local address also if we added the mapping for
1436 * local address first.
1438 err
= ipif_ndp_setup_multicast(ipif
, &mnce
);
1443 if ((ipif
->ipif_flags
& (IPIF_UNNUMBERED
|IPIF_NOLOCAL
)) == 0) {
1446 uchar_t
*hw_addr
= NULL
;
1448 ipmp_illgrp_t
*illg
= ill
->ill_grp
;
1450 /* Permanent entries don't need NUD */
1451 flags
= NCE_F_PERMANENT
| NCE_F_NONUD
;
1452 if (ill
->ill_flags
& ILLF_ROUTER
)
1453 flags
|= NCE_F_ISROUTER
;
1455 if (ipif
->ipif_flags
& IPIF_ANYCAST
)
1456 flags
|= NCE_F_ANYCAST
;
1459 ASSERT(ill
->ill_net_type
== IRE_IF_RESOLVER
);
1461 * If we're here via ipif_up(), then the ipif won't be
1462 * bound yet -- add it to the group, which will bind
1463 * it if possible. (We would add it in ipif_up(), but
1464 * deleting on failure there is gruesome.) If we're
1465 * here via ipmp_ill_bind_ipif(), then the ipif has
1466 * already been added to the group and we just need to
1469 if ((bound_ill
= ipmp_ipif_bound_ill(ipif
)) == NULL
) {
1470 bound_ill
= ipmp_illgrp_add_ipif(illg
, ipif
);
1471 if (bound_ill
== NULL
) {
1473 * We couldn't bind the ipif to an ill
1474 * yet, so we have nothing to publish.
1475 * Set ipif_addr_ready so that this
1476 * address can be used locally for now.
1477 * The routing socket message will be
1478 * sent from ipif_up_done_v6().
1480 ipif
->ipif_addr_ready
= 1;
1483 added_ipif
= B_TRUE
;
1485 hw_addr
= bound_ill
->ill_nd_lla
;
1488 if (ill
->ill_net_type
== IRE_IF_RESOLVER
)
1489 hw_addr
= ill
->ill_nd_lla
;
1493 * If this is an initial bring-up (or the ipif was never
1494 * completely brought up), do DAD. Otherwise, we're here
1495 * because IPMP has rebound an address to this ill: send
1496 * unsolicited advertisements to inform others.
1498 if (initial
|| !ipif
->ipif_addr_ready
) {
1501 state
= ND_REACHABLE
;
1502 flags
|= NCE_F_UNSOL_ADV
;
1506 * Create an nce for the local address. We pass a match_illgrp
1507 * of B_TRUE because the local address must be unique across
1508 * the illgrp, and the existence of an nce with nce_ill set
1509 * to any ill in the group is indicative of a duplicate address
1511 err
= ndp_lookup_then_add_v6(bound_ill
,
1514 &ipif
->ipif_v6lcl_addr
,
1523 ip1dbg(("ipif_ndp_up: NCE created for %s\n",
1525 ipif
->ipif_addr_ready
= 1;
1526 ipif
->ipif_added_nce
= 1;
1527 nce
->nce_ipif_cnt
++;
1530 ip1dbg(("ipif_ndp_up: running DAD now for %s\n",
1532 ipif
->ipif_added_nce
= 1;
1533 nce
->nce_ipif_cnt
++;
1536 ip1dbg(("ipif_ndp_up: NCE already exists for %s\n",
1538 if (!(nce
->nce_flags
& NCE_F_PERMANENT
)) {
1544 if ((ipif
->ipif_flags
& IPIF_POINTOPOINT
) == 0) {
1549 * Duplicate local addresses are permissible for
1550 * IPIF_POINTOPOINT interfaces which will get marked
1551 * IPIF_UNNUMBERED later in
1552 * ip_addr_availability_check().
1554 * The nce_ipif_cnt field tracks the number of
1555 * ipifs that have nce_addr as their local address.
1557 ipif
->ipif_addr_ready
= 1;
1558 ipif
->ipif_added_nce
= 1;
1559 nce
->nce_ipif_cnt
++;
1562 ip1dbg(("ipif_ndp_up: NCE creation failed for %s\n",
1567 /* No local NCE for this entry */
1568 ipif
->ipif_addr_ready
= 1;
1581 ipmp_illgrp_del_ipif(ill
->ill_grp
, ipif
);
1586 /* Remove all cache entries for this logical interface */
1588 ipif_ndp_down(ipif_t
*ipif
)
1591 ill_t
*ill
= ipif
->ipif_ill
;
1593 ASSERT(IAM_WRITER_ILL(ill
));
1595 if (ipif
->ipif_isv6
) {
1596 if (ipif
->ipif_added_nce
) {
1598 * For IPMP, `ill' can be the IPMP ill but the NCE will
1599 * always be tied to an underlying IP interface, so we
1600 * match across the illgrp. This is safe since we
1601 * ensure uniqueness across the group in ipif_ndp_up().
1603 nce
= ndp_lookup_v6(ill
, B_TRUE
, &ipif
->ipif_v6lcl_addr
,
1606 if (--nce
->nce_ipif_cnt
== 0)
1607 ndp_delete(nce
); /* last ipif for nce */
1610 ipif
->ipif_added_nce
= 0;
1614 * Make IPMP aware of the deleted data address.
1617 ipmp_illgrp_del_ipif(ill
->ill_grp
, ipif
);
1621 * Remove mapping and all other nces dependent on this ill
1622 * when the last ipif is going away.
1624 if (ill
->ill_ipif_up_count
== 0)
1625 ndp_walk(ill
, (pfi_t
)ndp_delete_per_ill
, ill
, ill
->ill_ipst
);
1629 * Used when an interface comes up to recreate any extra routes on this
1633 ipif_recover_ire_v6(ipif_t
*ipif
)
1636 ire_t
**ipif_saved_irep
;
1638 ip_stack_t
*ipst
= ipif
->ipif_ill
->ill_ipst
;
1640 ip1dbg(("ipif_recover_ire_v6(%s:%u)", ipif
->ipif_ill
->ill_name
,
1643 ASSERT(ipif
->ipif_isv6
);
1645 mutex_enter(&ipif
->ipif_saved_ire_lock
);
1646 ipif_saved_irep
= (ire_t
**)kmem_zalloc(sizeof (ire_t
*) *
1647 ipif
->ipif_saved_ire_cnt
, KM_NOSLEEP
);
1648 if (ipif_saved_irep
== NULL
) {
1649 mutex_exit(&ipif
->ipif_saved_ire_lock
);
1653 irep
= ipif_saved_irep
;
1655 for (mp
= ipif
->ipif_saved_ire_mp
; mp
!= NULL
; mp
= mp
->b_cont
) {
1660 in6_addr_t
*src_addr
;
1661 in6_addr_t
*gateway_addr
;
1662 char buf
[INET6_ADDRSTRLEN
];
1666 * When the ire was initially created and then added in
1667 * ip_rt_add_v6(), it was created either using
1668 * ipif->ipif_net_type in the case of a traditional interface
1669 * route, or as one of the IRE_OFFSUBNET types (with the
1670 * exception of IRE_HOST type redirect ire which is created by
1671 * icmp_redirect_v6() and which we don't need to save or
1672 * recover). In the case where ipif->ipif_net_type was
1673 * IRE_LOOPBACK, ip_rt_add_v6() will update the ire_type to
1674 * IRE_IF_NORESOLVER before calling ire_add_v6() to satisfy
1675 * software like GateD and Sun Cluster which creates routes
1676 * using the the loopback interface's address as a gateway.
1678 * As ifrt->ifrt_type reflects the already updated ire_type,
1679 * ire_create_v6() will be called in the same way here as in
1680 * ip_rt_add_v6(), namely using ipif->ipif_net_type when the
1681 * route looks like a traditional interface route (where
1682 * ifrt->ifrt_type & IRE_INTERFACE is true) and otherwise
1683 * using the saved ifrt->ifrt_type. This means that in
1684 * the case where ipif->ipif_net_type is IRE_LOOPBACK,
1685 * the ire created by ire_create_v6() will be an IRE_LOOPBACK,
1686 * it will then be turned into an IRE_IF_NORESOLVER and then
1687 * added by ire_add_v6().
1689 ifrt
= (ifrt_t
*)mp
->b_rptr
;
1690 if (ifrt
->ifrt_type
& IRE_INTERFACE
) {
1692 stq
= (ipif
->ipif_net_type
== IRE_IF_RESOLVER
)
1693 ? ipif
->ipif_rq
: ipif
->ipif_wq
;
1694 src_addr
= (ifrt
->ifrt_flags
& RTF_SETSRC
)
1695 ? &ifrt
->ifrt_v6src_addr
1696 : &ipif
->ipif_v6src_addr
;
1697 gateway_addr
= NULL
;
1698 type
= ipif
->ipif_net_type
;
1702 src_addr
= (ifrt
->ifrt_flags
& RTF_SETSRC
)
1703 ? &ifrt
->ifrt_v6src_addr
: NULL
;
1704 gateway_addr
= &ifrt
->ifrt_v6gateway_addr
;
1705 type
= ifrt
->ifrt_type
;
1709 * Create a copy of the IRE with the saved address and netmask.
1711 ip1dbg(("ipif_recover_ire_v6: creating IRE %s (%d) for %s/%d\n",
1712 ip_nv_lookup(ire_nv_tbl
, ifrt
->ifrt_type
), ifrt
->ifrt_type
,
1713 inet_ntop(AF_INET6
, &ifrt
->ifrt_v6addr
, buf
, sizeof (buf
)),
1714 ip_mask_to_plen_v6(&ifrt
->ifrt_v6mask
)));
1715 ire
= ire_create_v6(
1720 &ifrt
->ifrt_max_frag
,
1730 &ifrt
->ifrt_iulp_info
,
1735 mutex_exit(&ipif
->ipif_saved_ire_lock
);
1736 kmem_free(ipif_saved_irep
,
1737 ipif
->ipif_saved_ire_cnt
* sizeof (ire_t
*));
1742 * Some software (for example, GateD and Sun Cluster) attempts
1743 * to create (what amount to) IRE_PREFIX routes with the
1744 * loopback address as the gateway. This is primarily done to
1745 * set up prefixes with the RTF_REJECT flag set (for example,
1746 * when generating aggregate routes.)
1748 * If the IRE type (as defined by ipif->ipif_net_type) is
1749 * IRE_LOOPBACK, then we map the request into a
1750 * IRE_IF_NORESOLVER.
1752 if (ipif
->ipif_net_type
== IRE_LOOPBACK
)
1753 ire
->ire_type
= IRE_IF_NORESOLVER
;
1755 * ire held by ire_add, will be refreled' in ipif_up_done
1758 (void) ire_add(&ire
, NULL
, NULL
, NULL
, B_FALSE
);
1761 ip1dbg(("ipif_recover_ire_v6: added ire %p\n", (void *)ire
));
1763 mutex_exit(&ipif
->ipif_saved_ire_lock
);
1764 return (ipif_saved_irep
);
1768 * Return the scope of the given IPv6 address. If the address is an
1769 * IPv4 mapped IPv6 address, return the scope of the corresponding
1773 ip_addr_scope_v6(const in6_addr_t
*addr
)
1775 static in6_addr_t ipv6loopback
= IN6ADDR_LOOPBACK_INIT
;
1777 if (IN6_IS_ADDR_V4MAPPED(addr
)) {
1778 in_addr_t v4addr_h
= ntohl(V4_PART_OF_V6((*addr
)));
1779 if ((v4addr_h
>> IN_CLASSA_NSHIFT
) == IN_LOOPBACKNET
||
1780 (v4addr_h
& IN_AUTOCONF_MASK
) == IN_AUTOCONF_NET
)
1781 return (IP6_SCOPE_LINKLOCAL
);
1782 if ((v4addr_h
& IN_PRIVATE8_MASK
) == IN_PRIVATE8_NET
||
1783 (v4addr_h
& IN_PRIVATE12_MASK
) == IN_PRIVATE12_NET
||
1784 (v4addr_h
& IN_PRIVATE16_MASK
) == IN_PRIVATE16_NET
)
1785 return (IP6_SCOPE_SITELOCAL
);
1786 return (IP6_SCOPE_GLOBAL
);
1789 if (IN6_IS_ADDR_MULTICAST(addr
))
1790 return (IN6_ADDR_MC_SCOPE(addr
));
1792 /* link-local and loopback addresses are of link-local scope */
1793 if (IN6_IS_ADDR_LINKLOCAL(addr
) ||
1794 IN6_ARE_ADDR_EQUAL(addr
, &ipv6loopback
))
1795 return (IP6_SCOPE_LINKLOCAL
);
1796 if (IN6_IS_ADDR_SITELOCAL(addr
))
1797 return (IP6_SCOPE_SITELOCAL
);
1798 return (IP6_SCOPE_GLOBAL
);
1803 * Returns the length of the common prefix of a1 and a2, as per
1804 * CommonPrefixLen() defined in RFC 3484.
1807 ip_common_prefix_v6(const in6_addr_t
*a1
, const in6_addr_t
*a2
)
1810 uint32_t a1val
, a2val
, mask
;
1812 for (i
= 0; i
< 4; i
++) {
1813 if ((a1val
= a1
->s6_addr32
[i
]) != (a2val
= a2
->s6_addr32
[i
])) {
1817 while (!(a1val
& mask
)) {
1824 return (IPV6_ABITS
);
1827 #define IPIF_VALID_IPV6_SOURCE(ipif) \
1828 (((ipif)->ipif_flags & IPIF_UP) && \
1829 !((ipif)->ipif_flags & (IPIF_NOLOCAL|IPIF_ANYCAST)) && \
1830 (ipif)->ipif_addr_ready)
1832 /* source address candidate */
1833 typedef struct candidate
{
1835 /* The properties of this candidate */
1836 boolean_t cand_isdst
;
1837 boolean_t cand_isdst_set
;
1838 in6addr_scope_t cand_scope
;
1839 boolean_t cand_scope_set
;
1840 boolean_t cand_isdeprecated
;
1841 boolean_t cand_isdeprecated_set
;
1842 boolean_t cand_ispreferred
;
1843 boolean_t cand_ispreferred_set
;
1844 boolean_t cand_matchedinterface
;
1845 boolean_t cand_matchedinterface_set
;
1846 boolean_t cand_matchedlabel
;
1847 boolean_t cand_matchedlabel_set
;
1848 boolean_t cand_istmp
;
1849 boolean_t cand_istmp_set
;
1850 int cand_common_pref
;
1851 boolean_t cand_common_pref_set
;
1852 boolean_t cand_pref_eq
;
1853 boolean_t cand_pref_eq_set
;
1855 boolean_t cand_pref_len_set
;
1857 #define cand_srcaddr cand_ipif->ipif_v6lcl_addr
1858 #define cand_mask cand_ipif->ipif_v6net_mask
1859 #define cand_flags cand_ipif->ipif_flags
1860 #define cand_ill cand_ipif->ipif_ill
1861 #define cand_zoneid cand_ipif->ipif_zoneid
1863 /* information about the destination for source address selection */
1864 typedef struct dstinfo
{
1865 const in6_addr_t
*dst_addr
;
1867 uint_t dst_restrict_ill
;
1868 boolean_t dst_prefer_src_tmp
;
1869 in6addr_scope_t dst_scope
;
1874 * The following functions are rules used to select a source address in
1875 * ipif_select_source_v6(). Each rule compares a current candidate (cc)
1876 * against the best candidate (bc). Each rule has three possible outcomes;
1877 * the candidate is preferred over the best candidate (CAND_PREFER), the
1878 * candidate is not preferred over the best candidate (CAND_AVOID), or the
1879 * candidate is of equal value as the best candidate (CAND_TIE).
1881 * These rules are part of a greater "Default Address Selection for IPv6"
1882 * sheme, which is standards based work coming out of the IETF ipv6 working
1883 * group. The IETF document defines both IPv6 source address selection and
1884 * destination address ordering. The rules defined here implement the IPv6
1885 * source address selection. Destination address ordering is done by
1886 * libnsl, and uses a similar set of rules to implement the sorting.
1888 * Most of the rules are defined by the RFC and are not typically altered. The
1889 * last rule, number 8, has language that allows for local preferences. In the
1890 * scheme below, this means that new Solaris rules should normally go between
1891 * rule_ifprefix and rule_prefix.
1893 typedef enum {CAND_AVOID
, CAND_TIE
, CAND_PREFER
} rule_res_t
;
1894 typedef rule_res_t (*rulef_t
)(cand_t
*, cand_t
*, const dstinfo_t
*,
1897 /* Prefer an address if it is equal to the destination address. */
1900 rule_isdst(cand_t
*bc
, cand_t
*cc
, const dstinfo_t
*dstinfo
, ip_stack_t
*ipst
)
1902 if (!bc
->cand_isdst_set
) {
1904 IN6_ARE_ADDR_EQUAL(&bc
->cand_srcaddr
, dstinfo
->dst_addr
);
1905 bc
->cand_isdst_set
= B_TRUE
;
1909 IN6_ARE_ADDR_EQUAL(&cc
->cand_srcaddr
, dstinfo
->dst_addr
);
1910 cc
->cand_isdst_set
= B_TRUE
;
1912 if (cc
->cand_isdst
== bc
->cand_isdst
)
1914 else if (cc
->cand_isdst
)
1915 return (CAND_PREFER
);
1917 return (CAND_AVOID
);
1921 * Prefer addresses that are of closest scope to the destination. Always
1922 * prefer addresses that are of greater scope than the destination over
1923 * those that are of lesser scope than the destination.
1927 rule_scope(cand_t
*bc
, cand_t
*cc
, const dstinfo_t
*dstinfo
, ip_stack_t
*ipst
)
1929 if (!bc
->cand_scope_set
) {
1930 bc
->cand_scope
= ip_addr_scope_v6(&bc
->cand_srcaddr
);
1931 bc
->cand_scope_set
= B_TRUE
;
1934 cc
->cand_scope
= ip_addr_scope_v6(&cc
->cand_srcaddr
);
1935 cc
->cand_scope_set
= B_TRUE
;
1937 if (cc
->cand_scope
< bc
->cand_scope
) {
1938 if (cc
->cand_scope
< dstinfo
->dst_scope
)
1939 return (CAND_AVOID
);
1941 return (CAND_PREFER
);
1942 } else if (bc
->cand_scope
< cc
->cand_scope
) {
1943 if (bc
->cand_scope
< dstinfo
->dst_scope
)
1944 return (CAND_PREFER
);
1946 return (CAND_AVOID
);
1953 * Prefer non-deprecated source addresses.
1957 rule_deprecated(cand_t
*bc
, cand_t
*cc
, const dstinfo_t
*dstinfo
,
1960 if (!bc
->cand_isdeprecated_set
) {
1961 bc
->cand_isdeprecated
=
1962 ((bc
->cand_flags
& IPIF_DEPRECATED
) != 0);
1963 bc
->cand_isdeprecated_set
= B_TRUE
;
1966 cc
->cand_isdeprecated
= ((cc
->cand_flags
& IPIF_DEPRECATED
) != 0);
1967 cc
->cand_isdeprecated_set
= B_TRUE
;
1969 if (bc
->cand_isdeprecated
== cc
->cand_isdeprecated
)
1971 else if (cc
->cand_isdeprecated
)
1972 return (CAND_AVOID
);
1974 return (CAND_PREFER
);
1978 * Prefer source addresses that have the IPIF_PREFERRED flag set. This
1979 * rule must be before rule_interface because the flag could be set on any
1980 * interface, not just the interface being used for outgoing packets (for
1981 * example, the IFF_PREFERRED could be set on an address assigned to the
1982 * loopback interface).
1986 rule_preferred(cand_t
*bc
, cand_t
*cc
, const dstinfo_t
*dstinfo
,
1989 if (!bc
->cand_ispreferred_set
) {
1990 bc
->cand_ispreferred
= ((bc
->cand_flags
& IPIF_PREFERRED
) != 0);
1991 bc
->cand_ispreferred_set
= B_TRUE
;
1994 cc
->cand_ispreferred
= ((cc
->cand_flags
& IPIF_PREFERRED
) != 0);
1995 cc
->cand_ispreferred_set
= B_TRUE
;
1997 if (bc
->cand_ispreferred
== cc
->cand_ispreferred
)
1999 else if (cc
->cand_ispreferred
)
2000 return (CAND_PREFER
);
2002 return (CAND_AVOID
);
2006 * Prefer source addresses that are assigned to the outgoing interface.
2010 rule_interface(cand_t
*bc
, cand_t
*cc
, const dstinfo_t
*dstinfo
,
2013 ill_t
*dstill
= dstinfo
->dst_ill
;
2016 * If dstinfo->dst_restrict_ill is set, this rule is unnecessary
2017 * since we know all candidates will be on the same link.
2019 if (dstinfo
->dst_restrict_ill
)
2022 if (!bc
->cand_matchedinterface_set
) {
2023 bc
->cand_matchedinterface
= bc
->cand_ill
== dstill
;
2024 bc
->cand_matchedinterface_set
= B_TRUE
;
2027 cc
->cand_matchedinterface
= cc
->cand_ill
== dstill
;
2028 cc
->cand_matchedinterface_set
= B_TRUE
;
2030 if (bc
->cand_matchedinterface
== cc
->cand_matchedinterface
)
2032 else if (cc
->cand_matchedinterface
)
2033 return (CAND_PREFER
);
2035 return (CAND_AVOID
);
2039 * Prefer source addresses whose label matches the destination's label.
2042 rule_label(cand_t
*bc
, cand_t
*cc
, const dstinfo_t
*dstinfo
, ip_stack_t
*ipst
)
2046 if (!bc
->cand_matchedlabel_set
) {
2047 label
= ip6_asp_lookup(&bc
->cand_srcaddr
, NULL
, ipst
);
2048 bc
->cand_matchedlabel
=
2049 ip6_asp_labelcmp(label
, dstinfo
->dst_label
);
2050 bc
->cand_matchedlabel_set
= B_TRUE
;
2053 label
= ip6_asp_lookup(&cc
->cand_srcaddr
, NULL
, ipst
);
2054 cc
->cand_matchedlabel
= ip6_asp_labelcmp(label
, dstinfo
->dst_label
);
2055 cc
->cand_matchedlabel_set
= B_TRUE
;
2057 if (bc
->cand_matchedlabel
== cc
->cand_matchedlabel
)
2059 else if (cc
->cand_matchedlabel
)
2060 return (CAND_PREFER
);
2062 return (CAND_AVOID
);
2066 * Prefer public addresses over temporary ones. An application can reverse
2067 * the logic of this rule and prefer temporary addresses by using the
2068 * IPV6_SRC_PREFERENCES socket option.
2072 rule_temporary(cand_t
*bc
, cand_t
*cc
, const dstinfo_t
*dstinfo
,
2075 if (!bc
->cand_istmp_set
) {
2076 bc
->cand_istmp
= ((bc
->cand_flags
& IPIF_TEMPORARY
) != 0);
2077 bc
->cand_istmp_set
= B_TRUE
;
2080 cc
->cand_istmp
= ((cc
->cand_flags
& IPIF_TEMPORARY
) != 0);
2081 cc
->cand_istmp_set
= B_TRUE
;
2083 if (bc
->cand_istmp
== cc
->cand_istmp
)
2086 if (dstinfo
->dst_prefer_src_tmp
&& cc
->cand_istmp
)
2087 return (CAND_PREFER
);
2088 else if (!dstinfo
->dst_prefer_src_tmp
&& !cc
->cand_istmp
)
2089 return (CAND_PREFER
);
2091 return (CAND_AVOID
);
2095 * Prefer source addresses with longer matching prefix with the destination
2096 * under the interface mask. This gets us on the same subnet before applying
2097 * any Solaris-specific rules.
2101 rule_ifprefix(cand_t
*bc
, cand_t
*cc
, const dstinfo_t
*dstinfo
,
2104 if (!bc
->cand_pref_eq_set
) {
2105 bc
->cand_pref_eq
= V6_MASK_EQ_2(bc
->cand_srcaddr
,
2106 bc
->cand_mask
, *dstinfo
->dst_addr
);
2107 bc
->cand_pref_eq_set
= B_TRUE
;
2110 cc
->cand_pref_eq
= V6_MASK_EQ_2(cc
->cand_srcaddr
, cc
->cand_mask
,
2111 *dstinfo
->dst_addr
);
2112 cc
->cand_pref_eq_set
= B_TRUE
;
2114 if (bc
->cand_pref_eq
) {
2115 if (cc
->cand_pref_eq
) {
2116 if (!bc
->cand_pref_len_set
) {
2118 ip_mask_to_plen_v6(&bc
->cand_mask
);
2119 bc
->cand_pref_len_set
= B_TRUE
;
2121 cc
->cand_pref_len
= ip_mask_to_plen_v6(&cc
->cand_mask
);
2122 cc
->cand_pref_len_set
= B_TRUE
;
2123 if (bc
->cand_pref_len
== cc
->cand_pref_len
)
2125 else if (bc
->cand_pref_len
> cc
->cand_pref_len
)
2126 return (CAND_AVOID
);
2128 return (CAND_PREFER
);
2130 return (CAND_AVOID
);
2133 if (cc
->cand_pref_eq
)
2134 return (CAND_PREFER
);
2141 * Prefer to use zone-specific addresses when possible instead of all-zones
2146 rule_zone_specific(cand_t
*bc
, cand_t
*cc
, const dstinfo_t
*dstinfo
,
2149 if ((bc
->cand_zoneid
== ALL_ZONES
) ==
2150 (cc
->cand_zoneid
== ALL_ZONES
))
2152 else if (cc
->cand_zoneid
== ALL_ZONES
)
2153 return (CAND_AVOID
);
2155 return (CAND_PREFER
);
2159 * Prefer to use DHCPv6 (first) and static addresses (second) when possible
2160 * instead of statelessly autoconfigured addresses.
2162 * This is done after trying all other preferences (and before the final tie
2163 * breaker) so that, if all else is equal, we select addresses configured by
2164 * DHCPv6 over other addresses. We presume that DHCPv6 addresses, unlike
2165 * stateless autoconfigured addresses, are deliberately configured by an
2166 * administrator, and thus are correctly set up in DNS and network packet
2171 rule_addr_type(cand_t
*bc
, cand_t
*cc
, const dstinfo_t
*dstinfo
,
2175 ((x) & IPIF_DHCPRUNNING) ? 1 : ((x) & IPIF_ADDRCONF) ? 3 : 2
2176 int bcval
= ATYPE(bc
->cand_flags
);
2177 int ccval
= ATYPE(cc
->cand_flags
);
2182 else if (ccval
< bcval
)
2183 return (CAND_PREFER
);
2185 return (CAND_AVOID
);
2189 * Prefer source addresses with longer matching prefix with the destination.
2190 * We do the longest matching prefix calculation by doing an xor of both
2191 * addresses with the destination, and pick the address with the longest string
2192 * of leading zeros, as per CommonPrefixLen() defined in RFC 3484.
2196 rule_prefix(cand_t
*bc
, cand_t
*cc
, const dstinfo_t
*dstinfo
, ip_stack_t
*ipst
)
2199 * For IPMP, we always want to choose a random source address from
2200 * among any equally usable addresses, so always report a tie.
2202 if (IS_IPMP(dstinfo
->dst_ill
))
2205 if (!bc
->cand_common_pref_set
) {
2206 bc
->cand_common_pref
= ip_common_prefix_v6(&bc
->cand_srcaddr
,
2208 bc
->cand_common_pref_set
= B_TRUE
;
2211 cc
->cand_common_pref
= ip_common_prefix_v6(&cc
->cand_srcaddr
,
2213 cc
->cand_common_pref_set
= B_TRUE
;
2215 if (bc
->cand_common_pref
== cc
->cand_common_pref
)
2217 else if (bc
->cand_common_pref
> cc
->cand_common_pref
)
2218 return (CAND_AVOID
);
2220 return (CAND_PREFER
);
2224 * Last rule: we must pick something, so just prefer the current best
2229 rule_must_be_last(cand_t
*bc
, cand_t
*cc
, const dstinfo_t
*dstinfo
,
2232 return (CAND_AVOID
);
2236 * Determine the best source address given a destination address and a
2237 * destination ill. If no suitable source address is found, it returns
2238 * NULL. If there is a usable address pointed to by the usesrc
2239 * (i.e ill_usesrc_ifindex != 0) then return that first since it is more
2240 * fine grained (i.e per interface)
2242 * This implementation is based on the "Default Address Selection for IPv6"
2243 * specification produced by the IETF IPv6 working group. It has been
2244 * implemented so that the list of addresses is only traversed once (the
2245 * specification's algorithm could traverse the list of addresses once for
2248 * The restrict_ill argument restricts the algorithm to choose a source
2249 * address that is assigned to the destination ill. This is used when
2250 * the destination address is a link-local or multicast address, and when
2251 * ipv6_strict_dst_multihoming is turned on.
2253 * src_prefs is the caller's set of source address preferences. If source
2254 * address selection is being called to determine the source address of a
2255 * connected socket (from ip_bind_connected_v6()), then the preferences are
2256 * taken from conn_src_preferences. These preferences can be set on a
2257 * per-socket basis using the IPV6_SRC_PREFERENCES socket option. The only
2258 * preference currently implemented is for rfc3041 temporary addresses.
2261 ipif_select_source_v6(ill_t
*dstill
, const in6_addr_t
*dst
,
2262 boolean_t restrict_ill
, uint32_t src_prefs
, zoneid_t zoneid
)
2265 char dstr
[INET6_ADDRSTRLEN
];
2266 char sstr
[INET6_ADDRSTRLEN
];
2267 ipif_t
*ipif
, *start_ipif
, *next_ipif
;
2268 ill_t
*ill
, *usesrc_ill
= NULL
, *ipmp_ill
= NULL
;
2269 ill_walk_context_t ctx
;
2270 cand_t best_c
; /* The best candidate */
2271 cand_t curr_c
; /* The current candidate */
2273 boolean_t first_candidate
= B_TRUE
;
2274 rule_res_t rule_result
;
2275 tsol_tpc_t
*src_rhtp
, *dst_rhtp
;
2276 ip_stack_t
*ipst
= dstill
->ill_ipst
;
2279 * The list of ordering rules. They are applied in the order they
2280 * appear in the list.
2282 * Solaris doesn't currently support Mobile IPv6, so there's no
2283 * rule_mipv6 corresponding to rule 4 in the specification.
2293 rule_ifprefix
, /* local rules after this */
2296 rule_prefix
, /* local rules before this */
2297 rule_must_be_last
, /* must always be last */
2301 ASSERT(dstill
->ill_isv6
);
2302 ASSERT(!IN6_IS_ADDR_V4MAPPED(dst
));
2305 * Check if there is a usable src address pointed to by the
2306 * usesrc ifindex. This has higher precedence since it is
2307 * finer grained (i.e per interface) v/s being system wide.
2309 if (dstill
->ill_usesrc_ifindex
!= 0) {
2311 ill_lookup_on_ifindex(dstill
->ill_usesrc_ifindex
, B_TRUE
,
2312 NULL
, NULL
, NULL
, NULL
, ipst
)) != NULL
) {
2313 dstinfo
.dst_ill
= usesrc_ill
;
2317 } else if (IS_UNDER_IPMP(dstill
)) {
2319 * Test addresses should never be used for source address
2320 * selection, so if we were passed an underlying ill, switch
2321 * to the IPMP meta-interface.
2323 if ((ipmp_ill
= ipmp_ill_hold_ipmp_ill(dstill
)) != NULL
)
2324 dstinfo
.dst_ill
= ipmp_ill
;
2328 dstinfo
.dst_ill
= dstill
;
2332 * If we're dealing with an unlabeled destination on a labeled system,
2333 * make sure that we ignore source addresses that are incompatible with
2334 * the destination's default label. That destination's default label
2335 * must dominate the minimum label on the source address.
2337 * (Note that this has to do with Trusted Solaris. It's not related to
2338 * the labels described by ip6_asp_lookup.)
2341 if (is_system_labeled()) {
2342 dst_rhtp
= find_tpc(dst
, IPV6_VERSION
, B_FALSE
);
2343 if (dst_rhtp
== NULL
)
2345 if (dst_rhtp
->tpc_tp
.host_type
!= UNLABELED
) {
2351 dstinfo
.dst_addr
= dst
;
2352 dstinfo
.dst_scope
= ip_addr_scope_v6(dst
);
2353 dstinfo
.dst_label
= ip6_asp_lookup(dst
, NULL
, ipst
);
2354 dstinfo
.dst_prefer_src_tmp
= ((src_prefs
& IPV6_PREFER_SRC_TMP
) != 0);
2355 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
2357 * Section three of the I-D states that for multicast and
2358 * link-local destinations, the candidate set must be restricted to
2359 * an interface that is on the same link as the outgoing interface.
2360 * Also, when ipv6_strict_dst_multihoming is turned on, always
2361 * restrict the source address to the destination link as doing
2362 * otherwise will almost certainly cause problems.
2364 if (IN6_IS_ADDR_LINKLOCAL(dst
) || IN6_IS_ADDR_MULTICAST(dst
) ||
2365 ipst
->ips_ipv6_strict_dst_multihoming
|| usesrc_ill
!= NULL
) {
2366 dstinfo
.dst_restrict_ill
= B_TRUE
;
2368 dstinfo
.dst_restrict_ill
= restrict_ill
;
2371 bzero(&best_c
, sizeof (cand_t
));
2374 * Take a pass through the list of IPv6 interfaces to choose the best
2375 * possible source address. If restrict_ill is set, just use dst_ill.
2377 if (dstinfo
.dst_restrict_ill
)
2378 ill
= dstinfo
.dst_ill
;
2380 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
2382 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
2383 ASSERT(ill
->ill_isv6
);
2386 * Test addresses should never be used for source address
2387 * selection, so ignore underlying ills.
2389 if (IS_UNDER_IPMP(ill
))
2392 if (ill
->ill_ipif
== NULL
)
2395 * For source address selection, we treat the ipif list as
2396 * circular and continue until we get back to where we
2397 * started. This allows IPMP to vary source address selection
2398 * (which improves inbound load spreading) by caching its last
2399 * ending point and starting from there. NOTE: we don't have
2400 * to worry about ill_src_ipif changing ills since that can't
2401 * happen on the IPMP ill.
2403 start_ipif
= ill
->ill_ipif
;
2404 if (IS_IPMP(ill
) && ill
->ill_src_ipif
!= NULL
)
2405 start_ipif
= ill
->ill_src_ipif
;
2409 if ((next_ipif
= ipif
->ipif_next
) == NULL
)
2410 next_ipif
= ill
->ill_ipif
;
2412 if (!IPIF_VALID_IPV6_SOURCE(ipif
))
2415 if (zoneid
!= ALL_ZONES
&&
2416 ipif
->ipif_zoneid
!= zoneid
&&
2417 ipif
->ipif_zoneid
!= ALL_ZONES
)
2421 * Check compatibility of local address for
2422 * destination's default label if we're on a labeled
2423 * system. Incompatible addresses can't be used at
2424 * all and must be skipped over.
2426 if (dst_rhtp
!= NULL
) {
2429 src_rhtp
= find_tpc(&ipif
->ipif_v6lcl_addr
,
2430 IPV6_VERSION
, B_FALSE
);
2431 if (src_rhtp
== NULL
)
2434 src_rhtp
->tpc_tp
.host_type
!= SUN_CIPSO
||
2435 src_rhtp
->tpc_tp
.tp_doi
!=
2436 dst_rhtp
->tpc_tp
.tp_doi
||
2437 (!_blinrange(&dst_rhtp
->tpc_tp
.tp_def_label
,
2438 &src_rhtp
->tpc_tp
.tp_sl_range_cipso
) &&
2439 !blinlset(&dst_rhtp
->tpc_tp
.tp_def_label
,
2440 src_rhtp
->tpc_tp
.tp_sl_set_cipso
));
2446 if (first_candidate
) {
2448 * This is first valid address in the list.
2449 * It is automatically the best candidate
2452 best_c
.cand_ipif
= ipif
;
2453 first_candidate
= B_FALSE
;
2457 bzero(&curr_c
, sizeof (cand_t
));
2458 curr_c
.cand_ipif
= ipif
;
2461 * Compare this current candidate (curr_c) with the
2462 * best candidate (best_c) by applying the
2463 * comparison rules in order until one breaks the
2466 for (index
= 0; rules
[index
] != NULL
; index
++) {
2467 /* Apply a comparison rule. */
2468 rule_result
= (rules
[index
])(&best_c
, &curr_c
,
2470 if (rule_result
== CAND_AVOID
) {
2472 * The best candidate is still the
2473 * best candidate. Forget about
2474 * this current candidate and go on
2478 } else if (rule_result
== CAND_PREFER
) {
2480 * This candidate is prefered. It
2481 * becomes the best candidate so
2482 * far. Go on to the next address.
2487 /* We have a tie, apply the next rule. */
2491 * The last rule must be a tie breaker rule and
2492 * must never produce a tie. At this point, the
2493 * candidate should have either been rejected, or
2494 * have been prefered as the best candidate so far.
2496 ASSERT(rule_result
!= CAND_TIE
);
2497 } while ((ipif
= next_ipif
) != start_ipif
);
2500 * For IPMP, update the source ipif rotor to the next ipif,
2501 * provided we can look it up. (We must not use it if it's
2502 * IPIF_CONDEMNED since we may have grabbed ill_g_lock after
2503 * ipif_free() checked ill_src_ipif.)
2505 if (IS_IPMP(ill
) && ipif
!= NULL
) {
2506 mutex_enter(&ipif
->ipif_ill
->ill_lock
);
2507 next_ipif
= ipif
->ipif_next
;
2508 if (next_ipif
!= NULL
&& IPIF_CAN_LOOKUP(next_ipif
))
2509 ill
->ill_src_ipif
= next_ipif
;
2511 ill
->ill_src_ipif
= NULL
;
2512 mutex_exit(&ipif
->ipif_ill
->ill_lock
);
2516 * Only one ill to consider if dst_restrict_ill is set.
2518 if (dstinfo
.dst_restrict_ill
)
2522 ipif
= best_c
.cand_ipif
;
2523 ip1dbg(("ipif_select_source_v6(%s, %s) -> %s\n",
2524 dstinfo
.dst_ill
->ill_name
,
2525 inet_ntop(AF_INET6
, dstinfo
.dst_addr
, dstr
, sizeof (dstr
)),
2526 (ipif
== NULL
? "NULL" :
2527 inet_ntop(AF_INET6
, &ipif
->ipif_v6lcl_addr
, sstr
, sizeof (sstr
)))));
2529 if (usesrc_ill
!= NULL
)
2530 ill_refrele(usesrc_ill
);
2532 if (ipmp_ill
!= NULL
)
2533 ill_refrele(ipmp_ill
);
2535 if (dst_rhtp
!= NULL
)
2539 rw_exit(&ipst
->ips_ill_g_lock
);
2543 mutex_enter(&ipif
->ipif_ill
->ill_lock
);
2544 if (IPIF_CAN_LOOKUP(ipif
)) {
2545 ipif_refhold_locked(ipif
);
2546 mutex_exit(&ipif
->ipif_ill
->ill_lock
);
2547 rw_exit(&ipst
->ips_ill_g_lock
);
2550 mutex_exit(&ipif
->ipif_ill
->ill_lock
);
2551 rw_exit(&ipst
->ips_ill_g_lock
);
2552 ip1dbg(("ipif_select_source_v6 cannot lookup ipif %p"
2553 " returning null \n", (void *)ipif
));
2559 * If old_ipif is not NULL, see if ipif was derived from old
2560 * ipif and if so, recreate the interface route by re-doing
2561 * source address selection. This happens when ipif_down ->
2562 * ipif_update_other_ipifs calls us.
2564 * If old_ipif is NULL, just redo the source address selection
2565 * if needed. This happens when ipif_up_done_v6 calls us.
2568 ipif_recreate_interface_routes_v6(ipif_t
*old_ipif
, ipif_t
*ipif
)
2574 ipif_t
*nipif
= NULL
;
2575 boolean_t nipif_refheld
= B_FALSE
;
2576 boolean_t ip6_asp_table_held
= B_FALSE
;
2577 ip_stack_t
*ipst
= ipif
->ipif_ill
->ill_ipst
;
2579 ill
= ipif
->ipif_ill
;
2581 if (!(ipif
->ipif_flags
&
2582 (IPIF_NOLOCAL
|IPIF_ANYCAST
|IPIF_DEPRECATED
))) {
2584 * Can't possibly have borrowed the source
2591 * Is there any work to be done? No work if the address
2592 * is INADDR_ANY, loopback or NOLOCAL or ANYCAST (
2593 * ipif_select_source_v6() does not borrow addresses from
2594 * NOLOCAL and ANYCAST interfaces).
2596 if ((old_ipif
!= NULL
) &&
2597 ((IN6_IS_ADDR_UNSPECIFIED(&old_ipif
->ipif_v6lcl_addr
)) ||
2598 (old_ipif
->ipif_ill
->ill_wq
== NULL
) ||
2599 (old_ipif
->ipif_flags
&
2600 (IPIF_NOLOCAL
|IPIF_ANYCAST
)))) {
2605 * Perform the same checks as when creating the
2606 * IRE_INTERFACE in ipif_up_done_v6.
2608 if (!(ipif
->ipif_flags
& IPIF_UP
))
2611 if ((ipif
->ipif_flags
& IPIF_NOXMIT
))
2614 if (IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6subnet
) &&
2615 IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6net_mask
))
2619 * We know that ipif uses some other source for its
2620 * IRE_INTERFACE. Is it using the source of this
2623 ipif_ire
= ipif_to_ire_v6(ipif
);
2624 if (ipif_ire
== NULL
)
2627 if (old_ipif
!= NULL
&&
2628 !IN6_ARE_ADDR_EQUAL(&old_ipif
->ipif_v6lcl_addr
,
2629 &ipif_ire
->ire_src_addr_v6
)) {
2630 ire_refrele(ipif_ire
);
2636 pr_addr_dbg("ipif_recreate_interface_routes_v6: deleting IRE"
2637 " for src %s\n", AF_INET6
, &ipif_ire
->ire_src_addr_v6
);
2640 stq
= ipif_ire
->ire_stq
;
2643 * Can't use our source address. Select a different source address
2644 * for the IRE_INTERFACE. We restrict interface route source
2645 * address selection to ipif's assigned to the same link as the
2648 if (ip6_asp_can_lookup(ipst
)) {
2649 ip6_asp_table_held
= B_TRUE
;
2650 nipif
= ipif_select_source_v6(ill
, &ipif
->ipif_v6subnet
,
2651 B_TRUE
, IPV6_PREFER_SRC_DEFAULT
, ipif
->ipif_zoneid
);
2653 if (nipif
== NULL
) {
2654 /* Last resort - all ipif's have IPIF_NOLOCAL */
2657 nipif_refheld
= B_TRUE
;
2660 ire
= ire_create_v6(
2661 &ipif
->ipif_v6subnet
, /* dest pref */
2662 &ipif
->ipif_v6net_mask
, /* mask */
2663 &nipif
->ipif_v6src_addr
, /* src addr */
2664 NULL
, /* no gateway */
2665 &ipif
->ipif_mtu
, /* max frag */
2666 NULL
, /* no src nce */
2667 NULL
, /* no recv from queue */
2668 stq
, /* send-to queue */
2669 ill
->ill_net_type
, /* IF_[NO]RESOLVER */
2685 * We don't need ipif_ire anymore. We need to delete
2686 * before we add so that ire_add does not detect
2689 ire_delete(ipif_ire
);
2691 error
= ire_add(&ret_ire
, NULL
, NULL
, NULL
, B_FALSE
);
2693 ASSERT(ret_ire
== ire
);
2694 if (ret_ire
!= NULL
) {
2695 /* Held in ire_add */
2696 ire_refrele(ret_ire
);
2700 * Either we are falling through from above or could not
2701 * allocate a replacement.
2703 ire_refrele(ipif_ire
);
2704 if (ip6_asp_table_held
)
2705 ip6_asp_table_refrele(ipst
);
2707 ipif_refrele(nipif
);
2711 * This old_ipif is going away.
2713 * Determine if any other ipif's are using our address as
2714 * ipif_v6lcl_addr (due to those being IPIF_NOLOCAL, IPIF_ANYCAST, or
2716 * Find the IRE_INTERFACE for such ipif's and recreate them
2717 * to use an different source address following the rules in
2721 ipif_update_other_ipifs_v6(ipif_t
*old_ipif
)
2725 char buf
[INET6_ADDRSTRLEN
];
2727 ASSERT(IAM_WRITER_IPIF(old_ipif
));
2729 ill
= old_ipif
->ipif_ill
;
2731 ip1dbg(("ipif_update_other_ipifs_v6(%s, %s)\n",
2733 inet_ntop(AF_INET6
, &old_ipif
->ipif_v6lcl_addr
,
2734 buf
, sizeof (buf
))));
2736 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
2737 if (ipif
!= old_ipif
)
2738 ipif_recreate_interface_routes_v6(old_ipif
, ipif
);
2743 * Perform an attach and bind to get phys addr plus info_req for
2744 * the physical device.
2745 * q and mp represents an ioctl which will be queued waiting for
2746 * completion of the DLPI message exchange.
2747 * MUST be called on an ill queue. Can not set conn_pending_ill for that
2748 * reason thus the DL_PHYS_ADDR_ACK code does not assume ill_pending_q.
2750 * Returns EINPROGRESS when mp has been consumed by queueing it on
2751 * ill_pending_mp and the ioctl will complete in ip_rput.
2754 ill_dl_phys(ill_t
*ill
, ipif_t
*ipif
, mblk_t
*mp
, queue_t
*q
)
2756 mblk_t
*v6token_mp
= NULL
;
2757 mblk_t
*v6lla_mp
= NULL
;
2758 mblk_t
*dest_mp
= NULL
;
2759 mblk_t
*phys_mp
= NULL
;
2760 mblk_t
*info_mp
= NULL
;
2761 mblk_t
*attach_mp
= NULL
;
2762 mblk_t
*bind_mp
= NULL
;
2763 mblk_t
*unbind_mp
= NULL
;
2764 mblk_t
*notify_mp
= NULL
;
2766 ip1dbg(("ill_dl_phys(%s:%u)\n", ill
->ill_name
, ipif
->ipif_id
));
2767 ASSERT(ill
->ill_dlpi_style_set
);
2768 ASSERT(WR(q
)->q_next
!= NULL
);
2770 if (ill
->ill_isv6
) {
2771 v6token_mp
= ip_dlpi_alloc(sizeof (dl_phys_addr_req_t
) +
2772 sizeof (t_scalar_t
), DL_PHYS_ADDR_REQ
);
2773 if (v6token_mp
== NULL
)
2775 ((dl_phys_addr_req_t
*)v6token_mp
->b_rptr
)->dl_addr_type
=
2778 v6lla_mp
= ip_dlpi_alloc(sizeof (dl_phys_addr_req_t
) +
2779 sizeof (t_scalar_t
), DL_PHYS_ADDR_REQ
);
2780 if (v6lla_mp
== NULL
)
2782 ((dl_phys_addr_req_t
*)v6lla_mp
->b_rptr
)->dl_addr_type
=
2783 DL_IPV6_LINK_LAYER_ADDR
;
2786 if (ill
->ill_mactype
== DL_IPV4
|| ill
->ill_mactype
== DL_IPV6
) {
2787 dest_mp
= ip_dlpi_alloc(sizeof (dl_phys_addr_req_t
) +
2788 sizeof (t_scalar_t
), DL_PHYS_ADDR_REQ
);
2789 if (dest_mp
== NULL
)
2791 ((dl_phys_addr_req_t
*)dest_mp
->b_rptr
)->dl_addr_type
=
2796 * Allocate a DL_NOTIFY_REQ and set the notifications we want.
2798 notify_mp
= ip_dlpi_alloc(sizeof (dl_notify_req_t
) + sizeof (long),
2800 if (notify_mp
== NULL
)
2802 ((dl_notify_req_t
*)notify_mp
->b_rptr
)->dl_notifications
=
2803 (DL_NOTE_PHYS_ADDR
| DL_NOTE_SDU_SIZE
| DL_NOTE_FASTPATH_FLUSH
|
2804 DL_NOTE_LINK_UP
| DL_NOTE_LINK_DOWN
| DL_NOTE_CAPAB_RENEG
|
2805 DL_NOTE_PROMISC_ON_PHYS
| DL_NOTE_PROMISC_OFF_PHYS
|
2808 phys_mp
= ip_dlpi_alloc(sizeof (dl_phys_addr_req_t
) +
2809 sizeof (t_scalar_t
), DL_PHYS_ADDR_REQ
);
2810 if (phys_mp
== NULL
)
2812 ((dl_phys_addr_req_t
*)phys_mp
->b_rptr
)->dl_addr_type
=
2815 info_mp
= ip_dlpi_alloc(
2816 sizeof (dl_info_req_t
) + sizeof (dl_info_ack_t
),
2818 if (info_mp
== NULL
)
2821 bind_mp
= ip_dlpi_alloc(sizeof (dl_bind_req_t
) + sizeof (long),
2823 if (bind_mp
== NULL
)
2825 ((dl_bind_req_t
*)bind_mp
->b_rptr
)->dl_sap
= ill
->ill_sap
;
2826 ((dl_bind_req_t
*)bind_mp
->b_rptr
)->dl_service_mode
= DL_CLDLS
;
2828 unbind_mp
= ip_dlpi_alloc(sizeof (dl_unbind_req_t
), DL_UNBIND_REQ
);
2829 if (unbind_mp
== NULL
)
2832 /* If we need to attach, pre-alloc and initialize the mblk */
2833 if (ill
->ill_needs_attach
) {
2834 attach_mp
= ip_dlpi_alloc(sizeof (dl_attach_req_t
),
2836 if (attach_mp
== NULL
)
2838 ((dl_attach_req_t
*)attach_mp
->b_rptr
)->dl_ppa
= ill
->ill_ppa
;
2842 * Here we are going to delay the ioctl ack until after
2843 * ACKs from DL_PHYS_ADDR_REQ. So need to save the
2844 * original ioctl message before sending the requests
2846 mutex_enter(&ill
->ill_lock
);
2847 /* ipsq_pending_mp_add won't fail since we pass in a NULL connp */
2848 (void) ipsq_pending_mp_add(NULL
, ipif
, ill
->ill_wq
, mp
, 0);
2850 * Set ill_phys_addr_pend to zero. It will be set to the addr_type of
2851 * the DL_PHYS_ADDR_REQ in ill_dlpi_send() and ill_dlpi_done(). It will
2852 * be used to track which DL_PHYS_ADDR_REQ is being ACK'd/NAK'd.
2854 ill
->ill_phys_addr_pend
= 0;
2855 mutex_exit(&ill
->ill_lock
);
2857 if (attach_mp
!= NULL
) {
2858 ip1dbg(("ill_dl_phys: attach\n"));
2859 ill_dlpi_send(ill
, attach_mp
);
2861 ill_dlpi_send(ill
, bind_mp
);
2862 ill_dlpi_send(ill
, info_mp
);
2863 if (v6token_mp
!= NULL
)
2864 ill_dlpi_send(ill
, v6token_mp
);
2865 if (v6lla_mp
!= NULL
)
2866 ill_dlpi_send(ill
, v6lla_mp
);
2867 if (dest_mp
!= NULL
)
2868 ill_dlpi_send(ill
, dest_mp
);
2869 ill_dlpi_send(ill
, phys_mp
);
2870 ill_dlpi_send(ill
, notify_mp
);
2871 ill_dlpi_send(ill
, unbind_mp
);
2874 * This operation will complete in ip_rput_dlpi_writer with either
2875 * a DL_PHYS_ADDR_ACK or DL_ERROR_ACK.
2877 return (EINPROGRESS
);
2879 freemsg(v6token_mp
);
2891 uint_t ip_loopback_mtu_v6plus
= IP_LOOPBACK_MTU
+ IPV6_HDR_LEN
+ 20;
2895 * Create all the IREs associated with an interface bring up multicast.
2896 * Set the interface flag and finish other initialization
2897 * that potentially had to be differed to after DL_BIND_ACK.
2900 ipif_up_done_v6(ipif_t
*ipif
)
2902 ire_t
*ire_array
[20];
2903 ire_t
**irep
= ire_array
;
2905 ill_t
*ill
= ipif
->ipif_ill
;
2908 in6_addr_t route_mask
;
2909 ipif_t
*src_ipif
= NULL
;
2911 boolean_t flush_ire_cache
= B_TRUE
;
2913 char buf
[INET6_ADDRSTRLEN
];
2914 ire_t
**ipif_saved_irep
= NULL
;
2915 int ipif_saved_ire_cnt
;
2917 boolean_t src_ipif_held
= B_FALSE
;
2918 boolean_t loopback
= B_FALSE
;
2919 boolean_t ip6_asp_table_held
= B_FALSE
;
2920 ip_stack_t
*ipst
= ill
->ill_ipst
;
2922 ip1dbg(("ipif_up_done_v6(%s:%u)\n",
2923 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
));
2925 /* Check if this is a loopback interface */
2926 if (ipif
->ipif_ill
->ill_wq
== NULL
)
2929 ASSERT(ipif
->ipif_isv6
);
2930 ASSERT(!MUTEX_HELD(&ipif
->ipif_ill
->ill_lock
));
2933 * If all other interfaces for this ill are down or DEPRECATED,
2934 * or otherwise unsuitable for source address selection, remove
2935 * any IRE_CACHE entries for this ill to make sure source
2936 * address selection gets to take this new ipif into account.
2937 * No need to hold ill_lock while traversing the ipif list since
2940 for (tmp_ipif
= ill
->ill_ipif
; tmp_ipif
;
2941 tmp_ipif
= tmp_ipif
->ipif_next
) {
2942 if (((tmp_ipif
->ipif_flags
&
2943 (IPIF_NOXMIT
|IPIF_ANYCAST
|IPIF_NOLOCAL
|IPIF_DEPRECATED
)) ||
2944 !(tmp_ipif
->ipif_flags
& IPIF_UP
)) ||
2947 /* first useable pre-existing interface */
2948 flush_ire_cache
= B_FALSE
;
2951 if (flush_ire_cache
)
2952 ire_walk_ill_v6(MATCH_IRE_ILL
| MATCH_IRE_TYPE
,
2953 IRE_CACHE
, ill_ipif_cache_delete
, ill
, ill
);
2956 * Figure out which way the send-to queue should go. Only
2957 * IRE_IF_RESOLVER or IRE_IF_NORESOLVER should show up here.
2959 switch (ill
->ill_net_type
) {
2960 case IRE_IF_RESOLVER
:
2963 case IRE_IF_NORESOLVER
:
2971 if (IS_LOOPBACK(ill
)) {
2973 * lo0:1 and subsequent ipifs were marked IRE_LOCAL in
2974 * ipif_lookup_on_name(), but in the case of zones we can have
2975 * several loopback addresses on lo0. So all the interfaces with
2976 * loopback addresses need to be marked IRE_LOOPBACK.
2978 if (IN6_ARE_ADDR_EQUAL(&ipif
->ipif_v6lcl_addr
, &ipv6_loopback
))
2979 ipif
->ipif_ire_type
= IRE_LOOPBACK
;
2981 ipif
->ipif_ire_type
= IRE_LOCAL
;
2984 if (ipif
->ipif_flags
& (IPIF_NOLOCAL
|IPIF_ANYCAST
) ||
2985 ((ipif
->ipif_flags
& IPIF_DEPRECATED
) &&
2986 !(ipif
->ipif_flags
& IPIF_NOFAILOVER
))) {
2988 * Can't use our source address. Select a different
2989 * source address for the IRE_INTERFACE and IRE_LOCAL
2991 if (ip6_asp_can_lookup(ipst
)) {
2992 ip6_asp_table_held
= B_TRUE
;
2993 src_ipif
= ipif_select_source_v6(ipif
->ipif_ill
,
2994 &ipif
->ipif_v6subnet
, B_FALSE
,
2995 IPV6_PREFER_SRC_DEFAULT
, ipif
->ipif_zoneid
);
2997 if (src_ipif
== NULL
)
2998 src_ipif
= ipif
; /* Last resort */
3000 src_ipif_held
= B_TRUE
;
3005 if (!IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6lcl_addr
) &&
3006 !(ipif
->ipif_flags
& IPIF_NOLOCAL
)) {
3009 * If we're on a labeled system then make sure that zone-
3010 * private addresses have proper remote host database entries.
3012 if (is_system_labeled() &&
3013 ipif
->ipif_ire_type
!= IRE_LOOPBACK
) {
3014 if (ip6opt_ls
== 0) {
3015 cmn_err(CE_WARN
, "IPv6 not enabled "
3019 if (!tsol_check_interface_address(ipif
))
3023 /* Register the source address for __sin6_src_id */
3024 err
= ip_srcid_insert(&ipif
->ipif_v6lcl_addr
,
3025 ipif
->ipif_zoneid
, ipst
);
3027 ip0dbg(("ipif_up_done_v6: srcid_insert %d\n", err
));
3029 ipif_refrele(src_ipif
);
3030 if (ip6_asp_table_held
)
3031 ip6_asp_table_refrele(ipst
);
3035 * If the interface address is set, create the LOCAL
3038 ip1dbg(("ipif_up_done_v6: creating IRE %d for %s\n",
3039 ipif
->ipif_ire_type
,
3040 inet_ntop(AF_INET6
, &ipif
->ipif_v6lcl_addr
,
3041 buf
, sizeof (buf
))));
3043 *irep
++ = ire_create_v6(
3044 &ipif
->ipif_v6lcl_addr
, /* dest address */
3045 &ipv6_all_ones
, /* mask */
3046 &src_ipif
->ipif_v6src_addr
, /* source address */
3047 NULL
, /* no gateway */
3048 &ip_loopback_mtu_v6plus
, /* max frag size */
3050 ipif
->ipif_rq
, /* recv-from queue */
3051 NULL
, /* no send-to queue */
3052 ipif
->ipif_ire_type
, /* LOCAL or LOOPBACK */
3053 ipif
, /* interface */
3057 (ipif
->ipif_flags
& IPIF_PRIVATE
) ? RTF_PRIVATE
: 0,
3064 /* Set up the IRE_IF_RESOLVER or IRE_IF_NORESOLVER, as appropriate. */
3065 if (stq
!= NULL
&& !(ipif
->ipif_flags
& IPIF_NOXMIT
) &&
3066 !(IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6subnet
) &&
3067 IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6net_mask
))) {
3068 /* ipif_v6subnet is ipif_v6pp_dst_addr for pt-pt */
3069 v6addr
= ipif
->ipif_v6subnet
;
3071 if (ipif
->ipif_flags
& IPIF_POINTOPOINT
) {
3072 route_mask
= ipv6_all_ones
;
3074 route_mask
= ipif
->ipif_v6net_mask
;
3077 ip1dbg(("ipif_up_done_v6: creating if IRE %d for %s\n",
3079 inet_ntop(AF_INET6
, &v6addr
, buf
, sizeof (buf
))));
3081 *irep
++ = ire_create_v6(
3082 &v6addr
, /* dest pref */
3083 &route_mask
, /* mask */
3084 &src_ipif
->ipif_v6src_addr
, /* src addr */
3085 NULL
, /* no gateway */
3086 &ipif
->ipif_mtu
, /* max frag */
3087 NULL
, /* no src nce */
3088 NULL
, /* no recv from queue */
3089 stq
, /* send-to queue */
3090 ill
->ill_net_type
, /* IF_[NO]RESOLVER */
3095 (ipif
->ipif_flags
& IPIF_PRIVATE
) ? RTF_PRIVATE
: 0,
3102 /* If an earlier ire_create failed, get out now */
3103 for (irep1
= irep
; irep1
> ire_array
; ) {
3105 if (*irep1
== NULL
) {
3106 ip1dbg(("ipif_up_done_v6: NULL ire found in"
3113 ASSERT(!MUTEX_HELD(&ipif
->ipif_ill
->ill_lock
));
3116 * Need to atomically check for IP address availability under
3117 * ip_addr_avail_lock. ill_g_lock is held as reader to ensure no new
3118 * ills or new ipifs can be added while we are checking availability.
3120 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
3121 mutex_enter(&ipst
->ips_ip_addr_avail_lock
);
3122 ill
->ill_ipif_up_count
++;
3123 ipif
->ipif_flags
|= IPIF_UP
;
3124 err
= ip_addr_availability_check(ipif
);
3125 mutex_exit(&ipst
->ips_ip_addr_avail_lock
);
3126 rw_exit(&ipst
->ips_ill_g_lock
);
3130 * Our address may already be up on the same ill. In this case,
3131 * the external resolver entry for our ipif replaced the one for
3132 * the other ipif. So we don't want to delete it (otherwise the
3133 * other ipif would be unable to send packets).
3134 * ip_addr_availability_check() identifies this case for us and
3135 * returns EADDRINUSE; we need to turn it into EADDRNOTAVAIL
3136 * which is the expected error code.
3138 * Note that, for the non-XRESOLV case, ipif_ndp_down() will
3139 * only delete the nce in the case when the nce_ipif_cnt drops
3142 if (err
== EADDRINUSE
) {
3143 if (ipif
->ipif_ill
->ill_flags
& ILLF_XRESOLV
) {
3144 freemsg(ipif
->ipif_arp_del_mp
);
3145 ipif
->ipif_arp_del_mp
= NULL
;
3147 err
= EADDRNOTAVAIL
;
3149 ill
->ill_ipif_up_count
--;
3150 ipif
->ipif_flags
&= ~IPIF_UP
;
3155 * Add in all newly created IREs.
3157 * NOTE : We refrele the ire though we may branch to "bad"
3158 * later on where we do ire_delete. This is okay
3159 * because nobody can delete it as we are running
3162 for (irep1
= irep
; irep1
> ire_array
; ) {
3164 /* Shouldn't be adding any bcast ire's */
3165 ASSERT((*irep1
)->ire_type
!= IRE_BROADCAST
);
3166 ASSERT(!MUTEX_HELD(&ipif
->ipif_ill
->ill_lock
));
3168 * refheld by ire_add. refele towards the end of the func
3170 (void) ire_add(irep1
, NULL
, NULL
, NULL
, B_FALSE
);
3172 if (ip6_asp_table_held
) {
3173 ip6_asp_table_refrele(ipst
);
3174 ip6_asp_table_held
= B_FALSE
;
3177 /* Recover any additional IRE_IF_[NO]RESOLVER entries for this ipif */
3178 ipif_saved_ire_cnt
= ipif
->ipif_saved_ire_cnt
;
3179 ipif_saved_irep
= ipif_recover_ire_v6(ipif
);
3181 if (ill
->ill_need_recover_multicast
) {
3183 * Need to recover all multicast memberships in the driver.
3184 * This had to be deferred until we had attached.
3186 ill_recover_multicast(ill
);
3189 if (ill
->ill_ipif_up_count
== 1) {
3191 * Since the interface is now up, it may now be active.
3193 if (IS_UNDER_IPMP(ill
))
3194 ipmp_ill_refresh_active(ill
);
3197 /* Join the allhosts multicast address and the solicited node MC */
3198 ipif_multicast_up(ipif
);
3201 * See if anybody else would benefit from our new ipif.
3204 !(ipif
->ipif_flags
& (IPIF_NOLOCAL
|IPIF_ANYCAST
|IPIF_DEPRECATED
))) {
3205 ill_update_source_selection(ill
);
3208 for (irep1
= irep
; irep1
> ire_array
; ) {
3210 if (*irep1
!= NULL
) {
3211 /* was held in ire_add */
3212 ire_refrele(*irep1
);
3216 cnt
= ipif_saved_ire_cnt
;
3217 for (irep1
= ipif_saved_irep
; cnt
> 0; irep1
++, cnt
--) {
3218 if (*irep1
!= NULL
) {
3219 /* was held in ire_add */
3220 ire_refrele(*irep1
);
3224 if (ipif
->ipif_addr_ready
)
3225 ipif_up_notify(ipif
);
3227 if (ipif_saved_irep
!= NULL
) {
3228 kmem_free(ipif_saved_irep
,
3229 ipif_saved_ire_cnt
* sizeof (ire_t
*));
3233 ipif_refrele(src_ipif
);
3238 if (ip6_asp_table_held
)
3239 ip6_asp_table_refrele(ipst
);
3241 while (irep
> ire_array
) {
3246 (void) ip_srcid_remove(&ipif
->ipif_v6lcl_addr
, ipif
->ipif_zoneid
, ipst
);
3248 if (ipif_saved_irep
!= NULL
) {
3249 kmem_free(ipif_saved_irep
,
3250 ipif_saved_ire_cnt
* sizeof (ire_t
*));
3253 ipif_refrele(src_ipif
);
3255 ipif_ndp_down(ipif
);
3256 ipif_resolver_down(ipif
);
3262 * Delete an ND entry and the corresponding IRE_CACHE entry if it exists.
3266 ip_siocdelndp_v6(ipif_t
*ipif
, sin_t
*dummy_sin
, queue_t
*q
, mblk_t
*mp
,
3267 ip_ioctl_cmd_t
*ipip
, void *dummy_ifreq
)
3271 struct lifreq
*lifr
;
3273 ill_t
*ill
= ipif
->ipif_ill
;
3276 lifr
= (struct lifreq
*)mp
->b_cont
->b_cont
->b_rptr
;
3277 lnr
= &lifr
->lifr_nd
;
3278 /* Only allow for logical unit zero i.e. not on "le0:17" */
3279 if (ipif
->ipif_id
!= 0)
3282 if (!ipif
->ipif_isv6
)
3285 if (lnr
->lnr_addr
.ss_family
!= AF_INET6
)
3286 return (EAFNOSUPPORT
);
3288 sin6
= (sin6_t
*)&lnr
->lnr_addr
;
3291 * Since ND mappings must be consistent across an IPMP group, prohibit
3292 * deleting ND mappings on underlying interfaces. Also, since ND
3293 * mappings for IPMP data addresses are owned by IP itself, prohibit
3296 if (IS_UNDER_IPMP(ill
))
3300 ire
= ire_ctable_lookup_v6(&sin6
->sin6_addr
, NULL
, IRE_LOCAL
,
3301 ipif
, ALL_ZONES
, NULL
, MATCH_IRE_TYPE
| MATCH_IRE_ILL
,
3309 /* See comment in ndp_query() regarding IS_IPMP(ill) usage */
3310 nce
= ndp_lookup_v6(ill
, IS_IPMP(ill
), &sin6
->sin6_addr
, B_FALSE
);
3319 * Return nbr cache info.
3323 ip_siocqueryndp_v6(ipif_t
*ipif
, sin_t
*dummy_sin
, queue_t
*q
, mblk_t
*mp
,
3324 ip_ioctl_cmd_t
*ipip
, void *dummy_ifreq
)
3326 ill_t
*ill
= ipif
->ipif_ill
;
3327 struct lifreq
*lifr
;
3330 lifr
= (struct lifreq
*)mp
->b_cont
->b_cont
->b_rptr
;
3331 lnr
= &lifr
->lifr_nd
;
3332 /* Only allow for logical unit zero i.e. not on "le0:17" */
3333 if (ipif
->ipif_id
!= 0)
3336 if (!ipif
->ipif_isv6
)
3339 if (lnr
->lnr_addr
.ss_family
!= AF_INET6
)
3340 return (EAFNOSUPPORT
);
3342 if (ill
->ill_phys_addr_length
> sizeof (lnr
->lnr_hdw_addr
))
3345 return (ndp_query(ill
, lnr
));
3349 * Perform an update of the nd entry for the specified address.
3353 ip_siocsetndp_v6(ipif_t
*ipif
, sin_t
*dummy_sin
, queue_t
*q
, mblk_t
*mp
,
3354 ip_ioctl_cmd_t
*ipip
, void *dummy_ifreq
)
3357 ill_t
*ill
= ipif
->ipif_ill
;
3358 struct lifreq
*lifr
;
3362 lifr
= (struct lifreq
*)mp
->b_cont
->b_cont
->b_rptr
;
3363 lnr
= &lifr
->lifr_nd
;
3364 /* Only allow for logical unit zero i.e. not on "le0:17" */
3365 if (ipif
->ipif_id
!= 0)
3368 if (!ipif
->ipif_isv6
)
3371 if (lnr
->lnr_addr
.ss_family
!= AF_INET6
)
3372 return (EAFNOSUPPORT
);
3374 sin6
= (sin6_t
*)&lnr
->lnr_addr
;
3377 * Since ND mappings must be consistent across an IPMP group, prohibit
3378 * updating ND mappings on underlying interfaces. Also, since ND
3379 * mappings for IPMP data addresses are owned by IP itself, prohibit
3382 if (IS_UNDER_IPMP(ill
))
3386 ire
= ire_ctable_lookup_v6(&sin6
->sin6_addr
, NULL
, IRE_LOCAL
,
3387 ipif
, ALL_ZONES
, NULL
, MATCH_IRE_TYPE
| MATCH_IRE_ILL
,
3395 return (ndp_sioc_update(ill
, lnr
));