From 28d13f9a433e6554f9a210e9382ffd0e7879b45d Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Wed, 18 May 2022 15:39:14 +0100 Subject: [PATCH] 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(-) diff --git a/src/netconfig.c b/src/netconfig.c index 6694a0e9..2ab03b90 100644 --- a/src/netconfig.c +++ b/src/netconfig.c @@ -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)) + dhcp_priority = L_LOG_DEBUG; + else if (!strcmp("info", debug_level)) + dhcp_priority = L_LOG_INFO; + else if (!strcmp("warn", debug_level)) + dhcp_priority = L_LOG_WARNING; + else if (!strcmp("error", debug_level)) + 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,