Thomas Graf [Thu, 15 May 2008 11:26:32 +0000 (13:26 +0200)]
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.
Thomas Graf [Wed, 14 May 2008 15:49:44 +0000 (17:49 +0200)]
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!
Ben Gamsa [Thu, 8 May 2008 15:42:09 +0000 (11:42 -0400)]
Added two new functions to facilitate processing the nexthop entries for routes.
Added rtnl_route_foreach_nexthop() to walk the list of nexthops invoking a
caller-provided callback for each nexthop entry, and added rtnl_route_nexthop_n()
to retrieve the Nth nexthop entry in the list.
Thomas Graf [Thu, 8 May 2008 10:47:26 +0000 (12:47 +0200)]
Speed up metrics comparison
Using rtnl_route_get_metric() for route comparison became a bottleneck
because each metric which was not available resulted in the generation
of an error message. This changeset avoids this by accessing rt_metrics
and rt_metrics_mask directly while comparing route objects.
Thomas Graf [Wed, 7 May 2008 11:18:30 +0000 (13:18 +0200)]
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.
Thomas Graf [Mon, 5 May 2008 15:09:25 +0000 (17:09 +0200)]
Route cache support
This changesets adds the possibility to fill a nl_cache with
the contents of the route cache. It also adds the possibility
to limit route caches to certain address families.
Tad Kollar [Wed, 30 Apr 2008 15:40:44 +0000 (11:40 -0400)]
New netem funtionality and TBF fix
New netem-related functionality:
Added ability to save new settings to the kernel. In netem.c, the
netem_get_opts() stub has been replaced with netem_build_msg() which
manipulates the nl_msg data directly and returns an error code instead
of a new nl_msg. Modifications to qdisc_build() in qdisc.c and struct
rtnl_qdisc_ops were necessary for this.
Added support for getting/setting corruption probability/correlation.
Added support for setting a delay distribution.
Fixed tbf_msg_parser() to call tbf_alloc() instead of tbf_qdisc() to
prevent a seg fault.
libnl: recvmsgs doesn't necessarily free the message data
I stepped over libnl always freeing the messages and it
kind of made it awkward to reuse the message data without
reallocating.
The basic idea is: if a callback return value has a bit set,
don't free that message. The calling application owns it.
By default, things stay as before (messages are freed).
Thomas Graf [Tue, 29 Apr 2008 21:31:30 +0000 (23:31 +0200)]
Big routing code rework (API/ABI BREAK!)
Adds all missing routing attributes and brings the routing
related code to a working state. In the process the API
was broken several times with the justification that nobody
is using this code yet.
The changes include new example code which is also a prototype
for how plain CLI tools could look like to control routes.
Patrick McHardy [Fri, 18 Jan 2008 16:55:57 +0000 (17:55 +0100)]
[LIBNL]: Split up nfnetlink_log into log and msg objects
Split the nfnetlink_log code into two seperate objects, "netfilter/log"
to represent logging instances and "netfilter/log_msg" to represent
log messages. Also perform some function name unification for consistency
with other libnl object types, mainly renaming nfnl_log_build_*_msg
to nfnl_log_build_*_request.
This changes the API in an incompatible way, but since this feature is
new and the libnl netfilter headers haven't been installed so far,
there shouldn't be any users affected by this.
Thomas Graf [Tue, 5 Feb 2008 11:35:41 +0000 (12:35 +0100)]
Free associated caches when freeing cache manager
Caches allocated by the cache manager must be freed again when the cache
manager itself is freed. However, the netlink socket is allocated
indepdently so it should not be freed.
Thomas Graf [Mon, 14 Jan 2008 15:17:56 +0000 (16:17 +0100)]
Fix stale data pointers when constructing messages
Patrick McHardy reported a problem where pointers to the
payload of a netlink message as returned by f.e. the
nesting helpers become stale when the payload data
chunk is reallocated.
In order to avoid further problems, the payload chunk is
no longer extended on the fly. Instead the allocation is
made during netlink message object allocation time with
a default size of a page which should be fine for the
majority of all users. Additionally the functions
nlmsg_alloc_size() and nlmsg_set_default_size() have been
added to allocate messages of a particular length and to
modify the default message size.
Thomas Graf [Wed, 19 Dec 2007 18:41:01 +0000 (19:41 +0100)]
Represent default route with destination address length zero
So far the destination address for default routes was NULL
which complicated the handling of routes in general. By
assigning a address of length zero they can be compared
to each other.
This allows the cache manager to properly handle default
routes.
Thomas Graf [Mon, 17 Dec 2007 15:26:49 +0000 (16:26 +0100)]
Fix creation and destruction of sockets
Fixes an off-by-one when releasing local ports. Fixes nl_connect()
to properly close the socket upon failure. Return EBADFD if
operations are performed on unconnected sockets where appropriate.
Makes nl_handle_alloc() return an error if all local ports are
used up.
Patrick McHardy [Thu, 13 Dec 2007 13:33:37 +0000 (14:33 +0100)]
[LIBNL]: Fix pointer conversion warnings on 64 bit
nl-tctree-dump.c: In function 'print_class':
nl-tctree-dump.c:31: warning: cast from pointer to integer of different size
nl-tctree-dump.c:44: warning: cast from pointer to integer of different size
nl-tctree-dump.c: In function 'print_qdisc':
nl-tctree-dump.c:55: warning: cast from pointer to integer of different size
nl-tctree-dump.c:64: warning: cast from pointer to integer of different size