Thomas Graf [Mon, 26 Nov 2012 10:50:56 +0000 (11:50 +0100)]
cache: only continue iterating over co_groups if it is available
A co_groups == NULL must enter the loop to trigger the initial
fill of the cache but may never bump the grp pointer as doing
so prevents the loop from being escaped correctly.
roopa [Mon, 19 Nov 2012 06:14:23 +0000 (22:14 -0800)]
Bug Fix: Add new fill socket to cache manager
This patch adds a new socket to cache manager to request fill's on.
cache manager today uses cm_sock to request dump from
the kernel. It also listens to netlink async events on the same sock.
The problem with this is that when libnl is waiting to process the
response to get dump request sent to the kernel during fill,
it may receive an async event, resulting in libnl complaining about
unexpected msg
This is usually reproducible when there is heavy netlink async event
traffic during nl_cache_mngr_add.
This patch adds a new cm_sync_sock to use for fill during cache manager
add cache.
The other option is to provide an api to set the cm_sync_sock. But since
this is a bug fix its probably better to fix the cache manager add api
like this patch does. Please suggest otherwise.
Thomas Graf [Fri, 16 Nov 2012 00:11:55 +0000 (01:11 +0100)]
cache: provide safe variant of nl_cache_mngt_require() and use it
This makes runtime removal of cache operations possible if non-safe
API is not in use by application. The non-safe API will be removed
in the next major version.
roopa [Wed, 14 Nov 2012 19:33:51 +0000 (11:33 -0800)]
Add master support to rtnl_neigh for AF_BRIDGE objects
AF_BRIDGE neigh objects can be uniquely identified by
the family, lladdr and bridge ifindex. This patch adds
bridge ifindex to AF_BRIDGE neigh objects.
Things will be ok even without this patch with just family and
lladdr if we assume that we will have unique lladdr's
accross bridges in a system.
Kernel does not send the bridge ifindex in the AF_BRIDGE
fdb/neigh message. This patch tries to get that info by a
link cache lookup and adds it to the bridge neigh object
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com> Reviewed-by: Nolan Leake <nolan@cumulusnetworks.com> Reviewed-by: Shrijeet Mukherjee <shm@cumulusnetworks.com> Reviewed-by: Wilson Kok <wkok@cumulusnetworks.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
roopa [Wed, 14 Nov 2012 19:33:50 +0000 (11:33 -0800)]
Add AF_BRIDGE support to neigh cache
This patch adds AF_BRIDGE to the list of families
supported by the cache. Implements oo_id_attrs_get to
declare separate id attributes for AF_UNSPEC and AF_BRIDGE
neigh objects
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com> Reviewed-by: Nolan Leake <nolan@cumulusnetworks.com> Reviewed-by: Shrijeet Mukherjee <shm@cumulusnetworks.com> Reviewed-by: Wilson Kok <wkok@cumulusnetworks.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
roopa [Wed, 14 Nov 2012 14:06:41 +0000 (06:06 -0800)]
Add AF_BRIDGE support to link cache
This patch was previously submitted as the first approach in
RFC http://lists.infradead.org/pipermail/libnl/2012-November/000730.html
It adds support for AF_BRIDGE family in link cache.
And the key for link object lookups will now be ifindex and family.
This allows for AF_UNSPEC rtnl link objects to co-exist with the AF_BRIDGE
link objects in the same cache.
I have changed some of the rtnl_link api's to explicitly check for
AF_UNSPEC to not break existing apps. I will submit a new patch to
introduce equivalent rtnl_bridge_link_* api's.
We had also discussed updating the existing link objects with
AF_BRIDGE attributes, but realized that the updates to link objects will
be both AF_UNSPEC and AF_BRIDGE. And that would change link cache to always
update existing objects, resulting in comparing and updating close to
thirty attributes at cache_include time which seems like a overkill.
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com> Reviewed-by: Nolan Leake <nolan@cumulusnetworks.com> Reviewed-by: Shrijeet Mukherjee <shm@cumulusnetworks.com> Reviewed-by: Wilson Kok <wkok@cumulusnetworks.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
roopa [Mon, 12 Nov 2012 20:38:33 +0000 (12:38 -0800)]
Add NL_CACHE_AF_ITER support during refill and resync
This patch adds support to iter over all supported families
during cache fill and resync.
The motivation for this was previously introduced at
http://lists.infradead.org/pipermail/libnl/2012-November/000734.html
In short, this patch allows caches to request dump on all supported
families instead of only AF_UNSPEC as done today.
With feedback from thomas this patch makes the iter over all families
conditional on per cache flag NL_CACHE_AF_ITER
roopa [Mon, 12 Nov 2012 20:38:32 +0000 (12:38 -0800)]
New cache manager add cache api
This patch is an attempt to add a new nl_cache_mngr_add_cache api
to allow adding an existing cache to cache manager.
Since the new api is similar to nl_cache_mngr_add
except for allocating the cache, the patch moves most of the
nl_cache_mngr_add code to nl_cache_mngr_add_cache and changes
nl_cache_mngr_add to call nl_cache_mngr_add_cache.
One use case for this api as pointed out by thomas would be to set cache
flags before associating the cache with a cache manager.
roopa [Fri, 9 Nov 2012 22:41:31 +0000 (14:41 -0800)]
Add hash function
This patch adds a hash function for hashing libnl objects.
This hash function is from:
http://ccodearchive.net/info/hash.html
The original code was modified to remove unwanted dependencies,
unwanted code and fixes to header file locations
One requirement with this hash function is, hashing over multiple fields of an
un-packed struct requires that the struct be zeroed, otherwise random padding
bytes will change the hash.
Signed-off-by: Shrijeet Mukherjee <shm@cumulusnetworks.com> Signed-off-by: Nolan Leake <nolan@cumulusnetworks.com> Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com> Reviewed-by: Wilson Kok <wkok@cumulusnetworks.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
roopa [Thu, 1 Nov 2012 21:13:30 +0000 (14:13 -0700)]
Add support for updating objects in the cache
This patch adds support to update a cache object during cache_include instead
of the current approach of deleting the original object and adding a new one.
This operation is conditional on the object implementing the operation. If
the update is not successful, cache_include falls back to the existing cache
inclusion process of deleting and adding the object.
It adds a new object operation called oo_update. oo_update takes two objects
as arguments, first being the existing cache object that needs update, the
second argument being the new object. Currently it is left to the implementor
to use the msg type to decide wether to delete or add the new object attributes
to the old one. But the operation type or msg type can be easily made part of the
object arguments.
The motivation for this change is explained below in the context of including
support for AF_BRIDGE objects into the link cache.
libnl today deletes an object before it includes an identical object.
But for some objects like the AF_BRIDGE objects this does not work well.
link cache uses the ifindex as its key in object searches.
If link cache were to support AF_BRIDGE family objects, todays implementation,
- will replace the original link object with the bridge port link object
for add notifications
- And a bridge port delete notification from kernel would delete the
link object from the cache leaving the cache without the link object
until the kernel sends another notification for that link
The bridge port link notification contains some base link object attributes
plus bridge specific protocol info attributes. In such cases we think an
operation to update the existing object in place in cache might be useful.
This can be made to work for AF_INET6 link objects too.
roopa [Thu, 1 Nov 2012 14:15:28 +0000 (07:15 -0700)]
Add new object op oo_id_attrs_get
The current oo_id_attrs nl_object op allows a fixed
id attribute list for an cache. But a cache with multiple families
may need to specify different id attributes for different families.
An example for this is the bridge fdb entries in the neigh cache:
neigh entries belonging to the AF_UNSPEC family use
(NEIGH_ATTR_IFINDEX | NEIGH_ATTR_DST | NEIGH_ATTR_FAMILY) as id attributes.
AF_BRIDGE fdb entries which also support the same msg type, will need to use
(NEIGH_ATTR_LLADDR | NEIGH_ATTR_FAMILY) as id attributes.
Today you cannot specify different set of attributes to two families belonging
to the same cache.
This patch adds a new object function oo_id_attrs_get to get the attributes.
An example implementation of oo_id_attrs_get for the neigh cache will
look like:
static uint32_t neigh_id_attrs_get(struct nl_object *obj)
{
struct rtnl_neigh *neigh = (struct rtnl_neigh *)obj;
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.
genl/family flags can be damaged during the auto-indentation.
"-" was never used in the names of the flags. "_" was used in all places
of the library. So, I just changed the undescore to the minus.
Automatic indentation can insert spaces on either side of the minus,
so the library will be compiled, but will not be usable (in this part of the code),
as the parser will split words by white space, and the flag "admin - perm"
will never work.