neighbour: Namespacify arp_tbl and nd_tbl.
Subsystems (16)
v5 cover neighbour: Namespacify arp_tbl and nd_tbl.
The neighbour subsystem is almost ready to drop RTNL.
However, the control paths are serialised by the global per-table lock.
This series converts arp_tbl and nd_tbl to per-netns table.
With the series, /proc/sys/net/ipv{4,6}/neigh/default/ can be configured per netns, which was only configurable in init_net.
To avoid potential regression, all the settings are inherited from init_net by default, and this behaviour is controlled by a new sysctl knob, net.core.neigh_inherit_init_net:
# sysctl net.core.neigh_inherit_init_net net.core.neigh_inherit_init_net = 1 # sysctl net.ipv4.neigh.default.gc_thresh1 net.ipv4.neigh.default.gc_thresh1 = 128 # sysctl net.ipv4.neigh.default.gc_thresh1=129 net.ipv4.neigh.default.gc_thresh1 = 129 # unshare -n sysctl net.ipv4.neigh.default.gc_thresh1 net.ipv4.neigh.default.gc_thresh1 = 129
If it is turned off, all settings are reset in the new netns:
# sysctl net.core.neigh_inherit_init_net=0 net.core.neigh_inherit_init_net = 0 # unshare -n sysctl net.ipv4.neigh.default.gc_thresh1 net.ipv4.neigh.default.gc_thresh1 = 128
Series overview:
Patch 1 deflakes test_neigh.sh.
Patch 2 ~ 3 are misc cleanup.
Patch 4 ~ 7 store arp_tbl/nd_tbl to net->neigh_tables[] and remove the global neigh_tables[].
Patch 8 ~ 9 replace the direct access to arp_tbl/nd_tbl to net->neigh_tables[] using new helpers.
Patch 10 ~ 12 finally replace the global table with per-netns table.
Patch 13 ~ 14 clean up unnecessary net_eq().
Patch 15 updates test_neigh.sh.
Note that some buggy drivers access nd_tbl without checking disable_ipv6_mod, so nd_tbl's extern definition is still left.
Changes:
v5:
* Rebased on the latest net-next
v4: https://lore.kernel.org/netdev/[email protected]/
* Patch 12
* Add sysctl knob, net.core.neigh_inherit_init_net
* Inherit all neigh parms by default
v3: https://lore.kernel.org/netdev/[email protected]/
* Add Patch 1 & 11
* Patch 12
* Remove timer_shutdown_sync() in neigh_flush_one() and
rely on tbl->entries (Patch 11) to free it in neigh_table_free().
* Patch 15
* Remove stale comments
v2: https://lore.kernel.org/netdev/[email protected]/
* Add Patch 11 & 13
* Patch 7
* Add note about mlx5e_tc_update_neigh_used_value()
* Patch 9
* Add __maybe_unused to net in neigh_table_clear()
* Patch 10
* panic() when register_pernet_subsys(&arp_net_ops) fails
* Add timer_shutdown_sync() in neigh_flush_one()
* Patch 11
* Split from the next patch
* Remove net comparison in pneigh_dump_table()
* Remove net arg of pneigh_create(), pneigh_delete(), and pneigh_lookup()
v1: https://lore.kernel.org/netdev/[email protected]/
Kuniyuki Iwashima (15):
selftest: net: Deflake Periodic GC test in test_neigh.sh.
neighbour: Remove __neigh_for_each_release().
neighbour: Remove lock dance for neigh_update_{gc,managed}_list().
neighbour: Remove unnecessary EXPORT_SYMBOL().
neighbour: Remove __rcu from neigh_tables[].
neighbour: Store arp_tbl and nd_tbl in net->neigh_tables[].
neighbour: Remove neigh_tables[].
ipv4: Replace &arp_tbl with arp_table(net).
ipv6: Replace &nd_tbl with nd_table(net).
neighbour: Clean up neigh_table_init() and neigh_table_clear().
neighbour: Convert neigh_table.entries to refcount_t.
neighbour: Namespacify neigh_tables.
neighbour: Don't store net in struct pneigh_entry.
neighbour: Remove unnecessary net_eq().
selftest: net: Specify netns for ip ntable in test_neigh.sh.
Documentation/admin-guide/sysctl/net.rst | 14 + drivers/infiniband/ulp/ipoib/ipoib_main.c | 27 +- .../marvell/prestera/prestera_router.c | 10 +- .../mellanox/mlx5/core/en/rep/neigh.c | 29 +- .../mellanox/mlx5/core/en/tc_tun_encap.c | 23 +- .../mellanox/mlx5/core/en_accel/ipsec.c | 6 +- .../ethernet/mellanox/mlxsw/spectrum_router.c | 31 +- .../ethernet/mellanox/mlxsw/spectrum_span.c | 10 +- .../netronome/nfp/flower/tunnel_conf.c | 14 +- drivers/net/ethernet/rocker/rocker_main.c | 2 +- drivers/net/ethernet/rocker/rocker_ofdpa.c | 2 +- drivers/net/ethernet/sfc/tc_counters.c | 8 +- drivers/net/ethernet/sfc/tc_encap_actions.c | 4 +- drivers/net/vrf.c | 2 +- drivers/net/vxlan/vxlan_core.c | 16 +- include/net/arp.h | 10 +- include/net/ndisc.h | 20 +- include/net/neighbour.h | 22 +- include/net/net_namespace.h | 4 + include/net/route.h | 7 +- net/bridge/br_arp_nd_proxy.c | 4 +- net/core/neighbour.c | 400 +++++++++--------- net/core/sysctl_net_core.c | 12 + net/ieee802154/6lowpan/tx.c | 3 +- net/ipv4/arp.c | 131 ++++-- net/ipv4/devinet.c | 18 +- net/ipv4/fib_semantics.c | 7 +- net/ipv4/route.c | 2 +- net/ipv6/addrconf.c | 17 +- net/ipv6/ip6_output.c | 4 +- net/ipv6/ndisc.c | 146 ++++--- net/ipv6/route.c | 18 +- tools/testing/selftests/net/test_neigh.sh | 66 +-- 33 files changed, 620 insertions(+), 469 deletions(-)
Signature · 1 line
2.55.0.966.g6673acef38-goog
PATCH v5 1/15 selftest: net: Deflake Periodic GC test in test_neigh.sh.
test_neigh.sh has a test case to check if GC is running periodically.
It applies a new value to BASE_REACHABLE_TIME, waits for half of the old value (+2s) to ensure the config is reflected, and waits for BASE_REACHABLE_TIME to see if the next GC is triggered.
orig_base_reachable=$(ip -j ntable show name "$tbl_name" | jq '.[] | \
select(has("thresh1")) | .["base_reachable"]')
run_cmd "ip ntable change name $tbl_name thresh1 10 base_reachable 10000"
run_cmd "sleep $(((orig_base_reachable / 1000) / 2 + 2))"This is because neigh_periodic_work() schedules the next GC with (BASE_REACHABLE_TIME / 2) seconds:
queue_delayed_work(system_power_efficient_wq, &tbl->gc_work,
NEIGH_VAR(&tbl->parms, BASE_REACHABLE_TIME) >> 1);However, the very first run is scheduled with a longer period in neigh_table_init(), which will be up to 45s:
neigh_set_reach_time(&tbl->parms);
queue_delayed_work(system_power_efficient_wq, &tbl->gc_work,
tbl->parms.reachable_time);The initial value is randomly chosen, so if it is larger than 27s (larger than two "sleep"s), the test fails.
The test fails more frequently when neigh_table is namespacified by the later patch.
In addition, the long "sleep" makes the test more flaky on kernel with CONFIG_NO_HZ_IDLE=y, which is enabled by defconfig.
The tbl->gc_work is initialised with INIT_DEFERRABLE_WORK() and queued to system_power_efficient_wq.
Even when the next GC is supposed to be triggered 5s later, "sleep" makes the CPU idle, delaying GC execution until often 20s later, which is too late.
Let's take the initial tbl->parms.reachable_time into account and poll periodic_gc_runs every 0.1s up to the proper timeout, not to make CPU idle.
---
It seems NIPA has CONFIG_HZ_PERIODIC=y and has no problem. We may want to add it in net/config.
https://netdev-ctrl.bots.linux.dev/logs/vmksft/net-dbg/results/769301/config
--- tools/testing/selftests/net/test_neigh.sh | 27 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-)
tools/testing/selftests/net/test_neigh.sh +21 -6
@@ -63,6 +63,15 @@ exit_cleanup_all() exit "${EXIT_STATUS}" } +get_periodic_gc_runs() +{ + local ns=$1 + local tbl_name=$2 + + ip -n "$ns" -j -s ntable show name "$tbl_name" | \ + jq '.[] | select(has("periodic_gc_runs")) | .["periodic_gc_runs"]' +} + ################################################################################ # Tests
@@ -282,24 +291,30 @@ extern_valid_common() local periodic_gc_runs_t0 local periodic_gc_runs_t1 local orig_base_reachable + local base_reachable=10000 local orig_gc_stale + local timeout run_cmd "ip -n $ns1 neigh flush dev veth0" orig_thresh1=$(ip -j ntable show name "$tbl_name" | jq '.[] | select(has("thresh1")) | .["thresh1"]') orig_base_reachable=$(ip -j ntable show name "$tbl_name" | jq '.[] | select(has("thresh1")) | .["base_reachable"]') - run_cmd "ip ntable change name $tbl_name thresh1 10 base_reachable 10000" + run_cmd "ip ntable change name $tbl_name thresh1 10 base_reachable $base_reachable" orig_gc_stale=$(ip -n "$ns1" -j ntable show name "$tbl_name" dev veth0 | jq '.[]["gc_stale"]') run_cmd "ip -n $ns1 ntable change name $tbl_name dev veth0 gc_stale 1000" run_cmd "ip -n $ns1 neigh add $ip_addr lladdr $mac nud stale dev veth0 extern_valid" run_cmd "ip -n $ns1 neigh add ${subnet}3 lladdr $mac nud stale dev veth0" - # Wait orig_base_reachable/2 for the new interval to take effect. - run_cmd "sleep $(((orig_base_reachable / 1000) / 2 + 2))" + # Wait up to neigh_set_reach_time(BASE_REACHABLE_TIME) (~45s) + 5s + # for the new interval to take effect, see neigh_table_init(). + timeout=$(((orig_base_reachable / 1000) * 3 / 2 + 5)) + slowwait_for_counter "$timeout" 1 get_periodic_gc_runs "$ns1" "$tbl_name" >/dev/null for i in {1..20}; do run_cmd "ip -n $ns1 neigh add ${subnet}$((i + 4)) nud none dev veth0" done - periodic_gc_runs_t0=$(ip -j -s ntable show name "$tbl_name" | jq '.[] | select(has("periodic_gc_runs")) | .["periodic_gc_runs"]') - run_cmd "sleep 10" - periodic_gc_runs_t1=$(ip -j -s ntable show name "$tbl_name" | jq '.[] | select(has("periodic_gc_runs")) | .["periodic_gc_runs"]') + periodic_gc_runs_t0=$(get_periodic_gc_runs "$ns1" "$tbl_name") + # Wait up to BASE_REACHABLE_TIME / 2 + 5s, see neigh_periodic_work(). + timeout=$(((base_reachable / 1000) / 2 + 5)) + slowwait_for_counter "$timeout" 1 get_periodic_gc_runs "$ns1" "$tbl_name" >/dev/null + periodic_gc_runs_t1=$(get_periodic_gc_runs "$ns1" "$tbl_name") [[ $periodic_gc_runs_t1 -ne $periodic_gc_runs_t0 ]] check_err $? "Periodic garbage collection did not run" run_cmd "ip -n $ns1 neigh get $ip_addr dev veth0 | grep \"extern_valid\""
Signature · 1 line
2.55.0.966.g6673acef38-goog
PATCH v5 2/15 neighbour: Remove __neigh_for_each_release().
In reply to Kuniyuki IwashimaSince commit 6deb53595092 ("net: remove unused ATM protocols and legacy ATM device drivers"), there is no in-kernel user of __neigh_for_each_release().
Let's remove it.
--- include/net/neighbour.h | 2 -- net/core/neighbour.c | 31 ------------------------------- 2 files changed, 33 deletions(-)
include/net/neighbour.h +0 -2
@@ -405,8 +405,6 @@ static inline struct net *pneigh_net(const struct pneigh_entry *pneigh)void neigh_app_ns (struct neighbour *n);void neigh_for_each (struct neigh_table *tbl,void (*cb)(struct neighbour *,void *),void *cookie); -void __neigh_for_each_release (struct neigh_table *tbl, -int (*cb)(struct neighbour *));int neigh_xmit (int fam,struct net_device *,const void *,struct sk_buff *);struct neigh_seq_state {
net/core/neighbour.c +0 -31
@@ -3161,37 +3161,6 @@ void neigh_for_each(struct neigh_table *tbl, void (*cb)(struct neighbour *, void }EXPORT_SYMBOL (neigh_for_each); -/* The tbl->lock must be held as a writer and BH disabled. */ -void __neigh_for_each_release (struct neigh_table *tbl, -int (*cb)(struct neighbour *)) -{ -struct neigh_hash_table *nht; -int chain; - - nht =rcu_dereference_protected (tbl->nht, -lockdep_is_held (&tbl->lock)); -for (chain =0 ; chain < (1 << nht->hash_shift); chain++) { -struct hlist_node *tmp; -struct neighbour *n; - -neigh_for_each_in_bucket_safe (n, tmp, &nht->hash_heads[chain]) { -int release; - -write_lock (&n->lock); - release =cb (n); -if (release) { -hlist_del_rcu (&n->hash); -hlist_del_rcu (&n->dev_list); -neigh_mark_dead (n); - } -write_unlock (&n->lock); -if (release) -neigh_cleanup_and_release (n); - } - } -} -EXPORT_SYMBOL (__neigh_for_each_release); -int neigh_xmit (int index,struct net_device *dev,const void *addr,struct sk_buff *skb) {
Signature · 1 line
2.55.0.966.g6673acef38-goog
PATCH v5 3/15 neighbour: Remove lock dance for neigh_update_{gc,managed}_list().
In reply to Kuniyuki Iwashima__neigh_update() could call neigh_update_gc_list() and neigh_update_managed_list().
Both of them acquire neigh->tbl->lock and neigh->lock, check neigh->dead, perform link operations, and release the locks.
Let's remove the lock dance.
Note that neigh->dead is always marked under neigh->tbl->lock.
--- net/core/neighbour.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-)
net/core/neighbour.c +19 -20
@@ -135,6 +135,8 @@ EXPORT_SYMBOL(neigh_rand_reach_time);static void neigh_mark_dead (struct neighbour *n) { +lockdep_assert_held (&n->tbl->lock); + n->dead =1 ;if (!list_empty (&n->gc_list)) {list_del_init (&n->gc_list);
@@ -148,11 +150,6 @@ static void neigh_update_gc_list(struct neighbour *n) {bool on_gc_list, exempt_from_gc; -spin_lock_bh (&n->tbl->lock); -write_lock (&n->lock); -if (n->dead) - goto out; -/* remove from the gc list if new state is permanent or if neighbor is * externally learned / validated; otherwise entry should be on the gc * list
@@ -169,20 +166,12 @@ static void neigh_update_gc_list(struct neighbour *n)list_add_tail (&n->gc_list, &n->tbl->gc_list);atomic_inc (&n->tbl->gc_entries); } -out: -write_unlock (&n->lock); -spin_unlock_bh (&n->tbl->lock); }static void neigh_update_managed_list (struct neighbour *n) {bool on_managed_list, add_to_managed; -spin_lock_bh (&n->tbl->lock); -write_lock (&n->lock); -if (n->dead) - goto out; - add_to_managed = n->flags &NTF_MANAGED ; on_managed_list = !list_empty (&n->managed_list);
@@ -190,9 +179,6 @@ static void neigh_update_managed_list(struct neighbour *n)list_del_init (&n->managed_list); else if (add_to_managed && !on_managed_list) list_add_tail(&n->managed_list, &n->tbl->managed_list); -out: -write_unlock (&n->lock); -spin_unlock_bh (&n->tbl->lock); } static void neigh_update_flags(struct neighbour *neigh, u32 flags, int *notify,
@@ -1523,10 +1509,23 @@ static int __neigh_update(struct neighbour *neigh, const u8 *lladdr,write_unlock_bh (&neigh->lock); -if (((new ^ old) &NUD_PERMANENT ) || gc_update) -neigh_update_gc_list (neigh); -if (managed_update) -neigh_update_managed_list (neigh); + gc_update |= !!((new ^ old) &NUD_PERMANENT ); +if (gc_update || managed_update) { +spin_lock_bh (&neigh->tbl->lock); + +if (!neigh->dead) { +write_lock (&neigh->lock); + +if (gc_update) +neigh_update_gc_list (neigh); +if (managed_update) +neigh_update_managed_list (neigh); + +write_unlock (&neigh->lock); + } + +spin_unlock_bh (&neigh->tbl->lock); + }if (notify)call_netevent_notifiers (NETEVENT_NEIGH_UPDATE , neigh);
Signature · 1 line
2.55.0.966.g6673acef38-goog
PATCH v5 4/15 neighbour: Remove unnecessary EXPORT_SYMBOL().
In reply to Kuniyuki IwashimaCommit 1bf20cc62a54 ("neighbour: remove obsolete EXPORT_SYMBOL()") unexported some functions in neighbour.c because IPv6 is no longer built as module.
Since it unexported neigh_table_init(), no module can register neigh_table dynamically.
Let's unexport a few more functions.
--- net/core/neighbour.c | 17 ----------------- 1 file changed, 17 deletions(-)
net/core/neighbour.c +0 -17
@@ -131,7 +131,6 @@ unsigned long neigh_rand_reach_time(unsigned long base) {return base ?get_random_u32_below (base) + (base >>1 ) :0 ; } -EXPORT_SYMBOL (neigh_rand_reach_time);static void neigh_mark_dead (struct neighbour *n) {
@@ -1539,7 +1538,6 @@ int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new, {return __neigh_update (neigh, lladdr, new, flags, nlmsg_pid,NULL ); } -EXPORT_SYMBOL (neigh_update);/* Update the neigh to listen temporarily for probe responses, even if it is * in a NUD_FAILED state. The caller has to hold neigh->lock for writing.
@@ -1557,7 +1555,6 @@ void __neigh_set_probe_once(struct neighbour *neigh) jiffies +max (NEIGH_VAR (neigh->parms,RETRANS_TIME ), HZ/100)); } -EXPORT_SYMBOL (__neigh_set_probe_once); struct neighbour *neigh_event_ns(struct neigh_table *tbl, u8 *lladdr, void *saddr,
@@ -1570,7 +1567,6 @@ struct neighbour *neigh_event_ns(struct neigh_table *tbl, NEIGH_UPDATE_F_OVERRIDE, 0);return neigh; } -EXPORT_SYMBOL (neigh_event_ns);/* called with read_lock_bh(&n->lock); */ static void neigh_hh_init (struct neighbour *n)
@@ -1623,7 +1619,6 @@ int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb)kfree_skb_reason (skb,SKB_DROP_REASON_NEIGH_HH_FILLFAIL ); goto out; } -EXPORT_SYMBOL (neigh_resolve_output);/* As fast as possible without hh cache */
@@ -1740,7 +1735,6 @@ void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,mod_timer (&tbl->proxy_timer, sched_next);spin_unlock (&tbl->proxy_queue.lock); } -EXPORT_SYMBOL (pneigh_enqueue);static inline struct neigh_parms *lookup_neigh_parms (struct neigh_table *tbl,struct net *net,int ifindex)
@@ -1788,7 +1782,6 @@ struct neigh_parms *neigh_parms_alloc(struct net_device *dev, }return p; } -EXPORT_SYMBOL (neigh_parms_alloc);static void neigh_rcu_free_parms (struct rcu_head *head) {
@@ -1811,7 +1804,6 @@ void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms)netdev_put (parms->dev, &parms->dev_tracker);call_rcu (&parms->rcu_head, neigh_rcu_free_parms); } -EXPORT_SYMBOL (neigh_parms_release);static struct lock_class_key neigh_table_proxy_queue_class;
@@ -3398,7 +3390,6 @@ void *neigh_seq_start(struct seq_file *seq, loff_t *pos, struct neigh_table *tblreturn *pos ?neigh_get_idx_any (seq, pos) :SEQ_START_TOKEN ; } -EXPORT_SYMBOL (neigh_seq_start);void *neigh_seq_next (struct seq_file *seq,void *v,loff_t *pos) {
@@ -3425,7 +3416,6 @@ void *neigh_seq_next(struct seq_file *seq, void *v, loff_t *pos) ++(*pos);return rc; } -EXPORT_SYMBOL (neigh_seq_next); void neigh_seq_stop(struct seq_file *seq, void *v) __releases(tbl->lock)
@@ -3437,7 +3427,6 @@ void neigh_seq_stop(struct seq_file *seq, void *v)spin_unlock_bh (&tbl->lock);rcu_read_unlock (); } -EXPORT_SYMBOL (neigh_seq_stop);/* statistics via seq_file */
@@ -3561,7 +3550,6 @@ void neigh_app_ns(struct neighbour *n) {neigh_notify (n,RTM_GETNEIGH ,NLM_F_REQUEST ,0 ); } -EXPORT_SYMBOL (neigh_app_ns);#ifdef CONFIG_SYSCTL static int unres_qlen_max =INT_MAX /SKB_TRUESIZE (ETH_FRAME_LEN );
@@ -3657,7 +3645,6 @@ int neigh_proc_dointvec(const struct ctl_table *ctl, int write, void *buffer,neigh_proc_update (ctl, write);return ret; } -EXPORT_SYMBOL (neigh_proc_dointvec);int neigh_proc_dointvec_jiffies (const struct ctl_table *ctl,int write,void *buffer,size_t *lenp,loff_t *ppos)
@@ -3667,7 +3654,6 @@ int neigh_proc_dointvec_jiffies(const struct ctl_table *ctl, int write, void *buneigh_proc_update (ctl, write);return ret; } -EXPORT_SYMBOL (neigh_proc_dointvec_jiffies); static int neigh_proc_dointvec_userhz_jiffies(const struct ctl_table *ctl, int write, void *buffer, size_t *lenp,
@@ -3687,7 +3673,6 @@ int neigh_proc_dointvec_ms_jiffies(const struct ctl_table *ctl, int write,neigh_proc_update (ctl, write);return ret; } -EXPORT_SYMBOL (neigh_proc_dointvec_ms_jiffies); static int neigh_proc_dointvec_unres_qlen(const struct ctl_table *ctl, int write, void *buffer, size_t *lenp,
@@ -3894,7 +3879,6 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p, err:return -ENOBUFS ; } -EXPORT_SYMBOL (neigh_sysctl_register);void neigh_sysctl_unregister (struct neigh_parms *p) {
@@ -3905,7 +3889,6 @@ void neigh_sysctl_unregister(struct neigh_parms *p) kfree(t); } } -EXPORT_SYMBOL (neigh_sysctl_unregister);#endif /* CONFIG_SYSCTL */
Signature · 1 line
2.55.0.966.g6673acef38-goog
PATCH v5 5/15 neighbour: Remove __rcu from neigh_tables[].
In reply to Kuniyuki IwashimaSince commit 1bf20cc62a54 ("neighbour: remove obsolete EXPORT_SYMBOL()") unexported neigh_table_init(), neigh_table cannot be registered dynamically.
Let's remove RCU protection for neigh_tables[].
Note that neightbl_set() no longer needs RCU because it holds spin_lock_bh(&tbl->lock).
--- net/core/neighbour.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)
net/core/neighbour.c +9 -14
@@ -1807,7 +1807,7 @@ void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms)static struct lock_class_key neigh_table_proxy_queue_class; -static struct neigh_table __rcu *neigh_tables[NEIGH_NR_TABLES ]__read_mostly ; +static struct neigh_table *neigh_tables[NEIGH_NR_TABLES ]__read_mostly ;void neigh_table_init (int index,struct neigh_table *tbl) {
@@ -1864,7 +1864,7 @@ void neigh_table_init(int index, struct neigh_table *tbl) tbl->last_flush = now; tbl->last_rand = now + tbl->parms.reachable_time *20 ; -rcu_assign_pointer (neigh_tables[index], tbl); + neigh_tables[index] = tbl; }/*
@@ -1873,8 +1873,7 @@ void neigh_table_init(int index, struct neigh_table *tbl)*/ int neigh_table_clear (int index,struct neigh_table *tbl) { -RCU_INIT_POINTER (neigh_tables[index],NULL ); -synchronize_rcu (); + neigh_tables[index] =NULL ;/* It is not clean... Fix it to unload IPv6 module safely */ cancel_delayed_work_sync (&tbl->managed_work);
@@ -1906,10 +1905,10 @@ static struct neigh_table *neigh_find_table(int family)switch (family) {case AF_INET : - tbl =rcu_dereference_rtnl (neigh_tables[NEIGH_ARP_TABLE ]); + tbl = neigh_tables[NEIGH_ARP_TABLE ];break ;case AF_INET6 : - tbl =rcu_dereference_rtnl (neigh_tables[NEIGH_ND_TABLE ]); + tbl = neigh_tables[NEIGH_ND_TABLE ];break ; }
@@ -2391,10 +2390,8 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, ndtmsg =nlmsg_data (nlh); -rcu_read_lock (); -for (tidx =0 ; tidx <NEIGH_NR_TABLES ; tidx++) { - tbl =rcu_dereference (neigh_tables[tidx]); + tbl = neigh_tables[tidx];if (!tbl)continue ;
@@ -2408,7 +2405,6 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, }if (!found) { -rcu_read_unlock (); err = -ENOENT ; goto errout; }
@@ -2537,7 +2533,6 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, errout_tbl_lock:spin_unlock_bh (&tbl->lock); -rcu_read_unlock (); errout:return err; }
@@ -2589,7 +2584,7 @@ static int neightbl_dump_info(struct sk_buff *skb, struct netlink_callback *cb)for (tidx =0 ; tidx <NEIGH_NR_TABLES ; tidx++) {struct neigh_parms *p; - tbl =rcu_dereference (neigh_tables[tidx]); + tbl = neigh_tables[tidx];if (!tbl)continue ;
@@ -2949,7 +2944,7 @@ static int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb)rcu_read_lock ();for (t =0 ; t <NEIGH_NR_TABLES ; t++) { - tbl =rcu_dereference (neigh_tables[t]); + tbl = neigh_tables[t];if (!tbl)continue ;
@@ -3162,7 +3157,7 @@ int neigh_xmit(int index, struct net_device *dev,struct neighbour *neigh;rcu_read_lock (); - tbl =rcu_dereference (neigh_tables[index]); + tbl = neigh_tables[index];if (!tbl) {rcu_read_unlock (); goto out_kfree_skb;
Signature · 1 line
2.55.0.966.g6673acef38-goog
PATCH v5 6/15 neighbour: Store arp_tbl and nd_tbl in net->neigh_tables[].
In reply to Kuniyuki IwashimaWe will remove RTNL for neigh_add() and neigh_delete(), but they are still serialised by per-protocol neigh_table.lock.
We can avoid contention by converting neigh_tables[] to per-netns, but arp_tbl and nd_tbl are directly used in many places.
As a prep, let's store &arp_tbl and &nd_tbl in net->neigh_tables[].
We will replace such users with arp_table(net) and nd_table(net) and then allocate per-netns neigh_table.
Note that nd_table() still returns &nd_tbl in case disable_ipv6_mod is 1 because some buggy drivers use nd_tbl without checking it.
proc_create_net() is guarded with CONFIG_PROC_FS because it returns NULL when =n and setup_net() fails and panic()s. Also a later patch moves neigh_sysctl_register() under the guard.
---
v4: Add note about CONFIG_PROC_FS
--- include/net/arp.h | 6 +++++- include/net/ndisc.h | 9 +++++++++ include/net/neighbour.h | 2 ++ include/net/net_namespace.h | 4 ++++ net/core/neighbour.c | 12 ++++++++++++ net/ipv4/arp.c | 23 +++++++++++++++++++++-- net/ipv6/ndisc.c | 12 +++++++++++- 7 files changed, 64 insertions(+), 4 deletions(-)
include/net/arp.h +5 -1
@@ -7,9 +7,13 @@#include <linux/hash.h> #include <net/neighbour.h> -extern struct neigh_table arp_tbl; +static inline struct neigh_table *arp_table (struct net *net) +{ +return net->neigh_tables[NEIGH_ARP_TABLE ]; +} +static inline u32 arp_hashfn (const void *pkey,const struct net_device *dev,u32 *hash_rnd) {u32 key = *(const u32 *)pkey;
include/net/ndisc.h +9 -0
@@ -67,6 +67,15 @@ struct prefix_info;extern struct neigh_table nd_tbl; +static inline struct neigh_table *nd_table (struct net *net) +{ +#if IS_ENABLED (CONFIG_IPV6 ) +if (disable_ipv6_mod) +return &nd_tbl; +#endif +return net->neigh_tables[NEIGH_ND_TABLE ]; +} +struct nd_msg {struct icmp6hdr icmph;struct in6_addr target;
include/net/neighbour.h +2 -0
@@ -339,6 +339,8 @@ static inline void neigh_confirm(struct neighbour *n) } } +int neigh_table_register (struct net *net,struct neigh_table *tbl,int index); +void neigh_table_unregister (struct net *net,int index);void neigh_table_init (int index,struct neigh_table *tbl);int neigh_table_clear (int index,struct neigh_table *tbl); struct neighbour *neigh_lookup(struct neigh_table *tbl, const void *pkey,
include/net/net_namespace.h +4 -0
@@ -39,6 +39,7 @@#include <net/netns/mctp.h> #include <net/netns/vsock.h> #include <net/net_trackers.h> +#include <net/neighbour_tables.h> #include <linux/ns_common.h> #include <linux/idr.h> #include <linux/skbuff.h>
@@ -47,6 +48,7 @@struct user_namespace ;struct proc_dir_entry ; +struct neigh_table ;struct net_device ;struct sock ;struct ctl_table_header ;
@@ -103,6 +105,8 @@ struct net {struct proc_dir_entry *proc_net;struct proc_dir_entry *proc_net_stat; +struct neigh_table *neigh_tables[NEIGH_NR_TABLES ]; +#ifdef CONFIG_SYSCTL struct ctl_table_set sysctls;#endif
net/core/neighbour.c +12 -0
@@ -1899,6 +1899,18 @@ int neigh_table_clear(int index, struct neigh_table *tbl)return 0 ; } +int neigh_table_register (struct net *net,struct neigh_table *tbl,int index) +{ + net->neigh_tables[index] = tbl; + +return 0 ; +} + +void neigh_table_unregister (struct net *net,int index) +{ + net->neigh_tables[index] =NULL ; +} +static struct neigh_table *neigh_find_table (int family) {struct neigh_table *tbl =NULL ;
net/ipv4/arp.c +21 -2
@@ -1495,15 +1495,34 @@ static const struct seq_operations arp_seq_ops = {static int __net_init arp_net_init (struct net *net) { +int err; + + err =neigh_table_register (net, &arp_tbl,NEIGH_ARP_TABLE ); +if (err) + goto err; + +#ifdef CONFIG_PROC_FS if (!proc_create_net ("arp" ,0444 , net->proc_net, &arp_seq_ops, -sizeof (struct neigh_seq_state ))) -return -ENOMEM ; +sizeof (struct neigh_seq_state ))) { + err = -ENOMEM ; + goto err_proc_create; + } +#endif +return 0 ; + +#ifdef CONFIG_PROC_FS +err_proc_create: +neigh_table_unregister (net,NEIGH_ARP_TABLE ); +#endif +err: +return err; } static void __net_exit arp_net_exit(struct net *net) {remove_proc_entry ("arp" , net->proc_net); +neigh_table_unregister (net,NEIGH_ARP_TABLE ); }static struct pernet_operations arp_net_ops = {
net/ipv6/ndisc.c +11 -1
@@ -1974,12 +1974,16 @@ static int __net_init ndisc_net_init(struct net *net)struct sock *sk;int err; + err =neigh_table_register (net, &nd_tbl,NEIGH_ND_TABLE ); +if (err) + goto err; + err =inet_ctl_sock_create (&sk,PF_INET6 ,SOCK_RAW ,IPPROTO_ICMPV6 , net);if (err <0 ) {net_err_ratelimited ("NDISC: Failed to initialize the control socket (err %d)\n" , err); -return err; + goto err_sock_create; } net->ipv6.ndisc_sk = sk;
@@ -1990,11 +1994,17 @@ static int __net_init ndisc_net_init(struct net *net)inet6_clear_bit (MC6_LOOP , sk);return 0 ; + +err_sock_create: +neigh_table_unregister (net,NEIGH_ND_TABLE ); +err: +return err; } static void __net_exit ndisc_net_exit(struct net *net) {inet_ctl_sock_destroy (net->ipv6.ndisc_sk); +neigh_table_unregister (net,NEIGH_ND_TABLE ); }static struct pernet_operations ndisc_net_ops = {
Signature · 1 line
2.55.0.966.g6673acef38-goog
PATCH v5 7/15 neighbour: Remove neigh_tables[].
In reply to Kuniyuki IwashimaNow, &arp_tbl and &nd_tbl are stored in net->neigh_tables[].
Let's use net->neigh_tables[] in neighbour.c and remove the global neigh_tables[].
--- include/net/neighbour.h | 4 ++-- net/core/neighbour.c | 34 +++++++++++++++------------------- net/ipv4/arp.c | 2 +- net/ipv6/ndisc.c | 4 ++-- 4 files changed, 20 insertions(+), 24 deletions(-)
include/net/neighbour.h +2 -2
@@ -341,8 +341,8 @@ static inline void neigh_confirm(struct neighbour *n)int neigh_table_register (struct net *net,struct neigh_table *tbl,int index);void neigh_table_unregister (struct net *net,int index); -void neigh_table_init (int index,struct neigh_table *tbl); -int neigh_table_clear (int index,struct neigh_table *tbl); +void neigh_table_init (struct neigh_table *tbl); +int neigh_table_clear (struct neigh_table *tbl);struct neighbour *neigh_lookup (struct neigh_table *tbl,const void *pkey,struct net_device *dev); struct neighbour *__neigh_create(struct neigh_table *tbl, const void *pkey,
net/core/neighbour.c +15 -19
@@ -1807,9 +1807,7 @@ void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms)static struct lock_class_key neigh_table_proxy_queue_class; -static struct neigh_table *neigh_tables[NEIGH_NR_TABLES ]__read_mostly ; - -void neigh_table_init (int index,struct neigh_table *tbl) +void neigh_table_init (struct neigh_table *tbl) {unsigned long now = jiffies;unsigned long phsize;
@@ -1863,18 +1861,14 @@ void neigh_table_init(int index, struct neigh_table *tbl) tbl->last_flush = now; tbl->last_rand = now + tbl->parms.reachable_time *20 ; - - neigh_tables[index] = tbl; }/* * Only called from ndisc_cleanup(), which means this is dead code * because we no longer can unload IPv6 module. */ -int neigh_table_clear (int index,struct neigh_table *tbl) +int neigh_table_clear (struct neigh_table *tbl) { - neigh_tables[index] =NULL ; -/* It is not clean... Fix it to unload IPv6 module safely */ cancel_delayed_work_sync (&tbl->managed_work);cancel_delayed_work_sync (&tbl->gc_work);
@@ -1911,16 +1905,16 @@ void neigh_table_unregister(struct net *net, int index) net->neigh_tables[index] =NULL ; } -static struct neigh_table *neigh_find_table (int family) +static struct neigh_table *neigh_find_table (struct net *net,int family) {struct neigh_table *tbl =NULL ;switch (family) {case AF_INET : - tbl = neigh_tables[NEIGH_ARP_TABLE ]; + tbl = net->neigh_tables[NEIGH_ARP_TABLE ];break ;case AF_INET6 : - tbl = neigh_tables[NEIGH_ND_TABLE ]; + tbl = net->neigh_tables[NEIGH_ND_TABLE ];break ; }
@@ -1974,7 +1968,7 @@ static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, } } - tbl =neigh_find_table (ndm->ndm_family); + tbl =neigh_find_table (net, ndm->ndm_family);if (tbl ==NULL )return -EAFNOSUPPORT ;
@@ -2060,7 +2054,7 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, } } - tbl =neigh_find_table (ndm->ndm_family); + tbl =neigh_find_table (net, ndm->ndm_family);if (tbl ==NULL )return -EAFNOSUPPORT ;
@@ -2403,7 +2397,7 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, ndtmsg =nlmsg_data (nlh);for (tidx =0 ; tidx <NEIGH_NR_TABLES ; tidx++) { - tbl = neigh_tables[tidx]; + tbl = net->neigh_tables[tidx];if (!tbl)continue ;
@@ -2596,7 +2590,7 @@ static int neightbl_dump_info(struct sk_buff *skb, struct netlink_callback *cb)for (tidx =0 ; tidx <NEIGH_NR_TABLES ; tidx++) {struct neigh_parms *p; - tbl = neigh_tables[tidx]; + tbl = net->neigh_tables[tidx];if (!tbl)continue ;
@@ -2933,6 +2927,7 @@ static int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb) {const struct nlmsghdr *nlh = cb->nlh;struct neigh_dump_filter filter = {}; +struct net *net =sock_net (skb->sk);struct neigh_table *tbl;int t, family, s_t;int proxy =0 ;
@@ -2956,8 +2951,7 @@ static int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb)rcu_read_lock ();for (t =0 ; t <NEIGH_NR_TABLES ; t++) { - tbl = neigh_tables[t]; - + tbl = net->neigh_tables[t];if (!tbl)continue ;if (t < s_t || (family && tbl->family != family))
@@ -3079,7 +3073,7 @@ static int neigh_get(struct sk_buff *in_skb, struct nlmsghdr *nlh,rcu_read_lock (); - tbl =neigh_find_table (ndm->ndm_family); + tbl =neigh_find_table (net, ndm->ndm_family);if (!tbl) {NL_SET_ERR_MSG (extack,"Unsupported family in header for neighbor get request" ); err = -EAFNOSUPPORT ;
@@ -3167,9 +3161,11 @@ int neigh_xmit(int index, struct net_device *dev,if (likely (index <NEIGH_NR_TABLES )) {struct neigh_table *tbl;struct neighbour *neigh; +struct net *net;rcu_read_lock (); - tbl = neigh_tables[index]; + net =dev_net_rcu (dev); + tbl = net->neigh_tables[index];if (!tbl) {rcu_read_unlock (); goto out_kfree_skb;
net/ipv4/arp.c +1 -1
@@ -1532,7 +1532,7 @@ static struct pernet_operations arp_net_ops = {void __init arp_init (void ) { -neigh_table_init (NEIGH_ARP_TABLE , &arp_tbl); +neigh_table_init (&arp_tbl);dev_add_pack (&arp_packet_type);register_pernet_subsys (&arp_net_ops);
net/ipv6/ndisc.c +2 -2
@@ -2022,7 +2022,7 @@ int __init ndisc_init(void)/* * Initialize the neighbour table */ -neigh_table_init (NEIGH_ND_TABLE , &nd_tbl); +neigh_table_init (&nd_tbl);#ifdef CONFIG_SYSCTL err = neigh_sysctl_register(NULL, &nd_tbl.parms,
@@ -2055,6 +2055,6 @@ void ndisc_cleanup(void)#ifdef CONFIG_SYSCTL neigh_sysctl_unregister (&nd_tbl.parms);#endif -neigh_table_clear (NEIGH_ND_TABLE , &nd_tbl); +neigh_table_clear (&nd_tbl);unregister_pernet_subsys (&ndisc_net_ops); }
Signature · 1 line
2.55.0.966.g6673acef38-goog
PATCH v5 8/15 ipv4: Replace &arp_tbl with arp_table(net).
In reply to Kuniyuki IwashimaWe will allocate per-netns neigh_table in net->neigh_tables[].
Let's replace &arp_tbl with arp_table(net) and remove extern definition for arp_tbl.
Three notes:
1. mlx5e_rep_netevent_event() and nfp_tun_neigh_event_handler() have code assuming neigh_table other than &arp_tbl and &nb_tbl, and the part is removed as it will be false once per-netns table is allocated.
2. prestera and rocker uses init_net because they set
dev->netns_immutable to true.
3. mlx5e_tc_update_neigh_used_value() dereferences nhe->neigh_dev in trace_mlx5e_tc_update_neigh_used_value().
---
v2: Add note about mlx5e_tc_update_neigh_used_value()
--- drivers/infiniband/ulp/ipoib/ipoib_main.c | 27 ++++-- .../marvell/prestera/prestera_router.c | 10 ++- .../mellanox/mlx5/core/en/rep/neigh.c | 22 ++--- .../mellanox/mlx5/core/en/tc_tun_encap.c | 23 ++--- .../mellanox/mlx5/core/en_accel/ipsec.c | 6 +- .../ethernet/mellanox/mlxsw/spectrum_router.c | 18 ++-- .../ethernet/mellanox/mlxsw/spectrum_span.c | 5 +- .../netronome/nfp/flower/tunnel_conf.c | 10 +-- drivers/net/ethernet/rocker/rocker_main.c | 2 +- drivers/net/ethernet/rocker/rocker_ofdpa.c | 2 +- drivers/net/ethernet/sfc/tc_counters.c | 6 +- drivers/net/ethernet/sfc/tc_encap_actions.c | 2 +- drivers/net/vxlan/vxlan_core.c | 10 ++- include/net/arp.h | 6 +- include/net/route.h | 7 +- net/bridge/br_arp_nd_proxy.c | 2 +- net/ipv4/arp.c | 88 +++++++++++-------- net/ipv4/devinet.c | 18 ++-- net/ipv4/fib_semantics.c | 5 +- net/ipv4/route.c | 2 +- 20 files changed, 159 insertions(+), 112 deletions(-)
drivers/infiniband/ulp/ipoib/ipoib_main.c +19 -8
@@ -1378,7 +1378,8 @@ struct ipoib_neigh *ipoib_neigh_get(struct net_device *dev, u8 *daddr)return neigh; } -static void __ipoib_reap_neigh (struct ipoib_dev_priv *priv) +static void __ipoib_reap_neigh (struct ipoib_dev_priv *priv, +int gc_interval) {struct ipoib_neigh_table *ntbl = &priv->ntbl;struct ipoib_neigh_hash *htbl;
@@ -1397,7 +1398,7 @@ static void __ipoib_reap_neigh(struct ipoib_dev_priv *priv) goto out_unlock;/* neigh is obsolete if it was idle for two GC periods */ - dt =2 * arp_tbl.gc_interval; + dt =2 * gc_interval; neigh_obsolete = jiffies - dt;for (i =0 ; i < htbl->size; i++) {
@@ -1433,11 +1434,16 @@ static void ipoib_reap_neigh(struct work_struct *work) {struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv, neigh_reap_task.work); +struct net_device *dev = priv->dev; +struct net *net =dev_net (dev); +struct neigh_table *tbl; +int gc_interval; -__ipoib_reap_neigh (priv); + tbl =arp_table (net); + gc_interval = tbl->gc_interval; +__ipoib_reap_neigh (priv, gc_interval); -queue_delayed_work (priv->wq, &priv->neigh_reap_task, - arp_tbl.gc_interval); +queue_delayed_work (priv->wq, &priv->neigh_reap_task, gc_interval); }
@@ -1590,8 +1596,11 @@ void ipoib_neigh_free(struct ipoib_neigh *neigh)static int ipoib_neigh_hash_init (struct ipoib_dev_priv *priv) {struct ipoib_neigh_table *ntbl = &priv->ntbl; -struct ipoib_neigh_hash *htbl;struct ipoib_neigh __rcu **buckets; +struct net_device *dev = priv->dev; +struct net *net =dev_net (dev); +struct ipoib_neigh_hash *htbl; +struct neigh_table *tbl;u32 size;clear_bit (IPOIB_NEIGH_TBL_FLUSH , &priv->flags);
@@ -1599,7 +1608,9 @@ static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv) htbl =kzalloc_obj (*htbl);if (!htbl)return -ENOMEM ; - size =roundup_pow_of_two (arp_tbl.gc_thresh3); + + tbl =arp_table (net); + size =roundup_pow_of_two (tbl->gc_thresh3); buckets =kvzalloc_objs (*buckets, size);if (!buckets) {kfree (htbl);
@@ -1614,7 +1625,7 @@ static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv)/* start garbage collection */ queue_delayed_work (priv->wq, &priv->neigh_reap_task, - arp_tbl.gc_interval); + tbl->gc_interval);return 0 ; }
drivers/net/ethernet/marvell/prestera/prestera_router.c +6 -4
@@ -683,7 +683,7 @@ __prestera_k_arb_n_offload_set(struct prestera_switch *sw, {struct neighbour *n; - n =neigh_lookup (&arp_tbl, &nc->key.addr.u.ipv4, + n =neigh_lookup (arp_table (&init_net), &nc->key.addr.u.ipv4, nc->key.dev);if (!n)return ;
@@ -790,7 +790,7 @@ __prestera_k_arb_nc_kern_n_fetch(struct prestera_switch *sw,int err;memset (&nc->nh_neigh_info,0 ,sizeof (nc->nh_neigh_info)); - n =neigh_lookup (&arp_tbl, &nc->key.addr.u.ipv4, nc->key.dev); + n =neigh_lookup (arp_table (&init_net), &nc->key.addr.u.ipv4, nc->key.dev);if (!n) goto out;
@@ -1052,10 +1052,12 @@ static void __prestera_k_arb_hw_state_upd(struct prestera_switch *sw,#endif /* PRESTERA_IMPLICITY_RESOLVE_DEAD_NEIGH */ if (nc->key.addr.v ==PRESTERA_IPV4 ) { - n =neigh_lookup (&arp_tbl, &nc->key.addr.u.ipv4, +struct neigh_table *tbl =arp_table (&init_net); + + n =neigh_lookup (tbl, &nc->key.addr.u.ipv4, nc->key.dev);if (!n) - n =neigh_create (&arp_tbl, &nc->key.addr.u.ipv4, + n =neigh_create (tbl, &nc->key.addr.u.ipv4, nc->key.dev); }else { n =NULL ;
drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c +9 -13
@@ -27,10 +27,16 @@ static unsigned long mlx5e_rep_ipv6_interval(void)static void mlx5e_rep_neigh_update_init_interval (struct mlx5e_rep_priv *rpriv) { -unsigned long ipv4_interval =NEIGH_VAR (&arp_tbl.parms,DELAY_PROBE_TIME );unsigned long ipv6_interval =mlx5e_rep_ipv6_interval ();struct net_device *netdev = rpriv->netdev; -struct mlx5e_priv *priv =netdev_priv (netdev); +struct net *net =dev_net (netdev); +unsigned long ipv4_interval; +struct neigh_table *tbl; +struct mlx5e_priv *priv; + + priv =netdev_priv (netdev); + tbl =arp_table (net); + ipv4_interval =NEIGH_VAR (&tbl->parms,DELAY_PROBE_TIME ); rpriv->neigh_update.min_interval = min_t(unsigned long, ipv6_interval, ipv4_interval);mlx5_fc_update_sampling_interval (priv->mdev, rpriv->neigh_update.min_interval);
@@ -217,12 +223,6 @@ static int mlx5e_rep_netevent_event(struct notifier_block *nb,switch (event) {case NETEVENT_NEIGH_UPDATE : n = ptr; -#if IS_ENABLED (CONFIG_IPV6 ) -if (n->tbl != &nd_tbl && n->tbl != &arp_tbl) -#else - if (n->tbl != &arp_tbl) -#endif -return NOTIFY_DONE ; update_work =mlx5e_alloc_neigh_update_work (priv, n);if (!update_work)
@@ -238,11 +238,7 @@ static int mlx5e_rep_netevent_event(struct notifier_block *nb,* changes in the default table, we only care about changes * done per device delay prob time parameter. */ -#if IS_ENABLED (CONFIG_IPV6 ) -if (!p->dev || (p->tbl != &nd_tbl && p->tbl != &arp_tbl)) -#else - if (!p->dev || p->tbl != &arp_tbl) -#endif +if (!p->dev)return NOTIFY_DONE ;rcu_read_lock ();
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +12 -11
@@ -393,20 +393,10 @@ void mlx5e_tc_update_neigh_used_value(struct mlx5e_neigh_hash_entry *nhe)struct mlx5e_encap_entry *e =NULL ;struct mlx5e_tc_flow *flow;struct mlx5_fc *counter; -struct neigh_table *tbl;bool neigh_used = false;struct neighbour *n;u64 lastuse; -if (m_neigh->family ==AF_INET ) - tbl = &arp_tbl; -#if IS_ENABLED (CONFIG_IPV6 ) - else if (m_neigh->family == AF_INET6) - tbl = &nd_tbl; -#endif - else - return; -/* mlx5e_get_next_valid_encap() releases previous encap before returning * next one. */
@@ -447,12 +437,23 @@ void mlx5e_tc_update_neigh_used_value(struct mlx5e_neigh_hash_entry *nhe)trace_mlx5e_tc_update_neigh_used_value (nhe, neigh_used);if (neigh_used) { +struct net_device *dev =READ_ONCE (nhe->neigh_dev); +struct net *net =dev_net (dev); +struct neigh_table *tbl; + nhe->reported_lastuse = jiffies; +#if IS_ENABLED (CONFIG_IPV6 ) +if (m_neigh->family !=AF_INET ) + tbl = &nd_tbl; + else +#endif + tbl =arp_table (net); +/* find the relevant neigh according to the cached device and * dst ip pair */ - n =neigh_lookup (tbl, &m_neigh->dst_ip,READ_ONCE (nhe->neigh_dev)); + n =neigh_lookup (tbl, &m_neigh->dst_ip, dev);if (!n)return ;
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c +4 -2
@@ -262,6 +262,7 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,struct net_device *netdev = sa_entry->dev;struct xfrm_state *x = sa_entry->x;struct dst_entry *rt_dst_entry; +struct neigh_table *tbl;struct flowi4 fl4 = {};struct flowi6 fl6 = {};struct neighbour *n;
@@ -364,9 +365,10 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,return ; neigh: - n =neigh_lookup (&arp_tbl, pkey, netdev); + tbl =arp_table (dev_net (netdev)); + n =neigh_lookup (tbl, pkey, netdev);if (!n) { - n =neigh_create (&arp_tbl, pkey, netdev); + n =neigh_create (tbl, pkey, netdev);if (IS_ERR (n))return ;neigh_event_send (n,NULL );
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +12 -6
@@ -2397,14 +2397,15 @@ mlxsw_sp_neigh_entry_lookup(struct mlxsw_sp *mlxsw_sp, struct neighbour *n)static void mlxsw_sp_router_neighs_update_interval_init (struct mlxsw_sp *mlxsw_sp) { +struct net *net =mlxsw_sp_net (mlxsw_sp);unsigned long interval;#if IS_ENABLED (CONFIG_IPV6 ) interval = min_t(unsigned long, -NEIGH_VAR (&arp_tbl.parms,DELAY_PROBE_TIME ), +NEIGH_VAR (&arp_table (net)->parms,DELAY_PROBE_TIME ),NEIGH_VAR (&nd_tbl.parms,DELAY_PROBE_TIME ));#else - interval =NEIGH_VAR (&arp_tbl.parms,DELAY_PROBE_TIME ); + interval =NEIGH_VAR (&arp_table (net)->parms,DELAY_PROBE_TIME );#endif mlxsw_sp->router->neighs_update.interval =jiffies_to_msecs (interval); }
@@ -2414,6 +2415,8 @@ static void mlxsw_sp_router_neigh_ent_ipv4_process(struct mlxsw_sp *mlxsw_sp, int ent_index) {u64 max_rifs =MLXSW_CORE_RES_GET (mlxsw_sp->core,MAX_RIFS ); +struct net *net =mlxsw_sp_net (mlxsw_sp); +struct neigh_table *tbl;struct net_device *dev;struct neighbour *n;__be32 dipn;
@@ -2429,9 +2432,10 @@ static void mlxsw_sp_router_neigh_ent_ipv4_process(struct mlxsw_sp *mlxsw_sp,return ; } + tbl =arp_table (net); dipn =htonl (dip); dev =mlxsw_sp_rif_dev (mlxsw_sp->router->rifs[rif]); - n =neigh_lookup (&arp_tbl, &dipn, dev); + n =neigh_lookup (tbl, &dipn, dev);if (!n)return ;
@@ -3014,11 +3018,12 @@ static int mlxsw_sp_neigh_rif_made_sync(struct mlxsw_sp *mlxsw_sp, .mlxsw_sp = mlxsw_sp, .rif = rif, }; +struct net *net =mlxsw_sp_net (mlxsw_sp);if (!mlxsw_sp_dev_lower_is_port (mlxsw_sp_rif_dev (rif)))return 0 ; -neigh_for_each (&arp_tbl, mlxsw_sp_neigh_rif_made_sync_each, &rms); +neigh_for_each (arp_table (net), mlxsw_sp_neigh_rif_made_sync_each, &rms);if (rms.err) goto err_arp;
@@ -4622,7 +4627,7 @@ static int mlxsw_sp_nexthop4_init(struct mlxsw_sp *mlxsw_sp, nh->nh_weight =1 ;#endif memcpy (&nh->gw_addr, &fib_nh->fib_nh_gw4,sizeof (fib_nh->fib_nh_gw4)); - nh->neigh_tbl = &arp_tbl; + nh->neigh_tbl =arp_table (mlxsw_sp_net (mlxsw_sp)); err =mlxsw_sp_nexthop_insert (mlxsw_sp, nh);if (err)return err;
@@ -5112,6 +5117,7 @@ mlxsw_sp_nexthop_obj_init(struct mlxsw_sp *mlxsw_sp, struct nh_notifier_single_info *nh_obj, int weight) {struct net_device *dev = nh_obj->dev; +struct net *net =dev_net (dev);int err; nh->nhgi = nh_grp->nhgi;
@@ -5120,7 +5126,7 @@ mlxsw_sp_nexthop_obj_init(struct mlxsw_sp *mlxsw_sp,switch (nh_obj->gw_family) {case AF_INET :memcpy (&nh->gw_addr, &nh_obj->ipv4,sizeof (nh_obj->ipv4)); - nh->neigh_tbl = &arp_tbl; + nh->neigh_tbl =arp_table (net);break ;case AF_INET6 :memcpy (&nh->gw_addr, &nh_obj->ipv6,sizeof (nh_obj->ipv6));
drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c +4 -1
@@ -456,6 +456,7 @@ mlxsw_sp_span_entry_gretap4_parms(struct mlxsw_sp *mlxsw_sp,bool inherit_tos = tparm.iph.tos &0x1 ;bool inherit_ttl = !tparm.iph.ttl;union mlxsw_sp_l3addr gw = daddr; +struct neigh_table *tbl =NULL ;struct net_device *l3edev; if (!(to_dev->flags & IFF_UP) ||
@@ -469,9 +470,11 @@ mlxsw_sp_span_entry_gretap4_parms(struct mlxsw_sp *mlxsw_sp,return mlxsw_sp_span_entry_unoffloadable (sparmsp); l3edev =mlxsw_sp_span_gretap4_route (to_dev, &saddr.addr4, &gw.addr4); +if (l3edev) + tbl =arp_table (dev_net (l3edev));return mlxsw_sp_span_entry_tunnel_parms_common (l3edev, saddr, daddr, gw, tparm.iph.ttl, - &arp_tbl, sparmsp); + tbl, sparmsp); } static int
drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c +3 -7
@@ -209,6 +209,7 @@ void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb) {struct nfp_tun_active_tuns *payload;struct net_device *netdev; +struct neigh_table *tbl;int count, i, pay_len;struct neighbour *n;__be32 ipv4_addr;
@@ -235,7 +236,8 @@ void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb)if (!netdev)continue ; - n =neigh_lookup (&arp_tbl, &ipv4_addr, netdev); + tbl =arp_table (dev_net (netdev)); + n =neigh_lookup (tbl, &ipv4_addr, netdev);if (!n)continue ;
@@ -729,12 +731,6 @@ nfp_tun_neigh_event_handler(struct notifier_block *nb, unsigned long event,default :return NOTIFY_DONE ; } -#if IS_ENABLED (CONFIG_IPV6 ) -if (n->tbl != &nd_tbl && n->tbl != &arp_tbl) -#else -if (n->tbl != &arp_tbl) -#endif -return NOTIFY_DONE ; app_priv = container_of(nb, struct nfp_flower_priv, tun.neigh_nb); app = app_priv->app;
drivers/net/ethernet/rocker/rocker_main.c +1 -1
@@ -3134,7 +3134,7 @@ static int rocker_netevent_event(struct notifier_block *unused,switch (event) {case NETEVENT_NEIGH_UPDATE : -if (n->tbl != &arp_tbl) +if (n->tbl !=arp_table (&init_net))return NOTIFY_DONE ; dev = n->dev;if (!rocker_port_dev_check (dev))
drivers/net/ethernet/rocker/rocker_ofdpa.c +1 -1
@@ -1336,7 +1336,7 @@ static int ofdpa_port_ipv4_resolve(struct ofdpa_port *ofdpa_port,int err =0 ;if (!n) { - n =neigh_create (&arp_tbl, &ip_addr, dev); + n =neigh_create (arp_table (&init_net), &ip_addr, dev);if (IS_ERR (n))return PTR_ERR (n); }
drivers/net/ethernet/sfc/tc_counters.c +5 -1
@@ -91,6 +91,7 @@ static void efx_tc_counter_work(struct work_struct *work)struct efx_tc_action_set *act;unsigned long touched;struct neighbour *n; +struct net *net;spin_lock_bh (&cnt->lock); touched =READ_ONCE (cnt->touched);
@@ -103,12 +104,15 @@ static void efx_tc_counter_work(struct work_struct *work)continue ;if (time_after_eq (encap->neigh->used, touched))continue ; + encap->neigh->used = touched; + net = encap->neigh->net; +/* We have passed traffic using this ARP entry, so * indicate to the ARP cache that it's still active */ if (encap->neigh->dst_ip) - n =neigh_lookup (&arp_tbl, &encap->neigh->dst_ip, + n =neigh_lookup (arp_table (net), &encap->neigh->dst_ip, encap->neigh->egdev);else #if IS_ENABLED(CONFIG_IPV6)
drivers/net/ethernet/sfc/tc_encap_actions.c +1 -1
@@ -527,7 +527,7 @@ static int efx_neigh_event(struct efx_nic *efx, struct neighbour *n)if (WARN_ON (!efx->tc))return NOTIFY_DONE ; -if (n->tbl == &arp_tbl) { +if (n->tbl->family ==AF_INET ) { keysize =sizeof (keys.dst_ip);#if IS_ENABLED (CONFIG_IPV6 ) } else if (n->tbl == &nd_tbl) {
drivers/net/vxlan/vxlan_core.c +7 -3
@@ -1841,11 +1841,12 @@ static int vxlan_err_lookup(struct sock *sk, struct sk_buff *skb)static int arp_reduce (struct net_device *dev,struct sk_buff *skb,__be32 vni) { +struct neigh_table *tbl =arp_table (dev_net (dev));struct vxlan_dev *vxlan =netdev_priv (dev); +struct neighbour *n;struct arphdr *parp;u8 *arpptr, *sha;__be32 sip, tip; -struct neighbour *n;if (dev->flags &IFF_NOARP ) goto out;
@@ -1877,7 +1878,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) ipv4_is_multicast(tip)) goto out; - n =neigh_lookup (&arp_tbl, &tip, dev); + n =neigh_lookup (tbl, &tip, dev);if (n) {struct vxlan_rdst *rdst =NULL ;
@@ -2106,6 +2107,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)static bool route_shortcircuit (struct net_device *dev,struct sk_buff *skb) {struct vxlan_dev *vxlan =netdev_priv (dev); +struct neigh_table *tbl;struct neighbour *n;if (is_multicast_ether_addr (eth_hdr (skb)->h_dest))
@@ -2119,8 +2121,10 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb)if (!pskb_network_may_pull (skb,sizeof (struct iphdr )))return false; + + tbl =arp_table (dev_net (dev)); pip =ip_hdr (skb); - n =neigh_lookup (&arp_tbl, &pip->daddr, dev); + n =neigh_lookup (tbl, &pip->daddr, dev);if (!n && (vxlan->cfg.flags &VXLAN_F_L3MISS )) {union vxlan_addr ipa = { .sin.sin_addr.s_addr = pip->daddr,
include/net/arp.h +3 -3
@@ -7,8 +7,6 @@#include <linux/hash.h> #include <net/neighbour.h> -extern struct neigh_table arp_tbl; -static inline struct neigh_table *arp_table (struct net *net) {return net->neigh_tables[NEIGH_ARP_TABLE ];
@@ -25,10 +23,12 @@ static inline u32 arp_hashfn(const void *pkey, const struct net_device *dev, u32#ifdef CONFIG_INET static inline struct neighbour *__ipv4_neigh_lookup_noref (struct net_device *dev,u32 key) { +struct neigh_table *tbl =arp_table (dev_net (dev)); +if (dev->flags & (IFF_LOOPBACK |IFF_POINTOPOINT )) key =INADDR_ANY ; -return ___neigh_lookup_noref (&arp_tbl, neigh_key_eq32, arp_hashfn, &key, dev); +return ___neigh_lookup_noref (tbl, neigh_key_eq32, arp_hashfn, &key, dev); }#else static inline
include/net/route.h +5 -2
@@ -405,8 +405,11 @@ static inline struct neighbour *ip_neigh_gw4(struct net_device *dev,struct neighbour *neigh; neigh =__ipv4_neigh_lookup_noref (dev, (__force u32 )daddr); -if (unlikely (!neigh)) - neigh =__neigh_create (&arp_tbl, &daddr, dev, false); +if (unlikely (!neigh)) { +struct neigh_table *tbl =arp_table (dev_net (dev)); + + neigh =__neigh_create (tbl, &daddr, dev, false); + }return neigh; }
net/bridge/br_arp_nd_proxy.c +1 -1
@@ -193,7 +193,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,return ; } - n =neigh_lookup (&arp_tbl, &tip, vlandev); + n =neigh_lookup (arp_table (dev_net (vlandev)), &tip, vlandev);if (n) {struct net_bridge_fdb_entry *f;u8 ha[ETH_ALEN ]__aligned(2) ;
net/ipv4/arp.c +52 -36
255 lines not on this page · raw message
net/ipv4/devinet.c +10 -8
@@ -265,7 +265,9 @@ EXPORT_SYMBOL(in_dev_finish_destroy);static struct in_device *inetdev_init (struct net_device *dev) { +struct net *net =dev_net (dev);struct in_device *in_dev; +struct neigh_table *tbl;int err = -ENOMEM ;ASSERT_RTNL ();
@@ -273,11 +275,12 @@ static struct in_device *inetdev_init(struct net_device *dev) in_dev =kzalloc_obj (*in_dev);if (!in_dev) goto out; -memcpy (&in_dev->cnf,dev_net (dev)->ipv4.devconf_dflt, -sizeof (in_dev->cnf)); + + tbl =arp_table (net); +memcpy (&in_dev->cnf, net->ipv4.devconf_dflt,sizeof (in_dev->cnf)); in_dev->cnf.sysctl =NULL ; in_dev->dev = dev; - in_dev->arp_parms =neigh_parms_alloc (dev, &arp_tbl); + in_dev->arp_parms =neigh_parms_alloc (dev, tbl);if (!in_dev->arp_parms) goto out_kfree;if (IPV4_DEVCONF (in_dev->cnf,FORWARDING ))
@@ -291,7 +294,7 @@ static struct in_device *inetdev_init(struct net_device *dev) err =devinet_sysctl_register (in_dev);if (err) { in_dev->dead =1 ; -neigh_parms_release (&arp_tbl, in_dev->arp_parms); +neigh_parms_release (tbl, in_dev->arp_parms);in_dev_put (in_dev); in_dev =NULL ; goto out;
@@ -313,13 +316,12 @@ static struct in_device *inetdev_init(struct net_device *dev)static void inetdev_destroy (struct in_device *in_dev) { -struct net_device *dev; +struct net_device *dev = in_dev->dev; +struct net *net =dev_net (dev);struct in_ifaddr *ifa;ASSERT_RTNL (); - dev = in_dev->dev; - in_dev->dead =1 ;RCU_INIT_POINTER (dev->ip_ptr,NULL );
@@ -332,7 +334,7 @@ static void inetdev_destroy(struct in_device *in_dev) }devinet_sysctl_unregister (in_dev); -neigh_parms_release (&arp_tbl, in_dev->arp_parms); +neigh_parms_release (arp_table (net), in_dev->arp_parms);arp_ifdown (dev);in_dev_put (in_dev);
net/ipv4/fib_semantics.c +3 -2
@@ -610,11 +610,12 @@ static int fib_detect_death(struct fib_info *fi, int order, int dflt) {const struct fib_nh_common *nhc =fib_info_nhc (fi,0 ); -struct neighbour *n; +struct net *net = fi->fib_net;int state =NUD_NONE ; +struct neighbour *n;if (likely (nhc->nhc_gw_family ==AF_INET )) - n =neigh_lookup (&arp_tbl, &nhc->nhc_gw.ipv4, nhc->nhc_dev); + n =neigh_lookup (arp_table (net), &nhc->nhc_gw.ipv4, nhc->nhc_dev);else if (IS_ENABLED (CONFIG_IPV6 ) && nhc->nhc_gw_family ==AF_INET6 ) n =neigh_lookup (&nd_tbl, &nhc->nhc_gw.ipv6, nhc->nhc_dev);else
net/ipv4/route.c +1 -1
@@ -817,7 +817,7 @@ static void __ip_do_redirect(struct rtable *rt, struct sk_buff *skb, struct flow n =__ipv4_neigh_lookup (rt->dst.dev, (__force u32 )new_gw);if (!n) - n =neigh_create (&arp_tbl, &new_gw, rt->dst.dev); + n =neigh_create (arp_table (net), &new_gw, rt->dst.dev);if (!IS_ERR (n)) {if (!(READ_ONCE (n->nud_state) &NUD_VALID )) {neigh_event_send (n,NULL );
Signature · 1 line
2.55.0.966.g6673acef38-goog
PATCH v5 9/15 ipv6: Replace &nd_tbl with nd_table(net).
In reply to Kuniyuki IwashimaWe will allocate per-netns neigh_table in net->neigh_tables[].
Let's replace &nd_tbl with nd_table(net).
---
Cc: Saeed Mahameed <[email protected]>
Cc: Leon Romanovsky <[email protected]>
Cc: Tariq Toukan <[email protected]>
Cc: Mark Bloch <[email protected]>
Cc: Petr Machata <[email protected]>
Cc: Edward Cree <[email protected]>
Cc: Alexander Aring <[email protected]>
Cc: Stefan Schmidt <[email protected]>
Cc: Miquel Raynal <[email protected]>
--- .../mellanox/mlx5/core/en/rep/neigh.c | 7 +- .../mellanox/mlx5/core/en/tc_tun_encap.c | 2 +- .../ethernet/mellanox/mlxsw/spectrum_router.c | 13 ++- .../ethernet/mellanox/mlxsw/spectrum_span.c | 5 +- .../netronome/nfp/flower/tunnel_conf.c | 4 +- drivers/net/ethernet/sfc/tc_counters.c | 2 +- drivers/net/ethernet/sfc/tc_encap_actions.c | 2 +- drivers/net/vrf.c | 2 +- drivers/net/vxlan/vxlan_core.c | 6 +- include/net/ndisc.h | 11 ++- net/bridge/br_arp_nd_proxy.c | 2 +- net/ieee802154/6lowpan/tx.c | 3 +- net/ipv4/fib_semantics.c | 2 +- net/ipv6/addrconf.c | 17 ++-- net/ipv6/ip6_output.c | 4 +- net/ipv6/ndisc.c | 91 ++++++++++--------- net/ipv6/route.c | 18 ++-- 17 files changed, 112 insertions(+), 79 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c +4 -3
@@ -17,26 +17,27 @@#include "fs_core.h" #include "diag/en_rep_tracepoint.h" -static unsigned long mlx5e_rep_ipv6_interval (void ) +static unsigned long mlx5e_rep_ipv6_interval (struct net *net) {if (IS_ENABLED (CONFIG_IPV6 ) &&ipv6_mod_enabled ()) -return NEIGH_VAR (&nd_tbl.parms,DELAY_PROBE_TIME ); +return NEIGH_VAR (&nd_table (net)->parms,DELAY_PROBE_TIME );return ~0UL ; }static void mlx5e_rep_neigh_update_init_interval (struct mlx5e_rep_priv *rpriv) { -unsigned long ipv6_interval =mlx5e_rep_ipv6_interval ();struct net_device *netdev = rpriv->netdev;struct net *net =dev_net (netdev);unsigned long ipv4_interval; +unsigned long ipv6_interval;struct neigh_table *tbl;struct mlx5e_priv *priv; priv =netdev_priv (netdev); tbl =arp_table (net); ipv4_interval =NEIGH_VAR (&tbl->parms,DELAY_PROBE_TIME ); + ipv6_interval =mlx5e_rep_ipv6_interval (net); rpriv->neigh_update.min_interval = min_t(unsigned long, ipv6_interval, ipv4_interval);mlx5_fc_update_sampling_interval (priv->mdev, rpriv->neigh_update.min_interval);
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +1 -1
@@ -445,7 +445,7 @@ void mlx5e_tc_update_neigh_used_value(struct mlx5e_neigh_hash_entry *nhe)#if IS_ENABLED (CONFIG_IPV6 )if (m_neigh->family !=AF_INET ) - tbl = &nd_tbl; + tbl =nd_table (net); else#endif tbl =arp_table (net);
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +8 -5
@@ -2403,7 +2403,7 @@ mlxsw_sp_router_neighs_update_interval_init(struct mlxsw_sp *mlxsw_sp)#if IS_ENABLED (CONFIG_IPV6 ) interval = min_t(unsigned long,NEIGH_VAR (&arp_table (net)->parms,DELAY_PROBE_TIME ), -NEIGH_VAR (&nd_tbl.parms,DELAY_PROBE_TIME )); +NEIGH_VAR (&nd_table (net)->parms,DELAY_PROBE_TIME ));#else interval =NEIGH_VAR (&arp_table (net)->parms,DELAY_PROBE_TIME );#endif
@@ -2449,6 +2449,8 @@ static void mlxsw_sp_router_neigh_ent_ipv6_process(struct mlxsw_sp *mlxsw_sp, char *rauhtd_pl, int rec_index) { +struct net *net =mlxsw_sp_net (mlxsw_sp); +struct neigh_table *tbl;struct net_device *dev;struct neighbour *n;struct in6_addr dip;
@@ -2462,8 +2464,9 @@ static void mlxsw_sp_router_neigh_ent_ipv6_process(struct mlxsw_sp *mlxsw_sp,return ; } + tbl =nd_table (net); dev =mlxsw_sp_rif_dev (mlxsw_sp->router->rifs[rif]); - n =neigh_lookup (&nd_tbl, &dip, dev); + n =neigh_lookup (tbl, &dip, dev);if (!n)return ;
@@ -3028,7 +3031,7 @@ static int mlxsw_sp_neigh_rif_made_sync(struct mlxsw_sp *mlxsw_sp, goto err_arp;#if IS_ENABLED (CONFIG_IPV6 ) -neigh_for_each (&nd_tbl, mlxsw_sp_neigh_rif_made_sync_each, &rms); +neigh_for_each (nd_table (net), mlxsw_sp_neigh_rif_made_sync_each, &rms);#endif if (rms.err) goto err_nd;
@@ -5131,7 +5134,7 @@ mlxsw_sp_nexthop_obj_init(struct mlxsw_sp *mlxsw_sp,case AF_INET6 :memcpy (&nh->gw_addr, &nh_obj->ipv6,sizeof (nh_obj->ipv6));#if IS_ENABLED (CONFIG_IPV6 ) - nh->neigh_tbl = &nd_tbl; + nh->neigh_tbl =nd_table (net);#endif break ; }
@@ -6987,7 +6990,7 @@ static int mlxsw_sp_nexthop6_init(struct mlxsw_sp *mlxsw_sp, nh->nh_weight = rt->fib6_nh->fib_nh_weight;memcpy (&nh->gw_addr, &rt->fib6_nh->fib_nh_gw6,sizeof (nh->gw_addr));#if IS_ENABLED (CONFIG_IPV6 ) - nh->neigh_tbl = &nd_tbl; + nh->neigh_tbl =nd_table (mlxsw_sp_net (mlxsw_sp));#endif err =mlxsw_sp_nexthop_counter_enable (mlxsw_sp, nh);
drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c +4 -1
@@ -564,6 +564,7 @@ mlxsw_sp_span_entry_gretap6_parms(struct mlxsw_sp *mlxsw_sp,union mlxsw_sp_l3addr daddr = { .addr6 = tparm.raddr };bool inherit_ttl = !tparm.hop_limit;union mlxsw_sp_l3addr gw = daddr; +struct neigh_table *tbl =NULL ;struct net_device *l3edev; if (!(to_dev->flags & IFF_UP) ||
@@ -577,9 +578,11 @@ mlxsw_sp_span_entry_gretap6_parms(struct mlxsw_sp *mlxsw_sp,return mlxsw_sp_span_entry_unoffloadable (sparmsp); l3edev =mlxsw_sp_span_gretap6_route (to_dev, &saddr.addr6, &gw.addr6); +if (l3edev) + tbl =nd_table (dev_net (l3edev));return mlxsw_sp_span_entry_tunnel_parms_common (l3edev, saddr, daddr, gw, tparm.hop_limit, - &nd_tbl, sparmsp); + tbl, sparmsp); } static int
drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c +3 -1
@@ -253,6 +253,7 @@ void nfp_tunnel_keep_alive_v6(struct nfp_app *app, struct sk_buff *skb)#if IS_ENABLED (CONFIG_IPV6 )struct nfp_tun_active_tuns_v6 *payload;struct net_device *netdev; +struct neigh_table *tbl;int count, i, pay_len;struct neighbour *n;void *ipv6_add;
@@ -279,7 +280,8 @@ void nfp_tunnel_keep_alive_v6(struct nfp_app *app, struct sk_buff *skb)if (!netdev)continue ; - n =neigh_lookup (&nd_tbl, ipv6_add, netdev); + tbl =nd_table (dev_net (netdev)); + n =neigh_lookup (tbl, ipv6_add, netdev);if (!n)continue ;
drivers/net/ethernet/sfc/tc_counters.c +1 -1
@@ -116,7 +116,7 @@ static void efx_tc_counter_work(struct work_struct *work) encap->neigh->egdev); else #if IS_ENABLED(CONFIG_IPV6) - n =neigh_lookup (&nd_tbl, + n =neigh_lookup (nd_table (net), &encap->neigh->dst_ip6, encap->neigh->egdev);#else
drivers/net/ethernet/sfc/tc_encap_actions.c +1 -1
@@ -530,7 +530,7 @@ static int efx_neigh_event(struct efx_nic *efx, struct neighbour *n)if (n->tbl->family ==AF_INET ) { keysize =sizeof (keys.dst_ip);#if IS_ENABLED (CONFIG_IPV6 ) - } else if (n->tbl == &nd_tbl) { + } else if (n->tbl->family == AF_INET6) { ipv6 = true; keysize =sizeof (keys.dst_ip6);#endif
drivers/net/vrf.c +1 -1
@@ -616,7 +616,7 @@ static int vrf_finish_output6(struct net *net, struct sock *sk, nexthop =rt6_nexthop (dst_rt6_info (dst), &ipv6_hdr (skb)->daddr); neigh =__ipv6_neigh_lookup_noref (dst->dev, nexthop);if (unlikely (!neigh)) - neigh =__neigh_create (&nd_tbl, nexthop, dst->dev, false); + neigh =__neigh_create (nd_table (net), nexthop, dst->dev, false);if (!IS_ERR (neigh)) {sock_confirm_neigh (skb, neigh); ret =neigh_output (neigh, skb, false);
drivers/net/vxlan/vxlan_core.c +4 -2
@@ -2052,7 +2052,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) ipv6_addr_is_multicast(&msg->target)) goto out; - n =neigh_lookup (&nd_tbl, &msg->target, dev); + n =neigh_lookup (nd_table (dev_net (dev)), &msg->target, dev);if (n) {struct vxlan_rdst *rdst =NULL ;
@@ -2149,8 +2149,10 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb)return false;if (!pskb_network_may_pull (skb,sizeof (struct ipv6hdr )))return false; + + tbl =nd_table (dev_net (dev)); pip6 =ipv6_hdr (skb); - n =neigh_lookup (&nd_tbl, &pip6->daddr, dev); + n =neigh_lookup (tbl, &pip6->daddr, dev);if (!n && (vxlan->cfg.flags &VXLAN_F_L3MISS )) {union vxlan_addr ipa = { .sin6.sin6_addr = pip6->daddr,
include/net/ndisc.h +8 -3
@@ -363,7 +363,9 @@ static inline u32 ndisc_hashfn(const void *pkey, const struct net_device *dev, _static inline struct neighbour *__ipv6_neigh_lookup_noref (struct net_device *dev,const void *pkey) { -return ___neigh_lookup_noref (&nd_tbl, neigh_key_eq128, ndisc_hashfn, pkey, dev); +struct neigh_table *tbl =nd_table (dev_net (dev)); + +return ___neigh_lookup_noref (tbl, neigh_key_eq128, ndisc_hashfn, pkey, dev); }static inline struct neighbour *__ipv6_neigh_lookup (struct net_device *dev,const void *pkey)
@@ -397,8 +399,11 @@ static inline struct neighbour *ip_neigh_gw6(struct net_device *dev,struct neighbour *neigh; neigh =__ipv6_neigh_lookup_noref (dev, addr); -if (unlikely (!neigh)) - neigh =__neigh_create (&nd_tbl, addr, dev, false); +if (unlikely (!neigh)) { +struct neigh_table *tbl =nd_table (dev_net (dev)); + + neigh =__neigh_create (tbl, addr, dev, false); + }return neigh;#else
net/bridge/br_arp_nd_proxy.c +1 -1
@@ -470,7 +470,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,return ; } - n =neigh_lookup (&nd_tbl, &msg->target, vlandev); + n =neigh_lookup (nd_table (dev_net (vlandev)), &msg->target, vlandev);if (n) {struct net_bridge_fdb_entry *f;u8 ha[ETH_ALEN ]__aligned(2) ;
net/ieee802154/6lowpan/tx.c +2 -1
@@ -58,8 +58,9 @@ int lowpan_header_create(struct sk_buff *skb, struct net_device *ldev, info->daddr.mode =IEEE802154_ADDR_SHORT ; }else {__le16 short_addr =cpu_to_le16 (IEEE802154_ADDR_SHORT_UNSPEC ); +struct neigh_table *tbl =nd_table (dev_net (ldev)); - n =neigh_lookup (&nd_tbl, &hdr->daddr, ldev); + n =neigh_lookup (tbl, &hdr->daddr, ldev);if (n) { llneigh =lowpan_802154_neigh (neighbour_priv (n));read_lock_bh (&n->lock);
net/ipv4/fib_semantics.c +1 -1
@@ -617,7 +617,7 @@ static int fib_detect_death(struct fib_info *fi, int order,if (likely (nhc->nhc_gw_family ==AF_INET )) n =neigh_lookup (arp_table (net), &nhc->nhc_gw.ipv4, nhc->nhc_dev);else if (IS_ENABLED (CONFIG_IPV6 ) && nhc->nhc_gw_family ==AF_INET6 ) - n =neigh_lookup (&nd_tbl, &nhc->nhc_gw.ipv6, nhc->nhc_dev); + n =neigh_lookup (nd_table (net), &nhc->nhc_gw.ipv6, nhc->nhc_dev);else n =NULL ;
net/ipv6/addrconf.c +11 -6
@@ -376,6 +376,8 @@ static int snmp6_alloc_dev(struct inet6_dev *idev)static struct inet6_dev *ipv6_add_dev (struct net_device *dev) { +struct net *net =dev_net (dev); +struct neigh_table *tbl;struct inet6_dev *ndev;int err = -ENOMEM ;
@@ -393,14 +395,15 @@ static struct inet6_dev *ipv6_add_dev(struct net_device *dev) ndev->dev = dev;INIT_LIST_HEAD (&ndev->addr_list);timer_setup (&ndev->rs_timer, addrconf_rs_timer,0 ); -memcpy (&ndev->cnf,dev_net (dev)->ipv6.devconf_dflt,sizeof (ndev->cnf)); +memcpy (&ndev->cnf, net->ipv6.devconf_dflt,sizeof (ndev->cnf));if (ndev->cnf.stable_secret.initialized) ndev->cnf.addr_gen_mode =IN6_ADDR_GEN_MODE_STABLE_PRIVACY ; + tbl =nd_table (net); ndev->cnf.mtu6 = dev->mtu; ndev->ra_mtu =0 ; - ndev->nd_parms =neigh_parms_alloc (dev, &nd_tbl); + ndev->nd_parms =neigh_parms_alloc (dev, tbl);if (!ndev->nd_parms) {kfree (ndev);return ERR_PTR (err);
@@ -413,7 +416,7 @@ static struct inet6_dev *ipv6_add_dev(struct net_device *dev)if (snmp6_alloc_dev (ndev) <0 ) {netdev_dbg (dev,"%s: cannot allocate memory for statistics\n" , __func__); -neigh_parms_release (&nd_tbl, ndev->nd_parms); +neigh_parms_release (tbl, ndev->nd_parms);netdev_put (dev, &ndev->dev_tracker);kfree (ndev);return ERR_PTR (err);
@@ -481,7 +484,7 @@ static struct inet6_dev *ipv6_add_dev(struct net_device *dev)return ndev; err_release: -neigh_parms_release (&nd_tbl, ndev->nd_parms); +neigh_parms_release (tbl, ndev->nd_parms); ndev->dead =1 ;in6_dev_finish_destroy (ndev);return ERR_PTR (err);
@@ -4039,9 +4042,11 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister)/* Last: Shot the device (if unregistered) */ if (unregister) { +struct neigh_table *tbl =nd_table (net); +addrconf_sysctl_unregister (idev); -neigh_parms_release (&nd_tbl, idev->nd_parms); -neigh_ifdown (&nd_tbl, dev); +neigh_parms_release (tbl, idev->nd_parms); +neigh_ifdown (tbl, dev);in6_dev_put (idev); }return 0 ;
net/ipv6/ip6_output.c +2 -2
@@ -127,7 +127,7 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *if (IS_ERR_OR_NULL (neigh)) {if (unlikely (!neigh)) - neigh =__neigh_create (&nd_tbl, nexthop, dev, false); + neigh =__neigh_create (nd_table (net), nexthop, dev, false);if (IS_ERR (neigh)) {IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTNOROUTES );kfree_skb_reason (skb,SKB_DROP_REASON_NEIGH_CREATEFAIL );
@@ -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_tbl, net, &hdr->daddr, skb->dev)) { +pneigh_lookup (nd_table (net), net, &hdr->daddr, skb->dev)) {int proxied =ip6_forward_proxy_check (skb); hdr =ipv6_hdr (skb);
net/ipv6/ndisc.c +50 -41
264 lines not on this page · raw message
net/ipv6/route.c +10 -8
@@ -217,7 +217,7 @@ struct neighbour *ip6_neigh_lookup(const struct in6_addr *gw,if (n)return n; - n =neigh_create (&nd_tbl, daddr, dev); + n =neigh_create (nd_table (dev_net (dev)), daddr, dev);return IS_ERR (n) ?NULL : n; }
@@ -4241,6 +4241,7 @@ static int ip6_route_del(struct fib6_config *cfg,static void rt6_do_redirect (struct dst_entry *dst,struct sock *sk,struct sk_buff *skb) {struct netevent_redirect netevent; +struct net_device *dev = skb->dev;struct rt6_info *rt, *nrt =NULL ;struct fib6_result res = {};struct ndisc_options ndopts;
@@ -4274,7 +4275,7 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bureturn ; } - in6_dev =__in6_dev_get (skb->dev); + in6_dev =__in6_dev_get (dev);if (!in6_dev)return ; if (READ_ONCE(in6_dev->cnf.forwarding) ||
@@ -4286,15 +4287,14 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu* first-hop router for the specified ICMP Destination Address. */ -if (!ndisc_parse_options (skb->dev, msg->opt, optlen, &ndopts)) { +if (!ndisc_parse_options (dev, msg->opt, optlen, &ndopts)) {net_dbg_ratelimited ("rt6_redirect: invalid ND options\n" );return ; } lladdr =NULL ;if (ndopts.nd_opts_tgt_lladdr) { - lladdr =ndisc_opt_addr_data (ndopts.nd_opts_tgt_lladdr, - skb->dev); + lladdr =ndisc_opt_addr_data (ndopts.nd_opts_tgt_lladdr, dev);if (!lladdr) {net_dbg_ratelimited ("rt6_redirect: invalid link-layer address length\n" );return ;
@@ -4313,7 +4313,7 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu*/ dst_confirm_neigh (&rt->dst, &ipv6_hdr (skb)->saddr); - neigh =__neigh_lookup (&nd_tbl, &msg->target, skb->dev,1 ); + neigh =__neigh_lookup (nd_table (dev_net (dev)), &msg->target, dev,1 );if (!neigh)return ;
@@ -4321,7 +4321,7 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu* We have finally decided to accept it. */ - ndisc_update(skb->dev, neigh, lladdr, NUD_STALE, + ndisc_update(dev, neigh, lladdr, NUD_STALE, NEIGH_UPDATE_F_WEAK_OVERRIDE| NEIGH_UPDATE_F_OVERRIDE| (on_link ? 0 : (NEIGH_UPDATE_F_OVERRIDE_ISROUTER|
@@ -5042,9 +5042,11 @@ void rt6_sync_down_dev(struct net_device *dev, unsigned long event)void rt6_disable_ip (struct net_device *dev,unsigned long event) { +struct net *net =dev_net (dev); +rt6_sync_down_dev (dev, event);rt6_uncached_list_flush_dev (dev); -neigh_ifdown (&nd_tbl, dev); +neigh_ifdown (nd_table (net), dev); }struct rt6_mtu_change_arg {
Signature · 1 line
2.55.0.966.g6673acef38-goog
PATCH v5 10/15 neighbour: Clean up neigh_table_init() and neigh_table_clear().
In reply to Kuniyuki IwashimaCurrently, neigh_table_init() and neigh_table_clear() are called once at the boot time, but we will call them for each netns.
Let's clean up them.
For neigh_table_init(),
* Allocate all memory first and unwind on failure
* Remove !tbl->entry_size check since it is always true for arp_tbl and nd_tbl
* Initialise everything before starting delayed works
For neigh_table_clear(),
* Reorder function to match neigh_table_init()
* Use timer_shutdown_sync() instead of timer_delete_sync()
* Remove pneigh_queue_purge() since it is called via neigh_ifdown()
* Replace pr_crit() with DEBUG_NET_WARN_ON_ONCE()
* Call neigh_hash_free_rcu() directly without call_rcu()
In a later patch, neigh_table_clear() will be split so that tbl->{stats,phash_buckets,nht} will be freed only when all neighbour entries are freed.
---
v2: Add __maybe_unused to net in neigh_table_clear() to
avoid transient W=1 warning for CONFIG_PROC_FS=n (next patch removes it anyway)
--- net/core/neighbour.c | 98 +++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 43 deletions(-)
net/core/neighbour.c +55 -43
@@ -1810,57 +1810,68 @@ static struct lock_class_key neigh_table_proxy_queue_class;void neigh_table_init (struct neigh_table *tbl) {unsigned long now = jiffies; +struct net *net = &init_net;unsigned long phsize; -INIT_LIST_HEAD (&tbl->parms_list); -INIT_LIST_HEAD (&tbl->gc_list); -INIT_LIST_HEAD (&tbl->managed_list); +RCU_INIT_POINTER (tbl->nht,neigh_hash_alloc (3 )); +if (!tbl->nht) + goto err_hash; -list_add (&tbl->parms.list, &tbl->parms_list); -write_pnet (&tbl->parms.net, &init_net); -refcount_set (&tbl->parms.refcnt,1 ); -neigh_set_reach_time (&tbl->parms); - tbl->parms.qlen =0 ; + phsize = (PNEIGH_HASHMASK +1 ) *sizeof (struct pneigh_entry *); + tbl->phash_buckets =kzalloc (phsize,GFP_KERNEL ); +if (!tbl->phash_buckets) + goto err_phash; + + tbl->entry_size =ALIGN (offsetof(struct neighbour , primary_key) + + tbl->key_len,NEIGH_PRIV_ALIGN ); tbl->stats = alloc_percpu(struct neigh_statistics);if (!tbl->stats) -panic ("cannot create neighbour cache statistics" ); + goto err_stats;#ifdef CONFIG_PROC_FS -if (!proc_create_seq_data (tbl->id,0 , init_net.proc_net_stat, - &neigh_stat_seq_ops, tbl)) -panic ("cannot create neighbour proc dir entry" ); +if (!proc_create_seq_data (tbl->id,0 , net->proc_net_stat, + &neigh_stat_seq_ops, tbl)) + goto err_proc;#endif -RCU_INIT_POINTER (tbl->nht,neigh_hash_alloc (3 )); - - phsize = (PNEIGH_HASHMASK +1 ) *sizeof (struct pneigh_entry *); - tbl->phash_buckets =kzalloc (phsize,GFP_KERNEL ); - -if (!tbl->nht || !tbl->phash_buckets) -panic ("cannot allocate neighbour cache hashes" ); - -if (!tbl->entry_size) - tbl->entry_size =ALIGN (offsetof(struct neighbour , primary_key) + - tbl->key_len,NEIGH_PRIV_ALIGN ); -else -WARN_ON (tbl->entry_size %NEIGH_PRIV_ALIGN ); + tbl->parms.tbl = tbl; + tbl->parms.qlen =0 ; +INIT_LIST_HEAD (&tbl->parms_list); +list_add (&tbl->parms.list, &tbl->parms_list); +write_pnet (&tbl->parms.net, net); +refcount_set (&tbl->parms.refcnt,1 ); +neigh_set_reach_time (&tbl->parms); + tbl->last_flush = now; + tbl->last_rand = now + tbl->parms.reachable_time *20 ;spin_lock_init (&tbl->lock);mutex_init (&tbl->phash_lock); +skb_queue_head_init_class (&tbl->proxy_queue, + &neigh_table_proxy_queue_class); +timer_setup (&tbl->proxy_timer, neigh_proxy_process,0 ); +INIT_LIST_HEAD (&tbl->gc_list);INIT_DEFERRABLE_WORK (&tbl->gc_work, neigh_periodic_work);queue_delayed_work (system_power_efficient_wq, &tbl->gc_work, - tbl->parms.reachable_time); + tbl->parms.reachable_time); + +INIT_LIST_HEAD (&tbl->managed_list);INIT_DEFERRABLE_WORK (&tbl->managed_work, neigh_managed_work);queue_delayed_work (system_power_efficient_wq, &tbl->managed_work,0 ); -timer_setup (&tbl->proxy_timer, neigh_proxy_process,0 ); -skb_queue_head_init_class (&tbl->proxy_queue, - &neigh_table_proxy_queue_class); +return ; - tbl->last_flush = now; - tbl->last_rand = now + tbl->parms.reachable_time *20 ; +#ifdef CONFIG_PROC_FS +err_proc: +free_percpu (tbl->stats); +#endif +err_stats: +kfree (tbl->phash_buckets); +err_phash: +neigh_hash_free_rcu (&rcu_dereference_protected (tbl->nht,1 )->rcu); +err_hash: +panic ("cannot allocate memory" ); }/*
@@ -1869,26 +1880,27 @@ void neigh_table_init(struct neigh_table *tbl)*/ int neigh_table_clear (struct neigh_table *tbl) { -/* It is not clean... Fix it to unload IPv6 module safely */ +struct net *net__maybe_unused = &init_net; +struct neigh_hash_table *nht; +cancel_delayed_work_sync (&tbl->managed_work);cancel_delayed_work_sync (&tbl->gc_work); -timer_delete_sync (&tbl->proxy_timer); -pneigh_queue_purge (&tbl->proxy_queue,NULL , tbl->family); +timer_shutdown_sync (&tbl->proxy_timer); +neigh_ifdown (tbl,NULL ); -if (atomic_read (&tbl->entries)) -pr_crit ("neighbour leakage\n" ); +DEBUG_NET_WARN_ON_ONCE (atomic_read (&tbl->entries)); -call_rcu (&rcu_dereference_protected (tbl->nht,1 )->rcu, - neigh_hash_free_rcu); - tbl->nht =NULL ; +remove_proc_entry (tbl->id, net->proc_net_stat); + +free_percpu (tbl->stats); + tbl->stats =NULL ;kfree (tbl->phash_buckets); tbl->phash_buckets =NULL ; -remove_proc_entry (tbl->id, init_net.proc_net_stat); - -free_percpu (tbl->stats); - tbl->stats =NULL ; + nht =rcu_dereference_protected (tbl->nht,1 ); + tbl->nht =NULL ; +neigh_hash_free_rcu (&nht->rcu);return 0 ; }
Signature · 1 line
2.55.0.966.g6673acef38-goog
PATCH v5 11/15 neighbour: Convert neigh_table.entries to refcount_t.
In reply to Kuniyuki IwashimaWe will allocate neigh_table for each netns and free it when netns is destroyed.
neigh_ifdown() cleans up all neighbour entries during netns dismantle, but there is no synchronisation between timers because neigh_del_timer() uses timer_delete() to stop a timer.
If neigh_table were freed while timer were running, neigh_destroy() would touch the freed table.
If we called timer_delete_sync() in neigh_flush_one() under tbl->lock, lockdep would complain although it is false-positive.
Let's convert neigh_table.entries to refcount_t and destruct neigh_table only when the count reaches 0.
--- include/net/neighbour.h | 2 +- net/core/neighbour.c | 58 ++++++++++++++++++++++++++++------------- 2 files changed, 41 insertions(+), 19 deletions(-)
include/net/neighbour.h +1 -1
@@ -234,7 +234,7 @@ struct neigh_table {struct delayed_work managed_work;struct timer_list proxy_timer;struct sk_buff_head proxy_queue; -atomic_t entries; +refcount_t entries;atomic_t gc_entries;struct list_head gc_list;struct list_head managed_list;
net/core/neighbour.c +40 -18
126 lines not on this page · raw message
Signature · 1 line
2.55.0.966.g6673acef38-goog
PATCH v5 12/15 neighbour: Namespacify neigh_tables.
In reply to Kuniyuki IwashimaNow, neigh_table is ready to be namespacified.
Let's allocate per-netns neigh_table in neigh_table_register() and call neigh_table_init() and neigh_sysctl_register() for it.
proc_create_seq_data() is changed to proc_create_net_data().
Since each netns has its own sysctl knobs, RTM_SETNEIGHTBL can configure the default table param (ifindex==0) and GC parameters per netns.
To avoid potential regression, all the default parameters under /proc/sys/net/ipv{4,6}/neigh/default/, are inherited from init_net by default.
This behaviour is controlled by a new sysctl knob, net.core.neigh_inherit_init_net:
# sysctl net.core.neigh_inherit_init_net net.core.neigh_inherit_init_net = 1 # sysctl net.ipv4.neigh.default.gc_thresh1 net.ipv4.neigh.default.gc_thresh1 = 128 # sysctl net.ipv4.neigh.default.gc_thresh1=129 net.ipv4.neigh.default.gc_thresh1 = 129 # unshare -n sysctl net.ipv4.neigh.default.gc_thresh1 net.ipv4.neigh.default.gc_thresh1 = 129
If it is turned off, all settings are reset in the new netns:
# sysctl net.core.neigh_inherit_init_net=0 net.core.neigh_inherit_init_net = 0 # unshare -n sysctl net.ipv4.neigh.default.gc_thresh1 net.ipv4.neigh.default.gc_thresh1 = 128
The next patch will remove other unnecessary net_eq().
Note that CONFIG_SYSCTL cannot be enabled without CONFIG_PROC_FS.
---
v4:
* Add sysctl knob, net.core.neigh_inherit_init_net
* Inherit all neigh parms by default
* Move RTM_SETNEIGHTBL changes from patch 14
v3:
* Remove timer_shutdown_sync() in neigh_flush_one() and
rely on tbl->entries to free it in neigh_table_free().
v2:
* panic() when register_pernet_subsys(&arp_net_ops) fails
* Add timer_shutdown_sync() in neigh_flush_one()
--- Documentation/admin-guide/sysctl/net.rst | 14 +++++ include/net/neighbour.h | 4 +- net/core/neighbour.c | 79 ++++++++++++++++-------- net/core/sysctl_net_core.c | 12 ++++ net/ipv4/arp.c | 20 ++++-- net/ipv6/ndisc.c | 43 +++++-------- 6 files changed, 112 insertions(+), 60 deletions(-)
Documentation/admin-guide/sysctl/net.rst +14 -0
@@ -413,6 +413,20 @@ new netns has been created. Default : 0 (for compatibility reasons) +neigh_inherit_init_net +---------------------- + +Controls if a new network namespace should inherit all current +settings under /proc/sys/net/ipv{4,6}/neigh/default/. + +By default, the value is set to 1, and all settings are inherited +from init_net. + +If set to 0, both IPv4 and IPv6 settings are reset to their default +values. + +Default : 1 (for compatibility reasons) + txrehash --------
include/net/neighbour.h +2 -2
@@ -31,6 +31,8 @@#include <net/rtnetlink.h> #include <net/neighbour_tables.h> +extern int sysctl_neigh_inherit_init_net; +/* * NUD stands for "neighbor unreachability detection" */
@@ -341,8 +343,6 @@ static inline void neigh_confirm(struct neighbour *n)int neigh_table_register (struct net *net,struct neigh_table *tbl,int index);void neigh_table_unregister (struct net *net,int index); -void neigh_table_init (struct neigh_table *tbl); -int neigh_table_clear (struct neigh_table *tbl);struct neighbour *neigh_lookup (struct neigh_table *tbl,const void *pkey,struct net_device *dev); struct neighbour *__neigh_create(struct neigh_table *tbl, const void *pkey,
net/core/neighbour.c +54 -25
155 lines not on this page · raw message
net/core/sysctl_net_core.c +12 -0
@@ -21,6 +21,7 @@#include <net/ip.h> #include <net/sock.h> +#include <net/neighbour.h> #include <net/net_ratelimit.h> #include <net/busy_poll.h> #include <net/pkt_sched.h>
@@ -53,6 +54,8 @@ EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net);int sysctl_devconf_inherit_init_net__read_mostly ;EXPORT_SYMBOL (sysctl_devconf_inherit_init_net); +int sysctl_neigh_inherit_init_net__read_mostly =1 ; +#if IS_ENABLED (CONFIG_NET_FLOW_LIMIT ) ||IS_ENABLED (CONFIG_RPS )static int dump_cpumask (void *buffer,size_t *lenp,loff_t *ppos,struct cpumask *mask)
@@ -676,6 +679,15 @@ static struct ctl_table net_core_table[] = { .proc_handler = proc_do_skb_defer_max, .extra1 = SYSCTL_ZERO, }, + { + .procname = "neigh_inherit_init_net", + .data = &sysctl_neigh_inherit_init_net, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, };static const struct ctl_table netns_core_table[] = {
net/ipv4/arp.c +15 -5
@@ -1518,6 +1518,12 @@ static int __net_init arp_net_init(struct net *net) goto err;#ifdef CONFIG_PROC_FS +#ifdef CONFIG_SYSCTL + err =neigh_sysctl_register (NULL , &arp_table (net)->parms,NULL ); +if (err) + goto err_sysctl; +#endif +if (!proc_create_net ("arp" ,0444 , net->proc_net, &arp_seq_ops,sizeof (struct neigh_seq_state ))) { err = -ENOMEM ;
@@ -1529,6 +1535,10 @@ static int __net_init arp_net_init(struct net *net)#ifdef CONFIG_PROC_FS err_proc_create: +#ifdef CONFIG_SYSCTL +neigh_sysctl_unregister (&arp_table (net)->parms); +err_sysctl: +#endif neigh_table_unregister (net,NEIGH_ARP_TABLE );#endif err:
@@ -1538,6 +1548,9 @@ static int __net_init arp_net_init(struct net *net) static void __net_exit arp_net_exit(struct net *net) {remove_proc_entry ("arp" , net->proc_net); +#ifdef CONFIG_SYSCTL +neigh_sysctl_unregister (&arp_table (net)->parms); +#endif neigh_table_unregister (net,NEIGH_ARP_TABLE ); }
@@ -1548,12 +1561,9 @@ static struct pernet_operations arp_net_ops = {void __init arp_init (void ) { -neigh_table_init (&arp_tbl); +if (register_pernet_subsys (&arp_net_ops)) +panic ("Cannot allocate arp table\n" );dev_add_pack (&arp_packet_type); -register_pernet_subsys (&arp_net_ops); -#ifdef CONFIG_SYSCTL -neigh_sysctl_register (NULL , &arp_tbl.parms,NULL ); -#endif register_netdevice_notifier (&arp_netdev_notifier); }
net/ipv6/ndisc.c +15 -28
72 lines not on this page · raw message
Signature · 1 line
2.55.0.966.g6673acef38-goog
Ido Schimmel
maintainerRe: [PATCH v5 net-next 12/15] neighbour: Namespacify neigh_tables.
Quoted 18 lines · Kuniyuki Iwashima
(quoted diff) +17
-0+static void neigh_table_inherit(struct net *net, struct neigh_table *tbl, + int index) +{ + const struct neigh_table *init_tbl = init_net.neigh_tables[index]; + bool inherit = READ_ONCE(sysctl_neigh_inherit_init_net); + int i; + + if (net_eq(net, &init_net) || !inherit) + return; + + tbl->gc_interval = READ_ONCE(init_tbl->gc_interval); + tbl->gc_thresh1 = READ_ONCE(init_tbl->gc_thresh1); + tbl->gc_thresh2 = READ_ONCE(init_tbl->gc_thresh2); + tbl->gc_thresh3 = READ_ONCE(init_tbl->gc_thresh3); + + for (i = 0; i < NEIGH_VAR_DATA_MAX; i++) + tbl->parms.data[i] = READ_ONCE(init_tbl->parms.data[i]); }
[...]
Quoted 13 lines
net/core/sysctl_net_core.c +1
-0@@ -21,6 +21,7 @@#include <net/ip.h> #include <net/sock.h> +#include <net/neighbour.h> #include <net/net_ratelimit.h> #include <net/busy_poll.h> #include <net/pkt_sched.h>
net/core/sysctl_net_core.c EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net); · line 57
Quoted 4 lines
net/core/sysctl_net_core.c +1
-0@@ -53,6 +54,8 @@ EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net);int sysctl_devconf_inherit_init_net__read_mostly ;EXPORT_SYMBOL (sysctl_devconf_inherit_init_net); +int sysctl_neigh_inherit_init_net__read_mostly =1 ;
This fails to build with CONFIG_SYSCTL=n (yes, unlikely config):
$ vng -b /usr/bin/x86_64-linux-gnu-ld.bfd: vmlinux.o: in function `neigh_table_inherit': /home/idosch/.virtme/net/core/neighbour.c:1920:(.text+0xc8ddd9): undefined reference to `sysctl_neigh_inherit_init_net' make[2]: *** [scripts/Makefile.vmlinux:72: vmlinux.unstripped] Error 1 make[1]: *** [/data/idosch/virtme-build/Makefile:1376: vmlinux] Error 2 make: *** [Makefile:248: __sub-make] Error 2
$ grep CONFIG_SYSCTL .config CONFIG_SYSCTL_EXCEPTION_TRACE=y # CONFIG_SYSCTL is not set
Can be fixed with the following diff:
net/core/neighbour.c +2 -0
@@ -1913,6 +1913,8 @@ static void neigh_table_clear(struct net *net, struct neigh_table *tbl)neigh_table_put (tbl); } +int sysctl_neigh_inherit_init_net__read_mostly =1 ; +static void neigh_table_inherit (struct net *net,struct neigh_table *tbl,int index) {
net/core/sysctl_net_core.c +0 -2
@@ -54,8 +54,6 @@ EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net);int sysctl_devconf_inherit_init_net__read_mostly ;EXPORT_SYMBOL (sysctl_devconf_inherit_init_net); -int sysctl_neigh_inherit_init_net__read_mostly =1 ; -#if IS_ENABLED (CONFIG_NET_FLOW_LIMIT ) ||IS_ENABLED (CONFIG_RPS )static int dump_cpumask (void *buffer,size_t *lenp,loff_t *ppos,struct cpumask *mask)
Re: [PATCH v5 net-next 12/15] neighbour: Namespacify neigh_tables.
Quoted 39 lines · Ido Schimmel
Quoted 18 lines · Kuniyuki Iwashima
(quoted diff) +17
-0+static void neigh_table_inherit(struct net *net, struct neigh_table *tbl, + int index) +{ + const struct neigh_table *init_tbl = init_net.neigh_tables[index]; + bool inherit = READ_ONCE(sysctl_neigh_inherit_init_net); + int i; + + if (net_eq(net, &init_net) || !inherit) + return; + + tbl->gc_interval = READ_ONCE(init_tbl->gc_interval); + tbl->gc_thresh1 = READ_ONCE(init_tbl->gc_thresh1); + tbl->gc_thresh2 = READ_ONCE(init_tbl->gc_thresh2); + tbl->gc_thresh3 = READ_ONCE(init_tbl->gc_thresh3); + + for (i = 0; i < NEIGH_VAR_DATA_MAX; i++) + tbl->parms.data[i] = READ_ONCE(init_tbl->parms.data[i]); }[...]
Quoted 16 lines
net/core/sysctl_net_core.c +1
-0@@ -21,6 +21,7 @@#include <net/ip.h> #include <net/sock.h> +#include <net/neighbour.h> #include <net/net_ratelimit.h> #include <net/busy_poll.h> #include <net/pkt_sched.h> @@ -53,6 +54,8 @@ EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net);int sysctl_devconf_inherit_init_net__read_mostly ;EXPORT_SYMBOL (sysctl_devconf_inherit_init_net);
Quoted 3 lines
net/core/sysctl_net_core.c EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net); · line 57
Quoted 1 line
net/core/sysctl_net_core.c +1
-0+int sysctl_neigh_inherit_init_net__read_mostly =1 ;This fails to build with
CONFIG_SYSCTL=n(yes, unlikely config):
Oh, thanks for catching this !
Will squash the diff.
Thanks !
---
pw-bot: cr
Quoted 40 lines
$ vng -b /usr/bin/x86_64-linux-gnu-ld.bfd: vmlinux.o: in function `neigh_table_inherit': /home/idosch/.virtme/net/core/neighbour.c:1920:(.text+0xc8ddd9): undefined reference to `sysctl_neigh_inherit_init_net' make[2]: *** [scripts/Makefile.vmlinux:72: vmlinux.unstripped] Error 1 make[1]: *** [/data/idosch/virtme-build/Makefile:1376: vmlinux] Error 2 make: *** [Makefile:248: __sub-make] Error 2$ grep CONFIG_SYSCTL .config CONFIG_SYSCTL_EXCEPTION_TRACE=y # CONFIG_SYSCTL is not setCan be fixed with the following diff:
net/core/neighbour.c +2
-0@@ -1913,6 +1913,8 @@ static void neigh_table_clear(struct net *net, struct neigh_table *tbl)neigh_table_put (tbl); } +int sysctl_neigh_inherit_init_net__read_mostly =1 ; +static void neigh_table_inherit (struct net *net,struct neigh_table *tbl,int index) {net/core/sysctl_net_core.c +0
-2@@ -54,8 +54,6 @@ EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net);int sysctl_devconf_inherit_init_net__read_mostly ;EXPORT_SYMBOL (sysctl_devconf_inherit_init_net); -int sysctl_neigh_inherit_init_net__read_mostly =1 ; -#if IS_ENABLED (CONFIG_NET_FLOW_LIMIT ) ||IS_ENABLED (CONFIG_RPS )static int dump_cpumask (void *buffer,size_t *lenp,loff_t *ppos,struct cpumask *mask)
PATCH v5 13/15 neighbour: Don't store net in struct pneigh_entry.
In reply to Kuniyuki Iwashimaneigh_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().
---
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(-)
include/net/neighbour.h +3 -9
@@ -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);
net/core/neighbour.c +18 -37
174 lines not on this page · raw message
net/ipv4/arp.c +3 -3
@@ -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 );
net/ipv6/ip6_output.c +1 -1
@@ -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);
net/ipv6/ndisc.c +2 -2
@@ -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; }
Signature · 1 line
2.55.0.966.g6673acef38-goog
PATCH v5 14/15 neighbour: Remove unnecessary net_eq().
In reply to Kuniyuki Iwashimaneigh_table is now per-netns, and net_eq() is no longer needed.
Let's remove them.
---
v2: Split pneigh part into the prev patch
--- net/core/neighbour.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
net/core/neighbour.c +4 -12
@@ -2660,9 +2660,6 @@ static int neightbl_dump_info(struct sk_buff *skb, struct netlink_callback *cb) nidx =0 ; p =list_next_entry (&tbl->parms, list);list_for_each_entry_from_rcu (p, &tbl->parms_list, list) { -if (!net_eq (neigh_parms_net (p), net)) -continue ; -if (nidx < neigh_skip) goto next;
@@ -2840,12 +2837,11 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,struct netlink_callback *cb, struct neigh_dump_filter *filter) { - struct net *net = sock_net(skb->sk); -struct neighbour *n; -int err =0 , h, s_h = cb->args[1 ]; int idx, s_idx = idx = cb->args[2]; -struct neigh_hash_table *nht; +int err =0 , h, s_h = cb->args[1 ];unsigned int flags =NLM_F_MULTI ; +struct neigh_hash_table *nht; +struct neighbour *n;if (filter->dev_idx || filter->master_idx) flags |=NLM_F_DUMP_FILTERED ;
@@ -2857,7 +2853,7 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb, s_idx =0 ; idx =0 ;neigh_for_each_in_bucket_rcu (n, &nht->hash_heads[h]) { -if (idx < s_idx || !net_eq (dev_net (n->dev), net)) +if (idx < s_idx) goto next;if (neigh_ifindex_filtered (n->dev, filter->dev_idx) ||neigh_master_filtered (n->dev, filter->master_idx))
@@ -3262,10 +3258,6 @@ static struct neighbour *neigh_get_valid(struct seq_file *seq, loff_t *pos) {struct neigh_seq_state *state = seq->private; -struct net *net =seq_file_net (seq); - -if (!net_eq (dev_net (n->dev), net)) -return NULL ;if (state->neigh_sub_iter) {loff_t fakep =0 ;
Signature · 1 line
2.55.0.966.g6673acef38-goog
PATCH v5 15/15 selftest: net: Specify netns for ip ntable in test_neigh.sh.
In reply to Kuniyuki Iwashimatest_neigh.sh configures the following attributes in the root netns, but now these can be set per netns.
* NDTA_THRESH1 / NDTA_THRESH2 / NDTA_THRESH3
* NDTPA_BASE_REACHABLE_TIME
Let's specify netns for "ip ntable".
---
v3: Remove stale comments
--- tools/testing/selftests/net/test_neigh.sh | 41 ++++++++++++----------- 1 file changed, 22 insertions(+), 19 deletions(-)
tools/testing/selftests/net/test_neigh.sh +22 -19
@@ -240,9 +240,6 @@ extern_valid_common() # Check that an "extern_valid" entry survives a forced garbage # collection. Add an entry, wait 5 seconds and add more entries than # "thresh3" so that forced garbage collection will run. - # - # Note that the garbage collection thresholds are global resources and - # that changes in the initial namespace affect all the namespaces. local forced_gc_runs_t0 local forced_gc_runs_t1 local orig_thresh1
@@ -250,18 +247,23 @@ extern_valid_common() local orig_thresh3 run_cmd "ip -n $ns1 neigh flush dev veth0" - orig_thresh1=$(ip -j ntable show name "$tbl_name" | jq '.[] | select(has("thresh1")) | .["thresh1"]') - orig_thresh2=$(ip -j ntable show name "$tbl_name" | jq '.[] | select(has("thresh2")) | .["thresh2"]') - orig_thresh3=$(ip -j ntable show name "$tbl_name" | jq '.[] | select(has("thresh3")) | .["thresh3"]') - run_cmd "ip ntable change name $tbl_name thresh3 10 thresh2 9 thresh1 8" + orig_thresh1=$(ip -n "$ns1" -j ntable show name "$tbl_name" | \ + jq '.[] | select(has("thresh1")) | .["thresh1"]') + orig_thresh2=$(ip -n "$ns1" -j ntable show name "$tbl_name" | \ + jq '.[] | select(has("thresh2")) | .["thresh2"]') + orig_thresh3=$(ip -n "$ns1" -j ntable show name "$tbl_name" | \ + jq '.[] | select(has("thresh3")) | .["thresh3"]') + run_cmd "ip -n $ns1 ntable change name $tbl_name thresh3 10 thresh2 9 thresh1 8" run_cmd "ip -n $ns1 neigh add $ip_addr lladdr $mac nud stale dev veth0 extern_valid" run_cmd "ip -n $ns1 neigh add ${subnet}3 lladdr $mac nud stale dev veth0" run_cmd "sleep 5" - forced_gc_runs_t0=$(ip -j -s ntable show name "$tbl_name" | jq '.[] | select(has("forced_gc_runs")) | .["forced_gc_runs"]') + forced_gc_runs_t0=$(ip -n "$ns1" -j -s ntable show name "$tbl_name" | \ + jq '.[] | select(has("forced_gc_runs")) | .["forced_gc_runs"]') for i in {1..20}; do run_cmd "ip -n $ns1 neigh add ${subnet}$((i + 4)) nud none dev veth0" done - forced_gc_runs_t1=$(ip -j -s ntable show name "$tbl_name" | jq '.[] | select(has("forced_gc_runs")) | .["forced_gc_runs"]') + forced_gc_runs_t1=$(ip -n "$ns1" -j -s ntable show name "$tbl_name" | \ + jq '.[] | select(has("forced_gc_runs")) | .["forced_gc_runs"]') if [[ $forced_gc_runs_t1 -eq $forced_gc_runs_t0 ]]; then check_err 1 "Forced garbage collection did not run" fi
@@ -272,7 +274,8 @@ extern_valid_common() log_test "$af_str \"extern_valid\" flag: Forced garbage collection" - run_cmd "ip ntable change name $tbl_name thresh3 $orig_thresh3 thresh2 $orig_thresh2 thresh1 $orig_thresh1" + run_cmd "ip -n $ns1 ntable change name $tbl_name \ + thresh3 $orig_thresh3 thresh2 $orig_thresh2 thresh1 $orig_thresh1" RET=0
@@ -284,10 +287,6 @@ extern_valid_common() # collection. Add an "extern_valid" entry, add more than "thresh1" # regular entries, wait "base_reachable" (longer than "gc_stale") # seconds and check that the "extern_valid" entry was not deleted. - # - # Note that the garbage collection thresholds and "base_reachable" are - # global resources and that changes in the initial namespace affect all - # the namespaces. local periodic_gc_runs_t0 local periodic_gc_runs_t1 local orig_base_reachable
@@ -296,10 +295,13 @@ extern_valid_common() local timeout run_cmd "ip -n $ns1 neigh flush dev veth0" - orig_thresh1=$(ip -j ntable show name "$tbl_name" | jq '.[] | select(has("thresh1")) | .["thresh1"]') - orig_base_reachable=$(ip -j ntable show name "$tbl_name" | jq '.[] | select(has("thresh1")) | .["base_reachable"]') - run_cmd "ip ntable change name $tbl_name thresh1 10 base_reachable $base_reachable" - orig_gc_stale=$(ip -n "$ns1" -j ntable show name "$tbl_name" dev veth0 | jq '.[]["gc_stale"]') + orig_thresh1=$(ip -n "$ns1" -j ntable show name "$tbl_name" | \ + jq '.[] | select(has("thresh1")) | .["thresh1"]') + orig_base_reachable=$(ip -n "$ns1" -j ntable show name "$tbl_name" | \ + jq '.[] | select(has("thresh1")) | .["base_reachable"]') + run_cmd "ip -n $ns1 ntable change name $tbl_name thresh1 10 base_reachable $base_reachable" + orig_gc_stale=$(ip -n "$ns1" -j ntable show name "$tbl_name" dev veth0 | \ + jq '.[]["gc_stale"]') run_cmd "ip -n $ns1 ntable change name $tbl_name dev veth0 gc_stale 1000" run_cmd "ip -n $ns1 neigh add $ip_addr lladdr $mac nud stale dev veth0 extern_valid" run_cmd "ip -n $ns1 neigh add ${subnet}3 lladdr $mac nud stale dev veth0"
@@ -325,7 +327,8 @@ extern_valid_common() log_test "$af_str \"extern_valid\" flag: Periodic garbage collection" run_cmd "ip -n $ns1 ntable change name $tbl_name dev veth0 gc_stale $orig_gc_stale" - run_cmd "ip ntable change name $tbl_name thresh1 $orig_thresh1 base_reachable $orig_base_reachable" + run_cmd "ip -n $ns1 ntable change name $tbl_name \ + thresh1 $orig_thresh1 base_reachable $orig_base_reachable" } extern_valid_ipv4()
Signature · 1 line
2.55.0.966.g6673acef38-goog
Ido Schimmel
maintainerQuoted 10 lines · Kuniyuki Iwashima
The neighbour subsystem is almost ready to drop RTNL.
However, the control paths are serialised by the global per-table lock.
This series converts
arp_tblandnd_tblto per-netns table.With the series,
/proc/sys/net/ipv{4,6}/neigh/default/can be configured per netns, which was only configurable ininit_net.
LGTM overall. Two notes:
1. The two periodic works (GC and the one for "managed" entries) are now per-netns, including their intervals. An unpriv user can set an interval of 0 and hog the CPU. Previously you needed CAP_NET_ADMIN in the init netns.
neigh_managed_work() already has a floor for the re-queue delay since commit ed6cd6a17896 ("net, neigh: Set lower cap for neigh_managed_work rearming"). We need something similar for neigh_periodic_work(). Something like:
net/core/neighbour.c +2 -1
@@ -1038,7 +1038,8 @@ static void neigh_periodic_work(struct work_struct *work)* BASE_REACHABLE_TIME. */ queue_delayed_work (system_power_efficient_wq, &tbl->gc_work, -NEIGH_VAR (&tbl->parms,BASE_REACHABLE_TIME ) >>1 ); +max (NEIGH_VAR (&tbl->parms,BASE_REACHABLE_TIME ) >>1 , +HZ ));spin_unlock_bh (&tbl->lock); }
2. Related to the first point, we are now going to schedule periodic work per-netns for "managed" entries which are quite exotic. Better to schedule it only when we have such entries instead of unconditionally from neigh_table_init().
I think both can be done in a follow-up given you are already at 15 patches. The first is more critical, obviously.
Thanks!
Quoted 44 lines · Ido Schimmel
Quoted 10 lines · Kuniyuki Iwashima
The neighbour subsystem is almost ready to drop RTNL.
However, the control paths are serialised by the global per-table lock.
This series converts
arp_tblandnd_tblto per-netns table.With the series,
/proc/sys/net/ipv{4,6}/neigh/default/can be configured per netns, which was only configurable ininit_net.LGTM overall. Two notes:
1. The two periodic works (GC and the one for "managed" entries) are now per-netns, including their intervals. An unpriv user can set an interval of 0 and hog the CPU. Previously you needed
CAP_NET_ADMINin the init netns.
neigh_managed_work()already has a floor for the re-queue delay since commited6cd6a17896("net, neigh: Set lower cap forneigh_managed_workrearming"). We need something similar forneigh_periodic_work(). Something like:net/core/neighbour.c +2
-1@@ -1038,7 +1038,8 @@ static void neigh_periodic_work(struct work_struct *work)* BASE_REACHABLE_TIME. */ queue_delayed_work (system_power_efficient_wq, &tbl->gc_work, -NEIGH_VAR (&tbl->parms,BASE_REACHABLE_TIME ) >>1 ); +max (NEIGH_VAR (&tbl->parms,BASE_REACHABLE_TIME ) >>1 , +HZ ));spin_unlock_bh (&tbl->lock); }2. Related to the first point, we are now going to schedule periodic work per-netns for "managed" entries which are quite exotic. Better to schedule it only when we have such entries instead of unconditionally from
neigh_table_init().
Quoted 2 lines
I think both can be done in a follow-up given you are already at 15 patches. The first is more critical, obviously.
Both make sense, I'll follow up on them after this series.
Thanks !