From: Denis Kenzior <denkenz@gmail.com>
To: iwd@lists.linux.dev
Cc: Denis Kenzior <denkenz@gmail.com>
Subject: [PATCH 3/5] monitor: Use nlmon_print_* inside nlmon_receive
Date: Wed, 27 Dec 2023 00:09:48 -0600 [thread overview]
Message-ID: <20231227060954.103572-3-denkenz@gmail.com> (raw)
In-Reply-To: <20231227060954.103572-1-denkenz@gmail.com>
The current implementation inside nlmon_receive is asymmetrical. RTNL
packets are printed using nlmon_print_rtnl while GENL packets are
printed using nlmon_message.
nlmon_print_genl and nlmon_print_rtnl already handle iterating over data
containing multiple messages, and are used by nlmon started in reader
mode. Use these for better symmetry inside nlmon_receive.
While here, move store_netlink() call into nlmon_print_rtnl. This makes
handling of PCAP output symmetrical for both RTNL and GENL packets.
This also fixes a possibility where only the first message of a
multi-RTNL packet would be stored.
---
monitor/nlmon.c | 44 ++++++++++++++++++--------------------------
1 file changed, 18 insertions(+), 26 deletions(-)
diff --git a/monitor/nlmon.c b/monitor/nlmon.c
index b4d1f54c7579..72cd8ca7a05c 100644
--- a/monitor/nlmon.c
+++ b/monitor/nlmon.c
@@ -7280,12 +7280,6 @@ static void nlmon_message(struct nlmon *nlmon, const struct timeval *tv,
return;
}
- if (!nlmon->read && nlmsg->nlmsg_type != nlmon->id) {
- if (nlmsg->nlmsg_type == GENL_ID_CTRL)
- store_message(nlmon, tv, nlmsg);
- return;
- }
-
if (nlmsg->nlmsg_flags & NLM_F_REQUEST) {
const struct genlmsghdr *genlmsg = NLMSG_DATA(nlmsg);
uint32_t flags = nlmsg->nlmsg_flags & ~NLM_F_REQUEST;
@@ -8137,13 +8131,15 @@ void nlmon_print_rtnl(struct nlmon *nlmon, const struct timeval *tv,
int64_t aligned_size = NLMSG_ALIGN(size);
const struct nlmsghdr *nlmsg;
- if (nlmon->nortnl)
- return;
-
update_time_offset(tv);
for (nlmsg = data; NLMSG_OK(nlmsg, aligned_size);
nlmsg = NLMSG_NEXT(nlmsg, aligned_size)) {
+ store_netlink(nlmon, tv, NETLINK_ROUTE, nlmsg);
+
+ if (nlmon->nortnl)
+ continue;
+
switch (nlmsg->nlmsg_type) {
case NLMSG_NOOP:
case NLMSG_OVERRUN:
@@ -8177,7 +8173,12 @@ void nlmon_print_genl(struct nlmon *nlmon, const struct timeval *tv,
for (nlmsg = data; NLMSG_OK(nlmsg, size);
nlmsg = NLMSG_NEXT(nlmsg, size)) {
- if (nlmsg->nlmsg_type == GENL_ID_CTRL)
+ if (nlmsg->nlmsg_type == GENL_ID_CTRL) {
+ store_message(nlmon, tv, nlmsg);
+ continue;
+ }
+
+ if (!nlmon->read && nlmsg->nlmsg_type != nlmon->id)
continue;
nlmon_message(nlmon, tv, nlmsg);
@@ -8187,7 +8188,6 @@ void nlmon_print_genl(struct nlmon *nlmon, const struct timeval *tv,
static bool nlmon_receive(struct l_io *io, void *user_data)
{
struct nlmon *nlmon = user_data;
- struct nlmsghdr *nlmsg;
struct msghdr msg;
struct sockaddr_ll sll;
struct iovec iov;
@@ -8198,7 +8198,6 @@ static bool nlmon_receive(struct l_io *io, void *user_data)
unsigned char buf[8192];
unsigned char control[32];
ssize_t bytes_read;
- int64_t nlmsg_len;
int fd;
fd = l_io_get_fd(io);
@@ -8241,20 +8240,13 @@ static bool nlmon_receive(struct l_io *io, void *user_data)
}
}
- nlmsg_len = bytes_read;
-
- for (nlmsg = iov.iov_base; NLMSG_OK(nlmsg, nlmsg_len);
- nlmsg = NLMSG_NEXT(nlmsg, nlmsg_len)) {
- switch (proto_type) {
- case NETLINK_ROUTE:
- store_netlink(nlmon, tv, proto_type, nlmsg);
-
- nlmon_print_rtnl(nlmon, tv, nlmsg, nlmsg->nlmsg_len);
- break;
- case NETLINK_GENERIC:
- nlmon_message(nlmon, tv, nlmsg);
- break;
- }
+ switch (proto_type) {
+ case NETLINK_ROUTE:
+ nlmon_print_rtnl(nlmon, tv, iov.iov_base, bytes_read);
+ break;
+ case NETLINK_GENERIC:
+ nlmon_print_genl(nlmon, tv, iov.iov_base, bytes_read);
+ break;
}
return true;
--
2.43.0
next prev parent reply other threads:[~2023-12-27 6:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-27 6:09 [PATCH 1/5] monitor: Remove unused code path Denis Kenzior
2023-12-27 6:09 ` [PATCH 2/5] monitor: Remove unused PACKET_AUXDATA handling Denis Kenzior
2023-12-27 6:09 ` Denis Kenzior [this message]
2023-12-27 6:09 ` [PATCH 4/5] monitor: Move iwmon reading logic into main.c Denis Kenzior
2023-12-27 6:09 ` [PATCH 5/5] RFC: Initial iwtrace utility Denis Kenzior
2024-01-02 13:30 ` James Prestwood
2024-01-02 17:01 ` [PATCH 1/5] monitor: Remove unused code path Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231227060954.103572-3-denkenz@gmail.com \
--to=denkenz@gmail.com \
--cc=iwd@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox