]> git.ipfire.org Git - thirdparty/ulogd2.git/log
thirdparty/ulogd2.git
3 years agobuild: use pkg-config or pg_config for libpq
Jeremy Sowden [Sun, 9 Jan 2022 11:57:48 +0000 (11:57 +0000)] 
build: use pkg-config or pg_config for libpq

Recent versions of postgresql support pkg-config.  Use pkg-config if
available, otherwise fall back to pg_config.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: use pkg-config or pcap-config for libpcap
Jeremy Sowden [Sun, 9 Jan 2022 11:57:47 +0000 (11:57 +0000)] 
build: use pkg-config or pcap-config for libpcap

Recent versions of libpcap support pkg-config.  Older versions provide a
pcap-config script.  Use pkg-config if available, otherwise fall back to
pcap-config.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: use pkg-config or mysql_config for libmysqlclient
Jeremy Sowden [Sun, 9 Jan 2022 11:57:46 +0000 (11:57 +0000)] 
build: use pkg-config or mysql_config for libmysqlclient

Recent versions of mariadb and mysql support pkg-config.  Older versions
provide a mysql_config script.  Use pkg-config if available, otherwise
fall back to mysql_config.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: use pkg-config for libdbi
Jeremy Sowden [Sun, 9 Jan 2022 11:57:45 +0000 (11:57 +0000)] 
build: use pkg-config for libdbi

libdbi introduced pkg-config support in 0.9.0, which was released in
2013.  Use it.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: use `--enable-XYZ` options for output plugins
Jeremy Sowden [Sun, 9 Jan 2022 11:57:44 +0000 (11:57 +0000)] 
build: use `--enable-XYZ` options for output plugins

Currently, we use `AC_ARG_WITH` for output plugins.  However, this is
not consistent with the input plugins, which use `AC_ARG_ENABLE`, and in
some cases (dbi, mysql, pgsql) the macro calls in configure.ac conflict
with others in acinclude.m4.  Use `AC_ARG_ENABLE` instead and change the
name of the option for the JSON plugin from `jansson` to `json`.

Fixes: 51ba7aec8951 ("Fix automagic support of dbi, pcap and sqlite3")
Fixes: c61c05c2d050 ("configure.ac: Add --without-{mysql,pgsql}")
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: SQLITE3: remove unused variable
Jeremy Sowden [Wed, 5 Jan 2022 22:37:21 +0000 (22:37 +0000)] 
output: SQLITE3: remove unused variable

There's local variable left over from a previous tidy-up.  Remove it.

Fixes: 67b0be90f16f ("output: SQLITE3: improve mapping of fields to DB columns")
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: GPRINT: fix it with NFLOG
Pablo Neira Ayuso [Tue, 4 Jan 2022 11:17:11 +0000 (12:17 +0100)] 
output: GPRINT: fix it with NFLOG

Add ULOGD_DTYPE_RAW to GPRINT to make it work, it does not provide much
information since raw packets come with only a few fields set on.

Therefore, update example ulogd.conf.in file since BASE provides a more
complete packet dissection.

Fixes: 59a71256945d ("src: add example use of GPRINT to ulogd.conf.in configuration file")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: JSON: remove bogus check for host and port
Pablo Neira Ayuso [Mon, 3 Jan 2022 18:11:38 +0000 (19:11 +0100)] 
output: JSON: remove bogus check for host and port

struct config_entry already provides storage for the host and port
strings, .u.string is never NULL.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: JSON: fix possible truncation of socket path
Pablo Neira Ayuso [Mon, 3 Jan 2022 18:11:37 +0000 (19:11 +0100)] 
output: JSON: fix possible truncation of socket path

Verify that the path is shorter than 108 bytes (maximum unix socket path).

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: IPFIX: remove compiler attribute macros
Jeremy Sowden [Tue, 30 Nov 2021 10:56:00 +0000 (10:56 +0000)] 
output: IPFIX: remove compiler attribute macros

The ipfix.h header includes three macros which expand to compiler attributes.
Presumably, at some point the definitions were one branch of an if-else
preprocessor conditional where the definitions in the other branch expanded to
nothing.  This is no longer the case.  Only one of the macros (`__packed`) is
used and the raw attribute is used elsewhere in the code-base.  Remove the
macros.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: JSON: optimize appending of newline to output
Jeremy Sowden [Tue, 30 Nov 2021 10:55:58 +0000 (10:55 +0000)] 
output: JSON: optimize appending of newline to output

We have `buflen` available.  We can remove `strncat` and assign the characters
directly, without traversing the whole buffer.

Fixes a compiler warning:

  logd_output_JSON.c:407:9: warning: `strncat` specified bound 1 equals source length

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: JSON: fix possible leak in error-handling.
Jeremy Sowden [Tue, 30 Nov 2021 10:55:57 +0000 (10:55 +0000)] 
output: JSON: fix possible leak in error-handling.

The `realloc` extending the buffer containing the JSON to allow us to
insert a final new-line may fail.  Therefore, we need to assign the
return-value to a temporary variable or we will not able to free the
existing buffer on error.

Use the correct type for `buflen`.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: JSON: increase time-stamp buffer size
Jeremy Sowden [Tue, 30 Nov 2021 10:55:56 +0000 (10:55 +0000)] 
output: JSON: increase time-stamp buffer size

The output buffer for date-times is of sufficient size provided that we
don't get oversized integer values for any of the fields, which is a
reasonable assumption.  However, the compiler complains about possible
truncation, e.g.:

  ulogd_output_JSON.c:314:65: warning: `%06u` directive output may be truncated writing between 6 and 10 bytes into a region of size between 0 and 18
  ulogd_output_JSON.c:313:25: note: `snprintf` output between 27 and 88 bytes into a destination of size 38

Fix the warnings by increasing the buffer size.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: JSON: fix output of GMT offset
Jeremy Sowden [Tue, 30 Nov 2021 10:55:55 +0000 (10:55 +0000)] 
output: JSON: fix output of GMT offset

The compiler has two sets of complaints.  Firstly, `t->tm_gmtoffset` is
a `long int`, but it is being passed to `abs`, which leads to warnings
such as:

  ulogd_output_JSON.c:308:34: warning: absolute value function `abs` given an argument of type `long int` but has parameter of type `int` which may cause truncation of value

Secondly, it can't verify that the hour value derived from the offset
will in fact fit into `%02d`, thus:

  ulogd_output_JSON.c:306:37: warning: `%02d` directive output may be truncated writing between 2 and 6 bytes into a region of size 5

To remedy these, we now mod the offset by 86,400 and assign it to an `int`
before deriving the hour and minute values.

We also change the format-specifier for the hour value to `%+03d` which
causes a sign to be printed even if the value is positive, thus allowing
us not to specify the sign explicitly and to drop the `abs` call for the
hour value.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agodb: simplify initialization of ring-buffer
Jeremy Sowden [Tue, 30 Nov 2021 10:55:54 +0000 (10:55 +0000)] 
db: simplify initialization of ring-buffer

Currently, `strncpy` is used to copy the SQL statement to the ring
buffer, passing the length of the source string, which leads gcc to
complain:

  ../../util/db.c:231:25: warning: `strncpy` specified bound depends on the length of the source argument

In fact, the ring buffer is sized to be a multiple of the size of the
SQL buffer, and the SQL is simply copied multiple times at increasing
offsets, so use `strcpy` instead.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agodb: improve mapping of input-keys to DB columns
Jeremy Sowden [Tue, 30 Nov 2021 10:55:53 +0000 (10:55 +0000)] 
db: improve mapping of input-keys to DB columns

Currently, we copy the key-name to a buffer, iterate over it to replace
the full-stops with underscores, using `strchr` from the start of the
buffer on each iteration, then append the buffer to the SQL statement.

Apart from the inefficiency, `strncpy` is used to do the copies, which
leads gcc to complain:

  ../../util/db.c:118:25: warning: `strncpy` output may be truncated copying 31 bytes from a string of length 31

Furthermore, the buffer is one character too short and so there is the
possibility of overruns.

Instead, append the key-name directly to the statement using `sprintf`,
and run `strchr` from the last underscore on each iteration.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agodb: improve formatting of insert statement
Jeremy Sowden [Tue, 30 Nov 2021 10:55:52 +0000 (10:55 +0000)] 
db: improve formatting of insert statement

`sql_createstmt` contains a variable `stmt_val` which points to the end
of the SQL already written, where the next chunk should be appended.
Currently, this is assigned after every write:

  sprintf(stmt_val, ...);
  stmt_val = mi->stmt + strlen(mi->stmt);

However, since `sprintf` returns the number of bytes written, increment
`stmt_val` by the return-value of `sprintf` in order to avoid the
repeated `strlen` calls.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: SQLITE3: catch errors creating SQL statement
Jeremy Sowden [Tue, 30 Nov 2021 10:55:51 +0000 (10:55 +0000)] 
output: SQLITE3: catch errors creating SQL statement

`sqlite3_createstmt` returns non-zero on error, but the return-value was
being ignored.  Change the calling code to check the return-value, log
an error message and propagate the error.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: SQLITE3: improve mapping of fields to DB columns
Pablo Neira Ayuso [Mon, 3 Jan 2022 15:10:01 +0000 (16:10 +0100)] 
output: SQLITE3: improve mapping of fields to DB columns

Currently, we derive a field-name by replacing all the underscores in a
DB column-name with full-stops and use the field-name to find the
matching input-key.  However, every time we create a new insert SQL
statement, we derive the column-names by copying the field-names to a
buffer, replacing all the full-stops with underscores, and then
appending the buffer containing the column-name to the one containing
the statments.

Apart from the inefficiency, `strncpy` is used to do the copies, which
leads gcc to complain:

  ulogd_output_SQLITE3.c:234:17: warning: `strncpy` output may be truncated copying 31 bytes from a string of length 31

Instead, leave the underscores in the field-name, but copy it once to a
buffer in which the underscores are replaced and use this to find the
input-key.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: SQLITE3: improve mapping of DB columns to fields
Jeremy Sowden [Tue, 30 Nov 2021 10:55:49 +0000 (10:55 +0000)] 
output: SQLITE3: improve mapping of DB columns to fields

Currently, we copy the column-name to a buffer, iterate over it to
replace the underscores with full-stops, using `strchr` from the start
of the buffer on each iteration, then copy the buffer to the field's
`name` member.

Apart from the inefficiency, `strncpy` is used to do the copies, which
leads gcc to complain:

  ulogd_output_SQLITE3.c:341:17: warning: `strncpy` output may be truncated copying 31 bytes from a string of length 31

Furthermore, the buffer is not initialized, which means that there is
also a possible buffer overrun if the column-name is too long, since
`strncpy` will not append a NUL.

Instead, copy the column-name directly to the field using `snprintf`,
and run `strchr` from the last underscore on each iteration.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: SQLITE3: improve formatting of insert statement
Jeremy Sowden [Tue, 30 Nov 2021 10:55:48 +0000 (10:55 +0000)] 
output: SQLITE3: improve formatting of insert statement

`sqlite3_createstmt` contains a variable `stmt_pos` which points to the
end of the SQL already written, where the next chunk should be appended.
Currently, this is assigned after every write:

  sprintf(stmt_pos, ...);
  stmt_pos = priv->stmt + strlen(priv->stmt);

However, since `sprintf` returns the number of bytes written, increment
`stmt_pos` by the return-value of `sprintf` in order to avoid the
repeated `strlen` calls.

Pablo mangled this original patch to add this chunk at the end of this
patch (originally submitted as a conversion to use strcpy).

+       for (i = 0; i < cols - 1; i++)
+               stmt_pos += sprintf(stmt_pos, "?,");

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: bump libnetfilter_log dependency
Jeremy Sowden [Sat, 4 Dec 2021 20:56:00 +0000 (20:56 +0000)] 
build: bump libnetfilter_log dependency

Recent changes to add conntrack info to the NFLOG output plug-in rely on
symbols only present in the headers provided by libnetfilter-log v1.0.2:

    CC       ulogd_inppkt_NFLOG.lo
  ulogd_inppkt_NFLOG.c: In function 'build_ct':
  ulogd_inppkt_NFLOG.c:346:34: error: 'NFULA_CT' undeclared (first use in this function); did you mean 'NFULA_GID'?
     if (mnl_attr_get_type(attr) == NFULA_CT) {
                                    ^~~~~~~~
                                    NFULA_GID
  ulogd_inppkt_NFLOG.c:346:34: note: each undeclared identifier is reported only once for each function it appears in
  ulogd_inppkt_NFLOG.c: In function 'start':
  ulogd_inppkt_NFLOG.c:669:12: error: 'NFULNL_CFG_F_CONNTRACK' undeclared (first use in this function); did you mean 'NFULNL_CFG_F_SEQ'?
     flags |= NFULNL_CFG_F_CONNTRACK;
              ^~~~~~~~~~~~~~~~~~~~~~
              NFULNL_CFG_F_SEQ

Bump the pkg-config version accordingly.

Fixes: f6a615587a10 ("NFLOG: attach struct nf_conntrack")
Fixes: e513a04cd925 ("NFLOG: add NFULNL_CFG_F_CONNTRACK flag")
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: SQLITE3: fix memory-leak in error-handling
Jeremy Sowden [Tue, 30 Nov 2021 10:55:47 +0000 (10:55 +0000)] 
output: SQLITE3: fix memory-leak in error-handling

When mapping DB column names to input-keys, if we cannot find a key to
match a column, the newly allocated `struct field` is leaked.  Free it,
and log an error message.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: SQLITE3: fix possible buffer overruns
Jeremy Sowden [Tue, 30 Nov 2021 10:55:46 +0000 (10:55 +0000)] 
output: SQLITE3: fix possible buffer overruns

There is a an off-by-one error in the size of some of the buffers used
to hold key-names.  The maximum length of a name is `ULOGD_MAX_KEYLEN`,
and so declare the buffers with size `ULOGD_MAX_KEYLEN + 1`.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: PGSQL: fix non-`connstring` configuration of DB connection
Jeremy Sowden [Tue, 30 Nov 2021 10:55:45 +0000 (10:55 +0000)] 
output: PGSQL: fix non-`connstring` configuration of DB connection

In `open_db_pgsql`, we test whether various config-settings are defined
by comparing their string values to `NULL`.  However, the `u.string`
member of `struct config_entry` is an array, not a pointer, so it is
never `NULL`.  Instead, check whether the string is empty.

Use a pointer to the end of the `connstr` buffer and `sprintf`, rather
than repeated `strcat`s.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: PGSQL: improve mapping of DB columns to input-keys
Jeremy Sowden [Tue, 30 Nov 2021 10:55:44 +0000 (10:55 +0000)] 
output: PGSQL: improve mapping of DB columns to input-keys

Currently, we copy the column-name to a buffer, iterate over it to
replace the underscores with full-stops, using `strchr` from the start
of the buffer on each iteration, then copy the buffer to the input-key's
`name` member.

Apart from the inefficiency, `strncpy` is used to do the copies, which
leads gcc to complain:

  ulogd_output_PGSQL.c:204:17: warning: `strncpy` output may be truncated copying 31 bytes from a string of length 31

Furthermore, the buffer is not initialized, which means that there is
also a possible buffer overrun if the column-name is too long, since
`strncpy` will not append a NUL.

Instead, copy the column-name directly to the input-key using
`snprintf`, and run `strchr` from the last underscore on each iteration.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: MYSQL: improve mapping of DB columns to input-keys
Jeremy Sowden [Tue, 30 Nov 2021 10:55:43 +0000 (10:55 +0000)] 
output: MYSQL: improve mapping of DB columns to input-keys

Currently, we copy the column-name to a buffer, iterate over it to
replace the underscores with full-stops, using `strchr` from the start
of the buffer on each iteration, then copy the buffer to the input-key's
`name` member.

Apart from the inefficiency, `strncpy` is used to do the copies, which
leads gcc to complain:

  ulogd_output_MYSQL.c:149:17: warning: `strncpy` output may be truncated copying 31 bytes from a string of length 31

Furthermore, the buffer is not initialized, which means that there is
also a possible buffer overrun if the column-name is too long, since
`strncpy` will not append a NUL.

Instead, copy the column-name directly to the input-key using
`snprintf`, and run `strchr` from the last underscore on each iteration.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: DBI: fix configuration of DB connection
Jeremy Sowden [Tue, 30 Nov 2021 10:55:42 +0000 (10:55 +0000)] 
output: DBI: fix configuration of DB connection

In `open_db_dbi`, we test whether various config-settings are defined
by comparing their string values to `NULL`.  However, the `u.string`
member of `struct config_entry` is an array, not a pointer, so it is
never `NULL`.  Instead, check whether the string is empty.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: DBI: fix NUL-termination of escaped SQL string
Jeremy Sowden [Tue, 30 Nov 2021 10:55:41 +0000 (10:55 +0000)] 
output: DBI: fix NUL-termination of escaped SQL string

On error, `dbi_conn_quote_string_copy` returns zero.  In this case, we
need to set `*dst` to NUL.  Handle a return-value of `2` as normal
below.  `1` is never returned.

Replace `strncpy` with `memcpy`: using `strncpy` is nearly always a
mistake, and we don't need its special behaviour here.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: DBI: improve mapping of DB columns to input-keys
Jeremy Sowden [Tue, 30 Nov 2021 10:55:40 +0000 (10:55 +0000)] 
output: DBI: improve mapping of DB columns to input-keys

Currently, we copy the column-name to a buffer, iterate over it to
replace the underscores with full-stops, using `strchr` from the start
of the buffer on each iteration, iterate over it a second time to
lower-case all letters, and finally copy the buffer to the input-key's
`name` member.

In addition to being inefficient, `strncpy` is used to do the copies,
which leads gcc to complain:

  ulogd_output_DBI.c:160:17: warning: `strncpy` output may be truncated copying 31 bytes from a string of length 31

Furthermore, the buffer is not initialized, which means that there is
also a possible buffer overrun if the column-name is too long, since
`strncpy` will not append a NUL.

Instead, copy the column-name directly to the input-key using
`snprintf`, and then iterate over it once to replace underscores and
lower-case letters.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: DBI: fix deprecation warnings
Jeremy Sowden [Tue, 30 Nov 2021 10:55:39 +0000 (10:55 +0000)] 
output: DBI: fix deprecation warnings

The DBI output plugin uses some libdbi functions which have been
deprecated in favour of re-entrant equivalents.  Switch to the
re-entrant functions.

Remove superfluous `init` declaration.

Add destructor to clean up DBI instance on exit.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoinput: UNIXSOCK: prevent unaligned pointer access
Jeremy Sowden [Tue, 30 Nov 2021 10:55:38 +0000 (10:55 +0000)] 
input: UNIXSOCK: prevent unaligned pointer access

`struct ulogd_unixsock_packet_t` is packed, so taking the address of its
`struct iphdr payload` member may yield an unaligned pointer value.  We
only actually dereference the pointer to get the IP version, so replace
the pointer with a version variable and elsewhere use `pkt.payload`
directly.

Remove a couple of stray semicolons.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoinput: UNIXSOCK: fix possible truncation of socket path
Jeremy Sowden [Tue, 30 Nov 2021 10:55:37 +0000 (10:55 +0000)] 
input: UNIXSOCK: fix possible truncation of socket path

Verify that the socket path is short enough, and replace `strncpy` with
`strcpy`.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoinput: UNIXSOCK: remove stat of socket-path
Jeremy Sowden [Tue, 30 Nov 2021 10:55:36 +0000 (10:55 +0000)] 
input: UNIXSOCK: remove stat of socket-path

When creating the UNIX socket, there is a TOCTOU race between the
stat(2) and bind(2) calls, and if the path is already bound, the bind(2)
call will fail in any case.  Remove the stat(2) call.

Tidy up a couple of error message.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agofilter: PWSNIFF: replace malloc+strncpy with strndup
Jeremy Sowden [Tue, 30 Nov 2021 10:55:35 +0000 (10:55 +0000)] 
filter: PWSNIFF: replace malloc+strncpy with strndup

There are a couple of instances of allocating memory with `malloc`,
followed by copying a string to it with `strncpy` and adding an explicit
assignment of `\0` to terminate the string.  Replace them with
`strndup`.

Add an enum to name indices of output keys.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoReplace malloc+memset with calloc
Jeremy Sowden [Tue, 30 Nov 2021 10:55:34 +0000 (10:55 +0000)] 
Replace malloc+memset with calloc

There are a number of places where we `malloc` some memory and then
`memset` it to zero.  Use `calloc` instead.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agofilter: HWHDR: remove zero-initialization of MAC type
Jeremy Sowden [Tue, 30 Nov 2021 10:55:33 +0000 (10:55 +0000)] 
filter: HWHDR: remove zero-initialization of MAC type

We don't need to initialize `type`, and even if we did the right value
would be `ARPHDR_VOID`, not `0`, which is a valid MAC type
(`ARPHDR_NETROM`).

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agofilter: HWHDR: re-order KEY_RAW_MAC checks
Jeremy Sowden [Tue, 30 Nov 2021 10:55:32 +0000 (10:55 +0000)] 
filter: HWHDR: re-order KEY_RAW_MAC checks

Currently, in `interp_mac2str` we have:

  if (/* KEY_RAW_MAC is valid */) {
    /*
     * set mac type
     */
  }

  if (/* mac type is ethernet */)
    // parse ethernet

  if (/* KEY_RAW_MAC is not valid */)
    // return early.

The MAC type will not be set to ethernet unless KEY_RAW_MAC is valid,
so we can move the last check up and drop the first one:

  if (/* KEY_RAW_MAC is not valid */)
    // return early.

  /*
   * set mac type
   */

  if (/* mac type is ethernet */)
    // parse ethernet

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agofilter: HWHDR: simplify flow-control
Jeremy Sowden [Tue, 30 Nov 2021 10:55:31 +0000 (10:55 +0000)] 
filter: HWHDR: simplify flow-control

The `interp_mac2str` function concludes with a `switch` followed by a
`return` statement.

The `switch` has one case falling through to a default:

  switch (expr) {
  case X:
    // ... X code ...
  default:
    // ... default code ...
  }

This is equivalent to the simpler and more readily comprehensible:

  if (expr == X) {
    // ... X code ...
  }
  // ... default code ...

Replace the former with the latter.

Doing so makes it obvious that the following `return` statement is never
reached.  Remove it.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agodb: add missing `break` to switch case
Jeremy Sowden [Tue, 30 Nov 2021 10:55:30 +0000 (10:55 +0000)] 
db: add missing `break` to switch case

When formatting DB queries, if we get a input key of type `RAW`, we log
a message indicating that `RAW` is unsupported, then fall through to the
default case, which logs another message that the key type is unknown.
Add the missing `break` statement to prevent the fall-through.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agojhash: add "fall through" comments to switch cases
Jeremy Sowden [Tue, 30 Nov 2021 10:55:29 +0000 (10:55 +0000)] 
jhash: add "fall through" comments to switch cases

gcc warns about undocumented fall-throughs in switches.  In this case,
the fall-throughs are intended, so add commnts to indicate this to the
compiler.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoXML: show both nflog packet and conntrack
Ken-ichirou MATSUZAWA [Tue, 12 Oct 2021 11:17:07 +0000 (20:17 +0900)] 
XML: show both nflog packet and conntrack

This patch enables to show "ct" as well as "raw" if output type is
ULOGD_DTYPE_RAW and "ct" input exists.

Signed-off-by: Ken-ichirou MATSUZAWA <chamas@h4.dion.ne.jp>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoNFLOG: attach struct nf_conntrack
Ken-ichirou MATSUZAWA [Thu, 18 Nov 2021 11:09:19 +0000 (20:09 +0900)] 
NFLOG: attach struct nf_conntrack

put nf_conntrack in ct outputkey when "attach_conntrack" is specified.
But there is no way to show both nflog "raw" and "ct" now.

Signed-off-by: Ken-ichirou MATSUZAWA <chamas@h4.dion.ne.jp>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoNFLOG: add NFULNL_CFG_F_CONNTRACK flag
Ken-ichirou MATSUZAWA [Thu, 18 Nov 2021 11:07:24 +0000 (20:07 +0900)] 
NFLOG: add NFULNL_CFG_F_CONNTRACK flag

acquiring conntrack information by specifying "attack_conntrack=1"

Signed-off-by: Ken-ichirou MATSUZAWA <chamas@h4.dion.ne.jp>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agooutput: IPFIX: correct format specifiers
Jeremy Sowden [Sun, 21 Nov 2021 20:41:39 +0000 (20:41 +0000)] 
output: IPFIX: correct format specifiers

There are a couple of logging calls which use the wrong specifiers for
their integer arguments.  Change the specifiers to match the arguments.

Use the correct type for the variable holding the return-value of
`send(2)`.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoinput: UNIXSOCK: correct format specifiers
Jeremy Sowden [Sun, 21 Nov 2021 20:41:38 +0000 (20:41 +0000)] 
input: UNIXSOCK: correct format specifiers

There are a couple of logging calls which use the wrong specifiers for
their integer arguments.  Change the specifiers to match the arguments.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoulogd: fix order of log arguments
Jeremy Sowden [Sun, 21 Nov 2021 20:41:37 +0000 (20:41 +0000)] 
ulogd: fix order of log arguments

If `daemon` fails during start-up, ulogd attempts to print `errno` and
`strerror(errno)` to the log.  However, the arguments are the wrong way
round.  Swap them.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoulogd: remove empty log-line
Jeremy Sowden [Sun, 21 Nov 2021 20:41:36 +0000 (20:41 +0000)] 
ulogd: remove empty log-line

There is a `strdup` at the beginning of `create_stack`.  If it fails, an
empty log-line is printed.  It's not useful, so remove it.  This is
consistent with the error-handling of the `malloc` which immediately
follows it.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoinclude: add `format` attribute to `__ulogd_log` declaration
Jeremy Sowden [Sun, 21 Nov 2021 20:41:35 +0000 (20:41 +0000)] 
include: add `format` attribute to `__ulogd_log` declaration

`__ulogd_log` takes a printf-style format string and matching arguments.
Add the gcc `format` attribute to its declaration in order to allow the
compiler to type-check the function arguments against the specifiers in
the format string.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: missing ipfix.h header when running make distcheck
Pablo Neira Ayuso [Tue, 16 Nov 2021 11:35:01 +0000 (12:35 +0100)] 
build: missing ipfix.h header when running make distcheck

make distcheck reports ipfix.h is not included in the tarball file.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: use `AS_IF` consistently in configure.ac
Jeremy Sowden [Sun, 14 Nov 2021 15:52:31 +0000 (15:52 +0000)] 
build: use `AS_IF` consistently in configure.ac

configure.ac contains a mix of `AS_IF` and `if` conditionals.  Prefer
the portable M4sh `AS_IF` macro.  In some cases, where there are both
`AS_IF` and `if` conditionals evaluating the same predicates, the latter
are merged into the former.

Replace three instance of `test -n "$var"` with the usual, more portable,
autoconf idiom: `test "x$var" != "x"`.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: quote autoconf macro arguments
Jeremy Sowden [Sun, 14 Nov 2021 15:52:30 +0000 (15:52 +0000)] 
build: quote autoconf macro arguments

Arguments are supposed to be quoted in square brackets.  Fix several that
weren't.

Sort and reformat the `AC_OUTPUT_FILES` argument list while we're at it.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: remove commented-out code
Jeremy Sowden [Sun, 14 Nov 2021 15:52:29 +0000 (15:52 +0000)] 
build: remove commented-out code

There are a couple of blocks of macros in configure.ac which were
commented out in 2006.  Remove them.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: update obsolete autoconf macros
Jeremy Sowden [Sun, 14 Nov 2021 15:52:28 +0000 (15:52 +0000)] 
build: update obsolete autoconf macros

`AC_CONFIG_HEADER` has been superseded by `AC_CONFIG_HEADERS`.

`AC_PROG_LIBTOOL` has been superseded by `LT_INIT`.

`AC_DISABLE_STATIC` can be replaced by an argument to `LT_INIT`.

`AC_HEADER_STDC` is obsolete.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: use correct automake variable for library dependencies
Jeremy Sowden [Sun, 14 Nov 2021 15:52:27 +0000 (15:52 +0000)] 
build: use correct automake variable for library dependencies

A couple of library dependencies are specified in `_LDFLAGS` variables.
They are supposed to be specified in `_LIBADD` variables.  Move them.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: delete commented-out code
Jeremy Sowden [Sun, 14 Nov 2021 15:52:26 +0000 (15:52 +0000)] 
build: delete commented-out code

There are a few of commented-out variable definitions left over from
the introduction of Automake.  Remove them.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: group `*_la_*` variables with their libraries
Jeremy Sowden [Sun, 14 Nov 2021 15:52:25 +0000 (15:52 +0000)] 
build: group `*_la_*` variables with their libraries

Move the `_SOURCES`, `_LIBADD` and `_LDFLAGS` variables for each
input-packet library alongside the matching `.la` definition.  In
particular, move the `NFLOG` and `ULOG` variables inside the
conditionals controlling whether the libraries get built.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: skip sub-directories containing disabled plugins
Jeremy Sowden [Sun, 14 Nov 2021 15:52:24 +0000 (15:52 +0000)] 
build: skip sub-directories containing disabled plugins

Currently, make enters all sub-directories containing source-code, even
if they only contain optional targets which are not configured to be
built.  Instead, change the Makefiles so that the sub-directories are
optional, rather than the targets.

Group sub-directory definitions consistently at the top of the Makefiles
that contain them.

Trim a few leading and trailing blank lines.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: use `dist_man_MANS` to declare man-pages
Jeremy Sowden [Sun, 14 Nov 2021 15:52:23 +0000 (15:52 +0000)] 
build: use `dist_man_MANS` to declare man-pages

By using `dist_man_MANS`, instead of `man_MANS`, we no longer need to
include the man-pages in `EXTRA_DIST`.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: add Make_global.am for common flags
Jeremy Sowden [Sun, 14 Nov 2021 15:52:22 +0000 (15:52 +0000)] 
build: add Make_global.am for common flags

Move `${regular_CFLAGS}` from configure.ac to Make_global.am, renaming
it to `AM_CFLAGS`.  Add `AM_CPPFGLAGS` to include
`$(top_srcdir)/include`.  Include the new file in the Makefiles that
require it.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: move CPP `-D` flag.
Jeremy Sowden [Sun, 14 Nov 2021 15:52:21 +0000 (15:52 +0000)] 
build: move CPP `-D` flag.

The `ULOGD2_LIBDIR` macro is only used in one place, so move the flag
defining it out of the common `regular_CFLAGS` variable to the
`AM_CPPFLAGS` variable in the Makefile where it is needed.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: remove empty filter sub-directory
Jeremy Sowden [Sun, 14 Nov 2021 15:52:20 +0000 (15:52 +0000)] 
build: remove empty filter sub-directory

The only file in filter/packet2flow is an empty Makefile.am.  Remove it.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: remove unused Makefile fragment
Jeremy Sowden [Sun, 14 Nov 2021 15:52:19 +0000 (15:52 +0000)] 
build: remove unused Makefile fragment

Rules.make.in contains a number of variables defined by configure.  It
is left-over from the pre-Automake build-system, in which it used to
fill a similar role to Make_global.am.  It is no longer used anywhere.
Remove it.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agogitignore: ignore .dirstamp
Jeremy Sowden [Sun, 14 Nov 2021 15:52:18 +0000 (15:52 +0000)] 
gitignore: ignore .dirstamp

It's created by automake while making sure that build directories (utils/
and utils/.deps/, in this case) exist if the `subdir-objects` option is
enabled.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agogitignore: add Emacs artefacts
Jeremy Sowden [Sun, 14 Nov 2021 15:52:17 +0000 (15:52 +0000)] 
gitignore: add Emacs artefacts

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoNFLOG: fix seq global flag setting
Ken-ichirou MATSUZAWA [Fri, 17 Sep 2021 22:09:29 +0000 (07:09 +0900)] 
NFLOG: fix seq global flag setting

