A logical expression consists of one or more operations. An operation may consist of one or two operands and an operator, such as
ETH:DLC.DA = 01:23:45:67:89:ABwhere ETH:DLC.DA and 01:23:45:67:89:AB are the operands, and the equals symbol (=) operator indicates the purpose of the operation (to compare the variable ETH:DLC.DA to the constant 01:23:45:67:89:AB for equality). When evaluated using actual data to substitute for the variable operand, this expression will evaluate to true or false.
Alternatively, an operation may be self contained, as in the case of a user function. For example,
@pattern('Some text to look for', A)A user function is evaluated as an atomic operation which returns true or false. The value returned depends upon the purpose of the user function. In this example, the function will return true if the trace record being tested contains the ASCII byte pattern 'Some text to look for' (not including the single quotation marks).
A logical expression may be comprised of the following elements:
Expression | Purpose |
TOK:DLC.DA = FF:FF:FF:FF:FF:FF | Evaluates to true if the trace record being tested is a Token Ring frame whose destination MAC address is the broadcast address FF:FF:FF:FF:FF:FF. |
CAP:FL >= 1024 | Evaluates to true if the trace record being tested is a DatagLANce or Sniffer frame whose length is greater than or equal to 1024 bytes. |
@protocol(TCP) | Evaluates to true if the trace record being tested contains a TCP frame. |
@protocol(TCP) or @protocol(UDP) | Evaluates to true if the trace record being tested contains either a TCP frame or a UDP frame. |
A simple expression consists of a single unary or binary logical operation. A unary logical operation has a single operand and, optionally, a logical unary operator. A binary operation has two operands and a logical binary operator. Whether unary or binary, the logical expression must still evaluate to true or false.
Table 2 contains some examples of simple filter expressions.
Expression | Unary/Binary |
TOK:DLC.DA = FF:FF:FF:FF:FF:FF | Binary |
CAP:FL >= 1024 | Binary |
@protocol(TCP) | Unary |
!(@filter('TCP Frames')) | Unary |
A compound expression consists of two or more simple expressions joined together using the logical operators and (&&) or or (||). Simple expressions may be multiply nested to form complex compound expressions, using parentheses (()) to group operations by precedence. Each component expression unit within a compound expression is referred to as a subexpression. Subexpressions may be simple unary or binary expressions, or might be nested compound expressions.
Table 3 contains some examples of compound filter expressions.
Expression | # of Operations |
(TOK:DLC.DA = FF:FF:FF:FF:FF:FF) or (CAP:FL >= 1024) |
|
@protocol(TCP) or @protocol(UDP) |
|
(CAP:FL >= 1024) and ((@protocol(TCP) or @protocol(UDP)) |
|
Finally, a filter expression may have arithmetic or bitwise operations embedded within. For instance,
CAP:FL % 100 = 0could be used to determine which DatagLANce or Sniffer records have lengths that are multiples of 100. In such cases, the arithmetic or bitwise operation generally is evaluated before the logical test is applied (see the Operators section for specifics on operator precedence).
It should be noted that although arithmetic or
bitwise subexpressions are permissible, the overall filter expression must
be constructed in such a way as to ensure that it will be evaluated to
produce a boolean result: true or false. Expressions
which do not meet this requirement are not valid. Thus, when creating
compound expressions containing arithmetic subexpressions, the use of parentheses
and an understanding of operator precedence is
critical.
When a filter is applied to a trace record, the data which is associated
with a protocol field ID in the filter expression, if any, is extracted
from the appropriate offset in the record. The actual data for that
protocol field ID is substituted into the expression and the expression
is evaluated.
The set of operators which may be used within filter expressions is listed in Table 4. Operators in this table are listed in order of their precedence, from those evaluated first to those evaluated last. Operators which have the same precedence are grouped together. When evaluating operations whose operators have the same precedence, the program will evaluate the operations in the order in which they appear, from left to right. Parentheses (()) may be used to group operations which must be evaluated in a different order.
Precedence | Symbol | Type | Unary/Binary | Operation Performed |
|
|
Logical | Unary | Logical complement |
|
|
Bitwise | Binary | Bitwise complement |
|
|
Arithmetic | Binary | Multiplication |
|
Arithmetic | Binary | Division | |
|
Arithmetic | Binary | Remainder | |
|
|
Arithmetic | Binary | Addition |
|
Arithmetic | Binary | Subtraction | |
5 |
|
Bitwise | Binary | Left shift |
|
Bitwise | Binary | Right shift w/ sign extension | |
|
Bitwise | Binary | Right shift w/ zero extension | |
6 |
|
Logical | Binary | Is less than |
|
Logical | Binary | Is less than or equal to | |
|
Logical | Binary | Is greater than | |
|
Logical | Binary | Is greater than or equal to | |
7 |
|
Logical | Binary | Is equal to |
|
Logical | Binary | Is not equal to | |
|
|
Bitwise | Binary | Bitwise AND |
|
|
Bitwise | Binary | Bitwise XOR |
|
|
Bitwise | Binary | Bitwise OR |
|
|
Logical | Binary | Conditional AND |
|
|
Logical | Binary | Conditional OR |
This treatment of the above expression seems fairly intuitive. However, it should be noted that the expression
It is important to keep in mind the subtleties of how unresolved variables
are handled when designing your filter expressions.
The syntax of a user function varies from function to function, but is always of the general form
@function_name(arg_1[, arg_2...arg_N])where:
Function Name | Purpose |
filter | Embed a filter within another filter |
in | Test the data within a protocol field for a match against a list of constants |
isnull | Test for the presence of a specific data field within a record |
manuf | Test whether a network MAC address indicates a particular network adapter manufacturer |
pattern | Test for a specific byte pattern within a record |
protocol | Test for the presence of a specific protocol within a record |