1 /*
2  * Copyright (c) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3  *               2002, 2003, 2004
4  *	Ohio University.
5  *
6  * ---
7  *
8  * Starting with the release of tcptrace version 6 in 2001, tcptrace
9  * is licensed under the GNU General Public License (GPL).  We believe
10  * that, among the available licenses, the GPL will do the best job of
11  * allowing tcptrace to continue to be a valuable, freely-available
12  * and well-maintained tool for the networking community.
13  *
14  * Previous versions of tcptrace were released under a license that
15  * was much less restrictive with respect to how tcptrace could be
16  * used in commercial products.  Because of this, I am willing to
17  * consider alternate license arrangements as allowed in Section 10 of
18  * the GNU GPL.  Before I would consider licensing tcptrace under an
19  * alternate agreement with a particular individual or company,
20  * however, I would have to be convinced that such an alternative
21  * would be to the greater benefit of the networking community.
22  *
23  * ---
24  *
25  * This file is part of Tcptrace.
26  *
27  * Tcptrace was originally written and continues to be maintained by
28  * Shawn Ostermann with the help of a group of devoted students and
29  * users (see the file 'THANKS').  The work on tcptrace has been made
30  * possible over the years through the generous support of NASA GRC,
31  * the National Science Foundation, and Sun Microsystems.
32  *
33  * Tcptrace is free software; you can redistribute it and/or modify it
34  * under the terms of the GNU General Public License as published by
35  * the Free Software Foundation; either version 2 of the License, or
36  * (at your option) any later version.
37  *
38  * Tcptrace is distributed in the hope that it will be useful, but
39  * WITHOUT ANY WARRANTY; without even the implied warranty of
40  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
41  * General Public License for more details.
42  *
43  * You should have received a copy of the GNU General Public License
44  * along with Tcptrace (in the file 'COPYING'); if not, write to the
45  * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
46  * MA 02111-1307 USA
47  *
48  * Author:	Shawn Ostermann
49  * 		School of Electrical Engineering and Computer Science
50  * 		Ohio University
51  * 		Athens, OH
52  *		ostermann@cs.ohiou.edu
53  *		http://www.tcptrace.org/
54  */
55 static char const GCC_UNUSED rcsid_filter[] =
56     "@(#)$Header$";
57 
58 
59 /* all of the variable types that we understand */
60 enum vartype {
61     V_ULONG	= 1,
62     V_LONG	= 2,
63     V_UINT	= 3,
64     V_INT	= 4,
65     V_USHORT	= 5,
66     V_SHORT	= 6,
67     V_UCHAR	= 7,
68     V_CHAR	= 8,
69     V_BOOL	= 9,
70     V_STRING	= 10,
71     V_ULLONG	= 11,
72     V_LLONG	= 12,
73     V_IPADDR	= 13,
74 
75     /* functions */
76     V_FUNC	=14,		/* function returning unsigned */
77     V_UFUNC	=15		/* function returning signed */
78 };
79 
80 
81 
82 /* all of the operations that we understand */
83 enum optype {
84     /* just a constant */
85     OP_CONSTANT	  = 101,
86 
87     /* a variable */
88     OP_VARIABLE	  = 102,
89 
90     /* BINARY OPs */
91     OP_AND	  = 103,
92     OP_OR	  = 104,
93     OP_EQUAL	  = 105,
94     OP_NEQUAL	  = 106,
95     OP_GREATER	  = 107,
96     OP_GREATER_EQ = 108,
97     OP_LESS	  = 109,
98     OP_LESS_EQ	  = 110,
99 
100     /* Unary OPs */
101     OP_NOT	  = 111,
102     OP_SIGNED	  = 112,	/* convert unsigned to signed */
103 
104     /* binary arithmetic */
105     OP_PLUS	  = 113,
106     OP_MINUS	  = 114,
107     OP_TIMES	  = 115,
108     OP_DIVIDE	  = 116,
109     OP_MOD	  = 117,
110 
111     /* bitwise arithmetic */
112     OP_BAND	  = 118,
113     OP_BOR	  = 119
114 };
115 
116 
117 /* Constant -- just a big union based on the type */
118 union Constant {
119     u_llong	u_longint;
120     llong	longint;
121     Bool	bool;
122     char	*string;
123     ipaddr	*pipaddr;
124 };
125 
126 /* Variable - keep the name and offset within a tcp_pair */
127 struct Variable {
128     char 	*name;
129     u_long 	offset;
130     Bool	fclient;	/* from the client or server side? */
131     enum vartype realtype;
132 };
133 
134 /* Binary - binary operation */
135 struct Binary {
136     struct filter_node *left;
137     struct filter_node *right;
138 };
139 
140 /* Unary - unary operations */
141 struct Unary {
142     struct filter_node *pf;
143 };
144 
145 
146 struct filter_node {
147     enum optype op;		/* node type */
148     enum vartype vartype;	/* type of the result */
149     union {
150 	struct Unary unary;
151 	struct Binary binary;
152 	struct Variable variable;
153 	union Constant constant;
154     } un;
155     Bool conjunction;
156     struct filter_node *next_var; /* for wildcard variable matches */
157 };
158 
159 
160 /* the result of executing a filter node */
161 struct filter_res {
162     enum vartype vartype;
163     union Constant val;
164 };
165 
166 
167 /* just a big table of things that we can filter on */
168 struct filter_line {
169     char	*varname;	/* name of the variable to match */
170     enum vartype vartype;	/* type of the variable */
171     void 	*cl_addr;	/* address when in client */
172     void 	*sv_addr;	/* address when in server */
173     char	*descr;		/* brief description */
174 };
175 
176 
177 
178 /* filter globals */
179 extern int filtyydebug;
180 
181 
182 /* externals */
183 int filtyylex(void);
184 int filtyyparse(void);
185 void filtyyerror(char *error_string, ...);
186 void InstallFilter(struct filter_node *root);
187 int filter_getc();
188 void PrintFilter(struct filter_node *pn);
189 char *Filter2Str(struct filter_node *pn);
190 
191 struct filter_node *MakeUnaryNode(enum optype op, struct filter_node *pf);
192 struct filter_node *MakeBinaryNode(enum optype op, struct filter_node *pf_left, struct filter_node *pf_right);
193 struct filter_node *MakeVarNode(char *varname);
194 struct filter_node *MakeStringConstNode(char *val);
195 struct filter_node *MakeBoolConstNode(Bool val);
196 struct filter_node *MakeSignedConstNode(llong val);
197 struct filter_node *MakeUnsignedConstNode(u_llong val);
198 struct filter_node *MakeIPaddrConstNode(ipaddr *pipaddr);
199 
200 /* functions for calculated values */
201 u_llong VFuncClntTput(tcp_pair *ptp);
202 u_llong VFuncServTput(tcp_pair *ptp);
203 
204 
205 
206