[5/7] batctl: Allow to disable automatic interface new/destroy
Commit Message
Users may not want to lose their configured batman-adv soft-interface when
they remove a single interface from it. The default configuration may not
working well enough in the network setup of the user and thus it should be
possible to avoid that it gets reset to it when a new interface is added
after the last one was removed.
This can be done by avoiding automatic creation of an interface when the
command "add" is used together with the option "-M". The add would fail
when the soft-interface disappeared for some reason and thus the
soft-interface would not be created again with the default configuration.
But more importantly, the "del" command can be informed with the option
"-M" to not try to remove the soft-interface in the first place.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
man/batctl.8 | 4 +++-
sys.c | 12 +++++++++---
2 files changed, 12 insertions(+), 4 deletions(-)
Comments
On Wed, Jul 13, 2016 at 05:30:20PM +0200, Sven Eckelmann wrote:
> Users may not want to lose their configured batman-adv soft-interface when
> they remove a single interface from it. The default configuration may not
> working well enough in the network setup of the user and thus it should be
> possible to avoid that it gets reset to it when a new interface is added
> after the last one was removed.
>
> This can be done by avoiding automatic creation of an interface when the
> command "add" is used together with the option "-M". The add would fail
> when the soft-interface disappeared for some reason and thus the
> soft-interface would not be created again with the default configuration.
> But more importantly, the "del" command can be informed with the option
> "-M" to not try to remove the soft-interface in the first place.
Currently wondering... have you thought about maybe
memorizing when a batman-adv interface was created via the new
"new" command? And in that case then transparently avoiding the automatic
destruction.
Would be one less parameter to memorize for the user then.
On Dienstag, 20. September 2016 16:29:02 CEST Linus Lüssing wrote:
[...]
> > This can be done by avoiding automatic creation of an interface when the
> > command "add" is used together with the option "-M". The add would fail
> > when the soft-interface disappeared for some reason and thus the
> > soft-interface would not be created again with the default configuration.
> > But more importantly, the "del" command can be informed with the option
> > "-M" to not try to remove the soft-interface in the first place.
>
> Currently wondering... have you thought about maybe
> memorizing when a batman-adv interface was created via the new
> "new" command? And in that case then transparently avoiding the automatic
> destruction.
>
> Would be one less parameter to memorize for the user then.
batctl would have to remember this to work and batctl is no program which is
running all the time. So it has to use temporary files... no.
One point here is to get rid of the batman-adv only files for creation/
destruction of itnerfaces and use the standard rtnl netlink. So I don't want
to create a new interface which does this in the kernel which supports your
idea.
Kind regards,
Sven
@@ -52,10 +52,12 @@ performances, is also included.
.br
.TP
.I \fBcommands:
-.IP "\fBinterface\fP|\fBif\fP [\fBadd\fP|\fBdel iface(s)\fP]"
+.IP "\fBinterface\fP|\fBif\fP [\fB-M\fP] [\fBadd\fP|\fBdel iface(s)\fP]"
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.
.IP "\fBinterface\fP|\fBif\fP [\fBnew\fP|\fBdestroy\fP]"
A batman-adv interface without attached interfaces can be created using "new". The parameter "destroy" can be used to
free all attached interfaces and remove batman-adv interface.
@@ -22,6 +22,7 @@
#include <unistd.h>
#include <stdio.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@@ -122,6 +123,7 @@ static void interface_usage(void)
fprintf(stderr, "Usage: batctl [options] interface [parameters] [add|del iface(s)]\n");
fprintf(stderr, " batctl [options] interface [parameters] [new|destroy]\n");
fprintf(stderr, "parameters:\n");
+ fprintf(stderr, " \t -M disable automatic creation/removal of batman-adv interface\n");
fprintf(stderr, " \t -h print this help\n");
}
@@ -385,12 +387,16 @@ int interface(char *mesh_iface, int argc, char **argv)
unsigned int cnt;
int rest_argc;
char **rest_argv;
+ bool manual_mode = false;
- while ((optchar = getopt(argc, argv, "h")) != -1) {
+ while ((optchar = getopt(argc, argv, "hM")) != -1) {
switch (optchar) {
case 'h':
interface_usage();
return EXIT_SUCCESS;
+ case 'M':
+ manual_mode = true;
+ break;
default:
interface_usage();
return EXIT_FAILURE;
@@ -465,7 +471,7 @@ int interface(char *mesh_iface, int argc, char **argv)
/* get index of batman-adv interface - or try to create it */
ifmaster = if_nametoindex(mesh_iface);
- if (!ifmaster && rest_argv[0][0] == 'a') {
+ if (!manual_mode && !ifmaster && rest_argv[0][0] == 'a') {
ret = new_interface(mesh_iface);
if (ret < 0) {
fprintf(stderr,
@@ -518,7 +524,7 @@ int interface(char *mesh_iface, int argc, char **argv)
}
/* check if there is no interface left and then destroy mesh_iface */
- if (rest_argv[0][0] == 'd') {
+ if (!manual_mode && rest_argv[0][0] == 'd') {
cnt = count_interfaces(mesh_iface);
if (cnt == 0)
destroy_interface(mesh_iface);