Otherwise this is incorrectly setting on NFULNL_CFG_F_SEQ_GLOBAL if
local sequence number via NFULNL_CFG_F_SEQ is requested.

Signed-off-by: Ken-ichirou MATSUZAWA <chamas@h4.dion.ne.jp>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoXML: support nflog pkt output
Ken-ichirou MATSUZAWA [Fri, 17 Sep 2021 22:08:23 +0000 (07:08 +0900)] 
XML: support nflog pkt output

plugin input type ULOGD_DTYPE_RAW was missing

Signed-off-by: Ken-ichirou MATSUZAWA <chamas@h4.dion.ne.jp>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agoprintpkt: print pkt mark like kernel
Cole Dishington [Mon, 24 May 2021 20:59:13 +0000 (08:59 +1200)] 
printpkt: print pkt mark like kernel

Print the pkt mark in hex with a preceding '0x', like the kernel prints
pkts logged by netfilter.

Signed-off-by: Cole Dishington <Cole.Dishington@alliedtelesis.co.nz>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agoraw2packet: fix comma instead of semicolon
Timon Ulrich [Fri, 30 Oct 2020 14:30:47 +0000 (15:30 +0100)] 
raw2packet: fix comma instead of semicolon

Signed-off-by: Timon Ulrich <t.ulrich@anapur.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoulogd: printpkt: always print IPv6 protocol
Andreas Jaggi [Fri, 21 Feb 2020 06:40:36 +0000 (07:40 +0100)] 
ulogd: printpkt: always print IPv6 protocol

