icmp.c revision 19a8a986a692bc1fdeb3de480b5d435d2d13bede
/*
* 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. */
#define _SUN_TPI_VERSION 2
#include <sys/socketvar.h>
#include <sys/isa_defs.h>
#include <sys/xti_inet.h>
#include <sys/netstack.h>
#include <inet/proto_set.h>
#include <inet/kstatcom.h>
#include <inet/rawip_impl.h>
#include <netinet/ip_mroute.h>
#include <inet/ipsec_info.h>
#include <inet/ipclassifier.h>
/*
* Synchronization notes:
*
* RAWIP is MT and uses the usual kernel synchronization primitives. There is
* locks, which is icmp_rwlock. We also use conn_lock when updating things
* which affect the IP classifier lookup.
* The lock order is icmp_rwlock -> conn_lock.
*
* The icmp_rwlock:
* This protects most of the other fields in the icmp_t. The exact list of
* fields which are protected by each of the above locks is documented in
* the icmp_t structure definition.
*
* Plumbing notes:
* ICMP is always a device driver. For compatibility with mibopen() code
* it is possible to I_PUSH "icmp", but that results in pushing a passthrough
* dummy module.
*/
int sys_error);
static void icmp_input(void *, mblk_t *, void *);
int *errorp, void *thisdg_attrs);
static struct module_info icmp_mod_info = {
};
/*
* Entry points for ICMP as a device.
*/
static struct qinit icmprinitv4 = {
};
static struct qinit icmprinitv6 = {
};
};
/* ICMP entry point during fallback */
static struct qinit icmp_fallback_sock_winit = {
};
struct streamtab icmpinfov4 = {
};
struct streamtab icmpinfov6 = {
};
/* Default structure copied into T_INFO_ACK messages */
static struct T_info_ack icmp_g_t_info_ack = {
IP_MAXPACKET, /* TSDU_size. icmp allows maximum size messages. */
T_INVALID, /* ETSDU_size. icmp does not support expedited data. */
T_INVALID, /* CDATA_size. icmp does not support connect data. */
T_INVALID, /* DDATA_size. icmp does not support disconnect data. */
0, /* ADDR_size - filled in later. */
0, /* OPT_size - not initialized here */
IP_MAXPACKET, /* TIDU_size. icmp allows maximum size messages. */
T_CLTS, /* SERV_type. icmp supports connection-less. */
TS_UNBND, /* CURRENT_state. This is set from icmp_state. */
};
/*
* Table of ND variables supported by icmp. These are loaded into is_nd
* when the stack instance is created.
*/
static icmpparam_t icmp_param_arr[] = {
/* min max value name */
{ 0, 128, 32, "icmp_wroff_extra" },
{ 1, 255, 255, "icmp_ipv4_ttl" },
{ 0, 1, 1, "icmp_bsd_compat" },
{ 4096, 65536, 8192, "icmp_xmit_hiwat"},
{ 0, 65536, 1024, "icmp_xmit_lowat"},
{ 4096, 65536, 8192, "icmp_recv_hiwat"},
{ 65536, 1024*1024*1024, 256*1024, "icmp_max_buf"},
};
/*
* This routine is called to handle each O_T_BIND_REQ/T_BIND_REQ message
* passed to icmp_wput.
* The O_T_BIND_REQ/T_BIND_REQ is passed downstream to ip with the ICMP
* protocol type placed in the message following the address. A T_BIND_ACK
* message is returned by ip_bind_v4/v6.
*/
static void
{
int error;
struct T_bind_req *tbr;
"icmp_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;
}
/* Reset the message type in preparation for shipping it back. */
switch (len) {
case 0: /* request for a generic port */
} else {
}
break;
case sizeof (sin_t): /* Complete IPv4 address */
sizeof (sin_t));
break;
case sizeof (sin6_t): /* Complete IPv6 address */
break;
default:
return;
}
done:
if (error != 0) {
if (error > 0) {
} else {
}
} else {
}
}
static int
{
int error = 0;
return (EINVAL);
}
/*
* 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.
*/
goto done;
}
switch (len) {
case sizeof (sin_t): /* Complete IPv4 address */
/* TSYSERR, EAFNOSUPPORT */
goto done;
}
break;
case sizeof (sin6_t): /* Complete IPv6 address */
/* TSYSERR, EAFNOSUPPORT */
goto done;
}
/* No support for mapped addresses on raw sockets */
/* TSYSERR, EADDRNOTAVAIL */
goto done;
}
break;
default:
/* TBADADDR */
goto done;
}
/*
* Copy the source address into our icmp 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
* rawip_post_ip_bind_connect will clear the source address.
*/
&icmp->icmp_v6src);
} else {
int error;
/* Rebuild the header template */
if (error != 0) {
/*
* TSYSERR
*/
goto done;
}
}
/*
* request an IRE if src not 0 (INADDR_ANY)
*/
goto done;
}
}
done:
if (error != 0)
return (error);
} else {
}
return (error);
}
static void
{
/*
* not yet bound - bind sent by icmp_bind_proto.
*/
return;
}
if (error != 0) {
/* Connect failed */
/* Revert back to the bound source */
(void) icmp_build_hdrs(icmp);
} else {
(void) icmp_build_hdrs(icmp);
}
} else {
/*
* the source address to 0.
* This ensures no datagrams with broadcast address
* as source address are emitted (which would violate
* RFC1122 - Hosts requirements)
* Note: we get IRE_BROADCAST for IPv6
* to "mark" a multicast local address.
*/
/*
* This was just a local bind to a
*/
(void) icmp_build_hdrs(icmp);
}
}
}
}
/*
* Send message to IP to just bind to the protocol.
*/
static int
{
int error;
else
return (error);
}
static void
{
struct T_conn_req *tcr;
int error;
/* Sanity checks */
return;
}
if (tcr->OPT_length != 0) {
return;
}
switch (len) {
default:
return;
case sizeof (sin_t):
sizeof (sin_t));
break;
case sizeof (sin6_t):
break;
}
if (error != 0) {
return;
}
if (error != 0) {
if (error < 0) {
} else {
}
} else {
/*
* We have to send a connection confirmation to
* keep TLI happy.
*/
} else {
}
return;
}
/*
* Send ok_ack for T_CONN_REQ
*/
/* Unable to reuse the T_CONN_REQ for the ack. */
return;
}
}
}
static int
{
int error;
return (EINVAL);
}
return (ENOMEM);
return (-TOUTSTATE);
}
switch (len) {
case sizeof (sin_t):
/*
* Interpret a zero destination to mean loopback.
* generate the T_CONN_CON.
*/
if (v4dst == INADDR_ANY) {
}
/*
* 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.
*/
&icmp->icmp_v6src);
}
break;
case sizeof (sin6_t):
/* No support for mapped addresses on raw sockets */
return (EADDRNOTAVAIL);
}
/*
* Interpret a zero destination to mean loopback.
* generate the T_CONN_CON.
*/
}
/*
* 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).
*/
break;
}
/* Already connected - clear out state */
}
} else {
}
return (error);
}
static void
{
/* If there are any options associated with the stream, free them. */
icmp->icmp_ip_snd_options_len = 0;
}
}
/* Free memory associated with sticky options */
if (icmp->icmp_sticky_hdrs_len != 0) {
icmp->icmp_sticky_hdrs_len = 0;
}
/*
* Clear any fields which the kmem_cache constructor clears.
* Only icmp_connp needs to be preserved.
* TBD: We should make this more efficient to avoid clearing
* everything.
*/
}
static int
{
if (!IPCL_IS_NONSTR(connp)) {
}
/*
* 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.
*/
if (!IPCL_IS_NONSTR(connp)) {
} else {
}
return (0);
}
static int
{
if (flags & SO_FALLBACK) {
/*
* stream is being closed while in fallback
* simply free the resources that were allocated
*/
qprocsoff(q);
goto done;
}
(void) rawip_do_close(connp);
done:
return (0);
}
/*
* This routine handles each T_DISCON_REQ message passed to icmp
* as an indicating that ICMP is no longer connected. This results
* in sending a T_BIND_REQ to IP to restore the binding to just
* the local address.
*
* The disconnect completes in rawip_post_ip_bind_connect.
*/
static int
{
int error;
return (-TOUTSTATE);
}
/* Rebuild the header template */
if (error != 0) {
return (error);
}
}
return (ENOMEM);
}
} else {
}
return (error);
}
static void
{
int error;
/*
* Allocate the largest primitive we need to send back
* T_error_ack is > than T_ok_ack
*/
/* Unable to reuse the T_DISCON_REQ for the ack. */
return;
}
if (error != 0) {
if (error > 0) {
} else {
}
} else {
}
}
static int
{
int error;
if (error < 0)
return (error);
}
/* 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
{
struct T_error_ack *teackp;
}
}
/*
* icmp_icmp_error is called by icmp_input to process ICMP
* messages passed up by IP.
* Generates the appropriate 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;
return;
}
/*
* icmp does not support v4 mapped addresses
* so we can never be here for a V6 socket
* i.e. icmp_family == AF_INET6
*/
/* Skip past the outer IP and ICMP headers */
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 (!icmp->icmp_dgram_errind) {
return;
}
if (IPCL_IS_NONSTR(connp)) {
goto done;
}
} else {
}
} else {
0, error);
}
done:
}
/*
* icmp_icmp_error_ipv6 is called by icmp_icmp_error to process ICMPv6
* for IPv6 packets.
* Send permanent (non-transient) errors upstream.
* 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 (!icmp->icmp_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.
*/
if (!IPCL_IS_NONSTR(connp)) {
} else {
NULL);
}
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 (!icmp->icmp_dgram_errind) {
return;
}
if (IPCL_IS_NONSTR(connp)) {
goto done;
}
} else {
}
} else {
}
done:
}
/*
* This routine responds to T_ADDR_REQ messages. It is called by icmp_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
*/
/* Fill zeroes and then intialize non-zero fields */
} else {
/*
* INADDR_ANY
* icmp_v6src is not set, we might be bound to
* local address instead (that could
* also still be INADDR_ANY)
*/
}
} else {
/* Fill zeroes and then intialize non-zero fields */
} else {
/*
* UNSPECIFIED
* icmp_v6src is not set, we might be bound to
* local address instead (that could
* also still be UNSPECIFIED)
*/
}
}
}
}
static void
{
*tap = icmp_g_t_info_ack;
else
}
static void
{
}
}
/*
* This routine responds to T_CAPABILITY_REQ messages. It is called by
* icmp_wput. Much of the T_CAPABILITY_ACK information is copied from
* icmp_g_t_info_ack. The current state of the stream is copied from
* icmp_state.
*/
static void
{
struct T_capability_ack *tcap;
if (!mp)
return;
}
/*
* This routine responds to T_INFO_REQ messages. It is called by icmp_wput.
* Most of the T_INFO_ACK information is copied from icmp_g_t_info_ack.
* The current state of the stream is copied from icmp_state.
*/
static void
{
if (!mp)
return;
}
static int
int family)
{
int error;
/* If the stream is already open, return immediately. */
return (0);
return (EINVAL);
/*
* Since ICMP is not used so heavily, allocating from the small
* arena should be sufficient.
*/
return (EBUSY);
}
if (flag & SO_FALLBACK) {
/*
* Non streams socket needs a stream to fallback to
*/
qprocson(q);
return (0);
}
return (error);
}
/*
* Initialize the icmp_t structure for this stream.
*/
/* Build initial header template for transmit */
return (error);
}
}
qprocson(q);
/* Set the Stream head write offset. */
(void) proto_set_tx_wroff(q, connp,
return (0);
}
static int
{
}
static int
{
}
/*
* This is the open routine for icmp. It allocates a icmp_t structure for
* the stream and, on the first open of the module, creates an ND table.
*/
/* ARGSUSED */
static conn_t *
{
netstack_t *ns;
if (*err != 0)
return (NULL);
/*
* For exclusive stacks we set the zoneid to zero
* to make ICMP operate as if in the global zone.
*/
else
/*
* ipcl_conn_create did a netstack_hold. Undo the hold that was
* done by netstack_find_by_cred()
*/
/* Set the initial state of the stream and the privilege status. */
if (isv6) {
/* May be changed by a SO_PROTOTYPE socket option. */
} else {
/* May be changed by a SO_PROTOTYPE socket option. */
}
/*
* If the caller has the process-wide flag set, then default to MAC
* exempt mode. This allows read-down to unlabeled hosts.
*/
return (connp);
}
/*
* Which ICMP 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;
case IPPROTO_ICMPV6:
switch (name) {
case ICMP6_FILTER:
/* Make it look like "pass all" */
return (sizeof (icmp6_filter_t));
}
break;
}
return (-1);
}
/*
* This routine retrieves the current status of socket options.
* It returns the size of the option retrieved.
*/
int
{
int ret = 0;
switch (level) {
case SOL_SOCKET:
switch (name) {
case SO_DEBUG:
break;
case SO_TYPE:
break;
case SO_PROTOTYPE:
break;
case SO_REUSEADDR:
break;
/*
* The following three items are available here,
* but are only meaningful to IP.
*/
case SO_DONTROUTE:
break;
case SO_USELOOPBACK:
break;
case SO_BROADCAST:
break;
case SO_SNDBUF:
break;
case SO_RCVBUF:
break;
case SO_DGRAM_ERRIND:
break;
case SO_TIMESTAMP:
break;
case SO_MAC_EXEMPT:
break;
case SO_DOMAIN:
break;
/*
* Following four not meaningful for icmp
* Action is same as "default" to which we fallthrough
* so we keep them in comments.
* case SO_LINGER:
* case SO_KEEPALIVE:
* case SO_OOBINLINE:
* case SO_ALLZONES:
*/
default:
ret = -1;
goto done;
}
break;
case IPPROTO_IP:
/*
* Only allow IPv4 option processing on IPv4 sockets.
*/
ret = -1;
goto done;
}
switch (name) {
case IP_OPTIONS:
case T_IP_OPTIONS:
/* Options are passed up with each packet */
ret = 0;
goto done;
case IP_HDRINCL:
break;
case IP_TOS:
case T_IP_TOS:
break;
case IP_TTL:
break;
case IP_MULTICAST_IF:
/* 0 address if not set */
goto done;
case IP_MULTICAST_TTL:
goto done;
case IP_MULTICAST_LOOP:
goto done;
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_RECVIF:
break; /* goto sizeof (int) option return */
case IP_BROADCAST_TTL:
return (sizeof (uchar_t));
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.
*/
goto done;
/*
* Cannot "get" the value of following options
* at this level. Action is same as "default" to
* which we fallthrough so we keep them in comments.
*
* case IP_ADD_MEMBERSHIP:
* case IP_DROP_MEMBERSHIP:
* case IP_BLOCK_SOURCE:
* case IP_UNBLOCK_SOURCE:
* case IP_ADD_SOURCE_MEMBERSHIP:
* case IP_DROP_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 MRT_INIT:
* case MRT_DONE:
* case MRT_ADD_VIF:
* case MRT_DEL_VIF:
* case MRT_ADD_MFC:
* case MRT_DEL_MFC:
* case MRT_VERSION:
* case MRT_ASSERT:
* case IP_SEC_OPT:
* case IP_DONTFAILOVER_IF:
* case IP_NEXTHOP:
*/
default:
ret = -1;
goto done;
}
break;
case IPPROTO_IPV6:
/*
* Only allow IPv6 option processing on native IPv6 sockets.
*/
ret = -1;
goto done;
}
switch (name) {
case IPV6_UNICAST_HOPS:
break;
case IPV6_MULTICAST_IF:
/* 0 index if not set */
break;
case IPV6_MULTICAST_HOPS:
break;
case IPV6_MULTICAST_LOOP:
break;
case IPV6_BOUND_IF:
/* Zero if not set */
break;
case IPV6_UNSPEC_SRC:
break;
case IPV6_CHECKSUM:
/*
* Return offset or -1 if no checksum offset.
* Does not apply to IPPROTO_ICMPV6
*/
ret = -1;
goto done;
}
if (icmp->icmp_raw_checksum) {
} else {
*i1 = -1;
}
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:
/* cannot "get" the value for these */
ret = -1;
goto done;
case IPV6_RECVPKTINFO:
break;
case IPV6_RECVTCLASS:
break;
case IPV6_RECVPATHMTU:
break;
case IPV6_V6ONLY:
*i1 = 1;
break;
case IPV6_RECVHOPLIMIT:
break;
case IPV6_RECVHOPOPTS:
break;
case IPV6_RECVDSTOPTS:
break;
case _OLD_IPV6_RECVDSTOPTS:
break;
case IPV6_RECVRTHDRDSTOPTS:
break;
case IPV6_RECVRTHDR:
break;
case IPV6_PKTINFO: {
/* XXX assumes that caller has room for max size! */
struct in6_pktinfo *pkti;
else
pkti->ipi6_ifindex = 0;
else
ret = sizeof (struct in6_pktinfo);
goto done;
}
case IPV6_NEXTHOP: {
return (0);
goto done;
}
case IPV6_HOPOPTS:
return (0);
return (0);
if (icmp->icmp_label_len_v6 > 0) {
}
goto done;
case IPV6_RTHDRDSTOPTS:
return (0);
goto done;
case IPV6_RTHDR:
return (0);
goto done;
case IPV6_DSTOPTS:
ret = 0;
goto done;
}
goto done;
case IPV6_PATHMTU:
ret = 0;
} else {
(struct ip6_mtuinfo *)ptr,
is->is_netstack);
}
goto done;
case IPV6_TCLASS:
else
*i1 = IPV6_FLOW_TCLASS(
break;
default:
ret = -1;
goto done;
}
break;
case IPPROTO_ICMPV6:
/*
* Only allow IPv6 option processing on native IPv6 sockets.
*/
ret = -1;
}
ret = -1;
}
switch (name) {
case ICMP6_FILTER:
/* Make it look like "pass all" */
} else {
sizeof (icmp6_filter_t));
}
ret = sizeof (icmp6_filter_t);
goto done;
default:
ret = -1;
goto done;
}
default:
ret = -1;
goto done;
}
ret = sizeof (int);
done:
return (ret);
}
/*
* This routine retrieves the current status of socket options.
* It returns the size of the option retrieved.
*/
int
{
int err;
return (err);
}
int
{
int error;
/*
* 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_DEBUG:
if (!checkonly)
break;
case SO_PROTOTYPE:
secpolicy_net_rawaccess(cr) != 0) {
*outlenp = 0;
return (EACCES);
}
/* Can't use IPPROTO_RAW with IPv6 */
*outlenp = 0;
return (EPROTONOSUPPORT);
}
if (checkonly) {
/* T_CHECK case */
break;
}
else
icmp->icmp_hdrincl = 0;
/* Set offset for icmp6_cksum */
icmp->icmp_raw_checksum = 0;
}
} else {
icmp->icmp_no_tp_cksum = 0;
}
sizeof (icmp6_filter_t));
}
/* Rebuild the header template */
if (error != 0) {
*outlenp = 0;
return (error);
}
/*
* For SCTP, we don't use icmp_bind_proto() for
* raw socket binding. Note that we do not need
* to set *outlenp.
* FIXME: how does SCTP work?
*/
return (0);
*outlenp = sizeof (int);
/* Drop lock across the bind operation */
(void) icmp_bind_proto(connp);
return (0);
case SO_REUSEADDR:
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) {
if (!IPCL_IS_NONSTR(connp)) {
}
}
break;
case SO_RCVBUF:
*outlenp = 0;
return (ENOBUFS);
}
if (!checkonly) {
*i1);
}
break;
case SO_DGRAM_ERRIND:
if (!checkonly)
break;
case SO_ALLZONES:
/*
* "soft" error (negative)
* option not handled at this level
* Note: Do not modify *outlenp
*/
return (-EINVAL);
case SO_TIMESTAMP:
if (!checkonly) {
}
break;
case SO_MAC_EXEMPT:
/*
* "soft" error (negative)
* option not handled at this level
* Note: Do not modify *outlenp
*/
return (-EINVAL);
/*
* Following three not meaningful for icmp
* Action is same as "default" so we keep them
* in comments.
* case SO_LINGER:
* case SO_KEEPALIVE:
* case SO_OOBINLINE:
*/
default:
*outlenp = 0;
return (EINVAL);
}
break;
case IPPROTO_IP:
/*
* Only allow IPv4 option processing on IPv4 sockets.
*/
*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;
*outlenp = 0;
return (ENOMEM);
}
break;
case IP_HDRINCL:
if (!checkonly)
break;
case IP_TOS:
case T_IP_TOS:
if (!checkonly) {
}
break;
case IP_TTL:
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) {
(*invalp == 0) ? 0 : 1;
}
break;
case IP_BOUND_IF:
if (!checkonly) {
}
break;
case IP_UNSPEC_SRC:
if (!checkonly) {
}
break;
case IP_BROADCAST_TTL:
if (!checkonly)
break;
case IP_RECVIF:
if (!checkonly) {
}
/*
* pass to ip
*/
return (-EINVAL);
case IP_PKTINFO: {
/*
* This also handles IP_RECVPKTINFO.
* IP_PKTINFO and IP_RECVPKTINFO have the 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 wether this option is
* set or not and pass it down to IP for
* processing.
*/
return (-EINVAL);
}
if (inlen != sizeof (struct in_pktinfo)) {
return (EINVAL);
}
== NULL) {
/*
* sticky option is not supported
*/
return (EINVAL);
}
/*
* Atleast 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 MRT_INIT:
case MRT_DONE:
case MRT_ADD_VIF:
case MRT_DEL_VIF:
case MRT_ADD_MFC:
case MRT_DEL_MFC:
case MRT_VERSION:
case MRT_ASSERT:
case IP_SEC_OPT:
case IP_DONTFAILOVER_IF:
case IP_NEXTHOP:
/*
* "soft" error (negative)
* option not handled at this level
* Note: Do not modify *outlenp
*/
return (-EINVAL);
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_CHECKSUM:
/*
* Integer offset into the user data of where the
* checksum is located.
* Offset of -1 disables option.
* Does not apply to IPPROTO_ICMPV6.
*/
*outlenp = 0;
return (EINVAL);
}
/* Negative or not 16 bit aligned offset */
*outlenp = 0;
return (EINVAL);
}
if (checkonly)
break;
if (*i1 == -1) {
icmp->icmp_raw_checksum = 0;
} else {
}
/* Rebuild the header template */
if (error != 0) {
*outlenp = 0;
return (error);
}
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;
case IPV6_RECVTCLASS:
if (!checkonly) {
}
break;
/*
* Set boolean switches for ancillary data delivery
*/
case IPV6_RECVPKTINFO:
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.
*/
sizeof (struct in6_pktinfo)) {
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:
/* This option can only be used as ancillary data. */
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:
/*
* IPV6_RECVTCLASS accepts -1 as use kernel default
* and [0, 255] as the actualy traffic class.
*/
return (EINVAL);
}
if (checkonly)
break;
if (inlen == 0) {
} else {
return (EINVAL);
if (*i1 == -1) {
ipp->ipp_tclass =
} 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);
}
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;
/*
* This option can't be set. Its only returned via
* getsockopt() or ancillary data.
*/
case IPV6_PATHMTU:
return (EINVAL);
case IPV6_BOUND_PIF:
case IPV6_SEC_OPT:
case IPV6_DONTFAILOVER_IF:
case IPV6_SRC_PREFERENCES:
case IPV6_V6ONLY:
/* Handled at IP level */
return (-EINVAL);
default:
*outlenp = 0;
return (EINVAL);
}
break;
} /* end IPPROTO_IPV6 */
case IPPROTO_ICMPV6:
/*
* Only allow IPv6 option processing on IPv6 sockets.
*/
*outlenp = 0;
return (ENOPROTOOPT);
}
*outlenp = 0;
return (ENOPROTOOPT);
}
switch (name) {
case ICMP6_FILTER:
if (!checkonly) {
if ((inlen != 0) &&
(inlen != sizeof (icmp6_filter_t)))
return (EINVAL);
if (inlen == 0) {
sizeof (icmp6_filter_t));
}
} else {
sizeof (icmp6_filter_t),
*outlenp = 0;
return (ENOBUFS);
}
}
inlen);
}
}
break;
default:
*outlenp = 0;
return (EINVAL);
}
break;
default:
*outlenp = 0;
return (EINVAL);
}
/*
* Common case of OK return with outval same as inval.
*/
}
return (0);
}
/* This routine sets socket options. */
/* ARGSUSED */
int
{
int error;
error = 0;
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;
error = 0;
goto done;
}
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;
goto done;
}
break;
default:
/*
* We should never get here
*/
*outlenp = 0;
goto done;
}
done:
return (error);
}
/* This routine sets socket options. */
/* ARGSUSED */
int
{
int error;
return (error);
}
/*
* Update icmp_sticky_hdrs based on icmp_sticky_ipp, icmp_v6src, icmp_ttl,
* icmp_proto, icmp_raw_checksum and icmp_no_tp_cksum.
* The headers include ip6i_t (if needed), ip6_t, and any sticky extension
* headers.
* Returns failure if can't allocate memory.
*/
static int
{
/* Need to reallocate */
if (hdrs_len != 0) {
return (ENOMEM);
} else {
}
if (icmp->icmp_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 icmpparam_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);
}
}
}
NULL)) {
return (B_FALSE);
}
return (B_TRUE);
}
/* This routine sets an ND variable in a icmpparam_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
{
/*
* fallback has started but messages have not been moved yet
*/
} else {
}
} else {
/*
* no more fallbacks possible, ok to drop lock.
*/
}
}
/*ARGSUSED2*/
static void
{
struct T_unitdata_ind *tudi;
int hdr_len;
int udi_size; /* Size of T_unitdata_ind */
int error;
/*
* 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
*/
/*
* FIXME: does IP still do this?
* IP sends up the IPSEC_IN message for handling IPSEC
* policy at the TCP level. We don't need it here.
*/
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;
}
}
/*
* Discard message if it is misaligned or smaller than the IP header.
*/
if (options_mp != NULL)
return;
}
/* Handle M_DATA messages containing IP packets messages */
if (ipvers == IPV4_VERSION) {
/*
* Special case where IP attaches
* the IRE needs to be handled so that we don't send up
* IRE to the user land.
*/
}
}
}
if (is->is_bsd_compat) {
/*
* Allocate a new IP header so that we can
* modify ipha_length.
*/
if (!mp1) {
if (options_mp != NULL)
return;
}
}
}
}
/*
* This is the inbound data path. Packets are passed upstream as
* T_UNITDATA_IND messages with full IP headers still attached.
*/
sizeof (uint_t);
}
sizeof (struct in_pktinfo);
}
/*
* 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 (icmp->icmp_timestamp) {
sizeof (timestruc_t) + _POINTER_ALIGNMENT;
}
if (options_mp != NULL)
return;
}
sizeof (sin_t);
/*
* Add options if IP_RECVIF is set
*/
if (udi_size != 0) {
char *dstopt;
sizeof (uint_t);
}
if (icmp->icmp_timestamp) {
sizeof (timestruc_t) + _POINTER_ALIGNMENT;
/* Align for gethrestime() */
sizeof (intptr_t));
}
struct in_pktinfo *pktinfop;
sizeof (in_pktinfo_t);
dstopt += sizeof (struct in_pktinfo);
}
/* Consumed all of allocated space */
}
if (options_mp != NULL)
goto deliver;
}
/*
* We don't need options_mp in the IPv6 path.
*/
if (options_mp != NULL) {
options_mp = NULL;
}
/*
* Discard message if it is smaller than the IPv6 header
* or if the header is malformed.
*/
return;
}
/* Initialize */
ipp.ipp_fields = 0;
hopstrip = 0;
/*
* Call on ip_find_hdr_v6 which gets the total hdr len
* as well as individual lenghts of ext hdrs (and ptrs to
* them).
*/
/* Look for ifindex information */
}
}
}
/*
* We need to lie a bit to the user because users inside
* labeled compartments should not see their own labels. We
* assume that in all other respects IP has checked the label,
* and that the label is always first among the options. (If
* it's not first, then this code won't see it, and the option
* will be passed along to the user.)
*
* If we had multilevel ICMP sockets, then the following code
* should be skipped for them to allow the user to see the
* label.
*
* Alignment restrictions in the definition of IP options
* (namely, the requirement that the 4-octet DOI goes on a
* 4-octet boundary) mean that we know exactly where the option
* should start, but we're lenient for other hosts.
*
* Note that there are no multilevel ICMP or raw IP sockets
* yet, thus nobody ever sees the IP6OPT_LS option.
*/
while (remlen > 0) {
if (*ucp == IP6OPT_PAD1) {
remlen--;
ucp++;
} else if (*ucp == IP6OPT_PADN) {
break;
} else {
/* label option must be first */
break;
}
}
}
} else {
}
/*
* One special case where IP attaches the IRE needs to
* be handled so that we don't send up IRE to the user land.
*/
if (nexthdr == IPPROTO_TCP) {
}
}
}
/*
* Check a filter for ICMPv6 types if needed.
* Verify raw checksums if needed.
*/
int type;
/* Assumes that IP has done the pullupmsg */
return;
}
} else {
/* Checksum */
int remlen;
if (sum != 0) {
/* IPv6 RAW checksum failed */
ip0dbg(("icmp_rput: RAW checksum "
"failed %x\n", sum));
return;
}
}
}
/* Skip all the IPv6 headers per API */
/*
* We use local variables icmp_opt and icmp_ipv6_recvhoplimit to
* maintain state information, instead of relying on icmp_t
* structure, since there arent any locks protecting these members
* and there is a window where there might be a race between a
* thread setting options on the write side and a thread reading
* these options on the read size.
*/
if (icmp->icmp_ipv6_recvhopopts &&
icmp_opt |= IPPF_HOPOPTS;
}
if ((icmp->icmp_ipv6_recvdstopts ||
icmp_opt |= IPPF_DSTOPTS;
}
if (((icmp->icmp_ipv6_recvdstopts &&
}
if (icmp->icmp_ipv6_recvrthdr &&
icmp_opt |= IPPF_RTHDR;
}
if (icmp->icmp_ip_recvpktinfo &&
sizeof (struct in6_pktinfo);
icmp_opt |= IPPF_IFINDEX;
}
}
if (icmp->icmp_ipv6_recvhoplimit) {
}
if (icmp->icmp_ipv6_recvtclass)
/*
* 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 (icmp->icmp_timestamp) {
sizeof (timestruc_t) + _POINTER_ALIGNMENT;
}
return;
}
/* 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 (icmp_opt & IPPF_IFINDEX) {
struct in6_pktinfo *pkti;
sizeof (*pkti);
}
if (icmp_ipv6_recvhoplimit) {
sizeof (uint_t);
}
if (icmp->icmp_ipv6_recvtclass) {
sizeof (uint_t);
}
if (icmp->icmp_timestamp) {
sizeof (timestruc_t) + _POINTER_ALIGNMENT;
/* Align for gethrestime() */
sizeof (intptr_t));
}
if (icmp_opt & IPPF_HOPOPTS) {
if (hopstrip > 0) {
/* copy next header value and fake length */
hopstrip / 8;
}
}
if (icmp_opt & IPPF_RTDSTOPTS) {
}
if (icmp_opt & IPPF_RTHDR) {
}
if (icmp_opt & IPPF_DSTOPTS) {
}
/* Consumed all of allocated space */
}
if (IPCL_IS_NONSTR(connp)) {
NULL) < 0) {
/*
* let's confirm while holding the lock
*/
} else {
}
}
} else {
}
}
} else {
}
}
/*
* return SNMP stuff in buffer in mpdata
*/
mblk_t *
{
/*
* make a copy of the original message
*/
return (0);
}
/* fixed length structure for IPv4 and IPv6 counters */
sizeof (is->is_rawip_mib));
return (mp2ctl);
}
/*
* Return 0 if invalid set request, 1 otherwise, including non-rawip requests.
* TODO: If this ever actually tries to set anything, it needs to be
* to do the appropriate locking.
*/
/* ARGSUSED */
int
{
switch (level) {
case EXPER_RAWIP:
return (0);
default:
return (1);
}
}
/* Report for ndd "icmp_status" */
/* ARGSUSED */
static int
{
char laddrbuf[INET6_ADDRSTRLEN];
char faddrbuf[INET6_ADDRSTRLEN];
int i;
(void) mi_mpprintf(mp,
"RAWIP " MI_COL_HDRPAD_STR
/* 01234567[89ABCDEF] */
" src addr dest addr state");
/* xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx UNBOUND */
for (i = 0; i < CONN_G_HASH_SIZE; i++) {
char *state;
IPCL_RAWIPCONN)) != NULL) {
state = "UNBOUND";
state = "IDLE";
state = "CONNECTED";
else
state = "UnkState";
(void *)icmp,
sizeof (faddrbuf)),
sizeof (laddrbuf)),
state);
}
}
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
{
if (mp1)
}
static int
{
/* If a bind has not been done, we can't unbind. */
return (-TOUTSTATE);
}
/*
* Call ip to unbind
*/
/*
* Once we're unbound from IP, the pending operation may be cleared
* here.
*/
(void) icmp_build_hdrs(icmp);
return (0);
}
/*
* This routine is called by icmp_wput to handle T_UNBIND_REQ messages.
* After some error checking, the message is passed downstream to ip.
*/
static void
{
int error;
if (error) {
if (error < 0) {
} else {
}
return;
}
/*
* Convert mp into a T_OK_ACK
*/
/*
* should not happen in practice... T_OK_ACK is smaller than the
* original message.
*/
}
/*
* Process IPv4 packets that already include an IP header.
* Used when IP_HDRINCL has been set (implicit for IPPROTO_RAW and
* IPPROTO_IGMP).
*/
static int
{
int ip_hdr_length;
int tp_hdr_len;
optinfo.ip_opt_flags = 0;
optinfo.ip_opt_ill_index = 0;
return (0);
}
}
/*
* For the socket of SOCK_RAW type, the checksum is provided in the
* pre-built packet. We set the ipha_ident field to IP_HDR_INCLUDED to
* tell IP that the application has sent a complete IP header and not
* to compute the transport checksum nor change the DF flag.
*/
ipha->ipha_hdr_checksum = 0;
/* Insert options if any */
if (ip_hdr_length > IP_SIMPLE_HDR_LENGTH) {
/*
* Put the IP header plus any transport header that is
* checksumed by ip_wput into the first mblk. (ip_wput assumes
* that at least the checksum field is in the first mblk.)
*/
switch (ipha->ipha_protocol) {
case IPPROTO_UDP:
tp_hdr_len = 8;
break;
case IPPROTO_TCP:
tp_hdr_len = 20;
break;
default:
tp_hdr_len = 0;
break;
}
/*
* The code below assumes that IP_SIMPLE_HDR_LENGTH plus
* tp_hdr_len bytes will be in a single mblk.
*/
tp_hdr_len)) {
tp_hdr_len)) {
return (0);
}
}
/*
* if the length is larger then the max allowed IP packet,
* then send an error and abort the processing.
*/
if (pkt_len > IP_MAXPACKET) {
return (EMSGSIZE);
}
tp_hdr_len, BPRI_LO))) {
return (ENOMEM);
}
/* Copy transport header if any */
/* Add options */
/* Drop IP header and transport header from original */
/*
* Massage source route putting first source
* route in ipha_dst.
*/
}
/*
* Over write the source address provided in the header
*/
}
if (pktinfop->ip4_ill_index != 0) {
}
}
return (0);
}
static int
{
int err;
if (err == 0) {
}
if (err != 0) {
char *, "icmp(1) failed to update options(2) on mp(3)",
return (err);
}
return (0);
}
/*
* 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;
ipp->ipp_fields = 0;
ipp->ipp_sticky_ignored = 0;
case M_DATA:
if (icmp->icmp_hdrincl) {
return;
}
}
/*
* If this connection was used for v6 (inconceivable!)
* or if we have a new destination, then it's time to
* figure a new label.
*/
if (is_system_labeled() &&
if (error != 0) {
return;
}
}
if (error != 0)
return;
}
return;
case M_PROTO:
case M_PCPROTO:
if (ip_len >= sizeof (struct T_unitdata_req)) {
/* Expedite valid T_UNITDATA_REQ to below the switch */
== T_UNITDATA_REQ)
break;
}
/* FALLTHRU */
default:
icmp_wput_other(q, mp);
return;
}
/* Handle T_UNITDATA_REQ messages here. */
return;
}
return;
}
switch (icmp->icmp_family) {
case AF_INET6:
return;
}
/* No support for mapped addresses on raw sockets */
return;
}
/*
* Destination is a native IPv6 address.
* Send out an IPv6 format packet.
*/
if (tudr->OPT_length != 0) {
int error;
error = 0;
(void *)ipp) < 0) {
/* failure */
return;
}
}
goto done;
case AF_INET:
return;
}
/* Extract and ipaddr */
break;
default:
ASSERT(0);
}
pktinfop->ip4_ill_index = 0;
/*
* If options passed in, feed it for verification and handling
*/
if (tudr->OPT_length != 0) {
int error;
error = 0;
(void *)pktinfop) < 0) {
/* failure */
return;
}
/*
* Note: Success in processing options.
* mp option buffer represented by
* OPT_length/offset now potentially modified
* and contain option setting results
*/
}
done:
if (error != 0) {
return;
} else {
}
}
/* ARGSUSED */
static void
{
#ifdef DEBUG
#endif
}
static int
{
int ip_hdr_length;
optinfo.ip_opt_flags = 0;
optinfo.ip_opt_ill_index = 0;
/* If a port has not been bound to the stream, fail. */
return (EPROTO);
}
if (v4dst == INADDR_ANY)
/* Check if our saved options are valid; update if not */
if (is_system_labeled() &&
if (error != 0)
return (error);
}
/* Protocol 255 contains full IP headers */
if (icmp->icmp_hdrincl)
/* Add an IP header */
BPRI_LO))) {
return (ENOMEM);
}
}
#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,
* ip will fill in the real source address.
*/
}
if (pktinfop->ip4_ill_index != 0) {
}
/*
* For the socket of SOCK_RAW type, the checksum is provided in the
* pre-built packet. We set the ipha_ident field to IP_HDR_INCLUDED to
* tell IP that the application has sent a complete IP header and not
* to compute the transport checksum nor change the DF flag.
*/
/* Finish common formatting of the packet. */
/*
* Set the length into the IP header.
* If the length is greater than the maximum allowed by IP,
* then free the message and return. Do not try and send it
* as this can cause problems in layers below.
*/
if (ip_len > IP_MAXPACKET) {
return (EMSGSIZE);
}
/*
* Copy in the destination address request
*/
/*
* Set ttl based on IP_MULTICAST_TTL to match IPv6 logic.
*/
/* Copy in options if any */
if (ip_hdr_length > IP_SIMPLE_HDR_LENGTH) {
/*
* Massage source route putting first source route in ipha_dst.
* Ignore the destination in the T_unitdata_req.
*/
}
return (0);
}
static int
{
int err;
if (err == 0) {
}
if (err != 0) {
char *, "icmp(1) failed to update options(2) on mp(3)",
return (err);
}
return (0);
}
/*
* raw_ip_send_data_v6():
* Assumes that icmp_wput did some sanity checking on the destination
* address, but that the label may not yet be correct.
*/
static int
{
int ip_hdr_len = IPV6_HDR_LEN;
/*
* 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.
*/
return (EADDRNOTAVAIL);
}
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.
*/
if (is_system_labeled() &&
int error = 0;
if (error != 0)
return (error);
}
/*
* 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.
*/
if (icmp->icmp_label_len_v6 > 0) {
ignore &= ~IPPF_HOPOPTS;
}
(ipp->ipp_fields == 0)) {
/* 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;
}
}
/*
* Need to have a router header to use these.
*/
ip_hdr_len +=
}
}
if (!(ignore & IPPF_DSTOPTS)) {
}
}
if (!(ignore & IPPF_IFINDEX)) {
}
}
}
}
if (!(ignore & IPPF_DONTFRAG)) {
}
}
if (!(ignore & IPPF_USE_MIN_MTU)) {
}
}
if (!(ignore & IPPF_NEXTHOP)) {
}
}
/* IPV6_HOPLIMIT can never be sticky */
if (!(ignore & IPPF_UNICAST_HOPS) &&
}
if (!(ignore & IPPF_MULTICAST_HOPS) &&
}
/* This is a sticky socket option only */
}
/* This is a sticky socket option only */
}
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)
ip_hdr_len += sizeof (ip6i_t);
/* Try to get everything in a single mblk next time */
}
if (!mp1) {
return (ENOMEM);
}
}
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_RAW_CKSUM) {
}
if (option_exists & IPPF_NO_CKSUM) {
}
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 &&
is->is_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 */
}
/*
* 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
*/
/*
* 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.
*/
return (EPROTO);
}
/*
* rth->ip6r_len is twice the number of
* addresses in the header
*/
return (EPROTO);
}
/*
* 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).
*/
is->is_netstack);
/*
* Verify that the first hop isn't a mapped address.
* Routers along the path need to do this verification
* for subsequent hops.
*/
return (EADDRNOTAVAIL);
}
}
}
/*
* Set the length into the IP header.
* If the length is greater than the maximum allowed by IP,
* then free the message and return. Do not try and send it
* as this can cause problems in layers below.
*/
if (ip_len > IP_MAXPACKET) {
return (EMSGSIZE);
}
/* ICMPv6 must have an offset matching icmp6_cksum offset */
/*
* 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: ICMPv6 must always checksum the packet.
*/
return (0);
}
else
}
/* Add payload length to checksum */
}
#ifdef _LITTLE_ENDIAN
#endif
/* We're done. Pass the packet to IP */
return (0);
}
static void
{
case M_PROTO:
case M_PCPROTO:
/*
* If the message does not contain a PRIM_type,
* throw it away.
*/
return;
}
case T_ADDR_REQ:
icmp_addr_req(q, mp);
return;
case O_T_BIND_REQ:
case T_BIND_REQ:
icmp_tpi_bind(q, mp);
return;
case T_CONN_REQ:
icmp_tpi_connect(q, mp);
return;
case T_CAPABILITY_REQ:
icmp_capability_req(q, mp);
return;
case T_INFO_REQ:
icmp_info_req(q, mp);
return;
case T_UNITDATA_REQ:
/*
* If a T_UNITDATA_REQ gets here, the address must
* be bad. Valid T_UNITDATA_REQs are found above
* and break to below this switch.
*/
return;
case T_UNBIND_REQ:
icmp_tpi_unbind(q, mp);
return;
case T_SVR4_OPTMGMT_REQ:
cr)) {
/* Only IP can return anything meaningful */
&icmp_opt_obj, B_TRUE);
}
return;
case T_OPTMGMT_REQ:
/* Only IP can return anything meaningful */
return;
case T_DISCON_REQ:
icmp_tpi_disconnect(q, mp);
return;
/* The following TPI message is not supported by icmp. */
case O_T_CONN_RES:
case T_CONN_RES:
return;
/* The following 3 TPI requests are illegal for icmp. */
case T_DATA_REQ:
case T_EXDATA_REQ:
case T_ORDREL_REQ:
return;
default:
break;
}
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.
*/
err_ret:;
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.
*/
return;
case ND_SET:
/* nd_getset performs the necessary error checking */
case ND_GET:
return;
}
break;
case _SIOCSOCKFALLBACK:
/*
* socket is falling back to be a
* streams socket. Nothing to do
*/
return;
default:
break;
}
break;
case M_IOCDATA:
icmp_wput_iocdata(q, mp);
return;
default:
break;
}
}
/*
* icmp_wput_iocdata is called by icmp_wput_slow to handle all M_IOCDATA
* messages.
*/
static void
{
/* 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;
}
return;
case TI_GETMYNAME:
&addrlen);
break;
case TI_GETPEERNAME:
&addrlen);
break;
}
if (error != 0) {
} else {
/* Copy out the address */
mi_copyout(q, mp);
}
}
static int
void *thisdg_attrs)
{
struct T_unitdata_req *udreqp;
int is_absreq_failure;
*errorp = 0;
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
icmp_ddi_g_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 icmp_stack_t's.
*/
}
void
icmp_ddi_g_destroy(void)
{
}
#define INET_NAME "ip"
/*
* Initialize the ICMP stack instance.
*/
static void *
{
int error = 0;
return (is);
}
/*
* Free the ICMP stack instance.
*/
static void
{
}
static void *
{ "inDatagrams", KSTAT_DATA_UINT32, 0 },
{ "inCksumErrs", KSTAT_DATA_UINT32, 0 },
{ "inErrors", KSTAT_DATA_UINT32, 0 },
{ "outDatagrams", KSTAT_DATA_UINT32, 0 },
{ "outErrors", KSTAT_DATA_UINT32, 0 },
};
0, stackid);
return (NULL);
return (ksp);
}
static void
{
}
}
static int
{
netstack_t *ns;
return (EIO);
if (rw == KSTAT_WRITE)
return (EACCES);
return (-1);
return (-1);
}
return (0);
}
/* ARGSUSED */
int
{
return (EOPNOTSUPP);
}
/* ARGSUSED */
int
{
int error;
/* Binding to a NULL address really means unbind */
else
if (error < 0) {
else
}
return (error);
}
static int
{
int error;
len = sizeof (struct sockaddr_in);
} else {
}
}
static int
{
int error;
if (error < 0) {
}
return (error);
}
/* ARGSUSED */
int
{
return (EOPNOTSUPP);
}
/* ARGSUSED */
int
{
int error;
/*
* Disconnect
* Make sure we are connected
*/
return (EINVAL);
return (error);
}
if (error != 0)
return (error);
/* do an implicit bind if necessary */
/*
* We could be racing with an actual bind, in which case
* we would see EPROTO. We cross our fingers and try
* to connect.
*/
return (error);
}
/*
* set SO_DGRAM_ERRIND
*/
int unbind_err;
ASSERT(unbind_err == 0);
}
if (error == 0) {
*id = 0;
} else if (error < 0) {
}
return (error);
}
/* ARGSUSED */
void
{
struct T_capability_ack tca;
short opts;
struct stroptions *stropt;
int error;
/*
* setup the fallback stream that was allocated
*/
/* Notify stream head about options before sending up data */
/*
* free helper stream
*/
/*
* Collect the information needed to sync with the sonode
*/
if (error != 0)
faddrlen = 0;
opts = 0;
if (icmp->icmp_dgram_errind)
opts |= SO_DGRAM_ERRIND;
if (icmp->icmp_dontroute)
opts |= SO_DONTROUTE;
/*
* Once we grab the drain lock, no data will be send up
* to the socket. So we notify the socket that the endpoint
* is quiescent and it's therefore safe move data from
* the socket to the stream head.
*/
/*
* push up any packets that were queued in icmp_t
*/
}
/*
* No longer a streams less socket
*/
}
/* ARGSUSED */
{
return (NULL);
}
/* Build initial header template for transmit */
if ((*errorp =
return (NULL);
}
}
is->is_ldi_ident)) != 0) {
(void) rawip_do_close(connp);
return (NULL);
}
} else {
}
return ((sock_lower_handle_t)connp);
}
/* ARGSUSED */
void
{
struct sock_proto_props sopp;
}
static int
{
switch (icmp->icmp_family) {
case AF_INET:
return (EINVAL);
break;
}
} else {
/*
* INADDR_ANY
* icmp_v6src is not set, we might be bound to
* local address instead (that could
* also still be INADDR_ANY)
*/
}
break;
case AF_INET6:
return (EINVAL);
break;
}
} else {
/*
* UNSPECIFIED
* icmp_v6src is not set, we might be bound to
* local address instead (that could
* also still be UNSPECIFIED)
*/
}
break;
}
return (0);
}
static int
{
return (ENOTCONN);
switch (icmp->icmp_family) {
case AF_INET:
return (EINVAL);
break;
case AF_INET6:
return (EINVAL);
break;
}
return (0);
}
/* ARGSUSED */
int
{
int error;
return (error);
}
/* ARGSUSED */
int
{
int error;
return (error);
}
int
{
int error;
if (error != 0) {
/*
* option not recognized
*/
if (error < 0) {
}
return (error);
}
if (error < 0) {
/*
* Pass on to ip
*/
}
return (error);
}
int
{
int error;
void *optvalp_buf;
int len;
if (error != 0) {
if (error < 0) {
}
return (error);
}
if (len < 0) {
/*
* Pass on to IP
*/
} else {
/*
* update optlen and copy option value
*/
return (0);
}
}
/* ARGSUSED */
int
{
(void) rawip_do_close(connp);
return (0);
}
/* ARGSUSED */
int
{
/* shut down the send side */
SOCK_OPCTL_SHUT_SEND, 0);
/* shut down the recv side */
SOCK_OPCTL_SHUT_RECV, 0);
return (0);
}
void
{
}
int
{
int error;
switch (cmd) {
case ND_SET:
case ND_GET:
case _SIOCSOCKFALLBACK:
case TI_GETPEERNAME:
case TI_GETMYNAME:
#ifdef DEBUG
" socket", cmd);
#endif
break;
default:
/*
* Pass on to IP using helper stream
*/
break;
}
return (error);
}
/* ARGSUSED */
int
{
int error = 0;
if (is_system_labeled())
/* do an implicit bind if necessary */
/*
* We could be racing with an actual bind, in which case
* we would see EPROTO. We cross our fingers and try
* to connect.
*/
return (error);
}
}
goto done_lock;
}
switch (icmp->icmp_family) {
case AF_INET6: {
if (error != 0) {
goto done_lock;
}
if (icmp->icmp_delayed_error != 0) {
icmp->icmp_delayed_error = 0;
/* Compare IP address and port */
goto done_lock;
}
}
} else {
/*
* Use connected address
*/
goto done_lock;
}
}
/* No support for mapped addresses on raw sockets */
goto done_lock;
}
ipp->ipp_fields = 0;
ipp->ipp_sticky_ignored = 0;
/*
* If options passed in, feed it for verification and handling
*/
if (msg->msg_controllen != 0) {
if (error != 0) {
goto done_lock;
}
}
/*
* Destination is a native IPv6 address.
* Send out an IPv6 format packet.
*/
ipp);
}
break;
case AF_INET: {
if (error != 0) {
goto done_lock;
}
if (icmp->icmp_delayed_error != 0) {
icmp->icmp_delayed_error = 0;
/* Compare IP address and port */
goto done_lock;
}
}
} else {
/*
* Use connected address
*/
goto done_lock;
}
}
pktinfop->ip4_ill_index = 0;
/*
* If options passed in, feed it for verification and handling
*/
if (msg->msg_controllen != 0) {
if (error != 0) {
goto done_lock;
}
}
break;
}
default:
ASSERT(0);
}
goto done;
if (error != 0) {
}
done:
if (bypass_dgram_errind)
return (error);
}
NULL,
NULL,
NULL,
};