|
|
4aca6e |
From 7f257cb3dd2966aee6fdfc128ab2cb001cc123da Mon Sep 17 00:00:00 2001
|
|
|
4aca6e |
From: Phil Sutter <psutter@redhat.com>
|
|
|
4aca6e |
Date: Tue, 28 Feb 2017 16:11:51 +0100
|
|
|
4aca6e |
Subject: [PATCH] bridge: add batch command support
|
|
|
4aca6e |
|
|
|
4aca6e |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1417289
|
|
|
4aca6e |
Upstream Status: iproute2.git commit 9de8c6d9765f2
|
|
|
4aca6e |
|
|
|
4aca6e |
commit 9de8c6d9765f284f8f15ccbe4af791259afe707e
|
|
|
4aca6e |
Author: Wilson Kok <wkok@cumulusnetworks.com>
|
|
|
4aca6e |
Date: Sun Oct 11 14:03:03 2015 -0700
|
|
|
4aca6e |
|
|
|
4aca6e |
bridge: add batch command support
|
|
|
4aca6e |
|
|
|
4aca6e |
This patch adds support to batch bridge commands.
|
|
|
4aca6e |
Follows ip batch code.
|
|
|
4aca6e |
|
|
|
4aca6e |
Signed-off-by: Wilson Kok <wkok@cumulusnetworks.com>
|
|
|
4aca6e |
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
|
|
|
4aca6e |
Acked-by: Christophe Gouault <christophe.gouault@6wind.com>
|
|
|
4aca6e |
---
|
|
|
4aca6e |
bridge/bridge.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
4aca6e |
man/man8/bridge.8 | 11 +++++++++++
|
|
|
4aca6e |
2 files changed, 70 insertions(+)
|
|
|
4aca6e |
|
|
|
4aca6e |
diff --git a/bridge/bridge.c b/bridge/bridge.c
|
|
|
4aca6e |
index eaf09c8..72f153f 100644
|
|
|
4aca6e |
--- a/bridge/bridge.c
|
|
|
4aca6e |
+++ b/bridge/bridge.c
|
|
|
4aca6e |
@@ -9,6 +9,7 @@
|
|
|
4aca6e |
#include <unistd.h>
|
|
|
4aca6e |
#include <sys/socket.h>
|
|
|
4aca6e |
#include <string.h>
|
|
|
4aca6e |
+#include <errno.h>
|
|
|
4aca6e |
|
|
|
4aca6e |
#include "SNAPSHOT.h"
|
|
|
4aca6e |
#include "utils.h"
|
|
|
4aca6e |
@@ -23,6 +24,8 @@ int show_stats;
|
|
|
4aca6e |
int show_details;
|
|
|
4aca6e |
int compress_vlans;
|
|
|
4aca6e |
int timestamp;
|
|
|
4aca6e |
+char *batch_file;
|
|
|
4aca6e |
+int force;
|
|
|
4aca6e |
const char *_SL_;
|
|
|
4aca6e |
|
|
|
4aca6e |
static void usage(void) __attribute__((noreturn));
|
|
|
4aca6e |
@@ -31,6 +34,7 @@ static void usage(void)
|
|
|
4aca6e |
{
|
|
|
4aca6e |
fprintf(stderr,
|
|
|
4aca6e |
"Usage: bridge [ OPTIONS ] OBJECT { COMMAND | help }\n"
|
|
|
4aca6e |
+" bridge [ -force ] -batch filename\n"
|
|
|
4aca6e |
"where OBJECT := { link | fdb | mdb | vlan | monitor }\n"
|
|
|
4aca6e |
" OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] |\n"
|
|
|
4aca6e |
" -o[neline] | -t[imestamp] | -n[etns] name |\n"
|
|
|
4aca6e |
@@ -71,6 +75,50 @@ static int do_cmd(const char *argv0, int argc, char **argv)
|
|
|
4aca6e |
return -1;
|
|
|
4aca6e |
}
|
|
|
4aca6e |
|
|
|
4aca6e |
+static int batch(const char *name)
|
|
|
4aca6e |
+{
|
|
|
4aca6e |
+ char *line = NULL;
|
|
|
4aca6e |
+ size_t len = 0;
|
|
|
4aca6e |
+ int ret = EXIT_SUCCESS;
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+ if (name && strcmp(name, "-") != 0) {
|
|
|
4aca6e |
+ if (freopen(name, "r", stdin) == NULL) {
|
|
|
4aca6e |
+ fprintf(stderr,
|
|
|
4aca6e |
+ "Cannot open file \"%s\" for reading: %s\n",
|
|
|
4aca6e |
+ name, strerror(errno));
|
|
|
4aca6e |
+ return EXIT_FAILURE;
|
|
|
4aca6e |
+ }
|
|
|
4aca6e |
+ }
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+ if (rtnl_open(&rth, 0) < 0) {
|
|
|
4aca6e |
+ fprintf(stderr, "Cannot open rtnetlink\n");
|
|
|
4aca6e |
+ return EXIT_FAILURE;
|
|
|
4aca6e |
+ }
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+ cmdlineno = 0;
|
|
|
4aca6e |
+ while (getcmdline(&line, &len, stdin) != -1) {
|
|
|
4aca6e |
+ char *largv[100];
|
|
|
4aca6e |
+ int largc;
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+ largc = makeargs(line, largv, 100);
|
|
|
4aca6e |
+ if (largc == 0)
|
|
|
4aca6e |
+ continue; /* blank line */
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+ if (do_cmd(largv[0], largc, largv)) {
|
|
|
4aca6e |
+ fprintf(stderr, "Command failed %s:%d\n",
|
|
|
4aca6e |
+ name, cmdlineno);
|
|
|
4aca6e |
+ ret = EXIT_FAILURE;
|
|
|
4aca6e |
+ if (!force)
|
|
|
4aca6e |
+ break;
|
|
|
4aca6e |
+ }
|
|
|
4aca6e |
+ }
|
|
|
4aca6e |
+ if (line)
|
|
|
4aca6e |
+ free(line);
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+ rtnl_close(&rth);
|
|
|
4aca6e |
+ return ret;
|
|
|
4aca6e |
+}
|
|
|
4aca6e |
+
|
|
|
4aca6e |
int
|
|
|
4aca6e |
main(int argc, char **argv)
|
|
|
4aca6e |
{
|
|
|
4aca6e |
@@ -123,6 +171,14 @@ main(int argc, char **argv)
|
|
|
4aca6e |
exit(-1);
|
|
|
4aca6e |
} else if (matches(opt, "-compressvlans") == 0) {
|
|
|
4aca6e |
++compress_vlans;
|
|
|
4aca6e |
+ } else if (matches(opt, "-force") == 0) {
|
|
|
4aca6e |
+ ++force;
|
|
|
4aca6e |
+ } else if (matches(opt, "-batch") == 0) {
|
|
|
4aca6e |
+ argc--;
|
|
|
4aca6e |
+ argv++;
|
|
|
4aca6e |
+ if (argc <= 1)
|
|
|
4aca6e |
+ usage();
|
|
|
4aca6e |
+ batch_file = argv[1];
|
|
|
4aca6e |
} else {
|
|
|
4aca6e |
fprintf(stderr,
|
|
|
4aca6e |
"Option \"%s\" is unknown, try \"bridge help\".\n",
|
|
|
4aca6e |
@@ -134,6 +190,9 @@ main(int argc, char **argv)
|
|
|
4aca6e |
|
|
|
4aca6e |
_SL_ = oneline ? "\\" : "\n";
|
|
|
4aca6e |
|
|
|
4aca6e |
+ if (batch_file)
|
|
|
4aca6e |
+ return batch(batch_file);
|
|
|
4aca6e |
+
|
|
|
4aca6e |
if (rtnl_open(&rth, 0) < 0)
|
|
|
4aca6e |
exit(1);
|
|
|
4aca6e |
|
|
|
4aca6e |
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
|
|
|
4aca6e |
index 210a3ee..2f72710 100644
|
|
|
4aca6e |
--- a/man/man8/bridge.8
|
|
|
4aca6e |
+++ b/man/man8/bridge.8
|
|
|
4aca6e |
@@ -21,6 +21,7 @@ bridge \- show / manipulate bridge addresses and devices
|
|
|
4aca6e |
\fB\-V\fR[\fIersion\fR] |
|
|
|
4aca6e |
\fB\-s\fR[\fItatistics\fR] |
|
|
|
4aca6e |
\fB\-n\fR[\fIetns\fR] name }
|
|
|
4aca6e |
+\fB\-b\fR[\fIatch\fR] filename }
|
|
|
4aca6e |
|
|
|
4aca6e |
.ti -8
|
|
|
4aca6e |
.BR "bridge link set"
|
|
|
4aca6e |
@@ -137,6 +138,16 @@ to
|
|
|
4aca6e |
.RI "-n[etns] " NETNS " [ " OPTIONS " ] " OBJECT " { " COMMAND " | "
|
|
|
4aca6e |
.BR help " }"
|
|
|
4aca6e |
|
|
|
4aca6e |
+.TP
|
|
|
4aca6e |
+.BR "\-b", " \-batch " <FILENAME>
|
|
|
4aca6e |
+Read commands from provided file or standard input and invoke them.
|
|
|
4aca6e |
+First failure will cause termination of bridge command.
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+.TP
|
|
|
4aca6e |
+.BR "\-force"
|
|
|
4aca6e |
+Don't terminate bridge command on errors in batch mode.
|
|
|
4aca6e |
+If there were any errors during execution of the commands, the application
|
|
|
4aca6e |
+return code will be non zero.
|
|
|
4aca6e |
|
|
|
4aca6e |
.SH BRIDGE - COMMAND SYNTAX
|
|
|
4aca6e |
|
|
|
4aca6e |
--
|
|
|
4aca6e |
1.8.3.1
|
|
|
4aca6e |
|