If you are interested, I have attached a candidate patch to add an ENCAP
configuration parameter to the userlevel FromDevice element.
- Ian
Ian Rose wrote:
When using libpcap, some drivers support multiple datalink-types. I
believe this is why tcpdump exposes a -y flag (to set the datalink type)
and a -L flag (to list the available datalink types for a device). I
think perhaps if you do not specify one (via pcap_set_datalink) then it
will default to the first that appears in the -L list.
For example, we are using the 'ath' FreeBSD 802.11 driver:
ianr...@somehost 9$ sudo tcpdump -L -i ath1
Data link types (use option -y to set):
EN10MB (Ethernet)
IEEE802_11 (802.11)
IEEE802_11_RADIO (802.11 plus BSD radio information header)
If I run tcpdump without -y, or if I use an unmodified FromDevice
element, I receive ethernet packets from the device which is not what I
want. I just add a '-y IEEE802_11_RADIO' to make tcpdump work, but
FromDevice cannot be made to do this with hacking it.
- Ian
Eddie Kohler wrote:
Hi Ian --
I believe that user-level FromDevice detects the datalink type from
pcap, so there wouldn't be a point to the argument. Did you find this
did not work?
Eddie
Ian Rose wrote:
I perhaps should also clarify that I am talking specifically about the
userlevel FromDevice element ("FromDevice.u" on the wiki).
Ian Rose wrote:
Hello all -
I am new to this list - apologies if this question has previously be
answered. I am looking at the FromDevice element, but I see no way
to specify a datalinktype (i.e. the equivalent of the '-y' flag in
tcpdump). Is there any reason that an argument for this was left
out? It seems pretty easy for me to add, but I wanted to check first
to make sure I wasn't overlooking or misunderstanding something.
thanks,
Ian
p.s. I am running on FreeBSD, so I am using the libpcap-based code in
FromDevice, as opposed to the Linux-based code.
_______________________________________________
click mailing list
[email protected]
https://amsterdam.lcs.mit.edu/mailman/listinfo/click
_______________________________________________
click mailing list
[email protected]
https://amsterdam.lcs.mit.edu/mailman/listinfo/click
--- fromdevice.cc 2010-02-28 14:33:44.337025000 -0500
+++ elements/userlevel/fromdevice.cc 2010-02-28 14:26:07.645501000 -0500
@@ -61,7 +61,7 @@
#if FROMDEVICE_PCAP
_pcap(0), _pcap_task(this), _pcap_complaints(0),
#endif
- _count(0), _promisc(0), _snaplen(0)
+ _datalink(-1), _count(0), _promisc(0), _snaplen(0)
{
}
@@ -77,7 +77,8 @@
_headroom = Packet::default_headroom;
_headroom += (4 - (_headroom + 2) % 4) % 4; // default 4/2 alignment
_force_ip = false;
- String bpf_filter, capture;
+ String bpf_filter, capture, encap_type;
+ bool has_encap;
if (cp_va_kparse(conf, this, errh,
"DEVNAME", cpkP+cpkM, cpString, &_ifname,
"PROMISC", cpkP, cpBool, &promisc,
@@ -88,6 +89,7 @@
"BPF_FILTER", 0, cpString, &bpf_filter,
"OUTBOUND", 0, cpBool, &outbound,
"HEADROOM", 0, cpUnsigned, &_headroom,
+ "ENCAP", cpkC, &has_encap, cpWord, &encap_type,
cpEnd) < 0)
return -1;
if (_snaplen > 8190 || _snaplen < 14)
@@ -97,6 +99,11 @@
#if FROMDEVICE_PCAP
_bpf_filter = bpf_filter;
+ if (has_encap) {
+ _datalink = fake_pcap_parse_dlt(encap_type);
+ if (_datalink < 0)
+ return errh->error("bad encapsulation type");
+ }
#endif
// set _capture
@@ -251,6 +259,13 @@
}
# endif
+ if (_datalink == -1) { // no ENCAP specified in configure()
+ _datalink = pcap_datalink(_pcap);
+ } else {
+ if (pcap_set_datalink(_pcap, _datalink) == -1)
+ return errh->error("%s: pcap_set_datalink: %s", ifname, pcap_geterr(_pcap));
+ }
+
bpf_u_int32 netmask;
bpf_u_int32 localnet;
if (pcap_lookupnet(ifname, &localnet, &netmask, ebuf) < 0)
_______________________________________________
click mailing list
[email protected]
https://amsterdam.lcs.mit.edu/mailman/listinfo/click