2
* src/nl-route-list.c List route attributes
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation version 2.1
9
* Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
12
#include <netlink/cli/utils.h>
13
#include <netlink/cli/route.h>
14
#include <netlink/cli/link.h>
16
static void print_usage(void)
19
"Usage: nl-route-list [OPTION]... [ROUTE]\n"
22
" -c, --cache List the contents of the route cache\n"
23
" -f, --format=TYPE Output format { brief | details | stats }\n"
24
" -h, --help Show this help\n"
25
" -v, --version Show versioning information\n"
28
" -d, --dst=ADDR destination prefix, e.g. 10.10.0.0/16\n"
29
" -n, --nexthop=NH nexthop configuration:\n"
30
" dev=DEV route via device\n"
31
" weight=WEIGHT weight of nexthop\n"
33
" via=GATEWAY route via other node\n"
35
" e.g. dev=eth0,via=192.168.1.12\n"
36
" -t, --table=TABLE Routing table\n"
37
" --family=FAMILY Address family\n"
38
" --src=ADDR Source prefix\n"
39
" --iif=DEV Incomming interface\n"
40
" --pref-src=ADDR Preferred source address\n"
41
" --metrics=OPTS Metrics configurations\n"
42
" --priority=NUM Priotity\n"
43
" --scope=SCOPE Scope\n"
44
" --protocol=PROTO Protocol\n"
45
" --type=TYPE { unicast | local | broadcast | multicast }\n"
50
int main(int argc, char *argv[])
53
struct nl_cache *link_cache, *route_cache;
54
struct rtnl_route *route;
55
struct nl_dump_params params = {
57
.dp_type = NL_DUMP_LINE,
61
sock = nl_cli_alloc_socket();
62
nl_cli_connect(sock, NETLINK_ROUTE);
63
link_cache = nl_cli_link_alloc_cache(sock);
64
route = nl_cli_route_alloc();
79
static struct option long_opts[] = {
80
{ "cache", 0, 0, 'c' },
81
{ "format", 1, 0, 'f' },
82
{ "help", 0, 0, 'h' },
83
{ "version", 0, 0, 'v' },
85
{ "nexthop", 1, 0, 'n' },
86
{ "table", 1, 0, 't' },
87
{ "family", 1, 0, ARG_FAMILY },
88
{ "src", 1, 0, ARG_SRC },
89
{ "iif", 1, 0, ARG_IIF },
90
{ "pref-src", 1, 0, ARG_PREF_SRC },
91
{ "metrics", 1, 0, ARG_METRICS },
92
{ "priority", 1, 0, ARG_PRIORITY },
93
{ "scope", 1, 0, ARG_SCOPE },
94
{ "protocol", 1, 0, ARG_PROTOCOL },
95
{ "type", 1, 0, ARG_TYPE },
99
c = getopt_long(argc, argv, "cf:hvd:n:t:", long_opts, &optidx);
104
case 'c': print_cache = 1; break;
105
case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break;
106
case 'h': print_usage(); break;
107
case 'v': nl_cli_print_version(); break;
108
case 'd': nl_cli_route_parse_dst(route, optarg); break;
109
case 'n': nl_cli_route_parse_nexthop(route, optarg, link_cache); break;
110
case 't': nl_cli_route_parse_table(route, optarg); break;
111
case ARG_FAMILY: nl_cli_route_parse_family(route, optarg); break;
112
case ARG_SRC: nl_cli_route_parse_src(route, optarg); break;
113
case ARG_IIF: nl_cli_route_parse_iif(route, optarg, link_cache); break;
114
case ARG_PREF_SRC: nl_cli_route_parse_pref_src(route, optarg); break;
115
case ARG_METRICS: nl_cli_route_parse_metric(route, optarg); break;
116
case ARG_PRIORITY: nl_cli_route_parse_prio(route, optarg); break;
117
case ARG_SCOPE: nl_cli_route_parse_scope(route, optarg); break;
118
case ARG_PROTOCOL: nl_cli_route_parse_protocol(route, optarg); break;
119
case ARG_TYPE: nl_cli_route_parse_type(route, optarg); break;
123
route_cache = nl_cli_route_alloc_cache(sock,
124
print_cache ? ROUTE_CACHE_CONTENT : 0);
126
nl_cache_dump_filter(route_cache, ¶ms, OBJ_CAST(route));