Fixes & tweaks for sample and hold accounting.
[distributedratelimiting.git] / doc / ulogd.txt
1   ULOGD - the Userspace Logging Daemon
2   Harald Welte <laforge@gnumonks.org>
3   Revision $Revision: 5846 $, $Date: 2005-07-12 17:33:23 +0200
4   (Tue, 12 Jul 2005) $
5
6   This is the documentation for ulogd, the Userspace logging daemon.
7   ulogd makes use of the Linux >= 2.4.x packet filter subsystem (ipta-
8   bles) and the ULOG target for iptables.
9   ______________________________________________________________________
10
11   Table of Contents
12
13
14   1. DESIGN
15      1.1 CONCEPT
16      1.2 DETAILS
17
18   2. INSTALLATION
19      2.1 Linux kernel
20      2.2 ipt_ULOG from netfilter/iptables patch-o-matic
21      2.3 ulogd
22         2.3.1 Recompiling the source
23         2.3.2 Using a precompiled package
24
25   3. Configuration
26      3.1 iptables ULOG target
27         3.1.1 Quick Setup
28         3.1.2 ULOG target reference
29         3.1.3 ipt_ULOG module parameters
30      3.2 ulogd
31         3.2.1 ulogd configfile syntax reference
32         3.2.2 ulogd commandline option reference
33
34   4. Available plugins
35      4.1 Interpreter plugins
36         4.1.1 ulogd_BASE.so
37         4.1.2 ulogd_PWSNIFF.so
38         4.1.3 ulogd_LOCAL.so
39      4.2 Output plugins
40         4.2.1 ulogd_OPRINT.so
41         4.2.2 ulogd_LOGEMU.so
42         4.2.3 ulogd_MYSQL.so
43         4.2.4 ulogd_PGSQL.so
44         4.2.5 ulogd_PCAP.so
45         4.2.6 ulogd_SQLITE3.so
46         4.2.7 ulogd_SYSLOG.so
47
48   5. QUESTIONS / COMMENTS
49
50
51   ______________________________________________________________________
52
53   \e[1m1.  DESIGN\e[0m
54
55   \e[1m1.1.  CONCEPT\e[0m
56
57   I want to provide a flexible, almost universal logging daemon for my
58   netfilter ULOG target. It is not optimized in any way, the goal is to
59   keep as simple as possible. These are my thoughts about how the
60   architecture which is most capable of doing that:
61
62
63      \e[1mInterpreter plugins\e[0m
64         It should be possible to add plugins / runtime modules for new
65         protocols, etc.  For example the standard logging daemon
66         provides source-ip, dest-ip, source-port, dest-port, etc.
67         Logging for various other protocols (GRE, IPsec, ...) may be
68         implemented as modules.
69
70
71      \e[1mOutput plugins\e[0m
72         ... describe how and where to put the information gained by
73         logging plugins.  The easiest way is to build a line per packet
74         and fprint it to a file.  Some people might want to log into a
75         SQL database or want an output conforming to the intrusion
76         detection systems communication draft from the IETF.
77
78
79
80   \e[1m1.2.  DETAILS\e[0m
81
82   The major clue is providing a framework which is as flexible as
83   possible.  Nobody knows what strange network protocols are out there
84   :) Flexibility depends on the communication between the output of the
85   logging plugins and input of the output plugins.
86
87   Rusty advised me to use some kind of type-key-value triples, which is
88   in fact what I implemented.
89
90   One issue is, of course, performance. Up to ulogd 0.3, ulogd did
91   several linked list iterations and about 30 malloc() calls _per
92   packet_. This changed with the new >= 0.9 revisions:
93
94   o  Not a single dynamic allocation in the core during runtime.
95      Everything is pre-allocated at start of ulogd to provide the
96      highest possible throughput.
97
98   o  Hash tables in addition to the linked lists. Linked lists are only
99      traversed if we really want to access each element of the list.
100
101
102   \e[1m2.  INSTALLATION\e[0m
103
104
105   \e[1m2.1.  Linux kernel\e[0m
106
107   First you will need a recent 2.4.x kernel.  If you have a kernel >=
108   2.4.18-pre8, it already has the kernel support for ULOG (ipt_ULOG.o).
109
110   If you have an older kernel version (between 2.4.0 and 2.4.18-pre6),
111   you can use the patch-o-matic system of netfilter/iptables, as
112   described in the following section.
113
114
115   \e[1m2.2.  ipt_ULOG from netfilter/iptables patch-o-matic\e[0m
116
117   You only need to read this chapter if you have a 2.4.x kernel <=
118   2.4.18-pre6.
119
120   In order to put the ipt_ULOG module into your kernel source,you need
121   the latest iptables package, or even better: the latest CVS snapshot.
122   A description how to obtain this is provided on the netfilter homepage
123   <http://www.netfilter.org/>.
124
125   To run patch-o-matic, just type
126
127
128        make patch-o-matic
129
130
131
132   in the userspace directory of netfilter CVS.
133
134
135   \e[1m2.3.  ulogd\e[0m
136
137   \e[1m2.3.1.  Recompiling the source\e[0m
138
139   Download the ulogd package from  <http://ftp.netfilter.org/pub/ulogd/>
140   and untar it.
141
142   If you want to build ulogd with MySQL support, type './configure
143   --with-mysql'. You may also have to specify the path of the mysql
144   libraries using '--with-mysql=path'. To build ulogd without MySQL
145   support, just use './configure'.
146
147   To compile and install the program, call 'make install'.
148
149
150   \e[1m2.3.2.  Using a precompiled package\e[0m
151
152   I also provide a SRPM, which should compile on almost any rpm-based
153   distribution. It is available at
154   <http://ftp.netfilter.org/pub/ulogd/>
155
156   Just download the package and do the usual 'rpm --rebuild <file>'.
157
158
159   \e[1m3.  Configuration\e[0m
160
161   \e[1m3.1.  iptables ULOG target\e[0m
162
163   \e[1m3.1.1.  Quick Setup\e[0m
164
165   Just add rules using the ULOG target to your firewalling chain. A very
166   basic example:
167
168
169        iptables -A FORWARD -j ULOG --ulog-nlgroup 32 --ulog-prefix foo
170
171
172
173   To increase logging performance, try to use the
174
175
176        --ulog-qthreshold N
177
178
179
180   option (where 1 < N <= 50). The number you specify is the amount of
181   packets batched together in one multipart netlink message. If you set
182   this to 20, the kernel schedules ulogd only once every 20 packets. All
183   20 packets are then processed by ulogd. This reduces the number of
184   context switches between kernel and userspace.
185
186   Of course you can combine the ULOG target with the different netfilter
187   match modules.  For a more detailed description, have a look at the
188   netfilter HOWTO's, available on the netfilter homepage.
189
190   \e[1m3.1.2.  ULOG target reference\e[0m
191
192
193      \e[1m--ulog-nlgroup N\e[0m
194         The number of the netlink multicast group to which ULOG'ed
195         packets are sent.  You will have to use the same group number in
196         the ULOG target and ulogd in order to make logging work.
197
198      \e[1m--ulog-cprange N\e[0m
199         Copyrange.  This works like the 'snaplen' parameter of tcpdump.
200         You can specify a number of bytes up to which the packet is
201         copied.  If you say '40', you will receive the first fourty
202         bytes of every packet. Leave it to 0
203
204      \e[1m--ulog-qthreshold N\e[0m
205         Queue threshold.  If a packet is matched by the iptables rule,
206         and already N packets are in the queue, the queue is flushed to
207         userspace.  You can use this to implement a policy like: Use a
208         big queue in order to gain high performance, but still have
209         certain packets logged immediately to userspace.
210
211      \e[1m--ulog-prefix STRING\e[0m
212         A string that is associated with every packet logged by this
213         rule.  You can use this option to later tell from which rule the
214         packet was logged.
215
216
217   \e[1m3.1.3.  ipt_ULOG module parameters\e[0m
218
219   The ipt_ULOG kernel module has a couple of module loadtime parameters
220   which can (and should) be tuned to accomodate the needs of the
221   application:
222
223      \e[1mnlbufsiz N\e[0m
224         Netlink buffer size. A buffer of the specified size N is
225         allocated for every netlink group that is used.  Please note
226         that due to restrictions of the kernel memory allocator, we
227         cannot have a buffer size > 128kBytes.  Larger buffer sizes
228         increase the performance, since less kernel/userspace context
229         switches are needed for the same amount of packets.  The
230         backside of this performance gain is a potentially larger delay.
231         The default value is 4096 bytes, which is quite small.
232
233      \e[1mflushtimeout N\e[0m
234         The flushtimeout determines, after how many clock ticks (on
235         alpha: 1ms, on x86 and most other platforms: 10ms time units)
236         the buffer/queue is to be flushed, even if it is not full.  This
237         can be used to have the advantage of a large buffer, but still a
238         finite maximum delay introduced.  The default value is set to 10
239         seconds.
240
241   Example:
242
243
244        modprobe ipt_ULOG nlbufsiz=65535 flushtimeout=100
245
246
247
248   This would use a buffer size of 64k and a flushtimeout of 100 clock-
249   ticks (1 second on x86).
250
251
252   \e[1m3.2.  ulogd\e[0m
253
254   ulogd is what this is all about, so let's describe it's
255   configuration...
256
257   \e[1m3.2.1.  ulogd configfile syntax reference\e[0m
258
259   All configurable parameters of ulogd are in the configfile, typically
260   located at '/etc/ulogd.conf'.
261   The following configuration parameters are available:
262
263      \e[1mnlgroup\e[0m
264         The netlink multicast group, which ulgogd should bind to. This
265         is the same as given with the '--ulog-nlgroup' option to
266         iptables.
267
268      \e[1mlogfile\e[0m
269         The main logfile, where ulogd reports any errors, warnings and
270         other unexpected conditions. Apart from a regular filename, the
271         following special values can be used; ``syslog'' to log via the
272         unix syslog(3) mechanism.  ``stdout'' to log to stdout.
273
274      \e[1mloglevel\e[0m
275         This specifies, how verbose the logging to logfile is. Currently
276         defined loglevels are: 1=debug information, 3=informational
277         messages, 5=noticable exceptional conditions, 7=error
278         conditions, 8=fatal errors, program abort.
279
280      \e[1mplugin\e[0m
281         This option is followed by a filename of a ulogd plugin, which
282         ulogd shold load upon initialization. This option may appear
283         more than once.
284
285      \e[1mrmem\e[0m
286         Size of the netlink socket receive memory.  You should set this
287         to at least the size of the kernel buffer (nlbufsiz parameter of
288         the ipt_ULOG module).  Please note that there is a maximum limit
289         in /proc/sys/net/core/rmem_max which you cannot exceed by
290         increasing the ``rmem'' parameter.  You may need to raise the
291         system-wide maximum limit before.
292
293      \e[1mbufsize\e[0m
294         Size of the receive buffer. You should set this to at least the
295         socket receive buffer (rmem).
296
297   \e[1m3.2.2.  ulogd commandline option reference\e[0m
298
299   Apart from the configfile, there are a couple of commandline options
300   to ulogd:
301
302      \e[1m-h --help\e[0m
303         Print a help message about the commandline options.
304
305      \e[1m-V --version\e[0m
306         Print version information about ulogd.
307
308      \e[1m-d --daemon\e[0m
309         For off into daemon mode.  Unless you are debugging, you will
310         want to use this most of the time.
311
312      \e[1m-c --configfile\e[0m
313         Using this commandline option, an alternate config file can be
314         used.  This is important if multiple instances of ulogd are to
315         be run on a single machine.
316
317
318   \e[1m4.  Available plugins\e[0m
319
320   It is important to understand that ulogd without plugins does nothing.
321   It will receive packets, and do nothing with them.
322
323   There are two kinds of plugins, interpreter and output plugins.
324   Interpreter plugins parse the packet, output plugins write the
325   interpreted information to some logfile/database/...
326
327   \e[1m4.1.  Interpreter plugins\e[0m
328
329   ulogd comes with the following interpreter plugins:
330
331   \e[1m4.1.1.  ulogd_BASE.so\e[0m
332
333   Basic interpreter plugin for nfmark, timestamp, mac address, ip
334   header, tcp header, udp header, icmp header, ah/esp header... Most
335   people will want to load this very important plugin.
336
337   \e[1m4.1.2.  ulogd_PWSNIFF.so\e[0m
338
339   Example interpreter plugin to log plaintext passwords as used with FTP
340   and POP3. Don't blame me for writing this plugin! The protocols are
341   inherently insecure, and there are a lot of other tools for sniffing
342   passwords... it's just an example.
343
344   \e[1m4.1.3.  ulogd_LOCAL.so\e[0m
345
346   This is a 'virtual interpreter'.  It doesn't really return any
347   information on the packet itself, rather the local system time and
348   hostname.  Please note that the time is the time at the time of
349   logging, not the packets receive time.
350
351
352   \e[1m4.2.  Output plugins\e[0m
353
354   ulogd comes with the following output plugins:
355
356
357   \e[1m4.2.1.  ulogd_OPRINT.so\e[0m
358
359   A very simple output module, dumping all packets in the format
360
361
362        ===>PACKET BOUNDARY
363        key=value
364        key=value
365        ...
366        ===>PACKET BOUNDARY
367        ...
368
369
370
371   to a file.  The only useful application is debugging.
372
373   The module defines the following configuration directives:
374
375      \e[1mdumpfile\e[0m
376         The filename where it should log to. The default is
377         /var/log/ulogd.pktlog
378
379
380   \e[1m4.2.2.  ulogd_LOGEMU.so\e[0m
381
382   An output module which tries to emulate the old syslog-based LOG
383   targed as far as possible. Logging is done to a seperate textfile
384   instead of syslog, though.
385
386   The module defines the following configuration directives:
387
388      \e[1mfile\e[0m
389         The filename where it should log to. The default is
390         /var/log/ulogd.syslogemu
391
392      \e[1msync\e[0m
393         Set this to 1 if you want to have your logfile written
394         synchronously. This may reduce performance, but makes your log-
395         lines appear immediately.  The default is 0
396
397
398   \e[1m4.2.3.  ulogd_MYSQL.so\e[0m
399
400   An output plugin for logging into a mysql database. This is only
401   compiled if you have the mysql libraries installed, and the configure
402   script was able to detect them. (that is: --with-mysql was specified
403   for ./configure)
404
405
406   The plugin automagically inserts the data into the configured table;
407   It connects to mysql during the startup phase of ulogd and obtains a
408   list of the columns in the table. Then it tries to resolve the column
409   names against keys of interpreter plugins. This way you can easily
410   select which information you want to log - just by the layout of the
411   table.
412
413
414   If, for example, your table contains a field called 'ip_saddr', ulogd
415   will resolve this against the key 'ip.saddr' and put the ip address as
416   32bit unsigned integer into the table.
417
418
419   You may want to have a look at the file 'doc/mysql.table' as an
420   example table including fields to log all keys from ulogd_BASE.so.
421   Just delete the fields you are not interested in, and create the
422   table.
423
424
425   The module defines the following configuration directives:
426
427      \e[1mtable\e[0m
428         Name of the table to which ulogd should log.
429
430      \e[1mldb\e[0m
431         Name of the mysql database.
432
433      \e[1mhost\e[0m
434         Name of the mysql database host.
435
436      \e[1mport\e[0m
437         TCP port number of mysql database server.
438
439      \e[1muser\e[0m
440         Name of the mysql user.
441
442      \e[1mpass\e[0m
443         Password for mysql.
444
445
446   \e[1m4.2.4.  ulogd_PGSQL.so\e[0m
447
448   An output plugin for logging into a postgresql database. This is only
449   compiled if you have the mysql libraries installed, and the configure
450   script was able to detect them. (that is: --with-pgsql was specified
451   for ./configure)
452
453
454   The plugin automagically inserts the data into the configured table;
455   It connects to pgsql during the startup phase of ulogd and obtains a
456   list of the columns in the table. Then it tries to resolve the column
457   names against keys of interpreter plugins. This way you can easily
458   select which information you want to log - just by the layout of the
459   table.
460
461
462   If, for example, your table contains a field called 'ip_saddr', ulogd
463   will resolve this against the key 'ip.saddr' and put the ip address as
464   32bit unsigned integer into the table.
465
466
467   You may want to have a look at the file 'doc/mysql.table' as an
468   example table including fields to log all keys from ulogd_BASE.so.
469   Just delete the fields you are not interested in, and create the
470   table.
471
472
473   The module defines the following configuration directives:
474
475      \e[1mtable\e[0m
476         Name of the table to which ulogd should log.
477
478      \e[1mdb \e[22mName of the database.
479
480      \e[1mhost\e[0m
481         Name of the mysql database host.
482
483      \e[1mport\e[0m
484         TCP port number of database server.
485
486      \e[1muser\e[0m
487         Name of the sql user.
488
489      \e[1mpass\e[0m
490         Password for sql user.
491
492
493   \e[1m4.2.5.  ulogd_PCAP.so\e[0m
494
495   An output plugin that can be used to generate libpcap-style packet
496   logfiles.  This can be useful for later analysing the packet log with
497   tools like tcpdump or ethereal.
498
499   The module defines the following configuration directives:
500
501      \e[1mfile\e[0m
502         The filename where it should log to.  The default is:
503         /var/log/ulogd.pcap
504
505      \e[1msync\e[0m
506         Set this to 1 if you want to have your pcap logfile written
507         synchronously.  This may reduce performance, but makes your
508         packets appear immediately in the file on disk.  The default is
509         0
510
511
512   \e[1m4.2.6.  ulogd_SQLITE3.so\e[0m
513
514   An output plugin for logging into a SQLITE v3 database. This is only
515   compiled if you have the sqlite libraries installed, and the configure
516   script was able to detect them. (that is: --with-sqlite3 was specified
517   for ./configure)
518
519
520   The plugin automagically inserts the data into the configured table;
521   It opens the sqlite db during the startup phase of ulogd and obtains a
522   list of the columns in the table. Then it tries to resolve the column
523   names against keys of interpreter plugins. This way you can easily
524   select which information you want to log - just by the layout of the
525   table.
526
527
528   If, for example, your table contains a field called 'ip_saddr', ulogd
529   will resolve this against the key 'ip.saddr' and put the ip address as
530   32bit unsigned integer into the table.
531
532
533   You may want to have a look at the file 'doc/sqlite3.table' as an
534   example table including fields to log all keys from ulogd_BASE.so.
535   Just delete the fields you are not interested in, and create the
536   table.
537
538
539   The module defines the following configuration directives:
540
541      \e[1mtable\e[0m
542         Name of the table to which ulogd should log.
543
544      \e[1mdb \e[22mName of the database.
545
546      \e[1mbuffer\e[0m
547         Size of the sqlite buffer.
548
549   \e[1m4.2.7.  ulogd_SYSLOG.so\e[0m
550
551   An output plugin that really logs via syslogd. Lines will look exactly
552   like printed with traditional LOG target.
553
554
555   The module defines the following configuration directives:
556
557      \e[1mfacility\e[0m
558         The syslog facility (LOG_DAEMON, LOG_KERN, LOG_LOCAL0 ..
559         LOG_LOCAL7, LOG_USER)
560
561      \e[1mlevel\e[0m
562         The syslog level (LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR,
563         LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG)
564
565   \e[1m5.  QUESTIONS / COMMENTS\e[0m
566
567   All comments / questions / ... are appreciated.
568
569   Just drop me a note to laforge@gnumonks.org
570
571   Please note also that there is now a mailinglist,
572   ulogd@lists.gnumonks.org.  You can subscribe at
573   <http://lists.gnumonks.org/mailman/listinfo/ulogd/>.
574
575
576   The preferred method for reporting bugs is the netfilter bugzilla
577   system, available at  <http://bugzilla.netfilter.org/>.
578
579
580