]>
git.proxmox.com Git - mirror_iproute2.git/blob - bridge/bridge.c
2 * Get/set/delete bridge with netlink
4 * Authors: Stephen Hemminger <shemminger@vyatta.com>
10 #include <sys/socket.h>
16 #include "br_common.h"
17 #include "namespace.h"
19 struct rtnl_handle rth
= { .fd
= -1 };
20 int preferred_family
= AF_UNSPEC
;
31 static void usage(void) __attribute__((noreturn
));
33 static void usage(void)
36 "Usage: bridge [ OPTIONS ] OBJECT { COMMAND | help }\n"
37 " bridge [ -force ] -batch filename\n"
38 "where OBJECT := { link | fdb | mdb | vlan | monitor }\n"
39 " OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] |\n"
40 " -o[neline] | -t[imestamp] | -n[etns] name |\n"
41 " -c[ompressvlans] }\n");
45 static int do_help(int argc
, char **argv
)
51 static const struct cmd
{
53 int (*func
)(int argc
, char **argv
);
59 { "monitor", do_monitor
},
64 static int do_cmd(const char *argv0
, int argc
, char **argv
)
68 for (c
= cmds
; c
->cmd
; ++c
) {
69 if (matches(argv0
, c
->cmd
) == 0)
70 return c
->func(argc
-1, argv
+1);
74 "Object \"%s\" is unknown, try \"bridge help\".\n", argv0
);
78 static int batch(const char *name
)
82 int ret
= EXIT_SUCCESS
;
84 if (name
&& strcmp(name
, "-") != 0) {
85 if (freopen(name
, "r", stdin
) == NULL
) {
87 "Cannot open file \"%s\" for reading: %s\n",
88 name
, strerror(errno
));
93 if (rtnl_open(&rth
, 0) < 0) {
94 fprintf(stderr
, "Cannot open rtnetlink\n");
99 while (getcmdline(&line
, &len
, stdin
) != -1) {
103 largc
= makeargs(line
, largv
, 100);
105 continue; /* blank line */
107 if (do_cmd(largv
[0], largc
, largv
)) {
108 fprintf(stderr
, "Command failed %s:%d\n",
123 main(int argc
, char **argv
)
126 const char *opt
= argv
[1];
128 if (strcmp(opt
, "--") == 0) {
137 if (matches(opt
, "-help") == 0) {
139 } else if (matches(opt
, "-Version") == 0) {
140 printf("bridge utility, 0.0\n");
142 } else if (matches(opt
, "-stats") == 0 ||
143 matches(opt
, "-statistics") == 0) {
145 } else if (matches(opt
, "-details") == 0) {
147 } else if (matches(opt
, "-oneline") == 0) {
149 } else if (matches(opt
, "-timestamp") == 0) {
151 } else if (matches(opt
, "-family") == 0) {
156 if (strcmp(argv
[1], "inet") == 0)
157 preferred_family
= AF_INET
;
158 else if (strcmp(argv
[1], "inet6") == 0)
159 preferred_family
= AF_INET6
;
160 else if (strcmp(argv
[1], "help") == 0)
163 invarg("invalid protocol family", argv
[1]);
164 } else if (strcmp(opt
, "-4") == 0) {
165 preferred_family
= AF_INET
;
166 } else if (strcmp(opt
, "-6") == 0) {
167 preferred_family
= AF_INET6
;
168 } else if (matches(opt
, "-netns") == 0) {
170 if (netns_switch(argv
[1]))
172 } else if (matches(opt
, "-compressvlans") == 0) {
174 } else if (matches(opt
, "-force") == 0) {
176 } else if (matches(opt
, "-batch") == 0) {
181 batch_file
= argv
[1];
184 "Option \"%s\" is unknown, try \"bridge help\".\n",
191 _SL_
= oneline
? "\\" : "\n";
194 return batch(batch_file
);
196 if (rtnl_open(&rth
, 0) < 0)
200 return do_cmd(argv
[1], argc
-1, argv
+1);