]> granicus.if.org Git - libnl/commitdiff
Add new object op oo_id_attrs_get
authorroopa <roopa@cumulusnetworks.com>
Thu, 1 Nov 2012 14:15:28 +0000 (07:15 -0700)
committerThomas Graf <tgraf@redhat.com>
Mon, 5 Nov 2012 12:31:55 +0000 (13:31 +0100)
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;

        if (neigh->n_family == AF_BRIDGE)
                return (NEIGH_ATTR_LLADDR | NEIGH_ATTR_FAMILY);
        else
                return (NEIGH_ATTR_IFINDEX | NEIGH_ATTR_DST | NEIGH_ATTR_FAMILY);
}

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>
include/netlink/object-api.h
lib/object.c

index 70a4ddd06d42da6ed42620cc107c814723f181aa..cfd5699b6a5ce61edab2eb6e297fcfbc34c6c381 100644 (file)
@@ -337,6 +337,11 @@ struct nl_object_ops
 
 
        char *(*oo_attrs2str)(int, char *, size_t);
+
+       /**
+        * Get key attributes by family function
+        */
+       uint32_t   (*oo_id_attrs_get)(struct nl_object *);
 };
 
 /** @} */
index 055a208e9d258c9c1475213262d3bafef8cba133..585189e9187fe9f56a07aca4f615249c4aa9d910 100644 (file)
@@ -291,7 +291,15 @@ int nl_object_identical(struct nl_object *a, struct nl_object *b)
        if (ops != obj_ops(b))
                return 0;
 
-       req_attrs = ops->oo_id_attrs;
+       if (ops->oo_id_attrs_get) {
+               int req_attrs_a = ops->oo_id_attrs_get(a);
+               int req_attrs_b = ops->oo_id_attrs_get(b);
+               if (req_attrs_a != req_attrs_b)
+                       return 0;
+               req_attrs = req_attrs_a;
+       } else {
+               req_attrs = ops->oo_id_attrs;
+       }
        if (req_attrs == 0xFFFFFFFF)
                req_attrs = a->ce_mask & b->ce_mask;