ell.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v2 1/3] dhcp: Add priority to logging
@ 2022-05-17 17:10 Michael Johnson
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Johnson @ 2022-05-17 17:10 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 756 bytes --]

Hi Denis,

Sorry about that, I thought I caught them all.

Michael

On Tue, 17 May 2022 at 18:03, Denis Kenzior <denkenz(a)gmail.com> wrote:
>
> Hi Michael,
>
> On 5/17/22 11:56, Michael Johnson wrote:
> > Most dhcp clients have some logging to show what state the lease is in
> > so this just makes iwd more in line with them. The logging won't be
> > enabled by default but requires a max logging level to be passed in when
> > logging is set up.
> > ---
> >   ell/dhcp.c | 48 +++++++++++++++++++++++++++++-------------------
> >   ell/dhcp.h |  2 +-
> >   2 files changed, 30 insertions(+), 20 deletions(-)
>
> All applied, thanks!  I did amend patch 1 & 3 slightly to break up lines that
> were > 80 chars.
>
> Regards,
> -Denis

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 1/3] dhcp: Add priority to logging
@ 2022-05-17 17:02 Denis Kenzior
  0 siblings, 0 replies; 3+ messages in thread
From: Denis Kenzior @ 2022-05-17 17:02 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 575 bytes --]

Hi Michael,

On 5/17/22 11:56, Michael Johnson wrote:
> Most dhcp clients have some logging to show what state the lease is in
> so this just makes iwd more in line with them. The logging won't be
> enabled by default but requires a max logging level to be passed in when
> logging is set up.
> ---
>   ell/dhcp.c | 48 +++++++++++++++++++++++++++++-------------------
>   ell/dhcp.h |  2 +-
>   2 files changed, 30 insertions(+), 20 deletions(-)

All applied, thanks!  I did amend patch 1 & 3 slightly to break up lines that 
were > 80 chars.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/3] dhcp: Add priority to logging
@ 2022-05-17 16:56 Michael Johnson
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Johnson @ 2022-05-17 16:56 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 8088 bytes --]

Most dhcp clients have some logging to show what state the lease is in
so this just makes iwd more in line with them. The logging won't be
enabled by default but requires a max logging level to be passed in when
logging is set up.
---
 ell/dhcp.c | 48 +++++++++++++++++++++++++++++-------------------
 ell/dhcp.h |  2 +-
 2 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/ell/dhcp.c b/ell/dhcp.c
index 2d04900..f8e6fb0 100644
--- a/ell/dhcp.c
+++ b/ell/dhcp.c
@@ -43,10 +43,18 @@
 #include "netlink.h"
 #include "rtnl.h"
 #include "acd.h"
+#include "log.h"
 
