udp.c revision 9b3fddaeb50c3ff41054f8b237b4cd8a0b850885
/*
* 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.
*/
/* Copyright (c) 1990 Mentat Inc. */
#pragma ident "%Z%%M% %I% %E% SMI"
const char udp_version[] = "%Z%%M% %I% %E% SMI";
#define _SUN_TPI_VERSION 2
#include <sys/xti_inet.h>
#include <sys/isa_defs.h>
#include <inet/ip_multi.h>
#include <inet/kstatcom.h>
#include <inet/udp_impl.h>
#include <inet/ipclassifier.h>
#include <inet/ipsec_impl.h>
#include <inet/ipp_common.h>
/*
* The ipsec_info.h header file is here since it has the definition for the
* M_CTL message types used by IP to convey information to the ULP. The
* ipsec_info.h needs the pfkeyv2.h, hence the latter's presence.
*/
#include <inet/ipsec_info.h>
#include <rpc/pmap_prot.h>
/*
* Synchronization notes:
*
* UDP uses a combination of its internal perimeter, a global lock and
* a set of bind hash locks to protect its data structures. Please see
* the note above udp_mode_assertions for details about the internal
* perimeter.
*
* When a UDP endpoint is bound to a local port, it is inserted into
* a bind hash list. The list consists of an array of udp_fanout_t buckets.
* The size of the array is controlled by the udp_bind_fanout_size variable.
* not large enough. Each bind hash bucket is protected by a per bucket
* lock. It protects the udp_bind_hash and udp_ptpbhn fields in the udp_t
* structure. An UDP endpoint is removed from the bind hash list only
* when it is being unbound or being closed. The per bucket lock also
* protects a UDP endpoint's state changes.
*
* Plumbing notes:
*
* Both udp and ip are merged, but the streams plumbing is kept unchanged
* backwards compatibility for certain applications which rely on such
* plumbing geometry to do things such as issuing I_POP on the stream
*
* instance does not possess any state about the endpoint, and merely
* acts as a dummy module whose presence is to keep the streams plumbing
* happens to embed a udp_t. This stays dormant until the time udp is
* an IP to a UDP endpoint.
*
* We only allow for the following plumbing cases:
*
* Normal:
* This is the default action that happens when a udp socket or
* now shared and is marked with IPCL_UDP.
*
* SNMP-only:
* happens it will support only SNMP semantics. A new conn_t is
* allocated and marked with IPCL_UDPMOD.
*
* The above cases imply that we don't support any intermediate module to
* scenario in the past as the inter-layer communication semantics have
* always been private. Also note that the normal case allows for SNMP
* requests to be processed in addition to the rest of UDP operations.
*
* The normal case plumbing is depicted by the following diagram:
*
* +---------------+---------------+
* | | | udp
* | udp_wq | udp_rq |
* | | UDP_RD |
* | | |
* +---------------+---------------+
* | ^
* v |
* +---------------+---------------+
* | ip_wq | ip_rq | conn_t
* | UDP_WR | |
* | | |
* +---------------+---------------+
*
* Messages arriving at udp_wq from above will end up in ip_wq before
* it gets processed, i.e. udp write entry points will advance udp_wq
* and use its q_next value as ip_wq in order to use the conn_t that
* is stored in its q_ptr. Likewise, messages generated by ip to the
* module above udp will appear as if they are originated from udp_rq,
* i.e. putnext() calls to the module above udp is done using the
* udp_rq instead of ip_rq in order to avoid udp_rput() which does
* nothing more than calling putnext().
*
* The above implies the following rule of thumb:
*
* instance and is stored in q_ptr of both ip_wq and ip_rq. There
* is no direct reference to conn_t from either udp_wq or udp_rq.
*
* 2. Write-side entry points of udp can obtain the conn_t via the
* Q_TO_CONN() macro, using the queue value obtain from UDP_WR().
*
* be done by supplying the queue value obtained from UDP_RD().
*
*/
struct kmem_cache *udp_cache;
#define NDD_TOO_QUICK_MSG \
"ndd get info rate too high for non-privileged users, try again " \
"later.\n"
#define NDD_OUT_OF_BUF_MSG "<< Out of buffer >>\n"
/* Option processing attrs */
typedef struct udpattrs_s {
union {
} udpattr_ippu;
} udpattrs_t;
int sys_error);
int *error);
#ifdef DEBUG
static void udp_mode_assertions(udp_t *, int);
#endif /* DEBUG */
#define UDP6 "udp6"
#define UDP_RECV_LOWATER 128
#define UDP_XMIT_LOWATER 1024
static struct module_info udp_info = {
};
};
};
/* Support for just SNMP if UDP is not pushed directly over device IP */
struct qinit udp_snmp_rinit = {
};
struct qinit udp_snmp_winit = {
};
};
/* Default structure copied into T_INFO_ACK messages */
static struct T_info_ack udp_g_t_info_ack_ipv4 = {
UDP_MAXPACKET_IPV4, /* TSDU_size. Excl. headers */
T_INVALID, /* ETSU_size. udp does not support expedited data. */
T_INVALID, /* CDATA_size. udp does not support connect data. */
T_INVALID, /* DDATA_size. udp does not support disconnect data. */
sizeof (sin_t), /* ADDR_size. */
0, /* OPT_size - not initialized here */
UDP_MAXPACKET_IPV4, /* TIDU_size. Excl. headers */
T_CLTS, /* SERV_type. udp supports connection-less. */
TS_UNBND, /* CURRENT_state. This is set from udp_state. */
};
static struct T_info_ack udp_g_t_info_ack_ipv6 = {
UDP_MAXPACKET_IPV6, /* TSDU_size. Excl. headers */
T_INVALID, /* ETSU_size. udp does not support expedited data. */
T_INVALID, /* CDATA_size. udp does not support connect data. */
T_INVALID, /* DDATA_size. udp does not support disconnect data. */
sizeof (sin6_t), /* ADDR_size. */
0, /* OPT_size - not initialized here */
UDP_MAXPACKET_IPV6, /* TIDU_size. Excl. headers */
T_CLTS, /* SERV_type. udp supports connection-less. */
TS_UNBND, /* CURRENT_state. This is set from udp_state. */
};
/* largest UDP port number */
#define UDP_MAX_PORT 65535
/*
* Table of ND variables supported by udp. These are loaded into us_nd
* in udp_open.
*/
/* BEGIN CSTYLED */
udpparam_t udp_param_arr[] = {
/*min max value name */
{ 0L, 256, 32, "udp_wroff_extra" },
{ 1L, 255, 255, "udp_ipv4_ttl" },
{ 1024, (32 * 1024), 1024, "udp_smallest_nonpriv_port" },
{ 0, 1, 1, "udp_do_checksum" },
{ 65536, (1<<30), 2*1024*1024, "udp_max_buf"},
{ 100, 60000, 1000, "udp_ndd_get_info_interval"},
};
/* END CSTYLED */
/* If set to 0, pick ephemeral port sequentially; otherwise randomly. */
/*
* Hook functions to enable cluster networking.
* On non-clustered systems these vectors must always be NULL
*/
typedef union T_primitives *t_primp_t;
else \
(udp)->udp_mpcount++; \
}
#define UDP_READERS_INCREF(udp) { \
(udp)->udp_reader_count++; \
}
#define UDP_READERS_DECREF(udp) { \
(udp)->udp_reader_count--; \
if ((udp)->udp_reader_count == 0) \
}
#define UDP_SQUEUE_DECREF(udp) { \
(udp)->udp_squeue_count--; \
if ((udp)->udp_squeue_count == 0) \
}
/*
* Notes on UDP endpoint synchronization:
*
* UDP needs exclusive operation on a per endpoint basis, when executing
* functions that modify the endpoint state. udp_rput_other() deals with
* packets with IP options, and processing these packets end up having
* to update the endpoint's option related state. udp_wput_other() deals
* with control operations from the top, e.g. connect() that needs to
* update the endpoint state. These could be synchronized using locks,
* but the current version uses squeues for this purpose. squeues may
* give performance improvement for certain cases such as connected UDP
* sockets; thus the framework allows for using squeues.
*
* The perimeter routines are described as follows:
*
* udp_enter():
* Enter the UDP endpoint perimeter.
*
* udp_become_writer():
* Become exclusive on the UDP endpoint. Specifies a function
* that will be called exclusively either immediately or later
* when the perimeter is available exclusively.
*
* udp_exit():
* Exit the UDP perimeter.
*
* Entering UDP from the top or from the bottom must be done using
* udp_enter(). No lock must be held while attempting to enter the UDP
* perimeter. When finished, udp_exit() must be called to get out of
* the perimeter.
*
* UDP operates in either MT_HOT mode or in SQUEUE mode. In MT_HOT mode,
* multiple threads may enter a UDP endpoint concurrently. This is used
* special cases call udp_become_writer() to become exclusive on a per
* endpoint basis and this results in transitioning to SQUEUE mode. squeue
* by definition serializes access to the conn_t. When there are no more
* pending messages on the squeue for the UDP connection, the endpoint
* reverts to MT_HOT mode. During the interregnum when not all MT threads
* of an endpoint have finished, messages are queued in the UDP endpoint
* and the UDP is in UDP_MT_QUEUED mode or UDP_QUEUED_SQUEUE mode.
*
* These modes have the following analogs:
*
* UDP_MT_HOT/udp_reader_count==0 none
* UDP_MT_HOT/udp_reader_count>0 RW_READ_LOCK
* UDP_MT_QUEUED RW_WRITE_WANTED
* UDP_SQUEUE or UDP_QUEUED_SQUEUE RW_WRITE_LOCKED
*
* Stable modes: UDP_MT_HOT, UDP_SQUEUE
* Transient modes: UDP_MT_QUEUED, UDP_QUEUED_SQUEUE
*
* While in stable modes, UDP keeps track of the number of threads
* operating on the endpoint. The udp_reader_count variable represents
* the number of threads entering the endpoint as readers while it is
* in UDP_MT_HOT mode. Transitioning to UDP_SQUEUE happens when there
* is only a single reader, i.e. when this counter drops to 1. Likewise,
* udp_squeue_count represents the number of threads operating on the
* endpoint's squeue while it is in UDP_SQUEUE mode. The mode transition
* to UDP_MT_HOT happens after the last thread exits the endpoint, i.e.
* when this counter drops to 0.
*
* The default mode is set to UDP_MT_HOT and UDP alternates between
* UDP_MT_HOT and UDP_SQUEUE as shown in the state transition below.
*
* Mode transition:
* ----------------------------------------------------------------
* old mode Event New mode
* ----------------------------------------------------------------
* UDP_MT_HOT Call to udp_become_writer() UDP_SQUEUE
* and udp_reader_count == 1
*
* UDP_MT_HOT Call to udp_become_writer() UDP_MT_QUEUED
* and udp_reader_count > 1
*
* UDP_MT_QUEUED udp_reader_count drops to zero UDP_QUEUED_SQUEUE
*
* UDP_QUEUED_SQUEUE All messages enqueued on the UDP_SQUEUE
* internal UDP queue successfully
* moved to squeue AND udp_squeue_count != 0
*
* UDP_QUEUED_SQUEUE All messages enqueued on the UDP_MT_HOT
* internal UDP queue successfully
* moved to squeue AND udp_squeue_count
* drops to zero
*
* UDP_SQUEUE udp_squeue_count drops to zero UDP_MT_HOT
* ----------------------------------------------------------------
*/
static queue_t *
{
}
static queue_t *
{
}
#ifdef DEBUG
#else
#endif
/* Invariants */
#ifdef DEBUG
/* Context of udp_mode_assertions */
#define UDP_ENTER 1
#define UDP_BECOME_WRITER 2
#define UDP_EXIT 3
static void
{
case UDP_MT_HOT:
/*
* Messages have not yet been enqueued on the internal queue,
* otherwise we would have switched to UDP_MT_QUEUED. Likewise
* by definition, there can't be any messages enqueued on the
* squeue. The UDP could be quiescent, so udp_reader_count
* could be zero at entry.
*/
udp->udp_squeue_count == 0);
udp_count[0]++;
break;
case UDP_MT_QUEUED:
/*
* The last MT thread to exit the udp perimeter empties the
* internal queue and then switches the UDP to
* UDP_QUEUED_SQUEUE mode. Since we are still in UDP_MT_QUEUED
* mode, it means there must be at least 1 MT thread still in
* the perimeter and at least 1 message on the internal queue.
*/
udp_count[1]++;
break;
case UDP_QUEUED_SQUEUE:
/*
* The switch has happened from MT to SQUEUE. So there can't
* any MT threads. Messages could still pile up on the internal
* queue until the transition is complete and we move to
* UDP_SQUEUE mode. We can't assert on nonzero udp_squeue_count
* since the squeue could drain any time.
*/
udp_count[2]++;
break;
case UDP_SQUEUE:
/*
* The transition is complete. Thre can't be any messages on
* the internal queue. The udp could be quiescent or the squeue
* could drain any time, so we can't assert on nonzero
* udp_squeue_count during entry. Nor can we assert that
* udp_reader_count is zero, since, a reader thread could have
* directly become writer in line by calling udp_become_writer
* without going through the queued states.
*/
udp_count[3]++;
break;
}
}
#endif
\
} else { \
\
case UDP_MT_HOT: \
/* We can execute as reader right away. */ \
break; \
\
case UDP_SQUEUE: \
/* \
* We are in squeue mode, send the \
* packet to the squeue \
*/ \
_udp->udp_squeue_count++; \
break; \
\
case UDP_MT_QUEUED: \
case UDP_QUEUED_SQUEUE: \
/* \
* Some messages may have been enqueued \
* ahead of us. Enqueue the new message \
* at the tail of the internal queue to \
* preserve message ordering. \
*/ \
break; \
} \
} \
}
static void
{
}
static void
{
case UDP_MT_HOT:
/*
* We are the only MT thread. Switch to squeue mode
* immediately.
*/
return;
}
/* FALLTHRU */
case UDP_MT_QUEUED:
/* Enqueue the packet internally in UDP */
return;
case UDP_SQUEUE:
case UDP_QUEUED_SQUEUE:
/*
* We are already exclusive. i.e. we are already
* writer. Simply call the desired function.
*/
udp->udp_squeue_count++;
return;
}
}
/*
* Transition from MT mode to SQUEUE mode, when the last MT thread
* is exiting the UDP perimeter. Move all messages from the internal
* udp queue to the squeue. A better way would be to move all the
* messages in one shot, this needs more support from the squeue framework
*/
static void
{
udp->udp_mpcount = 0;
/*
* It is best not to hold any locks across the calls
* to squeue functions. Since we drop the lock we
* need to go back and check the udp_mphead once again
* after the squeue_fill and hence the while loop at
* the top of this function
*/
udp->udp_squeue_count++;
tag);
}
}
/*
* udp_squeue_count of zero implies that the squeue has drained
* even before we arrived here (i.e. after the squeue_fill above)
*/
}
\
\
case UDP_MT_HOT: \
break; \
\
case UDP_SQUEUE: \
if (_udp->udp_squeue_count == 0) \
break; \
\
case UDP_MT_QUEUED: \
/* \
* If this is the last MT thread, we need to \
* switch to squeue mode \
*/ \
if (_udp->udp_reader_count == 0) \
break; \
\
case UDP_QUEUED_SQUEUE: \
/* \
* Even if the udp_squeue_count drops to zero, we \
* don't want to change udp_mode to UDP_MT_HOT here. \
* The thread in udp_switch_to_squeue will take care \
* of the transition to UDP_MT_HOT, after emptying \
* any more new messages that have been enqueued in \
* udp_mphead. \
*/ \
break; \
} \
}
static void
{
}
/*
* Return the next anonymous port in the privileged port range for
* bind checking.
*
* Trusted Extension (TX) notes: TX allows administrator to mark or
* reserve ports as Multilevel ports (MLP). MLP has special function
* on TX systems. Once a port is made MLP, it's not available as
* ordinary port. This creates "holes" in the port name space. It
* may be necessary to skip the "holes" find a suitable anon port.
*/
static in_port_t
{
if (restart)
return (0);
}
if (is_system_labeled() &&
goto retry;
}
return (next_priv_port--);
}
/* UDP bind hash report triggered via the Named Dispatch mechanism. */
/* ARGSUSED */
static int
{
int i;
/* Refer to comments in udp_status_report(). */
return (0);
}
}
/* The following may work even if we cannot get a large buf. */
return (0);
}
(void) mi_mpprintf(mp,
"UDP " MI_COL_HDRPAD_STR
/* 12345678[89ABCDEF] */
" zone lport src addr dest addr port state");
/* 1234 12345 xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx 12345 UNBOUND */
for (i = 0; i < us->us_bind_fanout_size; i++) {
/* Print the hash index. */
if (zoneid != GLOBAL_ZONEID) {
/* skip to first entry in this zone; might be none */
}
buf_len, "%d\n", i);
} else {
}
if (zoneid == GLOBAL_ZONEID ||
}
}
}
return (0);
}
/*
* Hash list removal routine for udp_t structures.
*/
static void
{
return;
/*
* Extract the lock pointer in case there are concurrent
* hash_remove's for this instance.
*/
if (!caller_holds_lock) {
}
}
}
if (!caller_holds_lock) {
}
}
static void
{
}
/*
* If the new udp bound to the INADDR_ANY address
* and the first one in the list is not bound to
* INADDR_ANY we skip all entries until we find the
* first one bound to INADDR_ANY.
* This makes sure that applications binding to a
* specific address get preference over those binding to
* INADDR_ANY.
*/
udpnext->udp_bound_v6src)) {
}
} else {
}
}
}
/*
* This routine is called to handle each O_T_BIND_REQ/T_BIND_REQ message
* passed to udp_wput.
* It associates a port number and local address with the stream.
* The O_T_BIND_REQ/T_BIND_REQ is passed downstream to ip with the UDP
* protocol type (IPPROTO_UDP) placed in the message following the address.
* A T_BIND_ACK message is passed upstream when ip acknowledges the request.
* (Called as writer.)
*
* Note that UDP over IPv4 and IPv6 sockets can use the same port number
* without setting SO_REUSEADDR. This is needed so that they
* can be viewed as two independent transport protocols.
* However, anonymouns ports are allocated from the same range to avoid
* duplicating the us->us_next_port_to_try.
*/
static void
{
struct T_bind_req *tbr;
int count;
int loopmax;
"udp_bind: bad req, len %u",
return;
}
return;
}
/*
* Reallocate the message to make sure we have enough room for an
* address and the protocol type.
*/
if (!mp1) {
return;
}
switch (tbr->ADDR_length) {
case 0: /* Request for a generic port */
} else {
}
port = 0;
break;
case sizeof (sin_t): /* Complete IPv4 address */
sizeof (sin_t));
return;
}
return;
}
break;
case sizeof (sin6_t): /* complete IPv6 address */
sizeof (sin6_t));
return;
}
return;
}
break;
default: /* Invalid request */
return;
}
else /* T_BIND_REQ and requested_port != 0 */
if (requested_port == 0) {
/*
* If the application passed in zero for the port number, it
* doesn't care which port number we bind to. Get one in the
* valid range.
*/
if (udp->udp_anon_priv_bind) {
} else {
}
} else {
/*
* If the port is in the well-known privileged range,
* make sure the caller was privileged.
*/
int i;
} else {
for (i = 0; i < us->us_num_epriv_ports; i++) {
break;
}
}
}
if (priv) {
return;
}
}
}
if (port == 0) {
return;
}
/*
* Copy the source address into our udp structure. This address
* may still be zero; if so, IP will fill in the correct address
* each time an outbound packet is passed to it.
*/
} else {
if (IN6_IS_ADDR_V4MAPPED(&v6src)) {
} else {
}
}
/*
* If udp_reuseaddr is not set, then we have to make sure that
* the IP address and port number the application requested
* (or we selected for the application) is not being used by
* another stream. If another stream is already using the
* requested IP address and port, the behavior depends on
* "bind_to_req_port_only". If set the bind fails; otherwise we
* search for any an unused port to bind to the the stream.
*
* As per the BSD semantics, as modified by the Deering multicast
* changes, if udp_reuseaddr is set, then we allow multiple binds
* to the same port independent of the local IP address.
*
* This is slightly different than in SunOS 4.X which did not
* support IP multicast. Note that the change implemented by the
* Deering multicast code effects all binds - not only binding
* to IP multicast addresses.
*
* Note that when binding to port zero we ignore SO_REUSEADDR in
* order to guarantee a unique port.
*/
count = 0;
if (udp->udp_anon_priv_bind) {
/*
* loopmax = (IPPORT_RESERVED-1) -
* us->us_min_anonpriv_port + 1
*/
} else {
}
for (;;) {
/*
* Walk through the list of udp streams bound to
* requested port with the same IP address.
*/
continue;
/*
* On a labeled system, we must treat bindings to ports
* on shared IP addresses by sockets with MAC exemption
* privilege as being in all zones, as there's
* otherwise no way to identify the right receiver.
*/
continue;
/*
* If UDP_EXCLBIND is set for either the bound or
* binding endpoint, the semantics of bind
* is changed according to the following chart.
*
* spec = specified address (v4 or v6)
* unspec = unspecified address (v4 or v6)
* A = specified addresses are different for endpoints
*
* bound bind to allowed?
* -------------------------------------
* unspec unspec no
* unspec spec no
* spec unspec no
* spec spec yes if A
*
* For labeled systems, SO_MAC_EXEMPT behaves the same
* as UDP_EXCLBIND, except that zoneid is ignored.
*/
if (V6_OR_V4_INADDR_ANY(
udp1->udp_bound_v6src) ||
&v6src)) {
break;
}
continue;
}
/*
* Check ipversion to allow IPv4 and IPv6 sockets to
* have disjoint port number spaces.
*/
/*
* On the first time through the loop, if the
* the user intentionally specified a
* particular port number, then ignore any
* bindings of the other protocol that may
* conflict. This allows the user to bind IPv6
* alone and get both v4 and v6, or bind both
* both and get each seperately. On subsequent
* times through the loop, we're checking a
* port that we chose (not the user) and thus
* we do not allow casual duplicate bindings.
*/
if (count == 0 && requested_port != 0)
continue;
}
/*
* No difference depending on SO_REUSEADDR.
*
* If existing port is bound to a
* non-wildcard IP address and
* the requesting stream is bound to
* a distinct different IP addresses
* (non-wildcard, also), keep going.
*/
if (!is_inaddr_any &&
&v6src)) {
continue;
}
break;
}
if (!found_exclbind &&
break;
}
/*
* No other stream has this IP address
* and port number. We can use it.
*/
break;
}
if (bind_to_req_port_only) {
/*
* We get here only when requested port
* is bound (and only first of the for()
* loop iteration).
*
* The semantics of this bind request
* require it to fail so we return from
* the routine (and exit the loop).
*
*/
return;
}
if (udp->udp_anon_priv_bind) {
} else {
if ((count == 0) && (requested_port != 0)) {
/*
* If the application wants us to find
* a port, get one to start with. Set
* requested_port to 0, so that we will
* update us->us_next_port_to_try below.
*/
requested_port = 0;
} else {
B_FALSE);
}
}
/*
* We've tried every possible port number and
* there are none available, so send an error
* to the user.
*/
return;
}
}
/*
* Copy the source address into our udp structure. This address
* may still be zero; if so, ip will fill in the correct address
* each time an outbound packet is passed to it.
* If we are binding to a broadcast or multicast address udp_rput
* will clear the source address when it receives the T_BIND_ACK.
*/
/*
* Now reset the the next anonymous port if the application requested
* an anonymous port, or we handed out the next anonymous port.
*/
}
/* Initialize the O_T_BIND_REQ/T_BIND_REQ for ip. */
} else {
int error;
/* Rebuild the header template */
if (error != 0) {
return;
}
}
if (cl_inet_bind) {
/*
* Running in cluster mode - register bind information
*/
} else {
}
}
connp->conn_anon_mlp)) {
if (addrtype == mlptSingle) {
return;
}
addrtype);
if (mlptype != mlptSingle &&
secpolicy_net_bindmlp(cr) != 0)) {
"udp_bind: no priv for multilevel port %d",
mlpport);
}
return;
}
/*
* If we're specifically binding a shared IP address and the
* port is MLP on shared addresses, then check to see if this
* zone actually owns the MLP. Reject if not.
*/
/*
* No need to handle exclusive-stack zones since
* ALL_ZONES only applies to the shared stack.
*/
"udp_bind: attempt to bind port "
"%d on shared addr in zone %d "
"(should be %d)",
mlpzone);
}
return;
}
}
if (connp->conn_anon_port) {
int error;
if (error != 0) {
"udp_bind: cannot establish anon "
"MLP for port %d", port);
}
return;
}
}
}
/* Pass the protocol number in the message following the address. */
/*
* Append a request for an IRE if udp_v6src not
* zero (IPv4 - INADDR_ANY, or IPv6 - all-zeroes address).
*/
return;
}
}
else
else
}
void
{
}
/*
* This is called from ip_wput_nondata to resume a deferred UDP bind.
*/
/* ARGSUSED */
static void
{
}
/*
* This routine handles each T_CONN_REQ message passed to udp. It
* associates a default destination address with the stream.
*
* This routine sends down a T_BIND_REQ to IP with the following mblks:
* IRE_DB_REQ_TYPE - to get an IRE back containing ire_type and src
* T_OK_ACK - for the T_CONN_REQ
* T_CONN_CON - to keep the TPI user happy
*
* The connect completes in udp_rput.
* When a T_BIND_ACK is received information is extracted from the IRE
* and the two appended messages are sent to the TPI user.
* Should udp_rput receive T_ERROR_ACK for the T_BIND_REQ it will convert
* it to an error ack for the appropriate primitive.
*/
static void
{
struct T_conn_req *tcr;
/* A bit of sanity checking */
return;
}
/*
* This UDP must have bound to a port already before doing
* a connect.
*/
return;
}
/* Already connected - clear out state */
}
if (tcr->OPT_length != 0) {
return;
}
/*
* Determine packet type based on type of address passed in
* the request should contain an IPv4 or IPv6 address.
* Make sure that address family matches the type of
* family of the the address passed down
*/
switch (tcr->DEST_length) {
default:
return;
case sizeof (sin_t):
sizeof (sin_t));
return;
}
return;
}
break;
case sizeof (sin6_t):
sizeof (sin6_t));
return;
}
return;
}
if (IN6_IS_ADDR_V4MAPPED(&v6dst)) {
flowinfo = 0;
} else {
}
break;
}
if (dstport == 0) {
return;
}
/*
* Create a default IP header with no IP options.
*/
/*
* Interpret a zero destination to mean loopback.
* generate the T_CONN_CON.
*/
if (v4dst == INADDR_ANY) {
} else {
}
}
udp->udp_flowinfo = 0;
/*
* If the destination address is multicast and
* an outgoing multicast interface has been set,
* use the address of that interface as our
* source address if no source address has been set.
*/
}
} else {
/*
* Interpret a zero destination to mean loopback.
* generate the T_CONN_CON.
*/
if (IN6_IS_ADDR_UNSPECIFIED(&v6dst)) {
}
/*
* If the destination address is multicast and
* an outgoing multicast interface has been set,
* then the ip bind logic will pick the correct source
* address (i.e. matching the outgoing multicast interface).
*/
}
/*
* connections in TS_DATA_XFER
*/
continue;
continue;
return;
}
/*
* Send down bind to IP to verify that there is a route
* and to determine the source address.
* This will come back as T_BIND_ACK with an IRE_DB_TYPE in rput.
*/
else
return;
}
/*
* We also have to send a connection confirmation to
* keep TLI happy. Prepare it for udp_rput.
*/
else
goto bind_failed;
}
/* Unable to reuse the T_CONN_REQ for the ack. */
goto bind_failed;
}
/* Hang onto the T_OK_ACK and T_CONN_CON for later. */
else
else
}
static int
{
/*
* Disable read-side synchronous stream
* interface and drain any queued data.
*/
qprocsoff(q);
/* restore IP module's high and low water marks to default values */
/*
* Restore connp as an IP endpoint.
* Locking required to prevent a race with udp_snmp_get()/
* ipcl_get_next_conn(), which selects conn_t which are
* IPCL_UDP and not CONN_CONDEMNED.
*/
return (0);
}
/*
* Called in the close path from IP (ip_quiesce_conn) to quiesce the conn
*/
void
{
/*
* Running in cluster mode - register unbind information
*/
} else {
}
}
}
}
void
{
/* If there are any options associated with the stream, free them. */
if (udp->udp_ip_snd_options) {
}
if (udp->udp_ip_rcv_options) {
}
/* Free memory associated with sticky options */
if (udp->udp_sticky_hdrs_len != 0) {
udp->udp_sticky_hdrs_len = 0;
}
}
/*
* This routine handles each T_DISCON_REQ message passed to udp
* as an indicating that UDP is no longer connected. This results
* in sending a T_BIND_REQ to IP to restore the binding to just
*
* This routine sends down a T_BIND_REQ to IP with the following mblks:
* T_OK_ACK - for the T_DISCON_REQ
*
* The disconnect completes in udp_rput.
* When a T_BIND_ACK is received the appended T_OK_ACK is sent to the TPI user.
* Should udp_rput receive T_ERROR_ACK for the T_BIND_REQ it will convert
* it to an error ack for the appropriate primitive.
*/
static void
{
return;
}
/*
* Send down bind to IP to remove the full binding and revert
* to the local address binding.
*/
else
return;
}
/* Unable to reuse the T_DISCON_REQ for the ack. */
return;
}
int error;
/* Rebuild the header template */
if (error != 0) {
return;
}
}
/* Append the T_OK_ACK to the T_BIND_REQ for udp_rput */
else
else
}
/* This routine creates a T_ERROR_ACK message and passes it upstream. */
static void
{
}
/* Shorthand to generate and send TPI error acks to our client */
static void
int sys_error)
{
struct T_error_ack *teackp;
}
}
/*ARGSUSED*/
static int
{
int i;
for (i = 0; i < us->us_num_epriv_ports; i++) {
if (us->us_epriv_ports[i] != 0)
}
return (0);
}
/* ARGSUSED */
static int
{
long new_value;
int i;
/*
* Fail the request if the new value does not lie within the
* port number limits.
*/
return (EINVAL);
}
/* Check if the value is already in the list */
for (i = 0; i < us->us_num_epriv_ports; i++) {
return (EEXIST);
}
}
/* Find an empty slot */
for (i = 0; i < us->us_num_epriv_ports; i++) {
if (us->us_epriv_ports[i] == 0)
break;
}
if (i == us->us_num_epriv_ports) {
return (EOVERFLOW);
}
/* Set the new value */
return (0);
}
/* ARGSUSED */
static int
{
long new_value;
int i;
/*
* Fail the request if the new value does not lie within the
* port number limits.
*/
return (EINVAL);
}
/* Check that the value is already in the list */
for (i = 0; i < us->us_num_epriv_ports; i++) {
break;
}
if (i == us->us_num_epriv_ports) {
return (ESRCH);
}
/* Clear the value */
us->us_epriv_ports[i] = 0;
return (0);
}
/* At minimum we need 4 bytes of UDP header */
#define ICMP_MIN_UDP_HDR 4
/*
* udp_icmp_error is called by udp_rput to process ICMP msgs. passed up by IP.
* Generates the appropriate T_UDERROR_IND for permanent (non-transient) errors.
* Assumes that IP has pulled up everything up to and including the ICMP header.
* An M_CTL could potentially come here from some other module (i.e. if UDP
* is pushed on some module other than IP). Thus, if we find that the M_CTL
* does not have enough ICMP information , following STREAMS conventions,
* we send it upstream assuming it is an M_CTL we don't understand.
*/
static void
{
int iph_hdr_length;
int error = 0;
/*
* Assume IP provides aligned packets - otherwise toss
*/
return;
}
/*
* Verify that we have a complete IP header and the application has
* asked for errors. If not, send it upstream.
*/
return;
}
/*
* Verify IP version. Anything other than IPv4 or IPv6 packet is sent
* upstream. ICMPv6 is handled in udp_icmp_error_ipv6.
*/
switch (IPH_HDR_VERSION(ipha)) {
case IPV6_VERSION:
udp_icmp_error_ipv6(q, mp);
return;
case IPV4_VERSION:
break;
default:
goto noticmpv4;
}
/* Skip past the outer IP and ICMP headers */
/*
* If we don't have the correct outer IP header length or if the ULP
* is not IPPROTO_ICMP or if we don't have a complete inner IP header
* send the packet upstream.
*/
if (iph_hdr_length < sizeof (ipha_t) ||
goto noticmpv4;
}
/* Skip past the inner IP and find the ULP header */
/*
* If we don't have the correct inner IP header length or if the ULP
* is not IPPROTO_UDP or if we don't have at least ICMP_MIN_UDP_HDR
* bytes of UDP header, send it upstream.
*/
if (iph_hdr_length < sizeof (ipha_t) ||
goto noticmpv4;
}
switch (icmph->icmph_type) {
case ICMP_DEST_UNREACHABLE:
switch (icmph->icmph_code) {
/*
* IP has already adjusted the path MTU.
* XXX Somehow pass MTU indication to application?
*/
break;
case ICMP_PORT_UNREACHABLE:
break;
default:
/* Transient errors */
break;
}
break;
default:
/* Transient errors */
break;
}
if (error == 0) {
return;
}
switch (udp->udp_family) {
case AF_INET:
error);
break;
case AF_INET6:
break;
}
if (mp1)
}
/*
* udp_icmp_error_ipv6 is called by udp_icmp_error to process ICMP for IPv6.
* Generates the appropriate T_UDERROR_IND for permanent (non-transient) errors.
* Assumes that IP has pulled up all the extension headers as well as the
* ICMPv6 header.
* An M_CTL could potentially come here from some other module (i.e. if UDP
* is pushed on some module other than IP). Thus, if we find that the M_CTL
* does not have enough ICMP information , following STREAMS conventions,
* we send it upstream assuming it is an M_CTL we don't understand. The reason
* it might get here is if the non-ICMP M_CTL accidently has 6 in the version
* field (when cast to ipha_t in udp_icmp_error).
*/
static void
{
int error = 0;
/*
* Verify that we have a complete IP header. If not, send it upstream.
*/
return;
}
/*
* Verify this is an ICMPV6 packet, else send it upstream
*/
&nexthdrp) ||
*nexthdrp != IPPROTO_ICMPV6) {
goto noticmpv6;
}
/*
* Verify we have a complete ICMP and inner IP header.
*/
goto noticmpv6;
goto noticmpv6;
/*
* Validate inner header. If the ULP is not IPPROTO_UDP or if we don't
* have at least ICMP_MIN_UDP_HDR bytes of UDP header send the
* packet upstream.
*/
if ((*nexthdrp != IPPROTO_UDP) ||
goto noticmpv6;
}
switch (icmp6->icmp6_type) {
case ICMP6_DST_UNREACH:
switch (icmp6->icmp6_code) {
case ICMP6_DST_UNREACH_NOPORT:
break;
case ICMP6_DST_UNREACH_ADMIN:
case ICMP6_DST_UNREACH_ADDR:
/* Transient errors */
break;
default:
break;
}
break;
case ICMP6_PACKET_TOO_BIG: {
struct T_unitdata_ind *tudi;
sizeof (struct ip6_mtuinfo);
struct ip6_mtuinfo *mtuinfo;
/*
* If the application has requested to receive path mtu
* information, send up an empty message containing an
* IPV6_PATHMTU ancillary data item.
*/
if (!udp->udp_ipv6_recvpathmtu)
break;
break;
}
/*
* newmp->b_cont is left to NULL on purpose. This is an
* empty message containing only ancillary data.
*/
/*
* We've consumed everything we need from the original
* message. Free it, then send our empty message.
*/
return;
}
case ICMP6_TIME_EXCEEDED:
/* Transient errors */
break;
case ICMP6_PARAM_PROB:
/* If this corresponds to an ICMP_PROTOCOL_UNREACHABLE */
break;
}
break;
}
if (error == 0) {
return;
}
error);
if (mp1)
}
/*
* This routine responds to T_ADDR_REQ messages. It is called by udp_wput.
* The local address is filled in if endpoint is bound. The remote address
* is filled in if remote address has been precified ("connected endpoint")
* (The concept of connected CLTS sockets is alien to published TPI
* but we support it anyway).
*/
static void
{
struct T_addr_ack *taa;
/* Make it large enough for worst case */
return;
}
/*
* Note: Following code assumes 32 bit alignment of basic
* data structures like sin_t and struct T_addr_ack.
*/
/*
* Fill in local address first
*/
/* Fill zeroes and then initialize non-zero fields */
} else {
/*
* INADDR_ANY
* udp_v6src is not set, we might be bound to
* local address instead (that could
* also still be INADDR_ANY)
*/
}
/*
* connected, fill remote address too
*/
/* assumed 32-bit alignment */
/* initialize */
}
} else {
/* Fill zeroes and then initialize non-zero fields */
} else {
/*
* UNSPECIFIED
* udp_v6src is not set, we might be bound to
* local address instead (that could
* also still be UNSPECIFIED)
*/
}
/*
* connected, fill remote address too
*/
/* assumed 32-bit alignment */
/* initialize */
}
}
}
}
static void
{
} else {
}
}
/*
* This routine responds to T_CAPABILITY_REQ messages. It is called by
* udp_wput. Much of the T_CAPABILITY_ACK information is copied from
* udp_g_t_info_ack. The current state of the stream is copied from
* udp_state.
*/
static void
{
struct T_capability_ack *tcap;
if (!mp)
return;
}
}
/*
* This routine responds to T_INFO_REQ messages. It is called by udp_wput.
* Most of the T_INFO_ACK information is copied from udp_g_t_info_ack.
* The current state of the stream is copied from udp_state.
*/
static void
{
/* Create a T_INFO_ACK message. */
if (!mp)
return;
}
/*
* IP recognizes seven kinds of bind requests:
*
* - A zero-length address binds only to the protocol number.
*
* - A 4-byte address is treated as a request to
* validate that the address is a valid local IPv4
* address, appropriate for an application to bind to.
* IP does the verification, but does not make any note
* of the address at this time.
*
* - A 16-byte address contains is treated as a request
* to validate a local IPv6 address, as the 4-byte
* address case above.
*
* - A 16-byte sockaddr_in to validate the local IPv4 address and also
* use it for the inbound fanout of packets.
*
* - A 24-byte sockaddr_in6 to validate the local IPv6 address and also
* use it for the inbound fanout of packets.
*
* - A 12-byte address (ipa_conn_t) containing complete IPv4 fanout
* information consisting of local and remote addresses
* and ports. In this case, the addresses are both
* validated as appropriate for this operation, and, if
* so, the information is retained for use in the
* inbound fanout.
*
* - A 36-byte address address (ipa6_conn_t) containing complete IPv6
* fanout information, like the 12-byte case above.
*
* IP will also fill in the IRE request mblk with information
* regarding our peer. In all cases, we notify IP of our protocol
* type by appending a single protocol byte to the bind request.
*/
static mblk_t *
{
char *cp;
struct T_bind_req *tbr;
ipa_conn_t *ac;
if (!mp)
return (mp);
tbr->CONIND_number = 0;
switch (addr_length) {
case sizeof (ipa_conn_t):
/* Append a request for an IRE */
return (NULL);
}
/* cp known to be 32 bit aligned */
break;
case sizeof (ipa6_conn_t):
/* Append a request for an IRE */
return (NULL);
}
/* cp known to be 32 bit aligned */
break;
case sizeof (sin_t):
/* Append a request for an IRE */
return (NULL);
}
break;
case sizeof (sin6_t):
/* Append a request for an IRE */
return (NULL);
}
break;
}
/* Add protocol number to end */
return (mp);
}
/*
* This is the open routine for udp. It allocates a udp_t structure for
* the stream and, on the first open of the module, creates an ND table.
*/
/* ARGSUSED */
static int
{
int err;
netstack_t *ns;
/* If the stream is already open, return immediately. */
return (0);
/* If this is not a push of udp as a module, fail. */
return (EINVAL);
/*
* For exclusive stacks we set the zoneid to zero
* to make UDP operate as if in the global zone.
*/
else
/* Insert ourselves in the stream since we're about to walk q_next */
qprocson(q);
/*
* UDP is supported only as a module and it has to be pushed directly
* above the device instance of IP. If UDP is pushed anywhere else
* on a stream, it will support just T_SVR4_OPTMGMT_REQ for the
* sake of MIB browsers and fail everything else.
*/
if (NOT_OVER_IP(ip_wq)) {
/* Support just SNMP for MIB browsers */
us->us_netstack);
q->q_qinfo = &udp_snmp_rinit;
return (0);
}
/*
* Initialize the udp_t structure for this stream.
*/
/* Set the initial state of the stream and the privilege status. */
} else {
}
/*
* If the caller has the process-wide flag set, then default to MAC
* exempt mode. This allows read-down to unlabeled hosts.
*/
}
/*
* getsockopts.
*/
/* Build initial header template for transmit */
/* XXX missing free of connp? crfree? netstack_rele? */
return (err);
}
}
/* Set the Stream head write offset and high watermark. */
(void) mi_set_sth_wroff(UDP_RD(q),
return (0);
}
/*
* Which UDP options OK to set through T_UNITDATA_REQ...
*/
/* ARGSUSED */
static boolean_t
{
return (B_TRUE);
}
/*
* This routine gets default values of certain options whose default
* values are maintained by protcol specific code
*/
/* ARGSUSED */
int
{
switch (level) {
case IPPROTO_IP:
switch (name) {
case IP_MULTICAST_TTL:
return (sizeof (uchar_t));
case IP_MULTICAST_LOOP:
return (sizeof (uchar_t));
}
break;
case IPPROTO_IPV6:
switch (name) {
case IPV6_MULTICAST_HOPS:
return (sizeof (int));
case IPV6_MULTICAST_LOOP:
return (sizeof (int));
case IPV6_UNICAST_HOPS:
return (sizeof (int));
}
break;
}
return (-1);
}
/*
* This routine retrieves the current status of socket options
* and expects the caller to pass in the queue pointer of the
* upper instance. It returns the size of the option retrieved.
*/
int
{
int len;
q = UDP_WR(q);
switch (level) {
case SOL_SOCKET:
switch (name) {
case SO_DEBUG:
break; /* goto sizeof (int) option return */
case SO_REUSEADDR:
break; /* goto sizeof (int) option return */
case SO_TYPE:
*i1 = SOCK_DGRAM;
break; /* goto sizeof (int) option return */
/*
* The following three items are available here,
* but are only meaningful to IP.
*/
case SO_DONTROUTE:
break; /* goto sizeof (int) option return */
case SO_USELOOPBACK:
break; /* goto sizeof (int) option return */
case SO_BROADCAST:
break; /* goto sizeof (int) option return */
case SO_SNDBUF:
break; /* goto sizeof (int) option return */
case SO_RCVBUF:
break; /* goto sizeof (int) option return */
case SO_DGRAM_ERRIND:
break; /* goto sizeof (int) option return */
case SO_RECVUCRED:
break; /* goto sizeof (int) option return */
case SO_TIMESTAMP:
break; /* goto sizeof (int) option return */
case SO_ANON_MLP:
break; /* goto sizeof (int) option return */
case SO_MAC_EXEMPT:
break; /* goto sizeof (int) option return */
case SO_ALLZONES:
break; /* goto sizeof (int) option return */
case SO_EXCLBIND:
break;
case SO_PROTOTYPE:
*i1 = IPPROTO_UDP;
break;
case SO_DOMAIN:
break;
default:
return (-1);
}
break;
case IPPROTO_IP:
return (-1);
switch (name) {
case IP_OPTIONS:
case T_IP_OPTIONS:
if (len > 0) {
}
return (len);
case IP_TOS:
case T_IP_TOS:
break; /* goto sizeof (int) option return */
case IP_TTL:
break; /* goto sizeof (int) option return */
case IP_NEXTHOP:
case IP_RECVPKTINFO:
/*
* This also handles IP_PKTINFO.
* IP_PKTINFO and IP_RECVPKTINFO have the same value.
* Differentiation is based on the size of the argument
* passed in.
* This option is handled in IP which will return an
* error for IP_PKTINFO as it's not supported as a
* sticky option.
*/
return (-EINVAL);
case IP_MULTICAST_IF:
/* 0 address if not set */
return (sizeof (ipaddr_t));
case IP_MULTICAST_TTL:
return (sizeof (uchar_t));
case IP_MULTICAST_LOOP:
return (sizeof (uint8_t));
case IP_RECVOPTS:
break; /* goto sizeof (int) option return */
case IP_RECVDSTADDR:
break; /* goto sizeof (int) option return */
case IP_RECVIF:
break; /* goto sizeof (int) option return */
case IP_RECVSLLA:
break; /* goto sizeof (int) option return */
case IP_RECVTTL:
break; /* goto sizeof (int) option return */
case IP_ADD_MEMBERSHIP:
case IP_DROP_MEMBERSHIP:
case IP_BLOCK_SOURCE:
case IP_UNBLOCK_SOURCE:
case IP_ADD_SOURCE_MEMBERSHIP:
case MCAST_JOIN_GROUP:
case MCAST_LEAVE_GROUP:
case MCAST_BLOCK_SOURCE:
case MCAST_UNBLOCK_SOURCE:
case MCAST_JOIN_SOURCE_GROUP:
case MCAST_LEAVE_SOURCE_GROUP:
case IP_DONTFAILOVER_IF:
/* cannot "get" the value for these */
return (-1);
case IP_BOUND_IF:
/* Zero if not set */
break; /* goto sizeof (int) option return */
case IP_UNSPEC_SRC:
break; /* goto sizeof (int) option return */
case IP_XMIT_IF:
break; /* goto sizeof (int) option return */
default:
return (-1);
}
break;
case IPPROTO_IPV6:
return (-1);
switch (name) {
case IPV6_UNICAST_HOPS:
break; /* goto sizeof (int) option return */
case IPV6_MULTICAST_IF:
/* 0 index if not set */
break; /* goto sizeof (int) option return */
case IPV6_MULTICAST_HOPS:
break; /* goto sizeof (int) option return */
case IPV6_MULTICAST_LOOP:
break; /* goto sizeof (int) option return */
case IPV6_JOIN_GROUP:
case IPV6_LEAVE_GROUP:
case MCAST_JOIN_GROUP:
case MCAST_LEAVE_GROUP:
case MCAST_BLOCK_SOURCE:
case MCAST_UNBLOCK_SOURCE:
case MCAST_JOIN_SOURCE_GROUP:
case MCAST_LEAVE_SOURCE_GROUP:
/* cannot "get" the value for these */
return (-1);
case IPV6_BOUND_IF:
/* Zero if not set */
break; /* goto sizeof (int) option return */
case IPV6_UNSPEC_SRC:
break; /* goto sizeof (int) option return */
case IPV6_RECVPKTINFO:
break; /* goto sizeof (int) option return */
case IPV6_RECVTCLASS:
break; /* goto sizeof (int) option return */
case IPV6_RECVPATHMTU:
break; /* goto sizeof (int) option return */
case IPV6_RECVHOPLIMIT:
break; /* goto sizeof (int) option return */
case IPV6_RECVHOPOPTS:
break; /* goto sizeof (int) option return */
case IPV6_RECVDSTOPTS:
break; /* goto sizeof (int) option return */
case _OLD_IPV6_RECVDSTOPTS:
break; /* goto sizeof (int) option return */
case IPV6_RECVRTHDRDSTOPTS:
break; /* goto sizeof (int) option return */
case IPV6_RECVRTHDR:
break; /* goto sizeof (int) option return */
case IPV6_PKTINFO: {
/* XXX assumes that caller has room for max size! */
struct in6_pktinfo *pkti;
else
pkti->ipi6_ifindex = 0;
else
return (sizeof (struct in6_pktinfo));
}
case IPV6_TCLASS:
else
*i1 = IPV6_FLOW_TCLASS(
break; /* goto sizeof (int) option return */
case IPV6_NEXTHOP: {
return (0);
return (sizeof (sin6_t));
}
case IPV6_HOPOPTS:
return (0);
return (0);
/*
* User is not usually aware of this option.
* We copy out the hbh opt after the label option.
*/
if (udp->udp_label_len_v6 > 0) {
}
case IPV6_RTHDRDSTOPTS:
return (0);
return (ipp->ipp_rtdstoptslen);
case IPV6_RTHDR:
return (0);
return (ipp->ipp_rthdrlen);
case IPV6_DSTOPTS:
return (0);
return (ipp->ipp_dstoptslen);
case IPV6_PATHMTU:
us->us_netstack));
default:
return (-1);
}
break;
case IPPROTO_UDP:
switch (name) {
case UDP_ANONPRIVBIND:
break;
case UDP_EXCLBIND:
break;
case UDP_RCVHDR:
break;
default:
return (-1);
}
break;
default:
return (-1);
}
return (sizeof (int));
}
/*
* This routine sets socket options; it expects the caller
* to pass in the queue pointer of the upper instance.
*/
/* ARGSUSED */
int
{
int error;
q = UDP_WR(q);
switch (optset_context) {
case SETFN_OPTCOM_CHECKONLY:
/*
* Note: Implies T_CHECK semantics for T_OPTCOM_REQ
* inlen != 0 implies value supplied and
* we have to "pretend" to set it.
* inlen == 0 implies that there is no
* value part in T_CHECK request and just validation
* done elsewhere should be enough, we just return here.
*/
if (inlen == 0) {
*outlenp = 0;
return (0);
}
break;
case SETFN_OPTCOM_NEGOTIATE:
break;
case SETFN_UD_NEGOTIATE:
case SETFN_CONN_NEGOTIATE:
/*
* Negotiating local and "association-related" options
* through T_UNITDATA_REQ.
*
* Following routine can filter out ones we do not
* want to be "set" this way.
*/
*outlenp = 0;
return (EINVAL);
}
break;
default:
/*
* We should never get here
*/
*outlenp = 0;
return (EINVAL);
}
/*
* For fixed length options, no sanity check
* of passed in length is done. It is assumed *_optcom_req()
* routines do the right thing.
*/
switch (level) {
case SOL_SOCKET:
switch (name) {
case SO_REUSEADDR:
if (!checkonly)
break;
case SO_DEBUG:
if (!checkonly)
break;
/*
* The following three items are available here,
* but are only meaningful to IP.
*/
case SO_DONTROUTE:
if (!checkonly)
break;
case SO_USELOOPBACK:
if (!checkonly)
break;
case SO_BROADCAST:
if (!checkonly)
break;
case SO_SNDBUF:
*outlenp = 0;
return (ENOBUFS);
}
if (!checkonly) {
}
break;
case SO_RCVBUF:
*outlenp = 0;
return (ENOBUFS);
}
if (!checkonly) {
(void) mi_set_sth_hiwat(UDP_RD(q),
}
break;
case SO_DGRAM_ERRIND:
if (!checkonly)
break;
case SO_RECVUCRED:
if (!checkonly)
break;
case SO_ALLZONES:
/*
* "soft" error (negative)
* option not handled at this level
* Do not modify *outlenp.
*/
return (-EINVAL);
case SO_TIMESTAMP:
if (!checkonly)
break;
case SO_ANON_MLP:
if (!checkonly)
break;
case SO_MAC_EXEMPT:
if (secpolicy_net_mac_aware(cr) != 0 ||
return (EACCES);
if (!checkonly)
break;
case SCM_UCRED: {
/*
* Only sockets that have proper privileges and are
* bound to MLPs will have any other value here, so
* this implicitly tests for privilege to set label.
*/
break;
return (EINVAL);
if (!checkonly) {
return (EINVAL);
return (EINVAL);
return (ENOSR);
}
break;
}
case SO_EXCLBIND:
if (!checkonly)
break;
default:
*outlenp = 0;
return (EINVAL);
}
break;
case IPPROTO_IP:
*outlenp = 0;
return (ENOPROTOOPT);
}
switch (name) {
case IP_OPTIONS:
case T_IP_OPTIONS:
/* Save options for use by IP. */
*outlenp = 0;
return (EINVAL);
}
if (checkonly)
break;
*outlenp = 0;
return (ENOMEM);
}
us->us_wroff_extra);
break;
case IP_TTL:
if (!checkonly) {
}
break;
case IP_TOS:
case T_IP_TOS:
if (!checkonly) {
}
break;
case IP_MULTICAST_IF: {
/*
* TODO should check OPTMGMT reply and undo this if
* there is an error.
*/
if (!checkonly) {
}
break;
}
case IP_MULTICAST_TTL:
if (!checkonly)
break;
case IP_MULTICAST_LOOP:
if (!checkonly)
break;
case IP_RECVOPTS:
if (!checkonly)
break;
case IP_RECVDSTADDR:
if (!checkonly)
break;
case IP_RECVIF:
if (!checkonly)
break;
case IP_RECVSLLA:
if (!checkonly)
break;
case IP_RECVTTL:
if (!checkonly)
break;
case IP_PKTINFO: {
/*
* This also handles IP_RECVPKTINFO.
* IP_PKTINFO and IP_RECVPKTINFO have same value.
* Differentiation is based on the size of the
* argument passed in.
*/
struct in_pktinfo *pktinfop;
if (checkonly)
break;
if (inlen == sizeof (int)) {
/*
* This is IP_RECVPKTINFO option.
* Keep a local copy of whether this option is
* set or not and pass it down to IP for
* processing.
*/
return (-EINVAL);
}
/*
* sticky option or no buffer to return
* the results.
*/
return (EINVAL);
}
if (inlen != sizeof (struct in_pktinfo))
return (EINVAL);
/*
* At least one of the values should be specified
*/
if (pktinfop->ipi_ifindex == 0 &&
return (EINVAL);
}
break;
}
case IP_ADD_MEMBERSHIP:
case IP_DROP_MEMBERSHIP:
case IP_BLOCK_SOURCE:
case IP_UNBLOCK_SOURCE:
case IP_ADD_SOURCE_MEMBERSHIP:
case MCAST_JOIN_GROUP:
case MCAST_LEAVE_GROUP:
case MCAST_BLOCK_SOURCE:
case MCAST_UNBLOCK_SOURCE:
case MCAST_JOIN_SOURCE_GROUP:
case MCAST_LEAVE_SOURCE_GROUP:
case IP_SEC_OPT:
case IP_NEXTHOP:
/*
* "soft" error (negative)
* option not handled at this level
* Do not modify *outlenp.
*/
return (-EINVAL);
case IP_BOUND_IF:
if (!checkonly)
break;
case IP_UNSPEC_SRC:
if (!checkonly)
break;
case IP_XMIT_IF:
if (!checkonly)
break;
default:
*outlenp = 0;
return (EINVAL);
}
break;
case IPPROTO_IPV6: {
*outlenp = 0;
return (ENOPROTOOPT);
}
/*
* Deal with both sticky options and ancillary data
*/
NULL) {
/* sticky options, or none */
}
switch (name) {
case IPV6_MULTICAST_IF:
if (!checkonly)
break;
case IPV6_UNICAST_HOPS:
/* -1 means use default */
*outlenp = 0;
return (EINVAL);
}
if (!checkonly) {
if (*i1 == -1) {
/* Pass modified value to IP. */
} else {
}
/* Rebuild the header template */
if (error != 0) {
*outlenp = 0;
return (error);
}
}
break;
case IPV6_MULTICAST_HOPS:
/* -1 means use default */
*outlenp = 0;
return (EINVAL);
}
if (!checkonly) {
if (*i1 == -1) {
/* Pass modified value to IP. */
} else {
}
}
break;
case IPV6_MULTICAST_LOOP:
*outlenp = 0;
return (EINVAL);
}
if (!checkonly)
break;
case IPV6_JOIN_GROUP:
case IPV6_LEAVE_GROUP:
case MCAST_JOIN_GROUP:
case MCAST_LEAVE_GROUP:
case MCAST_BLOCK_SOURCE:
case MCAST_UNBLOCK_SOURCE:
case MCAST_JOIN_SOURCE_GROUP:
case MCAST_LEAVE_SOURCE_GROUP:
/*
* "soft" error (negative)
* option not handled at this level
* Note: Do not modify *outlenp
*/
return (-EINVAL);
case IPV6_BOUND_IF:
if (!checkonly)
break;
case IPV6_UNSPEC_SRC:
if (!checkonly)
break;
/*
* Set boolean switches for ancillary data delivery
*/
case IPV6_RECVPKTINFO:
if (!checkonly)
break;
case IPV6_RECVTCLASS:
if (!checkonly) {
}
break;
case IPV6_RECVPATHMTU:
if (!checkonly) {
}
break;
case IPV6_RECVHOPLIMIT:
if (!checkonly)
break;
case IPV6_RECVHOPOPTS:
if (!checkonly)
break;
case IPV6_RECVDSTOPTS:
if (!checkonly)
break;
case _OLD_IPV6_RECVDSTOPTS:
if (!checkonly)
break;
case IPV6_RECVRTHDRDSTOPTS:
if (!checkonly)
break;
case IPV6_RECVRTHDR:
if (!checkonly)
break;
/*
* Set sticky options or ancillary data.
* If sticky options, (re)build any extension headers
* that might be needed as a result.
*/
case IPV6_PKTINFO:
/*
* The source address and ifindex are verified
* in ip_opt_set(). For ancillary data the
* source address is checked in ip_wput_v6.
*/
return (EINVAL);
if (checkonly)
break;
if (inlen == 0) {
} else {
struct in6_pktinfo *pkti;
if (ipp->ipp_ifindex != 0)
else
if (!IN6_IS_ADDR_UNSPECIFIED(
else
}
if (sticky) {
if (error != 0)
return (error);
}
break;
case IPV6_HOPLIMIT:
if (sticky)
return (EINVAL);
return (EINVAL);
if (checkonly)
break;
if (inlen == 0) {
} else {
return (EINVAL);
if (*i1 == -1)
ipp->ipp_hoplimit =
else
}
break;
case IPV6_TCLASS:
return (EINVAL);
if (checkonly)
break;
if (inlen == 0) {
} else {
return (EINVAL);
if (*i1 == -1)
ipp->ipp_tclass = 0;
else
}
if (sticky) {
if (error != 0)
return (error);
}
break;
case IPV6_NEXTHOP:
/*
* IP will verify that the nexthop is reachable
* and fail for sticky options.
*/
return (EINVAL);
if (checkonly)
break;
if (inlen == 0) {
} else {
return (EAFNOSUPPORT);
if (IN6_IS_ADDR_V4MAPPED(
return (EADDRNOTAVAIL);
if (!IN6_IS_ADDR_UNSPECIFIED(
&ipp->ipp_nexthop))
else
}
if (sticky) {
if (error != 0)
return (error);
}
break;
case IPV6_HOPOPTS: {
/*
* Sanity checks - minimum size, size a multiple of
* eight bytes, and matching size passed in.
*/
if (inlen != 0 &&
return (EINVAL);
if (checkonly)
break;
if (error != 0)
return (error);
if (ipp->ipp_hopoptslen == 0) {
} else {
}
if (sticky) {
if (error != 0)
return (error);
}
break;
}
case IPV6_RTHDRDSTOPTS: {
/*
* Sanity checks - minimum size, size a multiple of
* eight bytes, and matching size passed in.
*/
if (inlen != 0 &&
return (EINVAL);
if (checkonly)
break;
if (inlen == 0) {
if (sticky &&
ipp->ipp_rtdstoptslen = 0;
}
} else {
&ipp->ipp_rtdstoptslen, 0);
if (error != 0)
return (error);
}
if (sticky) {
if (error != 0)
return (error);
}
break;
}
case IPV6_DSTOPTS: {
/*
* Sanity checks - minimum size, size a multiple of
* eight bytes, and matching size passed in.
*/
if (inlen != 0 &&
return (EINVAL);
if (checkonly)
break;
if (inlen == 0) {
if (sticky &&
ipp->ipp_dstoptslen = 0;
}
} else {
&ipp->ipp_dstoptslen, 0);
if (error != 0)
return (error);
}
if (sticky) {
if (error != 0)
return (error);
}
break;
}
case IPV6_RTHDR: {
/*
* Sanity checks - minimum size, size a multiple of
* eight bytes, and matching size passed in.
*/
if (inlen != 0 &&
return (EINVAL);
if (checkonly)
break;
if (inlen == 0) {
if (sticky &&
ipp->ipp_rthdrlen);
ipp->ipp_rthdrlen = 0;
}
} else {
&ipp->ipp_rthdrlen, 0);
if (error != 0)
return (error);
}
if (sticky) {
if (error != 0)
return (error);
}
break;
}
case IPV6_DONTFRAG:
if (checkonly)
break;
if (onoff) {
} else {
}
break;
case IPV6_USE_MIN_MTU:
if (inlen != sizeof (int))
return (EINVAL);
return (EINVAL);
if (checkonly)
break;
break;
case IPV6_BOUND_PIF:
case IPV6_SEC_OPT:
case IPV6_DONTFAILOVER_IF:
case IPV6_SRC_PREFERENCES:
case IPV6_V6ONLY:
/* Handled at the IP level */
return (-EINVAL);
default:
*outlenp = 0;
return (EINVAL);
}
break;
} /* end IPPROTO_IPV6 */
case IPPROTO_UDP:
switch (name) {
case UDP_ANONPRIVBIND:
*outlenp = 0;
return (error);
}
if (!checkonly) {
}
break;
case UDP_EXCLBIND:
if (!checkonly)
break;
case UDP_RCVHDR:
if (!checkonly)
break;
default:
*outlenp = 0;
return (EINVAL);
}
break;
default:
*outlenp = 0;
return (EINVAL);
}
/*
* Common case of OK return with outval same as inval.
*/
}
return (0);
}
/*
* Update udp_sticky_hdrs based on udp_sticky_ipp, udp_v6src, and udp_ttl.
* The headers include ip6i_t (if needed), ip6_t, any sticky extension
* headers, and the udp header.
* Returns failure if can't allocate memory.
*/
static int
{
/* Need to reallocate */
return (ENOMEM);
if (udp->udp_sticky_hdrs_len != 0) {
}
}
/* Set header fields not in ipp */
} else {
}
/* Try to get everything in a single mblk */
us->us_wroff_extra);
}
return (0);
}
/*
* This routine retrieves the value of an ND variable in a udpparam_t
* structure. It is called through nd_getset when a user reads the
* variable.
*/
/* ARGSUSED */
static int
{
return (0);
}
/*
* Walk through the param array specified registering each element with the
* named dispatch (ND) handler.
*/
static boolean_t
{
return (B_FALSE);
}
}
}
return (B_FALSE);
}
return (B_FALSE);
}
return (B_FALSE);
}
NULL)) {
return (B_FALSE);
}
NULL)) {
return (B_FALSE);
}
return (B_TRUE);
}
/* This routine sets an ND variable in a udpparam_t structure. */
/* ARGSUSED */
static int
{
long new_value;
/*
* Fail the request if the new value does not lie within the
* required bounds.
*/
return (EINVAL);
}
/* Set the new value */
return (0);
}
/*
* Copy hop-by-hop option from ipp->ipp_hopopts to the buffer provided (with
* T_opthdr) and return the number of bytes copied. 'dbuf' may be NULL to
* just count the length needed for allocation. If 'dbuf' is non-NULL,
* then it's assumed to be allocated to be large enough.
*
* Returns zero if trimming of the security option causes all options to go
* away.
*/
static size_t
{
}
/*
* If labeling is enabled, then skip the label option
* but get other options if there are any.
*/
if (is_system_labeled()) {
/* will fill in ip6h_len later */
}
/*
* This loop finds the first (lastpad pointer) of any number of
* pads that preceeds the security option, then treats the
* security option as though it were a pad, and then finds the
* next non-pad option (or end of list).
*
* It then treats the entire block as one big pad. To preserve
* alignment of any options that follow, or just the end of the
* list, it computes a minimal new padding size that keeps the
* same alignment for the next option.
*
* If it encounters just a sequence of pads with no security
* option, those are copied as-is rather than collapsed.
*
* Note that to handle the end of list case, the code makes one
* loop with 'hol' set to zero.
*/
for (;;) {
if (hol > 0) {
hol--;
continue;
}
continue;
}
} else {
/* if nothing was copied at all, then delete */
return (0);
/* last pass; pick up any trailing padding */
olen = 0;
}
if (deleting) {
/*
* compute aligning effect of deleted material
* to reproduce with pad.
*/
(const char *)lastpad) & 7;
if (plen == 1) {
} else if (plen > 1) {
if (plen > 0)
}
}
}
/* if there's uncopied padding, then copy that now */
(const char *)lastpad;
}
}
if (hol == 0)
break;
}
/* go back and patch up the length value, rounded upward */
} else {
}
return (tlen);
}
static void
{
struct T_unitdata_ind *tudi;
int hdr_length; /* Length of IP+UDP headers */
int udi_size; /* Size of T_unitdata_ind */
int mp_len;
int ipversion;
"udp_rput_start: q %p mp %p", q, mp);
/*
* IP should have prepended the options data in an M_CTL
* Check M_CTL "type" to make sure are not here bcos of
* a valid ICMP message
*/
IN_PKTINFO) {
/*
* IP_RECVIF or IP_RECVSLLA or IPF_RECVADDR information
* has been appended to the packet by IP. We need to
* extract the mblk and adjust the rptr
*/
options_mp = mp;
} else {
/*
* ICMP messages.
*/
udp_icmp_error(q, mp);
"udp_rput_end: q %p (%S)", q, "m_ctl");
return;
}
}
/*
* This is the inbound data path.
* First, we check to make sure the IP version number is correct,
* and then pull the IP and UDP headers into the first mblk.
* Assume IP provides aligned packets - otherwise toss.
* Also, check if we have a complete IP header.
*/
/* Initialize regardless if ipversion is IPv4 or IPv6 */
ipp.ipp_fields = 0;
switch (ipversion) {
case IPV4_VERSION:
(udp->udp_ip_rcv_options_len)) {
/*
* Handle IPv4 packets with options outside of the
* main data path. Not needed for AF_INET6 sockets
* since they don't support a getsockopt of IP_OPTIONS.
*/
break;
/*
* UDP length check performed for IPv4 packets with
* options to check whether UDP length specified in
* the header is the same as the physical length of
* the packet.
*/
hdr_length - UDPH_SIZE)) {
goto tossit;
}
/*
* Handle the case where the packet has IP options
* and the IP_RECVSLLA & IP_RECVIF are set
*/
mp = options_mp;
"udp_rput_end: q %p (%S)", q, "end");
return;
}
/* Handle IPV6_RECVHOPLIMIT. */
}
}
break;
case IPV6_VERSION:
/*
* IPv6 packets can only be received by applications
* that are prepared to receive IPv6 addresses.
* The IP fanout must ensure this.
*/
/* Look for ifindex information */
goto tossit;
}
}
goto tossit;
}
/*
* Find any potentially interesting extension headers
* as well as the length of the IPv6 + extension
* headers.
*/
} else {
}
break;
default:
ASSERT(0);
}
/*
* IP inspected the UDP header thus all of it must be in the mblk.
* UDP length check is performed for IPv6 packets and IPv4 packets
* without options to check if the size of the packet as specified
* by the header is the same as the physical size of the packet.
*/
goto tossit;
}
/* Walk past the headers. */
if (!udp->udp_rcvhdr) {
mp_len -= hdr_length;
}
/*
* This is the inbound data path. Packets are passed upstream as
* T_UNITDATA_IND messages with full IP headers still attached.
*/
/*
* Normally only send up the address.
* If IP_RECVDSTADDR is set we include the destination IP
* address as an option. With IP_RECVOPTS we include all
* the IP options. Only ip_rput_other() handles packets
* that contain IP options.
*/
if (udp->udp_recvdstaddr) {
sizeof (struct in_addr);
}
sizeof (struct in_pktinfo);
}
/*
* If the IP_RECVSLLA or the IP_RECVIF is set then allocate
* space accordingly
*/
}
sizeof (struct sockaddr_dl);
}
}
/*
* If SO_TIMESTAMP is set allocate the appropriate sized
* buffer. Since gethrestime() expects a pointer aligned
* argument, we allocate space necessary for extra
* alignment (even though it might not be used).
*/
if (udp->udp_timestamp) {
sizeof (timestruc_t) + _POINTER_ALIGNMENT;
}
/*
* If IP_RECVTTL is set allocate the appropriate sized buffer
*/
if (udp->udp_recvttl) {
}
/* Allocate a message block for the T_UNITDATA_IND structure. */
if (options_mp != NULL)
"udp_rput_end: q %p (%S)", q, "allocbfail");
return;
}
sizeof (sin_t);
/*
* Add options if IP_RECVDSTADDR, IP_RECVIF, IP_RECVSLLA or
* IP_RECVTTL has been set.
*/
if (udi_size != 0) {
/*
* Copy in destination address before options to avoid
* any padding issues.
*/
char *dstopt;
if (udp->udp_recvdstaddr) {
sizeof (ipaddr_t);
}
struct in_pktinfo *pktinfop;
sizeof (*pktinfop);
dstopt += sizeof (struct in_pktinfo);
}
struct sockaddr_dl *dstptr;
sizeof (struct sockaddr_dl);
sizeof (struct sockaddr_dl));
}
sizeof (uint_t);
}
}
if (udp->udp_timestamp) {
sizeof (timestruc_t) + _POINTER_ALIGNMENT;
/* Align for gethrestime() */
sizeof (intptr_t));
}
/*
* CAUTION:
* Due to aligment issues
* Processing of IP_RECVTTL option
* should always be the last. Adding
* any option processing after this will
* cause alignment panic.
*/
if (udp->udp_recvttl) {
sizeof (uint8_t);
}
/* Consumed all of allocated space */
}
} else {
/*
* Handle both IPv4 and IPv6 packets for IPv6 sockets.
*
* Normally we only send up the address. If receiving of any
* optional receive side information is enabled, we also send
* that up as options.
* [ Only udp_rput_other() handles packets that contain IP
* options so code to account for does not appear immediately
* below but elsewhere ]
*/
if (udp->udp_ipv6_recvhopopts &&
if (hlen == 0)
}
if ((udp->udp_ipv6_recvdstopts ||
}
if (((udp->udp_ipv6_recvdstopts &&
}
if (udp->udp_ipv6_recvrthdr &&
}
if (udp->udp_ip_recvpktinfo &&
sizeof (struct in6_pktinfo);
}
}
}
if (udp->udp_ipv6_recvhoplimit) {
}
if (udp->udp_ipv6_recvtclass) {
}
if (options_mp != NULL)
"udp_rput_end: q %p (%S)", q, "allocbfail");
return;
}
sizeof (sin6_t);
if (ipversion == IPV4_VERSION) {
&v6dst);
sin6->sin6_flowinfo = 0;
sin6->sin6_scope_id = 0;
} else {
/* No sin6_flowinfo per API */
sin6->sin6_flowinfo = 0;
/* For link-scope source pass up scope id */
else
sin6->sin6_scope_id = 0;
us->us_netstack);
}
if (udi_size != 0) {
if (udp->udp_ip_recvpktinfo &&
struct in6_pktinfo *pkti;
sizeof (*pkti);
if (ipversion == IPV6_VERSION)
else
}
if (udp->udp_ipv6_recvhoplimit) {
sizeof (uint_t);
if (ipversion == IPV6_VERSION)
else
}
if (udp->udp_ipv6_recvtclass) {
sizeof (uint_t);
if (ipversion == IPV6_VERSION) {
} else {
}
}
if (udp->udp_ipv6_recvhopopts &&
}
if (udp->udp_ipv6_recvdstopts &&
}
if (udp->udp_ipv6_recvrthdr &&
}
if (udp->udp_ipv6_recvdstopts &&
}
}
/* Consumed all of allocated space */
}
/* No IP_RECVDSTADDR for IPv6. */
}
"udp_rput_end: q %p (%S)", q, "end");
if (options_mp != NULL)
if (udp->udp_direct_sockfs) {
/*
* There is nothing above us except for the stream head;
* use the read-side synchronous stream interface in
* order to reduce the time spent in interrupt thread.
*/
} else {
/*
* Use regular STREAMS interface to pass data upstream
* if this is not a socket endpoint, or if we have
* switched over to the slow mode due to sockmod being
* popped or a module being pushed on top of us.
*/
}
return;
if (options_mp != NULL)
}
void
{
}
/* ARGSUSED */
static void
{
}
/*
* Process non-M_DATA messages as well as M_DATA messages that requires
* modifications to udp_ip_rcv_options i.e. IPv4 packets with IP options.
*/
static void
{
struct T_unitdata_ind *tudi;
int hdr_length;
int udi_size; /* Size of T_unitdata_ind */
int opt_len; /* Length of IP options */
struct T_error_ack *tea;
"udp_rput_other: q %p mp %p", q, mp);
case M_CTL:
/*
*/
options_mp = mp;
/*
* The actual data is in mp->b_cont
*/
break;
case M_DATA:
/*
* M_DATA messages contain IPv4 datagrams. They are handled
* after this switch.
*/
break;
case M_PROTO:
case M_PCPROTO:
/* M_PROTO messages contain some type of TPI message. */
"udp_rput_other_end: q %p (%S)", q, "protoshort");
return;
}
case T_ERROR_ACK:
switch (tea->ERROR_prim) {
case O_T_BIND_REQ:
case T_BIND_REQ: {
/*
* If our O_T_BIND_REQ/T_BIND_REQ fails,
* clear out the associated port and source
* address before passing the message
* upstream. If this was caused by a T_CONN_REQ
* revert back to bound state.
*/
/* Connect failed */
/* Revert back to the bound source */
(void) udp_build_hdrs(q, udp);
break;
}
if (udp->udp_discon_pending) {
udp->udp_discon_pending = 0;
}
(void) udp_build_hdrs(q, udp);
break;
}
default:
break;
}
break;
case T_BIND_ACK:
udp_rput_bind_ack(q, mp);
return;
case T_OPTMGMT_ACK:
case T_OK_ACK:
break;
default:
return;
}
return;
}
/*
* This is the inbound data path.
* First, we make sure the data contains both IP and UDP headers.
*
* This handle IPv4 packets for only AF_INET sockets.
* AF_INET6 sockets can never access udp_ip_rcv_options thus there
* is no need saving the options.
*/
if (options_mp != NULL)
"udp_rput_other_end: q %p (%S)", q, "hdrshort");
return;
}
}
/* Walk past the headers. */
if (!udp->udp_rcvhdr)
/* Save the options if any */
if (opt_len > 0) {
if (udp->udp_ip_rcv_options_len)
udp->udp_ip_rcv_options_len = 0;
if (udp->udp_ip_rcv_options)
}
if (udp->udp_ip_rcv_options_len) {
/* Adjust length if we are resusing the space */
}
} else if (udp->udp_ip_rcv_options_len) {
udp->udp_ip_rcv_options_len = 0;
}
/*
* Normally only send up the address.
* If IP_RECVDSTADDR is set we include the destination IP
* address as an option. With IP_RECVOPTS we include all
* the IP options.
*/
if (udp->udp_recvdstaddr) {
}
sizeof (struct in_pktinfo);
}
}
/*
* If the IP_RECVSLLA or the IP_RECVIF is set then allocate
* space accordingly
*/
}
sizeof (struct sockaddr_dl);
}
}
/*
* If IP_RECVTTL is set allocate the appropriate sized buffer
*/
if (udp->udp_recvttl) {
}
/* Allocate a message block for the T_UNITDATA_IND structure. */
if (options_mp != NULL)
"udp_rput_other_end: q %p (%S)", q, "allocbfail");
return;
}
/*
* Add options if IP_RECVDSTADDR, IP_RECVIF, IP_RECVSLLA or
* IP_RECVTTL has been set.
*/
if (udi_size != 0) {
/*
* Copy in destination address before options to avoid any
* padding issues.
*/
char *dstopt;
if (udp->udp_recvdstaddr) {
}
}
struct in_pktinfo *pktinfop;
sizeof (*pktinfop);
dstopt += sizeof (struct in_pktinfo);
}
struct sockaddr_dl *dstptr;
sizeof (struct sockaddr_dl);
sizeof (struct sockaddr_dl));
dstopt += sizeof (struct sockaddr_dl);
}
sizeof (uint_t);
}
}
if (udp->udp_recvttl) {
sizeof (uint8_t);
}
}
"udp_rput_other_end: q %p (%S)", q, "end");
if (options_mp != NULL)
if (udp->udp_direct_sockfs) {
/*
* There is nothing above us except for the stream head;
* use the read-side synchronous stream interface in
* order to reduce the time spent in interrupt thread.
*/
} else {
/*
* Use regular STREAMS interface to pass data upstream
* if this is not a socket endpoint, or if we have
* switched over to the slow mode due to sockmod being
* popped or a module being pushed on top of us.
*/
}
}
/* ARGSUSED */
static void
{
}
/*
* Process a T_BIND_ACK
*/
static void
{
struct T_bind_ack *tba;
ipa_conn_t *ac;
if (udp->udp_discon_pending)
udp->udp_discon_pending = 0;
/*
* the source address to 0.
* This ensures no datagrams with broadcast address
* as source address are emitted (which would violate
* RFC1122 - Hosts requirements)
*
* Note that when connecting the returned IRE is
* for the destination address and we only perform
* the broadcast check for the source address (it
*/
/*
* Note: we get IRE_BROADCAST for IPv6 to "mark" a multicast
* local address.
*/
/* This was just a local bind to a broadcast addr */
(void) udp_build_hdrs(q, udp);
/*
* Local address not yet set - pick it from the
* T_bind_ack
*/
switch (udp->udp_family) {
case AF_INET:
} else {
sizeof (ipa_conn_x_t));
}
break;
case AF_INET6:
} else {
sizeof (ipa6_conn_x_t));
ac6 = &((ipa6_conn_x_t *)
}
(void) udp_build_hdrs(q, udp);
break;
}
}
}
/*
* Look for one or more appended ACK message added by
* udp_connect or udp_disconnect.
* If none found just send up the T_BIND_ACK.
* udp_connect has appended a T_OK_ACK and a T_CONN_CON.
* udp_disconnect has appended a T_OK_ACK.
*/
else {
}
}
return;
}
}
/*
* return SNMP stuff in buffer in mpdata
*/
int
{
int state;
int i;
int v4_conn_idx;
int v6_conn_idx;
return (0);
}
/* fixed length structure for IPv4 and IPv6 counters */
/* synchronize 64- and 32-bit counters */
v4_conn_idx = v6_conn_idx = 0;
for (i = 0; i < CONN_G_HASH_SIZE; i++) {
IPCL_UDP))) {
continue;
/*
* Note that the port numbers are sent in
* host byte order
*/
else
}
/*
* Create an IPv4 table entry for IPv4 entries and also
* any IPv6 entries which are bound to in6addr_any
*/
/*
* If in6addr_any this will set it to
* INADDR_ANY
*/
/*
* Can potentially get here for
* v6 socket if another process
* (say, ping) has just done a
* sendto(), changing the state
* from the TS_IDLE above to
* TS_DATA_XFER by the time we hit
* this part of the code.
*/
} else {
}
/*
* We make the assumption that all udp_t
* structs will be created within an address
* region no larger than 32-bits.
*/
(udp->udp_open_pid < 0) ?
if (needattr)
(void) snmp_append_data2(
}
} else {
}
/*
* We make the assumption that all udp_t
* structs will be created within an address
* region no larger than 32-bits.
*/
(udp->udp_open_pid < 0) ?
&mp6_conn_tail, (char *)&ude6,
sizeof (ude6));
if (needattr)
(void) snmp_append_data2(
&mp6_attr_tail, (char *)&mlp,
sizeof (mlp));
}
}
}
/* IPv4 UDP endpoints */
sizeof (struct T_optmgmt_ack)];
qreply(q, mp_conn_ctl);
/* table of MLP attributes... */
sizeof (struct T_optmgmt_ack)];
else
qreply(q, mp_attr_ctl);
/* IPv6 UDP endpoints */
sizeof (struct T_optmgmt_ack)];
qreply(q, mp6_conn_ctl);
/* table of MLP attributes... */
sizeof (struct T_optmgmt_ack)];
else
qreply(q, mp6_attr_ctl);
return (1);
}
/*
* Return 0 if invalid set request, 1 otherwise, including non-udp requests.
* NOTE: Per MIB-II, UDP has no writable data.
* TODO: If this ever actually tries to set anything, it needs to be
* to do the appropriate locking.
*/
/* ARGSUSED */
int
{
switch (level) {
case MIB2_UDP:
return (0);
default:
return (1);
}
}
static void
{
char *state;
char addrbuf1[INET6_ADDRSTRLEN];
char addrbuf2[INET6_ADDRSTRLEN];
if (buf_len == 0)
return;
state = "UNBOUND";
state = "IDLE";
state = "CONNECTED";
else
state = "UnkState";
MI_COL_PTRFMT_STR "%4d %5u %s %s %5u %s\n",
} else {
}
}
/* Report for ndd "udp_status" */
/* ARGSUSED */
static int
{
int i;
/*
* Because of the ndd constraint, at most we can have 64K buffer
* to put in all UDP info. So to be more efficient, just
* allocate a 64K buffer here, assuming we need that large buffer.
* This may be a problem as any user can read udp_status. Therefore
* we limit the rate of doing this using us_ndd_get_info_interval.
* This should be OK as normal users should not do this too often.
*/
return (0);
}
}
/* The following may work even if we cannot get a large buf. */
return (0);
}
(void) mi_mpprintf(mp,
"UDP " MI_COL_HDRPAD_STR
/* 12345678[89ABCDEF] */
" zone lport src addr dest addr port state");
/* 1234 12345 xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx 12345 UNBOUND */
for (i = 0; i < CONN_G_HASH_SIZE; i++) {
IPCL_UDP))) {
if (zoneid != GLOBAL_ZONEID &&
continue;
}
}
return (0);
}
/*
* This routine creates a T_UDERROR_IND message and passes it upstream.
* The address and options are copied from the T_UNITDATA_REQ message
* passed in mp. This message is freed.
*/
static void
{
struct T_unitdata_req *tudr;
optlen = 0;
} else {
goto done;
}
goto done;
}
goto done;
}
}
done:
}
/*
* This routine removes a port number association from a stream. It
* is called by udp_wput to handle T_UNBIND_REQ messages.
*/
static void
{
/* If a bind has not been done, we can't unbind. */
return;
}
if (cl_inet_unbind != NULL) {
/*
* Running in cluster mode - register unbind information
*/
} else {
}
}
int error;
/* Rebuild the header template */
if (error != 0) {
return;
}
}
/*
* Pass the unbind to IP; T_UNBIND_REQ is larger than T_OK_ACK
* and therefore ip_unbind must never return NULL.
*/
}
/*
* Don't let port fall into the privileged range.
* Since the extra privileged ports can be arbitrary we also
* ensure that we exclude those from consideration.
* us->us_epriv_ports is not sorted thus we loop over it until
* there are no changes.
*/
static in_port_t
{
int i;
if (random && udp_random_anon_port != 0) {
sizeof (in_port_t));
/*
* Unless changed by a sys admin, the smallest anon port
* is 32768 and the largest anon port is 65535. It is
* very likely (50%) for the random port to be smaller
* than the smallest anon port. When that happens,
* add port % (anon port range) to the smallest anon
* port to get the random port. It should fall into the
* valid anon port range.
*/
}
}
if (restart)
return (0);
}
for (i = 0; i < us->us_num_epriv_ports; i++) {
port++;
/*
* Make sure that the port is in the
* valid range.
*/
goto retry;
}
}
if (is_system_labeled() &&
goto retry;
}
return (port);
}
static int
{
int err;
if (err == 0) {
}
if (err != 0) {
char *, "queue(1) failed to update options(2) on mp(3)",
} else {
}
return (err);
}
static mblk_t *
{
int ip_hdr_length;
uint32_t ip_snd_opt_len = 0;
*error = 0;
pktinfop->ip4_ill_index = 0;
optinfo.ip_opt_flags = 0;
optinfo.ip_opt_ill_index = 0;
if (v4dst == INADDR_ANY)
/*
* If options passed in, feed it for verification and handling
*/
goto done;
/*
* Note: success in processing options.
* mp option buffer represented by
* OPT_length/offset now potentially modified
* and contain option setting results
*/
}
}
/* mp1 points to the M_DATA mblk carrying the packet */
/*
* Check if our saved options are valid; update if not
* TSOL Note: Since we are not in WRITER mode, UDP packets
* to different destination may require different labels.
* We use conn_lock to ensure that lastdst, ip_snd_options,
* and ip_snd_options_len are consistent for the current
* destination and are updated atomically.
*/
if (is_system_labeled()) {
/* Using UDP MLP requires SCM_UCRED from user */
!attrs.udpattr_credset) {
char *, "MLP mp(1) lacks SCM_UCRED attr(2) on q(3)",
*error = ECONNREFUSED;
goto done;
}
goto done;
}
}
if (udp->udp_ip_snd_options_len > 0) {
}
/* Add an IP header */
"udp_wput_end: q %p (%S)", q, "allocbfail2");
goto done;
}
else
}
#ifdef _BIG_ENDIAN
/* Set version, header length, and tos */
/* Set ttl and protocol */
#else
/* Set version, header length, and tos */
/* Set ttl and protocol */
#endif
} else {
/*
* Copy our address into the packet. If this is zero,
* first look at __sin6_src_id for a hint. If we leave the
* source as INADDR_ANY then ip will fill in the real source
* address.
*/
us->us_netstack);
}
}
if (pktinfop->ip4_ill_index != 0) {
}
ipha->ipha_ident = 0;
/* Determine length of packet */
do {
}
/*
* If the size of the packet is greater than the maximum allowed by
* ip, return an error. Passing this down could cause panics because
* the size will have wrapped and be inconsistent with the msg size.
*/
if (ip_len > IP_MAXPACKET) {
"udp_wput_end: q %p (%S)", q, "IP length exceeded");
goto done;
}
ip_len -= ip_hdr_length;
/*
* Copy in the destination address
*/
/*
* Set ttl based on IP_MULTICAST_TTL to match IPv6 logic.
*/
if (ip_hdr_length > IP_SIMPLE_HDR_LENGTH) {
/*
* Massage source route putting first source route in ipha_dst.
* Ignore the destination in T_unitdata_req.
* Create a checksum adjustment for a source route, if any.
*/
if ((int)cksum < 0)
cksum--;
/*
* IP does the checksum if uha_checksum is non-zero,
* We make it easy for IP to include our pseudo header
* by putting our length in uha_checksum.
*/
/* There might be a carry. */
#ifdef _LITTLE_ENDIAN
if (us->us_do_checksum)
#else
if (us->us_do_checksum)
else
ip_len <<= 16;
#endif
} else {
/*
* IP does the checksum if uha_checksum is non-zero,
* We make it easy for IP to include our pseudo header
* by putting our length in uha_checksum.
*/
if (us->us_do_checksum)
#ifndef _LITTLE_ENDIAN
else
ip_len <<= 16;
#endif
}
/* Set UDP length and checksum */
}
/* mp has been consumed and we'll return success */
/* We're done. Pass the packet to ip. */
"udp_wput_end: q %p (%S)", q, "end");
optinfo.ip_opt_ill_index != 0 ||
&optinfo);
} else {
}
done:
if (*error != 0) {
}
return (mp);
}
static void
{
int err;
PHYI_LOOPBACK)) {
return;
}
}
}
if (!retry_caching) {
} else {
/* Release the old ire */
}
} else {
}
return;
}
}
}
/*
* We can continue to use the ire but since it was not
* cached, we should drop the extra reference.
*/
if (!cached)
}
/*
* Check if we can take the fast-path.
* Note that "incomplete" ire's (where the link-layer for next hop
* is not resolved, or where the fast-path header in nce_fp_mp is not
* available yet) are sent down the legacy (slow) path
*/
(connp->conn_nexthop_set) ||
return;
}
/*
* If the service thread is already running, or if the driver
* queue is currently flow-controlled, queue this packet.
*/
if (ipst->ips_ip_output_queue) {
} else {
}
return;
}
#ifndef _BIG_ENDIAN
#endif
else
}
} else {
hcksum_txflags = 0;
}
/* pseudo-header checksum (do it in parts for IP header checksum) */
if (*up != 0) {
/* Software checksum? */
if (DB_CKSUMFLAGS(mp) == 0) {
}
}
/* Calculate IP header checksum if hardware isn't capable */
}
connp->conn_multicast_loop ? 0 :
}
/* If multicast TTL is 0 then we are done */
return;
}
}
if (ILL_DLS_CAPABLE(ill)) {
/*
* Send the packet directly to DLD, where it may be queued
* depending on the availability of transmit resources at
* the media layer.
*/
} else {
}
}
static boolean_t
{
int err;
if (err == 0) {
}
if (err != 0) {
char *, "queue(1) failed to update options(2) on mp(3)",
} else {
}
return (err);
}
/*
* This routine handles all messages passed downstream. It either
* consumes the message or passes it downstream; it never queues a
* a message.
*/
static void
{
int error = 0;
struct sockaddr_storage ss;
/*
* We directly handle several cases here: T_UNITDATA_REQ message
* connected and non-connected socket. The latter carries the
* address structure along when this routine gets called.
*/
case M_DATA:
if (!udp->udp_direct_sockfs ||
/* Not connected; address is required */
"udp_wput_end: connp %p (%S)", connp,
"not-connected; address required");
return;
}
/* Not connected; do some more checks below */
break;
}
/* M_DATA for connected socket */
/* Initialize addr and addrlen as if they're passed in */
} else {
sin6->sin6_scope_id = 0;
sin6->__sin6_src_id = 0;
}
/*
* Handle both AF_INET and AF_INET6; the latter
* for IPV4 mapped destination addresses. Note
* here that both addr and addrlen point to the
* corresponding struct depending on the address
* family of the socket.
*/
} else {
}
if (error != 0) {
goto ud_error;
}
return;
case M_PROTO:
case M_PCPROTO: {
struct T_unitdata_req *tudr;
/* Handle valid T_UNITDATA_REQ here */
"udp_wput_end: q %p (%S)", q, "badaddr");
goto ud_error;
}
tudr->DEST_length)) {
"udp_wput_end: q %p (%S)", q, "badaddr");
goto ud_error;
}
/*
* If a port has not been bound to the stream, fail.
* This is not a problem when sockfs is directly
* above us, because it will ensure that the socket
* is first bound before allowing data to be sent.
*/
"udp_wput_end: q %p (%S)", q, "outstate");
goto ud_error;
}
if (tudr->OPT_length != 0)
break;
}
/* FALLTHRU */
}
default:
return;
}
switch (udp->udp_family) {
case AF_INET6:
"udp_wput_end: q %p (%S)", q, "badaddr");
goto ud_error;
}
/*
* Destination is a non-IPv4-compatible IPv6 address.
* Send out an IPv6 format packet.
*/
if (error != 0)
goto ud_error;
"udp_wput_end: q %p (%S)", q, "udp_output_v6");
return;
}
/*
* If the local address is not zero or a mapped address
* return an error. It would be possible to send an IPv4
* packet but the response would never make it back to the
* application since it is bound to a non-mapped address.
*/
"udp_wput_end: q %p (%S)", q, "badaddr");
goto ud_error;
}
/* Send IPv4 packet without modifying udp_ipversion */
/* Extract port and ipaddr */
break;
case AF_INET:
"udp_wput_end: q %p (%S)", q, "badaddr");
goto ud_error;
}
/* Extract port and ipaddr */
srcid = 0;
break;
}
if (error != 0) {
/* mp is freed by the following routine */
(t_scalar_t)error);
}
}
/* ARGSUSED */
static void
{
}
static void
{
}
/*
* Allocate and prepare a T_UNITDATA_REQ message.
*/
static mblk_t *
{
struct T_unitdata_req *tudr;
tudr->OPT_length = 0;
tudr->OPT_offset = 0;
}
return (mp);
}
/*
* Entry point for sockfs when udp is in "direct sockfs" mode. This mode
* is valid when we are directly beneath the stream head, and thus sockfs
* is able to bypass STREAMS and directly call us, passing along the sockaddr
* structure without the cumbersome T_UNITDATA_REQ interface. Note that
* this is done for both connected and non-connected endpoint.
*/
void
{
q = UDP_WR(q);
/* udpsockfs should only send down M_DATA for this entry point */
/*
* We can't enter this conn right away because another
* thread is currently executing as writer; therefore we
* need to deposit the message into the squeue to be
* drained later. If a socket address is present, we
* need to create a T_UNITDATA_REQ message as placeholder.
*/
return;
}
/* Tag the packet with T_UNITDATA_REQ */
}
return;
}
/* We can execute as reader right away. */
}
/*
* udp_output_v6():
* Assumes that udp_wput did some sanity checking on the destination
* address.
*/
static mblk_t *
{
uint_t hopoptslen = 0;
*error = 0;
/*
* If the local address is a mapped address return
* an error.
* It would be possible to send an IPv6 packet but the
* response would never make it back to the application
* since it is bound to a mapped address.
*/
*error = EADDRNOTAVAIL;
goto done;
}
ipp->ipp_fields = 0;
ipp->ipp_sticky_ignored = 0;
/*
* If TPI options passed in, feed it for verification and handling
*/
goto done;
}
}
/* mp1 points to the M_DATA mblk carrying the packet */
if (sin6->sin6_scope_id != 0 &&
/*
* IPPF_SCOPE_ID is special. It's neither a sticky
* option nor ancillary data. It needs to be
* explicitly set in options_exists.
*/
}
/*
* Compute the destination address
*/
/*
* If we're not going to the same destination as last time, then
* recompute the label required. This is done in a separate routine to
* avoid blowing up our stack here.
*
* TSOL Note: Since we are not in WRITER mode, UDP packets
* to different destination may require different labels.
* We use conn_lock to ensure that lastdst, sticky ipp_hopopts,
* and sticky ipp_hopoptslen are consistent for the current
* destination and are updated atomically.
*/
if (is_system_labeled()) {
/* Using UDP MLP requires SCM_UCRED from user */
!attrs.udpattr_credset) {
char *, "MLP mp(1) lacks SCM_UCRED attr(2) on q(3)",
*error = ECONNREFUSED;
goto done;
}
if ((opt_present ||
goto done;
}
}
/*
* If there's a security label here, then we ignore any options the
* user may try to set. We keep the peer's label as a hidden sticky
* option. We make a private copy of this label before releasing the
* lock so that label is kept consistent with the destination addr.
*/
if (udp->udp_label_len_v6 > 0) {
ignore &= ~IPPF_HOPOPTS;
}
/* No sticky options nor ancillary data. */
goto no_options;
}
/*
* Go through the options figuring out where each is going to
* come from and build two masks. The first mask indicates if
* the option exists at all. The second mask indicates if the
* option is sticky or ancillary.
*/
if (!(ignore & IPPF_HOPOPTS)) {
if (hopoptsptr == NULL) {
goto done;
}
}
}
if (!(ignore & IPPF_RTHDR)) {
is_sticky |= IPPF_RTHDR;
}
}
}
}
if (!(ignore & IPPF_DSTOPTS)) {
}
}
if (!(ignore & IPPF_IFINDEX)) {
}
}
}
}
if (!(ignore & IPPF_DONTFRAG)) {
}
}
if (!(ignore & IPPF_USE_MIN_MTU)) {
}
}
/* IPV6_HOPLIMIT can never be sticky */
if (!(ignore & IPPF_UNICAST_HOPS) &&
}
if (!(ignore & IPPF_MULTICAST_HOPS) &&
}
if (!(ignore & IPPF_TCLASS)) {
is_sticky |= IPPF_TCLASS;
}
}
if (!(ignore & IPPF_NEXTHOP) &&
}
/*
* If any options carried in the ip6i_t were specified, we
* need to account for the ip6i_t in the data we'll be sending
* down.
*/
if (option_exists & IPPF_HAS_IP6I)
udp_ip_hdr_len += sizeof (ip6i_t);
/* Try to get everything in a single mblk next time */
(void) mi_set_sth_wroff(UDP_RD(q),
}
goto done;
}
else
}
if (option_exists & IPPF_HAS_IP6I) {
ip6i->ip6i_flags = 0;
/* sin6_scope_id takes precendence over IPPF_IFINDEX */
if (option_exists & IPPF_SCOPE_ID) {
} else if (option_exists & IPPF_IFINDEX) {
}
if (option_exists & IPPF_ADDR) {
/*
* Enable per-packet source address verification if
* IPV6_PKTINFO specified the source address.
* ip6_src is set in the transport's _wput function.
*/
}
if (option_exists & IPPF_DONTFRAG) {
}
if (option_exists & IPPF_USE_MIN_MTU) {
}
if (option_exists & IPPF_NEXTHOP) {
}
/*
* tell IP this is an ip6i_t private header
*/
}
/* Initialize IPv6 header */
/* Set the hoplimit of the outgoing packet. */
if (option_exists & IPPF_HOPLIMIT) {
/* IPV6_HOPLIMIT ancillary data overrides all other settings. */
if (option_exists & IPPF_MULTICAST_HOPS)
} else {
if (option_exists & IPPF_UNICAST_HOPS)
}
if (option_exists & IPPF_ADDR) {
} else {
/*
* The source address was not set using IPV6_PKTINFO.
* First look at the bound source.
* If unspecified fallback to __sin6_src_id.
*/
if (sin6->__sin6_src_id != 0 &&
us->us_netstack);
}
}
/*
* Here's where we have to start stringing together
* any extension headers in the right order:
* Hop-by-hop, destination, routing, and final destination opts.
*/
if (option_exists & IPPF_HOPOPTS) {
/* Hop-by-hop options */
if (hopoptslen == 0) {
}
cp += hopoptslen;
hopoptsptr = NULL;
hopoptslen = 0;
}
}
/*
* En-route destination options
* Only do them if there's a routing header as well
*/
if (option_exists & IPPF_RTDSTOPTS) {
}
/*
* Routing header next
*/
if (option_exists & IPPF_RTHDR) {
}
/*
* Do ultimate destination options
*/
if (option_exists & IPPF_DSTOPTS) {
}
/*
* Now set the last header pointer to the proto passed in
*/
/* Update UDP header */
/*
* Copy in the destination address
*/
if (option_exists & IPPF_TCLASS) {
tipp->ipp_tclass);
}
if (option_exists & IPPF_RTHDR) {
/*
* Perform any processing needed for source routing.
* We know that all extension headers will be in the same mblk
* as the IPv6 header.
*/
/*
* Drop packet - only support Type 0 routing.
* Notify the application as well.
*/
goto done;
}
/*
* rth->ip6r_len is twice the number of
* addresses in the header. Thus it must be even.
*/
goto done;
}
/*
* Shuffle the routing header and ip6_dst
* addresses, and get the checksum difference
* between the first hop (in ip6_dst) and
* the destination (in the last routing hdr entry).
*/
us->us_netstack);
/*
* Verify that the first hop isn't a mapped address.
* Routers along the path need to do this verification
* for subsequent hops.
*/
*error = EADDRNOTAVAIL;
goto done;
}
}
}
/* count up length of UDP packet */
do {
}
/*
* If the size of the packet is greater than the maximum allowed by
* ip, return an error. Passing this down could cause panics because
* the size will have wrapped and be inconsistent with the msg size.
*/
if (ip_len > IP_MAXPACKET) {
goto done;
}
/* Store the UDP length. Subtract length of extension hdrs */
/*
* We make it easy for IP to include our pseudo header
* by putting our length in uh_checksum, modified (if
* we have a routing header) by the checksum difference
* between the ultimate destination and first hop addresses.
* Note: UDP over IPv6 must always checksum the packet.
*/
#ifdef _LITTLE_ENDIAN
#endif
}
/* mp has been consumed and we'll return success */
/* We're done. Pass the packet to IP */
done:
hopoptsptr = NULL;
}
if (*error != 0) {
}
return (mp);
}
static void
{
"udp_wput_other_start: q %p", q);
case M_PROTO:
case M_PCPROTO:
"udp_wput_other_end: q %p (%S)",
q, "protoshort");
return;
}
case T_ADDR_REQ:
udp_addr_req(q, mp);
"udp_wput_other_end: q %p (%S)", q, "addrreq");
return;
case O_T_BIND_REQ:
case T_BIND_REQ:
"udp_wput_other_end: q %p (%S)", q, "bindreq");
return;
case T_CONN_REQ:
udp_connect(q, mp);
"udp_wput_other_end: q %p (%S)", q, "connreq");
return;
case T_CAPABILITY_REQ:
udp_capability_req(q, mp);
"udp_wput_other_end: q %p (%S)", q, "capabreq");
return;
case T_INFO_REQ:
udp_info_req(q, mp);
"udp_wput_other_end: q %p (%S)", q, "inforeq");
return;
case T_UNITDATA_REQ:
/*
* If a T_UNITDATA_REQ gets here, the address must
* be bad. Valid T_UNITDATA_REQs are handled
* in udp_wput.
*/
"udp_wput_other_end: q %p (%S)",
q, "unitdatareq");
return;
case T_UNBIND_REQ:
udp_unbind(q, mp);
"udp_wput_other_end: q %p (%S)", q, "unbindreq");
return;
case T_SVR4_OPTMGMT_REQ:
/*
* Use upper queue for option processing in
* case the request is not handled at this
* level and needs to be passed down to IP.
*/
"udp_wput_other_end: q %p (%S)",
q, "optmgmtreq");
return;
case T_OPTMGMT_REQ:
/*
* Use upper queue for option processing in
* case the request is not handled at this
* level and needs to be passed down to IP.
*/
"udp_wput_other_end: q %p (%S)",
q, "optmgmtreq");
return;
case T_DISCON_REQ:
udp_disconnect(q, mp);
"udp_wput_other_end: q %p (%S)",
q, "disconreq");
return;
/* The following TPI message is not supported by udp. */
case O_T_CONN_RES:
case T_CONN_RES:
"udp_wput_other_end: q %p (%S)",
return;
/* The following 3 TPI messages are illegal for udp. */
case T_DATA_REQ:
case T_EXDATA_REQ:
case T_ORDREL_REQ:
"udp_wput_other_end: q %p (%S)",
return;
default:
break;
}
break;
case M_FLUSH:
break;
case M_IOCTL:
case TI_GETPEERNAME:
/*
* If a default destination address has not
* been associated with the stream, then we
* don't know the peer's name.
*/
"udp_wput_other_end: q %p (%S)",
q, "getpeername");
return;
}
/* FALLTHRU */
case TI_GETMYNAME: {
/*
* For TI_GETPEERNAME and TI_GETMYNAME, we first
* need to copyin the user's strbuf structure.
* Processing will continue in the M_IOCDATA case
* below.
*/
"udp_wput_other_end: q %p (%S)",
q, "getmyname");
return;
}
case ND_SET:
/* nd_getset performs the necessary checking */
case ND_GET:
"udp_wput_other_end: q %p (%S)",
q, "get");
return;
}
break;
case _SIOCSOCKFALLBACK:
/*
* Either sockmod is about to be popped and the
* socket would now be treated as a plain stream,
* or a module is about to be pushed so we could
* no longer use read-side synchronous stream.
* Drain any queued data and disable direct sockfs
* interface from now on.
*/
if (!udp->udp_issocket) {
} else {
if (udp->udp_direct_sockfs) {
/*
* Disable read-side synchronous
* stream interface and drain any
* queued data.
*/
B_FALSE);
}
}
return;
default:
break;
}
break;
case M_IOCDATA:
udp_wput_iocdata(q, mp);
"udp_wput_other_end: q %p (%S)", q, "iocdata");
return;
default:
/* Unrecognized messages are passed through without change. */
break;
}
"udp_wput_other_end: q %p (%S)", q, "end");
}
/* ARGSUSED */
static void
{
}
/*
* udp_wput_iocdata is called by udp_wput_other to handle all M_IOCDATA
* messages.
*/
static void
{
int addrlen;
/* Make sure it is one of ours. */
case TI_GETMYNAME:
case TI_GETPEERNAME:
break;
default:
return;
}
case -1:
return;
break;
/*
* The address has been copied out, so now
* copyout the strbuf.
*/
mi_copyout(q, mp);
return;
/*
* The address and strbuf have been copied out.
* We're done, so just acknowledge the original
* M_IOCTL.
*/
mi_copy_done(q, mp, 0);
return;
default:
/*
* Something strange has happened, so acknowledge
* the original M_IOCTL with an EPROTO error.
*/
return;
}
/*
* Now we have the strbuf structure for TI_GETMYNAME
* and TI_GETPEERNAME. Next we copyout the requested
* address and then we'll copyout the strbuf.
*/
else
return;
}
case TI_GETMYNAME:
} else {
/*
* INADDR_ANY
* udp_v6src is not set, we might be bound to
* local address instead (that could
* also still be INADDR_ANY)
*/
}
} else {
/* udp->udp_family == AF_INET6 */
} else {
/*
* UNSPECIFIED
* udp_v6src is not set, we might be bound to
* local address instead (that could
* also still be UNSPECIFIED)
*/
}
}
break;
case TI_GETPEERNAME:
return;
}
} else {
/* udp->udp_family == AF_INET6) */
}
break;
default:
return;
}
if (!mp1)
return;
} else {
/* udp->udp_family == AF_INET6 */
}
/* Copy out the address */
mi_copyout(q, mp);
}
static int
{
struct T_unitdata_req *udreqp;
int is_absreq_failure;
/*
* Use upper queue for option processing since the callback
* routines expect to be called in UDP instance instead of IP.
*/
if (*errorp != 0) {
/*
* Note: No special action needed in this
* module for "is_absreq_failure"
*/
return (-1); /* failure */
}
ASSERT(is_absreq_failure == 0);
return (0); /* success */
}
void
udp_ddi_init(void)
{
/*
* We want to be informed each time a stack is created or
* destroyed in the kernel, so we can maintain the
* set of udp_stack_t's.
*/
}
void
udp_ddi_destroy(void)
{
}
/*
* Initialize the UDP stack instance.
*/
static void *
{
udpparam_t *pa;
int i;
/*
* The smallest anonymous port in the priviledged port range which UDP
* looks for free port. Use in the option UDP_ANONPRIVBIND.
*/
/* Not a power of two. Round up to nearest power of two */
for (i = 0; i < 31; i++) {
break;
}
}
sizeof (udp_fanout_t), KM_SLEEP);
for (i = 0; i < us->us_bind_fanout_size; i++) {
NULL);
}
return (us);
}
/*
* Free the UDP stack instance.
*/
static void
{
int i;
for (i = 0; i < us->us_bind_fanout_size; i++) {
}
sizeof (udp_fanout_t));
}
static void *
{
udp_stat_t template = {
{ "udp_ip_send", KSTAT_DATA_UINT64 },
{ "udp_ip_ire_send", KSTAT_DATA_UINT64 },
{ "udp_ire_null", KSTAT_DATA_UINT64 },
{ "udp_drain", KSTAT_DATA_UINT64 },
{ "udp_sock_fallback", KSTAT_DATA_UINT64 },
{ "udp_rrw_busy", KSTAT_DATA_UINT64 },
{ "udp_rrw_msgcnt", KSTAT_DATA_UINT64 },
{ "udp_out_sw_cksum", KSTAT_DATA_UINT64 },
{ "udp_out_sw_cksum_bytes", KSTAT_DATA_UINT64 },
{ "udp_out_opt", KSTAT_DATA_UINT64 },
{ "udp_out_err_notconn", KSTAT_DATA_UINT64 },
{ "udp_out_err_output", KSTAT_DATA_UINT64 },
{ "udp_out_err_tudr", KSTAT_DATA_UINT64 },
{ "udp_in_pktinfo", KSTAT_DATA_UINT64 },
{ "udp_in_recvdstaddr", KSTAT_DATA_UINT64 },
{ "udp_in_recvopts", KSTAT_DATA_UINT64 },
{ "udp_in_recvif", KSTAT_DATA_UINT64 },
{ "udp_in_recvslla", KSTAT_DATA_UINT64 },
{ "udp_in_recvucred", KSTAT_DATA_UINT64 },
{ "udp_in_recvttl", KSTAT_DATA_UINT64 },
{ "udp_in_recvhopopts", KSTAT_DATA_UINT64 },
{ "udp_in_recvhoplimit", KSTAT_DATA_UINT64 },
{ "udp_in_recvdstopts", KSTAT_DATA_UINT64 },
{ "udp_in_recvrtdstopts", KSTAT_DATA_UINT64 },
{ "udp_in_recvrthdr", KSTAT_DATA_UINT64 },
{ "udp_in_recvpktinfo", KSTAT_DATA_UINT64 },
{ "udp_in_recvtclass", KSTAT_DATA_UINT64 },
{ "udp_in_timestamp", KSTAT_DATA_UINT64 },
#ifdef DEBUG
{ "udp_data_conn", KSTAT_DATA_UINT64 },
{ "udp_data_notconn", KSTAT_DATA_UINT64 },
#endif
};
return (NULL);
return (ksp);
}
static void
{
}
}
static void *
{
{ "inDatagrams", KSTAT_DATA_UINT64, 0 },
{ "inErrors", KSTAT_DATA_UINT32, 0 },
{ "outDatagrams", KSTAT_DATA_UINT64, 0 },
{ "entrySize", KSTAT_DATA_INT32, 0 },
{ "entry6Size", KSTAT_DATA_INT32, 0 },
{ "outErrors", KSTAT_DATA_UINT32, 0 },
};
return (NULL);
return (ksp);
}
static void
{
}
}
static int
{
netstack_t *ns;
return (EIO);
if (rw == KSTAT_WRITE)
return (EACCES);
return (-1);
return (-1);
}
return (0);
}
/* ARGSUSED */
static void
{
/*
* We get here whenever we do qreply() from IP,
* i.e as part of handlings ioctls, etc.
*/
}
/*
* Read-side synchronous stream info entry point, called as a
* result of handling certain STREAMS ioctl operations.
*/
static int
{
int res = 0;
int error = 0;
/* If shutdown on read has happened, return nothing */
goto done;
}
goto done;
if (cmd & INFOD_COUNT) {
/*
* Return the number of messages.
*/
res |= INFOD_COUNT;
}
if (cmd & INFOD_BYTES) {
/*
* Return size of all data messages.
*/
res |= INFOD_BYTES;
}
if (cmd & INFOD_FIRSTBYTES) {
/*
* Return size of first data message.
*/
res |= INFOD_FIRSTBYTES;
}
if (cmd & INFOD_COPYOUT) {
int n;
/*
* Return data contents of first message.
*/
goto done;
}
}
res |= INFOD_COPYOUT;
}
done:
return (error);
}
/*
* Read-side synchronous stream entry point. This is called as a result
* outside of the interrupt thread context. It returns a single datagram
* (b_cont chain of T_UNITDATA_IND plus data) to the upper layer.
*/
static int
{
/* We should never get here when we're in SNMP mode */
/*
* Dequeue datagram from the head of the list and return
* it to caller; also ensure that RSLEEP sd_wakeq flag is
* remaining in the list.
*/
if (!udp->udp_direct_sockfs) {
return (EBUSY);
}
/* Last datagram in the list? */
udp->udp_rcv_msgcnt--;
/* No longer flow-controlling? */
}
/*
* Either we just dequeued the last datagram or
* we get here from sockfs and have nothing to
* return; in this case clear RSLEEP.
*/
STR_WAKEUP_CLEAR(STREAM(q));
} else {
/*
* More data follows; we need udp_rrw() to be
* called in future to pick up the rest.
*/
STR_WAKEUP_SET(STREAM(q));
}
return (0);
}
/*
* Enqueue a completely-built T_UNITDATA_IND message into the receive
* list; this is typically executed within the interrupt thread context
* and so we do things as quickly as possible.
*/
static void
{
/*
* Wake up and signal the receiving app; it is okay to do this
* before enqueueing the mp because we are holding the drain lock.
* One of the advantages of synchronous stream is the ability for
* us to find out when the application performs a read on the
* socket by way of udp_rrw() entry point being called. We need
* of asynchronous socket just as in the strrput() case. However,
* we only wake the application up when necessary, i.e. during the
* first enqueue. When udp_rrw() is called, we send up a single
* datagram upstream and call STR_WAKEUP_SET() again when there
* are still data remaining in our receive queue.
*/
STR_WAKEUP_SET(STREAM(q));
} else {
}
udp->udp_rcv_msgcnt++;
/* Need to flow-control? */
STR_SENDSIG(STREAM(q));
}
/*
* Drain the contents of receive list to the module upstream; we do
* this during close or when we fallback to the slow mode due to
* sockmod being popped or a module being pushed on top of us.
*/
static void
{
/*
* There is no race with a concurrent udp_input() sending
* up packets using putnext() after we have cleared the
* udp_direct_sockfs flag but before we have completed
* sending up the packets in udp_rcv_list, since we are
* either a writer or we have quiesced the conn.
*/
/*
* Send up everything via putnext(); note here that we
* don't need the udp_drain_lock to protect us since
* nothing can enter udp_rrw() and that we currently
* have exclusive access to this udp.
*/
udp->udp_rcv_msgcnt--;
if (closing) {
} else {
}
}
}
static size_t
{
/* We add a bit of extra buffering */
return (size);
}
/*
* Little helper for IPsec's NAT-T processing.
*/
{
return (us->us_do_checksum);
}