Reputation: 6464
I have a necessity to add support for a proprietary headers that FPGA in our design inserts in incoming Ethernet frames between MAC header and payload. Obviously have to dig in tcpdump sources and libpcap, but could anybody give some hints at where exactly to start, so that I could save time?
Upvotes: 0
Views: 399
Reputation:
The first thing you need to do is to get a DLT_
/LINKTYPE_
value for your proprietary headers. See the link-layer header types page on the tcpdump.org Web site for the existing DLT_/LINKTYPE_ link-layer header type values and information on how to either use one of the DLT_USER
n values internally or get a new value assigned if you plan to have people outside your organization use this.
Once you have the value assigned, you'll have to do some work on libpcap:
If you've been assigned a DLT_
value, you'll have to modify the pcap/pcap.h
file to add that link-layer type (and change the DLT_MATCHING_MAX
value in that header file, and LINKTYPE_MATCHING_MAX
in pcap-common.c
, so that they are >= your DLT_
value), or wait for whoever at tcpdump.org (which will probably be me) assigns your DLT_
value and updates the libpcap Git repository (at which point you could use top-of-trunk libpcap).
If you plan to do live capturing, you may have to add a module to libpcap to support live capturing on your hardware, or, if your device looks like a regular networking device to your OS, so that you can use its native capture mechanism, modify the module for that OS to map whatever link-layer header type value the OS uses (e.g., a DLT_
value on *BSD/OS X or an ARPHRD_
value on Linux) to whatever DLT_
you're using for your link-layer header type.
You'd have to modify gencode.c
to be able to compile capture filters for your DLT_
value.
Once that's done, libpcap should now work.
Now, for tcpdump:
Add an if_print
routine that processes the proprietary headers (whether it just skips them or prints things for them), calls ether_print()
, and then returns the sum of the length of your proprietary headers and the Ethernet header (ETHER_HDRLEN
as defined in ether.h
). See ether_if_print()
in print-ether.c
for an example.
Add a declaration of that routine to interface.h
and netdissect.h
, and add an entry for it, with the routine name and DLT_
, to ndo_printers[]
if you copied ether_if_print()
(which you should) or to printers[]
if you didn't (if you didn't, you'll have to pass &gndo
as the first argument to ether_print()
). Those arrays are in tcpdump.c
.
Upvotes: 1