]> git.proxmox.com Git - mirror_iproute2.git/blob - bridge/bridge.c
Add bridge command
[mirror_iproute2.git] / bridge / bridge.c
1 /*
2 * Get/set/delete bridge with netlink
3 *
4 * Authors: Stephen Hemminger <shemminger@vyatta.com>
5 */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <sys/socket.h>
11 #include <string.h>
12
13 #include "SNAPSHOT.h"
14 #include "utils.h"
15 #include "br_common.h"
16
17 struct rtnl_handle rth = { .fd = -1 };
18 int resolve_hosts;
19 int show_stats;
20 int show_details;
21 int timestamp;
22
23 static void usage(void) __attribute__((noreturn));
24
25 static void usage(void)
26 {
27 fprintf(stderr,
28 "Usage: br [ OPTIONS ] OBJECT { COMMAND | help }\n"
29 "where OBJECT := { fdb | monitor }\n"
30 " OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails]\n" );
31 exit(-1);
32 }
33
34 static int do_help(int argc, char **argv)
35 {
36 usage();
37 }
38
39
40 static const struct cmd {
41 const char *cmd;
42 int (*func)(int argc, char **argv);
43 } cmds[] = {
44 { "fdb", do_fdb },
45 { "monitor", do_monitor },
46 { "help", do_help },
47 { 0 }
48 };
49
50 static int do_cmd(const char *argv0, int argc, char **argv)
51 {
52 const struct cmd *c;
53
54 for (c = cmds; c->cmd; ++c) {
55 if (matches(argv0, c->cmd) == 0)
56 return c->func(argc-1, argv+1);
57 }
58
59 fprintf(stderr, "Object \"%s\" is unknown, try \"br help\".\n", argv0);
60 return -1;
61 }
62
63 int
64 main(int argc, char **argv)
65 {
66 while (argc > 1) {
67 char *opt = argv[1];
68 if (strcmp(opt,"--") == 0) {
69 argc--; argv++;
70 break;
71 }
72 if (opt[0] != '-')
73 break;
74 if (opt[1] == '-')
75 opt++;
76
77 if (matches(opt, "-help") == 0) {
78 usage();
79 } else if (matches(opt, "-Version") == 0) {
80 printf("br utility, 0.0\n");
81 exit(0);
82 } else if (matches(opt, "-stats") == 0 ||
83 matches(opt, "-statistics") == 0) {
84 ++show_stats;
85 } else if (matches(opt, "-details") == 0) {
86 ++show_details;
87 } else if (matches(opt, "-timestamp") == 0) {
88 ++timestamp;
89 } else {
90 fprintf(stderr, "Option \"%s\" is unknown, try \"br -help\".\n", opt);
91 exit(-1);
92 }
93 argc--; argv++;
94 }
95
96 if (rtnl_open(&rth, 0) < 0)
97 exit(1);
98
99 if (argc > 1)
100 return do_cmd(argv[1], argc-1, argv+1);
101
102 rtnl_close(&rth);
103 usage();
104 }