ip_if.c revision 3e87ae1286f5b1197022556087b75e516d68b22b
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1990 Mentat Inc. */
/*
* This file contains the interface control functions for IP.
*/
#include <sys/sysmacros.h>
#include <sys/isa_defs.h>
#include <net/if_types.h>
#include <netinet/igmp_var.h>
#include <sys/ethernet.h>
#include <inet/ip_multi.h>
#include <inet/ip_ftable.h>
#include <inet/ip_netinfo.h>
#include <inet/ip_listutils.h>
#include <inet/ipclassifier.h>
#include <sys/mac_client.h>
#include <sys/systeminfo.h>
#include <sys/bootconf.h>
/* The character which tells where the ill_name ends */
#define IPIF_SEPARATOR_CHAR ':'
/* IP ioctl function table entry */
typedef struct ipft_s {
int ipft_cmd;
int ipft_min_size;
int ipft_flags;
} ipft_t;
static void ipsq_delete(ipsq_t *);
queue_t *q);
ip_stack_t *);
static void ill_delete_interface_type(ill_if_t *);
static void ill_glist_delete(ill_t *);
static ip_v4mapinfo_func_t ip_ib_v4_mapping;
static ip_v6mapinfo_func_t ip_ib_v6_mapping;
static ip_v4mapinfo_func_t ip_mbcast_mapping;
static void phyint_free(phyint_t *);
static void ill_capability_dld_enable(ill_t *);
static void ill_capability_ack_thr(void *);
static void ill_capability_lso_enable(ill_t *);
static void ill_disband_usesrc_group(ill_t *);
#ifdef DEBUG
static void ill_trace_cleanup(const ill_t *);
static void ipif_trace_cleanup(const ipif_t *);
#endif
/*
* if we go over the memory footprint limit more than once in this msec
* interval, we'll start pruning aggressively.
*/
int ip_min_frag_prune_time = 0;
static ipft_t ip_ioctl_ftbl[] = {
{ 0 }
};
/* Simple ICMP IP Header Template */
IP_SIMPLE_HDR_VERSION, 0, 0, 0, 0, 0, IPPROTO_ICMP
};
};
char ipif_loopback_name[] = "lo0";
static char *ipv4_forward_suffix = ":ip_forwarding";
static char *ipv6_forward_suffix = ":ip6_forwarding";
/* These are used by all IP network modules. */
/* When set search for unused ipif_seqid */
/*
* ppa arena is created after these many
* interfaces have been plumbed.
*/
/*
* Allocate per-interface mibs.
* Returns true if ok. False otherwise.
* ipsq may not yet be allocated (loopback case ).
*/
static boolean_t
{
/* Already allocated? */
return (B_TRUE);
}
return (B_FALSE);
}
/* Setup static information */
sizeof (mib2_ipIfStatsEntry_t));
sizeof (mib2_ipv6AddrEntry_t));
sizeof (mib2_ipv6RouteEntry_t));
sizeof (mib2_ipv6NetToMediaEntry_t));
sizeof (ipv6_member_t));
sizeof (ipv6_grpsrc_t));
} else {
sizeof (mib2_ipAddrEntry_t));
sizeof (mib2_ipRouteEntry_t));
sizeof (mib2_ipNetToMediaEntry_t));
sizeof (ip_member_t));
sizeof (ip_grpsrc_t));
/*
* For a v4 ill, we are done at this point, because per ill
* icmp mibs are only used for v6.
*/
return (B_TRUE);
}
return (B_FALSE);
}
/* static icmp info */
sizeof (mib2_ipv6IfIcmpEntry_t);
/*
* The ipIfStatsIfindex and ipv6IfIcmpIndex will be assigned later
* after the phyint merge occurs in ipif_set_values -> ill_glist_insert
* -> ill_phyint_reinit
*/
return (B_TRUE);
}
/*
* Completely vaporize a lower level tap and all associated interfaces.
* ill_delete is called only out of ip_close when the device control
* stream is being closed.
*/
void
{
/*
* ill_delete may be forcibly entering the ipsq. The previous
* ioctl may not have completed and may need to be aborted.
* ipsq_flush takes care of it. If we don't need to enter the
* the ipsq forcibly, the 2nd invocation of ipsq_flush in
* ill_delete_tail is sufficient.
*/
/*
* Nuke all interfaces. ipif_free will take down the interface,
* remove it from the list, and free the data structure.
* Walk down the ipif list and remove the logical interfaces
* first before removing the main ipif. We can't unplumb
* zeroth interface first in the case of IPv6 as update_conn_ill
* -> ip_ll_multireq de-references ill_ipif for checking
* POINTOPOINT.
*
* If ill_ipif was not properly initialized (i.e low on memory),
* then no interfaces to clean up. In this case just clean up the
* ill.
*/
/*
* clean out all the nce_t entries that depend on this
* ill for the ill_phys_addr.
*/
/* Clean up msgs on pending upcalls for mrouted */
/*
* Remove multicast references added as a result of calls to
* ip_join_allmulti().
*/
/*
* If the ill being deleted is under IPMP, boot it out of the illgrp.
*/
if (IS_UNDER_IPMP(ill))
/*
* ill_down will arrange to blow off any IRE's dependent on this
* ILL, and shut down fragmentation reassembly.
*/
/* Let SCTP know, so that it can remove this from its list. */
/*
* Walk all CONNs that can have a reference on an ire or nce for this
* ill (we actually walk all that now have stale references).
*/
/* With IPv6 we have dce_ifindex. Cleanup for neatness */
/*
* If an address on this ILL is being used as a source address then
* clear out the pointers in other ILLs that point to this ILL.
*/
} else { /* consumer of the usesrc ILL */
}
}
}
static void
{
}
}
/*
* ill_delete_tail is called from ip_modclose after all references
* to the closing ill are gone. The wait is done in ip_modclose
*/
void
{
(void) ipif_down_tail(ipif);
}
/*
* If polling capability is enabled (which signifies direct
* upcall into IP and driver has ill saved as a handle),
* we need to make sure that unbind has completed before we
* let the ill disappear and driver no longer has any reference
* to this ill.
*/
/*
* We do an ipsq_flush once again now. New messages could have
* landed up from below (M_ERROR or M_HANGUP). Similarly ioctls
* could also have landed up if an ioctl thread had looked up
* the ill before we set the ILL_CONDEMNED flag, but not yet
* enqueued the ioctl when we did the ipsq_flush last time.
*/
/*
* Free capabilities.
*/
}
sizeof (ill_zerocopy_capab_t));
}
}
}
/*
* We have removed all references to ilm from conn and the ones joined
* within the kernel.
*
* We don't walk conns, mrts and ires because
*
* 1) update_conn_ill and reset_mrt_ill cleans up conns and mrts.
* 2) ill_down ->ill_downi walks all the ires and cleans up
* ill references.
*/
/*
* If this ill is an IPMP meta-interface, blow away the illgrp. This
* is safe to do because the illgrp has already been unlinked from the
* group by I_PUNLINK, and thus SIOCSLIFGROUPNAME cannot find it.
*/
}
/*
* Take us out of the list of ILLs. ill_glist_delete -> phyint_free
* could free the phyint. No more reference to the phyint after this
* point.
*/
(void) ill_glist_delete(ill);
}
}
/* Free all retained control messages. */
do {
while (mpp[0]) {
}
}
#ifdef DEBUG
#endif
/* The default multicast interface might have changed */
/* Drop refcnt here */
}
static void
{
/*
* MIB statistics must not be lost, so when an interface
* goes away the counter values will be added to the global
* MIBs.
*/
ill->ill_ip_mib);
} else {
ill->ill_ip_mib);
}
}
ill->ill_icmp6_mib);
}
}
/*
* Concatenate together a physical address and a sap.
*
* Sap_lengths are interpreted as follows:
* sap_length == 0 ==> no sap
* sap_length > 0 ==> sap is at the head of the dlpi address
* sap_length < 0 ==> sap is at the tail of the dlpi address
*/
static void
{
if (sap_length == 0) {
else
} else if (sap_length < 0) {
else
} else {
else
}
}
/*
* Generate a dl_unitdata_req mblk for the device and address given.
* addr_length is the length of the physical portion of the address.
* If addr is NULL include an all zero address of the specified length.
* TRUE? In any case, addr_length is taken to be the entire length of the
* dlpi address, including the absolute value of sap_length.
*/
mblk_t *
{
return (NULL);
/* HACK: accomodate incompatible DLPI drivers */
if (addr_length == 8)
addr_length = 6;
return (mp);
}
/*
* Add the pending mp to the list. There can be only 1 pending mp
* in the list. Any exclusive ioctl that needs to wait for a response
* from another module or driver needs to use this function to set
* the ipx_pending_mp to the ioctl mblk and wait for the response from
*/
int waitfor)
{
/*
* The caller may be using a different ipif than the one passed into
* ipsq_current_start() (e.g., suppose an ioctl that came in on the V4
* ill needs to wait for the V6 ill to quiesce). So we can't ASSERT
* that `ipx_current_ipif == ipif'.
*/
/*
* driver.
*/
/*
* Return error if the conn has started closing. The conn
* could have finished cleaning up the pending mp list,
* If so we should not add another mp to the list negating
* the cleanup.
*/
return (B_FALSE);
}
/*
* Note down the queue in b_queue. This will be returned by
* ipsq_pending_mp_get. Caller will then use these values to restart
* the processing
*/
return (B_TRUE);
}
/*
* Retrieve the ipx_pending_mp and return it. There can be only 1 mp
* queued in the list.
*/
mblk_t *
{
return (NULL);
}
/* There can be only 1 such excl message */
ipx->ipx_waitfor = 0;
/*
* This mp did a refhold on the conn, at the start of the ioctl.
* So we can safely return a pointer to the conn to the caller.
*/
} else {
}
return (curr);
}
/*
* Cleanup the ioctl mp queued in ipx_pending_mp
* - Called in the ill_delete path
* - Called in the M_ERROR or M_HANGUP path on the ill.
* - Called in the conn close path.
*
* Returns success on finding the pending mblk associated with the ioctl or
* exclusive operation in progress, failure otherwise.
*/
{
queue_t *q;
int cmd;
/*
* Nothing to clean since the conn that is closing
* does not have a matching pending mblk in
* ipx_pending_mp.
*/
return (B_FALSE);
}
} else {
/*
* A non-zero ill_error signifies we are called in the
* M_ERROR or M_HANGUP path and we need to unconditionally
* abort any current ioctl and do the corresponding cleanup.
* A zero ill_error means we are in the ill_delete path and
* we do the cleanup only if there is a pending mp.
*/
return (B_FALSE);
}
}
/* Now remove from the ipx_pending_mp */
ipx->ipx_waitfor = 0;
ipx->ipx_current_ioctl = 0;
return (B_FALSE);
char *, "ipsq_pending_mp_cleanup",
} else {
}
} else {
}
return (B_TRUE);
}
/*
* Called in the conn close path and ill delete path
*/
static void
{
else
/*
* In the case of lo0 being unplumbed, ill_wq will be NULL. Guard
* against this here.
*/
/*
* Cleanup the ioctl mp's queued in ipsq_xopq_pending_mp if any.
* In the case of ioctl from a conn, there can be only 1 mp
* queued on the ipsq. If an ill is being unplumbed flush all
* the messages.
*/
/* Unlink the mblk from the pending mp list */
} else {
}
/*
* Create a temporary list and release the ipsq lock
* New elements are added to the head of the tmp_list
*/
} else {
}
}
char *, "ipsq_xopq_mp_cleanup",
} else {
/*
* this can't be just inet_freemsg. we have to
* restart it otherwise the thread will be stuck.
*/
}
}
}
/*
* This conn has started closing. Cleanup any pending ioctl from this conn.
* STREAMS ensures that there can be at most 1 active ioctl on a stream.
*/
void
{
/*
* Check for a queued ioctl. If the ioctl has not yet started, the mp
* is pending in the list headed by ipsq_xopq_head. If the ioctl has
* started the mp could be present in ipx_pending_mp. Note that if
* conn_oper_pending_ill is NULL, the ioctl may still be in flight and
* not yet queued anywhere. In this case, the conn close code will wait
* until the conn_ref is dropped. If the stream was a tcp stream, then
* tcp_close will wait first until all ioctls have completed for this
* conn.
*/
return;
}
/*
* is changing. But we need to make sure that the ill will
* not vanish. So we just bump up the ill_waiter count.
*/
if (refheld) {
/*
* Check whether this ioctl has started and is
* pending. If it is not found there then check
* whether this ioctl has not even started and is in
* the ipsq_xopq list.
*/
return;
}
}
/*
* The ill is also closing and we could not bump up the
* ill_waiter_count or we could not enter the ipsq. Leave
* the cleanup to ill_delete
*/
if (refheld)
}
/*
* ipcl_walk function for cleaning up conn_*_ill fields.
* Note that we leave ixa_multicast_ifindex, conn_incoming_ifindex, and
* conn_bound_if in place. We prefer dropping
* packets instead of sending them out the wrong interface, or accepting
* packets from the wrong ifindex.
*/
static void
{
}
}
static int
{
int err;
/*
* ipif_down_tail will call arp_ll_down on the last ipif
* and typically return EINPROGRESS when the DL_UNBIND is sent.
*/
return (err);
}
return (0);
}
/* ARGSUSED */
void
{
(void) ill_down_ipifs_tail(q->q_ptr);
}
/*
* ill_down_start is called when we want to down this ill and bring it up again
* It is called when we receive an M_ERROR / M_HANGUP. In this case we shut down
* all interfaces, but don't tear down any plumbing.
*/
{
/* no more nce addition allowed */
/*
* It is possible that some ioctl is already in progress while we
* received the M_ERROR / M_HANGUP in which case, we need to abort
* the ioctl. ill_down_start() is being processed as CUR_OP rather
* than as NEW_OP since the cause of the M_ERROR / M_HANGUP may prevent
* the in progress ioctl from ever completing.
*
* The thread that started the ioctl (if any) must have returned,
* since we are now executing as writer. After the 2 calls below,
* the state of the ipsq and the ill would reflect no trace of any
* pending operation. Subsequently if there is any response to the
* original ioctl from the driver, it would be discarded as an
* unsolicited message from the driver.
*/
/*
* Walk all CONNs that can have a reference on an ire or nce for this
* ill (we actually walk all that now have stale references).
*/
/* With IPv6 we have dce_ifindex. Cleanup for neatness */
/*
* Atomically test and add the pending mp if references are active.
*/
if (!ill_is_quiescent(ill)) {
/* call cannot fail since `conn_t *' argument is NULL */
return (B_FALSE);
}
return (B_TRUE);
}
static void
{
/*
* Blow off any IREs dependent on this ILL.
* The caller needs to handle conn_ixa_cleanup
*/
/* Remove any conn_*_ill depending on this ill */
/*
* Free state for additional IREs.
*/
ill->ill_saved_ire_cnt = 0;
}
/*
* ire_walk routine used to delete every IRE that depends on
* 'ill'. (Always called as writer, and may only be called from ire_walk.)
*
* Note: since the routes added by the kernel are deleted separately,
* this will only be 1) IRE_IF_CLONE and 2) manually added IRE_INTERFACE.
*
* We also remove references on ire_nce_cache entries that refer to the ill.
*/
void
{
else
/*
* The existing interface binding for ire must be
* deleted before trying to bind the route to another
* interface. However, since we are using the contents of the
* ire after ire_delete, the caller has to ensure that
* CONDEMNED (deleted) ire's are not removed from the list
* when ire_delete() returns. Currently ill_downi() is
* only called as part of ire_walk*() routines, so that
* the irb_refhold() done by ire_walk*() will ensure that
* ire_delete() does not lead to ire_inactive().
*/
if (ire->ire_unbound)
}
}
/* Remove IRE_IF_CLONE on this ill */
void
{
}
/* Consume an M_IOCACK of the fastpath probe. */
void
{
/*
* If this was the first attempt turn on the fastpath probing.
*/
/* Free the M_IOCACK mblk, hold on to the data */
return;
else
ip0dbg(("ill_fastpath_ack: no b_cont\n"));
}
/*
* Throw an M_IOCTL message downstream asking "do you know fastpath?"
* The data portion of the request is a dl_unitdata_req_t template for
* what we would send downstream in the absence of a fastpath confirmation.
*/
int
{
return (EINVAL);
switch (ill->ill_dlpi_fastpath_state) {
case IDS_FAILED:
/*
* Driver NAKed the first fastpath ioctl - assume it doesn't
* support it.
*/
return (ENOTSUP);
case IDS_UNKNOWN:
/* This is the first probe */
break;
default:
break;
}
return (EAGAIN);
return (EAGAIN);
}
return (0);
}
void
{
return;
/*
* We are starting a new cycle of capability negotiation.
* Free up the capab reset messages of any previous incarnation.
* We will do a fresh allocation when we get the response to our probe
*/
}
ip1dbg(("ill_capability_probe: starting capability negotiation\n"));
return;
}
void
{
return;
/*
* We turn off all capabilities except those pertaining to
* direct function call capabilities viz. ILL_CAPAB_DLD*
* which will be turned off by the corresponding reset functions.
*/
}
static void
{
int err;
if (ILL_HCKSUM_CAPABLE(ill)) {
size += sizeof (dl_capability_sub_t) +
sizeof (dl_capab_hcksum_t);
}
size += sizeof (dl_capability_sub_t) +
sizeof (dl_capab_zerocopy_t);
}
size += sizeof (dl_capability_sub_t) +
sizeof (dl_capab_dld_t);
}
/*
* Each handler fills in the corresponding dl_capability_sub_t
* inside the mblk,
*/
}
static void
{
/*
* Note: range checks here are not absolutely sufficient to
* make us robust against malformed messages sent by drivers;
* this is in keeping with the rest of IP's dlpi handling.
* (Remember, it's coming from something else in the kernel
* address space)
*/
"malformed sub-capability too long for mblk");
return;
}
"encapsulated capab type %d too long for mblk",
return;
}
ip1dbg(("ill_capability_id_ack: mid token for capab type %d "
"isn't as expected; pass-thru module(s) detected, "
return;
}
/* Process the encapsulated sub-capability */
}
static void
{
return;
/*
* The dl_capab_dld_t that follows the dl_capability_sub_t is not
* initialized below since it is not used by DLD.
*/
}
static void
{
/*
* If no ipif was brought up over this ill, this DL_CAPABILITY_REQ/ACK
* is only to get the VRRP capability.
*
* Note that we cannot check ill_ipif_up_count here since
* ill_ipif_up_count is only incremented when the resolver is setup.
* That is done asynchronously, and can race with this function.
*/
return;
}
case DL_CAPAB_HCKSUM:
break;
case DL_CAPAB_ZEROCOPY:
break;
case DL_CAPAB_DLD:
break;
case DL_CAPAB_VRRP:
break;
default:
ip1dbg(("ill_capability_dispatch: unknown capab type %d\n",
}
}
/*
* Process the vrrp capability received from a DLS Provider. isub must point
* to the sub-capability (DL_CAPAB_VRRP) of a DL_CAPABILITY_ACK message.
*/
static void
{
/*
* Note: range checks here are not absolutely sufficient to
* make us robust against malformed messages sent by drivers;
* this is in keeping with the rest of IP's dlpi handling.
* (Remember, it's coming from something else in the kernel
* address space)
*/
"malformed sub-capability too long for mblk");
return;
}
/*
* Compare the IP address family and set ILLF_VRRP for the right ill.
*/
}
}
/*
* Process a hardware checksum offload capability negotiation ack received
* from a DLS Provider.isub must point to the sub-capability (DL_CAPAB_HCKSUM)
* of a DL_CAPABILITY_ACK message.
*/
static void
{
/*
* Note: range checks here are not absolutely sufficient to
* make us robust against malformed messages sent by drivers;
* this is in keeping with the rest of IP's dlpi handling.
* (Remember, it's coming from something else in the kernel
* address space)
*/
"malformed sub-capability too long for mblk");
return;
}
/*
* There are two types of acks we process here:
* 1. acks in reply to a (first form) generic capability req
* (no ENABLE flag set)
* 2. acks in reply to a ENABLE capability req.
* (ENABLE flag set)
*/
"unsupported hardware checksum "
"sub-capability (version %d, expected %d)",
return;
}
ip1dbg(("ill_capability_hcksum_ack: mid token for hardware "
"checksum capability isn't as expected; pass-thru "
"module(s) detected, discarding capability\n"));
return;
}
#define CURR_HCKSUM_CAPAB \
/* do ENABLE processing */
if (*ill_hcksum == NULL) {
if (*ill_hcksum == NULL) {
"could not enable hcksum version %d "
"for %s (ENOMEM)\n", HCKSUM_CURRENT_VERSION,
return;
}
}
ip1dbg(("ill_capability_hcksum_ack: interface %s "
"has enabled hardware checksumming\n ",
/*
* Enabling hardware checksum offload
* Currently IP supports {TCP,UDP}/IPv4
* partial and full cksum offload and
* IPv4 header checksum offload.
* Allocate new mblk which will
* contain a new capability request
* to enable hardware checksum offload.
*/
size = sizeof (dl_capability_req_t) +
"could not enable hardware cksum for %s (ENOMEM)\n",
return;
}
/* initialize dl_capability_req_t */
sizeof (dl_capability_req_t);
sizeof (dl_capability_sub_t) +
/* initialize dl_capability_sub_t */
/* initialize dl_capab_hcksum_t */
/* Set ENABLE flag */
/*
* nmp points to a DL_CAPABILITY_REQ message to enable
* hardware checksum acceleration.
*/
} else {
ip1dbg(("ill_capability_hcksum_ack: interface %s has "
"advertised %x hardware checksum capability flags\n",
}
}
static void
{
if (!ILL_HCKSUM_CAPABLE(ill))
return;
hck_subcap->hcksum_txflags = 0;
}
static void
{
/*
* Note: range checks here are not absolutely sufficient to
* make us robust against malformed messages sent by drivers;
* this is in keeping with the rest of IP's dlpi handling.
* (Remember, it's coming from something else in the kernel
* address space)
*/
"malformed sub-capability too long for mblk");
return;
}
"unsupported ZEROCOPY sub-capability (version %d, "
return;
}
ip1dbg(("ill_capability_zerocopy_ack: mid token for zerocopy "
"capability isn't as expected; pass-thru module(s) "
"detected, discarding capability\n"));
return;
}
if (*ill_zerocopy_capab == NULL) {
kmem_zalloc(sizeof (ill_zerocopy_capab_t),
if (*ill_zerocopy_capab == NULL) {
"could not enable Zero-copy version %d "
"for %s (ENOMEM)\n", ZEROCOPY_VERSION_1,
return;
}
}
ip1dbg(("ill_capability_zerocopy_ack: interface %s "
} else {
size = sizeof (dl_capability_req_t) +
sizeof (dl_capability_sub_t) +
sizeof (dl_capab_zerocopy_t);
"could not enable zerocopy for %s (ENOMEM)\n",
return;
}
/* initialize dl_capability_req_t */
sizeof (dl_capab_zerocopy_t);
rptr += sizeof (dl_capability_req_t);
/* initialize dl_capability_sub_t */
/* initialize dl_capab_zerocopy_t */
ip1dbg(("ill_capability_zerocopy_ack: asking interface %s "
/* set VMSAFE_MEM flag */
/* nmp points to a DL_CAPABILITY_REQ message to enable zcopy */
}
}
static void
{
return;
}
/*
* DLD capability
* Refer to dld.h for more information regarding the purpose and usage
* of this capability.
*/
static void
{
/*
* Note: range checks here are not absolutely sufficient to
* make us robust against malformed messages sent by drivers;
* this is in keeping with the rest of IP's dlpi handling.
* (Remember, it's coming from something else in the kernel
* address space)
*/
"malformed sub-capability too long for mblk");
return;
}
"unsupported DLD sub-capability (version %d, "
return;
}
ip1dbg(("ill_capability_dld_ack: mid token for dld "
"capability isn't as expected; pass-thru module(s) "
"detected, discarding capability\n"));
return;
}
/*
* Copy locally to ensure alignment.
*/
"could not enable DLD version %d "
"for %s (ENOMEM)\n", DLD_CURRENT_VERSION,
return;
}
}
ip1dbg(("ill_capability_dld_ack: interface %s "
}
/*
* Typically capability negotiation between IP and the driver happens via
* DLPI message exchange. However GLD also offers a direct function call
* mechanism to exchange the DLD_DIRECT_CAPAB and DLD_POLL_CAPAB capabilities,
* But arbitrary function calls into IP or GLD are not permitted, since both
* of them are protected by their own perimeter mechanism. The perimeter can
* be viewed as a coarse lock or serialization mechanism. The hierarchy of
* these perimeters is IP -> MAC. Thus for example to enable the squeue
* polling, IP needs to enter its perimeter, then call ill_mac_perim_enter
* to enter the mac perimeter and then do the direct function calls into
* GLD to enable squeue polling. The ring related callbacks from the mac into
* the stack to add, bind, quiesce, restart or cleanup a ring are all
* protected by the mac perimeter.
*/
static void
{
int err;
}
static void
{
int err;
}
{
DLD_QUERY));
}
static void
{
int rc;
if (rc == 0) {
/*
* One time registration of flow enable callback function
*/
} else {
"capability, rc = %d\n", rc);
}
}
static void
{
int rc;
if (rc == 0) {
} else {
ip1dbg(("warning: could not enable POLL "
"capability, rc = %d\n", rc));
}
}
/*
* Enable the LSO capability.
*/
static void
{
int rc;
"could not enable LSO for %s (ENOMEM)\n",
return;
}
}
DLD_ENABLE)) == 0) {
ip1dbg(("ill_capability_lso_enable: interface %s "
} else {
}
}
static void
{
return;
}
}
static void
{
return;
/*
* For performance we avoid locks in the transmit data path
* and don't maintain a count of the number of threads using
* direct calls. Thus some threads could be using direct
* transmit calls to GLD, even after the capability mechanism
* turns it off. This is still safe since the handles used in
* the direct calls continue to be valid until the unplumb is
* completed. Remove the callback that was added (1-time) at
* capab enable time.
*/
}
NULL, DLD_DISABLE);
}
NULL, DLD_DISABLE);
}
/*
* Clear the capability flag for LSO but retain the
* ill_lso_capab structure since it's possible that another
* thread is still referring to it. The structure only gets
* deallocated when we destroy the ill.
*/
NULL, DLD_DISABLE);
}
}
/*
* Capability Negotiation protocol
*
* We don't wait for DLPI capability operations to finish during interface
* bringup or teardown. Doing so would introduce more asynchrony and the
* Instead the 'ipsq_current_ipif' of the ipsq is not cleared as long as
* the 'ill_dlpi_deferred' chain is non-empty. This ensures that the next
* exclusive operation won't start until the DLPI operations of the previous
* exclusive operation complete.
*
* The capability state machine is shown below.
*
* state next state event, action
*
* IDCS_UNKNOWN IDCS_PROBE_SENT ill_capability_probe
* IDCS_PROBE_SENT IDCS_OK ill_capability_ack
* IDCS_PROBE_SENT IDCS_FAILED ip_rput_dlpi_writer (nack)
* IDCS_OK IDCS_RENEG Receipt of DL_NOTE_CAPAB_RENEG
* IDCS_OK IDCS_RESET_SENT ill_capability_reset
* IDCS_RESET_SENT IDCS_UNKNOWN ill_capability_ack_thr
* IDCS_RENEG IDCS_PROBE_SENT ill_capability_ack_thr ->
* ill_capability_probe.
*/
/*
* Dedicated thread started from ip_stack_init that handles capability
* disable. This thread ensures the taskq dispatch does not fail by waiting
* for resources using TQ_SLEEP. The taskq mechanism is used to ensure
* that direct calls to DLD are done in a cv_waitable context.
*/
void
{
char name[64];
name);
for (;;) {
}
if (ipst->ips_capab_taskq_quit)
break;
}
thread_exit();
}
/*
* Consume a new-style hardware capabilities negotiation ack.
* Called via taskq on receipt of DL_CAPABILITY_ACK.
*/
static void
ill_capability_ack_thr(void *arg)
{
/*
* We have received the ack for our DL_CAPAB reset request.
* There isnt' anything in the message that needs processing.
* All message based capabilities have been disabled, now
* do the function call based capability disable.
*/
if (reneg)
goto done;
}
if (capp->dl_sub_length == 0) {
/* no new-style capabilities */
goto done;
}
/* make sure the driver supplied correct dl_sub_length */
ip0dbg(("ill_capability_ack: bad DL_CAPABILITY_ACK, "
goto done;
}
/*
* There are sub-capabilities. Process the ones we know about.
* Loop until we don't have room for another sub-cap header..
*/
case DL_CAPAB_ID_WRAPPER:
break;
default:
break;
}
}
done:
}
/*
* This needs to be started in a taskq thread to provide a cv_waitable
* context.
*/
void
{
TQ_NOSLEEP) != 0)
return;
/*
* The taskq dispatch failed. Signal the ill_taskq_dispatch thread
* which will do the dispatch using TQ_SLEEP to guarantee success.
*/
} else {
}
}
/*
* This routine is called to scan the fragmentation reassembly table for
* the specified ILL for any packets that are starting to smell.
* dead_interval is the maximum time in seconds that will be tolerated. It
* will either be the value specified in ip_g_frag_timeout, or zero if the
* ILL is shutting down and it is time to blow everything off.
*
* It returns the number of seconds (as a time_t) that the next frag timer
* should be scheduled for, 0 meaning that the timer doesn't need to be
* re-started. Note that the method of calculating next_timeout isn't
* entirely accurate since time will flow between the time we grab
* current_time and the time we schedule the next timeout. This isn't a
* big problem since this is the timer for sending an ICMP reassembly time
* exceeded messages, and it doesn't have to be exactly accurate.
*
* This function is
* sometimes called as writer, although this is not required.
*/
{
time_t next_timeout = 0;
return (B_FALSE);
/* Walk the frag hash table. */
if (frag_time < dead_interval) {
/*
* There are some outstanding fragments
* that will timeout later. Make note of
* the time so that we can reschedule the
* next timeout appropriately.
*/
if (next_timeout == 0 ||
frag_timeout < next_timeout) {
}
break;
}
/* Time's up. Get it out of here. */
if (ipfnext)
/* Extra points for neatness. */
IP_REASS_SET_START(mp, 0);
IP_REASS_SET_END(mp, 0);
}
ipfb->ipfb_frag_pkts--;
/*
* We do not send any icmp message from here because
* we currently are holding the ipfb_lock for this
* hash chain. If we try and send any icmp messages
* from here we may end up via a put back into ip
* trying to get the same lock, causing a recursive
* mutex panic. Instead we build a list and send all
* the icmp messages after we have dropped the lock.
*/
if (hdr_length != 0) {
} else {
}
} else {
if (hdr_length != 0) {
send_icmp_head = mp;
} else {
}
}
}
/*
* Now need to send any icmp messages that we delayed from
* above.
*/
while (send_icmp_head_v6 != NULL) {
/*
* This will result in an incorrect ALL_ZONES zoneid
* for multicast packets, but we
* don't send ICMP errors for those in any case.
*/
&iras);
}
while (send_icmp_head != NULL) {
mp = send_icmp_head;
/*
* This will result in an incorrect ALL_ZONES zoneid
* for broadcast and multicast packets, but we
* don't send ICMP errors for those in any case.
*/
}
}
/*
* A non-dying ILL will use the return value to decide whether to
* restart the frag timer, and for how long.
*/
return (next_timeout);
}
/*
* This routine is called when the approximate count of mblk memory used
* for the specified ILL has exceeded max_count.
*/
void
{
/*
* If we are here within ip_min_frag_prune_time msecs remove
* ill_frag_free_num_pkts oldest packets from each bucket and increment
* ill_frag_free_num_pkts.
*/
now = ddi_get_lbolt();
(ip_min_frag_prune_time != 0 ?
} else {
ill->ill_frag_free_num_pkts = 0;
}
/*
* free ill_frag_free_num_pkts oldest packets from each bucket.
*/
if (ill->ill_frag_free_num_pkts != 0) {
int ix;
}
}
}
/*
* While the reassembly list for this ILL is too big, prune a fragment
* queue by age, oldest first.
*/
int ix;
count = 0;
}
}
break;
return; /* Somebody beat us to it, nothing to do */
}
}
}
/*
* free 'free_cnt' fragmented packets starting at ipf.
*/
void
{
IP_REASS_SET_START(tmp, 0);
IP_REASS_SET_END(tmp, 0);
}
ipfb->ipfb_frag_pkts--;
}
if (ipf)
}
#define ND_FORWARD_WARNING "The <if>:ip*_forwarding ndd variables are " \
"obsolete and may be removed in a future release of Solaris. Use " \
"ifconfig(1M) to manipulate the forwarding status of an interface."
/*
* For obsolete per-interface forwarding configuration;
* called in response to ND_GET.
*/
/* ARGSUSED */
static int
{
return (0);
}
/*
* For obsolete per-interface forwarding configuration;
* called in response to ND_SET.
*/
/* ARGSUSED */
static int
{
long value;
int retval;
return (EINVAL);
}
return (retval);
}
/*
* Helper function for ill_forward_set().
*/
static void
{
ip1dbg(("ill_forward_set: %s %s forwarding on %s",
if (enable)
else
/* Notify routing socket listeners of this change. */
}
/*
* Set an ill's ILLF_ROUTER flag appropriately. Send up RTS_IFINFO routing
* socket messages for each interface whose flags we change.
*/
int
{
return (0);
if (IS_LOOPBACK(ill))
return (EINVAL);
/*
* Update all of the interfaces in the group.
*/
/*
* Update the IPMP meta-interface.
*/
return (0);
}
return (0);
}
/*
* Based on the ILLF_ROUTER flag of an ill, make sure all local nce's for
* addresses assigned to the ill have the NCE_F_ISROUTER flag appropriately
* set or clear.
*/
static void
{
/*
* NOTE: we match across the illgrp because nce's for
* addresses on IPMP interfaces have an nce_ill that points to
* the bound underlying ill.
*/
if (enable)
else
}
}
}
/*
* Given an ill with a _valid_ name, add the ip_forwarding ndd variable
* ill. The creation of this ndd variable is only for backwards compatibility.
* The preferred way to control per-interface IP forwarding is through the
* ILLF_ROUTER interface flag.
*/
static int
{
char *suffix;
else
/*
* Copies over the '\0'.
* Note that strlen(suffix) is always bounded.
*/
/*
* Use of the nd table requires holding the reader lock.
* the writer lock.
*/
/*
* If the nd_load failed, it only meant that it could not
* allocate a new bunch of room for further NDD expansion.
* Because of that, the ill_ndd_name will be set to 0, and
* this interface is at the mercy of the global ip_forwarding
* variable.
*/
return (ENOMEM);
}
return (0);
}
/*
* Intializes the context structure and returns the first ill in the list
* cuurently start_list and end_list can have values:
* MAX_G_HEADS Traverse both IPV4 and IPV6 lists.
* IP_V4_G_HEAD Traverse IPV4 list only.
* IP_V6_G_HEAD Traverse IPV6 list only.
*/
/*
* We don't check for CONDEMNED ills here. Caller must do that if
* necessary under the ill lock.
*/
ill_t *
{
/*
* setup the lists to search
*/
if (end_list != MAX_G_HEADS) {
} else {
ctx->ctx_current_list = 0;
}
/*
* ill is guaranteed to be non NULL or ifp should have
* not existed.
*/
return (ill);
}
ctx->ctx_current_list++;
}
return (NULL);
}
/*
* returns the next ill in the list. ill_first() must have been called
* before calling ill_next() or bad things will happen.
*/
/*
* We don't check for CONDEMNED ills here. Caller must do that if
* necessary under the ill lock.
*/
ill_t *
{
return (ill);
}
/* goto next ill_ifp in the list. */
/* make sure not at end of circular list */
while (ifp ==
return (NULL);
}
}
/*
* Check interface name for correct format: [a-zA-Z]+[a-zA-Z0-9._]*[0-9]+
* The final number (PPA) must not have any leading zeros. Upon success, a
* pointer to the start of the PPA is returned; otherwise NULL is returned.
*/
static char *
ill_get_ppa_ptr(char *name)
{
int ppa_ndx, i;
/*
* Check that the first character is [a-zA-Z], and that the last
* character is [0-9].
*/
return (NULL);
/*
* Set `ppa_ndx' to the PPA start, and check for leading zeroes.
*/
break;
return (NULL);
/*
* Check that the intermediate characters are [a-z0-9.]
*/
for (i = 1; i < ppa_ndx; i++) {
return (NULL);
}
}
}
/*
* use avl tree to locate the ill.
*/
static ill_t *
{
int len;
int list;
/*
* get ppa ptr
*/
if (isv6)
list = IP_V6_G_HEAD;
else
list = IP_V4_G_HEAD;
return (NULL);
}
/*
* match is done on len - 1 as the name is not null
* terminated it contains ppa in addition to the interface
* name.
*/
break;
} else {
}
}
/*
* Even the interface type does not exist.
*/
return (NULL);
}
if (ILL_CAN_LOOKUP(ill)) {
return (ill);
}
}
return (NULL);
}
/*
* comparison function for use with avl.
*/
static int
{
/*
* We want the ill with the lowest ppa to be on the
* top.
*/
return (1);
return (-1);
return (0);
}
/*
* remove an interface type from the global list.
*/
static void
{
}
/*
* remove ill from the global list.
*/
static void
{
return;
/*
* If the ill was never inserted into the AVL tree
* we skip the if branch.
*/
/*
* remove from AVL tree and free ppa number
*/
}
}
/*
* Indicate ill is no longer in the list.
*/
ill->ill_name_length = 0;
}
/* Generate one last event for this ill. */
/*
* ill_init allocates a phyint always to store the copy
* of flags relevant to phyint. At that point in time, we could
* not assign the name and hence phyint_illv4/v6 could not be
* initialized. Later in ipif_set_values, we assign the name to
* the ill, at which point in time we assign phyint_illv4/v6.
* Thus we don't rely on phyint_illv6 to be initialized always.
*/
else
return;
}
/*
* There are no ills left on this phyint; pull it out of the phyint
* avl trees, and free it.
*/
if (phyi->phyint_ifindex > 0) {
phyi);
phyi);
}
}
/*
* allocate a ppa, if the number of plumbed interfaces of this type are
* less than ill_no_arena do a linear search to find a unused ppa.
* When the number goes beyond ill_no_arena switch to using an arena.
* Note: ppa value of zero cannot be allocated from vmem_arena as it
* is the return value for an error condition, so allocation starts at one
* and is decremented by one.
*/
static int
{
int ppa;
/*
* Create an arena.
*/
/* allocate what has already been assigned */
1, /* size */
0, /* phase */
0, /* nocross */
/* minaddr */
/* maxaddr */
if (ppa == 0) {
ip1dbg(("ill_alloc_ppa: ppa allocation"
" failed while switching"));
break;
}
}
}
if (ppa == 0)
return (EAGAIN);
} else {
1, /* size */
0, /* phase */
0, /* nocross */
/*
* Most likely the allocation failed because
* the requested ppa was in use.
*/
if (ppa == 0)
return (EEXIST);
}
return (0);
}
/*
* No arena is in use and not enough (>ill_no_arena) interfaces have
* been plumbed to create one. Do a linear search to get a unused ppa.
*/
start = 0;
} else {
}
return (EAGAIN);
else
return (EEXIST);
}
}
return (0);
}
/*
* Insert ill into the list of configured ill's. Once this function completes,
* the ill is globally visible and is available through lookups. More precisely
* this happens after the caller drops the ill_g_lock.
*/
static int
{
avl_index_t where = 0;
int error;
int name_length;
int index;
if (isv6)
else
/*
* Search for interface type based on name
*/
break;
}
}
/*
* Interface type not found, create one.
*/
/*
* allocate ill_if_t structure
*/
if (ill_interface == NULL) {
return (ENOMEM);
}
ill_compare_ppa, sizeof (ill_t),
/*
* link the structure in the back to maintain order
* of configuration for ifconfig output.
*/
}
if (error != 0) {
return (error);
}
/*
* When the ppa is choosen by the system, check that there is
* enough space to insert ppa. if a specific ppa was passed in this
* check is not required as the interface name passed in will have
* the right ppa in it.
*/
if (check_length) {
/*
* UINT_MAX - 1 should fit in 10 chars, alloc 12 chars.
*/
/*
* convert ppa to string to calculate the amount of space
* required for it in the name.
*/
/* Do we have enough space to insert ppa ? */
/* Free ppa and interface type struct */
}
return (EINVAL);
}
}
&where);
return (0);
}
/* Initialize the per phyint ipsq used for serialization */
static boolean_t
{
return (B_FALSE);
if (enter) {
#ifdef DEBUG
#endif
}
return (B_TRUE);
}
/*
* ill_init is called by ip_open when a device control stream is opened.
* It does a few initializations, and shoots a DL_INFO_REQ message down
* to the driver. The response is later picked up in ip_rput_dlpi and
* used to set up default mechanisms for talking to the driver. (Always
* called as writer.)
*
* If this function returns error, ip_open will call ip_close which in
* turn will call ill_delete to clean up any memory allocated here that
* is not yet freed.
*/
int
{
int count;
/*
* The ill is initialized to zero by mi_alloc*(). In addition
* some fields already contain valid values, initialized in
* ip_open(), before we reach here.
*/
ill->ill_saved_ire_cnt = 0;
BPRI_HI);
return (ENOMEM);
/*
* Allocate sufficient space to contain our fragment hash table and
* the device name.
*/
return (ENOMEM);
}
ill->ill_frag_free_num_pkts = 0;
ill->ill_last_frag_clean_time = 0;
}
return (ENOMEM);
}
/*
* For now pretend this is a v4 ill. We need to set phyint_ill*
* at this point because of the following reason. If we can't
* enter the ipsq at some point and cv_wait, the writer that
* wakes us up tries to locate us using the list of all phyints
* in an ipsq and the ills from the phyint thru the phyint_ill*.
* If we don't set it now, we risk a missed wakeup.
*/
return (ENOMEM);
}
/* Frag queue limit stuff */
ill->ill_frag_count = 0;
ill->ill_ipf_gen = 0;
/*
* Initialize IPv6 configuration variables. The IP module is always
* opened as an IPv4 module. Instead tracking down the cases where
* it switches to do ipv6, we'll just initialize the IPv6 configuration
* here for convenience, this has no effect until the ill is set to do
* IPv6.
*/
ill->ill_refcnt = 0;
/* Send down the Info Request to the driver. */
qprocson(q);
return (0);
}
/*
* ill_dls_info
* creates datalink socket info from the device.
*/
int
{
return (sizeof (struct sockaddr_dl));
}
/*
* ill_xarp_info
* creates xarp info from the device.
*/
static int
{
}
static int
{
netstack_t *ns;
return (EIO);
if (rw == KSTAT_WRITE)
return (EACCES);
return (-1);
return (-1);
}
return (0);
}
/*
* Has ifindex been plumbed already?
*/
static boolean_t
{
}
/* Pick a unique ifindex */
{
if (!ipst->ips_ill_index_wrap) {
if (ipst->ips_ill_index == 0) {
/* Reached the uint_t limit Next time wrap */
}
return (B_TRUE);
}
/*
* Start reusing unused indexes. Note that we hold the ill_g_lock
* at this point and don't want to call any function that attempts
* to get the lock again.
*/
if (ipst->ips_ill_index != 0 &&
/* found unused index - use it */
return (B_TRUE);
}
}
/*
* all interface indicies are inuse.
*/
return (B_FALSE);
}
/*
* Assign a unique interface index for the phyint.
*/
static boolean_t
{
}
/*
* Initialize the flags on `phyi' as per the provided mactype.
*/
static void
{
/*
* Initialize PHYI_RUNNING and PHYI_FAILED. For non-IPMP interfaces,
* we always presume the underlying hardware is working and set
* PHYI_RUNNING (if it's not, the driver will subsequently send a
* DL_NOTE_LINK_DOWN message). For IPMP interfaces, at initialization
* there are no active interfaces in the group so we set PHYI_FAILED.
*/
if (mactype == SUNW_DL_IPMP)
flags |= PHYI_FAILED;
else
flags |= PHYI_RUNNING;
switch (mactype) {
case SUNW_DL_VNI:
flags |= PHYI_VIRTUAL;
break;
case SUNW_DL_IPMP:
break;
case DL_LOOP:
break;
}
}
/*
* Return a pointer to the ill which matches the supplied name. Note that
* the ill name length includes the null termination character. (May be
* called as writer.)
* If do_alloc and the interface is "lo0" it will be automatically created.
* Cannot bump up reference on condemned ills. So dup detect can't be done
* using this func.
*/
ill_t *
{
return (ill);
/*
* Couldn't find it. Does this happen to be a lookup for the
* loopback device and are we allowed to allocate it?
*/
if (!isloopback || !do_alloc)
return (NULL);
return (ill);
}
/* Create the loopback device on demand */
sizeof (ipif_loopback_name), BPRI_MED));
goto done;
/*
* For exclusive stacks we set the zoneid to zero
* to make IP operate as if in the global zone.
*/
goto done;
if (isv6)
else
if (isv6) {
} else {
}
if (!ill_allocate_mibs(ill))
goto done;
/*
* ipif_loopback_name can't be pointed at directly because its used
* by both the ipv4 and ipv6 interfaces. When the ill is removed
* from the glist, ill_glist_delete() sets the first character of
* ill_name to '\0'.
*/
/* Set ill_dlpi_pending for ipsq_current_finish() to work properly */
/* No resolver here. */
/* Initialize the ipsq */
goto done;
goto done;
/* Set up default loopback address and mask. */
if (!isv6) {
} else {
}
/*
* Chain us in at the end of the ill list. hold the ill
* before we make it globally visible. 1 for the lookup.
*/
ill->ill_refcnt = 0;
ill->ill_frag_count = 0;
ill->ill_frag_free_num_pkts = 0;
ill->ill_last_frag_clean_time = 0;
/* Let SCTP know so that it can add this to its list */
/*
* We have already assigned ipif_v6lcl_addr above, but we need to
* call sctp_update_ipif_addr() after SCTP_ILL_INSERT, which
* requires to be after ill_glist_insert() since we need the
* ill_index set. Pass on ipv6_loopback as the old address.
*/
/*
* ill_glist_insert() -> ill_phyint_reinit() may have merged IPSQs.
* If so, free our original one.
*/
/* Export loopback interface statistics */
ipif_loopback_name, "net",
KSTAT_TYPE_NAMED, 2, 0,
}
}
return (ill);
done:
}
}
}
return (NULL);
}
/*
* For IPP calls - use the ip_stack_t for global stack.
*/
ill_t *
{
return (NULL);
}
return (ill);
}
/*
* Return a pointer to the ill which matches the index and IP version type.
*/
ill_t *
{
/*
* Indexes are stored in the phyint - a common structure
* to both IPv4 and IPv6.
*/
if (!ILL_IS_CONDEMNED(ill)) {
return (ill);
}
}
}
return (NULL);
}
/*
* Verify whether or not an interface index is valid for the specified zoneid
* to transmit packets.
* It can be zero (meaning "reset") or an interface index assigned
* to a non-VNI interface. (We don't use VNI interface to send packets.)
*/
{
if (ifindex == 0)
return (B_TRUE);
return (B_FALSE);
return (B_FALSE);
}
return (B_TRUE);
}
/*
* Return the ifindex next in sequence after the passed in ifindex.
* If there is no next ifindex for the given protocol, return 0.
*/
{
if (index == 0) {
} else {
}
/*
* If we're not returning the first interface in the tree
* and we still haven't moved past the phyint_t that
* corresponds to index, avl_walk needs to be called again
*/
if (isv6) {
if ((phyi->phyint_illv6) &&
break;
} else {
if ((phyi->phyint_illv4) &&
break;
}
}
}
else
ifindex = 0;
return (ifindex);
}
/*
* Return the ifindex for the named interface.
* If there is no next ifindex for the interface, return 0.
*/
{
avl_index_t where = 0;
return (0);
}
return (ifindex);
}
/*
* Return the ifindex to be used by upper layer protocols for instance
* for IPV6_RECVPKTINFO. If IPMP this is the one for the upper ill.
*/
{
if (IS_UNDER_IPMP(ill))
return (ipmp_ill_get_ipmp_ifindex(ill));
else
}
/*
* Obtain a reference to the ill. The ill_refcnt is a dynamic refcnt
* that gives a running thread a reference to the ill. This reference must be
* released by the thread when it is done accessing the ill and related
* objects. ill_refcnt can not be used to account for static references
* such as other structures pointing to an ill. Callers must generally
* check whether an ill can be refheld by using ILL_CAN_LOOKUP macros
* or be sure that the ill is not being deleted or changing state before
* calling the refhold functions. A non-zero ill_refcnt ensures that the
* ill won't change any of its critical state such as address, netmask etc.
*/
void
{
ill->ill_refcnt++;
}
void
{
ill->ill_refcnt++;
}
/* Returns true if we managed to get a refhold */
{
if (!ILL_IS_CONDEMNED(ill)) {
return (B_TRUE);
}
return (B_FALSE);
}
/*
* Must not be called while holding any locks. Otherwise if this is
* the last reference to be released, there is a chance of recursive mutex
* panic due to ill_refrele -> ipif_ill_refrele_tail -> qwriter_ip trying
* to restart an ioctl.
*/
void
{
ill->ill_refcnt--;
if (ill->ill_refcnt != 0) {
/* Every ire pointing to the ill adds 1 to ill_refcnt */
return;
}
/* Drops the ill_lock */
}
/*
* Obtain a weak reference count on the ill. This reference ensures the
* ill won't be freed, but the ill may change any of its critical state
* such as netmask, address etc. Returns an error if the ill has started
* closing.
*/
{
return (B_FALSE);
}
ill->ill_waiters++;
return (B_TRUE);
}
void
{
ill->ill_waiters--;
if (ill->ill_waiters == 0)
}
/*
* ip_ll_subnet_defaults is called when we get the DL_INFO_ACK back from the
* driver. We construct best guess defaults for lower level information that
* we need. If an interface is brought up without injection of any overriding
* information from outside, we have to be ready to go with these defaults.
* When we get the first DL_INFO_ACK (from ip_open() sending a DL_INFO_REQ)
* we primarely want the dl_provider_style.
* The subsequent DL_INFO_ACK is received after doing a DL_ATTACH and DL_BIND
* at which point we assume the other part of the information is valid.
*/
void
{
int min_mtu;
/*
* Till the ill is fully up the ill is not globally visible.
* So no need for a lock.
*/
}
/*
* When the new DLPI stuff is ready we'll pull lengths
* from dlia.
*/
if (brdcst_addr == NULL) {
brdcst_addr_length = 0;
}
ip1dbg(("ip: bcast_len %d, sap_len %d, phys_len %d\n",
} else {
brdcst_addr_length = 6;
sap_length = -2;
}
/*
* Synthetic DLPI types such as SUNW_DL_IPMP specify a zero SDU,
* but we must ensure a minimum IP MTU is used since other bits of
* IP will fly apart otherwise.
*/
if (!ill->ill_dlpi_style_set) {
/*
* Allocate the first ipif on this ill. We don't delay it
* further as ioctl handling assumes at least one ipif exists.
*
* At this point we don't know whether the ill is v4 or v6.
* We will know this whan the SIOCSLIFNAME happens and
* the correct value for ill_isv6 will be assigned in
* ipif_set_values(). We need to hold the ill lock and
* clear the ILL_LL_SUBNET_PENDING flag and atomically do
* the wakeup.
*/
return;
}
/*
* We know whether it is IPv4 or IPv6 now, as this is the
* second DL_INFO_ACK we are recieving in response to the
* DL_INFO_REQ sent in ipif_set_values.
*/
/*
* Clear all the flags that were set based on ill_bcast_addr_length
* and ill_phys_addr_length (in ipif_set_values) as these could have
* changed now and we need to re-evaluate.
*/
/*
* Free ill_bcast_mp as things could have changed now.
*
* NOTE: The IPMP meta-interface is special-cased because it starts
* with no underlying interfaces (and thus an unknown broadcast
* address length), but we enforce that an interface is broadcast-
* capable as part of allowing it to join a group.
*/
/*
* Note: xresolv interfaces will eventually need NOARP
* set here as well, but that will require those
* external resolvers to have some knowledge of
* that flag and act appropriately. Not to be changed
* at present.
*/
else
} else if (ill->ill_phys_addr_length == 0 ||
/*
* The underying link is point-to-point, so mark the
* interface as such. We can do IP multicast over
* such a link since it transmits all network-layer
* packets to the remote side the same way.
*/
}
} else {
/*
* Later detect lack of DLPI driver multicast
* capability by catching DL_ENABMULTI errors in
* ip_rput_dlpi.
*/
}
/* For IPMP, PHYI_IPMP should already be set by phyint_flags_init() */
/* By default an interface does not support any CoS marking */
/*
* If we get QoS information in DL_INFO_ACK, the device supports
* some form of CoS marking, set ILLF_COS_ENABLED.
*/
}
/* Clear any previous error indication. */
}
/*
* Perform various checks to verify that an address would make sense as a
* local, remote, or subnet interface address.
*/
static boolean_t
{
/*
* Don't allow all zeroes, or all ones, but allow
* all ones netmask.
*/
return (B_FALSE);
/* A given netmask overrides the "guess" netmask */
if (subnet_mask != 0)
return (B_FALSE);
}
/*
* Even if the netmask is all ones, we do not allow address to be
* 255.255.255.255
*/
if (addr == INADDR_BROADCAST)
return (B_FALSE);
return (B_FALSE);
return (B_TRUE);
}
#define V6_IPIF_LINKLOCAL(p) \
/*
* Compare two given ipifs and check if the second one is better than
* the first one using the order of preference (not taking deprecated
* into acount) specified in ipif_lookup_multicast().
*/
static boolean_t
{
/* Check the least preferred first. */
/* If both ipifs are the same, use the first one. */
return (B_FALSE);
else
return (B_TRUE);
}
/* For IPv6, check for link local address. */
/* The second one is equal or less preferred. */
return (B_FALSE);
} else {
return (B_TRUE);
}
}
/* Then check for point to point interface. */
return (B_FALSE);
} else {
return (B_TRUE);
}
}
/* old_ipif is a normal interface, so no need to use the new one. */
return (B_FALSE);
}
/*
* Find a mulitcast-capable ipif given an IP instance and zoneid.
* The ipif must be up, and its ill must multicast-capable, not
* condemned, not an underlying interface in an IPMP group, and
* not a VNI interface. Order of preference:
*
* 1a. normal
* 1b. normal, but deprecated
* 2a. point to point
* 2b. point to point, but deprecated
* 3a. link local
* 3b. link local, but deprecated
* 4. loopback.
*/
static ipif_t *
{
if (isv6)
else
ILL_IS_CONDEMNED(ill) ||
continue;
}
continue;
}
continue;
}
/*
* Found one candidate. If it is deprecated,
* remember it in dep_ipif. If it is not deprecated,
* remember it in saved_ipif.
*/
isv6)) {
/*
* If the previous dep_ipif does not
* belong to the same ill, we've done
* a ipif_refhold() on it. So we need
* to release it.
*/
}
continue;
}
if (saved_ipif == NULL) {
saved_ipif = ipif;
} else {
saved_ipif = ipif;
}
}
}
/*
* Before going to the next ill, do a ipif_refhold() on the
* saved ones.
*/
}
/*
* If we have only the saved_ipif, return it. But if we have both
* saved_ipif and dep_ipif, check to see which one is better.
*/
if (saved_ipif != NULL) {
return (dep_ipif);
} else {
return (saved_ipif);
}
}
return (saved_ipif);
} else {
return (dep_ipif);
}
}
ill_t *
{
return (NULL);
return (ill);
}
/*
* This function is called when an application does not specify an interface
* calls ire_lookup_multi() to look for an interface route for the
* specified multicast group. Doing this allows the administrator to add
* prefix routes for multicast to indicate which interface to be used for
* multicast traffic in the above scenario. The route could be for all
* multicast (224.0/4), for a single multicast group (a /32 route) or
* anything in between. If there is no such multicast route, we just find
* any multicast capable interface and return it. The returned ipif
* is refhold'ed.
*
* We support MULTIRT and RTF_SETSRC on the multicast routes added to the
* unicast table. This is used by CGTP.
*/
ill_t *
{
return (ill);
}
/*
* Look for an ipif with the specified interface address and destination.
* The destination address is used only for matching point-to-point interfaces.
*/
ipif_t *
{
/*
* First match all the point-to-point interfaces
* before looking at non-point-to-point interfaces.
* This is done to avoid returning non-point-to-point
* ipif instead of unnumbered point-to-point ipif.
*/
/* Allow the ipif to be down */
if (!IPIF_IS_CONDEMNED(ipif)) {
return (ipif);
}
}
}
}
/* lookup the ipif based on interface address */
return (ipif);
}
/*
* Common function for ipif_lookup_addr() and ipif_lookup_addr_exact().
*/
static ipif_t *
{
/*
* Repeat twice, first based on local addresses and
* next time for pointopoint.
*/
continue;
}
continue;
continue;
/* Allow the ipif to be down */
if (!IPIF_IS_CONDEMNED(ipif)) {
return (ipif);
}
}
}
}
/* If we already did the ptp case, then we are done */
if (ptp) {
return (NULL);
}
goto repeat;
}
/*
* Lookup an ipif with the specified address. For point-to-point links we
* look for matches on either the destination address or the local address,
* but we skip the local address check if IPIF_UNNUMBERED is set. If the
* `match_ill' argument is non-NULL, the lookup is restricted to that ill
* (or illgrp if `match_ill' is in an IPMP group).
*/
ipif_t *
{
}
/*
* Lookup an ipif with the specified address. Similar to ipif_lookup_addr,
* except that we will only return an address if it is not marked as
* IPIF_DUPLICATE
*/
ipif_t *
{
}
/*
* Special abbreviated version of ipif_lookup_addr() that doesn't match
* `match_ill' across the IPMP group. This function is only needed in some
* corner-cases; almost everything should use ipif_lookup_addr().
*/
ipif_t *
{
ipst));
}
/*
* Look for an ipif with the specified address. For point-point links
* we look for matches on either the destination address and the local
* address, but we ignore the check on the local address if IPIF_UNNUMBERED
* is set.
* If the `match_ill' argument is non-NULL, the lookup is restricted to that
* ill (or illgrp if `match_ill' is in an IPMP group).
* Return the zoneid for the ipif which matches. ALL_ZONES if no match.
*/
{
/*
* Repeat twice, first based on local addresses and
* next time for pointopoint.
*/
continue;
}
/* Allow the ipif to be down */
/*
* If ipif_zoneid was ALL_ZONES then we have
* a trusted extensions shared IP address.
* In that case GLOBAL_ZONEID works to send.
*/
return (zoneid);
}
}
}
/* If we already did the ptp case, then we are done */
if (ptp) {
return (ALL_ZONES);
}
goto repeat;
}
/*
* Look for an ipif that matches the specified remote address i.e. the
* ipif that would receive the specified packet.
* First look for directly connected interfaces and then do a recursive
* IRE lookup and pick the first ipif corresponding to the source address in the
* ire.
* Returns: held ipif
*
* This is only used for ICMP_ADDRESS_MASK_REQUESTs
*/
ipif_t *
{
/*
* Someone could be changing this ipif currently or change it
* after we return this. Thus a few packets could use the old
* will atomically be updated or cleaned up with the new value
* Thus we don't need a lock to check the flags or other attrs below.
*/
if (IPIF_IS_CONDEMNED(ipif))
continue;
continue;
/* Allow the ipif to be down */
return (ipif);
}
return (ipif);
}
}
/*
* For a remote destination it isn't possible to nail down a particular
* ipif.
*/
/* Pick the first interface */
return (ipif);
}
/*
* This func does not prevent refcnt from increasing. But if
* the caller has taken steps to that effect, then this func
* can be used to determine whether the ill has become quiescent
*/
static boolean_t
{
if (ipif->ipif_refcnt != 0)
return (B_FALSE);
}
return (B_FALSE);
}
return (B_TRUE);
}
{
if (ipif->ipif_refcnt != 0) {
return (B_FALSE);
}
}
return (B_FALSE);
}
return (B_TRUE);
}
/*
* This func does not prevent refcnt from increasing. But if
* the caller has taken steps to that effect, then this func
* can be used to determine whether the ipif has become quiescent
*/
static boolean_t
{
if (ipif->ipif_refcnt != 0)
return (B_FALSE);
ill->ill_logical_down) {
return (B_TRUE);
}
/* This is the last ipif going down or being deleted on this ill */
return (B_FALSE);
}
return (B_TRUE);
}
/*
* return true if the ipif can be destroyed: the ipif has to be quiescent
*/
static boolean_t
{
return (ipif->ipif_refcnt == 0);
}
/*
* Determine if the ipif or ill in question has become quiescent and if so
* for the ipif_down (or ill_down)
*/
void
{
/* ip_modclose() may be waiting */
}
goto unlock;
goto unlock;
switch (ipx->ipx_waitfor) {
case IPIF_DOWN:
if (!ipif_is_quiescent(ipif))
goto unlock;
break;
case IPIF_FREE:
if (!ipif_is_freeable(ipif))
goto unlock;
break;
case ILL_DOWN:
if (!ill_is_quiescent(ill))
goto unlock;
break;
case ILL_FREE:
/*
* ILL_FREE is only for loopback; normal ill teardown waits
* synchronously in ip_modclose() without using ipx_waitfor,
* handled by the cv_broadcast() at the top of this function.
*/
if (!ill_is_freeable(ill))
goto unlock;
break;
default:
}
/*
* NOTE: all of the qwriter_ip() calls below use CUR_OP since
* we can only get here when the current operation decides it
* it needs to quiesce via ipsq_pending_mp_add().
*/
case M_PCPROTO:
case M_PROTO:
/*
* For now, only DL_NOTIFY_IND messages can use this facility.
*/
switch (dlindp->dl_notification) {
case DL_NOTE_PHYS_ADDR:
return;
case DL_NOTE_REPLUMB:
return;
default:
ASSERT(0);
}
break;
case M_ERROR:
case M_HANGUP:
B_TRUE);
return;
case M_IOCTL:
case M_IOCDATA:
return;
default:
}
return;
}
#ifdef DEBUG
/* Reuse trace buffer from beginning (if reached the end) and record trace */
static void
{
lastref++;
if (lastref == TR_BUF_MAX)
lastref = 0;
}
static void
th_trace_free(void *value)
{
}
/*
* Find or create the per-thread hash table used to track object references.
* The ipst argument is NULL if we shouldn't allocate.
*
* Accesses per-thread data, so there's no need to lock here.
*/
static mod_hash_t *
{
mod_hash_t *mh;
char name[256];
int retv;
return (NULL);
(void *)curthread);
/*
* We use mod_hash_create_extended here rather than the more
* obvious mod_hash_create_ptrhash because the latter has a
* hard-coded KM_SLEEP, and we'd prefer to fail rather than
* block.
*/
return (NULL);
}
/*
* We trace ills, ipifs, ires, and nces. All of these are
* per-IP-stack, so the lock on the thread list is as well.
*/
}
}
{
mod_hash_t *mh;
return (B_FALSE);
/*
* Attempt to locate the trace buffer for this obj and thread.
* If it does not exist, then allocate a new trace buffer and
* insert into the hash.
*/
return (B_FALSE);
(mod_hash_val_t)th_trace) != 0) {
return (B_FALSE);
}
} else {
}
return (B_TRUE);
}
/*
* For the purpose of tracing a reference release, we assume that global
* tracing is always on and that the same thread initiated the reference hold
* is releasing.
*/
void
th_trace_unref(const void *obj)
{
int retv;
mod_hash_t *mh;
}
/*
* If tracing has been disabled, then we assume that the reference counts are
* now useless, and we clear them out before destroying the entries.
*/
void
{
mod_hash_t *mh;
int retv;
&val) == 0) {
if (trace_disable)
}
}
}
void
{
if (ipif->ipif_trace_disable)
return;
}
}
void
{
if (!ipif->ipif_trace_disable)
}
void
{
if (ill->ill_trace_disable)
return;
}
}
void
{
if (!ill->ill_trace_disable)
}
/*
* Called when ipif is unplumbed or when memory alloc fails. Note that on
* failure, ipif_trace_disable is set.
*/
static void
{
}
/*
* Called when ill is unplumbed or when memory alloc fails. Note that on
* failure, ill_trace_disable is set.
*/
static void
{
}
#endif /* DEBUG */
void
{
ipif->ipif_refcnt++;
}
void
{
ipif->ipif_refcnt++;
}
/*
* Must not be called while holding any locks. Otherwise if this is
* the last reference to be released there is a chance of recursive mutex
* panic due to ipif_refrele -> ipif_ill_refrele_tail -> qwriter_ip trying
* to restart an ioctl.
*/
void
{
ipif->ipif_refcnt--;
if (ipif->ipif_refcnt != 0) {
return;
}
/* Drops the ill_lock */
}
ipif_t *
{
if (IPIF_IS_CONDEMNED(ipif))
continue;
return (ipif);
}
return (NULL);
}
/*
* TODO: make this table extendible at run time
* Return a pointer to the mac type info for 'mac_type'
*/
static ip_m_t *
{
return (ipm);
return (NULL);
}
/*
* Make a link layer address from the multicast IP address *addr.
* To form the link layer address, invoke the ip_m_v*mapping function
* associated with the link-layer type.
*/
void
{
return;
ip0dbg(("no mapping for ill %s mactype 0x%x\n",
return;
}
else
}
/*
* ip_rt_add is called to add an IPv4 route to the forwarding table.
* ill is passed in to associate it with the correct interface.
* If ire_arg is set, then we return the held IRE in that location.
*/
int
{
int match_flags = MATCH_IRE_TYPE;
ip1dbg(("ip_rt_add:"));
/*
* If this is the case of RTF_HOST being set, then we set the netmask
* to all ones (regardless if one was supplied).
*/
mask = IP_HOST_MASK;
/*
* Prevent routes with a zero gateway from being created (since
* interfaces can currently be plumbed and brought up no assigned
* address).
*/
if (gw_addr == 0)
return (ENETUNREACH);
/*
* Get the ipif, if any, corresponding to the gw_addr
* If -ifp was specified we restrict ourselves to the ill, otherwise
* we match on the gatway and destination to handle unnumbered pt-pt
* interfaces.
*/
else
return (EINVAL);
}
}
/*
* GateD will attempt to create routes with a loopback interface
* address as the gateway and with RTF_GATEWAY set. We allow
* these routes to be added, but create them as interface routes
* since the gateway is an interface address.
*/
flags &= ~RTF_GATEWAY;
mask == IP_HOST_MASK) {
NULL);
return (EEXIST);
}
ip1dbg(("ip_rt_add: 0x%p creating IRE 0x%x"
"for 0x%x\n", (void *)ipif,
ire = ire_create(
NULL, /* no gateway */
NULL,
ipst);
return (ENOMEM);
}
/* src address assigned by the caller? */
/*
* In the result of failure, ire_add() will have
* already deleted the ire in question, so there
* is no need to do that here.
*/
return (ENOMEM);
}
/*
* Check if it was a duplicate entry. This handles
* the case of two racing route adds for the same route
*/
return (EEXIST);
}
goto save_ire;
}
}
/*
* The routes for multicast with CGTP are quite special in that
* the gateway is the local interface address, yet RTF_GATEWAY
* is set. We turn off RTF_GATEWAY to provide compatibility with
* this undocumented and unusual use of multicast routes.
*/
flags &= ~RTF_GATEWAY;
/*
* Traditionally, interface routes are ones where RTF_GATEWAY isn't set
* and the gateway address provided is one of the system's interface
* addresses. By using the routing socket interface and supplying an
* RTA_IFP sockaddr with an interface index, an alternate method of
* specifying an interface route to be created is available which uses
* the interface index that specifies the outgoing interface rather than
* the address of an outgoing interface (which may not be able to
* uniquely identify an interface). When coupled with the RTF_GATEWAY
* flag, routes can be specified which not only specify the next-hop to
* be used when routing to a certain prefix, but also which outgoing
* interface should be used.
*
* Previously, interfaces would have unique addresses assigned to them
* and so the address assigned to a particular interface could be used
* to identify a particular interface. One exception to this was the
* case of an unnumbered interface (where IPIF_UNNUMBERED was set).
*
* With the advent of IPv6 and its link-local addresses, this
* restriction was relaxed and interfaces could share addresses between
* themselves. In fact, typically all of the link-local interfaces on
* an IPv6 node or router will have the same link-local address. In
* order to differentiate between these interfaces, the use of an
* interface index is necessary and this index can be carried inside a
* RTA_IFP sockaddr (which is actually a sockaddr_dl). One restriction
* of using the interface index, however, is that all of the ipif's that
* are part of an ill have the same index and so the RTA_IFP sockaddr
* cannot be used to differentiate between ipif's (or logical
* interfaces) that belong to the same ill (physical interface).
*
* For example, in the following case involving IPv4 interfaces and
* logical interfaces
*
* 192.0.2.32 255.255.255.224 192.0.2.33 U if0
* 192.0.2.32 255.255.255.224 192.0.2.34 U if0
* 192.0.2.32 255.255.255.224 192.0.2.35 U if0
*
* the ipif's corresponding to each of these interface routes can be
* uniquely identified by the "gateway" (actually interface address).
*
* In this case involving multiple IPv6 default routes to a particular
* link-local gateway, the use of RTA_IFP is necessary to specify which
* default route is of interest:
*
* default fe80::123:4567:89ab:cdef U if0
* default fe80::123:4567:89ab:cdef U if1
*/
/* RTF_GATEWAY not set */
if (!(flags & RTF_GATEWAY)) {
ip2dbg(("ip_rt_add: gateway security attributes "
"cannot be set with interface route\n"));
return (EINVAL);
}
/*
* Whether or not ill (RTA_IFP) is set, we require that
* the gateway is one of our local addresses.
*/
return (ENETUNREACH);
/*
* We use MATCH_IRE_ILL here. If the caller specified an
* interface (from the RTA_IFP sockaddr) we use it, otherwise
* we use the ill derived from the gateway address.
* We can always match the gateway address since we record it
* in ire_gateway_addr.
* We don't allow RTA_IFP to specify a different ill than the
* one matching the ipif to make sure we can delete the route.
*/
return (EINVAL);
}
/*
* We check for an existing entry at this point.
*
* Since a netmask isn't passed in via the ioctl interface
* (SIOCADDRT), we don't check for a matching netmask in that
* case.
*/
if (!ioctl_msg)
NULL);
return (EEXIST);
}
/*
* Some software (for example, GateD and Sun Cluster) attempts
* to create (what amount to) IRE_PREFIX routes with the
* loopback address as the gateway. This is primarily done to
* set up prefixes with the RTF_REJECT flag set (for example,
* when generating aggregate routes.)
*
* If the IRE type (as defined by ill->ill_net_type) would be
* IRE_LOOPBACK, then we map the request into a
* IRE_IF_NORESOLVER. We also OR in the RTF_BLACKHOLE flag as
* these interface routes, by definition, can only be that.
*
* Needless to say, the real IRE_LOOPBACK is NOT created by this
* routine, but rather using ire_create() directly.
*
*/
if (type == IRE_LOOPBACK) {
flags |= RTF_BLACKHOLE;
}
/*
* Create a copy of the IRE_IF_NORESOLVER or
* IRE_IF_RESOLVER with the modified address, netmask, and
* gateway.
*/
ire = ire_create(
type,
ill,
NULL,
ipst);
return (ENOMEM);
}
/* src address assigned by the caller? */
/*
* In the result of failure, ire_add() will have
* already deleted the ire in question, so there
* is no need to do that here.
*/
return (ENOMEM);
}
/*
* Check if it was a duplicate entry. This handles
* the case of two racing route adds for the same route
*/
return (EEXIST);
}
goto save_ire;
}
/*
* Get an interface IRE for the specified gateway.
* If we don't have an IRE_IF_NORESOLVER or IRE_IF_RESOLVER for the
* gateway, it is currently unreachable and we fail the request
* accordingly. We reject any RTF_GATEWAY routes where the gateway
* is an IRE_LOCAL or IRE_LOOPBACK.
* If RTA_IFP was specified we look on that particular ill.
*/
/* Check whether the gateway is reachable. */
if (flags & RTF_INDIRECT)
type |= IRE_OFFLINK;
/*
* With IPMP, we allow host routes to influence in.mpathd's
* target selection. However, if the test addresses are on
* their own network, the above lookup will fail since the
* underlying IRE_INTERFACEs are marked hidden. So allow
* hidden test IREs to be found and try again.
*/
if (!(match_flags & MATCH_IRE_TESTHIDDEN)) {
goto again;
}
return (ENETUNREACH);
}
return (ENETUNREACH);
}
if (ipst->ips_ip_strict_src_multihoming > 0)
}
/*
* We create one of three types of IREs as a result of this request
* based on the netmask. A netmask of all ones (which is automatically
* assumed when RTF_HOST is set) results in an IRE_HOST being created.
* An all zeroes netmask implies a default route so an IRE_DEFAULT is
* created. Otherwise, an IRE_PREFIX route is created for the
* destination prefix.
*/
if (mask == IP_HOST_MASK)
else if (mask == 0)
type = IRE_DEFAULT;
else
type = IRE_PREFIX;
/* check for a duplicate entry */
return (EEXIST);
}
/* Security attribute exists */
/* find or create the gateway credentials group */
/* we hold reference to it upon success */
return (ENOMEM);
}
/*
* Create and add the security attribute to the group; a
* reference to the group is made upon allocating a new
* entry successfully. If it finds an already-existing
* entry for the security attribute in the group, it simply
* returns it and no new reference is made to the group.
*/
/* release reference held by gcgrp_lookup */
return (ENOMEM);
}
}
/* Create the IRE. */
ire = ire_create(
ill,
gc, /* security attribute */
ipst);
/*
* The ire holds a reference to the 'gc' and the 'gc' holds a
* reference to the 'gcgrp'. We can now release the extra reference
* the 'gcgrp' acquired in the gcgrp_lookup, if it was not used.
*/
if (gcgrp_xtraref)
GC_REFRELE(gc);
return (ENOMEM);
}
/* Before we add, check if an extra CGTP broadcast is needed */
/* src address assigned by the caller? */
/*
* POLICY: should we allow an RTF_HOST with address INADDR_ANY?
*/
/* Add the new IRE. */
/*
* In the result of failure, ire_add() will have
* already deleted the ire in question, so there
* is no need to do that here.
*/
return (ENOMEM);
}
/*
* Check if it was a duplicate entry. This handles
* the case of two racing route adds for the same route
*/
return (EEXIST);
}
if (flags & RTF_MULTIRT) {
/*
* Invoke the CGTP (multirouting) filtering module
* to add the dst address in the filtering database.
* Replicated inbound packets coming from that address
* will be filtered to discard the duplicates.
* It is not necessary to call the CGTP filter hook
* when the dst address is a broadcast or multicast,
* because an IP source address cannot be a broadcast
* or a multicast.
*/
if (cgtp_broadcast) {
goto save_ire;
}
int res;
/* Find the source address corresponding to gw_ire */
} else {
res = EADDRNOTAVAIL;
}
if (res != 0) {
return (res);
}
}
}
}
/*
* Save enough information so that we can recreate the IRE if
* the interface goes down and then up. The metrics associated
* with the route will be saved as well when rts_setmetrics() is
* called after the IRE has been created. In the case where
* memory cannot be allocated, none of this information will be
* saved.
*/
}
if (ioctl_msg)
/*
* Store the ire that was successfully added into where ire_arg
* points to so that callers don't have to look it up
* themselves (but they are responsible for ire_refrele()ing
* the ire when they are finished with it).
*/
} else {
}
return (0);
}
/*
* ip_rt_delete is called to delete an IPv4 route.
* ill is passed in to associate it with the correct interface.
*/
/* ARGSUSED4 */
int
{
int err = 0;
ip1dbg(("ip_rt_delete:"));
/*
* If this is the case of RTF_HOST being set, then we set the netmask
* to all ones. Otherwise, we use the netmask if one was supplied.
*/
mask = IP_HOST_MASK;
} else if (rtm_addrs & RTA_NETMASK) {
}
/*
* Note that RTF_GATEWAY is never set on a delete, therefore
* we check if the gateway address is one of our interfaces first,
* and fall back on RTF_GATEWAY routes.
*
* This makes it possible to delete an original
* IRE_IF_NORESOLVER/IRE_IF_RESOLVER - consistent with SunOS 4.1.
* However, we have RTF_KERNEL set on the ones created by ipif_up
* and those can not be deleted here.
*
* We use MATCH_IRE_ILL if we know the interface. If the caller
* specified an interface (from the RTA_IFP sockaddr) we use it,
* otherwise we use the ill derived from the gateway address.
* We can always match the gateway address since we record it
* in ire_gateway_addr.
*
* For more detail on specifying routes by gateway address and by
* interface index, see the comments in ip_rt_add().
*/
else
}
}
/* Avoid deleting routes created by kernel from an ipif */
}
/* Restore in case we didn't find a match */
}
/*
* At this point, the gateway address is not one of our own
* addresses or a matching interface route was not found. We
* set the IRE type to lookup based on whether
* this is a host route, a default route or just a prefix.
*
* If an ill was passed in, then the lookup is based on an
* interface index so MATCH_IRE_ILL is added to match_flags.
*/
if (mask == IP_HOST_MASK)
else if (mask == 0)
type = IRE_DEFAULT;
else
type = IRE_PREFIX;
}
}
return (ESRCH);
/*
* Invoke the CGTP (multirouting) filtering module
* to remove the dst address from the filtering database.
* Packets coming from that address will no longer be
* filtered to remove duplicates.
*/
}
}
if (ioctl_msg)
return (err);
}
/*
* ip_siocaddrt is called to complete processing of an SIOCADDRT IOCTL.
*/
/* ARGSUSED */
int
{
int error = 0;
ipst = CONNQ_TO_IPST(q);
ip1dbg(("ip_siocaddrt:"));
/* Existence of mp1 verified in ip_wput_nondata */
/*
* If the RTF_HOST flag is on, this is a request to assign a gateway
* to a particular host address. In this case, we set the netmask to
* all ones for the particular destination address. Otherwise,
* determine the netmask to be used based on dst_addr and the interfaces
* in use.
*/
mask = IP_HOST_MASK;
} else {
/*
* Note that ip_subnet_mask returns a zero mask in the case of
* default (an all-zeroes address).
*/
}
return (error);
}
/*
* ip_siocdelrt is called to complete processing of an SIOCDELRT IOCTL.
*/
/* ARGSUSED */
int
{
int error;
ipst = CONNQ_TO_IPST(q);
ip1dbg(("ip_siocdelrt:"));
/* Existence of mp1 verified in ip_wput_nondata */
/*
* If the RTF_HOST flag is on, this is a request to delete a gateway
* to a particular host address. In this case, we set the netmask to
* all ones for the particular destination address. Otherwise,
* determine the netmask to be used based on dst_addr and the interfaces
* in use.
*/
mask = IP_HOST_MASK;
} else {
/*
* Note that ip_subnet_mask returns a zero mask in the case of
* default (an all-zeroes address).
*/
}
return (error);
}
/*
* Enqueue the mp onto the ipsq, chained by b_next.
* b_prev stores the function to be executed later, and b_queue the queue
* where this mp originated.
*/
void
{
switch (type) {
case CUR_OP:
} else {
}
break;
case NEW_OP:
} else {
}
break;
case SWITCH_OP:
/* only one switch operation is currently allowed */
break;
default:
}
}
}
/*
* Dequeue the next message that requested exclusive access to this IPSQ's
* xop. Specifically:
*
* 1. If we're still processing the current operation on `ipsq', then
* dequeue the next message for the operation (from ipx_mphead), or
* return NULL if there are no queued messages for the operation.
* These messages are queued via CUR_OP to qwriter_ip() and friends.
*
* 2. If the current operation on `ipsq' has completed (ipx_current_ipif is
* not set) see if the ipsq has requested an xop switch. If so, switch
* `ipsq' to a different xop. Xop switches only happen when joining or
* leaving IPMP groups and require a careful dance -- see the comments
* in-line below for details. If we're leaving a group xop or if we're
* joining a group xop and become writer on it, then we proceed to (3).
* Otherwise, we return NULL and exit the xop.
*
* 3. For each IPSQ in the xop, return any switch operation stored on
* ipsq_switch_mp (set via SWITCH_OP); these must be processed before
* any other messages queued on the IPSQ. Otherwise, dequeue the next
* exclusive operation (queued via NEW_OP) stored on ipsq_xopq_mphead.
* Note that if the phyint tied to `ipsq' is not using IPMP there will
* only be one IPSQ in the xop. Otherwise, there will be one IPSQ for
* each phyint in the group, including the IPMP meta-interface phyint.
*/
static mblk_t *
{
/*
* Grab all the locks we need in the defined order (ill_g_lock ->
* ipsq_lock -> ipx_lock); ill_g_lock is needed to use ipsq_next.
*/
/*
* Dequeue the next message associated with the current exclusive
* operation, if any.
*/
goto out;
}
goto empty;
/*
* The exclusive operation that is now being completed has
* requested a switch to a different xop. This happens
* when an interface joins or leaves an IPMP group. Joins
* happen through SIOCSLIFGROUPNAME (ip_sioctl_groupname()).
* Leaves happen via SIOCSLIFGROUPNAME, interface unplumb
* (phyint_free()), or interface plumb for an ill type
* not in the IPMP group (ip_rput_dlpi_writer()).
*
* Xop switches are not allowed on the IPMP meta-interface.
*/
/*
* We're switching back to our own xop, so we have two
* that we are leaving.
*
* First, pull ourselves out of the group ipsq list.
* This is safe since we're writer on ill_g_lock.
*/
/*
* Second, prepare to exit the group xop. The actual
* ipsq_exit() is done at the end of this function
* since we cannot hold any locks across ipsq_exit().
* Note that although we drop the group's ipx_lock, no
* threads can proceed since we're still ipx_writer.
*/
/*
* Third, set ipx to point to our own xop (which was
* inactive and therefore can be entered).
*/
} else {
/*
* We're switching from our own xop to a group xop.
* The requestor of the switch must ensure that the
* group xop cannot go away (e.g. by ensuring the
* phyint associated with the xop cannot go away).
*
* If we can become writer on our new xop, then we'll
* do the drain. Otherwise, the current writer of our
* new xop will do the drain when it exits.
*
* First, splice ourselves into the group IPSQ list.
* This is safe since we're writer on ill_g_lock.
*/
/*
* Second, exit our own xop, since it's now unused.
* This is safe since we've got the only reference.
*/
/*
* Third, set ipx to point to our new xop, and check
* if we can become writer on it. If we cannot, then
* the current writer will drain the IPSQ group when
* it exits. Our ipsq_xop is guaranteed to be stable
* because we're still holding ipsq_lock.
*/
goto out;
}
}
/*
* Fourth, become writer on our new ipx before we continue
* with the drain. Note that we never dropped ipsq_lock
* above, so no other thread could've raced with us to
* become writer first. Also, we're holding ipx_lock, so
* no other thread can examine the ipx right now.
*/
#ifdef DEBUG
#endif
}
do {
/*
* So that other operations operate on a consistent and
* complete phyint, a switch message on an IPSQ must be
* handled prior to any other operations on that IPSQ.
*/
goto out;
}
goto out;
}
/*
* There are no messages. Further, we are holding ipx_lock, hence no
* new messages can end up on any IPSQ in the xop.
*/
#ifdef DEBUG
#endif
out:
/*
* If we completely emptied the xop, then wake up any threads waiting
* to enter any of the IPSQ's associated with it.
*/
if (emptied) {
do {
continue;
}
/*
* Now that all locks are dropped, exit the IPSQ we left.
*/
return (mp);
}
/*
* Return completion status of previously initiated DLPI operations on
* ills in the purview of an ipsq.
*/
static boolean_t
{
ipsq_start = ipsq;
do {
/*
* The only current users of this function are ipsq_try_enter
* and ipsq_enter which have made sure that ipsq_writer is
* NULL before we reach here. ill_dlpi_pending is modified
* only by an ipsq writer
*/
/*
* phyi could be NULL if a phyint that is part of an
* IPMP group is being unplumbed. A more detailed
* comment is in ipmp_grp_update_kstats()
*/
return (B_FALSE);
return (B_FALSE);
}
return (B_TRUE);
}
/*
* Enter the ipsq corresponding to ill, by waiting synchronously till
* we can enter the ipsq exclusively. Unless 'force' is used, the ipsq
* will have to drain completely before ipsq_enter returns success.
* ipx_current_ipif will be set if some exclusive op is in progress,
* and the ipsq_exit logic will start the next enqueued op after
* completion of the current op. If 'force' is used, we don't wait
* for the enqueued ops. This is needed when a conn_close wants to
* enter the ipsq and abort an ioctl that is somehow stuck. Unplumb
* of an ill can also use this option. But we dont' use it currently.
*/
#define ENTER_SQ_WAIT_TICKS 100
{
/*
* Note that the relationship between ill and ipsq is fixed as long as
* the ill is not ILL_CONDEMNED. Holding ipsq_lock ensures the
* relationship between the IPSQ and xop cannot change. However,
* since we cannot hold ipsq_lock across the cv_wait(), it may change
* while we're waiting. We wait on ill_cv and rely on ipsq_exit()
* waking up all ills in the xop when it becomes available.
*/
for (;;) {
return (B_FALSE);
}
break;
} else {
}
}
ipx->ipx_reentry_cnt++;
#ifdef DEBUG
#endif
return (B_TRUE);
}
/*
* ipif_set_values() has a constraint that it cannot drop the ips_ill_g_lock
* across the call to the core interface ipsq_try_enter() and hence calls this
* function directly. This is explained more fully in ipif_set_values().
* In order to support the above constraint, ipsq_try_enter is implemented as
* a wrapper that grabs the ips_ill_g_lock and calls this function subsequently
*/
static ipsq_t *
{
/*
* lock ordering:
* ill_g_lock -> conn_lock -> ill_lock -> ipsq_lock -> ipx_lock.
*
* ipx of an ipsq can't change when ipsq_lock is held.
*/
GRAB_CONN_LOCK(q);
/*
* 1. Enter the ipsq if we are already writer and reentry is ok.
* (Note: If the caller does not specify reentry_ok then neither
* 'func' nor any of its callees must ever attempt to enter the ipsq
* again. Otherwise it can lead to an infinite loop
* 2. Enter the ipsq if there is no current writer and this attempted
* entry is part of the current operation
* 3. Enter the ipsq if there is no current writer and this is a new
* operation and the operation queue is empty and there is no
* operation currently in progress and if all previously initiated
* DLPI operations have completed.
*/
ipsq_dlpi_done(ipsq))))) {
/* Success. */
ipx->ipx_reentry_cnt++;
#ifdef DEBUG
#endif
return (ipsq);
}
return (NULL);
}
/*
* The ipsq_t (ipsq) is the synchronization data structure used to serialize
* certain critical operations like plumbing (i.e. most set ioctls), etc.
* There is one ipsq per phyint. The ipsq
* serializes exclusive ioctls issued by applications on a per ipsq basis in
* ipsq_xopq_mphead. It also protects against multiple threads executing in
* the ipsq. Responses from the driver pertain to the current ioctl (say a
* DL_BIND_ACK in response to a DL_BIND_REQ initiated as part of bringing
* up the interface) and are enqueued in ipx_mphead.
*
* If a thread does not want to reenter the ipsq when it is already writer,
* it must make sure that the specified reentry point to be called later
* when the ipsq is empty, nor any code path starting from the specified reentry
* point must never ever try to enter the ipsq again. Otherwise it can lead
* to an infinite loop. The reentry point ip_rput_dlpi_writer is an example.
* When the thread that is currently exclusive finishes, it (ipsq_exit)
* dequeues the requests waiting to become exclusive in ipx_mphead and calls
* the reentry point. When the list at ipx_mphead becomes empty ipsq_exit
* proceeds to dequeue the next ioctl in ipsq_xopq_mphead and start the next
* ioctl if the current ioctl has completed. If the current ioctl is still
* in progress it simply returns. The current ioctl could be waiting for
* a response from another module (the driver or could be waiting for
* and ipx_pending_ipif are set. ipx_current_ipif is set throughout the
* execution of the ioctl and ipsq_exit does not start the next ioctl unless
* ipx_current_ipif is NULL which happens only once the ioctl is complete and
* all associated DLPI operations have completed.
*/
/*
* Try to enter the IPSQ corresponding to `ipif' or `ill' exclusively (`ipif'
* and `ill' cannot both be specified). Returns a pointer to the entered IPSQ
* refholding it as necessary. If the IPSQ cannot be entered and `func' is
* non-NULL, then `func' will be called back with `q' and `mp' once the IPSQ
* can be entered. If `func' is NULL, then `q' and `mp' are ignored.
*/
ipsq_t *
{
/* Only 1 of ipif or ill can be specified */
return (ipsq);
}
/*
* Try to enter the IPSQ corresponding to `ill' as writer. The caller ensures
* ill is valid by refholding it if necessary; we will refrele. If the IPSQ
* cannot be entered, the mp is queued for completion.
*/
void
{
/*
* Drop the caller's refhold on the ill. This is safe since we either
* entered the IPSQ (and thus are exclusive), or failed to enter the
* IPSQ, in which case we return without accessing ill anymore. This
* is needed because func needs to see the correct refcount.
* e.g. removeif can work only then.
*/
}
}
/*
* Exit the specified IPSQ. If this is the final exit on it then drain it
* prior to exiting. Caller must be writer on the specified IPSQ.
*/
void
{
queue_t *q;
return;
}
for (;;) {
/*
* If we've changed to a new IPSQ, and the phyint associated
* with the old one has gone away, free the old IPSQ. Note
* that this cannot happen while the IPSQ is in a group.
*/
}
break;
/*
* If 'q' is an conn queue, it is valid, since we did a
* a refhold on the conn at the start of the ioctl.
* If 'q' is an ill queue, it is valid, since close of an
* ill will clean up its IPSQ.
*/
}
}
/*
* Used to start any igmp or mld timers that could not be started
* while holding ill_mcast_lock. The timers can't be started while holding
* the lock, since mld/igmp_start_timers may need to call untimeout()
* which can't be done while holding the lock which the timeout handler
* acquires. Otherwise
* there could be a deadlock since the timeout handlers
* mld_timeout_handler_per_ill/igmp_timeout_handler_per_ill also acquire
* ill_mcast_lock.
*/
void
{
int next;
}
/*
* Start the current exclusive operation on `ipsq'; associate it with `ipif'
* and `ioccmd'.
*/
void
{
/*
* Set IPIF_CHANGING on one or more ipifs associated with the
* current exclusive operation. IPIF_CHANGING prevents any new
* references to the ipif (so that the references will eventually
* drop to zero) and also prevents any "get" operations (e.g.,
* SIOCGLIFFLAGS) from being able to access the ipif until the
* operation has completed and the ipif is again in a stable state.
*
* For ioctls, IPIF_CHANGING is set on the ipif associated with the
* ioctl. For internal operations (where ioccmd is zero), all ipifs
* on the ill are marked with IPIF_CHANGING since it's unclear which
* ipifs will be affected.
*
* Note that SIOCLIFREMOVEIF is a special case as it sets
* IPIF_CONDEMNED internally after identifying the right ipif to
* operate on.
*/
switch (ioccmd) {
case SIOCLIFREMOVEIF:
break;
case 0:
break;
default:
}
}
/*
* Finish the current exclusive operation on `ipsq'. Usually, this will allow
* the next exclusive operation to begin once we ipsq_exit(). However, if
* pending DLPI operations remain, then we will wait for the queue to drain
* before allowing the next exclusive operation to begin. This ensures that
* DLPI operations from one exclusive operation are never improperly processed
* as part of a subsequent exclusive operation.
*/
void
{
/*
* For SIOCLIFREMOVEIF, the ipif has been already been blown away
* (but in that case, IPIF_CHANGING will already be clear and no
* pending DLPI messages can remain).
*/
if (ipx->ipx_current_ioctl == 0) {
} else {
}
}
ipx->ipx_current_ioctl = 0;
if (dlpi_pending == DL_PRIM_INVAL) {
}
}
/*
* The ill is closing. Flush all messages on the ipsq that originated
* from this ill. Usually there wont' be any messages on the ipsq_xopq_mphead
* for this ill since ipsq_enter could not have entered until then.
* New messages can't be queued since the CONDEMNED flag is set.
*/
static void
{
queue_t *q;
/*
* Flush any messages sent up by the driver.
*/
/* dequeue mp */
else
}
} else {
}
}
}
/*
* Parse an ifreq or lifreq struct coming down ioctls and refhold
* and return the associated ipif.
* Return value:
* Non zero: An error has occurred. ci may not be filled out.
* zero : ci is filled out with the ioctl cmd in ci.ci_name, and
* a held ipif in ci.ci_ipif.
*/
int
cmd_info_t *ci)
{
char *name;
} else {
if (zoneid == GLOBAL_ZONEID) {
/* global zone can access ipifs in all zones */
}
}
/* Has been checked in ip_wput_nondata */
/* This a old style SIOC[GS]IF* command */
/*
* Null terminate the string to protect against buffer
* overrun. String was generated by user code and may not
* be trusted.
*/
} else {
/* This a new style SIOC[GS]LIF* command */
/*
* Null terminate the string to protect against buffer
* overrun. String was generated by user code and may not
* be trusted.
*/
}
/*
* The ioctl will be failed if the ioctl comes down
* an conn stream
*/
/*
* Not an ill queue, return EINVAL same as the
* old error code.
*/
return (ENXIO);
}
} else {
/*
* Ensure that get ioctls don't see any internal state changes
* caused by set ioctls by deferring them if IPIF_CHANGING is
* set.
*/
!IAM_WRITER_IPIF(ipif)) {
if (IPIF_IS_CHANGING(ipif) &&
!IPIF_IS_CONDEMNED(ipif)) {
return (EINPROGRESS);
}
}
}
/*
* Old style [GS]IFCMD does not admit IPv6 ipif
*/
return (ENXIO);
}
name[0] == '\0') {
/*
* Handle a or a SIOC?IF* with a null name
* during plumb (on the ill queue before the I_PLINK).
*/
}
return (ENXIO);
return (0);
}
/*
* Return the total number of ipifs.
*/
static uint_t
{
if (IS_UNDER_IPMP(ill))
continue;
numifs++;
}
}
return (numifs);
}
/*
* Return the total number of ipifs.
*/
static uint_t
{
else
continue;
!(lifn_flags & LIFC_NOXMIT))
continue;
!(lifn_flags & LIFC_TEMPORARY))
continue;
if (((ipif->ipif_flags &
IPIF_DEPRECATED)) ||
IS_LOOPBACK(ill) ||
continue;
(zoneid != GLOBAL_ZONEID ||
!(lifn_flags & LIFC_ALLZONES)))
continue;
numifs++;
}
}
return (numifs);
}
{
/*
* ill_g_usesrc_lock protects ill_usesrc_grp_next, for example, some
* other thread may be trying to relink the ILLs in this usesrc group
* and adjusting the ill_usesrc_grp_next pointers
*/
if ((ill->ill_usesrc_ifindex == 0) &&
numifs++;
}
return (numifs);
}
/* Null values are passed in for ipif, sin, and ifreq */
/* ARGSUSED */
int
{
int *nump;
/* Existence of b_cont->b_cont checked in ip_wput_nondata */
return (0);
}
/* Null values are passed in for ipif, sin, and ifreq */
/* ARGSUSED */
int
{
/* Existence checked in ip_wput_nondata */
switch (lifn->lifn_family) {
case AF_UNSPEC:
case AF_INET:
case AF_INET6:
break;
default:
return (EAFNOSUPPORT);
}
return (0);
}
/* ARGSUSED */
int
{
struct sockaddr_in *sin;
ip1dbg(("ip_sioctl_get_ifconf"));
/* Existence verified in ip_wput_nondata */
/*
* The original SIOCGIFCONF passed in a struct ifconf which specified
* the user buffer address and length into which the list of struct
* ifreqs was to be copied. Since AT&T Streams does not seem to
* allow M_COPYOUT to be used in conjunction with I_STR IOCTLS,
* the SIOCGIFCONF operation was redefined to simply provide
* a large output buffer into which we are supposed to jam the ifreq
* array. The same ioctl command code was used, despite the fact that
* both the applications and the kernel code had to change, thus making
* it impossible to support both interfaces.
*
* For reasons not good enough to try to explain, the following
* algorithm is used for deciding what to do with one of these:
* If the IOCTL comes in as an I_STR, it is assumed to be of the new
* form with the output buffer coming down as the continuation message.
* If it arrives as a TRANSPARENT IOCTL, it is assumed to be old style,
* and we have to copy in the ifconf structure to find out how big the
* output buffer is and where to copy out to. Sure no problem...
*
*/
int numifs = 0;
/*
* Must be (better be!) continuation of a TRANSPARENT
* IOCTL. We just copied in the ifconf structure.
*/
/*
* Allocate a buffer to hold requested information.
*
* If ifc_len is larger than what is needed, we only
* allocate what we will use.
*
* If ifc_len is smaller than what is needed, return
* EINVAL.
*
* XXX: the ill_t structure can hava 2 counters, for
* v4 and v6 (not just ill_ipif_up_count) to store the
* number of interfaces for a device, so we don't need
* to count them here...
*/
if (ifc_bufsize > ifclen) {
/* old behaviour */
return (EINVAL);
} else {
}
}
return (ENOMEM);
}
/*
* the SIOCGIFCONF ioctl only knows about
* IPv4 addresses, so don't try to tell
* it about interfaces with IPv6-only
* addresses. (Last parm 'isv6' is B_FALSE)
*/
if (IS_UNDER_IPMP(ill))
continue;
continue;
/* old behaviour */
return (EINVAL);
} else {
goto if_copydone;
}
}
ifr++;
}
}
}
return (0);
}
/*
* Get the interfaces using the address hosted on the interface passed in,
* as a source adddress
*/
/* ARGSUSED */
int
{
int numlifs = 0;
struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
ipst = CONNQ_TO_IPST(q);
/* Existence verified in ip_wput_nondata */
/*
* Must be (better be!) continuation of a TRANSPARENT
* IOCTL. We just copied in the lifsrcof structure.
*/
return (EINVAL);
ip1dbg(("ip_sioctl_get_lifsrcof: no ipif for ifindex %d\n",
ifindex));
return (ENXIO);
}
/* Allocate a buffer to hold requested information */
/* The actual size needed is always returned in lifs_len */
/* If the amount we need is more than what is passed in, abort */
return (0);
}
return (ENOMEM);
}
/* ill_g_usesrc_lock protects ill_usesrc_grp_next */
break;
&ipif->ipif_v6net_mask);
} else {
}
lifr++;
}
return (0);
}
/* ARGSUSED */
int
{
int list;
int flags;
int numlifs = 0;
struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
ip1dbg(("ip_sioctl_get_lifconf"));
/* Existence verified in ip_wput_nondata */
/*
* An extended version of SIOCGIFCONF that takes an
* additional address family and flags field.
* AF_UNSPEC retrieve both IPv4 and IPv6.
* Unless LIFC_NOXMIT is specified the IPIF_NOXMIT
* interfaces are omitted.
* Similarly, IPIF_TEMPORARY interfaces are omitted
* unless LIFC_TEMPORARY is specified.
* If LIFC_EXTERNAL_SOURCE is specified, IPIF_NOXMIT,
* IPIF_NOLOCAL, PHYI_LOOPBACK, IPIF_DEPRECATED and
* not IPIF_UP interfaces are omitted. LIFC_EXTERNAL_SOURCE
* has priority over LIFC_NOXMIT.
*/
return (EINVAL);
/*
* Must be (better be!) continuation of a TRANSPARENT
* IOCTL. We just copied in the lifconf structure.
*/
switch (family) {
case AF_UNSPEC:
/*
* walk all ILL's.
*/
list = MAX_G_HEADS;
break;
case AF_INET:
/*
* walk only IPV4 ILL's.
*/
list = IP_V4_G_HEAD;
break;
case AF_INET6:
/*
* walk only IPV6 ILL's.
*/
list = IP_V6_G_HEAD;
break;
default:
return (EAFNOSUPPORT);
}
/*
* Allocate a buffer to hold requested information.
*
* If lifc_len is larger than what is needed, we only
* allocate what we will use.
*
* If lifc_len is smaller than what is needed, return
* EINVAL.
*/
if (lifc_bufsize > lifclen) {
return (EINVAL);
else
}
return (ENOMEM);
continue;
!(flags & LIFC_NOXMIT))
continue;
!(flags & LIFC_TEMPORARY))
continue;
if (((ipif->ipif_flags &
IPIF_DEPRECATED)) ||
IS_LOOPBACK(ill) ||
continue;
(zoneid != GLOBAL_ZONEID ||
!(flags & LIFC_ALLZONES)))
continue;
return (EINVAL);
} else {
goto lif_copydone;
}
}
lifr->lifr_addrlen =
&ipif->ipif_v6net_mask);
} else {
lifr->lifr_addrlen =
}
lifr++;
}
}
}
return (0);
}
static void
{
ipst = CONNQ_TO_IPST(q);
else
ipst = ILLQ_TO_IPST(q);
/* These two ioctls are I_STR only */
return;
}
/* The user passed us a NULL argument */
} else {
/*
* The user provided a table. The stream head
* may have copied in the user data in chunks,
* so make sure everything is pulled up
* properly.
*/
NULL) {
return;
}
}
}
case SIOCGIP6ADDRPOLICY:
int i;
/*
* We need to do an in-place shrink of the array
* to match the alignment attributes of the
* 32-bit ABI looking at it.
*/
/* LINTED: logical expression always true: op "||" */
for (i = 1; i < count; i++)
}
#endif
break;
case SIOCSIP6ADDRPOLICY:
/*
* We pass in the datamodel here so that the ip6_asp_replace()
* routine can handle converting from 32-bit to native formats
* where necessary.
*
* A better way to handle this might be to convert the inbound
* data structure here, and hang it off a new 'mp'; thus the
* ip6_asp_replace() logic would always be dealing with native
* format data structures..
*
* (An even simpler way to handle these ioctls is to just
* add a 32-bit trailing 'pad' field to the ip6_asp_t structure
* and just recompile everything that depends on it.)
*/
#endif
return;
}
}
static void
{
struct dstinforeq *dir;
int match_ire;
/*
* This ioctl is I_STR only, and must have a
* data mblk following the M_IOCTL mblk.
*/
return;
}
return;
}
}
cur += sizeof (struct dstinforeq)) {
/*
* ip_addr_scope_v6() and ip6_asp_lookup() handle
* v4 mapped addresses; ire_ftable_lookup_v6()
* and ip_select_source_v6() do not.
*/
if (isipv4) {
} else {
}
dir->dir_dreachable = 0;
/* move on to next dst addr */
continue;
}
continue;
}
/* With ipmp we most likely look at the ipmp ill here */
if (isipv4) {
ipif_flags = 0;
}
} else {
*saddr = ipv6_all_zeros;
ipif_flags = 0;
}
}
}
}
/*
* Check if this is an address assigned to this machine.
* Skips interfaces that are down by using ire checks.
* Translates mapped addresses to v4 addresses and then
* treats them as such, returning true if the v4 address
* associated with this mapped address is configured.
* Note: Applications will have to be careful what they do
* with the response; use of mapped addresses limits
* what can be done with the socket, especially with
* respect to socket options and ioctls - neither IPv4
* may be used.
*/
/* ARGSUSED */
int
{
struct sioc_addrreq *sia;
ip1dbg(("ip_sioctl_tmyaddr"));
ipst = CONNQ_TO_IPST(q);
/* Existence verified in ip_wput_nondata */
switch (sin->sin_family) {
case AF_INET6: {
v4_addr);
} else {
}
break;
}
case AF_INET: {
break;
}
default:
return (EAFNOSUPPORT);
}
} else {
}
return (0);
}
/*
* Check if this is an address assigned on-link i.e. neighbor,
* and makes sure it's reachable from the current zone.
* Returns true for my addresses as well.
* Translates mapped addresses to v4 addresses and then
* treats them as such, returning true if the v4 address
* associated with this mapped address is configured.
* Note: Applications will have to be careful what they do
* with the response; use of mapped addresses limits
* what can be done with the socket, especially with
* respect to socket options and ioctls - neither IPv4
* may be used.
*/
/* ARGSUSED */
int
{
struct sioc_addrreq *sia;
ip1dbg(("ip_sioctl_tonlink"));
ipst = CONNQ_TO_IPST(q);
/* Existence verified in ip_wput_nondata */
/*
* We check for IRE_ONLINK and exclude IRE_BROADCAST|IRE_MULTICAST
* to make sure we only look at on-link unicast address.
*/
switch (sin->sin_family) {
case AF_INET6: {
v4_addr);
}
} else {
if (!IN6_IS_ADDR_MULTICAST(&v6addr)) {
}
}
break;
}
case AF_INET: {
}
break;
}
default:
return (EAFNOSUPPORT);
}
}
return (0);
}
/*
* TBD: implement when kernel maintaines a list of site prefixes.
*/
/* ARGSUSED */
int
{
return (ENXIO);
}
/* ARP IOCTLs. */
/* ARGSUSED */
int
{
int err;
/* We have a chain - M_IOCTL-->MI_COPY_MBLK-->XARPREQ_MBLK */
/*
* Validate against user's link layer address length
* input and name and addr length limits.
*/
return (EINVAL);
}
} else {
/* We have a chain - M_IOCTL-->MI_COPY_MBLK-->ARPREQ_MBLK */
/*
* Theoretically, the sa_family could tell us what link
* layer type this operation is trying to deal with. By
* common usage AF_UNSPEC means ethernet. We'll assume
* any attempt to use the SIOC?ARP ioctls is for ethernet,
* for now. Our new SIOC*XARP ioctls can be used more
* generally.
*
* If the underlying media happens to have a non 6 byte
* operation will succeed.
*/
alength = 6;
return (EINVAL);
}
}
/* Translate ATF* flags to NCE* flags */
flags = 0;
if (arp_flags & ATF_AUTHORITY)
flags |= NCE_F_AUTHORITY;
flags |= NCE_F_PUBLISH;
/*
* IPMP ARP special handling:
*
* 1. Since ARP mappings must appear consistent across the group,
* prohibit changing ARP mappings on the underlying interfaces.
*
* 2. Since ARP mappings for IPMP data addresses are maintained by
* IP itself, prohibit changing them.
*
* 3. For proxy ARP, use a functioning hardware address in the group,
* provided one exists. If one doesn't, just add the entry as-is;
* ipmp_illgrp_refresh_arpent() will refresh it if things change.
*/
if (IS_UNDER_IPMP(ill)) {
return (EPERM);
}
case SIOCSARP:
case SIOCSXARP:
if (!ipmp_ill_is_active(proxy_ill))
}
/* FALLTHRU */
}
}
/*
* don't match across illgrp per case (1) and (2).
* XXX use IS_IPMP(ill) like ndp_sioc_update?
*/
case SIOCDARP:
case SIOCDXARP: {
/*
* Delete the NCE if any.
*/
break;
}
/* Don't allow changes to arp mappings of local addresses. */
if (NCE_MYADDR(ncec)) {
return (ENOTSUP);
}
/*
* Delete the nce_common which has ncec_ill set to ipmp_ill.
* This will delete all the nce entries on the under_ills.
*/
/*
* Once the NCE has been deleted, then the ire_dep* consistency
* mechanism will find any IRE which depended on the now
* condemned NCE (as part of sending packets).
* That mechanism handles redirects by deleting redirects
* that refer to UNREACHABLE nces.
*/
break;
}
case SIOCGARP:
case SIOCGXARP:
} else {
}
break;
case SIOCSARP:
case SIOCSXARP:
/* Don't allow changes to arp mappings of local addresses. */
return (ENOTSUP);
}
/* static arp entries will undergo NUD if ATF_PERM is not set */
flags |= NCE_F_STATIC;
if (!if_arp_ioctl) {
} else {
}
}
}
/*
* NCE_F_STATIC entries will be added in state ND_REACHABLE
* by nce_add_common()
*/
&nce);
err = 0;
}
}
flags);
break;
}
}
}
}
/*
* If we created an IPMP ARP entry, mark that we've notified ARP.
*/
}
/*
* Parse an [x]arpreq structure coming down SIOC[GSD][X]ARP ioctls, identify
* the associated sin and refhold and return the associated ipif via `ci'.
*/
int
cmd_info_t *ci)
{
struct sockaddr_dl *sdl;
/* ioctl comes down on a conn */
return (ENXIO);
/* Verified in ip_wput_nondata */
return (ENXIO);
return (EINVAL);
} else {
}
return (ENXIO);
return (ENXIO);
}
} else {
/*
* Either an SIOC[DGS]ARP or an SIOC[DGS]XARP with an sdl_nlen
* of 0: use the IP address to find the ipif. If the IP
* address is an IPMP test address, ire_ftable_lookup() will
* find the wrong ill, so we first do an ipif_lookup_addr().
*/
ipst);
return (ENXIO);
}
}
}
return (ENXIO);
}
return (0);
}
/*
* Link or unlink the illgrp on IPMP meta-interface `ill' depending on the
* value of `ioccmd'. While an illgrp is linked to an ipmp_grp_t, it is
* accessible from that ipmp_grp_t, which means SIOCSLIFGROUPNAME can look it
* up and thus an ill can join that illgrp.
*
* open()/close() primarily because close() is not allowed to fail or block
* forever. On the other hand, I_PUNLINK *can* fail, and there's no reason
* why anyone should ever need to I_PUNLINK an in-use IPMP stream. To ensure
* symmetric behavior (e.g., doing an I_PLINK after and I_PUNLINK undoes the
* I_PUNLINK) we defer linking to I_PLINK. Separately, we also fail attempts
* to I_LINK since I_UNLINK is optional and we'd end up in an inconsistent
* state if I_UNLINK didn't occur.
*
* once because of the way ifconfig works. However, it's OK to link the same
* illgrp more than once, or unlink an illgrp that's already unlinked.
*/
static int
{
int err;
switch (ioccmd) {
case I_LINK:
return (ENOTSUP);
case I_PLINK:
break;
case I_PUNLINK:
/*
* Require all UP ipifs be brought down prior to unlinking the
* illgrp so any associated IREs (and other state) is torched.
*/
return (EBUSY);
/*
* NOTE: We hold ipmp_lock across the unlink to prevent a race
* with an SIOCSLIFGROUPNAME request from an ill trying to
* join this group. Specifically: ills trying to join grab
* ipmp_lock and bump a "pending join" counter checked by
* ipmp_illgrp_unlink_grp(). During the unlink no new pending
* joins can occur (since we have ipmp_lock). Once we drop
* ipmp_lock, subsequent SIOCSLIFGROUPNAME requests will not
* find the illgrp (since we unlinked it) and will return
* EAFNOSUPPORT. This will then take them back through the
* IPMP meta-interface plumbing logic in ifconfig, and thus
* back through I_PLINK above.
*/
return (err);
default:
break;
}
return (0);
}
/*
* naking it. Note that the code is structured such that the link type,
* whether it's persistent or not, is treated equally. ifconfig(1M) and
* its clones use the persistent link, while pppd(1M) and perhaps many
* other daemons may use non-persistent link. When combined with some
* ill_t states, linking and unlinking lower streams may be used as
* indicators of dynamic re-plumbing events [see PSARC/1999/348].
*/
/* ARGSUSED */
void
{
int err = 0;
if (err == EINPROGRESS)
return;
done:
if (err == 0)
else
/* Conn was refheld in ip_sioctl_copyin_setup */
if (CONN_Q(q))
}
/*
* Process I_{P}LINK and I_{P}UNLINK requests named by `ioccmd' and pointed to
* by `mp' and `li' for the IP module stream (if li->q_bot is in fact an IP
* module stream). If `doconsist' is set, then do the extended consistency
* checks requested by ifconfig(1M) and (atomically) set ill_muxid here.
* Returns zero on success, EINPROGRESS if the operation is still pending, or
* an error code on failure.
*/
static int
{
int err = 0;
const char *name;
/*
* Walk the lower stream to verify it's the IP module stream.
* The IP module is identified by its name, wput function,
* and non-NULL q_next. STREAMS ensures that the lower stream
* (li->l_qbot) will not vanish until this ioctl completes.
*/
break;
}
break;
}
}
/*
* If this isn't an IP module stream, bail.
*/
return (0);
if (!is_ip) {
return (0);
} else {
}
if (!is_ip)
return (EINPROGRESS);
}
}
if (!is_ip) {
/*
* Plumbing has to be done with IP plumbed first, arp
* second, but here we have arp being plumbed first.
*/
return (EINVAL);
}
}
if (!is_ip) {
goto done;
}
goto done;
/*
* As part of I_{P}LINKing, stash the number of downstream modules and
* the read queue of the module immediately below IP in the ill.
* These are used during the capability negotiation below.
*/
ill->ill_lmod_cnt = 0;
ill->ill_lmod_cnt++;
}
/*
* Mark the ipsq busy until the capability operations initiated below
* returns, but the capability operation may complete asynchronously
* much later.
*/
/*
* If there's at least one up ipif on this ill, then we're bound to
* the underlying driver via DLPI. In that case, renegotiate
* capabilities to account for any possible change in modules
* interposed between IP and the driver.
*/
if (ill->ill_ipif_up_count > 0) {
if (islink)
else
}
done:
if (entered_ipsq)
return (err);
}
/*
* Search the ioctl command in the ioctl tables and return a pointer
* to the ioctl command information. The ioctl command tables are
* static and fully populated at compile time.
*/
ip_sioctl_lookup(int ioc_cmd)
{
int index;
if (ioc_cmd == IPI_DONTCARE)
return (NULL);
/*
* Do a 2 step search. First search the indexed table
* based on the least significant byte of the ioctl cmd.
* If we don't find a match, then search the misc table
* serially.
*/
if (index < ip_ndx_ioctl_count) {
/* Found a match in the ndx table */
return (ipip);
}
}
/* Search the misc table */
/* Found a match in the misc table */
return (ipip);
}
return (NULL);
}
/*
* Wrapper function for resuming deferred ioctl processing
* Used for SIOCGDSTINFO, SIOCGIP6ADDRPOLICY, SIOCGMSFILTER,
* SIOCSMSFILTER, SIOCGIPMSFILTER, and SIOCSIPMSFILTER currently.
*/
/* ARGSUSED */
void
void *dummy_arg)
{
ip_sioctl_copyin_setup(q, mp);
}
/*
* ip_sioctl_copyin_setup is called by ip_wput_nondata with any M_IOCTL message
* that arrives. Most of the IOCTLs are "socket" IOCTLs which we handle
* in either I_STR or TRANSPARENT form, using the mi_copy facility.
* We establish here the size of the block to be copied in. mi_copyin
* arranges for this to happen, an processing continues in ip_wput_nondata with
* an M_IOCDATA message.
*/
void
{
int copyin_size;
if (CONN_Q(q))
ipst = CONNQ_TO_IPST(q);
else
ipst = ILLQ_TO_IPST(q);
/*
* The ioctl is not one we understand or own.
* Pass it along to be processed down stream,
* if this is a module instance of IP, else nak
* the ioctl.
*/
goto nak;
} else {
return;
}
}
/*
* If this is deferred, then we will do all the checks when we
* come back.
*/
return;
}
/*
* Only allow a very small subset of IP ioctls on this stream if
* IP is a module and not a driver. Allowing ioctls to be processed
* in this case may cause assert failures or data corruption.
* Typically G[L]IFFLAGS, SLIFNAME/IF_UNITSEL are the only few
* ioctls allowed on an IP module stream, after which this stream
* normally becomes a multiplexor (at which time the stream head
* will fail all ioctls).
*/
goto nak;
}
/* Make sure we have ioctl data to process. */
goto nak;
/*
* Prefer dblk credential over ioctl credential; some synthesized
* ioctls have kcred set because there's no way to crhold()
* a credential in some contexts. (ioc_cr is not crfree() by
* the framework; the caller of ioctl needs to hold the reference
* for the duration of the call).
*/
/* Make sure normal users don't send down privileged ioctls */
/* We checked the privilege earlier but log it here */
return;
}
/*
* The ioctl command tables can only encode fixed length
* ioctl data. If the length is variable, the table will
* encode the length as zero. Such special cases are handled
* below in the switch.
*/
if (ipip->ipi_copyin_size != 0) {
return;
}
case O_SIOCGIFCONF:
case SIOCGIFCONF:
/*
* This IOCTL is hilarious. See comments in
* ip_sioctl_get_ifconf for the story.
*/
else
return;
case O_SIOCGLIFCONF:
case SIOCGLIFCONF:
return;
case SIOCGLIFSRCOF:
return;
case SIOCGIP6ADDRPOLICY:
return;
case SIOCSIP6ADDRPOLICY:
return;
case SIOCGDSTINFO:
ip_sioctl_dstinfo(q, mp);
return;
case I_PLINK:
case I_PUNLINK:
case I_LINK:
case I_UNLINK:
/*
* We treat non-persistent link similarly as the persistent
* link case, in terms of plumbing/unplumbing, as well as
* dynamic re-plumbing events indicator. See comments
* in ip_sioctl_plink() for more.
*
* Request can be enqueued in the 'ipsq' while waiting
* to become exclusive. So bump up the conn ref.
*/
if (CONN_Q(q))
CONN_INC_REF(Q_TO_CONN(q));
return;
case ND_GET:
case ND_SET:
/*
* Use of the nd table requires holding the reader lock.
* the writer lock.
*/
return;
}
/*
* We don't understand this subioctl of ND_GET / ND_SET.
* Maybe intended for some driver / module below us
*/
if (q->q_next) {
} else {
}
return;
case IP_IOCTL:
ip_wput_ioctl(q, mp);
return;
case SIOCILB:
/* The ioctl length varies depending on the ILB command. */
if (copyin_size < sizeof (ilb_cmd_t))
goto nak;
return;
default:
}
nak:
}
}
static void
{
int x_arp_ioctl = B_FALSE;
int *flagsp;
} else {
}
/*
* We're done if this is not an SIOCG{X}ARP
*/
if (x_arp_ioctl) {
return;
}
}
/*
* flag, or if this is one of my addresses print "permanent"
*/
*flagsp |= ATF_AUTHORITY;
if (flags & NCE_F_NONUD)
if (flags & NCE_F_PUBLISH)
}
}
/*
* Create a new logical interface. If ipif_id is zero (i.e. not a logical
* interface) create the next available logical interface for this
* physical interface.
* If ipif is NULL (i.e. the lookup didn't find one) attempt to create an
* ipif with the specified name.
*
* If the address family is not AF_UNSPEC then set the address as well.
*
* If ip_sioctl_addr returns EINPROGRESS then the ioctl (the copyout)
* is completed when the DL_BIND_ACK arrive in ip_rput_dlpi_writer.
*
* Executed as a writer on the ill.
* So no lock is needed to traverse the ipif chain, or examine the
* phyint flags.
*/
/* ARGSUSED */
int
{
char *name;
char *endp;
char *cp;
int namelen;
long id;
int err = 0;
ip1dbg(("ip_sioctl_addif\n"));
/* Existence of mp1 has been checked in ip_wput_nondata */
/*
* Null terminate the string to protect against buffer
* overrun. String was generated by user code and may not
* be trusted.
*/
if (namelen == 0)
return (EINVAL);
/*
* Allow creating lo0 using SIOCLIFADDIF.
* can't be any other writer thread. So can pass null below
* for the last 4 args to ipif_lookup_name.
*/
/* Prevent any further action */
return (ENOBUFS);
} else if (!exists) {
/* We created the ipif now and as writer */
return (0);
} else {
}
} else {
/* Look for a colon in the name. */
if (*cp == IPIF_SEPARATOR_CHAR) {
/*
* Reject any non-decimal aliases for plumbing
* of logical interfaces. Aliases with leading
* zeroes are also rejected as they introduce
* ambiguity in the naming of the interfaces.
* Comparing with "0" takes care of all such
* cases.
*/
return (EINVAL);
return (EINVAL);
}
*cp = '\0';
break;
}
}
if (found_sep)
return (ENXIO);
}
B_TRUE);
/*
* Release the refhold due to the lookup, now that we are excl
* or we are just returning
*/
return (EINPROGRESS);
/* We are now exclusive on the IPSQ */
if (found_sep) {
/* Now see if there is an IPIF with this unit number. */
goto done;
}
}
}
/*
* We use IRE_LOCAL for lo0:1 etc. for "receive only" use
* of lo0. Plumbing for lo0:0 happens in ipif_lookup_on_name()
* instead.
*/
goto done;
}
/* Return created name with ioctl */
/* Set address */
}
done:
return (err);
}
/*
* Remove an existing logical interface. If ipif_id is zero (i.e. not a logical
* interface) delete it based on the IP address (on this physical interface).
* Otherwise delete it based on the ipif_id.
* Also, special handling to allow a removeif of lo0.
*/
/* ARGSUSED */
int
{
ipst = CONNQ_TO_IPST(q);
ip1dbg(("ip_sioctl_remove_if(%s:%u %p)\n",
/*
* Special case for unplumbing lo0 (the loopback physical interface).
* If unplumbing lo0, the incoming address structure has been
* initialized to all zeros. When unplumbing lo0, all its logical
* interfaces must be removed too.
*
* Note that this interface may be called to remove a specific
* loopback logical interface (eg, lo0:1). But in that case
* ipif->ipif_id != 0 so that the code path for that case is the
* same as any other interface (meaning it skips the code directly
* below).
*/
/*
* Mark it condemned. No new ref. will be made to ill.
*/
}
/* unplumb the loopback interface */
/* Are any references to this ill active */
if (ill_is_freeable(ill)) {
return (0);
}
if (success)
return (EINPROGRESS);
else
return (EINTR);
}
}
/* Find based on address */
return (EAFNOSUPPORT);
/* We are a writer, so we should be able to lookup */
ipst);
} else {
return (EAFNOSUPPORT);
/* We are a writer, so we should be able to lookup */
ipst);
}
return (EADDRNOTAVAIL);
}
/*
* It is possible for a user to send an SIOCLIFREMOVEIF with
* lifr_name of the physical interface but with an ip address
* lifr_addr of a logical interface plumbed over it.
* So update ipx_current_ipif now that ipif points to the
* correct one.
*/
/* This is a writer */
}
/*
* Can not delete instance zero since it is tied to the ill.
*/
return (EBUSY);
/* Are any references to this ipif active */
if (ipif_is_freeable(ipif)) {
(void) ipif_down_tail(ipif);
return (0);
}
if (success)
return (EINPROGRESS);
else
return (EINTR);
}
/*
* Restart the removeif ioctl. The refcnt has gone down to 0.
* The ipif is already condemned. So can't find it thru lookups.
*/
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_removeif_restart(%s:%u %p)\n",
return (0);
}
(void) ipif_down_tail(ipif);
return (0);
}
/*
* Set the local interface address.
* Allow an address of all zero when the interface is down.
*/
/* ARGSUSED */
int
{
int err = 0;
ip1dbg(("ip_sioctl_addr(%s:%u %p)\n",
return (EAFNOSUPPORT);
/*
* Enforce that true multicast interfaces have a link-local
* address for logical unit 0.
*/
!IN6_IS_ADDR_LINKLOCAL(&v6addr)) {
return (EADDRNOTAVAIL);
}
/*
* up interfaces shouldn't have the unspecified address
* unless they also have the IPIF_NOLOCAL flags set and
* have a subnet assigned.
*/
return (EADDRNOTAVAIL);
}
return (EADDRNOTAVAIL);
} else {
return (EAFNOSUPPORT);
/* Allow 0 as the local address. */
return (EADDRNOTAVAIL);
}
/*
* Even if there is no change we redo things just to rerun
* ipif_set_default.
*/
/*
* Setting a new local address, make sure
* we have net and subnet bcast ire's for
* the old address if we need them.
*/
/*
* If the interface is already marked up,
* we call ipif_down which will take care
* of ditching any IREs that have been set
* up based on the old interface address.
*/
if (err == EINPROGRESS)
return (err);
(void) ipif_down_tail(ipif);
need_up = 1;
}
return (err);
}
int
{
int sinlen;
int err = 0;
ip1dbg(("ip_sioctl_addr_tail(%s:%u %p)\n",
/* Must cancel any pending timer before taking the ill_lock */
if (ipif->ipif_recovery_id != 0)
ipif->ipif_recovery_id = 0;
sinlen = sizeof (struct sockaddr_in6);
} else {
sinlen = sizeof (struct sockaddr_in);
}
ipif->ipif_addr_ready = 0;
/*
* If the interface was previously marked as a duplicate, then since
* we've now got a "new" address, it should no longer be considered a
* duplicate -- even if the "new" address is the same as the old one.
* Note that if all ipifs are down, we may have a pending ARP down
* event to handle. This is because we want to recover from duplicates
* and thus delay tearing down ARP until the duplicates have been
* removed or disabled.
*/
need_arp_down = !need_up;
}
}
/*
* If we've just manually set the IPv6 link-local address (0th ipif),
* tag the ill so that future updates to the interface ID don't result
* in this address getting automatically reconfigured from under the
* administrator.
*/
/*
* When publishing an interface address change event, we only notify
* the event listeners of the new address. It is assumed that if they
* actively care about the addresses assigned that they will have
* already discovered the previous address assigned (if there was one.)
*
* Don't attach nic event message for SIOCLIFADDIF ioctl.
*/
}
if (need_up) {
/*
* Now bring the interface back up. If this
* is the only IPIF for the ILL, ipif_up
* will have to re-bind to the device, so
* we may get back EINPROGRESS, in which
* case, this IOCTL will get completed in
* ip_rput_dlpi when we see the DL_BIND_ACK.
*/
} else {
/* Perhaps ilgs should use this ill */
}
if (need_dl_down)
(void) ipif_arp_down(ipif);
/*
* The default multicast interface might have changed (for
* instance if the IPv6 scope of the address changed)
*/
return (err);
}
/*
* Restart entry point to restart the address set operation after the
* refcounts have dropped to zero.
*/
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_addr_restart(%s:%u %p)\n",
(void) ipif_down_tail(ipif);
}
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_get_addr(%s:%u %p)\n",
/*
* The net mask and address can't change since we have a
* reference to the ipif. So no lock is necessary.
*/
lifr->lifr_addrlen =
} else {
lifr->lifr_addrlen =
}
}
return (0);
}
/*
* Set the destination address for a pt-pt interface.
*/
/* ARGSUSED */
int
{
int err = 0;
ip1dbg(("ip_sioctl_dstaddr(%s:%u %p)\n",
return (EAFNOSUPPORT);
return (EADDRNOTAVAIL);
} else {
return (EAFNOSUPPORT);
return (EADDRNOTAVAIL);
}
return (0); /* No change */
/*
* If the interface is already marked up,
* we call ipif_down which will take care
* of ditching any IREs that have been set
* up based on the old pp dst address.
*/
if (err == EINPROGRESS)
return (err);
(void) ipif_down_tail(ipif);
}
/*
* could return EINPROGRESS. If so ioctl will complete in
* ip_rput_dlpi_writer
*/
return (err);
}
static int
{
int err = 0;
/* Must cancel any pending timer before taking the ill_lock */
if (ipif->ipif_recovery_id != 0)
ipif->ipif_recovery_id = 0;
} else {
}
/* Set point to point destination address. */
/*
* Allow this as a means of creating logical
* pt-pt interfaces on top of e.g. an Ethernet.
* XXX Undocumented HACK for testing.
* pt-pt interfaces are created with NUD disabled.
*/
}
/*
* If the interface was previously marked as a duplicate, then since
* we've now got a "new" address, it should no longer be considered a
* duplicate -- even if the "new" address is the same as the old one.
* Note that if all ipifs are down, we may have a pending ARP down
* event to handle.
*/
need_arp_down = !need_up;
}
}
/*
* If we've just manually set the IPv6 destination link-local address
* (0th ipif), tag the ill so that future updates to the destination
* interface ID (as can happen with interfaces over IP tunnels) don't
* result in this address getting automatically reconfigured from
* under the administrator.
*/
/* Set the new address. */
/* Make sure subnet tracks pp_dst */
if (need_up) {
/*
* Now bring the interface back up. If this
* is the only IPIF for the ILL, ipif_up
* will have to re-bind to the device, so
* we may get back EINPROGRESS, in which
* case, this IOCTL will get completed in
* ip_rput_dlpi when we see the DL_BIND_ACK.
*/
}
if (need_dl_down)
(void) ipif_arp_down(ipif);
return (err);
}
/*
* Restart entry point to restart the dstaddress set operation after the
* refcounts have dropped to zero.
*/
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_dstaddr_restart(%s:%u %p)\n",
(void) ipif_down_tail(ipif);
}
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_get_dstaddr(%s:%u %p)\n",
/*
* Get point to point destination address. The addresses can't
* change since we hold a reference to the ipif.
*/
return (EADDRNOTAVAIL);
} else {
}
return (0);
}
/*
* Check which flags will change by the given flags being set
* silently ignore flags which userland is not allowed to control.
* (Because these flags may change between SIOCGLIFFLAGS and
* SIOCSLIFFLAGS, and that's outside of userland's control,
* we need to silently ignore them rather than fail.)
*/
static void
{
}
/*
* Set interface flags. Many flags require special handling (e.g.,
* bringing the interface down); see below for details.
*
* NOTE : We really don't enforce that ipif_id zero should be used
* for setting any flags other than IFF_LOGINT_FLAGS. This
* is because applications generally does SICGLIFFLAGS and
* ORs in the new flags (that affects the logical) and does a
* SIOCSLIFFLAGS. Thus, "flags" below could contain bits other
* than IFF_LOGINT_FLAGS. One could check whether "turn_on" - the
* flags that will be turned on is correct with respect to
* ipif_id 0. For backward compatibility reasons, it is not done.
*/
/* ARGSUSED */
int
{
int err = 0;
ip1dbg(("ip_sioctl_flags(%s:%u %p)\n",
} else {
}
/*
* Have the flags been set correctly until now?
*/
/*
* Compare the new flags to the old, and partition
* into those coming on and those going off.
* For the 16 bit command keep the bits above bit 16 unchanged.
*/
/*
* Explicitly fail attempts to change flags that are always invalid on
* an IPMP meta-interface.
*/
return (EINVAL);
return (0); /* No change */
/*
* All test addresses must be IFF_DEPRECATED (to ensure source address
* selection avoids them) -- so force IFF_DEPRECATED on, and do not
* allow it to be turned off.
*/
return (EINVAL);
return (EINVAL);
/*
* Only vrrp control socket is allowed to change IFF_UP and
* IFF_NOACCEPT flags when IFF_VRRP is set.
*/
if (!connp->conn_isvrrp)
return (EINVAL);
}
/*
* The IFF_NOACCEPT flag can only be set on an IFF_VRRP IP address by
* VRRP control socket.
*/
return (EINVAL);
}
if (turn_on & IFF_NOFAILOVER) {
flags |= IFF_DEPRECATED;
}
/*
* On underlying interfaces, only allow applications to manage test
* addresses -- otherwise, they may get confused when the address
* moves as part of being brought up. Likewise, prevent an
* application-managed test address from being converted to a data
* address. To prevent migration of administratively up addresses in
* the kernel, we don't allow them to be converted either.
*/
if (IS_UNDER_IPMP(ill)) {
return (EINVAL);
if ((turn_off & IFF_NOFAILOVER) &&
return (EINVAL);
}
/*
* Only allow IFF_TEMPORARY flag to be set on
* IPv6 interfaces.
*/
return (EINVAL);
/*
* cannot turn off IFF_NOXMIT on VNI interfaces.
*/
return (EINVAL);
/*
* Don't allow the IFF_ROUTER flag to be turned on on loopback
* interfaces. It makes no sense in that context.
*/
return (EINVAL);
/*
* For IPv6 ipif_id 0, don't allow the interface to be up without
* a link local address if IFF_NOLOCAL or IFF_ANYCAST are not set.
* If the link local address isn't set, and can be set, it will get
* set later on in this function.
*/
if (ipif_cant_setlinklocal(ipif))
return (EINVAL);
}
/*
* If we modify physical interface flags, we'll potentially need to
* send up two routing socket messages for the changes (one for the
* IPv4 ill, and another for the IPv6 ill). Note that here.
*/
/*
* All functioning PHYI_STANDBY interfaces start life PHYI_INACTIVE
* (otherwise, we'd immediately use them, defeating standby). Also,
* since PHYI_INACTIVE has a separate meaning when PHYI_STANDBY is not
* set, don't allow PHYI_STANDBY to be set if PHYI_INACTIVE is already
* set, and clear PHYI_INACTIVE if PHYI_STANDBY is being cleared. We
* also don't allow PHYI_STANDBY if VNI is enabled since its semantics
* will not be honored.
*/
if (turn_on & PHYI_STANDBY) {
/*
* No need to grab ill_g_usesrc_lock here; see the
* synchronization notes in ip.c.
*/
return (EINVAL);
if (!(flags & PHYI_FAILED)) {
flags |= PHYI_INACTIVE;
turn_on |= PHYI_INACTIVE;
}
}
if (turn_off & PHYI_STANDBY) {
flags &= ~PHYI_INACTIVE;
}
/*
* PHYI_FAILED and PHYI_INACTIVE are mutually exclusive; fail if both
* would end up on.
*/
(PHYI_FAILED | PHYI_INACTIVE))
return (EINVAL);
/*
* If ILLF_ROUTER changes, we need to change the ip forwarding
* status of the interface.
*/
/*
* If the interface is not UP and we are not going to
* bring it UP, record the flags and return. When the
* interface comes UP later, the right actions will be
* taken.
*/
/* Record new flags in their respective places. */
/*
* PHYI_FAILED, PHYI_INACTIVE, and PHYI_OFFLINE are all the
* same to the kernel: if any of them has been set by
* userland, the interface cannot be used for data traffic.
*/
/*
* It's possible the ill is part of an "anonymous"
* IPMP group rather than a real group. In that case,
* there are no other interfaces in the group and thus
* no need to call ipmp_phyint_refresh_active().
*/
if (IS_UNDER_IPMP(ill))
}
if (phyint_flags_modified) {
}
}
}
/* The default multicast interface might have changed */
return (0);
} else if (set_linklocal) {
if (set_linklocal)
}
/*
* Disallow IPv6 interfaces coming up that have the unspecified address,
* or point-to-point interfaces with an unspecified destination. We do
* allow the address to be unspecified for IPIF_NOLOCAL interfaces that
* have a subnet assigned, which is how in.ndpd currently manages its
* onlink prefix list when no addresses are configured with those
* prefixes.
*/
return (EINVAL);
}
/*
* Prevent IPv4 point-to-point interfaces with a 0.0.0.0 destination
* from being brought up.
*/
return (EINVAL);
}
/*
* If we are going to change one or more of the flags that are
* IPIF_UP, IPIF_DEPRECATED, IPIF_NOXMIT, IPIF_NOLOCAL, ILLF_NOARP,
* ILLF_NONUD, IPIF_PRIVATE, IPIF_ANYCAST, IPIF_PREFERRED, and
* IPIF_NOFAILOVER, we will take special action. This is
* done by bring the ipif down, changing the flags and bringing
* it back up again. For IPIF_NOFAILOVER, the act of bringing it
* back up will trigger the address to be moved.
*
* If we are going to change IFF_NOACCEPT, we need to bring
* all the ipifs down then bring them up again. The act of
* bringing all the ipifs back up will trigger the local
*
* Note that ILLF_NOACCEPT is always set separately from the
* other flags.
*/
IPIF_NOFAILOVER)) {
/*
* ipif_down() will ire_delete bcast ire's for the subnet,
* while the ire_identical_ref tracks the case of IRE_BROADCAST
* entries shared between multiple ipifs on the same subnet.
*/
}
if (err == EINPROGRESS)
return (err);
(void) ipif_down_tail(ipif);
/*
* If we can quiesce the ill, then continue. If not, then
* ip_sioctl_flags_tail() will be called from
* ipif_ill_refrele_tail().
*/
if (!ill_is_quiescent(ill)) {
}
}
}
static int
{
int err = 0;
ip1dbg(("ip_sioctl_flags_tail(%s:%u)\n",
/*
* IFF_UP is handled separately.
*/
/*
* Now we change the flags. Track current value of
* other flags in their respective places.
*/
}
if (set_linklocal)
(void) ipif_setlinklocal(ipif);
/*
* PHYI_FAILED, PHYI_INACTIVE, and PHYI_OFFLINE are all the same to
* the kernel: if any of them has been set by userland, the interface
* cannot be used for data traffic.
*/
/*
* It's possible the ill is part of an "anonymous" IPMP group
* rather than a real group. In that case, there are no other
* interfaces in the group and thus no need for us to call
* ipmp_phyint_refresh_active().
*/
if (IS_UNDER_IPMP(ill))
}
/*
* If the ILLF_NOACCEPT flag is changed, bring up all the
* ipifs that were brought down.
*
* The routing sockets messages are sent as the result
* of ill_up_ipifs(), further, SCTP's IPIF list was updated
* as well.
*/
/*
* XXX ipif_up really does not know whether a phyint flags
* was modified or not. So, it sends up information on
* only one routing sockets message. As we don't bring up
* the interface and also set PHYI_ flags simultaneously
* it should be okay.
*/
} else {
/*
* Make sure routing socket sees all changes to the flags.
* ipif_up_done* handles this when we use ipif_up.
*/
if (phyint_flags_modified) {
}
}
} else {
}
/*
* Update the flags in SCTP's IPIF list, ipif_up() will do
* this in need_up case.
*/
}
/* The default multicast interface might have changed */
return (err);
}
/*
* Restart the flags operation now that the refcounts have dropped to zero.
*/
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_flags_restart(%s:%u %p)\n",
/* cast to uint16_t prevents unwanted sign extension */
} else {
}
/*
* If this function call is a result of the ILLF_NOACCEPT flag
* change, do not call ipif_down_tail(). See ip_sioctl_flags().
*/
(void) ipif_down_tail(ipif);
}
/*
* Can operate on either a module or a driver queue.
*/
/* ARGSUSED */
int
{
/*
* Has the flags been set correctly till now ?
*/
ip1dbg(("ip_sioctl_get_flags(%s:%u %p)\n",
/*
* Need a lock since some flags can be set even when there are
* references to the ipif.
*/
/* Get interface flags (low 16 only). */
} else {
/* Get interface flags. */
}
return (0);
}
/*
* We allow the MTU to be set on an ILL, but not have it be different
* for different IPIFs since we don't actually send packets on IPIFs.
*/
/* ARGSUSED */
int
{
int mtu;
int ip_min_mtu;
} else {
}
/* Only allow for logical unit zero i.e. not on "bge0:17" */
return (EINVAL);
else
return (EINVAL);
}
/*
* The dce and fragmentation code can handle changes to ill_mtu
* concurrent with sending/fragmenting packets.
*/
/*
* Make sure all dce_generation checks find out
* that ill_mtu has changed.
*/
/* Update the MTU in SCTP's list */
return (0);
}
/* Get interface MTU. */
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_get_mtu(%s:%u %p)\n",
/*
* We allow a get on any logical interface even though the set
* can only be done on logical unit 0.
*/
} else {
}
return (0);
}
/* Set interface broadcast address. */
/* ARGSUSED2 */
int
{
return (EADDRNOTAVAIL);
return (EAFNOSUPPORT);
/*
* If we are already up, make sure the new
* broadcast address makes sense. If it does,
* there should be an IRE for it already.
*/
return (EINVAL);
} else {
}
}
/*
* Changing the broadcast addr for this ipif. Since the IRE_BROADCAST
* needs to already exist we never need to change the set of
* IRE_BROADCASTs when we are UP.
*/
return (0);
}
/* Get interface broadcast address. */
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_get_brdaddr(%s:%u %p)\n",
return (EADDRNOTAVAIL);
/* IPIF_BROADCAST not possible with IPv6 */
return (0);
}
/*
* This routine is called to handle the SIOCS*IFNETMASK IOCTL.
*/
/* ARGSUSED */
int
{
int err = 0;
ip1dbg(("ip_sioctl_netmask(%s:%u %p)\n",
return (EAFNOSUPPORT);
} else {
return (EAFNOSUPPORT);
}
/*
* No big deal if the interface isn't already up, or the mask
* isn't really changing, or this is pt-pt.
*/
}
return (0);
}
/*
* Make sure we have valid net and subnet broadcast ire's
* for the old netmask, if needed by other logical interfaces.
*/
if (err == EINPROGRESS)
return (err);
(void) ipif_down_tail(ipif);
return (err);
}
static int
{
int err = 0;
ip1dbg(("ip_sioctl_netmask_tail(%s:%u %p)\n",
} else {
}
}
/*
* The interface must be DL_BOUND if this packet has to
* go out on the wire. Since we only go through a logical
* down and are bound with the driver during an internal
*/
/* Potentially broadcast an address mask reply. */
}
}
return (err);
}
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_netmask_restart(%s:%u %p)\n",
(void) ipif_down_tail(ipif);
}
/* Get interface net mask. */
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_get_netmask(%s:%u %p)\n",
/*
* net mask can't change since we have a reference to the ipif.
*/
lifr->lifr_addrlen =
} else {
lifr->lifr_addrlen =
}
}
return (0);
}
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_metric(%s:%u %p)\n",
/*
* Since no applications should ever be setting metrics on underlying
* interfaces, we explicitly fail to smoke 'em out.
*/
return (EINVAL);
/*
* Set interface metric. We don't use this for
* anything but we keep track of it in case it is
* important to routing applications or such.
*/
} else {
}
return (0);
}
/* ARGSUSED */
int
{
/* Get interface metric. */
ip1dbg(("ip_sioctl_get_metric(%s:%u %p)\n",
} else {
}
return (0);
}
/* ARGSUSED */
int
{
int arp_muxid;
ip1dbg(("ip_sioctl_muxid(%s:%u %p)\n",
/*
* Set the muxid returned from I_PLINK.
*/
} else {
}
return (0);
}
/* ARGSUSED */
int
{
int arp_muxid = 0;
ip1dbg(("ip_sioctl_get_muxid(%s:%u %p)\n",
/*
* Get the muxid saved in ill for I_PUNLINK.
*/
} else {
}
return (0);
}
/*
* Set the subnet prefix. Does not modify the broadcast address.
*/
/* ARGSUSED */
int
{
int err = 0;
int addrlen;
ip1dbg(("ip_sioctl_subnet(%s:%u %p)\n",
return (EAFNOSUPPORT);
return (EADDRNOTAVAIL);
} else {
return (EAFNOSUPPORT);
return (EADDRNOTAVAIL);
/* Add 96 bits */
}
return (EINVAL);
/* Check if bits in the address is set past the mask */
return (EINVAL);
return (0); /* No change */
/*
* If the interface is already marked up,
* we call ipif_down which will take care
* of ditching any IREs that have been set
* up based on the old interface address.
*/
if (err == EINPROGRESS)
return (err);
(void) ipif_down_tail(ipif);
}
return (err);
}
static int
{
int err = 0;
ip1dbg(("ip_sioctl_subnet_tail(%s:%u %p)\n",
/* Set the new address. */
}
if (need_up) {
/*
* Now bring the interface back up. If this
* is the only IPIF for the ILL, ipif_up
* will have to re-bind to the device, so
* we may get back EINPROGRESS, in which
* case, this IOCTL will get completed in
* ip_rput_dlpi when we see the DL_BIND_ACK.
*/
if (err == EINPROGRESS)
return (err);
}
return (err);
}
/* ARGSUSED */
int
{
int addrlen;
ip1dbg(("ip_sioctl_subnet_restart(%s:%u %p)\n",
(void) ipif_down_tail(ipif);
} else {
}
}
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_get_subnet(%s:%u %p)\n",
lifr->lifr_addrlen =
} else {
}
return (0);
}
/*
* Set the IPv6 address token.
*/
/* ARGSUSED */
int
{
int err;
int i;
int addrlen;
ip1dbg(("ip_sioctl_token(%s:%u %p)\n",
/* Only allow for logical unit zero i.e. not on "le0:17" */
return (EINVAL);
return (EINVAL);
if (addrlen > IPV6_ABITS)
return (EINVAL);
/*
* The length of the token is the length from the end. To get
* the proper mask for this, compute the mask of the bits not
* in the token; ie. the prefix, and then xor to get the mask.
*/
return (EINVAL);
for (i = 0; i < 4; i++) {
}
return (0); /* No change */
if (err == EINPROGRESS)
return (err);
(void) ipif_down_tail(ipif);
}
return (err);
}
static int
{
int i;
int err = 0;
ip1dbg(("ip_sioctl_token_tail(%s:%u %p)\n",
/*
* The length of the token is the length from the end. To get
* the proper mask for this, compute the mask of the bits not
* in the token; ie. the prefix, and then xor to get the mask.
*/
for (i = 0; i < 4; i++)
/* Reconfigure the link-local address based on this new token */
if (need_up) {
/*
* Now bring the interface back up. If this
* is the only IPIF for the ILL, ipif_up
* will have to re-bind to the device, so
* we may get back EINPROGRESS, in which
* case, this IOCTL will get completed in
* ip_rput_dlpi when we see the DL_BIND_ACK.
*/
if (err == EINPROGRESS)
return (err);
}
return (err);
}
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_get_token(%s:%u %p)\n",
return (EINVAL);
return (ENXIO);
return (0);
}
/*
* Set (hardware) link specific information that might override
* what was acquired through the DL_INFO_ACK.
*/
/* ARGSUSED */
int
{
int ip_min_mtu;
ip1dbg(("ip_sioctl_lnkinfo(%s:%u %p)\n",
/* Only allow for logical unit zero i.e. not on "bge0:17" */
return (EINVAL);
/* Set interface MTU. */
else
/*
* Verify values before we set anything. Allow zero to
* mean unspecified.
*
* XXX We should be able to set the user-defined lir_mtu to some value
* that is greater than ill_current_frag but less than ill_max_frag- the
* ill_max_frag value tells us the max MTU that can be handled by the
* datalink, whereas the ill_current_frag is dynamically computed for
* some link-types like tunnels, based on the tunnel PMTU. However,
* since there is currently no way of distinguishing between
* administratively fixed link mtu values (e.g., those set via
* for tunnels) we conservatively choose the ill_current_frag as the
* upper-bound.
*/
if (lir->lir_maxmtu != 0 &&
return (EINVAL);
if (lir->lir_reachtime != 0 &&
return (EINVAL);
if (lir->lir_reachretrans != 0 &&
return (EINVAL);
/*
* The dce and fragmentation code can handle changes to ill_mtu
* concurrent with sending/fragmenting packets.
*/
if (lir->lir_maxmtu != 0)
if (lir->lir_reachtime != 0)
if (lir->lir_reachretrans != 0)
/*
* ill_mtu is the actual interface MTU, obtained as the min
* of user-configured mtu and the value announced by the
* driver (via DL_NOTE_SDU_SIZE/DL_INFO_ACK). Note that since
* we have already made the choice of requiring
* ill_user_mtu < ill_current_frag by the time we get here,
* the ill_mtu effectively gets assigned to the ill_user_mtu
* here.
*/
}
/*
* Make sure all dce_generation checks find out
* that ill_mtu has changed.
*/
/*
* Refresh IPMP meta-interface MTU if necessary.
*/
if (IS_UNDER_IPMP(ill))
return (0);
}
/* ARGSUSED */
int
{
struct lif_ifinfo_req *lir;
ip1dbg(("ip_sioctl_get_lnkinfo(%s:%u %p)\n",
return (EINVAL);
return (0);
}
/*
* Return best guess as to the subnet mask for the specified address.
* Based on the subnet masks for all the configured interfaces.
*
* We end up returning a zero mask in the case of default, multicast or
* experimental.
*/
static ipaddr_t
{
if (net_mask == 0) {
return (0);
}
/* Let's check to see if this is maybe a local subnet route. */
/* this function only applies to IPv4 interfaces */
if (IPIF_IS_CONDEMNED(ipif))
continue;
continue;
/*
* Don't trust pt-pt interfaces if there are
* other interfaces.
*/
if (fallback_ipif == NULL) {
}
continue;
}
/*
* Fine. Just assume the same net mask as the
* directly attached subnet interface is using.
*/
if (fallback_ipif != NULL)
return (ipif->ipif_net_mask);
}
}
}
*ipifp = fallback_ipif;
return ((fallback_ipif != NULL) ?
}
/*
* ip_sioctl_copyin_setup calls ip_wput_ioctl to process the IP_IOCTL ioctl.
*/
static void
{
int error = 0;
ip1dbg(("ip_wput_ioctl"));
return;
}
/*
* These IOCTLs provide various control capabilities to
* upstream agents such as ULPs and processes. There
* are currently two such IOCTLs implemented. They
* are used by TCP to provide update information for
* existing IREs and to forcibly delete an IRE for a
* host that is not responding, thereby forcing an
* attempt at a new route.
*/
goto done;
break;
}
/*
* prefer credential from mblk over ioctl;
* see ip_sioctl_copyin_setup
*/
/*
* Refhold the conn in case the request gets queued up in some lookup
*/
}
/*
* CONN_OPER_PENDING_DONE happens in the function called
* through ipft_pfi above.
*/
return;
}
return;
}
done:
}
/*
* Assign a unique id for the ipif. This is used by sctp_addr.c
* Note: remove if sctp_addr.c is redone to not shadow ill/ipif data structures.
*/
static void
{
}
/*
* Clone the contents of `sipif' to `dipif'. Requires that both ipifs are
* administratively down (i.e., no DAD), of the same type, and locked. Note
* that the clone is complete -- including the seqid -- and the expectation is
* that the caller will either free or overwrite `sipif' before it's unlocked.
*/
static void
{
/*
* As per the comment atop the function, we assume that these sipif
* fields will be changed before sipif is unlocked.
*/
}
/*
* Transfer the contents of `sipif' to `dipif', and then free (if `virgipif'
* is NULL) or overwrite `sipif' with `virgipif', which must be a virgin
* (unreferenced) ipif. Also, if `sipif' is used by the current xop, then
* transfer the xop to `dipif'. Requires that all ipifs are administratively
* down (i.e., no DAD), of the same type, and unlocked.
*/
static void
{
/*
* Grab all of the locks that protect the ipif in a defined order.
*/
}
/*
* Transfer ownership of the current xop, if necessary.
*/
}
}
/*
* checks if:
* - <ill_name>:<ipif_id> is at most LIFNAMSIZ - 1 and
* - logical interface is within the allowed range
*/
static int
{
return (ENAMETOOLONG);
return (ERANGE);
return (0);
}
/*
* Insert the ipif, so that the list of ipifs on the ill will be sorted
* with respect to ipif_id. Note that an ipif with an ipif_id of -1 will
* be inserted into the first space available in the list. The value of
* ipif_id will then be set to the appropriate value for its position.
*/
static int
{
/*
* In the case of lo0:0 we already hold the ill_g_lock.
* ill_lookup_on_name (acquires ill_g_lock) -> ipif_allocate ->
* ipif_insert.
*/
if (acquire_g_lock)
id = 0;
break; /* non-consecutive id */
id++;
}
if (acquire_g_lock)
return (err);
}
/* we have a real id; insert ipif in the right place */
break; /* found correct location */
}
} else {
if (acquire_g_lock)
return (err);
}
if (acquire_g_lock)
return (0);
}
static void
{
break;
}
}
}
/*
* Allocate and initialize a new interface control structure. (Always
* called as writer.)
* When ipif_allocate() is called from ip_ll_subnet_defaults, the ill
* is not part of the global linked list of ills. ipif_seqid is unique
* in the system and to preserve the uniqueness, it is assigned only
* when ill becomes part of the global list. At that point ill will
* have a name. If it doesn't get assigned here, it will get assigned
* in ipif_set_values() as part of SIOCSLIFNAME processing.
* Aditionally, if we come here from ip_ll_subnet_defaults, we don't set
* the interface flags or any other information from the DL_INFO_ACK for
* DL_STYLE2 drivers (initialize == B_FALSE), since we won't have them at
* this point. The flags etc. will be set in ip_ll_subnet_defaults when the
* second DL_INFO_ACK comes in from the driver.
*/
static ipif_t *
{
int err;
ip1dbg(("ipif_allocate(%s:%d ill %p)\n",
*errorp = 0;
return (NULL);
}
/*
* Inherit the zoneid from the ill; for the shared stack instance
* this is always the global zone
*/
ipif->ipif_refcnt = 0;
if (insert) {
return (NULL);
}
/* -1 id should have been replaced by real id */
}
/*
* If this is the zeroth ipif on the IPMP ill, create the illgrp
* (which must not exist yet because the zeroth ipif is created once
* per ill). However, do not not link it to the ipmp_grp_t until
* I_PLINK is called; see ip_sioctl_plink_ipmp() for details.
*/
if (insert) {
}
return (NULL);
}
}
/*
* We grab ill_lock to protect the flag changes. The ipif is still
* not up and can't be looked up until the ioctl completes and the
* IPIF_CHANGING flag is cleared.
*/
} else {
/* Keep the IN6_IS_ADDR_V4MAPPED assertions happy */
&ipif->ipif_v6lcl_addr);
&ipif->ipif_v6subnet);
&ipif->ipif_v6net_mask);
&ipif->ipif_v6brd_addr);
}
/*
* Don't set the interface flags etc. now, will do it in
* ip_ll_subnet_defaults.
*/
if (!initialize)
goto out;
/*
* NOTE: The IPMP meta-interface is special-cased because it starts
* with no underlying interfaces (and thus an unknown broadcast
* address length), but all interfaces that can be placed into an IPMP
* group are required to be broadcast-capable.
*/
/*
* Later detect lack of DLPI driver multicast capability by
* catching DL_ENABMULTI_REQ errors in ip_rput_dlpi().
*/
} else {
/*
* Note: xresolv interfaces will eventually need
* NOARP set here as well, but that will require
* those external resolvers to have some
* knowledge of that flag and act appropriately.
* Not to be changed at present.
*/
else
}
if (ill->ill_phys_addr_length == 0) {
} else {
/* pt-pt supports multicast. */
}
}
}
out:
return (ipif);
}
/*
* Remove the neighbor cache entries associated with this logical
* interface.
*/
int
{
int err = 0;
/*
* If this is the last ipif that is going down and there are no
* duplicate addresses we may yet attempt to re-probe, then we need to
* clean up ARP completely.
*/
/*
* If this was the last ipif on an IPMP interface, purge any
* static ARP entries associated with it.
*/
/* UNBIND, DETACH */
}
return (err);
}
/*
* Get the resolver set up for a new IP address. (Always called as writer.)
* Called both for IPv4 and IPv6 interfaces, though it only does some
* basic DAD related initialization for IPv6. Honors ILLF_NOARP.
*
* The enumerated value res_act tunes the behavior:
* * Res_act_initial: set up all the resolver structures for a new
* IP address.
* * Res_act_defend: tell ARP that it needs to send a single gratuitous
* ARP message in defense of the address.
* * Res_act_rebind: tell ARP to change the hardware address for an IP
* address (and issue gratuitous ARPs). Used by ipmp_ill_bind_ipif().
*
* Returns zero on success, or an errno upon failure.
*/
int
{
int err;
ip1dbg(("ipif_resolver_up(%s:%u) flags 0x%x\n",
if (res_act == Res_act_initial) {
ipif->ipif_addr_ready = 0;
/*
* We're bringing an interface up here. There's no way that we
* should need to shut down ARP now.
*/
}
}
if (ipif->ipif_recovery_id != 0)
ipif->ipif_recovery_id = 0;
return (0);
}
/* NDP will set the ipif_addr_ready flag when it's ready */
return (0);
return (err);
}
/*
* when a link has just gone back up.
*/
static void
{
if (isv6) {
&ipif->ipif_v6lcl_addr);
} else {
/*
* If we can't contact ARP for some reason,
* that's not really a problem. Just send
* out the routing socket notification that
* DAD completion would have done, and continue.
*/
return;
}
}
ip1dbg(("couldn't find ncec for ipif %p leaving !ready\n",
(void *)ipif));
return;
}
if (!nce_restart_dad(ncec)) {
/*
* If we can't restart DAD for some reason, that's not really a
* problem. Just send out the routing socket notification that
* DAD completion would have done, and continue.
*/
}
}
/*
* Restart duplicate address detection on all interfaces on the given ill.
*
* This is called when an interface transitions from down to up
* (DL_NOTE_LINK_UP) or up to down (DL_NOTE_LINK_DOWN).
*
* Note that since the underlying physical link has transitioned, we must cause
* at least one routing socket message to be sent here, either via DAD
* completion or just by default on the first ipif. (If we don't do this, then
* in.mpathd will see long delays when doing link-based failure recovery.)
*/
void
{
return;
/*
* If layer two doesn't support duplicate address detection, then just
* send the routing socket message now and be done with it.
*/
return;
}
if (went_up) {
/*
* kick off the bring-up process now.
*/
} else {
/*
* Unfortunately, the first ipif is "special"
* and represents the underlying ill in the
* routing socket messages. Thus, when this
* one ipif is down, we must still notify so
* that the user knows the IFF_RUNNING status
* change. (If the first ipif is up, then
* we'll handle eventual routing socket
* notification via DAD completion.)
*/
}
}
} else {
/*
* After link down, we'll need to send a new routing
* message when the link comes back, so clear
* ipif_addr_ready.
*/
ipif->ipif_addr_ready = 0;
}
}
/*
* If we've torn down links, then notify the user right away.
*/
if (!went_up)
}
static void
{
}
static int
{
int err = 0;
return (0);
if (ipif->ipif_was_up) {
if (err != 0) {
return (err);
}
}
}
return (0);
}
/*
* This function is called to bring up all the ipifs that were up before
* bringing the ill down via ill_down_ipifs().
*/
int
{
int err;
if (ill->ill_replumbing) {
ill->ill_replumbing = 0;
/*
* Send down REPLUMB_DONE notification followed by the
* BIND_REQ on the arp stream.
*/
}
if (err != 0)
return (err);
}
/*
* Bring down any IPIF_UP ipifs on ill. If "logical" is B_TRUE, we bring
* down the ipifs without sending DL_UNBIND_REQ to the driver.
*/
static void
{
/*
* We go through the ipif_down logic even if the ipif
* is already down, since routes can be added based
* on down ipifs. Going through ipif_down once again
* will delete any IREs created based on these routes.
*/
if (logical) {
(void) ipif_down_tail(ipif);
} else {
}
}
}
/*
* Redo source address selection. This makes IXAF_VERIFY_SOURCE take
* a look again at valid source addresses.
* This should be called each time after the set of source addresses has been
* changed.
*/
void
{
/* We skip past SRC_GENERATION_VERIFY */
}
/*
* Finish the group join started in ip_sioctl_groupname().
*/
/* ARGSUSED */
static void
{
/* IS_UNDER_IPMP() won't work until ipmp_ill_join_illgrp() is called */
}
}
}
/*
* Process an SIOCSLIFGROUPNAME request.
*/
/* ARGSUSED */
int
{
int err = 0;
/*
* Note that phyint_grp can only change here, where we're exclusive.
*/
return (EINVAL);
/*
* If the name hasn't changed, there's nothing to do.
*/
goto unlock;
/*
* Handle requests to rename an IPMP meta-interface.
*
* Note that creation of the IPMP meta-interface is handled in
* userland through the standard plumbing sequence. As part of the
* plumbing the IPMP meta-interface, its initial groupname is set to
* the name of the interface (see ipif_set_values_tail()).
*/
goto unlock;
}
/*
* Handle requests to add or remove an IP interface from a group.
*/
/*
* Moves are handled by first removing the interface from
* its existing group, and then adding it to another group.
* So, fail if it's already in a group.
*/
if (IS_UNDER_IPMP(ill)) {
goto unlock;
}
goto unlock;
}
/*
* Check if the phyint and its ills are suitable for
* inclusion into the group.
*/
goto unlock;
/*
* Checks pass; join the group, and enqueue the remaining
* illgrp joins for when we've become part of the group xop
* and are exclusive across its IPSQs. Since qwriter_ip()
* requires an mblk_t to scribble on, and since `mp' will be
* freed as part of completing the ioctl, allocate another.
*/
goto unlock;
}
/*
* Before we drop ipmp_lock, bump gr_pend* to ensure that the
* IPMP meta-interface ills needed by `phyi' cannot go away
* before ip_join_illgrps() is called back. See the comments
* in ip_sioctl_plink_ipmp() for more.
*/
return (0);
} else {
/*
* Request to remove the interface from a group. If the
* interface is not in a group, this trivially succeeds.
*/
if (IS_UNDER_IPMP(ill))
return (0);
}
return (err);
}
/*
* Process an SIOCGLIFBINDING request.
*/
/* ARGSUSED */
int
{
return (EINVAL);
else
return (0);
}
/*
* Process an SIOCGLIFGROUPNAME request.
*/
/* ARGSUSED */
int
{
else
return (0);
}
/*
* Process an SIOCGLIFGROUPINFO request.
*/
/* ARGSUSED */
int
{
/* ip_wput_nondata() verified mp->b_cont->b_cont */
return (ENOENT);
}
return (0);
}
static void
{
/*
* The ill is down; unbind but stay attached since we're still
* associated with a PPA. If we have negotiated DLPI capabilites
* with the data link service provider (IDS_OK) then reset them.
* The interval between unbinding and rebinding is potentially
* unbounded hence we cannot assume things will be the same.
* The DLPI capabilities will be probed again when the data link
* is brought up.
*/
if (!ill->ill_replumbing) {
/* Free all ilms for this ill */
} else {
}
ip1dbg(("ill_dl_down: %s (%u) for %s\n",
/*
* ip_rput does not pass up normal (M_PROTO) DLPI messages
* after ILL_CONDEMNED is set. So in the unplumb case, we call
* ill_capability_dld_disable disable rightaway. If this is not
* an unplumb operation then the disable happens on receipt of
* the capab ack via ip_rput_dlpi_writer ->
* ill_capability_ack_thr. In both cases the order of
* the operations seen by DLD is capability disable followed
* by DL_UNBIND. Also the DLD capability disable needs a
* cv_wait'able context.
*/
}
}
void
{
union DL_primitives *dlp;
ip1dbg(("ill_dlpi_dispatch: sending %s (%u) to %s\n",
switch (prim) {
case DL_PHYS_ADDR_REQ:
{
break;
}
case DL_BIND_REQ:
break;
}
/*
* Except for the ACKs for the M_PCPROTO messages, all other ACKs
* are dropped by ip_rput() if ILL_CONDEMNED is set. Therefore
* we only wait for the ACK of the DL_UNBIND_REQ.
*/
(prim == DL_UNBIND_REQ)) {
}
/*
* There is no ack for DL_NOTIFY_CONF messages
*/
}
/*
* Helper function for ill_dlpi_send().
*/
/* ARGSUSED */
static void
{
}
/*
* Send a DLPI control message to the driver but make sure there
* is only one outstanding message. Uses ill_dlpi_pending to tell
* when it must queue. ip_rput_dlpi_writer calls ill_dlpi_done()
* when an ACK or a NAK is received to process the next queued message.
*/
void
{
/*
* To ensure that any DLPI requests for current exclusive operation
* are always completely sent before any DLPI messages for other
* operations, require writer access before enqueuing.
*/
if (!IAM_WRITER_ILL(ill)) {
/* qwriter_ip() does the ill_refrele() */
return;
}
/* Must queue message. Tail insertion */
ip1dbg(("ill_dlpi_send: deferring request for %s "
return;
}
}
void
{
}
void
{
if (ill->ill_capab_pending_cnt == 0 &&
}
/*
* Send all deferred DLPI messages without waiting for their ACKs.
*/
void
{
/*
* Clear ill_dlpi_pending so that the message is not queued in
* ill_dlpi_send().
*/
}
}
/*
* Clear all the deferred DLPI messages. Called on receiving an M_ERROR
* or M_HANGUP
*/
static void
{
}
}
/*
* Check if the DLPI primitive `prim' is pending; print a warning if not.
*/
{
return (B_TRUE);
}
/*
* During teardown, ill_dlpi_dispatch() will send DLPI requests
* without waiting, so don't print any warnings in that case.
*/
return (B_FALSE);
}
if (pending == DL_PRIM_INVAL) {
"received unsolicited ack for %s on %s\n",
} else {
"received unexpected ack for %s on %s (expecting %s)\n",
}
return (B_FALSE);
}
/*
* Complete the current DLPI operation associated with `prim' on `ill' and
* start the next queued DLPI operation (if any). If there are no queued DLPI
* operations and the ill's current exclusive IPSQ operation has finished
* (i.e., ipsq_current_finish() was called), then clear ipsq_current_ipif to
* allow the next exclusive IPSQ operation to begin upon ipsq_exit(). See
* the comments above ipsq_current_finish() for details.
*/
void
{
if (ipx->ipx_current_done) {
}
return;
}
}
/*
* Queue a (multicast) DLPI control message to be sent to the driver by
* later calling ill_dlpi_send_queued.
* We queue them while holding a lock (ill_mcast_lock) to ensure that they
* are sent in order i.e., prevent a DL_DISABMULTI_REQ and DL_ENABMULTI_REQ
* for the same group to race.
* We send DLPI control messages in order using ill_lock.
* For IPMP we should be called on the cast_ill.
*/
void
{
/* Must queue message. Tail insertion */
}
/*
* Send the messages that were queued. Make sure there is only
* one outstanding message. ip_rput_dlpi_writer calls ill_dlpi_done()
* when an ACK or a NAK is received to process the next queued message.
* For IPMP we are called on the upper ill, but when send what is queued
* on the cast_ill.
*/
void
{
union DL_primitives *dlp;
/* On the upper IPMP ill. */
if (release_ill == NULL) {
/* Avoid ever sending anything down to the ipmpstub */
return;
}
ill = release_ill;
}
/* Can't send. Somebody else will send it */
goto done;
}
/*
* Nobody there. All multicast addresses will be
* re-joined when we get the DL_BIND_ACK bringing the
* interface up.
*/
continue;
}
(prim == DL_UNBIND_REQ)) {
}
}
done:
if (release_ill != NULL)
}
/*
* ill_mcast_send_queued
* We queue them while holding a lock (ill_mcast_lock) to ensure that they
* are sent in order i.e., prevent a IGMP leave and IGMP join for the same
* group to race.
* We send them in order using ill_lock.
* For IPMP we are called on the upper ill, but we queue on the cast_ill.
*/
void
{
/* On the upper IPMP ill. */
if (release_ill == NULL) {
/* Discard instead of queuing for the ipmp interface */
ip_drop_output("ipIfStatsOutDiscards - no cast_ill",
return;
}
ill = release_ill;
}
/* Must queue message. Tail insertion */
if (release_ill != NULL)
}
/*
* Send the IP packets that were queued by ill_mcast_queue.
*
* For IPMP we are called on the upper ill, but when send what is queued
* on the cast_ill.
*
* Request loopback of the report if we are acting as a multicast
* router, so that the process-level routing demon can hear it.
* This will run multiple times for the same group if there are members
* on the same group for multiple ipif's on the same ill. The
* igmp_input/mld_input code will suppress this due to the loopback thus we
* always loopback membership report.
*
* We also need to make sure that this does not get load balanced
* by IPMP. We do this by passing an ill to ip_output_simple.
*/
void
{
/* On the upper IPMP ill. */
if (release_ill == NULL) {
/*
* We should have no messages on the ipmp interface
* but no point in trying to send them.
*/
return;
}
ill = release_ill;
}
/*
* Here we set ixa_ifindex. If IPMP it will be the lower ill which
* makes ip_select_route pick the IRE_MULTICAST for the cast_ill.
*/
/*
* Nobody there. Just drop the ip packets.
*/
continue;
}
/*
* When the ill is getting deactivated, we only want to
* DLPI messages are handled by ill_dlpi_send_queued()
*/
continue;
}
/* Check whether we are sending IPv4 or IPv6. */
} else {
}
ixa_cleanup(&ixas);
}
done:
if (release_ill != NULL)
}
/*
* Take down a specific interface, but don't lose any information about it.
* (Always called as writer.)
* This function goes through the down sequence even if the interface is
* already down. There are 2 reasons.
* a. Currently we permit interface routes that depend on down interfaces
* to be added. This behaviour itself is questionable. However it appears
* that both Solaris and 4.3 BSD have exhibited this behaviour for a long
* time. We go thru the cleanup in order to remove these routes.
* b. The bringup of the interface could fail in ill_dl_up i.e. we get
* DL_ERROR_ACK in response to the DL_BIND request. The interface is
* down, but we need to cleanup i.e. do ill_dl_down and
* ip_rput_dlpi_writer (DL_ERROR_ACK) -> ipif_down.
*
* IP-MT notes:
*
* Model of reference to interfaces.
*
* The following members in ipif_t track references to the ipif.
* int ipif_refcnt; Active reference count
*
* The following members in ill_t track references to the ill.
* int ill_refcnt; active refcnt
* uint_t ill_ire_cnt; Number of ires referencing ill
* uint_t ill_ncec_cnt; Number of ncecs referencing ill
* uint_t ill_nce_cnt; Number of nces referencing ill
* uint_t ill_ilm_cnt; Number of ilms referencing ill
*
* Reference to an ipif or ill can be obtained in any of the following ways.
*
* Through the lookup functions ipif_lookup_* / ill_lookup_* functions
* Pointers to ipif / ill from other data structures viz ire and conn.
* Implicit reference to the ipif / ill by holding a reference to the ire.
*
* ipif_refcnt and ill_refcnt track the reference counts respectively.
* This is a purely dynamic reference count associated with threads holding
* references to the ipif / ill. Pointers from other structures do not
* count towards this reference count.
*
* ill_ire_cnt is the number of ire's associated with the
* ill. This is incremented whenever a new ire is created referencing the
* ill. This is done atomically inside ire_add_v[46] where the ire is
* actually added to the ire hash table. The count is decremented in
* ire_inactive where the ire is destroyed.
*
* ill_ncec_cnt is the number of ncec's referencing the ill thru ncec_ill.
* This is incremented atomically in
* ndp_add_v4()/ndp_add_v6() where the nce is actually added to the
* table. Similarly it is decremented in ncec_inactive() where the ncec
* is destroyed.
*
* ill_nce_cnt is the number of nce's referencing the ill thru nce_ill. This is
* incremented atomically in nce_add() where the nce is actually added to the
* ill_nce. Similarly it is decremented in nce_inactive() where the nce
* is destroyed.
*
* ill_ilm_cnt is the ilm's reference to the ill. It is incremented in
* ilm_add() and decremented before the ilm is freed in ilm_delete().
*
*
* The following is the sequence of an attempt to set some critical flags on an
* up interface.
* ip_sioctl_flags
* ipif_down
* wait for ipif to be quiescent
* ipif_down_tail
* ip_sioctl_flags_tail
*
* to the above. All the *tail functions are called after the refcounts have
* dropped to the appropriate values.
*
* SIOC ioctls during the IPIF_CHANGING interval.
*
* Threads handling SIOC set ioctls serialize on the squeue, but this
* is not done for SIOC get ioctls. Since a set ioctl can cause several
* steps of internal changes to the state, some of which are visible in
* ipif_flags (such as IFF_UP being cleared and later set), and we want
* the set ioctl to be atomic related to the get ioctls, the SIOC get code
* will wait and restart ioctls if IPIF_CHANGING is set. The mblk is then
* enqueued in the ipsq and the operation is restarted by ipsq_exit() when
* the current exclusive operation completes. The IPIF_CHANGING check
* and enqueue is atomic using the ill_lock and ipsq_lock. The
* change while the ill_lock is held. Before dropping the ill_lock we acquire
* the ipsq_lock and call ipsq_enq. This ensures that ipsq_exit can't finish
* can change after we drop the ill_lock.
*/
int
{
--ill->ill_ipif_up_count;
/* Update status in SCTP's list */
}
/*
* Blow away memberships we established in ipif_multicast_up().
*/
/*
* Remove from the mapping for __sin6_src_id. We insert only
* when the address is not INADDR_ANY. As IPv4 addresses are
* stored as mapped addresses, we need to check for mapped
* INADDR_ANY also.
*/
int err;
if (err != 0) {
}
}
if (ipif_was_up) {
/* only delete if we'd added ire's before */
else
}
/*
* Since the interface is now down, it may have just become
* inactive. Note that this needs to be done even for a
* lll_logical_down(), or ARP entries will not get correctly
* restored when the interface comes back up.
*/
if (IS_UNDER_IPMP(ill))
}
/*
* neighbor-discovery or arp entries for this interface. The ipif
* has to be quiesced, so we walk all the nce's and delete those
* that point at the ipif->ipif_ill. At the same time, we also
* update IPMP so that ipifs for data addresses are unbound. We dont
* call ipif_arp_down to DL_UNBIND the arp stream itself here, but defer
* that for ipif_down_tail()
*/
/*
* If this is the last ipif on the ill, we also need to remove
* any IREs with ire_ill set. Otherwise ipif_is_quiescent() will
* never succeed.
*/
/*
* Walk all CONNs that can have a reference on an ire for this
* ipif (we actually walk all that now have stale references).
*/
/*
* If mp is NULL the caller will wait for the appropriate refcnt.
* Eg. ip_sioctl_removeif -> ipif_free -> ipif_down
* and ill_delete -> ipif_free -> ipif_down
*/
return (0);
}
if (CONN_Q(q)) {
} else {
}
/*
* Are there any ire's pointing to this ipif that are still active ?
* If this is the last ipif going down, are there any ire's pointing
* to this ill that are still active ?
*/
if (ipif_is_quiescent(ipif)) {
return (0);
}
ip1dbg(("ipif_down: need to wait, adding pending mp %s ill %p",
/*
* Enqueue the mp atomically in ipsq_pending_mp. When the refcount
* drops down, the operation will be restarted by ipif_ill_refrele_tail
*/
if (!success) {
/* The conn is closing. So just return */
return (EINTR);
}
return (EINPROGRESS);
}
int
{
int err = 0;
/*
* Skip any loopback interface (null wq).
* If this is the last logical interface on the ill
* have ill_dl_down tell the driver we are gone (unbind)
* Note that lun 0 can ipif_down even though
* there are other logical units that are up.
* This occurs e.g. when we change a "significant" IFF_ flag.
*/
}
ill->ill_logical_down = 0;
return (err);
}
/*
* Bring interface logically down without bringing the physical interface
* down e.g. when the netmask is changed. This avoids long lasting link
* negotiations between an ethernet interface and a certain switches.
*/
static int
{
/*
* The ill_logical_down flag is a transient flag. It is set here
* and is cleared once the down has completed in ipif_down_tail.
* This flag does not indicate whether the ill stream is in the
* DL_BOUND state with the driver. Instead this flag is used by
* ipif_down_tail to determine whether to DL_UNBIND the stream with
* the driver. The state of the ill stream i.e. whether it is
* DL_BOUND with the driver or not is indicated by the ill_dl_up flag.
*/
}
/*
* Initiate deallocate of an IPIF. Always called as writer. Called by
* ill_delete or ip_sioctl_removeif.
*/
static void
{
if (ipif->ipif_recovery_id != 0)
ipif->ipif_recovery_id = 0;
/*
* Take down the interface. We can be called either from ill_delete
* or from ip_sioctl_removeif.
*/
/*
* Now that the interface is down, there's no chance it can still
* become a duplicate. Cancel any timer that may have been set while
* tearing down.
*/
if (ipif->ipif_recovery_id != 0)
ipif->ipif_recovery_id = 0;
/* Remove pointers to this ill in the multicast routing tables */
/* If necessary, clear the cached source ipif rotor. */
}
static void
{
/*
* Need to hold both ill_g_lock and ill_lock while
* inserting or removing an ipif from the linked list
* of ipifs hanging off the ill.
*/
#ifdef DEBUG
#endif
/* Ask SCTP to take it out of it list */
/* Get it out of the ILL interface list. */
/* Free the memory. */
}
/*
* Sets `buf' to an ipif name of the form "ill_name:id", or "ill_name" if "id"
* is zero.
*/
void
{
char *name;
buf[0] = '\0';
}
len -= 1;
}
/*
* Sets `buf' to an ill name.
*/
void
{
char *name;
len -= 1;
}
/*
* Find an IPIF based on the name passed in. Names can be of the form <phys>
* (e.g., le0) or <phys>:<#> (e.g., le0:1). When there is no colon, the
* implied unit id is zero. <phys> must correspond to the name of an ILL.
* (May be called as writer.)
*/
static ipif_t *
{
char *cp;
char *endp;
long id;
/*
* If the caller wants to us to create the ipif, make sure we have a
* valid zoneid
*/
if (namelen == 0) {
return (NULL);
}
/* Look for a colon in the name. */
if (*cp == IPIF_SEPARATOR_CHAR)
break;
}
if (*cp == IPIF_SEPARATOR_CHAR) {
/*
* Reject any non-decimal aliases for logical
* interfaces. Aliases with leading zeroes
* are also rejected as they introduce ambiguity
* in the naming of the interfaces.
* In order to confirm with existing semantics,
* on that behaviour, if<0>:0 is considered to be
* a valid interface.
*
* If alias has two or more digits and the first
* is zero, fail.
*/
return (NULL);
}
}
} else {
*cp = '\0';
}
/*
* Look up the ILL, based on the portion of the name
* before the slash. ill_lookup_on_name returns a held ill.
* Temporary to check whether ill exists already. If so
* ill_lookup_on_name will clear it.
*/
return (NULL);
/* Establish the unit number in the name. */
id = 0;
/* If there was a colon, the unit number follows. */
cp++;
return (NULL);
}
}
/* Now see if there is an IPIF with this unit number. */
return (NULL);
}
if (IPIF_CAN_LOOKUP(ipif)) {
if (!did_alloc)
/*
* Drop locks before calling ill_refrele
* since it can potentially call into
* ipif_ill_refrele_tail which can end up
* in trying to acquire any lock.
*/
return (ipif);
}
}
}
if (!do_alloc) {
return (NULL);
}
/*
* If none found, atomically allocate and return a new one.
* Historically, we used IRE_LOOPBACK only for lun 0, and IRE_LOCAL
* to support "receive only" use of lo0:1 etc. as is still done
* below as an initial guess.
* However, this is now likely to be overriden later in ipif_up_done()
* when we know for sure what address has been configured on the
* interface, since we might have more than one loopback interface
* with a loopback address, e.g. in the case of zones, and all the
* interfaces with loopback addresses need to be marked IRE_LOOPBACK.
*/
else
return (ipif);
}
/*
* This routine is called whenever a new address comes up on an ipif. If
* we are configured to respond to address mask requests, then we are supposed
* to broadcast an address mask reply at this time. This routine is also
* called if we are already up, but a netmask change is made. This is legal
* but might not make the system manager very popular. (May be called
* as writer.)
*/
void
{
return;
/* ICMP mask reply is IPv4 only */
/* ICMP mask reply is not for a loopback interface */
return;
return;
ipha->ipha_ident = 0;
ixas.ixa_ifindex = 0;
ixa_cleanup(&ixas);
}
/*
* Join the ipif specific multicast groups.
* Must be called after a mapping has been set up in the resolver. (Always
* called as writer.)
*/
void
{
int err;
ip1dbg(("ipif_multicast_up\n"));
return;
return;
ip1dbg(("ipif_multicast_up - addmulti\n"));
/*
* Join the all hosts multicast address. We skip this for
* underlying IPMP interfaces since they should be invisible.
*/
if (!IS_UNDER_IPMP(ill)) {
&err);
ip0dbg(("ipif_multicast_up: "
"all_hosts_mcast failed %d\n", err));
return;
}
}
/*
* Enable multicast for the solicited node multicast address.
* If IPMP we need to put the membership on the upper ill.
*/
if (IS_UNDER_IPMP(ill) &&
} else {
}
if (need_refrele)
ip0dbg(("ipif_multicast_up: solicited MC"
" failed %d\n", err));
(void) ip_delmulti(ilm);
}
return;
}
}
} else {
return;
/* Join the all hosts multicast address */
ip1dbg(("ipif_multicast_up - addmulti\n"));
return;
}
}
}
/*
* Blow away any multicast groups that we joined in ipif_multicast_up().
* (ilms from explicit memberships are handled in conn_update_ill.)
*/
void
{
ip1dbg(("ipif_multicast_down\n"));
}
}
}
/*
* Used when an interface comes up to recreate any extra routes on this
* interface.
*/
int
{
/*
* Create a copy of the IRE with the saved address and netmask.
*/
ire = ire_create_v6(
&ifrt->ifrt_v6addr,
&ifrt->ifrt_v6mask,
ill,
NULL,
ipst);
} else {
ire = ire_create(
ill,
NULL,
ipst);
}
return (ENOMEM);
}
} else {
}
}
/*
* Some software (for example, GateD and Sun Cluster) attempts
* to create (what amount to) IRE_PREFIX routes with the
* loopback address as the gateway. This is primarily done to
* set up prefixes with the RTF_REJECT flag set (for example,
* when generating aggregate routes.)
*
* If the IRE type (as defined by ill->ill_net_type) is
* IRE_LOOPBACK, then we map the request into a
* IRE_IF_NORESOLVER.
*/
/*
* ire held by ire_add, will be refreled' towards the
* the end of ipif_up_done
*/
/*
* Check if it was a duplicate entry. This handles
* the case of two racing route adds for the same route
*/
ip1dbg(("ill_recover_saved_ire: FAILED\n"));
ip1dbg(("ill_recover_saved_ire: duplicate ire %p\n",
(void *)nire));
} else {
ip1dbg(("ill_recover_saved_ire: added ire %p\n",
(void *)nire));
}
}
return (0);
}
/*
* Used to set the netmask and broadcast address to default values when the
* interface is brought up. (Always called as writer.)
*/
static void
{
/*
* Interface holds an IPv4 address. Default
* mask is the natural netmask.
*/
if (!ipif->ipif_net_mask) {
}
/* ipif_subnet is ipif_pp_dst_addr for pt-pt */
} else {
}
/*
* NOTE: SunOS 4.X does this even if the broadcast address
* has been already set thus we do the same here.
*/
}
} else {
/*
* Interface holds an IPv6-only address. Default
* mask is all-ones.
*/
/* ipif_subnet is ipif_pp_dst_addr for pt-pt */
} else {
}
}
}
/*
* Return 0 if this address can be used as local address without causing
* duplicate address problems. Otherwise, return EADDRNOTAVAIL if the address
* is already up on a different ill, and EADDRINUSE if it's up on the same ill.
* Note that the same IPv6 link-local address is allowed as long as the ills
* are not on the same link.
*/
int
{
return (0);
else
&our_v6addr))
continue;
else if ((IN6_IS_ADDR_LINKLOCAL(&our_v6addr) ||
continue;
continue;
return (EADDRINUSE);
else
return (EADDRNOTAVAIL);
}
}
return (0);
}
/*
* IREs for the ipif.
* When the routine returns EINPROGRESS then mp has been consumed and
* the ioctl will be acked from ip_rput_dlpi.
*/
int
{
int err = 0;
/* Shouldn't get here if it is already up. */
return (EALREADY);
/*
* If this is a request to bring up a data address on an interface
* under IPMP, then move the address to its IPMP meta-interface and
* try to bring it up. One complication is that the zeroth ipif for
* an ill is special, in that every ill always has one, and that code
* throughout IP deferences ill->ill_ipif without holding any locks.
*/
/*
* The ipif being brought up should be quiesced. If it's not,
* something has gone amiss and we need to bail out. (If it's
* quiesced, we know it will remain so via IPIF_CONDEMNED.)
*/
if (!ipif_is_quiescent(ipif)) {
return (EINVAL);
}
/*
* If we're going to need to allocate ipifs, do it prior
* to starting the move (and grabbing locks).
*/
return (err);
}
return (err);
}
}
/*
* Grab or transfer the ipif to move. During the move, keep
* ill_g_lock held to prevent any ill walker threads from
* seeing things in an inconsistent state.
*/
} else {
}
/*
* Place the ipif on the IPMP ill. If the zeroth ipif on
* the IPMP ill is a stub (0.0.0.0 down address) then we
* replace that one. Otherwise, pick the next available slot.
*/
} else {
/*
* No more available ipif_id's -- put it back
* on the original ill and fail the operation.
* Since we're writer on the ill, we can be
* sure our old slot is still available.
*/
if (ipif_orig_id == 0) {
NULL);
} else {
}
return (err);
}
}
/*
* Tell SCTP that the ipif has moved. Note that even if we
* had to allocate a new ipif, the original sequence id was
* preserved and therefore SCTP won't know.
*/
/*
* If the ipif being brought up was on slot zero, then we
* first need to bring up the placeholder we stuck there. In
* ip_rput_dlpi_writer(), arp_bringup_done(), or the recursive
* call to ipif_up() itself, if we successfully bring up the
* placeholder, we'll check ill_move_ipif and bring it up too.
*/
if (ipif_orig_id == 0) {
if (err != EINPROGRESS)
return (err);
}
/*
* Bring it up on the IPMP ill.
*/
}
/*
* ill_dl_up is not yet set. i.e. we are yet to
* DL_BIND with the driver and this is the first
* logical interface on the ill to become "up".
* Tell the driver to get going (via DL_BIND_REQ).
* Note that changing "significant" IFF_ flags
* does not cause an unbind (DL_UNBIND) with the driver
*/
}
/*
* the ARP stream, which in turn necessitates a
* DLPI message exchange with the driver. ioctls are
* serialized and so we cannot send more than one
* interface up message at a time. If ipif_resolver_up
* does need to wait for the DLPI handshake for the ARP stream,
* we get EINPROGRESS and we will complete in arp_bringup_done.
*/
if (!success)
return (EINTR);
/*
* Crank up IPv6 neighbor discovery. Unlike ARP, this should
* complete when ipif_ndp_up returns.
*/
if (err == EINPROGRESS) {
/* We will complete it in arp_bringup_done() */
return (err);
}
if (err != 0)
return (err);
} else {
/*
* Interfaces without underlying hardware don't do duplicate
* address detection.
*/
/* allocation failure? */
if (err != 0)
return (err);
}
}
return (err);
}
/*
* Add any IREs tied to the ill. For now this is just an IRE_MULTICAST.
* The identical set of IREs need to be removed in ill_delete_ires().
*/
int
{
return (0);
/*
* provide some dummy ire_addr for creating the ire.
*/
} else {
}
return (ENOMEM);
return (0);
}
void
{
/*
* which was taken without any th_tracing enabled.
* We also mark it as condemned (note that it was never added)
* so that caching conn's can move off of it.
*/
}
}
/*
* Perform a bind for the physical device.
* When the routine returns EINPROGRESS then mp has been consumed and
* the ioctl will be acked from ip_rput_dlpi.
* Allocate an unbind message and save it until ipif_down.
*/
static int
{
int err;
/*
* Make sure we have an IRE_MULTICAST in case we immediately
* start receiving packets.
*/
if (err != 0)
goto bad;
goto bad;
goto bad;
/*
* Record state needed to complete this operation when the
* DL_BIND_ACK shows up. Also remember the pre-allocated mblks.
*/
GRAB_CONN_LOCK(q);
if (!success)
goto bad;
/*
* Save the unbind message for ill_dl_down(); it will be consumed when
* the interface goes down.
*/
/* Send down link-layer capabilities probe if not already done. */
/*
* Sysid used to rely on the fact that netboots set domainname
* and the like. Now that miniroot boots aren't strictly netboots
* and miniroot network configuration is driven from userland
* these things still need to be set. This situation can be detected
* by comparing the interface being configured here to the one
* dhcifname was set to reference by the boot loader. Once sysid is
* converted to use dhcp_ipc_getinfo() this call can go away.
*/
(strlen(srpc_domain) == 0)) {
if (dhcpinit() != 0)
}
/*
* This operation will complete in ip_rput_dlpi with either
* a DL_BIND_ACK or DL_ERROR_ACK.
*/
return (EINPROGRESS);
bad:
return (ENOMEM);
}
/* Add room for tcp+ip headers */
/*
* DLPI and ARP is up.
* Create all the IREs associated with an interface. Bring up multicast.
* Set the interface flag and finish other initialization
* that potentially had to be deferred to after DL_BIND_ACK.
*/
int
{
int err = 0;
ip1dbg(("ipif_up_done(%s:%u)\n",
/* Check if this is a loopback interface */
/*
* If all other interfaces for this ill are down or DEPRECATED,
* or otherwise unsuitable for source address selection,
* reset the src generation numbers to make sure source
* address selection gets to take this new ipif into account.
* No need to hold ill_lock while traversing the ipif list since
* we are writer
*/
if (((tmp_ipif->ipif_flags &
continue;
/* first useable pre-existing interface */
break;
}
if (update_src_selection)
/*
* lo0:1 and subsequent ipifs were marked IRE_LOCAL in
* ipif_lookup_on_name(), but in the case of zones we can have
* several loopback addresses on lo0. So all the interfaces with
* loopback addresses need to be marked IRE_LOOPBACK.
*/
else
flags |= NCE_F_PUBLISH;
/* add unicast nce for the local addr */
ND_REACHABLE, &loop_nce);
/* A shared-IP zone sees EEXIST for lo0:N */
loop_nce->nce_ipif_cnt++;
err = 0;
} else {
return (err);
}
}
/* Create all the IREs associated with this interface */
if (err != 0) {
/*
* see comments about return value from
* ip_addr_availability_check() in ipif_add_ires_v4().
*/
if (err != EADDRINUSE) {
(void) ipif_arp_down(ipif);
} else {
/*
* Make IPMP aware of the deleted ipif so that
* the needed ipmp cleanup (e.g., of ipif_bound_ill)
* can be completed. Note that we do not want to
* destroy the nce that was created on the ipmp_ill
* for the active copy of the duplicate address in
* use.
*/
err = EADDRNOTAVAIL;
}
return (err);
}
/* Recover any additional IREs entries for this ill */
(void) ill_recover_saved_ire(ill);
}
if (ill->ill_need_recover_multicast) {
/*
* Need to recover all multicast memberships in the driver.
* This had to be deferred until we had attached. The same
* code exists in ipif_up_done_v6() to recover IPv6
* memberships.
*
* Note that it would be preferable to unconditionally do the
* ill_recover_multicast() in ill_dl_up(), but we cannot do
* that since ill_join_allmulti() depends on ill_dl_up being
* set, and it is not set until we receive a DL_BIND_ACK after
* having called ill_dl_up().
*/
}
/*
* Since the interface is now up, it may now be active.
*/
if (IS_UNDER_IPMP(ill))
/*
* If this is an IPMP interface, we may now be able to
* establish ARP entries.
*/
}
/* Join the allhosts multicast address */
if (!loopback && !update_src_selection &&
/* Broadcast an address mask reply. */
}
/* Perhaps ilgs should use this ill */
/*
* This had to be deferred until we had bound. Tell routing sockets and
* others that this interface is up if it looks like the address has
* been validated. Otherwise, if it isn't ready yet, wait for
* duplicate address detection to do its thing.
*/
if (ipif->ipif_addr_ready)
return (0);
}
/*
* Add the IREs associated with the ipif.
* Those MUST be explicitly removed in ipif_delete_ires_v4.
*/
static int
{
int err;
/*
* If we're on a labeled system then make sure that zone-
* private addresses have proper remote host database entries.
*/
if (is_system_labeled() &&
return (EINVAL);
/* Register the source address for __sin6_src_id */
if (err != 0) {
return (err);
}
if (loopback)
else
/* If the interface address is set, create the local IRE. */
gw, /* gateway */
RTF_PRIVATE : 0) | RTF_KERNEL,
NULL,
ipst);
ip1dbg(("ipif_add_ires: 0x%p creating IRE %p type 0x%x"
ip1dbg(("ipif_up_done: NULL ire_local\n"));
goto bad;
}
} else {
ip1dbg((
"ipif_add_ires: not creating IRE %d for 0x%x: flags 0x%x\n",
}
} else {
}
/*
* If mask was not specified, use natural netmask of
* interface address. Also, store this mask back into the
* ipif struct.
*/
if (subnet_mask == 0) {
}
/* Set up the IRE_IF_RESOLVER or IRE_IF_NORESOLVER, as appropriate. */
/* ipif_subnet is ipif_pp_dst_addr for pt-pt */
} else {
}
ip1dbg(("ipif_add_ires: ipif 0x%p ill 0x%p "
"creating if IRE ill_net_type 0x%x for 0x%x\n",
ire_if = ire_create(
(uchar_t *)&route_mask,
ill,
RTF_PRIVATE: 0) | RTF_KERNEL,
NULL,
ipst);
ip1dbg(("ipif_up_done: NULL ire_if\n"));
goto bad;
}
}
/*
* Create any necessary broadcast IREs.
*/
/* If an earlier ire_create failed, get out now */
irep1--;
ip1dbg(("ipif_up_done: NULL ire found in ire_array\n"));
goto bad;
}
}
/*
* Need to atomically check for IP address availability under
* ip_addr_avail_lock. ill_g_lock is held as reader to ensure no new
* ills or new ipifs can be added while we are checking availability.
*/
/* Mark it up, and increment counters. */
ill->ill_ipif_up_count++;
if (err != 0) {
/*
* Our address may already be up on the same ill. In this case,
* the ARP entry for our ipif replaced the one for the other
* ipif. So we don't want to delete it (otherwise the other ipif
* would be unable to send packets).
* ip_addr_availability_check() identifies this case for us and
* returns EADDRINUSE; Caller should turn it into EADDRNOTAVAIL
* which is the expected error code.
*/
ill->ill_ipif_up_count--;
goto bad;
}
/*
* Add in all newly created IREs. ire_create_bcast() has
* already checked for duplicates of the IRE_BROADCAST type.
* We add the IRE_INTERFACE before the IRE_LOCAL to ensure
* that lookups find the IRE_LOCAL even if the IRE_INTERFACE is
* a /32 route.
*/
goto bad2;
}
#ifdef DEBUG
#endif
}
goto bad2;
}
#ifdef DEBUG
#endif
}
/*
* We first add all of them, and if that succeeds we refrele the
* bunch. That enables us to delete all of them should any of the
* ire_adds fail.
*/
irep1--;
goto bad2;
}
}
irep1--;
/* refheld by ire_add. */
ire_refrele(*irep1);
}
}
if (!loopback) {
/*
* If the broadcast address has been set, make sure it makes
* sense based on the interface address.
* Only match on ill since we are sharing broadcast addresses.
*/
/*
* If there isn't a matching broadcast IRE,
* revert to the default for this netmask.
*/
} else {
}
}
}
return (0);
bad2:
ill->ill_ipif_up_count--;
bad:
ip1dbg(("ipif_add_ires: FAILED \n"));
}
}
irep--;
ire_delete(*irep);
}
}
return (err);
}
/* Remove all the IREs created by ipif_add_ires_v4 */
void
{
/*
* Move count to ipif so we don't loose the count due to
*/
}
}
/*
* Delete the broadcast IREs.
*/
}
/*
* Checks for availbility of a usable source address (if there is one) when the
* destination ILL has the ill_usesrc_ifindex pointing to another ILL. Note
* this selection is done regardless of the destination.
*/
{
return (B_FALSE);
if (IPIF_IS_CONDEMNED(ipif))
continue;
continue;
continue;
continue;
continue;
return (B_TRUE);
}
return (B_FALSE);
}
/*
* Find an ipif with a good local address on the ill+zoneid.
*/
ipif_t *
{
if (IPIF_IS_CONDEMNED(ipif))
continue;
continue;
continue;
continue;
continue;
return (ipif);
}
return (NULL);
}
/*
* IP source address type, sorted from worst to best. For a given type,
* always prefer IP addresses on the same subnet. All-zones addresses are
* suboptimal because they pose problems with unlabeled destinations.
*/
typedef enum {
IPIF_DIFFNET_DEPRECATED, /* deprecated and different subnet */
IPIF_SAMENET_DEPRECATED, /* deprecated and same subnet */
IPIF_DIFFNET_ALLZONES, /* allzones and different subnet */
IPIF_SAMENET_ALLZONES, /* allzones and same subnet */
IPIF_DIFFNET, /* normal and different subnet */
IPIF_SAMENET, /* normal and same subnet */
IPIF_LOCALADDR /* local loopback */
} ipif_type_t;
/*
* Pick the optimal ipif on `ill' for sending to destination `dst' from zone
* `zoneid'. We rate usable ipifs from low -> high as per the ipif_type_t
* enumeration, and return the highest-rated ipif. If there's a tie, we pick
* the first one, unless IPMP is used in which case we round-robin among them;
* see below for more.
*
* Returns NULL if there is no suitable source address for the ill.
* This only occurs when there is no valid source address for the ill.
*/
ipif_t *
{
else
return (NULL);
}
/*
* Test addresses should never be used for source address selection,
* so if we were passed one, switch to the IPMP meta-interface.
*/
if (IS_UNDER_IPMP(ill)) {
else
return (NULL);
}
/*
* If we're dealing with an unlabeled destination on a labeled system,
* make sure that we ignore source addresses that are incompatible with
* the destination's default label. That destination's default label
* must dominate the minimum label on the source address.
*/
if (is_system_labeled()) {
return (NULL);
}
}
/*
* After selecting the right ipif, under ill_lock make sure ipif is
* not condemned, and increment refcnt. If ipif is CONDEMNED,
* we retry. Inside the loop we still need to check for CONDEMNED,
* but not under a lock.
*/
/*
* For source address selection, we treat the ipif list as circular
* and continue until we get back to where we started. This allows
* IPMP to vary source address selection (which improves inbound load
* spreading) by caching its last ending point and starting from
* there. NOTE: we don't have to worry about ill_src_ipif changing
* ills since that can't happen on the IPMP ill.
*/
ipif = start_ipif;
do {
if (IPIF_IS_CONDEMNED(ipif))
continue;
/* Always skip NOLOCAL and ANYCAST interfaces */
continue;
/* Always skip NOACCEPT interfaces */
continue;
continue;
if (!ipif->ipif_addr_ready) {
continue;
}
continue;
/*
* Interfaces with 0.0.0.0 address are allowed to be UP, but
* are not valid as source addresses.
*/
continue;
/*
* Check compatibility of local address for destination's
* default label if we're on a labeled system. Incompatible
* addresses can't be used at all.
*/
continue;
if (incompat)
continue;
}
} else {
}
if (best_type == IPIF_LOCALADDR)
break; /* can't get better */
}
if (IPIF_IS_CONDEMNED(ipif)) {
goto retry;
}
/*
* For IPMP, update the source ipif rotor to the next ipif,
* provided we can look it up. (We must not use it if it's
* IPIF_CONDEMNED since we may have grabbed ill_g_lock after
* ipif_free() checked ill_src_ipif.)
*/
else
}
}
#ifdef DEBUG
char buf1[INET6_ADDRSTRLEN];
ip1dbg(("ipif_select_source_v4(%s, %s) -> NULL\n",
} else {
char buf1[INET6_ADDRSTRLEN];
char buf2[INET6_ADDRSTRLEN];
ip1dbg(("ipif_select_source_v4(%s, %s) -> %s\n",
}
#endif /* DEBUG */
return (ipif);
}
/*
* Pick a source address based on the destination ill and an optional setsrc
* address.
* The result is stored in srcp. If generation is set, then put the source
* generation number there before we look for the source address (to avoid
* missing changes in the set of source addresses.
* If flagsp is set, then us it to pass back ipif_flags.
*
* If the caller wants to cache the returned source address and detect when
* that might be stale, the caller should pass in a generation argument,
* which the caller can later compare against ips_src_generation
*
* The precedence order for selecting an IPv4 source address is:
* - RTF_SETSRC on the offlink ire always wins.
* - If usrsrc is set, swap the ill to be the usesrc one.
* - If IPMP is used on the ill, select a random address from the most
* preferred ones below:
* 1. If onlink destination, same subnet and not deprecated, not ALL_ZONES
* 2. Not deprecated, not ALL_ZONES
* 3. If onlink destination, same subnet and not deprecated, ALL_ZONES
* 4. Not deprecated, ALL_ZONES
* 5. If onlink destination, same subnet and deprecated
* 6. Deprecated.
*
* We have lower preference for ALL_ZONES IP addresses,
* as they pose problems with unlabeled destinations.
*
* Note that when multiple IP addresses match e.g., #1 we pick
* the first one if IPMP is not in use. With IPMP we randomize.
*/
int
{
*flagsp = 0;
/*
* Need to grab the generation number before we check to
* avoid a race with a change to the set of local addresses.
* No lock needed since the thread which updates the set of local
* barrier) before doing the atomic increase of ips_src_generation.
*/
if (generation != NULL) {
}
*srcp = multicast_ifaddr;
return (0);
}
/* Was RTF_SETSRC set on the first IRE in the recursive lookup? */
if (setsrc != INADDR_ANY) {
return (0);
}
if (notready)
return (ENETDOWN);
else
return (EADDRNOTAVAIL);
}
return (0);
}
/* ARGSUSED */
int
{
/*
* ill_phyint_reinit merged the v4 and v6 into a single
* ipsq. We might not have been able to complete the
* operation in ipif_set_values, if we could not become
* exclusive. If so restart it here.
*/
}
/*
* Can operate on either a module or a driver queue.
* Returns an error if not a module queue.
*/
/* ARGSUSED */
int
{
char *cp;
char interf_name[LIFNAMSIZ];
ip1dbg((
"if_unitsel: IF_UNITSEL: no q_next\n"));
return (EINVAL);
}
return (EALREADY);
do {
/*
* Here we are not going to delay the ioack until after
* ACKs from DL_ATTACH_REQ/DL_BIND_REQ. So no need to save the
* original ioctl message before sending the requests.
*/
}
/* ARGSUSED */
int
{
return (ENXIO);
}
/*
* Create any IRE_BROADCAST entries for `ipif', and store those entries in
* `irep'. Returns a pointer to the next free `irep' entry
* A mirror exists in ipif_delete_bcast_ires().
*
* The management of any "extra" or seemingly duplicate IRE_BROADCASTs is
* done in ire_add.
*/
static ire_t **
{
ip1dbg(("ipif_create_bcast_ires: creating broadcast IREs\n"));
/*
* For backward compatibility, we create net broadcast IREs based on
* the old "IP address class system", since some old machines only
* respond to these class derived net broadcast. However, we must not
* create these net broadcast IREs if the subnetmask is shorter than
* the IP address class based derived netmask. Otherwise, we may
* create a net broadcast address which is the same as an IP address
* on the subnet -- and then TCP will refuse to talk to that address.
*/
if (netmask < subnetmask) {
}
/*
* Don't create IRE_BROADCAST IREs for the interface if the subnetmask
* is 0xFFFFFFFF, as an IRE_LOCAL for that interface is already
* created. Creating these broadcast IREs will only create confusion
* as `addr' will be the same as the IP address.
*/
if (subnetmask != 0xFFFFFFFF) {
}
return (irep);
}
/*
* Mirror of ipif_create_bcast_ires()
*/
static void
{
/*
* For backward compatibility, we create net broadcast IREs based on
* the old "IP address class system", since some old machines only
* respond to these class derived net broadcast. However, we must not
* create these net broadcast IREs if the subnetmask is shorter than
* the IP address class based derived netmask. Otherwise, we may
* create a net broadcast address which is the same as an IP address
* on the subnet -- and then TCP will refuse to talk to that address.
*/
if (netmask < subnetmask) {
}
/*
* Don't create IRE_BROADCAST IREs for the interface if the subnetmask
* is 0xFFFFFFFF, as an IRE_LOCAL for that interface is already
* created. Creating these broadcast IREs will only create confusion
* as `addr' will be the same as the IP address.
*/
if (subnetmask != 0xFFFFFFFF) {
}
}
/*
* Extract both the flags (including IFF_CANTCHANGE) such as IFF_IPV*
* from lifr_flags and the name from lifr_name.
* Set IFF_IPV* and ill_isv6 prior to doing the lookup
* since ipif_lookup_on_name uses the _isv6 flags when matching.
* Returns EINPROGRESS when mp has been consumed by queueing it on
* ipx_pending_mp and the ioctl will complete in ip_rput.
*
* Can operate on either a module or a driver queue.
* Returns an error if not a module queue.
*/
/* ARGSUSED */
int
{
ip1dbg(("if_sioctl_slifname: SIOCSLIFNAME: no q_next\n"));
return (EINVAL);
}
/*
* If we are not writer on 'q' then this interface exists already
* and previous lookups (ip_extract_lifreq()) found this ipif --
* so return EALREADY.
*/
return (EALREADY);
return (EALREADY);
/*
* If there's another ill already with the requested name, ensure
* that it's of the same type. Otherwise, ill_phyint_reinit() will
* fuse together two unrelated ills, which will cause chaos.
*/
ip1dbg(("if_sioctl_slifname: SIOCSLIFNAME: attempt to "
"use the same ill name on differing media\n"));
return (EINVAL);
}
}
/*
* We start off as IFF_IPV4 in ipif_allocate and become
* IFF_IPV4 or IFF_IPV6 here depending on lifr_flags value.
* The only flags that we read from user space are IFF_IPV4,
* IFF_IPV6, and IFF_BROADCAST.
*
* This ill has not been inserted into the global list.
* So we are still single threaded and don't need any lock
*
* Saniy check the flags.
*/
ip1dbg(("ip_sioctl_slifname: link not broadcast capable "
"or IPv6 i.e., no broadcast \n"));
return (EINVAL);
}
ip1dbg(("ip_sioctl_slifname: flags must be exactly one of "
"IFF_IPV4 or IFF_IPV6\n"));
return (EINVAL);
}
/*
* We always start off as IPv4, so only need to check for IPv6.
*/
}
if ((new_flags & IFF_BROADCAST) != 0)
else
/* We started off as V4. */
}
}
/* ARGSUSED */
int
{
/*
* ill_phyint_reinit merged the v4 and v6 into a single
* ipsq. We might not have been able to complete the
* slifname in ipif_set_values, if we could not become
* exclusive. If so restart it here
*/
}
/*
* Return a pointer to the ipif which matches the index, IP version type and
* zoneid.
*/
ipif_t *
{
break;
}
}
}
return (ipif);
}
/*
* Change an existing physical interface's index. If the new index
* is acceptable we update the index and the phyint_list_avl_by_index tree.
* Finally, we update other systems which may have a dependence on the
* index value.
*/
/* ARGSUSED */
int
{
else
/*
* Only allow on physical interface. Also, index zero is illegal.
*/
return (EINVAL);
}
/* If the index is not changing, no work to do */
return (0);
/*
* Use phyint_exists() to determine if the new interface index
* is already in use. If the index is unused then we need to
* change the phyint's position in the phyint_list_avl_by_index
* tree. If we do not do this, subsequent lookups (using the new
* index value) will not find the phyint.
*/
return (EEXIST);
}
/*
* The new index is unused. Set it in the phyint. However we must not
* forget to trigger NE_IFINDEX_CHANGE event before the ifindex
* changes. The event must be bound to old ifindex value.
*/
/* Update SCTP's ILL list */
/* Send the routing sockets message */
/* Perhaps ilgs should use this ill */
return (0);
}
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_get_lifindex(%s:%u %p)\n",
/* Get the interface index */
} else {
}
return (0);
}
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_get_lifzone(%s:%u %p)\n",
/* Get the interface zone */
return (0);
}
/*
* Set the zoneid of an interface.
*/
/* ARGSUSED */
int
{
int err = 0;
if (!is_system_labeled())
return (ENOTSUP);
}
/* cannot assign instance zero to a non-global zone */
return (ENOTSUP);
/*
* Cannot assign to a zone that doesn't exist or is shutting down. In
* the event of a race with the zone shutdown processing, since IP
* serializes this ioctl and SIOCGLIFCONF/SIOCLIFREMOVEIF, we know the
* interface will be cleaned up even if the zone is shut down
* immediately after the status check. If the interface can't be brought
* down right away, and the zone is shut down before the restart
* function is called, we resolve the possible races by rechecking the
* zone status in the restart function.
*/
return (EINVAL);
return (EINVAL);
/*
* If the interface is already marked up,
* we call ipif_down which will take care
* of ditching any IREs that have been set
* up based on the old interface address.
*/
if (err == EINPROGRESS)
return (err);
(void) ipif_down_tail(ipif);
}
return (err);
}
static int
{
int err = 0;
ip1dbg(("ip_sioctl_zoneid_tail(%s:%u %p)\n",
if (CONN_Q(q))
ipst = CONNQ_TO_IPST(q);
else
ipst = ILLQ_TO_IPST(q);
/*
* For exclusive stacks we don't allow a different zoneid than
* global.
*/
zoneid != GLOBAL_ZONEID)
return (EINVAL);
/* Set the new zone id. */
/* Update sctp list */
/* The default multicast interface might have changed */
if (need_up) {
/*
* Now bring the interface back up. If this
* is the only IPIF for the ILL, ipif_up
* will have to re-bind to the device, so
* we may get back EINPROGRESS, in which
* case, this IOCTL will get completed in
* ip_rput_dlpi when we see the DL_BIND_ACK.
*/
}
return (err);
}
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_slifzone_restart(%s:%u %p)\n",
/*
* We recheck the zone status to resolve the following race condition:
* 1) process sends SIOCSLIFZONE to put hme0:1 in zone "myzone";
* 2) hme0:1 is up and can't be brought down right away;
* ip_sioctl_slifzone() returns EINPROGRESS and the request is queued;
* 3) zone "myzone" is halted; the zone status switches to
* 'shutting_down' and the zones framework sends SIOCGLIFCONF to list
* the interfaces to remove - hme0:1 is not returned because it's not
* yet in "myzone", so it won't be removed;
* 4) the restart function for SIOCSLIFZONE is called; without the
* status check here, we would have hme0:1 in "myzone" after it's been
* destroyed.
* Note that if the status check fails, we need to bring the interface
* back to its state prior to ip_sioctl_slifzone(), hence the call to
* ipif_up_done[_v6]().
*/
}
(void) ipif_up_done_v6(ipif);
} else {
(void) ipif_up_done(ipif);
}
return (EINVAL);
}
(void) ipif_down_tail(ipif);
B_TRUE));
}
/*
* Return the number of addresses on `ill' with one or more of the values
* in `set' set and all of the values in `clear' clear.
*/
static uint_t
{
cnt++;
return (cnt);
}
/*
* Return the number of migratable addresses on `ill' that are under
* application control.
*/
{
}
/*
* Return the number of point-to-point addresses on `ill'.
*/
{
}
/* ARGSUSED */
int
{
ip1dbg(("ip_sioctl_get_lifusesrc(%s:%u %p)\n",
return (0);
}
/* Find the previous ILL in this usesrc group */
static ill_t *
{
/* do nothing */;
return (ill);
}
/*
* Release all members of the usesrc group. This routine is called
* from ill_delete when the interface being unplumbed is the
* group head.
*
* This silently clears the usesrc that ifconfig setup.
* An alternative would be to keep that ifindex, and drop packets on the floor
* since no source address can be selected.
* Even if we keep the current semantics, don't need a lock and a linked list.
* Can walk all the ills checking if they have a ill_usesrc_ifindex matching
* the one that is being removed. Issue is how we return the usesrc users
* (SIOCGLIFSRCOF). We want to be able to find the ills which have an
* ill_usesrc_ifindex matching a target ill. We could also do that with an
* ill walk, but the walker would need to insert in the ioctl response.
*/
static void
{
do {
next_ill->ill_usesrc_ifindex = 0;
} while (next_ill->ill_usesrc_ifindex != 0);
}
/*
* Remove the client usesrc ILL from the list and relink to a new list
*/
int
{
/*
* Check if the usesrc client ILL passed in is not already
* in use as a usesrc ILL i.e one whose source address is
* in use OR a usesrc ILL is not already in use as a usesrc
* client ILL
*/
if ((ucill->ill_usesrc_ifindex == 0) ||
(uill->ill_usesrc_ifindex != 0)) {
return (-1);
}
/* Remove from the current list */
/* Only two elements in the list */
} else {
}
if (ifindex == 0) {
ucill->ill_usesrc_ifindex = 0;
return (0);
}
return (0);
}
/*
* Set the ill_usesrc and ill_usesrc_head fields. See synchronization notes in
* ip.c for locking details.
*/
/* ARGSUSED */
int
{
if (ifindex == 0) {
/* non usesrc group interface, nothing to reset */
return (0);
}
/* valid reset request */
}
if (usesrc_ill == NULL) {
return (ENXIO);
}
err = EINPROGRESS;
/* Operation enqueued on the ipsq of the usesrc ILL */
goto done;
}
/* USESRC isn't currently supported with IPMP */
goto done;
}
/*
* USESRC isn't compatible with the STANDBY flag. (STANDBY is only
* used by IPMP underlying interfaces, but someone might think it's
* more general and try to use it independently with VNI.)
*/
goto done;
}
/*
* If the client is already in use as a usesrc_ill or a usesrc_ill is
* already a client then return EINVAL
*/
goto done;
}
/*
* If the ill_usesrc_ifindex field is already set to what it needs to
* be then this is a duplicate operation.
*/
err = 0;
goto done;
}
ip1dbg(("ip_sioctl_slifusesrc: usesrc_cli_ill %s, usesrc_ill %s,"
usesrc_ill->ill_isv6));
/*
* ill_g_usesrc_lock global lock protects the ill_usesrc_grp_next
* and the ill_usesrc_ifindex fields
*/
if (reset_flg) {
if (ret != 0) {
}
goto done;
}
/*
* Four possibilities to consider:
* 1. Both usesrc_ill and usesrc_cli_ill are not part of any usesrc grp
* 2. usesrc_ill is part of a group but usesrc_cli_ill isn't
* 3. usesrc_cli_ill is part of a group but usesrc_ill isn't
* 4. Both are part of their respective usesrc groups
*/
/* Insert at head of list */
} else {
ifindex);
if (ret != 0)
}
done:
/* The refrele on the lifr_name ipif is done by ip_process_ioctl */
/* Let conn_ixa caching know that source address selection changed */
return (err);
}
/*
* comparison function used by avl.
*/
static int
{
/*
* let the phyint with the lowest index be on top.
*/
return (1);
return (-1);
return (0);
}
/*
* comparison function used by avl.
*/
static int
{
int res = 0;
else
if (res > 0)
return (1);
else if (res < 0)
return (-1);
return (0);
}
/*
* This function is called on the unplumb path via ill_glist_delete() when
* there are no ills left on the phyint and thus the phyint can be freed.
*/
static void
{
/*
* If this phyint was an IPMP meta-interface, blow away the group.
* This is safe to do because all of the illgrps have already been
* removed by I_PUNLINK, and thus SIOCSLIFGROUPNAME cannot find us.
* If we're cleaning up as a result of failed initialization,
* phyint_grp may be NULL.
*/
}
/*
* If this interface was under IPMP, take it out of the group.
*/
/*
* Delete the phyint and disassociate its ipsq. The ipsq itself
* will be freed in ipsq_exit().
*/
}
/*
* Attach the ill to the phyint structure which can be shared by both
* IPv4 and IPv6 ill. ill_init allocates a phyint to just hold flags. This
* function is called from ipif_set_values and ill_lookup_on_name (for
* loopback) where we know the name of the ill. We lookup the ill and if
* there is one present already with the name use that phyint. Otherwise
* reuse the one allocated by ill_init.
*/
static void
{
avl_index_t where = 0;
/*
* Now that our ill has a name, set it in the phyint.
*/
/*
* 1. We grabbed the ill_g_lock before inserting this ill into
* the global list of ills. So no other thread could have located
* this ill and hence the ipsq of this ill is guaranteed to be empty.
* 2. Now locate the other protocol instance of this ill.
* 3. Now grab both ill locks in the right order, and the phyint lock of
* the new ipsq. Holding ill locks + ill_g_lock ensures that the ipsq
* of neither ill can change.
* 4. Merge the phyint and thus the ipsq as well of this ill onto the
* other ill.
* 5. Release all locks.
*/
/*
* Look for IPv4 if we are initializing IPv6 or look for IPv6 if
* we are initializing IPv4.
*/
/*
* We are potentially throwing away phyint_flags which
* could be different from the one that we obtain from
* ill_other->ill_phyint. But it is okay as we are assuming
* that the state maintained within IP is correct.
*/
if (isv6) {
} else {
}
/*
* Delete the old phyint and make its ipsq eligible
* to be freed in ipsq_exit().
*/
} else {
/*
* We don't need to acquire any lock, since
* the ill is not yet visible globally and we
* have not yet released the ill_g_lock.
*/
/* XXX We need a recovery strategy here. */
}
/*
* Reassigning ill_phyint automatically reassigns the ipsq also.
* pending mp is not affected because that is per ill basis.
*/
/*
* Now that the phyint's ifindex has been assigned, complete the
* remaining
*/
} else {
}
/*
* Generate an event within the hooks framework to indicate that
* a new interface has just been added to IP. For this event to
* be generated, the network interface must, at least, have an
* ifindex assigned to it. (We don't generate the event for
* loopback since ill_lookup_on_name() has its own NE_PLUMB event.)
*
* This needs to be run inside the ill_g_lock perimeter to ensure
* that the ordering of delivered events to listeners matches the
* order of them in the kernel.
*/
if (!IS_LOOPBACK(ill)) {
}
}
/*
* Notify any downstream modules of the name of this interface.
* An M_IOCTL is used even though we don't expect a successful reply.
* Any reply message from the driver (presumably an M_IOCNAK) will
* eventually get discarded somewhere upstream. The message format is
* simply an SIOCSLIFNAME ioctl just as might be sent from ifconfig
* to IP.
*/
static void
{
return;
return;
}
}
static int
{
int err;
/* Set the obsolete NDD per-interface forwarding name. */
if (err != 0) {
err);
}
/*
* Now that ill_name is set, the configuration for the IPMP
* meta-interface can be performed.
*/
/*
* If phyi->phyint_grp is NULL, then this is the first IPMP
* meta-interface and we need to create the IPMP group.
*/
/*
* If someone has renamed another IPMP group to have
* the same name as our interface, bail.
*/
return (EEXIST);
}
return (ENOMEM);
}
}
}
/* Tell downstream modules where they are. */
ip_ifname_notify(ill, q);
/*
* ill_dl_phys returns EINPROGRESS in the usual case.
* Error cases are ENOMEM ...
*/
if (ipst->ips_mld_slowtimeout_id == 0) {
(void *)ipst,
}
} else {
if (ipst->ips_igmp_slowtimeout_id == 0) {
(void *)ipst,
}
}
return (err);
}
/*
* Common routine for ppa and ifname setting. Should be called exclusive.
*
* Returns EINPROGRESS when mp has been consumed by queueing it on
* ipx_pending_mp and the ioctl will complete in ip_rput.
*
* NOTE : If ppa is UNIT_MAX, we assign the next valid ppa and return
* the new name and new ppa in lifr_name and lifr_ppa respectively.
* For SLIFNAME, we pass these values back to the userland.
*/
static int
{
char *ppa_ptr;
char *old_ptr;
char old_char;
int error;
/* The ppa is sent down by ifconfig or is chosen */
return (EINVAL);
}
/*
* make sure ppa passed in is same as ppa in the name.
* This check is not made when ppa == UINT_MAX in that case ppa
* in the name could be anything. System will choose a ppa and
* update new_ppa_ptr and inter_name to contain the choosen ppa.
*/
if (*new_ppa_ptr != UINT_MAX) {
/* stoi changes the pointer */
/*
* ifconfig passed in 0 for the ppa for DLPI 1 style devices
* (they don't have an externally visible ppa). We assign one
* here so that we can manage the interface. Note that in
* the past this value was always 0 for DLPI 1 drivers.
*/
if (*new_ppa_ptr == 0)
return (EINVAL);
}
/*
* terminate string before ppa
* save char at that location.
*/
ppa_ptr[0] = '\0';
/*
* Finish as much work now as possible before calling ill_glist_insert
* which makes the ill globally visible and also merges it with the
* other protocol instance of this phyint. The remaining work is
* done after entering the ipsq which may happen sometime later.
* ill_set_ndd_name occurs after the ill has been made globally visible.
*/
/* We didn't do this when we allocated ipif in ip_ll_subnet_defaults */
}
/* Keep the !IN6_IS_ADDR_V4MAPPED assertions happy */
/*
* point-to-point or Non-mulicast capable
* interfaces won't do NUD unless explicitly
* configured to do so.
*/
}
/* Make sure IPv4 specific flag is not set on IPv6 if */
/*
* Note: xresolv interfaces will eventually need
* NOARP set here as well, but that will require
* those external resolvers to have some
* knowledge of that flag and act appropriately.
* Not to be changed at present.
*/
}
/*
* Set the ILLF_ROUTER flag according to the global
* IPv6 forwarding policy.
*/
if (ipst->ips_ipv6_forward != 0)
/*
* Set the ILLF_ROUTER flag according to the global
* IPv4 forwarding policy.
*/
if (ipst->ips_ip_g_forward != 0)
}
/*
* The ipIfStatsIfindex and ipv6IfIcmpIfIndex assignments will
* be completed in ill_glist_insert -> ill_phyint_reinit
*/
if (!ill_allocate_mibs(ill))
return (ENOMEM);
/*
* Pick a default sap until we get the DL_INFO_ACK back from
* the driver.
*/
ill->ill_ifname_pending_err = 0;
/*
* When the first ipif comes up in ipif_up_done(), multicast groups
* that were joined while this ill was not bound to the DLPI link need
* to be recovered by ill_recover_multicast().
*/
/*
* undo null termination done above.
*/
return (error);
}
/*
* When we return the buffer pointed to by interf_name should contain
* the same name as in ill_name.
* If a ppa was choosen by the system (ppa passed in was UINT_MAX)
* the buffer pointed to by new_ppa_ptr would not contain the right ppa
* so copy full name and update the ppa ptr.
* When ppa passed in != UINT_MAX all values are correct just undo
* null termination, this saves a bcopy.
*/
if (*new_ppa_ptr == UINT_MAX) {
} else {
/*
* undo null termination done above.
*/
}
/* Let SCTP know about this ILL */
/*
* ill_glist_insert has made the ill visible globally, and
* ill_phyint_reinit could have changed the ipsq. At this point,
* we need to hold the ips_ill_g_lock across the call to enter the
* ipsq to enforce atomicity and prevent reordering. In the event
* the ipsq has changed, and if the new ipsq is currently busy,
* we need to make sure that this half-completed ioctl is ahead of
* any subsequent ioctl. We achieve this by not dropping the
* ips_ill_g_lock which prevents any ill lookup itself thereby
* ensuring that new ioctls can't start.
*/
B_TRUE);
return (EINPROGRESS);
/*
* If ill_phyint_reinit() changed our ipsq, then start on the new ipsq.
*/
else
/*
* restore previous values
*/
}
return (error);
}
void
{
int i;
for (i = 0; i < MAX_G_HEADS; i++) {
}
sizeof (phyint_t),
sizeof (phyint_t),
}
/*
* Save enough information so that we can recreate the IRE if
* the interface goes down and then up.
*/
void
{
} else {
/* ire_gateway_addr_v6 can change due to RTM_CHANGE */
}
ill->ill_saved_ire_cnt++;
}
}
/*
* Remove one entry from ill_saved_ire_mp.
*/
void
{
/* Remove from ill_saved_ire_mp list if it is there */
/*
* On a given ill, the tuple of address, gateway, mask,
* ire_type, and zoneid is unique for each saved IRE.
*/
/* ire_gateway_addr_v6 can change - need lock */
continue;
&ire->ire_addr_v6) &&
&gw_addr_v6) &&
&ire->ire_mask_v6)) :
ill->ill_saved_ire_cnt--;
break;
}
}
}
/*
* IP multirouting broadcast routes handling
* Append CGTP broadcast IREs to regular ones created
* at ifconfig time.
* The usage is a route add <cgtp_bc> <nic_bc> -multirt i.e., both
* the destination and the gateway are broadcast addresses.
* The caller has verified that the destination is an IRE_BROADCAST and that
* RTF_MULTIRT was set. Here if the gateway is a broadcast address, then
* we create a MULTIRT IRE_BROADCAST.
* Note that the IRE_HOST created by ire_rt_add doesn't get found by anything
* since the IRE_BROADCAST takes precedence; ire_add_v4 does head insertion.
*/
static void
{
NULL);
/*
* We are in the special case of broadcasts for
* CGTP. We add an IRE_BROADCAST that holds
* the RTF_MULTIRT flag, the destination
* address and the low level
* info of ire_prim. In other words, CGTP
* broadcast is added to the redundant ipif.
*/
ip2dbg(("ip_cgtp_filter_bcast_add: ire_prim %p, ill_prim %p\n",
(uchar_t *)&ip_g_all_ones,
GLOBAL_ZONEID, /* CGTP is only for the global zone */
NULL,
ipst);
/*
* Here we assume that ire_add does head insertion so that
* the added IRE_BROADCAST comes before the existing IRE_HOST.
*/
}
ip2dbg(("ip_cgtp_filter_bcast_add: "
"added bcast_ire %p\n",
(void *)bcast_ire));
}
}
}
}
/*
* IP multirouting broadcast routes handling
* Remove the broadcast ire.
* The usage is a route delete <cgtp_bc> <nic_bc> -multirt i.e., both
* the destination and the gateway are broadcast addresses.
* The caller has only verified that RTF_MULTIRT was set. We check
* that the destination is broadcast and that the gateway is a broadcast
* address, and if so delete the IRE added by ip_cgtp_bcast_add().
*/
static void
{
ip2dbg(("ip_cgtp_filter_bcast_delete: "
"ire_prim %p, ill_prim %p\n",
ip2dbg(("ip_cgtp_filter_bcast_delete: "
"looked up bcast_ire %p\n",
(void *)bcast_ire));
}
}
}
}
/*
* Derive an interface id from the link layer address.
* Knows about IEEE 802 and IEEE EUI-64 mappings.
*/
static void
{
char *addr;
/*
* Note that some IPv6 interfaces get plumbed over links that claim to
* be DL_ETHER, but don't actually have Ethernet MAC addresses (e.g.
* PPP links). The ETHERADDRL check here ensures that we only set the
* interface ID on IPv6 interfaces above links that actually have real
* Ethernet addresses.
*/
/* Form EUI-64 like address */
}
}
/* ARGSUSED */
static void
{
}
typedef struct ipmp_ifcookie {
char ic_zonename[ZONENAME_MAX];
/*
* Construct a pseudo-random interface ID for the IPMP interface that's both
* predictable and (almost) guaranteed to be unique.
*/
static void
{
ipmp_ifcookie_t ic = { 0 };
}
/*
* Map the hash to an interface ID per the basic approach in RFC3041.
*/
}
/*
* Map the multicast in6_addr_t in m_ip6addr to the physaddr for ethernet.
*/
static void
{
/*
* Check PHYI_MULTI_BCAST and length of physical
* address to determine if we use the mapping or the
* broadcast address.
*/
return;
}
m_physaddr[0] = 0x33;
}
/*
* Map the multicast ipaddr_t in m_ipaddr to the physaddr for ethernet.
*/
static void
{
/*
* Check PHYI_MULTI_BCAST and length of physical
* address to determine if we use the mapping or the
* broadcast address.
*/
return;
}
m_physaddr[0] = 0x01;
}
/* ARGSUSED */
static void
{
/*
* for the MULTI_BCAST case and other cases when we want to
* use the link-layer broadcast address for multicast.
*/
if (ill->ill_sap_length < 0) {
} else {
}
}
/*
* Derive IPoIB interface id from the link layer address.
*/
static void
{
char *addr;
/*
* In IBA 1.1 timeframe, some vendors erroneously set the u/l bit
* in the globally assigned EUI-64 GUID to 1, in violation of IEEE
* rules. In these cases, the IBA considers these GUIDs to be in
* "Modified EUI-64" format, and thus toggling the u/l bit is not
* required; vendors are required not to assign global EUI-64's
* that differ only in u/l bit values, thus guaranteeing uniqueness
* of the interface identifier. Whether the GUID is in modified
* or proper EUI-64 format, the ipv6 identifier must have the u/l
* bit set to 1.
*/
}
/*
* Map the multicast ipaddr_t in m_ipaddr to the physaddr for InfiniBand.
* Note on mapping from multicast IP addresses to IPoIB multicast link
* addresses. IPoIB multicast link addresses are based on IBA link addresses.
* The format of an IPoIB multicast address is:
*
* 4 byte QPN Scope Sign. Pkey
* +--------------------------------------------+
* | 00FFFFFF | FF | 1X | X01B | Pkey | GroupID |
* +--------------------------------------------+
*
* The Scope and Pkey components are properties of the IBA port and
* network interface. They can be ascertained from the broadcast address.
* The Sign. part is the signature, and is 401B for IPv4 and 601B for IPv6.
*/
static void
{
0xff, 0x10, 0x40, 0x1b, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
/*
* RFC 4391: IPv4 MGID is 28-bit long.
*/
if (ill->ill_sap_length < 0) {
} else {
}
/*
*/
}
static void
{
0xff, 0x10, 0x60, 0x1b, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
/*
* RFC 4391: IPv4 MGID is 80-bit long.
*/
if (ill->ill_sap_length < 0) {
} else {
}
/*
*/
}
/*
* Derive IPv6 interface id from an IPv4 link-layer address (e.g. from an IPv4
* tunnel). The IPv4 address simply get placed in the lower 4 bytes of the
* IPv6 interface id. This is a suggested mechanism described in section 3.7
* of RFC4213.
*/
static void
{
}
/*
* Derive IPv6 interface id from an IPv6 link-layer address (e.g. from an IPv6
* tunnel). The lower 8 bytes of the IPv6 address simply become the interface
* id.
*/
static void
{
}
static void
{
}
static void
{
}
static void
{
}
static void
{
}
/*
* Lookup an ill and verify that the zoneid has an ipif on that ill.
* Returns an held ill, or NULL.
*/
ill_t *
{
return (NULL);
if (IPIF_IS_CONDEMNED(ipif))
continue;
continue;
return (ill);
}
return (NULL);
}
/*
* Return a pointer to an ipif_t given a combination of (ill_idx,ipif_id)
* If a pointer to an ipif_t is returned then the caller will need to do
* an ill_refrele().
*/
ipif_t *
{
return (NULL);
return (NULL);
}
if (!IPIF_CAN_LOOKUP(ipif))
continue;
break;
}
}
return (ipif);
}
/*
* Set ill_inputfn based on the current know state.
* This needs to be called when any of the factors taken into
* account changes.
*/
void
{
if (is_system_labeled())
else
} else {
if (is_system_labeled())
else if (ill->ill_dhcpinit != 0)
!= NULL)
else if (ipst->ips_ip_cgtp_filter &&
else
}
}
/*
* Re-evaluate ill_inputfn for all the IPv4 ills.
* Used when RSVP and CGTP comes and goes.
*/
void
{
}
/*
* Set the physical address information for `ill' to the contents of the
* dl_notify_ind_t pointed to by `mp'. Must be called as writer, and will be
* asynchronous if `ill' cannot immediately be quiesced -- in which case
* EINPROGRESS will be returned.
*/
int
{
/* Changing DL_IPV6_TOKEN is not yet supported */
return (0);
}
/*
* We need to store up to two copies of `mp' in `ill'. Due to the
* design of ipsq_pending_mp_add(), we can't pass them as separate
* arguments to ill_set_phys_addr_tail(). Instead, chain them
* together here, then pull 'em apart in ill_set_phys_addr_tail().
*/
return (ENOMEM);
}
/* no more nce addition allowed */
/*
* If we can quiesce the ill, then set the address. If not, then
* ill_set_phys_addr_tail() will be called from ipif_ill_refrele_tail().
*/
if (!ill_is_quiescent(ill)) {
/* call cannot fail since `conn_t *' argument is NULL */
return (EINPROGRESS);
}
return (0);
}
/*
* Once the ill associated with `q' has quiesced, set its physical address
* information to the values in `addrmp'. Note that two copies of `addrmp'
* are passed (linked by b_cont), since we sometimes need to save two distinct
* copies in the ill_t, and our context doesn't permit sleeping or allocation
* failure (we'll free the other copy if it's not needed). Since the ill_t
* is quiesced, we know any stale nce's with the old address information have
* already been removed, so we don't need to call nce_flush().
*/
/* ARGSUSED */
static void
{
int status;
case DL_IPV6_LINK_LAYER_ADDR:
break;
case DL_CURR_DEST_ADDR:
}
break;
case DL_CURR_PHYS_ADDR:
else
}
break;
default:
ASSERT(0);
}
/*
* If there are ipifs to bring up, ill_up_ipifs() will return
* EINPROGRESS, and ipsq_current_finish() will be called by
* ip_rput_dlpi_writer() or arp_bringup_done() when the last ipif is
* brought up.
*/
if (status != EINPROGRESS)
}
/*
* Helper routine for setting the ill_nd_lla fields.
*/
void
{
}
/*
* Replumb the ill.
*/
int
{
/* no more nce addition allowed */
/*
* If we can quiesce the ill, then continue. If not, then
* ill_replumb_tail() will be called from ipif_ill_refrele_tail().
*/
if (!ill_is_quiescent(ill)) {
/* call cannot fail since `conn_t *' argument is NULL */
return (EINPROGRESS);
}
return (0);
}
/* ARGSUSED */
static void
{
int err;
/* out of memory */
return;
}
if (!ill->ill_up_ipifs) {
/* already closing */
return;
}
/*
* Successfully quiesced and brought down the interface, now we send
* the DL_NOTE_REPLUMB_DONE message down to the driver. Reuse the
* DL_NOTE_REPLUMB message.
*/
/*
* For IPv4, we would usually get EINPROGRESS because the ETHERTYPE_ARP
* streams have to be unbound. When all the DLPI exchanges are done,
* ipsq_current_finish() will be called by arp_bringup_done(). The
* remainder of ipif bringup via ill_up_ipifs() will also be done in
* arp_bringup_done().
*/
if (err == EINPROGRESS)
return;
else
return;
}
}
/*
* Issue ioctl `cmd' on `lh'; caller provides the initial payload in `buf'
* which is `bufsize' bytes. On success, zero is returned and `buf' updated
* as per the ioctl. On failure, an errno is returned.
*/
static int
{
int rval;
}
/*
* Issue an SIOCGLIFCONF for address family `af' and store the result into a
* dynamically-allocated `lifcp' that will be `bufsizep' bytes on success.
*/
static int
{
int err;
return (err);
/*
* Pad the interface count to account for additional interfaces that
* may have been configured between the SIOCGLIFNUM and SIOCGLIFCONF.
*/
if (err != 0) {
return (err);
}
return (0);
}
/*
* Helper for ip_interface_cleanup() that removes the loopback interface.
*/
static void
{
int err;
if (err != 0) {
ip0dbg(("ip_loopback_removeif: IP%s SIOCLIFREMOVEIF failed: "
}
}
/*
* Helper for ip_interface_cleanup() that ensures no IP interfaces are in IPMP
* groups and that IPMP data addresses are down. These conditions must be met
* so that IPMP interfaces can be I_PUNLINK'd, as per ip_sioctl_plink_ipmp().
*/
static void
{
int i, nifs;
int err;
"(error %d); any IPMP interfaces cannot be shutdown", err);
return;
}
if (err != 0) {
continue;
}
continue;
if (err != 0) {
"bring down (error %d); IPMP interface may "
}
/*
* Check if IFF_DUPLICATE is still set -- and if so,
* reset the address to clear it.
*/
continue;
"reset DAD (error %d); IPMP interface may "
}
continue;
}
if (err != 0) {
"IPMP group (error %d); associated IPMP interface "
continue;
}
}
}
/*
* Remove the loopback interfaces and prep the IPMP interfaces to be torn down.
* Non-loopback interfaces are either I_LINK'd or I_PLINK'd; the former go away
* when the user-level processes in the zone are killed and the latter are
* cleaned up by str_stack_shutdown().
*/
void
{
int err;
int i;
" error %d", err);
return;
}
/*
* NOTE: loop executes exactly twice and is hardcoded to know that the
* first iteration is IPv6. (Unrolling yields repetitious code, hence
* the loop.)
*/
for (i = 0; i < 2; i++) {
if (err != 0) {
continue;
}
}
}
/*
* This needs to be in-sync with nic_event_t definition
*/
static const char *
{
switch (event) {
case NE_PLUMB:
return ("PLUMB");
case NE_UNPLUMB:
return ("UNPLUMB");
case NE_UP:
return ("UP");
case NE_DOWN:
return ("DOWN");
case NE_ADDRESS_CHANGE:
return ("ADDRESS_CHANGE");
case NE_LIF_UP:
return ("LIF_UP");
case NE_LIF_DOWN:
return ("LIF_DOWN");
case NE_IFINDEX_CHANGE:
return ("IFINDEX_CHANGE");
default:
return ("UNKNOWN");
}
}
void
{
/* create a new nic event info */
goto fail;
goto fail;
}
DDI_NOSLEEP) == DDI_SUCCESS)
return;
fail:
}
}
ip2dbg(("ill_nic_event_dispatch: could not dispatch %s nic event "
}
static int
{
int err = 0;
}
if (res_act != Res_act_initial)
return (EINVAL);
}
/* add unicast nce for the local addr */
/*
* If we're here via ipif_up(), then the ipif
* won't be bound yet -- add it to the group,
* which will bind it if possible. (We would
* add it in ipif_up(), but deleting on failure
* there is gruesome.) If we're here via
* ipmp_ill_bind_ipif(), then the ipif has
* already been added to the group and we
* just need to use the binding.
*/
/*
* We couldn't bind the ipif to an ill
* yet, so we have nothing to publish.
* Mark the address as ready and return.
*/
return (0);
}
added_ipif = B_TRUE;
}
} else {
}
/*
* If this is an initial bring-up (or the ipif was never
* completely brought up), do DAD. Otherwise, we're here
* because IPMP has rebound an address to this ill: send
* unsolicited advertisements (ARP announcements) to
* inform others.
*/
} else {
flags |= NCE_F_UNSOL_ADV;
}
/*
* note that we may encounter EEXIST if we are moving
* the nce as a result of a rebind operation.
*/
switch (err) {
case 0:
nce->nce_ipif_cnt++;
break;
case EEXIST:
ip1dbg(("ipif_arp_up: NCE already exists for %s\n",
/*
* A leftover nce from before this address
* existed
*/
goto retry;
}
ip1dbg(("ipif_arp_up: NCE already exists "
goto arp_up_done;
}
/*
* Duplicate local addresses are permissible for
* IPIF_POINTOPOINT interfaces which will get marked
* IPIF_UNNUMBERED later in
* ip_addr_availability_check().
*
* The nce_ipif_cnt field tracks the number of
* ipifs that have nce_addr as their local address.
*/
nce->nce_ipif_cnt++;
err = 0;
break;
default:
goto arp_up_done;
}
if (arp_no_defense) {
}
} else {
/* zero address. nothing to publish */
}
if (added_ipif && err != 0)
return (err);
}
int
{
int err = 0;
/*
* need to bring up ARP or setup mcast mapping only
* when the first interface is coming UP.
*/
/*
* Send ATTACH + BIND
*/
return (err);
/*
* Add NCE for local address. Start DAD.
* we'll wait to hear that DAD has finished
* before using the interface.
*/
if (err == EINPROGRESS)
}
if (!wait_for_dlpi)
return (!wait_for_dlpi ? 0 : EINPROGRESS);
}
/*
* Finish processing of "arp_up" after all the DLPI message
* exchanges have completed between arp and the driver.
*/
void
{
queue_t *q;
return;
/*
* If an IOCTL is waiting on this (ipsq_current_ioctl != 0), then we
* must have an associated conn_t. Otherwise, we're bringing this
* interface back up as part of handling an asynchronous event (e.g.,
* physical address change).
*/
q = CONNP_TO_WQ(connp);
} else {
}
if (err == 0) {
ip0dbg(("arp_bringup_done: init failed\n"));
} else {
if (err != 0 ||
ip0dbg(("arp_bringup_done: "
"init failed err %x\n", err));
(void) ipif_arp_down(ipif);
}
}
} else {
ip0dbg(("arp_bringup_done: DL_BIND_REQ failed\n"));
}
if (err == EINPROGRESS)
return;
}
/*
* If we have a moved ipif to bring up, and everything has succeeded
* to this point, bring it up on the IPMP ill. Otherwise, leave it
* down -- the admin can try to bring it up by hand if need be.
*/
if (err == 0) {
if (err == EINPROGRESS)
return;
}
}
/*
* The operation must complete without EINPROGRESS since
* ipsq_pending_mp_get() has removed the mblk from ipsq_pending_mp.
* Otherwise, the operation will be stuck forever in the ipsq.
*/
} else {
}
}
/*
* Finish processing of arp replumb after all the DLPI message
* exchanges have completed between arp and the driver.
*/
void
{
queue_t *q;
ip0dbg(("arp_replumb_done: bringup aborted ioctl %x\n",
/* bringup was aborted by the user */
return;
}
/*
* If an IOCTL is waiting on this (ipsq_current_ioctl != 0), then we
* must have an associated conn_t. Otherwise, we're bringing this
* interface back up as part of handling an asynchronous event (e.g.,
* physical address change).
*/
q = CONNP_TO_WQ(connp);
} else {
}
if (err == EINPROGRESS)
return;
}
/*
* The operation must complete without EINPROGRESS since
* ipsq_pending_mp_get() has removed the mblk from ipsq_pending_mp.
* Otherwise, the operation will be stuck forever in the ipsq.
*/
DTRACE_PROBE4(ipif__ioctl, char *,
"arp_replumb_done finish",
} else {
}
}
void
{
}
/*
* ILB ioctl uses cv_wait (such as deleting a rule or adding a server) and
* this assumes the context is cv_wait'able. Hence it shouldnt' be used on
* TPI end points with STREAMS modules pushed above. This is assured by not
* having the IPI_MODOK flag for the ioctl. And IP ensures the ILB ioctl
* never ends up on an ipsq, otherwise we may end up processing the ioctl
* while unwinding from the ispq and that could be a thread from the bottom.
*/
/* ARGSUSED */
int
{
int ret = 0;
int i;
ipst = CONNQ_TO_IPST(q);
switch (command) {
case ILB_CREATE_RULE: {
break;
}
break;
}
case ILB_DESTROY_RULE:
case ILB_ENABLE_RULE:
case ILB_DISABLE_RULE: {
break;
}
if (command == ILB_DESTROY_RULE) {
break;
} else if (command == ILB_ENABLE_RULE) {
break;
} else if (command == ILB_DISABLE_RULE) {
break;
}
} else {
if (command == ILB_DESTROY_RULE) {
} else if (command == ILB_ENABLE_RULE) {
NULL);
} else if (command == ILB_DISABLE_RULE) {
NULL);
}
}
break;
}
case ILB_NUM_RULES: {
break;
}
break;
}
case ILB_RULE_NAMES: {
break;
}
break;
}
break;
}
case ILB_NUM_SERVERS: {
break;
}
break;
}
case ILB_LIST_RULE: {
break;
}
break;
}
case ILB_LIST_SERVERS: {
cmd->num_servers == 0) {
break;
}
break;
}
&cmd->num_servers);
break;
}
case ILB_ADD_SERVERS: {
break;
}
break;
}
break;
}
for (i = 0; i < cmd->num_servers; i++) {
}
break;
}
case ILB_DEL_SERVERS:
case ILB_ENABLE_SERVERS:
case ILB_DISABLE_SERVERS: {
int (*f)();
break;
}
break;
}
if (command == ILB_DEL_SERVERS)
f = ilb_server_del;
else if (command == ILB_ENABLE_SERVERS)
f = ilb_server_enable;
else if (command == ILB_DISABLE_SERVERS)
f = ilb_server_disable;
break;
}
for (i = 0; i < cmd->num_servers; i++) {
ilb_server_arg_t *s;
}
break;
}
case ILB_LIST_NAT_TABLE: {
break;
}
break;
}
break;
}
case ILB_LIST_STICKY_TABLE: {
break;
}
break;
}
break;
}
default:
break;
}
done:
return (ret);
}
/* Remove all cache entries for this logical interface */
void
{
if (ipif->ipif_added_nce) {
else
if (--nce->nce_ipif_cnt == 0)
ipif->ipif_added_nce = 0;
} else {
/*
* nce may already be NULL because it was already
* flushed, e.g., due to a call to nce_flush
*/
ipif->ipif_added_nce = 0;
}
}
/*
* Make IPMP aware of the deleted data address.
*/
/*
* Remove all other nces dependent on this ill when the last ipif
* is going away.
*/
if (ill->ill_ipif_up_count == 0) {
if (IS_UNDER_IPMP(ill))
}
}
/*
* find the first interface that uses usill for its source address.
*/
ill_t *
{
/* ill_g_usesrc_lock protects ill_usesrc_grp_next */
!ILL_IS_CONDEMNED(ill)) {
break;
}
}
return (ill);
}