* [ANNOUNCE] libmnl 1.0.0 release @ 2010-12-17 14:20 Pablo Neira Ayuso 2010-12-18 5:23 ` Rob Sterenborg (lists) 0 siblings, 1 reply; 9+ messages in thread From: Pablo Neira Ayuso @ 2010-12-17 14:20 UTC (permalink / raw) To: netfilter-devel; +Cc: netfilter, netfilter-announce, lwn, Linux Netdev List [-- Attachment #1: Type: text/plain, Size: 1298 bytes --] 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! [-- Attachment #2: changes-libmnl-1.0.0.txt --] [-- Type: text/plain, Size: 5769 bytes --] 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [ANNOUNCE] libmnl 1.0.0 release 2010-12-17 14:20 [ANNOUNCE] libmnl 1.0.0 release Pablo Neira Ayuso @ 2010-12-18 5:23 ` Rob Sterenborg (lists) 2010-12-18 12:40 ` Pablo Neira Ayuso 2010-12-22 19:52 ` Pablo Neira Ayuso 0 siblings, 2 replies; 9+ messages in thread From: Rob Sterenborg (lists) @ 2010-12-18 5:23 UTC (permalink / raw) To: netfilter, netfilter-devel On Fri, 2010-12-17 at 15:20 +0100, Pablo Neira Ayuso wrote: > 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.orig 2010-12-18 07:16:51.000000000 +0100 +++ attr.c 2010-12-18 07:16:05.000000000 +0100 @@ -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.orig 2010-12-18 07:16:56.000000000 +0100 +++ nlmsg.c 2010-12-18 07:16:10.000000000 +0100 @@ -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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [ANNOUNCE] libmnl 1.0.0 release 2010-12-18 5:23 ` Rob Sterenborg (lists) @ 2010-12-18 12:40 ` Pablo Neira Ayuso 2010-12-18 12:53 ` Pablo Neira Ayuso 2010-12-18 15:35 ` Jan Engelhardt 2010-12-22 19:52 ` Pablo Neira Ayuso 1 sibling, 2 replies; 9+ messages in thread From: Pablo Neira Ayuso @ 2010-12-18 12:40 UTC (permalink / raw) To: Rob Sterenborg (lists); +Cc: netfilter, netfilter-devel Hi Rob, On 18/12/10 06:23, Rob Sterenborg (lists) wrote: > On Fri, 2010-12-17 at 15:20 +0100, Pablo Neira Ayuso wrote: >> 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. 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. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [ANNOUNCE] libmnl 1.0.0 release 2010-12-18 12:40 ` Pablo Neira Ayuso @ 2010-12-18 12:53 ` Pablo Neira Ayuso 2010-12-18 15:35 ` Jan Engelhardt 1 sibling, 0 replies; 9+ messages in thread From: Pablo Neira Ayuso @ 2010-12-18 12:53 UTC (permalink / raw) To: Rob Sterenborg (lists); +Cc: netfilter, netfilter-devel On 18/12/10 13:40, Pablo Neira Ayuso wrote: > Hi Rob, > > On 18/12/10 06:23, Rob Sterenborg (lists) wrote: >> On Fri, 2010-12-17 at 15:20 +0100, Pablo Neira Ayuso wrote: >>> 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. > > 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'. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [ANNOUNCE] libmnl 1.0.0 release 2010-12-18 12:40 ` Pablo Neira Ayuso 2010-12-18 12:53 ` Pablo Neira Ayuso @ 2010-12-18 15:35 ` Jan Engelhardt 2010-12-21 20:19 ` Pablo Neira Ayuso 1 sibling, 1 reply; 9+ messages in thread From: Jan Engelhardt @ 2010-12-18 15:35 UTC (permalink / raw) To: Pablo Neira Ayuso; +Cc: Rob Sterenborg (lists), netfilter, netfilter-devel On Saturday 2010-12-18 13:40, Pablo Neira Ayuso wrote: >On 18/12/10 06:23, Rob Sterenborg (lists) wrote: >> On Fri, 2010-12-17 at 15:20 +0100, Pablo Neira Ayuso wrote: >>> 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. > >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. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [ANNOUNCE] libmnl 1.0.0 release 2010-12-18 15:35 ` Jan Engelhardt @ 2010-12-21 20:19 ` Pablo Neira Ayuso 2010-12-21 20:22 ` David Miller 0 siblings, 1 reply; 9+ messages in thread From: Pablo Neira Ayuso @ 2010-12-21 20:19 UTC (permalink / raw) To: Jan Engelhardt; +Cc: Rob Sterenborg (lists), netfilter, netfilter-devel [-- Attachment #1: Type: text/plain, Size: 1332 bytes --] On 18/12/10 16:35, Jan Engelhardt wrote: > > On Saturday 2010-12-18 13:40, Pablo Neira Ayuso wrote: >> On 18/12/10 06:23, Rob Sterenborg (lists) wrote: >>> On Fri, 2010-12-17 at 15:20 +0100, Pablo Neira Ayuso wrote: >>>> 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. >> >> 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? [-- Attachment #2: 2.6.18.patch --] [-- Type: text/x-patch, Size: 1420 bytes --] nlmsg: fix compilation with Linux kernel headers <= 2.6.24 From: Pablo Neira Ayuso <pablo@netfilter.org> 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. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> --- src/nlmsg.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/src/nlmsg.c b/src/nlmsg.c index b2e3853..c22e71e 100644 --- a/src/nlmsg.c +++ b/src/nlmsg.c @@ -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) ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [ANNOUNCE] libmnl 1.0.0 release 2010-12-21 20:19 ` Pablo Neira Ayuso @ 2010-12-21 20:22 ` David Miller 2010-12-21 20:31 ` Pablo Neira Ayuso 0 siblings, 1 reply; 9+ messages in thread From: David Miller @ 2010-12-21 20:22 UTC (permalink / raw) To: pablo; +Cc: jengelh, lists, netfilter, netfilter-devel From: Pablo Neira Ayuso <pablo@netfilter.org> Date: Tue, 21 Dec 2010 21:19:40 +0100 > 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. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [ANNOUNCE] libmnl 1.0.0 release 2010-12-21 20:22 ` David Miller @ 2010-12-21 20:31 ` Pablo Neira Ayuso 0 siblings, 0 replies; 9+ messages in thread From: Pablo Neira Ayuso @ 2010-12-21 20:31 UTC (permalink / raw) To: David Miller; +Cc: jengelh, lists, netfilter, netfilter-devel On 21/12/10 21:22, David Miller wrote: > From: Pablo Neira Ayuso <pablo@netfilter.org> > Date: Tue, 21 Dec 2010 21:19:40 +0100 > >> 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. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [ANNOUNCE] libmnl 1.0.0 release 2010-12-18 5:23 ` Rob Sterenborg (lists) 2010-12-18 12:40 ` Pablo Neira Ayuso @ 2010-12-22 19:52 ` Pablo Neira Ayuso 1 sibling, 0 replies; 9+ messages in thread From: Pablo Neira Ayuso @ 2010-12-22 19:52 UTC (permalink / raw) To: Rob Sterenborg (lists); +Cc: netfilter, netfilter-devel [-- Attachment #1: Type: text/plain, Size: 932 bytes --] On 18/12/10 06:23, Rob Sterenborg (lists) wrote: > On Fri, 2010-12-17 at 15:20 +0100, Pablo Neira Ayuso wrote: >> 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. I'm going to apply the following patch to fix this. [-- Attachment #2: include.patch --] [-- Type: text/x-patch, Size: 10610 bytes --] headers: add local copy of linux/netlink.h to libmnl From: Pablo Neira Ayuso <pablo@netfilter.org> Davem suggested to add a copy of linux/netlink.h to avoid compilation problems in all cases scenarios. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> --- 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 diff --git a/include/libmnl/Makefile.am b/include/libmnl/Makefile.am index b03f68a..448d7ca 100644 --- a/include/libmnl/Makefile.am +++ b/include/libmnl/Makefile.am @@ -1 +1 @@ -pkginclude_HEADERS = libmnl.h +pkginclude_HEADERS = libmnl.h netlink.h diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h index 3e69629..a051200 100644 --- a/include/libmnl/libmnl.h +++ b/include/libmnl/libmnl.h @@ -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" { diff --git a/include/libmnl/netlink.h b/include/libmnl/netlink.h new file mode 100644 index 0000000..1235669 --- /dev/null +++ b/include/libmnl/netlink.h @@ -0,0 +1,274 @@ +#ifndef __LINUX_NETLINK_H +#define __LINUX_NETLINK_H + +#include <linux/socket.h> /* for sa_family_t */ +#include <linux/types.h> + +#define NETLINK_ROUTE 0 /* Routing/device hook */ +#define NETLINK_UNUSED 1 /* Unused number */ +#define NETLINK_USERSOCK 2 /* Reserved for user mode socket protocols */ +#define NETLINK_FIREWALL 3 /* Firewalling hook */ +#define NETLINK_INET_DIAG 4 /* INET socket monitoring */ +#define NETLINK_NFLOG 5 /* netfilter/iptables ULOG */ +#define NETLINK_XFRM 6 /* ipsec */ +#define NETLINK_SELINUX 7 /* SELinux event notifications */ +#define NETLINK_ISCSI 8 /* Open-iSCSI */ +#define NETLINK_AUDIT 9 /* auditing */ +#define NETLINK_FIB_LOOKUP 10 +#define NETLINK_CONNECTOR 11 +#define NETLINK_NETFILTER 12 /* netfilter subsystem */ +#define NETLINK_IP6_FW 13 +#define NETLINK_DNRTMSG 14 /* DECnet routing messages */ +#define NETLINK_KOBJECT_UEVENT 15 /* Kernel messages to userspace */ +#define NETLINK_GENERIC 16 +/* leave room for NETLINK_DM (DM Events) */ +#define NETLINK_SCSITRANSPORT 18 /* SCSI Transports */ +#define NETLINK_ECRYPTFS 19 + +#define MAX_LINKS 32 + +struct sockaddr_nl { + sa_family_t nl_family; /* AF_NETLINK */ + unsigned short nl_pad; /* zero */ + __u32 nl_pid; /* port ID */ + __u32 nl_groups; /* multicast groups mask */ +}; + +struct nlmsghdr { + __u32 nlmsg_len; /* Length of message including header */ + __u16 nlmsg_type; /* Message content */ + __u16 nlmsg_flags; /* Additional flags */ + __u32 nlmsg_seq; /* Sequence number */ + __u32 nlmsg_pid; /* Sending process port ID */ +}; + +/* Flags values */ + +#define NLM_F_REQUEST 1 /* It is request message. */ +#define NLM_F_MULTI 2 /* Multipart message, terminated by NLMSG_DONE */ +#define NLM_F_ACK 4 /* Reply with ack, with zero or error code */ +#define NLM_F_ECHO 8 /* Echo this request */ + +/* Modifiers to GET request */ +#define NLM_F_ROOT 0x100 /* specify tree root */ +#define NLM_F_MATCH 0x200 /* return all matching */ +#define NLM_F_ATOMIC 0x400 /* atomic GET */ +#define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH) + +/* Modifiers to NEW request */ +#define NLM_F_REPLACE 0x100 /* Override existing */ +#define NLM_F_EXCL 0x200 /* Do not touch, if it exists */ +#define NLM_F_CREATE 0x400 /* Create, if it does not exist */ +#define NLM_F_APPEND 0x800 /* Add to end of list */ + +/* + 4.4BSD ADD NLM_F_CREATE|NLM_F_EXCL + 4.4BSD CHANGE NLM_F_REPLACE + + True CHANGE NLM_F_CREATE|NLM_F_REPLACE + Append NLM_F_CREATE + Check NLM_F_EXCL + */ + +#define NLMSG_ALIGNTO 4 +#define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) ) +#define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr))) +#define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(NLMSG_HDRLEN)) +#define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len)) +#define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0))) +#define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \ + (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len))) +#define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \ + (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \ + (nlh)->nlmsg_len <= (len)) +#define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len))) + +#define NLMSG_NOOP 0x1 /* Nothing. */ +#define NLMSG_ERROR 0x2 /* Error */ +#define NLMSG_DONE 0x3 /* End of a dump */ +#define NLMSG_OVERRUN 0x4 /* Data lost */ + +#define NLMSG_MIN_TYPE 0x10 /* < 0x10: reserved control messages */ + +struct nlmsgerr { + int error; + struct nlmsghdr msg; +}; + +#define NETLINK_ADD_MEMBERSHIP 1 +#define NETLINK_DROP_MEMBERSHIP 2 +#define NETLINK_PKTINFO 3 +#define NETLINK_BROADCAST_ERROR 4 +#define NETLINK_NO_ENOBUFS 5 + +struct nl_pktinfo { + __u32 group; +}; + +#define NET_MAJOR 36 /* Major 36 is reserved for networking */ + +enum { + NETLINK_UNCONNECTED = 0, + NETLINK_CONNECTED, +}; + +/* + * <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)--> + * +---------------------+- - -+- - - - - - - - - -+- - -+ + * | Header | Pad | Payload | Pad | + * | (struct nlattr) | ing | | ing | + * +---------------------+- - -+- - - - - - - - - -+- - -+ + * <-------------- nlattr->nla_len --------------> + */ + +struct nlattr { + __u16 nla_len; + __u16 nla_type; +}; + +/* + * 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) + +#define NLA_ALIGNTO 4 +#define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1)) +#define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr))) + +#ifdef __KERNEL__ + +#include <linux/capability.h> +#include <linux/skbuff.h> + +struct net; + +static inline struct nlmsghdr *nlmsg_hdr(const struct sk_buff *skb) +{ + return (struct nlmsghdr *)skb->data; +} + +struct netlink_skb_parms { + struct ucred creds; /* Skb credentials */ + __u32 pid; + __u32 dst_group; + kernel_cap_t eff_cap; + __u32 loginuid; /* Login (audit) uid */ + __u32 sessionid; /* Session id (audit) */ + __u32 sid; /* SELinux security id */ +}; + +#define NETLINK_CB(skb) (*(struct netlink_skb_parms*)&((skb)->cb)) +#define NETLINK_CREDS(skb) (&NETLINK_CB((skb)).creds) + + +extern void netlink_table_grab(void); +extern void netlink_table_ungrab(void); + +extern struct sock *netlink_kernel_create(struct net *net, + int unit,unsigned int groups, + void (*input)(struct sk_buff *skb), + struct mutex *cb_mutex, + struct module *module); +extern void netlink_kernel_release(struct sock *sk); +extern int __netlink_change_ngroups(struct sock *sk, unsigned int groups); +extern int netlink_change_ngroups(struct sock *sk, unsigned int groups); +extern void __netlink_clear_multicast_users(struct sock *sk, unsigned int group); +extern void netlink_clear_multicast_users(struct sock *sk, unsigned int group); +extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err); +extern int netlink_has_listeners(struct sock *sk, unsigned int group); +extern int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 pid, int nonblock); +extern int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, __u32 pid, + __u32 group, gfp_t allocation); +extern int netlink_broadcast_filtered(struct sock *ssk, struct sk_buff *skb, + __u32 pid, __u32 group, gfp_t allocation, + int (*filter)(struct sock *dsk, struct sk_buff *skb, void *data), + void *filter_data); +extern int netlink_set_err(struct sock *ssk, __u32 pid, __u32 group, int code); +extern int netlink_register_notifier(struct notifier_block *nb); +extern int netlink_unregister_notifier(struct notifier_block *nb); + +/* finegrained unicast helpers: */ +struct sock *netlink_getsockbyfilp(struct file *filp); +int netlink_attachskb(struct sock *sk, struct sk_buff *skb, + long *timeo, struct sock *ssk); +void netlink_detachskb(struct sock *sk, struct sk_buff *skb); +int netlink_sendskb(struct sock *sk, struct sk_buff *skb); + +/* + * skb should fit one page. This choice is good for headerless malloc. + * But we should limit to 8K so that userspace does not have to + * use enormous buffer sizes on recvmsg() calls just to avoid + * MSG_TRUNC when PAGE_SIZE is very large. + */ +#if PAGE_SIZE < 8192UL +#define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(PAGE_SIZE) +#else +#define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(8192UL) +#endif + +#define NLMSG_DEFAULT_SIZE (NLMSG_GOODSIZE - NLMSG_HDRLEN) + + +struct netlink_callback { + struct sk_buff *skb; + const struct nlmsghdr *nlh; + int (*dump)(struct sk_buff * skb, + struct netlink_callback *cb); + int (*done)(struct netlink_callback *cb); + int family; + long args[6]; +}; + +struct netlink_notify { + struct net *net; + int pid; + int protocol; +}; + +static __inline__ struct nlmsghdr * +__nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len, int flags) +{ + struct nlmsghdr *nlh; + int size = NLMSG_LENGTH(len); + + nlh = (struct nlmsghdr*)skb_put(skb, NLMSG_ALIGN(size)); + nlh->nlmsg_type = type; + nlh->nlmsg_len = size; + nlh->nlmsg_flags = flags; + nlh->nlmsg_pid = pid; + nlh->nlmsg_seq = seq; + if (!__builtin_constant_p(size) || NLMSG_ALIGN(size) - size != 0) + memset(NLMSG_DATA(nlh) + len, 0, NLMSG_ALIGN(size) - size); + return nlh; +} + +#define NLMSG_NEW(skb, pid, seq, type, len, flags) \ +({ if (unlikely(skb_tailroom(skb) < (int)NLMSG_SPACE(len))) \ + goto nlmsg_failure; \ + __nlmsg_put(skb, pid, seq, type, len, flags); }) + +#define NLMSG_PUT(skb, pid, seq, type, len) \ + NLMSG_NEW(skb, pid, seq, type, len, 0) + +extern int netlink_dump_start(struct sock *ssk, struct sk_buff *skb, + const struct nlmsghdr *nlh, + int (*dump)(struct sk_buff *skb, struct netlink_callback*), + int (*done)(struct netlink_callback*)); + + +#define NL_NONROOT_RECV 0x1 +#define NL_NONROOT_SEND 0x2 +extern void netlink_set_nonroot(int protocol, unsigned flag); + +#endif /* __KERNEL__ */ + +#endif /* __LINUX_NETLINK_H */ ^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-12-22 19:52 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-12-17 14:20 [ANNOUNCE] libmnl 1.0.0 release Pablo Neira Ayuso 2010-12-18 5:23 ` Rob Sterenborg (lists) 2010-12-18 12:40 ` Pablo Neira Ayuso 2010-12-18 12:53 ` Pablo Neira Ayuso 2010-12-18 15:35 ` Jan Engelhardt 2010-12-21 20:19 ` Pablo Neira Ayuso 2010-12-21 20:22 ` David Miller 2010-12-21 20:31 ` Pablo Neira Ayuso 2010-12-22 19:52 ` Pablo Neira Ayuso
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).