A deletion of a hardif from a batadv meshif will also get a success reply from the kernel when the hardif was never part of the batadv meshif. If the batadv meshif had no attached hardifs before the removal was started, then users are then not expecting that the batadv meshif is removed at all.
Since the delete operation is not an atomic compare-and-swap operation, just check first the number of attached interfaces and only start the removal of the batadv meshif when the number attached hardifs was reduced.
Fixes: 25022e0b154d ("batctl: Use rtnl to add/remove interfaces") Reported-by: Matthias Schiffer mschiffer@universe-factory.net Signed-off-by: Sven Eckelmann sven@narfation.org --- interface.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/interface.c b/interface.c index 1cd6ede..ac4d883 100644 --- a/interface.c +++ b/interface.c @@ -386,6 +386,7 @@ static int interface(struct state *state, int argc, char **argv) int ret; unsigned int ifindex; unsigned int ifmaster; + unsigned int pre_cnt; const char *long_op; unsigned int cnt; int rest_argc; @@ -502,6 +503,8 @@ static int interface(struct state *state, int argc, char **argv) goto err; }
+ pre_cnt = count_interfaces(state->mesh_iface); + for (i = 1; i < rest_argc; i++) { ifindex = if_nametoindex(rest_argv[i]);
@@ -531,7 +534,7 @@ static int interface(struct state *state, int argc, char **argv) /* check if there is no interface left and then destroy mesh_iface */ if (!manual_mode && rest_argv[0][0] == 'd') { cnt = count_interfaces(state->mesh_iface); - if (cnt == 0) + if (cnt == 0 && pre_cnt > 0) destroy_interface(state->mesh_iface); }
The sysfs interface of batman-adv used an automatic drop of empty batadv meshifs. This was necessary because no other method to remove this type of interface was available. The same behavior was tried to emulate in the batctl rtnetlink implementation to make the migration easier.
But this caused problems with both (rtnetlink/sysfs) backends because the caller might not be aware of the current state of hardifs list for the current meshif. The meshif might therefore be deleted accidentally (and its configuration lost) even when the caller only wanted to swap some devices around.
Instead print information about the necessary addition steps to drop the empty meshif instead of performing it automatically.
Signed-off-by: Sven Eckelmann sven@narfation.org --- interface.c | 5 +++-- man/batctl.8 | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/interface.c b/interface.c index ac4d883..d0d9435 100644 --- a/interface.c +++ b/interface.c @@ -31,7 +31,7 @@ static void interface_usage(void) fprintf(stderr, "Usage: batctl [options] interface [parameters] [add|del iface(s)]\n"); fprintf(stderr, " batctl [options] interface [parameters] [create|destroy]\n"); fprintf(stderr, "parameters:\n"); - fprintf(stderr, " \t -M disable automatic creation/removal of batman-adv interface\n"); + fprintf(stderr, " \t -M disable automatic creation of batman-adv interface\n"); fprintf(stderr, " \t -h print this help\n"); }
@@ -535,7 +535,8 @@ static int interface(struct state *state, int argc, char **argv) if (!manual_mode && rest_argv[0][0] == 'd') { cnt = count_interfaces(state->mesh_iface); if (cnt == 0 && pre_cnt > 0) - destroy_interface(state->mesh_iface); + fprintf(stderr, "Warning: %s has no interfaces and can be destroyed with: batctl meshif %s interface destroy\n", + state->mesh_iface, state->mesh_iface); }
return EXIT_SUCCESS; diff --git a/man/batctl.8 b/man/batctl.8 index 6e75cdd..fedfb21 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -58,8 +58,8 @@ performances, is also included. If no parameter is given or the first parameter is neither "add" nor "del" the current interface settings are displayed. In order to add or delete interfaces specify "add" or "del" as first argument and append the interface names you wish to add or delete. Multiple interfaces can be specified. -The "-M" option tells batctl to not automatically create the batman-adv interface on "add" or to destroy it when "del" -removed all interfaces which belonged to it. +The "-M" option tells batctl to not automatically create the batman-adv interface on "add". It can also be used to +suppress the warning about the manual destruction when "del" removed all interfaces which belonged to it. .IP "[\fBmeshif <netdev>\fP] \fBinterface\fP|\fBif\fP [\fBcreate\fP|\fBdestroy\fP]" A batman-adv interface without attached interfaces can be created using "create". The parameter "destroy" can be used to free all attached interfaces and remove batman-adv interface.
b.a.t.m.a.n@lists.open-mesh.org