From nobody Tue Apr 14 12:29:21 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9266CC19F2A for ; Sat, 30 Jul 2022 16:04:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235230AbiG3QEC (ORCPT ); Sat, 30 Jul 2022 12:04:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235084AbiG3QDx (ORCPT ); Sat, 30 Jul 2022 12:03:53 -0400 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5DFCC32; Sat, 30 Jul 2022 09:03:49 -0700 (PDT) Received: by mail-qv1-xf30.google.com with SMTP id y11so5609330qvn.3; Sat, 30 Jul 2022 09:03:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=44S36YW/XCMky1KM2xLak/T6CHlN1QC9bWrP+1FyJlw=; b=g0Q21UbliVaSVVRMLR3KfiO1ctfkqbex+ADs1SZPfocxQiayXVsduesPlZ4XJEiDIX MbPdTPlfkRj/GfrNerNSTILsktSvye1srw6OW48ozmemcia6FSJlgkXOKVrgKLANXPmu +FF/9kp/oYfvE7hwMdi6PzVw2QgMACsouWINDbI3zFGjUzpPw/b098zruYu7M0QyxJVR wkqAQxQKbgxWILj3gAe+4QNYGSNupa3H3lBxy4TR2c4d7ZMnUOr9D3b+A3G93pV0yHxu SjwEyUuZRP1dzX4nkN6wf9HzXqxi3wo2x6YbfP2j6OxJYslXCvJOkk6/wJiWe97PEDUP ii0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=44S36YW/XCMky1KM2xLak/T6CHlN1QC9bWrP+1FyJlw=; b=k44Z+mZ4u9hXSj3NHFUYEaQ7aKTDiaamGgLuixxfhir0mr3dStxvMRdU3a/qKFcOen okR1nygYSi+iD6q56Wd2MOJXd0ZxPZE8OnA9Ftsv+a+ZJRV+ma7iaWzqkB3SFRut9FHO tKHeqPfAmaJyBCuR3gU/roo8lIxGc5OE1tmjVGabdlA6X0lERaecpquqI9ZCpUjqPXrm ltAMFd0BOzVZxicFg2IyI6SEU3WqObWF0GllcrzlsXLKANhiJZ680WF/5Eycnmmru660 3B9Aid5GRmvhu+z23aWJCUFOlqJdlKUn+JW5vqVzYYE0Ciw8kUhSi0xSDqeh1LqWLnAv bD/g== X-Gm-Message-State: ACgBeo2JZFN5Aa6qMEkaDkK69a/sVPJ4qSeK5UsFz8cJspuluOa8IJQg C1WGAMG0BnaGLB89URljQ2A= X-Google-Smtp-Source: AA6agR72LGiu7HIQOzRisPgkgt460ylBNaCgT7TT8h/4h/r1C95WTkSNIdRTCU8PS2wEFypJCH4CJA== X-Received: by 2002:a05:6214:d47:b0:474:7f18:4764 with SMTP id 7-20020a0562140d4700b004747f184764mr7535850qvr.15.1659197028459; Sat, 30 Jul 2022 09:03:48 -0700 (PDT) Received: from ada ([71.58.109.160]) by smtp.gmail.com with ESMTPSA id do54-20020a05620a2b3600b006b5e833d996sm4877020qkb.22.2022.07.30.09.03.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Jul 2022 09:03:47 -0700 (PDT) From: Sevinj Aghayeva To: aroulin@nvidia.com Cc: sbrivio@redhat.com, roopa@nvidia.com, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Nikolay Aleksandrov , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bridge@lists.linux-foundation.org, Sevinj Aghayeva Subject: [PATCH net-next 1/3] net: bridge: export br_vlan_upper_change Date: Sat, 30 Jul 2022 12:03:30 -0400 Message-Id: <75d00c06deadc0386811874f9e4edbf5381df949.1659195179.git.sevinj.aghayeva@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This function contains the logic for correctly setting the bridge binding behavior of a vlan interface. Therefore, it should be executed whenever the bridge binding flag of a vlan interface changes via the vlan_dev_change_flags function in the 8021q module. Currently this function is private, and it is only executed when a vlan interface is first created. Export the function so that it can be called from vlan_dev_change_flags. Signed-off-by: Sevinj Aghayeva Reviewed-by: Stefano Brivio Reviewed-by: Andy Roulin Reviewed-by: Roopa Prabhu --- include/linux/if_bridge.h | 9 +++++++++ net/bridge/br_vlan.c | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/linux/if_bridge.h b/include/linux/if_bridge.h index d62ef428e3aa..0d92b0ed0961 100644 --- a/include/linux/if_bridge.h +++ b/include/linux/if_bridge.h @@ -180,6 +180,9 @@ void br_fdb_clear_offload(const struct net_device *dev,= u16 vid); bool br_port_flag_is_set(const struct net_device *dev, unsigned long flag); u8 br_port_get_stp_state(const struct net_device *dev); clock_t br_get_ageing_time(const struct net_device *br_dev); +void br_vlan_upper_change(struct net_device *dev, + struct net_device *upper_dev, + bool linking); #else static inline struct net_device * br_fdb_find_port(const struct net_device *br_dev, @@ -208,6 +211,12 @@ static inline clock_t br_get_ageing_time(const struct = net_device *br_dev) { return 0; } + +static inline void br_vlan_upper_change(struct net_device *dev, + struct net_device *upper_dev, + bool linking) +{ +} #endif =20 #endif diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 6e53dc991409..6bfc36da5a88 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -1653,9 +1653,9 @@ static void br_vlan_set_all_vlan_dev_state(struct net= _bridge_port *p) } } =20 -static void br_vlan_upper_change(struct net_device *dev, - struct net_device *upper_dev, - bool linking) +void br_vlan_upper_change(struct net_device *dev, + struct net_device *upper_dev, + bool linking) { struct net_bridge *br =3D netdev_priv(dev); =20 @@ -1670,6 +1670,7 @@ static void br_vlan_upper_change(struct net_device *d= ev, br_vlan_has_upper_bind_vlan_dev(dev)); } } +EXPORT_SYMBOL_GPL(br_vlan_upper_change); =20 struct br_vlan_link_state_walk_data { struct net_bridge *br; --=20 2.25.1 From nobody Tue Apr 14 12:29:21 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D29B3C19F2B for ; Sat, 30 Jul 2022 16:04:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235209AbiG3QD6 (ORCPT ); Sat, 30 Jul 2022 12:03:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235014AbiG3QDx (ORCPT ); Sat, 30 Jul 2022 12:03:53 -0400 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B340175AB; Sat, 30 Jul 2022 09:03:52 -0700 (PDT) Received: by mail-qk1-x735.google.com with SMTP id e12so3108769qkl.2; Sat, 30 Jul 2022 09:03:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zRKN74TQjwEeR1MXdcsMHUkpi1gfgBWwqBLJHY0W5pg=; b=e8obaoeKKLn4nDRJrPnpp+Nx91jHsh+5jGuLA3o7/VXte2H4xHqwCTGOn7N/ElemPK MFg6uCb2jlRoLX9GgA24VUIL1lnmH4D+w+C33UK9+pNXxer39+llNCC+Wr02JgR2Llw3 Ran1qCCSgTh1O1r7SV95sNfZwjKyeZ1ogrlIUio3i9j98DyrUGqHbDhQU8GOD58+m2Kd /j5dUOQpykwJ/1eOkbrFTOeEdXCow4cXUi0V5K19/nkBL8e27mePsdpTwmt0yz6Vn8bS O+pKMBzosX+WPPzrYaxvj7oNz1b58i+aAP980qMehS8gGMkahcHDtrfQNj1DfE41DY6n f8jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zRKN74TQjwEeR1MXdcsMHUkpi1gfgBWwqBLJHY0W5pg=; b=S4I4MbT4FvIvtgIjuuTt9AbmKwtKVlbuiujodCOb3UoKESxj2kKfERQ/G9iBXn0fuV SUsAQm23wv0Ef3VAQXX19JZMfJP6WFwpcXQJLYE3EF5UG0e+MI5NQAs/gu9kRmY8neOe qPjoh8iJtSBAXBxqoCXp9qPggX+tZCK24xkeJW7m0tGk3JkVzufvN3usPW/d2el2CTkR 9MUgx1JCmhcGWBcEK7onJvNSJpBQa5aFoaj2O7Bi8wTEUbvrf8hMpr7Ef0IlMCzAYeeW QCVeR2D6lR6He8clyJmjJ7u16NAzA23vtDRmzP1R9DuGyaImmfu8KWSKKIdAghpEg10X ReTg== X-Gm-Message-State: AJIora/xs06LCFaarn8BYlR02W1qvZb+BuRQuR+YgePefWQCdoFXsWOV /BD+cOuwVLB7Qj/y6pmWjpQ= X-Google-Smtp-Source: AGRyM1tQF4ZDhWXmr4879jKeaqsCfxS0+QIrYK0Pb8ySlm3tndMJl7qWrMdy9M/hl4hg1/I5gQJxBw== X-Received: by 2002:a05:620a:2453:b0:6b6:104a:b9b4 with SMTP id h19-20020a05620a245300b006b6104ab9b4mr6449215qkn.713.1659197031240; Sat, 30 Jul 2022 09:03:51 -0700 (PDT) Received: from ada ([71.58.109.160]) by smtp.gmail.com with ESMTPSA id h3-20020a05620a400300b006b5da3c8d81sm4986651qko.73.2022.07.30.09.03.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Jul 2022 09:03:50 -0700 (PDT) From: Sevinj Aghayeva To: aroulin@nvidia.com Cc: sbrivio@redhat.com, roopa@nvidia.com, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Nikolay Aleksandrov , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bridge@lists.linux-foundation.org, Sevinj Aghayeva Subject: [PATCH net-next 2/3] net: 8021q: fix bridge binding behavior for vlan interfaces Date: Sat, 30 Jul 2022 12:03:31 -0400 Message-Id: <2b09fbacde7e8818f4ada4829818fdf015e36b58.1659195179.git.sevinj.aghayeva@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently, when one creates a vlan interface with the bridge binding flag disabled (using ip link add... command) and then enables the bridge binding flag afterwards (using ip link set... command), the second command has no effect. In other words, the vlan interface does not follow the status of the ports in its vlan. The root cause of this problem is as follows. The correct bridge binding behavior depends on two flags being set: a per vlan interface flag (VLAN_FLAG_BRIDGE_BINDING) and global per bridge flag (BROPT_VLAN_BRIDGE_BINDING); the ip link set command calls vlan_dev_change_flags function, which sets only the per vlan interface flag. The correct behavior is to set/unset per bridge flag as well, depending on whether there are other vlan interfaces with bridge binding flags set. The logic for this behavior is already captured in br_vlan_upper_change function. This patch fixes the bridge binding behavior by calling the br_vlan_upper_change function whenever the per interface flag is changed via vlan_dev_change_flags function. Signed-off-by: Sevinj Aghayeva Reviewed-by: Stefano Brivio Reviewed-by: Andy Roulin Reviewed-by: Roopa Prabhu Reported-by: kernel test robot --- net/8021q/vlan.h | 2 +- net/8021q/vlan_dev.c | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h index 5eaf38875554..71947cdcfaaa 100644 --- a/net/8021q/vlan.h +++ b/net/8021q/vlan.h @@ -130,7 +130,7 @@ void vlan_dev_set_ingress_priority(const struct net_dev= ice *dev, int vlan_dev_set_egress_priority(const struct net_device *dev, u32 skb_prio, u16 vlan_prio); void vlan_dev_free_egress_priority(const struct net_device *dev); -int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask= ); +int vlan_dev_change_flags(struct net_device *dev, u32 flag, u32 mask); void vlan_dev_get_realdev_name(const struct net_device *dev, char *result, size_t size); =20 diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index 035812b0461c..93680bac60b3 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -30,6 +30,7 @@ #include "vlan.h" #include "vlanproc.h" #include +#include #include =20 /* @@ -211,10 +212,11 @@ int vlan_dev_set_egress_priority(const struct net_dev= ice *dev, /* Flags are defined in the vlan_flags enum in * include/uapi/linux/if_vlan.h file. */ -int vlan_dev_change_flags(const struct net_device *dev, u32 flags, u32 mas= k) +int vlan_dev_change_flags(struct net_device *dev, u32 flags, u32 mask) { struct vlan_dev_priv *vlan =3D vlan_dev_priv(dev); u32 old_flags =3D vlan->flags; + struct net_device *br_dev; =20 if (mask & ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP | VLAN_FLAG_LOOSE_BINDING | VLAN_FLAG_MVRP | @@ -223,19 +225,32 @@ int vlan_dev_change_flags(const struct net_device *de= v, u32 flags, u32 mask) =20 vlan->flags =3D (old_flags & ~mask) | (flags & mask); =20 - if (netif_running(dev) && (vlan->flags ^ old_flags) & VLAN_FLAG_GVRP) { + if (!netif_running(dev)) + return 0; + + if ((vlan->flags ^ old_flags) & VLAN_FLAG_GVRP) { if (vlan->flags & VLAN_FLAG_GVRP) vlan_gvrp_request_join(dev); else vlan_gvrp_request_leave(dev); } =20 - if (netif_running(dev) && (vlan->flags ^ old_flags) & VLAN_FLAG_MVRP) { + if ((vlan->flags ^ old_flags) & VLAN_FLAG_MVRP) { if (vlan->flags & VLAN_FLAG_MVRP) vlan_mvrp_request_join(dev); else vlan_mvrp_request_leave(dev); } + + if ((vlan->flags ^ old_flags) & VLAN_FLAG_BRIDGE_BINDING && + netif_is_bridge_port(dev)) { + br_dev =3D vlan->real_dev; + if (vlan->flags & VLAN_FLAG_BRIDGE_BINDING) + br_vlan_upper_change(br_dev, dev, true); + else + br_vlan_upper_change(br_dev, dev, false); + } + return 0; } =20 --=20 2.25.1 From nobody Tue Apr 14 12:29:21 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52299C04A68 for ; Sat, 30 Jul 2022 16:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235225AbiG3QEF (ORCPT ); Sat, 30 Jul 2022 12:04:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229742AbiG3QD4 (ORCPT ); Sat, 30 Jul 2022 12:03:56 -0400 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF8D2175A5; Sat, 30 Jul 2022 09:03:54 -0700 (PDT) Received: by mail-qk1-x72d.google.com with SMTP id f14so5727758qkm.0; Sat, 30 Jul 2022 09:03:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qLzw+p0S78/HSEdQ7LBwxStiGJCgHNO2kd5yQe6cZ1o=; b=MKFggB8oiN4zKc2x0wkJ6tyvhwP2F+SpKt/g8ysZkswPoTRLd8TGnHZST9O1QdQUGP 5axm0ZkwMHkbAW94Fg4GCyM+iFetWv+6YNLrMIYiaNjAs2Gy6bRY8Ztot5v193jOn+Mz sufiLomkHEpZM2ejntx+bcY1nTh8exS3sAZaR0hdRiMCfAvt/dyfx+T8x2x24Z1BjuUw OPDbxlwlE7q9p/qVrTQ7s8urQkdTkLNS2LehHSNV9b3EyfBISqESwhEKyd1acvDOEwUd A5EuzFTotFp3hqiFd3vGwYxLdk2Xr6Y/rnD20bgvzumT5ijD2fsyC4uFFfKX7ZagZN4s xEqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qLzw+p0S78/HSEdQ7LBwxStiGJCgHNO2kd5yQe6cZ1o=; b=W/3Gl17pmNU7opDzgEMPpeK9I8rHL+LOOypI3jX3LMqk2y4lNhY6WS6uUGFavXW6Ox YYEDRoU4YOhtPoIYqAr/c4AMOWUWqTvkh1TAN9rUzpT9p7ID7c6jHceAdd7EXFWwFvXt N+PArAmHBan0g50FWLYxi/SmZrWY1NI28COXbSqjYYS+TmYhMUXP90VTr/vVHWTZ7TP/ ndvQt9qBM7SLc2KpWIuGAZfxd7yvhHoZT8fjU+ImAoGK4VyrciROTxya65o3HpU/XRAF C2bDlsgKLSfeMcvSy9TmoZWId6v6GbFazQ72znbgy3AOxDY0biirY0fjl3WkKm3tmc74 lnrQ== X-Gm-Message-State: AJIora84bqy2XUqNKOoV/CqJxRevFNDJCt5FwmF0cV2jpMXcdnyrKl/S eVZ+ETYrdRii0Bo9EWzMXwo= X-Google-Smtp-Source: AGRyM1uDRcFu6F/JhirJPEqanfOY+Kduw/8YivoJYjVgn7Ihv3i41gAhQ7yaXEI2FLc3lzfqKa5pVw== X-Received: by 2002:a05:620a:290d:b0:6b5:cecc:1cab with SMTP id m13-20020a05620a290d00b006b5cecc1cabmr6446562qkp.465.1659197033916; Sat, 30 Jul 2022 09:03:53 -0700 (PDT) Received: from ada ([71.58.109.160]) by smtp.gmail.com with ESMTPSA id c3-20020ac85a83000000b0031ec83851ccsm4449728qtc.38.2022.07.30.09.03.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Jul 2022 09:03:53 -0700 (PDT) From: Sevinj Aghayeva To: aroulin@nvidia.com Cc: sbrivio@redhat.com, roopa@nvidia.com, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Nikolay Aleksandrov , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bridge@lists.linux-foundation.org, Sevinj Aghayeva Subject: [PATCH net-next 3/3] selftests: net: tests for bridge binding behavior Date: Sat, 30 Jul 2022 12:03:32 -0400 Message-Id: <222e04a7b4647a57afbad89447f239564af39d24.1659195179.git.sevinj.aghayeva@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch adds two tests in a single file. The first of these is in function run_test_late_bridge_binding_set, which tests that when a vlan interface is created with bridge binding turned off, and later bridge binding is turned on (using ip link set... command), the vlan interface behaves accordingly, that is, it tracks the status of the ports in its vlan. The second test, which is in function run_test_multiple_vlan, tests that when there are two vlan interfaces with bridge binding turned on, turning off the bridge binding in one of the vlan interfaces does not affect the bridge binding on the other interface. Signed-off-by: Sevinj Aghayeva Reviewed-by: Stefano Brivio Reviewed-by: Andy Roulin Reviewed-by: Roopa Prabhu --- tools/testing/selftests/net/Makefile | 1 + .../selftests/net/bridge_vlan_binding_test.sh | 143 ++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100755 tools/testing/selftests/net/bridge_vlan_binding_test.sh diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests= /net/Makefile index 80628bf8413a..f3ac4cb01695 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -40,6 +40,7 @@ TEST_PROGS +=3D arp_ndisc_evict_nocarrier.sh TEST_PROGS +=3D ndisc_unsolicited_na_test.sh TEST_PROGS +=3D arp_ndisc_untracked_subnets.sh TEST_PROGS +=3D stress_reuseport_listen.sh +TEST_PROGS +=3D bridge_vlan_binding_test.sh TEST_PROGS_EXTENDED :=3D in_netns.sh setup_loopback.sh setup_veth.sh TEST_PROGS_EXTENDED +=3D toeplitz_client.sh toeplitz.sh TEST_GEN_FILES =3D socket nettest diff --git a/tools/testing/selftests/net/bridge_vlan_binding_test.sh b/tool= s/testing/selftests/net/bridge_vlan_binding_test.sh new file mode 100755 index 000000000000..d094d847800c --- /dev/null +++ b/tools/testing/selftests/net/bridge_vlan_binding_test.sh @@ -0,0 +1,143 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later + +cleanup() { + # Remove interfaces created by the previous run + ip link delete veth10 2>/dev/null + ip link delete veth20 2>/dev/null + ip link delete veth30 2>/dev/null + ip link delete br_default 2>/dev/null +} + +trap cleanup EXIT + +setup() { + cleanup + + # Create a bridge and add three ports to it. + ip link add dev br_default type bridge + ip link add dev veth10 type veth peer name veth11 + ip link add dev veth20 type veth peer name veth21 + ip link add dev veth30 type veth peer name veth31 + ip link set dev veth10 master br_default + ip link set dev veth20 master br_default + ip link set dev veth30 master br_default + + # Create VLAN 10 and VLAN 20. + bridge vlan add vid 10 dev br_default self + bridge vlan add vid 20 dev br_default self + + # Add veth10 to VLAN 10 and veth20 to VLAN 20. + bridge vlan add vid 10 dev veth10 + bridge vlan add vid 20 dev veth20 + + # Bring up the ports and the bridge. + ip link set veth10 up + ip link set veth11 up + ip link set veth20 up + ip link set veth21 up + ip link set veth30 up + ip link set veth31 up + ip link set br_default up +} + +# This test checks that when a vlan interface is created with bridge +# binding off, and then bridge binding turned on using "ip link set" +# command, bridge binding is actually turned on -- this hasn't been +# the case in the past. +run_test_late_bridge_binding_set() { + setup + + # Add VLAN interface vlan10 to VLAN 10 with bridge binding off. + ip link add link br_default name vlan10 type vlan id 10 protocol \ + 802.1q bridge_binding off + + # Bring up VLAN interface. + ip link set vlan10 up + + # Turn bridge binding on for vlan10. + ip link set vlan10 type vlan bridge_binding on + + # Bring down the port in vlan 10. + ip link set veth10 down + + # Since bridge binding is turned on for vlan10 interface, it + # should be tracking only the port, veth10 in its vlan. Since + # veth10 is down, vlan10 should be down as well. + if ! ip link show vlan10 | grep -q 'state LOWERLAYERDOWN'; then + echo "FAIL - vlan10 should be LOWERLAYERDOWN but it is not" + exit 1 + fi + + # Bringe the port back up. + ip link set veth10 up + + # The vlan 10 interface should be up now. + if ! ip link show vlan10 | grep -q 'state UP'; then + echo "FAIL - vlan10 should be UP but it is not" + exit 1 + fi + + echo "OK" +} + +# This test checks that when there are multiple vlan interfaces with +# bridge binding on, turning off bride binding in one of the vlan +# interfaces does not affect the bridge binding of the other +# interface. +run_test_multiple_vlan() { + setup + + # Add VLAN interface vlan10 to VLAN 10 with bridge binding on. + ip link add link br_default name vlan10 type vlan id 10 protocol \ + 802.1q bridge_binding on + # Add VLAN interface vlan20 to VLAN 20 with bridge binding on. + ip link add link br_default name vlan20 type vlan id 20 protocol \ + 802.1q bridge_binding on + + # Bring up VLAN interfaces. + ip link set vlan10 up + ip link set vlan20 up + + # Turn bridge binding off for vlan10. + ip link set vlan10 type vlan bridge_binding off + + # Bring down the ports in vlans 10 and 20. + ip link set veth10 down + ip link set veth20 down + + # Since bridge binding is off for vlan10 interface, it should + # be tracking all of the ports in the bridge; since veth30 is + # still up, vlan10 should also be up. + if ! ip link show vlan10 | grep -q 'state UP'; then + echo "FAIL - vlan10 should be UP but it is not" + exit 1 + fi + + # Since bridge binding is on for vlan20 interface, it should + # be tracking only the ports in its vlan. This port is veth20, + # and it is down; therefore, vlan20 should be down as well. + if ! ip link show vlan20 | grep -q 'state LOWERLAYERDOWN'; then + echo "FAIL - vlan20 should be LOWERLAYERDOWN but it is not" + exit 1 + fi + + # Bring the ports back up. + ip link set veth10 up + ip link set veth20 up + + # Both vlan interfaces should be up now. + if ! ip link show vlan10 | grep -q 'state UP'; then + echo "FAIL - vlan10 should be UP but it is not" + exit 1 + fi + if ! ip link show vlan20 | grep -q 'state UP' ; then + echo "FAIL - vlan20 should be UP but it is not" + exit 1 + fi + + echo "OK" +} + +run_test_late_bridge_binding_set +run_test_multiple_vlan --=20 2.25.1