From patchwork Tue Jul 9 17:26:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17994 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id C658D8164A; Tue, 9 Jul 2019 19:27:00 +0200 (CEST) Received: from dvalin.narfation.org (dvalin.narfation.org [IPv6:2a00:17d8:100::8b1]) by open-mesh.org (Postfix) with ESMTPS id 2631981932 for ; Tue, 9 Jul 2019 19:26:59 +0200 (CEST) Received: from sven-desktop.home.narfation.org (unknown [IPv6:2a00:1ca0:1480:f9fc::4065]) by dvalin.narfation.org (Postfix) with ESMTPSA id 9937B2018A; Tue, 9 Jul 2019 17:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1562693218; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b7btYVGM/8r4/jUjTbEGujQZ9dWr8jP1h8oq9Z3FbbI=; b=d4ytaZY3oim8yr6/FggIb7NipxVQqLmLsrqh5KeU963Nw08lqR/zzKiSEU8yZdFQ6dMzH2 zOdZCE05Sr6m+sO9dlyCeH31cT501Z4AW/HSc9NYhtmZG5Wm715KfyFdjuT7BdYO5I3yt2 XHf+IPVz0OywypdKNnbRfYrHXM6gTkc= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Subject: [PATCH v3 1/6] batctl: Make vlan setting explicit Date: Tue, 9 Jul 2019 19:26:46 +0200 Message-Id: <20190709172651.5869-2-sven@narfation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190709172651.5869-1-sven@narfation.org> References: <20190709172651.5869-1-sven@narfation.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1562693218; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b7btYVGM/8r4/jUjTbEGujQZ9dWr8jP1h8oq9Z3FbbI=; b=vY1LJ+zbRSUxzkVn/EA5wdAFyahplwIbjCm6k8uCyq1vxLPtwngdBtFavTXohjh+XXaNMr tFeJvUabwo58sD1hgQaO5jwavw5e7eYjvEV9Hb7FIwWNGjY9OrowCGhhHqO0otqjU2+EJZ jfm2NvC8o/01XTogoIHodlfTmME9KrM= ARC-Seal: i=1; s=20121; d=narfation.org; t=1562693218; a=rsa-sha256; cv=none; b=dOQaAZEzCcFrUOlNFIjWbvIGvT8ygeYqR4aZQFKQF86wA8lJUZAlWEhPuFJEMmq2sHNcW3 J6xlWQ5JCukfcT2zY45gr5PWO+oAPWBKQiZDBdp7BlzjQ1opIKS8bp2k1VIN1Ihgu8Cf75 hETjL/VgiMB7d+haubh7TgzycslsDxo= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=sven smtp.mailfrom=sven@narfation.org X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" The requirement to have a VLAN master device on top of the batadv mesh interface is artificially limiting the capabilities of batctl. Not all master devices in linux which register a VLAN are from type "vlan" and are only registering a single VLAN. For example VLAN aware bridges can create multiple VLANs. These require that the VLAN is identified using the VID and not the vlan device. Signed-off-by: Sven Eckelmann --- ap_isolation.c | 13 +++- functions.c | 61 ++++++++++++--- functions.h | 4 +- main.c | 200 +++++++++++++++++++++++++++++++++++++++++++------ main.h | 13 +++- man/batctl.8 | 8 +- sys.c | 50 ++++++++++--- 7 files changed, 294 insertions(+), 55 deletions(-) diff --git a/ap_isolation.c b/ap_isolation.c index 71dcd00..36fd4d6 100644 --- a/ap_isolation.c +++ b/ap_isolation.c @@ -28,7 +28,7 @@ static int get_attrs_ap_isolation(struct nl_msg *msg, void *arg) { struct state *state = arg; - if (state->vid >= 0) + if (state->selector == SP_VLAN) nla_put_u16(msg, BATADV_ATTR_VLANID, state->vid); return 0; @@ -38,7 +38,7 @@ static int get_ap_isolation(struct state *state) { enum batadv_nl_commands nl_cmd = BATADV_CMD_SET_MESH; - if (state->vid >= 0) + if (state->selector == SP_VLAN) nl_cmd = BATADV_CMD_GET_VLAN; return sys_simple_nlquery(state, nl_cmd, get_attrs_ap_isolation, @@ -53,7 +53,7 @@ static int set_attrs_ap_isolation(struct nl_msg *msg, void *arg) nla_put_u8(msg, BATADV_ATTR_AP_ISOLATION_ENABLED, data->val); - if (state->vid >= 0) + if (state->selector == SP_VLAN) nla_put_u16(msg, BATADV_ATTR_VLANID, state->vid); return 0; @@ -63,7 +63,7 @@ static int set_ap_isolation(struct state *state) { enum batadv_nl_commands nl_cmd = BATADV_CMD_SET_MESH; - if (state->vid >= 0) + if (state->selector == SP_VLAN) nl_cmd = BATADV_CMD_SET_VLAN; return sys_simple_nlquery(state, nl_cmd, set_attrs_ap_isolation, NULL); @@ -81,3 +81,8 @@ COMMAND_NAMED(SUBCOMMAND, 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"); + +COMMAND_NAMED(SUBCOMMAND_VID, 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 for vlan device or id"); diff --git a/functions.c b/functions.c index aad6327..61ea487 100644 --- a/functions.c +++ b/functions.c @@ -919,32 +919,44 @@ static int query_rtnl_link_single(int mesh_ifindex, return 0; } -int translate_mesh_iface(struct state *state) +int translate_vlan_iface(struct state *state, const char *vlandev) { struct rtnl_link_iface_data link_data; unsigned int arg_ifindex; - arg_ifindex = if_nametoindex(state->arg_iface); + arg_ifindex = if_nametoindex(vlandev); if (arg_ifindex == 0) - goto fallback_meshif; + return -ENODEV; query_rtnl_link_single(arg_ifindex, &link_data); if (!link_data.vid_found) - goto fallback_meshif; + return -ENODEV; if (!link_data.link_found) - goto fallback_meshif; + return -EINVAL; if (!link_data.kind_found) - goto fallback_meshif; + return -EINVAL; if (strcmp(link_data.kind, "vlan") != 0) - goto fallback_meshif; + return -EINVAL; if (!if_indextoname(link_data.link, state->mesh_iface)) - goto fallback_meshif; + return -ENODEV; state->vid = link_data.vid; + state->selector = SP_VLAN; + + return 0; +} + +int translate_mesh_iface_vlan(struct state *state, const char *vlandev) +{ + int ret; + + ret = translate_vlan_iface(state, vlandev); + if (ret < 0) + goto fallback_meshif; return 0; @@ -952,9 +964,36 @@ int translate_mesh_iface(struct state *state) /* if there is no vid then the argument must be the * mesh interface */ - snprintf(state->mesh_iface, sizeof(state->mesh_iface), "%s", - state->arg_iface); - state->vid = -1; + snprintf(state->mesh_iface, sizeof(state->mesh_iface), "%s", vlandev); + state->selector = SP_NONE_OR_MESHIF; + + return 0; +} + +int translate_vid(struct state *state, const char *vidstr) +{ + unsigned long vid; + char *endptr; + + if (vidstr[0] == '\0') { + fprintf(stderr, "Error - unparsable vid\n"); + return -EINVAL; + } + + vid = strtoul(vidstr, &endptr, 0); + if (!endptr || *endptr != '\0') { + fprintf(stderr, "Error - unparsable vid\n"); + return -EINVAL; + } + + if (vid > 4095) { + fprintf(stderr, "Error - too large vid (max 4095)\n"); + return -ERANGE; + } + + /* get mesh interface and overwrite vid afterwards */ + state->vid = vid; + state->selector = SP_VLAN; return 0; } diff --git a/functions.h b/functions.h index d4a5568..7474c40 100644 --- a/functions.h +++ b/functions.h @@ -50,7 +50,9 @@ struct ether_addr *translate_mac(const char *mesh_iface, struct ether_addr *resolve_mac(const char *asc); int query_rtnl_link(int ifindex, nl_recvmsg_msg_cb_t func, void *arg); int netlink_simple_request(struct nl_msg *msg); -int translate_mesh_iface(struct state *state); +int translate_mesh_iface_vlan(struct state *state, const char *vlandev); +int translate_vlan_iface(struct state *state, const char *vlandev); +int translate_vid(struct state *state, const char *vidstr); int get_algoname(const char *mesh_iface, char *algoname, size_t algoname_len); int check_mesh_iface(struct state *state); int check_mesh_iface_ownership(struct state *state, char *hard_iface); diff --git a/main.c b/main.c index 278683c..3090877 100644 --- a/main.c +++ b/main.c @@ -28,48 +28,75 @@ extern const struct command *__stop___command[]; static void print_usage(void) { - enum command_type type[] = { - SUBCOMMAND, - DEBUGTABLE, + struct { + const char *label; + uint32_t types; + } type[] = { + { + .label = "commands:\n", + .types = BIT(SUBCOMMAND) | + BIT(SUBCOMMAND_VID), + }, + { + .label = "debug tables: \tdisplay the corresponding debug table\n", + .types = BIT(DEBUGTABLE), + }, + }; + const char *default_prefixes[] = { + "", + NULL, + }; + const char *vlan_prefixes[] = { + "vlan ", + "vid ", + NULL, }; const struct command **p; - char buf[32]; + const char **prefixes; + const char **prefix; + char buf[64]; size_t i; fprintf(stderr, "Usage: batctl [options] command|debug table [parameters]\n"); fprintf(stderr, "options:\n"); - fprintf(stderr, " \t-m mesh interface or VLAN created on top of a mesh interface (default 'bat0')\n"); + fprintf(stderr, " \t-m mesh interface (default 'bat0')\n"); fprintf(stderr, " \t-h print this help (or 'batctl -h' for the parameter help)\n"); fprintf(stderr, " \t-v print version\n"); for (i = 0; i < sizeof(type) / sizeof(*type); i++) { fprintf(stderr, "\n"); - switch (type[i]) { - case SUBCOMMAND: - fprintf(stderr, "commands:\n"); - break; - case DEBUGTABLE: - fprintf(stderr, "debug tables: \tdisplay the corresponding debug table\n"); - break; - } + fprintf(stderr, "%s", type[i].label); for (p = __start___command; p < __stop___command; p++) { const struct command *cmd = *p; - if (cmd->type != type[i]) + if (!(BIT(cmd->type) & type[i].types)) continue; if (!cmd->usage) continue; - if (strcmp(cmd->name, cmd->abbr) == 0) - snprintf(buf, sizeof(buf), "%s", cmd->name); - else - snprintf(buf, sizeof(buf), "%s|%s", cmd->name, - cmd->abbr); + switch (cmd->type) { + case SUBCOMMAND_VID: + prefixes = vlan_prefixes; + break; + default: + prefixes = default_prefixes; + break; + } + + for (prefix = &prefixes[0]; *prefix; prefix++) { + if (strcmp(cmd->name, cmd->abbr) == 0) + snprintf(buf, sizeof(buf), "%s%s", + *prefix, cmd->name); + else + snprintf(buf, sizeof(buf), "%s%s|%s", + *prefix, cmd->name, cmd->abbr); - fprintf(stderr, " \t%-27s%s\n", buf, cmd->usage); + fprintf(stderr, " \t%-35s%s\n", buf, + cmd->usage); + } } } } @@ -93,13 +120,17 @@ static void version(void) exit(EXIT_SUCCESS); } -static const struct command *find_command(const char *name) +static const struct command *find_command_by_types(uint32_t types, + const char *name) { const struct command **p; for (p = __start___command; p < __stop___command; p++) { const struct command *cmd = *p; + if (!(BIT(cmd->type) & types)) + continue; + if (strcmp(cmd->name, name) == 0) return cmd; @@ -110,13 +141,123 @@ static const struct command *find_command(const char *name) return NULL; } +static const struct command *find_command(struct state *state, const char *name) +{ + uint32_t types; + + switch (state->selector) { + case SP_NONE_OR_MESHIF: + types = BIT(SUBCOMMAND) | + BIT(DEBUGTABLE); + break; + case SP_VLAN: + types = BIT(SUBCOMMAND_VID); + break; + default: + return NULL; + } + + return find_command_by_types(types, name); +} + +static int detect_selector_prefix(int argc, char *argv[], + enum selector_prefix *selector) +{ + /* not enough remaining arguments to detect anything */ + if (argc < 2) + return -EINVAL; + + /* only detect selector prefix which identifies meshif */ + if (strcmp(argv[0], "vlan") == 0) { + *selector = SP_VLAN; + return 2; + } + + return 0; +} + +static int parse_meshif_args(struct state *state, int argc, char *argv[]) +{ + enum selector_prefix selector; + int parsed_args; + char *dev_arg; + int ret; + + parsed_args = detect_selector_prefix(argc, argv, &selector); + if (parsed_args < 1) + goto fallback_meshif_vlan; + + dev_arg = argv[parsed_args - 1]; + + switch (selector) { + case SP_VLAN: + ret = translate_vlan_iface(state, dev_arg); + if (ret < 0) { + fprintf(stderr, "Error - invalid vlan device %s: %s\n", + dev_arg, strerror(-ret)); + return ret; + } + + return parsed_args; + case SP_NONE_OR_MESHIF: + /* not allowed - see detect_selector_prefix */ + break; + } + +fallback_meshif_vlan: + /* parse vlan as part of -m parameter or mesh_dfl_iface */ + translate_mesh_iface_vlan(state, state->arg_iface); + return 0; +} + +static int parse_dev_args(struct state *state, int argc, char *argv[]) +{ + int dev_arguments; + int ret; + + /* try to parse selector prefix which can be used to identify meshif */ + dev_arguments = parse_meshif_args(state, argc, argv); + if (dev_arguments < 0) + return dev_arguments; + + /* try to parse secondary prefix selectors which cannot be used to + * identify the meshif + */ + argv += dev_arguments; + argc -= dev_arguments; + + switch (state->selector) { + case SP_NONE_OR_MESHIF: + /* continue below */ + break; + default: + return dev_arguments; + } + + /* enough room for additional selectors? */ + if (argc < 2) + return dev_arguments; + + if (strcmp(argv[0], "vid") == 0) { + ret = translate_vid(state, argv[1]); + if (ret < 0) + return ret; + + return dev_arguments + 2; + } + + return dev_arguments; +} + int main(int argc, char **argv) { const struct command *cmd; struct state state = { .arg_iface = mesh_dfl_iface, + .selector = SP_NONE_OR_MESHIF, .cmd = NULL, }; + int dev_arguments; int opt; int ret; @@ -152,7 +293,20 @@ int main(int argc, char **argv) argc -= optind; optind = 0; - cmd = find_command(argv[0]); + /* parse arguments to identify vlan, ... */ + dev_arguments = parse_dev_args(&state, argc, argv); + if (dev_arguments < 0) + goto err; + + argv += dev_arguments; + argc -= dev_arguments; + + if (argc == 0) { + fprintf(stderr, "Error - no command specified\n"); + goto err; + } + + cmd = find_command(&state, argv[0]); if (!cmd) { fprintf(stderr, "Error - no valid command or debug table specified: %s\n", @@ -162,8 +316,6 @@ int main(int argc, char **argv) state.cmd = cmd; - translate_mesh_iface(&state); - if (cmd->flags & COMMAND_FLAG_MESH_IFACE && check_mesh_iface(&state) < 0) { fprintf(stderr, diff --git a/main.h b/main.h index 3978797..846efed 100644 --- a/main.h +++ b/main.h @@ -56,13 +56,20 @@ enum command_flags { COMMAND_FLAG_INVERSE = BIT(2), }; +enum selector_prefix { + SP_NONE_OR_MESHIF, + SP_VLAN, +}; + enum command_type { SUBCOMMAND, + SUBCOMMAND_VID, DEBUGTABLE, }; struct state { char *arg_iface; + enum selector_prefix selector; char mesh_iface[IF_NAMESIZE]; unsigned int mesh_ifindex; int vid; @@ -84,7 +91,7 @@ struct command { }; #define COMMAND_NAMED(_type, _name, _abbr, _handler, _flags, _arg, _usage) \ - static const struct command command_ ## _name = { \ + static const struct command command_ ## _name ## _ ## _type = { \ .type = (_type), \ .name = (#_name), \ .abbr = _abbr, \ @@ -93,8 +100,8 @@ struct command { .arg = (_arg), \ .usage = (_usage), \ }; \ - static const struct command *__command_ ## _name \ - __attribute__((__used__)) __attribute__ ((__section__ ("__command"))) = &command_ ## _name + static const struct command *__command_ ## _name ## _ ## _type \ + __attribute__((__used__)) __attribute__ ((__section__ ("__command"))) = &command_ ## _name ## _ ## _type #define COMMAND(_type, _handler, _abbr, _flags, _arg, _usage) \ COMMAND_NAMED(_type, _handler, _abbr, _handler, _flags, _arg, _usage) diff --git a/man/batctl.8 b/man/batctl.8 index 0b43031..a5656cf 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -46,7 +46,7 @@ performances, is also included. .SH OPTIONS .TP .I \fBoptions: -\-m specify mesh interface or VLAN created on top of a mesh interface (default 'bat0') +\-m specify mesh interface (default 'bat0') .br \-h print general batctl help .br @@ -70,7 +70,11 @@ originator interval. The interval is in units of milliseconds. .br .IP "\fBap_isolation\fP|\fBap\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current ap isolation setting is displayed. Otherwise the parameter is used to enable or -disable ap isolation. This command can be used in conjunction with "\-m" option to target per VLAN configurations. +disable ap isolation. +.br +.IP "<\fBvlan \fP|\fBvid \fP> \fBap_isolation\fP|\fBap\fP [\fB0\fP|\fB1\fP]" +If no parameter is given the current ap isolation setting for the specified VLAN is displayed. Otherwise the parameter is used to enable or +disable ap isolation for the specified VLAN. .br .IP "\fBbridge_loop_avoidance\fP|\fBbl\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current bridge loop avoidance setting is displayed. Otherwise the parameter is used to enable diff --git a/sys.c b/sys.c index 39123db..61a314d 100644 --- a/sys.c +++ b/sys.c @@ -141,9 +141,35 @@ int sys_simple_print_boolean(struct nl_msg *msg, void *arg, static void settings_usage(struct state *state) { - fprintf(stderr, "Usage: batctl [options] %s|%s [parameters] %s\n", - state->cmd->name, state->cmd->abbr, - state->cmd->usage ? state->cmd->usage : ""); + const char *default_prefixes[] = { + "", + NULL, + }; + const char *vlan_prefixes[] = { + "vlan ", + "vid ", + NULL, + }; + const char *linestart = "Usage:"; + const char **prefixes; + const char **prefix; + + switch (state->cmd->type) { + case SUBCOMMAND_VID: + prefixes = vlan_prefixes; + break; + default: + prefixes = default_prefixes; + break; + } + + for (prefix = &prefixes[0]; *prefix; prefix++) { + fprintf(stderr, "%s batctl [options] %s%s|%s [parameters] %s\n", + linestart, *prefix, state->cmd->name, state->cmd->abbr, + state->cmd->usage ? state->cmd->usage : ""); + + linestart = " "; + } fprintf(stderr, "parameters:\n"); fprintf(stderr, " \t -h print this help\n"); @@ -233,15 +259,19 @@ int handle_sys_setting(struct state *state, int argc, char **argv) return EXIT_FAILURE; } - /* if the specified interface is a VLAN then change the path to point - * to the proper "vlan%{vid}" subfolder in the sysfs tree. - */ - if (state->vid >= 0) - snprintf(path_buff, PATH_BUFF_LEN, SYS_VLAN_PATH, - state->mesh_iface, state->vid); - else + switch (state->selector) { + case SP_NONE_OR_MESHIF: snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, state->mesh_iface); + break; + case SP_VLAN: + /* if the specified interface is a VLAN then change the path to + * point to the proper "vlan%{vid}" subfolder in the sysfs tree. + */ + snprintf(path_buff, PATH_BUFF_LEN, SYS_VLAN_PATH, + state->mesh_iface, state->vid); + break; + } if (argc == 1) { res = sys_read_setting(state, path_buff, settings->sysfs_name); From patchwork Tue Jul 9 17:26:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17996 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id E4AF0821FE; Tue, 9 Jul 2019 19:27:06 +0200 (CEST) Received: from dvalin.narfation.org (dvalin.narfation.org [IPv6:2a00:17d8:100::8b1]) by open-mesh.org (Postfix) with ESMTPS id 385EA81F33 for ; Tue, 9 Jul 2019 19:27:04 +0200 (CEST) Received: from sven-desktop.home.narfation.org (unknown [IPv6:2a00:1ca0:1480:f9fc::4065]) by dvalin.narfation.org (Postfix) with ESMTPSA id CCA981FDB9; Tue, 9 Jul 2019 17:27:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1562693223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i9qeESC+Ot1hRXjY6eYceEgf+kaDpZTA8PPigfx0uxg=; b=sTDdBrT/WVjVB95Hxz+/pFB11MBWtEOVPYDaJEHPtSbLNPaTQ+twlZDBTIyiF0tw6wvC5X GV1FNBXVKGA8LIGXfIFeppXzeUfAivulrVuY9y3qFAKYFz0a1FN7vPr518FFAkJxfu9xuR yqhcOrudhKGRrmlhx7IPPe+L5CjIw9g= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Subject: [PATCH v3 2/6] batctl: Integrate hardif setting framework Date: Tue, 9 Jul 2019 19:26:47 +0200 Message-Id: <20190709172651.5869-3-sven@narfation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190709172651.5869-1-sven@narfation.org> References: <20190709172651.5869-1-sven@narfation.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1562693223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i9qeESC+Ot1hRXjY6eYceEgf+kaDpZTA8PPigfx0uxg=; b=GHLIkaQTrexrASYwiENY7k4s2da9VQizFUobRYXRe34ZJPcHW4i3TeULn2UCc5Mbp+alCa DQEuB9Mr7l6YbeH3Mfnz7LKy0uBV4KPRHYM6AGdLRtOLyQNoNlGsQO6j+teE760TnJUyzy ML/PLsaDTJdk228Xj774ci7VzglqrcQ= ARC-Seal: i=1; s=20121; d=narfation.org; t=1562693223; a=rsa-sha256; cv=none; b=ZaUKmlLnzc3Bu5desBMpsCxvj5t+COpSBs8+2pnKLO3gVt6OURq1NYLfW6MU4gN/cbDyiC UXKv0zpdIMApehbzihAx6eOrQLOd55Vcwf6XgoMzuugwq8Rs45jTPFODUrX3HKQddGXlCB GnzpdO4Oy2JXQhCqFhn1bJ9aXp+R1FU= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=sven smtp.mailfrom=sven@narfation.org X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" batctl currently supports settings which are either mesh interface or vlan specific. But B.A.T.M.A.N. V introduced two additional settings which are hard (slave) interface specific. To support these, an additional command prefix called hardif is implemented for some sysfs commands: $ batctl hardif eth0 ... Signed-off-by: Sven Eckelmann --- functions.c | 22 ++++++++++++++++++++++ functions.h | 1 + main.c | 26 +++++++++++++++++++++++++- main.h | 8 +++++++- sys.c | 15 +++++++++++++++ sys.h | 5 +++-- 6 files changed, 73 insertions(+), 4 deletions(-) diff --git a/functions.c b/functions.c index 61ea487..4ffa86c 100644 --- a/functions.c +++ b/functions.c @@ -998,6 +998,28 @@ int translate_vid(struct state *state, const char *vidstr) return 0; } +int translate_hard_iface(struct state *state, const char *hardif) +{ + struct rtnl_link_iface_data link_data; + unsigned int arg_ifindex; + + arg_ifindex = if_nametoindex(hardif); + if (arg_ifindex == 0) + return -ENODEV; + + query_rtnl_link_single(arg_ifindex, &link_data); + if (!link_data.master_found) + return -ENOLINK; + + if (!if_indextoname(link_data.master, state->mesh_iface)) + return -ENOLINK; + + state->hif = arg_ifindex; + state->selector = SP_HARDIF; + + return 0; +} + static int check_mesh_iface_netlink(struct state *state) { struct rtnl_link_iface_data link_data; diff --git a/functions.h b/functions.h index 7474c40..0a08870 100644 --- a/functions.h +++ b/functions.h @@ -53,6 +53,7 @@ int netlink_simple_request(struct nl_msg *msg); int translate_mesh_iface_vlan(struct state *state, const char *vlandev); int translate_vlan_iface(struct state *state, const char *vlandev); int translate_vid(struct state *state, const char *vidstr); +int translate_hard_iface(struct state *state, const char *hardif); int get_algoname(const char *mesh_iface, char *algoname, size_t algoname_len); int check_mesh_iface(struct state *state); int check_mesh_iface_ownership(struct state *state, char *hard_iface); diff --git a/main.c b/main.c index 3090877..3b3a16f 100644 --- a/main.c +++ b/main.c @@ -35,7 +35,8 @@ static void print_usage(void) { .label = "commands:\n", .types = BIT(SUBCOMMAND) | - BIT(SUBCOMMAND_VID), + BIT(SUBCOMMAND_VID) | + BIT(SUBCOMMAND_HIF), }, { .label = "debug tables: \tdisplay the corresponding debug table\n", @@ -51,6 +52,10 @@ static void print_usage(void) "vid ", NULL, }; + const char *hardif_prefixes[] = { + "hardif ", + NULL, + }; const struct command **p; const char **prefixes; const char **prefix; @@ -81,6 +86,9 @@ static void print_usage(void) case SUBCOMMAND_VID: prefixes = vlan_prefixes; break; + case SUBCOMMAND_HIF: + prefixes = hardif_prefixes; + break; default: prefixes = default_prefixes; break; @@ -153,6 +161,9 @@ static const struct command *find_command(struct state *state, const char *name) case SP_VLAN: types = BIT(SUBCOMMAND_VID); break; + case SP_HARDIF: + types = BIT(SUBCOMMAND_HIF); + break; default: return NULL; } @@ -171,6 +182,9 @@ static int detect_selector_prefix(int argc, char *argv[], if (strcmp(argv[0], "vlan") == 0) { *selector = SP_VLAN; return 2; + } else if (strcmp(argv[0], "hardif") == 0) { + *selector = SP_HARDIF; + return 2; } return 0; @@ -197,7 +211,17 @@ static int parse_meshif_args(struct state *state, int argc, char *argv[]) dev_arg, strerror(-ret)); return ret; } + return parsed_args; + case SP_HARDIF: + ret = translate_hard_iface(state, dev_arg); + if (ret < 0) { + fprintf(stderr, "Error - invalid hardif %s: %s\n", + dev_arg, strerror(-ret)); + return ret; + } + snprintf(state->hard_iface, sizeof(state->hard_iface), "%s", + dev_arg); return parsed_args; case SP_NONE_OR_MESHIF: /* not allowed - see detect_selector_prefix */ diff --git a/main.h b/main.h index 846efed..e3a95b5 100644 --- a/main.h +++ b/main.h @@ -59,11 +59,13 @@ enum command_flags { enum selector_prefix { SP_NONE_OR_MESHIF, SP_VLAN, + SP_HARDIF, }; enum command_type { SUBCOMMAND, SUBCOMMAND_VID, + SUBCOMMAND_HIF, DEBUGTABLE, }; @@ -72,7 +74,11 @@ struct state { enum selector_prefix selector; char mesh_iface[IF_NAMESIZE]; unsigned int mesh_ifindex; - int vid; + char hard_iface[IF_NAMESIZE]; + union { + unsigned int hif; + int vid; + }; const struct command *cmd; struct nl_sock *sock; diff --git a/sys.c b/sys.c index 61a314d..b9555ee 100644 --- a/sys.c +++ b/sys.c @@ -150,6 +150,10 @@ static void settings_usage(struct state *state) "vid ", NULL, }; + const char *hardif_prefixes[] = { + "hardif ", + NULL, + }; const char *linestart = "Usage:"; const char **prefixes; const char **prefix; @@ -158,6 +162,9 @@ static void settings_usage(struct state *state) case SUBCOMMAND_VID: prefixes = vlan_prefixes; break; + case SUBCOMMAND_HIF: + prefixes = hardif_prefixes; + break; default: prefixes = default_prefixes; break; @@ -271,6 +278,14 @@ int handle_sys_setting(struct state *state, int argc, char **argv) snprintf(path_buff, PATH_BUFF_LEN, SYS_VLAN_PATH, state->mesh_iface, state->vid); break; + case SP_HARDIF: + /* if a hard interface was specified then change the path to + * point to the proper ${hardif}/batman-adv path in the sysfs + * tree. + */ + snprintf(path_buff, PATH_BUFF_LEN, SYS_HARDIF_PATH, + state->hard_iface); + break; } if (argc == 1) { diff --git a/sys.h b/sys.h index d4f2fcf..b6f0f90 100644 --- a/sys.h +++ b/sys.h @@ -21,8 +21,9 @@ #define SYS_BATIF_PATH_FMT "/sys/class/net/%s/mesh/" #define SYS_IFACE_PATH "/sys/class/net" #define SYS_IFACE_DIR SYS_IFACE_PATH"/%s/" -#define SYS_MESH_IFACE_FMT SYS_IFACE_PATH"/%s/batman_adv/mesh_iface" -#define SYS_IFACE_STATUS_FMT SYS_IFACE_PATH"/%s/batman_adv/iface_status" +#define SYS_HARDIF_PATH SYS_IFACE_DIR "batman_adv/" +#define SYS_MESH_IFACE_FMT SYS_HARDIF_PATH "mesh_iface" +#define SYS_IFACE_STATUS_FMT SYS_HARDIF_PATH "iface_status" #define SYS_VLAN_PATH SYS_IFACE_PATH"/%s/mesh/vlan%d/" #define SYS_ROUTING_ALGO_FMT SYS_IFACE_PATH"/%s/mesh/routing_algo" #define VLAN_ID_MAX_LEN 4 From patchwork Tue Jul 9 17:26:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17997 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id 8E07A82151; Tue, 9 Jul 2019 19:27:10 +0200 (CEST) Received: from dvalin.narfation.org (dvalin.narfation.org [IPv6:2a00:17d8:100::8b1]) by open-mesh.org (Postfix) with ESMTPS id 774EB8222F for ; Tue, 9 Jul 2019 19:27:08 +0200 (CEST) Received: from sven-desktop.home.narfation.org (unknown [IPv6:2a00:1ca0:1480:f9fc::4065]) by dvalin.narfation.org (Postfix) with ESMTPSA id 278E01FDB9; Tue, 9 Jul 2019 17:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1562693228; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FJvYY5rPcJTkyxSxXLb+jsUXnS2/1+4mZu+uRKVGQiQ=; b=z/Sh1nKGePJlk6/SV7VJ49wzEuCI7yZ9qPX8xd1VkfxsKOv1dZV1LLRpfsoJlRaMWFMNHN deBOuSbPzsSFCDeAYM10RGbY8JUH/yTP4R7v7ao/duB7bWnx3hxa2Lo4xRdRjD81zbcgV2 n5u7wg9BT3yYJNm2OnJXG0I10ol7oko= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Subject: [PATCH v3 3/6] batctl: Add elp_interval setting command Date: Tue, 9 Jul 2019 19:26:48 +0200 Message-Id: <20190709172651.5869-4-sven@narfation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190709172651.5869-1-sven@narfation.org> References: <20190709172651.5869-1-sven@narfation.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1562693228; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FJvYY5rPcJTkyxSxXLb+jsUXnS2/1+4mZu+uRKVGQiQ=; b=a7ZQ0yF2eaCZdohTTtfZgP1WQwlEVhzx/ZSaXIyVSdmdzdo2fBaMUEr21Z91hqahKfoR/e k44YrdKgIVv+XUEJ1+EkNsUBtJFr1RFX/SKnq5Ik3JPFGMLlB8+z2wVv/9g3nHfGqX59F3 DkWh2WQvx/Hoh9Ixr9sltflJEElgvhY= ARC-Seal: i=1; s=20121; d=narfation.org; t=1562693228; a=rsa-sha256; cv=none; b=LoQJbYKY+uBzQyPCeHxHQd+X8xmY1VTldT7nSDv6GlPRPqIY7mADLvdwod6+CmIfHC48h7 iqki4H5vQI5COMGErWyycVrnMJM7VFs/dr1sSmxuggIt8zSrXpQR1joDUD33KcJEi9P8WI 2K0a9oSoQ1TsgKTYjBouxRL+8U25LPA= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=sven smtp.mailfrom=sven@narfation.org X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" B.A.T.M.A.N. V introduced a hard interface specific setting called elp_interval. It defines the interval in milliseconds in which batman-adv emits probing packets for neighbor sensing (ELP). Signed-off-by: Sven Eckelmann --- Makefile | 1 + README.rst | 16 +++++++ elp_interval.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++ man/batctl.8 | 4 ++ 4 files changed, 132 insertions(+) create mode 100644 elp_interval.c diff --git a/Makefile b/Makefile index b7bd545..f071da2 100755 --- a/Makefile +++ b/Makefile @@ -45,6 +45,7 @@ $(eval $(call add_command,bridge_loop_avoidance,y)) $(eval $(call add_command,claimtable,y)) $(eval $(call add_command,dat_cache,y)) $(eval $(call add_command,distributed_arp_table,y)) +$(eval $(call add_command,elp_interval,y)) $(eval $(call add_command,event,y)) $(eval $(call add_command,fragmentation,y)) $(eval $(call add_command,gateways,y)) diff --git a/README.rst b/README.rst index bc54412..92983aa 100644 --- a/README.rst +++ b/README.rst @@ -386,6 +386,22 @@ Example:: 1000 +batctl elp interval +=================== + +display or modify the elp interval in ms for hard interface + +Usage:: + + batctl hardif $hardif elp_interval|et [interval] + +Example:: + + $ batctl hardif eth0 elp_interval 200 + $ batctl hardif eth0 elp_interval + 200 + + batctl loglevel =============== diff --git a/elp_interval.c b/elp_interval.c new file mode 100644 index 0000000..0a5e989 --- /dev/null +++ b/elp_interval.c @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors: + * + * Marek Lindner + * + * License-Filename: LICENSES/preferred/GPL-2.0 + */ + +#include +#include +#include +#include + +#include "main.h" +#include "sys.h" + +static struct elp_interval_data { + uint32_t elp_interval; +} elp_interval; + +static int parse_elp_interval(struct state *state, int argc, char *argv[]) +{ + struct settings_data *settings = state->cmd->arg; + struct elp_interval_data *data = settings->data; + char *endptr; + + if (argc != 2) { + fprintf(stderr, "Error - incorrect number of arguments (expected 1)\n"); + return -EINVAL; + } + + data->elp_interval = strtoul(argv[1], &endptr, 0); + if (!endptr || *endptr != '\0') { + fprintf(stderr, "Error - the supplied argument is invalid: %s\n", argv[1]); + return -EINVAL; + } + + return 0; +} + +static int print_elp_interval(struct nl_msg *msg, void *arg) +{ + struct nlattr *attrs[BATADV_ATTR_MAX + 1]; + struct nlmsghdr *nlh = nlmsg_hdr(msg); + struct genlmsghdr *ghdr; + int *result = arg; + + if (!genlmsg_valid_hdr(nlh, 0)) + return NL_OK; + + ghdr = nlmsg_data(nlh); + + if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), + genlmsg_len(ghdr), batadv_netlink_policy)) { + return NL_OK; + } + + if (!attrs[BATADV_ATTR_ELP_INTERVAL]) + return NL_OK; + + printf("%u\n", nla_get_u32(attrs[BATADV_ATTR_ELP_INTERVAL])); + + *result = 0; + return NL_STOP; +} + +static int get_attrs_elp_interval(struct nl_msg *msg, void *arg) +{ + struct state *state = arg; + + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, state->hif); + + return 0; +} + +static int get_elp_interval(struct state *state) +{ + return sys_simple_nlquery(state, BATADV_CMD_GET_HARDIF, + get_attrs_elp_interval, print_elp_interval); +} + +static int set_attrs_elp_interval(struct nl_msg *msg, void *arg) +{ + struct state *state = arg; + struct settings_data *settings = state->cmd->arg; + struct elp_interval_data *data = settings->data; + + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, state->hif); + nla_put_u32(msg, BATADV_ATTR_ELP_INTERVAL, data->elp_interval); + + return 0; +} + +static int set_elp_interval(struct state *state) +{ + return sys_simple_nlquery(state, BATADV_CMD_SET_HARDIF, + set_attrs_elp_interval, NULL); +} + +static struct settings_data batctl_settings_elp_interval = { + .sysfs_name = "elp_interval", + .data = &elp_interval, + .parse = parse_elp_interval, + .netlink_get = get_elp_interval, + .netlink_set = set_elp_interval, +}; + +COMMAND_NAMED(SUBCOMMAND_HIF, elp_interval, "et", handle_sys_setting, + COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK, + &batctl_settings_elp_interval, + "[interval] \tdisplay or modify elp_interval setting"); diff --git a/man/batctl.8 b/man/batctl.8 index a5656cf..eef7cd8 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -97,6 +97,10 @@ the bonding mode. batctl will monitor for events from the netlink kernel interface of batman-adv. The local timestamp of the event will be printed when parameter \fB\-t\fP is specified. Parameter \fB\-r\fP will do the same but with relative timestamps. .br +.IP "\fBhardif \fP \fBelp_interval\fP|\fBet\fP [\fBinterval\fP]" +If no parameter is given the current ELP interval setting of the hard interface is displayed otherwise the parameter is used to set the +ELP interval. The interval is in units of milliseconds. +.br .IP "\fBfragmentation\fP|\fBf\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current fragmentation mode setting is displayed. Otherwise the parameter is used to enable or disable fragmentation. From patchwork Tue Jul 9 17:26:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17998 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id 200ED80D96; Tue, 9 Jul 2019 19:27:15 +0200 (CEST) Received: from dvalin.narfation.org (dvalin.narfation.org [213.160.73.56]) by open-mesh.org (Postfix) with ESMTPS id A9593823E0 for ; Tue, 9 Jul 2019 19:27:11 +0200 (CEST) Received: from sven-desktop.home.narfation.org (unknown [IPv6:2a00:1ca0:1480:f9fc::4065]) by dvalin.narfation.org (Postfix) with ESMTPSA id B9A511FDB9; Tue, 9 Jul 2019 17:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1562693230; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PQdeA3WRmQB0jbesSmggsFDcxD3R5c2E64KroEc84PE=; b=BHNeWmtvHERmFA/ooXpCvrVpSncjmTpaP54MHcq47d6818yNBXMdLoohsuw8LRnhQDlChF tcjy3TqKC4y4/rOi8XIgb2L4nxXyz5lIbtEvVAWeljW6asfrZAGCqn85X4S0IRELamaDDJ BIUU4u35btLwGDXkMhe5sREVdELFg7E= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Subject: [PATCH v3 4/6] batctl: Add throughput_override setting command Date: Tue, 9 Jul 2019 19:26:49 +0200 Message-Id: <20190709172651.5869-5-sven@narfation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190709172651.5869-1-sven@narfation.org> References: <20190709172651.5869-1-sven@narfation.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1562693230; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PQdeA3WRmQB0jbesSmggsFDcxD3R5c2E64KroEc84PE=; b=wI1Y57TUIx0JgalxZMrhtDR7o/iygsW00FCheYTxwr6b00OqijMpTBHONYV3Va+71cM2ZA SJZNDWI9++sGf4vFrxcD11A4xx9un15tVVypF1v3IybwtlqZXYp5AICwzoTXrHshExdFxC NNqBR4bSWzMKEYBWGaOa+RwtrqTw1qc= ARC-Seal: i=1; s=20121; d=narfation.org; t=1562693230; a=rsa-sha256; cv=none; b=lnPm9+Y9Y+U7b3joLYB0UxVoP2k7fNoTUfKCkHHds2i17AJJRI6r0Y5XLW+zZMNrBkr3Or gi6QlJD4gGSbwkuuGU1sGg60DpzBnm2hZ1viYJ3bwI+xh/p0Hn2UDFtDSBX7VZj03Zk+ge TLJiAmP5i79LfIOk8Ns/Y7PYmrhKi64= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=sven smtp.mailfrom=sven@narfation.org X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" B.A.T.M.A.N. V introduced a hard interface specific setting called throughput. It defines the throughput value to be used by B.A.T.M.A.N. V when estimating the link throughput using this interface. If the value is set to 0 then batman-adv will try to estimate the throughput by itself. Signed-off-by: Sven Eckelmann --- Makefile | 1 + README.rst | 17 +++++++ man/batctl.8 | 6 +++ throughput_override.c | 113 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 throughput_override.c diff --git a/Makefile b/Makefile index f071da2..e3747a2 100755 --- a/Makefile +++ b/Makefile @@ -67,6 +67,7 @@ $(eval $(call add_command,ping,y)) $(eval $(call add_command,routing_algo,y)) $(eval $(call add_command,statistics,y)) $(eval $(call add_command,tcpdump,y)) +$(eval $(call add_command,throughput_override,y)) $(eval $(call add_command,throughputmeter,y)) $(eval $(call add_command,traceroute,y)) $(eval $(call add_command,transglobal,y)) diff --git a/README.rst b/README.rst index 92983aa..128f539 100644 --- a/README.rst +++ b/README.rst @@ -402,6 +402,23 @@ Example:: 200 +batctl throughput override +========================== + +display or modify the throughput override in kbit/s for hard interface + +Usage:: + + batctl hardif $hardif throughput_override|to [kbit] + +Example:: + + $ batctl hardif eth0 throughput_override 15000 + $ batctl hardif eth0 throughput_override 15mbit + $ batctl hardif eth0 throughput_override + 15.0 MBit + + batctl loglevel =============== diff --git a/man/batctl.8 b/man/batctl.8 index eef7cd8..d42b682 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -207,6 +207,12 @@ supported routing algorithms are displayed. Otherwise the parameter is used to select the routing algorithm for the following batX interface to be created. .br +.IP "\fBhardif \fP \fBthroughput_override|to\fP [\fBbandwidth\fP]\fP" +If no parameter is given the current througput override is displayed otherwise +the parameter is used to set the throughput override for the specified hard +interface. +Just enter any number (optionally followed by "kbit" or "mbit"). +.br .IP "\fBisolation_mark\fP|\fBmark\fP" If no parameter is given the current isolation mark value is displayed. Otherwise the parameter is used to set or unset the isolation mark used by the diff --git a/throughput_override.c b/throughput_override.c new file mode 100644 index 0000000..28a6588 --- /dev/null +++ b/throughput_override.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors: + * + * Marek Lindner + * + * License-Filename: LICENSES/preferred/GPL-2.0 + */ + +#include +#include +#include +#include + +#include "functions.h" +#include "main.h" +#include "sys.h" + +static struct throughput_override_data { + uint32_t throughput_override; +} throughput_override; + +static int parse_throughput_override(struct state *state, int argc, char *argv[]) +{ + struct settings_data *settings = state->cmd->arg; + struct throughput_override_data *data = settings->data; + bool ret; + + if (argc != 2) { + fprintf(stderr, "Error - incorrect number of arguments (expected 1)\n"); + return -EINVAL; + } + + ret = parse_throughput(argv[1], "throughput override", + &data->throughput_override); + if (!ret) + return -EINVAL; + + return 0; +} + +static int print_throughput_override(struct nl_msg *msg, void *arg) +{ + struct nlattr *attrs[BATADV_ATTR_MAX + 1]; + struct nlmsghdr *nlh = nlmsg_hdr(msg); + struct genlmsghdr *ghdr; + int *result = arg; + uint32_t mbit; + + if (!genlmsg_valid_hdr(nlh, 0)) + return NL_OK; + + ghdr = nlmsg_data(nlh); + + if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), + genlmsg_len(ghdr), batadv_netlink_policy)) { + return NL_OK; + } + + if (!attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE]) + return NL_OK; + + mbit = nla_get_u32(attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE]); + printf("%u.%u MBit\n", mbit / 10, mbit % 10); + + *result = 0; + return NL_STOP; +} + +static int get_attrs_elp_isolation(struct nl_msg *msg, void *arg) +{ + struct state *state = arg; + + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, state->hif); + + return 0; +} + +static int get_throughput_override(struct state *state) +{ + return sys_simple_nlquery(state, BATADV_CMD_GET_HARDIF, + get_attrs_elp_isolation, print_throughput_override); +} + +static int set_attrs_throughput_override(struct nl_msg *msg, void *arg) +{ + struct state *state = arg; + struct settings_data *settings = state->cmd->arg; + struct throughput_override_data *data = settings->data; + + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, state->hif); + nla_put_u32(msg, BATADV_ATTR_THROUGHPUT_OVERRIDE, data->throughput_override); + + return 0; +} + +static int set_throughput_override(struct state *state) +{ + return sys_simple_nlquery(state, BATADV_CMD_SET_HARDIF, + set_attrs_throughput_override, NULL); +} + +static struct settings_data batctl_settings_throughput_override = { + .sysfs_name = "throughput_override", + .data = &throughput_override, + .parse = parse_throughput_override, + .netlink_get = get_throughput_override, + .netlink_set = set_throughput_override, +}; + +COMMAND_NAMED(SUBCOMMAND_HIF, throughput_override, "to", handle_sys_setting, + COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK, + &batctl_settings_throughput_override, + "[mbit] \tdisplay or modify throughput_override setting"); From patchwork Tue Jul 9 17:26:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17999 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id A4622824C1; Tue, 9 Jul 2019 19:27:18 +0200 (CEST) Received: from dvalin.narfation.org (dvalin.narfation.org [213.160.73.56]) by open-mesh.org (Postfix) with ESMTPS id B57CB823E0 for ; Tue, 9 Jul 2019 19:27:15 +0200 (CEST) Received: from sven-desktop.home.narfation.org (unknown [IPv6:2a00:1ca0:1480:f9fc::4065]) by dvalin.narfation.org (Postfix) with ESMTPSA id 21DF31FDB9; Tue, 9 Jul 2019 17:27:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1562693233; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LrcE6R2o26oEQGuoGYqTrta9SpkAQFdiIL/H77HUvqI=; b=rhhZcozINIpdVkf96sYQvh68ES+ra2FmvX/eU9RXEt+SSkhGYXAU+nMhYLIDYAmcdSF0fE 8cqJTgPdwkyj4jiAS891ZTDpCYETCHLvOB4XgVeP7QQ2RVxrO7Iup4nIS3rewTCkAIef8b f/6JiXf5u/vzaO+Z+i7QWmLKL4OfYwc= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Subject: [PATCH v3 5/6] batctl: Replace '-m meshif' option with selector prefix Date: Tue, 9 Jul 2019 19:26:50 +0200 Message-Id: <20190709172651.5869-6-sven@narfation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190709172651.5869-1-sven@narfation.org> References: <20190709172651.5869-1-sven@narfation.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1562693233; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LrcE6R2o26oEQGuoGYqTrta9SpkAQFdiIL/H77HUvqI=; b=R1x6w9mxDKEz16Dsu6FfCQKyuk/vOvhS7UMoI7D472CW1s3zK4p17QJKRi2KefaxnSmWik JNyIzf32AltoFo3++OgxGXHCiXwug4X5FjcsVJUi98HF90moowpvY2uU3H+ab8Dg+zCqL1 XLq2rc++nRz5GpSoW71AHM5RI0qboQg= ARC-Seal: i=1; s=20121; d=narfation.org; t=1562693233; a=rsa-sha256; cv=none; b=f3hK1tWeU3tMZIXgA77I5Na35QVC3MiZUowrItFP6ppikFGnP8bFP/nu+nOxKy7zTefOBk PSVOu02tdCF2dTk4ejLfrFqWDJFsNO3cZe03DGOunsOabI9qAwVnBJALgedECdSgOaUdkn ThM3sTAbTzM9Jmh1CtMEXEjPt0FA5HE= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=sven smtp.mailfrom=sven@narfation.org X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" 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: Sven Eckelmann --- aggregation.c | 2 +- ap_isolation.c | 2 +- bonding.c | 2 +- bridge_loop_avoidance.c | 2 +- distributed_arp_table.c | 2 +- fragmentation.c | 2 +- gw_mode.c | 2 +- hop_penalty.c | 2 +- interface.c | 2 +- isolation_mark.c | 2 +- loglevel.c | 2 +- main.c | 33 +++++++++++++++++++++++++------ main.h | 2 ++ man/batctl.8 | 44 ++++++++++++++++++++--------------------- multicast_fanout.c | 2 +- multicast_forceflood.c | 2 +- multicast_mode.c | 2 +- network_coding.c | 2 +- orig_interval.c | 2 +- ping.c | 2 +- statistics.c | 2 +- sys.c | 10 +++++++++- throughputmeter.c | 2 +- traceroute.c | 2 +- translate.c | 2 +- 25 files changed, 81 insertions(+), 50 deletions(-) diff --git a/aggregation.c b/aggregation.c index 18e19d8..b9edd94 100644 --- a/aggregation.c +++ b/aggregation.c @@ -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"); diff --git a/ap_isolation.c b/ap_isolation.c index 36fd4d6..66f8340 100644 --- a/ap_isolation.c +++ b/ap_isolation.c @@ -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"); diff --git a/bonding.c b/bonding.c index fd95e8d..e41379c 100644 --- a/bonding.c +++ b/bonding.c @@ -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"); diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c index 37acaa7..2994d2e 100644 --- a/bridge_loop_avoidance.c +++ b/bridge_loop_avoidance.c @@ -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"); diff --git a/distributed_arp_table.c b/distributed_arp_table.c index cbfb296..ad88d43 100644 --- a/distributed_arp_table.c +++ b/distributed_arp_table.c @@ -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"); diff --git a/fragmentation.c b/fragmentation.c index d4b0f54..eea2a08 100644 --- a/fragmentation.c +++ b/fragmentation.c @@ -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"); diff --git a/gw_mode.c b/gw_mode.c index 7c17bee..97ea65f 100644 --- a/gw_mode.c +++ b/gw_mode.c @@ -392,6 +392,6 @@ static int gw_mode(struct state *state, int argc, char **argv) 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"); diff --git a/hop_penalty.c b/hop_penalty.c index 56e1168..5cfb51a 100644 --- a/hop_penalty.c +++ b/hop_penalty.c @@ -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"); diff --git a/interface.c b/interface.c index 0a694c9..c2bfc74 100644 --- a/interface.c +++ b/interface.c @@ -541,5 +541,5 @@ static int interface(struct state *state, int argc, char **argv) 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"); diff --git a/isolation_mark.c b/isolation_mark.c index 3686317..340f33d 100644 --- a/isolation_mark.c +++ b/isolation_mark.c @@ -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"); diff --git a/loglevel.c b/loglevel.c index aff8b82..2e07edc 100644 --- a/loglevel.c +++ b/loglevel.c @@ -212,6 +212,6 @@ static int loglevel(struct state *state, int argc, char **argv) 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"); diff --git a/main.c b/main.c index 3b3a16f..f7e1c5e 100644 --- a/main.c +++ b/main.c @@ -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 ", + NULL, + }; const char *vlan_prefixes[] = { "vlan ", - "vid ", + "meshif 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 -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; diff --git a/main.h b/main.h index e3a95b5..8532bd1 100644 --- a/main.h +++ b/main.h @@ -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, diff --git a/man/batctl.8 b/man/batctl.8 index d42b682..6e75cdd 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -54,42 +54,42 @@ performances, is also included. .br .TP .I \fBcommands: -.IP "\fBinterface\fP|\fBif\fP [\fB-M\fP] [\fBadd\fP|\fBdel iface(s)\fP]" +.IP "[\fBmeshif \fP] \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 [\fBcreate\fP|\fBdestroy\fP]" +.IP "[\fBmeshif \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. .br -.IP "\fBorig_interval\fP|\fBit\fP [\fBinterval\fP]" +.IP "[\fBmeshif \fP] \fBorig_interval\fP|\fBit\fP [\fBinterval\fP]" If no parameter is given the current originator interval setting is displayed otherwise the parameter is used to set the originator interval. The interval is in units of milliseconds. .br -.IP "\fBap_isolation\fP|\fBap\fP [\fB0\fP|\fB1\fP]" +.IP "[\fBmeshif \fP] \fBap_isolation\fP|\fBap\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current ap isolation setting is displayed. Otherwise the parameter is used to enable or disable ap isolation. .br -.IP "<\fBvlan \fP|\fBvid \fP> \fBap_isolation\fP|\fBap\fP [\fB0\fP|\fB1\fP]" +.IP "<\fBvlan \fP|[\fBmeshif \fP] \fBvid \fP> \fBap_isolation\fP|\fBap\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current ap isolation setting for the specified VLAN is displayed. Otherwise the parameter is used to enable or disable ap isolation for the specified VLAN. .br -.IP "\fBbridge_loop_avoidance\fP|\fBbl\fP [\fB0\fP|\fB1\fP]" +.IP "[\fBmeshif \fP] \fBbridge_loop_avoidance\fP|\fBbl\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current bridge loop avoidance setting is displayed. Otherwise the parameter is used to enable or disable the bridge loop avoidance. Bridge loop avoidance support has to be enabled when compiling the module otherwise this option won't be available. .br -.IP "\fBdistributed_arp_table\fP|\fBdat\fP [\fB0\fP|\fB1\fP]" +.IP "[\fBmeshif \fP] \fBdistributed_arp_table\fP|\fBdat\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current distributed arp table setting is displayed. Otherwise the parameter is used to enable or disable the distributed arp table. .br -.IP "\fBaggregation\fP|\fBag\fP [\fB0\fP|\fB1\fP]" +.IP "[\fBmeshif \fP] \fBaggregation\fP|\fBag\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current aggregation setting is displayed. Otherwise the parameter is used to enable or disable OGM packet aggregation. .br -.IP "\fBbonding\fP|\fBb\fP [\fB0\fP|\fB1\fP]" +.IP "[\fBmeshif \fP] \fBbonding\fP|\fBb\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current bonding mode setting is displayed. Otherwise the parameter is used to enable or disable the bonding mode. .br @@ -101,30 +101,30 @@ when parameter \fB\-t\fP is specified. Parameter \fB\-r\fP will do the same but If no parameter is given the current ELP interval setting of the hard interface is displayed otherwise the parameter is used to set the ELP interval. The interval is in units of milliseconds. .br -.IP "\fBfragmentation\fP|\fBf\fP [\fB0\fP|\fB1\fP]" +.IP "[\fBmeshif \fP] \fBfragmentation\fP|\fBf\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current fragmentation mode setting is displayed. Otherwise the parameter is used to enable or disable fragmentation. .br -.IP "\fBhop_penalty\fP|\fBhp\fP [\fBpenalty\fP]" +.IP "[\fBmeshif \fP] \fBhop_penalty\fP|\fBhp\fP [\fBpenalty\fP]" If no parameter is given the current hop penalty setting is displayed. Otherwise the parameter is used to set the hop penalty. The penalty is can be 0-255 (255 sets originator message's TQ to zero when forwarded by this hop). .br -.IP "\fBnetwork_coding\fP|\fBnc\fP [\fB0\fP|\fB1\fP]" +.IP "[\fBmeshif \fP] \fBnetwork_coding\fP|\fBnc\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current network coding mode setting is displayed. Otherwise the parameter is used to enable or disable network coding. .br -.IP "\fBmulticast_forceflood\fP|\fBmff\fP [\fB0\fP|\fB1\fP]" +.IP "[\fBmeshif \fP] \fBmulticast_forceflood\fP|\fBmff\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current multicast forceflood setting is displayed. Otherwise the parameter is used to enable or disable multicast forceflood. This setting defines whether multicast optimizations should be replaced by simple broadcast-like flooding of multicast packets. If set to non-zero then all nodes in the mesh are going to use classic flooding for any multicast packet with no optimizations. .br -.IP "\fBmulticast_fanout\fP|\fBmo\fP [\fBfanout\fP]" +.IP "[\fBmeshif \fP] \fBmulticast_fanout\fP|\fBmo\fP [\fBfanout\fP]" If no parameter is given the current multicast fanout setting is displayed. Otherwise the parameter is used to set the multicast fanout. The multicast fanout defines the maximum number of packet copies that may be generated for a multicast-to-unicast conversion. Once this limit is exceeded distribution will fall back to broadcast. .br -.IP "\fBloglevel\fP|\fBll\fP [\fBlevel\fP[ \fBlevel\fP[ \fBlevel\fP]] \fB...\fP]" +.IP "[\fBmeshif \fP] \fBloglevel\fP|\fBll\fP [\fBlevel\fP[ \fBlevel\fP[ \fBlevel\fP]] \fB...\fP]" If no parameter is given the current log level settings are displayed otherwise the parameter(s) is/are used to set the log level. Level 'none' disables all verbose logging. Level 'batman' enables messages related to routing / flooding / broadcasting. Level 'routes' enables messages related to routes being added / changed / deleted. Level 'tt' enables messages related to @@ -135,7 +135,7 @@ Level 'all' enables all messages. The messages are sent to the batman-adv debug Make sure to have debugging output enabled when compiling the module otherwise the output as well as the loglevel options won't be available. .br -.IP "\fBgw_mode|gw\fP [\fBoff\fP|\fBclient\fP|\fBserver\fP] [\fBsel_class|bandwidth\fP]\fP" +.IP "[\fBmeshif \fP] \fBgw_mode|gw\fP [\fBoff\fP|\fBclient\fP|\fBserver\fP] [\fBsel_class|bandwidth\fP]\fP" If no parameter is given the current gateway mode is displayed otherwise the parameter is used to set the gateway mode. The second (optional) argument specifies the selection class (if 'client' was the first argument) or the gateway bandwidth (if 'server' was the first argument). If the node is a server this parameter is used to inform other nodes in the network about @@ -213,7 +213,7 @@ the parameter is used to set the throughput override for the specified hard interface. Just enter any number (optionally followed by "kbit" or "mbit"). .br -.IP "\fBisolation_mark\fP|\fBmark\fP" +.IP "[\fBmeshif \fP] \fBisolation_mark\fP|\fBmark\fP" If no parameter is given the current isolation mark value is displayed. Otherwise the parameter is used to set or unset the isolation mark used by the Extended Isolation feature. @@ -293,12 +293,12 @@ List of debug tables: .RE .RE .br -.IP "\fBtranslate\fP|\fBt\fP \fBMAC_address\fP|\fBbat\-host_name\fP|\fBhost_name\fP|\fBIP_address\fP" +.IP "[\fBmeshif \fP] \fBtranslate\fP|\fBt\fP \fBMAC_address\fP|\fBbat\-host_name\fP|\fBhost_name\fP|\fBIP_address\fP" Translates a destination (hostname, IP, MAC, bat_host-name) to the originator mac address responsible for it. .br -.IP "\fBstatistics\fP|\fBs\fP" +.IP "[\fBmeshif \fP] \fBstatistics\fP|\fBs\fP" Retrieve traffic counters from batman-adv kernel module. The output may vary depending on which features have been compiled into the kernel module. .br @@ -313,7 +313,7 @@ tt - translation table counters All counters without a prefix concern payload (pure user data) traffic. .RE .br -.IP "\fBping\fP|\fBp\fP [\fB\-c count\fP][\fB\-i interval\fP][\fB\-t time\fP][\fB\-R\fP][\fB\-T\fP] \fBMAC_address\fP|\fBbat\-host_name\fP|\fBhost_name\fP|\fBIP_address\fP" +.IP "[\fBmeshif \fP] \fBping\fP|\fBp\fP [\fB\-c count\fP][\fB\-i interval\fP][\fB\-t time\fP][\fB\-R\fP][\fB\-T\fP] \fBMAC_address\fP|\fBbat\-host_name\fP|\fBhost_name\fP|\fBIP_address\fP" Layer 2 ping of a MAC address or bat\-host name. batctl will try to find the bat\-host name if the given parameter was not a MAC address. It can also try to guess the MAC address using an IPv4/IPv6 address or a hostname when the IPv4/IPv6 address was configured on top of the batman-adv interface of the destination device and both source and @@ -324,7 +324,7 @@ interval between pings and the timeout time for replies, both in seconds. When r messages will be recorded. With "\-T" you can disable the automatic translation of a client MAC address to the originator address which is responsible for this client. .br -.IP "\fBtraceroute\fP|\fBtr\fP [\fB\-n\fP][\fB\-T\fP] \fBMAC_address\fP|\fBbat\-host_name\fP|\fBhost_name\fP|\fBIP_address\fP" +.IP "[\fBmeshif \fP] \fBtraceroute\fP|\fBtr\fP [\fB\-n\fP][\fB\-T\fP] \fBMAC_address\fP|\fBbat\-host_name\fP|\fBhost_name\fP|\fBIP_address\fP" Layer 2 traceroute to a MAC address or bat\-host name. batctl will try to find the bat\-host name if the given parameter was not a MAC address. It can also try to guess the MAC address using an IPv4/IPv6 address or a hostname when the IPv4/IPv6 address was configured on top of the batman-adv interface of the destination device and both source and @@ -376,7 +376,7 @@ specific sequence number, min. Furthermore using "\-o" you can filter the output given batctl will not replace the MAC addresses with bat\-host names in the output. .RE .br -.IP "\fBthroughputmeter\fP|\fBtp\fP \fBMAC\fP" +.IP "[\fBmeshif \fP] \fBthroughputmeter\fP|\fBtp\fP \fBMAC\fP" This command starts a throughput test entirely controlled by batman module in kernel space: the computational resources needed to align memory and copy data between user and kernel space that are required by other user space tools may diff --git a/multicast_fanout.c b/multicast_fanout.c index cec42a3..bea83c5 100644 --- a/multicast_fanout.c +++ b/multicast_fanout.c @@ -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"); diff --git a/multicast_forceflood.c b/multicast_forceflood.c index fdc5400..f15cc12 100644 --- a/multicast_forceflood.c +++ b/multicast_forceflood.c @@ -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"); diff --git a/multicast_mode.c b/multicast_mode.c index 063166e..e11d3af 100644 --- a/multicast_mode.c +++ b/multicast_mode.c @@ -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); diff --git a/network_coding.c b/network_coding.c index d22fab0..0fdcc78 100644 --- a/network_coding.c +++ b/network_coding.c @@ -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"); diff --git a/orig_interval.c b/orig_interval.c index a90ba27..f0e75c9 100644 --- a/orig_interval.c +++ b/orig_interval.c @@ -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"); diff --git a/ping.c b/ping.c index aa7cbc3..cc0ac0f 100644 --- a/ping.c +++ b/ping.c @@ -323,5 +323,5 @@ static int ping(struct state *state, int argc, char **argv) return ret; } -COMMAND(SUBCOMMAND, ping, "p", COMMAND_FLAG_MESH_IFACE, NULL, +COMMAND(SUBCOMMAND_MIF, ping, "p", COMMAND_FLAG_MESH_IFACE, NULL, " \tping another batman adv host via layer 2"); diff --git a/statistics.c b/statistics.c index 2a90a1d..c019d87 100644 --- a/statistics.c +++ b/statistics.c @@ -112,5 +112,5 @@ static int statistics(struct state *state, int argc __maybe_unused, return ret; } -COMMAND(SUBCOMMAND, statistics, "s", COMMAND_FLAG_MESH_IFACE, NULL, +COMMAND(SUBCOMMAND_MIF, statistics, "s", COMMAND_FLAG_MESH_IFACE, NULL, " \tprint mesh statistics"); diff --git a/sys.c b/sys.c index b9555ee..fe388fe 100644 --- a/sys.c +++ b/sys.c @@ -145,9 +145,13 @@ static void settings_usage(struct state *state) "", NULL, }; + const char *meshif_prefixes[] = { + "meshif ", + NULL, + }; const char *vlan_prefixes[] = { "vlan ", - "vid ", + "meshif 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; diff --git a/throughputmeter.c b/throughputmeter.c index f9d98cf..a46347d 100644 --- a/throughputmeter.c +++ b/throughputmeter.c @@ -529,5 +529,5 @@ static int throughputmeter(struct state *state, int argc, char **argv) return ret; } -COMMAND(SUBCOMMAND, throughputmeter, "tp", COMMAND_FLAG_MESH_IFACE, NULL, +COMMAND(SUBCOMMAND_MIF, throughputmeter, "tp", COMMAND_FLAG_MESH_IFACE, NULL, " \tstart a throughput measurement"); diff --git a/traceroute.c b/traceroute.c index d810122..07ba37f 100644 --- a/traceroute.c +++ b/traceroute.c @@ -209,5 +209,5 @@ static int traceroute(struct state *state, int argc, char **argv) return ret; } -COMMAND(SUBCOMMAND, traceroute, "tr", COMMAND_FLAG_MESH_IFACE, NULL, +COMMAND(SUBCOMMAND_MIF, traceroute, "tr", COMMAND_FLAG_MESH_IFACE, NULL, " \ttraceroute another batman adv host via layer 2"); diff --git a/translate.c b/translate.c index a59fc14..27d53e5 100644 --- a/translate.c +++ b/translate.c @@ -64,5 +64,5 @@ static int translate(struct state *state, int argc, char **argv) return ret; } -COMMAND(SUBCOMMAND, translate, "t", COMMAND_FLAG_MESH_IFACE, NULL, +COMMAND(SUBCOMMAND_MIF, translate, "t", COMMAND_FLAG_MESH_IFACE, NULL, " \ttranslate a destination to the originator responsible for it"); From patchwork Tue Jul 9 17:26:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 18000 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id 672158269B; Tue, 9 Jul 2019 19:27:21 +0200 (CEST) Received: from dvalin.narfation.org (dvalin.narfation.org [IPv6:2a00:17d8:100::8b1]) by open-mesh.org (Postfix) with ESMTPS id 30B6482540 for ; Tue, 9 Jul 2019 19:27:19 +0200 (CEST) Received: from sven-desktop.home.narfation.org (unknown [IPv6:2a00:1ca0:1480:f9fc::4065]) by dvalin.narfation.org (Postfix) with ESMTPSA id 7EE402018A; Tue, 9 Jul 2019 17:27:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1562693235; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2rvTpHl5ZTXfXcq6rdp2/OznwJdElLHPVHKn8WJR6R8=; b=DoaQeHD2k/bKjeG5g0jmLdESzcByB3B4JwSx4NMJzpo0mS3NI59591eiwa8QWJFIUDnrg9 Z31dgLmh5m9dfdBhW/1qC7LaQ2FwXkXnkwdxlJU9ZVUA7AKozLsR/MpHsP2z+z2NeycZPa uPc/3MU4pci6Exlc2z90QFRVQXmCk9g= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Subject: [PATCH v3 6/6] batctl: Allow to omit explicit prefix name Date: Tue, 9 Jul 2019 19:26:51 +0200 Message-Id: <20190709172651.5869-7-sven@narfation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190709172651.5869-1-sven@narfation.org> References: <20190709172651.5869-1-sven@narfation.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1562693235; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2rvTpHl5ZTXfXcq6rdp2/OznwJdElLHPVHKn8WJR6R8=; b=IyMSGo+kpmX0ndEypygi0Z1/7OxGBlCJeGHR3fTxqzNHdiTACHFWcnVqK3Gdjo5MrF4TEA YsTwqE6tY90QUJbkB4dhVrvcydn14iDydzaFBbCFg8hpd7VvCzkfdD2MGkgypHVh8m3ROz riC2dmUBzB2VuDRmUuhjb4nTV5FR6A0= ARC-Seal: i=1; s=20121; d=narfation.org; t=1562693235; a=rsa-sha256; cv=none; b=sLqQLBmY0wJS7DGgq0bFDQyDpJwXiR84RjWTJOh+zGHo8cqa9C4XBqX9QLuLIe0t9IwW9r trIkZ4AIPbTpQxRvOuSQXUZfBeK9CCG+3gVauaGb5ZmNsDppQ8JQfr5Oo9utb9kwHB4rgQ LEV0wT8J1/h7O2LSUtt7kPUhFDw9l98= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=sven smtp.mailfrom=sven@narfation.org X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" batctl allows three types of netdev based prefixes * meshif * vlan * hardif The first word is used to tell batctl that the netdev is expected to be of a specific type and all further information should be parsed in context of this specific type. This avoids ambiguity when parsing the command line information. But there are various situations when there is no ambiguity at all. For all of them, following points are true: * exists * has not the name of any existing batctl subcommand * is not "vlan", "vid", "hardif" or "meshif" In these situations, the first word can be omitted and batctl can guess the type automatically. Signed-off-by: Sven Eckelmann --- functions.c | 36 +++++++++++++++++++++++++++++++++--- functions.h | 3 +++ main.c | 28 +++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/functions.c b/functions.c index 4ffa86c..69d063e 100644 --- a/functions.c +++ b/functions.c @@ -1020,11 +1020,11 @@ int translate_hard_iface(struct state *state, const char *hardif) return 0; } -static int check_mesh_iface_netlink(struct state *state) +static int check_mesh_iface_netlink(unsigned int ifindex) { struct rtnl_link_iface_data link_data; - query_rtnl_link_single(state->mesh_ifindex, &link_data); + query_rtnl_link_single(ifindex, &link_data); if (!link_data.kind_found) return -1; @@ -1034,6 +1034,36 @@ static int check_mesh_iface_netlink(struct state *state) return 0; } +int guess_netdev_type(const char *netdev, enum selector_prefix *type) +{ + struct rtnl_link_iface_data link_data; + unsigned int netdev_ifindex; + + netdev_ifindex = if_nametoindex(netdev); + if (netdev_ifindex == 0) + return -ENODEV; + + query_rtnl_link_single(netdev_ifindex, &link_data); + + if (link_data.kind_found && strcmp(link_data.kind, "batadv") == 0) { + *type = SP_MESHIF; + return 0; + } + + if (link_data.master_found && + check_mesh_iface_netlink(link_data.master) >= 0) { + *type = SP_HARDIF; + return 0; + } + + if (link_data.kind_found && strcmp(link_data.kind, "vlan") == 0) { + *type = SP_VLAN; + return 0; + } + + return -EINVAL; +} + static int check_mesh_iface_sysfs(struct state *state) { char path_buff[PATH_BUFF_LEN]; @@ -1060,7 +1090,7 @@ int check_mesh_iface(struct state *state) if (state->mesh_ifindex == 0) return -1; - ret = check_mesh_iface_netlink(state); + ret = check_mesh_iface_netlink(state->mesh_ifindex); if (ret == 0) return ret; diff --git a/functions.h b/functions.h index 0a08870..31806d4 100644 --- a/functions.h +++ b/functions.h @@ -16,6 +16,8 @@ #include #include +#include "main.h" + /** * enum batadv_bandwidth_units - bandwidth unit types */ @@ -54,6 +56,7 @@ int translate_mesh_iface_vlan(struct state *state, const char *vlandev); int translate_vlan_iface(struct state *state, const char *vlandev); int translate_vid(struct state *state, const char *vidstr); int translate_hard_iface(struct state *state, const char *hardif); +int guess_netdev_type(const char *netdev, enum selector_prefix *type); int get_algoname(const char *mesh_iface, char *algoname, size_t algoname_len); int check_mesh_iface(struct state *state); int check_mesh_iface_ownership(struct state *state, char *hard_iface); diff --git a/main.c b/main.c index f7e1c5e..974d551 100644 --- a/main.c +++ b/main.c @@ -204,6 +204,32 @@ static int detect_selector_prefix(int argc, char *argv[], return 0; } +static int guess_selector_prefix(int argc, char *argv[], + enum selector_prefix *selector) +{ + int ret; + + /* check if there is a direct hit with full prefix */ + ret = detect_selector_prefix(argc, argv, selector); + if (ret > 0) + return ret; + + /* not enough remaining arguments to detect anything */ + if (argc < 1) + return -EINVAL; + + /* don't try to parse subcommand names as network interface */ + if (find_command_by_types(0xffffffff, argv[0])) + return -EEXIST; + + /* check if it is a netdev - and if it exists, try to guess what kind */ + ret = guess_netdev_type(argv[0], selector); + if (ret < 0) + return ret; + + return 1; +} + static int parse_meshif_args(struct state *state, int argc, char *argv[]) { enum selector_prefix selector; @@ -211,7 +237,7 @@ static int parse_meshif_args(struct state *state, int argc, char *argv[]) char *dev_arg; int ret; - parsed_args = detect_selector_prefix(argc, argv, &selector); + parsed_args = guess_selector_prefix(argc, argv, &selector); if (parsed_args < 1) goto fallback_meshif_vlan;