`ulog-acctd' 0.4 Manual

Table of Contents


Next: , Up: (dir)

TITLE

This manual is for ulog-acctd, version 0.4

Copyright © 2002 Hilko Bengen

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA


Next: , Previous: Top, Up: Top

1 Overview

ulog-acctd is a userspace network accounting daemon which generates log files of network traffic for accounting purposes.


Next: , Up: Overview

1.1 Features

ulog-acctd collects headers of IP packets fhat travel through the Linux 2.4+ Netfilter framework. It writes accounting information to a log which can include

The log file format is configurable. For instance, it should be possible to directly generate files that contain SQL statements so that the raw accounting data can be fed into a DBMS.


Next: , Previous: Features, Up: Overview

1.2 Nonfeatures

ulog-acctd only collects, aggregates, and logs the all data it is fed by netfilter. If only traffic for specific networks needs to be collected, selection for this should be done in the netfilter rulesets, as ulog-acctd has no way to ignore some packets and log others.

ulog-acctd does not analyze them nor paint pretty pictures for traffic visualization. In the "one tool for one job" spirit of UNIX, Other tools should be used for these tasks.


Previous: Nonfeatures, Up: Overview

1.3 Others


Next: , Up: Others

1.3.1 net–acct

net--acct (http://exorsus.net/projects/net–acct/) was developed by Ulrich Callmeier. The Mekafile hints that it can be used on Solaris (using libpcap). The Linux version uses the now obsolete packet interface at protocol level. (see ip(7)).

Information for net–acct is available at http://www.exorsus.net/net–acct/.

I had tried to implement support for the newer packet interface at device level (supported since Linux kernel versions 2.2, see packet(7)), but I found that it lost packets in high load situations. Patches against net--acct are available on request.

ulog-acctd is based on net--acct and still shares some portions of the code. net--acct does not seem to be actively maintained any longer.


Next: , Previous: net--acct, Up: Others

1.3.2 ipcad

ipcad stands for IP Cisco Accounting Daemon. It runs in background and listens traffic on the specified interfaces. Statistics are available through a Cisco–compatible rsh interface. ipcad can use the BPF interface or libpcap, which on Linux probably leads to packet less under high load, as described above.

ipcad is available from http://sourceforge.net/projects/ipcad.

It is certainly possible to set up a similar scenario with ulog-acctd with a small rsh daemon (or maybe just a shell script) which would emulate the relevant parts of Cisco command line syntax.


Next: , Previous: ipcad, Up: Others

1.3.3 traff

traff (http://sourceforge.net/projects/traff/) is a program that attaches itself to one or more network interfaces, sniffs all IP-packages passing at it and accounts each packets size. The collected information can be dumped to an SQL database (PostgreSQL or MySQL), syslog or a file.

Like ipcad, it uses libpcap.


Next: , Previous: traff, Up: Others

1.3.4 ipac–ng

ipac--ng regularly reads byte and packet counters associated with the Linux kernel's packet filter rules and stores those numbers in a database. This works well for a small number of IP addresses / ports, but it does not scale well since one rule in the packet filter is needed for each possible entry.


Previous: ipac--ng, Up: Others

1.3.5 ulogd

As the name suggests, ulogd uses the same approach for collecting IP packets as ulog-acctd does. ulogd can be extended through binary plugins for adding packet interpreters and output-targets (e.g. for logging into databases, user defined filetypes, etc.). It can be downloaded from http://www.gnumonks.org/projects/ulogd.


Next: , Previous: Overview, Up: Top

2 Installation

  1. Compile the sources: cd src; make
  2. Generate the documentation from the Texinfo source (optional): cd doc; make ulog-acctd.info ulog-acctd.html ulog-acctd.dvi
  3. Install the ulog-acctd binary into appropriate location, i.e. /usr/local/sbin.
  4. Install the configuration file src/ulog-acctd.conf to /etc and edit it to your needs.
  5. Create the directories for logging that are referenced in the configuration file. (In the default configuration, this is /var/log/ulog-acctd/.)


Next: , Previous: Installation, Up: Top

3 Configuration


Next: , Up: Configuration

3.1 Netfilter

ulog-acctd relies on the kernel (more specific: Netfilter) to pipe the packet headers to user space. This has to be enabled by adding rules with the ULOG target to packet filtering tables.

The following example causes all packets that successfully pass the FORWARD table to be logged to ulog-acctd.

     iptables --append FORWARD -j ULOG --ulog-nlgroup 1 --ulog-cprange 48 --ulog-qthreshold 50 --ulog-prefix "FORWARD"

Explaination:

For further information, see iptables(8).


Previous: Netfilter, Up: Configuration

3.2 ulog-acctd.conf

Per default, configuration is done via the file /etc/ulog-acctd.conf. The following keywords are recognized:

Example:

     
     multicast groups=1
     accounting file = /var/log/ulog-acctd/account.log
     dump file =       /var/log/ulog-acctd/dump
     debug file =      /var/log/ulog-acctd/debug.log
     debug = error
     accounting format = "%h\t%x\t%t\t%p\t%s\t%S\t%d\t%D\t%P\t%b\t\"%i\"\t\"%o\"\t\"%f\"\n"
     flush = 30
     fdelay = 30

The supplied accounting format string generates output records in the following form (all in one line, with a linefeed at the end):

judith	1032521450	1032521454	6	192.168.42.11	110	192.168.215.71	1546	12	250113	"eth0"	"eth1"	"prefix"

The following format string will generate cisco "ip accounting output-packets"-style output lines:

     
     accounting format = "%s %d %P %b\n"

The lines will look like this:

     
     192.168.42.11 192.168.215.71 12 250113

When not all types of information are collected, ulog-acctd will have to do fewer comparisions for each packet while collecting data. Records are smaller and likely fewer records will be written out. This will be the case especially if port information are not collected.


Next: , Previous: Configuration, Up: Top

4 Running


Next: , Up: Running

4.1 Invokation

ulog-acctd recognizes the following command-line parameters:


Next: , Previous: Invokation, Up: Running

4.2 Signals

The following signals are recognized by ulog-acctd:

`SIGHUP'
causes the config file to be re-read.
`SIGTSTP'
causes ulog-acctd to stop writing to the accounting logfile
`SIGCONT'
causes ulog-acctd to re-open both debug and log file and resume writing to the account log.
`SIGIOT'
causes ulog-acctd to re-open the capture socket.
`SIGINT'
`SIGTERM'
These signals stop the daemon, gracefully. The PID file is cleaned up and the IP data that is resident in memory is flushed to the accounting file.
`SIGKILL'
These signals stop the daemon.
`SIGALRM'
This is used internally. Do not send ulog-acctd this signal.


Next: , Previous: Signals, Up: Running

4.3 Rotating Log files

To cleanly rotate accounting log files, send SIGTSTP to the daemon, then move the logfiles out of the way, and finally send a SIGCONT to re-enable logging accounting data.

Be sure not to compress the log files immediately after rotating. When the accounting log file is written to, the writing process will create a hard link to the accounting file and gzip and bzip2 will not compress files with more than 1 link.


Previous: Rotating Log files, Up: Running

4.4 Hints

4.4.1 High CPU load and "No buffer space available" messages

This message in the debug log means that the kernel is delivering packets faster than ulog-acctd can process them. This happens most likely when ulog-acctd writes its accounting log to disk.

There are a few steps that can be taken both in kernel space and in ulog-acctd.

  1. Increase socket receive buffer. This requires that the kernel parameter net/core/rmem_max is set with sysctl(8) to allow for a larger socket receive buffer.
  2. Increase hash table size. However, be sure that the size of the hash table is a prime number.
  3. Set a nice value for the child process that writes the account log.
  4. Increase the --ulog-qthreshold value, if approtpiate
  5. Decrease the --ulog-cprange value, if approtpiate. Experience shows that 24 to 32 bytes are enough for normal IP traffic.

4.4.2 fdelay

The fdelay configuration parameter can be used to reduce log file size where ulog-acctd is used to account many long-lasting connections and where it is not strictly necessary that the time values are absolutely correct.

4.4.3 The dump file

When fdelay is set to a non-zero value, ulog-acctd writes an additional dump file every time it writes to the accounting log. This dump file contains those records that have been kept in memory. If ulog-acctd crashes before writing to the accounting log file, these entries can still be recovered by the system administrator.


Previous: Running, Up: Top

5 Credits

ulog-acctd was written by Hilko Bengen. Source tarballs and public CVS are accessible through http://alioth.debian.org/projects/pkg-ulog-acctd.

Thanks go to

Initial work (up to version 0.4.1) on this program was funded by toplink–plannet GmbH, Karlsruhe, Germany http://www.toplink-plannet.de/.