Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2274841rdb; Thu, 21 Sep 2023 13:43:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/t084SIMT0uSsNWyStrAx5WgkVaHCnIFbrt9dD3ZLQK0oU5mMEQpHWYLNO10xqfutaUpx X-Received: by 2002:a05:6a00:4095:b0:691:2d4:23b2 with SMTP id bw21-20020a056a00409500b0069102d423b2mr3205180pfb.15.1695329001646; Thu, 21 Sep 2023 13:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695329001; cv=none; d=google.com; s=arc-20160816; b=p3Z47Hg+wZZ7EPaSnqpISrhJRKrITtbFaqQPR9S34riLGHC/V6IHpA6sWoug94yYnU 9VOIdeXyw+yAf4GBdY81Zut+m7Ta7U8k5BetmaTmwiM8QV5lqsDcwABQ/gSYFym/D3tP LBGJGBUVFpE149/6udHQRDToZNsjKiD/yJqD44Jg0fJ3yJ1z0yEkyVgHoVw17c8HVJ6R tYkpwB2Kg9Pf3bvHNnPK1rStuqRxwCxwIZWBmsXLoqY8lto7I7yUvH4eK10hakcUSusf OYDH7UKRiGMRBZODkKewCwjhAtFMS+/izZPjUdYmylc76dLNWp0XGL3QQW4ZurpD2OVO zYEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=Fv18euYIHxUyDyU2umf2N7sAa5N8tvwc+B+kdZWr598=; fh=r8zpVSSoSO6PfqQy7ooLS7GpPkua5AzwTepuYCrhBPo=; b=HPUP6DQ/Eo+WbC4owbvzio2xQX2eZQhiAImy7ud2I3Nt2F6R62XSKo3NxT8rrvPPwy /sWwSt6jis72ByStqMeevlEvMktzyYJGPaIiiok16e9K2fmSz76q3+XzYc6JfzB11JOk psIYIGrqftgdFsO7cr+HyOiYu8Tk5RjWnhX+zkgWJ/KN01wwoYsIPFamUo1zJ5D+SQfE o2S8jkLrUTg0ErkQPzMp8EZtFPz64o+tA4eSfNFRZ8xo9gpN0qwXbZzu01pW0HSiQmf6 rAQpbL4ChxuTUwWY8o6eLneMzI9pGsRrzwjCofax/BxC+9vBgJndPthCIcyS9hPINsHV 1S5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@blackwall-org.20230601.gappssmtp.com header.s=20230601 header.b=QTWwg4uG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id t22-20020a056a0021d600b0068c0323c2b7si2280059pfj.172.2023.09.21.13.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 13:43:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@blackwall-org.20230601.gappssmtp.com header.s=20230601 header.b=QTWwg4uG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 18A888047DAD; Thu, 21 Sep 2023 13:28:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232080AbjIUU14 (ORCPT + 99 others); Thu, 21 Sep 2023 16:27:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231609AbjIUU13 (ORCPT ); Thu, 21 Sep 2023 16:27:29 -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 A931F81FD8 for ; Thu, 21 Sep 2023 10:53:52 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3214d4ecd39so1205078f8f.1 for ; Thu, 21 Sep 2023 10:53:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20230601.gappssmtp.com; s=20230601; t=1695318812; x=1695923612; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Fv18euYIHxUyDyU2umf2N7sAa5N8tvwc+B+kdZWr598=; b=QTWwg4uGH9PdWoLNa+ZhKm4sY5RrDVCDntKuODCQyx8jogdwFuDbNqxo2MdlS+6KuM 56C0JqKPaKzynsLd9MuG1b8C98fYuQ6CA8VGs6f43CH/diSX3nDehs9b1yRjI/AXruMg shx1aaUQd0jWaiWhd4vjfk//Z69jJlpSdjGwgf7bkqWDilCRj8xl5EktHRZ6ApyvJej0 kyhr7LyRZeWNV1jpIPr+LEH67dG8mOQb1GY8RePOuhxvsWYUWED0iMowHO5G5WMJkY7j IlAqXyZ3E4+wKF8D+/v1tPaEINl7TqFOZg8/sezKXj9fXlts6UPAt7zdKVsyfQrasNA5 75gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318812; x=1695923612; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Fv18euYIHxUyDyU2umf2N7sAa5N8tvwc+B+kdZWr598=; b=KWl994TFHELLk8X3m8Flxf5Rm3ONLrr6LT1iCUvewLv0I1rJxlpBUGM3hWjCjE4DFs HOVK14+PUMZhdSFiciyl5iZ9L3vfidWk+wAr1PLfp15433++LWKIfihrw75tkT9hbdRm D/dCyC0vVMPoi5XZBSZ36X7I9nyewon7cUpdKDTx8NAtgodBPzCFUAddURQYGM7nMQmv 4PgX6Klk18A0MZNI+FWFiWgRSxxGOcx4a3uOTu2GsBIuUTN+/luhxDn+S+T7U+D4/JgV qIIbVdtRDKkzYCF9PKKlSDE4+PfWDVOJIdtrAx6HdBqwIcinf6URWhcg4B5/zFQICJKc gQEw== X-Gm-Message-State: AOJu0YyoiqN9dMu8Gh5Y3MMLhN9CDVaEVUKm539J0CmETwYZ8BimVXaK GRVPTdNrCD1jsgXdgkDtT8Fua29gVdL1z/NW8iYKxoMt X-Received: by 2002:a17:906:9b94:b0:9a1:debe:6b9b with SMTP id dd20-20020a1709069b9400b009a1debe6b9bmr6177440ejc.35.1695300113099; Thu, 21 Sep 2023 05:41:53 -0700 (PDT) Received: from [192.168.0.105] (haunt.prize.volia.net. [93.72.109.136]) by smtp.gmail.com with ESMTPSA id i22-20020a17090671d600b0099bcdfff7cbsm991440ejk.160.2023.09.21.05.41.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Sep 2023 05:41:52 -0700 (PDT) Message-ID: <0ae67e4d-0d51-5290-1255-1fe1b699ca14@blackwall.org> Date: Thu, 21 Sep 2023 15:41:50 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH net-next v4 4/6] net: bridge: Add netlink knobs for number / max learned FDB entries Content-Language: en-US To: Johannes Nixdorf , "David S. Miller" , Andrew Lunn , David Ahern , Eric Dumazet , Florian Fainelli , Ido Schimmel , Jakub Kicinski , Oleksij Rempel , Paolo Abeni , Roopa Prabhu , Shuah Khan , Vladimir Oltean Cc: bridge@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org References: <20230919-fdb_limit-v4-0-39f0293807b8@avm.de> <20230919-fdb_limit-v4-4-39f0293807b8@avm.de> From: Nikolay Aleksandrov In-Reply-To: <20230919-fdb_limit-v4-4-39f0293807b8@avm.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:28:03 -0700 (PDT) On 9/19/23 11:12, Johannes Nixdorf wrote: > The previous patch added accounting and a limit for the number of > dynamically learned FDB entries per bridge. However it did not provide > means to actually configure those bounds or read back the count. This > patch does that. > > Two new netlink attributes are added for the accounting and limit of > dynamically learned FDB entries: > - IFLA_BR_FDB_N_LEARNED (RO) for the number of entries accounted for > a single bridge. > - IFLA_BR_FDB_MAX_LEARNED (RW) for the configured limit of entries for > the bridge. > > The new attributes are used like this: > > # ip link add name br up type bridge fdb_max_learned 256 > # ip link add name v1 up master br type veth peer v2 > # ip link set up dev v2 > # mausezahn -a rand -c 1024 v2 > 0.01 seconds (90877 packets per second > # bridge fdb | grep -v permanent | wc -l > 256 > # ip -d link show dev br > 13: br: mtu 1500 [...] > [...] fdb_n_learned 256 fdb_max_learned 256 > > Signed-off-by: Johannes Nixdorf > --- > include/uapi/linux/if_link.h | 2 ++ > net/bridge/br_netlink.c | 15 ++++++++++++++- > 2 files changed, 16 insertions(+), 1 deletion(-) > > diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h > index ce3117df9cec..0486f314c176 100644 > --- a/include/uapi/linux/if_link.h > +++ b/include/uapi/linux/if_link.h > @@ -510,6 +510,8 @@ enum { > IFLA_BR_VLAN_STATS_PER_PORT, > IFLA_BR_MULTI_BOOLOPT, > IFLA_BR_MCAST_QUERIER_STATE, > + IFLA_BR_FDB_N_LEARNED, > + IFLA_BR_FDB_MAX_LEARNED, > __IFLA_BR_MAX, > }; > > diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c > index 505683ef9a26..f5d49a05e61b 100644 > --- a/net/bridge/br_netlink.c > +++ b/net/bridge/br_netlink.c > @@ -1267,6 +1267,8 @@ static const struct nla_policy br_policy[IFLA_BR_MAX + 1] = { > [IFLA_BR_VLAN_STATS_PER_PORT] = { .type = NLA_U8 }, > [IFLA_BR_MULTI_BOOLOPT] = > NLA_POLICY_EXACT_LEN(sizeof(struct br_boolopt_multi)), > + [IFLA_BR_FDB_N_LEARNED] = { .type = NLA_U32 }, > + [IFLA_BR_FDB_MAX_LEARNED] = { .type = NLA_U32 }, > }; > > static int br_changelink(struct net_device *brdev, struct nlattr *tb[], > @@ -1541,6 +1543,12 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[], > return err; > } > > + if (data[IFLA_BR_FDB_MAX_LEARNED]) { > + u32 val = nla_get_u32(data[IFLA_BR_FDB_MAX_LEARNED]); > + > + WRITE_ONCE(br->fdb_max_learned, val); > + } > + > return 0; > } > > @@ -1595,6 +1603,8 @@ static size_t br_get_size(const struct net_device *brdev) > nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_TOPOLOGY_CHANGE_TIMER */ > nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_GC_TIMER */ > nla_total_size(ETH_ALEN) + /* IFLA_BR_GROUP_ADDR */ > + nla_total_size(sizeof(u32)) + /* IFLA_BR_FDB_N_LEARNED */ > + nla_total_size(sizeof(u32)) + /* IFLA_BR_FDB_MAX_LEARNED */ > #ifdef CONFIG_BRIDGE_IGMP_SNOOPING > nla_total_size(sizeof(u8)) + /* IFLA_BR_MCAST_ROUTER */ > nla_total_size(sizeof(u8)) + /* IFLA_BR_MCAST_SNOOPING */ > @@ -1670,7 +1680,10 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev) > nla_put_u8(skb, IFLA_BR_TOPOLOGY_CHANGE_DETECTED, > br->topology_change_detected) || > nla_put(skb, IFLA_BR_GROUP_ADDR, ETH_ALEN, br->group_addr) || > - nla_put(skb, IFLA_BR_MULTI_BOOLOPT, sizeof(bm), &bm)) > + nla_put(skb, IFLA_BR_MULTI_BOOLOPT, sizeof(bm), &bm) || > + nla_put_u32(skb, IFLA_BR_FDB_N_LEARNED, > + atomic_read(&br->fdb_n_learned)) || > + nla_put_u32(skb, IFLA_BR_FDB_MAX_LEARNED, br->fdb_max_learned)) > return -EMSGSIZE; > > #ifdef CONFIG_BRIDGE_VLAN_FILTERING > Actually you're using atomic for counting, but using a u32 for the limit, you should cap it because the count can overflow. Or you should use atomic64 for the counting.