From: Kuniyuki Iwashima <kuniyu@google.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>
Cc: Simon Horman <horms@kernel.org>,
Kuniyuki Iwashima <kuniyu@google.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>,
netdev@vger.kernel.org
Subject: [PATCH v2 net-next 11/13] neighbour: Don't store net in struct pneigh_entry.
Date: Fri, 7 Aug 2026 23:28:49 +0000 [thread overview]
Message-ID: <20260807232932.3986667-12-kuniyu@google.com> (raw)
In-Reply-To: <20260807232932.3986667-1-kuniyu@google.com>
neigh_table is now per-netns, so struct pneigh_entry does not need
to store a net pointer.
Let's remove it and net comparison for pneigh_entry.
We no longer need to pass net to pneigh_create(), pneigh_delete(),
and pneigh_lookup().
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
v2:
* Split from the next patch
* Remove net comparison in pneigh_dump_table()
* Remove net arg of pneigh_create(), pneigh_delete(), and
pneigh_lookup()
---
include/net/neighbour.h | 12 +++------
net/core/neighbour.c | 55 ++++++++++++++---------------------------
net/ipv4/arp.c | 6 ++---
net/ipv6/ip6_output.c | 2 +-
net/ipv6/ndisc.c | 4 +--
5 files changed, 27 insertions(+), 52 deletions(-)
diff --git a/include/net/neighbour.h b/include/net/neighbour.h
index b4e89533e1e6..954c13b3a2b4 100644
--- a/include/net/neighbour.h
+++ b/include/net/neighbour.h
@@ -179,7 +179,6 @@ struct neigh_ops {
struct pneigh_entry {
struct pneigh_entry __rcu *next;
- possible_net_t net;
struct net_device *dev;
netdevice_tracker dev_tracker;
union {
@@ -389,19 +388,14 @@ static inline void neigh_set_reach_time(struct neigh_parms *p)
void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
struct sk_buff *skb);
-struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, struct net *net,
+struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl,
const void *key, struct net_device *dev);
-int pneigh_create(struct neigh_table *tbl, struct net *net, const void *key,
+int pneigh_create(struct neigh_table *tbl, const void *key,
struct net_device *dev, u32 flags, u8 protocol,
bool permanent);
-int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *key,
+int pneigh_delete(struct neigh_table *tbl, const void *key,
struct net_device *dev);
-static inline struct net *pneigh_net(const struct pneigh_entry *pneigh)
-{
- return read_pnet(&pneigh->net);
-}
-
void neigh_app_ns(struct neighbour *n);
void neigh_for_each(struct neigh_table *tbl,
void (*cb)(struct neighbour *, void *), void *cookie);
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 71aadcf9626d..23ce17de23e3 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -334,8 +334,7 @@ static void neigh_parms_qlen_dec(struct net_device *dev, int family)
rcu_read_unlock();
}
-static void pneigh_queue_purge(struct sk_buff_head *list, struct net *net,
- int family)
+static void pneigh_queue_purge(struct sk_buff_head *list, int family)
{
struct sk_buff_head tmp;
unsigned long flags;
@@ -346,13 +345,11 @@ static void pneigh_queue_purge(struct sk_buff_head *list, struct net *net,
skb = skb_peek(list);
while (skb != NULL) {
struct sk_buff *skb_next = skb_peek_next(skb, list);
- struct net_device *dev = skb->dev;
- if (net == NULL || net_eq(dev_net(dev), net)) {
- neigh_parms_qlen_dec(dev, family);
- __skb_unlink(skb, list);
- __skb_queue_tail(&tmp, skb);
- }
+ neigh_parms_qlen_dec(skb->dev, family);
+ __skb_unlink(skb, list);
+ __skb_queue_tail(&tmp, skb);
+
skb = skb_next;
}
spin_unlock_irqrestore(&list->lock, flags);
@@ -459,8 +456,7 @@ static int __neigh_ifdown(struct neigh_table *tbl, struct net_device *dev,
spin_unlock_bh(&tbl->lock);
pneigh_ifdown(tbl, dev, skip_perm);
- pneigh_queue_purge(&tbl->proxy_queue, dev ? dev_net(dev) : NULL,
- tbl->family);
+ pneigh_queue_purge(&tbl->proxy_queue, tbl->family);
if (skb_queue_empty_lockless(&tbl->proxy_queue))
timer_delete_sync(&tbl->proxy_timer);
return 0;
@@ -740,8 +736,7 @@ static u32 pneigh_hash(const void *pkey, unsigned int key_len)
}
struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl,
- struct net *net, const void *pkey,
- struct net_device *dev)
+ const void *pkey, struct net_device *dev)
{
struct pneigh_entry *n;
unsigned int key_len;
@@ -754,7 +749,6 @@ struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl,
while (n) {
if (!memcmp(n->key, pkey, key_len) &&
- net_eq(pneigh_net(n), net) &&
(n->dev == dev || !n->dev))
return n;
@@ -764,7 +758,7 @@ struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl,
return NULL;
}
-int pneigh_create(struct neigh_table *tbl, struct net *net,
+int pneigh_create(struct neigh_table *tbl,
const void *pkey, struct net_device *dev,
u32 flags, u8 protocol, bool permanent)
{
@@ -775,7 +769,7 @@ int pneigh_create(struct neigh_table *tbl, struct net *net,
mutex_lock(&tbl->phash_lock);
- n = pneigh_lookup(tbl, net, pkey, dev);
+ n = pneigh_lookup(tbl, pkey, dev);
if (n)
goto update;
@@ -786,7 +780,6 @@ int pneigh_create(struct neigh_table *tbl, struct net *net,
goto out;
}
- write_pnet(&n->net, net);
memcpy(n->key, pkey, key_len);
n->dev = dev;
netdev_hold(dev, &n->dev_tracker, GFP_KERNEL);
@@ -819,7 +812,7 @@ static void pneigh_destroy(struct rcu_head *rcu)
kfree(n);
}
-int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *pkey,
+int pneigh_delete(struct neigh_table *tbl, const void *pkey,
struct net_device *dev)
{
struct pneigh_entry *n, __rcu **np;
@@ -834,8 +827,7 @@ int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *pkey,
for (np = &tbl->phash_buckets[hash_val];
(n = rcu_dereference_protected(*np, 1)) != NULL;
np = &n->next) {
- if (!memcmp(n->key, pkey, key_len) && n->dev == dev &&
- net_eq(pneigh_net(n), net)) {
+ if (!memcmp(n->key, pkey, key_len) && n->dev == dev) {
rcu_assign_pointer(*np, n->next);
mutex_unlock(&tbl->phash_lock);
@@ -2007,7 +1999,7 @@ static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh,
}
if (ndm->ndm_flags & NTF_PROXY) {
- err = pneigh_delete(tbl, net, nla_data(dst_attr), dev);
+ err = pneigh_delete(tbl, nla_data(dst_attr), dev);
goto out;
}
@@ -2103,7 +2095,7 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
goto out;
}
- err = pneigh_create(tbl, net, dst, dev, ndm_flags, protocol,
+ err = pneigh_create(tbl, dst, dev, ndm_flags, protocol,
!!(ndm->ndm_state & NUD_PERMANENT));
goto out;
}
@@ -2855,11 +2847,10 @@ static int pneigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
struct netlink_callback *cb,
struct neigh_dump_filter *filter)
{
- struct pneigh_entry *n;
- struct net *net = sock_net(skb->sk);
- int err = 0, h, s_h = cb->args[3];
int idx, s_idx = idx = cb->args[4];
+ int err = 0, h, s_h = cb->args[3];
unsigned int flags = NLM_F_MULTI;
+ struct pneigh_entry *n;
if (filter->dev_idx || filter->master_idx)
flags |= NLM_F_DUMP_FILTERED;
@@ -2870,7 +2861,7 @@ static int pneigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
for (n = rcu_dereference(tbl->phash_buckets[h]), idx = 0;
n;
n = rcu_dereference(n->next)) {
- if (idx < s_idx || pneigh_net(n) != net)
+ if (idx < s_idx)
goto next;
if (neigh_ifindex_filtered(n->dev, filter->dev_idx) ||
neigh_master_filtered(n->dev, filter->master_idx))
@@ -3129,7 +3120,7 @@ static int neigh_get(struct sk_buff *in_skb, struct nlmsghdr *nlh,
if (ndm->ndm_flags & NTF_PROXY) {
struct pneigh_entry *pn;
- pn = pneigh_lookup(tbl, net, dst, dev);
+ pn = pneigh_lookup(tbl, dst, dev);
if (!pn) {
NL_SET_ERR_MSG(extack, "Proxy neighbour entry not found");
err = -ENOENT;
@@ -3329,7 +3320,6 @@ static struct neighbour *neigh_get_idx(struct seq_file *seq, loff_t *pos)
static struct pneigh_entry *pneigh_get_first(struct seq_file *seq)
{
struct neigh_seq_state *state = seq->private;
- struct net *net = seq_file_net(seq);
struct neigh_table *tbl = state->tbl;
struct pneigh_entry *pn = NULL;
int bucket;
@@ -3337,9 +3327,6 @@ static struct pneigh_entry *pneigh_get_first(struct seq_file *seq)
state->flags |= NEIGH_SEQ_IS_PNEIGH;
for (bucket = 0; bucket <= PNEIGH_HASHMASK; bucket++) {
pn = rcu_dereference(tbl->phash_buckets[bucket]);
-
- while (pn && !net_eq(pneigh_net(pn), net))
- pn = rcu_dereference(pn->next);
if (pn)
break;
}
@@ -3353,21 +3340,15 @@ static struct pneigh_entry *pneigh_get_next(struct seq_file *seq,
loff_t *pos)
{
struct neigh_seq_state *state = seq->private;
- struct net *net = seq_file_net(seq);
struct neigh_table *tbl = state->tbl;
- do {
- pn = rcu_dereference(pn->next);
- } while (pn && !net_eq(pneigh_net(pn), net));
+ pn = rcu_dereference(pn->next);
while (!pn) {
if (++state->bucket > PNEIGH_HASHMASK)
break;
pn = rcu_dereference(tbl->phash_buckets[state->bucket]);
-
- while (pn && !net_eq(pneigh_net(pn), net))
- pn = rcu_dereference(pn->next);
if (pn)
break;
}
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index f197051d3aa7..90bc53fb8090 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -868,7 +868,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
(arp_fwd_proxy(in_dev, dev, rt) ||
arp_fwd_pvlan(in_dev, dev, rt, sip, tip) ||
(rt->dst.dev != dev &&
- pneigh_lookup(tbl, net, &tip, dev)))) {
+ pneigh_lookup(tbl, &tip, dev)))) {
n = neigh_event_ns(tbl, sha, &sip, dev);
if (n)
neigh_release(n);
@@ -1094,7 +1094,7 @@ static int arp_req_set_public(struct net *net, struct arpreq *r,
if (mask) {
__be32 ip = ((struct sockaddr_in *)&r->arp_pa)->sin_addr.s_addr;
- return pneigh_create(tbl, net, &ip, dev, 0, 0, false);
+ return pneigh_create(tbl, &ip, dev, 0, 0, false);
}
return arp_req_set_proxy(net, dev, 1);
@@ -1243,7 +1243,7 @@ static int arp_req_delete_public(struct net *net, struct arpreq *r,
if (mask) {
__be32 ip = ((struct sockaddr_in *)&r->arp_pa)->sin_addr.s_addr;
- return pneigh_delete(tbl, net, &ip, dev);
+ return pneigh_delete(tbl, &ip, dev);
}
return arp_req_set_proxy(net, dev, 0);
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 1ec32b3c0a7f..25fc57e52b5f 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -581,7 +581,7 @@ int ip6_forward(struct sk_buff *skb)
/* XXX: idev->cnf.proxy_ndp? */
if (READ_ONCE(net->ipv6.devconf_all->proxy_ndp) &&
- pneigh_lookup(nd_table(net), net, &hdr->daddr, skb->dev)) {
+ pneigh_lookup(nd_table(net), &hdr->daddr, skb->dev)) {
int proxied = ip6_forward_proxy_check(skb);
hdr = ipv6_hdr(skb);
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index 13e24c64dcdc..3e16cb581f42 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -770,7 +770,7 @@ static int pndisc_is_router(const void *pkey,
struct pneigh_entry *n;
int ret = -1;
- n = pneigh_lookup(nd_table(net), net, pkey, dev);
+ n = pneigh_lookup(nd_table(net), pkey, dev);
if (n)
ret = !!(READ_ONCE(n->flags) & NTF_ROUTER);
@@ -1102,7 +1102,7 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb)
if (lladdr && !memcmp(lladdr, dev->dev_addr, dev->addr_len) &&
READ_ONCE(net->ipv6.devconf_all->forwarding) &&
READ_ONCE(net->ipv6.devconf_all->proxy_ndp) &&
- pneigh_lookup(tbl, net, &msg->target, dev)) {
+ pneigh_lookup(tbl, &msg->target, dev)) {
/* XXX: idev->cnf.proxy_ndp */
goto out;
}
--
2.55.0.679.g6767b8d81c-goog
next prev parent reply other threads:[~2026-08-07 23:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 23:28 [PATCH v2 net-next 00/13] neighbour: Namespacify arp_tbl and nd_tbl Kuniyuki Iwashima
2026-08-07 23:28 ` [PATCH v2 net-next 01/13] neighbour: Remove __neigh_for_each_release() Kuniyuki Iwashima
2026-08-07 23:28 ` [PATCH v2 net-next 02/13] neighbour: Remove lock dance for neigh_update_{gc,managed}_list() Kuniyuki Iwashima
2026-08-07 23:28 ` [PATCH v2 net-next 03/13] neighbour: Remove unnecessary EXPORT_SYMBOL() Kuniyuki Iwashima
2026-08-07 23:28 ` [PATCH v2 net-next 04/13] neighbour: Remove __rcu from neigh_tables[] Kuniyuki Iwashima
2026-08-07 23:28 ` [PATCH v2 net-next 05/13] neighbour: Store arp_tbl and nd_tbl in net->neigh_tables[] Kuniyuki Iwashima
2026-08-07 23:28 ` [PATCH v2 net-next 06/13] neighbour: Remove neigh_tables[] Kuniyuki Iwashima
2026-08-07 23:28 ` [PATCH v2 net-next 07/13] ipv4: Replace &arp_tbl with arp_table(net) Kuniyuki Iwashima
2026-08-07 23:28 ` [PATCH v2 net-next 08/13] ipv6: Replace &nd_tbl with nd_table(net) Kuniyuki Iwashima
2026-08-07 23:28 ` [PATCH v2 net-next 09/13] neighbour: Clean up neigh_table_init() and neigh_table_clear() Kuniyuki Iwashima
2026-08-07 23:28 ` [PATCH v2 net-next 10/13] neighbour: Namespacify neigh_tables Kuniyuki Iwashima
2026-08-07 23:28 ` Kuniyuki Iwashima [this message]
2026-08-07 23:28 ` [PATCH v2 net-next 12/13] neighbour: Remove unnecessary net_eq() Kuniyuki Iwashima
2026-08-07 23:28 ` [PATCH v2 net-next 13/13] selftest: net: Specify netns for ip ntable in test_neigh.sh Kuniyuki Iwashima
2026-08-08 20:03 ` [PATCH v2 net-next 00/13] neighbour: Namespacify arp_tbl and nd_tbl Jakub Kicinski
2026-08-08 20:47 ` Kuniyuki Iwashima
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260807232932.3986667-12-kuniyu@google.com \
--to=kuniyu@google.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox