diff mbox series

monitor: allow parsing pcaps without -F option

Message ID 20221025160356.217578-1-prestwoj@gmail.com (mailing list archive)
State New
Headers show
Series monitor: allow parsing pcaps without -F option | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success

Commit Message

James Prestwood Oct. 25, 2022, 4:03 p.m. UTC
The -F option is undocumented but allows you to pass a nl80211
family ID so iwmon doesn't ignore messages which don't match the
systems nl80211 family ID (i.e. pcaps from other systems).

This is somewhat of a pain to use since its unclear what the other
system's family ID actually is until you run it though something
like wireshark. Instead iwmon can ignore the family ID when in
read mode which makes reading other systems pcap files automatic.
---
 monitor/main.c  | 2 +-
 monitor/nlmon.c | 6 ++++--
 monitor/nlmon.h | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)

Comments

Denis Kenzior Oct. 26, 2022, 7:59 p.m. UTC | #1
Hi James,

On 10/25/22 11:03, James Prestwood wrote:
> The -F option is undocumented but allows you to pass a nl80211
> family ID so iwmon doesn't ignore messages which don't match the
> systems nl80211 family ID (i.e. pcaps from other systems).

So should we remove -F option then as well?

> 
> This is somewhat of a pain to use since its unclear what the other
> system's family ID actually is until you run it though something
> like wireshark. Instead iwmon can ignore the family ID when in
> read mode which makes reading other systems pcap files automatic.
> ---
>   monitor/main.c  | 2 +-
>   monitor/nlmon.c | 6 ++++--
>   monitor/nlmon.h | 2 +-
>   3 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/monitor/main.c b/monitor/main.c
> index f0b16bbf..30aa06d2 100644
> --- a/monitor/main.c
> +++ b/monitor/main.c

<snip>

> @@ -7261,6 +7262,7 @@ struct nlmon *nlmon_create(uint16_t id)
>   
>   	nlmon->id = id;
>   	nlmon->req_list = l_queue_new();
> +	nlmon->read = true;

did you intend read = read_only; here?

>   
>   	return nlmon;
>   }

Regards,
-Denis
diff mbox series

Patch

diff --git a/monitor/main.c b/monitor/main.c
index f0b16bbf..30aa06d2 100644
--- a/monitor/main.c
+++ b/monitor/main.c
@@ -586,7 +586,7 @@  static int process_pcap(struct pcap *pcap, uint16_t id)
 		return EXIT_FAILURE;
 	}
 
-	nlmon = nlmon_create(id);
+	nlmon = nlmon_create(id, true);
 
 	while (pcap_read(pcap, &tv, buf, snaplen, &len, &real_len)) {
 		uint16_t arphrd_type;
diff --git a/monitor/nlmon.c b/monitor/nlmon.c
index 69e86ce3..f2db47a8 100644
--- a/monitor/nlmon.c
+++ b/monitor/nlmon.c
@@ -104,6 +104,7 @@  struct nlmon {
 	bool nowiphy;
 	bool noscan;
 	bool noies;
+	bool read;
 };
 
 struct nlmon_req {
@@ -7202,7 +7203,7 @@  static void nlmon_message(struct nlmon *nlmon, const struct timeval *tv,
 		return;
 	}
 
-	if (nlmsg->nlmsg_type != nlmon->id) {
+	if (!nlmon->read && nlmsg->nlmsg_type != nlmon->id) {
 		if (nlmsg->nlmsg_type == GENL_ID_CTRL)
 			store_message(nlmon, tv, nlmsg);
 		return;
@@ -7253,7 +7254,7 @@  static void nlmon_message(struct nlmon *nlmon, const struct timeval *tv,
 	}
 }
 
-struct nlmon *nlmon_create(uint16_t id)
+struct nlmon *nlmon_create(uint16_t id, bool read_only)
 {
 	struct nlmon *nlmon;
 
@@ -7261,6 +7262,7 @@  struct nlmon *nlmon_create(uint16_t id)
 
 	nlmon->id = id;
 	nlmon->req_list = l_queue_new();
+	nlmon->read = true;
 
 	return nlmon;
 }
diff --git a/monitor/nlmon.h b/monitor/nlmon.h
index ab038fdf..69391b85 100644
--- a/monitor/nlmon.h
+++ b/monitor/nlmon.h
@@ -36,7 +36,7 @@  struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname,
 				const struct nlmon_config *config);
 void nlmon_close(struct nlmon *nlmon);
 
-struct nlmon *nlmon_create(uint16_t id);
+struct nlmon *nlmon_create(uint16_t id, bool read_only);
 void nlmon_destroy(struct nlmon *nlmon);
 void nlmon_print_rtnl(struct nlmon *nlmon, const struct timeval *tv,
 					const void *data, uint32_t size);