[PATCH v2] Add AF_BRIDGE support to link cache

roopa at cumulusnetworks.com roopa at cumulusnetworks.com
Wed Nov 14 09:06:41 EST 2012


From: roopa <roopa at cumulusnetworks.com>

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 at cumulusnetworks.com>
Reviewed-by: Nolan Leake <nolan at cumulusnetworks.com>
Reviewed-by: Shrijeet Mukherjee <shm at cumulusnetworks.com>
Reviewed-by: Wilson Kok <wkok at cumulusnetworks.com>
---
 lib/route/link.c |   28 +++++++++-------------------
 1 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/lib/route/link.c b/lib/route/link.c
index f8646d1..b378f30 100644
--- a/lib/route/link.c
+++ b/lib/route/link.c
@@ -571,19 +571,6 @@ errout:
 	return err;
 }
 
-static int link_event_filter(struct nl_cache *cache, struct nl_object *obj)
-{
-	struct rtnl_link *link = (struct rtnl_link *) obj;
-
-	/*
-	 * Ignore bridging messages when keeping the cache manager up to date.
-	 */
-	if (link->l_family == AF_BRIDGE)
-		return NL_SKIP;
-
-	return NL_OK;
-}
-
 static int link_request_update(struct nl_cache *cache, struct nl_sock *sk)
 {
 	int family = cache->c_iarg1;
@@ -808,15 +795,17 @@ static void link_keygen(struct nl_object *obj, uint32_t *hashkey,
 	unsigned int lkey_sz;
 	struct link_hash_key {
 		uint32_t	l_index;
+		uint32_t	l_family;
 	} __attribute__((packed)) lkey;
 
 	lkey_sz = sizeof(lkey);
 	lkey.l_index = link->l_index;
+	lkey.l_family = link->l_family;
 
 	*hashkey = nl_hash(&lkey, lkey_sz, 0) % table_sz;
 
-	NL_DBG(5, "link %p key (dev %d) keysz %d, hash 0x%x\n",
-	       link, lkey.l_index, lkey_sz, *hashkey);
+	NL_DBG(5, "link %p key (dev %d fam %d) keysz %d, hash 0x%x\n",
+	       link, lkey.l_index, lkey.l_family, lkey_sz, *hashkey);
 
 	return;
 }
@@ -966,7 +955,7 @@ struct rtnl_link *rtnl_link_get(struct nl_cache *cache, int ifindex)
 		return NULL;
 
 	nl_list_for_each_entry(link, &cache->c_items, ce_list) {
-		if (link->l_index == ifindex) {
+		if (link->l_family == AF_UNSPEC && link->l_index == ifindex) {
 			nl_object_get((struct nl_object *) link);
 			return link;
 		}
@@ -999,7 +988,8 @@ struct rtnl_link *rtnl_link_get_by_name(struct nl_cache *cache,
 		return NULL;
 
 	nl_list_for_each_entry(link, &cache->c_items, ce_list) {
-		if (!strcmp(name, link->l_name)) {
+		if (link->l_family == AF_UNSPEC &&
+			!strcmp(name, link->l_name)) {
 			nl_object_get((struct nl_object *) link);
 			return link;
 		}
@@ -2524,11 +2514,12 @@ static struct nl_object_ops link_obj_ops = {
 	.oo_compare		= link_compare,
 	.oo_keygen		= link_keygen,
 	.oo_attrs2str		= link_attrs2str,
-	.oo_id_attrs		= LINK_ATTR_IFINDEX,
+	.oo_id_attrs		= LINK_ATTR_IFINDEX | LINK_ATTR_FAMILY,
 };
 
 static struct nl_af_group link_groups[] = {
 	{ AF_UNSPEC,	RTNLGRP_LINK },
+	{ AF_BRIDGE,    RTNLGRP_LINK },
 	{ END_OF_GROUP_LIST },
 };
 
@@ -2546,7 +2537,6 @@ static struct nl_cache_ops rtnl_link_ops = {
 	.co_groups		= link_groups,
 	.co_request_update	= link_request_update,
 	.co_msg_parser		= link_msg_parser,
-	.co_event_filter	= link_event_filter,
 	.co_obj_ops		= &link_obj_ops,
 };
 
-- 
1.7.2.5




More information about the libnl mailing list