Commit Graph

53 Commits

Author SHA1 Message Date
James Prestwood 705898d1db monitor: include unistd.h in main.c
This fixes a build break on some systems, specifically the
raspberry Pi 3 (ARM):

monitor/main.c: In function ‘open_packet’:
monitor/main.c:176:3: error: implicit declaration of function ‘close’; did you mean ‘pclose’? [-Werror=implicit-function-declaration]
  176 |   close(fd);
      |   ^~~~~
      |   pclose
2024-01-04 12:18:05 -06:00
Denis Kenzior cfb468e44d monitor: Move iwmon reading logic into main.c
To support multiple nlmon sources, move the logic that reads from iwmon
device into main.c instead of nlmon.  nlmon.c now becomes agnostic of
how the packets are actually obtained.  Packets are fed in via
high-level APIs such as nlmon_print_rtnl, nlmon_print_genl,
nlmon_print_pae.
2024-01-02 10:59:38 -06:00
James Prestwood 13bdb5ee80 monitor: remove -F option
This is now handled automatically by setting read_only which
bypasses the family ID check.
2022-10-26 16:48:45 -05:00
James Prestwood ad51250835 monitor: allow parsing pcaps without -F option
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.
2022-10-26 16:48:21 -05:00
James Prestwood 5ebcc48814 monitor: pass config to nlmon_create
Expand nlmon_create to be useful for both pcaps and monitoring. Doing
this also lets iwmon filter pcaps based on --no-ies,rtnl,scan etc
flags since they are part of the config.
2022-10-26 16:47:46 -05:00
James Prestwood 72d35fc491 monitor: use int64_t type for NLMSG_NEXT length
Commit c7640f8346 was meant to fix a sign compare warning
in clang because NLMSG_NEXT internally compares the length
with nlmsghdr->nlmsg_len which is a u32. The problem is the
NLMSG_NEXT can underflow an unsigned value, hence why it
expects an int type to be passed in.

To work around this we can instead pass a larger sized
int64_t which the compiler allows since it can upgrade the
unsigned nlmsghdr->nlmsg_len. There is no underflow risk
with an int64_t either because the buffer used is much
smaller than what can fit in an int64_t.

Fixes: c7640f8346 ("monitor: fix integer comparison error (clang)")
2022-10-14 09:49:13 -05:00
Denis Kenzior 6dbde8121d monitor: Support short form of '--noies' option 2021-09-14 10:43:36 -05:00
Denis Kenzior 83e1265c6b monitor: Add --noies option
To help understand scanning results a bit better and cut down on scan
output add an option to not print the contents of the IEs.  Only the
SSID IE will be printed.
2021-02-02 12:04:53 -06:00
Will Dietz 6c2b10b118 monitor: Don't pass NULL as src to memcpy
Skip the memcpy when len = 0
2019-10-28 14:58:15 -05:00
Marcel Holtmann 152b56a12a treewide: Move the Intel copyright forward to 2019 2019-10-25 00:43:08 +02:00
Denis Kenzior e34af3cfac monitor: Reset rtnl to NULL after destruction 2019-10-17 11:51:54 -05:00
Denis Kenzior 39bb4d07ee monitor: Fix potential memory leak
In case l_netlink object was not created successfully, rtmmsg would
leak.
2019-10-17 11:28:11 -05:00
Denis Kenzior 140c626a4b monitor: Remove duplicate monitor_interface structure
The global structure was intended to be used, not the one local to the
main function.
2019-07-23 09:22:01 -05:00
Marcel Holtmann 1ca82f4e49 monitor: Fix length parameter of strncpy for kernel names 2019-04-30 16:59:28 +02:00
Marcel Holtmann 5d9278913f monitor: Fix includes for using with -std=c99 compiler option 2018-11-01 22:19:11 +01:00
Marcel Holtmann 72a64fa7fb build: Adjust to the latest ELL signal API changes 2018-11-01 22:09:19 +01:00
Marcel Holtmann a9c2d71874 monitor: Use l_get_be16 and l_put_be16 instead of open coding it 2018-11-01 21:28:55 +01:00
Marcel Holtmann 0689877858 monitor: Use l_main_run_with_signal instead of open coding it 2018-11-01 20:02:53 +01:00
Denis Kenzior ec365e52eb monitor: Fix valgrind warning
==24195== Syscall param socketcall.sendto(msg) points to uninitialised byte(s)
==24195==    at 0x4F3DBEF: sendto (in /lib64/libc-2.26.so)
==24195==    by 0x13A453: can_write_data (netlink.c:119)
==24195==    by 0x13866B: io_callback (io.c:149)
==24195==    by 0x137365: l_main_iterate (main.c:389)
==24195==    by 0x1374A3: l_main_run (main.c:436)
==24195==    by 0x113524: main (main.c:832)
==24195==  Address 0x5205f99 is 57 bytes inside a block of size 88 alloc'd
==24195==    at 0x4C2D0AF: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24195==    by 0x133931: l_malloc (util.c:62)
==24195==    by 0x13AEF3: l_netlink_send (netlink.c:411)
==24195==    by 0x112351: rtm_interface_send_message (main.c:276)
==24195==    by 0x1126F3: iwmon_interface_lookup (main.c:405)
==24195==    by 0x11351F: main (main.c:830)
==24195==  Uninitialised value was created by a heap allocation
==24195==    at 0x4C2D0AF: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24195==    by 0x133931: l_malloc (util.c:62)
==24195==    by 0x11217B: rtm_interface_send_message (main.c:234)
==24195==    by 0x1126F3: iwmon_interface_lookup (main.c:405)
==24195==    by 0x11351F: main (main.c:830)
2018-10-30 17:52:24 -05:00
Denis Kenzior 76c8fd9a2f monitor: Fix invalid use of l_free
==23290== Invalid read of size 4
==23290==    at 0x12D334: timeout_destroy (timeout.c:61)
==23290==    by 0x12CDD1: l_main_exit (main.c:466)
==23290==    by 0x111F3B: main (main.c:835)
==23290==  Address 0x5211d80 is 0 bytes inside a block of size 32 free'd
==23290==    at 0x4C2E1BB: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==23290==    by 0x111F36: main (main.c:833)
==23290==  Block was alloc'd at
==23290==    at 0x4C2CF8F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==23290==    by 0x12A74D: l_malloc (util.c:62)
==23290==    by 0x12D40F: timeout_create_with_nanoseconds (timeout.c:135)
==23290==    by 0x112A31: signal_handler (main.c:661)
==23290==    by 0x12D03A: signal_callback (signal.c:82)
==23290==    by 0x12CC6D: l_main_iterate (main.c:387)
==23290==    by 0x12CD3B: l_main_run (main.c:434)
==23290==    by 0x1121F2: main (main.c:821)
==23290==
==23290== Invalid read of size 8
==23290==    at 0x12D33B: timeout_destroy (timeout.c:64)
==23290==    by 0x12CDD1: l_main_exit (main.c:466)
==23290==    by 0x111F3B: main (main.c:835)
==23290==  Address 0x5211d90 is 16 bytes inside a block of size 32 free'd
==23290==    at 0x4C2E1BB: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==23290==    by 0x111F36: main (main.c:833)
==23290==  Block was alloc'd at
==23290==    at 0x4C2CF8F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==23290==    by 0x12A74D: l_malloc (util.c:62)
==23290==    by 0x12D40F: timeout_create_with_nanoseconds (timeout.c:135)
==23290==    by 0x112A31: signal_handler (main.c:661)
==23290==    by 0x12D03A: signal_callback (signal.c:82)
==23290==    by 0x12CC6D: l_main_iterate (main.c:387)
==23290==    by 0x12CD3B: l_main_run (main.c:434)
==23290==    by 0x1121F2: main (main.c:821)
==23290==
==23290== Invalid write of size 4
==23290==    at 0x12D33F: timeout_destroy (timeout.c:62)
==23290==    by 0x12CDD1: l_main_exit (main.c:466)
==23290==    by 0x111F3B: main (main.c:835)
==23290==  Address 0x5211d80 is 0 bytes inside a block of size 32 free'd
==23290==    at 0x4C2E1BB: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==23290==    by 0x111F36: main (main.c:833)
==23290==  Block was alloc'd at
==23290==    at 0x4C2CF8F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==23290==    by 0x12A74D: l_malloc (util.c:62)
==23290==    by 0x12D40F: timeout_create_with_nanoseconds (timeout.c:135)
==23290==    by 0x112A31: signal_handler (main.c:661)
==23290==    by 0x12D03A: signal_callback (signal.c:82)
==23290==    by 0x12CC6D: l_main_iterate (main.c:387)
==23290==    by 0x12CD3B: l_main_run (main.c:434)
==23290==    by 0x1121F2: main (main.c:821)
2018-10-30 15:47:57 -05:00
James Prestwood 5c5bfbb423 monitor: added scan/wiphy flags
Specifying --noscan will filter out any scan related packets
Specifying --nowiphy will filter out any "new wiphy" packets
2018-05-15 19:42:46 -05:00
Mat Martineau 0e108f9727 monitor: Remove GENL_ID_GENERATE
Kernel v4.10 and later no longer export GENL_ID_GENERATE (which was
defined as 0). iwd was using this symbol to check for unmodified local
values rather than to ask for a dynamically generated netlink ID anyway,
so it makes sense to use the value 0 directly. This will work with
kernels before and after the GENL_ID_GENERATE change.
2017-04-14 15:52:11 -05:00
Denis Kenzior 303490261f monitor: Add nortnl option to help output 2017-03-24 10:51:01 -05:00
Denis Kenzior d6a9b0f85a monitor: Add option to not print rtnl output 2016-07-13 10:14:28 -05:00
Denis Kenzior 6de565db05 monitor: Update to new l_main api 2016-06-09 09:39:03 -05:00
Marcel Holtmann 75ec08df73 monitor: Define ARPHRD_NETLINK if it not provided by system headers 2014-12-19 01:44:49 +01:00
Ravi kumar Veeramally deb80322ea monitor: Fix memory leak
Memory allocated l_timeout struct from l_timeout_create not being
freed.

