filter.h revision 49372
1/* 2 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 3 * 4 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. 5 * 6 * Redistribution and use in source and binary forms are permitted 7 * provided that the above copyright notice and this paragraph are 8 * duplicated in all such forms and that any documentation, 9 * advertising materials, and other materials related to such 10 * distribution and use acknowledge that the software was developed 11 * by the Internet Initiative Japan. The name of the 12 * IIJ may not be used to endorse or promote products derived 13 * from this software without specific prior written permission. 14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 17 * 18 * $Id: filter.h,v 1.17 1999/07/27 23:43:59 brian Exp $ 19 * 20 * TODO: 21 */ 22 23/* Known protocols - f_proto */ 24#define P_NONE 0 25#define P_TCP 1 26#define P_UDP 2 27#define P_ICMP 3 28#define P_OSPF 4 29#define P_IGMP 5 30 31/* Operations - f_srcop, f_dstop */ 32#define OP_NONE 0 33#define OP_EQ 1 34#define OP_GT 2 35#define OP_LT 3 36 37/* srctype or dsttype */ 38#define T_ADDR 0 39#define T_MYADDR 1 40#define T_HISADDR 2 41 42/* 43 * There's a struct filterent for each possible filter rule. The 44 * layout is designed to minimise size (there are 4 * MAXFILTERS of 45 * them) - which is also conveniently a power of 2 (32 bytes) on 46 * architectures where sizeof(int)==4 (this makes indexing faster). 47 * 48 * f_action and f_proto only need to be 6 and 3 bits, respectively, 49 * but making them 8 bits allows them to be efficently accessed using 50 * byte operations as well as allowing space for future expansion 51 * (expanding MAXFILTERS or converting f_proto IPPROTO_... values). 52 * 53 * Note that there are four free bits in the initial word for future 54 * extensions. 55 */ 56struct filterent { 57 unsigned f_action : 8; /* Filtering action: goto or A_... */ 58 unsigned f_proto : 8; /* Protocol: P_... */ 59 unsigned f_srcop : 2; /* Source port operation: OP_... */ 60 unsigned f_dstop : 2; /* Destination port operation: OP_... */ 61 unsigned f_srctype : 2; /* T_ value of src */ 62 unsigned f_dsttype : 2; /* T_ value of dst */ 63 unsigned f_estab : 1; /* Check TCP ACK bit */ 64 unsigned f_syn : 1; /* Check TCP SYN bit */ 65 unsigned f_finrst : 1; /* Check TCP FIN/RST bits */ 66 unsigned f_invert : 1; /* true to complement match */ 67 struct in_range f_src; /* Source address and mask */ 68 struct in_range f_dst; /* Destination address and mask */ 69 u_short f_srcport; /* Source port, compared with f_srcop */ 70 u_short f_dstport; /* Destination port, compared with f_dstop */ 71}; 72 73#define MAXFILTERS 40 /* in each filter set */ 74 75/* f_action values [0..MAXFILTERS) specify the next filter rule, others are: */ 76#define A_NONE (MAXFILTERS) 77#define A_PERMIT (A_NONE+1) 78#define A_DENY (A_PERMIT+1) 79 80struct filter { 81 struct filterent rule[MAXFILTERS]; /* incoming packet filter */ 82 const char *name; 83 unsigned fragok : 1; 84 unsigned logok : 1; 85}; 86 87/* Which filter set */ 88#define FL_IN 0 89#define FL_OUT 1 90#define FL_DIAL 2 91#define FL_KEEP 3 92 93struct ipcp; 94struct cmdargs; 95 96extern int ParseAddr(struct ipcp *, const char *, struct in_addr *, 97 struct in_addr *, int *); 98extern int filter_Show(struct cmdargs const *); 99extern int filter_Set(struct cmdargs const *); 100extern const char * filter_Action2Nam(int); 101extern const char *filter_Proto2Nam(int); 102extern const char *filter_Op2Nam(int); 103extern struct in_addr bits2mask(int); 104extern void filter_AdjustAddr(struct filter *, struct in_addr *, 105 struct in_addr *); 106