ip6_asp.c revision 27c48ed935c6a5f6015c6534b98e3090b1ddfdb6
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/sysmacros.h>
#include <inet/ipclassifier.h>
#define IN6ADDR_MASK128_INIT \
{ 0xffffffffU, 0xffffffffU, 0xffffffffU, 0xffffffffU }
#ifdef _BIG_ENDIAN
#define IN6ADDR_MASK16_INIT { 0xffff0000U, 0, 0, 0 }
#else
#define IN6ADDR_MASK16_INIT { 0x0000ffffU, 0, 0, 0 }
#endif
/*
* This table is ordered such that longest prefix matches are hit first
* (longer prefix lengths first). The last entry must be the "default"
* entry (::0/0).
*/
static ip6_asp_t default_ip6_asp_table[] = {
"Loopback", 50 },
"IPv4_Compatible", 20 },
#ifdef _BIG_ENDIAN
{ { 0, 0, 0x0000ffffU, 0 }, IN6ADDR_MASK96_INIT,
"IPv4", 10 },
{ { 0x20020000U, 0, 0, 0 }, IN6ADDR_MASK16_INIT,
"6to4", 30 },
#else
{ { 0, 0, 0xffff0000U, 0 }, IN6ADDR_MASK96_INIT,
"IPv4", 10 },
{ { 0x00000220U, 0, 0, 0 }, IN6ADDR_MASK16_INIT,
"6to4", 30 },
#endif
"Default", 40 }
};
/*
* The IPv6 Default Address Selection policy table.
* Until someone up above reconfigures the policy table, use the global
* default. The table needs no lock since the only way to alter it is
* through the SIOCSIP6ADDRPOLICY which is exclusive in ip.
*/
static void ip6_asp_check_for_updates(ip_stack_t *);
void
{
/* Initialize the table lock */
sizeof (default_ip6_asp_table) / sizeof (ip6_asp_t);
}
void
{
}
}
/*
* Return false if the table is being updated. Else, increment the ref
* count and return true.
*/
{
if (ipst->ips_ip6_asp_uip) {
return (B_FALSE);
}
return (B_TRUE);
}
void
{
} else {
}
}
static void
{
queue_t *q;
}
}
/*
* Decrement reference count. When it gets to 0, we check for (pending)
* saved update to the table, if any.
*/
void
{
}
/*
* This function is guaranteed never to return a NULL pointer. It
* will always return information from one of the entries in the
* asp_table (which will never be empty). If a pointer is passed
* in for the precedence, the precedence value will be set; a
* pointer to the label will be returned by the function.
*
* Since the table is only anticipated to have five or six entries
* total, the lookup algorithm hasn't been optimized to anything
* better than O(n).
*/
char *
{
/* The default entry must always be the last one */
if (aspp == default_policy) {
} else {
else
aspp++;
}
}
if (precedence != NULL)
return (match->ip6_asp_label);
}
/*
* If we had deferred updating the table because of outstanding references,
* do it now. Note, we don't do error checking on the queued IOCTL mblk, since
* ip_sioctl_ip6addrpolicy() has already done it for us.
*/
void
{
ipst->ips_ip6_asp_refcnt > 0) {
return;
}
} else {
}
}
/*
* ip6_asp_replace replaces the contents of the IPv6 address selection
* policy table with those specified in new_table. If new_table is NULL,
* this indicates that the caller wishes ip to use the default policy
* table. The caller is responsible for making sure that there are exactly
* new_count policy entries in new_table.
*/
/*ARGSUSED5*/
void
{
int ret_val = 0;
queue_t *q;
#else
#endif
if (new_size % ip6_asp_size != 0) {
ip1dbg(("ip6_asp_replace: invalid table size\n"));
if (locked)
goto unlock_end;
goto replace_end;
} else {
}
if (!locked)
/*
* Check if we are in the process of creating any IRE using the
* current information. If so, wait till that is done.
*/
/* Save this request for later processing */
} else {
/* Let's not queue multiple requests for now */
ip1dbg(("ip6_asp_replace: discarding request\n"));
goto replace_end;
}
return;
}
/* Prevent lookups till the table have been updated */
if (!locked)
/*
* This is a special case. The user wants to revert
* back to using the default table.
*/
goto unlock_end;
sizeof (default_ip6_asp_table) / sizeof (ip6_asp_t);
goto unlock_end;
}
if (count == 0) {
ip1dbg(("ip6_asp_replace: empty table\n"));
goto unlock_end;
}
NULL) {
goto unlock_end;
}
/*
* If 'new_table' -actually- originates from a 32-bit process
* then the nicely aligned ip6_asp_label array will be
* subtlely misaligned on this kernel, because the structure
* is 8 byte aligned in the kernel, but only 4 byte aligned in
* userland. Fix it up here.
*
* XX64 See the notes in ip_sioctl_ip6addrpolicy. Perhaps we could
* do the datamodel transformation (below) there instead of here?
*/
int i;
KM_NOSLEEP)) == NULL) {
goto unlock_end;
}
/*
* Copy each element of the table from ip6_asp32_t
* format into ip6_asp_t format. Fortunately, since
* we're just dealing with a trailing structure pad,
* we can do this straightforwardly with a flurry of
* bcopying.
*/
for (i = 0; i < count; i++)
} else
#endif
/* Make sure the last entry is the default entry */
ip1dbg(("ip6_asp_replace: bad table: no default entry\n"));
goto unlock_end;
}
}
/*
* The user has changed the address selection policy table. IPv6
* source address selection for existing IRE_CACHE and
* RTF_DYNAMIC entries used the old table, so we need to
* clear the cache.
*/
/* Reply to the ioctl */
if (q == NULL) {
goto check_binds;
}
}
/*
* Copies the contents of src_table to dst_table, and sorts the
* entries in decending order of prefix lengths. It assumes that both
* tables are appropriately sized to contain count entries.
*/
static void
{
if (count == 1)
return;
/*
* Sort the entries in descending order of prefix lengths.
*
* Note: this should be a small table. In 99% of cases, we
* expect the table to have 5 entries. In the remaining 1%
* of cases, we expect the table to have one or two more
* entries. It would be very rare for the table to have
* double-digit entries.
*/
/*
* Make room to insert the source entry
* before dst_ptr by shifting entries to
* the right.
*/
break;
}
}
}
}
/*
* This function copies as many entries from ip6_asp_table as will fit
* into dtable. The dtable_size parameter is the size of dtable
* in bytes. This function returns the number of entries in
* ip6_asp_table, even if it's not able to fit all of the entries into
* dtable.
*/
int
{
if (dtable_size < sizeof (ip6_asp_t))
return (-1);
sizeof (ip6_asp_t));
}
return (ipst->ips_ip6_asp_table_count);
}
/*
* Compare two labels. Return B_TRUE if they are equal, B_FALSE
* otherwise.
*/
{
/*
* The common case, the two labels are actually the same string
* from the policy table.
*/
return (B_TRUE);
/*
* Since we know the labels are at most 16 bytes long, compare
* the two strings as two 8-byte long integers. The ip6_asp_t
* structure guarantees that the labels are 8 byte alligned.
*/
return (B_TRUE);
return (B_FALSE);
}