[PATCH 2/2] neigh cache: Add new neigh api to get neigh object by family
roopa at cumulusnetworks.com
roopa at cumulusnetworks.com
Wed Dec 12 17:10:51 EST 2012
From: roopa <roopa at cumulusnetworks.com>
This patch adds the following new api to get neigh objects by family:
struct rtnl_neigh * rtnl_neigh_get_by_family(struct nl_cache *cache,
int family, int ifindex,
struct nl_addr *addr)
And two new api's to get and set the master index for AF_BRIDGE
family neigh objects:
void rtnl_neigh_set_master_ifindex(struct rtnl_neigh *neigh,
int ifindex);
int rtnl_neigh_get_master_ifindex(struct rtnl_neigh *neigh);
Signed-off-by: Roopa Prabhu <roopa at cumulusnetworks.com>
---
include/netlink/route/neighbour.h | 6 ++++
lib/route/neigh.c | 61 +++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/include/netlink/route/neighbour.h b/include/netlink/route/neighbour.h
index 1d1179b..bef3b06 100644
--- a/include/netlink/route/neighbour.h
+++ b/include/netlink/route/neighbour.h
@@ -28,6 +28,8 @@ extern void rtnl_neigh_put(struct rtnl_neigh *);
extern int rtnl_neigh_alloc_cache(struct nl_sock *, struct nl_cache **);
extern struct rtnl_neigh *rtnl_neigh_get(struct nl_cache *, int,
struct nl_addr *);
+extern struct rtnl_neigh * rtnl_neigh_get_by_family(struct nl_cache *,
+ int, int, struct nl_addr *);
extern int rtnl_neigh_parse(struct nlmsghdr *, struct rtnl_neigh **);
@@ -60,6 +62,10 @@ extern void rtnl_neigh_set_ifindex(struct rtnl_neigh *,
int);
extern int rtnl_neigh_get_ifindex(struct rtnl_neigh *);
+extern void rtnl_neigh_set_master_ifindex(struct rtnl_neigh *,
+ int);
+extern int rtnl_neigh_get_master_ifindex(struct rtnl_neigh *);
+
extern void rtnl_neigh_set_lladdr(struct rtnl_neigh *,
struct nl_addr *);
extern struct nl_addr * rtnl_neigh_get_lladdr(struct rtnl_neigh *);
diff --git a/lib/route/neigh.c b/lib/route/neigh.c
index 4a85a85..8d3b38b 100644
--- a/lib/route/neigh.c
+++ b/lib/route/neigh.c
@@ -551,6 +551,52 @@ struct rtnl_neigh * rtnl_neigh_get(struct nl_cache *cache, int ifindex,
return NULL;
}
+/**
+ * Look up a neighbour by family, interface index and destination address
+ * @arg cache neighbour cache
+ * @arg ifindex interface index the neighbour is on. This is the
+ * bridge ifindex when family is AF_BRIDGE
+ * @arg addr destination address of the neighbour. bridge fdb mac
+ * when family is AF_BRIDGE
+ * @return neighbour handle or NULL if no match was found.
+ */
+struct rtnl_neigh * rtnl_neigh_get_by_family(struct nl_cache *cache,
+ int family, int ifindex,
+ struct nl_addr *addr)
+{
+ struct rtnl_neigh *neigh = NULL, *neigh_needle;
+
+ if (cache->c_ops != &rtnl_neigh_ops)
+ return NULL;
+
+ neigh_needle = rtnl_neigh_alloc();
+ if (!neigh_needle)
+ return NULL;
+
+ rtnl_neigh_set_family(neigh_needle, family);
+
+ switch(family) {
+ case AF_UNSPEC:
+ rtnl_neigh_set_ifindex(neigh_needle, ifindex);
+ rtnl_neigh_set_dst(neigh_needle, addr);
+ break;
+ case AF_BRIDGE:
+ rtnl_neigh_set_master_ifindex(neigh_needle, ifindex);
+ rtnl_neigh_set_lladdr(neigh_needle, addr);
+ break;
+ default:
+ goto errout;
+ }
+
+ neigh = (struct rtnl_neigh *)nl_cache_search(cache,
+ OBJ_CAST(neigh_needle));
+
+errout:
+ rtnl_neigh_put(neigh_needle);
+
+ return neigh;
+}
+
/** @} */
/**
@@ -830,6 +876,21 @@ int rtnl_neigh_get_ifindex(struct rtnl_neigh *neigh)
return neigh->n_ifindex;
}
+void rtnl_neigh_set_master_ifindex(struct rtnl_neigh *neigh,
+ int ifindex)
+{
+ neigh->n_master = ifindex;
+ neigh->ce_mask |= NEIGH_ATTR_MASTER;
+}
+
+int rtnl_neigh_get_master_ifindex(struct rtnl_neigh *neigh)
+{
+ if (neigh->ce_mask & NEIGH_ATTR_LLADDR)
+ return neigh->n_master;
+ else
+ return -1;
+}
+
static inline int __assign_addr(struct rtnl_neigh *neigh, struct nl_addr **pos,
struct nl_addr *new, int flag, int nocheck)
{
--
1.7.2.5
More information about the libnl
mailing list