ipf.h revision 153881
1/* $FreeBSD: head/contrib/ipfilter/ipf.h 153881 2005-12-30 11:52:26Z guido $ */ 2 3/* 4 * Copyright (C) 1993-2001, 2003 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: ipf.h,v 2.71.2.7 2005/06/12 07:18:31 darrenr Exp $ 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__ 35struct 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#if __FreeBSD_version >= 300000 46# include <net/if_var.h> 47#endif 48#include <netinet/in.h> 49#include <netinet/in_systm.h> 50#include <netinet/ip.h> 51#include <netinet/ip_icmp.h> 52#ifndef TCP_PAWS_IDLE /* IRIX */ 53# include <netinet/tcp.h> 54#endif 55#include <netinet/udp.h> 56 57#include <arpa/inet.h> 58 59#include <errno.h> 60#include <limits.h> 61#include <netdb.h> 62#include <stdlib.h> 63#include <stddef.h> 64#include <stdio.h> 65#if !defined(__SVR4) && !defined(__svr4__) && defined(sun) 66# include <strings.h> 67#endif 68#include <string.h> 69#include <unistd.h> 70 71#include "netinet/ip_compat.h" 72#include "netinet/ip_fil.h" 73#include "netinet/ip_nat.h" 74#include "netinet/ip_frag.h" 75#include "netinet/ip_state.h" 76#include "netinet/ip_proxy.h" 77#include "netinet/ip_auth.h" 78#include "netinet/ip_lookup.h" 79#include "netinet/ip_pool.h" 80#include "netinet/ip_scan.h" 81#include "netinet/ip_htable.h" 82#include "netinet/ip_sync.h" 83 84#include "opts.h" 85 86#ifndef __P 87# ifdef __STDC__ 88# define __P(x) x 89# else 90# define __P(x) () 91# endif 92#endif 93#ifndef __STDC__ 94# undef const 95# define const 96#endif 97 98#ifndef U_32_T 99# define U_32_T 1 100# if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \ 101 defined(__sgi) 102typedef u_int32_t u_32_t; 103# else 104# if defined(__alpha__) || defined(__alpha) || defined(_LP64) 105typedef unsigned int u_32_t; 106# else 107# if SOLARIS2 >= 6 108typedef uint32_t u_32_t; 109# else 110typedef unsigned int u_32_t; 111# endif 112# endif 113# endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ || __sgi */ 114#endif /* U_32_T */ 115 116#ifndef MAXHOSTNAMELEN 117# define MAXHOSTNAMELEN 256 118#endif 119 120#define MAX_ICMPCODE 16 121#define MAX_ICMPTYPE 19 122 123 124struct ipopt_names { 125 int on_value; 126 int on_bit; 127 int on_siz; 128 char *on_name; 129}; 130 131 132typedef struct alist_s { 133 struct alist_s *al_next; 134 int al_not; 135 i6addr_t al_i6addr; 136 i6addr_t al_i6mask; 137} alist_t; 138 139#define al_addr al_i6addr.in4_addr 140#define al_mask al_i6mask.in4_addr 141#define al_1 al_addr 142#define al_2 al_mask 143 144 145typedef struct { 146 u_short fb_c; 147 u_char fb_t; 148 u_char fb_f; 149 u_32_t fb_k; 150} fakebpf_t; 151 152 153#if defined(__NetBSD__) || defined(__OpenBSD__) || \ 154 (_BSDI_VERSION >= 199701) || (__FreeBSD_version >= 300000) || \ 155 SOLARIS || defined(__sgi) || defined(__osf__) || defined(linux) 156# include <stdarg.h> 157typedef int (* ioctlfunc_t) __P((int, ioctlcmd_t, ...)); 158#else 159typedef int (* ioctlfunc_t) __P((dev_t, ioctlcmd_t, void *)); 160#endif 161typedef void (* addfunc_t) __P((int, ioctlfunc_t, void *)); 162typedef int (* copyfunc_t) __P((void *, void *, size_t)); 163 164 165/* 166 * SunOS4 167 */ 168#if defined(sun) && !defined(__SVR4) && !defined(__svr4__) 169extern int ioctl __P((int, int, void *)); 170#endif 171 172extern char thishost[]; 173extern char flagset[]; 174extern u_char flags[]; 175extern struct ipopt_names ionames[]; 176extern struct ipopt_names secclass[]; 177extern char *icmpcodes[MAX_ICMPCODE + 1]; 178extern char *icmptypes[MAX_ICMPTYPE + 1]; 179extern int use_inet6; 180extern int lineNum; 181extern struct ipopt_names v6ionames[]; 182 183 184extern int addicmp __P((char ***, struct frentry *, int)); 185extern int addipopt __P((char *, struct ipopt_names *, int, char *)); 186extern int addkeep __P((char ***, struct frentry *, int)); 187extern int bcopywrap __P((void *, void *, size_t)); 188extern void binprint __P((void *, size_t)); 189extern void initparse __P((void)); 190extern u_32_t buildopts __P((char *, char *, int)); 191extern int checkrev __P((char *)); 192extern int count6bits __P((u_32_t *)); 193extern int count4bits __P((u_32_t)); 194extern int extras __P((char ***, struct frentry *, int)); 195extern char *fac_toname __P((int)); 196extern int fac_findname __P((char *)); 197extern void fill6bits __P((int, u_int *)); 198extern int gethost __P((char *, u_32_t *)); 199extern int getport __P((struct frentry *, char *, u_short *)); 200extern int getportproto __P((char *, int)); 201extern int getproto __P((char *)); 202extern char *getline __P((char *, size_t, FILE *, int *)); 203extern int genmask __P((char *, u_32_t *)); 204extern char *getnattype __P((struct ipnat *)); 205extern char *getsumd __P((u_32_t)); 206extern u_32_t getoptbyname __P((char *)); 207extern u_32_t getoptbyvalue __P((int)); 208extern u_32_t getv6optbyname __P((char *)); 209extern u_32_t getv6optbyvalue __P((int)); 210extern void hexdump __P((FILE *, void *, int, int)); 211extern int hostmask __P((char ***, char *, char *, u_32_t *, u_32_t *, int)); 212extern int hostnum __P((u_32_t *, char *, int, char *)); 213extern int icmpcode __P((char *)); 214extern int icmpidnum __P((char *, u_short *, int)); 215extern void initparse __P((void)); 216extern void ipf_dotuning __P((int, char *, ioctlfunc_t)); 217extern void ipf_addrule __P((int, ioctlfunc_t, void *)); 218extern int ipf_parsefile __P((int, addfunc_t, ioctlfunc_t *, char *)); 219extern int ipf_parsesome __P((int, addfunc_t, ioctlfunc_t *, FILE *)); 220extern int ipmon_parsefile __P((char *)); 221extern int ipmon_parsesome __P((FILE *)); 222extern void ipnat_addrule __P((int, ioctlfunc_t, void *)); 223extern int ipnat_parsefile __P((int, addfunc_t, ioctlfunc_t, char *)); 224extern int ipnat_parsesome __P((int, addfunc_t, ioctlfunc_t, FILE *)); 225extern int ippool_parsefile __P((int, char *, ioctlfunc_t)); 226extern int ippool_parsesome __P((int, FILE *, ioctlfunc_t)); 227extern int kmemcpywrap __P((void *, void *, size_t)); 228extern char *kvatoname __P((ipfunc_t, ioctlfunc_t)); 229extern int load_hash __P((struct iphtable_s *, struct iphtent_s *, 230 ioctlfunc_t)); 231extern int load_hashnode __P((int, char *, struct iphtent_s *, ioctlfunc_t)); 232extern int load_pool __P((struct ip_pool_s *list, ioctlfunc_t)); 233extern int load_poolnode __P((int, char *, ip_pool_node_t *, ioctlfunc_t)); 234extern int loglevel __P((char **, u_int *, int)); 235extern alist_t *make_range __P((int, struct in_addr, struct in_addr)); 236extern ipfunc_t nametokva __P((char *, ioctlfunc_t)); 237extern ipnat_t *natparse __P((char *, int)); 238extern void natparsefile __P((int, char *, int)); 239extern void nat_setgroupmap __P((struct ipnat *)); 240extern int ntomask __P((int, int, u_32_t *)); 241extern u_32_t optname __P((char ***, u_short *, int)); 242extern struct frentry *parse __P((char *, int)); 243extern char *portname __P((int, int)); 244extern int portnum __P((char *, char *, u_short *, int)); 245extern int ports __P((char ***, char *, u_short *, int *, u_short *, int)); 246extern int pri_findname __P((char *)); 247extern char *pri_toname __P((int)); 248extern void print_toif __P((char *, struct frdest *)); 249extern void printaps __P((ap_session_t *, int)); 250extern void printbuf __P((char *, int, int)); 251extern void printfr __P((struct frentry *, ioctlfunc_t)); 252extern void printtunable __P((ipftune_t *)); 253extern struct iphtable_s *printhash __P((struct iphtable_s *, copyfunc_t, 254 char *, int)); 255extern struct iphtent_s *printhashnode __P((struct iphtable_s *, 256 struct iphtent_s *, 257 copyfunc_t, int)); 258extern void printhostmask __P((int, u_32_t *, u_32_t *)); 259extern void printip __P((u_32_t *)); 260extern void printlog __P((struct frentry *)); 261extern void printlookup __P((i6addr_t *addr, i6addr_t *mask)); 262extern void printmask __P((u_32_t *)); 263extern void printpacket __P((struct ip *)); 264extern void printpacket6 __P((struct ip *)); 265extern struct ip_pool_s *printpool __P((struct ip_pool_s *, copyfunc_t, 266 char *, int)); 267extern struct ip_pool_node *printpoolnode __P((struct ip_pool_node *, int)); 268extern void printproto __P((struct protoent *, int, struct ipnat *)); 269extern void printportcmp __P((int, struct frpcmp *)); 270extern void optprint __P((u_short *, u_long, u_long)); 271#ifdef USE_INET6 272extern void optprintv6 __P((u_short *, u_long, u_long)); 273#endif 274extern int ratoi __P((char *, int *, int, int)); 275extern int ratoui __P((char *, u_int *, u_int, u_int)); 276extern int remove_hash __P((struct iphtable_s *, ioctlfunc_t)); 277extern int remove_hashnode __P((int, char *, struct iphtent_s *, ioctlfunc_t)); 278extern int remove_pool __P((ip_pool_t *, ioctlfunc_t)); 279extern int remove_poolnode __P((int, char *, ip_pool_node_t *, ioctlfunc_t)); 280extern u_char tcp_flags __P((char *, u_char *, int)); 281extern u_char tcpflags __P((char *)); 282extern int to_interface __P((struct frdest *, char *, int)); 283extern void printc __P((struct frentry *)); 284extern void printC __P((int)); 285extern void emit __P((int, int, void *, struct frentry *)); 286extern u_char secbit __P((int)); 287extern u_char seclevel __P((char *)); 288extern void printfraginfo __P((char *, struct ipfr *)); 289extern void printifname __P((char *, char *, void *)); 290extern char *hostname __P((int, void *)); 291extern struct ipstate *printstate __P((struct ipstate *, int, u_long)); 292extern void printsbuf __P((char *)); 293extern void printnat __P((struct ipnat *, int)); 294extern void printactivenat __P((struct nat *, int)); 295extern void printhostmap __P((struct hostmap *, u_int)); 296extern void printpacket __P((struct ip *)); 297 298extern void set_variable __P((char *, char *)); 299extern char *get_variable __P((char *, char **, int)); 300extern void resetlexer __P((void)); 301 302#if SOLARIS 303extern int gethostname __P((char *, int )); 304extern void sync __P((void)); 305#endif 306 307#endif /* __IPF_H__ */ 308