12 #include <netlink/cli/utils.h> 13 #include <netlink/cli/route.h> 14 #include <netlink/cli/link.h> 16 #include <linux/netlink.h> 18 static void print_usage(
void)
21 "Usage: nl-route-list [OPTION]... [ROUTE]\n" 24 " -c, --cache List the contents of the route cache\n" 25 " -f, --format=TYPE Output format { brief | details | stats }\n" 26 " -h, --help Show this help\n" 27 " -v, --version Show versioning information\n" 30 " -d, --dst=ADDR destination prefix, e.g. 10.10.0.0/16\n" 31 " -n, --nexthop=NH nexthop configuration:\n" 32 " dev=DEV route via device\n" 33 " weight=WEIGHT weight of nexthop\n" 35 " via=GATEWAY route via other node\n" 37 " e.g. dev=eth0,via=192.168.1.12\n" 38 " -t, --table=TABLE Routing table\n" 39 " --family=FAMILY Address family\n" 40 " --src=ADDR Source prefix\n" 41 " --iif=DEV Incomming interface\n" 42 " --pref-src=ADDR Preferred source address\n" 43 " --metrics=OPTS Metrics configurations\n" 44 " --priority=NUM Priotity\n" 45 " --scope=SCOPE Scope\n" 46 " --protocol=PROTO Protocol\n" 47 " --type=TYPE { unicast | local | broadcast | multicast }\n" 52 int main(
int argc,
char *argv[])
55 struct nl_cache *link_cache, *route_cache;
56 struct rtnl_route *route;
63 sock = nl_cli_alloc_socket();
64 nl_cli_connect(sock, NETLINK_ROUTE);
65 link_cache = nl_cli_link_alloc_cache(sock);
66 route = nl_cli_route_alloc();
81 static struct option long_opts[] = {
82 {
"cache", 0, 0,
'c' },
83 {
"format", 1, 0,
'f' },
84 {
"help", 0, 0,
'h' },
85 {
"version", 0, 0,
'v' },
87 {
"nexthop", 1, 0,
'n' },
88 {
"table", 1, 0,
't' },
89 {
"family", 1, 0, ARG_FAMILY },
90 {
"src", 1, 0, ARG_SRC },
91 {
"iif", 1, 0, ARG_IIF },
92 {
"pref-src", 1, 0, ARG_PREF_SRC },
93 {
"metrics", 1, 0, ARG_METRICS },
94 {
"priority", 1, 0, ARG_PRIORITY },
95 {
"scope", 1, 0, ARG_SCOPE },
96 {
"protocol", 1, 0, ARG_PROTOCOL },
97 {
"type", 1, 0, ARG_TYPE },
101 c = getopt_long(argc, argv,
"cf:hvd:n:t:", long_opts, &optidx);
106 case 'c': print_cache = 1;
break;
107 case 'f': params.
dp_type = nl_cli_parse_dumptype(optarg);
break;
108 case 'h': print_usage();
break;
109 case 'v': nl_cli_print_version();
break;
110 case 'd': nl_cli_route_parse_dst(route, optarg);
break;
111 case 'n': nl_cli_route_parse_nexthop(route, optarg, link_cache);
break;
112 case 't': nl_cli_route_parse_table(route, optarg);
break;
113 case ARG_FAMILY: nl_cli_route_parse_family(route, optarg);
break;
114 case ARG_SRC: nl_cli_route_parse_src(route, optarg);
break;
115 case ARG_IIF: nl_cli_route_parse_iif(route, optarg, link_cache);
break;
116 case ARG_PREF_SRC: nl_cli_route_parse_pref_src(route, optarg);
break;
117 case ARG_METRICS: nl_cli_route_parse_metric(route, optarg);
break;
118 case ARG_PRIORITY: nl_cli_route_parse_prio(route, optarg);
break;
119 case ARG_SCOPE: nl_cli_route_parse_scope(route, optarg);
break;
120 case ARG_PROTOCOL: nl_cli_route_parse_protocol(route, optarg);
break;
121 case ARG_TYPE: nl_cli_route_parse_type(route, optarg);
break;
125 route_cache = nl_cli_route_alloc_cache(sock,
Dump object briefly on one line.
FILE * dp_fd
File descriptor the dumping output should go to.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
#define ROUTE_CACHE_CONTENT
When passed to rtnl_route_alloc_cache() the cache will correspond to the contents of the routing cach...
void nl_cache_dump_filter(struct nl_cache *cache, struct nl_dump_params *params, struct nl_object *filter)
Dump all elements of a cache (filtered).