dect
/
libnl
Archived
13
0
Fork 0
Commit Graph

54 Commits

Author SHA1 Message Date
Thomas Graf 807fddc4cd nl: Increase receive buffer size to 4 pages
Assuming that the kernel does not send more than a page is no longer valid,
and enabling MSG_PEEK'ing by default to figure out the exact message buffer
requirements can have a negative influence on the performance of existing
applications. Bumping the default receive buffer space to 4 pages seems
a sane default.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-05-08 13:52:27 +02:00
Thomas Graf 375a6294a4 nl: Return -NLE_AGAIN if non-blocking socket would block
Previously 0 was returned which gave the caller no chance of detecting
when a non-blocking socket would block. If a caller intends to never
see an error message it should utilize poll()/select() to only read
when the socket has pending data or information.

Reported-by: Holger Eitzenberger <holger@eitzenberger.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-04-02 11:58:18 +02:00
Thomas Graf 9680f910f4 Move private header files to <netlink-private/*>
This clarifies the seperation between public and private
header files.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-01-24 13:51:24 +01:00
Thomas Graf 665464cde5 nl: Improve API doc of nl_send_simple()
Signed-off-by: Thomas Graf <tgraf@redhat.com>
2012-11-08 21:17:32 +01:00
Thomas Graf b28c25eb23 nl: Improve API doc of nl_connect() and nl_close()
Signed-off-by: Thomas Graf <tgraf@redhat.com>
2012-11-08 13:41:54 +01:00
Thomas Graf fd6f205f8a nl: Allow to overwrite nl_send()
Up to now only calls to nl_send_auto() could be overwritten with
nl_cb_overwrite_send(). This patch extends the capability to
nl_send()

Signed-off-by: Thomas Graf <tgraf@redhat.com>
2012-11-08 13:19:07 +01:00
Thomas Graf b132ee7e27 nl: improve API doc of transmit functions
Signed-off-by: Thomas Graf <tgraf@redhat.com>
2012-11-08 01:29:12 +01:00
Thomas Graf 8f47501741 nl: improve nl_sendto() docs and error checks
Make nl_sendto() return NLE_INVAL if provided buffer is NULL
and make it return NLE_BAD_SOCK if the socket is not connected.

Add note in docs about lack of NL_CB_MSG_OUT invokation
2012-11-06 17:48:28 +01:00
Thomas Graf 65f97deb63 nl_recv: fix indent style 2012-11-06 14:27:34 +01:00
Thomas Graf 220d8e141d nl_recv: return NLE_INVAL if socket address pointer is NULL 2012-11-06 14:24:09 +01:00
Thomas Graf eb36066909 nl_recv: return NLE_INVAL if buf is NULL 2012-11-06 14:22:50 +01:00
Thomas Graf fb42f19e2e nl_recv: improve function documentation 2012-11-06 14:21:18 +01:00
Thomas Graf 6d52ae6440 nl_recv: Don't update *buf in error path
iov.iov_base is either NULL or invalid
2012-11-06 00:21:35 +01:00
Thomas Graf ceb8fb9e87 Document buffer size limitations of nl_recv() 2012-11-06 00:19:28 +01:00
Коренберг Марк (дома) 420e4623fd nl_recv(): work with credentials only if "creds" given and NL_SOCK_PASSCRED set 2012-10-19 23:51:59 +06:00
Коренберг Марк (дома) da694e6c7b nl_recv(): small code cleanups
1. memset around nla is unnecessary
2. calloc() is unnecessary. malloc() used instead.
2012-10-19 23:49:30 +06:00
Коренберг Марк (дома) 2249eaebd4 nl_recv(): EWOULDBLOCK return value also checked 2012-10-19 23:49:30 +06:00
Коренберг Марк (дома) 69468517d0 nl_recv(): Memory allocation errors are handled properly now
1. all cleanup actions (like free()) now located at the end of function
2. in case of error or EOF, *buf and *creds (if given) set to NULL
   This protect from invalid code at user's side, like:
   char *buf;
   x = nl_recv(..., &buf, ...);
   if (x<=0)
      goto cleanup;
   cleanup:
      free(buf);
3. all intermediate buffers are stored into local variables, and user's
   variables only touches at the end.
2012-10-19 23:48:46 +06:00
Коренберг Марк (ноутбук дома) 9d6b104ec8 nl_recv(): "else if" logick simplified and refined 2012-10-19 22:43:17 +06:00
Коренберг Марк (ноутбук дома) e1b67fb23f Clang diagnostics
Based on clang diagnostics:

1. lib/nl.c: recvmsgs(): nla filling with zeros commented.
2. lib/route/classid.c: & lib/route/pktloc.c:
   remove zero-filling of struct stat
3. lib/route/qdisc/htb.c: Fix htb_qdisc_msg_fill(): fix zero-filling
4. ematch/container.c: container_parse:
   commented why only 4 bytes are copied
   len marked as unused to eliminate compiler warning
2012-10-19 22:32:59 +06:00
Thomas Graf e4192ff97f nl: Provide API to specify the default buffer size when receiving netlink messages
New functions:
  nl_socket_set_msg_buf_size(sk, size)
  nl_socket_get_msg_buf_size(sk)

Default remains getpagesize()

Signed-off-by: Thomas Graf <tgraf@redhat.com>
2012-10-09 16:16:54 +02:00
Коренберг Марк 8f2ce4d791 More clean NL_AUTO_PORT and NL_AUTO_SEQ usage in nl_complete_msg 2012-08-30 18:40:25 +06:00
Коренберг Марк (дома) 5eee974e03 Prevent potential socket file descriptor leak
This may happen when passing connected socket to nl_cache_mngr_alloc().

Now, nl_connect() will return error trying to connect already connected socket.

Also, dont call close(-1) if socket() fails.
2012-08-30 04:36:28 +06:00
Коренберг Марк 2bdcde7e8e Fix types-related warnings based on clang diagnostics
1. Fix some places where unsigned value compared < 0
2. Fix obsolete %Z specifier to more portable %z
3. Some erroneous types substitution
4. nl_msec2str() - 64-bit msec is now properly used,

Only safe changes. I mean int <--> uint32_t and signed/unsigned fixes.
Some functinos require size_t argument instead of int, but changes of
signatures of that functions is terrible thing.

Also, I do not pretend for a full list of fixes.
Just to shut up clang -Wall -Wextra

One more thing. ifindex. I don't change that because changes will
be too big for simple fix.
2012-06-13 13:30:26 +02:00
Jiri Pirko d733f8a0a6 use MSG_TRUNC flag to get recv message size at once
prevent multiple calls of recvmsg.

Signed-off-by: Jiri Pirko <jpirko@redhat.com>
2012-05-29 11:46:01 +02:00
Thomas Graf fec10a2823 doc: documentation restructuring
- changes the modules hierarchy to better represent the set of libaries
- list the header file that needs to be included
- remove examples/doc from api ref that is included in the guide
- add references to the guide
- fix doxygen api linking for version 1.8.0
- readd doxygen mainpage to config file
- fix a couple of doxygen doc bugs
2012-05-10 12:03:59 +02:00
Thomas Graf 6f156a7b58 nl: Fix return value of nl_recvmsgs()
Apparently the change to have nl_recvmsgs() return the number of
parsed messages broke nl_wait_for_ack() among other applications.

This patch reverts to the old behaviour and provides a new function
nl_recvmsgs_report() which provides the additional information for
use by the cache manager and possibly other applications.

Reported-by: Scott Bonar <sbonar@cradlepoint.com>
Signed-off-by: Thomas Graf <tgraf@redhat.com>
2012-05-08 22:48:00 +02:00
Thomas Graf e0482794a8 nl: Make nl_recvmsgs() return the number of netlink messages processed 2012-04-21 12:46:01 +02:00
Thomas Graf 8104b52f75 Fix typo in debug message 2011-10-28 12:30:31 +02:00
Thomas Graf 21d52eabba Support for NLM_F_INTR
Check if a dump was interrupted and needs to be redone
2011-07-14 10:51:49 +02:00
Thomas Graf ca0fc75580 socket: Set SOCK_CLOEXEC if available
Reported by Марк Коренберг <socketpair@gmail.com>
2011-06-15 17:37:28 +02:00
Thomas Graf 48d543cfdf API to issue direct GET requests to the kernel
Provide nl_pickup() to pick up an answer from a netlink request and parse
it using the supplied parser.

Add rtnl_link_get_kernel() which sends an RTM_GETLINK to the kernel to
fetch a single link directly from the kernel. This can be faster than
dumping the whole table, especially if lots of links are configured.
2011-04-11 12:34:01 +02:00
Thomas Graf 23845e942c Add nl_send_sync()
Function which sends message using nl_send_auto(), frees the message and
waits for ACK/error message (if auto-ack is not disabled).
2011-03-25 18:11:52 +01:00
Thomas Graf 4fb528bbaf nl_recv(): Zero out sockaddr in case the caller forgot 2010-11-22 14:19:40 +01:00
Thomas Graf 9fbdf6c92a nl_recv(): Make passing creds pointer optional 2010-11-22 14:18:59 +01:00
Thomas Graf e52a09c507 nl: rename nlmsg_msg_size() to nlmsg_size(), nlmsg_len() -> nlmsg_datalen()
The old symbols are left around for compatibility.
2010-11-22 13:13:04 +01:00
Thomas Graf 5a08c8ff4c Inherit return code of NL_CB_MSG_OUT in nl_sendmsg()
If NL_CB_MSG_OUT() returns anything != NL_OK, return that value
to let any caller of nl_sendmsg() know that the message has not
been sent.
2010-11-18 14:16:33 +01:00
Thomas Graf 8a365dbd49 rename nl_send_auto_complete() -> nl_send_auto(), nl_auto_complete -> nl_complete_msg()
Old symbols left to maintain backwards compatibility
2010-11-18 14:13:49 +01:00
Thomas Graf 063a2ebf53 only perform automatic sequence checking if auto-ack mode is enabled 2010-11-18 12:51:20 +01:00
dima 2dbc1ca76c Generic Netlink multicast groups support
I have a patch against commit d378220c96
extending libnl with a facility to receive generic netlink messages sent
to multicast groups.

Essentially it add one new function genl_ctrl_resolve_grp which
prototype looks like this
int genl_ctrl_resolve_grp(struct nl_sock *sk, const char *family_name,
        const char *grp_name)
It resolves  the family name and the group name to group id. Then
the returned id can be used in nl_socket_add_membership to subscribe
to multicast messages.

Besides that it adds two more functions

uint32_t nl_socket_get_peer_groups(struct nl_sock *sk)
void nl_socket_set_peer_groups(struct nl_sock *sk, uint32_t groups)

allowing to modify the socket peer groups field. So it's possible to
multicast messages from the user space using the legacy interface.
Looks like there is no way (or I was not able to find one?) to modify
the netlink socket destination group from the user space, when the
group id is greater then 32.
2010-10-14 13:46:02 +02:00
Thomas Graf 256d7e723c Fix compile warning in nl.c 2010-07-03 15:15:12 +02:00
Karl Hiramoto 27c505eb89 new feature nl_send_iovec(), nl_auto_complete() and code refactoring.
Create new function nl_send_iovec() to be used to send multiple 'struct iovec'
through the netlink socket.  This will be used for NF_QUEUE, to send
packet payload of a modified packet.

Refactor nl_send() to use nl_send_iovec() sending a single struct iovec.

Create new function nl_auto_complete() by refactoring nl_send_auto_complete(),
so other functions that call nl_send may also use nl_auto_complete()

Signed-off-by: Karl Hiramoto <karl@hiramoto.org>
2010-03-10 16:01:46 +01:00
Thomas Graf 664e1deaeb Fix up naming changes 2008-12-10 18:16:31 +01:00
Thomas Graf 6782b6f709 restructure module documentation order
split hiearchy into one top level module per library
2008-12-10 18:12:30 +01:00
Thomas Graf 4fd5f7cb66 Documentation update 2008-12-03 19:58:41 +01:00
Thomas Graf 2bdee95a76 Add socket flag NL_NO_AUTO_ACK to allow disabling auto ACKS 2008-10-20 13:02:38 +02:00
Thomas Graf 23ee46ef71 Replace NL_KEEP code with proper message reference counting
Adds reference counting to netlink messages so callbacks
can hold on to a message without using the broken keep
message flag.
2008-10-14 19:26:44 +02:00
Thomas Graf 1155370f52 Rename struct nl_handle to struct nl_sock
The idea of a common handle is long revised and only misleading,
nl_handle really represents a socket with some additional
action handlers assigned to it.

Alias for nl_handle is kept for backwards compatibility.
2008-05-15 13:26:32 +02:00
Thomas Graf 8a3efffa5b Thread-safe error handling
In order for the interface to become more thread safe, the error
handling was revised to no longer depend on a static errno and
error string buffer.

This patch converts all error paths to return a libnl specific
error code which can be translated to a error message using
nl_geterror(int error). The functions nl_error() and
nl_get_errno() are therefore obsolete.

This change required various sets of function prototypes to be
changed in order to return an error code, the most prominent
are:

    struct nl_cache *foo_alloc_cache(...);
changed to:
    int foo_alloc_cache(..., struct nl_cache **);

    struct nl_msg *foo_build_request(...);
changed to:
    int foo_build_request(..., struct nl_msg **);

    struct foo *foo_parse(...);
changed to:
    int foo_parse(..., struct foo **);

This pretty much only leaves trivial allocation functions to
still return a pointer object which can still return NULL to
signal out of memory.

This change is a serious API and ABI breaker, sorry!
2008-05-14 17:49:44 +02:00
Thomas Graf b7c5bf98c4 Improve performance by using malloc() over calloc() in critical places
As pointed out by Regis Hanna, a considerable performance gain can be
achieved by using malloc() over calloc() when allocating netlink message
buffers. This is likely due to the fact that we use a complete page for
each message.
2008-05-07 13:18:30 +02:00