Skip to contentSkip to conversation

Using l_notice for low level IWD state information

RFC New James Prestwood 1 participant 6 messages Feb 15, 2024

lore
Share & tools
lore
#0 lore raw

v2 cover Using l_notice for low level IWD state information

v2:
* Removed use of station_debug_event for notice logs
* Added iwd_notice to wrap l_notice:
1. To aid in enforcement of the formatting
2. To make it easier to enforce proper notice use during patch review, so people aren't calling l_notice directly.
If we want a separate header for this thats fine, I just put it in iwd.h for now.
* Made notice events constant defines. Using enums would be nice but in order to specify and event + formatting string constant strings were the only simple way to do that without reading in each argument via va_args. If anyone has better ideas I'm open to them.
* Please don't merge this, I still want to get more events added and make sure its as easy as possible to write tooling before we upstream. With this RFC I merely wanted to get feedback on how we should do this, not necissarily specifics on what events we should/shouldn't be logging.

James Prestwood (5):
main: add runtime flag for setting the logger
iwd: add iwd_notice for special event/state type of logging
doc: document use of l_log APIs
station: use iwd_notice for state/event information
netdev: add notice events for connection timeouts

 doc/coding-style.txt | 15 +++++++++++++++
 src/iwd.h            | 13 +++++++++++++
 src/main.c           | 14 ++++++++++++--
 src/netdev.c         |  7 ++++---
 src/station.c        | 32 +++++++++++++++++++++++++-------
 5 files changed, 69 insertions(+), 12 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

RFC v2 1/5 main: add runtime flag for setting the logger

The --logger,-l flag can now be used to specify the logger type. Unset (default) will set log output to stderr as it is today. The other valid options are "syslog" and "journal".

---
 src/main.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
src/main.c +12 -2
index 3ce8340f..acbfdc0c 100644
@@ -63,6 +63,7 @@ static const char *nointerfaces;
 static const char *phys;
 static const char *nophys;
 static const char *debugopt;
+static const char *logger;
 static bool developeropt;
 static bool terminating;
 static bool nl80211_complete;
