]> git.proxmox.com Git - mirror_iproute2.git/blob - ip/ipntable.c
5b61dd5cb001da598d171fd77fb35278631ff3ad
[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(struct nlmsghdr *n, void *arg)
524 {
525 FILE *fp = (FILE *)arg;
526 struct ndtmsg *ndtm = NLMSG_DATA(n);
527 int len = n->nlmsg_len;
528 struct rtattr *tb[NDTA_MAX+1];
529 struct rtattr *tpb[NDTPA_MAX+1];
530 int ret;
531
532 if (n->nlmsg_type != RTM_NEWNEIGHTBL) {
533 fprintf(stderr, "Not NEIGHTBL: %08x %08x %08x\n",
534 n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
535 return 0;
536 }
537 len -= NLMSG_LENGTH(sizeof(*ndtm));
538 if (len < 0) {
539 fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
540 return -1;
541 }
542
543 if (preferred_family && preferred_family != ndtm->ndtm_family)
544 return 0;
545
546 parse_rtattr(tb, NDTA_MAX, NDTA_RTA(ndtm),
547 n->nlmsg_len - NLMSG_LENGTH(sizeof(*ndtm)));
548
549 if (tb[NDTA_NAME]) {
550 const char *name = rta_getattr_str(tb[NDTA_NAME]);
551
552 if (filter.name && strcmp(filter.name, name))
553 return 0;
554 }
555
556 if (tb[NDTA_PARMS]) {
557 parse_rtattr(tpb, NDTPA_MAX, RTA_DATA(tb[NDTA_PARMS]),
558 RTA_PAYLOAD(tb[NDTA_PARMS]));
559
560 if (tpb[NDTPA_IFINDEX]) {
561 __u32 ifindex = rta_getattr_u32(tpb[NDTPA_IFINDEX]);
562
563 if (filter.index && filter.index != ifindex)
564 return 0;
565 } else {
566 if (filter.index && filter.index != NONE_DEV)
567 return 0;
568 }
569 }
570
571 open_json_object(NULL);
572 print_string(PRINT_ANY, "family",
573 "%s ", family_name(ndtm->ndtm_family));
574
575 if (tb[NDTA_NAME]) {
576 const char *name = rta_getattr_str(tb[NDTA_NAME]);
577
578 print_string(PRINT_ANY, "name", "%s ", name);
579 }
580
581 print_nl();
582
583 ret = (tb[NDTA_THRESH1] || tb[NDTA_THRESH2] || tb[NDTA_THRESH3] ||
584 tb[NDTA_GC_INTERVAL]);
585 if (ret)
586 print_string(PRINT_FP, NULL, " ", NULL);
587
588 if (tb[NDTA_THRESH1]) {
589 __u32 thresh1 = rta_getattr_u32(tb[NDTA_THRESH1]);
590
591 print_uint(PRINT_ANY, "thresh1", "thresh1 %u ", thresh1);
592 }
593
594 if (tb[NDTA_THRESH2]) {
595 __u32 thresh2 = rta_getattr_u32(tb[NDTA_THRESH2]);
596
597 print_uint(PRINT_ANY, "thresh2", "thresh2 %u ", thresh2);
598 }
599
600 if (tb[NDTA_THRESH3]) {
601 __u32 thresh3 = rta_getattr_u32(tb[NDTA_THRESH3]);
602
603 print_uint(PRINT_ANY, "thresh3", "thresh3 %u ", thresh3);
604 }
605
606 if (tb[NDTA_GC_INTERVAL]) {
607 __u64 gc_int = rta_getattr_u64(tb[NDTA_GC_INTERVAL]);
608
609 print_u64(PRINT_ANY, "gc_interval", "gc_int %llu ", gc_int);
610 }
611
612 if (ret)
613 print_nl();
614
615 if (tb[NDTA_CONFIG] && show_stats)
616 print_ndtconfig(RTA_DATA(tb[NDTA_CONFIG]));
617
618 if (tb[NDTA_PARMS])
619 print_ndtparams(tpb);
620
621 if (tb[NDTA_STATS] && show_stats)
622 print_ndtstats(RTA_DATA(tb[NDTA_STATS]));
623
624 print_string(PRINT_FP, NULL, "\n", "");
625 close_json_object();
626 fflush(fp);
627
628 return 0;
629 }
630
631 static void ipntable_reset_filter(void)
632 {
633 memset(&filter, 0, sizeof(filter));
634 }
635
636 static int ipntable_show(int argc, char **argv)
637 {
638 ipntable_reset_filter();
639
640 filter.family = preferred_family;
641
642 while (argc > 0) {
643 if (strcmp(*argv, "dev") == 0) {
644 NEXT_ARG();
645
646 if (strcmp("none", *argv) == 0)
647 filter.index = NONE_DEV;
648 else if ((filter.index = ll_name_to_index(*argv)) == 0)
649 invarg("\"DEV\" is invalid", *argv);
650 } else if (strcmp(*argv, "name") == 0) {
651 NEXT_ARG();
652
653 filter.name = *argv;
654 } else
655 invarg("unknown", *argv);
656
657 argc--; argv++;
658 }
659
660 if (rtnl_neightbldump_req(&rth, preferred_family) < 0) {
661 perror("Cannot send dump request");
662 exit(1);
663 }
664
665 new_json_obj(json);
666 if (rtnl_dump_filter(&rth, print_ntable, stdout) < 0) {
667 fprintf(stderr, "Dump terminated\n");
668 exit(1);
669 }
670 delete_json_obj();
671
672 return 0;
673 }
674
675 int do_ipntable(int argc, char **argv)
676 {
677 ll_init_map(&rth);
678
679 if (argc > 0) {
680 if (matches(*argv, "change") == 0 ||
681 matches(*argv, "chg") == 0)
682 return ipntable_modify(RTM_SETNEIGHTBL,
683 NLM_F_REPLACE,
684 argc-1, argv+1);
685 if (matches(*argv, "show") == 0 ||
686 matches(*argv, "lst") == 0 ||
687 matches(*argv, "list") == 0)
688 return ipntable_show(argc-1, argv+1);
689 if (matches(*argv, "help") == 0)
690 usage();
691 } else
692 return ipntable_show(0, NULL);
693
694 fprintf(stderr, "Command \"%s\" is unknown, try \"ip ntable help\".\n", *argv);
695 exit(-1);
696 }