ip_fil_solaris.c revision c793af95640863cd29868fc7c419c5d2496b207b
/*
* Copyright (C) 1993-2001, 2003 by Darren Reed.
*
* See the IPFILTER.LICENCE file for details on licencing.
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#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/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"
#ifdef IPFILTER_LOOKUP
# include "netinet/ip_lookup.h"
#endif
#if SOLARIS2 >= 7
#else
int fr_timer_id;
#endif
#if SOLARIS2 < 10
#if SOLARIS2 >= 7
# if SOLARIS2 >= 8
int *ip_forwarding = NULL;
# else
# endif
#else
int fr_timer_id;
#endif
#endif
int ipf_locks_done = 0;
/* ------------------------------------------------------------------------ */
/* 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. */
/* ------------------------------------------------------------------------ */
int ipldetach()
{
#if SOLARIS2 < 10
if (fr_control_forwarding & 2) {
if (ip_forwarding != NULL)
*ip_forwarding = 0;
#if SOLARIS2 >= 8
if (ip6_forwarding != NULL)
*ip6_forwarding = 0;
#endif
}
#endif
#ifdef IPFDEBUG
#endif
if (ipf_locks_done == 1) {
ipf_locks_done = 0;
}
return 0;
}
{
#if SOLARIS2 < 10
int i;
#endif
#ifdef IPFDEBUG
#endif
ipf_locks_done = 1;
if (fr_initialise() < 0)
return -1;
/* 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 (fr_control_forwarding & 1) {
if (ip_forwarding != NULL)
*ip_forwarding = 1;
#if SOLARIS2 >= 8
if (ip6_forwarding != NULL)
*ip6_forwarding = 1;
#endif
}
#endif
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;
if (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;
}
if (enable) {
if (fr_running > 0)
error = 0;
else
if (error == 0)
fr_running = 1;
else
(void) ipldetach();
} else {
if (error == 0)
fr_running = -1;
}
}
break;
case SIOCIPFSET :
break;
}
/* FALLTHRU */
case SIOCIPFGETNEXT :
case SIOCIPFGET :
break;
case SIOCSETFF :
else {
sizeof(fr_flags));
if (error != 0)
}
break;
case SIOCGETFF :
sizeof(fr_flags));
if (error != 0)
break;
case SIOCFUNCL :
break;
case SIOCINAFR :
case SIOCRMAFR :
case SIOCADAFR :
case SIOCZRLST :
else
fr_active, 1);
break;
case SIOCINIFR :
case SIOCRMIFR :
case SIOCADIFR :
else
break;
case SIOCSWAPA :
else {
sizeof(fr_active));
if (error != 0)
else
}
break;
case SIOCGETFS :
fr_getstat(&fio);
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) {
fr_state_lock = tmp;
fr_nat_lock = tmp;
fr_frag_lock = tmp;
fr_auth_lock = tmp;
} else
break;
#ifdef IPFILTER_LOG
case SIOCIPFFB :
else {
sizeof(tmp));
if (error)
}
break;
#endif /* IPFILTER_LOG */
case SIOCFRSYN :
else {
}
break;
case SIOCGFRST :
break;
case FIONREAD :
#ifdef IPFILTER_LOG
if (error != 0)
#endif
break;
default :
break;
}
return error;
}
char *name;
int v;
{
int sap;
if (v == 4)
sap = 0x0800;
else if (v == 6)
sap = 0x86dd;
else
return NULL;
return qf;
}
/*
* 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*/
{
# ifdef IPFDEBUG
# endif
# ifdef IPFILTER_SYNC
return ipfsync_read(uio);
# endif
}
#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.
*/
{
#ifdef IPFDEBUG
#endif
#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 icmp_nextmtu
#endif
#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);
}
#ifdef IRE_ILL_CN
#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;
}
MUTEX_EXIT(&ipf_rw);
if (need_printed) {
#ifdef _KERNEL
#else
#endif
}
}
#endif
/*
* return the first IP Address associated with an interface
*/
/*ARGSUSED*/
int v, atype;
void *qifptr;
{
#ifdef USE_INET6
#endif
#ifdef USE_INET6
#ifdef IRE_ILL_CN
#endif
#endif
return -1;
#ifdef USE_INET6
#ifdef IRE_ILL_CN
#endif
#endif
#ifdef USE_INET6
if (v == 6) {
#ifndef IRE_ILL_CN
/*
* First is always link local.
*/
if (!IN6_IS_ADDR_LINKLOCAL(inp6) &&
break;
}
return -1;
if (atype == FRI_BROADCAST)
else if (atype == FRI_PEERADDR)
else
#else /* IRE_ILL_CN */
"Check pfild is running: IP#/netmask is 0 on %s.\n",
return -1;
}
if (atype == FRI_BROADCAST)
else if (atype == FRI_PEERADDR)
else
#endif /* IRE_ILL_CN */
}
#endif
#ifndef IRE_ILL_CN
switch (atype)
{
case FRI_BROADCAST :
break;
case FRI_PEERADDR :
break;
default :
break;
}
#else
"Check pfild is running: IP#/netmask is 0 on %s.\n",
return -1;
}
if (atype == FRI_BROADCAST)
else if (atype == FRI_PEERADDR)
else
#endif /* IRE_ILL_CN */
}
{
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
MUTEX_EXIT(&ipf_rw);
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 */
/*
* 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.
* Pre-Solaris 10, we call into the routing code to make the determination.
* On Solaris 10 and later, we have a valid address set from pfild to check
* against.
*/
int fr_verifysrc(fin)
{
int result;
#if SOLARIS2 >= 6
#else
#endif
if (!dir)
return 0;
#if SOLARIS2 >= 8
#endif
return result;
}
#if (SOLARIS2 < 7)
void fr_slowtimer()
#else
/*ARGSUSED*/
#endif
{
if (fr_running <= 0) {
if (fr_running == -1)
drv_usectohz(500000));
else
fr_timer_id = NULL;
return;
}
fr_natexpire();
fr_ticks++;
else
fr_timer_id = NULL;
}
/*
* 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
*/
{
#ifndef IRE_ILL_CN
u_char *s;
#ifdef USE_INET6
#endif
#else
#endif
#ifndef sparc
#endif
#ifdef USE_INET6
#endif
#ifndef IRE_ILL_CN
#endif
/*
* 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
*/
}
#ifdef IRE_ILL_CN
#else
/*
* If the fdp is NULL then there is no set route for this packet.
*/
{
case 4 :
break;
#ifdef USE_INET6
case 6 :
break;
#endif
}
} else {
#endif
goto bad_fastroute;
}
/*
* In case we're here due to "to <if>" being used with
* "keep state", check that we're going in the correct
* direction.
*/
return -1;
} else {
#ifdef IRE_ILL_CN
#endif
} else
}
#ifdef USE_INET6
#ifdef IRE_ILL_CN
#endif
} else
}
#endif
else
goto bad_fastroute;
}
#ifndef IRE_ILL_CN
#if SOLARIS2 >= 6
}
# ifdef USE_INET6
}
# endif
#else
#endif
#if SOLARIS2 < 8
}
}
#else
}
#endif
#else /* IRE_ILL_CN */
{
goto bad_fastroute;
}
#endif /* IRE_ILL_CN */
#ifdef IRE_ILL_CN
#else
#if SOLARIS2 < 8
#else
#endif
#endif
void *saveqif;
{
/* FALLTHROUGH */
case 0 :
case 1 :
break;
case -1 :
goto bad_fastroute;
}
}
#ifndef sparc
}
#endif
#ifndef IRE_ILL_CN
if (
(dohwcksum &&
#endif
s -= hlen;
} else {
goto bad_fastroute;
}
}
if (q != NULL)
q = q->q_next;
if (q != NULL) {
u_32_t t;
t += 30;
t = (t & 0xffff) + (t >> 16);
}
#endif
ATOMIC_INCL(fr_frouteok[0]);
#if SOLARIS2 >= 8
#endif
return 0;
}
#else /* IRE_ILL_CN */
pfil_send_dl_packet(q, mb);
ATOMIC_INCL(fr_frouteok[0]);
return 0;
#endif /* IRE_ILL_CN */
}
#ifndef IRE_ILL_CN
#if SOLARIS2 >= 8
#endif
#endif
return -1;
}
/* ------------------------------------------------------------------------ */
/* 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;
}
}
return NULL;
}
}
return ip;
}