Attachment 'ip_fil.h'

Download

   1 /*  DO NOT EDIT THIS FILE.
   2 
   3     It has been auto-edited by fixincludes from:
   4 
   5 	"/usr/include/netinet/ip_fil.h"
   6 
   7     This had to be done to correct non-standard usages in the
   8     original, manufacturer supplied header file.  */
   9 
  10 /*
  11  * Copyright (C) 1993-2001, 2003 by Darren Reed.
  12  *
  13  * See the IPFILTER.LICENCE file for details on licencing.
  14  *
  15  * @(#)ip_fil.h	1.35 6/5/96
  16  * $Id: ip_fil.h,v 2.170.2.22 2005/07/16 05:55:35 darrenr Exp $
  17  *
  18  * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  19  */
  20 
  21 #pragma ident	"@(#)ip_fil.h	1.20	11/04/25 SMI"
  22 
  23 #ifndef	__IP_FIL_H__
  24 #define	__IP_FIL_H__
  25 
  26 #include "netinet/ip_compat.h"
  27 #include "sys/kstat.h"
  28 
  29 #ifndef	SOLARIS
  30 # define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
  31 #endif
  32 
  33 #ifndef	__P
  34 # ifdef	__STDC__
  35 #  define	__P(x)	x
  36 # else
  37 #  define	__P(x)	()
  38 # endif
  39 #endif
  40 
  41 #if defined(__STDC__) || defined(__GNUC__) || defined(_AIX51)
  42 # define	SIOCADAFR	_IOW('r', 60, struct ipfobj)
  43 # define	SIOCRMAFR	_IOW('r', 61, struct ipfobj)
  44 # define	SIOCSETFF	_IOW('r', 62, u_int)
  45 # define	SIOCGETFF	_IOR('r', 63, u_int)
  46 # define	SIOCGETFS	_IOWR('r', 64, struct ipfobj)
  47 # define	SIOCIPFFL	_IOWR('r', 65, int)
  48 # define	SIOCIPFFB	_IOR('r', 66, int)
  49 # define	SIOCADIFR	_IOW('r', 67, struct ipfobj)
  50 # define	SIOCRMIFR	_IOW('r', 68, struct ipfobj)
  51 # define	SIOCSWAPA	_IOR('r', 69, u_int)
  52 # define	SIOCINAFR	_IOW('r', 70, struct ipfobj)
  53 # define	SIOCINIFR	_IOW('r', 71, struct ipfobj)
  54 # define	SIOCFRENB	_IOW('r', 72, u_int)
  55 # define	SIOCFRSYN	_IOW('r', 73, u_int)
  56 # define	SIOCFRZST	_IOWR('r', 74, struct ipfobj)
  57 # define	SIOCZRLST	_IOWR('r', 75, struct ipfobj)
  58 # define	SIOCAUTHW	_IOWR('r', 76, struct ipfobj)
  59 # define	SIOCAUTHR	_IOWR('r', 77, struct ipfobj)
  60 # define	SIOCATHST	_IOWR('r', 78, struct ipfobj)
  61 # define	SIOCSTLCK	_IOWR('r', 79, u_int)
  62 # define	SIOCSTPUT	_IOWR('r', 80, struct ipfobj)
  63 # define	SIOCSTGET	_IOWR('r', 81, struct ipfobj)
  64 # define	SIOCSTGSZ	_IOWR('r', 82, struct ipfobj)
  65 # define	SIOCGFRST	_IOWR('r', 83, struct ipfobj)
  66 # define	SIOCSETLG	_IOWR('r', 84, int)
  67 # define	SIOCGETLG	_IOWR('r', 85, int)
  68 # define	SIOCFUNCL	_IOWR('r', 86, struct ipfunc_resolve)
  69 # define	SIOCIPFGETNEXT	_IOWR('r', 87, struct ipfobj)
  70 # define	SIOCIPFGET	_IOWR('r', 88, struct ipfobj)
  71 # define	SIOCIPFSET	_IOWR('r', 89, struct ipfobj)
  72 # define	SIOCIPFL6	_IOWR('r', 90, int)
  73 # define	SIOCIPFLP	_IOWR('r', 91, int)
  74 # define	SIOCIPFITER	_IOWR('r', 92, struct ipfobj)
  75 # define	SIOCGENITER	_IOWR('r', 93, struct ipfobj)
  76 # define	SIOCGTABL	_IOWR('r', 94, struct ipfobj)
  77 # define	SIOCIPFDELTOK	_IOWR('r', 95, int)
  78 # define	SIOCLOOKUPITER	_IOWR('r', 96, struct ipfobj)
  79 # define	SIOCGTQTAB	_IOWR('r', 97, struct ipfobj)
  80 #else
  81 # define	SIOCADAFR	_IOW('r', 60, struct ipfobj)
  82 # define	SIOCRMAFR	_IOW('r', 61, struct ipfobj)
  83 # define	SIOCSETFF	_IOW('r', 62, u_int)
  84 # define	SIOCGETFF	_IOR('r', 63, u_int)
  85 # define	SIOCGETFS	_IOWR('r', 64, struct ipfobj)
  86 # define	SIOCIPFFL	_IOWR('r', 65, int)
  87 # define	SIOCIPFFB	_IOR('r', 66, int)
  88 # define	SIOCADIFR	_IOW('r', 67, struct ipfobj)
  89 # define	SIOCRMIFR	_IOW('r', 68, struct ipfobj)
  90 # define	SIOCSWAPA	_IOR('r', 69, u_int)
  91 # define	SIOCINAFR	_IOW('r', 70, struct ipfobj)
  92 # define	SIOCINIFR	_IOW('r', 71, struct ipfobj)
  93 # define	SIOCFRENB	_IOW('r', 72, u_int)
  94 # define	SIOCFRSYN	_IOW('r', 73, u_int)
  95 # define	SIOCFRZST	_IOWR('r', 74, struct ipfobj)
  96 # define	SIOCZRLST	_IOWR('r', 75, struct ipfobj)
  97 # define	SIOCAUTHW	_IOWR('r', 76, struct ipfobj)
  98 # define	SIOCAUTHR	_IOWR('r', 77, struct ipfobj)
  99 # define	SIOCATHST	_IOWR('r', 78, struct ipfobj)
 100 # define	SIOCSTLCK	_IOWR('r', 79, u_int)
 101 # define	SIOCSTPUT	_IOWR('r', 80, struct ipfobj)
 102 # define	SIOCSTGET	_IOWR('r', 81, struct ipfobj)
 103 # define	SIOCSTGSZ	_IOWR('r', 82, struct ipfobj)
 104 # define	SIOCGFRST	_IOWR('r', 83, struct ipfobj)
 105 # define	SIOCSETLG	_IOWR('r', 84, int)
 106 # define	SIOCGETLG	_IOWR('r', 85, int)
 107 # define	SIOCFUNCL	_IOWR('r', 86, struct ipfunc_resolve)
 108 # define	SIOCIPFGETNEXT	_IOWR('r', 87, struct ipfobj)
 109 # define	SIOCIPFGET	_IOWR('r', 88, struct ipfobj)
 110 # define	SIOCIPFSET	_IOWR('r', 89, struct ipfobj)
 111 # define	SIOCIPFL6	_IOWR('r', 90, int)
 112 # define	SIOCIPFLP	_IOWR('r', 91, int)
 113 # define	SIOCIPFITER	_IOWR('r', 92, struct ipfobj)
 114 # define	SIOCGENITER	_IOWR('r', 93, struct ipfobj)
 115 # define	SIOCGTABL	_IOWR('r', 94, struct ipfobj)
 116 # define	SIOCIPFDELTOK	_IOWR('r', 95, int)
 117 # define	SIOCLOOKUPITER	_IOWR('r', 96, struct ipfobj)
 118 # define	SIOCGTQTAB	_IOWR('r', 97, struct ipfobj)
 119 #endif
 120 #define	SIOCADDFR	SIOCADAFR
 121 #define	SIOCDELFR	SIOCRMAFR
 122 #define	SIOCINSFR	SIOCINAFR
 123 
 124 /*
 125  * What type of table is getting flushed?
 126  */
 127 
 128 #define	NAT_FLUSH	1
 129 #define	STATE_FLUSH	2
 130 
 131 /*
 132  * What table flush options are available?
 133  */
 134 
 135 #define	FLUSH_LIST	0
 136 #define	FLUSH_TABLE_ALL		1	/* Flush entire table */
 137 #define	FLUSH_TABLE_CLOSING	2	/* Flush "closing" entries" */
 138 #define	FLUSH_TABLE_EXTRA	3	/* Targetted flush: almost closed, long idle */
 139 
 140 #define	VALID_TABLE_FLUSH_OPT(x)	((x) >= 1 && (x) <= 3)
 141 
 142 /*
 143  * Define the default hi and lo watermarks used when flushing the
 144  * tables.  The values represent percent full of respective tables.
 145  */
 146 
 147 #define NAT_FLUSH_HI	95
 148 #define NAT_FLUSH_LO	75
 149 
 150 #define ST_FLUSH_HI	95
 151 #define ST_FLUSH_LO	75
 152 
 153 /*
 154  * How full are the tables?
 155  */
 156 
 157 #define	NAT_TAB_WATER_LEVEL(x)	((x)->ifs_nat_stats.ns_inuse * 100 \
 158 				/ (x)->ifs_ipf_nattable_max)
 159 
 160 #define	ST_TAB_WATER_LEVEL(x)	((x)->ifs_ips_num * 100 \
 161 				/ (x)->ifs_fr_statemax)
 162 
 163 struct ipscan;
 164 struct ifnet;
 165 
 166 typedef struct ipf_stack ipf_stack_t;
 167 typedef struct fr_info fr_info_t;
 168 
 169 typedef	int	(* lookupfunc_t) __P((void *, int, void *, fr_info_t *, ipf_stack_t *));
 170 
 171 /*
 172  * i6addr is used as a container for both IPv4 and IPv6 addresses, as well
 173  * as other types of objects, depending on its qualifier.
 174  */
 175 #ifdef	USE_INET6
 176 typedef	union	i6addr	{
 177 	u_32_t	i6[4];
 178 	struct	in_addr	in4;
 179 	struct	in6_addr in6;
 180 	void	*vptr[2];
 181 	lookupfunc_t	lptr[2];
 182 } i6addr_t;
 183 #define	in6_addr8	in6.s6_addr
 184 #else
 185 typedef	union	i6addr	{
 186 	u_32_t	i6[4];
 187 	struct	in_addr	in4;
 188 	void	*vptr[2];
 189 	lookupfunc_t	lptr[2];
 190 } i6addr_t;
 191 #endif
 192 
 193 #define	in4_addr	in4.s_addr
 194 #define	iplookupnum	i6[0]
 195 #define	iplookuptype	i6[1]
 196 /*
 197  * NOTE: These DO overlap the above on 64bit systems and this IS recognised.
 198  */
 199 #define	iplookupptr	vptr[0]
 200 #define	iplookupfunc	lptr[1]
 201 
 202 #define	I60(x)	(((i6addr_t *)(x))->i6[0])
 203 #define	I61(x)	(((i6addr_t *)(x))->i6[1])
 204 #define	I62(x)	(((i6addr_t *)(x))->i6[2])
 205 #define	I63(x)	(((i6addr_t *)(x))->i6[3])
 206 #define	HI60(x)	ntohl(((i6addr_t *)(x))->i6[0])
 207 #define	HI61(x)	ntohl(((i6addr_t *)(x))->i6[1])
 208 #define	HI62(x)	ntohl(((i6addr_t *)(x))->i6[2])
 209 #define	HI63(x)	ntohl(((i6addr_t *)(x))->i6[3])
 210 
 211 #define	IP6_EQ(a,b)	((I63(a) == I63(b)) && (I62(a) == I62(b)) && \
 212 			 (I61(a) == I61(b)) && (I60(a) == I60(b)))
 213 #define	IP6_NEQ(a,b)	((I63(a) != I63(b)) || (I62(a) != I62(b)) || \
 214 			 (I61(a) != I61(b)) || (I60(a) != I60(b)))
 215 #define	IP6_ISZERO(a)   ((I60(a) | I61(a) | I62(a) | I63(a)) == 0)
 216 #define IP6_NOTZERO(a)  ((I60(a) | I61(a) | I62(a) | I63(a)) != 0)
 217 #define	IP6_ISONES(a)	((I63(a) == 0xffffffff) && (I62(a) == 0xffffffff) && \
 218 			 (I61(a) == 0xffffffff) && (I60(a) == 0xffffffff))
 219 #define	IP6_GT(a,b)	(ntohl(HI60(a)) > ntohl(HI60(b)) || \
 220 			 (HI60(a) == HI60(b) && \
 221 			  (ntohl(HI61(a)) > ntohl(HI61(b)) || \
 222 			   (HI61(a) == HI61(b) && \
 223 			    (ntohl(HI62(a)) > ntohl(HI62(b)) || \
 224 			     (HI62(a) == HI62(b) && \
 225 			      ntohl(HI63(a)) > ntohl(HI63(b))))))))
 226 #define	IP6_LT(a,b)	(ntohl(HI60(a)) < ntohl(HI60(b)) || \
 227 			 (HI60(a) == HI60(b) && \
 228 			  (ntohl(HI61(a)) < ntohl(HI61(b)) || \
 229 			   (HI61(a) == HI61(b) && \
 230 			    (ntohl(HI62(a)) < ntohl(HI62(b)) || \
 231 			     (HI62(a) == HI62(b) && \
 232 			      ntohl(HI63(a)) < ntohl(HI63(b))))))))
 233 #define	NLADD(n,x)	htonl(ntohl(n) + (x))
 234 #define	IP6_INC(a)	\
 235 		{ i6addr_t *_i6 = (i6addr_t *)(a); \
 236 		  _i6->i6[3] = NLADD(_i6->i6[3], 1); \
 237 		  if (_i6->i6[3] == 0) { \
 238 			_i6->i6[2] = NLADD(_i6->i6[2], 1); \
 239 			if (_i6->i6[2] == 0) { \
 240 				_i6->i6[1] = NLADD(_i6->i6[1], 1); \
 241 				if (_i6->i6[1] == 0) { \
 242 					_i6->i6[0] = NLADD(_i6->i6[0], 1); \
 243 				} \
 244 			} \
 245 		  } \
 246 		}
 247 #define	IP6_ADD(a,x,d)	\
 248 		{ i6addr_t *_s = (i6addr_t *)(a); \
 249 		  i6addr_t *_d = (i6addr_t *)(d); \
 250 		  _d->i6[3] = NLADD(_s->i6[3], x); \
 251 		  if (ntohl(_d->i6[3]) < ntohl(_s->i6[3])) { \
 252 			_d->i6[2] = NLADD(_d->i6[2], 1); \
 253 			if (ntohl(_d->i6[2]) < ntohl(_s->i6[2])) { \
 254 				_d->i6[1] = NLADD(_d->i6[1], 1); \
 255 				if (ntohl(_d->i6[1]) < ntohl(_s->i6[1])) { \
 256 					_d->i6[0] = NLADD(_d->i6[0], 1); \
 257 				} \
 258 			} \
 259 		  } \
 260 		}
 261 #define	IP6_AND(a,b,d)	{ i6addr_t *_s1 = (i6addr_t *)(a); \
 262 			  i6addr_t *_s2 = (i6addr_t *)(b); \
 263 			  i6addr_t *_d = (i6addr_t *)(d); \
 264 			  _d->i6[0] = _s1->i6[0] & _s2->i6[0]; \
 265 			  _d->i6[1] = _s1->i6[1] & _s2->i6[1]; \
 266 			  _d->i6[2] = _s1->i6[2] & _s2->i6[2]; \
 267 			  _d->i6[3] = _s1->i6[3] & _s2->i6[3]; \
 268 			}
 269 #define	IP6_MASKEQ(a,m,b) \
 270 			(((I60(a) & I60(m)) == I60(b)) && \
 271 			 ((I61(a) & I61(m)) == I61(b)) && \
 272 			 ((I62(a) & I62(m)) == I62(b)) && \
 273 			 ((I63(a) & I63(m)) == I63(b)))
 274 #define	IP6_MASKNEQ(a,m,b) \
 275 			(((I60(a) & I60(m)) != I60(b)) || \
 276 			 ((I61(a) & I61(m)) != I61(b)) || \
 277 			 ((I62(a) & I62(m)) != I62(b)) || \
 278 			 ((I63(a) & I63(m)) != I63(b)))
 279 #define	IP6_MERGE(a,b,c) \
 280 			{ i6addr_t *_d, *_s1, *_s2; \
 281 			  _d = (i6addr_t *)(a); \
 282 			  _s1 = (i6addr_t *)(b); \
 283 			  _s2 = (i6addr_t *)(c); \
 284 			  _d->i6[0] |= _s1->i6[0] & ~_s2->i6[0]; \
 285 			  _d->i6[1] |= _s1->i6[1] & ~_s2->i6[1]; \
 286 			  _d->i6[2] |= _s1->i6[2] & ~_s2->i6[2]; \
 287 			  _d->i6[3] |= _s1->i6[3] & ~_s2->i6[3]; \
 288 			}
 289 
 290 
 291 typedef	struct	fr_ip	{
 292 	u_32_t	fi_v:4;		/* IP version */
 293 	u_32_t	fi_xx:4;	/* spare */
 294 	u_32_t	fi_tos:8;	/* IP packet TOS */
 295 	u_32_t	fi_ttl:8;	/* IP packet TTL */
 296 	u_32_t	fi_p:8;		/* IP packet protocol */
 297 	u_32_t	fi_optmsk;	/* bitmask composed from IP options */
 298 	i6addr_t fi_src;	/* source address from packet */
 299 	i6addr_t fi_dst;	/* destination address from packet */
 300 	u_short	fi_secmsk;	/* bitmask composed from IP security options */
 301 	u_short	fi_auth;	/* authentication code from IP sec. options */
 302 	u_32_t	fi_flx;		/* packet flags */
 303 	u_32_t	fi_tcpmsk;	/* TCP options set/reset */
 304 	u_32_t	fi_res1;	/* RESERVED */
 305 } fr_ip_t;
 306 
 307 /*
 308  * For use in fi_flx
 309  */
 310 
 311 #define	FI_TCPUDP	0x0001	/* TCP/UCP implied comparison*/
 312 #define	FI_OPTIONS	0x0002
 313 #define	FI_FRAG		0x0004
 314 #define	FI_SHORT	0x0008
 315 #define	FI_NATED	0x0010
 316 #define	FI_MULTICAST	0x0020
 317 #define	FI_BROADCAST	0x0040
 318 #define	FI_MBCAST	0x0080
 319 #define	FI_STATE	0x0100
 320 #define	FI_BADNAT	0x0200
 321 #define	FI_BAD		0x0400
 322 #define	FI_OOW		0x0800	/* Out of state window, else match */
 323 #define	FI_ICMPERR	0x1000
 324 #define	FI_FRAGBODY	0x2000
 325 #define	FI_BADSRC	0x4000
 326 #define	FI_LOWTTL	0x8000
 327 #define	FI_CMP		0xcf03	/* Not FI_FRAG,FI_NATED,FI_FRAGTAIL,broadcast */
 328 #define	FI_ICMPCMP	0x0003	/* Flags we can check for ICMP error packets */
 329 #define	FI_WITH		0xeffe	/* Not FI_TCPUDP */
 330 #define	FI_V6EXTHDR	0x10000
 331 #define	FI_COALESCE	0x20000
 332 #define	FI_ICMPQUERY	0x40000
 333 #define	FI_NEWNAT	0x80000
 334 #define	FI_MOREFRAG	0x100000
 335 #define	FI_NEG_OOW	0x10000000	/* packet underflows TCP window */
 336 #define	FI_NOCKSUM	0x20000000	/* don't do a L4 checksum validation */
 337 #define	FI_DONTCACHE	0x40000000	/* don't cache the result */
 338 #define	FI_IGNORE	0x80000000
 339 
 340 #define	fi_saddr	fi_src.in4.s_addr
 341 #define	fi_daddr	fi_dst.in4.s_addr
 342 #define	fi_srcnum	fi_src.iplookupnum
 343 #define	fi_dstnum	fi_dst.iplookupnum
 344 #define	fi_srctype	fi_src.iplookuptype
 345 #define	fi_dsttype	fi_dst.iplookuptype
 346 #define	fi_srcptr	fi_src.iplookupptr
 347 #define	fi_dstptr	fi_dst.iplookupptr
 348 #define	fi_srcfunc	fi_src.iplookupfunc
 349 #define	fi_dstfunc	fi_dst.iplookupfunc
 350 
 351 
 352 /*
 353  * These are both used by the state and NAT code to indicate that one port or
 354  * the other should be treated as a wildcard.
 355  * NOTE: When updating, check bit masks in ip_state.h and update there too.
 356  */
 357 #define	SI_W_SPORT	0x00000100
 358 #define	SI_W_DPORT	0x00000200
 359 #define	SI_WILDP	(SI_W_SPORT|SI_W_DPORT)
 360 #define	SI_W_SADDR	0x00000400
 361 #define	SI_W_DADDR	0x00000800
 362 #define	SI_WILDA	(SI_W_SADDR|SI_W_DADDR)
 363 #define	SI_NEWFR	0x00001000
 364 #define	SI_CLONE	0x00002000
 365 #define	SI_CLONED	0x00004000
 366 
 367 
 368 
 369 
 370 struct	fr_info	{
 371 	void	*fin_ifp;		/* interface packet is `on' */
 372 	fr_ip_t	fin_fi;		/* IP Packet summary */
 373 	union	{
 374 		u_short	fid_16[2];	/* TCP/UDP ports, ICMP code/type */
 375 		u_32_t	fid_32;
 376 	} fin_dat;
 377 	int	fin_out;		/* in or out ? 1 == out, 0 == in */
 378 	int	fin_rev;		/* state only: 1 = reverse */
 379 	u_short	fin_hlen;		/* length of IP header in bytes */
 380 	u_char	fin_tcpf;		/* TCP header flags (SYN, ACK, etc) */
 381 	u_char	fin_icode;		/* ICMP error to return */
 382 	u_32_t	fin_rule;		/* rule # last matched */
 383 	char	fin_group[FR_GROUPLEN];	/* group number, -1 for none */
 384 	struct	frentry *fin_fr;	/* last matching rule */
 385 	void	*fin_dp;		/* start of data past IP header */
 386 	int	fin_dlen;		/* length of data portion of packet */
 387 	int	fin_plen;
 388 	int	fin_ipoff;		/* # bytes from buffer start to hdr */
 389 	u_32_t	fin_id;			/* IP packet id field */
 390 	u_short	fin_off;
 391 	int	fin_depth;		/* Group nesting depth */
 392 	int	fin_error;		/* Error code to return */
 393 	u_int	fin_pktnum;
 394 	void	*fin_nattag;
 395 	union {
 396 		ip_t	*fip_ip;
 397 #ifdef	USE_INET6
 398 		ip6_t	*fip_ip6;
 399 #endif
 400 	} fin_ipu;
 401 	mb_t	**fin_mp;		/* pointer to pointer to mbuf */
 402 	mb_t	*fin_m;			/* pointer to mbuf */
 403 #ifdef	MENTAT
 404 	mb_t	*fin_qfm;		/* pointer to mblk where pkt starts */
 405 	void	*fin_qpi;
 406 	ipf_stack_t *fin_ifs;
 407 #endif
 408 #ifdef	__sgi
 409 	void	*fin_hbuf;
 410 #endif
 411 };
 412 
 413 #define	fin_ip		fin_ipu.fip_ip
 414 #define	fin_ip6		fin_ipu.fip_ip6
 415 #define	fin_v		fin_fi.fi_v
 416 #define	fin_p		fin_fi.fi_p
 417 #define	fin_flx		fin_fi.fi_flx
 418 #define	fin_optmsk	fin_fi.fi_optmsk
 419 #define	fin_secmsk	fin_fi.fi_secmsk
 420 #define	fin_auth	fin_fi.fi_auth
 421 #define	fin_src		fin_fi.fi_src.in4
 422 #define	fin_saddr	fin_fi.fi_saddr
 423 #define	fin_dst		fin_fi.fi_dst.in4
 424 #define	fin_daddr	fin_fi.fi_daddr
 425 #define	fin_data	fin_dat.fid_16
 426 #define	fin_sport	fin_dat.fid_16[0]
 427 #define	fin_dport	fin_dat.fid_16[1]
 428 #define	fin_ports	fin_dat.fid_32
 429 
 430 #ifdef	USE_INET6
 431 # define	fin_src6	fin_fi.fi_src
 432 # define	fin_dst6	fin_fi.fi_dst
 433 # define	fin_dstip6	fin_fi.fi_dst.in6
 434 # define	fin_srcip6	fin_fi.fi_src.in6
 435 #endif
 436 
 437 #define	IPF_IN	0
 438 #define	IPF_OUT	1
 439 
 440 typedef	struct frentry	*(*ipfunc_t) __P((fr_info_t *, u_32_t *));
 441 typedef	int		(*ipfuncinit_t) __P((struct frentry *,
 442 					     ipf_stack_t *));
 443 
 444 typedef	struct	ipfunc_resolve	{
 445 	char		ipfu_name[32];
 446 	ipfunc_t	ipfu_addr;
 447 	ipfuncinit_t	ipfu_init;
 448 } ipfunc_resolve_t;
 449 
 450 /*
 451  * Size for compares on fr_info structures
 452  */
 453 #define	FI_CSIZE	offsetof(fr_info_t, fin_icode)
 454 #define	FI_LCSIZE	offsetof(fr_info_t, fin_dp)
 455 
 456 /*
 457  * Size for copying cache fr_info structure
 458  */
 459 #define	FI_COPYSIZE	offsetof(fr_info_t, fin_dp)
 460 
 461 /*
 462  * Structure for holding IPFilter's tag information
 463  */
 464 #define	IPFTAG_LEN	16
 465 typedef	struct	{
 466 	union	{
 467 		u_32_t	iptu_num[4];
 468 		char	iptu_tag[IPFTAG_LEN];
 469 	} ipt_un;
 470 	int	ipt_not;
 471 } ipftag_t;
 472 
 473 #define	ipt_tag	ipt_un.iptu_tag
 474 #define	ipt_num	ipt_un.iptu_num
 475 
 476 
 477 /*
 478  * This structure is used to hold information about the next hop for where
 479  * to forward a packet.
 480  */
 481 typedef	struct	frdest	{
 482 	void	*fd_ifp;
 483 	i6addr_t	fd_ip6;
 484 	char	fd_ifname[LIFNAMSIZ];
 485 } frdest_t;
 486 
 487 #define	fd_ip	fd_ip6.in4
 488 
 489 
 490 /*
 491  * This structure holds information about a port comparison.
 492  */
 493 typedef	struct	frpcmp	{
 494 	int	frp_cmp;	/* data for port comparisons */
 495 	u_short	frp_port;	/* top port for <> and >< */
 496 	u_short	frp_top;	/* top port for <> and >< */
 497 } frpcmp_t;
 498 
 499 #define FR_NONE 0
 500 #define FR_EQUAL 1
 501 #define FR_NEQUAL 2
 502 #define FR_LESST 3
 503 #define FR_GREATERT 4
 504 #define FR_LESSTE 5
 505 #define FR_GREATERTE 6
 506 #define FR_OUTRANGE 7
 507 #define FR_INRANGE 8
 508 #define FR_INCRANGE 9
 509 
 510 /*
 511  * Structure containing all the relevant TCP things that can be checked in
 512  * a filter rule.
 513  */
 514 typedef	struct	frtuc	{
 515 	u_char		ftu_tcpfm;	/* tcp flags mask */
 516 	u_char		ftu_tcpf;	/* tcp flags */
 517 	frpcmp_t	ftu_src;
 518 	frpcmp_t	ftu_dst;
 519 } frtuc_t;
 520 
 521 #define	ftu_scmp	ftu_src.frp_cmp
 522 #define	ftu_dcmp	ftu_dst.frp_cmp
 523 #define	ftu_sport	ftu_src.frp_port
 524 #define	ftu_dport	ftu_dst.frp_port
 525 #define	ftu_stop	ftu_src.frp_top
 526 #define	ftu_dtop	ftu_dst.frp_top
 527 
 528 #define	FR_TCPFMAX	0x3f
 529 
 530 /*
 531  * This structure makes up what is considered to be the IPFilter specific
 532  * matching components of a filter rule, as opposed to the data structures
 533  * used to define the result which are in frentry_t and not here.
 534  */
 535 typedef	struct	fripf	{
 536 	fr_ip_t	fri_ip;
 537 	fr_ip_t	fri_mip;	/* mask structure */
 538 
 539 	u_short	fri_icmpm;		/* data for ICMP packets (mask) */
 540 	u_short	fri_icmp;
 541 
 542 	frtuc_t	fri_tuc;
 543 	int	fri_satype;		/* addres type */
 544 	int	fri_datype;		/* addres type */
 545 	int	fri_sifpidx;		/* doing dynamic addressing */
 546 	int	fri_difpidx;		/* index into fr_ifps[] to use when */
 547 } fripf_t;
 548 
 549 #define	fri_dstnum	fri_ip.fi_dstnum
 550 #define	fri_srcnum	fri_mip.fi_srcnum
 551 #define	fri_dstptr	fri_ip.fi_dstptr
 552 #define	fri_srcptr	fri_mip.fi_srcptr
 553 
 554 #define	FRI_NORMAL	0	/* Normal address */
 555 #define	FRI_DYNAMIC	1	/* dynamic address */
 556 #define	FRI_LOOKUP	2	/* address is a pool # */
 557 #define	FRI_RANGE	3	/* address/mask is a range */
 558 #define	FRI_NETWORK	4	/* network address from if */
 559 #define	FRI_BROADCAST	5	/* broadcast address from if */
 560 #define	FRI_PEERADDR	6	/* Peer address for P-to-P */
 561 #define	FRI_NETMASKED	7	/* network address with netmask from if */
 562 
 563 
 564 typedef	struct	frentry	* (* frentfunc_t) __P((fr_info_t *));
 565 
 566 typedef	struct	frentry {
 567 	ipfmutex_t	fr_lock;
 568 	struct	frentry	*fr_next;
 569 	struct	frentry	**fr_grp;
 570 	struct	ipscan	*fr_isc;
 571 	void	*fr_ifas[4];
 572 	void	*fr_ptr;	/* for use with fr_arg */
 573 	char	*fr_comment;	/* text comment for rule */
 574 	int	fr_ref;		/* reference count - for grouping */
 575 	int	fr_statecnt;	/* state count - for limit rules */
 576 	/*
 577 	 * These are only incremented when a packet  matches this rule and
 578 	 * it is the last match
 579 	 */
 580 	U_QUAD_T	fr_hits;
 581 	U_QUAD_T	fr_bytes;
 582 
 583 	/*
 584 	 * For PPS rate limiting
 585 	 */
 586 	struct timeval	fr_lastpkt;
 587 	int		fr_curpps;
 588 
 589 	union	{
 590 		void		*fru_data;
 591 		caddr_t		fru_caddr;
 592 		fripf_t		*fru_ipf;
 593 		frentfunc_t	fru_func;
 594 	} fr_dun;
 595 
 596 	/*
 597 	 * Fields after this may not change whilst in the kernel.
 598 	 */
 599 	ipfunc_t fr_func; 	/* call this function */
 600 	int	fr_dsize;
 601 	int	fr_pps;
 602 	int	fr_statemax;	/* max reference count */
 603 	int	fr_flineno;	/* line number from conf file */
 604 	u_32_t	fr_type;
 605 	u_32_t	fr_flags;	/* per-rule flags && options (see below) */
 606 	u_32_t	fr_logtag;	/* user defined log tag # */
 607 	u_32_t	fr_collect;	/* collection number */
 608 	u_int	fr_arg;		/* misc. numeric arg for rule */ 
 609 	u_int	fr_loglevel;	/* syslog log facility + priority */
 610 	u_int	fr_age[2];	/* non-TCP timeouts */
 611 	u_char	fr_v;
 612 	u_char	fr_icode;	/* return ICMP code */
 613 	char	fr_group[FR_GROUPLEN];	/* group to which this rule belongs */
 614 	char	fr_grhead[FR_GROUPLEN];	/* group # which this rule starts */
 615 	ipftag_t fr_nattag;
 616 	char	fr_ifnames[4][LIFNAMSIZ];
 617 	char	fr_isctag[16];
 618 	frdest_t fr_tifs[2];	/* "to"/"reply-to" interface */
 619 	frdest_t fr_dif;	/* duplicate packet interface */
 620 	/*
 621 	 * This must be last and will change after loaded into the kernel.
 622 	 */
 623 	u_int	fr_cksum;	/* checksum on filter rules for performance */
 624 } frentry_t;
 625 
 626 #define	fr_caddr	fr_dun.fru_caddr
 627 #define	fr_data		fr_dun.fru_data
 628 #define	fr_dfunc	fr_dun.fru_func
 629 #define	fr_ipf		fr_dun.fru_ipf
 630 #define	fr_ip		fr_ipf->fri_ip
 631 #define	fr_mip		fr_ipf->fri_mip
 632 #define	fr_icmpm	fr_ipf->fri_icmpm
 633 #define	fr_icmp		fr_ipf->fri_icmp
 634 #define	fr_tuc		fr_ipf->fri_tuc
 635 #define	fr_satype	fr_ipf->fri_satype
 636 #define	fr_datype	fr_ipf->fri_datype
 637 #define	fr_sifpidx	fr_ipf->fri_sifpidx
 638 #define	fr_difpidx	fr_ipf->fri_difpidx
 639 #define	fr_proto	fr_ip.fi_p
 640 #define	fr_mproto	fr_mip.fi_p
 641 #define	fr_ttl		fr_ip.fi_ttl
 642 #define	fr_mttl		fr_mip.fi_ttl
 643 #define	fr_tos		fr_ip.fi_tos
 644 #define	fr_mtos		fr_mip.fi_tos
 645 #define	fr_tcpfm	fr_tuc.ftu_tcpfm
 646 #define	fr_tcpf		fr_tuc.ftu_tcpf
 647 #define	fr_scmp		fr_tuc.ftu_scmp
 648 #define	fr_dcmp		fr_tuc.ftu_dcmp
 649 #define	fr_dport	fr_tuc.ftu_dport
 650 #define	fr_sport	fr_tuc.ftu_sport
 651 #define	fr_stop		fr_tuc.ftu_stop
 652 #define	fr_dtop		fr_tuc.ftu_dtop
 653 #define	fr_dst		fr_ip.fi_dst.in4
 654 #define	fr_daddr	fr_ip.fi_dst.in4.s_addr
 655 #define	fr_src		fr_ip.fi_src.in4
 656 #define	fr_saddr	fr_ip.fi_src.in4.s_addr
 657 #define	fr_dmsk		fr_mip.fi_dst.in4
 658 #define	fr_dmask	fr_mip.fi_dst.in4.s_addr
 659 #define	fr_smsk		fr_mip.fi_src.in4
 660 #define	fr_smask	fr_mip.fi_src.in4.s_addr
 661 #define	fr_dstnum	fr_ip.fi_dstnum
 662 #define	fr_srcnum	fr_ip.fi_srcnum
 663 #define	fr_dsttype	fr_ip.fi_dsttype
 664 #define	fr_srctype	fr_ip.fi_srctype
 665 #define	fr_dstptr	fr_mip.fi_dstptr
 666 #define	fr_srcptr	fr_mip.fi_srcptr
 667 #define	fr_dstfunc	fr_mip.fi_dstfunc
 668 #define	fr_srcfunc	fr_mip.fi_srcfunc
 669 #define	fr_optbits	fr_ip.fi_optmsk
 670 #define	fr_optmask	fr_mip.fi_optmsk
 671 #define	fr_secbits	fr_ip.fi_secmsk
 672 #define	fr_secmask	fr_mip.fi_secmsk
 673 #define	fr_authbits	fr_ip.fi_auth
 674 #define	fr_authmask	fr_mip.fi_auth
 675 #define	fr_flx		fr_ip.fi_flx
 676 #define	fr_mflx		fr_mip.fi_flx
 677 #define	fr_ifname	fr_ifnames[0]
 678 #define	fr_oifname	fr_ifnames[2]
 679 #define	fr_ifa		fr_ifas[0]
 680 #define	fr_oifa		fr_ifas[2]
 681 #define	fr_tif		fr_tifs[0]
 682 #define	fr_rif		fr_tifs[1]
 683 
 684 #define	FR_NOLOGTAG	0
 685 
 686 #ifndef	offsetof
 687 #define	offsetof(t,m)	(int)((&((t *)0L)->m))
 688 #endif
 689 #define	FR_CMPSIZ	(sizeof(struct frentry) - \
 690 			 offsetof(struct frentry, fr_func))
 691 
 692 /*
 693  * fr_type
 694  */
 695 #define	FR_T_NONE	0
 696 #define	FR_T_IPF	1	/* IPF structures */
 697 #define	FR_T_BPFOPC	2	/* BPF opcode */
 698 #define	FR_T_CALLFUNC	3	/* callout to function in fr_func only */
 699 #define	FR_T_COMPIPF	4	/* compiled C code */
 700 #define	FR_T_BUILTIN	0x80000000	/* rule is in kernel space */
 701 
 702 /*
 703  * fr_flags
 704  */
 705 #define	FR_CALL		0x00000	/* call rule */
 706 #define	FR_BLOCK	0x00001	/* do not allow packet to pass */
 707 #define	FR_PASS		0x00002	/* allow packet to pass */
 708 #define	FR_AUTH		0x00003	/* use authentication */
 709 #define	FR_ACCOUNT	0x00005	/* Accounting rule */
 710 #define	FR_SKIP		0x00006	/* skip rule */
 711 #define	FR_DIVERT	0x00007	/* divert rule */
 712 #define	FR_CMDMASK	0x0000f
 713 #define	FR_LOG		0x00010	/* Log */
 714 #define	FR_LOGB		0x00011	/* Log-fail */
 715 #define	FR_LOGP		0x00012	/* Log-pass */
 716 #define	FR_LOGMASK	(FR_LOG|FR_CMDMASK)
 717 #define	FR_CALLNOW	0x00020	/* call another function (fr_func) if matches */
 718 #define	FR_NOTSRCIP	0x00040
 719 #define	FR_NOTDSTIP	0x00080
 720 #define	FR_QUICK	0x00100	/* match & stop processing list */
 721 #define	FR_KEEPFRAG	0x00200	/* keep fragment information */
 722 #define	FR_KEEPSTATE	0x00400	/* keep `connection' state information */
 723 #define	FR_FASTROUTE	0x00800	/* bypass normal routing */
 724 #define	FR_RETRST	0x01000	/* Return TCP RST packet - reset connection */
 725 #define	FR_RETICMP	0x02000	/* Return ICMP unreachable packet */
 726 #define	FR_FAKEICMP	0x03000	/* Return ICMP unreachable with fake source */
 727 #define	FR_OUTQUE	0x04000	/* outgoing packets */
 728 #define	FR_INQUE	0x08000	/* ingoing packets */
 729 #define	FR_LOGBODY	0x10000	/* Log the body */
 730 #define	FR_LOGFIRST	0x20000	/* Log the first byte if state held */
 731 #define	FR_LOGORBLOCK	0x40000	/* block the packet if it can't be logged */
 732 #define	FR_DUP		0x80000	/* duplicate packet */
 733 #define	FR_FRSTRICT	0x100000	/* strict frag. cache */
 734 #define	FR_STSTRICT	0x200000	/* strict keep state */
 735 #define	FR_NEWISN	0x400000	/* new ISN for outgoing TCP */
 736 #define	FR_NOICMPERR	0x800000	/* do not match ICMP errors in state */
 737 #define	FR_STATESYNC	0x1000000	/* synchronize state to slave */
 738 #define	FR_NOMATCH	0x8000000	/* no match occured */
 739 		/*	0x10000000 	FF_LOGPASS */
 740 		/*	0x20000000 	FF_LOGBLOCK */
 741 		/*	0x40000000 	FF_LOGNOMATCH */
 742 		/*	0x80000000 	FF_BLOCKNONIP */
 743 #define	FR_COPIED	0x40000000	/* copied from user space */
 744 #define	FR_INACTIVE	0x80000000	/* only used when flush'ing rules */
 745 
 746 #define	FR_RETMASK	(FR_RETICMP|FR_RETRST|FR_FAKEICMP)
 747 #define	FR_ISBLOCK(x)	(((x) & FR_CMDMASK) == FR_BLOCK)
 748 #define	FR_ISPASS(x)	(((x) & FR_CMDMASK) == FR_PASS)
 749 #define	FR_ISAUTH(x)	(((x) & FR_CMDMASK) == FR_AUTH)
 750 #define	FR_ISACCOUNT(x)	(((x) & FR_CMDMASK) == FR_ACCOUNT)
 751 #define	FR_ISSKIP(x)	(((x) & FR_CMDMASK) == FR_SKIP)
 752 #define	FR_ISNOMATCH(x)	((x) & FR_NOMATCH)
 753 #define	FR_INOUT	(FR_INQUE|FR_OUTQUE)
 754 
 755 /*
 756  * recognized flags for SIOCGETFF and SIOCSETFF, and get put in fr_flags
 757  */
 758 #define	FF_LOGPASS	0x10000000
 759 #define	FF_LOGBLOCK	0x20000000
 760 #define	FF_LOGNOMATCH	0x40000000
 761 #define	FF_LOGGING	(FF_LOGPASS|FF_LOGBLOCK|FF_LOGNOMATCH)
 762 #define	FF_BLOCKNONIP	0x80000000	/* Solaris2 Only */
 763 
 764 
 765 /*
 766  * Structure that passes information on what/how to flush to the kernel.
 767  */
 768 typedef	struct	ipfflush	{
 769 	int	ipflu_how;
 770 	int	ipflu_arg;
 771 } ipfflush_t;
 772 
 773 
 774 /*
 775  *
 776  */
 777 typedef	struct	ipfgetctl	{
 778 	u_int	ipfg_min;	/* min value */
 779 	u_int	ipfg_current;	/* current value */
 780 	u_int	ipfg_max;	/* max value */
 781 	u_int	ipfg_default;	/* default value */
 782 	u_int	ipfg_steps;	/* value increments */
 783 	char	ipfg_name[40];	/* tag name for this control */
 784 } ipfgetctl_t;
 785 
 786 typedef	struct	ipfsetctl	{
 787 	int	ipfs_which;	/* 0 = min 1 = current 2 = max 3 = default */
 788 	u_int	ipfs_value;	/* min value */
 789 	char	ipfs_name[40];	/* tag name for this control */
 790 } ipfsetctl_t;
 791 
 792 
 793 /*
 794  * Some of the statistics below are in their own counters, but most are kept
 795  * in this single structure so that they can all easily be collected and
 796  * copied back as required.
 797  *
 798  * NOTE: when changing, keep in sync with kstats (below).
 799  */
 800 typedef	struct	filterstats {
 801 	u_long	fr_pass;	/* packets allowed */
 802 	u_long	fr_block;	/* packets denied */
 803 	u_long	fr_nom;		/* packets which don't match any rule */
 804 	u_long	fr_short;	/* packets which are short */
 805 	u_long	fr_ppkl;	/* packets allowed and logged */
 806 	u_long	fr_bpkl;	/* packets denied and logged */
 807 	u_long	fr_npkl;	/* packets unmatched and logged */
 808 	u_long	fr_pkl;		/* packets logged */
 809 	u_long	fr_skip;	/* packets to be logged but buffer full */
 810 	u_long	fr_ret;		/* packets for which a return is sent */
 811 	u_long	fr_acct;	/* packets for which counting was performed */
 812 	u_long	fr_bnfr;	/* bad attempts to allocate fragment state */
 813 	u_long	fr_nfr;		/* new fragment state kept */
 814 	u_long	fr_cfr;		/* add new fragment state but complete pkt */
 815 	u_long	fr_bads;	/* bad attempts to allocate packet state */
 816 	u_long	fr_ads;		/* new packet state kept */
 817 	u_long	fr_chit;	/* cached hit */
 818 	u_long	fr_tcpbad;	/* TCP checksum check failures */
 819 	u_long	fr_pull[2];	/* good and bad pullup attempts */
 820 	u_long	fr_badsrc;	/* source received doesn't match route */
 821 	u_long	fr_badttl;	/* TTL in packet doesn't reach minimum */
 822 	u_long	fr_bad;		/* bad IP packets to the filter */
 823 	u_long	fr_ipv6;	/* IPv6 packets in/out */
 824 	u_long	fr_ppshit;	/* dropped because of pps ceiling */
 825 	u_long	fr_ipud;	/* IP id update failures */
 826 } filterstats_t;
 827 
 828 /*
 829  * kstat "copy" of the above - keep in sync!
 830  * also keep in sync with initialisation code in solaris.c, ipf_kstat_init().
 831  */
 832 typedef struct  filter_kstats {
 833 	kstat_named_t   fks_pass;	/* see above for comments */
 834 	kstat_named_t   fks_block;
 835 	kstat_named_t   fks_nom;
 836 	kstat_named_t   fks_short;
 837 	kstat_named_t   fks_ppkl;
 838 	kstat_named_t   fks_bpkl;
 839 	kstat_named_t   fks_npkl;
 840 	kstat_named_t   fks_pkl;
 841 	kstat_named_t   fks_skip;
 842 	kstat_named_t   fks_ret;
 843 	kstat_named_t   fks_acct;
 844 	kstat_named_t   fks_bnfr;
 845 	kstat_named_t   fks_nfr;
 846 	kstat_named_t   fks_cfr;
 847 	kstat_named_t   fks_bads;
 848 	kstat_named_t   fks_ads;
 849 	kstat_named_t   fks_chit;
 850 	kstat_named_t   fks_tcpbad;
 851 	kstat_named_t   fks_pull[2];
 852 	kstat_named_t   fks_badsrc;
 853 	kstat_named_t   fks_badttl;
 854 	kstat_named_t   fks_bad;
 855 	kstat_named_t   fks_ipv6;
 856 	kstat_named_t   fks_ppshit;
 857 	kstat_named_t   fks_ipud;
 858 } filter_kstats_t;
 859 
 860 /*
 861  * Log structure.  Each packet header logged is prepended by one of these.
 862  * Following this in the log records read from the device will be an ipflog
 863  * structure which is then followed by any packet data.
 864  */
 865 typedef	struct	iplog	{
 866 	u_32_t		ipl_magic;
 867 	u_int		ipl_count;
 868 	struct	timeval	ipl_time;
 869 	size_t		ipl_dsize;
 870 	struct	iplog	*ipl_next;
 871 } iplog_t;
 872 
 873 #define	ipl_sec		ipl_time.tv_sec
 874 #define	ipl_usec	ipl_time.tv_usec
 875 
 876 #define IPL_MAGIC	0x49504c4d	/* 'IPLM' */
 877 #define IPL_MAGIC_NAT	0x49504c4e	/* 'IPLN' */
 878 #define IPL_MAGIC_STATE	0x49504c53	/* 'IPLS' */
 879 #define	IPLOG_SIZE	sizeof(iplog_t)
 880 
 881 typedef	struct	ipflog	{
 882 #if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199603)) || \
 883         (defined(OpenBSD) && (OpenBSD >= 199603))
 884 #else
 885 	u_int	fl_unit;
 886 #endif
 887 	u_32_t	fl_rule;
 888 	u_32_t	fl_flags;
 889 	u_32_t	fl_lflags;
 890 	u_32_t	fl_logtag;
 891 	ipftag_t	fl_nattag;
 892 	u_short	fl_plen;	/* extra data after hlen */
 893 	u_short	fl_loglevel;	/* syslog log level */
 894 	char	fl_group[FR_GROUPLEN];
 895 	u_char	fl_hlen;	/* length of IP headers saved */
 896 	u_char	fl_dir;
 897 	u_char	fl_xxx[2];	/* pad */
 898 	char	fl_ifname[LIFNAMSIZ];
 899 } ipflog_t;
 900 
 901 #ifndef	IPF_LOGGING
 902 # define	IPF_LOGGING	0
 903 #endif
 904 #ifndef	IPF_DEFAULT_PASS
 905 # define	IPF_DEFAULT_PASS	FR_PASS
 906 #endif
 907 
 908 #define	DEFAULT_IPFLOGSIZE	8192
 909 #ifndef	IPFILTER_LOGSIZE
 910 # define	IPFILTER_LOGSIZE	DEFAULT_IPFLOGSIZE
 911 #else
 912 # if IPFILTER_LOGSIZE < DEFAULT_IPFLOGSIZE
 913 #  error IPFILTER_LOGSIZE too small.  Must be >= DEFAULT_IPFLOGSIZE
 914 # endif
 915 #endif
 916 
 917 #define	IPF_OPTCOPY	0x07ff00	/* bit mask of copied options */
 918 
 919 /*
 920  * Device filenames for reading log information.  Use ipf on Solaris2 because
 921  * ipl is already a name used by something else.
 922  */
 923 #ifndef	IPL_NAME
 924 # if	SOLARIS
 925 #  define	IPL_NAME	"/dev/ipf"
 926 # else
 927 #  define	IPL_NAME	"/dev/ipl"
 928 # endif
 929 #endif
 930 /*
 931  * Pathnames for various IP Filter control devices.  Used by LKM
 932  * and userland, so defined here.
 933  */
 934 #define	IPNAT_NAME	"/dev/ipnat"
 935 #define	IPSTATE_NAME	"/dev/ipstate"
 936 #define	IPAUTH_NAME	"/dev/ipauth"
 937 #define	IPSYNC_NAME	"/dev/ipsync"
 938 #define	IPSCAN_NAME	"/dev/ipscan"
 939 #define	IPLOOKUP_NAME	"/dev/iplookup"
 940 
 941 #define	IPL_LOGIPF	0	/* Minor device #'s for accessing logs */
 942 #define	IPL_LOGNAT	1
 943 #define	IPL_LOGSTATE	2
 944 #define	IPL_LOGAUTH	3
 945 #define	IPL_LOGSYNC	4
 946 #define	IPL_LOGSCAN	5
 947 #define	IPL_LOGLOOKUP	6
 948 #define	IPL_LOGCOUNT	7
 949 #define	IPL_LOGMAX	7
 950 #define	IPL_LOGSIZE	(IPL_LOGMAX + 1)
 951 #define	IPL_LOGALL	-1
 952 #define	IPL_LOGNONE	-2
 953 
 954 /*
 955  * For SIOCGETFS
 956  */
 957 typedef	struct	friostat	{
 958 	struct	filterstats	f_st[2];
 959 	struct	frentry		*f_ipf[2][2];
 960 	struct	frentry		*f_acct[2][2];
 961 	struct	frentry		*f_ipf6[2][2];
 962 	struct	frentry		*f_acct6[2][2];
 963 	struct	frentry		*f_auth;
 964 	struct	frgroup		*f_groups[IPL_LOGSIZE][2];
 965 	u_long	f_froute[2];
 966 	u_long	f_ticks;
 967 	int	f_locks[IPL_LOGMAX];
 968 	size_t	f_kmutex_sz;
 969 	size_t	f_krwlock_sz;
 970 	int	f_defpass;	/* default pass - from fr_pass */
 971 	int	f_active;	/* 1 or 0 - active rule set */
 972 	int	f_running;	/* 1 if running, else 0 */
 973 	int	f_logging;	/* 1 if enabled, else 0 */
 974 	int	f_features;
 975 	char	f_version[32];	/* version string */
 976 } friostat_t;
 977 
 978 #define	f_fin		f_ipf[0]
 979 #define	f_fin6		f_ipf6[0]
 980 #define	f_fout		f_ipf[1]
 981 #define	f_fout6		f_ipf6[1]
 982 #define	f_acctin	f_acct[0]
 983 #define	f_acctin6	f_acct6[0]
 984 #define	f_acctout	f_acct[1]
 985 #define	f_acctout6	f_acct6[1]
 986 
 987 #define	IPF_FEAT_LKM		0x001
 988 #define	IPF_FEAT_LOG		0x002
 989 #define	IPF_FEAT_LOOKUP		0x004
 990 #define	IPF_FEAT_BPF		0x008
 991 #define	IPF_FEAT_COMPILED	0x010
 992 #define	IPF_FEAT_CKSUM		0x020
 993 #define	IPF_FEAT_SYNC		0x040
 994 #define	IPF_FEAT_SCAN		0x080
 995 #define	IPF_FEAT_IPV6		0x100
 996 
 997 typedef struct	optlist {
 998 	u_short ol_val;
 999 	int	ol_bit;
1000 } optlist_t;
1001 
1002 
1003 /*
1004  * Group list structure.
1005  */
1006 typedef	struct frgroup {
1007 	struct	frgroup	*fg_next;
1008 	struct	frentry	*fg_head;
1009 	struct	frentry	*fg_start;
1010 	u_32_t	fg_flags;
1011 	int	fg_ref;
1012 	char	fg_name[FR_GROUPLEN];
1013 } frgroup_t;
1014 
1015 #define	FG_NAME(g)	(*(g)->fg_name == '\0' ? "" : (g)->fg_name)
1016 
1017 
1018 /*
1019  * Used by state and NAT tables
1020  */
1021 typedef struct icmpinfo {
1022 	u_short	ici_id;
1023 	u_short	ici_seq;
1024 	u_char	ici_type;
1025 } icmpinfo_t;
1026 
1027 typedef struct udpinfo {
1028 	u_short	us_sport;
1029 	u_short	us_dport;
1030 } udpinfo_t;
1031 
1032 
1033 typedef	struct	tcpdata	{
1034 	u_32_t	td_end;
1035 	u_32_t	td_maxend;
1036 	u_32_t	td_maxwin;
1037 	u_32_t	td_winscale;
1038 	u_32_t	td_maxseg;
1039 	int	td_winflags;
1040 } tcpdata_t;
1041 
1042 #define	TCP_WSCALE_MAX		14
1043 
1044 #define	TCP_WSCALE_SEEN		0x00000001
1045 #define	TCP_WSCALE_FIRST	0x00000002
1046 #define	TCP_SACK_PERMIT		0x00000004
1047 
1048 
1049 typedef	struct tcpinfo {
1050 	u_short	ts_sport;
1051 	u_short	ts_dport;
1052 	tcpdata_t ts_data[2];
1053 } tcpinfo_t;
1054 
1055 
1056 /*
1057  * Structures to define a GRE header as seen in a packet.
1058  */
1059 struct	grebits	{
1060 	u_32_t	grb_C:1;
1061 	u_32_t	grb_R:1;
1062 	u_32_t	grb_K:1;
1063 	u_32_t	grb_S:1;
1064 	u_32_t	grb_s:1;
1065 	u_32_t	grb_recur:1;
1066 	u_32_t	grb_A:1;
1067 	u_32_t	grb_flags:3;
1068 	u_32_t	grb_ver:3;
1069 	u_short	grb_ptype;
1070 };
1071 
1072 typedef	struct	grehdr	{
1073 	union	{
1074 		struct	grebits	gru_bits;
1075 		u_short	gru_flags;
1076 	} gr_un;
1077 	u_short	gr_len;
1078 	u_short	gr_call;
1079 } grehdr_t;
1080 
1081 #define	gr_flags	gr_un.gru_flags
1082 #define	gr_bits		gr_un.gru_bits
1083 #define	gr_ptype	gr_bits.grb_ptype
1084 #define	gr_C		gr_bits.grb_C
1085 #define	gr_R		gr_bits.grb_R
1086 #define	gr_K		gr_bits.grb_K
1087 #define	gr_S		gr_bits.grb_S
1088 #define	gr_s		gr_bits.grb_s
1089 #define	gr_recur	gr_bits.grb_recur
1090 #define	gr_A		gr_bits.grb_A
1091 #define	gr_ver		gr_bits.grb_ver
1092 
1093 /*
1094  * GRE information tracked by "keep state"
1095  */
1096 typedef	struct	greinfo	{
1097 	u_short	gs_call[2];
1098 	u_short	gs_flags;
1099 	u_short	gs_ptype;
1100 } greinfo_t;
1101 
1102 #define	GRE_REV(x)	((ntohs(x) >> 13) & 7)
1103 
1104 
1105 /*
1106  * Format of an Authentication header
1107  */
1108 typedef	struct	authhdr	{
1109 	u_char	ah_next;
1110 	u_char	ah_plen;
1111 	u_short	ah_reserved;
1112 	u_32_t	ah_spi;
1113 	u_32_t	ah_seq;
1114 	/* Following the sequence number field is 0 or more bytes of */
1115 	/* authentication data, as specified by ah_plen - RFC 2402.  */
1116 } authhdr_t;
1117 
1118 
1119 /*
1120  * Timeout tail queue list member
1121  */
1122 typedef	struct	ipftqent	{
1123 	struct ipftqent **tqe_pnext;
1124 	struct ipftqent *tqe_next;
1125 	struct	ipftq	*tqe_ifq;
1126 	void	*tqe_parent;		/* pointer back to NAT/state struct */
1127 	u_long	tqe_die;		/* when this entriy is to die */
1128 	u_long	tqe_touched;
1129 	int	tqe_flags;
1130 	int	tqe_state[2];		/* current state of this entry */
1131 } ipftqent_t;
1132 
1133 #define	TQE_RULEBASED	0x00000001
1134 
1135 
1136 /*
1137  * Timeout tail queue head for IPFilter
1138  */
1139 typedef struct  ipftq   {
1140 	ipfmutex_t	ifq_lock;
1141 	u_int	ifq_ttl;
1142 	ipftqent_t	*ifq_head;
1143 	ipftqent_t	**ifq_tail;
1144 	struct	ipftq	*ifq_next;
1145 	struct	ipftq	**ifq_pnext;
1146 	int	ifq_ref;
1147 	u_int	ifq_flags;
1148 } ipftq_t;
1149 
1150 #define	IFQF_USER	0x01		/* User defined aging */
1151 #define	IFQF_DELETE	0x02		/* Marked for deletion */
1152 #define	IFQF_PROXY	0x04		/* Timeout queue in use by a proxy */
1153 
1154 #define	IPF_HZ_MULT	1
1155 #define	IPF_HZ_DIVIDE	2		/* How many times a second ipfilter */
1156 					/* checks its timeout queues.       */
1157 #define	IPF_TTLVAL(x)	(((x) / IPF_HZ_MULT) * IPF_HZ_DIVIDE)
1158 
1159 /*
1160  * Structure to define address for pool lookups.
1161  */
1162 typedef	struct	{
1163 	u_char		adf_len;
1164 	sa_family_t	adf_family;
1165 	i6addr_t	adf_addr;
1166 } addrfamily_t;
1167 
1168 
1169 /*
1170  * Object structure description.  For passing through in ioctls.
1171  */
1172 typedef	struct	ipfobj	{
1173 	u_32_t	ipfo_rev;		/* IPFilter version number */
1174 	u_32_t	ipfo_size;		/* size of object at ipfo_ptr */
1175 	void	*ipfo_ptr;		/* pointer to object */
1176 	int	ipfo_type;		/* type of object being pointed to */
1177 	int	ipfo_offset;		/* bytes from ipfo_ptr where to start */
1178 	u_char	ipfo_xxxpad[32];	/* reserved for future use */
1179 } ipfobj_t;
1180 
1181 #define	IPFOBJ_FRENTRY		0	/* struct frentry */
1182 #define	IPFOBJ_IPFSTAT		1	/* struct friostat */
1183 #define	IPFOBJ_IPFINFO		2	/* struct fr_info */
1184 #define	IPFOBJ_AUTHSTAT		3	/* struct fr_authstat */
1185 #define	IPFOBJ_FRAGSTAT		4	/* struct ipfrstat */
1186 #define	IPFOBJ_IPNAT		5	/* struct ipnat */
1187 #define	IPFOBJ_NATSTAT		6	/* struct natstat */
1188 #define	IPFOBJ_STATESAVE	7	/* struct ipstate_save */
1189 #define	IPFOBJ_NATSAVE		8	/* struct nat_save */
1190 #define	IPFOBJ_NATLOOKUP	9	/* struct natlookup */
1191 #define	IPFOBJ_IPSTATE		10	/* struct ipstate */
1192 #define	IPFOBJ_STATESTAT	11	/* struct ips_stat */
1193 #define	IPFOBJ_FRAUTH		12	/* struct frauth */
1194 #define	IPFOBJ_TUNEABLE		13	/* struct ipftune */
1195 #define	IPFOBJ_NAT		14	/* struct nat */
1196 #define	IPFOBJ_IPFITER		15	/* struct ipfruleiter */
1197 #define	IPFOBJ_GENITER		16	/* struct ipfgeniter */
1198 #define	IPFOBJ_GTABLE		17	/* struct ipftable */
1199 #define	IPFOBJ_LOOKUPITER	18	/* struct ipflookupiter */
1200 #define	IPFOBJ_STATETQTAB	19	/* struct ipftq [NSTATES] */
1201 #define	IPFOBJ_COUNT		20	/* How many #defines are above this? */
1202 
1203 
1204 typedef	union	ipftunevalptr	{
1205 	void	*ipftp_void;
1206 	u_long	*ipftp_long;
1207 	u_int	*ipftp_int;
1208 	u_short	*ipftp_short;
1209 	u_char	*ipftp_char;
1210 } ipftunevalptr_t;
1211 
1212 typedef	struct	ipftuneable	{
1213 	ipftunevalptr_t	ipft_una;
1214 	char		*ipft_name;
1215 	u_long		ipft_min;
1216 	u_long		ipft_max;
1217 	int		ipft_sz;
1218 	int		ipft_flags;
1219 	struct ipftuneable *ipft_next;
1220 } ipftuneable_t;
1221 
1222 #define	ipft_addr	ipft_una.ipftp_void
1223 #define	ipft_plong	ipft_una.ipftp_long
1224 #define	ipft_pint	ipft_una.ipftp_int
1225 #define	ipft_pshort	ipft_una.ipftp_short
1226 #define	ipft_pchar	ipft_una.ipftp_char
1227 
1228 #define	IPFT_RDONLY	1	/* read-only */
1229 #define	IPFT_WRDISABLED	2	/* write when disabled only */
1230 
1231 typedef	union	ipftuneval	{
1232 	u_long	ipftu_long;
1233 	u_int	ipftu_int;
1234 	u_short	ipftu_short;
1235 	u_char	ipftu_char;
1236 } ipftuneval_t;
1237 
1238 typedef	struct	ipftune	{
1239 	void    	*ipft_cookie;
1240 	ipftuneval_t	ipft_un;
1241 	u_long  	ipft_min;
1242 	u_long  	ipft_max;
1243 	int		ipft_sz;
1244 	int		ipft_flags;
1245 	char		ipft_name[80];
1246 } ipftune_t;
1247 
1248 #define	ipft_vlong	ipft_un.ipftu_long
1249 #define	ipft_vint	ipft_un.ipftu_int
1250 #define	ipft_vshort	ipft_un.ipftu_short
1251 #define	ipft_vchar	ipft_un.ipftu_char
1252 
1253 /*
1254  * ipfruleiter is iterator structure used for filter rules.
1255  */
1256 
1257 typedef	struct	ipfruleiter {
1258 	int		iri_ver;
1259 	int		iri_inout;
1260 	char		iri_group[FR_GROUPLEN];
1261 	int		iri_active;
1262 	int		iri_nrules;
1263 	frentry_t	*iri_rule;
1264 } ipfruleiter_t;
1265 
1266 /* Values for iri_inout  */
1267 #define	F_IN	0
1268 #define	F_OUT	1
1269 #define	F_ACIN	2
1270 #define	F_ACOUT	3
1271 
1272 /*
1273  * ipfgeniter is generic iterator structure used for nat rules,
1274  * hostmap entries and nat table entries.
1275  */
1276 typedef	struct	ipfgeniter {
1277 	int	igi_type;	/* type of data we're looking at */
1278 	int	igi_nitems;
1279 	void	*igi_data;
1280 } ipfgeniter_t;
1281 
1282 #define	IPFGENITER_IPF		0
1283 #define	IPFGENITER_NAT		1
1284 #define	IPFGENITER_IPNAT	2
1285 #define	IPFGENITER_FRAG		3
1286 #define	IPFGENITER_AUTH		4
1287 #define	IPFGENITER_STATE	5
1288 #define	IPFGENITER_NATFRAG	6
1289 #define	IPFGENITER_HOSTMAP	7
1290 #define	IPFGENITER_LOOKUP	8
1291 
1292 typedef struct  ipftable {
1293         int     ita_type;
1294         void    *ita_table;
1295 } ipftable_t;
1296 
1297 #define	IPFTABLE_BUCKETS	1
1298 #define	IPFTABLE_BUCKETS_NATIN	2
1299 #define	IPFTABLE_BUCKETS_NATOUT	3
1300 
1301 typedef struct ipftoken {
1302         struct ipftoken *ipt_next;
1303         struct ipftoken **ipt_pnext;
1304         void            *ipt_ctx;
1305         void            *ipt_data;
1306         u_long          ipt_die;
1307         int             ipt_type;
1308         int             ipt_uid;
1309         int             ipt_subtype;
1310         int             ipt_alive;
1311 } ipftoken_t;
1312 
1313 
1314 /*
1315  * sync commands
1316  */
1317 #define	IPFSYNC_RESYNC	0
1318 #define	IPFSYNC_NEWIFP	1
1319 #define	IPFSYNC_OLDIFP	2
1320 
1321 
1322 /*
1323 ** HPUX Port
1324 */
1325 #ifdef __hpux
1326 /* HP-UX locking sequence deadlock detection module lock MAJOR ID */
1327 # define	IPF_SMAJ	0	/* temp assignment XXX, not critical */
1328 #endif
1329 
1330 #if !defined(CDEV_MAJOR) && defined (__FreeBSD_version) && \
1331     (__FreeBSD_version >= 220000)
1332 # define	CDEV_MAJOR	79
1333 #endif
1334 
1335 /*
1336  * Post NetBSD 1.2 has the PFIL interface for packet filters.  This turns
1337  * on those hooks.  We don't need any special mods in non-IP Filter code
1338  * with this!
1339  */
1340 #if (defined(NetBSD) && (NetBSD > 199609) && (NetBSD <= 1991011)) || \
1341     (defined(NetBSD1_2) && NetBSD1_2 > 1) || \
1342     (defined(__FreeBSD__) && (__FreeBSD_version >= 500043))
1343 # if (NetBSD >= 199905)
1344 #  define PFIL_HOOKS
1345 # endif
1346 # ifdef PFIL_HOOKS
1347 #  define NETBSD_PF
1348 # endif
1349 #endif
1350 
1351 #ifndef	_KERNEL
1352 extern	int	fr_check __P((struct ip *, int, void *, int, mb_t **, ipf_stack_t *));
1353 extern	int	(*fr_checkp) __P((ip_t *, int, void *, int, mb_t **, ipf_stack_t *));
1354 extern	int	ipf_log __P((void));
1355 extern	struct	ifnet *get_unit __P((char *, int, ipf_stack_t *));
1356 extern	char	*get_ifname __P((struct ifnet *));
1357 # if defined(__NetBSD__) || defined(__OpenBSD__) || \
1358 	  (_BSDI_VERSION >= 199701) || (__FreeBSD_version >= 300000)
1359 extern	int	frrequest __P((int, u_long, caddr_t, int, int, ipf_stack_t *));
1360 # else
1361 extern	int	iplioctl __P((int, ioctlcmd_t, caddr_t, int));
1362 # endif
1363 extern	int	iplopen __P((dev_t, int));
1364 extern	int	iplclose __P((dev_t, int));
1365 extern	void	m_freem __P((mb_t *));
1366 #else /* #ifndef _KERNEL */
1367 extern	phy_if_t	get_unit __P((char *, int, ipf_stack_t *));
1368 # if defined(__NetBSD__) && defined(PFIL_HOOKS)
1369 extern	void	ipfilterattach __P((int));
1370 # endif
1371 extern	int	ipl_enable __P((void));
1372 extern	int	ipl_disable __P((void));
1373 # ifdef MENTAT
1374 extern	ipf_stack_t *ipf_find_stack(const zoneid_t zone);
1375 extern	int	fr_check __P((struct ip *, int, void *, int, void *,
1376 			      mblk_t **, ipf_stack_t *));
1377 #  if SOLARIS
1378 #   if SOLARIS2 >= 7
1379 extern	int	iplioctl __P((dev_t, int, intptr_t, int, cred_t *, int *));
1380 #   else
1381 extern	int	iplioctl __P((dev_t, int, int *, int, cred_t *, int *));
1382 #   endif
1383 #   if SOLARIS2 >= 10 && defined(_KERNEL)
1384 extern	int	ipf_inject __P((fr_info_t *, mb_t *));
1385 extern	int	fr_make_rst __P((fr_info_t *));
1386 extern	int	fr_make_icmp __P((fr_info_t *));
1387 extern	void	fr_calc_chksum __P((fr_info_t *, mb_t *));
1388 #   endif
1389 extern	int	iplopen __P((dev_t *, int, int, cred_t *));
1390 extern	int	iplclose __P((dev_t, int, int, cred_t *));
1391 extern	int	iplread __P((dev_t, uio_t *, cred_t *));
1392 extern	int	iplwrite __P((dev_t, uio_t *, cred_t *));
1393 #  endif
1394 #  ifdef __hpux
1395 extern	int	iplopen __P((dev_t, int, intptr_t, int));
1396 extern	int	iplclose __P((dev_t, int, int));
1397 extern	int	iplioctl __P((dev_t, int, caddr_t, int));
1398 extern	int	iplread __P((dev_t, uio_t *));
1399 extern	int	iplwrite __P((dev_t, uio_t *));
1400 extern	int	iplselect __P((dev_t, int));
1401 #  endif
1402 extern	int	ipfsync __P((ipf_stack_t *));
1403 extern	int	fr_qout __P((queue_t *, mblk_t *));
1404 # else /* MENTAT */
1405 extern	int	fr_check __P((struct ip *, int, void *, int, mb_t **, ipf_stack_t *));
1406 extern	int	(*fr_checkp) __P((ip_t *, int, void *, int, mb_t **, ipf_stack_t *));
1407 extern	size_t	mbufchainlen __P((mb_t *));
1408 #  ifdef	__sgi
1409 #   include <sys/cred.h>
1410 extern	int	iplioctl __P((dev_t, int, caddr_t, int, cred_t *, int *));
1411 extern	int	iplopen __P((dev_t *, int, int, cred_t *));
1412 extern	int	iplclose __P((dev_t, int, int, cred_t *));
1413 extern	int	iplread __P((dev_t, uio_t *, cred_t *));
1414 extern	int	iplwrite __P((dev_t, uio_t *, cred_t *));
1415 extern	int	ipfsync __P((ipf_stack_t *));
1416 extern	int	ipfilter_sgi_attach __P((void));
1417 extern	void	ipfilter_sgi_detach __P((void));
1418 extern	void	ipfilter_sgi_intfsync __P((void));
1419 #  else
1420 #   ifdef	IPFILTER_LKM
1421 extern	int	iplidentify __P((char *));
1422 #   endif
1423 #   if (_BSDI_VERSION >= 199510) || (__FreeBSD_version >= 220000) || \
1424       (NetBSD >= 199511) || defined(__OpenBSD__)
1425 #    if defined(__NetBSD__) || (_BSDI_VERSION >= 199701) || \
1426        defined(__OpenBSD__) || (__FreeBSD_version >= 300000)
1427 #     if (__FreeBSD_version >= 500024)
1428 #      if (__FreeBSD_version >= 502116)
1429 extern	int	iplioctl __P((struct cdev*, u_long, caddr_t, int, struct thread *));
1430 #      else
1431 extern	int	iplioctl __P((dev_t, u_long, caddr_t, int, struct thread *));
1432 #      endif /* __FreeBSD_version >= 502116 */
1433 #     else
1434 extern	int	iplioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
1435 #     endif /* __FreeBSD_version >= 500024 */
1436 #    else
1437 extern	int	iplioctl __P((dev_t, int, caddr_t, int, struct proc *));
1438 #    endif
1439 #    if (__FreeBSD_version >= 500024)
1440 #      if (__FreeBSD_version >= 502116)
1441 extern	int	iplopen __P((struct cdev*, int, int, struct thread *));
1442 extern	int	iplclose __P((struct cdev*, int, int, struct thread *));
1443 #      else
1444 extern	int	iplopen __P((dev_t, int, int, struct thread *));
1445 extern	int	iplclose __P((dev_t, int, int, struct thread *));
1446 #      endif /* __FreeBSD_version >= 502116 */
1447 #    else
1448 extern	int	iplopen __P((dev_t, int, int, struct proc *));
1449 extern	int	iplclose __P((dev_t, int, int, struct proc *));
1450 #    endif /* __FreeBSD_version >= 500024 */
1451 #   else
1452 #    ifdef linux
1453 extern	int	iplioctl __P((struct inode *, struct file *, u_int, u_long));
1454 #    else
1455 extern	int	iplopen __P((dev_t, int));
1456 extern	int	iplclose __P((dev_t, int));
1457 extern	int	iplioctl __P((dev_t, int, caddr_t, int));
1458 #    endif
1459 #   endif /* (_BSDI_VERSION >= 199510) */
1460 #   if	BSD >= 199306
1461 #      if (__FreeBSD_version >= 502116)
1462 extern	int	iplread __P((struct cdev*, struct uio *, int));
1463 extern	int	iplwrite __P((struct cdev*, struct uio *, int));
1464 #      else
1465 extern	int	iplread __P((dev_t, struct uio *, int));
1466 extern	int	iplwrite __P((dev_t, struct uio *, int));
1467 #      endif /* __FreeBSD_version >= 502116 */
1468 #   else
1469 #    ifndef linux
1470 extern	int	iplread __P((dev_t, struct uio *));
1471 extern	int	iplwrite __P((dev_t, struct uio *));
1472 #    endif
1473 #   endif /* BSD >= 199306 */
1474 #  endif /* __ sgi */
1475 # endif /* MENTAT */
1476 
1477 #endif /* #ifndef _KERNEL */
1478 
1479 extern	char	*memstr __P((char *, char *, int, int));
1480 extern	int	count4bits __P((u_32_t));
1481 extern	int	count6bits __P((u_32_t *));
1482 extern	int	frrequest __P((int, ioctlcmd_t, caddr_t, int, int, ipf_stack_t *));
1483 extern	char	*getifname __P((struct ifnet *));
1484 extern	int	iplattach __P((ipf_stack_t *));
1485 extern	int	ipldetach __P((ipf_stack_t *));
1486 extern	u_short	ipf_cksum __P((u_short *, int));
1487 extern	int	copyinptr __P((void *, void *, size_t));
1488 extern	int	copyoutptr __P((void *, void *, size_t));
1489 extern	int	fr_fastroute __P((mb_t *, mb_t **, fr_info_t *, frdest_t *));
1490 extern	int	fr_inobj __P((void *, void *, int));
1491 extern	int	fr_inobjsz __P((void *, void *, int, int));
1492 extern	int	fr_ioctlswitch __P((int, void *, ioctlcmd_t, int, int, void *,
1493 				    ipf_stack_t *));
1494 extern	int	fr_ipftune __P((ioctlcmd_t, void *, ipf_stack_t *));
1495 extern	int	fr_outobj __P((void *, void *, int));
1496 extern	int	fr_outobjsz __P((void *, void *, int, int));
1497 extern	void	*fr_pullup __P((mb_t *, fr_info_t *, int));
1498 extern	void	fr_resolvedest __P((struct frdest *, int, ipf_stack_t *));
1499 extern	int	fr_resolvefunc __P((void *));
1500 extern	void	*fr_resolvenic __P((char *, int, ipf_stack_t *));
1501 extern	int	fr_send_icmp_err __P((int, fr_info_t *, int));
1502 extern	int	fr_send_reset __P((fr_info_t *));
1503 #if  (__FreeBSD_version < 490000) || !defined(_KERNEL)
1504 extern	int	ppsratecheck __P((struct timeval *, int *, int));
1505 #endif
1506 extern	ipftq_t	*fr_addtimeoutqueue __P((ipftq_t **, u_int, ipf_stack_t *));
1507 extern	void	fr_deletequeueentry __P((ipftqent_t *));
1508 extern	int	fr_deletetimeoutqueue __P((ipftq_t *));
1509 extern	void	fr_freetimeoutqueue __P((ipftq_t *, ipf_stack_t *));
1510 extern	void	fr_movequeue __P((ipftqent_t *, ipftq_t *, ipftq_t *,
1511 				  ipf_stack_t *));
1512 extern	void	fr_queueappend __P((ipftqent_t *, ipftq_t *, void *,
1513 				    ipf_stack_t *));
1514 extern	void	fr_queueback __P((ipftqent_t *, ipf_stack_t *));
1515 extern	void	fr_queuefront __P((ipftqent_t *));
1516 extern	void	fr_checkv4sum __P((fr_info_t *));
1517 extern	int	fr_checkl4sum __P((fr_info_t *));
1518 extern	int	fr_ifpfillv4addr __P((int, struct sockaddr_in *,
1519 				      struct sockaddr_in *, struct in_addr *,
1520 				      struct in_addr *));
1521 extern	int	fr_coalesce __P((fr_info_t *));
1522 #ifdef	USE_INET6
1523 extern	void	fr_checkv6sum __P((fr_info_t *));
1524 extern	int	fr_ifpfillv6addr __P((int, struct sockaddr_in6 *,
1525 				      struct sockaddr_in6 *, struct in_addr *,
1526 				      struct in_addr *));
1527 #endif
1528 
1529 #define	IPFILTER_COMPAT
1530 extern	int	fr_incomptrans __P((ipfobj_t *, void *));
1531 extern	int	fr_outcomptrans __P((ipfobj_t *, void *));
1532 
1533 extern	int		fr_addipftune __P((ipftuneable_t *, ipf_stack_t *));
1534 extern	int		fr_delipftune __P((ipftuneable_t *, ipf_stack_t *));
1535 
1536 extern	int	frflush __P((minor_t, int, int, ipf_stack_t *));
1537 extern	void	frsync __P((int, int, void *, char *, ipf_stack_t *));
1538 #if SOLARIS2 >= 10
1539 extern	void	fr_ifindexsync __P((void *, void *, ipf_stack_t *));
1540 #endif
1541 extern	frgroup_t *fr_addgroup __P((char *, void *, u_32_t, minor_t, int,
1542 				    ipf_stack_t *));
1543 extern	int	fr_derefrule __P((frentry_t **, ipf_stack_t *));
1544 extern	void	fr_delgroup __P((char *, minor_t, int, ipf_stack_t *));
1545 extern	frgroup_t *fr_findgroup __P((char *, minor_t, int, frgroup_t ***,
1546 				     ipf_stack_t *));
1547 
1548 extern	int	fr_loginit __P((ipf_stack_t *));
1549 extern	int	ipflog_clear __P((minor_t, ipf_stack_t *));
1550 extern	int	ipflog_read __P((minor_t, struct uio *, ipf_stack_t *));
1551 extern	int	ipflog __P((fr_info_t *, u_int));
1552 extern	int	ipllog __P((int, fr_info_t *, void **, size_t *, int *, int,
1553 			    ipf_stack_t *));
1554 extern	void	fr_logunload __P((ipf_stack_t *));
1555 
1556 extern	frentry_t	*fr_acctpkt __P((fr_info_t *, u_32_t *));
1557 extern	int		fr_copytolog __P((int, char *, int));
1558 extern	u_short		fr_cksum __P((mb_t *, ip_t *, int, void *));
1559 extern	void		fr_deinitialise __P((ipf_stack_t *));
1560 extern	frentry_t 	*fr_dolog __P((fr_info_t *, u_32_t *));
1561 extern	frentry_t 	*fr_dstgrpmap __P((fr_info_t *, u_32_t *));
1562 extern	void		fr_fixskip __P((frentry_t **, frentry_t *, int));
1563 extern	void		fr_forgetifp __P((void *, ipf_stack_t *));
1564 extern	frentry_t 	*fr_getrulen __P((int, char *, u_32_t, 
1565 					  ipf_stack_t *));
1566 extern	void		fr_getstat __P((struct friostat *, ipf_stack_t *));
1567 extern	int		fr_ifpaddr __P((int, int, void *,
1568 					struct in_addr *, struct in_addr *,
1569 					ipf_stack_t *));
1570 extern	int		fr_initialise __P((ipf_stack_t *));
1571 extern	int		fr_lock __P((caddr_t, int *));
1572 extern	int		fr_makefrip __P((int, ip_t *, fr_info_t *));
1573 extern	int		fr_matchtag __P((ipftag_t *, ipftag_t *));
1574 extern	int		fr_matchicmpqueryreply __P((int, icmpinfo_t *,
1575 						    struct icmp *, int));
1576 extern	u_32_t		fr_newisn __P((fr_info_t *));
1577 extern	u_short		fr_nextipid __P((fr_info_t *));
1578 extern	int		fr_rulen __P((int, frentry_t *, ipf_stack_t *));
1579 extern	int		fr_scanlist __P((fr_info_t *, u_32_t));
1580 extern	frentry_t 	*fr_srcgrpmap __P((fr_info_t *, u_32_t *));
1581 extern	int		fr_tcpudpchk __P((fr_info_t *, frtuc_t *));
1582 extern	int		fr_verifysrc __P((fr_info_t *fin));
1583 extern	int		fr_zerostats __P((char *, ipf_stack_t *));
1584 extern  ipftoken_t      *ipf_findtoken __P((int, int, void *, ipf_stack_t *));
1585 extern  int             ipf_getnextrule __P((ipftoken_t *, void *, ipf_stack_t *));
1586 extern  void            ipf_expiretokens __P((ipf_stack_t *));
1587 extern  void            ipf_freetoken __P((ipftoken_t *, ipf_stack_t *));
1588 extern	int		ipf_deltoken __P((int, int, void *, ipf_stack_t *));
1589 extern	int		ipf_genericiter __P((void *, int, void *, ipf_stack_t *));
1590 extern	int		ipf_extraflush __P((int, ipftq_t *, ipftq_t *, ipf_stack_t *));
1591 extern	int		ipf_flushclosing __P((int, int, ipftq_t *, ipftq_t *, ipf_stack_t *));
1592 extern	int		ipf_earlydrop __P((int, ipftq_t *, int, ipf_stack_t *));
1593 
1594 #ifndef ipf_random
1595 extern	u_32_t		ipf_random __P((void));
1596 #endif
1597 
1598 extern	char	ipfilter_version[];
1599 #ifdef	USE_INET6
1600 extern	int	icmptoicmp6types[ICMP_MAXTYPE+1];
1601 extern	int	icmptoicmp6unreach[ICMP_MAX_UNREACH];
1602 extern	int	icmpreplytype6[ICMP6_MAXTYPE + 1];
1603 #endif
1604 extern	int	icmpreplytype4[ICMP_MAXTYPE + 1];
1605 extern	frentry_t *ipfrule_match __P((fr_info_t *));
1606 
1607 extern void	ipftuneable_alloc(ipf_stack_t *);
1608 extern void	ipftuneable_free(ipf_stack_t *);
1609 
1610 #endif	/* __IP_FIL_H__ */
1611 

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2017-12-16 08:10:08, 69.4 KB) [[attachment:ip_compat.h]]
  • [get | view] (2017-12-16 08:10:17, 49.1 KB) [[attachment:ip_fil.h]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.