Skip to contentSkip to conversation

libmnl 1.0.0 release

ANNOUNCE Pablo Neira Ayuso 4 participants 9 messages Dec 17, 2010 – Dec 22, 2010

Subsystems (3)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

Hi!

The Netfilter project presents libmnl-1.0.0

libmnl is a minimalistic user-space library oriented to Netlink developers. There are a lot of common tasks in parsing, validating, constructing of both the Netlink header and TLVs that are repetitive and easy to get wrong. This library aims to provide simple helpers that allows you to re-use code and to avoid re-inventing the wheel.

This library is released under LGPLv2+.

Features:
* Small: the shared library requires around 45KB for an x86-based computer.
* Simple: this library avoids complexity and elaborated abstractions that tend to hide Netlink details.
* Easy to use: the library simplifies the work for Netlink-wise developers. It provides functions to make socket handling, message building, validating, parsing and sequence tracking, easier.
* Easy to re-use: you can use the library to build your own abstraction layer on top of this library.
* Decoupling: the interdependency of the main bricks that compose the library is reduced, i.e. the library provides many helpers, but the programmer is not forced to use them.

More info at:
http://www.netfilter.org/projects/libmnl/

Doxygen documentation at:
http://www.netfilter.org/projects/libmnl/doxygen/

You can download it via FTP at:
ftp://ftp.netfilter.org/pub/libmnl

Enjoy!

Cristian Rodríguez (1):
src: implement both GCC visibility support and export script

Jan Engelhardt (36):
build: just use autoreconf
build: do not abuse AM_INIT_AUTOMAKE for autoconf options
build: automake options should be in AM_INIT_AUTOMAKE
build: use subdir-objects and CC_C_O
build: run autoupdate
build: rebuild .pc files when configure status changed
build: resolve compiler warnings
build: remove unneeded -dynamic -ldl -nostartfiles flags
build: default to not build static libraries Add .gitignore files
build: fix disable_static functionality
src: avoid using deprecated unspecified argument lists
src: add const qualifiers
src: remove redundant casts
socket: remove statement with no effect
doc: documentation updates
include: consistent usage of "extern"
attr: string functions should take char *
callback: mnl_cb_run should use a void *
socket: use more appropriate types for mnl_socket_bind
include: add cplusplus guards for extern
nlmsg: use bool return type for yes-no functions
attr: rename str_null from NULL away
examples: remove redundant casts
build: remove -fPIC flag
build: remove statements without obvious effect
socket: constify a struct sockaddr_nl
nlmsg: use bool for mnl_nlmsg_ok()
attr: remove redundant check for NULL
include: use C++ headers in C++ mode
attr: avoid multiple definition of hidden variable
socket: propagate sendto/recvmsg's return types Update .gitignore
build: tag function headers rather than decls as exported
ld: add some more precautionary CFLAGS
nlmsg: remove unused function mnl_nlmsg_aligned_size()

Jozsef Kadlecsik (2):
fix for mnl_attr_for_each_nested()
fix mnl_attr_parse()

