• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

api/H05-Jul-2017-2,4741,897

m4/H05-Jul-2017-9,2958,415

os-daq-modules/H03-May-2022-6,3915,045

sfbpf/H05-Jul-2017-17,70211,076

COPYINGH A D09-Sep-201520.5 KiB395324

ChangeLogH A D05-Jul-201717.9 KiB551405

Makefile.amH A D08-Feb-2017168 128

Makefile.inH A D05-Jul-201725.2 KiB827729

READMEH A D08-Feb-201715.1 KiB514335

aclocal.m4H A D05-Jul-201741.4 KiB1,1601,054

compileH A D05-Jul-20177.2 KiB349259

config.guessH A D05-Jul-201743.2 KiB1,4741,280

config.h.inH A D05-Jul-20176.1 KiB214148

config.subH A D05-Jul-201735.7 KiB1,8371,699

configureH A D05-Jul-2017473.4 KiB16,33213,675

configure.acH A D05-Jul-201711.5 KiB325278

daq.dspH A D08-Feb-20177 KiB303230

depcompH A D05-Jul-201723 KiB792502

install-shH A D05-Jul-201714.3 KiB502327

ltmain.shH A D05-Jul-2017316.7 KiB11,1527,980

missingH A D05-Jul-20176.7 KiB216143

README

