summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas Graf <tgr@lsx.localdomain>2008-05-05 17:09:25 +0200
committerThomas Graf <tgr@lsx.localdomain>2008-05-05 17:09:25 +0200
commit85808860b6174aecc901c34c90968911ad013280 (patch)
tree50b656a80afe3daa422c94ece74552fae74c5b03 /src
parent861901c55bd9e2f84e7c8de0da5ea6179867907d (diff)
downloadandroid_external_libnl-85808860b6174aecc901c34c90968911ad013280.tar.gz
android_external_libnl-85808860b6174aecc901c34c90968911ad013280.tar.bz2
android_external_libnl-85808860b6174aecc901c34c90968911ad013280.zip
Route cache support
This changesets adds the possibility to fill a nl_cache with the contents of the route cache. It also adds the possibility to limit route caches to certain address families.
Diffstat (limited to 'src')
-rw-r--r--src/nl-route-add.c2
-rw-r--r--src/nl-route-delete.c2
-rw-r--r--src/nl-route-list.c13
-rw-r--r--src/utils.c4
-rw-r--r--src/utils.h2
5 files changed, 14 insertions, 9 deletions
diff --git a/src/nl-route-add.c b/src/nl-route-add.c
index 4895747..f411b30 100644
--- a/src/nl-route-add.c
+++ b/src/nl-route-add.c
@@ -66,7 +66,7 @@ int main(int argc, char *argv[])
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)
diff --git a/src/nl-route-delete.c b/src/nl-route-delete.c
index e0e2c1c..78403f6 100644
--- a/src/nl-route-delete.c
+++ b/src/nl-route-delete.c
@@ -103,7 +103,7 @@ int main(int argc, char *argv[])
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)
diff --git a/src/nl-route-list.c b/src/nl-route-list.c
index 78222d2..9999a02 100644
--- a/src/nl-route-list.c
+++ b/src/nl-route-list.c
@@ -23,6 +23,7 @@ static void print_usage(void)
"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"
@@ -59,12 +60,11 @@ int main(int argc, char *argv[])
.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)
@@ -84,6 +84,7 @@ int main(int argc, char *argv[])
ARG_TYPE,
};
static struct option long_opts[] = {
+ { "cache", 0, 0, 'c' },
{ "format", 1, 0, 'f' },
{ "help", 0, 0, 'h' },
{ "version", 0, 0, 'v' },
@@ -102,11 +103,12 @@ int main(int argc, char *argv[])
{ 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;
@@ -125,13 +127,16 @@ int main(int argc, char *argv[])
}
}
+ route_cache = nltool_alloc_route_cache(nlh,
+ print_cache ? ROUTE_CACHE_CONTENT : 0);
+
nl_cache_dump_filter(route_cache, &params, 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);
diff --git a/src/utils.c b/src/utils.c
index 9c34172..8961219 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -141,11 +141,11 @@ struct nl_cache *nltool_alloc_neightbl_cache(struct nl_handle *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());
diff --git a/src/utils.h b/src/utils.h
index 1e0bcb4..c400206 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -56,7 +56,7 @@ extern struct nl_cache *nltool_alloc_link_cache(struct nl_handle *nlh);
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);