Print the protocol number for protocols not known by name.

Signed-off-by: Andreas Jaggi <andreas.jaggi@waterwave.ch>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoIPFIX: Introduce template record support
Ander Juaristi [Fri, 26 Apr 2019 07:58:07 +0000 (09:58 +0200)] 
IPFIX: Introduce template record support

This commit adds the ability to send template records
to the remote collector.

In addition, it also introduces a new
configuration parameter 'send_template', which tells when template
records should be sent. It accepts the following string values:

 - "once": Send the template record only the first time (might be coalesced
    with data records).
 - "always": Send the template record always, with every data record that is sent
    to the collector (multiple data records might be sent together).
 - "never": Assume the collector knows the schema already. Do not send template records.

If omitted, the default value for 'send_template' is "once".

Signed-off-by: Ander Juaristi <a@juaristi.eus>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoIPFIX: Add IPFIX output plugin
Ander Juaristi [Fri, 26 Apr 2019 07:58:06 +0000 (09:58 +0200)] 
IPFIX: Add IPFIX output plugin

This patch adds an IPFIX output plugin to ulogd2. It generates NetFlow/IPFIX
traces and sends them to a remote server (collector) via TCP or UDP.

Based on original work by Holger Eitzenberger <holger@eitzenberger.org>.

How to test this
----------------

