icmp.c revision db5b637c3ad5d30e8f1abbe1c8ecdc74bc454bc0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1990 Mentat Inc. */
#pragma ident "%Z%%M% %I% %E% SMI"
#define _SUN_TPI_VERSION 2
#include <sys/isa_defs.h>
#include <sys/xti_inet.h>
#include <inet/kstatcom.h>
#include <inet/rawip_impl.h>
#include <netinet/ip_mroute.h>
#include <inet/ipsec_info.h>
#include <inet/ipclassifier.h>
#define ICMP6 "icmp6"
/*
* Object to represent database of options to search passed to
* {sock,tpi}optcom_req() interface routine to take care of option
* management and associated methods.
* XXX These and other extern's should really move to a icmp header.
*/
extern optdb_obj_t icmp_opt_obj;
extern uint_t icmp_max_optsize;
/*
* Synchronization notes:
*
* At all points in this code where exclusive access is required, we
* pass a message to a subroutine by invoking qwriter(..., PERIM_OUTER)
* which will arrange to call the routine only after all threads have
* exited the shared resource.
*/
/* Named Dispatch Parameter Management Structure */
typedef struct icmpparam_s {
char *icmp_param_name;
} icmpparam_t;
static void icmp_bind_proto(queue_t *q);
static int icmp_close(queue_t *q);
int sys_error);
int *errorp, void *thisdg_attrs);
static void rawip_kstat_init(void);
static void rawip_kstat_fini(void);
static struct module_info info = {
};
};
};
};
static void *icmp_g_head; /* Head for list of open icmp streams. */
/* MIB-2 stuff for SNMP */
/* 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 icmp_g_nd
* in icmp_open.
*/
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 passed upstream when ip acknowledges the request.
* (Called as writer.)
*/
static void
{
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;
}
switch (tbr->ADDR_length) {
case 0: /* Generic request */
} else {
}
break;
case sizeof (sin_t): /* Complete IP address */
sizeof (sin_t));
return;
}
return;
}
break;
case sizeof (sin6_t): /* Complete IP address */
sizeof (sin6_t));
return;
}
return;
}
/* No support for mapped addresses on raw sockets */
return;
}
break;
default:
return;
}
/*
* 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 icmp_rput
* will clear the source address when it receives the T_BIND_ACK.
*/
&icmp->icmp_v6src);
} else {
int error;
/* Rebuild the header template */
if (error != 0) {
return;
}
}
/*
* Place protocol type in the O_T_BIND_REQ/T_BIND_REQ following
* the address.
*/
/*
* Append a request for an IRE if src not 0 (INADDR_ANY)
*/
return;
}
}
/* Pass the O_T_BIND_REQ/T_BIND_REQ to ip. */
}
/*
* Send message to IP to just bind to the protocol.
*/
static void
{
struct T_bind_req *tbr;
BPRI_MED);
if (!mp) {
return;
}
} else {
}
/* Place protocol type in the O_T_BIND_REQ following the address. */
/* Pass the O_T_BIND_REQ to ip. */
}
/*
* This routine handles each T_CONN_REQ message passed to icmp. It
* associates a default destination address with the stream.
*
* This routine sends down a T_BIND_REQ to IP with the following mblks:
* T_BIND_REQ - specifying local and remote address.
* 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 icmp_rput.
* When a T_BIND_ACK is received information is extracted from the IRE
* and the two appended messages are sent to the TPI user.
* Should icmp_rput receive T_ERROR_ACK for the T_BIND_REQ it will convert
* it to an error ack for the appropriate primitive.
*/
static void
{
struct T_conn_req *tcr;
/* Sanity checks */
return;
}
/* Already connected - clear out state */
}
if (tcr->OPT_length != 0) {
return;
}
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;
}
/* No support for mapped addresses on raw sockets */
return;
}
break;
}
/*
* Interpret a zero destination to mean loopback.
* generate the T_CONN_CON.
*/
if (v4dst == INADDR_ANY) {
} else {
}
}
icmp->icmp_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.
*/
&icmp->icmp_v6src);
}
} 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).
*/
}
/*
* 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 icmp_rput.
*/
0);
} else {
0);
}
return;
}
/* Unable to reuse the T_CONN_REQ for the ack. */
return;
}
/* Hang onto the T_OK_ACK and T_CONN_CON for later. */
}
static int
icmp_close(queue_t *q)
{
int i1;
qprocsoff(q);
/* If there are any options associated with the stream, free them. */
if (icmp->icmp_ip_snd_options)
/* Free memory associated with sticky options */
if (icmp->icmp_sticky_hdrs_len != 0) {
icmp->icmp_sticky_hdrs_len = 0;
}
}
}
}
}
}
/* Free the icmp structure and release the minor device number. */
return (i1);
}
/*
* 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.
*
* This routine sends down a T_BIND_REQ to IP with the following mblks:
* T_BIND_REQ - specifying just the local address.
* T_OK_ACK - for the T_DISCON_REQ
*
* The disconnect completes in icmp_rput.
* When a T_BIND_ACK is received the appended T_OK_ACK is sent to the TPI user.
* Should icmp_rput receive T_ERROR_ACK for the T_BIND_REQ it will convert
* it to an error ack for the appropriate primitive.
*/
static void
{
return;
}
/*
* Send down bind to IP to remove the full binding and revert
* to the local address binding.
*/
} else {
}
return;
}
/* Unable to reuse the T_DISCON_REQ for the ack. */
return;
}
int error;
/* Rebuild the header template */
if (error != 0) {
return;
}
}
/* Append the T_OK_ACK to the T_BIND_REQ for icmp_rput */
}
/* 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_rput to process ICMP
* messages 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;
/*
* 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;
}
icmp_icmp_error_ipv6(q, mp);
return;
}
switch (icmph->icmph_type) {
case ICMP_DEST_UNREACHABLE:
switch (icmph->icmph_code) {
/*
* IP has already adjusted the path MTU.
* XXX Somehow pass MTU indication to application?
*/
break;
case ICMP_PORT_UNREACHABLE:
break;
default:
/* Transient errors */
break;
}
break;
default:
/* Transient errors */
break;
}
if (error == 0) {
return;
}
switch (icmp->icmp_family) {
case AF_INET:
error);
break;
case AF_INET6:
break;
}
if (mp1)
}
/*
* 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;
}
/*
* Could have switched icmp_proto after while ip did fanout of
* this message
*/
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.
*/
return;
}
case ICMP6_TIME_EXCEEDED:
/* Transient errors */
break;
case ICMP6_PARAM_PROB:
/* If this corresponds to an ICMP_PROTOCOL_UNREACHABLE */
break;
}
break;
}
if (error == 0) {
return;
}
error);
if (mp1)
}
/*
* This routine responds to T_ADDR_REQ messages. It is called by 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
}
/*
* 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;
}
/*
* 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 (unused for raw sockets). 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;
return (NULL);
tbr->CONIND_number = 0;
switch (addr_length) {
case sizeof (ipa_conn_t):
/* Append a request for an IRE */
return (NULL);
}
/* cp known to be 32 bit aligned */
break;
case sizeof (ipa6_conn_t):
/* Append a request for an IRE */
return (NULL);
}
/* cp known to be 32 bit aligned */
break;
case sizeof (sin_t):
/* Append a request for an IRE */
return (NULL);
}
break;
case sizeof (sin6_t):
/* Append a request for an IRE */
return (NULL);
}
break;
}
/* Add protocol number to end */
return (mp);
}
/*
* This is the open routine for icmp. It allocates a icmp_t structure for
* the stream and, on the first open of the module, creates an ND table.
*/
static int
{
int err;
/* If the stream is already open, return immediately. */
return (0);
/* If this is not a push of icmp as a module, fail. */
return (EINVAL);
/*
* Defer the qprocson until everything is initialized since
* we are D_MTPERQ and after qprocson the rput routine can
* run. (Could do qprocson earlier since icmp currently
* has an outer perimeter.)
*/
/*
* Create a icmp_t structure for this stream and link into the
* list of open streams.
*/
if (err)
return (err);
/*
* The receive hiwat is only looked at on the stream head queue.
* Store in q_hiwat in order to return on SO_RCVBUF getsockopts.
*/
q->q_hiwat = icmp_recv_hiwat;
/* Set the initial state of the stream and the privilege status. */
/* May be changed by a SO_PROTOTYPE socket option. */
} else {
/* May be changed by a SO_PROTOTYPE socket option. */
}
qprocson(q);
/*
* Check if icmp is being I_PUSHed by a non-privileged user.
* If so, we set icmp_restricted to indicate that only MIB
* traffic may pass.
*/
if (secpolicy_net_icmpaccess(credp) != 0) {
}
/*
* The transmit hiwat is only looked at on IP's queue.
* Store in q_hiwat in order to return on SO_SNDBUF
* getsockopts.
*/
/* Build initial header template for transmit */
int error;
if (error != 0) {
(void) icmp_close(q);
return (error);
}
}
/* Set the Stream head write offset. */
(void) mi_set_sth_hiwat(q, q->q_hiwat);
return (0);
}
/*
* 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:
*i1 = icmp_ipv6_hoplimit;
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
{
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;
/*
* Following three 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:
*/
default:
return (-1);
}
break;
case IPPROTO_IP:
/*
* Only allow IPv4 option processing on IPv4 sockets.
*/
return (-1);
switch (name) {
case IP_OPTIONS:
case T_IP_OPTIONS:
/* Options are passed up with each packet */
return (0);
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 */
return (sizeof (ipaddr_t));
case IP_MULTICAST_TTL:
return (sizeof (uchar_t));
case IP_MULTICAST_LOOP:
return (sizeof (uint8_t));
case IP_BOUND_IF:
/* Zero if not set */
break; /* goto sizeof (int) option return */
case IP_UNSPEC_SRC:
break; /* goto sizeof (int) option return */
case IP_XMIT_IF:
break; /* goto sizeof (int) option return */
case IP_RECVIF:
break; /* goto sizeof (int) option return */
/*
* 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:
return (-1);
}
break;
case IPPROTO_IPV6:
/*
* Only allow IPv6 option processing on native IPv6 sockets.
*/
return (-1);
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
*/
return (-1);
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 */
return (-1);
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
return (sizeof (struct in6_pktinfo));
}
case IPV6_NEXTHOP: {
return (0);
return (sizeof (sin6_t));
}
case IPV6_HOPOPTS:
return (0);
return (ipp->ipp_hopoptslen);
case IPV6_RTHDRDSTOPTS:
return (0);
return (ipp->ipp_rtdstoptslen);
case IPV6_RTHDR:
return (0);
return (ipp->ipp_rthdrlen);
case IPV6_DSTOPTS:
return (0);
return (ipp->ipp_dstoptslen);
case IPV6_PATHMTU:
return (0);
(struct ip6_mtuinfo *)ptr));
case IPV6_TCLASS:
else
*i1 = IPV6_FLOW_TCLASS(
break;
default:
return (-1);
}
break;
case IPPROTO_ICMPV6:
/*
* Only allow IPv6 option processing on native IPv6 sockets.
*/
return (-1);
return (-1);
switch (name) {
case ICMP6_FILTER:
/* Make it look like "pass all" */
} else {
sizeof (icmp6_filter_t));
}
return (sizeof (icmp6_filter_t));
default:
return (-1);
}
default:
return (-1);
}
return (sizeof (int));
}
/* 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_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.
*/
return (0);
icmp_bind_proto(q);
*outlenp = sizeof (int);
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:
if (*i1 > icmp_max_buf) {
*outlenp = 0;
return (ENOBUFS);
}
if (!checkonly) {
}
break;
case SO_RCVBUF:
if (*i1 > icmp_max_buf) {
*outlenp = 0;
return (ENOBUFS);
}
if (!checkonly) {
}
break;
case SO_DGRAM_ERRIND:
if (!checkonly)
break;
/*
* 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;
if (icmp->icmp_ip_snd_options) {
icmp->icmp_ip_snd_options_len = 0;
}
if (inlen) {
if (icmp->icmp_ip_snd_options) {
}
}
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_XMIT_IF:
if (!checkonly)
break;
case IP_RECVIF:
if (!checkonly)
break;
case IP_ADD_MEMBERSHIP:
case IP_DROP_MEMBERSHIP:
case IP_BLOCK_SOURCE:
case IP_UNBLOCK_SOURCE:
case IP_ADD_SOURCE_MEMBERSHIP:
case MCAST_JOIN_GROUP:
case MCAST_LEAVE_GROUP:
case MCAST_BLOCK_SOURCE:
case MCAST_UNBLOCK_SOURCE:
case MCAST_JOIN_SOURCE_GROUP:
case MCAST_LEAVE_SOURCE_GROUP:
case 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.
*/
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)
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 (inlen == 0) {
if (sticky &&
ipp->ipp_hopoptslen = 0;
}
} else {
&ipp->ipp_hopoptslen);
if (error != 0)
return (error);
}
if (sticky) {
if (error != 0)
return (error);
}
break;
}
case IPV6_RTHDRDSTOPTS: {
/*
* Sanity checks - minimum size, size a multiple of
* eight bytes, and matching size passed in.
*/
if (inlen != 0 &&
return (EINVAL);
if (checkonly)
break;
if (inlen == 0) {
if (sticky &&
ipp->ipp_rtdstoptslen = 0;
}
} else {
&ipp->ipp_rtdstoptslen);
if (error != 0)
return (error);
}
if (sticky) {
if (error != 0)
return (error);
}
break;
}
case IPV6_DSTOPTS: {
/*
* Sanity checks - minimum size, size a multiple of
* eight bytes, and matching size passed in.
*/
if (inlen != 0 &&
return (EINVAL);
if (checkonly)
break;
if (inlen == 0) {
if (sticky &&
ipp->ipp_dstoptslen = 0;
}
} else {
&ipp->ipp_dstoptslen);
if (error != 0)
return (error);
}
if (sticky) {
if (error != 0)
return (error);
}
break;
}
case IPV6_RTHDR: {
/*
* Sanity checks - minimum size, size a multiple of
* eight bytes, and matching size passed in.
*/
if (inlen != 0 &&
return (EINVAL);
if (checkonly)
break;
if (inlen == 0) {
if (sticky &&
ipp->ipp_rthdrlen);
ipp->ipp_rthdrlen = 0;
}
} else {
&ipp->ipp_rthdrlen);
if (error != 0)
return (error);
}
if (sticky) {
if (error != 0)
return (error);
}
break;
}
case IPV6_DONTFRAG:
if (checkonly)
break;
if (onoff) {
} else {
}
break;
case IPV6_USE_MIN_MTU:
if (inlen != sizeof (int))
return (EINVAL);
return (EINVAL);
if (checkonly)
break;
break;
/*
* 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);
}
/*
* 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);
}
/*
* Set optbuf and optlen for the option.
* If sticky is set allocate memory (if not already present).
* Otherwise just point optbuf and optlen at invalp and inlen.
* Returns failure if memory can not be allocated.
*/
static int
{
if (!sticky) {
return (0);
}
/* Unchanged length - no need to realocate */
return (0);
}
if (inlen != 0) {
/* Allocate new buffer before free */
return (ENOMEM);
} else {
}
/* Free old buffer */
if (*optlenp != 0)
return (0);
}
/*
* This routine retrieves the value of an ND variable in a 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
{
struct T_unitdata_ind *tudi;
struct T_error_ack *tea;
int hdr_len;
int udi_size; /* Size of T_unitdata_ind */
if (icmp->icmp_restricted) {
return;
}
/*
* IP sends up the IPSEC_IN message for handling IPSEC
* policy at the TCP level. We don't need it here.
*/
} else {
if ((icmp->icmp_recvif != 0) &&
/*
* IP has passed the options in mp and the
* actual data is in b_cont.
*/
/*
* We are here bcos IP_RECVIF is set so we need
* to extract the options mblk and adjust the
* rptr
*/
options_mp = mp;
}
}
}
case M_DATA:
/*
* M_DATA messages contain IP packets. They are handled
* following the switch.
*/
break;
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:
/*
* If our O_T_BIND_REQ/T_BIND_REQ fails,
* clear out the source address before
* passing the message upstream.
* If this was caused by a T_CONN_REQ
* revert back to bound state.
*/
/*
* TPI has not yet bound - bind sent by
* icmp_bind_proto.
*/
return;
}
/* Connect failed */
icmp->icmp_v6src =
(void) icmp_build_hdrs(q, icmp);
break;
}
if (icmp->icmp_discon_pending) {
icmp->icmp_discon_pending = 0;
}
(void) icmp_build_hdrs(q, icmp);
break;
default:
break;
}
break;
case T_BIND_ACK:
icmp_rput_bind_ack(q, mp);
return;
case T_OPTMGMT_ACK:
case T_OK_ACK:
/*
* If somebody sets IPSEC options, IP
* sends some IPSEC info which is used
* by the TCP for detached connections.
* We don't need it here.
*/
}
}
}
break;
default:
return;
}
return;
case M_CTL:
if (recvif) {
/*
* IP has passed the options in mp and the actual data
* is in b_cont. Jump to normal data processing.
*/
break;
}
/* Contains ICMP packet from IP */
icmp_icmp_error(q, mp);
return;
default:
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 (icmp_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.
*/
if (recvif) {
sizeof (uint_t);
}
if (options_mp != NULL)
return;
}
sizeof (sin_t);
/*
* Add options if IP_RECVIF is set
*/
if (udi_size != 0) {
char *dstopt;
if (recvif) {
sizeof (uint_t);
}
/* Consumed all of allocated space */
}
return;
}
/*
* 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;
/*
* 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 */
}
}
}
} 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_ipv6_recvpktinfo &&
sizeof (struct in6_pktinfo);
icmp_opt |= IPPF_IFINDEX;
}
}
if (icmp->icmp_ipv6_recvhoplimit) {
}
if (icmp->icmp_ipv6_recvtclass)
return;
}
/* No sin6_flowinfo per API */
sin6->sin6_flowinfo = 0;
/* For link-scope source pass up scope id */
else
sin6->sin6_scope_id = 0;
icmp->icmp_zoneid);
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_opt & IPPF_HOPOPTS) {
}
if (icmp_opt & IPPF_RTDSTOPTS) {
}
if (icmp_opt & IPPF_RTHDR) {
}
if (icmp_opt & IPPF_DSTOPTS) {
}
/* Consumed all of allocated space */
}
}
/*
* Process a T_BIND_ACK
*/
static void
{
struct T_bind_ack *tba;
ipa_conn_t *ac;
/*
* We know if headers are included or not so we can
* safely do this.
*/
/*
* TPI has not yet bound - bind sent by
* icmp_bind_proto.
*/
return;
}
if (icmp->icmp_discon_pending)
icmp->icmp_discon_pending = 0;
/*
* the source address to 0.
* This ensures no datagrams with broadcast address
* as source address are emitted (which would violate
* RFC1122 - Hosts requirements)
*
* Note that when connecting the returned IRE is
* for the destination address and we only perform
* the broadcast check for the source address (it
*/
/*
* Note: we get IRE_BROADCAST for IPv6 to "mark" a multicast
* local address.
*/
(void) icmp_build_hdrs(q, icmp);
/*
* Local address not yet set - pick it from the
* T_bind_ack
*/
switch (icmp->icmp_family) {
case AF_INET:
} else {
sizeof (ipa_conn_x_t));
}
&icmp->icmp_v6src);
break;
case AF_INET6:
} else {
sizeof (ipa6_conn_x_t));
ac6 = &((ipa6_conn_x_t *)
}
(void) icmp_build_hdrs(q, icmp);
}
}
}
/*
* Look for one or more appended ACK message added by
* icmp_connect or icmp_disconnect.
* If none found just send up the T_BIND_ACK.
* icmp_connect has appended a T_OK_ACK and a
* T_CONN_CON.
* icmp_disconnect has appended a T_OK_ACK.
*/
else {
}
}
return;
}
}
/*
* return SNMP stuff in buffer in mpdata
*/
static int
{
return (0);
}
/* fixed length structure for IPv4 and IPv6 counters */
return (1);
}
/*
* 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 */
static int
{
switch (level) {
case EXPER_RAWIP:
return (0);
default:
return (1);
}
}
/* Report for ndd "icmp_status" */
/* ARGSUSED */
static int
{
char *state;
char laddrbuf[INET6_ADDRSTRLEN];
char faddrbuf[INET6_ADDRSTRLEN];
(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 */
state = "UNBOUND";
state = "IDLE";
state = "CONNECTED";
else
state = "UnkState";
(void) mi_mpprintf(mp,
MI_COL_PTRFMT_STR "%s %s %s",
(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)
}
/*
* 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
{
/* If a bind has not been done, we can't unbind. */
return;
}
int error;
/* Rebuild the header template */
if (error != 0) {
return;
}
}
/* Pass the unbind to IP. */
}
/*
* Process IPv4 packets that already include an IP header.
* Used when IP_HDRINCL has been set (implicit for IPPROTO_RAW and
* IPPROTO_IGMP).
*/
static void
{
int ip_hdr_length;
int tp_hdr_len;
return;
}
}
/*
* 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;
}
}
/*
* 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;
}
tp_hdr_len, BPRI_LO))) {
return;
}
/* 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.
*/
(void) ip_massage_options(ipha);
}
}
/*
* 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 ip_hdr_length;
if (icmp->icmp_restricted) {
icmp_wput_restricted(q, mp);
return;
}
case M_DATA:
if (icmp->icmp_hdrincl) {
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. */
/* If a port has not been bound to the stream, fail. */
return;
}
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.
*/
return;
case AF_INET:
return;
}
/* Extract and ipaddr */
break;
}
/*
* If options passed in, feed it for verification and handling
*/
if (tudr->OPT_length != 0) {
int error;
(uchar_t *)0) < 0) {
/* failure */
return;
}
/*
* Note: Success in processing options.
* mp option buffer represented by
* OPT_length/offset now potentially modified
* and contain option setting results
*/
}
/* Protocol 255 contains full IP headers */
if (icmp->icmp_hdrincl) {
return;
}
/* Add an IP header */
BPRI_LO))) {
return;
}
}
#ifdef _BIG_ENDIAN
/* Set version, header length, and tos */
/* Set ttl and protocol */
#else
/* Set version, header length, and tos */
/* Set ttl and protocol */
#endif
/*
* Copy our address into the packet. If this is zero,
* ip will fill in the real source address.
*/
/*
* 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;
}
/*
* Copy in the destination address from the T_UNITDATA
* request
*/
if (v4dst == INADDR_ANY)
else
/*
* 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.
*/
(void) ip_massage_options(ipha);
}
}
/*
* icmp_wput_ipv6():
* Assumes that icmp_wput did some sanity checking on the destination
* address.
*/
void
{
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;
}
ipp->ipp_fields = 0;
ipp->ipp_sticky_ignored = 0;
/*
* If TPI options passed in, feed it for verification and handling
*/
if (tudr_optlen != 0) {
int error;
(void *)ipp) < 0) {
/* failure */
return;
}
}
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.
*/
}
(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 */
(void) mi_set_sth_wroff(RD(q),
}
if (!mp1) {
return;
}
}
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 &&
}
}
/*
* 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
*/
else
if (option_exists & IPPF_TCLASS) {
tipp->ipp_tclass);
}
if (option_exists & IPPF_RTHDR) {
/*
* Perform any processing needed for source routing.
* We know that all extension headers will be in the same mblk
* as the IPv6 header.
*/
/*
* Drop packet - only support Type 0 routing.
* Notify the application as well.
*/
return;
}
/*
* rth->ip6r_len is twice the number of
* addresses in the header
*/
return;
}
/*
* Shuffle the routing header and ip6_dst
* addresses, and get the checksum difference
* between the first hop (in ip6_dst) and
* the destination (in the last routing hdr entry).
*/
/*
* Verify that the first hop isn't a mapped address.
* Routers along the path need to do this verification
* for subsequent hops.
*/
return;
}
}
}
/*
* 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;
}
/* 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;
}
else
}
/* Add payload length to checksum */
}
#ifdef _LITTLE_ENDIAN
#endif
/* We're done. Pass the packet to IP */
}
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:
return;
case T_CONN_REQ:
icmp_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_unbind(q, mp);
return;
case T_SVR4_OPTMGMT_REQ:
cr))
/* Only IP can return anything meaningful */
&icmp_opt_obj);
return;
case T_OPTMGMT_REQ:
/* Only IP can return anything meaningful */
return;
case T_DISCON_REQ:
icmp_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;
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
{
int addrlen;
/* Make sure it is one of ours. */
case TI_GETMYNAME:
case TI_GETPEERNAME:
break;
default:
return;
}
case -1:
return;
break;
/*
* The address has been copied out, so now
* copyout the strbuf.
*/
mi_copyout(q, mp);
return;
/*
* The address and strbuf have been copied out.
* We're done, so just acknowledge the original
* M_IOCTL.
*/
mi_copy_done(q, mp, 0);
return;
default:
/*
* Something strange has happened, so acknowledge
* the original M_IOCTL with an EPROTO error.
*/
return;
}
/*
* Now we have the strbuf structure for TI_GETMYNAME
* and TI_GETPEERNAME. Next we copyout the requested
* address and then we'll copyout the strbuf.
*/
else
return;
}
case TI_GETMYNAME:
} else {
/*
* INADDR_ANY
* icmp_v6src is not set, we might be bound to
* local address instead (that could
* also still be INADDR_ANY)
*/
}
} else {
/* icmp->icmp_family == AF_INET6 */
} else {
/*
* UNSPECIFIED
* icmp_v6src is not set, we might be bound to
* local address instead (that could
* also still be UNSPECIFIED)
*/
}
}
break;
case TI_GETPEERNAME:
} else {
/* icmp->icmp_family == AF_INET6) */
}
break;
default:
return;
}
if (!mp1)
return;
} else {
/* icmp->icmp_family == AF_INET6 */
}
/* Copy out the address */
mi_copyout(q, mp);
}
/*
* Only allow MIB requests and M_FLUSHes to pass.
* All other messages are nacked or dropped.
*/
static void
{
case M_PROTO:
case M_PCPROTO:
return;
}
case T_SVR4_OPTMGMT_REQ:
if (!snmpcom_req(q, mp,
&icmp_opt_obj);
return;
case T_OPTMGMT_REQ:
return;
default:
return;
}
/* NOTREACHED */
case M_IOCTL:
break;
case M_FLUSH:
break;
default:
break;
}
}
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_init(void)
{
}
void
icmp_ddi_destroy(void)
{
}
static void
rawip_kstat_init(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);
if (rawip_mibkp == NULL)
return;
}
static void
rawip_kstat_fini(void) {
if (rawip_mibkp) {
rawip_mibkp = NULL;
}
}
static int
return (EIO);
if (rw == KSTAT_WRITE)
return (EACCES);
return (0);
}