Skip to contentSkip to conversation

netconfig: Add multiple levels to IWD_DHCP_DEBUG

PATCH In review Michael Johnson 3 participants 5 messages May 18, 2022 – May 19, 2022

lore
Share & tools
lore

Michael Johnson

author
#0 lore raw

PATCH v3 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 info, errors and warnings to match the rest of iwd.

Setting IWD_DHCP_DEBUG to "debug", "info", "warn", "error" will limit the logging to that level or higher allowing the default logging verbosity to be reduced.

Setting IWD_DHCP_DEBUG to "1" as per the current behavior will continue to enable debug level logging.

---
 src/netconfig.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
src/netconfig.c +18 -3
index 6694a0e9..0042a55d 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_INFO;
 
 	if (!netconfig_list)
 		return NULL;
@@ -1640,9 +1642,22 @@ 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) {
+		if (strcmp("debug", debug_level) == 0)
+			dhcp_priority = L_LOG_DEBUG;
+		else if (strcmp("info", debug_level) == 0)
+			dhcp_priority = L_LOG_INFO;
+		else if (strcmp("warn", debug_level) == 0)
+			dhcp_priority = L_LOG_WARNING;
+		else if (strcmp("error", debug_level) == 0)
+			dhcp_priority = L_LOG_ERR;
+		else 	/* Default for backwards compatibility */
+			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 v3 2/2 docs: Show new usage of IWD_DHCP_DEBUG

---
 src/iwd.debug.rst | 4 ++++
 1 file changed, 4 insertions(+)
src/iwd.debug.rst +4 -0
index 5a805562..3d4c8b58 100644
@@ -40,6 +40,10 @@ ENVIRONMENT
 
 *$IWD_WSC_DEBUG_KEYS* set to ``1`` enables printing received WSC keys.
 
+The granularity of the DHCP logging can also be tailored by setting
+*$IWD_DHCP_DEBUG* to the maximum verbosity level, "debug", "info", "warn", or
+"error".
+
 SEE ALSO
 ========
 
Signature · 1 line
2.25.1
#2 lore raw
In reply to Michael Johnson

Hi Michael,

Quoted 40 lines

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

Setting IWD_DHCP_DEBUG to "debug", "info", "warn", "error" will limit the logging to that level or higher allowing the default logging verbosity to be reduced.

Setting IWD_DHCP_DEBUG to "1" as per the current behavior will continue to enable debug level logging.
---
src/netconfig.c | 21 ++++++++++++++++++---

1 file changed, 18 insertions(+), 3 deletions(-)
src/netconfig.c +8 -3
index 6694a0e9..0042a55d 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_INFO;
 
 	if (!netconfig_list)
 		return NULL;
@@ -1640,9 +1642,22 @@ 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) {
+		if (strcmp("debug", debug_level) == 0)
+			dhcp_priority = L_LOG_DEBUG;
+		else if (strcmp("info", debug_level) == 0)
+			dhcp_priority = L_LOG_INFO;

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

Quoted 10 lines
src/netconfig.c +10 -0
+		else if (strcmp("warn", debug_level) == 0)
+			dhcp_priority = L_LOG_WARNING;
+		else if (strcmp("error", debug_level) == 0)
+			dhcp_priority = L_LOG_ERR;
+		else 	/* Default for backwards compatibility */
+			dhcp_priority = L_LOG_DEBUG;
+	}
+
+	l_dhcp_client_set_debug(netconfig->dhcp_client, do_debug,
+					"[DHCPv4] ", NULL, dhcp_priority);

please don’t always set l_dhcp_client_set_debug. It should not be set. And I don’t like the dhcp_priority parameter at all. That is just convoluted code and there is no precedence with any _set_debug() APIs.

Regards

Marcel

author
#3 lore raw

Hi Marcel,

Quoted 4 lines · Marcel Holtmann

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

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

please don’t always set l_dhcp_client_set_debug. It should not be set. And I don’t like the dhcp_priority parameter at all. That is just convoluted code and there is no precedence with any _set_debug() APIs.

Just so I'm on the same page, my intention is to turn on logging with the DHCP client by default so warnings and errors aren't silently dropped. Ideally I would also like to have a certain level of info logging that matches other DHCP clients so it's possible to see what state the system is in. Maybe this isn't something iwd is interested in, which is fine, but if it is, what would you propose I do instead here?

Regards,
Michael

#4 lore raw
In reply to Michael Johnson

Hi Michael,

Quoted 14 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 info, errors and warnings to match the rest of iwd.

Setting IWD_DHCP_DEBUG to "debug", "info", "warn", "error" will limit the logging to that level or higher allowing the default logging verbosity to be reduced.

Setting IWD_DHCP_DEBUG to "1" as per the current behavior will continue to enable debug level logging.

---
  src/netconfig.c | 21 ++++++++++++++++++---
  1 file changed, 18 insertions(+), 3 deletions(-)

<snip>

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

Quoted 1 line
src/netconfig.c +1 -0
+		if (strcmp("debug", debug_level) == 0)

We prefer !strcmp instead of comparing with 0, so I amended this.

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

Quoted 8 lines
src/netconfig.c +8 -0
+			dhcp_priority = L_LOG_DEBUG;
+		else if (strcmp("info", debug_level) == 0)
+			dhcp_priority = L_LOG_INFO;
+		else if (strcmp("warn", debug_level) == 0)
+			dhcp_priority = L_LOG_WARNING;
+		else if (strcmp("error", debug_level) == 0)
+			dhcp_priority = L_LOG_ERR;
+		else 	/* Default for backwards compatibility */

And I think there was a stray whitespace before <tab> that I took care of as well.

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

Quoted 3 lines
src/netconfig.c +3 -0
+			dhcp_priority = L_LOG_DEBUG;
+	}
+

Both patches applied, thanks!

Regards,
-Denis