From patchwork Wed Apr 13 10:51:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12811898 X-Patchwork-Delegate: kuba@kernel.org 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 3A0AAC433EF for ; Wed, 13 Apr 2022 10:52:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234857AbiDMKyq (ORCPT ); Wed, 13 Apr 2022 06:54:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232012AbiDMKyo (ORCPT ); Wed, 13 Apr 2022 06:54:44 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7D6759A4E for ; Wed, 13 Apr 2022 03:52:23 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id t11so3049958eju.13 for ; Wed, 13 Apr 2022 03:52:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=punCyQ5OlXSnY/goe5W8EQLjKTFZYGXPlnRQPpJuU2Q=; b=rU+fyBOGNDPr41fXvuDQ0DkGPCf1V24jkzQmDG4PWUkq88+kD3HhGIYVegC/JyoPqU XEa1rdx32WiRjGTEixr8QcvgVUojKKc4Wu/e5Kr4KvGoG+ryx12eTlBFSLL58BpcBli0 bUontmhkN/fG+g5hWkUlF8BZG1rD+vMA26GZF3r2luCDetHYxAwgA/5VY7IFiJZGrbQA jyMMz1pSAKz2Im0DEqtUZvCh+C8QATupt8gsqfJVWx62ebvLDxo+zxQ4niXNuGUQrw7B yawFY7R9Xs3rB0jEXSX7pbbASlGW30LrJDMxT784poSUYHtJHU9pK3Y76RnG1AKuRKiZ xyLg== 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=punCyQ5OlXSnY/goe5W8EQLjKTFZYGXPlnRQPpJuU2Q=; b=hYaMiwNZ8jhtR+sOZYLt5W11vn7gFWpqbroBJE14R0y/hb2CCVJWg4u2VMoGpjmT7g LHelcaAawXkTTX093XgJ3rEIh3cg/BrcnTm4i717wZKJaDIZMMWhKKbHQsUw3nvk83hC 4LwKLx93bSEpvL58oD6v1r0oBOz2PGzRBDDna0Z31joGsEiXiY1C4+QAo2/ztG88ZrXH 9xRVYVjQV4cO6vCeCOoi0wIYeBoYymcfAnrKQJzr9U96U9oXnZCT8SFhM/z4Q7OvTTpZ uNClSb7JZSp2Ii9Gg42nVYpVyo1Zgn0KFUh7VolCCcinbBAJZT5Bz1oTHTFXXHvq/AzD jo2Q== X-Gm-Message-State: AOAM5330okoYnbeqyozZRtQETCXsfq+RCBF4xGWQJ8C8a3WdZLU0aKuC Yzmeiv5N7L8baY9s3uJZgCMR883lwjHR7yvq X-Google-Smtp-Source: ABdhPJzJtPZE++TuJtHZ/Yg/lYt4Qo1/ToVPqrbAAkZVzw8xogV7ahAeZiktfTk3WFIRP8JnzVVurg== X-Received: by 2002:a17:906:ae85:b0:6e8:76c2:1f1f with SMTP id md5-20020a170906ae8500b006e876c21f1fmr17664530ejb.333.1649847142018; Wed, 13 Apr 2022 03:52:22 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id v8-20020a1709063bc800b006e898cfd926sm2960952ejf.134.2022.04.13.03.52.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 03:52:21 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: dsahern@kernel.org, roopa@nvidia.com, idosch@idosch.org, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next v4 01/12] net: rtnetlink: add msg kind names Date: Wed, 13 Apr 2022 13:51:51 +0300 Message-Id: <20220413105202.2616106-2-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413105202.2616106-1-razor@blackwall.org> References: <20220413105202.2616106-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add rtnl kind names instead of using raw values. We'll need to check for DEL kind later to validate bulk flag support. Signed-off-by: Nikolay Aleksandrov --- v4: new patch include/net/rtnetlink.h | 7 +++++++ net/core/rtnetlink.c | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h index 9f48733bfd21..78712b51f3da 100644 --- a/include/net/rtnetlink.h +++ b/include/net/rtnetlink.h @@ -13,6 +13,13 @@ enum rtnl_link_flags { RTNL_FLAG_DOIT_UNLOCKED = 1, }; +enum rtnl_kinds { + RTNL_KIND_NEW, + RTNL_KIND_DEL, + RTNL_KIND_GET, + RTNL_KIND_SET +}; + void rtnl_register(int protocol, int msgtype, rtnl_doit_func, rtnl_dumpit_func, unsigned int flags); int rtnl_register_module(struct module *owner, int protocol, int msgtype, diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 4041b3e2e8ec..2c36c9dc9b62 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -5928,11 +5928,11 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, { struct net *net = sock_net(skb->sk); struct rtnl_link *link; + enum rtnl_kinds kind; struct module *owner; int err = -EOPNOTSUPP; rtnl_doit_func doit; unsigned int flags; - int kind; int family; int type; @@ -5949,11 +5949,11 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, family = ((struct rtgenmsg *)nlmsg_data(nlh))->rtgen_family; kind = type&3; - if (kind != 2 && !netlink_net_capable(skb, CAP_NET_ADMIN)) + if (kind != RTNL_KIND_GET && !netlink_net_capable(skb, CAP_NET_ADMIN)) return -EPERM; rcu_read_lock(); - if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) { + if (kind == RTNL_KIND_GET && (nlh->nlmsg_flags & NLM_F_DUMP)) { struct sock *rtnl; rtnl_dumpit_func dumpit; u32 min_dump_alloc = 0; From patchwork Wed Apr 13 10:51:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12811899 X-Patchwork-Delegate: kuba@kernel.org 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 38DB1C433FE for ; Wed, 13 Apr 2022 10:52:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235021AbiDMKys (ORCPT ); Wed, 13 Apr 2022 06:54:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234173AbiDMKyp (ORCPT ); Wed, 13 Apr 2022 06:54:45 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9452593AA for ; Wed, 13 Apr 2022 03:52:24 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id u15so3061850ejf.11 for ; Wed, 13 Apr 2022 03:52:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BbnHd4o5vqqdVnPqrILq5Jq5sTNcgygmX2gIAOpm4mw=; b=q3Rk/2KB7HFk7J7NZDNTLPkXze8TdzSBWoDcZfcs8MVwnGlLHHKepzt+ioTyPh9U5K e6UiYrM/hkvDQyjqwUoqegngxb7Sp1GMfJ9L6kNFzRamoetEIZ57i41+2CWhdx/omzrr 5JoZzAzynleDl1MKk9KGO/pFfGIExlENek3seJD6BwB35giZPiEfvRkQcfkPKm/4SKfC c8Fb4fah5m4Y1idIi7UShlRDBgRCH89U6XkycmNr9cPt1RbiMJlW1QU3a57+IjoZn+pf +9ibxwmRLBKEMd8N94SyTsia7FOX5Cel1IiDLhw0fq6ks3pq7n1aeyPSh5Xa10rPchk0 OrxA== 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=BbnHd4o5vqqdVnPqrILq5Jq5sTNcgygmX2gIAOpm4mw=; b=NZn9Cvm4ViRVf8AoCyMITepjbsColn+TwBtMtWw2I0P7CEaiERZLU4Szq/f9yAMkgk I+jeSiBy47tdvJWkTltklJsKpeuisxaitHkw8hARofjb1TTfFtHvV5mTLGozBnaeZKwz AesVpPADduOvesvuUjoXAHAT3tbL9FQTqsGGnDEPQ6wRyVCpM8lESsY8tK0ny9dYT0Im ljnx4VYSZFVIH4lLWBIcFhB8Ei9YH0vf5PLqj1irzJsJWTVsbL5u447dkmF1ThBVtKmz XOkkfyziOIx+Xfp2Nh1ApynXKkOv3vOvcKMFAENEfWXiGxUwEbIDOC+8UF9WsCg4Zosk ab4w== X-Gm-Message-State: AOAM531lLEciat4ZxLJpO9jTKfojaw9ED7phkX6ryFq77NcNP5pGPKL4 0WS8F+aWo6dZwsUPt2CY+ryV7sSzdJQJ8smM X-Google-Smtp-Source: ABdhPJxAvtCcmeSBhisp1pbrVEqL//uk/agEXWAWo/IQOQjQ1T+jZW3uMWT3L9D0+ZjwXmfhmZ152A== X-Received: by 2002:a17:907:7b92:b0:6db:71f1:fc20 with SMTP id ne18-20020a1709077b9200b006db71f1fc20mr37128934ejc.343.1649847143262; Wed, 13 Apr 2022 03:52:23 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id v8-20020a1709063bc800b006e898cfd926sm2960952ejf.134.2022.04.13.03.52.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 03:52:22 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: dsahern@kernel.org, roopa@nvidia.com, idosch@idosch.org, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next v4 02/12] net: rtnetlink: add helper to extract msg type's kind Date: Wed, 13 Apr 2022 13:51:52 +0300 Message-Id: <20220413105202.2616106-3-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413105202.2616106-1-razor@blackwall.org> References: <20220413105202.2616106-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add a helper which extracts the msg type's kind using the kind mask (0x3). Signed-off-by: Nikolay Aleksandrov --- v4: new patch include/net/rtnetlink.h | 6 ++++++ net/core/rtnetlink.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h index 78712b51f3da..c51c5ff7f7e2 100644 --- a/include/net/rtnetlink.h +++ b/include/net/rtnetlink.h @@ -19,6 +19,12 @@ enum rtnl_kinds { RTNL_KIND_GET, RTNL_KIND_SET }; +#define RTNL_KIND_MASK 0x3 + +static inline enum rtnl_kinds rtnl_msgtype_kind(int msgtype) +{ + return msgtype & RTNL_KIND_MASK; +} void rtnl_register(int protocol, int msgtype, rtnl_doit_func, rtnl_dumpit_func, unsigned int flags); diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 2c36c9dc9b62..beda4a7da062 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -5947,7 +5947,7 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, return 0; family = ((struct rtgenmsg *)nlmsg_data(nlh))->rtgen_family; - kind = type&3; + kind = rtnl_msgtype_kind(type); if (kind != RTNL_KIND_GET && !netlink_net_capable(skb, CAP_NET_ADMIN)) return -EPERM; From patchwork Wed Apr 13 10:51:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12811900 X-Patchwork-Delegate: kuba@kernel.org 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 C1567C433F5 for ; Wed, 13 Apr 2022 10:52:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235044AbiDMKyx (ORCPT ); Wed, 13 Apr 2022 06:54:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235015AbiDMKyq (ORCPT ); Wed, 13 Apr 2022 06:54:46 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1FD6593B7 for ; Wed, 13 Apr 2022 03:52:25 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id lc2so3060842ejb.12 for ; Wed, 13 Apr 2022 03:52:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bxnUQR9V57rGqYOjdVUj6Nc/+H1dclO6Pe3lE8dzyks=; b=v0xXGtzEyPwMy5K5G8fUCwmcOyh3wq4YsIIBIWH6HBnko3nwWalZWY4oFTHxmdk4pi M92GRFrT5Bsy3V/YNM/ezVhobRWp1KXQfxbqubgOItaCQ0t0e6NXoj9+3KiLBCi3DPV0 Z87K75gLIM0v1GHRrLD95VMaKoXTjIKQcW12HfCn1Ogn3dYbQCuAHhJnKwlDCPhIaHjb s6UtWIMHBwYe5NubtFzkWx5+HX8dYwPpgO04JtZD3s0gTHQ+BgmQK46asyGkoZXNwD2I T26Wnsou5l8DcA/UuvQY66AeHoxKysm5vtQJ3e42nNV9kQhcJ2LV8gs7pA2b/uU7Slbb iRyw== 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=bxnUQR9V57rGqYOjdVUj6Nc/+H1dclO6Pe3lE8dzyks=; b=6otYZh8ZTNz2Hd8HEQa4G0uFL2jOQC2+xwbdXPmzaBhy2tUFZOAJYU5LYBq5oq9mdY Iy1qbnq8zxoHGhvu49UrFsLuAxdvkZYX+nv+7ySDPp6sVnbZuSexExyOMQaDreLdLkjx 6n/bJUN1RPuekYkM+5k7MasEpwrdXW1QukHcAvc8Vv8Qh0bp0D0JTQTcTBE4zMO/T/rS 8Wpdi0CJpfe9XtrLAgTST9YdFXsTC0T76JJyqayZ6T9tiHAfgMrdGz074mT6VZm7Ez0t nuJHOcgFMU+aSCPmmuwGYHn93wkfCJqoo/jYnlDDFJaM1R+mYtv6kQbIyY7epvUm6JFZ 3BYw== X-Gm-Message-State: AOAM530XEp82xaaZubLZJF2EvTplxhmeLiIs0qGIe3KBxNxg3D2xVz1s huoTQ666oZK2iSG1NpMYlLwBCpuveAJdR4hi X-Google-Smtp-Source: ABdhPJw+bDiRfssoWh5TNImSH9UMauJVpqt3IO01+EY9TCO0zL5F0os3pE9VyJs8NDDQq9WrPvi5Mw== X-Received: by 2002:a17:907:3e0b:b0:6e8:696c:d927 with SMTP id hp11-20020a1709073e0b00b006e8696cd927mr19139290ejc.747.1649847144149; Wed, 13 Apr 2022 03:52:24 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id v8-20020a1709063bc800b006e898cfd926sm2960952ejf.134.2022.04.13.03.52.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 03:52:23 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: dsahern@kernel.org, roopa@nvidia.com, idosch@idosch.org, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next v4 03/12] net: rtnetlink: use BIT for flag values Date: Wed, 13 Apr 2022 13:51:53 +0300 Message-Id: <20220413105202.2616106-4-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413105202.2616106-1-razor@blackwall.org> References: <20220413105202.2616106-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Use BIT to define flag values. Signed-off-by: Nikolay Aleksandrov --- v4: new patch include/net/rtnetlink.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h index c51c5ff7f7e2..0bf622409aaa 100644 --- a/include/net/rtnetlink.h +++ b/include/net/rtnetlink.h @@ -10,7 +10,7 @@ typedef int (*rtnl_doit_func)(struct sk_buff *, struct nlmsghdr *, typedef int (*rtnl_dumpit_func)(struct sk_buff *, struct netlink_callback *); enum rtnl_link_flags { - RTNL_FLAG_DOIT_UNLOCKED = 1, + RTNL_FLAG_DOIT_UNLOCKED = BIT(0), }; enum rtnl_kinds { From patchwork Wed Apr 13 10:51:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12811902 X-Patchwork-Delegate: kuba@kernel.org 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 B492AC433EF for ; Wed, 13 Apr 2022 10:52:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235058AbiDMKy4 (ORCPT ); Wed, 13 Apr 2022 06:54:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235019AbiDMKyr (ORCPT ); Wed, 13 Apr 2022 06:54:47 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF5E4593B8 for ; Wed, 13 Apr 2022 03:52:26 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id s18so3204369ejr.0 for ; Wed, 13 Apr 2022 03:52:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uUhhwavoelOAutf6ZINYv5+4TG3VETWVUGFixQHcuak=; b=rLSJSouYiv7OkG/FyDtfvfS0x+gh2sGEdXXD3TxkUkcmfLkc4s3DwFs9WTIygFn5Fj 9dSFB3Q1LOeTUmj52Pu5jrZS6Lqgao9V4kPo8O8KEc2Q/Kez1XjZZY4DPSluEyfFd4Ww EydDZh+HT81QxaYKcL6dvGh6SYfTkUwGZ+P7sw8+uGAjks7+/cXXSX2OzW4UjCXD4jly fx8cx49P+Jph5i4PQluNOpPv8OtonmhYKrDY9BeqB4i4IEa6rZhhDcdKDVufnhylZZ9E aPGeIj0Il1AgFqn+S7NrqP+SoGJSPoPoJSTOaVbWq47E7ub44xVG+fFXXW8ChJPQthi6 CPQw== 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=uUhhwavoelOAutf6ZINYv5+4TG3VETWVUGFixQHcuak=; b=t1mVYYCz+9kcXmTzhOFeIAdrUm46aWlyshqER2/0TxWxiiDedl9+yilesJY3S7lPP8 /4hMlSfgBWFEjFACFz0ZwuBPfqkfH4Mr7WmIMnv3/+vhL7WP8tDEaetdLSlereB+7Ab3 84SpTTUTOiSkf+myXZ/f3ZEOGaD7KCQglBcjrJdV/fzWCwOzkby0wE6H95Vdq7sd6B0W 7srUgrQgAHQ7TOprTbrl4u3OHf+xxU19k32yelpEYtgMZTpB/5yVZ68oQ8nVAwBjOWro w2O6QecSi7bgSeSeVuBofTfpS+ovIujKRFc7nPVP4u8tTN5u/ZXdii5OQ1MO70vHYadS gx3w== X-Gm-Message-State: AOAM533WxqQsTCmMGmxxrUowSci/I9OxF6rVRqDf1SjsTVFEr+0ZQtgv 8hj5Xly7NCsrS6qAFSwAHV0E8i9ky8PGn6O9 X-Google-Smtp-Source: ABdhPJwRtQi8x5hLJqvnOxjlqt8uUG4sb0nQ06Dq5kORtMji7kyjiZDwAaGxEDr/C2WKg/zOzLnO8A== X-Received: by 2002:a17:907:1690:b0:6db:325:3088 with SMTP id hc16-20020a170907169000b006db03253088mr39050134ejc.718.1649847145173; Wed, 13 Apr 2022 03:52:25 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id v8-20020a1709063bc800b006e898cfd926sm2960952ejf.134.2022.04.13.03.52.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 03:52:24 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: dsahern@kernel.org, roopa@nvidia.com, idosch@idosch.org, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next v4 04/12] net: netlink: add NLM_F_BULK delete request modifier Date: Wed, 13 Apr 2022 13:51:54 +0300 Message-Id: <20220413105202.2616106-5-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413105202.2616106-1-razor@blackwall.org> References: <20220413105202.2616106-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add a new delete request modifier called NLM_F_BULK which, when supported, would cause the request to delete multiple objects. The flag is a convenient way to signal that a multiple delete operation is requested which can be gradually added to different delete requests. In order to make sure older kernels will error out if the operation is not supported instead of doing something unintended we have to break a required condition when implementing support for this flag, f.e. for neighbors we will omit the mandatory mac address attribute. Initially it will be used to add flush with filtering support for bridge fdbs, but it also opens the door to add similar support to others. Signed-off-by: Nikolay Aleksandrov --- include/uapi/linux/netlink.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/uapi/linux/netlink.h b/include/uapi/linux/netlink.h index 4c0cde075c27..855dffb4c1c3 100644 --- a/include/uapi/linux/netlink.h +++ b/include/uapi/linux/netlink.h @@ -72,6 +72,7 @@ struct nlmsghdr { /* Modifiers to DELETE request */ #define NLM_F_NONREC 0x100 /* Do not delete recursively */ +#define NLM_F_BULK 0x200 /* Delete multiple objects */ /* Flags for ACK message */ #define NLM_F_CAPPED 0x100 /* request was capped */ From patchwork Wed Apr 13 10:51:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12811901 X-Patchwork-Delegate: kuba@kernel.org 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 8D7EBC433EF for ; Wed, 13 Apr 2022 10:52:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235054AbiDMKyy (ORCPT ); Wed, 13 Apr 2022 06:54:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235023AbiDMKys (ORCPT ); Wed, 13 Apr 2022 06:54:48 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB46B59A4A for ; Wed, 13 Apr 2022 03:52:27 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id bg10so3125944ejb.4 for ; Wed, 13 Apr 2022 03:52:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0+d6Rov8cjDp4XASxWMxnkxwuD5Gq2aFtJ+v6sDjNGk=; b=E2vRYdVkMpOuOmuBfP6Oq6xxQ8AygCk0IigcDxqCSJmZqps/Xbyf6XW0O12cT1Oax4 FiCB528iHFY03d7tXKx1d7N2lWiDg084eNkY9gq7shM2MIKG9UF5/64tnrZ3mpv2OI6e mV12s6jeyA6T8qTdawpgBxEpaf9xzc4JN48EHsKpzIF3Puf1xfFHkxbwqDOBfCUKcufz 72d5o/qUEMspTt1BacW//JMc0IKjZixQER9i2DrxZEZHW1da2hBX9DWVs/SXN4DCMKMj t4gR2S79+YxQGdmMRFJdJ5nY175E47oT+YLWlr/jgqTtIN17mxndg0U/ui3nDbEhX3z9 Zgrg== 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=0+d6Rov8cjDp4XASxWMxnkxwuD5Gq2aFtJ+v6sDjNGk=; b=aNFhOVagYQgerGw+XFxwVvGcmit3j84d5pDDyw8JRZdOR0xj9NGA1NKDY8iUTK0rEN osS6WRey9mPwy2k8q3iaUNv+Y7BT3SFdu4IaIeIfIjVwCBJwJBxGoMoJxc2jpOP06yCe rFVJbM0OXjiOSq5ruV+ZfGHFndb9d8ZUK86aHcVceCwmRXAH9rNAHEN4V0d1+gckYDJV efshKbfmKSoAo7emDotYxl8BVezW0ePXPtDrYpnwv6QxgIuMW1aDE/A5wutWZgkXDrm2 qx9Rhg/3qQoR86DT5iVXYVLT+qAb3h/BVKVxzlYWruX58kNXSzSG07yuT3eUqL/qkzXG 5ayQ== X-Gm-Message-State: AOAM533PlgTknxBMTGHLuj0Oi17UB6wqVsMchfL1bAS2Hri5SrTLKdPB ZRAp/wAEiisYe6oX0cSAyiA4VL0bp6BtPv1L X-Google-Smtp-Source: ABdhPJzHstTpmBQgNCZQOeZWES1aAH90boWyFAjDx2nJhi9OSbcCrVvB3z3PKcnCHhXapqWq8d+UHw== X-Received: by 2002:a17:906:3ad3:b0:6cd:382b:86e5 with SMTP id z19-20020a1709063ad300b006cd382b86e5mr36598097ejd.145.1649847146154; Wed, 13 Apr 2022 03:52:26 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id v8-20020a1709063bc800b006e898cfd926sm2960952ejf.134.2022.04.13.03.52.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 03:52:25 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: dsahern@kernel.org, roopa@nvidia.com, idosch@idosch.org, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next v4 05/12] net: rtnetlink: add bulk delete support flag Date: Wed, 13 Apr 2022 13:51:55 +0300 Message-Id: <20220413105202.2616106-6-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413105202.2616106-1-razor@blackwall.org> References: <20220413105202.2616106-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add a new rtnl flag (RTNL_FLAG_BULK_DEL_SUPPORTED) which is used to verify that the delete operation allows bulk object deletion. Also emit a warning if anyone tries to set it for non-delete kind. Suggested-by: David Ahern Signed-off-by: Nikolay Aleksandrov --- v4: new patch include/net/rtnetlink.h | 3 ++- net/core/rtnetlink.c | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h index 0bf622409aaa..bf8bb3357825 100644 --- a/include/net/rtnetlink.h +++ b/include/net/rtnetlink.h @@ -10,7 +10,8 @@ typedef int (*rtnl_doit_func)(struct sk_buff *, struct nlmsghdr *, typedef int (*rtnl_dumpit_func)(struct sk_buff *, struct netlink_callback *); enum rtnl_link_flags { - RTNL_FLAG_DOIT_UNLOCKED = BIT(0), + RTNL_FLAG_DOIT_UNLOCKED = BIT(0), + RTNL_FLAG_BULK_DEL_SUPPORTED = BIT(1), }; enum rtnl_kinds { diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index beda4a7da062..63c7df52a667 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -249,6 +249,8 @@ static int rtnl_register_internal(struct module *owner, if (dumpit) link->dumpit = dumpit; + WARN_ON(rtnl_msgtype_kind(msgtype) != RTNL_KIND_DEL && + (flags & RTNL_FLAG_BULK_DEL_SUPPORTED)); link->flags |= flags; /* publish protocol:msgtype */ @@ -6009,6 +6011,12 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, } flags = link->flags; + if (kind == RTNL_KIND_DEL && (nlh->nlmsg_flags & NLM_F_BULK) && + !(flags & RTNL_FLAG_BULK_DEL_SUPPORTED)) { + NL_SET_ERR_MSG(extack, "Bulk delete is not supported"); + goto err_unlock; + } + if (flags & RTNL_FLAG_DOIT_UNLOCKED) { doit = link->doit; rcu_read_unlock(); From patchwork Wed Apr 13 10:51:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12811903 X-Patchwork-Delegate: kuba@kernel.org 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 7EFF4C433EF for ; Wed, 13 Apr 2022 10:52:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235060AbiDMKy6 (ORCPT ); Wed, 13 Apr 2022 06:54:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235025AbiDMKyt (ORCPT ); Wed, 13 Apr 2022 06:54:49 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BD7C59A75 for ; Wed, 13 Apr 2022 03:52:28 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id lc2so3061091ejb.12 for ; Wed, 13 Apr 2022 03:52:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TL0c+Hs+0lBMqasciNPJrqUQXbgHwj7xsTQadVbU8KQ=; b=nOemDcgk5r0VlAKSVFNceh7dNh1uBqsIVQwLdnbY5q/cBVo39X4dUlRJlTF5Qurn5q beCBvCeRL3+X8pe82zI1Al4cih9Y1uHj/sGrCfUAsXLdvUCv/TtxUSowA6gLXCdpNxuu NCKs7HvTtrIGNAUO8Py93bu1fRsJudXEOetSGPOYkX5+1F+4PBVHk6rFkI8VXVX/FI77 zwCvbLKIIUZ3P/O20X26/vZCjzvBNpcsvBzyoGvEFubC28twGcjOYklmqbo1c3nWNnWn DL8JBQfxeYKIv2kt/VoYHSLG9fyTrDdvcVo5/S7G/HkLGw7lii/TzM9CvGmZik9mWU4E 7I2A== 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=TL0c+Hs+0lBMqasciNPJrqUQXbgHwj7xsTQadVbU8KQ=; b=Ytar79tnzBaKcG1fkQDhva7un1ClKeGu/Mrxmjh9ZIIYpxsEtGzBMySjTOmvPr70SM Mmlkqh4nBCfeO7Q7SxP03G41XdZMFjZvHsxP9v6JxOkedfJeUOdurHm9GsYzu2iSuBiA c1ZREBb2b72auVO2thIl83KKCHTA9DW323ZojfvWDzxxKE8/NXZ0kbSl9g0yc7hpuTdm 3+HtY/qmS8Nm+qnSIzuadOFbrry4UCJGeHhxYipZBTO5D0U1UV6c9aEPNQzBcvnkrksY 9o4Nema+Ptgw7qjzDVem8qsU7jyRYEljFroCdy6EevdFkBxHDlbQhzQufDL0w6NcHjgT H2JQ== X-Gm-Message-State: AOAM5330WgXxk0evLOZDNAw/OlElGBjdyjI113dhW5UJo1fWZKK5TVRQ 3kiG6kYe7slx7z+PKcENGi9umfpWSo6zx1ht X-Google-Smtp-Source: ABdhPJy6jvymQpMk1zpC1tA/B0YcrpU0Rqtjf4DLdZuYidwvgZC+l358W5S3hhilB/yQeW4IN50uGA== X-Received: by 2002:a17:907:2d20:b0:6e8:a4d3:3e91 with SMTP id gs32-20020a1709072d2000b006e8a4d33e91mr9121457ejc.475.1649847147170; Wed, 13 Apr 2022 03:52:27 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id v8-20020a1709063bc800b006e898cfd926sm2960952ejf.134.2022.04.13.03.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 03:52:26 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: dsahern@kernel.org, roopa@nvidia.com, idosch@idosch.org, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next v4 06/12] net: add ndo_fdb_del_bulk Date: Wed, 13 Apr 2022 13:51:56 +0300 Message-Id: <20220413105202.2616106-7-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413105202.2616106-1-razor@blackwall.org> References: <20220413105202.2616106-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add a new netdev op called ndo_fdb_del_bulk, it will be later used for driver-specific bulk delete implementation dispatched from rtnetlink. The first user will be the bridge, we need it to signal to rtnetlink from the driver that we support bulk delete operation (NLM_F_BULK). Signed-off-by: Nikolay Aleksandrov --- include/linux/netdevice.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 28ea4f8269d4..a602f29365b0 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1260,6 +1260,10 @@ struct netdev_net_notifier { * struct net_device *dev, * const unsigned char *addr, u16 vid) * Deletes the FDB entry from dev coresponding to addr. + * int (*ndo_fdb_del_bulk)(struct ndmsg *ndm, struct nlattr *tb[], + * struct net_device *dev, + * u16 vid, + * struct netlink_ext_ack *extack); * int (*ndo_fdb_dump)(struct sk_buff *skb, struct netlink_callback *cb, * struct net_device *dev, struct net_device *filter_dev, * int *idx) @@ -1510,6 +1514,11 @@ struct net_device_ops { struct net_device *dev, const unsigned char *addr, u16 vid); + int (*ndo_fdb_del_bulk)(struct ndmsg *ndm, + struct nlattr *tb[], + struct net_device *dev, + u16 vid, + struct netlink_ext_ack *extack); int (*ndo_fdb_dump)(struct sk_buff *skb, struct netlink_callback *cb, struct net_device *dev, From patchwork Wed Apr 13 10:51:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12811905 X-Patchwork-Delegate: kuba@kernel.org 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 0FE71C433EF for ; Wed, 13 Apr 2022 10:52:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235082AbiDMKzL (ORCPT ); Wed, 13 Apr 2022 06:55:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235032AbiDMKyw (ORCPT ); Wed, 13 Apr 2022 06:54:52 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 025CC5A086 for ; Wed, 13 Apr 2022 03:52:30 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id i27so3085437ejd.9 for ; Wed, 13 Apr 2022 03:52:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uxkLq5gH+i4vAlh1Vc6ej6SKnG7KxPEsV60wyj5/uCw=; b=T5NMz1Yd4mlZIRTnVHf624fuYfaEnl6cQl/aMH24k2VF6dnBpt81fvJlExFVLlMl8d +/OEY6zE5JYI+sHDKQn+4aOg0zjFL0NUB4iQEBo1QM0R4Ib0jlou80pL1tWlYY0WRuOq JQA1xV3/WL8WihukQ3KLw0Ms2f/SxH2DwMc9ypDDf7l554oN2Fbkpxhawxd7xc/VKQnT g0pMfs+Ma/7i9Q8THBb64oMMeUCLQgO//IV09CuP6gz746nFMy2EscIMlgt2O1X6RPl9 5WR0ePw5bST8//9z5XIByVQh6lazDEm3UWfA2KnGq5zf7XuATjJVYk3VAjmlYSE1YwKn 1UcQ== 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=uxkLq5gH+i4vAlh1Vc6ej6SKnG7KxPEsV60wyj5/uCw=; b=Jz9uuXaqXl8z32FPynZRqYDqySCMjerYW5HflYLfAb+6/o9m0vd3lxP5fCu83TGHrb eFKOhppEZbR2XE/KqC6ttXuBIKEZYVq0CCnBbPJqfmSv/39aFe0NCd4o9QCKynXHXmew JZHvIXXEmU4ihQFhB7QyU/HLVhwf+tLeNobtTObIVOOxzS7So907uPrEignHlzfXXDSY 9WYGi53hlaOL3+IKnvPdBqHpirB7VctunrXfKLNgQDhf23fK/34YyGFk0pXuSgwm8nZv 39NMn77JrU0DIiWktoqz2fZIsvwjCdWENK6KuM/LDcmcHr2D87/m09kXCQUv9iluCc3u 649g== X-Gm-Message-State: AOAM532fVoURNYCrLQHFnZis4JlzWLuFf2l1yoCS0B8j/DtKfPRmjOv7 lCwJKWjXHeZEUpuQnGr18zqPmz0nKHNh9MQ0 X-Google-Smtp-Source: ABdhPJy8JmTAW7T+vWGVLKtlcgUWa4rOrsc0IFA+UjTyqn8gXEcN9Ra1nKAeew+rP3Av1P/Tn6m/vQ== X-Received: by 2002:a17:906:3707:b0:6e8:6bfe:da0e with SMTP id d7-20020a170906370700b006e86bfeda0emr19542278ejc.78.1649847148295; Wed, 13 Apr 2022 03:52:28 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id v8-20020a1709063bc800b006e898cfd926sm2960952ejf.134.2022.04.13.03.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 03:52:27 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: dsahern@kernel.org, roopa@nvidia.com, idosch@idosch.org, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next v4 07/12] net: rtnetlink: add NLM_F_BULK support to rtnl_fdb_del Date: Wed, 13 Apr 2022 13:51:57 +0300 Message-Id: <20220413105202.2616106-8-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413105202.2616106-1-razor@blackwall.org> References: <20220413105202.2616106-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org When NLM_F_BULK is specified in a fdb del message we need to handle it differently. First since this is a new call we can strictly validate the passed attributes, at first only ifindex and vlan are allowed as these will be the initially supported filter attributes, any other attribute is rejected. The mac address is no longer mandatory, but we use it to error out in older kernels because it cannot be specified with bulk request (the attribute is not allowed) and then we have to dispatch the call to ndo_fdb_del_bulk if the device supports it. The del bulk callback can do further validation of the attributes if necessary. Signed-off-by: Nikolay Aleksandrov --- v4: mark PF_BRIDGE/RTM_DELNEIGH with RTNL_FLAG_BULK_DEL_SUPPORTED net/core/rtnetlink.c | 67 +++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 63c7df52a667..520d50fcaaea 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -4169,22 +4169,34 @@ int ndo_dflt_fdb_del(struct ndmsg *ndm, } EXPORT_SYMBOL(ndo_dflt_fdb_del); +static const struct nla_policy fdb_del_bulk_policy[NDA_MAX + 1] = { + [NDA_VLAN] = { .type = NLA_U16 }, + [NDA_IFINDEX] = NLA_POLICY_MIN(NLA_S32, 1), +}; + static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { + bool del_bulk = !!(nlh->nlmsg_flags & NLM_F_BULK); struct net *net = sock_net(skb->sk); + const struct net_device_ops *ops; struct ndmsg *ndm; struct nlattr *tb[NDA_MAX+1]; struct net_device *dev; - __u8 *addr; + __u8 *addr = NULL; int err; u16 vid; if (!netlink_capable(skb, CAP_NET_ADMIN)) return -EPERM; - err = nlmsg_parse_deprecated(nlh, sizeof(*ndm), tb, NDA_MAX, NULL, - extack); + if (!del_bulk) { + err = nlmsg_parse_deprecated(nlh, sizeof(*ndm), tb, NDA_MAX, + NULL, extack); + } else { + err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, + fdb_del_bulk_policy, extack); + } if (err < 0) return err; @@ -4200,9 +4212,12 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, return -ENODEV; } - if (!tb[NDA_LLADDR] || nla_len(tb[NDA_LLADDR]) != ETH_ALEN) { - NL_SET_ERR_MSG(extack, "invalid address"); - return -EINVAL; + if (!del_bulk) { + if (!tb[NDA_LLADDR] || nla_len(tb[NDA_LLADDR]) != ETH_ALEN) { + NL_SET_ERR_MSG(extack, "invalid address"); + return -EINVAL; + } + addr = nla_data(tb[NDA_LLADDR]); } if (dev->type != ARPHRD_ETHER) { @@ -4210,8 +4225,6 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, return -EINVAL; } - addr = nla_data(tb[NDA_LLADDR]); - err = fdb_vid_parse(tb[NDA_VLAN], &vid, extack); if (err) return err; @@ -4222,10 +4235,16 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, if ((!ndm->ndm_flags || ndm->ndm_flags & NTF_MASTER) && netif_is_bridge_port(dev)) { struct net_device *br_dev = netdev_master_upper_dev_get(dev); - const struct net_device_ops *ops = br_dev->netdev_ops; - if (ops->ndo_fdb_del) - err = ops->ndo_fdb_del(ndm, tb, dev, addr, vid); + ops = br_dev->netdev_ops; + if (!del_bulk) { + if (ops->ndo_fdb_del) + err = ops->ndo_fdb_del(ndm, tb, dev, addr, vid); + } else { + if (ops->ndo_fdb_del_bulk) + err = ops->ndo_fdb_del_bulk(ndm, tb, dev, vid, + extack); + } if (err) goto out; @@ -4235,15 +4254,24 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, /* Embedded bridge, macvlan, and any other device support */ if (ndm->ndm_flags & NTF_SELF) { - if (dev->netdev_ops->ndo_fdb_del) - err = dev->netdev_ops->ndo_fdb_del(ndm, tb, dev, addr, - vid); - else - err = ndo_dflt_fdb_del(ndm, tb, dev, addr, vid); + ops = dev->netdev_ops; + if (!del_bulk) { + if (ops->ndo_fdb_del) + err = ops->ndo_fdb_del(ndm, tb, dev, addr, vid); + else + err = ndo_dflt_fdb_del(ndm, tb, dev, addr, vid); + } else { + /* in case err was cleared by NTF_MASTER call */ + err = -EOPNOTSUPP; + if (ops->ndo_fdb_del_bulk) + err = ops->ndo_fdb_del_bulk(ndm, tb, dev, vid, + extack); + } if (!err) { - rtnl_fdb_notify(dev, addr, vid, RTM_DELNEIGH, - ndm->ndm_state); + if (!del_bulk) + rtnl_fdb_notify(dev, addr, vid, RTM_DELNEIGH, + ndm->ndm_state); ndm->ndm_flags &= ~NTF_SELF; } } @@ -6145,7 +6173,8 @@ void __init rtnetlink_init(void) rtnl_register(PF_UNSPEC, RTM_DELLINKPROP, rtnl_dellinkprop, NULL, 0); rtnl_register(PF_BRIDGE, RTM_NEWNEIGH, rtnl_fdb_add, NULL, 0); - rtnl_register(PF_BRIDGE, RTM_DELNEIGH, rtnl_fdb_del, NULL, 0); + rtnl_register(PF_BRIDGE, RTM_DELNEIGH, rtnl_fdb_del, NULL, + RTNL_FLAG_BULK_DEL_SUPPORTED); rtnl_register(PF_BRIDGE, RTM_GETNEIGH, rtnl_fdb_get, rtnl_fdb_dump, 0); rtnl_register(PF_BRIDGE, RTM_GETLINK, NULL, rtnl_bridge_getlink, 0); From patchwork Wed Apr 13 10:51:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12811904 X-Patchwork-Delegate: kuba@kernel.org 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 BFC2DC433FE for ; Wed, 13 Apr 2022 10:52:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235061AbiDMKzA (ORCPT ); Wed, 13 Apr 2022 06:55:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235031AbiDMKyw (ORCPT ); Wed, 13 Apr 2022 06:54:52 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 030B55A092 for ; Wed, 13 Apr 2022 03:52:31 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id r13so3114220ejd.5 for ; Wed, 13 Apr 2022 03:52:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rJB5kY6uPDJBtefnM9IfoNFJA4wwW57RZ1b7IzeHqA8=; b=hFdUSE4bdm3dm9ztdRKdeW/8cbk4xAYciXTuexkfId9nwCQCdmTBDzeHXaqgfzjQeN TZ/NsAKsRRvweTRt2EAW52YSO+2mnhtdOAADDKVaHA29uMQoS03VdTeW+86igTTMvECm ACUEP0LU5+tvPzhM4FJMzoBBmtRsIdRlXdQybuROhvIA4uHgrdlQvGSuaUsKQsOfSfVd RAybgRhJX6iwXEaoer6mxl6iJv8mrCSldsW804bEl+UIOMiYiD/oT8/MH7A8qdcFgKGj f5lFRyib564wGTYRT586IEXe6XyOsMfYecXCpGxRiZOTZQWKxMFiVOVTROU+brqsTDm6 xBow== 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=rJB5kY6uPDJBtefnM9IfoNFJA4wwW57RZ1b7IzeHqA8=; b=2GEmuGefV1Kw8PSbuekNW+UMB+LP5v4NZSd6FueHkv7D3uKwLsi9ml2hdNOLxr1qdC /Xdxqc/nkhtE6kpbj9gRwMoxMFF79gUnUq3YKVoMwBgrKdTdB3DHSYTukgs6Rmt2Zxkd mZ9LTJKP8qtXYb/S9PfeKW6aiM/dB2akXB12dZ3ivpFN4mZaNbzsLFhBpRQbZt3aPmHS 2Uq/U8B6Gz9rgPmMwES8PqKczM+xdpRrBjcsp8oKFW4XB2KP1EOcDlMWfIWB460UOExu IHqGnlH0O2S/wv/fRVleTPohR9enT7v9TIGG9iKYXbbiNNFMp+XYWHrx82t+C2DU4r4r MwYg== X-Gm-Message-State: AOAM531hcE3AH/VZ4OcZcLcNUdz3fmMU2xgVfvAePZqt0MUuCTANEpjQ XNCQ7l4VyikwbOjLIqblZoWwm8UdhzJVekm3 X-Google-Smtp-Source: ABdhPJxijpQhvK5fjap/CpjUrcUOdp8IrX5N4BwQia6pFPOIIL6KglnkwHXURm36vZ9YMjhMtvDBHg== X-Received: by 2002:a17:907:9506:b0:6da:b4cd:515b with SMTP id ew6-20020a170907950600b006dab4cd515bmr38189893ejc.602.1649847149264; Wed, 13 Apr 2022 03:52:29 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id v8-20020a1709063bc800b006e898cfd926sm2960952ejf.134.2022.04.13.03.52.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 03:52:28 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: dsahern@kernel.org, roopa@nvidia.com, idosch@idosch.org, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next v4 08/12] net: bridge: fdb: add ndo_fdb_del_bulk Date: Wed, 13 Apr 2022 13:51:58 +0300 Message-Id: <20220413105202.2616106-9-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413105202.2616106-1-razor@blackwall.org> References: <20220413105202.2616106-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add a minimal ndo_fdb_del_bulk implementation which flushes all entries. Support for more fine-grained filtering will be added in the following patches. Signed-off-by: Nikolay Aleksandrov --- v4: don't rename br_fdb_flush net/bridge/br_device.c | 1 + net/bridge/br_fdb.c | 23 +++++++++++++++++++++++ net/bridge/br_private.h | 3 +++ 3 files changed, 27 insertions(+) diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c index 8d6bab244c4a..58a4f70e01e3 100644 --- a/net/bridge/br_device.c +++ b/net/bridge/br_device.c @@ -465,6 +465,7 @@ static const struct net_device_ops br_netdev_ops = { .ndo_fix_features = br_fix_features, .ndo_fdb_add = br_fdb_add, .ndo_fdb_del = br_fdb_delete, + .ndo_fdb_del_bulk = br_fdb_delete_bulk, .ndo_fdb_dump = br_fdb_dump, .ndo_fdb_get = br_fdb_get, .ndo_bridge_getlink = br_getlink, diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 6ccda68bd473..363985f1a540 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -572,6 +572,29 @@ void br_fdb_flush(struct net_bridge *br) spin_unlock_bh(&br->hash_lock); } +int br_fdb_delete_bulk(struct ndmsg *ndm, struct nlattr *tb[], + struct net_device *dev, u16 vid, + struct netlink_ext_ack *extack) +{ + struct net_bridge_port *p = NULL; + struct net_bridge *br; + + if (netif_is_bridge_master(dev)) { + br = netdev_priv(dev); + } else { + p = br_port_get_rtnl(dev); + if (!p) { + NL_SET_ERR_MSG_MOD(extack, "Device is not a bridge port"); + return -EINVAL; + } + br = p->br; + } + + br_fdb_flush(br); + + return 0; +} + /* Flush all entries referring to a specific port. * if do_all is set also flush static entries * if vid is set delete all entries that match the vlan_id diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 6e62af2e07e9..f37d49bf5637 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -781,6 +781,9 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[], struct net_device *dev, const unsigned char *addr, u16 vid); +int br_fdb_delete_bulk(struct ndmsg *ndm, struct nlattr *tb[], + struct net_device *dev, u16 vid, + struct netlink_ext_ack *extack); int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev, const unsigned char *addr, u16 vid, u16 nlh_flags, struct netlink_ext_ack *extack); From patchwork Wed Apr 13 10:51:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12811906 X-Patchwork-Delegate: kuba@kernel.org 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 59D4DC433F5 for ; Wed, 13 Apr 2022 10:52:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232374AbiDMKzM (ORCPT ); Wed, 13 Apr 2022 06:55:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234173AbiDMKyx (ORCPT ); Wed, 13 Apr 2022 06:54:53 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A0925A09C for ; Wed, 13 Apr 2022 03:52:32 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id p15so3094901ejc.7 for ; Wed, 13 Apr 2022 03:52:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ilT4zUFtGaXgHtp2GJK2mepDZI/75DcJ6DrFnHIKpBs=; b=f5BuQoEEwTUVM51o3eEk6VO4Zk4tlK5Kw1wH/VgdHtzNTYnp1N/VYYymg6RiP+0A8N +QXGv0bnK7xKQH/A1+fSaIsgRA7bwwZQkbvRLsz4okmWcDyRAZxBTs2HjVN3Ok1Tmk53 8gE4DClTL+FNydXdcqRuB4Qg1q8y4cAzDFbLIBJf034e25gI05SJ9AAeHQ9iQW2MFjTg A4aD48sU5ovlU1rX/Hc66q7JXx6wt9t1cqm5nO3wHTvbCnQ4zwoS1k+VLJ7BBfecegKR QRa5N522QTcNmjFn1TN80h1R3ztjigBIFLLpmOYDTZK0JDeKIEpCKcjnc5jN2oEpUE2T Fy7g== 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=ilT4zUFtGaXgHtp2GJK2mepDZI/75DcJ6DrFnHIKpBs=; b=1fRrcze/8xfCuU/8T73RkM6W+JlVJsatDKw82Zpuq+WkO5XPP9hH1imNvTOgfErzfS 8UeT19tFdmPIdfbPA7FdsW5twl6t8VDrkYeCjoQZqniN+PaYdnlf/hqpfR8TrpEPNVbq Y1o/HNQERwLLRgIukzgLGEy/D+suGWOSMaKjHxw3Y4YKFNY/iwluv8+fBKHIsWwQut9o TXEsXuy7CJxW2LdOwbqRAe2TtddYjXGrb4mOH4VPvxjd38qGK/necyzeEw8UbYmo2SLG 9J7as7qISmEoH58oqHmv8I6p0UQrVCu+aTUV9SYVb5AihhZyzCiQfXYfDKi2K/JbzSjh GhjQ== X-Gm-Message-State: AOAM533HESPW0XszKWCEVrP0phx8VxTyNqb7QBzr+TfUlcaw11zCvVDp YFiNFMRvJRL7qixh9Ex2mVi2Sd/IxpZeDC2j X-Google-Smtp-Source: ABdhPJyP2F83jM1zrMYoqF3DaIY2wkF0titK07wLfVauNRzddIimJlqQse8Y5TQwhx5t0iEgiGTi1g== X-Received: by 2002:a17:907:728e:b0:6e8:9863:558a with SMTP id dt14-20020a170907728e00b006e89863558amr11127174ejc.205.1649847150571; Wed, 13 Apr 2022 03:52:30 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id v8-20020a1709063bc800b006e898cfd926sm2960952ejf.134.2022.04.13.03.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 03:52:30 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: dsahern@kernel.org, roopa@nvidia.com, idosch@idosch.org, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next v4 09/12] net: bridge: fdb: add support for fine-grained flushing Date: Wed, 13 Apr 2022 13:51:59 +0300 Message-Id: <20220413105202.2616106-10-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413105202.2616106-1-razor@blackwall.org> References: <20220413105202.2616106-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add the ability to specify exactly which fdbs to be flushed. They are described by a new structure - net_bridge_fdb_flush_desc. Currently it can match on port/bridge ifindex, vlan id and fdb flags. It is used to describe the existing dynamic fdb flush operation. Note that this flush operation doesn't treat permanent entries in a special way (fdb_delete vs fdb_delete_local), it will delete them regardless if any port is using them, so currently it can't directly replace deletes which need to handle that case, although we can extend it later for that too. Signed-off-by: Nikolay Aleksandrov --- v2: changed the flush matches func for better readability (Ido) net/bridge/br_fdb.c | 41 ++++++++++++++++++++++++++++++++-------- net/bridge/br_netlink.c | 9 +++++++-- net/bridge/br_private.h | 10 +++++++++- net/bridge/br_sysfs_br.c | 6 +++++- 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 363985f1a540..45d02f2264db 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -558,24 +558,49 @@ void br_fdb_cleanup(struct work_struct *work) mod_delayed_work(system_long_wq, &br->gc_work, work_delay); } -/* Completely flush all dynamic entries in forwarding database.*/ -void br_fdb_flush(struct net_bridge *br) +static bool __fdb_flush_matches(const struct net_bridge *br, + const struct net_bridge_fdb_entry *f, + const struct net_bridge_fdb_flush_desc *desc) +{ + const struct net_bridge_port *dst = READ_ONCE(f->dst); + int port_ifidx = dst ? dst->dev->ifindex : br->dev->ifindex; + + if (desc->vlan_id && desc->vlan_id != f->key.vlan_id) + return false; + if (desc->port_ifindex && desc->port_ifindex != port_ifidx) + return false; + if (desc->flags_mask && (f->flags & desc->flags_mask) != desc->flags) + return false; + + return true; +} + +/* Flush forwarding database entries matching the description */ +void br_fdb_flush(struct net_bridge *br, + const struct net_bridge_fdb_flush_desc *desc) { struct net_bridge_fdb_entry *f; - struct hlist_node *tmp; - spin_lock_bh(&br->hash_lock); - hlist_for_each_entry_safe(f, tmp, &br->fdb_list, fdb_node) { - if (!test_bit(BR_FDB_STATIC, &f->flags)) + rcu_read_lock(); + hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) { + if (!__fdb_flush_matches(br, f, desc)) + continue; + + spin_lock_bh(&br->hash_lock); + if (!hlist_unhashed(&f->fdb_node)) fdb_delete(br, f, true); + spin_unlock_bh(&br->hash_lock); } - spin_unlock_bh(&br->hash_lock); + rcu_read_unlock(); } int br_fdb_delete_bulk(struct ndmsg *ndm, struct nlattr *tb[], struct net_device *dev, u16 vid, struct netlink_ext_ack *extack) { + struct net_bridge_fdb_flush_desc desc = { + .flags_mask = BR_FDB_STATIC + }; struct net_bridge_port *p = NULL; struct net_bridge *br; @@ -590,7 +615,7 @@ int br_fdb_delete_bulk(struct ndmsg *ndm, struct nlattr *tb[], br = p->br; } - br_fdb_flush(br); + br_fdb_flush(br, &desc); return 0; } diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index 200ad05b296f..bb01776d2d88 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -1326,8 +1326,13 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[], br_recalculate_fwd_mask(br); } - if (data[IFLA_BR_FDB_FLUSH]) - br_fdb_flush(br); + if (data[IFLA_BR_FDB_FLUSH]) { + struct net_bridge_fdb_flush_desc desc = { + .flags_mask = BR_FDB_STATIC + }; + + br_fdb_flush(br, &desc); + } #ifdef CONFIG_BRIDGE_IGMP_SNOOPING if (data[IFLA_BR_MCAST_ROUTER]) { diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index f37d49bf5637..4d2a809546fb 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -274,6 +274,13 @@ struct net_bridge_fdb_entry { struct rcu_head rcu; }; +struct net_bridge_fdb_flush_desc { + unsigned long flags; + unsigned long flags_mask; + int port_ifindex; + u16 vlan_id; +}; + #define MDB_PG_FLAGS_PERMANENT BIT(0) #define MDB_PG_FLAGS_OFFLOAD BIT(1) #define MDB_PG_FLAGS_FAST_LEAVE BIT(2) @@ -759,7 +766,8 @@ int br_fdb_init(void); void br_fdb_fini(void); int br_fdb_hash_init(struct net_bridge *br); void br_fdb_hash_fini(struct net_bridge *br); -void br_fdb_flush(struct net_bridge *br); +void br_fdb_flush(struct net_bridge *br, + const struct net_bridge_fdb_flush_desc *desc); void br_fdb_find_delete_local(struct net_bridge *br, const struct net_bridge_port *p, const unsigned char *addr, u16 vid); diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c index 3f7ca88c2aa3..612e367fff20 100644 --- a/net/bridge/br_sysfs_br.c +++ b/net/bridge/br_sysfs_br.c @@ -344,7 +344,11 @@ static DEVICE_ATTR_RW(group_addr); static int set_flush(struct net_bridge *br, unsigned long val, struct netlink_ext_ack *extack) { - br_fdb_flush(br); + struct net_bridge_fdb_flush_desc desc = { + .flags_mask = BR_FDB_STATIC + }; + + br_fdb_flush(br, &desc); return 0; } From patchwork Wed Apr 13 10:52:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12811907 X-Patchwork-Delegate: kuba@kernel.org 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 8A104C433F5 for ; Wed, 13 Apr 2022 10:52:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235028AbiDMKzO (ORCPT ); Wed, 13 Apr 2022 06:55:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235049AbiDMKyy (ORCPT ); Wed, 13 Apr 2022 06:54:54 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90C4559A4A for ; Wed, 13 Apr 2022 03:52:33 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id c64so1835291edf.11 for ; Wed, 13 Apr 2022 03:52:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8mqGi6nmRQtdTy+PDFk54YLdSIt8nb+5grez+iJIyIQ=; b=QHcMActsk48o/Ali36FVmGtylPwMSvJWtiSShrN1MSayZJSwLjSyNfvMr1a/CihU8/ 2aXGBVDTXJEhEfHtDrgXEk+QpsK2Cx4T4Hormg5IXfa5i7gjdzWnri3JQwscS/gVMcnD GGGvjmMqLSPo9vTCpDa9ve0rNHD4LZGUAEHGtRNMmAea5QAlDDGTDAzsmRMUjIOB6DU5 HfEpjDEkLhD2p344keqn11DJkh51F/QHmYJ+Rj2XzRvBqwshtROJqFzcgM1CCWSJwSkp /F8UPaDME5EQHHfpDQcjPBzB3OZPNe5tcA09tTNzqcAdjmyD+auXM0JHVM6KTLqSS/QB FT3w== 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=8mqGi6nmRQtdTy+PDFk54YLdSIt8nb+5grez+iJIyIQ=; b=BWpVMHLFzlotzwCez7Zp8WsHb3Wgv0BmUQpBy3oB4CVLuSYLLAO2GeOkn2YFyN+0CK Jgc3V7PoZXzs0vJJKM24rPU6cw+nBluSHDJ0GKQhzHCJC/la1KuR83TmhdRWJi+8IO+c +u+iRSLzRtYLYGAJBLNs50t11XyBxcsi8wTsAr0lRU6NSjv2DXkylIC3qmNS3bl4kVfs vOP5q35+2KIrI53s8GkGPpfKuNuldT6M0S16ZOoQ7gEUdoIZJ3GN7Aziasj78LfoK16O Dzg8uOOcKheV5mhDx6sqNzaw6cFQ1wpw7iXP+ChEeCHNAn3Njhi213O/MjRIiMQhS8a3 ikaQ== X-Gm-Message-State: AOAM533oBN5CKxvYdfk+OlQrmGS+27QLivaxIV5IQwByBQuMEwQ3InPi G74uxKm863g456WQ6VYhb42JsouOtsP5B33i X-Google-Smtp-Source: ABdhPJwxlSGuLnyxI31hE+7V+fuhmPjhJYodVVueVT7xa/NWY1ZvwnY+NcgZckh1odvmfBV7RIX8rQ== X-Received: by 2002:a50:cd8c:0:b0:41c:bb5a:1c7b with SMTP id p12-20020a50cd8c000000b0041cbb5a1c7bmr42273201edi.351.1649847151603; Wed, 13 Apr 2022 03:52:31 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id v8-20020a1709063bc800b006e898cfd926sm2960952ejf.134.2022.04.13.03.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 03:52:31 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: dsahern@kernel.org, roopa@nvidia.com, idosch@idosch.org, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next v4 10/12] net: rtnetlink: add ndm flags and state mask attributes Date: Wed, 13 Apr 2022 13:52:00 +0300 Message-Id: <20220413105202.2616106-11-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413105202.2616106-1-razor@blackwall.org> References: <20220413105202.2616106-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add ndm flags/state masks which will be used for bulk delete filtering. All of these are used by the bridge and vxlan drivers. Also minimal attr policy validation is added, it is up to ndo_fdb_del_bulk implementers to further validate them. Signed-off-by: Nikolay Aleksandrov --- include/uapi/linux/neighbour.h | 2 ++ net/core/rtnetlink.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/uapi/linux/neighbour.h b/include/uapi/linux/neighbour.h index db05fb55055e..39c565e460c7 100644 --- a/include/uapi/linux/neighbour.h +++ b/include/uapi/linux/neighbour.h @@ -32,6 +32,8 @@ enum { NDA_NH_ID, NDA_FDB_EXT_ATTRS, NDA_FLAGS_EXT, + NDA_NDM_STATE_MASK, + NDA_NDM_FLAGS_MASK, __NDA_MAX }; diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 520d50fcaaea..ab7fb9a16da9 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -4172,6 +4172,8 @@ EXPORT_SYMBOL(ndo_dflt_fdb_del); static const struct nla_policy fdb_del_bulk_policy[NDA_MAX + 1] = { [NDA_VLAN] = { .type = NLA_U16 }, [NDA_IFINDEX] = NLA_POLICY_MIN(NLA_S32, 1), + [NDA_NDM_STATE_MASK] = { .type = NLA_U16 }, + [NDA_NDM_FLAGS_MASK] = { .type = NLA_U8 }, }; static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, From patchwork Wed Apr 13 10:52:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12811909 X-Patchwork-Delegate: kuba@kernel.org 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 AAF94C433F5 for ; Wed, 13 Apr 2022 10:52:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235031AbiDMKzQ (ORCPT ); Wed, 13 Apr 2022 06:55:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235056AbiDMKyz (ORCPT ); Wed, 13 Apr 2022 06:54:55 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 908645A0B3 for ; Wed, 13 Apr 2022 03:52:34 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id bv19so3109946ejb.6 for ; Wed, 13 Apr 2022 03:52:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nLzD5ZvuNGbT0XhKBua9fX6TvMHLlvf+6Ft78xLIFCA=; b=m38OBvuHHfPfmkqotdW5ajttO/ICTZzAXVPObUzxr6h97LiGtwqe/Gy/sYV0nvf/zz SKnbpal2+iL0BH92l664EYrT6FVn3DiffZNLekIc6jZyBnXh62+HDrphJGjzGvlEr8mA uA9OaeJujdz7XIByGk0R54D3pUtBnMPx60DvTXogOipDYQeTMnNjfSV2ogjoMIHI3QlK PsddNAjAvo220hS11uS2vPV1C4ppVGea8mGn6f7R9qpiKVwnfIOt1CjBmT/oRVPR7LTC Q5PHPIXQMaZi7+3MiiGi3USq4gqb3G7YJnH1ApZBYmbAaMCiMWhekcf/j7kyx3cZ3Cgt BTUw== 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=nLzD5ZvuNGbT0XhKBua9fX6TvMHLlvf+6Ft78xLIFCA=; b=ll1hORkgur1IJJ10y7YebcTAG9k/6GM5WJkhTHPVIfLFW2zgYORbUMNbXQCOJpdeaD bVwa3J64SwOGdJ4pSKEASPHNx/7s3CTtAxMniJEEsi/z9aDfE+PrJi+8W4SIh0z82Bbv SO6v2zsE3XXjEJbFnqklQYwuHtPx9O4jbHGqiwKO81QF2Ofm8WrLGTQBQT+kvXbuAB06 GN2zkd2CWPj4CmHBarD1HkgN1tIENaWD3NAd1U41b+qPiEDpddggwtwUnVz39cno7yw3 i0uavhB3I83I04t6SnQFtrNCpSXrmo9vWC2HK33mYZwbFL0HPA/bWt7wnQ3K6CqBW6Cm q8vQ== X-Gm-Message-State: AOAM530Jb70mXYcXNmfyICVRVruvaJ+0VFFB240srpHQdiWsU6q3cC15 EKBkQQAEaWYr7Gh+IPXo43m193TSIQF4bJ0N X-Google-Smtp-Source: ABdhPJzQKwhHFwo2WdAp/x+/8HKC4PXtIeFEfA76yM1TgLSHRKYVtGgnhNt0IQsEZFwh014KNVLOQw== X-Received: by 2002:a17:906:54e:b0:6e8:94b3:4563 with SMTP id k14-20020a170906054e00b006e894b34563mr12418560eja.505.1649847152857; Wed, 13 Apr 2022 03:52:32 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id v8-20020a1709063bc800b006e898cfd926sm2960952ejf.134.2022.04.13.03.52.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 03:52:32 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: dsahern@kernel.org, roopa@nvidia.com, idosch@idosch.org, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next v4 11/12] net: bridge: fdb: add support for flush filtering based on ndm flags and state Date: Wed, 13 Apr 2022 13:52:01 +0300 Message-Id: <20220413105202.2616106-12-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413105202.2616106-1-razor@blackwall.org> References: <20220413105202.2616106-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add support for fdb flush filtering based on ndm flags and state. NDM state and flags are mapped to bridge-specific flags and matched according to the specified masks. NTF_USE is used to represent added_by_user flag since it sets it on fdb add and we don't have a 1:1 mapping for it. Only allowed bits can be set, NTF_SELF and NTF_MASTER are ignored. Signed-off-by: Nikolay Aleksandrov --- v2: ignore NTF_USE/NTF_MASTER and reject unknown flags v3: NDFA -> NDA attributes net/bridge/br_fdb.c | 58 ++++++++++++++++++++++++++++++++++++++--- net/bridge/br_private.h | 5 ++++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 45d02f2264db..74d759d09f94 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -594,13 +594,40 @@ void br_fdb_flush(struct net_bridge *br, rcu_read_unlock(); } +static unsigned long __ndm_state_to_fdb_flags(u16 ndm_state) +{ + unsigned long flags = 0; + + if (ndm_state & NUD_PERMANENT) + __set_bit(BR_FDB_LOCAL, &flags); + if (ndm_state & NUD_NOARP) + __set_bit(BR_FDB_STATIC, &flags); + + return flags; +} + +static unsigned long __ndm_flags_to_fdb_flags(u8 ndm_flags) +{ + unsigned long flags = 0; + + if (ndm_flags & NTF_USE) + __set_bit(BR_FDB_ADDED_BY_USER, &flags); + if (ndm_flags & NTF_EXT_LEARNED) + __set_bit(BR_FDB_ADDED_BY_EXT_LEARN, &flags); + if (ndm_flags & NTF_OFFLOADED) + __set_bit(BR_FDB_OFFLOADED, &flags); + if (ndm_flags & NTF_STICKY) + __set_bit(BR_FDB_STICKY, &flags); + + return flags; +} + int br_fdb_delete_bulk(struct ndmsg *ndm, struct nlattr *tb[], struct net_device *dev, u16 vid, struct netlink_ext_ack *extack) { - struct net_bridge_fdb_flush_desc desc = { - .flags_mask = BR_FDB_STATIC - }; + u8 ndm_flags = ndm->ndm_flags & ~FDB_FLUSH_IGNORED_NDM_FLAGS; + struct net_bridge_fdb_flush_desc desc = {}; struct net_bridge_port *p = NULL; struct net_bridge *br; @@ -615,6 +642,31 @@ int br_fdb_delete_bulk(struct ndmsg *ndm, struct nlattr *tb[], br = p->br; } + if (ndm_flags & ~FDB_FLUSH_ALLOWED_NDM_FLAGS) { + NL_SET_ERR_MSG(extack, "Unsupported fdb flush ndm flag bits set"); + return -EINVAL; + } + if (ndm->ndm_state & ~FDB_FLUSH_ALLOWED_NDM_STATES) { + NL_SET_ERR_MSG(extack, "Unsupported fdb flush ndm state bits set"); + return -EINVAL; + } + + desc.flags |= __ndm_state_to_fdb_flags(ndm->ndm_state); + desc.flags |= __ndm_flags_to_fdb_flags(ndm_flags); + if (tb[NDA_NDM_STATE_MASK]) { + u16 ndm_state_mask = nla_get_u16(tb[NDA_NDM_STATE_MASK]); + + desc.flags_mask |= __ndm_state_to_fdb_flags(ndm_state_mask); + } + if (tb[NDA_NDM_FLAGS_MASK]) { + u8 ndm_flags_mask = nla_get_u8(tb[NDA_NDM_FLAGS_MASK]); + + desc.flags_mask |= __ndm_flags_to_fdb_flags(ndm_flags_mask); + } + + br_debug(br, "flushing port ifindex: %d vlan id: %u flags: 0x%lx flags mask: 0x%lx\n", + desc.port_ifindex, desc.vlan_id, desc.flags, desc.flags_mask); + br_fdb_flush(br, &desc); return 0; diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 4d2a809546fb..353dd4a6da7c 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -762,6 +762,11 @@ static inline void br_netpoll_disable(struct net_bridge_port *p) #endif /* br_fdb.c */ +#define FDB_FLUSH_IGNORED_NDM_FLAGS (NTF_MASTER | NTF_SELF) +#define FDB_FLUSH_ALLOWED_NDM_STATES (NUD_PERMANENT | NUD_NOARP) +#define FDB_FLUSH_ALLOWED_NDM_FLAGS (NTF_USE | NTF_EXT_LEARNED | \ + NTF_STICKY | NTF_OFFLOADED) + int br_fdb_init(void); void br_fdb_fini(void); int br_fdb_hash_init(struct net_bridge *br); From patchwork Wed Apr 13 10:52:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12811908 X-Patchwork-Delegate: kuba@kernel.org 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 337A9C433EF for ; Wed, 13 Apr 2022 10:52:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235053AbiDMKzQ (ORCPT ); Wed, 13 Apr 2022 06:55:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235029AbiDMKy4 (ORCPT ); Wed, 13 Apr 2022 06:54:56 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE1EB5A085 for ; Wed, 13 Apr 2022 03:52:35 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id c6so1856419edn.8 for ; Wed, 13 Apr 2022 03:52:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mqsQMGWoSGIiSBxMnK2lmj4CXMMwYXskZS4euBUat3E=; b=CqDiUuwWy9Ar00ARP8AYHLDoMiZ0B5XU5oPXE/n2LzKIKzDb49qspNm4EVvgWriuLB KZinTcU15VppmpjZEA9orOK8DU7Fo2EdjIq516B5dDIi3jLwGJ4d1e3sGe2O+aDhJKY+ H9VjOjlcifF4ptjMaqMKm55ysi4GaMzGDDfudxGhosRVz+6ueUxA+jloInbsRhcDb53O BwZTcmhYey2vPRJNCxvZxI2Xuz5WeRJyvv6jWAxY+JB7qlxOUvKlNqP06BAXFyx5wTRW u2a2YqRGR7QoqxFD7gp5t4D9kXT208DcQkRoSH6JOZTt+0/FHhUaA1KOsD5huESnC9iO hKvw== 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=mqsQMGWoSGIiSBxMnK2lmj4CXMMwYXskZS4euBUat3E=; b=psmaotGFuowUeRE25W4rsfyyZEnBCB2ShPy2LKdmWQ0HlLNY7EYME+ISJ4ThYugUyQ aO+VQ6RYUpJn1SJrBqCeSmPpt8WxcK0ciZDROaUf7G+jYsLD6CZ+5DJn5YuroYmD3HI1 QYzDRL+F+IosPynRTXEmSnqwsCWD1C77YPbbPiQqFgFinizgNTChdFJZe9R/wl4YhcoQ fiMs/W0CxM2SKyz8UcGLetGkyjH6Gr/0OEclNGP59IFAoq6jD496fLcFmEffrMacea4a jIZgl/utO3fYppw/U+eobOD7qHOQ3f7fLzIDcDtBXCf15YawzS3v2OIX4sLx/iMG7RWh 0OwA== X-Gm-Message-State: AOAM531INgkwAFq4+SRRd4YOmw6qGKqoxnuHdKBgaKFlZANwOqK9WyJQ yWRUbHWa/oFsBdOQc5pAMcPKWKUeTVYlBkmJ X-Google-Smtp-Source: ABdhPJyxmiTlU/gzlQY4BZV1whXOgPfQ2aPbByMtiLISua5V8l2KvoggVWfXCVu9uWjQFwcmNY+YoA== X-Received: by 2002:a05:6402:270b:b0:419:3383:7a9f with SMTP id y11-20020a056402270b00b0041933837a9fmr43266917edd.191.1649847153925; Wed, 13 Apr 2022 03:52:33 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id v8-20020a1709063bc800b006e898cfd926sm2960952ejf.134.2022.04.13.03.52.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 03:52:33 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: dsahern@kernel.org, roopa@nvidia.com, idosch@idosch.org, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next v4 12/12] net: bridge: fdb: add support for flush filtering based on ifindex and vlan Date: Wed, 13 Apr 2022 13:52:02 +0300 Message-Id: <20220413105202.2616106-13-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413105202.2616106-1-razor@blackwall.org> References: <20220413105202.2616106-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add support for fdb flush filtering based on destination ifindex and vlan id. The ifindex must either match a port's device ifindex or the bridge's. The vlan support is trivial since it's already validated by rtnl_fdb_del, we just need to fill it in. Signed-off-by: Nikolay Aleksandrov --- v2: validate ifindex and fill in vlan id v3: NDFA -> NDA attributes v4: use port's ifindex if NTF_MASTER is used and NDA_IFINDEX is not specified net/bridge/br_fdb.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 74d759d09f94..1a3d583fbc8e 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -622,12 +622,44 @@ static unsigned long __ndm_flags_to_fdb_flags(u8 ndm_flags) return flags; } +static int __fdb_flush_validate_ifindex(const struct net_bridge *br, + int ifindex, + struct netlink_ext_ack *extack) +{ + const struct net_device *dev; + + dev = __dev_get_by_index(dev_net(br->dev), ifindex); + if (!dev) { + NL_SET_ERR_MSG_MOD(extack, "Unknown flush device ifindex"); + return -ENODEV; + } + if (!netif_is_bridge_master(dev) && !netif_is_bridge_port(dev)) { + NL_SET_ERR_MSG_MOD(extack, "Flush device is not a bridge or bridge port"); + return -EINVAL; + } + if (netif_is_bridge_master(dev) && dev != br->dev) { + NL_SET_ERR_MSG_MOD(extack, + "Flush bridge device does not match target bridge device"); + return -EINVAL; + } + if (netif_is_bridge_port(dev)) { + struct net_bridge_port *p = br_port_get_rtnl(dev); + + if (p->br != br) { + NL_SET_ERR_MSG_MOD(extack, "Port belongs to a different bridge device"); + return -EINVAL; + } + } + + return 0; +} + int br_fdb_delete_bulk(struct ndmsg *ndm, struct nlattr *tb[], struct net_device *dev, u16 vid, struct netlink_ext_ack *extack) { u8 ndm_flags = ndm->ndm_flags & ~FDB_FLUSH_IGNORED_NDM_FLAGS; - struct net_bridge_fdb_flush_desc desc = {}; + struct net_bridge_fdb_flush_desc desc = { .vlan_id = vid }; struct net_bridge_port *p = NULL; struct net_bridge *br; @@ -663,6 +695,17 @@ int br_fdb_delete_bulk(struct ndmsg *ndm, struct nlattr *tb[], desc.flags_mask |= __ndm_flags_to_fdb_flags(ndm_flags_mask); } + if (tb[NDA_IFINDEX]) { + int err, ifidx = nla_get_s32(tb[NDA_IFINDEX]); + + err = __fdb_flush_validate_ifindex(br, ifidx, extack); + if (err) + return err; + desc.port_ifindex = ifidx; + } else if (p) { + /* flush was invoked with port device and NTF_MASTER */ + desc.port_ifindex = p->dev->ifindex; + } br_debug(br, "flushing port ifindex: %d vlan id: %u flags: 0x%lx flags mask: 0x%lx\n", desc.port_ifindex, desc.vlan_id, desc.flags, desc.flags_mask);