+#define CLIENT_LOG(priority, fmt, args...)				\
+	if (priority <= client->debug_level)				\
+		l_util_debug(client->debug_handler, client->debug_data,	\
+				"%s:%i " fmt, __func__, __LINE__, ## args)
 #define CLIENT_DEBUG(fmt, args...)					\
-	l_util_debug(client->debug_handler, client->debug_data,		\
-			"%s:%i " fmt, __func__, __LINE__, ## args)
+	CLIENT_LOG(L_LOG_DEBUG, fmt, ## args)
+#define CLIENT_INFO(fmt, args...)					\
+	CLIENT_LOG(L_LOG_INFO, fmt, ## args)
+#define CLIENT_WARN(fmt, args...)					\
+	CLIENT_LOG(L_LOG_WARNING, fmt, ## args)
 #define CLIENT_ENTER_STATE(s)						\
 	l_util_debug(client->debug_handler, client->debug_data,		\
 			"%s:%i Entering state: " #s,			\
@@ -192,6 +200,7 @@ struct l_dhcp_client {
 	l_dhcp_destroy_cb_t event_destroy;
 	l_dhcp_debug_cb_t debug_handler;
 	l_dhcp_destroy_cb_t debug_destroy;
+	int debug_level;
 	struct l_acd *acd;
 	void *debug_data;
 	bool have_addr : 1;
@@ -425,14 +434,14 @@ static int dhcp_client_send_request(struct l_dhcp_client *client)
 		if (!_dhcp_message_builder_append(&builder,
 					L_DHCP_OPTION_SERVER_IDENTIFIER,
 					4, &client->lease->server_address)) {
-			CLIENT_DEBUG("Failed to append server ID");
+			CLIENT_WARN("Failed to append server ID");
 			return -EINVAL;
 		}
 
 		if (!_dhcp_message_builder_append(&builder,
 					L_DHCP_OPTION_REQUESTED_IP_ADDRESS,
 					4, &client->lease->address)) {
-			CLIENT_DEBUG("Failed to append requested IP");
+			CLIENT_WARN("Failed to append requested IP");
 			return -EINVAL;
 		}
 
@@ -455,7 +464,7 @@ static int dhcp_client_send_request(struct l_dhcp_client *client)
 						L_DHCP_OPTION_HOST_NAME,
 						strlen(client->hostname),
 						client->hostname)) {
-			CLIENT_DEBUG("Failed to append host name");
+			CLIENT_WARN("Failed to append host name");
 			return -EINVAL;
 		}
 	}
@@ -507,7 +516,7 @@ static void dhcp_client_send_release(struct l_dhcp_client *client)
 	if (!_dhcp_message_builder_append(&builder,
 					L_DHCP_OPTION_SERVER_IDENTIFIER,
 					4, &client->lease->server_address)) {
-		CLIENT_DEBUG("Failed to append server ID");
+		CLIENT_WARN("Failed to append server ID");
 		return;
 	}
 
@@ -529,7 +538,7 @@ static void dhcp_client_timeout_resend(struct l_timeout *timeout,
 	case DHCP_STATE_SELECTING:
 		r = dhcp_client_send_discover(client);
 		if (r < 0) {
-			CLIENT_DEBUG("Sending discover failed: %s",
+			CLIENT_WARN("Sending discover failed: %s",
 								strerror(-r));
 			goto error;
 		}
@@ -540,7 +549,7 @@ static void dhcp_client_timeout_resend(struct l_timeout *timeout,
 	case DHCP_STATE_REBINDING:
 		r = dhcp_client_send_request(client);
 		if (r < 0) {
-			CLIENT_DEBUG("Sending Request failed: %s",
+			CLIENT_WARN("Sending Request failed: %s",
 								strerror(-r));
 			goto error;
 		}
@@ -632,7 +641,7 @@ static void dhcp_client_t1_expired(struct l_timeout *timeout, void *user_data)
 
 	r = dhcp_client_send_request(client);
 	if  (r < 0) {
-		CLIENT_DEBUG("Sending request failed: %s", strerror(-r));
+		CLIENT_WARN("Sending request failed: %s", strerror(-r));
 		goto error;
 	}
 
@@ -665,7 +674,7 @@ static void dhcp_client_address_add_cb(int error, uint16_t type,
 	if (error < 0 && error != -EEXIST) {
 		l_rtnl_address_free(client->rtnl_configured_address);
 		client->rtnl_configured_address = NULL;
-		CLIENT_DEBUG("Unable to set address on ifindex: %u: %d(%s)",
+		CLIENT_WARN("Unable to set address on ifindex: %u: %d(%s)",
 				client->ifindex, error,
 				strerror(-error));
 		return;
@@ -691,7 +700,7 @@ static int dhcp_client_receive_ack(struct l_dhcp_client *client,
 
 	lease = _dhcp_lease_parse_options(&iter);
 	if (!lease) {
-		CLIENT_DEBUG("Failed to parse DHCP options.");
+		CLIENT_WARN("Failed to parse DHCP options.");
 
 		return -ENOMSG;
 	}
@@ -746,7 +755,7 @@ static int dhcp_client_receive_ack(struct l_dhcp_client *client,
 		if (client->rtnl_add_cmdid)
 			client->rtnl_configured_address = a;
 		else {
-			CLIENT_DEBUG("Configuring address via RTNL failed");
+			CLIENT_WARN("Configuring address via RTNL failed");
 			l_rtnl_address_free(a);
 		}
 	}
@@ -785,7 +794,7 @@ static int dhcp_client_receive_offer(struct l_dhcp_client *client,
 			return -ENOMSG;
 		}
 
-		CLIENT_DEBUG("Server sent another offer, using it instead");
+		CLIENT_INFO("Server sent another offer, using it instead");
 
 		_dhcp_lease_free(client->lease);
 	}
@@ -890,7 +899,7 @@ static void dhcp_client_rx_message(const void *data, size_t len, void *userdata,
 	case DHCP_STATE_REBINDING:
 	receive_rapid_commit:
 		if (msg_type == DHCP_MESSAGE_TYPE_NAK) {
-			CLIENT_DEBUG("Received NAK, Stopping...");
+			CLIENT_INFO("Received NAK, Stopping...");
 			l_dhcp_client_stop(client);
 
 			dhcp_client_event_notify(client,
@@ -914,7 +923,7 @@ static void dhcp_client_rx_message(const void *data, size_t len, void *userdata,
 			e = client->transport->bind(client->transport,
 						client->lease->address);
 			if (e < 0) {
-				CLIENT_DEBUG("Failed to bind dhcp socket. "
+				CLIENT_WARN("Failed to bind dhcp socket. "
 					"Error %d: %s", e, strerror(-e));
 			}
 		}
@@ -940,7 +949,7 @@ static void dhcp_client_rx_message(const void *data, size_t len, void *userdata,
 			uint32_t next_timeout =
 					dhcp_fuzz_secs(client->lease->t1);
 
-			CLIENT_DEBUG("T1 expiring in %u ms", next_timeout);
+			CLIENT_INFO("T1 expiring in %u ms", next_timeout);
 			client->timeout_lease =
 				l_timeout_create_ms(next_timeout,
 							dhcp_client_t1_expired,
@@ -953,7 +962,7 @@ static void dhcp_client_rx_message(const void *data, size_t len, void *userdata,
 
 		client->acd = l_acd_new(client->ifindex);
 
-		if (client->debug_handler)
+		if (client->debug_handler && client->debug_level == L_LOG_DEBUG)
 			l_acd_set_debug(client->acd, client->debug_handler,
 					client->debug_data,
 					client->debug_destroy);
@@ -976,7 +985,7 @@ static void dhcp_client_rx_message(const void *data, size_t len, void *userdata,
 
 		/* For unit testing we don't want this to be a fatal error */
 		if (!l_acd_start(client->acd, buf)) {
-			CLIENT_DEBUG("Failed to start ACD on %s, continuing",
+			CLIENT_WARN("Failed to start ACD on %s, continuing",
 						buf);
 			l_acd_destroy(client->acd);
 			client->acd = NULL;
@@ -1290,7 +1299,7 @@ LIB_EXPORT bool l_dhcp_client_set_event_handler(struct l_dhcp_client *client,
 LIB_EXPORT bool l_dhcp_client_set_debug(struct l_dhcp_client *client,
 						l_dhcp_debug_cb_t function,
 						void *user_data,
-						l_dhcp_destroy_cb_t destroy)
+						l_dhcp_destroy_cb_t destroy, int priority)
 {
 	if (unlikely(!client))
 		return false;
@@ -1301,6 +1310,7 @@ LIB_EXPORT bool l_dhcp_client_set_debug(struct l_dhcp_client *client,
 	client->debug_handler = function;
 	client->debug_destroy = destroy;
 	client->debug_data = user_data;
+	client->debug_level = priority;
 
 	return true;
 }
diff --git a/ell/dhcp.h b/ell/dhcp.h
index 946bf63..b9c3480 100644
--- a/ell/dhcp.h
+++ b/ell/dhcp.h
@@ -102,7 +102,7 @@ bool l_dhcp_client_set_event_handler(struct l_dhcp_client *client,
 
 bool l_dhcp_client_set_debug(struct l_dhcp_client *client,
 				l_dhcp_debug_cb_t function,
-				void *user_data, l_dhcp_destroy_cb_t destroy);
+				void *user_data, l_dhcp_destroy_cb_t destroy, int priority);
 
 
 char *l_dhcp_lease_get_address(const struct l_dhcp_lease *lease);
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-17 17:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-17 17:10 [PATCH v2 1/3] dhcp: Add priority to logging Michael Johnson
  -- strict thread matches above, loose matches on Subject: below --
2022-05-17 17:02 Denis Kenzior
2022-05-17 16:56 Michael Johnson

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).