]>
Commit | Line | Data |
---|---|---|
d04bc300 SH |
1 | /* |
2 | * Get/set/delete fdb table with netlink | |
3 | * | |
0849e60a SH |
4 | * TODO: merge/replace this with ip neighbour |
5 | * | |
d04bc300 SH |
6 | * Authors: Stephen Hemminger <shemminger@vyatta.com> |
7 | */ | |
8 | ||
9 | #include <stdio.h> | |
10 | #include <stdlib.h> | |
11 | #include <unistd.h> | |
5f409678 | 12 | #include <netdb.h> |
d04bc300 SH |
13 | #include <time.h> |
14 | #include <fcntl.h> | |
15 | #include <sys/socket.h> | |
16 | #include <sys/time.h> | |
17 | #include <net/if.h> | |
18 | #include <netinet/in.h> | |
19 | #include <linux/if_bridge.h> | |
20 | #include <linux/if_ether.h> | |
21 | #include <linux/neighbour.h> | |
22 | #include <string.h> | |
dd9cc0ee | 23 | #include <limits.h> |
b239c56e AK |
24 | #include <json_writer.h> |
25 | #include <stdbool.h> | |
d04bc300 SH |
26 | |
27 | #include "libnetlink.h" | |
28 | #include "br_common.h" | |
0849e60a | 29 | #include "rt_names.h" |
d04bc300 SH |
30 | #include "utils.h" |
31 | ||
ae6eb907 | 32 | static unsigned int filter_index, filter_vlan; |
d04bc300 | 33 | |
b239c56e AK |
34 | json_writer_t *jw_global; |
35 | ||
d04bc300 SH |
36 | static void usage(void) |
37 | { | |
bd5bbad4 | 38 | fprintf(stderr, "Usage: bridge fdb { add | append | del | replace } ADDR dev DEV\n" |
cd8df30b | 39 | " [ self ] [ master ] [ use ] [ router ]\n" |
c6d0cfb5 | 40 | " [ local | static | dynamic ] [ dst IPADDR ] [ vlan VID ]\n" |
df4b043f | 41 | " [ port PORT] [ vni VNI ] [ via DEV ]\n"); |
ae6eb907 | 42 | fprintf(stderr, " bridge fdb [ show [ br BRDEV ] [ brport DEV ] [ vlan VID ] ]\n"); |
d04bc300 SH |
43 | exit(-1); |
44 | } | |
45 | ||
df4b043f | 46 | static const char *state_n2a(unsigned int s) |
d04bc300 SH |
47 | { |
48 | static char buf[32]; | |
49 | ||
0849e60a SH |
50 | if (s & NUD_PERMANENT) |
51 | return "permanent"; | |
d04bc300 SH |
52 | |
53 | if (s & NUD_NOARP) | |
54 | return "static"; | |
55 | ||
56 | if (s & NUD_STALE) | |
57 | return "stale"; | |
0849e60a | 58 | |
d04bc300 SH |
59 | if (s & NUD_REACHABLE) |
60 | return ""; | |
61 | ||
62 | sprintf(buf, "state=%#x", s); | |
63 | return buf; | |
64 | } | |
65 | ||
b239c56e AK |
66 | static void start_json_fdb_flags_array(bool *fdb_flags) |
67 | { | |
68 | if (*fdb_flags) | |
69 | return; | |
70 | jsonw_name(jw_global, "flags"); | |
71 | jsonw_start_array(jw_global); | |
72 | *fdb_flags = true; | |
73 | } | |
74 | ||
d04bc300 SH |
75 | int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) |
76 | { | |
0849e60a | 77 | FILE *fp = arg; |
d04bc300 SH |
78 | struct ndmsg *r = NLMSG_DATA(n); |
79 | int len = n->nlmsg_len; | |
df4b043f | 80 | struct rtattr *tb[NDA_MAX+1]; |
ae6eb907 | 81 | __u16 vid = 0; |
b239c56e AK |
82 | bool fdb_flags = false; |
83 | const char *state_s; | |
0849e60a SH |
84 | |
85 | if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH) { | |
86 | fprintf(stderr, "Not RTM_NEWNEIGH: %08x %08x %08x\n", | |
87 | n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); | |
0849e60a SH |
88 | return 0; |
89 | } | |
d04bc300 SH |
90 | |
91 | len -= NLMSG_LENGTH(sizeof(*r)); | |
92 | if (len < 0) { | |
93 | fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); | |
94 | return -1; | |
95 | } | |
96 | ||
97 | if (r->ndm_family != AF_BRIDGE) | |
98 | return 0; | |
99 | ||
100 | if (filter_index && filter_index != r->ndm_ifindex) | |
101 | return 0; | |
102 | ||
b239c56e AK |
103 | if (jw_global) { |
104 | jsonw_pretty(jw_global, 1); | |
105 | jsonw_start_object(jw_global); | |
106 | } | |
107 | ||
d04bc300 SH |
108 | parse_rtattr(tb, NDA_MAX, NDA_RTA(r), |
109 | n->nlmsg_len - NLMSG_LENGTH(sizeof(*r))); | |
110 | ||
ae6eb907 NA |
111 | if (tb[NDA_VLAN]) |
112 | vid = rta_getattr_u16(tb[NDA_VLAN]); | |
113 | ||
114 | if (filter_vlan && filter_vlan != vid) | |
115 | return 0; | |
116 | ||
b239c56e AK |
117 | if (n->nlmsg_type == RTM_DELNEIGH) { |
118 | if (jw_global) | |
119 | jsonw_string_field(jw_global, "opCode", "deleted"); | |
120 | else | |
121 | fprintf(fp, "Deleted "); | |
122 | } | |
0849e60a SH |
123 | |
124 | if (tb[NDA_LLADDR]) { | |
125 | SPRINT_BUF(b1); | |
b239c56e AK |
126 | ll_addr_n2a(RTA_DATA(tb[NDA_LLADDR]), |
127 | RTA_PAYLOAD(tb[NDA_LLADDR]), | |
128 | ll_index_to_type(r->ndm_ifindex), | |
129 | b1, sizeof(b1)); | |
130 | if (jw_global) | |
131 | jsonw_string_field(jw_global, "mac", b1); | |
132 | else | |
133 | fprintf(fp, "%s ", b1); | |
d04bc300 | 134 | } |
38df7ac9 | 135 | |
b239c56e AK |
136 | if (!filter_index && r->ndm_ifindex) { |
137 | if (jw_global) | |
138 | jsonw_string_field(jw_global, "dev", | |
139 | ll_index_to_name(r->ndm_ifindex)); | |
140 | else | |
141 | fprintf(fp, "dev %s ", | |
142 | ll_index_to_name(r->ndm_ifindex)); | |
143 | } | |
0849e60a SH |
144 | |
145 | if (tb[NDA_DST]) { | |
9e763fa5 | 146 | int family = AF_INET; |
b239c56e | 147 | const char *abuf_s; |
9e763fa5 MR |
148 | |
149 | if (RTA_PAYLOAD(tb[NDA_DST]) == sizeof(struct in6_addr)) | |
150 | family = AF_INET6; | |
151 | ||
b239c56e AK |
152 | abuf_s = format_host(family, |
153 | RTA_PAYLOAD(tb[NDA_DST]), | |
154 | RTA_DATA(tb[NDA_DST])); | |
155 | if (jw_global) | |
156 | jsonw_string_field(jw_global, "dst", abuf_s); | |
157 | else | |
158 | fprintf(fp, "dst %s ", abuf_s); | |
159 | } | |
160 | ||
161 | if (vid) { | |
162 | if (jw_global) | |
163 | jsonw_uint_field(jw_global, "vlan", vid); | |
164 | else | |
165 | fprintf(fp, "vlan %hu ", vid); | |
166 | } | |
167 | ||
168 | if (tb[NDA_PORT]) { | |
169 | if (jw_global) | |
170 | jsonw_uint_field(jw_global, "port", | |
171 | ntohs(rta_getattr_u16(tb[NDA_PORT]))); | |
172 | else | |
173 | fprintf(fp, "port %d ", | |
174 | ntohs(rta_getattr_u16(tb[NDA_PORT]))); | |
0849e60a | 175 | } |
38df7ac9 | 176 | |
b239c56e AK |
177 | if (tb[NDA_VNI]) { |
178 | if (jw_global) | |
179 | jsonw_uint_field(jw_global, "vni", | |
180 | rta_getattr_u32(tb[NDA_VNI])); | |
181 | else | |
182 | fprintf(fp, "vni %d ", | |
183 | rta_getattr_u32(tb[NDA_VNI])); | |
184 | } | |
fd08839c | 185 | |
5f409678 DS |
186 | if (tb[NDA_IFINDEX]) { |
187 | unsigned int ifindex = rta_getattr_u32(tb[NDA_IFINDEX]); | |
188 | ||
189 | if (ifindex) { | |
190 | char ifname[IF_NAMESIZE]; | |
191 | ||
a4797670 | 192 | if (!tb[NDA_LINK_NETNSID] && |
b239c56e AK |
193 | if_indextoname(ifindex, ifname)) { |
194 | if (jw_global) | |
195 | jsonw_string_field(jw_global, "viaIf", | |
196 | ifname); | |
197 | else | |
198 | fprintf(fp, "via %s ", ifname); | |
199 | } else { | |
200 | if (jw_global) | |
201 | jsonw_uint_field(jw_global, "viaIfIndex", | |
202 | ifindex); | |
203 | else | |
204 | fprintf(fp, "via ifindex %u ", ifindex); | |
205 | } | |
5f409678 DS |
206 | } |
207 | } | |
b239c56e AK |
208 | |
209 | if (tb[NDA_LINK_NETNSID]) { | |
210 | if (jw_global) | |
211 | jsonw_uint_field(jw_global, "linkNetNsId", | |
212 | rta_getattr_u32(tb[NDA_LINK_NETNSID])); | |
213 | else | |
214 | fprintf(fp, "link-netnsid %d ", | |
215 | rta_getattr_u32(tb[NDA_LINK_NETNSID])); | |
216 | } | |
5f409678 | 217 | |
d04bc300 SH |
218 | if (show_stats && tb[NDA_CACHEINFO]) { |
219 | struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]); | |
0849e60a | 220 | int hz = get_user_hz(); |
d04bc300 | 221 | |
b239c56e AK |
222 | if (jw_global) { |
223 | jsonw_uint_field(jw_global, "used", | |
224 | ci->ndm_used/hz); | |
225 | jsonw_uint_field(jw_global, "updated", | |
226 | ci->ndm_updated/hz); | |
227 | } else { | |
228 | fprintf(fp, "used %d/%d ", ci->ndm_used/hz, | |
229 | ci->ndm_updated/hz); | |
230 | } | |
231 | } | |
232 | ||
233 | if (jw_global) { | |
234 | if (r->ndm_flags & NTF_SELF) { | |
235 | start_json_fdb_flags_array(&fdb_flags); | |
236 | jsonw_string(jw_global, "self"); | |
237 | } | |
238 | if (r->ndm_flags & NTF_ROUTER) { | |
239 | start_json_fdb_flags_array(&fdb_flags); | |
240 | jsonw_string(jw_global, "router"); | |
241 | } | |
242 | if (r->ndm_flags & NTF_EXT_LEARNED) { | |
243 | start_json_fdb_flags_array(&fdb_flags); | |
244 | jsonw_string(jw_global, "offload"); | |
245 | } | |
246 | if (r->ndm_flags & NTF_MASTER) | |
247 | jsonw_string(jw_global, "master"); | |
248 | if (fdb_flags) | |
249 | jsonw_end_array(jw_global); | |
250 | ||
251 | if (tb[NDA_MASTER]) | |
252 | jsonw_string_field(jw_global, | |
253 | "master", | |
254 | ll_index_to_name(rta_getattr_u32(tb[NDA_MASTER]))); | |
255 | ||
256 | } else { | |
257 | if (r->ndm_flags & NTF_SELF) | |
258 | fprintf(fp, "self "); | |
259 | if (r->ndm_flags & NTF_ROUTER) | |
260 | fprintf(fp, "router "); | |
261 | if (r->ndm_flags & NTF_EXT_LEARNED) | |
262 | fprintf(fp, "offload "); | |
263 | if (tb[NDA_MASTER]) { | |
264 | fprintf(fp, "master %s ", | |
265 | ll_index_to_name(rta_getattr_u32(tb[NDA_MASTER]))); | |
266 | } else if (r->ndm_flags & NTF_MASTER) { | |
267 | fprintf(fp, "master "); | |
268 | } | |
269 | } | |
270 | ||
271 | state_s = state_n2a(r->ndm_state); | |
272 | if (jw_global) { | |
273 | if (state_s[0]) | |
274 | jsonw_string_field(jw_global, "state", state_s); | |
275 | ||
276 | jsonw_end_object(jw_global); | |
277 | } else { | |
278 | fprintf(fp, "%s\n", state_s); | |
279 | ||
280 | fflush(fp); | |
d04bc300 | 281 | } |
4d45bf3b | 282 | |
d04bc300 SH |
283 | return 0; |
284 | } | |
285 | ||
286 | static int fdb_show(int argc, char **argv) | |
287 | { | |
aeb14eb0 | 288 | struct { |
df4b043f | 289 | struct nlmsghdr n; |
aeb14eb0 | 290 | struct ifinfomsg ifm; |
df4b043f | 291 | char buf[256]; |
aeb14eb0 JHS |
292 | } req; |
293 | ||
d04bc300 | 294 | char *filter_dev = NULL; |
aeb14eb0 JHS |
295 | char *br = NULL; |
296 | int msg_size = sizeof(struct ifinfomsg); | |
297 | ||
298 | memset(&req, 0, sizeof(req)); | |
299 | req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); | |
300 | req.ifm.ifi_family = PF_BRIDGE; | |
0849e60a | 301 | |
d04bc300 | 302 | while (argc > 0) { |
aeb14eb0 | 303 | if ((strcmp(*argv, "brport") == 0) || strcmp(*argv, "dev") == 0) { |
d04bc300 | 304 | NEXT_ARG(); |
d04bc300 | 305 | filter_dev = *argv; |
aeb14eb0 JHS |
306 | } else if (strcmp(*argv, "br") == 0) { |
307 | NEXT_ARG(); | |
308 | br = *argv; | |
ae6eb907 NA |
309 | } else if (strcmp(*argv, "vlan") == 0) { |
310 | NEXT_ARG(); | |
311 | if (filter_vlan) | |
312 | duparg("vlan", *argv); | |
313 | filter_vlan = atoi(*argv); | |
aeb14eb0 JHS |
314 | } else { |
315 | if (matches(*argv, "help") == 0) | |
316 | usage(); | |
d04bc300 SH |
317 | } |
318 | argc--; argv++; | |
319 | } | |
320 | ||
aeb14eb0 JHS |
321 | if (br) { |
322 | int br_ifindex = ll_name_to_index(br); | |
df4b043f | 323 | |
aeb14eb0 JHS |
324 | if (br_ifindex == 0) { |
325 | fprintf(stderr, "Cannot find bridge device \"%s\"\n", br); | |
326 | return -1; | |
327 | } | |
328 | addattr32(&req.n, sizeof(req), IFLA_MASTER, br_ifindex); | |
329 | msg_size += RTA_LENGTH(4); | |
330 | } | |
331 | ||
332 | /*we'll keep around filter_dev for older kernels */ | |
d04bc300 | 333 | if (filter_dev) { |
0849e60a SH |
334 | filter_index = if_nametoindex(filter_dev); |
335 | if (filter_index == 0) { | |
336 | fprintf(stderr, "Cannot find device \"%s\"\n", | |
337 | filter_dev); | |
d04bc300 SH |
338 | return -1; |
339 | } | |
aeb14eb0 | 340 | req.ifm.ifi_index = filter_index; |
d04bc300 SH |
341 | } |
342 | ||
aeb14eb0 | 343 | if (rtnl_dump_request(&rth, RTM_GETNEIGH, &req.ifm, msg_size) < 0) { |
d04bc300 SH |
344 | perror("Cannot send dump request"); |
345 | exit(1); | |
346 | } | |
d04bc300 | 347 | |
b239c56e AK |
348 | if (json_output) { |
349 | jw_global = jsonw_new(stdout); | |
350 | if (!jw_global) { | |
351 | fprintf(stderr, "Error allocation json object\n"); | |
352 | exit(1); | |
353 | } | |
354 | jsonw_start_array(jw_global); | |
355 | } | |
0849e60a | 356 | if (rtnl_dump_filter(&rth, print_fdb, stdout) < 0) { |
d04bc300 SH |
357 | fprintf(stderr, "Dump terminated\n"); |
358 | exit(1); | |
359 | } | |
b239c56e AK |
360 | if (jw_global) { |
361 | jsonw_end_array(jw_global); | |
362 | jsonw_destroy(&jw_global); | |
363 | } | |
d04bc300 SH |
364 | |
365 | return 0; | |
366 | } | |
367 | ||
368 | static int fdb_modify(int cmd, int flags, int argc, char **argv) | |
369 | { | |
370 | struct { | |
df4b043f SH |
371 | struct nlmsghdr n; |
372 | struct ndmsg ndm; | |
373 | char buf[256]; | |
d04bc300 SH |
374 | } req; |
375 | char *addr = NULL; | |
376 | char *d = NULL; | |
377 | char abuf[ETH_ALEN]; | |
0849e60a SH |
378 | int dst_ok = 0; |
379 | inet_prefix dst; | |
5f409678 DS |
380 | unsigned long port = 0; |
381 | unsigned long vni = ~0; | |
382 | unsigned int via = 0; | |
383 | char *endptr; | |
fd08839c | 384 | short vid = -1; |
d04bc300 SH |
385 | |
386 | memset(&req, 0, sizeof(req)); | |
387 | ||
388 | req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)); | |
389 | req.n.nlmsg_flags = NLM_F_REQUEST|flags; | |
390 | req.n.nlmsg_type = cmd; | |
391 | req.ndm.ndm_family = PF_BRIDGE; | |
392 | req.ndm.ndm_state = NUD_NOARP; | |
393 | ||
394 | while (argc > 0) { | |
395 | if (strcmp(*argv, "dev") == 0) { | |
396 | NEXT_ARG(); | |
397 | d = *argv; | |
0849e60a SH |
398 | } else if (strcmp(*argv, "dst") == 0) { |
399 | NEXT_ARG(); | |
400 | if (dst_ok) | |
401 | duparg2("dst", *argv); | |
402 | get_addr(&dst, *argv, preferred_family); | |
403 | dst_ok = 1; | |
5f409678 DS |
404 | } else if (strcmp(*argv, "port") == 0) { |
405 | ||
406 | NEXT_ARG(); | |
407 | port = strtoul(*argv, &endptr, 0); | |
408 | if (endptr && *endptr) { | |
409 | struct servent *pse; | |
410 | ||
411 | pse = getservbyname(*argv, "udp"); | |
412 | if (!pse) | |
413 | invarg("invalid port\n", *argv); | |
414 | port = ntohs(pse->s_port); | |
415 | } else if (port > 0xffff) | |
416 | invarg("invalid port\n", *argv); | |
417 | } else if (strcmp(*argv, "vni") == 0) { | |
418 | NEXT_ARG(); | |
419 | vni = strtoul(*argv, &endptr, 0); | |
420 | if ((endptr && *endptr) || | |
421 | (vni >> 24) || vni == ULONG_MAX) | |
422 | invarg("invalid VNI\n", *argv); | |
423 | } else if (strcmp(*argv, "via") == 0) { | |
424 | NEXT_ARG(); | |
425 | via = if_nametoindex(*argv); | |
426 | if (via == 0) | |
427 | invarg("invalid device\n", *argv); | |
dc6a6a25 JF |
428 | } else if (strcmp(*argv, "self") == 0) { |
429 | req.ndm.ndm_flags |= NTF_SELF; | |
0849e60a | 430 | } else if (matches(*argv, "master") == 0) { |
dc6a6a25 | 431 | req.ndm.ndm_flags |= NTF_MASTER; |
5b8a1d4a DS |
432 | } else if (matches(*argv, "router") == 0) { |
433 | req.ndm.ndm_flags |= NTF_ROUTER; | |
e9e9365b | 434 | } else if (matches(*argv, "local") == 0 || |
0849e60a SH |
435 | matches(*argv, "permanent") == 0) { |
436 | req.ndm.ndm_state |= NUD_PERMANENT; | |
a1987cd1 RP |
437 | } else if (matches(*argv, "temp") == 0 || |
438 | matches(*argv, "static") == 0) { | |
0849e60a | 439 | req.ndm.ndm_state |= NUD_REACHABLE; |
c6d0cfb5 RP |
440 | } else if (matches(*argv, "dynamic") == 0) { |
441 | req.ndm.ndm_state |= NUD_REACHABLE; | |
442 | req.ndm.ndm_state &= ~NUD_NOARP; | |
fd08839c VY |
443 | } else if (matches(*argv, "vlan") == 0) { |
444 | if (vid >= 0) | |
445 | duparg2("vlan", *argv); | |
446 | NEXT_ARG(); | |
447 | vid = atoi(*argv); | |
cd8df30b RP |
448 | } else if (matches(*argv, "use") == 0) { |
449 | req.ndm.ndm_flags |= NTF_USE; | |
d04bc300 SH |
450 | } else { |
451 | if (strcmp(*argv, "to") == 0) { | |
452 | NEXT_ARG(); | |
453 | } | |
0849e60a SH |
454 | if (matches(*argv, "help") == 0) |
455 | usage(); | |
d04bc300 SH |
456 | if (addr) |
457 | duparg2("to", *argv); | |
458 | addr = *argv; | |
459 | } | |
460 | argc--; argv++; | |
461 | } | |
462 | ||
463 | if (d == NULL || addr == NULL) { | |
464 | fprintf(stderr, "Device and address are required arguments.\n"); | |
42ecedd4 | 465 | return -1; |
d04bc300 SH |
466 | } |
467 | ||
0849e60a SH |
468 | /* Assume self */ |
469 | if (!(req.ndm.ndm_flags&(NTF_SELF|NTF_MASTER))) | |
470 | req.ndm.ndm_flags |= NTF_SELF; | |
471 | ||
472 | /* Assume permanent */ | |
473 | if (!(req.ndm.ndm_state&(NUD_PERMANENT|NUD_REACHABLE))) | |
474 | req.ndm.ndm_state |= NUD_PERMANENT; | |
475 | ||
476 | if (sscanf(addr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", | |
d04bc300 SH |
477 | abuf, abuf+1, abuf+2, |
478 | abuf+3, abuf+4, abuf+5) != 6) { | |
479 | fprintf(stderr, "Invalid mac address %s\n", addr); | |
42ecedd4 | 480 | return -1; |
d04bc300 SH |
481 | } |
482 | ||
483 | addattr_l(&req.n, sizeof(req), NDA_LLADDR, abuf, ETH_ALEN); | |
0849e60a SH |
484 | if (dst_ok) |
485 | addattr_l(&req.n, sizeof(req), NDA_DST, &dst.data, dst.bytelen); | |
d04bc300 | 486 | |
fd08839c | 487 | if (vid >= 0) |
8ae66094 | 488 | addattr16(&req.n, sizeof(req), NDA_VLAN, vid); |
fd08839c | 489 | |
5f409678 DS |
490 | if (port) { |
491 | unsigned short dport; | |
492 | ||
493 | dport = htons((unsigned short)port); | |
494 | addattr16(&req.n, sizeof(req), NDA_PORT, dport); | |
495 | } | |
496 | if (vni != ~0) | |
497 | addattr32(&req.n, sizeof(req), NDA_VNI, vni); | |
498 | if (via) | |
499 | addattr32(&req.n, sizeof(req), NDA_IFINDEX, via); | |
500 | ||
d04bc300 SH |
501 | req.ndm.ndm_ifindex = ll_name_to_index(d); |
502 | if (req.ndm.ndm_ifindex == 0) { | |
503 | fprintf(stderr, "Cannot find device \"%s\"\n", d); | |
504 | return -1; | |
505 | } | |
506 | ||
c079e121 | 507 | if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) |
42ecedd4 | 508 | return -1; |
d04bc300 SH |
509 | |
510 | return 0; | |
511 | } | |
512 | ||
513 | int do_fdb(int argc, char **argv) | |
514 | { | |
515 | ll_init_map(&rth); | |
516 | ||
517 | if (argc > 0) { | |
518 | if (matches(*argv, "add") == 0) | |
519 | return fdb_modify(RTM_NEWNEIGH, NLM_F_CREATE|NLM_F_EXCL, argc-1, argv+1); | |
5f409678 DS |
520 | if (matches(*argv, "append") == 0) |
521 | return fdb_modify(RTM_NEWNEIGH, NLM_F_CREATE|NLM_F_APPEND, argc-1, argv+1); | |
5464049b TR |
522 | if (matches(*argv, "replace") == 0) |
523 | return fdb_modify(RTM_NEWNEIGH, NLM_F_CREATE|NLM_F_REPLACE, argc-1, argv+1); | |
d04bc300 SH |
524 | if (matches(*argv, "delete") == 0) |
525 | return fdb_modify(RTM_DELNEIGH, 0, argc-1, argv+1); | |
526 | if (matches(*argv, "show") == 0 || | |
527 | matches(*argv, "lst") == 0 || | |
528 | matches(*argv, "list") == 0) | |
529 | return fdb_show(argc-1, argv+1); | |
530 | if (matches(*argv, "help") == 0) | |
531 | usage(); | |
532 | } else | |
533 | return fdb_show(0, NULL); | |
534 | ||
083b46bb | 535 | fprintf(stderr, "Command \"%s\" is unknown, try \"bridge fdb help\".\n", *argv); |
d04bc300 SH |
536 | exit(-1); |
537 | } |