From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A7E33AE706 for ; Thu, 6 Aug 2026 01:12:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978726; cv=none; b=PhdOpFM2St8DV6nLnDogutCMlhtBBj/AWn9ato1m/B9YbJxBPYb4TnbyLUAK8x4nEROqNFv9amRUpCHVZEUixJMjUhNGB5m+kBX4+hjOKU2aq30L67JPCGiNVvAxEqkHoBpc9zl7DKm/tzDMC44TRReHBlc54Hry8lOCG3q4jzg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978726; c=relaxed/simple; bh=0xRU6EBu94YqIFSDXgdVFmw12Oasqk1W1JkIlB6fwM0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rH9qgs+/8My1bM+ZX80zi+w8kZz1cNcYAtKMNMVfaQY3D8TZrbkowHKhuc4Nq19fUrDOX+FxaQrd8Utz+dvwolFN2ImGbb4INKaM2QBkHfkbdUjCOQVd3XBYMHPULrygM9fKuHkMNNar248gDzWBlZGhtD6ZIYeWBj6+J75r/7k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=j2/sWEa7; arc=none smtp.client-ip=209.85.215.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="j2/sWEa7" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-c856470fe9fso1256974a12.2 for ; Wed, 05 Aug 2026 18:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978723; x=1786583523; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ktR3lN6ziEwt2JPoR0G5Q4Ir+bUJ1ux70lFKT+2qRxE=; b=j2/sWEa7I87mJ6jtkpIoU3XZfTiMN0CUAD7HsCNUkgcfVR6Ug8NxXaJ2X5bA49+MyO FIqzBxlsQyaP+VdaL0nAO3f5CbhXYU3yw2hBjcenyOoGcOcOu/7xqIgUDKgN0BErSDVt TAvyqHGZOPm8jQGzS9vylXQf4vRpHXxzSNmJpYlJg3FvYfuJFEbIlh5cEt3EMlALC8vY ecouYoM3vhXxyxTsS8N5RSHAgJVmf1nloOaMMliW4iDNMjIt+WrrizSRUahaBYBQC38o h57vJnNO+N0YiYr9tIKPb73Rar7Nclf+fM2C59cUS4Uj8tGHwZKVT8I+fUGVgGPZ+SFq 0H6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978723; x=1786583523; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ktR3lN6ziEwt2JPoR0G5Q4Ir+bUJ1ux70lFKT+2qRxE=; b=L/iXsfuy/sU7D3t+lpLiQ5cXnNVS86R4I+AjJR7k8TVp32abeqzkJZQKkqdymVJVFd YzaMzGGQ/vpOsyWbhyh5r7J4/obITRZMlisZyo3DTJFw4Fg86aLC9nchB8RdycHxeet6 OFUHOFIEV66REdgRElnu44eQ1kmL/Jm7H/Cdt/0NPpWugLVS5HY6fS83yrMHoG/stfbG 7ICtnYmgo9XUmwh4ZYWo55a44gxFuhqcnlP8DrsODFI4GWvtVI0JlzxHwIRoneoLrF/k n8SHm8riASRm/DftkHZxTjD4DSde7aGjmuy7U1G0Q/yvtiVdRdhidoG53KigRKHGDgAE 0DLg== X-Forwarded-Encrypted: i=1; AHgh+RqqmbYXDJSz4EGnmQo/0NOK5mPfWi5O+Tl1xBYxz6IgO9zgK5HTo8LDsT23MwUAoPiSJ+aqoRI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7T8YzcjATlDUp191lBldWzopOUh5Pt9m9fQV+tCmjE690dWsY K+V2VaAidX/CghNIovbq6T1smNrcNS8EpGdp0NqkPrKT+yMqIQrGmJg+pnBa0P0G5BVkptEtsgR WV+qd3Q== X-Received: from pfwz3.prod.google.com ([2002:a05:6a00:1d83:b0:84a:6b32:7768]) (user=kuniyu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:218d:b0:845:d6a5:716b with SMTP id d2e1a72fcca58-84f2e07129fmr12222742b3a.23.1785978722814; Wed, 05 Aug 2026 18:12:02 -0700 (PDT) Date: Thu, 6 Aug 2026 01:11:32 +0000 In-Reply-To: <20260806011152.1170012-1-kuniyu@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260806011152.1170012-1-kuniyu@google.com> X-Mailer: git-send-email 2.55.0.679.g6767b8d81c-goog Message-ID: <20260806011152.1170012-11-kuniyu@google.com> Subject: [PATCH v1 net-next 10/11] neighbour: Namespacify neigh_tables. From: Kuniyuki Iwashima To: Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern , Ido Schimmel Cc: Simon Horman , Kuniyuki Iwashima , Kuniyuki Iwashima , netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Now, 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(). The next patch will remove other unnecessary net_eq(). Note that CONFIG_SYSCTL cannot be enabled without CONFIG_PROC_FS. Signed-off-by: Kuniyuki Iwashima --- include/net/neighbour.h | 2 -- net/core/neighbour.c | 42 ++++++++++++++++++++++++++-------------- net/ipv4/arp.c | 20 +++++++++++++------ net/ipv6/ndisc.c | 43 ++++++++++++++--------------------------- 4 files changed, 57 insertions(+), 50 deletions(-) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 3e31eebf8663..b4e89533e1e6 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -341,8 +341,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, diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 83915526eb31..481f781e7ce8 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -1807,10 +1807,9 @@ void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms) static struct lock_class_key neigh_table_proxy_queue_class; -void neigh_table_init(struct neigh_table *tbl) +static int neigh_table_init(struct net *net, struct neigh_table *tbl) { unsigned long now = jiffies; - struct net *net = &init_net; unsigned long phsize; RCU_INIT_POINTER(tbl->nht, neigh_hash_alloc(3)); @@ -1830,8 +1829,9 @@ void neigh_table_init(struct neigh_table *tbl) goto err_stats; #ifdef CONFIG_PROC_FS - if (!proc_create_seq_data(tbl->id, 0, net->proc_net_stat, - &neigh_stat_seq_ops, tbl)) + if (!proc_create_net_data(tbl->id, 0, net->proc_net_stat, + &neigh_stat_seq_ops, + sizeof(struct seq_net_private), tbl)) goto err_proc; #endif @@ -1860,7 +1860,7 @@ void neigh_table_init(struct neigh_table *tbl) INIT_DEFERRABLE_WORK(&tbl->managed_work, neigh_managed_work); queue_delayed_work(system_power_efficient_wq, &tbl->managed_work, 0); - return; + return 0; #ifdef CONFIG_PROC_FS err_proc: @@ -1871,17 +1871,12 @@ void neigh_table_init(struct neigh_table *tbl) err_phash: neigh_hash_free_rcu(&rcu_dereference_protected(tbl->nht, 1)->rcu); err_hash: - panic("cannot allocate memory"); + return -ENOMEM; } -/* - * Only called from ndisc_cleanup(), which means this is dead code - * because we no longer can unload IPv6 module. - */ -int neigh_table_clear(struct neigh_table *tbl) +static void neigh_table_clear(struct net *net, struct neigh_table *tbl) { struct neigh_hash_table *nht; - struct net *net = &init_net; cancel_delayed_work_sync(&tbl->managed_work); cancel_delayed_work_sync(&tbl->gc_work); @@ -1901,20 +1896,39 @@ int neigh_table_clear(struct neigh_table *tbl) nht = rcu_dereference_protected(tbl->nht, 1); tbl->nht = NULL; neigh_hash_free_rcu(&nht->rcu); - - return 0; } int neigh_table_register(struct net *net, struct neigh_table *tbl, int index) { + int err; + + tbl = kmemdup(tbl, sizeof(*tbl), GFP_KERNEL); + if (!tbl) { + err = -ENOMEM; + goto err; + } + + err = neigh_table_init(net, tbl); + if (err) + goto free_table; + net->neigh_tables[index] = tbl; return 0; + +free_table: + kfree(tbl); +err: + return -ENOMEM; } void neigh_table_unregister(struct net *net, int index) { + struct neigh_table *tbl = net->neigh_tables[index]; + net->neigh_tables[index] = NULL; + neigh_table_clear(net, tbl); + kfree(tbl); } static struct neigh_table *neigh_find_table(struct net *net, int family) diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index a44fa68fdd07..c6d73b4e49a5 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c @@ -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,7 @@ static struct pernet_operations arp_net_ops = { void __init arp_init(void) { - neigh_table_init(&arp_tbl); - - dev_add_pack(&arp_packet_type); register_pernet_subsys(&arp_net_ops); -#ifdef CONFIG_SYSCTL - neigh_sysctl_register(NULL, &arp_tbl.parms, NULL); -#endif + dev_add_pack(&arp_packet_type); register_netdevice_notifier(&arp_netdev_notifier); } diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 3a458b188595..13e24c64dcdc 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1984,6 +1984,13 @@ static int __net_init ndisc_net_init(struct net *net) if (err) goto err; +#ifdef CONFIG_SYSCTL + err = neigh_sysctl_register(NULL, &nd_table(net)->parms, + ndisc_ifinfo_sysctl_change); + if (err) + goto err_sysctl; +#endif + err = inet_ctl_sock_create(&sk, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6, net); if (err < 0) { @@ -2002,6 +2009,10 @@ static int __net_init ndisc_net_init(struct net *net) return 0; err_sock_create: +#ifdef CONFIG_SYSCTL + neigh_sysctl_unregister(&nd_table(net)->parms); +err_sysctl: +#endif neigh_table_unregister(net, NEIGH_ND_TABLE); err: return err; @@ -2010,6 +2021,9 @@ static int __net_init ndisc_net_init(struct net *net) static void __net_exit ndisc_net_exit(struct net *net) { inet_ctl_sock_destroy(net->ipv6.ndisc_sk); +#ifdef CONFIG_SYSCTL + neigh_sysctl_unregister(&nd_table(net)->parms); +#endif neigh_table_unregister(net, NEIGH_ND_TABLE); } @@ -2020,30 +2034,7 @@ static struct pernet_operations ndisc_net_ops = { int __init ndisc_init(void) { - int err; - - err = register_pernet_subsys(&ndisc_net_ops); - if (err) - return err; - /* - * Initialize the neighbour table - */ - neigh_table_init(&nd_tbl); - -#ifdef CONFIG_SYSCTL - err = neigh_sysctl_register(NULL, &nd_tbl.parms, - ndisc_ifinfo_sysctl_change); - if (err) - goto out_unregister_pernet; -out: -#endif - return err; - -#ifdef CONFIG_SYSCTL -out_unregister_pernet: - unregister_pernet_subsys(&ndisc_net_ops); - goto out; -#endif + return register_pernet_subsys(&ndisc_net_ops); } int __init ndisc_late_init(void) @@ -2058,9 +2049,5 @@ void ndisc_late_cleanup(void) void ndisc_cleanup(void) { -#ifdef CONFIG_SYSCTL - neigh_sysctl_unregister(&nd_tbl.parms); -#endif - neigh_table_clear(&nd_tbl); unregister_pernet_subsys(&ndisc_net_ops); } -- 2.55.0.679.g6767b8d81c-goog