xref: /illumos-gate/usr/src/uts/common/sys/pfmod.h (revision 2d6eb4a5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_PFMOD_H
27 #define	_SYS_PFMOD_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 /*
34  * Ioctls.
35  */
36 #define	PFIOC		('P' << 8)
37 #define	PFIOCSETF	(PFIOC|1)	/* replace current packet filter */
38 
39 #define	ENMAXFILTERS	255		/* maximum filter short words */
40 #define	PF_MAXFILTERS	2047		/* max short words for newpacketfilt */
41 
42 /*
43  * filter structure for SETF
44  */
45 struct packetfilt {
46 	uchar_t	Pf_Priority;			/* priority of filter */
47 	uchar_t Pf_FilterLen;			/* length of filter cmd list */
48 	ushort_t Pf_Filter[ENMAXFILTERS];	/* filter command list */
49 };
50 
51 /*
52  * The extended packet filter structure
53  */
54 struct Pf_ext_packetfilt {
55 	uchar_t	Pf_Priority;			/* priority of filter */
56 	unsigned int Pf_FilterLen;		/* length of filter cmd list */
57 	ushort_t Pf_Filter[PF_MAXFILTERS];	/* filter command list */
58 };
59 
60 /*
61  * We now allow specification of up to MAXFILTERS (short) words of a filter
62  * command list to be applied to incoming packets to determine if
63  * those packets should be given to a particular open ethernet file.
64  * Alternatively, PF_MAXFILTERS and Pf_ext_packetfilt structure can be
65  * used in case even bigger filter command list is needed.
66  *
67  * In this context, "word" means a short (16-bit) integer.
68  *
69  * The filter command list is specified using ioctl().  Each filter command
70  * list specifies a sequence of actions that leaves a boolean value on the
71  * top of an internal stack.  There is also an offset register which is
72  * initialized to zero.  Each word of the command list specifies an action
73  * from the set {PUSHLIT, PUSHZERO, PUSHWORD+N, LOAD_OFFSET, BRTR, BRFL, POP}
74  * (see #defines below for definitions), and a binary operator from the set
75  * {EQ, LT, LE, GT, GE, AND, OR, XOR} which operates on the top two elements
76  * of the stack and replaces them with its result.  The special action NOPUSH
77  * and the special operator NOP can be used to only perform the binary
78  * operation or to only push a value on the stack.
79  *
80  * If the final value of the filter operation is true, then the packet is
81  * accepted for the open file which specified the filter.
82  */
83 
84 /* these must sum to sizeof (ushort_t)! */
85 #define	ENF_NBPA	10			/* # bits / action */
86 #define	ENF_NBPO	 6			/* # bits / operator */
87 
88 /* binary operators */
89 #define	ENF_NOP		(0 << ENF_NBPA)
90 #define	ENF_EQ		(1 << ENF_NBPA)
91 #define	ENF_LT		(2 << ENF_NBPA)
92 #define	ENF_LE		(3 << ENF_NBPA)
93 #define	ENF_GT		(4 << ENF_NBPA)
94 #define	ENF_GE		(5 << ENF_NBPA)
95 #define	ENF_AND		(6 << ENF_NBPA)
96 #define	ENF_OR		(7 << ENF_NBPA)
97 #define	ENF_XOR		(8 << ENF_NBPA)
98 #define	ENF_COR		(9 << ENF_NBPA)
99 #define	ENF_CAND	(10 << ENF_NBPA)
100 #define	ENF_CNOR	(11 << ENF_NBPA)
101 #define	ENF_CNAND	(12 << ENF_NBPA)
102 #define	ENF_NEQ		(13 << ENF_NBPA)
103 
104 /* stack actions */
105 #define	ENF_NOPUSH	0
106 #define	ENF_PUSHLIT	1  /* Push the next word on the stack */
107 #define	ENF_PUSHZERO	2  /* Push 0 on the stack */
108 #define	ENF_PUSHONE	3  /* Push 1 on the stack */
109 #define	ENF_PUSHFFFF	4  /* Push 0xffff on the stack */
110 #define	ENF_PUSHFF00	5  /* Push 0xff00 on the stack */
111 #define	ENF_PUSH00FF	6  /* Push 0x00ff on the stack */
112 #define	ENF_LOAD_OFFSET	7  /* Load the next word into the offset register */
113 #define	ENF_BRTR	8  /* Branch if the stack's top element is true */
114 #define	ENF_BRFL	9  /* Branch if the stack's top element is false */
115 #define	ENF_POP		10 /* Pop the top element from the stack */
116 #define	ENF_PUSHWORD	16
117 
118 #ifdef	__cplusplus
119 }
120 #endif
121 
122 #endif	/* _SYS_PFMOD_H */
123