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