1995-01-31 06:29:58 +00:00
|
|
|
/*
|
|
|
|
* Written by Toshiharu OHNO (tony-o@iij.ad.jp)
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that the above copyright notice and this paragraph are
|
|
|
|
* duplicated in all such forms and that any documentation,
|
|
|
|
* advertising materials, and other materials related to such
|
|
|
|
* distribution and use acknowledge that the software was developed
|
|
|
|
* by the Internet Initiative Japan. The name of the
|
|
|
|
* IIJ may not be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
*/
|
|
|
|
|
1999-07-27 23:44:00 +00:00
|
|
|
/* Known protocols - f_proto */
|
1995-01-31 06:29:58 +00:00
|
|
|
#define P_NONE 0
|
|
|
|
#define P_TCP 1
|
|
|
|
#define P_UDP 2
|
|
|
|
#define P_ICMP 3
|
1999-08-02 15:29:19 +00:00
|
|
|
#ifdef IPPROTO_OSPFIGP
|
1999-08-02 11:53:16 +00:00
|
|
|
#define P_OSPF 4
|
1999-08-02 15:29:19 +00:00
|
|
|
#endif
|
1999-08-02 11:53:16 +00:00
|
|
|
#define P_IGMP 5
|
1999-09-30 07:23:13 +00:00
|
|
|
#ifdef IPPROTO_GRE
|
|
|
|
#define P_GRE 6
|
|
|
|
#endif
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1999-07-27 23:44:00 +00:00
|
|
|
/* Operations - f_srcop, f_dstop */
|
1995-01-31 06:29:58 +00:00
|
|
|
#define OP_NONE 0
|
|
|
|
#define OP_EQ 1
|
|
|
|
#define OP_GT 2
|
1999-07-27 23:44:00 +00:00
|
|
|
#define OP_LT 3
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1999-05-31 23:57:40 +00:00
|
|
|
/* srctype or dsttype */
|
|
|
|
#define T_ADDR 0
|
|
|
|
#define T_MYADDR 1
|
|
|
|
#define T_HISADDR 2
|
|
|
|
|
1999-07-27 23:44:00 +00:00
|
|
|
/*
|
|
|
|
* There's a struct filterent for each possible filter rule. The
|
|
|
|
* layout is designed to minimise size (there are 4 * MAXFILTERS of
|
|
|
|
* them) - which is also conveniently a power of 2 (32 bytes) on
|
|
|
|
* architectures where sizeof(int)==4 (this makes indexing faster).
|
|
|
|
*
|
|
|
|
* f_action and f_proto only need to be 6 and 3 bits, respectively,
|
|
|
|
* but making them 8 bits allows them to be efficently accessed using
|
|
|
|
* byte operations as well as allowing space for future expansion
|
|
|
|
* (expanding MAXFILTERS or converting f_proto IPPROTO_... values).
|
|
|
|
*
|
|
|
|
* Note that there are four free bits in the initial word for future
|
|
|
|
* extensions.
|
|
|
|
*/
|
1995-01-31 06:29:58 +00:00
|
|
|
struct filterent {
|
1999-07-27 23:44:00 +00:00
|
|
|
unsigned f_action : 8; /* Filtering action: goto or A_... */
|
|
|
|
unsigned f_proto : 8; /* Protocol: P_... */
|
|
|
|
unsigned f_srcop : 2; /* Source port operation: OP_... */
|
|
|
|
unsigned f_dstop : 2; /* Destination port operation: OP_... */
|
|
|
|
unsigned f_srctype : 2; /* T_ value of src */
|
|
|
|
unsigned f_dsttype : 2; /* T_ value of dst */
|
|
|
|
unsigned f_estab : 1; /* Check TCP ACK bit */
|
|
|
|
unsigned f_syn : 1; /* Check TCP SYN bit */
|
|
|
|
unsigned f_finrst : 1; /* Check TCP FIN/RST bits */
|
|
|
|
unsigned f_invert : 1; /* true to complement match */
|
|
|
|
struct in_range f_src; /* Source address and mask */
|
|
|
|
struct in_range f_dst; /* Destination address and mask */
|
|
|
|
u_short f_srcport; /* Source port, compared with f_srcop */
|
|
|
|
u_short f_dstport; /* Destination port, compared with f_dstop */
|
1995-01-31 06:29:58 +00:00
|
|
|
};
|
|
|
|
|
1999-07-27 23:44:00 +00:00
|
|
|
#define MAXFILTERS 40 /* in each filter set */
|
|
|
|
|
|
|
|
/* f_action values [0..MAXFILTERS) specify the next filter rule, others are: */
|
|
|
|
#define A_NONE (MAXFILTERS)
|
|
|
|
#define A_PERMIT (A_NONE+1)
|
|
|
|
#define A_DENY (A_PERMIT+1)
|
1998-03-16 22:52:54 +00:00
|
|
|
|
|
|
|
struct filter {
|
|
|
|
struct filterent rule[MAXFILTERS]; /* incoming packet filter */
|
1998-04-18 01:01:28 +00:00
|
|
|
const char *name;
|
1998-03-16 22:52:54 +00:00
|
|
|
unsigned fragok : 1;
|
|
|
|
unsigned logok : 1;
|
|
|
|
};
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1999-07-27 23:44:00 +00:00
|
|
|
/* Which filter set */
|
1995-03-11 15:18:55 +00:00
|
|
|
#define FL_IN 0
|
|
|
|
#define FL_OUT 1
|
|
|
|
#define FL_DIAL 2
|
|
|
|
#define FL_KEEP 3
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-04-07 00:54:26 +00:00
|
|
|
struct ipcp;
|
|
|
|
struct cmdargs;
|
1997-08-25 00:29:32 +00:00
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
extern int ParseAddr(struct ipcp *, const char *, struct in_addr *,
|
1998-03-13 21:07:46 +00:00
|
|
|
struct in_addr *, int *);
|
1998-05-01 19:26:12 +00:00
|
|
|
extern int filter_Show(struct cmdargs const *);
|
|
|
|
extern int filter_Set(struct cmdargs const *);
|
1998-04-03 19:25:07 +00:00
|
|
|
extern const char * filter_Action2Nam(int);
|
|
|
|
extern const char *filter_Proto2Nam(int);
|
|
|
|
extern const char *filter_Op2Nam(int);
|
1999-01-28 01:56:34 +00:00
|
|
|
extern struct in_addr bits2mask(int);
|
1999-05-31 23:57:40 +00:00
|
|
|
extern void filter_AdjustAddr(struct filter *, struct in_addr *,
|
|
|
|
struct in_addr *);
|