dect
/
libpcap
Archived
13
0
Fork 0
Commit Graph

74 Commits

Author SHA1 Message Date
itojun 5918c491c1 whitespace cleanup 2002-06-11 17:04:44 +00:00
itojun f1183c9b15 tches #454 from yamt@mwd.biglobe.ne.jp
- avoid optimization involving subtract operations
- correct optimization of bitwise operations

TODO: re-introduce subtract optimization
2002-06-11 05:30:39 +00:00
guy ffd1e8f4ad Add comments to explain the incomplete definitions of "struct mbuf" and
"struct rtentry".
2002-06-01 23:22:57 +00:00
guy 4f544108b4 Handle the three types of link layers:
those that always use 802.2;

	those that never use 802.2;

	Ethernet (where 802.2 is used for 802.3 and is not used for
	Ethernet II);

correctly.  This requires having two variables for the offset of the
network layer header, one for use with protocols that would not run atop
802.2 on Ethernet and would run atop 802.2+SNAP on link layers that
always use 802.2, and one for use with protosol that would run atop
raw 802.2 (no SNAP) on Ethernet and on link layers that always use
802.2.

Fix the network layer offset for 802.11, and the link-layer offset for
RFC 1483 ATM (there's no link layer, there's just 802.2 LLC).
2002-04-11 07:38:32 +00:00
guy 1d35b4b590 Include <netdb.h> before <pcap-namedb.h>, as <netdb.h> is included to
define a structure used by <pcap-namedb.h> (only a pointer to the
structure is used in <pcap-namedb.h>, so code will compile no matter
which order you include them in, but it's a bit cleaner to include
<netdb.h> first).  Indicate why we're including <netdb.h>.
2002-04-07 00:04:37 +00:00
guy 705943d1bc There's no need to include <sys/socket.h> twice. 2002-04-06 23:57:52 +00:00
guy 4c16994790 Free up both "registers" (scratch memory locations, really) used by an
arithmetic expression in a filter; otherwise, we leak registers when
compiling arithmetic expressions.
2001-12-18 09:10:49 +00:00
guy b0ea1152b6 Add support for DLT_PRISM_HEADER. 2001-11-30 07:25:48 +00:00
fenner 1c20fa1fee Zero out IPv6 mask before using it. This fixes expressions like
'net 2002::/16', which were previously non-deterministic based on
the previous contents of memory.

Reported by:	Pekka Savola <pekkas@netcore.fi>
2001-11-12 21:59:44 +00:00
fenner ecead9709d Reset the VLAN flags when compiling a new expression.
This allows correct compilation of multiple expressions
 containing the "vlan" keyword in the same program.

Reported by:	Jon Dugan <jdugan@ncsa.uiuc.edu>, on the bro@lbl.gov list
2001-09-20 00:24:24 +00:00
guy ca3fec5964 Fix a memory leak found by Miklos Szeredi
<Miklos.Szeredi@eth.ericsson.se> - "pcap_ether_aton()" allocates memory
for the MAC address, but we don't free it when we're done with it.

Code inspection revealed that there's a similar problem with
"pcap_ether_hostton()"; fix that as well.
2001-07-03 19:15:47 +00:00
guy 7aa547ff09 Change from NetBSD, by Martin Husemann <martin@netbsd.org>:
Adapt to (temporary) DLT_PPP_ETHER useage by the pppoe code in tree
	now. This needs to be fixed when a generic PPP sheme is implemented.
2001-06-20 07:12:38 +00:00
guy 77d52cac81 Support for LocalTalk hardware, from Uns Lider <unslider@miranda.org>. 2001-06-18 08:46:28 +00:00
guy 6cd32e5cef 802.11 support, from Javier Achirica <achirica@ttd.net>. 2001-06-10 01:11:39 +00:00
fenner c3d1fa6983 Allow "ip6 proto ___" constructs.
Don't parse "ip6" if not compiled with ip6 support.
2001-05-30 01:27:21 +00:00
fenner 283da6d726 SCTP support from Armando L. Caro Jr. <acaro@mail.eecis.udel.edu> 2001-05-10 14:48:01 +00:00
guy 38b97b7e84 ARCNet support, from NetBSD. 2001-04-17 08:25:21 +00:00
guy 80788ad380 Add support for NetBSD DLT_PPP_ETHER, as per the NetBSD libpcap. 2001-04-17 08:10:00 +00:00
guy cae3c555e6 Patch from NetBSD, by Klaus Klein <kleink@netbsd.org>, to support "vrrp"
as an IP protocol, like "udp", "tcp", "icmp", "pim", etc..
2001-02-21 09:33:03 +00:00
itojun ae09ab3412 ignore non-IP address. 2001-02-12 09:33:21 +00:00
guy b0dcde29f7 Add a "netbeui" keyword, which selects NetBEUI packets (LLC packets with
0xf0 as the DSAP and SSAP).

Let "ipx" work on non-Ethernet 802.2 frames - we assume they're always
frames with the IPX DSAP.
2001-01-28 09:44:48 +00:00
guy 2f454fd004 Check for all four types of IPX frame on DLT_LINUX_SLL captures. 2001-01-15 00:03:40 +00:00
guy 79762d33da I've seen captures with all four different flavors of IPX frames on
Ethernet, so, at least on Ethernet, when checking for IPX frames, check
for all of them, including Ethernet_II and Ethernet_SNAP.

