summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKuniyuki Iwashima <kuniyu@google.com>2026-09-02 20:36:54 +0000
committerJakub Kicinski <kuba@kernel.org>2026-09-04 15:02:58 -0700
commitda5a7e7a90e625aa796f290451ccf0bab354ba77 (patch)
tree29f25ab7d18212d90454ba64ae699220449f677e
parentcda2962b6e2b9fc914d6a9ed84c6ca623100ead2 (diff)
downloadlinux-next-da5a7e7a90e625aa796f290451ccf0bab354ba77.tar.gz
linux-next-da5a7e7a90e625aa796f290451ccf0bab354ba77.zip
neighbour: Don't store net in struct pneigh_entry.
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> Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20260902203722.926528-14-kuniyu@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
-rw-r--r--include/net/neighbour.h12
-rw-r--r--net/core/neighbour.c55
-rw-r--r--net/ipv4/arp.c6
-rw-r--r--net/ipv6/ip6_output.c2
-rw-r--r--net/ipv6/ndisc.c4
5 files changed, 27 insertions, 52 deletions
diff --git a/include/net/neighbour.h b/include/net/neighbour.h
index 9ff62d1f8287..ed9d9ae6d3a6 100644
--- a/include/net/neighbour.h
+++ b/include/net/neighbour.h
@@ -181,7 +181,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 {
@@ -391,19 +390,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 414422bcc0ec..9649b979918f 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -351,8 +351,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;
@@ -363,13 +362,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);
@@ -473,8 +470,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;
@@ -754,8 +750,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;
@@ -768,7 +763,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;
@@ -778,7 +772,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)
{
@@ -789,7 +783,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;
@@ -800,7 +794,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);
@@ -833,7 +826,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;
@@ -848,8 +841,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);
@@ -2049,7 +2041,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;
}
@@ -2145,7 +2137,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;
}
@@ -2891,11 +2883,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;
@@ -2906,7 +2897,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))
@@ -3165,7 +3156,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;
@@ -3365,7 +3356,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;
@@ -3373,9 +3363,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;
}
@@ -3389,21 +3376,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 995fad3bf3b2..96ee3de55f93 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -583,7 +583,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 ffb8a8b81821..90cd5d852569 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -771,7 +771,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);
@@ -1103,7 +1103,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;
}