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