From patchwork Fri Apr 26 17:31:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Linus_L=C3=BCssing?= X-Patchwork-Id: 17898 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 F1DFD824C1; Fri, 26 Apr 2019 19:31:55 +0200 (CEST) Authentication-Results: open-mesh.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=c0d3.blue header.i=@c0d3.blue header.b="BXFYvFpH"; dkim-atps=neutral Received-SPF: None (mailfrom) identity=mailfrom; client-ip=138.201.29.205; helo=mail.aperture-lab.de; envelope-from=linus.luessing@c0d3.blue; receiver= Received: from mail.aperture-lab.de (mail.aperture-lab.de [138.201.29.205]) by open-mesh.org (Postfix) with ESMTPS id 6FB4E8062D for ; Fri, 26 Apr 2019 19:31:54 +0200 (CEST) From: =?utf-8?q?Linus_L=C3=BCssing?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c0d3.blue; s=2018; t=1556299914; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=Vb8K5rAgtghSkCcMIhnTM6uUgQC5gy7c8wCAZ24BRaM=; b=BXFYvFpHyHPChdxloAAi05j/TcL8YnhuF7IItaXvu7uuV2ZRKk7XHVyAq/qjvCMKEQH93p xLk403GXvltB8WBek/GCdUvKl0sdM04S3Hm57WLFRsba75MdZYovt/DmzeBsfoj3DDcKKH KI8HPj3dtiaafasimaIPxX/HD1V0yd3vE5lnywhQpN1PO5mte+mWR2gt2djS2z+oXkmWJZ exfFxfzkgMzRok9uqSbZ3VaN9CYLX2fN4ENWWy3LKVsdpYqIt1CPil22iylyNrHTb9Baq4 xInp2B1or9P26jVYWX8stB2vtV19zjmKC1T1E4cGGcHnJHhIuXL+57s/KROSWA== To: b.a.t.m.a.n@lists.open-mesh.org Date: Fri, 26 Apr 2019 19:31:48 +0200 Message-Id: <20190426173148.18677-1-linus.luessing@c0d3.blue> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=c0d3.blue; s=2018; t=1556299914; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=Vb8K5rAgtghSkCcMIhnTM6uUgQC5gy7c8wCAZ24BRaM=; b=YurogHvHWs8vU2lZT83DwRcC0DtbfWvVab8M48wjkubVPGtU7fftHgAM+mX6zsU5o6SaVx qNjGidUDj8G6D8VVHkcQ1GfAQp1Gt2KbmQiKH64N6yVW6cuUxMrbSf26uESR5iHH1R/RUc CBOQylnIrfm96KZOTpJbq70XswDwv6NcTa2TaCR+NOUGN8G8y8P88bYW7jwfHiufeaIRRM V3KQTTjznL/SiSlOYi0mDnw8fVgSDithQpFw6QM1XnknnhL3KnsL3X1COV7zDP58QIhQ0i G+97nHICTXdGYvEzQ3o7OVIFbeDdCfpm/sRQTKNPrl2QpyoBl5fIWwLaKueQGw== ARC-Seal: i=1; s=2018; d=c0d3.blue; t=1556299914; a=rsa-sha256; cv=none; b=Temfoirdr9+T8gbWHHV28wWcs9wEvPRgkxphU4yDdEWg8UF58rs+f09Ie3omgu52qcN1mK 87oSgUqxVz6syijers2tYEXvJRfLebUfEVO3VA/3lfIY2FMj0KFPMo4g5dHG3wD2491xAJ RnfnahivxEZeVsBtkrMzsKRtDNkzZhX0BHBUaQ7gyQ5GHXyBkH9mPNaaUTTunbyzwC5sxD 7HMF8sIm1Qr//lmitUCsOjkXdcY5JGhWJY6JRlXN5pGkhvilIejXhjYImEH0pszJ5HVZpc CQf47yWVN0uy3Q1Nq8/iiMKhAzNC1WyzLgs+xx4DkySrSFubGn3CYlumbs5Z2w== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=linus.luessing@c0d3.blue smtp.mailfrom=linus.luessing@c0d3.blue Authentication-Results: ORIGINATING; auth=pass smtp.auth=linus.luessing@c0d3.blue smtp.mailfrom=linus.luessing@c0d3.blue Subject: [B.A.T.M.A.N.] [PATCH v2] batctl: Add noflood command 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" Adds support for the new 'noflood' setting in batman-adv. Signed-off-by: Linus Lüssing --- Changelog v2: * added noflood.c --- Makefile | 1 + README.rst | 10 +++++ batman_adv.h | 10 +++++ man/batctl.8 | 7 ++++ noflood.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 noflood.c diff --git a/Makefile b/Makefile index df8b7b9..6a363d7 100755 --- a/Makefile +++ b/Makefile @@ -61,6 +61,7 @@ $(eval $(call add_command,multicast_mode,y)) $(eval $(call add_command,nc_nodes,y)) $(eval $(call add_command,neighbors,y)) $(eval $(call add_command,network_coding,y)) +$(eval $(call add_command,noflood,y)) $(eval $(call add_command,orig_interval,y)) $(eval $(call add_command,originators,y)) $(eval $(call add_command,ping,y)) diff --git a/README.rst b/README.rst index 03ea5e5..67d42f6 100644 --- a/README.rst +++ b/README.rst @@ -571,6 +571,16 @@ Usage:: * Example 4: ``batctl mark 0x0f`` +batctl noflood +======================= + +display or modify noflood setting (||) + +Usage:: + + batctl noflood|nf [0|1|2] + + batctl translocal ================= diff --git a/batman_adv.h b/batman_adv.h index 67f4636..ea2ffda 100644 --- a/batman_adv.h +++ b/batman_adv.h @@ -480,6 +480,16 @@ enum batadv_nl_attrs { */ BATADV_ATTR_MULTICAST_FANOUT, + /** + * @BATADV_ATTR_NOFLOOD: defines if and how strictly flooding prevention + * is configured. If the value is 0 then flood prevention is disabled. + * If the value is 1 then flood prevention is enabled for all multicast + * /broadcast packets excluding ICMPv6 and IGMP (cautious mode). If set + * to 2 then flood prevention is enabled for all multicast/broadcast + * packets (aggressive mode). + */ + BATADV_ATTR_NOFLOOD, + /* add attributes above here, update the policy in netlink.c */ /** diff --git a/man/batctl.8 b/man/batctl.8 index 8d7332a..7518f9c 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -116,6 +116,13 @@ If no parameter is given the current multicast fanout setting is displayed. Othe 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 "\fBnoflood\fP|\fBnf\fP [\fB0|1|2\fP]" +If no parameter is given the current noflood setting is displayed. Otherwise the parameter is used to set the +the noflood option. The noflood option defines if and how strictly flooding prevention is configured. If the value is +0 then flood prevention is disabled. If the value is 1 then flood prevention is enabled for all multicast/broadcast +packets excluding ICMPv6 and IGMP (cautious mode). If set to 2 then flood prevention is enabled for all multicast/broadcast +packets (aggressive mode). +.br .IP "\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. diff --git a/noflood.c b/noflood.c new file mode 100644 index 0000000..c60063c --- /dev/null +++ b/noflood.c @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors: + * + * Linus Lüssing + * + * License-Filename: LICENSES/preferred/GPL-2.0 + */ + +#include +#include +#include +#include + +#include "main.h" +#include "sys.h" + +static struct noflood_data { + uint32_t noflood; +} noflood; + +static int parse_noflood(struct state *state, int argc, char *argv[]) +{ + struct settings_data *settings = state->cmd->arg; + struct noflood_data *data = settings->data; + char *endptr; + + if (argc != 2) { + fprintf(stderr, "Error - incorrect number of arguments (expected 1)\n"); + return -EINVAL; + } + + data->noflood = 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_noflood(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_NOFLOOD]) + return NL_OK; + + printf("%u\n", nla_get_u8(attrs[BATADV_ATTR_NOFLOOD])); + + *result = 0; + return NL_STOP; +} + +static int get_noflood(struct state *state) +{ + return sys_simple_nlquery(state, BATADV_CMD_GET_MESH, + NULL, print_noflood); +} + +static int set_attrs_noflood(struct nl_msg *msg, void *arg) +{ + struct state *state = arg; + struct settings_data *settings = state->cmd->arg; + struct noflood_data *data = settings->data; + + nla_put_u8(msg, BATADV_ATTR_NOFLOOD, data->noflood); + + return 0; +} + +static int set_noflood(struct state *state) +{ + return sys_simple_nlquery(state, BATADV_CMD_SET_MESH, + set_attrs_noflood, NULL); +} + +static struct settings_data batctl_settings_noflood = { + .sysfs_name = NULL, + .data = &noflood, + .parse = parse_noflood, + .netlink_get = get_noflood, + .netlink_set = set_noflood, +}; + +COMMAND_NAMED(SUBCOMMAND, noflood, "nf", handle_sys_setting, + COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK, + &batctl_settings_noflood, + "[0|1|2] \tdisplay or modify noflood setting (||)");