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