Commit Graph

37 Commits

Author SHA1 Message Date
Gilbert Ramirez 6a20c7bbc5 Add "class" that understands IPv4 addresses and subnet masks.
We now store IPv4 addresses in host order, allowing non-equivalence
comparisons. That is, display filters with lt, le, gt, and ge will work
on big-endian and little-endian machines.

CIDR notation is now supported for IPv4 addresses in display filters.
You can test to see if an IPv4 address is on a certain subnet by using
this notation. For example, to test for IPv4 packets on a Class-C network:

	ip.addr == 192.168.1.0/24

svn path=/trunk/; revision=1032
1999-11-15 06:32:38 +00:00
Gilbert Ramirez a5b7e70a3e Enable display filtering on FT_DOUBLE fields.
svn path=/trunk/; revision=886
1999-10-19 05:31:14 +00:00
Gilbert Ramirez 997cff3aba Get rid of difference between T_VAL_NUMBER_STRING and
T_VAL_UNQUOTED string in order to fix parsing problem (single digit number
vs. multiple digit numbers). T_VAL_NUMBER_STRING no longer exists.

svn path=/trunk/; revision=877
1999-10-17 20:54:56 +00:00
Laurent Deniel 6b297846bb Remove no longer needed comment.
svn path=/trunk/; revision=875
1999-10-17 14:15:06 +00:00
Gilbert Ramirez ba5c767643 Fixed elem_size in ipv6-related dfilter_mknode() functions. Fixing this
makes arrays of ipv6 addressess correct, so that we can now filter on both
ipv6 headers in a tunnelled packet.

Removed ipv6_str_to_guint8_array() which was no longer used.

Fixed compiler warning regarding 2nd arg call to get_host_ipaddr6().

svn path=/trunk/; revision=846
1999-10-15 20:46:02 +00:00
Jun-ichiro itojun Hagino 9558d96859 use proto_tree_add_item() for IPv6 header, to allow filtering like below
possible.
	ipv6.nxt == 17
	ipv6.dst == ff02::9
	ipv6.src[0:2] == fe:80

modify dfilter lexical rule to allow standard IPv6 expression to be
passed up to parser.

XXX backward compat issue in lex rule, maybe
XXX IPv6 has chained headers.  how will dfilter behave when we have
multiple protocol header of the same type?
XXX ipv6.nxt is not really useful due to IPv6 chained header.  we need a
symbol to identify "final" protocol type on the chain (testing ipv6.final
but will SEGV).

svn path=/trunk/; revision=836
1999-10-15 04:22:48 +00:00
Guy Harris 154265bd94 Put back the "%expect 4" that I accidentally deleted.
svn path=/trunk/; revision=832
1999-10-14 08:05:51 +00:00
Guy Harris 98ce0fcfab Fix the
Field "XXX" has N byte[s] being compared, but M byte[s] were
	supplied.

and the

	The "XXX" field is only N byte[s] wide, but M byte[s] were
	supplied.

messages to have "was supplied" if M is 1.

svn path=/trunk/; revision=821
1999-10-13 06:01:04 +00:00
Gilbert Ramirez bacb9d5bae New proto_tree header_field_info stuff. Header_field_infos now contain
the base for numbers to be displayed in, bitmasks for bitfields, and blurbs
(which are one or two sentences describing the field).

proto_tree_add*() routines now automatically handle bitfields. You tell
it which header field you are adding, and just pass it the value of the
entire field, and the proto_tree routines will do the masking and shifting
for you.

This means that bitfields are more naturally filtered via dfilter now.

Added Phil Techau's support for signed integers in dfilters/proto_tree.

Added the beginning of the SNA dissector. It's not complete, but I'm
committing it now because it has example after example of how to use
bitfields with the new header_field_info struct and proto_tree routines.
It was the impetus to change how header_field_info works.

svn path=/trunk/; revision=815
1999-10-12 06:21:15 +00:00
Gilbert Ramirez 10c4bab8e1 The 4 shift/reduce conflicts have to do with the associativity of the
logical operators, e.g.:
	NOT expression AND expression
	expression AND expression AND expression

etc. The shift/reduce conflicts _are_resolved (according to the output
from bison -v), so the conflicts seem to be benign.

Right now I marked the 4 shift/reduce conflicts as expected, but perhaps
someone more knowledgable about yacc grammars could take a look at it?

svn path=/trunk/; revision=814
1999-10-12 05:21:07 +00:00
Guy Harris 99e8c65674 In "string_to_value()", make sure the number is valid.
svn path=/trunk/; revision=813
1999-10-12 05:13:32 +00:00
Gilbert Ramirez 1efcb7b2cf Re-implemented fix to keep display filter from reading data from outside
the packet boundary. Now the field boundary is honored. The frame boundary
is ignored, but of course we put proper field lengths in the proto_tree,
right? :)

