]>
Commit | Line | Data |
---|---|---|
aba5acdf SH |
1 | /* |
2 | * ipneigh.c "ip neigh". | |
3 | * | |
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. | |
8 | * | |
9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> | |
10 | * | |
aba5acdf SH |
11 | */ |
12 | ||
13 | #include <stdio.h> | |
14 | #include <stdlib.h> | |
15 | #include <unistd.h> | |
aba5acdf SH |
16 | #include <fcntl.h> |
17 | #include <string.h> | |
18 | #include <sys/time.h> | |
aba5acdf SH |
19 | #include <sys/socket.h> |
20 | #include <netinet/in.h> | |
21 | #include <netinet/ip.h> | |
22 | ||
23 | #include "rt_names.h" | |
24 | #include "utils.h" | |
25 | #include "ip_common.h" | |
26 | ||
27 | #define NUD_VALID (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE|NUD_PROBE|NUD_STALE|NUD_DELAY) | |
66081849 | 28 | #define MAX_ROUNDS 10 |
aba5acdf SH |
29 | |
30 | static struct | |
31 | { | |
32 | int family; | |
56f5daac | 33 | int index; |
aba5acdf SH |
34 | int state; |
35 | int unused_only; | |
36 | inet_prefix pfx; | |
37 | int flushed; | |
38 | char *flushb; | |
39 | int flushp; | |
40 | int flushe; | |
0d238ca2 | 41 | int master; |
aba5acdf SH |
42 | } filter; |
43 | ||
44 | static void usage(void) __attribute__((noreturn)); | |
45 | ||
46 | static void usage(void) | |
47 | { | |
03a0cf20 PS |
48 | fprintf(stderr, "Usage: ip neigh { add | del | change | replace }\n" |
49 | " { ADDR [ lladdr LLADDR ] [ nud STATE ] | proxy ADDR } [ dev DEV ]\n"); | |
5db1adae DA |
50 | fprintf(stderr, " ip neigh { show | flush } [ proxy ] [ to PREFIX ] [ dev DEV ] [ nud STATE ]\n"); |
51 | fprintf(stderr, " [ vrf NAME ]\n\n"); | |
03a0cf20 | 52 | fprintf(stderr, "STATE := { permanent | noarp | stale | reachable | none |\n" |
56f5daac | 53 | " incomplete | delay | probe | failed }\n"); |
aba5acdf SH |
54 | exit(-1); |
55 | } | |
56 | ||
56f5daac | 57 | static int nud_state_a2n(unsigned int *state, const char *arg) |
aba5acdf SH |
58 | { |
59 | if (matches(arg, "permanent") == 0) | |
60 | *state = NUD_PERMANENT; | |
61 | else if (matches(arg, "reachable") == 0) | |
62 | *state = NUD_REACHABLE; | |
63 | else if (strcmp(arg, "noarp") == 0) | |
64 | *state = NUD_NOARP; | |
65 | else if (strcmp(arg, "none") == 0) | |
66 | *state = NUD_NONE; | |
67 | else if (strcmp(arg, "stale") == 0) | |
68 | *state = NUD_STALE; | |
69 | else if (strcmp(arg, "incomplete") == 0) | |
70 | *state = NUD_INCOMPLETE; | |
71 | else if (strcmp(arg, "delay") == 0) | |
72 | *state = NUD_DELAY; | |
73 | else if (strcmp(arg, "probe") == 0) | |
74 | *state = NUD_PROBE; | |
75 | else if (matches(arg, "failed") == 0) | |
76 | *state = NUD_FAILED; | |
77 | else { | |
78 | if (get_unsigned(state, arg, 0)) | |
79 | return -1; | |
56f5daac | 80 | if (*state >= 0x100 || (*state&((*state)-1))) |
aba5acdf SH |
81 | return -1; |
82 | } | |
83 | return 0; | |
84 | } | |
85 | ||
aba5acdf SH |
86 | static int flush_update(void) |
87 | { | |
f31a37f7 | 88 | if (rtnl_send_check(&rth, filter.flushb, filter.flushp) < 0) { |
1fb0a998 | 89 | perror("Failed to send flush request"); |
aba5acdf SH |
90 | return -1; |
91 | } | |
92 | filter.flushp = 0; | |
93 | return 0; | |
94 | } | |
95 | ||
96 | ||
97 | static int ipneigh_modify(int cmd, int flags, int argc, char **argv) | |
98 | { | |
aba5acdf | 99 | struct { |
4806867a SH |
100 | struct nlmsghdr n; |
101 | struct ndmsg ndm; | |
56f5daac | 102 | char buf[256]; |
d17b136f PS |
103 | } req = { |
104 | .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)), | |
105 | .n.nlmsg_flags = NLM_F_REQUEST | flags, | |
106 | .n.nlmsg_type = cmd, | |
107 | .ndm.ndm_family = preferred_family, | |
108 | .ndm.ndm_state = NUD_PERMANENT, | |
109 | }; | |
e834eb8e | 110 | char *dev = NULL; |
aba5acdf | 111 | int dst_ok = 0; |
e834eb8e | 112 | int dev_ok = 0; |
aba5acdf | 113 | int lladdr_ok = 0; |
56f5daac | 114 | char *lla = NULL; |
aba5acdf SH |
115 | inet_prefix dst; |
116 | ||
aba5acdf SH |
117 | while (argc > 0) { |
118 | if (matches(*argv, "lladdr") == 0) { | |
119 | NEXT_ARG(); | |
120 | if (lladdr_ok) | |
121 | duparg("lladdr", *argv); | |
122 | lla = *argv; | |
123 | lladdr_ok = 1; | |
124 | } else if (strcmp(*argv, "nud") == 0) { | |
56f5daac SH |
125 | unsigned int state; |
126 | ||
aba5acdf SH |
127 | NEXT_ARG(); |
128 | if (nud_state_a2n(&state, *argv)) | |
129 | invarg("nud state is bad", *argv); | |
130 | req.ndm.ndm_state = state; | |
131 | } else if (matches(*argv, "proxy") == 0) { | |
132 | NEXT_ARG(); | |
133 | if (matches(*argv, "help") == 0) | |
134 | usage(); | |
135 | if (dst_ok) | |
136 | duparg("address", *argv); | |
137 | get_addr(&dst, *argv, preferred_family); | |
138 | dst_ok = 1; | |
e834eb8e | 139 | dev_ok = 1; |
aba5acdf SH |
140 | req.ndm.ndm_flags |= NTF_PROXY; |
141 | } else if (strcmp(*argv, "dev") == 0) { | |
142 | NEXT_ARG(); | |
e834eb8e KK |
143 | dev = *argv; |
144 | dev_ok = 1; | |
aba5acdf SH |
145 | } else { |
146 | if (strcmp(*argv, "to") == 0) { | |
147 | NEXT_ARG(); | |
148 | } | |
149 | if (matches(*argv, "help") == 0) { | |
150 | NEXT_ARG(); | |
151 | } | |
152 | if (dst_ok) | |
153 | duparg2("to", *argv); | |
154 | get_addr(&dst, *argv, preferred_family); | |
155 | dst_ok = 1; | |
156 | } | |
157 | argc--; argv++; | |
158 | } | |
e834eb8e | 159 | if (!dev_ok || !dst_ok || dst.family == AF_UNSPEC) { |
aba5acdf SH |
160 | fprintf(stderr, "Device and destination are required arguments.\n"); |
161 | exit(-1); | |
162 | } | |
163 | req.ndm.ndm_family = dst.family; | |
542b0cc7 SH |
164 | if (addattr_l(&req.n, sizeof(req), NDA_DST, &dst.data, dst.bytelen) < 0) |
165 | return -1; | |
aba5acdf SH |
166 | |
167 | if (lla && strcmp(lla, "null")) { | |
7b565754 | 168 | char llabuf[20]; |
aba5acdf SH |
169 | int l; |
170 | ||
171 | l = ll_addr_a2n(llabuf, sizeof(llabuf), lla); | |
542b0cc7 SH |
172 | if (l < 0) |
173 | return -1; | |
174 | ||
175 | if (addattr_l(&req.n, sizeof(req), NDA_LLADDR, llabuf, l) < 0) | |
176 | return -1; | |
aba5acdf SH |
177 | } |
178 | ||
aba5acdf SH |
179 | ll_init_map(&rth); |
180 | ||
e834eb8e KK |
181 | if (dev && (req.ndm.ndm_ifindex = ll_name_to_index(dev)) == 0) { |
182 | fprintf(stderr, "Cannot find device \"%s\"\n", dev); | |
aba5acdf SH |
183 | return -1; |
184 | } | |
185 | ||
86bf43c7 | 186 | if (rtnl_talk(&rth, &req.n, NULL) < 0) |
aba5acdf SH |
187 | exit(2); |
188 | ||
351efcde | 189 | return 0; |
aba5acdf SH |
190 | } |
191 | ||
192 | ||
50772dc5 | 193 | int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) |
aba5acdf | 194 | { |
56f5daac | 195 | FILE *fp = (FILE *)arg; |
aba5acdf SH |
196 | struct ndmsg *r = NLMSG_DATA(n); |
197 | int len = n->nlmsg_len; | |
56f5daac | 198 | struct rtattr *tb[NDA_MAX+1]; |
0d238ca2 | 199 | static int logit = 1; |
aba5acdf | 200 | |
1556e29d DS |
201 | if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH && |
202 | n->nlmsg_type != RTM_GETNEIGH) { | |
aba5acdf SH |
203 | fprintf(stderr, "Not RTM_NEWNEIGH: %08x %08x %08x\n", |
204 | n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); | |
ae665a52 | 205 | |
aba5acdf SH |
206 | return 0; |
207 | } | |
208 | len -= NLMSG_LENGTH(sizeof(*r)); | |
209 | if (len < 0) { | |
210 | fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); | |
211 | return -1; | |
212 | } | |
213 | ||
214 | if (filter.flushb && n->nlmsg_type != RTM_NEWNEIGH) | |
215 | return 0; | |
216 | ||
217 | if (filter.family && filter.family != r->ndm_family) | |
218 | return 0; | |
219 | if (filter.index && filter.index != r->ndm_ifindex) | |
220 | return 0; | |
221 | if (!(filter.state&r->ndm_state) && | |
1dac7817 | 222 | !(r->ndm_flags & NTF_PROXY) && |
aba5acdf | 223 | (r->ndm_state || !(filter.state&0x100)) && |
56f5daac | 224 | (r->ndm_family != AF_DECnet)) |
aba5acdf SH |
225 | return 0; |
226 | ||
0d238ca2 DA |
227 | if (filter.master && !(n->nlmsg_flags & NLM_F_DUMP_FILTERED)) { |
228 | if (logit) { | |
229 | logit = 0; | |
230 | fprintf(fp, | |
231 | "\nWARNING: Kernel does not support filtering by master device\n\n"); | |
232 | } | |
233 | } | |
234 | ||
aba5acdf SH |
235 | parse_rtattr(tb, NDA_MAX, NDA_RTA(r), n->nlmsg_len - NLMSG_LENGTH(sizeof(*r))); |
236 | ||
237 | if (tb[NDA_DST]) { | |
238 | if (filter.pfx.family) { | |
d17b136f | 239 | inet_prefix dst = { .family = r->ndm_family }; |
56f5daac | 240 | |
aba5acdf SH |
241 | memcpy(&dst.data, RTA_DATA(tb[NDA_DST]), RTA_PAYLOAD(tb[NDA_DST])); |
242 | if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen)) | |
243 | return 0; | |
244 | } | |
245 | } | |
246 | if (filter.unused_only && tb[NDA_CACHEINFO]) { | |
247 | struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]); | |
56f5daac | 248 | |
aba5acdf SH |
249 | if (ci->ndm_refcnt) |
250 | return 0; | |
251 | } | |
252 | ||
253 | if (filter.flushb) { | |
254 | struct nlmsghdr *fn; | |
56f5daac | 255 | |
aba5acdf SH |
256 | if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) { |
257 | if (flush_update()) | |
258 | return -1; | |
259 | } | |
56f5daac | 260 | fn = (struct nlmsghdr *)(filter.flushb + NLMSG_ALIGN(filter.flushp)); |
aba5acdf SH |
261 | memcpy(fn, n, n->nlmsg_len); |
262 | fn->nlmsg_type = RTM_DELNEIGH; | |
263 | fn->nlmsg_flags = NLM_F_REQUEST; | |
351efcde | 264 | fn->nlmsg_seq = ++rth.seq; |
56f5daac | 265 | filter.flushp = (((char *)fn) + n->nlmsg_len) - filter.flushb; |
aba5acdf SH |
266 | filter.flushed++; |
267 | if (show_stats < 2) | |
268 | return 0; | |
269 | } | |
270 | ||
6ea3ebaf | 271 | if (n->nlmsg_type == RTM_DELNEIGH) |
39ca4879 | 272 | fprintf(fp, "Deleted "); |
1556e29d DS |
273 | else if (n->nlmsg_type == RTM_GETNEIGH) |
274 | fprintf(fp, "miss "); | |
aba5acdf | 275 | if (tb[NDA_DST]) { |
ae665a52 | 276 | fprintf(fp, "%s ", |
d49f934c | 277 | format_host_rta(r->ndm_family, tb[NDA_DST])); |
aba5acdf SH |
278 | } |
279 | if (!filter.index && r->ndm_ifindex) | |
280 | fprintf(fp, "dev %s ", ll_index_to_name(r->ndm_ifindex)); | |
281 | if (tb[NDA_LLADDR]) { | |
282 | SPRINT_BUF(b1); | |
283 | fprintf(fp, "lladdr %s", ll_addr_n2a(RTA_DATA(tb[NDA_LLADDR]), | |
284 | RTA_PAYLOAD(tb[NDA_LLADDR]), | |
285 | ll_index_to_type(r->ndm_ifindex), | |
286 | b1, sizeof(b1))); | |
287 | } | |
288 | if (r->ndm_flags & NTF_ROUTER) { | |
289 | fprintf(fp, " router"); | |
290 | } | |
1dac7817 TZ |
291 | if (r->ndm_flags & NTF_PROXY) { |
292 | fprintf(fp, " proxy"); | |
293 | } | |
aba5acdf | 294 | if (tb[NDA_CACHEINFO] && show_stats) { |
aba5acdf | 295 | struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]); |
6a34d291 SH |
296 | int hz = get_user_hz(); |
297 | ||
aba5acdf SH |
298 | if (ci->ndm_refcnt) |
299 | printf(" ref %d", ci->ndm_refcnt); | |
300 | fprintf(fp, " used %d/%d/%d", ci->ndm_used/hz, | |
301 | ci->ndm_confirmed/hz, ci->ndm_updated/hz); | |
302 | } | |
303 | ||
69410a49 | 304 | if (tb[NDA_PROBES] && show_stats) { |
ff24746c | 305 | __u32 p = rta_getattr_u32(tb[NDA_PROBES]); |
56f5daac | 306 | |
69410a49 | 307 | fprintf(fp, " probes %u", p); |
308 | } | |
309 | ||
aba5acdf | 310 | if (r->ndm_state) { |
435ac6b8 | 311 | int nud = r->ndm_state; |
56f5daac | 312 | |
435ac6b8 | 313 | fprintf(fp, " "); |
314 | ||
315 | #define PRINT_FLAG(f) if (nud & NUD_##f) { \ | |
316 | nud &= ~NUD_##f; fprintf(fp, #f "%s", nud ? "," : ""); } | |
317 | PRINT_FLAG(INCOMPLETE); | |
318 | PRINT_FLAG(REACHABLE); | |
319 | PRINT_FLAG(STALE); | |
320 | PRINT_FLAG(DELAY); | |
321 | PRINT_FLAG(PROBE); | |
322 | PRINT_FLAG(FAILED); | |
323 | PRINT_FLAG(NOARP); | |
324 | PRINT_FLAG(PERMANENT); | |
325 | #undef PRINT_FLAG | |
aba5acdf SH |
326 | } |
327 | fprintf(fp, "\n"); | |
328 | ||
329 | fflush(fp); | |
330 | return 0; | |
331 | } | |
332 | ||
093b7646 | 333 | void ipneigh_reset_filter(int ifindex) |
aba5acdf SH |
334 | { |
335 | memset(&filter, 0, sizeof(filter)); | |
336 | filter.state = ~0; | |
093b7646 | 337 | filter.index = ifindex; |
aba5acdf SH |
338 | } |
339 | ||
d1f28cf1 | 340 | static int do_show_or_flush(int argc, char **argv, int flush) |
aba5acdf | 341 | { |
0d238ca2 DA |
342 | struct { |
343 | struct nlmsghdr n; | |
344 | struct ndmsg ndm; | |
56f5daac | 345 | char buf[256]; |
d17b136f PS |
346 | } req = { |
347 | .n.nlmsg_type = RTM_GETNEIGH, | |
348 | .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)), | |
349 | }; | |
aba5acdf | 350 | char *filter_dev = NULL; |
aba5acdf | 351 | int state_given = 0; |
0d238ca2 | 352 | |
093b7646 | 353 | ipneigh_reset_filter(0); |
aba5acdf SH |
354 | |
355 | if (!filter.family) | |
356 | filter.family = preferred_family; | |
357 | ||
358 | if (flush) { | |
359 | if (argc <= 0) { | |
360 | fprintf(stderr, "Flush requires arguments.\n"); | |
361 | return -1; | |
362 | } | |
363 | filter.state = ~(NUD_PERMANENT|NUD_NOARP); | |
364 | } else | |
365 | filter.state = 0xFF & ~NUD_NOARP; | |
366 | ||
367 | while (argc > 0) { | |
368 | if (strcmp(*argv, "dev") == 0) { | |
369 | NEXT_ARG(); | |
370 | if (filter_dev) | |
371 | duparg("dev", *argv); | |
372 | filter_dev = *argv; | |
0d238ca2 DA |
373 | } else if (strcmp(*argv, "master") == 0) { |
374 | int ifindex; | |
56f5daac | 375 | |
0d238ca2 DA |
376 | NEXT_ARG(); |
377 | ifindex = ll_name_to_index(*argv); | |
378 | if (!ifindex) | |
379 | invarg("Device does not exist\n", *argv); | |
380 | addattr32(&req.n, sizeof(req), NDA_MASTER, ifindex); | |
381 | filter.master = ifindex; | |
5db1adae DA |
382 | } else if (strcmp(*argv, "vrf") == 0) { |
383 | int ifindex; | |
384 | ||
385 | NEXT_ARG(); | |
386 | ifindex = ll_name_to_index(*argv); | |
387 | if (!ifindex) | |
388 | invarg("Not a valid VRF name\n", *argv); | |
389 | if (!name_is_vrf(*argv)) | |
390 | invarg("Not a valid VRF name\n", *argv); | |
391 | addattr32(&req.n, sizeof(req), NDA_MASTER, ifindex); | |
392 | filter.master = ifindex; | |
aba5acdf SH |
393 | } else if (strcmp(*argv, "unused") == 0) { |
394 | filter.unused_only = 1; | |
395 | } else if (strcmp(*argv, "nud") == 0) { | |
56f5daac SH |
396 | unsigned int state; |
397 | ||
aba5acdf SH |
398 | NEXT_ARG(); |
399 | if (!state_given) { | |
400 | state_given = 1; | |
401 | filter.state = 0; | |
402 | } | |
403 | if (nud_state_a2n(&state, *argv)) { | |
404 | if (strcmp(*argv, "all") != 0) | |
405 | invarg("nud state is bad", *argv); | |
406 | state = ~0; | |
407 | if (flush) | |
408 | state &= ~NUD_NOARP; | |
409 | } | |
410 | if (state == 0) | |
411 | state = 0x100; | |
412 | filter.state |= state; | |
1dac7817 | 413 | } else if (strcmp(*argv, "proxy") == 0) |
0d238ca2 | 414 | req.ndm.ndm_flags = NTF_PROXY; |
1dac7817 | 415 | else { |
aba5acdf SH |
416 | if (strcmp(*argv, "to") == 0) { |
417 | NEXT_ARG(); | |
418 | } | |
419 | if (matches(*argv, "help") == 0) | |
420 | usage(); | |
421 | get_prefix(&filter.pfx, *argv, filter.family); | |
422 | if (filter.family == AF_UNSPEC) | |
423 | filter.family = filter.pfx.family; | |
424 | } | |
425 | argc--; argv++; | |
426 | } | |
427 | ||
aba5acdf SH |
428 | ll_init_map(&rth); |
429 | ||
430 | if (filter_dev) { | |
431 | if ((filter.index = ll_name_to_index(filter_dev)) == 0) { | |
432 | fprintf(stderr, "Cannot find device \"%s\"\n", filter_dev); | |
433 | return -1; | |
434 | } | |
b8c75324 | 435 | addattr32(&req.n, sizeof(req), NDA_IFINDEX, filter.index); |
aba5acdf SH |
436 | } |
437 | ||
1c346dcc JH |
438 | req.ndm.ndm_family = filter.family; |
439 | ||
aba5acdf SH |
440 | if (flush) { |
441 | int round = 0; | |
442 | char flushb[4096-512]; | |
443 | ||
444 | filter.flushb = flushb; | |
445 | filter.flushp = 0; | |
446 | filter.flushe = sizeof(flushb); | |
aba5acdf | 447 | |
66081849 | 448 | while (round < MAX_ROUNDS) { |
1c346dcc | 449 | if (rtnl_dump_request_n(&rth, &req.n) < 0) { |
aba5acdf SH |
450 | perror("Cannot send dump request"); |
451 | exit(1); | |
452 | } | |
453 | filter.flushed = 0; | |
cd70f3f5 | 454 | if (rtnl_dump_filter(&rth, print_neigh, stdout) < 0) { |
aba5acdf SH |
455 | fprintf(stderr, "Flush terminated\n"); |
456 | exit(1); | |
457 | } | |
458 | if (filter.flushed == 0) { | |
f0b34d2d AH |
459 | if (show_stats) { |
460 | if (round == 0) | |
461 | printf("Nothing to flush.\n"); | |
462 | else | |
56f5daac | 463 | printf("*** Flush is complete after %d round%s ***\n", round, round > 1?"s":""); |
f0b34d2d | 464 | } |
aba5acdf SH |
465 | fflush(stdout); |
466 | return 0; | |
467 | } | |
468 | round++; | |
469 | if (flush_update() < 0) | |
470 | exit(1); | |
471 | if (show_stats) { | |
472 | printf("\n*** Round %d, deleting %d entries ***\n", round, filter.flushed); | |
473 | fflush(stdout); | |
474 | } | |
ad0a6a2c | 475 | filter.state &= ~NUD_FAILED; |
aba5acdf | 476 | } |
66081849 SH |
477 | printf("*** Flush not complete bailing out after %d rounds\n", |
478 | MAX_ROUNDS); | |
479 | return 1; | |
aba5acdf SH |
480 | } |
481 | ||
0d238ca2 | 482 | if (rtnl_dump_request_n(&rth, &req.n) < 0) { |
aba5acdf SH |
483 | perror("Cannot send dump request"); |
484 | exit(1); | |
485 | } | |
486 | ||
cd70f3f5 | 487 | if (rtnl_dump_filter(&rth, print_neigh, stdout) < 0) { |
aba5acdf SH |
488 | fprintf(stderr, "Dump terminated\n"); |
489 | exit(1); | |
490 | } | |
491 | ||
492 | return 0; | |
493 | } | |
494 | ||
495 | int do_ipneigh(int argc, char **argv) | |
496 | { | |
497 | if (argc > 0) { | |
498 | if (matches(*argv, "add") == 0) | |
499 | return ipneigh_modify(RTM_NEWNEIGH, NLM_F_CREATE|NLM_F_EXCL, argc-1, argv+1); | |
500 | if (matches(*argv, "change") == 0 || | |
501 | strcmp(*argv, "chg") == 0) | |
502 | return ipneigh_modify(RTM_NEWNEIGH, NLM_F_REPLACE, argc-1, argv+1); | |
503 | if (matches(*argv, "replace") == 0) | |
504 | return ipneigh_modify(RTM_NEWNEIGH, NLM_F_CREATE|NLM_F_REPLACE, argc-1, argv+1); | |
505 | if (matches(*argv, "delete") == 0) | |
506 | return ipneigh_modify(RTM_DELNEIGH, 0, argc-1, argv+1); | |
507 | if (matches(*argv, "get") == 0) { | |
508 | fprintf(stderr, "Sorry, \"neigh get\" is not implemented :-(\n"); | |
509 | return -1; | |
510 | } | |
511 | if (matches(*argv, "show") == 0 || | |
512 | matches(*argv, "lst") == 0 || | |
513 | matches(*argv, "list") == 0) | |
514 | return do_show_or_flush(argc-1, argv+1, 0); | |
515 | if (matches(*argv, "flush") == 0) | |
516 | return do_show_or_flush(argc-1, argv+1, 1); | |
517 | if (matches(*argv, "help") == 0) | |
518 | usage(); | |
519 | } else | |
520 | return do_show_or_flush(0, NULL, 0); | |
521 | ||
522 | fprintf(stderr, "Command \"%s\" is unknown, try \"ip neigh help\".\n", *argv); | |
523 | exit(-1); | |
524 | } |