Skip to contentSkip to conversation

netconfig: Add multiple levels to IWD_DHCP_DEBUG

PATCH Superseded Michael Johnson 2 participants 8 messages May 17, 2022 – May 18, 2022

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Michael Johnson

author
#0 lore raw

PATCH v2 1/2 netconfig: Add multiple levels to IWD_DHCP_DEBUG

Allows granularly specifying the DHCP logging level. This allows the user to tailor the output to what they need. By default always display errors and warnings.

1 = INFO
2 = DEBUG

---
 src/netconfig.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
src/netconfig.c +14 -3
index 6694a0e9..da9969f2 100644
@@ -1621,6 +1621,8 @@ struct netconfig *netconfig_new(uint32_t ifindex)
 	struct netdev *netdev = netdev_find(ifindex);
 	struct netconfig *netconfig;
 	struct l_icmp6_client *icmp6;
+	const char *debug_level = NULL;
+	int dhcp_priority = L_LOG_WARNING;
 
 	if (!netconfig_list)
 		return NULL;
@@ -1640,9 +1642,18 @@ struct netconfig *netconfig_new(uint32_t ifindex)
 					netconfig_ipv4_dhcp_event_handler,
 					netconfig, NULL);
 
-	if (getenv("IWD_DHCP_DEBUG"))
-		l_dhcp_client_set_debug(netconfig->dhcp_client, do_debug,
-							"[DHCPv4] ", NULL);
+	debug_level = getenv("IWD_DHCP_DEBUG");
+	if (debug_level != NULL)
+	{
+		// Convert from user 1 or 2 to L_LOG_*
+		if (*debug_level == '1')
+			dhcp_priority = L_LOG_INFO;
+		else if (*debug_level == '2')
+			dhcp_priority = L_LOG_DEBUG;
+	}
+
+	l_dhcp_client_set_debug(netconfig->dhcp_client, do_debug,
+					"[DHCPv4] ", NULL, dhcp_priority);
 
 	netconfig->dhcp6_client = l_dhcp6_client_new(ifindex);
 	l_dhcp6_client_set_event_handler(netconfig->dhcp6_client,
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 2/2 docs: Update IWD_DHCP_DEBUG values

Use ``1`` and ``2`` for debug level to maintain compatibility with existing settings.

---
 src/iwd.debug.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/iwd.debug.rst +1 -1
index 5a805562..e218c4a8 100644
@@ -34,7 +34,7 @@ ENVIRONMENT
 
 *$IWD_GENL_DEBUG* set to ``1`` enables printing Generic Netlink communication with the kernel.
 
-*$IWD_DHCP_DEBUG* set to ``1`` enables DHCP debugging.
+*$IWD_DHCP_DEBUG* set to ``1`` (info) or ``2`` (debug) to enabled DHCP logging.
 
 *$IWD_TLS_DEBUG* set to ``1`` enables TLS debugging.
 
Signature · 1 line
2.25.1
#2 lore raw
In reply to Michael Johnson

Hi Michael,

Quoted 24 lines · Michael Johnson

Allows granularly specifying the DHCP logging level. This allows the user to tailor the output to what they need. By default always display errors and warnings.

1 = INFO
2 = DEBUG

---
  src/netconfig.c | 17 ++++++++++++++---
  1 file changed, 14 insertions(+), 3 deletions(-)
src/netconfig.c +2 -0
index 6694a0e9..da9969f2 100644
@@ -1621,6 +1621,8 @@ struct netconfig *netconfig_new(uint32_t ifindex)
  	struct netdev *netdev = netdev_find(ifindex);
  	struct netconfig *netconfig;
  	struct l_icmp6_client *icmp6;
+	const char *debug_level = NULL;
+	int dhcp_priority = L_LOG_WARNING;
 
  	if (!netconfig_list)
  		return NULL;

src/netconfig.c struct netconfig *netconfig_new(uint32_t ifindex) · line 1648

Quoted 10 lines
src/netconfig.c +4 -3
@@ -1640,9 +1642,18 @@ struct netconfig *netconfig_new(uint32_t ifindex)
  					netconfig_ipv4_dhcp_event_handler,
  					netconfig, NULL);
 
