* [PATCH iproute2 v2] bridge: add batch command support
@ 2015-10-11 21:03 Roopa Prabhu
2015-10-12 7:40 ` Christophe Gouault
2015-10-12 16:25 ` Stephen Hemminger
0 siblings, 2 replies; 3+ messages in thread
From: Roopa Prabhu @ 2015-10-11 21:03 UTC (permalink / raw)
To: stephen; +Cc: netdev, wkok, christophe.gouault
From: Wilson Kok <wkok@cumulusnetworks.com>
This patch adds support to batch bridge commands.
Follows ip batch code.
Signed-off-by: Wilson Kok <wkok@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Acked-by: Christophe Gouault <christophe.gouault@6wind.com>
---
v2 - change tab to space in usage as pointed out by Christophe Gouault
bridge/bridge.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
man/man8/bridge.8 | 11 +++++++++++
2 files changed, 70 insertions(+)
diff --git a/bridge/bridge.c b/bridge/bridge.c
index eaf09c8..72f153f 100644
--- a/bridge/bridge.c
+++ b/bridge/bridge.c
@@ -9,6 +9,7 @@
#include <unistd.h>
#include <sys/socket.h>
#include <string.h>
+#include <errno.h>
#include "SNAPSHOT.h"
#include "utils.h"
@@ -23,6 +24,8 @@ int show_stats;
int show_details;
int compress_vlans;
int timestamp;
+char *batch_file;
+int force;
const char *_SL_;
static void usage(void) __attribute__((noreturn));
@@ -31,6 +34,7 @@ static void usage(void)
{
fprintf(stderr,
"Usage: bridge [ OPTIONS ] OBJECT { COMMAND | help }\n"
+" bridge [ -force ] -batch filename\n"
"where OBJECT := { link | fdb | mdb | vlan | monitor }\n"
" OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] |\n"
" -o[neline] | -t[imestamp] | -n[etns] name |\n"
@@ -71,6 +75,50 @@ static int do_cmd(const char *argv0, int argc, char **argv)
return -1;
}
+static int batch(const char *name)
+{
+ char *line = NULL;
+ size_t len = 0;
+ int ret = EXIT_SUCCESS;
+
+ if (name && strcmp(name, "-") != 0) {
+ if (freopen(name, "r", stdin) == NULL) {
+ fprintf(stderr,
+ "Cannot open file \"%s\" for reading: %s\n",
+ name, strerror(errno));
+ return EXIT_FAILURE;
+ }
+ }
+
+ if (rtnl_open(&rth, 0) < 0) {
+ fprintf(stderr, "Cannot open rtnetlink\n");
+ return EXIT_FAILURE;
+ }
+
+ cmdlineno = 0;
+ while (getcmdline(&line, &len, stdin) != -1) {
+ char *largv[100];
+ int largc;
+
+ largc = makeargs(line, largv, 100);
+ if (largc == 0)
+ continue; /* blank line */
+
+ if (do_cmd(largv[0], largc, largv)) {
+ fprintf(stderr, "Command failed %s:%d\n",
+ name, cmdlineno);
+ ret = EXIT_FAILURE;
+ if (!force)
+ break;
+ }
+ }
+ if (line)
+ free(line);
+
+ rtnl_close(&rth);
+ return ret;
+}
+
int
main(int argc, char **argv)
{
@@ -123,6 +171,14 @@ main(int argc, char **argv)
exit(-1);
} else if (matches(opt, "-compressvlans") == 0) {
++compress_vlans;
+ } else if (matches(opt, "-force") == 0) {
+ ++force;
+ } else if (matches(opt, "-batch") == 0) {
+ argc--;
+ argv++;
+ if (argc <= 1)
+ usage();
+ batch_file = argv[1];
} else {
fprintf(stderr,
"Option \"%s\" is unknown, try \"bridge help\".\n",
@@ -134,6 +190,9 @@ main(int argc, char **argv)
_SL_ = oneline ? "\\" : "\n";
+ if (batch_file)
+ return batch(batch_file);
+
if (rtnl_open(&rth, 0) < 0)
exit(1);
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index 5347a56..d45c728 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -21,6 +21,7 @@ bridge \- show / manipulate bridge addresses and devices
\fB\-V\fR[\fIersion\fR] |
\fB\-s\fR[\fItatistics\fR] |
\fB\-n\fR[\fIetns\fR] name }
+\fB\-b\fR[\fIatch\fR] filename }
.ti -8
.BR "bridge link set"
@@ -137,6 +138,16 @@ to
.RI "-n[etns] " NETNS " [ " OPTIONS " ] " OBJECT " { " COMMAND " | "
.BR help " }"
+.TP
+.BR "\-b", " \-batch " <FILENAME>
+Read commands from provided file or standard input and invoke them.
+First failure will cause termination of bridge command.
+
+.TP
+.BR "\-force"
+Don't terminate bridge command on errors in batch mode.
+If there were any errors during execution of the commands, the application
+return code will be non zero.
.SH BRIDGE - COMMAND SYNTAX
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2 v2] bridge: add batch command support
2015-10-11 21:03 [PATCH iproute2 v2] bridge: add batch command support Roopa Prabhu
@ 2015-10-12 7:40 ` Christophe Gouault
2015-10-12 16:25 ` Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Christophe Gouault @ 2015-10-12 7:40 UTC (permalink / raw)
To: Roopa Prabhu; +Cc: Stephen Hemminger, netdev@vger.kernel.org, wkok
2015-10-11 23:03 GMT+02:00 Roopa Prabhu <roopa@cumulusnetworks.com>:
> From: Wilson Kok <wkok@cumulusnetworks.com>
>
> This patch adds support to batch bridge commands.
> Follows ip batch code.
>
> Signed-off-by: Wilson Kok <wkok@cumulusnetworks.com>
> Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
> Acked-by: Christophe Gouault <christophe.gouault@6wind.com>
> ---
> v2 - change tab to space in usage as pointed out by Christophe Gouault
No more comments on this patch, looks good to me.
Best Regards,
Christophe
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2 v2] bridge: add batch command support
2015-10-11 21:03 [PATCH iproute2 v2] bridge: add batch command support Roopa Prabhu
2015-10-12 7:40 ` Christophe Gouault
@ 2015-10-12 16:25 ` Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2015-10-12 16:25 UTC (permalink / raw)
To: Roopa Prabhu; +Cc: netdev, wkok, christophe.gouault
On Sun, 11 Oct 2015 14:03:03 -0700
Roopa Prabhu <roopa@cumulusnetworks.com> wrote:
> From: Wilson Kok <wkok@cumulusnetworks.com>
>
> This patch adds support to batch bridge commands.
> Follows ip batch code.
>
> Signed-off-by: Wilson Kok <wkok@cumulusnetworks.com>
> Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
> Acked-by: Christophe Gouault <christophe.gouault@6wind.com>
Applied, thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-10-12 16:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-11 21:03 [PATCH iproute2 v2] bridge: add batch command support Roopa Prabhu
2015-10-12 7:40 ` Christophe Gouault
2015-10-12 16:25 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).