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 (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 1990 Mentat Inc.
24 * Copyright (c) 2013 by Delphix. All rights reserved.
25 * Copyright (c) 2016, Joyent, Inc. All rights reserved.
26 * Copyright (c) 2014, OmniTI Computer Consulting, Inc. All rights reserved.
30 * This file contains the interface control functions for IP.
33 #include <sys/types.h>
34 #include <sys/stream.h>
36 #include <sys/stropts.h>
37 #include <sys/strsun.h>
38 #include <sys/sysmacros.h>
39 #include <sys/strsubr.h>
40 #include <sys/strlog.h>
42 #include <sys/sunddi.h>
43 #include <sys/cmn_err.h>
44 #include <sys/kstat.h>
45 #include <sys/debug.h>
47 #include <sys/sunldi.h>
49 #include <sys/bitmap.h>
50 #include <sys/cpuvar.h>
52 #include <sys/ctype.h>
54 #include <sys/systm.h>
55 #include <sys/param.h>
56 #include <sys/socket.h>
57 #include <sys/isa_defs.h>
59 #include <net/if_arp.h>
60 #include <net/if_types.h>
61 #include <net/if_dl.h>
62 #include <net/route.h>
63 #include <sys/sockio.h>
64 #include <netinet/in.h>
65 #include <netinet/ip6.h>
66 #include <netinet/icmp6.h>
67 #include <netinet/igmp_var.h>
68 #include <sys/policy.h>
69 #include <sys/ethernet.h>
70 #include <sys/callb.h>
73 #include <inet/common.h> /* for various inet/mi.h and inet/nd.h needs */
76 #include <inet/tunables.h>
78 #include <inet/ip_arp.h>
79 #include <inet/mib2.h>
82 #include <inet/ip6_asp.h>
84 #include <inet/ip_multi.h>
85 #include <inet/ip_ire.h>
86 #include <inet/ip_ftable.h>
87 #include <inet/ip_rts.h>
88 #include <inet/ip_ndp.h>
89 #include <inet/ip_if.h>
90 #include <inet/ip_impl.h>
91 #include <inet/sctp_ip.h>
92 #include <inet/ip_netinfo.h>
93 #include <inet/ilb_ip.h>
95 #include <netinet/igmp.h>
96 #include <inet/ip_listutils.h>
97 #include <inet/ipclassifier.h>
98 #include <sys/mac_client.h>
100 #include <sys/mac_flow.h>
102 #include <sys/systeminfo.h>
103 #include <sys/bootconf.h>
105 #include <inet/rawip_impl.h> /* needed for icmp_stack_t */
106 #include <inet/udp_impl.h> /* needed for udp_stack_t */
108 /* The character which tells where the ill_name ends */
109 #define IPIF_SEPARATOR_CHAR ':'
111 /* IP ioctl function table entry */
112 typedef struct ipft_s
{
118 #define IPFT_F_NO_REPLY 0x1 /* IP ioctl does not expect any reply */
119 #define IPFT_F_SELF_REPLY 0x2 /* ioctl callee does the ioctl reply */
121 static int nd_ill_forward_get(queue_t
*, mblk_t
*, caddr_t
, cred_t
*);
122 static int nd_ill_forward_set(queue_t
*q
, mblk_t
*mp
,
123 char *value
, caddr_t cp
, cred_t
*ioc_cr
);
125 static boolean_t
ill_is_quiescent(ill_t
*);
126 static boolean_t
ip_addr_ok_v4(ipaddr_t addr
, ipaddr_t subnet_mask
);
127 static ip_m_t
*ip_m_lookup(t_uscalar_t mac_type
);
128 static int ip_sioctl_addr_tail(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
,
129 mblk_t
*mp
, boolean_t need_up
);
130 static int ip_sioctl_dstaddr_tail(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
,
131 mblk_t
*mp
, boolean_t need_up
);
132 static int ip_sioctl_slifzone_tail(ipif_t
*ipif
, zoneid_t zoneid
,
133 queue_t
*q
, mblk_t
*mp
, boolean_t need_up
);
134 static int ip_sioctl_flags_tail(ipif_t
*ipif
, uint64_t flags
, queue_t
*q
,
136 static int ip_sioctl_netmask_tail(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
,
138 static int ip_sioctl_subnet_tail(ipif_t
*ipif
, in6_addr_t
, in6_addr_t
,
139 queue_t
*q
, mblk_t
*mp
, boolean_t need_up
);
140 static int ip_sioctl_plink_ipmod(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
,
141 int ioccmd
, struct linkblk
*li
);
142 static ipaddr_t
ip_subnet_mask(ipaddr_t addr
, ipif_t
**, ip_stack_t
*);
143 static void ip_wput_ioctl(queue_t
*q
, mblk_t
*mp
);
144 static void ipsq_flush(ill_t
*ill
);
146 static int ip_sioctl_token_tail(ipif_t
*ipif
, sin6_t
*sin6
, int addrlen
,
147 queue_t
*q
, mblk_t
*mp
, boolean_t need_up
);
148 static void ipsq_delete(ipsq_t
*);
150 static ipif_t
*ipif_allocate(ill_t
*ill
, int id
, uint_t ire_type
,
151 boolean_t initialize
, boolean_t insert
, int *errorp
);
152 static ire_t
**ipif_create_bcast_ires(ipif_t
*ipif
, ire_t
**irep
);
153 static void ipif_delete_bcast_ires(ipif_t
*ipif
);
154 static int ipif_add_ires_v4(ipif_t
*, boolean_t
);
155 static boolean_t
ipif_comp_multi(ipif_t
*old_ipif
, ipif_t
*new_ipif
,
157 static int ipif_logical_down(ipif_t
*ipif
, queue_t
*q
, mblk_t
*mp
);
158 static void ipif_free(ipif_t
*ipif
);
159 static void ipif_free_tail(ipif_t
*ipif
);
160 static void ipif_set_default(ipif_t
*ipif
);
161 static int ipif_set_values(queue_t
*q
, mblk_t
*mp
,
162 char *interf_name
, uint_t
*ppa
);
163 static int ipif_set_values_tail(ill_t
*ill
, ipif_t
*ipif
, mblk_t
*mp
,
165 static ipif_t
*ipif_lookup_on_name(char *name
, size_t namelen
,
166 boolean_t do_alloc
, boolean_t
*exists
, boolean_t isv6
, zoneid_t zoneid
,
168 static ipif_t
*ipif_lookup_on_name_async(char *name
, size_t namelen
,
169 boolean_t isv6
, zoneid_t zoneid
, queue_t
*q
, mblk_t
*mp
, ipsq_func_t func
,
170 int *error
, ip_stack_t
*);
172 static int ill_alloc_ppa(ill_if_t
*, ill_t
*);
173 static void ill_delete_interface_type(ill_if_t
*);
174 static int ill_dl_up(ill_t
*ill
, ipif_t
*ipif
, mblk_t
*mp
, queue_t
*q
);
175 static void ill_dl_down(ill_t
*ill
);
176 static void ill_down(ill_t
*ill
);
177 static void ill_down_ipifs(ill_t
*, boolean_t
);
178 static void ill_free_mib(ill_t
*ill
);
179 static void ill_glist_delete(ill_t
*);
180 static void ill_phyint_reinit(ill_t
*ill
);
181 static void ill_set_nce_router_flags(ill_t
*, boolean_t
);
182 static void ill_set_phys_addr_tail(ipsq_t
*, queue_t
*, mblk_t
*, void *);
183 static void ill_replumb_tail(ipsq_t
*, queue_t
*, mblk_t
*, void *);
185 static ip_v6intfid_func_t ip_ether_v6intfid
, ip_ib_v6intfid
;
186 static ip_v6intfid_func_t ip_ipv4_v6intfid
, ip_ipv6_v6intfid
;
187 static ip_v6intfid_func_t ip_ipmp_v6intfid
, ip_nodef_v6intfid
;
188 static ip_v6intfid_func_t ip_ipv4_v6destintfid
, ip_ipv6_v6destintfid
;
189 static ip_v4mapinfo_func_t ip_ether_v4_mapping
;
190 static ip_v6mapinfo_func_t ip_ether_v6_mapping
;
191 static ip_v4mapinfo_func_t ip_ib_v4_mapping
;
192 static ip_v6mapinfo_func_t ip_ib_v6_mapping
;
193 static ip_v4mapinfo_func_t ip_mbcast_mapping
;
194 static void ip_cgtp_bcast_add(ire_t
*, ip_stack_t
*);
195 static void ip_cgtp_bcast_delete(ire_t
*, ip_stack_t
*);
196 static void phyint_free(phyint_t
*);
198 static void ill_capability_dispatch(ill_t
*, mblk_t
*, dl_capability_sub_t
*);
199 static void ill_capability_id_ack(ill_t
*, mblk_t
*, dl_capability_sub_t
*);
200 static void ill_capability_vrrp_ack(ill_t
*, mblk_t
*, dl_capability_sub_t
*);
201 static void ill_capability_hcksum_ack(ill_t
*, mblk_t
*, dl_capability_sub_t
*);
202 static void ill_capability_hcksum_reset_fill(ill_t
*, mblk_t
*);
203 static void ill_capability_zerocopy_ack(ill_t
*, mblk_t
*,
204 dl_capability_sub_t
*);
205 static void ill_capability_zerocopy_reset_fill(ill_t
*, mblk_t
*);
206 static void ill_capability_dld_reset_fill(ill_t
*, mblk_t
*);
207 static void ill_capability_dld_ack(ill_t
*, mblk_t
*,
208 dl_capability_sub_t
*);
209 static void ill_capability_dld_enable(ill_t
*);
210 static void ill_capability_ack_thr(void *);
211 static void ill_capability_lso_enable(ill_t
*);
213 static ill_t
*ill_prev_usesrc(ill_t
*);
214 static int ill_relink_usesrc_ills(ill_t
*, ill_t
*, uint_t
);
215 static void ill_disband_usesrc_group(ill_t
*);
216 static void ip_sioctl_garp_reply(mblk_t
*, ill_t
*, void *, int);
219 static void ill_trace_cleanup(const ill_t
*);
220 static void ipif_trace_cleanup(const ipif_t
*);
223 static void ill_dlpi_clear_deferred(ill_t
*ill
);
225 static void phyint_flags_init(phyint_t
*, t_uscalar_t
);
228 * if we go over the memory footprint limit more than once in this msec
229 * interval, we'll start pruning aggressively.
231 int ip_min_frag_prune_time
= 0;
233 static ipft_t ip_ioctl_ftbl
[] = {
234 { IP_IOC_IRE_DELETE
, ip_ire_delete
, sizeof (ipid_t
), 0 },
235 { IP_IOC_IRE_DELETE_NO_REPLY
, ip_ire_delete
, sizeof (ipid_t
),
237 { IP_IOC_RTS_REQUEST
, ip_rts_request
, 0, IPFT_F_SELF_REPLY
},
241 /* Simple ICMP IP Header Template */
242 static ipha_t icmp_ipha
= {
243 IP_SIMPLE_HDR_VERSION
, 0, 0, 0, 0, 0, IPPROTO_ICMP
246 static uchar_t ip_six_byte_all_ones
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
248 static ip_m_t ip_m_tbl
[] = {
249 { DL_ETHER
, IFT_ETHER
, ETHERTYPE_IP
, ETHERTYPE_IPV6
,
250 ip_ether_v4_mapping
, ip_ether_v6_mapping
, ip_ether_v6intfid
,
252 { DL_CSMACD
, IFT_ISO88023
, ETHERTYPE_IP
, ETHERTYPE_IPV6
,
253 ip_ether_v4_mapping
, ip_ether_v6_mapping
, ip_nodef_v6intfid
,
255 { DL_TPB
, IFT_ISO88024
, ETHERTYPE_IP
, ETHERTYPE_IPV6
,
256 ip_ether_v4_mapping
, ip_ether_v6_mapping
, ip_nodef_v6intfid
,
258 { DL_TPR
, IFT_ISO88025
, ETHERTYPE_IP
, ETHERTYPE_IPV6
,
259 ip_ether_v4_mapping
, ip_ether_v6_mapping
, ip_nodef_v6intfid
,
261 { DL_FDDI
, IFT_FDDI
, ETHERTYPE_IP
, ETHERTYPE_IPV6
,
262 ip_ether_v4_mapping
, ip_ether_v6_mapping
, ip_ether_v6intfid
,
264 { DL_IB
, IFT_IB
, ETHERTYPE_IP
, ETHERTYPE_IPV6
,
265 ip_ib_v4_mapping
, ip_ib_v6_mapping
, ip_ib_v6intfid
,
267 { DL_IPV4
, IFT_IPV4
, IPPROTO_ENCAP
, IPPROTO_IPV6
,
268 ip_mbcast_mapping
, ip_mbcast_mapping
, ip_ipv4_v6intfid
,
269 ip_ipv4_v6destintfid
},
270 { DL_IPV6
, IFT_IPV6
, IPPROTO_ENCAP
, IPPROTO_IPV6
,
271 ip_mbcast_mapping
, ip_mbcast_mapping
, ip_ipv6_v6intfid
,
272 ip_ipv6_v6destintfid
},
273 { DL_6TO4
, IFT_6TO4
, IPPROTO_ENCAP
, IPPROTO_IPV6
,
274 ip_mbcast_mapping
, ip_mbcast_mapping
, ip_ipv4_v6intfid
,
276 { SUNW_DL_VNI
, IFT_OTHER
, ETHERTYPE_IP
, ETHERTYPE_IPV6
,
277 NULL
, NULL
, ip_nodef_v6intfid
, ip_nodef_v6intfid
},
278 { SUNW_DL_IPMP
, IFT_OTHER
, ETHERTYPE_IP
, ETHERTYPE_IPV6
,
279 NULL
, NULL
, ip_ipmp_v6intfid
, ip_nodef_v6intfid
},
280 { DL_OTHER
, IFT_OTHER
, ETHERTYPE_IP
, ETHERTYPE_IPV6
,
281 ip_ether_v4_mapping
, ip_ether_v6_mapping
, ip_nodef_v6intfid
,
285 char ipif_loopback_name
[] = "lo0";
287 /* These are used by all IP network modules. */
288 sin6_t sin6_null
; /* Zero address for quick clears */
289 sin_t sin_null
; /* Zero address for quick clears */
291 /* When set search for unused ipif_seqid */
292 static ipif_t ipif_zero
;
295 * ppa arena is created after these many
296 * interfaces have been plumbed.
298 uint_t ill_no_arena
= 12; /* Setable in /etc/system */
301 * Allocate per-interface mibs.
302 * Returns true if ok. False otherwise.
303 * ipsq may not yet be allocated (loopback case ).
306 ill_allocate_mibs(ill_t
*ill
)
308 /* Already allocated? */
309 if (ill
->ill_ip_mib
!= NULL
) {
311 ASSERT(ill
->ill_icmp6_mib
!= NULL
);
315 ill
->ill_ip_mib
= kmem_zalloc(sizeof (*ill
->ill_ip_mib
),
317 if (ill
->ill_ip_mib
== NULL
) {
321 /* Setup static information */
322 SET_MIB(ill
->ill_ip_mib
->ipIfStatsEntrySize
,
323 sizeof (mib2_ipIfStatsEntry_t
));
325 ill
->ill_ip_mib
->ipIfStatsIPVersion
= MIB2_INETADDRESSTYPE_ipv6
;
326 SET_MIB(ill
->ill_ip_mib
->ipIfStatsAddrEntrySize
,
327 sizeof (mib2_ipv6AddrEntry_t
));
328 SET_MIB(ill
->ill_ip_mib
->ipIfStatsRouteEntrySize
,
329 sizeof (mib2_ipv6RouteEntry_t
));
330 SET_MIB(ill
->ill_ip_mib
->ipIfStatsNetToMediaEntrySize
,
331 sizeof (mib2_ipv6NetToMediaEntry_t
));
332 SET_MIB(ill
->ill_ip_mib
->ipIfStatsMemberEntrySize
,
333 sizeof (ipv6_member_t
));
334 SET_MIB(ill
->ill_ip_mib
->ipIfStatsGroupSourceEntrySize
,
335 sizeof (ipv6_grpsrc_t
));
337 ill
->ill_ip_mib
->ipIfStatsIPVersion
= MIB2_INETADDRESSTYPE_ipv4
;
338 SET_MIB(ill
->ill_ip_mib
->ipIfStatsAddrEntrySize
,
339 sizeof (mib2_ipAddrEntry_t
));
340 SET_MIB(ill
->ill_ip_mib
->ipIfStatsRouteEntrySize
,
341 sizeof (mib2_ipRouteEntry_t
));
342 SET_MIB(ill
->ill_ip_mib
->ipIfStatsNetToMediaEntrySize
,
343 sizeof (mib2_ipNetToMediaEntry_t
));
344 SET_MIB(ill
->ill_ip_mib
->ipIfStatsMemberEntrySize
,
345 sizeof (ip_member_t
));
346 SET_MIB(ill
->ill_ip_mib
->ipIfStatsGroupSourceEntrySize
,
347 sizeof (ip_grpsrc_t
));
350 * For a v4 ill, we are done at this point, because per ill
351 * icmp mibs are only used for v6.
356 ill
->ill_icmp6_mib
= kmem_zalloc(sizeof (*ill
->ill_icmp6_mib
),
358 if (ill
->ill_icmp6_mib
== NULL
) {
359 kmem_free(ill
->ill_ip_mib
, sizeof (*ill
->ill_ip_mib
));
360 ill
->ill_ip_mib
= NULL
;
363 /* static icmp info */
364 ill
->ill_icmp6_mib
->ipv6IfIcmpEntrySize
=
365 sizeof (mib2_ipv6IfIcmpEntry_t
);
367 * The ipIfStatsIfindex and ipv6IfIcmpIndex will be assigned later
368 * after the phyint merge occurs in ipif_set_values -> ill_glist_insert
369 * -> ill_phyint_reinit
375 * Completely vaporize a lower level tap and all associated interfaces.
376 * ill_delete is called only out of ip_close when the device control
377 * stream is being closed.
380 ill_delete(ill_t
*ill
)
384 ip_stack_t
*ipst
= ill
->ill_ipst
;
387 * ill_delete may be forcibly entering the ipsq. The previous
388 * ioctl may not have completed and may need to be aborted.
389 * ipsq_flush takes care of it. If we don't need to enter the
390 * the ipsq forcibly, the 2nd invocation of ipsq_flush in
391 * ill_delete_tail is sufficient.
396 * Nuke all interfaces. ipif_free will take down the interface,
397 * remove it from the list, and free the data structure.
398 * Walk down the ipif list and remove the logical interfaces
399 * first before removing the main ipif. We can't unplumb
400 * zeroth interface first in the case of IPv6 as update_conn_ill
401 * -> ip_ll_multireq de-references ill_ipif for checking
404 * If ill_ipif was not properly initialized (i.e low on memory),
405 * then no interfaces to clean up. In this case just clean up the
408 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
)
412 * clean out all the nce_t entries that depend on this
413 * ill for the ill_phys_addr.
415 nce_flush(ill
, B_TRUE
);
417 /* Clean up msgs on pending upcalls for mrouted */
420 update_conn_ill(ill
, ipst
);
423 * Remove multicast references added as a result of calls to
424 * ip_join_allmulti().
426 ip_purge_allmulti(ill
);
429 * If the ill being deleted is under IPMP, boot it out of the illgrp.
431 if (IS_UNDER_IPMP(ill
))
432 ipmp_ill_leave_illgrp(ill
);
435 * ill_down will arrange to blow off any IRE's dependent on this
436 * ILL, and shut down fragmentation reassembly.
440 /* Let SCTP know, so that it can remove this from its list. */
441 sctp_update_ill(ill
, SCTP_ILL_REMOVE
);
444 * Walk all CONNs that can have a reference on an ire or nce for this
445 * ill (we actually walk all that now have stale references).
447 ipcl_walk(conn_ixa_cleanup
, (void *)B_TRUE
, ipst
);
449 /* With IPv6 we have dce_ifindex. Cleanup for neatness */
451 dce_cleanup(ill
->ill_phyint
->phyint_ifindex
, ipst
);
454 * If an address on this ILL is being used as a source address then
455 * clear out the pointers in other ILLs that point to this ILL.
457 rw_enter(&ipst
->ips_ill_g_usesrc_lock
, RW_WRITER
);
458 if (ill
->ill_usesrc_grp_next
!= NULL
) {
459 if (ill
->ill_usesrc_ifindex
== 0) { /* usesrc ILL ? */
460 ill_disband_usesrc_group(ill
);
461 } else { /* consumer of the usesrc ILL */
462 prev_ill
= ill_prev_usesrc(ill
);
463 prev_ill
->ill_usesrc_grp_next
=
464 ill
->ill_usesrc_grp_next
;
467 rw_exit(&ipst
->ips_ill_g_usesrc_lock
);
471 ipif_non_duplicate(ipif_t
*ipif
)
473 ill_t
*ill
= ipif
->ipif_ill
;
474 mutex_enter(&ill
->ill_lock
);
475 if (ipif
->ipif_flags
& IPIF_DUPLICATE
) {
476 ipif
->ipif_flags
&= ~IPIF_DUPLICATE
;
477 ASSERT(ill
->ill_ipif_dup_count
> 0);
478 ill
->ill_ipif_dup_count
--;
480 mutex_exit(&ill
->ill_lock
);
484 * ill_delete_tail is called from ip_modclose after all references
485 * to the closing ill are gone. The wait is done in ip_modclose
488 ill_delete_tail(ill_t
*ill
)
492 ip_stack_t
*ipst
= ill
->ill_ipst
;
494 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
495 ipif_non_duplicate(ipif
);
496 (void) ipif_down_tail(ipif
);
499 ASSERT(ill
->ill_ipif_dup_count
== 0);
502 * If polling capability is enabled (which signifies direct
503 * upcall into IP and driver has ill saved as a handle),
504 * we need to make sure that unbind has completed before we
505 * let the ill disappear and driver no longer has any reference
508 mutex_enter(&ill
->ill_lock
);
509 while (ill
->ill_state_flags
& ILL_DL_UNBIND_IN_PROGRESS
)
510 cv_wait(&ill
->ill_cv
, &ill
->ill_lock
);
511 mutex_exit(&ill
->ill_lock
);
512 ASSERT(!(ill
->ill_capabilities
&
513 (ILL_CAPAB_DLD
| ILL_CAPAB_DLD_POLL
| ILL_CAPAB_DLD_DIRECT
)));
515 if (ill
->ill_net_type
!= IRE_LOOPBACK
)
516 qprocsoff(ill
->ill_rq
);
519 * We do an ipsq_flush once again now. New messages could have
520 * landed up from below (M_ERROR or M_HANGUP). Similarly ioctls
521 * could also have landed up if an ioctl thread had looked up
522 * the ill before we set the ILL_CONDEMNED flag, but not yet
523 * enqueued the ioctl when we did the ipsq_flush last time.
530 if (ill
->ill_hcksum_capab
!= NULL
) {
531 kmem_free(ill
->ill_hcksum_capab
, sizeof (ill_hcksum_capab_t
));
532 ill
->ill_hcksum_capab
= NULL
;
535 if (ill
->ill_zerocopy_capab
!= NULL
) {
536 kmem_free(ill
->ill_zerocopy_capab
,
537 sizeof (ill_zerocopy_capab_t
));
538 ill
->ill_zerocopy_capab
= NULL
;
541 if (ill
->ill_lso_capab
!= NULL
) {
542 kmem_free(ill
->ill_lso_capab
, sizeof (ill_lso_capab_t
));
543 ill
->ill_lso_capab
= NULL
;
546 if (ill
->ill_dld_capab
!= NULL
) {
547 kmem_free(ill
->ill_dld_capab
, sizeof (ill_dld_capab_t
));
548 ill
->ill_dld_capab
= NULL
;
551 /* Clean up ill_allowed_ips* related state */
552 if (ill
->ill_allowed_ips
!= NULL
) {
553 ASSERT(ill
->ill_allowed_ips_cnt
> 0);
554 kmem_free(ill
->ill_allowed_ips
,
555 ill
->ill_allowed_ips_cnt
* sizeof (in6_addr_t
));
556 ill
->ill_allowed_ips
= NULL
;
557 ill
->ill_allowed_ips_cnt
= 0;
560 while (ill
->ill_ipif
!= NULL
)
561 ipif_free_tail(ill
->ill_ipif
);
564 * We have removed all references to ilm from conn and the ones joined
567 * We don't walk conns, mrts and ires because
569 * 1) update_conn_ill and reset_mrt_ill cleans up conns and mrts.
570 * 2) ill_down ->ill_downi walks all the ires and cleans up
575 * If this ill is an IPMP meta-interface, blow away the illgrp. This
576 * is safe to do because the illgrp has already been unlinked from the
577 * group by I_PUNLINK, and thus SIOCSLIFGROUPNAME cannot find it.
580 ipmp_illgrp_destroy(ill
->ill_grp
);
584 if (ill
->ill_mphysaddr_list
!= NULL
) {
585 multiphysaddr_t
*mpa
, *tmpa
;
587 mpa
= ill
->ill_mphysaddr_list
;
588 ill
->ill_mphysaddr_list
= NULL
;
590 tmpa
= mpa
->mpa_next
;
591 kmem_free(mpa
, sizeof (*mpa
));
596 * Take us out of the list of ILLs. ill_glist_delete -> phyint_free
597 * could free the phyint. No more reference to the phyint after this
600 (void) ill_glist_delete(ill
);
602 if (ill
->ill_frag_ptr
!= NULL
) {
605 for (count
= 0; count
< ILL_FRAG_HASH_TBL_COUNT
; count
++) {
606 mutex_destroy(&ill
->ill_frag_hash_tbl
[count
].ipfb_lock
);
608 mi_free(ill
->ill_frag_ptr
);
609 ill
->ill_frag_ptr
= NULL
;
610 ill
->ill_frag_hash_tbl
= NULL
;
613 freemsg(ill
->ill_nd_lla_mp
);
614 /* Free all retained control messages. */
615 mpp
= &ill
->ill_first_mp_to_free
;
623 for (mp1
= mp
; mp1
!= NULL
; mp1
= mp1
->b_cont
) {
629 } while (mpp
++ != &ill
->ill_last_mp_to_free
);
634 ill_trace_cleanup(ill
);
637 /* The default multicast interface might have changed */
638 ire_increment_multicast_generation(ipst
, ill
->ill_isv6
);
640 /* Drop refcnt here */
641 netstack_rele(ill
->ill_ipst
->ips_netstack
);
642 ill
->ill_ipst
= NULL
;
646 ill_free_mib(ill_t
*ill
)
648 ip_stack_t
*ipst
= ill
->ill_ipst
;
651 * MIB statistics must not be lost, so when an interface
652 * goes away the counter values will be added to the global
655 if (ill
->ill_ip_mib
!= NULL
) {
657 ip_mib2_add_ip_stats(&ipst
->ips_ip6_mib
,
660 ip_mib2_add_ip_stats(&ipst
->ips_ip_mib
,
664 kmem_free(ill
->ill_ip_mib
, sizeof (*ill
->ill_ip_mib
));
665 ill
->ill_ip_mib
= NULL
;
667 if (ill
->ill_icmp6_mib
!= NULL
) {
668 ip_mib2_add_icmp6_stats(&ipst
->ips_icmp6_mib
,
670 kmem_free(ill
->ill_icmp6_mib
, sizeof (*ill
->ill_icmp6_mib
));
671 ill
->ill_icmp6_mib
= NULL
;
676 * Concatenate together a physical address and a sap.
678 * Sap_lengths are interpreted as follows:
679 * sap_length == 0 ==> no sap
680 * sap_length > 0 ==> sap is at the head of the dlpi address
681 * sap_length < 0 ==> sap is at the tail of the dlpi address
684 ill_dlur_copy_address(uchar_t
*phys_src
, uint_t phys_length
,
685 t_scalar_t sap_src
, t_scalar_t sap_length
, uchar_t
*dst
)
687 uint16_t sap_addr
= (uint16_t)sap_src
;
689 if (sap_length
== 0) {
690 if (phys_src
== NULL
)
691 bzero(dst
, phys_length
);
693 bcopy(phys_src
, dst
, phys_length
);
694 } else if (sap_length
< 0) {
695 if (phys_src
== NULL
)
696 bzero(dst
, phys_length
);
698 bcopy(phys_src
, dst
, phys_length
);
699 bcopy(&sap_addr
, (char *)dst
+ phys_length
, sizeof (sap_addr
));
701 bcopy(&sap_addr
, dst
, sizeof (sap_addr
));
702 if (phys_src
== NULL
)
703 bzero((char *)dst
+ sap_length
, phys_length
);
705 bcopy(phys_src
, (char *)dst
+ sap_length
, phys_length
);
710 * Generate a dl_unitdata_req mblk for the device and address given.
711 * addr_length is the length of the physical portion of the address.
712 * If addr is NULL include an all zero address of the specified length.
713 * TRUE? In any case, addr_length is taken to be the entire length of the
714 * dlpi address, including the absolute value of sap_length.
717 ill_dlur_gen(uchar_t
*addr
, uint_t addr_length
, t_uscalar_t sap
,
718 t_scalar_t sap_length
)
720 dl_unitdata_req_t
*dlur
;
722 t_scalar_t abs_sap_length
; /* absolute value */
724 abs_sap_length
= ABS(sap_length
);
725 mp
= ip_dlpi_alloc(sizeof (*dlur
) + addr_length
+ abs_sap_length
,
729 dlur
= (dl_unitdata_req_t
*)mp
->b_rptr
;
730 /* HACK: accomodate incompatible DLPI drivers */
731 if (addr_length
== 8)
733 dlur
->dl_dest_addr_length
= addr_length
+ abs_sap_length
;
734 dlur
->dl_dest_addr_offset
= sizeof (*dlur
);
735 dlur
->dl_priority
.dl_min
= 0;
736 dlur
->dl_priority
.dl_max
= 0;
737 ill_dlur_copy_address(addr
, addr_length
, sap
, sap_length
,
738 (uchar_t
*)&dlur
[1]);
743 * Add the pending mp to the list. There can be only 1 pending mp
744 * in the list. Any exclusive ioctl that needs to wait for a response
745 * from another module or driver needs to use this function to set
746 * the ipx_pending_mp to the ioctl mblk and wait for the response from
747 * the other module/driver. This is also used while waiting for the
748 * ipif/ill/ire refcnts to drop to zero in bringing down an ipif.
751 ipsq_pending_mp_add(conn_t
*connp
, ipif_t
*ipif
, queue_t
*q
, mblk_t
*add_mp
,
754 ipxop_t
*ipx
= ipif
->ipif_ill
->ill_phyint
->phyint_ipsq
->ipsq_xop
;
756 ASSERT(IAM_WRITER_IPIF(ipif
));
757 ASSERT(MUTEX_HELD(&ipif
->ipif_ill
->ill_lock
));
758 ASSERT((add_mp
->b_next
== NULL
) && (add_mp
->b_prev
== NULL
));
759 ASSERT(ipx
->ipx_pending_mp
== NULL
);
761 * The caller may be using a different ipif than the one passed into
762 * ipsq_current_start() (e.g., suppose an ioctl that came in on the V4
763 * ill needs to wait for the V6 ill to quiesce). So we can't ASSERT
764 * that `ipx_current_ipif == ipif'.
766 ASSERT(ipx
->ipx_current_ipif
!= NULL
);
769 * M_IOCDATA from ioctls, M_ERROR/M_HANGUP/M_PROTO/M_PCPROTO from the
772 ASSERT((DB_TYPE(add_mp
) == M_IOCDATA
) || (DB_TYPE(add_mp
) == M_ERROR
) ||
773 (DB_TYPE(add_mp
) == M_HANGUP
) || (DB_TYPE(add_mp
) == M_PROTO
) ||
774 (DB_TYPE(add_mp
) == M_PCPROTO
));
777 ASSERT(MUTEX_HELD(&connp
->conn_lock
));
779 * Return error if the conn has started closing. The conn
780 * could have finished cleaning up the pending mp list,
781 * If so we should not add another mp to the list negating
784 if (connp
->conn_state_flags
& CONN_CLOSING
)
787 mutex_enter(&ipx
->ipx_lock
);
788 ipx
->ipx_pending_ipif
= ipif
;
790 * Note down the queue in b_queue. This will be returned by
791 * ipsq_pending_mp_get. Caller will then use these values to restart
794 add_mp
->b_next
= NULL
;
796 ipx
->ipx_pending_mp
= add_mp
;
797 ipx
->ipx_waitfor
= waitfor
;
798 mutex_exit(&ipx
->ipx_lock
);
801 connp
->conn_oper_pending_ill
= ipif
->ipif_ill
;
807 * Retrieve the ipx_pending_mp and return it. There can be only 1 mp
808 * queued in the list.
811 ipsq_pending_mp_get(ipsq_t
*ipsq
, conn_t
**connpp
)
814 ipxop_t
*ipx
= ipsq
->ipsq_xop
;
817 mutex_enter(&ipx
->ipx_lock
);
818 if (ipx
->ipx_pending_mp
== NULL
) {
819 mutex_exit(&ipx
->ipx_lock
);
823 /* There can be only 1 such excl message */
824 curr
= ipx
->ipx_pending_mp
;
825 ASSERT(curr
->b_next
== NULL
);
826 ipx
->ipx_pending_ipif
= NULL
;
827 ipx
->ipx_pending_mp
= NULL
;
828 ipx
->ipx_waitfor
= 0;
829 mutex_exit(&ipx
->ipx_lock
);
831 if (CONN_Q(curr
->b_queue
)) {
833 * This mp did a refhold on the conn, at the start of the ioctl.
834 * So we can safely return a pointer to the conn to the caller.
836 *connpp
= Q_TO_CONN(curr
->b_queue
);
846 * Cleanup the ioctl mp queued in ipx_pending_mp
847 * - Called in the ill_delete path
848 * - Called in the M_ERROR or M_HANGUP path on the ill.
849 * - Called in the conn close path.
851 * Returns success on finding the pending mblk associated with the ioctl or
852 * exclusive operation in progress, failure otherwise.
855 ipsq_pending_mp_cleanup(ill_t
*ill
, conn_t
*connp
)
863 ASSERT(IAM_WRITER_ILL(ill
));
864 ipx
= ill
->ill_phyint
->phyint_ipsq
->ipsq_xop
;
866 mutex_enter(&ipx
->ipx_lock
);
867 mp
= ipx
->ipx_pending_mp
;
869 if (mp
== NULL
|| mp
->b_queue
!= CONNP_TO_WQ(connp
)) {
871 * Nothing to clean since the conn that is closing
872 * does not have a matching pending mblk in
875 mutex_exit(&ipx
->ipx_lock
);
880 * A non-zero ill_error signifies we are called in the
881 * M_ERROR or M_HANGUP path and we need to unconditionally
882 * abort any current ioctl and do the corresponding cleanup.
883 * A zero ill_error means we are in the ill_delete path and
884 * we do the cleanup only if there is a pending mp.
886 if (mp
== NULL
&& ill
->ill_error
== 0) {
887 mutex_exit(&ipx
->ipx_lock
);
892 /* Now remove from the ipx_pending_mp */
893 ipx
->ipx_pending_mp
= NULL
;
894 ipif
= ipx
->ipx_pending_ipif
;
895 ipx
->ipx_pending_ipif
= NULL
;
896 ipx
->ipx_waitfor
= 0;
897 ipx
->ipx_current_ipif
= NULL
;
898 cmd
= ipx
->ipx_current_ioctl
;
899 ipx
->ipx_current_ioctl
= 0;
900 ipx
->ipx_current_done
= B_TRUE
;
901 mutex_exit(&ipx
->ipx_lock
);
911 if (DB_TYPE(mp
) == M_IOCTL
|| DB_TYPE(mp
) == M_IOCDATA
) {
912 DTRACE_PROBE4(ipif__ioctl
,
913 char *, "ipsq_pending_mp_cleanup",
914 int, cmd
, ill_t
*, ipif
== NULL
? NULL
: ipif
->ipif_ill
,
917 ip_ioctl_finish(q
, mp
, ENXIO
, NO_COPYOUT
, NULL
);
919 ip_ioctl_finish(q
, mp
, ENXIO
, CONN_CLOSE
, NULL
);
920 mutex_enter(&ipif
->ipif_ill
->ill_lock
);
921 ipif
->ipif_state_flags
&= ~IPIF_CHANGING
;
922 mutex_exit(&ipif
->ipif_ill
->ill_lock
);
931 * Called in the conn close path and ill delete path
934 ipsq_xopq_mp_cleanup(ill_t
*ill
, conn_t
*connp
)
940 queue_t
*wq
, *rq
= NULL
;
941 mblk_t
*tmp_list
= NULL
;
943 ASSERT(IAM_WRITER_ILL(ill
));
945 wq
= CONNP_TO_WQ(connp
);
950 * In the case of lo0 being unplumbed, ill_wq will be NULL. Guard
956 ipsq
= ill
->ill_phyint
->phyint_ipsq
;
958 * Cleanup the ioctl mp's queued in ipsq_xopq_pending_mp if any.
959 * In the case of ioctl from a conn, there can be only 1 mp
960 * queued on the ipsq. If an ill is being unplumbed flush all
963 mutex_enter(&ipsq
->ipsq_lock
);
964 for (prev
= NULL
, curr
= ipsq
->ipsq_xopq_mphead
; curr
!= NULL
;
968 (curr
->b_queue
== wq
|| curr
->b_queue
== rq
)) {
969 /* Unlink the mblk from the pending mp list */
971 prev
->b_next
= curr
->b_next
;
973 ASSERT(ipsq
->ipsq_xopq_mphead
== curr
);
974 ipsq
->ipsq_xopq_mphead
= curr
->b_next
;
976 if (ipsq
->ipsq_xopq_mptail
== curr
)
977 ipsq
->ipsq_xopq_mptail
= prev
;
979 * Create a temporary list and release the ipsq lock
980 * New elements are added to the head of the tmp_list
982 curr
->b_next
= tmp_list
;
988 mutex_exit(&ipsq
->ipsq_lock
);
990 while (tmp_list
!= NULL
) {
992 tmp_list
= curr
->b_next
;
996 curr
->b_queue
= NULL
;
997 if (DB_TYPE(curr
) == M_IOCTL
|| DB_TYPE(curr
) == M_IOCDATA
) {
998 DTRACE_PROBE4(ipif__ioctl
,
999 char *, "ipsq_xopq_mp_cleanup",
1000 int, 0, ill_t
*, NULL
, ipif_t
*, NULL
);
1001 ip_ioctl_finish(wq
, curr
, ENXIO
, connp
!= NULL
?
1002 CONN_CLOSE
: NO_COPYOUT
, NULL
);
1005 * IP-MT XXX In the case of TLI/XTI bind / optmgmt
1006 * this can't be just inet_freemsg. we have to
1007 * restart it otherwise the thread will be stuck.
1015 * This conn has started closing. Cleanup any pending ioctl from this conn.
1016 * STREAMS ensures that there can be at most 1 active ioctl on a stream.
1019 conn_ioctl_cleanup(conn_t
*connp
)
1026 * Check for a queued ioctl. If the ioctl has not yet started, the mp
1027 * is pending in the list headed by ipsq_xopq_head. If the ioctl has
1028 * started the mp could be present in ipx_pending_mp. Note that if
1029 * conn_oper_pending_ill is NULL, the ioctl may still be in flight and
1030 * not yet queued anywhere. In this case, the conn close code will wait
1031 * until the conn_ref is dropped. If the stream was a tcp stream, then
1032 * tcp_close will wait first until all ioctls have completed for this
1035 mutex_enter(&connp
->conn_lock
);
1036 ill
= connp
->conn_oper_pending_ill
;
1038 mutex_exit(&connp
->conn_lock
);
1043 * We may not be able to refhold the ill if the ill/ipif
1044 * is changing. But we need to make sure that the ill will
1045 * not vanish. So we just bump up the ill_waiter count.
1047 refheld
= ill_waiter_inc(ill
);
1048 mutex_exit(&connp
->conn_lock
);
1050 if (ipsq_enter(ill
, B_TRUE
, NEW_OP
)) {
1051 ill_waiter_dcr(ill
);
1053 * Check whether this ioctl has started and is
1054 * pending. If it is not found there then check
1055 * whether this ioctl has not even started and is in
1056 * the ipsq_xopq list.
1058 if (!ipsq_pending_mp_cleanup(ill
, connp
))
1059 ipsq_xopq_mp_cleanup(ill
, connp
);
1060 ipsq
= ill
->ill_phyint
->phyint_ipsq
;
1067 * The ill is also closing and we could not bump up the
1068 * ill_waiter_count or we could not enter the ipsq. Leave
1069 * the cleanup to ill_delete
1071 mutex_enter(&connp
->conn_lock
);
1072 while (connp
->conn_oper_pending_ill
!= NULL
)
1073 cv_wait(&connp
->conn_refcv
, &connp
->conn_lock
);
1074 mutex_exit(&connp
->conn_lock
);
1076 ill_waiter_dcr(ill
);
1080 * ipcl_walk function for cleaning up conn_*_ill fields.
1081 * Note that we leave ixa_multicast_ifindex, conn_incoming_ifindex, and
1082 * conn_bound_if in place. We prefer dropping
1083 * packets instead of sending them out the wrong interface, or accepting
1084 * packets from the wrong ifindex.
1087 conn_cleanup_ill(conn_t
*connp
, caddr_t arg
)
1089 ill_t
*ill
= (ill_t
*)arg
;
1091 mutex_enter(&connp
->conn_lock
);
1092 if (connp
->conn_dhcpinit_ill
== ill
) {
1093 connp
->conn_dhcpinit_ill
= NULL
;
1094 ASSERT(ill
->ill_dhcpinit
!= 0);
1095 atomic_dec_32(&ill
->ill_dhcpinit
);
1096 ill_set_inputfn(ill
);
1098 mutex_exit(&connp
->conn_lock
);
1102 ill_down_ipifs_tail(ill_t
*ill
)
1107 ASSERT(IAM_WRITER_ILL(ill
));
1108 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
1109 ipif_non_duplicate(ipif
);
1111 * ipif_down_tail will call arp_ll_down on the last ipif
1112 * and typically return EINPROGRESS when the DL_UNBIND is sent.
1114 if ((err
= ipif_down_tail(ipif
)) != 0)
1122 ipif_all_down_tail(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
, void *dummy_arg
)
1124 ASSERT(IAM_WRITER_IPSQ(ipsq
));
1125 (void) ill_down_ipifs_tail(q
->q_ptr
);
1127 ipsq_current_finish(ipsq
);
1131 * ill_down_start is called when we want to down this ill and bring it up again
1132 * It is called when we receive an M_ERROR / M_HANGUP. In this case we shut down
1133 * all interfaces, but don't tear down any plumbing.
1136 ill_down_start(queue_t
*q
, mblk_t
*mp
)
1138 ill_t
*ill
= q
->q_ptr
;
1141 ASSERT(IAM_WRITER_ILL(ill
));
1143 * It is possible that some ioctl is already in progress while we
1144 * received the M_ERROR / M_HANGUP in which case, we need to abort
1145 * the ioctl. ill_down_start() is being processed as CUR_OP rather
1146 * than as NEW_OP since the cause of the M_ERROR / M_HANGUP may prevent
1147 * the in progress ioctl from ever completing.
1149 * The thread that started the ioctl (if any) must have returned,
1150 * since we are now executing as writer. After the 2 calls below,
1151 * the state of the ipsq and the ill would reflect no trace of any
1152 * pending operation. Subsequently if there is any response to the
1153 * original ioctl from the driver, it would be discarded as an
1154 * unsolicited message from the driver.
1156 (void) ipsq_pending_mp_cleanup(ill
, NULL
);
1157 ill_dlpi_clear_deferred(ill
);
1159 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
)
1160 (void) ipif_down(ipif
, NULL
, NULL
);
1165 * Walk all CONNs that can have a reference on an ire or nce for this
1166 * ill (we actually walk all that now have stale references).
1168 ipcl_walk(conn_ixa_cleanup
, (void *)B_TRUE
, ill
->ill_ipst
);
1170 /* With IPv6 we have dce_ifindex. Cleanup for neatness */
1172 dce_cleanup(ill
->ill_phyint
->phyint_ifindex
, ill
->ill_ipst
);
1174 ipsq_current_start(ill
->ill_phyint
->phyint_ipsq
, ill
->ill_ipif
, 0);
1177 * Atomically test and add the pending mp if references are active.
1179 mutex_enter(&ill
->ill_lock
);
1180 if (!ill_is_quiescent(ill
)) {
1181 /* call cannot fail since `conn_t *' argument is NULL */
1182 (void) ipsq_pending_mp_add(NULL
, ill
->ill_ipif
, ill
->ill_rq
,
1184 mutex_exit(&ill
->ill_lock
);
1187 mutex_exit(&ill
->ill_lock
);
1192 ill_down(ill_t
*ill
)
1195 ip_stack_t
*ipst
= ill
->ill_ipst
;
1198 * Blow off any IREs dependent on this ILL.
1199 * The caller needs to handle conn_ixa_cleanup
1201 ill_delete_ires(ill
);
1203 ire_walk_ill(0, 0, ill_downi
, ill
, ill
);
1205 /* Remove any conn_*_ill depending on this ill */
1206 ipcl_walk(conn_cleanup_ill
, (caddr_t
)ill
, ipst
);
1209 * Free state for additional IREs.
1211 mutex_enter(&ill
->ill_saved_ire_lock
);
1212 mp
= ill
->ill_saved_ire_mp
;
1213 ill
->ill_saved_ire_mp
= NULL
;
1214 ill
->ill_saved_ire_cnt
= 0;
1215 mutex_exit(&ill
->ill_saved_ire_lock
);
1220 * ire_walk routine used to delete every IRE that depends on
1221 * 'ill'. (Always called as writer, and may only be called from ire_walk.)
1223 * Note: since the routes added by the kernel are deleted separately,
1224 * this will only be 1) IRE_IF_CLONE and 2) manually added IRE_INTERFACE.
1226 * We also remove references on ire_nce_cache entries that refer to the ill.
1229 ill_downi(ire_t
*ire
, char *ill_arg
)
1231 ill_t
*ill
= (ill_t
*)ill_arg
;
1234 mutex_enter(&ire
->ire_lock
);
1235 nce
= ire
->ire_nce_cache
;
1236 if (nce
!= NULL
&& nce
->nce_ill
== ill
)
1237 ire
->ire_nce_cache
= NULL
;
1240 mutex_exit(&ire
->ire_lock
);
1243 if (ire
->ire_ill
== ill
) {
1245 * The existing interface binding for ire must be
1246 * deleted before trying to bind the route to another
1247 * interface. However, since we are using the contents of the
1248 * ire after ire_delete, the caller has to ensure that
1249 * CONDEMNED (deleted) ire's are not removed from the list
1250 * when ire_delete() returns. Currently ill_downi() is
1251 * only called as part of ire_walk*() routines, so that
1252 * the irb_refhold() done by ire_walk*() will ensure that
1253 * ire_delete() does not lead to ire_inactive().
1255 ASSERT(ire
->ire_bucket
->irb_refcnt
> 0);
1257 if (ire
->ire_unbound
)
1262 /* Remove IRE_IF_CLONE on this ill */
1264 ill_downi_if_clone(ire_t
*ire
, char *ill_arg
)
1266 ill_t
*ill
= (ill_t
*)ill_arg
;
1268 ASSERT(ire
->ire_type
& IRE_IF_CLONE
);
1269 if (ire
->ire_ill
== ill
)
1273 /* Consume an M_IOCACK of the fastpath probe. */
1275 ill_fastpath_ack(ill_t
*ill
, mblk_t
*mp
)
1280 * If this was the first attempt turn on the fastpath probing.
1282 mutex_enter(&ill
->ill_lock
);
1283 if (ill
->ill_dlpi_fastpath_state
== IDS_INPROGRESS
)
1284 ill
->ill_dlpi_fastpath_state
= IDS_OK
;
1285 mutex_exit(&ill
->ill_lock
);
1287 /* Free the M_IOCACK mblk, hold on to the data */
1292 if (mp
->b_cont
!= NULL
)
1293 nce_fastpath_update(ill
, mp
);
1295 ip0dbg(("ill_fastpath_ack: no b_cont\n"));
1300 * Throw an M_IOCTL message downstream asking "do you know fastpath?"
1301 * The data portion of the request is a dl_unitdata_req_t template for
1302 * what we would send downstream in the absence of a fastpath confirmation.
1305 ill_fastpath_probe(ill_t
*ill
, mblk_t
*dlur_mp
)
1310 if (dlur_mp
== NULL
)
1313 mutex_enter(&ill
->ill_lock
);
1314 switch (ill
->ill_dlpi_fastpath_state
) {
1317 * Driver NAKed the first fastpath ioctl - assume it doesn't
1320 mutex_exit(&ill
->ill_lock
);
1323 /* This is the first probe */
1324 ill
->ill_dlpi_fastpath_state
= IDS_INPROGRESS
;
1329 mutex_exit(&ill
->ill_lock
);
1331 if ((mp
= mkiocb(DL_IOC_HDR_INFO
)) == NULL
)
1334 mp
->b_cont
= copyb(dlur_mp
);
1335 if (mp
->b_cont
== NULL
) {
1340 ioc
= (struct iocblk
*)mp
->b_rptr
;
1341 ioc
->ioc_count
= msgdsize(mp
->b_cont
);
1343 DTRACE_PROBE3(ill__dlpi
, char *, "ill_fastpath_probe",
1344 char *, "DL_IOC_HDR_INFO", ill_t
*, ill
);
1345 putnext(ill
->ill_wq
, mp
);
1350 ill_capability_probe(ill_t
*ill
)
1354 ASSERT(IAM_WRITER_ILL(ill
));
1356 if (ill
->ill_dlpi_capab_state
!= IDCS_UNKNOWN
&&
1357 ill
->ill_dlpi_capab_state
!= IDCS_FAILED
)
1361 * We are starting a new cycle of capability negotiation.
1362 * Free up the capab reset messages of any previous incarnation.
1363 * We will do a fresh allocation when we get the response to our probe
1365 if (ill
->ill_capab_reset_mp
!= NULL
) {
1366 freemsg(ill
->ill_capab_reset_mp
);
1367 ill
->ill_capab_reset_mp
= NULL
;
1370 ip1dbg(("ill_capability_probe: starting capability negotiation\n"));
1372 mp
= ip_dlpi_alloc(sizeof (dl_capability_req_t
), DL_CAPABILITY_REQ
);
1376 ill_capability_send(ill
, mp
);
1377 ill
->ill_dlpi_capab_state
= IDCS_PROBE_SENT
;
1381 ill_capability_reset(ill_t
*ill
, boolean_t reneg
)
1383 ASSERT(IAM_WRITER_ILL(ill
));
1385 if (ill
->ill_dlpi_capab_state
!= IDCS_OK
)
1388 ill
->ill_dlpi_capab_state
= reneg
? IDCS_RENEG
: IDCS_RESET_SENT
;
1390 ill_capability_send(ill
, ill
->ill_capab_reset_mp
);
1391 ill
->ill_capab_reset_mp
= NULL
;
1393 * We turn off all capabilities except those pertaining to
1394 * direct function call capabilities viz. ILL_CAPAB_DLD*
1395 * which will be turned off by the corresponding reset functions.
1397 ill
->ill_capabilities
&= ~(ILL_CAPAB_HCKSUM
| ILL_CAPAB_ZEROCOPY
);
1401 ill_capability_reset_alloc(ill_t
*ill
)
1406 dl_capability_req_t
*capb
;
1408 ASSERT(IAM_WRITER_ILL(ill
));
1409 ASSERT(ill
->ill_capab_reset_mp
== NULL
);
1411 if (ILL_HCKSUM_CAPABLE(ill
)) {
1412 size
+= sizeof (dl_capability_sub_t
) +
1413 sizeof (dl_capab_hcksum_t
);
1416 if (ill
->ill_capabilities
& ILL_CAPAB_ZEROCOPY
) {
1417 size
+= sizeof (dl_capability_sub_t
) +
1418 sizeof (dl_capab_zerocopy_t
);
1421 if (ill
->ill_capabilities
& ILL_CAPAB_DLD
) {
1422 size
+= sizeof (dl_capability_sub_t
) +
1423 sizeof (dl_capab_dld_t
);
1426 mp
= allocb_wait(size
+ sizeof (dl_capability_req_t
), BPRI_MED
,
1429 mp
->b_datap
->db_type
= M_PROTO
;
1430 bzero(mp
->b_rptr
, size
+ sizeof (dl_capability_req_t
));
1432 capb
= (dl_capability_req_t
*)mp
->b_rptr
;
1433 capb
->dl_primitive
= DL_CAPABILITY_REQ
;
1434 capb
->dl_sub_offset
= sizeof (dl_capability_req_t
);
1435 capb
->dl_sub_length
= size
;
1437 mp
->b_wptr
+= sizeof (dl_capability_req_t
);
1440 * Each handler fills in the corresponding dl_capability_sub_t
1443 ill_capability_hcksum_reset_fill(ill
, mp
);
1444 ill_capability_zerocopy_reset_fill(ill
, mp
);
1445 ill_capability_dld_reset_fill(ill
, mp
);
1447 ill
->ill_capab_reset_mp
= mp
;
1451 ill_capability_id_ack(ill_t
*ill
, mblk_t
*mp
, dl_capability_sub_t
*outers
)
1453 dl_capab_id_t
*id_ic
;
1454 uint_t sub_dl_cap
= outers
->dl_cap
;
1455 dl_capability_sub_t
*inners
;
1458 ASSERT(sub_dl_cap
== DL_CAPAB_ID_WRAPPER
);
1461 * Note: range checks here are not absolutely sufficient to
1462 * make us robust against malformed messages sent by drivers;
1463 * this is in keeping with the rest of IP's dlpi handling.
1464 * (Remember, it's coming from something else in the kernel
1468 capend
= (uint8_t *)(outers
+ 1) + outers
->dl_length
;
1469 if (capend
> mp
->b_wptr
) {
1470 cmn_err(CE_WARN
, "ill_capability_id_ack: "
1471 "malformed sub-capability too long for mblk");
1475 id_ic
= (dl_capab_id_t
*)(outers
+ 1);
1477 if (outers
->dl_length
< sizeof (*id_ic
) ||
1478 (inners
= &id_ic
->id_subcap
,
1479 inners
->dl_length
> (outers
->dl_length
- sizeof (*inners
)))) {
1480 cmn_err(CE_WARN
, "ill_capability_id_ack: malformed "
1481 "encapsulated capab type %d too long for mblk",
1486 if (!dlcapabcheckqid(&id_ic
->id_mid
, ill
->ill_lmod_rq
)) {
1487 ip1dbg(("ill_capability_id_ack: mid token for capab type %d "
1488 "isn't as expected; pass-thru module(s) detected, "
1489 "discarding capability\n", inners
->dl_cap
));
1493 /* Process the encapsulated sub-capability */
1494 ill_capability_dispatch(ill
, mp
, inners
);
1498 ill_capability_dld_reset_fill(ill_t
*ill
, mblk_t
*mp
)
1500 dl_capability_sub_t
*dl_subcap
;
1502 if (!(ill
->ill_capabilities
& ILL_CAPAB_DLD
))
1506 * The dl_capab_dld_t that follows the dl_capability_sub_t is not
1507 * initialized below since it is not used by DLD.
1509 dl_subcap
= (dl_capability_sub_t
*)mp
->b_wptr
;
1510 dl_subcap
->dl_cap
= DL_CAPAB_DLD
;
1511 dl_subcap
->dl_length
= sizeof (dl_capab_dld_t
);
1513 mp
->b_wptr
+= sizeof (dl_capability_sub_t
) + sizeof (dl_capab_dld_t
);
1517 ill_capability_dispatch(ill_t
*ill
, mblk_t
*mp
, dl_capability_sub_t
*subp
)
1520 * If no ipif was brought up over this ill, this DL_CAPABILITY_REQ/ACK
1521 * is only to get the VRRP capability.
1523 * Note that we cannot check ill_ipif_up_count here since
1524 * ill_ipif_up_count is only incremented when the resolver is setup.
1525 * That is done asynchronously, and can race with this function.
1527 if (!ill
->ill_dl_up
) {
1528 if (subp
->dl_cap
== DL_CAPAB_VRRP
)
1529 ill_capability_vrrp_ack(ill
, mp
, subp
);
1533 switch (subp
->dl_cap
) {
1534 case DL_CAPAB_HCKSUM
:
1535 ill_capability_hcksum_ack(ill
, mp
, subp
);
1537 case DL_CAPAB_ZEROCOPY
:
1538 ill_capability_zerocopy_ack(ill
, mp
, subp
);
1541 ill_capability_dld_ack(ill
, mp
, subp
);
1546 ip1dbg(("ill_capability_dispatch: unknown capab type %d\n",
1552 * Process the vrrp capability received from a DLS Provider. isub must point
1553 * to the sub-capability (DL_CAPAB_VRRP) of a DL_CAPABILITY_ACK message.
1556 ill_capability_vrrp_ack(ill_t
*ill
, mblk_t
*mp
, dl_capability_sub_t
*isub
)
1558 dl_capab_vrrp_t
*vrrp
;
1559 uint_t sub_dl_cap
= isub
->dl_cap
;
1562 ASSERT(IAM_WRITER_ILL(ill
));
1563 ASSERT(sub_dl_cap
== DL_CAPAB_VRRP
);
1566 * Note: range checks here are not absolutely sufficient to
1567 * make us robust against malformed messages sent by drivers;
1568 * this is in keeping with the rest of IP's dlpi handling.
1569 * (Remember, it's coming from something else in the kernel
1572 capend
= (uint8_t *)(isub
+ 1) + isub
->dl_length
;
1573 if (capend
> mp
->b_wptr
) {
1574 cmn_err(CE_WARN
, "ill_capability_vrrp_ack: "
1575 "malformed sub-capability too long for mblk");
1578 vrrp
= (dl_capab_vrrp_t
*)(isub
+ 1);
1581 * Compare the IP address family and set ILLF_VRRP for the right ill.
1583 if ((vrrp
->vrrp_af
== AF_INET6
&& ill
->ill_isv6
) ||
1584 (vrrp
->vrrp_af
== AF_INET
&& !ill
->ill_isv6
)) {
1585 ill
->ill_flags
|= ILLF_VRRP
;
1590 * Process a hardware checksum offload capability negotiation ack received
1591 * from a DLS Provider.isub must point to the sub-capability (DL_CAPAB_HCKSUM)
1592 * of a DL_CAPABILITY_ACK message.
1595 ill_capability_hcksum_ack(ill_t
*ill
, mblk_t
*mp
, dl_capability_sub_t
*isub
)
1597 dl_capability_req_t
*ocap
;
1598 dl_capab_hcksum_t
*ihck
, *ohck
;
1599 ill_hcksum_capab_t
**ill_hcksum
;
1601 uint_t sub_dl_cap
= isub
->dl_cap
;
1604 ASSERT(sub_dl_cap
== DL_CAPAB_HCKSUM
);
1606 ill_hcksum
= (ill_hcksum_capab_t
**)&ill
->ill_hcksum_capab
;
1609 * Note: range checks here are not absolutely sufficient to
1610 * make us robust against malformed messages sent by drivers;
1611 * this is in keeping with the rest of IP's dlpi handling.
1612 * (Remember, it's coming from something else in the kernel
1615 capend
= (uint8_t *)(isub
+ 1) + isub
->dl_length
;
1616 if (capend
> mp
->b_wptr
) {
1617 cmn_err(CE_WARN
, "ill_capability_hcksum_ack: "
1618 "malformed sub-capability too long for mblk");
1623 * There are two types of acks we process here:
1624 * 1. acks in reply to a (first form) generic capability req
1625 * (no ENABLE flag set)
1626 * 2. acks in reply to a ENABLE capability req.
1629 ihck
= (dl_capab_hcksum_t
*)(isub
+ 1);
1631 if (ihck
->hcksum_version
!= HCKSUM_VERSION_1
) {
1632 cmn_err(CE_CONT
, "ill_capability_hcksum_ack: "
1633 "unsupported hardware checksum "
1634 "sub-capability (version %d, expected %d)",
1635 ihck
->hcksum_version
, HCKSUM_VERSION_1
);
1639 if (!dlcapabcheckqid(&ihck
->hcksum_mid
, ill
->ill_lmod_rq
)) {
1640 ip1dbg(("ill_capability_hcksum_ack: mid token for hardware "
1641 "checksum capability isn't as expected; pass-thru "
1642 "module(s) detected, discarding capability\n"));
1646 #define CURR_HCKSUM_CAPAB \
1647 (HCKSUM_INET_PARTIAL | HCKSUM_INET_FULL_V4 | \
1648 HCKSUM_INET_FULL_V6 | HCKSUM_IPHDRCKSUM)
1650 if ((ihck
->hcksum_txflags
& HCKSUM_ENABLE
) &&
1651 (ihck
->hcksum_txflags
& CURR_HCKSUM_CAPAB
)) {
1652 /* do ENABLE processing */
1653 if (*ill_hcksum
== NULL
) {
1654 *ill_hcksum
= kmem_zalloc(sizeof (ill_hcksum_capab_t
),
1657 if (*ill_hcksum
== NULL
) {
1658 cmn_err(CE_WARN
, "ill_capability_hcksum_ack: "
1659 "could not enable hcksum version %d "
1660 "for %s (ENOMEM)\n", HCKSUM_CURRENT_VERSION
,
1666 (*ill_hcksum
)->ill_hcksum_version
= ihck
->hcksum_version
;
1667 (*ill_hcksum
)->ill_hcksum_txflags
= ihck
->hcksum_txflags
;
1668 ill
->ill_capabilities
|= ILL_CAPAB_HCKSUM
;
1669 ip1dbg(("ill_capability_hcksum_ack: interface %s "
1670 "has enabled hardware checksumming\n ",
1672 } else if (ihck
->hcksum_txflags
& CURR_HCKSUM_CAPAB
) {
1674 * Enabling hardware checksum offload
1675 * Currently IP supports {TCP,UDP}/IPv4
1676 * partial and full cksum offload and
1677 * IPv4 header checksum offload.
1678 * Allocate new mblk which will
1679 * contain a new capability request
1680 * to enable hardware checksum offload.
1685 size
= sizeof (dl_capability_req_t
) +
1686 sizeof (dl_capability_sub_t
) + isub
->dl_length
;
1688 if ((nmp
= ip_dlpi_alloc(size
, DL_CAPABILITY_REQ
)) == NULL
) {
1689 cmn_err(CE_WARN
, "ill_capability_hcksum_ack: "
1690 "could not enable hardware cksum for %s (ENOMEM)\n",
1696 /* initialize dl_capability_req_t */
1697 ocap
= (dl_capability_req_t
*)nmp
->b_rptr
;
1698 ocap
->dl_sub_offset
=
1699 sizeof (dl_capability_req_t
);
1700 ocap
->dl_sub_length
=
1701 sizeof (dl_capability_sub_t
) +
1703 nmp
->b_rptr
+= sizeof (dl_capability_req_t
);
1705 /* initialize dl_capability_sub_t */
1706 bcopy(isub
, nmp
->b_rptr
, sizeof (*isub
));
1707 nmp
->b_rptr
+= sizeof (*isub
);
1709 /* initialize dl_capab_hcksum_t */
1710 ohck
= (dl_capab_hcksum_t
*)nmp
->b_rptr
;
1711 bcopy(ihck
, ohck
, sizeof (*ihck
));
1714 ASSERT(nmp
->b_wptr
== (nmp
->b_rptr
+ size
));
1716 /* Set ENABLE flag */
1717 ohck
->hcksum_txflags
&= CURR_HCKSUM_CAPAB
;
1718 ohck
->hcksum_txflags
|= HCKSUM_ENABLE
;
1721 * nmp points to a DL_CAPABILITY_REQ message to enable
1722 * hardware checksum acceleration.
1724 ill_capability_send(ill
, nmp
);
1726 ip1dbg(("ill_capability_hcksum_ack: interface %s has "
1727 "advertised %x hardware checksum capability flags\n",
1728 ill
->ill_name
, ihck
->hcksum_txflags
));
1733 ill_capability_hcksum_reset_fill(ill_t
*ill
, mblk_t
*mp
)
1735 dl_capab_hcksum_t
*hck_subcap
;
1736 dl_capability_sub_t
*dl_subcap
;
1738 if (!ILL_HCKSUM_CAPABLE(ill
))
1741 ASSERT(ill
->ill_hcksum_capab
!= NULL
);
1743 dl_subcap
= (dl_capability_sub_t
*)mp
->b_wptr
;
1744 dl_subcap
->dl_cap
= DL_CAPAB_HCKSUM
;
1745 dl_subcap
->dl_length
= sizeof (*hck_subcap
);
1747 hck_subcap
= (dl_capab_hcksum_t
*)(dl_subcap
+ 1);
1748 hck_subcap
->hcksum_version
= ill
->ill_hcksum_capab
->ill_hcksum_version
;
1749 hck_subcap
->hcksum_txflags
= 0;
1751 mp
->b_wptr
+= sizeof (*dl_subcap
) + sizeof (*hck_subcap
);
1755 ill_capability_zerocopy_ack(ill_t
*ill
, mblk_t
*mp
, dl_capability_sub_t
*isub
)
1758 dl_capability_req_t
*oc
;
1759 dl_capab_zerocopy_t
*zc_ic
, *zc_oc
;
1760 ill_zerocopy_capab_t
**ill_zerocopy_capab
;
1761 uint_t sub_dl_cap
= isub
->dl_cap
;
1764 ASSERT(sub_dl_cap
== DL_CAPAB_ZEROCOPY
);
1766 ill_zerocopy_capab
= (ill_zerocopy_capab_t
**)&ill
->ill_zerocopy_capab
;
1769 * Note: range checks here are not absolutely sufficient to
1770 * make us robust against malformed messages sent by drivers;
1771 * this is in keeping with the rest of IP's dlpi handling.
1772 * (Remember, it's coming from something else in the kernel
1775 capend
= (uint8_t *)(isub
+ 1) + isub
->dl_length
;
1776 if (capend
> mp
->b_wptr
) {
1777 cmn_err(CE_WARN
, "ill_capability_zerocopy_ack: "
1778 "malformed sub-capability too long for mblk");
1782 zc_ic
= (dl_capab_zerocopy_t
*)(isub
+ 1);
1783 if (zc_ic
->zerocopy_version
!= ZEROCOPY_VERSION_1
) {
1784 cmn_err(CE_CONT
, "ill_capability_zerocopy_ack: "
1785 "unsupported ZEROCOPY sub-capability (version %d, "
1786 "expected %d)", zc_ic
->zerocopy_version
,
1787 ZEROCOPY_VERSION_1
);
1791 if (!dlcapabcheckqid(&zc_ic
->zerocopy_mid
, ill
->ill_lmod_rq
)) {
1792 ip1dbg(("ill_capability_zerocopy_ack: mid token for zerocopy "
1793 "capability isn't as expected; pass-thru module(s) "
1794 "detected, discarding capability\n"));
1798 if ((zc_ic
->zerocopy_flags
& DL_CAPAB_VMSAFE_MEM
) != 0) {
1799 if (*ill_zerocopy_capab
== NULL
) {
1800 *ill_zerocopy_capab
=
1801 kmem_zalloc(sizeof (ill_zerocopy_capab_t
),
1804 if (*ill_zerocopy_capab
== NULL
) {
1805 cmn_err(CE_WARN
, "ill_capability_zerocopy_ack: "
1806 "could not enable Zero-copy version %d "
1807 "for %s (ENOMEM)\n", ZEROCOPY_VERSION_1
,
1813 ip1dbg(("ill_capability_zerocopy_ack: interface %s "
1814 "supports Zero-copy version %d\n", ill
->ill_name
,
1815 ZEROCOPY_VERSION_1
));
1817 (*ill_zerocopy_capab
)->ill_zerocopy_version
=
1818 zc_ic
->zerocopy_version
;
1819 (*ill_zerocopy_capab
)->ill_zerocopy_flags
=
1820 zc_ic
->zerocopy_flags
;
1822 ill
->ill_capabilities
|= ILL_CAPAB_ZEROCOPY
;
1827 size
= sizeof (dl_capability_req_t
) +
1828 sizeof (dl_capability_sub_t
) +
1829 sizeof (dl_capab_zerocopy_t
);
1831 if ((nmp
= ip_dlpi_alloc(size
, DL_CAPABILITY_REQ
)) == NULL
) {
1832 cmn_err(CE_WARN
, "ill_capability_zerocopy_ack: "
1833 "could not enable zerocopy for %s (ENOMEM)\n",
1839 /* initialize dl_capability_req_t */
1840 oc
= (dl_capability_req_t
*)rptr
;
1841 oc
->dl_sub_offset
= sizeof (dl_capability_req_t
);
1842 oc
->dl_sub_length
= sizeof (dl_capability_sub_t
) +
1843 sizeof (dl_capab_zerocopy_t
);
1844 rptr
+= sizeof (dl_capability_req_t
);
1846 /* initialize dl_capability_sub_t */
1847 bcopy(isub
, rptr
, sizeof (*isub
));
1848 rptr
+= sizeof (*isub
);
1850 /* initialize dl_capab_zerocopy_t */
1851 zc_oc
= (dl_capab_zerocopy_t
*)rptr
;
1854 ip1dbg(("ill_capability_zerocopy_ack: asking interface %s "
1855 "to enable zero-copy version %d\n", ill
->ill_name
,
1856 ZEROCOPY_VERSION_1
));
1858 /* set VMSAFE_MEM flag */
1859 zc_oc
->zerocopy_flags
|= DL_CAPAB_VMSAFE_MEM
;
1861 /* nmp points to a DL_CAPABILITY_REQ message to enable zcopy */
1862 ill_capability_send(ill
, nmp
);
1867 ill_capability_zerocopy_reset_fill(ill_t
*ill
, mblk_t
*mp
)
1869 dl_capab_zerocopy_t
*zerocopy_subcap
;
1870 dl_capability_sub_t
*dl_subcap
;
1872 if (!(ill
->ill_capabilities
& ILL_CAPAB_ZEROCOPY
))
1875 ASSERT(ill
->ill_zerocopy_capab
!= NULL
);
1877 dl_subcap
= (dl_capability_sub_t
*)mp
->b_wptr
;
1878 dl_subcap
->dl_cap
= DL_CAPAB_ZEROCOPY
;
1879 dl_subcap
->dl_length
= sizeof (*zerocopy_subcap
);
1881 zerocopy_subcap
= (dl_capab_zerocopy_t
*)(dl_subcap
+ 1);
1882 zerocopy_subcap
->zerocopy_version
=
1883 ill
->ill_zerocopy_capab
->ill_zerocopy_version
;
1884 zerocopy_subcap
->zerocopy_flags
= 0;
1886 mp
->b_wptr
+= sizeof (*dl_subcap
) + sizeof (*zerocopy_subcap
);
1891 * Refer to dld.h for more information regarding the purpose and usage
1892 * of this capability.
1895 ill_capability_dld_ack(ill_t
*ill
, mblk_t
*mp
, dl_capability_sub_t
*isub
)
1897 dl_capab_dld_t
*dld_ic
, dld
;
1898 uint_t sub_dl_cap
= isub
->dl_cap
;
1900 ill_dld_capab_t
*idc
;
1902 ASSERT(IAM_WRITER_ILL(ill
));
1903 ASSERT(sub_dl_cap
== DL_CAPAB_DLD
);
1906 * Note: range checks here are not absolutely sufficient to
1907 * make us robust against malformed messages sent by drivers;
1908 * this is in keeping with the rest of IP's dlpi handling.
1909 * (Remember, it's coming from something else in the kernel
1912 capend
= (uint8_t *)(isub
+ 1) + isub
->dl_length
;
1913 if (capend
> mp
->b_wptr
) {
1914 cmn_err(CE_WARN
, "ill_capability_dld_ack: "
1915 "malformed sub-capability too long for mblk");
1918 dld_ic
= (dl_capab_dld_t
*)(isub
+ 1);
1919 if (dld_ic
->dld_version
!= DLD_CURRENT_VERSION
) {
1920 cmn_err(CE_CONT
, "ill_capability_dld_ack: "
1921 "unsupported DLD sub-capability (version %d, "
1922 "expected %d)", dld_ic
->dld_version
,
1923 DLD_CURRENT_VERSION
);
1926 if (!dlcapabcheckqid(&dld_ic
->dld_mid
, ill
->ill_lmod_rq
)) {
1927 ip1dbg(("ill_capability_dld_ack: mid token for dld "
1928 "capability isn't as expected; pass-thru module(s) "
1929 "detected, discarding capability\n"));
1934 * Copy locally to ensure alignment.
1936 bcopy(dld_ic
, &dld
, sizeof (dl_capab_dld_t
));
1938 if ((idc
= ill
->ill_dld_capab
) == NULL
) {
1939 idc
= kmem_zalloc(sizeof (ill_dld_capab_t
), KM_NOSLEEP
);
1941 cmn_err(CE_WARN
, "ill_capability_dld_ack: "
1942 "could not enable DLD version %d "
1943 "for %s (ENOMEM)\n", DLD_CURRENT_VERSION
,
1947 ill
->ill_dld_capab
= idc
;
1949 idc
->idc_capab_df
= (ip_capab_func_t
)dld
.dld_capab
;
1950 idc
->idc_capab_dh
= (void *)dld
.dld_capab_handle
;
1951 ip1dbg(("ill_capability_dld_ack: interface %s "
1952 "supports DLD version %d\n", ill
->ill_name
, DLD_CURRENT_VERSION
));
1954 ill_capability_dld_enable(ill
);
1958 * Typically capability negotiation between IP and the driver happens via
1959 * DLPI message exchange. However GLD also offers a direct function call
1960 * mechanism to exchange the DLD_DIRECT_CAPAB and DLD_POLL_CAPAB capabilities,
1961 * But arbitrary function calls into IP or GLD are not permitted, since both
1962 * of them are protected by their own perimeter mechanism. The perimeter can
1963 * be viewed as a coarse lock or serialization mechanism. The hierarchy of
1964 * these perimeters is IP -> MAC. Thus for example to enable the squeue
1965 * polling, IP needs to enter its perimeter, then call ill_mac_perim_enter
1966 * to enter the mac perimeter and then do the direct function calls into
1967 * GLD to enable squeue polling. The ring related callbacks from the mac into
1968 * the stack to add, bind, quiesce, restart or cleanup a ring are all
1969 * protected by the mac perimeter.
1972 ill_mac_perim_enter(ill_t
*ill
, mac_perim_handle_t
*mphp
)
1974 ill_dld_capab_t
*idc
= ill
->ill_dld_capab
;
1977 err
= idc
->idc_capab_df(idc
->idc_capab_dh
, DLD_CAPAB_PERIM
, mphp
,
1983 ill_mac_perim_exit(ill_t
*ill
, mac_perim_handle_t mph
)
1985 ill_dld_capab_t
*idc
= ill
->ill_dld_capab
;
1988 err
= idc
->idc_capab_df(idc
->idc_capab_dh
, DLD_CAPAB_PERIM
, mph
,
1994 ill_mac_perim_held(ill_t
*ill
)
1996 ill_dld_capab_t
*idc
= ill
->ill_dld_capab
;
1998 return (idc
->idc_capab_df(idc
->idc_capab_dh
, DLD_CAPAB_PERIM
, NULL
,
2003 ill_capability_direct_enable(ill_t
*ill
)
2005 ill_dld_capab_t
*idc
= ill
->ill_dld_capab
;
2006 ill_dld_direct_t
*idd
= &idc
->idc_direct
;
2007 dld_capab_direct_t direct
;
2010 ASSERT(!ill
->ill_isv6
&& IAM_WRITER_ILL(ill
));
2012 bzero(&direct
, sizeof (direct
));
2013 direct
.di_rx_cf
= (uintptr_t)ip_input
;
2014 direct
.di_rx_ch
= ill
;
2016 rc
= idc
->idc_capab_df(idc
->idc_capab_dh
, DLD_CAPAB_DIRECT
, &direct
,
2019 idd
->idd_tx_df
= (ip_dld_tx_t
)direct
.di_tx_df
;
2020 idd
->idd_tx_dh
= direct
.di_tx_dh
;
2021 idd
->idd_tx_cb_df
= (ip_dld_callb_t
)direct
.di_tx_cb_df
;
2022 idd
->idd_tx_cb_dh
= direct
.di_tx_cb_dh
;
2023 idd
->idd_tx_fctl_df
= (ip_dld_fctl_t
)direct
.di_tx_fctl_df
;
2024 idd
->idd_tx_fctl_dh
= direct
.di_tx_fctl_dh
;
2025 ASSERT(idd
->idd_tx_cb_df
!= NULL
);
2026 ASSERT(idd
->idd_tx_fctl_df
!= NULL
);
2027 ASSERT(idd
->idd_tx_df
!= NULL
);
2029 * One time registration of flow enable callback function
2031 ill
->ill_flownotify_mh
= idd
->idd_tx_cb_df(idd
->idd_tx_cb_dh
,
2032 ill_flow_enable
, ill
);
2033 ill
->ill_capabilities
|= ILL_CAPAB_DLD_DIRECT
;
2034 DTRACE_PROBE1(direct_on
, (ill_t
*), ill
);
2036 cmn_err(CE_WARN
, "warning: could not enable DIRECT "
2037 "capability, rc = %d\n", rc
);
2038 DTRACE_PROBE2(direct_off
, (ill_t
*), ill
, (int), rc
);
2043 ill_capability_poll_enable(ill_t
*ill
)
2045 ill_dld_capab_t
*idc
= ill
->ill_dld_capab
;
2046 dld_capab_poll_t poll
;
2049 ASSERT(!ill
->ill_isv6
&& IAM_WRITER_ILL(ill
));
2051 bzero(&poll
, sizeof (poll
));
2052 poll
.poll_ring_add_cf
= (uintptr_t)ip_squeue_add_ring
;
2053 poll
.poll_ring_remove_cf
= (uintptr_t)ip_squeue_clean_ring
;
2054 poll
.poll_ring_quiesce_cf
= (uintptr_t)ip_squeue_quiesce_ring
;
2055 poll
.poll_ring_restart_cf
= (uintptr_t)ip_squeue_restart_ring
;
2056 poll
.poll_ring_bind_cf
= (uintptr_t)ip_squeue_bind_ring
;
2057 poll
.poll_ring_ch
= ill
;
2058 rc
= idc
->idc_capab_df(idc
->idc_capab_dh
, DLD_CAPAB_POLL
, &poll
,
2061 ill
->ill_capabilities
|= ILL_CAPAB_DLD_POLL
;
2062 DTRACE_PROBE1(poll_on
, (ill_t
*), ill
);
2064 ip1dbg(("warning: could not enable POLL "
2065 "capability, rc = %d\n", rc
));
2066 DTRACE_PROBE2(poll_off
, (ill_t
*), ill
, (int), rc
);
2071 * Enable the LSO capability.
2074 ill_capability_lso_enable(ill_t
*ill
)
2076 ill_dld_capab_t
*idc
= ill
->ill_dld_capab
;
2077 dld_capab_lso_t lso
;
2080 ASSERT(!ill
->ill_isv6
&& IAM_WRITER_ILL(ill
));
2082 if (ill
->ill_lso_capab
== NULL
) {
2083 ill
->ill_lso_capab
= kmem_zalloc(sizeof (ill_lso_capab_t
),
2085 if (ill
->ill_lso_capab
== NULL
) {
2086 cmn_err(CE_WARN
, "ill_capability_lso_enable: "
2087 "could not enable LSO for %s (ENOMEM)\n",
2093 bzero(&lso
, sizeof (lso
));
2094 if ((rc
= idc
->idc_capab_df(idc
->idc_capab_dh
, DLD_CAPAB_LSO
, &lso
,
2095 DLD_ENABLE
)) == 0) {
2096 ill
->ill_lso_capab
->ill_lso_flags
= lso
.lso_flags
;
2097 ill
->ill_lso_capab
->ill_lso_max
= lso
.lso_max
;
2098 ill
->ill_capabilities
|= ILL_CAPAB_LSO
;
2099 ip1dbg(("ill_capability_lso_enable: interface %s "
2100 "has enabled LSO\n ", ill
->ill_name
));
2102 kmem_free(ill
->ill_lso_capab
, sizeof (ill_lso_capab_t
));
2103 ill
->ill_lso_capab
= NULL
;
2104 DTRACE_PROBE2(lso_off
, (ill_t
*), ill
, (int), rc
);
2109 ill_capability_dld_enable(ill_t
*ill
)
2111 mac_perim_handle_t mph
;
2113 ASSERT(IAM_WRITER_ILL(ill
));
2118 ill_mac_perim_enter(ill
, &mph
);
2119 if (!ill
->ill_isv6
) {
2120 ill_capability_direct_enable(ill
);
2121 ill_capability_poll_enable(ill
);
2122 ill_capability_lso_enable(ill
);
2124 ill
->ill_capabilities
|= ILL_CAPAB_DLD
;
2125 ill_mac_perim_exit(ill
, mph
);
2129 ill_capability_dld_disable(ill_t
*ill
)
2131 ill_dld_capab_t
*idc
;
2132 ill_dld_direct_t
*idd
;
2133 mac_perim_handle_t mph
;
2135 ASSERT(IAM_WRITER_ILL(ill
));
2137 if (!(ill
->ill_capabilities
& ILL_CAPAB_DLD
))
2140 ill_mac_perim_enter(ill
, &mph
);
2142 idc
= ill
->ill_dld_capab
;
2143 if ((ill
->ill_capabilities
& ILL_CAPAB_DLD_DIRECT
) != 0) {
2145 * For performance we avoid locks in the transmit data path
2146 * and don't maintain a count of the number of threads using
2147 * direct calls. Thus some threads could be using direct
2148 * transmit calls to GLD, even after the capability mechanism
2149 * turns it off. This is still safe since the handles used in
2150 * the direct calls continue to be valid until the unplumb is
2151 * completed. Remove the callback that was added (1-time) at
2152 * capab enable time.
2154 mutex_enter(&ill
->ill_lock
);
2155 ill
->ill_capabilities
&= ~ILL_CAPAB_DLD_DIRECT
;
2156 mutex_exit(&ill
->ill_lock
);
2157 if (ill
->ill_flownotify_mh
!= NULL
) {
2158 idd
= &idc
->idc_direct
;
2159 idd
->idd_tx_cb_df(idd
->idd_tx_cb_dh
, NULL
,
2160 ill
->ill_flownotify_mh
);
2161 ill
->ill_flownotify_mh
= NULL
;
2163 (void) idc
->idc_capab_df(idc
->idc_capab_dh
, DLD_CAPAB_DIRECT
,
2167 if ((ill
->ill_capabilities
& ILL_CAPAB_DLD_POLL
) != 0) {
2168 ill
->ill_capabilities
&= ~ILL_CAPAB_DLD_POLL
;
2169 ip_squeue_clean_all(ill
);
2170 (void) idc
->idc_capab_df(idc
->idc_capab_dh
, DLD_CAPAB_POLL
,
2174 if ((ill
->ill_capabilities
& ILL_CAPAB_LSO
) != 0) {
2175 ASSERT(ill
->ill_lso_capab
!= NULL
);
2177 * Clear the capability flag for LSO but retain the
2178 * ill_lso_capab structure since it's possible that another
2179 * thread is still referring to it. The structure only gets
2180 * deallocated when we destroy the ill.
2183 ill
->ill_capabilities
&= ~ILL_CAPAB_LSO
;
2184 (void) idc
->idc_capab_df(idc
->idc_capab_dh
, DLD_CAPAB_LSO
,
2188 ill
->ill_capabilities
&= ~ILL_CAPAB_DLD
;
2189 ill_mac_perim_exit(ill
, mph
);
2193 * Capability Negotiation protocol
2195 * We don't wait for DLPI capability operations to finish during interface
2196 * bringup or teardown. Doing so would introduce more asynchrony and the
2197 * interface up/down operations will need multiple return and restarts.
2198 * Instead the 'ipsq_current_ipif' of the ipsq is not cleared as long as
2199 * the 'ill_dlpi_deferred' chain is non-empty. This ensures that the next
2200 * exclusive operation won't start until the DLPI operations of the previous
2201 * exclusive operation complete.
2203 * The capability state machine is shown below.
2205 * state next state event, action
2207 * IDCS_UNKNOWN IDCS_PROBE_SENT ill_capability_probe
2208 * IDCS_PROBE_SENT IDCS_OK ill_capability_ack
2209 * IDCS_PROBE_SENT IDCS_FAILED ip_rput_dlpi_writer (nack)
2210 * IDCS_OK IDCS_RENEG Receipt of DL_NOTE_CAPAB_RENEG
2211 * IDCS_OK IDCS_RESET_SENT ill_capability_reset
2212 * IDCS_RESET_SENT IDCS_UNKNOWN ill_capability_ack_thr
2213 * IDCS_RENEG IDCS_PROBE_SENT ill_capability_ack_thr ->
2214 * ill_capability_probe.
2218 * Dedicated thread started from ip_stack_init that handles capability
2219 * disable. This thread ensures the taskq dispatch does not fail by waiting
2220 * for resources using TQ_SLEEP. The taskq mechanism is used to ensure
2221 * that direct calls to DLD are done in a cv_waitable context.
2224 ill_taskq_dispatch(ip_stack_t
*ipst
)
2226 callb_cpr_t cprinfo
;
2230 (void) snprintf(name
, sizeof (name
), "ill_taskq_dispatch_%d",
2231 ipst
->ips_netstack
->netstack_stackid
);
2232 CALLB_CPR_INIT(&cprinfo
, &ipst
->ips_capab_taskq_lock
, callb_generic_cpr
,
2234 mutex_enter(&ipst
->ips_capab_taskq_lock
);
2237 mp
= ipst
->ips_capab_taskq_head
;
2238 while (mp
!= NULL
) {
2239 ipst
->ips_capab_taskq_head
= mp
->b_next
;
2240 if (ipst
->ips_capab_taskq_head
== NULL
)
2241 ipst
->ips_capab_taskq_tail
= NULL
;
2242 mutex_exit(&ipst
->ips_capab_taskq_lock
);
2245 VERIFY(taskq_dispatch(system_taskq
,
2246 ill_capability_ack_thr
, mp
, TQ_SLEEP
) != 0);
2247 mutex_enter(&ipst
->ips_capab_taskq_lock
);
2248 mp
= ipst
->ips_capab_taskq_head
;
2251 if (ipst
->ips_capab_taskq_quit
)
2253 CALLB_CPR_SAFE_BEGIN(&cprinfo
);
2254 cv_wait(&ipst
->ips_capab_taskq_cv
, &ipst
->ips_capab_taskq_lock
);
2255 CALLB_CPR_SAFE_END(&cprinfo
, &ipst
->ips_capab_taskq_lock
);
2257 VERIFY(ipst
->ips_capab_taskq_head
== NULL
);
2258 VERIFY(ipst
->ips_capab_taskq_tail
== NULL
);
2259 CALLB_CPR_EXIT(&cprinfo
);
2264 * Consume a new-style hardware capabilities negotiation ack.
2265 * Called via taskq on receipt of DL_CAPABILITY_ACK.
2268 ill_capability_ack_thr(void *arg
)
2271 dl_capability_ack_t
*capp
;
2272 dl_capability_sub_t
*subp
, *endp
;
2276 ill
= (ill_t
*)mp
->b_prev
;
2279 VERIFY(ipsq_enter(ill
, B_FALSE
, CUR_OP
) == B_TRUE
);
2281 if (ill
->ill_dlpi_capab_state
== IDCS_RESET_SENT
||
2282 ill
->ill_dlpi_capab_state
== IDCS_RENEG
) {
2284 * We have received the ack for our DL_CAPAB reset request.
2285 * There isnt' anything in the message that needs processing.
2286 * All message based capabilities have been disabled, now
2287 * do the function call based capability disable.
2289 reneg
= ill
->ill_dlpi_capab_state
== IDCS_RENEG
;
2290 ill_capability_dld_disable(ill
);
2291 ill
->ill_dlpi_capab_state
= IDCS_UNKNOWN
;
2293 ill_capability_probe(ill
);
2297 if (ill
->ill_dlpi_capab_state
== IDCS_PROBE_SENT
)
2298 ill
->ill_dlpi_capab_state
= IDCS_OK
;
2300 capp
= (dl_capability_ack_t
*)mp
->b_rptr
;
2302 if (capp
->dl_sub_length
== 0) {
2303 /* no new-style capabilities */
2307 /* make sure the driver supplied correct dl_sub_length */
2308 if ((sizeof (*capp
) + capp
->dl_sub_length
) > MBLKL(mp
)) {
2309 ip0dbg(("ill_capability_ack: bad DL_CAPABILITY_ACK, "
2310 "invalid dl_sub_length (%d)\n", capp
->dl_sub_length
));
2314 #define SC(base, offset) (dl_capability_sub_t *)(((uchar_t *)(base))+(offset))
2316 * There are sub-capabilities. Process the ones we know about.
2317 * Loop until we don't have room for another sub-cap header..
2319 for (subp
= SC(capp
, capp
->dl_sub_offset
),
2320 endp
= SC(subp
, capp
->dl_sub_length
- sizeof (*subp
));
2322 subp
= SC(subp
, sizeof (dl_capability_sub_t
) + subp
->dl_length
)) {
2324 switch (subp
->dl_cap
) {
2325 case DL_CAPAB_ID_WRAPPER
:
2326 ill_capability_id_ack(ill
, mp
, subp
);
2329 ill_capability_dispatch(ill
, mp
, subp
);
2336 ill_capability_done(ill
);
2337 ipsq_exit(ill
->ill_phyint
->phyint_ipsq
);
2341 * This needs to be started in a taskq thread to provide a cv_waitable
2345 ill_capability_ack(ill_t
*ill
, mblk_t
*mp
)
2347 ip_stack_t
*ipst
= ill
->ill_ipst
;
2349 mp
->b_prev
= (mblk_t
*)ill
;
2350 ASSERT(mp
->b_next
== NULL
);
2352 if (taskq_dispatch(system_taskq
, ill_capability_ack_thr
, mp
,
2357 * The taskq dispatch failed. Signal the ill_taskq_dispatch thread
2358 * which will do the dispatch using TQ_SLEEP to guarantee success.
2360 mutex_enter(&ipst
->ips_capab_taskq_lock
);
2361 if (ipst
->ips_capab_taskq_head
== NULL
) {
2362 ASSERT(ipst
->ips_capab_taskq_tail
== NULL
);
2363 ipst
->ips_capab_taskq_head
= mp
;
2365 ipst
->ips_capab_taskq_tail
->b_next
= mp
;
2367 ipst
->ips_capab_taskq_tail
= mp
;
2369 cv_signal(&ipst
->ips_capab_taskq_cv
);
2370 mutex_exit(&ipst
->ips_capab_taskq_lock
);
2374 * This routine is called to scan the fragmentation reassembly table for
2375 * the specified ILL for any packets that are starting to smell.
2376 * dead_interval is the maximum time in seconds that will be tolerated. It
2377 * will either be the value specified in ip_g_frag_timeout, or zero if the
2378 * ILL is shutting down and it is time to blow everything off.
2380 * It returns the number of seconds (as a time_t) that the next frag timer
2381 * should be scheduled for, 0 meaning that the timer doesn't need to be
2382 * re-started. Note that the method of calculating next_timeout isn't
2383 * entirely accurate since time will flow between the time we grab
2384 * current_time and the time we schedule the next timeout. This isn't a
2385 * big problem since this is the timer for sending an ICMP reassembly time
2386 * exceeded messages, and it doesn't have to be exactly accurate.
2389 * sometimes called as writer, although this is not required.
2392 ill_frag_timeout(ill_t
*ill
, time_t dead_interval
)
2399 time_t current_time
= gethrestime_sec();
2400 time_t next_timeout
= 0;
2401 uint32_t hdr_length
;
2402 mblk_t
*send_icmp_head
;
2403 mblk_t
*send_icmp_head_v6
;
2404 ip_stack_t
*ipst
= ill
->ill_ipst
;
2405 ip_recv_attr_t iras
;
2407 bzero(&iras
, sizeof (iras
));
2409 iras
.ira_ill
= iras
.ira_rill
= ill
;
2410 iras
.ira_ruifindex
= ill
->ill_phyint
->phyint_ifindex
;
2411 iras
.ira_rifindex
= iras
.ira_ruifindex
;
2413 ipfb
= ill
->ill_frag_hash_tbl
;
2416 endp
= &ipfb
[ILL_FRAG_HASH_TBL_COUNT
];
2417 /* Walk the frag hash table. */
2418 for (; ipfb
< endp
; ipfb
++) {
2419 send_icmp_head
= NULL
;
2420 send_icmp_head_v6
= NULL
;
2421 mutex_enter(&ipfb
->ipfb_lock
);
2422 while ((ipf
= ipfb
->ipfb_ipf
) != 0) {
2423 time_t frag_time
= current_time
- ipf
->ipf_timestamp
;
2424 time_t frag_timeout
;
2426 if (frag_time
< dead_interval
) {
2428 * There are some outstanding fragments
2429 * that will timeout later. Make note of
2430 * the time so that we can reschedule the
2431 * next timeout appropriately.
2433 frag_timeout
= dead_interval
- frag_time
;
2434 if (next_timeout
== 0 ||
2435 frag_timeout
< next_timeout
) {
2436 next_timeout
= frag_timeout
;
2440 /* Time's up. Get it out of here. */
2441 hdr_length
= ipf
->ipf_nf_hdr_len
;
2442 ipfnext
= ipf
->ipf_hash_next
;
2444 ipfnext
->ipf_ptphn
= ipf
->ipf_ptphn
;
2445 *ipf
->ipf_ptphn
= ipfnext
;
2446 mp
= ipf
->ipf_mp
->b_cont
;
2447 for (; mp
; mp
= mp
->b_cont
) {
2448 /* Extra points for neatness. */
2449 IP_REASS_SET_START(mp
, 0);
2450 IP_REASS_SET_END(mp
, 0);
2452 mp
= ipf
->ipf_mp
->b_cont
;
2453 atomic_add_32(&ill
->ill_frag_count
, -ipf
->ipf_count
);
2454 ASSERT(ipfb
->ipfb_count
>= ipf
->ipf_count
);
2455 ipfb
->ipfb_count
-= ipf
->ipf_count
;
2456 ASSERT(ipfb
->ipfb_frag_pkts
> 0);
2457 ipfb
->ipfb_frag_pkts
--;
2459 * We do not send any icmp message from here because
2460 * we currently are holding the ipfb_lock for this
2461 * hash chain. If we try and send any icmp messages
2462 * from here we may end up via a put back into ip
2463 * trying to get the same lock, causing a recursive
2464 * mutex panic. Instead we build a list and send all
2465 * the icmp messages after we have dropped the lock.
2467 if (ill
->ill_isv6
) {
2468 if (hdr_length
!= 0) {
2469 mp
->b_next
= send_icmp_head_v6
;
2470 send_icmp_head_v6
= mp
;
2475 if (hdr_length
!= 0) {
2476 mp
->b_next
= send_icmp_head
;
2477 send_icmp_head
= mp
;
2482 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsReasmFails
);
2483 ip_drop_input("ipIfStatsReasmFails", ipf
->ipf_mp
, ill
);
2486 mutex_exit(&ipfb
->ipfb_lock
);
2488 * Now need to send any icmp messages that we delayed from
2491 while (send_icmp_head_v6
!= NULL
) {
2494 mp
= send_icmp_head_v6
;
2495 send_icmp_head_v6
= send_icmp_head_v6
->b_next
;
2497 ip6h
= (ip6_t
*)mp
->b_rptr
;
2500 * This will result in an incorrect ALL_ZONES zoneid
2501 * for multicast packets, but we
2502 * don't send ICMP errors for those in any case.
2505 ipif_lookup_addr_zoneid_v6(&ip6h
->ip6_dst
,
2507 ip_drop_input("ICMP_TIME_EXCEEDED reass", mp
, ill
);
2508 icmp_time_exceeded_v6(mp
,
2509 ICMP_REASSEMBLY_TIME_EXCEEDED
, B_FALSE
,
2511 ASSERT(!(iras
.ira_flags
& IRAF_IPSEC_SECURE
));
2513 while (send_icmp_head
!= NULL
) {
2516 mp
= send_icmp_head
;
2517 send_icmp_head
= send_icmp_head
->b_next
;
2520 dst
= ((ipha_t
*)mp
->b_rptr
)->ipha_dst
;
2522 iras
.ira_flags
= IRAF_IS_IPV4
;
2524 * This will result in an incorrect ALL_ZONES zoneid
2525 * for broadcast and multicast packets, but we
2526 * don't send ICMP errors for those in any case.
2528 iras
.ira_zoneid
= ipif_lookup_addr_zoneid(dst
,
2530 ip_drop_input("ICMP_TIME_EXCEEDED reass", mp
, ill
);
2531 icmp_time_exceeded(mp
,
2532 ICMP_REASSEMBLY_TIME_EXCEEDED
, &iras
);
2533 ASSERT(!(iras
.ira_flags
& IRAF_IPSEC_SECURE
));
2537 * A non-dying ILL will use the return value to decide whether to
2538 * restart the frag timer, and for how long.
2540 return (next_timeout
);
2544 * This routine is called when the approximate count of mblk memory used
2545 * for the specified ILL has exceeded max_count.
2548 ill_frag_prune(ill_t
*ill
, uint_t max_count
)
2556 * If we are here within ip_min_frag_prune_time msecs remove
2557 * ill_frag_free_num_pkts oldest packets from each bucket and increment
2558 * ill_frag_free_num_pkts.
2560 mutex_enter(&ill
->ill_lock
);
2561 now
= ddi_get_lbolt();
2562 if (TICK_TO_MSEC(now
- ill
->ill_last_frag_clean_time
) <=
2563 (ip_min_frag_prune_time
!= 0 ?
2564 ip_min_frag_prune_time
: msec_per_tick
)) {
2566 ill
->ill_frag_free_num_pkts
++;
2569 ill
->ill_frag_free_num_pkts
= 0;
2571 ill
->ill_last_frag_clean_time
= now
;
2572 mutex_exit(&ill
->ill_lock
);
2575 * free ill_frag_free_num_pkts oldest packets from each bucket.
2577 if (ill
->ill_frag_free_num_pkts
!= 0) {
2580 for (ix
= 0; ix
< ILL_FRAG_HASH_TBL_COUNT
; ix
++) {
2581 ipfb
= &ill
->ill_frag_hash_tbl
[ix
];
2582 mutex_enter(&ipfb
->ipfb_lock
);
2583 if (ipfb
->ipfb_ipf
!= NULL
) {
2584 ill_frag_free_pkts(ill
, ipfb
, ipfb
->ipfb_ipf
,
2585 ill
->ill_frag_free_num_pkts
);
2587 mutex_exit(&ipfb
->ipfb_lock
);
2591 * While the reassembly list for this ILL is too big, prune a fragment
2592 * queue by age, oldest first.
2594 while (ill
->ill_frag_count
> max_count
) {
2596 ipfb_t
*oipfb
= NULL
;
2597 uint_t oldest
= UINT_MAX
;
2600 for (ix
= 0; ix
< ILL_FRAG_HASH_TBL_COUNT
; ix
++) {
2601 ipfb
= &ill
->ill_frag_hash_tbl
[ix
];
2602 mutex_enter(&ipfb
->ipfb_lock
);
2603 ipf
= ipfb
->ipfb_ipf
;
2604 if (ipf
!= NULL
&& ipf
->ipf_gen
< oldest
) {
2605 oldest
= ipf
->ipf_gen
;
2608 count
+= ipfb
->ipfb_count
;
2609 mutex_exit(&ipfb
->ipfb_lock
);
2614 if (count
<= max_count
)
2615 return; /* Somebody beat us to it, nothing to do */
2616 mutex_enter(&oipfb
->ipfb_lock
);
2617 ipf
= oipfb
->ipfb_ipf
;
2619 ill_frag_free_pkts(ill
, oipfb
, ipf
, 1);
2621 mutex_exit(&oipfb
->ipfb_lock
);
2626 * free 'free_cnt' fragmented packets starting at ipf.
2629 ill_frag_free_pkts(ill_t
*ill
, ipfb_t
*ipfb
, ipf_t
*ipf
, int free_cnt
)
2634 ipf_t
**ipfp
= ipf
->ipf_ptphn
;
2636 ASSERT(MUTEX_HELD(&ipfb
->ipfb_lock
));
2637 ASSERT(ipfp
!= NULL
);
2638 ASSERT(ipf
!= NULL
);
2640 while (ipf
!= NULL
&& free_cnt
-- > 0) {
2641 count
= ipf
->ipf_count
;
2643 ipf
= ipf
->ipf_hash_next
;
2644 for (tmp
= mp
; tmp
; tmp
= tmp
->b_cont
) {
2645 IP_REASS_SET_START(tmp
, 0);
2646 IP_REASS_SET_END(tmp
, 0);
2648 atomic_add_32(&ill
->ill_frag_count
, -count
);
2649 ASSERT(ipfb
->ipfb_count
>= count
);
2650 ipfb
->ipfb_count
-= count
;
2651 ASSERT(ipfb
->ipfb_frag_pkts
> 0);
2652 ipfb
->ipfb_frag_pkts
--;
2653 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsReasmFails
);
2654 ip_drop_input("ipIfStatsReasmFails", mp
, ill
);
2659 ipf
->ipf_ptphn
= ipfp
;
2664 * Helper function for ill_forward_set().
2667 ill_forward_set_on_ill(ill_t
*ill
, boolean_t enable
)
2669 ip_stack_t
*ipst
= ill
->ill_ipst
;
2671 ASSERT(IAM_WRITER_ILL(ill
) || RW_READ_HELD(&ipst
->ips_ill_g_lock
));
2673 ip1dbg(("ill_forward_set: %s %s forwarding on %s",
2674 (enable
? "Enabling" : "Disabling"),
2675 (ill
->ill_isv6
? "IPv6" : "IPv4"), ill
->ill_name
));
2676 mutex_enter(&ill
->ill_lock
);
2678 ill
->ill_flags
|= ILLF_ROUTER
;
2680 ill
->ill_flags
&= ~ILLF_ROUTER
;
2681 mutex_exit(&ill
->ill_lock
);
2683 ill_set_nce_router_flags(ill
, enable
);
2684 /* Notify routing socket listeners of this change. */
2685 if (ill
->ill_ipif
!= NULL
)
2686 ip_rts_ifmsg(ill
->ill_ipif
, RTSQ_DEFAULT
);
2690 * Set an ill's ILLF_ROUTER flag appropriately. Send up RTS_IFINFO routing
2691 * socket messages for each interface whose flags we change.
2694 ill_forward_set(ill_t
*ill
, boolean_t enable
)
2696 ipmp_illgrp_t
*illg
;
2697 ip_stack_t
*ipst
= ill
->ill_ipst
;
2699 ASSERT(IAM_WRITER_ILL(ill
) || RW_READ_HELD(&ipst
->ips_ill_g_lock
));
2701 if ((enable
&& (ill
->ill_flags
& ILLF_ROUTER
)) ||
2702 (!enable
&& !(ill
->ill_flags
& ILLF_ROUTER
)))
2705 if (IS_LOOPBACK(ill
))
2708 if (enable
&& ill
->ill_allowed_ips_cnt
> 0)
2711 if (IS_IPMP(ill
) || IS_UNDER_IPMP(ill
)) {
2713 * Update all of the interfaces in the group.
2715 illg
= ill
->ill_grp
;
2716 ill
= list_head(&illg
->ig_if
);
2717 for (; ill
!= NULL
; ill
= list_next(&illg
->ig_if
, ill
))
2718 ill_forward_set_on_ill(ill
, enable
);
2721 * Update the IPMP meta-interface.
2723 ill_forward_set_on_ill(ipmp_illgrp_ipmp_ill(illg
), enable
);
2727 ill_forward_set_on_ill(ill
, enable
);
2732 * Based on the ILLF_ROUTER flag of an ill, make sure all local nce's for
2733 * addresses assigned to the ill have the NCE_F_ISROUTER flag appropriately
2737 ill_set_nce_router_flags(ill_t
*ill
, boolean_t enable
)
2743 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
2745 * NOTE: we match across the illgrp because nce's for
2746 * addresses on IPMP interfaces have an nce_ill that points to
2747 * the bound underlying ill.
2749 nce
= nce_lookup_v6(ill
, &ipif
->ipif_v6lcl_addr
);
2751 ncec
= nce
->nce_common
;
2752 mutex_enter(&ncec
->ncec_lock
);
2754 ncec
->ncec_flags
|= NCE_F_ISROUTER
;
2756 ncec
->ncec_flags
&= ~NCE_F_ISROUTER
;
2757 mutex_exit(&ncec
->ncec_lock
);
2764 * Intializes the context structure and returns the first ill in the list
2765 * cuurently start_list and end_list can have values:
2766 * MAX_G_HEADS Traverse both IPV4 and IPV6 lists.
2767 * IP_V4_G_HEAD Traverse IPV4 list only.
2768 * IP_V6_G_HEAD Traverse IPV6 list only.
2772 * We don't check for CONDEMNED ills here. Caller must do that if
2773 * necessary under the ill lock.
2776 ill_first(int start_list
, int end_list
, ill_walk_context_t
*ctx
,
2781 avl_tree_t
*avl_tree
;
2783 ASSERT(RW_LOCK_HELD(&ipst
->ips_ill_g_lock
));
2784 ASSERT(end_list
<= MAX_G_HEADS
&& start_list
>= 0);
2787 * setup the lists to search
2789 if (end_list
!= MAX_G_HEADS
) {
2790 ctx
->ctx_current_list
= start_list
;
2791 ctx
->ctx_last_list
= end_list
;
2793 ctx
->ctx_last_list
= MAX_G_HEADS
- 1;
2794 ctx
->ctx_current_list
= 0;
2797 while (ctx
->ctx_current_list
<= ctx
->ctx_last_list
) {
2798 ifp
= IP_VX_ILL_G_LIST(ctx
->ctx_current_list
, ipst
);
2799 if (ifp
!= (ill_if_t
*)
2800 &IP_VX_ILL_G_LIST(ctx
->ctx_current_list
, ipst
)) {
2801 avl_tree
= &ifp
->illif_avl_by_ppa
;
2802 ill
= avl_first(avl_tree
);
2804 * ill is guaranteed to be non NULL or ifp should have
2807 ASSERT(ill
!= NULL
);
2810 ctx
->ctx_current_list
++;
2817 * returns the next ill in the list. ill_first() must have been called
2818 * before calling ill_next() or bad things will happen.
2822 * We don't check for CONDEMNED ills here. Caller must do that if
2823 * necessary under the ill lock.
2826 ill_next(ill_walk_context_t
*ctx
, ill_t
*lastill
)
2830 ip_stack_t
*ipst
= lastill
->ill_ipst
;
2832 ASSERT(lastill
->ill_ifptr
!= (ill_if_t
*)
2833 &IP_VX_ILL_G_LIST(ctx
->ctx_current_list
, ipst
));
2834 if ((ill
= avl_walk(&lastill
->ill_ifptr
->illif_avl_by_ppa
, lastill
,
2835 AVL_AFTER
)) != NULL
) {
2839 /* goto next ill_ifp in the list. */
2840 ifp
= lastill
->ill_ifptr
->illif_next
;
2842 /* make sure not at end of circular list */
2844 (ill_if_t
*)&IP_VX_ILL_G_LIST(ctx
->ctx_current_list
, ipst
)) {
2845 if (++ctx
->ctx_current_list
> ctx
->ctx_last_list
)
2847 ifp
= IP_VX_ILL_G_LIST(ctx
->ctx_current_list
, ipst
);
2850 return (avl_first(&ifp
->illif_avl_by_ppa
));
2854 * Check interface name for correct format: [a-zA-Z]+[a-zA-Z0-9._]*[0-9]+
2855 * The final number (PPA) must not have any leading zeros. Upon success, a
2856 * pointer to the start of the PPA is returned; otherwise NULL is returned.
2859 ill_get_ppa_ptr(char *name
)
2861 int namelen
= strlen(name
);
2862 int end_ndx
= namelen
- 1;
2866 * Check that the first character is [a-zA-Z], and that the last
2867 * character is [0-9].
2869 if (namelen
== 0 || !isalpha(name
[0]) || !isdigit(name
[end_ndx
]))
2873 * Set `ppa_ndx' to the PPA start, and check for leading zeroes.
2875 for (ppa_ndx
= end_ndx
; ppa_ndx
> 0; ppa_ndx
--)
2876 if (!isdigit(name
[ppa_ndx
- 1]))
2879 if (name
[ppa_ndx
] == '0' && ppa_ndx
< end_ndx
)
2883 * Check that the intermediate characters are [a-z0-9.]
2885 for (i
= 1; i
< ppa_ndx
; i
++) {
2886 if (!isalpha(name
[i
]) && !isdigit(name
[i
]) &&
2887 name
[i
] != '.' && name
[i
] != '_') {
2892 return (name
+ ppa_ndx
);
2896 * use avl tree to locate the ill.
2899 ill_find_by_name(char *name
, boolean_t isv6
, ip_stack_t
*ipst
)
2901 char *ppa_ptr
= NULL
;
2912 list
= IP_V6_G_HEAD
;
2914 list
= IP_V4_G_HEAD
;
2916 if ((ppa_ptr
= ill_get_ppa_ptr(name
)) == NULL
) {
2920 len
= ppa_ptr
- name
+ 1;
2922 ppa
= stoi(&ppa_ptr
);
2924 ifp
= IP_VX_ILL_G_LIST(list
, ipst
);
2926 while (ifp
!= (ill_if_t
*)&IP_VX_ILL_G_LIST(list
, ipst
)) {
2928 * match is done on len - 1 as the name is not null
2929 * terminated it contains ppa in addition to the interface
2932 if ((ifp
->illif_name_len
== len
) &&
2933 bcmp(ifp
->illif_name
, name
, len
- 1) == 0) {
2936 ifp
= ifp
->illif_next
;
2940 if (ifp
== (ill_if_t
*)&IP_VX_ILL_G_LIST(list
, ipst
)) {
2942 * Even the interface type does not exist.
2947 ill
= avl_find(&ifp
->illif_avl_by_ppa
, (void *) &ppa
, NULL
);
2949 mutex_enter(&ill
->ill_lock
);
2950 if (ILL_CAN_LOOKUP(ill
)) {
2951 ill_refhold_locked(ill
);
2952 mutex_exit(&ill
->ill_lock
);
2955 mutex_exit(&ill
->ill_lock
);
2961 * comparison function for use with avl.
2964 ill_compare_ppa(const void *ppa_ptr
, const void *ill_ptr
)
2969 ASSERT(ppa_ptr
!= NULL
&& ill_ptr
!= NULL
);
2971 ppa
= *((uint_t
*)ppa_ptr
);
2972 ill_ppa
= ((const ill_t
*)ill_ptr
)->ill_ppa
;
2974 * We want the ill with the lowest ppa to be on the
2985 * remove an interface type from the global list.
2988 ill_delete_interface_type(ill_if_t
*interface
)
2990 ASSERT(interface
!= NULL
);
2991 ASSERT(avl_numnodes(&interface
->illif_avl_by_ppa
) == 0);
2993 avl_destroy(&interface
->illif_avl_by_ppa
);
2994 if (interface
->illif_ppa_arena
!= NULL
)
2995 vmem_destroy(interface
->illif_ppa_arena
);
3003 * remove ill from the global list.
3006 ill_glist_delete(ill_t
*ill
)
3013 ipst
= ill
->ill_ipst
;
3014 rw_enter(&ipst
->ips_ill_g_lock
, RW_WRITER
);
3017 * If the ill was never inserted into the AVL tree
3018 * we skip the if branch.
3020 if (ill
->ill_ifptr
!= NULL
) {
3022 * remove from AVL tree and free ppa number
3024 avl_remove(&ill
->ill_ifptr
->illif_avl_by_ppa
, ill
);
3026 if (ill
->ill_ifptr
->illif_ppa_arena
!= NULL
) {
3027 vmem_free(ill
->ill_ifptr
->illif_ppa_arena
,
3028 (void *)(uintptr_t)(ill
->ill_ppa
+1), 1);
3030 if (avl_numnodes(&ill
->ill_ifptr
->illif_avl_by_ppa
) == 0) {
3031 ill_delete_interface_type(ill
->ill_ifptr
);
3035 * Indicate ill is no longer in the list.
3037 ill
->ill_ifptr
= NULL
;
3038 ill
->ill_name_length
= 0;
3039 ill
->ill_name
[0] = '\0';
3040 ill
->ill_ppa
= UINT_MAX
;
3043 /* Generate one last event for this ill. */
3044 ill_nic_event_dispatch(ill
, 0, NE_UNPLUMB
, ill
->ill_name
,
3045 ill
->ill_name_length
);
3047 ASSERT(ill
->ill_phyint
!= NULL
);
3048 phyi
= ill
->ill_phyint
;
3049 ill
->ill_phyint
= NULL
;
3052 * ill_init allocates a phyint always to store the copy
3053 * of flags relevant to phyint. At that point in time, we could
3054 * not assign the name and hence phyint_illv4/v6 could not be
3055 * initialized. Later in ipif_set_values, we assign the name to
3056 * the ill, at which point in time we assign phyint_illv4/v6.
3057 * Thus we don't rely on phyint_illv6 to be initialized always.
3059 if (ill
->ill_flags
& ILLF_IPV6
)
3060 phyi
->phyint_illv6
= NULL
;
3062 phyi
->phyint_illv4
= NULL
;
3064 if (phyi
->phyint_illv4
!= NULL
|| phyi
->phyint_illv6
!= NULL
) {
3065 rw_exit(&ipst
->ips_ill_g_lock
);
3070 * There are no ills left on this phyint; pull it out of the phyint
3071 * avl trees, and free it.
3073 if (phyi
->phyint_ifindex
> 0) {
3074 avl_remove(&ipst
->ips_phyint_g_list
->phyint_list_avl_by_index
,
3076 avl_remove(&ipst
->ips_phyint_g_list
->phyint_list_avl_by_name
,
3079 rw_exit(&ipst
->ips_ill_g_lock
);
3085 * allocate a ppa, if the number of plumbed interfaces of this type are
3086 * less than ill_no_arena do a linear search to find a unused ppa.
3087 * When the number goes beyond ill_no_arena switch to using an arena.
3088 * Note: ppa value of zero cannot be allocated from vmem_arena as it
3089 * is the return value for an error condition, so allocation starts at one
3090 * and is decremented by one.
3093 ill_alloc_ppa(ill_if_t
*ifp
, ill_t
*ill
)
3099 if (ifp
->illif_ppa_arena
== NULL
&&
3100 (avl_numnodes(&ifp
->illif_avl_by_ppa
) + 1 > ill_no_arena
)) {
3104 ifp
->illif_ppa_arena
= vmem_create(ifp
->illif_name
,
3105 (void *)1, UINT_MAX
- 1, 1, NULL
, NULL
,
3106 NULL
, 0, VM_SLEEP
| VMC_IDENTIFIER
);
3107 /* allocate what has already been assigned */
3108 for (tmp_ill
= avl_first(&ifp
->illif_avl_by_ppa
);
3109 tmp_ill
!= NULL
; tmp_ill
= avl_walk(&ifp
->illif_avl_by_ppa
,
3110 tmp_ill
, AVL_AFTER
)) {
3111 ppa
= (int)(uintptr_t)vmem_xalloc(ifp
->illif_ppa_arena
,
3113 1, /* align/quantum */
3117 (void *)((uintptr_t)tmp_ill
->ill_ppa
+ 1),
3119 (void *)((uintptr_t)tmp_ill
->ill_ppa
+ 2),
3120 VM_NOSLEEP
|VM_FIRSTFIT
);
3122 ip1dbg(("ill_alloc_ppa: ppa allocation"
3123 " failed while switching"));
3124 vmem_destroy(ifp
->illif_ppa_arena
);
3125 ifp
->illif_ppa_arena
= NULL
;
3131 if (ifp
->illif_ppa_arena
!= NULL
) {
3132 if (ill
->ill_ppa
== UINT_MAX
) {
3133 ppa
= (int)(uintptr_t)vmem_alloc(ifp
->illif_ppa_arena
,
3134 1, VM_NOSLEEP
|VM_FIRSTFIT
);
3137 ill
->ill_ppa
= --ppa
;
3139 ppa
= (int)(uintptr_t)vmem_xalloc(ifp
->illif_ppa_arena
,
3141 1, /* align/quantum */
3144 (void *)(uintptr_t)(ill
->ill_ppa
+ 1), /* minaddr */
3145 (void *)(uintptr_t)(ill
->ill_ppa
+ 2), /* maxaddr */
3146 VM_NOSLEEP
|VM_FIRSTFIT
);
3148 * Most likely the allocation failed because
3149 * the requested ppa was in use.
3158 * No arena is in use and not enough (>ill_no_arena) interfaces have
3159 * been plumbed to create one. Do a linear search to get a unused ppa.
3161 if (ill
->ill_ppa
== UINT_MAX
) {
3165 end
= start
= ill
->ill_ppa
;
3168 tmp_ill
= avl_find(&ifp
->illif_avl_by_ppa
, (void *)&start
, NULL
);
3169 while (tmp_ill
!= NULL
&& tmp_ill
->ill_ppa
== start
) {
3170 if (start
++ >= end
) {
3171 if (ill
->ill_ppa
== UINT_MAX
)
3176 tmp_ill
= avl_walk(&ifp
->illif_avl_by_ppa
, tmp_ill
, AVL_AFTER
);
3178 ill
->ill_ppa
= start
;
3183 * Insert ill into the list of configured ill's. Once this function completes,
3184 * the ill is globally visible and is available through lookups. More precisely
3185 * this happens after the caller drops the ill_g_lock.
3188 ill_glist_insert(ill_t
*ill
, char *name
, boolean_t isv6
)
3190 ill_if_t
*ill_interface
;
3191 avl_index_t where
= 0;
3195 boolean_t check_length
= B_FALSE
;
3196 ip_stack_t
*ipst
= ill
->ill_ipst
;
3198 ASSERT(RW_WRITE_HELD(&ipst
->ips_ill_g_lock
));
3200 name_length
= mi_strlen(name
) + 1;
3203 index
= IP_V6_G_HEAD
;
3205 index
= IP_V4_G_HEAD
;
3207 ill_interface
= IP_VX_ILL_G_LIST(index
, ipst
);
3209 * Search for interface type based on name
3211 while (ill_interface
!= (ill_if_t
*)&IP_VX_ILL_G_LIST(index
, ipst
)) {
3212 if ((ill_interface
->illif_name_len
== name_length
) &&
3213 (strcmp(ill_interface
->illif_name
, name
) == 0)) {
3216 ill_interface
= ill_interface
->illif_next
;
3220 * Interface type not found, create one.
3222 if (ill_interface
== (ill_if_t
*)&IP_VX_ILL_G_LIST(index
, ipst
)) {
3226 * allocate ill_if_t structure
3228 ill_interface
= (ill_if_t
*)mi_zalloc(sizeof (ill_if_t
));
3229 if (ill_interface
== NULL
) {
3233 (void) strcpy(ill_interface
->illif_name
, name
);
3234 ill_interface
->illif_name_len
= name_length
;
3236 avl_create(&ill_interface
->illif_avl_by_ppa
,
3237 ill_compare_ppa
, sizeof (ill_t
),
3238 offsetof(struct ill_s
, ill_avl_byppa
));
3241 * link the structure in the back to maintain order
3242 * of configuration for ifconfig output.
3244 ghead
= ipst
->ips_ill_g_heads
[index
];
3245 insque(ill_interface
, ghead
.ill_g_list_tail
);
3248 if (ill
->ill_ppa
== UINT_MAX
)
3249 check_length
= B_TRUE
;
3251 error
= ill_alloc_ppa(ill_interface
, ill
);
3253 if (avl_numnodes(&ill_interface
->illif_avl_by_ppa
) == 0)
3254 ill_delete_interface_type(ill
->ill_ifptr
);
3259 * When the ppa is choosen by the system, check that there is
3260 * enough space to insert ppa. if a specific ppa was passed in this
3261 * check is not required as the interface name passed in will have
3262 * the right ppa in it.
3266 * UINT_MAX - 1 should fit in 10 chars, alloc 12 chars.
3268 char buf
[sizeof (uint_t
) * 3];
3271 * convert ppa to string to calculate the amount of space
3272 * required for it in the name.
3274 numtos(ill
->ill_ppa
, buf
);
3276 /* Do we have enough space to insert ppa ? */
3278 if ((mi_strlen(name
) + mi_strlen(buf
) + 1) > LIFNAMSIZ
) {
3279 /* Free ppa and interface type struct */
3280 if (ill_interface
->illif_ppa_arena
!= NULL
) {
3281 vmem_free(ill_interface
->illif_ppa_arena
,
3282 (void *)(uintptr_t)(ill
->ill_ppa
+1), 1);
3284 if (avl_numnodes(&ill_interface
->illif_avl_by_ppa
) == 0)
3285 ill_delete_interface_type(ill
->ill_ifptr
);
3291 (void) sprintf(ill
->ill_name
, "%s%u", name
, ill
->ill_ppa
);
3292 ill
->ill_name_length
= mi_strlen(ill
->ill_name
) + 1;
3294 (void) avl_find(&ill_interface
->illif_avl_by_ppa
, &ill
->ill_ppa
,
3296 ill
->ill_ifptr
= ill_interface
;
3297 avl_insert(&ill_interface
->illif_avl_by_ppa
, ill
, where
);
3299 ill_phyint_reinit(ill
);
3303 /* Initialize the per phyint ipsq used for serialization */
3305 ipsq_init(ill_t
*ill
, boolean_t enter
)
3310 if ((ipsq
= kmem_zalloc(sizeof (ipsq_t
), KM_NOSLEEP
)) == NULL
)
3313 ill
->ill_phyint
->phyint_ipsq
= ipsq
;
3314 ipx
= ipsq
->ipsq_xop
= &ipsq
->ipsq_ownxop
;
3315 ipx
->ipx_ipsq
= ipsq
;
3316 ipsq
->ipsq_next
= ipsq
;
3317 ipsq
->ipsq_phyint
= ill
->ill_phyint
;
3318 mutex_init(&ipsq
->ipsq_lock
, NULL
, MUTEX_DEFAULT
, 0);
3319 mutex_init(&ipx
->ipx_lock
, NULL
, MUTEX_DEFAULT
, 0);
3320 ipsq
->ipsq_ipst
= ill
->ill_ipst
; /* No netstack_hold */
3322 ipx
->ipx_writer
= curthread
;
3323 ipx
->ipx_forced
= B_FALSE
;
3324 ipx
->ipx_reentry_cnt
= 1;
3326 ipx
->ipx_depth
= getpcstack(ipx
->ipx_stack
, IPX_STACK_DEPTH
);
3333 * Here we perform initialisation of the ill_t common to both regular
3334 * interface ILLs and the special loopback ILL created by ill_lookup_on_name.
3337 ill_init_common(ill_t
*ill
, queue_t
*q
, boolean_t isv6
, boolean_t is_loopback
,
3338 boolean_t ipsq_enter
)
3343 mutex_init(&ill
->ill_lock
, NULL
, MUTEX_DEFAULT
, 0);
3344 mutex_init(&ill
->ill_saved_ire_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
3345 ill
->ill_saved_ire_cnt
= 0;
3348 ill
->ill_max_frag
= isv6
? ip_loopback_mtu_v6plus
:
3349 ip_loopback_mtuplus
;
3353 ill
->ill_net_type
= IRE_LOOPBACK
;
3356 ill
->ill_wq
= WR(q
);
3357 ill
->ill_ppa
= UINT_MAX
;
3360 ill
->ill_isv6
= isv6
;
3363 * Allocate sufficient space to contain our fragment hash table and
3366 frag_ptr
= (uchar_t
*)mi_zalloc(ILL_FRAG_HASH_TBL_SIZE
+ 2 * LIFNAMSIZ
);
3367 if (frag_ptr
== NULL
)
3369 ill
->ill_frag_ptr
= frag_ptr
;
3370 ill
->ill_frag_free_num_pkts
= 0;
3371 ill
->ill_last_frag_clean_time
= 0;
3372 ill
->ill_frag_hash_tbl
= (ipfb_t
*)frag_ptr
;
3373 ill
->ill_name
= (char *)(frag_ptr
+ ILL_FRAG_HASH_TBL_SIZE
);
3374 for (count
= 0; count
< ILL_FRAG_HASH_TBL_COUNT
; count
++) {
3375 mutex_init(&ill
->ill_frag_hash_tbl
[count
].ipfb_lock
,
3376 NULL
, MUTEX_DEFAULT
, NULL
);
3379 ill
->ill_phyint
= (phyint_t
*)mi_zalloc(sizeof (phyint_t
));
3380 if (ill
->ill_phyint
== NULL
) {
3385 mutex_init(&ill
->ill_phyint
->phyint_lock
, NULL
, MUTEX_DEFAULT
, 0);
3387 ill
->ill_phyint
->phyint_illv6
= ill
;
3389 ill
->ill_phyint
->phyint_illv4
= ill
;
3392 phyint_flags_init(ill
->ill_phyint
, DL_LOOP
);
3395 list_create(&ill
->ill_nce
, sizeof (nce_t
), offsetof(nce_t
, nce_node
));
3397 ill_set_inputfn(ill
);
3399 if (!ipsq_init(ill
, ipsq_enter
)) {
3401 mi_free(ill
->ill_phyint
);
3405 /* Frag queue limit stuff */
3406 ill
->ill_frag_count
= 0;
3407 ill
->ill_ipf_gen
= 0;
3409 rw_init(&ill
->ill_mcast_lock
, NULL
, RW_DEFAULT
, NULL
);
3410 mutex_init(&ill
->ill_mcast_serializer
, NULL
, MUTEX_DEFAULT
, NULL
);
3411 ill
->ill_global_timer
= INFINITY
;
3412 ill
->ill_mcast_v1_time
= ill
->ill_mcast_v2_time
= 0;
3413 ill
->ill_mcast_v1_tset
= ill
->ill_mcast_v2_tset
= 0;
3414 ill
->ill_mcast_rv
= MCAST_DEF_ROBUSTNESS
;
3415 ill
->ill_mcast_qi
= MCAST_DEF_QUERY_INTERVAL
;
3418 * Initialize IPv6 configuration variables. The IP module is always
3419 * opened as an IPv4 module. Instead tracking down the cases where
3420 * it switches to do ipv6, we'll just initialize the IPv6 configuration
3421 * here for convenience, this has no effect until the ill is set to do
3424 ill
->ill_reachable_time
= ND_REACHABLE_TIME
;
3425 ill
->ill_xmit_count
= ND_MAX_MULTICAST_SOLICIT
;
3426 ill
->ill_max_buf
= ND_MAX_Q
;
3427 ill
->ill_refcnt
= 0;
3433 * ill_init is called by ip_open when a device control stream is opened.
3434 * It does a few initializations, and shoots a DL_INFO_REQ message down
3435 * to the driver. The response is later picked up in ip_rput_dlpi and
3436 * used to set up default mechanisms for talking to the driver. (Always
3437 * called as writer.)
3439 * If this function returns error, ip_open will call ip_close which in
3440 * turn will call ill_delete to clean up any memory allocated here that
3443 * Note: ill_ipst and ill_zoneid must be set before calling ill_init.
3446 ill_init(queue_t
*q
, ill_t
*ill
)
3449 dl_info_req_t
*dlir
;
3452 info_mp
= allocb(MAX(sizeof (dl_info_req_t
), sizeof (dl_info_ack_t
)),
3454 if (info_mp
== NULL
)
3458 * For now pretend this is a v4 ill. We need to set phyint_ill*
3459 * at this point because of the following reason. If we can't
3460 * enter the ipsq at some point and cv_wait, the writer that
3461 * wakes us up tries to locate us using the list of all phyints
3462 * in an ipsq and the ills from the phyint thru the phyint_ill*.
3463 * If we don't set it now, we risk a missed wakeup.
3465 if ((ret
= ill_init_common(ill
, q
, B_FALSE
, B_FALSE
, B_TRUE
)) != 0) {
3470 ill
->ill_state_flags
|= ILL_LL_SUBNET_PENDING
;
3472 /* Send down the Info Request to the driver. */
3473 info_mp
->b_datap
->db_type
= M_PCPROTO
;
3474 dlir
= (dl_info_req_t
*)info_mp
->b_rptr
;
3475 info_mp
->b_wptr
= (uchar_t
*)&dlir
[1];
3476 dlir
->dl_primitive
= DL_INFO_REQ
;
3478 ill
->ill_dlpi_pending
= DL_PRIM_INVAL
;
3481 ill_dlpi_send(ill
, info_mp
);
3488 * creates datalink socket info from the device.
3491 ill_dls_info(struct sockaddr_dl
*sdl
, const ill_t
*ill
)
3495 sdl
->sdl_family
= AF_LINK
;
3496 sdl
->sdl_index
= ill_get_upper_ifindex(ill
);
3497 sdl
->sdl_type
= ill
->ill_type
;
3498 ill_get_name(ill
, sdl
->sdl_data
, sizeof (sdl
->sdl_data
));
3499 len
= strlen(sdl
->sdl_data
);
3501 sdl
->sdl_nlen
= (uchar_t
)len
;
3502 sdl
->sdl_alen
= ill
->ill_phys_addr_length
;
3504 if (ill
->ill_phys_addr_length
!= 0 && ill
->ill_phys_addr
!= NULL
)
3505 bcopy(ill
->ill_phys_addr
, &sdl
->sdl_data
[len
], sdl
->sdl_alen
);
3507 return (sizeof (struct sockaddr_dl
));
3512 * creates xarp info from the device.
3515 ill_xarp_info(struct sockaddr_dl
*sdl
, ill_t
*ill
)
3517 sdl
->sdl_family
= AF_LINK
;
3518 sdl
->sdl_index
= ill
->ill_phyint
->phyint_ifindex
;
3519 sdl
->sdl_type
= ill
->ill_type
;
3520 ill_get_name(ill
, sdl
->sdl_data
, sizeof (sdl
->sdl_data
));
3521 sdl
->sdl_nlen
= (uchar_t
)mi_strlen(sdl
->sdl_data
);
3522 sdl
->sdl_alen
= ill
->ill_phys_addr_length
;
3524 return (sdl
->sdl_nlen
);
3528 loopback_kstat_update(kstat_t
*ksp
, int rw
)
3531 netstackid_t stackid
;
3535 if (ksp
== NULL
|| ksp
->ks_data
== NULL
)
3538 if (rw
== KSTAT_WRITE
)
3541 kn
= KSTAT_NAMED_PTR(ksp
);
3542 stackid
= (zoneid_t
)(uintptr_t)ksp
->ks_private
;
3544 ns
= netstack_find_by_stackid(stackid
);
3548 ipst
= ns
->netstack_ip
;
3553 kn
[0].value
.ui32
= ipst
->ips_loopback_packets
;
3554 kn
[1].value
.ui32
= ipst
->ips_loopback_packets
;
3560 * Has ifindex been plumbed already?
3563 phyint_exists(uint_t index
, ip_stack_t
*ipst
)
3566 ASSERT(RW_LOCK_HELD(&ipst
->ips_ill_g_lock
));
3568 return (avl_find(&ipst
->ips_phyint_g_list
->phyint_list_avl_by_index
,
3569 &index
, NULL
) != NULL
);
3573 * Pick a unique ifindex.
3574 * When the index counter passes IF_INDEX_MAX for the first time, the wrap
3575 * flag is set so that next time time ip_assign_ifindex() is called, it
3576 * falls through and resets the index counter back to 1, the minimum value
3577 * for the interface index. The logic below assumes that ips_ill_index
3578 * can hold a value of IF_INDEX_MAX+1 without there being any loss
3579 * (i.e. reset back to 0.)
3582 ip_assign_ifindex(uint_t
*indexp
, ip_stack_t
*ipst
)
3586 if (!ipst
->ips_ill_index_wrap
) {
3587 *indexp
= ipst
->ips_ill_index
++;
3588 if (ipst
->ips_ill_index
> IF_INDEX_MAX
) {
3590 * Reached the maximum ifindex value, set the wrap
3591 * flag to indicate that it is no longer possible
3592 * to assume that a given index is unallocated.
3594 ipst
->ips_ill_index_wrap
= B_TRUE
;
3599 if (ipst
->ips_ill_index
> IF_INDEX_MAX
)
3600 ipst
->ips_ill_index
= 1;
3603 * Start reusing unused indexes. Note that we hold the ill_g_lock
3604 * at this point and don't want to call any function that attempts
3605 * to get the lock again.
3607 for (loops
= IF_INDEX_MAX
; loops
> 0; loops
--) {
3608 if (!phyint_exists(ipst
->ips_ill_index
, ipst
)) {
3609 /* found unused index - use it */
3610 *indexp
= ipst
->ips_ill_index
;
3614 ipst
->ips_ill_index
++;
3615 if (ipst
->ips_ill_index
> IF_INDEX_MAX
)
3616 ipst
->ips_ill_index
= 1;
3620 * all interface indicies are inuse.
3626 * Assign a unique interface index for the phyint.
3629 phyint_assign_ifindex(phyint_t
*phyi
, ip_stack_t
*ipst
)
3631 ASSERT(phyi
->phyint_ifindex
== 0);
3632 return (ip_assign_ifindex(&phyi
->phyint_ifindex
, ipst
));
3636 * Initialize the flags on `phyi' as per the provided mactype.
3639 phyint_flags_init(phyint_t
*phyi
, t_uscalar_t mactype
)
3644 * Initialize PHYI_RUNNING and PHYI_FAILED. For non-IPMP interfaces,
3645 * we always presume the underlying hardware is working and set
3646 * PHYI_RUNNING (if it's not, the driver will subsequently send a
3647 * DL_NOTE_LINK_DOWN message). For IPMP interfaces, at initialization
3648 * there are no active interfaces in the group so we set PHYI_FAILED.
3650 if (mactype
== SUNW_DL_IPMP
)
3651 flags
|= PHYI_FAILED
;
3653 flags
|= PHYI_RUNNING
;
3657 flags
|= PHYI_VIRTUAL
;
3663 flags
|= (PHYI_LOOPBACK
| PHYI_VIRTUAL
);
3667 mutex_enter(&phyi
->phyint_lock
);
3668 phyi
->phyint_flags
|= flags
;
3669 mutex_exit(&phyi
->phyint_lock
);
3673 * Return a pointer to the ill which matches the supplied name. Note that
3674 * the ill name length includes the null termination character. (May be
3675 * called as writer.)
3676 * If do_alloc and the interface is "lo0" it will be automatically created.
3677 * Cannot bump up reference on condemned ills. So dup detect can't be done
3681 ill_lookup_on_name(char *name
, boolean_t do_alloc
, boolean_t isv6
,
3682 boolean_t
*did_alloc
, ip_stack_t
*ipst
)
3688 boolean_t isloopback
;
3691 isloopback
= mi_strcmp(name
, ipif_loopback_name
) == 0;
3693 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
3694 ill
= ill_find_by_name(name
, isv6
, ipst
);
3695 rw_exit(&ipst
->ips_ill_g_lock
);
3700 * Couldn't find it. Does this happen to be a lookup for the
3701 * loopback device and are we allowed to allocate it?
3703 if (!isloopback
|| !do_alloc
)
3706 rw_enter(&ipst
->ips_ill_g_lock
, RW_WRITER
);
3707 ill
= ill_find_by_name(name
, isv6
, ipst
);
3709 rw_exit(&ipst
->ips_ill_g_lock
);
3713 /* Create the loopback device on demand */
3714 ill
= (ill_t
*)(mi_alloc(sizeof (ill_t
) +
3715 sizeof (ipif_loopback_name
), BPRI_MED
));
3719 bzero(ill
, sizeof (*ill
));
3720 ill
->ill_ipst
= ipst
;
3721 netstack_hold(ipst
->ips_netstack
);
3723 * For exclusive stacks we set the zoneid to zero
3724 * to make IP operate as if in the global zone.
3726 ill
->ill_zoneid
= GLOBAL_ZONEID
;
3728 if (ill_init_common(ill
, NULL
, isv6
, B_TRUE
, B_FALSE
) != 0)
3731 if (!ill_allocate_mibs(ill
))
3734 ill
->ill_current_frag
= ill
->ill_max_frag
;
3735 ill
->ill_mtu
= ill
->ill_max_frag
; /* Initial value */
3736 ill
->ill_mc_mtu
= ill
->ill_mtu
;
3738 * ipif_loopback_name can't be pointed at directly because its used
3739 * by both the ipv4 and ipv6 interfaces. When the ill is removed
3740 * from the glist, ill_glist_delete() sets the first character of
3743 ill
->ill_name
= (char *)ill
+ sizeof (*ill
);
3744 (void) strcpy(ill
->ill_name
, ipif_loopback_name
);
3745 ill
->ill_name_length
= sizeof (ipif_loopback_name
);
3746 /* Set ill_dlpi_pending for ipsq_current_finish() to work properly */
3747 ill
->ill_dlpi_pending
= DL_PRIM_INVAL
;
3749 ipif
= ipif_allocate(ill
, 0L, IRE_LOOPBACK
, B_TRUE
, B_TRUE
, NULL
);
3753 ill
->ill_flags
= ILLF_MULTICAST
;
3755 ov6addr
= ipif
->ipif_v6lcl_addr
;
3756 /* Set up default loopback address and mask. */
3758 ipaddr_t inaddr_loopback
= htonl(INADDR_LOOPBACK
);
3760 IN6_IPADDR_TO_V4MAPPED(inaddr_loopback
, &ipif
->ipif_v6lcl_addr
);
3761 V4MASK_TO_V6(htonl(IN_CLASSA_NET
), ipif
->ipif_v6net_mask
);
3762 V6_MASK_COPY(ipif
->ipif_v6lcl_addr
, ipif
->ipif_v6net_mask
,
3763 ipif
->ipif_v6subnet
);
3764 ill
->ill_flags
|= ILLF_IPV4
;
3766 ipif
->ipif_v6lcl_addr
= ipv6_loopback
;
3767 ipif
->ipif_v6net_mask
= ipv6_all_ones
;
3768 V6_MASK_COPY(ipif
->ipif_v6lcl_addr
, ipif
->ipif_v6net_mask
,
3769 ipif
->ipif_v6subnet
);
3770 ill
->ill_flags
|= ILLF_IPV6
;
3774 * Chain us in at the end of the ill list. hold the ill
3775 * before we make it globally visible. 1 for the lookup.
3779 ipsq
= ill
->ill_phyint
->phyint_ipsq
;
3781 if (ill_glist_insert(ill
, "lo", isv6
) != 0)
3782 cmn_err(CE_PANIC
, "cannot insert loopback interface");
3784 /* Let SCTP know so that it can add this to its list */
3785 sctp_update_ill(ill
, SCTP_ILL_INSERT
);
3788 * We have already assigned ipif_v6lcl_addr above, but we need to
3789 * call sctp_update_ipif_addr() after SCTP_ILL_INSERT, which
3790 * requires to be after ill_glist_insert() since we need the
3791 * ill_index set. Pass on ipv6_loopback as the old address.
3793 sctp_update_ipif_addr(ipif
, ov6addr
);
3795 ip_rts_newaddrmsg(RTM_CHGADDR
, 0, ipif
, RTSQ_DEFAULT
);
3798 * ill_glist_insert() -> ill_phyint_reinit() may have merged IPSQs.
3799 * If so, free our original one.
3801 if (ipsq
!= ill
->ill_phyint
->phyint_ipsq
)
3804 if (ipst
->ips_loopback_ksp
== NULL
) {
3805 /* Export loopback interface statistics */
3806 ipst
->ips_loopback_ksp
= kstat_create_netstack("lo", 0,
3807 ipif_loopback_name
, "net",
3808 KSTAT_TYPE_NAMED
, 2, 0,
3809 ipst
->ips_netstack
->netstack_stackid
);
3810 if (ipst
->ips_loopback_ksp
!= NULL
) {
3811 ipst
->ips_loopback_ksp
->ks_update
=
3812 loopback_kstat_update
;
3813 kn
= KSTAT_NAMED_PTR(ipst
->ips_loopback_ksp
);
3814 kstat_named_init(&kn
[0], "ipackets", KSTAT_DATA_UINT32
);
3815 kstat_named_init(&kn
[1], "opackets", KSTAT_DATA_UINT32
);
3816 ipst
->ips_loopback_ksp
->ks_private
=
3817 (void *)(uintptr_t)ipst
->ips_netstack
->
3819 kstat_install(ipst
->ips_loopback_ksp
);
3823 *did_alloc
= B_TRUE
;
3824 rw_exit(&ipst
->ips_ill_g_lock
);
3825 ill_nic_event_dispatch(ill
, MAP_IPIF_ID(ill
->ill_ipif
->ipif_id
),
3826 NE_PLUMB
, ill
->ill_name
, ill
->ill_name_length
);
3830 if (ill
->ill_phyint
!= NULL
) {
3831 ipsq
= ill
->ill_phyint
->phyint_ipsq
;
3833 ipsq
->ipsq_phyint
= NULL
;
3836 mi_free(ill
->ill_phyint
);
3839 if (ill
->ill_ipst
!= NULL
)
3840 netstack_rele(ill
->ill_ipst
->ips_netstack
);
3843 rw_exit(&ipst
->ips_ill_g_lock
);
3848 * For IPP calls - use the ip_stack_t for global stack.
3851 ill_lookup_on_ifindex_global_instance(uint_t index
, boolean_t isv6
)
3857 ns
= netstack_find_by_stackid(GLOBAL_NETSTACKID
);
3859 if ((ipst
= ns
->netstack_ip
) == NULL
) {
3860 cmn_err(CE_WARN
, "No ip_stack_t for zoneid zero!\n");
3865 ill
= ill_lookup_on_ifindex(index
, isv6
, ipst
);
3871 * Return a pointer to the ill which matches the index and IP version type.
3874 ill_lookup_on_ifindex(uint_t index
, boolean_t isv6
, ip_stack_t
*ipst
)
3880 * Indexes are stored in the phyint - a common structure
3881 * to both IPv4 and IPv6.
3883 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
3884 phyi
= avl_find(&ipst
->ips_phyint_g_list
->phyint_list_avl_by_index
,
3885 (void *) &index
, NULL
);
3887 ill
= isv6
? phyi
->phyint_illv6
: phyi
->phyint_illv4
;
3889 mutex_enter(&ill
->ill_lock
);
3890 if (!ILL_IS_CONDEMNED(ill
)) {
3891 ill_refhold_locked(ill
);
3892 mutex_exit(&ill
->ill_lock
);
3893 rw_exit(&ipst
->ips_ill_g_lock
);
3896 mutex_exit(&ill
->ill_lock
);
3899 rw_exit(&ipst
->ips_ill_g_lock
);
3904 * Verify whether or not an interface index is valid for the specified zoneid
3905 * to transmit packets.
3906 * It can be zero (meaning "reset") or an interface index assigned
3907 * to a non-VNI interface. (We don't use VNI interface to send packets.)
3910 ip_xmit_ifindex_valid(uint_t ifindex
, zoneid_t zoneid
, boolean_t isv6
,
3918 ill
= ill_lookup_on_ifindex_zoneid(ifindex
, zoneid
, isv6
, ipst
);
3930 * Return the ifindex next in sequence after the passed in ifindex.
3931 * If there is no next ifindex for the given protocol, return 0.
3934 ill_get_next_ifindex(uint_t index
, boolean_t isv6
, ip_stack_t
*ipst
)
3937 phyint_t
*phyi_initial
;
3940 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
3944 &ipst
->ips_phyint_g_list
->phyint_list_avl_by_index
);
3946 phyi
= phyi_initial
= avl_find(
3947 &ipst
->ips_phyint_g_list
->phyint_list_avl_by_index
,
3948 (void *) &index
, NULL
);
3951 for (; phyi
!= NULL
;
3952 phyi
= avl_walk(&ipst
->ips_phyint_g_list
->phyint_list_avl_by_index
,
3955 * If we're not returning the first interface in the tree
3956 * and we still haven't moved past the phyint_t that
3957 * corresponds to index, avl_walk needs to be called again
3959 if (!((index
!= 0) && (phyi
== phyi_initial
))) {
3961 if ((phyi
->phyint_illv6
) &&
3962 ILL_CAN_LOOKUP(phyi
->phyint_illv6
) &&
3963 (phyi
->phyint_illv6
->ill_isv6
== 1))
3966 if ((phyi
->phyint_illv4
) &&
3967 ILL_CAN_LOOKUP(phyi
->phyint_illv4
) &&
3968 (phyi
->phyint_illv4
->ill_isv6
== 0))
3974 rw_exit(&ipst
->ips_ill_g_lock
);
3977 ifindex
= phyi
->phyint_ifindex
;
3985 * Return the ifindex for the named interface.
3986 * If there is no next ifindex for the interface, return 0.
3989 ill_get_ifindex_by_name(char *name
, ip_stack_t
*ipst
)
3992 avl_index_t where
= 0;
3995 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
3997 if ((phyi
= avl_find(&ipst
->ips_phyint_g_list
->phyint_list_avl_by_name
,
3998 name
, &where
)) == NULL
) {
3999 rw_exit(&ipst
->ips_ill_g_lock
);
4003 ifindex
= phyi
->phyint_ifindex
;
4005 rw_exit(&ipst
->ips_ill_g_lock
);
4011 * Return the ifindex to be used by upper layer protocols for instance
4012 * for IPV6_RECVPKTINFO. If IPMP this is the one for the upper ill.
4015 ill_get_upper_ifindex(const ill_t
*ill
)
4017 if (IS_UNDER_IPMP(ill
))
4018 return (ipmp_ill_get_ipmp_ifindex(ill
));
4020 return (ill
->ill_phyint
->phyint_ifindex
);
4025 * Obtain a reference to the ill. The ill_refcnt is a dynamic refcnt
4026 * that gives a running thread a reference to the ill. This reference must be
4027 * released by the thread when it is done accessing the ill and related
4028 * objects. ill_refcnt can not be used to account for static references
4029 * such as other structures pointing to an ill. Callers must generally
4030 * check whether an ill can be refheld by using ILL_CAN_LOOKUP macros
4031 * or be sure that the ill is not being deleted or changing state before
4032 * calling the refhold functions. A non-zero ill_refcnt ensures that the
4033 * ill won't change any of its critical state such as address, netmask etc.
4036 ill_refhold(ill_t
*ill
)
4038 mutex_enter(&ill
->ill_lock
);
4041 mutex_exit(&ill
->ill_lock
);
4045 ill_refhold_locked(ill_t
*ill
)
4047 ASSERT(MUTEX_HELD(&ill
->ill_lock
));
4052 /* Returns true if we managed to get a refhold */
4054 ill_check_and_refhold(ill_t
*ill
)
4056 mutex_enter(&ill
->ill_lock
);
4057 if (!ILL_IS_CONDEMNED(ill
)) {
4058 ill_refhold_locked(ill
);
4059 mutex_exit(&ill
->ill_lock
);
4062 mutex_exit(&ill
->ill_lock
);
4067 * Must not be called while holding any locks. Otherwise if this is
4068 * the last reference to be released, there is a chance of recursive mutex
4069 * panic due to ill_refrele -> ipif_ill_refrele_tail -> qwriter_ip trying
4070 * to restart an ioctl.
4073 ill_refrele(ill_t
*ill
)
4075 mutex_enter(&ill
->ill_lock
);
4076 ASSERT(ill
->ill_refcnt
!= 0);
4078 ILL_UNTRACE_REF(ill
);
4079 if (ill
->ill_refcnt
!= 0) {
4080 /* Every ire pointing to the ill adds 1 to ill_refcnt */
4081 mutex_exit(&ill
->ill_lock
);
4085 /* Drops the ill_lock */
4086 ipif_ill_refrele_tail(ill
);
4090 * Obtain a weak reference count on the ill. This reference ensures the
4091 * ill won't be freed, but the ill may change any of its critical state
4092 * such as netmask, address etc. Returns an error if the ill has started
4096 ill_waiter_inc(ill_t
*ill
)
4098 mutex_enter(&ill
->ill_lock
);
4099 if (ill
->ill_state_flags
& ILL_CONDEMNED
) {
4100 mutex_exit(&ill
->ill_lock
);
4104 mutex_exit(&ill
->ill_lock
);
4109 ill_waiter_dcr(ill_t
*ill
)
4111 mutex_enter(&ill
->ill_lock
);
4113 if (ill
->ill_waiters
== 0)
4114 cv_broadcast(&ill
->ill_cv
);
4115 mutex_exit(&ill
->ill_lock
);
4119 * ip_ll_subnet_defaults is called when we get the DL_INFO_ACK back from the
4120 * driver. We construct best guess defaults for lower level information that
4121 * we need. If an interface is brought up without injection of any overriding
4122 * information from outside, we have to be ready to go with these defaults.
4123 * When we get the first DL_INFO_ACK (from ip_open() sending a DL_INFO_REQ)
4124 * we primarely want the dl_provider_style.
4125 * The subsequent DL_INFO_ACK is received after doing a DL_ATTACH and DL_BIND
4126 * at which point we assume the other part of the information is valid.
4129 ip_ll_subnet_defaults(ill_t
*ill
, mblk_t
*mp
)
4131 uchar_t
*brdcst_addr
;
4132 uint_t brdcst_addr_length
, phys_addr_length
;
4133 t_scalar_t sap_length
;
4134 dl_info_ack_t
*dlia
;
4136 dl_qos_cl_sel1_t
*sel1
;
4139 ASSERT(IAM_WRITER_ILL(ill
));
4142 * Till the ill is fully up the ill is not globally visible.
4143 * So no need for a lock.
4145 dlia
= (dl_info_ack_t
*)mp
->b_rptr
;
4146 ill
->ill_mactype
= dlia
->dl_mac_type
;
4148 ipm
= ip_m_lookup(dlia
->dl_mac_type
);
4150 ipm
= ip_m_lookup(DL_OTHER
);
4151 ASSERT(ipm
!= NULL
);
4153 ill
->ill_media
= ipm
;
4156 * When the new DLPI stuff is ready we'll pull lengths
4159 if (dlia
->dl_version
== DL_VERSION_2
) {
4160 brdcst_addr_length
= dlia
->dl_brdcst_addr_length
;
4161 brdcst_addr
= mi_offset_param(mp
, dlia
->dl_brdcst_addr_offset
,
4162 brdcst_addr_length
);
4163 if (brdcst_addr
== NULL
) {
4164 brdcst_addr_length
= 0;
4166 sap_length
= dlia
->dl_sap_length
;
4167 phys_addr_length
= dlia
->dl_addr_length
- ABS(sap_length
);
4168 ip1dbg(("ip: bcast_len %d, sap_len %d, phys_len %d\n",
4169 brdcst_addr_length
, sap_length
, phys_addr_length
));
4171 brdcst_addr_length
= 6;
4172 brdcst_addr
= ip_six_byte_all_ones
;
4174 phys_addr_length
= brdcst_addr_length
;
4177 ill
->ill_bcast_addr_length
= brdcst_addr_length
;
4178 ill
->ill_phys_addr_length
= phys_addr_length
;
4179 ill
->ill_sap_length
= sap_length
;
4182 * Synthetic DLPI types such as SUNW_DL_IPMP specify a zero SDU,
4183 * but we must ensure a minimum IP MTU is used since other bits of
4184 * IP will fly apart otherwise.
4186 min_mtu
= ill
->ill_isv6
? IPV6_MIN_MTU
: IP_MIN_MTU
;
4187 ill
->ill_max_frag
= MAX(min_mtu
, dlia
->dl_max_sdu
);
4188 ill
->ill_current_frag
= ill
->ill_max_frag
;
4189 ill
->ill_mtu
= ill
->ill_max_frag
;
4190 ill
->ill_mc_mtu
= ill
->ill_mtu
; /* Overridden by DL_NOTE_SDU_SIZE2 */
4192 ill
->ill_type
= ipm
->ip_m_type
;
4194 if (!ill
->ill_dlpi_style_set
) {
4195 if (dlia
->dl_provider_style
== DL_STYLE2
)
4196 ill
->ill_needs_attach
= 1;
4198 phyint_flags_init(ill
->ill_phyint
, ill
->ill_mactype
);
4201 * Allocate the first ipif on this ill. We don't delay it
4202 * further as ioctl handling assumes at least one ipif exists.
4204 * At this point we don't know whether the ill is v4 or v6.
4205 * We will know this whan the SIOCSLIFNAME happens and
4206 * the correct value for ill_isv6 will be assigned in
4207 * ipif_set_values(). We need to hold the ill lock and
4208 * clear the ILL_LL_SUBNET_PENDING flag and atomically do
4211 (void) ipif_allocate(ill
, 0, IRE_LOCAL
,
4212 dlia
->dl_provider_style
!= DL_STYLE2
, B_TRUE
, NULL
);
4213 mutex_enter(&ill
->ill_lock
);
4214 ASSERT(ill
->ill_dlpi_style_set
== 0);
4215 ill
->ill_dlpi_style_set
= 1;
4216 ill
->ill_state_flags
&= ~ILL_LL_SUBNET_PENDING
;
4217 cv_broadcast(&ill
->ill_cv
);
4218 mutex_exit(&ill
->ill_lock
);
4222 ASSERT(ill
->ill_ipif
!= NULL
);
4224 * We know whether it is IPv4 or IPv6 now, as this is the
4225 * second DL_INFO_ACK we are recieving in response to the
4226 * DL_INFO_REQ sent in ipif_set_values.
4228 ill
->ill_sap
= (ill
->ill_isv6
) ? ipm
->ip_m_ipv6sap
: ipm
->ip_m_ipv4sap
;
4230 * Clear all the flags that were set based on ill_bcast_addr_length
4231 * and ill_phys_addr_length (in ipif_set_values) as these could have
4232 * changed now and we need to re-evaluate.
4234 ill
->ill_flags
&= ~(ILLF_MULTICAST
| ILLF_NONUD
| ILLF_NOARP
);
4235 ill
->ill_ipif
->ipif_flags
&= ~(IPIF_BROADCAST
| IPIF_POINTOPOINT
);
4238 * Free ill_bcast_mp as things could have changed now.
4240 * NOTE: The IPMP meta-interface is special-cased because it starts
4241 * with no underlying interfaces (and thus an unknown broadcast
4242 * address length), but we enforce that an interface is broadcast-
4243 * capable as part of allowing it to join a group.
4245 if (ill
->ill_bcast_addr_length
== 0 && !IS_IPMP(ill
)) {
4246 if (ill
->ill_bcast_mp
!= NULL
)
4247 freemsg(ill
->ill_bcast_mp
);
4248 ill
->ill_net_type
= IRE_IF_NORESOLVER
;
4250 ill
->ill_bcast_mp
= ill_dlur_gen(NULL
,
4251 ill
->ill_phys_addr_length
,
4253 ill
->ill_sap_length
);
4257 * Note: xresolv interfaces will eventually need NOARP
4258 * set here as well, but that will require those
4259 * external resolvers to have some knowledge of
4260 * that flag and act appropriately. Not to be changed
4263 ill
->ill_flags
|= ILLF_NONUD
;
4265 ill
->ill_flags
|= ILLF_NOARP
;
4267 if (ill
->ill_mactype
== SUNW_DL_VNI
) {
4268 ill
->ill_ipif
->ipif_flags
|= IPIF_NOXMIT
;
4269 } else if (ill
->ill_phys_addr_length
== 0 ||
4270 ill
->ill_mactype
== DL_IPV4
||
4271 ill
->ill_mactype
== DL_IPV6
) {
4273 * The underying link is point-to-point, so mark the
4274 * interface as such. We can do IP multicast over
4275 * such a link since it transmits all network-layer
4276 * packets to the remote side the same way.
4278 ill
->ill_flags
|= ILLF_MULTICAST
;
4279 ill
->ill_ipif
->ipif_flags
|= IPIF_POINTOPOINT
;
4282 ill
->ill_net_type
= IRE_IF_RESOLVER
;
4283 if (ill
->ill_bcast_mp
!= NULL
)
4284 freemsg(ill
->ill_bcast_mp
);
4285 ill
->ill_bcast_mp
= ill_dlur_gen(brdcst_addr
,
4286 ill
->ill_bcast_addr_length
, ill
->ill_sap
,
4287 ill
->ill_sap_length
);
4289 * Later detect lack of DLPI driver multicast
4290 * capability by catching DL_ENABMULTI errors in
4293 ill
->ill_flags
|= ILLF_MULTICAST
;
4295 ill
->ill_ipif
->ipif_flags
|= IPIF_BROADCAST
;
4298 /* For IPMP, PHYI_IPMP should already be set by phyint_flags_init() */
4299 if (ill
->ill_mactype
== SUNW_DL_IPMP
)
4300 ASSERT(ill
->ill_phyint
->phyint_flags
& PHYI_IPMP
);
4302 /* By default an interface does not support any CoS marking */
4303 ill
->ill_flags
&= ~ILLF_COS_ENABLED
;
4306 * If we get QoS information in DL_INFO_ACK, the device supports
4307 * some form of CoS marking, set ILLF_COS_ENABLED.
4309 sel1
= (dl_qos_cl_sel1_t
*)mi_offset_param(mp
, dlia
->dl_qos_offset
,
4310 dlia
->dl_qos_length
);
4311 if ((sel1
!= NULL
) && (sel1
->dl_qos_type
== DL_QOS_CL_SEL1
)) {
4312 ill
->ill_flags
|= ILLF_COS_ENABLED
;
4315 /* Clear any previous error indication. */
4321 * Perform various checks to verify that an address would make sense as a
4322 * local, remote, or subnet interface address.
4325 ip_addr_ok_v4(ipaddr_t addr
, ipaddr_t subnet_mask
)
4330 * Don't allow all zeroes, or all ones, but allow
4333 if ((net_mask
= ip_net_mask(addr
)) == 0)
4335 /* A given netmask overrides the "guess" netmask */
4336 if (subnet_mask
!= 0)
4337 net_mask
= subnet_mask
;
4338 if ((net_mask
!= ~(ipaddr_t
)0) && ((addr
== (addr
& net_mask
)) ||
4339 (addr
== (addr
| ~net_mask
)))) {
4344 * Even if the netmask is all ones, we do not allow address to be
4347 if (addr
== INADDR_BROADCAST
)
4356 #define V6_IPIF_LINKLOCAL(p) \
4357 IN6_IS_ADDR_LINKLOCAL(&(p)->ipif_v6lcl_addr)
4360 * Compare two given ipifs and check if the second one is better than
4361 * the first one using the order of preference (not taking deprecated
4362 * into acount) specified in ipif_lookup_multicast().
4365 ipif_comp_multi(ipif_t
*old_ipif
, ipif_t
*new_ipif
, boolean_t isv6
)
4367 /* Check the least preferred first. */
4368 if (IS_LOOPBACK(old_ipif
->ipif_ill
)) {
4369 /* If both ipifs are the same, use the first one. */
4370 if (IS_LOOPBACK(new_ipif
->ipif_ill
))
4376 /* For IPv6, check for link local address. */
4377 if (isv6
&& V6_IPIF_LINKLOCAL(old_ipif
)) {
4378 if (IS_LOOPBACK(new_ipif
->ipif_ill
) ||
4379 V6_IPIF_LINKLOCAL(new_ipif
)) {
4380 /* The second one is equal or less preferred. */
4387 /* Then check for point to point interface. */
4388 if (old_ipif
->ipif_flags
& IPIF_POINTOPOINT
) {
4389 if (IS_LOOPBACK(new_ipif
->ipif_ill
) ||
4390 (isv6
&& V6_IPIF_LINKLOCAL(new_ipif
)) ||
4391 (new_ipif
->ipif_flags
& IPIF_POINTOPOINT
)) {
4398 /* old_ipif is a normal interface, so no need to use the new one. */
4403 * Find a mulitcast-capable ipif given an IP instance and zoneid.
4404 * The ipif must be up, and its ill must multicast-capable, not
4405 * condemned, not an underlying interface in an IPMP group, and
4406 * not a VNI interface. Order of preference:
4409 * 1b. normal, but deprecated
4410 * 2a. point to point
4411 * 2b. point to point, but deprecated
4413 * 3b. link local, but deprecated
4417 ipif_lookup_multicast(ip_stack_t
*ipst
, zoneid_t zoneid
, boolean_t isv6
)
4420 ill_walk_context_t ctx
;
4422 ipif_t
*saved_ipif
= NULL
;
4423 ipif_t
*dep_ipif
= NULL
;
4425 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
4427 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
4429 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
4431 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
4432 mutex_enter(&ill
->ill_lock
);
4433 if (IS_VNI(ill
) || IS_UNDER_IPMP(ill
) ||
4434 ILL_IS_CONDEMNED(ill
) ||
4435 !(ill
->ill_flags
& ILLF_MULTICAST
)) {
4436 mutex_exit(&ill
->ill_lock
);
4439 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
4440 ipif
= ipif
->ipif_next
) {
4441 if (zoneid
!= ipif
->ipif_zoneid
&&
4442 zoneid
!= ALL_ZONES
&&
4443 ipif
->ipif_zoneid
!= ALL_ZONES
) {
4446 if (!(ipif
->ipif_flags
& IPIF_UP
) ||
4447 IPIF_IS_CONDEMNED(ipif
)) {
4452 * Found one candidate. If it is deprecated,
4453 * remember it in dep_ipif. If it is not deprecated,
4454 * remember it in saved_ipif.
4456 if (ipif
->ipif_flags
& IPIF_DEPRECATED
) {
4457 if (dep_ipif
== NULL
) {
4459 } else if (ipif_comp_multi(dep_ipif
, ipif
,
4462 * If the previous dep_ipif does not
4463 * belong to the same ill, we've done
4464 * a ipif_refhold() on it. So we need
4467 if (dep_ipif
->ipif_ill
!= ill
)
4468 ipif_refrele(dep_ipif
);
4473 if (saved_ipif
== NULL
) {
4476 if (ipif_comp_multi(saved_ipif
, ipif
, isv6
)) {
4477 if (saved_ipif
->ipif_ill
!= ill
)
4478 ipif_refrele(saved_ipif
);
4484 * Before going to the next ill, do a ipif_refhold() on the
4487 if (saved_ipif
!= NULL
&& saved_ipif
->ipif_ill
== ill
)
4488 ipif_refhold_locked(saved_ipif
);
4489 if (dep_ipif
!= NULL
&& dep_ipif
->ipif_ill
== ill
)
4490 ipif_refhold_locked(dep_ipif
);
4491 mutex_exit(&ill
->ill_lock
);
4493 rw_exit(&ipst
->ips_ill_g_lock
);
4496 * If we have only the saved_ipif, return it. But if we have both
4497 * saved_ipif and dep_ipif, check to see which one is better.
4499 if (saved_ipif
!= NULL
) {
4500 if (dep_ipif
!= NULL
) {
4501 if (ipif_comp_multi(saved_ipif
, dep_ipif
, isv6
)) {
4502 ipif_refrele(saved_ipif
);
4505 ipif_refrele(dep_ipif
);
4506 return (saved_ipif
);
4509 return (saved_ipif
);
4516 ill_lookup_multicast(ip_stack_t
*ipst
, zoneid_t zoneid
, boolean_t isv6
)
4521 ipif
= ipif_lookup_multicast(ipst
, zoneid
, isv6
);
4525 ill
= ipif
->ipif_ill
;
4532 * This function is called when an application does not specify an interface
4533 * to be used for multicast traffic (joining a group/sending data). It
4534 * calls ire_lookup_multi() to look for an interface route for the
4535 * specified multicast group. Doing this allows the administrator to add
4536 * prefix routes for multicast to indicate which interface to be used for
4537 * multicast traffic in the above scenario. The route could be for all
4538 * multicast (224.0/4), for a single multicast group (a /32 route) or
4539 * anything in between. If there is no such multicast route, we just find
4540 * any multicast capable interface and return it. The returned ipif
4543 * We support MULTIRT and RTF_SETSRC on the multicast routes added to the
4544 * unicast table. This is used by CGTP.
4547 ill_lookup_group_v4(ipaddr_t group
, zoneid_t zoneid
, ip_stack_t
*ipst
,
4548 boolean_t
*multirtp
, ipaddr_t
*setsrcp
)
4552 ill
= ire_lookup_multi_ill_v4(group
, zoneid
, ipst
, multirtp
, setsrcp
);
4556 return (ill_lookup_multicast(ipst
, zoneid
, B_FALSE
));
4560 * Look for an ipif with the specified interface address and destination.
4561 * The destination address is used only for matching point-to-point interfaces.
4564 ipif_lookup_interface(ipaddr_t if_addr
, ipaddr_t dst
, ip_stack_t
*ipst
)
4568 ill_walk_context_t ctx
;
4571 * First match all the point-to-point interfaces
4572 * before looking at non-point-to-point interfaces.
4573 * This is done to avoid returning non-point-to-point
4574 * ipif instead of unnumbered point-to-point ipif.
4576 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
4577 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
4578 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
4579 mutex_enter(&ill
->ill_lock
);
4580 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
4581 ipif
= ipif
->ipif_next
) {
4582 /* Allow the ipif to be down */
4583 if ((ipif
->ipif_flags
& IPIF_POINTOPOINT
) &&
4584 (ipif
->ipif_lcl_addr
== if_addr
) &&
4585 (ipif
->ipif_pp_dst_addr
== dst
)) {
4586 if (!IPIF_IS_CONDEMNED(ipif
)) {
4587 ipif_refhold_locked(ipif
);
4588 mutex_exit(&ill
->ill_lock
);
4589 rw_exit(&ipst
->ips_ill_g_lock
);
4594 mutex_exit(&ill
->ill_lock
);
4596 rw_exit(&ipst
->ips_ill_g_lock
);
4598 /* lookup the ipif based on interface address */
4599 ipif
= ipif_lookup_addr(if_addr
, NULL
, ALL_ZONES
, ipst
);
4600 ASSERT(ipif
== NULL
|| !ipif
->ipif_isv6
);
4605 * Common function for ipif_lookup_addr() and ipif_lookup_addr_exact().
4608 ipif_lookup_addr_common(ipaddr_t addr
, ill_t
*match_ill
, uint32_t match_flags
,
4609 zoneid_t zoneid
, ip_stack_t
*ipst
)
4613 boolean_t ptp
= B_FALSE
;
4614 ill_walk_context_t ctx
;
4615 boolean_t match_illgrp
= (match_flags
& IPIF_MATCH_ILLGRP
);
4616 boolean_t no_duplicate
= (match_flags
& IPIF_MATCH_NONDUP
);
4618 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
4620 * Repeat twice, first based on local addresses and
4621 * next time for pointopoint.
4624 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
4625 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
4626 if (match_ill
!= NULL
&& ill
!= match_ill
&&
4627 (!match_illgrp
|| !IS_IN_SAME_ILLGRP(ill
, match_ill
))) {
4630 mutex_enter(&ill
->ill_lock
);
4631 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
4632 ipif
= ipif
->ipif_next
) {
4633 if (zoneid
!= ALL_ZONES
&&
4634 zoneid
!= ipif
->ipif_zoneid
&&
4635 ipif
->ipif_zoneid
!= ALL_ZONES
)
4638 if (no_duplicate
&& !(ipif
->ipif_flags
& IPIF_UP
))
4641 /* Allow the ipif to be down */
4642 if ((!ptp
&& (ipif
->ipif_lcl_addr
== addr
) &&
4643 ((ipif
->ipif_flags
& IPIF_UNNUMBERED
) == 0)) ||
4644 (ptp
&& (ipif
->ipif_flags
& IPIF_POINTOPOINT
) &&
4645 (ipif
->ipif_pp_dst_addr
== addr
))) {
4646 if (!IPIF_IS_CONDEMNED(ipif
)) {
4647 ipif_refhold_locked(ipif
);
4648 mutex_exit(&ill
->ill_lock
);
4649 rw_exit(&ipst
->ips_ill_g_lock
);
4654 mutex_exit(&ill
->ill_lock
);
4657 /* If we already did the ptp case, then we are done */
4659 rw_exit(&ipst
->ips_ill_g_lock
);
4667 * Lookup an ipif with the specified address. For point-to-point links we
4668 * look for matches on either the destination address or the local address,
4669 * but we skip the local address check if IPIF_UNNUMBERED is set. If the
4670 * `match_ill' argument is non-NULL, the lookup is restricted to that ill
4671 * (or illgrp if `match_ill' is in an IPMP group).
4674 ipif_lookup_addr(ipaddr_t addr
, ill_t
*match_ill
, zoneid_t zoneid
,
4677 return (ipif_lookup_addr_common(addr
, match_ill
, IPIF_MATCH_ILLGRP
,
4682 * Lookup an ipif with the specified address. Similar to ipif_lookup_addr,
4683 * except that we will only return an address if it is not marked as
4687 ipif_lookup_addr_nondup(ipaddr_t addr
, ill_t
*match_ill
, zoneid_t zoneid
,
4690 return (ipif_lookup_addr_common(addr
, match_ill
,
4691 (IPIF_MATCH_ILLGRP
| IPIF_MATCH_NONDUP
),
4696 * Special abbreviated version of ipif_lookup_addr() that doesn't match
4697 * `match_ill' across the IPMP group. This function is only needed in some
4698 * corner-cases; almost everything should use ipif_lookup_addr().
4701 ipif_lookup_addr_exact(ipaddr_t addr
, ill_t
*match_ill
, ip_stack_t
*ipst
)
4703 ASSERT(match_ill
!= NULL
);
4704 return (ipif_lookup_addr_common(addr
, match_ill
, 0, ALL_ZONES
,
4709 * Look for an ipif with the specified address. For point-point links
4710 * we look for matches on either the destination address and the local
4711 * address, but we ignore the check on the local address if IPIF_UNNUMBERED
4713 * If the `match_ill' argument is non-NULL, the lookup is restricted to that
4714 * ill (or illgrp if `match_ill' is in an IPMP group).
4715 * Return the zoneid for the ipif which matches. ALL_ZONES if no match.
4718 ipif_lookup_addr_zoneid(ipaddr_t addr
, ill_t
*match_ill
, ip_stack_t
*ipst
)
4723 boolean_t ptp
= B_FALSE
;
4724 ill_walk_context_t ctx
;
4726 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
4728 * Repeat twice, first based on local addresses and
4729 * next time for pointopoint.
4732 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
4733 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
4734 if (match_ill
!= NULL
&& ill
!= match_ill
&&
4735 !IS_IN_SAME_ILLGRP(ill
, match_ill
)) {
4738 mutex_enter(&ill
->ill_lock
);
4739 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
4740 ipif
= ipif
->ipif_next
) {
4741 /* Allow the ipif to be down */
4742 if ((!ptp
&& (ipif
->ipif_lcl_addr
== addr
) &&
4743 ((ipif
->ipif_flags
& IPIF_UNNUMBERED
) == 0)) ||
4744 (ptp
&& (ipif
->ipif_flags
& IPIF_POINTOPOINT
) &&
4745 (ipif
->ipif_pp_dst_addr
== addr
)) &&
4746 !(ipif
->ipif_state_flags
& IPIF_CONDEMNED
)) {
4747 zoneid
= ipif
->ipif_zoneid
;
4748 mutex_exit(&ill
->ill_lock
);
4749 rw_exit(&ipst
->ips_ill_g_lock
);
4753 mutex_exit(&ill
->ill_lock
);
4756 /* If we already did the ptp case, then we are done */
4758 rw_exit(&ipst
->ips_ill_g_lock
);
4766 * Look for an ipif that matches the specified remote address i.e. the
4767 * ipif that would receive the specified packet.
4768 * First look for directly connected interfaces and then do a recursive
4769 * IRE lookup and pick the first ipif corresponding to the source address in the
4771 * Returns: held ipif
4773 * This is only used for ICMP_ADDRESS_MASK_REQUESTs
4776 ipif_lookup_remote(ill_t
*ill
, ipaddr_t addr
, zoneid_t zoneid
)
4780 ASSERT(!ill
->ill_isv6
);
4783 * Someone could be changing this ipif currently or change it
4784 * after we return this. Thus a few packets could use the old
4785 * old values. However structure updates/creates (ire, ilg, ilm etc)
4786 * will atomically be updated or cleaned up with the new value
4787 * Thus we don't need a lock to check the flags or other attrs below.
4789 mutex_enter(&ill
->ill_lock
);
4790 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
4791 if (IPIF_IS_CONDEMNED(ipif
))
4793 if (zoneid
!= ALL_ZONES
&& zoneid
!= ipif
->ipif_zoneid
&&
4794 ipif
->ipif_zoneid
!= ALL_ZONES
)
4796 /* Allow the ipif to be down */
4797 if (ipif
->ipif_flags
& IPIF_POINTOPOINT
) {
4798 if ((ipif
->ipif_pp_dst_addr
== addr
) ||
4799 (!(ipif
->ipif_flags
& IPIF_UNNUMBERED
) &&
4800 ipif
->ipif_lcl_addr
== addr
)) {
4801 ipif_refhold_locked(ipif
);
4802 mutex_exit(&ill
->ill_lock
);
4805 } else if (ipif
->ipif_subnet
== (addr
& ipif
->ipif_net_mask
)) {
4806 ipif_refhold_locked(ipif
);
4807 mutex_exit(&ill
->ill_lock
);
4811 mutex_exit(&ill
->ill_lock
);
4813 * For a remote destination it isn't possible to nail down a particular
4817 /* Pick the first interface */
4818 ipif
= ipif_get_next_ipif(NULL
, ill
);
4823 * This func does not prevent refcnt from increasing. But if
4824 * the caller has taken steps to that effect, then this func
4825 * can be used to determine whether the ill has become quiescent
4828 ill_is_quiescent(ill_t
*ill
)
4832 ASSERT(MUTEX_HELD(&ill
->ill_lock
));
4834 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
4835 if (ipif
->ipif_refcnt
!= 0)
4838 if (!ILL_DOWN_OK(ill
) || ill
->ill_refcnt
!= 0) {
4845 ill_is_freeable(ill_t
*ill
)
4849 ASSERT(MUTEX_HELD(&ill
->ill_lock
));
4851 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
4852 if (ipif
->ipif_refcnt
!= 0) {
4856 if (!ILL_FREE_OK(ill
) || ill
->ill_refcnt
!= 0) {
4863 * This func does not prevent refcnt from increasing. But if
4864 * the caller has taken steps to that effect, then this func
4865 * can be used to determine whether the ipif has become quiescent
4868 ipif_is_quiescent(ipif_t
*ipif
)
4872 ASSERT(MUTEX_HELD(&ipif
->ipif_ill
->ill_lock
));
4874 if (ipif
->ipif_refcnt
!= 0)
4877 ill
= ipif
->ipif_ill
;
4878 if (ill
->ill_ipif_up_count
!= 0 || ill
->ill_ipif_dup_count
!= 0 ||
4879 ill
->ill_logical_down
) {
4883 /* This is the last ipif going down or being deleted on this ill */
4884 if (ill
->ill_ire_cnt
!= 0 || ill
->ill_refcnt
!= 0) {
4892 * return true if the ipif can be destroyed: the ipif has to be quiescent
4893 * with zero references from ire/ilm to it.
4896 ipif_is_freeable(ipif_t
*ipif
)
4898 ASSERT(MUTEX_HELD(&ipif
->ipif_ill
->ill_lock
));
4899 ASSERT(ipif
->ipif_id
!= 0);
4900 return (ipif
->ipif_refcnt
== 0);
4904 * The ipif/ill/ire has been refreled. Do the tail processing.
4905 * Determine if the ipif or ill in question has become quiescent and if so
4906 * wakeup close and/or restart any queued pending ioctl that is waiting
4907 * for the ipif_down (or ill_down)
4910 ipif_ill_refrele_tail(ill_t
*ill
)
4917 dl_notify_ind_t
*dlindp
;
4919 ASSERT(MUTEX_HELD(&ill
->ill_lock
));
4921 if ((ill
->ill_state_flags
& ILL_CONDEMNED
) && ill_is_freeable(ill
)) {
4922 /* ip_modclose() may be waiting */
4923 cv_broadcast(&ill
->ill_cv
);
4926 ipsq
= ill
->ill_phyint
->phyint_ipsq
;
4927 mutex_enter(&ipsq
->ipsq_lock
);
4928 ipx
= ipsq
->ipsq_xop
;
4929 mutex_enter(&ipx
->ipx_lock
);
4930 if (ipx
->ipx_waitfor
== 0) /* no one's waiting; bail */
4933 ASSERT(ipx
->ipx_pending_mp
!= NULL
&& ipx
->ipx_pending_ipif
!= NULL
);
4935 ipif
= ipx
->ipx_pending_ipif
;
4936 if (ipif
->ipif_ill
!= ill
) /* wait is for another ill; bail */
4939 switch (ipx
->ipx_waitfor
) {
4941 if (!ipif_is_quiescent(ipif
))
4945 if (!ipif_is_freeable(ipif
))
4949 if (!ill_is_quiescent(ill
))
4954 * ILL_FREE is only for loopback; normal ill teardown waits
4955 * synchronously in ip_modclose() without using ipx_waitfor,
4956 * handled by the cv_broadcast() at the top of this function.
4958 if (!ill_is_freeable(ill
))
4962 cmn_err(CE_PANIC
, "ipsq: %p unknown ipx_waitfor %d\n",
4963 (void *)ipsq
, ipx
->ipx_waitfor
);
4966 ill_refhold_locked(ill
); /* for qwriter_ip() call below */
4967 mutex_exit(&ipx
->ipx_lock
);
4968 mp
= ipsq_pending_mp_get(ipsq
, &connp
);
4969 mutex_exit(&ipsq
->ipsq_lock
);
4970 mutex_exit(&ill
->ill_lock
);
4974 * NOTE: all of the qwriter_ip() calls below use CUR_OP since
4975 * we can only get here when the current operation decides it
4976 * it needs to quiesce via ipsq_pending_mp_add().
4978 switch (mp
->b_datap
->db_type
) {
4982 * For now, only DL_NOTIFY_IND messages can use this facility.
4984 dlindp
= (dl_notify_ind_t
*)mp
->b_rptr
;
4985 ASSERT(dlindp
->dl_primitive
== DL_NOTIFY_IND
);
4987 switch (dlindp
->dl_notification
) {
4988 case DL_NOTE_PHYS_ADDR
:
4989 qwriter_ip(ill
, ill
->ill_rq
, mp
,
4990 ill_set_phys_addr_tail
, CUR_OP
, B_TRUE
);
4992 case DL_NOTE_REPLUMB
:
4993 qwriter_ip(ill
, ill
->ill_rq
, mp
,
4994 ill_replumb_tail
, CUR_OP
, B_TRUE
);
5004 qwriter_ip(ill
, ill
->ill_rq
, mp
, ipif_all_down_tail
, CUR_OP
,
5010 qwriter_ip(ill
, (connp
!= NULL
? CONNP_TO_WQ(connp
) :
5011 ill
->ill_wq
), mp
, ip_reprocess_ioctl
, CUR_OP
, B_TRUE
);
5015 cmn_err(CE_PANIC
, "ipif_ill_refrele_tail mp %p "
5016 "db_type %d\n", (void *)mp
, mp
->b_datap
->db_type
);
5020 mutex_exit(&ipsq
->ipsq_lock
);
5021 mutex_exit(&ipx
->ipx_lock
);
5022 mutex_exit(&ill
->ill_lock
);
5026 /* Reuse trace buffer from beginning (if reached the end) and record trace */
5028 th_trace_rrecord(th_trace_t
*th_trace
)
5033 lastref
= th_trace
->th_trace_lastref
;
5035 if (lastref
== TR_BUF_MAX
)
5037 th_trace
->th_trace_lastref
= lastref
;
5038 tr_buf
= &th_trace
->th_trbuf
[lastref
];
5039 tr_buf
->tr_time
= ddi_get_lbolt();
5040 tr_buf
->tr_depth
= getpcstack(tr_buf
->tr_stack
, TR_STACK_DEPTH
);
5044 th_trace_free(void *value
)
5046 th_trace_t
*th_trace
= value
;
5048 ASSERT(th_trace
->th_refcnt
== 0);
5049 kmem_free(th_trace
, sizeof (*th_trace
));
5053 * Find or create the per-thread hash table used to track object references.
5054 * The ipst argument is NULL if we shouldn't allocate.
5056 * Accesses per-thread data, so there's no need to lock here.
5059 th_trace_gethash(ip_stack_t
*ipst
)
5063 if ((thh
= tsd_get(ip_thread_data
)) == NULL
&& ipst
!= NULL
) {
5066 size_t objsize
, rshift
;
5069 if ((thh
= kmem_alloc(sizeof (*thh
), KM_NOSLEEP
)) == NULL
)
5071 (void) snprintf(name
, sizeof (name
), "th_trace_%p",
5075 * We use mod_hash_create_extended here rather than the more
5076 * obvious mod_hash_create_ptrhash because the latter has a
5077 * hard-coded KM_SLEEP, and we'd prefer to fail rather than
5080 objsize
= MAX(MAX(sizeof (ill_t
), sizeof (ipif_t
)),
5081 MAX(sizeof (ire_t
), sizeof (ncec_t
)));
5082 rshift
= highbit(objsize
);
5083 mh
= mod_hash_create_extended(name
, 64, mod_hash_null_keydtor
,
5084 th_trace_free
, mod_hash_byptr
, (void *)rshift
,
5085 mod_hash_ptrkey_cmp
, KM_NOSLEEP
);
5087 kmem_free(thh
, sizeof (*thh
));
5091 thh
->thh_ipst
= ipst
;
5093 * We trace ills, ipifs, ires, and nces. All of these are
5094 * per-IP-stack, so the lock on the thread list is as well.
5096 rw_enter(&ip_thread_rwlock
, RW_WRITER
);
5097 list_insert_tail(&ip_thread_list
, thh
);
5098 rw_exit(&ip_thread_rwlock
);
5099 retv
= tsd_set(ip_thread_data
, thh
);
5102 return (thh
!= NULL
? thh
->thh_hash
: NULL
);
5106 th_trace_ref(const void *obj
, ip_stack_t
*ipst
)
5108 th_trace_t
*th_trace
;
5112 if ((mh
= th_trace_gethash(ipst
)) == NULL
)
5116 * Attempt to locate the trace buffer for this obj and thread.
5117 * If it does not exist, then allocate a new trace buffer and
5118 * insert into the hash.
5120 if (mod_hash_find(mh
, (mod_hash_key_t
)obj
, &val
) == MH_ERR_NOTFOUND
) {
5121 th_trace
= kmem_zalloc(sizeof (th_trace_t
), KM_NOSLEEP
);
5122 if (th_trace
== NULL
)
5125 th_trace
->th_id
= curthread
;
5126 if (mod_hash_insert(mh
, (mod_hash_key_t
)obj
,
5127 (mod_hash_val_t
)th_trace
) != 0) {
5128 kmem_free(th_trace
, sizeof (th_trace_t
));
5132 th_trace
= (th_trace_t
*)val
;
5135 ASSERT(th_trace
->th_refcnt
>= 0 &&
5136 th_trace
->th_refcnt
< TR_BUF_MAX
- 1);
5138 th_trace
->th_refcnt
++;
5139 th_trace_rrecord(th_trace
);
5144 * For the purpose of tracing a reference release, we assume that global
5145 * tracing is always on and that the same thread initiated the reference hold
5149 th_trace_unref(const void *obj
)
5153 th_trace_t
*th_trace
;
5156 mh
= th_trace_gethash(NULL
);
5157 retv
= mod_hash_find(mh
, (mod_hash_key_t
)obj
, &val
);
5159 th_trace
= (th_trace_t
*)val
;
5161 ASSERT(th_trace
->th_refcnt
> 0);
5162 th_trace
->th_refcnt
--;
5163 th_trace_rrecord(th_trace
);
5167 * If tracing has been disabled, then we assume that the reference counts are
5168 * now useless, and we clear them out before destroying the entries.
5171 th_trace_cleanup(const void *obj
, boolean_t trace_disable
)
5176 th_trace_t
*th_trace
;
5179 rw_enter(&ip_thread_rwlock
, RW_READER
);
5180 for (thh
= list_head(&ip_thread_list
); thh
!= NULL
;
5181 thh
= list_next(&ip_thread_list
, thh
)) {
5182 if (mod_hash_find(mh
= thh
->thh_hash
, (mod_hash_key_t
)obj
,
5184 th_trace
= (th_trace_t
*)val
;
5186 th_trace
->th_refcnt
= 0;
5187 retv
= mod_hash_destroy(mh
, (mod_hash_key_t
)obj
);
5191 rw_exit(&ip_thread_rwlock
);
5195 ipif_trace_ref(ipif_t
*ipif
)
5197 ASSERT(MUTEX_HELD(&ipif
->ipif_ill
->ill_lock
));
5199 if (ipif
->ipif_trace_disable
)
5202 if (!th_trace_ref(ipif
, ipif
->ipif_ill
->ill_ipst
)) {
5203 ipif
->ipif_trace_disable
= B_TRUE
;
5204 ipif_trace_cleanup(ipif
);
5209 ipif_untrace_ref(ipif_t
*ipif
)
5211 ASSERT(MUTEX_HELD(&ipif
->ipif_ill
->ill_lock
));
5213 if (!ipif
->ipif_trace_disable
)
5214 th_trace_unref(ipif
);
5218 ill_trace_ref(ill_t
*ill
)
5220 ASSERT(MUTEX_HELD(&ill
->ill_lock
));
5222 if (ill
->ill_trace_disable
)
5225 if (!th_trace_ref(ill
, ill
->ill_ipst
)) {
5226 ill
->ill_trace_disable
= B_TRUE
;
5227 ill_trace_cleanup(ill
);
5232 ill_untrace_ref(ill_t
*ill
)
5234 ASSERT(MUTEX_HELD(&ill
->ill_lock
));
5236 if (!ill
->ill_trace_disable
)
5237 th_trace_unref(ill
);
5241 * Called when ipif is unplumbed or when memory alloc fails. Note that on
5242 * failure, ipif_trace_disable is set.
5245 ipif_trace_cleanup(const ipif_t
*ipif
)
5247 th_trace_cleanup(ipif
, ipif
->ipif_trace_disable
);
5251 * Called when ill is unplumbed or when memory alloc fails. Note that on
5252 * failure, ill_trace_disable is set.
5255 ill_trace_cleanup(const ill_t
*ill
)
5257 th_trace_cleanup(ill
, ill
->ill_trace_disable
);
5262 ipif_refhold_locked(ipif_t
*ipif
)
5264 ASSERT(MUTEX_HELD(&ipif
->ipif_ill
->ill_lock
));
5265 ipif
->ipif_refcnt
++;
5266 IPIF_TRACE_REF(ipif
);
5270 ipif_refhold(ipif_t
*ipif
)
5274 ill
= ipif
->ipif_ill
;
5275 mutex_enter(&ill
->ill_lock
);
5276 ipif
->ipif_refcnt
++;
5277 IPIF_TRACE_REF(ipif
);
5278 mutex_exit(&ill
->ill_lock
);
5282 * Must not be called while holding any locks. Otherwise if this is
5283 * the last reference to be released there is a chance of recursive mutex
5284 * panic due to ipif_refrele -> ipif_ill_refrele_tail -> qwriter_ip trying
5285 * to restart an ioctl.
5288 ipif_refrele(ipif_t
*ipif
)
5292 ill
= ipif
->ipif_ill
;
5294 mutex_enter(&ill
->ill_lock
);
5295 ASSERT(ipif
->ipif_refcnt
!= 0);
5296 ipif
->ipif_refcnt
--;
5297 IPIF_UNTRACE_REF(ipif
);
5298 if (ipif
->ipif_refcnt
!= 0) {
5299 mutex_exit(&ill
->ill_lock
);
5303 /* Drops the ill_lock */
5304 ipif_ill_refrele_tail(ill
);
5308 ipif_get_next_ipif(ipif_t
*curr
, ill_t
*ill
)
5312 mutex_enter(&ill
->ill_lock
);
5313 for (ipif
= (curr
== NULL
? ill
->ill_ipif
: curr
->ipif_next
);
5314 ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
5315 if (IPIF_IS_CONDEMNED(ipif
))
5317 ipif_refhold_locked(ipif
);
5318 mutex_exit(&ill
->ill_lock
);
5321 mutex_exit(&ill
->ill_lock
);
5326 * TODO: make this table extendible at run time
5327 * Return a pointer to the mac type info for 'mac_type'
5330 ip_m_lookup(t_uscalar_t mac_type
)
5334 for (ipm
= ip_m_tbl
; ipm
< A_END(ip_m_tbl
); ipm
++)
5335 if (ipm
->ip_m_mac_type
== mac_type
)
5341 * Make a link layer address from the multicast IP address *addr.
5342 * To form the link layer address, invoke the ip_m_v*mapping function
5343 * associated with the link-layer type.
5346 ip_mcast_mapping(ill_t
*ill
, uchar_t
*addr
, uchar_t
*hwaddr
)
5350 if (ill
->ill_net_type
== IRE_IF_NORESOLVER
)
5353 ASSERT(addr
!= NULL
);
5355 ipm
= ip_m_lookup(ill
->ill_mactype
);
5357 (ill
->ill_isv6
&& ipm
->ip_m_v6mapping
== NULL
) ||
5358 (!ill
->ill_isv6
&& ipm
->ip_m_v4mapping
== NULL
)) {
5359 ip0dbg(("no mapping for ill %s mactype 0x%x\n",
5360 ill
->ill_name
, ill
->ill_mactype
));
5364 (*ipm
->ip_m_v6mapping
)(ill
, addr
, hwaddr
);
5366 (*ipm
->ip_m_v4mapping
)(ill
, addr
, hwaddr
);
5370 * Returns B_FALSE if the IPv4 netmask pointed by `mask' is non-contiguous.
5371 * Otherwise returns B_TRUE.
5373 * The netmask can be verified to be contiguous with 32 shifts and or
5374 * operations. Take the contiguous mask (in host byte order) and compute
5375 * mask | mask << 1 | mask << 2 | ... | mask << 31
5376 * the result will be the same as the 'mask' for contiguous mask.
5379 ip_contiguous_mask(uint32_t mask
)
5384 for (i
= 1; i
< 32; i
++)
5391 * ip_rt_add is called to add an IPv4 route to the forwarding table.
5392 * ill is passed in to associate it with the correct interface.
5393 * If ire_arg is set, then we return the held IRE in that location.
5396 ip_rt_add(ipaddr_t dst_addr
, ipaddr_t mask
, ipaddr_t gw_addr
,
5397 ipaddr_t src_addr
, int flags
, ill_t
*ill
, ire_t
**ire_arg
,
5398 boolean_t ioctl_msg
, ip_stack_t
*ipst
, zoneid_t zoneid
)
5401 ire_t
*gw_ire
= NULL
;
5402 ipif_t
*ipif
= NULL
;
5404 int match_flags
= MATCH_IRE_TYPE
;
5405 boolean_t cgtp_broadcast
;
5406 boolean_t unbound
= B_FALSE
;
5408 ip1dbg(("ip_rt_add:"));
5410 if (ire_arg
!= NULL
)
5413 /* disallow non-contiguous netmasks */
5414 if (!ip_contiguous_mask(ntohl(mask
)))
5418 * If this is the case of RTF_HOST being set, then we set the netmask
5419 * to all ones (regardless if one was supplied).
5421 if (flags
& RTF_HOST
)
5422 mask
= IP_HOST_MASK
;
5425 * Prevent routes with a zero gateway from being created (since
5426 * interfaces can currently be plumbed and brought up no assigned
5430 return (ENETUNREACH
);
5432 * Get the ipif, if any, corresponding to the gw_addr
5433 * If -ifp was specified we restrict ourselves to the ill, otherwise
5434 * we match on the gatway and destination to handle unnumbered pt-pt
5438 ipif
= ipif_lookup_addr(gw_addr
, ill
, ALL_ZONES
, ipst
);
5440 ipif
= ipif_lookup_interface(gw_addr
, dst_addr
, ipst
);
5442 if (IS_VNI(ipif
->ipif_ill
)) {
5449 * GateD will attempt to create routes with a loopback interface
5450 * address as the gateway and with RTF_GATEWAY set. We allow
5451 * these routes to be added, but create them as interface routes
5452 * since the gateway is an interface address.
5454 if ((ipif
!= NULL
) && (ipif
->ipif_ire_type
== IRE_LOOPBACK
)) {
5455 flags
&= ~RTF_GATEWAY
;
5456 if (gw_addr
== INADDR_LOOPBACK
&& dst_addr
== INADDR_LOOPBACK
&&
5457 mask
== IP_HOST_MASK
) {
5458 ire
= ire_ftable_lookup_v4(dst_addr
, 0, 0, IRE_LOOPBACK
,
5459 NULL
, ALL_ZONES
, MATCH_IRE_TYPE
, 0, ipst
, NULL
);
5465 ip1dbg(("ip_rt_add: 0x%p creating IRE 0x%x"
5466 "for 0x%x\n", (void *)ipif
,
5467 ipif
->ipif_ire_type
,
5468 ntohl(ipif
->ipif_lcl_addr
)));
5470 (uchar_t
*)&dst_addr
, /* dest address */
5471 (uchar_t
*)&mask
, /* mask */
5472 NULL
, /* no gateway */
5473 ipif
->ipif_ire_type
, /* LOOPBACK */
5476 (ipif
->ipif_flags
& IPIF_PRIVATE
) ? RTF_PRIVATE
: 0,
5483 /* src address assigned by the caller? */
5484 if ((src_addr
!= INADDR_ANY
) && (flags
& RTF_SETSRC
))
5485 ire
->ire_setsrc_addr
= src_addr
;
5487 nire
= ire_add(ire
);
5490 * In the result of failure, ire_add() will have
5491 * already deleted the ire in question, so there
5492 * is no need to do that here.
5498 * Check if it was a duplicate entry. This handles
5499 * the case of two racing route adds for the same route
5502 ASSERT(nire
->ire_identical_ref
> 1);
5514 * The routes for multicast with CGTP are quite special in that
5515 * the gateway is the local interface address, yet RTF_GATEWAY
5516 * is set. We turn off RTF_GATEWAY to provide compatibility with
5517 * this undocumented and unusual use of multicast routes.
5519 if ((flags
& RTF_MULTIRT
) && ipif
!= NULL
)
5520 flags
&= ~RTF_GATEWAY
;
5523 * Traditionally, interface routes are ones where RTF_GATEWAY isn't set
5524 * and the gateway address provided is one of the system's interface
5525 * addresses. By using the routing socket interface and supplying an
5526 * RTA_IFP sockaddr with an interface index, an alternate method of
5527 * specifying an interface route to be created is available which uses
5528 * the interface index that specifies the outgoing interface rather than
5529 * the address of an outgoing interface (which may not be able to
5530 * uniquely identify an interface). When coupled with the RTF_GATEWAY
5531 * flag, routes can be specified which not only specify the next-hop to
5532 * be used when routing to a certain prefix, but also which outgoing
5533 * interface should be used.
5535 * Previously, interfaces would have unique addresses assigned to them
5536 * and so the address assigned to a particular interface could be used
5537 * to identify a particular interface. One exception to this was the
5538 * case of an unnumbered interface (where IPIF_UNNUMBERED was set).
5540 * With the advent of IPv6 and its link-local addresses, this
5541 * restriction was relaxed and interfaces could share addresses between
5542 * themselves. In fact, typically all of the link-local interfaces on
5543 * an IPv6 node or router will have the same link-local address. In
5544 * order to differentiate between these interfaces, the use of an
5545 * interface index is necessary and this index can be carried inside a
5546 * RTA_IFP sockaddr (which is actually a sockaddr_dl). One restriction
5547 * of using the interface index, however, is that all of the ipif's that
5548 * are part of an ill have the same index and so the RTA_IFP sockaddr
5549 * cannot be used to differentiate between ipif's (or logical
5550 * interfaces) that belong to the same ill (physical interface).
5552 * For example, in the following case involving IPv4 interfaces and
5553 * logical interfaces
5555 * 192.0.2.32 255.255.255.224 192.0.2.33 U if0
5556 * 192.0.2.32 255.255.255.224 192.0.2.34 U if0
5557 * 192.0.2.32 255.255.255.224 192.0.2.35 U if0
5559 * the ipif's corresponding to each of these interface routes can be
5560 * uniquely identified by the "gateway" (actually interface address).
5562 * In this case involving multiple IPv6 default routes to a particular
5563 * link-local gateway, the use of RTA_IFP is necessary to specify which
5564 * default route is of interest:
5566 * default fe80::123:4567:89ab:cdef U if0
5567 * default fe80::123:4567:89ab:cdef U if1
5570 /* RTF_GATEWAY not set */
5571 if (!(flags
& RTF_GATEWAY
)) {
5573 * Whether or not ill (RTA_IFP) is set, we require that
5574 * the gateway is one of our local addresses.
5577 return (ENETUNREACH
);
5580 * We use MATCH_IRE_ILL here. If the caller specified an
5581 * interface (from the RTA_IFP sockaddr) we use it, otherwise
5582 * we use the ill derived from the gateway address.
5583 * We can always match the gateway address since we record it
5584 * in ire_gateway_addr.
5585 * We don't allow RTA_IFP to specify a different ill than the
5586 * one matching the ipif to make sure we can delete the route.
5588 match_flags
|= MATCH_IRE_GW
| MATCH_IRE_ILL
;
5590 ill
= ipif
->ipif_ill
;
5591 } else if (ill
!= ipif
->ipif_ill
) {
5597 * We check for an existing entry at this point.
5599 * Since a netmask isn't passed in via the ioctl interface
5600 * (SIOCADDRT), we don't check for a matching netmask in that
5604 match_flags
|= MATCH_IRE_MASK
;
5605 ire
= ire_ftable_lookup_v4(dst_addr
, mask
, gw_addr
,
5606 IRE_INTERFACE
, ill
, ALL_ZONES
, match_flags
, 0, ipst
, NULL
);
5614 * Some software (for example, GateD and Sun Cluster) attempts
5615 * to create (what amount to) IRE_PREFIX routes with the
5616 * loopback address as the gateway. This is primarily done to
5617 * set up prefixes with the RTF_REJECT flag set (for example,
5618 * when generating aggregate routes.)
5620 * If the IRE type (as defined by ill->ill_net_type) would be
5621 * IRE_LOOPBACK, then we map the request into a
5622 * IRE_IF_NORESOLVER. We also OR in the RTF_BLACKHOLE flag as
5623 * these interface routes, by definition, can only be that.
5625 * Needless to say, the real IRE_LOOPBACK is NOT created by this
5626 * routine, but rather using ire_create() directly.
5629 type
= ill
->ill_net_type
;
5630 if (type
== IRE_LOOPBACK
) {
5631 type
= IRE_IF_NORESOLVER
;
5632 flags
|= RTF_BLACKHOLE
;
5636 * Create a copy of the IRE_IF_NORESOLVER or
5637 * IRE_IF_RESOLVER with the modified address, netmask, and
5641 (uchar_t
*)&dst_addr
,
5643 (uint8_t *)&gw_addr
,
5654 /* src address assigned by the caller? */
5655 if ((src_addr
!= INADDR_ANY
) && (flags
& RTF_SETSRC
))
5656 ire
->ire_setsrc_addr
= src_addr
;
5658 nire
= ire_add(ire
);
5661 * In the result of failure, ire_add() will have
5662 * already deleted the ire in question, so there
5663 * is no need to do that here.
5669 * Check if it was a duplicate entry. This handles
5670 * the case of two racing route adds for the same route
5683 * Get an interface IRE for the specified gateway.
5684 * If we don't have an IRE_IF_NORESOLVER or IRE_IF_RESOLVER for the
5685 * gateway, it is currently unreachable and we fail the request
5686 * accordingly. We reject any RTF_GATEWAY routes where the gateway
5687 * is an IRE_LOCAL or IRE_LOOPBACK.
5688 * If RTA_IFP was specified we look on that particular ill.
5691 match_flags
|= MATCH_IRE_ILL
;
5693 /* Check whether the gateway is reachable. */
5695 type
= IRE_INTERFACE
| IRE_LOCAL
| IRE_LOOPBACK
;
5696 if (flags
& RTF_INDIRECT
)
5697 type
|= IRE_OFFLINK
;
5699 gw_ire
= ire_ftable_lookup_v4(gw_addr
, 0, 0, type
, ill
,
5700 ALL_ZONES
, match_flags
, 0, ipst
, NULL
);
5701 if (gw_ire
== NULL
) {
5703 * With IPMP, we allow host routes to influence in.mpathd's
5704 * target selection. However, if the test addresses are on
5705 * their own network, the above lookup will fail since the
5706 * underlying IRE_INTERFACEs are marked hidden. So allow
5707 * hidden test IREs to be found and try again.
5709 if (!(match_flags
& MATCH_IRE_TESTHIDDEN
)) {
5710 match_flags
|= MATCH_IRE_TESTHIDDEN
;
5715 return (ENETUNREACH
);
5717 if (gw_ire
->ire_type
& (IRE_LOCAL
|IRE_LOOPBACK
)) {
5718 ire_refrele(gw_ire
);
5721 return (ENETUNREACH
);
5724 if (ill
== NULL
&& !(flags
& RTF_INDIRECT
)) {
5726 if (ipst
->ips_ip_strict_src_multihoming
> 0)
5727 ill
= gw_ire
->ire_ill
;
5731 * We create one of three types of IREs as a result of this request
5732 * based on the netmask. A netmask of all ones (which is automatically
5733 * assumed when RTF_HOST is set) results in an IRE_HOST being created.
5734 * An all zeroes netmask implies a default route so an IRE_DEFAULT is
5735 * created. Otherwise, an IRE_PREFIX route is created for the
5736 * destination prefix.
5738 if (mask
== IP_HOST_MASK
)
5745 /* check for a duplicate entry */
5746 ire
= ire_ftable_lookup_v4(dst_addr
, mask
, gw_addr
, type
, ill
,
5747 ALL_ZONES
, match_flags
| MATCH_IRE_MASK
| MATCH_IRE_GW
, 0, ipst
,
5752 ire_refrele(gw_ire
);
5757 /* Create the IRE. */
5759 (uchar_t
*)&dst_addr
, /* dest address */
5760 (uchar_t
*)&mask
, /* mask */
5761 (uchar_t
*)&gw_addr
, /* gateway address */
5762 (ushort_t
)type
, /* IRE type */
5771 ire_refrele(gw_ire
);
5775 /* Before we add, check if an extra CGTP broadcast is needed */
5776 cgtp_broadcast
= ((flags
& RTF_MULTIRT
) &&
5777 ip_type_v4(ire
->ire_addr
, ipst
) == IRE_BROADCAST
);
5779 /* src address assigned by the caller? */
5780 if ((src_addr
!= INADDR_ANY
) && (flags
& RTF_SETSRC
))
5781 ire
->ire_setsrc_addr
= src_addr
;
5783 ire
->ire_unbound
= unbound
;
5786 * POLICY: should we allow an RTF_HOST with address INADDR_ANY?
5787 * SUN/OS socket stuff does but do we really want to allow 0.0.0.0?
5790 /* Add the new IRE. */
5791 nire
= ire_add(ire
);
5794 * In the result of failure, ire_add() will have
5795 * already deleted the ire in question, so there
5796 * is no need to do that here.
5800 ire_refrele(gw_ire
);
5804 * Check if it was a duplicate entry. This handles
5805 * the case of two racing route adds for the same route
5812 ire_refrele(gw_ire
);
5817 if (flags
& RTF_MULTIRT
) {
5819 * Invoke the CGTP (multirouting) filtering module
5820 * to add the dst address in the filtering database.
5821 * Replicated inbound packets coming from that address
5822 * will be filtered to discard the duplicates.
5823 * It is not necessary to call the CGTP filter hook
5824 * when the dst address is a broadcast or multicast,
5825 * because an IP source address cannot be a broadcast
5828 if (cgtp_broadcast
) {
5829 ip_cgtp_bcast_add(ire
, ipst
);
5832 if (ipst
->ips_ip_cgtp_filter_ops
!= NULL
&&
5833 !CLASSD(ire
->ire_addr
)) {
5837 /* Find the source address corresponding to gw_ire */
5838 src_ipif
= ipif_lookup_addr(gw_ire
->ire_gateway_addr
,
5839 NULL
, zoneid
, ipst
);
5840 if (src_ipif
!= NULL
) {
5841 res
= ipst
->ips_ip_cgtp_filter_ops
->
5843 ipst
->ips_netstack
->netstack_stackid
,
5845 ire
->ire_gateway_addr
,
5846 ire
->ire_setsrc_addr
,
5847 src_ipif
->ipif_lcl_addr
);
5848 ipif_refrele(src_ipif
);
5850 res
= EADDRNOTAVAIL
;
5855 ire_refrele(gw_ire
);
5857 ire_refrele(ire
); /* Held in ire_add */
5864 if (gw_ire
!= NULL
) {
5865 ire_refrele(gw_ire
);
5870 * Save enough information so that we can recreate the IRE if
5871 * the interface goes down and then up. The metrics associated
5872 * with the route will be saved as well when rts_setmetrics() is
5873 * called after the IRE has been created. In the case where
5874 * memory cannot be allocated, none of this information will be
5877 ill_save_ire(ill
, ire
);
5880 ip_rts_rtmsg(RTM_OLDADD
, ire
, 0, ipst
);
5881 if (ire_arg
!= NULL
) {
5883 * Store the ire that was successfully added into where ire_arg
5884 * points to so that callers don't have to look it up
5885 * themselves (but they are responsible for ire_refrele()ing
5886 * the ire when they are finished with it).
5890 ire_refrele(ire
); /* Held in ire_add */
5898 * ip_rt_delete is called to delete an IPv4 route.
5899 * ill is passed in to associate it with the correct interface.
5903 ip_rt_delete(ipaddr_t dst_addr
, ipaddr_t mask
, ipaddr_t gw_addr
,
5904 uint_t rtm_addrs
, int flags
, ill_t
*ill
, boolean_t ioctl_msg
,
5905 ip_stack_t
*ipst
, zoneid_t zoneid
)
5910 uint_t match_flags
= MATCH_IRE_TYPE
;
5913 ip1dbg(("ip_rt_delete:"));
5915 * If this is the case of RTF_HOST being set, then we set the netmask
5916 * to all ones. Otherwise, we use the netmask if one was supplied.
5918 if (flags
& RTF_HOST
) {
5919 mask
= IP_HOST_MASK
;
5920 match_flags
|= MATCH_IRE_MASK
;
5921 } else if (rtm_addrs
& RTA_NETMASK
) {
5922 match_flags
|= MATCH_IRE_MASK
;
5926 * Note that RTF_GATEWAY is never set on a delete, therefore
5927 * we check if the gateway address is one of our interfaces first,
5928 * and fall back on RTF_GATEWAY routes.
5930 * This makes it possible to delete an original
5931 * IRE_IF_NORESOLVER/IRE_IF_RESOLVER - consistent with SunOS 4.1.
5932 * However, we have RTF_KERNEL set on the ones created by ipif_up
5933 * and those can not be deleted here.
5935 * We use MATCH_IRE_ILL if we know the interface. If the caller
5936 * specified an interface (from the RTA_IFP sockaddr) we use it,
5937 * otherwise we use the ill derived from the gateway address.
5938 * We can always match the gateway address since we record it
5939 * in ire_gateway_addr.
5941 * For more detail on specifying routes by gateway address and by
5942 * interface index, see the comments in ip_rt_add().
5944 ipif
= ipif_lookup_interface(gw_addr
, dst_addr
, ipst
);
5951 ill_match
= ipif
->ipif_ill
;
5953 match_flags
|= MATCH_IRE_ILL
;
5954 if (ipif
->ipif_ire_type
== IRE_LOOPBACK
) {
5955 ire
= ire_ftable_lookup_v4(dst_addr
, mask
, 0,
5956 IRE_LOOPBACK
, ill_match
, ALL_ZONES
, match_flags
, 0,
5960 match_flags
|= MATCH_IRE_GW
;
5961 ire
= ire_ftable_lookup_v4(dst_addr
, mask
, gw_addr
,
5962 IRE_INTERFACE
, ill_match
, ALL_ZONES
, match_flags
,
5965 /* Avoid deleting routes created by kernel from an ipif */
5966 if (ire
!= NULL
&& (ire
->ire_flags
& RTF_KERNEL
)) {
5971 /* Restore in case we didn't find a match */
5972 match_flags
&= ~(MATCH_IRE_GW
|MATCH_IRE_ILL
);
5977 * At this point, the gateway address is not one of our own
5978 * addresses or a matching interface route was not found. We
5979 * set the IRE type to lookup based on whether
5980 * this is a host route, a default route or just a prefix.
5982 * If an ill was passed in, then the lookup is based on an
5983 * interface index so MATCH_IRE_ILL is added to match_flags.
5985 match_flags
|= MATCH_IRE_GW
;
5987 match_flags
|= MATCH_IRE_ILL
;
5988 if (mask
== IP_HOST_MASK
)
5994 ire
= ire_ftable_lookup_v4(dst_addr
, mask
, gw_addr
, type
, ill
,
5995 ALL_ZONES
, match_flags
, 0, ipst
, NULL
);
6006 if (ire
->ire_flags
& RTF_MULTIRT
) {
6008 * Invoke the CGTP (multirouting) filtering module
6009 * to remove the dst address from the filtering database.
6010 * Packets coming from that address will no longer be
6011 * filtered to remove duplicates.
6013 if (ipst
->ips_ip_cgtp_filter_ops
!= NULL
) {
6014 err
= ipst
->ips_ip_cgtp_filter_ops
->cfo_del_dest_v4(
6015 ipst
->ips_netstack
->netstack_stackid
,
6016 ire
->ire_addr
, ire
->ire_gateway_addr
);
6018 ip_cgtp_bcast_delete(ire
, ipst
);
6023 ill_remove_saved_ire(ill
, ire
);
6025 ip_rts_rtmsg(RTM_OLDDEL
, ire
, 0, ipst
);
6032 * ip_siocaddrt is called to complete processing of an SIOCADDRT IOCTL.
6036 ip_siocaddrt(ipif_t
*dummy_ipif
, sin_t
*dummy_sin
, queue_t
*q
, mblk_t
*mp
,
6037 ip_ioctl_cmd_t
*ipip
, void *dummy_if_req
)
6045 ipif_t
*ipif
= NULL
;
6048 ASSERT(q
->q_next
== NULL
);
6049 ipst
= CONNQ_TO_IPST(q
);
6051 ip1dbg(("ip_siocaddrt:"));
6052 /* Existence of mp1 verified in ip_wput_nondata */
6053 mp1
= mp
->b_cont
->b_cont
;
6054 rt
= (struct rtentry
*)mp1
->b_rptr
;
6056 dst_addr
= ((sin_t
*)&rt
->rt_dst
)->sin_addr
.s_addr
;
6057 gw_addr
= ((sin_t
*)&rt
->rt_gateway
)->sin_addr
.s_addr
;
6060 * If the RTF_HOST flag is on, this is a request to assign a gateway
6061 * to a particular host address. In this case, we set the netmask to
6062 * all ones for the particular destination address. Otherwise,
6063 * determine the netmask to be used based on dst_addr and the interfaces
6066 if (rt
->rt_flags
& RTF_HOST
) {
6067 mask
= IP_HOST_MASK
;
6070 * Note that ip_subnet_mask returns a zero mask in the case of
6071 * default (an all-zeroes address).
6073 mask
= ip_subnet_mask(dst_addr
, &ipif
, ipst
);
6076 error
= ip_rt_add(dst_addr
, mask
, gw_addr
, 0, rt
->rt_flags
, NULL
, NULL
,
6077 B_TRUE
, ipst
, ALL_ZONES
);
6084 * ip_siocdelrt is called to complete processing of an SIOCDELRT IOCTL.
6088 ip_siocdelrt(ipif_t
*dummy_ipif
, sin_t
*dummy_sin
, queue_t
*q
, mblk_t
*mp
,
6089 ip_ioctl_cmd_t
*ipip
, void *dummy_if_req
)
6097 ipif_t
*ipif
= NULL
;
6100 ASSERT(q
->q_next
== NULL
);
6101 ipst
= CONNQ_TO_IPST(q
);
6103 ip1dbg(("ip_siocdelrt:"));
6104 /* Existence of mp1 verified in ip_wput_nondata */
6105 mp1
= mp
->b_cont
->b_cont
;
6106 rt
= (struct rtentry
*)mp1
->b_rptr
;
6108 dst_addr
= ((sin_t
*)&rt
->rt_dst
)->sin_addr
.s_addr
;
6109 gw_addr
= ((sin_t
*)&rt
->rt_gateway
)->sin_addr
.s_addr
;
6112 * If the RTF_HOST flag is on, this is a request to delete a gateway
6113 * to a particular host address. In this case, we set the netmask to
6114 * all ones for the particular destination address. Otherwise,
6115 * determine the netmask to be used based on dst_addr and the interfaces
6118 if (rt
->rt_flags
& RTF_HOST
) {
6119 mask
= IP_HOST_MASK
;
6122 * Note that ip_subnet_mask returns a zero mask in the case of
6123 * default (an all-zeroes address).
6125 mask
= ip_subnet_mask(dst_addr
, &ipif
, ipst
);
6128 error
= ip_rt_delete(dst_addr
, mask
, gw_addr
,
6129 RTA_DST
| RTA_GATEWAY
| RTA_NETMASK
, rt
->rt_flags
, NULL
, B_TRUE
,
6137 * Enqueue the mp onto the ipsq, chained by b_next.
6138 * b_prev stores the function to be executed later, and b_queue the queue
6139 * where this mp originated.
6142 ipsq_enq(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
, ipsq_func_t func
, int type
,
6146 ipxop_t
*ipx
= ipsq
->ipsq_xop
;
6148 ASSERT(MUTEX_HELD(&ipsq
->ipsq_lock
));
6149 ASSERT(MUTEX_HELD(&ipx
->ipx_lock
));
6150 ASSERT(func
!= NULL
);
6153 mp
->b_prev
= (void *)func
;
6158 if (ipx
->ipx_mptail
!= NULL
) {
6159 ASSERT(ipx
->ipx_mphead
!= NULL
);
6160 ipx
->ipx_mptail
->b_next
= mp
;
6162 ASSERT(ipx
->ipx_mphead
== NULL
);
6163 ipx
->ipx_mphead
= mp
;
6165 ipx
->ipx_mptail
= mp
;
6169 if (ipsq
->ipsq_xopq_mptail
!= NULL
) {
6170 ASSERT(ipsq
->ipsq_xopq_mphead
!= NULL
);
6171 ipsq
->ipsq_xopq_mptail
->b_next
= mp
;
6173 ASSERT(ipsq
->ipsq_xopq_mphead
== NULL
);
6174 ipsq
->ipsq_xopq_mphead
= mp
;
6176 ipsq
->ipsq_xopq_mptail
= mp
;
6177 ipx
->ipx_ipsq_queued
= B_TRUE
;
6181 ASSERT(ipsq
->ipsq_swxop
!= NULL
);
6182 /* only one switch operation is currently allowed */
6183 ASSERT(ipsq
->ipsq_switch_mp
== NULL
);
6184 ipsq
->ipsq_switch_mp
= mp
;
6185 ipx
->ipx_ipsq_queued
= B_TRUE
;
6188 cmn_err(CE_PANIC
, "ipsq_enq %d type \n", type
);
6191 if (CONN_Q(q
) && pending_ill
!= NULL
) {
6192 connp
= Q_TO_CONN(q
);
6193 ASSERT(MUTEX_HELD(&connp
->conn_lock
));
6194 connp
->conn_oper_pending_ill
= pending_ill
;
6199 * Dequeue the next message that requested exclusive access to this IPSQ's
6200 * xop. Specifically:
6202 * 1. If we're still processing the current operation on `ipsq', then
6203 * dequeue the next message for the operation (from ipx_mphead), or
6204 * return NULL if there are no queued messages for the operation.
6205 * These messages are queued via CUR_OP to qwriter_ip() and friends.
6207 * 2. If the current operation on `ipsq' has completed (ipx_current_ipif is
6208 * not set) see if the ipsq has requested an xop switch. If so, switch
6209 * `ipsq' to a different xop. Xop switches only happen when joining or
6210 * leaving IPMP groups and require a careful dance -- see the comments
6211 * in-line below for details. If we're leaving a group xop or if we're
6212 * joining a group xop and become writer on it, then we proceed to (3).
6213 * Otherwise, we return NULL and exit the xop.
6215 * 3. For each IPSQ in the xop, return any switch operation stored on
6216 * ipsq_switch_mp (set via SWITCH_OP); these must be processed before
6217 * any other messages queued on the IPSQ. Otherwise, dequeue the next
6218 * exclusive operation (queued via NEW_OP) stored on ipsq_xopq_mphead.
6219 * Note that if the phyint tied to `ipsq' is not using IPMP there will
6220 * only be one IPSQ in the xop. Otherwise, there will be one IPSQ for
6221 * each phyint in the group, including the IPMP meta-interface phyint.
6224 ipsq_dq(ipsq_t
*ipsq
)
6226 ill_t
*illv4
, *illv6
;
6229 ipsq_t
*leftipsq
= NULL
;
6231 phyint_t
*phyi
= ipsq
->ipsq_phyint
;
6232 ip_stack_t
*ipst
= ipsq
->ipsq_ipst
;
6233 boolean_t emptied
= B_FALSE
;
6236 * Grab all the locks we need in the defined order (ill_g_lock ->
6237 * ipsq_lock -> ipx_lock); ill_g_lock is needed to use ipsq_next.
6239 rw_enter(&ipst
->ips_ill_g_lock
,
6240 ipsq
->ipsq_swxop
!= NULL
? RW_WRITER
: RW_READER
);
6241 mutex_enter(&ipsq
->ipsq_lock
);
6242 ipx
= ipsq
->ipsq_xop
;
6243 mutex_enter(&ipx
->ipx_lock
);
6246 * Dequeue the next message associated with the current exclusive
6247 * operation, if any.
6249 if ((mp
= ipx
->ipx_mphead
) != NULL
) {
6250 ipx
->ipx_mphead
= mp
->b_next
;
6251 if (ipx
->ipx_mphead
== NULL
)
6252 ipx
->ipx_mptail
= NULL
;
6253 mp
->b_next
= (void *)ipsq
;
6257 if (ipx
->ipx_current_ipif
!= NULL
)
6260 if (ipsq
->ipsq_swxop
!= NULL
) {
6262 * The exclusive operation that is now being completed has
6263 * requested a switch to a different xop. This happens
6264 * when an interface joins or leaves an IPMP group. Joins
6265 * happen through SIOCSLIFGROUPNAME (ip_sioctl_groupname()).
6266 * Leaves happen via SIOCSLIFGROUPNAME, interface unplumb
6267 * (phyint_free()), or interface plumb for an ill type
6268 * not in the IPMP group (ip_rput_dlpi_writer()).
6270 * Xop switches are not allowed on the IPMP meta-interface.
6272 ASSERT(phyi
== NULL
|| !(phyi
->phyint_flags
& PHYI_IPMP
));
6273 ASSERT(RW_WRITE_HELD(&ipst
->ips_ill_g_lock
));
6274 DTRACE_PROBE1(ipsq__switch
, (ipsq_t
*), ipsq
);
6276 if (ipsq
->ipsq_swxop
== &ipsq
->ipsq_ownxop
) {
6278 * We're switching back to our own xop, so we have two
6279 * xop's to drain/exit: our own, and the group xop
6280 * that we are leaving.
6282 * First, pull ourselves out of the group ipsq list.
6283 * This is safe since we're writer on ill_g_lock.
6285 ASSERT(ipsq
->ipsq_xop
!= &ipsq
->ipsq_ownxop
);
6287 xopipsq
= ipx
->ipx_ipsq
;
6288 while (xopipsq
->ipsq_next
!= ipsq
)
6289 xopipsq
= xopipsq
->ipsq_next
;
6291 xopipsq
->ipsq_next
= ipsq
->ipsq_next
;
6292 ipsq
->ipsq_next
= ipsq
;
6293 ipsq
->ipsq_xop
= ipsq
->ipsq_swxop
;
6294 ipsq
->ipsq_swxop
= NULL
;
6297 * Second, prepare to exit the group xop. The actual
6298 * ipsq_exit() is done at the end of this function
6299 * since we cannot hold any locks across ipsq_exit().
6300 * Note that although we drop the group's ipx_lock, no
6301 * threads can proceed since we're still ipx_writer.
6304 mutex_exit(&ipx
->ipx_lock
);
6307 * Third, set ipx to point to our own xop (which was
6308 * inactive and therefore can be entered).
6310 ipx
= ipsq
->ipsq_xop
;
6311 mutex_enter(&ipx
->ipx_lock
);
6312 ASSERT(ipx
->ipx_writer
== NULL
);
6313 ASSERT(ipx
->ipx_current_ipif
== NULL
);
6316 * We're switching from our own xop to a group xop.
6317 * The requestor of the switch must ensure that the
6318 * group xop cannot go away (e.g. by ensuring the
6319 * phyint associated with the xop cannot go away).
6321 * If we can become writer on our new xop, then we'll
6322 * do the drain. Otherwise, the current writer of our
6323 * new xop will do the drain when it exits.
6325 * First, splice ourselves into the group IPSQ list.
6326 * This is safe since we're writer on ill_g_lock.
6328 ASSERT(ipsq
->ipsq_xop
== &ipsq
->ipsq_ownxop
);
6330 xopipsq
= ipsq
->ipsq_swxop
->ipx_ipsq
;
6331 while (xopipsq
->ipsq_next
!= ipsq
->ipsq_swxop
->ipx_ipsq
)
6332 xopipsq
= xopipsq
->ipsq_next
;
6334 xopipsq
->ipsq_next
= ipsq
;
6335 ipsq
->ipsq_next
= ipsq
->ipsq_swxop
->ipx_ipsq
;
6336 ipsq
->ipsq_xop
= ipsq
->ipsq_swxop
;
6337 ipsq
->ipsq_swxop
= NULL
;
6340 * Second, exit our own xop, since it's now unused.
6341 * This is safe since we've got the only reference.
6343 ASSERT(ipx
->ipx_writer
== curthread
);
6344 ipx
->ipx_writer
= NULL
;
6345 VERIFY(--ipx
->ipx_reentry_cnt
== 0);
6346 ipx
->ipx_ipsq_queued
= B_FALSE
;
6347 mutex_exit(&ipx
->ipx_lock
);
6350 * Third, set ipx to point to our new xop, and check
6351 * if we can become writer on it. If we cannot, then
6352 * the current writer will drain the IPSQ group when
6353 * it exits. Our ipsq_xop is guaranteed to be stable
6354 * because we're still holding ipsq_lock.
6356 ipx
= ipsq
->ipsq_xop
;
6357 mutex_enter(&ipx
->ipx_lock
);
6358 if (ipx
->ipx_writer
!= NULL
||
6359 ipx
->ipx_current_ipif
!= NULL
) {
6365 * Fourth, become writer on our new ipx before we continue
6366 * with the drain. Note that we never dropped ipsq_lock
6367 * above, so no other thread could've raced with us to
6368 * become writer first. Also, we're holding ipx_lock, so
6369 * no other thread can examine the ipx right now.
6371 ASSERT(ipx
->ipx_current_ipif
== NULL
);
6372 ASSERT(ipx
->ipx_mphead
== NULL
&& ipx
->ipx_mptail
== NULL
);
6373 VERIFY(ipx
->ipx_reentry_cnt
++ == 0);
6374 ipx
->ipx_writer
= curthread
;
6375 ipx
->ipx_forced
= B_FALSE
;
6377 ipx
->ipx_depth
= getpcstack(ipx
->ipx_stack
, IPX_STACK_DEPTH
);
6384 * So that other operations operate on a consistent and
6385 * complete phyint, a switch message on an IPSQ must be
6386 * handled prior to any other operations on that IPSQ.
6388 if ((mp
= xopipsq
->ipsq_switch_mp
) != NULL
) {
6389 xopipsq
->ipsq_switch_mp
= NULL
;
6390 ASSERT(mp
->b_next
== NULL
);
6391 mp
->b_next
= (void *)xopipsq
;
6395 if ((mp
= xopipsq
->ipsq_xopq_mphead
) != NULL
) {
6396 xopipsq
->ipsq_xopq_mphead
= mp
->b_next
;
6397 if (xopipsq
->ipsq_xopq_mphead
== NULL
)
6398 xopipsq
->ipsq_xopq_mptail
= NULL
;
6399 mp
->b_next
= (void *)xopipsq
;
6402 } while ((xopipsq
= xopipsq
->ipsq_next
) != ipsq
);
6405 * There are no messages. Further, we are holding ipx_lock, hence no
6406 * new messages can end up on any IPSQ in the xop.
6408 ipx
->ipx_writer
= NULL
;
6409 ipx
->ipx_forced
= B_FALSE
;
6410 VERIFY(--ipx
->ipx_reentry_cnt
== 0);
6411 ipx
->ipx_ipsq_queued
= B_FALSE
;
6417 mutex_exit(&ipx
->ipx_lock
);
6418 mutex_exit(&ipsq
->ipsq_lock
);
6421 * If we completely emptied the xop, then wake up any threads waiting
6422 * to enter any of the IPSQ's associated with it.
6427 if ((phyi
= xopipsq
->ipsq_phyint
) == NULL
)
6430 illv4
= phyi
->phyint_illv4
;
6431 illv6
= phyi
->phyint_illv6
;
6433 GRAB_ILL_LOCKS(illv4
, illv6
);
6435 cv_broadcast(&illv4
->ill_cv
);
6437 cv_broadcast(&illv6
->ill_cv
);
6438 RELEASE_ILL_LOCKS(illv4
, illv6
);
6439 } while ((xopipsq
= xopipsq
->ipsq_next
) != ipsq
);
6441 rw_exit(&ipst
->ips_ill_g_lock
);
6444 * Now that all locks are dropped, exit the IPSQ we left.
6446 if (leftipsq
!= NULL
)
6447 ipsq_exit(leftipsq
);
6453 * Return completion status of previously initiated DLPI operations on
6454 * ills in the purview of an ipsq.
6457 ipsq_dlpi_done(ipsq_t
*ipsq
)
6463 ASSERT(RW_LOCK_HELD(&ipsq
->ipsq_ipst
->ips_ill_g_lock
));
6468 * The only current users of this function are ipsq_try_enter
6469 * and ipsq_enter which have made sure that ipsq_writer is
6470 * NULL before we reach here. ill_dlpi_pending is modified
6471 * only by an ipsq writer
6473 ASSERT(ipsq
->ipsq_xop
->ipx_writer
== NULL
);
6474 phyi
= ipsq
->ipsq_phyint
;
6476 * phyi could be NULL if a phyint that is part of an
6477 * IPMP group is being unplumbed. A more detailed
6478 * comment is in ipmp_grp_update_kstats()
6481 ill
= phyi
->phyint_illv4
;
6483 (ill
->ill_dlpi_pending
!= DL_PRIM_INVAL
||
6484 ill
->ill_arl_dlpi_pending
))
6487 ill
= phyi
->phyint_illv6
;
6489 ill
->ill_dlpi_pending
!= DL_PRIM_INVAL
)
6493 } while ((ipsq
= ipsq
->ipsq_next
) != ipsq_start
);
6499 * Enter the ipsq corresponding to ill, by waiting synchronously till
6500 * we can enter the ipsq exclusively. Unless 'force' is used, the ipsq
6501 * will have to drain completely before ipsq_enter returns success.
6502 * ipx_current_ipif will be set if some exclusive op is in progress,
6503 * and the ipsq_exit logic will start the next enqueued op after
6504 * completion of the current op. If 'force' is used, we don't wait
6505 * for the enqueued ops. This is needed when a conn_close wants to
6506 * enter the ipsq and abort an ioctl that is somehow stuck. Unplumb
6507 * of an ill can also use this option. But we dont' use it currently.
6509 #define ENTER_SQ_WAIT_TICKS 100
6511 ipsq_enter(ill_t
*ill
, boolean_t force
, int type
)
6515 boolean_t waited_enough
= B_FALSE
;
6516 ip_stack_t
*ipst
= ill
->ill_ipst
;
6519 * Note that the relationship between ill and ipsq is fixed as long as
6520 * the ill is not ILL_CONDEMNED. Holding ipsq_lock ensures the
6521 * relationship between the IPSQ and xop cannot change. However,
6522 * since we cannot hold ipsq_lock across the cv_wait(), it may change
6523 * while we're waiting. We wait on ill_cv and rely on ipsq_exit()
6524 * waking up all ills in the xop when it becomes available.
6527 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
6528 mutex_enter(&ill
->ill_lock
);
6529 if (ill
->ill_state_flags
& ILL_CONDEMNED
) {
6530 mutex_exit(&ill
->ill_lock
);
6531 rw_exit(&ipst
->ips_ill_g_lock
);
6535 ipsq
= ill
->ill_phyint
->phyint_ipsq
;
6536 mutex_enter(&ipsq
->ipsq_lock
);
6537 ipx
= ipsq
->ipsq_xop
;
6538 mutex_enter(&ipx
->ipx_lock
);
6540 if (ipx
->ipx_writer
== NULL
&& (type
== CUR_OP
||
6541 (ipx
->ipx_current_ipif
== NULL
&& ipsq_dlpi_done(ipsq
)) ||
6545 rw_exit(&ipst
->ips_ill_g_lock
);
6547 if (!force
|| ipx
->ipx_writer
!= NULL
) {
6548 mutex_exit(&ipx
->ipx_lock
);
6549 mutex_exit(&ipsq
->ipsq_lock
);
6550 cv_wait(&ill
->ill_cv
, &ill
->ill_lock
);
6552 mutex_exit(&ipx
->ipx_lock
);
6553 mutex_exit(&ipsq
->ipsq_lock
);
6554 (void) cv_reltimedwait(&ill
->ill_cv
,
6555 &ill
->ill_lock
, ENTER_SQ_WAIT_TICKS
, TR_CLOCK_TICK
);
6556 waited_enough
= B_TRUE
;
6558 mutex_exit(&ill
->ill_lock
);
6561 ASSERT(ipx
->ipx_mphead
== NULL
&& ipx
->ipx_mptail
== NULL
);
6562 ASSERT(ipx
->ipx_reentry_cnt
== 0);
6563 ipx
->ipx_writer
= curthread
;
6564 ipx
->ipx_forced
= (ipx
->ipx_current_ipif
!= NULL
);
6565 ipx
->ipx_reentry_cnt
++;
6567 ipx
->ipx_depth
= getpcstack(ipx
->ipx_stack
, IPX_STACK_DEPTH
);
6569 mutex_exit(&ipx
->ipx_lock
);
6570 mutex_exit(&ipsq
->ipsq_lock
);
6571 mutex_exit(&ill
->ill_lock
);
6572 rw_exit(&ipst
->ips_ill_g_lock
);
6578 * ipif_set_values() has a constraint that it cannot drop the ips_ill_g_lock
6579 * across the call to the core interface ipsq_try_enter() and hence calls this
6580 * function directly. This is explained more fully in ipif_set_values().
6581 * In order to support the above constraint, ipsq_try_enter is implemented as
6582 * a wrapper that grabs the ips_ill_g_lock and calls this function subsequently
6585 ipsq_try_enter_internal(ill_t
*ill
, queue_t
*q
, mblk_t
*mp
, ipsq_func_t func
,
6586 int type
, boolean_t reentry_ok
)
6590 ip_stack_t
*ipst
= ill
->ill_ipst
;
6594 * ill_g_lock -> conn_lock -> ill_lock -> ipsq_lock -> ipx_lock.
6596 * ipx of an ipsq can't change when ipsq_lock is held.
6598 ASSERT(RW_LOCK_HELD(&ipst
->ips_ill_g_lock
));
6600 mutex_enter(&ill
->ill_lock
);
6601 ipsq
= ill
->ill_phyint
->phyint_ipsq
;
6602 mutex_enter(&ipsq
->ipsq_lock
);
6603 ipx
= ipsq
->ipsq_xop
;
6604 mutex_enter(&ipx
->ipx_lock
);
6607 * 1. Enter the ipsq if we are already writer and reentry is ok.
6608 * (Note: If the caller does not specify reentry_ok then neither
6609 * 'func' nor any of its callees must ever attempt to enter the ipsq
6610 * again. Otherwise it can lead to an infinite loop
6611 * 2. Enter the ipsq if there is no current writer and this attempted
6612 * entry is part of the current operation
6613 * 3. Enter the ipsq if there is no current writer and this is a new
6614 * operation and the operation queue is empty and there is no
6615 * operation currently in progress and if all previously initiated
6616 * DLPI operations have completed.
6618 if ((ipx
->ipx_writer
== curthread
&& reentry_ok
) ||
6619 (ipx
->ipx_writer
== NULL
&& (type
== CUR_OP
|| (type
== NEW_OP
&&
6620 !ipx
->ipx_ipsq_queued
&& ipx
->ipx_current_ipif
== NULL
&&
6621 ipsq_dlpi_done(ipsq
))))) {
6623 ipx
->ipx_reentry_cnt
++;
6624 ipx
->ipx_writer
= curthread
;
6625 ipx
->ipx_forced
= B_FALSE
;
6626 mutex_exit(&ipx
->ipx_lock
);
6627 mutex_exit(&ipsq
->ipsq_lock
);
6628 mutex_exit(&ill
->ill_lock
);
6629 RELEASE_CONN_LOCK(q
);
6631 ipx
->ipx_depth
= getpcstack(ipx
->ipx_stack
, IPX_STACK_DEPTH
);
6637 ipsq_enq(ipsq
, q
, mp
, func
, type
, ill
);
6639 mutex_exit(&ipx
->ipx_lock
);
6640 mutex_exit(&ipsq
->ipsq_lock
);
6641 mutex_exit(&ill
->ill_lock
);
6642 RELEASE_CONN_LOCK(q
);
6647 * The ipsq_t (ipsq) is the synchronization data structure used to serialize
6648 * certain critical operations like plumbing (i.e. most set ioctls), etc.
6649 * There is one ipsq per phyint. The ipsq
6650 * serializes exclusive ioctls issued by applications on a per ipsq basis in
6651 * ipsq_xopq_mphead. It also protects against multiple threads executing in
6652 * the ipsq. Responses from the driver pertain to the current ioctl (say a
6653 * DL_BIND_ACK in response to a DL_BIND_REQ initiated as part of bringing
6654 * up the interface) and are enqueued in ipx_mphead.
6656 * If a thread does not want to reenter the ipsq when it is already writer,
6657 * it must make sure that the specified reentry point to be called later
6658 * when the ipsq is empty, nor any code path starting from the specified reentry
6659 * point must never ever try to enter the ipsq again. Otherwise it can lead
6660 * to an infinite loop. The reentry point ip_rput_dlpi_writer is an example.
6661 * When the thread that is currently exclusive finishes, it (ipsq_exit)
6662 * dequeues the requests waiting to become exclusive in ipx_mphead and calls
6663 * the reentry point. When the list at ipx_mphead becomes empty ipsq_exit
6664 * proceeds to dequeue the next ioctl in ipsq_xopq_mphead and start the next
6665 * ioctl if the current ioctl has completed. If the current ioctl is still
6666 * in progress it simply returns. The current ioctl could be waiting for
6667 * a response from another module (the driver or could be waiting for
6668 * the ipif/ill/ire refcnts to drop to zero. In such a case the ipx_pending_mp
6669 * and ipx_pending_ipif are set. ipx_current_ipif is set throughout the
6670 * execution of the ioctl and ipsq_exit does not start the next ioctl unless
6671 * ipx_current_ipif is NULL which happens only once the ioctl is complete and
6672 * all associated DLPI operations have completed.
6676 * Try to enter the IPSQ corresponding to `ipif' or `ill' exclusively (`ipif'
6677 * and `ill' cannot both be specified). Returns a pointer to the entered IPSQ
6678 * on success, or NULL on failure. The caller ensures ipif/ill is valid by
6679 * refholding it as necessary. If the IPSQ cannot be entered and `func' is
6680 * non-NULL, then `func' will be called back with `q' and `mp' once the IPSQ
6681 * can be entered. If `func' is NULL, then `q' and `mp' are ignored.
6684 ipsq_try_enter(ipif_t
*ipif
, ill_t
*ill
, queue_t
*q
, mblk_t
*mp
,
6685 ipsq_func_t func
, int type
, boolean_t reentry_ok
)
6690 /* Only 1 of ipif or ill can be specified */
6691 ASSERT((ipif
!= NULL
) ^ (ill
!= NULL
));
6694 ill
= ipif
->ipif_ill
;
6695 ipst
= ill
->ill_ipst
;
6697 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
6698 ipsq
= ipsq_try_enter_internal(ill
, q
, mp
, func
, type
, reentry_ok
);
6699 rw_exit(&ipst
->ips_ill_g_lock
);
6705 * Try to enter the IPSQ corresponding to `ill' as writer. The caller ensures
6706 * ill is valid by refholding it if necessary; we will refrele. If the IPSQ
6707 * cannot be entered, the mp is queued for completion.
6710 qwriter_ip(ill_t
*ill
, queue_t
*q
, mblk_t
*mp
, ipsq_func_t func
, int type
,
6711 boolean_t reentry_ok
)
6715 ipsq
= ipsq_try_enter(NULL
, ill
, q
, mp
, func
, type
, reentry_ok
);
6718 * Drop the caller's refhold on the ill. This is safe since we either
6719 * entered the IPSQ (and thus are exclusive), or failed to enter the
6720 * IPSQ, in which case we return without accessing ill anymore. This
6721 * is needed because func needs to see the correct refcount.
6722 * e.g. removeif can work only then.
6726 (*func
)(ipsq
, q
, mp
, NULL
);
6732 * Exit the specified IPSQ. If this is the final exit on it then drain it
6733 * prior to exiting. Caller must be writer on the specified IPSQ.
6736 ipsq_exit(ipsq_t
*ipsq
)
6744 ASSERT(IAM_WRITER_IPSQ(ipsq
));
6746 ASSERT(ipsq
->ipsq_xop
->ipx_reentry_cnt
>= 1);
6747 if (ipsq
->ipsq_xop
->ipx_reentry_cnt
!= 1) {
6748 ipsq
->ipsq_xop
->ipx_reentry_cnt
--;
6753 phyi
= ipsq
->ipsq_phyint
;
6755 mp_ipsq
= (mp
== NULL
) ? NULL
: (ipsq_t
*)mp
->b_next
;
6758 * If we've changed to a new IPSQ, and the phyint associated
6759 * with the old one has gone away, free the old IPSQ. Note
6760 * that this cannot happen while the IPSQ is in a group.
6762 if (mp_ipsq
!= ipsq
&& phyi
== NULL
) {
6763 ASSERT(ipsq
->ipsq_next
== ipsq
);
6764 ASSERT(ipsq
->ipsq_xop
== &ipsq
->ipsq_ownxop
);
6772 func
= (ipsq_func_t
)mp
->b_prev
;
6774 mp
->b_next
= mp
->b_prev
= NULL
;
6778 * If 'q' is an conn queue, it is valid, since we did a
6779 * a refhold on the conn at the start of the ioctl.
6780 * If 'q' is an ill queue, it is valid, since close of an
6781 * ill will clean up its IPSQ.
6783 (*func
)(ipsq
, q
, mp
, NULL
);
6788 * Used to start any igmp or mld timers that could not be started
6789 * while holding ill_mcast_lock. The timers can't be started while holding
6790 * the lock, since mld/igmp_start_timers may need to call untimeout()
6791 * which can't be done while holding the lock which the timeout handler
6792 * acquires. Otherwise
6793 * there could be a deadlock since the timeout handlers
6794 * mld_timeout_handler_per_ill/igmp_timeout_handler_per_ill also acquire
6798 ill_mcast_timer_start(ip_stack_t
*ipst
)
6802 mutex_enter(&ipst
->ips_igmp_timer_lock
);
6803 next
= ipst
->ips_igmp_deferred_next
;
6804 ipst
->ips_igmp_deferred_next
= INFINITY
;
6805 mutex_exit(&ipst
->ips_igmp_timer_lock
);
6807 if (next
!= INFINITY
)
6808 igmp_start_timers(next
, ipst
);
6810 mutex_enter(&ipst
->ips_mld_timer_lock
);
6811 next
= ipst
->ips_mld_deferred_next
;
6812 ipst
->ips_mld_deferred_next
= INFINITY
;
6813 mutex_exit(&ipst
->ips_mld_timer_lock
);
6815 if (next
!= INFINITY
)
6816 mld_start_timers(next
, ipst
);
6820 * Start the current exclusive operation on `ipsq'; associate it with `ipif'
6824 ipsq_current_start(ipsq_t
*ipsq
, ipif_t
*ipif
, int ioccmd
)
6826 ill_t
*ill
= ipif
->ipif_ill
;
6827 ipxop_t
*ipx
= ipsq
->ipsq_xop
;
6829 ASSERT(IAM_WRITER_IPSQ(ipsq
));
6830 ASSERT(ipx
->ipx_current_ipif
== NULL
);
6831 ASSERT(ipx
->ipx_current_ioctl
== 0);
6833 ipx
->ipx_current_done
= B_FALSE
;
6834 ipx
->ipx_current_ioctl
= ioccmd
;
6835 mutex_enter(&ipx
->ipx_lock
);
6836 ipx
->ipx_current_ipif
= ipif
;
6837 mutex_exit(&ipx
->ipx_lock
);
6840 * Set IPIF_CHANGING on one or more ipifs associated with the
6841 * current exclusive operation. IPIF_CHANGING prevents any new
6842 * references to the ipif (so that the references will eventually
6843 * drop to zero) and also prevents any "get" operations (e.g.,
6844 * SIOCGLIFFLAGS) from being able to access the ipif until the
6845 * operation has completed and the ipif is again in a stable state.
6847 * For ioctls, IPIF_CHANGING is set on the ipif associated with the
6848 * ioctl. For internal operations (where ioccmd is zero), all ipifs
6849 * on the ill are marked with IPIF_CHANGING since it's unclear which
6850 * ipifs will be affected.
6852 * Note that SIOCLIFREMOVEIF is a special case as it sets
6853 * IPIF_CONDEMNED internally after identifying the right ipif to
6857 case SIOCLIFREMOVEIF
:
6860 mutex_enter(&ill
->ill_lock
);
6861 ipif
= ipif
->ipif_ill
->ill_ipif
;
6862 for (; ipif
!= NULL
; ipif
= ipif
->ipif_next
)
6863 ipif
->ipif_state_flags
|= IPIF_CHANGING
;
6864 mutex_exit(&ill
->ill_lock
);
6867 mutex_enter(&ill
->ill_lock
);
6868 ipif
->ipif_state_flags
|= IPIF_CHANGING
;
6869 mutex_exit(&ill
->ill_lock
);
6874 * Finish the current exclusive operation on `ipsq'. Usually, this will allow
6875 * the next exclusive operation to begin once we ipsq_exit(). However, if
6876 * pending DLPI operations remain, then we will wait for the queue to drain
6877 * before allowing the next exclusive operation to begin. This ensures that
6878 * DLPI operations from one exclusive operation are never improperly processed
6879 * as part of a subsequent exclusive operation.
6882 ipsq_current_finish(ipsq_t
*ipsq
)
6884 ipxop_t
*ipx
= ipsq
->ipsq_xop
;
6885 t_uscalar_t dlpi_pending
= DL_PRIM_INVAL
;
6886 ipif_t
*ipif
= ipx
->ipx_current_ipif
;
6888 ASSERT(IAM_WRITER_IPSQ(ipsq
));
6891 * For SIOCLIFREMOVEIF, the ipif has been already been blown away
6892 * (but in that case, IPIF_CHANGING will already be clear and no
6893 * pending DLPI messages can remain).
6895 if (ipx
->ipx_current_ioctl
!= SIOCLIFREMOVEIF
) {
6896 ill_t
*ill
= ipif
->ipif_ill
;
6898 mutex_enter(&ill
->ill_lock
);
6899 dlpi_pending
= ill
->ill_dlpi_pending
;
6900 if (ipx
->ipx_current_ioctl
== 0) {
6901 ipif
= ill
->ill_ipif
;
6902 for (; ipif
!= NULL
; ipif
= ipif
->ipif_next
)
6903 ipif
->ipif_state_flags
&= ~IPIF_CHANGING
;
6905 ipif
->ipif_state_flags
&= ~IPIF_CHANGING
;
6907 mutex_exit(&ill
->ill_lock
);
6910 ASSERT(!ipx
->ipx_current_done
);
6911 ipx
->ipx_current_done
= B_TRUE
;
6912 ipx
->ipx_current_ioctl
= 0;
6913 if (dlpi_pending
== DL_PRIM_INVAL
) {
6914 mutex_enter(&ipx
->ipx_lock
);
6915 ipx
->ipx_current_ipif
= NULL
;
6916 mutex_exit(&ipx
->ipx_lock
);
6921 * The ill is closing. Flush all messages on the ipsq that originated
6922 * from this ill. Usually there wont' be any messages on the ipsq_xopq_mphead
6923 * for this ill since ipsq_enter could not have entered until then.
6924 * New messages can't be queued since the CONDEMNED flag is set.
6927 ipsq_flush(ill_t
*ill
)
6933 ipxop_t
*ipx
= ill
->ill_phyint
->phyint_ipsq
->ipsq_xop
;
6935 ASSERT(IAM_WRITER_ILL(ill
));
6938 * Flush any messages sent up by the driver.
6940 mutex_enter(&ipx
->ipx_lock
);
6941 for (prev
= NULL
, mp
= ipx
->ipx_mphead
; mp
!= NULL
; mp
= mp_next
) {
6942 mp_next
= mp
->b_next
;
6944 if (q
== ill
->ill_rq
|| q
== ill
->ill_wq
) {
6947 ipx
->ipx_mphead
= mp
->b_next
;
6949 prev
->b_next
= mp
->b_next
;
6950 if (ipx
->ipx_mptail
== mp
) {
6951 ASSERT(mp_next
== NULL
);
6952 ipx
->ipx_mptail
= prev
;
6959 mutex_exit(&ipx
->ipx_lock
);
6960 (void) ipsq_pending_mp_cleanup(ill
, NULL
);
6961 ipsq_xopq_mp_cleanup(ill
, NULL
);
6965 * Parse an ifreq or lifreq struct coming down ioctls and refhold
6966 * and return the associated ipif.
6968 * Non zero: An error has occurred. ci may not be filled out.
6969 * zero : ci is filled out with the ioctl cmd in ci.ci_name, and
6970 * a held ipif in ci.ci_ipif.
6973 ip_extract_lifreq(queue_t
*q
, mblk_t
*mp
, const ip_ioctl_cmd_t
*ipip
,
6978 struct lifreq
*lifr
;
6979 ipif_t
*ipif
= NULL
;
6988 if (q
->q_next
!= NULL
) {
6989 ill
= (ill_t
*)q
->q_ptr
;
6990 isv6
= ill
->ill_isv6
;
6993 ipst
= ill
->ill_ipst
;
6996 connp
= Q_TO_CONN(q
);
6997 isv6
= (connp
->conn_family
== AF_INET6
);
6998 zoneid
= connp
->conn_zoneid
;
6999 if (zoneid
== GLOBAL_ZONEID
) {
7000 /* global zone can access ipifs in all zones */
7003 ipst
= connp
->conn_netstack
->netstack_ip
;
7006 /* Has been checked in ip_wput_nondata */
7007 mp1
= mp
->b_cont
->b_cont
;
7009 if (ipip
->ipi_cmd_type
== IF_CMD
) {
7010 /* This a old style SIOC[GS]IF* command */
7011 ifr
= (struct ifreq
*)mp1
->b_rptr
;
7013 * Null terminate the string to protect against buffer
7014 * overrun. String was generated by user code and may not
7017 ifr
->ifr_name
[IFNAMSIZ
- 1] = '\0';
7018 name
= ifr
->ifr_name
;
7019 ci
->ci_sin
= (sin_t
*)&ifr
->ifr_addr
;
7021 ci
->ci_lifr
= (struct lifreq
*)ifr
;
7023 /* This a new style SIOC[GS]LIF* command */
7024 ASSERT(ipip
->ipi_cmd_type
== LIF_CMD
);
7025 lifr
= (struct lifreq
*)mp1
->b_rptr
;
7027 * Null terminate the string to protect against buffer
7028 * overrun. String was generated by user code and may not
7031 lifr
->lifr_name
[LIFNAMSIZ
- 1] = '\0';
7032 name
= lifr
->lifr_name
;
7033 ci
->ci_sin
= (sin_t
*)&lifr
->lifr_addr
;
7034 ci
->ci_sin6
= (sin6_t
*)&lifr
->lifr_addr
;
7038 if (ipip
->ipi_cmd
== SIOCSLIFNAME
) {
7040 * The ioctl will be failed if the ioctl comes down
7045 * Not an ill queue, return EINVAL same as the
7050 ipif
= ill
->ill_ipif
;
7054 * Ensure that ioctls don't see any internal state changes
7055 * caused by set ioctls by deferring them if IPIF_CHANGING is
7058 ipif
= ipif_lookup_on_name_async(name
, mi_strlen(name
),
7059 isv6
, zoneid
, q
, mp
, ip_process_ioctl
, &err
, ipst
);
7061 if (err
== EINPROGRESS
)
7063 err
= 0; /* Ensure we don't use it below */
7068 * Old style [GS]IFCMD does not admit IPv6 ipif
7070 if (ipif
!= NULL
&& ipif
->ipif_isv6
&& ipip
->ipi_cmd_type
== IF_CMD
) {
7075 if (ipif
== NULL
&& ill
!= NULL
&& ill
->ill_ipif
!= NULL
&&
7078 * Handle a or a SIOC?IF* with a null name
7079 * during plumb (on the ill queue before the I_PLINK).
7081 ipif
= ill
->ill_ipif
;
7088 DTRACE_PROBE4(ipif__ioctl
, char *, "ip_extract_lifreq",
7089 int, ipip
->ipi_cmd
, ill_t
*, ipif
->ipif_ill
, ipif_t
*, ipif
);
7096 * Return the total number of ipifs.
7099 ip_get_numifs(zoneid_t zoneid
, ip_stack_t
*ipst
)
7103 ill_walk_context_t ctx
;
7106 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
7107 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
7108 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
7109 if (IS_UNDER_IPMP(ill
))
7111 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
7112 ipif
= ipif
->ipif_next
) {
7113 if (ipif
->ipif_zoneid
== zoneid
||
7114 ipif
->ipif_zoneid
== ALL_ZONES
)
7118 rw_exit(&ipst
->ips_ill_g_lock
);
7123 * Return the total number of ipifs.
7126 ip_get_numlifs(int family
, int lifn_flags
, zoneid_t zoneid
, ip_stack_t
*ipst
)
7131 ill_walk_context_t ctx
;
7133 ip1dbg(("ip_get_numlifs(%d %u %d)\n", family
, lifn_flags
, (int)zoneid
));
7135 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
7136 if (family
== AF_INET
)
7137 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
7138 else if (family
== AF_INET6
)
7139 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
7141 ill
= ILL_START_WALK_ALL(&ctx
, ipst
);
7143 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
7144 if (IS_UNDER_IPMP(ill
) && !(lifn_flags
& LIFC_UNDER_IPMP
))
7147 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
7148 ipif
= ipif
->ipif_next
) {
7149 if ((ipif
->ipif_flags
& IPIF_NOXMIT
) &&
7150 !(lifn_flags
& LIFC_NOXMIT
))
7152 if ((ipif
->ipif_flags
& IPIF_TEMPORARY
) &&
7153 !(lifn_flags
& LIFC_TEMPORARY
))
7155 if (((ipif
->ipif_flags
&
7156 (IPIF_NOXMIT
|IPIF_NOLOCAL
|
7157 IPIF_DEPRECATED
)) ||
7159 !(ipif
->ipif_flags
& IPIF_UP
)) &&
7160 (lifn_flags
& LIFC_EXTERNAL_SOURCE
))
7163 if (zoneid
!= ipif
->ipif_zoneid
&&
7164 ipif
->ipif_zoneid
!= ALL_ZONES
&&
7165 (zoneid
!= GLOBAL_ZONEID
||
7166 !(lifn_flags
& LIFC_ALLZONES
)))
7172 rw_exit(&ipst
->ips_ill_g_lock
);
7177 ip_get_lifsrcofnum(ill_t
*ill
)
7180 ill_t
*ill_head
= ill
;
7181 ip_stack_t
*ipst
= ill
->ill_ipst
;
7184 * ill_g_usesrc_lock protects ill_usesrc_grp_next, for example, some
7185 * other thread may be trying to relink the ILLs in this usesrc group
7186 * and adjusting the ill_usesrc_grp_next pointers
7188 rw_enter(&ipst
->ips_ill_g_usesrc_lock
, RW_READER
);
7189 if ((ill
->ill_usesrc_ifindex
== 0) &&
7190 (ill
->ill_usesrc_grp_next
!= NULL
)) {
7191 for (; (ill
!= NULL
) && (ill
->ill_usesrc_grp_next
!= ill_head
);
7192 ill
= ill
->ill_usesrc_grp_next
)
7195 rw_exit(&ipst
->ips_ill_g_usesrc_lock
);
7200 /* Null values are passed in for ipif, sin, and ifreq */
7203 ip_sioctl_get_ifnum(ipif_t
*dummy_ipif
, sin_t
*dummy_sin
, queue_t
*q
,
7204 mblk_t
*mp
, ip_ioctl_cmd_t
*ipip
, void *ifreq
)
7207 conn_t
*connp
= Q_TO_CONN(q
);
7209 ASSERT(q
->q_next
== NULL
); /* not a valid ioctl for ip as a module */
7211 /* Existence of b_cont->b_cont checked in ip_wput_nondata */
7212 nump
= (int *)mp
->b_cont
->b_cont
->b_rptr
;
7214 *nump
= ip_get_numifs(connp
->conn_zoneid
,
7215 connp
->conn_netstack
->netstack_ip
);
7216 ip1dbg(("ip_sioctl_get_ifnum numifs %d", *nump
));
7220 /* Null values are passed in for ipif, sin, and ifreq */
7223 ip_sioctl_get_lifnum(ipif_t
*dummy_ipif
, sin_t
*dummy_sin
,
7224 queue_t
*q
, mblk_t
*mp
, ip_ioctl_cmd_t
*ipip
, void *ifreq
)
7226 struct lifnum
*lifn
;
7228 conn_t
*connp
= Q_TO_CONN(q
);
7230 ASSERT(q
->q_next
== NULL
); /* not a valid ioctl for ip as a module */
7232 /* Existence checked in ip_wput_nondata */
7233 mp1
= mp
->b_cont
->b_cont
;
7235 lifn
= (struct lifnum
*)mp1
->b_rptr
;
7236 switch (lifn
->lifn_family
) {
7242 return (EAFNOSUPPORT
);
7245 lifn
->lifn_count
= ip_get_numlifs(lifn
->lifn_family
, lifn
->lifn_flags
,
7246 connp
->conn_zoneid
, connp
->conn_netstack
->netstack_ip
);
7247 ip1dbg(("ip_sioctl_get_lifnum numifs %d", lifn
->lifn_count
));
7253 ip_sioctl_get_ifconf(ipif_t
*dummy_ipif
, sin_t
*dummy_sin
, queue_t
*q
,
7254 mblk_t
*mp
, ip_ioctl_cmd_t
*ipip
, void *ifreq
)
7256 STRUCT_HANDLE(ifconf
, ifc
);
7258 struct iocblk
*iocp
;
7260 ill_walk_context_t ctx
;
7263 struct sockaddr_in
*sin
;
7266 ip_stack_t
*ipst
= CONNQ_TO_IPST(q
);
7268 ASSERT(q
->q_next
== NULL
); /* not valid ioctls for ip as a module */
7270 ip1dbg(("ip_sioctl_get_ifconf"));
7271 /* Existence verified in ip_wput_nondata */
7272 mp1
= mp
->b_cont
->b_cont
;
7273 iocp
= (struct iocblk
*)mp
->b_rptr
;
7274 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
7277 * The original SIOCGIFCONF passed in a struct ifconf which specified
7278 * the user buffer address and length into which the list of struct
7279 * ifreqs was to be copied. Since AT&T Streams does not seem to
7280 * allow M_COPYOUT to be used in conjunction with I_STR IOCTLS,
7281 * the SIOCGIFCONF operation was redefined to simply provide
7282 * a large output buffer into which we are supposed to jam the ifreq
7283 * array. The same ioctl command code was used, despite the fact that
7284 * both the applications and the kernel code had to change, thus making
7285 * it impossible to support both interfaces.
7287 * For reasons not good enough to try to explain, the following
7288 * algorithm is used for deciding what to do with one of these:
7289 * If the IOCTL comes in as an I_STR, it is assumed to be of the new
7290 * form with the output buffer coming down as the continuation message.
7291 * If it arrives as a TRANSPARENT IOCTL, it is assumed to be old style,
7292 * and we have to copy in the ifconf structure to find out how big the
7293 * output buffer is and where to copy out to. Sure no problem...
7296 STRUCT_SET_HANDLE(ifc
, iocp
->ioc_flag
, NULL
);
7297 if ((mp1
->b_wptr
- mp1
->b_rptr
) == STRUCT_SIZE(ifc
)) {
7302 * Must be (better be!) continuation of a TRANSPARENT
7303 * IOCTL. We just copied in the ifconf structure.
7305 STRUCT_SET_HANDLE(ifc
, iocp
->ioc_flag
,
7306 (struct ifconf
*)mp1
->b_rptr
);
7309 * Allocate a buffer to hold requested information.
7311 * If ifc_len is larger than what is needed, we only
7312 * allocate what we will use.
7314 * If ifc_len is smaller than what is needed, return
7317 * XXX: the ill_t structure can hava 2 counters, for
7318 * v4 and v6 (not just ill_ipif_up_count) to store the
7319 * number of interfaces for a device, so we don't need
7320 * to count them here...
7322 numifs
= ip_get_numifs(zoneid
, ipst
);
7324 ifclen
= STRUCT_FGET(ifc
, ifc_len
);
7325 ifc_bufsize
= numifs
* sizeof (struct ifreq
);
7326 if (ifc_bufsize
> ifclen
) {
7327 if (iocp
->ioc_cmd
== O_SIOCGIFCONF
) {
7331 ifc_bufsize
= ifclen
;
7335 mp1
= mi_copyout_alloc(q
, mp
,
7336 STRUCT_FGETP(ifc
, ifc_buf
), ifc_bufsize
, B_FALSE
);
7340 mp1
->b_wptr
= mp1
->b_rptr
+ ifc_bufsize
;
7342 bzero(mp1
->b_rptr
, mp1
->b_wptr
- mp1
->b_rptr
);
7344 * the SIOCGIFCONF ioctl only knows about
7345 * IPv4 addresses, so don't try to tell
7346 * it about interfaces with IPv6-only
7347 * addresses. (Last parm 'isv6' is B_FALSE)
7350 ifr
= (struct ifreq
*)mp1
->b_rptr
;
7352 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
7353 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
7354 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
7355 if (IS_UNDER_IPMP(ill
))
7357 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
7358 ipif
= ipif
->ipif_next
) {
7359 if (zoneid
!= ipif
->ipif_zoneid
&&
7360 ipif
->ipif_zoneid
!= ALL_ZONES
)
7362 if ((uchar_t
*)&ifr
[1] > mp1
->b_wptr
) {
7363 if (iocp
->ioc_cmd
== O_SIOCGIFCONF
) {
7365 rw_exit(&ipst
->ips_ill_g_lock
);
7371 ipif_get_name(ipif
, ifr
->ifr_name
,
7372 sizeof (ifr
->ifr_name
));
7373 sin
= (sin_t
*)&ifr
->ifr_addr
;
7375 sin
->sin_family
= AF_INET
;
7376 sin
->sin_addr
.s_addr
= ipif
->ipif_lcl_addr
;
7381 rw_exit(&ipst
->ips_ill_g_lock
);
7382 mp1
->b_wptr
= (uchar_t
*)ifr
;
7384 if (STRUCT_BUF(ifc
) != NULL
) {
7385 STRUCT_FSET(ifc
, ifc_len
,
7386 (int)((uchar_t
*)ifr
- mp1
->b_rptr
));
7392 * Get the interfaces using the address hosted on the interface passed in,
7393 * as a source adddress
7397 ip_sioctl_get_lifsrcof(ipif_t
*dummy_ipif
, sin_t
*dummy_sin
, queue_t
*q
,
7398 mblk_t
*mp
, ip_ioctl_cmd_t
*ipip
, void *ifreq
)
7401 ill_t
*ill
, *ill_head
;
7402 ipif_t
*ipif
, *orig_ipif
;
7404 size_t lifs_bufsize
, lifsmaxlen
;
7405 struct lifreq
*lifr
;
7406 struct iocblk
*iocp
= (struct iocblk
*)mp
->b_rptr
;
7409 boolean_t isv6
= B_FALSE
;
7410 struct sockaddr_in
*sin
;
7411 struct sockaddr_in6
*sin6
;
7412 STRUCT_HANDLE(lifsrcof
, lifs
);
7415 ipst
= CONNQ_TO_IPST(q
);
7417 ASSERT(q
->q_next
== NULL
);
7419 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
7421 /* Existence verified in ip_wput_nondata */
7422 mp1
= mp
->b_cont
->b_cont
;
7425 * Must be (better be!) continuation of a TRANSPARENT
7426 * IOCTL. We just copied in the lifsrcof structure.
7428 STRUCT_SET_HANDLE(lifs
, iocp
->ioc_flag
,
7429 (struct lifsrcof
*)mp1
->b_rptr
);
7431 if (MBLKL(mp1
) != STRUCT_SIZE(lifs
))
7434 ifindex
= STRUCT_FGET(lifs
, lifs_ifindex
);
7435 isv6
= (Q_TO_CONN(q
))->conn_family
== AF_INET6
;
7436 ipif
= ipif_lookup_on_ifindex(ifindex
, isv6
, zoneid
, ipst
);
7438 ip1dbg(("ip_sioctl_get_lifsrcof: no ipif for ifindex %d\n",
7443 /* Allocate a buffer to hold requested information */
7444 numlifs
= ip_get_lifsrcofnum(ipif
->ipif_ill
);
7445 lifs_bufsize
= numlifs
* sizeof (struct lifreq
);
7446 lifsmaxlen
= STRUCT_FGET(lifs
, lifs_maxlen
);
7447 /* The actual size needed is always returned in lifs_len */
7448 STRUCT_FSET(lifs
, lifs_len
, lifs_bufsize
);
7450 /* If the amount we need is more than what is passed in, abort */
7451 if (lifs_bufsize
> lifsmaxlen
|| lifs_bufsize
== 0) {
7456 mp1
= mi_copyout_alloc(q
, mp
,
7457 STRUCT_FGETP(lifs
, lifs_buf
), lifs_bufsize
, B_FALSE
);
7463 mp1
->b_wptr
= mp1
->b_rptr
+ lifs_bufsize
;
7464 bzero(mp1
->b_rptr
, lifs_bufsize
);
7466 lifr
= (struct lifreq
*)mp1
->b_rptr
;
7468 ill
= ill_head
= ipif
->ipif_ill
;
7471 /* ill_g_usesrc_lock protects ill_usesrc_grp_next */
7472 rw_enter(&ipst
->ips_ill_g_usesrc_lock
, RW_READER
);
7473 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
7475 ill
= ill
->ill_usesrc_grp_next
; /* start from next ill */
7476 for (; (ill
!= NULL
) && (ill
!= ill_head
);
7477 ill
= ill
->ill_usesrc_grp_next
) {
7479 if ((uchar_t
*)&lifr
[1] > mp1
->b_wptr
)
7482 ipif
= ill
->ill_ipif
;
7483 ipif_get_name(ipif
, lifr
->lifr_name
, sizeof (lifr
->lifr_name
));
7484 if (ipif
->ipif_isv6
) {
7485 sin6
= (sin6_t
*)&lifr
->lifr_addr
;
7487 sin6
->sin6_family
= AF_INET6
;
7488 sin6
->sin6_addr
= ipif
->ipif_v6lcl_addr
;
7489 lifr
->lifr_addrlen
= ip_mask_to_plen_v6(
7490 &ipif
->ipif_v6net_mask
);
7492 sin
= (sin_t
*)&lifr
->lifr_addr
;
7494 sin
->sin_family
= AF_INET
;
7495 sin
->sin_addr
.s_addr
= ipif
->ipif_lcl_addr
;
7496 lifr
->lifr_addrlen
= ip_mask_to_plen(
7497 ipif
->ipif_net_mask
);
7501 rw_exit(&ipst
->ips_ill_g_lock
);
7502 rw_exit(&ipst
->ips_ill_g_usesrc_lock
);
7503 ipif_refrele(orig_ipif
);
7504 mp1
->b_wptr
= (uchar_t
*)lifr
;
7505 STRUCT_FSET(lifs
, lifs_len
, (int)((uchar_t
*)lifr
- mp1
->b_rptr
));
7512 ip_sioctl_get_lifconf(ipif_t
*dummy_ipif
, sin_t
*dummy_sin
, queue_t
*q
,
7513 mblk_t
*mp
, ip_ioctl_cmd_t
*ipip
, void *ifreq
)
7521 size_t lifc_bufsize
;
7522 struct lifreq
*lifr
;
7524 struct sockaddr_in
*sin
;
7525 struct sockaddr_in6
*sin6
;
7526 ill_walk_context_t ctx
;
7527 struct iocblk
*iocp
= (struct iocblk
*)mp
->b_rptr
;
7530 STRUCT_HANDLE(lifconf
, lifc
);
7531 ip_stack_t
*ipst
= CONNQ_TO_IPST(q
);
7533 ip1dbg(("ip_sioctl_get_lifconf"));
7535 ASSERT(q
->q_next
== NULL
);
7537 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
7539 /* Existence verified in ip_wput_nondata */
7540 mp1
= mp
->b_cont
->b_cont
;
7543 * An extended version of SIOCGIFCONF that takes an
7544 * additional address family and flags field.
7545 * AF_UNSPEC retrieve both IPv4 and IPv6.
7546 * Unless LIFC_NOXMIT is specified the IPIF_NOXMIT
7547 * interfaces are omitted.
7548 * Similarly, IPIF_TEMPORARY interfaces are omitted
7549 * unless LIFC_TEMPORARY is specified.
7550 * If LIFC_EXTERNAL_SOURCE is specified, IPIF_NOXMIT,
7551 * IPIF_NOLOCAL, PHYI_LOOPBACK, IPIF_DEPRECATED and
7552 * not IPIF_UP interfaces are omitted. LIFC_EXTERNAL_SOURCE
7553 * has priority over LIFC_NOXMIT.
7555 STRUCT_SET_HANDLE(lifc
, iocp
->ioc_flag
, NULL
);
7557 if ((mp1
->b_wptr
- mp1
->b_rptr
) != STRUCT_SIZE(lifc
))
7561 * Must be (better be!) continuation of a TRANSPARENT
7562 * IOCTL. We just copied in the lifconf structure.
7564 STRUCT_SET_HANDLE(lifc
, iocp
->ioc_flag
, (struct lifconf
*)mp1
->b_rptr
);
7566 family
= STRUCT_FGET(lifc
, lifc_family
);
7567 flags
= STRUCT_FGET(lifc
, lifc_flags
);
7578 * walk only IPV4 ILL's.
7580 list
= IP_V4_G_HEAD
;
7584 * walk only IPV6 ILL's.
7586 list
= IP_V6_G_HEAD
;
7589 return (EAFNOSUPPORT
);
7593 * Allocate a buffer to hold requested information.
7595 * If lifc_len is larger than what is needed, we only
7596 * allocate what we will use.
7598 * If lifc_len is smaller than what is needed, return
7601 numlifs
= ip_get_numlifs(family
, flags
, zoneid
, ipst
);
7602 lifc_bufsize
= numlifs
* sizeof (struct lifreq
);
7603 lifclen
= STRUCT_FGET(lifc
, lifc_len
);
7604 if (lifc_bufsize
> lifclen
) {
7605 if (iocp
->ioc_cmd
== O_SIOCGLIFCONF
)
7608 lifc_bufsize
= lifclen
;
7611 mp1
= mi_copyout_alloc(q
, mp
,
7612 STRUCT_FGETP(lifc
, lifc_buf
), lifc_bufsize
, B_FALSE
);
7616 mp1
->b_wptr
= mp1
->b_rptr
+ lifc_bufsize
;
7617 bzero(mp1
->b_rptr
, mp1
->b_wptr
- mp1
->b_rptr
);
7619 lifr
= (struct lifreq
*)mp1
->b_rptr
;
7621 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
7622 ill
= ill_first(list
, list
, &ctx
, ipst
);
7623 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
7624 if (IS_UNDER_IPMP(ill
) && !(flags
& LIFC_UNDER_IPMP
))
7627 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
7628 ipif
= ipif
->ipif_next
) {
7629 if ((ipif
->ipif_flags
& IPIF_NOXMIT
) &&
7630 !(flags
& LIFC_NOXMIT
))
7633 if ((ipif
->ipif_flags
& IPIF_TEMPORARY
) &&
7634 !(flags
& LIFC_TEMPORARY
))
7637 if (((ipif
->ipif_flags
&
7638 (IPIF_NOXMIT
|IPIF_NOLOCAL
|
7639 IPIF_DEPRECATED
)) ||
7641 !(ipif
->ipif_flags
& IPIF_UP
)) &&
7642 (flags
& LIFC_EXTERNAL_SOURCE
))
7645 if (zoneid
!= ipif
->ipif_zoneid
&&
7646 ipif
->ipif_zoneid
!= ALL_ZONES
&&
7647 (zoneid
!= GLOBAL_ZONEID
||
7648 !(flags
& LIFC_ALLZONES
)))
7651 if ((uchar_t
*)&lifr
[1] > mp1
->b_wptr
) {
7652 if (iocp
->ioc_cmd
== O_SIOCGLIFCONF
) {
7653 rw_exit(&ipst
->ips_ill_g_lock
);
7660 ipif_get_name(ipif
, lifr
->lifr_name
,
7661 sizeof (lifr
->lifr_name
));
7662 lifr
->lifr_type
= ill
->ill_type
;
7663 if (ipif
->ipif_isv6
) {
7664 sin6
= (sin6_t
*)&lifr
->lifr_addr
;
7666 sin6
->sin6_family
= AF_INET6
;
7668 ipif
->ipif_v6lcl_addr
;
7669 lifr
->lifr_addrlen
=
7671 &ipif
->ipif_v6net_mask
);
7673 sin
= (sin_t
*)&lifr
->lifr_addr
;
7675 sin
->sin_family
= AF_INET
;
7676 sin
->sin_addr
.s_addr
=
7677 ipif
->ipif_lcl_addr
;
7678 lifr
->lifr_addrlen
=
7680 ipif
->ipif_net_mask
);
7686 rw_exit(&ipst
->ips_ill_g_lock
);
7688 mp1
->b_wptr
= (uchar_t
*)lifr
;
7689 if (STRUCT_BUF(lifc
) != NULL
) {
7690 STRUCT_FSET(lifc
, lifc_len
,
7691 (int)((uchar_t
*)lifr
- mp1
->b_rptr
));
7697 ip_sioctl_ip6addrpolicy(queue_t
*q
, mblk_t
*mp
)
7702 struct iocblk
*iocp
= (struct iocblk
*)mp
->b_rptr
;
7705 if (q
->q_next
== NULL
)
7706 ipst
= CONNQ_TO_IPST(q
);
7708 ipst
= ILLQ_TO_IPST(q
);
7710 /* These two ioctls are I_STR only */
7711 if (iocp
->ioc_count
== TRANSPARENT
) {
7712 miocnak(q
, mp
, 0, EINVAL
);
7716 data_mp
= mp
->b_cont
;
7717 if (data_mp
== NULL
) {
7718 /* The user passed us a NULL argument */
7720 table_size
= iocp
->ioc_count
;
7723 * The user provided a table. The stream head
7724 * may have copied in the user data in chunks,
7725 * so make sure everything is pulled up
7728 if (MBLKL(data_mp
) < iocp
->ioc_count
) {
7729 mblk_t
*new_data_mp
;
7730 if ((new_data_mp
= msgpullup(data_mp
, -1)) ==
7732 miocnak(q
, mp
, 0, ENOMEM
);
7736 data_mp
= new_data_mp
;
7737 mp
->b_cont
= data_mp
;
7739 table
= (ip6_asp_t
*)data_mp
->b_rptr
;
7740 table_size
= iocp
->ioc_count
;
7743 switch (iocp
->ioc_cmd
) {
7744 case SIOCGIP6ADDRPOLICY
:
7745 iocp
->ioc_rval
= ip6_asp_get(table
, table_size
, ipst
);
7746 if (iocp
->ioc_rval
== -1)
7747 iocp
->ioc_error
= EINVAL
;
7748 #if defined(_SYSCALL32_IMPL) && _LONG_LONG_ALIGNMENT_32 == 4
7749 else if (table
!= NULL
&&
7750 (iocp
->ioc_flag
& IOC_MODELS
) == IOC_ILP32
) {
7751 ip6_asp_t
*src
= table
;
7752 ip6_asp32_t
*dst
= (void *)table
;
7753 int count
= table_size
/ sizeof (ip6_asp_t
);
7757 * We need to do an in-place shrink of the array
7758 * to match the alignment attributes of the
7759 * 32-bit ABI looking at it.
7761 /* LINTED: logical expression always true: op "||" */
7762 ASSERT(sizeof (*src
) > sizeof (*dst
));
7763 for (i
= 1; i
< count
; i
++)
7764 bcopy(src
+ i
, dst
+ i
, sizeof (*dst
));
7769 case SIOCSIP6ADDRPOLICY
:
7770 ASSERT(mp
->b_prev
== NULL
);
7771 mp
->b_prev
= (void *)q
;
7772 #if defined(_SYSCALL32_IMPL) && _LONG_LONG_ALIGNMENT_32 == 4
7774 * We pass in the datamodel here so that the ip6_asp_replace()
7775 * routine can handle converting from 32-bit to native formats
7778 * A better way to handle this might be to convert the inbound
7779 * data structure here, and hang it off a new 'mp'; thus the
7780 * ip6_asp_replace() logic would always be dealing with native
7781 * format data structures..
7783 * (An even simpler way to handle these ioctls is to just
7784 * add a 32-bit trailing 'pad' field to the ip6_asp_t structure
7785 * and just recompile everything that depends on it.)
7788 ip6_asp_replace(mp
, table
, table_size
, B_FALSE
, ipst
,
7789 iocp
->ioc_flag
& IOC_MODELS
);
7793 DB_TYPE(mp
) = (iocp
->ioc_error
== 0) ? M_IOCACK
: M_IOCNAK
;
7798 ip_sioctl_dstinfo(queue_t
*q
, mblk_t
*mp
)
7801 struct dstinforeq
*dir
;
7803 in6_addr_t
*daddr
, *saddr
;
7807 in6_addr_t v6setsrc
;
7808 char *slabel
, *dlabel
;
7812 struct iocblk
*iocp
= (struct iocblk
*)mp
->b_rptr
;
7813 conn_t
*connp
= Q_TO_CONN(q
);
7814 zoneid_t zoneid
= IPCL_ZONEID(connp
);
7815 ip_stack_t
*ipst
= connp
->conn_netstack
->netstack_ip
;
7816 uint64_t ipif_flags
;
7818 ASSERT(q
->q_next
== NULL
); /* this ioctl not allowed if ip is module */
7821 * This ioctl is I_STR only, and must have a
7822 * data mblk following the M_IOCTL mblk.
7824 data_mp
= mp
->b_cont
;
7825 if (iocp
->ioc_count
== TRANSPARENT
|| data_mp
== NULL
) {
7826 miocnak(q
, mp
, 0, EINVAL
);
7830 if (MBLKL(data_mp
) < iocp
->ioc_count
) {
7831 mblk_t
*new_data_mp
;
7833 if ((new_data_mp
= msgpullup(data_mp
, -1)) == NULL
) {
7834 miocnak(q
, mp
, 0, ENOMEM
);
7838 data_mp
= new_data_mp
;
7839 mp
->b_cont
= data_mp
;
7841 match_ire
= MATCH_IRE_DSTONLY
;
7843 for (cur
= data_mp
->b_rptr
, end
= data_mp
->b_wptr
;
7844 end
- cur
>= sizeof (struct dstinforeq
);
7845 cur
+= sizeof (struct dstinforeq
)) {
7846 dir
= (struct dstinforeq
*)cur
;
7847 daddr
= &dir
->dir_daddr
;
7848 saddr
= &dir
->dir_saddr
;
7851 * ip_addr_scope_v6() and ip6_asp_lookup() handle
7852 * v4 mapped addresses; ire_ftable_lookup_v6()
7853 * and ip_select_source_v6() do not.
7855 dir
->dir_dscope
= ip_addr_scope_v6(daddr
);
7856 dlabel
= ip6_asp_lookup(daddr
, &dir
->dir_precedence
, ipst
);
7858 isipv4
= IN6_IS_ADDR_V4MAPPED(daddr
);
7860 IN6_V4MAPPED_TO_IPADDR(daddr
, v4daddr
);
7861 v4setsrc
= INADDR_ANY
;
7862 ire
= ire_route_recursive_v4(v4daddr
, 0, NULL
, zoneid
,
7863 match_ire
, IRR_ALLOCATE
, 0, ipst
, &v4setsrc
, NULL
);
7865 v6setsrc
= ipv6_all_zeros
;
7866 ire
= ire_route_recursive_v6(daddr
, 0, NULL
, zoneid
,
7867 match_ire
, IRR_ALLOCATE
, 0, ipst
, &v6setsrc
, NULL
);
7869 ASSERT(ire
!= NULL
);
7870 if (ire
->ire_flags
& (RTF_REJECT
|RTF_BLACKHOLE
)) {
7872 dir
->dir_dreachable
= 0;
7874 /* move on to next dst addr */
7877 dir
->dir_dreachable
= 1;
7879 dst_ill
= ire_nexthop_ill(ire
);
7880 if (dst_ill
== NULL
) {
7885 /* With ipmp we most likely look at the ipmp ill here */
7886 dir
->dir_dmactype
= dst_ill
->ill_mactype
;
7891 if (ip_select_source_v4(dst_ill
, v4setsrc
, v4daddr
,
7892 connp
->conn_ixa
->ixa_multicast_ifaddr
, zoneid
, ipst
,
7893 &v4saddr
, NULL
, &ipif_flags
) != 0) {
7894 v4saddr
= INADDR_ANY
;
7897 IN6_IPADDR_TO_V4MAPPED(v4saddr
, saddr
);
7899 if (ip_select_source_v6(dst_ill
, &v6setsrc
, daddr
,
7900 zoneid
, ipst
, B_FALSE
, IPV6_PREFER_SRC_DEFAULT
,
7901 saddr
, NULL
, &ipif_flags
) != 0) {
7902 *saddr
= ipv6_all_zeros
;
7907 dir
->dir_sscope
= ip_addr_scope_v6(saddr
);
7908 slabel
= ip6_asp_lookup(saddr
, NULL
, ipst
);
7909 dir
->dir_labelmatch
= ip6_asp_labelcmp(dlabel
, slabel
);
7910 dir
->dir_sdeprecated
= (ipif_flags
& IPIF_DEPRECATED
) ? 1 : 0;
7912 ill_refrele(dst_ill
);
7914 miocack(q
, mp
, iocp
->ioc_count
, 0);
7918 * Check if this is an address assigned to this machine.
7919 * Skips interfaces that are down by using ire checks.
7920 * Translates mapped addresses to v4 addresses and then
7921 * treats them as such, returning true if the v4 address
7922 * associated with this mapped address is configured.
7923 * Note: Applications will have to be careful what they do
7924 * with the response; use of mapped addresses limits
7925 * what can be done with the socket, especially with
7926 * respect to socket options and ioctls - neither IPv4
7927 * options nor IPv6 sticky options/ancillary data options
7932 ip_sioctl_tmyaddr(ipif_t
*dummy_ipif
, sin_t
*dummy_sin
, queue_t
*q
, mblk_t
*mp
,
7933 ip_ioctl_cmd_t
*ipip
, void *dummy_ifreq
)
7935 struct sioc_addrreq
*sia
;
7942 ip1dbg(("ip_sioctl_tmyaddr"));
7944 ASSERT(q
->q_next
== NULL
); /* this ioctl not allowed if ip is module */
7945 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
7946 ipst
= CONNQ_TO_IPST(q
);
7948 /* Existence verified in ip_wput_nondata */
7949 mp1
= mp
->b_cont
->b_cont
;
7950 sia
= (struct sioc_addrreq
*)mp1
->b_rptr
;
7951 sin
= (sin_t
*)&sia
->sa_addr
;
7952 switch (sin
->sin_family
) {
7954 sin6_t
*sin6
= (sin6_t
*)sin
;
7956 if (IN6_IS_ADDR_V4MAPPED(&sin6
->sin6_addr
)) {
7959 IN6_V4MAPPED_TO_IPADDR(&sin6
->sin6_addr
,
7961 ire
= ire_ftable_lookup_v4(v4_addr
, 0, 0,
7962 IRE_LOCAL
|IRE_LOOPBACK
, NULL
, zoneid
,
7963 MATCH_IRE_TYPE
| MATCH_IRE_ZONEONLY
, 0, ipst
, NULL
);
7967 v6addr
= sin6
->sin6_addr
;
7968 ire
= ire_ftable_lookup_v6(&v6addr
, 0, 0,
7969 IRE_LOCAL
|IRE_LOOPBACK
, NULL
, zoneid
,
7970 MATCH_IRE_TYPE
| MATCH_IRE_ZONEONLY
, 0, ipst
, NULL
);
7977 v4addr
= sin
->sin_addr
.s_addr
;
7978 ire
= ire_ftable_lookup_v4(v4addr
, 0, 0,
7979 IRE_LOCAL
|IRE_LOOPBACK
, NULL
, zoneid
,
7980 MATCH_IRE_TYPE
| MATCH_IRE_ZONEONLY
, 0, ipst
, NULL
);
7984 return (EAFNOSUPPORT
);
7996 * Check if this is an address assigned on-link i.e. neighbor,
7997 * and makes sure it's reachable from the current zone.
7998 * Returns true for my addresses as well.
7999 * Translates mapped addresses to v4 addresses and then
8000 * treats them as such, returning true if the v4 address
8001 * associated with this mapped address is configured.
8002 * Note: Applications will have to be careful what they do
8003 * with the response; use of mapped addresses limits
8004 * what can be done with the socket, especially with
8005 * respect to socket options and ioctls - neither IPv4
8006 * options nor IPv6 sticky options/ancillary data options
8011 ip_sioctl_tonlink(ipif_t
*dummy_ipif
, sin_t
*dummy_sin
, queue_t
*q
, mblk_t
*mp
,
8012 ip_ioctl_cmd_t
*ipip
, void *duymmy_ifreq
)
8014 struct sioc_addrreq
*sia
;
8021 ip1dbg(("ip_sioctl_tonlink"));
8023 ASSERT(q
->q_next
== NULL
); /* this ioctl not allowed if ip is module */
8024 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
8025 ipst
= CONNQ_TO_IPST(q
);
8027 /* Existence verified in ip_wput_nondata */
8028 mp1
= mp
->b_cont
->b_cont
;
8029 sia
= (struct sioc_addrreq
*)mp1
->b_rptr
;
8030 sin
= (sin_t
*)&sia
->sa_addr
;
8033 * We check for IRE_ONLINK and exclude IRE_BROADCAST|IRE_MULTICAST
8034 * to make sure we only look at on-link unicast address.
8036 switch (sin
->sin_family
) {
8038 sin6_t
*sin6
= (sin6_t
*)sin
;
8040 if (IN6_IS_ADDR_V4MAPPED(&sin6
->sin6_addr
)) {
8043 IN6_V4MAPPED_TO_IPADDR(&sin6
->sin6_addr
,
8045 if (!CLASSD(v4_addr
)) {
8046 ire
= ire_ftable_lookup_v4(v4_addr
, 0, 0, 0,
8047 NULL
, zoneid
, MATCH_IRE_DSTONLY
, 0, ipst
,
8053 v6addr
= sin6
->sin6_addr
;
8054 if (!IN6_IS_ADDR_MULTICAST(&v6addr
)) {
8055 ire
= ire_ftable_lookup_v6(&v6addr
, 0, 0, 0,
8056 NULL
, zoneid
, MATCH_IRE_DSTONLY
, 0, ipst
,
8065 v4addr
= sin
->sin_addr
.s_addr
;
8066 if (!CLASSD(v4addr
)) {
8067 ire
= ire_ftable_lookup_v4(v4addr
, 0, 0, 0, NULL
,
8068 zoneid
, MATCH_IRE_DSTONLY
, 0, ipst
, NULL
);
8073 return (EAFNOSUPPORT
);
8077 ASSERT(!(ire
->ire_type
& IRE_MULTICAST
));
8079 if ((ire
->ire_type
& IRE_ONLINK
) &&
8080 !(ire
->ire_type
& IRE_BROADCAST
))
8088 * TBD: implement when kernel maintaines a list of site prefixes.
8092 ip_sioctl_tmysite(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
8093 ip_ioctl_cmd_t
*ipip
, void *ifreq
)
8101 ip_sioctl_arp(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
8102 ip_ioctl_cmd_t
*ipip
, void *dummy_ifreq
)
8106 struct iocblk
*iocp
;
8109 struct xarpreq
*xar
;
8110 int arp_flags
, flags
, alength
;
8113 ill_t
*ill
= ipif
->ipif_ill
;
8114 ill_t
*proxy_ill
= NULL
;
8115 ipmp_arpent_t
*entp
= NULL
;
8116 boolean_t proxyarp
= B_FALSE
;
8117 boolean_t if_arp_ioctl
= B_FALSE
;
8118 ncec_t
*ncec
= NULL
;
8121 ASSERT(!(q
->q_flag
& QREADR
) && q
->q_next
== NULL
);
8122 connp
= Q_TO_CONN(q
);
8123 ipst
= connp
->conn_netstack
->netstack_ip
;
8124 iocp
= (struct iocblk
*)mp
->b_rptr
;
8126 if (ipip
->ipi_cmd_type
== XARP_CMD
) {
8127 /* We have a chain - M_IOCTL-->MI_COPY_MBLK-->XARPREQ_MBLK */
8128 xar
= (struct xarpreq
*)mp
->b_cont
->b_cont
->b_rptr
;
8131 arp_flags
= xar
->xarp_flags
;
8132 lladdr
= (uchar_t
*)LLADDR(&xar
->xarp_ha
);
8133 if_arp_ioctl
= (xar
->xarp_ha
.sdl_nlen
!= 0);
8135 * Validate against user's link layer address length
8136 * input and name and addr length limits.
8138 alength
= ill
->ill_phys_addr_length
;
8139 if (ipip
->ipi_cmd
== SIOCSXARP
) {
8140 if (alength
!= xar
->xarp_ha
.sdl_alen
||
8141 (alength
+ xar
->xarp_ha
.sdl_nlen
>
8142 sizeof (xar
->xarp_ha
.sdl_data
)))
8146 /* We have a chain - M_IOCTL-->MI_COPY_MBLK-->ARPREQ_MBLK */
8147 ar
= (struct arpreq
*)mp
->b_cont
->b_cont
->b_rptr
;
8150 arp_flags
= ar
->arp_flags
;
8151 lladdr
= (uchar_t
*)ar
->arp_ha
.sa_data
;
8153 * Theoretically, the sa_family could tell us what link
8154 * layer type this operation is trying to deal with. By
8155 * common usage AF_UNSPEC means ethernet. We'll assume
8156 * any attempt to use the SIOC?ARP ioctls is for ethernet,
8157 * for now. Our new SIOC*XARP ioctls can be used more
8160 * If the underlying media happens to have a non 6 byte
8161 * address, arp module will fail set/get, but the del
8162 * operation will succeed.
8165 if ((ipip
->ipi_cmd
!= SIOCDARP
) &&
8166 (alength
!= ill
->ill_phys_addr_length
)) {
8171 /* Translate ATF* flags to NCE* flags */
8173 if (arp_flags
& ATF_AUTHORITY
)
8174 flags
|= NCE_F_AUTHORITY
;
8175 if (arp_flags
& ATF_PERM
)
8176 flags
|= NCE_F_NONUD
; /* not subject to aging */
8177 if (arp_flags
& ATF_PUBL
)
8178 flags
|= NCE_F_PUBLISH
;
8181 * IPMP ARP special handling:
8183 * 1. Since ARP mappings must appear consistent across the group,
8184 * prohibit changing ARP mappings on the underlying interfaces.
8186 * 2. Since ARP mappings for IPMP data addresses are maintained by
8187 * IP itself, prohibit changing them.
8189 * 3. For proxy ARP, use a functioning hardware address in the group,
8190 * provided one exists. If one doesn't, just add the entry as-is;
8191 * ipmp_illgrp_refresh_arpent() will refresh it if things change.
8193 if (IS_UNDER_IPMP(ill
)) {
8194 if (ipip
->ipi_cmd
!= SIOCGARP
&& ipip
->ipi_cmd
!= SIOCGXARP
)
8198 ipmp_illgrp_t
*illg
= ill
->ill_grp
;
8200 switch (ipip
->ipi_cmd
) {
8203 proxy_ill
= ipmp_illgrp_find_ill(illg
, lladdr
, alength
);
8204 if (proxy_ill
!= NULL
) {
8206 if (!ipmp_ill_is_active(proxy_ill
))
8207 proxy_ill
= ipmp_illgrp_next_ill(illg
);
8208 if (proxy_ill
!= NULL
)
8209 lladdr
= proxy_ill
->ill_phys_addr
;
8215 ipaddr
= sin
->sin_addr
.s_addr
;
8217 * don't match across illgrp per case (1) and (2).
8218 * XXX use IS_IPMP(ill) like ndp_sioc_update?
8220 nce
= nce_lookup_v4(ill
, &ipaddr
);
8222 ncec
= nce
->nce_common
;
8224 switch (iocp
->ioc_cmd
) {
8228 * Delete the NCE if any.
8231 iocp
->ioc_error
= ENXIO
;
8234 /* Don't allow changes to arp mappings of local addresses. */
8235 if (NCE_MYADDR(ncec
)) {
8239 iocp
->ioc_error
= 0;
8242 * Delete the nce_common which has ncec_ill set to ipmp_ill.
8243 * This will delete all the nce entries on the under_ills.
8247 * Once the NCE has been deleted, then the ire_dep* consistency
8248 * mechanism will find any IRE which depended on the now
8249 * condemned NCE (as part of sending packets).
8250 * That mechanism handles redirects by deleting redirects
8251 * that refer to UNREACHABLE nces.
8258 lladdr
= ncec
->ncec_lladdr
;
8259 flags
= ncec
->ncec_flags
;
8260 iocp
->ioc_error
= 0;
8261 ip_sioctl_garp_reply(mp
, ncec
->ncec_ill
, lladdr
, flags
);
8263 iocp
->ioc_error
= ENXIO
;
8268 /* Don't allow changes to arp mappings of local addresses. */
8269 if (ncec
!= NULL
&& NCE_MYADDR(ncec
)) {
8274 /* static arp entries will undergo NUD if ATF_PERM is not set */
8275 flags
|= NCE_F_STATIC
;
8276 if (!if_arp_ioctl
) {
8277 ip_nce_lookup_and_update(&ipaddr
, NULL
, ipst
,
8278 lladdr
, alength
, flags
);
8280 ipif_t
*ipif
= ipif_get_next_ipif(NULL
, ill
);
8282 ip_nce_lookup_and_update(&ipaddr
, ipif
, ipst
,
8283 lladdr
, alength
, flags
);
8292 * NCE_F_STATIC entries will be added in state ND_REACHABLE
8293 * by nce_add_common()
8295 err
= nce_lookup_then_add_v4(ill
, lladdr
,
8296 ill
->ill_phys_addr_length
, &ipaddr
, flags
, ND_UNCHANGED
,
8298 if (err
== EEXIST
) {
8299 ncec
= nce
->nce_common
;
8300 mutex_enter(&ncec
->ncec_lock
);
8301 ncec
->ncec_state
= ND_REACHABLE
;
8302 ncec
->ncec_flags
= flags
;
8303 nce_update(ncec
, ND_UNCHANGED
, lladdr
);
8304 mutex_exit(&ncec
->ncec_lock
);
8311 if (IS_IPMP(ill
) && err
== 0) {
8312 entp
= ipmp_illgrp_create_arpent(ill
->ill_grp
,
8313 proxyarp
, ipaddr
, lladdr
, ill
->ill_phys_addr_length
,
8315 if (entp
== NULL
|| (proxyarp
&& proxy_ill
== NULL
)) {
8316 iocp
->ioc_error
= (entp
== NULL
? ENOMEM
: 0);
8320 iocp
->ioc_error
= err
;
8328 * If we created an IPMP ARP entry, mark that we've notified ARP.
8331 ipmp_illgrp_mark_arpent(ill
->ill_grp
, entp
);
8333 return (iocp
->ioc_error
);
8337 * Parse an [x]arpreq structure coming down SIOC[GSD][X]ARP ioctls, identify
8338 * the associated sin and refhold and return the associated ipif via `ci'.
8341 ip_extract_arpreq(queue_t
*q
, mblk_t
*mp
, const ip_ioctl_cmd_t
*ipip
,
8353 struct xarpreq
*xar
;
8354 struct sockaddr_dl
*sdl
;
8356 /* ioctl comes down on a conn */
8357 ASSERT(!(q
->q_flag
& QREADR
) && q
->q_next
== NULL
);
8358 connp
= Q_TO_CONN(q
);
8359 if (connp
->conn_family
== AF_INET6
)
8362 ipst
= connp
->conn_netstack
->netstack_ip
;
8364 /* Verified in ip_wput_nondata */
8365 mp1
= mp
->b_cont
->b_cont
;
8367 if (ipip
->ipi_cmd_type
== XARP_CMD
) {
8368 ASSERT(MBLKL(mp1
) >= sizeof (struct xarpreq
));
8369 xar
= (struct xarpreq
*)mp1
->b_rptr
;
8370 sin
= (sin_t
*)&xar
->xarp_pa
;
8371 sdl
= &xar
->xarp_ha
;
8373 if (sdl
->sdl_family
!= AF_LINK
|| sin
->sin_family
!= AF_INET
)
8375 if (sdl
->sdl_nlen
>= LIFNAMSIZ
)
8378 ASSERT(ipip
->ipi_cmd_type
== ARP_CMD
);
8379 ASSERT(MBLKL(mp1
) >= sizeof (struct arpreq
));
8380 ar
= (struct arpreq
*)mp1
->b_rptr
;
8381 sin
= (sin_t
*)&ar
->arp_pa
;
8384 if (ipip
->ipi_cmd_type
== XARP_CMD
&& sdl
->sdl_nlen
!= 0) {
8385 ipif
= ipif_lookup_on_name(sdl
->sdl_data
, sdl
->sdl_nlen
,
8386 B_FALSE
, &exists
, B_FALSE
, ALL_ZONES
, ipst
);
8389 if (ipif
->ipif_id
!= 0) {
8395 * Either an SIOC[DGS]ARP or an SIOC[DGS]XARP with an sdl_nlen
8396 * of 0: use the IP address to find the ipif. If the IP
8397 * address is an IPMP test address, ire_ftable_lookup() will
8398 * find the wrong ill, so we first do an ipif_lookup_addr().
8400 ipif
= ipif_lookup_addr(sin
->sin_addr
.s_addr
, NULL
, ALL_ZONES
,
8403 ire
= ire_ftable_lookup_v4(sin
->sin_addr
.s_addr
,
8404 0, 0, IRE_IF_RESOLVER
, NULL
, ALL_ZONES
,
8405 MATCH_IRE_TYPE
, 0, ipst
, NULL
);
8406 if (ire
== NULL
|| ((ill
= ire
->ire_ill
) == NULL
)) {
8411 ASSERT(ire
!= NULL
&& ill
!= NULL
);
8412 ipif
= ill
->ill_ipif
;
8418 if (ipif
->ipif_ill
->ill_net_type
!= IRE_IF_RESOLVER
) {
8429 * Link or unlink the illgrp on IPMP meta-interface `ill' depending on the
8430 * value of `ioccmd'. While an illgrp is linked to an ipmp_grp_t, it is
8431 * accessible from that ipmp_grp_t, which means SIOCSLIFGROUPNAME can look it
8432 * up and thus an ill can join that illgrp.
8434 * We use I_PLINK/I_PUNLINK to do the link/unlink operations rather than
8435 * open()/close() primarily because close() is not allowed to fail or block
8436 * forever. On the other hand, I_PUNLINK *can* fail, and there's no reason
8437 * why anyone should ever need to I_PUNLINK an in-use IPMP stream. To ensure
8438 * symmetric behavior (e.g., doing an I_PLINK after and I_PUNLINK undoes the
8439 * I_PUNLINK) we defer linking to I_PLINK. Separately, we also fail attempts
8440 * to I_LINK since I_UNLINK is optional and we'd end up in an inconsistent
8441 * state if I_UNLINK didn't occur.
8443 * Note that for each plumb/unplumb operation, we may end up here more than
8444 * once because of the way ifconfig works. However, it's OK to link the same
8445 * illgrp more than once, or unlink an illgrp that's already unlinked.
8448 ip_sioctl_plink_ipmp(ill_t
*ill
, int ioccmd
)
8451 ip_stack_t
*ipst
= ill
->ill_ipst
;
8453 ASSERT(IS_IPMP(ill
));
8454 ASSERT(IAM_WRITER_ILL(ill
));
8461 rw_enter(&ipst
->ips_ipmp_lock
, RW_WRITER
);
8462 ipmp_illgrp_link_grp(ill
->ill_grp
, ill
->ill_phyint
->phyint_grp
);
8463 rw_exit(&ipst
->ips_ipmp_lock
);
8468 * Require all UP ipifs be brought down prior to unlinking the
8469 * illgrp so any associated IREs (and other state) is torched.
8471 if (ill
->ill_ipif_up_count
+ ill
->ill_ipif_dup_count
> 0)
8475 * NOTE: We hold ipmp_lock across the unlink to prevent a race
8476 * with an SIOCSLIFGROUPNAME request from an ill trying to
8477 * join this group. Specifically: ills trying to join grab
8478 * ipmp_lock and bump a "pending join" counter checked by
8479 * ipmp_illgrp_unlink_grp(). During the unlink no new pending
8480 * joins can occur (since we have ipmp_lock). Once we drop
8481 * ipmp_lock, subsequent SIOCSLIFGROUPNAME requests will not
8482 * find the illgrp (since we unlinked it) and will return
8483 * EAFNOSUPPORT. This will then take them back through the
8484 * IPMP meta-interface plumbing logic in ifconfig, and thus
8485 * back through I_PLINK above.
8487 rw_enter(&ipst
->ips_ipmp_lock
, RW_WRITER
);
8488 err
= ipmp_illgrp_unlink_grp(ill
->ill_grp
);
8489 rw_exit(&ipst
->ips_ipmp_lock
);
8498 * Do I_PLINK/I_LINK or I_PUNLINK/I_UNLINK with consistency checks and also
8499 * atomically set/clear the muxids. Also complete the ioctl by acking or
8500 * naking it. Note that the code is structured such that the link type,
8501 * whether it's persistent or not, is treated equally. ifconfig(1M) and
8502 * its clones use the persistent link, while pppd(1M) and perhaps many
8503 * other daemons may use non-persistent link. When combined with some
8504 * ill_t states, linking and unlinking lower streams may be used as
8505 * indicators of dynamic re-plumbing events [see PSARC/1999/348].
8509 ip_sioctl_plink(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
, void *dummy_arg
)
8513 int ioccmd
= ((struct iocblk
*)mp
->b_rptr
)->ioc_cmd
;
8516 ASSERT(ioccmd
== I_PLINK
|| ioccmd
== I_PUNLINK
||
8517 ioccmd
== I_LINK
|| ioccmd
== I_UNLINK
);
8519 mp1
= mp
->b_cont
; /* This is the linkblk info */
8520 li
= (struct linkblk
*)mp1
->b_rptr
;
8522 err
= ip_sioctl_plink_ipmod(ipsq
, q
, mp
, ioccmd
, li
);
8523 if (err
== EINPROGRESS
)
8526 miocack(q
, mp
, 0, 0);
8528 miocnak(q
, mp
, 0, err
);
8530 /* Conn was refheld in ip_sioctl_copyin_setup */
8532 CONN_DEC_IOCTLREF(Q_TO_CONN(q
));
8533 CONN_OPER_PENDING_DONE(Q_TO_CONN(q
));
8538 * Process I_{P}LINK and I_{P}UNLINK requests named by `ioccmd' and pointed to
8539 * by `mp' and `li' for the IP module stream (if li->q_bot is in fact an IP
8541 * Returns zero on success, EINPROGRESS if the operation is still pending, or
8542 * an error code on failure.
8545 ip_sioctl_plink_ipmod(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
, int ioccmd
,
8550 queue_t
*ipwq
, *dwq
;
8552 struct qinit
*qinfo
;
8553 boolean_t islink
= (ioccmd
== I_PLINK
|| ioccmd
== I_LINK
);
8554 boolean_t entered_ipsq
= B_FALSE
;
8555 boolean_t is_ip
= B_FALSE
;
8559 * Walk the lower stream to verify it's the IP module stream.
8560 * The IP module is identified by its name, wput function,
8561 * and non-NULL q_next. STREAMS ensures that the lower stream
8562 * (li->l_qbot) will not vanish until this ioctl completes.
8564 for (ipwq
= li
->l_qbot
; ipwq
!= NULL
; ipwq
= ipwq
->q_next
) {
8565 qinfo
= ipwq
->q_qinfo
;
8566 name
= qinfo
->qi_minfo
->mi_idname
;
8567 if (name
!= NULL
&& strcmp(name
, ip_mod_info
.mi_idname
) == 0 &&
8568 qinfo
->qi_putp
!= (pfi_t
)ip_lwput
&& ipwq
->q_next
!= NULL
) {
8572 if (name
!= NULL
&& strcmp(name
, arp_mod_info
.mi_idname
) == 0 &&
8573 qinfo
->qi_putp
!= (pfi_t
)ip_lwput
&& ipwq
->q_next
!= NULL
) {
8579 * If this isn't an IP module stream, bail.
8585 arl
= (arl_t
*)ipwq
->q_ptr
;
8586 ill
= arl_to_ill(arl
);
8592 ASSERT(ill
!= NULL
);
8595 ipsq
= ipsq_try_enter(NULL
, ill
, q
, mp
, ip_sioctl_plink
,
8600 return (EINPROGRESS
);
8602 entered_ipsq
= B_TRUE
;
8604 ASSERT(IAM_WRITER_ILL(ill
));
8605 mutex_enter(&ill
->ill_lock
);
8607 if (islink
&& ill
->ill_muxid
== 0) {
8609 * Plumbing has to be done with IP plumbed first, arp
8610 * second, but here we have arp being plumbed first.
8612 mutex_exit(&ill
->ill_lock
);
8619 mutex_exit(&ill
->ill_lock
);
8621 arl
->arl_muxid
= islink
? li
->l_index
: 0;
8626 if (IS_IPMP(ill
) && (err
= ip_sioctl_plink_ipmp(ill
, ioccmd
)) != 0)
8630 * As part of I_{P}LINKing, stash the number of downstream modules and
8631 * the read queue of the module immediately below IP in the ill.
8632 * These are used during the capability negotiation below.
8634 ill
->ill_lmod_rq
= NULL
;
8635 ill
->ill_lmod_cnt
= 0;
8636 if (islink
&& ((dwq
= ipwq
->q_next
) != NULL
)) {
8637 ill
->ill_lmod_rq
= RD(dwq
);
8638 for (; dwq
!= NULL
; dwq
= dwq
->q_next
)
8639 ill
->ill_lmod_cnt
++;
8642 ill
->ill_muxid
= islink
? li
->l_index
: 0;
8645 * Mark the ipsq busy until the capability operations initiated below
8646 * complete. The PLINK/UNLINK ioctl itself completes when our caller
8647 * returns, but the capability operation may complete asynchronously
8650 ipsq_current_start(ipsq
, ill
->ill_ipif
, ioccmd
);
8652 * If there's at least one up ipif on this ill, then we're bound to
8653 * the underlying driver via DLPI. In that case, renegotiate
8654 * capabilities to account for any possible change in modules
8655 * interposed between IP and the driver.
8657 if (ill
->ill_ipif_up_count
> 0) {
8659 ill_capability_probe(ill
);
8661 ill_capability_reset(ill
, B_FALSE
);
8663 ipsq_current_finish(ipsq
);
8672 * Search the ioctl command in the ioctl tables and return a pointer
8673 * to the ioctl command information. The ioctl command tables are
8674 * static and fully populated at compile time.
8677 ip_sioctl_lookup(int ioc_cmd
)
8680 ip_ioctl_cmd_t
*ipip
;
8681 ip_ioctl_cmd_t
*ipip_end
;
8683 if (ioc_cmd
== IPI_DONTCARE
)
8687 * Do a 2 step search. First search the indexed table
8688 * based on the least significant byte of the ioctl cmd.
8689 * If we don't find a match, then search the misc table
8692 index
= ioc_cmd
& 0xFF;
8693 if (index
< ip_ndx_ioctl_count
) {
8694 ipip
= &ip_ndx_ioctl_table
[index
];
8695 if (ipip
->ipi_cmd
== ioc_cmd
) {
8696 /* Found a match in the ndx table */
8701 /* Search the misc table */
8702 ipip_end
= &ip_misc_ioctl_table
[ip_misc_ioctl_count
];
8703 for (ipip
= ip_misc_ioctl_table
; ipip
< ipip_end
; ipip
++) {
8704 if (ipip
->ipi_cmd
== ioc_cmd
)
8705 /* Found a match in the misc table */
8713 * helper function for ip_sioctl_getsetprop(), which does some sanity checks
8716 getset_ioctl_checks(mblk_t
*mp
)
8718 struct iocblk
*iocp
= (struct iocblk
*)mp
->b_rptr
;
8719 mblk_t
*mp1
= mp
->b_cont
;
8720 mod_ioc_prop_t
*pioc
;
8724 /* do sanity checks on various arguments */
8725 if (mp1
== NULL
|| iocp
->ioc_count
== 0 ||
8726 iocp
->ioc_count
== TRANSPARENT
) {
8729 if (msgdsize(mp1
) < iocp
->ioc_count
) {
8730 if (!pullupmsg(mp1
, iocp
->ioc_count
))
8734 pioc
= (mod_ioc_prop_t
*)mp1
->b_rptr
;
8736 /* sanity checks on mpr_valsize */
8737 pioc_size
= sizeof (mod_ioc_prop_t
);
8738 if (pioc
->mpr_valsize
!= 0)
8739 pioc_size
+= pioc
->mpr_valsize
- 1;
8741 if (iocp
->ioc_count
!= pioc_size
)
8744 flags
= pioc
->mpr_flags
;
8745 if (iocp
->ioc_cmd
== SIOCSETPROP
) {
8747 * One can either reset the value to it's default value or
8748 * change the current value or append/remove the value from
8749 * a multi-valued properties.
8751 if ((flags
& MOD_PROP_DEFAULT
) != MOD_PROP_DEFAULT
&&
8752 flags
!= MOD_PROP_ACTIVE
&&
8753 flags
!= (MOD_PROP_ACTIVE
|MOD_PROP_APPEND
) &&
8754 flags
!= (MOD_PROP_ACTIVE
|MOD_PROP_REMOVE
))
8757 ASSERT(iocp
->ioc_cmd
== SIOCGETPROP
);
8760 * One can retrieve only one kind of property information
8763 if ((flags
& MOD_PROP_ACTIVE
) != MOD_PROP_ACTIVE
&&
8764 (flags
& MOD_PROP_DEFAULT
) != MOD_PROP_DEFAULT
&&
8765 (flags
& MOD_PROP_POSSIBLE
) != MOD_PROP_POSSIBLE
&&
8766 (flags
& MOD_PROP_PERM
) != MOD_PROP_PERM
)
8774 * process the SIOC{SET|GET}PROP ioctl's
8778 ip_sioctl_getsetprop(queue_t
*q
, mblk_t
*mp
)
8780 struct iocblk
*iocp
= (struct iocblk
*)mp
->b_rptr
;
8781 mblk_t
*mp1
= mp
->b_cont
;
8782 mod_ioc_prop_t
*pioc
;
8783 mod_prop_info_t
*ptbl
= NULL
, *pinfo
= NULL
;
8790 ASSERT(q
->q_next
== NULL
);
8793 if (!getset_ioctl_checks(mp
)) {
8794 miocnak(q
, mp
, 0, EINVAL
);
8797 ipst
= CONNQ_TO_IPST(q
);
8798 stack
= ipst
->ips_netstack
;
8799 pioc
= (mod_ioc_prop_t
*)mp1
->b_rptr
;
8801 switch (pioc
->mpr_proto
) {
8803 case MOD_PROTO_IPV4
:
8804 case MOD_PROTO_IPV6
:
8805 ptbl
= ipst
->ips_propinfo_tbl
;
8807 case MOD_PROTO_RAWIP
:
8808 ptbl
= stack
->netstack_icmp
->is_propinfo_tbl
;
8811 ptbl
= stack
->netstack_tcp
->tcps_propinfo_tbl
;
8814 ptbl
= stack
->netstack_udp
->us_propinfo_tbl
;
8816 case MOD_PROTO_SCTP
:
8817 ptbl
= stack
->netstack_sctp
->sctps_propinfo_tbl
;
8820 miocnak(q
, mp
, 0, EINVAL
);
8824 pinfo
= mod_prop_lookup(ptbl
, pioc
->mpr_name
, pioc
->mpr_proto
);
8825 if (pinfo
== NULL
) {
8826 miocnak(q
, mp
, 0, ENOENT
);
8830 set
= (iocp
->ioc_cmd
== SIOCSETPROP
) ? B_TRUE
: B_FALSE
;
8831 if (set
&& pinfo
->mpi_setf
!= NULL
) {
8832 cr
= msg_getcred(mp
, NULL
);
8835 err
= pinfo
->mpi_setf(stack
, cr
, pinfo
, pioc
->mpr_ifname
,
8836 pioc
->mpr_val
, pioc
->mpr_flags
);
8837 } else if (!set
&& pinfo
->mpi_getf
!= NULL
) {
8838 err
= pinfo
->mpi_getf(stack
, pinfo
, pioc
->mpr_ifname
,
8839 pioc
->mpr_val
, pioc
->mpr_valsize
, pioc
->mpr_flags
);
8845 miocnak(q
, mp
, 0, err
);
8848 miocack(q
, mp
, 0, 0);
8849 else /* For get, we need to return back the data */
8850 miocack(q
, mp
, iocp
->ioc_count
, 0);
8855 * process the legacy ND_GET, ND_SET ioctl just for {ip|ip6}_forwarding
8856 * as several routing daemons have unfortunately used this 'unpublished'
8857 * but well-known ioctls.
8861 ip_process_legacy_nddprop(queue_t
*q
, mblk_t
*mp
)
8863 struct iocblk
*iocp
= (struct iocblk
*)mp
->b_rptr
;
8864 mblk_t
*mp1
= mp
->b_cont
;
8865 char *pname
, *pval
, *buf
;
8866 uint_t bufsize
, proto
;
8867 mod_prop_info_t
*pinfo
= NULL
;
8872 ipst
= CONNQ_TO_IPST(q
);
8874 if (iocp
->ioc_count
== 0 || mp1
== NULL
) {
8875 miocnak(q
, mp
, 0, EINVAL
);
8879 mp1
->b_datap
->db_lim
[-1] = '\0'; /* Force null termination */
8880 pval
= buf
= pname
= (char *)mp1
->b_rptr
;
8881 bufsize
= MBLKL(mp1
);
8883 if (strcmp(pname
, "ip_forwarding") == 0) {
8884 pname
= "forwarding";
8885 proto
= MOD_PROTO_IPV4
;
8886 } else if (strcmp(pname
, "ip6_forwarding") == 0) {
8887 pname
= "forwarding";
8888 proto
= MOD_PROTO_IPV6
;
8890 miocnak(q
, mp
, 0, EINVAL
);
8894 pinfo
= mod_prop_lookup(ipst
->ips_propinfo_tbl
, pname
, proto
);
8896 switch (iocp
->ioc_cmd
) {
8898 if ((err
= pinfo
->mpi_getf(ipst
->ips_netstack
, pinfo
, NULL
, buf
,
8899 bufsize
, 0)) == 0) {
8900 miocack(q
, mp
, iocp
->ioc_count
, 0);
8906 * buffer will have property name and value in the following
8908 * <property name>'\0'<property value>'\0', extract them;
8913 if (!*pval
|| pval
>= (char *)mp1
->b_wptr
) {
8915 } else if ((err
= pinfo
->mpi_setf(ipst
->ips_netstack
, NULL
,
8916 pinfo
, NULL
, pval
, 0)) == 0) {
8917 miocack(q
, mp
, 0, 0);
8925 miocnak(q
, mp
, 0, err
);
8929 * Wrapper function for resuming deferred ioctl processing
8930 * Used for SIOCGDSTINFO, SIOCGIP6ADDRPOLICY, SIOCGMSFILTER,
8931 * SIOCSMSFILTER, SIOCGIPMSFILTER, and SIOCSIPMSFILTER currently.
8935 ip_sioctl_copyin_resume(ipsq_t
*dummy_ipsq
, queue_t
*q
, mblk_t
*mp
,
8938 ip_sioctl_copyin_setup(q
, mp
);
8942 * ip_sioctl_copyin_setup is called by ip_wput_nondata with any M_IOCTL message
8943 * that arrives. Most of the IOCTLs are "socket" IOCTLs which we handle
8944 * in either I_STR or TRANSPARENT form, using the mi_copy facility.
8945 * We establish here the size of the block to be copied in. mi_copyin
8946 * arranges for this to happen, an processing continues in ip_wput_nondata with
8947 * an M_IOCDATA message.
8950 ip_sioctl_copyin_setup(queue_t
*q
, mblk_t
*mp
)
8953 struct iocblk
*iocp
= (struct iocblk
*)mp
->b_rptr
;
8954 ip_ioctl_cmd_t
*ipip
;
8959 ipst
= CONNQ_TO_IPST(q
);
8961 ipst
= ILLQ_TO_IPST(q
);
8963 ipip
= ip_sioctl_lookup(iocp
->ioc_cmd
);
8966 * The ioctl is not one we understand or own.
8967 * Pass it along to be processed down stream,
8968 * if this is a module instance of IP, else nak
8971 if (q
->q_next
== NULL
) {
8980 * If this is deferred, then we will do all the checks when we
8983 if ((iocp
->ioc_cmd
== SIOCGDSTINFO
||
8984 iocp
->ioc_cmd
== SIOCGIP6ADDRPOLICY
) && !ip6_asp_can_lookup(ipst
)) {
8985 ip6_asp_pending_op(q
, mp
, ip_sioctl_copyin_resume
);
8990 * Only allow a very small subset of IP ioctls on this stream if
8991 * IP is a module and not a driver. Allowing ioctls to be processed
8992 * in this case may cause assert failures or data corruption.
8993 * Typically G[L]IFFLAGS, SLIFNAME/IF_UNITSEL are the only few
8994 * ioctls allowed on an IP module stream, after which this stream
8995 * normally becomes a multiplexor (at which time the stream head
8996 * will fail all ioctls).
8998 if ((q
->q_next
!= NULL
) && !(ipip
->ipi_flags
& IPI_MODOK
)) {
9002 /* Make sure we have ioctl data to process. */
9003 if (mp
->b_cont
== NULL
&& !(ipip
->ipi_flags
& IPI_NULL_BCONT
))
9007 * Prefer dblk credential over ioctl credential; some synthesized
9008 * ioctls have kcred set because there's no way to crhold()
9009 * a credential in some contexts. (ioc_cr is not crfree() by
9010 * the framework; the caller of ioctl needs to hold the reference
9011 * for the duration of the call).
9013 cr
= msg_getcred(mp
, NULL
);
9017 /* Make sure normal users don't send down privileged ioctls */
9018 if ((ipip
->ipi_flags
& IPI_PRIV
) &&
9019 (cr
!= NULL
) && secpolicy_ip_config(cr
, B_TRUE
) != 0) {
9020 /* We checked the privilege earlier but log it here */
9021 miocnak(q
, mp
, 0, secpolicy_ip_config(cr
, B_FALSE
));
9026 * The ioctl command tables can only encode fixed length
9027 * ioctl data. If the length is variable, the table will
9028 * encode the length as zero. Such special cases are handled
9029 * below in the switch.
9031 if (ipip
->ipi_copyin_size
!= 0) {
9032 mi_copyin(q
, mp
, NULL
, ipip
->ipi_copyin_size
);
9036 switch (iocp
->ioc_cmd
) {
9040 * This IOCTL is hilarious. See comments in
9041 * ip_sioctl_get_ifconf for the story.
9043 if (iocp
->ioc_count
== TRANSPARENT
)
9044 copyin_size
= SIZEOF_STRUCT(ifconf
,
9047 copyin_size
= iocp
->ioc_count
;
9048 mi_copyin(q
, mp
, NULL
, copyin_size
);
9051 case O_SIOCGLIFCONF
:
9053 copyin_size
= SIZEOF_STRUCT(lifconf
, iocp
->ioc_flag
);
9054 mi_copyin(q
, mp
, NULL
, copyin_size
);
9058 copyin_size
= SIZEOF_STRUCT(lifsrcof
, iocp
->ioc_flag
);
9059 mi_copyin(q
, mp
, NULL
, copyin_size
);
9062 case SIOCGIP6ADDRPOLICY
:
9063 ip_sioctl_ip6addrpolicy(q
, mp
);
9064 ip6_asp_table_refrele(ipst
);
9067 case SIOCSIP6ADDRPOLICY
:
9068 ip_sioctl_ip6addrpolicy(q
, mp
);
9072 ip_sioctl_dstinfo(q
, mp
);
9073 ip6_asp_table_refrele(ipst
);
9078 ip_process_legacy_nddprop(q
, mp
);
9083 ip_sioctl_getsetprop(q
, mp
);
9091 * We treat non-persistent link similarly as the persistent
9092 * link case, in terms of plumbing/unplumbing, as well as
9093 * dynamic re-plumbing events indicator. See comments
9094 * in ip_sioctl_plink() for more.
9096 * Request can be enqueued in the 'ipsq' while waiting
9097 * to become exclusive. So bump up the conn ref.
9100 CONN_INC_REF(Q_TO_CONN(q
));
9101 CONN_INC_IOCTLREF(Q_TO_CONN(q
))
9103 ip_sioctl_plink(NULL
, q
, mp
, NULL
);
9107 ip_wput_ioctl(q
, mp
);
9111 /* The ioctl length varies depending on the ILB command. */
9112 copyin_size
= iocp
->ioc_count
;
9113 if (copyin_size
< sizeof (ilb_cmd_t
))
9115 mi_copyin(q
, mp
, NULL
, copyin_size
);
9119 cmn_err(CE_WARN
, "Unknown ioctl %d/0x%x slipped through.",
9120 iocp
->ioc_cmd
, iocp
->ioc_cmd
);
9124 if (mp
->b_cont
!= NULL
) {
9125 freemsg(mp
->b_cont
);
9128 iocp
->ioc_error
= EINVAL
;
9129 mp
->b_datap
->db_type
= M_IOCNAK
;
9130 iocp
->ioc_count
= 0;
9135 ip_sioctl_garp_reply(mblk_t
*mp
, ill_t
*ill
, void *hwaddr
, int flags
)
9138 struct xarpreq
*xar
;
9140 struct iocblk
*iocp
;
9141 int x_arp_ioctl
= B_FALSE
;
9143 char *storage
= NULL
;
9145 ASSERT(ill
!= NULL
);
9147 iocp
= (struct iocblk
*)mp
->b_rptr
;
9148 ASSERT(iocp
->ioc_cmd
== SIOCGXARP
|| iocp
->ioc_cmd
== SIOCGARP
);
9150 tmp
= (mp
->b_cont
)->b_cont
; /* xarpreq/arpreq */
9151 if ((iocp
->ioc_cmd
== SIOCGXARP
) ||
9152 (iocp
->ioc_cmd
== SIOCSXARP
)) {
9153 x_arp_ioctl
= B_TRUE
;
9154 xar
= (struct xarpreq
*)tmp
->b_rptr
;
9155 flagsp
= &xar
->xarp_flags
;
9156 storage
= xar
->xarp_ha
.sdl_data
;
9158 ar
= (struct arpreq
*)tmp
->b_rptr
;
9159 flagsp
= &ar
->arp_flags
;
9160 storage
= ar
->arp_ha
.sa_data
;
9164 * We're done if this is not an SIOCG{X}ARP
9167 storage
+= ill_xarp_info(&xar
->xarp_ha
, ill
);
9168 if ((ill
->ill_phys_addr_length
+ ill
->ill_name_length
) >
9169 sizeof (xar
->xarp_ha
.sdl_data
)) {
9170 iocp
->ioc_error
= EINVAL
;
9174 *flagsp
= ATF_INUSE
;
9176 * If /sbin/arp told us we are the authority using the "permanent"
9177 * flag, or if this is one of my addresses print "permanent"
9178 * in the /sbin/arp output.
9180 if ((flags
& NCE_F_MYADDR
) || (flags
& NCE_F_AUTHORITY
))
9181 *flagsp
|= ATF_AUTHORITY
;
9182 if (flags
& NCE_F_NONUD
)
9183 *flagsp
|= ATF_PERM
; /* not subject to aging */
9184 if (flags
& NCE_F_PUBLISH
)
9185 *flagsp
|= ATF_PUBL
;
9186 if (hwaddr
!= NULL
) {
9188 bcopy((char *)hwaddr
, storage
, ill
->ill_phys_addr_length
);
9193 * Create a new logical interface. If ipif_id is zero (i.e. not a logical
9194 * interface) create the next available logical interface for this
9195 * physical interface.
9196 * If ipif is NULL (i.e. the lookup didn't find one) attempt to create an
9197 * ipif with the specified name.
9199 * If the address family is not AF_UNSPEC then set the address as well.
9201 * If ip_sioctl_addr returns EINPROGRESS then the ioctl (the copyout)
9202 * is completed when the DL_BIND_ACK arrive in ip_rput_dlpi_writer.
9204 * Executed as a writer on the ill.
9205 * So no lock is needed to traverse the ipif chain, or examine the
9210 ip_sioctl_addif(ipif_t
*dummy_ipif
, sin_t
*dummy_sin
, queue_t
*q
, mblk_t
*mp
,
9211 ip_ioctl_cmd_t
*dummy_ipip
, void *dummy_ifreq
)
9214 struct lifreq
*lifr
;
9227 boolean_t found_sep
= B_FALSE
;
9230 ip_stack_t
*ipst
= CONNQ_TO_IPST(q
);
9232 ASSERT(q
->q_next
== NULL
);
9233 ip1dbg(("ip_sioctl_addif\n"));
9234 /* Existence of mp1 has been checked in ip_wput_nondata */
9235 mp1
= mp
->b_cont
->b_cont
;
9237 * Null terminate the string to protect against buffer
9238 * overrun. String was generated by user code and may not
9241 lifr
= (struct lifreq
*)mp1
->b_rptr
;
9242 lifr
->lifr_name
[LIFNAMSIZ
- 1] = '\0';
9243 name
= lifr
->lifr_name
;
9245 connp
= Q_TO_CONN(q
);
9246 isv6
= (connp
->conn_family
== AF_INET6
);
9247 zoneid
= connp
->conn_zoneid
;
9248 namelen
= mi_strlen(name
);
9253 if ((namelen
+ 1 == sizeof (ipif_loopback_name
)) &&
9254 (mi_strcmp(name
, ipif_loopback_name
) == 0)) {
9256 * Allow creating lo0 using SIOCLIFADDIF.
9257 * can't be any other writer thread. So can pass null below
9258 * for the last 4 args to ipif_lookup_name.
9260 ipif
= ipif_lookup_on_name(lifr
->lifr_name
, namelen
, B_TRUE
,
9261 &exists
, isv6
, zoneid
, ipst
);
9262 /* Prevent any further action */
9265 } else if (!exists
) {
9266 /* We created the ipif now and as writer */
9270 ill
= ipif
->ipif_ill
;
9275 /* Look for a colon in the name. */
9276 endp
= &name
[namelen
];
9277 for (cp
= endp
; --cp
> name
; ) {
9278 if (*cp
== IPIF_SEPARATOR_CHAR
) {
9281 * Reject any non-decimal aliases for plumbing
9282 * of logical interfaces. Aliases with leading
9283 * zeroes are also rejected as they introduce
9284 * ambiguity in the naming of the interfaces.
9285 * Comparing with "0" takes care of all such
9288 if ((strncmp("0", cp
+1, 1)) == 0)
9291 if (ddi_strtol(cp
+1, &endp
, 10, &id
) != 0 ||
9292 id
<= 0 || *endp
!= '\0') {
9299 ill
= ill_lookup_on_name(name
, B_FALSE
, isv6
, NULL
, ipst
);
9301 *cp
= IPIF_SEPARATOR_CHAR
;
9306 ipsq
= ipsq_try_enter(NULL
, ill
, q
, mp
, ip_process_ioctl
, NEW_OP
,
9310 * Release the refhold due to the lookup, now that we are excl
9311 * or we are just returning
9316 return (EINPROGRESS
);
9318 /* We are now exclusive on the IPSQ */
9319 ASSERT(IAM_WRITER_ILL(ill
));
9322 /* Now see if there is an IPIF with this unit number. */
9323 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
9324 ipif
= ipif
->ipif_next
) {
9325 if (ipif
->ipif_id
== id
) {
9333 * We use IRE_LOCAL for lo0:1 etc. for "receive only" use
9334 * of lo0. Plumbing for lo0:0 happens in ipif_lookup_on_name()
9337 if ((ipif
= ipif_allocate(ill
, found_sep
? id
: -1, IRE_LOCAL
,
9338 B_TRUE
, B_TRUE
, &err
)) == NULL
) {
9342 /* Return created name with ioctl */
9343 (void) sprintf(lifr
->lifr_name
, "%s%c%d", ill
->ill_name
,
9344 IPIF_SEPARATOR_CHAR
, ipif
->ipif_id
);
9345 ip1dbg(("created %s\n", lifr
->lifr_name
));
9348 sin
= (sin_t
*)&lifr
->lifr_addr
;
9349 if (sin
->sin_family
!= AF_UNSPEC
) {
9350 err
= ip_sioctl_addr(ipif
, sin
, q
, mp
,
9351 &ip_ndx_ioctl_table
[SIOCLIFADDR_NDX
], lifr
);
9360 * Remove an existing logical interface. If ipif_id is zero (i.e. not a logical
9361 * interface) delete it based on the IP address (on this physical interface).
9362 * Otherwise delete it based on the ipif_id.
9363 * Also, special handling to allow a removeif of lo0.
9367 ip_sioctl_removeif(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
9368 ip_ioctl_cmd_t
*ipip
, void *dummy_if_req
)
9371 ill_t
*ill
= ipif
->ipif_ill
;
9375 ipst
= CONNQ_TO_IPST(q
);
9377 ASSERT(q
->q_next
== NULL
);
9378 ip1dbg(("ip_sioctl_remove_if(%s:%u %p)\n",
9379 ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
9380 ASSERT(IAM_WRITER_IPIF(ipif
));
9382 connp
= Q_TO_CONN(q
);
9384 * Special case for unplumbing lo0 (the loopback physical interface).
9385 * If unplumbing lo0, the incoming address structure has been
9386 * initialized to all zeros. When unplumbing lo0, all its logical
9387 * interfaces must be removed too.
9389 * Note that this interface may be called to remove a specific
9390 * loopback logical interface (eg, lo0:1). But in that case
9391 * ipif->ipif_id != 0 so that the code path for that case is the
9392 * same as any other interface (meaning it skips the code directly
9395 if (ipif
->ipif_id
== 0 && ill
->ill_net_type
== IRE_LOOPBACK
) {
9396 if (sin
->sin_family
== AF_UNSPEC
&&
9397 (IN6_IS_ADDR_UNSPECIFIED(&((sin6_t
*)sin
)->sin6_addr
))) {
9399 * Mark it condemned. No new ref. will be made to ill.
9401 mutex_enter(&ill
->ill_lock
);
9402 ill
->ill_state_flags
|= ILL_CONDEMNED
;
9403 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
9404 ipif
= ipif
->ipif_next
) {
9405 ipif
->ipif_state_flags
|= IPIF_CONDEMNED
;
9407 mutex_exit(&ill
->ill_lock
);
9409 ipif
= ill
->ill_ipif
;
9410 /* unplumb the loopback interface */
9412 mutex_enter(&connp
->conn_lock
);
9413 mutex_enter(&ill
->ill_lock
);
9415 /* Are any references to this ill active */
9416 if (ill_is_freeable(ill
)) {
9417 mutex_exit(&ill
->ill_lock
);
9418 mutex_exit(&connp
->conn_lock
);
9419 ill_delete_tail(ill
);
9423 success
= ipsq_pending_mp_add(connp
, ipif
,
9424 CONNP_TO_WQ(connp
), mp
, ILL_FREE
);
9425 mutex_exit(&connp
->conn_lock
);
9426 mutex_exit(&ill
->ill_lock
);
9428 return (EINPROGRESS
);
9434 if (ipif
->ipif_id
== 0) {
9437 /* Find based on address */
9438 if (ipif
->ipif_isv6
) {
9441 if (sin
->sin_family
!= AF_INET6
)
9442 return (EAFNOSUPPORT
);
9444 sin6
= (sin6_t
*)sin
;
9445 /* We are a writer, so we should be able to lookup */
9446 ipif
= ipif_lookup_addr_exact_v6(&sin6
->sin6_addr
, ill
,
9449 if (sin
->sin_family
!= AF_INET
)
9450 return (EAFNOSUPPORT
);
9452 /* We are a writer, so we should be able to lookup */
9453 ipif
= ipif_lookup_addr_exact(sin
->sin_addr
.s_addr
, ill
,
9457 return (EADDRNOTAVAIL
);
9461 * It is possible for a user to send an SIOCLIFREMOVEIF with
9462 * lifr_name of the physical interface but with an ip address
9463 * lifr_addr of a logical interface plumbed over it.
9464 * So update ipx_current_ipif now that ipif points to the
9467 ipsq
= ipif
->ipif_ill
->ill_phyint
->phyint_ipsq
;
9468 ipsq
->ipsq_xop
->ipx_current_ipif
= ipif
;
9470 /* This is a writer */
9475 * Can not delete instance zero since it is tied to the ill.
9477 if (ipif
->ipif_id
== 0)
9480 mutex_enter(&ill
->ill_lock
);
9481 ipif
->ipif_state_flags
|= IPIF_CONDEMNED
;
9482 mutex_exit(&ill
->ill_lock
);
9486 mutex_enter(&connp
->conn_lock
);
9487 mutex_enter(&ill
->ill_lock
);
9489 /* Are any references to this ipif active */
9490 if (ipif_is_freeable(ipif
)) {
9491 mutex_exit(&ill
->ill_lock
);
9492 mutex_exit(&connp
->conn_lock
);
9493 ipif_non_duplicate(ipif
);
9494 (void) ipif_down_tail(ipif
);
9495 ipif_free_tail(ipif
); /* frees ipif */
9498 success
= ipsq_pending_mp_add(connp
, ipif
, CONNP_TO_WQ(connp
), mp
,
9500 mutex_exit(&ill
->ill_lock
);
9501 mutex_exit(&connp
->conn_lock
);
9503 return (EINPROGRESS
);
9509 * Restart the removeif ioctl. The refcnt has gone down to 0.
9510 * The ipif is already condemned. So can't find it thru lookups.
9514 ip_sioctl_removeif_restart(ipif_t
*ipif
, sin_t
*dummy_sin
, queue_t
*q
,
9515 mblk_t
*mp
, ip_ioctl_cmd_t
*ipip
, void *dummy_if_req
)
9517 ill_t
*ill
= ipif
->ipif_ill
;
9519 ASSERT(IAM_WRITER_IPIF(ipif
));
9520 ASSERT(ipif
->ipif_state_flags
& IPIF_CONDEMNED
);
9522 ip1dbg(("ip_sioctl_removeif_restart(%s:%u %p)\n",
9523 ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
9525 if (ipif
->ipif_id
== 0 && ill
->ill_net_type
== IRE_LOOPBACK
) {
9526 ASSERT(ill
->ill_state_flags
& ILL_CONDEMNED
);
9527 ill_delete_tail(ill
);
9532 ipif_non_duplicate(ipif
);
9533 (void) ipif_down_tail(ipif
);
9534 ipif_free_tail(ipif
);
9540 * Set the local interface address using the given prefix and ill_token.
9544 ip_sioctl_prefix(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
9545 ip_ioctl_cmd_t
*dummy_ipip
, void *dummy_ifreq
)
9553 ip1dbg(("ip_sioctl_prefix(%s:%u %p)\n",
9554 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
9556 ASSERT(IAM_WRITER_IPIF(ipif
));
9558 if (!ipif
->ipif_isv6
)
9561 if (sin
->sin_family
!= AF_INET6
)
9562 return (EAFNOSUPPORT
);
9564 sin6
= (sin6_t
*)sin
;
9565 v6addr
= sin6
->sin6_addr
;
9566 ill
= ipif
->ipif_ill
;
9568 if (IN6_IS_ADDR_UNSPECIFIED(&v6addr
) ||
9569 IN6_IS_ADDR_UNSPECIFIED(&ill
->ill_token
))
9570 return (EADDRNOTAVAIL
);
9572 for (i
= 0; i
< 4; i
++)
9573 sin6
->sin6_addr
.s6_addr32
[i
] |= ill
->ill_token
.s6_addr32
[i
];
9575 err
= ip_sioctl_addr(ipif
, sin
, q
, mp
,
9576 &ip_ndx_ioctl_table
[SIOCLIFADDR_NDX
], dummy_ifreq
);
9581 * Restart entry point to restart the address set operation after the
9582 * refcounts have dropped to zero.
9586 ip_sioctl_prefix_restart(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
9587 ip_ioctl_cmd_t
*ipip
, void *ifreq
)
9589 ip1dbg(("ip_sioctl_prefix_restart(%s:%u %p)\n",
9590 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
9591 return (ip_sioctl_addr_restart(ipif
, sin
, q
, mp
, ipip
, ifreq
));
9595 * Set the local interface address.
9596 * Allow an address of all zero when the interface is down.
9600 ip_sioctl_addr(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
9601 ip_ioctl_cmd_t
*dummy_ipip
, void *dummy_ifreq
)
9605 boolean_t need_up
= B_FALSE
;
9609 ip1dbg(("ip_sioctl_addr(%s:%u %p)\n",
9610 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
9612 ASSERT(IAM_WRITER_IPIF(ipif
));
9614 ill
= ipif
->ipif_ill
;
9615 if (ipif
->ipif_isv6
) {
9619 if (sin
->sin_family
!= AF_INET6
)
9620 return (EAFNOSUPPORT
);
9622 sin6
= (sin6_t
*)sin
;
9623 v6addr
= sin6
->sin6_addr
;
9624 phyi
= ill
->ill_phyint
;
9627 * Enforce that true multicast interfaces have a link-local
9628 * address for logical unit 0.
9630 * However for those ipif's for which link-local address was
9631 * not created by default, also allow setting :: as the address.
9632 * This scenario would arise, when we delete an address on ipif
9633 * with logical unit 0, we would want to set :: as the address.
9635 if (ipif
->ipif_id
== 0 &&
9636 (ill
->ill_flags
& ILLF_MULTICAST
) &&
9637 !(ipif
->ipif_flags
& (IPIF_POINTOPOINT
)) &&
9638 !(phyi
->phyint_flags
& (PHYI_LOOPBACK
)) &&
9639 !IN6_IS_ADDR_LINKLOCAL(&v6addr
)) {
9642 * if default link-local was not created by kernel for
9643 * this ill, allow setting :: as the address on ipif:0.
9645 if (ill
->ill_flags
& ILLF_NOLINKLOCAL
) {
9646 if (!IN6_IS_ADDR_UNSPECIFIED(&v6addr
))
9647 return (EADDRNOTAVAIL
);
9649 return (EADDRNOTAVAIL
);
9654 * up interfaces shouldn't have the unspecified address
9655 * unless they also have the IPIF_NOLOCAL flags set and
9656 * have a subnet assigned.
9658 if ((ipif
->ipif_flags
& IPIF_UP
) &&
9659 IN6_IS_ADDR_UNSPECIFIED(&v6addr
) &&
9660 (!(ipif
->ipif_flags
& IPIF_NOLOCAL
) ||
9661 IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6subnet
))) {
9662 return (EADDRNOTAVAIL
);
9665 if (!ip_local_addr_ok_v6(&v6addr
, &ipif
->ipif_v6net_mask
))
9666 return (EADDRNOTAVAIL
);
9670 if (sin
->sin_family
!= AF_INET
)
9671 return (EAFNOSUPPORT
);
9673 addr
= sin
->sin_addr
.s_addr
;
9675 /* Allow INADDR_ANY as the local address. */
9676 if (addr
!= INADDR_ANY
&&
9677 !ip_addr_ok_v4(addr
, ipif
->ipif_net_mask
))
9678 return (EADDRNOTAVAIL
);
9680 IN6_IPADDR_TO_V4MAPPED(addr
, &v6addr
);
9683 * verify that the address being configured is permitted by the
9684 * ill_allowed_ips[] for the interface.
9686 if (ill
->ill_allowed_ips_cnt
> 0) {
9687 for (i
= 0; i
< ill
->ill_allowed_ips_cnt
; i
++) {
9688 if (IN6_ARE_ADDR_EQUAL(&ill
->ill_allowed_ips
[i
],
9692 if (i
== ill
->ill_allowed_ips_cnt
) {
9693 pr_addr_dbg("!allowed addr %s\n", AF_INET6
, &v6addr
);
9698 * Even if there is no change we redo things just to rerun
9701 if (ipif
->ipif_flags
& IPIF_UP
) {
9703 * Setting a new local address, make sure
9704 * we have net and subnet bcast ire's for
9705 * the old address if we need them.
9708 * If the interface is already marked up,
9709 * we call ipif_down which will take care
9710 * of ditching any IREs that have been set
9711 * up based on the old interface address.
9713 err
= ipif_logical_down(ipif
, q
, mp
);
9714 if (err
== EINPROGRESS
)
9716 (void) ipif_down_tail(ipif
);
9720 err
= ip_sioctl_addr_tail(ipif
, sin
, q
, mp
, need_up
);
9725 ip_sioctl_addr_tail(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
9734 ill_t
*ill
= ipif
->ipif_ill
;
9735 boolean_t need_dl_down
;
9736 boolean_t need_arp_down
;
9737 struct iocblk
*iocp
;
9739 iocp
= (mp
!= NULL
) ? (struct iocblk
*)mp
->b_rptr
: NULL
;
9741 ip1dbg(("ip_sioctl_addr_tail(%s:%u %p)\n",
9742 ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
9743 ASSERT(IAM_WRITER_IPIF(ipif
));
9745 /* Must cancel any pending timer before taking the ill_lock */
9746 if (ipif
->ipif_recovery_id
!= 0)
9747 (void) untimeout(ipif
->ipif_recovery_id
);
9748 ipif
->ipif_recovery_id
= 0;
9750 if (ipif
->ipif_isv6
) {
9751 sin6
= (sin6_t
*)sin
;
9752 v6addr
= sin6
->sin6_addr
;
9753 sinlen
= sizeof (struct sockaddr_in6
);
9755 addr
= sin
->sin_addr
.s_addr
;
9756 IN6_IPADDR_TO_V4MAPPED(addr
, &v6addr
);
9757 sinlen
= sizeof (struct sockaddr_in
);
9759 mutex_enter(&ill
->ill_lock
);
9760 ov6addr
= ipif
->ipif_v6lcl_addr
;
9761 ipif
->ipif_v6lcl_addr
= v6addr
;
9762 sctp_update_ipif_addr(ipif
, ov6addr
);
9763 ipif
->ipif_addr_ready
= 0;
9765 ip_rts_newaddrmsg(RTM_CHGADDR
, 0, ipif
, RTSQ_DEFAULT
);
9768 * If the interface was previously marked as a duplicate, then since
9769 * we've now got a "new" address, it should no longer be considered a
9770 * duplicate -- even if the "new" address is the same as the old one.
9771 * Note that if all ipifs are down, we may have a pending ARP down
9772 * event to handle. This is because we want to recover from duplicates
9773 * and thus delay tearing down ARP until the duplicates have been
9774 * removed or disabled.
9776 need_dl_down
= need_arp_down
= B_FALSE
;
9777 if (ipif
->ipif_flags
& IPIF_DUPLICATE
) {
9778 need_arp_down
= !need_up
;
9779 ipif
->ipif_flags
&= ~IPIF_DUPLICATE
;
9780 if (--ill
->ill_ipif_dup_count
== 0 && !need_up
&&
9781 ill
->ill_ipif_up_count
== 0 && ill
->ill_dl_up
) {
9782 need_dl_down
= B_TRUE
;
9786 ipif_set_default(ipif
);
9789 * If we've just manually set the IPv6 link-local address (0th ipif),
9790 * tag the ill so that future updates to the interface ID don't result
9791 * in this address getting automatically reconfigured from under the
9794 if (ipif
->ipif_isv6
&& ipif
->ipif_id
== 0) {
9795 if (iocp
== NULL
|| (iocp
->ioc_cmd
== SIOCSLIFADDR
&&
9796 !IN6_IS_ADDR_UNSPECIFIED(&v6addr
)))
9797 ill
->ill_manual_linklocal
= 1;
9801 * When publishing an interface address change event, we only notify
9802 * the event listeners of the new address. It is assumed that if they
9803 * actively care about the addresses assigned that they will have
9804 * already discovered the previous address assigned (if there was one.)
9806 * Don't attach nic event message for SIOCLIFADDIF ioctl.
9808 if (iocp
!= NULL
&& iocp
->ioc_cmd
!= SIOCLIFADDIF
) {
9809 ill_nic_event_dispatch(ill
, MAP_IPIF_ID(ipif
->ipif_id
),
9810 NE_ADDRESS_CHANGE
, sin
, sinlen
);
9813 mutex_exit(&ill
->ill_lock
);
9817 * Now bring the interface back up. If this
9818 * is the only IPIF for the ILL, ipif_up
9819 * will have to re-bind to the device, so
9820 * we may get back EINPROGRESS, in which
9821 * case, this IOCTL will get completed in
9822 * ip_rput_dlpi when we see the DL_BIND_ACK.
9824 err
= ipif_up(ipif
, q
, mp
);
9826 /* Perhaps ilgs should use this ill */
9827 update_conn_ill(NULL
, ill
->ill_ipst
);
9833 if (need_arp_down
&& !ill
->ill_isv6
)
9834 (void) ipif_arp_down(ipif
);
9837 * The default multicast interface might have changed (for
9838 * instance if the IPv6 scope of the address changed)
9840 ire_increment_multicast_generation(ill
->ill_ipst
, ill
->ill_isv6
);
9846 * Restart entry point to restart the address set operation after the
9847 * refcounts have dropped to zero.
9851 ip_sioctl_addr_restart(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
9852 ip_ioctl_cmd_t
*ipip
, void *ifreq
)
9854 ip1dbg(("ip_sioctl_addr_restart(%s:%u %p)\n",
9855 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
9856 ASSERT(IAM_WRITER_IPIF(ipif
));
9857 (void) ipif_down_tail(ipif
);
9858 return (ip_sioctl_addr_tail(ipif
, sin
, q
, mp
, B_TRUE
));
9863 ip_sioctl_get_addr(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
9864 ip_ioctl_cmd_t
*ipip
, void *if_req
)
9866 sin6_t
*sin6
= (struct sockaddr_in6
*)sin
;
9867 struct lifreq
*lifr
= (struct lifreq
*)if_req
;
9869 ip1dbg(("ip_sioctl_get_addr(%s:%u %p)\n",
9870 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
9872 * The net mask and address can't change since we have a
9873 * reference to the ipif. So no lock is necessary.
9875 if (ipif
->ipif_isv6
) {
9877 sin6
->sin6_family
= AF_INET6
;
9878 sin6
->sin6_addr
= ipif
->ipif_v6lcl_addr
;
9879 if (IN6_IS_ADDR_LINKLOCAL(&sin6
->sin6_addr
)) {
9880 sin6
->sin6_scope_id
=
9881 ipif
->ipif_ill
->ill_phyint
->phyint_ifindex
;
9883 ASSERT(ipip
->ipi_cmd_type
== LIF_CMD
);
9884 lifr
->lifr_addrlen
=
9885 ip_mask_to_plen_v6(&ipif
->ipif_v6net_mask
);
9888 sin
->sin_family
= AF_INET
;
9889 sin
->sin_addr
.s_addr
= ipif
->ipif_lcl_addr
;
9890 if (ipip
->ipi_cmd_type
== LIF_CMD
) {
9891 lifr
->lifr_addrlen
=
9892 ip_mask_to_plen(ipif
->ipif_net_mask
);
9899 * Set the destination address for a pt-pt interface.
9903 ip_sioctl_dstaddr(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
9904 ip_ioctl_cmd_t
*ipip
, void *if_req
)
9908 boolean_t need_up
= B_FALSE
;
9910 ip1dbg(("ip_sioctl_dstaddr(%s:%u %p)\n",
9911 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
9912 ASSERT(IAM_WRITER_IPIF(ipif
));
9914 if (ipif
->ipif_isv6
) {
9917 if (sin
->sin_family
!= AF_INET6
)
9918 return (EAFNOSUPPORT
);
9920 sin6
= (sin6_t
*)sin
;
9921 v6addr
= sin6
->sin6_addr
;
9923 if (!ip_remote_addr_ok_v6(&v6addr
, &ipif
->ipif_v6net_mask
))
9924 return (EADDRNOTAVAIL
);
9928 if (sin
->sin_family
!= AF_INET
)
9929 return (EAFNOSUPPORT
);
9931 addr
= sin
->sin_addr
.s_addr
;
9932 if (addr
!= INADDR_ANY
&&
9933 !ip_addr_ok_v4(addr
, ipif
->ipif_net_mask
)) {
9934 return (EADDRNOTAVAIL
);
9937 IN6_IPADDR_TO_V4MAPPED(addr
, &v6addr
);
9940 if (IN6_ARE_ADDR_EQUAL(&ipif
->ipif_v6pp_dst_addr
, &v6addr
))
9941 return (0); /* No change */
9943 if (ipif
->ipif_flags
& IPIF_UP
) {
9945 * If the interface is already marked up,
9946 * we call ipif_down which will take care
9947 * of ditching any IREs that have been set
9948 * up based on the old pp dst address.
9950 err
= ipif_logical_down(ipif
, q
, mp
);
9951 if (err
== EINPROGRESS
)
9953 (void) ipif_down_tail(ipif
);
9957 * could return EINPROGRESS. If so ioctl will complete in
9958 * ip_rput_dlpi_writer
9960 err
= ip_sioctl_dstaddr_tail(ipif
, sin
, q
, mp
, need_up
);
9965 ip_sioctl_dstaddr_tail(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
9969 ill_t
*ill
= ipif
->ipif_ill
;
9971 boolean_t need_dl_down
;
9972 boolean_t need_arp_down
;
9974 ip1dbg(("ip_sioctl_dstaddr_tail(%s:%u %p)\n", ill
->ill_name
,
9975 ipif
->ipif_id
, (void *)ipif
));
9977 /* Must cancel any pending timer before taking the ill_lock */
9978 if (ipif
->ipif_recovery_id
!= 0)
9979 (void) untimeout(ipif
->ipif_recovery_id
);
9980 ipif
->ipif_recovery_id
= 0;
9982 if (ipif
->ipif_isv6
) {
9985 sin6
= (sin6_t
*)sin
;
9986 v6addr
= sin6
->sin6_addr
;
9990 addr
= sin
->sin_addr
.s_addr
;
9991 IN6_IPADDR_TO_V4MAPPED(addr
, &v6addr
);
9993 mutex_enter(&ill
->ill_lock
);
9994 /* Set point to point destination address. */
9995 if ((ipif
->ipif_flags
& IPIF_POINTOPOINT
) == 0) {
9997 * Allow this as a means of creating logical
9998 * pt-pt interfaces on top of e.g. an Ethernet.
9999 * XXX Undocumented HACK for testing.
10000 * pt-pt interfaces are created with NUD disabled.
10002 ipif
->ipif_flags
|= IPIF_POINTOPOINT
;
10003 ipif
->ipif_flags
&= ~IPIF_BROADCAST
;
10004 if (ipif
->ipif_isv6
)
10005 ill
->ill_flags
|= ILLF_NONUD
;
10009 * If the interface was previously marked as a duplicate, then since
10010 * we've now got a "new" address, it should no longer be considered a
10011 * duplicate -- even if the "new" address is the same as the old one.
10012 * Note that if all ipifs are down, we may have a pending ARP down
10015 need_dl_down
= need_arp_down
= B_FALSE
;
10016 if (ipif
->ipif_flags
& IPIF_DUPLICATE
) {
10017 need_arp_down
= !need_up
;
10018 ipif
->ipif_flags
&= ~IPIF_DUPLICATE
;
10019 if (--ill
->ill_ipif_dup_count
== 0 && !need_up
&&
10020 ill
->ill_ipif_up_count
== 0 && ill
->ill_dl_up
) {
10021 need_dl_down
= B_TRUE
;
10026 * If we've just manually set the IPv6 destination link-local address
10027 * (0th ipif), tag the ill so that future updates to the destination
10028 * interface ID (as can happen with interfaces over IP tunnels) don't
10029 * result in this address getting automatically reconfigured from
10030 * under the administrator.
10032 if (ipif
->ipif_isv6
&& ipif
->ipif_id
== 0)
10033 ill
->ill_manual_dst_linklocal
= 1;
10035 /* Set the new address. */
10036 ipif
->ipif_v6pp_dst_addr
= v6addr
;
10037 /* Make sure subnet tracks pp_dst */
10038 ipif
->ipif_v6subnet
= ipif
->ipif_v6pp_dst_addr
;
10039 mutex_exit(&ill
->ill_lock
);
10043 * Now bring the interface back up. If this
10044 * is the only IPIF for the ILL, ipif_up
10045 * will have to re-bind to the device, so
10046 * we may get back EINPROGRESS, in which
10047 * case, this IOCTL will get completed in
10048 * ip_rput_dlpi when we see the DL_BIND_ACK.
10050 err
= ipif_up(ipif
, q
, mp
);
10055 if (need_arp_down
&& !ipif
->ipif_isv6
)
10056 (void) ipif_arp_down(ipif
);
10062 * Restart entry point to restart the dstaddress set operation after the
10063 * refcounts have dropped to zero.
10067 ip_sioctl_dstaddr_restart(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
10068 ip_ioctl_cmd_t
*ipip
, void *ifreq
)
10070 ip1dbg(("ip_sioctl_dstaddr_restart(%s:%u %p)\n",
10071 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
10072 (void) ipif_down_tail(ipif
);
10073 return (ip_sioctl_dstaddr_tail(ipif
, sin
, q
, mp
, B_TRUE
));
10078 ip_sioctl_get_dstaddr(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
10079 ip_ioctl_cmd_t
*ipip
, void *if_req
)
10081 sin6_t
*sin6
= (struct sockaddr_in6
*)sin
;
10083 ip1dbg(("ip_sioctl_get_dstaddr(%s:%u %p)\n",
10084 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
10086 * Get point to point destination address. The addresses can't
10087 * change since we hold a reference to the ipif.
10089 if ((ipif
->ipif_flags
& IPIF_POINTOPOINT
) == 0)
10090 return (EADDRNOTAVAIL
);
10092 if (ipif
->ipif_isv6
) {
10093 ASSERT(ipip
->ipi_cmd_type
== LIF_CMD
);
10095 sin6
->sin6_family
= AF_INET6
;
10096 sin6
->sin6_addr
= ipif
->ipif_v6pp_dst_addr
;
10099 sin
->sin_family
= AF_INET
;
10100 sin
->sin_addr
.s_addr
= ipif
->ipif_pp_dst_addr
;
10106 * Check which flags will change by the given flags being set
10107 * silently ignore flags which userland is not allowed to control.
10108 * (Because these flags may change between SIOCGLIFFLAGS and
10109 * SIOCSLIFFLAGS, and that's outside of userland's control,
10110 * we need to silently ignore them rather than fail.)
10113 ip_sioctl_flags_onoff(ipif_t
*ipif
, uint64_t flags
, uint64_t *onp
,
10116 ill_t
*ill
= ipif
->ipif_ill
;
10117 phyint_t
*phyi
= ill
->ill_phyint
;
10118 uint64_t cantchange_flags
, intf_flags
;
10119 uint64_t turn_on
, turn_off
;
10121 intf_flags
= ipif
->ipif_flags
| ill
->ill_flags
| phyi
->phyint_flags
;
10122 cantchange_flags
= IFF_CANTCHANGE
;
10124 cantchange_flags
|= IFF_IPMP_CANTCHANGE
;
10125 turn_on
= (flags
^ intf_flags
) & ~cantchange_flags
;
10126 turn_off
= intf_flags
& turn_on
;
10127 turn_on
^= turn_off
;
10133 * Set interface flags. Many flags require special handling (e.g.,
10134 * bringing the interface down); see below for details.
10136 * NOTE : We really don't enforce that ipif_id zero should be used
10137 * for setting any flags other than IFF_LOGINT_FLAGS. This
10138 * is because applications generally does SICGLIFFLAGS and
10139 * ORs in the new flags (that affects the logical) and does a
10140 * SIOCSLIFFLAGS. Thus, "flags" below could contain bits other
10141 * than IFF_LOGINT_FLAGS. One could check whether "turn_on" - the
10142 * flags that will be turned on is correct with respect to
10143 * ipif_id 0. For backward compatibility reasons, it is not done.
10147 ip_sioctl_flags(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
10148 ip_ioctl_cmd_t
*ipip
, void *if_req
)
10156 uint64_t intf_flags
;
10157 boolean_t phyint_flags_modified
= B_FALSE
;
10160 struct lifreq
*lifr
;
10161 boolean_t set_linklocal
= B_FALSE
;
10163 ip1dbg(("ip_sioctl_flags(%s:%u %p)\n",
10164 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
10166 ASSERT(IAM_WRITER_IPIF(ipif
));
10168 ill
= ipif
->ipif_ill
;
10169 phyi
= ill
->ill_phyint
;
10171 if (ipip
->ipi_cmd_type
== IF_CMD
) {
10172 ifr
= (struct ifreq
*)if_req
;
10173 flags
= (uint64_t)(ifr
->ifr_flags
& 0x0000ffff);
10175 lifr
= (struct lifreq
*)if_req
;
10176 flags
= lifr
->lifr_flags
;
10179 intf_flags
= ipif
->ipif_flags
| ill
->ill_flags
| phyi
->phyint_flags
;
10182 * Have the flags been set correctly until now?
10184 ASSERT((phyi
->phyint_flags
& ~(IFF_PHYINT_FLAGS
)) == 0);
10185 ASSERT((ill
->ill_flags
& ~(IFF_PHYINTINST_FLAGS
)) == 0);
10186 ASSERT((ipif
->ipif_flags
& ~(IFF_LOGINT_FLAGS
)) == 0);
10188 * Compare the new flags to the old, and partition
10189 * into those coming on and those going off.
10190 * For the 16 bit command keep the bits above bit 16 unchanged.
10192 if (ipip
->ipi_cmd
== SIOCSIFFLAGS
)
10193 flags
|= intf_flags
& ~0xFFFF;
10196 * Explicitly fail attempts to change flags that are always invalid on
10197 * an IPMP meta-interface.
10199 if (IS_IPMP(ill
) && ((flags
^ intf_flags
) & IFF_IPMP_INVALID
))
10202 ip_sioctl_flags_onoff(ipif
, flags
, &turn_on
, &turn_off
);
10203 if ((turn_on
|turn_off
) == 0)
10204 return (0); /* No change */
10207 * All test addresses must be IFF_DEPRECATED (to ensure source address
10208 * selection avoids them) -- so force IFF_DEPRECATED on, and do not
10209 * allow it to be turned off.
10211 if ((turn_off
& (IFF_DEPRECATED
|IFF_NOFAILOVER
)) == IFF_DEPRECATED
&&
10212 (turn_on
|intf_flags
) & IFF_NOFAILOVER
)
10215 if ((connp
= Q_TO_CONN(q
)) == NULL
)
10219 * Only vrrp control socket is allowed to change IFF_UP and
10220 * IFF_NOACCEPT flags when IFF_VRRP is set.
10222 if ((intf_flags
& IFF_VRRP
) && ((turn_off
| turn_on
) & IFF_UP
)) {
10223 if (!connp
->conn_isvrrp
)
10228 * The IFF_NOACCEPT flag can only be set on an IFF_VRRP IP address by
10229 * VRRP control socket.
10231 if ((turn_off
| turn_on
) & IFF_NOACCEPT
) {
10232 if (!connp
->conn_isvrrp
|| !(intf_flags
& IFF_VRRP
))
10236 if (turn_on
& IFF_NOFAILOVER
) {
10237 turn_on
|= IFF_DEPRECATED
;
10238 flags
|= IFF_DEPRECATED
;
10242 * On underlying interfaces, only allow applications to manage test
10243 * addresses -- otherwise, they may get confused when the address
10244 * moves as part of being brought up. Likewise, prevent an
10245 * application-managed test address from being converted to a data
10246 * address. To prevent migration of administratively up addresses in
10247 * the kernel, we don't allow them to be converted either.
10249 if (IS_UNDER_IPMP(ill
)) {
10250 const uint64_t appflags
= IFF_DHCPRUNNING
| IFF_ADDRCONF
;
10252 if ((turn_on
& appflags
) && !(flags
& IFF_NOFAILOVER
))
10255 if ((turn_off
& IFF_NOFAILOVER
) &&
10256 (flags
& (appflags
| IFF_UP
| IFF_DUPLICATE
)))
10261 * Only allow IFF_TEMPORARY flag to be set on
10264 if ((turn_on
& IFF_TEMPORARY
) && !(ipif
->ipif_isv6
))
10268 * cannot turn off IFF_NOXMIT on VNI interfaces.
10270 if ((turn_off
& IFF_NOXMIT
) && IS_VNI(ipif
->ipif_ill
))
10274 * Don't allow the IFF_ROUTER flag to be turned on on loopback
10275 * interfaces. It makes no sense in that context.
10277 if ((turn_on
& IFF_ROUTER
) && (phyi
->phyint_flags
& PHYI_LOOPBACK
))
10281 * For IPv6 ipif_id 0, don't allow the interface to be up without
10282 * a link local address if IFF_NOLOCAL or IFF_ANYCAST are not set.
10283 * If the link local address isn't set, and can be set, it will get
10284 * set later on in this function.
10286 if (ipif
->ipif_id
== 0 && ipif
->ipif_isv6
&&
10287 (flags
& IFF_UP
) && !(flags
& (IFF_NOLOCAL
|IFF_ANYCAST
)) &&
10288 IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6lcl_addr
)) {
10289 if (ipif_cant_setlinklocal(ipif
))
10291 set_linklocal
= B_TRUE
;
10295 * If we modify physical interface flags, we'll potentially need to
10296 * send up two routing socket messages for the changes (one for the
10297 * IPv4 ill, and another for the IPv6 ill). Note that here.
10299 if ((turn_on
|turn_off
) & IFF_PHYINT_FLAGS
)
10300 phyint_flags_modified
= B_TRUE
;
10303 * All functioning PHYI_STANDBY interfaces start life PHYI_INACTIVE
10304 * (otherwise, we'd immediately use them, defeating standby). Also,
10305 * since PHYI_INACTIVE has a separate meaning when PHYI_STANDBY is not
10306 * set, don't allow PHYI_STANDBY to be set if PHYI_INACTIVE is already
10307 * set, and clear PHYI_INACTIVE if PHYI_STANDBY is being cleared. We
10308 * also don't allow PHYI_STANDBY if VNI is enabled since its semantics
10309 * will not be honored.
10311 if (turn_on
& PHYI_STANDBY
) {
10313 * No need to grab ill_g_usesrc_lock here; see the
10314 * synchronization notes in ip.c.
10316 if (ill
->ill_usesrc_grp_next
!= NULL
||
10317 intf_flags
& PHYI_INACTIVE
)
10319 if (!(flags
& PHYI_FAILED
)) {
10320 flags
|= PHYI_INACTIVE
;
10321 turn_on
|= PHYI_INACTIVE
;
10325 if (turn_off
& PHYI_STANDBY
) {
10326 flags
&= ~PHYI_INACTIVE
;
10327 turn_off
|= PHYI_INACTIVE
;
10331 * PHYI_FAILED and PHYI_INACTIVE are mutually exclusive; fail if both
10334 if ((flags
& (PHYI_FAILED
| PHYI_INACTIVE
)) ==
10335 (PHYI_FAILED
| PHYI_INACTIVE
))
10339 * If ILLF_ROUTER changes, we need to change the ip forwarding
10340 * status of the interface.
10342 if ((turn_on
| turn_off
) & ILLF_ROUTER
) {
10343 err
= ill_forward_set(ill
, ((turn_on
& ILLF_ROUTER
) != 0));
10349 * If the interface is not UP and we are not going to
10350 * bring it UP, record the flags and return. When the
10351 * interface comes UP later, the right actions will be
10354 if (!(ipif
->ipif_flags
& IPIF_UP
) &&
10355 !(turn_on
& IPIF_UP
)) {
10356 /* Record new flags in their respective places. */
10357 mutex_enter(&ill
->ill_lock
);
10358 mutex_enter(&ill
->ill_phyint
->phyint_lock
);
10359 ipif
->ipif_flags
|= (turn_on
& IFF_LOGINT_FLAGS
);
10360 ipif
->ipif_flags
&= (~turn_off
& IFF_LOGINT_FLAGS
);
10361 ill
->ill_flags
|= (turn_on
& IFF_PHYINTINST_FLAGS
);
10362 ill
->ill_flags
&= (~turn_off
& IFF_PHYINTINST_FLAGS
);
10363 phyi
->phyint_flags
|= (turn_on
& IFF_PHYINT_FLAGS
);
10364 phyi
->phyint_flags
&= (~turn_off
& IFF_PHYINT_FLAGS
);
10365 mutex_exit(&ill
->ill_lock
);
10366 mutex_exit(&ill
->ill_phyint
->phyint_lock
);
10369 * PHYI_FAILED, PHYI_INACTIVE, and PHYI_OFFLINE are all the
10370 * same to the kernel: if any of them has been set by
10371 * userland, the interface cannot be used for data traffic.
10373 if ((turn_on
|turn_off
) &
10374 (PHYI_FAILED
| PHYI_INACTIVE
| PHYI_OFFLINE
)) {
10375 ASSERT(!IS_IPMP(ill
));
10377 * It's possible the ill is part of an "anonymous"
10378 * IPMP group rather than a real group. In that case,
10379 * there are no other interfaces in the group and thus
10380 * no need to call ipmp_phyint_refresh_active().
10382 if (IS_UNDER_IPMP(ill
))
10383 ipmp_phyint_refresh_active(phyi
);
10386 if (phyint_flags_modified
) {
10387 if (phyi
->phyint_illv4
!= NULL
) {
10388 ip_rts_ifmsg(phyi
->phyint_illv4
->
10389 ill_ipif
, RTSQ_DEFAULT
);
10391 if (phyi
->phyint_illv6
!= NULL
) {
10392 ip_rts_ifmsg(phyi
->phyint_illv6
->
10393 ill_ipif
, RTSQ_DEFAULT
);
10396 /* The default multicast interface might have changed */
10397 ire_increment_multicast_generation(ill
->ill_ipst
,
10401 } else if (set_linklocal
) {
10402 mutex_enter(&ill
->ill_lock
);
10404 ipif
->ipif_state_flags
|= IPIF_SET_LINKLOCAL
;
10405 mutex_exit(&ill
->ill_lock
);
10409 * Disallow IPv6 interfaces coming up that have the unspecified address,
10410 * or point-to-point interfaces with an unspecified destination. We do
10411 * allow the address to be unspecified for IPIF_NOLOCAL interfaces that
10412 * have a subnet assigned, which is how in.ndpd currently manages its
10413 * onlink prefix list when no addresses are configured with those
10416 if (ipif
->ipif_isv6
&&
10417 ((IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6lcl_addr
) &&
10418 (!(ipif
->ipif_flags
& IPIF_NOLOCAL
) && !(turn_on
& IPIF_NOLOCAL
) ||
10419 IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6subnet
))) ||
10420 ((ipif
->ipif_flags
& IPIF_POINTOPOINT
) &&
10421 IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6pp_dst_addr
)))) {
10426 * Prevent IPv4 point-to-point interfaces with a 0.0.0.0 destination
10427 * from being brought up.
10429 if (!ipif
->ipif_isv6
&&
10430 ((ipif
->ipif_flags
& IPIF_POINTOPOINT
) &&
10431 ipif
->ipif_pp_dst_addr
== INADDR_ANY
)) {
10436 * If we are going to change one or more of the flags that are
10437 * IPIF_UP, IPIF_DEPRECATED, IPIF_NOXMIT, IPIF_NOLOCAL, ILLF_NOARP,
10438 * ILLF_NONUD, IPIF_PRIVATE, IPIF_ANYCAST, IPIF_PREFERRED, and
10439 * IPIF_NOFAILOVER, we will take special action. This is
10440 * done by bring the ipif down, changing the flags and bringing
10441 * it back up again. For IPIF_NOFAILOVER, the act of bringing it
10442 * back up will trigger the address to be moved.
10444 * If we are going to change IFF_NOACCEPT, we need to bring
10445 * all the ipifs down then bring them up again. The act of
10446 * bringing all the ipifs back up will trigger the local
10447 * ires being recreated with "no_accept" set/cleared.
10449 * Note that ILLF_NOACCEPT is always set separately from the
10452 if ((turn_on
|turn_off
) &
10453 (IPIF_UP
|IPIF_DEPRECATED
|IPIF_NOXMIT
|IPIF_NOLOCAL
|ILLF_NOARP
|
10454 ILLF_NONUD
|IPIF_PRIVATE
|IPIF_ANYCAST
|IPIF_PREFERRED
|
10455 IPIF_NOFAILOVER
)) {
10457 * ipif_down() will ire_delete bcast ire's for the subnet,
10458 * while the ire_identical_ref tracks the case of IRE_BROADCAST
10459 * entries shared between multiple ipifs on the same subnet.
10461 if (((ipif
->ipif_flags
| turn_on
) & IPIF_UP
) &&
10462 !(turn_off
& IPIF_UP
)) {
10463 if (ipif
->ipif_flags
& IPIF_UP
)
10464 ill
->ill_logical_down
= 1;
10465 turn_on
&= ~IPIF_UP
;
10467 err
= ipif_down(ipif
, q
, mp
);
10468 ip1dbg(("ipif_down returns %d err ", err
));
10469 if (err
== EINPROGRESS
)
10471 (void) ipif_down_tail(ipif
);
10472 } else if ((turn_on
|turn_off
) & ILLF_NOACCEPT
) {
10474 * If we can quiesce the ill, then continue. If not, then
10475 * ip_sioctl_flags_tail() will be called from
10476 * ipif_ill_refrele_tail().
10478 ill_down_ipifs(ill
, B_TRUE
);
10480 mutex_enter(&connp
->conn_lock
);
10481 mutex_enter(&ill
->ill_lock
);
10482 if (!ill_is_quiescent(ill
)) {
10485 success
= ipsq_pending_mp_add(connp
, ill
->ill_ipif
,
10487 mutex_exit(&ill
->ill_lock
);
10488 mutex_exit(&connp
->conn_lock
);
10489 return (success
? EINPROGRESS
: EINTR
);
10491 mutex_exit(&ill
->ill_lock
);
10492 mutex_exit(&connp
->conn_lock
);
10494 return (ip_sioctl_flags_tail(ipif
, flags
, q
, mp
));
10498 ip_sioctl_flags_tail(ipif_t
*ipif
, uint64_t flags
, queue_t
*q
, mblk_t
*mp
)
10502 uint64_t turn_on
, turn_off
;
10503 boolean_t phyint_flags_modified
= B_FALSE
;
10505 boolean_t set_linklocal
= B_FALSE
;
10507 ip1dbg(("ip_sioctl_flags_tail(%s:%u)\n",
10508 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
));
10510 ASSERT(IAM_WRITER_IPIF(ipif
));
10512 ill
= ipif
->ipif_ill
;
10513 phyi
= ill
->ill_phyint
;
10515 ip_sioctl_flags_onoff(ipif
, flags
, &turn_on
, &turn_off
);
10518 * IFF_UP is handled separately.
10520 turn_on
&= ~IFF_UP
;
10521 turn_off
&= ~IFF_UP
;
10523 if ((turn_on
|turn_off
) & IFF_PHYINT_FLAGS
)
10524 phyint_flags_modified
= B_TRUE
;
10527 * Now we change the flags. Track current value of
10528 * other flags in their respective places.
10530 mutex_enter(&ill
->ill_lock
);
10531 mutex_enter(&phyi
->phyint_lock
);
10532 ipif
->ipif_flags
|= (turn_on
& IFF_LOGINT_FLAGS
);
10533 ipif
->ipif_flags
&= (~turn_off
& IFF_LOGINT_FLAGS
);
10534 ill
->ill_flags
|= (turn_on
& IFF_PHYINTINST_FLAGS
);
10535 ill
->ill_flags
&= (~turn_off
& IFF_PHYINTINST_FLAGS
);
10536 phyi
->phyint_flags
|= (turn_on
& IFF_PHYINT_FLAGS
);
10537 phyi
->phyint_flags
&= (~turn_off
& IFF_PHYINT_FLAGS
);
10538 if (ipif
->ipif_state_flags
& IPIF_SET_LINKLOCAL
) {
10539 set_linklocal
= B_TRUE
;
10540 ipif
->ipif_state_flags
&= ~IPIF_SET_LINKLOCAL
;
10543 mutex_exit(&ill
->ill_lock
);
10544 mutex_exit(&phyi
->phyint_lock
);
10547 (void) ipif_setlinklocal(ipif
);
10550 * PHYI_FAILED, PHYI_INACTIVE, and PHYI_OFFLINE are all the same to
10551 * the kernel: if any of them has been set by userland, the interface
10552 * cannot be used for data traffic.
10554 if ((turn_on
|turn_off
) & (PHYI_FAILED
| PHYI_INACTIVE
| PHYI_OFFLINE
)) {
10555 ASSERT(!IS_IPMP(ill
));
10557 * It's possible the ill is part of an "anonymous" IPMP group
10558 * rather than a real group. In that case, there are no other
10559 * interfaces in the group and thus no need for us to call
10560 * ipmp_phyint_refresh_active().
10562 if (IS_UNDER_IPMP(ill
))
10563 ipmp_phyint_refresh_active(phyi
);
10566 if ((turn_on
|turn_off
) & ILLF_NOACCEPT
) {
10568 * If the ILLF_NOACCEPT flag is changed, bring up all the
10569 * ipifs that were brought down.
10571 * The routing sockets messages are sent as the result
10572 * of ill_up_ipifs(), further, SCTP's IPIF list was updated
10575 err
= ill_up_ipifs(ill
, q
, mp
);
10576 } else if ((flags
& IFF_UP
) && !(ipif
->ipif_flags
& IPIF_UP
)) {
10578 * XXX ipif_up really does not know whether a phyint flags
10579 * was modified or not. So, it sends up information on
10580 * only one routing sockets message. As we don't bring up
10581 * the interface and also set PHYI_ flags simultaneously
10582 * it should be okay.
10584 err
= ipif_up(ipif
, q
, mp
);
10587 * Make sure routing socket sees all changes to the flags.
10588 * ipif_up_done* handles this when we use ipif_up.
10590 if (phyint_flags_modified
) {
10591 if (phyi
->phyint_illv4
!= NULL
) {
10592 ip_rts_ifmsg(phyi
->phyint_illv4
->
10593 ill_ipif
, RTSQ_DEFAULT
);
10595 if (phyi
->phyint_illv6
!= NULL
) {
10596 ip_rts_ifmsg(phyi
->phyint_illv6
->
10597 ill_ipif
, RTSQ_DEFAULT
);
10600 ip_rts_ifmsg(ipif
, RTSQ_DEFAULT
);
10603 * Update the flags in SCTP's IPIF list, ipif_up() will do
10604 * this in need_up case.
10606 sctp_update_ipif(ipif
, SCTP_IPIF_UPDATE
);
10609 /* The default multicast interface might have changed */
10610 ire_increment_multicast_generation(ill
->ill_ipst
, ill
->ill_isv6
);
10615 * Restart the flags operation now that the refcounts have dropped to zero.
10619 ip_sioctl_flags_restart(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
10620 ip_ioctl_cmd_t
*ipip
, void *if_req
)
10623 struct ifreq
*ifr
= if_req
;
10624 struct lifreq
*lifr
= if_req
;
10625 uint64_t turn_on
, turn_off
;
10627 ip1dbg(("ip_sioctl_flags_restart(%s:%u %p)\n",
10628 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
10630 if (ipip
->ipi_cmd_type
== IF_CMD
) {
10631 /* cast to uint16_t prevents unwanted sign extension */
10632 flags
= (uint16_t)ifr
->ifr_flags
;
10634 flags
= lifr
->lifr_flags
;
10638 * If this function call is a result of the ILLF_NOACCEPT flag
10639 * change, do not call ipif_down_tail(). See ip_sioctl_flags().
10641 ip_sioctl_flags_onoff(ipif
, flags
, &turn_on
, &turn_off
);
10642 if (!((turn_on
|turn_off
) & ILLF_NOACCEPT
))
10643 (void) ipif_down_tail(ipif
);
10645 return (ip_sioctl_flags_tail(ipif
, flags
, q
, mp
));
10649 * Can operate on either a module or a driver queue.
10653 ip_sioctl_get_flags(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
10654 ip_ioctl_cmd_t
*ipip
, void *if_req
)
10657 * Has the flags been set correctly till now ?
10659 ill_t
*ill
= ipif
->ipif_ill
;
10660 phyint_t
*phyi
= ill
->ill_phyint
;
10662 ip1dbg(("ip_sioctl_get_flags(%s:%u %p)\n",
10663 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
10664 ASSERT((phyi
->phyint_flags
& ~(IFF_PHYINT_FLAGS
)) == 0);
10665 ASSERT((ill
->ill_flags
& ~(IFF_PHYINTINST_FLAGS
)) == 0);
10666 ASSERT((ipif
->ipif_flags
& ~(IFF_LOGINT_FLAGS
)) == 0);
10669 * Need a lock since some flags can be set even when there are
10670 * references to the ipif.
10672 mutex_enter(&ill
->ill_lock
);
10673 if (ipip
->ipi_cmd_type
== IF_CMD
) {
10674 struct ifreq
*ifr
= (struct ifreq
*)if_req
;
10676 /* Get interface flags (low 16 only). */
10677 ifr
->ifr_flags
= ((ipif
->ipif_flags
|
10678 ill
->ill_flags
| phyi
->phyint_flags
) & 0xffff);
10680 struct lifreq
*lifr
= (struct lifreq
*)if_req
;
10682 /* Get interface flags. */
10683 lifr
->lifr_flags
= ipif
->ipif_flags
|
10684 ill
->ill_flags
| phyi
->phyint_flags
;
10686 mutex_exit(&ill
->ill_lock
);
10691 * We allow the MTU to be set on an ILL, but not have it be different
10692 * for different IPIFs since we don't actually send packets on IPIFs.
10696 ip_sioctl_mtu(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
10697 ip_ioctl_cmd_t
*ipip
, void *if_req
)
10702 struct lifreq
*lifr
;
10705 ip1dbg(("ip_sioctl_mtu(%s:%u %p)\n", ipif
->ipif_ill
->ill_name
,
10706 ipif
->ipif_id
, (void *)ipif
));
10707 if (ipip
->ipi_cmd_type
== IF_CMD
) {
10708 ifr
= (struct ifreq
*)if_req
;
10709 mtu
= ifr
->ifr_metric
;
10711 lifr
= (struct lifreq
*)if_req
;
10712 mtu
= lifr
->lifr_mtu
;
10714 /* Only allow for logical unit zero i.e. not on "bge0:17" */
10715 if (ipif
->ipif_id
!= 0)
10718 ill
= ipif
->ipif_ill
;
10719 if (ipif
->ipif_isv6
)
10720 ip_min_mtu
= IPV6_MIN_MTU
;
10722 ip_min_mtu
= IP_MIN_MTU
;
10724 mutex_enter(&ill
->ill_lock
);
10725 if (mtu
> ill
->ill_max_frag
|| mtu
< ip_min_mtu
) {
10726 mutex_exit(&ill
->ill_lock
);
10729 /* Avoid increasing ill_mc_mtu */
10730 if (ill
->ill_mc_mtu
> mtu
)
10731 ill
->ill_mc_mtu
= mtu
;
10734 * The dce and fragmentation code can handle changes to ill_mtu
10735 * concurrent with sending/fragmenting packets.
10737 ill
->ill_mtu
= mtu
;
10738 ill
->ill_flags
|= ILLF_FIXEDMTU
;
10739 mutex_exit(&ill
->ill_lock
);
10742 * Make sure all dce_generation checks find out
10743 * that ill_mtu/ill_mc_mtu has changed.
10745 dce_increment_all_generations(ill
->ill_isv6
, ill
->ill_ipst
);
10748 * Refresh IPMP meta-interface MTU if necessary.
10750 if (IS_UNDER_IPMP(ill
))
10751 ipmp_illgrp_refresh_mtu(ill
->ill_grp
);
10753 /* Update the MTU in SCTP's list */
10754 sctp_update_ipif(ipif
, SCTP_IPIF_UPDATE
);
10758 /* Get interface MTU. */
10761 ip_sioctl_get_mtu(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
10762 ip_ioctl_cmd_t
*ipip
, void *if_req
)
10765 struct lifreq
*lifr
;
10767 ip1dbg(("ip_sioctl_get_mtu(%s:%u %p)\n",
10768 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
10771 * We allow a get on any logical interface even though the set
10772 * can only be done on logical unit 0.
10774 if (ipip
->ipi_cmd_type
== IF_CMD
) {
10775 ifr
= (struct ifreq
*)if_req
;
10776 ifr
->ifr_metric
= ipif
->ipif_ill
->ill_mtu
;
10778 lifr
= (struct lifreq
*)if_req
;
10779 lifr
->lifr_mtu
= ipif
->ipif_ill
->ill_mtu
;
10784 /* Set interface broadcast address. */
10787 ip_sioctl_brdaddr(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
10788 ip_ioctl_cmd_t
*ipip
, void *if_req
)
10792 ill_t
*ill
= ipif
->ipif_ill
;
10793 ip_stack_t
*ipst
= ill
->ill_ipst
;
10795 ip1dbg(("ip_sioctl_brdaddr(%s:%u)\n", ill
->ill_name
,
10798 ASSERT(IAM_WRITER_IPIF(ipif
));
10799 if (!(ipif
->ipif_flags
& IPIF_BROADCAST
))
10800 return (EADDRNOTAVAIL
);
10802 ASSERT(!(ipif
->ipif_isv6
)); /* No IPv6 broadcast */
10804 if (sin
->sin_family
!= AF_INET
)
10805 return (EAFNOSUPPORT
);
10807 addr
= sin
->sin_addr
.s_addr
;
10809 if (ipif
->ipif_flags
& IPIF_UP
) {
10811 * If we are already up, make sure the new
10812 * broadcast address makes sense. If it does,
10813 * there should be an IRE for it already.
10815 ire
= ire_ftable_lookup_v4(addr
, 0, 0, IRE_BROADCAST
,
10816 ill
, ipif
->ipif_zoneid
,
10817 (MATCH_IRE_ILL
| MATCH_IRE_TYPE
), 0, ipst
, NULL
);
10825 * Changing the broadcast addr for this ipif. Since the IRE_BROADCAST
10826 * needs to already exist we never need to change the set of
10827 * IRE_BROADCASTs when we are UP.
10829 if (addr
!= ipif
->ipif_brd_addr
)
10830 IN6_IPADDR_TO_V4MAPPED(addr
, &ipif
->ipif_v6brd_addr
);
10835 /* Get interface broadcast address. */
10838 ip_sioctl_get_brdaddr(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
10839 ip_ioctl_cmd_t
*ipip
, void *if_req
)
10841 ip1dbg(("ip_sioctl_get_brdaddr(%s:%u %p)\n",
10842 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
10843 if (!(ipif
->ipif_flags
& IPIF_BROADCAST
))
10844 return (EADDRNOTAVAIL
);
10846 /* IPIF_BROADCAST not possible with IPv6 */
10847 ASSERT(!ipif
->ipif_isv6
);
10849 sin
->sin_family
= AF_INET
;
10850 sin
->sin_addr
.s_addr
= ipif
->ipif_brd_addr
;
10855 * This routine is called to handle the SIOCS*IFNETMASK IOCTL.
10859 ip_sioctl_netmask(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
10860 ip_ioctl_cmd_t
*ipip
, void *if_req
)
10865 ip1dbg(("ip_sioctl_netmask(%s:%u %p)\n",
10866 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
10868 ASSERT(IAM_WRITER_IPIF(ipif
));
10870 if (ipif
->ipif_isv6
) {
10873 if (sin
->sin_family
!= AF_INET6
)
10874 return (EAFNOSUPPORT
);
10876 sin6
= (sin6_t
*)sin
;
10877 v6mask
= sin6
->sin6_addr
;
10881 if (sin
->sin_family
!= AF_INET
)
10882 return (EAFNOSUPPORT
);
10884 mask
= sin
->sin_addr
.s_addr
;
10885 if (!ip_contiguous_mask(ntohl(mask
)))
10887 V4MASK_TO_V6(mask
, v6mask
);
10891 * No big deal if the interface isn't already up, or the mask
10892 * isn't really changing, or this is pt-pt.
10894 if (!(ipif
->ipif_flags
& IPIF_UP
) ||
10895 IN6_ARE_ADDR_EQUAL(&v6mask
, &ipif
->ipif_v6net_mask
) ||
10896 (ipif
->ipif_flags
& IPIF_POINTOPOINT
)) {
10897 ipif
->ipif_v6net_mask
= v6mask
;
10898 if ((ipif
->ipif_flags
& IPIF_POINTOPOINT
) == 0) {
10899 V6_MASK_COPY(ipif
->ipif_v6lcl_addr
,
10900 ipif
->ipif_v6net_mask
,
10901 ipif
->ipif_v6subnet
);
10906 * Make sure we have valid net and subnet broadcast ire's
10907 * for the old netmask, if needed by other logical interfaces.
10909 err
= ipif_logical_down(ipif
, q
, mp
);
10910 if (err
== EINPROGRESS
)
10912 (void) ipif_down_tail(ipif
);
10913 err
= ip_sioctl_netmask_tail(ipif
, sin
, q
, mp
);
10918 ip_sioctl_netmask_tail(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
)
10923 ip1dbg(("ip_sioctl_netmask_tail(%s:%u %p)\n",
10924 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
10926 if (ipif
->ipif_isv6
) {
10929 sin6
= (sin6_t
*)sin
;
10930 v6mask
= sin6
->sin6_addr
;
10934 mask
= sin
->sin_addr
.s_addr
;
10935 V4MASK_TO_V6(mask
, v6mask
);
10938 ipif
->ipif_v6net_mask
= v6mask
;
10939 if ((ipif
->ipif_flags
& IPIF_POINTOPOINT
) == 0) {
10940 V6_MASK_COPY(ipif
->ipif_v6lcl_addr
, ipif
->ipif_v6net_mask
,
10941 ipif
->ipif_v6subnet
);
10943 err
= ipif_up(ipif
, q
, mp
);
10945 if (err
== 0 || err
== EINPROGRESS
) {
10947 * The interface must be DL_BOUND if this packet has to
10948 * go out on the wire. Since we only go through a logical
10949 * down and are bound with the driver during an internal
10950 * down/up that is satisfied.
10952 if (!ipif
->ipif_isv6
&& ipif
->ipif_ill
->ill_wq
!= NULL
) {
10953 /* Potentially broadcast an address mask reply. */
10954 ipif_mask_reply(ipif
);
10962 ip_sioctl_netmask_restart(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
10963 ip_ioctl_cmd_t
*ipip
, void *if_req
)
10965 ip1dbg(("ip_sioctl_netmask_restart(%s:%u %p)\n",
10966 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
10967 (void) ipif_down_tail(ipif
);
10968 return (ip_sioctl_netmask_tail(ipif
, sin
, q
, mp
));
10971 /* Get interface net mask. */
10974 ip_sioctl_get_netmask(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
10975 ip_ioctl_cmd_t
*ipip
, void *if_req
)
10977 struct lifreq
*lifr
= (struct lifreq
*)if_req
;
10978 struct sockaddr_in6
*sin6
= (sin6_t
*)sin
;
10980 ip1dbg(("ip_sioctl_get_netmask(%s:%u %p)\n",
10981 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
10984 * net mask can't change since we have a reference to the ipif.
10986 if (ipif
->ipif_isv6
) {
10987 ASSERT(ipip
->ipi_cmd_type
== LIF_CMD
);
10989 sin6
->sin6_family
= AF_INET6
;
10990 sin6
->sin6_addr
= ipif
->ipif_v6net_mask
;
10991 lifr
->lifr_addrlen
=
10992 ip_mask_to_plen_v6(&ipif
->ipif_v6net_mask
);
10995 sin
->sin_family
= AF_INET
;
10996 sin
->sin_addr
.s_addr
= ipif
->ipif_net_mask
;
10997 if (ipip
->ipi_cmd_type
== LIF_CMD
) {
10998 lifr
->lifr_addrlen
=
10999 ip_mask_to_plen(ipif
->ipif_net_mask
);
11007 ip_sioctl_metric(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
11008 ip_ioctl_cmd_t
*ipip
, void *if_req
)
11010 ip1dbg(("ip_sioctl_metric(%s:%u %p)\n",
11011 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
11014 * Since no applications should ever be setting metrics on underlying
11015 * interfaces, we explicitly fail to smoke 'em out.
11017 if (IS_UNDER_IPMP(ipif
->ipif_ill
))
11021 * Set interface metric. We don't use this for
11022 * anything but we keep track of it in case it is
11023 * important to routing applications or such.
11025 if (ipip
->ipi_cmd_type
== IF_CMD
) {
11028 ifr
= (struct ifreq
*)if_req
;
11029 ipif
->ipif_ill
->ill_metric
= ifr
->ifr_metric
;
11031 struct lifreq
*lifr
;
11033 lifr
= (struct lifreq
*)if_req
;
11034 ipif
->ipif_ill
->ill_metric
= lifr
->lifr_metric
;
11041 ip_sioctl_get_metric(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
11042 ip_ioctl_cmd_t
*ipip
, void *if_req
)
11044 /* Get interface metric. */
11045 ip1dbg(("ip_sioctl_get_metric(%s:%u %p)\n",
11046 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
11048 if (ipip
->ipi_cmd_type
== IF_CMD
) {
11051 ifr
= (struct ifreq
*)if_req
;
11052 ifr
->ifr_metric
= ipif
->ipif_ill
->ill_metric
;
11054 struct lifreq
*lifr
;
11056 lifr
= (struct lifreq
*)if_req
;
11057 lifr
->lifr_metric
= ipif
->ipif_ill
->ill_metric
;
11065 ip_sioctl_muxid(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
11066 ip_ioctl_cmd_t
*ipip
, void *if_req
)
11070 ip1dbg(("ip_sioctl_muxid(%s:%u %p)\n",
11071 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
11073 * Set the muxid returned from I_PLINK.
11075 if (ipip
->ipi_cmd_type
== IF_CMD
) {
11076 struct ifreq
*ifr
= (struct ifreq
*)if_req
;
11078 ipif
->ipif_ill
->ill_muxid
= ifr
->ifr_ip_muxid
;
11079 arp_muxid
= ifr
->ifr_arp_muxid
;
11081 struct lifreq
*lifr
= (struct lifreq
*)if_req
;
11083 ipif
->ipif_ill
->ill_muxid
= lifr
->lifr_ip_muxid
;
11084 arp_muxid
= lifr
->lifr_arp_muxid
;
11086 arl_set_muxid(ipif
->ipif_ill
, arp_muxid
);
11092 ip_sioctl_get_muxid(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
11093 ip_ioctl_cmd_t
*ipip
, void *if_req
)
11097 ip1dbg(("ip_sioctl_get_muxid(%s:%u %p)\n",
11098 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
11100 * Get the muxid saved in ill for I_PUNLINK.
11102 arp_muxid
= arl_get_muxid(ipif
->ipif_ill
);
11103 if (ipip
->ipi_cmd_type
== IF_CMD
) {
11104 struct ifreq
*ifr
= (struct ifreq
*)if_req
;
11106 ifr
->ifr_ip_muxid
= ipif
->ipif_ill
->ill_muxid
;
11107 ifr
->ifr_arp_muxid
= arp_muxid
;
11109 struct lifreq
*lifr
= (struct lifreq
*)if_req
;
11111 lifr
->lifr_ip_muxid
= ipif
->ipif_ill
->ill_muxid
;
11112 lifr
->lifr_arp_muxid
= arp_muxid
;
11118 * Set the subnet prefix. Does not modify the broadcast address.
11122 ip_sioctl_subnet(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
11123 ip_ioctl_cmd_t
*ipip
, void *if_req
)
11128 boolean_t need_up
= B_FALSE
;
11131 ip1dbg(("ip_sioctl_subnet(%s:%u %p)\n",
11132 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
11134 ASSERT(IAM_WRITER_IPIF(ipif
));
11135 addrlen
= ((struct lifreq
*)if_req
)->lifr_addrlen
;
11137 if (ipif
->ipif_isv6
) {
11140 if (sin
->sin_family
!= AF_INET6
)
11141 return (EAFNOSUPPORT
);
11143 sin6
= (sin6_t
*)sin
;
11144 v6addr
= sin6
->sin6_addr
;
11145 if (!ip_remote_addr_ok_v6(&v6addr
, &ipv6_all_ones
))
11146 return (EADDRNOTAVAIL
);
11150 if (sin
->sin_family
!= AF_INET
)
11151 return (EAFNOSUPPORT
);
11153 addr
= sin
->sin_addr
.s_addr
;
11154 if (!ip_addr_ok_v4(addr
, 0xFFFFFFFF))
11155 return (EADDRNOTAVAIL
);
11156 IN6_IPADDR_TO_V4MAPPED(addr
, &v6addr
);
11158 addrlen
+= IPV6_ABITS
- IP_ABITS
;
11161 if (ip_plen_to_mask_v6(addrlen
, &v6mask
) == NULL
)
11164 /* Check if bits in the address is set past the mask */
11165 if (!V6_MASK_EQ(v6addr
, v6mask
, v6addr
))
11168 if (IN6_ARE_ADDR_EQUAL(&ipif
->ipif_v6subnet
, &v6addr
) &&
11169 IN6_ARE_ADDR_EQUAL(&ipif
->ipif_v6net_mask
, &v6mask
))
11170 return (0); /* No change */
11172 if (ipif
->ipif_flags
& IPIF_UP
) {
11174 * If the interface is already marked up,
11175 * we call ipif_down which will take care
11176 * of ditching any IREs that have been set
11177 * up based on the old interface address.
11179 err
= ipif_logical_down(ipif
, q
, mp
);
11180 if (err
== EINPROGRESS
)
11182 (void) ipif_down_tail(ipif
);
11186 err
= ip_sioctl_subnet_tail(ipif
, v6addr
, v6mask
, q
, mp
, need_up
);
11191 ip_sioctl_subnet_tail(ipif_t
*ipif
, in6_addr_t v6addr
, in6_addr_t v6mask
,
11192 queue_t
*q
, mblk_t
*mp
, boolean_t need_up
)
11194 ill_t
*ill
= ipif
->ipif_ill
;
11197 ip1dbg(("ip_sioctl_subnet_tail(%s:%u %p)\n",
11198 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
11200 /* Set the new address. */
11201 mutex_enter(&ill
->ill_lock
);
11202 ipif
->ipif_v6net_mask
= v6mask
;
11203 if ((ipif
->ipif_flags
& IPIF_POINTOPOINT
) == 0) {
11204 V6_MASK_COPY(v6addr
, ipif
->ipif_v6net_mask
,
11205 ipif
->ipif_v6subnet
);
11207 mutex_exit(&ill
->ill_lock
);
11211 * Now bring the interface back up. If this
11212 * is the only IPIF for the ILL, ipif_up
11213 * will have to re-bind to the device, so
11214 * we may get back EINPROGRESS, in which
11215 * case, this IOCTL will get completed in
11216 * ip_rput_dlpi when we see the DL_BIND_ACK.
11218 err
= ipif_up(ipif
, q
, mp
);
11219 if (err
== EINPROGRESS
)
11227 ip_sioctl_subnet_restart(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
11228 ip_ioctl_cmd_t
*ipip
, void *if_req
)
11233 struct lifreq
*lifr
= (struct lifreq
*)if_req
;
11235 ip1dbg(("ip_sioctl_subnet_restart(%s:%u %p)\n",
11236 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
11237 (void) ipif_down_tail(ipif
);
11239 addrlen
= lifr
->lifr_addrlen
;
11240 if (ipif
->ipif_isv6
) {
11243 sin6
= (sin6_t
*)sin
;
11244 v6addr
= sin6
->sin6_addr
;
11248 addr
= sin
->sin_addr
.s_addr
;
11249 IN6_IPADDR_TO_V4MAPPED(addr
, &v6addr
);
11250 addrlen
+= IPV6_ABITS
- IP_ABITS
;
11252 (void) ip_plen_to_mask_v6(addrlen
, &v6mask
);
11254 return (ip_sioctl_subnet_tail(ipif
, v6addr
, v6mask
, q
, mp
, B_TRUE
));
11259 ip_sioctl_get_subnet(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
11260 ip_ioctl_cmd_t
*ipip
, void *if_req
)
11262 struct lifreq
*lifr
= (struct lifreq
*)if_req
;
11263 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sin
;
11265 ip1dbg(("ip_sioctl_get_subnet(%s:%u %p)\n",
11266 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
11267 ASSERT(ipip
->ipi_cmd_type
== LIF_CMD
);
11269 if (ipif
->ipif_isv6
) {
11271 sin6
->sin6_family
= AF_INET6
;
11272 sin6
->sin6_addr
= ipif
->ipif_v6subnet
;
11273 lifr
->lifr_addrlen
=
11274 ip_mask_to_plen_v6(&ipif
->ipif_v6net_mask
);
11277 sin
->sin_family
= AF_INET
;
11278 sin
->sin_addr
.s_addr
= ipif
->ipif_subnet
;
11279 lifr
->lifr_addrlen
= ip_mask_to_plen(ipif
->ipif_net_mask
);
11285 * Set the IPv6 address token.
11289 ip_sioctl_token(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
11290 ip_ioctl_cmd_t
*ipi
, void *if_req
)
11292 ill_t
*ill
= ipif
->ipif_ill
;
11296 boolean_t need_up
= B_FALSE
;
11298 sin6_t
*sin6
= (sin6_t
*)sin
;
11299 struct lifreq
*lifr
= (struct lifreq
*)if_req
;
11302 ip1dbg(("ip_sioctl_token(%s:%u %p)\n",
11303 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
11304 ASSERT(IAM_WRITER_IPIF(ipif
));
11306 addrlen
= lifr
->lifr_addrlen
;
11307 /* Only allow for logical unit zero i.e. not on "le0:17" */
11308 if (ipif
->ipif_id
!= 0)
11311 if (!ipif
->ipif_isv6
)
11314 if (addrlen
> IPV6_ABITS
)
11317 v6addr
= sin6
->sin6_addr
;
11320 * The length of the token is the length from the end. To get
11321 * the proper mask for this, compute the mask of the bits not
11322 * in the token; ie. the prefix, and then xor to get the mask.
11324 if (ip_plen_to_mask_v6(IPV6_ABITS
- addrlen
, &v6mask
) == NULL
)
11326 for (i
= 0; i
< 4; i
++) {
11327 v6mask
.s6_addr32
[i
] ^= (uint32_t)0xffffffff;
11330 if (V6_MASK_EQ(v6addr
, v6mask
, ill
->ill_token
) &&
11331 ill
->ill_token_length
== addrlen
)
11332 return (0); /* No change */
11334 if (ipif
->ipif_flags
& IPIF_UP
) {
11335 err
= ipif_logical_down(ipif
, q
, mp
);
11336 if (err
== EINPROGRESS
)
11338 (void) ipif_down_tail(ipif
);
11341 err
= ip_sioctl_token_tail(ipif
, sin6
, addrlen
, q
, mp
, need_up
);
11346 ip_sioctl_token_tail(ipif_t
*ipif
, sin6_t
*sin6
, int addrlen
, queue_t
*q
,
11347 mblk_t
*mp
, boolean_t need_up
)
11351 ill_t
*ill
= ipif
->ipif_ill
;
11355 ip1dbg(("ip_sioctl_token_tail(%s:%u %p)\n",
11356 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
11357 v6addr
= sin6
->sin6_addr
;
11359 * The length of the token is the length from the end. To get
11360 * the proper mask for this, compute the mask of the bits not
11361 * in the token; ie. the prefix, and then xor to get the mask.
11363 (void) ip_plen_to_mask_v6(IPV6_ABITS
- addrlen
, &v6mask
);
11364 for (i
= 0; i
< 4; i
++)
11365 v6mask
.s6_addr32
[i
] ^= (uint32_t)0xffffffff;
11367 mutex_enter(&ill
->ill_lock
);
11368 V6_MASK_COPY(v6addr
, v6mask
, ill
->ill_token
);
11369 ill
->ill_token_length
= addrlen
;
11370 ill
->ill_manual_token
= 1;
11372 /* Reconfigure the link-local address based on this new token */
11373 ipif_setlinklocal(ill
->ill_ipif
);
11375 mutex_exit(&ill
->ill_lock
);
11379 * Now bring the interface back up. If this
11380 * is the only IPIF for the ILL, ipif_up
11381 * will have to re-bind to the device, so
11382 * we may get back EINPROGRESS, in which
11383 * case, this IOCTL will get completed in
11384 * ip_rput_dlpi when we see the DL_BIND_ACK.
11386 err
= ipif_up(ipif
, q
, mp
);
11387 if (err
== EINPROGRESS
)
11395 ip_sioctl_get_token(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
11396 ip_ioctl_cmd_t
*ipi
, void *if_req
)
11399 sin6_t
*sin6
= (sin6_t
*)sin
;
11400 struct lifreq
*lifr
= (struct lifreq
*)if_req
;
11402 ip1dbg(("ip_sioctl_get_token(%s:%u %p)\n",
11403 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
11404 if (ipif
->ipif_id
!= 0)
11407 ill
= ipif
->ipif_ill
;
11408 if (!ill
->ill_isv6
)
11412 sin6
->sin6_family
= AF_INET6
;
11413 ASSERT(!IN6_IS_ADDR_V4MAPPED(&ill
->ill_token
));
11414 sin6
->sin6_addr
= ill
->ill_token
;
11415 lifr
->lifr_addrlen
= ill
->ill_token_length
;
11420 * Set (hardware) link specific information that might override
11421 * what was acquired through the DL_INFO_ACK.
11425 ip_sioctl_lnkinfo(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
11426 ip_ioctl_cmd_t
*ipi
, void *if_req
)
11428 ill_t
*ill
= ipif
->ipif_ill
;
11430 struct lifreq
*lifr
= (struct lifreq
*)if_req
;
11431 lif_ifinfo_req_t
*lir
;
11433 ip1dbg(("ip_sioctl_lnkinfo(%s:%u %p)\n",
11434 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
11435 lir
= &lifr
->lifr_ifinfo
;
11436 ASSERT(IAM_WRITER_IPIF(ipif
));
11438 /* Only allow for logical unit zero i.e. not on "bge0:17" */
11439 if (ipif
->ipif_id
!= 0)
11442 /* Set interface MTU. */
11443 if (ipif
->ipif_isv6
)
11444 ip_min_mtu
= IPV6_MIN_MTU
;
11446 ip_min_mtu
= IP_MIN_MTU
;
11449 * Verify values before we set anything. Allow zero to
11450 * mean unspecified.
11452 * XXX We should be able to set the user-defined lir_mtu to some value
11453 * that is greater than ill_current_frag but less than ill_max_frag- the
11454 * ill_max_frag value tells us the max MTU that can be handled by the
11455 * datalink, whereas the ill_current_frag is dynamically computed for
11456 * some link-types like tunnels, based on the tunnel PMTU. However,
11457 * since there is currently no way of distinguishing between
11458 * administratively fixed link mtu values (e.g., those set via
11459 * /sbin/dladm) and dynamically discovered MTUs (e.g., those discovered
11460 * for tunnels) we conservatively choose the ill_current_frag as the
11463 if (lir
->lir_maxmtu
!= 0 &&
11464 (lir
->lir_maxmtu
> ill
->ill_current_frag
||
11465 lir
->lir_maxmtu
< ip_min_mtu
))
11467 if (lir
->lir_reachtime
!= 0 &&
11468 lir
->lir_reachtime
> ND_MAX_REACHTIME
)
11470 if (lir
->lir_reachretrans
!= 0 &&
11471 lir
->lir_reachretrans
> ND_MAX_REACHRETRANSTIME
)
11474 mutex_enter(&ill
->ill_lock
);
11476 * The dce and fragmentation code can handle changes to ill_mtu
11477 * concurrent with sending/fragmenting packets.
11479 if (lir
->lir_maxmtu
!= 0)
11480 ill
->ill_user_mtu
= lir
->lir_maxmtu
;
11482 if (lir
->lir_reachtime
!= 0)
11483 ill
->ill_reachable_time
= lir
->lir_reachtime
;
11485 if (lir
->lir_reachretrans
!= 0)
11486 ill
->ill_reachable_retrans_time
= lir
->lir_reachretrans
;
11488 ill
->ill_max_hops
= lir
->lir_maxhops
;
11489 ill
->ill_max_buf
= ND_MAX_Q
;
11490 if (!(ill
->ill_flags
& ILLF_FIXEDMTU
) && ill
->ill_user_mtu
!= 0) {
11492 * ill_mtu is the actual interface MTU, obtained as the min
11493 * of user-configured mtu and the value announced by the
11494 * driver (via DL_NOTE_SDU_SIZE/DL_INFO_ACK). Note that since
11495 * we have already made the choice of requiring
11496 * ill_user_mtu < ill_current_frag by the time we get here,
11497 * the ill_mtu effectively gets assigned to the ill_user_mtu
11500 ill
->ill_mtu
= MIN(ill
->ill_current_frag
, ill
->ill_user_mtu
);
11501 ill
->ill_mc_mtu
= MIN(ill
->ill_mc_mtu
, ill
->ill_user_mtu
);
11503 mutex_exit(&ill
->ill_lock
);
11506 * Make sure all dce_generation checks find out
11507 * that ill_mtu/ill_mc_mtu has changed.
11509 if (!(ill
->ill_flags
& ILLF_FIXEDMTU
) && (lir
->lir_maxmtu
!= 0))
11510 dce_increment_all_generations(ill
->ill_isv6
, ill
->ill_ipst
);
11513 * Refresh IPMP meta-interface MTU if necessary.
11515 if (IS_UNDER_IPMP(ill
))
11516 ipmp_illgrp_refresh_mtu(ill
->ill_grp
);
11523 ip_sioctl_get_lnkinfo(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
11524 ip_ioctl_cmd_t
*ipi
, void *if_req
)
11526 struct lif_ifinfo_req
*lir
;
11527 ill_t
*ill
= ipif
->ipif_ill
;
11529 ip1dbg(("ip_sioctl_get_lnkinfo(%s:%u %p)\n",
11530 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
11531 if (ipif
->ipif_id
!= 0)
11534 lir
= &((struct lifreq
*)if_req
)->lifr_ifinfo
;
11535 lir
->lir_maxhops
= ill
->ill_max_hops
;
11536 lir
->lir_reachtime
= ill
->ill_reachable_time
;
11537 lir
->lir_reachretrans
= ill
->ill_reachable_retrans_time
;
11538 lir
->lir_maxmtu
= ill
->ill_mtu
;
11544 * Return best guess as to the subnet mask for the specified address.
11545 * Based on the subnet masks for all the configured interfaces.
11547 * We end up returning a zero mask in the case of default, multicast or
11551 ip_subnet_mask(ipaddr_t addr
, ipif_t
**ipifp
, ip_stack_t
*ipst
)
11556 ill_walk_context_t ctx
;
11557 ipif_t
*fallback_ipif
= NULL
;
11559 net_mask
= ip_net_mask(addr
);
11560 if (net_mask
== 0) {
11565 /* Let's check to see if this is maybe a local subnet route. */
11566 /* this function only applies to IPv4 interfaces */
11567 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
11568 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
11569 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
11570 mutex_enter(&ill
->ill_lock
);
11571 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
11572 ipif
= ipif
->ipif_next
) {
11573 if (IPIF_IS_CONDEMNED(ipif
))
11575 if (!(ipif
->ipif_flags
& IPIF_UP
))
11577 if ((ipif
->ipif_subnet
& net_mask
) ==
11578 (addr
& net_mask
)) {
11580 * Don't trust pt-pt interfaces if there are
11581 * other interfaces.
11583 if (ipif
->ipif_flags
& IPIF_POINTOPOINT
) {
11584 if (fallback_ipif
== NULL
) {
11585 ipif_refhold_locked(ipif
);
11586 fallback_ipif
= ipif
;
11592 * Fine. Just assume the same net mask as the
11593 * directly attached subnet interface is using.
11595 ipif_refhold_locked(ipif
);
11596 mutex_exit(&ill
->ill_lock
);
11597 rw_exit(&ipst
->ips_ill_g_lock
);
11598 if (fallback_ipif
!= NULL
)
11599 ipif_refrele(fallback_ipif
);
11601 return (ipif
->ipif_net_mask
);
11604 mutex_exit(&ill
->ill_lock
);
11606 rw_exit(&ipst
->ips_ill_g_lock
);
11608 *ipifp
= fallback_ipif
;
11609 return ((fallback_ipif
!= NULL
) ?
11610 fallback_ipif
->ipif_net_mask
: net_mask
);
11614 * ip_sioctl_copyin_setup calls ip_wput_ioctl to process the IP_IOCTL ioctl.
11617 ip_wput_ioctl(queue_t
*q
, mblk_t
*mp
)
11627 ip1dbg(("ip_wput_ioctl"));
11628 iocp
= (IOCP
)mp
->b_rptr
;
11631 iocp
->ioc_error
= EINVAL
;
11632 mp
->b_datap
->db_type
= M_IOCNAK
;
11633 iocp
->ioc_count
= 0;
11639 * These IOCTLs provide various control capabilities to
11640 * upstream agents such as ULPs and processes. There
11641 * are currently two such IOCTLs implemented. They
11642 * are used by TCP to provide update information for
11643 * existing IREs and to forcibly delete an IRE for a
11644 * host that is not responding, thereby forcing an
11645 * attempt at a new route.
11647 iocp
->ioc_error
= EINVAL
;
11648 if (!pullupmsg(mp1
, sizeof (ipllc
->ipllc_cmd
)))
11651 ipllc
= (ipllc_t
*)mp1
->b_rptr
;
11652 for (ipft
= ip_ioctl_ftbl
; ipft
->ipft_pfi
; ipft
++) {
11653 if (ipllc
->ipllc_cmd
== ipft
->ipft_cmd
)
11657 * prefer credential from mblk over ioctl;
11658 * see ip_sioctl_copyin_setup
11660 cr
= msg_getcred(mp
, NULL
);
11665 * Refhold the conn in case the request gets queued up in some lookup
11668 connp
= Q_TO_CONN(q
);
11669 CONN_INC_REF(connp
);
11670 CONN_INC_IOCTLREF(connp
);
11671 if (ipft
->ipft_pfi
&&
11672 ((mp1
->b_wptr
- mp1
->b_rptr
) >= ipft
->ipft_min_size
||
11673 pullupmsg(mp1
, ipft
->ipft_min_size
))) {
11674 error
= (*ipft
->ipft_pfi
)(q
,
11675 (ipft
->ipft_flags
& IPFT_F_SELF_REPLY
) ? mp
: mp1
, cr
);
11677 if (ipft
->ipft_flags
& IPFT_F_SELF_REPLY
) {
11679 * CONN_OPER_PENDING_DONE happens in the function called
11680 * through ipft_pfi above.
11685 CONN_DEC_IOCTLREF(connp
);
11686 CONN_OPER_PENDING_DONE(connp
);
11687 if (ipft
->ipft_flags
& IPFT_F_NO_REPLY
) {
11691 iocp
->ioc_error
= error
;
11694 mp
->b_datap
->db_type
= M_IOCACK
;
11695 if (iocp
->ioc_error
)
11696 iocp
->ioc_count
= 0;
11701 * Assign a unique id for the ipif. This is used by sctp_addr.c
11702 * Note: remove if sctp_addr.c is redone to not shadow ill/ipif data structures.
11705 ipif_assign_seqid(ipif_t
*ipif
)
11707 ip_stack_t
*ipst
= ipif
->ipif_ill
->ill_ipst
;
11709 ipif
->ipif_seqid
= atomic_inc_64_nv(&ipst
->ips_ipif_g_seqid
);
11713 * Clone the contents of `sipif' to `dipif'. Requires that both ipifs are
11714 * administratively down (i.e., no DAD), of the same type, and locked. Note
11715 * that the clone is complete -- including the seqid -- and the expectation is
11716 * that the caller will either free or overwrite `sipif' before it's unlocked.
11719 ipif_clone(const ipif_t
*sipif
, ipif_t
*dipif
)
11721 ASSERT(MUTEX_HELD(&sipif
->ipif_ill
->ill_lock
));
11722 ASSERT(MUTEX_HELD(&dipif
->ipif_ill
->ill_lock
));
11723 ASSERT(!(sipif
->ipif_flags
& (IPIF_UP
|IPIF_DUPLICATE
)));
11724 ASSERT(!(dipif
->ipif_flags
& (IPIF_UP
|IPIF_DUPLICATE
)));
11725 ASSERT(sipif
->ipif_ire_type
== dipif
->ipif_ire_type
);
11727 dipif
->ipif_flags
= sipif
->ipif_flags
;
11728 dipif
->ipif_zoneid
= sipif
->ipif_zoneid
;
11729 dipif
->ipif_v6subnet
= sipif
->ipif_v6subnet
;
11730 dipif
->ipif_v6lcl_addr
= sipif
->ipif_v6lcl_addr
;
11731 dipif
->ipif_v6net_mask
= sipif
->ipif_v6net_mask
;
11732 dipif
->ipif_v6brd_addr
= sipif
->ipif_v6brd_addr
;
11733 dipif
->ipif_v6pp_dst_addr
= sipif
->ipif_v6pp_dst_addr
;
11736 * As per the comment atop the function, we assume that these sipif
11737 * fields will be changed before sipif is unlocked.
11739 dipif
->ipif_seqid
= sipif
->ipif_seqid
;
11740 dipif
->ipif_state_flags
= sipif
->ipif_state_flags
;
11744 * Transfer the contents of `sipif' to `dipif', and then free (if `virgipif'
11745 * is NULL) or overwrite `sipif' with `virgipif', which must be a virgin
11746 * (unreferenced) ipif. Also, if `sipif' is used by the current xop, then
11747 * transfer the xop to `dipif'. Requires that all ipifs are administratively
11748 * down (i.e., no DAD), of the same type, and unlocked.
11751 ipif_transfer(ipif_t
*sipif
, ipif_t
*dipif
, ipif_t
*virgipif
)
11753 ipsq_t
*ipsq
= sipif
->ipif_ill
->ill_phyint
->phyint_ipsq
;
11754 ipxop_t
*ipx
= ipsq
->ipsq_xop
;
11756 ASSERT(sipif
!= dipif
);
11757 ASSERT(sipif
!= virgipif
);
11760 * Grab all of the locks that protect the ipif in a defined order.
11762 GRAB_ILL_LOCKS(sipif
->ipif_ill
, dipif
->ipif_ill
);
11764 ipif_clone(sipif
, dipif
);
11765 if (virgipif
!= NULL
) {
11766 ipif_clone(virgipif
, sipif
);
11770 RELEASE_ILL_LOCKS(sipif
->ipif_ill
, dipif
->ipif_ill
);
11773 * Transfer ownership of the current xop, if necessary.
11775 if (ipx
->ipx_current_ipif
== sipif
) {
11776 ASSERT(ipx
->ipx_pending_ipif
== NULL
);
11777 mutex_enter(&ipx
->ipx_lock
);
11778 ipx
->ipx_current_ipif
= dipif
;
11779 mutex_exit(&ipx
->ipx_lock
);
11782 if (virgipif
== NULL
)
11788 * - <ill_name>:<ipif_id> is at most LIFNAMSIZ - 1 and
11789 * - logical interface is within the allowed range
11792 is_lifname_valid(ill_t
*ill
, unsigned int ipif_id
)
11794 if (snprintf(NULL
, 0, "%s:%d", ill
->ill_name
, ipif_id
) >= LIFNAMSIZ
)
11795 return (ENAMETOOLONG
);
11797 if (ipif_id
>= ill
->ill_ipst
->ips_ip_addrs_per_if
)
11803 * Insert the ipif, so that the list of ipifs on the ill will be sorted
11804 * with respect to ipif_id. Note that an ipif with an ipif_id of -1 will
11805 * be inserted into the first space available in the list. The value of
11806 * ipif_id will then be set to the appropriate value for its position.
11809 ipif_insert(ipif_t
*ipif
, boolean_t acquire_g_lock
)
11817 ASSERT(ipif
->ipif_ill
->ill_net_type
== IRE_LOOPBACK
||
11818 IAM_WRITER_IPIF(ipif
));
11820 ill
= ipif
->ipif_ill
;
11821 ASSERT(ill
!= NULL
);
11822 ipst
= ill
->ill_ipst
;
11825 * In the case of lo0:0 we already hold the ill_g_lock.
11826 * ill_lookup_on_name (acquires ill_g_lock) -> ipif_allocate ->
11829 if (acquire_g_lock
)
11830 rw_enter(&ipst
->ips_ill_g_lock
, RW_WRITER
);
11831 mutex_enter(&ill
->ill_lock
);
11832 id
= ipif
->ipif_id
;
11833 tipifp
= &(ill
->ill_ipif
);
11834 if (id
== -1) { /* need to find a real id */
11836 while ((tipif
= *tipifp
) != NULL
) {
11837 ASSERT(tipif
->ipif_id
>= id
);
11838 if (tipif
->ipif_id
!= id
)
11839 break; /* non-consecutive id */
11841 tipifp
= &(tipif
->ipif_next
);
11843 if ((err
= is_lifname_valid(ill
, id
)) != 0) {
11844 mutex_exit(&ill
->ill_lock
);
11845 if (acquire_g_lock
)
11846 rw_exit(&ipst
->ips_ill_g_lock
);
11849 ipif
->ipif_id
= id
; /* assign new id */
11850 } else if ((err
= is_lifname_valid(ill
, id
)) == 0) {
11851 /* we have a real id; insert ipif in the right place */
11852 while ((tipif
= *tipifp
) != NULL
) {
11853 ASSERT(tipif
->ipif_id
!= id
);
11854 if (tipif
->ipif_id
> id
)
11855 break; /* found correct location */
11856 tipifp
= &(tipif
->ipif_next
);
11859 mutex_exit(&ill
->ill_lock
);
11860 if (acquire_g_lock
)
11861 rw_exit(&ipst
->ips_ill_g_lock
);
11865 ASSERT(tipifp
!= &(ill
->ill_ipif
) || id
== 0);
11867 ipif
->ipif_next
= tipif
;
11869 mutex_exit(&ill
->ill_lock
);
11870 if (acquire_g_lock
)
11871 rw_exit(&ipst
->ips_ill_g_lock
);
11877 ipif_remove(ipif_t
*ipif
)
11880 ill_t
*ill
= ipif
->ipif_ill
;
11882 ASSERT(RW_WRITE_HELD(&ill
->ill_ipst
->ips_ill_g_lock
));
11884 mutex_enter(&ill
->ill_lock
);
11885 ipifp
= &ill
->ill_ipif
;
11886 for (; *ipifp
!= NULL
; ipifp
= &ipifp
[0]->ipif_next
) {
11887 if (*ipifp
== ipif
) {
11888 *ipifp
= ipif
->ipif_next
;
11892 mutex_exit(&ill
->ill_lock
);
11896 * Allocate and initialize a new interface control structure. (Always
11897 * called as writer.)
11898 * When ipif_allocate() is called from ip_ll_subnet_defaults, the ill
11899 * is not part of the global linked list of ills. ipif_seqid is unique
11900 * in the system and to preserve the uniqueness, it is assigned only
11901 * when ill becomes part of the global list. At that point ill will
11902 * have a name. If it doesn't get assigned here, it will get assigned
11903 * in ipif_set_values() as part of SIOCSLIFNAME processing.
11904 * Aditionally, if we come here from ip_ll_subnet_defaults, we don't set
11905 * the interface flags or any other information from the DL_INFO_ACK for
11906 * DL_STYLE2 drivers (initialize == B_FALSE), since we won't have them at
11907 * this point. The flags etc. will be set in ip_ll_subnet_defaults when the
11908 * second DL_INFO_ACK comes in from the driver.
11911 ipif_allocate(ill_t
*ill
, int id
, uint_t ire_type
, boolean_t initialize
,
11912 boolean_t insert
, int *errorp
)
11916 ip_stack_t
*ipst
= ill
->ill_ipst
;
11918 ip1dbg(("ipif_allocate(%s:%d ill %p)\n",
11919 ill
->ill_name
, id
, (void *)ill
));
11920 ASSERT(ire_type
== IRE_LOOPBACK
|| IAM_WRITER_ILL(ill
));
11922 if (errorp
!= NULL
)
11925 if ((ipif
= mi_alloc(sizeof (ipif_t
), BPRI_MED
)) == NULL
) {
11926 if (errorp
!= NULL
)
11930 *ipif
= ipif_zero
; /* start clean */
11932 ipif
->ipif_ill
= ill
;
11933 ipif
->ipif_id
= id
; /* could be -1 */
11935 * Inherit the zoneid from the ill; for the shared stack instance
11936 * this is always the global zone
11938 ipif
->ipif_zoneid
= ill
->ill_zoneid
;
11940 ipif
->ipif_refcnt
= 0;
11943 if ((err
= ipif_insert(ipif
, ire_type
!= IRE_LOOPBACK
)) != 0) {
11945 if (errorp
!= NULL
)
11949 /* -1 id should have been replaced by real id */
11950 id
= ipif
->ipif_id
;
11954 if (ill
->ill_name
[0] != '\0')
11955 ipif_assign_seqid(ipif
);
11958 * If this is the zeroth ipif on the IPMP ill, create the illgrp
11959 * (which must not exist yet because the zeroth ipif is created once
11960 * per ill). However, do not not link it to the ipmp_grp_t until
11961 * I_PLINK is called; see ip_sioctl_plink_ipmp() for details.
11963 if (id
== 0 && IS_IPMP(ill
)) {
11964 if (ipmp_illgrp_create(ill
) == NULL
) {
11966 rw_enter(&ipst
->ips_ill_g_lock
, RW_WRITER
);
11968 rw_exit(&ipst
->ips_ill_g_lock
);
11971 if (errorp
!= NULL
)
11978 * We grab ill_lock to protect the flag changes. The ipif is still
11979 * not up and can't be looked up until the ioctl completes and the
11980 * IPIF_CHANGING flag is cleared.
11982 mutex_enter(&ill
->ill_lock
);
11984 ipif
->ipif_ire_type
= ire_type
;
11986 if (ipif
->ipif_isv6
) {
11987 ill
->ill_flags
|= ILLF_IPV6
;
11989 ipaddr_t inaddr_any
= INADDR_ANY
;
11991 ill
->ill_flags
|= ILLF_IPV4
;
11993 /* Keep the IN6_IS_ADDR_V4MAPPED assertions happy */
11994 IN6_IPADDR_TO_V4MAPPED(inaddr_any
,
11995 &ipif
->ipif_v6lcl_addr
);
11996 IN6_IPADDR_TO_V4MAPPED(inaddr_any
,
11997 &ipif
->ipif_v6subnet
);
11998 IN6_IPADDR_TO_V4MAPPED(inaddr_any
,
11999 &ipif
->ipif_v6net_mask
);
12000 IN6_IPADDR_TO_V4MAPPED(inaddr_any
,
12001 &ipif
->ipif_v6brd_addr
);
12002 IN6_IPADDR_TO_V4MAPPED(inaddr_any
,
12003 &ipif
->ipif_v6pp_dst_addr
);
12007 * Don't set the interface flags etc. now, will do it in
12008 * ip_ll_subnet_defaults.
12014 * NOTE: The IPMP meta-interface is special-cased because it starts
12015 * with no underlying interfaces (and thus an unknown broadcast
12016 * address length), but all interfaces that can be placed into an IPMP
12017 * group are required to be broadcast-capable.
12019 if (ill
->ill_bcast_addr_length
!= 0 || IS_IPMP(ill
)) {
12021 * Later detect lack of DLPI driver multicast capability by
12022 * catching DL_ENABMULTI_REQ errors in ip_rput_dlpi().
12024 ill
->ill_flags
|= ILLF_MULTICAST
;
12025 if (!ipif
->ipif_isv6
)
12026 ipif
->ipif_flags
|= IPIF_BROADCAST
;
12028 if (ill
->ill_net_type
!= IRE_LOOPBACK
) {
12029 if (ipif
->ipif_isv6
)
12031 * Note: xresolv interfaces will eventually need
12032 * NOARP set here as well, but that will require
12033 * those external resolvers to have some
12034 * knowledge of that flag and act appropriately.
12035 * Not to be changed at present.
12037 ill
->ill_flags
|= ILLF_NONUD
;
12039 ill
->ill_flags
|= ILLF_NOARP
;
12041 if (ill
->ill_phys_addr_length
== 0) {
12043 ipif
->ipif_flags
|= IPIF_NOXMIT
;
12045 /* pt-pt supports multicast. */
12046 ill
->ill_flags
|= ILLF_MULTICAST
;
12047 if (ill
->ill_net_type
!= IRE_LOOPBACK
)
12048 ipif
->ipif_flags
|= IPIF_POINTOPOINT
;
12053 mutex_exit(&ill
->ill_lock
);
12058 * Remove the neighbor cache entries associated with this logical
12062 ipif_arp_down(ipif_t
*ipif
)
12064 ill_t
*ill
= ipif
->ipif_ill
;
12067 ip1dbg(("ipif_arp_down(%s:%u)\n", ill
->ill_name
, ipif
->ipif_id
));
12068 ASSERT(IAM_WRITER_IPIF(ipif
));
12070 DTRACE_PROBE3(ipif__downup
, char *, "ipif_arp_down",
12071 ill_t
*, ill
, ipif_t
*, ipif
);
12072 ipif_nce_down(ipif
);
12075 * If this is the last ipif that is going down and there are no
12076 * duplicate addresses we may yet attempt to re-probe, then we need to
12077 * clean up ARP completely.
12079 if (ill
->ill_ipif_up_count
== 0 && ill
->ill_ipif_dup_count
== 0 &&
12080 !ill
->ill_logical_down
&& ill
->ill_net_type
== IRE_IF_RESOLVER
) {
12082 * If this was the last ipif on an IPMP interface, purge any
12083 * static ARP entries associated with it.
12086 ipmp_illgrp_refresh_arpent(ill
->ill_grp
);
12088 /* UNBIND, DETACH */
12089 err
= arp_ll_down(ill
);
12096 * Get the resolver set up for a new IP address. (Always called as writer.)
12097 * Called both for IPv4 and IPv6 interfaces, though it only does some
12098 * basic DAD related initialization for IPv6. Honors ILLF_NOARP.
12100 * The enumerated value res_act tunes the behavior:
12101 * * Res_act_initial: set up all the resolver structures for a new
12103 * * Res_act_defend: tell ARP that it needs to send a single gratuitous
12104 * ARP message in defense of the address.
12105 * * Res_act_rebind: tell ARP to change the hardware address for an IP
12106 * address (and issue gratuitous ARPs). Used by ipmp_ill_bind_ipif().
12108 * Returns zero on success, or an errno upon failure.
12111 ipif_resolver_up(ipif_t
*ipif
, enum ip_resolver_action res_act
)
12113 ill_t
*ill
= ipif
->ipif_ill
;
12117 ip1dbg(("ipif_resolver_up(%s:%u) flags 0x%x\n",
12118 ill
->ill_name
, ipif
->ipif_id
, (uint_t
)ipif
->ipif_flags
));
12119 ASSERT(IAM_WRITER_IPIF(ipif
));
12122 if (res_act
== Res_act_initial
) {
12123 ipif
->ipif_addr_ready
= 0;
12125 * We're bringing an interface up here. There's no way that we
12126 * should need to shut down ARP now.
12128 mutex_enter(&ill
->ill_lock
);
12129 if (ipif
->ipif_flags
& IPIF_DUPLICATE
) {
12130 ipif
->ipif_flags
&= ~IPIF_DUPLICATE
;
12131 ill
->ill_ipif_dup_count
--;
12134 mutex_exit(&ill
->ill_lock
);
12136 if (ipif
->ipif_recovery_id
!= 0)
12137 (void) untimeout(ipif
->ipif_recovery_id
);
12138 ipif
->ipif_recovery_id
= 0;
12139 if (ill
->ill_net_type
!= IRE_IF_RESOLVER
) {
12140 ipif
->ipif_addr_ready
= 1;
12143 /* NDP will set the ipif_addr_ready flag when it's ready */
12147 err
= ipif_arp_up(ipif
, res_act
, was_dup
);
12152 * This routine restarts IPv4/IPv6 duplicate address detection (DAD)
12153 * when a link has just gone back up.
12156 ipif_nce_start_dad(ipif_t
*ipif
)
12159 ill_t
*ill
= ipif
->ipif_ill
;
12160 boolean_t isv6
= ill
->ill_isv6
;
12163 ncec
= ncec_lookup_illgrp_v6(ipif
->ipif_ill
,
12164 &ipif
->ipif_v6lcl_addr
);
12168 if (ill
->ill_net_type
!= IRE_IF_RESOLVER
||
12169 (ipif
->ipif_flags
& IPIF_UNNUMBERED
) ||
12170 ipif
->ipif_lcl_addr
== INADDR_ANY
) {
12172 * If we can't contact ARP for some reason,
12173 * that's not really a problem. Just send
12174 * out the routing socket notification that
12175 * DAD completion would have done, and continue.
12177 ipif_mask_reply(ipif
);
12178 ipif_up_notify(ipif
);
12179 ipif
->ipif_addr_ready
= 1;
12183 IN6_V4MAPPED_TO_IPADDR(&ipif
->ipif_v6lcl_addr
, v4addr
);
12184 ncec
= ncec_lookup_illgrp_v4(ipif
->ipif_ill
, &v4addr
);
12187 if (ncec
== NULL
) {
12188 ip1dbg(("couldn't find ncec for ipif %p leaving !ready\n",
12192 if (!nce_restart_dad(ncec
)) {
12194 * If we can't restart DAD for some reason, that's not really a
12195 * problem. Just send out the routing socket notification that
12196 * DAD completion would have done, and continue.
12198 ipif_up_notify(ipif
);
12199 ipif
->ipif_addr_ready
= 1;
12201 ncec_refrele(ncec
);
12205 * Restart duplicate address detection on all interfaces on the given ill.
12207 * This is called when an interface transitions from down to up
12208 * (DL_NOTE_LINK_UP) or up to down (DL_NOTE_LINK_DOWN).
12210 * Note that since the underlying physical link has transitioned, we must cause
12211 * at least one routing socket message to be sent here, either via DAD
12212 * completion or just by default on the first ipif. (If we don't do this, then
12213 * in.mpathd will see long delays when doing link-based failure recovery.)
12216 ill_restart_dad(ill_t
*ill
, boolean_t went_up
)
12224 * If layer two doesn't support duplicate address detection, then just
12225 * send the routing socket message now and be done with it.
12227 if (!ill
->ill_isv6
&& arp_no_defense
) {
12228 ip_rts_ifmsg(ill
->ill_ipif
, RTSQ_DEFAULT
);
12232 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
12235 if (ipif
->ipif_flags
& IPIF_UP
) {
12236 ipif_nce_start_dad(ipif
);
12237 } else if (ipif
->ipif_flags
& IPIF_DUPLICATE
) {
12239 * kick off the bring-up process now.
12241 ipif_do_recovery(ipif
);
12244 * Unfortunately, the first ipif is "special"
12245 * and represents the underlying ill in the
12246 * routing socket messages. Thus, when this
12247 * one ipif is down, we must still notify so
12248 * that the user knows the IFF_RUNNING status
12249 * change. (If the first ipif is up, then
12250 * we'll handle eventual routing socket
12251 * notification via DAD completion.)
12253 if (ipif
== ill
->ill_ipif
) {
12254 ip_rts_ifmsg(ill
->ill_ipif
,
12260 * After link down, we'll need to send a new routing
12261 * message when the link comes back, so clear
12264 ipif
->ipif_addr_ready
= 0;
12269 * If we've torn down links, then notify the user right away.
12272 ip_rts_ifmsg(ill
->ill_ipif
, RTSQ_DEFAULT
);
12276 ipsq_delete(ipsq_t
*ipsq
)
12278 ipxop_t
*ipx
= ipsq
->ipsq_xop
;
12280 ipsq
->ipsq_ipst
= NULL
;
12281 ASSERT(ipsq
->ipsq_phyint
== NULL
);
12282 ASSERT(ipsq
->ipsq_xop
!= NULL
);
12283 ASSERT(ipsq
->ipsq_xopq_mphead
== NULL
&& ipx
->ipx_mphead
== NULL
);
12284 ASSERT(ipx
->ipx_pending_mp
== NULL
);
12285 kmem_free(ipsq
, sizeof (ipsq_t
));
12289 ill_up_ipifs_on_ill(ill_t
*ill
, queue_t
*q
, mblk_t
*mp
)
12297 ASSERT(IAM_WRITER_ILL(ill
));
12298 ill
->ill_up_ipifs
= B_TRUE
;
12299 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
12300 if (ipif
->ipif_was_up
) {
12301 if (!(ipif
->ipif_flags
& IPIF_UP
))
12302 err
= ipif_up(ipif
, q
, mp
);
12303 ipif
->ipif_was_up
= B_FALSE
;
12305 ASSERT(err
== EINPROGRESS
);
12310 ill
->ill_up_ipifs
= B_FALSE
;
12315 * This function is called to bring up all the ipifs that were up before
12316 * bringing the ill down via ill_down_ipifs().
12319 ill_up_ipifs(ill_t
*ill
, queue_t
*q
, mblk_t
*mp
)
12323 ASSERT(IAM_WRITER_ILL(ill
));
12325 if (ill
->ill_replumbing
) {
12326 ill
->ill_replumbing
= 0;
12328 * Send down REPLUMB_DONE notification followed by the
12329 * BIND_REQ on the arp stream.
12331 if (!ill
->ill_isv6
)
12332 arp_send_replumb_conf(ill
);
12334 err
= ill_up_ipifs_on_ill(ill
->ill_phyint
->phyint_illv4
, q
, mp
);
12338 return (ill_up_ipifs_on_ill(ill
->ill_phyint
->phyint_illv6
, q
, mp
));
12342 * Bring down any IPIF_UP ipifs on ill. If "logical" is B_TRUE, we bring
12343 * down the ipifs without sending DL_UNBIND_REQ to the driver.
12346 ill_down_ipifs(ill_t
*ill
, boolean_t logical
)
12350 ASSERT(IAM_WRITER_ILL(ill
));
12352 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
12354 * We go through the ipif_down logic even if the ipif
12355 * is already down, since routes can be added based
12356 * on down ipifs. Going through ipif_down once again
12357 * will delete any IREs created based on these routes.
12359 if (ipif
->ipif_flags
& IPIF_UP
)
12360 ipif
->ipif_was_up
= B_TRUE
;
12363 (void) ipif_logical_down(ipif
, NULL
, NULL
);
12364 ipif_non_duplicate(ipif
);
12365 (void) ipif_down_tail(ipif
);
12367 (void) ipif_down(ipif
, NULL
, NULL
);
12373 * Redo source address selection. This makes IXAF_VERIFY_SOURCE take
12374 * a look again at valid source addresses.
12375 * This should be called each time after the set of source addresses has been
12379 ip_update_source_selection(ip_stack_t
*ipst
)
12381 /* We skip past SRC_GENERATION_VERIFY */
12382 if (atomic_inc_32_nv(&ipst
->ips_src_generation
) ==
12383 SRC_GENERATION_VERIFY
)
12384 atomic_inc_32(&ipst
->ips_src_generation
);
12388 * Finish the group join started in ip_sioctl_groupname().
12392 ip_join_illgrps(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
, void *dummy
)
12394 ill_t
*ill
= q
->q_ptr
;
12395 phyint_t
*phyi
= ill
->ill_phyint
;
12396 ipmp_grp_t
*grp
= phyi
->phyint_grp
;
12397 ip_stack_t
*ipst
= ill
->ill_ipst
;
12399 /* IS_UNDER_IPMP() won't work until ipmp_ill_join_illgrp() is called */
12400 ASSERT(!IS_IPMP(ill
) && grp
!= NULL
);
12401 ASSERT(IAM_WRITER_IPSQ(ipsq
));
12403 if (phyi
->phyint_illv4
!= NULL
) {
12404 rw_enter(&ipst
->ips_ipmp_lock
, RW_WRITER
);
12405 VERIFY(grp
->gr_pendv4
-- > 0);
12406 rw_exit(&ipst
->ips_ipmp_lock
);
12407 ipmp_ill_join_illgrp(phyi
->phyint_illv4
, grp
->gr_v4
);
12409 if (phyi
->phyint_illv6
!= NULL
) {
12410 rw_enter(&ipst
->ips_ipmp_lock
, RW_WRITER
);
12411 VERIFY(grp
->gr_pendv6
-- > 0);
12412 rw_exit(&ipst
->ips_ipmp_lock
);
12413 ipmp_ill_join_illgrp(phyi
->phyint_illv6
, grp
->gr_v6
);
12419 * Process an SIOCSLIFGROUPNAME request.
12423 ip_sioctl_groupname(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
12424 ip_ioctl_cmd_t
*ipip
, void *ifreq
)
12426 struct lifreq
*lifr
= ifreq
;
12427 ill_t
*ill
= ipif
->ipif_ill
;
12428 ip_stack_t
*ipst
= ill
->ill_ipst
;
12429 phyint_t
*phyi
= ill
->ill_phyint
;
12430 ipmp_grp_t
*grp
= phyi
->phyint_grp
;
12435 * Note that phyint_grp can only change here, where we're exclusive.
12437 ASSERT(IAM_WRITER_ILL(ill
));
12439 if (ipif
->ipif_id
!= 0 || ill
->ill_usesrc_grp_next
!= NULL
||
12440 (phyi
->phyint_flags
& PHYI_VIRTUAL
))
12443 lifr
->lifr_groupname
[LIFGRNAMSIZ
- 1] = '\0';
12445 rw_enter(&ipst
->ips_ipmp_lock
, RW_WRITER
);
12448 * If the name hasn't changed, there's nothing to do.
12450 if (grp
!= NULL
&& strcmp(grp
->gr_name
, lifr
->lifr_groupname
) == 0)
12454 * Handle requests to rename an IPMP meta-interface.
12456 * Note that creation of the IPMP meta-interface is handled in
12457 * userland through the standard plumbing sequence. As part of the
12458 * plumbing the IPMP meta-interface, its initial groupname is set to
12459 * the name of the interface (see ipif_set_values_tail()).
12461 if (IS_IPMP(ill
)) {
12462 err
= ipmp_grp_rename(grp
, lifr
->lifr_groupname
);
12467 * Handle requests to add or remove an IP interface from a group.
12469 if (lifr
->lifr_groupname
[0] != '\0') { /* add */
12471 * Moves are handled by first removing the interface from
12472 * its existing group, and then adding it to another group.
12473 * So, fail if it's already in a group.
12475 if (IS_UNDER_IPMP(ill
)) {
12480 grp
= ipmp_grp_lookup(lifr
->lifr_groupname
, ipst
);
12487 * Check if the phyint and its ills are suitable for
12488 * inclusion into the group.
12490 if ((err
= ipmp_grp_vet_phyint(grp
, phyi
)) != 0)
12494 * Checks pass; join the group, and enqueue the remaining
12495 * illgrp joins for when we've become part of the group xop
12496 * and are exclusive across its IPSQs. Since qwriter_ip()
12497 * requires an mblk_t to scribble on, and since `mp' will be
12498 * freed as part of completing the ioctl, allocate another.
12500 if ((ipsq_mp
= allocb(0, BPRI_MED
)) == NULL
) {
12506 * Before we drop ipmp_lock, bump gr_pend* to ensure that the
12507 * IPMP meta-interface ills needed by `phyi' cannot go away
12508 * before ip_join_illgrps() is called back. See the comments
12509 * in ip_sioctl_plink_ipmp() for more.
12511 if (phyi
->phyint_illv4
!= NULL
)
12513 if (phyi
->phyint_illv6
!= NULL
)
12516 rw_exit(&ipst
->ips_ipmp_lock
);
12518 ipmp_phyint_join_grp(phyi
, grp
);
12520 qwriter_ip(ill
, ill
->ill_rq
, ipsq_mp
, ip_join_illgrps
,
12521 SWITCH_OP
, B_FALSE
);
12525 * Request to remove the interface from a group. If the
12526 * interface is not in a group, this trivially succeeds.
12528 rw_exit(&ipst
->ips_ipmp_lock
);
12529 if (IS_UNDER_IPMP(ill
))
12530 ipmp_phyint_leave_grp(phyi
);
12534 rw_exit(&ipst
->ips_ipmp_lock
);
12539 * Process an SIOCGLIFBINDING request.
12543 ip_sioctl_get_binding(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
12544 ip_ioctl_cmd_t
*ipip
, void *ifreq
)
12547 struct lifreq
*lifr
= ifreq
;
12548 ip_stack_t
*ipst
= ipif
->ipif_ill
->ill_ipst
;
12550 if (!IS_IPMP(ipif
->ipif_ill
))
12553 rw_enter(&ipst
->ips_ipmp_lock
, RW_READER
);
12554 if ((ill
= ipif
->ipif_bound_ill
) == NULL
)
12555 lifr
->lifr_binding
[0] = '\0';
12557 (void) strlcpy(lifr
->lifr_binding
, ill
->ill_name
, LIFNAMSIZ
);
12558 rw_exit(&ipst
->ips_ipmp_lock
);
12563 * Process an SIOCGLIFGROUPNAME request.
12567 ip_sioctl_get_groupname(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
12568 ip_ioctl_cmd_t
*ipip
, void *ifreq
)
12571 struct lifreq
*lifr
= ifreq
;
12572 ip_stack_t
*ipst
= ipif
->ipif_ill
->ill_ipst
;
12574 rw_enter(&ipst
->ips_ipmp_lock
, RW_READER
);
12575 if ((grp
= ipif
->ipif_ill
->ill_phyint
->phyint_grp
) == NULL
)
12576 lifr
->lifr_groupname
[0] = '\0';
12578 (void) strlcpy(lifr
->lifr_groupname
, grp
->gr_name
, LIFGRNAMSIZ
);
12579 rw_exit(&ipst
->ips_ipmp_lock
);
12584 * Process an SIOCGLIFGROUPINFO request.
12588 ip_sioctl_groupinfo(ipif_t
*dummy_ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
12589 ip_ioctl_cmd_t
*ipip
, void *dummy
)
12592 lifgroupinfo_t
*lifgr
;
12593 ip_stack_t
*ipst
= CONNQ_TO_IPST(q
);
12595 /* ip_wput_nondata() verified mp->b_cont->b_cont */
12596 lifgr
= (lifgroupinfo_t
*)mp
->b_cont
->b_cont
->b_rptr
;
12597 lifgr
->gi_grname
[LIFGRNAMSIZ
- 1] = '\0';
12599 rw_enter(&ipst
->ips_ipmp_lock
, RW_READER
);
12600 if ((grp
= ipmp_grp_lookup(lifgr
->gi_grname
, ipst
)) == NULL
) {
12601 rw_exit(&ipst
->ips_ipmp_lock
);
12604 ipmp_grp_info(grp
, lifgr
);
12605 rw_exit(&ipst
->ips_ipmp_lock
);
12610 ill_dl_down(ill_t
*ill
)
12612 DTRACE_PROBE2(ill__downup
, char *, "ill_dl_down", ill_t
*, ill
);
12615 * The ill is down; unbind but stay attached since we're still
12616 * associated with a PPA. If we have negotiated DLPI capabilites
12617 * with the data link service provider (IDS_OK) then reset them.
12618 * The interval between unbinding and rebinding is potentially
12619 * unbounded hence we cannot assume things will be the same.
12620 * The DLPI capabilities will be probed again when the data link
12623 mblk_t
*mp
= ill
->ill_unbind_mp
;
12625 ip1dbg(("ill_dl_down(%s)\n", ill
->ill_name
));
12627 if (!ill
->ill_replumbing
) {
12628 /* Free all ilms for this ill */
12629 update_conn_ill(ill
, ill
->ill_ipst
);
12631 ill_leave_multicast(ill
);
12634 ill
->ill_unbind_mp
= NULL
;
12636 ip1dbg(("ill_dl_down: %s (%u) for %s\n",
12637 dl_primstr(*(int *)mp
->b_rptr
), *(int *)mp
->b_rptr
,
12639 mutex_enter(&ill
->ill_lock
);
12640 ill
->ill_state_flags
|= ILL_DL_UNBIND_IN_PROGRESS
;
12641 mutex_exit(&ill
->ill_lock
);
12643 * ip_rput does not pass up normal (M_PROTO) DLPI messages
12644 * after ILL_CONDEMNED is set. So in the unplumb case, we call
12645 * ill_capability_dld_disable disable rightaway. If this is not
12646 * an unplumb operation then the disable happens on receipt of
12647 * the capab ack via ip_rput_dlpi_writer ->
12648 * ill_capability_ack_thr. In both cases the order of
12649 * the operations seen by DLD is capability disable followed
12650 * by DL_UNBIND. Also the DLD capability disable needs a
12651 * cv_wait'able context.
12653 if (ill
->ill_state_flags
& ILL_CONDEMNED
)
12654 ill_capability_dld_disable(ill
);
12655 ill_capability_reset(ill
, B_FALSE
);
12656 ill_dlpi_send(ill
, mp
);
12658 mutex_enter(&ill
->ill_lock
);
12659 ill
->ill_dl_up
= 0;
12660 ill_nic_event_dispatch(ill
, 0, NE_DOWN
, NULL
, 0);
12661 mutex_exit(&ill
->ill_lock
);
12665 ill_dlpi_dispatch(ill_t
*ill
, mblk_t
*mp
)
12667 union DL_primitives
*dlp
;
12669 boolean_t waitack
= B_FALSE
;
12671 ASSERT(DB_TYPE(mp
) == M_PROTO
|| DB_TYPE(mp
) == M_PCPROTO
);
12673 dlp
= (union DL_primitives
*)mp
->b_rptr
;
12674 prim
= dlp
->dl_primitive
;
12676 ip1dbg(("ill_dlpi_dispatch: sending %s (%u) to %s\n",
12677 dl_primstr(prim
), prim
, ill
->ill_name
));
12680 case DL_PHYS_ADDR_REQ
:
12682 dl_phys_addr_req_t
*dlpap
= (dl_phys_addr_req_t
*)mp
->b_rptr
;
12683 ill
->ill_phys_addr_pend
= dlpap
->dl_addr_type
;
12687 mutex_enter(&ill
->ill_lock
);
12688 ill
->ill_state_flags
&= ~ILL_DL_UNBIND_IN_PROGRESS
;
12689 mutex_exit(&ill
->ill_lock
);
12694 * Except for the ACKs for the M_PCPROTO messages, all other ACKs
12695 * are dropped by ip_rput() if ILL_CONDEMNED is set. Therefore
12696 * we only wait for the ACK of the DL_UNBIND_REQ.
12698 mutex_enter(&ill
->ill_lock
);
12699 if (!(ill
->ill_state_flags
& ILL_CONDEMNED
) ||
12700 (prim
== DL_UNBIND_REQ
)) {
12701 ill
->ill_dlpi_pending
= prim
;
12705 mutex_exit(&ill
->ill_lock
);
12706 DTRACE_PROBE3(ill__dlpi
, char *, "ill_dlpi_dispatch",
12707 char *, dl_primstr(prim
), ill_t
*, ill
);
12708 putnext(ill
->ill_wq
, mp
);
12711 * There is no ack for DL_NOTIFY_CONF messages
12713 if (waitack
&& prim
== DL_NOTIFY_CONF
)
12714 ill_dlpi_done(ill
, prim
);
12718 * Helper function for ill_dlpi_send().
12722 ill_dlpi_send_writer(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
, void *arg
)
12724 ill_dlpi_send(q
->q_ptr
, mp
);
12728 * Send a DLPI control message to the driver but make sure there
12729 * is only one outstanding message. Uses ill_dlpi_pending to tell
12730 * when it must queue. ip_rput_dlpi_writer calls ill_dlpi_done()
12731 * when an ACK or a NAK is received to process the next queued message.
12734 ill_dlpi_send(ill_t
*ill
, mblk_t
*mp
)
12738 ASSERT(DB_TYPE(mp
) == M_PROTO
|| DB_TYPE(mp
) == M_PCPROTO
);
12741 * To ensure that any DLPI requests for current exclusive operation
12742 * are always completely sent before any DLPI messages for other
12743 * operations, require writer access before enqueuing.
12745 if (!IAM_WRITER_ILL(ill
)) {
12747 /* qwriter_ip() does the ill_refrele() */
12748 qwriter_ip(ill
, ill
->ill_wq
, mp
, ill_dlpi_send_writer
,
12753 mutex_enter(&ill
->ill_lock
);
12754 if (ill
->ill_dlpi_pending
!= DL_PRIM_INVAL
) {
12755 /* Must queue message. Tail insertion */
12756 mpp
= &ill
->ill_dlpi_deferred
;
12757 while (*mpp
!= NULL
)
12758 mpp
= &((*mpp
)->b_next
);
12760 ip1dbg(("ill_dlpi_send: deferring request for %s "
12761 "while %s pending\n", ill
->ill_name
,
12762 dl_primstr(ill
->ill_dlpi_pending
)));
12765 mutex_exit(&ill
->ill_lock
);
12768 mutex_exit(&ill
->ill_lock
);
12769 ill_dlpi_dispatch(ill
, mp
);
12773 ill_capability_send(ill_t
*ill
, mblk_t
*mp
)
12775 ill
->ill_capab_pending_cnt
++;
12776 ill_dlpi_send(ill
, mp
);
12780 ill_capability_done(ill_t
*ill
)
12782 ASSERT(ill
->ill_capab_pending_cnt
!= 0);
12784 ill_dlpi_done(ill
, DL_CAPABILITY_REQ
);
12786 ill
->ill_capab_pending_cnt
--;
12787 if (ill
->ill_capab_pending_cnt
== 0 &&
12788 ill
->ill_dlpi_capab_state
== IDCS_OK
)
12789 ill_capability_reset_alloc(ill
);
12793 * Send all deferred DLPI messages without waiting for their ACKs.
12796 ill_dlpi_send_deferred(ill_t
*ill
)
12798 mblk_t
*mp
, *nextmp
;
12801 * Clear ill_dlpi_pending so that the message is not queued in
12804 mutex_enter(&ill
->ill_lock
);
12805 ill
->ill_dlpi_pending
= DL_PRIM_INVAL
;
12806 mp
= ill
->ill_dlpi_deferred
;
12807 ill
->ill_dlpi_deferred
= NULL
;
12808 mutex_exit(&ill
->ill_lock
);
12810 for (; mp
!= NULL
; mp
= nextmp
) {
12811 nextmp
= mp
->b_next
;
12813 ill_dlpi_send(ill
, mp
);
12818 * Clear all the deferred DLPI messages. Called on receiving an M_ERROR
12822 ill_dlpi_clear_deferred(ill_t
*ill
)
12824 mblk_t
*mp
, *nextmp
;
12826 mutex_enter(&ill
->ill_lock
);
12827 ill
->ill_dlpi_pending
= DL_PRIM_INVAL
;
12828 mp
= ill
->ill_dlpi_deferred
;
12829 ill
->ill_dlpi_deferred
= NULL
;
12830 mutex_exit(&ill
->ill_lock
);
12832 for (; mp
!= NULL
; mp
= nextmp
) {
12833 nextmp
= mp
->b_next
;
12839 * Check if the DLPI primitive `prim' is pending; print a warning if not.
12842 ill_dlpi_pending(ill_t
*ill
, t_uscalar_t prim
)
12844 t_uscalar_t pending
;
12846 mutex_enter(&ill
->ill_lock
);
12847 if (ill
->ill_dlpi_pending
== prim
) {
12848 mutex_exit(&ill
->ill_lock
);
12853 * During teardown, ill_dlpi_dispatch() will send DLPI requests
12854 * without waiting, so don't print any warnings in that case.
12856 if (ill
->ill_state_flags
& ILL_CONDEMNED
) {
12857 mutex_exit(&ill
->ill_lock
);
12860 pending
= ill
->ill_dlpi_pending
;
12861 mutex_exit(&ill
->ill_lock
);
12863 if (pending
== DL_PRIM_INVAL
) {
12864 (void) mi_strlog(ill
->ill_rq
, 1, SL_CONSOLE
|SL_ERROR
|SL_TRACE
,
12865 "received unsolicited ack for %s on %s\n",
12866 dl_primstr(prim
), ill
->ill_name
);
12868 (void) mi_strlog(ill
->ill_rq
, 1, SL_CONSOLE
|SL_ERROR
|SL_TRACE
,
12869 "received unexpected ack for %s on %s (expecting %s)\n",
12870 dl_primstr(prim
), ill
->ill_name
, dl_primstr(pending
));
12876 * Complete the current DLPI operation associated with `prim' on `ill' and
12877 * start the next queued DLPI operation (if any). If there are no queued DLPI
12878 * operations and the ill's current exclusive IPSQ operation has finished
12879 * (i.e., ipsq_current_finish() was called), then clear ipsq_current_ipif to
12880 * allow the next exclusive IPSQ operation to begin upon ipsq_exit(). See
12881 * the comments above ipsq_current_finish() for details.
12884 ill_dlpi_done(ill_t
*ill
, t_uscalar_t prim
)
12887 ipsq_t
*ipsq
= ill
->ill_phyint
->phyint_ipsq
;
12888 ipxop_t
*ipx
= ipsq
->ipsq_xop
;
12890 ASSERT(IAM_WRITER_IPSQ(ipsq
));
12891 mutex_enter(&ill
->ill_lock
);
12893 ASSERT(prim
!= DL_PRIM_INVAL
);
12894 ASSERT(ill
->ill_dlpi_pending
== prim
);
12896 ip1dbg(("ill_dlpi_done: %s has completed %s (%u)\n", ill
->ill_name
,
12897 dl_primstr(ill
->ill_dlpi_pending
), ill
->ill_dlpi_pending
));
12899 if ((mp
= ill
->ill_dlpi_deferred
) == NULL
) {
12900 ill
->ill_dlpi_pending
= DL_PRIM_INVAL
;
12901 if (ipx
->ipx_current_done
) {
12902 mutex_enter(&ipx
->ipx_lock
);
12903 ipx
->ipx_current_ipif
= NULL
;
12904 mutex_exit(&ipx
->ipx_lock
);
12906 cv_signal(&ill
->ill_cv
);
12907 mutex_exit(&ill
->ill_lock
);
12911 ill
->ill_dlpi_deferred
= mp
->b_next
;
12913 mutex_exit(&ill
->ill_lock
);
12915 ill_dlpi_dispatch(ill
, mp
);
12919 * Queue a (multicast) DLPI control message to be sent to the driver by
12920 * later calling ill_dlpi_send_queued.
12921 * We queue them while holding a lock (ill_mcast_lock) to ensure that they
12922 * are sent in order i.e., prevent a DL_DISABMULTI_REQ and DL_ENABMULTI_REQ
12923 * for the same group to race.
12924 * We send DLPI control messages in order using ill_lock.
12925 * For IPMP we should be called on the cast_ill.
12928 ill_dlpi_queue(ill_t
*ill
, mblk_t
*mp
)
12932 ASSERT(DB_TYPE(mp
) == M_PROTO
|| DB_TYPE(mp
) == M_PCPROTO
);
12934 mutex_enter(&ill
->ill_lock
);
12935 /* Must queue message. Tail insertion */
12936 mpp
= &ill
->ill_dlpi_deferred
;
12937 while (*mpp
!= NULL
)
12938 mpp
= &((*mpp
)->b_next
);
12941 mutex_exit(&ill
->ill_lock
);
12945 * Send the messages that were queued. Make sure there is only
12946 * one outstanding message. ip_rput_dlpi_writer calls ill_dlpi_done()
12947 * when an ACK or a NAK is received to process the next queued message.
12948 * For IPMP we are called on the upper ill, but when send what is queued
12952 ill_dlpi_send_queued(ill_t
*ill
)
12955 union DL_primitives
*dlp
;
12957 ill_t
*release_ill
= NULL
;
12959 if (IS_IPMP(ill
)) {
12960 /* On the upper IPMP ill. */
12961 release_ill
= ipmp_illgrp_hold_cast_ill(ill
->ill_grp
);
12962 if (release_ill
== NULL
) {
12963 /* Avoid ever sending anything down to the ipmpstub */
12968 mutex_enter(&ill
->ill_lock
);
12969 while ((mp
= ill
->ill_dlpi_deferred
) != NULL
) {
12970 if (ill
->ill_dlpi_pending
!= DL_PRIM_INVAL
) {
12971 /* Can't send. Somebody else will send it */
12972 mutex_exit(&ill
->ill_lock
);
12975 ill
->ill_dlpi_deferred
= mp
->b_next
;
12977 if (!ill
->ill_dl_up
) {
12979 * Nobody there. All multicast addresses will be
12980 * re-joined when we get the DL_BIND_ACK bringing the
12986 dlp
= (union DL_primitives
*)mp
->b_rptr
;
12987 prim
= dlp
->dl_primitive
;
12989 if (!(ill
->ill_state_flags
& ILL_CONDEMNED
) ||
12990 (prim
== DL_UNBIND_REQ
)) {
12991 ill
->ill_dlpi_pending
= prim
;
12993 mutex_exit(&ill
->ill_lock
);
12995 DTRACE_PROBE3(ill__dlpi
, char *, "ill_dlpi_send_queued",
12996 char *, dl_primstr(prim
), ill_t
*, ill
);
12997 putnext(ill
->ill_wq
, mp
);
12998 mutex_enter(&ill
->ill_lock
);
13000 mutex_exit(&ill
->ill_lock
);
13002 if (release_ill
!= NULL
)
13003 ill_refrele(release_ill
);
13007 * Queue an IP (IGMP/MLD) message to be sent by IP from
13008 * ill_mcast_send_queued
13009 * We queue them while holding a lock (ill_mcast_lock) to ensure that they
13010 * are sent in order i.e., prevent a IGMP leave and IGMP join for the same
13012 * We send them in order using ill_lock.
13013 * For IPMP we are called on the upper ill, but we queue on the cast_ill.
13016 ill_mcast_queue(ill_t
*ill
, mblk_t
*mp
)
13019 ill_t
*release_ill
= NULL
;
13021 ASSERT(RW_LOCK_HELD(&ill
->ill_mcast_lock
));
13023 if (IS_IPMP(ill
)) {
13024 /* On the upper IPMP ill. */
13025 release_ill
= ipmp_illgrp_hold_cast_ill(ill
->ill_grp
);
13026 if (release_ill
== NULL
) {
13027 /* Discard instead of queuing for the ipmp interface */
13028 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
13029 ip_drop_output("ipIfStatsOutDiscards - no cast_ill",
13037 mutex_enter(&ill
->ill_lock
);
13038 /* Must queue message. Tail insertion */
13039 mpp
= &ill
->ill_mcast_deferred
;
13040 while (*mpp
!= NULL
)
13041 mpp
= &((*mpp
)->b_next
);
13044 mutex_exit(&ill
->ill_lock
);
13045 if (release_ill
!= NULL
)
13046 ill_refrele(release_ill
);
13050 * Send the IP packets that were queued by ill_mcast_queue.
13051 * These are IGMP/MLD packets.
13053 * For IPMP we are called on the upper ill, but when send what is queued
13056 * Request loopback of the report if we are acting as a multicast
13057 * router, so that the process-level routing demon can hear it.
13058 * This will run multiple times for the same group if there are members
13059 * on the same group for multiple ipif's on the same ill. The
13060 * igmp_input/mld_input code will suppress this due to the loopback thus we
13061 * always loopback membership report.
13063 * We also need to make sure that this does not get load balanced
13064 * by IPMP. We do this by passing an ill to ip_output_simple.
13067 ill_mcast_send_queued(ill_t
*ill
)
13070 ip_xmit_attr_t ixas
;
13071 ill_t
*release_ill
= NULL
;
13073 if (IS_IPMP(ill
)) {
13074 /* On the upper IPMP ill. */
13075 release_ill
= ipmp_illgrp_hold_cast_ill(ill
->ill_grp
);
13076 if (release_ill
== NULL
) {
13078 * We should have no messages on the ipmp interface
13079 * but no point in trying to send them.
13085 bzero(&ixas
, sizeof (ixas
));
13086 ixas
.ixa_zoneid
= ALL_ZONES
;
13087 ixas
.ixa_cred
= kcred
;
13088 ixas
.ixa_cpid
= NOPID
;
13090 * Here we set ixa_ifindex. If IPMP it will be the lower ill which
13091 * makes ip_select_route pick the IRE_MULTICAST for the cast_ill.
13092 * That is necessary to handle IGMP/MLD snooping switches.
13094 ixas
.ixa_ifindex
= ill
->ill_phyint
->phyint_ifindex
;
13095 ixas
.ixa_ipst
= ill
->ill_ipst
;
13097 mutex_enter(&ill
->ill_lock
);
13098 while ((mp
= ill
->ill_mcast_deferred
) != NULL
) {
13099 ill
->ill_mcast_deferred
= mp
->b_next
;
13101 if (!ill
->ill_dl_up
) {
13103 * Nobody there. Just drop the ip packets.
13104 * IGMP/MLD will resend later, if this is a replumb.
13109 mutex_enter(&ill
->ill_phyint
->phyint_lock
);
13110 if (IS_UNDER_IPMP(ill
) && !ipmp_ill_is_active(ill
)) {
13112 * When the ill is getting deactivated, we only want to
13113 * send the DLPI messages, so drop IGMP/MLD packets.
13114 * DLPI messages are handled by ill_dlpi_send_queued()
13116 mutex_exit(&ill
->ill_phyint
->phyint_lock
);
13120 mutex_exit(&ill
->ill_phyint
->phyint_lock
);
13121 mutex_exit(&ill
->ill_lock
);
13123 /* Check whether we are sending IPv4 or IPv6. */
13124 if (ill
->ill_isv6
) {
13125 ip6_t
*ip6h
= (ip6_t
*)mp
->b_rptr
;
13127 ixas
.ixa_multicast_ttl
= ip6h
->ip6_hops
;
13128 ixas
.ixa_flags
= IXAF_BASIC_SIMPLE_V6
;
13130 ipha_t
*ipha
= (ipha_t
*)mp
->b_rptr
;
13132 ixas
.ixa_multicast_ttl
= ipha
->ipha_ttl
;
13133 ixas
.ixa_flags
= IXAF_BASIC_SIMPLE_V4
;
13134 ixas
.ixa_flags
&= ~IXAF_SET_ULP_CKSUM
;
13136 ixas
.ixa_flags
&= ~IXAF_VERIFY_SOURCE
;
13137 ixas
.ixa_flags
|= IXAF_MULTICAST_LOOP
| IXAF_SET_SOURCE
;
13138 (void) ip_output_simple(mp
, &ixas
);
13139 ixa_cleanup(&ixas
);
13141 mutex_enter(&ill
->ill_lock
);
13143 mutex_exit(&ill
->ill_lock
);
13146 if (release_ill
!= NULL
)
13147 ill_refrele(release_ill
);
13151 * Take down a specific interface, but don't lose any information about it.
13152 * (Always called as writer.)
13153 * This function goes through the down sequence even if the interface is
13154 * already down. There are 2 reasons.
13155 * a. Currently we permit interface routes that depend on down interfaces
13156 * to be added. This behaviour itself is questionable. However it appears
13157 * that both Solaris and 4.3 BSD have exhibited this behaviour for a long
13158 * time. We go thru the cleanup in order to remove these routes.
13159 * b. The bringup of the interface could fail in ill_dl_up i.e. we get
13160 * DL_ERROR_ACK in response to the DL_BIND request. The interface is
13161 * down, but we need to cleanup i.e. do ill_dl_down and
13162 * ip_rput_dlpi_writer (DL_ERROR_ACK) -> ipif_down.
13166 * Model of reference to interfaces.
13168 * The following members in ipif_t track references to the ipif.
13169 * int ipif_refcnt; Active reference count
13171 * The following members in ill_t track references to the ill.
13172 * int ill_refcnt; active refcnt
13173 * uint_t ill_ire_cnt; Number of ires referencing ill
13174 * uint_t ill_ncec_cnt; Number of ncecs referencing ill
13175 * uint_t ill_nce_cnt; Number of nces referencing ill
13176 * uint_t ill_ilm_cnt; Number of ilms referencing ill
13178 * Reference to an ipif or ill can be obtained in any of the following ways.
13180 * Through the lookup functions ipif_lookup_* / ill_lookup_* functions
13181 * Pointers to ipif / ill from other data structures viz ire and conn.
13182 * Implicit reference to the ipif / ill by holding a reference to the ire.
13184 * The ipif/ill lookup functions return a reference held ipif / ill.
13185 * ipif_refcnt and ill_refcnt track the reference counts respectively.
13186 * This is a purely dynamic reference count associated with threads holding
13187 * references to the ipif / ill. Pointers from other structures do not
13188 * count towards this reference count.
13190 * ill_ire_cnt is the number of ire's associated with the
13191 * ill. This is incremented whenever a new ire is created referencing the
13192 * ill. This is done atomically inside ire_add_v[46] where the ire is
13193 * actually added to the ire hash table. The count is decremented in
13194 * ire_inactive where the ire is destroyed.
13196 * ill_ncec_cnt is the number of ncec's referencing the ill thru ncec_ill.
13197 * This is incremented atomically in
13198 * ndp_add_v4()/ndp_add_v6() where the nce is actually added to the
13199 * table. Similarly it is decremented in ncec_inactive() where the ncec
13202 * ill_nce_cnt is the number of nce's referencing the ill thru nce_ill. This is
13203 * incremented atomically in nce_add() where the nce is actually added to the
13204 * ill_nce. Similarly it is decremented in nce_inactive() where the nce
13207 * ill_ilm_cnt is the ilm's reference to the ill. It is incremented in
13208 * ilm_add() and decremented before the ilm is freed in ilm_delete().
13210 * Flow of ioctls involving interface down/up
13212 * The following is the sequence of an attempt to set some critical flags on an
13216 * wait for ipif to be quiescent
13218 * ip_sioctl_flags_tail
13220 * All set ioctls that involve down/up sequence would have a skeleton similar
13221 * to the above. All the *tail functions are called after the refcounts have
13222 * dropped to the appropriate values.
13224 * SIOC ioctls during the IPIF_CHANGING interval.
13226 * Threads handling SIOC set ioctls serialize on the squeue, but this
13227 * is not done for SIOC get ioctls. Since a set ioctl can cause several
13228 * steps of internal changes to the state, some of which are visible in
13229 * ipif_flags (such as IFF_UP being cleared and later set), and we want
13230 * the set ioctl to be atomic related to the get ioctls, the SIOC get code
13231 * will wait and restart ioctls if IPIF_CHANGING is set. The mblk is then
13232 * enqueued in the ipsq and the operation is restarted by ipsq_exit() when
13233 * the current exclusive operation completes. The IPIF_CHANGING check
13234 * and enqueue is atomic using the ill_lock and ipsq_lock. The
13235 * lookup is done holding the ill_lock. Hence the ill/ipif state flags can't
13236 * change while the ill_lock is held. Before dropping the ill_lock we acquire
13237 * the ipsq_lock and call ipsq_enq. This ensures that ipsq_exit can't finish
13238 * until we release the ipsq_lock, even though the ill/ipif state flags
13239 * can change after we drop the ill_lock.
13242 ipif_down(ipif_t
*ipif
, queue_t
*q
, mblk_t
*mp
)
13244 ill_t
*ill
= ipif
->ipif_ill
;
13247 boolean_t ipif_was_up
= B_FALSE
;
13248 ip_stack_t
*ipst
= ill
->ill_ipst
;
13250 ASSERT(IAM_WRITER_IPIF(ipif
));
13252 ip1dbg(("ipif_down(%s:%u)\n", ill
->ill_name
, ipif
->ipif_id
));
13254 DTRACE_PROBE3(ipif__downup
, char *, "ipif_down",
13255 ill_t
*, ill
, ipif_t
*, ipif
);
13257 if (ipif
->ipif_flags
& IPIF_UP
) {
13258 mutex_enter(&ill
->ill_lock
);
13259 ipif
->ipif_flags
&= ~IPIF_UP
;
13260 ASSERT(ill
->ill_ipif_up_count
> 0);
13261 --ill
->ill_ipif_up_count
;
13262 mutex_exit(&ill
->ill_lock
);
13263 ipif_was_up
= B_TRUE
;
13264 /* Update status in SCTP's list */
13265 sctp_update_ipif(ipif
, SCTP_IPIF_DOWN
);
13266 ill_nic_event_dispatch(ipif
->ipif_ill
,
13267 MAP_IPIF_ID(ipif
->ipif_id
), NE_LIF_DOWN
, NULL
, 0);
13271 * Removal of the last ipif from an ill may result in a DL_UNBIND
13272 * being sent to the driver, and we must not send any data packets to
13273 * the driver after the DL_UNBIND_REQ. To ensure this, all the
13274 * ire and nce entries used in the data path will be cleaned
13275 * up, and we also set the ILL_DOWN_IN_PROGRESS bit to make
13276 * sure on new entries will be added until the ill is bound
13277 * again. The ILL_DOWN_IN_PROGRESS bit is turned off upon
13278 * receipt of a DL_BIND_ACK.
13280 if (ill
->ill_wq
!= NULL
&& !ill
->ill_logical_down
&&
13281 ill
->ill_ipif_up_count
== 0 && ill
->ill_ipif_dup_count
== 0 &&
13283 ill
->ill_state_flags
|= ILL_DOWN_IN_PROGRESS
;
13287 * Blow away memberships we established in ipif_multicast_up().
13289 ipif_multicast_down(ipif
);
13292 * Remove from the mapping for __sin6_src_id. We insert only
13293 * when the address is not INADDR_ANY. As IPv4 addresses are
13294 * stored as mapped addresses, we need to check for mapped
13297 if (ipif_was_up
&& !IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6lcl_addr
) &&
13298 !IN6_IS_ADDR_V4MAPPED_ANY(&ipif
->ipif_v6lcl_addr
) &&
13299 !(ipif
->ipif_flags
& IPIF_NOLOCAL
)) {
13302 err
= ip_srcid_remove(&ipif
->ipif_v6lcl_addr
,
13303 ipif
->ipif_zoneid
, ipst
);
13305 ip0dbg(("ipif_down: srcid_remove %d\n", err
));
13310 /* only delete if we'd added ire's before */
13311 if (ipif
->ipif_isv6
)
13312 ipif_delete_ires_v6(ipif
);
13314 ipif_delete_ires_v4(ipif
);
13317 if (ipif_was_up
&& ill
->ill_ipif_up_count
== 0) {
13319 * Since the interface is now down, it may have just become
13320 * inactive. Note that this needs to be done even for a
13321 * lll_logical_down(), or ARP entries will not get correctly
13322 * restored when the interface comes back up.
13324 if (IS_UNDER_IPMP(ill
))
13325 ipmp_ill_refresh_active(ill
);
13329 * neighbor-discovery or arp entries for this interface. The ipif
13330 * has to be quiesced, so we walk all the nce's and delete those
13331 * that point at the ipif->ipif_ill. At the same time, we also
13332 * update IPMP so that ipifs for data addresses are unbound. We dont
13333 * call ipif_arp_down to DL_UNBIND the arp stream itself here, but defer
13334 * that for ipif_down_tail()
13336 ipif_nce_down(ipif
);
13339 * If this is the last ipif on the ill, we also need to remove
13340 * any IREs with ire_ill set. Otherwise ipif_is_quiescent() will
13343 if (ill
->ill_ipif_up_count
== 0 && ill
->ill_ipif_dup_count
== 0)
13344 ire_walk_ill(0, 0, ill_downi
, ill
, ill
);
13347 * Walk all CONNs that can have a reference on an ire for this
13348 * ipif (we actually walk all that now have stale references).
13350 ipcl_walk(conn_ixa_cleanup
, (void *)B_TRUE
, ipst
);
13353 * If mp is NULL the caller will wait for the appropriate refcnt.
13354 * Eg. ip_sioctl_removeif -> ipif_free -> ipif_down
13355 * and ill_delete -> ipif_free -> ipif_down
13363 connp
= Q_TO_CONN(q
);
13364 mutex_enter(&connp
->conn_lock
);
13368 mutex_enter(&ill
->ill_lock
);
13370 * Are there any ire's pointing to this ipif that are still active ?
13371 * If this is the last ipif going down, are there any ire's pointing
13372 * to this ill that are still active ?
13374 if (ipif_is_quiescent(ipif
)) {
13375 mutex_exit(&ill
->ill_lock
);
13377 mutex_exit(&connp
->conn_lock
);
13381 ip1dbg(("ipif_down: need to wait, adding pending mp %s ill %p",
13382 ill
->ill_name
, (void *)ill
));
13384 * Enqueue the mp atomically in ipsq_pending_mp. When the refcount
13385 * drops down, the operation will be restarted by ipif_ill_refrele_tail
13386 * which in turn is called by the last refrele on the ipif/ill/ire.
13388 success
= ipsq_pending_mp_add(connp
, ipif
, q
, mp
, IPIF_DOWN
);
13390 /* The conn is closing. So just return */
13391 ASSERT(connp
!= NULL
);
13392 mutex_exit(&ill
->ill_lock
);
13393 mutex_exit(&connp
->conn_lock
);
13397 mutex_exit(&ill
->ill_lock
);
13399 mutex_exit(&connp
->conn_lock
);
13400 return (EINPROGRESS
);
13404 ipif_down_tail(ipif_t
*ipif
)
13406 ill_t
*ill
= ipif
->ipif_ill
;
13409 DTRACE_PROBE3(ipif__downup
, char *, "ipif_down_tail",
13410 ill_t
*, ill
, ipif_t
*, ipif
);
13413 * Skip any loopback interface (null wq).
13414 * If this is the last logical interface on the ill
13415 * have ill_dl_down tell the driver we are gone (unbind)
13416 * Note that lun 0 can ipif_down even though
13417 * there are other logical units that are up.
13418 * This occurs e.g. when we change a "significant" IFF_ flag.
13420 if (ill
->ill_wq
!= NULL
&& !ill
->ill_logical_down
&&
13421 ill
->ill_ipif_up_count
== 0 && ill
->ill_ipif_dup_count
== 0 &&
13425 if (!ipif
->ipif_isv6
)
13426 err
= ipif_arp_down(ipif
);
13428 ill
->ill_logical_down
= 0;
13430 ip_rts_ifmsg(ipif
, RTSQ_DEFAULT
);
13431 ip_rts_newaddrmsg(RTM_DELETE
, 0, ipif
, RTSQ_DEFAULT
);
13436 * Bring interface logically down without bringing the physical interface
13437 * down e.g. when the netmask is changed. This avoids long lasting link
13438 * negotiations between an ethernet interface and a certain switches.
13441 ipif_logical_down(ipif_t
*ipif
, queue_t
*q
, mblk_t
*mp
)
13443 DTRACE_PROBE3(ipif__downup
, char *, "ipif_logical_down",
13444 ill_t
*, ipif
->ipif_ill
, ipif_t
*, ipif
);
13447 * The ill_logical_down flag is a transient flag. It is set here
13448 * and is cleared once the down has completed in ipif_down_tail.
13449 * This flag does not indicate whether the ill stream is in the
13450 * DL_BOUND state with the driver. Instead this flag is used by
13451 * ipif_down_tail to determine whether to DL_UNBIND the stream with
13452 * the driver. The state of the ill stream i.e. whether it is
13453 * DL_BOUND with the driver or not is indicated by the ill_dl_up flag.
13455 ipif
->ipif_ill
->ill_logical_down
= 1;
13456 return (ipif_down(ipif
, q
, mp
));
13460 * Initiate deallocate of an IPIF. Always called as writer. Called by
13461 * ill_delete or ip_sioctl_removeif.
13464 ipif_free(ipif_t
*ipif
)
13466 ip_stack_t
*ipst
= ipif
->ipif_ill
->ill_ipst
;
13468 ASSERT(IAM_WRITER_IPIF(ipif
));
13470 if (ipif
->ipif_recovery_id
!= 0)
13471 (void) untimeout(ipif
->ipif_recovery_id
);
13472 ipif
->ipif_recovery_id
= 0;
13475 * Take down the interface. We can be called either from ill_delete
13476 * or from ip_sioctl_removeif.
13478 (void) ipif_down(ipif
, NULL
, NULL
);
13481 * Now that the interface is down, there's no chance it can still
13482 * become a duplicate. Cancel any timer that may have been set while
13485 if (ipif
->ipif_recovery_id
!= 0)
13486 (void) untimeout(ipif
->ipif_recovery_id
);
13487 ipif
->ipif_recovery_id
= 0;
13489 rw_enter(&ipst
->ips_ill_g_lock
, RW_WRITER
);
13490 /* Remove pointers to this ill in the multicast routing tables */
13491 reset_mrt_vif_ipif(ipif
);
13492 /* If necessary, clear the cached source ipif rotor. */
13493 if (ipif
->ipif_ill
->ill_src_ipif
== ipif
)
13494 ipif
->ipif_ill
->ill_src_ipif
= NULL
;
13495 rw_exit(&ipst
->ips_ill_g_lock
);
13499 ipif_free_tail(ipif_t
*ipif
)
13501 ip_stack_t
*ipst
= ipif
->ipif_ill
->ill_ipst
;
13504 * Need to hold both ill_g_lock and ill_lock while
13505 * inserting or removing an ipif from the linked list
13506 * of ipifs hanging off the ill.
13508 rw_enter(&ipst
->ips_ill_g_lock
, RW_WRITER
);
13511 ipif_trace_cleanup(ipif
);
13514 /* Ask SCTP to take it out of it list */
13515 sctp_update_ipif(ipif
, SCTP_IPIF_REMOVE
);
13516 ip_rts_newaddrmsg(RTM_FREEADDR
, 0, ipif
, RTSQ_DEFAULT
);
13518 /* Get it out of the ILL interface list. */
13520 rw_exit(&ipst
->ips_ill_g_lock
);
13522 ASSERT(!(ipif
->ipif_flags
& (IPIF_UP
| IPIF_DUPLICATE
)));
13523 ASSERT(ipif
->ipif_recovery_id
== 0);
13524 ASSERT(ipif
->ipif_ire_local
== NULL
);
13525 ASSERT(ipif
->ipif_ire_if
== NULL
);
13527 /* Free the memory. */
13532 * Sets `buf' to an ipif name of the form "ill_name:id", or "ill_name" if "id"
13536 ipif_get_name(const ipif_t
*ipif
, char *buf
, int len
)
13538 char lbuf
[LIFNAMSIZ
];
13543 name
= ipif
->ipif_ill
->ill_name
;
13544 name_len
= ipif
->ipif_ill
->ill_name_length
;
13545 if (ipif
->ipif_id
!= 0) {
13546 (void) sprintf(lbuf
, "%s%c%d", name
, IPIF_SEPARATOR_CHAR
,
13549 name_len
= mi_strlen(name
) + 1;
13553 len
= MIN(len
, name_len
);
13554 bcopy(name
, buf
, len
);
13558 * Sets `buf' to an ill name.
13561 ill_get_name(const ill_t
*ill
, char *buf
, int len
)
13566 name
= ill
->ill_name
;
13567 name_len
= ill
->ill_name_length
;
13570 len
= MIN(len
, name_len
);
13571 bcopy(name
, buf
, len
);
13575 * Find an IPIF based on the name passed in. Names can be of the form <phys>
13576 * (e.g., le0) or <phys>:<#> (e.g., le0:1). When there is no colon, the
13577 * implied unit id is zero. <phys> must correspond to the name of an ILL.
13578 * (May be called as writer.)
13581 ipif_lookup_on_name(char *name
, size_t namelen
, boolean_t do_alloc
,
13582 boolean_t
*exists
, boolean_t isv6
, zoneid_t zoneid
, ip_stack_t
*ipst
)
13590 boolean_t did_alloc
= B_FALSE
;
13594 * If the caller wants to us to create the ipif, make sure we have a
13597 ASSERT(!do_alloc
|| zoneid
!= ALL_ZONES
);
13599 if (namelen
== 0) {
13604 /* Look for a colon in the name. */
13605 endp
= &name
[namelen
];
13606 for (cp
= endp
; --cp
> name
; ) {
13607 if (*cp
== IPIF_SEPARATOR_CHAR
)
13611 if (*cp
== IPIF_SEPARATOR_CHAR
) {
13613 * Reject any non-decimal aliases for logical
13614 * interfaces. Aliases with leading zeroes
13615 * are also rejected as they introduce ambiguity
13616 * in the naming of the interfaces.
13617 * In order to confirm with existing semantics,
13618 * and to not break any programs/script relying
13619 * on that behaviour, if<0>:0 is considered to be
13620 * a valid interface.
13622 * If alias has two or more digits and the first
13625 if (&cp
[2] < endp
&& cp
[1] == '0') {
13637 * Look up the ILL, based on the portion of the name
13638 * before the slash. ill_lookup_on_name returns a held ill.
13639 * Temporary to check whether ill exists already. If so
13640 * ill_lookup_on_name will clear it.
13642 ill
= ill_lookup_on_name(name
, do_alloc
, isv6
,
13648 /* Establish the unit number in the name. */
13650 if (cp
< endp
&& *endp
== '\0') {
13651 /* If there was a colon, the unit number follows. */
13653 if (ddi_strtol(cp
, NULL
, 0, &id
) != 0) {
13659 mutex_enter(&ill
->ill_lock
);
13660 /* Now see if there is an IPIF with this unit number. */
13661 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
13662 if (ipif
->ipif_id
== id
) {
13663 if (zoneid
!= ALL_ZONES
&&
13664 zoneid
!= ipif
->ipif_zoneid
&&
13665 ipif
->ipif_zoneid
!= ALL_ZONES
) {
13666 mutex_exit(&ill
->ill_lock
);
13670 if (IPIF_CAN_LOOKUP(ipif
)) {
13671 ipif_refhold_locked(ipif
);
13672 mutex_exit(&ill
->ill_lock
);
13676 * Drop locks before calling ill_refrele
13677 * since it can potentially call into
13678 * ipif_ill_refrele_tail which can end up
13679 * in trying to acquire any lock.
13688 mutex_exit(&ill
->ill_lock
);
13694 * If none found, atomically allocate and return a new one.
13695 * Historically, we used IRE_LOOPBACK only for lun 0, and IRE_LOCAL
13696 * to support "receive only" use of lo0:1 etc. as is still done
13697 * below as an initial guess.
13698 * However, this is now likely to be overriden later in ipif_up_done()
13699 * when we know for sure what address has been configured on the
13700 * interface, since we might have more than one loopback interface
13701 * with a loopback address, e.g. in the case of zones, and all the
13702 * interfaces with loopback addresses need to be marked IRE_LOOPBACK.
13704 if (ill
->ill_net_type
== IRE_LOOPBACK
&& id
== 0)
13705 ire_type
= IRE_LOOPBACK
;
13707 ire_type
= IRE_LOCAL
;
13708 ipif
= ipif_allocate(ill
, id
, ire_type
, B_TRUE
, B_TRUE
, NULL
);
13710 ipif_refhold_locked(ipif
);
13711 mutex_exit(&ill
->ill_lock
);
13717 * Variant of the above that queues the request on the ipsq when
13718 * IPIF_CHANGING is set.
13721 ipif_lookup_on_name_async(char *name
, size_t namelen
, boolean_t isv6
,
13722 zoneid_t zoneid
, queue_t
*q
, mblk_t
*mp
, ipsq_func_t func
, int *error
,
13730 boolean_t did_alloc
= B_FALSE
;
13736 if (namelen
== 0) {
13742 /* Look for a colon in the name. */
13743 endp
= &name
[namelen
];
13744 for (cp
= endp
; --cp
> name
; ) {
13745 if (*cp
== IPIF_SEPARATOR_CHAR
)
13749 if (*cp
== IPIF_SEPARATOR_CHAR
) {
13751 * Reject any non-decimal aliases for logical
13752 * interfaces. Aliases with leading zeroes
13753 * are also rejected as they introduce ambiguity
13754 * in the naming of the interfaces.
13755 * In order to confirm with existing semantics,
13756 * and to not break any programs/script relying
13757 * on that behaviour, if<0>:0 is considered to be
13758 * a valid interface.
13760 * If alias has two or more digits and the first
13763 if (&cp
[2] < endp
&& cp
[1] == '0') {
13777 * Look up the ILL, based on the portion of the name
13778 * before the slash. ill_lookup_on_name returns a held ill.
13779 * Temporary to check whether ill exists already. If so
13780 * ill_lookup_on_name will clear it.
13782 ill
= ill_lookup_on_name(name
, B_FALSE
, isv6
, &did_alloc
, ipst
);
13784 *cp
= IPIF_SEPARATOR_CHAR
;
13788 /* Establish the unit number in the name. */
13790 if (cp
< endp
&& *endp
== '\0') {
13791 /* If there was a colon, the unit number follows. */
13793 if (ddi_strtol(cp
, NULL
, 0, &id
) != 0) {
13802 mutex_enter(&ill
->ill_lock
);
13803 /* Now see if there is an IPIF with this unit number. */
13804 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
13805 if (ipif
->ipif_id
== id
) {
13806 if (zoneid
!= ALL_ZONES
&&
13807 zoneid
!= ipif
->ipif_zoneid
&&
13808 ipif
->ipif_zoneid
!= ALL_ZONES
) {
13809 mutex_exit(&ill
->ill_lock
);
13810 RELEASE_CONN_LOCK(q
);
13817 if (!(IPIF_IS_CHANGING(ipif
) ||
13818 IPIF_IS_CONDEMNED(ipif
)) ||
13819 IAM_WRITER_IPIF(ipif
)) {
13820 ipif_refhold_locked(ipif
);
13821 mutex_exit(&ill
->ill_lock
);
13823 * Drop locks before calling ill_refrele
13824 * since it can potentially call into
13825 * ipif_ill_refrele_tail which can end up
13826 * in trying to acquire any lock.
13828 RELEASE_CONN_LOCK(q
);
13831 } else if (q
!= NULL
&& !IPIF_IS_CONDEMNED(ipif
)) {
13832 ipsq
= ill
->ill_phyint
->phyint_ipsq
;
13833 mutex_enter(&ipsq
->ipsq_lock
);
13834 mutex_enter(&ipsq
->ipsq_xop
->ipx_lock
);
13835 mutex_exit(&ill
->ill_lock
);
13836 ipsq_enq(ipsq
, q
, mp
, func
, NEW_OP
, ill
);
13837 mutex_exit(&ipsq
->ipsq_xop
->ipx_lock
);
13838 mutex_exit(&ipsq
->ipsq_lock
);
13839 RELEASE_CONN_LOCK(q
);
13842 *error
= EINPROGRESS
;
13847 RELEASE_CONN_LOCK(q
);
13848 mutex_exit(&ill
->ill_lock
);
13856 * This routine is called whenever a new address comes up on an ipif. If
13857 * we are configured to respond to address mask requests, then we are supposed
13858 * to broadcast an address mask reply at this time. This routine is also
13859 * called if we are already up, but a netmask change is made. This is legal
13860 * but might not make the system manager very popular. (May be called
13864 ipif_mask_reply(ipif_t
*ipif
)
13869 ip_stack_t
*ipst
= ipif
->ipif_ill
->ill_ipst
;
13870 ip_xmit_attr_t ixas
;
13872 #define REPLY_LEN (sizeof (icmp_ipha) + sizeof (icmph_t) + IP_ADDR_LEN)
13874 if (!ipst
->ips_ip_respond_to_address_mask_broadcast
)
13877 /* ICMP mask reply is IPv4 only */
13878 ASSERT(!ipif
->ipif_isv6
);
13879 /* ICMP mask reply is not for a loopback interface */
13880 ASSERT(ipif
->ipif_ill
->ill_wq
!= NULL
);
13882 if (ipif
->ipif_lcl_addr
== INADDR_ANY
)
13885 mp
= allocb(REPLY_LEN
, BPRI_HI
);
13888 mp
->b_wptr
= mp
->b_rptr
+ REPLY_LEN
;
13890 ipha
= (ipha_t
*)mp
->b_rptr
;
13891 bzero(ipha
, REPLY_LEN
);
13893 ipha
->ipha_ttl
= ipst
->ips_ip_broadcast_ttl
;
13894 ipha
->ipha_src
= ipif
->ipif_lcl_addr
;
13895 ipha
->ipha_dst
= ipif
->ipif_brd_addr
;
13896 ipha
->ipha_length
= htons(REPLY_LEN
);
13897 ipha
->ipha_ident
= 0;
13899 icmph
= (icmph_t
*)&ipha
[1];
13900 icmph
->icmph_type
= ICMP_ADDRESS_MASK_REPLY
;
13901 bcopy(&ipif
->ipif_net_mask
, &icmph
[1], IP_ADDR_LEN
);
13902 icmph
->icmph_checksum
= IP_CSUM(mp
, sizeof (ipha_t
), 0);
13904 bzero(&ixas
, sizeof (ixas
));
13905 ixas
.ixa_flags
= IXAF_BASIC_SIMPLE_V4
;
13906 ixas
.ixa_zoneid
= ALL_ZONES
;
13907 ixas
.ixa_ifindex
= 0;
13908 ixas
.ixa_ipst
= ipst
;
13909 ixas
.ixa_multicast_ttl
= IP_DEFAULT_MULTICAST_TTL
;
13910 (void) ip_output_simple(mp
, &ixas
);
13911 ixa_cleanup(&ixas
);
13916 * Join the ipif specific multicast groups.
13917 * Must be called after a mapping has been set up in the resolver. (Always
13918 * called as writer.)
13921 ipif_multicast_up(ipif_t
*ipif
)
13927 ASSERT(IAM_WRITER_IPIF(ipif
));
13929 ill
= ipif
->ipif_ill
;
13931 ip1dbg(("ipif_multicast_up\n"));
13932 if (!(ill
->ill_flags
& ILLF_MULTICAST
) ||
13933 ipif
->ipif_allhosts_ilm
!= NULL
)
13936 if (ipif
->ipif_isv6
) {
13937 in6_addr_t v6allmc
= ipv6_all_hosts_mcast
;
13938 in6_addr_t v6solmc
= ipv6_solicited_node_mcast
;
13940 v6solmc
.s6_addr32
[3] |= ipif
->ipif_v6lcl_addr
.s6_addr32
[3];
13942 if (IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6lcl_addr
))
13945 ip1dbg(("ipif_multicast_up - addmulti\n"));
13948 * Join the all hosts multicast address. We skip this for
13949 * underlying IPMP interfaces since they should be invisible.
13951 if (!IS_UNDER_IPMP(ill
)) {
13952 ilm
= ip_addmulti(&v6allmc
, ill
, ipif
->ipif_zoneid
,
13956 ip0dbg(("ipif_multicast_up: "
13957 "all_hosts_mcast failed %d\n", err
));
13960 ipif
->ipif_allhosts_ilm
= ilm
;
13964 * Enable multicast for the solicited node multicast address.
13965 * If IPMP we need to put the membership on the upper ill.
13967 if (!(ipif
->ipif_flags
& IPIF_NOLOCAL
)) {
13968 ill_t
*mcast_ill
= NULL
;
13969 boolean_t need_refrele
;
13971 if (IS_UNDER_IPMP(ill
) &&
13972 (mcast_ill
= ipmp_ill_hold_ipmp_ill(ill
)) != NULL
) {
13973 need_refrele
= B_TRUE
;
13976 need_refrele
= B_FALSE
;
13979 ilm
= ip_addmulti(&v6solmc
, mcast_ill
,
13980 ipif
->ipif_zoneid
, &err
);
13982 ill_refrele(mcast_ill
);
13986 ip0dbg(("ipif_multicast_up: solicited MC"
13987 " failed %d\n", err
));
13988 if ((ilm
= ipif
->ipif_allhosts_ilm
) != NULL
) {
13989 ipif
->ipif_allhosts_ilm
= NULL
;
13990 (void) ip_delmulti(ilm
);
13994 ipif
->ipif_solmulti_ilm
= ilm
;
13997 in6_addr_t v6group
;
13999 if (ipif
->ipif_lcl_addr
== INADDR_ANY
|| IS_UNDER_IPMP(ill
))
14002 /* Join the all hosts multicast address */
14003 ip1dbg(("ipif_multicast_up - addmulti\n"));
14004 IN6_IPADDR_TO_V4MAPPED(htonl(INADDR_ALLHOSTS_GROUP
), &v6group
);
14006 ilm
= ip_addmulti(&v6group
, ill
, ipif
->ipif_zoneid
, &err
);
14009 ip0dbg(("ipif_multicast_up: failed %d\n", err
));
14012 ipif
->ipif_allhosts_ilm
= ilm
;
14017 * Blow away any multicast groups that we joined in ipif_multicast_up().
14018 * (ilms from explicit memberships are handled in conn_update_ill.)
14021 ipif_multicast_down(ipif_t
*ipif
)
14023 ASSERT(IAM_WRITER_IPIF(ipif
));
14025 ip1dbg(("ipif_multicast_down\n"));
14027 if (ipif
->ipif_allhosts_ilm
!= NULL
) {
14028 (void) ip_delmulti(ipif
->ipif_allhosts_ilm
);
14029 ipif
->ipif_allhosts_ilm
= NULL
;
14031 if (ipif
->ipif_solmulti_ilm
!= NULL
) {
14032 (void) ip_delmulti(ipif
->ipif_solmulti_ilm
);
14033 ipif
->ipif_solmulti_ilm
= NULL
;
14038 * Used when an interface comes up to recreate any extra routes on this
14042 ill_recover_saved_ire(ill_t
*ill
)
14045 ip_stack_t
*ipst
= ill
->ill_ipst
;
14047 ip1dbg(("ill_recover_saved_ire(%s)", ill
->ill_name
));
14049 mutex_enter(&ill
->ill_saved_ire_lock
);
14050 for (mp
= ill
->ill_saved_ire_mp
; mp
!= NULL
; mp
= mp
->b_cont
) {
14054 ifrt
= (ifrt_t
*)mp
->b_rptr
;
14056 * Create a copy of the IRE with the saved address and netmask.
14058 if (ill
->ill_isv6
) {
14059 ire
= ire_create_v6(
14060 &ifrt
->ifrt_v6addr
,
14061 &ifrt
->ifrt_v6mask
,
14062 &ifrt
->ifrt_v6gateway_addr
,
14070 (uint8_t *)&ifrt
->ifrt_addr
,
14071 (uint8_t *)&ifrt
->ifrt_mask
,
14072 (uint8_t *)&ifrt
->ifrt_gateway_addr
,
14080 mutex_exit(&ill
->ill_saved_ire_lock
);
14084 if (ifrt
->ifrt_flags
& RTF_SETSRC
) {
14085 if (ill
->ill_isv6
) {
14086 ire
->ire_setsrc_addr_v6
=
14087 ifrt
->ifrt_v6setsrc_addr
;
14089 ire
->ire_setsrc_addr
= ifrt
->ifrt_setsrc_addr
;
14094 * Some software (for example, GateD and Sun Cluster) attempts
14095 * to create (what amount to) IRE_PREFIX routes with the
14096 * loopback address as the gateway. This is primarily done to
14097 * set up prefixes with the RTF_REJECT flag set (for example,
14098 * when generating aggregate routes.)
14100 * If the IRE type (as defined by ill->ill_net_type) is
14101 * IRE_LOOPBACK, then we map the request into a
14102 * IRE_IF_NORESOLVER.
14104 if (ill
->ill_net_type
== IRE_LOOPBACK
)
14105 ire
->ire_type
= IRE_IF_NORESOLVER
;
14108 * ire held by ire_add, will be refreled' towards the
14109 * the end of ipif_up_done
14111 nire
= ire_add(ire
);
14113 * Check if it was a duplicate entry. This handles
14114 * the case of two racing route adds for the same route
14116 if (nire
== NULL
) {
14117 ip1dbg(("ill_recover_saved_ire: FAILED\n"));
14118 } else if (nire
!= ire
) {
14119 ip1dbg(("ill_recover_saved_ire: duplicate ire %p\n",
14123 ip1dbg(("ill_recover_saved_ire: added ire %p\n",
14129 mutex_exit(&ill
->ill_saved_ire_lock
);
14134 * Used to set the netmask and broadcast address to default values when the
14135 * interface is brought up. (Always called as writer.)
14138 ipif_set_default(ipif_t
*ipif
)
14140 ASSERT(MUTEX_HELD(&ipif
->ipif_ill
->ill_lock
));
14142 if (!ipif
->ipif_isv6
) {
14144 * Interface holds an IPv4 address. Default
14145 * mask is the natural netmask.
14147 if (!ipif
->ipif_net_mask
) {
14150 v4mask
= ip_net_mask(ipif
->ipif_lcl_addr
);
14151 V4MASK_TO_V6(v4mask
, ipif
->ipif_v6net_mask
);
14153 if (ipif
->ipif_flags
& IPIF_POINTOPOINT
) {
14154 /* ipif_subnet is ipif_pp_dst_addr for pt-pt */
14155 ipif
->ipif_v6subnet
= ipif
->ipif_v6pp_dst_addr
;
14157 V6_MASK_COPY(ipif
->ipif_v6lcl_addr
,
14158 ipif
->ipif_v6net_mask
, ipif
->ipif_v6subnet
);
14161 * NOTE: SunOS 4.X does this even if the broadcast address
14162 * has been already set thus we do the same here.
14164 if (ipif
->ipif_flags
& IPIF_BROADCAST
) {
14167 v4addr
= ipif
->ipif_subnet
| ~ipif
->ipif_net_mask
;
14168 IN6_IPADDR_TO_V4MAPPED(v4addr
, &ipif
->ipif_v6brd_addr
);
14172 * Interface holds an IPv6-only address. Default
14173 * mask is all-ones.
14175 if (IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6net_mask
))
14176 ipif
->ipif_v6net_mask
= ipv6_all_ones
;
14177 if (ipif
->ipif_flags
& IPIF_POINTOPOINT
) {
14178 /* ipif_subnet is ipif_pp_dst_addr for pt-pt */
14179 ipif
->ipif_v6subnet
= ipif
->ipif_v6pp_dst_addr
;
14181 V6_MASK_COPY(ipif
->ipif_v6lcl_addr
,
14182 ipif
->ipif_v6net_mask
, ipif
->ipif_v6subnet
);
14188 * Return 0 if this address can be used as local address without causing
14189 * duplicate address problems. Otherwise, return EADDRNOTAVAIL if the address
14190 * is already up on a different ill, and EADDRINUSE if it's up on the same ill.
14191 * Note that the same IPv6 link-local address is allowed as long as the ills
14192 * are not on the same link.
14195 ip_addr_availability_check(ipif_t
*new_ipif
)
14197 in6_addr_t our_v6addr
;
14200 ill_walk_context_t ctx
;
14201 ip_stack_t
*ipst
= new_ipif
->ipif_ill
->ill_ipst
;
14203 ASSERT(IAM_WRITER_IPIF(new_ipif
));
14204 ASSERT(MUTEX_HELD(&ipst
->ips_ip_addr_avail_lock
));
14205 ASSERT(RW_READ_HELD(&ipst
->ips_ill_g_lock
));
14207 new_ipif
->ipif_flags
&= ~IPIF_UNNUMBERED
;
14208 if (IN6_IS_ADDR_UNSPECIFIED(&new_ipif
->ipif_v6lcl_addr
) ||
14209 IN6_IS_ADDR_V4MAPPED_ANY(&new_ipif
->ipif_v6lcl_addr
))
14212 our_v6addr
= new_ipif
->ipif_v6lcl_addr
;
14214 if (new_ipif
->ipif_isv6
)
14215 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
14217 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
14219 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
14220 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
14221 ipif
= ipif
->ipif_next
) {
14222 if ((ipif
== new_ipif
) ||
14223 !(ipif
->ipif_flags
& IPIF_UP
) ||
14224 (ipif
->ipif_flags
& IPIF_UNNUMBERED
) ||
14225 !IN6_ARE_ADDR_EQUAL(&ipif
->ipif_v6lcl_addr
,
14229 if (new_ipif
->ipif_flags
& IPIF_POINTOPOINT
)
14230 new_ipif
->ipif_flags
|= IPIF_UNNUMBERED
;
14231 else if (ipif
->ipif_flags
& IPIF_POINTOPOINT
)
14232 ipif
->ipif_flags
|= IPIF_UNNUMBERED
;
14233 else if ((IN6_IS_ADDR_LINKLOCAL(&our_v6addr
) ||
14234 IN6_IS_ADDR_SITELOCAL(&our_v6addr
)) &&
14235 !IS_ON_SAME_LAN(ill
, new_ipif
->ipif_ill
))
14237 else if (new_ipif
->ipif_zoneid
!= ipif
->ipif_zoneid
&&
14238 ipif
->ipif_zoneid
!= ALL_ZONES
&& IS_LOOPBACK(ill
))
14240 else if (new_ipif
->ipif_ill
== ill
)
14241 return (EADDRINUSE
);
14243 return (EADDRNOTAVAIL
);
14251 * Bring up an ipif: bring up arp/ndp, bring up the DLPI stream, and add
14252 * IREs for the ipif.
14253 * When the routine returns EINPROGRESS then mp has been consumed and
14254 * the ioctl will be acked from ip_rput_dlpi.
14257 ipif_up(ipif_t
*ipif
, queue_t
*q
, mblk_t
*mp
)
14259 ill_t
*ill
= ipif
->ipif_ill
;
14260 boolean_t isv6
= ipif
->ipif_isv6
;
14263 uint_t ipif_orig_id
;
14264 ip_stack_t
*ipst
= ill
->ill_ipst
;
14266 ASSERT(IAM_WRITER_IPIF(ipif
));
14268 ip1dbg(("ipif_up(%s:%u)\n", ill
->ill_name
, ipif
->ipif_id
));
14269 DTRACE_PROBE3(ipif__downup
, char *, "ipif_up",
14270 ill_t
*, ill
, ipif_t
*, ipif
);
14272 /* Shouldn't get here if it is already up. */
14273 if (ipif
->ipif_flags
& IPIF_UP
)
14277 * If this is a request to bring up a data address on an interface
14278 * under IPMP, then move the address to its IPMP meta-interface and
14279 * try to bring it up. One complication is that the zeroth ipif for
14280 * an ill is special, in that every ill always has one, and that code
14281 * throughout IP deferences ill->ill_ipif without holding any locks.
14283 if (IS_UNDER_IPMP(ill
) && ipmp_ipif_is_dataaddr(ipif
) &&
14284 (!ipif
->ipif_isv6
|| !V6_IPIF_LINKLOCAL(ipif
))) {
14285 ipif_t
*stubipif
= NULL
, *moveipif
= NULL
;
14286 ill_t
*ipmp_ill
= ipmp_illgrp_ipmp_ill(ill
->ill_grp
);
14289 * The ipif being brought up should be quiesced. If it's not,
14290 * something has gone amiss and we need to bail out. (If it's
14291 * quiesced, we know it will remain so via IPIF_CONDEMNED.)
14293 mutex_enter(&ill
->ill_lock
);
14294 if (!ipif_is_quiescent(ipif
)) {
14295 mutex_exit(&ill
->ill_lock
);
14298 mutex_exit(&ill
->ill_lock
);
14301 * If we're going to need to allocate ipifs, do it prior
14302 * to starting the move (and grabbing locks).
14304 if (ipif
->ipif_id
== 0) {
14305 if ((moveipif
= ipif_allocate(ill
, 0, IRE_LOCAL
, B_TRUE
,
14306 B_FALSE
, &err
)) == NULL
) {
14309 if ((stubipif
= ipif_allocate(ill
, 0, IRE_LOCAL
, B_TRUE
,
14310 B_FALSE
, &err
)) == NULL
) {
14317 * Grab or transfer the ipif to move. During the move, keep
14318 * ill_g_lock held to prevent any ill walker threads from
14319 * seeing things in an inconsistent state.
14321 rw_enter(&ipst
->ips_ill_g_lock
, RW_WRITER
);
14322 if (ipif
->ipif_id
!= 0) {
14325 ipif_transfer(ipif
, moveipif
, stubipif
);
14330 * Place the ipif on the IPMP ill. If the zeroth ipif on
14331 * the IPMP ill is a stub (0.0.0.0 down address) then we
14332 * replace that one. Otherwise, pick the next available slot.
14334 ipif
->ipif_ill
= ipmp_ill
;
14335 ipif_orig_id
= ipif
->ipif_id
;
14337 if (ipmp_ipif_is_stubaddr(ipmp_ill
->ill_ipif
)) {
14338 ipif_transfer(ipif
, ipmp_ill
->ill_ipif
, NULL
);
14339 ipif
= ipmp_ill
->ill_ipif
;
14341 ipif
->ipif_id
= -1;
14342 if ((err
= ipif_insert(ipif
, B_FALSE
)) != 0) {
14344 * No more available ipif_id's -- put it back
14345 * on the original ill and fail the operation.
14346 * Since we're writer on the ill, we can be
14347 * sure our old slot is still available.
14349 ipif
->ipif_id
= ipif_orig_id
;
14350 ipif
->ipif_ill
= ill
;
14351 if (ipif_orig_id
== 0) {
14352 ipif_transfer(ipif
, ill
->ill_ipif
,
14355 VERIFY(ipif_insert(ipif
, B_FALSE
) == 0);
14357 rw_exit(&ipst
->ips_ill_g_lock
);
14361 rw_exit(&ipst
->ips_ill_g_lock
);
14364 * Tell SCTP that the ipif has moved. Note that even if we
14365 * had to allocate a new ipif, the original sequence id was
14366 * preserved and therefore SCTP won't know.
14368 sctp_move_ipif(ipif
, ill
, ipmp_ill
);
14371 * If the ipif being brought up was on slot zero, then we
14372 * first need to bring up the placeholder we stuck there. In
14373 * ip_rput_dlpi_writer(), arp_bringup_done(), or the recursive
14374 * call to ipif_up() itself, if we successfully bring up the
14375 * placeholder, we'll check ill_move_ipif and bring it up too.
14377 if (ipif_orig_id
== 0) {
14378 ASSERT(ill
->ill_move_ipif
== NULL
);
14379 ill
->ill_move_ipif
= ipif
;
14380 if ((err
= ipif_up(ill
->ill_ipif
, q
, mp
)) == 0)
14381 ASSERT(ill
->ill_move_ipif
== NULL
);
14382 if (err
!= EINPROGRESS
)
14383 ill
->ill_move_ipif
= NULL
;
14388 * Bring it up on the IPMP ill.
14390 return (ipif_up(ipif
, q
, mp
));
14393 /* Skip arp/ndp for any loopback interface. */
14394 if (ill
->ill_wq
!= NULL
) {
14395 conn_t
*connp
= CONN_Q(q
) ? Q_TO_CONN(q
) : NULL
;
14396 ipsq_t
*ipsq
= ill
->ill_phyint
->phyint_ipsq
;
14398 if (!ill
->ill_dl_up
) {
14400 * ill_dl_up is not yet set. i.e. we are yet to
14401 * DL_BIND with the driver and this is the first
14402 * logical interface on the ill to become "up".
14403 * Tell the driver to get going (via DL_BIND_REQ).
14404 * Note that changing "significant" IFF_ flags
14405 * address/netmask etc cause a down/up dance, but
14406 * does not cause an unbind (DL_UNBIND) with the driver
14408 return (ill_dl_up(ill
, ipif
, mp
, q
));
14412 * ipif_resolver_up may end up needeing to bind/attach
14413 * the ARP stream, which in turn necessitates a
14414 * DLPI message exchange with the driver. ioctls are
14415 * serialized and so we cannot send more than one
14416 * interface up message at a time. If ipif_resolver_up
14417 * does need to wait for the DLPI handshake for the ARP stream,
14418 * we get EINPROGRESS and we will complete in arp_bringup_done.
14421 ASSERT(connp
!= NULL
|| !CONN_Q(q
));
14423 mutex_enter(&connp
->conn_lock
);
14424 mutex_enter(&ill
->ill_lock
);
14425 success
= ipsq_pending_mp_add(connp
, ipif
, q
, mp
, 0);
14426 mutex_exit(&ill
->ill_lock
);
14428 mutex_exit(&connp
->conn_lock
);
14433 * Crank up IPv6 neighbor discovery. Unlike ARP, this should
14434 * complete when ipif_ndp_up returns.
14436 err
= ipif_resolver_up(ipif
, Res_act_initial
);
14437 if (err
== EINPROGRESS
) {
14438 /* We will complete it in arp_bringup_done() */
14442 if (isv6
&& err
== 0)
14443 err
= ipif_ndp_up(ipif
, B_TRUE
);
14445 ASSERT(err
!= EINPROGRESS
);
14446 mp
= ipsq_pending_mp_get(ipsq
, &connp
);
14447 ASSERT(mp
!= NULL
);
14452 * Interfaces without underlying hardware don't do duplicate
14453 * address detection.
14455 ASSERT(!(ipif
->ipif_flags
& IPIF_DUPLICATE
));
14456 ipif
->ipif_addr_ready
= 1;
14457 err
= ill_add_ires(ill
);
14458 /* allocation failure? */
14463 err
= (isv6
? ipif_up_done_v6(ipif
) : ipif_up_done(ipif
));
14464 if (err
== 0 && ill
->ill_move_ipif
!= NULL
) {
14465 ipif
= ill
->ill_move_ipif
;
14466 ill
->ill_move_ipif
= NULL
;
14467 return (ipif_up(ipif
, q
, mp
));
14473 * Add any IREs tied to the ill. For now this is just an IRE_MULTICAST.
14474 * The identical set of IREs need to be removed in ill_delete_ires().
14477 ill_add_ires(ill_t
*ill
)
14480 in6_addr_t dummy6
= {(uint32_t)V6_MCAST
, 0, 0, 1};
14481 in_addr_t dummy4
= htonl(INADDR_ALLHOSTS_GROUP
);
14483 if (ill
->ill_ire_multicast
!= NULL
)
14487 * provide some dummy ire_addr for creating the ire.
14489 if (ill
->ill_isv6
) {
14490 ire
= ire_create_v6(&dummy6
, 0, 0, IRE_MULTICAST
, ill
,
14491 ALL_ZONES
, RTF_UP
, ill
->ill_ipst
);
14493 ire
= ire_create((uchar_t
*)&dummy4
, 0, 0, IRE_MULTICAST
, ill
,
14494 ALL_ZONES
, RTF_UP
, ill
->ill_ipst
);
14499 ill
->ill_ire_multicast
= ire
;
14504 ill_delete_ires(ill_t
*ill
)
14506 if (ill
->ill_ire_multicast
!= NULL
) {
14508 * BIND/ATTACH completed; Release the ref for ill_ire_multicast
14509 * which was taken without any th_tracing enabled.
14510 * We also mark it as condemned (note that it was never added)
14511 * so that caching conn's can move off of it.
14513 ire_make_condemned(ill
->ill_ire_multicast
);
14514 ire_refrele_notr(ill
->ill_ire_multicast
);
14515 ill
->ill_ire_multicast
= NULL
;
14520 * Perform a bind for the physical device.
14521 * When the routine returns EINPROGRESS then mp has been consumed and
14522 * the ioctl will be acked from ip_rput_dlpi.
14523 * Allocate an unbind message and save it until ipif_down.
14526 ill_dl_up(ill_t
*ill
, ipif_t
*ipif
, mblk_t
*mp
, queue_t
*q
)
14528 mblk_t
*bind_mp
= NULL
;
14529 mblk_t
*unbind_mp
= NULL
;
14534 DTRACE_PROBE2(ill__downup
, char *, "ill_dl_up", ill_t
*, ill
);
14536 ip1dbg(("ill_dl_up(%s)\n", ill
->ill_name
));
14537 ASSERT(IAM_WRITER_ILL(ill
));
14538 ASSERT(mp
!= NULL
);
14541 * Make sure we have an IRE_MULTICAST in case we immediately
14542 * start receiving packets.
14544 err
= ill_add_ires(ill
);
14548 bind_mp
= ip_dlpi_alloc(sizeof (dl_bind_req_t
) + sizeof (long),
14550 if (bind_mp
== NULL
)
14552 ((dl_bind_req_t
*)bind_mp
->b_rptr
)->dl_sap
= ill
->ill_sap
;
14553 ((dl_bind_req_t
*)bind_mp
->b_rptr
)->dl_service_mode
= DL_CLDLS
;
14556 * ill_unbind_mp would be non-null if the following sequence had
14558 * - send DL_BIND_REQ to driver, wait for response
14559 * - multiple ioctls that need to bring the ipif up are encountered,
14560 * but they cannot enter the ipsq due to the outstanding DL_BIND_REQ.
14561 * These ioctls will then be enqueued on the ipsq
14562 * - a DL_ERROR_ACK is returned for the DL_BIND_REQ
14563 * At this point, the pending ioctls in the ipsq will be drained, and
14564 * since ill->ill_dl_up was not set, ill_dl_up would be invoked with
14565 * a non-null ill->ill_unbind_mp
14567 if (ill
->ill_unbind_mp
== NULL
) {
14568 unbind_mp
= ip_dlpi_alloc(sizeof (dl_unbind_req_t
),
14570 if (unbind_mp
== NULL
)
14574 * Record state needed to complete this operation when the
14575 * DL_BIND_ACK shows up. Also remember the pre-allocated mblks.
14577 connp
= CONN_Q(q
) ? Q_TO_CONN(q
) : NULL
;
14578 ASSERT(connp
!= NULL
|| !CONN_Q(q
));
14580 mutex_enter(&ipif
->ipif_ill
->ill_lock
);
14581 success
= ipsq_pending_mp_add(connp
, ipif
, q
, mp
, 0);
14582 mutex_exit(&ipif
->ipif_ill
->ill_lock
);
14583 RELEASE_CONN_LOCK(q
);
14588 * Save the unbind message for ill_dl_down(); it will be consumed when
14589 * the interface goes down.
14591 if (ill
->ill_unbind_mp
== NULL
)
14592 ill
->ill_unbind_mp
= unbind_mp
;
14594 ill_dlpi_send(ill
, bind_mp
);
14595 /* Send down link-layer capabilities probe if not already done. */
14596 ill_capability_probe(ill
);
14599 * Sysid used to rely on the fact that netboots set domainname
14600 * and the like. Now that miniroot boots aren't strictly netboots
14601 * and miniroot network configuration is driven from userland
14602 * these things still need to be set. This situation can be detected
14603 * by comparing the interface being configured here to the one
14604 * dhcifname was set to reference by the boot loader. Once sysid is
14605 * converted to use dhcp_ipc_getinfo() this call can go away.
14607 if ((ipif
->ipif_flags
& IPIF_DHCPRUNNING
) &&
14608 (strcmp(ill
->ill_name
, dhcifname
) == 0) &&
14609 (strlen(srpc_domain
) == 0)) {
14610 if (dhcpinit() != 0)
14611 cmn_err(CE_WARN
, "no cached dhcp response");
14615 * This operation will complete in ip_rput_dlpi with either
14616 * a DL_BIND_ACK or DL_ERROR_ACK.
14618 return (EINPROGRESS
);
14620 ip1dbg(("ill_dl_up(%s) FAILED\n", ill
->ill_name
));
14623 freemsg(unbind_mp
);
14627 /* Add room for tcp+ip headers */
14628 uint_t ip_loopback_mtuplus
= IP_LOOPBACK_MTU
+ IP_SIMPLE_HDR_LENGTH
+ 20;
14631 * DLPI and ARP is up.
14632 * Create all the IREs associated with an interface. Bring up multicast.
14633 * Set the interface flag and finish other initialization
14634 * that potentially had to be deferred to after DL_BIND_ACK.
14637 ipif_up_done(ipif_t
*ipif
)
14639 ill_t
*ill
= ipif
->ipif_ill
;
14641 boolean_t loopback
= B_FALSE
;
14642 boolean_t update_src_selection
= B_TRUE
;
14645 ip1dbg(("ipif_up_done(%s:%u)\n",
14646 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
));
14647 DTRACE_PROBE3(ipif__downup
, char *, "ipif_up_done",
14648 ill_t
*, ill
, ipif_t
*, ipif
);
14650 /* Check if this is a loopback interface */
14651 if (ipif
->ipif_ill
->ill_wq
== NULL
)
14654 ASSERT(!MUTEX_HELD(&ipif
->ipif_ill
->ill_lock
));
14657 * If all other interfaces for this ill are down or DEPRECATED,
14658 * or otherwise unsuitable for source address selection,
14659 * reset the src generation numbers to make sure source
14660 * address selection gets to take this new ipif into account.
14661 * No need to hold ill_lock while traversing the ipif list since
14664 for (tmp_ipif
= ill
->ill_ipif
; tmp_ipif
;
14665 tmp_ipif
= tmp_ipif
->ipif_next
) {
14666 if (((tmp_ipif
->ipif_flags
&
14667 (IPIF_NOXMIT
|IPIF_ANYCAST
|IPIF_NOLOCAL
|IPIF_DEPRECATED
)) ||
14668 !(tmp_ipif
->ipif_flags
& IPIF_UP
)) ||
14669 (tmp_ipif
== ipif
))
14671 /* first useable pre-existing interface */
14672 update_src_selection
= B_FALSE
;
14675 if (update_src_selection
)
14676 ip_update_source_selection(ill
->ill_ipst
);
14678 if (IS_LOOPBACK(ill
) || ill
->ill_net_type
== IRE_IF_NORESOLVER
) {
14679 nce_t
*loop_nce
= NULL
;
14680 uint16_t flags
= (NCE_F_MYADDR
| NCE_F_AUTHORITY
| NCE_F_NONUD
);
14683 * lo0:1 and subsequent ipifs were marked IRE_LOCAL in
14684 * ipif_lookup_on_name(), but in the case of zones we can have
14685 * several loopback addresses on lo0. So all the interfaces with
14686 * loopback addresses need to be marked IRE_LOOPBACK.
14688 if (V4_PART_OF_V6(ipif
->ipif_v6lcl_addr
) ==
14689 htonl(INADDR_LOOPBACK
))
14690 ipif
->ipif_ire_type
= IRE_LOOPBACK
;
14692 ipif
->ipif_ire_type
= IRE_LOCAL
;
14693 if (ill
->ill_net_type
!= IRE_LOOPBACK
)
14694 flags
|= NCE_F_PUBLISH
;
14696 /* add unicast nce for the local addr */
14697 err
= nce_lookup_then_add_v4(ill
, NULL
,
14698 ill
->ill_phys_addr_length
, &ipif
->ipif_lcl_addr
, flags
,
14699 ND_REACHABLE
, &loop_nce
);
14700 /* A shared-IP zone sees EEXIST for lo0:N */
14701 if (err
== 0 || err
== EEXIST
) {
14702 ipif
->ipif_added_nce
= 1;
14703 loop_nce
->nce_ipif_cnt
++;
14704 nce_refrele(loop_nce
);
14707 ASSERT(loop_nce
== NULL
);
14712 /* Create all the IREs associated with this interface */
14713 err
= ipif_add_ires_v4(ipif
, loopback
);
14716 * see comments about return value from
14717 * ip_addr_availability_check() in ipif_add_ires_v4().
14719 if (err
!= EADDRINUSE
) {
14720 (void) ipif_arp_down(ipif
);
14723 * Make IPMP aware of the deleted ipif so that
14724 * the needed ipmp cleanup (e.g., of ipif_bound_ill)
14725 * can be completed. Note that we do not want to
14726 * destroy the nce that was created on the ipmp_ill
14727 * for the active copy of the duplicate address in
14731 ipmp_illgrp_del_ipif(ill
->ill_grp
, ipif
);
14732 err
= EADDRNOTAVAIL
;
14737 if (ill
->ill_ipif_up_count
== 1 && !loopback
) {
14738 /* Recover any additional IREs entries for this ill */
14739 (void) ill_recover_saved_ire(ill
);
14742 if (ill
->ill_need_recover_multicast
) {
14744 * Need to recover all multicast memberships in the driver.
14745 * This had to be deferred until we had attached. The same
14746 * code exists in ipif_up_done_v6() to recover IPv6
14749 * Note that it would be preferable to unconditionally do the
14750 * ill_recover_multicast() in ill_dl_up(), but we cannot do
14751 * that since ill_join_allmulti() depends on ill_dl_up being
14752 * set, and it is not set until we receive a DL_BIND_ACK after
14753 * having called ill_dl_up().
14755 ill_recover_multicast(ill
);
14758 if (ill
->ill_ipif_up_count
== 1) {
14760 * Since the interface is now up, it may now be active.
14762 if (IS_UNDER_IPMP(ill
))
14763 ipmp_ill_refresh_active(ill
);
14766 * If this is an IPMP interface, we may now be able to
14767 * establish ARP entries.
14770 ipmp_illgrp_refresh_arpent(ill
->ill_grp
);
14773 /* Join the allhosts multicast address */
14774 ipif_multicast_up(ipif
);
14776 if (!loopback
&& !update_src_selection
&&
14777 !(ipif
->ipif_flags
& (IPIF_NOLOCAL
|IPIF_ANYCAST
|IPIF_DEPRECATED
)))
14778 ip_update_source_selection(ill
->ill_ipst
);
14780 if (!loopback
&& ipif
->ipif_addr_ready
) {
14781 /* Broadcast an address mask reply. */
14782 ipif_mask_reply(ipif
);
14784 /* Perhaps ilgs should use this ill */
14785 update_conn_ill(NULL
, ill
->ill_ipst
);
14788 * This had to be deferred until we had bound. Tell routing sockets and
14789 * others that this interface is up if it looks like the address has
14790 * been validated. Otherwise, if it isn't ready yet, wait for
14791 * duplicate address detection to do its thing.
14793 if (ipif
->ipif_addr_ready
)
14794 ipif_up_notify(ipif
);
14799 * Add the IREs associated with the ipif.
14800 * Those MUST be explicitly removed in ipif_delete_ires_v4.
14803 ipif_add_ires_v4(ipif_t
*ipif
, boolean_t loopback
)
14805 ill_t
*ill
= ipif
->ipif_ill
;
14806 ip_stack_t
*ipst
= ill
->ill_ipst
;
14807 ire_t
*ire_array
[20];
14808 ire_t
**irep
= ire_array
;
14810 ipaddr_t net_mask
= 0;
14811 ipaddr_t subnet_mask
, route_mask
;
14813 ire_t
*ire_local
= NULL
; /* LOCAL or LOOPBACK */
14814 ire_t
*ire_if
= NULL
;
14817 if ((ipif
->ipif_lcl_addr
!= INADDR_ANY
) &&
14818 !(ipif
->ipif_flags
& IPIF_NOLOCAL
)) {
14819 /* Register the source address for __sin6_src_id */
14820 err
= ip_srcid_insert(&ipif
->ipif_v6lcl_addr
,
14821 ipif
->ipif_zoneid
, ipst
);
14823 ip0dbg(("ipif_add_ires: srcid_insert %d\n", err
));
14828 gw
= (uchar_t
*)&ipif
->ipif_lcl_addr
;
14832 /* If the interface address is set, create the local IRE. */
14833 ire_local
= ire_create(
14834 (uchar_t
*)&ipif
->ipif_lcl_addr
, /* dest address */
14835 (uchar_t
*)&ip_g_all_ones
, /* mask */
14837 ipif
->ipif_ire_type
, /* LOCAL or LOOPBACK */
14840 ((ipif
->ipif_flags
& IPIF_PRIVATE
) ?
14841 RTF_PRIVATE
: 0) | RTF_KERNEL
,
14843 ip1dbg(("ipif_add_ires: 0x%p creating IRE %p type 0x%x"
14844 " for 0x%x\n", (void *)ipif
, (void *)ire_local
,
14845 ipif
->ipif_ire_type
,
14846 ntohl(ipif
->ipif_lcl_addr
)));
14847 if (ire_local
== NULL
) {
14848 ip1dbg(("ipif_up_done: NULL ire_local\n"));
14854 "ipif_add_ires: not creating IRE %d for 0x%x: flags 0x%x\n",
14855 ipif
->ipif_ire_type
,
14856 ntohl(ipif
->ipif_lcl_addr
),
14857 (uint_t
)ipif
->ipif_flags
));
14859 if ((ipif
->ipif_lcl_addr
!= INADDR_ANY
) &&
14860 !(ipif
->ipif_flags
& IPIF_NOLOCAL
)) {
14861 net_mask
= ip_net_mask(ipif
->ipif_lcl_addr
);
14863 net_mask
= htonl(IN_CLASSA_NET
); /* fallback */
14866 subnet_mask
= ipif
->ipif_net_mask
;
14869 * If mask was not specified, use natural netmask of
14870 * interface address. Also, store this mask back into the
14873 if (subnet_mask
== 0) {
14874 subnet_mask
= net_mask
;
14875 V4MASK_TO_V6(subnet_mask
, ipif
->ipif_v6net_mask
);
14876 V6_MASK_COPY(ipif
->ipif_v6lcl_addr
, ipif
->ipif_v6net_mask
,
14877 ipif
->ipif_v6subnet
);
14880 /* Set up the IRE_IF_RESOLVER or IRE_IF_NORESOLVER, as appropriate. */
14881 if (!loopback
&& !(ipif
->ipif_flags
& IPIF_NOXMIT
) &&
14882 ipif
->ipif_subnet
!= INADDR_ANY
) {
14883 /* ipif_subnet is ipif_pp_dst_addr for pt-pt */
14885 if (ipif
->ipif_flags
& IPIF_POINTOPOINT
) {
14886 route_mask
= IP_HOST_MASK
;
14888 route_mask
= subnet_mask
;
14891 ip1dbg(("ipif_add_ires: ipif 0x%p ill 0x%p "
14892 "creating if IRE ill_net_type 0x%x for 0x%x\n",
14893 (void *)ipif
, (void *)ill
, ill
->ill_net_type
,
14894 ntohl(ipif
->ipif_subnet
)));
14895 ire_if
= ire_create(
14896 (uchar_t
*)&ipif
->ipif_subnet
,
14897 (uchar_t
*)&route_mask
,
14898 (uchar_t
*)&ipif
->ipif_lcl_addr
,
14902 ((ipif
->ipif_flags
& IPIF_PRIVATE
) ?
14903 RTF_PRIVATE
: 0) | RTF_KERNEL
,
14905 if (ire_if
== NULL
) {
14906 ip1dbg(("ipif_up_done: NULL ire_if\n"));
14913 * Create any necessary broadcast IREs.
14915 if ((ipif
->ipif_flags
& IPIF_BROADCAST
) &&
14916 !(ipif
->ipif_flags
& IPIF_NOXMIT
))
14917 irep
= ipif_create_bcast_ires(ipif
, irep
);
14919 /* If an earlier ire_create failed, get out now */
14920 for (irep1
= irep
; irep1
> ire_array
; ) {
14922 if (*irep1
== NULL
) {
14923 ip1dbg(("ipif_up_done: NULL ire found in ire_array\n"));
14930 * Need to atomically check for IP address availability under
14931 * ip_addr_avail_lock. ill_g_lock is held as reader to ensure no new
14932 * ills or new ipifs can be added while we are checking availability.
14934 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
14935 mutex_enter(&ipst
->ips_ip_addr_avail_lock
);
14936 /* Mark it up, and increment counters. */
14937 ipif
->ipif_flags
|= IPIF_UP
;
14938 ill
->ill_ipif_up_count
++;
14939 err
= ip_addr_availability_check(ipif
);
14940 mutex_exit(&ipst
->ips_ip_addr_avail_lock
);
14941 rw_exit(&ipst
->ips_ill_g_lock
);
14945 * Our address may already be up on the same ill. In this case,
14946 * the ARP entry for our ipif replaced the one for the other
14947 * ipif. So we don't want to delete it (otherwise the other ipif
14948 * would be unable to send packets).
14949 * ip_addr_availability_check() identifies this case for us and
14950 * returns EADDRINUSE; Caller should turn it into EADDRNOTAVAIL
14951 * which is the expected error code.
14953 ill
->ill_ipif_up_count
--;
14954 ipif
->ipif_flags
&= ~IPIF_UP
;
14959 * Add in all newly created IREs. ire_create_bcast() has
14960 * already checked for duplicates of the IRE_BROADCAST type.
14961 * We add the IRE_INTERFACE before the IRE_LOCAL to ensure
14962 * that lookups find the IRE_LOCAL even if the IRE_INTERFACE is
14965 if (ire_if
!= NULL
) {
14966 ire_if
= ire_add(ire_if
);
14967 if (ire_if
== NULL
) {
14972 ire_refhold_notr(ire_if
);
14973 ire_refrele(ire_if
);
14976 if (ire_local
!= NULL
) {
14977 ire_local
= ire_add(ire_local
);
14978 if (ire_local
== NULL
) {
14983 ire_refhold_notr(ire_local
);
14984 ire_refrele(ire_local
);
14987 rw_enter(&ipst
->ips_ill_g_lock
, RW_WRITER
);
14988 if (ire_local
!= NULL
)
14989 ipif
->ipif_ire_local
= ire_local
;
14990 if (ire_if
!= NULL
)
14991 ipif
->ipif_ire_if
= ire_if
;
14992 rw_exit(&ipst
->ips_ill_g_lock
);
14997 * We first add all of them, and if that succeeds we refrele the
14998 * bunch. That enables us to delete all of them should any of the
15001 for (irep1
= irep
; irep1
> ire_array
; ) {
15003 ASSERT(!MUTEX_HELD(&((*irep1
)->ire_ill
->ill_lock
)));
15004 *irep1
= ire_add(*irep1
);
15005 if (*irep1
== NULL
) {
15011 for (irep1
= irep
; irep1
> ire_array
; ) {
15013 /* refheld by ire_add. */
15014 if (*irep1
!= NULL
) {
15015 ire_refrele(*irep1
);
15022 * If the broadcast address has been set, make sure it makes
15023 * sense based on the interface address.
15024 * Only match on ill since we are sharing broadcast addresses.
15026 if ((ipif
->ipif_brd_addr
!= INADDR_ANY
) &&
15027 (ipif
->ipif_flags
& IPIF_BROADCAST
)) {
15030 ire
= ire_ftable_lookup_v4(ipif
->ipif_brd_addr
, 0, 0,
15031 IRE_BROADCAST
, ipif
->ipif_ill
, ALL_ZONES
,
15032 (MATCH_IRE_TYPE
| MATCH_IRE_ILL
), 0, ipst
, NULL
);
15036 * If there isn't a matching broadcast IRE,
15037 * revert to the default for this netmask.
15039 ipif
->ipif_v6brd_addr
= ipv6_all_zeros
;
15040 mutex_enter(&ipif
->ipif_ill
->ill_lock
);
15041 ipif_set_default(ipif
);
15042 mutex_exit(&ipif
->ipif_ill
->ill_lock
);
15052 ill
->ill_ipif_up_count
--;
15053 ipif
->ipif_flags
&= ~IPIF_UP
;
15056 ip1dbg(("ipif_add_ires: FAILED \n"));
15057 if (ire_local
!= NULL
)
15058 ire_delete(ire_local
);
15059 if (ire_if
!= NULL
)
15060 ire_delete(ire_if
);
15062 rw_enter(&ipst
->ips_ill_g_lock
, RW_WRITER
);
15063 ire_local
= ipif
->ipif_ire_local
;
15064 ipif
->ipif_ire_local
= NULL
;
15065 ire_if
= ipif
->ipif_ire_if
;
15066 ipif
->ipif_ire_if
= NULL
;
15067 rw_exit(&ipst
->ips_ill_g_lock
);
15068 if (ire_local
!= NULL
) {
15069 ire_delete(ire_local
);
15070 ire_refrele_notr(ire_local
);
15072 if (ire_if
!= NULL
) {
15073 ire_delete(ire_if
);
15074 ire_refrele_notr(ire_if
);
15077 while (irep
> ire_array
) {
15079 if (*irep
!= NULL
) {
15083 (void) ip_srcid_remove(&ipif
->ipif_v6lcl_addr
, ipif
->ipif_zoneid
, ipst
);
15088 /* Remove all the IREs created by ipif_add_ires_v4 */
15090 ipif_delete_ires_v4(ipif_t
*ipif
)
15092 ill_t
*ill
= ipif
->ipif_ill
;
15093 ip_stack_t
*ipst
= ill
->ill_ipst
;
15096 rw_enter(&ipst
->ips_ill_g_lock
, RW_WRITER
);
15097 ire
= ipif
->ipif_ire_local
;
15098 ipif
->ipif_ire_local
= NULL
;
15099 rw_exit(&ipst
->ips_ill_g_lock
);
15102 * Move count to ipif so we don't loose the count due to
15105 atomic_add_32(&ipif
->ipif_ib_pkt_count
, ire
->ire_ib_pkt_count
);
15108 ire_refrele_notr(ire
);
15110 rw_enter(&ipst
->ips_ill_g_lock
, RW_WRITER
);
15111 ire
= ipif
->ipif_ire_if
;
15112 ipif
->ipif_ire_if
= NULL
;
15113 rw_exit(&ipst
->ips_ill_g_lock
);
15116 ire_refrele_notr(ire
);
15120 * Delete the broadcast IREs.
15122 if ((ipif
->ipif_flags
& IPIF_BROADCAST
) &&
15123 !(ipif
->ipif_flags
& IPIF_NOXMIT
))
15124 ipif_delete_bcast_ires(ipif
);
15128 * Checks for availbility of a usable source address (if there is one) when the
15129 * destination ILL has the ill_usesrc_ifindex pointing to another ILL. Note
15130 * this selection is done regardless of the destination.
15133 ipif_zone_avail(uint_t ifindex
, boolean_t isv6
, zoneid_t zoneid
,
15136 ipif_t
*ipif
= NULL
;
15139 ASSERT(ifindex
!= 0);
15141 uill
= ill_lookup_on_ifindex(ifindex
, isv6
, ipst
);
15145 mutex_enter(&uill
->ill_lock
);
15146 for (ipif
= uill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
15147 if (IPIF_IS_CONDEMNED(ipif
))
15149 if (ipif
->ipif_flags
& (IPIF_NOLOCAL
|IPIF_ANYCAST
))
15151 if (!(ipif
->ipif_flags
& IPIF_UP
))
15153 if (ipif
->ipif_zoneid
!= zoneid
)
15155 if (isv6
? IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6lcl_addr
) :
15156 ipif
->ipif_lcl_addr
== INADDR_ANY
)
15158 mutex_exit(&uill
->ill_lock
);
15162 mutex_exit(&uill
->ill_lock
);
15168 * Find an ipif with a good local address on the ill+zoneid.
15171 ipif_good_addr(ill_t
*ill
, zoneid_t zoneid
)
15175 mutex_enter(&ill
->ill_lock
);
15176 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
15177 if (IPIF_IS_CONDEMNED(ipif
))
15179 if (ipif
->ipif_flags
& (IPIF_NOLOCAL
|IPIF_ANYCAST
))
15181 if (!(ipif
->ipif_flags
& IPIF_UP
))
15183 if (ipif
->ipif_zoneid
!= zoneid
&&
15184 ipif
->ipif_zoneid
!= ALL_ZONES
&& zoneid
!= ALL_ZONES
)
15186 if (ill
->ill_isv6
?
15187 IN6_IS_ADDR_UNSPECIFIED(&ipif
->ipif_v6lcl_addr
) :
15188 ipif
->ipif_lcl_addr
== INADDR_ANY
)
15190 ipif_refhold_locked(ipif
);
15191 mutex_exit(&ill
->ill_lock
);
15194 mutex_exit(&ill
->ill_lock
);
15199 * IP source address type, sorted from worst to best. For a given type,
15200 * always prefer IP addresses on the same subnet. All-zones addresses are
15201 * suboptimal because they pose problems with unlabeled destinations.
15205 IPIF_DIFFNET_DEPRECATED
, /* deprecated and different subnet */
15206 IPIF_SAMENET_DEPRECATED
, /* deprecated and same subnet */
15207 IPIF_DIFFNET_ALLZONES
, /* allzones and different subnet */
15208 IPIF_SAMENET_ALLZONES
, /* allzones and same subnet */
15209 IPIF_DIFFNET
, /* normal and different subnet */
15210 IPIF_SAMENET
, /* normal and same subnet */
15211 IPIF_LOCALADDR
/* local loopback */
15215 * Pick the optimal ipif on `ill' for sending to destination `dst' from zone
15216 * `zoneid'. We rate usable ipifs from low -> high as per the ipif_type_t
15217 * enumeration, and return the highest-rated ipif. If there's a tie, we pick
15218 * the first one, unless IPMP is used in which case we round-robin among them;
15219 * see below for more.
15221 * Returns NULL if there is no suitable source address for the ill.
15222 * This only occurs when there is no valid source address for the ill.
15225 ipif_select_source_v4(ill_t
*ill
, ipaddr_t dst
, zoneid_t zoneid
,
15226 boolean_t allow_usesrc
, boolean_t
*notreadyp
)
15228 ill_t
*usill
= NULL
;
15229 ill_t
*ipmp_ill
= NULL
;
15230 ipif_t
*start_ipif
, *next_ipif
, *ipif
, *best_ipif
;
15231 ipif_type_t type
, best_type
;
15232 ip_stack_t
*ipst
= ill
->ill_ipst
;
15235 if (ill
->ill_usesrc_ifindex
!= 0 && allow_usesrc
) {
15236 usill
= ill_lookup_on_ifindex(ill
->ill_usesrc_ifindex
,
15239 ill
= usill
; /* Select source from usesrc ILL */
15245 * Test addresses should never be used for source address selection,
15246 * so if we were passed one, switch to the IPMP meta-interface.
15248 if (IS_UNDER_IPMP(ill
)) {
15249 if ((ipmp_ill
= ipmp_ill_hold_ipmp_ill(ill
)) != NULL
)
15250 ill
= ipmp_ill
; /* Select source from IPMP ill */
15256 * Hold the ill_g_lock as reader. This makes sure that no ipif/ill
15257 * can be deleted. But an ipif/ill can get CONDEMNED any time.
15258 * After selecting the right ipif, under ill_lock make sure ipif is
15259 * not condemned, and increment refcnt. If ipif is CONDEMNED,
15260 * we retry. Inside the loop we still need to check for CONDEMNED,
15261 * but not under a lock.
15263 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
15266 * For source address selection, we treat the ipif list as circular
15267 * and continue until we get back to where we started. This allows
15268 * IPMP to vary source address selection (which improves inbound load
15269 * spreading) by caching its last ending point and starting from
15270 * there. NOTE: we don't have to worry about ill_src_ipif changing
15271 * ills since that can't happen on the IPMP ill.
15273 start_ipif
= ill
->ill_ipif
;
15274 if (IS_IPMP(ill
) && ill
->ill_src_ipif
!= NULL
)
15275 start_ipif
= ill
->ill_src_ipif
;
15279 best_type
= IPIF_NONE
;
15281 if ((next_ipif
= ipif
->ipif_next
) == NULL
)
15282 next_ipif
= ill
->ill_ipif
;
15284 if (IPIF_IS_CONDEMNED(ipif
))
15286 /* Always skip NOLOCAL and ANYCAST interfaces */
15287 if (ipif
->ipif_flags
& (IPIF_NOLOCAL
|IPIF_ANYCAST
))
15289 /* Always skip NOACCEPT interfaces */
15290 if (ipif
->ipif_ill
->ill_flags
& ILLF_NOACCEPT
)
15292 if (!(ipif
->ipif_flags
& IPIF_UP
))
15295 if (!ipif
->ipif_addr_ready
) {
15296 if (notreadyp
!= NULL
)
15297 *notreadyp
= B_TRUE
;
15301 if (zoneid
!= ALL_ZONES
&&
15302 ipif
->ipif_zoneid
!= zoneid
&&
15303 ipif
->ipif_zoneid
!= ALL_ZONES
)
15307 * Interfaces with 0.0.0.0 address are allowed to be UP, but
15308 * are not valid as source addresses.
15310 if (ipif
->ipif_lcl_addr
== INADDR_ANY
)
15313 samenet
= ((ipif
->ipif_net_mask
& dst
) == ipif
->ipif_subnet
);
15315 if (ipif
->ipif_lcl_addr
== dst
) {
15316 type
= IPIF_LOCALADDR
;
15317 } else if (ipif
->ipif_flags
& IPIF_DEPRECATED
) {
15318 type
= samenet
? IPIF_SAMENET_DEPRECATED
:
15319 IPIF_DIFFNET_DEPRECATED
;
15320 } else if (ipif
->ipif_zoneid
== ALL_ZONES
) {
15321 type
= samenet
? IPIF_SAMENET_ALLZONES
:
15322 IPIF_DIFFNET_ALLZONES
;
15324 type
= samenet
? IPIF_SAMENET
: IPIF_DIFFNET
;
15327 if (type
> best_type
) {
15330 if (best_type
== IPIF_LOCALADDR
)
15331 break; /* can't get better */
15333 } while ((ipif
= next_ipif
) != start_ipif
);
15335 if ((ipif
= best_ipif
) != NULL
) {
15336 mutex_enter(&ipif
->ipif_ill
->ill_lock
);
15337 if (IPIF_IS_CONDEMNED(ipif
)) {
15338 mutex_exit(&ipif
->ipif_ill
->ill_lock
);
15341 ipif_refhold_locked(ipif
);
15344 * For IPMP, update the source ipif rotor to the next ipif,
15345 * provided we can look it up. (We must not use it if it's
15346 * IPIF_CONDEMNED since we may have grabbed ill_g_lock after
15347 * ipif_free() checked ill_src_ipif.)
15349 if (IS_IPMP(ill
) && ipif
!= NULL
) {
15350 next_ipif
= ipif
->ipif_next
;
15351 if (next_ipif
!= NULL
&& !IPIF_IS_CONDEMNED(next_ipif
))
15352 ill
->ill_src_ipif
= next_ipif
;
15354 ill
->ill_src_ipif
= NULL
;
15356 mutex_exit(&ipif
->ipif_ill
->ill_lock
);
15359 rw_exit(&ipst
->ips_ill_g_lock
);
15361 ill_refrele(usill
);
15362 if (ipmp_ill
!= NULL
)
15363 ill_refrele(ipmp_ill
);
15366 if (ipif
== NULL
) {
15367 char buf1
[INET6_ADDRSTRLEN
];
15369 ip1dbg(("ipif_select_source_v4(%s, %s) -> NULL\n",
15371 inet_ntop(AF_INET
, &dst
, buf1
, sizeof (buf1
))));
15373 char buf1
[INET6_ADDRSTRLEN
];
15374 char buf2
[INET6_ADDRSTRLEN
];
15376 ip1dbg(("ipif_select_source_v4(%s, %s) -> %s\n",
15377 ipif
->ipif_ill
->ill_name
,
15378 inet_ntop(AF_INET
, &dst
, buf1
, sizeof (buf1
)),
15379 inet_ntop(AF_INET
, &ipif
->ipif_lcl_addr
,
15380 buf2
, sizeof (buf2
))));
15387 * Pick a source address based on the destination ill and an optional setsrc
15389 * The result is stored in srcp. If generation is set, then put the source
15390 * generation number there before we look for the source address (to avoid
15391 * missing changes in the set of source addresses.
15392 * If flagsp is set, then us it to pass back ipif_flags.
15394 * If the caller wants to cache the returned source address and detect when
15395 * that might be stale, the caller should pass in a generation argument,
15396 * which the caller can later compare against ips_src_generation
15398 * The precedence order for selecting an IPv4 source address is:
15399 * - RTF_SETSRC on the offlink ire always wins.
15400 * - If usrsrc is set, swap the ill to be the usesrc one.
15401 * - If IPMP is used on the ill, select a random address from the most
15402 * preferred ones below:
15403 * 1. If onlink destination, same subnet and not deprecated, not ALL_ZONES
15404 * 2. Not deprecated, not ALL_ZONES
15405 * 3. If onlink destination, same subnet and not deprecated, ALL_ZONES
15406 * 4. Not deprecated, ALL_ZONES
15407 * 5. If onlink destination, same subnet and deprecated
15410 * We have lower preference for ALL_ZONES IP addresses,
15411 * as they pose problems with unlabeled destinations.
15413 * Note that when multiple IP addresses match e.g., #1 we pick
15414 * the first one if IPMP is not in use. With IPMP we randomize.
15417 ip_select_source_v4(ill_t
*ill
, ipaddr_t setsrc
, ipaddr_t dst
,
15418 ipaddr_t multicast_ifaddr
,
15419 zoneid_t zoneid
, ip_stack_t
*ipst
, ipaddr_t
*srcp
,
15420 uint32_t *generation
, uint64_t *flagsp
)
15423 boolean_t notready
= B_FALSE
; /* Set if !ipif_addr_ready found */
15425 if (flagsp
!= NULL
)
15429 * Need to grab the generation number before we check to
15430 * avoid a race with a change to the set of local addresses.
15431 * No lock needed since the thread which updates the set of local
15432 * addresses use ipif/ill locks and exit those (hence a store memory
15433 * barrier) before doing the atomic increase of ips_src_generation.
15435 if (generation
!= NULL
) {
15436 *generation
= ipst
->ips_src_generation
;
15439 if (CLASSD(dst
) && multicast_ifaddr
!= INADDR_ANY
) {
15440 *srcp
= multicast_ifaddr
;
15444 /* Was RTF_SETSRC set on the first IRE in the recursive lookup? */
15445 if (setsrc
!= INADDR_ANY
) {
15449 ipif
= ipif_select_source_v4(ill
, dst
, zoneid
, B_TRUE
, ¬ready
);
15450 if (ipif
== NULL
) {
15454 return (EADDRNOTAVAIL
);
15456 *srcp
= ipif
->ipif_lcl_addr
;
15457 if (flagsp
!= NULL
)
15458 *flagsp
= ipif
->ipif_flags
;
15459 ipif_refrele(ipif
);
15465 if_unitsel_restart(ipif_t
*ipif
, sin_t
*dummy_sin
, queue_t
*q
, mblk_t
*mp
,
15466 ip_ioctl_cmd_t
*ipip
, void *dummy_ifreq
)
15469 * ill_phyint_reinit merged the v4 and v6 into a single
15470 * ipsq. We might not have been able to complete the
15471 * operation in ipif_set_values, if we could not become
15472 * exclusive. If so restart it here.
15474 return (ipif_set_values_tail(ipif
->ipif_ill
, ipif
, mp
, q
));
15478 * Can operate on either a module or a driver queue.
15479 * Returns an error if not a module queue.
15483 if_unitsel(ipif_t
*dummy_ipif
, sin_t
*dummy_sin
, queue_t
*q
, mblk_t
*mp
,
15484 ip_ioctl_cmd_t
*ipip
, void *dummy_ifreq
)
15488 char interf_name
[LIFNAMSIZ
];
15489 uint_t ppa
= *(uint_t
*)mp
->b_cont
->b_cont
->b_rptr
;
15491 if (q
->q_next
== NULL
) {
15493 "if_unitsel: IF_UNITSEL: no q_next\n"));
15497 if (((ill_t
*)(q
->q_ptr
))->ill_name
[0] != '\0')
15502 } while (q1
->q_next
);
15503 cp
= q1
->q_qinfo
->qi_minfo
->mi_idname
;
15504 (void) sprintf(interf_name
, "%s%d", cp
, ppa
);
15507 * Here we are not going to delay the ioack until after
15508 * ACKs from DL_ATTACH_REQ/DL_BIND_REQ. So no need to save the
15509 * original ioctl message before sending the requests.
15511 return (ipif_set_values(q
, mp
, interf_name
, &ppa
));
15516 ip_sioctl_sifname(ipif_t
*dummy_ipif
, sin_t
*dummy_sin
, queue_t
*q
, mblk_t
*mp
,
15517 ip_ioctl_cmd_t
*ipip
, void *dummy_ifreq
)
15523 * Create any IRE_BROADCAST entries for `ipif', and store those entries in
15524 * `irep'. Returns a pointer to the next free `irep' entry
15525 * A mirror exists in ipif_delete_bcast_ires().
15527 * The management of any "extra" or seemingly duplicate IRE_BROADCASTs is
15531 ipif_create_bcast_ires(ipif_t
*ipif
, ire_t
**irep
)
15534 ipaddr_t netmask
= ip_net_mask(ipif
->ipif_lcl_addr
);
15535 ipaddr_t subnetmask
= ipif
->ipif_net_mask
;
15536 ill_t
*ill
= ipif
->ipif_ill
;
15537 zoneid_t zoneid
= ipif
->ipif_zoneid
;
15539 ip1dbg(("ipif_create_bcast_ires: creating broadcast IREs\n"));
15541 ASSERT(ipif
->ipif_flags
& IPIF_BROADCAST
);
15542 ASSERT(!(ipif
->ipif_flags
& IPIF_NOXMIT
));
15544 if (ipif
->ipif_lcl_addr
== INADDR_ANY
||
15545 (ipif
->ipif_flags
& IPIF_NOLOCAL
))
15546 netmask
= htonl(IN_CLASSA_NET
); /* fallback */
15548 irep
= ire_create_bcast(ill
, 0, zoneid
, irep
);
15549 irep
= ire_create_bcast(ill
, INADDR_BROADCAST
, zoneid
, irep
);
15552 * For backward compatibility, we create net broadcast IREs based on
15553 * the old "IP address class system", since some old machines only
15554 * respond to these class derived net broadcast. However, we must not
15555 * create these net broadcast IREs if the subnetmask is shorter than
15556 * the IP address class based derived netmask. Otherwise, we may
15557 * create a net broadcast address which is the same as an IP address
15558 * on the subnet -- and then TCP will refuse to talk to that address.
15560 if (netmask
< subnetmask
) {
15561 addr
= netmask
& ipif
->ipif_subnet
;
15562 irep
= ire_create_bcast(ill
, addr
, zoneid
, irep
);
15563 irep
= ire_create_bcast(ill
, ~netmask
| addr
, zoneid
, irep
);
15567 * Don't create IRE_BROADCAST IREs for the interface if the subnetmask
15568 * is 0xFFFFFFFF, as an IRE_LOCAL for that interface is already
15569 * created. Creating these broadcast IREs will only create confusion
15570 * as `addr' will be the same as the IP address.
15572 if (subnetmask
!= 0xFFFFFFFF) {
15573 addr
= ipif
->ipif_subnet
;
15574 irep
= ire_create_bcast(ill
, addr
, zoneid
, irep
);
15575 irep
= ire_create_bcast(ill
, ~subnetmask
| addr
, zoneid
, irep
);
15582 * Mirror of ipif_create_bcast_ires()
15585 ipif_delete_bcast_ires(ipif_t
*ipif
)
15588 ipaddr_t netmask
= ip_net_mask(ipif
->ipif_lcl_addr
);
15589 ipaddr_t subnetmask
= ipif
->ipif_net_mask
;
15590 ill_t
*ill
= ipif
->ipif_ill
;
15591 zoneid_t zoneid
= ipif
->ipif_zoneid
;
15594 ASSERT(ipif
->ipif_flags
& IPIF_BROADCAST
);
15595 ASSERT(!(ipif
->ipif_flags
& IPIF_NOXMIT
));
15597 if (ipif
->ipif_lcl_addr
== INADDR_ANY
||
15598 (ipif
->ipif_flags
& IPIF_NOLOCAL
))
15599 netmask
= htonl(IN_CLASSA_NET
); /* fallback */
15601 ire
= ire_lookup_bcast(ill
, 0, zoneid
);
15602 ASSERT(ire
!= NULL
);
15603 ire_delete(ire
); ire_refrele(ire
);
15604 ire
= ire_lookup_bcast(ill
, INADDR_BROADCAST
, zoneid
);
15605 ASSERT(ire
!= NULL
);
15606 ire_delete(ire
); ire_refrele(ire
);
15609 * For backward compatibility, we create net broadcast IREs based on
15610 * the old "IP address class system", since some old machines only
15611 * respond to these class derived net broadcast. However, we must not
15612 * create these net broadcast IREs if the subnetmask is shorter than
15613 * the IP address class based derived netmask. Otherwise, we may
15614 * create a net broadcast address which is the same as an IP address
15615 * on the subnet -- and then TCP will refuse to talk to that address.
15617 if (netmask
< subnetmask
) {
15618 addr
= netmask
& ipif
->ipif_subnet
;
15619 ire
= ire_lookup_bcast(ill
, addr
, zoneid
);
15620 ASSERT(ire
!= NULL
);
15621 ire_delete(ire
); ire_refrele(ire
);
15622 ire
= ire_lookup_bcast(ill
, ~netmask
| addr
, zoneid
);
15623 ASSERT(ire
!= NULL
);
15624 ire_delete(ire
); ire_refrele(ire
);
15628 * Don't create IRE_BROADCAST IREs for the interface if the subnetmask
15629 * is 0xFFFFFFFF, as an IRE_LOCAL for that interface is already
15630 * created. Creating these broadcast IREs will only create confusion
15631 * as `addr' will be the same as the IP address.
15633 if (subnetmask
!= 0xFFFFFFFF) {
15634 addr
= ipif
->ipif_subnet
;
15635 ire
= ire_lookup_bcast(ill
, addr
, zoneid
);
15636 ASSERT(ire
!= NULL
);
15637 ire_delete(ire
); ire_refrele(ire
);
15638 ire
= ire_lookup_bcast(ill
, ~subnetmask
| addr
, zoneid
);
15639 ASSERT(ire
!= NULL
);
15640 ire_delete(ire
); ire_refrele(ire
);
15645 * Extract both the flags (including IFF_CANTCHANGE) such as IFF_IPV*
15646 * from lifr_flags and the name from lifr_name.
15647 * Set IFF_IPV* and ill_isv6 prior to doing the lookup
15648 * since ipif_lookup_on_name uses the _isv6 flags when matching.
15649 * Returns EINPROGRESS when mp has been consumed by queueing it on
15650 * ipx_pending_mp and the ioctl will complete in ip_rput.
15652 * Can operate on either a module or a driver queue.
15653 * Returns an error if not a module queue.
15657 ip_sioctl_slifname(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
15658 ip_ioctl_cmd_t
*ipip
, void *if_req
)
15660 ill_t
*ill
= q
->q_ptr
;
15663 struct lifreq
*lifr
= if_req
;
15664 uint64_t new_flags
;
15666 ASSERT(ipif
!= NULL
);
15667 ip1dbg(("ip_sioctl_slifname %s\n", lifr
->lifr_name
));
15669 if (q
->q_next
== NULL
) {
15670 ip1dbg(("if_sioctl_slifname: SIOCSLIFNAME: no q_next\n"));
15675 * If we are not writer on 'q' then this interface exists already
15676 * and previous lookups (ip_extract_lifreq()) found this ipif --
15677 * so return EALREADY.
15679 if (ill
!= ipif
->ipif_ill
)
15682 if (ill
->ill_name
[0] != '\0')
15686 * If there's another ill already with the requested name, ensure
15687 * that it's of the same type. Otherwise, ill_phyint_reinit() will
15688 * fuse together two unrelated ills, which will cause chaos.
15690 ipst
= ill
->ill_ipst
;
15691 phyi
= avl_find(&ipst
->ips_phyint_g_list
->phyint_list_avl_by_name
,
15692 lifr
->lifr_name
, NULL
);
15693 if (phyi
!= NULL
) {
15694 ill_t
*ill_mate
= phyi
->phyint_illv4
;
15696 if (ill_mate
== NULL
)
15697 ill_mate
= phyi
->phyint_illv6
;
15698 ASSERT(ill_mate
!= NULL
);
15700 if (ill_mate
->ill_media
->ip_m_mac_type
!=
15701 ill
->ill_media
->ip_m_mac_type
) {
15702 ip1dbg(("if_sioctl_slifname: SIOCSLIFNAME: attempt to "
15703 "use the same ill name on differing media\n"));
15709 * We start off as IFF_IPV4 in ipif_allocate and become
15710 * IFF_IPV4 or IFF_IPV6 here depending on lifr_flags value.
15711 * The only flags that we read from user space are IFF_IPV4,
15712 * IFF_IPV6, and IFF_BROADCAST.
15714 * This ill has not been inserted into the global list.
15715 * So we are still single threaded and don't need any lock
15717 * Saniy check the flags.
15720 if ((lifr
->lifr_flags
& IFF_BROADCAST
) &&
15721 ((lifr
->lifr_flags
& IFF_IPV6
) ||
15722 (!ill
->ill_needs_attach
&& ill
->ill_bcast_addr_length
== 0))) {
15723 ip1dbg(("ip_sioctl_slifname: link not broadcast capable "
15724 "or IPv6 i.e., no broadcast \n"));
15729 lifr
->lifr_flags
& (IFF_IPV6
|IFF_IPV4
|IFF_BROADCAST
);
15731 if ((new_flags
^ (IFF_IPV6
|IFF_IPV4
)) == 0) {
15732 ip1dbg(("ip_sioctl_slifname: flags must be exactly one of "
15733 "IFF_IPV4 or IFF_IPV6\n"));
15738 * We always start off as IPv4, so only need to check for IPv6.
15740 if ((new_flags
& IFF_IPV6
) != 0) {
15741 ill
->ill_flags
|= ILLF_IPV6
;
15742 ill
->ill_flags
&= ~ILLF_IPV4
;
15744 if (lifr
->lifr_flags
& IFF_NOLINKLOCAL
)
15745 ill
->ill_flags
|= ILLF_NOLINKLOCAL
;
15748 if ((new_flags
& IFF_BROADCAST
) != 0)
15749 ipif
->ipif_flags
|= IPIF_BROADCAST
;
15751 ipif
->ipif_flags
&= ~IPIF_BROADCAST
;
15753 /* We started off as V4. */
15754 if (ill
->ill_flags
& ILLF_IPV6
) {
15755 ill
->ill_phyint
->phyint_illv6
= ill
;
15756 ill
->ill_phyint
->phyint_illv4
= NULL
;
15759 return (ipif_set_values(q
, mp
, lifr
->lifr_name
, &lifr
->lifr_ppa
));
15764 ip_sioctl_slifname_restart(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
15765 ip_ioctl_cmd_t
*ipip
, void *if_req
)
15768 * ill_phyint_reinit merged the v4 and v6 into a single
15769 * ipsq. We might not have been able to complete the
15770 * slifname in ipif_set_values, if we could not become
15771 * exclusive. If so restart it here
15773 return (ipif_set_values_tail(ipif
->ipif_ill
, ipif
, mp
, q
));
15777 * Return a pointer to the ipif which matches the index, IP version type and
15781 ipif_lookup_on_ifindex(uint_t index
, boolean_t isv6
, zoneid_t zoneid
,
15785 ipif_t
*ipif
= NULL
;
15787 ill
= ill_lookup_on_ifindex(index
, isv6
, ipst
);
15789 mutex_enter(&ill
->ill_lock
);
15790 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
15791 ipif
= ipif
->ipif_next
) {
15792 if (!IPIF_IS_CONDEMNED(ipif
) && (zoneid
== ALL_ZONES
||
15793 zoneid
== ipif
->ipif_zoneid
||
15794 ipif
->ipif_zoneid
== ALL_ZONES
)) {
15795 ipif_refhold_locked(ipif
);
15799 mutex_exit(&ill
->ill_lock
);
15806 * Change an existing physical interface's index. If the new index
15807 * is acceptable we update the index and the phyint_list_avl_by_index tree.
15808 * Finally, we update other systems which may have a dependence on the
15813 ip_sioctl_slifindex(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
15814 ip_ioctl_cmd_t
*ipip
, void *ifreq
)
15818 struct ifreq
*ifr
= (struct ifreq
*)ifreq
;
15819 struct lifreq
*lifr
= (struct lifreq
*)ifreq
;
15820 uint_t old_index
, index
;
15821 ip_stack_t
*ipst
= ipif
->ipif_ill
->ill_ipst
;
15824 if (ipip
->ipi_cmd_type
== IF_CMD
)
15825 index
= ifr
->ifr_index
;
15827 index
= lifr
->lifr_index
;
15830 * Only allow on physical interface. Also, index zero is illegal.
15832 ill
= ipif
->ipif_ill
;
15833 phyi
= ill
->ill_phyint
;
15834 if (ipif
->ipif_id
!= 0 || index
== 0 || index
> IF_INDEX_MAX
) {
15838 /* If the index is not changing, no work to do */
15839 if (phyi
->phyint_ifindex
== index
)
15843 * Use phyint_exists() to determine if the new interface index
15844 * is already in use. If the index is unused then we need to
15845 * change the phyint's position in the phyint_list_avl_by_index
15846 * tree. If we do not do this, subsequent lookups (using the new
15847 * index value) will not find the phyint.
15849 rw_enter(&ipst
->ips_ill_g_lock
, RW_WRITER
);
15850 if (phyint_exists(index
, ipst
)) {
15851 rw_exit(&ipst
->ips_ill_g_lock
);
15856 * The new index is unused. Set it in the phyint. However we must not
15857 * forget to trigger NE_IFINDEX_CHANGE event before the ifindex
15858 * changes. The event must be bound to old ifindex value.
15860 ill_nic_event_dispatch(ill
, 0, NE_IFINDEX_CHANGE
,
15861 &index
, sizeof (index
));
15863 old_index
= phyi
->phyint_ifindex
;
15864 phyi
->phyint_ifindex
= index
;
15866 avl_remove(&ipst
->ips_phyint_g_list
->phyint_list_avl_by_index
, phyi
);
15867 (void) avl_find(&ipst
->ips_phyint_g_list
->phyint_list_avl_by_index
,
15869 avl_insert(&ipst
->ips_phyint_g_list
->phyint_list_avl_by_index
,
15871 rw_exit(&ipst
->ips_ill_g_lock
);
15873 /* Update SCTP's ILL list */
15874 sctp_ill_reindex(ill
, old_index
);
15876 /* Send the routing sockets message */
15877 ip_rts_ifmsg(ipif
, RTSQ_DEFAULT
);
15878 if (ILL_OTHER(ill
))
15879 ip_rts_ifmsg(ILL_OTHER(ill
)->ill_ipif
, RTSQ_DEFAULT
);
15881 /* Perhaps ilgs should use this ill */
15882 update_conn_ill(NULL
, ill
->ill_ipst
);
15888 ip_sioctl_get_lifindex(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
15889 ip_ioctl_cmd_t
*ipip
, void *ifreq
)
15891 struct ifreq
*ifr
= (struct ifreq
*)ifreq
;
15892 struct lifreq
*lifr
= (struct lifreq
*)ifreq
;
15894 ip1dbg(("ip_sioctl_get_lifindex(%s:%u %p)\n",
15895 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
15896 /* Get the interface index */
15897 if (ipip
->ipi_cmd_type
== IF_CMD
) {
15898 ifr
->ifr_index
= ipif
->ipif_ill
->ill_phyint
->phyint_ifindex
;
15900 lifr
->lifr_index
= ipif
->ipif_ill
->ill_phyint
->phyint_ifindex
;
15907 ip_sioctl_get_lifzone(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
15908 ip_ioctl_cmd_t
*ipip
, void *ifreq
)
15910 struct lifreq
*lifr
= (struct lifreq
*)ifreq
;
15912 ip1dbg(("ip_sioctl_get_lifzone(%s:%u %p)\n",
15913 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
15914 /* Get the interface zone */
15915 ASSERT(ipip
->ipi_cmd_type
== LIF_CMD
);
15916 lifr
->lifr_zoneid
= ipif
->ipif_zoneid
;
15921 * Set the zoneid of an interface.
15925 ip_sioctl_slifzone(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
15926 ip_ioctl_cmd_t
*ipip
, void *ifreq
)
15928 struct lifreq
*lifr
= (struct lifreq
*)ifreq
;
15930 boolean_t need_up
= B_FALSE
;
15932 zone_status_t status
;
15935 ASSERT(ipip
->ipi_cmd_type
== LIF_CMD
);
15936 if ((zoneid
= lifr
->lifr_zoneid
) == ALL_ZONES
)
15939 /* cannot assign instance zero to a non-global zone */
15940 if (ipif
->ipif_id
== 0 && zoneid
!= GLOBAL_ZONEID
)
15944 * Cannot assign to a zone that doesn't exist or is shutting down. In
15945 * the event of a race with the zone shutdown processing, since IP
15946 * serializes this ioctl and SIOCGLIFCONF/SIOCLIFREMOVEIF, we know the
15947 * interface will be cleaned up even if the zone is shut down
15948 * immediately after the status check. If the interface can't be brought
15949 * down right away, and the zone is shut down before the restart
15950 * function is called, we resolve the possible races by rechecking the
15951 * zone status in the restart function.
15953 if ((zptr
= zone_find_by_id(zoneid
)) == NULL
)
15955 status
= zone_status_get(zptr
);
15958 if (status
!= ZONE_IS_READY
&& status
!= ZONE_IS_RUNNING
)
15961 if (ipif
->ipif_flags
& IPIF_UP
) {
15963 * If the interface is already marked up,
15964 * we call ipif_down which will take care
15965 * of ditching any IREs that have been set
15966 * up based on the old interface address.
15968 err
= ipif_logical_down(ipif
, q
, mp
);
15969 if (err
== EINPROGRESS
)
15971 (void) ipif_down_tail(ipif
);
15975 err
= ip_sioctl_slifzone_tail(ipif
, lifr
->lifr_zoneid
, q
, mp
, need_up
);
15980 ip_sioctl_slifzone_tail(ipif_t
*ipif
, zoneid_t zoneid
,
15981 queue_t
*q
, mblk_t
*mp
, boolean_t need_up
)
15986 ip1dbg(("ip_sioctl_zoneid_tail(%s:%u %p)\n",
15987 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
15990 ipst
= CONNQ_TO_IPST(q
);
15992 ipst
= ILLQ_TO_IPST(q
);
15995 * For exclusive stacks we don't allow a different zoneid than
15998 if (ipst
->ips_netstack
->netstack_stackid
!= GLOBAL_NETSTACKID
&&
15999 zoneid
!= GLOBAL_ZONEID
)
16002 /* Set the new zone id. */
16003 ipif
->ipif_zoneid
= zoneid
;
16005 /* Update sctp list */
16006 sctp_update_ipif(ipif
, SCTP_IPIF_UPDATE
);
16008 /* The default multicast interface might have changed */
16009 ire_increment_multicast_generation(ipst
, ipif
->ipif_ill
->ill_isv6
);
16013 * Now bring the interface back up. If this
16014 * is the only IPIF for the ILL, ipif_up
16015 * will have to re-bind to the device, so
16016 * we may get back EINPROGRESS, in which
16017 * case, this IOCTL will get completed in
16018 * ip_rput_dlpi when we see the DL_BIND_ACK.
16020 err
= ipif_up(ipif
, q
, mp
);
16027 ip_sioctl_slifzone_restart(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
16028 ip_ioctl_cmd_t
*ipip
, void *if_req
)
16030 struct lifreq
*lifr
= (struct lifreq
*)if_req
;
16033 zone_status_t status
;
16035 ASSERT(ipip
->ipi_cmd_type
== LIF_CMD
);
16036 if ((zoneid
= lifr
->lifr_zoneid
) == ALL_ZONES
)
16037 zoneid
= GLOBAL_ZONEID
;
16039 ip1dbg(("ip_sioctl_slifzone_restart(%s:%u %p)\n",
16040 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
16043 * We recheck the zone status to resolve the following race condition:
16044 * 1) process sends SIOCSLIFZONE to put hme0:1 in zone "myzone";
16045 * 2) hme0:1 is up and can't be brought down right away;
16046 * ip_sioctl_slifzone() returns EINPROGRESS and the request is queued;
16047 * 3) zone "myzone" is halted; the zone status switches to
16048 * 'shutting_down' and the zones framework sends SIOCGLIFCONF to list
16049 * the interfaces to remove - hme0:1 is not returned because it's not
16050 * yet in "myzone", so it won't be removed;
16051 * 4) the restart function for SIOCSLIFZONE is called; without the
16052 * status check here, we would have hme0:1 in "myzone" after it's been
16054 * Note that if the status check fails, we need to bring the interface
16055 * back to its state prior to ip_sioctl_slifzone(), hence the call to
16056 * ipif_up_done[_v6]().
16058 status
= ZONE_IS_UNINITIALIZED
;
16059 if ((zptr
= zone_find_by_id(zoneid
)) != NULL
) {
16060 status
= zone_status_get(zptr
);
16063 if (status
!= ZONE_IS_READY
&& status
!= ZONE_IS_RUNNING
) {
16064 if (ipif
->ipif_isv6
) {
16065 (void) ipif_up_done_v6(ipif
);
16067 (void) ipif_up_done(ipif
);
16072 (void) ipif_down_tail(ipif
);
16074 return (ip_sioctl_slifzone_tail(ipif
, lifr
->lifr_zoneid
, q
, mp
,
16079 * Return the number of addresses on `ill' with one or more of the values
16080 * in `set' set and all of the values in `clear' clear.
16083 ill_flagaddr_cnt(const ill_t
*ill
, uint64_t set
, uint64_t clear
)
16088 ASSERT(IAM_WRITER_ILL(ill
));
16090 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
)
16091 if ((ipif
->ipif_flags
& set
) && !(ipif
->ipif_flags
& clear
))
16098 * Return the number of migratable addresses on `ill' that are under
16099 * application control.
16102 ill_appaddr_cnt(const ill_t
*ill
)
16104 return (ill_flagaddr_cnt(ill
, IPIF_DHCPRUNNING
| IPIF_ADDRCONF
,
16109 * Return the number of point-to-point addresses on `ill'.
16112 ill_ptpaddr_cnt(const ill_t
*ill
)
16114 return (ill_flagaddr_cnt(ill
, IPIF_POINTOPOINT
, 0));
16119 ip_sioctl_get_lifusesrc(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
16120 ip_ioctl_cmd_t
*ipip
, void *ifreq
)
16122 struct lifreq
*lifr
= ifreq
;
16124 ASSERT(q
->q_next
== NULL
);
16127 ip1dbg(("ip_sioctl_get_lifusesrc(%s:%u %p)\n",
16128 ipif
->ipif_ill
->ill_name
, ipif
->ipif_id
, (void *)ipif
));
16129 lifr
->lifr_index
= ipif
->ipif_ill
->ill_usesrc_ifindex
;
16130 ip1dbg(("ip_sioctl_get_lifusesrc:lifr_index = %d\n", lifr
->lifr_index
));
16135 /* Find the previous ILL in this usesrc group */
16137 ill_prev_usesrc(ill_t
*uill
)
16141 for (ill
= uill
->ill_usesrc_grp_next
;
16142 ASSERT(ill
), ill
->ill_usesrc_grp_next
!= uill
;
16143 ill
= ill
->ill_usesrc_grp_next
)
16149 * Release all members of the usesrc group. This routine is called
16150 * from ill_delete when the interface being unplumbed is the
16153 * This silently clears the usesrc that ifconfig setup.
16154 * An alternative would be to keep that ifindex, and drop packets on the floor
16155 * since no source address can be selected.
16156 * Even if we keep the current semantics, don't need a lock and a linked list.
16157 * Can walk all the ills checking if they have a ill_usesrc_ifindex matching
16158 * the one that is being removed. Issue is how we return the usesrc users
16159 * (SIOCGLIFSRCOF). We want to be able to find the ills which have an
16160 * ill_usesrc_ifindex matching a target ill. We could also do that with an
16161 * ill walk, but the walker would need to insert in the ioctl response.
16164 ill_disband_usesrc_group(ill_t
*uill
)
16166 ill_t
*next_ill
, *tmp_ill
;
16167 ip_stack_t
*ipst
= uill
->ill_ipst
;
16169 ASSERT(RW_WRITE_HELD(&ipst
->ips_ill_g_usesrc_lock
));
16170 next_ill
= uill
->ill_usesrc_grp_next
;
16173 ASSERT(next_ill
!= NULL
);
16174 tmp_ill
= next_ill
->ill_usesrc_grp_next
;
16175 ASSERT(tmp_ill
!= NULL
);
16176 next_ill
->ill_usesrc_grp_next
= NULL
;
16177 next_ill
->ill_usesrc_ifindex
= 0;
16178 next_ill
= tmp_ill
;
16179 } while (next_ill
->ill_usesrc_ifindex
!= 0);
16180 uill
->ill_usesrc_grp_next
= NULL
;
16184 * Remove the client usesrc ILL from the list and relink to a new list
16187 ill_relink_usesrc_ills(ill_t
*ucill
, ill_t
*uill
, uint_t ifindex
)
16189 ill_t
*ill
, *tmp_ill
;
16190 ip_stack_t
*ipst
= ucill
->ill_ipst
;
16192 ASSERT((ucill
!= NULL
) && (ucill
->ill_usesrc_grp_next
!= NULL
) &&
16193 (uill
!= NULL
) && RW_WRITE_HELD(&ipst
->ips_ill_g_usesrc_lock
));
16196 * Check if the usesrc client ILL passed in is not already
16197 * in use as a usesrc ILL i.e one whose source address is
16198 * in use OR a usesrc ILL is not already in use as a usesrc
16201 if ((ucill
->ill_usesrc_ifindex
== 0) ||
16202 (uill
->ill_usesrc_ifindex
!= 0)) {
16206 ill
= ill_prev_usesrc(ucill
);
16207 ASSERT(ill
->ill_usesrc_grp_next
!= NULL
);
16209 /* Remove from the current list */
16210 if (ill
->ill_usesrc_grp_next
->ill_usesrc_grp_next
== ill
) {
16211 /* Only two elements in the list */
16212 ASSERT(ill
->ill_usesrc_ifindex
== 0);
16213 ill
->ill_usesrc_grp_next
= NULL
;
16215 ill
->ill_usesrc_grp_next
= ucill
->ill_usesrc_grp_next
;
16218 if (ifindex
== 0) {
16219 ucill
->ill_usesrc_ifindex
= 0;
16220 ucill
->ill_usesrc_grp_next
= NULL
;
16224 ucill
->ill_usesrc_ifindex
= ifindex
;
16225 tmp_ill
= uill
->ill_usesrc_grp_next
;
16226 uill
->ill_usesrc_grp_next
= ucill
;
16227 ucill
->ill_usesrc_grp_next
=
16228 (tmp_ill
!= NULL
) ? tmp_ill
: uill
;
16233 * Set the ill_usesrc and ill_usesrc_head fields. See synchronization notes in
16234 * ip.c for locking details.
16238 ip_sioctl_slifusesrc(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
16239 ip_ioctl_cmd_t
*ipip
, void *ifreq
)
16241 struct lifreq
*lifr
= (struct lifreq
*)ifreq
;
16242 boolean_t isv6
= B_FALSE
, reset_flg
= B_FALSE
;
16243 ill_t
*usesrc_ill
, *usesrc_cli_ill
= ipif
->ipif_ill
;
16246 ipsq_t
*ipsq
= NULL
;
16247 ip_stack_t
*ipst
= ipif
->ipif_ill
->ill_ipst
;
16249 ASSERT(IAM_WRITER_IPIF(ipif
));
16250 ASSERT(q
->q_next
== NULL
);
16253 isv6
= (Q_TO_CONN(q
))->conn_family
== AF_INET6
;
16255 ifindex
= lifr
->lifr_index
;
16256 if (ifindex
== 0) {
16257 if (usesrc_cli_ill
->ill_usesrc_grp_next
== NULL
) {
16258 /* non usesrc group interface, nothing to reset */
16261 ifindex
= usesrc_cli_ill
->ill_usesrc_ifindex
;
16262 /* valid reset request */
16263 reset_flg
= B_TRUE
;
16266 usesrc_ill
= ill_lookup_on_ifindex(ifindex
, isv6
, ipst
);
16267 if (usesrc_ill
== NULL
)
16269 if (usesrc_ill
== ipif
->ipif_ill
) {
16270 ill_refrele(usesrc_ill
);
16274 ipsq
= ipsq_try_enter(NULL
, usesrc_ill
, q
, mp
, ip_process_ioctl
,
16276 if (ipsq
== NULL
) {
16278 /* Operation enqueued on the ipsq of the usesrc ILL */
16282 /* USESRC isn't currently supported with IPMP */
16283 if (IS_IPMP(usesrc_ill
) || IS_UNDER_IPMP(usesrc_ill
)) {
16289 * USESRC isn't compatible with the STANDBY flag. (STANDBY is only
16290 * used by IPMP underlying interfaces, but someone might think it's
16291 * more general and try to use it independently with VNI.)
16293 if (usesrc_ill
->ill_phyint
->phyint_flags
& PHYI_STANDBY
) {
16299 * If the client is already in use as a usesrc_ill or a usesrc_ill is
16300 * already a client then return EINVAL
16302 if (IS_USESRC_ILL(usesrc_cli_ill
) || IS_USESRC_CLI_ILL(usesrc_ill
)) {
16308 * If the ill_usesrc_ifindex field is already set to what it needs to
16309 * be then this is a duplicate operation.
16311 if (!reset_flg
&& usesrc_cli_ill
->ill_usesrc_ifindex
== ifindex
) {
16316 ip1dbg(("ip_sioctl_slifusesrc: usesrc_cli_ill %s, usesrc_ill %s,"
16317 " v6 = %d", usesrc_cli_ill
->ill_name
, usesrc_ill
->ill_name
,
16318 usesrc_ill
->ill_isv6
));
16321 * ill_g_usesrc_lock global lock protects the ill_usesrc_grp_next
16322 * and the ill_usesrc_ifindex fields
16324 rw_enter(&ipst
->ips_ill_g_usesrc_lock
, RW_WRITER
);
16327 ret
= ill_relink_usesrc_ills(usesrc_cli_ill
, usesrc_ill
, 0);
16331 rw_exit(&ipst
->ips_ill_g_usesrc_lock
);
16336 * Four possibilities to consider:
16337 * 1. Both usesrc_ill and usesrc_cli_ill are not part of any usesrc grp
16338 * 2. usesrc_ill is part of a group but usesrc_cli_ill isn't
16339 * 3. usesrc_cli_ill is part of a group but usesrc_ill isn't
16340 * 4. Both are part of their respective usesrc groups
16342 if ((usesrc_ill
->ill_usesrc_grp_next
== NULL
) &&
16343 (usesrc_cli_ill
->ill_usesrc_grp_next
== NULL
)) {
16344 ASSERT(usesrc_ill
->ill_usesrc_ifindex
== 0);
16345 usesrc_cli_ill
->ill_usesrc_ifindex
= ifindex
;
16346 usesrc_ill
->ill_usesrc_grp_next
= usesrc_cli_ill
;
16347 usesrc_cli_ill
->ill_usesrc_grp_next
= usesrc_ill
;
16348 } else if ((usesrc_ill
->ill_usesrc_grp_next
!= NULL
) &&
16349 (usesrc_cli_ill
->ill_usesrc_grp_next
== NULL
)) {
16350 usesrc_cli_ill
->ill_usesrc_ifindex
= ifindex
;
16351 /* Insert at head of list */
16352 usesrc_cli_ill
->ill_usesrc_grp_next
=
16353 usesrc_ill
->ill_usesrc_grp_next
;
16354 usesrc_ill
->ill_usesrc_grp_next
= usesrc_cli_ill
;
16356 ret
= ill_relink_usesrc_ills(usesrc_cli_ill
, usesrc_ill
,
16361 rw_exit(&ipst
->ips_ill_g_usesrc_lock
);
16366 /* The refrele on the lifr_name ipif is done by ip_process_ioctl */
16367 ill_refrele(usesrc_ill
);
16369 /* Let conn_ixa caching know that source address selection changed */
16370 ip_update_source_selection(ipst
);
16377 ip_sioctl_get_dadstate(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
16378 ip_ioctl_cmd_t
*ipip
, void *if_req
)
16380 struct lifreq
*lifr
= (struct lifreq
*)if_req
;
16381 ill_t
*ill
= ipif
->ipif_ill
;
16384 * Need a lock since IFF_UP can be set even when there are
16385 * references to the ipif.
16387 mutex_enter(&ill
->ill_lock
);
16388 if ((ipif
->ipif_flags
& IPIF_UP
) && ipif
->ipif_addr_ready
== 0)
16389 lifr
->lifr_dadstate
= DAD_IN_PROGRESS
;
16391 lifr
->lifr_dadstate
= DAD_DONE
;
16392 mutex_exit(&ill
->ill_lock
);
16397 * comparison function used by avl.
16400 ill_phyint_compare_index(const void *index_ptr
, const void *phyip
)
16405 ASSERT(phyip
!= NULL
&& index_ptr
!= NULL
);
16407 index
= *((uint_t
*)index_ptr
);
16409 * let the phyint with the lowest index be on top.
16411 if (((phyint_t
*)phyip
)->phyint_ifindex
< index
)
16413 if (((phyint_t
*)phyip
)->phyint_ifindex
> index
)
16419 * comparison function used by avl.
16422 ill_phyint_compare_name(const void *name_ptr
, const void *phyip
)
16427 ASSERT(phyip
!= NULL
&& name_ptr
!= NULL
);
16429 if (((phyint_t
*)phyip
)->phyint_illv4
)
16430 ill
= ((phyint_t
*)phyip
)->phyint_illv4
;
16432 ill
= ((phyint_t
*)phyip
)->phyint_illv6
;
16433 ASSERT(ill
!= NULL
);
16435 res
= strcmp(ill
->ill_name
, (char *)name_ptr
);
16444 * This function is called on the unplumb path via ill_glist_delete() when
16445 * there are no ills left on the phyint and thus the phyint can be freed.
16448 phyint_free(phyint_t
*phyi
)
16450 ip_stack_t
*ipst
= PHYINT_TO_IPST(phyi
);
16452 ASSERT(phyi
->phyint_illv4
== NULL
&& phyi
->phyint_illv6
== NULL
);
16455 * If this phyint was an IPMP meta-interface, blow away the group.
16456 * This is safe to do because all of the illgrps have already been
16457 * removed by I_PUNLINK, and thus SIOCSLIFGROUPNAME cannot find us.
16458 * If we're cleaning up as a result of failed initialization,
16459 * phyint_grp may be NULL.
16461 if ((phyi
->phyint_flags
& PHYI_IPMP
) && (phyi
->phyint_grp
!= NULL
)) {
16462 rw_enter(&ipst
->ips_ipmp_lock
, RW_WRITER
);
16463 ipmp_grp_destroy(phyi
->phyint_grp
);
16464 phyi
->phyint_grp
= NULL
;
16465 rw_exit(&ipst
->ips_ipmp_lock
);
16469 * If this interface was under IPMP, take it out of the group.
16471 if (phyi
->phyint_grp
!= NULL
)
16472 ipmp_phyint_leave_grp(phyi
);
16475 * Delete the phyint and disassociate its ipsq. The ipsq itself
16476 * will be freed in ipsq_exit().
16478 phyi
->phyint_ipsq
->ipsq_phyint
= NULL
;
16479 phyi
->phyint_name
[0] = '\0';
16485 * Attach the ill to the phyint structure which can be shared by both
16486 * IPv4 and IPv6 ill. ill_init allocates a phyint to just hold flags. This
16487 * function is called from ipif_set_values and ill_lookup_on_name (for
16488 * loopback) where we know the name of the ill. We lookup the ill and if
16489 * there is one present already with the name use that phyint. Otherwise
16490 * reuse the one allocated by ill_init.
16493 ill_phyint_reinit(ill_t
*ill
)
16495 boolean_t isv6
= ill
->ill_isv6
;
16496 phyint_t
*phyi_old
;
16498 avl_index_t where
= 0;
16499 ill_t
*ill_other
= NULL
;
16500 ip_stack_t
*ipst
= ill
->ill_ipst
;
16502 ASSERT(RW_WRITE_HELD(&ipst
->ips_ill_g_lock
));
16504 phyi_old
= ill
->ill_phyint
;
16505 ASSERT(isv6
|| (phyi_old
->phyint_illv4
== ill
&&
16506 phyi_old
->phyint_illv6
== NULL
));
16507 ASSERT(!isv6
|| (phyi_old
->phyint_illv6
== ill
&&
16508 phyi_old
->phyint_illv4
== NULL
));
16509 ASSERT(phyi_old
->phyint_ifindex
== 0);
16512 * Now that our ill has a name, set it in the phyint.
16514 (void) strlcpy(ill
->ill_phyint
->phyint_name
, ill
->ill_name
, LIFNAMSIZ
);
16516 phyi
= avl_find(&ipst
->ips_phyint_g_list
->phyint_list_avl_by_name
,
16517 ill
->ill_name
, &where
);
16520 * 1. We grabbed the ill_g_lock before inserting this ill into
16521 * the global list of ills. So no other thread could have located
16522 * this ill and hence the ipsq of this ill is guaranteed to be empty.
16523 * 2. Now locate the other protocol instance of this ill.
16524 * 3. Now grab both ill locks in the right order, and the phyint lock of
16525 * the new ipsq. Holding ill locks + ill_g_lock ensures that the ipsq
16526 * of neither ill can change.
16527 * 4. Merge the phyint and thus the ipsq as well of this ill onto the
16529 * 5. Release all locks.
16533 * Look for IPv4 if we are initializing IPv6 or look for IPv6 if
16534 * we are initializing IPv4.
16536 if (phyi
!= NULL
) {
16537 ill_other
= (isv6
) ? phyi
->phyint_illv4
: phyi
->phyint_illv6
;
16538 ASSERT(ill_other
->ill_phyint
!= NULL
);
16539 ASSERT((isv6
&& !ill_other
->ill_isv6
) ||
16540 (!isv6
&& ill_other
->ill_isv6
));
16541 GRAB_ILL_LOCKS(ill
, ill_other
);
16543 * We are potentially throwing away phyint_flags which
16544 * could be different from the one that we obtain from
16545 * ill_other->ill_phyint. But it is okay as we are assuming
16546 * that the state maintained within IP is correct.
16548 mutex_enter(&phyi
->phyint_lock
);
16550 ASSERT(phyi
->phyint_illv6
== NULL
);
16551 phyi
->phyint_illv6
= ill
;
16553 ASSERT(phyi
->phyint_illv4
== NULL
);
16554 phyi
->phyint_illv4
= ill
;
16558 * Delete the old phyint and make its ipsq eligible
16559 * to be freed in ipsq_exit().
16561 phyi_old
->phyint_illv4
= NULL
;
16562 phyi_old
->phyint_illv6
= NULL
;
16563 phyi_old
->phyint_ipsq
->ipsq_phyint
= NULL
;
16564 phyi_old
->phyint_name
[0] = '\0';
16567 mutex_enter(&ill
->ill_lock
);
16569 * We don't need to acquire any lock, since
16570 * the ill is not yet visible globally and we
16571 * have not yet released the ill_g_lock.
16574 mutex_enter(&phyi
->phyint_lock
);
16575 /* XXX We need a recovery strategy here. */
16576 if (!phyint_assign_ifindex(phyi
, ipst
))
16577 cmn_err(CE_PANIC
, "phyint_assign_ifindex() failed");
16579 avl_insert(&ipst
->ips_phyint_g_list
->phyint_list_avl_by_name
,
16580 (void *)phyi
, where
);
16582 (void) avl_find(&ipst
->ips_phyint_g_list
->
16583 phyint_list_avl_by_index
,
16584 &phyi
->phyint_ifindex
, &where
);
16585 avl_insert(&ipst
->ips_phyint_g_list
->phyint_list_avl_by_index
,
16586 (void *)phyi
, where
);
16590 * Reassigning ill_phyint automatically reassigns the ipsq also.
16591 * pending mp is not affected because that is per ill basis.
16593 ill
->ill_phyint
= phyi
;
16596 * Now that the phyint's ifindex has been assigned, complete the
16599 ill
->ill_ip_mib
->ipIfStatsIfIndex
= ill
->ill_phyint
->phyint_ifindex
;
16600 if (ill
->ill_isv6
) {
16601 ill
->ill_icmp6_mib
->ipv6IfIcmpIfIndex
=
16602 ill
->ill_phyint
->phyint_ifindex
;
16603 ill
->ill_mcast_type
= ipst
->ips_mld_max_version
;
16605 ill
->ill_mcast_type
= ipst
->ips_igmp_max_version
;
16609 * Generate an event within the hooks framework to indicate that
16610 * a new interface has just been added to IP. For this event to
16611 * be generated, the network interface must, at least, have an
16612 * ifindex assigned to it. (We don't generate the event for
16613 * loopback since ill_lookup_on_name() has its own NE_PLUMB event.)
16615 * This needs to be run inside the ill_g_lock perimeter to ensure
16616 * that the ordering of delivered events to listeners matches the
16617 * order of them in the kernel.
16619 if (!IS_LOOPBACK(ill
)) {
16620 ill_nic_event_dispatch(ill
, 0, NE_PLUMB
, ill
->ill_name
,
16621 ill
->ill_name_length
);
16623 RELEASE_ILL_LOCKS(ill
, ill_other
);
16624 mutex_exit(&phyi
->phyint_lock
);
16628 * Notify any downstream modules of the name of this interface.
16629 * An M_IOCTL is used even though we don't expect a successful reply.
16630 * Any reply message from the driver (presumably an M_IOCNAK) will
16631 * eventually get discarded somewhere upstream. The message format is
16632 * simply an SIOCSLIFNAME ioctl just as might be sent from ifconfig
16636 ip_ifname_notify(ill_t
*ill
, queue_t
*q
)
16639 struct iocblk
*iocp
;
16640 struct lifreq
*lifr
;
16642 mp1
= mkiocb(SIOCSLIFNAME
);
16645 mp2
= allocb(sizeof (struct lifreq
), BPRI_HI
);
16652 iocp
= (struct iocblk
*)mp1
->b_rptr
;
16653 iocp
->ioc_count
= sizeof (struct lifreq
);
16655 lifr
= (struct lifreq
*)mp2
->b_rptr
;
16656 mp2
->b_wptr
+= sizeof (struct lifreq
);
16657 bzero(lifr
, sizeof (struct lifreq
));
16659 (void) strncpy(lifr
->lifr_name
, ill
->ill_name
, LIFNAMSIZ
);
16660 lifr
->lifr_ppa
= ill
->ill_ppa
;
16661 lifr
->lifr_flags
= (ill
->ill_flags
& (ILLF_IPV4
|ILLF_IPV6
));
16663 DTRACE_PROBE3(ill__dlpi
, char *, "ip_ifname_notify",
16664 char *, "SIOCSLIFNAME", ill_t
*, ill
);
16669 ipif_set_values_tail(ill_t
*ill
, ipif_t
*ipif
, mblk_t
*mp
, queue_t
*q
)
16672 ip_stack_t
*ipst
= ill
->ill_ipst
;
16673 phyint_t
*phyi
= ill
->ill_phyint
;
16676 * Now that ill_name is set, the configuration for the IPMP
16677 * meta-interface can be performed.
16679 if (IS_IPMP(ill
)) {
16680 rw_enter(&ipst
->ips_ipmp_lock
, RW_WRITER
);
16682 * If phyi->phyint_grp is NULL, then this is the first IPMP
16683 * meta-interface and we need to create the IPMP group.
16685 if (phyi
->phyint_grp
== NULL
) {
16687 * If someone has renamed another IPMP group to have
16688 * the same name as our interface, bail.
16690 if (ipmp_grp_lookup(ill
->ill_name
, ipst
) != NULL
) {
16691 rw_exit(&ipst
->ips_ipmp_lock
);
16694 phyi
->phyint_grp
= ipmp_grp_create(ill
->ill_name
, phyi
);
16695 if (phyi
->phyint_grp
== NULL
) {
16696 rw_exit(&ipst
->ips_ipmp_lock
);
16700 rw_exit(&ipst
->ips_ipmp_lock
);
16703 /* Tell downstream modules where they are. */
16704 ip_ifname_notify(ill
, q
);
16707 * ill_dl_phys returns EINPROGRESS in the usual case.
16708 * Error cases are ENOMEM ...
16710 err
= ill_dl_phys(ill
, ipif
, mp
, q
);
16712 if (ill
->ill_isv6
) {
16713 mutex_enter(&ipst
->ips_mld_slowtimeout_lock
);
16714 if (ipst
->ips_mld_slowtimeout_id
== 0) {
16715 ipst
->ips_mld_slowtimeout_id
= timeout(mld_slowtimo
,
16717 MSEC_TO_TICK(MCAST_SLOWTIMO_INTERVAL
));
16719 mutex_exit(&ipst
->ips_mld_slowtimeout_lock
);
16721 mutex_enter(&ipst
->ips_igmp_slowtimeout_lock
);
16722 if (ipst
->ips_igmp_slowtimeout_id
== 0) {
16723 ipst
->ips_igmp_slowtimeout_id
= timeout(igmp_slowtimo
,
16725 MSEC_TO_TICK(MCAST_SLOWTIMO_INTERVAL
));
16727 mutex_exit(&ipst
->ips_igmp_slowtimeout_lock
);
16734 * Common routine for ppa and ifname setting. Should be called exclusive.
16736 * Returns EINPROGRESS when mp has been consumed by queueing it on
16737 * ipx_pending_mp and the ioctl will complete in ip_rput.
16739 * NOTE : If ppa is UNIT_MAX, we assign the next valid ppa and return
16740 * the new name and new ppa in lifr_name and lifr_ppa respectively.
16741 * For SLIFNAME, we pass these values back to the userland.
16744 ipif_set_values(queue_t
*q
, mblk_t
*mp
, char *interf_name
, uint_t
*new_ppa_ptr
)
16755 ip1dbg(("ipif_set_values: interface %s\n", interf_name
));
16756 ASSERT(q
->q_next
!= NULL
);
16757 ASSERT(interf_name
!= NULL
);
16759 ill
= (ill_t
*)q
->q_ptr
;
16760 ipst
= ill
->ill_ipst
;
16762 ASSERT(ill
->ill_ipst
!= NULL
);
16763 ASSERT(ill
->ill_name
[0] == '\0');
16764 ASSERT(IAM_WRITER_ILL(ill
));
16765 ASSERT((mi_strlen(interf_name
) + 1) <= LIFNAMSIZ
);
16766 ASSERT(ill
->ill_ppa
== UINT_MAX
);
16768 ill
->ill_defend_start
= ill
->ill_defend_count
= 0;
16769 /* The ppa is sent down by ifconfig or is chosen */
16770 if ((ppa_ptr
= ill_get_ppa_ptr(interf_name
)) == NULL
) {
16775 * make sure ppa passed in is same as ppa in the name.
16776 * This check is not made when ppa == UINT_MAX in that case ppa
16777 * in the name could be anything. System will choose a ppa and
16778 * update new_ppa_ptr and inter_name to contain the choosen ppa.
16780 if (*new_ppa_ptr
!= UINT_MAX
) {
16781 /* stoi changes the pointer */
16784 * ifconfig passed in 0 for the ppa for DLPI 1 style devices
16785 * (they don't have an externally visible ppa). We assign one
16786 * here so that we can manage the interface. Note that in
16787 * the past this value was always 0 for DLPI 1 drivers.
16789 if (*new_ppa_ptr
== 0)
16790 *new_ppa_ptr
= stoi(&old_ptr
);
16791 else if (*new_ppa_ptr
!= (uint_t
)stoi(&old_ptr
))
16795 * terminate string before ppa
16796 * save char at that location.
16798 old_char
= ppa_ptr
[0];
16801 ill
->ill_ppa
= *new_ppa_ptr
;
16803 * Finish as much work now as possible before calling ill_glist_insert
16804 * which makes the ill globally visible and also merges it with the
16805 * other protocol instance of this phyint. The remaining work is
16806 * done after entering the ipsq which may happen sometime later.
16808 ipif
= ill
->ill_ipif
;
16810 /* We didn't do this when we allocated ipif in ip_ll_subnet_defaults */
16811 ipif_assign_seqid(ipif
);
16813 if (!(ill
->ill_flags
& (ILLF_IPV4
|ILLF_IPV6
)))
16814 ill
->ill_flags
|= ILLF_IPV4
;
16816 ASSERT(ipif
->ipif_next
== NULL
); /* Only one ipif on ill */
16817 ASSERT((ipif
->ipif_flags
& IPIF_UP
) == 0);
16819 if (ill
->ill_flags
& ILLF_IPV6
) {
16821 ill
->ill_isv6
= B_TRUE
;
16822 ill_set_inputfn(ill
);
16823 if (ill
->ill_rq
!= NULL
) {
16824 ill
->ill_rq
->q_qinfo
= &iprinitv6
;
16827 /* Keep the !IN6_IS_ADDR_V4MAPPED assertions happy */
16828 ipif
->ipif_v6lcl_addr
= ipv6_all_zeros
;
16829 ipif
->ipif_v6subnet
= ipv6_all_zeros
;
16830 ipif
->ipif_v6net_mask
= ipv6_all_zeros
;
16831 ipif
->ipif_v6brd_addr
= ipv6_all_zeros
;
16832 ipif
->ipif_v6pp_dst_addr
= ipv6_all_zeros
;
16833 ill
->ill_reachable_retrans_time
= ND_RETRANS_TIMER
;
16835 * point-to-point or Non-mulicast capable
16836 * interfaces won't do NUD unless explicitly
16837 * configured to do so.
16839 if (ipif
->ipif_flags
& IPIF_POINTOPOINT
||
16840 !(ill
->ill_flags
& ILLF_MULTICAST
)) {
16841 ill
->ill_flags
|= ILLF_NONUD
;
16843 /* Make sure IPv4 specific flag is not set on IPv6 if */
16844 if (ill
->ill_flags
& ILLF_NOARP
) {
16846 * Note: xresolv interfaces will eventually need
16847 * NOARP set here as well, but that will require
16848 * those external resolvers to have some
16849 * knowledge of that flag and act appropriately.
16850 * Not to be changed at present.
16852 ill
->ill_flags
&= ~ILLF_NOARP
;
16855 * Set the ILLF_ROUTER flag according to the global
16856 * IPv6 forwarding policy.
16858 if (ipst
->ips_ipv6_forwarding
!= 0)
16859 ill
->ill_flags
|= ILLF_ROUTER
;
16860 } else if (ill
->ill_flags
& ILLF_IPV4
) {
16861 ill
->ill_isv6
= B_FALSE
;
16862 ill_set_inputfn(ill
);
16863 ill
->ill_reachable_retrans_time
= ARP_RETRANS_TIMER
;
16864 IN6_IPADDR_TO_V4MAPPED(INADDR_ANY
, &ipif
->ipif_v6lcl_addr
);
16865 IN6_IPADDR_TO_V4MAPPED(INADDR_ANY
, &ipif
->ipif_v6subnet
);
16866 IN6_IPADDR_TO_V4MAPPED(INADDR_ANY
, &ipif
->ipif_v6net_mask
);
16867 IN6_IPADDR_TO_V4MAPPED(INADDR_ANY
, &ipif
->ipif_v6brd_addr
);
16868 IN6_IPADDR_TO_V4MAPPED(INADDR_ANY
, &ipif
->ipif_v6pp_dst_addr
);
16870 * Set the ILLF_ROUTER flag according to the global
16871 * IPv4 forwarding policy.
16873 if (ipst
->ips_ip_forwarding
!= 0)
16874 ill
->ill_flags
|= ILLF_ROUTER
;
16877 ASSERT(ill
->ill_phyint
!= NULL
);
16880 * The ipIfStatsIfindex and ipv6IfIcmpIfIndex assignments will
16881 * be completed in ill_glist_insert -> ill_phyint_reinit
16883 if (!ill_allocate_mibs(ill
))
16887 * Pick a default sap until we get the DL_INFO_ACK back from
16890 ill
->ill_sap
= (ill
->ill_isv6
) ? ill
->ill_media
->ip_m_ipv6sap
:
16891 ill
->ill_media
->ip_m_ipv4sap
;
16893 ill
->ill_ifname_pending
= 1;
16894 ill
->ill_ifname_pending_err
= 0;
16897 * When the first ipif comes up in ipif_up_done(), multicast groups
16898 * that were joined while this ill was not bound to the DLPI link need
16899 * to be recovered by ill_recover_multicast().
16901 ill
->ill_need_recover_multicast
= 1;
16904 rw_enter(&ipst
->ips_ill_g_lock
, RW_WRITER
);
16905 if ((error
= ill_glist_insert(ill
, interf_name
,
16906 (ill
->ill_flags
& ILLF_IPV6
) == ILLF_IPV6
)) > 0) {
16907 ill
->ill_ppa
= UINT_MAX
;
16908 ill
->ill_name
[0] = '\0';
16910 * undo null termination done above.
16912 ppa_ptr
[0] = old_char
;
16913 rw_exit(&ipst
->ips_ill_g_lock
);
16918 ASSERT(ill
->ill_name_length
<= LIFNAMSIZ
);
16921 * When we return the buffer pointed to by interf_name should contain
16922 * the same name as in ill_name.
16923 * If a ppa was choosen by the system (ppa passed in was UINT_MAX)
16924 * the buffer pointed to by new_ppa_ptr would not contain the right ppa
16925 * so copy full name and update the ppa ptr.
16926 * When ppa passed in != UINT_MAX all values are correct just undo
16927 * null termination, this saves a bcopy.
16929 if (*new_ppa_ptr
== UINT_MAX
) {
16930 bcopy(ill
->ill_name
, interf_name
, ill
->ill_name_length
);
16931 *new_ppa_ptr
= ill
->ill_ppa
;
16934 * undo null termination done above.
16936 ppa_ptr
[0] = old_char
;
16939 /* Let SCTP know about this ILL */
16940 sctp_update_ill(ill
, SCTP_ILL_INSERT
);
16943 * ill_glist_insert has made the ill visible globally, and
16944 * ill_phyint_reinit could have changed the ipsq. At this point,
16945 * we need to hold the ips_ill_g_lock across the call to enter the
16946 * ipsq to enforce atomicity and prevent reordering. In the event
16947 * the ipsq has changed, and if the new ipsq is currently busy,
16948 * we need to make sure that this half-completed ioctl is ahead of
16949 * any subsequent ioctl. We achieve this by not dropping the
16950 * ips_ill_g_lock which prevents any ill lookup itself thereby
16951 * ensuring that new ioctls can't start.
16953 ipsq
= ipsq_try_enter_internal(ill
, q
, mp
, ip_reprocess_ioctl
, NEW_OP
,
16956 rw_exit(&ipst
->ips_ill_g_lock
);
16959 return (EINPROGRESS
);
16962 * If ill_phyint_reinit() changed our ipsq, then start on the new ipsq.
16964 if (ipsq
->ipsq_xop
->ipx_current_ipif
== NULL
)
16965 ipsq_current_start(ipsq
, ipif
, SIOCSLIFNAME
);
16967 ASSERT(ipsq
->ipsq_xop
->ipx_current_ipif
== ipif
);
16969 error
= ipif_set_values_tail(ill
, ipif
, mp
, q
);
16971 if (error
!= 0 && error
!= EINPROGRESS
) {
16973 * restore previous values
16975 ill
->ill_isv6
= B_FALSE
;
16976 ill_set_inputfn(ill
);
16982 ipif_init(ip_stack_t
*ipst
)
16986 for (i
= 0; i
< MAX_G_HEADS
; i
++) {
16987 ipst
->ips_ill_g_heads
[i
].ill_g_list_head
=
16988 (ill_if_t
*)&ipst
->ips_ill_g_heads
[i
];
16989 ipst
->ips_ill_g_heads
[i
].ill_g_list_tail
=
16990 (ill_if_t
*)&ipst
->ips_ill_g_heads
[i
];
16993 avl_create(&ipst
->ips_phyint_g_list
->phyint_list_avl_by_index
,
16994 ill_phyint_compare_index
,
16996 offsetof(struct phyint
, phyint_avl_by_index
));
16997 avl_create(&ipst
->ips_phyint_g_list
->phyint_list_avl_by_name
,
16998 ill_phyint_compare_name
,
17000 offsetof(struct phyint
, phyint_avl_by_name
));
17004 * Save enough information so that we can recreate the IRE if
17005 * the interface goes down and then up.
17008 ill_save_ire(ill_t
*ill
, ire_t
*ire
)
17012 save_mp
= allocb(sizeof (ifrt_t
), BPRI_MED
);
17013 if (save_mp
!= NULL
) {
17016 save_mp
->b_wptr
+= sizeof (ifrt_t
);
17017 ifrt
= (ifrt_t
*)save_mp
->b_rptr
;
17018 bzero(ifrt
, sizeof (ifrt_t
));
17019 ifrt
->ifrt_type
= ire
->ire_type
;
17020 if (ire
->ire_ipversion
== IPV4_VERSION
) {
17021 ASSERT(!ill
->ill_isv6
);
17022 ifrt
->ifrt_addr
= ire
->ire_addr
;
17023 ifrt
->ifrt_gateway_addr
= ire
->ire_gateway_addr
;
17024 ifrt
->ifrt_setsrc_addr
= ire
->ire_setsrc_addr
;
17025 ifrt
->ifrt_mask
= ire
->ire_mask
;
17027 ASSERT(ill
->ill_isv6
);
17028 ifrt
->ifrt_v6addr
= ire
->ire_addr_v6
;
17029 /* ire_gateway_addr_v6 can change due to RTM_CHANGE */
17030 mutex_enter(&ire
->ire_lock
);
17031 ifrt
->ifrt_v6gateway_addr
= ire
->ire_gateway_addr_v6
;
17032 mutex_exit(&ire
->ire_lock
);
17033 ifrt
->ifrt_v6setsrc_addr
= ire
->ire_setsrc_addr_v6
;
17034 ifrt
->ifrt_v6mask
= ire
->ire_mask_v6
;
17036 ifrt
->ifrt_flags
= ire
->ire_flags
;
17037 ifrt
->ifrt_zoneid
= ire
->ire_zoneid
;
17038 mutex_enter(&ill
->ill_saved_ire_lock
);
17039 save_mp
->b_cont
= ill
->ill_saved_ire_mp
;
17040 ill
->ill_saved_ire_mp
= save_mp
;
17041 ill
->ill_saved_ire_cnt
++;
17042 mutex_exit(&ill
->ill_saved_ire_lock
);
17047 * Remove one entry from ill_saved_ire_mp.
17050 ill_remove_saved_ire(ill_t
*ill
, ire_t
*ire
)
17056 /* Remove from ill_saved_ire_mp list if it is there */
17057 mutex_enter(&ill
->ill_saved_ire_lock
);
17058 for (mpp
= &ill
->ill_saved_ire_mp
; *mpp
!= NULL
;
17059 mpp
= &(*mpp
)->b_cont
) {
17060 in6_addr_t gw_addr_v6
;
17063 * On a given ill, the tuple of address, gateway, mask,
17064 * ire_type, and zoneid is unique for each saved IRE.
17067 ifrt
= (ifrt_t
*)mp
->b_rptr
;
17068 /* ire_gateway_addr_v6 can change - need lock */
17069 mutex_enter(&ire
->ire_lock
);
17070 gw_addr_v6
= ire
->ire_gateway_addr_v6
;
17071 mutex_exit(&ire
->ire_lock
);
17073 if (ifrt
->ifrt_zoneid
!= ire
->ire_zoneid
||
17074 ifrt
->ifrt_type
!= ire
->ire_type
)
17077 if (ill
->ill_isv6
?
17078 (IN6_ARE_ADDR_EQUAL(&ifrt
->ifrt_v6addr
,
17079 &ire
->ire_addr_v6
) &&
17080 IN6_ARE_ADDR_EQUAL(&ifrt
->ifrt_v6gateway_addr
,
17082 IN6_ARE_ADDR_EQUAL(&ifrt
->ifrt_v6mask
,
17083 &ire
->ire_mask_v6
)) :
17084 (ifrt
->ifrt_addr
== ire
->ire_addr
&&
17085 ifrt
->ifrt_gateway_addr
== ire
->ire_gateway_addr
&&
17086 ifrt
->ifrt_mask
== ire
->ire_mask
)) {
17088 ill
->ill_saved_ire_cnt
--;
17093 mutex_exit(&ill
->ill_saved_ire_lock
);
17097 * IP multirouting broadcast routes handling
17098 * Append CGTP broadcast IREs to regular ones created
17099 * at ifconfig time.
17100 * The usage is a route add <cgtp_bc> <nic_bc> -multirt i.e., both
17101 * the destination and the gateway are broadcast addresses.
17102 * The caller has verified that the destination is an IRE_BROADCAST and that
17103 * RTF_MULTIRT was set. Here if the gateway is a broadcast address, then
17104 * we create a MULTIRT IRE_BROADCAST.
17105 * Note that the IRE_HOST created by ire_rt_add doesn't get found by anything
17106 * since the IRE_BROADCAST takes precedence; ire_add_v4 does head insertion.
17109 ip_cgtp_bcast_add(ire_t
*ire
, ip_stack_t
*ipst
)
17113 ASSERT(ire
!= NULL
);
17115 ire_prim
= ire_ftable_lookup_v4(ire
->ire_gateway_addr
, 0, 0,
17116 IRE_BROADCAST
, NULL
, ALL_ZONES
, MATCH_IRE_TYPE
, 0, ipst
, NULL
);
17117 if (ire_prim
!= NULL
) {
17119 * We are in the special case of broadcasts for
17120 * CGTP. We add an IRE_BROADCAST that holds
17121 * the RTF_MULTIRT flag, the destination
17122 * address and the low level
17123 * info of ire_prim. In other words, CGTP
17124 * broadcast is added to the redundant ipif.
17129 ill_prim
= ire_prim
->ire_ill
;
17131 ip2dbg(("ip_cgtp_filter_bcast_add: ire_prim %p, ill_prim %p\n",
17132 (void *)ire_prim
, (void *)ill_prim
));
17134 bcast_ire
= ire_create(
17135 (uchar_t
*)&ire
->ire_addr
,
17136 (uchar_t
*)&ip_g_all_ones
,
17137 (uchar_t
*)&ire
->ire_gateway_addr
,
17140 GLOBAL_ZONEID
, /* CGTP is only for the global zone */
17141 ire
->ire_flags
| RTF_KERNEL
,
17145 * Here we assume that ire_add does head insertion so that
17146 * the added IRE_BROADCAST comes before the existing IRE_HOST.
17148 if (bcast_ire
!= NULL
) {
17149 if (ire
->ire_flags
& RTF_SETSRC
) {
17150 bcast_ire
->ire_setsrc_addr
=
17151 ire
->ire_setsrc_addr
;
17153 bcast_ire
= ire_add(bcast_ire
);
17154 if (bcast_ire
!= NULL
) {
17155 ip2dbg(("ip_cgtp_filter_bcast_add: "
17156 "added bcast_ire %p\n",
17157 (void *)bcast_ire
));
17159 ill_save_ire(ill_prim
, bcast_ire
);
17160 ire_refrele(bcast_ire
);
17163 ire_refrele(ire_prim
);
17168 * IP multirouting broadcast routes handling
17169 * Remove the broadcast ire.
17170 * The usage is a route delete <cgtp_bc> <nic_bc> -multirt i.e., both
17171 * the destination and the gateway are broadcast addresses.
17172 * The caller has only verified that RTF_MULTIRT was set. We check
17173 * that the destination is broadcast and that the gateway is a broadcast
17174 * address, and if so delete the IRE added by ip_cgtp_bcast_add().
17177 ip_cgtp_bcast_delete(ire_t
*ire
, ip_stack_t
*ipst
)
17179 ASSERT(ire
!= NULL
);
17181 if (ip_type_v4(ire
->ire_addr
, ipst
) == IRE_BROADCAST
) {
17184 ire_prim
= ire_ftable_lookup_v4(ire
->ire_gateway_addr
, 0, 0,
17185 IRE_BROADCAST
, NULL
, ALL_ZONES
, MATCH_IRE_TYPE
, 0, ipst
,
17187 if (ire_prim
!= NULL
) {
17191 ill_prim
= ire_prim
->ire_ill
;
17193 ip2dbg(("ip_cgtp_filter_bcast_delete: "
17194 "ire_prim %p, ill_prim %p\n",
17195 (void *)ire_prim
, (void *)ill_prim
));
17197 bcast_ire
= ire_ftable_lookup_v4(ire
->ire_addr
, 0,
17198 ire
->ire_gateway_addr
, IRE_BROADCAST
,
17199 ill_prim
, ALL_ZONES
,
17200 MATCH_IRE_TYPE
| MATCH_IRE_GW
| MATCH_IRE_ILL
|
17201 MATCH_IRE_MASK
, 0, ipst
, NULL
);
17203 if (bcast_ire
!= NULL
) {
17204 ip2dbg(("ip_cgtp_filter_bcast_delete: "
17205 "looked up bcast_ire %p\n",
17206 (void *)bcast_ire
));
17207 ill_remove_saved_ire(bcast_ire
->ire_ill
,
17209 ire_delete(bcast_ire
);
17210 ire_refrele(bcast_ire
);
17212 ire_refrele(ire_prim
);
17218 * Derive an interface id from the link layer address.
17219 * Knows about IEEE 802 and IEEE EUI-64 mappings.
17222 ip_ether_v6intfid(ill_t
*ill
, in6_addr_t
*v6addr
)
17227 * Note that some IPv6 interfaces get plumbed over links that claim to
17228 * be DL_ETHER, but don't actually have Ethernet MAC addresses (e.g.
17229 * PPP links). The ETHERADDRL check here ensures that we only set the
17230 * interface ID on IPv6 interfaces above links that actually have real
17231 * Ethernet addresses.
17233 if (ill
->ill_phys_addr_length
== ETHERADDRL
) {
17234 /* Form EUI-64 like address */
17235 addr
= (char *)&v6addr
->s6_addr32
[2];
17236 bcopy(ill
->ill_phys_addr
, addr
, 3);
17237 addr
[0] ^= 0x2; /* Toggle Universal/Local bit */
17238 addr
[3] = (char)0xff;
17239 addr
[4] = (char)0xfe;
17240 bcopy(ill
->ill_phys_addr
+ 3, addr
+ 5, 3);
17246 ip_nodef_v6intfid(ill_t
*ill
, in6_addr_t
*v6addr
)
17250 typedef struct ipmp_ifcookie
{
17251 uint32_t ic_hostid
;
17252 char ic_ifname
[LIFNAMSIZ
];
17253 char ic_zonename
[ZONENAME_MAX
];
17257 * Construct a pseudo-random interface ID for the IPMP interface that's both
17258 * predictable and (almost) guaranteed to be unique.
17261 ip_ipmp_v6intfid(ill_t
*ill
, in6_addr_t
*v6addr
)
17268 ipmp_ifcookie_t ic
= { 0 };
17270 ASSERT(IS_IPMP(ill
));
17272 (void) ddi_strtoul(hw_serial
, NULL
, 10, &hostid
);
17273 ic
.ic_hostid
= htonl((uint32_t)hostid
);
17275 (void) strlcpy(ic
.ic_ifname
, ill
->ill_name
, LIFNAMSIZ
);
17277 if ((zp
= zone_find_by_id(ill
->ill_zoneid
)) != NULL
) {
17278 (void) strlcpy(ic
.ic_zonename
, zp
->zone_name
, ZONENAME_MAX
);
17283 MD5Update(&ctx
, &ic
, sizeof (ic
));
17284 MD5Final(hash
, &ctx
);
17287 * Map the hash to an interface ID per the basic approach in RFC3041.
17289 addr
= &v6addr
->s6_addr8
[8];
17290 bcopy(hash
+ 8, addr
, sizeof (uint64_t));
17291 addr
[0] &= ~0x2; /* set local bit */
17295 * Map the multicast in6_addr_t in m_ip6addr to the physaddr for ethernet.
17298 ip_ether_v6_mapping(ill_t
*ill
, uchar_t
*m_ip6addr
, uchar_t
*m_physaddr
)
17300 phyint_t
*phyi
= ill
->ill_phyint
;
17303 * Check PHYI_MULTI_BCAST and length of physical
17304 * address to determine if we use the mapping or the
17305 * broadcast address.
17307 if ((phyi
->phyint_flags
& PHYI_MULTI_BCAST
) != 0 ||
17308 ill
->ill_phys_addr_length
!= ETHERADDRL
) {
17309 ip_mbcast_mapping(ill
, m_ip6addr
, m_physaddr
);
17312 m_physaddr
[0] = 0x33;
17313 m_physaddr
[1] = 0x33;
17314 m_physaddr
[2] = m_ip6addr
[12];
17315 m_physaddr
[3] = m_ip6addr
[13];
17316 m_physaddr
[4] = m_ip6addr
[14];
17317 m_physaddr
[5] = m_ip6addr
[15];
17321 * Map the multicast ipaddr_t in m_ipaddr to the physaddr for ethernet.
17324 ip_ether_v4_mapping(ill_t
*ill
, uchar_t
*m_ipaddr
, uchar_t
*m_physaddr
)
17326 phyint_t
*phyi
= ill
->ill_phyint
;
17329 * Check PHYI_MULTI_BCAST and length of physical
17330 * address to determine if we use the mapping or the
17331 * broadcast address.
17333 if ((phyi
->phyint_flags
& PHYI_MULTI_BCAST
) != 0 ||
17334 ill
->ill_phys_addr_length
!= ETHERADDRL
) {
17335 ip_mbcast_mapping(ill
, m_ipaddr
, m_physaddr
);
17338 m_physaddr
[0] = 0x01;
17339 m_physaddr
[1] = 0x00;
17340 m_physaddr
[2] = 0x5e;
17341 m_physaddr
[3] = m_ipaddr
[1] & 0x7f;
17342 m_physaddr
[4] = m_ipaddr
[2];
17343 m_physaddr
[5] = m_ipaddr
[3];
17348 ip_mbcast_mapping(ill_t
*ill
, uchar_t
*m_ipaddr
, uchar_t
*m_physaddr
)
17351 * for the MULTI_BCAST case and other cases when we want to
17352 * use the link-layer broadcast address for multicast.
17354 uint8_t *bphys_addr
;
17355 dl_unitdata_req_t
*dlur
;
17357 dlur
= (dl_unitdata_req_t
*)ill
->ill_bcast_mp
->b_rptr
;
17358 if (ill
->ill_sap_length
< 0) {
17359 bphys_addr
= (uchar_t
*)dlur
+
17360 dlur
->dl_dest_addr_offset
;
17362 bphys_addr
= (uchar_t
*)dlur
+
17363 dlur
->dl_dest_addr_offset
+ ill
->ill_sap_length
;
17366 bcopy(bphys_addr
, m_physaddr
, ill
->ill_phys_addr_length
);
17370 * Derive IPoIB interface id from the link layer address.
17373 ip_ib_v6intfid(ill_t
*ill
, in6_addr_t
*v6addr
)
17377 ASSERT(ill
->ill_phys_addr_length
== 20);
17378 addr
= (char *)&v6addr
->s6_addr32
[2];
17379 bcopy(ill
->ill_phys_addr
+ 12, addr
, 8);
17381 * In IBA 1.1 timeframe, some vendors erroneously set the u/l bit
17382 * in the globally assigned EUI-64 GUID to 1, in violation of IEEE
17383 * rules. In these cases, the IBA considers these GUIDs to be in
17384 * "Modified EUI-64" format, and thus toggling the u/l bit is not
17385 * required; vendors are required not to assign global EUI-64's
17386 * that differ only in u/l bit values, thus guaranteeing uniqueness
17387 * of the interface identifier. Whether the GUID is in modified
17388 * or proper EUI-64 format, the ipv6 identifier must have the u/l
17391 addr
[0] |= 2; /* Set Universal/Local bit to 1 */
17395 * Map the multicast ipaddr_t in m_ipaddr to the physaddr for InfiniBand.
17396 * Note on mapping from multicast IP addresses to IPoIB multicast link
17397 * addresses. IPoIB multicast link addresses are based on IBA link addresses.
17398 * The format of an IPoIB multicast address is:
17400 * 4 byte QPN Scope Sign. Pkey
17401 * +--------------------------------------------+
17402 * | 00FFFFFF | FF | 1X | X01B | Pkey | GroupID |
17403 * +--------------------------------------------+
17405 * The Scope and Pkey components are properties of the IBA port and
17406 * network interface. They can be ascertained from the broadcast address.
17407 * The Sign. part is the signature, and is 401B for IPv4 and 601B for IPv6.
17410 ip_ib_v4_mapping(ill_t
*ill
, uchar_t
*m_ipaddr
, uchar_t
*m_physaddr
)
17412 static uint8_t ipv4_g_phys_ibmulti_addr
[] = { 0x00, 0xff, 0xff, 0xff,
17413 0xff, 0x10, 0x40, 0x1b, 0x00, 0x00, 0x00, 0x00,
17414 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
17415 uint8_t *bphys_addr
;
17416 dl_unitdata_req_t
*dlur
;
17418 bcopy(ipv4_g_phys_ibmulti_addr
, m_physaddr
, ill
->ill_phys_addr_length
);
17421 * RFC 4391: IPv4 MGID is 28-bit long.
17423 m_physaddr
[16] = m_ipaddr
[0] & 0x0f;
17424 m_physaddr
[17] = m_ipaddr
[1];
17425 m_physaddr
[18] = m_ipaddr
[2];
17426 m_physaddr
[19] = m_ipaddr
[3];
17429 dlur
= (dl_unitdata_req_t
*)ill
->ill_bcast_mp
->b_rptr
;
17430 if (ill
->ill_sap_length
< 0) {
17431 bphys_addr
= (uchar_t
*)dlur
+ dlur
->dl_dest_addr_offset
;
17433 bphys_addr
= (uchar_t
*)dlur
+ dlur
->dl_dest_addr_offset
+
17434 ill
->ill_sap_length
;
17437 * Now fill in the IBA scope/Pkey values from the broadcast address.
17439 m_physaddr
[5] = bphys_addr
[5];
17440 m_physaddr
[8] = bphys_addr
[8];
17441 m_physaddr
[9] = bphys_addr
[9];
17445 ip_ib_v6_mapping(ill_t
*ill
, uchar_t
*m_ipaddr
, uchar_t
*m_physaddr
)
17447 static uint8_t ipv4_g_phys_ibmulti_addr
[] = { 0x00, 0xff, 0xff, 0xff,
17448 0xff, 0x10, 0x60, 0x1b, 0x00, 0x00, 0x00, 0x00,
17449 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
17450 uint8_t *bphys_addr
;
17451 dl_unitdata_req_t
*dlur
;
17453 bcopy(ipv4_g_phys_ibmulti_addr
, m_physaddr
, ill
->ill_phys_addr_length
);
17456 * RFC 4391: IPv4 MGID is 80-bit long.
17458 bcopy(&m_ipaddr
[6], &m_physaddr
[10], 10);
17460 dlur
= (dl_unitdata_req_t
*)ill
->ill_bcast_mp
->b_rptr
;
17461 if (ill
->ill_sap_length
< 0) {
17462 bphys_addr
= (uchar_t
*)dlur
+ dlur
->dl_dest_addr_offset
;
17464 bphys_addr
= (uchar_t
*)dlur
+ dlur
->dl_dest_addr_offset
+
17465 ill
->ill_sap_length
;
17468 * Now fill in the IBA scope/Pkey values from the broadcast address.
17470 m_physaddr
[5] = bphys_addr
[5];
17471 m_physaddr
[8] = bphys_addr
[8];
17472 m_physaddr
[9] = bphys_addr
[9];
17476 * Derive IPv6 interface id from an IPv4 link-layer address (e.g. from an IPv4
17477 * tunnel). The IPv4 address simply get placed in the lower 4 bytes of the
17478 * IPv6 interface id. This is a suggested mechanism described in section 3.7
17482 ip_ipv4_genv6intfid(ill_t
*ill
, uint8_t *physaddr
, in6_addr_t
*v6addr
)
17484 ASSERT(ill
->ill_phys_addr_length
== sizeof (ipaddr_t
));
17485 v6addr
->s6_addr32
[2] = 0;
17486 bcopy(physaddr
, &v6addr
->s6_addr32
[3], sizeof (ipaddr_t
));
17490 * Derive IPv6 interface id from an IPv6 link-layer address (e.g. from an IPv6
17491 * tunnel). The lower 8 bytes of the IPv6 address simply become the interface
17495 ip_ipv6_genv6intfid(ill_t
*ill
, uint8_t *physaddr
, in6_addr_t
*v6addr
)
17497 in6_addr_t
*v6lladdr
= (in6_addr_t
*)physaddr
;
17499 ASSERT(ill
->ill_phys_addr_length
== sizeof (in6_addr_t
));
17500 bcopy(&v6lladdr
->s6_addr32
[2], &v6addr
->s6_addr32
[2], 8);
17504 ip_ipv6_v6intfid(ill_t
*ill
, in6_addr_t
*v6addr
)
17506 ip_ipv6_genv6intfid(ill
, ill
->ill_phys_addr
, v6addr
);
17510 ip_ipv6_v6destintfid(ill_t
*ill
, in6_addr_t
*v6addr
)
17512 ip_ipv6_genv6intfid(ill
, ill
->ill_dest_addr
, v6addr
);
17516 ip_ipv4_v6intfid(ill_t
*ill
, in6_addr_t
*v6addr
)
17518 ip_ipv4_genv6intfid(ill
, ill
->ill_phys_addr
, v6addr
);
17522 ip_ipv4_v6destintfid(ill_t
*ill
, in6_addr_t
*v6addr
)
17524 ip_ipv4_genv6intfid(ill
, ill
->ill_dest_addr
, v6addr
);
17528 * Lookup an ill and verify that the zoneid has an ipif on that ill.
17529 * Returns an held ill, or NULL.
17532 ill_lookup_on_ifindex_zoneid(uint_t index
, zoneid_t zoneid
, boolean_t isv6
,
17538 ill
= ill_lookup_on_ifindex(index
, isv6
, ipst
);
17542 mutex_enter(&ill
->ill_lock
);
17543 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
17544 if (IPIF_IS_CONDEMNED(ipif
))
17546 if (zoneid
!= ALL_ZONES
&& ipif
->ipif_zoneid
!= zoneid
&&
17547 ipif
->ipif_zoneid
!= ALL_ZONES
)
17550 mutex_exit(&ill
->ill_lock
);
17553 mutex_exit(&ill
->ill_lock
);
17559 * Return a pointer to an ipif_t given a combination of (ill_idx,ipif_id)
17560 * If a pointer to an ipif_t is returned then the caller will need to do
17561 * an ill_refrele().
17564 ipif_getby_indexes(uint_t ifindex
, uint_t lifidx
, boolean_t isv6
,
17570 ill
= ill_lookup_on_ifindex(ifindex
, isv6
, ipst
);
17574 mutex_enter(&ill
->ill_lock
);
17575 if (ill
->ill_state_flags
& ILL_CONDEMNED
) {
17576 mutex_exit(&ill
->ill_lock
);
17581 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
; ipif
= ipif
->ipif_next
) {
17582 if (!IPIF_CAN_LOOKUP(ipif
))
17584 if (lifidx
== ipif
->ipif_id
) {
17585 ipif_refhold_locked(ipif
);
17590 mutex_exit(&ill
->ill_lock
);
17596 * Set ill_inputfn based on the current know state.
17597 * This needs to be called when any of the factors taken into
17601 ill_set_inputfn(ill_t
*ill
)
17603 ip_stack_t
*ipst
= ill
->ill_ipst
;
17605 if (ill
->ill_isv6
) {
17606 ill
->ill_inputfn
= ill_input_short_v6
;
17608 if (ill
->ill_dhcpinit
!= 0)
17609 ill
->ill_inputfn
= ill_input_full_v4
;
17610 else if (ipst
->ips_ipcl_proto_fanout_v4
[IPPROTO_RSVP
].connf_head
17612 ill
->ill_inputfn
= ill_input_full_v4
;
17613 else if (ipst
->ips_ip_cgtp_filter
&&
17614 ipst
->ips_ip_cgtp_filter_ops
!= NULL
)
17615 ill
->ill_inputfn
= ill_input_full_v4
;
17617 ill
->ill_inputfn
= ill_input_short_v4
;
17622 * Re-evaluate ill_inputfn for all the IPv4 ills.
17623 * Used when RSVP and CGTP comes and goes.
17626 ill_set_inputfn_all(ip_stack_t
*ipst
)
17628 ill_walk_context_t ctx
;
17631 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
17632 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
17633 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
))
17634 ill_set_inputfn(ill
);
17636 rw_exit(&ipst
->ips_ill_g_lock
);
17640 * Set the physical address information for `ill' to the contents of the
17641 * dl_notify_ind_t pointed to by `mp'. Must be called as writer, and will be
17642 * asynchronous if `ill' cannot immediately be quiesced -- in which case
17643 * EINPROGRESS will be returned.
17646 ill_set_phys_addr(ill_t
*ill
, mblk_t
*mp
)
17648 ipsq_t
*ipsq
= ill
->ill_phyint
->phyint_ipsq
;
17649 dl_notify_ind_t
*dlindp
= (dl_notify_ind_t
*)mp
->b_rptr
;
17651 ASSERT(IAM_WRITER_IPSQ(ipsq
));
17653 if (dlindp
->dl_data
!= DL_IPV6_LINK_LAYER_ADDR
&&
17654 dlindp
->dl_data
!= DL_CURR_DEST_ADDR
&&
17655 dlindp
->dl_data
!= DL_CURR_PHYS_ADDR
) {
17656 /* Changing DL_IPV6_TOKEN is not yet supported */
17661 * We need to store up to two copies of `mp' in `ill'. Due to the
17662 * design of ipsq_pending_mp_add(), we can't pass them as separate
17663 * arguments to ill_set_phys_addr_tail(). Instead, chain them
17664 * together here, then pull 'em apart in ill_set_phys_addr_tail().
17666 if ((mp
= copyb(mp
)) == NULL
|| (mp
->b_cont
= copyb(mp
)) == NULL
) {
17671 ipsq_current_start(ipsq
, ill
->ill_ipif
, 0);
17674 * Since we'll only do a logical down, we can't rely on ipif_down
17675 * to turn on ILL_DOWN_IN_PROGRESS, or for the DL_BIND_ACK to reset
17676 * ILL_DOWN_IN_PROGRESS. We instead manage this separately for this
17677 * case, to quiesce ire's and nce's for ill_is_quiescent.
17679 mutex_enter(&ill
->ill_lock
);
17680 ill
->ill_state_flags
|= ILL_DOWN_IN_PROGRESS
;
17681 /* no more ire/nce addition allowed */
17682 mutex_exit(&ill
->ill_lock
);
17685 * If we can quiesce the ill, then set the address. If not, then
17686 * ill_set_phys_addr_tail() will be called from ipif_ill_refrele_tail().
17688 ill_down_ipifs(ill
, B_TRUE
);
17689 mutex_enter(&ill
->ill_lock
);
17690 if (!ill_is_quiescent(ill
)) {
17691 /* call cannot fail since `conn_t *' argument is NULL */
17692 (void) ipsq_pending_mp_add(NULL
, ill
->ill_ipif
, ill
->ill_rq
,
17694 mutex_exit(&ill
->ill_lock
);
17695 return (EINPROGRESS
);
17697 mutex_exit(&ill
->ill_lock
);
17699 ill_set_phys_addr_tail(ipsq
, ill
->ill_rq
, mp
, NULL
);
17704 * When the allowed-ips link property is set on the datalink, IP receives a
17705 * DL_NOTE_ALLOWED_IPS notification that is processed in ill_set_allowed_ips()
17706 * to initialize the ill_allowed_ips[] array in the ill_t. This array is then
17707 * used to vet addresses passed to ip_sioctl_addr() and to ensure that the
17708 * only IP addresses configured on the ill_t are those in the ill_allowed_ips[]
17712 ill_set_allowed_ips(ill_t
*ill
, mblk_t
*mp
)
17714 ipsq_t
*ipsq
= ill
->ill_phyint
->phyint_ipsq
;
17715 dl_notify_ind_t
*dlip
= (dl_notify_ind_t
*)mp
->b_rptr
;
17716 mac_protect_t
*mrp
;
17719 ASSERT(IAM_WRITER_IPSQ(ipsq
));
17720 mrp
= (mac_protect_t
*)&dlip
[1];
17722 if (mrp
->mp_ipaddrcnt
== 0) { /* reset allowed-ips */
17723 kmem_free(ill
->ill_allowed_ips
,
17724 ill
->ill_allowed_ips_cnt
* sizeof (in6_addr_t
));
17725 ill
->ill_allowed_ips_cnt
= 0;
17726 ill
->ill_allowed_ips
= NULL
;
17727 mutex_enter(&ill
->ill_phyint
->phyint_lock
);
17728 ill
->ill_phyint
->phyint_flags
&= ~PHYI_L3PROTECT
;
17729 mutex_exit(&ill
->ill_phyint
->phyint_lock
);
17733 if (ill
->ill_allowed_ips
!= NULL
) {
17734 kmem_free(ill
->ill_allowed_ips
,
17735 ill
->ill_allowed_ips_cnt
* sizeof (in6_addr_t
));
17737 ill
->ill_allowed_ips_cnt
= mrp
->mp_ipaddrcnt
;
17738 ill
->ill_allowed_ips
= kmem_alloc(
17739 ill
->ill_allowed_ips_cnt
* sizeof (in6_addr_t
), KM_SLEEP
);
17740 for (i
= 0; i
< mrp
->mp_ipaddrcnt
; i
++)
17741 ill
->ill_allowed_ips
[i
] = mrp
->mp_ipaddrs
[i
].ip_addr
;
17743 mutex_enter(&ill
->ill_phyint
->phyint_lock
);
17744 ill
->ill_phyint
->phyint_flags
|= PHYI_L3PROTECT
;
17745 mutex_exit(&ill
->ill_phyint
->phyint_lock
);
17749 * Once the ill associated with `q' has quiesced, set its physical address
17750 * information to the values in `addrmp'. Note that two copies of `addrmp'
17751 * are passed (linked by b_cont), since we sometimes need to save two distinct
17752 * copies in the ill_t, and our context doesn't permit sleeping or allocation
17753 * failure (we'll free the other copy if it's not needed). Since the ill_t
17754 * is quiesced, we know any stale nce's with the old address information have
17755 * already been removed, so we don't need to call nce_flush().
17759 ill_set_phys_addr_tail(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*addrmp
, void *dummy
)
17761 ill_t
*ill
= q
->q_ptr
;
17762 mblk_t
*addrmp2
= unlinkb(addrmp
);
17763 dl_notify_ind_t
*dlindp
= (dl_notify_ind_t
*)addrmp
->b_rptr
;
17764 uint_t addrlen
, addroff
;
17767 ASSERT(IAM_WRITER_IPSQ(ipsq
));
17769 addroff
= dlindp
->dl_addr_offset
;
17770 addrlen
= dlindp
->dl_addr_length
- ABS(ill
->ill_sap_length
);
17772 switch (dlindp
->dl_data
) {
17773 case DL_IPV6_LINK_LAYER_ADDR
:
17774 ill_set_ndmp(ill
, addrmp
, addroff
, addrlen
);
17778 case DL_CURR_DEST_ADDR
:
17779 freemsg(ill
->ill_dest_addr_mp
);
17780 ill
->ill_dest_addr
= addrmp
->b_rptr
+ addroff
;
17781 ill
->ill_dest_addr_mp
= addrmp
;
17782 if (ill
->ill_isv6
) {
17783 ill_setdesttoken(ill
);
17784 ipif_setdestlinklocal(ill
->ill_ipif
);
17789 case DL_CURR_PHYS_ADDR
:
17790 freemsg(ill
->ill_phys_addr_mp
);
17791 ill
->ill_phys_addr
= addrmp
->b_rptr
+ addroff
;
17792 ill
->ill_phys_addr_mp
= addrmp
;
17793 ill
->ill_phys_addr_length
= addrlen
;
17795 ill_set_ndmp(ill
, addrmp2
, addroff
, addrlen
);
17798 if (ill
->ill_isv6
) {
17799 ill_setdefaulttoken(ill
);
17800 ipif_setlinklocal(ill
->ill_ipif
);
17808 * reset ILL_DOWN_IN_PROGRESS so that we can successfully add ires
17809 * as we bring the ipifs up again.
17811 mutex_enter(&ill
->ill_lock
);
17812 ill
->ill_state_flags
&= ~ILL_DOWN_IN_PROGRESS
;
17813 mutex_exit(&ill
->ill_lock
);
17815 * If there are ipifs to bring up, ill_up_ipifs() will return
17816 * EINPROGRESS, and ipsq_current_finish() will be called by
17817 * ip_rput_dlpi_writer() or arp_bringup_done() when the last ipif is
17820 status
= ill_up_ipifs(ill
, q
, addrmp
);
17821 if (status
!= EINPROGRESS
)
17822 ipsq_current_finish(ipsq
);
17826 * Helper routine for setting the ill_nd_lla fields.
17829 ill_set_ndmp(ill_t
*ill
, mblk_t
*ndmp
, uint_t addroff
, uint_t addrlen
)
17831 freemsg(ill
->ill_nd_lla_mp
);
17832 ill
->ill_nd_lla
= ndmp
->b_rptr
+ addroff
;
17833 ill
->ill_nd_lla_mp
= ndmp
;
17834 ill
->ill_nd_lla_len
= addrlen
;
17841 ill_replumb(ill_t
*ill
, mblk_t
*mp
)
17843 ipsq_t
*ipsq
= ill
->ill_phyint
->phyint_ipsq
;
17845 ASSERT(IAM_WRITER_IPSQ(ipsq
));
17847 ipsq_current_start(ipsq
, ill
->ill_ipif
, 0);
17850 * If we can quiesce the ill, then continue. If not, then
17851 * ill_replumb_tail() will be called from ipif_ill_refrele_tail().
17853 ill_down_ipifs(ill
, B_FALSE
);
17855 mutex_enter(&ill
->ill_lock
);
17856 if (!ill_is_quiescent(ill
)) {
17857 /* call cannot fail since `conn_t *' argument is NULL */
17858 (void) ipsq_pending_mp_add(NULL
, ill
->ill_ipif
, ill
->ill_rq
,
17860 mutex_exit(&ill
->ill_lock
);
17861 return (EINPROGRESS
);
17863 mutex_exit(&ill
->ill_lock
);
17865 ill_replumb_tail(ipsq
, ill
->ill_rq
, mp
, NULL
);
17871 ill_replumb_tail(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
, void *dummy
)
17873 ill_t
*ill
= q
->q_ptr
;
17875 conn_t
*connp
= NULL
;
17877 ASSERT(IAM_WRITER_IPSQ(ipsq
));
17878 freemsg(ill
->ill_replumb_mp
);
17879 ill
->ill_replumb_mp
= copyb(mp
);
17881 if (ill
->ill_replumb_mp
== NULL
) {
17882 /* out of memory */
17883 ipsq_current_finish(ipsq
);
17887 mutex_enter(&ill
->ill_lock
);
17888 ill
->ill_up_ipifs
= ipsq_pending_mp_add(NULL
, ill
->ill_ipif
,
17889 ill
->ill_rq
, ill
->ill_replumb_mp
, 0);
17890 mutex_exit(&ill
->ill_lock
);
17892 if (!ill
->ill_up_ipifs
) {
17893 /* already closing */
17894 ipsq_current_finish(ipsq
);
17897 ill
->ill_replumbing
= 1;
17898 err
= ill_down_ipifs_tail(ill
);
17901 * Successfully quiesced and brought down the interface, now we send
17902 * the DL_NOTE_REPLUMB_DONE message down to the driver. Reuse the
17903 * DL_NOTE_REPLUMB message.
17905 mp
= mexchange(NULL
, mp
, sizeof (dl_notify_conf_t
), M_PROTO
,
17907 ASSERT(mp
!= NULL
);
17908 ((dl_notify_conf_t
*)mp
->b_rptr
)->dl_notification
=
17909 DL_NOTE_REPLUMB_DONE
;
17910 ill_dlpi_send(ill
, mp
);
17913 * For IPv4, we would usually get EINPROGRESS because the ETHERTYPE_ARP
17914 * streams have to be unbound. When all the DLPI exchanges are done,
17915 * ipsq_current_finish() will be called by arp_bringup_done(). The
17916 * remainder of ipif bringup via ill_up_ipifs() will also be done in
17917 * arp_bringup_done().
17919 ASSERT(ill
->ill_replumb_mp
!= NULL
);
17920 if (err
== EINPROGRESS
)
17923 ill
->ill_replumb_mp
= ipsq_pending_mp_get(ipsq
, &connp
);
17924 ASSERT(connp
== NULL
);
17925 if (err
== 0 && ill
->ill_replumb_mp
!= NULL
&&
17926 ill_up_ipifs(ill
, q
, ill
->ill_replumb_mp
) == EINPROGRESS
) {
17929 ipsq_current_finish(ipsq
);
17933 * Issue ioctl `cmd' on `lh'; caller provides the initial payload in `buf'
17934 * which is `bufsize' bytes. On success, zero is returned and `buf' updated
17935 * as per the ioctl. On failure, an errno is returned.
17938 ip_ioctl(ldi_handle_t lh
, int cmd
, void *buf
, uint_t bufsize
, cred_t
*cr
)
17941 struct strioctl iocb
;
17944 iocb
.ic_timout
= 15;
17945 iocb
.ic_len
= bufsize
;
17948 return (ldi_ioctl(lh
, I_STR
, (intptr_t)&iocb
, FKIOCTL
, cr
, &rval
));
17952 * Issue an SIOCGLIFCONF for address family `af' and store the result into a
17953 * dynamically-allocated `lifcp' that will be `bufsizep' bytes on success.
17956 ip_lifconf_ioctl(ldi_handle_t lh
, int af
, struct lifconf
*lifcp
,
17957 uint_t
*bufsizep
, cred_t
*cr
)
17960 struct lifnum lifn
;
17962 bzero(&lifn
, sizeof (lifn
));
17963 lifn
.lifn_family
= af
;
17964 lifn
.lifn_flags
= LIFC_UNDER_IPMP
;
17966 if ((err
= ip_ioctl(lh
, SIOCGLIFNUM
, &lifn
, sizeof (lifn
), cr
)) != 0)
17970 * Pad the interface count to account for additional interfaces that
17971 * may have been configured between the SIOCGLIFNUM and SIOCGLIFCONF.
17973 lifn
.lifn_count
+= 4;
17974 bzero(lifcp
, sizeof (*lifcp
));
17975 lifcp
->lifc_flags
= LIFC_UNDER_IPMP
;
17976 lifcp
->lifc_family
= af
;
17977 lifcp
->lifc_len
= *bufsizep
= lifn
.lifn_count
* sizeof (struct lifreq
);
17978 lifcp
->lifc_buf
= kmem_zalloc(*bufsizep
, KM_SLEEP
);
17980 err
= ip_ioctl(lh
, SIOCGLIFCONF
, lifcp
, sizeof (*lifcp
), cr
);
17982 kmem_free(lifcp
->lifc_buf
, *bufsizep
);
17990 * Helper for ip_interface_cleanup() that removes the loopback interface.
17993 ip_loopback_removeif(ldi_handle_t lh
, boolean_t isv6
, cred_t
*cr
)
17996 struct lifreq lifr
;
17998 bzero(&lifr
, sizeof (lifr
));
17999 (void) strcpy(lifr
.lifr_name
, ipif_loopback_name
);
18002 * Attempt to remove the interface. It may legitimately not exist
18003 * (e.g. the zone administrator unplumbed it), so ignore ENXIO.
18005 err
= ip_ioctl(lh
, SIOCLIFREMOVEIF
, &lifr
, sizeof (lifr
), cr
);
18006 if (err
!= 0 && err
!= ENXIO
) {
18007 ip0dbg(("ip_loopback_removeif: IP%s SIOCLIFREMOVEIF failed: "
18008 "error %d\n", isv6
? "v6" : "v4", err
));
18013 * Helper for ip_interface_cleanup() that ensures no IP interfaces are in IPMP
18014 * groups and that IPMP data addresses are down. These conditions must be met
18015 * so that IPMP interfaces can be I_PUNLINK'd, as per ip_sioctl_plink_ipmp().
18018 ip_ipmp_cleanup(ldi_handle_t lh
, boolean_t isv6
, cred_t
*cr
)
18020 int af
= isv6
? AF_INET6
: AF_INET
;
18024 uint_t lifrsize
= sizeof (struct lifreq
);
18025 struct lifconf lifc
;
18026 struct lifreq
*lifrp
;
18028 if ((err
= ip_lifconf_ioctl(lh
, af
, &lifc
, &bufsize
, cr
)) != 0) {
18029 cmn_err(CE_WARN
, "ip_ipmp_cleanup: cannot get interface list "
18030 "(error %d); any IPMP interfaces cannot be shutdown", err
);
18034 nifs
= lifc
.lifc_len
/ lifrsize
;
18035 for (lifrp
= lifc
.lifc_req
, i
= 0; i
< nifs
; i
++, lifrp
++) {
18036 err
= ip_ioctl(lh
, SIOCGLIFFLAGS
, lifrp
, lifrsize
, cr
);
18038 cmn_err(CE_WARN
, "ip_ipmp_cleanup: %s: cannot get "
18039 "flags: error %d", lifrp
->lifr_name
, err
);
18043 if (lifrp
->lifr_flags
& IFF_IPMP
) {
18044 if ((lifrp
->lifr_flags
& (IFF_UP
|IFF_DUPLICATE
)) == 0)
18047 lifrp
->lifr_flags
&= ~IFF_UP
;
18048 err
= ip_ioctl(lh
, SIOCSLIFFLAGS
, lifrp
, lifrsize
, cr
);
18050 cmn_err(CE_WARN
, "ip_ipmp_cleanup: %s: cannot "
18051 "bring down (error %d); IPMP interface may "
18052 "not be shutdown", lifrp
->lifr_name
, err
);
18056 * Check if IFF_DUPLICATE is still set -- and if so,
18057 * reset the address to clear it.
18059 err
= ip_ioctl(lh
, SIOCGLIFFLAGS
, lifrp
, lifrsize
, cr
);
18060 if (err
!= 0 || !(lifrp
->lifr_flags
& IFF_DUPLICATE
))
18063 err
= ip_ioctl(lh
, SIOCGLIFADDR
, lifrp
, lifrsize
, cr
);
18064 if (err
!= 0 || (err
= ip_ioctl(lh
, SIOCGLIFADDR
,
18065 lifrp
, lifrsize
, cr
)) != 0) {
18066 cmn_err(CE_WARN
, "ip_ipmp_cleanup: %s: cannot "
18067 "reset DAD (error %d); IPMP interface may "
18068 "not be shutdown", lifrp
->lifr_name
, err
);
18073 if (strchr(lifrp
->lifr_name
, IPIF_SEPARATOR_CHAR
) == 0) {
18074 lifrp
->lifr_groupname
[0] = '\0';
18075 if ((err
= ip_ioctl(lh
, SIOCSLIFGROUPNAME
, lifrp
,
18076 lifrsize
, cr
)) != 0) {
18077 cmn_err(CE_WARN
, "ip_ipmp_cleanup: %s: cannot "
18078 "leave IPMP group (error %d); associated "
18079 "IPMP interface may not be shutdown",
18080 lifrp
->lifr_name
, err
);
18086 kmem_free(lifc
.lifc_buf
, bufsize
);
18089 #define UDPDEV "/devices/pseudo/udp@0:udp"
18090 #define UDP6DEV "/devices/pseudo/udp6@0:udp6"
18093 * Remove the loopback interfaces and prep the IPMP interfaces to be torn down.
18094 * Non-loopback interfaces are either I_LINK'd or I_PLINK'd; the former go away
18095 * when the user-level processes in the zone are killed and the latter are
18096 * cleaned up by str_stack_shutdown().
18099 ip_interface_cleanup(ip_stack_t
*ipst
)
18106 char *devs
[] = { UDP6DEV
, UDPDEV
};
18107 netstackid_t stackid
= ipst
->ips_netstack
->netstack_stackid
;
18109 if ((err
= ldi_ident_from_major(ddi_name_to_major("ip"), &li
)) != 0) {
18110 cmn_err(CE_WARN
, "ip_interface_cleanup: cannot get ldi ident:"
18115 cr
= zone_get_kcred(netstackid_to_zoneid(stackid
));
18116 ASSERT(cr
!= NULL
);
18119 * NOTE: loop executes exactly twice and is hardcoded to know that the
18120 * first iteration is IPv6. (Unrolling yields repetitious code, hence
18123 for (i
= 0; i
< 2; i
++) {
18124 err
= ldi_open_by_name(devs
[i
], FREAD
|FWRITE
, cr
, &lh
, li
);
18126 cmn_err(CE_WARN
, "ip_interface_cleanup: cannot open %s:"
18127 " error %d", devs
[i
], err
);
18131 ip_loopback_removeif(lh
, i
== 0, cr
);
18132 ip_ipmp_cleanup(lh
, i
== 0, cr
);
18134 (void) ldi_close(lh
, FREAD
|FWRITE
, cr
);
18137 ldi_ident_release(li
);
18142 * This needs to be in-sync with nic_event_t definition
18144 static const char *
18145 ill_hook_event2str(nic_event_t event
)
18151 return ("UNPLUMB");
18156 case NE_ADDRESS_CHANGE
:
18157 return ("ADDRESS_CHANGE");
18161 return ("LIF_DOWN");
18162 case NE_IFINDEX_CHANGE
:
18163 return ("IFINDEX_CHANGE");
18165 return ("UNKNOWN");
18170 ill_nic_event_dispatch(ill_t
*ill
, lif_if_t lif
, nic_event_t event
,
18171 nic_event_data_t data
, size_t datalen
)
18173 ip_stack_t
*ipst
= ill
->ill_ipst
;
18174 hook_nic_event_int_t
*info
;
18175 const char *str
= NULL
;
18177 /* create a new nic event info */
18178 if ((info
= kmem_alloc(sizeof (*info
), KM_NOSLEEP
)) == NULL
)
18181 info
->hnei_event
.hne_nic
= ill
->ill_phyint
->phyint_ifindex
;
18182 info
->hnei_event
.hne_lif
= lif
;
18183 info
->hnei_event
.hne_event
= event
;
18184 info
->hnei_event
.hne_protocol
= ill
->ill_isv6
?
18185 ipst
->ips_ipv6_net_data
: ipst
->ips_ipv4_net_data
;
18186 info
->hnei_event
.hne_data
= NULL
;
18187 info
->hnei_event
.hne_datalen
= 0;
18188 info
->hnei_stackid
= ipst
->ips_netstack
->netstack_stackid
;
18190 if (data
!= NULL
&& datalen
!= 0) {
18191 info
->hnei_event
.hne_data
= kmem_alloc(datalen
, KM_NOSLEEP
);
18192 if (info
->hnei_event
.hne_data
== NULL
)
18194 bcopy(data
, info
->hnei_event
.hne_data
, datalen
);
18195 info
->hnei_event
.hne_datalen
= datalen
;
18198 if (ddi_taskq_dispatch(eventq_queue_nic
, ip_ne_queue_func
, info
,
18199 DDI_NOSLEEP
) == DDI_SUCCESS
)
18203 if (info
!= NULL
) {
18204 if (info
->hnei_event
.hne_data
!= NULL
) {
18205 kmem_free(info
->hnei_event
.hne_data
,
18206 info
->hnei_event
.hne_datalen
);
18208 kmem_free(info
, sizeof (hook_nic_event_t
));
18210 str
= ill_hook_event2str(event
);
18211 ip2dbg(("ill_nic_event_dispatch: could not dispatch %s nic event "
18212 "information for %s (ENOMEM)\n", str
, ill
->ill_name
));
18216 ipif_arp_up_done_tail(ipif_t
*ipif
, enum ip_resolver_action res_act
)
18219 const in_addr_t
*addr
= NULL
;
18221 ill_t
*ill
= ipif
->ipif_ill
;
18223 boolean_t added_ipif
= B_FALSE
;
18227 DTRACE_PROBE3(ipif__downup
, char *, "ipif_arp_up_done_tail",
18228 ill_t
*, ill
, ipif_t
*, ipif
);
18229 if (ipif
->ipif_lcl_addr
!= INADDR_ANY
) {
18230 addr
= &ipif
->ipif_lcl_addr
;
18233 if ((ipif
->ipif_flags
& IPIF_UNNUMBERED
) || addr
== NULL
) {
18234 if (res_act
!= Res_act_initial
)
18238 if (addr
!= NULL
) {
18239 ipmp_illgrp_t
*illg
= ill
->ill_grp
;
18241 /* add unicast nce for the local addr */
18243 if (IS_IPMP(ill
)) {
18245 * If we're here via ipif_up(), then the ipif
18246 * won't be bound yet -- add it to the group,
18247 * which will bind it if possible. (We would
18248 * add it in ipif_up(), but deleting on failure
18249 * there is gruesome.) If we're here via
18250 * ipmp_ill_bind_ipif(), then the ipif has
18251 * already been added to the group and we
18252 * just need to use the binding.
18254 if ((bound_ill
= ipmp_ipif_bound_ill(ipif
)) == NULL
) {
18255 bound_ill
= ipmp_illgrp_add_ipif(illg
, ipif
);
18256 if (bound_ill
== NULL
) {
18258 * We couldn't bind the ipif to an ill
18259 * yet, so we have nothing to publish.
18260 * Mark the address as ready and return.
18262 ipif
->ipif_addr_ready
= 1;
18265 added_ipif
= B_TRUE
;
18271 flags
= (NCE_F_MYADDR
| NCE_F_PUBLISH
| NCE_F_AUTHORITY
|
18274 * If this is an initial bring-up (or the ipif was never
18275 * completely brought up), do DAD. Otherwise, we're here
18276 * because IPMP has rebound an address to this ill: send
18277 * unsolicited advertisements (ARP announcements) to
18280 if (res_act
== Res_act_initial
|| !ipif
->ipif_addr_ready
) {
18281 state
= ND_UNCHANGED
; /* compute in nce_add_common() */
18283 state
= ND_REACHABLE
;
18284 flags
|= NCE_F_UNSOL_ADV
;
18288 err
= nce_lookup_then_add_v4(ill
,
18289 bound_ill
->ill_phys_addr
, bound_ill
->ill_phys_addr_length
,
18290 addr
, flags
, state
, &nce
);
18293 * note that we may encounter EEXIST if we are moving
18294 * the nce as a result of a rebind operation.
18298 ipif
->ipif_added_nce
= 1;
18299 nce
->nce_ipif_cnt
++;
18302 ip1dbg(("ipif_arp_up: NCE already exists for %s\n",
18304 if (!NCE_MYADDR(nce
->nce_common
)) {
18306 * A leftover nce from before this address
18309 ncec_delete(nce
->nce_common
);
18314 if ((ipif
->ipif_flags
& IPIF_POINTOPOINT
) == 0) {
18317 ip1dbg(("ipif_arp_up: NCE already exists "
18318 "for %s:%u\n", ill
->ill_name
,
18323 * Duplicate local addresses are permissible for
18324 * IPIF_POINTOPOINT interfaces which will get marked
18325 * IPIF_UNNUMBERED later in
18326 * ip_addr_availability_check().
18328 * The nce_ipif_cnt field tracks the number of
18329 * ipifs that have nce_addr as their local address.
18331 ipif
->ipif_addr_ready
= 1;
18332 ipif
->ipif_added_nce
= 1;
18333 nce
->nce_ipif_cnt
++;
18337 ASSERT(nce
== NULL
);
18340 if (arp_no_defense
) {
18341 if ((ipif
->ipif_flags
& IPIF_UP
) &&
18342 !ipif
->ipif_addr_ready
)
18343 ipif_up_notify(ipif
);
18344 ipif
->ipif_addr_ready
= 1;
18347 /* zero address. nothing to publish */
18348 ipif
->ipif_addr_ready
= 1;
18353 if (added_ipif
&& err
!= 0)
18354 ipmp_illgrp_del_ipif(ill
->ill_grp
, ipif
);
18359 ipif_arp_up(ipif_t
*ipif
, enum ip_resolver_action res_act
, boolean_t was_dup
)
18362 ill_t
*ill
= ipif
->ipif_ill
;
18363 boolean_t first_interface
, wait_for_dlpi
= B_FALSE
;
18365 DTRACE_PROBE3(ipif__downup
, char *, "ipif_arp_up",
18366 ill_t
*, ill
, ipif_t
*, ipif
);
18369 * need to bring up ARP or setup mcast mapping only
18370 * when the first interface is coming UP.
18372 first_interface
= (ill
->ill_ipif_up_count
== 0 &&
18373 ill
->ill_ipif_dup_count
== 0 && !was_dup
);
18375 if (res_act
== Res_act_initial
&& first_interface
) {
18377 * Send ATTACH + BIND
18379 err
= arp_ll_up(ill
);
18380 if (err
!= EINPROGRESS
&& err
!= 0)
18384 * Add NCE for local address. Start DAD.
18385 * we'll wait to hear that DAD has finished
18386 * before using the interface.
18388 if (err
== EINPROGRESS
)
18389 wait_for_dlpi
= B_TRUE
;
18392 if (!wait_for_dlpi
)
18393 (void) ipif_arp_up_done_tail(ipif
, res_act
);
18395 return (!wait_for_dlpi
? 0 : EINPROGRESS
);
18399 * Finish processing of "arp_up" after all the DLPI message
18400 * exchanges have completed between arp and the driver.
18403 arp_bringup_done(ill_t
*ill
, int err
)
18407 conn_t
*connp
= NULL
;
18411 ip1dbg(("arp_bringup_done(%s)\n", ill
->ill_name
));
18413 ASSERT(IAM_WRITER_ILL(ill
));
18415 ipsq
= ill
->ill_phyint
->phyint_ipsq
;
18416 ipif
= ipsq
->ipsq_xop
->ipx_pending_ipif
;
18417 mp1
= ipsq_pending_mp_get(ipsq
, &connp
);
18418 ASSERT(!((mp1
!= NULL
) ^ (ipif
!= NULL
)));
18419 if (mp1
== NULL
) /* bringup was aborted by the user */
18423 * If an IOCTL is waiting on this (ipsq_current_ioctl != 0), then we
18424 * must have an associated conn_t. Otherwise, we're bringing this
18425 * interface back up as part of handling an asynchronous event (e.g.,
18426 * physical address change).
18428 if (ipsq
->ipsq_xop
->ipx_current_ioctl
!= 0) {
18429 ASSERT(connp
!= NULL
);
18430 q
= CONNP_TO_WQ(connp
);
18432 ASSERT(connp
== NULL
);
18436 if (ipif
->ipif_isv6
) {
18437 if ((err
= ipif_up_done_v6(ipif
)) != 0)
18438 ip0dbg(("arp_bringup_done: init failed\n"));
18440 err
= ipif_arp_up_done_tail(ipif
, Res_act_initial
);
18442 (err
= ipif_up_done(ipif
)) != 0) {
18443 ip0dbg(("arp_bringup_done: "
18444 "init failed err %x\n", err
));
18445 (void) ipif_arp_down(ipif
);
18450 ip0dbg(("arp_bringup_done: DL_BIND_REQ failed\n"));
18453 if ((err
== 0) && (ill
->ill_up_ipifs
)) {
18454 err
= ill_up_ipifs(ill
, q
, mp1
);
18455 if (err
== EINPROGRESS
)
18460 * If we have a moved ipif to bring up, and everything has succeeded
18461 * to this point, bring it up on the IPMP ill. Otherwise, leave it
18462 * down -- the admin can try to bring it up by hand if need be.
18464 if (ill
->ill_move_ipif
!= NULL
) {
18465 ipif
= ill
->ill_move_ipif
;
18466 ip1dbg(("bringing up ipif %p on ill %s\n", (void *)ipif
,
18467 ipif
->ipif_ill
->ill_name
));
18468 ill
->ill_move_ipif
= NULL
;
18470 err
= ipif_up(ipif
, q
, mp1
);
18471 if (err
== EINPROGRESS
)
18477 * The operation must complete without EINPROGRESS since
18478 * ipsq_pending_mp_get() has removed the mblk from ipsq_pending_mp.
18479 * Otherwise, the operation will be stuck forever in the ipsq.
18481 ASSERT(err
!= EINPROGRESS
);
18482 if (ipsq
->ipsq_xop
->ipx_current_ioctl
!= 0) {
18483 DTRACE_PROBE4(ipif__ioctl
, char *, "arp_bringup_done finish",
18484 int, ipsq
->ipsq_xop
->ipx_current_ioctl
,
18485 ill_t
*, ill
, ipif_t
*, ipif
);
18486 ip_ioctl_finish(q
, mp1
, err
, NO_COPYOUT
, ipsq
);
18488 ipsq_current_finish(ipsq
);
18493 * Finish processing of arp replumb after all the DLPI message
18494 * exchanges have completed between arp and the driver.
18497 arp_replumb_done(ill_t
*ill
, int err
)
18501 conn_t
*connp
= NULL
;
18505 ASSERT(IAM_WRITER_ILL(ill
));
18507 ipsq
= ill
->ill_phyint
->phyint_ipsq
;
18508 ipif
= ipsq
->ipsq_xop
->ipx_pending_ipif
;
18509 mp1
= ipsq_pending_mp_get(ipsq
, &connp
);
18510 ASSERT(!((mp1
!= NULL
) ^ (ipif
!= NULL
)));
18512 ip0dbg(("arp_replumb_done: bringup aborted ioctl %x\n",
18513 ipsq
->ipsq_xop
->ipx_current_ioctl
));
18514 /* bringup was aborted by the user */
18518 * If an IOCTL is waiting on this (ipsq_current_ioctl != 0), then we
18519 * must have an associated conn_t. Otherwise, we're bringing this
18520 * interface back up as part of handling an asynchronous event (e.g.,
18521 * physical address change).
18523 if (ipsq
->ipsq_xop
->ipx_current_ioctl
!= 0) {
18524 ASSERT(connp
!= NULL
);
18525 q
= CONNP_TO_WQ(connp
);
18527 ASSERT(connp
== NULL
);
18530 if ((err
== 0) && (ill
->ill_up_ipifs
)) {
18531 err
= ill_up_ipifs(ill
, q
, mp1
);
18532 if (err
== EINPROGRESS
)
18536 * The operation must complete without EINPROGRESS since
18537 * ipsq_pending_mp_get() has removed the mblk from ipsq_pending_mp.
18538 * Otherwise, the operation will be stuck forever in the ipsq.
18540 ASSERT(err
!= EINPROGRESS
);
18541 if (ipsq
->ipsq_xop
->ipx_current_ioctl
!= 0) {
18542 DTRACE_PROBE4(ipif__ioctl
, char *,
18543 "arp_replumb_done finish",
18544 int, ipsq
->ipsq_xop
->ipx_current_ioctl
,
18545 ill_t
*, ill
, ipif_t
*, ipif
);
18546 ip_ioctl_finish(q
, mp1
, err
, NO_COPYOUT
, ipsq
);
18548 ipsq_current_finish(ipsq
);
18553 ipif_up_notify(ipif_t
*ipif
)
18555 ip_rts_ifmsg(ipif
, RTSQ_DEFAULT
);
18556 ip_rts_newaddrmsg(RTM_ADD
, 0, ipif
, RTSQ_DEFAULT
);
18557 sctp_update_ipif(ipif
, SCTP_IPIF_UP
);
18558 ill_nic_event_dispatch(ipif
->ipif_ill
, MAP_IPIF_ID(ipif
->ipif_id
),
18559 NE_LIF_UP
, NULL
, 0);
18563 * ILB ioctl uses cv_wait (such as deleting a rule or adding a server) and
18564 * this assumes the context is cv_wait'able. Hence it shouldnt' be used on
18565 * TPI end points with STREAMS modules pushed above. This is assured by not
18566 * having the IPI_MODOK flag for the ioctl. And IP ensures the ILB ioctl
18567 * never ends up on an ipsq, otherwise we may end up processing the ioctl
18568 * while unwinding from the ispq and that could be a thread from the bottom.
18572 ip_sioctl_ilb_cmd(ipif_t
*ipif
, sin_t
*sin
, queue_t
*q
, mblk_t
*mp
,
18573 ip_ioctl_cmd_t
*ipip
, void *arg
)
18575 mblk_t
*cmd_mp
= mp
->b_cont
->b_cont
;
18576 ilb_cmd_t command
= *((ilb_cmd_t
*)cmd_mp
->b_rptr
);
18584 ipst
= CONNQ_TO_IPST(q
);
18585 ilbs
= ipst
->ips_netstack
->netstack_ilb
;
18586 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
18589 case ILB_CREATE_RULE
: {
18590 ilb_rule_cmd_t
*cmd
= (ilb_rule_cmd_t
*)cmd_mp
->b_rptr
;
18592 if (MBLKL(cmd_mp
) != sizeof (ilb_rule_cmd_t
)) {
18597 ret
= ilb_rule_add(ilbs
, zoneid
, cmd
);
18600 case ILB_DESTROY_RULE
:
18601 case ILB_ENABLE_RULE
:
18602 case ILB_DISABLE_RULE
: {
18603 ilb_name_cmd_t
*cmd
= (ilb_name_cmd_t
*)cmd_mp
->b_rptr
;
18605 if (MBLKL(cmd_mp
) != sizeof (ilb_name_cmd_t
)) {
18610 if (cmd
->flags
& ILB_RULE_ALLRULES
) {
18611 if (command
== ILB_DESTROY_RULE
) {
18612 ilb_rule_del_all(ilbs
, zoneid
);
18614 } else if (command
== ILB_ENABLE_RULE
) {
18615 ilb_rule_enable_all(ilbs
, zoneid
);
18617 } else if (command
== ILB_DISABLE_RULE
) {
18618 ilb_rule_disable_all(ilbs
, zoneid
);
18622 if (command
== ILB_DESTROY_RULE
) {
18623 ret
= ilb_rule_del(ilbs
, zoneid
, cmd
->name
);
18624 } else if (command
== ILB_ENABLE_RULE
) {
18625 ret
= ilb_rule_enable(ilbs
, zoneid
, cmd
->name
,
18627 } else if (command
== ILB_DISABLE_RULE
) {
18628 ret
= ilb_rule_disable(ilbs
, zoneid
, cmd
->name
,
18634 case ILB_NUM_RULES
: {
18635 ilb_num_rules_cmd_t
*cmd
;
18637 if (MBLKL(cmd_mp
) != sizeof (ilb_num_rules_cmd_t
)) {
18641 cmd
= (ilb_num_rules_cmd_t
*)cmd_mp
->b_rptr
;
18642 ilb_get_num_rules(ilbs
, zoneid
, &(cmd
->num
));
18645 case ILB_RULE_NAMES
: {
18646 ilb_rule_names_cmd_t
*cmd
;
18648 cmd
= (ilb_rule_names_cmd_t
*)cmd_mp
->b_rptr
;
18649 if (MBLKL(cmd_mp
) < sizeof (ilb_rule_names_cmd_t
) ||
18650 cmd
->num_names
== 0) {
18654 size
= cmd
->num_names
* ILB_RULE_NAMESZ
;
18655 if (cmd_mp
->b_rptr
+ offsetof(ilb_rule_names_cmd_t
, buf
) +
18656 size
!= cmd_mp
->b_wptr
) {
18660 ilb_get_rulenames(ilbs
, zoneid
, &cmd
->num_names
, cmd
->buf
);
18663 case ILB_NUM_SERVERS
: {
18664 ilb_num_servers_cmd_t
*cmd
;
18666 if (MBLKL(cmd_mp
) != sizeof (ilb_num_servers_cmd_t
)) {
18670 cmd
= (ilb_num_servers_cmd_t
*)cmd_mp
->b_rptr
;
18671 ret
= ilb_get_num_servers(ilbs
, zoneid
, cmd
->name
,
18675 case ILB_LIST_RULE
: {
18676 ilb_rule_cmd_t
*cmd
= (ilb_rule_cmd_t
*)cmd_mp
->b_rptr
;
18678 if (MBLKL(cmd_mp
) != sizeof (ilb_rule_cmd_t
)) {
18682 ret
= ilb_rule_list(ilbs
, zoneid
, cmd
);
18685 case ILB_LIST_SERVERS
: {
18686 ilb_servers_info_cmd_t
*cmd
;
18688 cmd
= (ilb_servers_info_cmd_t
*)cmd_mp
->b_rptr
;
18689 if (MBLKL(cmd_mp
) < sizeof (ilb_servers_info_cmd_t
) ||
18690 cmd
->num_servers
== 0) {
18694 size
= cmd
->num_servers
* sizeof (ilb_server_info_t
);
18695 if (cmd_mp
->b_rptr
+ offsetof(ilb_servers_info_cmd_t
, servers
) +
18696 size
!= cmd_mp
->b_wptr
) {
18701 ret
= ilb_get_servers(ilbs
, zoneid
, cmd
->name
, cmd
->servers
,
18702 &cmd
->num_servers
);
18705 case ILB_ADD_SERVERS
: {
18706 ilb_servers_info_cmd_t
*cmd
;
18709 cmd
= (ilb_servers_info_cmd_t
*)cmd_mp
->b_rptr
;
18710 if (MBLKL(cmd_mp
) < sizeof (ilb_servers_info_cmd_t
)) {
18714 size
= cmd
->num_servers
* sizeof (ilb_server_info_t
);
18715 if (cmd_mp
->b_rptr
+ offsetof(ilb_servers_info_cmd_t
, servers
) +
18716 size
!= cmd_mp
->b_wptr
) {
18720 rule
= ilb_find_rule(ilbs
, zoneid
, cmd
->name
, &ret
);
18721 if (rule
== NULL
) {
18725 for (i
= 0; i
< cmd
->num_servers
; i
++) {
18726 ilb_server_info_t
*s
;
18728 s
= &cmd
->servers
[i
];
18729 s
->err
= ilb_server_add(ilbs
, rule
, s
);
18731 ILB_RULE_REFRELE(rule
);
18734 case ILB_DEL_SERVERS
:
18735 case ILB_ENABLE_SERVERS
:
18736 case ILB_DISABLE_SERVERS
: {
18737 ilb_servers_cmd_t
*cmd
;
18741 cmd
= (ilb_servers_cmd_t
*)cmd_mp
->b_rptr
;
18742 if (MBLKL(cmd_mp
) < sizeof (ilb_servers_cmd_t
)) {
18746 size
= cmd
->num_servers
* sizeof (ilb_server_arg_t
);
18747 if (cmd_mp
->b_rptr
+ offsetof(ilb_servers_cmd_t
, servers
) +
18748 size
!= cmd_mp
->b_wptr
) {
18753 if (command
== ILB_DEL_SERVERS
)
18754 f
= ilb_server_del
;
18755 else if (command
== ILB_ENABLE_SERVERS
)
18756 f
= ilb_server_enable
;
18757 else if (command
== ILB_DISABLE_SERVERS
)
18758 f
= ilb_server_disable
;
18760 rule
= ilb_find_rule(ilbs
, zoneid
, cmd
->name
, &ret
);
18761 if (rule
== NULL
) {
18766 for (i
= 0; i
< cmd
->num_servers
; i
++) {
18767 ilb_server_arg_t
*s
;
18769 s
= &cmd
->servers
[i
];
18770 s
->err
= f(ilbs
, zoneid
, NULL
, rule
, &s
->addr
);
18772 ILB_RULE_REFRELE(rule
);
18775 case ILB_LIST_NAT_TABLE
: {
18776 ilb_list_nat_cmd_t
*cmd
;
18778 cmd
= (ilb_list_nat_cmd_t
*)cmd_mp
->b_rptr
;
18779 if (MBLKL(cmd_mp
) < sizeof (ilb_list_nat_cmd_t
)) {
18783 size
= cmd
->num_nat
* sizeof (ilb_nat_entry_t
);
18784 if (cmd_mp
->b_rptr
+ offsetof(ilb_list_nat_cmd_t
, entries
) +
18785 size
!= cmd_mp
->b_wptr
) {
18790 ret
= ilb_list_nat(ilbs
, zoneid
, cmd
->entries
, &cmd
->num_nat
,
18794 case ILB_LIST_STICKY_TABLE
: {
18795 ilb_list_sticky_cmd_t
*cmd
;
18797 cmd
= (ilb_list_sticky_cmd_t
*)cmd_mp
->b_rptr
;
18798 if (MBLKL(cmd_mp
) < sizeof (ilb_list_sticky_cmd_t
)) {
18802 size
= cmd
->num_sticky
* sizeof (ilb_sticky_entry_t
);
18803 if (cmd_mp
->b_rptr
+ offsetof(ilb_list_sticky_cmd_t
, entries
) +
18804 size
!= cmd_mp
->b_wptr
) {
18809 ret
= ilb_list_sticky(ilbs
, zoneid
, cmd
->entries
,
18810 &cmd
->num_sticky
, &cmd
->flags
);
18821 /* Remove all cache entries for this logical interface */
18823 ipif_nce_down(ipif_t
*ipif
)
18825 ill_t
*ill
= ipif
->ipif_ill
;
18828 DTRACE_PROBE3(ipif__downup
, char *, "ipif_nce_down",
18829 ill_t
*, ill
, ipif_t
*, ipif
);
18830 if (ipif
->ipif_added_nce
) {
18831 if (ipif
->ipif_isv6
)
18832 nce
= nce_lookup_v6(ill
, &ipif
->ipif_v6lcl_addr
);
18834 nce
= nce_lookup_v4(ill
, &ipif
->ipif_lcl_addr
);
18836 if (--nce
->nce_ipif_cnt
== 0)
18837 ncec_delete(nce
->nce_common
);
18838 ipif
->ipif_added_nce
= 0;
18842 * nce may already be NULL because it was already
18843 * flushed, e.g., due to a call to nce_flush
18845 ipif
->ipif_added_nce
= 0;
18849 * Make IPMP aware of the deleted data address.
18852 ipmp_illgrp_del_ipif(ill
->ill_grp
, ipif
);
18855 * Remove all other nces dependent on this ill when the last ipif
18858 if (ill
->ill_ipif_up_count
== 0) {
18859 ncec_walk(ill
, (pfi_t
)ncec_delete_per_ill
,
18860 (uchar_t
*)ill
, ill
->ill_ipst
);
18861 if (IS_UNDER_IPMP(ill
))
18862 nce_flush(ill
, B_TRUE
);
18867 * find the first interface that uses usill for its source address.
18870 ill_lookup_usesrc(ill_t
*usill
)
18872 ip_stack_t
*ipst
= usill
->ill_ipst
;
18875 ASSERT(usill
!= NULL
);
18877 /* ill_g_usesrc_lock protects ill_usesrc_grp_next */
18878 rw_enter(&ipst
->ips_ill_g_usesrc_lock
, RW_WRITER
);
18879 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
18880 for (ill
= usill
->ill_usesrc_grp_next
; ill
!= NULL
&& ill
!= usill
;
18881 ill
= ill
->ill_usesrc_grp_next
) {
18882 if (!IS_UNDER_IPMP(ill
) && (ill
->ill_flags
& ILLF_MULTICAST
) &&
18883 !ILL_IS_CONDEMNED(ill
)) {
18888 rw_exit(&ipst
->ips_ill_g_lock
);
18889 rw_exit(&ipst
->ips_ill_g_usesrc_lock
);
18894 * This comment applies to both ip_sioctl_get_ifhwaddr and
18895 * ip_sioctl_get_lifhwaddr as the basic function of these two functions
18898 * The goal here is to find an IP interface that corresponds to the name
18899 * provided by the caller in the ifreq/lifreq structure held in the mblk_t
18900 * chain and to fill out a sockaddr/sockaddr_storage structure with the
18903 * The SIOCGIFHWADDR/SIOCGLIFHWADDR ioctl may return an error for a number
18904 * of different reasons:
18905 * ENXIO - the device name is not known to IP.
18906 * EADDRNOTAVAIL - the device has no hardware address. This is indicated
18907 * by ill_phys_addr not pointing to an actual address.
18908 * EPFNOSUPPORT - this will indicate that a request is being made for a
18909 * mac address that will not fit in the data structure supplier (struct
18915 ip_sioctl_get_ifhwaddr(ipif_t
*ipif
, sin_t
*dummy_sin
, queue_t
*q
, mblk_t
*mp
,
18916 ip_ioctl_cmd_t
*ipip
, void *if_req
)
18918 struct sockaddr
*sock
;
18923 ASSERT(ipif
!= NULL
);
18924 ill
= ipif
->ipif_ill
;
18926 if (ill
->ill_phys_addr
== NULL
) {
18927 return (EADDRNOTAVAIL
);
18929 if (ill
->ill_phys_addr_length
> sizeof (sock
->sa_data
)) {
18930 return (EPFNOSUPPORT
);
18933 ip1dbg(("ip_sioctl_get_hwaddr(%s)\n", ill
->ill_name
));
18935 /* Existence of mp1 has been checked in ip_wput_nondata */
18936 mp1
= mp
->b_cont
->b_cont
;
18937 ifr
= (struct ifreq
*)mp1
->b_rptr
;
18939 sock
= &ifr
->ifr_addr
;
18941 * The "family" field in the returned structure is set to a value
18942 * that represents the type of device to which the address belongs.
18943 * The value returned may differ to that on Linux but it will still
18944 * represent the correct symbol on Solaris.
18946 sock
->sa_family
= arp_hw_type(ill
->ill_mactype
);
18947 bcopy(ill
->ill_phys_addr
, &sock
->sa_data
, ill
->ill_phys_addr_length
);
18953 * The expection of applications using SIOCGIFHWADDR is that data will
18954 * be returned in the sa_data field of the sockaddr structure. With
18955 * SIOCGLIFHWADDR, we're breaking new ground as there is no Linux
18956 * equivalent. In light of this, struct sockaddr_dl is used as it
18957 * offers more space for address storage in sll_data.
18961 ip_sioctl_get_lifhwaddr(ipif_t
*ipif
, sin_t
*dummy_sin
, queue_t
*q
, mblk_t
*mp
,
18962 ip_ioctl_cmd_t
*ipip
, void *if_req
)
18964 struct sockaddr_dl
*sock
;
18965 struct lifreq
*lifr
;
18969 ASSERT(ipif
!= NULL
);
18970 ill
= ipif
->ipif_ill
;
18972 if (ill
->ill_phys_addr
== NULL
) {
18973 return (EADDRNOTAVAIL
);
18975 if (ill
->ill_phys_addr_length
> sizeof (sock
->sdl_data
)) {
18976 return (EPFNOSUPPORT
);
18979 ip1dbg(("ip_sioctl_get_lifhwaddr(%s)\n", ill
->ill_name
));
18981 /* Existence of mp1 has been checked in ip_wput_nondata */
18982 mp1
= mp
->b_cont
->b_cont
;
18983 lifr
= (struct lifreq
*)mp1
->b_rptr
;
18986 * sockaddr_ll is used here because it is also the structure used in
18987 * responding to the same ioctl in sockpfp. The only other choice is
18988 * sockaddr_dl which contains fields that are not required here
18989 * because its purpose is different.
18991 lifr
->lifr_type
= ill
->ill_type
;
18992 sock
= (struct sockaddr_dl
*)&lifr
->lifr_addr
;
18993 sock
->sdl_family
= AF_LINK
;
18994 sock
->sdl_index
= ill
->ill_phyint
->phyint_ifindex
;
18995 sock
->sdl_type
= ill
->ill_mactype
;
18996 sock
->sdl_nlen
= 0;
18997 sock
->sdl_slen
= 0;
18998 sock
->sdl_alen
= ill
->ill_phys_addr_length
;
18999 bcopy(ill
->ill_phys_addr
, sock
->sdl_data
, ill
->ill_phys_addr_length
);