extern "C" {
#endif
+/* flags */
+#define ROUTE_CACHE_CONTENT 1
+
struct rtnl_route;
struct rtnl_rtcacheinfo
/* General */
extern struct rtnl_route * rtnl_route_alloc(void);
extern void rtnl_route_put(struct rtnl_route *);
-extern struct nl_cache * rtnl_route_alloc_cache(struct nl_handle *);
+extern struct nl_cache * rtnl_route_alloc_cache(struct nl_handle *,
+ int, int);
extern void rtnl_route_get(struct rtnl_route *);
extern void rtnl_route_put(struct rtnl_route *);
static int route_request_update(struct nl_cache *c, struct nl_handle *h)
{
- return nl_rtgen_request(h, RTM_GETROUTE, AF_UNSPEC, NLM_F_DUMP);
+ struct rtmsg rhdr = {
+ .rtm_family = c->c_iarg1,
+ };
+
+ if (c->c_iarg2 & ROUTE_CACHE_CONTENT)
+ rhdr.rtm_flags |= RTM_F_CLONED;
+
+ return nl_send_simple(h, RTM_GETROUTE, NLM_F_DUMP, &rhdr, sizeof(rhdr));
}
/**
/**
* Build a route cache holding all routes currently configured in the kernel
* @arg handle netlink handle
+ * @arg family Address family of routes to cover or AF_UNSPEC
+ * @arg flags Flags
*
* Allocates a new cache, initializes it properly and updates it to
* contain all routes currently configured in the kernel.
* cache after using it.
* @return The cache or NULL if an error has occured.
*/
-struct nl_cache *rtnl_route_alloc_cache(struct nl_handle *handle)
+struct nl_cache *rtnl_route_alloc_cache(struct nl_handle *handle,
+ int family, int flags)
{
struct nl_cache *cache;
if (!cache)
return NULL;
+ cache->c_iarg1 = family;
+ cache->c_iarg2 = flags;
+
if (handle && nl_cache_refill(handle, cache) < 0) {
free(cache);
return NULL;
nlh = nltool_alloc_handle();
nltool_connect(nlh, NETLINK_ROUTE);
link_cache = nltool_alloc_link_cache(nlh);
- route_cache = nltool_alloc_route_cache(nlh);
+ route_cache = nltool_alloc_route_cache(nlh, 0);
route = rtnl_route_alloc();
if (!route)
nlh = nltool_alloc_handle();
nltool_connect(nlh, NETLINK_ROUTE);
link_cache = nltool_alloc_link_cache(nlh);
- route_cache = nltool_alloc_route_cache(nlh);
+ route_cache = nltool_alloc_route_cache(nlh, 0);
route = rtnl_route_alloc();
if (!route)
"Usage: nl-route-list [OPTION]... [ROUTE]\n"
"\n"
"Options\n"
+ " -c, --cache List the contents of the route cache\n"
" -f, --format=TYPE Output format { brief | details | stats }\n"
" -h, --help Show this help\n"
" -v, --version Show versioning information\n"
.dp_fd = stdout,
.dp_type = NL_DUMP_BRIEF
};
- int err = 1;
+ int err = 1, print_cache = 0;
nlh = nltool_alloc_handle();
nltool_connect(nlh, NETLINK_ROUTE);
link_cache = nltool_alloc_link_cache(nlh);
- route_cache = nltool_alloc_route_cache(nlh);
route = rtnl_route_alloc();
if (!route)
ARG_TYPE,
};
static struct option long_opts[] = {
+ { "cache", 0, 0, 'c' },
{ "format", 1, 0, 'f' },
{ "help", 0, 0, 'h' },
{ "version", 0, 0, 'v' },
{ 0, 0, 0, 0 }
};
- c = getopt_long(argc, argv, "f:hvd:n:t:", long_opts, &optidx);
+ c = getopt_long(argc, argv, "cf:hvd:n:t:", long_opts, &optidx);
if (c == -1)
break;
switch (c) {
+ case 'c': print_cache = 1; break;
case 'f': params.dp_type = nltool_parse_dumptype(optarg); break;
case 'h': print_usage(); break;
case 'v': print_version(); break;
}
}
+ route_cache = nltool_alloc_route_cache(nlh,
+ print_cache ? ROUTE_CACHE_CONTENT : 0);
+
nl_cache_dump_filter(route_cache, ¶ms, OBJ_CAST(route));
err = 0;
rtnl_route_put(route);
-errout:
nl_cache_free(route_cache);
+errout:
nl_cache_free(link_cache);
nl_close(nlh);
nl_handle_destroy(nlh);
return cache;
}
-struct nl_cache *nltool_alloc_route_cache(struct nl_handle *nlh)
+struct nl_cache *nltool_alloc_route_cache(struct nl_handle *nlh, int flags)
{
struct nl_cache *cache;
- cache = rtnl_route_alloc_cache(nlh);
+ cache = rtnl_route_alloc_cache(nlh, AF_UNSPEC, flags);
if (!cache)
fatal(nl_get_errno(), "Unable to retrieve route cache: %s\n",
nl_geterror());
extern struct nl_cache *nltool_alloc_addr_cache(struct nl_handle *nlh);
extern struct nl_cache *nltool_alloc_neigh_cache(struct nl_handle *nlh);
extern struct nl_cache *nltool_alloc_neightbl_cache(struct nl_handle *nlh);
-extern struct nl_cache *nltool_alloc_route_cache(struct nl_handle *nlh);
+extern struct nl_cache *nltool_alloc_route_cache(struct nl_handle *nlh, int);
extern struct nl_cache *nltool_alloc_rule_cache(struct nl_handle *nlh);
extern struct nl_cache *nltool_alloc_qdisc_cache(struct nl_handle *nlh);
extern struct nl_cache *nltool_alloc_genl_family_cache(struct nl_handle *nlh);