summaryrefslogtreecommitdiff
path: root/src/nl-route-add.c
diff options
context:
space:
mode:
authorThomas Graf <tgr@lsx.localdomain>2008-04-30 18:51:24 +0200
committerThomas Graf <tgr@lsx.localdomain>2008-04-30 18:51:24 +0200
commita948e082ea1d9457057296f65e5d72708cd5e768 (patch)
tree6a711fcc3cb8ce37789a88cbdaab4eea44303b24 /src/nl-route-add.c
parent182608e23629781698756aaf36c1db4ba888626f (diff)
downloadlibnl-a948e082ea1d9457057296f65e5d72708cd5e768.tar.gz
Adapt syntax of nl-route-add to nl-route-delete
Diffstat (limited to 'src/nl-route-add.c')
-rw-r--r--src/nl-route-add.c120
1 files changed, 73 insertions, 47 deletions
diff --git a/src/nl-route-add.c b/src/nl-route-add.c
index eb63a22..4895747 100644
--- a/src/nl-route-add.c
+++ b/src/nl-route-add.c
@@ -11,43 +11,56 @@
#include "route-utils.h"
+static int quiet = 0;
static struct nl_cache *link_cache, *route_cache;
+static void print_version(void)
+{
+ fprintf(stderr, "%s\n", LIBNL_STRING);
+ exit(0);
+}
+
static void print_usage(void)
{
printf(
- "Usage: nl-route-add [OPTION]... --dst=ADDR --nh=NEXTHOP [--nh=...]\n"
- " nl-route-add [OPTION]... ADDR NEXTHOP\n"
+ "Usage: nl-route-add [OPTION]... [ROUTE]\n"
+ "\n"
+ "Options\n"
+ " -q, --quiet Do not print informal notifications\n"
+ " -h, --help Show this help\n"
+ " -v, --version Show versioning information\n"
"\n"
- "Required Options\n"
+ "Route Options\n"
" -d, --dst=ADDR destination prefix, e.g. 10.10.0.0/16\n"
- " -n, --nh=NEXTHOP nexthop configuration:\n"
+ " -n, --nexthop=NH nexthop configuration:\n"
" dev=DEV route via device\n"
" weight=WEIGHT weight of nexthop\n"
" flags=FLAGS\n"
" via=GATEWAY route via other node\n"
" realms=REALMS\n"
- "\n"
" e.g. dev=eth0,via=192.168.1.12\n"
- "\n"
- "Options\n"
- " -s, --src=ADDR source prefix\n"
- " -i, --iif=DEV incomming interface\n"
- " -P, --pref-src=ADDR preferred source address\n"
- " -t, --table=TABLE routing table\n"
- " -m, --metric=OPTS metrics\n"
- " -p, --prio=NUM priotity\n"
- " -S, --scope=SCOPE scope\n"
- " -x, --proto=PROTO protocol\n"
- " -T, --type=TYPE routing type\n"
- " -h, --help show this help\n");
- exit(1);
+ " -t, --table=TABLE Routing table\n"
+ " --family=FAMILY Address family\n"
+ " --src=ADDR Source prefix\n"
+ " --iif=DEV Incomming interface\n"
+ " --pref-src=ADDR Preferred source address\n"
+ " --metrics=OPTS Metrics configurations\n"
+ " --priority=NUM Priotity\n"
+ " --scope=SCOPE Scope\n"
+ " --protocol=PROTO Protocol\n"
+ " --type=TYPE { unicast | local | broadcast | multicast }\n"
+ );
+ exit(0);
}
int main(int argc, char *argv[])
{
struct nl_handle *nlh;
struct rtnl_route *route;
+ struct nl_dump_params dp = {
+ .dp_type = NL_DUMP_ONELINE,
+ .dp_fd = stdout,
+ };
int err = 1;
nlh = nltool_alloc_handle();
@@ -61,56 +74,69 @@ int main(int argc, char *argv[])
for (;;) {
int c, optidx = 0;
+ enum {
+ ARG_FAMILY = 257,
+ ARG_SRC = 258,
+ ARG_IIF,
+ ARG_PREF_SRC,
+ ARG_METRICS,
+ ARG_PRIORITY,
+ ARG_SCOPE,
+ ARG_PROTOCOL,
+ ARG_TYPE,
+ };
static struct option long_opts[] = {
+ { "quiet", 0, 0, 'q' },
+ { "help", 0, 0, 'h' },
+ { "version", 0, 0, 'v' },
{ "dst", 1, 0, 'd' },
- { "src", 1, 0, 's' },
- { "iif", 1, 0, 'i' },
- { "nh", 1, 0, 'n' },
- { "pref-src", 1, 0, 'P' },
+ { "nexthop", 1, 0, 'n' },
{ "table", 1, 0, 't' },
- { "metric", 1, 0, 'm' },
- { "prio", 1, 0, 'p' },
- { "scope", 1, 0, 'S' },
- { "proto", 1, 0, 'x' },
- { "type", 1, 0, 'T' },
- { "help", 0, 0, 'h' },
+ { "family", 1, 0, ARG_FAMILY },
+ { "src", 1, 0, ARG_SRC },
+ { "iif", 1, 0, ARG_IIF },
+ { "pref-src", 1, 0, ARG_PREF_SRC },
+ { "metrics", 1, 0, ARG_METRICS },
+ { "priority", 1, 0, ARG_PRIORITY },
+ { "scope", 1, 0, ARG_SCOPE },
+ { "protocol", 1, 0, ARG_PROTOCOL },
+ { "type", 1, 0, ARG_TYPE },
{ 0, 0, 0, 0 }
};
- c = getopt_long(argc, argv, "d:s:i:n:P:t:m:p:S:x:T:h", long_opts, &optidx);
+ c = getopt_long(argc, argv, "qhvd:n:t:", long_opts, &optidx);
if (c == -1)
break;
switch (c) {
+ case 'q': quiet = 1; break;
+ case 'h': print_usage(); break;
+ case 'v': print_version(); break;
case 'd': parse_dst(route, optarg); break;
- case 's': parse_src(route, optarg); break;
- case 'i': parse_iif(route, optarg, link_cache); break;
case 'n': parse_nexthop(route, optarg, link_cache); break;
- case 'P': parse_pref_src(route, optarg); break;
case 't': parse_table(route, optarg); break;
- case 'm': parse_metric(route, optarg); break;
- case 'p': parse_prio(route, optarg); break;
- case 'S': parse_scope(route, optarg); break;
- case 'x': parse_protocol(route, optarg); break;
- case 'T': parse_type(route, optarg); break;
- case 'h': print_usage(); break;
+ case ARG_FAMILY: parse_family(route, optarg); break;
+ case ARG_SRC: parse_src(route, optarg); break;
+ case ARG_IIF: parse_iif(route, optarg, link_cache); break;
+ case ARG_PREF_SRC: parse_pref_src(route, optarg); break;
+ case ARG_METRICS: parse_metric(route, optarg); break;
+ case ARG_PRIORITY: parse_prio(route, optarg); break;
+ case ARG_SCOPE: parse_scope(route, optarg); break;
+ case ARG_PROTOCOL: parse_protocol(route, optarg); break;
+ case ARG_TYPE: parse_type(route, optarg); break;
}
}
- while (optind < argc) {
- if (!rtnl_route_get_dst(route)) {
- parse_dst(route, argv[optind++]);
- continue;
- }
-
- /* This must all be nexthop configuration */
- }
-
if (rtnl_route_add(nlh, route, 0) < 0) {
fprintf(stderr, "rtnl_route_add failed: %s\n", nl_geterror());
goto errout_free;
}
+ if (!quiet) {
+ printf("Added ");
+ nl_object_dump(OBJ_CAST(route), &dp);
+ }
+
err = 0;
errout_free:
rtnl_route_put(route);