From patchwork Sun Jun 23 13:07:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17958 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 9D2488266E; Sun, 23 Jun 2019 15:07:57 +0200 (CEST) Received: from durin.narfation.org (durin.narfation.org [IPv6:2001:4d88:2000:7::2]) by open-mesh.org (Postfix) with ESMTPS id 2BD0281FEF for ; Sun, 23 Jun 2019 15:07:54 +0200 (CEST) Received: from sven-desktop.home.narfation.org (unknown [IPv6:2a00:1ca0:1480:f1fc::4065]) by durin.narfation.org (Postfix) with ESMTPSA id 5701A1100D0; Sun, 23 Jun 2019 15:07:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1561295273; 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=XT/mlJTk+S2X1vX3cGpeuXcdSbHUK9uzUxXSRPYBI09HkeeE3kOkM0T/Qwfqn3zUE9pVq0 tKlPt9buUZH4npsOEFIct15um+KqmToFwLNtC1BxLPrGqcRGHyqT68ci8ySTH/jxRRBtVl iHCqKRsMSivnLG2ItBZmTwTdzHtFnJA= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Subject: [PATCH v2 3/6] batctl: Add elp_interval setting command Date: Sun, 23 Jun 2019 15:07:06 +0200 Message-Id: <20190623130709.24751-4-sven@narfation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190623130709.24751-1-sven@narfation.org> References: <20190623130709.24751-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=1561295273; 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=fSzFI81hkK8yenmfOl2Cdc/JDXUpArMu27ygrQr2omEIXw9qAHG53w59CiVgOch7RoKmCB gBpzWR0rwydkrflcH6U0ovz+ZUvAWXZeOxbyLeIlMmHNjZ+0S4z+44CYJhSOsspyc/XCLa zfHfbozmt/Q00VRYru32TV/2qotiqyk= ARC-Seal: i=1; s=20121; d=narfation.org; t=1561295273; a=rsa-sha256; cv=none; b=Zeu9MzRzDhYXXpXJUzSBQtP1QkLVdnDb9LYel6hVilVbBnFhdMfsei/Ehp0/w2lMNMr8lk 6L50vN2rtxy9xYMJd1+kZNhiRO8WWDnZ/4Ycbh8haI6x8sHvHTLRpysxZ7co7A9R7kq7GA Cq8Psn4AxQWRPpVKg0KY6AqReEv0y1M= 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.