mausezahn: use getopt_long instead of getopt
[netsniff-ng.git] / netsniff-ng.8
blobe4cc14b551d3e0ac4688f54a119ff9fe1ff639fe
1 .\" netsniff-ng - the packet sniffing beast
2 .\" Copyright 2013 Daniel Borkmann.
3 .\" Subject to the GPL, version 2.
4 .TH NETSNIFF-NG 8 "03 March 2013" "Linux" "netsniff-ng toolkit"
5 .SH NAME
6 netsniff-ng \- the packet sniffing beast
7 .PP
8 .SH SYNOPSIS
9 .PP
10 \fBnetsniff-ng\fP { [\fIoptions\fP] [\fIfilter-expression\fP] }
11 .PP
12 .SH DESCRIPTION
13 .PP
14 netsniff-ng is a fast, minimal tool to analyze network packets, capture
15 pcap files, replay pcap files, and redirect traffic between interfaces
16 with the help of zero-copy packet(7) sockets. netsniff-ng uses both Linux
17 specific RX_RING and TX_RING interfaces to perform zero-copy. This is to avoid
18 copy and system call overhead between kernel and user address space. When we
19 started working on netsniff-ng, the pcap(3) library did not use this
20 zero-copy facility.
21 .PP
22 netsniff-ng is Linux specific, meaning there is no support for other
23 operating systems. Therefore we can keep the code footprint quite minimal and to
24 the point. Linux packet(7) sockets and its RX_RING and TX_RING interfaces
25 bypass the normal packet processing path through the networking stack.
26 This is the fastest capturing or transmission performance one can get from user
27 space out of the box, without having to load unsupported or non-mainline
28 third-party kernel modules. We explicitly refuse to build netsniff-ng on top of
29 ntop/PF_RING. Not because we do not like it (we do find it interesting), but
30 because of the fact that it is not part of the mainline kernel. Therefore, the
31 ntop project has to maintain and sync out-of-tree drivers to adapt them to their
32 DNA. Eventually, we went for untainted Linux kernel, since its code has a higher
33 rate of review, maintenance, security and bug fixes.
34 .PP
35 netsniff-ng also supports early packet filtering in the kernel. It has support
36 for low-level and high-level packet filters that are translated into Berkeley
37 Packet Filter instructions.
38 .PP
39 netsniff-ng can capture pcap files in several different pcap formats that
40 are interoperable with other tools. The following pcap I/O methods are supported
41 for efficient to-disc capturing: scatter-gather,
42 .BR mmap (2),
43 .BR read (2),
44 and
45 .BR write (2).
46 netsniff-ng is also able to rotate pcap files based on data size or time
47 intervals, thus, making it a useful backend tool for subsequent traffic
48 analysis.
49 .PP
50 netsniff-ng itself also supports analysis, replaying, and dumping of raw 802.11
51 frames. For online or offline analysis, netsniff-ng has a built-in packet
52 dissector for the current 802.3 (Ethernet), 802.11* (WLAN), ARP, MPLS, 802.1Q
53 (VLAN), 802.1QinQ, LLDP, IPv4, IPv6, ICMPv4, ICMPv6, IGMP, TCP and UDP,
54 including GeoIP location analysis. Since netsniff-ng does not establish any
55 state or perform reassembly during packet dissection, its memory footprint is quite
56 low, thus, making netsniff-ng quite efficient for offline analysis of large
57 pcap files as well.
58 .PP
59 Note that netsniff-ng is currently not multithreaded. However, this does not
60 prevent you from starting multiple netsniff-ng instances that are pinned to
61 different, non-overlapping CPUs and f.e. have different BPF filters attached.
62 Likely that at some point in time your harddisc might become a bottleneck
63 assuming you do not rotate such pcaps in ram (and from there periodically
64 scheduled move to slower medias). You can then use
65 .BR mergecap (1)
66 to transform all pcap files into a single large pcap file. Thus, netsniff-ng
67 then works multithreaded eventually.
68 .PP
69 netsniff-ng can also be used to debug netlink traffic.
70 .PP
71 .SH OPTIONS
72 .TP
73 .B -i <dev|pcap|->, -d <dev|pcap|->, --in <dev|pcap|->, --dev <dev|pcap|->
74 Defines an input device. This can either be a networking device, a pcap file
75 or stdin (\[lq]\-\[rq]). In case of a pcap file, the pcap type (\fB\-D\fP
76 option) is determined automatically by the pcap file magic. In case of stdin,
77 it is assumed that the input stream is a pcap file. If the pcap link type is
78 Netlink and pcap type is default format (usec or nsec), then each packet will
79 be wrapped with pcap cooked header [2].
80 .TP
81 .B -o <dev|pcap|dir|cfg|->, --out <dev|pcap|dir|cfg|->
82 Defines the output device. This can either be a networking device, a pcap file,
83 a folder, a
84 .BR trafgen (8)
85 configuration file or stdout (\[lq]-\[rq]). If the output device is a pcap or
86 .BR trafgen (8)
87 configuration file, it may include a time format as defined by
88 .BR strfime (3).
89 If used in conjunction with the \fB-F\fP option, each rotated file will have a
90 unique time stamp. In the case of a pcap file that should not have the default
91 pcap type (0xa1b2c3d4), the additional option \fB\-T\fP must be provided. If a
92 directory is given, then, instead of a single pcap file, multiple pcap files are
93 generated with rotation based on maximum file size or a given interval
94 (\fB\-F\fP option). Optionally, sending the SIGHUP signal to the netsniff-ng
95 process causes a premature rotation of the file. A trafgen configuration file
96 can currently only be specified if the input device is a pcap file. To specify a
97 pcap file as the output device, the file name must have \[lq].pcap\[rq] as its
98 extension. If stdout is given as a device, then a trafgen configuration will be
99 written to stdout if the input device is a pcap file, or a pcap file if the
100 input device is a networking device. If the input device is a Netlink monitor
101 device and pcap type is default (usec or nsec) then each packet will be wrapped
102 with pcap cooked header [2] to keep Netlink family number (Kuznetzov's and
103 netsniff-ng pcap types already contain family number in protocol number field).
105 .B -C <id>, --fanout-group <id>
106 If multiple netsniff-ng instances are being started that all have the same packet
107 fanout group id, then the ingress network traffic being captured is being
108 distributed/load-balanced among these group participants. This gives a much better
109 scaling than running multiple netsniff-ng processes without a fanout group parameter
110 in parallel, but only with a BPF filter attached as a packet would otherwise need
111 to be delivered to all such capturing processes, instead of only once to such a
112 fanout member. Naturally, each fanout member can have its own BPF filters attached.
114 .B -K <hash|lb|cpu|rnd|roll|qm>, --fanout-type <hash|lb|cpu|rnd|roll|qm>
115 This parameter specifies the fanout discipline, in other words, how the captured
116 network traffic is dispatched to the fanout group members. Options are to distribute
117 traffic by the packet hash (\[lq]hash\[rq]), in a round-robin manner (\[lq]lb\[rq]),
118 by CPU the packet arrived on (\[lq]cpu\[rq]), by random (\[lq]rnd\[rq]), by rolling
119 over sockets (\[lq]roll\[rq]) which means if one socket's queue is full, we move on
120 to the next one, or by NIC hardware queue mapping (\[lq]qm\[rq]).
122 .B -L <defrag|roll>, --fanout-opts <defrag|roll>
123 Defines some auxiliary fanout options to be used in addition to a given fanout type.
124 These options apply to any fanout type. In case of \[lq]defrag\[rq], the kernel is
125 being told to defragment packets before delivering to user space, and \[lq]roll\[rq]
126 provides the same roll-over option as the \[lq]roll\[rq] fanout type, so that on any
127 different fanout type being used (e.g. \[lq]qm\[rq]) the socket may temporarily roll
128 over to the next fanout group member in case the original one's queue is full.
130 .B -f, --filter <bpf-file|-|expr>
131 Specifies to not dump all traffic, but to filter the network packet haystack.
132 As a filter, either a
133 .BR bpfc (8)
134 compiled file/stdin can be passed as a parameter or a
135 .BR tcpdump (1)-like
136 filter expression in quotes. For details regarding the bpf-file have a look at
137 .BR bpfc (8),
138 for details regarding a
139 .BR tcpdump (1)-like
140 filter have a look at section \[lq]filter example\[rq] or at
141 .BR pcap-filter (7).
142 A filter expression may also be passed to netsniff-ng without option \fB-f\fP in
143 case there is no subsequent option following after the command-line filter
144 expression.
146 .B -t, --type <type>
147 This defines some sort of filtering mechanisms in terms of addressing. Possible
148 values for type are \[lq]host\[rq] (to us), \[lq]broadcast\[rq] (to all), \[lq]multicast\[rq] (to
149 group), \[lq]others\[rq] (promiscuous mode) or \[lq]outgoing\[rq] (from us).
151 .B -F, --interval <size|time>
152 If the output device is a folder, with \[lq]\-F\[rq], it is possible to define the pcap
153 file rotation interval either in terms of size or time. Thus, when the interval
154 limit has been reached, a new pcap file will be started. As size parameter, the
155 following values are accepted \[lq]<num>KiB/MiB/GiB\[rq]; As time parameter,
156 it can be \[lq]<num>s/sec/min/hrs\[rq].
158 .B -J, --jumbo-support
159 By default, in pcap replay or redirect mode, netsniff-ng's ring buffer frames
160 are a fixed size of 2048 bytes. This means that if you are expecting jumbo
161 frames or even super jumbo frames to pass through your network, then you need
162 to enable support for that by using this option. However, this has the
163 disadvantage of performance degradation and a bigger memory footprint for the
164 ring buffer. Note that this doesn't affect (pcap) capturing mode, since tpacket
165 in version 3 is used!
167 .B -R, --rfraw
168 In case the input or output networking device is a wireless device, it is
169 possible with netsniff-ng to turn this into monitor mode and create a mon<X>
170 device that netsniff-ng will be listening on instead of wlan<X>, for instance.
171 This enables netsniff-ng to analyze, dump, or even replay raw 802.11 frames.
173 .B -n <0|uint>, --num <0|uint>
174 Process a number of packets and then exit. If the number of packets is 0, then
175 this is equivalent to infinite packets resp. processing until interrupted.
176 Otherwise, a number given as an unsigned integer will limit processing.
178 .B -O <N>, --overwrite <N>
179 A number from 0 to N-1 will be used in the file name instead of a Unix
180 timestamp. The previous file will be overwritten when number wraps around. The
181 maximum value is 2^32 - 1. Intended for rotating capture files when used
182 with options \fB\-F\fP and \fB\-P\fP.
184 .B -P <name>, --prefix <name>
185 When dumping pcap files into a folder, a file name prefix can be defined with
186 this option. If not otherwise specified, the default prefix is \[lq]dump\-\[rq]
187 followed by a Unix timestamp. Use \[lq]\-\-prefex ""\[rq] to set filename as
188 seconds since the Unix Epoch e.g. 1369179203.pcap
190 .B -T <pcap-magic>, --magic <pcap-magic>
191 Specify a pcap type for storage. Different pcap types with their various meta
192 data capabilities are shown with option \fB\-D\fP. If not otherwise
193 specified, the pcap-magic 0xa1b2c3d4, also known as a standard tcpdump-capable
194 pcap format, is used. Pcap files with swapped endianness are also supported.
196 .B -D, --dump-pcap-types
197 Dump all available pcap types with their capabilities and magic numbers that
198 can be used with option \[lq]\-T\[rq] to stdout and exit.
200 .B -B, --dump-bpf
201 If a Berkeley Packet Filter is given, for example via option \[lq]\-f\[rq], then
202 dump the BPF disassembly to stdout during ring setup. This only serves for informative
203 or verification purposes.
205 .B -r, --rand
206 If the input and output device are both networking devices, then this option will
207 randomize packet order in the output ring buffer.
209 .B -M, --no-promisc
210 The networking interface will not be put into promiscuous mode. By default,
211 promiscuous mode is turned on.
213 .B -N, --no-hwtimestamp
214 Disable taking hardware time stamps for RX packets. By default, if the network
215 device supports hardware time stamping, the hardware time stamps will be used
216 when writing packets to pcap files. This option disables this behavior and
217 forces (kernel based) software time stamps to be used, even if hardware time
218 stamps are available.
220 .B -A, --no-sock-mem
221 On startup and shutdown, netsniff-ng tries to increase socket read and
222 write buffers if appropriate. This option will prevent netsniff-ng from doing
225 .B -m, --mmap
227 .BR mmap (2)
228 as pcap file I/O. This is the default when replaying pcap files.
230 .B -G, --sg
231 Use scatter-gather as pcap file I/O. This is the default when capturing
232 pcap files.
234 .B -c, --clrw
235 Use slower
236 .BR read (2)
238 .BR write (2)
239 I/O. This is not the default case anywhere, but in
240 some situations it could be preferred as it has a lower latency on write-back
241 to disc.
243 .B -S <size>, --ring-size <size>
244 Manually define the RX_RING resp. TX_RING size in \[lq]<num>KiB/MiB/GiB\[rq]. By
245 default, the size is determined based on the network connectivity rate.
247 .B -k <uint>, --kernel-pull <uint>
248 Manually define the interval in micro-seconds where the kernel should be triggered
249 to batch process the ring buffer frames. By default, it is every 10us, but it can
250 manually be prolonged, for instance.
252 .B -b <cpu>, --bind-cpu <cpu>
253 Pin netsniff-ng to a specific CPU and also pin resp. migrate the NIC's IRQ
254 CPU affinity to this CPU. This option should be preferred in combination with
255 \fB\-s\fP in case a middle to high packet rate is expected.
257 .B -u <uid>, --user <uid> resp. -g <gid>, --group <gid>
258 After ring setup drop privileges to a non-root user/group combination.
260 .B -H, --prio-high
261 Set this process as a high priority process in order to achieve a higher
262 scheduling rate resp. CPU time. This is however not the default setting, since
263 it could lead to starvation of other processes, for example low priority kernel
264 threads.
266 .B -Q, --notouch-irq
267 Do not reassign the NIC's IRQ CPU affinity settings.
269 .B -s, --silent
270 Do not enter the packet dissector at all and do not print any packet information
271 to the terminal. Just shut up and be silent. This option should be preferred in
272 combination with pcap recording or replay, since it will not flood your terminal
273 which causes a significant performance degradation.
275 .B -q, --less
276 Print a less verbose one-line information for each packet to the terminal.
278 .B -X, --hex
279 Only dump packets in hex format to the terminal.
281 .B -l, --ascii
282 Only display ASCII printable characters.
284 .B -U, --update
285 If geographical IP location is used, the built-in database update
286 mechanism will be invoked to get Maxmind's latest database. To configure
287 search locations for databases, the file /etc/netsniff-ng/geoip.conf contains
288 possible addresses. Thus, to save bandwidth or for mirroring of Maxmind's
289 databases (to bypass their traffic limit policy), different hosts or IP
290 addresses can be placed into geoip.conf, separated by a newline.
292 .B -w, --cooked
293 Replace each frame link header with Linux "cooked" header [3] which keeps info
294 about link type and protocol. It allows to dump and dissect frames captured
295 from different link types when -i "any" was specified, for example.
297 .B -V, --verbose
298 Be more verbose during startup i.e. show detailed ring setup information.
300 .B -v, --version
301 Show version information and exit.
303 .B -h, --help
304 Show user help and exit.
306 .SH USAGE EXAMPLE
308 .B netsniff-ng
309 The most simple command is to just run \[lq]netsniff-ng\[rq]. This will start
310 listening on all available networking devices in promiscuous mode and dump
311 the packet dissector output to the terminal. No files will be recorded.
313 .B netsniff-ng --in eth0 --out dump.pcap -s -T 0xa1e2cb12 -b 0 tcp or udp
314 Capture TCP or UDP traffic from the networking device eth0 into the pcap file
315 named dump.pcap, which has netsniff-ng specific pcap extensions (see
316 \[lq]netsniff-ng \-D\[rq] for capabilities). Also, do not print the content to
317 the terminal and pin the process and NIC IRQ affinity to CPU 0. The pcap write
318 method is scatter-gather I/O.
320 .B netsniff-ng --in wlan0 --rfraw --out dump.pcap --silent --bind-cpu 0
321 Put the wlan0 device into monitoring mode and capture all raw 802.11 frames
322 into the file dump.pcap. Do not dissect and print the content to the terminal
323 and pin the process and NIC IRQ affinity to CPU 0. The pcap write method is
324 scatter-gather I/O.
326 .B netsniff-ng --in dump.pcap --mmap --out eth0 -k1000 --silent --bind-cpu 0
327 Replay the pcap file dump.pcap which is read through
328 .BR mmap (2)
329 I/O and send the packets out via the eth0 networking device. Do not dissect and
330 print the content to the terminal and pin the process and NIC IRQ affinity to
331 CPU 0.  Also, trigger the kernel every 1000us to traverse the TX_RING instead of
332 every 10us. Note that the pcap magic type is detected automatically from the
333 pcap file header.
335 .B netsniff-ng --in eth0 --out eth1 --silent --bind-cpu 0 --type host -r
336 Redirect network traffic from the networking device eth0 to eth1 for traffic
337 that is destined for our host, thus ignore broadcast, multicast and promiscuous
338 traffic. Randomize the order of packets for the outgoing device and do not
339 print any packet contents to the terminal. Also, pin the process and NIC IRQ
340 affinity to CPU 0.
342 .B netsniff-ng --in team0 --out /opt/probe/ -s -m --interval 100MiB -b 0
343 Capture on an aggregated team0 networking device and dump packets into multiple
344 pcap files that are split into 100MiB each. Use
345 .BR mmap (2)
346 I/O as a pcap write method, support for super jumbo frames is built-in (does not
347 need to be configured here), and do not print the captured data to the terminal.
348 Pin netsniff-ng and NIC IRQ affinity to CPU 0. The default pcap magic type is
349 0xa1b2c3d4 (tcpdump-capable pcap).
351 .B netsniff-ng --in vlan0 --out dump.pcap -c -u `id -u bob` -g `id -g bob`
352 Capture network traffic on device vlan0 into a pcap file called dump.pcap
353 by using normal
354 .BR read (2),
355 .BR write (2)
356 I/O for the pcap file (slower but less latency). Also, after setting up the
357 RX_RING for capture, drop privileges from root to the user and group
358 \[lq]bob\[rq]. Invoke the packet dissector and print packet contents to the
359 terminal for further analysis.
361 .B netsniff-ng --in any --filter http.bpf -B --ascii -V
362 Capture from all available networking interfaces and install a low-level
363 filter that was previously compiled by
364 .BR bpfc (8)
365 into http.bpf in order to filter HTTP traffic. Super jumbo frame support is
366 automatically enabled and only print human readable packet data to the terminal,
367 and also be more verbose during setup phase. Moreover, dump a BPF disassembly of
368 http.bpf.
370 .B netsniff-ng --in dump.pcap --out dump.cfg --silent
371 Convert the pcap file dump.pcap into a
372 .BR trafgen (8)
373 configuration file dump.cfg. Do not print pcap contents to the terminal.
375 .B netsniff-ng -i dump.pcap -f beacon.bpf -o -
376 Convert the pcap file dump.pcap into a
377 .BR trafgen (8)
378 configuration file and write it to stdout. However, do not dump all of its
379 content, but only the one that passes the low-level filter for raw 802.11 from
380 beacon.bpf. The BPF engine here is invoked in user space inside of netsniff-ng,
381 so Linux extensions are not available.
383 .B cat foo.pcap | netsniff-ng -i - -o -
384 Read a pcap file from stdin and convert it into a
385 .BR trafgen (8)
386 configuration
387 file to stdout.
389 .B netsniff-ng -i nlmon0 -o dump.pcap -s
390 Capture netlink traffic to a pcap file. This command needs a netlink monitoring
391 device to be set up beforehand using the follwing commands using
392 .BR ip (1)
393 from the iproute2 utility collection:
395   modprobe nlmon
396   ip link add type nlmon
397   ip link set nlmon0 up
399 To tear down the \fBnlmon0\fP device, use the following commands:
401   ip link set nlmon0 down
402   ip link del dev nlmon0
403   rmmod nlmon
405 .B netsniff-ng --fanout-group 1 --fanout-type cpu --fanout-opts defrag --bind-cpu 0 --notouch-irq --silent --in em1 --out /var/cap/cpu0/ --interval 120sec
406 Start two netsniff-ng fanout instances. Both are assigned into the same fanout
407 group membership and traffic is splitted among them by incoming cpu. Furthermore,
408 the kernel is supposed to defragment possible incoming fragments. First instance
409 is assigned to CPU 0 and the second one to CPU 1, IRQ bindings are not altered as
410 they might have been adapted to this scenario by the user a-priori, and traffic
411 is captured on interface em1, and written out in 120 second intervals as pcap
412 files into /var/cap/cpu0/. Tools like mergecap(1) will be able to merge the cpu0/1
413 split back together if needed.
415 .SH CONFIG FILES
417 Files under /etc/netsniff-ng/ can be modified to extend netsniff-ng's
418 functionality:
420     * oui.conf - OUI/MAC vendor database
421     * ether.conf - Ethernet type descriptions
422     * tcp.conf - TCP port/services map
423     * udp.conf - UDP port/services map
424     * geoip.conf - GeoIP database mirrors
426 .SH FILTER EXAMPLE
428 netsniff-ng supports both, low-level and high-level filters that are
429 attached to its
430 .BR packet (7)
431 socket. Low-level filters are described in the
432 .BR bpfc (8)
433 man page.
435 Low-level filters can be used with netsniff-ng in the following way:
437     1. bpfc foo > bar
438     2. netsniff-ng \-f bar
439     3. bpfc foo | netsniff-ng -i nlmon0 -f -
441 Here, foo is the bpfc program that will be translated into a netsniff-ng
442 readable \[lq]opcodes\[rq] file and passed to netsniff-ng through the \-f
443 option.
445 Similarly, high-level filter can be either passed through the \fB\-f\fP option,
446 e.g. \-f "tcp or udp" or at the end of all options without the \[lq]\-f\[rq].
448 The filter syntax is the same as in
449 .BR tcpdump (8),
450 which is described in the man page
451 .BR pcap-filter (7).
452 Just to quote some examples:
454 .B host sundown
455 To select all packets arriving at or departing from sundown.
457 .B host helios and (hot or ace)
458 To select traffic between helios and either hot or ace.
460 .B ip host ace and not helios
461 To select all IP packets between ace and any host except helios.
463 .B net ucb-ether
464 To select all traffic between local hosts and hosts at Berkeley.
466 .B gateway snup and (port ftp or ftp-data)
467 To select all FTP traffic through Internet gateway snup.
469 .B ip and not net localnet
470 To select traffic neither sourced from, nor destined for, local hosts. If you
471 have a gateway to another network, this traffic should never make it onto
472 your local network.
474 .B tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 and not src and dst net localnet
475 To select the start and end packets (the SYN and FIN packets) of each TCP
476 conversation that involve a non-local host.
478 .B tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)
479 To select all IPv4 HTTP packets to and from port 80, that is to say, print only packets
480 that contain data, not, for example, SYN and FIN packets and ACK-only packets.
481 (IPv6 is left as an exercise for the reader.)
483 .B gateway snup and ip[2:2] > 576
484 To select IP packets longer than 576 bytes sent through gateway snup.
486 .B ether[0] & 1 = 0 and ip[16] >= 224
487 To select IP broadcast or multicast packets that were not sent via Ethernet
488 broadcast or multicast.
490 .B icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply
491 To select all ICMP packets that are not echo requests or replies
492 (that is to say, not "ping" packets).
494 .SH PCAP FORMATS:
496 netsniff-ng supports a couple of pcap formats, visible through ``netsniff-ng \-D'':
498 .B tcpdump-capable pcap (default)
499 Pcap magic number is encoded as 0xa1b2c3d4 resp. 0xd4c3b2a1. As packet meta data
500 this format contains the timeval in microseconds, the original packet length and
501 the captured packet length.
503 .B tcpdump-capable pcap with ns resolution
504 Pcap magic number is encoded as 0xa1b23c4d resp. 0x4d3cb2a1. As packet meta data
505 this format contains the timeval in nanoseconds, the original packet length and
506 the captured packet length.
508 .B Alexey Kuznetzov's pcap
509 Pcap magic number is encoded as 0xa1b2cd34 resp. 0x34cdb2a1. As packet meta data
510 this format contains the timeval in microseconds, the original packet length,
511 the captured packet length, the interface index (sll_ifindex), the packet's
512 protocol (sll_protocol), and the packet type (sll_pkttype).
514 .B netsniff-ng pcap
515 Pcap magic number is encoded as 0xa1e2cb12 resp. 0x12cbe2a1. As packet meta data
516 this format contains the timeval in nanoseconds, the original packet length,
517 the captured packet length, the timestamp hw/sw source, the interface index
518 (sll_ifindex), the packet's protocol (sll_protocol), the packet type (sll_pkttype)
519 and the hardware type (sll_hatype).
521 For further implementation details or format support in your application,
522 have a look at pcap_io.h in the netsniff-ng sources.
524 .SH NOTE
525 To avoid confusion, it should be noted that there is another network
526 analyzer with a similar name, called NetSniff, that is unrelated to
527 the netsniff-ng project.
529 For introducing bit errors, delays with random variation and more
530 while replaying pcaps, make use of
531 .BR tc (8)
532 with its disciplines such as netem.
534 netsniff-ng does only some basic, architecture generic tuning on
535 startup. If you are considering to do high performance capturing,
536 you need to carefully tune your machine, both hardware and software.
537 Simply letting netsniff-ng run without thinking about your underlying
538 system might not necessarily give you the desired performance. Note
539 that tuning your system is always a tradeoff and fine-grained
540 balancing act (throughput versus latency). You should know what
541 you are doing!
543 One recommendation for software-based tuning is
544 .BR tuned (8).
545 Besides that, there are many other things to consider. Just to throw you
546 a few things that you might want to look at: NAPI networking drivers,
547 tickless kernel, I/OAT DMA engine, Direct Cache Access, RAM-based
548 file systems, multi-queues, and many more things. Also, you might
549 want to read the kernel's Documentation/networking/scaling.txt file
550 regarding technologies such as RSS, RPS, RFS, aRFS and XPS. Also
551 check your ethtool(8) settings, for example regarding offloading or
552 Ethernet pause frames.
554 Moreover, to get a deeper understanding of netsniff-ng internals
555 and how it interacts with the Linux kernel, the kernel documentation
556 under Documentation/networking/{packet_mmap.txt, filter.txt,
557 multiqueue.txt} might be of interest.
559 How do you sniff in a switched environment? I rudely refer to dSniff's
560 documentation that says:
562 The easiest route is simply to impersonate the local gateway, stealing
563 client traffic en route to some remote destination. Of course, the traffic
564 must be forwarded by your attacking machine, either by enabling kernel IP
565 forwarding or with a userland program that accomplishes the same
566 (fragrouter \-B1).
568 Several people have reportedly destroyed connectivity on their LAN to the
569 outside world by ARP spoofing the gateway, and forgetting to enable IP
570 forwarding on the attacking machine. Do not do this. You have been warned.
572 A safer option than ARP spoofing would be to use a "port mirror" function
573 if your switch hardware supports it and if you have access to the switch.
575 If you do not need to dump all possible traffic, you have to consider
576 running netsniff-ng with a BPF filter for the ingress path. For that
577 purpose, read the
578 .BR bpfc (8)
579 man page.
581 Also, to aggregate multiple NICs that you want to capture on, you
582 should consider using team devices, further explained in libteam resp.
583 .BR teamd (8).
585 The following netsniff-ng pcap magic numbers are compatible with other
586 tools, at least tcpdump or Wireshark:
588     0xa1b2c3d4 (tcpdump-capable pcap)
589     0xa1b23c4d (tcpdump-capable pcap with ns resolution)
590     0xa1b2cd34 (Alexey Kuznetzov's pcap)
592 Pcap files with different meta data endianness are supported by netsniff-ng
593 as well.
595 .SH BUGS
597 When replaying pcap files, the timing information from the pcap packet
598 header is currently ignored.
600 Also, when replaying pcap files, demultiplexing traffic among multiple
601 networking interfaces does not work. Currently, it is only sent via the
602 interface that is given by the \-\-out parameter.
604 When performing traffic capture on the Ethernet interface, the pcap file
605 is created and packets are received but without a 802.1Q header. When one
606 uses tshark, all headers are visible, but netsniff-ng removes 802.1Q
607 headers. Is that normal behavior?
609 Yes and no. The way VLAN headers are handled in PF_PACKET sockets by the
610 kernel is somewhat \[lq]problematic\[rq] [1]. The problem in the Linux kernel
611 is that some drivers already handle VLANs, others do not. Those who handle it
612 can have different implementations, such as hardware acceleration and so on.
613 So in some cases the VLAN tag is even stripped before entering the protocol
614 stack, in some cases probably not. The bottom line is that a "hack" was
615 introduced in PF_PACKET so that a VLAN ID is visible in some helper data
616 structure that is accessible from the RX_RING.
618 Then it gets really messy in the user space to artificially put the VLAN
619 header back into the right place. Not to mention the resulting performance
620 implications on all of libpcap(3) tools since parts of the packet need to
621 be copied for reassembly via memmove(3).
623 A user reported the following, just to demonstrate this mess: some tests were
624 made with two machines, and it seems that results depend on the driver ...
626     AR8131:
627       ethtool \-k eth0 gives "rx-vlan-offload: on"
628       - wireshark gets the vlan header
629       - netsniff-ng doesn't get the vlan header
630       ethtool \-K eth0 rxvlan off
631       - wireshark gets a QinQ header even though no one sent QinQ
632       - netsniff-ng gets the vlan header
634     RTL8111/8168B:
635       ethtool \-k eth0 gives "rx-vlan-offload: on"
636       - wireshark gets the vlan header
637       - netsniff-ng doesn't get the vlan header
638       ethtool \-K eth0 rxvlan off
639       - wireshark gets the vlan header
640       - netsniff-ng doesn't get the vlan header
642 Even if we agreed on doing the same workaround as libpcap, we still will
643 not be able to see QinQ, for instance, due to the fact that only one VLAN tag
644 is stored in the kernel helper data structure. We think that there should be
645 a good consensus on the kernel space side about what gets transferred to
646 userland first.
648 Update (28.11.2012): the Linux kernel and also
649 .BR bpfc (8)
650 has built-in support for hardware accelerated VLAN filtering, even though tags
651 might not be visible in the payload itself as reported here. However, the
652 filtering for VLANs works reliable if your NIC supports it. See
653 .BR bpfc (8)
654 for an example.
656    [1] http://lkml.indiana.edu/hypermail/linux/kernel/0710.3/3816.html
657    [2] http://www.tcpdump.org/linktypes/LINKTYPE_NETLINK.html
658    [3] http://www.tcpdump.org/linktypes/LINKTYPE_LINUX_SLL.html
660 .SH LEGAL
661 netsniff-ng is licensed under the GNU GPL version 2.0.
663 .SH HISTORY
664 .B netsniff-ng
665 was originally written for the netsniff-ng toolkit by Daniel Borkmann. Bigger
666 contributions were made by Emmanuel Roullit, Markus Amend, Tobias Klauser and
667 Christoph Jaeger. It is currently maintained by Tobias Klauser
668 <tklauser@distanz.ch> and Daniel Borkmann <dborkma@tik.ee.ethz.ch>.
670 .SH SEE ALSO
671 .BR trafgen (8),
672 .BR mausezahn (8),
673 .BR ifpps (8),
674 .BR bpfc (8),
675 .BR flowtop (8),
676 .BR astraceroute (8),
677 .BR curvetun (8)
679 .SH AUTHOR
680 Manpage was written by Daniel Borkmann.
682 .SH COLOPHON
683 This page is part of the Linux netsniff-ng toolkit project. A description of the project,
684 and information about reporting bugs, can be found at http://netsniff-ng.org/.