-	if (getenv("IWD_DHCP_DEBUG"))
-		l_dhcp_client_set_debug(netconfig->dhcp_client, do_debug,
-							"[DHCPv4] ", NULL);
+	debug_level = getenv("IWD_DHCP_DEBUG");
+	if (debug_level != NULL)
+	{
+		// Convert from user 1 or 2 to L_LOG_*

Actually, that's not our coding style. We use Linux Kernel style, so it would be:

if (debug_level != NULL) {

and no C++ comments please.

src/netconfig.c struct netconfig *netconfig_new(uint32_t ifindex) · line 1654

Quoted 6 lines
src/netconfig.c +6 -0
+		if (*debug_level == '1')
+			dhcp_priority = L_LOG_INFO;
+		else if (*debug_level == '2')
+			dhcp_priority = L_LOG_DEBUG;
+	}
+

This changes the semantics slightly. In our wiki, etc we show IWD_DHCP_DEBUG with value "1" to enable debugging, so I think we should be nice and keep that behavior if possible. How about:

if IWD_DHCP_DEBUG is not set, use L_LOG_WARNING.

If IWD_DHCP_DEBUG is set and has a non-NULL value, use L_LOG_DEBUG

If the value above is from the set L_LOG_ERR .. L_LOG_DEBUG (3 .. 7), then use that.

src/netconfig.c struct netconfig *netconfig_new(uint32_t ifindex) · line 1659

Quoted 6 lines
src/netconfig.c +2 -0
+	l_dhcp_client_set_debug(netconfig->dhcp_client, do_debug,
+					"[DHCPv4] ", NULL, dhcp_priority);
 
  	netconfig->dhcp6_client = l_dhcp6_client_new(ifindex);
  	l_dhcp6_client_set_event_handler(netconfig->dhcp6_client,

Regards,
-Denis

author
#3 lore raw

Hi Denis,

On Tue, 17 May 2022 at 19:09, Denis Kenzior <denkenz(a)gmail.com> wrote:
...

Quoted 2 lines

Actually, that's not our coding style. We use Linux Kernel style, so it would be:

Sorry about that, I'll fix it up. I saw the functions and assumed without checking other if's.

Quoted 9 lines

This changes the semantics slightly. In our wiki, etc we show IWD_DHCP_DEBUG with value "1" to enable debugging, so I think we should be nice and keep that behavior if possible. How about:

if IWD_DHCP_DEBUG is not set, use L_LOG_WARNING.

If IWD_DHCP_DEBUG is set and has a non-NULL value, use L_LOG_DEBUG

If the value above is from the set L_LOG_ERR .. L_LOG_DEBUG (3 .. 7), then use that.

I made this change but it seems quite difficult to explain in a reasonable way to the user why the values are 3, 4, 6, and 7. How about using strings instead? info, warn, error, debug? That still allows us to keep the old behavior if it's a 1.

I'm also questioning if I should keep the L_LOG_WARN as the default or make it L_LOG_INFO which is more in line with what I intended when I started (i.e. not setting the env should result in similar output to other DHCP clients). Do you prefer WARN?

Regards,
Michael

#4 lore raw

Hi Michael,

Quoted 6 lines
Quoted 6 lines

This changes the semantics slightly. In our wiki, etc we show IWD_DHCP_DEBUG with value "1" to enable debugging, so I think we should be nice and keep that behavior if possible. How about:

if IWD_DHCP_DEBUG is not set, use L_LOG_WARNING.

Quoted 8 lines
Quoted 3 lines

If IWD_DHCP_DEBUG is set and has a non-NULL value, use L_LOG_DEBUG

If the value above is from the set L_LOG_ERR .. L_LOG_DEBUG (3 .. 7), then use that.

I made this change but it seems quite difficult to explain in a reasonable way to the user why the values are 3, 4, 6, and 7. How about using strings instead? info, warn, error, debug? That still allows us to keep the old behavior if it's a 1.

Sure, that sounds even better.

Quoted 5 lines

I'm also questioning if I should keep the L_LOG_WARN as the default or make it L_LOG_INFO which is more in line with what I intended when I started (i.e. not setting the env should result in similar output to other DHCP clients). Do you prefer WARN?

If you intended this to be info, then do that. iwd prints l_info, l_error and l_warn messages by default and only l_debug is enabled via '-d'.

Regards,
-Denis

author
#5 lore raw

Hi Denis,

Quoted 2 lines · Denis Kenzior

If you intended this to be info, then do that. iwd prints l_info, l_error and l_warn messages by default and only l_debug is enabled via '-d'.

This makes me think DHCP should just follow the same pattern for simplicity. I have sent a new patch which always enable DHCP info level logging and if the user sets IWD_DHCP_DEBUG then bump it up to debug.
This patch is much simpler and doesn't change the behavior of the env var but it comes with the downside of not being able to quieten it (although that is similar to iwd).

I have the v3 version of this patch ready with the string comparisons if you prefer the first approach.

Regards,
Michael

#6 lore raw

Hi Michael,

Quoted 14 lines · Michael Johnson

Hi Denis,

Quoted 2 lines · Denis Kenzior

If you intended this to be info, then do that. iwd prints l_info, l_error and l_warn messages by default and only l_debug is enabled via '-d'.

This makes me think DHCP should just follow the same pattern for simplicity. I have sent a new patch which always enable DHCP info level logging and if the user sets IWD_DHCP_DEBUG then bump it up to debug.
This patch is much simpler and doesn't change the behavior of the env var but it comes with the downside of not being able to quieten it (although that is similar to iwd).

Quoted 2 lines

I have the v3 version of this patch ready with the string comparisons if you prefer the first approach.

Send it out and I'll ponder which one I like more. I think longer term, it might be desirable to be able to quiet down some of this output, even for iwd itself.

Regards,
-Denis

author
#7 lore raw

Hi Denis,

Quoted 3 lines · Denis Kenzior

Send it out and I'll ponder which one I like more. I think longer term, it might be desirable to be able to quiet down some of this output, even for iwd itself.

Ok, I've sent it out.

I also sent another ell patch for changes that would allow limiting the iwd logging as well which I wrote when putting together a more complex patch (before it got too complex). This would go better with the second iwd patch as the verbosity can be reduced through a new l_log_set_max_level function in ell/log and therefore IWD_DHCP_DEBUG can remain simple.

I don't have a matching patch to limit logging verbosity in all of iwd though it should be fairly straightforward to add.

Regards,
Michael