ip_fil_solaris.c revision 40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5
/*
* Copyright (C) 1993-2001, 2003 by Darren Reed.
*
* See the IPFILTER.LICENCE file for details on licencing.
*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#if !defined(lint)
static const char sccsid[] = "@(#)ip_fil_solaris.c 1.7 07/22/06 (C) 1993-2000 Darren Reed";
static const char rcsid[] = "@(#)$Id: ip_fil_solaris.c,v 2.62.2.19 2005/07/13 21:40:46 darrenr Exp $";
#endif
#include <sys/cred_impl.h>
#include <sys/dditypes.h>
#include <netinet/in_systm.h>
#include "netinet/ip_compat.h"
#ifdef USE_INET6
#endif
#include "netinet/ip_state.h"
#include "netinet/ip_proxy.h"
#include "netinet/ipf_stack.h"
#ifdef IPFILTER_LOOKUP
# include "netinet/ip_lookup.h"
#endif
void *));
void *));
void *));
#if SOLARIS2 < 10
#if SOLARIS2 >= 7
# if SOLARIS2 >= 8
int *ip_forwarding = NULL;
# else
# endif
#else
#endif
#endif
/* ------------------------------------------------------------------------ */
/* Function: ipldetach */
/* Returns: int - 0 == success, else error. */
/* Parameters: Nil */
/* */
/* This function is responsible for undoing anything that might have been */
/* done in a call to iplattach(). It must be able to clean up from a call */
/* to iplattach() that did not succeed. Why might that happen? Someone */
/* configures a table to be so large that we cannot allocate enough memory */
/* for it. */
/* ------------------------------------------------------------------------ */
{
#if SOLARIS2 < 10
if (ip_forwarding != NULL)
*ip_forwarding = 0;
#if SOLARIS2 >= 8
if (ip6_forwarding != NULL)
*ip6_forwarding = 0;
#endif
}
#endif
/*
* This lock needs to be dropped around the net_hook_unregister calls
* because we can deadlock here with:
* W(ipf_global)->R(hook_family)->W(hei_lock) (this code path) vs
* R(hook_family)->R(hei_lock)->R(ipf_global) (active hook running)
*/
do { \
} \
} \
} \
} while (0)
/*
* Remove IPv6 Hooks
*/
goto detach_failed;
}
/*
* Remove IPv4 Hooks
*/
goto detach_failed;
}
#ifdef IPFDEBUG
#endif
ifs->ifs_ipf_locks_done = 0;
}
return -1;
return 0;
return -1;
}
{
#if SOLARIS2 < 10
int i;
#endif
#ifdef IPFDEBUG
#endif
#ifdef _KERNEL
ifs->ifs_fr_update_ipid = 0;
#else
#endif
#if defined(IPFILTER_DEFAULT_BLOCK)
#else
#endif
if (fr_initialise(ifs) < 0)
return -1;
"ipfilter_hook4_nicevents", ifs);
"ipfilter_hook4_in", ifs);
"ipfilter_hook4_out", ifs);
"ipfilter_hook4_loop_in", ifs);
"ipfilter_hook4_loop_out", ifs);
/*
* If we hold this lock over all of the net_hook_register calls, we
* can cause a deadlock to occur with the following lock ordering:
* W(ipf_global)->R(hook_family)->W(hei_lock) (this code path) vs
* R(hook_family)->R(hei_lock)->R(ipf_global) (packet path)
*/
/*
* Add IPv4 hooks
*/
goto hookup_failed;
if (!ifs->ifs_hook4_nic_events)
goto hookup_failed;
if (!ifs->ifs_hook4_physical_in)
goto hookup_failed;
if (!ifs->ifs_hook4_physical_out)
goto hookup_failed;
if (ifs->ifs_ipf_loopback) {
ifs->ifs_ipfhook4_loop_in) == 0);
if (!ifs->ifs_hook4_loopback_in)
goto hookup_failed;
ifs->ifs_ipfhook4_loop_out) == 0);
if (!ifs->ifs_hook4_loopback_out)
goto hookup_failed;
}
/*
* Add IPv6 hooks
*/
goto hookup_failed;
"ipfilter_hook6_nicevents", ifs);
"ipfilter_hook6_in", ifs);
"ipfilter_hook6_out", ifs);
"ipfilter_hook6_loop_in", ifs);
"ipfilter_hook6_loop_out", ifs);
if (!ifs->ifs_hook6_nic_events)
goto hookup_failed;
if (!ifs->ifs_hook6_physical_in)
goto hookup_failed;
if (!ifs->ifs_hook6_physical_out)
goto hookup_failed;
if (ifs->ifs_ipf_loopback) {
ifs->ifs_ipfhook6_loop_in) == 0);
if (!ifs->ifs_hook6_loopback_in)
goto hookup_failed;
ifs->ifs_ipfhook6_loop_out) == 0);
if (!ifs->ifs_hook6_loopback_out)
goto hookup_failed;
}
/*
* Reacquire ipf_global, now it is safe.
*/
/* Do not use private interface ip_params_arr[] in Solaris 10 */
#if SOLARIS2 < 10
#if SOLARIS2 >= 8
#endif
/*
* XXX - There is no terminator for this array, so it is not possible
* to tell if what we are looking for is missing and go off the end
* of the array.
*/
#if SOLARIS2 <= 8
for (i = 0; ; i++) {
"ip_path_mtu_discovery")) {
}
#if SOLARIS2 < 8
"ip_forwarding")) {
}
#else
"ip6_forwarding")) {
}
#endif
#if SOLARIS2 >= 8
ip6_forwarding != NULL &&
#endif
ip_forwarding != NULL)
break;
}
#endif
if (ip_forwarding != NULL)
*ip_forwarding = 1;
#if SOLARIS2 >= 8
if (ip6_forwarding != NULL)
*ip6_forwarding = 1;
#endif
}
#endif
return 0;
return -1;
}
int set;
{
return EFAULT;
ifs->ifs_ipfhook4_loop_in) == 0);
if (!ifs->ifs_hook4_loopback_in)
return EINVAL;
ifs->ifs_ipfhook4_loop_out) == 0);
if (!ifs->ifs_hook4_loopback_out)
return EINVAL;
ifs->ifs_ipfhook6_loop_in) == 0);
if (!ifs->ifs_hook6_loopback_in)
return EINVAL;
ifs->ifs_ipfhook6_loop_out) == 0);
if (!ifs->ifs_hook6_loopback_out)
return EINVAL;
ifs->ifs_ipf_loopback = 0;
if (ifs->ifs_hook4_loopback_in)
return EBUSY;
if (ifs->ifs_hook4_loopback_out)
return EBUSY;
if (ifs->ifs_hook6_loopback_in)
return EBUSY;
if (ifs->ifs_hook6_loopback_out)
return EBUSY;
}
return 0;
}
/*
* Filter ioctl interface.
*/
/*ARGSUSED*/
int cmd;
#if SOLARIS2 >= 7
#else
int *data;
#endif
int mode;
int *rp;
{
#ifdef IPFDEBUG
#endif
if (IPL_LOGMAX < unit)
return ENXIO;
/*
* As we're calling ipf_find_stack in user space, from a given zone
* to find the stack pointer for this zone, there is no need to have
*/
if (ifs->ifs_fr_running <= 0) {
if (unit != IPL_LOGIPF) {
return EIO;
}
return EIO;
}
}
if (error != -1) {
return error;
}
error = 0;
switch (cmd)
{
case SIOCFRENB :
else {
sizeof(enable));
if (error != 0) {
break;
}
}
break;
case SIOCIPFSET :
break;
}
/* FALLTHRU */
case SIOCIPFGETNEXT :
case SIOCIPFGET :
break;
case SIOCSETFF :
else {
sizeof(ifs->ifs_fr_flags));
if (error != 0)
}
break;
case SIOCIPFLP :
sizeof(tmp));
if (error != 0)
else
break;
case SIOCGETFF :
sizeof(ifs->ifs_fr_flags));
if (error != 0)
break;
case SIOCFUNCL :
break;
case SIOCINAFR :
case SIOCRMAFR :
case SIOCADAFR :
case SIOCZRLST :
else
break;
case SIOCINIFR :
case SIOCRMIFR :
case SIOCADIFR :
else
break;
case SIOCSWAPA :
else {
sizeof(ifs->ifs_fr_active));
if (error != 0)
else
}
break;
case SIOCGETFS :
break;
case SIOCFRZST :
else
break;
case SIOCIPFFL :
else {
sizeof(tmp));
if (!error) {
sizeof(tmp));
if (error != 0)
} else
}
break;
#ifdef USE_INET6
case SIOCIPFL6 :
else {
sizeof(tmp));
if (!error) {
sizeof(tmp));
if (error != 0)
} else
}
break;
#endif
case SIOCSTLCK :
if (error == 0) {
} else
break;
#ifdef IPFILTER_LOG
case SIOCIPFFB :
else {
sizeof(tmp));
if (error)
}
break;
#endif /* IPFILTER_LOG */
case SIOCFRSYN :
else {
error = 0;
}
break;
case SIOCGFRST :
break;
case FIONREAD :
#ifdef IPFILTER_LOG
if (error != 0)
#endif
break;
case SIOCIPFITER :
break;
case SIOCGENITER :
break;
case SIOCIPFDELTOK :
if (error != 0) {
} else {
}
break;
default :
break;
}
return error;
}
int enable;
{
int error;
if (!enable) {
if (error == 0)
return error;
}
if (ifs->ifs_fr_running > 0)
return 0;
if (error == 0) {
(void *)ifs,
hz);
}
} else {
}
return error;
}
char *name;
int v;
{
if (v == 4)
else if (v == 6)
else
return 0;
}
/*
* routines below for saving IP headers to buffer
*/
/*ARGSUSED*/
{
#ifdef IPFDEBUG
#endif
return ENXIO;
return min;
}
/*ARGSUSED*/
{
#ifdef IPFDEBUG
#endif
return min;
}
#ifdef IPFILTER_LOG
/*
* both of these must operate with at least splnet() lest they be
* called during packet processing and cause an inconsistancy to appear in
* the filter lists.
*/
/*ARGSUSED*/
{
int ret;
/*
* As we're calling ipf_find_stack in user space, from a given zone
* to find the stack pointer for this zone, there is no need to have
*/
# ifdef IPFDEBUG
# endif
return EIO;
}
# ifdef IPFILTER_SYNC
return ipfsync_read(uio);
}
# endif
return ret;
}
#endif /* IPFILTER_LOG */
/*
* both of these must operate with at least splnet() lest they be
* called during packet processing and cause an inconsistancy to appear in
* the filter lists.
*/
{
/*
* As we're calling ipf_find_stack in user space, from a given zone
* to find the stack pointer for this zone, there is no need to have
*/
#ifdef IPFDEBUG
#endif
return EIO;
}
#ifdef IPFILTER_SYNC
return ipfsync_write(uio);
#endif /* IPFILTER_SYNC */
return ENXIO;
}
/*
* fr_send_reset - this could conceivably be a call to tcp_respond(), but that
* requires a large amount of setting up and isn't any more efficient.
*/
int fr_send_reset(fin)
{
mblk_t *m;
#ifdef USE_INET6
#endif
return -1;
#ifndef IPFILTER_CKSUM
return -1;
#endif
#ifdef USE_INET6
else
#endif
return -1;
m->b_rptr += 64;
} else {
}
#ifdef USE_INET6
} else
#endif
{
}
return fr_send_ip(fin, m, &m);
}
/*
* Function: fr_send_ip
* Returns: 0: success
* -1: failed
* Parameters:
* fin: packet information
* m: the message block where ip head starts
*
* Send a new packet through the IP stack.
*
* For IPv4 packets, ip_len must be in host byte order, and ip_v,
* ip_ttl, ip_off, and ip_sum are ignored (filled in by this
* function).
*
* For IPv6 packets, ip6_flow, ip6_vfc, and ip6_hlim are filled
* in by this function.
*
* All other portions of the packet must be in on-the-wire format.
*/
/*ARGSUSED*/
{
int i, hlen;
#ifdef USE_INET6
} else
#endif
{
#if SOLARIS2 >= 10
#else
if (ip_ttl_ptr != NULL)
else
if (ip_mtudisc != NULL)
else
#endif
/*
* fr_fastroute, it expects them to be in host byte order but
* ipf_cksum expects them to be in network byte order.
*/
}
return i;
}
int type;
int dst;
{
#ifdef USE_INET6
#endif
mblk_t *m;
#ifdef USE_INET6
#endif
return -1;
#ifdef USE_INET6
return -1;
#endif
#ifndef IPFILTER_CKSUM
return -1;
#endif
#ifdef USE_INET6
if (type == ICMP6_DST_UNREACH)
} else
#endif
{
{
case ICMP_ECHO :
case ICMP_TSTAMP :
case ICMP_IREQ :
case ICMP_MASKREQ :
break;
default :
return 0;
}
}
return -1;
m->b_rptr += 64;
#ifdef USE_INET6
int csz;
if (dst == 0) {
FREE_MB_T(m);
return -1;
}
} else
} else
#endif
{
if (dst == 0) {
FREE_MB_T(m);
return -1;
}
} else {
}
}
/*
* Need to exit out of these so we don't recursively call rw_enter
* from fr_qout.
*/
return fr_send_ip(fin, m, &m);
}
#ifndef _KERNEL
#include <stdio.h>
#endif
/*
* Print out warning message at rate-limited speed.
*/
{
char msg_buf[256];
int need_printed = 0;
now = ddi_get_time();
/* make sure, no multiple entries */
need_printed = 1;
}
if (need_printed) {
#ifdef _KERNEL
#else
#endif
}
}
/*
* return the first IP Address associated with an interface
*/
/*ARGSUSED*/
int v, atype;
void *ifptr;
{
void *array;
switch (v)
{
case 4:
break;
case 6:
break;
default:
break;
}
return -1;
switch (atype)
{
case FRI_PEERADDR :
break;
case FRI_BROADCAST :
type[0] = NA_BROADCAST;
break;
default :
type[0] = NA_ADDRESS;
break;
}
return -1;
if (v == 6) {
}
}
{
static int iss_seq_off = 0;
/*
* Compute the base value of the ISS. It is a hash
* of (saddr, sport, daddr, dport, secret).
*/
/*
* Now increment our "timer", and add it in to
* the computed value.
*
* XXX Use `addin'?
* XXX TCP_ISSINCR too large to use?
*/
iss_seq_off += 0x00010000;
newiss += iss_seq_off;
return newiss;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_nextipid */
/* Returns: int - 0 == success, -1 == error (packet should be droppped) */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* Returns the next IPv4 ID to use for this packet. */
/* ------------------------------------------------------------------------ */
{
} else
return id;
}
#ifndef IPFILTER_CKSUM
/* ARGSUSED */
#endif
{
#ifdef IPFILTER_CKSUM
#endif
}
#ifdef USE_INET6
# ifndef IPFILTER_CKSUM
/* ARGSUSED */
# endif
{
# ifdef IPFILTER_CKSUM
# endif
}
#endif /* USE_INET6 */
#if (SOLARIS2 < 7)
void fr_slowtimer()
#else
/*ARGSUSED*/
#endif
{
return;
}
ifs->ifs_fr_ticks++;
drv_usectohz(500000));
else
}
/* ------------------------------------------------------------------------ */
/* Function: fr_pullup */
/* Returns: NULL == pullup failed, else pointer to protocol header */
/* Parameters: m(I) - pointer to buffer where data packet starts */
/* fin(I) - pointer to packet information */
/* len(I) - number of bytes to pullup */
/* */
/* Attempt to move at least len bytes (from the start of the buffer) into a */
/* single buffer for ease of access. Operating system native functions are */
/* used to manage buffers - if necessary. If the entire packet ends up in */
/* a single buffer, set the FI_COALESCE flag even though fr_coalesce() has */
/* not been called. Both fin_ip and fin_dp are updated before exiting _IF_ */
/* and ONLY if the pullup succeeds. */
/* */
/* We assume that 'min' is a pointer to a buffer that is part of the chain */
/* of buffers that starts at *fin->fin_mp. */
/* ------------------------------------------------------------------------ */
int len;
{
char *ip;
if (m == NULL)
return NULL;
return ip;
else
dpoff = 0;
/*
* pfil_precheck ensures the IP header is on a 32bit
* aligned address so simply fail if that isn't currently
* the case (should never happen).
*/
int inc = 0;
if (ipoff > 0) {
if ((ipoff & 3) != 0) {
else
inc = 0;
}
}
/*
* XXX This is here as a work around for a bug with DEBUG
* XXX Solaris kernels. The problem is b_prev is used by IP
* XXX code as a way to stash the phyint_index for a packet,
* XXX this doesn't get reset by IP but freeb does an ASSERT()
* XXX for both of these to be NULL. See 6442390.
*/
m1 = m;
do {
} while (m1);
/*
* Need to preserve checksum information by copying them
* to newmp which heads the pulluped message.
*/
return NULL;
}
}
return ip;
}
/*
* Function: fr_verifysrc
* Returns: int (really boolean)
* Parameters: fin - packet information
*
* Check whether the packet has a valid source address for the interface on
* which the packet arrived, implementing the "fr_chksrc" feature.
* Returns true iff the packet's source address is valid.
*/
int fr_verifysrc(fin)
{
} else {
return (0);
}
/* Get the index corresponding to the if name */
}
/*
* Function: fr_fastroute
* Returns: 0: success;
* -1: failed
* Parameters:
* mb: the message block where ip head starts
* mpp: the pointer to the pointer of the orignal
* packet message
* fin: packet information
* fdp: destination interface information
* if it is NULL, no interface information provided.
*
* pfil_make_lay2_packet to search route, make lay-2 header
* ,and identify output queue for the IP packet.
* The destination address depends on the following conditions:
* 1: for fastroute rule, fdp is passed in as NULL, so the
* destination address is the IP Packet's destination address
* the interface name, this address is the as destination
* address. Otherwise IP Packet's destination address is used
*/
{
struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
#ifndef sparc
#endif
} else {
return (-1);
}
return -1;
/*
* If this is a duplicate mblk then we want ip to point at that
* data, not the original, if and only if it is already pointing at
* the current mblk data.
*
* Otherwise, if it's not a duplicate, and we're not already pointing
* at the current mblk data, then we want to ensure that the data
* points at ip.
*/
}
/*
* If there is another M_PROTO, we don't want it
*/
}
/*
* In case we're here due to "to <if>" being used with
* "keep state", check that we're going in the correct
* direction.
*/
goto bad_fastroute;
} else {
}
} else {
} else {
}
}
/*
* Clear the hardware checksum flags from packets that we are doing
* input processing on as leaving them set will cause the outgoing
* NIC (if it supports hardware checksum) to calculate them anew,
* using the old (correct) checksums as the pseudo value to start
* from.
*/
DB_CKSUMFLAGS(mb) = 0;
}
void *saveifp;
goto bad_fastroute;
}
#ifndef sparc
}
#endif
if (net_data_p) {
return (-1);
}
}
ifs->ifs_fr_frouteok[0]++;
return 0;
return -1;
}
/* ------------------------------------------------------------------------ */
/* Function: ipf_hook4_out */
/* Returns: int - 0 == packet ok, else problem, free packet if not done */
/* Parameters: event(I) - pointer to event */
/* info(I) - pointer to hook information for firewalling */
/* */
/* Calling ipf_hook. */
/* ------------------------------------------------------------------------ */
/*ARGSUSED*/
{
}
/*ARGSUSED*/
{
}
/* ------------------------------------------------------------------------ */
/* Function: ipf_hook4_in */
/* Returns: int - 0 == packet ok, else problem, free packet if not done */
/* Parameters: event(I) - pointer to event */
/* info(I) - pointer to hook information for firewalling */
/* */
/* Calling ipf_hook. */
/* ------------------------------------------------------------------------ */
/*ARGSUSED*/
{
}
/*ARGSUSED*/
{
}
/* ------------------------------------------------------------------------ */
/* Function: ipf_hook4_loop_out */
/* Returns: int - 0 == packet ok, else problem, free packet if not done */
/* Parameters: event(I) - pointer to event */
/* info(I) - pointer to hook information for firewalling */
/* */
/* Calling ipf_hook. */
/* ------------------------------------------------------------------------ */
/*ARGSUSED*/
{
}
/*ARGSUSED*/
{
}
/* ------------------------------------------------------------------------ */
/* Function: ipf_hook4_loop_in */
/* Returns: int - 0 == packet ok, else problem, free packet if not done */
/* Parameters: event(I) - pointer to event */
/* info(I) - pointer to hook information for firewalling */
/* */
/* Calling ipf_hook. */
/* ------------------------------------------------------------------------ */
/*ARGSUSED*/
{
}
/*ARGSUSED*/
{
}
/* ------------------------------------------------------------------------ */
/* Function: ipf_hook */
/* Returns: int - 0 == packet ok, else problem, free packet if not done */
/* Parameters: info(I) - pointer to hook information for firewalling */
/* out(I) - whether packet is going in or out */
/* loopback(I) - whether packet is a loopback packet or not */
/* */
/* Stepping stone function between the IP mainline and IPFilter. Extracts */
/* parameters out of the info structure and forms them up to be useful for */
/* calling ipfilter. */
/* ------------------------------------------------------------------------ */
{
/* For fastroute cases, fr_check returns 0 with mp set to NULL */
rval = 1;
/* Notify IP the packet mblk_t and IP header pointers. */
if (rval == 0) {
}
return rval;
}
{
/* For fastroute cases, fr_check returns 0 with mp set to NULL */
rval = 1;
/* Notify IP the packet mblk_t and IP header pointers. */
return rval;
}
/* ------------------------------------------------------------------------ */
/* Function: ipf_nic_event_v4 */
/* Returns: int - 0 == no problems encountered */
/* Parameters: event(I) - pointer to event */
/* info(I) - pointer to information about a NIC event */
/* */
/* Function to receive asynchronous NIC events from IP */
/* ------------------------------------------------------------------------ */
/*ARGSUSED*/
{
struct sockaddr_in *sin;
{
case NE_PLUMB :
ifs);
break;
case NE_UNPLUMB :
ifs);
break;
case NE_ADDRESS_CHANGE :
/*
* We only respond to events for logical interface 0 because
* IPFilter only uses the first address given to a network
* interface. We check for hne_lif==1 because the netinfo
* code maps adds 1 to the lif number so that it can return
* 0 to indicate "no more lifs" when walking them.
*/
ifs);
ifs);
}
break;
default :
break;
}
return 0;
}
/* ------------------------------------------------------------------------ */
/* Function: ipf_nic_event_v6 */
/* Returns: int - 0 == no problems encountered */
/* Parameters: event(I) - pointer to event */
/* info(I) - pointer to information about a NIC event */
/* */
/* Function to receive asynchronous NIC events from IP */
/* ------------------------------------------------------------------------ */
/*ARGSUSED*/
{
struct sockaddr_in6 *sin6;
{
case NE_PLUMB :
break;
case NE_UNPLUMB :
ifs);
break;
case NE_ADDRESS_CHANGE :
ifs);
}
break;
default :
break;
}
return 0;
}