Pablo Neira Ayuso (75):
initial libmnl import
fix leak in mnl_socket_open()
remove libnfnetlink stuff from autogen.sh
finish API documentation
fix mnl_cb_run() and mnl_cb_run2() return value logic
add COPYING file
use `unsigned int' for number of bytes and array size in callback API partially revert previous commit
fix mnl_socket_bind() to support the selection of the netlink portID constify several mnl_socket_* parameters and use size_t instead of int use C99 types uintXX_t instead of POSIX u_intXX_t
check portid of received messages in examples
revert abcaad6b65ed368c13c353ed71619332f76d9c2a
add validation infrastructure and rework attribute parsing
check source of the netlink message and fix sequence tracking logic remove mnl_align() as it's been replaced by MNL_ALIGN()
rename mnl_attr_type_invalid() by mnl_attr_type_ok()
remove bogus checking in mnl_attr_validate() and mnl_attr_validate2() add -Wextra to spot more errors in compilation
fix warning in compilation due to different signess
rename mnl_attr_type_ok() by mnl_attr_type_valid() for consistency rename msg.c to nlmsg.c
rename mnl_nlmsg_payload_size() to mnl_nlmsg_get_payload_len() for consistency x
more consistency name issues: rename get_data*() to get_payload*() add new README file
review documentation on netlink attribute helpers
improve documentation of netlink message helpers
remove bogus casting in mnl_nlmsg_get_payload_tail()
remove mnl_nlmsg_get_len() function
minor update in README (library is around 30KB here, not 20KB) update socket helper documentation
add mnl_nlmsg_fprintf() function for debugging purposes
review data types for input parameters of mnl_attr_*() functions use size_t to indicate the buffer size in mnl_cb_run*()
remove redudant alignment in mnl_nlmsg_size()
fix warning in mnl_cb_run2()
add -Wextra -Wall for example files
fix lots of compilation warnings in example files
remove references to 'generic' in header file
add rtnl-route-add.c to examples
add helpers to nest attributes
add licensing terms of example files
add nf-queue.c example file for nfnetlink_queue
statify function in nf-queue.c example
change errno values for mnl_cb_run[2]()
relax mnl_attr_type_valid() checkings and change errno value
fix rtnl-link-dump3.c
add nfct-event example
nlmsg: use size_t instead of int for several input parameters
socket: remove mnl_socket_sendmsg() and mnl_socket_recvmsg()
examples: fix rtnl-set-link
examples: fix byte-order in nfct-event
build: add notice on how to update library API version
skip PortID and sequence checking if zero
add missing .gitignore file to m4/ directory
examples: put examples files into specific directories
doxygen documentation
add quote from Thoureau to documentation
src: define MNL_SOCKET_BUFFER_SIZE to 8192UL
doc: git tree update (now at netfilter.org) and fix listing in doxygen
examples: add nflog example
nlmsg: rework mnl_nlmsg_fprintf
Merge branch 'master' of git://dev.medozas.de/libmnl
license: change licensing terms from GPLv2+ to LGPLv2.1+
nlmsg: remove unexisting mnl_nlmsg_total_size
add libmnl.map file to src/Makefile.am
attr: add mnl_attr_nest_cancel()
header: add MNL_ARRAY_SIZE(x)
callback: use of inline in mnl_cb_run*() function
attr: add put function that allows to check buffer size
header: use getpagesize() for MNL_SOCKET_BUFFER_SIZE
header: missing parenthesis in MNL_SOCKET_BUFFER_SIZE definition
nlmsg: add new message batching infrastructure
build: 1.0.0 release

#1 lore raw
Quoted 3 lines · Pablo Neira Ayuso

Hi!

The Netfilter project presents libmnl-1.0.0

Hi,

I have a CentOS 5.5 base with a 2.6.36.2 kernel installed. When compiling libmnl I got these errors:

nlmsg.c: In function 'mnl_nlmsg_fprintf_payload':
nlmsg.c:274: error: 'NLA_TYPE_MASK' undeclared (first use in this function)
nlmsg.c:274: error: (Each undeclared identifier is reported only once nlmsg.c:274: error: for each function it appears in.) nlmsg.c:290: error: 'NLA_F_NESTED' undeclared (first use in this function)
nlmsg.c:292: error: 'NLA_F_NET_BYTEORDER' undeclared (first use in this function)
make: *** [nlmsg.lo] Error 1

NLA_TYPE_MASK is used in nlmsg.c and attr.c. Searching I found that it should be defined in linux/netlink.h but it's not there.

To make it compile, I did the following.

New file nla.h:

/*
* nla_type (16 bits)
* +---+---+-------------------------------+
* | N | O | Attribute Type |
* +---+---+-------------------------------+
* N := Carries nested attributes
* O := Payload stored in network byte order
*
* Note: The N and O flag are mutually exclusive.
*/

#define NLA_F_NESTED            (1 << 15)
#define NLA_F_NET_BYTEORDER     (1 << 14)
#define NLA_TYPE_MASK           ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)

These changes in nlmsg.c and attr.c:

attr.c 2010-12-18 07:16:05.000000000 +0100 renamed from attr.c.orig 2010-12-18 07:16:51.000000000 +0100 +3 -0
@@ -11,6 +11,9 @@
 #include <string.h>
 #include <values.h>    /* for INT_MAX */
 #include <errno.h>
+#ifndef NLA_TYPE_MASK
+#include "nla.h"
+#endif
 #include "internal.h"
 
 /**
nlmsg.c 2010-12-18 07:16:10.000000000 +0100 renamed from nlmsg.c.orig 2010-12-18 07:16:56.000000000 +0100 +3 -0
@@ -13,6 +13,9 @@
 #include <errno.h>
 #include <string.h>
 #include <libmnl/libmnl.h>
+#ifndef NLA_TYPE_MASK
+#include "nla.h"
+#endif
 #include "internal.h"
 
 /**

After this change, I get no errors when compiling libmnl. I am not a C programmer, so: is the above the correct way?

Thanks,
Rob

author maintainer
#2 lore raw

Hi Rob,

Quoted 21 lines · Rob Sterenborg (lists)
Quoted 3 lines · Pablo Neira Ayuso

Hi!

The Netfilter project presents libmnl-1.0.0

Hi,

I have a CentOS 5.5 base with a 2.6.36.2 kernel installed. When compiling libmnl I got these errors:

nlmsg.c: In function 'mnl_nlmsg_fprintf_payload':
nlmsg.c:274: error: 'NLA_TYPE_MASK' undeclared (first use in this function)
nlmsg.c:274: error: (Each undeclared identifier is reported only once nlmsg.c:274: error: for each function it appears in.) nlmsg.c:290: error: 'NLA_F_NESTED' undeclared (first use in this function)
nlmsg.c:292: error: 'NLA_F_NET_BYTEORDER' undeclared (first use in this function)
make: *** [nlmsg.lo] Error 1

Quoted 2 lines

NLA_TYPE_MASK is used in nlmsg.c and attr.c. Searching I found that it should be defined in linux/netlink.h but it's not there.

I'd appreciate if you can guess what version of the kernel header files you're using (CentOS uses a mutant Linux kernel 2.6.18, right?).

I can make a patch based on your idea to make libmnl compile cleanly with old Linux kernels.

author maintainer
#3 lore raw
Quoted 24 lines · Pablo Neira Ayuso

Hi Rob,

Quoted 21 lines · Rob Sterenborg (lists)
Quoted 3 lines · Pablo Neira Ayuso

Hi!

The Netfilter project presents libmnl-1.0.0

Hi,

I have a CentOS 5.5 base with a 2.6.36.2 kernel installed. When compiling libmnl I got these errors:

nlmsg.c: In function 'mnl_nlmsg_fprintf_payload':
nlmsg.c:274: error: 'NLA_TYPE_MASK' undeclared (first use in this function)
nlmsg.c:274: error: (Each undeclared identifier is reported only once nlmsg.c:274: error: for each function it appears in.) nlmsg.c:290: error: 'NLA_F_NESTED' undeclared (first use in this function)
nlmsg.c:292: error: 'NLA_F_NET_BYTEORDER' undeclared (first use in this function)
make: *** [nlmsg.lo] Error 1

Quoted 8 lines
Quoted 2 lines

NLA_TYPE_MASK is used in nlmsg.c and attr.c. Searching I found that it should be defined in linux/netlink.h but it's not there.

I'd appreciate if you can guess what version of the kernel header files you're using (CentOS uses a mutant Linux kernel 2.6.18, right?).

I can make a patch based on your idea to make libmnl compile cleanly with old Linux kernels.

I bet that examples will not compile either in old Linux kernels. Try `make check'.

