fil.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright (C) 1993-2003 by Darren Reed.
*
* See the IPFILTER.LICENCE file for details on licencing.
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
# define KERNEL 1
# define _KERNEL 1
#endif
#if defined(__NetBSD__)
# include "opt_ipfilter_log.h"
# endif
#endif
#if defined(_KERNEL) && defined(__FreeBSD_version) && \
(__FreeBSD_version >= 220000)
# if (__FreeBSD_version >= 400000)
# if !defined(IPFILTER_LKM)
# include "opt_inet6.h"
# endif
# if (__FreeBSD_version == 400019)
# define CSUM_DELAY_DATA
# endif
# endif
#else
#endif
#if defined(_KERNEL)
#else
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# define _KERNEL
# ifdef __OpenBSD__
struct file;
# endif
#endif
#else
# include <sys/byteorder.h>
# include <sys/dditypes.h>
# endif
#endif
#ifdef __hpux
# define _NET_ROUTE_INCLUDED
#endif
#ifdef sun
#endif
#include <netinet/in_systm.h>
#endif
#ifdef __hpux
#endif
#if SOLARIS2 >= 10
# include "ip_compat.h"
#else
# include "netinet/ip_compat.h"
#endif
#ifdef USE_INET6
# endif
#endif
#if SOLARIS2 >= 10
#include "ip_fil.h"
#include "ip_nat.h"
#include "ip_frag.h"
#include "ip_state.h"
#include "ip_proxy.h"
#include "ip_auth.h"
#else
#include "netinet/ip_state.h"
#include "netinet/ip_proxy.h"
#endif
#ifdef IPFILTER_SCAN
#endif
#if SOLARIS2 >= 10
#include "ip_pool.h"
#include "ip_htable.h"
#else
#include "netinet/ip_htable.h"
#endif
#ifdef IPFILTER_BPF
#endif
# if defined(_KERNEL) && !defined(IPFILTER_LKM)
# include "opt_ipfilter.h"
# endif
#endif
#if SOLARIS2 >= 10
#include "ipl.h"
#else
#endif
#if !defined(lint)
#endif
#ifndef _KERNEL
# include "ipf.h"
# include "ipt.h"
extern int opts;
#else /* #ifndef _KERNEL */
# define FR_VERBOSE(verb_pr)
#endif /* _KERNEL */
int fr_refcnt = 0;
/*
* For fr_running:
* 0 == loading, 1 = running, -1 = disabled, -2 = unloading
*/
int fr_running = 0;
int fr_flags = IPF_LOGGING;
int fr_active = 0;
int fr_control_forwarding = 0;
#ifdef _KERNEL
int fr_update_ipid = 0;
#else
int fr_update_ipid = 1;
#endif
int fr_chksrc = 0;
int fr_minttl = 4;
#if defined(IPFILTER_DEFAULT_BLOCK)
#else
#endif
u_long fr_userifqs = 0;
#ifdef ICMP_UNREACH_FILTER_PROHIB
#else
int fr_unreach = ICMP_UNREACH_FILTER;
#endif
char ipfilter_version[] = IPL_VERSION;
#ifdef IPFILTER_LOOKUP
#endif
/*
* bit values for identifying presence of individual IP options
*/
{ IPOPT_NOP, 0x000001 },
{ IPOPT_RR, 0x000002 },
{ IPOPT_ZSU, 0x000004 },
{ IPOPT_MTUP, 0x000008 },
{ IPOPT_MTUR, 0x000010 },
{ IPOPT_ENCODE, 0x000020 },
{ IPOPT_TS, 0x000040 },
{ IPOPT_TR, 0x000080 },
{ IPOPT_SECURITY, 0x000100 },
{ IPOPT_LSRR, 0x000200 },
{ IPOPT_E_SEC, 0x000400 },
{ IPOPT_CIPSO, 0x000800 },
{ IPOPT_SATID, 0x001000 },
{ IPOPT_SSRR, 0x002000 },
{ IPOPT_ADDEXT, 0x004000 },
{ IPOPT_VISA, 0x008000 },
{ IPOPT_IMITD, 0x010000 },
{ IPOPT_EIP, 0x020000 },
{ IPOPT_FINN, 0x040000 },
{ 0, 0x000000 }
};
#ifdef USE_INET6
{ IPPROTO_HOPOPTS, 0x000001 },
{ IPPROTO_DSTOPTS, 0x000002 },
{ IPPROTO_ESP, 0x000004 },
{ IPPROTO_AH, 0x000008 },
{ IPPROTO_ROUTING, 0x000010 },
{ IPPROTO_IPV6, 0x000020 },
{ IPPROTO_FRAGMENT, 0x000040 },
{ IPPROTO_NONE, 0x000080 }
};
#endif
{ TCPOPT_NOP, 0x000001 },
{ TCPOPT_MAXSEG, 0x000002 },
{ TCPOPT_WINDOW, 0x000004 },
{ TCPOPT_SACK_PERMITTED, 0x000008 },
{ TCPOPT_SACK, 0x000010 },
{ TCPOPT_TIMESTAMP, 0x000020 },
{ 0, 0x000000 }
};
/*
* bit values for identifying presence of individual IP security options
*/
{ IPSO_CLASS_RES4, 0x01 },
{ IPSO_CLASS_TOPS, 0x02 },
{ IPSO_CLASS_SECR, 0x04 },
{ IPSO_CLASS_RES3, 0x08 },
{ IPSO_CLASS_CONF, 0x10 },
{ IPSO_CLASS_UNCL, 0x20 },
{ IPSO_CLASS_RES2, 0x40 },
{ IPSO_CLASS_RES1, 0x80 }
};
/*
* Table of functions available for use with call rules.
*/
static ipfunc_resolve_t fr_availfuncs[] = {
#ifdef IPFILTER_LOOKUP
#endif
{ "", NULL }
};
/*
* The next section of code is a a collection of small routines that set
* fields in the fr_info_t structure passed based on properties of the
* current packet. There are different routines for the same protocol
* for each of IPv4 and IPv6. Adding a new protocol, for which there
* will "special" inspection for setup, is now more easily done by adding
* a new routine and expanding the frpr_ipinit*() function rather than by
* adding more code to a growing switch statement.
*/
#ifdef USE_INET6
/* ------------------------------------------------------------------------ */
/* Function: frpr_short6 */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* IPv6 Only */
/* This is function enforces the 'is a packet too short to be legit' rule */
/* for IPv6 and marks the packet with FI_SHORT if so. See function comment */
/* for frpr_short() for more details. */
/* ------------------------------------------------------------------------ */
int min;
{
int off;
if (off == 0) {
}
}
/* ------------------------------------------------------------------------ */
/* Function: frpr_ipv6hdr */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* IPv6 Only */
/* Copy values from the IPv6 header into the fr_info_t struct and call the */
/* per-protocol analyzer if it exists. */
/* ------------------------------------------------------------------------ */
{
coalesced = 0;
hdrcount = 0;
switch (p)
{
case IPPROTO_UDP :
go = 0;
break;
case IPPROTO_TCP :
go = 0;
break;
case IPPROTO_ICMPV6 :
go = 0;
break;
case IPPROTO_HOPOPTS :
/*
* Actually, hop by hop header is only allowed right
* after IPv6 header!
*/
if (coalesced == 0) {
if (coalesced == -1)
return;
}
if (hdrcount != 0)
else
break;
case IPPROTO_DSTOPTS :
if (coalesced == 0) {
if (coalesced == -1)
return;
}
break;
case IPPROTO_ROUTING :
if (coalesced == 0) {
if (coalesced == -1)
return;
}
break;
case IPPROTO_ESP :
case IPPROTO_AH :
case IPPROTO_IPV6 :
break;
go = 0;
break;
case IPPROTO_NONE :
go = 0;
break;
case IPPROTO_FRAGMENT :
if (coalesced == 0) {
if (coalesced == -1)
return;
}
break;
default :
go = 0;
break;
}
hdrcount++;
}
}
/* ------------------------------------------------------------------------ */
/* Function: frpr_hopopts6 */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* IPv6 Only */
/* This is function checks pending hop by hop options extension header */
/* ------------------------------------------------------------------------ */
{
int i;
/* 8 is default length of extension hdr */
return;
}
return;
}
break;
return;
}
/* ------------------------------------------------------------------------ */
/* Function: frpr_routing6 */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* IPv6 Only */
/* This is function checks pending routing extension header */
/* ------------------------------------------------------------------------ */
{
int i;
/* 8 is default length of extension hdr */
return;
}
/*
* Nasty extension header length?
*/
return;
}
break;
return;
}
/* ------------------------------------------------------------------------ */
/* Function: frpr_fragment6 */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* IPv6 Only */
/* Examine the IPv6 fragment header and extract fragment offset information.*/
/* ------------------------------------------------------------------------ */
{
int i;
/*
* Only one frgament header is allowed per IPv6 packet but it need
* not be the first nor last (not possible in some cases.)
*/
break;
return;
}
/*
* Length must be zero, i.e. it is no length.
*/
return;
}
return;
}
return;
}
/* ------------------------------------------------------------------------ */
/* Function: frpr_dstopts6 */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* nextheader(I) - stores next header value */
/* */
/* IPv6 Only */
/* This is function checks pending destination options extension header */
/* ------------------------------------------------------------------------ */
{
int i;
/* 8 is default length of extension hdr */
return;
}
return;
}
break;
return;
}
/* ------------------------------------------------------------------------ */
/* Function: frpr_icmp6 */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* IPv6 Only */
/* This routine is mainly concerned with determining the minimum valid size */
/* for an ICMPv6 packet. */
/* ------------------------------------------------------------------------ */
{
switch (icmp6->icmp6_type)
{
case ICMP6_ECHO_REPLY :
case ICMP6_ECHO_REQUEST :
break;
case ICMP6_DST_UNREACH :
case ICMP6_PACKET_TOO_BIG :
case ICMP6_TIME_EXCEEDED :
case ICMP6_PARAM_PROB :
return;
}
break;
default :
break;
}
}
}
/* ------------------------------------------------------------------------ */
/* Function: frpr_udp6 */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* IPv6 Only */
/* ------------------------------------------------------------------------ */
{
}
/* ------------------------------------------------------------------------ */
/* Function: frpr_tcp6 */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* IPv6 Only */
/* ------------------------------------------------------------------------ */
{
}
#endif /* USE_INET6 */
/* ------------------------------------------------------------------------ */
/* Function: frpr_short */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* min(I) - minimum size of packet */
/* hdrmin(I) - minimum header size */
/* */
/* Check if a packet is "short" as defined by min and hdrmin. */
/* ------------------------------------------------------------------------ */
/*ARGSUSED*/
{
int off;
if (off == 0) {
}
}
/* ------------------------------------------------------------------------ */
/* Function: frpr_icmp */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* IPv4 Only */
/* Do a sanity check on the packet for ICMP (v4). In nearly all cases, */
/* except extrememly bad packets, both type and code will be present. */
/* The expected minimum size of an ICMP packet is very much dependant on */
/* the type of it. */
/* */
/* XXX - other ICMP sanity checks? */
/* ------------------------------------------------------------------------ */
{
{
case ICMP_ECHOREPLY :
case ICMP_ECHO :
/* Router discovery messaes - RFC 1256 */
case ICMP_ROUTERADVERT :
case ICMP_ROUTERSOLICIT :
break;
/*
* type(1) + code(1) + cksum(2) + id(2) seq(2) +
* 3 * timestamp(3 * 4)
*/
case ICMP_TSTAMP :
case ICMP_TSTAMPREPLY :
minicmpsz = 20;
break;
/*
* type(1) + code(1) + cksum(2) + id(2) seq(2) +
* mask(4)
*/
case ICMP_MASKREQ :
case ICMP_MASKREPLY :
minicmpsz = 12;
break;
/*
* type(1) + code(1) + cksum(2) + id(2) seq(2) + ip(20+)
*/
case ICMP_UNREACH :
case ICMP_SOURCEQUENCH :
case ICMP_REDIRECT :
case ICMP_TIMXCEED :
case ICMP_PARAMPROB :
return;
}
break;
default :
break;
}
}
}
/* ------------------------------------------------------------------------ */
/* Function: frpr_tcpcommon */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* TCP header sanity checking. Look for bad combinations of TCP flags, */
/* and make some checks with how they interact with other fields. */
/* If compiled with IPFILTER_CKSUM, check to see if the TCP checksum is */
/* valid and mark the packet as bad if not. */
/* ------------------------------------------------------------------------ */
{
return;
}
#endif
/*
* Use of the TCP data offset *must* result in a value that is at
* least the same size as the TCP header.
*/
/*
* If the urgent flag is set, then the urgent pointer must
* also be set and vice versa. Good TCP packets do not have
* just one of these set.
*/
/*
* If the ack bit isn't set, then either the SYN or
* RST bit must be set. If the SYN bit is set, then
* we expect the ACK field to be 0. If the ACK is
* not set and if URG, PSH or FIN are set, consdier
* that to indicate a bad TCP packet.
*/
}
}
}
}
#if 0
/*
* At this point, it's not exactly clear what is to be gained by
* marking up which TCP options are and are not present. The one we
* are most interested in is the TCP window scale. This is only in
* a SYN packet [RFC1323] so we don't need this here...?
* Now if we were to analyse the header for passive fingerprinting,
* then that might add some weight to adding this...
*/
return;
# ifdef _KERNEL
return;
}
# endif
opt = *s;
if (opt == '\0')
break;
else if (opt == TCPOPT_NOP)
ol = 1;
else {
if (hlen < 2)
break;
ol = (int)*(s + 1);
break;
}
break;
}
}
s += ol;
}
#endif /* 0 */
}
/* ------------------------------------------------------------------------ */
/* Function: frpr_udpcommon */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* Extract the UDP source and destination ports, if present. If compiled */
/* with IPFILTER_CKSUM, check to see if the UDP checksum is valid. */
/* ------------------------------------------------------------------------ */
{
}
}
/* ------------------------------------------------------------------------ */
/* Function: frpr_tcp */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* IPv4 Only */
/* ------------------------------------------------------------------------ */
{
}
/* ------------------------------------------------------------------------ */
/* Function: frpr_udp */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* IPv4 Only */
/* ------------------------------------------------------------------------ */
{
}
/* ------------------------------------------------------------------------ */
/* Function: frpr_ipv4hdr */
/* Returns: void */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* IPv4 Only */
/* Analyze the IPv4 header and set fields in the fr_info_t structure. */
/* Check all options present and flag their presence if any exist. */
/* ------------------------------------------------------------------------ */
{
/* Get both TTL and protocol */
#if 0
#endif
/* Zero out bits not used in IPv6 address */
/*
* set packet attribute flags based on the offset and
* calculate the byte offset that it represents.
*/
}
if (off != 0) {
off &= IP_OFFMASK;
if (off != 0) {
off <<= 3;
}
}
/*
* Call per-protocol setup and checking
*/
switch (p)
{
case IPPROTO_UDP :
break;
case IPPROTO_TCP :
break;
case IPPROTO_ICMP :
break;
}
return;
/*
* If it is a standard IP header (no options), set the flag fields
* which relate to options to 0.
*/
return;
}
/*
* So the IP header has some IP options attached. Walk the entire
* list of options present with this packet and set flags to indicate
* which ones are here and which ones are not. For the somewhat out
* of date and obscure security classification options, set a flag to
* represent which classification is present.
*/
opt = *s;
if (opt == '\0')
break;
ol = 1;
else {
if (hlen < 2)
break;
ol = (int)*(s + 1);
break;
}
if (opt == IPOPT_SECURITY) {
int j, m;
for (j = 3, m = 2; m >= 0; ) {
auth = *(s + 3);
auth *= 256;
auth += *(s + 4);
break;
}
j -= m;
else
j += m;
m--;
}
}
break;
}
i -= mv;
else
i += mv;
mv--;
}
s += ol;
}
/*
*
*/
auth &= 0xff00;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_makefrip */
/* Returns: void */
/* Parameters: hlen(I) - length of IP packet header */
/* ip(I) - pointer to the IP header */
/* fin(IO) - pointer to packet information */
/* */
/* Compact the IP header into a structure which contains just the info. */
/* which is useful for comparing IP headers with and store this information */
/* in the fr_info_t structure pointer to by fin. At present, it is assumed */
/* this function will be called with either an IPv4 or IPv6 packet. */
/* ------------------------------------------------------------------------ */
int hlen;
{
int v;
if (v == 4)
#ifdef USE_INET6
else if (v == 6)
#endif
return -1;
return 0;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_portcheck */
/* Returns: int - 1 == port matched, 0 == port match failed */
/* Parameters: frp(I) - pointer to port check `expression' */
/* pop(I) - pointer to port number to evaluate */
/* */
/* Perform a comparison of a port number against some other(s), using a */
/* structure with compare information stored in it. */
/* ------------------------------------------------------------------------ */
{
int err = 1;
/*
* Do opposite test to that required and continue if that succeeds.
*/
{
case FR_EQUAL :
err = 0;
break;
case FR_NEQUAL :
err = 0;
break;
case FR_LESST :
err = 0;
break;
case FR_GREATERT :
err = 0;
break;
case FR_LESSTE :
err = 0;
break;
case FR_GREATERTE :
err = 0;
break;
case FR_OUTRANGE :
err = 0;
break;
case FR_INRANGE :
err = 0;
break;
case FR_INCRANGE :
err = 0;
break;
default :
break;
}
return err;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_tcpudpchk */
/* Returns: int - 1 == protocol matched, 0 == check failed */
/* Parameters: fin(I) - pointer to packet information */
/* ft(I) - pointer to structure with comparison data */
/* */
/* structure containing information that we want to match against. */
/* ------------------------------------------------------------------------ */
{
int err = 1;
/*
* Both ports should *always* be in the first fragment.
* So far, I cannot find any cases where they can not be.
*
* compare destination ports
*/
/*
* compare source ports
*/
/*
* expect to do any sort of match on it ? If we were looking for
* TCP flags, then NO match. If not, then match (which should
* satisfy the "short" class too).
*/
/*
* Match the flags ? If not, abort this match.
*/
err = 0;
}
}
return err;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_ipfcheck */
/* Returns: int - 0 == match, 1 == no match */
/* Parameters: fin(I) - pointer to packet information */
/* fr(I) - pointer to filter rule */
/* portcmp(I) - flag indicating whether to attempt matching on */
/* */
/* Check to see if a packet matches an IPFilter rule. Checks of addresses, */
/* port numbers, etc, for "standard" IPFilter rules are all orchestrated in */
/* this function. */
/* ------------------------------------------------------------------------ */
int portcmp;
{
int i;
/*
* first 32 bits to check coversion:
* IP version, TOS, TTL, protocol
*/
FR_DEBUG(("0. %#08x & %#08x != %#08x\n",
if (i)
return 1;
/*
* Next 32 bits is a constructed bitmask indicating which IP options
* are present (if any) in this packet.
*/
FR_DEBUG(("1. %#08x & %#08x != %#08x\n",
if (i)
return 1;
/*
* Unrolled loops (4 each, for 32 bits) for address checks.
*/
/*
* Check the source address.
*/
#ifdef IPFILTER_LOOKUP
if (i == -1)
return 1;
lip += 3;
lm += 3;
ld += 3;
} else {
#endif
FR_DEBUG(("2a. %#08x & %#08x != %#08x\n",
FR_DEBUG(("2b. %#08x & %#08x != %#08x\n",
FR_DEBUG(("2c. %#08x & %#08x != %#08x\n",
FR_DEBUG(("2d. %#08x & %#08x != %#08x\n",
} else {
lip += 3;
lm += 3;
ld += 3;
}
#ifdef IPFILTER_LOOKUP
}
#endif
if (i)
return 1;
/*
* Check the destination address.
*/
#ifdef IPFILTER_LOOKUP
if (i == -1)
return 1;
lip += 3;
lm += 3;
ld += 3;
} else {
#endif
FR_DEBUG(("3a. %#08x & %#08x != %#08x\n",
FR_DEBUG(("3b. %#08x & %#08x != %#08x\n",
FR_DEBUG(("3c. %#08x & %#08x != %#08x\n",
FR_DEBUG(("3d. %#08x & %#08x != %#08x\n",
} else {
lip += 3;
lm += 3;
ld += 3;
}
#ifdef IPFILTER_LOOKUP
}
#endif
if (i)
return 1;
/*
* IP addresses matched. The next 32bits contains:
* mast of old IP header security & authentication bits.
*/
FR_DEBUG(("4. %#08x & %#08x != %#08x\n",
/*
* Next we have 32 bits of packet flags.
*/
FR_DEBUG(("5. %#08x & %#08x != %#08x\n",
if (i == 0) {
/*
* If a fragment, then only the first has what we're
* looking for here...
*/
if (portcmp) {
i = 1;
} else {
i = 1;
i = 1;
FR_DEBUG(("i. %#x & %#x != %#x\n",
i = 1;
}
}
}
}
return i;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_scanlist */
/* Returns: int - result flags of scanning filter list */
/* Parameters: fin(I) - pointer to packet information */
/* pass(I) - default result to return for filtering */
/* */
/* If a match is found, the value of fr_flags from the rule becomes the */
/* return value and fin->fin_fr points to the matched rule. */
/* */
/* This function may be called recusively upto 16 times (limit inbuilt.) */
/* When unwinding, it should finish up with fin_depth as 0. */
/* */
/* Could be per interface, but this gets real nasty when you don't have, */
/* or can't easily change, the kernel source code to . */
/* ------------------------------------------------------------------------ */
{
/*
* Do not allow nesting deeper than 16 levels.
*/
return pass;
/*
* If there are no rules in this list, return now.
*/
return pass;
skip = 0;
logged = 0;
portcmp = 0;
portcmp = 1;
if (skip != 0) {
skip--;
continue;
}
/*
* In all checks below, a null (zero) value in the
* filter struture is taken to mean a wildcard.
*
* check that we are working for the right interface
*/
#ifdef _KERNEL
continue;
#else
printf("\n");
continue;
FR_VERBOSE((":i"));
#endif
{
case FR_T_IPF :
case FR_T_IPF|FR_T_BUILTIN :
continue;
break;
#if defined(IPFILTER_BPF) && defined(_KERNEL)
case FR_T_BPFOPC :
case FR_T_BPFOPC|FR_T_BUILTIN :
{
int wlen;
continue;
continue;
continue;
break;
}
#endif
case FR_T_CALLFUNC|FR_T_BUILTIN :
{
frentry_t *f;
if (f != NULL)
fr = f;
else
continue;
break;
}
default :
break;
}
continue;
continue;
}
/*
* If the rule is a "call now" rule, then call the function
* in the rule, if it exists and use the results from that.
* If the function pointer is bad, just make like we ignore
* it, except for increasing the hit counter.
*/
if ((passt & FR_CALLNOW) != 0) {
continue;
}
}
} else {
}
#ifdef IPFILTER_LOG
/*
* Just log this packet...
*/
if (passt & FR_LOGORBLOCK) {
passt &= ~FR_CMDMASK;
}
}
logged = 1;
}
#endif /* IPFILTER_LOG */
}
logged = 1;
}
break;
}
if (logged)
return pass;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_acctpkt */
/* Returns: frentry_t* - always returns NULL */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* Checks a packet against accounting rules, if there are any for the given */
/* IP protocol version. */
/* */
/* N.B.: this function returns NULL to match the prototype used by other */
/* functions called from the IPFilter "mainline" in fr_check(). */
/* ------------------------------------------------------------------------ */
{
char group[FR_GROUPLEN];
#ifdef USE_INET6
else
#endif
if (FR_ISACCOUNT(pass)) {
}
}
return NULL;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_firewall */
/* Returns: frentry_t* - returns pointer to matched rule, if no matches */
/* were found, returns NULL. */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* Applies an appropriate set of firewall rules to the packet, to see if */
/* there are any matches. The first check is to see if a match can be seen */
/* in the cache. If not, then search an appropriate list of rules. Once a */
/* matching rule is found, take any appropriate actions as defined by the */
/* rule - except logging. */
/* ------------------------------------------------------------------------ */
{
int out;
/*
* If a packet is found in the auth table, then skip checking
* the access lists for permission but we do need to consider
* the result as if it were from the ACL's.
*/
/*
* copy cached data so we can unlock the mutex
* earlier.
*/
}
} else {
#ifdef USE_INET6
else
#endif
if (((pass & FR_KEEPSTATE) == 0) &&
if ((pass & FR_NOMATCH)) {
}
}
/*
* Apply packets per second rate-limiting to a rule as required.
*/
}
/*
* If we fail to add a packet to the authorization queue, then we
* drop the packet later. However, if it was added then pretend
* we've dropped it already.
*/
#ifdef _KERNEL
#else
;
#endif
} else
}
/*
* If a rule is a pre-auth rule, check again in the list of rules
* loaded for authenticated use. It does not particulary matter
* if this search fails because a "preauth" result, from a rule,
* is treated as "not a pass", hence the packet is blocked.
*/
if (FR_ISPREAUTH(pass)) {
}
/*
* If the rule has "keep frag" and the packet is actually a fragment,
* then create a fragment state entry.
*/
} else {
}
} else {
}
}
/*
* Finally, if we've asked to track state for this packet, set it up.
*/
if (pass & FR_KEEPSTATE) {
} else {
}
}
return fr;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_check */
/* Returns: int - 0 == packet allowed through, */
/* User space: */
/* -1 == packet blocked */
/* 1 == packet not matched */
/* -2 == requires authantication */
/* Kernel: */
/* > 0 == filter error # for packet */
/* Parameters: ip(I) - pointer to start of IPv4/6 packet */
/* hlen(I) - length of header */
/* ifp(I) - pointer to interface this packet is on */
/* out(I) - 0 == packet going in, 1 == packet going out */
/* mp(IO) - pointer to caller's buffer pointer that holds this */
/* IP packet. */
/* Solaris & HP-UX ONLY : */
/* qif(I) - pointer to STREAMS queue information for this */
/* interface & direction. */
/* */
/* fr_check() is the master function for all IPFilter packet processing. */
/* It orchestrates: Network Address Translation (NAT), checking for packet */
/* authorisation (or pre-authorisation), presence of related state info., */
/* generating log entries, IP packet accounting, routing of packets as */
/* directed by firewall rules and of course whether or not to allow the */
/* packet to be further processed by the kernel. */
/* */
/* For packets blocked, the contents of "mp" will be NULL'd and the buffer */
/* freed. Packets passed may be returned with the pointer pointed to by */
/* by "mp" changed to a new buffer. */
/* ------------------------------------------------------------------------ */
#else
, mp)
#endif
int hlen;
void *ifp;
int out;
{
/*
* The above really sucks, but short of writing a diff
*/
mb_t *m;
/*
* The first part of fr_check() deals with making sure that what goes
* into the filtering engine makes some sense. Information about the
* the packet is distilled, collected into a fr_info_t structure and
* the an attempt to ensure the buffer the packet is in is big enough
* to hold all the required packet headers.
*/
#ifdef _KERNEL
# ifdef __sgi
char hbuf[MAX_IPV4HDR];
# endif
# ifdef MENTAT
return 2;
# endif
if (fr_running <= 0) {
return 0;
}
# ifdef MENTAT
# else /* MENTAT */
m = *mp;
# if defined(M_MCAST)
# endif
# if defined(M_BCAST)
# endif
# ifdef M_CANFASTFWD
/*
* XXX For now, IP Filter and fast-forwarding of cached flows
* XXX are mutually exclusive. Eventually, IP Filter should
* XXX get a "can-fast-forward" filter rule.
*/
m->m_flags &= ~M_CANFASTFWD;
# endif /* M_CANFASTFWD */
# ifdef CSUM_DELAY_DATA
/*
* disable delayed checksums.
*/
in_delayed_cksum(m);
}
# endif /* CSUM_DELAY_DATA */
# endif /* MENTAT */
#else
m = *mp;
#endif /* _KERNEL */
#ifdef USE_INET6
if (v == 6) {
/*
* Jumbo grams are quite likely too big for internal buffer
* structures to handle comfortably, for now, so just drop
* them for now.
*/
if (len == 0) {
goto filtered;
}
} else
#endif
{
}
if (p == IPPROTO_TCP || p == IPPROTO_UDP ||
(v == 4 && p == IPPROTO_ICMP)
#ifdef USE_INET6
|| (v == 6 && p == IPPROTO_ICMPV6)
#endif
) {
#if defined(_KERNEL)
switch(p)
{
case IPPROTO_TCP:
break;
case IPPROTO_UDP:
break;
/* 96 - enough for complete ICMP error IP header */
case IPPROTO_ICMP:
break;
# ifdef USE_INET6
case IPPROTO_ICMPV6 :
/*
* XXX does not take intermediate header
* into account.
*/
break;
# endif
}
# ifdef __sgi
/* Under IRIX, avoid m_pullup as it makes ping <hostname> panic */
goto filtered;
}
# else /* __ sgi */
/*
* Having determined that we need to pullup some data,
* try to bring as much of the packet up into a single
* buffer with the first pullup. This hopefully means
* less need for doing futher pullups. Not needed for
* Solaris because fr_precheck() does it anyway.
*
* become quite small, lets say < 64 bytes...but if
* that did happen, BSD networking as a whole would be
* slow/inefficient.
*/
# ifdef MHLEN
/*
* Assume that M_PKTHDR is set and just work with what
* is left rather than check.. Should not make any
* real difference, anyway.
*/
# else
# ifdef MLEN
# endif /* MLEN */
# endif /* MHLEN */
goto finished;
# endif /* __sgi */
}
#else
/*EMPTY*/
#endif /* _KERNEL */
}
goto finished;
if (v == 6) {
}
/*
* For at least IPv6 packets, if a m_pullup() fails then this pointer
* becomes NULL and so we have no packet to free.
*/
goto finished;
if (!out) {
if (v == 4) {
#ifdef _KERNEL
}
#endif
}
}
#ifdef USE_INET6
else if (v == 6) {
}
}
#endif
}
}
/*
* Check auth now. This, combined with the check below to see if apass
* is 0 is to ensure that we don't count the packet twice, which can
* otherwise occur when we reprocess it. As it is, we only count it
* after it has no auth. table matchup. This also stops NAT from
* occuring until after the packet has been auth'd.
*/
if (!out)
if (!out)
/*
* interface.
*/
if ((fr_update_ipid != 0) && (v == 4)) {
pass &= ~FR_CMDMASK;
} else {
}
}
}
#ifdef IPFILTER_LOG
#endif
/*
* Only allow FR_DUP to work if a rule matched - it makes no sense to
* set FR_DUP as a "default" as there are no instructions about where
* to send the packet.
*/
mc = M_DUPLICATE(m);
}
/*
* Should we return an ICMP packet to indicate error
* status passing through the packet filter ?
* WARNING: ICMP error packets AND TCP RST packets should
* ONLY be sent in repsonse to incoming packets. Sending them
* in response to outbound packets can result in a panic on
* some operating systems.
*/
if (!out) {
if (pass & FR_RETICMP) {
int dst;
dst = 1;
else
dst = 0;
if (fr_send_reset(fin) == 0) {
}
}
} else {
}
}
/*
* If we didn't drop off the bottom of the list of rules (and thus
* the 'current' rule fr is not NULL), then we may have some extra
* instructions about what to do with a packet.
* Once we're finished return to our caller, freeing the packet if
* we are dropping it (* BSD ONLY *).
*/
#endif
} else if (FR_ISBLOCK(pass)) {
}
/*
* For fastroute rule, no destioation interface defined
* so pass NULL as the frdest_t parameter
*/
/* this is for to rules: */
}
/*
* Generate a duplicated packet.
*/
}
/*
* This late because the likes of fr_fastroute() use fin_fr.
*/
if (m != NULL) {
}
}
else {
}
}
#endif
#ifdef _KERNEL
#else /* _KERNEL */
if ((pass & FR_NOMATCH) != 0)
return 1;
if ((pass & FR_RETMASK) != 0)
switch (pass & FR_RETMASK)
{
case FR_RETRST :
return 3;
case FR_RETICMP :
return 4;
case FR_FAKEICMP :
return 5;
}
switch (pass & FR_CMDMASK)
{
case FR_PASS :
return 0;
case FR_BLOCK :
return -1;
case FR_AUTH :
return -2;
case FR_ACCOUNT :
return -3;
case FR_PREAUTH :
return -4;
}
return 2;
#endif /* _KERNEL */
}
#ifdef IPFILTER_LOG
/* ------------------------------------------------------------------------ */
/* Function: fr_dolog */
/* Returns: frentry_t* - returns contents of fin_fr (no change made) */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* Checks flags set to see how a packet should be logged, if it is to be */
/* logged. Adjust statistics based on its success or not. */
/* ------------------------------------------------------------------------ */
{
int out;
pass |= FF_LOGNOMATCH;
goto logit;
pass |= FF_LOGPASS;
goto logit;
pass |= FF_LOGBLOCK;
/*
* If the "or-block" option has been used then
* block the packet if we failed to log it.
*/
if ((pass & FR_LOGORBLOCK) &&
pass &= ~FR_CMDMASK;
}
}
}
}
#endif /* IPFILTER_LOG */
/* ------------------------------------------------------------------------ */
/* Function: ipf_cksum */
/* Returns: u_short - IP header checksum */
/* Parameters: addr(I) - pointer to start of buffer to checksum */
/* len(I) - length of buffer in bytes */
/* */
/* Calculate the two's complement 16 bit checksum of the buffer passed. */
/* */
/* N.B.: addr should be 16bit aligned. */
/* ------------------------------------------------------------------------ */
int len;
{
/* mop up an odd byte, if necessary */
if (len == 1)
/*
* add back carry outs from top 16 bits to low 16 bits
*/
}
/* ------------------------------------------------------------------------ */
/* Function: fr_cksum */
/* Returns: u_short - layer 4 checksum */
/* Parameters: m(I ) - pointer to buffer holding packet */
/* ip(I) - pointer to IP header */
/* l4hdr(I) - pointer to layer 4 header */
/* */
/* Calculates the TCP checksum for the packet held in "m", using the data */
/* in the IP header "ip" to seed it. */
/* */
/* NB: This function assumes we've pullup'd enough for all of the IP header */
/* and the TCP header. We also assume that data blocks aren't allocated in */
/* odd sizes. */
/* ------------------------------------------------------------------------ */
mb_t *m;
int l4proto;
void *l4hdr;
{
int hlen;
#ifdef USE_INET6
#endif
sumsave = 0;
l4hlen = 0;
slen = 0;
hlen = 0;
sum = 0;
/*
* Add up IP Header portion
*/
#ifdef USE_INET6
#endif
#ifdef USE_INET6
}
#endif
switch (l4proto)
{
case IPPROTO_UDP :
break;
case IPPROTO_TCP :
break;
case IPPROTO_ICMP :
l4hlen = 4;
break;
default :
break;
}
*csump = 0;
}
#ifdef _KERNEL
# ifdef MENTAT
{
}
# else /* MENTAT */
# if BSD >= 199103
# else
# endif
# if BSD >= 199103
# else
# endif
/*
* Both sum and sum2 are partial sums, so combine them together.
*/
while (sum > 0xffff)
# else /* defined(BSD) || defined(sun) */
{
union {
u_char c[2];
u_short s;
} bytes;
# if defined(__sgi)
int add;
# endif
/*
* Add up IP Header portion
*/
{
case IPPROTO_UDP :
break;
case IPPROTO_TCP :
break;
}
# ifdef __sgi
/*
* In case we had to copy the IP & TCP header out of mbufs,
* skip over the mbuf bits which are the header
*/
while (hlen) {
m = m->m_next;
if (!hlen) {
if (!m)
break;
}
PANIC((!m),("fr_cksum(1): not enough data"));
}
}
}
# endif
if (len <= 0)
goto nodata;
while (len > 1) {
m = m->m_next;
PANIC((!m),("fr_cksum(2): not enough data"));
}
m = m->m_next;
PANIC((!m),("fr_cksum(3): not enough data"));
}
} else
len -= 2;
}
if (len != 0)
while (sum > 0xffff)
}
# endif /* defined(BSD) || defined(sun) */
# endif /* MENTAT */
#else /* _KERNEL */
if (slen)
while (sum > 0xffff)
#endif /* _KERNEL */
return sum2;
}
defined(__sgi) )
/*
* Copyright (c) 1982, 1986, 1988, 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)uipc_mbuf.c 8.2 (Berkeley) 1/4/94
* $Id: fil.c,v 2.197 2003/07/01 18:30:18 darrenr Exp $
*/
/*
* Copy data from an mbuf chain starting "off" bytes from the beginning,
* continuing for "len" bytes, into the indicated buffer.
*/
void
mb_t *m;
int off;
int len;
{
unsigned count;
panic("m_copydata");
while (off > 0) {
if (m == 0)
panic("m_copydata");
break;
m = m->m_next;
}
while (len > 0) {
if (m == 0)
panic("m_copydata");
off = 0;
m = m->m_next;
}
}
/*
* Copy data from a buffer back into the indicated mbuf chain,
* starting "off" bytes from the beginning, extending the mbuf
* chain if necessary.
*/
void
int off;
int len;
{
int mlen;
int totlen = 0;
if (m0 == 0)
return;
if (m->m_next == 0) {
if (n == 0)
goto out;
m->m_next = n;
}
m = m->m_next;
}
while (len > 0) {
off = 0;
if (len == 0)
break;
if (m->m_next == 0) {
if (n == 0)
break;
m->m_next = n;
}
m = m->m_next;
}
out:
#if 0
#endif
return;
}
#endif /* (_KERNEL) && ( ((BSD < 199103) && !MENTAT) || __sgi) */
/* ------------------------------------------------------------------------ */
/* Function: fr_findgroup */
/* Returns: frgroup_t * - NULL = group not found, else pointer to group */
/* Parameters: group(I) - group name to search for */
/* unit(I) - device to which this group belongs */
/* fgpp(O) - pointer to place to store pointer to the pointer */
/* to where to add the next (last) group or where */
/* to delete group from. */
/* */
/* Search amongst the defined groups for a particular group number. */
/* ------------------------------------------------------------------------ */
char *group;
int set;
{
/*
* Which list of groups to search in is dependant on which list of
* rules are being operated on.
*/
break;
else
}
return fg;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_addgroup */
/* Returns: frgroup_t * - NULL == did not create group, */
/* != NULL == pointer to the group */
/* Parameters: num(I) - group number to add */
/* head(I) - rule pointer that is using this as the head */
/* flags(I) - rule flags which describe the type of rule it is */
/* unit(I) - device to which this group will belong to */
/* Write Locks: ipf_mutex */
/* */
/* Add a new group head, or if it already exists, increase the reference */
/* count to it. */
/* ------------------------------------------------------------------------ */
char *group;
void *head;
int set;
{
return NULL;
return NULL;
return NULL;
return fg;
}
}
return fg;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_delgroup */
/* Returns: Nil */
/* Parameters: group(I) - group name to delete */
/* unit(I) - device to which this group belongs */
/* Write Locks: ipf_mutex */
/* */
/* Attempt to delete a group head. */
/* Only do this when its reference count reaches 0. */
/* ------------------------------------------------------------------------ */
char *group;
int set;
{
return;
}
}
/* ------------------------------------------------------------------------ */
/* Function: fr_getrulen */
/* Returns: frentry_t * - NULL == not found, else pointer to rule n */
/* Parameters: unit(I) - device for which to count the rule's number */
/* flags(I) - which set of rules to find the rule in */
/* group(I) - group name */
/* n(I) - rule number to find */
/* */
/* Find rule # n in group # g and return a pointer to it. Return NULl if */
/* group # g doesn't exist or there are less than n rules in the group. */
/* ------------------------------------------------------------------------ */
int unit;
char *group;
u_32_t n;
{
return NULL;
;
if (n != 0)
return NULL;
return fr;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_rulen */
/* Returns: int - >= 0 - rule number, -1 == search failed */
/* Parameters: unit(I) - device for which to count the rule's number */
/* fr(I) - pointer to rule to match */
/* */
/* Return the number for a rule on a specific filtering device. */
/* ------------------------------------------------------------------------ */
int unit;
{
u_32_t n = 0;
return -1;
return -1;
break;
return -1;
return n;
}
/* ------------------------------------------------------------------------ */
/* Function: frflushlist */
/* Returns: int - >= 0 - number of flushed rules */
/* unit(I) - device for which to flush rules */
/* flags(I) - which set of rules to flush */
/* nfreedp(O) - pointer to int where flush count is stored */
/* listp(I) - pointer to list to flush pointer */
/* Write Locks: ipf_mutex */
/* */
/* Recursively flush rules from the list, descending groups as they are */
/* encountered. if a rule is the head of a group and it has lost all its */
/* group members, then also delete the group reference. nfreedp is needed */
/* to store the accumulating count of rules removed, whereas the returned */
/* value is just the number removed from the current list. The latter is */
/* needed to correctly adjust reference counts on rules that define groups. */
/* */
/* NOTE: Rules not loaded from user space cannot be flushed. */
/* ------------------------------------------------------------------------ */
int set;
int *nfreedp;
{
int freed = 0, i;
continue;
}
}
}
if (fr_derefrule(&fp) == 0)
freed++;
}
return freed;
}
/* ------------------------------------------------------------------------ */
/* Function: frflush */
/* Returns: int - >= 0 - number of flushed rules */
/* Parameters: unit(I) - device for which to flush rules */
/* flags(I) - which set of rules to flush */
/* */
/* Calls flushlist() for all filter rules (accounting, firewall - both IPv4 */
/* and IPv6) as defined by the value of flags. */
/* ------------------------------------------------------------------------ */
int flags;
{
if (unit != IPL_LOGIPF)
return 0;
}
}
return flushed;
}
/* ------------------------------------------------------------------------ */
/* Function: memstr */
/* Returns: char * - NULL if failed, != NULL pointer to matching bytes */
/* Parameters: src(I) - pointer to byte sequence to match */
/* dst(I) - pointer to byte sequence to search */
/* slen(I) - match length */
/* dlen(I) - length available to search in */
/* */
/* Search dst for a sequence of bytes matching those at src and extend for */
/* slen bytes. */
/* ------------------------------------------------------------------------ */
{
char *s = NULL;
s = dst;
break;
}
dst++;
dlen--;
}
return s;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_fixskip */
/* Returns: Nil */
/* Parameters: listp(IO) - pointer to start of list with skip rule */
/* addremove(I) - adjustment (-1/+1) to make to skip count, */
/* depending on whether a rule was just added */
/* or removed. */
/* */
/* Adjust all the rules in a list which would have skip'd past the position */
/* where we are inserting to skip to the right place given the change. */
/* ------------------------------------------------------------------------ */
int addremove;
{
rules = 0;
rules++;
if (!fp)
return;
}
#ifdef _KERNEL
/* ------------------------------------------------------------------------ */
/* Function: count4bits */
/* Returns: int - >= 0 - number of consecutive bits in input */
/* Parameters: ip(I) - 32bit IP address */
/* */
/* IPv4 ONLY */
/* count consecutive 1's in bit mask. If the mask generated by counting */
/* consecutive 1's is different to that passed, return -1, else return # */
/* of bits. */
/* ------------------------------------------------------------------------ */
int count4bits(ip)
{
int cnt = 0, i, j;
if (ipn & 0x80000000)
cnt++;
else
break;
ipn = 0;
for (i = 32, j = cnt; i; i--, j--) {
ipn *= 2;
if (j > 0)
ipn++;
}
return cnt;
return -1;
}
# if 0
/* ------------------------------------------------------------------------ */
/* Function: count6bits */
/* Returns: int - >= 0 - number of consecutive bits in input */
/* Parameters: msk(I) - pointer to start of IPv6 bitmask */
/* */
/* IPv6 ONLY */
/* count consecutive 1's in bit mask. */
/* ------------------------------------------------------------------------ */
int count6bits(msk)
{
int i = 0, k;
u_32_t j;
for (k = 3; k >= 0; k--)
if (msk[k] == 0xffffffff)
i += 32;
else {
for (j = msk[k]; j; j <<= 1)
if (j & 0x80000000)
i++;
}
return i;
}
# endif
#endif /* _KERNEL */
/* ------------------------------------------------------------------------ */
/* Function: frsynclist */
/* Returns: void */
/* Parameters: Nil */
/* Write Locks: ipf_mutex */
/* */
/* Walk through a list of filter rules and resolve any interface names into */
/* pointers. Where dynamic addresses are used, also update the IP address */
/* used in the rule. */
/* ------------------------------------------------------------------------ */
static void frsynclist(fr)
{
int v, i;
/*
* Lookup all the interface names that are part of the rule.
*/
for (i = 0; i < 4; i++) {
}
}
}
}
}
}
}
else
}
#ifdef IPFILTER_LOOKUP
&fr->fr_srcfunc);
}
&fr->fr_dstfunc);
}
#endif
}
}
#ifdef _KERNEL
/* ------------------------------------------------------------------------ */
/* Function: frsync */
/* Returns: void */
/* Parameters: Nil */
/* */
/* frsync() is called when we suspect that the interface list or */
/* information about interfaces (like IP#) has changed. Go through all */
/* filter rules, NAT entries and the state table and check if anything */
/* ------------------------------------------------------------------------ */
void frsync()
{
int i;
# ifndef MENTAT
IFNET_RLOCK();
# else
# endif
# else
# endif
{
}
# endif
# endif
for (i = 0; i < IPL_LOGSIZE; i++) {
frgroup_t *g;
frsynclist(g->fg_start);
frsynclist(g->fg_start);
}
}
/*
* In the functions below, bcopy() is called because the pointer being
* copied _from_ in this instance is a pointer to a char buf (which could
* end up being unaligned) and on the kernel's local stack.
*/
/* ------------------------------------------------------------------------ */
/* Function: copyinptr */
/* Returns: int - 0 = success, else failure */
/* Parameters: src(I) - pointer to the source address */
/* dst(I) - destination address */
/* size(I) - number of bytes to copy */
/* */
/* Copy a block of data in from user space, given a pointer to the pointer */
/* to start copying from (src) and a pointer to where to store it (dst). */
/* NB: src - pointer to user space pointer, dst - kernel space pointer */
/* ------------------------------------------------------------------------ */
{
int err;
#if SOLARIS
if (err != 0)
return err;
#else
#endif
return err;
}
/* ------------------------------------------------------------------------ */
/* Function: copyoutptr */
/* Returns: int - 0 = success, else failure */
/* Parameters: src(I) - pointer to the source address */
/* dst(I) - destination address */
/* size(I) - number of bytes to copy */
/* */
/* Copy a block of data out to user space, given a pointer to the pointer */
/* to start copying from (src) and a pointer to where to store it (dst). */
/* NB: src - kernel space pointer, dst - pointer to user space pointer. */
/* ------------------------------------------------------------------------ */
{
int err;
#if SOLARIS
if (err != 0)
return err;
#else
#endif
return err;
}
#else /* _KERNEL */
/*
* See above for description, except that all addressing is in user space.
*/
{
return 0;
}
/*
* See above for description, except that all addressing is in user space.
*/
{
return 0;
}
/*
* return the first IP Address associated with an interface
*/
int v, flags;
void *ifptr;
{
return 0;
}
#endif
/* ------------------------------------------------------------------------ */
/* Function: fr_lock */
/* Returns: int - 0 == success, else error */
/* Parameters: data(I) - pointer to lock value to set */
/* lockp(O) - pointer to location to store old lock value */
/* */
/* Get the new value for the lock integer, set it and return the old value */
/* in *lockp. */
/* ------------------------------------------------------------------------ */
int *lockp;
{
if (!error) {
if (!error)
}
return error;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_getstat */
/* Returns: Nil */
/* Parameters: fiop(I) - pointer to ipfilter stats structure */
/* */
/* Stores a copy of current pointers, counters, etc, in the friostat */
/* structure. */
/* ------------------------------------------------------------------------ */
void fr_getstat(fiop)
{
int i, j;
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++) {
}
for (i = 0; i < IPL_LOGSIZE; i++) {
}
#ifdef IPFILTER_LOG
#else
#endif
}
#ifdef USE_INET6
ICMP6_ECHO_REPLY, /* 0: ICMP_ECHOREPLY */
-1, /* 1: UNUSED */
-1, /* 2: UNUSED */
ICMP6_DST_UNREACH, /* 3: ICMP_UNREACH */
-1, /* 4: ICMP_SOURCEQUENCH */
ND_REDIRECT, /* 5: ICMP_REDIRECT */
-1, /* 6: UNUSED */
-1, /* 7: UNUSED */
ICMP6_ECHO_REQUEST, /* 8: ICMP_ECHO */
-1, /* 9: UNUSED */
-1, /* 10: UNUSED */
ICMP6_TIME_EXCEEDED, /* 11: ICMP_TIMXCEED */
ICMP6_PARAM_PROB, /* 12: ICMP_PARAMPROB */
-1, /* 13: ICMP_TSTAMP */
-1, /* 14: ICMP_TSTAMPREPLY */
-1, /* 15: ICMP_IREQ */
-1, /* 16: ICMP_IREQREPLY */
-1, /* 17: ICMP_MASKREQ */
-1, /* 18: ICMP_MASKREPLY */
};
int icmptoicmp6unreach[ICMP_MAX_UNREACH] = {
ICMP6_DST_UNREACH_ADDR, /* 0: ICMP_UNREACH_NET */
ICMP6_DST_UNREACH_ADDR, /* 1: ICMP_UNREACH_HOST */
-1, /* 2: ICMP_UNREACH_PROTOCOL */
ICMP6_DST_UNREACH_NOPORT, /* 3: ICMP_UNREACH_PORT */
-1, /* 4: ICMP_UNREACH_NEEDFRAG */
ICMP6_DST_UNREACH_NOTNEIGHBOR, /* 5: ICMP_UNREACH_SRCFAIL */
ICMP6_DST_UNREACH_ADDR, /* 6: ICMP_UNREACH_NET_UNKNOWN */
ICMP6_DST_UNREACH_ADDR, /* 7: ICMP_UNREACH_HOST_UNKNOWN */
-1, /* 8: ICMP_UNREACH_ISOLATED */
ICMP6_DST_UNREACH_ADMIN, /* 9: ICMP_UNREACH_NET_PROHIB */
ICMP6_DST_UNREACH_ADMIN, /* 10: ICMP_UNREACH_HOST_PROHIB */
-1, /* 11: ICMP_UNREACH_TOSNET */
-1, /* 12: ICMP_UNREACH_TOSHOST */
ICMP6_DST_UNREACH_ADMIN, /* 13: ICMP_UNREACH_ADMIN_PROHIBIT */
};
#endif
/* ------------------------------------------------------------------------ */
/* Function: fr_matchicmpqueryreply */
/* Returns: int - 1 if "icmp" is a valid reply to "ic" else 0. */
/* Parameters: v(I) - IP protocol version (4 or 6) */
/* ic(I) - ICMP information */
/* icmp(I) - ICMP packet header */
/* rev(I) - direction (0 = forward/1 = reverse) of packet */
/* */
/* Check if the ICMP packet defined by the header pointed to by icmp is a */
/* reply to one as described by what's in ic. If it is a match, return 1, */
/* else return 0 for no match. */
/* ------------------------------------------------------------------------ */
int v;
icmpinfo_t *ic;
int rev;
{
int ictype;
if (v == 4) {
/*
* If we matched its type on the way in, then when going out
* it will still be the same type.
*/
return 1;
return 1;
}
}
#ifdef USE_INET6
else if (v == 6) {
return 1;
return 1;
}
}
#endif
return 0;
}
#ifdef IPFILTER_LOOKUP
/* ------------------------------------------------------------------------ */
/* Function: fr_resolvelookup */
/* Returns: void * - NULL = failure, else success. */
/* Parameters: type(I) - type of lookup these parameters are for. */
/* number(I) - table number to use when searching */
/* funcptr(IO) - pointer to pointer for storing IP address */
/* searching function. */
/* */
/* Search for the "table" number passed in amongst those configured for */
/* that particular type. If the type is recognised then the function to */
/* call to do the IP address search will be change, regardless of whether */
/* or not the "table" number exists. */
/* ------------------------------------------------------------------------ */
{
char name[FR_GROUPLEN];
void *ptr;
switch (type)
{
case IPLT_POOL :
# else
}
# endif
break;
case IPLT_HASH :
}
*funcptr = fr_iphmfindip;
break;
default:
break;
}
return ptr;
}
#endif
/* ------------------------------------------------------------------------ */
/* Function: frrequest */
/* Returns: int - 0 == success, > 0 == errno value */
/* Parameters: unit(I) - device for which this is for */
/* req(I) - ioctl command (SIOC*) */
/* data(I) - pointr to ioctl data */
/* set(I) - 1 or 0 (filter set) */
/* makecopy(I) - flag indicating whether data points to a rule */
/* in kernel space & hence doesn't need copying. */
/* */
/* This function handles all the requests which operate on the list of */
/* filter rules. This includes adding, deleting, insertion. It is also */
/* responsible for creating groups when a "head" rule is loaded. Interface */
/* names are resolved here and other sanity checks are made on the content */
/* of the rule structure being loaded. If a rule has user defined timeouts */
/* then make sure they are created and initialised before exiting. */
/* ------------------------------------------------------------------------ */
int unit;
#if defined(__NetBSD__) || defined(__OpenBSD__) || \
#else
int req;
#endif
{
char *group;
void *ptr;
if (makecopy != 0) {
if (error)
return EFAULT;
return EINVAL;
} else {
return EINVAL;
}
return EINVAL;
/*
* Only filter rules for IPv4 or IPv6 are accepted.
*/
if (v == 4)
/*EMPTY*/;
#ifdef USE_INET6
else if (v == 6)
/*EMPTY*/;
#endif
else {
return EINVAL;
}
/*
* If the rule is being loaded from user space, i.e. we had to copy it
* into kernel space, then do not trust the function pointer in the
* rule.
*/
return ESRCH;
if (error != 0)
return error;
}
/*
* matches what the rule is.
*/
*group = '\0';
return ESRCH;
return ESRCH;
}
/*
* Work out which rule list this change is being applied to.
*/
if (unit == IPL_LOGAUTH)
else if (v == 4) {
} else if (v == 6) {
}
return ESRCH;
if (*group != '\0') {
return ESRCH;
}
break;
/*
* Copy in extra data for the rule.
*/
if (makecopy != 0) {
if (!ptr)
return ENOMEM;
} else {
error = 0;
}
if (error != 0) {
return ENOMEM;
}
} else
/*
* Perform per-rule type sanity checks of their members.
*/
{
#if defined(IPFILTER_BPF) && defined(_KERNEL)
case FR_T_BPFOPC :
return EINVAL;
}
return EINVAL;
}
break;
#endif
case FR_T_IPF :
return EINVAL;
{
case FRI_BROADCAST :
case FRI_DYNAMIC :
case FRI_NETWORK :
case FRI_NETMASKED :
case FRI_PEERADDR :
}
return EINVAL;
}
break;
#ifdef IPFILTER_LOOKUP
case FRI_LOOKUP :
&fp->fr_srcfunc);
break;
#endif
default :
break;
}
{
case FRI_BROADCAST :
case FRI_DYNAMIC :
case FRI_NETWORK :
case FRI_NETMASKED :
case FRI_PEERADDR :
}
return EINVAL;
}
break;
#ifdef IPFILTER_LOOKUP
case FRI_LOOKUP :
&fp->fr_dstfunc);
break;
#endif
default :
break;
}
break;
case FR_T_NONE :
break;
case FR_T_CALLFUNC :
break;
case FR_T_COMPIPF :
break;
default :
}
return EINVAL;
}
/*
* Lookup all the interface names that are part of the rule.
*/
frsynclist(fp);
fp->fr_statecnt = 0;
/*
* Look for an existing matching filter rule, but don't include the
* next or interface pointer in the comparison (fr_next, fr_ifa).
* This elminates rules which are indentical being loaded. Checksum
* the constant part of the filter rule to make comparisons quicker
* (this meaning no pointers are included).
*/
p < pp; p++)
break;
/*
* If zero'ing statistics, copy current to caller and zero.
*/
if (f == NULL)
else {
if (error == 0) {
f->fr_dsize);
if (error == 0) {
f->fr_hits = 0;
f->fr_bytes = 0;
}
}
}
}
return error;
}
if (!f) {
}
f = NULL;
error = 0;
}
}
/*
* Request to remove a rule.
*/
if (!f)
else {
/*
* Do not allow activity from user space to interfere
* with rules not loaded that way.
*/
goto done;
}
/*
* Return EBUSY if the rule is being reference by
* something else (eg state information.
*/
if (f->fr_ref > 1) {
goto done;
}
#ifdef IPFILTER_SCAN
if (f->fr_isctag[0] != '\0' &&
isc_detachfr(f);
#endif
if (unit == IPL_LOGAUTH) {
goto done;
}
if (*f->fr_grhead != '\0')
(void)fr_derefrule(&f);
}
} else {
/*
*/
if (f)
else {
if (unit == IPL_LOGAUTH) {
goto done;
}
if (makecopy) {
} else
f = fp;
if (f != NULL) {
if (fp != f)
sizeof(*f));
MUTEX_NUKE(&f->fr_lock);
#ifdef IPFILTER_SCAN
#endif
f->fr_hits = 0;
if (makecopy != 0)
f->fr_ref = 1;
*ftail = f;
if (*group != '\0') {
}
} else
}
}
done:
}
return (error);
}
/* ------------------------------------------------------------------------ */
/* Function: fr_funcinit */
/* Returns: int - 0 == success, else ESRCH: cannot resolve rule details */
/* Parameters: fr(I) - pointer to filter rule */
/* */
/* If a rule is a call rule, then check if the function it points to needs */
/* an init function to be called now the rule has been loaded. */
/* ------------------------------------------------------------------------ */
static int fr_funcinit(fr)
{
int err;
err = 0;
break;
}
return err;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_findfunc */
/* Returns: ipfunc_t - pointer to function if found, else NULL */
/* Parameters: funcptr(I) - function pointer to lookup */
/* */
/* Look for a function in the table of known functions. */
/* ------------------------------------------------------------------------ */
{
return funcptr;
return NULL;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_resolvefunc */
/* Returns: int - 0 == success, else error */
/* Parameters: data(IO) - ioctl data pointer to ipfunc_resolve_t struct */
/* */
/* Copy in a ipfunc_resolve_t structure and then fill in the missing field. */
/* This will either be the function name (if the pointer is set) or the */
/* function pointer if the name is set. When found, fill in the details so */
/* it can be copied back to user space. */
/* ------------------------------------------------------------------------ */
int fr_resolvefunc(data)
void *data;
{
return EFAULT;
return EFAULT;
return 0;
}
}
return EFAULT;
return 0;
}
}
return ESRCH;
}
/*
* From: NetBSD
* ppsratecheck(): packets (or events) per second limitation.
*/
int
int *curpps;
int maxpps; /* maximum pps allowed */
{
int rv;
}
/*
* check for 0,0 is so that the message will be seen at least once.
* if more than one second have passed since the last update of
* lasttime, reset the counter.
*
* we do increment *curpps even in *curpps < maxpps case, as some may
* try to use *curpps for stat purposes as well.
*/
*curpps = 0;
rv = 1;
} else if (maxpps < 0)
rv = 1;
rv = 1;
else
rv = 0;
return (rv);
}
#endif
/* ------------------------------------------------------------------------ */
/* Function: fr_derefrule */
/* Returns: int - 0 == rule freed up, else rule not freed */
/* Parameters: fr(I) - pointer to filter rule */
/* */
/* Decrement the reference counter to a rule by one. If it reaches zero, */
/* free it and any associated storage space being used by it. */
/* ------------------------------------------------------------------------ */
int fr_derefrule(frp)
{
#ifdef IPFILTER_LOOKUP
#endif
}
return 0;
}
return 1;
} else {
}
return -1;
}
#ifdef IPFILTER_LOOKUP
/* ------------------------------------------------------------------------ */
/* Function: fr_grpmapinit */
/* Returns: int - 0 == success, else ESRCH because table entry not found*/
/* Parameters: fr(I) - pointer to rule to find hash table for */
/* */
/* Looks for group hash table fr_arg and stores a pointer to it in fr_ptr. */
/* fr_ptr is later used by fr_srcgrpmap and fr_dstgrpmap. */
/* ------------------------------------------------------------------------ */
static int fr_grpmapinit(fr)
{
char name[FR_GROUPLEN];
return ESRCH;
return ESRCH;
return 0;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_srcgrpmap */
/* Returns: frentry_t * - pointer to "new last matching" rule or NULL */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* Look for a rule group head in a hash table, using the source address as */
/* the key, and descend into that group and continue matching rules against */
/* the packet. */
/* ------------------------------------------------------------------------ */
{
void *rval;
return NULL;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_dstgrpmap */
/* Returns: frentry_t * - pointer to "new last matching" rule or NULL */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* Look for a rule group head in a hash table, using the destination */
/* address as the key, and descend into that group and continue matching */
/* rules against the packet. */
/* ------------------------------------------------------------------------ */
{
void *rval;
return NULL;
}
#endif /* IPFILTER_LOOKUP */
/* ------------------------------------------------------------------------ */
/* Function: fr_addtimeoutqueue */
/* Returns: struct ifqtq * - NULL if malloc fails, else pointer to */
/* timeout queue with given interval. */
/* Parameters: parent(I) - pointer to pointer to parent node of this list */
/* of interface queues. */
/* seconds(I) - timeout value in seconds for this queue. */
/* */
/* This routine first looks for a timeout queue that matches the interval */
/* being requested. If it finds one, increments the reference counter and */
/* returns a pointer to it. If none are found, it allocates a new one and */
/* inserts it at the top of the list. */
/* ------------------------------------------------------------------------ */
{
break;
return ifq;
}
fr_userifqs++;
}
return ifq;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_deletetimeoutqueue */
/* Returns: Nil */
/* Parameters: difp(I) - timeout queue which is losing a reference. */
/* */
/* This routine must be called when we're discarding a pointer to a timeout */
/* queue object. It takes care of the reference counter and free's it when */
/* it reaches 0. */
/* ------------------------------------------------------------------------ */
void fr_deletetimeoutqueue(ifq)
{
/*
* Remove from its position in the list.
*/
fr_userifqs--;
} else {
}
}
/* ------------------------------------------------------------------------ */
/* Function: fr_queuefront */
/* Returns: Nil */
/* Parameters: tq(I) - pointer to timeout queue information */
/* */
/* Move a queue entry to the front of the queue, if it isn't already there. */
/* ------------------------------------------------------------------------ */
void fr_queuefront(tqe)
{
else
}
}
/* ------------------------------------------------------------------------ */
/* Function: fr_queueback */
/* Returns: Nil */
/* Parameters: tq(I) - pointer to timeout queue information */
/* */
/* Move a queue entry to the back of the queue, if it isn't already there. */
/* ------------------------------------------------------------------------ */
void fr_queueback(tqe)
{
}
}
/* ------------------------------------------------------------------------ */
/* Function: fr_movequeue */
/* Returns: Nil */
/* Parameters: tq(I) - pointer to timeout queue information */
/* oifp(I) - old timeout queue entry was on */
/* nifp(I) - new timeout queue to put entry on */
/* */
/* Move a queue entry from one timeout queue to another timeout queue. */
/* If it notices that the current entry is already last and does not need */
/* to move queue, the return. */
/* ------------------------------------------------------------------------ */
{
/*
* Is the operation here going to be a no-op ?
*/
return;
/*
* Remove from the old queue
*/
else
/*
* If we're moving from one queue to another, release the lock on the
* old queue and get a lock on the new queue. For user defined queues,
* if we're moving off it, call delete in case it can now be freed.
*/
}
/*
* Add to the bottom of the new queue
*/
}
/* ------------------------------------------------------------------------ */
/* Function: fr_updateipid */
/* Returns: int - 0 == success, -1 == error (packet should be droppped) */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* When we are doing NAT, change the IP of every packet to represent a */
/* single sequence of packets coming from the host, hiding any host */
/* specific sequencing that might otherwise be revealed. If the packet is */
/* a fragment, then store the 'new' IPid in the fragment cache and look up */
/* the fragment cache for non-leading fragments. If a non-leading fragment */
/* has no match in the cache, return an error. */
/* ------------------------------------------------------------------------ */
{
if (sum == 0xffffffff)
return -1;
sum &= 0xffff;
} else {
}
return 0;
return 0;
}
#ifdef NEED_FRGETIFNAME
/* ------------------------------------------------------------------------ */
/* Function: fr_getifname */
/* Returns: char * - pointer to interface name */
/* Parameters: ifp(I) - pointer to network interface */
/* */
/* Constructs an interface name in the buffer passed. */
/* ------------------------------------------------------------------------ */
char *buffer;
{
char temp[20];
char *s;
for (s = buffer; *s; s++)
;
if (space > 0) {
}
return buffer;
}
#endif
/* ------------------------------------------------------------------------ */
/* Function: fr_ioctlswitch */
/* Returns: int - -1 continue processing, else ioctl return value */
/* Parameters: unit(I) - device unit opened */
/* data(I) - pointer to ioctl data */
/* cmd(I) - ioctl command */
/* mode(I) - mode value */
/* */
/* Based on the value of unit, call the appropriate ioctl handler or return */
/* EIO if ipfilter is not running. Also checks if write perms are req'd */
/* for the device in order to execute the ioctl. */
/* ------------------------------------------------------------------------ */
# if defined(__NetBSD__) || defined(__OpenBSD__)
#else
int cmd;
#endif
void *data;
{
int error = 0;
switch (unit)
{
case IPL_LOGIPF :
error = -1;
break;
case IPL_LOGNAT :
if (fr_running > 0)
else
break;
case IPL_LOGSTATE :
if (fr_running > 0)
else
break;
case IPL_LOGAUTH :
if (fr_running > 0) {
} else {
fr_active, 1);
}
} else {
}
} else
break;
case IPL_LOGSYNC :
#ifdef IPFILTER_SYNC
if (fr_running > 0)
else
#endif
break;
case IPL_LOGSCAN :
#ifdef IPFILTER_SCAN
if (fr_running > 0)
else
#endif
break;
case IPL_LOGLOOKUP :
#ifdef IPFILTER_LOOKUP
if (fr_running > 0)
else
#endif
break;
default :
break;
}
return error;
}
/*
* This array defines the expected size of objects coming into the kernel
* for the various recognised object types.
*/
static int fr_objbytes[] = {
0, /* frentry */
sizeof(struct friostat),
sizeof(struct fr_info),
sizeof(struct fr_authstat),
sizeof(struct ipfrstat),
sizeof(struct ipnat),
sizeof(struct natstat),
sizeof(struct ipstate_save),
sizeof(struct nat_save),
sizeof(struct natlookup),
0, /* ipstate */
sizeof(struct ips_stat),
sizeof(struct frauth),
sizeof(struct ipftune)
};
/* ------------------------------------------------------------------------ */
/* Function: fr_inobj */
/* Returns: int - 0 = success, else failure */
/* Parameters: data(I) - pointer to ioctl data */
/* ptr(I) - pointer to store real data in */
/* type(I) - type of structure being moved */
/* */
/* Copy in the contents of what the ipfobj_t points to. In future, we */
/* add things to check for version numbers, sizes, etc, to make it backward */
/* compatible at the ABI for user land. */
/* ------------------------------------------------------------------------ */
void *data;
void *ptr;
int type;
{
int error = 0;
if ((type < 0) ||
return EINVAL;
return EINVAL;
#ifndef IPFILTER_COMPAT
return EINVAL;
return EINVAL;
#else
/* XXX compatibility hook here */
return EINVAL;
/* XXX compatibility hook here */
return EINVAL;
#endif
return error;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_outobj */
/* Returns: int - 0 = success, else failure */
/* Parameters: data(I) - pointer to ioctl data */
/* ptr(I) - pointer to store real data in */
/* type(I) - type of structure being moved */
/* */
/* Copy out the contents of what ptr is to where ipfobj points to. In */
/* future, we add things to check for version numbers, sizes, etc, to make */
/* it backward compatible at the ABI for user land. */
/* ------------------------------------------------------------------------ */
void *data;
void *ptr;
int type;
{
int error;
return EINVAL;
#ifndef IPFILTER_COMPAT
return EINVAL;
return EINVAL;
#else
/* XXX compatibility hook here */
return EINVAL;
/* XXX compatibility hook here */
return EINVAL;
#endif
return error;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_checkl4sum */
/* Returns: int - 0 = good, -1 = bad, 1 = cannot check */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* If possible, calculate the layer 4 checksum for the packet. If this is */
/* not possible, return without indicating a failure or success but in a */
/* way that is ditinguishable. */
/* ------------------------------------------------------------------------ */
int fr_checkl4sum(fin)
{
int dosum;
return 0;
/*
* If the TCP packet isn't a fragment, isn't too short and otherwise
* isn't already considered "bad", then validate the checksum. If
* this check fails then considered the packet to be "bad".
*/
return 1;
hdrsum = 0;
dosum = 0;
sum = 0;
hdrsum = 0;
sum = 0;
} else {
#endif
{
case IPPROTO_TCP :
dosum = 1;
break;
case IPPROTO_UDP :
dosum = 1;
}
break;
case IPPROTO_ICMP :
dosum = 1;
break;
default :
return 1;
/*NOTREACHED*/
}
if (dosum)
}
#endif
#if !defined(_KERNEL)
#endif
return 0;
return -1;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_ifpfillv4addr */
/* Returns: int - 0 = address update, -1 = address not updated */
/* Parameters: atype(I) - type of network address update to perform */
/* sin(I) - pointer to source of address information */
/* mask(I) - pointer to source of netmask information */
/* inp(I) - pointer to destination address store */
/* inpmask(I) - pointer to destination netmask store */
/* */
/* Given a type of network address update (atype) to perform, copy */
/* netmask update is performed unless FRI_NETMASKED is passed as atype, in */
/* which case the operation fails. For all values of atype other than */
/* FRI_NETMASKED, if inpmask is non-NULL then the mask is set to an all 1s */
/* value. */
/* ------------------------------------------------------------------------ */
int atype;
{
if (atype == FRI_NETMASKED) {
return -1;
}
} else {
}
return 0;
}
#ifdef USE_INET6
/* ------------------------------------------------------------------------ */
/* Function: fr_ifpfillv6addr */
/* Returns: int - 0 = address update, -1 = address not updated */
/* Parameters: atype(I) - type of network address update to perform */
/* sin(I) - pointer to source of address information */
/* mask(I) - pointer to source of netmask information */
/* inp(I) - pointer to destination address store */
/* inpmask(I) - pointer to destination netmask store */
/* */
/* Given a type of network address update (atype) to perform, copy */
/* netmask update is performed unless FRI_NETMASKED is passed as atype, in */
/* which case the operation fails. For all values of atype other than */
/* FRI_NETMASKED, if inpmask is non-NULL then the mask is set to an all 1s */
/* value. */
/* ------------------------------------------------------------------------ */
int atype;
{
}
if (atype == FRI_NETMASKED) {
return -1;
}
} else {
}
return 0;
}
#endif
/* ------------------------------------------------------------------------ */
/* Function: fr_coalesce */
/* Returns: 1 == success, -1 == failure */
/* Parameters: fin(I) - pointer to packet information */
/* */
/* Attempt to get all of the packet data into a single, contiguous buffer. */
/* If this call returns a failure then the buffers have also been freed. */
/* ------------------------------------------------------------------------ */
int fr_coalesce(fin)
{
# ifdef MENTAT
# endif
return -1;
}
#endif
return 1;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_matchtag */
/* Returns: 0 == mismatch, 1 == match. */
/* Parameters: tag1(I) - pointer to first tag to compare */
/* tag2(I) - pointer to second tag to compare */
/* */
/* Returns true (non-zero) or false(0) if the two tag structures can be */
/* considered to be a match or not match, respectively. The tag is 16 */
/* bytes long (16 characters) but that is overlayed with 4 32bit ints so */
/* compare the ints instead, for speed. tag1 is the master of the */
/* comparison. This function should only be called with both tag1 and tag2 */
/* as non-NULL pointers. */
/* ------------------------------------------------------------------------ */
{
return 1;
return 1;
return 1;
return 0;
}
/* ------------------------------------------------------------------------ */
/* 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. */
/* ------------------------------------------------------------------------ */
int len;
{
# ifdef MENTAT
# endif
char *ip;
if (m == NULL)
return NULL;
return MTOD(m, void *);
else
dpoff = 0;
# ifdef MENTAT
int inc = 0;
if (ipoff > 0) {
if ((ipoff & 3) != 0) {
else
inc = 0;
}
}
return NULL;
}
# else
if (m == NULL) {
return NULL;
}
# endif /* MENTAT */
}
return ip;
}
#endif /* _KERNEL && !__sgi */
/*
* The following table lists all of the tunable variables that can be
* accessed via SIOCIPFGET/SIOCIPFSET/SIOCIPFGETNEXt. The format of each row
* in the table below is as follows:
*
* pointer to value, name of value, minimum, maximum, size of the value's
* container, value attribute flags
*
* For convienience, IPFT_RDONLY means the value is read-only, IPFT_WRDISABLED
* means the value can only be written to when IPFilter is loaded but disabled.
* The obvious implication is if neither of these are set then the value can be
* changed at any time without harm.
*/
ipftuneable_t ipf_tuneables[] = {
/* filtering */
sizeof(fr_flags), 0 },
{ { &fr_active }, "fr_active", 0, 0,
sizeof(fr_active), IPFT_RDONLY },
sizeof(fr_control_forwarding), 0 },
sizeof(fr_update_ipid), 0 },
sizeof(fr_chksrc), 0 },
sizeof(fr_pass), 0 },
sizeof(fr_unreach), 0 },
/* state */
sizeof(fr_tcpidletimeout), IPFT_WRDISABLED },
sizeof(fr_tcpclosewait), IPFT_WRDISABLED },
sizeof(fr_tcplastack), IPFT_WRDISABLED },
sizeof(fr_tcptimeout), IPFT_WRDISABLED },
sizeof(fr_tcpclosed), IPFT_WRDISABLED },
sizeof(fr_tcphalfclosed), IPFT_WRDISABLED },
sizeof(fr_udptimeout), IPFT_WRDISABLED },
sizeof(fr_udpacktimeout), IPFT_WRDISABLED },
sizeof(fr_icmptimeout), IPFT_WRDISABLED },
sizeof(fr_icmpacktimeout), IPFT_WRDISABLED },
sizeof(fr_statemax), IPFT_WRDISABLED },
sizeof(fr_statesize), IPFT_WRDISABLED },
sizeof(fr_state_lock), IPFT_RDONLY },
sizeof(fr_state_maxbucket), IPFT_WRDISABLED },
sizeof(fr_state_maxbucket_reset), IPFT_WRDISABLED },
sizeof(ipstate_logging), 0 },
/* nat */
sizeof(fr_nat_lock), IPFT_RDONLY },
sizeof(ipf_nattable_sz), IPFT_WRDISABLED },
sizeof(ipf_natrules_sz), IPFT_WRDISABLED },
sizeof(ipf_rdrrules_sz), IPFT_WRDISABLED },
sizeof(ipf_hostmap_sz), IPFT_WRDISABLED },
sizeof(fr_nat_maxbucket), IPFT_WRDISABLED },
sizeof(fr_nat_maxbucket_reset), IPFT_WRDISABLED },
sizeof(nat_logging), 0 },
sizeof(fr_defnatage), IPFT_WRDISABLED },
sizeof(fr_defnaticmpage), IPFT_WRDISABLED },
/* frag */
sizeof(ipfr_size), IPFT_WRDISABLED },
sizeof(fr_ipfrttl), IPFT_WRDISABLED },
#ifdef IPFILTER_LOG
/* log */
sizeof(ipl_suppress), 0 },
{ { &ipl_buffer_sz }, "ipl_buffer_sz", 0, 0,
sizeof(ipl_buffer_sz), IPFT_RDONLY },
sizeof(ipl_logmax), IPFT_WRDISABLED },
sizeof(ipl_logall), 0 },
#endif
};
/* ------------------------------------------------------------------------ */
/* Function: fr_ipftune */
/* Returns: int - 0 == success, else failure */
/* Parameters: cmd(I) - ioctl command number */
/* data(I) - pointer to ioctl data structure */
/* */
/* Implement handling of SIOCIPFGETNEXT, SIOCIPFGET and SIOCIPFSET. These */
/* three ioctls provide the means to access and control global variables */
/* within IPFilter, allowing (for example) timeouts and table sizes to be */
/* changed without rebooting, reloading or recompiling. The initialisation */
/* and 'destruction' routines of the various components of ipfilter are all */
/* each responsible for handling their own values being too big. */
/* ------------------------------------------------------------------------ */
#if defined(__NetBSD__) || defined(__OpenBSD__) || \
#else
int cmd;
#endif
char *data;
{
char namebuf[80];
void *cookie;
int error;
if (error != 0)
return error;
ta = ipf_tuneables;
switch (cmd)
{
case SIOCIPFGETNEXT :
/*
* If cookie is non-NULL, assume it to be a pointer to the last
* entry we looked at, so find it (if possible) and return a
* pointer to the next one after it. The last entry in the
* the table is a NULL entry, so when we get to it, set cookie
* to NULL and return that, indicating end of list, erstwhile
* if we come in with cookie set to NULL, we are starting anew
* at the front of the list.
*/
ta++;
break;
}
}
/*
* Entry found, but does the data pointed to by that
* row fit in what we can return?
*/
return EINVAL;
tu.ipft_vlong = 0;
}
return error;
/*NOTREACHED*/
case SIOCIPFGET :
case SIOCIPFSET :
/*
* Search by name or by cookie value for a particular entry
* in the tuning paramter table.
*/
break;
break;
} else
return ESRCH;
return ESRCH;
switch (cmd)
{
case SIOCIPFGET :
/*
* Fetch the tuning parameters for a particular value
*/
tu.ipft_vlong = 0;
return error;
/*NOTREACHED*/
case SIOCIPFSET :
/*
* Set an internal parameter. The hard part here is
* getting the new value safely and correctly out of
* the kernel (given we only know its size, not type.)
*/
{
(fr_running > 0))
return EBUSY;
return EINVAL;
}
return error;
}
/*NOTREACHED*/
}
default :
break;
}
return EINVAL;
}