From patchwork Sat Dec 7 16:22:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13898334 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 273FB14C5AA for ; Sat, 7 Dec 2024 16:22:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733588582; cv=none; b=ZW7ZztD/QgbMrwkAJdm2iMkBK/f+qkNwmkqZJGzCGGFz4gPYWFiAjZbZRInNIe5ZzIaCSgdcTO4IKAWEsnLKZ66fYpKB70L+v7rIRZ+1towWtNI+V5gbQHGacA4o6u5aCInoihUPfdhPTI+BS76xfXxwMqVNr60Aff46YGpsfGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733588582; c=relaxed/simple; bh=mcuxVimTDVFaBUeaYQS0aykEsC4nm5KfQqOK3SnWKCQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CaioE3SOgzd3dfj78wFmI0evgIsah9r1vV+EPHeOfkujTgamQJadgee5YkwVcRbhWYU6oLJRtiFATZd+OGBi7e3XBJwajiS85heHm8Mr3jokXk6rFoR2KL+99Ii6DePLZfNR5jJ/xqQxz/dGhS/sl/f/a6oTtT1bLPe/xEKI5XY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=SzHhbCpJ; arc=none smtp.client-ip=209.85.160.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SzHhbCpJ" Received: by mail-qt1-f201.google.com with SMTP id d75a77b69052e-466b72ca44eso43360441cf.0 for ; Sat, 07 Dec 2024 08:22:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733588578; x=1734193378; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6QRTawL+6Yqt9YzIX1HcIs3HxK3NWFqJyLbSHBWQpAY=; b=SzHhbCpJgVN0wbxXwTsdeNcSaFanbkcVsfkZk2H0/ffo4EOKbFKAbtVr2JYCiOYEoP G4MNLcHwdnfDzTu7q57iT/cgwvd+HsNsT44DZnPOLTUGMHvDO59Zi12iZPWdU3D22gOq d6xjYs7+0XOMk4ilqO7W22o7bk3qVZAr15ogEEWozSAgj9V83M9WKF5GDeeX3Gf28qu/ qw+mPIYtChtwORPQOpv5ypSvPUwJM/7biGo6EJKb1feSgTG0teU7a+3Iav/WAHmsR/xD AAaPfJPP1Uzmb+WXkvYAvv2CwLyci787OAntNaQVpyxOq+ISZGqtSzC+dBZmarXzR/gz 1Ikw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733588578; x=1734193378; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6QRTawL+6Yqt9YzIX1HcIs3HxK3NWFqJyLbSHBWQpAY=; b=L/aLPbmP8JzJao6SZeJ1JgVOG3WXe5bbCGH+hgmFQ68Mi/jMuFWA2Z8j0SuGdKMKQt w7pLIkfSWxFaeQ3XyEZi8Eh1aVpUcrqvb20AH2mGYbCh1Sa8lTbsH86qK9ws9icGH+UW zTRJ3u2PlDcNYUy/92Pwm2ua7j+QlCHUNDQqWe5pKnICroMQl2UPvLjM3ha+3dDFGE4l s9X7zW6AuWg9Pn6jxUz7W+x3aHYevdTxxisHbjDEhG5ExiZQO3xWN/p09eaxCGVo1blC 8f5ETeKmpOwbsptQN9vuP9GybPx/74PyLL8kaZLTwOsq42Vy8UaPX/mUEI+1ewUkEH+0 iaxQ== X-Gm-Message-State: AOJu0YxkPCc8kCADm4/V+JsUZNJmpKbg1+I4ujjNSQJskvtVasNXLFKo 5yUOW+UkXLCij+6s4j68JQ24Mc11QJT3bpJInZi5Pim+QZIhi7/3Ul8RRTuzHd+UVOBDmrdl0+/ QogmOIWYUGQ== X-Google-Smtp-Source: AGHT+IENcFd1S9aLJ6rnsWr9MY9ihlMhIypdmxNO0B018J2m4HXtjXFufj+60QuamfxUwbdvhe6J5NjCd0fmgQ== X-Received: from qtben8.prod.google.com ([2002:a05:622a:5408:b0:466:975f:b220]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:8e07:b0:467:4f0a:1b5d with SMTP id d75a77b69052e-4674f0a7a43mr28158721cf.42.1733588578056; Sat, 07 Dec 2024 08:22:58 -0800 (PST) Date: Sat, 7 Dec 2024 16:22:46 +0000 In-Reply-To: <20241207162248.18536-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241207162248.18536-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241207162248.18536-2-edumazet@google.com> Subject: [PATCH net-next 1/3] rtnetlink: add ndo_fdb_dump_context From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Simon Horman , Roopa Prabhu , Kuniyuki Iwashima , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org rtnl_fdb_dump() and various ndo_fdb_dump() helpers share a hidden layout of cb->ctx. Before switching rtnl_fdb_dump() to for_each_netdev_dump() in the following patch, make this more explicit. Signed-off-by: Eric Dumazet Reviewed-by: Ido Schimmel Reviewed-by: Kuniyuki Iwashima --- .../ethernet/freescale/dpaa2/dpaa2-switch.c | 3 ++- drivers/net/ethernet/mscc/ocelot_net.c | 3 ++- drivers/net/vxlan/vxlan_core.c | 5 ++-- include/linux/rtnetlink.h | 7 ++++++ net/bridge/br_fdb.c | 3 ++- net/core/rtnetlink.c | 24 +++++++++---------- net/dsa/user.c | 3 ++- 7 files changed, 30 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c index a293b08f36d46dfde7e25412951da78c15e2dfd6..de383e6c6d523f01f02cb3c3977b1c448a3ac9a7 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c @@ -781,12 +781,13 @@ static int dpaa2_switch_fdb_dump_nl(struct fdb_dump_entry *entry, struct ethsw_dump_ctx *dump) { int is_dynamic = entry->type & DPSW_FDB_ENTRY_DINAMIC; + struct ndo_fdb_dump_context *ctx = (void *)dump->cb->ctx; u32 portid = NETLINK_CB(dump->cb->skb).portid; u32 seq = dump->cb->nlh->nlmsg_seq; struct nlmsghdr *nlh; struct ndmsg *ndm; - if (dump->idx < dump->cb->args[2]) + if (dump->idx < ctx->fdb_idx) goto skip; nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH, diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c index 558e03301aa8ed89e15c5f37d148a287feaf0018..8d48468cddd7cf91fb49ad23a5c57110900160ef 100644 --- a/drivers/net/ethernet/mscc/ocelot_net.c +++ b/drivers/net/ethernet/mscc/ocelot_net.c @@ -758,12 +758,13 @@ static int ocelot_port_fdb_do_dump(const unsigned char *addr, u16 vid, bool is_static, void *data) { struct ocelot_dump_ctx *dump = data; + struct ndo_fdb_dump_context *ctx = (void *)dump->cb->ctx; u32 portid = NETLINK_CB(dump->cb->skb).portid; u32 seq = dump->cb->nlh->nlmsg_seq; struct nlmsghdr *nlh; struct ndmsg *ndm; - if (dump->idx < dump->cb->args[2]) + if (dump->idx < ctx->fdb_idx) goto skip; nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH, diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index b46a799bd3904c4183775cb2e86172a0b127bb4f..2cb33c2cb836cf38b6e03b8a620594aa616f00fa 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -1352,6 +1352,7 @@ static int vxlan_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, struct net_device *dev, struct net_device *filter_dev, int *idx) { + struct ndo_fdb_dump_context *ctx = (void *)cb->ctx; struct vxlan_dev *vxlan = netdev_priv(dev); unsigned int h; int err = 0; @@ -1364,7 +1365,7 @@ static int vxlan_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, struct vxlan_rdst *rd; if (rcu_access_pointer(f->nh)) { - if (*idx < cb->args[2]) + if (*idx < ctx->fdb_idx) goto skip_nh; err = vxlan_fdb_info(skb, vxlan, f, NETLINK_CB(cb->skb).portid, @@ -1381,7 +1382,7 @@ static int vxlan_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, } list_for_each_entry_rcu(rd, &f->remotes, list) { - if (*idx < cb->args[2]) + if (*idx < ctx->fdb_idx) goto skip; err = vxlan_fdb_info(skb, vxlan, f, diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index 14b88f55192085def8f318c7913a76d5447b4975..a91dfea64724615c9db778646e52cb8573f47e06 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -178,6 +178,13 @@ void rtnetlink_init(void); void __rtnl_unlock(void); void rtnl_kfree_skbs(struct sk_buff *head, struct sk_buff *tail); +/* Shared by rtnl_fdb_dump() and various ndo_fdb_dump() helpers. */ +struct ndo_fdb_dump_context { + unsigned long s_h; + unsigned long s_idx; + unsigned long fdb_idx; +}; + extern int ndo_dflt_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, struct net_device *dev, diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 82bac2426631bcea63ea834e72f074fa2eaf0cee..902694c0ce643ec448978e4c4625692ccb1facd9 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -955,6 +955,7 @@ int br_fdb_dump(struct sk_buff *skb, struct net_device *filter_dev, int *idx) { + struct ndo_fdb_dump_context *ctx = (void *)cb->ctx; struct net_bridge *br = netdev_priv(dev); struct net_bridge_fdb_entry *f; int err = 0; @@ -970,7 +971,7 @@ int br_fdb_dump(struct sk_buff *skb, rcu_read_lock(); hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) { - if (*idx < cb->args[2]) + if (*idx < ctx->fdb_idx) goto skip; if (filter_dev && (!f->dst || f->dst->dev != filter_dev)) { if (filter_dev != dev) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index ab5f201bf0ab41b463175f501e8560b4d64d9b0a..02791328102e7590465aab9ab949af093721b256 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -4762,15 +4762,16 @@ static int nlmsg_populate_fdb(struct sk_buff *skb, int *idx, struct netdev_hw_addr_list *list) { + struct ndo_fdb_dump_context *ctx = (void *)cb->ctx; struct netdev_hw_addr *ha; - int err; u32 portid, seq; + int err; portid = NETLINK_CB(cb->skb).portid; seq = cb->nlh->nlmsg_seq; list_for_each_entry(ha, &list->list, list) { - if (*idx < cb->args[2]) + if (*idx < ctx->fdb_idx) goto skip; err = nlmsg_populate_fdb_fill(skb, dev, ha->addr, 0, @@ -4909,10 +4910,9 @@ static int valid_fdb_dump_legacy(const struct nlmsghdr *nlh, static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb) { - struct net_device *dev; - struct net_device *br_dev = NULL; - const struct net_device_ops *ops = NULL; - const struct net_device_ops *cops = NULL; + const struct net_device_ops *ops = NULL, *cops = NULL; + struct ndo_fdb_dump_context *ctx = (void *)cb->ctx; + struct net_device *dev, *br_dev = NULL; struct net *net = sock_net(skb->sk); struct hlist_head *head; int brport_idx = 0; @@ -4939,8 +4939,8 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb) ops = br_dev->netdev_ops; } - s_h = cb->args[0]; - s_idx = cb->args[1]; + s_h = ctx->s_h; + s_idx = ctx->s_idx; for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) { idx = 0; @@ -4992,7 +4992,7 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb) cops = NULL; /* reset fdb offset to 0 for rest of the interfaces */ - cb->args[2] = 0; + ctx->fdb_idx = 0; fidx = 0; cont: idx++; @@ -5000,9 +5000,9 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb) } out: - cb->args[0] = h; - cb->args[1] = idx; - cb->args[2] = fidx; + ctx->s_h = h; + ctx->s_idx = idx; + ctx->fdb_idx = fidx; return skb->len; } diff --git a/net/dsa/user.c b/net/dsa/user.c index 06c30a9e29ff820d2dd58fb1801d5e76a5928326..c736c019e2af90747738f10b667e6ad936c9eb0b 100644 --- a/net/dsa/user.c +++ b/net/dsa/user.c @@ -515,12 +515,13 @@ dsa_user_port_fdb_do_dump(const unsigned char *addr, u16 vid, bool is_static, void *data) { struct dsa_user_dump_ctx *dump = data; + struct ndo_fdb_dump_context *ctx = (void *)dump->cb->ctx; u32 portid = NETLINK_CB(dump->cb->skb).portid; u32 seq = dump->cb->nlh->nlmsg_seq; struct nlmsghdr *nlh; struct ndmsg *ndm; - if (dump->idx < dump->cb->args[2]) + if (dump->idx < ctx->fdb_idx) goto skip; nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH, From patchwork Sat Dec 7 16:22:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13898333 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qv1-f74.google.com (mail-qv1-f74.google.com [209.85.219.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B94231AAC4 for ; Sat, 7 Dec 2024 16:23:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733588582; cv=none; b=D1QbSHcgABnLcNWdQHOTIn0AbZ5c7MBx68aSqLvCpw2QzVxJ6AjxMtvP9f5DEy8oW+nFLSYotbnRrU/uwAmPDpNFmoJ5Hios9JekWu0RJCveLOLhVyZxoKfBOfrby32/VSIYun7dBqvc2ayjvHmEN8AT+ll8dVTws7i0wqs6NsQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733588582; c=relaxed/simple; bh=N1kwMeSNlbHzYyNp/qwOpPf35SX6fxu0cMZ3/S3YPOs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KNMg5+anOk5gaEMNLZk058WBJYbShFbjoJcY9aaXpVNMhCEgA1FJqoUXij7UNiinR0MtfOb68HhsoUhne4Z7BbgmbrEIV97P9mKNN9JRZoKcj8CckM9OTKpORKdZSq2zCeqVQ+nlzHOqmMTgzbuNVX1P3PvRNLweE81MJc9aZEg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ZQFk7Ss8; arc=none smtp.client-ip=209.85.219.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZQFk7Ss8" Received: by mail-qv1-f74.google.com with SMTP id 6a1803df08f44-6d8eb5ea994so22226146d6.1 for ; Sat, 07 Dec 2024 08:23:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733588579; x=1734193379; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=cBeUvaqxTUa0vvaeake0pfkuB0PcxzzK5ZCov9MMdGY=; b=ZQFk7Ss8Hv8jgls0t3dcVcD7Du09BOrX5d0FIN0IHeh9Toj7AFpI48l4jmVg8WVkZW JgncP7t9pFGAWrG0+1sxGjRzwwHHs+siXcO8kBCzd6eyfDwjCL+CYpk/DIYGZwfeBAdm /afiy8zPeP5ZZL11o5qcJFJNoGgatS169fDEDYCYHsMEtGGQLLAjT74UHFZ36CRpro8k OZnc+Xezope/iKKau9n21HY8Hc6XzWwA+nnmekMR4WGNur90PXXI3FUKwZ1MpDWYhbfs js25u67hacMpRcagXiIr7msio7isrQ6hEEa09Fd2Z6hN0koy9pQRGkmUsJX3hmL8MfVl ChvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733588579; x=1734193379; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cBeUvaqxTUa0vvaeake0pfkuB0PcxzzK5ZCov9MMdGY=; b=YjQDPzODR3vv/iYxPT1zWrOTVaug+1l4qRha4uTPMgwRH0+/l8lz13m+sF3HTZwr4Z sGKZGz3FEYwv9Eb4Q5QjJAZ62eWVXr4e/OIpFS2gjFKKnU4Wl9N/TWpZJiN2ah//db+v fwMphkR7UnUv07fpLKCX5oz24G8mp6tAauZTCMJokY52PdSajebYUbTe9Q2BXQr6TIQ9 zul2n7XIwDU3ps13rYdNd3SyH38jMHLwE6y/M4YuyStQXbrmJpvNZny8RRoybWfr1XOZ KnOA1G7R2oKuu4J3LMBDouUuzPmwvV3v8EPVHoDBnnaZCRnksC5Z7CzcIncK6+87oYDc U3hA== X-Gm-Message-State: AOJu0YzwRmPyK8DUQzNRk9ENWK7cxoC5v5ZMowZ2Wdm9pWA4GsYPYGQ2 Zh8+9bO1SoPfuBZoXHN+AFt8ETomdxUJeDScefVLB2x+zNc5qB2YS6EMiPjHsq28PsDGTpyM+Vl 0alsNzYi0ug== X-Google-Smtp-Source: AGHT+IHMm6x90ijCQbbNUPARd6N6TxPGyvvJBWKANnXSD12E3CZ/e7NVvTh2AbReBmsVP2ZkTDUN24ixPlxMVQ== X-Received: from qvbqz1.prod.google.com ([2002:a05:6214:4d41:b0:6d8:9c4c:32fd]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:c64:b0:6d8:899e:c3bf with SMTP id 6a1803df08f44-6d8e71a6668mr106250176d6.34.1733588579595; Sat, 07 Dec 2024 08:22:59 -0800 (PST) Date: Sat, 7 Dec 2024 16:22:47 +0000 In-Reply-To: <20241207162248.18536-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241207162248.18536-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241207162248.18536-3-edumazet@google.com> Subject: [PATCH net-next 2/3] rtnetlink: switch rtnl_fdb_dump() to for_each_netdev_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Simon Horman , Roopa Prabhu , Kuniyuki Iwashima , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org This is the last netdev iterator still using net->dev_index_head[]. Convert to modern for_each_netdev_dump() for better scalability, and use common patterns in our stack. Following patch in this series removes the pad field in struct ndo_fdb_dump_context. Signed-off-by: Eric Dumazet Reviewed-by: Ido Schimmel Reviewed-by: Kuniyuki Iwashima --- include/linux/rtnetlink.h | 4 +- net/core/rtnetlink.c | 92 +++++++++++++++------------------------ 2 files changed, 37 insertions(+), 59 deletions(-) diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index a91dfea64724615c9db778646e52cb8573f47e06..2b17d7eebd92342e472b9eb3b2ade84bc8ae2e94 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -180,8 +180,8 @@ void rtnl_kfree_skbs(struct sk_buff *head, struct sk_buff *tail); /* Shared by rtnl_fdb_dump() and various ndo_fdb_dump() helpers. */ struct ndo_fdb_dump_context { - unsigned long s_h; - unsigned long s_idx; + unsigned long ifindex; + unsigned long pad; unsigned long fdb_idx; }; diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 02791328102e7590465aab9ab949af093721b256..cdedb46edc2fd54f6fbd6ce7fb8e9a26486034e7 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -4914,13 +4914,10 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb) struct ndo_fdb_dump_context *ctx = (void *)cb->ctx; struct net_device *dev, *br_dev = NULL; struct net *net = sock_net(skb->sk); - struct hlist_head *head; int brport_idx = 0; int br_idx = 0; - int h, s_h; - int idx = 0, s_idx; - int err = 0; int fidx = 0; + int err; if (cb->strict_check) err = valid_fdb_dump_strict(cb->nlh, &br_idx, &brport_idx, @@ -4939,69 +4936,50 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb) ops = br_dev->netdev_ops; } - s_h = ctx->s_h; - s_idx = ctx->s_idx; - - for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) { - idx = 0; - head = &net->dev_index_head[h]; - hlist_for_each_entry(dev, head, index_hlist) { - - if (brport_idx && (dev->ifindex != brport_idx)) - continue; - - if (!br_idx) { /* user did not specify a specific bridge */ - if (netif_is_bridge_port(dev)) { - br_dev = netdev_master_upper_dev_get(dev); - cops = br_dev->netdev_ops; - } - } else { - if (dev != br_dev && - !netif_is_bridge_port(dev)) - continue; + for_each_netdev_dump(net, dev, ctx->ifindex) { + if (brport_idx && (dev->ifindex != brport_idx)) + continue; - if (br_dev != netdev_master_upper_dev_get(dev) && - !netif_is_bridge_master(dev)) - continue; - cops = ops; + if (!br_idx) { /* user did not specify a specific bridge */ + if (netif_is_bridge_port(dev)) { + br_dev = netdev_master_upper_dev_get(dev); + cops = br_dev->netdev_ops; } + } else { + if (dev != br_dev && + !netif_is_bridge_port(dev)) + continue; - if (idx < s_idx) - goto cont; + if (br_dev != netdev_master_upper_dev_get(dev) && + !netif_is_bridge_master(dev)) + continue; + cops = ops; + } - if (netif_is_bridge_port(dev)) { - if (cops && cops->ndo_fdb_dump) { - err = cops->ndo_fdb_dump(skb, cb, - br_dev, dev, - &fidx); - if (err == -EMSGSIZE) - goto out; - } + if (netif_is_bridge_port(dev)) { + if (cops && cops->ndo_fdb_dump) { + err = cops->ndo_fdb_dump(skb, cb, br_dev, dev, + &fidx); + if (err == -EMSGSIZE) + break; } + } - if (dev->netdev_ops->ndo_fdb_dump) - err = dev->netdev_ops->ndo_fdb_dump(skb, cb, - dev, NULL, - &fidx); - else - err = ndo_dflt_fdb_dump(skb, cb, dev, NULL, - &fidx); - if (err == -EMSGSIZE) - goto out; + if (dev->netdev_ops->ndo_fdb_dump) + err = dev->netdev_ops->ndo_fdb_dump(skb, cb, dev, NULL, + &fidx); + else + err = ndo_dflt_fdb_dump(skb, cb, dev, NULL, &fidx); + if (err == -EMSGSIZE) + break; - cops = NULL; + cops = NULL; - /* reset fdb offset to 0 for rest of the interfaces */ - ctx->fdb_idx = 0; - fidx = 0; -cont: - idx++; - } + /* reset fdb offset to 0 for rest of the interfaces */ + ctx->fdb_idx = 0; + fidx = 0; } -out: - ctx->s_h = h; - ctx->s_idx = idx; ctx->fdb_idx = fidx; return skb->len; From patchwork Sat Dec 7 16:22:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13898335 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D103114D29B for ; Sat, 7 Dec 2024 16:23:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733588583; cv=none; b=loZx1PaxEi3mXlHsUOq8sIInFHhAxB/t9qt2ghHvStv7iyew6dpfe0oIZ3AQiEggvTDWEuIWifWYEwUwBOZtwVNCw7rh3M58L4iuoN31g8sF4ZVnn5MRpBRtkftjQVmGl+s7s2lM+E1Fm9nVsPyToHt5fz9vpq0dPiTaV+r3+nY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733588583; c=relaxed/simple; bh=LWVBJx/mHg8fZ1laWBOVoZRo452ecAG52axAib24ye4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XE4GYG3RSEJsx3AvjGSFk4jYVd1MTtP1h9wKlxGg06yBSvBU+6Cla67YRZWFhpsouBOgfKRokuhG+BqV4mcCjd5PJGsBYM+czmYHbxxmYGmX2jNDqCrQyaRtUwdmHpB+FKSIPtnWYESkCEcE4lQJK8U2vRu0OoumycMJIpUiwnc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=acBTLjIh; arc=none smtp.client-ip=209.85.160.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="acBTLjIh" Received: by mail-qt1-f202.google.com with SMTP id d75a77b69052e-46752894cb6so7257991cf.1 for ; Sat, 07 Dec 2024 08:23:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733588581; x=1734193381; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=P/x1yWtZsJ79zjjGA9KqHWwyoR7sBywej0TPCqjBT9o=; b=acBTLjIhVylqyZXiIsKxpXTUugrU8AGbdfBu0XsEVPnsT+4h5yJLQ/8BkwjFtEeksT a48MstAwdHlyM9xKegr5hhKGVkXEo8fW4i4kMRF6aGJjp0qeFBeY/qfXw0iI/WrC+FWY lXzOFA4lE48Hpgtg8j8IVWZVFFdwQ+lxkLmIOby1WOI+2BTTz7DekmXDkKmkozU5Lxn8 fgTCAiY0c65PFsY9wJV03B1tJVt3WEUV+C/DwQUjA3nIoOIARf/h2qwFN1WOkVPbj7tH LjwOjcQHZWqbfQn27+SKvJEDsaQSRNltu52HUiiczZiCLB65zP16XFPa3igDyvlAK3Jo 88nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733588581; x=1734193381; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=P/x1yWtZsJ79zjjGA9KqHWwyoR7sBywej0TPCqjBT9o=; b=CwZQ3s2Z6znKggzm8uuvTFIG5kGkT9U3/nAGgwBuFp+Bo6Geweh/s+tN4zEPRg+i6L +Wgyp1NN8L4w/ILuR/c+0aWxJzfXRHF46uHkWQYUsWq6IM5H6g1n6pDksALnA+ghMLPQ cmGrTViqp/k64cBrb5SI1nPtnKBSjCABOXaVoI5qRfoI3QqaNLlhnSP+sr8hyM4Vjv5h PuorKf/ANBoc/xY0krSyUYFsekdN7oqSsRGiGwIoUTXkU6oeGoTih3hrDSqmr+ylXjs4 vn7w4VlvLO0R9/IqJRYvRAHoVBtOvLjMxgYnJDo4LWMdQTcozj++nx/xrDaAVwE6apWY VCDQ== X-Gm-Message-State: AOJu0YyYaTxY0dNLmMUEtQzS1BSaQx8bHXY1RJCJH1M1LJCEKGzUHPWt QJWQ8N3hweZcyUVg//OVZXL2ZzIx/OwUEHvk4efQc9CLMH7bXdMF/lhnEgy/FNE4gWIw1vbc66M y+VkJ+h244A== X-Google-Smtp-Source: AGHT+IGPFXO99oeW/46E/PjopjTUg28FlFK/IZpvFaKVndaMdib/6t2Ahpkwcql+uyFkY7aBjCgd/fe5vm6spg== X-Received: from qtbcp6.prod.google.com ([2002:a05:622a:4206:b0:462:bcd3:319d]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:2294:b0:460:a928:696f with SMTP id d75a77b69052e-46734cfdd5amr117105931cf.29.1733588581031; Sat, 07 Dec 2024 08:23:01 -0800 (PST) Date: Sat, 7 Dec 2024 16:22:48 +0000 In-Reply-To: <20241207162248.18536-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241207162248.18536-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241207162248.18536-4-edumazet@google.com> Subject: [PATCH net-next 3/3] rtnetlink: remove pad field in ndo_fdb_dump_context From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Simon Horman , Roopa Prabhu , Kuniyuki Iwashima , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org I chose to remove this field in a separate patch to ease potential bisection, in case one ndo_fdb_dump() is still using the old way (cb->args[2] instead of ctx->fdb_idx) Signed-off-by: Eric Dumazet Reviewed-by: Ido Schimmel Reviewed-by: Kuniyuki Iwashima --- include/linux/rtnetlink.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index 2b17d7eebd92342e472b9eb3b2ade84bc8ae2e94..af668b79eb757c86970b2455d9d820c902699a13 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -181,7 +181,6 @@ void rtnl_kfree_skbs(struct sk_buff *head, struct sk_buff *tail); /* Shared by rtnl_fdb_dump() and various ndo_fdb_dump() helpers. */ struct ndo_fdb_dump_context { unsigned long ifindex; - unsigned long pad; unsigned long fdb_idx; };