ip_srcid.c revision bd670b35a010421b6e1a5536c34453a827007c81
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This is used to support the hidden __sin6_src_id in the sockaddr_in6
* structure which is there to ensure that applications (such as UDP apps)
* which get an address from recvfrom and use that address in a sendto
* or connect will by default use the same source address in the "response"
* as the destination address in the "request" they received.
*
* This is built using some new functions (in IP - doing their own locking
* so they can be called from the transports) to map between integer IDs
* and in6_addr_t.
* The use applies to sockaddr_in6 - whether or not mapped addresses are used.
*
* This file contains the functions used by both IP and the transports
* to implement __sin6_src_id.
* The routines do their own locking since they are called from
* the transports (to map between a source id and an address)
* and from IP proper when IP addresses are added and removed.
*
* The routines handle both IPv4 and IPv6 with the IPv4 addresses represented
* as IPv4-mapped addresses.
*/
#include <sys/sysmacros.h>
#define _SUN_TPI_VERSION 2
#include <sys/xti_inet.h>
#include <sys/isa_defs.h>
#include <netinet/igmp_var.h>
#include <inet/ip_multi.h>
#include <netinet/ip_mroute.h>
#include <inet/ipclassifier.h>
/*
* Returns zero if ok; otherwise errno (e.g. for memory allocation failure).
*/
int
{
srcid_map_t **smpp;
#ifdef DEBUG
char abuf[INET6_ADDRSTRLEN];
ip1dbg(("ip_srcid_insert(%s, %d)\n",
#endif
/* Already present - increment refcount */
return (0);
}
/* Insert new */
return (ENOMEM);
}
return (0);
}
/*
* Remove an new address from the map.
* Returns zero if ok; otherwise errno (e.g. for nonexistent address).
*/
int
{
srcid_map_t **smpp;
#ifdef DEBUG
char abuf[INET6_ADDRSTRLEN];
ip1dbg(("ip_srcid_remove(%s, %d)\n",
#endif
/* Not preset */
return (ENOENT);
}
/* Decrement refcount */
return (0);
}
/* Remove entry */
return (0);
}
/*
* Map from an address to a source id.
* If the address is unknown return the unknown id (zero).
*/
netstack_t *ns)
{
srcid_map_t **smpp;
char abuf[INET6_ADDRSTRLEN];
/* Not present - could be broadcast or multicast address */
ip1dbg(("ip_srcid_find_addr: unknown %s in zone %d\n",
id = 0;
} else {
}
return (id);
}
/*
* Map from a source id to an address.
* If the id is unknown return the unspecified address.
*/
void
netstack_t *ns)
{
srcid_map_t **smpp;
/* Not preset */
*addr = ipv6_all_zeros;
} else {
}
}
/* Assign the next available ID */
static uint_t
{
srcid_map_t **smpp;
if (!ipst->ips_srcid_wrapped) {
if (ipst->ips_ip_src_id == 0)
return (id);
}
/* Once it wraps we search for an unused ID. */
return (id);
}
panic("srcid_nextid: No free identifiers!");
/* NOTREACHED */
}
/*
* Lookup based on address.
* Always returns a non-null pointer.
* If found then *ptr will be the found object.
* Otherwise *ptr will be NULL and can be used to insert a new object.
*/
static srcid_map_t **
{
srcid_map_t **smpp;
return (smpp);
}
return (smpp);
}
/*
* Lookup based on address.
* Always returns a non-null pointer.
* If found then *ptr will be the found object.
* Otherwise *ptr will be NULL and can be used to insert a new object.
*/
static srcid_map_t **
{
srcid_map_t **smpp;
return (smpp);
}
return (smpp);
}