==4184== HEAP SUMMARY:
==4184==     in use at exit: 32 bytes in 1 blocks
==4184==   total heap usage: 50 allocs, 49 frees, 39,902 bytes allocated
==4184==
==4184== 32 bytes in 1 blocks are definitely lost in loss record 1 of 1
==4184==    at 0x4C2ABA0: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4184==    by 0x40706D: l_malloc (util.c:62)
==4184==    by 0x408D9A: l_timeout_create (timeout.c:117)
==4184==    by 0x40896A: signal_callback (signal.c:82)
==4184==    by 0x408692: l_main_run (main.c:346)
==4184==    by 0x402474: main (main.c:797)
==4184==
==4184== LEAK SUMMARY:
==4184==    definitely lost: 32 bytes in 1 blocks
==4184==    indirectly lost: 0 bytes in 0 blocks
==4184==      possibly lost: 0 bytes in 0 blocks
==4184==    still reachable: 0 bytes in 0 blocks
==4184==         suppressed: 0 bytes in 0 blocks
2014-12-16 08:56:57 -06:00
Denis Kenzior d9768348d5 monitor: Always try to find an existing interface
Duplicate detection will happen when we try to create a new link.  The
newlink flags were updated to fail if the device already exists.
2014-10-04 21:31:58 -05:00
Denis Kenzior 046e49588e monitor: Fix minor coding style issues 2014-10-04 21:08:51 -05:00
Denis Kenzior 5fae2cc524 monitor: Fix whitespace
No spaces for indentation
2014-10-04 21:07:18 -05:00
Patrik Flykt 1d4ab8de47 monitor: Remove netlink monitor interface if created by iwmon
Send a RTM_DELLINK for the interface in use if it was created by iwmon.
As the main loop needs to be running when sending RTM_DELLINK, add a
timeout function for quitting the main loop.
2014-10-04 21:07:15 -05:00
Patrik Flykt 0b75b71555 monitor: Create netlink monitor interface if not found
If the netlink monitor interface is not found or did not have all needed
flags set, create one with the proper flags.
2014-10-04 20:58:46 -05:00
Denis Kenzior 73f5f0766d monitor: Fix memory leak
In the case that we use iwmon --interface nlmon
2014-10-04 20:50:16 -05:00
Denis Kenzior 38ab7511af monitor: minor coding style fix ups 2014-10-04 20:41:32 -05:00
Patrik Flykt 19e2132fce monitor: Lookup existing monitor interface via netlink
On startup, request a list of interfaces via netlink. Find out whether
an interface of type nlmon exists and use it if it has all the needed
flags set. The default name of the interface is 'nlmon', which can be
changed from the command line. If the interface name is in use and is
not an nlmon type, print out an error message and exit.
2014-10-04 19:56:01 -05:00
Marcel Holtmann 9fa506c237 monitor: Add option to provide nl80211 family identifier 2014-08-16 00:00:10 +02:00
Marcel Holtmann 18652f1f49 monitor: Add support for extracting family identifiers from traces 2014-08-15 23:38:37 +02:00
Marcel Holtmann d3f37628b0 monitor: Add support for writing combined PCAP trace files 2014-08-12 19:35:59 -07:00
Marcel Holtmann 581f00171d monitor: Skip packet from PCAP file if it is truncated 2014-08-12 00:40:07 -07:00
Marcel Holtmann a95c720d64 monitor: Decode the EAPoL packet headers of PAE frames 2014-08-10 20:20:13 -07:00
Marcel Holtmann a2a59e78fa monitor: Extract PAE port traffic out of PCAP files and decode it 2014-08-10 18:32:11 -07:00
Marcel Holtmann b4eb544355 monitor: Handle timestamp and real packet length information 2014-08-10 12:45:56 -07:00
Marcel Holtmann b91bb55206 monitor: Use packet buffer of 16 kilobytes to allow large frames 2014-08-10 12:25:20 -07:00
Marcel Holtmann 7a1bb1e953 monitor: Improve message and attribute display handling 2014-08-09 22:59:42 -07:00
Marcel Holtmann 9635f317c0 monitor: Add support for builtin pager functionality 2014-08-09 19:29:48 -07:00
Marcel Holtmann b5b292ee25 monitor: Terminate program when setup of netlink monitor failed 2014-08-09 12:32:29 -07:00
Marcel Holtmann 9694998f28 monitor: Minor typo fix in usage text 2014-08-08 15:20:24 -07:00
Marcel Holtmann 34f5c56199 monitor: Print program description and version 2014-08-07 01:01:28 +02:00
Marcel Holtmann 609cc86717 monitor: Do not abort when receiving unknown ARPHRD 2014-08-06 06:52:09 +02:00
Marcel Holtmann d484715a17 monitor: Check that protocol type is set to generic netlink 2014-08-06 00:12:20 +02:00