]>
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"
21 struct rtnl_handle rth
= { .fd
= -1 };
22 int preferred_family
= AF_UNSPEC
;
34 static void usage(void) __attribute__((noreturn
));
36 static void usage(void)
39 "Usage: bridge [ OPTIONS ] OBJECT { COMMAND | help }\n"
40 " bridge [ -force ] -batch filename\n"
41 "where OBJECT := { link | fdb | mdb | vlan | monitor }\n"
42 " OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] |\n"
43 " -o[neline] | -t[imestamp] | -n[etns] name |\n"
44 " -c[ompressvlans] -color -p[retty] -j[son] }\n");
48 static int do_help(int argc
, char **argv
)
54 static const struct cmd
{
56 int (*func
)(int argc
, char **argv
);
62 { "monitor", do_monitor
},
67 static int do_cmd(const char *argv0
, int argc
, char **argv
)
71 for (c
= cmds
; c
->cmd
; ++c
) {
72 if (matches(argv0
, c
->cmd
) == 0)
73 return c
->func(argc
-1, argv
+1);
77 "Object \"%s\" is unknown, try \"bridge help\".\n", argv0
);
81 static int batch(const char *name
)
85 int ret
= EXIT_SUCCESS
;
87 if (name
&& strcmp(name
, "-") != 0) {
88 if (freopen(name
, "r", stdin
) == NULL
) {
90 "Cannot open file \"%s\" for reading: %s\n",
91 name
, strerror(errno
));
96 if (rtnl_open(&rth
, 0) < 0) {
97 fprintf(stderr
, "Cannot open rtnetlink\n");
102 while (getcmdline(&line
, &len
, stdin
) != -1) {
106 largc
= makeargs(line
, largv
, 100);
108 continue; /* blank line */
110 if (do_cmd(largv
[0], largc
, largv
)) {
111 fprintf(stderr
, "Command failed %s:%d\n",
126 main(int argc
, char **argv
)
129 const char *opt
= argv
[1];
131 if (strcmp(opt
, "--") == 0) {
140 if (matches(opt
, "-help") == 0) {
142 } else if (matches(opt
, "-Version") == 0) {
143 printf("bridge utility, 0.0\n");
145 } else if (matches(opt
, "-stats") == 0 ||
146 matches(opt
, "-statistics") == 0) {
148 } else if (matches(opt
, "-details") == 0) {
150 } else if (matches(opt
, "-oneline") == 0) {
152 } else if (matches(opt
, "-timestamp") == 0) {
154 } else if (matches(opt
, "-family") == 0) {
159 if (strcmp(argv
[1], "inet") == 0)
160 preferred_family
= AF_INET
;
161 else if (strcmp(argv
[1], "inet6") == 0)
162 preferred_family
= AF_INET6
;
163 else if (strcmp(argv
[1], "help") == 0)
166 invarg("invalid protocol family", argv
[1]);
167 } else if (strcmp(opt
, "-4") == 0) {
168 preferred_family
= AF_INET
;
169 } else if (strcmp(opt
, "-6") == 0) {
170 preferred_family
= AF_INET6
;
171 } else if (matches(opt
, "-netns") == 0) {
173 if (netns_switch(argv
[1]))
175 } else if (matches_color(opt
, &color
)) {
176 } else if (matches(opt
, "-compressvlans") == 0) {
178 } else if (matches(opt
, "-force") == 0) {
180 } else if (matches(opt
, "-json") == 0) {
182 } else if (matches(opt
, "-pretty") == 0) {
184 } else if (matches(opt
, "-batch") == 0) {
189 batch_file
= argv
[1];
192 "Option \"%s\" is unknown, try \"bridge help\".\n",
199 _SL_
= oneline
? "\\" : "\n";
201 check_enable_color(color
, json
);
204 return batch(batch_file
);
206 if (rtnl_open(&rth
, 0) < 0)
210 return do_cmd(argv
[1], argc
-1, argv
+1);