udp.c revision 222c5bce8762079550e5ccd485a12de1fff5a82e
/*
* 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 2008 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 is MT and uses the usual kernel synchronization primitives. There are 2
* locks, the fanout lock (uf_lock) and the udp endpoint lock udp_rwlock.
* We also use conn_lock when updating things that affect the IP classifier
* lookup.
* The lock order is udp_rwlock -> uf_lock and is udp_rwlock -> conn_lock.
*
* The fanout lock uf_lock:
* 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 and a few other fields in the udp_t. A 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.
*
* The udp_rwlock:
* This protects most of the other fields in the udp_t. The exact list of
* fields which are protected by each of the above locks is documented in
* the udp_t structure definition.
*
* Plumbing notes:
* UDP is always a device driver. For compatibility with mibopen() code
* it is possible to I_PUSH "udp", but that results in pushing a passthrough
* dummy module.
*
* The above implies that we don't support any intermediate module to
* scenario in the past as the inter-layer communication semantics have
* always been private.
*/
#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 *, boolean_t);
int *error);
#define UDP_RECV_LOWATER 128
#define UDP_XMIT_LOWATER 1024
static struct module_info udp_mod_info = {
};
/*
* Entry points for UDP as a device.
*/
static struct qinit udp_rinitv4 = {
};
static struct qinit udp_rinitv6 = {
};
};
/*
* UDP needs to handle I_LINK and I_PLINK since ifconfig
* likes to use it as a place to hang the various streams.
*/
static struct qinit udp_lrinit = {
};
static struct qinit udp_lwinit = {
};
};
};
/* 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;
/*
* 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) {
IPPROTO_UDP) != 0) {
return;
}
}
}
if (port == 0) {
return;
}
/*
* The state must be TS_UNBND. TPI mandates that users must send
* TPI primitives only 1 at a time and wait for the response before
* sending the next primitive.
*/
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. Since the udp is
* not yet in the bind hash list, we don't grab the uf_lock to
* change udp_ipversion
*/
} else {
if (IN6_IS_ADDR_V4MAPPED(&v6src)) {
/*
* no need to hold the uf_lock to set the udp_ipversion
* since we are not yet in the fanout list
*/
} 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.
*/
!connp->conn_mac_exempt && \
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.
*/
connp->conn_mac_exempt) {
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 then
* udp_bind_ack 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
/* The above return NULL if the bind needs to be deferred */
else
}
/*
* This is called from ip_wput_nondata to handle the results of a
* deferred UDP bind. It is called once the bind has been completed.
*/
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_bind_result.
* 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_bind_result 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;
}
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;
}
/*
* This UDP must have bound to a port already before doing a connect.
* TPI mandates that users must send TPI primitives only 1 at a time
* and wait for the response before sending the next primitive.
*/
return;
}
if (ipversion == IPV4_VERSION) {
} else {
}
/* Already connected - clear out state */
}
/*
* Create a default IP header with no IP options.
*/
if (ipversion == IPV4_VERSION) {
/*
* 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_bind_result.
*/
else
goto bind_failed;
}
/* Unable to reuse the T_CONN_REQ for the ack. */
return;
}
/* Hang onto the T_OK_ACK and T_CONN_CON for later. */
else
/* The above return NULL if the bind needs to be deferred */
else
}
static int
{
/*
* Disable read-side synchronous stream
* interface and drain any queued data.
*/
qprocsoff(q);
/*
* Now we are truly single threaded on this stream, and can
* delete the things hanging off the connp, and finally the connp.
* We removed this connp from the fanout list, it cannot be
* accessed thru the fanouts, and we already waited for the
* conn_ref to drop to 0. We are already in close, so
* there cannot be any other thread from the top. qprocsoff
* has completed, and service has completed or won't run in
* future.
*/
return (0);
}
/*
* Called in the close path 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. */
udp->udp_ip_snd_options_len = 0;
}
udp->udp_ip_rcv_options_len = 0;
}
/* Free memory associated with sticky options */
if (udp->udp_sticky_hdrs_len != 0) {
udp->udp_sticky_hdrs_len = 0;
}
/*
* Clear any fields which the kmem_cache constructor clears.
* Only udp_connp needs to be preserved.
* TBD: We should make this more efficient to avoid clearing
* everything.
*/
}
/*
* 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_bind_result.
* When a T_BIND_ACK is received the appended T_OK_ACK is sent to the TPI user.
* Should udp_bind_result 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_bind_ack */
else
/* The above return NULL if the bind needs to be deferred */
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_input 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.
*/
static void
{
int iph_hdr_length;
int error = 0;
udp_icmp_error_ipv6(q, mp);
return;
}
/* Skip past the outer IP and ICMP headers */
/* Skip past the inner IP and find the ULP header */
switch (icmph->icmph_type) {
case ICMP_DEST_UNREACHABLE:
switch (icmph->icmph_code) {
/*
* IP has already adjusted the path MTU.
*/
break;
case ICMP_PORT_UNREACHABLE:
break;
default:
/* Transient errors */
break;
}
break;
default:
/* Transient errors */
break;
}
if (error == 0) {
return;
}
/*
* Deliver T_UDERROR_IND when the application has asked for it.
* The socket layer enables this automatically when connected.
*/
if (!udp->udp_dgram_errind) {
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.
*/
static void
{
int error = 0;
else
return;
}
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;
}
/*
* Deliver T_UDERROR_IND when the application has asked for it.
* The socket layer enables this automatically when connected.
*/
if (!udp->udp_dgram_errind) {
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);
}
static int
{
}
static int
{
}
/*
* 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.
*/
/*ARGSUSED2*/
static int
{
int err;
netstack_t *ns;
/* If the stream is already open, return immediately. */
return (0);
return (EINVAL);
/*
* For exclusive stacks we set the zoneid to zero
* to make UDP operate as if in the global zone.
*/
else
} else {
/*
* Either minor numbers in the large arena were exhausted
* or a non socket application is doing the open.
* Try to allocate from the small arena.
*/
return (EBUSY);
}
}
/*
* ipcl_conn_create did a netstack_hold. Undo the hold that was
* done by netstack_find_by_cred()
*/
/*
* Initialize the udp_t structure for this stream.
*/
/* Set the initial state of the stream and the privilege status. */
if (isv6) {
} else {
}
/*
* If the caller has the process-wide flag set, then default to MAC
* exempt mode. This allows read-down to unlabeled hosts.
*/
if (flag & SO_SOCKSTR) {
}
qprocson(q);
/* Build initial header template for transmit */
qprocsoff(q);
return (err);
}
}
/* Set the Stream head write offset and high watermark. */
(void) mi_set_sth_wroff(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.
* It returns the size of the option retrieved.
*/
int
{
int len;
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_DHCPINIT_IF:
return (-EINVAL);
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_BROADCAST_TTL:
return (sizeof (uchar_t));
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;
case UDP_NAT_T_ENDPOINT:
break;
default:
return (-1);
}
break;
default:
return (-1);
}
return (sizeof (int));
}
int
{
int err;
return (err);
}
/*
* This routine sets socket options.
*/
/* ARGSUSED */
int
{
int error;
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(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:
/* Pass option along to IP level for handling */
return (-EINVAL);
case SO_MAC_EXEMPT:
/* Pass option along to IP level for handling */
return (-EINVAL);
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;
/*
* Update the stored options taking into account
* any CIPSO option which we should not overwrite.
*/
*outlenp = 0;
return (ENOMEM);
}
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:
case IP_DHCPINIT_IF:
/*
* "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_BROADCAST_TTL:
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:
IPPROTO_UDP)) != 0) {
*outlenp = 0;
return (error);
}
if (!checkonly) {
}
break;
case UDP_EXCLBIND:
if (!checkonly)
break;
case UDP_RCVHDR:
if (!checkonly)
break;
case UDP_NAT_T_ENDPOINT:
*outlenp = 0;
return (error);
}
/*
* Use udp_family instead so we can avoid ambiguitites
* with AF_INET6 sockets that may switch from IPv4
* to IPv6.
*/
*outlenp = 0;
return (EAFNOSUPPORT);
}
if (!checkonly) {
/* Also, adjust wroff */
if (onoff) {
udp->udp_max_hdr_len +=
sizeof (uint32_t);
}
(void) mi_set_sth_wroff(RD(q),
}
break;
default:
*outlenp = 0;
return (EINVAL);
}
break;
default:
*outlenp = 0;
return (EINVAL);
}
/*
* Common case of OK return with outval same as inval.
*/
}
return (0);
}
int
{
int err;
return (err);
}
/*
* 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);
}
/*
* 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);
}
/*
* Update udp_rcv_opt_len from the packet.
* Called when options received, and when no options received but
* udp_ip_recv_opt_len has previously recorded options.
*/
static void
{
/* Save the options if any */
if (opt_len > 0) {
/* Need to allocate larger buffer */
if (udp->udp_ip_rcv_options_len != 0)
udp->udp_ip_rcv_options_len = 0;
}
if (udp->udp_ip_rcv_options_len != 0) {
/* Adjust length if we are resusing the space */
}
} else if (udp->udp_ip_rcv_options_len != 0) {
/* Clear out previously recorded options */
udp->udp_ip_rcv_options_len = 0;
}
}
/* ARGSUSED2 */
static void
{
struct T_unitdata_ind *tudi;
int hdr_length; /* Length of IP+UDP headers */
int opt_len;
int udi_size; /* Size of T_unitdata_ind */
int mp_len;
int ipversion;
/*
* 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 prepended to the packet by IP. We need to
* extract the mblk and adjust the rptr
*/
options_mp = mp;
} else {
/*
* ICMP messages.
*/
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.
*/
/* Initialize regardless if ipversion is IPv4 or IPv6 */
ipp.ipp_fields = 0;
switch (ipversion) {
case IPV4_VERSION:
if ((opt_len > 0 || udp_ip_rcv_options_len > 0) &&
/*
* held. Not needed for AF_INET6 sockets
* since they don't support a getsockopt of IP_OPTIONS.
*/
opt_len);
}
/* Handle IPV6_RECVPKTINFO even for IPv4 packet. */
}
}
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
* to check if the size of the packet as specified
* by the header is the same as the physical size of the packet.
* FIXME? Didn't IP already check this?
*/
goto tossit;
}
/* Walk past the headers unless IP_RECVHDR was set. */
if (!udp_bits.udpb_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 source 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_bits.udpb_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 ((udp_bits.udpb_recvucred) &&
}
/*
* 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_bits.udpb_timestamp) {
sizeof (timestruc_t) + _POINTER_ALIGNMENT;
}
/*
* If IP_RECVTTL is set allocate the appropriate sized buffer
*/
if (udp_bits.udpb_recvttl) {
}
/* Allocate a message block for the T_UNITDATA_IND structure. */
if (options_mp != NULL)
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_bits.udpb_recvdstaddr) {
sizeof (ipaddr_t);
}
opt_len);
}
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_bits.udpb_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_bits.udpb_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.
*/
if ((udp_bits.udpb_ipv6_recvhopopts) &&
if (hlen == 0)
}
if (((udp_bits.udpb_ipv6_recvdstopts) ||
}
if ((((udp_bits.udpb_ipv6_recvdstopts) &&
}
if ((udp_bits.udpb_ipv6_recvrthdr) &&
}
if ((udp_bits.udpb_ip_recvpktinfo) &&
sizeof (struct in6_pktinfo);
}
}
if ((udp_bits.udpb_recvucred) &&
}
/*
* 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_bits.udpb_timestamp) {
sizeof (timestruc_t) + _POINTER_ALIGNMENT;
}
if (udp_bits.udpb_ipv6_recvhoplimit) {
}
if (udp_bits.udpb_ipv6_recvtclass) {
}
if (options_mp != NULL)
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_bits.udpb_ip_recvpktinfo) &&
struct in6_pktinfo *pkti;
sizeof (*pkti);
if (ipversion == IPV6_VERSION)
else
}
if (udp_bits.udpb_ipv6_recvhoplimit) {
sizeof (uint_t);
if (ipversion == IPV6_VERSION)
else
}
if (udp_bits.udpb_ipv6_recvtclass) {
sizeof (uint_t);
if (ipversion == IPV6_VERSION) {
} else {
}
}
if ((udp_bits.udpb_ipv6_recvhopopts) &&
}
if ((udp_bits.udpb_ipv6_recvdstopts) &&
}
if ((udp_bits.udpb_ipv6_recvrthdr) &&
}
if ((udp_bits.udpb_ipv6_recvdstopts) &&
}
}
if (udp_bits.udpb_timestamp) {
sizeof (timestruc_t) + _POINTER_ALIGNMENT;
/* Align for gethrestime() */
sizeof (intptr_t));
}
/* Consumed all of allocated space */
}
/* No IP_RECVDSTADDR for IPv6. */
}
if (options_mp != NULL)
if (udp_bits.udpb_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)
}
/*
* Handle the results of a T_BIND_REQ whether deferred by IP or handled
* immediately.
*/
static void
{
struct T_error_ack *tea;
case M_PROTO:
case M_PCPROTO:
/* M_PROTO messages contain some type of TPI message. */
return;
}
case T_ERROR_ACK:
switch (tea->ERROR_prim) {
case O_T_BIND_REQ:
case T_BIND_REQ:
return;
default:
break;
}
ASSERT(0);
return;
case T_BIND_ACK:
return;
default:
break;
}
return;
default:
/* FIXME: other cases? */
ASSERT(0);
return;
}
}
/*
* Process a T_BIND_ACK
*/
static void
{
struct T_bind_ack *tba;
ipa_conn_t *ac;
/*
* 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(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(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;
}
}
static void
{
struct T_error_ack *tea;
/*
* 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.
*/
switch (tea->ERROR_prim) {
case T_CONN_REQ:
/* Connect failed */
/* Revert back to the bound source */
(void) udp_build_hdrs(udp);
break;
case T_DISCON_REQ:
case T_BIND_REQ:
case O_T_BIND_REQ:
(void) udp_build_hdrs(udp);
break;
default:
"udp_input_other: bad ERROR_prim, "
}
}
/*
* return SNMP stuff in buffer in mpdata. We don't hold any lock and report
* information that can be changing beneath us.
*/
mblk_t *
{
int state;
int i;
int v4_conn_idx;
int v6_conn_idx;
/*
* make a copy of the original message
*/
return (0);
}
/* fixed length structure for IPv4 and IPv6 counters */
/* synchronize 64- and 32-bit counters */
sizeof (us->us_udp_mib));
v4_conn_idx = v6_conn_idx = 0;
for (i = 0; i < CONN_G_HASH_SIZE; i++) {
IPCL_UDPCONN))) {
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 (mp2ctl);
}
/*
* 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_UDPCONN))) {
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 (cl_inet_unbind != NULL) {
/*
* Running in cluster mode - register unbind information
*/
} else {
}
}
return;
}
/*
* Pass the unbind to IP; T_UNBIND_REQ is larger than T_OK_ACK
* and therefore ip_unbind must never return NULL.
*/
/*
* Once we're unbound from IP, the pending operation may be cleared
* here.
*/
(void) udp_build_hdrs(udp);
}
/*
* 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,
* or worse, UDP packets to same IP address may require
* different labels due to use of shared all-zones address.
* 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;
}
/*
* update label option for this UDP socket if
* - the destination has changed, or
* - the UDP socket is MLP
*/
goto done;
}
}
if (udp->udp_ip_snd_options_len > 0) {
}
/* Add an IP header */
(insert_spi ? sizeof (uint32_t) : 0);
"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 (ip_hdr_length == IP_SIMPLE_HDR_LENGTH) {
}
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;
/* Insert all-0s SPI now. */
if (insert_spi)
/*
* Copy in the destination address
*/
/*
* Set ttl based on IP_MULTICAST_TTL to match IPv6 logic.
*/
if (ip_snd_opt_len > 0) {
/*
* 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");
connp->conn_dontroute ||
optinfo.ip_opt_ill_index != 0 ||
&optinfo);
} else {
}
done:
if (lock_held)
if (*error != 0) {
}
return (mp);
}
static void
{
int err;
PHYI_LOOPBACK)) {
return;
}
}
}
if (!retry_caching) {
} else {
/* Release the old ire */
}
} else {
}
return;
}
/*
* IRE's created for non-connection oriented transports
* are normally initialized with IRE_MARK_TEMPORARY set
* in the ire_marks. These IRE's are preferentially
* reaped when the hash chain length in the cache
* bucket exceeds the maximum value specified in
* ip[6]_ire_max_bucket_cnt. This can severely affect
* UDP performance if IRE cache entries that we need
* to reuse are continually removed. To remedy this,
* when we cache the IRE in the conn_t, we remove the
* IRE_MARK_TEMPORARY bit from the ire_marks if it was
* set.
*/
irb->irb_tmp_ire_cnt--;
}
}
}
/*
* 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
*/
return;
}
else
}
}
static void
{
if (DEV_Q_IS_FLOW_CTLED(dev_q)) {
if (ipst->ips_ip_output_queue)
else
return;
}
#ifndef _BIG_ENDIAN
#endif
} 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 */
}
if (ilm_exists) {
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);
}
void
{
struct sockaddr_storage ss;
int error;
/* M_DATA for connected socket */
"udp_wput_end: connp %p (%S)", connp,
"not-connected; address required");
return;
}
if (mapped_addr)
/* Initialize addr and addrlen as if they're passed in */
} else {
sin6->sin6_scope_id = 0;
sin6->__sin6_src_id = 0;
}
if (mapped_addr) {
/*
* 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) {
return;
}
/* mp is freed by the following routine */
(t_scalar_t)error);
}
/*
* This routine handles all messages passed downstream. It either
* consumes the message or passes it downstream; it never queues a
* a message.
*
* Also 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 for the case of
* connected endpoints.
*/
void
{
int error = 0;
"udp_wput_start: queue %p mp %p", q, mp);
/*
* We directly handle several cases here: T_UNITDATA_REQ message
* socket.
*/
case M_DATA:
/*
* Quick check for error cases. Checks will be done again
* under the lock later on
*/
/* Not connected; address is required */
"udp_wput_end: connp %p (%S)", connp,
"not-connected; address required");
return;
}
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:
udp_wput_other(q, mp);
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);
}
}
/*
* 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
*/
&attrs) < 0) {
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,
* or worse, UDP packets to same IP address may require
* different labels due to use of shared all-zones address.
* 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;
}
/*
* update label option for this UDP socket if
* - the destination has changed, or
* - the UDP socket is MLP
*/
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 */
}
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:
if (sth_wroff != 0) {
(void) mi_set_sth_wroff(RD(q),
}
hopoptsptr = NULL;
}
if (*error != 0) {
}
return (mp);
}
static int
{
return (ENOTCONN);
switch (udp->udp_family) {
case AF_INET:
return (EINVAL);
break;
case AF_INET6:
return (EINVAL);
break;
}
return (0);
}
static int
{
switch (udp->udp_family) {
case AF_INET:
return (EINVAL);
/*
* If udp_v6src is unspecified, we might be bound to broadcast
* / multicast. Use udp_bound_v6src as local address instead
* (that could also still be unspecified).
*/
} else {
}
break;
case AF_INET6:
return (EINVAL);
/*
* If udp_v6src is unspecified, we might be bound to broadcast
* / multicast. Use udp_bound_v6src as local address instead
* (that could also still be unspecified).
*/
else
break;
}
return (0);
}
/*
* Handle special out-of-band ioctl requests (see PSARC/2008/265).
*/
static void
{
void *data;
return;
}
case TI_GETPEERNAME:
break;
case TI_GETMYNAME:
break;
default:
break;
}
}
static void
{
"udp_wput_other_start: q %p", q);
case M_CMD:
udp_wput_cmdblk(q, mp);
return;
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:
cr)) {
(void) svr4_optcom_req(q,
}
"udp_wput_other_end: q %p (%S)", q, "optmgmtreq");
return;
case T_OPTMGMT_REQ:
"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)", q,
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)", q,
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");
}
/*
* udp_wput_iocdata is called by udp_wput_other to handle all M_IOCDATA
* messages.
*/
static void
{
int error;
/* 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.
*/
return;
}
return;
case TI_GETMYNAME:
break;
case TI_GETPEERNAME:
break;
}
if (error != 0) {
} else {
/* Copy out the address */
mi_copyout(q, mp);
}
}
static int
{
struct T_unitdata_req *udreqp;
int is_absreq_failure;
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);
}
/*
* 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
{
/*
* 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);
}
/*
* For the lower queue so that UDP can be a dummy mux.
* Nobody should be sending
* packets up this stream
*/
static void
{
case M_FLUSH:
/* Turn around */
return;
}
break;
}
/* Could receive messages that passed through ar_rput */
}
/*
* For the lower queue so that UDP can be a dummy mux.
* Nobody should be sending packets down this stream.
*/
/* ARGSUSED */
void
{
}