xref: /freebsd/usr.sbin/ppp/filter.h (revision 0a4b6c5c)
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  * $FreeBSD$
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 #ifdef IPPROTO_OSPFIGP
29 #define	P_OSPF	4
30 #endif
31 #define	P_IGMP	5
32 #ifdef IPPROTO_GRE
33 #define P_GRE   6
34 #endif
35 
36 /* Operations - f_srcop, f_dstop */
37 #define	OP_NONE	0
38 #define	OP_EQ	1
39 #define	OP_GT	2
40 #define	OP_LT	3
41 
42 /* srctype or dsttype */
43 #define T_ADDR		0
44 #define T_MYADDR	1
45 #define T_HISADDR	2
46 #define T_DNS0		3
47 #define T_DNS1		4
48 
49 /*
50  * There's a struct filterent for each possible filter rule.  The
51  * layout is designed to minimise size (there are 4 * MAXFILTERS of
52  * them) - which is also conveniently a power of 2 (32 bytes) on
53  * architectures where sizeof(int)==4 (this makes indexing faster).
54  *
55  * f_action and f_proto only need to be 6 and 3 bits, respectively,
56  * but making them 8 bits allows them to be efficently accessed using
57  * byte operations as well as allowing space for future expansion
58  * (expanding MAXFILTERS or converting f_proto IPPROTO_... values).
59  *
60  * Note that there are four free bits in the initial word for future
61  * extensions.
62  */
63 struct filterent {
64   unsigned f_action : 8;		/* Filtering action: goto or A_... */
65   unsigned f_proto : 8;		/* Protocol: P_... */
66   unsigned f_srcop : 2;		/* Source port operation: OP_... */
67   unsigned f_dstop : 2;		/* Destination port operation: OP_... */
68   unsigned f_srctype : 3;	/* T_ value of src */
69   unsigned f_dsttype : 3;	/* T_ value of dst */
70   unsigned f_estab : 1;		/* Check TCP ACK bit */
71   unsigned f_syn : 1;		/* Check TCP SYN bit */
72   unsigned f_finrst : 1;	/* Check TCP FIN/RST bits */
73   unsigned f_invert : 1;	/* true to complement match */
74   struct in_range f_src;	/* Source address and mask */
75   struct in_range f_dst;	/* Destination address and mask */
76   u_short f_srcport;		/* Source port, compared with f_srcop */
77   u_short f_dstport;		/* Destination port, compared with f_dstop */
78   unsigned timeout;		/* Keep alive value for passed packet */
79 };
80 
81 #define	MAXFILTERS	40	/* in each filter set */
82 
83 /* f_action values [0..MAXFILTERS) specify the next filter rule, others are: */
84 #define	A_NONE		(MAXFILTERS)
85 #define	A_PERMIT	(A_NONE+1)
86 #define	A_DENY		(A_PERMIT+1)
87 
88 struct filter {
89   struct filterent rule[MAXFILTERS];	/* incoming packet filter */
90   const char *name;
91   unsigned fragok : 1;
92   unsigned logok : 1;
93 };
94 
95 /* Which filter set */
96 #define FL_IN		0
97 #define FL_OUT		1
98 #define FL_DIAL		2
99 #define FL_KEEP		3
100 
101 struct ipcp;
102 struct cmdargs;
103 
104 extern int ParseAddr(struct ipcp *, const char *, struct in_addr *,
105                      struct in_addr *, int *);
106 extern int filter_Show(struct cmdargs const *);
107 extern int filter_Set(struct cmdargs const *);
108 extern const char * filter_Action2Nam(int);
109 extern const char *filter_Proto2Nam(int);
110 extern const char *filter_Op2Nam(int);
111 extern struct in_addr bits2mask(int);
112 extern void filter_AdjustAddr(struct filter *, struct in_addr *,
113                               struct in_addr *, struct in_addr [2]);
114