From 88997b4cd8480bcbcb3b0470020968a944495233 Mon Sep 17 00:00:00 2001
From: Phil Sutter <psutter@redhat.com>
Date: Tue, 28 Feb 2017 16:10:15 +0100
Subject: [PATCH] fix ip -force -batch to continue on errors
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1417289
Upstream Status: iproute2.git commit 42ecedd4bae53
Conflicts: Previously backported changes to rtnl_talk() signature.
commit 42ecedd4bae534fc688194a795eb4548c6530cda
Author: Roopa Prabhu <roopa@cumulusnetworks.com>
Date: Tue Mar 17 19:26:32 2015 -0700
fix ip -force -batch to continue on errors
This patch replaces exits with returns in several
iproute2 commands. This fixes `ip -batch -force`
to not exit but continue on errors.
$cat c.txt
route del 1.2.3.0/24 dev eth0
route del 1.2.4.0/24 dev eth0
route del 1.2.5.0/24 dev eth0
route add 1.2.3.0/24 dev eth0
$ip -force -batch c.txt
RTNETLINK answers: No such process
Command failed c.txt:2
RTNETLINK answers: No such process
Command failed c.txt:3
Reported-by: Sven-Haegar Koch <haegar@sdinet.de>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
---
bridge/fdb.c | 6 +++---
bridge/link.c | 24 ++++++++++++------------
bridge/mdb.c | 8 ++++----
bridge/vlan.c | 4 ++--
ip/iproute.c | 2 +-
5 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/bridge/fdb.c b/bridge/fdb.c
index e411932..3020633 100644
--- a/bridge/fdb.c
+++ b/bridge/fdb.c
@@ -322,7 +322,7 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
if (d == NULL || addr == NULL) {
fprintf(stderr, "Device and address are required arguments.\n");
- exit(-1);
+ return -1;
}
/* Assume self */
@@ -337,7 +337,7 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
abuf, abuf+1, abuf+2,
abuf+3, abuf+4, abuf+5) != 6) {
fprintf(stderr, "Invalid mac address %s\n", addr);
- exit(-1);
+ return -1;
}
addattr_l(&req.n, sizeof(req), NDA_LLADDR, abuf, ETH_ALEN);
@@ -365,7 +365,7 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
}
if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
- exit(2);
+ return -1;
return 0;
}
diff --git a/bridge/link.c b/bridge/link.c
index 69c0bfb..a9b1262 100644
--- a/bridge/link.c
+++ b/bridge/link.c
@@ -284,31 +284,31 @@ static int brlink_modify(int argc, char **argv)
} else if (strcmp(*argv, "guard") == 0) {
NEXT_ARG();
if (!on_off("guard", &bpdu_guard, *argv))
- exit(-1);
+ return -1;
} else if (strcmp(*argv, "hairpin") == 0) {
NEXT_ARG();
if (!on_off("hairping", &hairpin, *argv))
- exit(-1);
+ return -1;
} else if (strcmp(*argv, "fastleave") == 0) {
NEXT_ARG();
if (!on_off("fastleave", &fast_leave, *argv))
- exit(-1);
+ return -1;
} else if (strcmp(*argv, "root_block") == 0) {
NEXT_ARG();
if (!on_off("root_block", &root_block, *argv))
- exit(-1);
+ return -1;
} else if (strcmp(*argv, "learning") == 0) {
NEXT_ARG();
if (!on_off("learning", &learning, *argv))
- exit(-1);
+ return -1;
} else if (strcmp(*argv, "learning_sync") == 0) {
NEXT_ARG();
if (!on_off("learning_sync", &learning_sync, *argv))
- exit(-1);
+ return -1;
} else if (strcmp(*argv, "flood") == 0) {
NEXT_ARG();
if (!on_off("flood", &flood, *argv))
- exit(-1);
+ return -1;
} else if (strcmp(*argv, "cost") == 0) {
NEXT_ARG();
cost = atoi(*argv);
@@ -327,7 +327,7 @@ static int brlink_modify(int argc, char **argv)
if (state == nstates) {
fprintf(stderr,
"Error: invalid STP port state\n");
- exit(-1);
+ return -1;
}
}
} else if (strcmp(*argv, "hwmode") == 0) {
@@ -341,7 +341,7 @@ static int brlink_modify(int argc, char **argv)
fprintf(stderr,
"Mode argument must be \"vepa\" or "
"\"veb\".\n");
- exit(-1);
+ return -1;
}
} else if (strcmp(*argv, "self") == 0) {
flags |= BRIDGE_FLAGS_SELF;
@@ -354,14 +354,14 @@ static int brlink_modify(int argc, char **argv)
}
if (d == NULL) {
fprintf(stderr, "Device is a required argument.\n");
- exit(-1);
+ return -1;
}
req.ifm.ifi_index = ll_name_to_index(d);
if (req.ifm.ifi_index == 0) {
fprintf(stderr, "Cannot find bridge device \"%s\"\n", d);
- exit(-1);
+ return -1;
}
/* Nested PROTINFO attribute. Contains: port flags, cost, priority and
@@ -416,7 +416,7 @@ static int brlink_modify(int argc, char **argv)
}
if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
- exit(2);
+ return -1;
return 0;
}
diff --git a/bridge/mdb.c b/bridge/mdb.c
index 837fa5d..9a8ed54 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -145,12 +145,12 @@ static int mdb_show(int argc, char **argv)
if (rtnl_wilddump_request(&rth, PF_BRIDGE, RTM_GETMDB) < 0) {
perror("Cannot send dump request");
- exit(1);
+ return -1;
}
if (rtnl_dump_filter(&rth, print_mdb, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
- exit(1);
+ return -1;
}
return 0;
@@ -198,7 +198,7 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
if (d == NULL || grp == NULL || p == NULL) {
fprintf(stderr, "Device, group address and port name are required arguments.\n");
- exit(-1);
+ return -1;
}
req.bpm.ifindex = ll_name_to_index(d);
@@ -225,7 +225,7 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
addattr_l(&req.n, sizeof(req), MDBA_SET_ENTRY, &entry, sizeof(entry));
if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
- exit(2);
+ return -1;
return 0;
}
diff --git a/bridge/vlan.c b/bridge/vlan.c
index 0fb479c..ac2f523 100644
--- a/bridge/vlan.c
+++ b/bridge/vlan.c
@@ -80,7 +80,7 @@ static int vlan_modify(int cmd, int argc, char **argv)
if (d == NULL || vid == -1) {
fprintf(stderr, "Device and VLAN ID are required arguments.\n");
- exit(-1);
+ return -1;
}
req.ifm.ifi_index = ll_name_to_index(d);
@@ -132,7 +132,7 @@ static int vlan_modify(int cmd, int argc, char **argv)
addattr_nest_end(&req.n, afspec);
if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
- exit(2);
+ return -1;
return 0;
}
diff --git a/ip/iproute.c b/ip/iproute.c
index 8a706ea..9dcfd19 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -1112,7 +1112,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
req.r.rtm_family = AF_INET;
if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
- exit(2);
+ return -1;
return 0;
}
--
1.8.3.1