Add an "llc.h" file with LLC SAP values, taken from tcpdump's "llc.h"
file, and use those, rather than defining them ourselves in "gencode.c".
2001-01-14 21:26:52 +00:00
guy d4869582d0 Handle STP (under the assumption that the "Bridging PDU"s that go over
PPP are Spanning Tree Protocol Bridging PDUs) and IPX over PPP.
2001-01-14 08:09:58 +00:00
guy d17596dbd9 Add "ipx", which checks for the LLC SAP for IPX as well as, on Ethernet,
for "Novell 802.3" frames, which are 802.3 frames (i.e., the type/length
field is a length field, i.e. it's <= ETHERMTU) with 0xFFFF as the first
2 bytes.  We don't yet check for ETHERTYPE_IPX as well.

When checking for OSI packets on Linux cooked captures, check for 802.2
frames by testing the packet type for LINUX_SLL_P_802_2 rather than by
checking whether the type field is <= ETHERMTU (it's always a type field
in DLT_LINUX_SLL captures).
2001-01-14 07:57:47 +00:00
guy c3c2ed00d5 Generate code to check for LLC SAP values on Linux cooked captures.
Set "off_linktype" to the correct value for the offset of the Ethernet
type field in the fake header for Linux cooked captures, so that the
correct code is generated for tests of that field.
2001-01-14 05:30:07 +00:00
guy 2b3dac284e Support checking for protocols specified by an LLC SAP on FDDI, Token
Ring, and RFC 1483-style ATM, as well as on Ethernet.

Support checking for LLC SAP protocols other than OSI protocols on
Ethernet - for now, we check only the DSAP on those, rather than
checking both the DSAP and SSAP as we do for OSI, as I think, in some
cases, the SSAP isn't the same as the DSAP.

When generating protocol type checks on link-layer types with no type
field, where packets are always IP (SLIP, BSD/OS SLIP, raw IP), generate
a "test" that always succeeds if the protocol being checked for is IP or
IPv6 and a "test" that always fails otherwise.  (We originally did
"gen_true()" if the protocol is IP, and bogusly generated code to check
the field at an offset of -1 otherwise; a subsequent change caused us
always to do "gen_true()", but that doesn't properly handle attempts to
check for other protocols - those attempts should generate code that
always fails, meaning that if you try to look for ARP packets in such a
capture the BPF compiler will return "expression rejects all packets" as
an error - and still generated extra code not all of which was removed
by the optimizer.  The current code generates no *more* BPF code.)

Add "stp", which checks for the LLC SAP for the Spanning Tree Protocol.
2001-01-14 04:34:51 +00:00
guy 5b0a98d641 Add support for a new link layer type DLT_LINUX_SLL, for use when doing
live captures with a "cooked" (SOCK_DGRAM) rather than a "raw"
(SOCK_RAW) PF_PACKET socket; it includes a bunch of the fields from the
"struct sockaddr_ll" you get in a "recvfrom()", including the Ethernet
protocol field.

This requires us to rewrite the BPF program if we're stuffing it into
the kernel; as long as we're doing *ex post facto* rewriting, we might
as well also do the "ret <snaplen>" -> "ret 65535" fixup there as well,
rather than in the code generator.
2000-12-21 10:29:21 +00:00
guy 7928a0e823 Handle DLT_NULL correctly - the AF_ value is in host byte order, which
means that we should "htonl()" it before using it in BPF expressions
*but*, if we're reading a capture file from a machine with the opposite
byte order from ours, we should byte-swap it before "htonl()"ing it.

Handle OpenBSD DLT_LOOP as well - it's like DLT_NULL except that the AF_
value is in *network* byte order.

Don't support checking for inbound or outbound packets except on those
data link types that supply an inbound/outbound qualifier (DLT_SLIP and
DLT_PPP) - this came from OpenBSD's libpcap, delta 1.12 to "gencode.c".
2000-12-16 21:31:10 +00:00
guy e20bbc40f7 If the user specifies an Ethernet address in an expression such as
"ether host XX:XX:XX:XX:XX:XX", but the device on which you're capturing
isn't a device with Ethernet-style link-layer addresses, report
"ethernet addresses supported only on ethernet, FDDI or token ring", not
"ethernet address used in non-ether expression", as the error.
2000-12-12 08:08:38 +00:00
guy 26f7f272c0 Make "pcap_compile_nopcap()" a wrapper around "pcap_open_dead()" and
"pcap_compile()", rather than a routine that duplicates a lot of code in
"pcap_compile()", so that we don't run the risk of having
"pcap_compile_nopcap()" fail to take actions that "pcap_compile()"
takes.
2000-12-12 03:26:16 +00:00
itojun 142ff8d0c7 correct "protochain" processing. 2000-11-09 06:20:05 +00:00
guy 7d16400ec5 When reporting an unknown data link type, print it in decimal, not hex,
as DLT_ values are defined with decimal values in "net/bpf.h".

Cast the last argument to "gen_cmp()" to "bpf_int32", not "long", as
it's a "bpf_int32".
2000-10-30 06:06:53 +00:00
guy daef269870 Add a #define for the LSAP value for SNAP. 2000-10-29 05:53:21 +00:00
guy 00357a902a Handle "iso" as a PPP link-layer type. 2000-10-28 10:28:15 +00:00
guy 195ad572d1 Allow "clnp", as well as "esis" and "isis", as OSI protocols for which
we can check.
2000-10-28 10:18:39 +00:00
guy f4cbadac41 Allow "iso proto esis" and "iso proto isis" (as the FreeBSD man page
claims are allowed, even though the FreeBSD tcpdump doesn't support
them).
2000-10-28 10:05:46 +00:00
guy be6af9e0ad Catch attempts to filter on ISO hosts (we don't support that) and to
apply "esis" or "isis" to host names.
2000-10-28 09:43:56 +00:00
guy af30d75a3e Tony Li's changes, from FreeBSD, to support filtering for OSI packets
and for ESIS and ISIS packets.
2000-10-28 09:30:20 +00:00
guy 14972aa99d Handle for DLT_PPP all the protocol types we handle for DLT_PPP_BSDOS. 2000-10-28 09:06:06 +00:00
guy 54b2ab13c2 Patch from Monroe Williams <monroe@pobox.com>, submitted with NetBSD PR
#5228, to correctly check for Appletalk for EtherTalk phase II - they
use 802.3 with LLC SNAP packets, rather than D/I/X Ethernet packets.

His patch made "atalk" check for Appletalk ARP as well as other
Appletalk packets; I've instead added a separate "aarp" packet type,
leaving "atalk" checking only for ETHERTYPE_ATALK, so you can check for
ETHERTYPE_ATALK, ETHERTYPE_AARP, or both.
2000-10-28 08:19:29 +00:00
guy 82547471f7 When attaching a "bpf_program" to a "pcap_t" to use as a userland
filter, always attach a copy, as "pcap-linux.c" does; that way, after a
program uses "pcap_setfilter()", it can safely use "pcap_freecode()" to
free up the BPF instructions allocated by "pcap_compile()".  Also,
always free it up when the "pcap_t" is closed.

Get rid of the "pcap_t *" argument to "pcap_freecode()", as it's not
necessary.

Document "pcap_freecode()", for the benefit of programs that might
repeatedly compile filter programs and attach them, so that they can
free them up after attaching them and avoid leaking memory for them.
2000-10-28 00:01:26 +00:00
guy 5c4a950507 Clean up the lexical analyzer if we return normally from
"pcap_compile()", not just if we return with an error, so that we don't
leak memory by allocating a Flex buffer for the expression to be parsed
but not freeing it.
2000-10-25 07:28:22 +00:00
guy c900791477 The Linux "pcap_setfilter()" makes a copy of the filter it's handed, and
installs that copy; when closing a pcap_t on Linux, free that copy.
2000-10-25 06:59:09 +00:00
guy 98a503e843 Improved VLAN support, from Peter Jeremy - "vlan" filtering keyword,
letting you filter based on the VLAN to which a packet belongs, and an
improvement to the printing of VLAN packets (adding an extra space to
separate the VLAN priority and flags from the next stuff printed).
2000-10-22 04:15:55 +00:00
guy 2c961ff224 Get rid of the PCAP_ENCAP_ values - if an application uses them, that
application won't build with any other version of libpcap, which means
that a lot of applications won't use them.  In addition,
"pcap_linktype()" needs to return DLT_ values, so that platforms that
build libpcap as a shared library won't break binary compatibility if
they update to this version of libpcap.

Instead, we map from DLT_ values to LINKTYPE_ values when writing
savefiles, and map from LINKTYPE_ values to DLT_ values when reading
savefiles, so that savefiles don't have platform-dependent DLT_ values
in the header as the link type, they have platform-independent LINKTYPE_
values.

This means we don't need to make DLT_ATM_RFC1483, DLT_RAW, etc. have
platform-independent values starting at 100 - only the values in the
savefile header need to be like that.
2000-10-12 03:53:57 +00:00
guy fd7f1bf605 Include <string.h> to declare various string-manipulating routines. 2000-10-10 04:53:08 +00:00
guy 79e2793fb3 Make "gen_protochain()", as it's not used outside "gencode.c", and
declare it before it's defined.
2000-10-06 04:52:53 +00:00
guy 6ef0c9a172 Add definitions of Ethernet types from
"linux-includes/netinet/if_ether.h" to "ethertype.h", and remove
includes of <netinet/if_ether.h> from files that only include it to get
ETHERTYPE_ values defined.
2000-09-23 07:26:27 +00:00
guy 8439f66a3f In "init_linktype()", map DLT_ codes that don't have the same value as
the equivalent PCAP_ENCAP_ codes to the corresponding PCAP_ENCAP_ code
so that the code generator need check only the PCAP_ENCAP_ codes.

Handle PCAP_ENCAP_PPP_HDLC just like PCAP_ENCAP_PPP.
2000-09-18 06:39:44 +00:00