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