Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 30 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c57a3ad
tools/nut-scanner/{scan_xml_http.c,scan_snmp.c,scan_nut.c,scan_ipmi.c…
jimklimov Jul 4, 2024
acfc878
tools/nut-scanner/nut-scanner.c: clarify some code comments [#2244]
jimklimov Jul 4, 2024
d7c2d40
tools/nut-scanner/nut-scanner.c: comment some TODO for IPv6 netmask p…
jimklimov Jul 4, 2024
11bf9c3
docs/man/nut-scanner.txt: update general wording about IP address opt…
jimklimov Jul 4, 2024
8d3305b
docs/man/nut-scanner.txt: update general markup
jimklimov Jul 4, 2024
ab34a10
docs/man/nut-scanner.txt: note that some protocols require IP address…
jimklimov Jul 4, 2024
286909f
tools/nut-scanner/nut-scanner.c, docs/man/nut-scanner.txt, NEWS.adoc:…
jimklimov Jul 4, 2024
70338b6
tools/nut-scanner/nut-scanner.c: use run*() methods for most of the n…
jimklimov Jul 4, 2024
d41e204
tools/nut-scanner/nutscan-device.c: protect nutscan_add_device_to_dev…
jimklimov Jul 4, 2024
8067751
tools/nut-scanner/nut-scanner.c: drop unused DEFAULT_TIMEOUT macro [#…
jimklimov Jul 4, 2024
f202955
docs/man/nut-scanner.txt: document that currently different IP range …
jimklimov Jul 4, 2024
511f9b5
tools/nut-scanner/Makefile.am, NEWS.adoc: expose more of libcommon* s…
jimklimov Jul 5, 2024
d5c3304
tools/nut-scanner/nut-scanner.c: use xcalloc() instead of hackarounds…
jimklimov Jul 5, 2024
18998e0
tools/nut-scanner/nutscan-ip.c: nutscan_cidr_to_ip(): update comments…
jimklimov Jul 5, 2024
a863a15
tools/nut-scanner/nutscan-ip.c: refactor to name IPv4 vars with a "4"…
jimklimov Jul 5, 2024
c8f4fe9
tools/nut-scanner/nut-scanner.c: quieter debug about add_ip_range() i…
jimklimov Jul 5, 2024
7b26627
drivers/libshut.c: libshut_open(): use static structs and memcpy() to…
jimklimov Jul 5, 2024
4597926
tools/nut-scanner/nut-scanner.c et al: prepare for `-m auto` mode wit…
jimklimov Jul 5, 2024
e8f9395
tools/nut-scanner/nut-scanner.c: upscale sockaddr flags to uintmax_t …
jimklimov Jul 5, 2024
b77f581
tools/nut-scanner/nut-scanner.c: retain getifaddrs() findings printou…
jimklimov Jul 5, 2024
d335387
tools/nut-scanner/nut-scanner.c: use fatalx() instead of hackarounds …
jimklimov Jul 5, 2024
0116847
tools/nut-scanner/nut-scanner.c: use pre-allocated struct sockaddr_in…
jimklimov Jul 5, 2024
4d2672b
tools/nut-scanner/nut-scanner.c: quieter debug about "Discovering get…
jimklimov Jul 5, 2024
de50f0c
tools/nut-scanner/nut-scanner.c: flush existing start_ip/end_ip befor…
jimklimov Jul 5, 2024
52157e4
tools/nut-scanner/nut-scanner.c: `-m auto`: implement actually conver…
jimklimov Jul 5, 2024
6f53345
tools/nut-scanner/nut-scanner.c: comment some TODOs [#2244]
jimklimov Jul 5, 2024
e9550ab
tools/nut-scanner/nut-scanner.c: `-m auto` discovery: use shorter add…
jimklimov Jul 5, 2024
92bbcec
tools/nut-scanner/nut-scanner.c: separate POSIX headers from WIN32 on…
jimklimov Jul 6, 2024
89bf574
tools/nut-scanner/nut-scanner.c, NEWS.adoc: neuter networking "-m aut…
jimklimov Jul 6, 2024
822dae0
tools/nut-scanner/nut-scanner.c: implement "-m auto{4,6}" modes to li…
jimklimov Jul 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ https://github.com/networkupstools/nut/milestone/11
+
NOTE: Currently both the long and short names for `libupsclient` should be
installed.
* newly added support to scan several IP addresses (single or ranges)
with the same call, by repeating command-line options; also `-m auto{,4,6}`
can be specified (once) to select IP (all, IPv4, IPv6) address ranges of
configured local network interfaces (currently not implemented for WIN32).
[issue #2244, PR #2509, PR #2513]
* bumped version of `libnutscan` to 2.5.2, it now includes a few more
methods and symbols from `libcommon`. [issue #2244, PR #2509]

- common code:
* introduced a `NUT_DEBUG_SYSLOG` environment variable to tweak activation
Expand Down
44 changes: 35 additions & 9 deletions docs/man/nut-scanner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,38 +78,59 @@ an 'end IP'. See specific SNMP OPTIONS for community and security settings.

*-M* | *--xml_scan*::
Scan XML/HTTP devices. Can broadcast a network message on the current network
interfaces to retrieve XML/HTTP capable devices. No IP required in this mode.
interface(s) to retrieve XML/HTTP capable devices. No IP required in this mode.
If IP address ranges are specified, they would be scanned instead of a broadcast.

*-O* | *--oldnut_scan*::
Scan NUT devices (i.e. upsd daemon) on IP ranging from 'start IP' to 'end IP'.

*-n* | *--nut_simulation_scan*::
Scan NUT simulated devices (.dev files in $CONFPATH).
Scan NUT simulated devices (`.dev` files in `$NUT_CONFPATH`).

*-A* | *--avahi_scan*::
Scan NUT servers using Avahi request on the current network interfaces.
No IP required.
Scan NUT servers using Avahi request on the current network interface(s).
No IP address options are required or used.

*-I* | *--ipmi_scan*::
Scan NUT compatible power supplies available via IPMI on the current host,
or over the network.
or over the network if IP address ranges are specified.

*-E* | *--eaton_serial* 'serial ports'::
Scan Eaton devices (XCP and SHUT) available via serial bus on the current host.
This option must be requested explicitly, even for a complete scan.
'serial ports' can be expressed in various forms:

+
- 'auto' to scan all serial ports.
- a single character indicating a port number ('0' (zero) for /dev/ttyS0 and
/dev/ttyUSB0 on Linux, '1' for COM1 on Windows, 'a' for /dev/ttya on Solaris...)
/dev/ttyUSB0 on Linux, '1' for COM1 on Windows, 'a' for /dev/ttya on Solaris...)
- a range of N characters, hyphen separated, describing the range of
ports using 'X-Y', where X and Y are characters referring to the port number.
ports using 'X-Y', where X and Y are characters referring to the port number.
- a single port name.
- a list of ports name, coma separated, like '/dev/ttyS1,/dev/ttyS4'.

NETWORK OPTIONS
---------------

NOTE: The networked buses (such as SNMP, NetXML, IPMI and "Old NUT") allow to
specify several IP (IPv4 or IPv6) address ranges, down to individual single
IP addresses. Normally a new range is specified by a set of one `-s` and one
`-e` options following each other (in any order). Lone or consecutive `-s` or
`-e` options present on the command line would translate to single-IP queries.
Also a `-m` option squashed between two `-s` and `-e` options would be a new
range, turning those two into single-IP queries. This feature does not by
itself recombine "neighboring" addresses into one range, nor even check for
duplicate or overlapping specifications.
+
Also note that some buses require IP address(es) to scan, and others have a
different behavior when exactly no addresses are specified (it is not currently
possible to mix the two behaviors in one invocation of the `nut-scanner` tool).
+
Finally note that currently even if multi-threaded support is available, each
range specification is a separate fan-out of queries constrained by the timeout.
Requests to scan many single IP addresses will take a while to complete, much
longer than if they were a single range. This will be hopefully fixed in later
releases.

*-t* | *--timeout* 'timeout'::
Set the network timeout in seconds. Default timeout is 5 seconds.

Expand All @@ -124,7 +145,12 @@ If this parameter is omitted, only the 'start IP' is scanned. If 'end IP' is
less than 'start IP', both parameters are internally permuted.

*-m* | *--mask_cidr* 'IP address/mask'::
Set a range of IP using CIDR notation.
Set a range of IP addresses by using CIDR notation.
+
A special form `-m auto` allows `nut-scanner` to detect local IP address(es)
and scan corresponding subnet(s) on supported platforms, and `-m auto4` or
`-m auto6` limits the selected addresses to IPv4 and IPv6 respectively. Only
the first "auto*" request would be honoured, others ignored with a warning.

NUT DEVICE OPTION
-----------------
Expand Down
3 changes: 2 additions & 1 deletion docs/nut.dict
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 3177 utf-8
personal_ws-1.1 en 3178 utf-8
AAC
AAS
ABI
Expand Down Expand Up @@ -754,6 +754,7 @@ NetInvent
NetPro
NetServer
NetUps
NetXML
Netman
NetworkUPSTools
Neus
Expand Down
41 changes: 4 additions & 37 deletions drivers/libshut.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,10 @@ static int libshut_open(
usb_ctrl_charbuf rdbuf, usb_ctrl_charbufsize rdlen))
{
int ret, res;
/* Below we cast this buffer as sometimes containing entried of type
* "struct device_descriptor_s" or "struct my_hid_descriptor".
* Currently both of these are sized "2", and I don't see a way
* to require a "max()" of such sizes to align for generally.
*/
usb_ctrl_char buf[20] __attribute__((aligned(4)));
char string[MAX_STRING_SIZE];
struct my_hid_descriptor *desc;
struct device_descriptor_s *dev_descriptor;
struct my_hid_descriptor desc_buf, *desc = &desc_buf;
struct device_descriptor_s dev_descriptor_buf, *dev_descriptor = &dev_descriptor_buf;

/* report descriptor */
usb_ctrl_char rdbuf[MAX_REPORT_SIZE];
Expand Down Expand Up @@ -470,21 +465,7 @@ static int libshut_open(
}

/* Get DEVICE descriptor */
#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_ALIGN)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wcast-align"
#endif
#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wcast-align"
#endif
dev_descriptor = (struct device_descriptor_s *)buf;
#ifdef __clang__
# pragma clang diagnostic pop
#endif
#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_ALIGN)
# pragma GCC diagnostic pop
#endif
memcpy(dev_descriptor, buf, sizeof(struct device_descriptor_s));
res = shut_get_descriptor(*arg_upsfd, USB_DT_DEVICE, 0, buf, USB_DT_DEVICE_SIZE);
/* res = shut_control_msg(devp, USB_ENDPOINT_IN+1, USB_REQ_GET_DESCRIPTOR,
(USB_DT_DEVICE << 8) + 0, 0, buf, 0x9, SHUT_TIMEOUT); */
Expand Down Expand Up @@ -587,21 +568,7 @@ static int libshut_open(
}

/* Get HID descriptor */
#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_ALIGN)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wcast-align"
#endif
#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wcast-align"
#endif
desc = (struct my_hid_descriptor *)buf;
#ifdef __clang__
# pragma clang diagnostic pop
#endif
#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_ALIGN)
# pragma GCC diagnostic pop
#endif
memcpy(desc, buf, sizeof(struct my_hid_descriptor));
res = shut_get_descriptor(*arg_upsfd, USB_DT_HID, hid_desc_index, buf, 0x9);
/* res = shut_control_msg(devp, USB_ENDPOINT_IN+1, USB_REQ_GET_DESCRIPTOR,
(USB_DT_HID << 8) + 0, 0, buf, 0x9, SHUT_TIMEOUT); */
Expand Down
4 changes: 2 additions & 2 deletions tools/nut-scanner/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ endif HAVE_WINDOWS
# object .so names would differ)
#
# libnutscan version information
libnutscan_la_LDFLAGS += -version-info 2:5:1
libnutscan_la_LDFLAGS += -version-info 2:5:2

# libnutscan exported symbols regex
# WARNING: Since the library includes parts of libcommon (as much as needed
Expand All @@ -94,7 +94,7 @@ libnutscan_la_LDFLAGS += -version-info 2:5:1
# copies of "nut_debug_level" making fun of our debug-logging attempts.
# One solution to tackle if needed for those cases would be to make some
# dynamic/shared libnutcommon (etc.)
libnutscan_la_LDFLAGS += -export-symbols-regex '^(nutscan_|nut_debug_level|s_upsdebugx|max_threads|curr_threads|nut_report_config_flags|upsdebugx_report_search_paths|nut_prepare_search_paths)'
libnutscan_la_LDFLAGS += -export-symbols-regex '^(nutscan_|nut_debug_level|s_upsdebugx|fatalx|xcalloc|snprintfcat|max_threads|curr_threads|nut_report_config_flags|upsdebugx_report_search_paths|nut_prepare_search_paths)'
libnutscan_la_CFLAGS = -I$(top_srcdir)/clients -I$(top_srcdir)/include \
$(LIBLTDL_CFLAGS) -I$(top_srcdir)/drivers

Expand Down
Loading
Loading