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