Skip to content

Teach nut-scanner to discover locally connected subnets: implement -m auto mode#2513

Merged
jimklimov merged 30 commits intonetworkupstools:masterfrom
jimklimov:issue-2244-auto
Jul 8, 2024
Merged

Teach nut-scanner to discover locally connected subnets: implement -m auto mode#2513
jimklimov merged 30 commits intonetworkupstools:masterfrom
jimklimov:issue-2244-auto

Conversation

@jimklimov
Copy link
Copy Markdown
Member

Follow-up from PR #2509 for issue #2244 to complete the feature. Separated because of need for longer testing and adaptation to different platforms and certain questions raised in #2509, while that PR has value of its own and can be merged to already allow multiple IP address range scans with one call to the tool.

Closes: #2244

jimklimov added 26 commits July 5, 2024 00:05
…}: report the IP address (range, single, none) in the log [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…roper support [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…ions [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
… options and others behave differently without them [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
… introduce a way to scan several IP address ranges [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…on-threaded scans too [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…ice() from adding a list to itself

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…etworkupstools#2244]

We actually use DEFAULT_NETWORK_TIMEOUT from common.h
same as in clients/upsclient.c

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…scans do not parallelize together [networkupstools#2244]

See also: networkupstools#2511

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…ymbols in libnutscan to use them in nut-scanner [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
… and logged reports to help troubleshooting [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
… in the name, and use static structs and memcpy() to actually fix alignment warnings [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…n-/semi-valid inputs [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
… actually fix alignment warnings

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…h detection of configured network interfaces

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…for debug printouts to be predictable on different platforms [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…t as a real upsdebugx() trail [networkupstools#2244]

Originally I intended to use these to check that the address parsing
code works, and drop the printf() of these messages. But if I collect
them into a string and upsdebug() it - why not, can help troubleshooting
in real life later, too.

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…{,6} so it is aligned how-ever the platform likes [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…ifaddrs()" [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…e handling whatever value of `-m` option [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…ting discovered subnets into CIDR and adding to IP ranges for scanning [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov jimklimov added enhancement Windows nut-scanner portability We want NUT to build and run everywhere possible labels Jul 5, 2024
@jimklimov jimklimov added the impacts-release-2.8.2 Issues reported against NUT release 2.8.2 (maybe vanilla or with minor packaging tweaks) label Jul 5, 2024
@jimklimov jimklimov added this to the 2.8.3 milestone Jul 5, 2024
…r/mask buffers [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@AppVeyorBot
Copy link
Copy Markdown

@jimklimov
Copy link
Copy Markdown
Member Author

For WIN32 different methods are needed, mingw does not provide the POSIXish types and methods here:

For now will shunt the feature to have checkable it on POSIX systems at least.

@jimklimov jimklimov added the Windows-not-on-par-with-POSIX Aspect of Windows builds known to be dysfunctional compared to POSIX builds; fix needed to be on par label Jul 6, 2024
jimklimov added 3 commits July 6, 2024 03:18
…es (for networking "-m auto" support) [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…o" support for WIN32 (needs different implementation) [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…mit selection of ranges to IPv4/IPv6 only [networkupstools#2244]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov
Copy link
Copy Markdown
Member Author

jimklimov commented Jul 6, 2024

Added -m auto4 and -m auto6 support for good measure, while thinking how to constrain link-local addresses (especially IPv6). Although a proper home LAN addressed with a /64 in IPv6 is also not too friendly. The scan would finish about when our sun would...

Worked "as is" even on MacOS:

   0.038557     [D5] add_ip_range: only start address was provided, setting end to same: 1.2.3.4
   0.038562     [D1] Recorded IP address range #1: [1.2.3.4 .. 1.2.3.4]
   0.038567     [D1] Recorded IP address range #2: [1.1.1.1 .. 1.1.1.3]
   0.038572     [D5] Processing CIDR net/mask: xxx.yyy.zzz.0/24
   0.038580     [D5] nutscan_cidr_to_ip: parsed cidr=xxx.yyy.zzz.0/24 into first_ip=xxx.yyy.zzz.0 and mask=24
   0.038584     [D5] nutscan_cidr_to_ip: parsed mask into numeric value 24
   0.039024     [D5] Extracted IP address range from CIDR net/mask: xxx.yyy.zzz.0 => xxx.yyy.zzz.255
   0.039034     [D1] Recorded IP address range #3: [xxx.yyy.zzz.0 .. xxx.yyy.zzz.255]
   0.039039     [D5] Processing CIDR net/mask: 127.0.0.0/28
   0.039043     [D5] nutscan_cidr_to_ip: parsed cidr=127.0.0.0/28 into first_ip=127.0.0.0 and mask=28
   0.039047     [D5] nutscan_cidr_to_ip: parsed mask into numeric value 28
   0.039067     [D5] Extracted IP address range from CIDR net/mask: 127.0.0.0 => 127.0.0.15
   0.039071     [D1] Recorded IP address range #4: [127.0.0.0 .. 127.0.0.15]
   0.039134     [D5] Discovering getifaddrs(): Interface: lo0   Address: 127.0.0.1      Mask: 255.0.0.0 (len: 8)        Flags: 00008049 IFF_LOOPBACK IFF_UP IFF_RUNNING
   0.039144     [D5] Discovering getifaddrs(): Interface: lo0   Address: ::1    Mask: ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (len: 128)        Flags: 00008049 IFF_LOOPBACK IFF_UP IFF_RUNNING
   0.039202     [D5] Discovering getifaddrs(): Interface: lo0   Address: fe80::1%lo0    Mask: ffff:ffff:ffff:ffff:: (len: 64)   Flags: 00008049 IFF_LOOPBACK IFF_UP IFF_RUNNING
   0.039430     [D5] Discovering getifaddrs(): Interface: en0   Address: fe80::c62:892:6b4:b33c%en0     Mask: ffff:ffff:ffff:ffff:: (len: 64)   Flags: 00008863 IFF_UP IFF_RUNNING IFF_BROADCAST(is assigned)
   0.039441     [D5] Discovering getifaddrs(): Interface: en0   Address: xxxx:xxxx:xxxx:xxxx:861:485d:efed:87cf  Mask: ffff:ffff:ffff:ffff:: (len: 64)   Flags: 00008863 IFF_UP IFF_RUNNING IFF_BROADCAST(is assigned)
   0.039450     [D5] Discovering getifaddrs(): Interface: en0   Address: xxxx:xxxx:xxxx:xxxx:cc11:dda1:ac0a:b8b0 Mask: ffff:ffff:ffff:ffff:: (len: 64)   Flags: 00008863 IFF_UP IFF_RUNNING IFF_BROADCAST(is assigned)
   0.039457     [D5] Discovering getifaddrs(): Interface: en0   Address: xxx.yyy.zzz.233   Mask: 255.255.255.0 (len: 24)   Flags: 00008863 IFF_UP IFF_RUNNING IFF_BROADCAST(is assigned)
   0.039461     [D5] Processing CIDR net/mask: xxx.yyy.zzz.233/24
   0.039465     [D5] nutscan_cidr_to_ip: parsed cidr=xxx.yyy.zzz.233/24 into first_ip=xxx.yyy.zzz.233 and mask=24
   0.039469     [D5] nutscan_cidr_to_ip: parsed mask into numeric value 24
   0.039576     [D5] Extracted IP address range from CIDR net/mask: xxx.yyy.zzz.0 => xxx.yyy.zzz.255
   0.039583     [D1] Recorded IP address range #5: [xxx.yyy.zzz.0 .. xxx.yyy.zzz.255]
   0.039592     [D5] Discovering getifaddrs(): Interface: en0   Address: xxxx:xxxx:xxxx:xxxx:18db:78f6:d7f0:2c47 Mask: ffff:ffff:ffff:ffff:: (len: 64)   Flags: 00008863 IFF_UP IFF_RUNNING IFF_BROADCAST(is assigned)
   0.039674     [D5] Discovering getifaddrs(): Interface: utun0 Address: fe80::4f3b:c861:4198:2b5%utun0 Mask: ffff:ffff:ffff:ffff:: (len: 64)   Flags: 00008051 IFF_UP IFF_RUNNING
   0.039748     [D5] Discovering getifaddrs(): Interface: utun1 Address: fe80::8c5d:8b9e:de76:1807%utun1        Mask: ffff:ffff:ffff:ffff:: (len: 64)   Flags: 00008051 IFF_UP IFF_RUNNING
   0.039821     [D5] Discovering getifaddrs(): Interface: utun2 Address: fe80::ce81:b1c:bd2c:69e%utun2  Mask: ffff:ffff:ffff:ffff:: (len: 64)   Flags: 00008051 IFF_UP IFF_RUNNING

For that matter, to filter usable addresses by flags on MacOS, there seems to be a difference of temporary(+deprecated?) and secured addresses:

en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        options=463<RXCSUM,TXCSUM,TSO4,TSO6,CHANNEL_IO>
        ether ee:4e:36:60:39:dc
        inet6 fe80::c62:892:6b4:b33c%en0 prefixlen 64 secured scopeid 0x4
        inet6 xxxx:xxxx:xxxx:xxxx:861:485d:efed:87cf prefixlen 64 autoconf secured
        inet6 xxxx:xxxx:xxxx:xxxx:cc11:dda1:ac0a:b8b0 prefixlen 64 deprecated autoconf temporary
        inet xxx.yyy.zzz.233 netmask 0xffffff00 broadcast xxz.yyy.zzz.255
        inet6 xxxx:xxxx:xxxx:xxxx:18db:78f6:d7f0:2c47 prefixlen 64 deprecated autoconf temporary
        inet6 xxxx:xxxx:xxxx:xxxx:515f:c4e9:239b:11ec prefixlen 64 deprecated autoconf temporary
        inet6 xxxx:xxxx:xxxx:xxxx:6592:9558:474b:2a72 prefixlen 64 deprecated autoconf temporary
        inet6 xxxx:xxxx:xxxx:xxxx:e94b:cf66:815f:6b9b prefixlen 64 autoconf temporary
        nd6 options=201<PERFORMNUD,DAD>
        media: autoselect <full-duplex,flow-control>
        status: active

@AppVeyorBot
Copy link
Copy Markdown

@jimklimov jimklimov merged commit 4a71a9b into networkupstools:master Jul 8, 2024
@jimklimov jimklimov deleted the issue-2244-auto branch July 8, 2024 06:44
@jimklimov jimklimov restored the issue-2244-auto branch April 15, 2025 09:41
@jimklimov jimklimov deleted the issue-2244-auto branch April 15, 2025 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement impacts-release-2.8.2 Issues reported against NUT release 2.8.2 (maybe vanilla or with minor packaging tweaks) nut-scanner portability We want NUT to build and run everywhere possible Windows Windows-not-on-par-with-POSIX Aspect of Windows builds known to be dysfunctional compared to POSIX builds; fix needed to be on par

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nut-scanner network scans should provide a "-m auto" option

2 participants