#4 lore raw
In reply to Pablo Neira Ayuso
Quoted 22 lines · Pablo Neira Ayuso
Quoted 21 lines · Rob Sterenborg (lists)
Quoted 3 lines · Pablo Neira Ayuso

Hi!

The Netfilter project presents libmnl-1.0.0

Hi,

I have a CentOS 5.5 base with a 2.6.36.2 kernel installed. When compiling libmnl I got these errors:

nlmsg.c: In function 'mnl_nlmsg_fprintf_payload':
nlmsg.c:274: error: 'NLA_TYPE_MASK' undeclared (first use in this function)
nlmsg.c:274: error: (Each undeclared identifier is reported only once nlmsg.c:274: error: for each function it appears in.) nlmsg.c:290: error: 'NLA_F_NESTED' undeclared (first use in this function)
nlmsg.c:292: error: 'NLA_F_NET_BYTEORDER' undeclared (first use in this function)
make: *** [nlmsg.lo] Error 1

Quoted 5 lines
Quoted 2 lines

NLA_TYPE_MASK is used in nlmsg.c and attr.c. Searching I found that it should be defined in linux/netlink.h but it's not there.

I'd appreciate if you can guess what version of the kernel header files you're using (CentOS uses a mutant Linux kernel 2.6.18, right?).