Implemented negative offsets in byte-strings:
	frame[-4:4] will read the last 4 bytes of a frame.

Implemented "offset-only" byte-string comparisons, since the dfilter
compiler knows the length of the byte-string you supplied. These are
now legal:
	frame[-4] == 0.0.0.1
	tr.dst[0] == 00:06:29

Implemented the use of integers if you're comparing one byte. These are
legal:
	llc[0] == 0xaa
	llc[0:1] == 0xaa

All these forms check against the length of the field, so these will be
reported as bad to the user:
	eth.src[5] == 00:06:29      (goes beyond field boundary)
	eth.dst == 1.2.3.4.5.6.7    (too long, goes beyond field boundary)

Thes is also reported as bad:
	eth.dst[0:3] == 1.2          (incorrect number of bytes specified)
	eth.dst[0:1] == eth.src[0:2] (disparate lengths)

I had to add a new function, proto_registrar_get_length() in proto.c, which
reports the length of a field as can be determined at registration time.

There are some shift/reduce errors in the grammar that I need to get rid of.

svn path=/trunk/; revision=811
1999-10-12 04:21:13 +00:00
Guy Harris 0faf733914 The answer to the question
(Is there a better way to force a parse to fail from arbitrary
	places in routines called by the parser?)

asked in an earlier checkin is "yes", which would've been obvious had I
seen the code that handles MAC addresses, as it returns NULL on an
error, and the YACC clause checks for a null return value and, if the
return value is null, uses YYERROR to make the parse fail.

Use that for IPv4 and IPv6 errors.

Also, use "dfilter_fail()" for the MAC address code.

svn path=/trunk/; revision=810
1999-10-11 19:39:29 +00:00
Laurent Deniel 2e08b800b4 - add handling of FT_IPv6 variables
there is still some work to do in resolv.c (get_host_ipaddr6)

- add display filters of this kind in packet-ipv6.c just
  for testing (display filtering is incomplete)

svn path=/trunk/; revision=808
1999-10-11 17:05:49 +00:00
Guy Harris 6b5159e8de Solaris 7 (and perhaps other OSes) lack INADDR_NONE; it doesn't matter
what we set "node->value.numeric" to if we failed to convert a string to
an IP address (that failure means "dfilter_compile()" will throw the
filter away and return NULL), so just set it to 0.

svn path=/trunk/; revision=804
1999-10-11 07:06:43 +00:00
Guy Harris 3b9013d393 When a new display filter is to be applied, don't set "cf.dfilter" or
"cf.dfcode" if the new filter doesn't compile, because the filter
currently in effect will be the one that was last applied - just free up
the text of the new filter, and whatever memory was allocated for the
new filter code.

This means we allocate a new dfilter when a new filter is to be applied,
rather than recycling stuff from the old filter, as we want the old
filter code to remain around if the new filter doesn't compile.

This means that "cf.dfilter" and "cf.dfcode" will be null if there's no
filter in effect.

svn path=/trunk/; revision=803
1999-10-11 06:39:26 +00:00
Guy Harris 29b9c8a285 Have "get_host_ipaddr()" return a Boolean indicating whether it
succeeded or failed, and, if it succeeded, have it fill in the IP
address if found through a pointer passed as the second argument.

Have it first try interpreting its first argument as a dotted-quad IP
address, with "inet_aton()", and, if that fails, have it try to
interpret it as a host name with "gethostbyname()"; don't bother with
"gethostbyaddr()", as we should be allowed to filter on IP addresses
even if there's no host name associated with them (there's no guarantee
that "gethostbyaddr()" will succeed if handed an IP address with no
corresponding name - and it looks as if FreeBSD 3.2, at least, may not
succeed in that case).

Add a "dfilter_fail()" routine that takes "printf()"-like arguments and
uses them to set an error message for the parse; doing so means that
even if the filter expression is syntactically valid, we treat it as
being invalid.  (Is there a better way to force a parse to fail from
arbitrary places in routines called by the parser?)

Use that routine in the lexical analyzer.

If that error message was set, use it as is as the failure message,
rather than adding "Unable to parse filter string XXX" to it.

Have the code to handle IP addresses and host names in display filters
check whether "get_host_ipaddr()" succeeded or failed and, if it failed,
arrange that the parse fail with an error message indicating the source
of the problem.

svn path=/trunk/; revision=802
1999-10-11 03:03:12 +00:00
Guy Harris 361fcf26e9 Make "dfilter_error()" available to the lexical analyzer.
Get rid of the declaration of the non-existent "dfilter_yyerror()", and
put in some #defines to work around the fact that the #defines to
replace "yy" with "dfilter_" in the names of Flex-generated and
Yacc-generated routines aren't put into a header file, they're put into
".c" files.

Have it remember the error message it was handed (unless it's Yacc's
boring "parse error" message).

