[PATCH 4/4] link: Add af data compare to link objects

roopa at cumulusnetworks.com roopa at cumulusnetworks.com
Tue Jan 8 08:29:11 EST 2013


From: roopa <roopa at cumulusnetworks.com>

Today the link compare function does not
compare af data of a link. We have found a
need for this to get approriate change callbacks
when af_data of a link changes.

This patch adds support to compare af_data
in link_compare function. This patch today
only adds support to compare af_data set by
PROTINFO attributes. It can be extended to
support compares of af_data set by AF_SPEC
attributes

It has been tested for AF_BRIDGE objects.
In case of AF_BRIDGE objects, this helps with
bridge port change notification callbacks.

Signed-off-by: Wilson Kok <wkok at cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa at cumulusnetworks.com>
---
 lib/route/link.c |   22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/lib/route/link.c b/lib/route/link.c
index 1cecd54..d4fa0a4 100644
--- a/lib/route/link.c
+++ b/lib/route/link.c
@@ -54,6 +54,8 @@
 #define LINK_ATTR_NUM_TX_QUEUES	(1 << 22)
 #define LINK_ATTR_NUM_RX_QUEUES	(1 << 23)
 #define LINK_ATTR_GROUP		(1 << 24)
+#define LINK_ATTR_PROTINFO	(1 << 25)
+#define LINK_ATTR_AF_SPEC	(1 << 26)
 
 static struct nl_cache_ops rtnl_link_ops;
 static struct nl_object_ops link_obj_ops;
@@ -515,6 +517,7 @@ static int link_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
 				}
 			}
 		}
+		link->ce_mask |= LINK_ATTR_LINKINFO;
 	}
 
 	if (tb[IFLA_PROTINFO] && af_ops && af_ops->ao_parse_protinfo) {
@@ -522,6 +525,7 @@ static int link_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
 						link->l_af_data[link->l_family]);
 		if (err < 0)
 			goto errout;
+		link->ce_mask |= LINK_ATTR_PROTINFO;
 	}
 
 	if (tb[IFLA_AF_SPEC]) {
@@ -542,6 +546,7 @@ static int link_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
 			}
 
 		}
+		link->ce_mask |= LINK_ATTR_AF_SPEC;
 	}
 
 	if (tb[IFLA_PROMISCUITY]) {
@@ -839,15 +844,28 @@ static int link_compare(struct nl_object *_a, struct nl_object *_b,
 	diff |= LINK_DIFF(NUM_RX_QUEUES,a->l_num_rx_queues != b->l_num_rx_queues);
 	diff |= LINK_DIFF(GROUP,	a->l_group != b->l_group);
 
+	/*
+	 * Compare LINK_ATTR_PROTINFO af_data
+	 */
+	if (a->l_family == b->l_family) {
+		if (rtnl_link_af_data_compare(a, b, a->l_family, ~0, 0) != 0)
+			goto protinfo_mismatch;
+	}
+
 	if (flags & LOOSE_COMPARISON)
 		diff |= LINK_DIFF(FLAGS,
 				  (a->l_flags ^ b->l_flags) & b->l_flag_mask);
 	else
 		diff |= LINK_DIFF(FLAGS, a->l_flags != b->l_flags);
 
-#undef LINK_DIFF
-
+out:
 	return diff;
+
+protinfo_mismatch:
+	diff |= LINK_DIFF(PROTINFO, 1);
+	goto out;
+
+#undef LINK_DIFF
 }
 
 static const struct trans_tbl link_attrs[] = {
-- 
1.7.10.4




More information about the libnl mailing list