]> git.proxmox.com Git - mirror_iproute2.git/blob - ip/ipntable.c
Merge branch 'master' into iproute2-next
[mirror_iproute2.git] / ip / ipntable.c
1 /*
2 * Copyright (C)2006 USAGI/WIDE Project
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses>.
16 */
17 /*
18 * based on ipneigh.c
19 */
20 /*
21 * Authors:
22 * Masahide NAKAMURA @USAGI
23 */
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <sys/time.h>
29 #include <sys/socket.h>
30 #include <time.h>
31
32 #include "utils.h"
33 #include "ip_common.h"
34 #include "json_print.h"
35
36 static struct
37 {
38 int family;
39 int index;
40 #define NONE_DEV (-1)
41 const char *name;
42 } filter;
43
44 static void usage(void) __attribute__((noreturn));
45
46 static void usage(void)
47 {
48 fprintf(stderr,
49 "Usage: ip ntable change name NAME [ dev DEV ]\n"
50 " [ thresh1 VAL ] [ thresh2 VAL ] [ thresh3 VAL ] [ gc_int MSEC ]\n"
51 " [ PARMS ]\n"
52 "Usage: ip ntable show [ dev DEV ] [ name NAME ]\n"
53
54 "PARMS := [ base_reachable MSEC ] [ retrans MSEC ] [ gc_stale MSEC ]\n"
55 " [ delay_probe MSEC ] [ queue LEN ]\n"
56 " [ app_probes VAL ] [ ucast_probes VAL ] [ mcast_probes VAL ]\n"
57 " [ anycast_delay MSEC ] [ proxy_delay MSEC ] [ proxy_queue LEN ]\n"
58 " [ locktime MSEC ]\n"
59 );
60
61 exit(-1);
62 }
63
64 static int ipntable_modify(int cmd, int flags, int argc, char **argv)
65 {
66 struct {
67 struct nlmsghdr n;
68 struct ndtmsg ndtm;
69 char buf[1024];
70 } req = {
71 .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndtmsg)),
72 .n.nlmsg_flags = NLM_F_REQUEST | flags,
73 .n.nlmsg_type = cmd,
74 .ndtm.ndtm_family = preferred_family,
75 };
76 char *namep = NULL;
77 char *threshsp = NULL;
78 char *gc_intp = NULL;
79 char parms_buf[1024] = {};
80 struct rtattr *parms_rta = (struct rtattr *)parms_buf;
81 int parms_change = 0;
82
83 parms_rta->rta_type = NDTA_PARMS;
84 parms_rta->rta_len = RTA_LENGTH(0);
85
86 while (argc > 0) {
87 if (strcmp(*argv, "name") == 0) {
88 int len;
89
90 NEXT_ARG();
91 if (namep)
92 duparg("NAME", *argv);
93
94 namep = *argv;
95 len = strlen(namep) + 1;
96 addattr_l(&req.n, sizeof(req), NDTA_NAME, namep, len);
97 } else if (strcmp(*argv, "thresh1") == 0) {
98 __u32 thresh1;
99
100 NEXT_ARG();
101 threshsp = *argv;
102
103 if (get_u32(&thresh1, *argv, 0))
104 invarg("\"thresh1\" value is invalid", *argv);
105
106 addattr32(&req.n, sizeof(req), NDTA_THRESH1, thresh1);
107 } else if (strcmp(*argv, "thresh2") == 0) {
108 __u32 thresh2;
109
110 NEXT_ARG();
111 threshsp = *argv;
112
113 if (get_u32(&thresh2, *argv, 0))
114 invarg("\"thresh2\" value is invalid", *argv);
115
116 addattr32(&req.n, sizeof(req), NDTA_THRESH2, thresh2);
117 } else if (strcmp(*argv, "thresh3") == 0) {
118 __u32 thresh3;
119
120 NEXT_ARG();
121 threshsp = *argv;
122
123 if (get_u32(&thresh3, *argv, 0))
124 invarg("\"thresh3\" value is invalid", *argv);
125
126 addattr32(&req.n, sizeof(req), NDTA_THRESH3, thresh3);
127 } else if (strcmp(*argv, "gc_int") == 0) {
128 __u64 gc_int;
129
130 NEXT_ARG();
131 gc_intp = *argv;
132
133 if (get_u64(&gc_int, *argv, 0))
134 invarg("\"gc_int\" value is invalid", *argv);
135
136 addattr_l(&req.n, sizeof(req), NDTA_GC_INTERVAL,
137 &gc_int, sizeof(gc_int));
138 } else if (strcmp(*argv, "dev") == 0) {
139 __u32 ifindex;
140
141 NEXT_ARG();
142 ifindex = ll_name_to_index(*argv);
143 if (!ifindex)
144 return nodev(*argv);
145
146 rta_addattr32(parms_rta, sizeof(parms_buf),
147 NDTPA_IFINDEX, ifindex);
148 } else if (strcmp(*argv, "base_reachable") == 0) {
149 __u64 breachable;
150
151 NEXT_ARG();
152
153 if (get_u64(&breachable, *argv, 0))
154 invarg("\"base_reachable\" value is invalid", *argv);
155
156 rta_addattr_l(parms_rta, sizeof(parms_buf),
157 NDTPA_BASE_REACHABLE_TIME,
158 &breachable, sizeof(breachable));
159 parms_change = 1;
160 } else if (strcmp(*argv, "retrans") == 0) {
161 __u64 retrans;
162
163 NEXT_ARG();
164
165 if (get_u64(&retrans, *argv, 0))
166 invarg("\"retrans\" value is invalid", *argv);
167
168 rta_addattr_l(parms_rta, sizeof(parms_buf),
169 NDTPA_RETRANS_TIME,
170 &retrans, sizeof(retrans));
171 parms_change = 1;
172 } else if (strcmp(*argv, "gc_stale") == 0) {
173 __u64 gc_stale;
174
175 NEXT_ARG();
176
177 if (get_u64(&gc_stale, *argv, 0))
178 invarg("\"gc_stale\" value is invalid", *argv);
179
180 rta_addattr_l(parms_rta, sizeof(parms_buf),
181 NDTPA_GC_STALETIME,
182 &gc_stale, sizeof(gc_stale));
183 parms_change = 1;
184 } else if (strcmp(*argv, "delay_probe") == 0) {
185 __u64 delay_probe;
186
187 NEXT_ARG();
188
189 if (get_u64(&delay_probe, *argv, 0))
190 invarg("\"delay_probe\" value is invalid", *argv);
191
192 rta_addattr_l(parms_rta, sizeof(parms_buf),
193 NDTPA_DELAY_PROBE_TIME,
194 &delay_probe, sizeof(delay_probe));
195 parms_change = 1;
196 } else if (strcmp(*argv, "queue") == 0) {
197 __u32 queue;
198
199 NEXT_ARG();
200
201 if (get_u32(&queue, *argv, 0))
202 invarg("\"queue\" value is invalid", *argv);
203
204 rta_addattr32(parms_rta, sizeof(parms_buf),
205 NDTPA_QUEUE_LEN, queue);
206 parms_change = 1;
207 } else if (strcmp(*argv, "app_probes") == 0) {
208 __u32 aprobe;
209
210 NEXT_ARG();
211
212 if (get_u32(&aprobe, *argv, 0))
213 invarg("\"app_probes\" value is invalid", *argv);
214
215 rta_addattr32(parms_rta, sizeof(parms_buf),
216 NDTPA_APP_PROBES, aprobe);
217 parms_change = 1;
218 } else if (strcmp(*argv, "ucast_probes") == 0) {
219 __u32 uprobe;
220
221 NEXT_ARG();
222
223 if (get_u32(&uprobe, *argv, 0))
224 invarg("\"ucast_probes\" value is invalid", *argv);
225
226 rta_addattr32(parms_rta, sizeof(parms_buf),
227 NDTPA_UCAST_PROBES, uprobe);
228 parms_change = 1;
229 } else if (strcmp(*argv, "mcast_probes") == 0) {
230 __u32 mprobe;
231
232 NEXT_ARG();
233
234 if (get_u32(&mprobe, *argv, 0))
235 invarg("\"mcast_probes\" value is invalid", *argv);
236
237 rta_addattr32(parms_rta, sizeof(parms_buf),
238 NDTPA_MCAST_PROBES, mprobe);
239 parms_change = 1;
240 } else if (strcmp(*argv, "anycast_delay") == 0) {
241 __u64 anycast_delay;
242
243 NEXT_ARG();
244
245 if (get_u64(&anycast_delay, *argv, 0))
246 invarg("\"anycast_delay\" value is invalid", *argv);
247
248 rta_addattr_l(parms_rta, sizeof(parms_buf),
249 NDTPA_ANYCAST_DELAY,
250 &anycast_delay, sizeof(anycast_delay));
251 parms_change = 1;
252 } else if (strcmp(*argv, "proxy_delay") == 0) {
253 __u64 proxy_delay;
254
255 NEXT_ARG();
256
257 if (get_u64(&proxy_delay, *argv, 0))
258 invarg("\"proxy_delay\" value is invalid", *argv);
259
260 rta_addattr_l(parms_rta, sizeof(parms_buf),
261 NDTPA_PROXY_DELAY,
262 &proxy_delay, sizeof(proxy_delay));
263 parms_change = 1;
264 } else if (strcmp(*argv, "proxy_queue") == 0) {
265 __u32 pqueue;
266
267 NEXT_ARG();
268
269 if (get_u32(&pqueue, *argv, 0))
270 invarg("\"proxy_queue\" value is invalid", *argv);
271
272 rta_addattr32(parms_rta, sizeof(parms_buf),
273 NDTPA_PROXY_QLEN, pqueue);
274 parms_change = 1;
275 } else if (strcmp(*argv, "locktime") == 0) {
276 __u64 locktime;
277
278 NEXT_ARG();
279
280 if (get_u64(&locktime, *argv, 0))
281 invarg("\"locktime\" value is invalid", *argv);
282
283 rta_addattr_l(parms_rta, sizeof(parms_buf),
284 NDTPA_LOCKTIME,
285 &locktime, sizeof(locktime));
286 parms_change = 1;
287 } else {
288 invarg("unknown", *argv);
289 }
290
291 argc--; argv++;
292 }
293
294 if (!namep)
295 missarg("NAME");
296 if (!threshsp && !gc_intp && !parms_change) {
297 fprintf(stderr, "Not enough information: changeable attributes required.\n");
298 exit(-1);
299 }
300
301 if (parms_rta->rta_len > RTA_LENGTH(0)) {
302 addattr_l(&req.n, sizeof(req), NDTA_PARMS, RTA_DATA(parms_rta),
303 RTA_PAYLOAD(parms_rta));
304 }
305
306 if (rtnl_talk(&rth, &req.n, NULL) < 0)
307 exit(2);
308
309 return 0;
310 }
311
312 static const char *ntable_strtime_delta(__u32 msec)
313 {
314 static char str[32];
315 struct timeval now = {};
316 time_t t;
317 struct tm *tp;
318
319 if (msec == 0)
320 goto error;
321
322 if (gettimeofday(&now, NULL) < 0) {
323 perror("gettimeofday");
324 goto error;
325 }
326
327 t = now.tv_sec - (msec / 1000);
328 tp = localtime(&t);
329 if (!tp)
330 goto error;
331
332 strftime(str, sizeof(str), "%Y-%m-%d %T", tp);
333
334 return str;
335 error:
336 strcpy(str, "(error)");
337 return str;
338 }
339
340 static void print_ndtconfig(const struct ndt_config *ndtc)
341 {
342
343 print_uint(PRINT_ANY, "key_length",
344 " config key_len %u ", ndtc->ndtc_key_len);
345 print_uint(PRINT_ANY, "entry_size",
346 "entry_size %u ", ndtc->ndtc_entry_size);
347 print_uint(PRINT_ANY, "entries", "entries %u ", ndtc->ndtc_entries);
348
349 print_nl();
350
351 print_string(PRINT_ANY, "last_flush",
352 " last_flush %s ",
353 ntable_strtime_delta(ndtc->ndtc_last_flush));
354 print_string(PRINT_ANY, "last_rand",
355 "last_rand %s ",
356 ntable_strtime_delta(ndtc->ndtc_last_rand));
357
358 print_nl();
359
360 print_uint(PRINT_ANY, "hash_rnd",
361 " hash_rnd %u ", ndtc->ndtc_hash_rnd);
362 print_0xhex(PRINT_ANY, "hash_mask",
363 "hash_mask %08x ", ndtc->ndtc_hash_mask);
364
365 print_uint(PRINT_ANY, "hash_chain_gc",
366 "hash_chain_gc %u ", ndtc->ndtc_hash_chain_gc);
367 print_uint(PRINT_ANY, "proxy_qlen",
368 "proxy_qlen %u ", ndtc->ndtc_proxy_qlen);
369
370 print_nl();
371 }
372
373 static void print_ndtparams(struct rtattr *tpb[])
374 {
375
376 if (tpb[NDTPA_IFINDEX]) {
377 __u32 ifindex = rta_getattr_u32(tpb[NDTPA_IFINDEX]);
378
379 print_string(PRINT_FP, NULL, " dev ", NULL);
380 print_color_string(PRINT_ANY, COLOR_IFNAME,
381 "dev", "%s ", ll_index_to_name(ifindex));
382 print_nl();
383 }
384
385 print_string(PRINT_FP, NULL, " ", NULL);
386 if (tpb[NDTPA_REFCNT]) {
387 __u32 refcnt = rta_getattr_u32(tpb[NDTPA_REFCNT]);
388
389 print_uint(PRINT_ANY, "refcnt", "refcnt %u ", refcnt);
390 }
391
392 if (tpb[NDTPA_REACHABLE_TIME]) {
393 __u64 reachable = rta_getattr_u64(tpb[NDTPA_REACHABLE_TIME]);
394
395 print_u64(PRINT_ANY, "reachable",
396 "reachable %llu ", reachable);
397 }
398
399 if (tpb[NDTPA_BASE_REACHABLE_TIME]) {
400 __u64 breachable
401 = rta_getattr_u64(tpb[NDTPA_BASE_REACHABLE_TIME]);
402
403 print_u64(PRINT_ANY, "base_reachable",
404 "base_reachable %llu ", breachable);
405 }
406
407 if (tpb[NDTPA_RETRANS_TIME]) {
408 __u64 retrans = rta_getattr_u64(tpb[NDTPA_RETRANS_TIME]);
409
410 print_u64(PRINT_ANY, "retrans", "retrans %llu ", retrans);
411 }
412
413 print_string(PRINT_FP, NULL, "%s ", _SL_);
414
415 if (tpb[NDTPA_GC_STALETIME]) {
416 __u64 gc_stale = rta_getattr_u64(tpb[NDTPA_GC_STALETIME]);
417
418 print_u64(PRINT_ANY, "gc_stale", "gc_stale %llu ", gc_stale);
419 }
420
421 if (tpb[NDTPA_DELAY_PROBE_TIME]) {
422 __u64 delay_probe
423 = rta_getattr_u64(tpb[NDTPA_DELAY_PROBE_TIME]);
424
425 print_u64(PRINT_ANY, "delay_probe",
426 "delay_probe %llu ", delay_probe);
427 }
428
429 if (tpb[NDTPA_QUEUE_LEN]) {
430 __u32 queue = rta_getattr_u32(tpb[NDTPA_QUEUE_LEN]);
431
432 print_uint(PRINT_ANY, "queue", "queue %u ", queue);
433 }
434
435 print_string(PRINT_FP, NULL, "%s ", _SL_);
436
437 if (tpb[NDTPA_APP_PROBES]) {
438 __u32 aprobe = rta_getattr_u32(tpb[NDTPA_APP_PROBES]);
439
440 print_uint(PRINT_ANY, "app_probes", "app_probes %u ", aprobe);
441 }
442
443 if (tpb[NDTPA_UCAST_PROBES]) {
444 __u32 uprobe = rta_getattr_u32(tpb[NDTPA_UCAST_PROBES]);
445
446 print_uint(PRINT_ANY, "ucast_probes",
447 "ucast_probes %u ", uprobe);
448 }
449
450 if (tpb[NDTPA_MCAST_PROBES]) {
451 __u32 mprobe = rta_getattr_u32(tpb[NDTPA_MCAST_PROBES]);
452
453 print_uint(PRINT_ANY, "mcast_probes",
454 "mcast_probes %u ", mprobe);
455 }
456
457 print_string(PRINT_FP, NULL, "%s ", _SL_);
458
459 if (tpb[NDTPA_ANYCAST_DELAY]) {
460 __u64 anycast_delay = rta_getattr_u64(tpb[NDTPA_ANYCAST_DELAY]);
461
462 print_u64(PRINT_ANY, "anycast_delay",
463 "anycast_delay %llu ", anycast_delay);
464 }
465
466 if (tpb[NDTPA_PROXY_DELAY]) {
467 __u64 proxy_delay = rta_getattr_u64(tpb[NDTPA_PROXY_DELAY]);
468
469 print_u64(PRINT_ANY, "proxy_delay",
470 "proxy_delay %llu ", proxy_delay);
471 }
472
473 if (tpb[NDTPA_PROXY_QLEN]) {
474 __u32 pqueue = rta_getattr_u32(tpb[NDTPA_PROXY_QLEN]);
475
476 print_uint(PRINT_ANY, "proxy_queue", "proxy_queue %u ", pqueue);
477 }
478
479 if (tpb[NDTPA_LOCKTIME]) {
480 __u64 locktime = rta_getattr_u64(tpb[NDTPA_LOCKTIME]);
481
482 print_u64(PRINT_ANY, "locktime", "locktime %llu ", locktime);
483 }
484
485 print_nl();
486 }
487
488 static void print_ndtstats(const struct ndt_stats *ndts)
489 {
490
491 print_string(PRINT_FP, NULL, " stats ", NULL);
492
493 print_u64(PRINT_ANY, "allocs", "allocs %llu ", ndts->ndts_allocs);
494 print_u64(PRINT_ANY, "destroys", "destroys %llu ",
495 ndts->ndts_destroys);
496 print_u64(PRINT_ANY, "hash_grows", "hash_grows %llu ",
497 ndts->ndts_hash_grows);
498
499 print_string(PRINT_FP, NULL, "%s ", _SL_);
500
501 print_u64(PRINT_ANY, "res_failed", "res_failed %llu ",
502 ndts->ndts_res_failed);
503 print_u64(PRINT_ANY, "lookups", "lookups %llu ", ndts->ndts_lookups);
504 print_u64(PRINT_ANY, "hits", "hits %llu ", ndts->ndts_hits);
505
506 print_string(PRINT_FP, NULL, "%s ", _SL_);
507
508 print_u64(PRINT_ANY, "rcv_probes_mcast", "rcv_probes_mcast %llu ",
509 ndts->ndts_rcv_probes_mcast);
510 print_u64(PRINT_ANY, "rcv_probes_ucast", "rcv_probes_ucast %llu ",
511 ndts->ndts_rcv_probes_ucast);
512
513 print_string(PRINT_FP, NULL, "%s ", _SL_);
514
515 print_u64(PRINT_ANY, "periodic_gc_runs", "periodic_gc_runs %llu ",
516 ndts->ndts_periodic_gc_runs);
517 print_u64(PRINT_ANY, "forced_gc_runs", "forced_gc_runs %llu ",
518 ndts->ndts_forced_gc_runs);
519
520 print_nl();
521 }
522
523 static int print_ntable(const struct sockaddr_nl *who,
524 struct nlmsghdr *n, void *arg)
525 {
526 FILE *fp = (FILE *)arg;
527 struct ndtmsg *ndtm = NLMSG_DATA(n);
528 int len = n->nlmsg_len;
529 struct rtattr *tb[NDTA_MAX+1];
530 struct rtattr *tpb[NDTPA_MAX+1];
531 int ret;
532
533 if (n->nlmsg_type != RTM_NEWNEIGHTBL) {
534 fprintf(stderr, "Not NEIGHTBL: %08x %08x %08x\n",
535 n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
536 return 0;
537 }
538 len -= NLMSG_LENGTH(sizeof(*ndtm));
539 if (len < 0) {
540 fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
541 return -1;
542 }
543
544 if (preferred_family && preferred_family != ndtm->ndtm_family)
545 return 0;
546
547 parse_rtattr(tb, NDTA_MAX, NDTA_RTA(ndtm),
548 n->nlmsg_len - NLMSG_LENGTH(sizeof(*ndtm)));
549
550 if (tb[NDTA_NAME]) {
551 const char *name = rta_getattr_str(tb[NDTA_NAME]);
552
553 if (filter.name && strcmp(filter.name, name))
554 return 0;
555 }
556
557 if (tb[NDTA_PARMS]) {
558 parse_rtattr(tpb, NDTPA_MAX, RTA_DATA(tb[NDTA_PARMS]),
559 RTA_PAYLOAD(tb[NDTA_PARMS]));
560
561 if (tpb[NDTPA_IFINDEX]) {
562 __u32 ifindex = rta_getattr_u32(tpb[NDTPA_IFINDEX]);
563
564 if (filter.index && filter.index != ifindex)
565 return 0;
566 } else {
567 if (filter.index && filter.index != NONE_DEV)
568 return 0;
569 }
570 }
571
572 open_json_object(NULL);
573 print_string(PRINT_ANY, "family",
574 "%s ", family_name(ndtm->ndtm_family));
575
576 if (tb[NDTA_NAME]) {
577 const char *name = rta_getattr_str(tb[NDTA_NAME]);
578
579 print_string(PRINT_ANY, "name", "%s ", name);
580 }
581
582 print_nl();
583
584 ret = (tb[NDTA_THRESH1] || tb[NDTA_THRESH2] || tb[NDTA_THRESH3] ||
585 tb[NDTA_GC_INTERVAL]);
586 if (ret)
587 print_string(PRINT_FP, NULL, " ", NULL);
588
589 if (tb[NDTA_THRESH1]) {
590 __u32 thresh1 = rta_getattr_u32(tb[NDTA_THRESH1]);
591
592 print_uint(PRINT_ANY, "thresh1", "thresh1 %u ", thresh1);
593 }
594
595 if (tb[NDTA_THRESH2]) {
596 __u32 thresh2 = rta_getattr_u32(tb[NDTA_THRESH2]);
597
598 print_uint(PRINT_ANY, "thresh2", "thresh2 %u ", thresh2);
599 }
600
601 if (tb[NDTA_THRESH3]) {
602 __u32 thresh3 = rta_getattr_u32(tb[NDTA_THRESH3]);
603
604 print_uint(PRINT_ANY, "thresh3", "thresh3 %u ", thresh3);
605 }
606
607 if (tb[NDTA_GC_INTERVAL]) {
608 __u64 gc_int = rta_getattr_u64(tb[NDTA_GC_INTERVAL]);
609
610 print_u64(PRINT_ANY, "gc_interval", "gc_int %llu ", gc_int);
611 }
612
613 if (ret)
614 print_nl();
615
616 if (tb[NDTA_CONFIG] && show_stats)
617 print_ndtconfig(RTA_DATA(tb[NDTA_CONFIG]));
618
619 if (tb[NDTA_PARMS])
620 print_ndtparams(tpb);
621
622 if (tb[NDTA_STATS] && show_stats)
623 print_ndtstats(RTA_DATA(tb[NDTA_STATS]));
624
625 print_string(PRINT_FP, NULL, "\n", "");
626 close_json_object();
627 fflush(fp);
628
629 return 0;
630 }
631
632 static void ipntable_reset_filter(void)
633 {
634 memset(&filter, 0, sizeof(filter));
635 }
636
637 static int ipntable_show(int argc, char **argv)
638 {
639 ipntable_reset_filter();
640
641 filter.family = preferred_family;
642
643 while (argc > 0) {
644 if (strcmp(*argv, "dev") == 0) {
645 NEXT_ARG();
646
647 if (strcmp("none", *argv) == 0)
648 filter.index = NONE_DEV;
649 else if ((filter.index = ll_name_to_index(*argv)) == 0)
650 invarg("\"DEV\" is invalid", *argv);
651 } else if (strcmp(*argv, "name") == 0) {
652 NEXT_ARG();
653
654 filter.name = *argv;
655 } else
656 invarg("unknown", *argv);
657
658 argc--; argv++;
659 }
660
661 if (rtnl_neightbldump_req(&rth, preferred_family) < 0) {
662 perror("Cannot send dump request");
663 exit(1);
664 }
665
666 new_json_obj(json);
667 if (rtnl_dump_filter(&rth, print_ntable, stdout) < 0) {
668 fprintf(stderr, "Dump terminated\n");
669 exit(1);
670 }
671 delete_json_obj();
672
673 return 0;
674 }
675
676 int do_ipntable(int argc, char **argv)
677 {
678 ll_init_map(&rth);
679
680 if (argc > 0) {
681 if (matches(*argv, "change") == 0 ||
682 matches(*argv, "chg") == 0)
683 return ipntable_modify(RTM_SETNEIGHTBL,
684 NLM_F_REPLACE,
685 argc-1, argv+1);
686 if (matches(*argv, "show") == 0 ||
687 matches(*argv, "lst") == 0 ||
688 matches(*argv, "list") == 0)
689 return ipntable_show(argc-1, argv+1);
690 if (matches(*argv, "help") == 0)
691 usage();
692 } else
693 return ipntable_show(0, NULL);
694
695 fprintf(stderr, "Command \"%s\" is unknown, try \"ip ntable help\".\n", *argv);
696 exit(-1);
697 }