Commit 23f39261 authored by Sven Eckelmann's avatar Sven Eckelmann

batctl: Replace '-m meshif' option with selector prefix

The '-m meshif' option doesn't follow the prefix style which is used for
VLANs/hard interfaces. It is also not clear for a user which command
understands the '-m' option and which is actually operating on a
global/non-meshif specific scope. To clean this up, an additional command
prefix called meshif is implemented:

  $ batctl meshif bat0 ...

This can be omitted when it would be "meshif bat0". And when it is
specified, all non-meshif specific subcommands will be rejected.

The old option '-m meshif' option is still available to avoid breaking
existing scripts. It will will show an error message but continues to work
for now. Users of batctl should still transition to the new format.
Signed-off-by: default avatarSven Eckelmann <sven@narfation.org>
parent e5e6560d
......@@ -55,7 +55,7 @@ static struct settings_data batctl_settings_aggregation = {
.netlink_set = set_aggregated_ogms,
};
COMMAND_NAMED(SUBCOMMAND, aggregation, "ag", handle_sys_setting,
COMMAND_NAMED(SUBCOMMAND_MIF, aggregation, "ag", handle_sys_setting,
COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
&batctl_settings_aggregation,
"[0|1] \tdisplay or modify aggregation setting");
......@@ -77,7 +77,7 @@ static struct settings_data batctl_settings_ap_isolation = {
.netlink_set = set_ap_isolation,
};
COMMAND_NAMED(SUBCOMMAND, ap_isolation, "ap", handle_sys_setting,
COMMAND_NAMED(SUBCOMMAND_MIF, ap_isolation, "ap", handle_sys_setting,
COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
&batctl_settings_ap_isolation,
"[0|1] \tdisplay or modify ap_isolation setting");
......
......@@ -54,7 +54,7 @@ static struct settings_data batctl_settings_bonding = {
.netlink_set = set_bonding,
};
COMMAND_NAMED(SUBCOMMAND, bonding, "b", handle_sys_setting,
COMMAND_NAMED(SUBCOMMAND_MIF, bonding, "b", handle_sys_setting,
COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
&batctl_settings_bonding,
"[0|1] \tdisplay or modify bonding setting");
......@@ -55,7 +55,7 @@ static struct settings_data batctl_settings_bridge_loop_avoidance = {
.netlink_set = set_bridge_loop_avoidance,
};
COMMAND_NAMED(SUBCOMMAND, bridge_loop_avoidance, "bl", handle_sys_setting,
COMMAND_NAMED(SUBCOMMAND_MIF, bridge_loop_avoidance, "bl", handle_sys_setting,
COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
&batctl_settings_bridge_loop_avoidance,
"[0|1] \tdisplay or modify bridge_loop_avoidance setting");
......@@ -55,7 +55,7 @@ static struct settings_data batctl_settings_distributed_arp_table = {
.netlink_set = set_distributed_arp_table,
};
COMMAND_NAMED(SUBCOMMAND, distributed_arp_table, "dat", handle_sys_setting,
COMMAND_NAMED(SUBCOMMAND_MIF, distributed_arp_table, "dat", handle_sys_setting,
COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
&batctl_settings_distributed_arp_table,
"[0|1] \tdisplay or modify distributed_arp_table setting");
......@@ -55,7 +55,7 @@ static struct settings_data batctl_settings_fragmentation = {
.netlink_set = set_fragmentation,
};
COMMAND_NAMED(SUBCOMMAND, fragmentation, "f", handle_sys_setting,
COMMAND_NAMED(SUBCOMMAND_MIF, fragmentation, "f", handle_sys_setting,
COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
&batctl_settings_fragmentation,
"[0|1] \tdisplay or modify fragmentation setting");
......@@ -392,6 +392,6 @@ out:
return res;
}
COMMAND(SUBCOMMAND, gw_mode, "gw",
COMMAND(SUBCOMMAND_MIF, gw_mode, "gw",
COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK, NULL,
"[mode] \tdisplay or modify the gateway mode");
......@@ -95,7 +95,7 @@ static struct settings_data batctl_settings_hop_penalty = {
.netlink_set = set_hop_penalty,
};
COMMAND_NAMED(SUBCOMMAND, hop_penalty, "hp", handle_sys_setting,
COMMAND_NAMED(SUBCOMMAND_MIF, hop_penalty, "hp", handle_sys_setting,
COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
&batctl_settings_hop_penalty,
"[penalty] \tdisplay or modify hop_penalty setting");
......@@ -541,5 +541,5 @@ err:
return EXIT_FAILURE;
}
COMMAND(SUBCOMMAND, interface, "if", 0, NULL,
COMMAND(SUBCOMMAND_MIF, interface, "if", 0, NULL,
"[add|del iface(s)]\tdisplay or modify the interface settings");
......@@ -134,7 +134,7 @@ static struct settings_data batctl_settings_isolation_mark = {
.netlink_set = set_isolation_mark,
};
COMMAND_NAMED(SUBCOMMAND, isolation_mark, "mark", handle_sys_setting,
COMMAND_NAMED(SUBCOMMAND_MIF, isolation_mark, "mark", handle_sys_setting,
COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
&batctl_settings_isolation_mark,
"[mark] \tdisplay or modify isolation_mark setting");
......@@ -212,6 +212,6 @@ out:
return res;
}
COMMAND(SUBCOMMAND, loglevel, "ll",
COMMAND(SUBCOMMAND_MIF, loglevel, "ll",
COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK, NULL,
"[level] \tdisplay or modify the log level");
......@@ -35,6 +35,7 @@ static void print_usage(void)
{
.label = "commands:\n",
.types = BIT(SUBCOMMAND) |
BIT(SUBCOMMAND_MIF) |
BIT(SUBCOMMAND_VID) |
BIT(SUBCOMMAND_HIF),
},
......@@ -47,9 +48,13 @@ static void print_usage(void)
"",
NULL,
};
const char *meshif_prefixes[] = {
"meshif <netdev> ",
NULL,
};
const char *vlan_prefixes[] = {
"vlan <vdev> ",
"vid <vid> ",
"meshif <netdev> vid <vid> ",
NULL,
};
const char *hardif_prefixes[] = {
......@@ -64,7 +69,6 @@ static void print_usage(void)
fprintf(stderr, "Usage: batctl [options] command|debug table [parameters]\n");
fprintf(stderr, "options:\n");
fprintf(stderr, " \t-m mesh interface (default 'bat0')\n");
fprintf(stderr, " \t-h print this help (or 'batctl <command|debug table> -h' for the parameter help)\n");
fprintf(stderr, " \t-v print version\n");
......@@ -83,6 +87,10 @@ static void print_usage(void)
continue;
switch (cmd->type) {
case DEBUGTABLE:
case SUBCOMMAND_MIF:
prefixes = meshif_prefixes;
break;
case SUBCOMMAND_VID:
prefixes = vlan_prefixes;
break;
......@@ -102,7 +110,7 @@ static void print_usage(void)
snprintf(buf, sizeof(buf), "%s%s|%s",
*prefix, cmd->name, cmd->abbr);
fprintf(stderr, " \t%-35s%s\n", buf,
fprintf(stderr, " \t%-43s%s\n", buf,
cmd->usage);
}
}
......@@ -155,8 +163,11 @@ static const struct command *find_command(struct state *state, const char *name)
switch (state->selector) {
case SP_NONE_OR_MESHIF:
types = BIT(SUBCOMMAND) |
BIT(DEBUGTABLE);
types = BIT(SUBCOMMAND);
/* fall through */
case SP_MESHIF:
types |= BIT(SUBCOMMAND_MIF) |
BIT(DEBUGTABLE);
break;
case SP_VLAN:
types = BIT(SUBCOMMAND_VID);
......@@ -179,7 +190,10 @@ static int detect_selector_prefix(int argc, char *argv[],
return -EINVAL;
/* only detect selector prefix which identifies meshif */
if (strcmp(argv[0], "vlan") == 0) {
if (strcmp(argv[0], "meshif") == 0) {
*selector = SP_MESHIF;
return 2;
} else if (strcmp(argv[0], "vlan") == 0) {
*selector = SP_VLAN;
return 2;
} else if (strcmp(argv[0], "hardif") == 0) {
......@@ -204,6 +218,11 @@ static int parse_meshif_args(struct state *state, int argc, char *argv[])
dev_arg = argv[parsed_args - 1];
switch (selector) {
case SP_MESHIF:
snprintf(state->mesh_iface, sizeof(state->mesh_iface), "%s",
dev_arg);
state->selector = SP_MESHIF;
return parsed_args;
case SP_VLAN:
ret = translate_vlan_iface(state, dev_arg);
if (ret < 0) {
......@@ -252,6 +271,7 @@ static int parse_dev_args(struct state *state, int argc, char *argv[])
switch (state->selector) {
case SP_NONE_OR_MESHIF:
case SP_MESHIF:
/* continue below */
break;
default:
......@@ -297,6 +317,7 @@ int main(int argc, char **argv)
"Error - multiple mesh interfaces specified\n");
goto err;
}
fprintf(stderr, "Warning - option -m was deprecated in will be removed in the future\n");
state.arg_iface = argv[2];
break;
......
......@@ -58,12 +58,14 @@ enum command_flags {
enum selector_prefix {
SP_NONE_OR_MESHIF,
SP_MESHIF,
SP_VLAN,
SP_HARDIF,
};
enum command_type {
SUBCOMMAND,
SUBCOMMAND_MIF,
SUBCOMMAND_VID,
SUBCOMMAND_HIF,
DEBUGTABLE,
......
This diff is collapsed.
......@@ -95,7 +95,7 @@ static struct settings_data batctl_settings_multicast_fanout = {
.netlink_set = set_multicast_fanout,
};
COMMAND_NAMED(SUBCOMMAND, multicast_fanout, "mo", handle_sys_setting,
COMMAND_NAMED(SUBCOMMAND_MIF, multicast_fanout, "mo", handle_sys_setting,
COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
&batctl_settings_multicast_fanout,
"[fanout] \tdisplay or modify multicast_fanout setting");
......@@ -75,7 +75,7 @@ static struct settings_data batctl_settings_multicast_forceflood = {
.netlink_set = set_multicast_forceflood,
};
COMMAND_NAMED(SUBCOMMAND, multicast_forceflood, "mff", handle_sys_setting,
COMMAND_NAMED(SUBCOMMAND_MIF, multicast_forceflood, "mff", handle_sys_setting,
COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK | COMMAND_FLAG_INVERSE,
&batctl_settings_multicast_forceflood,
"[0|1] \tdisplay or modify multicast_forceflood setting");
......@@ -75,6 +75,6 @@ static struct settings_data batctl_settings_multicast_mode = {
.netlink_set = set_multicast_mode,
};
COMMAND_NAMED(SUBCOMMAND, multicast_mode, "mm", handle_sys_setting,
COMMAND_NAMED(SUBCOMMAND_MIF, multicast_mode, "mm", handle_sys_setting,
COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
&batctl_settings_multicast_mode, NULL);
......@@ -55,7 +55,7 @@ static struct settings_data batctl_settings_network_coding = {
.netlink_set = set_network_coding,
};
COMMAND_NAMED(SUBCOMMAND, network_coding, "nc", handle_sys_setting,
COMMAND_NAMED(SUBCOMMAND_MIF, network_coding, "nc", handle_sys_setting,
COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
&batctl_settings_network_coding,
"[0|1] \tdisplay or modify network_coding setting");
......@@ -95,7 +95,7 @@ static struct settings_data batctl_settings_orig_interval = {
.netlink_set = set_orig_interval,
};
COMMAND_NAMED(SUBCOMMAND, orig_interval, "it", handle_sys_setting,
COMMAND_NAMED(SUBCOMMAND_MIF, orig_interval, "it", handle_sys_setting,
COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
&batctl_settings_orig_interval,
"[interval] \tdisplay or modify orig_interval setting");
......@@ -323,5 +323,5 @@ out:
return ret;
}
COMMAND(SUBCOMMAND, ping, "p", COMMAND_FLAG_MESH_IFACE, NULL,
COMMAND(SUBCOMMAND_MIF, ping, "p", COMMAND_FLAG_MESH_IFACE, NULL,
"<destination> \tping another batman adv host via layer 2");
......@@ -112,5 +112,5 @@ out:
return ret;
}
COMMAND(SUBCOMMAND, statistics, "s", COMMAND_FLAG_MESH_IFACE, NULL,
COMMAND(SUBCOMMAND_MIF, statistics, "s", COMMAND_FLAG_MESH_IFACE, NULL,
" \tprint mesh statistics");
......@@ -145,9 +145,13 @@ static void settings_usage(struct state *state)
"",
NULL,
};
const char *meshif_prefixes[] = {
"meshif <netdev> ",
NULL,
};
const char *vlan_prefixes[] = {
"vlan <vdev> ",
"vid <vid> ",
"meshif <netdev> vid <vid> ",
NULL,
};
const char *hardif_prefixes[] = {
......@@ -159,6 +163,9 @@ static void settings_usage(struct state *state)
const char **prefix;
switch (state->cmd->type) {
case SUBCOMMAND_MIF:
prefixes = meshif_prefixes;
break;
case SUBCOMMAND_VID:
prefixes = vlan_prefixes;
break;
......@@ -268,6 +275,7 @@ int handle_sys_setting(struct state *state, int argc, char **argv)
switch (state->selector) {
case SP_NONE_OR_MESHIF:
case SP_MESHIF:
snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT,
state->mesh_iface);
break;
......
......@@ -529,5 +529,5 @@ out:
return ret;
}
COMMAND(SUBCOMMAND, throughputmeter, "tp", COMMAND_FLAG_MESH_IFACE, NULL,
COMMAND(SUBCOMMAND_MIF, throughputmeter, "tp", COMMAND_FLAG_MESH_IFACE, NULL,
"<destination> \tstart a throughput measurement");
......@@ -209,5 +209,5 @@ out:
return ret;
}
COMMAND(SUBCOMMAND, traceroute, "tr", COMMAND_FLAG_MESH_IFACE, NULL,
COMMAND(SUBCOMMAND_MIF, traceroute, "tr", COMMAND_FLAG_MESH_IFACE, NULL,
"<destination> \ttraceroute another batman adv host via layer 2");
......@@ -64,5 +64,5 @@ out:
return ret;
}
COMMAND(SUBCOMMAND, translate, "t", COMMAND_FLAG_MESH_IFACE, NULL,
COMMAND(SUBCOMMAND_MIF, translate, "t", COMMAND_FLAG_MESH_IFACE, NULL,
"<destination> \ttranslate a destination to the originator responsible for it");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment