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