From patchwork Sun Apr 18 12:01:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12210053 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D31E6C433B4 for ; Sun, 18 Apr 2021 12:03:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0BA861019 for ; Sun, 18 Apr 2021 12:03:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231281AbhDRMDg (ORCPT ); Sun, 18 Apr 2021 08:03:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230457AbhDRMDe (ORCPT ); Sun, 18 Apr 2021 08:03:34 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB830C061760 for ; Sun, 18 Apr 2021 05:03:04 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id h4so22058948wrt.12 for ; Sun, 18 Apr 2021 05:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aX1JtiuKoA7JI8C3Gss56MOs3H4KZoZy+yqmEJ2hMLY=; b=r7nu6MLCaLTnRw85lWKjir8JUUy76RwuGt6QCdZ7ahknDjT07N5L0TWGo/vZsd1fU3 j87Cb2PErI07VkMJENHLt11oPb0KjSHUPWBBfB9+a1mnRhhoOPrRad7rLEFyOgrPISjt OVYbpYX/KN6du+VvFQ1nB2MEQdU1XB1YF6DMQFZepwxDGdxj+DdQDtpzM/bPg/5tpO2q V8x2xtXrTknE3E1E7AXGLFY5YRkT7ENxWCygjsHr6BKZ4SNv4XhNtT05kK4+e/C0iAp3 MF3OshFr/35EDBCXjSjyK2QP8bz8xTzKARwIY2IL8GKtuoRqfSzIL7DKskS2LQbaTrmW nvAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aX1JtiuKoA7JI8C3Gss56MOs3H4KZoZy+yqmEJ2hMLY=; b=t7hWsGtT8vXSqYrnZNGe6fH7tUaWgHofb1awDc+GcvK0nMCBnpZlPogVul4SHzG7cM G9u2tHPzmchd4lTWKw88fGm6aGzG2CyCokkB3TmqDQZCDSm4O/igHQ32sE8nWiP3GGC4 R4OkjV9bAxhxKE1fF4S9mFNhKTTEEman8xCZAbg1rcTRxFswbinLOLpQnrrVHKVXg1nr vhB33kajXeA0Kw5goTrfqd6cCfRuvp+VV2nUDJ73qBJp7eXfPcNHbLDvtbtghTsZD9aF dI4DZwirjR/4UYNfub8kntvL6CDe1djg7Ihknz2FNqRCPXfVkzl1Y5+78G/Xon8VkGi1 ihyw== X-Gm-Message-State: AOAM532TZqLhedxlIhMM6k2nnRnPY10yueaL7P1ebHkPBn52Vf6P3asz GghyiTz9vy9fBUea/uUPPWG05Dn6Y/vcgYDA X-Google-Smtp-Source: ABdhPJz3trNwWSubjd9YK0wT0aihM8sjiKVuRSZWOEe31aVYK7ZMyNyElKQUU2f8b+/SCgYIw53m3w== X-Received: by 2002:adf:fecd:: with SMTP id q13mr8897001wrs.7.1618747383209; Sun, 18 Apr 2021 05:03:03 -0700 (PDT) Received: from debil.vdiclient.nvidia.com (84-238-136-197.ip.btc-net.bg. [84.238.136.197]) by smtp.gmail.com with ESMTPSA id x25sm16584763wmj.34.2021.04.18.05.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Apr 2021 05:03:02 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: roopa@nvidia.com, dsahern@gmail.com, Nikolay Aleksandrov Subject: [PATCH iproute2-next 1/6] bridge: rename and export print_portstate Date: Sun, 18 Apr 2021 15:01:32 +0300 Message-Id: <20210418120137.2605522-2-razor@blackwall.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210418120137.2605522-1-razor@blackwall.org> References: <20210418120137.2605522-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Nikolay Aleksandrov Rename print_portstate to print_stp_state in preparation for use by vlan code as well (per-vlan state), and export it. To be in line with the new naming rename also port_states to stp_states as they'll be used for vlans, too. Signed-off-by: Nikolay Aleksandrov --- bridge/br_common.h | 1 + bridge/link.c | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bridge/br_common.h b/bridge/br_common.h index b5798da300e8..e3f46765ab89 100644 --- a/bridge/br_common.h +++ b/bridge/br_common.h @@ -10,6 +10,7 @@ void print_vlan_info(struct rtattr *tb, int ifindex); int print_linkinfo(struct nlmsghdr *n, void *arg); int print_mdb_mon(struct nlmsghdr *n, void *arg); int print_fdb(struct nlmsghdr *n, void *arg); +void print_stp_state(__u8 state); int do_fdb(int argc, char **argv); int do_mdb(int argc, char **argv); diff --git a/bridge/link.c b/bridge/link.c index d88c469db78e..a8cfa1814986 100644 --- a/bridge/link.c +++ b/bridge/link.c @@ -19,7 +19,7 @@ static unsigned int filter_index; -static const char *port_states[] = { +static const char *stp_states[] = { [BR_STATE_DISABLED] = "disabled", [BR_STATE_LISTENING] = "listening", [BR_STATE_LEARNING] = "learning", @@ -68,11 +68,11 @@ static void print_link_flags(FILE *fp, unsigned int flags, unsigned int mdown) close_json_array(PRINT_ANY, "> "); } -static void print_portstate(__u8 state) +void print_stp_state(__u8 state) { if (state <= BR_STATE_BLOCKING) print_string(PRINT_ANY, "state", - "state %s ", port_states[state]); + "state %s ", stp_states[state]); else print_uint(PRINT_ANY, "state", "state (%d) ", state); @@ -96,7 +96,7 @@ static void print_protinfo(FILE *fp, struct rtattr *attr) parse_rtattr_nested(prtb, IFLA_BRPORT_MAX, attr); if (prtb[IFLA_BRPORT_STATE]) - print_portstate(rta_getattr_u8(prtb[IFLA_BRPORT_STATE])); + print_stp_state(rta_getattr_u8(prtb[IFLA_BRPORT_STATE])); if (prtb[IFLA_BRPORT_PRIORITY]) print_uint(PRINT_ANY, "priority", @@ -161,7 +161,7 @@ static void print_protinfo(FILE *fp, struct rtattr *attr) print_on_off(PRINT_ANY, "isolated", "isolated %s ", rta_getattr_u8(prtb[IFLA_BRPORT_ISOLATED])); } else - print_portstate(rta_getattr_u8(attr)); + print_stp_state(rta_getattr_u8(attr)); } @@ -359,12 +359,12 @@ static int brlink_modify(int argc, char **argv) } else if (strcmp(*argv, "state") == 0) { NEXT_ARG(); char *endptr; - size_t nstates = ARRAY_SIZE(port_states); + size_t nstates = ARRAY_SIZE(stp_states); state = strtol(*argv, &endptr, 10); if (!(**argv != '\0' && *endptr == '\0')) { for (state = 0; state < nstates; state++) - if (strcasecmp(port_states[state], *argv) == 0) + if (strcasecmp(stp_states[state], *argv) == 0) break; if (state == nstates) { fprintf(stderr, From patchwork Sun Apr 18 12:01:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12210055 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1B10C433ED for ; Sun, 18 Apr 2021 12:03:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B57F61019 for ; Sun, 18 Apr 2021 12:03:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231464AbhDRMDh (ORCPT ); Sun, 18 Apr 2021 08:03:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230441AbhDRMDe (ORCPT ); Sun, 18 Apr 2021 08:03:34 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D59CC06174A for ; Sun, 18 Apr 2021 05:03:05 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id g9so15080682wrx.0 for ; Sun, 18 Apr 2021 05:03:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w5EWL9x9pFyov9bRXc5AqdXBp6bk93RVasdGvAZevwI=; b=sDUI78YjY9rEY3DnQ3zzY0SzukrzlRgs7/5e5vPQW859PwmrcLqkWO95AWLI9r69vz VQu5NCA6KGoZoqxarK2LN9BoQjzEdWIdaMtMiGE28NTaMsciuwpRHjnbXhRpObhWcimL YMjI8YgRmbGcHwYmSsEdJ8dnQS4Fic+UAxKo0FU0o8cs9HObtaR681JJ7wVIo7aEMVQL VzotO1WTVnGcJMd/VdbE0gZMiyJaNvLrZLeiXp+rD2QE6vt7IfOLDMRVkYwYS1bqPFhf yyBcsaD7tWoDyCfv7+ORW3y5tL0nBWWxDqW1MtjmapquSnr+MwmdtdknYVXOUVbiodvp mrPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w5EWL9x9pFyov9bRXc5AqdXBp6bk93RVasdGvAZevwI=; b=Yzpr3W3EdBzwnP1BHgevKn9/C2n7+jyGdeqYNysqB6eyQ9o0a154RBu1gNVpBs/QIl xN9BM+KrTAc3iwJXH8fHmp/YGcp9P39xrAyoTjIKFvXq3g6yFATqUkiDsfskjwOjRe7O U0XC8MoYozLjUDrix4uoANXvgcG17eMwWmcuXbak1cTwCHyZnq1dEmrluGQXiG11E5KF B6Oxp/xF/TgqN8uxFXj8fK7WLVterCWujjS8BIYm6IP2GJhG8NhecyFIcNoBc4YM7dIU 2EBbVrY/Y3GUzykL301XEbrh6Yndcf0tR8E9XcsrVIqrV4L7f3RWFJGRMmufi/VHLv8R H8CA== X-Gm-Message-State: AOAM5301HoNrvPLN8EPFNl9zfldyeoPzpHB5Kq2meZrYewmX+N3MvUr5 unnR77nL2v2/7WSGfamP8noUeteoBfC5C+bB X-Google-Smtp-Source: ABdhPJx+rGdfJmCEWeCd0ifaWJntDJ2X/nvPcmQhFopV8+C13mbL/2Qkd/6zuiwzx+xO/fORJ3i0kQ== X-Received: by 2002:a5d:6881:: with SMTP id h1mr9061103wru.121.1618747384019; Sun, 18 Apr 2021 05:03:04 -0700 (PDT) Received: from debil.vdiclient.nvidia.com (84-238-136-197.ip.btc-net.bg. [84.238.136.197]) by smtp.gmail.com with ESMTPSA id x25sm16584763wmj.34.2021.04.18.05.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Apr 2021 05:03:03 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: roopa@nvidia.com, dsahern@gmail.com, Nikolay Aleksandrov Subject: [PATCH iproute2-next 2/6] bridge: add parse_stp_state helper Date: Sun, 18 Apr 2021 15:01:33 +0300 Message-Id: <20210418120137.2605522-3-razor@blackwall.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210418120137.2605522-1-razor@blackwall.org> References: <20210418120137.2605522-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Nikolay Aleksandrov Add a helper which parses an STP state string to its numeric value. Signed-off-by: Nikolay Aleksandrov --- bridge/br_common.h | 1 + bridge/link.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/bridge/br_common.h b/bridge/br_common.h index e3f46765ab89..33e56452702b 100644 --- a/bridge/br_common.h +++ b/bridge/br_common.h @@ -11,6 +11,7 @@ int print_linkinfo(struct nlmsghdr *n, void *arg); int print_mdb_mon(struct nlmsghdr *n, void *arg); int print_fdb(struct nlmsghdr *n, void *arg); void print_stp_state(__u8 state); +int parse_stp_state(const char *arg); int do_fdb(int argc, char **argv); int do_mdb(int argc, char **argv); diff --git a/bridge/link.c b/bridge/link.c index a8cfa1814986..205a2fe79c1a 100644 --- a/bridge/link.c +++ b/bridge/link.c @@ -78,6 +78,21 @@ void print_stp_state(__u8 state) "state (%d) ", state); } +int parse_stp_state(const char *arg) +{ + size_t nstates = ARRAY_SIZE(stp_states); + int state; + + for (state = 0; state < nstates; state++) + if (strcmp(stp_states[state], arg) == 0) + break; + + if (state == nstates) + state = -1; + + return state; +} + static void print_hwmode(__u16 mode) { if (mode >= ARRAY_SIZE(hw_mode)) @@ -359,14 +374,11 @@ static int brlink_modify(int argc, char **argv) } else if (strcmp(*argv, "state") == 0) { NEXT_ARG(); char *endptr; - size_t nstates = ARRAY_SIZE(stp_states); state = strtol(*argv, &endptr, 10); if (!(**argv != '\0' && *endptr == '\0')) { - for (state = 0; state < nstates; state++) - if (strcasecmp(stp_states[state], *argv) == 0) - break; - if (state == nstates) { + state = parse_stp_state(*argv); + if (state == -1) { fprintf(stderr, "Error: invalid STP port state\n"); return -1; From patchwork Sun Apr 18 12:01:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12210059 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62531C433B4 for ; Sun, 18 Apr 2021 12:03:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3811D61359 for ; Sun, 18 Apr 2021 12:03:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231339AbhDRMDl (ORCPT ); Sun, 18 Apr 2021 08:03:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231272AbhDRMDf (ORCPT ); Sun, 18 Apr 2021 08:03:35 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 687BCC061761 for ; Sun, 18 Apr 2021 05:03:06 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id w186so12131864wmg.3 for ; Sun, 18 Apr 2021 05:03:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=piBsJVg8SSFD7g3ZzOjEi7IlK8Xhlh8XK9iu1OQWyes=; b=rRMD3xGslFTS9tZkFZ+uB7M/QzbV+D/Ofmuc/+g/bsQN6kOeOv2kF82rCMJxos95kg A3+C/zVdMpkpI/Imc2afXVf55NXdyGWN87BTirVZZDP2s7LkxlpNmptc55fTou6zVvWW 7aHIVpX4LAt/iCK1reNADT29ldSVBHfDKT6M/zFUkbmMXWBLfRRzYcJCTDHc+xm+zT3V XUGZReMLWY0ibToeE0O5rSCOhOqXFFJEf9v1kyKdHJHvj9mN7bXkFkKfTINW015NU7ix dbm36sVHsi42nD0Lgi2Kb4ZwpzSeITHaMc7vLBg++kPA5yjzExq8m8PKk6+TdBcaQ2sY pwoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=piBsJVg8SSFD7g3ZzOjEi7IlK8Xhlh8XK9iu1OQWyes=; b=HdQSJz+nqXlOYA6cipv0iN/y1LN8iLjFh3Gzb+NCeQmecnJx4wdMSnVKZuDe5d3NIK 4TmvBmJhdFaedhVSm9f+Up4HNvcEHgOrG1O6KL0SH2hiXjBWUW9qeRmSFunmIo4pgbNA H8X4NOBRq7TsNTUfXm7OQGMfqBG6vdUhfqtxY/QDtmNePWMcm1ZQlJKj2Feo2R1ZXt7c +nFRO15WB2/CsoUGgwdcdrlC5DLKx+xMtC7FA7AqsIKs3b95/9uZtR36O27OtVwbNYxv JGSKLWp9Ffy5tt6B0NBvNCCkHEuezR/VBb1wRcgn7PPfqk6Ut6GVNgYKNZwyMl49ab8X Q0Mg== X-Gm-Message-State: AOAM530vxoo8M1+KxujcbVOf+eQ9VHuYgVNOlImN53vNflaLmzdhrBT3 00lYkEV2W2ADNSRCqH/WS54QuxMn7V7hVH/R X-Google-Smtp-Source: ABdhPJzcl8NORbtec5SxpHatF3jOagi3EGgqaOnt+07CtrHxy5hlEIAv5yT4oPUTzpokIQ8SDzUX/A== X-Received: by 2002:a05:600c:2d56:: with SMTP id a22mr16851246wmg.175.1618747384831; Sun, 18 Apr 2021 05:03:04 -0700 (PDT) Received: from debil.vdiclient.nvidia.com (84-238-136-197.ip.btc-net.bg. [84.238.136.197]) by smtp.gmail.com with ESMTPSA id x25sm16584763wmj.34.2021.04.18.05.03.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Apr 2021 05:03:04 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: roopa@nvidia.com, dsahern@gmail.com, Nikolay Aleksandrov Subject: [PATCH iproute2-next 3/6] bridge: vlan: add option set command and state option Date: Sun, 18 Apr 2021 15:01:34 +0300 Message-Id: <20210418120137.2605522-4-razor@blackwall.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210418120137.2605522-1-razor@blackwall.org> References: <20210418120137.2605522-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Nikolay Aleksandrov Add a new per-vlan option set command. It allows to manipulate vlan options, those can be bridge-wide or per-port depending on what device is specified. The first option that can be set is the vlan STP state, it is identical to the bridge port STP state. The man page is also updated accordingly. Example: $ bridge vlan set vid 10 dev br0 state learning or a range: $ bridge vlan set vid 10-20 dev swp1 state blocking Signed-off-by: Nikolay Aleksandrov --- bridge/vlan.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++ man/man8/bridge.8 | 64 +++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) diff --git a/bridge/vlan.c b/bridge/vlan.c index 0d142bc9055d..09884870df81 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -33,6 +33,7 @@ static void usage(void) "Usage: bridge vlan { add | del } vid VLAN_ID dev DEV [ tunnel_info id TUNNEL_ID ]\n" " [ pvid ] [ untagged ]\n" " [ self ] [ master ]\n" + " bridge vlan { set } vid VLAN_ID dev DEV [ state STP_STATE ]\n" " bridge vlan { show } [ dev DEV ] [ vid VLAN_ID ]\n" " bridge vlan { tunnelshow } [ dev DEV ] [ vid VLAN_ID ]\n"); exit(-1); @@ -241,6 +242,100 @@ static int vlan_modify(int cmd, int argc, char **argv) return 0; } +static int vlan_option_set(int argc, char **argv) +{ + struct { + struct nlmsghdr n; + struct br_vlan_msg bvm; + char buf[1024]; + } req = { + .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct br_vlan_msg)), + .n.nlmsg_flags = NLM_F_REQUEST, + .n.nlmsg_type = RTM_NEWVLAN, + .bvm.family = PF_BRIDGE, + }; + struct bridge_vlan_info vinfo = {}; + struct rtattr *afspec; + short vid_end = -1; + char *d = NULL; + short vid = -1; + int state = -1; + + while (argc > 0) { + if (strcmp(*argv, "dev") == 0) { + NEXT_ARG(); + d = *argv; + } else if (strcmp(*argv, "vid") == 0) { + char *p; + + NEXT_ARG(); + p = strchr(*argv, '-'); + if (p) { + *p = '\0'; + p++; + vid = atoi(*argv); + vid_end = atoi(p); + if (vid >= vid_end || vid_end >= 4096) { + fprintf(stderr, "Invalid VLAN range \"%hu-%hu\"\n", + vid, vid_end); + return -1; + } + } else { + vid = atoi(*argv); + } + } else if (strcmp(*argv, "state") == 0) { + char *endptr; + + NEXT_ARG(); + state = strtol(*argv, &endptr, 10); + if (!(**argv != '\0' && *endptr == '\0')) + state = parse_stp_state(*argv); + if (state == -1) { + fprintf(stderr, "Error: invalid STP state\n"); + return -1; + } + } else { + if (matches(*argv, "help") == 0) + NEXT_ARG(); + } + argc--; argv++; + } + + if (d == NULL || vid == -1) { + fprintf(stderr, "Device and VLAN ID are required arguments.\n"); + return -1; + } + + req.bvm.ifindex = ll_name_to_index(d); + if (req.bvm.ifindex == 0) { + fprintf(stderr, "Cannot find network device \"%s\"\n", d); + return -1; + } + + if (vid >= 4096) { + fprintf(stderr, "Invalid VLAN ID \"%hu\"\n", vid); + return -1; + } + afspec = addattr_nest(&req.n, sizeof(req), BRIDGE_VLANDB_ENTRY); + afspec->rta_type |= NLA_F_NESTED; + + vinfo.flags = BRIDGE_VLAN_INFO_ONLY_OPTS; + vinfo.vid = vid; + addattr_l(&req.n, sizeof(req), BRIDGE_VLANDB_ENTRY_INFO, &vinfo, + sizeof(vinfo)); + if (vid_end != -1) + addattr16(&req.n, sizeof(req), BRIDGE_VLANDB_ENTRY_RANGE, + vid_end); + if (state >= 0) + addattr8(&req.n, sizeof(req), BRIDGE_VLANDB_ENTRY_STATE, state); + addattr_nest_end(&req.n, afspec); + + if (rtnl_talk(&rth, &req.n, NULL) < 0) + return -1; + + return 0; +} + /* In order to use this function for both filtering and non-filtering cases * we need to make it a tristate: * return -1 - if filtering we've gone over so don't continue @@ -667,6 +762,8 @@ int do_vlan(int argc, char **argv) if (matches(*argv, "tunnelshow") == 0) { return vlan_show(argc-1, argv+1, VLAN_SHOW_TUNNELINFO); } + if (matches(*argv, "set") == 0) + return vlan_option_set(argc-1, argv+1); if (matches(*argv, "help") == 0) usage(); } else { diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index 9d8663bd23cc..90dcae73ce71 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -138,6 +138,15 @@ bridge \- show / manipulate bridge addresses and devices .BR pvid " ] [ " untagged " ] [ " .BR self " ] [ " master " ] " +.ti -8 +.BR "bridge vlan set" +.B dev +.I DEV +.B vid +.IR VID " [ " +.B state +.IR STP_STATE " ] " + .ti -8 .BR "bridge vlan" " [ " show " | " tunnelshow " ] [ " .B dev @@ -813,6 +822,61 @@ The .BR "pvid " and " untagged" flags are ignored. +.SS bridge vlan set - change vlan filter entry's options + +This command changes vlan filter entry's options. + +.TP +.BI dev " NAME" +the interface with which this vlan is associated. + +.TP +.BI vid " VID" +the VLAN ID that identifies the vlan. + +.TP +.BI state " STP_STATE " +the operation state of the vlan. One may enter STP state name (case insensitive), or one of the +numbers below. Negative inputs are ignored, and unrecognized names return an +error. Note that the state is set only for the vlan of the specified device, e.g. if it is +a bridge port then the state will be set only for the vlan of the port. + +.B 0 +- vlan is in STP +.B DISABLED +state. Make this vlan completely inactive for STP. This is also called +BPDU filter and could be used to disable STP on an untrusted vlan. +.sp + +.B 1 +- vlan is in STP +.B LISTENING +state. Only valid if STP is enabled on the bridge. In this +state the vlan listens for STP BPDUs and drops all other traffic frames. +.sp + +.B 2 +- vlan is in STP +.B LEARNING +state. Only valid if STP is enabled on the bridge. In this +state the vlan will accept traffic only for the purpose of updating MAC +address tables. +.sp + +.B 3 +- vlan is in STP +.B FORWARDING +state. This is the default vlan state. +.sp + +.B 4 +- vlan is in STP +.B BLOCKING +state. Only valid if STP is enabled on the bridge. This state +is used during the STP election process. In this state, the vlan will only process +STP BPDUs. +.sp + .SS bridge vlan show - list vlan configuration. This command displays the current VLAN filter table. From patchwork Sun Apr 18 12:01:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12210057 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11923C43460 for ; Sun, 18 Apr 2021 12:03:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E702061019 for ; Sun, 18 Apr 2021 12:03:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230441AbhDRMDj (ORCPT ); Sun, 18 Apr 2021 08:03:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231169AbhDRMDf (ORCPT ); Sun, 18 Apr 2021 08:03:35 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 045BFC061763 for ; Sun, 18 Apr 2021 05:03:07 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id y5-20020a05600c3645b0290132b13aaa3bso4821379wmq.1 for ; Sun, 18 Apr 2021 05:03:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2ssRpSujeKUYFK0HQ+R/6RY8ue2oV1kYrGO5GO9Gink=; b=odLurbwYIkRhDSDRzJPqjXKVuYGm+X53q6vdHqvZvMx32pYMsXeDa5CGIvyA35SDy8 W9d9MNVTZMGRFEQoe/rdqU1SU/QipKhNSALiWo8KIS5VTLYiioIKz+eXR3ziJDrZYILv QHWC0G8xEBBVD7vMO/Uv/2Ly7fKUyUxf7A1w5hgeHNqcwRHowwmCL6boLkZn6iiFVdbo 0FdGCcm51JsIXmaIzcutTYhhS82CI9U97wPMzoysiHS5GBe501tCglW9cqcg1khqcIqz aNIW9cpCxOtI4ymQcXLI0tHlhwpx4QaR6wtTrutiXQFKdmGs+9x8SNB3xhkd1iOknc6T Fl0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2ssRpSujeKUYFK0HQ+R/6RY8ue2oV1kYrGO5GO9Gink=; b=MEp5/aTMOQdsA8a8wca6KdS5411xTJNJ4XXN64w4m+iPqlY7qJXpTh/lftRPT99aO2 v28YZnUWBhMwY8w80WgbhKSwnBlEVpeRvr58dKytyeWhvOGMZTQjtGKcF4Pu5+mBX2fK 64qHsan3n1ldX/y0TiRIzbih6PFMxCQSdbez/WsV5FWmBAxaPMTzEf1lb9LYveQja4Oi NZ7d13dZ+tsg2jXK5j9elKIbcgImWE0jjNORaonNilcvLmXZH0C3m9JE06R9I7ZPnQNZ o4YJHIk3zz5EItWEz/ZAjWm0FJ7ripa/8uJ0M/HUf2Jhd/PeHHnX98L/lxyUzE3EabVN OWJg== X-Gm-Message-State: AOAM533GgBiSJGYHWqsy22nPmqHwxlXs3C+KiC3SXIRCXu8HT1/7Sw1y DHhmcxYWWOcMcrlVmrG30z1azRYFHcwHM02H X-Google-Smtp-Source: ABdhPJw014SYF3psdIDGjlhid1fRVNEBBQbY1YwCDqvTnYr/doIwp44uOR05AZwjnNRQT9mQjprejA== X-Received: by 2002:a05:600c:2141:: with SMTP id v1mr16762792wml.22.1618747385562; Sun, 18 Apr 2021 05:03:05 -0700 (PDT) Received: from debil.vdiclient.nvidia.com (84-238-136-197.ip.btc-net.bg. [84.238.136.197]) by smtp.gmail.com with ESMTPSA id x25sm16584763wmj.34.2021.04.18.05.03.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Apr 2021 05:03:05 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: roopa@nvidia.com, dsahern@gmail.com, Nikolay Aleksandrov Subject: [PATCH iproute2-next 4/6] libnetlink: add bridge vlan dump request helper Date: Sun, 18 Apr 2021 15:01:35 +0300 Message-Id: <20210418120137.2605522-5-razor@blackwall.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210418120137.2605522-1-razor@blackwall.org> References: <20210418120137.2605522-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Nikolay Aleksandrov Add rtnl bridge vlan dump request helper which will be used to retrieve bridge vlan information and options. Signed-off-by: Nikolay Aleksandrov --- include/libnetlink.h | 2 ++ lib/libnetlink.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/libnetlink.h b/include/libnetlink.h index e8ed5d7fb495..da96c69b9ede 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -69,6 +69,8 @@ int rtnl_neightbldump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); int rtnl_mdbdump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); +int rtnl_brvlandump_req(struct rtnl_handle *rth, int family, __u32 dump_flags) + __attribute__((warn_unused_result)); int rtnl_netconfdump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 6885087b34f9..2f2cc1fe0a61 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -450,6 +450,25 @@ int rtnl_mdbdump_req(struct rtnl_handle *rth, int family) return send(rth->fd, &req, sizeof(req), 0); } +int rtnl_brvlandump_req(struct rtnl_handle *rth, int family, __u32 dump_flags) +{ + struct { + struct nlmsghdr nlh; + struct br_vlan_msg bvm; + char buf[256]; + } req = { + .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct br_vlan_msg)), + .nlh.nlmsg_type = RTM_GETVLAN, + .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .bvm.family = family, + }; + + addattr32(&req.nlh, sizeof(req), BRIDGE_VLANDB_DUMP_FLAGS, dump_flags); + + return send(rth->fd, &req, sizeof(req), 0); +} + int rtnl_netconfdump_req(struct rtnl_handle *rth, int family) { struct { From patchwork Sun Apr 18 12:01:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12210061 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63542C433ED for ; Sun, 18 Apr 2021 12:03:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 452D561019 for ; Sun, 18 Apr 2021 12:03:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234677AbhDRMDm (ORCPT ); Sun, 18 Apr 2021 08:03:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231312AbhDRMDh (ORCPT ); Sun, 18 Apr 2021 08:03:37 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01363C06174A for ; Sun, 18 Apr 2021 05:03:08 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id w186so12131891wmg.3 for ; Sun, 18 Apr 2021 05:03:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=on3EgqSKCI//AH2PnGOSrMuXlDspgsGk19tPu2f6tWQ=; b=zgiUqJG55c77cfyJVvxo5rBBUC4l5+Tbae8RDOZiijuksl4JvkgwrQyVHT4spiDkDL AEIBKYeDEuWwX4wrRPQeAL7AMadIpkrDxTBxyNXNrfkp+WRDBtTXTAlUPjDsVCcCoDo6 1YDjNIZVeJvxMv+EyW7ltSHxoj5UDIGkwDJBkaxOVhtUQ+n1oq2+mQ0C59FDlp+ib0eM Z1zqViluOpE3ZUqKJu5oU1e9TG1/SGEBLV89sXoVV6izepurOg666sPNteFRa9lzNZUy MfjKApCdaUp/oJGYwQmgK73uUa7DRlZyzk4OOJCjXjYGBNgzdRVy5r+hZ0H4HdmIQAY/ 0eEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=on3EgqSKCI//AH2PnGOSrMuXlDspgsGk19tPu2f6tWQ=; b=h8MPlbj4piWA7dcNDBiwkz8lu850gKkZkhKBTlAu5YPVzXpZYp0GIwrG3y6jxGjda1 +OzYj+n9Dix6h8kdIuCf5ZBKpDeIRP4dcmYqOIN8SYoLzB6G5T4mDnEsnIOa/mNxJt2U IzhuptxbOJOfWWSGYouuQj2fxRov4P/ot8e4txJuYyjKUqG91iFFc+DnjkykXS0KZVs1 3ou0c+TVYF1O/RFAYKRAAP7/T5hOBcdCIymSRDatZ+Pq8gSSmNTI0YR4e75ZA8AAYfbO dC1qzOlMzhXRnHi4vwHVK3WrBVUiZyLGZsfOx/9O5dx0PuQ8WByMnzQdprz4amjufg73 4Mtg== X-Gm-Message-State: AOAM532BYBKqynJOwof5SWZK3zK8uUn5CgGNT6EsqmGNWGwg7gn9N+1E UqgX6dCR+oUTFMhGVm0fw92PWl2V3z6re0ai X-Google-Smtp-Source: ABdhPJzKaM1k4yDyaMtCnpCpDGE+Xy6pUAYzSNOdvct7ACWWqstx3qqBLrQq+BJ6ndIWosRNunw4ZQ== X-Received: by 2002:a1c:bd85:: with SMTP id n127mr16725009wmf.37.1618747386393; Sun, 18 Apr 2021 05:03:06 -0700 (PDT) Received: from debil.vdiclient.nvidia.com (84-238-136-197.ip.btc-net.bg. [84.238.136.197]) by smtp.gmail.com with ESMTPSA id x25sm16584763wmj.34.2021.04.18.05.03.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Apr 2021 05:03:06 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: roopa@nvidia.com, dsahern@gmail.com, Nikolay Aleksandrov Subject: [PATCH iproute2-next 5/6] bridge: vlan: add support for the new rtm dump call Date: Sun, 18 Apr 2021 15:01:36 +0300 Message-Id: <20210418120137.2605522-6-razor@blackwall.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210418120137.2605522-1-razor@blackwall.org> References: <20210418120137.2605522-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Nikolay Aleksandrov Use the new bridge vlan rtm dump helper to dump all of the available vlan information when -details (-d) is used with vlan show. It is also capable of dumping vlan stats if -statistics (-s) is added. Currently this is the only interface capable of dumping per-vlan options. The vlan dump format is compatible with current vlan show, it uses the same helpers to dump vlan information. The new addition is one line which will contain the per-vlan options (similar to ip -d link show for ports). Currently only the vlan STP state is printed. The call uses compressed vlan format by default. Example: $ bridge -s -d vlan show port vlan-id virbr1 1 PVID Egress Untagged state forwarding Signed-off-by: Nikolay Aleksandrov --- bridge/br_common.h | 1 + bridge/vlan.c | 147 ++++++++++++++++++++++++++++++++++++++++--- include/libnetlink.h | 5 ++ man/man8/bridge.8 | 7 ++- 4 files changed, 152 insertions(+), 8 deletions(-) diff --git a/bridge/br_common.h b/bridge/br_common.h index 33e56452702b..43870546ff28 100644 --- a/bridge/br_common.h +++ b/bridge/br_common.h @@ -12,6 +12,7 @@ int print_mdb_mon(struct nlmsghdr *n, void *arg); int print_fdb(struct nlmsghdr *n, void *arg); void print_stp_state(__u8 state); int parse_stp_state(const char *arg); +int print_vlan_rtm(struct nlmsghdr *n, void *arg); int do_fdb(int argc, char **argv); int do_mdb(int argc, char **argv); diff --git a/bridge/vlan.c b/bridge/vlan.c index 09884870df81..c681e14189b8 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -16,6 +16,7 @@ #include "utils.h" static unsigned int filter_index, filter_vlan; +static int vlan_rtm_cur_ifidx = -1; enum vlan_show_subject { VLAN_SHOW_VLAN, @@ -517,14 +518,8 @@ static void print_vlan_flags(__u16 flags) close_json_array(PRINT_JSON, NULL); } -static void print_one_vlan_stats(const struct bridge_vlan_xstats *vstats) +static void __print_one_vlan_stats(const struct bridge_vlan_xstats *vstats) { - open_json_object(NULL); - - print_hu(PRINT_ANY, "vid", "%hu", vstats->vid); - print_vlan_flags(vstats->flags); - print_nl(); - print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); print_lluint(PRINT_ANY, "rx_bytes", "RX: %llu bytes", vstats->rx_bytes); @@ -536,6 +531,16 @@ static void print_one_vlan_stats(const struct bridge_vlan_xstats *vstats) vstats->tx_bytes); print_lluint(PRINT_ANY, "tx_packets", " %llu packets\n", vstats->tx_packets); +} + +static void print_one_vlan_stats(const struct bridge_vlan_xstats *vstats) +{ + open_json_object(NULL); + + print_hu(PRINT_ANY, "vid", "%hu", vstats->vid); + print_vlan_flags(vstats->flags); + print_nl(); + __print_one_vlan_stats(vstats); close_json_object(); } @@ -616,6 +621,105 @@ static int print_vlan_stats(struct nlmsghdr *n, void *arg) return 0; } +int print_vlan_rtm(struct nlmsghdr *n, void *arg) +{ + struct rtattr *vtb[BRIDGE_VLANDB_ENTRY_MAX + 1], *a; + struct br_vlan_msg *bvm = NLMSG_DATA(n); + int len = n->nlmsg_len; + bool newport = false; + int rem; + + if (n->nlmsg_type != RTM_NEWVLAN && n->nlmsg_type != RTM_DELVLAN && + n->nlmsg_type != RTM_GETVLAN) { + fprintf(stderr, "Unknown vlan rtm message: %08x %08x %08x\n", + n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); + return 0; + } + + len -= NLMSG_LENGTH(sizeof(*bvm)); + if (len < 0) { + fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); + return -1; + } + + if (bvm->family != AF_BRIDGE) + return 0; + + if (filter_index && filter_index != bvm->ifindex) + return 0; + + if (vlan_rtm_cur_ifidx == -1 || vlan_rtm_cur_ifidx != bvm->ifindex) { + if (vlan_rtm_cur_ifidx != -1) + close_vlan_port(); + open_vlan_port(bvm->ifindex, VLAN_SHOW_VLAN); + vlan_rtm_cur_ifidx = bvm->ifindex; + newport = true; + } + + rem = len; + for (a = BRVLAN_RTA(bvm); RTA_OK(a, rem); a = RTA_NEXT(a, rem)) { + struct bridge_vlan_xstats vstats; + struct bridge_vlan_info *vinfo; + __u32 vrange = 0; + __u8 state = 0; + + parse_rtattr_flags(vtb, BRIDGE_VLANDB_ENTRY_MAX, RTA_DATA(a), + RTA_PAYLOAD(a), NLA_F_NESTED); + vinfo = RTA_DATA(vtb[BRIDGE_VLANDB_ENTRY_INFO]); + + memset(&vstats, 0, sizeof(vstats)); + if (vtb[BRIDGE_VLANDB_ENTRY_RANGE]) + vrange = rta_getattr_u16(vtb[BRIDGE_VLANDB_ENTRY_RANGE]); + else + vrange = vinfo->vid; + + if (vtb[BRIDGE_VLANDB_ENTRY_STATE]) + state = rta_getattr_u8(vtb[BRIDGE_VLANDB_ENTRY_STATE]); + + if (vtb[BRIDGE_VLANDB_ENTRY_STATS]) { + struct rtattr *stb[BRIDGE_VLANDB_STATS_MAX+1]; + struct rtattr *attr; + + attr = vtb[BRIDGE_VLANDB_ENTRY_STATS]; + parse_rtattr(stb, BRIDGE_VLANDB_STATS_MAX, RTA_DATA(attr), + RTA_PAYLOAD(attr)); + + if (stb[BRIDGE_VLANDB_STATS_RX_BYTES]) { + attr = stb[BRIDGE_VLANDB_STATS_RX_BYTES]; + vstats.rx_bytes = rta_getattr_u64(attr); + } + if (stb[BRIDGE_VLANDB_STATS_RX_PACKETS]) { + attr = stb[BRIDGE_VLANDB_STATS_RX_PACKETS]; + vstats.rx_packets = rta_getattr_u64(attr); + } + if (stb[BRIDGE_VLANDB_STATS_TX_PACKETS]) { + attr = stb[BRIDGE_VLANDB_STATS_TX_PACKETS]; + vstats.tx_packets = rta_getattr_u64(attr); + } + if (stb[BRIDGE_VLANDB_STATS_TX_BYTES]) { + attr = stb[BRIDGE_VLANDB_STATS_TX_BYTES]; + vstats.tx_bytes = rta_getattr_u64(attr); + } + } + open_json_object(NULL); + if (!newport) + print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + else + newport = false; + print_range("vlan", vinfo->vid, vrange); + print_vlan_flags(vinfo->flags); + print_nl(); + print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + print_stp_state(state); + print_nl(); + if (show_stats) + __print_one_vlan_stats(&vstats); + close_json_object(); + } + + return 0; +} + static int vlan_show(int argc, char **argv, int subject) { char *filter_dev = NULL; @@ -644,6 +748,34 @@ static int vlan_show(int argc, char **argv, int subject) new_json_obj(json); + /* if show_details is true then use the new bridge vlan dump format */ + if (show_details && subject == VLAN_SHOW_VLAN) { + __u32 dump_flags = show_stats ? BRIDGE_VLANDB_DUMPF_STATS : 0; + + if (rtnl_brvlandump_req(&rth, PF_BRIDGE, dump_flags) < 0) { + perror("Cannot send dump request"); + exit(1); + } + + if (!is_json_context()) { + printf("%-" __stringify(IFNAMSIZ) "s %-" + __stringify(VLAN_ID_LEN) "s", "port", + "vlan-id"); + printf("\n"); + } + + ret = rtnl_dump_filter(&rth, print_vlan_rtm, &subject); + if (ret < 0) { + fprintf(stderr, "Dump terminated\n"); + exit(1); + } + + if (vlan_rtm_cur_ifidx != -1) + close_vlan_port(); + + goto out; + } + if (!show_stats) { if (rtnl_linkdump_req_filter(&rth, PF_BRIDGE, (compress_vlans ? @@ -697,6 +829,7 @@ static int vlan_show(int argc, char **argv, int subject) } } +out: delete_json_obj(); fflush(stdout); return 0; diff --git a/include/libnetlink.h b/include/libnetlink.h index da96c69b9ede..6bff6bae6ddf 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -285,6 +285,11 @@ int rtnl_from_file(FILE *, rtnl_listen_filter_t handler, ((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct if_stats_msg)))) #endif +#ifndef BRVLAN_RTA +#define BRVLAN_RTA(r) \ + ((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct br_vlan_msg)))) +#endif + /* User defined nlmsg_type which is used mostly for logging netlink * messages from dump file */ #define NLMSG_TSTAMP 15 diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index 90dcae73ce71..9c8ebac3c6aa 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -171,7 +171,7 @@ As a rule, the information is statistics or some time values. .TP .BR "\-d" , " \-details" -print detailed information about MDB router ports. +print detailed information about bridge vlan filter entries or MDB router ports. .TP .BR "\-n" , " \-net" , " \-netns " @@ -881,6 +881,11 @@ STP BPDUs. This command displays the current VLAN filter table. +.PP +With the +.B -details +option, the command becomes verbose. It displays the per-vlan options. + .PP With the .B -statistics From patchwork Sun Apr 18 12:01:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12210063 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C055CC433B4 for ; Sun, 18 Apr 2021 12:03:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9BA5961359 for ; Sun, 18 Apr 2021 12:03:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235116AbhDRMDp (ORCPT ); Sun, 18 Apr 2021 08:03:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231338AbhDRMDh (ORCPT ); Sun, 18 Apr 2021 08:03:37 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2E9EC061760 for ; Sun, 18 Apr 2021 05:03:08 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id o21-20020a1c4d150000b029012e52898006so6921447wmh.0 for ; Sun, 18 Apr 2021 05:03:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EpHY1MbAXhUL60YiE+86B1HjUYTVmOkAbHwqH2hSAgQ=; b=P+mDJEhy8rVpLdF6TRuTvH+n5zRyT9uhAAip+UN2ZVPcxFhwwK66DA5NRGd1fWz2h1 ahJtmC5XRkIPmbI9+Qa109XKDN9QHxXSMmpw3xU3z/VTvSirngLL3rzAjClNK0NaoCdC HXuXJWpIKanq2kPcGLjRvoETycaYxbfRSFORqXIlwSpcsA/QBYI1CG8eAgkH7OwAD0x2 jfUp2vd9sfbJgEBxYL7GKX3m7ZKwJiVBSsfQxDAFZiTnZH5i56dzeCq7G/waLXA0+vRp 3peeNy0O3uJy+Qbb6nQPmN2dAQepN/jCxKrqVOIhIlg1WsPo4Dzmz59nFkWzMoJTZXjo zKpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EpHY1MbAXhUL60YiE+86B1HjUYTVmOkAbHwqH2hSAgQ=; b=mARNM63B4Z/eYmGYsWUCaXdCpe5pz0Aw8WJEI/Wxi4vkFhMUYeEednXYYyRts72LNf ABVn8ziWqO/J2ohlI0zMDfHLJn+A5HAYGRGInOorcJVW79aePKUWIrw0gga9xMXrcKqw 6lzzCzqHzJq2VQsRQdxh+/MrOFzP1pL+ZgZR/EEwtZyY7SQZ4EinW0ndo8FAhCYAxdXg S/5SPI/EeKRSMMa/6BY8Xw/xTGttXI+pKEw6uuRCGplac3SNxTqnItHDcT6fuuB7dwL4 2XtiXuA39M+NrPYb21nmsTl/bZRnqd+YkA6jXcynE2fFI6V0UnCsiFrf0qjx2M9JsW8z oD6w== X-Gm-Message-State: AOAM532M15wpVmdMO+VfHX7KCfZ6Y3netTbVIXXo6w14PPGW91vZOh/k Z75RQrCLnBCnvXFRuoQMAZOtBtHMvo8UbR9B X-Google-Smtp-Source: ABdhPJxmh4IHvz+rq6ZvviumLM5rB+lLgH1WvASRbyX93T1uFxto1s0vv9S/foMOavEAl5dbe52tyw== X-Received: by 2002:a1c:c918:: with SMTP id f24mr17158729wmb.12.1618747387111; Sun, 18 Apr 2021 05:03:07 -0700 (PDT) Received: from debil.vdiclient.nvidia.com (84-238-136-197.ip.btc-net.bg. [84.238.136.197]) by smtp.gmail.com with ESMTPSA id x25sm16584763wmj.34.2021.04.18.05.03.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Apr 2021 05:03:06 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: roopa@nvidia.com, dsahern@gmail.com, Nikolay Aleksandrov Subject: [PATCH iproute2-next 6/6] bridge: monitor: add support for vlan monitoring Date: Sun, 18 Apr 2021 15:01:37 +0300 Message-Id: <20210418120137.2605522-7-razor@blackwall.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210418120137.2605522-1-razor@blackwall.org> References: <20210418120137.2605522-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Nikolay Aleksandrov Add support for vlan activity monitoring, we display vlan notifications on vlan add/del/options change. The man page and help are also updated accordingly. Signed-off-by: Nikolay Aleksandrov --- bridge/br_common.h | 2 +- bridge/mdb.c | 2 +- bridge/monitor.c | 19 ++++++++++++++++++- bridge/vlan.c | 15 +++++++++++++-- man/man8/bridge.8 | 4 ++-- 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/bridge/br_common.h b/bridge/br_common.h index 43870546ff28..b9adafd98dea 100644 --- a/bridge/br_common.h +++ b/bridge/br_common.h @@ -12,7 +12,7 @@ int print_mdb_mon(struct nlmsghdr *n, void *arg); int print_fdb(struct nlmsghdr *n, void *arg); void print_stp_state(__u8 state); int parse_stp_state(const char *arg); -int print_vlan_rtm(struct nlmsghdr *n, void *arg); +int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor); int do_fdb(int argc, char **argv); int do_mdb(int argc, char **argv); diff --git a/bridge/mdb.c b/bridge/mdb.c index ef89258bc5c3..b427d878677f 100644 --- a/bridge/mdb.c +++ b/bridge/mdb.c @@ -16,9 +16,9 @@ #include #include "libnetlink.h" +#include "utils.h" #include "br_common.h" #include "rt_names.h" -#include "utils.h" #include "json_print.h" #ifndef MDBA_RTA diff --git a/bridge/monitor.c b/bridge/monitor.c index 08439a60288a..88f52f52f084 100644 --- a/bridge/monitor.c +++ b/bridge/monitor.c @@ -31,7 +31,7 @@ static int prefix_banner; static void usage(void) { - fprintf(stderr, "Usage: bridge monitor [file | link | fdb | mdb | all]\n"); + fprintf(stderr, "Usage: bridge monitor [file | link | fdb | mdb | vlan | all]\n"); exit(-1); } @@ -67,6 +67,12 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl, print_nlmsg_timestamp(fp, n); return 0; + case RTM_NEWVLAN: + case RTM_DELVLAN: + if (prefix_banner) + fprintf(fp, "[VLAN]"); + return print_vlan_rtm(n, arg, true); + default: return 0; } @@ -79,6 +85,7 @@ int do_monitor(int argc, char **argv) int llink = 0; int lneigh = 0; int lmdb = 0; + int lvlan = 0; rtnl_close(&rth); @@ -95,8 +102,12 @@ int do_monitor(int argc, char **argv) } else if (matches(*argv, "mdb") == 0) { lmdb = 1; groups = 0; + } else if (matches(*argv, "vlan") == 0) { + lvlan = 1; + groups = 0; } else if (strcmp(*argv, "all") == 0) { groups = ~RTMGRP_TC; + lvlan = 1; prefix_banner = 1; } else if (matches(*argv, "help") == 0) { usage(); @@ -134,6 +145,12 @@ int do_monitor(int argc, char **argv) if (rtnl_open(&rth, groups) < 0) exit(1); + + if (lvlan && rtnl_add_nl_group(&rth, RTNLGRP_BRVLAN) < 0) { + fprintf(stderr, "Failed to add bridge vlan group to list\n"); + exit(1); + } + ll_init_map(&rth); if (rtnl_listen(&rth, accept_msg, stdout) < 0) diff --git a/bridge/vlan.c b/bridge/vlan.c index c681e14189b8..9bb9e28d11bb 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -621,7 +621,7 @@ static int print_vlan_stats(struct nlmsghdr *n, void *arg) return 0; } -int print_vlan_rtm(struct nlmsghdr *n, void *arg) +int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor) { struct rtattr *vtb[BRIDGE_VLANDB_ENTRY_MAX + 1], *a; struct br_vlan_msg *bvm = NLMSG_DATA(n); @@ -648,6 +648,12 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg) if (filter_index && filter_index != bvm->ifindex) return 0; + if (n->nlmsg_type == RTM_DELVLAN) + print_bool(PRINT_ANY, "deleted", "Deleted ", true); + + if (monitor) + vlan_rtm_cur_ifidx = -1; + if (vlan_rtm_cur_ifidx == -1 || vlan_rtm_cur_ifidx != bvm->ifindex) { if (vlan_rtm_cur_ifidx != -1) close_vlan_port(); @@ -720,6 +726,11 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg) return 0; } +static int print_vlan_rtm_filter(struct nlmsghdr *n, void *arg) +{ + return print_vlan_rtm(n, arg, false); +} + static int vlan_show(int argc, char **argv, int subject) { char *filter_dev = NULL; @@ -764,7 +775,7 @@ static int vlan_show(int argc, char **argv, int subject) printf("\n"); } - ret = rtnl_dump_filter(&rth, print_vlan_rtm, &subject); + ret = rtnl_dump_filter(&rth, print_vlan_rtm_filter, &subject); if (ret < 0) { fprintf(stderr, "Dump terminated\n"); exit(1); diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index 9c8ebac3c6aa..eec7df4383bc 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -153,7 +153,7 @@ bridge \- show / manipulate bridge addresses and devices .IR DEV " ]" .ti -8 -.BR "bridge monitor" " [ " all " | " neigh " | " link " | " mdb " ]" +.BR "bridge monitor" " [ " all " | " neigh " | " link " | " mdb " | " vlan " ]" .SH OPTIONS @@ -911,7 +911,7 @@ command is the first in the command line and then the object list follows: .I OBJECT-LIST is the list of object types that we want to monitor. It may contain -.BR link ", " fdb ", and " mdb "." +.BR link ", " fdb ", " vlan " and " mdb "." If no .B file argument is given,