diff options
author | David Ahern <dsa@cumulusnetworks.com> | 2015-10-27 22:40:48 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-11-19 15:48:21 (GMT) |
commit | 18d60cb9d72f61f2070f3758bcd347bb2e3747c1 (patch) | |
tree | 56b5794a49531dc4ebaa6d1511196ba8e3b8a95d /lib | |
parent | 7ea15f60a726de67f02e6868a8125a59570e956d (diff) | |
download | libnl-18d60cb9d72f61f2070f3758bcd347bb2e3747c1.zip libnl-18d60cb9d72f61f2070f3758bcd347bb2e3747c1.tar.gz libnl-18d60cb9d72f61f2070f3758bcd347bb2e3747c1.tar.bz2 |
link/neigh: add flags option to link and neighbor caches
Both link and neighbor cache support specify multiple groups (nl_af_group),
but the alloc_cache functions for both do not set the NL_CACHE_AF_ITER
flag before populating the cache so only the first group is used by
default. This patch adds an API to pass in flags to make that happen
and updates the nl-neigh-list command to make use of it.
http://lists.infradead.org/pipermail/libnl/2015-October/001996.html
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/route/link.c | 39 | ||||
-rw-r--r-- | lib/route/neigh.c | 32 |
2 files changed, 69 insertions, 2 deletions
diff --git a/lib/route/link.c b/lib/route/link.c index 5c32550..6dc416b 100644 --- a/lib/route/link.c +++ b/lib/route/link.c @@ -1008,6 +1008,7 @@ static char *link_attrs2str(int attrs, char *buf, size_t len) * @arg sk Netlink socket. * @arg family Link address family or AF_UNSPEC * @arg result Pointer to store resulting cache. + * @arg flags Flags to set in link cache before filling * * Allocates and initializes a new link cache. If \c sk is valid, a netlink * message is sent to the kernel requesting a full dump of all configured @@ -1027,7 +1028,8 @@ static char *link_attrs2str(int attrs, char *buf, size_t len) * @see rtnl_link_get_by_name() * @return 0 on success or a negative error code. */ -int rtnl_link_alloc_cache(struct nl_sock *sk, int family, struct nl_cache **result) +int rtnl_link_alloc_cache_flags(struct nl_sock *sk, int family, + struct nl_cache **result, unsigned int flags) { struct nl_cache * cache; int err; @@ -1037,7 +1039,10 @@ int rtnl_link_alloc_cache(struct nl_sock *sk, int family, struct nl_cache **resu return -NLE_NOMEM; cache->c_iarg1 = family; - + + if (flags) + nl_cache_set_flags(cache, flags); + if (sk && (err = nl_cache_refill(sk, cache)) < 0) { nl_cache_free(cache); return err; @@ -1048,6 +1053,36 @@ int rtnl_link_alloc_cache(struct nl_sock *sk, int family, struct nl_cache **resu } /** + * Allocate link cache and fill in all configured links. + * @arg sk Netlink socket. + * @arg family Link address family or AF_UNSPEC + * @arg result Pointer to store resulting cache. + * + * Allocates and initializes a new link cache. If \c sk is valid, a netlink + * message is sent to the kernel requesting a full dump of all configured + * links. The returned messages are parsed and filled into the cache. If + * the operation succeeds, the resulting cache will contain a link object for + * each link configured in the kernel. If \c sk is NULL, returns 0 but the + * cache is still empty. + * + * If \c family is set to an address family other than \c AF_UNSPEC the + * contents of the cache can be limited to a specific address family. + * Currently the following address families are supported: + * - AF_BRIDGE + * - AF_INET6 + * + * @route_doc{link_list, Get List of Links} + * @see rtnl_link_get() + * @see rtnl_link_get_by_name() + * @return 0 on success or a negative error code. + */ +int rtnl_link_alloc_cache(struct nl_sock *sk, int family, struct nl_cache **result) +{ + return rtnl_link_alloc_cache_flags(sk, family, result, 0); +} + + +/** * Lookup link in cache by interface index * @arg cache Link cache * @arg ifindex Interface index diff --git a/lib/route/neigh.c b/lib/route/neigh.c index ab07ec9..6059e7f 100644 --- a/lib/route/neigh.c +++ b/lib/route/neigh.c @@ -546,6 +546,38 @@ int rtnl_neigh_alloc_cache(struct nl_sock *sock, struct nl_cache **result) } /** + * Build a neighbour cache including all neighbours currently configured in the kernel. + * @arg sock Netlink socket. + * @arg result Pointer to store resulting cache. + * @arg flags Flags to apply to cache before filling + * + * Allocates a new neighbour cache, initializes it properly and updates it + * to include all neighbours currently configured in the kernel. + * + * @return 0 on success or a negative error code. + */ +int rtnl_neigh_alloc_cache_flags(struct nl_sock *sock, struct nl_cache **result, + unsigned int flags) +{ + struct nl_cache * cache; + int err; + + cache = nl_cache_alloc(&rtnl_neigh_ops); + if (!cache) + return -NLE_NOMEM; + + nl_cache_set_flags(cache, flags); + + if (sock && (err = nl_cache_refill(sock, cache)) < 0) { + nl_cache_free(cache); + return err; + } + + *result = cache; + return 0; +} + +/** * Look up a neighbour by interface index and destination address * @arg cache neighbour cache * @arg ifindex interface index the neighbour is on |