ip.c revision f1c454b4ca60de954c3f9b89aad635ec90c8fe2d
/*
* 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 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1990 Mentat Inc. */
#include <sys/sysmacros.h>
#define _SUN_TPI_VERSION 2
#include <sys/xti_inet.h>
#include <sys/isa_defs.h>
#include <inet/kstatcom.h>
#include <netinet/igmp_var.h>
#include <inet/tcp_impl.h>
#include <inet/ip_multi.h>
#include <inet/ip_ftable.h>
#include <inet/ip_listutils.h>
#include <netinet/ip_mroute.h>
#include <inet/ipp_common.h>
#include <inet/ipsec_impl.h>
#include <inet/ip_netinfo.h>
#include <sys/ethernet.h>
#include <net/if_types.h>
#include <ipp/ipp_impl.h>
#include <inet/ipclassifier.h>
#include <inet/udp_impl.h>
#include <inet/rawip_impl.h>
#include <inet/rts_impl.h>
#include <sys/squeue_impl.h>
/*
* Values for squeue switch:
* IP_SQUEUE_ENTER_NODRAIN: SQ_NODRAIN
* IP_SQUEUE_ENTER: SQ_PROCESS
* IP_SQUEUE_FILL: SQ_FILL
*/
int ip_squeue_flag;
/*
*/
int ip_poll_normal_ms = 100;
int ip_poll_normal_ticks = 0;
int ip_modclose_ackwait_ms = 3000;
/*
* It would be nice to have these present only in DEBUG systems, but the
* current design of the global symbol checking logic requires them to be
* unconditionally present.
*/
/*
* Structure to represent a linked list of msgblks. Used by ip_snmp_ functions.
*/
struct listptr_s {
};
/*
* This is used by ip_snmp_get_mib2_ip_route_media and
* ip_snmp_get_mib2_ip6_route_media to carry the lists of return data.
*/
typedef struct iproutedata_s {
/* Include ire_testhidden and IRE_IF_CLONE routes */
#define IRD_REPORT_ALL 0x01
/*
* Cluster specific hooks. These should be NULL when booted as a non-cluster
*/
/*
* Hook functions to enable cluster networking
* On non-clustered systems these vectors must always be NULL.
*
* Hook function to Check ip specified ip address is a shared ip address
* in the cluster
*
*/
/*
* Hook function to generate cluster wide ip fragment identifier
*/
/*
* Hook function to generate cluster wide SPI.
*/
void *) = NULL;
/*
* Hook function to verify if the SPI is already utlized.
*/
/*
* Hook function to delete the SPI from the cluster wide repository.
*/
/*
* Hook function to inform the cluster when packet received on an IDLE SA
*/
/*
* Synchronization notes:
*
* MT level protection given by STREAMS. IP uses a combination of its own
* internal serialization mechanism and standard Solaris locking techniques.
* The internal serialization is per phyint. This is used to serialize
* plumbing operations, IPMP operations, most set ioctls, etc.
*
* Plumbing is a long sequence of operations involving message
* exchanges between IP, ARP and device drivers. Many set ioctls are typically
* involved in plumbing operations. A natural model is to serialize these
* ioctls one per ill. For example plumbing of hme0 and qfe0 can go on in
* parallel without any interference. But various set ioctls on hme0 are best
* serialized, along with IPMP operations and processing of DLPI control
* messages received from drivers on a per phyint basis. This serialization is
* provided by the ipsq_t and primitives operating on this. Details can
* be found in ip_if.c above the core primitives operating on ipsq_t.
*
* Lookups of an ipif or ill by a thread return a refheld ipif / ill.
* Simiarly lookup of an ire by a thread also returns a refheld ire.
* In addition ipif's and ill's referenced by the ire are also indirectly
* refheld. Thus no ipif or ill can vanish as long as an ipif is refheld
* directly or indirectly. For example an SIOCSLIFADDR ioctl that changes the
* address of an ipif has to go through the ipsq_t. This ensures that only
* one such exclusive operation proceeds at any time on the ipif. It then
* waits for all refcnts
* associated with this ipif to come down to zero. The address is changed
* only after the ipif has been quiesced. Then the ipif is brought up again.
* More details are described above the comment in ip_sioctl_flags.
*
* Packet processing is based mostly on IREs and are fully multi-threaded
* using standard Solaris MT techniques.
*
* There are explicit locks in IP to handle:
* - The ip_g_head list maintained by mi_open_link() and friends.
*
* - The reassembly data structures (one lock per hash bucket)
*
* - conn_lock is meant to protect conn_t fields. The fields actually
* protected by conn_lock are documented in the conn_t definition.
*
* - ire_lock to protect some of the fields of the ire, IRE tables
* (one lock per hash bucket). Refer to ip_ire.c for details.
*
* - ndp_g_lock and ncec_lock for protecting NCEs.
*
* - ill_lock protects fields of the ill and ipif. Details in ip.h
*
* * The AVL tree based global multi list of all ills.
* * The linked list of all ipifs of an ill
* * The <ipsq-xop> mapping
* * <ill-phyint> association
* into an ill, changing the <ipsq-xop> mapping of an ill, changing the
* <ill-phyint> assoc of an ill will all have to hold the ill_g_lock as
*
* - ill_lock: This is a per ill mutex.
* It protects some members of the ill_t struct; see ip.h for details.
* It also protects the <ill-phyint> assoc.
* It also protects the list of ipifs hanging off the ill.
*
* - ipsq_lock: This is a per ipsq_t mutex lock.
* This protects some members of the ipsq_t struct; see ip.h for details.
* It also protects the <ipsq-ipxop> mapping
*
* - ipx_lock: This is a per ipxop_t mutex lock.
* This protects some members of the ipxop_t struct; see ip.h for details.
*
* - phyint_lock: This is a per phyint mutex lock. Protects just the
* phyint_flags
*
* Any call to nd_load to load a new parameter to the ND table must hold the
* as reader.
*
* - ip_addr_avail_lock: This is used to ensure the uniqueness of IP addresses.
* This lock is held in ipif_up_done and the ipif is marked IPIF_UP and the
* uniqueness check also done atomically.
*
* group list linked by ill_usesrc_grp_next. It also protects the
* ill_usesrc_ifindex field. It is taken as a writer when a member of the
* group is being added or deleted. This lock is taken as a reader when
* Note, it is only necessary to take this lock if the ill_usesrc_grp_next
* field is changing state i.e from NULL to non-NULL or vice-versa. For
* example, it is not necessary to take this lock in the initial portion
* of ip_sioctl_slifusesrc or at all in ip_sioctl_flags since these
* operations are executed exclusively and that ensures that the "usesrc
* group state" cannot change. The "usesrc group state" change can happen
* only in the latter part of ip_sioctl_slifusesrc and in ill_delete.
*
* Changing <ill-phyint>, <ipsq-xop> assocications:
*
* To change the <ill-phyint> association, the ill_g_lock must be held
* as writer, and the ill_locks of both the v4 and v6 instance of the ill
* must be held.
*
* To change the <ipsq-xop> association, the ill_g_lock must be held as
* writer, the ipsq_lock must be held, and one must be writer on the ipsq.
* This is only done when ills are added or removed from IPMP groups.
*
* To add or delete an ipif from the list of ipifs hanging off the ill,
* ill_g_lock (writer) and ill_lock must be held and the thread must be
* a writer on the associated ipsq.
*
* To add or delete an ill to the system, the ill_g_lock must be held as
* writer and the thread must be a writer on the associated ipsq.
*
* To add or delete an ilm to an ill, the ill_lock must be held and the thread
* must be a writer on the associated ipsq.
*
* Lock hierarchy
*
* Some lock hierarchy scenarios are listed below.
*
* ill_g_lock -> conn_lock -> ill_lock -> ipsq_lock -> ipx_lock
* ill_g_lock -> ill_lock(s) -> phyint_lock
* ill_g_lock -> ndp_g_lock -> ill_lock -> ncec_lock
* ill_g_lock -> ip_addr_avail_lock
* conn_lock -> irb_lock -> ill_lock -> ire_lock
* ill_g_lock -> ip_g_nd_lock
* ill_g_lock -> ips_ipmp_lock -> ill_lock -> nce_lock
* ill_g_lock -> ndp_g_lock -> ill_lock -> ncec_lock -> nce_lock
* arl_lock -> ill_lock
* ips_ire_dep_lock -> irb_lock
*
* When more than 1 ill lock is needed to be held, all ill lock addresses
* are sorted on address and locked starting from highest addressed lock
* downward.
*
* Multicast scenarios
* ips_ill_g_lock -> ill_mcast_lock
* conn_ilg_lock -> ips_ill_g_lock -> ill_lock
* ill_mcast_serializer -> ill_mcast_lock -> ips_ipmp_lock -> ill_lock
* ill_mcast_serializer -> ill_mcast_lock -> connf_lock -> conn_lock
* ill_mcast_serializer -> ill_mcast_lock -> conn_ilg_lock
* ill_mcast_serializer -> ill_mcast_lock -> ips_igmp_timer_lock
*
* IPsec scenarios
*
* ipsa_lock -> ill_g_lock -> ill_lock
* ill_g_usesrc_lock -> ill_g_lock -> ill_lock
*
* Trusted Solaris scenarios
*
* igsa_lock -> gcgrp_rwlock -> gcgrp_lock
* igsa_lock -> gcdb_lock
* gcgrp_rwlock -> ire_lock
* gcgrp_rwlock -> gcdb_lock
*
* squeue(sq_lock), flow related (ft_lock, fe_lock) locking
*
* cpu_lock --> ill_lock --> sqset_lock --> sq_lock
* sq_lock -> conn_lock -> QLOCK(q)
* ill_lock -> ft_lock -> fe_lock
*
* Routing/forwarding table locking notes:
*
* Lock acquisition order: Radix tree lock, irb_lock.
* Requirements:
* i. Walker must not hold any locks during the walker callback.
* ii Walker must not see a truncated tree during the walk because of any node
* deletion.
* iii Existing code assumes ire_bucket is valid if it is non-null and is used
* in many places in the code to walk the irb list. Thus even if all the
* ires in a bucket have been deleted, we still can't free the radix node
* until the ires have actually been inactive'd (freed).
*
* Tree traversal - Need to hold the global tree lock in read mode.
* Before dropping the global tree lock, need to either increment the ire_refcnt
* to ensure that the radix node can't be deleted.
*
* Tree add - Need to hold the global tree lock in write mode to add a
* radix node. To prevent the node from being deleted, increment the
* irb_refcnt, after the node is added to the tree. The ire itself is
* added later while holding the irb_lock, but not the tree lock.
*
* Tree delete - Need to hold the global tree lock and irb_lock in write mode.
* All associated ires must be inactive (i.e. freed), and irb_refcnt
* must be zero.
*
* Walker - Increment irb_refcnt before calling the walker callback. Hold the
* global tree lock (read mode) for traversal.
*
* IRE dependencies - In some cases we hold ips_ire_dep_lock across ire_refrele
* hence we will acquire irb_lock while holding ips_ire_dep_lock.
*
* IPsec notes :
*
* in the ip_xmit_attr_t ip_recv_attr_t. For outbound datagrams, the
* ip_xmit_attr_t has the
* information used by the IPsec code for applying the right level of
* protection. The information initialized by IP in the ip_xmit_attr_t
* is determined by the per-socket policy or global policy in the system.
* For inbound datagrams, the ip_recv_attr_t
* starts out with nothing in it. It gets filled
* happens if the incoming packet is secure. The information initialized
* the policy requirements needed by per-socket policy or global policy
* is met or not.
*
* For fully connected sockets i.e dst, src [addr, port] is known,
* conn_policy_cached is set indicating that policy has been cached.
* conn_in_enforce_policy may or may not be set depending on whether
* there is a global policy match or per-socket policy match.
* Policy inheriting happpens in ip_policy_set once the destination is known.
* Once the right policy is set on the conn_t, policy cannot change for
* this socket. This makes life simpler for TCP (UDP ?) where
* re-transmissions go out with the same policy. For symmetry, policy
* is cached for fully connected UDP sockets also. Thus if policy is cached,
* it also implies that policy is latched i.e policy cannot change
* on these sockets. As we have the right policy on the conn, we don't
* have to lookup global policy for every outbound and inbound datagram
* and thus serving as an optimization. Note that a global policy change
* does not affect fully connected sockets if they have policy. If fully
* connected sockets did not have any policy associated with it, global
* policy change may affect them.
*
* IP Flow control notes:
* ---------------------
* Non-TCP streams are flow controlled by IP. The way this is accomplished
* differs when ILL_CAPAB_DLD_DIRECT is enabled for that IP instance. When
* ILL_DIRECT_CAPABLE(ill) is TRUE, IP can do direct function calls into
* GLDv3. Otherwise packets are sent down to lower layers using STREAMS
* functions.
*
* Per Tx ring udp flow control:
* This is applicable only when ILL_CAPAB_DLD_DIRECT capability is set in
* the ill (i.e. ILL_DIRECT_CAPABLE(ill) is true).
*
* The underlying link can expose multiple Tx rings to the GLDv3 mac layer.
* To achieve best performance, outgoing traffic need to be fanned out among
* these Tx ring. mac_tx() is called (via str_mdata_fastpath_put()) to send
* traffic out of the NIC and it takes a fanout hint. UDP connections pass
* the address of connp as fanout hint to mac_tx(). Under flow controlled
* condition, mac_tx() returns a non-NULL cookie (ip_mac_tx_cookie_t). This
* cookie points to a specific Tx ring that is blocked. The cookie is used to
* hash into an idl_tx_list[] entry in idl_tx_list[] array. Each idl_tx_list_t
* point to drain_lists (idl_t's). These drain list will store the blocked UDP
* connp's. The drain list is not a single list but a configurable number of
* lists.
*
* The diagram below shows idl_tx_list_t's and their drain_lists. ip_stack_t
* has an array of idl_tx_list_t. The size of the array is TX_FANOUT_SIZE
* which is equal to 128. This array in turn contains a pointer to idl_t[],
* the ip drain list. The idl_t[] array size is MIN(max_ncpus, 8). The drain
* list will point to the list of connp's that are flow controlled.
*
* --------------- ------- ------- -------
* |->|drain_list[0]|-->|connp|-->|connp|-->|connp|-->
* | --------------- ------- ------- -------
* | --------------- ------- ------- -------
* |->|drain_list[1]|-->|connp|-->|connp|-->|connp|-->
* ---------------- | --------------- ------- ------- -------
* |idl_tx_list[0]|->| --------------- ------- ------- -------
* ---------------- |->|drain_list[2]|-->|connp|-->|connp|-->|connp|-->
* | --------------- ------- ------- -------
* . . . . .
* | --------------- ------- ------- -------
* |->|drain_list[n]|-->|connp|-->|connp|-->|connp|-->
* --------------- ------- ------- -------
* --------------- ------- ------- -------
* |->|drain_list[0]|-->|connp|-->|connp|-->|connp|-->
* | --------------- ------- ------- -------
* | --------------- ------- ------- -------
* ---------------- |->|drain_list[1]|-->|connp|-->|connp|-->|connp|-->
* |idl_tx_list[1]|->| --------------- ------- ------- -------
* ---------------- | . . . .
* | --------------- ------- ------- -------
* |->|drain_list[n]|-->|connp|-->|connp|-->|connp|-->
* --------------- ------- ------- -------
* .....
* ----------------
* |idl_tx_list[n]|-> ...
* ----------------
*
* When mac_tx() returns a cookie, the cookie is used to hash into a
* idl_tx_list in ips_idl_tx_list[] array. Then conn_drain_insert() is
* called passing idl_tx_list. The connp gets inserted in a drain list
* pointed to by idl_tx_list. conn_drain_list() asserts flow control for
* the sockets (non stream based) and sets QFULL condition on the conn_wq
* of streams sockets, or the su_txqfull for non-streams sockets.
* connp->conn_direct_blocked will be set to indicate the blocked
* condition.
*
* GLDv3 mac layer calls ill_flow_enable() when flow control is relieved.
* A cookie is passed in the call to ill_flow_enable() that identifies the
* blocked Tx ring. This cookie is used to get to the idl_tx_list that
* contains the blocked connp's. conn_walk_drain() uses the idl_tx_list_t
* and goes through each conn in the drain list and calls conn_idl_remove
* for the conn to clear the qfull condition for the conn, as well as to
* remove the conn from the idl list. In addition, streams based sockets
* will have the conn_wq enabled, causing ip_wsrv to run for the
* conn. ip_wsrv drains the queued messages, and removes the conn from the
* drain list, if all messages were drained. It also notifies the
* conn_upcalls for the conn to signal that flow-control has opened up.
*
* In reality the drain list is not a single list, but a configurable number
* of lists. conn_walk_drain() in the IP module, notifies the conn_upcalls for
* each conn in the list. conn_drain_insert and conn_drain_tail are the only
* functions that manipulate this drain list. conn_drain_insert is called in
* from the protocol layer when conn_ip_output returns EWOULDBLOCK.
* (as opposed to from ip_wsrv context for STREAMS
* case -- see below). The synchronization between drain insertion and flow
* control wakeup is handled by using idl_txl->txl_lock.
*
* Flow control using STREAMS:
* When ILL_DIRECT_CAPABLE() is not TRUE, STREAMS flow control mechanism
* is used. On the send side, if the packet cannot be sent down to the
* driver by IP, because of a canput failure, ip_xmit drops the packet
* and returns EWOULDBLOCK to the caller, who may then invoke
* ixa_check_drain_insert to insert the conn on the 0'th drain list.
* When ip_wsrv runs on the ill_wq because flow control has been relieved, the
* blocked conns in the * 0'th drain list is drained as with the
* non-STREAMS case.
*
* In both the STREAMS and non-STREAMS case, the sockfs upcall to set
* qfull is done when the conn is inserted into the drain list
* (conn_drain_insert()) and cleared when the conn is removed from the drain
* list (conn_idl_remove()).
*
* IPQOS notes:
*
* IPQoS Policies are applied to packets using IPPF (IP Policy framework)
* and IPQoS modules. IPPF includes hooks in IP at different control points
* (callout positions) which direct packets to IPQoS modules for policy
* processing. Policies, if present, are global.
*
* The callout positions are located in the following paths:
* o local_in (packets destined for this host)
* o local_out (packets orginating from this host )
* o fwd_in (packets forwarded by this m/c - inbound)
* o fwd_out (packets forwarded by this m/c - outbound)
* ip_policy_mask (a bit mask with the 4 LSB indicating the callout positions).
* By default all the callout positions are enabled.
*
* Outbound (local_out)
* Hooks are placed in ire_send_wire_v4 and ire_send_wire_v6.
*
* Inbound (local_in)
* Hooks are placed in ip_fanout_v4 and ip_fanout_v6.
*
* Forwarding (in and out)
* Hooks are placed in ire_recv_forward_v4/v6.
*
* IP Policy Framework processing (IPPF processing)
* Policy processing for a packet is initiated by ip_process, which ascertains
* that the classifier (ipgpc) is loaded and configured, failing which the
* packet resumes normal processing in IP. If the clasifier is present, the
* packet is acted upon by one or more IPQoS modules (action instances), per
* filters configured in ipgpc and resumes normal IP processing thereafter.
* An action instance can drop a packet in course of its processing.
*
* Zones notes:
*
* The partitioning rules for networking are as follows:
* 1) Packets coming from a zone must have a source address belonging to that
* zone.
* 2) Packets coming from a zone can only be sent on a physical interface on
* which the zone has an IP address.
* 3) Between two zones on the same machine, packet delivery is only allowed if
* there's a matching route for the destination and zone in the forwarding
* table.
* 4) The TCP and UDP port spaces are per-zone; that is, two processes in
* different zones can bind to the same port with the wildcard address
* (INADDR_ANY).
*
* The granularity of interface partitioning is at the logical interface level.
* Therefore, every zone has its own IP addresses, and incoming packets can be
* attributed to a zone unambiguously. A logical interface is placed into a zone
* using the SIOCSLIFZONE ioctl; this sets the ipif_zoneid field in the ipif_t
* structure. Rule (1) is implemented by modifying the source address selection
* algorithm so that the list of eligible addresses is filtered based on the
* sending process zone.
*
* The Internet Routing Entries (IREs) are either exclusive to a zone or shared
* across all zones, depending on their type. Here is the break-up:
*
* -------- ----------------
* IRE_BROADCAST Exclusive
* IRE_DEFAULT (default routes) Shared (*)
* IRE_LOCAL Exclusive (x)
* IRE_LOOPBACK Exclusive
* IRE_PREFIX (net routes) Shared (*)
* IRE_IF_NORESOLVER (interface routes) Exclusive
* IRE_IF_RESOLVER (interface routes) Exclusive
* IRE_IF_CLONE (interface routes) Exclusive
* IRE_HOST (host routes) Shared (*)
*
* (*) A zone can only use a default or off-subnet route if the gateway is
* directly reachable from the zone, that is, if the gateway's address matches
* one of the zone's logical interfaces.
*
* (x) IRE_LOCAL are handled a bit differently.
* When ip_restrict_interzone_loopback is set (the default),
* ire_route_recursive restricts loopback using an IRE_LOCAL
* between zone to the case when L2 would have conceptually looped the packet
* back, i.e. the loopback which is required since neither Ethernet drivers
* nor Ethernet hardware loops them back. This is the case when the normal
* routes (ignoring IREs with different zoneids) would send out the packet on
* the same ill as the ill with which is IRE_LOCAL is associated.
*
* Multiple zones can share a common broadcast address; typically all zones
* share the 255.255.255.255 address. Incoming as well as locally originated
* broadcast packets must be dispatched to all the zones on the broadcast
* network. For directed broadcasts (e.g. 10.16.72.255) this is not trivial
* since some zones may not be on the 10.16.72/24 network. To handle this, each
* zone has its own set of IRE_BROADCAST entries; then, broadcast packets are
* sent to every zone that has an IRE_BROADCAST entry for the destination
* address on the input ill, see ip_input_broadcast().
*
* Applications in different zones can join the same multicast group address.
* The same logic applies for multicast as for broadcast. ip_input_multicast
* dispatches packets to all zones that have members on the physical interface.
*/
/*
* Squeue Fanout flags:
* 0: No fanout.
* 1: Fanout across all squeues
*/
/*
* Maximum dups allowed per packet.
*/
/* RFC 1122 Conformance */
#define IP_FORWARD_DEFAULT IP_FORWARD_NEVER
ip_recv_attr_t *);
static void icmp_options_update(ipha_t *);
ip_recv_attr_t *);
ip_recv_attr_t *);
char *ip_dot_addr(ipaddr_t, char *);
static char *ip_dot_saddr(uchar_t *, char *);
char *ip_nv_lookup(nv_t *, int);
void *dummy_arg);
mib2_ipIfStatsEntry_t *, ip_stack_t *);
ip_stack_t *);
ip_stack_t *ipst);
ip_stack_t *ipst);
ip_stack_t *ipst);
ip_stack_t *ipst);
ip_stack_t *ipst);
ip_stack_t *ipst);
ip_stack_t *ipst);
ip_stack_t *ipst);
ip_stack_t *ipst);
ip_stack_t *ipst);
mblk_t *);
static void conn_drain_init(ip_stack_t *);
static void conn_drain_fini(ip_stack_t *);
const in6_addr_t *);
cred_t *);
static int ip_squeue_switch(int);
static void *icmp_kstat_init(netstackid_t);
static void ipobs_init(ip_stack_t *);
static void ipobs_fini(ip_stack_t *);
/* How long, in seconds, we allow frags to hang around. */
#define IP_FRAG_TIMEOUT 15
#define IPV6_FRAG_TIMEOUT 60
static long ip_rput_pullups;
int ip_debug;
/*
* Multirouting/CGTP stuff
*/
/*
* Named Dispatch Parameter Table.
*/
static ipparam_t lcl_param_arr[] = {
/* min max value name */
{ 0, 1, 0, "ip_respond_to_address_mask_broadcast"},
{ 0, 1, 1, "ip_respond_to_echo_broadcast"},
{ 0, 1, 1, "ip_respond_to_echo_multicast"},
{ 0, 1, 0, "ip_respond_to_timestamp"},
{ 0, 1, 0, "ip_respond_to_timestamp_broadcast"},
{ 0, 1, 1, "ip_send_redirects"},
{ 0, 1, 0, "ip_forward_directed_broadcasts"},
{ 0, 10, 0, "ip_mrtdebug"},
{ 1, 8, 3, "ip_ire_reclaim_fraction" },
{ 1, 8, 3, "ip_nce_reclaim_fraction" },
{ 1, 8, 3, "ip_dce_reclaim_fraction" },
{ 1, 255, 255, "ip_def_ttl" },
{ 0, 1, 0, "ip_forward_src_routed"},
{ 0, 256, 32, "ip_wroff_extra" },
{ 2, 999999999, 60*20, "ip_pathmtu_interval" }, /* In seconds */
{ 8, 65536, 64, "ip_icmp_return_data_bytes" },
{ 0, 1, 1, "ip_path_mtu_discovery" },
{ 68, 65535, 576, "ip_pmtu_min" },
{ 0, 1, 0, "ip_ignore_redirect" },
{ 0, 1, 0, "ip_arp_icmp_error" },
{ 1, 254, 1, "ip_broadcast_ttl" },
{ 0, 99999, 100, "ip_icmp_err_interval" },
{ 1, 99999, 10, "ip_icmp_err_burst" },
{ 0, 999999999, 1000000, "ip_reass_queue_bytes" },
{ 0, 1, 0, "ip_strict_dst_multihoming" },
{ 0, 1, 0, "ipsec_override_persocket_policy" },
{ 0, 1, 1, "icmp_accept_clear_messages" },
{ 0, 1, 1, "igmp_accept_clear_messages" },
"ip_ndp_delay_first_probe_time"},
"ip_ndp_max_unicast_solicit"},
{ 0, 1, 0, "ip6_forward_src_routed"},
{ 0, 1, 1, "ip6_respond_to_echo_multicast"},
{ 0, 1, 1, "ip6_send_redirects"},
{ 0, 1, 0, "ip6_ignore_redirect" },
{ 0, 1, 0, "ip6_strict_dst_multihoming" },
{ 0, 2, 2, "ip_src_check" },
{ 0, 999999, 1000, "ipsec_policy_log_interval" },
{ 0, 1, 1, "pim_accept_clear_messages" },
{ 1000, 20000, 2000, "ip_ndp_unsolicit_interval" },
{ 1, 20, 3, "ip_ndp_unsolicit_count" },
{ 0, 1, 1, "ip6_ignore_home_address_opt" },
{ 0, 15, 0, "ip_policy_mask" },
{ 0, 2, 2, "ip_ecmp_behavior" },
{ 0, 255, 1, "ip_multirt_ttl" },
{ 0, 3600, 60, "ip_ire_badcnt_lifetime" }, /* In seconds */
{ 0, 999999, 60*60*24, "ip_max_temp_idle" },
{ 0, 1000, 1, "ip_max_temp_defend" },
/*
* when a conflict of an active address is detected,
* defend up to ip_max_defend times, within any
* ip_defend_interval span.
*/
{ 0, 1000, 3, "ip_max_defend" },
{ 0, 999999, 30, "ip_defend_interval" },
{ 0, 3600000, 300000, "ip_dup_recovery" },
{ 0, 1, 1, "ip_restrict_interzone_loopback" },
{ 0, 1, 1, "ip_lso_outbound" },
#ifdef DEBUG
{ 0, 1, 0, "ip6_drop_inbound_icmpv6" },
#else
{ 0, 0, 0, "" },
#endif
/* delay before sending first probe: */
{ 0, 20000, 1000, "arp_probe_delay" },
{ 0, 20000, 100, "arp_fastprobe_delay" },
/* interval at which DAD probes are sent: */
{ 10, 20000, 1500, "arp_probe_interval" },
{ 10, 20000, 150, "arp_fastprobe_interval" },
/* setting probe count to 0 will disable ARP probing for DAD. */
{ 0, 20, 3, "arp_probe_count" },
{ 0, 20, 3, "arp_fastprobe_count" },
{ 0, 3600000, 15000, "ipv4_dad_announce_interval"},
{ 0, 3600000, 15000, "ipv6_dad_announce_interval"},
/*
* Rate limiting parameters for DAD defense used in
* ill_defend_rate_limit():
* defend_interval : time that can elapse before we send out a
* DAD defense.
* defend_period: denominator for defend_rate (in seconds).
*/
{ 0, 3600000, 300000, "arp_defend_interval"},
{ 0, 20000, 100, "arp_defend_rate"},
{ 0, 3600000, 300000, "ndp_defend_interval"},
{ 0, 20000, 100, "ndp_defend_rate"},
{ 5, 86400, 3600, "arp_defend_period"},
{ 5, 86400, 3600, "ndp_defend_period"},
{ 0, 1, 1, "ipv4_icmp_return_pmtu" },
{ 0, 1, 1, "ipv6_icmp_return_pmtu" },
/*
* for IPv4, IPv6.
*/
{ 1, 20, 5, "ip_arp_publish_count" },
{ 1000, 20000, 2000, "ip_arp_publish_interval" },
};
/*
* Extended NDP table
* The addresses for the first two are filled in to be ips_ip_g_forward
* and ips_ipv6_forward at init time.
*/
static ipndp_t lcl_ndp_arr[] = {
/* getf setf data name */
#define IPNDP_IP_FORWARDING_OFFSET 0
"ip_forwarding" },
#define IPNDP_IP6_FORWARDING_OFFSET 1
"ip6_forwarding" },
#define IPNDP_CGTP_FILTER_OFFSET 4
"ip_cgtp_filter" },
"ip_debug" },
};
/*
* Table of IP ioctls encoding the various properties of the ioctl and
* indexed based on the last byte of the ioctl command. Occasionally there
* is a clash, and there is more than 1 ioctl with the same last byte.
* In such a case 1 ioctl is encoded in the ndx table and the remaining
* ioctls are encoded in the misc table. An entry in the ndx table is
* retrieved by indexing on the last byte of the ioctl command and comparing
* the ioctl command with the value in the ndx table. In the event of a
* mismatch the misc table is then searched sequentially for the desired
* ioctl command.
*
* Entry: <command> <copyin_size> <flags> <cmd_type> <function> <restart_func>
*/
/* copyin size cannot be coded for SIOCGIFCONF */
/* See 166-168 below for extended SIOC*XARP ioctls */
/* Both if and lif variants share same func */
/* Both if and lif variants share same func */
/* copyin size cannot be coded for SIOCGIFCONF */
#define SIOCLIFADDR_NDX 112
/* IPSECioctls handled in ip_sioctl_copyin_setup itself */
/* Leave 158-160 unused; used to be SIOC*IFARP ioctls */
/* These are handled in ip_sioctl_copyin_setup itself */
/* SIOCPOPSOCKFS is not handled by IP */
/* 172-174 are SCTP ioctls and not handled by IP */
ip_sioctl_get_lifusesrc, 0 },
NULL },
/* SIOCSENABLESDP is handled by SDP */
};
};
int ip_misc_ioctl_count =
sizeof (ip_misc_ioctl_table) / sizeof (ip_ioctl_cmd_t);
int conn_drain_nthreads; /* Number of drainers reqd. */
/* Defined in ip_ire.c */
static nv_t ire_nv_arr[] = {
{ IRE_BROADCAST, "BROADCAST" },
{ IRE_LOCAL, "LOCAL" },
{ IRE_LOOPBACK, "LOOPBACK" },
{ IRE_DEFAULT, "DEFAULT" },
{ IRE_PREFIX, "PREFIX" },
{ IRE_IF_NORESOLVER, "IF_NORESOL" },
{ IRE_IF_RESOLVER, "IF_RESOLV" },
{ IRE_IF_CLONE, "IF_CLONE" },
{ IRE_HOST, "HOST" },
{ IRE_MULTICAST, "MULTICAST" },
{ IRE_NOROUTE, "NOROUTE" },
{ 0 }
};
/* Simple ICMP IP Header Template */
IP_SIMPLE_HDR_VERSION, 0, 0, 0, 0, 0, IPPROTO_ICMP
};
struct module_info ip_mod_info = {
};
/*
* Duplicate static symbols within a module confuses mdb; so we avoid the
* problem by making the symbols here distinct from those in udp.c.
*/
/*
* Entry points for IP as a device and as a module.
*/
};
};
};
};
};
};
};
#ifdef DEBUG
#endif
/*
* Generate an ICMP fragmentation needed message.
* When called from ip_output side a minimal ip_recv_attr_t needs to be
* constructed by the caller.
*/
void
{
return;
}
/*
* icmp_inbound_v4 deals with ICMP messages that are handled by IP.
* If the ICMP message is consumed by IP, i.e., it should not be delivered
* to any IPPROTO_ICMP raw sockets, then it returns NULL.
* Likewise, if the ICMP error is misformed (too short, etc), then it
* returns NULL. The caller uses this to determine whether or not to send
* to raw sockets.
*
* All error messages are passed to the matching transport stream.
*
* The following cases are handled by icmp_inbound:
* 1) It needs to send a reply back and possibly delivering it
* to the "interested" upper clients.
* 2) Return the mblk so that the caller can pass it to the RAW socket clients.
* 3) It needs to change some values in IP only.
* 4) It needs to change some values in IP and upper layers e.g TCP
* by delivering an error to the upper layers.
*
* We handle the above three cases in the context of IPsec in the
* following way :
*
* 1) Send the reply back in the same way as the request came in.
* If it came in encrypted, it goes out encrypted. If it came in
* clear, it goes out in clear. Thus, this will prevent chosen
* plain text attack.
* 2) The client may or may not expect things to come in secure.
* If it comes in secure, the policy constraints are checked
* before delivering it to the upper layers. If it comes in
* clear, ipsec_inbound_accept_clear will decide whether to
* accept this in clear or not. In both the cases, if the returned
* message (IP header + 8 bytes) that caused the icmp message has
* sending up. If there are only 8 bytes of returned message, then
* upper client will not be notified.
* 3) Check with global policy to see whether it matches the constaints.
* But this will be done only if icmp_accept_messages_in_clear is
* zero.
* 4) If we need to change both in IP and ULP, then the decision taken
* while affecting the values in IP and while delivering up to TCP
* should be the same.
*
* There are two cases.
*
* a) If we reject data at the IP layer (ipsec_check_global_policy()
* failed), we will not deliver it to the ULP, even though they
* are *willing* to accept in *clear*. This is fine as our global
* disposition to icmp messages asks us reject the datagram.
*
* b) If we accept data at the IP layer (ipsec_check_global_policy()
* succeeded or icmp_accept_messages_in_clear is 1), and not able
* to deliver it to ULP (policy failed), it can lead to
* consistency problems. The cases known at this time are
* ICMP_DESTINATION_UNREACHABLE messages with following code
* values :
*
* - ICMP_FRAGMENTATION_NEEDED : IP adapts to the new value
* and Upper layer rejects. Then the communication will
* come to a stop. This is solved by making similar decisions
* at both levels. Currently, when we are unable to deliver
* to the Upper Layer (due to policy failures) while IP has
* adjusted dce_pmtu, the next outbound datagram would
* generate a local ICMP_FRAGMENTATION_NEEDED message - which
* will be with the right level of protection. Thus the right
* value will be communicated even if we are not able to
* communicate when we get from the wire initially. But this
* assumes there would be at least one outbound datagram after
* IP has adjusted its dce_pmtu value. To make things
* simpler, we accept in clear after the validation of
*
* - Other ICMP ERRORS : We may not be able to deliver it to the
* upper layer depending on the level of protection the upper
* layer expects and the disposition in ipsec_inbound_accept_clear().
* ipsec_inbound_accept_clear() decides whether a given ICMP error
* should be accepted in clear when the Upper layer expects secure.
* Thus the communication may get aborted by some bad ICMP
* packets.
*/
mblk_t *
{
int ip_hdr_length; /* Outer header length */
int len_needed;
return (NULL);
}
/* Last chance to get real. */
return (NULL);
}
}
/* The IP header will always be a multiple of four bytes */
icmph->icmph_code));
/*
* We will set "interested" to "true" if we should pass a copy to
* the transport or if we handle the packet locally.
*/
switch (icmph->icmph_type) {
case ICMP_ECHO_REPLY:
break;
case ICMP_DEST_UNREACHABLE:
break;
case ICMP_SOURCE_QUENCH:
break;
case ICMP_REDIRECT:
if (!ipst->ips_ip_ignore_redirect)
interested = B_TRUE;
break;
case ICMP_ECHO_REQUEST:
/*
* Whether to respond to echo requests that come in as IP
* broadcasts or as IP multicast is subject to debate
* (what isn't?). We aim to please, you pick it.
* Default is do it.
*/
/* multicast: respond based on tunable */
/* broadcast: respond based on tunable */
} else {
/* unicast: always respond */
interested = B_TRUE;
}
if (!interested) {
/* We never pass these to RAW sockets */
return (NULL);
}
/* Check db_ref to make sure we can modify the packet. */
if (!mp1) {
return (NULL);
}
}
return (NULL);
case ICMP_ROUTER_SOLICITATION:
break;
case ICMP_TIME_EXCEEDED:
break;
case ICMP_PARAM_PROBLEM:
break;
case ICMP_TIME_STAMP_REQUEST:
/* Response to Time Stamp Requests is local policy. */
if (ipst->ips_ip_g_resp_to_timestamp) {
else
interested = B_TRUE;
}
if (!interested) {
/* We never pass these to RAW sockets */
return (NULL);
}
/* Make sure we have enough of the packet */
3 * sizeof (uint32_t);
ip_drop_input("ipIfStatsInDiscards - ip_pullup",
return (NULL);
}
/* Refresh following the pullup. */
}
/* Check db_ref to make sure we can modify the packet. */
if (!mp1) {
return (NULL);
}
}
tsp++; /* Skip past 'originate time' */
/* Compute # of milliseconds since midnight */
gethrestime(&now);
return (NULL);
case ICMP_TIME_STAMP_REPLY:
break;
case ICMP_INFO_REQUEST:
/* Per RFC 1122 3.2.2.7, ignore this. */
case ICMP_INFO_REPLY:
break;
} else {
interested = B_TRUE;
}
if (!interested) {
/* We never pass these to RAW sockets */
return (NULL);
}
ill);
return (NULL);
}
/* Refresh following the pullup. */
}
/* Check db_ref to make sure we can modify the packet. */
if (!mp1) {
return (NULL);
}
}
/*
* Need the ipif with the mask be the same as the source
* address of the mask reply. For unicast we have a specific
* senders, and use the source address to pick an ipif.
*/
/* Broadcast or multicast */
return (NULL);
}
}
return (NULL);
case ICMP_ADDRESS_MASK_REPLY:
break;
default:
break;
}
/*
* if there isn't one.
*/
/* If there is an ICMP client and we want one too, copy it. */
if (!interested) {
/* Caller will deliver to RAW sockets */
return (mp);
}
}
} else if (!interested) {
/* Neither we nor raw sockets are interested. Drop packet now */
return (NULL);
}
/*
* ICMP error or redirect packet. Make sure we have enough of
* the header and that db_ref == 1 since we might end up modifying
* the packet.
*/
ip_drop_input("ipIfStatsInDiscards - ip_pullup",
return (mp_ret);
}
}
return (mp_ret);
}
}
/*
* In case mp has changed, verify the message before any further
* processes.
*/
return (mp_ret);
}
switch (icmph->icmph_type) {
case ICMP_REDIRECT:
break;
case ICMP_DEST_UNREACHABLE:
/* Update DCE and adjust MTU is icmp header if needed */
}
/* FALLTHRU */
default:
break;
}
return (mp_ret);
}
/*
* Send an ICMP echo, timestamp or address mask reply.
* The caller has already updated the payload part of the packet.
* We handle the ICMP checksum, IP source address selection and feed
* the packet into ip_output_simple.
*/
static void
{
/* Send out an ICMP packet */
icmph->icmph_checksum = 0;
/* Reset time to live. */
{
/* Swap source and destination addresses */
}
ipha->ipha_ident = 0;
if (!IS_SIMPLE_IPH(ipha))
ixas.ixa_ifindex = 0;
/*
* This packet should go out the same way as it
* came in i.e in clear, independent of the IPsec policy
* for transmitting packets.
*/
} else {
/* Note: mp already consumed and ip_drop_packet done */
return;
}
}
/*
* Not one or our addresses (IRE_LOCALs), thus we let
* ip_output_simple pick the source.
*/
}
/* Should we send with DF and use dce_pmtu? */
if (ipst->ips_ipv4_icmp_return_pmtu) {
}
ixa_cleanup(&ixas);
}
/*
* Verify the ICMP messages for either for ICMP error or redirect packet.
* The caller should have fully pulled up the message. If it's a redirect
* packet, only basic checks on IP header will be done; otherwise, verify
* the packet by looking at the included ULP header.
*
* Called before icmp_inbound_error_fanout_v4 is called.
*/
static boolean_t
{
int hdr_length;
goto truncated;
goto discard_pkt;
if (hdr_length < sizeof (ipha_t))
goto truncated;
goto truncated;
/*
* Stop here for ICMP_REDIRECT.
*/
return (B_TRUE);
/*
* ICMP errors only.
*/
switch (ipha->ipha_protocol) {
case IPPROTO_UDP:
/*
* Verify we have at least ICMP_MIN_TP_HDR_LEN bytes of
* transport header.
*/
goto truncated;
break;
case IPPROTO_TCP: {
/*
* Verify we have at least ICMP_MIN_TP_HDR_LEN bytes of
* transport header.
*/
goto truncated;
ipst);
goto discard_pkt;
goto discard_pkt;
}
break;
}
case IPPROTO_SCTP:
/*
* Verify we have at least ICMP_MIN_TP_HDR_LEN bytes of
* transport header.
*/
goto truncated;
break;
case IPPROTO_ESP:
case IPPROTO_AH:
break;
case IPPROTO_ENCAP:
goto truncated;
break;
default:
break;
}
return (B_TRUE);
/* Bogus ICMP error. */
return (B_FALSE);
/* We pulled up everthing already. Must be truncated */
return (B_FALSE);
}
/* Table from RFC 1191 */
static int icmp_frag_size_table[] =
{ 32000, 17914, 8166, 4352, 2002, 1496, 1006, 508, 296, 68 };
/*
* Process received ICMP Packet too big.
* PMTU guesses. The caller is responsible for validating the packet before
* passing it in and also to fanout the ICMP error to any matching transport
* conns. Assumes the message has been fully pulled up and verified.
*
* Before getting here, the caller has called icmp_inbound_verify_v4()
* that should have verified with ULP to prevent undoing the changes we're
* going to make to DCE. For example, TCP might have verified that the packet
* which generated error is in the send window.
*
* In some cases modified this MTU in the ICMP header packet; the caller
* should pass to the matching ULP after this returns.
*/
static void
{
int old_mtu;
/* Caller already pulled up everything. */
/*
* We handle path MTU for source routed packets since the DCE
* is looked up using the final destination.
*/
/* Couldn't add a unique one - ENOMEM */
ip1dbg(("icmp_inbound_too_big_v4: no dce for 0x%x\n",
return;
}
/* Check for MTU discovery advice as described in RFC 1191 */
else
int i;
/*
* Use the table from RFC 1191 to figure out
* the next "plateau" based on the length in
* the original IP packet.
*/
/*
* Handle broken BSD 4.2 systems that
* return the wrong ipha_length in ICMP
* errors.
*/
ip1dbg(("Wrong mtu: sent %d, dce %d\n",
length -= hdr_length;
}
for (i = 0; i < A_CNT(icmp_frag_size_table); i++) {
if (length > icmp_frag_size_table[i])
break;
}
if (i == A_CNT(icmp_frag_size_table)) {
/* Smaller than IP_MIN_MTU! */
ip1dbg(("Too big for packet size %d\n",
length));
} else {
mtu = icmp_frag_size_table[i];
ip1dbg(("Calculated mtu %d, packet size %d, "
}
}
}
if (disable_pmtud)
else
/* Prepare to send the new max frag size for the ULP. */
icmph->icmph_du_zero = 0;
/* We now have a PMTU for sure */
/*
* After dropping the lock the new value is visible to everyone.
* Then we bump the generation number so any cached values reinspect
* the dce_t.
*/
}
/*
* If the packet in error is Self-Encapsulated, icmp_inbound_error_fanout_v4
* calls this function.
*/
static mblk_t *
{
int length;
/* icmp_inbound_v4 has already pulled up the whole error packet */
/*
* The length that we want to overlay is the inner header
* and what follows it.
*/
/*
* Overlay the inner header and whatever follows it over the
* outer header.
*/
/* Adjust for what we removed */
return (mp);
}
/*
* Try to pass the ICMP message upstream in case the ULP cares.
*
* If the packet that caused the ICMP error is secure, we send
* valid association. ipha in the code below points to the
* IP header of the packet that caused the error.
*
* For IPsec cases, we let the next-layer-up (which has access to
* cached policy on the conn_t, or can query the SPD directly)
* subtract out any IPsec overhead if they must. We therefore make no
* adjustments here for IPsec overhead.
*
* IFN could have been generated locally or by some router.
*
* LOCAL : ire_send_wire (before calling ipsec_out_process) can call
* icmp_frag_needed/icmp_pkt2big_v6 to generated a local IFN.
* This happens because IP adjusted its value of MTU on an
* earlier IFN message and could not tell the upper layer,
* the new adjusted value of MTU e.g. Packet was encrypted
* or there was not enough information to fanout to upper
* layers. Thus on the next outbound datagram, ire_send_wire
* generates the IFN, where IPsec processing has *not* been
* done.
*
* Note that we retain ixa_fragsize across IPsec thus once
* we have picking ixa_fragsize and entered ipsec_out_process we do
* no change the fragsize even if the path MTU changes before
* we reach ip_output_post_ipsec.
*
* In the local case, IRAF_LOOPBACK will be set indicating
* that IFN was generated locally.
*
* ROUTER : IFN could be secure or non-secure.
*
* not and send it back. We will fanout again if we have more
* data in the packet.
*
* like any other case.
*
* valid SA or not and send it back. We will fanout again if
* we have more data in the packet.
*
* like any other case.
*
* The caller must have called icmp_inbound_verify_v4.
*/
static void
{
/* Caller already pulled up everything. */
/*
* We need a separate IP header with the source and destination
* addresses reversed to do fanout/classification because the ipha in
* the ICMP error is in the form we sent it out.
*/
ip2dbg(("icmp_inbound_error_v4: proto %d %x to %x: %d/%d\n",
switch (ipha->ipha_protocol) {
case IPPROTO_UDP:
/* Attempt to find a client stream based on port. */
ip2dbg(("icmp_inbound_error_v4: UDP ports %d to %d\n",
/* Note that we send error to all matches. */
return;
case IPPROTO_TCP:
/*
* Find a TCP client stream for this packet.
* Note that we do a reverse lookup since the header is
* in the form we sent it out.
*/
ipst);
goto discard_pkt;
/* Note that mp is NULL */
return;
}
}
if (IPCL_IS_TCP(connp)) {
} else {
/* Not TCP; must be SOCK_RAW, IPPROTO_TCP */
}
return;
case IPPROTO_SCTP:
/* Find a SCTP client stream for this packet. */
return;
case IPPROTO_ESP:
case IPPROTO_AH:
if (!ipsec_loaded(ipss)) {
return;
}
else
return;
/* Just in case ipsec didn't preserve the NULL b_cont */
goto discard_pkt;
}
/*
* Note that ira_pktlen and ira_ip_hdr_length are no longer
* correct, but we don't use them any more here.
*
* If succesful, the mp has been modified to not include
* error handler.
*/
goto truncated;
/* Verify the modified message before any further processes. */
return;
}
return;
case IPPROTO_ENCAP: {
/* Look for self-encapsulated packets that caused an error */
/*
* Caller has verified that length has to be
* at least the size of IP header.
*/
/*
* Check the sanity of the inner IP header like
* we did for the outer header.
*/
goto discard_pkt;
}
goto discard_pkt;
}
/* Check for Self-encapsulated tunnels */
in_ipha);
goto discard_pkt;
/*
* Just in case self_encap didn't preserve the NULL
* b_cont
*/
goto discard_pkt;
}
/*
* Note that ira_pktlen and ira_ip_hdr_length are no
* longer correct, but we don't use them any more here.
*/
goto truncated;
/*
* Verify the modified message before any further
* processes.
*/
return;
}
/*
* The packet in error is self-encapsualted.
* And we are finding it further encapsulated
* which we could not have possibly generated.
*/
goto discard_pkt;
}
return;
}
/* No self-encapsulated */
/* FALLTHRU */
}
case IPPROTO_IPV6:
return;
}
/*
* No IP tunnel is interested, fallthrough and see
* if a raw socket will want it.
*/
/* FALLTHRU */
default:
return;
}
/* NOTREACHED */
ip1dbg(("icmp_inbound_error_fanout_v4: drop pkt\n"));
return;
/* We pulled up everthing already. Must be truncated */
}
/*
* Common IP options parser.
*
* Setup routine: fill in *optp with options-parsing state, then
* tail-call ipoptp_next to return the first option.
*/
{
totallen <<= 2;
optp->ipoptp_flags = 0;
return (ipoptp_next(optp));
}
/* Like above but without an ipha_t */
{
optp->ipoptp_flags = 0;
return (ipoptp_next(optp));
}
/*
* Common IP options parser: extract next option.
*/
{
/*
* If cur > end already, then the ipoptp_end or ipoptp_next pointer
* has been corrupted.
*/
return (IPOPT_EOL);
/*
* Skip any NOP options.
*/
cur++;
return (IPOPT_EOL);
}
return (IPOPT_EOL);
/*
* Option requiring a length.
*/
return (IPOPT_EOL);
}
if (len < 2) {
return (IPOPT_EOL);
}
return (IPOPT_EOL);
}
/*
* For the options which require a pointer field, make sure
* its there, and make sure it points to either something
* inside this option, or the end of the option.
*/
switch (opt) {
case IPOPT_RR:
case IPOPT_TS:
case IPOPT_LSRR:
case IPOPT_SSRR:
if (len <= IPOPT_OFFSET) {
return (opt);
}
return (opt);
}
break;
}
/*
* Sanity check the pointer field based on the type of the
* option.
*/
switch (opt) {
case IPOPT_RR:
case IPOPT_SSRR:
case IPOPT_LSRR:
if (pointer < IPOPT_MINOFF_SR)
break;
case IPOPT_TS:
if (pointer < IPOPT_MINOFF_IT)
/*
* Note that the Internet Timestamp option also
* contains two four bit fields (the Overflow field,
* and the Flag field), which follow the pointer
* field. We don't need to check that these fields
* fall within the length of the option because this
* was implicitely done above. We've checked that the
* pointer value is at least IPOPT_MINOFF_IT, and that
* it falls within the option. Since IPOPT_MINOFF_IT >
* IPOPT_POS_OV_FLG, we don't need the explicit check.
*/
break;
}
return (opt);
}
/*
* Use the outgoing IP header to create an IP_OPTIONS option the way
* it was passed down from the application.
*
* This is compatible with BSD in that it returns
* the reverse source route with the final destination
* as the last entry. The first 4 bytes of the option
* will contain the final destination.
*/
int
{
return (0);
if (totallen & 0x3)
return (0);
len += IP_ADDR_LEN;
int off;
break;
}
switch (optval) {
case IPOPT_SSRR:
case IPOPT_LSRR:
/*
* Insert destination as the first entry in the source
* route and move down the entries on step.
* The last entry gets placed at buf1.
*/
if (off < 0) {
/* No entries in source route */
break;
}
/* Last entry in source route if not already set */
if (dst == INADDR_ANY)
off -= IP_ADDR_LEN;
while (off > 0) {
off -= IP_ADDR_LEN;
}
/* ipha_dst into first slot */
break;
default:
break;
}
}
done:
/* Pad the resulting options */
while (len & 0x3) {
len++;
}
return (len);
}
/*
* Update any record route or timestamp options to include this host.
* Reverse any source route option.
* This routine assumes that the options are well formed i.e. that they
* have already been checked.
*/
static void
{
ip2dbg(("icmp_options_update\n"));
ip2dbg(("icmp_options_update: opt %d, len %d\n",
switch (optval) {
case IPOPT_SSRR:
case IPOPT_LSRR:
/*
* Reverse the source route. The first entry
* should be the next to last one in the current
* source route (the last entry is our address).
* The last entry should be the final destination.
*/
if (off2 < 0) {
/* No entries in source route */
ip1dbg((
"icmp_options_update: bad src route\n"));
break;
}
off2 -= IP_ADDR_LEN;
off1 += IP_ADDR_LEN;
off2 -= IP_ADDR_LEN;
}
break;
}
}
}
/*
* Process received ICMP Redirect messages.
* Assumes the caller has verified that the headers are in the pulled up mblk.
* Consumes mp.
*/
static void
{
/* Caller already pulled up everything. */
/* Make sure the new gateway is reachable somehow. */
/*
* Make sure we had a route for the dest in question and that
* that route was pointing to the old gateway (the source of the
* redirect packet.)
* We do longest match and then compare ire_gateway_addr below.
*/
/*
* Check that
* the redirect was not from ourselves
* the new gateway and the old gateway are directly reachable
*/
return;
}
/*
* TODO: more precise handling for cases 0, 2, 3, the latter two
* require TOS routing
*/
switch (icmph->icmph_code) {
case 0:
case 1:
/* TODO: TOS specificity for cases 2 and 3 */
case 2:
case 3:
break;
default:
return;
}
/*
* Create a Route Association. This will allow us to remember that
* someone we believe told us to use the particular gateway.
*/
ire = ire_create(
NULL, /* ill */
NULL, /* tsol_gc_t */
ipst);
return;
}
/* Check if it was a duplicate entry */
}
/* tell routing sockets that we received a redirect */
}
/*
* Delete any existing IRE_HOST type redirect ires for this destination.
* This together with the added IRE has the effect of
* modifying an existing redirect.
*/
}
}
/*
* Generate an ICMP parameter problem message.
* When called from ip_output side a minimal ip_recv_attr_t needs to be
* constructed by the caller.
*/
static void
{
return;
}
/*
* Build and ship an IPv4 ICMP message using the packet data in mp, and
* the ICMP header pointed to by "stuff". (May be called as writer.)
* Note: assumes that icmp_pkt_err_ok has been called to verify that
* an icmp error packet can be sent.
* Assigns an appropriate source address to the packet. If ipha_dst is
* one of our addresses use it for source. Otherwise let ip_output_simple
* pick the source address.
*/
static void
{
ixas.ixa_ifindex = 0;
/*
* Apply IPsec based on how IPsec was applied to
* the packet that had the error.
*
* If it was an outbound packet that caused the ICMP
* error, then the caller will have setup the IRA
* appropriately.
*/
/* Note: mp already consumed and ip_drop_packet done */
return;
}
} else {
/*
* This is in clear. The icmp message we are building
* here should go out in clear, independent of our policy.
*/
}
/* Remember our eventual destination */
/*
* If the packet was for one of our unicast addresses, make
* sure we respond with that as the source. Otherwise
* have ip_output_simple pick the source address.
*/
} else {
src = INADDR_ANY;
}
/*
* Check if we can send back more then 8 bytes in addition to
* the IP header. We try to send 64 bytes of data and the internal
* header in the special cases of ipv4 encapsulated ipv4 or ipv6.
*/
return;
}
len_needed));
} else {
}
}
if (msg_len > len_needed) {
}
return;
}
/*
* Set IXAF_TRUSTED_ICMP so we can let the ICMP messages this
* node generates be accepted in peace by all on-host destinations.
* If we do NOT assume that all on-host destinations trust
* (Look for IXAF_TRUSTED_ICMP).
*/
if (msg_len > IP_MAXPACKET) {
}
icmph->icmph_checksum = 0;
ixa_cleanup(&ixas);
}
/*
* Determine if an ICMP error packet can be sent given the rate limit.
* The limit consists of an average frequency (icmp_pkt_err_interval measured
* in milliseconds) and a burst size. Burst size number of packets can
* be sent arbitrarely closely spaced.
* The state is tracked using two variables to implement an approximate
* token bucket filter:
* icmp_pkt_err_last - lbolt value when the last burst started
* icmp_pkt_err_sent - number of packets sent in current burst
*/
{
/* Guard against changes by loading into local variable */
if (err_interval == 0)
return (B_FALSE);
/* 100HZ lbolt in ms for 32bit arch wraps every 49.7 days */
ipst->ips_icmp_pkt_err_last = 0;
ipst->ips_icmp_pkt_err_sent = 0;
}
/*
* If we are in a burst update the token bucket filter.
* Update the "last" time to be close to "now" but make sure
* we don't loose precision.
*/
if (ipst->ips_icmp_pkt_err_sent != 0) {
ipst->ips_icmp_pkt_err_sent = 0;
} else {
}
}
if (ipst->ips_icmp_pkt_err_sent == 0) {
/* Start of new burst */
}
ip1dbg(("icmp_err_rate_limit: %d sent in burst\n",
return (B_FALSE);
}
ip1dbg(("icmp_err_rate_limit: dropped\n"));
return (B_TRUE);
}
/*
* Check if it is ok to send an IPv4 ICMP error packet in
* response to the IPv4 packet in mp.
* Free the message and return null if no
* ICMP error packet should be sent.
*/
static mblk_t *
{
if (!mp)
return (NULL);
if (ip_csum_hdr(ipha)) {
return (NULL);
}
/* Note: only errors to the fragment with offset 0 */
return (NULL);
}
/*
* Check the ICMP type. RFC 1122 sez: don't send ICMP
* errors in response to any ICMP errors.
*/
return (NULL);
}
}
switch (icmph->icmph_type) {
case ICMP_DEST_UNREACHABLE:
case ICMP_SOURCE_QUENCH:
case ICMP_TIME_EXCEEDED:
case ICMP_PARAM_PROBLEM:
case ICMP_REDIRECT:
return (NULL);
default:
break;
}
}
/*
* If this is a labeled system, then check to see if we're allowed to
* send a response to this particular sender. If not, then just drop.
*/
ip2dbg(("icmp_pkt_err_ok: can't respond to packet\n"));
return (NULL);
}
if (icmp_err_rate_limit(ipst)) {
/*
* Only send ICMP error packets every so often.
* but for now this will suffice.
*/
return (NULL);
}
return (mp);
}
/*
* Called when a packet was sent out the same link that it arrived on.
* Check if it is ok to send a redirect and then send it.
*/
void
{
/*
* Check the source address to see if it originated
* on the same logical subnet it is going back out on.
* If so, we should be able to send it a redirect.
* Avoid sending a redirect if the destination
* is directly connected (i.e., we matched an IRE_ONLINK),
* or if the packet was source routed out this interface.
*
* We avoid sending a redirect if the
* destination is directly connected
* because it is possible that multiple
* IP subnets may have been configured on
* the link, and the source may not
* be on the same subnet as ip destination,
* even though they are on the same
* physical link.
*/
return;
return;
/* Follow ire_dep_parent to find non-clone IRE_INTERFACE */
}
return;
/*
* We look at the interface ire for the nexthop,
* to see if ipha_src is in the same subnet
* as the nexthop.
*/
/*
* The source is directly connected.
*/
}
}
}
/*
* Generate an ICMP redirect message.
*/
static void
{
return;
}
/*
* Generate an ICMP time exceeded message.
*/
void
{
return;
}
/*
* Generate an ICMP unreachable message.
* When called from ip_output side a minimal ip_recv_attr_t needs to be
* constructed by the caller.
*/
void
{
return;
}
/*
* Latch in the IPsec state for a stream based the policy in the listener
* and the actions in the ip_recv_attr_t.
* Called directly from TCP and SCTP.
*/
{
return (B_FALSE);
}
}
return (B_TRUE);
}
/*
* Verify whether or not the IP address is a valid local address.
* Could be a unicast, including one for a down interface.
* If allow_mcbc then a multicast or broadcast address is also
* acceptable.
*
* upper protocol is expected to reset the src address
* to zero when we return IPVL_MCAST/IPVL_BCAST so that
* source address (that violates hosts requirements RFC 1122)
* The addresses valid for bind are:
* (1) - INADDR_ANY (0)
* (2) - IP address of an UP interface
* (3) - IP address of a DOWN interface
* (4) - valid local IP broadcast addresses. In this case
* the conn will only receive packets destined to
* the specified broadcast address.
* (5) - a multicast address. In this case
* the conn will only receive packets destined to
* the specified multicast address. Note: the
* application still has to issue an
* IP_ADD_MEMBERSHIP socket option.
*
* In all the above cases, the bound address must be valid in the current zone.
* When the address is loopback, multicast or broadcast, there might be many
* matching IREs so bind has to look up based on the zone.
*/
{
/*
* If an address other than in6addr_any is requested,
* we verify that it is a valid address for bind
* Note: Following code is in if-else-if form for
* readability compared to a condition check.
*/
/*
* (2) Bind to address of local UP interface
*/
return (IPVL_UNICAST_UP);
/*
* (4) Bind to broadcast address
*/
if (allow_mcbc)
return (IPVL_BCAST);
else
return (IPVL_BAD);
/* (5) bind to multicast address. */
if (allow_mcbc)
return (IPVL_MCAST);
else
return (IPVL_BAD);
} else {
/*
* (3) Bind to address of local DOWN interface?
* (ipif_lookup_addr() looks up all interfaces
* but we do not get here for UP interfaces
* - case (2) above)
*/
return (IPVL_BAD);
/* Not a useful source? */
return (IPVL_BAD);
}
return (IPVL_UNICAST_DOWN);
}
}
/*
* Insert in the bind fanout for IPv4 and IPv6.
* The caller should already have used ip_laddr_verify_v*() before calling
* this.
*/
int
{
int error;
/*
* Allow setting new policies. For example, disconnects result
* in us being called. As we would have set conn_policy_cached
* to B_TRUE before, we should set it to B_FALSE, so that policy
* can change after the disconnect.
*/
if (error != 0) {
if (connp->conn_anon_port) {
}
}
return (error);
}
/*
* Verify that both the source and destination addresses are valid. If
* IPDF_VERIFY_DST is not set, then the destination address may be unreachable,
* i.e. have no route to it. Protocols like TCP want to verify destination
* reachability, while tunnels do not.
*
* Determine the route, the interface, and (optionally) the source address
* to use to reach a given destination.
* Note that we allow connect to broadcast and multicast addresses when
* IPDF_ALLOW_MCBC is set.
* first_hop and dst_addr are normally the same, but if source routing
* they will differ; in that case the first_hop is what we'll use for the
* routing lookup but the dce and label checks will be done on dst_addr,
*
* If uinfo is set, then we fill in the best available information
* we have for the destination. This is based on (in priority order) any
* metrics and path MTU stored in a dce_t, route metrics, and finally the
* ill_mtu.
*
* Tsol note: If we have a source route then dst_addr != firsthop. But we
* always do the label check on dst_addr.
*/
int
{
int error = 0;
/*
* We never send to zero; the ULPs map it to the loopback address.
* We can't allow it since we use zero to mean unitialized in some
* places.
*/
if (is_system_labeled()) {
if (error != 0)
return (error);
/* Update the label */
}
}
setsrc = INADDR_ANY;
/*
* Select a route; For IPMP interfaces, we would only select
* a "hidden" route (i.e., going through a specific under_ill)
* if ixa_ifindex has been specified.
*/
&multirt);
if (error != 0)
goto bad_addr;
/*
* ire can't be a broadcast or multicast unless IPDF_ALLOW_MCBC is set.
* If IPDF_VERIFY_DST is set, the destination must be reachable;
* Otherwise the destination needn't be reachable.
*
* If we match on a reject or black hole, then we've got a
* local failure. May as well fail out the connect() attempt,
* since it's never going to succeed.
*/
/*
* If we're verifying destination reachability, we always want
* to complain here.
*
* If we're not verifying destination reachability but the
* destination has a route, we still want to fail on the
* temporary address and broadcast address tests.
*
* In both cases do we let the code continue so some reasonable
* information is returned to the caller. That enables the
* caller to use (and even cache) the IRE. conn_ip_ouput will
* use the generation mismatch path to check for the unreachable
* case thereby avoiding any specific check in the main path.
*/
if (flags & IPDF_VERIFY_DST) {
/*
* Set errno but continue to set up ixa_ire to be
* the RTF_REJECT|RTF_BLACKHOLE IRE.
* That allows callers to use ip_output to get an
* ICMP error back.
*/
error = ENETUNREACH;
else
}
}
!(flags & IPDF_ALLOW_MCBC)) {
error = ENETUNREACH;
}
/* Cache things */
#ifdef DEBUG
#endif
/*
* For multicast with multirt we have a flag passed back from
* ire_lookup_multi_ill_v4 since we don't have an IRE for each
* possible multicast address.
* We also need a flag for multicast since we can't check
* whether RTF_MULTIRT is set in ixa_ire for multicast.
*/
if (multirt) {
} else {
}
/* Get an nce to cache. */
/* Allocation failure? */
} else {
}
}
/*
* If the source address is a loopback address, the
* destination had best be local or multicast.
* If we are sending to an IRE_LOCAL using a loopback source then
* it had better be the same zoneid.
*/
goto bad_addr;
}
goto bad_addr;
}
}
/*
* If the ULP didn't have a specified source, then we
* make sure we reselect the source when sending
* broadcasts out different interfaces.
*/
if (flags & IPDF_SELECT_SRC)
else
}
/*
* Does the caller want us to pick a source address?
*/
if (flags & IPDF_SELECT_SRC) {
/*
* We use use ire_nexthop_ill to avoid the under ipmp
* interface for source address selection. Note that for ipmp
* probe packets, ixa_ifindex would have been specified, and
* the ip_select_route() invocation would have picked an ire
* will ire_ill pointing at an under interface.
*/
/* If unreachable we have no ill but need some source */
/* Make sure we look for a better source address */
} else {
if (error != 0) {
goto bad_addr;
}
}
/*
* We allow the source address to to down.
* However, we check that we don't use the loopback address
* as a source when sending out on the wire.
*/
goto bad_addr;
}
}
if (flags & IPDF_UNIQUE_DCE) {
/* Fallback to the default dce if allocation fails */
else
} else {
}
#ifdef DEBUG
#endif
/*
* Make sure we don't leave an unreachable ixa_nce in place
* since ip_select_route is used when we unplumb i.e., remove
* references on ixa_ire, ixa_nce, and ixa_dce.
*/
}
/*
* The caller has set IXAF_PMTU_DISCOVERY if path MTU is desired.
* However, we can't do it for IPv4 multicast or broadcast.
*/
/*
* Set initial value for fragmentation limit. Either conn_ip_output
* or ULP might updates it when there are routing changes.
* Handles a NULL ixa_ire->ire_ill or a NULL ixa_nce for RTF_REJECT.
*/
/* Make sure ixa_fragsize and ixa_pmtu remain identical */
/*
* Extract information useful for some transports.
* First we look for DCE metrics. Then we take what we have in
* the metrics in the route, where the offlink is used if we have
* one.
*/
/* Allow ire_metrics to decrease the path MTU from above */
}
return (error);
/*
* Make sure we don't leave an unreachable ixa_nce in place
* since ip_select_route is used when we unplumb i.e., remove
* references on ixa_ire, ixa_nce, and ixa_dce.
*/
}
return (error);
}
/*
* Get the base MTU for the case when path MTU discovery is not used.
* Takes the MTU of the IRE into account.
*/
{
return (mtu);
}
/*
* Get the PMTU for the attributes. Handles both IPv4 and IPv6.
* Assumes that ixa_ire, dce, and nce have already been set up.
*
* The caller has set IXAF_PMTU_DISCOVERY if path MTU discovery is desired.
* We avoid path MTU discovery if it is disabled with ndd.
* Furtermore, if the path MTU is too small, then we don't set DF for IPv4.
*
* NOTE: We also used to turn it off for source routed packets. That
* is no longer required since the dce is per final destination.
*/
{
/*
* If path MTU discovery has been turned off by ndd, then we ignore
* any dce_pmtu and for IPv4 we will not set DF.
*/
if (!ipst->ips_ip_path_mtu_discovery)
pmtu = IP_MAXPACKET;
/*
* Decide whether whether IPv4 sets DF
* For IPv6 "no DF" means to use the 1280 mtu
*/
} else {
pmtu = IPV6_MIN_MTU;
}
/* Check if the PMTU is to old before we use it */
/*
* Older than 20 minutes. Drop the path MTU information.
*/
}
/* The metrics on the route can lower the path MTU */
/*
* If the path MTU is smaller than some minimum, we still use dce_pmtu
* above (would be 576 for IPv4 and 1280 for IPv6), but we clear
* IXAF_PMTU_IPV4_DF so that we avoid setting DF for IPv4.
*/
} else {
}
} else {
}
}
/*
* If we have an IRE_LOCAL we use the loopback mtu instead of
* the ill for going out the wire i.e., IRE_LOCAL gets the same
* mtu as IRE_LOOPBACK.
*/
if (loopback_mtu < pmtu)
pmtu = loopback_mtu;
/*
* Make sure we don't exceed the interface MTU.
* In the case of RTF_REJECT or RTF_BLACKHOLE we might not have
* an ill. We'd use the above IP_MAXPACKET in that case just
* to tell the transport something larger than zero.
*/
/*
* for interfaces in an IPMP group, the mtu of
* the nce_ill (under_ill) could be different
* from the mtu of the ncec_ill, so we take the
* min of the two.
*/
}
}
/*
* Handle the IPV6_USE_MIN_MTU socket option or ancillary data.
* Only applies to IPv6.
*/
switch (ixa->ixa_use_min_mtu) {
pmtu = IPV6_MIN_MTU;
break;
case IPV6_USE_MIN_MTU_ALWAYS:
pmtu = IPV6_MIN_MTU;
break;
case IPV6_USE_MIN_MTU_NEVER:
break;
}
} else {
/* Default is IPV6_USE_MIN_MTU_MULTICAST */
pmtu = IPV6_MIN_MTU;
}
}
/*
* After receiving an ICMPv6 "packet too big" message with a
* MTU < 1280, and for multirouted IPv6 packets, the IP layer
* will insert a 8-byte fragment header in every packet. We compensate
* for those cases by returning a smaller path MTU to the ULP.
*
* In the case of CGTP then ip_output will add a fragment header.
* Make sure there is room for it by telling a smaller number
* to the transport.
*
* When IXAF_IPV6_ADDR_FRAGHDR we subtract the frag hdr here
* so the ULPs consistently see a iulp_pmtu and ip_get_pmtu()
* which is the size of the packets it can send.
*/
pmtu -= sizeof (ip6_frag_t);
}
}
return (pmtu);
}
/*
* Carve "len" bytes out of an mblk chain, consuming any we empty, and duping
* the final piece where we don't. Return a pointer to the first mblk in the
* result, and update the pointer to the next mblk to chew on. If anything
* goes wrong (i.e., dupb fails), we waste everything in sight and return a
* NULL pointer.
*/
mblk_t *
{
return (NULL);
/* If we aren't going to consume the first mblk, we need a dup. */
if (mp1) {
/* Partition the data between the two mblks. */
/*
* after adjustments if mblk not consumed is now
* unaligned, try to align it. If this fails free
* all messages and let upper layer recover.
*/
return (NULL);
}
}
}
return (mp1);
}
/* Eat through as many mblks as we need to get len bytes. */
/*
* We won't consume the entire last mblk. Like
* above, dup and partition it.
*/
if (!mp1) {
/*
* Trouble. Rather than go to a lot of
* trouble to clean up, we free the messages.
* This won't be any worse than losing it on
* the wire.
*/
return (NULL);
}
/*
* after adjustments if mblk not consumed is now
* unaligned, try to align it. If this fails free
* all messages and let upper layer recover.
*/
return (NULL);
}
}
return (mp0);
}
/* Decrement len by the amount we just got. */
}
/*
* len should be reduced to zero now. If not our caller has
* screwed up.
*/
if (len) {
/* Shouldn't happen! */
return (NULL);
}
/*
* We consumed up to exactly the end of an mblk. Detach the part
* we are returning from the rest of the chain.
*/
return (mp0);
}
/* The ill stream is being unplumbed. Called from ip_close */
int
{
int i;
/*
* The punlink prior to this may have initiated a capability
* negotiation. But ipsq_enter will block until that finishes or
* times out.
*/
/*
* per stream by STREAMS. FS guarantees that all references
* from top are gone before close is called. So there can't
* be another close thread that has set CONDEMNED on this ill.
* and cause ipsq_enter to return failure.
*/
/*
* Mark it condemned. No new reference will be made to this ill.
* Lookup functions will return an error. Threads that try to
* increment the refcnt must check for ILL_CAN_LOOKUP. This ensures
* that the refcnt will drop down to zero.
*/
}
/*
* Wake up anybody waiting to enter the ipsq. ipsq_enter
* returns error if ILL_CONDEMNED is set
*/
/*
* Send all the deferred DLPI messages downstream which came in
* during the small window right before ipsq_enter(). We do this
* without waiting for the ACKs because all the ACKs for M_PROTO
* messages are ignored in ip_rput() when ILL_CONDEMNED is set.
*/
/*
* Shut down fragmentation reassembly.
* ill_frag_timer won't start a timer again.
* Now cancel any existing timer
*/
(void) ill_frag_timeout(ill, 0);
/*
* Call ill_delete to bring down the ipifs, ilms and ill on
* this ill. Then wait for the refcnts to drop to zero.
* ill_is_freeable checks whether the ill is really quiescent.
* Then make sure that threads that are waiting to enter the
* ipsq have seen the error returned by ipsq_enter and have
* gone away. Then we call ill_delete_tail which does the
* DL_UNBIND_REQ with the driver and then qprocsoff.
*/
while (!ill_is_freeable(ill))
while (ill->ill_waiters)
/*
* ill_delete_tail drops reference on ill_ipst, but we need to keep
* it held until the end of the function since the cleanup
* below needs to be able to use the ip_stack_t.
*/
/* qprocsoff is done via ill_delete_tail */
/*
* synchronously wait for arp stream to unbind. After this, we
* cannot get any data packets up from the driver.
*/
/*
* Walk through all conns and qenable those that have queued data.
* Close synchronization needs this to
* be done to ensure that all upper layers blocked
* due to flow control to the closing device
* get unblocked.
*/
ip1dbg(("ip_wsrv: walking\n"));
for (i = 0; i < TX_FANOUT_SIZE; i++) {
}
/*
* ai can be null if this is an IPv6 ill, or if the IPv4
* stream is being torn down before ARP was plumbed (e.g.,
* an error
*/
} else {
}
}
/*
* credp could be null if the open didn't succeed and ip_modopen
* itself calls ip_close.
*/
/*
* Now we are done with the module close pieces that
* need the netstack_t.
*/
return (0);
}
/*
* This is called as part of close() for IP, UDP, ICMP, and RTS
* in order to quiesce the conn.
*/
void
{
/*
* Mark the conn as closing, and this conn must not be
* inserted in future into any list. Eg. conn_drain_insert(),
* won't insert this conn into the conn_drain_list.
*
* conn_idl, and conn_ilg cannot get set henceforth.
*/
}
connp->conn_anon_port = 0;
}
/*
* Remove this conn from any fanout list it is on.
* and then wait for any threads currently operating
* on this endpoint to finish
*/
/*
* Remove this conn from the drain list, and do
* any other cleanup that may be required.
* (Only non-tcp conns may have a non-null conn_idl.
* TCP conns are never flow controlled, and
* conn_idl will be null)
*/
}
(void) ip_mrouter_done(ipst);
if (ilg_cleanup_reqd)
/*
* Now conn refcnt can increase only thru CONN_INC_REF_LOCKED.
* callers from write side can't be there now because close
* is in progress. The only other caller is ipcl_walk
* which checks for the condemned flag.
*/
}
/* ARGSUSED */
int
{
/*
* Call the appropriate delete routine depending on whether this is
* a module or device.
*/
/* This is a module close */
}
qprocsoff(q);
/*
* Now we are truly single threaded on this stream, and can
* delete the things hanging off the connp, and finally the connp.
* We removed this connp from the fanout list, it cannot be
* accessed thru the fanouts, and we already waited for the
* conn_ref to drop to 0. We are already in close, so
* there cannot be any other thread from the top. qprocsoff
* has completed, and service has completed or won't run in
* future.
*/
return (0);
}
/*
* Wapper around putnext() so that ip_rts_request can merely use
* conn_recv.
*/
/*ARGSUSED2*/
static void
{
}
/* ARGSUSED */
static void
{
}
/*
* Called when the module is about to be unloaded
*/
void
ip_ddi_destroy(void)
{
tnet_fini();
#if defined(_LP64)
#endif
#ifdef DEBUG
#endif
}
/*
* First step in cleanup.
*/
/* ARGSUSED */
static void
{
#ifdef NS_DEBUG
#endif
/*
* Perform cleanup for special interfaces (loopback and IPMP).
*/
/*
* The *_hook_shutdown()s start the process of notifying any
* consumers that things are going away.... nothing is destroyed.
*/
}
/*
* Free the IP stack instance.
*/
static void
{
int ret;
#ifdef NS_DEBUG
#endif
/*
* At this point, all of the notifications that the events and
* protocols are going away have been run, meaning that we can
* now set about starting to clean things up.
*/
if (ret == -1) {
} else {
ipst->ips_igmp_timeout_id = 0;
}
if (ret == -1) {
} else {
ipst->ips_igmp_slowtimeout_id = 0;
}
if (ret == -1) {
} else {
ipst->ips_mld_timeout_id = 0;
}
if (ret == -1) {
} else {
ipst->ips_mld_slowtimeout_id = 0;
}
}
}
/*
* This function is called from the TSD destructor, and is used to debug
* details.
*/
static void
ip_thread_exit(void *phash)
{
}
/*
* Called when the IP kernel module is loaded into the kernel
*/
void
ip_ddi_init(void)
{
/*
* For IP and TCP the minor numbers should start from 2 since we have 4
* initial devices: ip, ip6, tcp, tcp6.
*/
/*
* If this is a 64-bit kernel, then create two separate arenas -
* one for TLIs in the range of INET_MIN_DEV+2 through 2^^18-1, and the
* other for socket apps in the range 2^^18 through 2^^32-1.
*/
#if defined(_LP64)
"ip_ddi_init: ip_minor_arena_sa creation failed\n");
}
"ip_ddi_init: ip_minor_arena_la creation failed\n");
}
#else
"ip_ddi_init: ip_minor_arena_sa creation failed\n");
}
#endif
ipcl_g_init();
#ifdef DEBUG
#endif
dce_g_init();
/*
* We want to be informed each time a stack is created or
* destroyed in the kernel, so we can maintain the
* set of udp_stack_t's.
*/
tnet_init();
}
/*
* Initialize the IP stack instance.
*/
static void *
{
#ifdef NS_DEBUG
#endif
KM_SLEEP);
KM_SLEEP);
"ip_cgtp_filter") == 0);
/*
* Create the taskq dispatcher thread and initialize related stuff.
*/
return (ipst);
}
/*
* Allocate and initialize a DLPI template of the specified length. (May be
* called as writer.)
*/
mblk_t *
{
if (!mp)
return (NULL);
/*
* DLPIv2 says that DL_INFO_REQ and DL_TOKEN_REQ (the latter
* of which we don't seem to use) are sent with M_PCPROTO, and
* that other DLPI are M_PROTO.
*/
if (prim == DL_INFO_REQ) {
} else {
}
return (mp);
}
/*
* Allocate and initialize a DLPI notification. (May be called as writer.)
*/
mblk_t *
{
return (NULL);
return (mp);
}
/*
* Debug formatting routine. Returns a character string representation of the
* addr in buf, of the form xxx.xxx.xxx.xxx. This routine takes the address
* in the form of a ipaddr_t and calls ip_dot_saddr with a pointer.
*
* Once the ndd table-printing interfaces are removed, this can be changed to
* standard dotted-decimal form.
*/
char *
{
return (buf);
}
/*
* Write the given MAC address as a printable string in the usual colon-
* separated format.
*/
const char *
{
char *bp;
return ("?");
for (;;) {
/*
* If there are more MAC address bytes available, but we won't
* have any room to print them, then add "..." to the string
* instead. See below for the 'magic number' explanation.
*/
break;
}
bp += 2;
if (--alen == 0)
break;
*bp++ = ':';
buflen -= 3;
/*
* At this point, based on the first 'if' statement above,
* either alen == 1 and buflen >= 3, or alen > 1 and
* buflen >= 4. The first case leaves room for the final "xx"
* number and trailing NUL byte. The second leaves room for at
* least "...". Thus the apparently 'magic' numbers chosen for
* that statement.
*/
}
return (buf);
}
/*
* Called when it is conceptually a ULP that would sent the packet
* e.g., port unreachable and protocol unreachable. Check that the packet
* would have passed the IPsec global policy before sending the error.
*
* Send an ICMP error after patching up the packet appropriately.
* Uses ip_drop_input and bumps the appropriate MIB.
*/
void
{
/*
* We are generating an icmp error for some inbound packet.
* Called from all ip_fanout_(udp, tcp, proto) functions.
* Before we generate an error, check with global policy
* to see whether this is allowed to enter the system. As
* there is no "conn", we are checking with global policy.
*/
return;
}
/* We never send errors for protocols that we do implement */
return;
}
/*
* Have to correct checksum since
* the packet might have been
* fragmented and the reassembly code in ip_rput
* does not restore the IP checksum.
*/
ipha->ipha_hdr_checksum = 0;
switch (icmp_type) {
case ICMP_DEST_UNREACHABLE:
switch (icmp_code) {
break;
case ICMP_PORT_UNREACHABLE:
break;
}
break;
default:
#ifdef DEBUG
panic("ip_fanout_send_icmp_v4: wrong type");
/*NOTREACHED*/
#else
break;
#endif
}
}
/*
* Used to send an ICMP error message when a packet is received for
* a protocol that is not supported. The mblk passed as argument
* is consumed by this function.
*/
void
{
} else {
}
}
/*
* Deliver a rawip packet to the given conn, possibly applying ipsec policy.
* Handles IPv4 and IPv6.
* We are responsible for disposing of mp, such as by freemsg() or putnext()
* Caller is responsible for dropping references to the conn.
*/
void
{
switch (protocol) {
case IPPROTO_ICMPV6:
break;
case IPPROTO_ICMP:
break;
default:
break;
}
return;
}
if (((iraflags & IRAF_IS_IPV4) ?
secure) {
/* Note that mp is NULL */
return;
}
}
if (iraflags & IRAF_ICMP_ERROR) {
} else {
/* Send it upstream */
}
}
/*
* Handle protocols with which IP is less intimate. There
* can be more than one stream bound to a particular
* protocol. When this is the case, normally each one gets a copy
* of any incoming packets.
*
* IPsec NOTE :
*
* Don't allow a secure packet going up a non-secure connection.
* We don't allow this because
*
* 1) Reply might go out in clear which will be dropped at
* the sending side.
* 2) If the reply goes out in clear it will give the
* adversary enough information for getting the key in
* most of the cases.
*
* Moreover getting a secure packet when we expect clear
* implies that SA's were added without checking for
* policy on both ends. This should not happen once ISAKMP
* is used to negotiate SAs as SAs will be added only after
* verifying the policy.
*
* Zones notes:
* Earlier in ip_input on a system with multiple shared-IP zones we
* duplicate the multicast and broadcast packets and send them up
* with each explicit zoneid that exists on that ill.
* This means that here we can match the zoneid with SO_ALLZONES being special.
*/
void
{
/* Note: IPCL_PROTO_MATCH includes conn_wantpacket */
break;
}
}
/*
* No one bound to these addresses. Is
* there a client that wants all
* unclaimed datagrams?
*/
return;
}
first_connp = connp;
for (;;) {
/* Note: IPCL_PROTO_MATCH includes conn_wantpacket */
break;
}
/* No more interested clients */
connp = first_connp;
break;
}
/* Memory allocation failed */
connp = first_connp;
break;
}
ira);
/* Follow the next pointer before releasing the conn. */
connp = next_connp;
}
/* Last one. Send it upstream. */
}
/*
* If we have a IPsec NAT-Traversal packet, strip the zero-SPI or
* pass it along to ESP if the SPI is non-zero. Returns the mblk if the mblk
* is not consumed.
*
* One of three things can happen, all of which affect the passed-in mblk:
*
* 1.) The packet is stock UDP and gets its zero-SPI stripped. Return mblk..
*
* 2.) The packet is ESP-in-UDP, gets transformed into an equivalent
* ESP packet, and is passed along to ESP for consumption. Return NULL.
*
* 3.) The packet is an ESP-in-UDP Keepalive. Drop it and return NULL.
*/
mblk_t *
{
/*
* Most likely a keepalive for the benefit of an intervening
* NAT. These aren't for us, per se, so drop it.
*
* RFC 3947/8 doesn't say for sure what to do for 2-3
* byte packets (keepalives are 1-byte), but we'll drop them
* also.
*/
return (NULL);
}
/* might as well pull it all up - it might be ESP. */
&ipss->ipsec_dropper);
return (NULL);
}
}
if (*spi == 0) {
/* UDP packet - remove 0-spi. */
} else {
/* ESP-in-UDP packet - reduce to ESP. */
}
/* Fix IP header */
ipha->ipha_hdr_checksum = 0;
if (*spi == 0) {
esp_ports = 0;
} else {
}
if (esp_ports != 0) /* Punt up for ESP processing. */ {
return (NULL);
}
return (mp);
}
/*
* Deliver a udp packet to the given conn, possibly applying ipsec policy.
* Handles IPv4 and IPv6.
* We are responsible for disposing of mp, such as by freemsg() or putnext()
* Caller is responsible for dropping references to the conn.
*/
void
{
return;
}
if (((iraflags & IRAF_IS_IPV4) ?
secure) {
/* Note that mp is NULL */
return;
}
}
/*
* Since this code is not used for UDP unicast we don't need a NAT_T
* check. Only ip_fanout_v4 has that check.
*/
} else {
/* Send it upstream */
}
}
/*
* Fanout for UDP packets that are multicast or broadcast, and ICMP errors.
* (Unicast fanout is handled in ip_input_v4.)
*
* If SO_REUSEADDR is set all multicast and broadcast packets
* will be delivered to all conns bound to the same port.
*
* If there is at least one matching AF_INET receiver, then we will
* ignore any AF_INET6 receivers.
* In the special case where an AF_INET socket binds to 0.0.0.0/<port> and an
* AF_INET6 socket binds to ::/<port>, only the AF_INET socket receives the IPv4
* packets.
*
* Zones notes:
* Earlier in ip_input on a system with multiple shared-IP zones we
* duplicate the multicast and broadcast packets and send them up
* with each explicit zoneid that exists on that ill.
* This means that here we can match the zoneid with SO_ALLZONES being special.
*/
void
{
/*
* If SO_REUSEADDR has been set on the first we send the
* packet to all clients that have joined the group and
* match the port.
*/
break;
}
goto notfound;
if (connp->conn_reuseaddr) {
for (;;) {
break;
}
/* No more interested clients */
connp = first_connp;
break;
}
/* Memory allocation failed */
connp = first_connp;
break;
}
/* Follow the next pointer before releasing the conn */
connp = next_connp;
}
}
/* Last one. Send it upstream. */
return;
/*
* IPv6 endpoints bound to multicast IPv4-mapped addresses
* have already been matched above, since they live in the IPv4
* fanout tables. This implies we only need to
* check for IPv6 in6addr_any endpoints here.
* Thus we compare using ipv6_all_zeros instead of the destination
* address, except for the multicast group membership lookup which
* uses the IPv4 destination.
*/
/*
* IPv4 multicast packet being delivered to an AF_INET6
* in6addr_any endpoint.
* Need to check conn_wantpacket(). Note that we use conn_wantpacket()
* and not conn_wantpacket_v6() since any multicast membership is
* for an IPv4-mapped multicast address.
*/
break;
}
/*
* No one bound to this port. Is
* there a client that wants all
* unclaimed datagrams?
*/
NULL) {
} else {
/*
* We used to attempt to send an icmp error here, but
* since this is known to be a multicast packet
* and we don't send icmp errors in response to
* multicast, just drop the packet and give up sooner.
*/
}
return;
}
/*
* If SO_REUSEADDR has been set on the first we send the
* packet to all clients that have joined the group and
* match the port.
*/
if (connp->conn_reuseaddr) {
for (;;) {
break;
}
/* No more interested clients */
connp = first_connp;
break;
}
/* Memory allocation failed */
connp = first_connp;
break;
}
/* Follow the next pointer before releasing the conn */
connp = next_connp;
}
}
/* Last one. Send it upstream. */
}
/*
* Split an incoming packet's IPv4 options into the label and the other options.
* If 'allocate' is set it does memory allocation for the ip_pkt_t, including
* clearing out any leftover label or options.
* Otherwise it just makes ipp point into the packet.
*
* Returns zero if ok; ENOMEM if the buffer couldn't be allocated.
*/
int
{
/*
* Get length (in 4 byte octets) of IP header options.
*/
if (totallen == 0) {
if (!allocate)
return (0);
/* Clear out anything from a previous packet */
ipp->ipp_ipv4_options_len = 0;
}
ipp->ipp_label_len_v4 = 0;
}
return (0);
}
totallen <<= 2;
if (!is_system_labeled()) {
if (!allocate) {
if (totallen != 0) {
}
return (0);
}
/* Just copy all of options */
return (0);
}
ipp->ipp_ipv4_options_len = 0;
}
if (totallen == 0)
return (0);
return (ENOMEM);
return (0);
}
ipp->ipp_label_len_v4 = 0;
}
/*
* Search for CIPSO option.
* We assume CIPSO is first in options if it is present.
* If it isn't, then ipp_opt_ipv4_options will not include the options
* prior to the CIPSO option.
*/
while (totallen != 0) {
case IPOPT_EOL:
return (0);
case IPOPT_NOP:
optlen = 1;
break;
default:
if (totallen <= IPOPT_OLEN)
return (EINVAL);
if (optlen < 2)
return (EINVAL);
}
return (EINVAL);
switch (optval) {
case IPOPT_COMSEC:
if (!allocate) {
} else {
return (ENOMEM);
}
/* Skip padding bytes until we get to a multiple of 4 */
totallen--;
opt++;
}
/* Remaining as ipp_ipv4_options */
goto copyall;
}
}
/* No CIPSO found; return everything as ipp_ipv4_options */
totallen <<= 2;
goto copyall;
}
/*
* Efficient versions of lookup for an IRE when we only
* match the address.
* For RTF_REJECT or BLACKHOLE we return IRE_NOROUTE.
* Does not handle multicast addresses.
*/
{
else
return (result);
}
/*
* Efficient versions of lookup for an IRE when we only
* match the address.
* For RTF_REJECT or BLACKHOLE we return IRE_NOROUTE.
* Does not handle multicast addresses.
*/
{
else
return (result);
}
/*
* Nobody should be sending
* packets up this stream
*/
static void
{
case M_FLUSH:
/* Turn around */
return;
}
break;
}
}
/* Nobody should be sending packets down this stream */
/* ARGSUSED */
void
{
}
/*
* Move the first hop in any source route to ipha_dst and remove that part of
* the source route. Called by other protocols. Errors in option formatting
* are ignored - will be handled by ip_output_options. Return the final
* destination (either ipha_dst or the last entry in a source route.)
*/
{
int i;
ip2dbg(("ip_massage_options\n"));
switch (optval) {
case IPOPT_SSRR:
case IPOPT_LSRR:
ip1dbg(("ip_massage_options: bad src route\n"));
break;
}
off--;
if (optlen < IP_ADDR_LEN ||
/* End of source route */
ip1dbg(("ip_massage_options: end of SR\n"));
break;
}
ip1dbg(("ip_massage_options: next hop 0x%x\n",
/*
* Check if our address is present more than
* once as consecutive hops in source route.
* XXX verify per-interface ip_forwarding
* for source route?
*/
off += IP_ADDR_LEN;
goto redo_srr;
}
ip1dbg(("ip_massage_options: loopback addr in "
"source route!\n"));
break;
}
/*
* Update ipha_dst to be the first hop and remove the
* first hop from the source route (by overwriting
* part of the option with NOP options).
*/
/* Put the last entry in dst */
3;
ip1dbg(("ip_massage_options: last hop 0x%x\n",
/* Move down and overwrite */
for (i = 0; i < IP_ADDR_LEN; i++)
break;
}
}
return (dst);
}
/*
* Return the network mask
* associated with the specified address.
*/
{
#define TOTALLY_BRAIN_DAMAGED_C_COMPILER
#endif
#endif
maskp[0] = 0xF0;
return (mask);
}
/* We assume Class E default netmask to be 32 */
return (0xffffffffU);
if (addr == 0)
return (0);
maskp[0] = 0xFF;
if ((up[0] & 0x80) == 0)
return (mask);
return (mask);
return (mask);
/* Otherwise return no mask */
return ((ipaddr_t)0);
}
char *
{
if (!nv)
return (NULL);
}
return ("unknown");
}
static int
{
int err;
/*
* Return value of 0 indicates a pending signal.
*/
if (err == 0) {
return (EINTR);
}
}
/*
* ip_rput_other could have set an error in ill_error on
* receipt of M_ERROR.
*/
}
/*
* This is a module open, i.e. this is a control stream for access
* to a DLPI device. We allocate an ill_t as the instance data in
* this case.
*/
static int
{
int err;
netstack_t *ns;
/*
* Prevent unprivileged processes from pushing IP so that
* they can't send raw IP.
*/
if (secpolicy_net_rawaccess(credp) != 0)
return (EPERM);
/*
* For exclusive stacks we set the zoneid to zero
* to make IP operate as if in the global zone.
*/
else
/*
* ill_init initializes the ill fields and then sends down
* down a DL_INFO_REQ after calling qprocson.
*/
if (err != 0) {
return (err);
}
/*
* Wait for the DL_INFO_ACK if a DL_INFO_REQ was sent.
*
* ill_init initializes the ipsq marking this thread as
* writer
*/
if (err == 0)
else
goto fail;
fail:
if (err) {
(void) ip_close(q, 0);
return (err);
}
return (0);
}
int
{
}
int
{
}
/* IP open routine. */
int
{
netstack_t *ns;
/* Allow reopen. */
return (0);
/* This is a module open */
}
/*
* Non streams based socket looking for a stream
* to access IP
*/
}
/*
* For exclusive stacks we set the zoneid to zero
* to make IP operate as if in the global zone.
*/
else
/*
* We are opening as a device. This is an IP client stream, and we
* allocate an conn_t as the instance data.
*/
/*
* ipcl_conn_create did a netstack_hold. Undo the hold that was
* done by netstack_find_by_cred()
*/
/* conn_allzones can not be set this early, hence no IPCL_ZONEID */
/* Minor tells us which /dev entry was opened */
if (isv6) {
} else {
}
} else {
/*
* Either minor numbers in the large arena were exhausted
* or a non socket application is doing the open.
* Try to allocate from the small arena.
*/
inet_minor_alloc(ip_minor_arena_sa)) == 0) {
/* CONN_DEC_REF takes care of netstack_rele() */
return (EBUSY);
}
}
/*
* connp->conn_cred is crfree()ed in ipcl_conn_destroy()
*/
/* Cache things in ixa without an extra refhold */
if (is_system_labeled())
/*
* Handle IP_IOC_RTS_REQUEST and other ioctls which use conn_recv
*/
/*
* If the caller has the process-wide flag set, then default to MAC
* exempt mode. This allows read-down to unlabeled hosts.
*/
/* Non-zero default values */
/*
* Make the conn globally visible to walkers
*/
qprocson(q);
return (0);
}
/*
* Set IPsec policy from an ipsec_req_t. If the req is not "zero" and valid,
* all of them are copied to the conn_t. If the req is "zero", the policy is
* zeroed out. A "zero" policy has zero ipsr_{ah,req,self_encap}_req
* fields.
* We keep only the latest setting of the policy and thus policy setting
* is not incremental/cumulative.
*
* Requests to set policies with multiple alternative actions will
* go through a different API.
*/
int
{
int error = 0;
/*
* The IP_SEC_OPT option does not allow variable length parameters,
* hence a request cannot be NULL.
*/
return (EINVAL);
return (EINVAL);
/*
* Are we dealing with a request to reset the policy (i.e.
* zero requests).
*/
if (!is_pol_reset) {
/*
* If we couldn't load IPsec, fail with "protocol
* not supported".
* IPsec may not have been loaded for a request with zero
* policies, so we don't fail in this case.
*/
return (EPROTONOSUPPORT);
}
/*
* Test for valid requests. Invalid algorithms
* need to be tested by IPsec code because new
* algorithms can be added dynamically.
*/
return (EINVAL);
}
/*
* Only privileged users can issue these
* requests.
*/
if (((ah_req & IPSEC_PREF_NEVER) ||
(esp_req & IPSEC_PREF_NEVER) ||
(se_req & IPSEC_PREF_NEVER)) &&
return (EPERM);
}
/*
* The IPSEC_PREF_REQUIRED and IPSEC_PREF_NEVER
* are mutually exclusive.
*/
/* Both of them are set */
return (EINVAL);
}
}
/*
* If we have already cached policies in conn_connect(), don't
* let them change now. We cache policies for connections
* whose src,dst [addr, port] is known.
*/
if (connp->conn_policy_cached) {
return (EINVAL);
}
/*
* We have a zero policies, reset the connection policy if already
* set. This will cause the connection to inherit the
* global policy, if any.
*/
if (is_pol_reset) {
}
return (0);
}
ipst->ips_netstack);
goto enomem;
goto enomem;
/*
* Always insert IPv4 policy entries, since they can also apply to
* ipv6 sockets being used in ipv4-compat mode.
*/
goto enomem;
goto enomem;
/*
* We're looking at a v6 socket, also insert the v6-specific
* entries.
*/
goto enomem;
goto enomem;
}
/*
* If the requests need security, set enforce_policy.
* If the requests are IPSEC_PREF_NEVER, one should
* still set conn_out_enforce_policy so that ip_set_destination
* marks the ip_xmit_attr_t appropriatly. This is needed so that
* for connections that we don't cache policy in at connect time,
* if global policy matches in ip_output_attach_policy, we
* don't wrongly inherit global policy. Similarly, we need
* to set conn_in_enforce_policy also so that we don't verify
* policy wrongly.
*/
}
return (error);
/*
* Common memory-allocation-failure exit path.
*/
if (is_pol_inserted)
return (ENOMEM);
}
/*
* Set socket options for joining and leaving multicast groups.
* Common to IPv4 and IPv6; inet6 indicates the type of socket.
* The caller has already check that the option name is consistent with
* the address family of the socket.
*/
int
{
int error = 0;
switch (name) {
case IP_ADD_MEMBERSHIP:
case IPV6_JOIN_GROUP:
/* FALLTHRU */
case MCAST_JOIN_GROUP:
break;
case IP_DROP_MEMBERSHIP:
case IPV6_LEAVE_GROUP:
/* FALLTHRU */
case MCAST_LEAVE_GROUP:
break;
default:
ASSERT(0);
}
if (mcast_opt) {
struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
} else {
if (!inet6)
return (EINVAL); /* Not on INET socket */
}
ifaddr = INADDR_ANY;
} else if (inet6) {
ifaddr = INADDR_ANY;
} else {
ifindex = 0;
}
/*
* In the multirouting case, we need to replicate
* the request on all interfaces that will take part
* in replication. We do so because multirouting is
* reflective, thus we will probably receive multi-
* casts on those interfaces.
* The ip_multirt_apply_membership() succeeds if
* the operation succeeds on at least one interface.
*/
if (IN6_IS_ADDR_V4MAPPED(&v6group)) {
} else {
}
}
}
if (!done) {
fmode, &ipv6_all_zeros);
}
return (error);
}
/*
* Set socket options for joining and leaving multicast groups
* for specific sources.
* Common to IPv4 and IPv6; inet6 indicates the type of socket.
* The caller has already check that the option name is consistent with
* the address family of the socket.
*/
int
{
int error = 0;
struct ip_mreq_source *imreqp;
struct group_source_req *gsreqp;
switch (name) {
case IP_BLOCK_SOURCE:
/* FALLTHRU */
case MCAST_BLOCK_SOURCE:
break;
case IP_UNBLOCK_SOURCE:
/* FALLTHRU */
case MCAST_UNBLOCK_SOURCE:
break;
case IP_ADD_SOURCE_MEMBERSHIP:
/* FALLTHRU */
case MCAST_JOIN_SOURCE_GROUP:
break;
/* FALLTHRU */
case MCAST_LEAVE_SOURCE_GROUP:
break;
default:
ASSERT(0);
}
if (mcast_opt) {
struct sockaddr_in *s;
} else {
struct sockaddr_in6 *s6;
if (!inet6)
return (EINVAL); /* Not on INET socket */
}
ifaddr = INADDR_ANY;
} else {
ifindex = 0;
}
/*
* Handle src being mapped INADDR_ANY by changing it to unspecified.
*/
if (IN6_IS_ADDR_V4MAPPED_ANY(&v6src))
/*
* In the multirouting case, we need to replicate
* the request as noted in the mcast cases above.
*/
if (IN6_IS_ADDR_V4MAPPED(&v6group)) {
} else {
}
}
}
if (!done) {
}
return (error);
}
/*
* Given a destination address and a pointer to where to put the information
* this routine fills in the mtuinfo.
* The socket must be connected.
* For sctp conn_faddr is the primary address.
*/
int
{
return (-1);
/* In case we never sent or called ip_set_destination_v4/v6 */
else
scopeid = 0;
return (sizeof (struct ip6_mtuinfo));
}
/* Named Dispatch routine to get a current value out of our parameter table. */
/* ARGSUSED */
static int
{
return (0);
}
/* ARGSUSED */
static int
{
return (0);
}
/*
* Set ip{,6}_forwarding values. This means walking through all of the
* ill's and toggling their forwarding values.
*/
/* ARGSUSED */
static int
{
long new_value;
int *forwarding_value = (int *)cp;
return (EINVAL);
}
/*
* Regardless of the current value of ip_forwarding, set all per-ill
* values of ip_forwarding to the value being set.
*
* Bring all the ill's up to date with the new global value.
*/
if (isv6)
else
return (0);
}
/*
* Walk through the param array specified registering each element with the
* Named Dispatch handler. This is called only during init. So it is ok
* not to acquire any locks
*/
static boolean_t
{
return (B_FALSE);
}
}
}
ipnd->ip_ndp_data)) {
return (B_FALSE);
}
}
}
return (B_TRUE);
}
/* Named Dispatch routine to negotiate a new value for one of our parameters. */
/* ARGSUSED */
static int
{
long new_value;
return (EINVAL);
}
return (0);
}
/*
* Handles both IPv4 and IPv6 reassembly - doing the out-of-order cases,
* When an ipf is passed here for the first time, if
* we already have in-order fragments on the queue, we convert from the fast-
* path reassembly scheme to the hard-case scheme. From then on, additional
* fragments are reassembled here. We keep track of the start and end offsets
* of each piece, and the number of holes in the chain. When the hole count
* goes to zero, we are done!
*
* The ipf_count will be updated to account for any mblk(s) added (pointed to
* by mp) or subtracted (freeb()ed dups), upon return the caller must update
* ipfb_count and ill_frag_count by the difference of ipf_count before and
* after the call to ip_reassemble().
*/
int
{
/* If start == 0 then ipf_nf_hdr_len has to be set. */
/* Add in byte count */
/*
* We were part way through in-order reassembly, but now there
* is a hole. We walk through messages already queued, and
* mark them for hard case reassembly. We know that up till
* now they were in order starting from offset zero.
*/
offset = 0;
if (offset == 0) {
}
}
/* One hole at the end. */
/* Brand it as a hard case, forever. */
}
/* Walk through all the new pieces. */
do {
/*
* If start is 0, decrease 'end' only for the first mblk of
* the fragment. Otherwise 'end' can get wrong value in the
* second pass of the loop if first mblk is exactly the
* size of ipf_nf_hdr_len.
*/
if (start == 0 && !offset_zero_seen) {
/* First segment */
}
/*
* We are checking to see if there is any interesing data
* to process. If there isn't and the mblk isn't the
* one which carries the unfragmentable header then we
* drop it. It's possible to have just the unfragmentable
* header come through without any data. That needs to be
* saved.
*
* If the assert at the top of this function holds then the
* term "ipf->ipf_nf_hdr_len != 0" isn't needed. This code
* is infrequently traveled enough that the test is left in
* to protect against future code changes which break that
* invariant.
*/
/* Empty. Blast it. */
IP_REASS_SET_START(mp, 0);
IP_REASS_SET_END(mp, 0);
/*
* If the ipf points to the mblk we are about to free,
* update ipf to point to the next mblk (or NULL
* if none).
*/
continue;
}
if (!ipf->ipf_tail_mp) {
/*
* if the first fragment comes in more than one
* mblk, this loop will be executed for each
* mblk. Need to adjust hole count so exiting
* this routine will leave hole count at 1.
*/
if (next_mp)
ipf->ipf_hole_cnt++;
} else
continue;
/*
* We check datagram boundary only if this fragment
* claims to be the last fragment and we have seen a
* last fragment in the past too. We do this only
* once for a given fragment.
*
* start cannot be 0 here as fragments with start=0
* and MF=0 gets handled as a complete packet. These
* fragments should not reach here.
*/
/*
* We have two fragments both of which claim
* to be the last fragment but gives conflicting
* information about the whole datagram size.
* Something fishy is going on. Drop the
* fragment and free up the reassembly list.
*/
return (IP_REASS_FAILED);
}
/*
* We shouldn't come to this code block again for this
* particular fragment.
*/
}
/* New stuff at or beyond tail? */
if (ipf->ipf_last_frag_seen) {
/* current fragment is beyond last fragment */
return (IP_REASS_FAILED);
}
/* Link it on end. */
if (more) {
ipf->ipf_hole_cnt++;
ipf->ipf_hole_cnt--;
continue;
}
/* New stuff at the front? */
if (start == 0) {
/* Nailed the hole at the begining. */
ipf->ipf_hole_cnt--;
}
/*
* A hole, stuff, and a hole where there used
* to be just a hole.
*/
ipf->ipf_hole_cnt++;
}
/* Check for overlap. */
break;
}
/* Did we cover another hole? */
IP_REASS_END(mp1) !=
ipf->ipf_hole_cnt--;
}
/* Clip out mp1. */
/*
* After clipping out mp1, this guy
* is now hanging off the end.
*/
}
IP_REASS_SET_START(mp1, 0);
IP_REASS_SET_END(mp1, 0);
/* Subtract byte count */
if (!mp1)
break;
}
continue;
}
/*
* The new piece starts somewhere between the start of the head
* and before the end of the tail.
*/
/* Nothing new. */
IP_REASS_SET_START(mp, 0);
IP_REASS_SET_END(mp, 0);
/* Subtract byte count */
if (incr_dups) {
ipf->ipf_num_dups++;
}
break;
}
/*
* Trim redundant stuff off beginning of new
* piece.
*/
/*
* After trimming, this guy is now
* hanging off the end.
*/
if (!more) {
ipf->ipf_hole_cnt--;
}
break;
}
}
continue;
/* Fill a hole */
ipf->ipf_hole_cnt++;
ipf->ipf_hole_cnt--;
/* Check for overlap. */
/*
* TODO we might bump
* this up twice if there is
* overlap at both ends.
*/
break;
}
/* Did we cover another hole? */
end >=
(!ipf->ipf_last_frag_seen &&
!more)) {
ipf->ipf_hole_cnt--;
}
/* Clip out mp1. */
NULL) {
/*
* After clipping out mp1,
* this guy is now hanging
* off the end.
*/
}
IP_REASS_SET_START(mp1, 0);
IP_REASS_SET_END(mp1, 0);
/* Subtract byte count */
if (!mp1)
break;
}
}
break;
}
/* Fragment just processed could be the last one. Remember this fact */
if (!more)
/* Still got holes? */
if (ipf->ipf_hole_cnt)
return (IP_REASS_PARTIAL);
/* Clean up overloaded fields to avoid upstream disasters. */
IP_REASS_SET_START(mp1, 0);
IP_REASS_SET_END(mp1, 0);
}
return (IP_REASS_COMPLETE);
}
/*
* Fragmentation reassembly. Each ILL has a hash table for
* queuing packets undergoing reassembly for all IPIFs
* associated with the ILL. The hash is based on the packet
* IP ident field. The ILL frag hash table was allocated
* as a timer block at the time the ILL was created. Whenever
* there is anything on the reassembly queue, the timer will
* be running. Returns the reassembled packet if reassembly completes.
*/
mblk_t *
{
uint16_t ident;
/*
* Drop the fragmented as early as possible, if
* we don't have resource(s) to re-assemble.
*/
if (ipst->ips_ip_reass_queue_bytes == 0) {
return (NULL);
}
/* Check for fragmentation offset; return if there's none */
(IPH_MF | IPH_OFFSET)) == 0)
return (mp);
/*
* We utilize hardware computed checksum info only for UDP since
* IP fragmentation is a normal occurrence for the protocol. In
* addition, checksum offload support for IP fragments carrying
* UDP payload is commonly implemented across network adapters.
*/
/* Record checksum information from the packet */
/* IP payload offset from beginning of mblk */
if ((sum_flags & HCK_PARTIALCKSUM) &&
/*
* Partial checksum has been calculated by hardware
* and attached to the packet; in addition, any
* prepended extraneous data is even byte aligned.
* If any such data exists, we adjust the checksum;
* this would also handle any postpended data.
*/
/* One's complement subtract extraneous checksum */
else
}
} else {
sum_val = 0;
sum_flags = 0;
}
/* Clear hardware checksumming flag */
DB_CKSUMFLAGS(mp) = 0;
ident = ipha->ipha_ident;
/* If end == 0 then we have a packet with no data, so just free it */
if (end == 0) {
return (NULL);
}
/* Record the ECN field info. */
if (offset != 0) {
/*
* If this isn't the first piece, strip the header, and
* add the offset to the end value.
*/
}
/* Handle vnic loopback of fragments */
msg_len = 0;
else
}
/* If the reassembly list for this ILL will get too big, prune it */
}
/* Try to find an existing fragment queue for this packet. */
for (;;) {
/*
*/
/*
* If we have received too many
* duplicate fragments for this packet
* free it.
*/
return (NULL);
}
/* Found it. */
break;
}
continue;
}
/*
* If we pruned the list, do we want to store this new
* fragment?. We apply an optimization here based on the
* fact that most fragments will be received in order.
* So if the offset of this incoming fragment is zero,
* it is the first fragment of a new packet. We will
* keep it. Otherwise drop the fragment, as we have
* probably pruned the packet already (since the
* packet cannot be found).
*/
return (NULL);
}
/*
* Too many fragmented packets in this hash
* bucket. Free the oldest.
*/
}
/* New guy. Allocate a frag message. */
return (NULL);
}
/* Initialize the fragment header. */
ipf->ipf_nf_hdr_len = 0;
/* Record reassembly start time. */
/* Record ipf generation and account for frag header */
ipf->ipf_num_dups = 0;
ipfb->ipfb_frag_pkts++;
ipf->ipf_checksum = 0;
ipf->ipf_checksum_flags = 0;
/* Store checksum value in fragment header */
if (sum_flags != 0) {
}
/*
* We handle reassembly two ways. In the easy case,
* where all the fragments show up in order, we do
* minimal bookkeeping, and just clip new pieces on
* the end. If we ever see a hole, then we go off
* to ip_reassemble which has to mark the pieces and
* keep track of the number of holes, etc. Obviously,
* the point of having both mechanisms is so we can
* handle the easy case as efficiently as possible.
*/
if (offset == 0) {
/* Easy case, in-order reassembly so far. */
/*
* Keep track of next expected offset in
* ipf_end.
*/
} else {
/* Hard case, hole at the beginning. */
/*
* ipf_end == 0 means that we have given up
* on easy reassembly.
*/
/* Forget checksum offload from now on */
ipf->ipf_checksum_flags = 0;
/*
* ipf_hole_cnt is set by ip_reassemble.
* ipf_count is updated by ip_reassemble.
* No need to check for return value here
* as we don't expect reassembly to complete
* or fail for the first fragment itself.
*/
}
/* Update per ipfb and ill byte counts */
/* If the frag timer wasn't already going, start it. */
goto reass_done;
}
/*
* If the packet's flag has changed (it could be coming up
* from an interface different than the previous, therefore
* possibly different checksum capability), then forget about
* any stored checksum states. Otherwise add the value to
* the existing one stored in the fragment header.
*/
} else if (ipf->ipf_checksum_flags != 0) {
/* Forget checksum offload from now on */
ipf->ipf_checksum_flags = 0;
}
/*
* We have a new piece of a datagram which is already being
* reassembled. Update the ECN info if all IP fragments
* are ECN capable. If there is one which is not, clear
* all the info. If there is at least one which has CE
* code point, IP needs to report that up to transport.
*/
if (ecn_info == IPH_ECN_CE)
} else {
}
/* The new fragment fits at the end */
/* Update the byte count */
/* Update per ipfb and ill byte counts */
if (frag_offset_flags & IPH_MF) {
/* More to come. */
goto reass_done;
}
} else {
/* Go do the hard cases. */
int ret;
if (offset == 0)
/* Save current byte count */
/* Count of bytes added and subtracted (freeb()ed) */
if (count) {
/* Update per ipfb and ill byte counts */
}
if (ret == IP_REASS_PARTIAL) {
goto reass_done;
} else if (ret == IP_REASS_FAILED) {
/* Reassembly failed. Free up all resources */
IP_REASS_SET_START(t_mp, 0);
IP_REASS_SET_END(t_mp, 0);
}
goto reass_done;
}
/* We will reach here iff 'ret' is IP_REASS_COMPLETE */
}
/*
* We have completed reassembly. Unhook the frag header from
* the reassembly list.
*
* Before we free the frag header, record the ECN info
* to report back to the transport.
*/
/* We need to supply these to caller */
else
sum_val = 0;
ipfb->ipfb_frag_pkts--;
/* Ditch the frag header. */
/* Restore original IP length in header. */
if (packet_size > IP_MAXPACKET) {
return (NULL);
}
return (NULL);
}
}
/* We're now complete, zip the frag state */
/* Record the ECN info. */
/* Update the receive attributes */
/* Reassembly is successful; set checksum information in packet */
return (mp);
}
/*
* Pullup function that should be used for IP input in order to
* ensure we do not loose the L2 source address; we need the l2 source
* address for IP_RECVSLLA and for ndp_input.
*
* We return either NULL or b_rptr.
*/
void *
{
if (ip_rput_pullups++ == 0) {
"ip_pullup: %s forced us to "
" pullup pkt, hdr len %ld, hdr addr %p",
}
return (NULL);
else
}
/*
* Make sure ira_l2src has an address. If we don't have one fill with zeros.
* When called from the ULP ira_rill will be NULL hence the caller has to
* pass in the ill.
*/
/* ARGSUSED */
void
{
int alen;
return;
} else {
}
}
/*
* check ip header length and align it.
*/
mblk_t *
{
else
/* Guard against bogus device drivers */
if (len < 0) {
return (NULL);
}
if (len == 0) {
/* GLD sometimes sends up mblk with b_rptr == b_wptr! */
return (NULL);
return (mp);
}
} else {
}
return (NULL);
}
return (mp);
}
/*
* Common code for IPv4 and IPv6 to check and pullup multi-mblks
*/
mblk_t *
{
/*
* Make sure we have data length consistent
* with the IP header.
*/
/* pkt_len is based on ipha_len, not the mblk length */
return (NULL);
}
if (len < 0) {
return (NULL);
}
/* Drop any pad */
return (NULL);
}
if (len < 0) {
return (NULL);
}
/* Drop any pad */
/*
* adjmsg may have freed an mblk from the chain, hence
* invalidate any hw checksum here. This will force IP to
* calculate the checksum in sw, but only for this packet.
*/
DB_CKSUMFLAGS(mp) = 0;
}
return (mp);
}
/*
* Check that the IPv4 opt_len is consistent with the packet and pullup
* the options.
*/
mblk_t *
{
/* Assume no IPv6 packets arrive over the IPv4 queue */
return (NULL);
}
return (NULL);
}
/*
* Recompute complete header length and make sure we
* have access to all of it.
*/
return (NULL);
}
return (NULL);
}
}
return (mp);
}
/*
* Returns a new ire, or the same ire, or NULL.
* If a different IRE is returned, then it is held; the caller
* needs to release it.
*/
ire_t *
{
/*
* IPMP common case: if IRE and ILL are in the same group, there's no
* issue (e.g. packet received on an underlying interface matched an
* IRE_LOCAL on its associated group interface).
*/
return (ire);
/*
* Do another ire lookup here, using the ingress ill, to see if the
* interface is in a usesrc group.
* As long as the ills belong to the same group, we don't consider
* them to be arriving on the wrong interface. Thus, if the switch
* is doing inbound load spreading, we won't drop packets when the
* ip*_strict_dst_multihoming switch is on.
* We also need to check for IPIF_UNNUMBERED point2point interfaces
* where the local address may not be unique. In this case we were
* at the mercy of the initial ire lookup and the IRE_LOCAL it
* actually returned. The new lookup, which is more specific, should
* only find the IRE_LOCAL associated with the ingress ill if one
* exists.
*/
} else {
}
/*
* If the same ire that was returned in ip_input() is found then this
* is an indication that usesrc groups are in use. The packet
* arrived on a different ill in the group than the one associated with
* the destination address. If a different ire was found then the same
* IP address must be hosted on multiple ills. This is possible with
* unnumbered point2point interfaces. We switch to use this new ire in
* order to have accurate interface statistics.
*/
/* Note: held in one case but not the other? Caller handles */
return (new_ire);
/* Unchanged */
return (ire);
}
/*
* Chase pointers once and store locally.
*/
/*
* Check if it's a legal address on the 'usesrc' interface.
* For IPMP data addresses the IRE_LOCAL is the upper, hence we
* can just check phyint_ifindex.
*/
return (ire);
}
/*
* If the ip*_strict_dst_multihoming switch is on then we can
* only accept this packet if the interface is marked as routing.
*/
if (!(strict_check))
return (ire);
return (ire);
}
return (NULL);
}
/*
* This function is used to construct a mac_header_info_s from a
* DL_UNITDATA_IND message.
* The address fields in the mhi structure points into the message,
* thus the caller can't use those fields after freeing the message.
*
* We determine whether the packet received is a non-unicast packet
* and in doing so, determine whether or not it is broadcast vs multicast.
* For it to be a broadcast packet, we must have the appropriate mblk_t
* hanging off the ill_t. If this is either not present or doesn't match
* the destination mac address in the DL_UNITDATA_IND, the packet is deemed
* to be multicast. Thus NICs that have no broadcast address (or no
* capability for one, such as point to point links) cannot return as
* the packet being broadcast.
*/
void
{
if (ill->ill_sap_length < 0)
extra_offset = 0;
else
if (!ind->dl_group_address)
return;
/* Multicast or broadcast */
ind->dl_dest_addr_length) == 0)
}
}
/*
* This function is used to construct a mac_header_info_s from a
* M_DATA fastpath message from a DLPI driver.
* The address fields in the mhi structure points into the message,
* thus the caller can't use those fields after freeing the message.
*
* We determine whether the packet received is a non-unicast packet
* and in doing so, determine whether or not it is broadcast vs multicast.
* For it to be a broadcast packet, we must have the appropriate mblk_t
* hanging off the ill_t. If this is either not present or doesn't match
* the destination mac address in the DL_UNITDATA_IND, the packet is deemed
* to be multicast. Thus NICs that have no broadcast address (or no
* capability for one, such as point to point links) cannot return as
* the packet being broadcast.
*/
void
{
struct ether_header *pether;
- sizeof (struct ether_header));
/*
* Make sure the interface is an ethernet type, since we don't
* know the header format for anything but Ethernet. Also make
* sure we are pointing correctly above db_base.
*/
return;
return;
/* Is there a VLAN tag? */
goto retry;
}
} else {
goto retry;
}
}
return;
/* Multicast or broadcast */
if (ill->ill_sap_length < 0) {
} else {
}
}
}
/*
* Handle anything but M_DATA messages
* We see the DL_UNITDATA_IND which are part
* of the data path, and also the other messages from the driver.
*/
void
{
struct mac_header_info_s mhi;
case M_PROTO:
case M_PCPROTO: {
/* Go handle anything other than data elsewhere. */
return;
}
return;
}
else
/* Ditch the DLPI header. */
return;
}
case M_IOCACK:
case DL_IOC_HDR_INFO:
return;
default:
return;
}
/* FALLTHRU */
case M_ERROR:
case M_HANGUP:
return;
}
B_FALSE);
return;
case M_CTL:
return;
case M_IOCNAK:
ip1dbg(("got iocnak "));
case DL_IOC_HDR_INFO:
return;
default:
break;
}
/* FALLTHRU */
default:
return;
}
}
/* Read side put procedure. Packets coming from the wire arrive here. */
void
{
union DL_primitives *dl;
/*
* If things are opening or closing, only accept high-priority
* DLPI messages. (On open ill->ill_ipif has not yet been
* created; on close, things hanging off the ill may have been
* freed already.)
*/
return;
}
}
struct mac_header_info_s mhi;
} else {
}
}
/*
* Move the information to a copy.
*/
mblk_t *
{
/* Make sure we have ira_l2src before we loose the original mblk */
return (NULL);
}
/* preserve the hardware checksum flags and data, if present */
if (DB_CKSUMFLAGS(mp) != 0) {
}
return (mp1);
}
static void
{
"%s: %s failed: DL_SYSERR (errno %u)\n",
return;
}
}
/*
* ip_rput_dlpi is called by ip_rput to handle all DLPI messages other
* than DL_UNITDATA_IND messages. If we need to process this message
* exclusively, we call qwriter_ip, in which case we also need to call
* ill_refhold before that, since qwriter_ip does an ill_refrele.
*/
void
{
ip1dbg(("ip_rput_dlpi"));
/*
* If we received an ACK but didn't send a request for it, then it
* can't be part of any pending operation; discard up-front.
*/
switch (prim) {
case DL_ERROR_ACK:
ip2dbg(("ip_rput_dlpi(%s): DL_ERROR_ACK for %s (0x%x): %s "
dlea->dl_unix_errno));
break;
case DL_OK_ACK:
break;
case DL_INFO_ACK:
break;
case DL_BIND_ACK:
break;
case DL_PHYS_ADDR_ACK:
break;
case DL_NOTIFY_ACK:
break;
case DL_CAPABILITY_ACK:
break;
}
if (prim != DL_NOTIFY_IND) {
if (reqprim == DL_PRIM_INVAL ||
/* Not a DLPI message we support or expected */
return;
}
dl_primstr(reqprim)));
}
switch (reqprim) {
case DL_UNBIND_REQ:
/*
* NOTE: we mark the unbind as complete even if we got a
* DL_ERROR_ACK, since there's not much else we can do.
*/
break;
case DL_ENABMULTI_REQ:
}
break;
}
/*
* The message is one we're waiting for (or DL_NOTIFY_IND), but we
* need to become writer to continue to process it. Because an
* exclusive operation doesn't complete until replies to all queued
* DLPI messages have been received, we know we're in the middle of an
* exclusive operation and pass CUR_OP (except for DL_NOTIFY_IND).
*
* As required by qwriter_ip(), we refhold the ill; it will refrele.
* Since this is on the ill stream we unconditionally bump up the
* refcount without doing ILL_CAN_LOOKUP().
*/
if (prim == DL_NOTIFY_IND)
else
}
/*
* Handling of DLPI messages that require exclusive access to the ipsq.
*
* Need to do ipsq_pending_mp_get on ioctl completion, which could
* happen here. (along with mi_copy_done)
*/
/* ARGSUSED */
static void
{
int err = 0;
ip1dbg(("ip_rput_dlpi_writer .."));
/*
* The current ioctl could have been aborted by the user and a new
* ioctl to bring up another ill could have started. We could still
* get a response from the driver later.
*/
switch (dloa->dl_primitive) {
case DL_ERROR_ACK:
ip1dbg(("ip_rput_dlpi_writer: got DL_ERROR_ACK for %s\n",
switch (dlea->dl_error_primitive) {
case DL_DISABMULTI_REQ:
break;
case DL_PROMISCON_REQ:
case DL_PROMISCOFF_REQ:
case DL_UNBIND_REQ:
case DL_ATTACH_REQ:
case DL_INFO_REQ:
break;
case DL_NOTIFY_REQ:
break;
case DL_PHYS_ADDR_REQ:
/*
* For IPv6 only, there are two additional
* phys_addr_req's sent to the driver to get the
* IPv6 token and lla. This allows IP to acquire
* the hardware address format for a given interface
* without having built in knowledge of the hardware
* address. ill_phys_addr_pend keeps track of the last
* DL_PAR sent so we know which response we are
* dealing with. ill_dlpi_done will update
* ill_phys_addr_pend when it sends the next req.
* We don't complete the IOCTL until all three DL_PARs
* have been attempted, so set *_len to 0 and break.
*/
if (paddrreq == DL_IPV6_TOKEN) {
ill->ill_token_length = 0;
break;
} else if (paddrreq == DL_IPV6_LINK_LAYER_ADDR) {
ill->ill_nd_lla_len = 0;
break;
}
/*
* Something went wrong with the DL_PHYS_ADDR_REQ.
* We presumably have an IOCTL hanging out waiting
* for completion. Find it and complete the IOCTL
* with the error noted.
* However, ill_dl_phys was called on an ill queue
* (from SIOCSLIFNAME), thus conn_pending_ill is not
* set. But the ioctl is known to be pending on ill_wq.
*/
if (!ill->ill_ifname_pending)
break;
ill->ill_ifname_pending = 0;
if (!ioctl_aborted)
/*
* This operation (SIOCSLIFNAME) must have
* happened on the ill. Assert there is no conn
*/
}
break;
case DL_BIND_REQ:
if (ill->ill_ifname_pending)
break;
/*
* Something went wrong with the bind. We presumably
* have an IOCTL hanging out waiting for completion.
* Find it, take down the interface that was coming
* up, and complete the IOCTL with the error noted.
*/
if (!ioctl_aborted)
/*
* This might be a result of a DL_NOTE_REPLUMB
* notification. In that case, connp is NULL.
*/
q = CONNP_TO_WQ(connp);
/* error is set below the switch */
}
break;
case DL_ENABMULTI_REQ:
printf("ip: joining multicasts failed (%d)"
" on %s - will use link layer "
"broadcasts for multicast\n",
/*
* Set up for multi_bcast; We are the
* writer, so ok to access ill->ill_ipif
* without any lock.
*/
}
return;
case DL_CAPABILITY_REQ:
ip1dbg(("ip_rput_dlpi_writer: got DL_ERROR_ACK for "
"DL_CAPABILITY REQ\n"));
return;
}
/*
* Note the error for IOCTL completion (mp1 is set when
* ready to complete ioctl). If ill_ifname_pending_err is
* set, an error occured during plumbing (ill_ifname_pending),
* so we want to report that error.
*
* NOTE: there are two addtional DL_PHYS_ADDR_REQ's
* (DL_IPV6_TOKEN and DL_IPV6_LINK_LAYER_ADDR) that are
* expected to get errack'd if the driver doesn't support
* these flags (e.g. ethernet). log will be set to B_FALSE
* if these error conditions are encountered.
*/
if (ill->ill_ifname_pending_err != 0) {
ill->ill_ifname_pending_err = 0;
} else {
}
/*
* If we're plumbing an interface and an error hasn't already
* been saved, set ill_ifname_pending_err to the error passed
* up. Ignore the error if log is B_FALSE (see comment above).
*/
ill->ill_ifname_pending_err == 0) {
}
if (log)
break;
case DL_CAPABILITY_ACK:
/*
* The message has been handed off to ill_capability_ack
* and must not be freed below
*/
break;
case DL_INFO_ACK:
/* Call a routine to handle this one. */
return;
case DL_BIND_ACK:
/*
* We should have an IOCTL waiting on this unless
* sent by ill_dl_phys, in which case just return
*/
if (ill->ill_ifname_pending) {
break;
}
if (!ioctl_aborted)
break;
}
/*
* mp1 was added by ill_dl_up(). if that is a result of
* a DL_NOTE_REPLUMB notification, connp could be NULL.
*/
q = CONNP_TO_WQ(connp);
/*
* We are exclusive. So nothing can change even after
* we get the pending mp.
*/
/*
* Now bring up the resolver; when that is complete, we'll
* create IREs. Note that we intentionally mirror what
* ipif_up() would have done, because we got here by way of
* ill_dl_up(), which stopped ipif_up()'s processing.
*/
/*
* v6 interfaces.
* Unlike ARP which has to do another bind
* and attach, once we get here we are
* done with NDP
*/
/*
* ARP and other v4 external resolvers.
* Leave the pending mblk intact so that
* the ioctl completes in ip_rput().
*/
if (success) {
if (err == EINPROGRESS) {
return;
}
} else {
/* The conn has started closing */
}
} else {
/*
* This one is complete. Reply to pending ioctl.
*/
}
if (err == EINPROGRESS) {
return;
}
}
/*
* If we have a moved ipif to bring up, and everything has
* succeeded to this point, bring it up on the IPMP ill.
* Otherwise, leave it down -- the admin can try to bring it
* up by hand if need be.
*/
if (err != 0) {
} else {
if (err == EINPROGRESS) {
return;
}
}
}
break;
case DL_NOTIFY_IND: {
switch (notify->dl_notification) {
case DL_NOTE_PHYS_ADDR:
break;
case DL_NOTE_REPLUMB:
/*
* Directly return after calling ill_replumb().
* Note that we should not free mp as it is reused
* in the ill_replumb() function.
*/
return;
case DL_NOTE_FASTPATH_FLUSH:
break;
case DL_NOTE_SDU_SIZE:
/*
* The dce and fragmentation code can cope with
* this changing while packets are being sent.
* When packets are sent ip_output will discover
* a change.
*
* Change the MTU size of the interface.
*/
/*
* If ill_user_mtu was set (via
* SIOCSLIFLNKINFO), clamp ill_mtu at it.
*/
if (ill->ill_user_mtu != 0 &&
} else {
}
}
/*
* Make sure all dce_generation checks find out
* that ill_mtu has changed.
*/
}
/*
* Refresh IPMP meta-interface MTU if necessary.
*/
if (IS_UNDER_IPMP(ill))
break;
case DL_NOTE_LINK_UP:
case DL_NOTE_LINK_DOWN: {
/*
* We are writer. ill / phyint / ipsq assocs stable.
* The RUNNING flag reflects the state of the link.
*/
}
}
/*
* ill_restart_dad handles the DAD restart and routing
* socket notification logic.
*/
if (changed) {
}
break;
}
case DL_NOTE_PROMISC_ON_PHYS: {
break;
}
case DL_NOTE_PROMISC_OFF_PHYS: {
break;
}
case DL_NOTE_CAPAB_RENEG:
/*
* Something changed on the driver side.
* It wants us to renegotiate the capabilities
* on this ill. One possible cause is the aggregation
* interface under us where a port got added or
* went away.
*
* If the capability negotiation is already done
* or is in progress, reset the capabilities and
* mark the ill's ill_capab_reneg to be B_TRUE,
* so that when the ack comes back, we can start
* the renegotiation process.
*
* Note that if ill_capab_reneg is already B_TRUE
* (ill_dlpi_capab_state is IDS_UNKNOWN in this case),
* the capability resetting request has been sent
* and the renegotiation has not been started yet;
* nothing needs to be done in this case.
*/
break;
default:
ip0dbg(("ip_rput_dlpi_writer: unknown notification "
"type 0x%x for DL_NOTIFY_IND\n",
break;
}
/*
* As this is an asynchronous operation, we
* should not call ill_dlpi_done
*/
break;
}
case DL_NOTIFY_ACK: {
break;
}
case DL_PHYS_ADDR_ACK: {
/*
* As part of plumbing the interface via SIOCSLIFNAME,
* ill_dl_phys() will queue a series of DL_PHYS_ADDR_REQs,
* whose answers we receive here. As each answer is received,
* we call ill_dlpi_done() to dispatch the next request as
* we're processing the current one. Once all answers have
* been received, we use ipsq_pending_mp_get() to dequeue the
* outstanding IOCTL and reply to it. (Because ill_dl_phys()
* is invoked from an ill queue, conn_oper_pending_ill is not
* available, but we know the ioctl is pending on ill_wq.)
*/
if (paddrreq == DL_IPV6_TOKEN) {
/*
* bcopy to low-order bits of ill_token
*
* XXX Temporary hack - currently, all known tokens
* are 64 bits, so I'll cheat for the moment.
*/
break;
} else if (paddrreq == DL_IPV6_LINK_LAYER_ADDR) {
break;
} else if (paddrreq == DL_CURR_DEST_ADDR) {
}
break;
}
if (!ill->ill_ifname_pending)
break;
ill->ill_ifname_pending = 0;
if (!ioctl_aborted)
}
/*
* If any error acks received during the plumbing sequence,
* ill_ifname_pending_err will be set. Break out and send up
* the error to the pending ioctl.
*/
if (ill->ill_ifname_pending_err != 0) {
ill->ill_ifname_pending_err = 0;
break;
}
/*
* If paddrlen or ill_phys_addr_length is zero, the DLPI
* provider doesn't support physical addresses. We check both
* paddrlen and ill_phys_addr_length because sppp (PPP) does
* not have physical addresses, but historically adversises a
* physical address length of 0 in its DL_INFO_ACK, but 6 in
* its DL_PHYS_ADDR_ACK.
*/
ip0dbg(("DL_PHYS_ADDR_ACK: got addrlen %d, expected %d",
break;
}
break;
}
}
}
break;
}
case DL_OK_ACK:
ip2dbg(("DL_OK_ACK %s (0x%x)\n",
switch (dloa->dl_correct_primitive) {
case DL_ENABMULTI_REQ:
case DL_DISABMULTI_REQ:
break;
case DL_PROMISCON_REQ:
case DL_PROMISCOFF_REQ:
case DL_UNBIND_REQ:
case DL_ATTACH_REQ:
break;
}
break;
default:
break;
}
return;
/*
* The operation must complete without EINPROGRESS since
* ipsq_pending_mp_get() has removed the mblk (mp1). Otherwise,
* the operation will be stuck forever inside the IPSQ.
*/
case 0:
break;
case SIOCSLIFNAME:
case IF_UNITSEL: {
/*
* If SIOCSLIFNAME or IF_UNITSEL is about to succeed, and the
* ill has a peer which is in an IPMP group, then place ill
* into the same group. One catch: although ifconfig plumbs
* the appropriate IPMP meta-interface prior to plumbing this
* ill, it is possible for multiple ifconfig applications to
* race (or for another application to adjust plumbing), in
* which case the IPMP meta-interface we need will be missing.
* If so, kick the phyint out of the group.
*/
else
}
else
break;
}
case SIOCLIFADDIF:
break;
default:
break;
}
}
/*
* ip_rput_other is called by ip_rput to handle messages modifying the global
* state in IP. If 'ipsq' is non-NULL, caller is writer on it.
*/
/* ARGSUSED */
void
{
ip1dbg(("ip_rput_other "));
}
case M_ERROR:
case M_HANGUP:
/*
* The device has a problem. We force the ILL down. It can
* be brought up again manually using SIOCSIFFLAGS (via
* ifconfig or equivalent).
*/
if (!ill_down_start(q, mp))
return;
break;
case M_IOCNAK: {
/*
* If this was the first attempt, turn off the fastpath
* probing.
*/
/*
* don't flush the nce_t entries: we use them
* as an index to the ncec itself.
*/
ip1dbg(("ip_rput: DLPI fastpath off on interface %s\n",
} else {
}
break;
}
default:
ASSERT(0);
break;
}
}
/*
* Update any source route, record route or timestamp options
* When it fails it has consumed the message and BUMPed the MIB.
*/
{
ip2dbg(("ip_forward_options\n"));
ip2dbg(("ip_forward_options: opt %d, len %d\n",
switch (optval) {
case IPOPT_SSRR:
case IPOPT_LSRR:
/* Check if adminstratively disabled */
if (!ipst->ips_ip_forward_src_routed) {
ip_drop_input("ICMP_SOURCE_ROUTE_FAILED",
ira);
return (B_FALSE);
}
/*
* Must be partial since ip_input_options
* checked for strict.
*/
break;
}
off--;
if (optlen < IP_ADDR_LEN ||
/* End of source route */
ip1dbg((
"ip_forward_options: end of SR\n"));
break;
}
/* Pick a reasonable address on the outbound if */
NULL) != 0) {
/* No source! Shouldn't happen */
ifaddr = INADDR_ANY;
}
ip1dbg(("ip_forward_options: next hop 0x%x\n",
/*
* Check if our address is present more than
* once as consecutive hops in source route.
*/
off += IP_ADDR_LEN;
goto redo_srr;
}
break;
case IPOPT_RR:
off--;
if (optlen < IP_ADDR_LEN ||
/* No more room - ignore */
ip1dbg((
"ip_forward_options: end of RR\n"));
break;
}
/* Pick a reasonable address on the outbound if */
NULL) != 0) {
/* No source! Shouldn't happen */
ifaddr = INADDR_ANY;
}
break;
case IPOPT_TS:
/* Insert timestamp if there is room */
case IPOPT_TS_TSONLY:
break;
case IPOPT_TS_PRESPEC:
case IPOPT_TS_PRESPEC_RFC791:
/* Verify that the address matched */
/* Not for us */
break;
}
/* FALLTHRU */
case IPOPT_TS_TSANDADDR:
break;
default:
/*
* ip_*put_options should have already
* dropped this packet.
*/
"unknown IT - bug in ip_input_options?\n");
return (B_TRUE); /* Keep "lint" happy */
}
/* Increase overflow counter */
(off << 4));
break;
}
case IPOPT_TS_PRESPEC:
case IPOPT_TS_PRESPEC_RFC791:
case IPOPT_TS_TSANDADDR:
/* Pick a reasonable addr on the outbound if */
/* No source! Shouldn't happen */
ifaddr = INADDR_ANY;
}
/* FALLTHRU */
case IPOPT_TS_TSONLY:
/* Compute # of milliseconds since midnight */
gethrestime(&now);
break;
}
break;
}
}
return (B_TRUE);
}
/*
* Call ill_frag_timeout to do garbage collection. ill_frag_timeout
* returns 'true' if there are still fragments left on the queue, in
* which case we restart the timer.
*/
void
ill_frag_timer(void *arg)
{
ill->ill_frag_timer_id = 0;
return;
}
else
/*
* Restart the timer, if we have fragments pending or if someone
* wanted us to be scheduled again.
*/
ill->ill_fragtimer_executing = 0;
ill->ill_frag_timer_id = 0;
}
void
{
/* If the ill is closing or opening don't proceed */
return;
if (ill->ill_fragtimer_executing) {
/*
* ill_frag_timer is currently executing. Just record the
* the fact that we want the timer to be restarted.
* ill_frag_timer will post a timeout before it returns,
* ensuring it will be called again.
*/
return;
}
if (ill->ill_frag_timer_id == 0) {
else
/*
* The timer is neither running nor is the timeout handler
* executing. Post a timeout so that ill_frag_timer will be
* called
*/
ill->ill_fragtimer_needrestart = 0;
}
}
/*
* Update any source route, record route or timestamp options.
* Check that we are at end of strict source route.
* The options have already been checked for sanity in ip_input_options().
*/
{
ip2dbg(("ip_input_local_options\n"));
ip2dbg(("ip_input_local_options: opt %d, len %d\n",
switch (optval) {
case IPOPT_SSRR:
case IPOPT_LSRR:
off--;
if (optlen < IP_ADDR_LEN ||
/* End of source route */
ip1dbg(("ip_input_local_options: end of SR\n"));
break;
}
/*
* This will only happen if two consecutive entries
* in the source route contains our address or if
* it is a packet with a loose source route which
* reaches us before consuming the whole source route
*/
ip1dbg(("ip_input_local_options: not end of SR\n"));
if (optval == IPOPT_SSRR) {
goto bad_src_route;
}
/*
* Hack: instead of dropping the packet truncate the
* source route to what has been used by filling the
* rest with IPOPT_NOP.
*/
}
break;
case IPOPT_RR:
off--;
if (optlen < IP_ADDR_LEN ||
/* No more room - ignore */
ip1dbg((
"ip_input_local_options: end of RR\n"));
break;
}
/* Pick a reasonable address on the outbound if */
NULL) != 0) {
/* No source! Shouldn't happen */
ifaddr = INADDR_ANY;
}
break;
case IPOPT_TS:
/* Insert timestamp if there is romm */
case IPOPT_TS_TSONLY:
break;
case IPOPT_TS_PRESPEC:
case IPOPT_TS_PRESPEC_RFC791:
/* Verify that the address matched */
/* Not for us */
break;
}
/* FALLTHRU */
case IPOPT_TS_TSANDADDR:
break;
default:
/*
* ip_*put_options should have already
* dropped this packet.
*/
"unknown IT - bug in ip_input_options?\n");
return (B_TRUE); /* Keep "lint" happy */
}
/* Increase overflow counter */
(off << 4));
break;
}
case IPOPT_TS_PRESPEC:
case IPOPT_TS_PRESPEC_RFC791:
case IPOPT_TS_TSANDADDR:
/* Pick a reasonable addr on the outbound if */
/* No source! Shouldn't happen */
ifaddr = INADDR_ANY;
}
/* FALLTHRU */
case IPOPT_TS_TSONLY:
/* Compute # of milliseconds since midnight */
gethrestime(&now);
break;
}
break;
}
}
return (B_TRUE);
/* make sure we clear any indication of a hardware checksum */
DB_CKSUMFLAGS(mp) = 0;
return (B_FALSE);
}
/*
* Process IP options in an inbound packet. Always returns the nexthop.
* Normally this is the passed in nexthop, but if there is an option
* that effects the nexthop (such as a source route) that will be returned.
* Sets *errorp if there is an error, in which case an ICMP error has been sent
* and mp freed.
*/
{
ip2dbg(("ip_input_options\n"));
*errorp = 0;
ip2dbg(("ip_input_options: opt %d, len %d\n",
/*
* Note: we need to verify the checksum before we
* modify anything thus this routine only extracts the next
* hop dst from any source route.
*/
switch (optval) {
case IPOPT_SSRR:
case IPOPT_LSRR:
if (optval == IPOPT_SSRR) {
ip1dbg(("ip_input_options: not next"
" strict source route 0x%x\n",
(char *)ipha;
goto param_prob; /* RouterReq's */
}
ip2dbg(("ip_input_options: "
"not next source route 0x%x\n",
break;
}
ip1dbg((
"ip_input_options: bad option offset\n"));
(char *)ipha;
goto param_prob;
}
off--;
if (optlen < IP_ADDR_LEN ||
/* End of source route */
ip1dbg(("ip_input_options: end of SR\n"));
break;
}
ip1dbg(("ip_input_options: next hop 0x%x\n",
/*
* Check if our address is present more than
* once as consecutive hops in source route.
* XXX verify per-interface ip_forwarding
* for source route?
*/
off += IP_ADDR_LEN;
goto redo_srr;
}
ip1dbg(("ip_input_options: loopback addr in "
"source route!\n"));
goto bad_src_route;
}
/*
* For strict: verify that dst is directly
* reachable.
*/
if (optval == IPOPT_SSRR) {
NULL);
ip1dbg(("ip_input_options: SSRR not "
"directly reachable: 0x%x\n",
goto bad_src_route;
}
}
/*
* Defer update of the offset and the record route
* until the packet is forwarded.
*/
break;
case IPOPT_RR:
ip1dbg((
"ip_input_options: bad option offset\n"));
(char *)ipha;
goto param_prob;
}
break;
case IPOPT_TS:
/*
* Verify that length >= 5 and that there is either
* room for another timestamp or that the overflow
* counter is not maxed out.
*/
if (optlen < IPOPT_MINLEN_IT) {
goto param_prob;
}
ip1dbg((
"ip_input_options: bad option offset\n"));
(char *)ipha;
goto param_prob;
}
case IPOPT_TS_TSONLY:
break;
case IPOPT_TS_TSANDADDR:
case IPOPT_TS_PRESPEC:
case IPOPT_TS_PRESPEC_RFC791:
break;
default:
(char *)ipha;
goto param_prob;
}
/*
* No room and the overflow counter is 15
* already.
*/
goto param_prob;
}
break;
}
}
return (dst);
}
ip1dbg(("ip_input_options: error processing IP options."));
/* make sure we clear any indication of a hardware checksum */
DB_CKSUMFLAGS(mp) = 0;
*errorp = -1;
return (dst);
/* make sure we clear any indication of a hardware checksum */
DB_CKSUMFLAGS(mp) = 0;
*errorp = -1;
return (dst);
}
/*
* IP & ICMP info in >=14 msg's ...
* - ip fixed part (mib2_ip_t)
* - icmp fixed part (mib2_icmp_t)
* - ipAddrEntryTable (ip 20) all IPv4 ipifs
* - ipRouteEntryTable (ip 21) all IPv4 IREs
* - ipNetToMediaEntryTable (ip 22) all IPv4 Neighbor Cache entries
* - ipRouteAttributeTable (ip 102) labeled routes
* - ip multicast membership (ip_member_t)
* - ip multicast source filtering (ip_grpsrc_t)
* - igmp fixed part (struct igmpstat)
* - multicast routing stats (struct mrtstat)
* - multicast routing vifs (array of struct vifctl)
* - multicast routing routes (array of struct mfcctl)
* - ip6 fixed part (mib2_ipv6IfStatsEntry_t)
* One per ill plus one generic
* - icmp6 fixed part (mib2_ipv6IfIcmpEntry_t)
* One per ill plus one generic
* - ipv6RouteEntry all IPv6 IREs
* - ipv6RouteAttributeTable (ip6 102) labeled routes
* - ipv6NetToMediaEntry all IPv6 Neighbor Cache entries
* - ipv6AddrEntry all IPv6 ipifs
* - ipv6 multicast membership (ipv6_member_t)
* - ipv6 multicast source filtering (ipv6_grpsrc_t)
*
* NOTE: original mpctl is copied for msg's 2..N, since its ctl part is
* already filled in by the caller.
* Return value of 0 indicates that no messages were sent and caller
* should free mpctl.
*/
int
{
ipst = ILLQ_TO_IPST(q);
} else {
ipst = CONNQ_TO_IPST(q);
}
return (0);
}
/*
* For the purposes of the (broken) packet shell use
* to make TCP and UDP appear first in the list of mib items.
* TBD: We could expand this and use it in netstat so that
* the kernel doesn't have to produce large tables (connections,
* routes, etc) when netstat only wants the statistics or a particular
* table.
*/
return (1);
}
}
return (1);
}
}
return (1);
}
}
return (1);
}
return (1);
}
return (1);
}
return (1);
}
return (1);
}
return (1);
}
return (1);
}
return (1);
}
return (1);
}
return (1);
}
return (1);
}
return (1);
}
return (1);
}
return (1);
}
return (1);
return (1);
return (1);
}
return (1);
}
return (1);
}
/* Get global (legacy) IPv4 statistics */
static mblk_t *
{
/*
* make a copy of the original message
*/
/* fixed length IP structure... */
sizeof (mib2_ipAddrEntry_t));
sizeof (mib2_ipRouteEntry_t));
sizeof (mib2_ipNetToMediaEntry_t));
sizeof (mib2_ipAttributeEntry_t));
/*
* Grab the statistics from the new IP MIB
*/
/* ipRoutingDiscards is not being used */
(int)sizeof (old_ip_mib))) {
ip1dbg(("ip_snmp_get_mib2_ip: failed to allocate %u bytes\n",
(uint_t)sizeof (old_ip_mib)));
}
ip3dbg(("ip_snmp_get_mib2_ip: level %d, name %d, len %d\n",
return (mp2ctl);
}
/* Per interface IPv4 statistics */
static mblk_t *
{
/*
* Make a copy of the original message
*/
/* Include "unknown interface" ip_mib */
MIB2_UNKNOWN_INTERFACE; /* Flag to netstat */
sizeof (mib2_ipIfStatsEntry_t));
sizeof (mib2_ipAddrEntry_t));
sizeof (mib2_ipRouteEntry_t));
sizeof (mib2_ipNetToMediaEntry_t));
sizeof (ip_member_t));
sizeof (ip_grpsrc_t));
ip1dbg(("ip_snmp_get_mib2_ip_traffic_stats: "
"failed to allocate %u bytes\n",
}
(char *)ill->ill_ip_mib,
(int)sizeof (*ill->ill_ip_mib))) {
ip1dbg(("ip_snmp_get_mib2_ip_traffic_stats: "
"failed to allocate %u bytes\n",
}
}
ip3dbg(("ip_snmp_get_mib2_ip_traffic_stats: "
"level %d, name %d, len %d\n",
return (NULL);
}
/* Global IPv4 ICMP statistics */
static mblk_t *
{
/*
* Make a copy of the original message
*/
(int)sizeof (ipst->ips_icmp_mib))) {
ip1dbg(("ip_snmp_get_mib2_icmp: failed to allocate %u bytes\n",
}
ip3dbg(("ip_snmp_get_mib2_icmp: level %d, name %d, len %d\n",
return (mp2ctl);
}
/* Global IPv4 IGMP statistics */
static mblk_t *
{
/*
* make a copy of the original message
*/
(int)sizeof (ipst->ips_igmpstat))) {
ip1dbg(("ip_snmp_get_mib2_igmp: failed to allocate %u bytes\n",
}
ip3dbg(("ip_snmp_get_mib2_igmp: level %d, name %d, len %d\n",
return (mp2ctl);
}
/* Global IPv4 Multicast Routing statistics */
static mblk_t *
{
/*
* make a copy of the original message
*/
ip0dbg(("ip_mroute_stats: failed\n"));
}
ip3dbg(("ip_snmp_get_mib2_multi: level %d, name %d, len %d\n",
return (mp2ctl);
}
/* IPv4 address information */
static mblk_t *
{
/*
* make a copy of the original message
*/
/* ipAddrEntryTable */
continue;
/* Sum of count from dead IRE_LO* and our current */
}
for (bitval = 1;
bitval &&
bitval <<= 1)
noop;
(char *)&mae, (int)sizeof (mib2_ipAddrEntry_t))) {
ip1dbg(("ip_snmp_get_mib2_ip_addr: failed to "
"allocate %u bytes\n",
(uint_t)sizeof (mib2_ipAddrEntry_t)));
}
}
}
ip3dbg(("ip_snmp_get_mib2_ip_addr: level %d, name %d, len %d\n",
return (mp2ctl);
}
/* IPv6 address information */
static mblk_t *
{
/*
* make a copy of the original message
*/
/* ipv6AddrEntryTable */
continue;
/* Sum of count from dead IRE_LO* and our current */
}
/* Type: stateless(1), stateful(2), unknown(3) */
else
/* Anycast: true(1), false(2) */
else
/*
* Address status: preferred(1), deprecated(2),
* invalid(3), inaccessible(4), unknown(5)
*/
else
(char *)&mae6,
(int)sizeof (mib2_ipv6AddrEntry_t))) {
ip1dbg(("ip_snmp_get_mib2_ip6_addr: failed to "
"allocate %u bytes\n",
(uint_t)sizeof (mib2_ipv6AddrEntry_t)));
}
}
}
ip3dbg(("ip_snmp_get_mib2_ip6_addr: level %d, name %d, len %d\n",
return (mp2ctl);
}
/* IPv4 multicast group membership. */
static mblk_t *
{
/*
* make a copy of the original message
*/
/* ipGroupMember table */
sizeof (struct T_optmgmt_ack)];
/* Make sure the ill isn't going away. */
if (!ill_check_and_refhold(ill))
continue;
continue;
/* Is there an ipif for ilm_ifaddr? */
if (!IPIF_IS_CONDEMNED(ipif) &&
break;
}
} else {
}
ip1dbg(("ip_snmp_get_mib2_ip_group: "
"failed to allocate %u bytes\n",
}
}
}
ip3dbg(("ip_snmp_get: level %d, name %d, len %d\n",
return (mp2ctl);
}
/* IPv6 multicast group membership. */
static mblk_t *
{
/*
* make a copy of the original message
*/
/* ip6GroupMember table */
/* Make sure the ill isn't going away. */
if (!ill_check_and_refhold(ill))
continue;
/*
* Normally we don't have any members on under IPMP interfaces.
* We report them as a debugging aid.
*/
continue; /* not this zone */
&mp_tail,
ip1dbg(("ip_snmp_get_mib2_ip6_group: "
"failed to allocate %u bytes\n",
}
}
}
ip3dbg(("ip_snmp_get: level %d, name %d, len %d\n",
return (mp2ctl);
}
/* IP multicast filtered sources */
static mblk_t *
{
int i;
/*
* make a copy of the original message
*/
/* ipGroupSource table */
sizeof (struct T_optmgmt_ack)];
/* Make sure the ill isn't going away. */
if (!ill_check_and_refhold(ill))
continue;
continue;
if (SLIST_IS_EMPTY(sl))
continue;
/* Is there an ipif for ilm_ifaddr? */
if (!IPIF_IS_CONDEMNED(ipif) &&
break;
}
} else {
}
continue;
ip1dbg(("ip_snmp_get_mib2_ip_group_src:"
" failed to allocate %u bytes\n",
}
}
}
}
ip3dbg(("ip_snmp_get: level %d, name %d, len %d\n",
return (mp2ctl);
}
/* IPv6 multicast filtered sources. */
static mblk_t *
{
int i;
/*
* make a copy of the original message
*/
/* ip6GroupMember table */
/* Make sure the ill isn't going away. */
if (!ill_check_and_refhold(ill))
continue;
/*
* Normally we don't have any members on under IPMP interfaces.
* We report them as a debugging aid.
*/
continue;
if (SLIST_IS_EMPTY(sl))
continue;
ip1dbg(("ip_snmp_get_mib2_ip6_"
"group_src: failed to allocate "
"%u bytes\n",
}
}
}
}
ip3dbg(("ip_snmp_get: level %d, name %d, len %d\n",
return (mp2ctl);
}
/* Multicast routing virtual interface table. */
static mblk_t *
{
/*
* make a copy of the original message
*/
ip0dbg(("ip_mroute_vif: failed\n"));
}
ip3dbg(("ip_snmp_get_mib2_virt_multi: level %d, name %d, len %d\n",
return (mp2ctl);
}
/* Multicast routing table. */
static mblk_t *
{
/*
* make a copy of the original message
*/
ip0dbg(("ip_mroute_mrt: failed\n"));
}
ip3dbg(("ip_snmp_get_mib2_multi_rtable: level %d, name %d, len %d\n",
return (mp2ctl);
}
/*
* Return ipRouteEntryTable, ipNetToMediaEntryTable, and ipRouteAttributeTable
* in one IRE walk.
*/
static mblk_t *
{
/*
* make copies of the original message
* - mp2ctl is returned unchanged to the caller for his use
* - mpctl is sent upstream as ipRouteEntryTable
* - mp3ctl is sent upstream as ipNetToMediaEntryTable
* - mp4ctl is sent upstream as ipRouteAttributeTable
*/
return (NULL);
}
/*
* If the level has been set the special EXPER_IP_AND_ALL_IRES value,
* then also include ire_testhidden IREs and IRE_IF_CLONE. This is
* intended a temporary solution until a proper MIB API is provided
* that provides complete filtering/caller-opt-in.
*/
if (level == EXPER_IP_AND_ALL_IRES)
/* ipRouteEntryTable in mpctl */
ip3dbg(("ip_snmp_get_mib2_ip_route_media: level %d, name %d, len %d\n",
/* ipNetToMediaEntryTable in mp3ctl */
ip3dbg(("ip_snmp_get_mib2_ip_route_media: level %d, name %d, len %d\n",
/* ipRouteAttributeTable in mp4ctl */
ip3dbg(("ip_snmp_get_mib2_ip_route_media: level %d, name %d, len %d\n",
else
return (mp2ctl);
}
/*
* Return ipv6RouteEntryTable and ipv6RouteAttributeTable in one IRE walk, and
* ipv6NetToMediaEntryTable in an NDP walk.
*/
static mblk_t *
{
/*
* make copies of the original message
* - mp2ctl is returned unchanged to the caller for his use
* - mpctl is sent upstream as ipv6RouteEntryTable
* - mp3ctl is sent upstream as ipv6NetToMediaEntryTable
* - mp4ctl is sent upstream as ipv6RouteAttributeTable
*/
return (NULL);
}
/*
* If the level has been set the special EXPER_IP_AND_ALL_IRES value,
* then also include ire_testhidden IREs and IRE_IF_CLONE. This is
* intended a temporary solution until a proper MIB API is provided
* that provides complete filtering/caller-opt-in.
*/
if (level == EXPER_IP_AND_ALL_IRES)
ip3dbg(("ip_snmp_get_mib2_ip6_route_media: level %d, name %d, len %d\n",
/* ipv6NetToMediaEntryTable in mp3ctl */
ip3dbg(("ip_snmp_get_mib2_ip6_route_media: level %d, name %d, len %d\n",
/* ipv6RouteAttributeTable in mp4ctl */
ip3dbg(("ip_snmp_get_mib2_ip6_route_media: level %d, name %d, len %d\n",
else
return (mp2ctl);
}
/*
* IPv6 mib: One per ill
*/
static mblk_t *
{
/*
* Make a copy of the original message
*/
/* fixed length IPv6 structure ... */
/* Include "unknown interface" ip6_mib */
MIB2_UNKNOWN_INTERFACE; /* Flag to netstat */
sizeof (mib2_ipIfStatsEntry_t));
sizeof (mib2_ipv6AddrEntry_t));
sizeof (mib2_ipv6RouteEntry_t));
sizeof (mib2_ipv6NetToMediaEntry_t));
sizeof (ipv6_member_t));
sizeof (ipv6_grpsrc_t));
/*
* Synchronize 64- and 32-bit counters
*/
ip1dbg(("ip_snmp_get_mib2_ip6: failed to allocate %u bytes\n",
}
ill->ill_max_hops);
/*
* Synchronize 64- and 32-bit counters
*/
(char *)ill->ill_ip_mib,
(int)sizeof (*ill->ill_ip_mib))) {
ip1dbg(("ip_snmp_get_mib2_ip6: failed to allocate "
}
}
ip3dbg(("ip_snmp_get_mib2_ip6: level %d, name %d, len %d\n",
return (mp2ctl);
}
/*
* ICMPv6 mib: One per ill
*/
static mblk_t *
{
/*
* Make a copy of the original message
*/
/* fixed length ICMPv6 structure ... */
/* Include "unknown interface" icmp6_mib */
MIB2_UNKNOWN_INTERFACE; /* netstat flag */
sizeof (mib2_ipv6IfIcmpEntry_t);
(char *)&ipst->ips_icmp6_mib,
(int)sizeof (ipst->ips_icmp6_mib))) {
ip1dbg(("ip_snmp_get_mib2_icmp6: failed to allocate %u bytes\n",
}
(char *)ill->ill_icmp6_mib,
(int)sizeof (*ill->ill_icmp6_mib))) {
ip1dbg(("ip_snmp_get_mib2_icmp6: failed to allocate "
"%u bytes\n",
}
}
ip3dbg(("ip_snmp_get_mib2_icmp6: level %d, name %d, len %d\n",
return (mp2ctl);
}
/*
* ire_walk routine to create both ipRouteEntryTable and
* ipRouteAttributeTable in one IRE walk
*/
static void
{
if (ire->ire_testhidden)
return;
return;
}
return;
}
}
/*
* Return all IRE types for route table... let caller pick and choose
*/
}
/* indirect(4), direct(3), or invalid(2) */
else
/* Add the IRE_IF_CLONE's counters to their parent IRE_INTERFACE */
}
}
} else {
}
ip1dbg(("ip_snmp_get2_v4: failed to allocate %u bytes\n",
}
ip1dbg(("ip_snmp_get2_v4: failed to allocate %u "
}
}
/* bump route index for next pass */
}
/*
* ire_walk routine to create ipv6RouteEntryTable and ipRouteEntryTable.
*/
static void
{
if (ire->ire_testhidden)
return;
return;
}
return;
}
}
/*
* Return all IRE types for route table... let caller pick and choose
*/
}
/* remote(4), local(3), or discard(2) */
else
re->ipv6RoutePolicy = 0;
re->ipv6RouteNextHopRDI = 0;
re->ipv6RouteWeight = 0;
re->ipv6RouteMetric = 0;
/* Add the IRE_IF_CLONE's counters to their parent IRE_INTERFACE */
}
}
} else {
}
ip1dbg(("ip_snmp_get2_v6: failed to allocate %u bytes\n",
}
ip1dbg(("ip_snmp_get2_v6: failed to allocate %u "
}
}
/* bump route index for next pass */
}
/*
* ncec_walk routine to create ipv6NetToMediaEntryTable
*/
static int
{
/* skip arpce entries, and loopback ncec entries */
return (0);
/*
* Neighbor cache entry attached to IRE with on-link
* destination.
* We report all IPMP groups on ncec_ill which is normally the upper.
*/
}
/*
* Note: Returns ND_* states. Should be:
* reachable(1), stale(2), delay(3), probe(4),
* invalid(5), unknown(6)
*/
/* other(1), dynamic(2), static(3), local(4) */
if (NCE_MYADDR(ncec)) {
} else {
}
ip1dbg(("ip_snmp_get2_v6_media: failed to allocate %u bytes\n",
}
return (0);
}
int
{
int flags = 0;
if (NCE_ISREACHABLE(ncec))
flags |= ACE_F_RESOLVED;
flags |= ACE_F_AUTHORITY;
flags |= ACE_F_PUBLISH;
flags |= ACE_F_PERMANENT;
if (NCE_MYADDR(ncec))
flags |= ACE_F_AUTHORITY;
flags |= ACE_F_DELAYED;
return (flags);
}
/*
* ncec_walk routine to create ipNetToMediaEntryTable
*/
static int
{
const char *name = "unknown";
return (0);
/* We report all IPMP groups on ncec_ill which is normally the upper. */
/* Based on RFC 4293: other(1), inval(2), dyn(3), stat(4) */
if (NCE_MYADDR(ncec)) {
} else {
}
sizeof (ncec_addr));
/*
* map all the flags to the ACE counterpart.
*/
if (!NCE_ISREACHABLE(ncec))
else {
}
}
ip1dbg(("ip_snmp_get2_v4_media: failed to allocate %u bytes\n",
}
return (0);
}
/*
* return (0) if invalid set request, 1 otherwise, including non-tcp requests
*/
/* ARGSUSED */
int
{
switch (level) {
case MIB2_IP:
case MIB2_ICMP:
switch (name) {
default:
break;
}
return (1);
default:
return (1);
}
}
/*
* When there exists both a 64- and 32-bit counter of a particular type
* (i.e., InReceives), only the 64-bit counters are added.
*/
void
{
}
void
{
}
/*
* Called before the options are updated to check if this packet will
* be source routed from here.
* This routine assumes that the options are well formed i.e. that they
* have already been checked.
*/
{
if (IS_SIMPLE_IPH(ipha)) {
ip2dbg(("not source routed\n"));
return (B_FALSE);
}
ip2dbg(("ip_source_routed: opt %d, len %d\n",
switch (optval) {
case IPOPT_SSRR:
case IPOPT_LSRR:
/*
* If dst is one of our addresses and there are some
* entries left in the source route return (true).
*/
ip2dbg(("ip_source_routed: not next"
" source route 0x%x\n",
return (B_FALSE);
}
off--;
if (optlen < IP_ADDR_LEN ||
/* End of source route */
ip1dbg(("ip_source_routed: end of SR\n"));
return (B_FALSE);
}
return (B_TRUE);
}
}
ip2dbg(("not source routed\n"));
return (B_FALSE);
}
/*
* ip_unbind is called by the transports to remove a conn from
* the fanout table.
*/
void
{
connp->conn_anon_port = 0;
}
}
/*
* Used for deciding the MSS size for the upper layer. Thus
* we need to check the outbound policy values in the conn.
*/
int
{
return (0);
return (0);
}
/*
* Returns an estimate of the IPsec headers size. This is used if
* we don't want to call into IPsec to get the exact size.
*/
int
{
ipsec_action_t *a;
return (0);
a = ixa->ixa_ipsec_action;
if (a == NULL) {
}
return (a->ipa_ovhd);
}
/*
* If there are any source route options, return the true final
* destination. Otherwise, return the destination.
*/
{
if (IS_SIMPLE_IPH(ipha))
return (dst);
switch (optval) {
case IPOPT_SSRR:
case IPOPT_LSRR:
/*
* If one of the conditions is true, it means
* end of options and dst already has the right
* value.
*/
}
return (dst);
default:
break;
}
}
return (dst);
}
/*
* Outbound IP fragmentation routine.
* Assumes the caller has checked whether or not fragmentation should
* be allowed. Here we copy the DF bit from the header to all the generated
* fragments.
*/
int
{
int i1;
int hdr_len;
int ip_data_end;
int len;
int offset;
int error = 0;
ip0dbg(("Packet length mismatch: %d, %ld\n",
return (EINVAL);
}
if (max_frag == 0) {
ip1dbg(("ip_fragment_v4: max_frag is zero. Dropping packet\n"));
return (EINVAL);
}
/*
* Establish the starting offset. May not be zero if we are fragging
* a fragment that is being forwarded.
*/
/* TODO why is this test needed? */
/* TODO: notify ulp somehow */
return (EINVAL);
}
ipha->ipha_hdr_checksum = 0;
/*
* Establish the number of bytes maximum per frag, after putting
* in the header.
*/
/* Get a copy of the header for the trailing frags */
mp);
return (ENOBUFS);
}
/* Store the starting offset, with the MoreFrags flag. */
/* Establish the ending byte offset, based on the starting offset. */
offset <<= 3;
/* Store the length of the first fragment in the IP header. */
/*
* Compute the IP header checksum for the first frag. We have to
* watch out that we stop at the end of the header.
*/
/*
* Now carve off the first frag. Note that this will include the
* original IP header.
*/
return (ENOBUFS);
}
/* No point in sending the other fragments */
return (error);
}
/* No need to redo state machine in loop */
ixaflags &= ~IXAF_REACH_CONF;
/* Advance the offset to the second frag starting point. */
/*
* Update hdr_len from the copied header - there might be less options
* in the later fragments.
*/
/* Loop until done. */
for (;;) {
/*
* Carve off the appropriate amount from the original
* datagram.
*/
break;
}
/*
* More frags after this one. Get another copy
* of the header.
*/
/* Inline IP header */
} else {
break;
}
/* Get priority marking, if any. */
}
} else {
/*
* Last frag. Consume the header. Set len to
* the length of this last piece.
*/
/*
* Carve off the appropriate amount from the original
* datagram.
*/
break;
}
/* Inline IP header */
} else {
/* Get priority marking, if any. */
}
/* A frag of a frag might have IPH_MF non-zero */
}
/* Store the offset and flags in the IP header. */
/* Store the length in the IP header. */
/*
* Set the IP header checksum. Note that mp is just
* the header, so this is easy to pass to ip_csum.
*/
nolzid, ixa_cookie);
/* All done if we just consumed the hdr_mp. */
return (error);
}
/* No point in sending the other fragments */
break;
}
/* Otherwise, advance and loop. */
}
/* Clean up following allocation failure. */
return (error);
}
/*
* Copy the header plus those options which have the copy bit set
*/
static mblk_t *
{
/*
* Quick check if we need to look for options without the copy bit
* set
*/
if (!mp)
return (mp);
return (mp);
}
while (hdr_len > 0) {
break;
optlen = 1;
else
if (optval & IPOPT_COPY) {
}
}
/*
* Make sure that we drop an even number of words by filling
* with EOL to the next word boundary.
*/
/* Update header length */
return (mp);
}
/*
* Update any source route, record route, or timestamp options when
* sending a packet back to ourselves.
* Check that we are at end of strict source route.
* The options have been sanity checked by ip_output_options().
*/
void
{
switch (optval) {
case IPOPT_SSRR:
case IPOPT_LSRR:
off--;
if (optlen < IP_ADDR_LEN ||
/* End of source route */
break;
}
/*
* This will only happen if two consecutive entries
* in the source route contains our address or if
* it is a packet with a loose source route which
* reaches us before consuming the whole source route
*/
if (optval == IPOPT_SSRR) {
return;
}
/*
* Hack: instead of dropping the packet truncate the
* source route to what has been used by filling the
* rest with IPOPT_NOP.
*/
}
break;
case IPOPT_RR:
off--;
if (optlen < IP_ADDR_LEN ||
/* No more room - ignore */
ip1dbg((
"ip_output_local_options: end of RR\n"));
break;
}
break;
case IPOPT_TS:
/* Insert timestamp if there is romm */
case IPOPT_TS_TSONLY:
break;
case IPOPT_TS_PRESPEC:
case IPOPT_TS_PRESPEC_RFC791:
/* Verify that the address matched */
/* Not for us */
break;
}
/* FALLTHRU */
case IPOPT_TS_TSANDADDR:
break;
default:
/*
* ip_*put_options should have already
* dropped this packet.
*/
"unknown IT - bug in ip_output_options?\n");
return; /* Keep "lint" happy */
}
/* Increase overflow counter */
(off << 4);
break;
}
case IPOPT_TS_PRESPEC:
case IPOPT_TS_PRESPEC_RFC791:
case IPOPT_TS_TSANDADDR:
/* FALLTHRU */
case IPOPT_TS_TSONLY:
/* Compute # of milliseconds since midnight */
gethrestime(&now);
break;
}
break;
}
}
}
/*
* Prepend an M_DATA fastpath header, and if none present prepend a
* DL_UNITDATA_REQ. Frees the mblk on failure.
*
* nce_dlur_mp and nce_fp_mp can not disappear once they have been set.
* If there is a change to them, the nce will be deleted (condemned) and
* a new nce_t will be created when packets are sent. Thus we need no locks
* to access those fields.
*
* We preserve b_band to support IPQoS. If a DL_UNITDATA_REQ is prepended
* we place b_band in dl_priority.dl_max.
*/
static mblk_t *
{
/*
* Check if we have enough room to prepend fastpath
* header
*/
/*
* Set the b_rptr to the start of the link layer
* header
*/
return (mp);
}
return (NULL);
}
/*
* XXX disable ICK_VALID and compute checksum
* here; can happen if nce_fp_mp changes and
* it can't be copied now due to insufficient
* space. (unlikely, fp mp can change, but it
* does not increase in length)
*/
return (mp1);
}
return (NULL);
}
if (priority != 0) {
}
return (mp1);
}
/*
* Finish the outbound IPsec processing. This function is called from
* ipsec_out_process() if the IPsec packet was processed
* synchronously, or from {ah,esp}_kcf_callback_outbound() if it was processed
* asynchronously.
*
* This is common to IPv4 and IPv6.
*/
int
{
if (ixaflags & IXAF_IS_IPV4) {
} else {
}
/*
* We release any hard reference on the SAs here to make
* sure the SAs can be garbage collected. ipsr_sa has a soft reference
* on the SAs.
* If in the future we want the hard latching of the SAs in the
* ip_xmit_attr_t then we should remove this.
*/
}
}
/* Do we need to fragment? */
if (ixaflags & IXAF_IS_IPV4) {
/*
* We check for the DF case in ipsec_out_process
* hence this only handles the non-DF case.
*/
&ixa->ixa_cookie));
} else {
/* MIB and ip_drop_output already done */
return (ENOMEM);
}
pktlen += sizeof (ip6_frag_t);
}
}
}
}
/*
* Finish the inbound IPsec processing. This function is called from
* ipsec_out_process() if the IPsec packet was processed
* synchronously, or from {ah,esp}_kcf_callback_outbound() if it was processed
* asynchronously.
*
* This is common to IPv4 and IPv6.
*/
void
{
/* Length might have changed */
if (iraflags & IRAF_IS_IPV4) {
} else {
&nexthdrp)) {
/* Malformed packet */
return;
}
}
}
/*
* Select which AH & ESP SA's to use (if any) for the outbound packet.
*
* If this function returns B_TRUE, the requested SA's have been filled
* into the ixa_ipsec_*_sa pointers.
*
* If the function returns B_FALSE, the packet has been "consumed", most
* likely by an ACQUIRE sent up via PF_KEY to a key management daemon.
*
* The SA references created by the protocol-specific "select"
* function will be released in ip_output_post_ipsec.
*/
static boolean_t
{
}
/*
* We have an action. now, let's select SA's.
* A side effect of setting ixa_ipsec_*_sa is that it will
* be cached in the conn_t.
*/
if (ap->ipa_want_esp) {
}
}
if (ap->ipa_want_ah) {
}
/*
* The ESP and AH processing order needs to be preserved
* when both protocols are required (ESP should be applied
* before AH for an outbound packet). Force an ESP ACQUIRE
* when both ESP and AH are required, and an AH ACQUIRE
* is needed.
*/
}
/*
* Send an ACQUIRE (extended, regular, or both) if we need one.
* Release SAs that got referenced, but will not be used until we
* acquire _all_ of the SAs we need.
*/
if (need_ah_acquire || need_esp_acquire) {
}
}
return (B_FALSE);
}
return (B_TRUE);
}
/*
* Handle IPsec output processing.
* This function is only entered once for a given packet.
* We try to do things synchronously, but if we need to have user-level
* set up SAs, or ESP or AH uses asynchronous kEF, then the operation
* will be completed
* - when the SAs are added in esp_add_sa_finish/ah_add_sa_finish
* - when asynchronous ESP is done it will do AH
*
* In all cases we come back in ip_output_post_ipsec() to fragment and
* send out the packet.
*/
int
{
if (!ipsec_loaded(ipss)) {
&ipss->ipsec_dropper);
return (ENOTSUP);
}
}
/* Handle explicit drop action and bypass. */
case IPSEC_ACT_DISCARD:
case IPSEC_ACT_REJECT:
return (EHOSTUNREACH); /* IPsec policy failure */
case IPSEC_ACT_BYPASS:
}
/*
* The order of processing is first insert a IP header if needed.
* Then insert the ESP header and then the AH header.
*/
/*
* First get the outer IP header before sending
* it to ESP.
*/
"ipsec_out_process: "
"Self-Encapsulation failed: Out of memory\n");
return (ENOBUFS);
}
sizeof (ipha_t));
oipha->ipha_hdr_checksum = 0;
}
/* If we need to wait for a SA then we can't return any errno */
return (0);
/*
* By now, we know what SA's to use. Toss over to ESP & AH
* to do the heavy lifting.
*/
if (ap->ipa_want_esp) {
/*
* Either it failed or is pending. In the former case
* ipIfStatsInDiscards was increased.
*/
return (0);
}
}
if (ap->ipa_want_ah) {
/*
* Either it failed or is pending. In the former case
* ipIfStatsInDiscards was increased.
*/
return (0);
}
}
/*
* We are done with IPsec processing. Send it over
* the wire.
*/
}
/*
* to complete. This involves waiting for the ire and ipif refcnts to go down
* to zero. Subsequently the ioctl is restarted from ipif_ill_refrele_tail.
*/
/* ARGSUSED */
void
{
int err;
/* Existence of mp1 verified in ip_wput_nondata */
/*
* Special case where ipx_current_ipif is not set:
* ill_phyint_reinit merged the v4 and v6 into a single ipsq.
* We are here as were not able to complete the operation in
* ipif_set_values because we could not become exclusive on
* the new ipsq.
*/
}
/* This a old style SIOC[GS]IF* command */
/* This a new style SIOC[GS]LIF* command */
} else {
}
}
/*
* ioctl processing
*
* ioctl processing starts with ip_sioctl_copyin_setup(), which looks up
* the ioctl command in the ioctl tables, determines the copyin data size
* from the ipi_copyin_size field, and does an mi_copyin() of that size.
*
* ioctl processing then continues when the M_IOCDATA makes its way down to
* ip_wput_nondata(). The ioctl is looked up again in the ioctl table, its
* associated 'conn' is refheld till the end of the ioctl and the general
* ioctl processing function ip_process_ioctl() is called to extract the
* arguments and process the ioctl. To simplify extraction, ioctl commands
* are "typed" based on the arguments they take (e.g., LIF_CMD which takes a
* `struct lifreq'), and a common extract function (e.g., ip_extract_lifreq())
* is used to extract the ioctl's arguments.
*
* ip_process_ioctl determines if the ioctl needs to be serialized, and if
* so goes thru the serialization primitive ipsq_try_enter. Then the
* appropriate function to handle the ioctl is called based on the entry in
* the ioctl table. ioctl completion is encapsulated in ip_ioctl_finish
* which also refreleases the 'conn' that was refheld at the start of the
* ioctl. Finally ipsq_exit is called if needed to exit the ipsq.
*
* Many exclusive ioctls go thru an internal down up sequence as part of
* the operation. For example an attempt to change the IP address of an
* ipif entails ipif_down, set address, ipif_up. Bringing down the interface
* does all the cleanup such as deleting all ires that use this address.
* Then we need to wait till all references to the interface go away.
*/
void
{
int err;
/*
* SIOCLIFADDIF needs to go thru a special path since the
* ill may not exist yet. This happens in the case of lo0
* which is created using this ioctl.
*/
return;
}
switch (ipip->ipi_cmd_type) {
case MISC_CMD:
case MSFILT_CMD:
/*
* All MISC_CMD ioctls come in here -- e.g. SIOCGLIFCONF.
*/
/* ioctl comes down the ill */
}
err = 0;
break;
case IF_CMD:
case LIF_CMD:
break;
case ARP_CMD:
case XARP_CMD:
break;
default:
ASSERT(0);
}
if (extract_funcp != NULL) {
if (err != 0) {
char *, "ip_process_ioctl finish err",
return;
}
/*
* All of the extraction functions return a refheld ipif.
*/
}
/*
* A return value of EINPROGRESS means the ioctl is
* either queued and waiting for some reason or has
* already completed.
*/
char *, "ip_process_ioctl finish RD",
} else {
char *, "ip_process_ioctl finish RD",
}
return;
}
/*
* If ipsq is non-NULL, we are already being called exclusively
*/
return;
}
}
/*
* Release the ipif so that ipif_down and friends that wait for
* references to go away are not misled about the current ipif_refcnt
* values. We are writer so we can access the ipif even after releasing
* the ipif.
*/
/*
* A return value of EINPROGRESS means the ioctl is
* either queued and waiting for some reason or has
* already completed.
*/
if (entered_ipsq)
}
/*
* Complete the ioctl. Typically ioctls use the mi package and need to
* do mi_copyout/mi_copy_done.
*/
void
{
if (err == EINPROGRESS)
return;
if (CONN_Q(q)) {
}
switch (mode) {
case COPYOUT:
if (err == 0)
mi_copyout(q, mp);
else
break;
case NO_COPYOUT:
break;
default:
break;
}
/*
* The conn refhold and ioctlref placed on the conn at the start of the
* ioctl are released here.
*/
}
}
/* Handles all non data messages */
void
{
char *proto_str;
if (CONN_Q(q))
else
case M_IOCTL:
/*
* IOCTL processing begins in ip_sioctl_copyin_setup which
* will arrange to copy in associated control structures.
*/
ip_sioctl_copyin_setup(q, mp);
return;
case M_IOCDATA:
/*
* Ensure that this is associated with one of our trans-
* parent ioctls. If it's not ours, discard it if we're
* running as a driver, or pass it on if we're a module.
*/
goto nak;
} else {
}
return;
}
/*
* The ioctl is one we recognise, but is not consumed
* by IP as a module and we are a module, so we drop
*/
goto nak;
}
/* IOCTL continuation following copyin or copyout. */
/*
* The copy operation failed. mi_copy_state already
* cleaned up, so we're out of here.
*/
return;
}
/*
* If we just completed a copy in, we become writer and
* continue processing in ip_sioctl_copyin_done. If it
* was a copy out, we call mi_copyout again. If there is
* nothing more to copy out, it will complete the IOCTL.
*/
return;
}
/*
* Check for cases that need more copying. A return
* value of 0 means a second copyin has been started,
* so we return; a return value of 1 means no more
* copying is needed, so we continue.
*/
if (ip_copyin_msfilter(q, mp) == 0)
return;
}
/*
* Refhold the conn, till the ioctl completes. This is
* needed in case the ioctl ends up in the pending mp
* list. Every mp in the ipx_pending_mp list must have
* a refhold on the conn to resume processing. The
* refhold is released when the ioctl completes
* (whether normally or abnormally). An ioctlref is also
* placed on the conn to prevent TCP from removing the
* queue needed to send the ioctl reply back.
* In all cases ip_ioctl_finish is called to finish
* the ioctl and release the refholds.
*/
/* This is not a reentry */
} else {
return;
}
}
} else {
mi_copyout(q, mp);
}
return;
case M_IOCNAK:
/*
* The only way we could get here is if a resolver didn't like
* an IOCTL we sent it. This shouldn't happen.
*/
"ip_wput_nondata: unexpected M_IOCNAK, ioc_cmd 0x%x",
return;
case M_IOCACK:
goto nak;
case M_FLUSH:
if (q->q_next) {
return;
}
return;
}
return;
case M_CTL:
break;
case M_PROTO:
case M_PCPROTO:
/*
* The only PROTO messages we expect are SNMP-related.
*/
case T_SVR4_OPTMGMT_REQ:
ip2dbg(("ip_wput_nondata: T_SVR4_OPTMGMT_REQ "
"flags %x\n",
proto_str = "T_SVR4_OPTMGMT_REQ";
goto protonak;
}
/*
* All Solaris components should pass a db_credp
* for this TPI message, hence we ASSERT.
* But in case there is some other M_PROTO that looks
* like a TPI message sent by some other kernel
* component, we check and return an error.
*/
return;
}
proto_str = "Bad SNMPCOM request?";
goto protonak;
}
return;
default:
ip1dbg(("ip_wput_nondata: dropping M_PROTO prim %u\n",
return;
}
default:
break;
}
if (q->q_next) {
} else
return;
nak:
return;
}
/*
* Process IP options in an outbound packet. Verify that the nexthop in a
* strict source route is onlink.
* Returns non-zero if something fails in which case an ICMP error has been
* sent and mp freed.
*
* Assumes the ULP has called ip_massage_options to move nexthop into ipha_dst.
*/
int
{
ip2dbg(("ip_output_options\n"));
ip2dbg(("ip_output_options: opt %d, len %d\n",
switch (optval) {
case IPOPT_SSRR:
case IPOPT_LSRR:
ip1dbg((
"ip_output_options: bad option offset\n"));
(char *)ipha;
goto param_prob;
}
ip1dbg(("ip_output_options: next hop 0x%x\n",
/*
* For strict: verify that dst is directly
* reachable.
*/
if (optval == IPOPT_SSRR) {
NULL);
ip1dbg(("ip_output_options: SSRR not"
" directly reachable: 0x%x\n",
goto bad_src_route;
}
}
break;
case IPOPT_RR:
ip1dbg((
"ip_output_options: bad option offset\n"));
(char *)ipha;
goto param_prob;
}
break;
case IPOPT_TS:
/*
* Verify that length >=5 and that there is either
* room for another timestamp or that the overflow
* counter is not maxed out.
*/
if (optlen < IPOPT_MINLEN_IT) {
goto param_prob;
}
ip1dbg((
"ip_output_options: bad option offset\n"));
(char *)ipha;
goto param_prob;
}
case IPOPT_TS_TSONLY:
break;
case IPOPT_TS_TSANDADDR:
case IPOPT_TS_PRESPEC:
case IPOPT_TS_PRESPEC_RFC791:
break;
default:
(char *)ipha;
goto param_prob;
}
/*
* No room and the overflow counter is 15
* already.
*/
goto param_prob;
}
break;
}
}
return (0);
ip1dbg(("ip_output_options: error processing IP options."));
return (-1);
return (-1);
}
/*
* The maximum value of conn_drain_list_cnt is CONN_MAXDRAINCNT.
* conn_drain_list_cnt can be changed by setting conn_drain_nthreads
*/
#define CONN_MAXDRAINCNT 64
static void
{
int i, j;
if ((ipst->ips_conn_drain_list_cnt == 0) ||
/*
* Default value of the number of drainers is the
* number of cpus, subject to maximum of 8 drainers.
*/
if (boot_max_ncpus != -1)
else
}
for (i = 0; i < TX_FANOUT_SIZE; i++) {
for (j = 0; j < ipst->ips_conn_drain_list_cnt; j++) {
}
}
}
static void
{
int i;
for (i = 0; i < TX_FANOUT_SIZE; i++) {
}
TX_FANOUT_SIZE * sizeof (idl_tx_list_t));
}
/*
* Note: For an overview of how flowcontrol is handled in IP please see the
* IP Flowcontrol notes at the top of this file.
*
* Flow control has blocked us from proceeding. Insert the given conn in one
* of the conn drain lists. These conn wq's will be qenabled later on when
* STREAMS flow control does a backenable. conn_walk_drain will enable
* the first conn in each of these drain lists. Each of these qenabled conns
* in turn enables the next in the list, after it runs, or when it closes,
* thus sustaining the drain process.
*/
void
{
/*
* The conn is closing as a result of which CONN_CLOSING
* is set. Return.
*/
return;
/*
* Assign the next drain list round robin. We dont' use
* a lock, and thus it may not be strictly round robin.
* conn_drain_list_index is always within bounds.
*/
index++;
index = 0;
}
/*
* The conn is already in the drain list, OR
* the conn is closing. We need to check again for
* the closing case again since close can happen
* after we drop the conn_lock, and before we
* acquire the CONN_DRAIN_LIST_LOCK.
*/
return;
} else {
}
/*
* The conn is not in the drain list. Insert it at the
* tail of the drain list. The drain list is circular
* and doubly linked. idl_conn points to the 1st element
* in the list.
*/
} else {
}
/*
* For non streams based sockets assert flow control.
*/
}
static void
{
/*
* Remove ourself from the drain list, if we did not do
* a putq, or if the conn is closing.
* Note: It is possible that q->q_first is non-null. It means
* that these messages landed after we did a enableok() in
* ip_wsrv. Thus STREAMS will call ip_wsrv once again to
* service them.
*/
/* Singleton in the list */
} else {
}
}
/*
* For streams based sockets open up flow control.
*/
if (!IPCL_IS_NONSTR(connp))
}
/*
* This conn is closing, and we are called from ip_close. OR
* this conn is draining because flow-control on the ill has been relieved.
*
* We must also need to remove conn's on this idl from the list, and also
* inform the sockfs upcalls about the change in flow-control.
*/
static void
{
/*
* connp->conn_idl is stable at this point, and no lock is needed
* to check it. If we are called from ip_close, close has already
* set CONN_CLOSING, thus freezing the value of conn_idl, and
* called us only because conn_idl is non-null. If we are called thru
* service, conn_idl could be null, but it cannot change because
* service is single-threaded per queue, and there cannot be another
* instance of service trying to call conn_drain_insert on this conn
* now.
*/
/*
* If connp->conn_idl is null, the conn has not been inserted into any
* drain list even once since creation of the conn. Just return.
*/
return;
/* This conn is currently not in the drain list. */
return;
}
if (!closing) {
/*
* This conn is the current drainer. If this is the last conn
* in the drain list, we need to do more checks, in the 'if'
* below. Otherwwise we need to just qenable the next conn,
* to sustain the draining, and is handled in the 'else'
* below.
*/
while (next_connp != connp) {
}
}
}
/*
* Write service routine. Shared perimeter entry point.
* The device queue's messages has fallen below the low water mark and STREAMS
* has backenabled the ill_wq. Send sockfs notification about flow-control onx
* each waiting conn.
*/
void
{
if (ill->ill_state_flags == 0) {
/*
* The device flow control has opened up.
* Walk through conn drain lists and qenable the
* first conn in each list. This makes sense only
* if the stream is fully plumbed and setup.
* Hence the ill_state_flags check above.
*/
ip1dbg(("ip_wsrv: walking\n"));
}
}
/*
* Callback to disable flow control in IP.
*
* This is a mac client callback added when the DLD_CAPAB_DIRECT capability
* is enabled.
*
* When MAC_TX() is not able to send any more packets, dld sets its queue
* to QFULL and enable the STREAMS flow control. Later, when the underlying
* driver is able to continue to send packets, it calls mac_tx_(ring_)update()
* function and wakes up corresponding mac worker threads, which in turn
* calls this callback function, and disables flow control.
*/
void
{
/* add code to to set a flag to indicate idl_txl is enabled */
}
/*
* Flowcontrol has relieved, and STREAMS has backenabled us. For each list
* of conns that need to be drained, check if drain is already in progress.
* If so set the idl_repeat bit, indicating that the last conn in the list
* needs to reinitiate the drain once again, for the list. If drain is not
* in progress for the list, initiate the draining, by qenabling the 1st
* conn in the list. The drain is self-sustaining, each qenabled conn will
*/
static void
{
int i;
for (i = 0; i < ipst->ips_conn_drain_list_cnt; i++) {
}
}
/*
* Determine if the ill and multicast aspects of that packets
* "matches" the conn.
*/
{
/*
* conn_incoming_ifindex is set by IP_BOUND_IF which limits
* unicast, broadcast and multicast reception to
* conn_incoming_ifindex.
* conn_wantpacket is called for unicast, broadcast and
* multicast packets.
*/
/* mpathd can bind to the under IPMP interface, which we allow */
if (!IS_UNDER_IPMP(ill))
return (B_FALSE);
return (B_FALSE);
}
return (B_FALSE);
return (B_TRUE);
if (connp->conn_multi_router) {
/* multicast packet and multicast router socket: send up */
return (B_TRUE);
}
return (B_TRUE);
}
void
{
if (IPCL_IS_NONSTR(connp)) {
if (flow_stopped != NULL)
*flow_stopped = B_TRUE;
} else {
mutex_enter(QLOCK(q));
/* still need to set QFULL */
/* set flow_stopped to true under QLOCK */
if (flow_stopped != NULL)
*flow_stopped = B_TRUE;
mutex_exit(QLOCK(q));
} else {
/* flow_stopped is left unchanged */
mutex_exit(QLOCK(q));
}
}
}
}
void
{
if (IPCL_IS_NONSTR(connp)) {
if (flow_stopped != NULL)
*flow_stopped = B_FALSE;
} else {
mutex_enter(QLOCK(q));
/* set flow_stopped to false under QLOCK */
if (flow_stopped != NULL)
*flow_stopped = B_FALSE;
mutex_exit(QLOCK(q));
qbackenable(q, 0);
} else {
/* flow_stopped is left unchanged */
mutex_exit(QLOCK(q));
}
}
}
}
/*
* Return the length in bytes of the IPv4 headers (base header, label, and
* other IP options) that will be needed based on the
* ip_pkt_t structure passed by the caller.
*
* The returned length does not include the length of the upper level
* protocol (ULP) header.
* The caller needs to check that the length doesn't exceed the max for IPv4.
*/
int
{
int len;
/* We need to round up here */
}
}
return (len);
}
/*
* All-purpose routine to build an IPv4 header with options based
* on the abstract ip_pkt_t.
*
* The caller has to set the source and destination address as well as
* ipha_length. The caller has to massage any source route and compensate
* for the ULP pseudo-header checksum due to the source route.
*/
void
{
/* Initialize IPv4 header */
ipha->ipha_ident = 0;
ipha->ipha_hdr_checksum = 0;
/* We need to round up here */
}
}
}
}
/* Allocate the private structure */
static int
ip_priv_alloc(void **bufp)
{
void *buf;
return (ENOMEM);
return (0);
}
/* Function to delete the private structure */
void
ip_priv_free(void *buf)
{
}
/*
* The entry point for IPPF processing.
* If the classifier (IPGPC_CLASSIFY) is not loaded and configured, the
* routine just returns.
*
* When called, ip_process generates an ipp_packet_t structure
* which holds the state information for this packet and invokes the
* the classifier (via ipp_packet_process). The classification, depending on
* configured filters, results in a list of actions for this packet. Invoking
* an action may cause the packet to be dropped, in which case we return NULL.
* proc indicates the callout position for
* this packet and ill is the interface this packet arrived on or will leave
* on (inbound and outbound resp.).
*
* We do the processing on the rill (mapped to the upper if ipmp), but MIB
* on the ill corrsponding to the destination IP address.
*/
mblk_t *
{
int rc = 0;
/* If the classifier is not loaded, return */
return (mp);
}
/* Allocate the packet structure */
if (rc != 0)
goto drop;
/* Allocate the private structure */
if (rc != 0) {
goto drop;
}
/* Invoke the classifier */
if (rc != 0)
goto drop;
return (mp);
} else {
/* No mp to trace in ip_drop_input/ip_drop_output */
}
drop:
} else {
}
return (NULL);
}
/*
* all the interfaces crossed by the related multirt routes.
* The call is considered successful if the operation succeeds
* on at least one interface.
*
* This assumes that a set of IRE_HOST/RTF_MULTIRT has been created for the
* multicast addresses with the ire argument being the first one.
* We walk the bucket to find all the of those.
*
* Common to IPv4 and IPv6.
*/
static int
{
int ifindex;
int error = 0;
int result;
int match_flags;
if (IN6_IS_ADDR_V4MAPPED(v6group)) {
} else {
}
result = 0;
continue;
/* We handle -ifp routes by matching on the ill if set */
if (isv6) {
continue;
} else {
continue;
}
/* No interface route exists for the gateway; skip this ire. */
continue;
continue;
}
/*
* The operation is considered a success if
* it succeeds at least once on any one interface.
*/
if (error == 0)
}
/*
* Consider the call as successful if we succeeded on at least
* one interface. Otherwise, return the last encountered error.
*/
}
/*
* Get the CGTP (multirouting) filtering status.
* If 0, the CGTP hooks are transparent.
*/
/* ARGSUSED */
static int
{
return (0);
}
/*
* Set the CGTP (multirouting) filtering status.
* If the status is changed from active to transparent
* or from transparent to active, forward the new status
* to the filtering module (if loaded).
*/
/* ARGSUSED */
static int
{
long new_value;
return (EPERM);
return (EINVAL);
}
if ((!*ip_cgtp_filter_value) && new_value) {
" (module not loaded)" : "");
}
if (*ip_cgtp_filter_value && (!new_value)) {
" (module not loaded)" : "");
}
int res;
if (res)
return (res);
}
return (0);
}
/*
* Return the expected CGTP hooks version number.
*/
int
ip_cgtp_filter_supported(void)
{
return (ip_cgtp_filter_rev);
}
/*
* CGTP hooks can be registered by invoking this function.
* Checks that the version number matches.
*/
int
{
netstack_t *ns;
return (ENOTSUP);
return (EINVAL);
return (EALREADY);
}
return (0);
}
/*
* CGTP hooks can be unregistered by invoking this function.
* Returns ENXIO if there was no registration.
* Returns EBUSY if the ndd variable has not been turned off.
*/
int
{
netstack_t *ns;
return (EINVAL);
if (ipst->ips_ip_cgtp_filter) {
return (EBUSY);
}
return (ENXIO);
}
return (0);
}
/*
* Check whether there is a CGTP filter registration.
* Returns non-zero if there is a registration, otherwise returns zero.
* Note: returns zero if bad stackid.
*/
int
{
netstack_t *ns;
int ret;
return (0);
ret = 1;
else
ret = 0;
return (ret);
}
static int
ip_squeue_switch(int val)
{
int rval;
switch (val) {
case IP_SQUEUE_ENTER_NODRAIN:
rval = SQ_NODRAIN;
break;
case IP_SQUEUE_ENTER:
rval = SQ_PROCESS;
break;
case IP_SQUEUE_FILL:
default:
break;
}
return (rval);
}
/* ARGSUSED */
static int
{
int *v = (int *)addr;
long new_value;
return (EPERM);
return (EINVAL);
*v = new_value;
return (0);
}
/*
* Handle ndd set of variables which require PRIV_SYS_NET_CONFIG such as
* ip_debug.
*/
/* ARGSUSED */
static int
{
int *v = (int *)addr;
long new_value;
return (EPERM);
return (EINVAL);
*v = new_value;
return (0);
}
static void *
{
{ "ip_udp_fannorm", KSTAT_DATA_UINT64 },
{ "ip_udp_fanmb", KSTAT_DATA_UINT64 },
{ "ip_recv_pullup", KSTAT_DATA_UINT64 },
{ "ip_db_ref", KSTAT_DATA_UINT64 },
{ "ip_notaligned", KSTAT_DATA_UINT64 },
{ "ip_multimblk", KSTAT_DATA_UINT64 },
{ "ip_opt", KSTAT_DATA_UINT64 },
{ "ipsec_proto_ahesp", KSTAT_DATA_UINT64 },
{ "ip_conn_flputbq", KSTAT_DATA_UINT64 },
{ "ip_conn_walk_drain", KSTAT_DATA_UINT64 },
{ "ip_out_sw_cksum", KSTAT_DATA_UINT64 },
{ "ip_out_sw_cksum_bytes", KSTAT_DATA_UINT64 },
{ "ip_in_sw_cksum", KSTAT_DATA_UINT64 },
{ "ip_ire_reclaim_calls", KSTAT_DATA_UINT64 },
{ "ip_ire_reclaim_deleted", KSTAT_DATA_UINT64 },
{ "ip_nce_reclaim_calls", KSTAT_DATA_UINT64 },
{ "ip_nce_reclaim_deleted", KSTAT_DATA_UINT64 },
{ "ip_dce_reclaim_calls", KSTAT_DATA_UINT64 },
{ "ip_dce_reclaim_deleted", KSTAT_DATA_UINT64 },
{ "ip_tcp_in_full_hw_cksum_err", KSTAT_DATA_UINT64 },
{ "ip_tcp_in_part_hw_cksum_err", KSTAT_DATA_UINT64 },
{ "ip_tcp_in_sw_cksum_err", KSTAT_DATA_UINT64 },
{ "ip_udp_in_full_hw_cksum_err", KSTAT_DATA_UINT64 },
{ "ip_udp_in_part_hw_cksum_err", KSTAT_DATA_UINT64 },
{ "ip_udp_in_sw_cksum_err", KSTAT_DATA_UINT64 },
{ "conn_in_recvdstaddr", KSTAT_DATA_UINT64 },
{ "conn_in_recvopts", KSTAT_DATA_UINT64 },
{ "conn_in_recvif", KSTAT_DATA_UINT64 },
{ "conn_in_recvslla", KSTAT_DATA_UINT64 },
{ "conn_in_recvucred", KSTAT_DATA_UINT64 },
{ "conn_in_recvttl", KSTAT_DATA_UINT64 },
{ "conn_in_recvhopopts", KSTAT_DATA_UINT64 },
{ "conn_in_recvhoplimit", KSTAT_DATA_UINT64 },
{ "conn_in_recvdstopts", KSTAT_DATA_UINT64 },
{ "conn_in_recvrthdrdstopts", KSTAT_DATA_UINT64 },
{ "conn_in_recvrthdr", KSTAT_DATA_UINT64 },
{ "conn_in_recvpktinfo", KSTAT_DATA_UINT64 },
{ "conn_in_recvtclass", KSTAT_DATA_UINT64 },
{ "conn_in_timestamp", KSTAT_DATA_UINT64 },
};
return (NULL);
return (ksp);
}
static void
{
}
}
static void *
{
{ "forwarding", KSTAT_DATA_UINT32, 0 },
{ "defaultTTL", KSTAT_DATA_UINT32, 0 },
{ "inReceives", KSTAT_DATA_UINT64, 0 },
{ "inHdrErrors", KSTAT_DATA_UINT32, 0 },
{ "inAddrErrors", KSTAT_DATA_UINT32, 0 },
{ "forwDatagrams", KSTAT_DATA_UINT64, 0 },
{ "inUnknownProtos", KSTAT_DATA_UINT32, 0 },
{ "inDiscards", KSTAT_DATA_UINT32, 0 },
{ "inDelivers", KSTAT_DATA_UINT64, 0 },
{ "outRequests", KSTAT_DATA_UINT64, 0 },
{ "outDiscards", KSTAT_DATA_UINT32, 0 },
{ "outNoRoutes", KSTAT_DATA_UINT32, 0 },
{ "reasmTimeout", KSTAT_DATA_UINT32, 0 },
{ "reasmReqds", KSTAT_DATA_UINT32, 0 },
{ "reasmOKs", KSTAT_DATA_UINT32, 0 },
{ "reasmFails", KSTAT_DATA_UINT32, 0 },
{ "fragOKs", KSTAT_DATA_UINT32, 0 },
{ "fragFails", KSTAT_DATA_UINT32, 0 },
{ "fragCreates", KSTAT_DATA_UINT32, 0 },
{ "addrEntrySize", KSTAT_DATA_INT32, 0 },
{ "routeEntrySize", KSTAT_DATA_INT32, 0 },
{ "netToMediaEntrySize", KSTAT_DATA_INT32, 0 },
{ "routingDiscards", KSTAT_DATA_UINT32, 0 },
{ "inErrs", KSTAT_DATA_UINT32, 0 },
{ "noPorts", KSTAT_DATA_UINT32, 0 },
{ "inCksumErrs", KSTAT_DATA_UINT32, 0 },
{ "reasmDuplicates", KSTAT_DATA_UINT32, 0 },
{ "reasmPartDups", KSTAT_DATA_UINT32, 0 },
{ "forwProhibits", KSTAT_DATA_UINT32, 0 },
{ "udpInCksumErrs", KSTAT_DATA_UINT32, 0 },
{ "udpInOverflows", KSTAT_DATA_UINT32, 0 },
{ "rawipInOverflows", KSTAT_DATA_UINT32, 0 },
{ "ipsecInSucceeded", KSTAT_DATA_UINT32, 0 },
{ "ipsecInFailed", KSTAT_DATA_INT32, 0 },
{ "memberEntrySize", KSTAT_DATA_INT32, 0 },
{ "inIPv6", KSTAT_DATA_UINT32, 0 },
{ "outIPv6", KSTAT_DATA_UINT32, 0 },
{ "outSwitchIPv6", KSTAT_DATA_UINT32, 0 },
};
return (NULL);
sizeof (mib2_ipNetToMediaEntry_t);
return (ksp);
}
static void
{
}
}
static int
{
netstack_t *ns;
return (EIO);
if (rw == KSTAT_WRITE)
return (EACCES);
return (-1);
return (-1);
}
return (0);
}
static void *
{
{ "inMsgs", KSTAT_DATA_UINT32 },
{ "inErrors", KSTAT_DATA_UINT32 },
{ "inDestUnreachs", KSTAT_DATA_UINT32 },
{ "inTimeExcds", KSTAT_DATA_UINT32 },
{ "inParmProbs", KSTAT_DATA_UINT32 },
{ "inSrcQuenchs", KSTAT_DATA_UINT32 },
{ "inRedirects", KSTAT_DATA_UINT32 },
{ "inEchos", KSTAT_DATA_UINT32 },
{ "inEchoReps", KSTAT_DATA_UINT32 },
{ "inTimestamps", KSTAT_DATA_UINT32 },
{ "inTimestampReps", KSTAT_DATA_UINT32 },
{ "inAddrMasks", KSTAT_DATA_UINT32 },
{ "inAddrMaskReps", KSTAT_DATA_UINT32 },
{ "outMsgs", KSTAT_DATA_UINT32 },
{ "outErrors", KSTAT_DATA_UINT32 },
{ "outDestUnreachs", KSTAT_DATA_UINT32 },
{ "outTimeExcds", KSTAT_DATA_UINT32 },
{ "outParmProbs", KSTAT_DATA_UINT32 },
{ "outSrcQuenchs", KSTAT_DATA_UINT32 },
{ "outRedirects", KSTAT_DATA_UINT32 },
{ "outEchos", KSTAT_DATA_UINT32 },
{ "outEchoReps", KSTAT_DATA_UINT32 },
{ "outTimestamps", KSTAT_DATA_UINT32 },
{ "outTimestampReps", KSTAT_DATA_UINT32 },
{ "outAddrMasks", KSTAT_DATA_UINT32 },
{ "outAddrMaskReps", KSTAT_DATA_UINT32 },
{ "inChksumErrs", KSTAT_DATA_UINT32 },
{ "inUnknowns", KSTAT_DATA_UINT32 },
{ "inFragNeeded", KSTAT_DATA_UINT32 },
{ "outFragNeeded", KSTAT_DATA_UINT32 },
{ "outDrops", KSTAT_DATA_UINT32 },
{ "inOverFlows", KSTAT_DATA_UINT32 },
{ "inBadRedirects", KSTAT_DATA_UINT32 },
};
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);
}
/*
* This is the fanout function for raw socket opened for SCTP. Note
* that it is called after SCTP checks that there is no socket which
* wants a packet. Then before SCTP handles this out of the blue packet,
* this function is called to see if there is any raw socket for SCTP.
* If there is and it is bound to the correct address, the packet will
* be sent to that socket. Note that only one raw socket can be bound to
* a port. This is assured in ipcl_sctp_hash_insert();
*/
void
{
/*
* Although raw sctp is not summed, OOB chunks must be.
* Drop the packet here if the sctp checksum failed.
*/
if (iraflags & IRAF_SCTP_CSUM_ERR) {
return;
}
return;
}
return;
}
if (((iraflags & IRAF_IS_IPV4) ?
secure) {
/* Note that mp is NULL */
return;
}
}
if (iraflags & IRAF_ICMP_ERROR) {
} else {
/* This is the SOCK_RAW, IPPROTO_SCTP case. */
}
}
/*
* Free a packet that has the link-layer dl_unitdata_req_t or fast-path
* header before the ip payload.
*/
static void
{
/*
* fastpath header and ip header in the first mblk
*/
} else {
/*
* ip_xmit_attach_llhdr had to prepend an mblk to
* attach the fastpath header before ip header.
*/
}
} else {
}
}
/*
* Normal post fragmentation function.
*
* Send a packet using the passed in nce. This handles both IPv4 and IPv6
* using the same state machine.
*
* We return an error on failure. In particular we return EWOULDBLOCK
* when the driver flow controls. In that case this ensures that ip_wsrv runs
* (currently by canputnext failure resulting in backenabling from GLD.)
* This allows the callers of conn_ip_output() to use EWOULDBLOCK as an
* indication that they can flow control until ip_wsrv() tells then to restart.
*
* If the nce passed by caller is incomplete, this function
* queues the packet and if necessary, sends ARP request and bails.
* If the Neighbor Cache passed is fully resolved, we simply prepend
* the link-layer header to the packet, do ipsec hw acceleration
* work if necessary, and send the packet out on the wire.
*/
/* ARGSUSED6 */
int
{
/*
* the IXAF_NO_TRACE flag is set. We skip FW_HOOKS, DTRACE and ipobs
* in that case since they have seen the packet when it came here
* the first time.
*/
if (ixaflags & IXAF_NO_TRACE)
goto sendit;
if (ixaflags & IXAF_IS_IPV4) {
if (HOOKS4_INTERESTED_PHYSICAL_OUT(ipst) &&
!(ixaflags & IXAF_NO_PFHOOK)) {
int error;
return (error);
/* The length could have changed */
}
/*
* Note that for TX the zoneid is the sending
* zone, whether or not MLP is in play.
* Since the szone argument is the IP zoneid (i.e.,
* zero for exclusive-IP zones) and ipobs wants
* the system zoneid, we map it here.
*/
/*
* On the outbound path the destination zone will be
* unknown as we're sending this packet out on the
* wire.
*/
}
} else {
if (HOOKS6_INTERESTED_PHYSICAL_OUT(ipst) &&
!(ixaflags & IXAF_NO_PFHOOK)) {
int error;
return (error);
/* The length could have changed */
}
/* See above */
}
}
/*
* We check the state without a lock because the state can never
* move "backwards" to initial or incomplete.
*/
switch (ncec->ncec_state) {
case ND_REACHABLE:
case ND_STALE:
case ND_DELAY:
case ND_PROBE:
/*
* ip_xmit_attach_llhdr has increased
* ipIfStatsOutDiscards and called ip_drop_output()
*/
return (ENOBUFS);
}
/*
* check if nce_fastpath completed and we tagged on a
* copy of nce_fp_mp in ip_xmit_attach_llhdr().
*/
if (fp_mp &&
/*
* Send the packet directly to DLD, where it
* may be queued depending on the availability
* of transmit resources at the media layer.
* Return value should be taken into
* account and flow control the TCP.
*/
pkt_len);
if (ixaflags & IXAF_NO_DEV_FLOW_CTL) {
} else {
return (EWOULDBLOCK);
}
}
} else {
if (!(ixaflags & IXAF_NO_DEV_FLOW_CTL) &&
!canputnext(wq)) {
*ixacookie = 0;
return (EWOULDBLOCK);
}
pkt_len);
}
/*
* The rest of this function implements Neighbor Unreachability
* detection. Determine if the ncec is eligible for NUD.
*/
return (0);
/*
* Check for upper layer advice
*/
if (ixaflags & IXAF_REACH_CONF) {
/*
* It should be o.k. to check the state without
* a lock here, at most we lose an advice.
*/
ncec->ncec_timeout_id = 0;
if (ip_debug > 2) {
/* ip1dbg */
pr_addr_dbg("ip_xmit: state"
" for %s changed to"
" REACHABLE\n", AF_INET6,
}
}
return (0);
}
" ill_reachable_time = %d \n", delta,
switch (ncec->ncec_state) {
case ND_REACHABLE:
/* FALLTHROUGH */
case ND_STALE:
/*
* ND_REACHABLE is identical to
* ND_STALE in this specific case. If
* reachable time has expired for this
* neighbor (delta is greater than
* reachable time), conceptually, the
* neighbor cache is no longer in
* REACHABLE state, but already in
* STALE state. So the correct
* transition here is to ND_DELAY.
*/
if (ip_debug > 3) {
/* ip2dbg */
pr_addr_dbg("ip_xmit: state"
" for %s changed to"
" DELAY\n", AF_INET6,
}
break;
case ND_DELAY:
case ND_PROBE:
/* Timers have already started */
break;
case ND_UNREACHABLE:
/*
* nce_timer has detected that this ncec
* is unreachable and initiated deleting
* this ncec.
* This is a harmless race where we found the
* ncec before it was deleted and have
* just sent out a packet using this
* unreachable ncec.
*/
break;
default:
ASSERT(0);
}
}
return (0);
case ND_INCOMPLETE:
/*
* the state could have changed since we didn't hold the lock.
* Re-verify state under lock.
*/
if (NCE_ISREACHABLE(ncec)) {
goto sendit;
}
/* queue the packet */
return (0);
case ND_INITIAL:
/*
* State could have changed since we didn't hold the lock, so
* re-verify state.
*/
if (NCE_ISREACHABLE(ncec)) {
goto sendit;
}
/*
* figure out the source we want to use
* and resolve it.
*/
} else {
}
return (0);
case ND_UNREACHABLE:
ip_drop_output("ipIfStatsOutDiscards - ND_UNREACHABLE",
return (0);
default:
ASSERT(0);
ip_drop_output("ipIfStatsOutDiscards - ND_other",
return (ENETUNREACH);
}
}
/*
* Return B_TRUE if the buffers differ in length or content.
* This is used for comparing extension header buffers.
* Note that an extension header would be declared different
* even if all that changed was the next header value in that header i.e.
* what really changed is the next extension header.
*/
{
if (!b_valid)
blen = 0;
return (B_TRUE);
if (alen == 0)
return (B_FALSE); /* Both zero length */
}
/*
* Preallocate memory for ip_savebuf(). Returns B_TRUE if ok.
* Return B_FALSE if memory allocation fails - don't change any state!
*/
{
void *dst;
if (!src_valid)
srclen = 0;
return (B_FALSE);
} else {
}
return (B_TRUE);
}
/*
* Replace what is in *dst, *dstlen with the source.
* Assumes ip_allocbuf has already been called.
*/
void
{
if (!src_valid)
srclen = 0;
}
/*
* Free the storage pointed to by the members of an ip_pkt_t.
*/
void
{
if (fields & IPPF_HOPOPTS) {
ipp->ipp_hopoptslen = 0;
}
if (fields & IPPF_RTHDRDSTOPTS) {
ipp->ipp_rthdrdstoptslen = 0;
}
if (fields & IPPF_DSTOPTS) {
ipp->ipp_dstoptslen = 0;
}
if (fields & IPPF_RTHDR) {
ipp->ipp_rthdrlen = 0;
}
if (fields & IPPF_IPV4_OPTIONS) {
ipp->ipp_ipv4_options_len = 0;
}
if (fields & IPPF_LABEL_V4) {
ipp->ipp_label_len_v4 = 0;
}
if (fields & IPPF_LABEL_V6) {
ipp->ipp_label_len_v6 = 0;
}
}
/*
* Copy from src to dst and allocate as needed.
* Returns zero or ENOMEM.
*
* The caller must initialize dst to zero.
*/
int
{
/* Start with fields that don't require memory allocation */
return (0);
if (fields & IPPF_HOPOPTS) {
return (ENOMEM);
}
}
if (fields & IPPF_RTHDRDSTOPTS) {
kmflag);
return (ENOMEM);
}
}
if (fields & IPPF_DSTOPTS) {
return (ENOMEM);
}
}
if (fields & IPPF_RTHDR) {
return (ENOMEM);
}
src->ipp_rthdrlen);
}
if (fields & IPPF_IPV4_OPTIONS) {
kmflag);
return (ENOMEM);
}
}
if (fields & IPPF_LABEL_V4) {
return (ENOMEM);
}
}
if (fields & IPPF_LABEL_V6) {
return (ENOMEM);
}
}
if (fields & IPPF_FRAGHDR) {
return (ENOMEM);
}
}
return (0);
}
/*
* Returns INADDR_ANY if no source route
*/
{
return (INADDR_ANY);
if (totallen & 0x3)
return (INADDR_ANY);
switch (optval) {
case IPOPT_SSRR:
case IPOPT_LSRR:
break;
}
off--;
if (optlen < IP_ADDR_LEN ||
/* End of source route */
break;
}
/* Ignore */
break;
}
break;
}
}
return (nexthop);
}
/*
* Reverse a source route.
*/
void
{
return;
if (totallen & 0x3)
return;
switch (optval) {
case IPOPT_SSRR:
case IPOPT_LSRR:
break;
}
off2 -= IP_ADDR_LEN;
off1 += IP_ADDR_LEN;
}
break;
}
}
}
/*
* Returns NULL if no routing header
*/
{
return (NULL);
if (rthdr->ip6r0_segleft == 0)
return (NULL);
return (nexthop);
}
{
int ire_flags = MATCH_IRE_TYPE;
return (ALL_ZONES);
if (lookup_zoneid != ALL_ZONES)
}
return (zoneid);
}
{
int ire_flags = MATCH_IRE_TYPE;
return (ALL_ZONES);
if (IN6_IS_ADDR_LINKLOCAL(addr))
if (lookup_zoneid != ALL_ZONES)
}
return (zoneid);
}
/*
* IP obserability hook support functions.
*/
static void
{
}
static void
{
}
/*
* hook_pkt_observe_t is composed in network byte order so that the
* entire mblk_t chain handed into hook_run can be used as-is.
* The caveat is that use of the fields, such as the zone fields,
* requires conversion into host byte order first.
*/
void
{
return;
/*
* b_wptr is set to make the apparent size of the data in the mblk_t
* to exclude the pointers at the end of hook_pkt_observer_t.
*/
if (IS_UNDER_IPMP(ill))
else
grifindex = 0;
} else {
}
}
/*
* Utility routine that checks if `v4srcp' is a valid address on underlying
* interface `ill'. If `ipifp' is non-NULL, it's set to a held ipif
* associated with `v4srcp' on success. NOTE: if this is not called from
* inside the IPSQ (ill_g_lock is not held), `ill' may be removed from the
* group during or after this lookup.
*/
{
else
return (B_TRUE);
}
ip1dbg(("ipif_lookup_testaddr_v4: cannot find ipif for src %x\n",
*v4srcp));
return (B_FALSE);
}