NLA_F_NESTED et al are available starting with 2.6.24.

author maintainer
#5 lore raw
Quoted 24 lines · Jan Engelhardt
Quoted 22 lines · Pablo Neira Ayuso
Quoted 21 lines · Rob Sterenborg (lists)
Quoted 3 lines · Pablo Neira Ayuso

Hi!

The Netfilter project presents libmnl-1.0.0

Hi,

I have a CentOS 5.5 base with a 2.6.36.2 kernel installed. When compiling libmnl I got these errors:

nlmsg.c: In function 'mnl_nlmsg_fprintf_payload':
nlmsg.c:274: error: 'NLA_TYPE_MASK' undeclared (first use in this function)
nlmsg.c:274: error: (Each undeclared identifier is reported only once nlmsg.c:274: error: for each function it appears in.) nlmsg.c:290: error: 'NLA_F_NESTED' undeclared (first use in this function)
nlmsg.c:292: error: 'NLA_F_NET_BYTEORDER' undeclared (first use in this function)
make: *** [nlmsg.lo] Error 1

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

NLA_TYPE_MASK is used in nlmsg.c and attr.c. Searching I found that it should be defined in linux/netlink.h but it's not there.

I'd appreciate if you can guess what version of the kernel header files you're using (CentOS uses a mutant Linux kernel 2.6.18, right?).

NLA_F_NESTED et al are available starting with 2.6.24.

I think that this approach (see patch) is safe to fix this problem.

Rob, would you give it a test?

nlmsg: fix compilation with Linux kernel headers <= 2.6.24

From: Pablo Neira Ayuso <[email protected]>

This patch adds the internal definition of NLA_F_NESTED, NLA_F_NET_BYTEORDER and NLA_TYPE_MASK which were introduced in 2.6.24.

This patch is rather conservative since we internally define these constants instead of making them public in libmnl.h. I don't like the idea of polluting the libmnl.h file with declarations that may be missing in old linux/netlink.h files.

Moreover, I don't want to keep copies of useful Netlink headers in libmnl to avoid the overhead of keeping them in sync with those in the Linux kernel, not until I'm convinced at least.

---
 src/nlmsg.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
src/nlmsg.c +12 -0
index b2e3853..c22e71e 100644
@@ -243,6 +243,18 @@ static void mnl_nlmsg_fprintf_header(FILE *fd, const struct nlmsghdr *nlh)
 	fprintf(fd, "----------------\t------------------\n");
 }
 
