ip.c revision fd00680555e8f4173d02435c3b015e23cb232c49
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1990 Mentat Inc. */
#pragma ident "%Z%%M% %I% %E% SMI"
#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_info.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 <sys/multidata.h>
#include <inet/ipclassifier.h>
#include <inet/udp_impl.h>
#include <rpc/pmap_prot.h>
/*
* Values for squeue switch:
* IP_SQUEUE_ENTER_NODRAIN: squeue_enter_nodrain
* IP_SQUEUE_ENTER: squeue_enter
* IP_SQUEUE_FILL: squeue_fill
*/
#define TCP6 "tcp6"
#define TCP "tcp"
#define SCTP "sctp"
#define SCTP6 "sctp6"
/*
*/
int ip_poll_normal_ms = 100;
int ip_poll_normal_ticks = 0;
int ip_modclose_ackwait_ms = 3000;
/*
* 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 {
/*
* 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
*/
/*
* 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 (no IPMP) or per IPMP group.
* This is used to serialize plumbing operations, IPMP operations, certain
*
* 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. However if the system uses IPMP, the operations are easier if
* they are serialized on a per IPMP group basis since IPMP operations
* happen across ill's of a group. Thus the lowest common denominator is to
* from drivers on a per IPMP group basis. If the system does not employ
* IPMP the serialization is 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 nor can critical parameters like
* the ipif's address or netmask change as long as an ipif is refheld
* directly or indirectly. For example an SIOCLIFADDR ioctl that changes the
* address of an ipif has to go through the ipsq_t. This ensures that only
* 1 such exclusive operation proceeds at any time on the ipif. It then
* deletes all ires associated with this ipif, and 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 nce_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 <ill-ipsq> mapping
* * The ipsq->ipsq_phyint_list threaded by phyint_ipsq_next
* * The illgroup list threaded by ill_group_next.
* * <ill-phyint> association
* of an ill into the illgrp list, changing the <ill-phyint> assoc of an ill
* will all have to hold the ill_g_lock as writer for the actual duration
* may be found in the IPMP section.
*
* - ill_lock: This is a per ill mutex.
* It protects some members of the ill and is documented below.
* It also protects the <ill-ipsq> mapping
* It also protects the illgroup list threaded by ill_group_next.
* 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 all the other members of the ipsq struct except
* ipsq_refs and ipsq_phyint_list which are protected by ill_g_lock
*
* - illgrp_lock: This is a per ill_group mutex lock.
* The only thing it protects is the illgrp_ill_schednext member of ill_group
* which dictates which is the next ill in an ill_group that is to be chosen
* for sending outgoing packets, through creation of an IRE_CACHE that
* references this ill.
*
* - 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.
*
* lists of IPsec capable ills (ipsec_capab_ills_{ah,esp}). It is taken
* as a writer when adding or deleting elements from these lists, and
* as a reader when walking these lists to send a SADB update to the
* IPsec capable ills.
*
* 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_groupname and
* ip_sioctl_flags since the 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>, <ill-ipsq>, <ill-illgroup> 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 <ill-ipsq> association the ill_g_lock must be held as writer
* and the ill_lock of the ill in question must be held.
*
* To change the <ill-illgroup> association the ill_g_lock must be held as
* writer and the ill_lock of the ill in question must be held.
*
* 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
* ill_g_lock -> illgrp_lock -> ill_lock
* ill_g_lock -> ill_lock(s) -> phyint_lock
* ill_g_lock -> ndp_g_lock -> ill_lock -> nce_lock
* ill_g_lock -> ip_addr_avail_lock
* conn_lock -> irb_lock -> ill_lock -> ire_lock
* ill_g_lock -> ip_g_nd_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.
*
* Mobile-IP scenarios
*
* irb_lock -> ill_lock -> ire_mrtun_lock
* irb_lock -> ill_lock -> ire_srcif_table_lock
*
* IPsec scenarios
*
* ipsa_lock -> ill_g_lock -> ill_lock
* ipsec_capab_ills_lock -> ill_g_lock -> ill_lock
* ipsec_capab_ills_lock -> ipsa_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
*
*
* 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.
*
* IPSEC notes :
*
* in front of the actual packet. For outbound datagrams, the M_CTL
* contains a ipsec_out_t (defined in ipsec_info.h), which has the
* information used by the IPSEC code for applying the right level of
* protection. The information initialized by IP in the ipsec_out_t
* is determined by the per-socket policy or global policy in the system.
* For inbound datagrams, the M_CTL contains a ipsec_in_t (defined in
* ipsec_info.h) which 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.
*
* If there is both per-socket policy (set using setsockopt) and there
* is also global policy match for the 5 tuples of the socket,
* ipsec_override_policy() makes the decision of which one to use.
*
* 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_bind during the ipa_conn_t bind.
* 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. On the send side, if the packet
* cannot be sent down to the driver by IP, because of a canput failure, IP
* does a putq on the conn_wq. This will cause ip_wsrv to run on the conn_wq.
* ip_wsrv in turn, inserts the conn in a list of conn's that need to be drained
* when the flowcontrol condition subsides. Ultimately STREAMS backenables the
* ip_wsrv on the IP module, which in turn does a qenable of the conn_wq of the
* first conn in the list of conn's to be drained. ip_wsrv on this conn drains
* the queued messages, and removes the conn from the drain list, if all
* messages were drained. It also qenables the next conn in the drain list to
* continue the drain process.
*
* In reality the drain list is not a single list, but a configurable number
* of lists. The ip_wsrv on the IP module, qenables the first conn in each
* list. If the ip_wsrv of the next qenabled conn does not run, because the
* stream closes, ip_close takes responsibility to qenable the next conn in
* the drain list. The directly called ip_wput path always does a putq, if
* it cannot putnext. Thus synchronization problems are handled between
* ip_wsrv and ip_close. conn_drain_insert and conn_drain_tail are the only
* functions that manipulate this drain list. Furthermore conn_drain_insert
* is called only from ip_wsrv, and there can be only 1 instance of ip_wsrv
* running on a queue at any time. conn_drain_tail can be simultaneously called
* from both ip_wsrv and ip_close.
*
* 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 ip_wput_ire and ipsec_out_process.
*
* Inbound (local_in)
* Hooks are placed in ip_proto_input, icmp_inbound, ip_fanout_proto and
* TCP and UDP fanout routines.
*
* Forwarding (in and out)
* Hooks are placed in ip_rput_forward and ip_mrtun_forward.
*
* 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.
*
* A boolean variable, ip_policy, is used in all the fanout routines that can
* invoke ip_process for a packet. This variable indicates if the packet should
* to be sent for policy processing. The variable is set to B_TRUE by default,
* i.e. when the routines are invoked in the normal ip procesing path for a
* packet. The two exceptions being ip_wput_local and icmp_inbound_error_fanout;
* ip_policy is set to B_FALSE for all the routines called in these two
* functions because, in the former case, we don't process loopback traffic
* currently while in the latter, the packets have already been processed in
* icmp_inbound.
*
* 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_CACHE Exclusive
* IRE_IF_NORESOLVER (interface routes) Exclusive
* IRE_IF_RESOLVER (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, since for all other entries
* in ire_ctable and IRE_INTERFACE, ire_src_addr is what can be used as source
* when sending packets using the IRE. For IRE_LOCAL ire_src_addr is the IP
* address of the zone itself (the destination). Since IRE_LOCAL is used
* for communication between zones, ip_wput_ire has special logic to set
* the right source address when sending using an IRE_LOCAL.
*
* Furthermore, when ip_restrict_interzone_loopback is set (the default),
* ire_cache_lookup 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 (or ill group) 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 conn_wantpacket().
*
* Applications in different zones can join the same multicast group address.
* For IPv4, group memberships are per-logical interface, so they're already
* inherently part of a zone. For IPv6, group memberships are per-physical
* interface, so we distinguish IPv6 group memberships based on group address,
* interface and zoneid. In both cases, received multicast packets are sent to
* every zone for which a group membership entry exists. On IPv6 we need to
* check that the target zone still has an address on the receiving physical
* interface; it could have been removed since the application issued the
* IPV6_JOIN_GROUP.
*/
/*
* Squeue Fanout flags:
* 0: No fanout.
* 1: Fanout across all squeues
*/
/*
* Maximum dups allowed per packet.
*/
#define IS_SIMPLE_IPH(ipha) \
/* RFC1122 Conformance */
#define IP_FORWARD_DEFAULT IP_FORWARD_NEVER
#define ILL_MAX_NAMELEN LIFNAMSIZ
ip_stack_t *);
mblk_t *, int, ip_stack_t *);
static void icmp_options_update(ipha_t *);
ip_stack_t *);
ip_stack_t *);
ip_stack_t *);
char *ip_dot_addr(ipaddr_t, char *);
static char *ip_dot_saddr(uchar_t *, char *);
zoneid_t, ip_stack_t *);
char *ip_nv_lookup(nv_t *, int);
void *dummy_arg);
ip_stack_t *);
ire_t *, ip_stack_t *);
ip_stack_t *);
uint16_t *);
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);
static void ip_trash_ire_reclaim_stack(ip_stack_t *);
zoneid_t, ip_stack_t *);
zoneid_t, ip_stack_t *);
static void conn_drain_init(ip_stack_t *);
static void conn_drain_fini(ip_stack_t *);
static void conn_walk_drain(ip_stack_t *);
zoneid_t);
zoneid_t);
void *dummy_arg);
cred_t *);
cred_t *);
cred_t *);
static squeue_func_t ip_squeue_switch(int);
static void *icmp_kstat_init(netstackid_t);
/* How long, in seconds, we allow frags to hang around. */
#define IP_FRAG_TIMEOUT 60
/*
* Threshold which determines whether MDT should be used when
* generating IP fragments; payload size must be greater than
* this threshold for MDT to take place.
*/
#define IP_WPUT_FRAG_MDT_MIN 32768
static long ip_rput_pullups;
int ip_debug;
#ifdef DEBUG
uint32_t ipsechw_debug = 0;
#endif
/*
* Multirouting/CGTP stuff
*/
/*
* XXX following really should only be in a header. Would need more
* header and .c clean up first.
*/
extern optdb_obj_t ip_opt_obj;
/*
* 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_debug"},
{ 0, 10, 0, "ip_mrtdebug"},
{ 5000, 999999999, 60000, "ip_ire_timer_interval" },
{ 60000, 999999999, 1200000, "ip_ire_arp_interval" },
{ 60000, 999999999, 60000, "ip_ire_redirect_interval" },
{ 1, 255, 255, "ip_def_ttl" },
{ 0, 1, 0, "ip_forward_src_routed"},
{ 0, 256, 32, "ip_wroff_extra" },
{ 5000, 999999999, 600000, "ip_ire_pathmtu_interval" },
{ 8, 65536, 64, "ip_icmp_return_data_bytes" },
{ 0, 1, 1, "ip_path_mtu_discovery" },
{ 0, 240, 30, "ip_ignore_delete_time" },
{ 0, 1, 0, "ip_ignore_redirect" },
{ 0, 1, 1, "ip_output_queue" },
{ 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" },
{ 1, 8, 3, "ip_ire_reclaim_fraction" },
{ 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" },
{ 1000, 60000, 1000, "ip_multirt_resolution_interval" },
{ 0, 255, 1, "ip_multirt_ttl" },
{ 0, 1, 1, "ip_multidata_outbound" },
{ 0, 3600000, 300000, "ip_ndp_defense_interval" },
{ 0, 999999, 60*60*24, "ip_max_temp_idle" },
{ 0, 1000, 1, "ip_max_temp_defend" },
{ 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
};
/*
* 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" },
"ip_ill_status" },
"ip_ipif_status" },
"ipv4_ire_status" },
"ipv4_mrtun_ire_status" },
"ipv4_srcif_ire_status" },
"ipv6_ire_status" },
"ip_conn_status" },
"ip_rput_pullups" },
"ip_ndp_cache_report" },
"ip_srcid_status" },
#define IPNDP_CGTP_FILTER_OFFSET 16
"ip_cgtp_filter" },
#define IPNDP_IPMP_HOOK_OFFSET 18
"ipmp_hook_emulation" },
};
/*
* 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
LIF_CMD, ip_sioctl_get_lifindex, 0 },
LIF_CMD, ip_sioctl_slifindex, 0 },
/* 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 },
};
{ OSIOCGTUNPARAM, sizeof (struct old_iftun_req),
};
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_CACHE, "CACHE" },
{ IRE_DEFAULT, "DEFAULT" },
{ IRE_PREFIX, "PREFIX" },
{ IRE_IF_NORESOLVER, "IF_NORESOL" },
{ IRE_IF_RESOLVER, "IF_RESOLV" },
{ IRE_HOST, "HOST" },
{ 0 }
};
/* Defined in ip_netinfo.c */
extern ddi_taskq_t *eventq_queue_nic;
/* 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.
*/
};
};
};
};
};
#ifdef DEBUG
#endif
/*
* Prepend the zoneid using an ipsec_out_t for later use by functions like
* ip_rput_v6(), ip_output(), etc. If the message
* block already has a M_CTL at the front of it, then simply set the zoneid
* appropriately.
*/
mblk_t *
{
return (mp);
}
return (NULL);
/* This is not a secure packet */
return (first_mp);
}
/*
* Copy an M_CTL-tagged message, preserving reference counts appropriately.
*/
mblk_t *
{
/*
* Note that M_CTL is also used for delivering ICMP error messages
* upstream to transport layers.
*/
} else {
}
}
/* Generate an ICMP fragmentation needed message. */
static void
{
if (mctl_present)
return;
}
ipst);
}
/*
* icmp_inbound deals with ICMP messages in the following ways.
*
* 1) It needs to send a reply back and possibly delivering it
* to the "interested" upper clients.
* 2) It needs to send it to the upper clients only.
* 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.
*
* We need to accomodate icmp messages coming in clear until we get
* everything secure from the wire. If icmp_accept_clear_messages
* is zero we check with the global policy and act accordingly. If
* it is non-zero, we accept the message without any checks. But
* *this does not mean* that this will be delivered to the upper
* clients. By accepting we might send replies back, change our MTU
* dispositions.
*
* We handle the above 4 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 ire_max_frag, 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 ire_max_frag 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.
*
* IPQoS Notes:
* The only instance when a packet is sent for processing is when there
* isn't an ICMP client and if we are interested in it.
* If there is a client, IPPF processing will take place in the
* ip_fanout_proto routine.
*
* Zones notes:
* The packet is only processed in the context of the specified zone: typically
* only this zone will reply to an echo request, and only interested clients in
* this zone will receive a copy of the packet. This means that the caller must
* call icmp_inbound() for each relevant zone.
*/
static void
{
int iph_hdr_length;
int hdr_length;
ipsec_in_t *ii;
if (mctl_present) {
}
if (ipst->ips_icmp_accept_clear_messages == 0) {
return;
}
/*
* On a labeled system, we have to check whether the zone itself is
* permitted to receive raw traffic.
*/
if (is_system_labeled()) {
ip1dbg(("icmp_inbound: zone %d can't receive raw",
zoneid));
return;
}
}
/*
* We have accepted the ICMP message. It means that we will
* respond to the packet if needed. It may not be delivered
* to the upper client depending on the policy constraints
* and the disposition in ipsec_inbound_accept_clear.
*/
/* Last chance to get real. */
return;
}
/* Refresh iph following the pullup. */
}
/* ICMP header checksum, including checksum field, should be zero. */
return;
}
/* The IP header will always be a multiple of four bytes */
icmph->icmph_code));
/* We will set "interested" to "true" if we want a copy */
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.
*/
/* unicast: always respond */
interested = B_TRUE;
/* multicast: respond based on tunable */
} else if (broadcast) {
/* broadcast: respond based on tunable */
}
break;
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 &&
/* So is whether to respond if it was an IP broadcast. */
return;
}
/* Refresh ipha following the pullup. */
}
interested = B_TRUE;
}
break;
case ICMP_TIME_STAMP_REPLY:
break;
case ICMP_INFO_REQUEST:
/* Per RFC 1122 3.2.2.7, ignore this. */
case ICMP_INFO_REPLY:
break;
!broadcast) &&
/* TODO m_pullup of complete header? */
interested = B_TRUE;
break;
case ICMP_ADDRESS_MASK_REPLY:
break;
default:
break;
}
/* See if there is an ICMP client. */
/* If there is an ICMP client and we want one too, copy it. */
if (!interested) {
return;
}
}
} else if (!interested) {
return;
} else {
/*
* Initiate policy processing for this packet if ip_policy
* is true.
*/
if (mctl_present) {
}
return;
}
}
}
/* We want to do something with it. */
/* Check db_ref to make sure we can modify the packet. */
if (!first_mp1) {
return;
}
if (mctl_present) {
} else {
}
}
switch (icmph->icmph_type) {
return;
}
/*
* outging interface must be IPv4
*/
break;
case ICMP_ECHO_REQUEST:
break;
case ICMP_TIME_STAMP_REQUEST: {
tsp++; /* Skip past 'originate time' */
/* Compute # of milliseconds since midnight */
gethrestime(&now);
break;
}
default:
return;
}
}
return;
}
if (hdr_length < sizeof (ipha_t)) {
return;
}
return;
}
}
switch (icmph->icmph_type) {
case ICMP_REDIRECT:
/*
* As there is no upper client to deliver, we don't
* need the first_mp any more.
*/
if (mctl_present) {
}
return;
case ICMP_DEST_UNREACHABLE:
return;
}
/*
* icmp_inbound_too_big() may alter mp.
* Resynch ipha and icmph accordingly.
*/
}
/* FALLTHRU */
default :
/*
* IPQoS notes: Since we have already done IPQoS
* processing we don't want to do it again in
* the fanout routines called by
* icmp_inbound_error_fanout, hence the last
* argument, ip_policy, is B_FALSE.
*/
}
return;
}
/* Send out an ICMP packet */
icmph->icmph_checksum = 0;
/*
* Make it look like it was directed to us, so we don't look
* like a fool with a broadcast or multicast source address.
*/
/*
* Make sure that we haven't grabbed an interface that's DOWN.
*/
if (ipif_chosen != NULL) {
ipif = ipif_chosen;
}
}
ip0dbg(("icmp_inbound: "
"\tsrc 0x%x dst 0x%x ill %p "
"ipif_lcl_addr 0x%x\n",
(void *)ill,
return;
}
}
/* Reset time to live. */
{
/* Swap source and destination addresses */
}
ipha->ipha_ident = 0;
if (!IS_SIMPLE_IPH(ipha))
/*
* ICMP echo replies should go out on the same interface
* the request came on as probes used by in.mpathd for detecting
* NIC failures are ECHO packets. We turn-off load spreading
* by setting ipsec_in_attach_if to B_TRUE, which is copied
* to ipsec_out_attach_if by ipsec_in_to_out called later in this
* function. This is in turn handled by ip_wput and ip_newroute
* to make sure that the packet goes out on the interface it came
* in on. If we don't turnoff load spreading, the packets might get
* dropped if there are no non-FAILED/INACTIVE interfaces for it
* to go out and in.mpathd would wrongly detect a failure or
* mis-detect a NIC failure for link failure. As load spreading
* can happen only if ill_group is not NULL, we do only for
* that case and this does not affect the normal case.
*
* We turn off load spreading only on echo packets that came from
* on-link hosts. If the interface route has been deleted, this will
* not be enforced as we can't do much. For off-link hosts, as the
* default routes in IPv4 does not typically have an ire_ipif
* pointer, we can't force MATCH_IRE_ILL in ip_wput/ip_newroute.
* Moreover, expecting a default route through this interface may
* not be correct. We use ipha_dst because of the swap above.
*/
/*
* First, we need to make sure that it is not one of our
* local addresses. If we set onlink when it is one of
* our local addresses, we will end up creating IRE_CACHES
* for one of our local addresses. Then, we will never
* accept packets for them afterwards.
*/
return;
}
}
} else {
}
}
if (!mctl_present) {
/*
* This packet should go out the same way as it
* came in i.e in clear. To make sure that global
* policy will not be applied to this in ip_wput_ire,
* we attach a IPSEC_IN mp and clear ipsec_in_secure.
*/
return;
}
/* This is not a secure packet */
if (onlink) {
}
} else if (onlink) {
} else {
}
return;
}
}
static ipaddr_t
{
switch (ipha->ipha_protocol) {
case IPPROTO_TCP:
{
/* do a reverse lookup */
TCPS_LISTEN, ipst);
break;
}
case IPPROTO_UDP:
{
/* Extract ports in net byte order */
/* do a reverse lookup */
}
break;
}
case IPPROTO_SCTP:
{
} else {
}
break;
}
default:
{
if (IPCL_PROTO_MATCH(connp,
0, zoneid)) {
break;
}
}
}
}
if (connp->conn_nexthop_set)
}
return (nexthop_addr);
}
/* 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.
* After updating any IRE it does the fanout to any matching transport streams.
* Assumes the message has been pulled up till the IP header that caused
* the error.
*
* Returns B_FALSE on failure and B_TRUE on success.
*/
static boolean_t
{
int mtu;
int hdr_length;
/* Drop if the original packet contained a source route */
if (ip_source_route_included(ipha)) {
return (B_FALSE);
}
/*
* Verify we have atleast ICMP_MIN_TP_HDR_LENGTH bytes of transport
* header.
*/
ip1dbg(("icmp_inbound_too_big: insufficient hdr\n"));
return (B_FALSE);
}
}
if (nexthop_addr != INADDR_ANY) {
/* nexthop set */
} else {
/* nexthop not set */
}
if (!first_ire) {
ip1dbg(("icmp_inbound_too_big: no route for 0x%x\n",
return (B_FALSE);
}
/* Check for MTU discovery advice as described in RFC 1191 */
/*
* Look for the connection to which this ICMP message is
* directed. If it has the IP_NEXTHOP option set, then the
* search is limited to IREs with the MATCH_IRE_PRIVATE
* option. Else the search is limited to regular IREs.
*/
(nexthop_addr != INADDR_ANY)))
continue;
/* Reduce the IRE max frag value as advised. */
ip1dbg(("Received mtu from router: %d (was %d)\n",
} 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 iph_length in ICMP
* errors.
*/
ip1dbg(("Wrong mtu: sent %d, ire %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 68! */
ip1dbg(("Too big for packet size %d\n",
length));
ire->ire_frag_flag = 0;
} else {
mtu = icmp_frag_size_table[i];
ip1dbg(("Calculated mtu %d, packet size %d, "
ire->ire_max_frag));
}
/* Record the new max frag size for the ULP. */
icmph->icmph_du_zero = 0;
}
}
return (B_TRUE);
}
/*
* If the packet in error is Self-Encapsulated, icmp_inbound_error_fanout
* calls this function.
*/
static mblk_t *
{
int length;
/*
* For Self-encapsulated packets, we added an extra IP header
* without the options. Inner IP header is the one from which
* the outer IP header was formed. Thus, we need to remove the
* outer IP header. To do this, we pullup the whole message
* and overlay whatever follows the outer IP header over the
* outer IP header.
*/
return (NULL);
/*
* The length that we want to overlay is following the inner
* IP header. Subtracting the IP header + icmp header + outer
* IP header's length should give us the length that we want to
* overlay.
*/
/*
* Overlay whatever follows the inner header over the
* outer header.
*/
/* Set the wptr to account for the outer header */
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.
*
* We handle ICMP_FRAGMENTATION_NEEDED(IFN) message differently
* in the context of IPSEC. Normally we tell the upper layer
* whenever we send the ire (including ip_bind), the IPSEC header
* length in ire_ipsec_overhead. TCP can deduce the MSS as it
* has both the MTU (ire_max_frag) and the ire_ipsec_overhead.
* Similarly, we pass the new MTU icmph_du_mtu and TCP does the
* same thing. As TCP has the IPSEC options size that needs to be
* adjusted, we just pass the MTU unchanged.
*
* IFN could have been generated locally or by some router.
*
* LOCAL : *ip_wput_ire -> icmp_frag_needed could have generated this.
* 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, ip_wput_ire
* generates the IFN, where IPSEC processing has *not* been
* done.
*
* *ip_wput_ire_fragmentit -> ip_wput_frag -> icmp_frag_needed
* could have generated this. This happens because ire_max_frag
* value in IP was set to a new value, while the IPSEC processing
* was being done and after we made the fragmentation check in
* ip_wput_ire. Thus on return from IPSEC processing,
* ip_wput_ipsec_out finds that the new length is > ire_max_frag
* and generates the IFN. As IPSEC processing is over, we fanout
*
* In both these cases, ipsec_in_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.
*/
static void
{
ipsec_in_t *ii;
if (mctl_present) {
} else {
}
switch (ipha->ipha_protocol) {
case IPPROTO_UDP:
/*
* Verify we have at least ICMP_MIN_TP_HDR_LEN bytes of
* transport header.
*/
goto discard_pkt;
}
}
/*
* Attempt to find a client stream based on port.
* Note that we do a reverse lookup since the header is
* in the form we sent it out.
* The ripha header is only used for the IP_UDP_MATCH and we
* only set the src and dst addresses and protocol.
*/
ip2dbg(("icmp_inbound_error: UDP %x:%d to %x:%d: %d/%d\n",
/* Have to change db_type after any pullupmsg */
return;
case IPPROTO_TCP:
/*
* Verify we have at least ICMP_MIN_TP_HDR_LEN bytes of
* transport header.
*/
goto discard_pkt;
}
}
/*
* 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;
/* Have to change db_type after any pullupmsg */
return;
case IPPROTO_SCTP:
/*
* Verify we have at least ICMP_MIN_TP_HDR_LEN bytes of
* transport header.
*/
goto discard_pkt;
}
}
/*
* Find a SCTP client stream for this packet.
* Note that we do a reverse lookup since the header is
* in the form we sent it out.
* The ripha header is only used for the matching and we
* only set the src and dst addresses, protocol, and version.
*/
/* Have to change db_type after any pullupmsg */
return;
case IPPROTO_ESP:
case IPPROTO_AH: {
int ipsec_rc;
/*
* We will re-use the IPSEC_IN if it is already present as
* ICMP errors. If there is no IPSEC_IN, allocate a new
* one and attach it in the front.
*/
/*
* ip_fanout_proto_again converts the ICMP errors
* this function, it would work. Convert it back
* to M_CTL before we send up as this is a ICMP
* error. This could have been generated locally or
* by some router. Validate the inner IPSEC
* headers.
*
* NOTE : ill_index is used by ip_fanout_proto_again
* to locate the ill.
*/
} else {
/*
* IPSEC_IN is not present. We attach a ipsec_in
* message and send up to IPSEC for validating
* and removing the IPSEC headers. Clear
* ipsec_in_secure so that when we return
* from IPSEC, we don't mistakenly think that this
* is a secure packet came from the network.
*
* NOTE : ill_index is used by ip_fanout_proto_again
* to locate the ill.
*/
return;
}
/* This is not a secure packet */
}
ip2dbg(("icmp_inbound_error: ipsec\n"));
if (!ipsec_loaded(ipss)) {
return;
}
else
if (ipsec_rc == IPSEC_STATUS_FAILED)
return;
return;
}
default:
/*
* The ripha header is only used for the lookup and we
* only set the src and dst addresses and protocol.
*/
ip2dbg(("icmp_inbound_error: proto %d %x to %x: %d/%d\n",
hdr_length + sizeof (ipha_t) -
goto discard_pkt;
}
}
/*
* 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 */
goto discard_pkt;
/*
* 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;
}
}
ii->ipsec_in_loopback &&
ii->ipsec_in_secure) {
/*
* For IP tunnels that get a looped-back
* ICMP_FRAGMENTATION_NEEDED message, adjust the
* reported new MTU to take into account the IPsec
* headers protecting this configured tunnel.
*
* This allows the tunnel module (tun.c) to blindly
* accept the MTU reported in an ICMP "too big"
* message.
*
* Non-looped back ICMP messages will just be
* handled by the security protocols (if needed),
* and the first subsequent packet will hit this
* path.
*/
}
/* Have to change db_type after any pullupmsg */
return;
}
/* NOTREACHED */
drop_pkt:;
ip1dbg(("icmp_inbound_error_fanout: drop pkt\n"));
}
/*
* 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));
}
/*
* 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.
*/
int
{
len += IP_ADDR_LEN;
/*
* OK to cast away const here, as we don't store through the returned
* opts.ipoptp_cur pointer.
*/
int off;
switch (optval) {
case IPOPT_SSRR:
case IPOPT_LSRR:
/*
* Insert ipha_dst 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 */
off -= IP_ADDR_LEN;
while (off > 0) {
off -= IP_ADDR_LEN;
}
/* ipha_dst into first slot */
break;
case IPOPT_COMSEC:
case IPOPT_SECURITY:
/* if passing up a label is not ok, then remove */
if (is_system_labeled())
break;
/* FALLTHROUGH */
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.
*/
static void
{
int iph_hdr_length;
int error;
sizeof (icmph_t) + IP_SIMPLE_HDR_LENGTH) {
return;
}
/* 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.)
*/
/*
* Check that
* the redirect was not from ourselves
* the new gateway and the old gateway are directly reachable
*/
if (!prev_ire ||
!ire ||
return;
}
/*
* Should we use the old ULP info to create the new gateway? From
* a user's perspective, we should inherit the info so that it
* is a "smooth" transition. If we do not do that, then new
* connections going thru the new gateway will have no route metrics,
* which is counter-intuitive to user. From a network point of
* view, this may or may not make sense even though the new gateway
* is still directly connected to us so the route metrics should not
* change much.
*
* But if the old ire_uinfo is not initialized, we do another
* recursive lookup on the dest using the new gateway. There may
* be a route to that. If so, use it to initialize the redirect
* route.
*/
} else {
ipst);
/*
* If sire != NULL, ire_ftable_lookup() should not
* return a NULL value.
*/
sizeof (iulp_t));
}
}
/*
* 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, /* no in_srcaddr */
NULL, /* Fast Path header */
NULL, /* no rfq */
NULL, /* no stq */
NULL,
NULL,
NULL,
0,
0,
0,
&ulp_info,
NULL,
NULL,
ipst);
return;
}
if (error == 0) {
/* 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.
*/
static void
{
if (mctl_present)
return;
}
ipst);
}
/*
* 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 pick a source based
* on a route lookup back to ipha_src.
* Note that ipha_src must be set here since the
* packet is likely to arrive on an ill queue in ip_wput() which will
* not set a source address.
*/
static void
{
if (mctl_present) {
/*
* If it is :
*
* 1) a IPSEC_OUT, then this is caused by outbound
* datagram originating on this host. IPSEC processing
* may or may not have been done. Refer to comments above
* icmp_inbound_error_fanout for details.
*
* 2) a IPSEC_IN if we are generating a icmp_message
* for an incoming datagram destined for us i.e called
* from ip_fanout_send_icmp.
*/
/*
* Convert the IPSEC_IN to IPSEC_OUT.
*/
return;
}
} else {
if (io->ipsec_out_xmit_if)
xmit_if_on = B_TRUE;
/*
* Clear out ipsec_out_proc_begin, so we do a fresh
* ire lookup.
*/
}
} else {
/*
* This is in clear. The icmp message we are building
* here should go out in clear.
*
* Pardon the convolution of it all, but it's easier to
* allocate a "use cleartext" IPSEC_IN message and convert
* it than it is to allocate a new one.
*/
ipsec_in_t *ii;
return;
}
/* This is not a secure packet */
/*
* For trusted extensions using a shared IP address we can
* send using any zoneid.
*/
else
/*
* Convert the IPSEC_IN to IPSEC_OUT.
*/
return;
}
}
/* Remember our eventual destination */
} else if (!xmit_if_on) {
ipst);
return;
}
} else {
/*
* This must be an ICMP error coming from
* ip_mrtun_forward(). The src addr should
* be equal to the IP-addr of the outgoing
* interface.
*/
/* This is not a IPSEC_OUT type control msg */
return;
}
}
return;
}
}
/*
* Check if we can send back more then 8 bytes in addition
* to the IP header. We will include as much as 64 bytes.
*/
}
if (msg_len > len_needed) {
}
return;
}
/*
* On an unlabeled system, dblks don't necessarily have creds.
*/
/*
* Set ipsec_out_icmp_loopback 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 ipsec_out_icmp_loopback).
*/
if (msg_len > IP_MAXPACKET) {
}
icmph->icmph_checksum = 0;
}
/*
* 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);
}
/*
* Generate an ICMP redirect message.
*/
static void
{
/*
* We are called from ip_rput where we could
* not have attached an IPSEC_IN.
*/
return;
}
/* Redirects sent by router, and router is global zone */
}
/*
* Generate an ICMP time exceeded message.
*/
void
{
if (mctl_present)
return;
}
ipst);
}
/*
* Generate an ICMP unreachable message.
*/
void
{
if (mctl_present)
return;
}
}
/*
* Attempt to start recovery of an IPv4 interface that's been shut down as a
* duplicate. As long as someone else holds the address, the interface will
* stay down. When that conflict goes away, the interface is brought back up.
* This is done so that accidental shutdowns of addresses aren't made
* permanent. Your server will recover from a failure.
*
* For DHCP, recovery is not done in the kernel. Instead, it's handled by a
* user space process (dhcpagent).
*
* Recovery completes if ARP reports that the address is now ours (via
* AR_CN_READY). In that case, we go to ip_arp_excl to finish the operation.
*
* This function is entered on a timer expiry; the ID is in ipif_recovery_id.
*/
static void
ipif_dup_recovery(void *arg)
{
ipif->ipif_recovery_id = 0;
/*
* No lock needed for moving or condemned check, as this is just an
* optimization.
*/
/* No reason to try to bring this address back. */
return;
}
goto alloc_fail;
goto alloc_fail;
}
/* Setting the 'unverified' flag restarts DAD */
return;
/*
* On allocation failure, just restart the timer. Note that the ipif
* is down here, so no other thread could be trying to start a recovery
* timer. The ill_lock protects the condemned flag and the recovery
* timer ID.
*/
}
}
/*
* This is for exclusive changes due to ARP. Either tear down an interface due
* to AR_CN_FAILED and AR_CN_BOGON, or bring one up for successful recovery.
*/
/* ARGSUSED */
static void
{
char hbuf[MAC_STR_LEN];
char sbuf[INET_ADDRSTRLEN];
const char *failtype;
case AR_CN_READY:
break;
case AR_CN_FAILED:
failtype = "in use";
break;
default:
failtype = "claimed";
break;
}
/* Handle failures due to probes */
if (src == 0) {
}
sizeof (hbuf));
continue;
}
/*
* If we failed on a recovery probe, then restart the timer to
* try again later.
*/
ipst->ips_ip_dup_recovery > 0 &&
ipif->ipif_recovery_id == 0) {
continue;
}
/*
* If what we're trying to do has already been done, then do
* nothing.
*/
continue;
}
ibuf);
} else {
}
if (bring_up) {
/*
* Free up the ARP delete message so we can allocate
* a fresh one through the normal path.
*/
EINPROGRESS) {
(void) ipif_up_done(ipif);
}
continue;
}
/*
* Already exclusive on the ill; no need to handle deferred
* processing here.
*/
ipst->ips_ip_dup_recovery > 0) {
}
}
}
/* ARGSUSED */
static void
{
}
}
/*
* News from ARP. ARP sends notification of interesting events down
* to its clients using M_CTL messages with the interesting ARP packet
* attached via b_cont.
* The interesting event from a device comes up the corresponding ARP-IP-DEV
* queue as opposed to ARP sending the message to all the clients, i.e. all
* its ARP-IP-DEV instances. Thus, for AR_CN_ANNOUNCE, we must walk the cache
* table if a cache IRE is found to delete all the entries for the address in
* the packet.
*/
static void
{
char hbuf[MAC_STR_LEN];
char sbuf[INET_ADDRSTRLEN];
if (CONN_Q(q)) {
} else {
}
if (q->q_next) {
} else
return;
}
/* Is it one we are interested in? */
} else {
return;
}
case AR_CN_BOGON:
/*
* Someone is sending ARP packets with a source protocol
* address that we have published and for which we believe our
* entry is authoritative and (when ill_arp_extend is set)
* verified to be unique on the network.
*
* The ARP module internally handles the cases where the sender
* is just probing (for DAD) and where the hardware address of
* a non-authoritative entry has changed. Thus, these are the
* real conflicts, and we have to do resolution.
*
* We back away quickly from the address if it's from DHCP or
* otherwise temporary and hasn't been used recently (or at
* all). We'd like to include "deprecated" addresses here as
* well (as there's no real reason to defend something we're
* discarding), but IPMP "reuses" this flag to mean something
* other than the standard meaning.
*
* If the ARP module above is not extended (meaning that it
* doesn't know how to defend the address), then we just log
* the problem as we always did and continue on. It's not
* right, but there's little else we can do, and those old ATM
* users are going away anyway.
*/
if (isv6) {
ipst);
} else {
}
/*
* First, figure out if this address hasn't been used
* in a while. If it hasn't, then it's a better
* candidate for abandoning.
*/
now = gethrestime_sec();
else
/*
* Now figure out how many times we've defended
* ourselves. Ignore defenses that happened long in
* the past.
*/
}
ire->ire_defense_count++;
/*
* If we've defended ourselves too many times already,
* then give up and tear down the interface(s) using
* this address. Otherwise, defend by sending out a
* gratuitous ARP.
*/
} else {
"node %s is using our IP address %s on %s",
/*
* If this is an old (ATM) ARP module, then
* don't try to defend the address. Remain
* compatible with the old behavior. Defend
* only with new ARP.
*/
if (ill->ill_arp_extend) {
} else {
}
}
return;
}
"proxy ARP problem? Node '%s' is using %s on %s",
break;
case AR_CN_ANNOUNCE:
if (isv6) {
/*
* For XRESOLV interfaces.
* Delete the IRE cache entry and NCE for this
* v6 address
*/
/*
* If v6src is a non-zero, it's a router address
* as below. Do the same sort of thing to clean
* out off-net IRE_CACHE entries that go through
* the router.
*/
if (!IN6_IS_ADDR_UNSPECIFIED(&v6src)) {
}
} else {
/*
* ARP gives us a copy of any packet where it thinks
* the address has changed, so that we can update our
* caches. We're responsible for caching known answers
* in the current design. We check whether the
* hardware address really has changed in all of our
* entries that have cached this mapping, and if so, we
* blow them away. This way we will immediately pick
* up the rare case of a host changing hardware
* address.
*/
if (src == 0)
break;
}
break;
case AR_CN_READY:
/* No external v6 resolver has a contract to use this */
if (isv6)
break;
/* If the link is down, we'll retry this later */
break;
/*
* If this is a duplicate recovery, then we now need to
* go exclusive to bring this thing back up.
*/
return;
}
/*
* If this is the first notice that this address is
* ready, then let the user know now.
*/
!ipif->ipif_addr_ready) {
}
}
ire->ire_defense_count = 0;
}
break;
case AR_CN_FAILED:
/* No external v6 resolver has a contract to use this */
if (isv6)
break;
B_FALSE);
return;
}
}
/*
* address. This mblk is tagged as an M_CTL and is sent to ULP. This is used
* application.
*/
mblk_t *
{
struct ether_header *pether;
ip1dbg(("ip_add_info: allocation failure.\n"));
return (data_mp);
}
if (flags & IPF_RECVADDR) {
/*
* Only valid for V4
*/
(IPV4_VERSION << 4));
/*
* Since a decision has already been made to deliver the
* packet, there is no need to test for SECATTR and
* ZONEONLY.
*/
/*
* packet must have come on a different
* interface.
* Since a decision has already been made to
* deliver the packet, there is no need to test
* for SECATTR and ZONEONLY.
*/
}
/*
* This is either a multicast packet or
* the address has been removed since
* the packet was received.
* Return INADDR_ANY so that normal source
* selection occurs for the response.
*/
} else {
}
} else {
}
}
- sizeof (struct ether_header));
/*
* Make sure the interface is an ethernet type, since this option
* is currently supported only on this type of interface. Also make
* sure we are pointing correctly above db_base.
*/
if ((flags & IPF_RECVSLLA) &&
} else {
/*
* Clear the bit. Indicate to upper layer that IP is not
* sending this ancillary info.
*/
}
return (mp);
}
/*
* Latch in the IPsec state for a stream based on the ipsec_in_t passed in as
* part of the bind request.
*/
{
ipsec_in_t *ii;
return (B_FALSE);
}
}
return (B_TRUE);
}
/*
* Upper level protocols (ULP) pass through bind requests to IP for inspection
* and to arrange for power-fanout assist. The ULP is identified by
* adding a single byte at the end of the original bind message.
* A ULP other than UDP or TCP that wishes to be recognized passes
* down a bind with a zero length address.
*
* The binding works as follows:
* - A zero byte address means just bind to the protocol.
* - A four byte address is treated as a request to validate
* that the address is a valid local address, appropriate for
* an application to bind to. This does not affect any fanout
* information in IP.
* - A sizeof sin_t byte address is used to bind to only the local address
* and port.
* - A sizeof ipa_conn_t byte address contains complete fanout information
* consisting of local and remote addresses and ports. In
* this case, the addresses are both validated as appropriate
* for this operation, and, if so, the information is retained
* for use in the inbound fanout.
*
* The ULP (except in the zero-length bind) can append an
* additional mblk of db_type IRE_DB_REQ_TYPE or IPSEC_POLICY_SET to the
* T_BIND_REQ/O_T_BIND_REQ. IRE_DB_REQ_TYPE indicates that the ULP wants
* a copy of the source or destination IRE (source for local bind;
* destination for complete bind). IPSEC_POLICY_SET indicates that the
* policy information contained should be copied on to the conn.
*
* NOTE : Only one of IRE_DB_REQ_TYPE or IPSEC_POLICY_SET can be present.
*/
mblk_t *
{
struct T_bind_req *tbr;
ipa_conn_t *ac;
int error = 0;
int protocol;
"ip_bind: bogus msg, len %ld", len);
/* XXX: Need to return something better */
goto bad_addr;
}
/* Back up and extract the protocol identifier. */
/* Reset the message type in preparation for shipping it back. */
/*
* Check for a zero length address. This is from a protocol that
* wants to register to receive all packets of its type.
*/
if (tbr->ADDR_length == 0) {
/*
* These protocols are now intercepted in ip_bind_v6().
* Reject protocol-level binds here for now.
*
* For SCTP raw socket, ICMP sends down a bind with sin_t
* so that the protocol type cannot be SCTP.
*/
goto bad_addr;
}
/*
*
* The udp module never sends down a zero-length address,
* and allowing this on a labeled system will break MLP
* functionality.
*/
goto bad_addr;
if (connp->conn_mac_exempt)
goto bad_addr;
/* No hash here really. The table is big enough. */
return (mp);
}
/* Extract the address pointer from the message. */
tbr->ADDR_length);
ip1dbg(("ip_bind: no address\n"));
goto bad_addr;
}
ip1dbg(("ip_bind: unaligned address\n"));
goto bad_addr;
}
/*
* Check for trailing mps.
*/
switch (tbr->ADDR_length) {
default:
ip1dbg(("ip_bind: bad address length %d\n",
(int)tbr->ADDR_length));
goto bad_addr;
case IP_ADDR_LEN:
/* Verification of local address only */
break;
case sizeof (sin_t):
break;
case sizeof (ipa_conn_t):
/* For raw socket, the local port is not set. */
/* Always verify destination reachability. */
break;
case sizeof (ipa_conn_x_t):
/*
* Whether or not to verify destination reachability depends
* on the setting of the ACX_VERIFY_DST flag in acx->acx_flags.
*/
break;
}
if (error == EINPROGRESS)
return (NULL);
else if (error != 0)
goto bad_addr;
/*
* Pass the IPSEC headers size in ire_ipsec_overhead.
* We can't do this in ip_bind_insert_ire because the policy
* may not have been inherited at that point in time and hence
* conn_out_enforce_policy may not be set.
*/
}
/* Send it home. */
return (mp);
/*
* If error = -1 then we generate a TBADADDR - otherwise error is
* a unix errno.
*/
if (error > 0)
else
return (mp);
}
/*
* Here address is verified to be a valid local address.
* address is also considered a valid local address.
* upper protocol is expected to reset the src address
* to 0 if it sees a IRE_BROADCAST type returned so that
* source address (that violates hosts requirements RFC1122)
* 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.
*
* On error, return -1 for TBADADDR otherwise pass the
* errno with TSYSERR reply.
*
* 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.
*
* Note: lport is in network byte order.
*/
int
{
int error = 0;
if (ipsec_policy_set) {
}
/*
* If it was previously connected, conn_fully_bound would have
* been set.
*/
if (src_addr) {
/*
* If an address other than 0.0.0.0 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.
*/
/* LINTED - statement has no consequent */
if (IRE_IS_LOCAL(src_ire)) {
/*
* (2) Bind to address of local UP interface
*/
/*
* (4) Bind to broadcast address
* Note: permitted only from transports that
* request IRE
*/
if (!ire_requested)
} 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)
* We put the protocol byte back into the mblk
* since we may come back via ip_wput_nondata()
* later with this mblk if ipif_lookup_addr chooses
* to defer processing.
*/
} else if (error == EINPROGRESS) {
return (EINPROGRESS);
error = 0;
/*
* (5) bind to multicast address.
* Fake out the IRE returned to upper
* layer to be a broadcast IRE.
*/
ipst);
} else {
/*
* Not a valid address for bind
*/
}
/*
* Just to keep it consistent with the processing in
* ip_bind_v4()
*/
}
if (error) {
/* Red Alert! Attempting to be a bogon! */
ip1dbg(("ip_bind: bad src address 0x%x\n",
goto bad_addr;
}
}
/*
* Allow setting new policies. For example, disconnects come
* down as ipa_t bind. 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 not fanout_insert this was just an address verification
*/
if (fanout_insert) {
/*
* The addresses have been verified. Time to insert in
* the correct fanout list.
*/
connp->conn_fport = 0;
/*
* Do we need to add a check to reject Multicast packets
*
* We need to make sure that the conn_recv is set to a non-null
* value before we insert the conn into the classifier table.
* This is to avoid a race with an incoming packet which does an
* ipcl_classify().
*/
}
if (error == 0) {
if (ire_requested) {
error = -1;
/* Falls through to bad_addr */
}
} else if (ipsec_policy_set) {
error = -1;
/* Falls through to bad_addr */
}
}
}
if (error != 0) {
if (connp->conn_anon_port) {
B_FALSE);
}
}
if (ipsec_policy_set) {
/*
* As of now assume that nothing else accompanies
* IPSEC_POLICY_SET.
*/
}
return (error);
}
/*
* Verify that both the source and destination addresses
* are valid. If verify_dst is false, 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.
* Note that we allow connect to broadcast and multicast
* addresses when ire_requested is set. Thus the ULP
* has to check for IRE_BROADCAST and multicast.
*
* Returns zero if ok.
* On error: returns -1 to mean TBADADDR otherwise returns an errno
* (for use with TSYSERR reply).
*
* Note: lport and fport are in network byte order.
*/
int
{
int error = 0;
int protocol;
/*
* If we never got a disconnect before, clear it now.
*/
if (ipsec_policy_set) {
}
/* Pick up an IRE_BROADCAST */
} else {
/*
* If conn_dontroute is set or if conn_nexthop_set is set,
* and onlink ipif is not found set ENETUNREACH error.
*/
error = ENETUNREACH;
goto bad_addr;
}
}
if (connp->conn_nexthop_set) {
} else {
}
}
/*
* dst_ire can't be a broadcast when not ire_requested.
* We also prevent ire's with src address INADDR_ANY to
* be used, which are created temporarily for
* sending out packets from endpoints that have
* conn_unspec_src set. If verify_dst is true, the destination must be
* reachable. If verify_dst is false, 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.
*/
if (ip_debug > 2) {
pr_addr_dbg("ip_bind_connected: bad connected "
}
error = ENETUNREACH;
else
goto bad_addr;
}
}
/*
* We now know that routing will allow us to reach the destination.
* Check whether Trusted Solaris policy allows communication with this
* host, and pretend that the destination is unreachable if not.
*
* This is never a problem for TCP, since that transport is known to
* compute the label properly as part of the tcp_rput_other T_BIND_ACK
* handling. If the remote is unreachable, it will be detected at that
* point, so there's no reason to check it here.
*
* Note that for sendto (and other datagram-oriented friends), this
* check is done as part of the data path label computation instead.
* The check here is just to make non-TCP connect() report the right
* error.
*/
!IPCL_IS_TCP(connp) &&
if (ip_debug > 2) {
pr_addr_dbg("ip_bind_connected: no label for dst %s\n",
}
goto bad_addr;
}
/*
* If the app does a connect(), it means that it will most likely
* send more than 1 packet to the destination. It makes sense
* to clear the temporary flag.
*/
irb->irb_tmp_ire_cnt--;
}
/*
* eligibility tests for passive connects are handled separately
* through tcp_adapt_ire(). We do this before the source address
* selection, because dst_ire may change after a call to
* ipif_select_source(). This is a best-effort check, as the
* packet for this connection may not actually go through
* dst_ire->ire_stq, and the exact IRE can only be known after
* calling ip_newroute(). This is why we further check on the
* tcp_lsosend()/tcp_multisend().
*/
} else if (ipst->ips_ip_multidata_outbound &&
ILL_MDT_CAPABLE(ill)) {
}
}
/*
* If the IRE belongs to a different zone, look for a matching
* route in the forwarding table and use the source address from
* that route.
*/
goto bad_addr;
error = ENETUNREACH;
else
goto bad_addr;
}
if (src_addr == INADDR_ANY)
} else {
/*
* Pick a source address so that a proper inbound
* load spreading would happen.
*/
/*
* Supply a local source address such that inbound
* load spreading happens.
*
* Determine the best source address on this ill for
* the destination.
*
* 1) For broadcast, we should return a broadcast ire
* found above so that upper layers know that the
* destination address is a broadcast address.
*
* 2) If this is part of a group, select a better
* source address so that better inbound load
* balancing happens. Do the same if the ipif
* is DEPRECATED.
*
* 3) If the outgoing interface is part of a usesrc
* group, then try selecting a source address from
* the usesrc ILL.
*/
(dst_ill->ill_usesrc_ifindex != 0)))) {
/*
* If the destination is reachable via a
* given gateway, the selected source address
* should be in the same subnet as the gateway.
* Otherwise, the destination is not reachable.
*
* If there are no interfaces on the same subnet
* as the destination, ipif_select_source gives
* first non-deprecated interface which might be
* on a different subnet than the gateway.
* This is not desirable. Hence pass the dst_ire
* source address to ipif_select_source.
* It is sure that the destination is reachable
* with the dst_ire source address subnet.
* So passing dst_ire source address to
* ipif_select_source will make sure that the
* selected source will be on the same subnet
* as dst_ire source address.
*/
/*
* For VNI there is no
* interface route
*/
src_addr =
} else {
ipif_ire =
}
src_addr =
}
} else {
}
} else {
}
}
}
/*
* We do ire_route_lookup() here (and not
* interface lookup as we assert that
* src_addr should only come from an
* UP interface for hard binding.
*/
/* src_ire must be a local|loopback */
if (!IRE_IS_LOCAL(src_ire)) {
if (ip_debug > 2) {
pr_addr_dbg("ip_bind_connected: bad connected "
}
goto bad_addr;
}
/*
* If the source address is a loopback address, the
* destination had best be local or multicast.
* The transports that can't handle multicast will reject
* those addresses.
*/
ip1dbg(("ip_bind_connected: bad connected loopback\n"));
error = -1;
goto bad_addr;
}
/*
* Allow setting new policies. For example, disconnects come
* down as ipa_t bind. 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.
*/
/*
* can handle their passed-in conn's.
*/
if (ire_requested) {
/*
* Note that sire will not be NULL if this is an off-link
* connection and there is not cache for that dest yet.
*
* XXX Because of an existing bug, if there are multiple
* default routes, the IRE returned now may not be the actual
* default route used (default routes are chosen in a
* round robin fashion). So if the metrics for different
* default routes are different, we may return the wrong
* metrics. This will not be a problem if the existing
* bug is fixed.
*/
}
error = -1;
goto bad_addr;
}
} else if (ipsec_policy_set) {
error = -1;
goto bad_addr;
}
}
/*
* Cache IPsec policy in this conn. If we have per-socket policy,
* we'll cache that. If we don't, we'll inherit global policy.
*
* We can't insert until the conn reflects the policy. Note that
* conn_policy_cached is set by ipsec_conn_cache_policy() even for
* connections where we don't have a policy. This is to prevent
* global policy lookups in the inbound path.
*
* If we insert before we set conn_policy_cached,
* CONN_INBOUND_POLICY_PRESENT() check can still evaluate true
* because global policy cound be non-empty. We normally call
* ipsec_check_policy() for conn_policy_cached connections only if
* ipc_in_enforce_policy is set. But in this case,
* conn_policy_cached can get set anytime since we made the
* CONN_INBOUND_POLICY_PRESENT() check and ipsec_check_policy() is
* called, which will make the above assumption false. Thus, we
* need to insert after we set conn_policy_cached.
*/
goto bad_addr;
if (fanout_insert) {
/*
* The addresses have been verified. Time to insert in
* the correct fanout list.
* We need to make sure that the conn_recv is set to a non-null
* value before we insert into the classifier table to avoid a
* race with an incoming packet which does an ipcl_classify().
*/
if (protocol == IPPROTO_TCP)
}
if (error == 0) {
/*
* ip_xxinfo_return(), which performs further checks
* mblk which we will attach to the bind acknowledgment.
*/
if (lso_dst_ire != NULL) {
} else if (md_dst_ire != NULL) {
}
}
if (ipsec_policy_set) {
/*
* As of now assume that nothing else accompanies
* IPSEC_POLICY_SET.
*/
}
if (md_dst_ire != NULL)
if (lso_dst_ire != NULL)
return (error);
}
/*
* Insert the ire in b_cont. Returns false if it fails (due to lack of space).
* Prefers dst_ire over src_ire.
*/
static boolean_t
{
/*
* mp1 initialized above to IRE_DB_REQ_TYPE
* appended mblk. Its <upper protocol>'s
* job to make sure there is room.
*/
return (0);
/*
* Pass the latest setting of the ip_path_mtu_discovery and
* copy the ulp info if any.
*/
IPH_DF : 0;
sizeof (iulp_t));
}
} else {
/*
* No IRE was found. Remove IRE mblk.
*/
}
return (1);
}
/*
* 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
{
/*
* Wait for the ACKs of all deferred control messages to be processed.
* In particular, we wait for a potential capability reset initiated
* in ip_sioctl_plink() to complete before proceeding.
*
* Note: we wait for at most ip_modclose_ackwait_ms (by default 3000 ms)
* in case the driver never replies.
*/
/* Timeout */
break;
}
}
/*
* Forcibly enter the ipsq after some delay. This is to take
* care of the case when some ioctl does not complete because
* we sent a control message to the driver and it did not
* send us a reply. We want to be able to at least unplumb
* and replumb rather than force the user to reboot the system.
*/
/*
* 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 control 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);
/*
* If MOVE was in progress, clear the
* move_in_progress fields also.
*/
if (ill->ill_move_in_progress) {
}
/*
* 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_quiescent 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 and DL_DETACH with the driver and then qprocsoff.
*/
while (!ill_is_quiescent(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 called in ill_delete_tail */
/*
* Walk through all upper (conn) streams 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"));
/*
* 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 both IP and UDP
* 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.
* Similarly ill_pending_mp_add() will not add any mp to
* the pending mp list, after this conn has started closing.
*
* conn_idl, conn_pending_ill, conn_down_pending_ill, conn_ilg
* cannot get set henceforth.
*/
if (connp->conn_ilg_inuse != 0)
if (IPCL_IS_UDP(connp))
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 streams may have a non-null conn_idl.
* TCP streams are never flow controlled, and
* conn_idl will be null)
*/
if (drain_cleanup_reqd)
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.
*/
/*
* A conn which was previously marked as IPCL_UDP cannot
* retain the flag because it would have been cleared by
* udp_close().
*/
}
}
}
return (0);
}
int
{
qprocsoff(q);
}
return (0);
}
/*
* The only supported primitives are T_SVR4_OPTMGMT_REQ and T_OPTMGMT_REQ.
* M_FLUSH messages and ioctls are only passed downstream; we don't flush our
* queues as we never enqueue messages there and we don't handle any ioctls.
* Everything else is freed.
*/
void
{
case M_PROTO:
case M_PCPROTO:
T_OPTMGMT_REQ))) {
/*
* This is the only TPI primitive supported. Its
* handling does not require tcp_t, but it does require
* conn_t to check permissions.
*/
} else {
}
return;
}
!= NULL)
break;
case M_FLUSH:
case M_IOCTL:
break;
default:
break;
}
}
/* Return the IP checksum for the IP header at "iph". */
{
int opt_len;
if (opt_len > 0) {
do {
uph += 2;
} while (--opt_len);
}
if (sum == 0xffff)
sum = 0;
}
/*
* Called when the module is about to be unloaded
*/
void
ip_ddi_destroy(void)
{
tnet_fini();
}
/*
* First step in cleanup.
*/
/* ARGSUSED */
static void
{
#ifdef NS_DEBUG
#endif
/* Get rid of loopback interfaces and their IREs */
}
/*
* Free the IP stack instance.
*/
static void
{
int ret;
#ifdef NS_DEBUG
#endif
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;
}
if (ret == -1) {
} else {
ipst->ips_ip_ire_expire_id = 0;
}
}
}
/*
* 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.
*/
"ip_ddi_init: ip_minor_arena creation failed\n");
}
ipcl_g_init();
#ifdef ILL_DEBUG
/* Default cleanup function */
#endif
/*
* 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);
"ipmp_hook_emulation") == 0);
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);
}
const char *
dlpi_prim_str(int prim)
{
switch (prim) {
case DL_INFO_REQ: return ("DL_INFO_REQ");
case DL_INFO_ACK: return ("DL_INFO_ACK");
case DL_ATTACH_REQ: return ("DL_ATTACH_REQ");
case DL_DETACH_REQ: return ("DL_DETACH_REQ");
case DL_BIND_REQ: return ("DL_BIND_REQ");
case DL_BIND_ACK: return ("DL_BIND_ACK");
case DL_UNBIND_REQ: return ("DL_UNBIND_REQ");
case DL_OK_ACK: return ("DL_OK_ACK");
case DL_ERROR_ACK: return ("DL_ERROR_ACK");
case DL_ENABMULTI_REQ: return ("DL_ENABMULTI_REQ");
case DL_DISABMULTI_REQ: return ("DL_DISABMULTI_REQ");
case DL_PROMISCON_REQ: return ("DL_PROMISCON_REQ");
case DL_PROMISCOFF_REQ: return ("DL_PROMISCOFF_REQ");
case DL_UNITDATA_REQ: return ("DL_UNITDATA_REQ");
case DL_UNITDATA_IND: return ("DL_UNITDATA_IND");
case DL_UDERROR_IND: return ("DL_UDERROR_IND");
case DL_PHYS_ADDR_REQ: return ("DL_PHYS_ADDR_REQ");
case DL_PHYS_ADDR_ACK: return ("DL_PHYS_ADDR_ACK");
case DL_SET_PHYS_ADDR_REQ: return ("DL_SET_PHYS_ADDR_REQ");
case DL_NOTIFY_REQ: return ("DL_NOTIFY_REQ");
case DL_NOTIFY_ACK: return ("DL_NOTIFY_ACK");
case DL_NOTIFY_IND: return ("DL_NOTIFY_IND");
case DL_CAPABILITY_REQ: return ("DL_CAPABILITY_REQ");
case DL_CAPABILITY_ACK: return ("DL_CAPABILITY_ACK");
case DL_CONTROL_REQ: return ("DL_CONTROL_REQ");
case DL_CONTROL_ACK: return ("DL_CONTROL_ACK");
default: return ("<unknown primitive>");
}
}
const char *
dlpi_err_str(int err)
{
switch (err) {
case DL_ACCESS: return ("DL_ACCESS");
case DL_BADADDR: return ("DL_BADADDR");
case DL_BADCORR: return ("DL_BADCORR");
case DL_BADDATA: return ("DL_BADDATA");
case DL_BADPPA: return ("DL_BADPPA");
case DL_BADPRIM: return ("DL_BADPRIM");
case DL_BADQOSPARAM: return ("DL_BADQOSPARAM");
case DL_BADQOSTYPE: return ("DL_BADQOSTYPE");
case DL_BADSAP: return ("DL_BADSAP");
case DL_BADTOKEN: return ("DL_BADTOKEN");
case DL_BOUND: return ("DL_BOUND");
case DL_INITFAILED: return ("DL_INITFAILED");
case DL_NOADDR: return ("DL_NOADDR");
case DL_NOTINIT: return ("DL_NOTINIT");
case DL_OUTSTATE: return ("DL_OUTSTATE");
case DL_SYSERR: return ("DL_SYSERR");
case DL_UNSUPPORTED: return ("DL_UNSUPPORTED");
case DL_UNDELIVERABLE: return ("DL_UNDELIVERABLE");
case DL_NOTSUPPORTED : return ("DL_NOTSUPPORTED ");
case DL_TOOMANY: return ("DL_TOOMANY");
case DL_NOTENAB: return ("DL_NOTENAB");
case DL_BUSY: return ("DL_BUSY");
case DL_NOAUTO: return ("DL_NOAUTO");
case DL_NOXIDAUTO: return ("DL_NOXIDAUTO");
case DL_NOTESTAUTO: return ("DL_NOTESTAUTO");
case DL_XIDAUTO: return ("DL_XIDAUTO");
case DL_TESTAUTO: return ("DL_TESTAUTO");
case DL_PENDING: return ("DL_PENDING");
default: return ("<unknown error>");
}
}
/*
* 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);
}
/*
* Send an ICMP error after patching up the packet appropriately. Returns
* non-zero if the appropriate MIB should be bumped; zero otherwise.
*/
static boolean_t
{
unsigned char db_type;
if (mctl_present) {
} else {
/*
* If this is an ICMP error being reported - which goes
* up as M_CTLs, we need to convert them to M_DATA till
* we finish checking with global policy because
* ipsec_check_global_policy() assumes M_DATA as clear
* and M_CTL as secure.
*/
}
/*
* 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 (B_FALSE);
}
if (!mctl_present)
if (flags & IP_FF_SEND_ICMP) {
if (flags & IP_FF_HDR_COMPLETE) {
return (B_TRUE);
}
}
if (flags & IP_FF_CKSUM) {
/*
* 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:
ipst);
break;
default:
break;
}
} else {
return (B_FALSE);
}
return (B_TRUE);
}
/*
* 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
{
ipsec_in_t *ii;
/* Get ill from index in ipsec_in_t. */
ipst);
}
} else {
}
}
} else { /* re-link for the freemsg() below. */
}
/* If ICMP delivered, ipsec_mp will be a singleton (b_cont == NULL). */
}
/*
* See if the inbound datagram has had IPsec processing applied to it.
*/
{
ipsec_in_t *ii;
if (ii->ipsec_in_loopback) {
return (ii->ipsec_in_secure);
} else {
}
}
/*
* 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.
*
* NOTE : If the packet was tunneled and not multicast we only send
* to it the first match. Unlike TCP and UDP fanouts this doesn't fall
* back to delivering packets to AF_INET6 raw sockets.
*
* IPQoS Notes:
* Once we have determined the client, invoke IPPF processing.
* Policy processing takes place only if the callout_position, IPP_LOCAL_IN,
* is enabled. If we get here from icmp_inbound_error_fanout or ip_wput_local
* ip_policy will be false.
*
* Zones notes:
* Currently only applications in the global zone can create raw sockets for
* protocols other than ICMP. So unlike the broadcast / multicast case of
* ip_fanout_udp(), we only send a copy of the packet to streams in the
* specified zone. For ICMP, this is handled by the callers of icmp_inbound().
*/
static void
{
if (mctl_present) {
} else {
}
/*
* If the packet was tunneled and not multicast we only send to it
* the first match.
*/
if (shared_addr) {
/*
* We don't allow multilevel ports for raw IP, so no need to
* check for that here.
*/
}
zoneid) &&
(!is_system_labeled() ||
connp)))
break;
}
/*
* No one bound to these addresses. Is
* there a client that wants all
* unclaimed datagrams?
*/
/*
* Check for IPPROTO_ENCAP...
*/
/*
* If an IPsec mblk is here on a multicast
* tunnel (using ip_mroute stuff), check policy here,
* THEN ship off to ip_mroute_decap().
*
* BTW, If I match a configured IP-in-IP
* tunnel, this path will not be reached, and
* ip_mroute_decap will never be called.
*/
if (mctl_present)
} /* Else we already freed everything! */
} else {
/*
* Otherwise send an ICMP protocol unreachable.
*/
}
}
return;
}
first_connp = connp;
/*
* Only send message to one tunnel driver by immediately
* terminating the loop.
*/
for (;;) {
(!is_system_labeled() ||
shared_addr, connp)))
break;
}
/*
* Copy the packet.
*/
/*
* No more interested clients or memory
* allocation failed
*/
connp = first_connp;
break;
}
if (!canputnext(rq)) {
if (flags & IP_FF_RAWIP) {
} else {
}
} else {
/*
* Don't enforce here if we're an actual tunnel -
* let "tun" do it instead.
*/
if (!IPCL_IS_IPTUN(connp) &&
secure)) {
}
int in_flags = 0;
/*
* ip_fanout_proto also gets called from
* icmp_inbound_error_fanout, in which case
* the msg type is M_CTL. Don't add info
* in this case for the time being. In future
* when there is a need for knowing the
* inbound iface index for ICMP error msgs,
* then this can be changed.
*/
if (connp->conn_recvif)
/*
* The ULP may support IP_RECVPKTINFO for both
* IP v4 and v6 so pass the appropriate argument
* based on conn IP version.
*/
if (connp->conn_ip_recvpktinfo) {
if (connp->conn_af_isv6) {
/*
* V6 only needs index
*/
in_flags |= IPF_RECVIF;
} else {
/*
* V4 needs index +
* matching address.
*/
in_flags |= IPF_RECVADDR;
}
}
if ((in_flags != 0) &&
/*
* the actual data will be
* contained in b_cont upon
* successful return of the
* following call else
* original mblk is returned
*/
}
if (mctl_present)
}
}
/* Follow the next pointer before releasing the conn. */
connp = next_connp;
}
/* Last one. Send it upstream. */
/*
* If this packet is coming from icmp_inbound_error_fanout ip_policy
* will be set to false.
*/
if (mctl_present) {
}
return;
}
}
if (!canputnext(rq)) {
if (flags & IP_FF_RAWIP) {
} else {
}
} else {
if (IPCL_IS_IPTUN(connp)) {
/*
* Tunneled packet. We enforce policy in the tunnel
* module itself.
*
* Send the WHOLE packet up (incl. IPSEC_IN) without
* a policy check.
*/
return;
}
}
int in_flags = 0;
/*
* ip_fanout_proto also gets called
* from icmp_inbound_error_fanout, in
* which case the msg type is M_CTL.
* Don't add info in this case for time
* being. In future when there is a
* need for knowing the inbound iface
* index for ICMP error msgs, then this
* can be changed
*/
if (connp->conn_recvif)
if (connp->conn_ip_recvpktinfo) {
if (connp->conn_af_isv6) {
/*
* V6 only needs index
*/
in_flags |= IPF_RECVIF;
} else {
/*
* V4 needs index +
* matching address.
*/
in_flags |= IPF_RECVADDR;
}
}
if ((in_flags != 0) &&
/*
* the actual data will be contained in
* b_cont upon successful return
* of the following call else original
* mblk is returned
*/
}
if (mctl_present)
}
}
}
/*
* Fanout for TCP packets
* The caller puts <fport, lport> in the ports parameter.
*
* IPQoS Notes
* Before sending it to the client, invoke IPPF processing.
* Policy processing takes place only if the callout_position, IPP_LOCAL_IN,
* is enabled. If we get here from icmp_inbound_error_fanout or ip_wput_local
* ip_policy is false.
*/
static void
{
int ip_hdr_len;
if (mctl_present) {
} else {
}
/*
* No connected connection or listener. Send a
* TH_RST via tcp_xmit_listeners_reset.
*/
/* Initiate IPPf processing, if needed. */
return;
}
ip2dbg(("ip_fanout_tcp: no listener; send reset to zone %d\n",
zoneid));
return;
}
/*
* Allocate the SYN for the TCP connection here itself
*/
if (IPCL_IS_TCP(connp)) {
/*
* For fused tcp loopback, assign the eager's
* squeue to be that of the active connect's.
* Note that we don't check for IP_FF_LOOPBACK
* here since this routine gets called only
* for loopback (unlike the IPv6 counterpart).
*/
if (do_tcp_fusion &&
!secure &&
IPCL_IS_TCP(Q_TO_CONN(q))) {
} else {
}
}
}
return;
}
return;
}
return;
}
NULL, mctl_present);
return;
}
if (mctl_present) {
} else {
}
} else {
/*
* Discard first_mp early since we're dealing with a
* fully-connected conn_t and tcp doesn't do policy in
* this case.
*/
if (mctl_present) {
}
}
}
/*
* Initiate policy processing here if needed. If we get here from
* icmp_inbound_error_fanout, ip_policy is false.
*/
if (mctl_present)
return;
} else if (mctl_present) {
} else {
}
}
/* Handle socket options. */
if (!syn_present &&
/* Add header */
/*
* Since tcp does not support IP_RECVPKTINFO for V4, only pass
* IPF_RECVIF.
*/
ipst);
if (mctl_present)
return;
} else if (mctl_present) {
/*
* ip_add_info might return a new mp.
*/
} else {
}
}
if (IPCL_IS_TCP(connp)) {
} else {
}
}
/*
* Deliver a udp packet to the given conn, possibly applying ipsec policy.
* We are responsible for disposing of mp, such as by freemsg() or putnext()
* Caller is responsible for dropping references to the conn, and freeing
* first_mp.
*
* IPQoS Notes
* Before sending it to the client, invoke IPPF processing. Policy processing
* takes place only if the callout_position, IPP_LOCAL_IN, is enabled and
* ip_policy is true. If we get here from icmp_inbound_error_fanout or
* ip_wput_local, ip_policy is false.
*/
static void
{
if (mctl_present)
else
if (CONN_UDP_FLOWCTLD(connp)) {
return;
}
NULL, mctl_present);
return; /* Freed by ipsec_check_inbound_policy(). */
}
}
if (mctl_present)
/* Handle options. */
if (connp->conn_recvif)
/*
* UDP supports IP_RECVPKTINFO option for both v4 and v6 so the flag
* passed to ip_add_info is based on IP version of connp.
*/
if (connp->conn_af_isv6) {
/*
* V6 only needs index
*/
in_flags |= IPF_RECVIF;
} else {
/*
* V4 needs index + matching address.
*/
in_flags |= IPF_RECVADDR;
}
}
in_flags |= IPF_RECVSLLA;
/*
* Initiate IPPF processing here, if needed. Note first_mp won't be
* freed if the packet is dropped. The caller will do so.
*/
return;
}
}
if ((in_flags != 0) &&
/*
* The actual data will be contained in b_cont
* upon successful return of the following call
* else original mblk is returned
*/
ipst);
}
/* Send it upstream */
}
/*
* Fanout for UDP packets.
* The caller puts <fport, lport> in the ports parameter.
*
* If SO_REUSEADDR is set all multicast and broadcast packets
* will be delivered to all streams bound to the same port.
*
* Zones notes:
* Multicast and broadcast packets will be distributed to streams in all zones.
* 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. To maintain this behavior with multiple zones, the conns are grouped
* by zone and the SO_REUSEADDR flag is checked for the first matching conn in
* each zone. If unset, all the following conns in the same zone are skipped.
*/
static void
{
if (mctl_present) {
} else {
}
/* Extract ports in net byte order */
if (shared_addr) {
/*
* No need to handle exclusive-stack zones since ALL_ZONES
* only applies to the shared stack.
*/
}
/*
* Not broadcast or multicast. Send to the one (first)
* client we find. No need to check conn_wantpacket()
* since IP_BOUND_IF/conn_incoming_ill does not apply to
* IPv4 unicast packets.
*/
}
goto notfound;
if (is_system_labeled() &&
connp))
goto notfound;
return;
}
/*
* Broadcast and multicast case
*
* Need to check conn_wantpacket().
* 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.
*/
(!is_system_labeled() ||
connp)))
break;
}
goto notfound;
first_connp = connp;
/*
* When SO_REUSEADDR is not set, send the packet only to the first
* matching connection in its zone by keeping track of the zoneid.
*/
for (;;) {
(!is_system_labeled() ||
shared_addr, connp)))
break;
}
/*
* Just copy the data part alone. The mctl part is
* needed just for verifying policy and it is never
* sent up.
*/
/*
* No more interested clients or memory
* allocation failed
*/
connp = first_connp;
break;
}
/*
* Update the zoneid so that the packet isn't sent to
* any more conns in the same zone unless SO_REUSEADDR
* is set.
*/
}
ipsec_info_type == IPSEC_IN);
ipst->ips_netstack);
connp = first_connp;
break;
}
} else {
}
/*
* IPQoS notes: We don't send the packet for policy
* processing here, will do it for the last one (below).
* i.e. we do it per-packet now, but if we do policy
* processing per-conn, then we would need to do it
* here too.
*/
/* Follow the next pointer before releasing the conn. */
connp = next_connp;
}
/* Last one. Send it upstream. */
return;
/*
* IPv6 endpoints bound to unicast or 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.
*/
break;
}
connp))
/*
* No one bound to this port. Is
* there a client that wants all
* unclaimed datagrams?
*/
if (mctl_present)
else
connf_head != NULL) {
} else {
}
}
return;
}
return;
}
/*
* 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.
* The packet is sent to all clients in all zones that have joined the
* group and match the port.
*/
(!is_system_labeled() ||
connp)))
break;
}
/*
* No one bound to this port. Is
* there a client that wants all
* unclaimed datagrams?
*/
if (mctl_present)
else
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;
}
first_connp = connp;
for (;;) {
(!is_system_labeled() ||
shared_addr, connp)))
break;
}
/*
* Just copy the data part alone. The mctl part is
* needed just for verifying policy and it is never
* sent up.
*/
/*
* No more intested clients or memory
* allocation failed
*/
connp = first_connp;
break;
}
ipsec_info_type == IPSEC_IN);
ipst->ips_netstack);
connp = first_connp;
break;
}
} else {
}
/*
* IPQoS notes: We don't send the packet for policy
* processing here, will do it for the last one (below).
* i.e. we do it per-packet now, but if we do policy
* processing per-conn, then we would need to do it
* here too.
*/
/* Follow the next pointer before releasing the conn. */
connp = next_connp;
}
/* Last one. Send it upstream. */
}
/*
* Complete the ip_wput header so that it
* is possible to generate ICMP
* errors.
*/
int
{
ip1dbg(("ip_hdr_complete: no source IRE\n"));
return (1);
}
}
ipha->ipha_hdr_checksum = 0;
return (0);
}
/*
* Nobody should be sending
* packets up this stream
*/
static void
{
case M_FLUSH:
/* Turn around */
return;
}
break;
}
/* Could receive messages that passed through ar_rput */
}
/* 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_wput_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);
}
/*
* This function's job is to forward data to the reverse tunnel (FA->HA)
* after doing a few checks. It is assumed that the incoming interface
* of the packet is always different than the outgoing interface and the
* ire_type of the found ire has to be a non-resolver type.
*
* IPQoS notes
* IP policy is invoked twice for a forwarded packet, once on the read side
* and again on the write side if both, IPP_FWD_IN and IPP_FWD_OUT are
* enabled.
*/
static void
{
queue_t *q;
/* Initiate read side IPPF processing */
ip2dbg(("ip_mrtun_forward: inbound pkt "
"dropped during IPPF processing\n"));
return;
}
}
ILLF_ROUTER) == 0) ||
ip0dbg(("ip_mrtun_forward: Can't forward :"
"forwarding is not turned on\n"));
goto drop_pkt;
}
/*
* Don't forward if the interface is down
*/
goto discard_pkt;
}
/* Adjust the checksum to reflect the ttl decrement. */
if (ip_csum_hdr(ipha)) {
goto drop_pkt;
}
goto discard_pkt;
}
/* Sent by forwarding path, and router is global zone */
return;
}
/* Get the ill_index of the ILL */
/*
* This location is chosen for the placement of the forwarding hook
* because at this point we know that we have a path out for the
* packet but haven't yet applied any logic (such as fragmenting)
* that happen as part of transmitting the packet out.
*/
return;
/*
* ip_mrtun_forward is only used by foreign agent to reverse
* tunnel the incoming packet. So it does not do any option
* processing for source routing.
*/
/*
* It needs fragging on its way out. We haven't
* verified the header checksum yet. Since we
* are going to put a surely good checksum in the
* outgoing header, we have to make sure that it
* was good coming in.
*/
if (ip_csum_hdr(ipha)) {
goto drop_pkt;
}
/* Initiate write side IPPF processing */
ip2dbg(("ip_mrtun_forward: outbound pkt "\
"processing\n"));
return;
}
}
goto discard_pkt;
}
return;
}
return;
/* Now send the packet to the tunnel interface */
if ((pktxmit_state == SEND_FAILED) ||
(pktxmit_state == LLHDR_RESLV_FAILED)) {
ip2dbg(("ip_mrtun_forward: failed to send packet to ill %p\n",
q->q_ptr));
}
return;
drop_pkt:;
ip2dbg(("ip_mrtun_forward: dropping pkt\n"));
}
/*
* Fills the ipsec_out_t data structure with appropriate fields and
* prepends it to mp which contains the IP hdr + data that was meant
* to be forwarded. Please note that ipsec_out_info data structure
* is used here to communicate the outgoing ill path at ip_wput()
* for the ICMP error packet. This has nothing to do with ipsec IP
* security. ipsec_out_t is really used to pass the info to the module
* IP where this information cannot be extracted from conn.
* This functions is called by ip_mrtun_forward().
*/
void
{
/*
* This is to pass info to ip_wput in absence of conn.
* ipsec_out_secure will be B_FALSE because of this.
* Thus ipsec_out_secure being B_FALSE indicates that
* this is not IPSEC security related information.
*/
}
/*
* Return the network mask
* associated with the specified address.
*/
{
#define TOTALLY_BRAIN_DAMAGED_C_COMPILER
#endif
#endif
maskp[0] = 0xF0;
return (mask);
}
if (addr == 0)
return (0);
maskp[0] = 0xFF;
if ((up[0] & 0x80) == 0)
return (mask);
return (mask);
return (mask);
/* Must be experimental or multicast, indicate as much */
return ((ipaddr_t)0);
}
/*
* Select an ill for the packet by considering load spreading across
* a different ill in the group if dst_ill is part of some group.
*/
ill_t *
{
/*
* We schedule irrespective of whether the source address is
* INADDR_ANY or not. illgrp_scheduler returns a held ill.
*/
return (NULL);
/*
* For groups with names ip_sioctl_groupname ensures that all
* ills are of same type. For groups without names, ifgrp_insert
* ensures this.
*/
return (ill);
}
/*
* Helper function for the IPIF_NOFAILOVER/ATTACH_IF interface attachment case.
*/
ill_t *
{
ipst);
if (isv6) {
} else {
}
ip1dbg(("ip_grab_attach_ill (IPv6): "
"bad ifindex %d.\n", ifindex));
} else {
} else {
}
ip1dbg(("ip_grab_attach_ill (IPv4): "
"bad ifindex %d.\n", ifindex));
}
return (NULL);
}
return (ret_ill);
}
/*
* IPv4 -
* ip_newroute is called by ip_rput or ip_wput whenever we need to send
* out a packet to a destination address for which we do not have specific
* (or sufficient) routing information.
*
* NOTE : These are the scopes of some of the variables that point at IRE,
* which needs to be followed while making any future modifications
* to avoid memory leaks.
*
* - ire and sire are the entries looked up initially by
* ire_ftable_lookup.
* - ipif_ire is used to hold the interface ire associated with
* the new cache ire. But it's scope is limited, so we always REFRELE
* it before branching out to error paths.
* - save_ire is initialized before ire_create, so that ire returned
* by ire_create will not over-write the ire. We REFRELE save_ire
* before breaking out of the switch.
*
* Thus on failures, we have to REFRELE only ire and sire, if they
* are not NULL.
*/
void
{
if (ip_debug > 2) {
/* ip1dbg */
}
if (mctl_present) {
}
/* All multicast lookups come through ip_newroute_ipif() */
ip0dbg(("ip_newroute: CLASSD 0x%x (b_prev %p, b_next %p)\n",
return;
}
/* ip_grab_attach_ill returns a held ill */
/* Failure case frees things for us. */
if (attach_ill == NULL)
return;
/*
* Check if we need an ire that will not be
* looked up by anybody else i.e. HIDDEN.
*/
if (ill_is_probeonly(attach_ill))
}
ip_nexthop = B_TRUE;
}
/*
* If this IRE is created for forwarding or it is not for
* traffic for congestion controlled protocols, mark it as temporary.
*/
/*
* Get what we can from ire_ftable_lookup which will follow an IRE
* chain until it gets the most specific information available.
* For example, we know that there is no IRE_CACHE for this dest,
* but there may be an IRE_OFFSUBNET which specifies a gateway.
* ire_ftable_lookup will look up the gateway, etc.
* Check if in_ill != NULL. If it is true, the packet must be
* from an incoming interface where RTA_SRCIFP is set.
* Otherwise, given ire_ftable_lookup algorithm, only one among routes
* to the destination, of equal netmask length in the forward table,
* will be recursively explored. If no information is available
* for the final gateway of that route, we force the returned ire
* to be equal to sire using MATCH_IRE_PARENT.
* At least, in this case we have a starting point (in the buckets)
* to look for other routes to the destination in the forward table.
* This is actually used only for multirouting, where a list
* of routes has to be processed in sequence.
*
* In the process of coming up with the most specific information,
* ire_ftable_lookup may end up with an incomplete IRE_CACHE entry
* for the gateway (i.e., one for which the ire_nce->nce_state is
* not yet ND_REACHABLE, and is in the middle of arp resolution).
* Two caveats when handling incomplete ire's in ip_newroute:
* - we should be careful when accessing its ire_nce (specifically
* the nce_res_mp) ast it might change underneath our feet, and,
* - not all legacy code path callers are prepared to handle
* ire_cache entries here. (See discussion about temporary solution
* further below).
*
* In order to minimize packet dropping, and to preserve existing
* behavior, we treat this case as if there were no IRE_CACHE for the
* gateway, and instead use the IF_RESOLVER ire to send out
* another request to ARP (this is achieved by passing the
* MATCH_IRE_COMPLETE flag to ire_ftable_lookup). When the
* arp response comes back in ip_wput_nondata, we will create
* a per-dst ire_cache that has an ND_COMPLETE ire.
*
* Note that this is a temporary solution; the correct solution is
* to create an incomplete per-dst ire_cache entry, and send the
* packet out when the gw's nce is resolved. In order to achieve this,
* all packet processing must have been completed prior to calling
* ire_add_then_send. Some legacy code paths (e.g. cgtp) would need
* to be modified to accomodate this solution.
*/
} else if (ip_nexthop) {
/*
* The first time we come here, we look for an IRE_INTERFACE
* entry for the specified nexthop, set the dst to be the
* nexthop address and create an IRE_CACHE entry for the
* nexthop. The next time around, we are able to find an
* IRE_CACHE entry for the nexthop, set the gateway to be the
* nexthop address and create an IRE_CACHE entry for the
* destination address via the specified nexthop.
*/
gw = nexthop_addr;
} else {
ipst);
dst = nexthop_addr;
}
}
} else if (attach_ill == NULL) {
ipst);
} else {
/*
* attach_ill is set only for communicating with
* on-link hosts. So, don't look for DEFAULT.
*/
if (attach_ipif == NULL) {
goto icmp_err_ret;
}
}
ip3dbg(("ip_newroute: ire_ftable_lookup() "
/*
* This loop is run only once in most cases.
* We loop to resolve further routes only when the destination
* can be reached through multiple RTF_MULTIRT-flagged ires.
*/
do {
/* Clear the previous iteration's values */
}
}
/*
* We check if packets have to be multirouted.
* In this case, given the current <ire, sire> couple,
* we look for the next suitable <ire, sire>.
* This check is done in ire_multirt_lookup(),
* which applies various criteria to find the next route
* to resolve. ire_multirt_lookup() leaves <ire, sire>
* unchanged if it detects it has not been tried yet.
*/
ip3dbg(("ip_newroute: starting next_resolution "
"with first_mp %p, tag %d\n",
(void *)first_mp,
ip3dbg(("ip_newroute: multirt_is_resolvable %d, "
"ire %p, sire %p\n",
if (!multirt_is_resolvable) {
/*
* No more multirt route to resolve; give up
* (all routes resolved or no more
* resolvable routes).
*/
}
} else {
/*
* We simply use first_sire as a flag that
* indicates if a resolvable multirt route
* has already been found.
* If it is not the case, we may have to send
* an ICMP error to report that the
* destination is unreachable.
* We do not IRE_REFHOLD first_sire.
*/
if (first_sire == NULL) {
first_sire = sire;
}
}
}
if (ip_debug > 3) {
/* ip2dbg */
pr_addr_dbg("ip_newroute: "
}
ip3dbg(("ip_newroute: "
"ire %p, sire %p, first_sire %p\n",
}
if (first_sire != NULL) {
/*
* At least one multirt route has been found
* in the same call to ip_newroute();
* there is no need to report an ICMP error.
* first_sire was not IRE_REFHOLDed.
*/
return;
}
if (attach_ill != NULL)
goto icmp_err_ret;
}
/*
* When RTA_SRCIFP is used to add a route, then an interface
* route is added in the source interface's routing table.
* If the outgoing interface of this route is of type
* IRE_IF_RESOLVER, then upon creation of the ire,
* ire_nce->nce_res_mp is set to NULL.
* Later, when this route is first used for forwarding
* a packet, ip_newroute() is called
* to resolve the hardware address of the outgoing ipif.
* We do not come here for IRE_IF_NORESOLVER entries in the
* source interface based table. We only come here if the
* outgoing interface is a resolver interface and we don't
* have the ire_nce->nce_res_mp information yet.
* If in_ill is not null that means it is called from
* ip_rput.
*/
/*
* Verify that the returned IRE does not have either
* the RTF_REJECT or RTF_BLACKHOLE flags set and that the IRE is
* either an IRE_CACHE, IRE_IF_NORESOLVER or IRE_IF_RESOLVER.
*/
if (attach_ill != NULL)
goto icmp_err_ret;
}
/*
* Increment the ire_ob_pkt_count field for ire if it is an
* INTERFACE (IF_RESOLVER or IF_NORESOLVER) IRE type, and
* increment the same for the parent IRE, sire, if it is some
* sort of prefix IRE (which includes DEFAULT, PREFIX, HOST
* and HOST_REDIRECT).
*/
}
IRE_INTERFACE)) == 0);
}
/*
* We have a route to reach the destination.
*
* 1) If the interface is part of ill group, try to get a new
* ill taking load spreading into account.
*
* 2) After selecting the ill, get a source address that
* might create good inbound load spreading.
* ipif_select_source does this for us.
*
* If the application specified the ill (ifindex), we still
* load spread. Only if the packets needs to go out
* specifically on a given ill e.g. binding to
* IPIF_NOFAILOVER address, then we don't try to use a
* different ill for load spreading.
*/
if (attach_ill == NULL) {
/*
* Don't perform outbound load spreading in the
* case of an RTF_MULTIRT route, as we actually
* typically want to replicate outgoing packets
* through particular interfaces.
*/
/* for uniformity */
} else {
/*
* If we are here trying to create an IRE_CACHE
* for an offlink destination and have the
* IRE_CACHE for the next hop and the latter is
* using virtual IP source address selection i.e
* it's ire->ire_ipif is pointing to a virtual
* network interface (vni) then
* ip_newroute_get_dst_ll() will return the vni
* interface as the dst_ill. Since the vni is
* virtual i.e not associated with any physical
* interface, it cannot be the dst_ill, hence
* in such a case call ip_newroute_get_dst_ll()
* with the stq_ill instead of the ire_ipif ILL.
* The function returns a refheld ill.
*/
else
}
if (ip_debug > 2) {
pr_addr_dbg("ip_newroute: "
"no dst ill for dst"
}
goto icmp_err_ret;
}
} else {
/* for uniformity */
/*
* We should have found a route matching ill as we
* called ire_ftable_lookup with MATCH_IRE_ILL.
* Rather than asserting, when there is a mismatch,
* we just drop the packet.
*/
if (dst_ill != attach_ill) {
ip0dbg(("ip_newroute: Packet dropped as "
"IPIF_NOFAILOVER ill is %s, "
"ire->ire_ipif->ipif_ill is %s\n",
goto icmp_err_ret;
}
}
/* attach_ill can't go in loop. IPMP and CGTP are disjoint */
if (attach_ill != NULL) {
attach_ill = NULL;
}
/*
* Pick the best source address from dst_ill.
*
* 1) If it is part of a multipathing group, we would
* like to spread the inbound packets across different
* interfaces. ipif_select_source picks a random source
* across the different ills in the group.
*
* 2) If it is not part of a multipathing group, we try
* to pick the source address from the destination
* route. Clustering assumes that when we have multiple
* prefixes hosted on an interface, the prefix of the
* source address matches the prefix of the destination
* route. We do this only if the address is not
* DEPRECATED.
*
* 3) If the conn is in a different zone than the ire, we
* need to pick a source address from the right zone.
*
* NOTE : If we hit case (1) above, the prefix of the source
* address picked may not match the prefix of the
* destination routes prefix as ipif_select_source
* does not look at "dst" while picking a source
* address.
* If we want the same behavior as (2), we will need
* to change the behavior of ipif_select_source.
*/
/*
* The RTF_SETSRC flag is set in the parent ire (sire).
* Check that the ipif matching the requested source
* address still exists.
*/
}
(dst_ill->ill_usesrc_ifindex != 0)) {
/*
* If the destination is reachable via a
* given gateway, the selected source address
* should be in the same subnet as the gateway.
* Otherwise, the destination is not reachable.
*
* If there are no interfaces on the same subnet
* as the destination, ipif_select_source gives
* first non-deprecated interface which might be
* on a different subnet than the gateway.
* This is not desirable. Hence pass the dst_ire
* source address to ipif_select_source.
* It is sure that the destination is reachable
* with the dst_ire source address subnet.
* So passing dst_ire source address to
* ipif_select_source will make sure that the
* selected source will be on the same subnet
* as dst_ire source address.
*/
zoneid);
if (ip_debug > 2) {
pr_addr_dbg("ip_newroute: "
"no src for dst %s ",
printf("through interface %s\n",
}
goto icmp_err_ret;
}
} else {
/* hold src_ipif for uniformity */
}
}
/*
* Assign a source address while we have the conn.
* We can't have ip_wput_ire pick a source address when the
* packet returns from arp since we need to look at
* conn_unspec_src and conn_zoneid, and we lose the conn when
* going through arp.
*
* NOTE : ip_newroute_v6 does not have this piece of code as
* it uses ip6i to store this information.
*/
}
if (ip_debug > 3) {
/* ip2dbg */
pr_addr_dbg("ip_newroute: first hop %s\n",
}
ip2dbg(("\tire type %s (%d)\n",
/*
* The TTL of multirouted packets is bounded by the
* ip_multirt_ttl ndd variable.
*/
/* Force TTL of multirouted packets */
if ((ipst->ips_ip_multirt_ttl > 0) &&
ip2dbg(("ip_newroute: forcing multirt TTL "
"to %d (was %d), dst 0x%08x\n",
}
}
/*
* At this point in ip_newroute(), ire is either the
* IRE_CACHE of the next-hop gateway for an off-subnet
* destination or an IRE_INTERFACE type that should be used
* to resolve an on-subnet destination or an on-subnet
* next-hop gateway.
*
* In the IRE_CACHE case, we have the following :
*
* 1) src_ipif - used for getting a source address.
*
* means packets using this IRE_CACHE will go out on
* dst_ill.
*
* 3) The IRE sire will point to the prefix that is the
* longest matching route for the destination. These
* prefix types include IRE_DEFAULT, IRE_PREFIX, IRE_HOST.
*
* The newly created IRE_CACHE entry for the off-subnet
* destination is tied to both the prefix route and the
* interface route used to resolve the next-hop gateway
* via the ire_phandle and ire_ihandle fields,
* respectively.
*
* In the IRE_INTERFACE case, we have the following :
*
* 1) src_ipif - used for getting a source address.
*
* means packets using the IRE_CACHE that we will build
* here will go out on dst_ill.
*
* 3) sire may or may not be NULL. But, the IRE_CACHE that is
* to be created will only be tied to the IRE_INTERFACE
* that was derived from the ire_ihandle field.
*
* If sire is non-NULL, it means the destination is
* off-link and we will first create the IRE_CACHE for the
* gateway. Next time through ip_newroute, we will create
* the IRE_CACHE for the final destination as described
* above.
*
* In both cases, after the current resolution has been
* completed (or possibly initialised, in the IRE_INTERFACE
* case), the loop may be re-entered to attempt the resolution
* of another RTF_MULTIRT route.
*
* When an IRE_CACHE entry for the off-subnet destination is
* created, RTF_SETSRC and RTF_MULTIRT are inherited from sire,
* for further processing in emission loops.
*/
case IRE_CACHE: {
if (gw == 0)
/*
* We need 3 ire's to create a new cache ire for an
* off-link destination from the cache ire of the
* gateway.
*
* 1. The prefix ire 'sire' (Note that this does
* not apply to the conn_nexthop_set case)
* 2. The cache ire of the gateway 'ire'
* 3. The interface ire 'ipif_ire'
*
* We have (1) and (2). We lookup (3) below.
*
* If there is no interface route to the gateway,
* it is a race condition, where we found the cache
* but the interface route has been deleted.
*/
if (ip_nexthop) {
} else {
ipif_ire =
}
ip1dbg(("ip_newroute: "
"ire_ihandle_lookup_offlink failed\n"));
goto icmp_err_ret;
}
/*
* XXX We are using the same res_mp
* (DL_UNITDATA_REQ) though the save_ire is not
* pointing at the same ill.
* This is incorrect. We need to send it up to the
* resolver to get the right res_mp. For ethernets
* this may be okay (ill_type == DL_ETHER).
*/
/*
* Check cached gateway IRE for any security
* attributes; if found, associate the gateway
* credentials group to the destination IRE.
*/
}
ire = ire_create(
NULL,
ire_fp_mp, /* Fast Path header */
IRE_CACHE, /* IRE type */
in_ill, /* incoming ill */
NULL,
ipst);
}
break;
}
/* reference now held by IRE */
/*
* Prevent sire and ipif_ire from getting deleted.
* The newly created ire is tied to both of them via
* the phandle and ihandle respectively.
*/
/* Has it been removed already ? */
break;
}
}
/* Has it been removed already ? */
break;
}
/*
* In the case of multirouting, a copy
* of the packet is done before its sending.
* The copy is used to attempt another
* route resolution, in a next loop.
*/
}
}
/* Assert that sire is not deleted yet. */
}
/* Assert that ipif_ire is not deleted yet. */
/*
* If copy_mp is not NULL, multirouting was
* requested. We loop to initiate a next
* route resolution attempt, starting from sire.
*/
/*
* Search for the next unresolved
* multirt route.
*/
continue;
}
return;
}
case IRE_IF_NORESOLVER: {
/*
* We have what we need to build an IRE_CACHE.
*
* Create a new res_mp with the IP gateway address
* in destination address in the DLPI hdr if the
* physical length is exactly 4 bytes.
*/
if (gw)
else
ip1dbg(("ip_newroute: res_mp NULL\n"));
break;
}
ip1dbg(("ip_newroute: dst_ill %p "
"for IF_NORESOLV ire %p has "
"no ill_resolver_mp\n",
break;
} else {
}
/*
* TSol note: We are creating the ire cache for the
* destination 'dst'. If 'dst' is offlink, going
* through the first hop 'gw', the security attributes
* of 'dst' must be set to point to the gateway
* credentials of gateway 'gw'. If 'dst' is onlink, it
* is possible that 'dst' is a potential gateway that is
* referenced by some route that has some security
* attributes. Thus in the former case, we need to do a
* gcgrp_lookup of 'gw' while in the latter case we
* need to do gcgrp_lookup of 'dst' itself.
*/
ire = ire_create(
NULL,
NULL, /* Fast Path header */
in_ill, /* Incoming ill */
sire->ire_phandle : 0,
NULL,
ipst);
}
break;
}
/* reference now held by IRE */
/* Prevent save_ire from getting deleted */
/* Has it been removed already ? */
break;
}
/*
* In the case of multirouting, a copy
* of the packet is made before it is sent.
* The copy is used in the next
* loop to attempt another resolution.
*/
}
}
/* Assert that it is not deleted yet. */
/*
* If we found a (no)resolver, we ignore any
* trailing top priority IRE_CACHE in further
* loops. This ensures that we do not omit any
* (no)resolver.
* This IRE_CACHE, if any, will be processed
* by another thread entering ip_newroute().
* IRE_CACHE entries, if any, will be processed
* by another thread entering ip_newroute(),
* (upon resolver response, for instance).
* This aims to force parallel multirt
* resolutions as soon as a packet must be sent.
* In the best case, after the tx of only one
* packet, all reachable routes are resolved.
* Otherwise, the resolution of all RTF_MULTIRT
* routes would require several emissions.
*/
/*
* Search for the next unresolved multirt
* route.
*/
continue;
}
/*
* Don't need sire anymore
*/
return;
}
case IRE_IF_RESOLVER:
/*
* We can't build an IRE_CACHE yet, but at least we
* found a resolver that can help.
*/
if (!OK_RESOLVER_MP(res_mp))
break;
/*
* To be at this point in the code with a non-zero gw
* means that dst is reachable through a gateway that
* we have never resolved. By changing dst to the gw
* addr we resolve the gateway first.
* When ire_add_then_send() tries to put the IP dg
* to dst, it will reenter ip_newroute() at which
* time we will find the IRE_CACHE for the gw and
* create another IRE_CACHE in case IRE_CACHE above.
*/
if (gw != INADDR_ANY) {
/*
* The source ipif that was determined above was
* relative to the destination address, not the
* gateway's. If src_ipif was not taken out of
* the IRE_IF_RESOLVER entry, we'll need to call
* ipif_select_source() again.
*/
if (ip_debug > 2) {
"ip_newroute: no "
"src for gw %s ",
printf("through "
"interface %s\n",
}
goto icmp_err_ret;
}
}
gw = INADDR_ANY;
}
/*
* We obtain a partial IRE_CACHE which we will pass
* along with the resolver query. When the response
* comes back it will be there ready for us to add.
* The ire_max_frag is atomically set under the
* irebucket lock in ire_add_v[46].
*/
ire = ire_create_mp(
NULL, /* no in_src_addr */
NULL, /* ire_max_frag */
NULL, /* Fast Path header */
NULL,
src_ipif, /* Interface ipif */
in_ill, /* Incoming ILL */
0,
0, /* flags if any */
NULL,
NULL,
ipst);
break;
}
}
/*
* Construct message chain for the resolver
* of the form:
* ARP_REQ_MBLK-->IRE_MBLK-->Packet
* Packet could contain a IPSEC_OUT mp.
*
* NOTE : ire will be added later when the response
* comes back from ARP. If the response does not
* come back, ARP frees the packet. For this reason,
* we can't REFHOLD the bucket of save_ire to prevent
* deletions. We may not be able to REFRELE the bucket
* if the response never comes back. Thus, before
* adding the ire, ire_add_v4 will make sure that the
* interface route does not get deleted. This is the
* only case unlike ip_newroute_v6, ip_newroute_ipif_v6
* where we can always prevent deletions because of
* the synchronous nature of adding IRES i.e
* ire_add_then_send is called after creating the IRE.
*/
/* Have saved_mp handy, for cleanup if canput fails */
/* Prepare for cleanup */
}
break;
}
/*
* Fill in the source and dest addrs for the resolver.
* NOTE: this depends on memory layouts imposed by
* ill_init().
*/
if (do_attach_ill) {
/*
* This is bind to no failover case.
* arp packet also must go out on attach_ill.
*/
} else {
}
/* Up to the resolver. */
!(dst_ill->ill_arp_closing)) {
/*
* If we found a resolver, we ignore
* any trailing top priority IRE_CACHE
* in the further loops. This ensures
* that we do not omit any resolver.
* IRE_CACHE entries, if any, will be
* processed next time we enter
* ip_newroute().
*/
/*
* Search for the next unresolved
* multirt route.
*/
/* Prepare the next resolution loop. */
if (mctl_present)
io = (ipsec_out_t *)
continue;
}
/*
* The response will come back in ip_wput
* with db_type IRE_DB_TYPE.
*/
return;
} else {
/* Prepare for cleanup */
mp);
/*
* this is an ire that is not added to the
* cache. ire_freemblk will handle the release
* of any resources associated with the ire.
*/
}
break;
}
default:
break;
}
} while (multirt_resolve_next);
ip1dbg(("ip_newroute: dropped\n"));
/* Did this packet originate externally? */
} else {
}
} else {
} else {
}
}
return;
ip1dbg(("ip_newroute: no route\n"));
/* Did this packet originate externally? */
} else {
}
q = WR(q);
} else {
/*
* There is no outgoing ill, so just increment the
* system MIB.
*/
/*
* Since ip_wput() isn't close to finished, we fill
* in enough of the header for credible error reporting.
*/
/* Failed */
return;
}
}
/*
* At this point we will have ire only if RTF_BLACKHOLE
* or RTF_REJECT flags are set on the IRE. It will not
* generate ICMP_HOST_UNREACHABLE if RTF_BLACKHOLE is set.
*/
return;
}
}
return;
}
}
/*
* IPv4 -
* ip_newroute_ipif is called by ip_wput_multicast and
* ip_rput_forward_multicast whenever we need to send
* out a packet to a destination address for which we do not have specific
* routing information. It is used when the packet will be sent out
* on a specific interface. It is also called by ip_wput() when IP_XMIT_IF
* socket option is set or icmp error message wants to go out on a particular
* interface for a unicast packet.
*
* In most cases, the destination address is resolved thanks to the ipif
* intrinsic resolver. However, there are some cases where the call to
* ip_newroute_ipif must take into account the potential presence of
* that uses the interface. This is specified through flags,
* which can be a combination of:
* - RTF_SETSRC: if an IRE_OFFSUBNET ire exists that has the RTF_SETSRC
* flag, the resulting ire will inherit the IRE_OFFSUBNET source address
* and flags. Additionally, the packet source address has to be set to
* the specified address. The caller is thus expected to set this flag
* if the packet has no specific source address yet.
* - RTF_MULTIRT: if an IRE_OFFSUBNET ire exists that has the RTF_MULTIRT
* flag, the resulting ire will inherit the flag. All unresolved routes
* to the destination must be explored in the same call to
* ip_newroute_ipif().
*/
static void
{
int ihandle = 0;
/*
* CGTP goes in a loop which looks up a new ipif, do an ipif_refhold
* here for uniformity
*/
/*
* This loop is run only once in most cases.
* We loop to resolve further routes only when the destination
* can be reached through multiple RTF_MULTIRT-flagged ires.
*/
do {
}
}
if (mctl_present)
/*
* Save the packet destination address, we may need it after
* the packet has been consumed.
*/
/*
* If the interface is a pt-pt interface we look for an
* IRE_IF_RESOLVER or IRE_IF_NORESOLVER that matches both the
* local_address and the pt-pt destination address. Otherwise
* we just match the local address.
* NOTE: dst could be different than ipha->ipha_dst in case
* of sending igmp multicast packets over a point-to-point
* connection.
* Thus we must be careful enough to check ipha_dst to be a
* multicast address, otherwise it will take xmit_if path for
* multicast packets resulting into kernel stack overflow by
* repeated calls to ip_newroute_ipif from ire_send().
*/
goto err_ret;
}
/*
* We check if an IRE_OFFSUBNET for the addr that goes through
* RTF_MULTIRT flags must be honored. This IRE_OFFSUBNET ire may
* propagate its flags to the new ire.
*/
ip2dbg(("ip_newroute_ipif: "
"ipif_lookup_multi_ire("
"ipif %p, dst %08x) = fire %p\n",
}
/* Failure case frees things for us. */
if (attach_ill == NULL) {
return;
}
/*
* Check if we need an ire that will not be
* looked up by anybody else i.e. HIDDEN.
*/
if (ill_is_probeonly(attach_ill)) {
}
/*
* ip_wput passes the right ipif for IPIF_NOFAILOVER
* case.
*/
/* attach_ill has been refheld by ip_grab_attach_ill */
} else {
/*
* If this is set by IP_XMIT_IF, then make sure that
* ipif is pointing to the same ill as the IP_XMIT_IF
* specified ill.
*/
/*
* If the interface belongs to an interface group,
* make sure the next possible interface in the group
* is used. This encourages load spreading among
* peers in an interface group.
* Note: load spreading is disabled for RTF_MULTIRT
* routes.
*/
/*
* Don't perform outbound load spreading
* in the case of an RTF_MULTIRT issued route,
* we actually typically want to replicate
* outgoing packets through particular
* interfaces.
*/
} else {
}
if (ip_debug > 2) {
pr_addr_dbg("ip_newroute_ipif: "
"no dst ill for dst %s\n",
}
goto err_ret;
}
}
/*
* Pick a source address preferring non-deprecated ones.
* Unlike ip_newroute, we don't do any source address
* selection here since for multicast it really does not help
* in inbound load spreading as in the unicast case.
*/
/*
* As requested by flags, an IRE_OFFSUBNET was looked up
* on that interface. This ire has RTF_SETSRC flag, so
* the source address of the packet must be changed.
* Check that the ipif matching the requested source
* address still exists.
*/
}
if (ip_debug > 2) {
/* ip1dbg */
pr_addr_dbg("ip_newroute_ipif: "
"no src for dst %s",
}
ip1dbg((" through interface %s\n",
goto err_ret;
}
}
}
/*
* Assign a source address while we have the conn.
* We can't have ip_wput_ire pick a source address when the
* packet returns from arp since conn_unspec_src might be set
* and we loose the conn when going through arp.
*/
}
/*
* In case of IP_XMIT_IF, it is possible that the outgoing
* interface does not have an interface ire.
* Example: Thousands of mobileip PPP interfaces to mobile
* nodes. We don't want to create interface ires because
* packets from other mobile nodes must not take the route
* via interface ires to the visiting mobile node without
* going through the home agent, in absence of mobileip
* route optimization.
*/
infop->ip_opt_ill_index == 0) {
/* ipif_to_ire returns an held ire */
goto err_ret;
goto err_ret;
/*
* ihandle is needed when the ire is added to
* cache table.
*/
ip2dbg(("ip_newroute_ipif: ire %p, ipif %p, "
"flags %04x\n",
/*
* As requested by flags, an IRE_OFFSUBNET was
* looked up on that interface. This ire has
* RTF_MULTIRT flag, so the resolution loop will
* be re-entered to resolve additional routes on
* other interfaces. For that purpose, a copy of
* the packet is performed at this point.
*/
if (copy_mp) {
}
}
/*
* As requested by flags, an IRE_OFFSUBET was
* looked up on that interface. This ire has
* RTF_SETSRC flag, so the source address of the
* packet must be changed.
*/
}
} else {
(connp->conn_dontroute) ||
infop->ip_opt_ill_index != 0);
/*
* The only ways we can come here are:
* 1) IP_XMIT_IF socket option is set
* 2) ICMP error message generated from
* ip_mrtun_forward() routine and it needs
* to go through the specified ill.
* 3) SO_DONTROUTE socket option is set
* 4) IP_PKTINFO option is passed in as ancillary data.
* In all cases, the new ire will not be added
* into cache table.
*/
}
switch (ipif->ipif_net_type) {
case IRE_IF_NORESOLVER: {
/* We have what we need to build an IRE_CACHE. */
/*
* Create a new res_mp with the
* IP gateway address as destination address in the
* DLPI hdr if the physical length is exactly 4 bytes.
*/
ip1dbg(("ip_newroute: dst_ill %p "
"for IF_NORESOLV ire %p has "
"no ill_resolver_mp\n",
break;
} else {
/* use the value set in ip_ll_subnet_defaults */
}
break;
/*
* The new ire inherits the IRE_OFFSUBNET flags
* and source address, if this was requested.
*/
ire = ire_create(
NULL, /* gateway address */
NULL,
NULL, /* Fast Path header */
NULL,
fire->ire_phandle : 0,
ihandle, /* Interface handle */
(RTF_SETSRC | RTF_MULTIRT)) : 0,
NULL,
NULL,
ipst);
break;
}
/*
* If IRE_MARK_NOADD is set then we need to convert
* the max_fragp to a useable value now. This is
* normally done in ire_add_v[46]. We also need to
* associate the ire with an nce (normally would be
* done in ip_wput_nondata()).
*
* Note that IRE_MARK_NOADD packets created here
* do not have a non-null ire_mp pointer. The null
* value of ire_bucket indicates that they were
* never added.
*/
break;
}
}
/* Prevent save_ire from getting deleted */
/* Has it been removed already ? */
break;
}
}
/* Assert that save_ire is not deleted yet. */
}
}
/*
* the resolution loop is re-entered if this
* was requested through flags and if we
* actually are in a multirouting case.
*/
if (!need_resolve) {
} else {
/*
* ipif_lookup_group() calls
* ire_lookup_multi() that uses
* ire_ftable_lookup() to find
* an IRE_INTERFACE for the group.
* In the multirt case,
* ire_lookup_multi() then invokes
* ire_multirt_lookup() to find
* the next resolvable ire.
* As a result, we obtain an new
* interface, derived from the
* next ire.
*/
ip2dbg(("ip_newroute_ipif: "
"multirt dst %08x, ipif %p\n",
continue;
} else {
}
}
}
return;
}
case IRE_IF_RESOLVER:
/*
* We can't build an IRE_CACHE yet, but at least
* we found a resolver that can help.
*/
if (!OK_RESOLVER_MP(res_mp))
break;
/*
* We obtain a partial IRE_CACHE which we will pass
* along with the resolver query. When the response
* comes back it will be there ready for us to add.
* The new ire inherits the IRE_OFFSUBNET flags
* and source address, if this was requested.
* The ire_max_frag is atomically set under the
* irebucket lock in ire_add_v[46]. Only in the
* case of IRE_MARK_NOADD, we set it here itself.
*/
ire = ire_create_mp(
NULL, /* gateway address */
NULL, /* no in_src_addr */
(ire_marks & IRE_MARK_NOADD) ?
NULL, /* Fast path header */
NULL, /* let ire_nce_init figure res_mp out */
NULL,
fire->ire_phandle : 0,
ihandle, /* Interface handle */
(RTF_SETSRC | RTF_MULTIRT)) : 0,
NULL,
NULL,
ipst);
}
break;
/*
* Construct message chain for the resolver of the
* form:
* ARP_REQ_MBLK-->IRE_MBLK-->Packet
*
* NOTE : ire will be added later when the response
* comes back from ARP. If the response does not
* come back, ARP frees the packet. For this reason,
* we can't REFHOLD the bucket of save_ire to prevent
* deletions. We may not be able to REFRELE the
* bucket if the response never comes back.
* Thus, before adding the ire, ire_add_v4 will make
* sure that the interface route does not get deleted.
* This is the only case unlike ip_newroute_v6,
* ip_newroute_ipif_v6 where we can always prevent
* deletions because ire_add_then_send is called after
* creating the IRE.
* If IRE_MARK_NOADD is set, then ire_add_then_send
* does not add this IRE into the IRE CACHE.
*/
/* Have saved_mp handy, for cleanup if canput fails */
/* Prepare for cleanup */
}
break;
}
/*
* Fill in the source and dest addrs for the resolver.
* NOTE: this depends on memory layouts imposed by
* ill_init().
*/
/* Up to the resolver. */
!(dst_ill->ill_arp_closing)) {
/*
* The response will come back in ip_wput
* with db_type IRE_DB_TYPE.
*/
} else {
ip2dbg(("ip_newroute_ipif: dropped\n"));
}
}
/*
* The resolution loop is re-entered if this was
* requested through flags and we actually are
* in a multirouting case.
*/
if (!need_resolve) {
} else {
/*
* ipif_lookup_group() calls
* ire_lookup_multi() that uses
* ire_ftable_lookup() to find
* an IRE_INTERFACE for the group.
* In the multirt case,
* ire_lookup_multi() then invokes
* ire_multirt_lookup() to find
* the next resolvable ire.
* As a result, we obtain an new
* interface, derived from the
* next ire.
*/
continue;
} else {
}
}
}
return;
default:
break;
}
} while (multirt_resolve_next);
ip2dbg(("ip_newroute_ipif: dropped\n"));
/* Did this packet originate externally? */
} else {
/*
* Since ip_wput() isn't close to finished, we fill
* in enough of the header for credible error reporting.
*/
/* Failed */
return;
}
}
/*
* At this point we will have ire only if RTF_BLACKHOLE
* or RTF_REJECT flags are set on the IRE. It will not
* generate ICMP_HOST_UNREACHABLE if RTF_BLACKHOLE is set.
*/
return;
}
}
}
char *
{
if (!nv)
return (NULL);
}
return ("unknown");
}
/*
* 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.
*/
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);
}
/* ill_init initializes the ipsq marking this thread as writer */
/* Wait for the DL_INFO_ACK */
/*
* Return value of 0 indicates a pending signal.
*/
if (err == 0) {
(void) ip_close(q, 0);
return (EINTR);
}
}
/*
* ip_rput_other could have set an error in ill_error on
* receipt of M_ERROR.
*/
if (err != 0) {
(void) ip_close(q, 0);
return (err);
}
credp);
if (err) {
(void) ip_close(q, 0);
return (err);
}
return (0);
}
/* IP open routine. */
int
{
netstack_t *ns;
/* Allow reopen. */
return (0);
/* This is a module open */
}
/*
* 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()
*/
if (flag & SO_SOCKSTR)
/* Minor tells us which /dev entry was opened */
} else {
}
/* CONN_DEC_REF takes care of netstack_rele() */
return (EBUSY);
}
/*
* connp->conn_cred is crfree()ed in ipcl_conn_destroy()
*/
/*
* If the caller has the process-wide flag set, then default to MAC
* exempt mode. This allows read-down to unlabeled hosts.
*/
/*
* This should only happen for ndd, netstat, raw socket or other SCTP
* administrative ops. In these cases, we just need a normal conn_t
* with ulp set to IPPROTO_SCTP. All other ops are trapped and
* an error will be returned.
*/
} else {
}
/* Non-zero default values */
/*
* Make the conn globally visible to walkers
*/
qprocson(q);
return (0);
}
/*
* Change q_qinfo based on the value of isv6.
* This can not called on an ill queue.
* Note that there is no race since either q_qinfo works for conn queues - it
* is just an optimization to enter the best wput routine directly.
*/
void
{
if (minor == IPV6_MINOR) {
if (bump_mib) {
}
q->q_qinfo = &rinit_ipv6;
} else {
if (bump_mib) {
}
}
}
/*
* See if IPsec needs loading because of the options in mp.
*/
static boolean_t
{
int opthdr_len;
/*
* Walk through the mess, and find IP_SEC_OPT. If it's there,
* return TRUE.
*/
opthdr_len = sizeof (struct T_opthdr);
} else { /* O_OPTMGMT_REQ */
opthdr_len = sizeof (struct opthdr);
}
return (B_FALSE); /* Not enough option header. */
} else {
}
return (B_FALSE); /* bad option buffer */
/*
* Check to see if it's an all-bypass or all-zeroes
* IPsec request. Don't bother loading IPsec if
* the socket doesn't want to use it. (A good example
* is a bypass request.)
*
* Basically, if any of the non-NEVER bits are set,
* load IPsec.
*/
!= 0)
return (B_TRUE);
}
}
return (B_FALSE);
}
/*
* If conn is is waiting for ipsec to finish loading, kick it.
*/
/* ARGSUSED */
static void
{
int err = 0;
/*
* This function is called, after ipsec loading is complete.
* Since IP checks exclusively and atomically (i.e it prevents
* ipsec load from completing until ip_optcom_req completes)
* whether ipsec load is complete, there cannot be a race with IP
* trying to set the CONN_IPSEC_LOAD_WAIT flag on any conn now.
*/
if (optreq_prim == T_OPTMGMT_REQ) {
&ip_opt_obj);
} else {
&ip_opt_obj);
}
if (err != EINPROGRESS)
return;
}
}
/*
* Called from the ipsec_loader thread, outside any perimeter, to tell
* ip qenable any of the queues waiting for the ipsec loader to
* complete.
*/
void
{
}
/*
* Can't be used. Need to call svr4* -> optset directly. the leaf routine
* determines the grp on which it has to become exclusive, queues the mp
* and sq draining restarts the optmgmt
*/
static boolean_t
{
/*
* Take IPsec requests and treat them special.
*/
if (ipsec_opt_present(mp)) {
/* First check if IPsec is loaded. */
return (B_FALSE);
}
return (B_TRUE);
}
return (B_FALSE);
}
/*
* 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 fam;
int error = 0;
/*
* The IP_SEC_OPT option does not allow variable length parameters,
* hence a request cannot be NULL.
*/
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 ip_bind_connected*(), 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 allocate IPv4 policy entries, since they can also
* apply to ipv6 sockets being used in ipv4-compat mode.
*/
ipst->ips_netstack);
goto enomem;
ipst->ips_netstack);
goto enomem;
if (connp->conn_pkt_isv6) {
/*
* We're looking at a v6 socket, also allocate the
* v6-specific entries...
*/
goto enomem;
goto enomem;
/*
* .. and file them away in the right place.
*/
fam = IPSEC_AF_V6;
}
/*
* File the v4 policies.
*/
fam = IPSEC_AF_V4;
/*
* 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 an ipsec_out
* gets attached in ip_wput. This is needed so that
* for connections that we don't cache policy in ip_bind,
* if global policy matches in ip_wput_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.
*/
return (ENOMEM);
}
/*
* Only for options that pass in an IP addr. Currently only V4 options
* pass in an ipif. V6 options always pass an ifindex specifying the ill.
* So this function assumes level is IPPROTO_IP
*/
int
{
int error;
int zoneid;
if (option == IP_NEXTHOP) {
} else {
}
if (error == EINPROGRESS)
return (error);
else if ((option == IP_MULTICAST_IF) ||
(option == IP_NEXTHOP))
return (EHOSTUNREACH);
else
return (EINVAL);
} else if (checkonly) {
if (option == IP_MULTICAST_IF) {
/* not supported by the virtual network iface */
return (EINVAL);
}
}
return (0);
}
return (option == IP_MULTICAST_IF ?
EHOSTUNREACH : EINVAL);
}
} else {
}
/* None of the options below are supported on the VNI */
return (EINVAL);
}
switch (option) {
case IP_DONTFAILOVER_IF:
/*
* This option is used by in.mpathd to ensure
* that IPMP probe packets only go out on the
* test interfaces. in.mpathd sets this option
* on the non-failover interfaces.
* For backward compatibility, this option
* implicitly sets IP_MULTICAST_IF, as used
* be done in bind(), so that ip_wput gets
* this ipif to send mcast packets.
*/
} else {
}
break;
case IP_MULTICAST_IF:
break;
case IP_NEXTHOP:
break;
}
return (0);
}
/* We succeded in cleared the option */
return (0);
}
/*
* For options that pass in an ifindex specifying the ill. V6 options always
* pass in an ill. Some v4 options also pass in ifindex specifying the ill.
*/
int
{
int error = 0;
if (ifindex != 0) {
if (checkonly) {
/* not supported by the virtual network iface */
return (EINVAL);
}
return (0);
}
0, NULL)) {
goto setit;
}
}
goto setit;
} else if (error == EINPROGRESS) {
return (error);
} else {
error = 0;
}
}
/*
* receives traffic. Neither of which is true for the virtual network
* interface, so fail setting these on a VNI.
*/
return (EINVAL);
}
if (level == IPPROTO_IP) {
switch (option) {
case IP_BOUND_IF:
0 : ifindex;
break;
case IP_XMIT_IF:
/*
* Similar to IP_BOUND_IF, but this only
* determines the outgoing interface for
* unicast packets. Also no IRE_CACHE entry
* is added for the destination of the
* outgoing packets. This feature is needed
* for mobile IP.
*/
0 : ifindex;
break;
case IP_MULTICAST_IF:
/*
* This option is an internal special. The socket
* level IP_MULTICAST_IF specifies an 'ipaddr' and
* is handled in ip_opt_set_ipif. IPV6_MULTICAST_IF
* specifies an ifindex and we try first on V6 ill's.
* If we don't find one, we they try using on v4 ill's
* intenally and we come here.
*/
} else {
}
}
break;
}
} else {
switch (option) {
case IPV6_BOUND_IF:
0 : ifindex;
break;
case IPV6_BOUND_PIF:
/*
* Limit all transmit to this ill.
* Unlike IPV6_BOUND_IF, using this option
* prevents load spreading and failover from
* happening when the interface is part of the
* group. That's why we don't need to remember
* the ifindex in orig_bound_ifindex as in
* IPV6_BOUND_IF.
*/
break;
case IPV6_DONTFAILOVER_IF:
/*
* This option is used by in.mpathd to ensure
* that IPMP probe packets only go out on the
* test interfaces. in.mpathd sets this option
* on the non-failover interfaces.
*/
/*
* For backward compatibility, this option
* implicitly sets ip_multicast_ill as used in
* IP_MULTICAST_IF so that ip_wput gets
* this ipif to send mcast packets.
*/
0 : ifindex;
break;
case IPV6_MULTICAST_IF:
/*
* Set conn_multicast_ill to be the IPv6 ill.
* Set conn_multicast_ipif to be an IPv4 ipif
* for ifindex to make IPv4 mapped addresses
* on PF_INET6 sockets honor IPV6_MULTICAST_IF.
* Even if no IPv6 ill exists for the ifindex
* we need to check for an IPv4 ifindex in order
* for this to work with mapped addresses. In that
* case only set conn_multicast_ipif.
*/
if (!checkonly) {
if (ifindex == 0) {
}
}
break;
}
}
return (0);
}
/*
* We succeeded in clearing the option (ifindex == 0) or failed to
* locate the ill and could not set the option (ifindex != 0)
*/
}
/* This routine sets socket options. */
/* ARGSUSED */
int
{
int error = 0;
switch (optset_context) {
case SETFN_OPTCOM_CHECKONLY:
/*
* Note: Implies T_CHECK semantics for T_OPTCOM_REQ
* inlen != 0 implies value supplied and
* we have to "pretend" to set it.
* inlen == 0 implies that there is no
* value part in T_CHECK request and just validation
* done elsewhere should be enough, we just return here.
*/
if (inlen == 0) {
*outlenp = 0;
return (0);
}
break;
case SETFN_OPTCOM_NEGOTIATE:
case SETFN_UD_NEGOTIATE:
case SETFN_CONN_NEGOTIATE:
break;
default:
/*
* We should never get here
*/
*outlenp = 0;
return (EINVAL);
}
/*
* For fixed length options, no sanity check
* of passed in length is done. It is assumed *_optcom_req()
* routines do the right thing.
*/
switch (level) {
case SOL_SOCKET:
/*
* conn_lock protects the bitfields, and is used to
* set the fields atomically.
*/
switch (name) {
case SO_BROADCAST:
if (!checkonly) {
/* TODO: use value someplace? */
}
break; /* goto sizeof (int) option return */
case SO_USELOOPBACK:
if (!checkonly) {
/* TODO: use value someplace? */
}
break; /* goto sizeof (int) option return */
case SO_DONTROUTE:
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case SO_REUSEADDR:
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case SO_PROTOTYPE:
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case SO_ALLZONES:
if (!checkonly) {
if (IPCL_IS_BOUND(connp)) {
return (EINVAL);
}
}
break; /* goto sizeof (int) option return */
case SO_ANON_MLP:
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case SO_MAC_EXEMPT:
if (secpolicy_net_mac_aware(cr) != 0 ||
return (EACCES);
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
default:
/*
* "soft" error (negative)
* option not handled at this level
* Note: Do not modify *outlenp
*/
return (-EINVAL);
}
break;
case IPPROTO_IP:
switch (name) {
case IP_NEXTHOP:
return (EPERM);
/* FALLTHRU */
case IP_MULTICAST_IF:
case IP_DONTFAILOVER_IF: {
first_mp);
if (error != 0)
return (error);
break; /* goto sizeof (int) option return */
}
case IP_MULTICAST_TTL:
/* Recorded in transport above IP */
return (0);
case IP_MULTICAST_LOOP:
if (!checkonly) {
}
return (0);
case IP_ADD_MEMBERSHIP:
case MCAST_JOIN_GROUP:
case IP_DROP_MEMBERSHIP:
case MCAST_LEAVE_GROUP: {
struct sockaddr_in *sin;
switch (name) {
case IP_ADD_MEMBERSHIP:
/* FALLTHRU */
case MCAST_JOIN_GROUP:
break;
case IP_DROP_MEMBERSHIP:
/* FALLTHRU */
case MCAST_LEAVE_GROUP:
break;
}
if (mcast_opt) {
*outlenp = 0;
return (ENOPROTOOPT);
}
ifaddr = INADDR_ANY;
} else {
}
/*
* 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 (!done) {
}
if (error) {
/*
* EINPROGRESS is a soft error, needs retry
* so don't make *outlenp zero.
*/
if (error != EINPROGRESS)
*outlenp = 0;
return (error);
}
/* OK return - copy input buffer into output buffer */
}
return (0);
}
case IP_BLOCK_SOURCE:
case IP_UNBLOCK_SOURCE:
case IP_ADD_SOURCE_MEMBERSHIP:
case MCAST_BLOCK_SOURCE:
case MCAST_UNBLOCK_SOURCE:
case MCAST_JOIN_SOURCE_GROUP:
case MCAST_LEAVE_SOURCE_GROUP: {
struct ip_mreq_source *imreqp;
struct group_source_req *gsreqp;
struct sockaddr_in *sin;
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;
}
if (mcast_opt) {
*outlenp = 0;
return (ENOPROTOOPT);
}
} else {
}
/*
* In the multirouting case, we need to replicate
* the request as noted in the mcast cases above.
*/
}
}
if (!done) {
}
if (error != 0) {
/*
* EINPROGRESS is a soft error, needs retry
* so don't make *outlenp zero.
*/
if (error != EINPROGRESS)
*outlenp = 0;
return (error);
}
/* OK return - copy input buffer into output buffer */
}
return (0);
}
case IP_SEC_OPT:
if (error != 0) {
*outlenp = 0;
return (error);
}
break;
case IP_HDRINCL:
case IP_OPTIONS:
case T_IP_OPTIONS:
case IP_TOS:
case T_IP_TOS:
case IP_TTL:
case IP_RECVDSTADDR:
case IP_RECVOPTS:
/* OK return - copy input buffer into output buffer */
}
return (0);
case IP_RECVIF:
/* Retrieve the inbound interface index */
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case IP_RECVPKTINFO:
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case IP_RECVSLLA:
/* Retrieve the source link layer address */
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case MRT_INIT:
case MRT_DONE:
case MRT_ADD_VIF:
case MRT_DEL_VIF:
case MRT_ADD_MFC:
case MRT_DEL_MFC:
case MRT_ASSERT:
*outlenp = 0;
return (error);
}
if (error) {
*outlenp = 0;
return (error);
}
/* OK return - copy input buffer into output buffer */
}
return (0);
case IP_BOUND_IF:
case IP_XMIT_IF:
if (error != 0)
return (error);
break; /* goto sizeof (int) option return */
case IP_UNSPEC_SRC:
/* Allow sending with a zero source address */
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
default:
/*
* "soft" error (negative)
* option not handled at this level
* Note: Do not modify *outlenp
*/
return (-EINVAL);
}
break;
case IPPROTO_IPV6:
switch (name) {
case IPV6_BOUND_IF:
case IPV6_BOUND_PIF:
case IPV6_DONTFAILOVER_IF:
if (error != 0)
return (error);
break; /* goto sizeof (int) option return */
case IPV6_MULTICAST_IF:
/*
* The only possible errors are EINPROGRESS and
* EINVAL. EINPROGRESS will be restarted and is not
* a hard error. We call this option on both V4 and V6
* If both return EINVAL, then this call returns
* EINVAL. If at least one of them succeeds we
* return success.
*/
if (error == EINPROGRESS)
return (error);
if (error == 0)
if (error == 0)
if (!found)
return (error);
break; /* goto sizeof (int) option return */
case IPV6_MULTICAST_HOPS:
/* Recorded in transport above IP */
break; /* goto sizeof (int) option return */
case IPV6_MULTICAST_LOOP:
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case IPV6_JOIN_GROUP:
case MCAST_JOIN_GROUP:
case IPV6_LEAVE_GROUP:
case MCAST_LEAVE_GROUP: {
switch (name) {
case IPV6_JOIN_GROUP:
/* FALLTHRU */
case MCAST_JOIN_GROUP:
break;
case IPV6_LEAVE_GROUP:
/* FALLTHRU */
case MCAST_LEAVE_GROUP:
break;
}
if (mcast_opt) {
struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
sin = (struct sockaddr_in *)
&groupv6);
} else {
sin6 = (struct sockaddr_in6 *)
}
} else {
}
/*
* 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_v6() succeeds if
* the operation succeeds on at least one interface.
*/
first_mp);
}
}
if (!done) {
}
if (error) {
/*
* EINPROGRESS is a soft error, needs retry
* so don't make *outlenp zero.
*/
if (error != EINPROGRESS)
*outlenp = 0;
return (error);
}
/* OK return - copy input buffer into output buffer */
}
return (0);
}
case MCAST_BLOCK_SOURCE:
case MCAST_UNBLOCK_SOURCE:
case MCAST_JOIN_SOURCE_GROUP:
case MCAST_LEAVE_SOURCE_GROUP: {
struct group_source_req *gsreqp;
switch (name) {
case MCAST_BLOCK_SOURCE:
break;
case MCAST_UNBLOCK_SOURCE:
break;
case MCAST_JOIN_SOURCE_GROUP:
break;
case MCAST_LEAVE_SOURCE_GROUP:
break;
}
struct sockaddr_in *s;
} else {
struct sockaddr_in6 *s6;
}
/*
* In the multirouting case, we need to replicate
* the request as noted in the mcast cases above.
*/
}
}
if (!done) {
}
if (error != 0) {
/*
* EINPROGRESS is a soft error, needs retry
* so don't make *outlenp zero.
*/
if (error != EINPROGRESS)
*outlenp = 0;
return (error);
}
/* OK return - copy input buffer into output buffer */
}
return (0);
}
case IPV6_UNICAST_HOPS:
/* Recorded in transport above IP */
break; /* goto sizeof (int) option return */
case IPV6_UNSPEC_SRC:
/* Allow sending with a zero source address */
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case IPV6_RECVPKTINFO:
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case IPV6_RECVTCLASS:
if (!checkonly) {
return (EINVAL);
}
}
break;
case IPV6_RECVPATHMTU:
if (!checkonly) {
return (EINVAL);
}
}
break;
case IPV6_RECVHOPLIMIT:
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case IPV6_RECVHOPOPTS:
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case IPV6_RECVDSTOPTS:
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case IPV6_RECVRTHDR:
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case IPV6_RECVRTHDRDSTOPTS:
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case IPV6_PKTINFO:
if (inlen == 0)
return (-EINVAL); /* clearing option */
if (error != 0)
*outlenp = 0;
else
return (error);
case IPV6_NEXTHOP: {
struct sockaddr_in6 *sin6;
/* Verify that the nexthop is reachable */
if (inlen == 0)
return (-EINVAL); /* clearing option */
*outlenp = 0;
return (EHOSTUNREACH);
}
return (-EINVAL);
}
case IPV6_SEC_OPT:
if (error != 0) {
*outlenp = 0;
return (error);
}
break;
case IPV6_SRC_PREFERENCES: {
/*
* This is implemented strictly in the ip module
* (here and in tcp_opt_*() to accomodate tcp
* sockets). Modules above ip pass this option
* down here since ip is the only one that needs to
* be aware of source address preferences.
*
* This socket option only affects connected
* sockets that haven't already bound to a specific
* IPv6 address. In other words, sockets that
* don't call bind() with an address other than the
* unspecified address and that call connect().
* ip_bind_connected_v6() passes these preferences
* to the ipif_select_source_v6() function.
*/
return (EINVAL);
if (error != 0) {
*outlenp = 0;
return (error);
} else {
}
break;
}
case IPV6_V6ONLY:
return (EINVAL);
}
break;
default:
return (-EINVAL);
}
break;
default:
/*
* "soft" error (negative)
* option not handled at this level
* Note: Do not modify *outlenp
*/
return (-EINVAL);
}
/*
* Common case of return from an option that is sizeof (int)
*/
*outlenp = sizeof (int);
return (0);
}
/*
* This routine gets default values of certain options whose default
* values are maintained by protocol specific code
*/
/* ARGSUSED */
int
{
switch (level) {
case IPPROTO_IP:
switch (name) {
case IP_MULTICAST_TTL:
return (sizeof (uchar_t));
case IP_MULTICAST_LOOP:
return (sizeof (uchar_t));
default:
return (-1);
}
case IPPROTO_IPV6:
switch (name) {
case IPV6_UNICAST_HOPS:
return (sizeof (int));
case IPV6_MULTICAST_HOPS:
return (sizeof (int));
case IPV6_MULTICAST_LOOP:
return (sizeof (int));
case IPV6_V6ONLY:
*i1 = 1;
return (sizeof (int));
default:
return (-1);
}
default:
return (-1);
}
/* NOTREACHED */
}
/*
* Given a destination address and a pointer to where to put the information
* this routine fills in the mtuinfo.
*/
int
{
if (IN6_IS_ADDR_UNSPECIFIED(in6))
return (-1);
} else {
}
return (sizeof (struct ip6_mtuinfo));
}
/*
* This routine gets socket options. For MRT_VERSION and MRT_ASSERT, error
* checking of GET_QUEUE_CRED(q) and that ip_g_mrouter is set should be done and
* isn't. This doesn't matter as the error checking is done properly for the
* other MRT options coming in through ip_opt_set.
*/
int
{
switch (level) {
case IPPROTO_IP:
switch (name) {
case MRT_VERSION:
case MRT_ASSERT:
return (sizeof (int));
case IP_SEC_OPT:
case IP_NEXTHOP:
if (connp->conn_nexthop_set) {
return (sizeof (ipaddr_t));
} else
return (0);
case IP_RECVPKTINFO:
return (sizeof (int));
default:
break;
}
break;
case IPPROTO_IPV6:
switch (name) {
case IPV6_SEC_OPT:
case IPV6_SRC_PREFERENCES: {
return (ip6_get_src_preferences(connp,
}
case IPV6_V6ONLY:
return (sizeof (int));
case IPV6_PATHMTU:
(struct ip6_mtuinfo *)ptr,
connp->conn_netstack));
default:
break;
}
break;
default:
break;
}
return (-1);
}
/* 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);
}
/*
* ipsec processing for the fast path, used for input UDP Packets
*/
static boolean_t
{
/* The ill_index of the incoming ILL */
/* pass packet up to the transport */
NULL, mctl_present);
return (B_FALSE);
}
}
/* Initiate IPPF processing for fastpath UDP */
ip2dbg(("ip_input_ipsec_process: UDP pkt "
return (B_FALSE);
}
}
/*
* We make the checks as below since we are in the fast path
*/
if (connp->conn_recvif) {
}
/*
* UDP supports IP_RECVPKTINFO option for both v4 and v6
* so the flag passed to ip_add_info is based on IP version
* of connp.
*/
if (connp->conn_ip_recvpktinfo) {
if (connp->conn_af_isv6) {
/*
* V6 only needs index
*/
in_flags |= IPF_RECVIF;
} else {
/*
* V4 needs index + matching address.
*/
in_flags |= IPF_RECVADDR;
}
}
if (connp->conn_recvslla) {
in_flags |= IPF_RECVSLLA;
}
/*
* since in_flags are being set ill will be
* referenced in ip_add_info, so it better not
* be NULL.
*/
/*
* the actual data will be contained in b_cont
* upon successful return of the following call.
* If the call fails then the original mblk is
* returned.
*/
ipst);
}
return (B_TRUE);
}
/*
* 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 B_TRUE if successful else B_FALSE;
* frees mp on failure.
*/
static boolean_t
{
uint16_t ident;
*cksum_val = 0;
if (cksum_flags != NULL)
*cksum_flags = 0;
/*
* 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 (B_FALSE);
}
/* Check for fragmentation offset; return if there's none */
(IPH_MF | IPH_OFFSET)) == 0)
return (B_TRUE);
/*
* We utilize hardware computed checksum info only for UDP since
* IP fragmentation is a normal occurence 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 (B_FALSE);
}
/* 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.
*/
}
}
/* 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 (B_FALSE);
}
/* 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 (B_FALSE);
}
/*
* Too many fragmented packets in this hash
* bucket. Free the oldest.
*/
}
/* New guy. Allocate a frag message. */
return (B_FALSE);
}
/* 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 (B_FALSE);
}
return (B_FALSE);
}
}
/* We're now complete, zip the frag state */
/* Record the ECN info. */
/* Reassembly is successful; return checksum information if needed */
if (cksum_flags != NULL)
*cksum_flags = sum_flags;
return (B_TRUE);
}
/*
* Perform ip header check sum update local options.
* return B_TRUE if all is well, else return B_FALSE and release
* the mp. caller is responsible for decrementing ire ref cnt.
*/
static boolean_t
{
/*
* processing.
*/
if (!mctl_present) {
if (sum != 0) {
} else {
}
return (B_FALSE);
}
}
if (mctl_present)
return (B_FALSE);
}
return (B_TRUE);
}
/*
* All udp packet are delivered to the local host via this routine.
*/
void
{
uint16_t reass_hck_flags = 0;
/*
* FAST PATH for udp packets
*/
/* u1 is # words of IP options */
/* IP options present */
if (u1 != 0)
goto ipoptions;
/* Check the IP header checksum. */
/* Clear the IP header h/w cksum flag */
} else {
/* finish doing IP checksum */
/*
* Don't verify header checksum if this packet is coming
*/
return;
}
}
/*
* Count for SNMP of inbound packets for ire.
* if mctl is present this might be a secure packet and
* has already been counted for in ip_proto_input().
*/
if (!mctl_present) {
}
/* packet part of fragmented IP packet? */
goto fragmented;
}
/* u1 = IP header length (20 bytes) */
/* packet does not contain complete IP & UDP headers */
goto udppullup;
/* up points to UDP header */
/* if udp hdr cksum != 0, then need to checksum udp packet */
if (up[3] != 0) {
/* Pseudo-header checksum */
/*
* Revert to software checksum calculation if the interface
* isn't capable of checksum offload or if IPsec is present.
*/
if (cksum_err) {
if (hck_flags & HCK_FULLCKSUM)
else if (hck_flags & HCK_PARTIALCKSUM)
else
return;
}
}
/* Non-fragmented broadcast or multicast packet? */
goto udpslowpath;
if (CONN_UDP_FLOWCTLD(connp)) {
} else {
if (!mctl_present) {
}
/*
* mp and first_mp can change.
*/
/* Send it upstream */
}
}
/*
* freeb() cannot deal with null mblk being passed
* in and first_mp can be set to null in the call
* ipsec_input_fast_proc()->ipsec_check_inbound_policy.
*/
}
return;
}
/*
* if we got here we know the packet is not fragmented and
* has no options. The classifier could not find a conn_t and
* most likely its an icmp packet so send it through slow path.
*/
goto udpslowpath;
goto slow_done;
}
/*
* "sum" and "reass_hck_flags" are non-zero if the
* reassembled packet has a valid hardware computed
* checksum information associated with it.
*/
goto slow_done;
/*
* Make sure that first_mp points back to mp as
* the mp we came in with could have changed in
* ip_rput_fragment().
*/
}
/* Now we have a complete datagram, destined for this machine. */
/* Pull up the UDP header, if necessary. */
goto slow_done;
}
}
/*
* Validate the checksum for the reassembled packet; for the
* pullup case we calculate the payload checksum in software.
*/
if (up[3] != 0) {
if (cksum_err) {
if (reass_hck_flags & HCK_FULLCKSUM)
else if (reass_hck_flags & HCK_PARTIALCKSUM)
else
goto slow_done;
}
}
/* Clear hardware checksum flag to be safe */
DB_CKSUMFLAGS(mp) = 0;
return;
}
/* ARGSUSED */
static mblk_t *
{
int offset;
/*
* FAST PATH for tcp packets
*/
/* u1 is # words of IP options */
/* IP options present */
if (u1) {
goto ipoptions;
} else {
/* Check the IP header checksum. */
/* Clear the IP header h/w cksum flag */
} else {
/* finish doing IP checksum */
/*
* Don't verify header checksum if this packet
*/
goto error;
}
}
}
if (!mctl_present) {
}
/* packet part of fragmented IP packet? */
goto fragmented;
}
/* u1 = IP header length (20 bytes) */
/* does packet contain IP+TCP headers? */
goto tcppullup;
}
/* TCP options present? */
/*
* If options need to be pulled up, then goto tcpoptions.
* otherwise we are still in the fast path
*/
goto tcpoptions;
}
/* multiple mblks of tcp data? */
/* more then two? */
goto multipkttcp;
}
}
/* part of pseudo checksum */
/* TCP datagram length */
#ifdef _BIG_ENDIAN
u1 += IPPROTO_TCP;
#else
#endif
/*
* Revert to software checksum calculation if the interface
* isn't capable of checksum offload or if IPsec is present.
*/
if (cksum_err) {
if (hck_flags & HCK_FULLCKSUM)
else if (hck_flags & HCK_PARTIALCKSUM)
else
goto error;
}
/* Send the TH_RST */
goto no_conn;
}
/*
* TCP FAST PATH for AF_INET socket.
*
* TCP fast path to avoid extra work. An AF_INET socket type
* does not have facility to receive extra information via
* ip_process or ip_add_info. Also, when the connection was
* established, we made a check if this connection is impacted
* by any global IPSec policy or per connection policy (a
* policy that comes in effect later will not apply to this
* connection). Since all this can be determined at the
* connection establishment time, a quick check of flags
* can avoid extra work.
*/
return (mp);
}
if (IPCL_IS_TCP(connp)) {
DB_CKSUMSTART(mp) =
return (mp);
connp);
return (mp);
}
}
}
/* No need to send this packet to TCP */
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (NULL);
}
if (mctl_present) {
} else {
}
} else {
/*
* Discard first_mp early since we're dealing with a
* fully-connected conn_t and tcp doesn't do policy in
* this case.
*/
if (mctl_present) {
}
}
}
/* Initiate IPPF processing for fastpath */
ip2dbg(("ip_input_ipsec_process: TCP pkt "
if (mctl_present)
return (NULL);
} else if (mctl_present) {
/*
* ip_process might return a new mp.
*/
} else {
}
}
/*
* TCP does not support IP_RECVPKTINFO for v4 so lets
* make sure IPF_RECVIF is passed to ip_add_info.
*/
if (mctl_present)
return (NULL);
} else if (mctl_present) {
/*
* ip_add_info might return a new mp.
*/
} else {
}
}
if (IPCL_IS_TCP(connp)) {
return (first_mp);
} else {
return (NULL);
}
/* Initiate IPPf processing, if needed. */
return (NULL);
}
}
return (NULL);
goto slow_done;
}
if (mctl_present)
goto slow_done;
}
/*
* Make sure that first_mp points back to mp as
* the mp we came in with could have changed in
* ip_rput_fragment().
*/
}
/* Now we have a complete datagram, destined for this machine. */
/* Pull up a minimal TCP header, if necessary. */
goto error;
}
}
/*
* Extract the offset field from the TCP header. As usual, we
* try to help the compiler more than the reader.
*/
if (offset != 5) {
if (offset < 5) {
goto error;
}
/*
* There must be TCP options.
* Make sure we can grab them.
*/
offset <<= 2;
goto error;
}
}
}
/* Get the total packet length in len, including headers. */
}
/*
* Check the TCP checksum by pulling together the pseudo-
* header checksum, and passing it to ip_csum to be added in
* with the TCP datagram.
*
* Since we are not using the hwcksum if available we must
* clear the flag. We may come here via tcppullup or tcpoptions.
* If either of these fails along the way the mblk is freed.
* If this logic ever changes and mblk is reused to say send
* ICMP's back, then this flag may need to be cleared in
* other places as well.
*/
DB_CKSUMFLAGS(mp) = 0;
#ifdef _BIG_ENDIAN
u1 += IPPROTO_TCP;
#else
#endif
/*
* Not M_DATA mblk or its a dup, so do the checksum now.
*/
goto error;
}
goto try_again;
return (NULL);
}
/* ARGSUSED */
static void
{
/* u1 is # words of IP options */
/* IP options present */
if (u1 > 0) {
goto ipoptions;
} else {
/* Check the IP header checksum. */
/* finish doing IP checksum */
/*
* Don't verify header checksum if this packet
*/
goto error;
}
}
/*
* Since there is no SCTP h/w cksum support yet, just
* clear the flag.
*/
DB_CKSUMFLAGS(mp) = 0;
}
/*
* Don't verify header checksum if this packet is coming
*/
if (!mctl_present) {
}
/* packet part of fragmented IP packet? */
goto fragmented;
/* u1 = IP header length (20 bytes) */
/* Pullup if we don't have the sctp common header. */
goto error;
}
}
#ifdef DEBUG
if (!skip_sctp_cksum) {
#endif
goto error;
}
#ifdef DEBUG /* skip_sctp_cksum */
}
#endif
/* get the ports */
/* Check for raw socket or OOTB handling */
goto no_conn;
}
/* Found a client; up it goes */
return;
return;
DB_CKSUMFLAGS(mp) = 0;
goto slow_done;
goto slow_done;
/*
* Make sure that first_mp points back to mp as
* the mp we came in with could have changed in
* ip_rput_fragment().
*/
}
/* Now we have a complete datagram, destined for this machine. */
goto find_sctp_client;
}
#define VER_BITS 0xF0
#define VERSION_6 0x60
static boolean_t
{
/* Assume no IPv6 packets arrive over the IPv4 queue */
return (B_FALSE);
}
/* multiple mblk or too short */
/* Get the number of words of IP options in the IP header. */
if (opt_len) {
/* IP Options present! Validate and process. */
goto done;
}
/*
* Recompute complete header length and make sure we
* have access to all of it.
*/
goto done;
}
goto done;
}
}
/*
* Go off to ip_rput_options which returns the next hop
* destination address, which may have been affected
* by source routing.
*/
return (B_FALSE);
}
}
return (B_TRUE);
done:
/* clear b_prev - used by ip_mroute_decap */
return (B_FALSE);
}
/*
* Deal with the fact that there is no ire for the destination.
* The incoming ill (in_ill) is passed in to ip_newroute only
* in the case of packets coming from mobile ip forward tunnel.
* It must be null otherwise.
*/
static ire_t *
{
/*
* No IRE for this destination, so it can't be for us.
* Unless we are forwarding, drop the packet.
* We have to let source routed packets through
* since we don't yet know if they are 'ping -l'
* packets i.e. if they will go out over the
* same interface as they came in on.
*/
if (ll_multicast) {
return (NULL);
}
return (NULL);
}
/*
* Mark this packet as having originated externally.
*
* For non-forwarding code path, ire_send later double
* checks this interface to see if it is still exists
* post-ARP resolution.
*
* Also, IPQOS uses this to differentiate between
* IPP_FWD_OUT and IPP_LOCAL_OUT for post-ARP
* QOS packet processing in ip_wput_attach_llhdr().
* The QoS module can mark the b_band for a fastpath message
* or the dl_priority field in a unitdata_req header for
* CoS marking. This info can only be found in
* ip_wput_attach_llhdr().
*/
/*
* Clear the indication that this may have a hardware checksum
* as we are not using it
*/
DB_CKSUMFLAGS(mp) = 0;
/*
* Now hand the packet to ip_newroute.
*/
return (NULL);
}
/* Let ip_newroute handle CGTP */
return (NULL);
}
return (ire);
/* send icmp unreachable */
q = WR(q);
/* Sent by forwarding path, and router is global zone */
} else {
ipst);
}
return (NULL);
}
/*
* check ip header length and align it.
*/
static boolean_t
{
else
/* Guard against bogus device drivers */
if (len < 0) {
/* clear b_prev - used by ip_mroute_decap */
return (B_FALSE);
}
if (ip_rput_pullups++ == 0) {
"ip_check_and_align_header: %s forced us to "
" pullup pkt, hdr len %ld, hdr addr %p",
}
/* clear b_prev - used by ip_mroute_decap */
return (B_FALSE);
}
}
return (B_TRUE);
}
ire_t *
{
/*
* This packet came in on an interface other than the one associated
* with the first ire we found for the destination address. We do
* another ire lookup here, using the ingress ill, to see if the
* interface is in an interface 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. Note, the same holds true
* for 'usesrc groups' where the destination address may belong to
* another interface to allow multipathing to happen.
* 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 cache 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 interface 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.
*/
} else {
}
return (ire);
/*
* The best match could have been the original ire which
* was created against an IRE_LOCAL on lo0. In the IPv4 case
* the strict multihoming checks are irrelevant as we consider
* local addresses hosted on lo0 to be interface agnostic. We
* only expect a null ire_rfq on IREs which are associated with
* lo0 hence we can return now.
*/
return (ire);
}
/*
* Chase pointers once and store locally.
*/
/*
* Check if it's a legal address on the 'usesrc' interface.
*/
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);
ILLF_ROUTER) != 0) {
return (ire);
}
return (NULL);
}
ire_t *
{
/*
* Martian Address Filtering [RFC 1812, Section 5.3.7]
* The loopback address check for both src and dst has already
* been checked in ip_input
*/
goto drop;
}
goto drop;
}
/* No ire cache of nexthop. So first create one */
/*
* We only come to ip_fast_forward if ip_cgtp_filter is
* is not set. So upon return from ire_forward
* check_multirt should remain as false.
*/
/* An attempt was made to forward the packet */
/* send icmp unreachable */
/* Sent by forwarding path, and router is global zone */
ipst);
} else {
ipst);
}
return (ire);
}
}
/*
* Forwarding fastpath exception case:
* If either of the follwoing case is true, we take
* the slowpath
* o forwarding is not enabled
* o incoming and outgoing interface are the same, or the same
* IPMP group
* o corresponding ire is in incomplete state
* o packet needs fragmentation
*
* The codeflow from here on is thus:
* ip_rput_process_forward->ip_rput_forward->ip_xmit_v4
*/
return (ire);
}
goto drop;
/* Adjust the checksum to reflect the ttl decrement. */
goto indiscard;
}
mp);
goto drop;
pkt_len);
return (ire);
}
}
drop:
return (ire);
}
/*
* This function is called in the forwarding slowpath, when
* either the ire lacks the link-layer address, or the packet needs
* further processing(eg. fragmentation), before transmission.
*/
static void
{
if (ll_multicast != 0) {
goto drop_pkt;
}
/*
* check if ipha_src is a broadcast address. Note that this
* check is redundant when we get here from ip_fast_forward()
* which has already done this check. However, since we can
* also get here from ip_rput_process_broadcast() or, for
* for the slow path through ip_fast_forward(), we perform
* the check again for code-reusability
*/
ip2dbg(("ip_rput_process_forward: Received packet with"
goto drop_pkt;
}
/*
* Check if we want to forward this one at this time.
* We allow source routed packets on a host provided that
* they go out the same interface or same interface group
* as they came in on.
*
* XXX To be quicker, we may wish to not chase pointers to
* get the ILLF_ROUTER flag and instead store the
* forwarding policy in the ire. An unfortunate
* side-effect of that would be requiring an ire flush
* whenever the ILLF_ROUTER flag changes.
*/
ILLF_ROUTER) == 0) &&
q = WR(q);
/*
* Clear the indication that this may have
* hardware checksum as we are not using it.
*/
DB_CKSUMFLAGS(mp) = 0;
/* Sent by forwarding path, and router is global zone */
icmp_unreachable(q, mp,
return;
}
goto drop_pkt;
}
/* Packet is being forwarded. Turning off hwcksum flag. */
DB_CKSUMFLAGS(mp) = 0;
if (ipst->ips_ip_g_send_redirects) {
/*
* Check whether the incoming interface and outgoing
* interface is part of the same group. If so,
* send redirects.
*
* 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., ipha_dst is the same
* as ire_gateway_addr or the ire_addr of the
* nexthop IRE_CACHE ), or if the packet was source
* routed out this interface.
*/
/*
* Check whether ire_rfq and q are from the same ill
* or if they are not same, they at least belong
* to the same group. If so, send redirects.
*/
/*
* 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.
*/
goto sendit;
}
/*
* We look up the interface ire for the nexthop,
* to see if ipha_src is in the same subnet
* as the nexthop.
*
* Note that, if, in the future, IRE_CACHE entries
* are obsoleted, this lookup will not be needed,
* as the ire passed to this function will be the
* same as the nhop_ire computed below.
*/
/*
* The source is directly connected.
* Just copy the ip header (which is
* in the first mblk)
*/
}
}
}
}
}
return;
}
return;
ip2dbg(("ip_rput_process_forward: drop pkt\n"));
}
ire_t *
{
queue_t *q;
q = *qp;
/*
* Clear the indication that this may have hardware
* checksum as we are not using it for forwarding.
*/
DB_CKSUMFLAGS(mp) = 0;
/*
* Directed broadcast forwarding: if the packet came in over a
* different interface then it is routed out over we can forward it.
*/
return (NULL);
}
/*
* For multicast we have set dst to be INADDR_BROADCAST
* for delivering to all STREAMS. IRE_MARK_NORECV is really
* only for broadcast packets.
*/
/*
* For ill groups, as the switch duplicates broadcasts
* across all the ports, we need to filter out and
* send up only one copy. There is one copy for every
* broadcast address on each ill. Thus, we look for a
* specific IRE on this ill and look at IRE_MARK_NORECV
* later to see whether this ill is eligible to receive
* them or not. ill_nominate_bcast_rcv() nominates only
* one set of IREs for receiving.
*/
return (NULL);
}
return (NULL);
}
/*
* In the special case of multirouted broadcast
* packets, we unconditionally need to "gateway"
* them to the appropriate interface here.
* In the normal case, this cannot happen, because
* there is no broadcast IRE tagged with the
* RTF_MULTIRT flag.
*/
*qp = q;
}
} else {
}
} else if (cgtp_flt_pkt == CGTP_IP_PKT_NOT_CGTP) {
if (!ipst->ips_ip_g_forward_directed_bcast) {
/*
* Free the message if
* ip_g_forward_directed_bcast is turned
* off for non-local broadcast.
*/
return (NULL);
}
} else {
/*
* This CGTP packet successfully passed the
* CGTP filter, but the related CGTP
* broadcast IRE has not been found,
* meaning that the redundant ipif is
* probably down. However, if we discarded
* this packet, its duplicate would be
* filtered out by the CGTP filter so none
* of them would get through. So we keep
* going with this one.
*/
*qp = q;
}
}
}
/*
* Verify that there are not more then one
* IRE_BROADCAST with this broadcast address which
* has ire_stq set.
* TODO: simplify, loop over all IRE's
*/
int num_stq = 0;
/* Find the first one with ire_stq set */
;
if (ire1) {
}
/* Check if there are additional ones with stq set */
break;
num_stq++;
break;
}
}
ip1dbg(("ip_rput_process_broadcast: directed "
"broadcast to 0x%x\n",
if (mp1) {
switch (ipha->ipha_protocol) {
case IPPROTO_UDP:
break;
default:
break;
}
}
/*
* Adjust ttl to 2 (1+1 - the forward engine
* will decrement it by one.
*/
if (ip_csum_hdr(ipha)) {
ip2dbg(("ip_rput_broadcast:drop pkt\n"));
return (NULL);
}
ipha->ipha_hdr_checksum = 0;
ill, ll_multicast);
return (NULL);
}
ip1dbg(("ip_rput: NO directed broadcast to 0x%x\n",
}
/* Restore any hardware checksum flags */
return (ire);
}
/* ARGSUSED */
static boolean_t
{
/*
* Forward packets only if we have joined the allmulti
* group on this interface.
*/
int retval;
/*
* Clear the indication that this may have hardware
* checksum as we are not using it.
*/
DB_CKSUMFLAGS(mp) = 0;
/* ip_mforward updates mib variables if needed */
/* clear b_prev - used by ip_mroute_decap */
switch (retval) {
case 0:
/*
* pkt is okay and arrived on phyint.
*
* If we are running as a multicast router
*/
goto done;
}
break;
case -1:
/* pkt is mal-formed, toss it */
goto drop_pkt;
case 1:
/* pkt is okay and arrived on a tunnel */
/*
* If we are running a multicast router
* we need to see all igmp packets.
*/
*dstp = INADDR_BROADCAST;
*ll_multicast = 1;
return (B_FALSE);
}
goto drop_pkt;
}
}
/*
* This might just be caused by the fact that
* multiple IP Multicast addresses map to the same
* link layer multicast - no need to increment counter!
*/
return (B_TRUE);
}
done:
/*
* This assumes the we deliver to all streams for multicast
* and broadcast packets.
*/
*dstp = INADDR_BROADCAST;
*ll_multicast = 1;
return (B_FALSE);
ip2dbg(("ip_rput: drop pkt\n"));
return (B_TRUE);
}
static boolean_t
{
/*
* if db_ref > 1 then copymsg and free original. Packet may be
* changed and do not want other entity who has a reference to this
* message to trip over the changes. This is a blind change because
* trying to catch all places that might change packet is too
* difficult (since it may be a module above this one)
*
* This corresponds to the non-fast path case. We walk down the full
* chain in this case, and check the db_ref count of all the dblks,
* and do a copymsg if required. It is possible that the db_ref counts
* of the data blocks in the mblk chain can be different.
* For Example, we can get a DL_UNITDATA_IND(M_PROTO) with a db_ref
* count of 1, followed by a M_DATA block with a ref count of 2, if
* 'snoop' is running.
*/
break;
}
}
if (must_copy) {
}
} else {
}
return (B_TRUE);
}
/* Copy b_prev - used by ip_mroute_decap */
}
}
/*
* previous code has a case for M_DATA.
* We want to check how that happens.
*/
case M_PROTO:
case M_PCPROTO:
/* Go handle anything other than data elsewhere. */
ip_rput_dlpi(q, mp);
return (B_TRUE);
}
/* Ditch the DLPI header. */
return (B_FALSE);
case M_IOCACK:
ip1dbg(("got iocack "));
case DL_IOC_HDR_INFO:
return (B_TRUE);
case SIOCSTUNPARAM:
case OSIOCSTUNPARAM:
/* Go through qwriter_ip */
break;
case SIOCGTUNPARAM:
case OSIOCGTUNPARAM:
return (B_TRUE);
default:
return (B_TRUE);
}
/* FALLTHRU */
case M_ERROR:
case M_HANGUP:
/*
* Since this is on the ill stream we unconditionally
* bump up the refcount
*/
B_FALSE);
return (B_TRUE);
case M_CTL:
IPHADA_M_CTL)) {
/*
* It's an IPsec accelerated packet.
* Make sure that the ill from which we received the
* packet has enabled IPsec hardware acceleration.
*/
if (!(ill->ill_capabilities &
(ILL_CAPAB_AH|ILL_CAPAB_ESP))) {
/* IPsec kstats: bean counter */
return (B_TRUE);
}
/*
* Make mp point to the mblk following the M_CTL,
* then process according to type of mp.
* After this processing, first_mp will point to
* the data-attributes and mp to the pkt following
* the M_CTL.
*/
return (B_TRUE);
}
/*
* A Hardware Accelerated packet can only be M_DATA
* ESP or AH packet.
*/
/* non-M_DATA IPsec accelerated packet */
("non-M_DATA IPsec accelerated pkt\n"));
return (B_TRUE);
}
("non-M_DATA IPsec accelerated pkt\n"));
return (B_TRUE);
}
return (B_FALSE);
}
return (B_TRUE);
case M_FLUSH:
return (B_TRUE);
}
return (B_TRUE);
case M_IOCNAK:
ip1dbg(("got iocnak "));
case DL_IOC_HDR_INFO:
case SIOCSTUNPARAM:
case OSIOCSTUNPARAM:
/*
* Since this is on the ill stream we unconditionally
* bump up the refcount
*/
return (B_TRUE);
case SIOCGTUNPARAM:
case OSIOCGTUNPARAM:
return (B_TRUE);
default:
break;
}
/* FALLTHRU */
default:
return (B_TRUE);
}
}
/* Read side put procedure. Packets coming from the wire arrive here. */
void
{
union DL_primitives *dl;
/*
* Things are opening or closing. Only accept DLPI control
* messages. In the open case, the ill->ill_ipif has not yet
* been created. In the close case, things hanging off the
* ill could have been freed already. In either case it
* may not be safe to proceed further.
*/
/*
* Also SIOC[GS]TUN* ioctls can come here.
*/
"ip_input_end: q %p (%S)", q, "uninit");
return;
}
}
/*
* if db_ref > 1 then copymsg and free original. Packet may be
* changed and we do not want the other entity who has a reference to
* this message to trip over the changes. This is a blind change because
* trying to catch all places that might change the packet is too
* difficult.
*
* This corresponds to the fast path case, where we have a chain of
* M_DATA mblks. We check the db_ref count of only the 1st data block
* in the mblk chain. There doesn't seem to be a reason why a device
* driver would send up data with varying db_ref counts in the mblk
* chain. In any case the Fast path is a private interface, and our
* drivers don't do such a thing. Given the above assumption, there is
* no need to walk down the entire mblk chain (which could have a
* potential performance problem)
*/
/*
* The IP_RECVSLLA option depends on having the link layer
* header. First check that:
* a> the underlying device is of type ether, since this
* option is currently supported only over ethernet.
* b> there is enough room to copy over the link layer header.
*
* Once the checks are done, adjust rptr so that the link layer
* header will be copied via copymsg. Note that, IFT_ETHER may
* be returned by some non-ethernet drivers but in this case the
* second check will fail.
*/
sizeof (struct ether_header)) {
}
/* clear b_prev - used by ip_mroute_decap */
"ip_rput_end: q %p (%S)", q, "copymsg");
return;
}
if (adjusted) {
/*
* Copy is done. Restore the pointer in the _new_ mblk
*/
}
/* Copy b_prev - used by ip_mroute_decap */
}
"ip_rput_end: q %p (%S)", q, "end");
}
/*
* Direct read side procedure capable of dealing with chains. GLDv3 based
* drivers call this function directly with mblk chains while STREAMS
* read side procedure ip_rput() calls this for single packet with ip_ring
* set to NULL to process one packet at a time.
*
* The ill will always be valid if this function is called directly from
* the driver.
*
* If ip_input() is called from GLDv3:
*
* - This must be a non-VLAN IP stream.
* - 'mp' is either an untagged or a special priority-tagged packet.
* - Any VLAN tag that was in the MAC header has been stripped.
*
* If the IP header in packet is not 32-bit aligned, every message in the
* chain will be aligned before further operations. This is required on SPARC
* platform.
*/
/* ARGSUSED */
void
struct mac_header_info_s *mhip)
{
int ll_multicast;
int cgtp_flt_pkt;
int cnt = 0;
ll_multicast = 0;
/*
* We do ire caching from one iteration to
* another. In the event the packet chain contains
* all packets from the same dst, this caching saves
* an ire_cache_lookup for each of the succeeding
* packets in a packet chain.
*/
/*
* Check and align the IP header.
*/
} else {
}
/*
* IP header ptr not aligned?
* OR IP header not complete in first mblk
*/
continue;
}
}
/*
* ip_input fast path
*/
/* mblk type is not M_DATA */
&ll_multicast, &mp))
continue;
}
/* Make sure its an M_DATA and that its aligned */
/*
* We must count all incoming packets, even if they end
* up being dropped later on.
*/
/* multiple mblk or too short */
if (len != 0) {
/*
* Make sure we have data length consistent
* with the IP header.
*/
ip2dbg(("ip_input: drop pkt\n"));
continue;
}
ip2dbg(("ip_input: drop pkt\n"));
continue;
}
}
}
/* Obtain the dst of the current packet */
if (IP_LOOPBACK_ADDR(dst) ||
continue;
}
/*
* The event for packets being received from a 'physical'
* destination address as being local so that packets can be
* redirected to loopback addresses using ipnat.
*/
continue;
}
/*
* Attach any necessary label information to
* this packet
*/
if (is_system_labeled() &&
continue;
}
/*
* Reuse the cached ire only if the ipha_dst of the previous
* packet is the same as the current packet AND it is not
* INADDR_ANY.
*/
}
/*
* Check to see if we can take the fastpath.
* That is possible if the following conditions are met
* o Tsol disabled
* o CGTP disabled
* o ipp_action_count is 0
* o Mobile IP not running
* o no options in the packet
* o not a RSVP packet
* o not a multicast packet
*/
if (!is_system_labeled() &&
!ip_cgtp_filter && ipp_action_count == 0 &&
ipst);
/* incoming packet is for forwarding */
continue;
}
/* incoming packet is for local consumption */
goto local;
}
/*
* Disable ire caching for anything more complex
* than the simple fast path case we checked for above.
*/
}
/* Full-blown slow path */
if (opt_len != 0) {
if (len != 0)
else
continue;
}
/*
* Invoke the CGTP (multirouting) filtering module to process
* the incoming packet. Packets identified as duplicates
* must be discarded. Filtering is active only if the
* the ip_cgtp_filter ndd variable is non-zero.
*
* Only applies to the shared stack since the filter_ops
* do not carry an ip_stack_t or zoneid.
*/
if (cgtp_flt_pkt == CGTP_IP_PKT_DUPLICATE) {
continue;
}
}
/*
* If rsvpd is running, let RSVP daemon handle its processing
* If rsvpd is not running but mrouted is running, RSVP
* multicast packets are forwarded as multicast traffic
* and RSVP unicast packets are forwarded by unicast router.
* If neither rsvpd nor mrouted is running, RSVP multicast
* packets are not forwarded, but the unicast packets are
* forwarded like unicast traffic.
*/
NULL) {
/* RSVP packet and rsvpd running. Treat as ours */
/*
* This assumes that we deliver to all streams for
* multicast and broadcast packets.
* We have to force ll_multicast to 1 to handle the
* M_DATA messages passed in from ip_mroute_decap.
*/
ll_multicast = 1;
/* packet is multicast */
&ll_multicast, &dst))
continue;
}
/*
* Check if the packet is coming from the Mobile IP
* forward tunnel interface
*/
if (ill->ill_srcif_refcnt > 0) {
/* We need to resolve the link layer info */
ll_multicast, dst);
continue;
}
}
}
/*
* If mipagent is running and reverse tunnel is created as per
* mobile node request, then any packet coming through the
* incoming interface from the mobile-node, should be reverse
* tunneled to it's home agent except those that are destined
* to foreign agent only.
* This needs source address based ire lookup. The routing
* entries for source address based lookup are only created by
* mipagent program only when a reverse tunnel is created.
* Reference : RFC2002, RFC2344
*/
if (ill->ill_mrtun_refcnt > 0) {
/*
* Should not be getting iphada packet
* here. we should only get those for
* IRE_LOCAL traffic, excluded above.
* Fail-safe (drop packet) in the event
* hardware is misbehaving.
*/
/* IPsec KSTATS: beancount me */
} else {
/*
* This packet must be forwarded
* to Reverse Tunnel
*/
}
}
"ip_input_end: q %p (%S)",
q, "uninit");
continue;
}
}
/*
* If this packet is from a non-mobilenode or a
* mobile-node which does not request reverse
* tunnel service
*/
}
/*
* If we reach here that means the incoming packet satisfies
* one of the following conditions:
* - packet is from a mobile node which does not request
* reverse tunnel
* - packet is from a non-mobile node, which is the most
* common case
* - packet is from a reverse tunnel enabled mobile node
* and destined to foreign agent only
*/
/*
* No IRE for this destination, so it can't be for us.
* Unless we are forwarding, drop the packet.
* We have to let source routed packets through
* since we don't yet know if they are 'ping -l'
* packets i.e. if they will go out over the
* same interface as they came in on.
*/
continue;
}
/*
* Broadcast IRE may indicate either broadcast or
* multicast packet
*/
/*
* Skip broadcast checks if packet is UDP multicast;
* we'd rather not enter ip_rput_process_broadcast()
* unless the packet is broadcast for real, since
* that routine is a no-op for multicast.
*/
continue;
}
/* fowarding? */
/* ip_rput_process_forward consumed the packet */
continue;
}
/*
* If the queue in the ire is different to the ingress queue
* then we need to check to see if we can accept the packet.
* Note that for multicast packets and broadcast packets sent
* to a broadcast address which is shared between multiple
* interfaces we should not do this since we just got a random
* broadcast ire.
*/
/* Drop packet */
continue;
}
}
switch (ipha->ipha_protocol) {
case IPPROTO_TCP:
cnt++;
cnt++;
} else {
/*
* A different squeue. Send the
* chain for the previous squeue on
* its way. This shouldn't happen
* often unless interrupt binding
* changes.
*/
cnt = 1;
}
}
continue;
case IPPROTO_UDP:
continue;
case IPPROTO_SCTP:
q, dst);
/* ire has been released by ip_sctp_input */
continue;
default:
continue;
}
}
/*
*
* Its possible that after being in polling mode (and having cleared
* the backlog), squeues have turned the interrupt frequency higher
* to improve latency at the expense of more CPU utilization (less
* packets per interrupts or more number of interrupts). Workloads
* but for the remaining time, stay in higher interrupt mode since
* their packet arrival rate is pretty uniform and this shows up
* as higher CPU utilization. Since people care about CPU utilization
*/
}
}
"ip_input_end: q %p (%S)", q, "end");
}
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"));
switch (dloa->dl_primitive) {
case DL_ERROR_ACK:
ip2dbg(("ip_rput_dlpi(%s): DL_ERROR_ACK %s (0x%x): "
dlea->dl_unix_errno));
switch (dlea->dl_error_primitive) {
case DL_UNBIND_REQ:
/* FALLTHRU */
case DL_NOTIFY_REQ:
case DL_ATTACH_REQ:
case DL_DETACH_REQ:
case DL_INFO_REQ:
case DL_BIND_REQ:
case DL_ENABMULTI_REQ:
case DL_PHYS_ADDR_REQ:
case DL_CAPABILITY_REQ:
case DL_CONTROL_REQ:
/*
* Refhold the ill to match qwriter_ip which does a
* refrele. Since this is on the ill stream we
* unconditionally bump up the refcount without
* checking for ILL_CAN_LOOKUP
*/
return;
case DL_DISABMULTI_REQ:
return;
default:
break;
}
return;
case DL_INFO_ACK:
case DL_BIND_ACK:
case DL_PHYS_ADDR_ACK:
case DL_NOTIFY_ACK:
case DL_CAPABILITY_ACK:
case DL_CONTROL_ACK:
/*
* Refhold the ill to match qwriter_ip which does a refrele
* Since this is on the ill stream we unconditionally
* bump up the refcount without doing ILL_CAN_LOOKUP.
*/
return;
case DL_NOTIFY_IND:
/*
* The DL_NOTIFY_IND is an asynchronous message that has no
* relation to the current ioctl in progress (if any). Hence we
* pass in NEW_OP in this case.
*/
return;
case DL_OK_ACK:
ip1dbg(("ip_rput: DL_OK_ACK for %s\n",
switch (dloa->dl_correct_primitive) {
case DL_UNBIND_REQ:
/* FALLTHRU */
case DL_ATTACH_REQ:
case DL_DETACH_REQ:
/*
* Refhold the ill to match qwriter_ip which does a
* refrele. Since this is on the ill stream we
* unconditionally bump up the refcount
*/
return;
case DL_ENABMULTI_REQ:
break;
}
break;
default:
break;
}
}
/*
* Handling of DLPI messages that require exclusive access to the ipsq.
*
* Need to do ill_pending_mp_release on ioctl completion, which could
* happen here. (along with mi_copy_done)
*/
/* ARGSUSED */
static void
{
int err = 0;
ip1dbg(("ip_rput_dlpi_writer .."));
/*
* ipsq_pending_mp and ipsq_pending_ipif track each other. i.e.
* both are null or non-null. However we can assert that only
* after grabbing the ipsq_lock. So we don't make any assertion
* here and in other places in the code.
*/
/*
* 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:
switch (dlea->dl_error_primitive) {
case DL_UNBIND_REQ:
case DL_ATTACH_REQ:
case DL_DETACH_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 operation (SIOCSLIFFLAGS) must have
* happened from a conn.
*/
q = CONNP_TO_WQ(connp);
if (ill->ill_move_in_progress) {
}
/* error is set below the switch */
}
break;
case DL_ENABMULTI_REQ:
ip1dbg(("DL_ERROR_ACK to enabmulti\n"));
printf("ip: joining multicasts failed (%d)"
" on %s - will use link layer "
"broadcasts for multicast\n",
/*
* Set up the multicast mapping alone.
* writer, so ok to access ill->ill_ipif
* without any lock.
*/
(void) ipif_arp_setup_multicast(ipif,
NULL);
} else {
(void) ipif_ndp_setup_multicast(ipif,
NULL);
}
}
return;
case DL_CAPABILITY_REQ:
case DL_CONTROL_REQ:
ip1dbg(("ip_rput_dlpi_writer: got DL_ERROR_ACK for "
"DL_CAPABILITY/CONTROL 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: {
/* Call a routine to handle this one. */
/*
* Check if the ACK is due to renegotiation case since we
* will need to send a new CAPABILITY_REQ later.
*/
/* This is the ack for a renogiation case */
reneg_flag = B_TRUE;
}
if (reneg_flag)
break;
}
case DL_CONTROL_ACK:
/* We treat all of these as "fire and forget" */
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;
/*
* Because mp1 was added by ill_dl_up(), and it always
* passes a valid connp, connp must be valid here.
*/
q = CONNP_TO_WQ(connp);
/*
* We are exclusive. So nothing can change even after
* we get the pending mp. If need be we can put it back
* and restart, as in calling ipif_arp_up() below.
*/
ip2dbg(("ip_rput_dlpi_writer: unexpected nic event %d "
}
info->hne_datalen = 0;
} else
ip2dbg(("ip_rput_dlpi_writer: could not attach UP nic "
"event information for %s (ENOMEM)\n",
/*
* 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. Except in the case of
* ILLF_XRESOLV, in which case we send an
* AR_INTERFACE_UP to the external resolver.
* If all goes well, the ioctl will complete
* in ip_rput(). If there's an error, we
* complete it here.
*/
if (err == 0) {
if (success) {
if (err == EINPROGRESS) {
return;
}
&connp);
} else {
/* conn has started closing */
}
} else { /* Non XRESOLV interface */
(void) ipif_resolver_up(ipif,
}
}
/*
* 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 (ill->ill_up_ipifs) {
}
break;
case DL_NOTIFY_IND: {
switch (notify->dl_notification) {
case DL_NOTE_PHYS_ADDR:
break;
case DL_NOTE_FASTPATH_FLUSH:
break;
case DL_NOTE_SDU_SIZE:
/*
* Change the MTU size of the interface, of all
* attached ipif's, and of all relevant ire's. The
* new value's a uint32_t at notify->dl_data.
* Mtu change Vs. new ire creation - protocol below.
*
* a Mark the ipif as IPIF_CHANGING.
* b Set the new mtu in the ipif.
* c Change the ire_max_frag on all affected ires
* d Unmark the IPIF_CHANGING
*
* To see how the protocol works, assume an interface
* route is also being added simultaneously by
* ip_rt_add and let 'ipif' be the ipif referenced by
* the ire. If the ire is created before step a,
* it will be cleaned up by step c. If the ire is
* created after step d, it will see the new value of
* ipif_mtu. Any attempt to create the ire between
* steps a to d will fail because of the IPIF_CHANGING
* flag. Note that ire_create() is passed a pointer to
* the ipif_mtu, and not the value. During ire_add
* under the bucket lock, the ire_max_frag of the
* which it is being derived.
*/
/*
* If an SIOCSLIFLNKINFO has changed the ill_max_mtu
* leave it alone
*/
if (ill->ill_mtu_userspecified) {
break;
}
} else {
}
/*
* Don't override the mtu if the user
* has explicitly set it.
*/
continue;
else
}
else
}
}
if (need_ire_walk_v4)
if (need_ire_walk_v6)
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:
"got a DL_NOTE_PROMISC_ON_PHYS\n"));
break;
case DL_NOTE_PROMISC_OFF_PHYS:
"got a DL_NOTE_PROMISC_OFF_PHYS\n"));
break;
case DL_NOTE_CAPAB_RENEG:
/*
* Something changed on the driver side.
* It wants us to renegotiate the capabilities
* on this ill. The most likely cause is the
* aggregation interface under us where a
* port got added or went away.
*
* We reset the capabilities and set the
* state to IDS_RENG so that when the ack
* comes back, we can start the
* renegotiation process.
*/
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;
}
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 is zero, the DLPI provider doesn't support
* physical addresses. The other two tests were historical
* workarounds for bugs in our former PPP implementation, but
* now other things have grown dependencies on them -- e.g.,
* the tun module specifies a dl_addr_length of zero in its
* DL_BIND_ACK, but then specifies an incorrect value in its
* DL_PHYS_ADDR_ACK. These bogus checks need to be removed,
* but only after careful testing ensures that all dependent
* broken DLPI providers have been fixed.
*/
ip0dbg(("DL_PHYS_ADDR_ACK: got addrlen %d, expected %d",
break;
}
break;
}
}
/*
* Set the interface token. If the zeroth interface address
* is unspecified, then set it to the link local address.
*/
(void) ill_setdefaulttoken(ill);
(void) ipif_setlinklocal(ipif);
}
break;
}
case DL_OK_ACK:
ip2dbg(("DL_OK_ACK %s (0x%x)\n",
switch (dloa->dl_correct_primitive) {
case DL_UNBIND_REQ:
case DL_ATTACH_REQ:
case DL_DETACH_REQ:
break;
}
break;
default:
break;
}
/*
* The operation must complete without EINPROGRESS
* since ipsq_pending_mp_get() has removed the mblk
* from ipsq_pending_mp. Otherwise, the operation
* will be stuck forever in the ipsq.
*/
switch (ipsq->ipsq_current_ioctl) {
case 0:
break;
case SIOCLIFADDIF:
case SIOCSLIFNAME:
break;
default:
break;
}
}
}
/*
* ip_rput_other is called by ip_rput to handle messages modifying the global
* state in IP. Normally called as writer. Exception SIOCGTUNPARAM (shared)
*/
/* ARGSUSED */
void
{
ip1dbg(("ip_rput_other "));
/*
* This routine is not a writer in the case of SIOCGTUNPARAM
* in which case ipsq is NULL.
*/
}
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_IOCACK:
case SIOCSTUNPARAM:
case OSIOCSTUNPARAM:
/*
* Finish socket ioctl passed through to tun.
* We should have an IOCTL waiting on this.
*/
/*
* if a source or destination is
* being set, try and set the link
* local address for the tunnel
*/
}
}
/*
* mi code for the mi_copy* functions.
* See ip_sioctl_tunparam() for the reason.
* Also protect against missing b_cont.
*/
}
} else {
}
break;
case SIOCGTUNPARAM:
case OSIOCGTUNPARAM:
/*
* This is really M_IOCDATA from the tunnel driver.
* convert back and complete the ioctl.
* We should have an IOCTL waiting on this.
*/
if (mp1) {
/*
* mi code for the mi_copy* functions.
* See ip_sioctl_tunparam() for the reason.
* Also protect against missing b_cont.
*/
}
} else {
}
break;
default:
break;
}
break;
case M_IOCNAK:
int mode;
case DL_IOC_HDR_INFO:
/*
* If this was the first attempt turn of the
* fastpath probing.
*/
ip1dbg(("ip_rput: DLPI fastpath off on "
"interface %s\n",
} else {
}
break;
case SIOCSTUNPARAM:
case OSIOCSTUNPARAM:
/*
* Finish socket ioctl passed through to tun
* We should have an IOCTL waiting on this.
*/
/* FALLTHRU */
case SIOCGTUNPARAM:
case OSIOCGTUNPARAM:
/*
* This is really M_IOCDATA from the tunnel driver.
* convert back and complete the ioctl.
* We should have an IOCTL waiting on this.
*/
} else {
mode = NO_COPYOUT;
}
/*
* mi code for the mi_copy* functions.
* See ip_sioctl_tunparam() for the reason.
* Also protect against missing b_cont.
*/
}
} else {
}
break;
default:
break;
}
default:
break;
}
}
/*
* NOTE : This function does not ire_refrele the ire argument passed in.
*
* IPQoS notes
* IP policy is invoked twice for a forwarded packet, once on the read side
* and again on the write side if both, IPP_FWD_IN and IPP_FWD_OUT are
* enabled. An additional parameter, in_ill, has been added for this purpose.
* Note that in_ill could be NULL when called from ip_rput_forward_multicast
* because ip_mroute drops this information.
*
*/
void
{
queue_t *q;
/* Get the ill_index of the incoming ILL */
/* Initiate Read side IPPF processing */
"during IPPF processing\n"));
return;
}
}
/* Adjust the checksum to reflect the ttl decrement. */
if (ip_csum_hdr(ipha)) {
goto drop_pkt;
}
/*
* Note: ire_stq this will be NULL for multicast
* datagrams using the long path through arp (the IRE
* is not an IRE_CACHE). This should not cause
* problems since we don't generate ICMP errors for
* multicast packets.
*/
if (q != NULL) {
/* Sent by forwarding path, and router is global zone */
} else
return;
}
/*
* Don't forward if the interface is down
*/
ip2dbg(("ip_rput_forward:interface is down\n"));
goto drop_pkt;
}
/* Get the ill_index of the outgoing ILL */
return;
if (is_system_labeled()) {
goto drop_pkt;
}
/* Size may have changed */
}
/* Check if there are options to update */
if (!IS_SIMPLE_IPH(ipha)) {
if (ip_csum_hdr(ipha)) {
goto drop_pkt;
}
return;
}
ipha->ipha_hdr_checksum = 0;
}
/*
* It needs fragging on its way out. We haven't
* verified the header checksum yet. Since we
* are going to put a surely good checksum in the
* outgoing header, we have to make sure that it
* was good coming in.
*/
if (ip_csum_hdr(ipha)) {
goto drop_pkt;
}
/* Initiate Write side IPPF processing */
" during IPPF processing\n"));
return;
}
}
ip2dbg(("ip_rput_forward:sent to ip_wput_frag\n"));
return;
}
return;
ip1dbg(("ip_rput_forward: Calling ip_xmit_v4\n"));
/* ip_xmit_v4 always consumes the packet */
return;
drop_pkt:;
ip1dbg(("ip_rput_forward: drop pkt\n"));
}
void
{
/*
* Find an IRE which matches the destination and the outgoing
* queue in the cache table. All we need is an IRE_CACHE which
* is pointing at ipif->ipif_ill. If it is part of some ill group,
* then it is enough to have some IRE_CACHE in the group.
*/
/*
* Mark this packet to make it be delivered to
* ip_rput_forward after the new ire has been
* created.
*/
} else {
}
}
/* Update any source route, record route or timestamp options */
static int
{
ip2dbg(("ip_rput_forward_options\n"));
ip2dbg(("ip_rput_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) {
/*
* Sent by forwarding path, and router
* is global zone
*/
} else {
ip0dbg(("ip_rput_forward_options: "
"unable to send unreach\n"));
}
return (-1);
}
/*
* Must be partial since ip_rput_options
* checked for strict.
*/
break;
}
off--;
if (optlen < IP_ADDR_LEN ||
/* End of source route */
ip1dbg((
"ip_rput_forward_options: end of SR\n"));
break;
}
ip1dbg(("ip_rput_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_rput_forward_options: end of RR\n"));
break;
}
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_rput_options?\n");
return (0); /* 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;
}
}
return (0);
}
/*
*
* NOTE: the ill corresponding to ipsec_in_ill_index may not be
* the actual, physical interface on which the packet was received,
* but, when ip_strict_dst_multihoming is set to 1, could be the
* interface which had the ipha_dst configured when the packet went
* through ip_rput. The ill_index corresponding to the recv_ill
* is saved in ipsec_in_rill_index
*/
void
{
ipsec_in_t *ii;
netstack_t *ns;
/*
* We need to get the original queue on which ip_rput_local
* or ip_rput_data_v6 was called.
*/
} else {
}
ip0dbg(("ip_fanout_proto_again: interface "
"disappeared\n"));
return;
}
}
/*
* removing their headers. Fanout again till
* it gets to the right protocol.
*/
if (ii->ipsec_in_v4) {
int iph_hdr_length;
int hdr_length;
/*
* icmp_inbound_error_fanout may need to do pullupmsg.
* Reset the type to M_DATA.
*/
} else {
int hdr_length;
/* Don't call hdr_length_v6() unless you have to. */
else
/*
* icmp_inbound_error_fanout_v6 may need to do
* pullupmsg. Reset the type to M_DATA.
*/
}
if (ill_need_rele)
if (rill_need_rele)
return;
}
if (ii->ipsec_in_v4) {
/*
* Multicast has to be delivered to all streams.
*/
}
if (ill_need_rele)
if (rill_need_rele)
ip1dbg(("ip_fanout_proto_again: "
"IRE not found"));
return;
}
}
switch (ipha->ipha_protocol) {
case IPPROTO_UDP:
recv_ill);
if (ire_need_rele)
break;
case IPPROTO_TCP:
if (!ire_need_rele)
break;
case IPPROTO_SCTP:
if (!ire_need_rele)
break;
default:
recv_ill);
if (ire_need_rele)
break;
}
} else {
uint32_t rput_flags = 0;
/*
* XXX Assumes ip_rput_v6 sets ll_multicast only for multicast
* address.
*
* Currently, we don't store that state in the IPSEC_IN
* message, and we may need to.
*/
IP6_IN_LLMCAST : 0);
}
if (ill_need_rele)
if (rill_need_rele)
}
/*
* 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;
}
/*
* 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) {
/*
* 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;
}
}
/*
* This routine is needed for loopback when forwarding multicasts.
*
* IPQoS Notes:
* IPPF processing is done in fanout routines.
* Policy processing is done only if IPP_lOCAL_IN is enabled. Further,
* processing for IPSec packets is done when it comes back in clear.
* NOTE : The callers of this function need to do the ire_refrele for the
* ire that is being passed in.
*/
void
{
int hdr_length;
"ip_rput_locl_start: q %p", q);
/*
* no UDP or TCP packet should come here anymore.
*/
if (mctl_present &&
/*
* It's an IPsec accelerated packet.
* Keep a pointer to the data attributes around until
* we allocate the ipsec_info_t.
*/
("ip_rput_local: inbound HW accelerated IPsec pkt\n"));
/*
* Since it is accelerated, it comes directly from
* the ill and the data attributes is followed by
* the packet data.
*/
}
/*
* IF M_CTL is not present, then ipsec_in_is_secure
* should return B_TRUE. There is a case where loopback
* packets has an M_CTL in the front with all the
* IPSEC options set to IPSEC_PREF_NEVER - which means
* ipsec_in_is_secure will return B_FALSE. As loopback
* packets never comes here, it is safe to ASSERT the
* following.
*/
/* u1 is # words of IP options */
if (u1) {
return;
}
} else {
/* Check the IP header checksum. */
/* finish doing IP checksum */
/*
* Don't verify header checksum if this packet is coming
*/
goto drop_pkt;
}
}
/*
* Count for SNMP of inbound packets for ire. As ip_proto_input
* might be called more than once for secure packets, count only
* the first time.
*/
if (!mctl_present) {
}
/* Check for fragmentation offset. */
if (u1) {
/*
* processing. Thus, M_CTL should not be present
* while we are re-assembling.
*/
return;
}
/*
* Make sure that first_mp points back to mp as
* the mp we came in with could have changed in
* ip_rput_fragment().
*/
}
/*
* Clear hardware checksumming flag as it is currently only
* used by TCP and UDP.
*/
DB_CKSUMFLAGS(mp) = 0;
/* Now we have a complete datagram, destined for this machine. */
switch (ipha->ipha_protocol) {
case IPPROTO_ICMP: {
/*
* In the multicast case, applications may have joined
* the group from different zones, so we need to deliver
* the packet to each of them. Loop through the
* multicast memberships structures (ilm) on the receive
* ill and send a copy of the packet up each matching
* one. However, we don't do this for multicasts sent on
* the loopback interface (PHYI_LOOPBACK flag set) as
* they must stay in the sender's zone.
*
* ilm_add_v6() ensures that ilms in the same zone are
* contiguous in the ill_ilm list. We use this property
* to avoid sending duplicates needed when two
* applications in the same zone join the same group on
* different logical interfaces: we ignore the ilm if
* its zoneid is the same as the last matching one.
* In addition, the sending of the packet for
* ire_zoneid is delayed until all of the other ilms
* have been exhausted.
*/
last_zoneid = -1;
continue;
continue;
}
/*
* In the broadcast case, there may be many zones
* which need a copy of the packet delivered to them.
* There is one IRE_BROADCAST per broadcast address
* and per zone; we walk those using a helper function.
* In addition, the sending of the packet for ire is
* delayed until all of the other ires have been
* processed.
*/
continue;
}
}
ire->ire_zoneid);
"ip_rput_locl_end: q %p (%S)", q, "icmp");
return;
}
case IPPROTO_IGMP:
/*
* If we are not willing to accept IGMP packets in clear,
* then check with global policy.
*/
if (ipst->ips_igmp_accept_clear_messages == 0) {
return;
}
ip1dbg(("ip_proto_input: zone all cannot accept raw"));
return;
}
/* Bad packet - discarded by igmp_input */
"ip_rput_locl_end: q %p (%S)", q, "igmp");
if (mctl_present)
return;
}
/*
* igmp_input() may have returned the pulled up message.
* So first_mp and ipha need to be reinitialized.
*/
if (mctl_present)
else
connf_head != NULL) {
/* No user-level listener for IGMP packets */
goto drop_pkt;
}
/* deliver to local raw users */
break;
case IPPROTO_PIM:
/*
* If we are not willing to accept PIM packets in clear,
* then check with global policy.
*/
if (ipst->ips_pim_accept_clear_messages == 0) {
return;
}
ip1dbg(("ip_proto_input: zone all cannot accept PIM"));
return;
}
/* Bad packet - discarded by pim_input */
"ip_rput_locl_end: q %p (%S)", q, "pim");
if (mctl_present)
return;
}
/*
* pim_input() may have pulled up the message so ipha needs to
* be reinitialized.
*/
connf_head != NULL) {
/* No user-level listener for PIM packets */
goto drop_pkt;
}
/* deliver to local raw users */
break;
case IPPROTO_ENCAP:
/*
* Handle self-encapsulated packets (IP-in-IP where
* the inner addresses == the outer addresses).
*/
return;
}
}
/*
* Check the sanity of the inner IP header.
*/
return;
}
return;
}
ipsec_in_t *ii;
/*
* Self-encapsulated tunnel packet. Remove
* the outer IP header and fanout again.
* We also need to make sure that the inner
* header is pulled up until options.
*/
ipha = inner_ipha;
return;
}
}
if (!mctl_present) {
/*
* This means that somebody is sending
* allocated the first_mp.
*/
ipst->ips_netstack);
ip1dbg(("ip_proto_input: IPSEC_IN "
"allocation failure.\n"));
return;
}
}
/*
* We generally store the ill_index if we need to
* do IPSEC processing as we lose the ill queue when
* we come back. But in this case, we never should
* have to store the ill_index here as it should have
* been stored previously when we processed the
* cases, we still have the queue. But for some bad
* packets from the wire, we can get to IPSEC after
* this and we better store the index for that case.
*/
if (ii->ipsec_in_decaps) {
/*
* This packet is self-encapsulated multiple
* times. We don't want to recurse infinitely.
* To keep it simple, drop the packet.
*/
return;
}
ire);
return;
}
break;
case IPPROTO_AH:
case IPPROTO_ESP: {
/*
* a IPSEC_IN message and prepend it. Otherwise,
* just fanout.
*/
int ipsec_rc;
ipsec_in_t *ii;
if (!mctl_present) {
ip1dbg(("ip_proto_input: IPSEC_IN "
"allocation failure.\n"));
return;
}
/*
* Store the ill_index so that when we come back
* from IPSEC we ride on the same queue.
*/
/*
* Cache hardware acceleration info.
*/
("ip_rput_local: caching data attr.\n"));
}
} else {
}
if (!ipsec_loaded(ipss)) {
return;
}
/* select inbound SA and have IPsec process the pkt */
return;
} else {
return;
}
switch (ipsec_rc) {
case IPSEC_STATUS_SUCCESS:
break;
case IPSEC_STATUS_FAILED:
/* FALLTHRU */
case IPSEC_STATUS_PENDING:
return;
}
/* we're done with IPsec processing, send it up */
return;
}
default:
break;
}
ip1dbg(("ip_proto_input: zone %d cannot accept raw IP",
ire->ire_zoneid));
goto drop_pkt;
}
/*
* 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, each one gets a copy
* of any incoming packets.
*/
"ip_rput_locl_end: q %p (%S)", q, "ip_fanout_proto");
return;
"ip_rput_locl_end: q %p (%S)", q, "droppkt");
}
/*
* 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_rput_options().
*/
static boolean_t
{
ip2dbg(("ip_rput_local_options\n"));
ip2dbg(("ip_rput_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_rput_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_rput_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_rput_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 */
ipst);
/* 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_rput_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:
/* FALLTHRU */
case IPOPT_TS_TSONLY:
/* Compute # of milliseconds since midnight */
gethrestime(&now);
break;
}
break;
}
}
return (B_TRUE);
q = WR(q);
else
/* make sure we clear any indication of a hardware checksum */
DB_CKSUMFLAGS(mp) = 0;
else
return (B_FALSE);
}
/*
* Process IP options in an inbound packet. If an option affects the
* effective destination address, return the next hop address via dstp.
* Returns -1 if something fails in which case an ICMP error has been sent
* and mp freed.
*/
static int
{
ip2dbg(("ip_rput_options\n"));
ip2dbg(("ip_rput_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_rput_options: not next"
" strict source route 0x%x\n",
(char *)ipha;
goto param_prob; /* RouterReq's */
}
ip2dbg(("ip_rput_options: "
"not next source route 0x%x\n",
break;
}
ip1dbg((
"ip_rput_options: bad option offset\n"));
(char *)ipha;
goto param_prob;
}
off--;
if (optlen < IP_ADDR_LEN ||
/* End of source route */
ip1dbg(("ip_rput_options: end of SR\n"));
break;
}
ip1dbg(("ip_rput_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_rput_options: loopback addr in "
"source route!\n"));
goto bad_src_route;
}
/*
* For strict: verify that dst is directly
* reachable.
*/
if (optval == IPOPT_SSRR) {
ip1dbg(("ip_rput_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_rput_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_rput_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_rput_options: error processing IP options."));
q = WR(q);
else
/* make sure we clear any indication of a hardware checksum */
DB_CKSUMFLAGS(mp) = 0;
/* Don't know whether this is for non-global or global/forwarding */
else
return (-1);
q = WR(q);
else
/* make sure we clear any indication of a hardware checksum */
DB_CKSUMFLAGS(mp) = 0;
else
return (-1);
}
/*
* 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) [filled in by the arp module]
* - 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 Neighbor Cache entries
* - ipv6AddrEntry all IPv6 ipifs
* - ipv6 multicast membership (ipv6_member_t)
* - ipv6 multicast source filtering (ipv6_grpsrc_t)
*
* MIB2_IP_MEDIA is filled in by the arp module with ARP cache entries.
*
* 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);
}
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",
}
/* 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;
(void) ipif_get_name(ipif,
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;
(void) ipif_get_name(ipif,
/* 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)];
continue; /* not this zone */
(void) ipif_get_name(ipif,
continue;
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 */
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)];
continue; /* not this zone */
(void) ipif_get_name(ipif,
continue;
if (!IN6_IS_ADDR_V4MAPPED(
continue;
(int)sizeof (ips)) == 0) {
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 */
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 (zoneid == GLOBAL_ZONEID) {
/*
* Those IREs are used by Mobile-IP; since mipagent(1M)
* requires the sys_net_config or sys_ip_config privilege,
* it can only run in the global zone or an exclusive-IP zone,
* and both those have a conn_zoneid == GLOBAL_ZONEID.
*/
}
/* 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);
}
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 "
"%u bytes\n",
}
}
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
{
int i;
return;
sacnt = 1;
}
/* do nothing if there's no gc to report */
/* we might as well drop the lock now */
}
}
}
if (sacnt != 0 &&
return;
}
/*
* Return all IRE types for route table... let caller pick and choose
*/
ill->ill_name_length == 0 ? 0 :
}
else
/* indirect(4), direct(3), or invalid(2) */
else
} else {
}
}
ip1dbg(("ip_snmp_get2_v4: failed to allocate %u bytes\n",
}
}
ip1dbg(("ip_snmp_get2_v4: failed to allocate %u bytes\n",
}
/* bump route index for next pass */
if (sacnt != 0)
}
/*
* ire_walk routine to create ipv6RouteEntryTable and ipRouteEntryTable.
*/
static void
{
int i;
return;
sacnt = 1;
}
/* do nothing if there's no gc to report */
/* we might as well drop the lock now */
}
}
}
if (sacnt != 0 &&
return;
}
/*
* Return all IRE types for route table... let caller pick and choose
*/
ill->ill_name_length == 0 ? 0 :
}
else
/* remote(4), local(3), or discard(2) */
else if (IN6_IS_ADDR_UNSPECIFIED(&gw_addr_v6))
else
re->ipv6RoutePolicy = 0;
re->ipv6RouteNextHopRDI = 0;
re->ipv6RouteWeight = 0;
re->ipv6RouteMetric = 0;
} else {
}
ip1dbg(("ip_snmp_get2_v6: failed to allocate %u bytes\n",
}
}
ip1dbg(("ip_snmp_get2_v6: failed to allocate %u bytes\n",
}
/* bump route index for next pass */
if (sacnt != 0)
}
/*
* ndp_walk routine to create ipv6NetToMediaEntryTable
*/
static int
{
return (0);
/*
* Neighbor cache entry attached to IRE with on-link
* destination.
*/
} else {
}
} else {
}
/*
* 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) */
} else {
}
ip1dbg(("ip_snmp_get2_v6_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.
*/
static boolean_t
{
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);
}
/*
* Check if the packet contains any source route.
*/
static boolean_t
{
if (IS_SIMPLE_IPH(ipha))
return (B_FALSE);
switch (optval) {
case IPOPT_SSRR:
case IPOPT_LSRR:
return (B_TRUE);
}
}
return (B_FALSE);
}
/*
* Called when the IRE expiration timer fires.
*/
void
ip_trash_timer_expire(void *args)
{
int flush_flag = 0;
/*
* ip_ire_expire_id is protected by ip_trash_timer_lock.
* This lock makes sure that a new invocation of this function
* that occurs due to an almost immediate timer firing will not
* progress beyond this point until the current invocation is done
*/
ipst->ips_ip_ire_expire_id = 0;
/* Periodic timer */
if (ipst->ips_ip_ire_arp_time_elapsed >=
/*
* Remove all IRE_CACHE entries since they might
* contain arp information.
*/
}
if (ipst->ips_ip_ire_rd_time_elapsed >=
/* Remove all redirects */
}
if (ipst->ips_ip_ire_pmtu_time_elapsed >=
/* Increase path mtu */
}
/*
* Optimize for the case when there are no redirects in the
* ftable, that is, no need to walk the ftable in that case.
*/
}
if ((flush_flag & FLUSH_REDIRECT_TIME) &&
ipst->ips_ip_redirect_cnt > 0) {
}
if (flush_flag & FLUSH_MTU_TIME) {
/*
* Walk all IPv6 IRE's and update them
* Note that ARP and redirect timers are not
* needed since NUD handles stale entries.
*/
}
/*
* Hold the lock to serialize timeout calls and prevent
* stale values in ip_ire_expire_id. Otherwise it is possible
* for the timer to fire and a new invocation of this function
* to start before the return value of timeout has been stored
* in ip_ire_expire_id by the current invocation.
*/
}
/*
* Called by the memory allocator subsystem directly, when the system
* is running low on memory.
*/
/* ARGSUSED */
void
ip_trash_ire_reclaim(void *args)
{
netstack_t *ns;
}
}
static void
{
/*
* Memory reclaim call back.
* Count unused, offlink, pmtu, and onlink IRE_CACHE entries.
* Then, with a target of freeing 1/Nth of IRE_CACHE
* entries, determine what fraction to free for
* each category of IRE_CACHE entries giving absolute priority
* in the order of onlink, pmtu, offlink, unused (e.g. no pmtu
* entry will be freed unless all offlink entries are freed).
*/
icc.icc_unused = 0;
icc.icc_offlink = 0;
icc.icc_onlink = 0;
/*
* Free NCEs for IPv6 like the onlink ires.
*/
if (delete_cnt == 0)
return;
/* Always delete all unused offlink entries */
/*
* Only need to free unused entries. In other words,
* there are enough unused entries to free to meet our
* target number of freed ire cache entries.
*/
/*
* Only need to free unused entries, plus a fraction of offlink
* entries. It follows from the first if statement that
* icc_offlink is non-zero, and that delete_cnt != icc_unused.
*/
/* Round up # deleted by truncating fraction */
} else if (delete_cnt <=
/*
* Free all unused and offlink entries, plus a fraction of
* pmtu entries. It follows from the previous if statement
* that icc_pmtu is non-zero, and that
* delete_cnt != icc_unused + icc_offlink.
*/
/* Round up # deleted by truncating fraction */
icr.icr_onlink = 0;
} else {
/*
* Free all unused, offlink, and pmtu entries, plus a fraction
* of onlink entries. If we're here, then we know that
* icc_onlink is non-zero, and that
* delete_cnt != icc_unused + icc_offlink + icc_pmtu.
*/
/* Round up # deleted by truncating fraction */
/* Using the same delete fraction as for onlink IREs */
}
#ifdef DEBUG
ip1dbg(("IP reclaim: target %d out of %d current %d/%d/%d/%d "
"fractions %d/%d/%d/%d\n",
#endif
#ifdef DEBUG
ip1dbg(("IP reclaim: result total %d %d/%d/%d/%d\n",
#endif
}
/*
* ip_unbind is called when a copy of an unbind request is received from the
* upper level protocol. We remove this conn from any fanout hash list it is
* on, and zero out the bind information. No reply is expected up above.
*/
mblk_t *
{
connp->conn_anon_port = 0;
}
/*
* Convert mp into a T_OK_ACK
*/
/*
* should not happen in practice... T_OK_ACK is smaller than the
* original message.
*/
return (NULL);
/*
* Don't bzero the ports if its TCP since TCP still needs the
* lport to remove it from its own bind hash. TCP will do the
* cleanup.
*/
if (!IPCL_IS_TCP(connp))
return (mp);
}
/*
* Write side put procedure. Outbound data, IOCTLs, responses from
* resolvers, etc, come down through here.
*
* arg2 is always a queue_t *.
* When that queue is an ill_t (i.e. q_next != NULL), then arg must be
* the zoneid.
* When that queue is not an ill_t, then arg must be a conn_t pointer.
*/
void
{
}
void
{
int match_flags;
/* Bind to IPIF_NOFAILOVER ill etc. */
int err;
int adjust;
#ifdef _BIG_ENDIAN
#else
#endif
"ip_wput_start: q %p", q);
/*
* ip_wput fast path
*/
/* is packet from ARP ? */
goto qnext;
}
/* is queue flow controlled? */
return;
}
/* Multidata transmit? */
/*
* We should never get here, since all Multidata messages
* originating from tcp should have been directed over to
* tcp_multisend() in the first place.
*/
return;
goto notdata;
}
/* is IP header non-aligned or mblk smaller than basic IP header */
#ifndef SAFETY_BEFORE_SPEED
goto hdrtoosmall;
#endif
/*
* This function assumes that mp points to an IPv4 packet. If it's the
* wrong version, we'll catch it again in ip_output_v6.
*
* Note that this is *only* locally-generated output here, and never
* forwarded data, and that we need to deal only with transports that
* label.)
*/
if (is_system_labeled() &&
!connp->conn_ulp_labeled) {
if (err != 0) {
goto icmp_parameter_problem;
goto discard_pkt;
}
}
/*
* IP_PKTINFO ancillary option is present.
* IPCL_ZONEID is used to honor IP_ALLZONES option which
* allows using address of any zone as the source address.
*/
goto drop_pkt;
}
/*
* IP_DONTFAILOVER_IF and IP_XMIT_IF have precedence over
* ill index passed in IP_PKTINFO.
*/
if (infop->ip_opt_ill_index != 0 &&
ipst);
goto drop_pkt;
/*
* check that there is an ipif belonging
* to our zone. IPCL_ZONEID is not used because
* IP_ALLZONES option is valid only when the ill is
* accessible from all zones i.e has a valid ipif in
* all zones.
*/
goto drop_pkt;
}
}
/*
* If there is a policy, try to attach an ipsec_out in
* the front. At the end, first_mp either points to a
* M_DATA message or IPSEC_OUT message linked to a
* M_DATA message. We have to do it now as we might
* lose the "conn" if we go through ip_newroute.
*/
if (need_decref)
return;
} else {
}
} else {
}
/* is wrong version or IP options present */
if (V_HLEN != IP_SIMPLE_HDR_VERSION)
goto version_hdrlen_check;
if (err == ILL_LOOKUP_FAILED) {
if (need_decref)
return;
}
}
/* is packet multicast? */
goto multicast;
/*
* If xmit_ill is set above due to index passed in ip_pkt_info. It
* takes precedence over conn_dontroute and conn_nexthop_set
*/
goto send_from_ill;
}
(connp->conn_nexthop_set)) {
/*
* If the destination is a broadcast or a loopback
* address, SO_DONTROUTE, IP_XMIT_IF and IP_NEXTHOP go
* through the standard path. But in the case of local
* destination only SO_DONTROUTE and IP_NEXTHOP go through
* the standard path not IP_XMIT_IF.
*/
if ((connp->conn_dontroute ||
goto standard_path;
/* No more access to ire */
}
/*
* bypass routing checks and go directly to
* interface.
*/
if (connp->conn_dontroute) {
goto dontroute;
} else if (connp->conn_nexthop_set) {
ip_nexthop = B_TRUE;
goto send_from_ill;
}
/*
* If IP_XMIT_IF socket option is set,
* then we allow unicast and multicast
* packets to go through the ill. It is
* quite possible that the destination
* is not in the ire cache table and we
* do not want to go to ip_newroute()
* instead we call ip_newroute_ipif.
*/
if (err == ILL_LOOKUP_FAILED) {
if (attach_ill != NULL)
if (need_decref)
return;
}
goto send_from_ill;
}
/* Must be a broadcast, a loopback or a local ire */
/* No more access to ire */
}
}
if (attach_ill != NULL)
goto send_from_ill;
/*
* We cache IRE_CACHEs to avoid lookups. We don't do
* this for the tcp global queue and listen end point
* as it does not really have a real destination to
* talk to. This is also true for SCTP.
*/
!connp->conn_fully_bound) {
goto noirefound;
"ip_wput_end: q %p (%S)", q, "end");
/*
* Check if the ire has the RTF_MULTIRT flag, inherited
* from an IRE_OFFSUBNET ire entry in ip_newroute().
*/
/*
* Force the TTL of multirouted packets if required.
* The TTL of such packets is bounded by the
* ip_multirt_ttl ndd variable.
*/
if ((ipst->ips_ip_multirt_ttl > 0) &&
ip2dbg(("ip_wput: forcing multirt TTL to %d "
"(was %d), dst 0x%08x\n",
}
/*
* We look at this point if there are pending
* unresolved routes. ire_multirt_resolvable()
* checks in O(n) that all IRE_OFFSUBNET ire
* entries for the packet's destination and
* flagged RTF_MULTIRT are currently resolved.
* If some remain unresolved, we make a copy
* of the current message. It will be used
* to initiate additional route resolutions.
*/
ip2dbg(("ip_wput[TCP]: ire %p, "
"multirt_need_resolve %d, first_mp %p\n",
(void *)ire, multirt_need_resolve,
(void *)first_mp));
if (multirt_need_resolve) {
}
}
}
/*
* Try to resolve another multiroute if
* ire_multirt_need_resolve() deemed it necessary.
*/
}
if (need_decref)
return;
}
/*
* Access to conn_ire_cache. (protected by conn_lock)
*
* IRE_MARK_CONDEMNED is marked in ire_delete. We don't grab
* the ire bucket lock here to check for CONDEMNED as it is okay to
* send a packet or two with the IRE_CACHE that is going away.
* Access to the ire requires an ire refhold on the ire prior to
* its use since an interface unplumb thread may delete the cached
* ire and release the refhold at any time.
*
* Caching an ire in the conn_ire_cache
*
* o Caching an ire pointer in the conn requires a strict check for
* IRE_MARK_CONDEMNED. An interface unplumb thread deletes all relevant
* ires before cleaning up the conns. So the caching of an ire pointer
* in the conn is done after making sure under the bucket lock that the
* ire has not yet been marked CONDEMNED. Otherwise we will end up
* caching an ire after the unplumb thread has cleaned up the conn.
* If the conn does not send a packet subsequently the unplumb thread
* will be hanging waiting for the ire count to drop to zero.
*
* o We also need to atomically test for a null conn_ire_cache and
* set the conn_ire_cache under the the protection of the conn_lock
* to avoid races among concurrent threads trying to simultaneously
* cache an ire in the conn_ire_cache.
*/
} else {
/* Release the old ire */
goto noirefound;
}
}
/*
* We can continue to use the ire but since it was
* not cached, we should drop the extra reference.
*/
if (!cached)
}
"ip_wput_end: q %p (%S)", q, "end");
/*
* Check if the ire has the RTF_MULTIRT flag, inherited
* from an IRE_OFFSUBNET ire entry in ip_newroute().
*/
/*
* Force the TTL of multirouted packets if required.
* The TTL of such packets is bounded by the
* ip_multirt_ttl ndd variable.
*/
if ((ipst->ips_ip_multirt_ttl > 0) &&
ip2dbg(("ip_wput: forcing multirt TTL to %d "
"(was %d), dst 0x%08x\n",
}
/*
* At this point, we check to see if there are any pending
* unresolved routes. ire_multirt_resolvable()
* checks in O(n) that all IRE_OFFSUBNET ire
* entries for the packet's destination and
* flagged RTF_MULTIRT are currently resolved.
* If some remain unresolved, we make a copy
* of the current message. It will be used
* to initiate additional route resolutions.
*/
ip2dbg(("ip_wput[not TCP]: ire %p, "
"multirt_need_resolve %d, first_mp %p\n",
if (multirt_need_resolve) {
}
}
}
/*
* Try to resolve another multiroute if
* ire_multirt_resolvable() deemed it necessary
*/
}
if (need_decref)
return;
/*
* Upper Level Protocols pass down complete IP datagrams
* as M_DATA messages. Everything else is a sideshow.
*
* 1) We could be re-entering ip_wput because of ip_neworute
* in which case we could have a IPSEC_OUT message. We
* need to pass through ip_wput like other datagrams and
* hence cannot branch to ip_wput_nondata.
*
* 2) ARP, AH, ESP, and other clients who are on the module
* instance of IP stream, give us something to deal with.
* We will handle AH and ESP here and rest in ip_wput_nondata.
*
* 3) ICMP replies also could come here.
*/
ipst = ILLQ_TO_IPST(q);
/*
* M_CTL messages are used by ARP, AH and ESP to
* communicate with IP. We deal with IPSEC_IN and
* IPSEC_OUT here. ip_wput_nondata handles other
* cases.
*/
}
/*
* Either this message goes back to
* IPSEC for further processing or to
* ULP after policy checks.
*/
return;
if (io->ipsec_out_proc_begin) {
/*
* IPSEC processing has already started.
* Complete it.
* IPQoS notes: We don't care what is
* in ipsec_out_ill_index since this
* won't be processed for IPQoS policies
* in ipsec_out_process.
*/
return;
} else {
}
/*
* It's an IPsec control message requesting
* an SADB update to be sent to the IPsec
* hardware acceleration capable ills.
*/
ipst->ips_netstack);
return;
} else {
/*
* This must be ARP or special TSOL signaling.
*/
"ip_wput_end: q %p (%S)", q, "nondata");
return;
}
} else {
/*
*/
"ip_wput_end: q %p (%S)", q, "nondata");
return;
}
} else {
}
/*
* ICMP echo replies attach an ipsec_out and set ipsec_out_attach_if
* to make sure that this packet goes out on the same interface it
* came in. We handle that here.
*/
if (mctl_present) {
if (io->ipsec_out_attach_if ||
io->ipsec_out_xmit_if ||
/*
* We may have lost the conn context if we are
* coming here from ip_newroute(). Copy the
* nexthop information.
*/
if (io->ipsec_out_ip_nexthop) {
ip_nexthop = B_TRUE;
goto send_from_ill;
} else {
/*
* ipsec_out_xmit_if bit is used to tell
* ip_wput to use the ill to send outgoing data
* as we have no conn when data comes from ICMP
* error msg routines. Currently this feature is
* only used by ip_mrtun_forward routine.
*/
if (io->ipsec_out_xmit_if) {
ip1dbg(("ip_output:bad ifindex "
"for xmit_ill %d\n",
ifindex));
return;
}
/* Free up the ipsec_out_t mblk */
/* Just send the IP header+ICMP+data */
goto send_from_ill;
} else {
attach_ill = ill;
}
if (attach_ill == NULL) {
ip1dbg(("ip_output: bad ifindex for "
"(BIND TO IPIF_NOFAILOVER) %d\n",
ifindex));
return;
}
}
}
}
/* We have a complete IP datagram heading outbound. */
#ifndef SPEED_BEFORE_SAFETY
/*
* Make sure we have a full-word aligned message and that at least
* a simple IP header is accessible in the first message. If not,
* try a pullup.
*/
"ip_wput_end: q %p (%S)", q, "pullupfailed");
goto discard_pkt;
}
/* This function assumes that mp points to an IPv4 packet. */
!connp->conn_ulp_labeled) {
if (err != 0) {
goto icmp_parameter_problem;
ip2dbg(("ip_wput: label check failed (%d)\n",
err));
goto discard_pkt;
}
}
/*
* If we got here because of "goto hdrtoosmall"
* We need to attach a IPSEC_OUT.
*/
if (connp->conn_out_enforce_policy) {
if (need_decref)
return;
} else {
}
} else {
}
}
}
#endif
/* Most of the code below is written for speed, not readability */
/*
* If ip_newroute() fails, we're going to need a full
* header for the icmp wraparound.
*/
if (V_HLEN != IP_SIMPLE_HDR_VERSION) {
/*
* siphon off IPv6 packets coming down from transport
* layer modules here.
* Note: high-order bit carries NUD reachability confirmation
*/
/*
* XXX implement a IPv4 and IPv6 packet counter per
* conn and switch when ratio exceeds e.g. 10:1
*/
#ifdef notyet
#endif
if (attach_ill != NULL)
if (need_decref)
return;
}
"ip_wput_end: q %p (%S)", q, "badvers");
goto discard_pkt;
}
/*
* Is the header length at least 20 bytes?
*
* Are there enough bytes accessible in the header? If
* not, try a pullup.
*/
v_hlen &= 0xF;
v_hlen <<= 2;
if (v_hlen < IP_SIMPLE_HDR_LENGTH) {
"ip_wput_end: q %p (%S)", q, "badlen");
goto discard_pkt;
}
"ip_wput_end: q %p (%S)", q, "badpullup2");
goto discard_pkt;
}
}
/*
* Move first entry from any source route into ipha_dst and
* verify the options
*/
if (attach_ill != NULL)
"ip_wput_end: q %p (%S)", q, "badopts");
if (need_decref)
return;
}
}
/*
* Try to get an IRE_CACHE for the destination address. If we can't,
* we have to run the packet through ip_newroute which will take
* the appropriate action to arrange for an IRE_CACHE, such as querying
* a resolver, or assigning a default gateway, etc.
*/
ip2dbg(("ip_wput: CLASSD\n"));
/*
* Use the first good ipif on the ill.
* XXX Should this ever happen? (Appears
* to show up with just ppp and no ethernet due
* to in.rdisc.)
* However, ire_send should be able to
* call ip_wput_ire directly.
*
* XXX Also, this can happen for ICMP and other packets
* with multicast source addresses. Perhaps we should
* fix things so that we drop the packet in question,
* but for now, just run with it.
*/
/*
* Don't honor attach_if for this case. If ill
* is part of the group, ipif could belong to
* any ill and we cannot maintain attach_ill
* and ipif_ill same anymore and the assert
* below would fail.
*/
io->ipsec_out_ill_index = 0;
attach_ill = NULL;
}
if (need_decref)
return;
}
ip1dbg(("ip_wput: CLASSD no CONN: dst 0x%x on %s\n",
} else {
/*
* The order of precedence is IP_XMIT_IF, IP_PKTINFO
* and IP_MULTICAST_IF.
* Block comment above this function explains the
* locking mechanism used here
*/
if (err == ILL_LOOKUP_FAILED) {
ip1dbg(("ip_wput: No ill for "
"IP_XMIT_IF\n"));
goto drop_pkt;
}
}
if (err == IPIF_LOOKUP_FAILED) {
ip1dbg(("ip_wput: No ipif for "
"multicast\n"));
goto drop_pkt;
}
}
ip1dbg(("ip_wput: No ipif for "
"IP_XMIT_IF\n"));
goto drop_pkt;
}
/*
* We must do this ipif determination here
* else we could pass through ip_newroute
* and come back here without the conn context.
*
* Note: we do late binding i.e. we bind to
* the interface when the first packet is sent.
* For performance reasons we do not rebind on
* each packet but keep the binding until the
* next IP_MULTICAST_IF option.
*
* conn_multicast_{ipif,ill} are shared between
* IPv4 and IPv6 and AF_INET6 sockets can
* send both IPv4 and IPv6 packets. Hence
* we have to check that "isv6" matches above.
*/
ip1dbg(("ip_wput: No ipif for "
"multicast\n"));
goto drop_pkt;
}
if (err == IPIF_LOOKUP_FAILED) {
ip1dbg(("ip_wput: No ipif for "
"multicast\n"));
goto drop_pkt;
}
}
}
/*
* As we may lose the conn by the time we reach ip_wput_ire,
* we copy conn_multicast_loop and conn_dontroute on to an
* ipsec_out. In case if this datagram goes out secure,
* we need the ill_index also. Copy that also into the
* ipsec_out.
*/
if (mctl_present) {
} else {
goto discard_pkt;
}
/* ipsec_out_secure is B_FALSE now */
}
if (attach_ill != NULL) {
/*
* Check if we need an ire that will not be
* looked up by anybody else i.e. HIDDEN.
*/
if (ill_is_probeonly(attach_ill)) {
}
} else {
}
}
/*
* If the application uses IP_MULTICAST_IF with
* different logical addresses of the same ILL, we
* need to make sure that the soruce address of
* the packet matches the logical IP address used
* in the option. We do it by initializing ipha_src
* here. This should keep IPSEC also happy as
* when we return from IPSEC processing, we don't
* have to worry about getting the right address on
* the packet. Thus it is sufficient to look for
* IRE_CACHE using MATCH_IRE_ILL rathen than
* MATCH_IRE_IPIF.
*
* NOTE : We need to do it for non-secure case also as
* this might go out secure if there is a global policy
* match in ip_wput_ire. For bind to IPIF_NOFAILOVER
* address, the source should be initialized already and
* hence we won't be initializing here.
*
* As we do not have the ire yet, it is possible that
* we set the source address here and then later discover
* that the ire implies the source address to be assigned
* through the RTF_SETSRC flag.
* In that case, the setsrc variable will remind us
* that overwritting the source address by the one
* of the RTF_SETSRC-flagged ire is allowed.
*/
setsrc = RTF_SETSRC;
}
/*
* Find an IRE which matches the destination and the outgoing
* queue (i.e. the outgoing interface.)
* For loopback use a unicast IP address for
* the ire lookup.
*/
}
/*
* If IP_XMIT_IF is set, we branch out to ip_newroute_ipif.
* We don't need to lookup ire in ctable as the packet
* needs to be sent to the destination through the specified
* ill irrespective of ires in the cache table.
*/
}
/*
* refrele attach_ill as its not needed anymore.
*/
if (attach_ill != NULL) {
attach_ill = NULL;
}
/*
* Multicast loopback and multicast forwarding is
* done in ip_wput_ire.
*
* Mark this packet to make it be delivered to
* ip_wput_ire after the new ire has been
* created.
*
* The call to ip_newroute_ipif takes into account
* the setsrc reminder. In any case, we take care
* of the RTF_MULTIRT flag.
*/
xmit_ill->ill_ipif_up_count > 0) {
"ip_wput_end: q %p (%S)", q, "noire");
} else {
}
if (need_decref)
return;
}
/*
* Honor the RTF_SETSRC flag for multicast packets,
* if allowed by the setsrc reminder.
*/
}
/*
* Unconditionally force the TTL to 1 for
* multirouted multicast packets:
* multirouted multicast should not cross
* multicast routers.
*/
ip2dbg(("ip_wput: forcing multicast "
"multirt TTL to 1 (was %d), dst 0x%08x\n",
}
}
} else {
}
}
/*
* Guard against coming in from arp in which case conn is NULL.
* Also guard against non M_DATA with dontroute set but
* destined to local, loopback or broadcast addresses.
*/
!ignore_dontroute) {
/*
* Set TTL to 1 if SO_DONTROUTE is set to prevent
* routing protocols from seeing false direct
* connectivity.
*/
/*
* If IP_XMIT_IF is also set (conn_xmit_if_ill != NULL)
* along with SO_DONTROUTE, higher precedence is
* given to IP_XMIT_IF and the IP_XMIT_IF ipif is used.
*/
/* If suitable ipif not found, drop packet */
ipst);
ip1dbg(("ip_wput: no route for "
"dst using SO_DONTROUTE\n"));
goto drop_pkt;
} else {
/*
* If suitable ipif has been found, set
* xmit_ill to the corresponding
* ipif_ill because we'll be following
* the IP_XMIT_IF logic.
*/
if (!ILL_CAN_LOOKUP(xmit_ill)) {
ip1dbg(("ip_wput: no route for"
" dst using"
" SO_DONTROUTE\n"));
goto drop_pkt;
}
}
}
}
/*
* If we are bound to IPIF_NOFAILOVER address, look for
* an IRE_CACHE matching the ill.
*/
if (attach_ill != NULL) {
/*
* Check if we need an ire that will not be
* looked up by anybody else i.e. HIDDEN.
*/
if (ill_is_probeonly(attach_ill)) {
}
if (attach_ipif == NULL) {
ip1dbg(("ip_wput: No ipif for attach_ill\n"));
goto discard_pkt;
}
/*
* Mark this packet as originated locally
*/
/*
* xmit_ill could be NULL if SO_DONTROUTE
* is also set.
*/
if (err == ILL_LOOKUP_FAILED) {
if (need_decref)
return;
}
if (connp->conn_dontroute)
goto dontroute;
goto send_from_ill;
}
}
/*
* Could be SO_DONTROUTE case also.
* check at least one interface is UP as
* specified by this ILL
*/
if (xmit_ill->ill_ipif_up_count > 0) {
ip1dbg(("ip_output: "
"xmit_ill NULL ipif\n"));
goto drop_pkt;
}
/*
* Look for a ire that is part of the group,
* if found use it else call ip_newroute_ipif.
* IPCL_ZONEID is not used for matching because
* IP_ALLZONES option is valid only when the
* ill is accessible from all zones i.e has a
* valid ipif in all zones.
*/
/*
* If an ire exists use it or else create
* an ire but don't add it to the cache.
* Adding an ire may cause issues with
* asymmetric routing.
* In case of multiroute always act as if
* ire does not exist.
*/
ip1dbg(("ip_wput: ip_unicast_if\n"));
if (need_decref)
return;
}
} else {
goto drop_pkt;
}
if (!ip_nexthop) {
ip_nexthop = B_TRUE;
}
} else {
ipst);
}
if (!ire) {
/*
* Make sure we don't load spread if this
* is IPIF_NOFAILOVER case.
*/
if ((attach_ill != NULL) ||
(ip_nexthop && !ignore_nexthop)) {
if (mctl_present) {
M_CTL);
} else {
sizeof (ipsec_info_t), BPRI_HI);
goto discard_pkt;
}
sizeof (ipsec_info_t);
/* ipsec_out_secure is B_FALSE now */
sizeof (ipsec_info_t));
io->ipsec_out_len =
sizeof (ipsec_out_t);
}
if (attach_ill != NULL) {
} else {
}
}
/*
* Mark this packet as having originated on
* this machine. This will be noted in
* ire_add_then_send, which needs to know
* whether to run it back through ip_wput or
* ip_rput following successful resolution.
*/
ipst);
"ip_wput_end: q %p (%S)", q, "newroute");
if (attach_ill != NULL)
if (need_decref)
return;
}
}
/* We now know where we are going with it. */
"ip_wput_end: q %p (%S)", q, "end");
/*
* Check if the ire has the RTF_MULTIRT flag, inherited
* from an IRE_OFFSUBNET ire entry in ip_newroute.
*/
/*
* Force the TTL of multirouted packets if required.
* The TTL of such packets is bounded by the
* ip_multirt_ttl ndd variable.
*/
if ((ipst->ips_ip_multirt_ttl > 0) &&
ip2dbg(("ip_wput: forcing multirt TTL to %d "
"(was %d), dst 0x%08x\n",
}
/*
* At this point, we check to see if there are any pending
* unresolved routes. ire_multirt_resolvable()
* checks in O(n) that all IRE_OFFSUBNET ire
* entries for the packet's destination and
* flagged RTF_MULTIRT are currently resolved.
* If some remain unresolved, we make a copy
* of the current message. It will be used
* to initiate additional route resolutions.
*/
ip2dbg(("ip_wput[noirefound]: ire %p, "
"multirt_need_resolve %d, first_mp %p\n",
if (multirt_need_resolve) {
}
}
}
/*
* Try to resolve another multiroute if
* ire_multirt_resolvable() deemed it necessary.
* At this point, we need to distinguish
* multicasts from other packets. For multicasts,
* we call ip_newroute_ipif() and request that both
* multirouting and setsrc flags are checked.
*/
if (ipif) {
} else {
}
} else {
}
}
if (attach_ill != NULL)
if (need_decref)
return;
/* could not have originated externally */
/* it's the IP header length that's in trouble */
}
ip1dbg(("ip_wput: dropped packet\n"));
if (need_decref)
if (attach_ill != NULL)
"ip_wput_end: q %p (%S)", q, "droppkt");
}
/*
* If this is a conn_t queue, then we pass in the conn. This includes the
* zoneid.
* Otherwise, this is a message coming back from ARP or for an ill_t queue,
* in which case we use the global zoneid since those are all part of
* the global zone.
*/
void
{
if (CONN_Q(q))
else
}
/*
*
* The following rules must be observed when accessing any ipif or ill
* that has been cached in the conn. Typically conn_nofailover_ill,
* conn_xmit_if_ill, conn_multicast_ipif and conn_multicast_ill.
*
* Access: The ipif or ill pointed to from the conn can be accessed under
* the protection of the conn_lock or after it has been refheld under the
* protection of the conn lock. In addition the IPIF_CAN_LOOKUP or
* ILL_CAN_LOOKUP macros must be used before actually doing the refhold.
* The reason for this is that a concurrent unplumb could actually be
* cleaning up these cached pointers by walking the conns and might have
* finished cleaning up the conn in question. The macros check that an
* unplumb has not yet started on the ipif or ill.
*
* Caching: An ipif or ill pointer may be cached in the conn only after
* making sure that an unplumb has not started. So the caching is done
* while holding both the conn_lock and the ill_lock and after using the
* ILL_CAN_LOOKUP/IPIF_CAN_LOOKUP macro. An unplumb will set the ILL_CONDEMNED
* flag before starting the cleanup of conns.
*
* The list of ipifs hanging off the ill is protected by ill_g_lock and ill_lock
* On the other hand to access ipif->ipif_ill, we need one of either ill_g_lock
* or a reference to the ipif or a reference to an ire that references the
* the ipif refcnt has gone to zero and holding the ill_g_lock and ill_lock
* the above holds.
*/
ipif_t *
{
*err = 0;
if (IPIF_CAN_LOOKUP(ipif)) {
return (ipif);
} else {
}
}
return (NULL);
}
ill_t *
{
*err = 0;
if (ILL_CAN_LOOKUP(ill)) {
return (ill);
} else {
*err = ILL_LOOKUP_FAILED;
}
}
return (NULL);
}
static int
{
if (IPIF_CAN_LOOKUP(ipif)) {
return (0);
}
return (IPIF_LOOKUP_FAILED);
}
/*
* This is called if the outbound datagram needs fragmentation.
*
* NOTE : This function does not ire_refrele the ire argument passed in.
*/
static void
{
} else {
}
#ifdef _BIG_ENDIAN
#else
#endif
#ifndef SPEED_BEFORE_SAFETY
/*
* Check that ipha_length is consistent with
* the mblk length
*/
ip0dbg(("Packet length mismatch: %d, %ld\n",
"ip_wput_ire_fragmentit: mp %p (%S)", mp,
"packet length mismatch");
return;
}
#endif
/*
* Don't use frag_flag if pre-built packet or source
* routed or if multicast (since multicast packets do not solicit
* ICMP "packet too big" messages). Get the values of
* max_frag and frag_flag atomically by acquiring the
* ire_lock.
*/
(V_HLEN != IP_SIMPLE_HDR_VERSION &&
}
/*
* 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;
if (!io->ipsec_out_secure)
return (0);
a = io->ipsec_out_act;
if (a == NULL) {
}
return (a->ipa_ovhd);
}
/*
* 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;
a = ii->ipsec_in_action;
}
/*
* 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);
}
mblk_t *
{
/*
* ip_wput[_v6] attaches an IPSEC_OUT in two cases.
*
* 1) There is per-socket policy (including cached global
* policy) or a policy on the IP-in-IP tunnel.
* 2) There is no per-socket policy, but it is
* a multicast packet that needs to go out
* on a specific interface. This is the case
* where (ip_wput and ip_wput_multicast) attaches
* an IPSEC_OUT and sets ipsec_out_secure B_FALSE.
*
* In case (2) we check with global policy to
* see if there is a match and set the ill_index
* appropriately so that we can lookup the ire
* properly in ip_wput_ipsec_out.
*/
/*
* ipsec_out_use_global_policy is set to B_FALSE
* in ipsec_in_to_out(). Refer to that function for
* details.
*/
}
if (!io->ipsec_out_secure) {
/*
* If this is not a secure packet, drop
* the IPSEC_OUT mp and treat it as a clear
* packet. This happens when we are sending
* a ICMP reply back to a clear packet. See
* ipsec_in_to_out() for details.
*/
}
return (mp);
}
/*
* See whether we need to attach a global policy here. We
* don't depend on the conn (as it could be null) for deciding
* what policy this datagram should go through because it
* should have happened in ip_wput if there was some
* policy. This normally happens for connections which are not
* fully bound preventing us from caching policies in
* - which are non-hard_bound - could also be affected by
* applying policy here.
*
* If this packet is coming from tcp global queue or listener,
* we will be applying policy here. This may not be *right*
* if these packets are coming from the detached connection as
* it could have gone in clear before. This happens only if a
* TCP connection started when there is no policy and somebody
* added policy before it became detached. Thus packets of the
* detached connection could go out secure and the other end
* would drop it because it will be expecting in clear. The
* converse is not true i.e if somebody starts a TCP
* connection and deletes the policy, all the packets will
* still go out with the policy that existed before deleting
* because ip_unbind sends up policy information which is used
* by TCP on subsequent ip_wputs. The right solution is to fix
* TCP to attach a dummy IPSEC_OUT and set
* ipsec_out_use_global_policy to B_FALSE. As this might
* affect performance for normal cases, we are not doing it.
* Thus, set policy before starting any TCP connections.
*
* NOTE - We might apply policy even for a hard bound connection
* - for which we cached policy in ip_bind - if somebody added
* global policy after we inherited the policy in ip_bind.
* This means that the packets that were going out in clear
* previously would start going secure and hence get dropped
* on the other side. To fix this, TCP attaches a dummy
* ipsec_out and make sure that we don't apply global policy.
*/
else
if (!policy_present)
return (mp);
zoneid));
}
ire_t *
{
int err;
if (err == ILL_LOOKUP_FAILED) {
return (NULL);
}
return (save_ire);
}
/*
* If IP_BOUND_IF has been done, conn_outgoing_ill will be set.
* If it is part of the group, we need to send on the ire
* that has been cleared of IRE_MARK_NORECV and that belongs
* to this group. This is okay as IP_BOUND_IF really means
* any ill in the group. We depend on the fact that the
* first ire in the group is always cleared of IRE_MARK_NORECV
* if such an ire exists. This is possible only if you have
* at least one ill in the group that has not failed.
*
* First get to the ire that matches the address and group.
*
* We don't look for an ire with a matching zoneid because a given zone
* won't always have broadcast ires on all ills in the group.
*/
/*
* If the current zone only has an ire broadcast for this
* address marked NORECV, the ire we want is ahead in the
* bucket, so we look it up deliberately ignoring the zoneid.
*/
continue;
/* skip over deleted ires */
continue;
}
}
/*
* If a new interface is coming up, we could end up
* seeing the loopback ire and the non-loopback ire
* may not have been added yet. So check for ire_stq
*/
break;
}
}
/*
* Refhold the ill to make the conn_outgoing_ill
* independent of the ire. ip_wput_ire goes in a loop
* and may refrele the ire. Since we have an ire at this
* point we don't need to use ILL_CAN_LOOKUP on the ill.
*/
return (ire);
}
ip1dbg(("conn_set_outgoing_ill: No matching ire\n"));
/*
* If we can't find a suitable ire, return the original ire.
*/
return (save_ire);
}
/*
* This function does the ire_refrele of the ire passed in as the
* argument. As this function looks up more ires i.e broadcast ires,
* it needs to REFRELE them. Currently, for simplicity we don't
* differentiate the one passed in and looked up here. We always
* REFRELE.
* IPQoS Notes:
* IP policy is invoked if IPP_LOCAL_OUT is enabled. Processing for
* IPSec packets are done in ipsec_out_process.
*
*/
void
{
int clusterwide;
int ipsec_len;
int err;
"ip_wput_ire_start: q %p", q);
/*
* Multirouting case. The bucket where ire is stored
* probably holds other RTF_MULTIRT flagged ire
* to the destination. In this call to ip_wput_ire,
* we attempt to send the packet through all
* those ires. Thus, we first ensure that ire is the
* first RTF_MULTIRT ire in the bucket,
* before walking the ire list.
*/
/* Make sure we do not omit any multiroute ire. */
break;
}
}
}
/*
* conn_outgoing_ill is used only in the broadcast loop.
* for performance we don't grab the mutexs in the fastpath
*/
/*
* Bind to IPIF_NOFAILOVER address overrides IP_BOUND_IF
* option. So, see if this endpoint is bound to a
* IPIF_NOFAILOVER address. If so, honor it. This implies
* that if the interface is failed, we will still send
* the packet on the same ill which is what we want.
*/
if (err == ILL_LOOKUP_FAILED) {
return;
}
if (conn_outgoing_ill == NULL) {
/*
* Choose a good ill in the group to send the
* packets on.
*/
return;
}
}
}
} else {
/*
* For the multicast case, ipsec_out carries conn_dontroute and
* conn_multicast_loop as conn may not be available here. We
* need this for multicast loopback and forwarding which is done
* later in the code.
*/
/*
* If conn_dontroute is not set or conn_multicast_loop
* is set, we need to do forwarding/loopback. For
* datagrams from ip_wput_multicast, conn_dontroute is
* set to B_TRUE and conn_multicast_loop is set to
* B_FALSE so that we neither do forwarding nor
* loopback.
*/
if (!conn_dontroute || conn_multicast_loop)
}
}
/*
* When a zone sends a packet to another zone, we try to deliver
* the packet under the same conditions as if the destination
* was a real node on the network. To do so, we look for a
* matching route in the forwarding table.
* RTF_REJECT and RTF_BLACKHOLE are handled just like
* ip_newroute() does.
* Note that IRE_LOCAL are special, since they are used
* when the zoneid doesn't match in some cases. This means that
* we need to handle ipha_src differently since ire_src_addr
* belongs to the receiving zone instead of the sending zone.
* When ip_restrict_interzone_loopback is set, then
* ire_cache_lookup() ensures that IRE_LOCAL are only used
* for loopback between zones when the logical "Ethernet" would
* have looped them back.
*/
} else {
if (conn_outgoing_ill != NULL)
return;
}
}
/* Failed */
return;
}
ipst);
return;
}
}
unspec_src, zoneid);
if (conn_outgoing_ill != NULL)
return;
}
}
ipsec_len = 0;
/* We already picked up the zoneid from the M_CTL above */
/*
* Drop M_CTL here if IPsec processing is not needed.
* (Non-IPsec use of M_CTL extracted any information it
* needed above).
*/
if (ipsec_len == 0) {
}
}
/*
* Fast path for ip_wput_ire
*/
/*
* ICMP(RAWIP) module should set the ipha_ident to IP_HDR_INCLUDED
* if the socket is a SOCK_RAW type. The transport checksum should
* be provided in the pre-built packet, so we don't need to compute it.
* Also, other application set flags, like DF, should not be altered.
* Other transport MUST pass down zero.
*/
ip1dbg(("ip_wput_ire: to 0x%x ire %s addr 0x%x\n",
}
/* Macros to extract header fields from data already in registers */
#ifdef _BIG_ENDIAN
#else
#endif
/* (The loop back to "another" is explained down below.) */
another:;
/*
* Assign an ident value for this packet. We assign idents on
* a per destination basis out of the IRE. There could be
* other threads targeting the same destination, so we have to
* arrange for a atomic increment. Note that we use a 32-bit
* atomic add because it has better performance than its
* 16-bit sibling.
*
* If running in cluster mode and if the source address
* belongs to a replicated service then vector through
* cl_inet_ipident vector to allocate ip identifier
* NOTE: This is a contract private interface with the
* clustering group.
*/
clusterwide = 0;
if (cl_inet_ipident) {
if ((*cl_inet_isclusterwide)(IPPROTO_IP,
clusterwide = 1;
}
}
if (!clusterwide) {
ipha->ipha_ident =
}
#ifndef _BIG_ENDIAN
#endif
/*
* Set source address unless sent on an ill or conn_unspec_src is set.
* This is needed to obey conn_unspec_src when packets go through
* ip_newroute + arp.
* Assumes ip_newroute{,_multi} sets the source address as well.
*/
/*
* Assign the appropriate source address from the IRE if none
* was specified.
*/
/*
* With IP multipathing, broadcast packets are sent on the ire
* that has been cleared of IRE_MARK_NORECV and that belongs to
* the group. However, this ire might not be in the same zone so
* we can't always use its source address. We look for a
* broadcast ire in the same group and in the right zone.
*/
} else {
if (conn_outgoing_ill != NULL)
} else {
}
return;
}
} else {
}
ip1dbg(("ip_wput_ire: no connp and no src "
"address for dst 0x%x, using src 0x%x\n",
}
}
/*
* We only allow ire chains for broadcasts since there will
* be multiple IRE_CACHE entries for the same multicast
* address (one per ipif).
*/
/* broadcast packet */
goto broadcast;
/* loopback ? */
goto nullstq;
/* The ill_index for outbound ILL */
/* pseudo checksum (do it in parts for IP header checksum) */
if (!IP_FLOW_CONTROLLED_ULP(PROTO)) {
/* flow controlled */
goto blocked;
if ((PROTO == IPPROTO_UDP) &&
(ip_hdr_included != IP_HDR_INCLUDED)) {
if (*up != 0) {
/* Software checksum? */
if (DB_CKSUMFLAGS(mp) == 0) {
}
}
}
} else if (ip_hdr_included != IP_HDR_INCLUDED) {
if (PROTO == IPPROTO_TCP) {
/*
* The packet header is processed once and for all, even
* in the multirouting case. We disable hardware
* checksum if the packet is multirouted, as it will be
* replicated via several interfaces, and not all of
* them may have this capability.
*/
/* Software checksum? */
if (DB_CKSUMFLAGS(mp) == 0) {
}
} else {
/*
* Zero out the checksum field to ensure proper
* checksum calculation.
*/
#ifdef DEBUG
if (!skip_sctp_cksum)
#endif
}
}
/*
* If this is a multicast packet and originated from ip_wput
* we need to do loopback and forwarding checks. If it comes
* from ip_wput_multicast, we SHOULD not do this.
*/
/* checksum */
cksum += ttl_protocol;
/* fragment the packet */
goto fragmentit;
/*
* Don't use frag_flag if packet is pre-built or source
* routed or if multicast (since multicast packets do
* not solicit ICMP "packet too big" messages).
*/
if ((ip_hdr_included != IP_HDR_INCLUDED) &&
(V_HLEN == IP_SIMPLE_HDR_VERSION ||
!ip_source_route_included(ipha)) &&
/* calculate IP header checksum */
/* IP options present */
if (hlen)
goto checksumoptions;
/* calculate hdr checksum */
}
if (ipsec_len != 0) {
/*
* We will do the rest of the processing after
* we come back from IPSEC in ip_wput_ipsec_out().
*/
if (conn_outgoing_ill != NULL)
return;
}
/*
* In most cases, the emission loop below is entered only
* once. Only in the case where the ire holds the
* RTF_MULTIRT flag, do we loop to process all RTF_MULTIRT
* flagged ires in the bucket, and send the packet
* through all crossed RTF_MULTIRT routes.
*/
}
do {
if (multirt_send) {
/*
* We are in a multiple send case, need to get
* the next ire and make a duplicate of the packet.
* ire1 holds here the next ire to process in the
* bucket. If multirouting is expected,
* any non-RTF_MULTIRT ire that has the
* right destination address is ignored.
*/
continue;
continue;
continue;
/* Got one */
break;
}
}
}
/* Last multiroute ire; don't loop anymore. */
}
}
goto release_ire_and_ill;
if ((pktxmit_state == SEND_FAILED) ||
(pktxmit_state == LLHDR_RESLV_FAILED)) {
ip2dbg(("ip_wput_ire: ip_xmit_v4 failed"
"- packet dropped\n"));
}
if (conn_outgoing_ill != NULL)
return;
}
LENGTH);
}
"ip_wput_ire_end: q %p (%S)",
q, "last copy out");
if (multirt_send) {
/*
* Proceed with the next RTF_MULTIRT ire,
* Also set up the send-to queue accordingly.
*/
}
} while (multirt_send);
if (conn_outgoing_ill != NULL)
return;
/*
* ire->ire_type == IRE_BROADCAST (minimize diffs)
*/
{
/*
* Avoid broadcast storms by setting the ttl to 1
* for broadcasts. This parameter can be set
* via ndd, so make sure that for the SO_DONTROUTE
* case that ipha_ttl is always set to 1.
* In the event that we are replying to incoming
* ICMP packets, conn could be NULL.
*/
else
/*
* Note that we are not doing a IRB_REFHOLD here.
* Actually we don't care if the list changes i.e
* if somebody deletes an IRE from the list while
* we drop the lock, the next time we come around
* ire_next will be NULL and hence we won't send
* out multiple copies which is fine.
*/
if (conn_outgoing_ill != NULL) {
continue;
}
/* Did not find a matching ill */
ip1dbg(("ip_wput_ire: broadcast with no "
"matching IP_BOUND_IF ill %s\n",
return;
}
/*
* If the next IRE has the same address and is not one
* of the two copies that we need to send, try to see
* whether this copy should be sent at all. This
* assumes that we insert loopbacks first and then
* non-loopbacks. This is acheived by inserting the
* loopback always before non-loopback.
* This is used to send a single copy of a broadcast
* packet out all physical interfaces that have an
* matching IRE_BROADCAST while also looping
* back one copy (to ip_wput_local) for each
* matching physical interface. However, we avoid
* sending packets out different logical that match by
* IRE_BROADCASTS.
*
* This feature is currently used to get broadcasts
* sent to multiple interfaces, when the broadcast
* address being used applies to multiple interfaces.
* For example, a whole net broadcast will be
* replicated on every connected subnet of
* the target net.
*
* Each zone has its own set of IRE_BROADCASTs, so that
* we're able to distribute inbound packets to multiple
* zones who share a broadcast address. We avoid looping
* back outbound packets in different zones but on the
* same ill, as the application would see duplicates.
*
* If the interfaces are part of the same group,
* we would want to send only one copy out for
* whole group.
*
* This logic assumes that ire_add_v4() groups the
* IRE_BROADCAST entries so that those with the same
* ire_addr and ill_group are kept together.
*/
/*
* If the current zone only has an ire
* broadcast for this address marked
* NORECV, the ire we want is ahead in
* the bucket, so we look it up
* deliberately ignoring the zoneid.
*/
ire1_ill =
continue;
/* skip over the current ire */
continue;
/* skip over deleted ires */
continue;
/*
* non-loopback ire in our
* group: use it for the next
* pass in the loop
*/
break;
}
}
} else {
/*
* We can have two broadcast ires on the
* same ill in different zones; here
* we'll send a copy of the packet on
* each ill and the fanout code will
* call conn_wantpacket() to check that
* the zone has the broadcast address
* configured on the ill. If the two
* ires are in the same group we only
* send one copy up.
*/
break;
}
}
}
}
/*
* We are in the multirouting case.
* The message must be sent at least
* on both ires. These ires have been
* inserted AFTER the standard ones
* in ip_rt_add(). There are thus no
* other ire entries for the destination
* address in the rest of the bucket
* that do not have the RTF_MULTIRT
* flag. We don't process a copy
* of the message here. This will be
* done in the final sending loop.
*/
} else {
}
}
}
if (stq) {
/*
* A non-NULL send-to queue means this packet is going
* out of this machine.
*/
/*
* We accumulate the pseudo header checksum in cksum.
* This is pretty hairy code, so watch close. One
* thing to keep in mind is that UDP and TCP have
* stored their respective datagram lengths in their
* checksum fields. This lines things up real nice.
*/
/*
* We assume the udp checksum field contains the
* length, so to compute the pseudo header checksum,
*/
/* Provide the checksums for UDP and TCP. */
if ((PROTO == IPPROTO_TCP) &&
(ip_hdr_included != IP_HDR_INCLUDED)) {
/* hlen gets the number of uchar_ts in the IP header */
} else if (PROTO == IPPROTO_SCTP &&
(ip_hdr_included != IP_HDR_INCLUDED)) {
#ifdef DEBUG
if (!skip_sctp_cksum)
#endif
} else {
/*
* If we don't have a conn to apply
* backpressure, free the message.
* In the ire_send path, we don't know
* the position to requeue the packet. Rather
* than reorder packets, we just drop this
* packet.
*/
if (ipst->ips_ip_output_queue &&
first_mp);
/*
* This is the service thread,
* and the queue is already
* noenabled. The check for
* canput and the putbq is not
* atomic. So we need to check
* again.
*/
= 0;
} else {
/*
* We are not the service proc.
* ip_wsrv will be scheduled or
* is already running.
*/
first_mp);
}
} else {
"ip_wput_ire_end: q %p (%S)",
q, "discard");
}
if (next_mp) {
}
if (conn_outgoing_ill != NULL)
return;
}
if ((PROTO == IPPROTO_UDP) &&
(ip_hdr_included != IP_HDR_INCLUDED)) {
/*
* hlen gets the number of uchar_ts in the
* IP header
*/
if (*up != 0) {
/* Software checksum? */
if (DB_CKSUMFLAGS(mp) == 0) {
}
}
}
}
/*
* Need to do this even when fragmenting. The local
* loopback can be done without computing checksums
* but forwarding out other interface must be done
* after the IP checksum (and ULP checksums) have been
* computed.
*
* NOTE : multicast_forward is set only if this packet
* originated from ip_wput. For packets originating from
* ip_wput_multicast, it is not set.
*/
ip2dbg(("ip_wput: multicast, loop %d\n",
/* Forget header checksum offload */
/*
* Local loopback of multicasts? Check the
* ill.
*
* Note that the loopback function will not come
* in through ip_rput - it will only do the
* client fanout thus we need to do an mforward
* as well. The is different from the BSD
* logic.
*/
/*
* Pass along the virtual output q.
* ip_wput_local() will distribute the
* packet to all the matching zones,
* except the sending zone when
* IP_MULTICAST_LOOP is false.
*/
conn_multicast_loop ? 0 :
}
}
/*
* 0 => only to this host i.e. we are
* done. We are also done if this was the
* loopback interface since it is sufficient
* to loopback one copy of a multicast packet.
*/
"ip_wput_ire_end: q %p (%S)",
q, "loopback");
if (conn_outgoing_ill != NULL)
return;
}
/*
* ILLF_MULTICAST is checked in ip_newroute
* i.e. we don't need to check it here since
* all IRE_CACHEs come from ip_newroute.
* For multicast traffic, SO_DONTROUTE is interpreted
* to mean only send the packet out the interface
* (optionally specified with IP_MULTICAST_IF)
* and do not forward it out additional interfaces.
* RSVP and the rsvp daemon is an example of a
* protocol and user level process that
* handles it's own routing. Hence, it uses the
* SO_DONTROUTE option to accomplish this.
*/
/* Unconditionally redo the checksum */
ipha->ipha_hdr_checksum = 0;
/*
* If this needs to go out secure, we need
* to wait till we finish the IPSEC
* processing.
*/
if (ipsec_len == 0 &&
ip1dbg(("ip_wput: mforward failed\n"));
"ip_wput_ire_end: q %p (%S)",
q, "mforward failed");
if (conn_outgoing_ill != NULL)
return;
}
}
}
cksum += ttl_protocol;
/* No fragmentation required for this one. */
/*
* Don't use frag_flag if packet is pre-built or source
* routed or if multicast (since multicast packets do
* not solicit ICMP "packet too big" messages).
*/
if ((ip_hdr_included != IP_HDR_INCLUDED) &&
(V_HLEN == IP_SIMPLE_HDR_VERSION ||
!ip_source_route_included(ipha)) &&
/* Complete the IP header checksum. */
(v_hlen_tos_len & 0xFFFF);
if (hlen) {
/*
* Account for the IP Options in the IP
* header checksum.
*/
do {
up += 2;
} while (--hlen);
}
}
if (ipsec_len != 0) {
if (!next_mp) {
if (conn_outgoing_ill != NULL)
return;
}
goto next;
}
/*
* multirt_send has already been handled
* for broadcast, but not yet for multicast
* or IP options.
*/
}
}
/*
* In most cases, the emission loop below is
* entered only once. Only in the case where
* the ire holds the RTF_MULTIRT flag, do we loop
* to process all RTF_MULTIRT ires in the bucket,
* and send the packet through all crossed
* RTF_MULTIRT routes.
*/
do {
if (multirt_send) {
/*
* We are in a multiple send case,
* need to get the next IRE and make
* a duplicate of the packet.
*/
continue;
continue;
continue;
/* Got one */
break;
}
== NULL))) {
}
}
/*
* Last multiroute ire; don't loop
* anymore. The emission is over
* and next_mp is NULL.
*/
}
}
goto release_ire_and_ill_2;
if ((pktxmit_state == SEND_FAILED) ||
(pktxmit_state == LLHDR_RESLV_FAILED)) {
if (next_mp) {
}
"ip_wput_ire_end: q %p (%S)",
q, "discard MDATA");
if (conn_outgoing_ill != NULL)
return;
}
LENGTH);
}
if (multirt_send) {
/*
* We are in a multiple send case,
* need to re-enter the sending loop
* using the next ire.
*/
}
} while (multirt_send);
if (!next_mp) {
/*
* Last copy going out (the ultra-common
* case). Note that we intentionally replicate
* the putnext rather than calling it before
* the next_mp check in hopes of a little
* tail-call action out of the compiler.
*/
"ip_wput_ire_end: q %p (%S)",
q, "last copy out(1)");
if (conn_outgoing_ill != NULL)
return;
}
/* More copies going out below. */
} else {
int offset;
/*
* If this would generate a icmp_frag_needed message,
* we need to handle it before we do the IPSEC
* processing. Otherwise, we need to strip the IPSEC
* headers before we send up the message to the ULPs
* which becomes messy and difficult.
*/
if (ipsec_len != 0) {
ipha->ipha_hdr_checksum = 0;
if (!next_mp) {
if (conn_outgoing_ill != NULL) {
}
return;
}
} else {
/*
* This won't cause a icmp_frag_needed
* message. to be generated. Send it on
* the wire. Note that this could still
* cause fragmentation and all we
* do is the generation of the message
* to the ULP if needed before IPSEC.
*/
if (!next_mp) {
"ip_wput_ire_end: q %p "
"(%S)", q,
"last ipsec_out_process");
if (conn_outgoing_ill != NULL) {
}
return;
}
}
} else {
/*
* Initiate IPPF processing. For
* fragmentable packets we finish
* all QOS packet processing before
* calling:
* ip_wput_ire_fragmentit->ip_wput_frag
*/
}
"ip_wput_ire: q %p (%S)",
q, "discard MDATA");
if (conn_outgoing_ill != NULL) {
}
return;
}
}
if (!next_mp) {
"ip_wput_ire_end: q %p (%S)",
q, "last fragmentation");
if (conn_outgoing_ill != NULL)
return;
}
}
}
} else {
/* A NULL stq means the destination address is local. */
if (!next_mp) {
/*
* Is there an "in" and "out" for traffic local
* to a host (loopback)? The code in Solaris doesn't
* explicitly draw a line in its code for in vs out,
* so we've had to draw a line in the sand: ip_wput_ire
* is considered to be the "output" side and
* ip_wput_local to be the "input" side.
*/
"ip_wput_ire_end: q %p (%S)",
q, "local address");
if (conn_outgoing_ill != NULL)
return;
}
}
next:
/*
* More copies going out to additional interfaces.
* ire1 has already been held. We don't need the
* "ire" anymore.
*/
if (ipsec_len != 0) {
}
/*
* Restore src so that we will pick up ire->ire_src_addr if src was 0.
* Restore ipha_ident "no checksum" flag.
*/
goto another;
}
/*
* Routine to allocate a message that is used to notify the ULP about MDT.
* The caller may provide a pointer to the link-layer MDT capabilities,
* or NULL if MDT is to be disabled on the stream.
*/
mblk_t *
{
/*
* If the caller provides us with the capability, copy
* it over into our notification message; otherwise
* we zero out the capability portion.
*/
else
}
return (mp);
}
/*
* Routine which determines whether MDT can be enabled on the destination
* IRE and IPC combination, and if so, allocates and returns the MDT
* notification mblk that may be used by ULP. We also check if we need to
* turn MDT back to 'on' when certain restrictions prohibiting us to allow
* MDT usage in the past have been lifted. This gets called during IP
* and ULP binding.
*/
mblk_t *
{
/*
* Currently, we only support simple TCP/{IPv4,IPv6} with
* Multidata, which is handled in tcp_multisend(). This
* is the reason why we do all these checks here, to ensure
* that we don't enable Multidata for the cases which we
* can't handle at the moment.
*/
do {
/* Only do TCP at the moment */
break;
/*
* IPSEC outbound policy present? Note that we get here
* after calling ipsec_conn_cache_policy() where the global
* policy checking is performed. conn_latch will be
* non-NULL as long as there's a policy defined,
* i.e. conn_out_enforce_policy may be NULL in such case
* when the connection is non-secure, and hence we check
* further if the latch refers to an outbound policy.
*/
break;
/* CGTP (multiroute) is enabled? */
break;
/* Outbound IPQoS enabled? */
/*
* In this case, we disable MDT for this and all
* future connections going over the interface.
*/
mdt_cap->ill_mdt_on = 0;
break;
}
/* socket option(s) present? */
if (!CONN_IS_LSO_MD_FASTPATH(connp))
break;
/* CONSTCOND */
} while (0);
/* Remember the result */
if (!rc)
return (NULL);
else if (!mdt_cap->ill_mdt_on) {
/*
* If MDT has been previously turned off in the past, and we
* currently can do MDT (due to IPQoS policy removal, etc.)
* then enable it for this interface.
*/
ip1dbg(("ip_mdinfo_return: reenabling MDT for "
"interface %s\n", ill_name));
}
/* Allocate the MDT info mblk */
ip0dbg(("ip_mdinfo_return: can't enable Multidata for "
return (NULL);
}
return (mp);
}
/*
* Routine to allocate a message that is used to notify the ULP about LSO.
* The caller may provide a pointer to the link-layer LSO capabilities,
* or NULL if LSO is to be disabled on the stream.
*/
mblk_t *
{
/*
* If the caller provides us with the capability, copy
* it over into our notification message; otherwise
* we zero out the capability portion.
*/
else
}
return (mp);
}
/*
* Routine which determines whether LSO can be enabled on the destination
* IRE and IPC combination, and if so, allocates and returns the LSO
* notification mblk that may be used by ULP. We also check if we need to
* turn LSO back to 'on' when certain restrictions prohibiting us to allow
* LSO usage in the past have been lifted. This gets called during IP
* and ULP binding.
*/
mblk_t *
{
/*
* Disable LSO for this and all future connections going
* over the interface.
*/
lso_cap->ill_lso_on = 0;
}
}
if (!connp->conn_lso_ok)
return (NULL);
else if (!lso_cap->ill_lso_on) {
/*
* If LSO has been previously turned off in the past, and we
* currently can do LSO (due to IPQoS policy removal, etc.)
* then enable it for this interface.
*/
ip1dbg(("ip_mdinfo_return: reenabling LSO for interface %s\n",
ill_name));
}
/* Allocate the LSO info mblk */
ip0dbg(("ip_lsoinfo_return: can't enable LSO for "
return (mp);
}
/*
* Create destination address attribute, and fill it with the physical
* destination address and SAP taken from the template DL_UNITDATA_REQ
* message block.
*/
{
/* create and associate the attribute */
(*das)->addr_is_group = 0;
}
}
/*
* Create hardware checksum attribute and fill it with the values passed.
*/
{
/* create and associate the attribute */
}
}
/*
* Create zerocopy attribute and fill it with the specified flags
*/
{
/* create and associate the attribute */
}
}
/*
* Check if ip_wput_frag_mdt() and ip_wput_frag_mdt_v6() can handle a message
* block chain. We could rewrite to handle arbitrary message block chains but
* that would make the code complicated and slow. Right now there three
* restrictions:
*
* 1. The first message block must contain the complete IP header and
* at least 1 byte of payload data.
* 2. At most MULTIDATA_MAX_PBUFS non-empty message blocks are allowed
* so that we can use a single Multidata message.
* 3. No frag must be distributed over two or more message blocks so
* that we don't need more than two packet descriptors per frag.
*
* The above restrictions allow us to support userland applications (which
* will send down a single message block) and NFS over UDP (which will
* send down a chain of at most three message blocks).
*
* We also don't use MDT for payloads with less than or equal to
* ip_wput_frag_mdt_min bytes because it would cause too much overhead.
*/
{
int blocks;
if (size <= 0)
return (B_FALSE);
/* The first mblk contains the header and some payload. */
blocks = 1;
/*
* Give up if we encounter a zero length message block.
* In practice, this should rarely happen and therefore
* not worth the trouble of freeing and re-linking the
* mblk from the chain to handle such case.
*/
return (B_FALSE);
/* Too many payload buffers for a single Multidata message? */
if (++blocks > MULTIDATA_MAX_PBUFS)
return (B_FALSE);
/* Is a frag distributed over two or more message blocks? */
return (B_FALSE);
}
return (total > ip_wput_frag_mdt_min);
}
/*
* Outbound IPv4 fragmentation routine using MDT.
*/
static void
{
int i1, ip_data_end;
/* Calculate how many packets we will send out */
/* Allocate a message block which will hold all the IP Headers. */
/*
* Create the header buffer, Multidata and destination address
* and SAP attribute that should be associated with it.
*/
} else {
}
return;
}
/*
* Add a payload buffer to the Multidata; this operation must not
* fail, or otherwise our logic in this routine is broken. There
* is no memory allocation done by the routine, so any returned
* failure simply tells us that we've done something wrong.
*
* A failure tells us that either we're adding the same payload
* buffer more than once, or we're trying to add more buffers than
* allowed. None of the above cases should happen, and we panic
* programming mistake.
*/
goto pbuf_panic;
/* Establish the ending byte offset, based on the starting offset. */
offset <<= 3;
int error;
} else {
/*
* Last frag. Set len to the length of this last piece.
*/
/* 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.
*/
/*
* Record offset and size of header and data of the next packet
* in the multidata message.
*/
} else {
/*
* Attach the next payload message block to the
* multidata message.
*/
goto pbuf_panic;
}
KM_NOSLEEP)) == NULL) {
/*
* Any failure other than ENOMEM indicates that we
* have passed in invalid pdesc info or parameters
* to mmd_addpdesc, which must not happen.
*
* EINVAL is a result of failure on boundary checks
* against the pdesc info contents. It should not
* happen, and we panic because either there's
* mistake.
*/
"pdesc logic error detected for "
"mmd %p pinfo %p (%d)\n",
/* NOTREACHED */
}
/* Free unattached payload message blocks as well */
goto free_mmd;
}
/* Advance fragment offset. */
/* Advance to location for next header in the buffer. */
hdr_ptr += hdr_chunk_len;
/* Did we reach the next payload message block? */
/*
* Attach the next message block with payload
* data to the multidata message.
*/
goto pbuf_panic;
}
}
/* Update IP statistics */
} else {
/*
* The type is IB_PKT in the forwarding path and in
* the mobile IP case when the packet is being reverse-
* tunneled to the home agent.
*/
} else {
}
}
/* Send it down */
return;
pbuf_idx);
/* NOTREACHED */
}
/*
* Outbound IP fragmentation routine.
*
* NOTE : This routine does not ire_refrele the ire that is passed in
* as the argument.
*/
static void
{
int i1;
int ll_hdr_len;
int hdr_len;
int ip_data_end;
int len;
int offset;
queue_t *q;
/*
* IPSEC does not allow hw accelerated packets to be fragmented
* This check is made in ip_wput_ipsec_out prior to coming here
* via ip_wput_ire_fragmentit.
*
* If at this point we have an ire whose ARP request has not
* been sent out, we call ip_xmit_v4->ire_arpresolve to trigger
* sending of ARP query and change ire's state to ND_INCOMPLETE.
* This packet and all fragmentable packets for this ire will
* continue to get dropped while ire_nce->nce_state remains in
* ND_INCOMPLETE. Post-ARP resolution, after ire's nce_state changes to
* ND_REACHABLE, all subsquent large packets for this ire will
* get fragemented and sent out by this function.
*/
/* If nce_state is ND_INITIAL, trigger ARP query */
ip1dbg(("ip_wput_frag: mac address for ire is unresolved"
" - dropping packet\n"));
return;
}
"ip_wput_frag_start:");
} else {
}
/*
* If the Don't Fragment flag is on, generate an ICMP destination
* unreachable, fragmentation needed.
*/
/*
* Need to compute hdr checksum if called from ip_wput_ire.
* Note that ip_rput_forward verifies the checksum before
* calling this routine so in that case this is a noop.
*/
ipha->ipha_hdr_checksum = 0;
ipst);
"ip_wput_frag_end:(%S)",
"don't fragment");
return;
}
if (mctl_present)
/*
* 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 */
"ip_wput_frag_end:(%S)",
"len < 8");
return;
}
ipha->ipha_hdr_checksum = 0;
/*
* Establish the number of bytes maximum per frag, after putting
* in the header.
*/
/* Check if we can use MDT to send out the frags. */
if (hdr_len == IP_SIMPLE_HDR_LENGTH &&
/*
* If MDT has been previously turned off in the past,
* and we currently can do MDT (due to IPQoS policy
* removal, etc.) then enable it for this interface.
*/
ip1dbg(("ip_wput_frag: enabled MDT for interface %s\n",
}
offset);
return;
}
/* Get a copy of the header for the trailing frags */
if (!hdr_mp) {
"ip_wput_frag_end:(%S)",
"couldn't copy hdr");
return;
}
/* 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.
*/
"ip_wput_frag_end:(%S)",
"couldn't carve first");
return;
}
/*
* Multirouting case. Each fragment is replicated
* via all non-condemned RTF_MULTIRT routes
* currently resolved.
* We ensure that first_ire is the first RTF_MULTIRT
* ire in the bucket.
*/
/* Make sure we do not omit any multiroute ire. */
break;
}
/*
* Do not release the ire passed in
* as the argument.
*/
} else {
}
}
/*
* Save the first ire; we will need to restore it
* for the trailing frags.
* We REFHOLD save_ire, as each iterated ire will be
* REFRELEd.
*/
}
/*
* First fragment emission loop.
* In most cases, the emission loop below is entered only
* once. Only in the case where the ire holds the RTF_MULTIRT
* flag, do we loop to process all RTF_MULTIRT ires in the
* bucket, and send the fragment through all crossed
* RTF_MULTIRT routes.
*/
do {
/*
* We are in a multiple send case, need to get
* the next ire and make a copy of the packet.
* ire1 holds here the next ire to process in the
* bucket. If multirouting is expected,
* any non-RTF_MULTIRT ire that has the
* right destination address is ignored.
*
* We have to take into account the MTU of
* each walked ire. max_frag is set by the
* the caller and generally refers to
* the primary ire entry. Here we ensure that
* no route with a lower MTU will be used, as
* fragments are carved once for all ires,
* then replicated.
*/
continue;
continue;
continue;
/*
* Ensure we do not exceed the MTU
* of the next route.
*/
continue;
}
/* Got one. */
break;
}
}
}
/* Last multiroute ire; don't loop anymore. */
}
}
ll_hdr_len = 0;
} else {
}
/* If there is a transmit header, get a copy for this frag. */
/*
* TODO: should check db_ref before calling ip_carve_mp since
* it might give us a dup.
*/
if (!ll_hdr_mp) {
/* No xmit header. */
/* We have a link-layer header that can fit in our mblk. */
ll_hdr_len != 0 &&
/* M_DATA fastpath */
/* Corner case if copyb has failed */
"ip_wput_frag_end:(%S)",
"discard");
if (multirt_send) {
}
return;
/*
* Case of res_mp OR the fastpath mp can't fit
* in the mblk
*/
} else {
/*
* Get priority marking, if any.
* We propagate the CoS marking from the
* original packet that went to QoS processing
* in ip_wput_ire to the newly carved mp.
*/
}
/*
* Update the packet count and MIB stats
* of trailing RTF_MULTIRT ires.
*/
}
}
if (multirt_send) {
/*
* We are in a multiple send case; look for
* the next ire and re-enter the loop.
*/
/* REFRELE the current ire before looping */
}
} while (multirt_send);
/* Restore the original ire; we need it for the trailing frags */
/* REFRELE the last iterated ire */
/* save_ire has been REFHOLDed */
}
} else {
}
/* 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.
*/
/* Attach a transmit header, if any, and ship it. */
} else {
}
/*
* Save the original ire; we will need to restore it
* for the tailing frags.
*/
}
/*
* Emission loop for this fragment, similar
* to what is done for the first fragment.
*/
do {
if (multirt_send) {
/*
* We are in a multiple send case, need to get
* the next ire and make a copy of the packet.
*/
continue;
continue;
continue;
/*
* Ensure we do not exceed the MTU
* of the next route.
*/
max_frag);
continue;
}
/* Got one. */
break;
}
}
}
/* Last multiroute ire; don't loop anymore. */
}
}
/* Update transmit header */
ll_hdr_len = 0;
} else {
}
if (!ll_hdr_mp) {
/*
* We have link-layer header that can fit in
* our mblk.
*/
ll_hdr_len != 0 &&
/* M_DATA fastpath */
/*
* Case of res_mp OR the fastpath mp can't fit
* in the mblk
*/
/* Get priority marking, if any. */
/* Corner case if copyb failed */
} else {
/*
* Exit both the replication and
* fragmentation loops.
*/
goto drop_pkt;
}
/*
* Update the packet count of trailing
* RTF_MULTIRT ires.
*/
}
}
/* All done if we just consumed the hdr_mp. */
}
if (multirt_send) {
/*
* We are in a multiple send case; look for
* the next ire and re-enter the loop.
*/
/* REFRELE the current ire before looping */
}
} while (multirt_send);
/*
* Restore the original ire; we need it for the
* trailing frags
*/
/* REFRELE the last iterated ire */
/* save_ire has been REFHOLDed */
}
if (last_frag) {
"ip_wput_frag_end:(%S)",
"consumed hdr_mp");
return;
}
/* Otherwise, advance and loop. */
}
/* Clean up following allocation failure. */
"ip_wput_frag_end:(%S)",
"end--alloc failure");
}
/*
* 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);
}
/*
* Delivery to local recipients including fanout to multiple recipients.
* Note: q should be the read side queue for either the ill or conn.
* Note: rq should be the read side q for the lower (ill) stream.
* We don't send packets to IPPF processing, thus the last argument
* to all the fanout calls are B_FALSE.
*/
void
{
int ire_type;
"ip_wput_local_start: q %p", q);
} else {
/*
* Only ip_multicast_loopback() calls us with a NULL ire. If the
* packet is not multicast, we can't tell the ire type.
*/
}
if (!io->ipsec_out_secure) {
/*
* This ipsec_out_t was allocated in ip_wput
* for multicast packets to store the ill_index.
* As this is being delivered locally, we don't
* need this anymore.
*/
} else {
/*
* Convert IPSEC_OUT to IPSEC_IN, preserving all
* security properties for the looped-back packet.
*/
}
} else {
}
return;
ip2dbg(("ip_wput_local: from 0x%x to 0x%x in zone %d\n",
if (!IS_SIMPLE_IPH(ipha)) {
}
switch (protocol) {
case IPPROTO_ICMP: {
/*
* In the multicast case, applications may have joined
* the group from different zones, so we need to deliver
* the packet to each of them. Loop through the
* multicast memberships structures (ilm) on the receive
* ill and send a copy of the packet up each matching
* one. However, we don't do this for multicasts sent on
* the loopback interface (PHYI_LOOPBACK flag set) as
* they must stay in the sender's zone.
*
* ilm_add_v6() ensures that ilms in the same zone are
* contiguous in the ill_ilm list. We use this property
* to avoid sending duplicates needed when two
* applications in the same zone join the same group on
* different logical interfaces: we ignore the ilm if
* it's zoneid is the same as the last matching one.
* In addition, the sending of the packet for
* ire_zoneid is delayed until all of the other ilms
* have been exhausted.
*/
last_zoneid = -1;
continue;
continue;
ilm->ilm_zoneid);
}
/*
* Loopback case: the sending endpoint has
* IP_MULTICAST_LOOP disabled, therefore we don't
* dispatch the multicast packet to the sending zone.
*/
if (fanout_flags & IP_FF_NO_MCAST_LOOP) {
return;
}
} else if (ire_type == IRE_BROADCAST) {
/*
* In the broadcast case, there may be many zones
* which need a copy of the packet delivered to them.
* There is one IRE_BROADCAST per broadcast address
* and per zone; we walk those using a helper function.
* In addition, the sending of the packet for zoneid is
* delayed until all of the other ires have been
* processed.
*/
continue;
}
}
"ip_wput_local_end: q %p (%S)",
q, "icmp");
return;
}
case IPPROTO_IGMP:
/* Bad packet - discarded by igmp_input */
"ip_wput_local_end: q %p (%S)",
q, "igmp_input--bad packet");
if (mctl_present)
return;
}
/*
* igmp_input() may have returned the pulled up message.
* So first_mp and ipha need to be reinitialized.
*/
if (mctl_present)
else
/* deliver to local raw users */
break;
case IPPROTO_ENCAP:
/*
* This case is covered by either ip_fanout_proto, or by
* the above security processing for self-tunneled packets.
*/
break;
case IPPROTO_UDP: {
/* Force a 'valid' checksum. */
up[3] = 0;
(ire_type == IRE_BROADCAST),
"ip_wput_local_end: q %p (%S)", q, "ip_fanout_udp");
return;
}
case IPPROTO_TCP: {
/*
* For TCP, discard broadcast packets.
*/
ip2dbg(("ip_wput_local: discard broadcast\n"));
return;
}
/*
* M_DATA mblk, so init mblk (chain) for no struio().
*/
do
}
"ip_wput_local_end: q %p (%S)", q, "ip_fanout_tcp");
return;
}
case IPPROTO_SCTP:
{
return;
}
default:
break;
}
/*
* Find a client for some other protocol. We give
* copies to multiple clients, if more than one is
* bound.
*/
"ip_wput_local_end: q %p (%S)", q, "ip_fanout_proto");
}
/*
* Update any source route, record route, or timestamp options.
* Check that we are at end of strict source route.
* The options have been sanity checked by ip_wput_options().
*/
static void
{
ip2dbg(("ip_wput_local_options\n"));
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
*/
ip1dbg(("ip_wput_local_options: not end of SR\n"));
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_wput_forward_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 */
ipst);
/* 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_wput_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;
}
}
}
/*
* Send out a multicast packet on interface ipif.
* The sender does not have an conn.
* Caller verifies that this isn't a PHYI_LOOPBACK.
*/
void
{
/* igmp_sendpkt always allocates a ipsec_out_t */
/*
* Find an IRE which matches the destination and the outgoing
* queue (i.e. the outgoing interface.)
*/
else
/*
* The source address has already been initialized by the
* caller and hence matching on ILL (MATCH_IRE_ILL) would
* be sufficient rather than MATCH_IRE_IPIF.
*
* This function is used for sending IGMP packets. We need
* to make sure that we send the packet out of the interface
* (ipif->ipif_ill) where we joined the group. This is to
* prevent from switches doing IGMP snooping to send us multicast
* packets for a given group on the interface we have joined.
* If we can't find an ire, igmp_sendpkt has already initialized
* ipsec_out_attach_if so that this will not be load spread in
* ip_newroute_ipif.
*/
if (!ire) {
/*
* Mark this packet to make it be delivered to
* ip_wput_ire after the new ire has been
* created.
*/
return;
}
/*
* Honor the RTF_SETSRC flag; this is the only case
* where we force this addr whatever the current src addr is,
* because this address is set by igmp_sendpkt(), and
* cannot be specified by any user.
*/
}
}
/*
* NOTE : This function does not ire_refrele the ire argument passed in.
*
* Copy the link layer header and do IPQoS if needed. Frees the mblk on
* failure. The nce_fp_mp can vanish any time in the case of IRE_MIPRTUN
* and IRE_BROADCAST due to DL_NOTE_FASTPATH_FLUSH. Hence we have to hold
* the ire_lock to access the nce_fp_mp in this case.
* IPQoS assumes that the first M_DATA contains the IP header. So, if we are
* prepending a fastpath message IPQoS processing must precede it, we also set
* the b_band of the fastpath message to that of the mblk returned by IPQoS
* (IPQoS might have set the b_band for CoS marking).
* However, if we are prepending DL_UNITDATA_REQ message, IPQoS processing
* must follow it so that IPQoS can mark the dl_priority field for CoS
* marking, if needed.
*/
static mblk_t *
{
hlen = 0;
/* Initiate IPPF processing */
return (NULL);
goto no_fp_mp;
}
}
/*
* Check if we have enough room to prepend fastpath
* header
*/
/*
* Set the b_rptr to the start of the link layer
* header
*/
} else {
goto unlock_err;
/*
* certain system generated traffic may not
* is true even for a labeled system. But for
* labeled traffic, inherit the label in the
* new header.
*/
/*
* 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)
*/
}
} else {
return (NULL);
}
/*
* certain system generated traffic may not
* is true even for a labeled system. But for
* labeled traffic, inherit the label in the
* new header.
*/
return (NULL);
}
}
return (mp1);
}
/*
* Finish the outbound IPsec processing for an IPv6 packet. This function
* is called from ipsec_out_process() if the IPsec packet was processed
* synchronously, or from {ah,esp}_kcf_callback() if it was processed
* asynchronously.
*/
void
{
int match_flags;
if (io->ipsec_out_reachable) {
}
/* Multicast addresses should have non-zero ill_index. */
if (ill_index != 0) {
/* Failure case frees things for us. */
return;
}
/*
* If this packet needs to go out on a particular interface
* honor it.
*/
if (attach_if) {
/*
* Check if we need an ire that will not be
* looked up by anybody else i.e. HIDDEN.
*/
if (ill_is_probeonly(ill)) {
}
}
}
if (IN6_IS_ADDR_MULTICAST(v6dstp)) {
/*
* Use the ill_index to get the right ill.
*/
if (ill_need_rele)
return;
}
} else {
}
/*
* XXX Do the multicast forwarding now, as the IPSEC
* processing has been done.
*/
goto send;
}
ip0dbg(("ip_wput_ipsec_out_v6: multicast: IRE disappeared\n"));
/*
* If the IPsec packet was processed asynchronously,
* drop it now.
*/
if (q == NULL) {
if (ill_need_rele)
return;
}
unspec_src, zoneid);
} else {
if (attach_if) {
if (ill_need_rele)
return;
}
} else {
} else {
ipst);
}
}
goto send;
/*
* ire disappeared underneath.
*
* What we need to do here is the ip_newroute
* logic to get the ire without doing the IPSEC
* processing. Follow the same old path. But this
* time, ip_wput or ire_add_then_send will call us
* directly as all the IPSEC operations are done.
*/
ip1dbg(("ip_wput_ipsec_out_v6: IRE disappeared\n"));
/*
* If the IPsec packet was processed asynchronously,
* drop it now.
*/
if (q == NULL) {
if (ill_need_rele)
return;
}
}
return;
send:
/* Local delivery */
/* PFHooks: LOOPBACK_OUT */
if (ire_need_rele)
return;
}
/*
* Everything is done. Send it out on the wire.
* We force the insertion of a fragment header using the
* IPH_FRAG_HDR flag in two cases:
* - after reception of an ICMPv6 "packet too big" message
* with a MTU < 1280 (cf. RFC 2460 section 5)
* - for multirouted IPv6 packets, so that the receiver can
* discard duplicates according to their fragment identifier
*/
/* XXX fix flow control problems. */
if (hwaccel) {
/*
* hardware acceleration does not handle these
* "slow path" cases.
*/
/* IPsec KSTATS: should bump bean counter here. */
if (ire_need_rele)
return;
}
/* IPsec KSTATS: should bump bean counter here. */
ip0dbg(("Packet length mismatch: %d, %ld\n",
if (ire_need_rele)
return;
}
ip2dbg(("Fragmenting Size = %d, mtu = %d\n",
ire->ire_max_frag);
} else {
}
if (ire_need_rele)
}
void
{
/* IPsec KSTATS: Bump lose counter here! */
return;
}
/*
* It's an IPsec packet that must be
* accelerated by the Provider, and the
* outbound ill is IPsec acceleration capable.
* Prepends the mblk with an IPHADA_M_CTL, and ship it
* to the ill.
* IPsec KSTATS: should bump packet counter here.
*/
/* IPsec KSTATS: should bump packet counter here. */
return;
}
}
/*
* 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() if it was processed
* asynchronously.
*/
void
{
int match_flags, offset;
#ifdef _BIG_ENDIAN
#else
#endif
if (ill_index != 0) {
/* Failure case frees things for us. */
return;
}
/*
* If this packet needs to go out on a particular interface
* honor it.
*/
if (attach_if) {
/*
* Check if we need an ire that will not be
* looked up by anybody else i.e. HIDDEN.
*/
if (ill_is_probeonly(ill)) {
}
}
}
/*
* Use the ill_index to get the right ipif.
*/
if (ill_index == 0)
else
ip1dbg(("ip_wput_ipsec_out: No ipif for"
" multicast\n"));
goto done;
}
/*
* ipha_src has already been intialized with the
* value of the ipif in ip_wput. All we need now is
* an ire to send this downstream.
*/
/*
* Do the multicast forwarding now, as the IPSEC
* processing has been done.
*/
ip1dbg(("ip_wput_ipsec_out: mforward "
"failed\n"));
goto done;
}
}
goto send;
}
ip0dbg(("ip_wput_ipsec_out: multicast: IRE disappeared\n"));
/*
* If the IPsec packet was processed asynchronously,
* drop it now.
*/
if (q == NULL) {
goto done;
}
/*
* We may be using a wrong ipif to create the ire.
* But it is okay as the source address is assigned
* for the packet already. Next outbound packet would
* create the IRE with the right IPIF in ip_wput.
*
* Also handle RTF_MULTIRT routes.
*/
} else {
if (attach_if) {
} else {
} else {
}
}
goto send;
}
/*
* ire disappeared underneath.
*
* What we need to do here is the ip_newroute
* logic to get the ire without doing the IPSEC
* processing. Follow the same old path. But this
* time, ip_wput or ire_add_then_put will call us
* directly as all the IPSEC operations are done.
*/
ip1dbg(("ip_wput_ipsec_out: IRE disappeared\n"));
/*
* If the IPsec packet was processed asynchronously,
* drop it now.
*/
if (q == NULL) {
goto done;
}
/*
* Since we're going through ip_newroute() again, we
* need to make sure we don't:
*
* 1.) Trigger the ASSERT() with the ipha_ident
* overloading.
* 2.) Redo transport-layer checksumming, since we've
* already done all that to get this far.
*
* The easiest way not do either of the above is to set
* the ipha_ident field to IP_HDR_INCLUDED.
*/
}
goto done;
send:
/*
* ESP NAT-Traversal packet.
*
* Just do software checksum for now.
*/
break; /* out of for loop */
} else {
}
} /* Otherwise, just keep the all-zero checksum. */
/*
* Loopbacks go through ip_wput_local except for one case.
* We come here if we generate a icmp_frag_needed message
* after IPSEC processing is over. When this function calls
* ip_wput_ire_fragmentit, ip_wput_frag might end up calling
* icmp_frag_needed. The message generated comes back here
* through icmp_frag_needed -> icmp_pkt -> ip_wput ->
* ipsec_out_process -> ip_wput_ipsec_out. We need to set the
* source address as it is usually set in ip_wput_ire. As
* ipsec_out_proc_begin is set, ip_wput calls ipsec_out_process
* and we end up here. We can't enter ip_wput_ire once the
* IPSEC processing is over and hence we need to do it here.
*/
/* PFHooks: LOOPBACK_OUT */
if (ire_need_rele)
goto done;
}
/*
* We are through with IPSEC processing.
* Fragment this and send it on the wire.
*/
if (io->ipsec_out_accelerated) {
/*
* The packet has been accelerated but must
* be fragmented. This should not happen
* since AH and ESP must not accelerate
* packets that need fragmentation, however
* the configuration could have changed
* since the AH or ESP processing.
* Drop packet.
* IPsec KSTATS: bump bean counter here.
*/
"fragmented accelerated packet!\n"));
} else {
}
if (ire_need_rele)
goto done;
}
ip2dbg(("ip_wput_ipsec_out: ipsec_mp %p, ire %p, ire_ipif %p, "
/*
* Multiroute the secured packet, unless IPsec really
* requires the packet to go out only through a particular
* interface.
*/
/*
* This ire has been looked up as the one that
* goes through the given ipif;
* make sure we do not omit any other multiroute ire
* that may be present in the bucket before this one.
*/
break;
}
/*
* Don't change the ire if the packet must
* be fragmented if sent via this new one.
*/
if (ire_need_rele)
else
}
}
} else {
ip1dbg(("ip_wput_ipsec_out: ignoring multirouting "
"flag, attach_if %d\n", attach_if));
}
}
/*
* In most cases, the emission loop below is entered only once.
* Only in the case where the ire holds the RTF_MULTIRT
* flag, we loop to process all RTF_MULTIRT ires in the
* bucket, and send the packet through all crossed
* RTF_MULTIRT routes.
*/
do {
if (multirt_send) {
/*
* ire1 holds here the next ire to process in the
* bucket. If multirouting is expected,
* any non-RTF_MULTIRT ire that has the
* right destination address is ignored.
*/
continue;
continue;
continue;
/* No loopback here */
continue;
/*
* Ensure we do not exceed the MTU
* of the next route.
*/
continue;
}
break;
}
/*
* We are in a multiple send case, need to
* make a copy of the packet.
*/
}
}
}
/*
* Everything is done. Send it out on the wire
*
* ip_xmit_v4 will call ip_wput_attach_llhdr and then
* either send it on the wire or, in the case of
* HW acceleration, call ipsec_hw_putnext.
*/
/*
* If ire's link-layer is unresolved (this
* would only happen if the incomplete ire
* was added to cachetable via forwarding path)
* don't bother going to ip_xmit_v4. Just drop the
* packet.
* There is a slight risk here, in that, if we
* have the forwarding path create an incomplete
* IRE, then until the IRE is completed, any
* transmitted IPSEC packets will be dropped
* instead of being queued waiting for resolution.
*
* But the likelihood of a forwarding packet and a wput
* packet sending to the same dst at the same time
* and there not yet be an ARP entry for it is small.
* Furthermore, if this actually happens, it might
* be likely that wput would generate multiple
* packets (and forwarding would also have a train
* of packets) for that destination. If this is
* the case, some of them would have been dropped
* anyway, since ARP only queues a few packets while
* waiting for resolution
*
* NOTE: We should really call ip_xmit_v4,
* and let it queue the packet and send the
* ARP query and have ARP come back thus:
* <ARP> ip_wput->ip_output->ip-wput_nondata->
* ip_xmit_v4->ip_wput_attach_llhdr + ipsec
* hw accel work. But it's too complex to get
* the IPsec hw acceleration approach to fit
* well with ip_xmit_v4 doing ARP without
* doing IPSEC simplification. For now, we just
* poke ip_xmit_v4 to trigger the arp resolve, so
* that we can continue with the send on the next
* attempt.
*
* XXX THis should be revisited, when
*/
ip1dbg(("ip_wput_ipsec_out: ire is incomplete"
" - dropping packet\n"));
/*
* Call ip_xmit_v4() to trigger ARP query
* in case the nce_state is ND_INITIAL
*/
goto drop_pkt;
}
goto drop_pkt;
ip1dbg(("ip_wput_ipsec_out: calling ip_xmit_v4\n"));
if ((pktxmit_state == SEND_FAILED) ||
(pktxmit_state == LLHDR_RESLV_FAILED)) {
if (ire_need_rele)
}
goto done;
}
if (ire_need_rele)
} else {
}
} while (multirt_send);
done:
}
/*
* Get the ill corresponding to the specified ire, and compare its
* capabilities with the protocol and algorithms specified by the
* the SA obtained from ipsec_out. If they match, annotate the
* ipsec_out structure to indicate that the packet needs acceleration.
*
*
* A packet is eligible for outbound hardware acceleration if the
* following conditions are satisfied:
*
* 1. the packet will not be fragmented
* 2. the provider supports the algorithm
* 3. there is no pending control message being exchanged
* 4. snoop is not attached
* 5. the destination address is not a broadcast or multicast address.
*
* Rationale:
* - Hardware drivers do not support fragmentation with
* the current interface.
* - snoop, multicast, and broadcast may result in exposure of
* a cleartext datagram.
* We check all five of these conditions here.
*
* XXX would like to nuke "ire_t *" parameter here; problem is that
* IRE is only way to figure out if a v4 address is a broadcast and
* thus ineligible for acceleration...
*/
static void
{
return;
return;
/*
* Destination address is a broadcast or multicast. Punt.
*/
IRE_LOCAL)))
return;
return;
} else {
return;
}
/*
* Is there a pending DLPI control message being exchanged
* could be a SADB update, and the state of the DLS Provider
* SADB might not be in sync with the SADB maintained by
* IPsec. To avoid dropping packets or using the wrong keying
* material, we do not accelerate this packet.
*/
"ill_dlpi_pending! don't accelerate packet\n"));
return;
}
/*
* Is the Provider in promiscous mode? If it does, we don't
* accelerate the packet since it will bounce back up to the
* listeners in the clear.
*/
if (ill->ill_promisc_on_phys) {
"ill in promiscous mode, don't accelerate packet\n"));
return;
}
/*
* Will the packet require fragmentation?
*/
/*
* IPsec ESP note: this is a pessimistic estimate, but the same
* as is used elsewhere.
* SPI + sequence + MAC + IV(blocksize) + padding(blocksize-1)
* + 2-byte trailer
*/
return;
/*
* Can the ill accelerate this IPsec protocol and algorithm
* specified by the SA?
*/
return;
}
/*
* Tell AH or ESP that the outbound ill is capable of
* accelerating this packet.
*/
}
/*
* 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 ipsec_out_*_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 when the ipsec_mp is freed, thanks to the
* ipsec_out_free destructor -- see spd.c.
*/
static boolean_t
{
if (!io->ipsec_out_secure) {
/*
* We came here by mistake.
* Don't bother with ipsec processing
* We should "discourage" this path in the future.
*/
return (B_FALSE);
}
/*
* IPSEC processing has started.
*/
}
/*
* We have an action. now, let's select SA's.
* (In the future, we can cache this 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);
}
/*
* Process an IPSEC_OUT message and see what you can
* do with it.
* IPQoS Notes:
* We do IPPF processing if IPP_LOCAL_OUT is enabled before processing for
* IPSec.
* XXX would like to nuke ire_t.
* XXX ill_index better be "real"
*/
void
{
/*
* Initiate IPPF processing. We do it here to account for packets
* coming here that don't have any policy (i.e. !io->ipsec_out_secure).
* We can check for ipsec_out_proc_begin even for such packets, as
* they will always be false (asserted below).
*/
ip2dbg(("ipsec_out_process: packet dropped "\
"during IPPF processing\n"));
return;
}
}
if (!io->ipsec_out_secure) {
/*
* We came here by mistake.
* Don't bother with ipsec processing
* Should "discourage" this path in the future.
*/
goto done;
}
if (!ipsec_loaded(ipss)) {
} else {
}
&ipss->ipsec_dropper);
return;
}
/*
* IPSEC processing has started.
*/
}
/*
* Save the outbound ill index. When the packet comes back
* from IPsec, we make sure the ill hasn't changed or disappeared
* before sending it the accelerated packet.
*/
int ifindex;
}
/*
* The order of processing is first insert a IP header if needed.
* Then insert the ESP header and then the AH header.
*/
(ap->ipa_want_se)) {
/*
* First get the outer IP header before sending
* it to ESP.
*/
"ipsec_out_process: "
"Self-Encapsulation failed: Out of memory\n");
} else {
}
return;
}
sizeof (ipha_t));
oipha->ipha_hdr_checksum = 0;
}
return;
/*
* By now, we know what SA's to use. Toss over to ESP & AH
* to do the heavy lifting.
*/
/*
* Note that since hw accel can only apply one transform,
* not two, we skip hw accel for ESP if we also have AH
* This is an design limitation of the interface
* which should be revisited.
*/
}
switch (ipsec_rc) {
case IPSEC_STATUS_SUCCESS:
break;
case IPSEC_STATUS_FAILED:
} else {
}
/* FALLTHRU */
case IPSEC_STATUS_PENDING:
return;
}
}
} else {
}
ire);
switch (ipsec_rc) {
case IPSEC_STATUS_SUCCESS:
break;
case IPSEC_STATUS_FAILED:
} else {
}
/* FALLTHRU */
case IPSEC_STATUS_PENDING:
return;
}
}
/*
* We are done with IPSEC processing. Send it over
* the wire.
*/
done:
} else {
}
}
/* ARGSUSED */
void
{
int err;
/*
* We don't need to pass any credentials here since this is just
* a restart. The credentials are passed in when svr4_optcom_req
* is called the first time (from ip_wput_nondata).
*/
&ip_opt_obj);
} else {
&ip_opt_obj);
}
if (err != EINPROGRESS) {
/* operation is done */
}
}
/*
* 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 ipsq_current_ipif is not set:
* ill_phyint_reinit merged the v4 and v6 into a single ipsq.
* ill could also have become part of a ipmp group in the
* process, 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, In such a case ipsq_current_ipif
* will not be set so we need to set it.
*/
}
/* 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 and determines the copyin data size
* from the ioctl property ipi_copyin_size, and does an mi_copyin() of that
* size.
*
* ioctl processing then continues when the M_IOCDATA makes its way down.
* Now the ioctl is looked up again in the ioctl table, and its properties are
* extracted. The associated 'conn' is then refheld till the end of the ioctl
* and the general ioctl processing function ip_process_ioctl is called.
* 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.
* struct and looks up the ipif. ip_extract_tunreq handles the case of tunnel.
*
* 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 IF_CMD:
case LIF_CMD:
/*
* ioctls that pass in a [l]ifreq appear here.
* ip_extract_lifreq_cmn returns a refheld ipif in
* ci.ci_ipif
*/
if (err != 0) {
return;
}
break;
case TUN_CMD:
/*
* SIOC[GS]TUNPARAM appear here. ip_extract_tunreq returns
* a refheld ipif in ci.ci_ipif
*/
if (err != 0) {
return;
}
break;
case MISC_CMD:
/*
* ioctls that neither pass in [l]ifreq or iftun_req come here
* For eg. SIOCGLIFCONF will appear here.
*/
case IF_UNITSEL:
/* ioctl comes down the ill */
break;
case SIOCGMSFILTER:
case SIOCSMSFILTER:
case SIOCGIPMSFILTER:
case SIOCSIPMSFILTER:
if (err != 0) {
NULL);
}
break;
}
err = 0;
break;
}
/*
* If ipsq is non-null, we are already being called exclusively
*/
/*
* A return value of EINPROGRESS means the ioctl is
* either queued and waiting for some reason or has
* already completed.
*/
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.
*/
return;
/*
* For most set ioctls that come here, this serves as a single point
* where we set the IPIF_CHANGING flag. This ensures that there won't
* be any new references to the ipif. This helps functions that go
* through this path and end up trying to wait for the refcnts
* associated with the ipif to go down to zero. Some exceptions are
* Failover, Failback, and Groupname commands that operate on more than
* just the ci.ci_ipif. These commands internally determine the
* set of ipif's they operate on and set and clear the IPIF_CHANGING
* flags on that set. Another exception is the Removeif command that
* sets the IPIF_CONDEMNED flag internally after identifying the right
* ipif to operate on.
*/
/*
* 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 refhold placed at the start of the ioctl is released here.
*/
}
/*
* This is called from ip_wput_nondata to resume a deferred TCP bind.
*/
/* ARGSUSED */
void
{
else
}
/* Called from ip_wput for all non data messages */
/* ARGSUSED */
void
{
char *proto_str;
if (CONN_Q(q)) {
} else {
ipst = ILLQ_TO_IPST(q);
}
return;
}
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, pass M_IOCDATA
* for processing downstream, but only for
* common Streams ioctls.
*/
return;
} else {
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 ill_pending_mp list and
* the ipsq_pending_mp must have a refhold on the conn
* to resume processing. The refhold is released when
* the ioctl completes. (normally or abnormally)
* In all cases ip_ioctl_finish is called to finish
* the ioctl.
*/
/* This is not a reentry */
} else {
return;
}
}
} else {
mi_copyout(q, mp);
}
return;
nak:
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: unexpected M_IOCNAK, ioc_cmd 0x%x",
return;
case M_IOCACK:
if (CONN_Q(q))
goto nak;
/* Finish socket ioctls passed through to ARP. */
ip_sioctl_iocack(q, mp);
return;
case M_FLUSH:
if (q->q_next) {
/*
* M_FLUSH is sent up to IP by some drivers during
* unbind. ip_rput has already replied to it. We are
* here for the M_FLUSH that we originated in IP
* before sending the unbind request to the driver.
* Just free it as we don't queue packets in IP
* on the write side of the device instance.
*/
return;
}
return;
}
return;
case IRE_DB_REQ_TYPE:
proto_str = "IRE_DB_REQ_TYPE";
goto protonak;
}
/* An Upper Level Protocol wants a copy of an IRE. */
ip_ire_req(q, mp);
return;
case M_CTL:
break;
TUN_HELLO) {
return;
}
break;
return;
}
/* M_CTL messages are used by ARP to tell us things. */
break;
case AR_ENTRY_SQUERY:
ip_wput_ctl(q, mp);
return;
case AR_CLIENT_NOTIFY:
ip_arp_news(q, mp);
return;
case AR_DLPIOP_DONE:
/* qwriter_ip releases the refhold */
/* refhold on ill stream is ok without ILL_CAN_LOOKUP */
return;
case AR_ARP_CLOSING:
/*
* ARP (above us) is closing. If no ARP bringup is
* currently pending, ack the message so that ARP
* can complete its close. Also mark ill_arp_closing
* so that new ARP bringups will fail. If any
* ARP bringup is currently in progress, we will
* ack this when the current ARP bringup completes.
*/
if (!ill->ill_arp_bringup_pending) {
} else {
}
return;
case AR_ARP_EXTEND:
/*
* The ARP module above us is capable of duplicate
* address detection. Old ATM drivers will not send
* this message.
*/
return;
default:
break;
}
break;
case M_PROTO:
case M_PCPROTO:
/*
* The only PROTO messages we expect are ULP binds and
* copies of option negotiation acknowledgements.
*/
case O_T_BIND_REQ:
case T_BIND_REQ: {
/* Request can get queued in bind */
goto protonak;
}
/*
* Both TCP and UDP call ip_bind_{v4,v6}() directly
* instead of going through this path. We only get
* here in the following cases:
*
* a. Bind retries, where ipsq is non-NULL.
* transport, e.g. icmp for raw socket,
* in which case ipsq will be NULL.
*/
/* Don't increment refcnt if this is a re-entry */
return;
if (IPCL_IS_TCP(connp)) {
/*
* In the case of TCP endpoint we
* come here only for bind retries
*/
return;
} else if (IPCL_IS_UDP(connp)) {
/*
* In the case of UDP endpoint we
* come here only for bind retries
*/
return;
}
return;
}
case T_SVR4_OPTMGMT_REQ:
ip2dbg(("ip_wput: T_SVR4_OPTMGMT_REQ flags %x\n",
proto_str = "T_SVR4_OPTMGMT_REQ";
goto protonak;
}
ip_snmp_get, cr)) {
/*
* Call svr4_optcom_req so that it can
* generate the ack. We don't come here
* if this operation is being restarted.
* ip_restart_optmgmt will drop the conn ref.
* In the case of ipsec option after the ipsec
* load is complete conn_restart_ipsec_waiter
* drops the conn ref.
*/
if (ip_check_for_ipsec_opt(q, mp))
return;
if (err != EINPROGRESS) {
/* Operation is done */
}
}
return;
case T_OPTMGMT_REQ:
ip2dbg(("ip_wput: T_OPTMGMT_REQ\n"));
/*
* Note: No snmpcom_req support through new
* T_OPTMGMT_REQ.
* Call tpi_optcom_req so that it can
* generate the ack.
*/
proto_str = "T_OPTMGMT_REQ";
goto protonak;
}
/*
* We don't come here for restart. ip_restart_optmgmt
* will drop the conn ref. In the case of ipsec option
* after the ipsec load is complete
* conn_restart_ipsec_waiter drops the conn ref.
*/
if (ip_check_for_ipsec_opt(q, mp))
return;
if (err != EINPROGRESS) {
/* Operation is done */
}
return;
case T_UNBIND_REQ:
proto_str = "T_UNBIND_REQ";
goto protonak;
}
return;
default:
/*
* Have to drop any DLPI messages coming down from
* arp (such as an info_req which would cause ip
* to receive an extra info_ack if it was passed
* through.
*/
ip1dbg(("ip_wput_nondata: dropping M_PROTO %d\n",
return;
}
/* NOTREACHED */
case IRE_DB_TYPE: {
/*
* This is a response back from a resolver. It
* consists of a message chain containing:
* IRE_MBLK-->LL_HDR_MBLK->pkt
* The IRE_MBLK is the one we allocated in ip_newroute.
* The LL_HDR_MBLK is the DLPI header to use to get
* the attached packet, and subsequent ones for the
* same destination, transmitted.
*/
break;
/*
* First, check to make sure the resolution succeeded.
* If it failed, the second mblk will be empty.
* If it is, free the chain, dropping the packet.
* (We must ire_delete the ire; that frees the ire mblk)
* We're doing this now to support PVCs for ATM; it's
* a partial xresolv implementation. When we fully implement
* xresolv interfaces, instead of freeing everything here
* we'll initiate neighbor discovery.
*
* For v4 (ARP and other external resolvers) the resolver
* frees the message, so no check is needed. This check
* is required, though, for a full xresolve implementation.
* Including this code here now both shows how external
* resolvers can NACK a resolution request using an
* existing design that has no specific provisions for NACKs,
* and also takes into account that the current non-ARP
* external resolver has been coded to use this method of
* NACKing for all IPv6 (xresolv) cases,
* whether our xresolv implementation is complete or not.
*
*/
/*
* XRESOLV interface.
*/
if (IN6_IS_ADDR_UNSPECIFIED(&gw_addr_v6)) {
} else {
B_FALSE);
}
}
}
return;
}
/*
* Split them into IRE_MBLK and pkt and feed it into
* ire_add_then_send. Then in ire_add_then_send
* the IRE will be added, and then the packet will be
* run back through ip_wput. This time it will make
* it to the wire.
*/
ip1dbg(("ip_wput_nondata: reply from external resolver \n"));
/*
* XRESOLV interface. Find the nce and put a copy
* of the dl_unitdata_req in nce_res_mp
*/
if (IN6_IS_ADDR_UNSPECIFIED(&gw_addr_v6)) {
B_FALSE);
} else {
}
/*
* We have to protect nce_res_mp here
* from being accessed by other threads
* while we change the mblk pointer.
* Other functions will also lock the nce when
* accessing nce_res_mp.
*
* The reason we change the mblk pointer
* here rather than copying the resolved address
* into the template is that, unlike with
* ethernet, we have no guarantee that the
* resolved address length will be
* smaller than or equal to the lla length
* with which the template was allocated,
* (for ethernet, they're equal)
* so we have to use the actual resolved
* address mblk - which holds the real
* dl_unitdata_req with the resolved address.
*
* Doing this is the same behavior as was
* previously used in the v4 ARP case.
*/
/*
* We do a fastpath probe here because
* we have resolved the address without
* using Neighbor Discovery.
* In the non-XRESOLV v6 case, the fastpath
* probe is done right after neighbor
* discovery completes.
*/
int res;
nce->nce_res_mp);
}
/*
* Now we have to clean out any packets
* that may have been queued on the nce
* while it was waiting for address resolution
* to complete.
*/
/*
* Retrieve ifindex stored in
* ip_rput_data_v6()
*/
ifindex =
if (inbound_ill != NULL)
} else
}
} else { /* nce is NULL; clean up */
return;
}
} else {
/*
* Link layer resolution succeeded. Recompute the
* ire_nce.
*/
return;
}
/*
* Someone resolved this before us;
* cleanup the res_mp. Since ire has
* not been added yet, the call to ire_add_v4
* from ire_add_then_send (when a dup is
* detected) will clean up the ire.
*/
} else {
}
/*
* this ire will not be added to the ire
* cache table, so we can set the ire_nce
* here, as there are no atomicity constraints.
*/
/*
* We are associating this nce with the ire
* so change the nce ref taken in
* ndp_lookup_v4() from
* NCE_REFHOLD to NCE_REFHOLD_NOTR
*/
} else {
}
}
return; /* All is well, the packet has been sent. */
}
case IRE_ARPRESOLVE_TYPE: {
break;
/*
* First, check to make sure the resolution succeeded.
* If it failed, the second mblk will be empty.
*/
/* cleanup the incomplete ire, free queued packets */
return;
}
/*
* update any incomplete nce_t found. we lookup the ctable
* and find the nce from the ire->ire_nce because we need
* to pass the ire to ip_xmit_v4 later, and can find both
* ire and nce in one lookup from the ctable.
*/
/*
* By the time we come back here from ARP
* the logical outgoing interface of the incomplete ire
* we added in ire_forward could have disappeared,
* causing the incomplete ire to also have
* dissapeared. So we need to retreive the
* proper ipif for the ire before looking
* in ctable; do the ctablelookup based on ire_ipif_seqid
*/
/* Get the outgoing ipif */
return;
}
ip1dbg(("logical intrf to incomplete ire vanished\n"));
return;
}
/*
* no ire was found; check if there is an nce
* for this lookup; if it has no ire's pointing at it
* cleanup.
*/
/*
* cleanup:
* We check for refcnt 2 (one for the nce
* hash list + 1 for the ref taken by
* ndp_lookup_v4) to check that there are
* no ire's pointing at the nce.
*/
}
return;
}
/*
* Someone resolved this before us;
* our response is not needed any more.
*/
} else {
/* existing dl_unitdata template */
}
}
/*
* The cached nce_t has been updated to be reachable;
* Set the IRE_MARK_UNCACHED flag and free the fake_ire.
*/
/*
* send out queued packets.
*/
return;
}
default:
break;
}
if (q->q_next) {
} else
return;
}
/*
* Process IP options in an outbound packet. Modify the destination if there
* is a source route option.
* Returns non-zero if something fails in which case an ICMP error has been
* sent and mp freed.
*/
static int
{
ip2dbg(("ip_wput_options\n"));
if (mctl_present) {
}
ip2dbg(("ip_wput_options: opt %d, len %d\n",
switch (optval) {
case IPOPT_SSRR:
case IPOPT_LSRR:
ip1dbg((
"ip_wput_options: bad option offset\n"));
(char *)ipha;
goto param_prob;
}
ip1dbg(("ip_wput_options: next hop 0x%x\n",
/*
* For strict: verify that dst is directly
* reachable.
*/
if (optval == IPOPT_SSRR) {
ip1dbg(("ip_wput_options: SSRR not"
" directly reachable: 0x%x\n",
goto bad_src_route;
}
}
break;
case IPOPT_RR:
ip1dbg((
"ip_wput_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_wput_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_wput_options: error processing IP options."));
/*
* Since ip_wput() isn't close to finished, we fill
* in enough of the header for credible error reporting.
*/
/* Failed */
return (-1);
}
return (-1);
/*
* Since ip_wput() isn't close to finished, we fill
* in enough of the header for credible error reporting.
*/
/* Failed */
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;
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 < ipst->ips_conn_drain_list_cnt; i++) {
}
}
static void
{
int i;
for (i = 0; i < ipst->ips_conn_drain_list_cnt; i++)
}
/*
* 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.
*
* The only possible calling sequence is ip_wsrv (on conn) -> ip_wput ->
* conn_drain_insert. Thus there can be only 1 instance of conn_drain_insert
* running at any time, on a given conn, since there can be only 1 service proc
* running on a queue at any time.
*/
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 {
}
}
/*
* This conn is closing, and we are called from ip_close. OR
* This conn has been serviced by ip_wsrv, and we need to do the tail
* processing.
* If this conn is part of the drain list, we may need to sustain the drain
* process by qenabling the next conn in the drain list. We may also need to
* remove this conn from the list, if it is done.
*/
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;
}
/*
* 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.
*/
/*
* This conn is the last in this list. This round
* of draining is complete. If idl_repeat is set,
* it means another flow enabling has happened from
* of draining.
* If there are more than 2 conns in the drain list,
* do a left rotate by 1, so that all conns except the
* conn at the head move towards the head by 1, and the
* the conn at the head goes to the tail. This attempts
* a more even share for all queues that are being
* drained.
*/
}
if (idl->idl_repeat) {
idl->idl_repeat = 0;
} else {
}
} else {
/*
* If the next queue that we are now qenable'ing,
* is closing, it will remove itself from this list
* and qenable the subsequent queue in ip_close().
* Serialization is acheived thru idl_lock.
*/
}
}
/*
* Remove ourself from the drain list, if we did not do
* a putbq, 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 {
}
}
}
/*
* Write service routine. Shared perimeter entry point.
* ip_wsrv can be called in any of the following ways.
* 1. The device queue's messages has fallen below the low water mark
* and STREAMS has backenabled the ill_wq. We walk thru all the
* the drain lists and backenable the first conn in each list.
* 2. The above causes STREAMS to run ip_wsrv on the conn_wq of the
* qenabled non-tcp upper layers. We start dequeing messages and call
* ip_wput for each message.
*/
void
{
if (q->q_next) {
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 if check above.
*/
ip1dbg(("ip_wsrv: walking\n"));
}
return;
}
/*
* 1. Set conn_draining flag to signal that service is active.
*
* 2. ip_output determines whether it has been called from service,
* based on the last parameter. If it is IP_WSRV it concludes it
* has been called from service.
*
* 3. Message ordering is preserved by the following logic.
* i. A directly called ip_output (i.e. not thru service) will queue
* the message at the tail, if conn_draining is set (i.e. service
* is running) or if q->q_first is non-null.
*
* ii. If ip_output is called from service, and if ip_output cannot
* putnext due to flow control, it does a putbq.
*
* 4. noenable the queue so that a putbq from ip_wsrv does not reenable
* (causing an infinite loop).
*/
noenable(q);
if (connp->conn_did_putbq) {
/* ip_wput did a putbq */
break;
}
}
/*
* At this point, a thread coming down from top, calling
* ip_wput, may end up queueing the message. We have not yet
* enabled the queue, so ip_wsrv won't be called again.
* To avoid this race, check q->q_first again (in the loop)
* If the other thread queued the message before we call
* enableok(), we will catch it in the q->q_first check.
* If the other thread queues the message after we call
* enableok(), ip_wsrv will be called again by STREAMS.
*/
connp->conn_draining = 0;
enableok(q);
}
/* Enable the next conn for draining */
connp->conn_did_putbq = 0;
}
/*
* Walk the list of all conn's calling the function provided with the
* specified argument for each. Note that this only walks conn's that
* have been bound.
* Applies to both IPv4 and IPv6.
*/
static void
{
}
/*
* 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++) {
continue;
}
/*
* If this list is not being drained currently by
* an ip_wsrv thread, start the process.
*/
} else {
}
}
}
/*
* Walk an conn hash table of `count' buckets, calling func for each entry.
*/
static void
{
while (count-- > 0) {
if (zoneid == GLOBAL_ZONEID ||
}
}
connfp++;
}
}
/* ipcl_walk routine invoked for ip_conn_report for each conn. */
static void
{
char buf1[INET6_ADDRSTRLEN];
char buf2[INET6_ADDRSTRLEN];
if (buf_len <= 0)
return;
"%5d %s/%05d %s/%05d\n",
} else {
}
}
/*
* Named Dispatch routine to produce a formatted report on all conns
* that are listed in one of the fanout tables.
* This report is accessed by using the ndd utility to "get" ND variable
* "ip_conn_status".
*/
/* ARGSUSED */
static int
{
(void) mi_mpprintf(mp,
"CONN " MI_COL_HDRPAD_STR
"rfq " MI_COL_HDRPAD_STR
"stq " MI_COL_HDRPAD_STR
" zone local remote");
/*
* Because of the ndd constraint, at most we can have 64K buffer
* to put in all conn info. So to be more efficient, just
* allocate a 64K buffer here, assuming we need that large buffer.
*/
/* The following may work even if we cannot get a large buf. */
return (0);
}
return (0);
}
/*
* Determine if the ill and multicast aspects of that packets
* "matches" the conn.
*/
{
/*
* conn_incoming_ill is set by IP_BOUND_IF which limits
* unicast, broadcast and multicast reception to
* conn_incoming_ill. conn_wantpacket itself is called
* only for BROADCAST and multicast.
*
* 1) ip_rput supresses duplicate broadcasts if the ill
* is part of a group. Hence, we should be receiving
* just one copy of broadcast for the whole group.
* Thus, if it is part of the group the packet could
* come on any ill of the group and hence we need a
* match on the group. Otherwise, match on ill should
* be sufficient.
*
* 2) ip_rput does not suppress duplicate multicast packets.
* If there are two interfaces in a ill group and we have
* 2 applications (conns) joined a multicast group G on
* both the interfaces, ilm_lookup_ill filter in ip_rput
* will give us two packets because we join G on both the
* interfaces rather than nominating just one interface
* for receiving multicast like broadcast above. So,
* we have to call ilg_lookup_ill to filter out duplicate
* copies, if ill is part of a group.
*/
return (B_FALSE);
return (B_FALSE);
}
}
return (B_TRUE);
/*
* The conn is in a different zone; we need to check that this
* broadcast address is configured in the application's zone and
* on one ill in the group.
*/
return (B_FALSE);
return (B_TRUE);
} else {
return (B_FALSE);
}
}
if ((fanout_flags & IP_FF_NO_MCAST_LOOP) &&
/*
* Loopback case: the sending endpoint has IP_MULTICAST_LOOP
* disabled, therefore we don't dispatch the multicast packet to
* the sending zone.
*/
return (B_FALSE);
}
/*
* Multicast packet on the loopback interface: we only match
* conns who joined the group in the specified zone.
*/
return (B_FALSE);
}
if (connp->conn_multi_router) {
/* multicast packet and multicast router socket: send up */
return (B_TRUE);
}
return (found);
}
/*
* Finish processing of "arp_up" when AR_DLPIOP_DONE is received from arp.
*/
/* ARGSUSED */
static void
{
int err = 0;
/*
* We have now received the arp bringup completion message
* from ARP. Mark the arp bringup as done. Also if the arp
* stream has already started closing, send up the AR_ARP_CLOSING
* ack now since ARP is waiting in close for this ack.
*/
ill->ill_arp_bringup_pending = 0;
if (ill->ill_arp_closing) {
/* Let's reuse the mp for sending the ack */
} else {
}
/* bringup was aborted by the user */
return;
}
/*
* If an IOCTL is waiting on this (ipsq_current_ioctl != 0), then we
* must have an associated conn_t. Otherwise, we're bringing this
* interface back up as part of handling an asynchronous event (e.g.,
* physical address change).
*/
if (ipsq->ipsq_current_ioctl != 0) {
q = CONNP_TO_WQ(connp);
} else {
}
/*
* If the DL_BIND_REQ fails, it is noted
* in arc_name_offset.
*/
if (err == 0) {
ip0dbg(("ip_arp_done: init failed\n"));
} else {
ip0dbg(("ip_arp_done: init failed\n"));
}
} else {
ip0dbg(("ip_arp_done: DL_BIND_REQ failed\n"));
}
if (err == EINPROGRESS)
return;
}
if (ill->ill_up_ipifs)
/*
* The operation must complete without EINPROGRESS since
* ipsq_pending_mp_get() has removed the mblk from ipsq_pending_mp.
* Otherwise, the operation will be stuck forever in the ipsq.
*/
if (ipsq->ipsq_current_ioctl != 0)
else
}
/* 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 the resulting
* mblk (*mpp) is NULL. proc indicates the callout position for
* this packet and ill_index is the interface this packet on or will leave
* on (inbound and outbound resp.).
*/
void
{
int rc = 0;
#define IP_CLASS "ip"
/* If the classifier is not loaded, return */
return;
}
/* Allocate the packet structure */
if (rc != 0) {
return;
}
/* Allocate the private structure */
if (rc != 0) {
return;
}
/* Invoke the classifier */
if (rc != 0) {
}
} else {
}
}
/*
* all the interfaces crossed by the related multirt routes.
* The call is considered successful if the operation succeeds
* on at least one interface.
*/
static int
{
int error = 0;
continue;
continue;
/* No resolver exists for the gateway; skip this ire. */
continue;
/*
* This function can return EINPROGRESS. If so the operation
* will be restarted from ip_restart_optmgmt which will
* call ip_opt_set and option processing will restart for
* this option. So we may end up calling 'fn' more than once.
* This requires that 'fn' is idempotent except for the
* return value. The operation is considered a success if
* it succeeds at least once on any one interface.
*/
if (error == 0)
if (ip_debug > 0) {
char *ksym;
ip2dbg(("ip_multirt_apply_membership: "
"called %s, multirt group 0x%08x via itf 0x%08x, "
"error %d [success %u]\n",
}
if (error == EINPROGRESS) {
return (error);
}
}
/*
* Consider the call as successful if we succeeded on at least
* one interface. Otherwise, return the last encountered error.
*/
}
/*
* Issue a warning regarding a route crossing an interface with an
* incorrect MTU. Only one message every 'ip_multirt_log_interval'
* amount of time is logged.
*/
static void
{
char buf[INET_ADDRSTRLEN];
/* Convert interval in ms to hrtime in ns */
current) {
"to %s, incorrect MTU %u (expected %u)\n",
}
}
/*
* Get the CGTP (multirouting) filtering status.
* If 0, the CGTP hooks are transparent.
*/
/* ARGSUSED */
static int
{
/*
* Only applies to the shared stack since the filter_ops
* do not carry an ip_stack_t or zoneid.
*/
return (ENOTSUP);
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);
/*
* Only applies to the shared stack since the filter_ops
* do not carry an ip_stack_t or zoneid.
*/
return (ENOTSUP);
return (EINVAL);
}
/*
* Do not enable CGTP filtering - thus preventing the hooks
* from being invoked - if the version number of the
* filtering module hooks does not match.
*/
if ((ip_cgtp_filter_ops != NULL) &&
"(module hooks version %d, expecting %d)\n",
return (ENOTSUP);
}
if ((!*ip_cgtp_filter_value) && new_value) {
ip_cgtp_filter_ops == NULL ?
" (module not loaded)" : "");
}
if (*ip_cgtp_filter_value && (!new_value)) {
ip_cgtp_filter_ops == NULL ?
" (module not loaded)" : "");
}
if (ip_cgtp_filter_ops != NULL) {
int res;
if (res)
return (res);
}
return (0);
}
/*
* Return the expected CGTP hooks version number.
*/
int
ip_cgtp_filter_supported(void)
{
int ret;
return (-1);
return (ret);
}
/*
* CGTP hooks can be registered by directly touching ip_cgtp_filter_ops
* or by invoking this function. In the first case, the version number
* of the registered structure is checked at hooks activation time
* in ip_cgtp_filter_set().
*
* Only applies to the shared stack since the filter_ops
* do not carry an ip_stack_t or zoneid.
*/
int
{
return (ENOTSUP);
return (EINVAL);
return (0);
}
static squeue_func_t
ip_squeue_switch(int val)
{
switch (val) {
case IP_SQUEUE_ENTER_NODRAIN:
break;
case IP_SQUEUE_ENTER:
rval = squeue_enter;
break;
default:
break;
}
return (rval);
}
/* ARGSUSED */
static int
{
int *v = (int *)addr;
long new_value;
return (EPERM);
return (EINVAL);
*v = new_value;
return (0);
}
/* ARGSUSED */
static int
{
int *v = (int *)addr;
long new_value;
return (EPERM);
return (EINVAL);
*v = new_value;
return (0);
}
/*
* Handle changes to ipmp_hook_emulation ndd variable.
* Need to update phyint_hook_ifindex.
* Also generate a nic plumb event should a new ifidex be assigned to a group.
*/
static void
{
char *groupname;
int namelen;
/*
* Group indicies are stored in the phyint - a common structure
* to both IPv4 and IPv6.
*/
/* Ignore the ones that do not have a group */
if (phyi->phyint_groupname_len == 0)
continue;
/*
* Look for other phyint in group.
*/
phyi->phyint_groupname_len = 0;
/* Restore */
if (ipst->ips_ipmp_hook_emulation) {
/*
* If the group already exists and has already
* been assigned a group ifindex, we use the existing
* group_ifindex, otherwise we pick a new group_ifindex
* here.
*/
phyi_tmp->phyint_group_ifindex != 0) {
} else {
/* XXX We need a recovery strategy here. */
if (!ip_assign_ifindex(
"ip_assign_ifindex() failed");
}
} else {
phyi->phyint_group_ifindex = 0;
}
if (ipst->ips_ipmp_hook_emulation)
else
/*
* For IP Filter to find out the relationship between
* names and interface indicies, we need to generate
* a NE_PLUMB event when a new group can appear.
* We always generate events when a new interface appears
* (even when ipmp_hook_emulation is set) so there
* is no need to generate NE_PLUMB events when
* ipmp_hook_emulation is turned off.
* And since it isn't critical for IP Filter to get
* the NE_UNPLUMB events we skip those here.
*/
if (new_group) {
/*
* First phyint in group - generate group PLUMB event.
* Since we are not running inside the ipsq we do
* the dispatch immediately.
*/
else
}
}
}
}
/* ARGSUSED */
static int
{
int *v = (int *)addr;
long new_value;
return (EINVAL);
if (*v != new_value) {
*v = new_value;
}
return (0);
}
static void *
{
{ "ipsec_fanout_proto", KSTAT_DATA_UINT64 },
{ "ip_udp_fannorm", KSTAT_DATA_UINT64 },
{ "ip_udp_fanmb", KSTAT_DATA_UINT64 },
{ "ip_udp_fanothers", KSTAT_DATA_UINT64 },
{ "ip_udp_fast_path", KSTAT_DATA_UINT64 },
{ "ip_udp_slow_path", KSTAT_DATA_UINT64 },
{ "ip_udp_input_err", KSTAT_DATA_UINT64 },
{ "ip_tcppullup", KSTAT_DATA_UINT64 },
{ "ip_tcpoptions", KSTAT_DATA_UINT64 },
{ "ip_multipkttcp", KSTAT_DATA_UINT64 },
{ "ip_tcp_fast_path", KSTAT_DATA_UINT64 },
{ "ip_tcp_slow_path", KSTAT_DATA_UINT64 },
{ "ip_tcp_input_error", KSTAT_DATA_UINT64 },
{ "ip_db_ref", KSTAT_DATA_UINT64 },
{ "ip_notaligned1", KSTAT_DATA_UINT64 },
{ "ip_notaligned2", KSTAT_DATA_UINT64 },
{ "ip_multimblk3", KSTAT_DATA_UINT64 },
{ "ip_multimblk4", KSTAT_DATA_UINT64 },
{ "ip_ipoptions", KSTAT_DATA_UINT64 },
{ "ip_classify_fail", KSTAT_DATA_UINT64 },
{ "ip_opt", KSTAT_DATA_UINT64 },
{ "ip_udp_rput_local", 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_in_sw_cksum", KSTAT_DATA_UINT64 },
{ "ip_trash_ire_reclaim_calls", KSTAT_DATA_UINT64 },
{ "ip_trash_ire_reclaim_success", KSTAT_DATA_UINT64 },
{ "ip_ire_arp_timer_expired", KSTAT_DATA_UINT64 },
{ "ip_ire_redirect_timer_expired", KSTAT_DATA_UINT64 },
{ "ip_ire_pmtu_timer_expired", KSTAT_DATA_UINT64 },
{ "ip_input_multi_squeue", 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_tcp_out_sw_cksum_bytes", 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 },
{ "ip_udp_out_sw_cksum_bytes", KSTAT_DATA_UINT64 },
{ "ip_frag_mdt_pkt_out", KSTAT_DATA_UINT64 },
{ "ip_frag_mdt_discarded", KSTAT_DATA_UINT64 },
{ "ip_frag_mdt_allocfail", KSTAT_DATA_UINT64 },
{ "ip_frag_mdt_addpdescfail", KSTAT_DATA_UINT64 },
{ "ip_frag_mdt_allocd", 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 },
};
0, stackid);
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 },
};
0, stackid);
return (NULL);
return (ksp);
}
static void
{
}
}
static int
{
netstack_t *ns;
return (EIO);
if (rw == KSTAT_WRITE)
return (EACCES);
return (-1);
return (-1);
}
return (0);
}
/*
* 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
{
if (mctl_present) {
} else {
}
return;
}
if (!canputnext(rq)) {
return;
}
return;
}
}
/*
* We probably should not send M_CTL message up to
* raw socket.
*/
if (mctl_present)
/* Initiate IPPF processing here if needed. */
return;
}
}
((connp->conn_ip_recvpktinfo ||
(flags & IP_FF_IPINFO))) {
int in_flags = 0;
/*
* Since sctp does not support IP_RECVPKTINFO for v4, only pass
* IPF_RECVIF.
*/
}
if (connp->conn_recvslla) {
in_flags |= IPF_RECVSLLA;
}
if (isv4) {
} else {
return;
}
}
}
/*
* We are sending the IPSEC_IN message also up. Refer
* to comments above this function.
*/
}
{ \
}
/*
* This function should be called only if all packet processing
* including fragmentation is complete. Callers of this function
* must set mp->b_prev to one of these values:
* {0, IPP_FWD_OUT, IPP_LOCAL_OUT}
* prior to handing over the mp as first argument to this function.
*
* If the ire passed by caller is incomplete, this function
* queues the packet and if necessary, sends ARP request and bails.
* If the ire 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.
*
* NOTE: IPSEC will only call this function with fully resolved
* ires if hw acceleration is involved.
* TODO list :
* a Handle M_MULTIDATA so that
* tcp_multisend->tcp_multisend_data can
* call ip_xmit_v4 directly
* b Handle post-ARP work for fragments so that
* ip_wput_frag can call this function.
*/
{
queue_t *q;
int ill_index;
int pkt_len;
case ND_REACHABLE:
/* If there are other queued packets, queue this packet */
}
/*
* Flush the queue. In the common case, where the
* ARP is already resolved, it will go through the
* while loop only once.
*/
/*
* This info is needed for IPQOS to do COS marking
* in ip_wput_attach_llhdr->ip_process.
*/
/* set up ill index for outbound qos processing */
goto next_mp;
}
/* non-ipsec hw accel case */
/* send it */
if (proc == IPP_FWD_OUT) {
} else {
}
if (flow_ctl_enabled || canputnext(q)) {
if (proc == IPP_FWD_OUT) {
}
pkt_len);
} else {
}
} else {
/*
* Safety Pup says: make sure this
* is going to the right interface!
*/
int ifindex =
if (ifindex !=
} else {
pkt_len);
}
}
} /* while (mp != NULL) */
if (xmit_drop)
return (SEND_FAILED);
else
return (SEND_PASSED);
case ND_INITIAL:
case ND_INCOMPLETE:
/*
* While we do send off packets to dests that
* use fully-resolved CGTP routes, we do not
* handle unresolved CGTP routes.
*/
/* queue the packet */
}
(ipsec_out_t *), io);
return (LOOKUP_IN_PROGRESS);
}
/*
* Note that ire_add() (called from ire_forward())
* holds a ref on the ire until ARP is completed.
*/
return (LOOKUP_IN_PROGRESS);
default:
ASSERT(0);
return (LLHDR_RESLV_FAILED);
}
}
/*
* 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 ip6_pkt_t.
*/
void
{
ipp->ipp_hopoptslen = 0;
}
ipp->ipp_rtdstoptslen = 0;
}
ipp->ipp_dstoptslen = 0;
}
ipp->ipp_rthdrlen = 0;
}
}