1 /* $FreeBSD$ */ 2 3 /* 4 * Copyright (C) 2012 by Darren Reed. 5 * 6 * See the IPFILTER.LICENCE file for details on licencing. 7 * 8 * @(#)ipf.h 1.12 6/5/96 9 * $Id$ 10 */ 11 12 #ifndef __IPF_H__ 13 #define __IPF_H__ 14 15 #if defined(__osf__) 16 # define radix_mask ipf_radix_mask 17 # define radix_node ipf_radix_node 18 # define radix_node_head ipf_radix_node_head 19 #endif 20 21 #include <sys/param.h> 22 #include <sys/types.h> 23 #include <sys/file.h> 24 /* 25 * This is a workaround for <sys/uio.h> troubles on FreeBSD, HPUX, OpenBSD. 26 * Needed here because on some systems <sys/uio.h> gets included by things 27 * like <sys/socket.h> 28 */ 29 #ifndef _KERNEL 30 # define ADD_KERNEL 31 # define _KERNEL 32 # define KERNEL 33 #endif 34 #ifdef __OpenBSD__ 35 struct file; 36 #endif 37 #include <sys/uio.h> 38 #ifdef ADD_KERNEL 39 # undef _KERNEL 40 # undef KERNEL 41 #endif 42 #include <sys/time.h> 43 #include <sys/socket.h> 44 #include <net/if.h> 45 46 #include <netinet/in.h> 47 #include <netinet/in_systm.h> 48 #include <netinet/ip.h> 49 #include <netinet/ip_icmp.h> 50 #ifndef TCP_PAWS_IDLE /* IRIX */ 51 # include <netinet/tcp.h> 52 #endif 53 #include <netinet/udp.h> 54 55 #include <arpa/inet.h> 56 57 #include <errno.h> 58 #include <limits.h> 59 #include <netdb.h> 60 #include <stdlib.h> 61 #include <stddef.h> 62 #include <stdio.h> 63 #if !defined(__SVR4) && !defined(__svr4__) && defined(sun) 64 # include <strings.h> 65 #endif 66 #include <string.h> 67 #include <unistd.h> 68 69 #include "netinet/ip_compat.h" 70 #include "netinet/ip_fil.h" 71 #include "netinet/ip_nat.h" 72 #include "netinet/ip_frag.h" 73 #include "netinet/ip_state.h" 74 #include "netinet/ip_proxy.h" 75 #include "netinet/ip_auth.h" 76 #include "netinet/ip_lookup.h" 77 #include "netinet/ip_pool.h" 78 #include "netinet/ip_scan.h" 79 #include "netinet/ip_htable.h" 80 #include "netinet/ip_sync.h" 81 #include "netinet/ip_dstlist.h" 82 83 #include "opts.h" 84 85 #ifndef __P 86 # ifdef __STDC__ 87 # define __P(x) x 88 # else 89 # define __P(x) () 90 # endif 91 #endif 92 #ifndef __STDC__ 93 # undef const 94 # define const 95 #endif 96 97 #ifndef U_32_T 98 # define U_32_T 1 99 # if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \ 100 defined(__sgi) 101 typedef u_int32_t u_32_t; 102 # else 103 # if defined(__alpha__) || defined(__alpha) || defined(_LP64) 104 typedef unsigned int u_32_t; 105 # else 106 # if SOLARIS2 >= 6 107 typedef uint32_t u_32_t; 108 # else 109 typedef unsigned int u_32_t; 110 # endif 111 # endif 112 # endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ || __sgi */ 113 #endif /* U_32_T */ 114 115 #ifndef MAXHOSTNAMELEN 116 # define MAXHOSTNAMELEN 256 117 #endif 118 119 #define MAX_ICMPCODE 16 120 #define MAX_ICMPTYPE 19 121 122 #define PRINTF (void)printf 123 #define FPRINTF (void)fprintf 124 125 126 struct ipopt_names { 127 int on_value; 128 int on_bit; 129 int on_siz; 130 char *on_name; 131 }; 132 133 134 typedef struct alist_s { 135 struct alist_s *al_next; 136 int al_not; 137 int al_family; 138 i6addr_t al_i6addr; 139 i6addr_t al_i6mask; 140 } alist_t; 141 142 #define al_addr al_i6addr.in4_addr 143 #define al_mask al_i6mask.in4_addr 144 #define al_1 al_addr 145 #define al_2 al_mask 146 147 148 typedef struct plist_s { 149 struct plist_s *pl_next; 150 int pl_compare; 151 u_short pl_port1; 152 u_short pl_port2; 153 } plist_t; 154 155 156 typedef struct { 157 u_short fb_c; 158 u_char fb_t; 159 u_char fb_f; 160 u_32_t fb_k; 161 } fakebpf_t; 162 163 164 typedef struct { 165 char *it_name; 166 int it_v4; 167 int it_v6; 168 } icmptype_t; 169 170 171 typedef struct wordtab { 172 char *w_word; 173 int w_value; 174 } wordtab_t; 175 176 177 typedef struct namelist { 178 struct namelist *na_next; 179 char *na_name; 180 int na_value; 181 } namelist_t; 182 183 184 typedef struct proxyrule { 185 struct proxyrule *pr_next; 186 char *pr_proxy; 187 char *pr_conf; 188 namelist_t *pr_names; 189 int pr_proto; 190 } proxyrule_t; 191 192 193 #if defined(__NetBSD__) || defined(__OpenBSD__) || \ 194 (_BSDI_VERSION >= 199701) || (__FreeBSD_version >= 300000) || \ 195 SOLARIS || defined(__sgi) || defined(__osf__) || defined(linux) 196 # include <stdarg.h> 197 typedef int (* ioctlfunc_t) __P((int, ioctlcmd_t, ...)); 198 #else 199 typedef int (* ioctlfunc_t) __P((dev_t, ioctlcmd_t, void *)); 200 #endif 201 typedef int (* addfunc_t) __P((int, ioctlfunc_t, void *)); 202 typedef int (* copyfunc_t) __P((void *, void *, size_t)); 203 204 205 /* 206 * SunOS4 207 */ 208 #if defined(sun) && !defined(__SVR4) && !defined(__svr4__) 209 extern int ioctl __P((int, int, void *)); 210 #endif 211 212 extern char thishost[]; 213 extern char flagset[]; 214 extern u_char flags[]; 215 extern struct ipopt_names ionames[]; 216 extern struct ipopt_names secclass[]; 217 extern char *icmpcodes[MAX_ICMPCODE + 1]; 218 extern char *icmptypes[MAX_ICMPTYPE + 1]; 219 extern int use_inet6; 220 extern int lineNum; 221 extern int debuglevel; 222 extern struct ipopt_names v6ionames[]; 223 extern icmptype_t icmptypelist[]; 224 extern wordtab_t statefields[]; 225 extern wordtab_t natfields[]; 226 extern wordtab_t poolfields[]; 227 228 229 extern int addicmp __P((char ***, struct frentry *, int)); 230 extern int addipopt __P((char *, struct ipopt_names *, int, char *)); 231 extern int addkeep __P((char ***, struct frentry *, int)); 232 extern alist_t *alist_new __P((int, char *)); 233 extern void alist_free __P((alist_t *)); 234 extern void assigndefined __P((char *)); 235 extern void binprint __P((void *, size_t)); 236 extern u_32_t buildopts __P((char *, char *, int)); 237 extern int checkrev __P((char *)); 238 extern int connecttcp __P((char *, int)); 239 extern int count6bits __P((u_32_t *)); 240 extern int count4bits __P((u_32_t)); 241 extern char *fac_toname __P((int)); 242 extern int fac_findname __P((char *)); 243 extern const char *familyname __P((const int)); 244 extern void fill6bits __P((int, u_int *)); 245 extern wordtab_t *findword __P((wordtab_t *, char *)); 246 extern int ftov __P((int)); 247 extern char *ipf_geterror __P((int, ioctlfunc_t *)); 248 extern int genmask __P((int, char *, i6addr_t *)); 249 extern int gethost __P((int, char *, i6addr_t *)); 250 extern int geticmptype __P((int, char *)); 251 extern int getport __P((struct frentry *, char *, u_short *, char *)); 252 extern int getportproto __P((char *, int)); 253 extern int getproto __P((char *)); 254 extern char *getnattype __P((struct nat *)); 255 extern char *getsumd __P((u_32_t)); 256 extern u_32_t getoptbyname __P((char *)); 257 extern u_32_t getoptbyvalue __P((int)); 258 extern u_32_t getv6optbyname __P((char *)); 259 extern u_32_t getv6optbyvalue __P((int)); 260 extern char *icmptypename __P((int, int)); 261 extern void initparse __P((void)); 262 extern void ipf_dotuning __P((int, char *, ioctlfunc_t)); 263 extern int ipf_addrule __P((int, ioctlfunc_t, void *)); 264 extern void ipf_mutex_clean __P((void)); 265 extern int ipf_parsefile __P((int, addfunc_t, ioctlfunc_t *, char *)); 266 extern int ipf_parsesome __P((int, addfunc_t, ioctlfunc_t *, FILE *)); 267 extern void ipf_perror __P((int, char *)); 268 extern int ipf_perror_fd __P(( int, ioctlfunc_t, char *)); 269 extern void ipf_rwlock_clean __P((void)); 270 extern char *ipf_strerror __P((int)); 271 extern void ipferror __P((int, char *)); 272 extern int ipmon_parsefile __P((char *)); 273 extern int ipmon_parsesome __P((FILE *)); 274 extern int ipnat_addrule __P((int, ioctlfunc_t, void *)); 275 extern int ipnat_parsefile __P((int, addfunc_t, ioctlfunc_t, char *)); 276 extern int ipnat_parsesome __P((int, addfunc_t, ioctlfunc_t, FILE *)); 277 extern int ippool_parsefile __P((int, char *, ioctlfunc_t)); 278 extern int ippool_parsesome __P((int, FILE *, ioctlfunc_t)); 279 extern int kmemcpywrap __P((void *, void *, size_t)); 280 extern char *kvatoname __P((ipfunc_t, ioctlfunc_t)); 281 extern int load_dstlist __P((struct ippool_dst *, ioctlfunc_t, 282 ipf_dstnode_t *)); 283 extern int load_dstlistnode __P((int, char *, struct ipf_dstnode *, 284 ioctlfunc_t)); 285 extern alist_t *load_file __P((char *)); 286 extern int load_hash __P((struct iphtable_s *, struct iphtent_s *, 287 ioctlfunc_t)); 288 extern int load_hashnode __P((int, char *, struct iphtent_s *, int, 289 ioctlfunc_t)); 290 extern alist_t *load_http __P((char *)); 291 extern int load_pool __P((struct ip_pool_s *list, ioctlfunc_t)); 292 extern int load_poolnode __P((int, char *, ip_pool_node_t *, int, ioctlfunc_t)); 293 extern alist_t *load_url __P((char *)); 294 extern alist_t *make_range __P((int, struct in_addr, struct in_addr)); 295 extern void mb_hexdump __P((mb_t *, FILE *)); 296 extern ipfunc_t nametokva __P((char *, ioctlfunc_t)); 297 extern void nat_setgroupmap __P((struct ipnat *)); 298 extern int ntomask __P((int, int, u_32_t *)); 299 extern u_32_t optname __P((char ***, u_short *, int)); 300 extern wordtab_t *parsefields __P((wordtab_t *, char *)); 301 extern int *parseipfexpr __P((char *, char **)); 302 extern int parsewhoisline __P((char *, addrfamily_t *, addrfamily_t *)); 303 extern void pool_close __P((void)); 304 extern int pool_fd __P((void)); 305 extern int pool_ioctl __P((ioctlfunc_t, ioctlcmd_t, void *)); 306 extern int pool_open __P((void)); 307 extern char *portname __P((int, int)); 308 extern int pri_findname __P((char *)); 309 extern char *pri_toname __P((int)); 310 extern void print_toif __P((int, char *, char *, struct frdest *)); 311 extern void printaps __P((ap_session_t *, int, int)); 312 extern void printaddr __P((int, int, char *, int, u_32_t *, u_32_t *)); 313 extern void printbuf __P((char *, int, int)); 314 extern void printfieldhdr __P((wordtab_t *, wordtab_t *)); 315 extern void printfr __P((struct frentry *, ioctlfunc_t)); 316 extern struct iphtable_s *printhash __P((struct iphtable_s *, copyfunc_t, 317 char *, int, wordtab_t *)); 318 extern struct iphtable_s *printhash_live __P((iphtable_t *, int, char *, 319 int, wordtab_t *)); 320 extern ippool_dst_t *printdstl_live __P((ippool_dst_t *, int, char *, 321 int, wordtab_t *)); 322 extern void printhashdata __P((iphtable_t *, int)); 323 extern struct iphtent_s *printhashnode __P((struct iphtable_s *, 324 struct iphtent_s *, 325 copyfunc_t, int, wordtab_t *)); 326 extern void printhost __P((int, u_32_t *)); 327 extern void printhostmask __P((int, u_32_t *, u_32_t *)); 328 extern void printip __P((int, u_32_t *)); 329 extern void printlog __P((struct frentry *)); 330 extern void printlookup __P((char *, i6addr_t *addr, i6addr_t *mask)); 331 extern void printmask __P((int, u_32_t *)); 332 extern void printnataddr __P((int, char *, nat_addr_t *, int)); 333 extern void printnatfield __P((nat_t *, int)); 334 extern void printnatside __P((char *, nat_stat_side_t *)); 335 extern void printpacket __P((int, mb_t *)); 336 extern void printpacket6 __P((int, mb_t *)); 337 extern struct ippool_dst *printdstlist __P((struct ippool_dst *, copyfunc_t, 338 char *, int, ipf_dstnode_t *, 339 wordtab_t *)); 340 extern void printdstlistdata __P((ippool_dst_t *, int)); 341 extern ipf_dstnode_t *printdstlistnode __P((ipf_dstnode_t *, copyfunc_t, 342 int, wordtab_t *)); 343 extern void printdstlistpolicy __P((ippool_policy_t)); 344 extern struct ip_pool_s *printpool __P((struct ip_pool_s *, copyfunc_t, 345 char *, int, wordtab_t *)); 346 extern struct ip_pool_s *printpool_live __P((struct ip_pool_s *, int, 347 char *, int, wordtab_t *)); 348 extern void printpooldata __P((ip_pool_t *, int)); 349 extern void printpoolfield __P((void *, int, int)); 350 extern struct ip_pool_node *printpoolnode __P((struct ip_pool_node *, 351 int, wordtab_t *)); 352 extern void printproto __P((struct protoent *, int, struct ipnat *)); 353 extern void printportcmp __P((int, struct frpcmp *)); 354 extern void printstatefield __P((ipstate_t *, int)); 355 extern void printtqtable __P((ipftq_t *)); 356 extern void printtunable __P((ipftune_t *)); 357 extern void printunit __P((int)); 358 extern void optprint __P((u_short *, u_long, u_long)); 359 #ifdef USE_INET6 360 extern void optprintv6 __P((u_short *, u_long, u_long)); 361 #endif 362 extern int remove_hash __P((struct iphtable_s *, ioctlfunc_t)); 363 extern int remove_hashnode __P((int, char *, struct iphtent_s *, ioctlfunc_t)); 364 extern int remove_pool __P((ip_pool_t *, ioctlfunc_t)); 365 extern int remove_poolnode __P((int, char *, ip_pool_node_t *, ioctlfunc_t)); 366 extern u_char tcpflags __P((char *)); 367 extern void printc __P((struct frentry *)); 368 extern void printC __P((int)); 369 extern void emit __P((int, int, void *, struct frentry *)); 370 extern u_char secbit __P((int)); 371 extern u_char seclevel __P((char *)); 372 extern void printfraginfo __P((char *, struct ipfr *)); 373 extern void printifname __P((char *, char *, void *)); 374 extern char *hostname __P((int, void *)); 375 extern struct ipstate *printstate __P((struct ipstate *, int, u_long)); 376 extern void printsbuf __P((char *)); 377 extern void printnat __P((struct ipnat *, int)); 378 extern void printactiveaddress __P((int, char *, i6addr_t *, char *)); 379 extern void printactivenat __P((struct nat *, int, u_long)); 380 extern void printhostmap __P((struct hostmap *, u_int)); 381 extern void printtcpflags __P((u_32_t, u_32_t)); 382 extern void printipfexpr __P((int *)); 383 extern void printstatefield __P((ipstate_t *, int)); 384 extern void printstatefieldhdr __P((int)); 385 extern int sendtrap_v1_0 __P((int, char *, char *, int, time_t)); 386 extern int sendtrap_v2_0 __P((int, char *, char *, int)); 387 extern int vtof __P((int)); 388 389 extern void set_variable __P((char *, char *)); 390 extern char *get_variable __P((char *, char **, int)); 391 extern void resetlexer __P((void)); 392 393 extern void debug __P((int, char *, ...)); 394 extern void verbose __P((int, char *, ...)); 395 extern void ipfkdebug __P((char *, ...)); 396 extern void ipfkverbose __P((char *, ...)); 397 398 #if SOLARIS 399 extern int gethostname __P((char *, int )); 400 extern void sync __P((void)); 401 #endif 402 403 #endif /* __IPF_H__ */ 404