@@ -164,6 +165,7 @@ static const struct option main_options[] = {
 	{ "nointerfaces", required_argument, NULL, 'I' },
 	{ "phys",         required_argument, NULL, 'p' },
 	{ "nophys",       required_argument, NULL, 'P' },
+	{ "logger",       required_argument, NULL, 'l' },
 	{ "debug",        optional_argument, NULL, 'd' },
 	{ "help",         no_argument,       NULL, 'h' },
 	{ }
@@ -474,7 +476,7 @@ int main(int argc, char *argv[])
 	for (;;) {
 		int opt;
 
-		opt = getopt_long(argc, argv, "Ei:I:p:P:d::vh",
+		opt = getopt_long(argc, argv, "Ei:I:p:P:d::vhl:",
 							main_options, NULL);
 		if (opt < 0)
 			break;
@@ -503,6 +505,9 @@ int main(int argc, char *argv[])
 			else
 				debugopt = "*";
 			break;
+		case 'l':
+			logger = optarg;
+			break;
 		case 'v':
 			printf("%s\n", VERSION);
 			return EXIT_SUCCESS;
@@ -519,7 +524,12 @@ int main(int argc, char *argv[])
 		return EXIT_FAILURE;
 	}
 
-	l_log_set_stderr();
+	if (logger && !strcmp(logger, "syslog"))
+		l_log_set_syslog();
+	else if (logger && !strcmp(logger, "journal"))
+		l_log_set_journal();
+	else
+		l_log_set_stderr();
 
 	if (check_crypto() < 0)
 		return EXIT_FAILURE;
Signature · 1 line
2.34.1
#2 lore raw

RFC v2 2/5 iwd: add iwd_notice for special event/state type of logging

In reply to James Prestwood

iwd_notice is being added so modules can communicate internal state or event information via the NOTICE log level. This log level will be reserved in IWD for only these type of messages.

The iwd_notice macro aims to help enforce some formatting requirements for these type of log messages. The messages should be one or more comma-separated "key: value" pairs starting with "event: <name>" and followed by any additional info that pertains to that event.

iwd_notice only enforces the initial event key/value format and additional arguments are left to the caller to be formatted correctly.

---
 src/iwd.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
src/iwd.h +13 -0
index 1be20df3..e25b4c03 100644
@@ -42,3 +42,16 @@ const char *iwd_get_iface_blacklist(void);
 const char *iwd_get_phy_whitelist(void);
 const char *iwd_get_phy_blacklist(void);
 bool iwd_is_developer_mode(void);
+
+#define IWD_NOTICE_STATE		"state"
+#define IWD_NOTICE_CONNECT_INFO		"connect-info"
+#define IWD_NOTICE_ROAM_INFO		"roam-info"
+#define IWD_NOTICE_DISCONNECT_INFO	"disconnect-info"
+#define IWD_NOTICE_FT_ROAM_FAILED	"ft-roam-failed"
+#define IWD_NOTICE_CONNECT_FAILED	"connect-failed"
+#define IWD_NOTICE_AUTH_TIMEOUT		"authentication-timeout"
+#define IWD_NOTICE_ASSOC_TIMEOUT	"association-timeout"
+#define IWD_NOTICE_CONNECT_TIMEOUT	"connect-timeout"
+
+#define iwd_notice(event, ...) \
+	l_notice("event: " event ", " __VA_ARGS__)
Signature · 1 line
2.34.1
#3 lore raw

RFC v2 3/5 doc: document use of l_log APIs

In reply to James Prestwood

With the introduction of l_notice in IWD some guidelines need to be set for l_info, l_warn, l_error, l_debug and l_notice.

---
 doc/coding-style.txt | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
doc/coding-style.txt +15 -0
index bf0535c5..882de026 100644
@@ -317,6 +317,21 @@ Functions that are static should not be forward-declared.  The only exception
 to this rule is if a circular dependency condition exists, and the forward
 declaration cannot be avoided.
 
+M18: Use appropriate logging levels
+===================================
+An appropriate log level should be used depending on the type of message
+being logged. Logging is done using the l_log APIs in ELL:
+
+l_error   An unexpected condition ocurred. These are generally fatal to the
+          current connection/protocol that is running but not generally to IWD's
+          overall operation.
+l_warn    An unexpected, but non-fatal condition ocurred
+l_notice  Should not be used directly. This log level is reserved for special
+          event type notifications which is handled by iwd_notice().
+l_info    Information that is expected during normal operation. l_info's use
+          should be very limited so non-debug logs are concise
+l_debug   General debugging. These can be used relatively freely but should
+          provide some piece of useful information.
 
 O1: Shorten the name
 ====================
Signature · 1 line
2.34.1
#4 lore raw

RFC v2 4/5 station: use iwd_notice for state/event information

In reply to James Prestwood

For anyone debugging or trying to identify network infrastructure problems the IWD DBus API isn't all that useful and ultimately requires going through debug logs to figure out exactly what happened. Having a concise set of debug logs containing only relavent information would be very useful. In addition, having some kind of syntax for these logs to be parsed by tooling could automate these tasks.

This is being done, starting with station, by using iwd_notice which internally uses l_notice. The use of the notice log level
(5) in IWD will be strictly for the type of messages described above.

---
 src/station.c | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)
src/station.c +25 -7
index ea505ca2..51eee56e 100644
@@ -1561,9 +1561,9 @@ static void station_enter_state(struct station *station,
 	bool disconnected;
 	int ret;
 
-	l_debug("Old State: %s, new state: %s",
-			station_state_to_string(station->state),
-			station_state_to_string(state));
+	iwd_notice(IWD_NOTICE_STATE, "old: %s, new: %s",
+					station_state_to_string(station->state),
+					station_state_to_string(state));
 
 	station_debug_event(station, station_state_to_string(state));
 
@@ -2358,6 +2358,8 @@ static bool station_ft_work_ready(struct wiphy_radio_work_item *item)
 		break;
 	case -ENOENT:
 		station_debug_event(station, "ft-roam-failed");
+		iwd_notice(IWD_NOTICE_FT_ROAM_FAILED,
+				"status: authentication timeout");
 try_next:
 		station_transition_start(station);
 		break;
@@ -2384,8 +2386,10 @@ disassociate:
 		station_disassociated(station);
 		break;
 	default:
-		if (ret > 0)
+		if (ret > 0) {
+			iwd_notice(IWD_NOTICE_FT_ROAM_FAILED, "status: %d", ret);
 			goto try_next;
+		}
 
 		station_roam_failed(station);
 		break;
@@ -2457,8 +2461,10 @@ static bool station_try_next_transition(struct station *station,
 	struct handshake_state *new_hs;
 	struct ie_rsn_info cur_rsne, target_rsne;
 
-	l_debug("%u, target %s", netdev_get_ifindex(station->netdev),
-			util_address_to_string(bss->addr));
+	iwd_notice(IWD_NOTICE_ROAM_INFO, "bss: "MAC", signal: %d, load: %d/255",
+					MAC_STR(bss->addr),
+					bss->signal_strength / 100,
+					bss->utilization);
 
 	/* Reset AP roam flag, at this point the roaming behaves the same */
 	station->ap_directed_roaming = false;
@@ -2561,6 +2567,7 @@ static void station_roam_scan_triggered(int err, void *user_data)
 	}
 
 	station_debug_event(station, "roam-scan-triggered");
+	iwd_notice("roam-scan-triggered");
 
 	/*
 	 * Do not update the Scanning property as we won't be updating the
@@ -3159,6 +3166,8 @@ static bool station_retry_owe_default_group(struct station *station)
 static bool station_retry_with_reason(struct station *station,
 					uint16_t reason_code)
 {
+	iwd_notice(IWD_NOTICE_CONNECT_FAILED, "reason: %u", reason_code);
+
 	/*
 	 * We don't want to cause a retry and blacklist if the password was
 	 * incorrect. Otherwise we would just continue to fail.
@@ -3209,6 +3218,8 @@ static bool station_retry_with_status(struct station *station,
 	else
 		blacklist_add_bss(station->connected_bss->addr);
 
+	iwd_notice(IWD_NOTICE_CONNECT_FAILED, "status: %u", status_code);
+
 	return station_try_next_bss(station);
 }
 
@@ -3369,6 +3380,8 @@ static void station_disconnect_event(struct station *station, void *event_data)
 	case STATION_STATE_FT_ROAMING:
 	case STATION_STATE_FW_ROAMING:
 	case STATION_STATE_NETCONFIG:
+		iwd_notice(IWD_NOTICE_DISCONNECT_INFO, "reason: %u",
+					l_get_u16(event_data));
 		station_disassociated(station);
 		return;
 	default:
@@ -3508,7 +3521,12 @@ int __station_connect_network(struct station *station, struct network *network,
 		return r;
 	}
 
-	l_debug("connecting to BSS "MAC, MAC_STR(bss->addr));
+	iwd_notice(IWD_NOTICE_CONNECT_INFO, "ssid: %s, bss: "MAC", "
+					"signal: %d, load: %d/255",
+					network_get_ssid(network),
+					MAC_STR(bss->addr),
+					bss->signal_strength / 100,
+					bss->utilization);
 
 	station->connected_bss = bss;
 	station->connected_network = network;
Signature · 1 line
2.34.1
#5 lore raw

RFC v2 5/5 netdev: add notice events for connection timeouts

In reply to James Prestwood

The information specific to auth/assoc/connect timeouts isn't communicated to station so emit the notice events within netdev. We could communicate this to station by adding separate netdev events, but this does not seem worth it for this use case as these notice events aren't strictly limited to station.

---
 src/netdev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
src/netdev.c +4 -3
index 48fb15df..8a7ff092 100644
@@ -2639,7 +2639,8 @@ static void netdev_connect_event(struct l_genl_msg *msg, struct netdev *netdev)
 	}
 
 	if (timeout) {
-		l_warn("connect event timed out, reason=%u", timeout_reason);
+		iwd_notice(IWD_NOTICE_CONNECT_TIMEOUT, "reason: %u",
+				timeout_reason);
 		goto error;
 	}
 
@@ -2931,7 +2932,7 @@ static void netdev_authenticate_event(struct l_genl_msg *msg,
 	while (l_genl_attr_next(&attr, &type, &len, &data)) {
 		switch (type) {
 		case NL80211_ATTR_TIMED_OUT:
-			l_warn("authentication event timed out");
+			iwd_notice(IWD_NOTICE_AUTH_TIMEOUT);
 
 			if (auth_proto_auth_timeout(netdev->ap))
 				return;
@@ -3032,7 +3033,7 @@ static void netdev_associate_event(struct l_genl_msg *msg,
 	while (l_genl_attr_next(&attr, &type, &len, &data)) {
 		switch (type) {
 		case NL80211_ATTR_TIMED_OUT:
-			l_warn("association timed out");
+			iwd_notice(IWD_NOTICE_ASSOC_TIMEOUT);
 
 			if (auth_proto_assoc_timeout(netdev->ap))
 				return;
Signature · 1 line
2.34.1