]>
git.proxmox.com Git - mirror_iproute2.git/blob - bridge/bridge.c
1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Get/set/delete bridge with netlink
5 * Authors: Stephen Hemminger <shemminger@vyatta.com>
11 #include <sys/socket.h>
17 #include "br_common.h"
18 #include "namespace.h"
20 struct rtnl_handle rth
= { .fd
= -1 };
21 int preferred_family
= AF_UNSPEC
;
32 static void usage(void) __attribute__((noreturn
));
34 static void usage(void)
37 "Usage: bridge [ OPTIONS ] OBJECT { COMMAND | help }\n"
38 " bridge [ -force ] -batch filename\n"
39 "where OBJECT := { link | fdb | mdb | vlan | monitor }\n"
40 " OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] |\n"
41 " -o[neline] | -t[imestamp] | -n[etns] name |\n"
42 " -c[ompressvlans] -j{son} }\n");
46 static int do_help(int argc
, char **argv
)
52 static const struct cmd
{
54 int (*func
)(int argc
, char **argv
);
60 { "monitor", do_monitor
},
65 static int do_cmd(const char *argv0
, int argc
, char **argv
)
69 for (c
= cmds
; c
->cmd
; ++c
) {
70 if (matches(argv0
, c
->cmd
) == 0)
71 return c
->func(argc
-1, argv
+1);
75 "Object \"%s\" is unknown, try \"bridge help\".\n", argv0
);
79 static int batch(const char *name
)
83 int ret
= EXIT_SUCCESS
;
85 if (name
&& strcmp(name
, "-") != 0) {
86 if (freopen(name
, "r", stdin
) == NULL
) {
88 "Cannot open file \"%s\" for reading: %s\n",
89 name
, strerror(errno
));
94 if (rtnl_open(&rth
, 0) < 0) {
95 fprintf(stderr
, "Cannot open rtnetlink\n");
100 while (getcmdline(&line
, &len
, stdin
) != -1) {
104 largc
= makeargs(line
, largv
, 100);
106 continue; /* blank line */
108 if (do_cmd(largv
[0], largc
, largv
)) {
109 fprintf(stderr
, "Command failed %s:%d\n",
124 main(int argc
, char **argv
)
127 const char *opt
= argv
[1];
129 if (strcmp(opt
, "--") == 0) {
138 if (matches(opt
, "-help") == 0) {
140 } else if (matches(opt
, "-Version") == 0) {
141 printf("bridge utility, 0.0\n");
143 } else if (matches(opt
, "-stats") == 0 ||
144 matches(opt
, "-statistics") == 0) {
146 } else if (matches(opt
, "-details") == 0) {
148 } else if (matches(opt
, "-oneline") == 0) {
150 } else if (matches(opt
, "-timestamp") == 0) {
152 } else if (matches(opt
, "-family") == 0) {
157 if (strcmp(argv
[1], "inet") == 0)
158 preferred_family
= AF_INET
;
159 else if (strcmp(argv
[1], "inet6") == 0)
160 preferred_family
= AF_INET6
;
161 else if (strcmp(argv
[1], "help") == 0)
164 invarg("invalid protocol family", argv
[1]);
165 } else if (strcmp(opt
, "-4") == 0) {
166 preferred_family
= AF_INET
;
167 } else if (strcmp(opt
, "-6") == 0) {
168 preferred_family
= AF_INET6
;
169 } else if (matches(opt
, "-netns") == 0) {
171 if (netns_switch(argv
[1]))
173 } else if (matches(opt
, "-compressvlans") == 0) {
175 } else if (matches(opt
, "-force") == 0) {
177 } else if (matches(opt
, "-json") == 0) {
179 } else if (matches(opt
, "-batch") == 0) {
184 batch_file
= argv
[1];
187 "Option \"%s\" is unknown, try \"bridge help\".\n",
194 _SL_
= oneline
? "\\" : "\n";
197 return batch(batch_file
);
199 if (rtnl_open(&rth
, 0) < 0)
203 return do_cmd(argv
[1], argc
-1, argv
+1);