ip_ire.c revision 87c3980e28619b2b20d03f92d14b18fd89c183ca
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1990 Mentat Inc. */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file contains routines that manipulate Internet Routing Entries (IREs).
*/
#include <inet/ipsec_info.h>
#include <inet/ipclassifier.h>
/*
* Synchronization notes:
*
* The fields of the ire_t struct are protected in the following way :
*
*
* - bucket lock of the respective tables (cache or forwarding tables).
*
* ire_fp_mp
* ire_dlureq_mp
*
* - ire_lock protects multiple threads updating ire_fp_mp
* simultaneously. Otherwise no locks are used while accessing
*
* ire_mp, ire_rfq, ire_stq, ire_u *except* ire_gateway_addr[v6], ire_mask,
* ire_type, ire_create_time, ire_masklen, ire_ipversion, ire_flags, ire_ipif,
* ire_ihandle, ire_phandle, ire_nce, ire_bucket, ire_in_ill, ire_in_src_addr
*
* - Set in ire_create_v4/v6 and never changes after that. Thus,
* we don't need a lock whenever these fields are accessed.
*
* - ire_bucket and ire_masklen (also set in ire_create) is set in
* ire_add_v4/ire_add_v6 before inserting in the bucket and never
* changes after that. Thus we don't need a lock whenever these
* fields are accessed.
*
* ire_gateway_addr_v4[v6]
*
* - ire_gateway_addr_v4[v6] is set during ire_create and later modified
* by rts_setgwr[v6]. As ire_gateway_addr is a uint32_t, updates to
* it assumed to be atomic and hence the other parts of the code
* does not use any locks. ire_gateway_addr_v6 updates are not atomic
*
* ire_ident, ire_refcnt
*
* - Updated atomically using atomic_add_32
*
* ire_ssthresh, ire_rtt_sd, ire_rtt, ire_ib_pkt_count, ire_ob_pkt_count
*
* - Assumes that 32 bit writes are atomic. No locks. ire_lock is
* used to serialize updates to ire_ssthresh, ire_rtt_sd, ire_rtt.
*
* ire_max_frag, ire_frag_flag
*
*
* ire_tire_mark
*
* - Set in ire_create and updated in ire_expire, which is called
* by only one function namely ip_trash_timer_expire. Thus only
* one function updates and examines the value.
*
* ire_marks
* - bucket lock protects this.
*
*
* - Place holder for returning the information to the upper layers
* when IRE_DB_REQ comes down.
*
* ip_ire_default_count protected by the bucket lock of
* ip_forwarding_table[0][0].
*
* ipv6_ire_default_count is protected by the bucket lock of
* ip_forwarding_table_v6[0][0].
*
* ip_ire_default_index/ipv6_ire_default_index is not protected as it
* is just a hint at which default gateway to use. There is nothing
* wrong in using the same gateway for two different connections.
*
* As we always hold the bucket locks in all the places while accessing
* the above values, it is natural to use them for protecting them.
*
* We have a separate cache table and forwarding table for IPv4 and IPv6.
* Cache table (ip_cache_table/ip_cache_table_v6) is a pointer to an
* array of irb_t structure and forwarding table (ip_forwarding_table/
* ip_forwarding_table_v6) is an array of pointers to array of irb_t
* structure. ip_forwarding_table[_v6] is allocated dynamically in
* ire_add_v4/v6. ire_ft_init_lock is used to serialize multiple threads
* initializing the same bucket. Once a bucket is initialized, it is never
* de-alloacted. This assumption enables us to access ip_forwarding_table[i]
* or ip_forwarding_table_v6[i] without any locks.
*
* Each irb_t - ire bucket structure has a lock to protect
* a bucket and the ires residing in the bucket have a back pointer to
* the bucket structure. It also has a reference count for the number
* of threads walking the bucket - irb_refcnt which is bumped up
* using the macro IRB_REFHOLD macro. The flags irb_flags can be
* set to IRE_MARK_CONDEMNED indicating that there are some ires
* in this bucket that are marked with IRE_MARK_CONDEMNED and the
* last thread to leave the bucket should delete the ires. Usually
* this is done by the IRB_REFRELE macro which is used to decrement
* the reference count on a bucket.
*
* IRE_REFHOLD/IRE_REFRELE macros operate on the ire which increments/
* decrements the reference count, ire_refcnt, atomically on the ire.
* ire_refcnt is modified only using this macro. Operations on the IRE
* could be described as follows :
*
* CREATE an ire with reference count initialized to 1.
*
* ADDITION of an ire holds the bucket lock, checks for duplicates
* and then adds the ire. ire_add_v4/ire_add_v6 returns the ire after
* bumping up once more i.e the reference count is 2. This is to avoid
* an extra lookup in the functions calling ire_add which wants to
* work with the ire after adding.
*
* LOOKUP of an ire bumps up the reference count using IRE_REFHOLD
* macro. It is valid to bump up the referece count of the IRE,
* after the lookup has returned an ire. Following are the lookup
* functions that return an HELD ire :
*
* ire_lookup_local[_v6], ire_ctable_lookup[_v6], ire_ftable_lookup[_v6],
* ire_cache_lookup[_v6], ire_lookup_multi[_v6], ire_route_lookup[_v6],
* ipif_to_ire[_v6], ire_mrtun_lookup, ire_srcif_table_lookup.
*
* DELETION of an ire holds the bucket lock, removes it from the list
* and then decrements the reference count for having removed from the list
* by using the IRE_REFRELE macro. If some other thread has looked up
* the ire, the reference count would have been bumped up and hence
* this ire will not be freed once deleted. It will be freed once the
* reference count drops to zero.
*
* Add and Delete acquires the bucket lock as RW_WRITER, while all the
* lookups acquire the bucket lock as RW_READER.
*
* NOTE : The only functions that does the IRE_REFRELE when an ire is
* passed as an argument are :
*
* 1) ip_wput_ire : This is because it IRE_REFHOLD/RELEs the
* broadcast ires it looks up internally within
* the function. Currently, for simplicity it does
* not differentiate the one that is passed in and
* the ones it looks up internally. It always
* IRE_REFRELEs.
* 2) ire_send
* ire_send_v6 : As ire_send calls ip_wput_ire and other functions
* that take ire as an argument, it has to selectively
* IRE_REFRELE the ire. To maintain symmetry,
* ire_send_v6 does the same.
*
* Otherwise, the general rule is to do the IRE_REFRELE in the function
* that is passing the ire as an argument.
*
* In trying to locate ires the following points are to be noted.
*
* IRE_MARK_CONDEMNED signifies that the ire has been logically deleted and is
* to be ignored when walking the ires using ire_next.
*
* IRE_MARK_HIDDEN signifies that the ire is a special ire typically for the
* benefit of in.mpathd which needs to probe interfaces for failures. Normal
* applications should not be seeing this ire and hence this ire is ignored
* in most cases in the search using ire_next.
*
* Zones note:
* Walking IREs within a given zone also walks certain ires in other
* zones. This is done intentionally. IRE walks with a specified
* zoneid are used only when doing informational reports, and
* zone users want to see things that they can access. See block
* comment in ire_walk_ill_match().
*/
/* This is dynamically allocated in ip_ire_init */
static irb_t *ip_cache_table;
/* This is dynamically allocated in ire_add_mrtun */
/*
* ire_ft_init_lock is used while initializing ip_forwarding_table
* dynamically in ire_add.
*/
/*
* The following counts are used to determine whether a walk is
* needed through the reverse tunnel table or through ills
*/
/*
* A per-interface routing table is created ( if not present)
* when the first entry is added to this special routing table.
* This special routing table is accessed through the ill data structure.
* The routing table looks like cache table. For example, currently it
* is used by mobile-ip foreign agent to forward data that only comes from
* the home agent tunnel for a mobile node. Thus if the outgoing interface
* is a RESOLVER interface, IP may need to resolve the hardware address for
* the outgoing interface. The routing entries in this table are not updated
* in IRE_CACHE. When MCTL msg comes back from ARP, the incoming ill informa-
* tion is lost as the write queue is passed to ip_wput.
* But, before sending the packet out, the hardware information must be updated
* in the special forwarding table. ire_srcif_table_count keeps track of total
* number of ires that are in interface based tables. Each interface based
* table hangs off of the incoming ill and each ill_t also keeps a refcnt
* of ires in that table.
*/
/*
* The minimum size of IRE cache table. It will be recalcuated in
* ip_ire_init().
*/
/*
* The size of the forwarding table. We will make sure that it is a
* power of 2 in ip_ire_init().
*/
struct kmem_cache *ire_cache;
/*
* The threshold number of IRE in a bucket when the IREs are
* cleaned up. This threshold is calculated later in ip_open()
* based on the speed of CPU and available memory. This default
* value is the maximum.
*
* We have two kinds of cached IRE, temporary and
* non-temporary. Temporary IREs are marked with
* IRE_MARK_TEMPORARY. They are IREs created for non
* TCP traffic and for forwarding purposes. All others
* are non-temporary IREs. We don't mark IRE created for
* TCP as temporary because TCP is stateful and there are
* info stored in the IRE which can be shared by other TCP
* connections to the same destination. For connected
* endpoint, we also don't want to mark the IRE used as
* temporary because the same IRE will be used frequently,
* otherwise, the app should not do a connect(). We change
* the marking at ip_bind_connected_*() if necessary.
*
* We want to keep the cache IRE hash bucket length reasonably
* short, otherwise IRE lookup functions will take "forever."
* We use the "crude" function that the IRE bucket
* length should be based on the CPU speed, which is 1 entry
* per x MHz, depending on the shift factor ip_ire_cpu_ratio
* (n). This means that with a 750MHz CPU, the max bucket
* length can be (750 >> n) entries.
*
* Note that this threshold is separate for temp and non-temp
* IREs. This means that the actual bucket length can be
* twice as that. And while we try to keep temporary IRE
* length at most at the threshold value, we do not attempt to
* make the length for non-temporary IREs fixed, for the
* reason stated above. Instead, we start trying to find
* "unused" non-temporary IREs when the bucket length reaches
* this threshold and clean them up.
*
* We also want to limit the amount of memory used by
* IREs. So if we are allowed to use ~3% of memory (M)
* for those IREs, each bucket should not have more than
*
* M / num of cache bucket / sizeof (ire_t)
*
* Again the above memory uses are separate for temp and
* non-temp cached IREs.
*
* We may also want the limit to be a function of the number
* of interfaces and number of CPUs. Doing the initialization
* in ip_open() means that every time an interface is plumbed,
* the max is re-calculated. Right now, we don't do anything
* different. In future, when we have more experience, we
* may want to change this behavior.
*/
/*
* The minimum of the temporary IRE bucket count. We do not want
* the length of each bucket to be too short. This may hurt
* performance of some apps as the temporary IREs are removed too
* often.
*/
/*
* The ratio of memory consumed by IRE used for temporary to available
* memory. This is a shift factor, so 6 means the ratio 1 to 64. This
*/
/* The shift factor for CPU speed to calculate the max IRE bucket length. */
/*
* The maximum number of buckets in IRE cache table. In future, we may
* want to make it a dynamic hash table. For the moment, we fix the
* size and allocate the table in ip_ire_init() when IP is first loaded.
* We take into account the amount of memory a system has.
*/
#define IP_MAX_CACHE_TABLE_SIZE 4096
/* Zero iulp_t for initialization. */
const iulp_t ire_uinfo_null = { 0 };
extern void th_trace_rrecord(th_trace_t *);
#ifdef IRE_DEBUG
static void ire_trace_inactive(ire_t *);
#endif
/*
* To avoid bloating the code, we call this function instead of
* using the macro IRE_REFRELE. Use macro only in performance
* critical paths.
*
* 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 ire_refrele -> ipif_ill_refrele_tail -> qwriter_ip trying
* to restart an ioctl. The one exception is when the caller is sure that
* this is not the last reference to be released. Eg. if the caller is
* sure that the ire has not been deleted and won't be deleted.
*/
void
{
}
void
{
}
/*
* kmem_cache_alloc constructor for IRE in kma space.
* Note that when ire_mp is set the IRE is stored in that mblk and
* not in this cache.
*/
/* ARGSUSED */
static int
{
return (0);
}
/* ARGSUSED1 */
static void
{
}
/*
* This function is associated with the IP_IOC_IRE_ADVISE_NO_REPLY
* IOCTL. It is used by TCP (or other ULPs) to supply revised information
* for an existing CACHED IRE.
*/
/* ARGSUSED */
int
{
/*
* Check privilege using the ioctl credential; if it is NULL
* then this is a kernel message and therefor privileged.
*/
return (EPERM);
ipic->ipic_addr_length))) {
return (EINVAL);
}
return (EINVAL);
switch (ipic->ipic_addr_length) {
case IP_ADDR_LEN: {
/* Extract the destination address. */
/* Find the corresponding IRE. */
break;
}
case IPV6_ADDR_LEN: {
/* Extract the destination address. */
/* Find the corresponding IRE. */
break;
}
default:
return (EINVAL);
}
return (ENOENT);
/*
*
* We serialize multiple advises using ire_lock.
*/
/*
* If there is no old cached values, initialize them
* conservatively. Set them to be (1.5 * new value).
*/
} else {
}
} else {
}
}
if (ipic->ipic_max_frag)
if (ipic->ipic_ssthresh != 0) {
(ipic->ipic_ssthresh +
else
}
/*
* Don't need the ire_lock below this. ire_type does not change
* after initialization. ire_marks is protected by irb_lock.
*/
/*
* Only increment the temporary IRE count if the original
* IRE is not already marked temporary.
*/
irb->irb_tmp_ire_cnt++;
}
}
return (0);
}
/*
* This function is associated with the IP_IOC_IRE_DELETE[_NO_REPLY]
* IOCTL[s]. The NO_REPLY form is used by TCP to delete a route IRE
* for a host that is not responding. This will force an attempt to
* establish a new route, if available. Management processes may want
* to use the version that generates a reply.
*
* This function does not support IPv6 since Neighbor Unreachability Detection
* means that negative advise like this is useless.
*/
/* ARGSUSED */
int
{
/*
* Check privilege using the ioctl credential; if it is NULL
* then this is a kernel message and therefor privileged.
*/
return (EPERM);
/* Only actions on IRE_CACHEs are acceptable at present. */
return (EINVAL);
return (EINVAL);
switch (ipid->ipid_addr_length) {
case IP_ADDR_LEN:
/* addr_ucp points at IP addr */
break;
case sizeof (sin_t): {
/*
* got complete (sockaddr) address - increment addr_ucp to point
* at the ip_addr field.
*/
break;
}
default:
return (EINVAL);
}
/* Extract the destination address. */
/* Try to find the CACHED IRE. */
/* Nail it. */
if (ire) {
/* Allow delete only on CACHE entries */
return (EINVAL);
}
/*
* Verify that the IRE has been around for a while.
* This is to protect against transport protocols
* that are too eager in sending delete messages.
*/
if (gethrestime_sec() <
return (EINVAL);
}
/*
* Now we have a potentially dead cache entry. We need
* to remove it.
* If this cache entry is generated from a default route,
* search the default list and mark it dead and some
* background process will try to activate it.
*/
/*
* Make sure that we pick a different
* IRE_DEFAULT next time.
* The ip_ire_default_count tracks the number of
* IRE_DEFAULT entries. However, the
* ip_forwarding_table[0] also contains
* interface routes thus the count can be zero.
*/
ip_ire_default_count != 0) {
/*
* We grab it as writer just to serialize
* multiple threads trying to bump up
* ip_ire_default_index.
*/
goto done;
}
/* Skip past the potentially bad gateway */
if (ire->ire_gateway_addr ==
}
}
done:
/* report the bad route to routing sockets */
}
/* Also look for an IRE_HOST_REDIRECT and remove it if present */
/* Nail it. */
if (ire) {
if (!routing_sock_info) {
ire->ire_src_addr, 0, 0, 0,
}
}
return (0);
}
/*
* Named Dispatch routine to produce a formatted report on all IREs.
* This report is accessed by using the ndd utility to "get" ND variable
* "ipv4_ire_status".
*/
/* ARGSUSED */
int
{
(void) mi_mpprintf(mp,
"IRE " MI_COL_HDRPAD_STR
/* 01234567[89ABCDEF] */
"rfq " MI_COL_HDRPAD_STR
/* 01234567[89ABCDEF] */
"stq " MI_COL_HDRPAD_STR
/* 01234567[89ABCDEF] */
" zone "
/* 12345 */
"addr mask "
/* 123.123.123.123 123.123.123.123 */
"src gateway mxfrg rtt rtt_sd ssthresh ref "
/* 123.123.123.123 123.123.123.123 12345 12345 123456 12345678 123 */
"rtomax tstamp_ok wscale_ok ecn_ok pmtud_ok sack sendpipe "
/* 123456 123456789 123456789 123456 12345678 1234 12345678 */
/*
* Because of the ndd constraint, at most we can have 64K buffer
* to put in all IRE info. So to be more efficient, just
* allocate a 64K buffer here, assuming we need that large buffer.
*/
/* The following may work even if we cannot get a large buf. */
return (0);
}
if (zoneid == GLOBAL_ZONEID)
return (0);
}
/* ire_walk routine invoked for ip_ire_report for each IRE. */
static void
{
char buf1[16];
char buf2[16];
char buf3[16];
char buf4[16];
int ref;
return;
if (buf_len <= 0)
return;
/* Number of active references of this ire */
/* "inbound" to a non local address is a forward */
fo_pkt_count = 0;
ib_pkt_count = 0;
}
"%s %s %s %s %05d %05ld %06ld %08d %03d %06d %09d %09d %06d %08d "
"%04d %08d %08d %d/%d/%d %s\n",
(int)ire->ire_zoneid,
} else {
}
}
/* ire_walk routine invoked for ip_ire_report for each cached IRE. */
static void
{
char buf1[16];
char buf2[16];
char buf3[16];
char buf4[16];
int ref;
return;
if (buf_len <= 0)
return;
/* Number of active references of this ire */
/* "inbound" to a non local address is a forward */
fo_pkt_count = 0;
ib_pkt_count = 0;
}
"%s %s %s %s %05d %05ld %06ld %08d %03d %06d %09d %09d %06d %08d "
"%04d %08d %08d %d/%d/%d %s\n",
(int)ire->ire_zoneid,
} else {
}
}
/* ARGSUSED */
int
{
(void) mi_mpprintf(mp,
"IRE " MI_COL_HDRPAD_STR
/* 01234567[89ABCDEF] */
"stq " MI_COL_HDRPAD_STR
/* 01234567[89ABCDEF] */
"in_ill " MI_COL_HDRPAD_STR
/* 01234567[89ABCDEF] */
"in_src_addr "
/* 123.123.123.123 */
"max_frag "
/* 12345 */
"ref ");
/* 123 */
return (0);
}
/* mrtun report table - supports ipv4_mrtun_ire_status ndd variable */
static void
{
char buf1[INET_ADDRSTRLEN];
int ref;
/* Number of active references of this ire */
"%s %05d %03d",
(void *)ire->ire_in_ill,
}
/*
* Dispatch routine to format ires in interface based routine
*/
/* ARGSUSED */
int
{
/* Report all interface based ires */
(void) mi_mpprintf(mp,
"IRE " MI_COL_HDRPAD_STR
/* 01234567[89ABCDEF] */
"stq " MI_COL_HDRPAD_STR
/* 01234567[89ABCDEF] */
"in_ill " MI_COL_HDRPAD_STR
/* 01234567[89ABCDEF] */
"addr "
/* 123.123.123.123 */
"gateway "
/* 123.123.123.123 */
"max_frag "
/* 12345 */
"ref "
/* 123 */
"type "
/* ABCDEFGH */
return (0);
}
/* Reports the interface table ires */
static void
{
char buf1[INET_ADDRSTRLEN];
char buf2[INET_ADDRSTRLEN];
int ref;
"%s %s %05d %03d %s %d",
(void *)ire->ire_in_ill,
}
/*
* ip_ire_req is called by ip_wput when an IRE_DB_REQ_TYPE message is handed
* down from the Upper Level Protocol to request a copy of the IRE (to check
* its type or to extract information like round-trip time estimates or the
* MTU.)
* The address is assumed to be in the ire_addr field. If no IRE is found
* an IRE is returned with ire_type being zero.
* Note that the upper lavel protocol has to check for broadcast
* (IRE_BROADCAST) and multicast (CLASSD(addr)).
* If there is a b_cont the resulting IRE_DB_TYPE mblk is placed at the
* end of the returned message.
*
* TCP sends down a message of this type with a connection request packet
* chained on. UDP and ICMP send it down to verify that a route exists for
* the destination address when they get connected.
*/
void
{
return;
}
/*
* Got it, now take our best shot at an IRE.
*/
} else {
}
/*
* We prevent returning IRES with source address INADDR_ANY
* as these were temporarily created for sending packets
* from endpoints that have conn_unspec_src set.
*/
} else {
/* Copy the route metrics from the parent. */
sizeof (iulp_t));
}
/*
* As we don't lookup global policy here, we may not
* pass the right size if per-socket policy is not
* present. For these cases, path mtu discovery will
* do the right thing.
*/
/* Pass the latest setting of the ip_path_mtu_discovery */
}
/* Put the IRE_DB_TYPE mblk last in the chain */
}
}
/*
* Send a packet using the specified IRE.
* If ire_src_addr_v6 is all zero then discard the IRE after
* the packet has been sent.
*/
static void
{
if (is_secure)
/* If the packet originated externally then */
/*
* Extract the ifindex from b_prev (set in ip_rput_noire).
* Look up interface to see if it still exists (it could have
* been unplumbed by the time the reply came back from ARP)
*/
return;
}
return;
}
/*
* This packet has not gone through IPSEC processing
* and hence we should not have any IPSEC message
* prepended.
*/
/* Packets from multicast router */
/*
* We never get the IPSEC_OUT while forwarding the
* packet for multicast router.
*/
} else {
/* Locally originated packets */
/*
* We need to do an ire_delete below for which
* we need to make sure that the IRE will be
* around even after calling ip_wput_ire -
* which does ire_refrele. Otherwise somebody
* could potentially delete this ire and hence
* free this ire and we will be calling ire_delete
* on a freed ire below.
*/
if (is_inaddr_any) {
}
/*
* If we were resolving a router we can not use the
* routers IRE for sending the packet (since it would
* violate the uniqness of the IP idents) thus we
* make another pass through ip_wput to create the IRE_CACHE
* for the destination.
* When IRE_MARK_NOADD is set, ire_add() is not called.
* Thus ip_wput() will never find a ire and result in an
* infinite loop. Thus we check whether IRE_MARK_NOADD is
* is set. This also implies that IRE_MARK_NOADD can only be
* used to send packets to directly connected hosts.
*/
} else {
if (is_secure) {
if (oi->ipsec_out_proc_begin) {
/*
* This is the case where
* ip_wput_ipsec_out could not find
* the IRE and recreated a new one.
* As ip_wput_ipsec_out does ire
* lookups, ire_refrele for the extra
* bump in ire_add.
*/
} else {
/*
* IRE_REFRELE will be done in
* ip_wput_ire.
*/
IRE_SEND);
}
} else {
/*
* IRE_REFRELE will be done in ip_wput_ire.
*/
IRE_SEND);
}
}
/*
* Special code to support sending a single packet with
* conn_unspec_src using an IRE which has no source address.
* The IRE is deleted here after sending the packet to avoid
* having other code trip on it. But before we delete the
* ire, somebody could have looked up this ire.
* by making checks to NULL source address in other places
* like e.g ip_ire_append, ip_ire_req and ip_bind_connected.
* Though, this does not completely prevent other threads
* from using this ire, this should not cause any problems.
*
* NOTE : We use is_inaddr_any instead of using ire_src_addr
* because for the normal case i.e !is_inaddr_any, ire_refrele
* above could have potentially freed the ire.
*/
if (is_inaddr_any) {
/*
* If this IRE has been deleted by another thread, then
* ire_bucket won't be NULL, but ire_ptpn will be NULL.
* Thus, ire_delete will do nothing. This check
* guards against calling ire_delete when the IRE was
* never inserted in the table, which is handled by
* ire_delete as dropping another reference.
*/
ip1dbg(("ire_send: delete IRE\n"));
}
}
}
}
/*
* Send a packet using the specified IRE.
* If ire_src_addr_v6 is all zero then discard the IRE after
* the packet has been sent.
*/
static void
{
} else {
}
/* If the packet originated externally then */
/*
* Extract the ifindex from b_prev (set in ip_rput_data_v6).
* Look up interface to see if it still exists (it could have
* been unplumbed by the time the reply came back from the
* resolver). Unlike IPv4 there is no need for a prepended
* M_BREAK since ip_rput_data_v6 does not process options
* before finding an IRE.
*/
return;
}
/*
* This packet has not gone through IPSEC processing
* and hence we should not have any IPSEC message
* prepended.
*/
/* Packets from multicast router */
/*
* We never get the IPSEC_OUT while forwarding the
* packet for multicast router.
*/
/*
* XXX TODO IPv6.
*/
#ifdef XXX
#endif
} else {
if (secure) {
if (oi->ipsec_out_proc_begin) {
/*
* This is the case where
* ip_wput_ipsec_out could not find
* the IRE and recreated a new one.
*/
} else {
q, IRE_SEND);
}
} else {
/*
* Send packets through ip_output_v6 so that any
* ip6_info header can be processed again.
*/
IRE_SEND);
}
/*
* Special code to support sending a single packet with
* conn_unspec_src using an IRE which has no source address.
* The IRE is deleted here after sending the packet to avoid
* having other code trip on it. But before we delete the
* ire, somebody could have looked up this ire.
* by making checks to NULL source address in other places
* like e.g ip_ire_append_v6, ip_ire_req and
* ip_bind_connected_v6. Though, this does not completely
* prevent other threads from using this ire, this should
* not cause any problems.
*/
ip1dbg(("ire_send_v6: delete IRE\n"));
}
}
}
/*
* Make sure that IRE bucket does not get too long.
* This can cause lock up because ire_cache_lookup()
* may take "forever" to finish.
*
* We just remove cnt IREs each time. This means that
* the bucket length will stay approximately constant,
* depending on cnt. This should be enough to defend
* against DoS attack based on creating temporary IREs
* (for forwarding and non-TCP traffic).
*
* Note that new IRE is normally added at the tail of the
* bucket. This means that we are removing the "oldest"
* temporary IRE added. Only if there are IREs with
* the same ire_addr, do we not add it at the tail. Refer
* to ire_add_v*(). It should be OK for our purpose.
*
* For non-temporary cached IREs, we make sure that they
* have not been used for some time (defined below), they
* are non-local destinations, and there is no one using
* them at the moment (refcnt == 1).
*
* The above means that the IRE bucket length may become
* very long, consisting of mostly non-temporary IREs.
* This can happen when the hash function does a bad job
* so that most TCP connections cluster to a specific bucket.
* This "hopefully" should never happen. It can also
* happen if most TCP connections have very long lives.
* Even with the minimal hash table size of 256, there
* has to be a lot of such connections to make the bucket
* length unreasonably long. This should probably not
* happen either. The third can when this can happen is
* when the machine is under attack, such as SYN flooding.
* TCP should already have the proper mechanism to protect
* that. So we should be safe.
*
* This function is called by ire_add_then_send() after
* a new IRE is added and the packet is sent.
*
* The idle cutoff interval is set to 60s. It can be
*/
static void
{
/*
* irb is NULL if the IRE is not added to the hash. This
* happens when IRE_MARK_NOADD is set in ire_add_then_send()
* and when ires are returned from ire_update_srcif_v4() routine.
*/
return;
continue;
tmp_cnt--;
}
}
}
ire->ire_gateway_addr == 0) {
continue;
}
cnt--;
}
}
}
}
/*
* ire_add_then_send is called when a new IRE has been created in order to
* route an outgoing packet. Typically, it is called from ip_wput when
* a response comes back down from a resolver. We add the IRE, and then
* possibly run the packet through ip_wput or ip_rput, as appropriate.
* However, we do not add the newly created IRE in the cache when
* IRE_MARK_NOADD is set in the IRE. IRE_MARK_NOADD is set at
* ip_newroute_ipif(). The ires with IRE_MARK_NOADD and ires returned
* by ire_update_srcif_v4() are ire_refrele'd by ip_wput_ire() and get
* deleted.
* Multirouting support: the packet is silently discarded when the new IRE
* holds the RTF_MULTIRT flag, but is not the first IRE to be added with the
* RTF_MULTIRT flag for the same destination address.
* In this case, we just want to register this additional ire without
* sending the packet, as it has already been replicated through
* existing multirt routes in ip_wput().
*/
void
{
/* LINTED : set but not used in function */
/*
* We first have to retrieve the destination address carried
* by the packet.
* We can't rely on ire as it can be related to a gateway.
* The destination address will help in determining if
* other RTF_MULTIRT ires are already registered.
*
* We first need to know where we are going : v4 or V6.
* the ire version is enough, as there is no risk that
* we resolve an IPv6 address with an IPv4 ire
* or vice versa.
*/
ire->ire_zoneid);
} else {
/*
* Get a pointer to the beginning of the IPv6 header.
* Ignore leading IPsec control mblks.
*/
}
ire->ire_zoneid);
}
/*
* At least one resolved multirt route
* already exists for the destination,
* don't sent this packet: either drop it
* or complete the pending resolution,
* depending on the ire.
*/
}
ip1dbg(("ire_add_then_send: dst_ire %p "
"[dst %08x, gw %08x], drop %d\n",
(void *)dst_ire,
drop));
}
}
/*
* Regular packets with cache bound ires and
* the packets from ARP response for ires which
* belong to the ire_srcif_v4 table, are here.
*/
/* Add the ire */
} else {
/*
* This must be ARP response for ire in interface based
* table. Note that we don't add them in cache table,
* instead we update the existing table with dlureq_mp
* information. The reverse tunnel ires do not come
* here, as reverse tunnel is non-resolver interface.
* XXX- another design alternative was to mark the
* ires in interface based table with a special mark to
* make absolutely sure that we operate in right ires.
* This idea was not implemented as part of code review
* suggestion, as ire_in_ill suffice to distinguish
* between the regular ires and interface based
* ires now and thus we save a bit in the ire_marks.
*/
}
return;
}
return;
}
}
if (drop) {
/*
* If we're adding an RTF_MULTIRT ire, the resolution
* is over: we just drop the packet.
*/
if (save_mp) {
}
} else {
/*
* Otherwise, we're adding the ire to a gateway
* for a multirt route.
* Invoke ip_newroute() to complete the resolution
* of the route. We will then come back here and
* finally drop this packet in the above code.
*/
/*
* TODO: in order for CGTP to work in non-global
* zones, ip_newroute() must create the IRE
* cache in the zone indicated by
* ire->ire_zoneid.
*/
} else {
}
}
return;
}
/*
* Need to remember ire_bucket here as ire_send*() may delete
* the ire so we cannot reference it after that.
*/
/*
* Clean up more than 1 IRE so that the clean up does not
* need to be done every time when a new IRE is added and
* the threshold is reached.
*/
} else {
}
}
/*
* Initialize the ire that is specific to IPv4 part and call
* ire_init_common to finish it.
*/
ire_t *
{
/*
* We can't dupb() here as multiple threads could be
* calling dupb on the same mp which is incorrect.
* First dupb() should be called only by one thread.
*/
return (NULL);
}
/*
* We can't dupb() here as multiple threads could be
* calling dupb on the same mp which is incorrect.
* First dupb() should be called only by one thread.
*/
return (NULL);
}
}
/*
* Check that IRE_IF_RESOLVER and IRE_IF_NORESOLVER have a
* dlureq_mp which is the ill_resolver_mp for IRE_IF_RESOLVER
* and DL_UNITDATA_REQ for IRE_IF_NORESOLVER.
*/
if ((type & IRE_INTERFACE) &&
ip0dbg(("ire_init: no dlureq_mp\n"));
return (NULL);
}
}
}
if (in_src_addr != NULL) {
}
return (ire);
}
/*
* Similar to ire_create except that it is called only when
* we want to allocate ire as an mblk e.g. we have an external
* resolver ARP.
*/
ire_t *
{
/* Allocate the new IRE. */
ip1dbg(("ire_create_mp: alloc failed\n"));
return (NULL);
}
/* Start clean. */
return (NULL);
}
/*
* ire_max_frag is normally zero here and is atomically set
* under the irebucket lock in ire_add_v[46] except for the
* case of IRE_MARK_NOADD. In that event the the ire_max_frag
* is non-zero here.
*/
return (ire);
}
/*
* ire_create is called to allocate and initialize a new IRE.
*
* NOTE : This is called as writer sometimes though not required
* by this function.
*/
ire_t *
{
ip1dbg(("ire_create: alloc failed\n"));
return (NULL);
}
return (NULL);
}
return (ire);
}
/*
* Common to IPv4 and IPv6
*/
void
{
if (ipif) {
else
}
/*
* If this IRE is an IRE_CACHE, inherit the handles from the
* parent IREs. For others in the forwarding table, assign appropriate
* new ones.
*
* The mutex protecting ire_handle is because ire_create is not always
* called as a writer.
*/
}
} else {
}
#ifdef IRE_DEBUG
#endif
}
/*
* This routine is called repeatedly by ipif_up to create broadcast IREs.
* It is passed a pointer to a slot in an IRE pointer array into which to
* place the pointer to the new IRE, if indeed we create one. If the
* IRE corresponding to the address passed in would be a duplicate of an
* existing one, we don't create the new one. irep is incremented before
* return only if we do create a new IRE. (Always called as writer.)
*
* Note that with the "match_flags" parameter, we can match on either
* a particular logical interface (MATCH_IRE_IPIF) or for all logical
* interfaces for a given physical interface (MATCH_IRE_ILL). Currently,
* we only create broadcast ire's on a per physical interface basis. If
* someone is going to be mucking with logical interfaces, it is important
* to call "ipif_check_bcast_ires()" to make sure that any change to a
* logical interface will not cause critical broadcast IRE's to be deleted.
*/
ire_t **
int match_flags)
{
/*
* No broadcast IREs for the LOOPBACK interface
* or others such as point to point and IPIF_NOXMIT.
*/
return (irep);
/* If this would be a duplicate, don't bother. */
/*
* We look for non-deprecated (and non-anycast, non-nolocal)
* ipifs as the best choice. ipifs with check_flags matching
* (deprecated, etc) are used only if non-deprecated ipifs
* are not available. if the existing ire's ipif is deprecated
* and the new ipif is non-deprecated, switch to the new ipif
*/
return (irep);
}
/*
* Bcast ires exist in pairs. Both have to be deleted,
* Since we are exclusive we can make the above assertion.
* The 1st has to be refrele'd since it was ctable_lookup'd.
*/
}
return (irep);
}
/*
* This routine is called from ipif_check_bcast_ires and ire_check_bcast.
* It leaves all the verifying and deleting to those routines. So it always
* creates 2 bcast ires and chains them into the ire array passed in.
*/
ire_t **
{
*irep++ = ire_create(
NULL, /* no gateway */
NULL, /* no in_src_addr */
NULL, /* fast path header */
ipif,
NULL,
0,
0,
0,
0,
*irep++ = ire_create(
NULL, /* no gateway */
NULL, /* no in_src_addr */
&ip_loopback_mtu, /* max frag size */
NULL, /* Fast Path header */
NULL, /* no send-to queue */
IRE_BROADCAST, /* Needed for fanout in wput */
NULL,
ipif,
NULL,
0,
0,
0,
0,
return (irep);
}
/*
* ire_walk routine to delete or update any IRE_CACHE that might contain
* stale information.
* The flags state which entries to delete or update.
* Garbage collection is done separately using kmem alloc callbacks to
* ip_trash_ire_reclaim.
* Used for both IPv4 and IPv6. However, IPv6 only uses FLUSH_MTU_TIME
* since other stale information is cleaned up using NUD.
*/
void
{
if ((flush_flags & FLUSH_REDIRECT_TIME) &&
/* Make sure we delete the corresponding IRE_CACHE */
ip1dbg(("ire_expire: all redirects\n"));
return;
}
return;
if (flush_flags & FLUSH_ARP_TIME) {
/*
* Remove all IRE_CACHE.
* Verify that create time is more than
* ip_ire_arp_interval milliseconds ago.
*/
ip1dbg(("ire_expire: all IRE_CACHE\n"));
return;
}
}
/* Increase pmtu if it is less than the interface mtu */
/*
* If the ipif is a vni (whose mtu is 0, since it's virtual)
* get the mtu from the sending interfaces' ipif
*/
} else {
}
}
}
/*
* Do fast path probing if necessary.
*/
static void
{
int res;
/*
* Already contains fastpath info or
* doesn't have DL_UNITDATA_REQ header
* or is a loopback broadcast ire i.e. no stq.
*/
return;
}
return;
/*
* EAGAIN is an indication of a transient error
* i.e. allocation failure etc. leave the ire in the list it will
* be updated when another probe happens for another ire if not
* it will be taken out of the list when the ire is deleted.
*/
}
/*
* Update all IRE's that are not in fastpath mode and
* have an dlureq_mp that matches mp. mp->b_cont contains
* the fastpath header.
*
* Returns TRUE if entry should be dequeued, or FALSE otherwise.
*/
{
IRE_MIPRTUN)) != 0);
/*
* Already contains fastpath info or doesn't have
* DL_UNITDATA_REQ header.
*/
return (B_TRUE);
ip2dbg(("ire_fastpath_update: trying\n"));
/* Serialize multiple fast path updates */
/*
* Don't take the ire off the fastpath list yet,
* since the response may come later.
*/
return (B_FALSE);
}
/* Matched - install mp as the ire_fp_mp */
ip1dbg(("ire_fastpath_update: match\n"));
if (fp_mp) {
/*
* We checked ire_fp_mp above. Check it again with the
* lock. Update fp_mp only if it has not been done
* already.
*/
/*
* ire_ll_hdr_length is just an optimization to
* store the length. It is used to return the
* fast path header length to the upper layers.
*/
} else {
}
}
return (B_TRUE);
}
/*
* This function handles the DL_NOTE_FASTPATH_FLUSH notification from the
* driver.
*/
/* ARGSUSED */
void
{
int res;
/* No fastpath info? */
return;
/*
* Just remove the IRE if it is for non-broadcast dest. Then
* we will create another one which will have the correct
* fastpath info.
*/
case IRE_CACHE:
break;
case IRE_MIPRTUN:
case IRE_BROADCAST:
/*
* We can't delete the ire since it is difficult to
* recreate these ire's without going through the
* ire_lock in the case of IRE_MIPRTUN and IRE_BROADCAST.
* All access to ire_fp_mp in the case of these 2 ire types
* is protected by ire_lock.
*/
/*
* No fastpath probe if there is no stq i.e.
* i.e. the case of loopback broadcast ire.
*/
break;
/*
* EAGAIN is an indication of a transient error
* i.e. allocation failure etc. leave the ire in the
* list it will be updated when another probe happens
* for another ire if not it will be taken out of the
* list when the ire is deleted.
*/
} else {
}
break;
default:
/* This should not happen! */
ip0dbg(("ire_fastpath_flush: Wrong ire type %s\n",
break;
}
}
/*
* Drain the list of ire's waiting for fastpath response.
*/
void
void *arg)
{
/*
* Take it off the list if we're flushing, or if the callback
* routine tells us to do so. Otherwise, leave the ire in the
* fastpath list to handle any pending response from the lower
* layer. We can't drain the list when the callback routine
* comparison failed, because the response is asynchronous in
* nature, and may not arrive in the same order as the list
* insertion.
*/
if (current_ire == first_ire)
else
} else {
/* previous element that is still in the list */
}
}
}
/*
* Add ire to the ire fastpath list.
*/
static void
{
/*
* if ire has not been deleted and
* is not already in the list add it.
*/
}
}
/*
* remove ire from the ire fastpath list.
*/
void
{
goto done;
} else {
break;
}
}
}
done:
}
/*
* Find an IRE_INTERFACE for the multicast group.
* Allows different routes for multicast addresses
* in the unicast routing table (akin to 224.0.0.0 but could be more specific)
* which point at different interfaces. This is used when IP_MULTICAST_IF
* isn't specified (when sending) and when IP_ADD_MEMBERSHIP doesn't
* specify the interface to join on.
*
*/
ire_t *
{
int match_flags = MATCH_IRE_TYPE;
0, MATCH_IRE_DEFAULT);
/* We search a resolvable ire in case of multirouting. */
/*
* If the route is not resolvable, the looked up ire
* may be changed here. In that case, ire_multirt_lookup()
* IRE_REFRELE the original ire and change it.
*/
}
return (NULL);
/*
* Make sure we follow ire_ipif.
*
* We need to determine the interface route through
* which the gateway will be reached. We don't really
* care which interface is picked if the interface is
* part of a group.
*/
}
case IRE_DEFAULT:
case IRE_PREFIX:
case IRE_HOST:
return (ire);
case IRE_IF_NORESOLVER:
case IRE_IF_RESOLVER:
return (ire);
default:
return (NULL);
}
}
/*
* Return any local address. We use this to target ourselves
* when the src address was specified as 'default'.
* Preference for IRE_LOCAL entries.
*/
ire_t *
{
int i;
for (i = 0; i < ip_cache_table_size; i++) {
irb = &ip_cache_table[i];
continue;
continue;
case IRE_LOOPBACK:
}
break;
case IRE_LOCAL:
}
return (ire);
}
}
}
return (maybe);
}
/*
* If the specified IRE is associated with a particular ILL, return
* that ILL pointer (May be called as writer.).
*
* NOTE : This is not a generic function that can be used always.
* This function always returns the ill of the outgoing packets
* if this ire is used.
*/
ill_t *
{
/*
* 1) For an IRE_CACHE, ire_ipif is the one where it obtained
* the source address from. ire_stq is the one where the
* packets will be sent out on. We return that here.
*
* 2) IRE_BROADCAST normally has a loopback and a non-loopback
* copy and they always exist next to each other with loopback
* copy being the first one. If we are called on the non-loopback
* copy, return the one pointed by ire_stq. If it was called on
* a loopback copy, we still return the one pointed by the next
* ire's ire_stq pointer i.e the one pointed by the non-loopback
* copy. We don't want use ire_ipif as it might represent the
* source address (if we borrow source addresses for
* IRE_BROADCASTS in the future).
* However if an interface is currently coming up, the above
* condition may not hold during that period since the ires
* are added one at a time. Thus one of the pair could have been
* added and the other not yet added.
* 3) For all others return the ones pointed by ire_ipif->ipif_ill.
*/
} else {
}
}
}
return (ill);
}
/* Arrange to call the specified function for every IRE in the world. */
void
{
}
void
{
}
void
{
}
/*
* Walk a particular version. version == 0 means both v4 and v6.
*/
static void
{
if (vers != IPV6_VERSION) {
}
if (vers != IPV4_VERSION) {
}
}
/*
* Arrange to call the specified
* function for every IRE that matches the ill.
*/
void
{
}
void
{
ill);
}
void
{
ill);
}
/*
* Walk a particular ill and version. version == 0 means both v4 and v6.
*/
static void
{
if (vers != IPV6_VERSION) {
}
if (vers != IPV4_VERSION) {
}
}
static boolean_t
{
/*
* 1) MATCH_IRE_WQ : Used specifically to match on ire_stq.
* The fast path update uses this to make sure it does not
* update the fast path header of interface X with the fast
* path updates it recieved on interface Y. It is similar
* in handling DL_NOTE_FASTPATH_FLUSH.
*
* 2) MATCH_IRE_ILL/MATCH_IRE_ILL_GROUP : We match both on ill
* pointed by ire_stq and ire_ipif. Only in the case of
* IRE_CACHEs can ire_stq and ire_ipif be pointing to
* different ills. But we want to keep this function generic
* enough for future use. So, we always try to match on both.
* The only caller of this function ire_walk_ill_tables, will
* call "func" after we return from this function. We expect
* "func" to do the right filtering of ires in this case.
*
* NOTE : In the case of MATCH_IRE_ILL_GROUP, groups
* pointed by ire_stq and ire_ipif should always be the same.
* So, we just match on only one of them.
*/
if (ire_stq_ill != NULL)
}
/*
* We're walking the IREs for a specific zone. The only relevant
* IREs are:
* - all IREs with a matching ire_zoneid
* - all IRE_OFFSUBNETs as they're shared across all zones
* - IRE_INTERFACE IREs for interfaces with a usable source addr
* with a matching zone
* - IRE_DEFAULTs with a gateway reachable from the zone
* We should really match on IRE_OFFSUBNETs and IRE_DEFAULTs
* using the same rule; but the above rules are consistent with
* the behavior of ire_ftable_lookup[_v6]() so that all the
* routes that can be matched during lookup are also matched
* here.
*/
/*
* Note, IRE_INTERFACE can have the stq as NULL. For
* example, if the default multicast route is tied to
* the loopback address.
*/
if (!ipif_usesrc_avail(ire_stq_ill,
zoneid))
/* No usable src addr in zone */
return (B_FALSE);
} else if (ire_stq_ill->ill_usesrc_ifindex
!= 0) {
/*
* For IPv6 use ipif_select_source_v6()
* so the right scope selection is done
*/
src_ipif =
zoneid);
} else {
return (B_FALSE);
}
} else {
return (B_FALSE);
}
return (B_FALSE);
}
}
/*
* Match all default routes from the global zone, irrespective
* of reachability.
*/
int ire_match_flags = 0;
}
} else {
}
return (B_FALSE);
}
}
}
if (((!(match_flags & MATCH_IRE_TYPE)) ||
((!(match_flags & MATCH_IRE_WQ)) ||
((!(match_flags & MATCH_IRE_ILL)) ||
((!(match_flags & MATCH_IRE_ILL_GROUP)) ||
(ire_ill_group != NULL &&
return (B_TRUE);
}
return (B_FALSE);
}
/*
* Walk the ftable and the ctable entries that match the ill.
*/
static void
{
int i, j;
/*
* Optimize by not looking at the forwarding table if there
* is a MATCH_IRE_TYPE specified with no IRE_FORWARDTABLE
* specified in ire_type.
*/
if (!(match_flags & MATCH_IRE_TYPE) ||
((ire_type & IRE_FORWARDTABLE) != 0)) {
for (i = (ftbl_sz - 1); i >= 0; i--) {
continue;
for (j = 0; j < htbl_sz; j++) {
continue;
if (match_flags == 0 &&
} else {
}
if (ret)
}
}
}
}
/*
* Optimize by not looking at the cache table if there
* is a MATCH_IRE_TYPE specified with no IRE_CACHETABLE
* specified in ire_type.
*/
if (!(match_flags & MATCH_IRE_TYPE) ||
((ire_type & IRE_CACHETABLE) != 0)) {
for (i = 0; i < ctbl_sz; i++) {
continue;
} else {
}
if (ret)
}
}
}
}
/*
* This routine walks through the ill chain to find if there is any
* ire linked to the ill's interface based forwarding table
* The arg could be ill or mp. This routine is called when a ill goes
*/
void
{
int i;
int total_count;
/*
* Take care of ire's in other ill's per-interface forwarding
* table. Check if any ire in any of the ill's ill_srcif_table
* is pointing to this ill.
*/
if (ire_srcif_table_count == 0) {
return;
}
#ifdef DEBUG
/* Keep accounting of all interface based table ires */
total_count = 0;
}
/* Hold lock here to make sure ire_srcif_table_count is stable */
ip1dbg(("ire_walk_srcif_v4: ire_srcif_table_count %d "
"total ill_srcif_refcnt %d\n", i, total_count));
#endif
continue;
}
for (i = 0; i < IP_SRCIF_TABLE_SIZE; i++) {
continue;
}
}
}
}
}
/*
* This function takes a mask and returns
* number of bits set in the mask. If no
* bit is set it returns 0.
* Assumes a contiguous mask.
*/
int
{
}
/*
* Convert length for a mask to the mask.
*/
{
}
void
{
}
/*
* ire_add_v[46] atomically make sure that the ipif or ill associated
* with the new ire being added is stable and not IPIF_CHANGING or ILL_CHANGING
* before adding the ire to the table. This ensures that we don't create
* new IRE_CACHEs with stale values for parameters that are passed to
* ire_create such as ire_max_frag. Note that ire_create() is passed a pointer
* to the ipif_mtu, and not the value. The actual value is derived from the
* parent ire or ipif under the bucket lock.
*/
int
{
int error = 0;
GRAB_CONN_LOCK(q);
/*
* While the IRE is in the process of being added, a user may have
* invoked the ifconfig usesrc option on the stq_ill to make it a
* usesrc client ILL. Check for this possibility here, if it is true
* then we fail adding the IRE_CACHE. Another check is to make sure
* that an ipif_ill of an IRE_CACHE being added is not part of a usesrc
* group. The ill_g_usesrc_lock is released in ire_atomic_end
*/
if (stq_ill->ill_usesrc_ifindex != 0) {
(ipif_ill->ill_usesrc_ifindex != 0)) {
goto done;
}
goto done;
}
}
/*
* IPMP flag settings happen without taking the exclusive route
* in ip_sioctl_flags. So we need to make an atomic check here
* FAILBACK=no case.
*/
(ill_is_probeonly(stq_ill) &&
}
goto done;
}
/*
* the source address selection logic (ipif_select_source)
* may still select a source address from such an ill. The
* assumption is that these addresses will be moved by in.mpathd
* soon. (i.e. this is a race). However link local addresses
* will not move and hence ipif_select_source_v6 tries to avoid
* FAILED ills. Please see ipif_select_source_v6 for more info
*/
goto done;
}
goto done;
}
goto done;
}
done:
error = EINPROGRESS;
} else if (error != 0) {
}
return (error);
}
/*
* Add a fully initialized IRE to an appropriate table based on
* ire_type.
*/
int
{
int error;
/* get ready for the day when original ire is not created as mblk */
/* Copy the ire to a kmem_alloc'ed area */
ip1dbg(("ire_add: alloc failed\n"));
return (ENOMEM);
}
}
/*
* If this interface is FAILED, or INACTIVE or has hit
* the FAILBACK=no case, we create IRE_CACHES marked
* HIDDEN for some special cases e.g. bind to
* IPIF_NOFAILOVER address etc. So, if this interface
* not creating hidden ires, we should not allow that.
* This happens because the state of the interface
* changed while we were waiting in ARP. If this is the
* daemon sending probes, the next probe will create
* HIDDEN ires and we will create an ire then. This
* cannot happen with NDP currently because IRE is
* never queued in NDP. But it can happen in the
* future when we have external resolvers with IPv6.
* If the interface gets marked with OFFLINE while we
* are waiting in ARP, don't add the ire.
*/
(ill_is_probeonly(stq_ill) &&
/*
* We don't know whether it is a valid ipif or not.
* unless we do the check below. So, set it to NULL.
*/
return (EINVAL);
}
}
continue;
}
/*
* We need to make sure that the ipif is a valid one
* before adding the IRE_CACHE. This happens only
* with IRE_CACHE when there is an external resolver.
*
* We can unplumb a logical interface while the
* packet is waiting in ARP with the IRE. Then,
* later on when we feed the IRE back, the ipif
* has to be re-checked. This can't happen with
* NDP currently, as we never queue the IRE with
* the packet. We always try to recreate the IRE
* when the resolution is completed. But, we do
* it for IPv6 also here so that in future if
* we have external resolvers, it will work without
* any change.
*/
break;
}
}
&ipif->ipif_v6src_addr)) ||
return (EINVAL);
}
/*
* If this group was dismantled while this packets was
* queued in ARP, don't add it here.
*/
/* We don't want ire_inactive bump stats for this */
return (EINVAL);
}
}
/*
* In case ire was changed
*/
} else {
else
}
return (error);
}
/*
* Add a fully initialized IRE to an appropriate
* table based on ire_type.
*
* The forward table contains IRE_PREFIX/IRE_HOST/IRE_HOST_REDIRECT
* IRE_IF_RESOLVER/IRE_IF_NORESOLVER and IRE_DEFAULT.
*
* The cache table contains IRE_BROADCAST/IRE_LOCAL/IRE_LOOPBACK
* and IRE_CACHE.
*
* NOTE : This function is called as writer though not required
* by this function.
*/
static int
{
int mask_table_index;
int flags;
int error;
/* Find the appropriate list head. */
case IRE_HOST:
ire->ire_src_addr = 0;
break;
case IRE_HOST_REDIRECT:
ire->ire_src_addr = 0;
break;
case IRE_CACHE:
case IRE_BROADCAST:
case IRE_LOCAL:
case IRE_LOOPBACK:
break;
case IRE_PREFIX:
ire->ire_src_addr = 0;
break;
case IRE_DEFAULT:
ire->ire_src_addr = 0;
break;
case IRE_IF_RESOLVER:
case IRE_IF_NORESOLVER:
break;
default:
printf("ire_add_v4: ire %p has unrecognized IRE type (%d)\n",
return (EINVAL);
}
/* Make sure the address is properly masked. */
/* IRE goes into Forward Table */
int i;
sizeof (irb_t)));
return (ENOMEM);
}
for (i = 0; i < ip_ftable_hash_size; i++) {
RW_DEFAULT, NULL);
}
} else {
/*
* Some other thread won the race in
* initializing the forwarding table at the
* same index.
*/
for (i = 0; i < ip_ftable_hash_size; i++) {
}
}
}
} else {
}
/*
* ip_newroute/ip_newroute_multi are unable to prevent the deletion
* of the interface route while adding an IRE_CACHE for an on-link
* destination in the IRE_IF_RESOLVER case, since the ire has to
* go to ARP and return. We can't do a REFHOLD on the
* associated interface ire for fear of ARP freeing the message.
* Here we look up the interface ire in the forwarding table and
* make sure that the interface route has not been deleted.
*/
/*
* The ihandle that we used in ip_newroute_multi
* comes from the interface route corresponding
* to ire_ipif. Lookup here to see if it exists
* still.
* If the ire has a source address assigned using
* RTF_SETSRC, ire_ipif is the logical interface holding
* this source address, so we can't use it to check for
* the existence of the interface route. Instead we rely
* on the brute force ihandle search in
* ire_ihandle_lookup_onlink() below.
*/
return (EINVAL);
return (EINVAL);
}
} else {
return (EINVAL);
}
}
/* Prevent pire from getting deleted */
/* Has it been removed already ? */
return (EINVAL);
}
} else {
}
/*
* We use MATCH_IRE_IPIF while adding IRE_CACHES only
* for historic reasons and to maintain symmetry with
* IPv6 code path. Historically this was used by
* multicast code to create multiple IRE_CACHES on
* a single ill with different ipifs. This was used
* so that multicast packets leaving the node had the
* right source address. This is no longer needed as
* ip_wput initializes the address correctly.
*/
flags |= MATCH_IRE_IPIF;
/*
* If we are creating hidden ires, make sure we search on
* this ill (MATCH_IRE_ILL) and a hidden ire,
* while we are searching for duplicates below. Otherwise we
* could potentially find an IRE on some other interface
* and it may not be a IRE marked with IRE_MARK_HIDDEN. We
* shouldn't do this as this will lead to an infinite loop
* (if we get to ip_wput again) eventually we need an hidden
* ire for this packet to go out. MATCH_IRE_ILL is explicitly
* done below.
*/
flags |= (MATCH_IRE_MARK_HIDDEN);
}
/*
* Start the atomic add of the ire. Grab the ill locks,
* ill_g_usesrc_lock and the bucket lock. Check for condemned
*
* If ipif or ill is changing ire_atomic_start() may queue the
* request and return EINPROGRESS.
*/
if (error != 0) {
/*
* We don't know whether it is a valid ipif or not.
* So, set it to NULL. This assumes that the ire has not added
* a reference to the ipif.
*/
}
return (error);
}
/*
* To avoid creating ires having stale values for the ire_max_frag
* we get the latest value atomically here. For more details
* see the block comment in ip_sioctl_mtu and in DL_NOTE_SDU_CHANGE
* in ip_rput_dlpi_writer
*/
else
} else {
}
/*
* Atomically check for duplicate and insert in the table.
*/
continue;
/*
* We do MATCH_IRE_ILL implicitly here for IREs
* with a non-null ire_ipif, including IRE_CACHEs.
* As ire_ipif and ire_stq could point to two
* different ills, we can't pass just ire_ipif to
* ire_match_args and get a match on both ills.
* This is just needed for duplicate checks here and
* so we don't add an extra argument to
* ire_match_args for this. Do it locally.
*
* NOTE : Currently there is no part of the code
* that asks for both MATH_IRE_IPIF and MATCH_IRE_ILL
* match for IRE_CACHEs. Thus we don't want to
* extend the arguments to ire_match_args.
*/
continue;
/*
* Multiroute IRE_CACHEs for a given destination can
* have the same ire_ipif, typically if their source
* address is forced using RTF_SETSRC, and the same
* send-to queue. We differentiate them using the parent
* handle.
*/
continue;
}
continue;
/*
* Return the old ire after doing a REFHOLD.
* As most of the callers continue to use the IRE
* after adding, we return a held ire. This will
* avoid a lookup in the caller again. If the callers
* don't want to use it, they need to do a REFRELE.
*/
ip1dbg(("found dup ire existing %p new %p",
/*
* Assert that it is not removed from the
* list yet.
*/
}
return (0);
}
}
/*
* Make it easy for ip_wput_ire() to hit multiple broadcast ires by
* grouping identical addresses together on the hash chain. We also
* don't want to send multiple copies out if there are two ills part
* of the same group. Thus we group the ires with same addr and same
* ill group together so that ip_wput_ire can easily skip all the
* ires with same addr and same group after sending the first copy.
* We do this only for IRE_BROADCASTs as ip_wput_ire is currently
* interested in such groupings only for broadcasts.
*
* NOTE : If the interfaces are brought up first and then grouped,
* illgrp_insert will handle it. We come here when the interfaces
* are already in group and we are bringing them UP.
*
* Find the first entry that matches ire_addr. *irep will be null
* if no match.
*/
/*
* We found some ire (i.e *irep) with a matching addr. We
* want to group ires with same addr and same ill group
* together.
*
* First get to the entry that matches our address and
* ill group i.e stop as soon as we find the first ire
* matching the ill group and address. If there is only
* an address match, we should walk and look for some
* group match. These are some of the possible scenarios :
*
* 1) There are no groups at all i.e all ire's ill_group
* are NULL. In that case we will essentially group
* all the ires with the same addr together. Same as
* the "else" block of this "if".
*
* 2) There are some groups and this ire's ill_group is
* NULL. In this case, we will first find the group
* that matches the address and a NULL group. Then
* we will insert the ire at the end of that group.
*
* 3) There are some groups and this ires's ill_group is
* non-NULL. In this case we will first find the group
* that matches the address and the ill_group. Then
* we will insert the ire at the end of that group.
*/
/* LINTED : constant in conditional context */
while (1) {
break;
}
/*
* Either we have hit the end of the list or the address
* did not match or the group *matched*. If we found
* a match on the group, skip to the end of the group.
*/
break;
break;
}
}
/*
* Find the last ire which matches ire_addr.
* Needed to do tail insertion among entries with the same
* ire_addr.
*/
break;
}
}
/*
* We keep a count of default gateways which is used when
* assigning them as routes.
*/
}
/* Insert at *irep */
/* Link the new one in. */
/*
* ire_walk routines de-reference ire_next without holding
* a lock. Before we point to the new ire, we want to make
* sure the store that sets the ire_next of the new ire
* reaches global visibility, so that ire_walk routines
* don't see a truncated list of ires i.e if the ire_next
* of the new ire gets set after we do "*irep = ire" due
* to re-ordering, the ire_walk thread will see a NULL
* once it accesses the ire_next of the new ire.
* membar_producer() makes sure that the following store
* happens *after* all of the above stores.
*/
/*
* We return a bumped up IRE above. Keep it symmetrical
* so that the callers will always have to release. This
* helps the callers of this function because they continue
* to use the IRE after adding and hence they don't have to
* lookup again after we return the IRE.
*
* NOTE : We don't have to use atomics as this is appearing
* in the list for the first time and no one else can bump
* up the reference count on this yet.
*/
irb_ptr->irb_ire_cnt++;
stq_ill->ill_ire_cnt++;
}
} else {
}
/* Assert that it is not removed from the list yet */
}
/*
* For ire's with with host mask see if there is an entry
* in the cache. If there is one flush the whole cache as
* there might be multiple entries due to RTF_MULTIRT (CGTP).
* If no entry is found than there is no need to flush the
* cache.
*/
}
} else {
}
}
/*
* We had to delay the fast path probe until the ire is inserted
* in the list. Otherwise the fast path ack won't find the ire in
* the table.
*/
return (0);
}
/*
* Search for all HOST REDIRECT routes that are
* pointing at the specified gateway and
* delete them. This routine is called only
* when a default gateway is going away.
*/
static void
{
int i;
/* get the hash table for HOST routes */
return;
for (i = 0; (i < ip_ftable_hash_size); i++) {
continue;
}
}
}
}
/*
* IRB_REFRELE is the only caller of the function. ire_unlink calls to
* do the final cleanup for this ire.
*/
void
{
} else {
}
/*
* Now it's really out of the list. Before doing the
* REFRELE, set ire_next to NULL as ire_inactive asserts
* so.
*/
}
}
/*
* IRB_REFRELE is the only caller of the function. It calls to unlink
* all the CONDEMNED ires from this bucket.
*/
ire_t *
{
if (ire1)
/*
* IRE is out of the list. We need to adjust
* the accounting before the caller drops
* the lock.
*/
ASSERT(ipv6_ire_default_count != 0);
} else {
ASSERT(ip_ire_default_count != 0);
}
}
/*
* We need to call ire_delete_v4 or ire_delete_v6
* to clean up the cache or the redirects pointing at
* the default gateway. We need to drop the lock
* as ire_flush_cache/ire_delete_host_redircts require
* so. But we can't drop the lock, as ire_unlink needs
* to atomically remove the ires from the list.
* So, create a temporary list of CONDEMNED ires
* for doing ire_delete_v4/ire_delete_v6 operations
* later on.
*/
}
}
return (ire_list);
}
/*
* Delete all the cache entries with this 'addr'. When IP gets a gratuitous
* ARP message on any of its interface queue, it scans the cache table and
* deletes all the cache entries for that address. This function is called
* ip_ire_clookup_and_delete returns true if it finds at least one cache entry
* which is used by ip_arp_news to determine if it needs to do an ire_walk_v4.
* The return value is also used for the same purpose by ARP IOCTL processing
* in ip_if.c when deleting ARP entries. For SIOC*IFARP ioctls in addition to
* the address, ip_if->ipif_ill also needs to be matched.
*/
{
continue;
/* This signifies start of an address match */
if (!loop_end)
/* We are interested only in IRE_CACHEs */
/* If we want a match with the ILL */
continue;
}
if (!found)
}
/* End of the match */
} else if (loop_end)
break;
}
return (found);
}
/*
* Delete the specified IRE.
*/
void
{
/*
* It was never inserted in the list. Should call REFRELE
* to free this IRE.
*/
return;
}
/*
* In case of V4 we might still be waiting for fastpath ack.
*/
}
/*
* Some other thread has removed us from the list.
* It should have done the REFRELE for us.
*/
return;
}
if (irb->irb_refcnt != 0) {
/*
* The last thread to leave this bucket will
* delete this ire.
*/
irb->irb_ire_cnt--;
irb->irb_tmp_ire_cnt--;
}
return;
}
/*
* Normally to delete an ire, we walk the bucket. While we
* walk the bucket, we normally bump up irb_refcnt and hence
* we return from above where we mark CONDEMNED and the ire
* gets deleted from ire_unlink. This case is where somebody
* knows the ire e.g by doing a lookup, and wants to delete the
* IRE. irb_refcnt would be 0 in this case if nobody is walking
* the bucket.
*/
} else {
}
/*
* ip_wput/ip_wput_v6 checks this flag to see whether
* it should still use the cached ire or not.
*/
/*
* IRE is out of the list. We need to adjust the
* accounting before we drop the lock.
*/
ASSERT(ipv6_ire_default_count != 0);
} else {
ASSERT(ip_ire_default_count != 0);
}
}
irb->irb_ire_cnt--;
irb->irb_tmp_ire_cnt--;
} else {
}
/*
* We removed it from the list. Decrement the
* reference count.
*/
}
/*
* Delete the specified IRE.
* All calls should use ire_delete().
* Sometimes called as writer though not required by this function.
*
* NOTE : This function is called only if the ire was added
* in the list.
*/
static void
{
/*
* when a default gateway is going away
* delete all the host redirects pointing at that
* gateway.
*/
}
}
/*
* IRE_REFRELE/ire_refrele are the only caller of the function. It calls
* to free the ire when the reference count goes to zero.
*/
void
{
/* Only IPv6 IRE_CACHE type has an nce */
}
goto end;
/* The ire was never inserted in the table. */
goto end;
}
/*
* ipif_ire_cnt on this ipif goes down by 1. If the ire_stq is
* non-null ill_ire_count also goes down by 1. If the in_ill is
* non-null either ill_mrtun_refcnt or ill_srcif_refcnt goes down by 1.
*
* The ipif that is associated with an ire is ire->ire_ipif and
* hence when the ire->ire_ipif->ipif_ire_cnt drops to zero we call
* ipif_ill_refrele_tail. Usually stq_ill is null or the same as
* ire->ire_ipif->ipif_ill. So nothing more needs to be done. Only
* in the case of IRE_CACHES when IPMP is used, stq_ill can be
* different. If this is different from ire->ire_ipif->ipif_ill and
* if the ill_ire_cnt on the stq_ill also has dropped to zero, we call
* ipif_ill_refrele_tail on the stq_ill. If mobile ip is in use
* in_ill could be non-null. If it is a reverse tunnel related ire
* ill_mrtun_refcnt is non-zero. If it is forward tunnel related ire
* ill_srcif_refcnt is non-null.
*/
/* Optimize the most common case */
ipif->ipif_ire_cnt--;
if (ipif->ipif_ire_cnt == 0)
stq_ill->ill_ire_cnt--;
if (stq_ill->ill_ire_cnt == 0)
}
if (need_wakeup) {
/* Drops the ill lock */
} else {
}
} else {
/*
* We can't grab all the ill locks at the same time.
* It can lead to recursive lock enter in the call to
* ipif_ill_refrele_tail and later. Instead do it 1 at
* a time.
*/
ipif->ipif_ire_cnt--;
if (ipif->ipif_ire_cnt == 0) {
/* Drops the lock */
} else {
}
stq_ill->ill_ire_cnt--;
if (stq_ill->ill_ire_cnt == 0) {
/* Drops the ill lock */
} else {
}
}
/*
* Mobile IP reverse tunnel ire.
* Decrement table count and the
* ill reference count. This signifies
* mipagent is deleting reverse tunnel
* route for a particular mobile node.
*/
if (in_ill->ill_mrtun_refcnt == 0) {
/* Drops the ill lock */
} else {
}
} else {
if (in_ill->ill_srcif_refcnt == 0) {
/* Drops the ill lock */
} else {
}
}
}
}
end:
/* This should be true for both V4 and V6 */
/* Free the xmit header, and the IRE itself. */
}
}
}
#ifdef IRE_DEBUG
#endif
} else {
}
/* Still in an mblk */
} else {
/* Has been allocated out of the cache */
}
}
/*
* ire_walk routine to delete all IRE_CACHE/IRE_HOST_REDIRECT entries
* that have a given gateway address.
*/
void
{
return;
ip1dbg(("ire_delete_cache_gw: deleted 0x%x type %d to 0x%x\n",
}
}
/*
* Remove all IRE_CACHE entries that match the ire specified.
*
* The flag argument indicates if the flush request is due to addition
* of new route (IRE_FLUSH_ADD) or deletion of old route (IRE_FLUSH_DELETE).
*
* This routine takes only the IREs from the forwarding table and flushes
* the corresponding entries from the cache table.
*
* When flushing due to the deletion of an old route, it
* just checks the cache handles (ire_phandle and ire_ihandle) and
* deletes the ones that match.
*
* When flushing due to the creation of a new route, it checks
* if a cache entry's address matches the one in the IRE and
* that the cache entry's parent has a less specific mask than the
* one in IRE. The destination of such a cache entry could be the
* gateway for other cache entries, so we need to flush those as
* well by looking for gateway addresses matching the IRE's address.
*/
void
{
int i;
return;
/*
* If a default is just created, there is no point
* in going through the cache, as there will not be any
* cached ires.
*/
return;
if (flag == IRE_FLUSH_ADD) {
/*
* This selective flush is due to the addition of
* new IRE.
*/
for (i = 0; i < ip_cache_table_size; i++) {
irb = &ip_cache_table[i];
continue;
continue;
/*
* If 'cire' belongs to the same subnet
* as the new ire being added, and 'cire'
* is derived from a prefix that is less
* specific than the new ire being added,
* we need to flush 'cire'; for instance,
* when a new interface comes up.
*/
ire->ire_masklen)) {
continue;
}
/*
* This is the case when the ire_gateway_addr
* of 'cire' belongs to the same subnet as
* the new ire being added.
* Flushing such ires is sometimes required to
* avoid misrouting: say we have a machine with
* two interfaces (I1 and I2), a default router
* R on the I1 subnet, and a host route to an
* off-link destination D with a gateway G on
* the I2 subnet.
* Under normal operation, we will have an
* on-link cache entry for G and an off-link
* cache entry for D with G as ire_gateway_addr,
* traffic to D will reach its destination
* through gateway G.
* If the administrator does 'ifconfig I2 down',
* the cache entries for D and G will be
* flushed. However, G will now be resolved as
* an off-link destination using R (the default
* router) as gateway. Then D will also be
* resolved as an off-link destination using G
* as gateway - this behavior is due to
* compatibility reasons, see comment in
* ire_ihandle_lookup_offlink(). Traffic to D
* will go to the router R and probably won't
* reach the destination.
* The administrator then does 'ifconfig I2 up'.
* Since G is on the I2 subnet, this routine
* will flush its cache entry. It must also
* flush the cache entry for D, otherwise
* traffic will stay misrouted until the IRE
* times out.
*/
continue;
}
}
}
} else {
/*
* delete the cache entries based on
* handle in the IRE as this IRE is
*/
for (i = 0; i < ip_cache_table_size; i++) {
irb = &ip_cache_table[i];
continue;
continue;
if ((cire->ire_phandle == 0 ||
(cire->ire_ihandle == 0 ||
continue;
}
}
}
}
/*
* Matches the arguments passed with the values in the ire.
*
* Note: for match types that match using "ipif" passed in, ipif
* must be checked for non-NULL before calling this routine.
*/
static boolean_t
{
/*
* HIDDEN cache entries have to be looked up specifically with
* MATCH_IRE_MARK_HIDDEN. MATCH_IRE_MARK_HIDDEN is usually set
* when the interface is FAILED or INACTIVE. In that case,
* any IRE_CACHES that exists should be marked with
* IRE_MARK_HIDDEN. So, we don't really need to match below
* for IRE_MARK_HIDDEN. But we do so for consistency.
*/
if (!(match_flags & MATCH_IRE_MARK_HIDDEN) &&
return (B_FALSE);
/*
* If MATCH_IRE_ZONEONLY has been set and the supplied zoneid is
* valid and does not match that of ire_zoneid, a failure to
* match is reported at this point. Otherwise, since some IREs
* that are available in the global zone can be used in local
* zones, additional checks need to be performed:
*
* IRE_BROADCAST, IRE_CACHE and IRE_LOOPBACK
* entries should never be matched in this situation.
*
* IRE entries that have an interface associated with them
* should in general not match unless they are an IRE_LOCAL
* or in the case when MATCH_IRE_DEFAULT has been set in
* the caller. In the case of the former, checking of the
* other fields supplied should take place.
*
* In the case where MATCH_IRE_DEFAULT has been set,
* all of the ipif's associated with the IRE's ill are
* checked to see if there is a matching zoneid. If any
* one ipif has a matching zoneid, this IRE is a
* potential candidate so checking of the other fields
* takes place.
*
* In the case where the IRE_INTERFACE has a usable source
* address (indicated by ill_usesrc_ifindex) in the
* correct zone then it's permitted to return this IRE
*/
if (match_flags & MATCH_IRE_ZONEONLY)
return (B_FALSE);
return (B_FALSE);
/*
* Note, IRE_INTERFACE can have the stq as NULL. For
* example, if the default multicast route is tied to
* the loopback address.
*/
/*
* If there is a usable source address in the
* zone, then it's ok to return an
* IRE_INTERFACE
*/
ip3dbg(("ire_match_args: dst_ill %p match %d\n",
(void *)dst_ill,
} else {
ip3dbg(("ire_match_args: src_ipif NULL"
" dst_ill %p\n", (void *)dst_ill));
return (B_FALSE);
}
}
if ((match_flags & MATCH_IRE_DEFAULT) == 0) {
return (B_FALSE);
}
if (IPIF_CAN_LOOKUP(tipif) &&
break;
}
return (B_FALSE);
}
}
}
/*
* For IRE_CACHES, MATCH_IRE_ILL/ILL_GROUP really means that
* somebody wants to send out on a particular interface which
* is given by ire_stq and hence use ire_stq to derive the ill
* value. ire_ipif for IRE_CACHES is just the means of getting
* a source address i.e ire_src_addr = ire->ire_ipif->ipif_src_addr.
* ire_to_ill does the right thing for this.
*/
}
((!(match_flags & MATCH_IRE_GW)) ||
((!(match_flags & MATCH_IRE_TYPE)) ||
((!(match_flags & MATCH_IRE_SRC)) ||
((!(match_flags & MATCH_IRE_IPIF)) ||
((!(match_flags & MATCH_IRE_MARK_HIDDEN)) ||
((!(match_flags & MATCH_IRE_ILL)) ||
((!(match_flags & MATCH_IRE_IHANDLE)) ||
((!(match_flags & MATCH_IRE_ILL_GROUP)) ||
(ire_ill_group != NULL &&
ire_ill_group == ipif_ill_group))) {
/* We found the matched IRE */
return (B_TRUE);
}
return (B_FALSE);
}
/*
* Lookup for a route in all the tables
*/
ire_t *
{
/*
* ire_match_args() will dereference ipif MATCH_IRE_SRC or
* MATCH_IRE_ILL is set.
*/
return (NULL);
/*
* might be asking for a cache lookup,
* This is not best way to lookup cache,
* user should call ire_cache_lookup directly.
*
* If MATCH_IRE_TYPE was set, first lookup in the cache table and then
* in the forwarding table, if the applicable type flags were set.
*/
flags);
return (ire);
}
}
return (ire);
}
/*
* Lookup a route in forwarding table.
* specific lookup is indicated by passing the
* required parameters and indicating the
* match required in flag field.
*
* Looking for default route can be done in three ways
* 1) pass mask as 0 and set MATCH_IRE_MASK in flags field
* along with other matches.
* 2) pass type as IRE_DEFAULT and set MATCH_IRE_TYPE in flags
* field along with other matches.
* 3) if the destination and mask are passed as zeros.
*
* A request to return a default route if no route
* is found, can be specified by setting MATCH_IRE_DEFAULT
* in flags.
*
* It does not support recursion more than one level. It
* will do recursive lookup only when the lookup maps to
* a prefix or default route and MATCH_IRE_RECURSIVE flag is passed.
*
* If the routing table is setup to allow more than one level
* of recursion, the cleaning up cache table will not work resulting
* in invalid routing.
*
*
* NOTE : When this function returns NULL, pire has already been released.
* pire is valid only when this function successfully returns an
* ire.
*/
ire_t *
int flags)
{
int i;
/*
* When we return NULL from this function, we should make
* sure that *pire is NULL so that the callers will not
* wrongly REFRELE the pire.
*/
/*
* ire_match_args() will dereference ipif MATCH_IRE_SRC or
* MATCH_IRE_ILL is set.
*/
return (NULL);
/*
* If the mask is known, the lookup
* is simple, if the mask is not known
* we need to search.
*/
if (flags & MATCH_IRE_MASK) {
return (NULL);
continue;
goto found_ire;
}
} else {
/*
* In this case we don't know the mask, we need to
* search the table assuming different mask sizes.
* we start with 32 bit mask, we don't allow default here.
*/
for (i = (IP_MASK_TABLE_SIZE - 1); i > 0; i--) {
if ((ip_forwarding_table[i]) == NULL)
continue;
tmpmask = ip_plen_to_mask(i);
irb_ptr = &ip_forwarding_table[i][
continue;
flags))
goto found_ire;
}
}
}
/*
* We come here if no route has yet been found.
*
* Handle the case where default route is
* requested by specifying type as one of the possible
* types for that can have a zero mask (IRE_DEFAULT and IRE_INTERFACE).
*
* If MATCH_IRE_MASK is specified, then the appropriate default route
* would have been found above if it exists so it isn't looked up here.
* If MATCH_IRE_DEFAULT was also specified, then a default route will be
* searched for later.
*/
if ((ip_forwarding_table[0])) {
/* addr & mask is zero for defaults */
irb_ptr = &ip_forwarding_table[0][
continue;
flags))
goto found_ire;
}
}
}
/*
* we come here only if no route is found.
* see if the default route can be used which is allowed
* only if the default matching criteria is specified.
* The ip_ire_default_count tracks the number of IRE_DEFAULT
* entries. However, the ip_forwarding_table[0] also contains
* interface routes thus the count can be zero.
*/
if (ip_forwarding_table[0] == NULL)
return (NULL);
irb_ptr = &(ip_forwarding_table[0])[0];
/*
* Keep a tab on the bucket while looking the IRE_DEFAULT
* entries. We need to keep track of a particular IRE
* (ire_origin) so this ensures that it will not be unlinked
* from the hash list during the recursive lookup below.
*/
return (NULL);
}
/*
* Get the index first, since it can be changed by other
* threads. Then get to the right default route skipping
* default interface routes if any. As we hold a reference on
* the IRE bucket, ip_ire_default_count can only increase so we
* can't reach the end of the hash list unexpectedly.
*/
if (ip_ire_default_count != 0) {
while (index != 0) {
index--;
}
} else {
/*
* No default routes, so we only have default interface
* routes: don't enter the first loop.
*/
}
/*
* Round-robin the default routers list looking for a route that
* matches the passed in parameters. If we can't find a default
* route (IRE_DEFAULT), look for interface default routes.
* We start with the ire we found above and we walk the hash
* list until we're back where we started, see
* ire_get_next_default_ire(). It doesn't matter if default
* routes are added or deleted by other threads - we know this
* ire will stay in the list because we hold a reference on the
* ire bucket.
* NB: if we only have interface default routes, ire is NULL so
* we don't even enter this loop (see above).
*/
ire_origin = ire;
int match_flags = 0;
/*
* The potentially expensive call to
* ire_route_lookup() is avoided when we have
* only one default route.
*/
if (ip_ire_default_count == 1 ||
goto found_ire_held;
}
/*
* When we're in a local zone, we're only
* interested in default routers that are
* reachable through ipifs within our zone.
*/
}
goto found_ire_held;
}
}
}
/*
* Either there are no default routes or we could not
* find a default route. Look for a interface default
* route matching the args passed in. No round robin
* here. Just pick the right one.
*/
continue;
continue;
goto found_ire_held;
}
}
}
return (NULL);
if ((flags & MATCH_IRE_RJ_BHOLE) &&
return (ire);
}
/*
* At this point, IRE that was found must be an IRE_FORWARDTABLE
* type. If this is a recursive lookup and an IRE_INTERFACE type was
* found, return that. If it was some other IRE_FORWARDTABLE type of
* IRE (one of the prefix types), then it is necessary to fill in the
* parent IRE pointed to by pire, and then lookup the gateway address of
* the parent. For backwards compatiblity, if this lookup returns an
* IRE other than a IRE_CACHETABLE or IRE_INTERFACE, then one more level
* of lookup is done.
*/
if (flags & MATCH_IRE_RECURSIVE) {
int match_flags = MATCH_IRE_DSTONLY;
return (ire);
/*
* If we can't find an IRE_INTERFACE or the caller has not
* asked for pire, we need to REFRELE the save_ire.
*/
/*
* Currently MATCH_IRE_ILL is never used with
* (MATCH_IRE_RECURSIVE | MATCH_IRE_DEFAULT) while
* sending out packets as MATCH_IRE_ILL is used only
* for communicating with on-link hosts. We can't assert
* that here as RTM_GET calls this function with
* MATCH_IRE_ILL | MATCH_IRE_DEFAULT | MATCH_IRE_RECURSIVE.
* We have already used the MATCH_IRE_ILL in determining
* the right prefix route at this point. To match the
* behavior of how we locate routes while sending out
* packets, we don't want to use MATCH_IRE_ILL below
* while locating the interface route.
*/
/*
* Do not release the parent ire if MATCH_IRE_PARENT
* is set. Also return it via ire.
*/
if (flags & MATCH_IRE_PARENT) {
/*
* Need an extra REFHOLD, if the parent
* ire is returned via both ire and
* pire.
*/
}
} else {
}
return (ire);
}
/*
* If the caller did not ask for pire, release
* it now.
*/
}
return (ire);
}
/*
* Do not release the parent ire if MATCH_IRE_PARENT
* is set. Also return it via ire.
*/
if (flags & MATCH_IRE_PARENT) {
/*
* Need an extra REFHOLD, if the
* parent ire is returned via both
* ire and pire.
*/
}
} else {
}
return (ire);
/*
* If the caller did not ask for pire, release
* it now.
*/
}
return (ire);
}
return (ire);
}
/*
* Looks up cache table for a route.
* specific lookup can be indicated by
* passing the MATCH_* flags and the
* necessary parameters.
*/
ire_t *
{
/*
* ire_match_args() will dereference ipif MATCH_IRE_SRC or
* MATCH_IRE_ILL is set.
*/
return (NULL);
continue;
return (ire);
}
}
return (NULL);
}
/*
* Lookup cache. Don't return IRE_MARK_HIDDEN entries. Callers
* should use ire_ctable_lookup with MATCH_IRE_MARK_HIDDEN to get
* to the hidden ones.
*/
ire_t *
{
continue;
return (ire);
}
}
}
return (NULL);
}
/*
* Locate the interface ire that is tied to the cache ire 'cire' via
* cire->ire_ihandle.
*
* We are trying to create the cache ire for an offlink destn based
* on the cache ire of the gateway in 'cire'. 'pire' is the prefix ire
* as found by ip_newroute(). We are called from ip_newroute() in
* the IRE_CACHE case.
*/
ire_t *
{
int match_flags;
/*
* We don't need to specify the zoneid to ire_ftable_lookup() below
* because the ihandle refers to an ipif which can be in only one zone.
*/
/*
* ip_newroute calls ire_ftable_lookup with MATCH_IRE_ILL only
* for on-link hosts. We should never be here for onlink.
* Thus, use MATCH_IRE_ILL_GROUP.
*/
/*
* We know that the mask of the interface ire equals cire->ire_cmask.
* (When ip_newroute() created 'cire' for the gateway it set its
* cmask from the interface ire's mask)
*/
return (ire);
/*
* If we didn't find an interface ire above, we can't declare failure.
* For backwards compatibility, we need to support prefix routes
* pointing to next hop gateways that are not on-link.
*
* Assume we are trying to ping some offlink destn, and we have the
* routing table below.
*
* Eg. default - gw1 <--- pire (line 1)
* gw1 - gw2 (line 2)
* gw2 - hme0 (line 3)
*
* If we already have a cache ire for gw1 in 'cire', the
* ire_ftable_lookup above would have failed, since there is no
* interface ire to reach gw1. We will fallthru below.
*
* Here we duplicate the steps that ire_ftable_lookup() did in
* getting 'cire' from 'pire', in the MATCH_IRE_RECURSIVE case.
* The differences are the following
* i. We want the interface ire only, so we call ire_ftable_lookup()
* instead of ire_route_lookup()
* ii. We look for only prefix routes in the 1st call below.
* ii. We want to match on the ihandle in the 2nd call below.
*/
return (NULL);
/*
* At this point 'ire' corresponds to the entry shown in line 2.
* gw_addr is 'gw2' in the example above.
*/
return (ire);
}
/*
* Locate the interface ire that is tied to the cache ire 'cire' via
* cire->ire_ihandle.
*
* We are trying to create the cache ire for an onlink destn. or
* gateway in 'cire'. We are called from ire_add_v4() in the IRE_IF_RESOLVER
* case, after the ire has come back from ARP.
*/
ire_t *
{
int match_flags;
int i;
int j;
/*
* We don't need to specify the zoneid to ire_ftable_lookup() below
* because the ihandle refers to an ipif which can be in only one zone.
*/
/*
* We know that the mask of the interface ire equals cire->ire_cmask.
* (When ip_newroute() created 'cire' for an on-link destn. it set its
* cmask from the interface ire's mask)
*/
return (ire);
/*
* If we didn't find an interface ire above, we can't declare failure.
* For backwards compatibility, we need to support prefix routes
* pointing to next hop gateways that are not on-link.
*
* In the resolver/noresolver case, ip_newroute() thinks it is creating
* the cache ire for an onlink destination in 'cire'. But 'cire' is
* not actually onlink, because ire_ftable_lookup() cheated it, by
* doing ire_route_lookup() twice and returning an interface ire.
*
* Eg. default - gw1 (line 1)
* gw1 - gw2 (line 2)
* gw2 - hme0 (line 3)
*
* In the above example, ip_newroute() tried to create the cache ire
* 'cire' for gw1, based on the interface route in line 3. The
* ire_ftable_lookup() above fails, because there is no interface route
* to reach gw1. (it is gw2). We fall thru below.
*
* Do a brute force search based on the ihandle in a subset of the
* forwarding tables, corresponding to cire->ire_cmask. Otherwise
* things become very complex, since we don't have 'pire' in this
* case. (Also note that this method is not possible in the offlink
* case because we don't know the mask)
*/
if ((ip_forwarding_table[i]) == NULL)
return (NULL);
for (j = 0; j < ip_ftable_hash_size; j++) {
irb_ptr = &ip_forwarding_table[i][j];
continue;
return (ire);
}
}
}
return (NULL);
}
/*
* ire_mrtun_lookup() is called by ip_rput() when packet is to be
* tunneled through reverse tunnel. This is only supported for
* IPv4 packets
*/
ire_t *
{
if (ip_mrtun_table == NULL)
return (NULL);
continue;
return (ire);
}
}
return (NULL);
}
/*
* Return the IRE_LOOPBACK, IRE_IF_RESOLVER or IRE_IF_NORESOLVER
* ire associated with the specified ipif.
*
* This might occasionally be called when IPIF_UP is not set since
* the IP_MULTICAST_IF as well as creating interface routes
* allows specifying a down ipif (ipif_lookup* match ipifs that are down).
*
* Note that if IPIF_NOLOCAL, IPIF_NOXMIT, or IPIF_DEPRECATED is set on
* the ipif, this routine might return NULL.
*/
ire_t *
{
/* In this case we need to lookup destination address. */
} else {
}
return (ire);
}
/*
* ire_walk function.
* Count the number of IRE_CACHE entries in different categories.
*/
void
{
return;
icc->icc_onlink++;
return;
}
} else {
if (ire->ire_gateway_addr == 0) {
icc->icc_onlink++;
return;
}
}
icc->icc_offlink++;
else
icc->icc_unused++;
}
/*
* ire_walk function called by ip_trash_ire_reclaim().
* Free a fraction of the IRE_CACHE cache entries. The fractions are
* different for different categories of IRE_CACHE entries.
* A fraction of zero means to not free any in that category.
* Use the hash bucket id plus lbolt as a random number. Thus if the fraction
* is N then every Nth hash bucket chain will be freed.
*/
void
{
return;
if (icr->icr_onlink != 0 &&
return;
}
goto done;
}
} else {
if (ire->ire_gateway_addr == 0) {
if (icr->icr_onlink != 0 &&
return;
}
goto done;
}
}
/* Not onlink IRE */
/* Use ptmu fraction */
return;
}
ire->ire_ib_pkt_count) {
/* Use offlink fraction */
if (icr->icr_offlink != 0 &&
return;
}
} else {
/* Use unused fraction */
if (icr->icr_unused != 0 &&
return;
}
}
done:
/*
* Update tire_mark so that those that haven't been used since this
* reclaim will be considered unused next time we reclaim.
*/
}
static void
{
int i;
for (i = 1; i < 31; i++) {
if (*value <= (1 << i))
break;
}
*value = (1 << i);
}
void
{
int i;
/* Calculate the IPv4 cache table size. */
/*
* Make sure that the table size is always a power of 2. The
* hash macro IRE_ADDR_HASH() depends on that.
*/
for (i = 0; i < ip_cache_table_size; i++) {
RW_DEFAULT, NULL);
}
/* Calculate the IPv6 cache table size. */
/*
* Make sure that the table size is always a power of 2. The
* hash macro IRE_ADDR_HASH_V6() depends on that.
*/
for (i = 0; i < ip6_cache_table_size; i++) {
RW_DEFAULT, NULL);
}
/*
* Create ire caches, ire_reclaim()
* will give IRE_CACHE back to system when needed.
* This needs to be done here before anything else, since
* ire_add() expects the cache to be created.
*/
sizeof (ire_t), 0, ip_ire_constructor,
/*
* Initialize ip_mrtun_table to NULL now, it will be
* populated by ip_rt_add if reverse tunnel is created
*/
/*
* Make sure that the forwarding table size is a power of 2.
* The IRE*_ADDR_HASH() macroes depend on that.
*/
}
void
{
int i;
for (i = 0; i < ip_cache_table_size; i++) {
}
for (i = 0; i < ip6_cache_table_size; i++) {
}
if (ip_mrtun_table != NULL) {
for (i = 0; i < IP_MRTUN_TABLE_SIZE; i++) {
}
}
}
int
{
int i;
int error;
/* Is ip_mrtun_table empty ? */
if (ip_mrtun_table == NULL) {
/* create the mrtun table */
if (ip_mrtun_table == NULL) {
sizeof (irb_t), KM_NOSLEEP);
if (ip_mrtun_table == NULL) {
ip2dbg(("ire_add_mrtun: allocation failure\n"));
return (ENOMEM);
}
for (i = 0; i < IP_MRTUN_TABLE_SIZE; i++) {
RW_DEFAULT, NULL);
}
ip2dbg(("ire_add_mrtun: mrtun table is created\n"));
}
/* some other thread got it and created the table */
}
/*
* Check for duplicate in the bucket and insert in the table
*/
/*
* Start the atomic add of the ire. Grab the ill locks,
* ill_g_usesrc_lock and the bucket lock.
*
* If ipif or ill is changing ire_atomic_start() may queue the
* request and return EINPROGRESS.
*/
if (error != 0) {
/*
* We don't know whether it is a valid ipif or not.
* So, set it to NULL. This assumes that the ire has not added
* a reference to the ipif.
*/
ip1dbg(("ire_add_mrtun: ire_atomic_start failed\n"));
return (error);
}
continue;
/* has anyone inserted the route in the meanwhile ? */
ip1dbg(("ire_add_mrtun: Duplicate entry exists\n"));
/* Return the old ire */
return (0);
}
}
/* Atomically set the ire_max_frag */
/* Find the last ire which matches ire_in_src_addr */
break;
}
}
/* Link the new one in. */
/*
* Protect ire_mrtun_count and ill_mrtun_refcnt from
* another thread trying to add ire in the table
*/
/*
* ill_mrtun_refcnt is protected by the ill_lock held via
* ire_atomic_start
*/
stq_ill->ill_ire_cnt++;
}
} else {
}
return (0);
}
/* Walks down the mrtun table */
void
{
int i;
int ret;
if (ire_mrtun_count == 0) {
return;
}
ip2dbg(("ire_walk_ill_mrtun:walking the reverse tunnel table \n"));
for (i = 0; i < IP_MRTUN_TABLE_SIZE; i++) {
irb = &(ip_mrtun_table[i]);
continue;
if (match_flags != 0) {
}
if (match_flags == 0 || ret)
}
}
}
/*
* Source interface based lookup routine (IPV4 only).
* This routine is called only when RTA_SRCIFP bitflag is set
* also called from ip_rput() when packets arrive from an interface
* for which ill_srcif_ref_cnt is positive. This function is useful
* when a packet coming from one interface must be forwarded to another
* designated interface to reach the correct node. This function is also
* called from ip_newroute when the link-layer address of an ire is resolved.
* We need to make sure that ip_newroute searches for IRE_IF_RESOLVER type
* ires--thus the ire_type parameter is needed.
*/
ire_t *
{
/*
* No need to lock the ill since it is refheld by the caller of this
* function
*/
return (NULL);
}
if (!(flags & MATCH_IRE_TYPE)) {
flags |= MATCH_IRE_TYPE;
}
continue;
return (ire);
}
}
/* Not Found */
return (NULL);
}
/*
* Adds the ire into the special routing table which is hanging off of
* the src_ipif->ipif_ill. It also increments the refcnt in the ill.
* The forward table contains only IRE_IF_RESOLVER, IRE_IF_NORESOLVER
* i,e. IRE_INTERFACE entries. Originally the dlureq_mp field is NULL
* for IRE_IF_RESOLVER entry because we do not have the dst_addr's
* link-layer address at the time of addition.
* Upon resolving the address from ARP, dlureq_mp field is updated with
* proper information in ire_update_srcif_v4.
*/
static int
{
int flags;
int i;
int error = 0;
/* Update ire_dlureq_mp with NULL value upon creation */
/*
* assign NULL now, it will be updated
* with correct value upon returning from
* ARP
*/
} else {
}
/* Make sure the address is properly masked. */
/* create the incoming interface based table */
sizeof (irb_t), KM_NOSLEEP);
ip1dbg(("ire_add_srcif_v4: Allocation fail\n"));
return (ENOMEM);
}
for (i = 0; i < IP_SRCIF_TABLE_SIZE; i++) {
RW_DEFAULT, NULL);
}
ip2dbg(("ire_add_srcif_v4: table created for ill %p\n",
(void *)ire->ire_in_ill));
}
/* Check for duplicate and insert */
irb_ptr =
flags |= MATCH_IRE_IPIF;
/*
* Start the atomic add of the ire. Grab the ill locks,
* ill_g_usesrc_lock and the bucket lock.
*
* If ipif or ill is changing ire_atomic_start() may queue the
* request and return EINPROGRESS.
*/
if (error != 0) {
/*
* We don't know whether it is a valid ipif or not.
* So, set it to NULL. This assumes that the ire has not added
* a reference to the ipif.
*/
ip1dbg(("ire_add_srcif_v4: ire_atomic_start failed\n"));
return (error);
}
continue;
continue;
/* Has anyone inserted route in the meanwhile ? */
ip1dbg(("ire_add_srcif_v4 : Duplicate entry exists\n"));
/* Return old ire as in ire_add_v4 */
return (0);
}
}
/* Find the last ire which matches ire_addr */
break;
}
}
/* Link the new one in. */
/*
* Protect ire_in_ill->ill_srcif_refcnt and table reference count.
* Note, ire_atomic_start already grabs the ire_in_ill->ill_lock
* so ill_srcif_refcnt is already protected.
*/
irb_ptr->irb_ire_cnt++;
stq_ill->ill_ire_cnt++;
}
} else {
}
return (0);
}
/*
* This function is called by ire_add_then_send when ARP request comes
* back to ip_wput->ire_add_then_send for resolved ire in the interface
* based routing table. At this point, it only needs to update the resolver
* information for the ire. The passed ire is returned to the caller as it
* is the ire which is created as mblk.
*/
static ire_t *
{
int error;
/*
* This ire is from ARP. Update
* ire_dlureq_mp info
*/
/* Mobile node registration expired ? */
return (NULL);
}
/*
* Start the atomic add of the ire. Grab the ill locks,
* ill_g_usesrc_lock and the bucket lock.
*/
if (error != 0) {
/*
* We don't know whether it is a valid ipif or not.
* So, set it to NULL. This assumes that the ire has not added
* a reference to the ipif.
*/
ip1dbg(("ire_update_srcif_v4: ire_atomic_start failed\n"));
return (NULL);
}
/*
* Update resolver information and
* send-to queue.
*/
ip0dbg(("ire_update_srcif: copyb failed\n"));
return (NULL);
}
/* Return the passed ire */
return (ire); /* Update done */
}
/*
* Check if another multirt route resolution is needed.
* B_TRUE is returned is there remain a resolvable route,
* or if no route for that dst is resolved yet.
* B_FALSE is returned if all routes for that dst are resolved
* or if the remaining unresolved routes are actually not
* resolvable.
* This only works in the global zone.
*/
{
int unres_cnt = 0;
/* Retrieve the first IRE_HOST that matches the destination */
/* No route at all */
if (first_fire == NULL) {
return (B_TRUE);
}
/* Retrieve the first IRE_CACHE ire for that destination. */
/* No resolved route. */
if (first_cire == NULL) {
return (B_TRUE);
}
/*
* At least one route is resolved. Here we look through the forward
* and cache tables, to compare the number of declared routes
* with the number of resolved routes. The search for a resolvable
* route is performed only if at least one route remains
* unresolved.
*/
/* Count the number of routes to that dest that are declared. */
continue;
continue;
unres_cnt++;
}
/* Then subtract the number of routes to that dst that are resolved */
continue;
continue;
continue;
unres_cnt--;
}
/* At least one route is unresolved; search for a resolvable route. */
if (unres_cnt > 0)
if (first_fire != NULL)
if (first_cire != NULL)
return (resolvable);
}
/*
* Explore a forward_table bucket, starting from fire_arg.
* fire_arg MUST be an IRE_HOST entry.
*
* Return B_TRUE and update *ire_arg and *fire_arg
* if at least one resolvable route is found. *ire_arg
* is the IRE entry for *fire_arg's gateway.
*
* Return B_FALSE otherwise (all routes are resolved or
* the remaining unresolved routes are all unresolvable).
*
* The IRE selection relies on a priority mechanism
* driven by the flags passed in by the caller.
* The caller, such as ip_newroute_ipif(), can get the most
* relevant ire at each stage of a multiple route resolution.
*
* The rules are:
*
* - if MULTIRT_CACHEGW is specified in flags, IRE_CACHETABLE
* ires are preferred for the gateway. This gives the highest
* priority to routes that can be resolved without using
* a resolver.
*
* - if MULTIRT_CACHEGW is not specified, or if MULTIRT_CACHEGW
* is specified but no IRE_CACHETABLE ire entry for the gateway
* is found, the following rules apply.
*
* - if MULTIRT_USESTAMP is specified in flags, IRE_INTERFACE
* ires for the gateway, that have not been tried since
* a configurable amount of time, are preferred.
* This applies when a resolver must be invoked for
* a missing route, but we don't want to use the resolver
* upon each packet emission. If no such resolver is found,
* B_FALSE is returned.
* The MULTIRT_USESTAMP flag can be combined with
* MULTIRT_CACHEGW.
*
* - if MULTIRT_USESTAMP is not specified in flags, the first
* unresolved but resolvable route is selected.
*
* - Otherwise, there is no resolvalble route, and
* B_FALSE is returned.
*
* At last, MULTIRT_SETSTAMP can be specified in flags to
* request the timestamp of unresolvable routes to
* be refreshed. This prevents the useless exploration
* of those routes for a while, when MULTIRT_USESTAMP is used.
*
* This only works in the global zone.
*/
{
ip2dbg(("ire_multirt_lookup: *ire_arg %p, *fire_arg %p, flags %04x\n",
/* Not an IRE_HOST ire; give up. */
return (B_FALSE);
}
/* This is the first IRE_HOST ire for that destination. */
first_fire = *fire_arg;
/*
* Retrieve the first IRE_CACHE ire for that destination;
* if we don't find one, no route for that dest is
* resolved yet.
*/
if (first_cire != NULL) {
}
/*
* Search for a resolvable route, giving the top priority
* to routes that can be resolved without any call to the resolver.
*/
/*
* For all multiroute IRE_HOST ires for that destination,
* check if the route via the IRE_HOST's gateway is
* resolved yet.
*/
continue;
continue;
ip2dbg(("ire_multirt_lookup: fire %p, "
"ire_addr %08x, ire_gateway_addr %08x\n",
if (first_cire != NULL) {
/*
* For all IRE_CACHE ires for that
* destination.
*/
for (cire = first_cire;
continue;
continue;
continue;
/*
* Check if the IRE_CACHE's gateway
* matches the IRE_HOST's gateway.
*/
break;
}
}
}
/*
* This route is already resolved;
* proceed with next one.
*/
if (already_resolved) {
ip2dbg(("ire_multirt_lookup: found cire %p, "
"already resolved\n", (void *)cire));
continue;
}
/*
* The route is unresolved; is it actually
* resolvable, i.e. is there a cache or a resolver
* for the gateway?
*/
ip2dbg(("ire_multirt_lookup: looked up gw_ire %p\n",
(void *)gw_ire));
/*
* If gw_ire is typed IRE_CACHETABLE,
* this route can be resolved without any call to the
* resolver. If the MULTIRT_CACHEGW flag is set,
* give the top priority to this ire and exit the
* loop.
* This is typically the case when an ARP reply
* is processed through ip_wput_nondata().
*/
if ((flags & MULTIRT_CACHEGW) &&
/*
* Release the resolver associated to the
* previous candidate best ire, if any.
*/
}
ip2dbg(("ire_multirt_lookup: found top prio "
"best_fire %p, best_cire %p\n",
break;
}
/*
* Compute the time elapsed since our preceding
* attempt to resolve that route.
* If the MULTIRT_USESTAMP flag is set, we take that
* route into account only if this time interval
* exceeds ip_multirt_resolution_interval;
* this prevents us from attempting to resolve a
* broken route upon each sending of a packet.
*/
((delta > ip_multirt_resolution_interval) ||
(!(flags & MULTIRT_USESTAMP)));
ip2dbg(("ire_multirt_lookup: fire %p, delta %lu, "
"res %d\n",
if (res) {
/*
* We are here if MULTIRT_USESTAMP flag is set
* and the resolver for fire's gateway
* has not been tried since
* ip_multirt_resolution_interval, or if
* MULTIRT_USESTAMP is not set but gw_ire did
* not fill the conditions for MULTIRT_CACHEGW,
* or if neither MULTIRT_USESTAMP nor
* MULTIRT_CACHEGW are set.
*/
ip2dbg(("ire_multirt_lookup:"
"found candidate "
"best_fire %p, "
"best_cire %p\n",
(void *)best_fire,
(void *)best_cire));
/*
* If MULTIRT_CACHEGW is not
* set, we ignore the top
* priority ires that can
* be resolved without any
* call to the resolver;
* In that case, there is
* actually no need
* to continue the loop.
*/
if (!(flags &
MULTIRT_CACHEGW)) {
break;
}
continue;
}
} else {
/*
* No resolver for the gateway: the
* route is not resolvable.
* If the MULTIRT_SETSTAMP flag is
* set, we stamp the IRE_HOST ire,
* so we will not select it again
* during this resolution interval.
*/
if (flags & MULTIRT_SETSTAMP)
}
}
}
} else { /* CLASSD(dst) */
for (fire = first_fire;
continue;
continue;
/* No resolver for the gateway; we skip this ire. */
continue;
}
if (first_cire != NULL) {
/*
* For all IRE_CACHE ires for that
* destination.
*/
for (cire = first_cire;
continue;
continue;
continue;
/*
* Cache entries are linked to the
* parent routes using the parent handle
* (ire_phandle). If no cache entry has
* the same handle as fire, fire is
* still unresolved.
*/
if (cire->ire_phandle ==
fire->ire_phandle) {
break;
}
}
}
/*
* This route is already resolved; proceed with
* next one.
*/
if (already_resolved) {
continue;
}
/*
* Compute the time elapsed since our preceding
* attempt to resolve that route.
* If the MULTIRT_USESTAMP flag is set, we take
* that route into account only if this time
* interval exceeds ip_multirt_resolution_interval;
* this prevents us from attempting to resolve a
* broken route upon each sending of a packet.
*/
((delta > ip_multirt_resolution_interval) ||
(!(flags & MULTIRT_USESTAMP)));
ip3dbg(("ire_multirt_lookup: fire %p, delta %lx, "
"flags %04x, res %d\n",
if (res) {
/*
* Release the resolver associated
* to the preceding candidate best
* ire, if any.
*/
}
continue;
}
}
}
}
/* Release the first IRE_CACHE we initially looked up, if any. */
if (first_cire != NULL)
/* Found a resolvable route. */
/*
* Update the passed-in arguments with the
* resolvable multirt route we found.
*/
ip2dbg(("ire_multirt_lookup: returning B_TRUE, "
"*fire_arg %p, *ire_arg %p\n",
return (B_TRUE);
}
ip2dbg(("ire_multirt_lookup: returning B_FALSE, *fire_arg %p, "
"*ire_arg %p\n",
/* No resolvable route. */
return (B_FALSE);
}
/*
* Find an IRE_OFFSUBNET IRE entry for the multicast address 'group'
* that goes through 'ipif'. As a fallback, a route that goes through
* ipif->ipif_ill can be returned.
*/
ire_t *
{
return (NULL);
continue;
}
case IRE_DEFAULT:
case IRE_PREFIX:
case IRE_HOST:
}
return (ire);
}
}
break;
case IRE_IF_NORESOLVER:
case IRE_IF_RESOLVER:
}
return (ire);
}
break;
}
}
return (save_ire);
}
/*
* The purpose of the next two functions is to provide some external access to
* returned by name instead of by ILL reference. These functions are used by
* IP Filter.
* Return a link layer header suitable for an IP packet being sent to the
* dst_addr IP address. The interface associated with the route is put into
* ifname, which must be a buffer of LIFNAMSIZ bytes. The dst_addr is the
* packet's ultimate destination address, not a router address.
*
* This function is used when the caller wants to know the outbound interface
* and MAC header for a packet given only the address.
*/
mblk_t *
{
/* parameter sanity */
return (NULL);
/* Find the route entry, if it exists. */
case AF_INET:
0xffffffff,
break;
case AF_INET6:
NULL,
}
break;
default:
break;
}
return (NULL);
/* Map the IRE to an ILL so we can fill in ifname. */
return (NULL);
}
/* Return a copy of the header to the caller. */
case AF_INET :
} else {
}
break;
case AF_INET6 :
} else {
}
break;
}
return (mp);
}
/*
* Return a link layer header suitable for an IP packet being sent to the
* dst_addr IP address on the specified output interface. The dst_addr
* may be the packet's ultimate destination or a predetermined next hop
* router's address.
* ifname must be nul-terminated.
*
* This function is used when the caller knows the outbound interface (usually
* because it was specified by policy) and only needs the MAC header for a
* packet.
*/
mblk_t *
{
/* parameter sanity */
return (NULL);
case AF_INET :
break;
case AF_INET6 :
sap = IP6_DL_SAP;
break;
default:
return (NULL);
}
/* Lock ill_g_lock before walking through the list */
/*
* Can we find the interface name among those currently configured?
*/
break;
}
return (NULL);
}
if (!ILL_CAN_LOOKUP(ill)) {
return (NULL);
}
/* Find the resolver entry, if it exists. */
case AF_INET:
0xffffffff,
break;
case AF_INET6:
}
break;
default:
break;
}
return (NULL);
/* Return a copy of the header to the caller. */
case AF_INET :
} else {
}
break;
case AF_INET6 :
} else {
}
break;
}
return (mp);
}
/*
* IRE iterator for inbound and loopback broadcast processing.
* Given an IRE_BROADCAST ire, walk the ires with the same destination
* address, but skip over the passed-in ire. Returns the next ire without
* a hold - assumes that the caller holds a reference on the IRE bucket.
*/
ire_t *
{
break;
}
} else {
}
/*
* All the IREs to a given destination are contiguous;
* break out once the address doesn't match.
*/
break;
}
/* skip over the passed-in ire */
continue;
}
/*
* If the passed-in ire is loopback, skip over
* non-loopback ires and vice versa.
*/
continue;
}
/* skip over IREs going through a different interface */
continue;
}
/* skip over deleted IREs */
continue;
}
return (curr);
}
return (NULL);
}
/*
* IRE iterator used by ire_ftable_lookup[_v6]() to process multiple default
* routes. Given a starting point in the hash list (ire_origin), walk the IREs
* in the bucket skipping default interface routes and deleted entries.
* Returns the next IRE (unheld), or NULL when we're back to the starting point.
* Assumes that the caller holds a reference on the IRE bucket.
*/
ire_t *
{
do {
if (ire == ire_origin)
return (NULL);
return (ire);
}
#ifdef IRE_DEBUG
{
int bucket_id;
return (th_trace);
}
return (NULL);
}
void
{
int bucket_id;
/*
* Attempt to locate the trace buffer for the curthread.
* If it does not exist, then allocate a new trace buffer
* and link it in list of trace bufs for this ipif, at the head
*/
return;
}
return;
}
}
}
void
{
/* unlink th_trace and free it */
}
void
{
return;
}
}
static void
{
int i;
for (i = 0; i < IP_TR_HASH_MAX; i++) {
/* unlink th_trace and free it */
}
}
}
/* ARGSUSED */
void
{
return;
}
}
#endif