2 * iproute.c "ip route".
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <netinet/ip.h>
24 #include <arpa/inet.h>
25 #include <linux/in_route.h>
29 #include "ip_common.h"
32 #define RTAX_RTTVAR RTAX_HOPS
36 static const char *mx_names[RTAX_MAX+1] = {
38 [RTAX_WINDOW] = "window",
40 [RTAX_RTTVAR] = "rttvar",
41 [RTAX_SSTHRESH] = "ssthresh",
43 [RTAX_ADVMSS] = "advmss",
44 [RTAX_REORDERING]="reordering",
45 [RTAX_HOPLIMIT] = "hoplimit",
46 [RTAX_INITCWND] = "initcwnd",
47 [RTAX_FEATURES] = "features",
48 [RTAX_RTO_MIN] = "rto_min",
49 [RTAX_INITRWND] = "initrwnd",
51 static void usage(void) __attribute__((noreturn));
53 static void usage(void)
55 fprintf(stderr, "Usage: ip route { list | flush } SELECTOR\n");
56 fprintf(stderr, " ip route get ADDRESS [ from ADDRESS iif STRING ]\n");
57 fprintf(stderr, " [ oif STRING ] [ tos TOS ]\n");
58 fprintf(stderr, " [ mark NUMBER ]\n");
59 fprintf(stderr, " ip route { add | del | change | append | replace | monitor } ROUTE\n");
60 fprintf(stderr, "SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ]\n");
61 fprintf(stderr, " [ table TABLE_ID ] [ proto RTPROTO ]\n");
62 fprintf(stderr, " [ type TYPE ] [ scope SCOPE ]\n");
63 fprintf(stderr, "ROUTE := NODE_SPEC [ INFO_SPEC ]\n");
64 fprintf(stderr, "NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ]\n");
65 fprintf(stderr, " [ table TABLE_ID ] [ proto RTPROTO ]\n");
66 fprintf(stderr, " [ scope SCOPE ] [ metric METRIC ]\n");
67 fprintf(stderr, "INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ]...\n");
68 fprintf(stderr, "NH := [ via ADDRESS ] [ dev STRING ] [ weight NUMBER ] NHFLAGS\n");
69 fprintf(stderr, "OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ]\n");
70 fprintf(stderr, " [ rtt TIME ] [ rttvar TIME ] [reordering NUMBER ]\n");
71 fprintf(stderr, " [ window NUMBER] [ cwnd NUMBER ] [ initcwnd NUMBER ]\n");
72 fprintf(stderr, " [ ssthresh NUMBER ] [ realms REALM ] [ src ADDRESS ]\n");
73 fprintf(stderr, " [ rto_min TIME ] [ hoplimit NUMBER ] [ initrwnd NUMBER ]\n");
74 fprintf(stderr, "TYPE := [ unicast | local | broadcast | multicast | throw |\n");
75 fprintf(stderr, " unreachable | prohibit | blackhole | nat ]\n");
76 fprintf(stderr, "TABLE_ID := [ local | main | default | all | NUMBER ]\n");
77 fprintf(stderr, "SCOPE := [ host | link | global | NUMBER ]\n");
78 fprintf(stderr, "MP_ALGO := { rr | drr | random | wrandom }\n");
79 fprintf(stderr, "NHFLAGS := [ onlink | pervasive ]\n");
80 fprintf(stderr, "RTPROTO := [ kernel | boot | static | NUMBER ]\n");
81 fprintf(stderr, "TIME := NUMBER[s|ms|us|ns|j]\n");
94 int protocol, protocolmask;
101 int realm, realmmask;
102 inet_prefix rprefsrc;
110 static int flush_update(void)
112 if (rtnl_send_check(&rth, filter.flushb, filter.flushp) < 0) {
113 perror("Failed to send flush request");
120 int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
122 FILE *fp = (FILE*)arg;
123 struct rtmsg *r = NLMSG_DATA(n);
124 int len = n->nlmsg_len;
125 struct rtattr * tb[RTA_MAX+1];
132 static int ip6_multiple_tables;
137 if (n->nlmsg_type != RTM_NEWROUTE && n->nlmsg_type != RTM_DELROUTE) {
138 fprintf(stderr, "Not a route: %08x %08x %08x\n",
139 n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
142 if (filter.flushb && n->nlmsg_type != RTM_NEWROUTE)
144 len -= NLMSG_LENGTH(sizeof(*r));
146 fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
150 if (r->rtm_family == AF_INET6)
152 else if (r->rtm_family == AF_INET)
154 else if (r->rtm_family == AF_DECnet)
156 else if (r->rtm_family == AF_IPX)
159 parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
160 table = rtm_get_table(r, tb);
162 if (r->rtm_family == AF_INET6 && table != RT_TABLE_MAIN)
163 ip6_multiple_tables = 1;
165 if (filter.cloned == !(r->rtm_flags&RTM_F_CLONED))
168 if (r->rtm_family == AF_INET6 && !ip6_multiple_tables) {
170 if (filter.tb == RT_TABLE_LOCAL) {
171 if (r->rtm_type != RTN_LOCAL)
173 } else if (filter.tb == RT_TABLE_MAIN) {
174 if (r->rtm_type == RTN_LOCAL)
181 if (filter.tb > 0 && filter.tb != table)
184 if ((filter.protocol^r->rtm_protocol)&filter.protocolmask)
186 if ((filter.scope^r->rtm_scope)&filter.scopemask)
188 if ((filter.type^r->rtm_type)&filter.typemask)
190 if ((filter.tos^r->rtm_tos)&filter.tosmask)
192 if (filter.rdst.family &&
193 (r->rtm_family != filter.rdst.family || filter.rdst.bitlen > r->rtm_dst_len))
195 if (filter.mdst.family &&
196 (r->rtm_family != filter.mdst.family ||
197 (filter.mdst.bitlen >= 0 && filter.mdst.bitlen < r->rtm_dst_len)))
199 if (filter.rsrc.family &&
200 (r->rtm_family != filter.rsrc.family || filter.rsrc.bitlen > r->rtm_src_len))
202 if (filter.msrc.family &&
203 (r->rtm_family != filter.msrc.family ||
204 (filter.msrc.bitlen >= 0 && filter.msrc.bitlen < r->rtm_src_len)))
206 if (filter.rvia.family && r->rtm_family != filter.rvia.family)
208 if (filter.rprefsrc.family && r->rtm_family != filter.rprefsrc.family)
211 memset(&dst, 0, sizeof(dst));
212 dst.family = r->rtm_family;
214 memcpy(&dst.data, RTA_DATA(tb[RTA_DST]), (r->rtm_dst_len+7)/8);
215 if (filter.rsrc.family || filter.msrc.family) {
216 memset(&src, 0, sizeof(src));
217 src.family = r->rtm_family;
219 memcpy(&src.data, RTA_DATA(tb[RTA_SRC]), (r->rtm_src_len+7)/8);
221 if (filter.rvia.bitlen>0) {
222 memset(&via, 0, sizeof(via));
223 via.family = r->rtm_family;
225 memcpy(&via.data, RTA_DATA(tb[RTA_GATEWAY]), host_len/8);
227 if (filter.rprefsrc.bitlen>0) {
228 memset(&prefsrc, 0, sizeof(prefsrc));
229 prefsrc.family = r->rtm_family;
231 memcpy(&prefsrc.data, RTA_DATA(tb[RTA_PREFSRC]), host_len/8);
234 if (filter.rdst.family && inet_addr_match(&dst, &filter.rdst, filter.rdst.bitlen))
236 if (filter.mdst.family && filter.mdst.bitlen >= 0 &&
237 inet_addr_match(&dst, &filter.mdst, r->rtm_dst_len))
240 if (filter.rsrc.family && inet_addr_match(&src, &filter.rsrc, filter.rsrc.bitlen))
242 if (filter.msrc.family && filter.msrc.bitlen >= 0 &&
243 inet_addr_match(&src, &filter.msrc, r->rtm_src_len))
246 if (filter.rvia.family && inet_addr_match(&via, &filter.rvia, filter.rvia.bitlen))
248 if (filter.rprefsrc.family && inet_addr_match(&prefsrc, &filter.rprefsrc, filter.rprefsrc.bitlen))
250 if (filter.realmmask) {
253 realms = *(__u32*)RTA_DATA(tb[RTA_FLOW]);
254 if ((realms^filter.realm)&filter.realmmask)
257 if (filter.iifmask) {
260 iif = *(int*)RTA_DATA(tb[RTA_IIF]);
261 if ((iif^filter.iif)&filter.iifmask)
264 if (filter.oifmask) {
267 oif = *(int*)RTA_DATA(tb[RTA_OIF]);
268 if ((oif^filter.oif)&filter.oifmask)
271 if (filter.markmask) {
274 mark = *(int *)RTA_DATA(tb[RTA_MARK]);
275 if ((mark ^ filter.mark) & filter.markmask)
279 r->rtm_family == AF_INET6 &&
280 r->rtm_dst_len == 0 &&
281 r->rtm_type == RTN_UNREACHABLE &&
283 *(int*)RTA_DATA(tb[RTA_PRIORITY]) == -1)
288 if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) {
292 fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp));
293 memcpy(fn, n, n->nlmsg_len);
294 fn->nlmsg_type = RTM_DELROUTE;
295 fn->nlmsg_flags = NLM_F_REQUEST;
296 fn->nlmsg_seq = ++rth.seq;
297 filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb;
303 if (n->nlmsg_type == RTM_DELROUTE)
304 fprintf(fp, "Deleted ");
305 if (r->rtm_type != RTN_UNICAST && !filter.type)
306 fprintf(fp, "%s ", rtnl_rtntype_n2a(r->rtm_type, b1, sizeof(b1)));
309 if (r->rtm_dst_len != host_len) {
310 fprintf(fp, "%s/%u ", rt_addr_n2a(r->rtm_family,
311 RTA_PAYLOAD(tb[RTA_DST]),
312 RTA_DATA(tb[RTA_DST]),
317 fprintf(fp, "%s ", format_host(r->rtm_family,
318 RTA_PAYLOAD(tb[RTA_DST]),
319 RTA_DATA(tb[RTA_DST]),
323 } else if (r->rtm_dst_len) {
324 fprintf(fp, "0/%d ", r->rtm_dst_len);
326 fprintf(fp, "default ");
329 if (r->rtm_src_len != host_len) {
330 fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family,
331 RTA_PAYLOAD(tb[RTA_SRC]),
332 RTA_DATA(tb[RTA_SRC]),
337 fprintf(fp, "from %s ", format_host(r->rtm_family,
338 RTA_PAYLOAD(tb[RTA_SRC]),
339 RTA_DATA(tb[RTA_SRC]),
343 } else if (r->rtm_src_len) {
344 fprintf(fp, "from 0/%u ", r->rtm_src_len);
346 if (r->rtm_tos && filter.tosmask != -1) {
348 fprintf(fp, "tos %s ", rtnl_dsfield_n2a(r->rtm_tos, b1, sizeof(b1)));
351 if (tb[RTA_GATEWAY] && filter.rvia.bitlen != host_len) {
352 fprintf(fp, "via %s ",
353 format_host(r->rtm_family,
354 RTA_PAYLOAD(tb[RTA_GATEWAY]),
355 RTA_DATA(tb[RTA_GATEWAY]),
356 abuf, sizeof(abuf)));
358 if (tb[RTA_OIF] && filter.oifmask != -1)
359 fprintf(fp, "dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF])));
361 if (!(r->rtm_flags&RTM_F_CLONED)) {
362 if (table != RT_TABLE_MAIN && !filter.tb)
363 fprintf(fp, " table %s ", rtnl_rttable_n2a(table, b1, sizeof(b1)));
364 if (r->rtm_protocol != RTPROT_BOOT && filter.protocolmask != -1)
365 fprintf(fp, " proto %s ", rtnl_rtprot_n2a(r->rtm_protocol, b1, sizeof(b1)));
366 if (r->rtm_scope != RT_SCOPE_UNIVERSE && filter.scopemask != -1)
367 fprintf(fp, " scope %s ", rtnl_rtscope_n2a(r->rtm_scope, b1, sizeof(b1)));
369 if (tb[RTA_PREFSRC] && filter.rprefsrc.bitlen != host_len) {
370 /* Do not use format_host(). It is our local addr
371 and symbolic name will not be useful.
373 fprintf(fp, " src %s ",
374 rt_addr_n2a(r->rtm_family,
375 RTA_PAYLOAD(tb[RTA_PREFSRC]),
376 RTA_DATA(tb[RTA_PREFSRC]),
377 abuf, sizeof(abuf)));
379 if (tb[RTA_PRIORITY])
380 fprintf(fp, " metric %d ", *(__u32*)RTA_DATA(tb[RTA_PRIORITY]));
381 if (r->rtm_flags & RTNH_F_DEAD)
382 fprintf(fp, "dead ");
383 if (r->rtm_flags & RTNH_F_ONLINK)
384 fprintf(fp, "onlink ");
385 if (r->rtm_flags & RTNH_F_PERVASIVE)
386 fprintf(fp, "pervasive ");
387 if (r->rtm_flags & RTM_F_NOTIFY)
388 fprintf(fp, "notify ");
390 unsigned int mark = *(unsigned int*)RTA_DATA(tb[RTA_MARK]);
393 fprintf(fp, " mark 0x%x", mark);
395 fprintf(fp, " mark %u", mark);
399 if (tb[RTA_FLOW] && filter.realmmask != ~0U) {
400 __u32 to = *(__u32*)RTA_DATA(tb[RTA_FLOW]);
403 fprintf(fp, "realm%s ", from ? "s" : "");
406 rtnl_rtrealm_n2a(from, b1, sizeof(b1)));
409 rtnl_rtrealm_n2a(to, b1, sizeof(b1)));
411 if ((r->rtm_flags&RTM_F_CLONED) && r->rtm_family == AF_INET) {
412 __u32 flags = r->rtm_flags&~0xFFFF;
415 fprintf(fp, "%s cache ", _SL_);
417 #define PRTFL(fl,flname) if (flags&RTCF_##fl) { \
418 flags &= ~RTCF_##fl; \
419 fprintf(fp, "%s" flname "%s", first ? "<" : "", flags ? "," : "> "); \
421 PRTFL(LOCAL, "local");
422 PRTFL(REJECT, "reject");
423 PRTFL(MULTICAST, "mc");
424 PRTFL(BROADCAST, "brd");
425 PRTFL(DNAT, "dst-nat");
426 PRTFL(SNAT, "src-nat");
428 PRTFL(DIRECTDST, "dst-direct");
429 PRTFL(DIRECTSRC, "src-direct");
430 PRTFL(REDIRECTED, "redirected");
431 PRTFL(DOREDIRECT, "redirect");
432 PRTFL(FAST, "fastroute");
433 PRTFL(NOTIFY, "notify");
434 PRTFL(TPROXY, "proxy");
437 fprintf(fp, "%s%x> ", first ? "<" : "", flags);
438 if (tb[RTA_CACHEINFO]) {
439 struct rta_cacheinfo *ci = RTA_DATA(tb[RTA_CACHEINFO]);
442 if (ci->rta_expires != 0)
443 fprintf(fp, " expires %dsec", ci->rta_expires/hz);
444 if (ci->rta_error != 0)
445 fprintf(fp, " error %d", ci->rta_error);
448 fprintf(fp, " users %d", ci->rta_clntref);
449 if (ci->rta_used != 0)
450 fprintf(fp, " used %d", ci->rta_used);
451 if (ci->rta_lastuse != 0)
452 fprintf(fp, " age %dsec", ci->rta_lastuse/hz);
454 #ifdef RTNETLINK_HAVE_PEERINFO
456 fprintf(fp, " ipid 0x%04x", ci->rta_id);
457 if (ci->rta_ts || ci->rta_tsage)
458 fprintf(fp, " ts 0x%x tsage %dsec", ci->rta_ts, ci->rta_tsage);
461 } else if (r->rtm_family == AF_INET6) {
462 struct rta_cacheinfo *ci = NULL;
463 if (tb[RTA_CACHEINFO])
464 ci = RTA_DATA(tb[RTA_CACHEINFO]);
465 if ((r->rtm_flags & RTM_F_CLONED) || (ci && ci->rta_expires)) {
468 if (r->rtm_flags & RTM_F_CLONED)
469 fprintf(fp, "%s cache ", _SL_);
471 fprintf(fp, " expires %dsec", ci->rta_expires/hz);
472 if (ci->rta_error != 0)
473 fprintf(fp, " error %d", ci->rta_error);
476 fprintf(fp, " users %d", ci->rta_clntref);
477 if (ci->rta_used != 0)
478 fprintf(fp, " used %d", ci->rta_used);
479 if (ci->rta_lastuse != 0)
480 fprintf(fp, " age %dsec", ci->rta_lastuse/hz);
483 if (ci->rta_error != 0)
484 fprintf(fp, " error %d", ci->rta_error);
487 if (tb[RTA_METRICS]) {
490 struct rtattr *mxrta[RTAX_MAX+1];
492 parse_rtattr(mxrta, RTAX_MAX, RTA_DATA(tb[RTA_METRICS]),
493 RTA_PAYLOAD(tb[RTA_METRICS]));
494 if (mxrta[RTAX_LOCK])
495 mxlock = *(unsigned*)RTA_DATA(mxrta[RTAX_LOCK]);
497 for (i=2; i<= RTAX_MAX; i++) {
500 if (mxrta[i] == NULL)
505 if (i < sizeof(mx_names)/sizeof(char*) && mx_names[i])
506 fprintf(fp, " %s", mx_names[i]);
508 fprintf(fp, " metric %d", i);
510 fprintf(fp, " lock");
512 val = *(unsigned*)RTA_DATA(mxrta[i]);
519 fprintf(fp, " %u", val);
528 else if (i == RTAX_RTTVAR)
532 fprintf(fp, " %llums",
533 (unsigned long long) val / hz);
535 fprintf(fp, " %.2fms",
540 if (tb[RTA_IIF] && filter.iifmask != -1) {
541 fprintf(fp, " iif %s", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_IIF])));
543 if (tb[RTA_MULTIPATH]) {
544 struct rtnexthop *nh = RTA_DATA(tb[RTA_MULTIPATH]);
547 len = RTA_PAYLOAD(tb[RTA_MULTIPATH]);
550 if (len < sizeof(*nh))
552 if (nh->rtnh_len > len)
554 if (r->rtm_flags&RTM_F_CLONED && r->rtm_type == RTN_MULTICAST) {
556 fprintf(fp, " Oifs:");
560 fprintf(fp, "%s\tnexthop", _SL_);
561 if (nh->rtnh_len > sizeof(*nh)) {
562 parse_rtattr(tb, RTA_MAX, RTNH_DATA(nh), nh->rtnh_len - sizeof(*nh));
563 if (tb[RTA_GATEWAY]) {
564 fprintf(fp, " via %s ",
565 format_host(r->rtm_family,
566 RTA_PAYLOAD(tb[RTA_GATEWAY]),
567 RTA_DATA(tb[RTA_GATEWAY]),
568 abuf, sizeof(abuf)));
571 __u32 to = *(__u32*)RTA_DATA(tb[RTA_FLOW]);
574 fprintf(fp, " realm%s ", from ? "s" : "");
577 rtnl_rtrealm_n2a(from, b1, sizeof(b1)));
580 rtnl_rtrealm_n2a(to, b1, sizeof(b1)));
583 if (r->rtm_flags&RTM_F_CLONED && r->rtm_type == RTN_MULTICAST) {
584 fprintf(fp, " %s", ll_index_to_name(nh->rtnh_ifindex));
585 if (nh->rtnh_hops != 1)
586 fprintf(fp, "(ttl>%d)", nh->rtnh_hops);
588 fprintf(fp, " dev %s", ll_index_to_name(nh->rtnh_ifindex));
589 fprintf(fp, " weight %d", nh->rtnh_hops+1);
591 if (nh->rtnh_flags & RTNH_F_DEAD)
592 fprintf(fp, " dead");
593 if (nh->rtnh_flags & RTNH_F_ONLINK)
594 fprintf(fp, " onlink");
595 if (nh->rtnh_flags & RTNH_F_PERVASIVE)
596 fprintf(fp, " pervasive");
597 len -= NLMSG_ALIGN(nh->rtnh_len);
607 int parse_one_nh(struct rtattr *rta, struct rtnexthop *rtnh, int *argcp, char ***argvp)
610 char **argv = *argvp;
612 while (++argv, --argc > 0) {
613 if (strcmp(*argv, "via") == 0) {
615 rta_addattr32(rta, 4096, RTA_GATEWAY, get_addr32(*argv));
616 rtnh->rtnh_len += sizeof(struct rtattr) + 4;
617 } else if (strcmp(*argv, "dev") == 0) {
619 if ((rtnh->rtnh_ifindex = ll_name_to_index(*argv)) == 0) {
620 fprintf(stderr, "Cannot find device \"%s\"\n", *argv);
623 } else if (strcmp(*argv, "weight") == 0) {
626 if (get_unsigned(&w, *argv, 0) || w == 0 || w > 256)
627 invarg("\"weight\" is invalid\n", *argv);
628 rtnh->rtnh_hops = w - 1;
629 } else if (strcmp(*argv, "onlink") == 0) {
630 rtnh->rtnh_flags |= RTNH_F_ONLINK;
631 } else if (matches(*argv, "realms") == 0) {
634 if (get_rt_realms(&realm, *argv))
635 invarg("\"realm\" value is invalid\n", *argv);
636 rta_addattr32(rta, 4096, RTA_FLOW, realm);
637 rtnh->rtnh_len += sizeof(struct rtattr) + 4;
646 int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r, int argc, char **argv)
649 struct rtattr *rta = (void*)buf;
650 struct rtnexthop *rtnh;
652 rta->rta_type = RTA_MULTIPATH;
653 rta->rta_len = RTA_LENGTH(0);
654 rtnh = RTA_DATA(rta);
657 if (strcmp(*argv, "nexthop") != 0) {
658 fprintf(stderr, "Error: \"nexthop\" or end of line is expected instead of \"%s\"\n", *argv);
662 fprintf(stderr, "Error: unexpected end of line after \"nexthop\"\n");
665 memset(rtnh, 0, sizeof(*rtnh));
666 rtnh->rtnh_len = sizeof(*rtnh);
667 rta->rta_len += rtnh->rtnh_len;
668 parse_one_nh(rta, rtnh, &argc, &argv);
669 rtnh = RTNH_NEXT(rtnh);
672 if (rta->rta_len > RTA_LENGTH(0))
673 addattr_l(n, 1024, RTA_MULTIPATH, RTA_DATA(rta), RTA_PAYLOAD(rta));
678 int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
686 struct rtattr * mxrta = (void*)mxbuf;
698 memset(&req, 0, sizeof(req));
700 req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
701 req.n.nlmsg_flags = NLM_F_REQUEST|flags;
702 req.n.nlmsg_type = cmd;
703 req.r.rtm_family = preferred_family;
704 req.r.rtm_table = RT_TABLE_MAIN;
705 req.r.rtm_scope = RT_SCOPE_NOWHERE;
707 if (cmd != RTM_DELROUTE) {
708 req.r.rtm_protocol = RTPROT_BOOT;
709 req.r.rtm_scope = RT_SCOPE_UNIVERSE;
710 req.r.rtm_type = RTN_UNICAST;
713 mxrta->rta_type = RTA_METRICS;
714 mxrta->rta_len = RTA_LENGTH(0);
717 if (strcmp(*argv, "src") == 0) {
720 get_addr(&addr, *argv, req.r.rtm_family);
721 if (req.r.rtm_family == AF_UNSPEC)
722 req.r.rtm_family = addr.family;
723 addattr_l(&req.n, sizeof(req), RTA_PREFSRC, &addr.data, addr.bytelen);
724 } else if (strcmp(*argv, "via") == 0) {
728 get_addr(&addr, *argv, req.r.rtm_family);
729 if (req.r.rtm_family == AF_UNSPEC)
730 req.r.rtm_family = addr.family;
731 addattr_l(&req.n, sizeof(req), RTA_GATEWAY, &addr.data, addr.bytelen);
732 } else if (strcmp(*argv, "from") == 0) {
735 get_prefix(&addr, *argv, req.r.rtm_family);
736 if (req.r.rtm_family == AF_UNSPEC)
737 req.r.rtm_family = addr.family;
739 addattr_l(&req.n, sizeof(req), RTA_SRC, &addr.data, addr.bytelen);
740 req.r.rtm_src_len = addr.bitlen;
741 } else if (strcmp(*argv, "tos") == 0 ||
742 matches(*argv, "dsfield") == 0) {
745 if (rtnl_dsfield_a2n(&tos, *argv))
746 invarg("\"tos\" value is invalid\n", *argv);
748 } else if (matches(*argv, "metric") == 0 ||
749 matches(*argv, "priority") == 0 ||
750 matches(*argv, "preference") == 0) {
753 if (get_u32(&metric, *argv, 0))
754 invarg("\"metric\" value is invalid\n", *argv);
755 addattr32(&req.n, sizeof(req), RTA_PRIORITY, metric);
756 } else if (strcmp(*argv, "scope") == 0) {
759 if (rtnl_rtscope_a2n(&scope, *argv))
760 invarg("invalid \"scope\" value\n", *argv);
761 req.r.rtm_scope = scope;
763 } else if (strcmp(*argv, "mtu") == 0) {
766 if (strcmp(*argv, "lock") == 0) {
767 mxlock |= (1<<RTAX_MTU);
770 if (get_unsigned(&mtu, *argv, 0))
771 invarg("\"mtu\" value is invalid\n", *argv);
772 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_MTU, mtu);
774 } else if (strcmp(*argv, "hoplimit") == 0) {
777 if (strcmp(*argv, "lock") == 0) {
778 mxlock |= (1<<RTAX_HOPLIMIT);
781 if (get_unsigned(&hoplimit, *argv, 0))
782 invarg("\"hoplimit\" value is invalid\n", *argv);
783 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_HOPLIMIT, hoplimit);
786 } else if (strcmp(*argv, "advmss") == 0) {
789 if (strcmp(*argv, "lock") == 0) {
790 mxlock |= (1<<RTAX_ADVMSS);
793 if (get_unsigned(&mss, *argv, 0))
794 invarg("\"mss\" value is invalid\n", *argv);
795 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_ADVMSS, mss);
797 #ifdef RTAX_REORDERING
798 } else if (matches(*argv, "reordering") == 0) {
801 if (strcmp(*argv, "lock") == 0) {
802 mxlock |= (1<<RTAX_REORDERING);
805 if (get_unsigned(&reord, *argv, 0))
806 invarg("\"reordering\" value is invalid\n", *argv);
807 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_REORDERING, reord);
809 } else if (strcmp(*argv, "rtt") == 0) {
812 if (strcmp(*argv, "lock") == 0) {
813 mxlock |= (1<<RTAX_RTT);
816 if (get_jiffies(&rtt, *argv, 0, &raw))
817 invarg("\"rtt\" value is invalid\n", *argv);
818 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTT,
819 (raw) ? rtt : rtt * 8);
820 } else if (strcmp(*argv, "rto_min") == 0) {
823 mxlock |= (1<<RTAX_RTO_MIN);
824 if (get_jiffies(&rto_min, *argv, 0, &raw))
825 invarg("\"rto_min\" value is invalid\n",
827 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTO_MIN,
829 } else if (matches(*argv, "window") == 0) {
832 if (strcmp(*argv, "lock") == 0) {
833 mxlock |= (1<<RTAX_WINDOW);
836 if (get_unsigned(&win, *argv, 0))
837 invarg("\"window\" value is invalid\n", *argv);
838 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_WINDOW, win);
839 } else if (matches(*argv, "cwnd") == 0) {
842 if (strcmp(*argv, "lock") == 0) {
843 mxlock |= (1<<RTAX_CWND);
846 if (get_unsigned(&win, *argv, 0))
847 invarg("\"cwnd\" value is invalid\n", *argv);
848 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_CWND, win);
849 } else if (matches(*argv, "initcwnd") == 0) {
852 if (strcmp(*argv, "lock") == 0) {
853 mxlock |= (1<<RTAX_INITCWND);
856 if (get_unsigned(&win, *argv, 0))
857 invarg("\"initcwnd\" value is invalid\n", *argv);
858 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_INITCWND, win);
859 } else if (matches(*argv, "initrwnd") == 0) {
862 if (strcmp(*argv, "lock") == 0) {
863 mxlock |= (1<<RTAX_INITRWND);
866 if (get_unsigned(&win, *argv, 0))
867 invarg("\"initrwnd\" value is invalid\n", *argv);
868 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_INITRWND, win);
869 } else if (matches(*argv, "rttvar") == 0) {
872 if (strcmp(*argv, "lock") == 0) {
873 mxlock |= (1<<RTAX_RTTVAR);
876 if (get_jiffies(&win, *argv, 0, &raw))
877 invarg("\"rttvar\" value is invalid\n", *argv);
878 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTTVAR,
879 (raw) ? win : win * 4);
880 } else if (matches(*argv, "ssthresh") == 0) {
883 if (strcmp(*argv, "lock") == 0) {
884 mxlock |= (1<<RTAX_SSTHRESH);
887 if (get_unsigned(&win, *argv, 0))
888 invarg("\"ssthresh\" value is invalid\n", *argv);
889 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_SSTHRESH, win);
890 } else if (matches(*argv, "realms") == 0) {
893 if (get_rt_realms(&realm, *argv))
894 invarg("\"realm\" value is invalid\n", *argv);
895 addattr32(&req.n, sizeof(req), RTA_FLOW, realm);
896 } else if (strcmp(*argv, "onlink") == 0) {
897 req.r.rtm_flags |= RTNH_F_ONLINK;
898 } else if (strcmp(*argv, "nexthop") == 0) {
901 } else if (matches(*argv, "protocol") == 0) {
904 if (rtnl_rtprot_a2n(&prot, *argv))
905 invarg("\"protocol\" value is invalid\n", *argv);
906 req.r.rtm_protocol = prot;
908 } else if (matches(*argv, "table") == 0) {
911 if (rtnl_rttable_a2n(&tid, *argv))
912 invarg("\"table\" value is invalid\n", *argv);
914 req.r.rtm_table = tid;
916 req.r.rtm_table = RT_TABLE_UNSPEC;
917 addattr32(&req.n, sizeof(req), RTA_TABLE, tid);
920 } else if (strcmp(*argv, "dev") == 0 ||
921 strcmp(*argv, "oif") == 0) {
928 if (strcmp(*argv, "to") == 0) {
931 if ((**argv < '0' || **argv > '9') &&
932 rtnl_rtntype_a2n(&type, *argv) == 0) {
934 req.r.rtm_type = type;
938 if (matches(*argv, "help") == 0)
941 duparg2("to", *argv);
942 get_prefix(&dst, *argv, req.r.rtm_family);
943 if (req.r.rtm_family == AF_UNSPEC)
944 req.r.rtm_family = dst.family;
945 req.r.rtm_dst_len = dst.bitlen;
948 addattr_l(&req.n, sizeof(req), RTA_DST, &dst.data, dst.bytelen);
959 if ((idx = ll_name_to_index(d)) == 0) {
960 fprintf(stderr, "Cannot find device \"%s\"\n", d);
963 addattr32(&req.n, sizeof(req), RTA_OIF, idx);
967 if (mxrta->rta_len > RTA_LENGTH(0)) {
969 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_LOCK, mxlock);
970 addattr_l(&req.n, sizeof(req), RTA_METRICS, RTA_DATA(mxrta), RTA_PAYLOAD(mxrta));
974 parse_nexthops(&req.n, &req.r, argc, argv);
977 if (req.r.rtm_type == RTN_LOCAL ||
978 req.r.rtm_type == RTN_BROADCAST ||
979 req.r.rtm_type == RTN_NAT ||
980 req.r.rtm_type == RTN_ANYCAST)
981 req.r.rtm_table = RT_TABLE_LOCAL;
984 if (req.r.rtm_type == RTN_LOCAL ||
985 req.r.rtm_type == RTN_NAT)
986 req.r.rtm_scope = RT_SCOPE_HOST;
987 else if (req.r.rtm_type == RTN_BROADCAST ||
988 req.r.rtm_type == RTN_MULTICAST ||
989 req.r.rtm_type == RTN_ANYCAST)
990 req.r.rtm_scope = RT_SCOPE_LINK;
991 else if (req.r.rtm_type == RTN_UNICAST ||
992 req.r.rtm_type == RTN_UNSPEC) {
993 if (cmd == RTM_DELROUTE)
994 req.r.rtm_scope = RT_SCOPE_NOWHERE;
995 else if (!gw_ok && !nhs_ok)
996 req.r.rtm_scope = RT_SCOPE_LINK;
1000 if (req.r.rtm_family == AF_UNSPEC)
1001 req.r.rtm_family = AF_INET;
1003 if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0)
1009 static int rtnl_rtcache_request(struct rtnl_handle *rth, int family)
1012 struct nlmsghdr nlh;
1015 struct sockaddr_nl nladdr;
1017 memset(&nladdr, 0, sizeof(nladdr));
1018 memset(&req, 0, sizeof(req));
1019 nladdr.nl_family = AF_NETLINK;
1021 req.nlh.nlmsg_len = sizeof(req);
1022 req.nlh.nlmsg_type = RTM_GETROUTE;
1023 req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_REQUEST;
1024 req.nlh.nlmsg_pid = 0;
1025 req.nlh.nlmsg_seq = rth->dump = ++rth->seq;
1026 req.rtm.rtm_family = family;
1027 req.rtm.rtm_flags |= RTM_F_CLONED;
1029 return sendto(rth->fd, (void*)&req, sizeof(req), 0, (struct sockaddr*)&nladdr, sizeof(nladdr));
1032 static int iproute_flush_cache(void)
1034 #define ROUTE_FLUSH_PATH "/proc/sys/net/ipv4/route/flush"
1037 int flush_fd = open (ROUTE_FLUSH_PATH, O_WRONLY);
1038 char *buffer = "-1";
1041 fprintf (stderr, "Cannot open \"%s\"\n", ROUTE_FLUSH_PATH);
1045 len = strlen (buffer);
1047 if ((write (flush_fd, (void *)buffer, len)) < len) {
1048 fprintf (stderr, "Cannot flush routing cache\n");
1056 static int iproute_list_or_flush(int argc, char **argv, int flush)
1058 int do_ipv6 = preferred_family;
1061 unsigned int mark = 0;
1063 iproute_reset_filter();
1064 filter.tb = RT_TABLE_MAIN;
1066 if (flush && argc <= 0) {
1067 fprintf(stderr, "\"ip route flush\" requires arguments.\n");
1072 if (matches(*argv, "table") == 0) {
1075 if (rtnl_rttable_a2n(&tid, *argv)) {
1076 if (strcmp(*argv, "all") == 0) {
1078 } else if (strcmp(*argv, "cache") == 0) {
1080 } else if (strcmp(*argv, "help") == 0) {
1083 invarg("table id value is invalid\n", *argv);
1087 } else if (matches(*argv, "cached") == 0 ||
1088 matches(*argv, "cloned") == 0) {
1090 } else if (strcmp(*argv, "tos") == 0 ||
1091 matches(*argv, "dsfield") == 0) {
1094 if (rtnl_dsfield_a2n(&tos, *argv))
1095 invarg("TOS value is invalid\n", *argv);
1097 filter.tosmask = -1;
1098 } else if (matches(*argv, "protocol") == 0) {
1101 filter.protocolmask = -1;
1102 if (rtnl_rtprot_a2n(&prot, *argv)) {
1103 if (strcmp(*argv, "all") != 0)
1104 invarg("invalid \"protocol\"\n", *argv);
1106 filter.protocolmask = 0;
1108 filter.protocol = prot;
1109 } else if (matches(*argv, "scope") == 0) {
1112 filter.scopemask = -1;
1113 if (rtnl_rtscope_a2n(&scope, *argv)) {
1114 if (strcmp(*argv, "all") != 0)
1115 invarg("invalid \"scope\"\n", *argv);
1116 scope = RT_SCOPE_NOWHERE;
1117 filter.scopemask = 0;
1119 filter.scope = scope;
1120 } else if (matches(*argv, "type") == 0) {
1123 filter.typemask = -1;
1124 if (rtnl_rtntype_a2n(&type, *argv))
1125 invarg("node type value is invalid\n", *argv);
1127 } else if (strcmp(*argv, "dev") == 0 ||
1128 strcmp(*argv, "oif") == 0) {
1131 } else if (strcmp(*argv, "iif") == 0) {
1134 } else if (strcmp(*argv, "mark") == 0) {
1136 get_unsigned(&mark, *argv, 0);
1137 filter.markmask = -1;
1138 } else if (strcmp(*argv, "via") == 0) {
1140 get_prefix(&filter.rvia, *argv, do_ipv6);
1141 } else if (strcmp(*argv, "src") == 0) {
1143 get_prefix(&filter.rprefsrc, *argv, do_ipv6);
1144 } else if (matches(*argv, "realms") == 0) {
1147 if (get_rt_realms(&realm, *argv))
1148 invarg("invalid realms\n", *argv);
1149 filter.realm = realm;
1150 filter.realmmask = ~0U;
1151 if ((filter.realm&0xFFFF) == 0 &&
1152 (*argv)[strlen(*argv) - 1] == '/')
1153 filter.realmmask &= ~0xFFFF;
1154 if ((filter.realm&0xFFFF0000U) == 0 &&
1155 (strchr(*argv, '/') == NULL ||
1157 filter.realmmask &= ~0xFFFF0000U;
1158 } else if (matches(*argv, "from") == 0) {
1160 if (matches(*argv, "root") == 0) {
1162 get_prefix(&filter.rsrc, *argv, do_ipv6);
1163 } else if (matches(*argv, "match") == 0) {
1165 get_prefix(&filter.msrc, *argv, do_ipv6);
1167 if (matches(*argv, "exact") == 0) {
1170 get_prefix(&filter.msrc, *argv, do_ipv6);
1171 filter.rsrc = filter.msrc;
1174 if (matches(*argv, "to") == 0) {
1177 if (matches(*argv, "root") == 0) {
1179 get_prefix(&filter.rdst, *argv, do_ipv6);
1180 } else if (matches(*argv, "match") == 0) {
1182 get_prefix(&filter.mdst, *argv, do_ipv6);
1184 if (matches(*argv, "exact") == 0) {
1187 get_prefix(&filter.mdst, *argv, do_ipv6);
1188 filter.rdst = filter.mdst;
1194 if (do_ipv6 == AF_UNSPEC && filter.tb)
1203 if ((idx = ll_name_to_index(id)) == 0) {
1204 fprintf(stderr, "Cannot find device \"%s\"\n", id);
1208 filter.iifmask = -1;
1211 if ((idx = ll_name_to_index(od)) == 0) {
1212 fprintf(stderr, "Cannot find device \"%s\"\n", od);
1216 filter.oifmask = -1;
1223 char flushb[4096-512];
1224 time_t start = time(0);
1226 if (filter.cloned) {
1227 if (do_ipv6 != AF_INET6) {
1228 iproute_flush_cache();
1230 printf("*** IPv4 routing cache is flushed.\n");
1232 if (do_ipv6 == AF_INET)
1236 filter.flushb = flushb;
1238 filter.flushe = sizeof(flushb);
1241 if (rtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE) < 0) {
1242 perror("Cannot send dump request");
1246 if (rtnl_dump_filter(&rth, print_route, stdout, NULL, NULL) < 0) {
1247 fprintf(stderr, "Flush terminated\n");
1250 if (filter.flushed == 0) {
1252 if (round == 0 && (!filter.cloned || do_ipv6 == AF_INET6))
1253 printf("Nothing to flush.\n");
1255 printf("*** Flush is complete after %d round%s ***\n", round, round>1?"s":"");
1261 if (flush_update() < 0)
1264 if (time(0) - start > 30) {
1265 printf("\n*** Flush not completed after %ld seconds, %d entries remain ***\n",
1266 time(0) - start, filter.flushed);
1271 printf("\n*** Round %d, deleting %d entries ***\n", round, filter.flushed);
1277 if (!filter.cloned) {
1278 if (rtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE) < 0) {
1279 perror("Cannot send dump request");
1283 if (rtnl_rtcache_request(&rth, do_ipv6) < 0) {
1284 perror("Cannot send dump request");
1289 if (rtnl_dump_filter(&rth, print_route, stdout, NULL, NULL) < 0) {
1290 fprintf(stderr, "Dump terminated\n");
1298 int iproute_get(int argc, char **argv)
1309 unsigned int mark = 0;
1311 memset(&req, 0, sizeof(req));
1313 iproute_reset_filter();
1316 req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
1317 req.n.nlmsg_flags = NLM_F_REQUEST;
1318 req.n.nlmsg_type = RTM_GETROUTE;
1319 req.r.rtm_family = preferred_family;
1320 req.r.rtm_table = 0;
1321 req.r.rtm_protocol = 0;
1322 req.r.rtm_scope = 0;
1324 req.r.rtm_src_len = 0;
1325 req.r.rtm_dst_len = 0;
1329 if (strcmp(*argv, "tos") == 0 ||
1330 matches(*argv, "dsfield") == 0) {
1333 if (rtnl_dsfield_a2n(&tos, *argv))
1334 invarg("TOS value is invalid\n", *argv);
1335 req.r.rtm_tos = tos;
1336 } else if (matches(*argv, "from") == 0) {
1339 if (matches(*argv, "help") == 0)
1342 get_prefix(&addr, *argv, req.r.rtm_family);
1343 if (req.r.rtm_family == AF_UNSPEC)
1344 req.r.rtm_family = addr.family;
1346 addattr_l(&req.n, sizeof(req), RTA_SRC, &addr.data, addr.bytelen);
1347 req.r.rtm_src_len = addr.bitlen;
1348 } else if (matches(*argv, "iif") == 0) {
1351 } else if (matches(*argv, "mark") == 0) {
1353 get_unsigned(&mark, *argv, 0);
1354 } else if (matches(*argv, "oif") == 0 ||
1355 strcmp(*argv, "dev") == 0) {
1358 } else if (matches(*argv, "notify") == 0) {
1359 req.r.rtm_flags |= RTM_F_NOTIFY;
1360 } else if (matches(*argv, "connected") == 0) {
1364 if (strcmp(*argv, "to") == 0) {
1367 if (matches(*argv, "help") == 0)
1369 get_prefix(&addr, *argv, req.r.rtm_family);
1370 if (req.r.rtm_family == AF_UNSPEC)
1371 req.r.rtm_family = addr.family;
1373 addattr_l(&req.n, sizeof(req), RTA_DST, &addr.data, addr.bytelen);
1374 req.r.rtm_dst_len = addr.bitlen;
1379 if (req.r.rtm_dst_len == 0) {
1380 fprintf(stderr, "need at least destination address\n");
1390 if ((idx = ll_name_to_index(idev)) == 0) {
1391 fprintf(stderr, "Cannot find device \"%s\"\n", idev);
1394 addattr32(&req.n, sizeof(req), RTA_IIF, idx);
1397 if ((idx = ll_name_to_index(odev)) == 0) {
1398 fprintf(stderr, "Cannot find device \"%s\"\n", odev);
1401 addattr32(&req.n, sizeof(req), RTA_OIF, idx);
1405 addattr32(&req.n, sizeof(req), RTA_MARK, mark);
1407 if (req.r.rtm_family == AF_UNSPEC)
1408 req.r.rtm_family = AF_INET;
1410 if (rtnl_talk(&rth, &req.n, 0, 0, &req.n, NULL, NULL) < 0)
1413 if (connected && !from_ok) {
1414 struct rtmsg *r = NLMSG_DATA(&req.n);
1415 int len = req.n.nlmsg_len;
1416 struct rtattr * tb[RTA_MAX+1];
1418 if (print_route(NULL, &req.n, (void*)stdout) < 0) {
1419 fprintf(stderr, "An error :-)\n");
1423 if (req.n.nlmsg_type != RTM_NEWROUTE) {
1424 fprintf(stderr, "Not a route?\n");
1427 len -= NLMSG_LENGTH(sizeof(*r));
1429 fprintf(stderr, "Wrong len %d\n", len);
1433 parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
1435 if (tb[RTA_PREFSRC]) {
1436 tb[RTA_PREFSRC]->rta_type = RTA_SRC;
1437 r->rtm_src_len = 8*RTA_PAYLOAD(tb[RTA_PREFSRC]);
1438 } else if (!tb[RTA_SRC]) {
1439 fprintf(stderr, "Failed to connect the route\n");
1442 if (!odev && tb[RTA_OIF])
1443 tb[RTA_OIF]->rta_type = 0;
1444 if (tb[RTA_GATEWAY])
1445 tb[RTA_GATEWAY]->rta_type = 0;
1446 if (!idev && tb[RTA_IIF])
1447 tb[RTA_IIF]->rta_type = 0;
1448 req.n.nlmsg_flags = NLM_F_REQUEST;
1449 req.n.nlmsg_type = RTM_GETROUTE;
1451 if (rtnl_talk(&rth, &req.n, 0, 0, &req.n, NULL, NULL) < 0)
1455 if (print_route(NULL, &req.n, (void*)stdout) < 0) {
1456 fprintf(stderr, "An error :-)\n");
1463 void iproute_reset_filter()
1465 memset(&filter, 0, sizeof(filter));
1466 filter.mdst.bitlen = -1;
1467 filter.msrc.bitlen = -1;
1470 int do_iproute(int argc, char **argv)
1473 return iproute_list_or_flush(0, NULL, 0);
1475 if (matches(*argv, "add") == 0)
1476 return iproute_modify(RTM_NEWROUTE, NLM_F_CREATE|NLM_F_EXCL,
1478 if (matches(*argv, "change") == 0 || strcmp(*argv, "chg") == 0)
1479 return iproute_modify(RTM_NEWROUTE, NLM_F_REPLACE,
1481 if (matches(*argv, "replace") == 0)
1482 return iproute_modify(RTM_NEWROUTE, NLM_F_CREATE|NLM_F_REPLACE,
1484 if (matches(*argv, "prepend") == 0)
1485 return iproute_modify(RTM_NEWROUTE, NLM_F_CREATE,
1487 if (matches(*argv, "append") == 0)
1488 return iproute_modify(RTM_NEWROUTE, NLM_F_CREATE|NLM_F_APPEND,
1490 if (matches(*argv, "test") == 0)
1491 return iproute_modify(RTM_NEWROUTE, NLM_F_EXCL,
1493 if (matches(*argv, "delete") == 0)
1494 return iproute_modify(RTM_DELROUTE, 0,
1496 if (matches(*argv, "list") == 0 || matches(*argv, "show") == 0
1497 || matches(*argv, "lst") == 0)
1498 return iproute_list_or_flush(argc-1, argv+1, 0);
1499 if (matches(*argv, "get") == 0)
1500 return iproute_get(argc-1, argv+1);
1501 if (matches(*argv, "flush") == 0)
1502 return iproute_list_or_flush(argc-1, argv+1, 1);
1503 if (matches(*argv, "help") == 0)
1505 fprintf(stderr, "Command \"%s\" is unknown, try \"ip route help\".\n", *argv);