* [PATCH net-next] net: add sysctl ndisc_debug
@ 2025-06-24 12:51 Wang Liang
2025-06-24 14:31 ` Ido Schimmel
0 siblings, 1 reply; 3+ messages in thread
From: Wang Liang @ 2025-06-24 12:51 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, horms, dsahern
Cc: yuehaibing, zhangchangzhong, wangliang74, netdev, linux-kernel
Ipv6 ndisc uses ND_PRINTK to print logs. However it only works when
ND_DEBUG was set in the compilation phase. This patch adds sysctl
ndisc_debug, so we can change the print switch when system is running and
get ipv6 ndisc log to debug.
Signed-off-by: Wang Liang <wangliang74@huawei.com>
---
include/net/ndisc.h | 5 ++---
net/ipv6/ndisc.c | 3 +++
net/ipv6/sysctl_net_ipv6.c | 7 +++++++
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/include/net/ndisc.h b/include/net/ndisc.h
index 3c88d5bc5eed..481a7fc5d5c1 100644
--- a/include/net/ndisc.h
+++ b/include/net/ndisc.h
@@ -60,12 +60,11 @@ enum {
#include <net/neighbour.h>
-/* Set to 3 to get tracing... */
-#define ND_DEBUG 1
+extern u8 ndisc_debug;
#define ND_PRINTK(val, level, fmt, ...) \
do { \
- if (val <= ND_DEBUG) \
+ if (val <= ndisc_debug) \
net_##level##_ratelimited(fmt, ##__VA_ARGS__); \
} while (0)
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index ecb5c4b8518f..be4bb72b1d61 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -83,6 +83,9 @@ static void pndisc_destructor(struct pneigh_entry *n);
static void pndisc_redo(struct sk_buff *skb);
static int ndisc_is_multicast(const void *pkey);
+u8 ndisc_debug = 1;
+EXPORT_SYMBOL_GPL(ndisc_debug);
+
static const struct neigh_ops ndisc_generic_ops = {
.family = AF_INET6,
.solicit = ndisc_solicit,
diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
index d2cd33e2698d..c0968f0c5d00 100644
--- a/net/ipv6/sysctl_net_ipv6.c
+++ b/net/ipv6/sysctl_net_ipv6.c
@@ -247,6 +247,13 @@ static struct ctl_table ipv6_rotable[] = {
.proc_handler = proc_dointvec,
},
#endif /* CONFIG_NETLABEL */
+ {
+ .procname = "ndisc_debug",
+ .data = &ndisc_debug,
+ .maxlen = sizeof(u8),
+ .mode = 0644,
+ .proc_handler = proc_dou8vec_minmax
+ },
};
static int __net_init ipv6_sysctl_net_init(struct net *net)
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: add sysctl ndisc_debug
2025-06-24 12:51 [PATCH net-next] net: add sysctl ndisc_debug Wang Liang
@ 2025-06-24 14:31 ` Ido Schimmel
2025-06-27 1:13 ` Wang Liang
0 siblings, 1 reply; 3+ messages in thread
From: Ido Schimmel @ 2025-06-24 14:31 UTC (permalink / raw)
To: Wang Liang
Cc: davem, edumazet, kuba, pabeni, horms, dsahern, yuehaibing,
zhangchangzhong, netdev, linux-kernel
On Tue, Jun 24, 2025 at 08:51:15PM +0800, Wang Liang wrote:
> Ipv6 ndisc uses ND_PRINTK to print logs. However it only works when
> ND_DEBUG was set in the compilation phase. This patch adds sysctl
> ndisc_debug, so we can change the print switch when system is running and
> get ipv6 ndisc log to debug.
Is there a good reason to do this instead of using dynamic debug? Note
that we will never be able to remove this sysctl.
Users of vanilla kernels can only see the messages printed with 'val'
being 0 or 1. Maybe convert them to call net_{err,warn}_ratelimited()
instead of ND_PRINTK() and convert the rest to net_dbg_ratelimited() so
that users will be able to enable / disable them during runtime via the
dynamic debug interface?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: add sysctl ndisc_debug
2025-06-24 14:31 ` Ido Schimmel
@ 2025-06-27 1:13 ` Wang Liang
0 siblings, 0 replies; 3+ messages in thread
From: Wang Liang @ 2025-06-27 1:13 UTC (permalink / raw)
To: Ido Schimmel
Cc: davem, edumazet, kuba, pabeni, horms, dsahern, yuehaibing,
zhangchangzhong, netdev, linux-kernel
在 2025/6/24 22:31, Ido Schimmel 写道:
> On Tue, Jun 24, 2025 at 08:51:15PM +0800, Wang Liang wrote:
>> Ipv6 ndisc uses ND_PRINTK to print logs. However it only works when
>> ND_DEBUG was set in the compilation phase. This patch adds sysctl
>> ndisc_debug, so we can change the print switch when system is running and
>> get ipv6 ndisc log to debug.
> Is there a good reason to do this instead of using dynamic debug? Note
> that we will never be able to remove this sysctl.
>
> Users of vanilla kernels can only see the messages printed with 'val'
> being 0 or 1. Maybe convert them to call net_{err,warn}_ratelimited()
> instead of ND_PRINTK() and convert the rest to net_dbg_ratelimited() so
> that users will be able to enable / disable them during runtime via the
> dynamic debug interface?
Hi! Thanks for your review!
Yes, you are right. Dynamic debug is indeed a better choice.
I will use it to replace sysctl in v2.
------
Best regards
Wang Liang
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-27 1:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-24 12:51 [PATCH net-next] net: add sysctl ndisc_debug Wang Liang
2025-06-24 14:31 ` Ido Schimmel
2025-06-27 1:13 ` Wang Liang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).