+#ifndef NLA_F_NESTED
+#define NLA_F_NESTED		(1 << 15)
+#endif
+
+#ifndef NLA_F_NET_BYTEORDER
+#define NLA_F_NET_BYTEORDER	(1 << 14)
+#endif
+
+#ifndef NLA_TYPE_MASK
+#define NLA_TYPE_MASK		~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
+#endif
+
 static void
 mnl_nlmsg_fprintf_payload(FILE *fd, const struct nlmsghdr *nlh,
 			  size_t extra_header_size)
maintainer
#6 lore raw

From: Pablo Neira Ayuso <[email protected]>
Date: Tue, 21 Dec 2010 21:19:40 +0100

Quoted 1 line

I think that this approach (see patch) is safe to fix this problem.

This is fine for now, but really you should have a copy of the headers in your tree.

It's the only way to sanely control the build in all possible scenerios. The kernel headers are just too large of a variable for things like this.

author maintainer
#7 lore raw
Quoted 11 lines · David Miller

From: Pablo Neira Ayuso <[email protected]>
Date: Tue, 21 Dec 2010 21:19:40 +0100

Quoted 1 line

I think that this approach (see patch) is safe to fix this problem.

This is fine for now, but really you should have a copy of the headers in your tree.

It's the only way to sanely control the build in all possible scenerios. The kernel headers are just too large of a variable for things like this.

I was thinking on the overhead that this adds since we have to keep in sync kernel and library header files. If there's some new feature in the kernel, you'll have to wait until the new stuff in included in the libmnl header.

But this is indeed a problem since people will report compilation problems.

I'll make a patch to add them.

author maintainer
#8 lore raw
In reply to Rob Sterenborg (lists)
Quoted 21 lines · Rob Sterenborg (lists)
Quoted 3 lines · Pablo Neira Ayuso

Hi!

The Netfilter project presents libmnl-1.0.0

Hi,

I have a CentOS 5.5 base with a 2.6.36.2 kernel installed. When compiling libmnl I got these errors:

nlmsg.c: In function 'mnl_nlmsg_fprintf_payload':
nlmsg.c:274: error: 'NLA_TYPE_MASK' undeclared (first use in this function)
nlmsg.c:274: error: (Each undeclared identifier is reported only once nlmsg.c:274: error: for each function it appears in.) nlmsg.c:290: error: 'NLA_F_NESTED' undeclared (first use in this function)
nlmsg.c:292: error: 'NLA_F_NET_BYTEORDER' undeclared (first use in this function)
make: *** [nlmsg.lo] Error 1

Quoted 2 lines

NLA_TYPE_MASK is used in nlmsg.c and attr.c. Searching I found that it should be defined in linux/netlink.h but it's not there.

I'm going to apply the following patch to fix this.

headers: add local copy of linux/netlink.h to libmnl

From: Pablo Neira Ayuso <[email protected]>

Davem suggested to add a copy of linux/netlink.h to avoid compilation problems in all cases scenarios.

---
 include/libmnl/Makefile.am |    2 
 include/libmnl/libmnl.h    |    2 
 include/libmnl/netlink.h   |  274 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 276 insertions(+), 2 deletions(-)
 create mode 100644 include/libmnl/netlink.h
include/libmnl/Makefile.am +1 -1
index b03f68a..448d7ca 100644
@@ -1 +1 @@
-pkginclude_HEADERS = libmnl.h
+pkginclude_HEADERS = libmnl.h netlink.h
include/libmnl/libmnl.h +1 -1
index 3e69629..a051200 100644
@@ -11,7 +11,7 @@
 #endif
 #include <unistd.h>
 #include <sys/socket.h> /* for sa_family_t */
-#include <linux/netlink.h>
+#include <libmnl/netlink.h>
 
 #ifdef __cplusplus
 extern "C" {
include/libmnl/netlink.h new file +274 -0

274 lines not on this page · raw message