filter.h revision 225736
1254721Semaste/*-
2254721Semaste * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
3254721Semaste *          based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
4254721Semaste *                           Internet Initiative Japan, Inc (IIJ)
5254721Semaste * All rights reserved.
6254721Semaste *
7254721Semaste * Redistribution and use in source and binary forms, with or without
8254721Semaste * modification, are permitted provided that the following conditions
9254721Semaste * are met:
10254721Semaste * 1. Redistributions of source code must retain the above copyright
11254721Semaste *    notice, this list of conditions and the following disclaimer.
12254721Semaste * 2. Redistributions in binary form must reproduce the above copyright
13254721Semaste *    notice, this list of conditions and the following disclaimer in the
14254721Semaste *    documentation and/or other materials provided with the distribution.
15254721Semaste *
16254721Semaste * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17254721Semaste * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18254721Semaste * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19254721Semaste * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20254721Semaste * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21254721Semaste * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22254721Semaste * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23254721Semaste * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24254721Semaste * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25254721Semaste * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26254721Semaste * SUCH DAMAGE.
27254721Semaste *
28254721Semaste * $FreeBSD: stable/9/usr.sbin/ppp/filter.h 134789 2004-09-05 01:46:52Z brian $
29254721Semaste */
30254721Semaste
31254721Semaste/* Operations - f_srcop, f_dstop */
32254721Semaste#define	OP_NONE	0
33254721Semaste#define	OP_EQ	1
34254721Semaste#define	OP_GT	2
35254721Semaste#define	OP_LT	3
36254721Semaste
37254721Semaste/* srctype or dsttype */
38254721Semaste#define T_ADDR		0
39254721Semaste#define T_MYADDR	1
40254721Semaste#define T_MYADDR6	2
41254721Semaste#define T_HISADDR	3
42254721Semaste#define T_HISADDR6	4
43254721Semaste#define T_DNS0		5
44254721Semaste#define T_DNS1		6
45254721Semaste
46254721Semaste/*
47254721Semaste * There's a struct filterent for each possible filter rule.  The
48254721Semaste * layout is designed to minimise size (there are 4 * MAXFILTERS of
49254721Semaste * them) - which is also conveniently a power of 2 (32 bytes) on
50262528Semaste * architectures where sizeof(int)==4 (this makes indexing faster).
51254721Semaste *
52254721Semaste * Note that there are four free bits in the initial word for future
53254721Semaste * extensions.
54254721Semaste */
55262528Semastestruct filterent {
56254721Semaste  int f_proto;			/* Protocol: getprotoby*() */
57254721Semaste  unsigned f_action : 8;	/* Filtering action: goto or A_... */
58254721Semaste  unsigned f_srcop : 2;		/* Source port operation: OP_... */
59254721Semaste  unsigned f_dstop : 2;		/* Destination port operation: OP_... */
60254721Semaste  unsigned f_srctype : 3;	/* T_ value of src */
61262528Semaste  unsigned f_dsttype : 3;	/* T_ value of dst */
62262528Semaste  unsigned f_estab : 1;		/* Check TCP ACK bit */
63262528Semaste  unsigned f_syn : 1;		/* Check TCP SYN bit */
64262528Semaste  unsigned f_finrst : 1;	/* Check TCP FIN/RST bits */
65262528Semaste  unsigned f_invert : 1;	/* true to complement match */
66262528Semaste  struct ncprange f_src;	/* Source address and mask */
67262528Semaste  struct ncprange f_dst;	/* Destination address and mask */
68262528Semaste  u_short f_srcport;		/* Source port, compared with f_srcop */
69262528Semaste  u_short f_dstport;		/* Destination port, compared with f_dstop */
70262528Semaste  unsigned timeout;		/* Keep alive value for passed packet */
71262528Semaste};
72262528Semaste
73262528Semaste#define	MAXFILTERS	40	/* in each filter set */
74262528Semaste
75262528Semaste/* f_action values [0..MAXFILTERS) specify the next filter rule, others are: */
76262528Semaste#define	A_NONE		(MAXFILTERS)
77262528Semaste#define	A_PERMIT	(A_NONE+1)
78262528Semaste#define	A_DENY		(A_PERMIT+1)
79262528Semaste
80262528Semastestruct filter {
81262528Semaste  struct filterent rule[MAXFILTERS];	/* incoming packet filter */
82254721Semaste  const char *name;
83254721Semaste  unsigned fragok : 1;
84254721Semaste  unsigned logok : 1;
85254721Semaste};
86254721Semaste
87254721Semaste/* Which filter set */
88258884Semaste#define FL_IN		0
89254721Semaste#define FL_OUT		1
90254721Semaste#define FL_DIAL		2
91258884Semaste#define FL_KEEP		3
92258884Semaste
93258884Semastestruct ipcp;
94258884Semastestruct cmdargs;
95258884Semaste
96258884Semasteextern int filter_Show(struct cmdargs const *);
97258884Semasteextern int filter_Set(struct cmdargs const *);
98254721Semasteextern const char * filter_Action2Nam(unsigned);
99254721Semasteextern const char *filter_Op2Nam(unsigned);
100254721Semasteextern void filter_AdjustAddr(struct filter *, struct ncpaddr *,
101254721Semaste                              struct ncpaddr *, struct in_addr *);
102254721Semaste