xref: /freebsd/usr.sbin/ppp/filter.h (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
5  *          based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
6  *                           Internet Initiative Japan, Inc (IIJ)
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * $FreeBSD$
31  */
32 
33 /* Operations - f_srcop, f_dstop */
34 #define	OP_NONE	0
35 #define	OP_EQ	1
36 #define	OP_GT	2
37 #define	OP_LT	3
38 
39 /* srctype or dsttype */
40 #define T_ADDR		0
41 #define T_MYADDR	1
42 #define T_MYADDR6	2
43 #define T_HISADDR	3
44 #define T_HISADDR6	4
45 #define T_DNS0		5
46 #define T_DNS1		6
47 
48 /*
49  * There's a struct filterent for each possible filter rule.  The
50  * layout is designed to minimise size (there are 4 * MAXFILTERS of
51  * them) - which is also conveniently a power of 2 (32 bytes) on
52  * architectures where sizeof(int)==4 (this makes indexing faster).
53  *
54  * Note that there are four free bits in the initial word for future
55  * extensions.
56  */
57 struct filterent {
58   int f_proto;			/* Protocol: getprotoby*() */
59   unsigned f_action : 8;	/* Filtering action: goto or A_... */
60   unsigned f_srcop : 2;		/* Source port operation: OP_... */
61   unsigned f_dstop : 2;		/* Destination port operation: OP_... */
62   unsigned f_srctype : 3;	/* T_ value of src */
63   unsigned f_dsttype : 3;	/* T_ value of dst */
64   unsigned f_estab : 1;		/* Check TCP ACK bit */
65   unsigned f_syn : 1;		/* Check TCP SYN bit */
66   unsigned f_finrst : 1;	/* Check TCP FIN/RST bits */
67   unsigned f_invert : 1;	/* true to complement match */
68   struct ncprange f_src;	/* Source address and mask */
69   struct ncprange f_dst;	/* Destination address and mask */
70   u_short f_srcport;		/* Source port, compared with f_srcop */
71   u_short f_dstport;		/* Destination port, compared with f_dstop */
72   unsigned timeout;		/* Keep alive value for passed packet */
73 };
74 
75 #define	MAXFILTERS	40	/* in each filter set */
76 
77 /* f_action values [0..MAXFILTERS) specify the next filter rule, others are: */
78 #define	A_NONE		(MAXFILTERS)
79 #define	A_PERMIT	(A_NONE+1)
80 #define	A_DENY		(A_PERMIT+1)
81 
82 struct filter {
83   struct filterent rule[MAXFILTERS];	/* incoming packet filter */
84   const char *name;
85   unsigned fragok : 1;
86   unsigned logok : 1;
87 };
88 
89 /* Which filter set */
90 #define FL_IN		0
91 #define FL_OUT		1
92 #define FL_DIAL		2
93 #define FL_KEEP		3
94 
95 struct ipcp;
96 struct cmdargs;
97 
98 extern int filter_Show(struct cmdargs const *);
99 extern int filter_Set(struct cmdargs const *);
100 extern const char * filter_Action2Nam(unsigned);
101 extern const char *filter_Op2Nam(unsigned);
102 extern void filter_AdjustAddr(struct filter *, struct ncpaddr *,
103                               struct ncpaddr *, struct in_addr *);
104