1Snort 2.9 introduces the DAQ, or Data Acquisition library, for packet I/O.  The
2DAQ replaces direct calls to libpcap functions with an abstraction layer that
3facilitates operation on a variety of hardware and software interfaces without
4requiring changes to Snort.  It is possible to select the DAQ type and mode
5when invoking Snort to perform pcap readback or inline operation, etc.  The
6DAQ library may be useful for other packet processing applications and the
7modular nature allows you to build new modules for other platforms.
8
9This README summarizes the important things you need to know to use the DAQ.
10
11
12Building the DAQ Library and DAQ Modules
13========================================
14
15The DAQ is bundled with Snort but must be built first using these steps:
16
17    ./configure
18    make
19    sudo make install
20
21This will build and install both static and dynamic DAQ modules.
22
23Note that pcap >= 1.5.0 is required.  pcap 1.8.1 is available at the time
24of this writing and is recommended.
25
26Also, libdnet is required for IPQ and NFQ DAQs.  If you get a relocation error
27trying to build those DAQs, you may need to reinstall libdnet and configure it
28with something like this:
29
30    ./configure "CFLAGS=-fPIC -g -O2"
31
32You may also experience problems trying to find the dynamic dnet library
33because it isn't always named properly.  Try creating a link to the shared
34library (identified by its .x or .x.y etc. extension) with the same name but
35with ".so" inserted as follows:
36
37    $ ln -s libdnet.1.1 libdnet.so.1.1
38    $ ldconfig -Rv /usr/local/lib 2>&1 | grep dnet
39      Adding /usr/local/lib/libdnet.so.1.1
40
41Alternatively, you should be able to fix both issues as follows:
42
43    libtoolize --copy --force
44    aclocal -I config
45    autoheader
46    autoconf
47    automake --foreign
48
49When the DAQ library is built, both static and dynamic flavors will be
50generated.  The various DAQ modules will be built if the requisite headers and
51libraries are available.  You can disable individual modules, etc. with options
52to configure.  For the complete list of configure options, run:
53
54    ./configure --help
55
56
57PCAP Module
58===========
59
60pcap is the default DAQ.  If snort is run w/o any DAQ arguments, it will
61operate as it always did using this module.  These are equivalent:
62
63    ./snort -i <device>
64    ./snort -r <file>
65
66    ./snort --daq pcap --daq-mode passive -i <device>
67    ./snort --daq pcap --daq-mode read-file -r <file>
68
69You can specify the buffer size pcap uses with:
70
71    ./snort --daq pcap --daq-var buffer_size=<#bytes>
72
73Immediate (less-buffered or unbuffered) delivery mode can be enabled with:
74
75    ./snort --daq pcap --daq-var immediate=1
76
77This immediate delivery mode can be particularly useful on modern Linux systems
78with TPACKET_V3 support.  LibPCAP will attempt to use this mode when it is
79available, but it introduces some potentially undesirable behavior in exchange
80for better performance.  The most notable behavior change is that the packet
81timeout will never occur if packets are not being received, causing the poll()
82to potentially hang indefinitely.  Enabling immediate delivery mode will cause
83LibPCAP to use TPACKET_V2 instead of TPACKET_V3.
84
85* The pcap DAQ does not count filtered packets. *
86
87
88AFPACKET Module
89===============
90
91afpacket functions similar to the pcap DAQ but with better performance:
92
93    ./snort --daq afpacket -i <device>
94            [--daq-var buffer_size_mb=<#MB>]
95            [--daq-var debug]
96
97If you want to run afpacket in inline mode, you must craft the device string as
98one or more interface pairs, where each member of a pair is separated by a
99single colon and each pair is separated by a double colon like this:
100
101    eth0:eth1
102
103or this:
104
105    eth0:eth1::eth2:eth3
106
107By default, the afpacket DAQ allocates 128MB for packet memory.  You can change
108this with:
109
110    --daq-var buffer_size_mb=<#MB>
111
112Note that the total allocated is actually higher, here's why.  Assuming the
113default packet memory with a snaplen of 1518, the numbers break down like this:
114
115* The frame size is 1518 (snaplen) + the size of the AFPacket header (66
116  bytes) = 1584 bytes.
117
118* The number of frames is 128 MB / 1518 = 84733.
119
120* The smallest block size that can fit at least one frame is  4 KB = 4096 bytes
121  @ 2 frames per block.
122
123* As a result, we need 84733 / 2 = 42366 blocks.
124
125* Actual memory allocated is 42366 * 4 KB = 165.5 MB.
126
127NOTE: Linux kernel version 2.6.31 or higher is required for the AFPacket DAQ
128module due to its dependency on both TPACKET v2 and PACKET_TX_RING support.
129
130Fanout (Kernel Loadbalancing)
131-----------------------------
132More recent Linux kernel versions (3.1+) support various kernel-space
133loadbalancing methods within AFPacket configured using the PACKET_FANOUT ioctl.
134This allows you to have multiple AFPacket DAQ module instances processing
135packets from the same interfaces in parallel for significantly improved
136throughput.
137
138To configure PACKET_FANOUT in the AFPacket DAQ module, two DAQ variables are
139used:
140
141    --daq-var fanout_type=<hash|lb|cpu|rollover|rnd|qm>
142
143and (optionally):
144
145    --daq-var fanout_flag=<rollover|defrag>
146
147In general, you're going to want to use the 'hash' fanout type, but the others
148have been included for completeness.  The 'defrag' fanout flag is probably a
149good idea to correctly handle loadbalancing of flows containing fragmented
150packets.
151
152Please read the man page for 'packet' or packet_mmap.txt in the Linux kernel
153source for more details on the different fanout types and modifier flags.
154
155
156NFQ Module
157==========
158
159NFQ is the new and improved way to process iptables packets:
160
161    ./snort --daq nfq \
162        [--daq-var device=<dev>] \
163        [--daq-var proto=<proto>] \
164        [--daq-var queue=<qid>]
165
166    <dev> ::= ip | eth0, etc; default is IP injection
167    <proto> ::= ip4 | ip6 |; default is ip4
168    <qid> ::= 0..65535; default is 0
169
170This module can not run unprivileged so ./snort -u -g will produce a warning
171and won't change user or group.
172
173Notes on iptables are given below.
174
175
176IPQ Module
177==========
178
179IPQ is the old way to process iptables packets.  It replaces the inline version
180available in pre-2.9 versions built with this:
181
182    ./configure --enable-inline
183
184Note that layer 2 resets are not supported with the IPQ DAQ:
185
186    config layer2resets[: <mac>]
187
188Start the IPQ DAQ as follows:
189
190    ./snort --daq ipq \
191        [--daq-var device=<dev>] \
192        [--daq-var proto=<proto>] \
193
194    <dev> ::= ip | eth0, etc; default is IP injection
195    <proto> ::= ip4 | ip6; default is ip4
196
197This module can not run unprivileged so ./snort -u -g will produce a warning
198and won't change user or group.
199
200Notes on iptables are given below.
201
202
203IPFW Module
204===========
205
206IPFW is available for BSD systems.  It replaces the inline version available in
207pre-2.9 versions built with this:
208
209    ./configure --enable-ipfw
210
211This command line argument is no longer supported:
212
213    ./snort -J <port#>
214
215Instead, start Snort like this:
216
217    ./snort --daq ipfw [--daq-var port=<port>]
218
219    <port> ::= 1..65535; default is 8000
220
221* IPFW only supports ip4 traffic.
222
223Notes on FreeBSD and OpenBSD are given below.
224
225
226Dump Module
227===========
228
229The dump DAQ allows you to test the various inline mode features available in
2302.9 Snort like injection and normalization.
231
232    ./snort -i <device> --daq dump
233    ./snort -r <pcap> --daq dump
234
235By default a file named inline-out.pcap will be created containing all packets
236that passed through or were generated by snort.  You can optionally specify a
237different name.
238
239    ./snort --daq dump --daq-var file=<name>
240
241The dump DAQ also supports text output of verdicts rendered, injected packets,
242and other such items.  In order to enable text output, the 'output' DAQ
243variable must be set to either 'text' (text output only) or 'both' (both text
244and PCAP output will be written). The default filename for the text output is
245inline-out.txt, but it can be overridden like so:
246
247    ./snort --daq dump --daq-var output=text --daq-var text-file=<filename>
248
249dump uses the pcap daq for packet acquisition.  It therefore does not count
250filtered packets (a pcap limitation).
251
252Note that the dump DAQ inline mode is not an actual inline mode.  Furthermore,
253you will probably want to have the pcap DAQ acquire in another mode like this:
254
255    ./snort -r <pcap> -Q --daq dump --daq-var load-mode=read-file
256    ./snort -i <device> -Q --daq dump --daq-var load-mode=passive
257
258
259Netmap Module
260=============
261
262The netmap project is a framework for very high speed packet I/O.  It is
263available on both FreeBSD and Linux with varying amounts of preparatory
264setup required.  Specific notes for each follow.
265
266    ./snort --daq netmap -i <device>
267            [--daq-var debug]
268
269If you want to run netmap in inline mode, you must craft the device string as
270one or more interface pairs, where each member of a pair is separated by a
271single colon and each pair is separated by a double colon like this:
272
273    em1:em2
274
275or this:
276
277    em1:em2::em3:em4
278
279Inline operation performs Layer 2 forwarding with no MAC filtering, akin to the
280AFPacket module's behavior.  All packets received on one interface in an inline
281pair will be forwarded out the other interface unless dropped by the reader and
282vice versa.
283
284IMPORTANT: The interfaces will need to be up and in promiscuous mode in order to
285function ('ifconfig em1 up promisc').  The DAQ module does not currently do
286either of these configuration steps for itself.
287
288FreeBSD
289-------
290In FreeBSD 10.0, netmap has been integrated into the core OS.  In order to use
291it, you must recompile your kernel with the line
292
293    device netmap
294
295added to your kernel config.
296
297Linux
298-----
299You will need to download the netmap source code from the project's repository:
300
301    https://code.google.com/p/netmap/
302
303Follow the instructions on the project's homepage for compiling and installing
304the code:
305
306    http://info.iet.unipi.it/~luigi/netmap/
307
308It will involve a standalone kernel module (netmap_lin) as well as patching and
309rebuilding the kernel module used to drive your network adapters. The following
310drivers are supported under Linux at the time of writing (June 2014):
311
312    e1000
313    e1000e
314    forcedeth
315    igb
316    ixgbe
317    r8169
318    virtio
319
320TODO:
321- Support for attaching to only a single ring (queue) on a network adapter.
322- Support for VALE and netmap pipes.
323
324
325Notes on iptables
326=================
327
328These notes are just a quick reminder that you need to set up iptables to use
329the IPQ or NFQ DAQs.  Doing so may cause problems with your network so tread
330carefully.  The examples below are intentionally incomplete so please read the
331related documentation first.
332
333Here is a blog post by Marty for historical reference:
334
335    http://archives.neohapsis.com/archives/snort/2000-11/0394.html
336
337You can check this out for queue sizing tips:
338
339    http://www.inliniac.net/blog/2008/01/23/improving-snort_inlines-nfq-performance.html
340
341You might find useful IPQ info here:
342
343    http://snort-inline.sourceforge.net/
344
345Use this to examine your iptables:
346
347    sudo /sbin/iptables -L
348
349Use something like this to set up NFQ:
350
351    sudo /sbin/iptables
352        -I <table> [<protocol stuff>] [<state stuff>]
353        -j NFQUEUE --queue-num 1
354
355Use something like this to set up IPQ:
356
357    sudo iptables -I FORWARD -j QUEUE
358
359Use something like this to "disconnect" snort:
360
361    sudo /sbin/iptables -D <table> <rule pos>
362
363Be sure to start Snort prior to routing packets through NFQ with iptables.
364Such packets will be dropped until Snort is started.
365
366The queue-num is the number you must give Snort.
367
368If you are running on a system with both NFQ and IPQ support, you may
369experience some start-up failures of the sort:
370
371The solution seems to be to remove both modules from the kernel like this:
372
373    modprobe -r nfnetlink_queue
374    modprobe -r ip_queue
375
376and then install the module you want:
377
378    modprobe ip_queue
379
380or:
381
382    modprobe nfnetlink_queue
383
384These DAQs should be run with a snaplen of 65535 since the kernel defrags the
385packets before queuing.  Also, no need to configure frag3.
386
387
388Notes on FreeBSD::IPFW
389======================
390
391Check the online manual at:
392
393    http://www.freebsd.org/doc/handbook/firewalls-ipfw.html.
394
395Here is a brief example to divert icmp packets to Snort at port 8000:
396
397To enable support for divert sockets, place the following lines in the
398kernel configuration file:
399
400    options IPFIREWALL
401    options IPDIVERT
402
403(The file in this case was: /usr/src/sys/i386/conf/GENERIC; which is platform
404dependent.)
405
406You may need to also set these to use the loadable kernel modules:
407
408/etc/rc.conf:
409firewall_enable="YES"
410
411/boot/loader.conf:
412ipfw_load="YES"
413ipdivert_load="YES"
414
415$ dmesg | grep ipfw
416ipfw2 (+ipv6) initialized, divert loadable, nat loadable, rule-based
417forwarding disabled, default to deny, logging disabled
418
419$ kldload -v ipdivert
420Loaded ipdivert, id=4
421
422$ ipfw add 75 divert 8000 icmp from any to any
42300075 divert 8000 icmp from any to any
424
425$ ipfw list
426...
42700075 divert 8000 icmp from any to any
42800080 allow icmp from any to any
429...
430
431* Note that on FreeBSD, divert sockets don't work with bridges!
432
433Please refer to the following articles for more information:
434
435https://forums.snort.org/forums/support/topics/snort-inline-on-freebsd-ipfw
436http://freebsd.rogness.net/snort_inline/
437
438NAT gateway can be used with divert sockets if the network environment is
439conducive to using NAT.
440
441The steps to set up NAT with ipfw are as follows:
442
4431. Set up NAT with two interface em0 and em1 by adding
444the following to /etc/rc.conf
445
446gateway_enable="YES"
447natd_program="/sbin/natd"   # path to natd
448natd_enable="YES"           # Enable natd (if firewall_enable == YES)
449natd_interface="em0"       # Public interface or IP Address
450natd_flags="-dynamic"       # Additional flags
451defaultrouter=""
452ifconfig_em0="DHCP"
453ifconfig_em1="inet 192.168.1.2 netmask 255.255.255.0"
454firewall_enable="YES"
455firewall_script="/etc/rc.firewall"
456firewall_type="simple"
457
458Here em0 is connected to external network and em1 to host-only LAN.
459
4602. Add the following divert rules to divert packets to Snort above and
461below the NAT rule in the "Simple" section of /etc/rc.firewall.
462
463   ...
464   # Inspect outbound packets (those arriving on "inside" interface)
465   # before NAT translation.
466   ${fwcmd} add divert 8000 all from any to any in via ${iif}
467   case ${natd_enable} in
468   [Yy][Ee][Ss])
469       if [ -n "${natd_interface}" ]; then
470           ${fwcmd} add divert natd all from any to any via
471${natd_interface}
472       fi
473       ;;
474   esac
475   ...
476   # Inspect inbound packets (those arriving on "outside" interface)
477   # after NAT translation that aren't blocked for other reasons,
478   # after the TCP "established" rule.
479   ${fwcmd} add divert 8000 all from any to any in via ${oif}
480
481
482Notes on OpenBSD::IPFW
483======================
484
485OpenBSD supports divert sockets as of 4.7, so we use the ipfw DAQ.
486
487Here is one way to set things up:
488
4891.  Configure the system to forward packets:
490
491    $ sysctl net.inet.ip.forwarding=1
492    $ sysctl net.inet6.ip6.forwarding=1
493
494    (You can also put that in /etc/sysctl.conf to enable on boot.)
495
4962.  Set up interfaces
497
498    $ dhclient vic1
499    $ dhclient vic2
500
5013.  Set up packet filter rules:
502
503    $ echo "pass out on vic1 divert-packet port 9000 keep-state" > rules.txt
504    $ echo "pass out on vic2 divert-packet port 9000 keep-state" >> rules.txt
505
506    $ pfctl -v -f rules.txt
507
5084.  Analyze packets diverted to port 9000:
509
510    $ ./snort --daq ipfw --daq-var port=9000
511
512* Note that on OpenBSD, divert sockets don't work with bridges!
513
514