libnfnetlink Docu
Hi Pablo, hello readers of the list,
as already promised, I wrote a small documentation on libnfnetlink (based on version 0.0.16-pablo-r1). It has now reached a state, where I dare showing it (see attached). There are some points still missing:
* nfnl_sendmsg, nfnl_sendiov - may come in the next revision
* get message_first and _next - I'm working out the difference to the iterator API at the moment, it will therefore definitely be in one of the next revisions.
* attributes - will definitely be in one of the next revisions
* _step, _is_error, _handle_[msg|packet] - are they intended for public use or internal functions of the lib (that should not occur in the docu)?
There are two different ways of joining multicast groups. nfnl_join, that uses setsockopt and recalc_rebind_subscriptions (used by nfnl_subsys_open), that uses bind. I think, this difference should be mentioned in the docu, but I don't see, why it is needed. As far, as I see it atm, only nfnl_join (because of its more understandable name, with whatever interface is better) should be used and shoud set nfnlh->subscriptions, what it does not do atm.
The last point, I want to mention is the use of nfnl_handle *h in nfnl_iterator_create and nfnl_iterator_next. They both don't use the handle, so wouldn't it be better to remove it from their argument list? I wonder how many existing implementations using libnfnetlink would break. I assume, it would only be the subsystem libraries, which can be changed relatively easy.
I ask you to please provide comments on my paper. It was made with the goal of making the official documentation of the lib one day in mind ;o)
so long
Maik
<!doctype linuxdoc system>
<article>
<title>libnfnetlink API documentation
<author>Maik Hentsche, mailing list <tt>[email protected]</tt> <date>$Revision: 0.1 $ $Date: 2006/09/25 09:20:00 $
<abstract>
This document describes the API of libnfnetlink, the basic library for communication with netfilter/iptables through a netlink device. </abstract>
<toc>
<sect>Introduction<label id="intro">
<p>
Greatings mortal,
<p>
your are about to enter the dark dungeon of libnfnetlink. Communication with netfilter has been nonuniform so far, but a new approach tries to eliminiate this issue. All communication goes now through a netlink device. The library libnfnetlink puts an abstraction layer into this communication. All operations of this lib a based upon a handle, the user has to work with. Each handle keeps a number of subsystem handles. These subsystems are responsible for comnunication with different parts of netfilter, for example for logging through ULOG or reading an manipulation of the connection tracking tables using the CTNETLINK subsystem. For using these subsystems, specialized libraries, which add another level of abstraction, exist and should be used additionally.
<sect>Headers and Data Structures<label id="datastruct">
<p>
To use libnfnetlink, you should <tt>#include <libnfnetlink/nfnetlink.h></tt> and link your program with <tt>-lnfnetlink</tt>. nfnetlink.h defines two important structs, a programmer needs to know (in fact they are forward definitions, but that should not make a difference). The first one is the handle, that encapsulates all access to the nfnetlink facility:
<tscreen><verb>
struct nfnl_handle {
int fd;
struct sockaddr_nl local;
struct sockaddr_nl peer;
u_int32_t subscriptions;
u_int32_t seq;
u_int32_t dump;
struct nlmsghdr *last_nlhdr;
struct nfnl_subsys_handle subsys[NFNL_MAX_SUBSYS+1];
};</verb></tscreen>
You should not try to access the filedescriptor fd directly but instead use the function <ref id="nfnl_fd" name ="nfnl_fd()">, whenever you need it. Subscribtions is a bit field of the netlink groups, at least one subsystem managed by this handle, is subscribed to. The array subsys keeps one entry for every existing subsystem. At the moment, the size of this array and thus the number of possible subsystems is limited to 16 and even less subsystem already exist. To create this handle <ref id="nfnl_open" name="nfnl_open()"> ist used.
<p>
As already mentioned, a handle contains a number of subsys_handles. These are created with <ref id="nfnl_subsys_open" name="nfnl_subsys_open()"> and are defined as follows:
<tscreen><verb>
struct nfnl_subsys_handle {
struct nfnl_handle *nfnlh;
u_int32_t subscriptions;
u_int8_t subsys_id;
u_int8_t cb_count;
struct nfnl_callback *cb;
};</verb></tscreen>
nfnlh is a link back to the nfnetlink handle and subscriptions is again a bitfield of netlink groups, this subsys_handle is subscribed to. *cb is an array of callbacks, registered for this subsys_handle.
<p>
A callback is a function, which is called, when a message for the subsystem arrives. The callback is supposed to handle that message. It can be registered using <ref id="nfnl_callback_register" name="nfnl_callback_register()">. This function uses the following data structure:
<label id="nfnl_callback">
<tscreen><verb>
struct nfnl_callback {
int (*call)(struct nlmsghdr *nlh, struct nfattr *nfa[], void *data);
void *data;
u_int16_t attr_count;
};</verb></tscreen>
In this case, call is a function pointer to an appropriate callback function. The pointer data, used in the struct nfnl_callback given to <ref id="nfnl_callback_register" name="nfnl_callback_register()"> is passed to the callback whenever it is executed.
<sect>Basic Functions
<p>
The following sections contain short descriptions of all functions, that a user of the libnfnetlink needs to know. All errors, a function may generate, are listed. If a not listed error occurs, this is a bug (most probably in the lib, in rare exceptions even in this documentation). Please report it.
<sect1>nfnl_open<label id="nfnl_open">
<p>
<tscreen><verb>
struct nfnl_handle *nfnl_open(void)
</verb></tscreen>
<p>
This function creates a nfnetlink handle, which is required to establish a communication between the userspace and the nfnetlink system. As you see, it takes no argument.
<p>
On success, a valid address that points to a nfnl_handle structure
is returned. On error, NULL is returned and errno is set approapiately.
<p>
Possible errors are:
<itemize>
<item><bf>ENOMEM</bf> or <bf>ENOBUFS</bf> Not enough memory to allocate the handle or data structures needed for its initialisation
<item><bf>EMFILE</bf> or <bf>ENFILE</bf> The system limit on the total number of open files has been reached.
<item><bf>EINVAL</bf> No netlink support in the kernel.
</itemize>
<sect1>nfnl_close<label id="nfnl_close">
<p>
<tscreen><verb>
int nfnl_close(struct nfnl_handle *nfnlh)
</verb></tscreen>
<p>
This function closes a nfnetlink handle.
<p>The argument of the function has the following meaning:
<itemize>
<item><bf>struct nfnl_handle *nfnlh</bf> The nfnetlink handle, that is to be closed.
</itemize>
<p>
On success, 0 is returned. On error, -1 is returned and errno is set appropiately.
<p>
Possible errors are:
<itemize>
<item><bf>EBADF</bf> The handle was not opened or already closed before. <item><bf>EINTR</bf> A systemcall used in this function was interrupted by a signal. Please retry closing the handle.
<!-- (FIXME: Is that possible at all or are interrupted syscalls restarted in --> <!-- linux? Assume they are not.) -->
</itemize>
<sect1>nfnl_subsys_open<label id="nfnl_subsys_open">
<p>
<tscreen><verb>
struct nfnl_subsys_handle *nfnl_subsys_open(struct nfnl_handle *nfnlh, u_int8_t subsys_id, u_int8_t cb_count, u_int32_t subscriptions) </verb></tscreen>
<p>
This function creates a subsystem handle that contains the set of callbacks,
which handle certain types of messages coming from a netfilter
subsystem. Initially the callback set is empty, you can register callbacks
via <ref id="nfnl_callback_register" name="nfnl_callback_register()">. It is
possible, to have several different subsystems opened for one netlink handle
or the same subsystem for different netlink handles, but it is not allowed to
open one subsystem multiple times for one and the same netlink handle.
<p>
The arguments of this function have the following meaning:
<itemize>
<item><bf>struct nfnl_handle *nfnlh</bf> The netlink handle, for which this
subsystem shall be opened. This handle needs to be opened before.
<item><bf>u_int8_t sybsys_id</bf> The number of the subsystem, you want to
open. At the moment, the following subsystems are defined:
<itemize>
<item><bf>NFNL_SUBSYS_NONE</bf>
<item><bf>NFNL_SUBSYS_CTNETLINK</bf>
<item><bf>NFNL_SUBSYS_CTNETLINK_EXP</bf>
<item><bf>NFNL_SUBSYS_QUEUE</bf>
<item><bf>NFNL_SUBSYS_ULOG</bf>
<item><bf>NFNL_SUBSYS_CTHELPER</bf>
<item><bf>NFNL_SUBSYS_COUNT</bf>
</itemize> <item><bf>u_int8_t cb_count</bf> The number of callbacks that are used maximum. This value is dependend on the subsystem.
<item><bf>u_int32_t subscribtions</bf> The netlink groups you want to be subscribed to. This is is used as a bit field, so you have to set the appropriate bit to subscribe to one specific netlink group. The meaning of these groups is again dependend on the subsystem used.
</itemize>
<p>
On error, NULL is returned and errno is set appropiately. On success,
a valid address that points to a nfnl_subsys_handle structure is returned. <p>
Possible errors are:
<itemize>
<item><bf>ENOMEM</bf> or <bf>ENOBUFS</bf> Not enough memory to allocate the handle or data structures needed for its initialisation
<item><bf>ENOENT</bf> The specified subsystem id does not correespond to any existing subsystem.
<item><bf>EBUSY</bf> This subsystem has already been opened for this netlink handle.
<!-- <item>FIXME: EACCESS? EADDRINUSE? Don't see atm, if they are possible. --> </itemize>
<sect1>nfnl_subsys_close<label id="nfnl_subsys_close"> <p>
<tscreen><verb>
void nfnl_subsys_close(struct nfnl_subsys_handle *ssh) </verb></tscreen>
<p>
This function closes a subsystem handle. All callbacks, that are not yet unregistered for this subsystem are released.
<p>
The arguments of this function have the following meaning:
<itemize>
<item><bf>struct nfnl_subsys_handle *ssh</bf> The subsys_handle to be closed.
</itemize>
<p>
No errors should occur.
<sect1>nfnl_recv<label id="nfnl_recv">
<p>
<tscreen><verb>ssize_t nfnl_recv(const struct nfnl_handle *h, unsigned char *buf, size_t len) </verb></tscreen>
<p>
This function is used to receive data from the netlink device. No sanity
checks are performed and no callback function is executed. The buffer, given to this function needs to be at least big enough to hold a struct nlmsgerr, which is used for error reporting. A size of <bf>NFNL_BUFFSIZE</bf> is recommended. nfnl_recv() does not do any sanity checks.
<p>
The arguments of this function have the following meaning:
<itemize>
<item><bf>struct nfnl_handle *h</bf> The nfnetlink handle to receive from. <item><bf>unsigned char buf</bf> The buffer where the data will be stored. <item><bf>size_t len</bf> The size of the buffer.
</itemize>
<p>
On success, the number of received bytes is returned. On error, -1 is returned
and errno is set appropiately. In case ENOBUFS is returned, it is possible that data is lost.
<p>
Possible errors are:
<itemize>
<item><bf>ENOBUFS</bf> The buffer, you passed was to small or the netlink device was exhausted. In the later case, increasing the receive buffer size with <ref id="nfnl_rcvbufsiz" name ="nfnl_rcvbufsiz"> may help. <item><bf>EINTR</bf> The receive was interrupted by delivery of a signal before any data were available.
</itemize>
<sect1>nfnl_send<label id="nfnl_send">
<p>
<tscreen><verb>
int nfnl_send(struct nfnl_handle *nfnlh, struct nlmsghdr *n) </verb></tscreen>
<p>
This is one function, which can be used to send a nfnetlink message through
netlink socket. The meaning of these messages is of course heavily dependend on the subsystem, so the use of the appropiate subsystem library is encouragaed. If you are sure, you need to build such a message yourself, you should use <ref id="nfnl_fill_hdr" name="nfnl_fill_hdr()"> to generate the header. nfnl_send() does not do any sanity checks.
<p>
The arguments of this function have the following meaning:
<itemize>
<item><bf>struct nfnl_handle *nfnlh</bf> The nfnetlink handle, to which you want to send your message.
<item><bf>struct nlmsghdr * n</bf> The header of the netlink message to be send.
</itemize>
<p>
On success, the number of send bytes is returned. On error, -1 is returned and errno is set appropiately.
<p>
Possible errors for this function are:
<itemize>
<item><bf>ENOBUFS</bf> The netlink device was exhausted. Data loss is highly probable.
<item><bf>EMSGSIZE</bf> The size of your message was to big. <item><bf>EFAULT</bf> The message, you passed was invalid.
</itemize>
<sect>Callback Handling Functions<label id="callbackfunc">
<p>
A callback is a function, which is called by a message parsing function to handle a nfnetlink message. Every callback is responsible for one specific type of message of one specific subsystem. The callback function has to return an integer. In case of an error, it should return -1 and set errno appropriatelly. This will force the calling function to stop processing of the received messages immediatelly. If the callback returned 0, the calling function will stop receiving messages. A positive return value lets the caller continue receiving messages.
<sect1>nfnl_callback_register<label id="nfnl_callback_register">
<p>
<tscreen><verb>
int nfnl_callback_register(struct nfnl_subsys_handle *ssh, u_int8_t type, struct nfnl_callback *cb) </verb></tscreen>
<p>
This function registers a callback for a certain message type. This callback is executed every time a message of the specified type arrives.
<p>
The arguments of this function have the following meaning:
<itemize>
<item><bf>struct nfnl_subsys_handle *ssh</bf> The subsys_handle, which should have this callback registered.
<item><bf>u_int8_t type</bf> The type of messages, this callback is responsible for. It is dependend on the subsystem. <item><bf>struct nfnl_callback *cb</bf> The callback to be registered. This struct is discussed <ref id="nfnl_callback" name="here">.
</itemize>
<p>
On success, 0 is returned. On error, -1 is returned and errno is set appropiately.
<p>
Possible errors are:
<itemize>
<item><bf>EINVAL</bf> The message type is outside the range requested in <ref id="nfnl_subsys_open" name="nfnl_subsys_open()">
</itemize>
<sect1>nfnl_callback_unregister<label id="nfnl_callback_unregister"> <p>
<tscreen><verb>
int nfnl_callback_unregister(struct nfnl_subsys_handle *ssh, u_int8_t type) </verb></tscreen>
<p>
This function unregisters a callback for a certain message type. It is possible to unregister the callbacks for a message type, for which no callback has ever been registered.
<p>
The arguments of this function have the following meaning:
<itemize>
<item><bf>struct nfnl_subsys_handle *ssh</bf> The subsys_handle, which has this callback registered.
<item><bf>u_int8_t type</bf> The type of messages, this callback was registered for. It is dependend on the subsystem.
</itemize>
<p>
On success, 0 is returned. On error, -1 is returned and errno is set appropiately.
<p>
Possible errors are:
<itemize>
<item><bf>EINVAL</bf> The message type is outside the range requested in <ref id="nfnl_subsys_open" name="nfnl_subsys_open()">
</itemize>
<sect>Processing Functions<label id="processing">
<p>
Processing is one of two APIs (the other is the <ref id="iterator" name="iterator API">) for handling nfnetlink messages. If multiple messages arrive in one packet, functions of this API handle them together and do not offer access to every single message. Message handling is done using <ref id="callbackfunc" name="callback functions">. If a message is received, for which no callback is registered, this message is discarded. The functions described below offer different abstraction levels of receiving and processing incoming messages. They are sorted from highest to lowest abstraction level. In most cases, you can use <ref id="nfnl_catch" name="nfnl_catch()"> for receiving messages or even <ref id="nfnl_query" name="nfnl_query()"> for sending a number of messages and receiving answers.
<sect1>nfnl_query<label id="nfnl_query">
<p>
<tscreen><verb>
int nfnl_catch(struct nfnl_handle *h)
</verb></tscreen>
<p>
This function sends a nfnetlink message to a certain subsystem and receives the response messages associated. It uses <ref id="nfnl_catch" name="nfnl_catch()"> for receiving and <ref id="nfnl_send" name="nfnl_send()"> for sending, so its behaviour is dictated by them. nfnl_query replaces the now deprecated nfnl_talk.
<p>
The argument of the function has the following meaning:
<itemize>
<item><bf>struct nfnl_handle *h</bf> The nfnetlink handle to be used.
</itemize>
<p>
On success, 0 is returned. On error, a negative value is returned.
<p>
Possible errors for this function are:
<itemize>
<item><bf>ENOMEM</bf> or <bf>ENOBUFS</bf> Not enough memory to allocate the handle or data structures needed for its initialisation. It is possible to loose data in that case.
<item><bf>EILSEQ</bf> The sequence number of a received netlink message was out of sync. Data loss is most probable.
<item><bf>ENOENT</bf> A message of a not opened subsystem has been
received or not callback was registered for the received message type. You can continue receiving messages using <ref id="nfnl_catch" name="nfnl_catch()"> for example. The message, that generated this error will be lost.
</itemize>
<sect1>nfnl_catch<label id="nfnl_catch">
<p>
<tscreen><verb>
int nfnl_catch(struct nfnl_handle *h)
</verb></tscreen>
<p>
This functions sleeps until a message arrives through the netlink device and
processes this messages afterwards. Processing is done by calling the appropriate registered callback function for a received message. If this callback returns 1, nfnl_catch will continue its work, if it return 0, nfnl_catch stops without an error and a return value of -1 is threaded as an error within the processing of the callback and let nfnl_catch return immediatelly. nfnl_catch replaces the now deprecated nfnl_listen. Note, that information may be lost, if an error occurs within this function.
<p>
The argument of this function has the following meaning:
<itemize>
<item><bf>struct nfnl_handle *h</bf> The nfnetlink handle, that should process the received message.
</itemize>
<p>
On success, 0 is returned. On error, a -1 is returned.
<p>
Possible error are:
<itemize>
<item><bf>ENOMEM</bf> or <bf>ENOBUFS</bf> Not enough memory to allocate the handle or data structures needed for its initialisation. It is possible to loose data in that case.
<item><bf>EILSEQ</bf> The sequence number of a received netlink message was out of sync. Data loss is most probable.
<item><bf>ENOENT</bf> A message of a not opened subsystem has been
received or not callback was registered for the received message type. You can continue receiving messages for example by calling this function
again. The message, that generated this error will be lost.
</itemize>
<sect1>nfnl_process<label id="nfnl_process">
<p>
<tscreen><verb>
int nfnl_process(struct nfnl_handle *h, const unsigned char *buf, size_t len) </verb></tscreen>
<p>
This function processes all the nfnetlink messages contained inside a buffer filled with <ref id="nfnl_recv" name="nfnl_recv()"> for example. It performs the appropiate sanity checks and passes the message to a certain callback function that is registered via <ref id="nfnl_callback_register" name="nfnl_callback_register()">.
<p>
The arguments of this function have the following meaning:
<itemize>
<item><bf>struct nfhandle *h</bf> The nfnetlink handle to be used. <item><bf>const unsigned char *buf</bf> The buffer that contains the netlink message.
<item><bf>size_t len</bf> The size of the data contained in the buffer (<bf>NOT</bf> the buffer size)
</itemize>
<p>
On success, 0 is returned if the data processing has finished. If a value > 0 is returned, then there is more data to process. On error, -1 is returned and errno is set to the appropiate value.
Note that the callback must return -1 and set errno in case of error. If your callback decides not to process data anymore for any reason, then it must return 0. Otherwise, if the callback continues the processing 1 has to be returned.
<p>
Possible error are:
<itemize>
<item><bf>EILSEQ</bf> The sequence number of a received netlink message was out of sync. Data loss is most probable.
<item><bf>ENOENT</bf> A message of a not opened subsystem has been received or not callback was registered for the received message type. Since the message is still in the buffer, you can correct this error and call this function again.
<!-- Not sure, is ENOSPC can occur. Does the test in while prevent this? --> </itemize>
<sect>Iterator API<label id="iterator">
<p>
To ease parsing of multiple messages, an API based on iterators is offered by libnfnetlink. An iterator is a data structure, that keeps a pointer to the next available message. Thus the user can simply iterate through all messages using the associated functions. The iterator API is an alternative to the functions discussed in section <ref id="processing" name="processing functions">. The struct nfnl_iterator was not discussed in section <ref id="datastruct" name="headers and data structures"> because its knowledge is not considered valueable for a user of the lib, who can treat this struct as an opaque data structure. To use this API, you need messages received with <ref
id="nfnl_recv" name="nfnl_recv()"> for example.
<sect1>nfnl_iterator_create<label id="nfnl_iterator_create">
<p>
<tscreen><verb>
struct nfnl_iterator *nfnl_iterator_create(const struct nfnl_handle *h, const char *buf, size_t len) </verb></tscreen>
<p>
This function creates an iterator, that can be used to parse netfilter netlink
messages one by one.
<p>
The arguments of this function have the following meaning:
<itemize>
<item><bf>struct nfnl_handle *h</bf> The nfnetlink handle responsible for this message.
<item><bf>char *buf</bf> The buffer that contains data received from a nfnetlink system.
<item><bf>size_t len</bf> The size of the data contained in the buffer (not the buffer size).
</itemize>
<p>
On success, an address of valid iterator is returned. On error, NULL is
returned and errno is set to the appropiate value.
<p>
Possible errors are:
<itemize>
<item><bf>ENOMEM</bf> No enough memory to allocate a new iterator. <item><bf>EBADMSG</bf> The buffer, you provided, does not contain a valid nfnetlink message.
</itemize>
<sect1>nfnl_iterator_destroy<label id="nfnl_iterator_destroy"> <p>
<tscreen><verb>
void nfnl_iterator_destroy(struct nfnl_iterator *it) </verb></tscreen>
<p>
This function destroys a certain iterator and therefore should be called, when you are finished handling all messages in the buffer associated with this iterator.
<p>
The argument of this function has the following meaning:
<itemize>
<item><bf>struct nfnl_iterator *it</bf> The nfnetlink iterator to be destroyed.
</itemize>
Nothing is returned and no errors should occur.
<sect1>nfnl_iterator_next<label id="nfnl_iterator_next">
<p>
<tscreen><verb>
int nfnl_iterator_next(const struct nfnl_handle *h, struct nfnl_iterator *it) </verb></tscreen>
<p>
This function updates the pointer to the current message to be processed.
<p>
The arguments of this function have the following meaning:
<itemize>
<item><bf>struct nfnl_handle *h</bf> A nfnetlink handle. This argument is not used.
<item><bf>struct nfnl_iterator *it</bf> The nfnetlink iterator that is to be updated.
</itemize>
<p>
This function returns 1 if there is still more messages to be processed, otherwise 0 is returned.
<p>
No error checking is done and therefore, no errors should occur in this function.
<sect1>nfnl_iterator_process<label id="nfnl_iterator_process"> <p>
<tscreen><verb>
int nfnl_iterator_process(struct nfnl_handle *h, struct nfnl_iterator *it) </verb></tscreen>
This function process just the current message selected by the iterator. It performs sanity checks and passes the message to the appropriate callback function. It does not update the iterator and does not check for subsequent messages in the associated buffer.
<p>
<itemize>
<item><bf>struct nfnl_handle *h</bf> The nfnetlink handle, that was used to fill the buffer associated with this iterator. It is needed for sanity checks.
<item><bf>struct iterator *it</bf> The nfnetlink iterator that contains the current message to be proccesed.
</itemize>
<p>
On success, a value greater or equal to zero is returned. On error, -1 is returned and errno is appropiately set.
<p>
Possible errors are:
<itemize>
<item><bf>EILSEQ</bf> The sequence number of a received netlink message was out of sync. Data loss is most probable.
<item><bf>ENOENT</bf> A message of a not opened subsystem has been received or not callback was registered for the received message type. Since the message is still in the buffer, you can correct this error and call this function again.
</itemize>
<sect>Helper functions
<sect1>nfnl_fd<label id="nfnl_fd">
<p>
<tscreen><verb>
int nfnl_fd(struct nfnl_handle *h)
</verb></tscreen>
<p>
This function returns the file descriptor associated with the handle. This might be needed for example when using poll() or select().
<p>
The argument of this function has the following meaning:
<itemize>
<item><bf>struct nfnl_handle *h</bf>The nfnetlink handle to be used.
</itemize>
<p>
No errors should occur.
<sect1>nfnl_rcvbufsiz<label id="nfnl_rcvbufsiz">
<p>
<tscreen><verb>
unsigned int nfnl_rcvbufsiz(struct nfnl_handle *h, unsigned int size) </verb></tscreen>
<p>
This function sets the new size of the socket buffer. Use this setting to increase the socket buffer size if your system is reporting ENOBUFS errors. The function tries to force setting the requested size even if it is above the systemwide maximum. This force might fail, so check the return value.
<p>
The arguments of this function have the following meaning:
<itemize>
<item><bf>struct nfnl_handle *h</bf> The nfnetlink handle to be used. <item><bf>unsigned int size</bf> The size of the buffer you want to set.
</itemize>
<p>
This function returns the new size of the socket buffer. The new size may
differ from the requested size. No errors should occur.
<sect1>nfnl_join<label id="nfnl_join">
<p>
<tscreen><verb>
int nfnl_join(const struct nfnl_handle *nfnlh, unsigned int group) </verb></tscreen>
<p>
This function is used to join a certain multicast group. The meaning of these groups is dependend on the subsystem.
<p>
The arguments of this function have the following meaning:
<itemize>
<item><bf>struct nfnl_handle *nfnlh</bf> The nfnetlink handle to be used. <item><bf>unsigned int group</bf> The multicast group we want to join. This value needs to be between 1 and 32.
</itemize>
<p>
This function returns 0 on success. On error, -1 is returned and errno is set approapiately.
<p>
Possible errors are:
<itemize>
<item><bf>EINVAL</bf> Group is out of range 1 to 32.
</itemize>
<sect1>nfnl_fill_hdr<label id="nfnl_fill_hdr">
<p>
<tscreen><verb>
void nfnl_fill_hdr(struct nfnl_subsys_handle *ssh, struct nlmsghdr *nlh, unsigned int len, u_int8_t family, u_int16_t res_id, u_int16_t msg_type, u_int16_t msg_flags) </verb></tscreen>
<p>
This function sets up appropiately the nfnetlink header. See that the pointer to the netlink message passed must point to a memory region of at least the size of struct nlmsghdr + struct nfgenmsg.
<p>
The arguments of this function have the following meaning. <itemize>
<item><bf>struct nfnl_subsys_handle *ssh</bf> The handle for the subsystem, the message will be send to.
<item><bf>struct nlmsghdr *nlh</bf> A pointer to the buffer, that will contain the netlink message.
<item><bf>unsigned int len</bf> The length of <em>payload</em> bytes (not including nfgenmsg)
<item><bf>u_int8_t family</bf> The address family like AF_INET, ... <item><bf>u_int16_t res_id</bf> resource id <item><bf>u_int16_t msg_type</bf> nfnetlink message type (without subsystem)
<item><bf>u_int16_t msg_flags</bf> Netlink message flags
</itemize>
No value is returned and no error should occur.
</article>