I am currently testing this with the NFCT input and Wireshark.

Place the following in ulogd.conf:

      # this will print all flows on screen
      loglevel=1

      # load NFCT and IPFIX plugins
      plugin="/lib/ulogd/ulogd_inpflow_NFCT.so"
      plugin="/lib/ulogd/ulogd_output_IPFIX.so"

      stack=ct1:NFCT,ipfix1:IPFIX

      [ct1]
      netlink_socket_buffer_size=217088
      netlink_socket_buffer_maxsize=1085440
      accept_proto_filter=tcp,sctp

      [ipfix1]
      oid=1
      host="127.0.0.1"
      #port=4739
      #send_template="once"

I am currently testing it by launching a plain NetCat listener on port
4739 (the default for IPFIX) and then running Wireshark and see that it
dissects the IPFIX/NetFlow traffic correctly (obviously this relies on
the Wireshark NetFlow dissector being correct).

First:

      nc -vvvv -l 127.0.0.1 4739

Then:

      sudo ulogd -vc ulogd.conf

Signed-off-by: Ander Juaristi <a@juaristi.eus>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoulogd: fix build with musl libc
Cameron Norman [Sat, 27 Oct 2018 20:05:45 +0000 (13:05 -0700)] 
ulogd: fix build with musl libc

The attached patch fixes building ulogd2 with musl libc. It is being
used on Void Linux right now.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1278
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoulogd: json: send messages to a remote host / unix socket
Andreas Jaggi [Wed, 30 May 2018 20:15:36 +0000 (22:15 +0200)] 
ulogd: json: send messages to a remote host / unix socket

Extend the JSON output plugin so that the generated JSON stream can be
sent to a remote host via TCP/UDP or to a local unix socket.

Signed-off-by: Andreas Jaggi <andreas.jaggi@waterwave.ch>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoremove ulogd2.rotate and ulogd2.spec from Makefile.am ulogd-2.0.7
Arturo Borrero Gonzalez [Thu, 26 Apr 2018 22:58:00 +0000 (00:58 +0200)] 
remove ulogd2.rotate and ulogd2.spec from Makefile.am

Fixes: 42b384044dab ("ulogd2: cleanup downstream files")
Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
7 years agoSet release number to 2.0.7.
Arturo Borrero Gonzalez [Thu, 26 Apr 2018 22:53:53 +0000 (00:53 +0200)] 
Set release number to 2.0.7.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
7 years agoulogd2: cleanup downstream files
Arturo Borrero Gonzalez [Tue, 3 Apr 2018 10:08:09 +0000 (12:08 +0200)] 
ulogd2: cleanup downstream files

These files are outdated and they belong to downstream users (distributions).
Providing outdated and unmaintained files here serves no purpose other than
confusing users and annoy packagers.

If an user is using ulogd2 directly from the source tarball, I would expect it
to be proficient enough to generate these files by itself.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoulogd: load all plugins by default
Arturo Borrero Gonzalez [Mon, 2 Oct 2017 13:06:49 +0000 (15:06 +0200)] 
ulogd: load all plugins by default

This new configuration behaviour option eases a bit the configuration of ulogd2
by allowing to load all plugins in one go, without having to know their full
path.

Choosing concrete plugins and using full path for them is great for some
environmnets, but I don't think it's a common case. The common case is to
load all plugins, even ignoring where do they live in the filesystem.

Even worse, the full path may be architecture-dependant, which makes copying
the ulogd.conf file between machines unnecesarily complex.

To experiment this new behaviour, don't put any 'plugin=' directive in the
config file. Plugins will be loaded from a default directory, choosen at
build/configure time (--with-ulogd2libdir). If no specified, this is something
like '/usr/local/lib/ulogd/'.

This new configuration option doesn't implement any special logic. We simply
open the dir and try to load all files ending with '.so'.

The log message level for plugins loading is increased so users can see by
default which plugins are loaded.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoulogd: use a RT scheduler by default
Arturo Borrero Gonzalez [Thu, 7 Sep 2017 11:36:53 +0000 (13:36 +0200)] 
ulogd: use a RT scheduler by default

Is common that ulogd runs in scenarios where a lot of packets are to be logged.
If there are more packets than ulogd can handle, users can start seing log
messages like this:

 ulogd[556]: We are losing events. Please, consider using the clauses \
 `netlink_socket_buffer_size' and `netlink_socket_buffer_maxsize'

Which means that Netlink buffer overrun have happened.
There are several approaches to prevent this situation:

 * in the ruleset, limit the amount of packet queued for log
 * in the ruleset, instruct the kernel to use a queue-threshold
 * from userspace, increment Netlink buffer sizes
 * from userspace, configure ulogd to run as high priority process

The first 3 method can be configured by users at runtime.
This patch deals with the last method. SCHED_RR is configured by default,
with no associated configuration parameter for users, since I believe
this is common enough, and should produce no harm.

A similar approach is used in the conntrackd daemon.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Acked-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoip2bin: fix plugin link for some compiler
Eric Leblond [Sun, 2 Jul 2017 15:57:54 +0000 (17:57 +0200)] 
ip2bin: fix plugin link for some compiler

Declaring a function inline and building with -O0 was causing the
following message:
 undefined symbol: uint32_to_ipv6
By declaring the function as static we fix the problem.

8 years agoulogd: fix crash when plugin version are incorrect
Eric Leblond [Sat, 1 Jul 2017 23:20:48 +0000 (01:20 +0200)] 
ulogd: fix crash when plugin version are incorrect

Format string in error message had more arguments than given and
it was resulting in a crash at start.

8 years agoSet release number to 2.0.6.
Eric Leblond [Mon, 15 May 2017 22:07:56 +0000 (00:07 +0200)] 
Set release number to 2.0.6.

8 years agorotate all default output files
Kaarle Ritvanen [Mon, 27 Mar 2017 18:43:39 +0000 (21:43 +0300)] 
rotate all default output files

Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
8 years agoharmonize log file defaults with ulogd.conf
Kaarle Ritvanen [Mon, 27 Mar 2017 18:43:38 +0000 (21:43 +0300)] 
harmonize log file defaults with ulogd.conf

Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
8 years agoulogd.conf: fix incorrect stack
Eric Leblond [Tue, 21 Mar 2017 21:08:58 +0000 (22:08 +0100)] 
ulogd.conf: fix incorrect stack

The stack was not correctly defined triggering an error on
type conflict.

Signed-off-by: Eric Leblond <eric@regit.org>
8 years agoulogd: use strncpy instead of memcpy
Eric Leblond [Tue, 21 Mar 2017 20:49:46 +0000 (21:49 +0100)] 
ulogd: use strncpy instead of memcpy

On some architecture, ulogd is not starting due to a
crash in memcpy. This patch switches to strncpy to
avoid the problem.

Reported-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Signed-off-by: Eric Leblond <eric@regit.org>
8 years agoulogd: add automake option
Eric Leblond [Thu, 31 Mar 2016 07:17:46 +0000 (09:17 +0200)] 
ulogd: add automake option

This option will be needed for future version of automake.

Signed-off-by: Eric Leblond <eric@regit.org>
8 years agoulogd: fix crash when ipv4 packet is truncated
Liping Zhang [Tue, 11 Oct 2016 14:22:27 +0000 (22:22 +0800)] 
ulogd: fix crash when ipv4 packet is truncated

If ipv4 packet is truncated, we should not try to dereference the
iph pointer. Otherwise, if the user add such iptables rules
"-j NFLOG --nflog-size 0", we will dereference the NULL pointer
and crash may happen.

Reported-by: Chris Caputo <ccaputo@alt.net>
Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoulogd: fix indentation in acinclude.m4
Eric Leblond [Thu, 31 Mar 2016 06:45:19 +0000 (08:45 +0200)] 
ulogd: fix indentation in acinclude.m4

Some imbricated tests were not indented.

Signed-off-by: Eric Leblond <eric@regit.org>
9 years agoulogd: fix cross compilation errors with mysql_config
Helmut Schaa [Fri, 18 Mar 2016 14:43:24 +0000 (15:43 +0100)] 
ulogd: fix cross compilation errors with mysql_config

When cross-compiling ulogd, mysql_config and pg_config will return build host
configuration not build target configuration. This leads to build failures
if mysql_config is installed on the host system but mysql is not available
on the build target.

Fix this by not using mysql_config and pg_config for cross-compilation.

Signed-off-by: Helmut Schaa <helmut.schaa@googlemail.com>
9 years agoulogd: add missing newline in log message
Eric Leblond [Fri, 5 Feb 2016 10:55:26 +0000 (11:55 +0100)] 
ulogd: add missing newline in log message

9 years agoulogd: restructures signal handling by self-pipe trick
Hironobu Ishii [Tue, 2 Feb 2016 14:01:41 +0000 (23:01 +0900)] 
ulogd: restructures signal handling by self-pipe trick

ulogd had a critical bug that is calling Async-Signal-Unsafe functions
in signal hander context.
  - Most of libc functions like fopen(), malloc() are Async-Signal-Unsafe.
    So you should not call these functions in signal handler context.
  - Calling pluginstances in signal handler context is danger.
    For implementer of pluginstances, it is very hard to recognize their
    functions are called in signal handler context.

To solve the issue, I restructured signal handling by self-pipe trick.
For more detail on self-pipe trick, please see the following.
https://lwn.net/Articles/177897/

This patch will solve various symptoms like following.
  - Deadlock
  - Segmentation fault caused by libc management data corruption,
  - Other unpredictable behavior.

Deadlock example
================
This bug was already filed at:
https://bugzilla.netfilter.org/show_bug.cgi?id=1030

I also hit this bug. The backtrace of this issue is following.
In this case, main thread was calling ctime(),
and signal handler called localtime_r().
That caused the dead lock while getting tzset_lock in __tz_convert().
Because vsyslog() is Async-Signal-Unsafe function, we cannot call
this function in signal handler context.

 (gdb) bt
 #0  __lll_lock_wait_private () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
 #1  0x00007f3c3fc7e4ac in _L_lock_2462 () at tzset.c:621
 #2  0x00007f3c3fc7e2e7 in __tz_convert (timer=0x7f3c3ff8bf00 <tzset_lock>,
     timer@entry=0x7fffcfa923b8, use_localtime=use_localtime@entry=1,
     tp=tp@entry=0x7fffcfa92400) at tzset.c:624
 #3  0x00007f3c3fc7c28d in __localtime_r (t=t@entry=0x7fffcfa923b8,
     tp=tp@entry=0x7fffcfa92400) at localtime.c:32
 #4  0x00007f3c3fcbf1ba in __GI___vsyslog_chk (pri=<optimized out>, flag=1,
     fmt=0x406fa8 "signal received, calling pluginstances\n", ap=0x7fffcfa924a0)
     at ../misc/syslog.c:199
 #5  0x00000000004037b5 in __ulogd_log ()
 #6  0x00000000004047be in signal_handler ()
 #7  <signal handler called>
 #8  0x00007f3c3fcb62f5 in __GI___xstat (vers=<optimized out>,
     name=0x7f3c3fd4b2c3 "/etc/localtime", buf=0x7fffcfa92c10)
     at ../sysdeps/unix/sysv/linux/wordsize-64/xstat.c:37
 #9  0x00007f3c3fc7e5f6 in __tzfile_read (file=file@entry=0x7f3c3fd4b2c3 "/etc/localtime",
     extra=extra@entry=0, extrap=extrap@entry=0x0) at tzfile.c:170
 #10 0x00007f3c3fc7d954 in tzset_internal (always=<optimized out>,
     explicit=explicit@entry=1) at tzset.c:444
 #11 0x00007f3c3fc7e303 in __tz_convert (timer=0x7fffcfa92d50,
     use_localtime=use_localtime@entry=1, tp=tp@entry=0x7f3c3ff8ed80 <_tmbuf>)
     at tzset.c:629
 #12 0x00007f3c3fc7c2a1 in __GI_localtime (t=<optimized out>) at localtime.c:42
 #13 0x00007f3c3fc7c1f9 in ctime (t=<optimized out>) at ctime.c:27
 #14 0x00007f3c3e180ec2 in ?? ()
 #15 0x0000000056a100c2 in ?? ()
 #16 0xf8570f79d4fc4200 in ?? ()
 #17 0x000000000209bec0 in ?? ()
 #18 0x00007f3c4059f1f8 in ?? ()
 #19 0x000000000000003c in ?? ()
 #20 0x0000000000404952 in ulogd_propagate_results ()
 #21 0x00007f3c3f9cc203 in ?? ()
 #22 0x0000000000000000 in ?? ()

Segmentation fault in free()
============================
>From my experience, I think this was caused by some routine called
malloc()/free() in signal handler context.
By that, malloc() management data became inconsistent.
As a result, free() made a wrong dereference.

Program terminated with signal SIGSEGV, Segmentation fault.
 #0  __GI___libc_free (mem=0x7f430f011000) at malloc.c:2903
 2903      if (chunk_is_mmapped(p))                       /* release mmapped memory. */
 (gdb) bt
 #0  __GI___libc_free (mem=0x7f430f011000) at malloc.c:2903
 #1  0x00007f430e68affa in __GI__IO_free_backup_area (fp=fp@entry=0x742500)
     at genops.c:210
 #2  0x00007f430e68a795 in _IO_new_file_overflow (f=0x742500, ch=-1) at fileops.c:849
 #3  0x00007f430e689511 in _IO_new_file_xsputn (f=0x742500, data=<optimized out>, n=15)
     at fileops.c:1372
 #4  0x00007f430e65aa4d in _IO_vfprintf_internal (s=s@entry=0x742500,
     format=<optimized out>, format@entry=0x7f430cbc4008 "%.15s %s %s",
     ap=ap@entry=0x7fff456ece38) at vfprintf.c:1635
 #5  0x00007f430e71d615 in ___fprintf_chk (fp=0x742500, flag=flag@entry=1,
     format=format@entry=0x7f430cbc4008 "%.15s %s %s") at fprintf_chk.c:36
 #6  0x00007f430cbc3f04 in fprintf (__fmt=0x7f430cbc4008 "%.15s %s %s",
     __stream=<optimized out>) at /usr/include/bits/stdio2.h:97
 #7  _output_logemu (upi=0x74e5a0) at ulogd_output_LOGEMU.c:102
 #8  0x0000000000404952 in ulogd_propagate_results ()
 #9  0x00007f430e40f203 in interp_packet (ldata=0x7fff456ed060, pf_family=2 '\002',
     upi=0x74a6b0) at ulogd_inppkt_NFLOG.c:400
 #10 msg_cb (gh=<optimized out>, nfmsg=0x7f430efe2020, nfa=0x7fff456ed060, data=0x74a6b0)
     at ulogd_inppkt_NFLOG.c:483
 #11 0x00007f430e20a307 in __nflog_rcv_pkt (nlh=<optimized out>, nfa=<optimized out>,
     data=<optimized out>) at libnetfilter_log.c:160
 #12 0x00007f430e0056b7 in __nfnl_handle_msg (len=268, nlh=0x7f430efe2010, h=0x74e8e0)
     at libnfnetlink.c:1236
 #13 nfnl_handle_packet (h=0x74e8e0, buf=0x7f430efe2010 "\f\001", len=<optimized out>)
     at libnfnetlink.c:1256
 #14 0x00007f430e20a508 in nflog_handle_packet (h=<optimized out>, buf=<optimized out>,
     len=<optimized out>) at libnetfilter_log.c:323
 #15 0x00007f430e40eaed in nful_read_cb (fd=<optimized out>, what=<optimized out>,
     param=0x74a6b0) at ulogd_inppkt_NFLOG.c:463
 #16 0x0000000000404ee0 in ulogd_select_main ()
 #17 0x0000000000402b17 in main ()

Signed-off-by: Hironobu Ishii <ishii.hironobu@jp.fujitsu.com>
9 years agosqlite3: Remove unused "buffer" option.
Alex Xu [Wed, 13 Jan 2016 20:37:58 +0000 (15:37 -0500)] 
sqlite3: Remove unused "buffer" option.

This option was left behind when the code was rewritten and is no longer
functional or useful. Remove it entirely.

Signed-off-by: Alex Xu (Hello71) <alex_y_xu@yahoo.ca>
9 years agojson: append timezone information to ISO 8601 date
Vincent Bernat [Fri, 2 Oct 2015 15:00:58 +0000 (17:00 +0200)] 
json: append timezone information to ISO 8601 date

While this is not strictly needed for ISO 8601, this is helpful since
otherwise, the receiver can't assume anything about the
timezone.

This uses a GNU extension but as ulogd is quite Linux-specific, this
shouldn't be a problem. The POSIX variables (tzname and daylight) are
quite difficult to use because daylight handling is incomplete (daylight
don't say if DST is now in effect, it just says it is sometimes in
effect).

A timezone offset is used instead of a timezone since it is usually
easier to parse (strptime in glibc is not able to parse a timezone name)
and don't require an up-to-date TZ database.

Signed-off-by: Vincent Bernat <Vincent.Bernat@exoscale.ch>
9 years agojson: output messages in JSONv1 format
Vincent Bernat [Wed, 30 Sep 2015 12:32:07 +0000 (14:32 +0200)] 
json: output messages in JSONv1 format

While Logstash is quite flexible in the JSON messages received, the
canonical format it "expects" is the JSON Event v1 format. The timestamp
should be keyed by `@timestamp` and there should be a `@version` key
whose value is 1. All other keys are free.

There is no formal specification of this format. It is however described
here:

 https://github.com/elastic/logstash/blob/1.5/lib/logstash/event.rb#L26-L47

It's useful to respect this format as it allows a user to use a less
capable receiver. The new format is enabled only when `eventv1=1` is set
in plugin configuration.

Signed-off-by: Vincent Bernat <Vincent.Bernat@exoscale.ch>
10 years agoUse stdint types everywhere
Felix Janda [Wed, 24 Jun 2015 17:53:34 +0000 (19:53 +0200)] 
Use stdint types everywhere

Signed-off-by: Felix Janda <felix.janda@posteo.de>
10 years agoulogd: Use /dev/null as dummy logfile when logging to syslog
Felix Janda [Sat, 16 May 2015 15:43:23 +0000 (17:43 +0200)] 
ulogd: Use /dev/null as dummy logfile when logging to syslog

Fixes compilation error with musl libc:

ulogd.c:86:13: error: storage size of 'syslog_dummy' isn't known
 static FILE syslog_dummy;

Signed-off-by: Felix Janda <felix.janda@posteo.de>
10 years agoDefine _GNU_SOURCE to get members of tcphdr
Felix Janda [Sat, 16 May 2015 13:44:32 +0000 (15:44 +0200)] 
Define _GNU_SOURCE to get members of tcphdr

The source uses linux names for members of tcphdr. For example
"source" instead of "th_sport", ... musl libc's headers need
_GNU_SOURCE defined in order to expose these.

Signed-off-by: Felix Janda <felix.janda@posteo.de>
10 years agoSync with kernel headers
Felix Janda [Sat, 16 May 2015 13:01:30 +0000 (15:01 +0200)] 
Sync with kernel headers

Signed-off-by: Felix Janda <felix.janda@posteo.de>
10 years agoconfigure.ac: Add --without-{mysql,pgsql}
Harald Welte [Sun, 3 May 2015 09:08:54 +0000 (11:08 +0200)] 
configure.ac: Add --without-{mysql,pgsql}

In some cases you may not want to build a certain output plugin, even
if the headers/libraries actually exist on the build host.