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