udp.c revision 955790646a3828735e0b7a562bc0a546ef4be680
/*
* 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 2006 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 latters presence.
*/
#include <inet/ipsec_info.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().
*
*/
{ "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 },
#ifdef DEBUG
{ "udp_data_conn", KSTAT_DATA_UINT64 },
{ "udp_data_notconn", KSTAT_DATA_UINT64 },
#endif
};
struct kmem_cache *udp_cache;
/*
* Bind hash list size and hash function. It has to be a power of 2 for
* hashing.
*/
#define UDP_BIND_FANOUT_SIZE 512
#define UDP_BIND_HASH(lport) \
/* UDP bind fanout hash structure. */
typedef struct udp_fanout_s {
char uf_pad[48];
#else
char uf_pad[56];
#endif
} udp_fanout_t;
/* udp_fanout_t *udp_bind_fanout. */
static udp_fanout_t *udp_bind_fanout;
/*
* This controls the rate some ndd info report functions can be used
* by non-priviledged users. It stores the last time such info is
* requested. When those report functions are called again, this
* is checked with the current time and compare with the ndd param
* udp_ndd_get_info_interval.
*/
static clock_t udp_last_ndd_get_info_time;
#define NDD_TOO_QUICK_MSG \
"ndd get info rate too high for non-priviledged users, try again " \
"later.\n"
#define NDD_OUT_OF_BUF_MSG "<< Out of buffer >>\n"
int sys_error);
int *errorp, void *thisdg_attrs);
static void udp_kstat_init(void);
static void udp_kstat_fini(void);
#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 = {
};
};
/* Hint not protected by any lock */
static in_port_t udp_g_next_port_to_try;
/*
* Extra privileged ports. In host byte order.
*/
#define UDP_NUM_EPRIV_PORTS 64
static int udp_g_num_epriv_ports = UDP_NUM_EPRIV_PORTS;
/* Only modified during _init and _fini thus no locking is needed. */
/* MIB-2 stuff for SNMP */
/* 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 udp_g_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 */
/*
* The smallest anonymous port in the priviledged port range which UDP
* looks for free port. Use in the option UDP_ANONPRIVBIND.
*/
/* 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 priviledged port range for
* bind checking.
*/
static in_port_t
udp_get_next_priv_port(void)
{
if (next_priv_port < udp_min_anonpriv_port) {
}
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(). */
if (ddi_get_lbolt() - udp_last_ndd_get_info_time <
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 < udp_bind_fanout_size; i++) {
udpf = &udp_bind_fanout[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 udp_g_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 {
B_TRUE);
}
} else {
/*
* If the port is in the well-known privileged range,
* make sure the caller was privileged.
*/
int i;
if (port < udp_smallest_nonpriv_port) {
} else {
for (i = 0; i < udp_g_num_epriv_ports; i++) {
if (port == udp_g_epriv_ports[i]) {
break;
}
}
}
if (priv) {
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) - udp_min_anonpriv_port + 1 */
} else {
}
for (;;) {
/*
* Walk through the list of udp streams bound to
* requested port with the same IP address.
*/
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
*/
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.
*/
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 udp_g_next_port_to_try below.
*/
requested_port = 0;
} else {
}
}
/*
* 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 {
}
}
/* 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 */
/* connp is now single threaded. */
/*
* Restore connp as an IP endpoint. We don't need
* any locks since we are now single threaded
*/
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 < udp_g_num_epriv_ports; i++) {
if (udp_g_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 < udp_g_num_epriv_ports; i++) {
if (new_value == udp_g_epriv_ports[i]) {
return (EEXIST);
}
}
/* Find an empty slot */
for (i = 0; i < udp_g_num_epriv_ports; i++) {
if (udp_g_epriv_ports[i] == 0)
break;
}
if (i == udp_g_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 < udp_g_num_epriv_ports; i++) {
if (udp_g_epriv_ports[i] == new_value)
break;
}
if (i == udp_g_num_epriv_ports) {
return (ESRCH);
}
/* Clear the value */
udp_g_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;
char *name;
/* If the stream is already open, return immediately. */
return (0);
/* If this is not a push of udp as a module, fail. */
return (EINVAL);
q->q_hiwat = udp_recv_hiwat;
/* 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.
*/
/* Support just SNMP for MIB browsers */
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 {
}
}
/*
* getsockopts.
*/
q->q_hiwat = udp_recv_hiwat;
/* Build initial header template for transmit */
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:
*i1 = udp_ipv6_hoplimit;
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
{
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 */
default:
return (-1);
}
break;
case IPPROTO_IP:
return (-1);
switch (name) {
case IP_OPTIONS:
case T_IP_OPTIONS:
if (udp->udp_ip_rcv_options_len)
return (udp->udp_ip_rcv_options_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:
/* Handled at IP level */
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 (ipp->ipp_hopoptslen);
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:
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:
if (*i1 > udp_max_buf) {
*outlenp = 0;
return (ENOBUFS);
}
if (!checkonly) {
}
break;
case SO_RCVBUF:
if (*i1 > udp_max_buf) {
*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;
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. */
if (inlen & 0x3) {
*outlenp = 0;
return (EINVAL);
}
if (checkonly)
break;
if (udp->udp_ip_snd_options) {
udp->udp_ip_snd_options_len = 0;
}
if (inlen) {
if (udp->udp_ip_snd_options) {
inlen);
}
}
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_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
*/
if (thisdg_attrs == NULL) {
/* sticky options, or none */
} else {
/* ancillary data */
}
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)
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 (inlen == 0) {
if (sticky &&
ipp->ipp_hopoptslen = 0;
}
} else {
&ipp->ipp_hopoptslen);
if (error != 0)
return (error);
}
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);
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);
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);
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 */
}
return (0);
}
/*
* Set optbuf and optlen for the option.
* If sticky is set allocate memory (if not already present).
* Otherwise just point optbuf and optlen at invalp and inlen.
* Returns failure if memory can not be allocated.
*/
static int
{
if (!sticky) {
return (0);
}
/* Unchanged length - no need to realocate */
return (0);
}
if (inlen != 0) {
/* Allocate new buffer before free */
return (ENOMEM);
} else {
}
/* Free old buffer */
if (*optlenp != 0)
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);
}
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 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);
}
/*
* 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_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 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);
}
/* 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 ((udp->udp_ipv6_recvdstopts ||
}
if (((udp->udp_ipv6_recvdstopts &&
}
if (udp->udp_ipv6_recvrthdr &&
}
if (udp->udp_ipv6_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;
connp->conn_zoneid);
} else {
/* No sin6_flowinfo per API */
sin6->sin6_flowinfo = 0;
/* For link-scope source pass up scope id */
else
sin6->sin6_scope_id = 0;
}
if (udi_size != 0) {
if (udp->udp_ipv6_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.
*/
udpf = &udp_bind_fanout[
/* 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) {
}
}
/*
* 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 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;
return (0);
}
/* fixed length structure for IPv4 and IPv6 counters */
for (i = 0; i < CONN_G_HASH_SIZE; i++) {
connfp = &ipcl_globalhash_fanout[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 {
}
(void) snmp_append_data2(mp_conn_data,
}
} else {
}
(void) snmp_append_data2(mp6_conn_data,
&mp6_conn_tail, (char *)&ude6,
sizeof (ude6));
}
}
}
/* IPv4 UDP endpoints */
sizeof (struct T_optmgmt_ack)];
qreply(q, mp_conn_ctl);
/* IPv6 UDP endpoints */
sizeof (struct T_optmgmt_ack)];
qreply(q, mp6_conn_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 udp_ndd_get_info_interval.
* This should be OK as normal users should not do this too often.
*/
if (ddi_get_lbolt() - udp_last_ndd_get_info_time <
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++) {
connfp = &ipcl_globalhash_fanout[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 priviledged ports can be arbitrary we also
* ensure that we exclude those from consideration.
* udp_g_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 (port < udp_smallest_anon_port) {
}
}
if (port < udp_smallest_nonpriv_port)
for (i = 0; i < udp_g_num_epriv_ports; i++) {
if (port == udp_g_epriv_ports[i]) {
port++;
/*
* Make sure that the port is in the
* valid range.
*/
goto retry;
}
}
return (port);
}
static mblk_t *
{
int ip_hdr_length;
*error = 0;
/* mp1 points to the M_DATA mblk carrying the packet */
/* 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
/*
* 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.
*/
}
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
*/
if (v4dst == INADDR_ANY)
else
/*
* 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 (udp_do_checksum)
#else
if (udp_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 (udp_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");
} 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)
}
(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 (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 {
}
}
/*
* 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 */
optlen = 0;
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 (optlen != 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 options passed in, feed it for verification and handling
*/
if (optlen != 0) {
/* failure */
"udp_wput_end: q %p (%S)", q,
"udp_unitdata_opt_process");
goto ud_error;
}
/*
* Note: success in processing options.
* mp option buffer represented by
* OPT_length/offset now potentially modified
* and contain option setting results
*/
}
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 *
int *error)
{
*error = 0;
/* mp1 points to the M_DATA mblk carrying the packet */
/*
* 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
*/
if (tudr_optlen != 0) {
/* failure */
goto done;
}
}
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.
*/
}
/* 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 (!(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 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 &&
}
}
/*
* 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 */
}
/*
* 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
*/
else
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).
*/
/*
* 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:
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
void *thisdg_attrs)
{
struct T_unitdata_req *udreqp;
int is_absreq_failure;
*errorp = 0;
/*
* 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)
{
int i;
/* Not a power of two. Round up to nearest power of two */
for (i = 0; i < 31; i++) {
if (udp_bind_fanout_size < (1 << i))
break;
}
udp_bind_fanout_size = 1 << i;
}
sizeof (udp_fanout_t), KM_SLEEP);
for (i = 0; i < udp_bind_fanout_size; i++) {
NULL);
}
}
void
udp_ddi_destroy(void)
{
int i;
for (i = 0; i < udp_bind_fanout_size; i++) {
}
sizeof (udp_fanout_t));
}
static void
udp_kstat_init(void)
{
{ "inDatagrams", KSTAT_DATA_UINT32, 0 },
{ "inErrors", KSTAT_DATA_UINT32, 0 },
{ "outDatagrams", KSTAT_DATA_UINT32, 0 },
{ "entrySize", KSTAT_DATA_INT32, 0 },
{ "entry6Size", KSTAT_DATA_INT32, 0 },
{ "outErrors", KSTAT_DATA_UINT32, 0 },
};
return;
"net", KSTAT_TYPE_NAMED,
sizeof (udp_statistics) / sizeof (kstat_named_t),
KSTAT_FLAG_VIRTUAL)) != NULL) {
}
}
static void
udp_kstat_fini(void)
{
}
}
}
static int
{
return (EIO);
if (rw == KSTAT_WRITE)
return (EACCES);
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 */
if (size > udp_max_buf)
size = udp_max_buf;
return (size);
}
/*
* Little helper for IPsec's NAT-T processing.
*/
udp_compute_checksum(void)
{
return (udp_do_checksum);
}