From patchwork Wed Sep 1 10:38:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12469047 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,URIBL_BLOCKED,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 378A2C4320A for ; Wed, 1 Sep 2021 10:38:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1CFCF60724 for ; Wed, 1 Sep 2021 10:38:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235980AbhIAKjU (ORCPT ); Wed, 1 Sep 2021 06:39:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235258AbhIAKjS (ORCPT ); Wed, 1 Sep 2021 06:39:18 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0534EC061575 for ; Wed, 1 Sep 2021 03:38:22 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id me10so5529686ejb.11 for ; Wed, 01 Sep 2021 03:38:21 -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=5lE8m62tSp6aNk3T+0edy9NLkv9Nbj+TwR8sRB68q/U=; b=r38fXqtj0XWEpOrqaPxCMZnGb7K3jLQY1GH8Ac98CaLoHBpX0aeO1ydAU3aonDEbVP 8F2vaMwuvwaWcgn1Dt2h7NGibxFJyTg1UAnvrcnfdPqAJp7yS8Xs0is2N1VKkS3a9UIk 36eLdEGepTtUs7a7c0+9VRW8ipfEhkiPuW91La5i46Aj6aveMxElvlvQOKH2VxL+9K65 cv3IZaYtjICmw688pJWtyAYq3TOWKR0PwWpfihwXN8NAL898A62nT3KP51AYNgRoKYtA fRadfZ4kYFbyV0IEgj/+J8pQOr98684l5/SNtP83CQ9jjcX2l+oCNuT7lQ3lm6EtN7LB mCNg== 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=5lE8m62tSp6aNk3T+0edy9NLkv9Nbj+TwR8sRB68q/U=; b=Z4PI02x6/Oyq9vPvfQJNaRvgPxb6eAT/5RjQ9UpZh5F2gzYNo7LmWphTR7m1m/3fk0 TzsannBBnG87smL5O+7X1vn+giVhGGWgLM4E9ZX9hrJgV6XMes2RSColLM0fDgxvopgA /7U+6//R+aH9TDEZ+t5k+oGR90gkt68Pub1iOUsPKSDBxGuaKzvINMljd4qjgA3T0rMR qrQmXCNhba5owqc1ntkjFzA9h1djbJPQple2OSm7lrSO+oU6Ruy3E08LiJKMq7FldrBk 2glHAD2OqxsHNEnNuR/XFLqHwMAS4dJnU9G/z+2rxAZDl61Fp4tJ06+XlerrWJ8SiiFI 5mbw== X-Gm-Message-State: AOAM532f1Kj1jZOdff0OnCX81QgkuHSt9Hr4ckj/O0INl5Zt31xA7p1L ++imy+PzIXLmEPwVUmc5DMBCkJ059ZiCvaSt X-Google-Smtp-Source: ABdhPJyGOIKOHb9VRmGn+h/Gi97NXxR9MkB/59DyfCLWgS7h5zO/GadQ6hYeiRC6zdH47dUgKYksSQ== X-Received: by 2002:a17:907:766e:: with SMTP id kk14mr35704971ejc.339.1630492700368; Wed, 01 Sep 2021 03:38:20 -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 y23sm9580527ejp.115.2021.09.01.03.38.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 03:38:20 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: roopa@nvidia.com, dsahern@gmail.com, stephen@networkplumber.org, Nikolay Aleksandrov Subject: [PATCH iproute2-next 1/2] bridge: vlan: set vlan option attributes while parsing Date: Wed, 1 Sep 2021 13:38:15 +0300 Message-Id: <20210901103816.1163765-2-razor@blackwall.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210901103816.1163765-1-razor@blackwall.org> References: <20210901103816.1163765-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 Set vlan option attributes immediately while parsing to simplify the checks, avoid having reserved values (e.g. -1 for unset var) and have more limited scope for the variables. This is also similar to how global vlan options are set. The attribute setting and checks are moved with option parsing, no functional changes intended. Signed-off-by: Nikolay Aleksandrov --- bridge/vlan.c | 53 ++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 4ead57b783a8..48365bca4c4a 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -272,16 +272,24 @@ static int vlan_option_set(int argc, char **argv) }; struct bridge_vlan_info vinfo = {}; struct rtattr *afspec; - short vid_end = -1; char *d = NULL; short vid = -1; - int state = -1; + afspec = addattr_nest(&req.n, sizeof(req), BRIDGE_VLANDB_ENTRY); + afspec->rta_type |= NLA_F_NESTED; while (argc > 0) { if (strcmp(*argv, "dev") == 0) { NEXT_ARG(); d = *argv; + req.bvm.ifindex = ll_name_to_index(d); + if (req.bvm.ifindex == 0) { + fprintf(stderr, + "Cannot find network device \"%s\"\n", + d); + return -1; + } } else if (strcmp(*argv, "vid") == 0) { + short vid_end = -1; char *p; NEXT_ARG(); @@ -299,8 +307,22 @@ static int vlan_option_set(int argc, char **argv) } else { vid = atoi(*argv); } + if (vid >= 4096) { + fprintf(stderr, "Invalid VLAN ID \"%hu\"\n", + vid); + return -1; + } + + 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); } else if (strcmp(*argv, "state") == 0) { char *endptr; + int state; NEXT_ARG(); state = strtol(*argv, &endptr, 10); @@ -310,42 +332,21 @@ static int vlan_option_set(int argc, char **argv) fprintf(stderr, "Error: invalid STP state\n"); return -1; } + addattr8(&req.n, sizeof(req), BRIDGE_VLANDB_ENTRY_STATE, + state); } else { if (matches(*argv, "help") == 0) NEXT_ARG(); } argc--; argv++; } + addattr_nest_end(&req.n, afspec); 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; From patchwork Wed Sep 1 10:38:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12469049 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,URIBL_BLOCKED,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 C3D97C4320E for ; Wed, 1 Sep 2021 10:38:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A57F860724 for ; Wed, 1 Sep 2021 10:38:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236262AbhIAKjW (ORCPT ); Wed, 1 Sep 2021 06:39:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235782AbhIAKjT (ORCPT ); Wed, 1 Sep 2021 06:39:19 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0455CC061575 for ; Wed, 1 Sep 2021 03:38:23 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id u19so3126353edb.3 for ; Wed, 01 Sep 2021 03:38:22 -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=0qbAjndh2+jmxHkbpCy1/hG88MHkSdQ6vCKeHXY4Lw0=; b=zldFIW9Rh54R9CVqGp7ZlMMZZeyjw+LhnlOGs+R6bTD8pcqbkPGJbp3wzg40zrloh1 d0O2wF4DUGpuVG/HK9gFlk8WZseIPp3/PJXC9qTPwQeQLKOQDgbL0Bj/VNGiiu7N6DGA F3VjjCtKwm3cxtK+5H95rAeXodxc0aLsYWvmSk5qz7POsay553uvnmgk7BhePxUsmAg8 q/cl1mHqRmR1f0lrP39k/Sfwxuh02GgoN69oMh8hsH2dI09U3rSjNUDfI++hXtc9SBeI nXW91fS+muscvdj9TUX6mCTShV1PW93gAFr2AbsStw2efO91oGYxza8mEL2FJkVxNwDU e+LA== 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=0qbAjndh2+jmxHkbpCy1/hG88MHkSdQ6vCKeHXY4Lw0=; b=Xq1oJwwV5qRe5/u6aFIJeQam4BS6RQHcag6PH2UYsLe/QuMxre+Uew//V5B11S7zaT SJ3fuEEy84SH67iBnjNxTS0DJeprdEWjEyLBbixuY/jYwrfjaQ2GxPj6XPGuyiY+hg7/ 3ohxAmdRGMIpSpUl43UlPLYbNe47ONiW2xcQGfS1cmz8ymeCJFGvtqGuPU6kCLRAAKzG kMdGLmX5TgmoBWc0HzKeTI60ZDg2ZbV9GV4B5Lz4+t+okq97P7UjBYAIL43uj7KJf5BF nZhBJhZjkcbF1pHnBY+xqROTmNxmCc2Fs1EPOBJoUPIffurqyIqV3E0ElSFnd1KwPtfu cuDw== X-Gm-Message-State: AOAM5310cOEFEXasm0ETYfwpj22bcas8b2kJvqiZLfD2Qxz/FKIvuHf5 u4gfl1k+4mrgRgojRcykMFaJuUF7eckpR4be X-Google-Smtp-Source: ABdhPJyI6vfkV5cXgQi/B9UVClx5SKxkMgBwaw0wlPyEbeXXskjR5bOWELizHzqVoc+mnkAMu+SzTQ== X-Received: by 2002:a05:6402:705:: with SMTP id w5mr34960520edx.344.1630492701327; Wed, 01 Sep 2021 03:38:21 -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 y23sm9580527ejp.115.2021.09.01.03.38.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 03:38:20 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: roopa@nvidia.com, dsahern@gmail.com, stephen@networkplumber.org, Nikolay Aleksandrov Subject: [PATCH iproute2-next 2/2] bridge: vlan: add support for mcast_router option Date: Wed, 1 Sep 2021 13:38:16 +0300 Message-Id: <20210901103816.1163765-3-razor@blackwall.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210901103816.1163765-1-razor@blackwall.org> References: <20210901103816.1163765-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 setting and dumping per-vlan/interface mcast_router option. It controls the mcast router mode of a vlan/interface pair. For bridge devices only modes 0 - 2 are allowed. The possible modes are: 0 - disabled 1 - automatic router presence detection (default) 2 - permanent router 3 - temporary router (available only for ports) Example: # mark port ens16 as a permanent mcast router for vlan 100 $ bridge vlan set dev ens16 vid 100 mcast_router 2 # disable mcast router for port ens16 and vlan 200 $ bridge vlan set dev ens16 vid 200 mcast_router 0 $ bridge -d vlan show port vlan-id ens16 1 PVID Egress Untagged state forwarding mcast_router 1 100 state forwarding mcast_router 2 200 state forwarding mcast_router 0 Signed-off-by: Nikolay Aleksandrov --- bridge/vlan.c | 17 ++++++++++++++++- man/man8/bridge.8 | 29 ++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 48365bca4c4a..8300f353f1a7 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -36,6 +36,7 @@ static void usage(void) " [ pvid ] [ untagged ]\n" " [ self ] [ master ]\n" " bridge vlan { set } vid VLAN_ID dev DEV [ state STP_STATE ]\n" + " [ mcast_router MULTICAST_ROUTER ]\n" " bridge vlan { show } [ dev DEV ] [ vid VLAN_ID ]\n" " bridge vlan { tunnelshow } [ dev DEV ] [ vid VLAN_ID ]\n" " bridge vlan global { set } vid VLAN_ID dev DEV\n" @@ -334,6 +335,15 @@ static int vlan_option_set(int argc, char **argv) } addattr8(&req.n, sizeof(req), BRIDGE_VLANDB_ENTRY_STATE, state); + } else if (strcmp(*argv, "mcast_router") == 0) { + __u8 mcast_router; + + NEXT_ARG(); + if (get_u8(&mcast_router, *argv, 0)) + invarg("invalid mcast_router", *argv); + addattr8(&req.n, sizeof(req), + BRIDGE_VLANDB_ENTRY_MCAST_ROUTER, + mcast_router); } else { if (matches(*argv, "help") == 0) NEXT_ARG(); @@ -942,7 +952,7 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) static void print_vlan_opts(struct rtattr *a, int ifindex) { - struct rtattr *vtb[BRIDGE_VLANDB_ENTRY_MAX + 1]; + struct rtattr *vtb[BRIDGE_VLANDB_ENTRY_MAX + 1], *vattr; struct bridge_vlan_xstats vstats; struct bridge_vlan_info *vinfo; __u16 vrange = 0; @@ -1006,6 +1016,11 @@ static void print_vlan_opts(struct rtattr *a, int ifindex) print_nl(); print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); print_stp_state(state); + if (vtb[BRIDGE_VLANDB_ENTRY_MCAST_ROUTER]) { + vattr = vtb[BRIDGE_VLANDB_ENTRY_MCAST_ROUTER]; + print_uint(PRINT_ANY, "mcast_router", "mcast_router %u ", + rta_getattr_u8(vattr)); + } print_nl(); if (show_stats) __print_one_vlan_stats(&vstats); diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index 76d2fa09d5bc..c3c4ae48aaed 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -145,7 +145,9 @@ bridge \- show / manipulate bridge addresses and devices .B vid .IR VID " [ " .B state -.IR STP_STATE " ] " +.IR STP_STATE " ] [ " +.B mcast_router +.IR MULTICAST_ROUTER " ]" .ti -8 .BR "bridge vlan" " [ " show " | " tunnelshow " ] [ " @@ -915,6 +917,31 @@ is used during the STP election process. In this state, the vlan will only proce STP BPDUs. .sp +.TP +.BI mcast_router " MULTICAST_ROUTER " +configure this vlan and interface's multicast router mode, note that only modes +0 - 2 are available for bridge devices. +A vlan and interface with a multicast router will receive all multicast traffic. +.I MULTICAST_ROUTER +may be either +.sp +.B 0 +- to disable multicast router. +.sp + +.B 1 +- to let the system detect the presence of routers (default). +.sp + +.B 2 +- to permanently enable multicast traffic forwarding on this vlan and interface. +.sp + +.B 3 +- to temporarily mark this vlan and port as having a multicast router, i.e. +enable multicast traffic forwarding. This mode is available only for ports. +.sp + .SS bridge vlan show - list vlan configuration. This command displays the current VLAN filter table.