When generating the message to be shown to the user on a parse error,
make it be the "Unable to parse filter string" message, and, if a
non-boring error message was supplied to "dfilter_error()", take that
error message onto the end.

Don't panic if a field type we don't yet support in the parser is seen;
generate an error, telling the user we don't support filter on that type
yet.

Don't assume that "global_df" has been set if we see an empty statement
(if the first token was the end-marker, because, say, the first token
the lexical analyzer found was a field of a type not yet supported in
filter expressions, "global_df" won't have been set).

svn path=/trunk/; revision=783
1999-10-07 21:47:20 +00:00
Gilbert Ramirez 7b732a9f80 Fixed assert error reported by Dewi Morgan <dewim@sco.com>.
After some bad dfilter parses, the top-level dfilter tree (global_df->dftree)
would erroneously be set to the last good dfilter_node that was parsed.
Later, the non-NULLness of the dftree made us clear it.. really confusing
GTK internals. After _that_, new GNodes created via g_node_new() would
all have the same address!

svn path=/trunk/; revision=735
1999-09-29 22:11:51 +00:00
Gilbert Ramirez bcf4001ef0 Changed (again) the way that the FT_BOOLEAN field type works internally.
Dissector code can add FT_BOOLEAN fields to the proto_tree and pass TRUE
or FALSE values (non-zero and zero values). The display filter language,
however, treats the checking for the existence of a FT_BOOLEAN field as
the checking for its truth. Before this change, packet-tr.c was the only
dissector using FT_BOOLEAN fields, and it only added the field to the
proto_tree if the TRUE; the dissector was determining the difference between
the check for existence and the check for truth.

I made this change because packet-ppp.c added some FT_BOOLEAN fields and
added them to the tree regardless of truth value, It's more natural just to
do it this way and let the display filter code worry about whether to
check for existence or truth. So that's how it works now.

svn path=/trunk/; revision=679
1999-09-15 06:13:21 +00:00
Gilbert Ramirez 10adb4dbee Removed from the display filter/proto_tree code the assumption that
a protocol occurs only once in a packet. Because of encapsulation (IP within
IP), a protocol can occur more than once. I don't have a packet trace
showing such a packet, but the code should handle it now. The one thing
that it cannot do, though, is differentiate the levels. It might be
nice to say:
	ip{1}.src == 192.168.1.1 && ipx{2}.dst == 10.0.0.1

In the dfilter grammar I had left IPXNET variables out of the list
of variables that could be checked for existence. Now you can check
for the existence of ipx.srcnet and ipx.dstnet. Hurrah.

svn path=/trunk/; revision=608
1999-08-29 04:06:43 +00:00
Gilbert Ramirez b53d4ba179 Changed packet-tr.c to insert tr.sr, a FT_BOOLEAN field, only if tr.sr
is true. The test for truth now becomes a test for existence. The dfilter
grammar no longer recognizes 'true' and 'false', since you can now check
a boolean field via:

	tr.sr

or by its negation:

	!tr.sr

svn path=/trunk/; revision=591
1999-08-27 19:27:22 +00:00
Gilbert Ramirez ae356ef145 The dfilter yacc grammar now keeps track of every GNode that it allocates.
After a bad parse, instead of leaking this memory, the memory used for
those GNodes is now freed.

Added some memory-freeing "cleanup" routines for the dfilter and proto_tree
modules, which are called right before ethereal exits. Maybe once we get
a complete set of cleanup routines, we'll be able to better check if
memory is leaking.

svn path=/trunk/; revision=582
1999-08-26 06:20:50 +00:00
Gilbert Ramirez b85bb70925 Changed some symbols inside parser, fixed default error message in
dfilter_compile, and removed debug printf that I left in match_selected.

svn path=/trunk/; revision=532
1999-08-20 21:19:28 +00:00
Guy Harris 0a25d2df5b Include "snprintf.h" if necessary, to squelch some "gcc -Wall"
complaints.

svn path=/trunk/; revision=531
1999-08-20 20:45:14 +00:00
Gilbert Ramirez f0e5afe7a9 Enabled error reporting for bad ETHER values in display filters. A new
global variable, dfilter_error_msg is now available, being NULL when there
was no error, or pointing to a string when an error occurred. The three
places that dfilter_compile() is called now use this global variable to
report the error message to the user. A default error message is put
in that string if no context-specific error message is available (since
I only have one context-specifici error message, namely, ETHER values,
that will be most of the time).

svn path=/trunk/; revision=530
1999-08-20 20:37:47 +00:00
Gilbert Ramirez 57198bc28f Made handling of byte strings in scanner and parser much simpler,
improving size of grammar and creating the possibility of dfilter_compile
reporting errors back to user. In this case, if an ETHER variable is
compared against a byte string that is not 6 bytes, an error condition is
flagged appropriately. I have not put in the code to conver that error flag
to a message to the user, but that's what I'm working on next.

Also, fixed sample debug session in README to show correct gdb prompt.

svn path=/trunk/; revision=522
1999-08-20 06:01:07 +00:00
Gilbert Ramirez 8030084e93 Modified YACC grammar to use non-yy symbols, to avoid conflicts with
libpcap's that were compiled with symbols beginning with 'yy'.

svn path=/trunk/; revision=487
1999-08-14 06:24:27 +00:00
Gilbert Ramirez ab6490398c Moved global memory alloction used in display filters (which was stored
in dfilter-grammar.y) to a new struct dfilter. Display filters now have
their own struct, rather than simply being GNode's. This allows multiple
display filters to exist at once, aiding John McDermott in his
work on colorization.

svn path=/trunk/; revision=480
1999-08-13 23:47:43 +00:00
Guy Harris a5acc58fe3 Create a "dfilter-int.h" file, containing stuff used internally to the
display filter code but not outside it (and not static to one of the
modules in the display filter code), with most of that stuff moved there
from "dfilter.h".

Add a declaration of "byte_str_to_guint8_array()" to "dfilter-int.h".

svn path=/trunk/; revision=479
1999-08-12 21:16:32 +00:00
Gilbert Ramirez 336b94f506 Fixed two bugs in display filter parsing.
1. Some IP addresses (like 0.0.0.0) would be interpreted as byte ranges.
2. Parens were being ignored.

Thanks to Guy for pointing these out to me.

svn path=/trunk/; revision=477
1999-08-12 15:10:48 +00:00
Gilbert Ramirez 8b3ee0f761 Modified the flex scanner to use symbols that start with "dfilter_"
instead of "yy". (dfilter-grammar.y was modified to #define yylex as
dfilter_lex).

VERSION is no longer needed since the doc/Makefile now uses @VERSION@,
passed to it from 'configure'.

svn path=/trunk/; revision=469
1999-08-11 16:25:07 +00:00
Gilbert Ramirez aebcf2eb32 Removed the "exists" keyword from the grammar. The name of a protocol or a
field by itself assumes you are checking for the existence of that protocol
or field.

Changed the format of the list of filterable fields in the man page.
Developers: run "./configure" so that your configure script will re-create
dfilter2pod from the new dfilter2pod.in

svn path=/trunk/; revision=426
1999-08-03 15:04:33 +00:00
Gilbert Ramirez 36ecdca372 I was able to get rid of all the reduce/reduce conflicts by removing
the rules allowing values to precede variables in a relation, like this:

	192.168.1.1 eq ip.src

More profound changes should still be made to the grammar, though.

svn path=/trunk/; revision=422
1999-08-02 06:34:23 +00:00
Gilbert Ramirez b2f932c1db Changed the display filter scanner from GLIB's GScanner to lex. The code
as it standed depends on your lex being flex, but that only matters if you're
a developer. The distribution will include the dfilter-scanner.c file, so
that if the user doesn't modify dfilter-scanner.l, he won't need flex to
re-create the *.c file.

The new lex scanner gives me better syntax checking for ether addresses. I
thought I could get by using GScanner, but it simply wasn't powerful enough.

All operands have English-like abbreviations and C-like syntax:
and, && ; or, || ; eq, == ; ne, != ; , etc.

I removed the ETHER_VENDOR type in favor of letting the user use the [x:y]
notation:	ether.src[0:3] == 0:6:29 instead of ether.srcvendor == 00:06:29

I implemented the IPXNET field type; it had been there before, but was
not implemented. I chose to make it use integer values rather than byte
ranges, since an IPX Network is 4 bytes. So a display filter looks like this:
	ipx.srcnet == 0xc0a82c00
rather than this:
	ipx.srcnet == c0:a8:2c:00

I can supposrt the byte-range type IPXNET in the future, very trivially.

I still have more work to do on the parser though. It needs to check ranges
when extracting byte ranges ([x:y]) from packets. And I need to get rid
of those reduce/reduce errors from yacc!

svn path=/trunk/; revision=414
1999-08-01 04:28:20 +00:00
Gilbert Ramirez 56c0587491 Fixed the byte_range implementation, and removed some of the C-style
operators that I had thrown in at the last moment. Sorry! But I'm trying
to get rid of those embarrassing shift/reduce and reduce/reduce warnings.
I also removed wiretap/wiretap.c, which is no longer needed.

svn path=/trunk/; revision=345
1999-07-08 03:05:55 +00:00
Gilbert Ramirez 07f42b5b31 Created a new protocol tree implementation and a new display filter
mechanism that is built into ethereal. Wiretap is now used to read all
file formats. Libpcap is used only for capturing.

svn path=/trunk/; revision=342
1999-07-07 22:52:57 +00:00