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 -m auto*/ADDRLEN modes #2517

Merged
merged 21 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d20f9ab
tools/nut-scanner/nut-scanner.c: refactor handle_arg_cidr() into a se…
jimklimov Jul 8, 2024
54c2365
tools/nut-scanner/nut-scanner.c: refactor handle_arg_cidr() logic to …
jimklimov Jul 8, 2024
45d8730
tools/nut-scanner/nut-scanner.c: handle_arg_cidr(): tabs (style) [#2244]
jimklimov Jul 8, 2024
5c1d4b0
tools/nut-scanner/nut-scanner.c: handle_arg_cidr(): line-wrap long pr…
jimklimov Jul 8, 2024
065002c
tools/nut-scanner/nut-scanner.c: handle_arg_cidr(): log why some disc…
jimklimov Jul 8, 2024
e91412e
tools/nut-scanner/nut-scanner.c, docs/man/nut-scanner.txt, docs/nut.d…
jimklimov Jul 8, 2024
c2f5221
tools/nut-scanner/nut-scanner.c: handle_arg_cidr() rename "optarg" to…
jimklimov Jul 8, 2024
58a4e23
tools/nut-scanner/nut-scanner.c: handle_arg_cidr(): report ignoring a…
jimklimov Jul 8, 2024
b116f75
tools/nut-scanner/nut-scanner.c: handle_arg_cidr(): fix to use strtol…
jimklimov Jul 8, 2024
60c4d33
tools/nut-scanner/nut-scanner.c: `-t timeout`: fix to use strtol() no…
jimklimov Jul 8, 2024
2777423
tools/nut-scanner/nut-scan.h: move __cplusplus extern "C" guard up to…
jimklimov Jul 8, 2024
50471bb
tools/nut-scanner/nut-scanner.c, tools/nut-scanner/nutscan-ip.h: move…
jimklimov Jul 8, 2024
644bb3a
nut-scanner code and docs: refactor with nutscan_ip_range_list_t type…
jimklimov Jul 8, 2024
4aa4ecb
Merge branch 'issue-2244-ext' into issue-2244
jimklimov Jul 8, 2024
cfeec4e
docs/man/nut-scanner.txt: clarify about text host names as start/stop…
jimklimov Jul 8, 2024
d05e768
docs/man/Makefile.am: move a comment up to cover more relevant entries
jimklimov Jul 8, 2024
fd74b20
docs/man/Makefile.am: extend HTML_DEV_MANS_FICTION to be on par with …
jimklimov Jul 8, 2024
fe90f6b
docs/man/nutscan_add_ip_range.txt: fix copy-paste typo in title [#224…
jimklimov Jul 8, 2024
2ddd4c5
docs/man/nutscan_add_ip_range.txt: update wording and structure comme…
jimklimov Jul 8, 2024
d968dff
tools/nut-scanner/nutscan-ip.c: fix comment markup
jimklimov Jul 8, 2024
bf8cc0d
tools/nut-scanner/nutscan-ip.h: add nutscan_ip_range_list_t structure…
jimklimov Jul 8, 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
5 changes: 4 additions & 1 deletion NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ installed.
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]
An `/ADDRLEN` suffix can be added to the option, to filter out discovered
subnets with too many bits available for the host address part (avoiding
millions of scans in the extreme cases).
[issue #2244, PR #2509, PR #2513, PR #2517]
* bumped version of `libnutscan` to 2.5.2, it now includes a few more
methods and symbols from `libcommon`. [issue #2244, PR #2509]

Expand Down
19 changes: 18 additions & 1 deletion docs/man/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ SRC_DEV_PAGES = \
nutscan_display_ups_conf_with_sanity_check.txt \
nutscan_display_ups_conf.txt \
nutscan_display_parsable.txt \
nutscan_init_ip_ranges.txt \
nutscan_free_ip_ranges.txt \
nutscan_add_ip_range.txt \
nutscan_cidr_to_ip.txt \
nutscan_new_device.txt \
nutscan_free_device.txt \
Expand Down Expand Up @@ -316,6 +319,9 @@ MAN3_DEV_PAGES = \
nutscan_display_ups_conf_with_sanity_check.3 \
nutscan_display_ups_conf.3 \
nutscan_display_parsable.3 \
nutscan_init_ip_ranges.3 \
nutscan_free_ip_ranges.3 \
nutscan_add_ip_range.3 \
nutscan_cidr_to_ip.3 \
nutscan_new_device.3 \
nutscan_free_device.3 \
Expand All @@ -325,13 +331,13 @@ MAN3_DEV_PAGES = \
nutscan_get_serial_ports_list.3 \
nutscan_init.3

# Alias page for one text describing two commands:
upscli_readline_timeout.3: upscli_readline.3
touch $@

upscli_sendline_timeout.3: upscli_sendline.3
touch $@

# Alias page for one text describing two commands:
nutscan_add_commented_option_to_device.3: nutscan_add_option_to_device.3
touch $@

Expand Down Expand Up @@ -391,6 +397,9 @@ HTML_DEV_MANS = \
nutscan_display_ups_conf_with_sanity_check.html \
nutscan_display_ups_conf.html \
nutscan_display_parsable.html \
nutscan_init_ip_ranges.html \
nutscan_free_ip_ranges.html \
nutscan_add_ip_range.html \
nutscan_cidr_to_ip.html \
nutscan_new_device.html \
nutscan_free_device.html \
Expand All @@ -405,8 +414,16 @@ HTML_DEV_MANS = \
# Can't make this work on all make implementations at once, so disabled for now
# Anyway it would be the same man-like page for several functions
HTML_DEV_MANS_FICTION = \
upscli_readline_timeout.html \
upscli_sendline_timeout.html \
nutscan_add_commented_option_to_device.html

upscli_readline_timeout.html: upscli_readline.html
test -n "$?" -a -s "$@" && rm -f $@ && ln -s $? $@

upscli_sendline_timeout.html: upscli_sendline.html
test -n "$?" -a -s "$@" && rm -f $@ && ln -s $? $@

nutscan_add_commented_option_to_device.html: nutscan_add_option_to_device.html
test -n "$?" -a -s "$@" && rm -f $@ && ln -s $? $@

Expand Down
13 changes: 13 additions & 0 deletions docs/man/nut-scanner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ 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).
+
A single-address range may be a host name which would be resolved into one IP
address by the system resolver. A CIDR using a host name and netmask length
would be resolved into an IP address and subjected to the mask application,
to query hosts "near" the named one.
+
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
Expand All @@ -151,6 +156,14 @@ 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.
+
An `/ADDRLEN` suffix can be added to the option, to filter out discovered
subnets with too many bits available for the host address part (avoiding
millions of scans in the extreme cases). For example, if your IPv4 LAN's
network range is `10.2.3.0/24`, its address part is `(32-24)=8`. Note that
while this is applied to IPv6 networks also, their typical `/64` subnets
are not likely to have a NUT/SNMP/NetXML/... server *that* close nearby
(in addressing terms), for a tight filter to find them. Default is `8`.

NUT DEVICE OPTION
-----------------
Expand Down
3 changes: 3 additions & 0 deletions docs/man/nutscan.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ linkman:nutscan_display_parsable[3], linkman:nutscan_display_ups_conf[3],
linkman:nutscan_new_device[3], linkman:nutscan_free_device[3],
linkman:nutscan_add_device_to_device[3],
linkman:nutscan_add_option_to_device[3],
linkman:nutscan_init_ip_ranges[3],
linkman:nutscan_free_ip_ranges[3],
linkman:nutscan_add_ip_range[3],
linkman:nutscan_cidr_to_ip[3]

Internet resources:
Expand Down
74 changes: 74 additions & 0 deletions docs/man/nutscan_add_ip_range.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
NUTSCAN_ADD_IP_RANGE(3)
=======================

NAME
----

nutscan_add_ip_range - Add an entry with IP address range (starting
and ending addresses) to a `nutscan_ip_range_list_t` structure.

SYNOPSIS
--------

#include <nut-scan.h>

/* One IP address range: */
typedef struct nutscan_ip_range_s {
char * start_ip;
char * end_ip;
struct nutscan_ip_range_s * next;
} nutscan_ip_range_t;

/* List of IP address ranges and helper data: */
typedef struct nutscan_ip_range_list_s {
nutscan_ip_range_t * ip_ranges; /* Actual linked list of entries, first entry */
nutscan_ip_range_t * ip_ranges_last; /* Pointer to end of list for quicker additions */
size_t ip_ranges_count; /* Counter of added entries */
} nutscan_ip_range_list_t;


size_t nutscan_add_ip_range(
nutscan_ip_range_list_t *irl,
char * start_ip,
char * end_ip);

DESCRIPTION
-----------

The *nutscan_add_ip_range()* function can create and add a `nutscan_ip_range_t`
entry based on provided inputs to the specified `nutscan_ip_range_list_t`
structure. The resulting amount of entries in the structure is returned,
or 0 in case of non-fatal errors.

This function skips work if:

* the structure pointer is `NULL` (0 is returned);
* neither `start_ip` nor `end_ip` were provided, i.e. they have `NULL` values
(current list length from the structure is returned);
* failed to allocate the entry (fatal).

If only one of `start_ip` or `end_ip` values was provided (not `NULL`), a
single-address range is created with both addresses set to the same pointer
value.

The structure should be initialized before use by `nutscan_init_ip_ranges()`.

The caller must free the contents of the structure after completing its use
by calling `nutscan_free_ip_ranges()` (after which the structure can be
re-used for a new list), and explicitly `free()` the structure object itself if
it was allocated dynamically (e.g. by calling `nutscan_init_ip_ranges(NULL)`).

NOTES
-----

Technically, the function is currently defined in 'nutscan-ip.h' file.

Currently there are no checks for duplicate or overlapping entries, so the
same IP addresses and whole IP address ranges can be added to the list (and
would eventually be scanned) many times.

SEE ALSO
--------

linkman:nutscan_init_ip_ranges[3], linkman:nutscan_free_ip_ranges[3],
linkman:nutscan_cidr_to_ip[3]
40 changes: 40 additions & 0 deletions docs/man/nutscan_free_ip_ranges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
NUTSCAN_FREE_IP_RANGES(3)
=========================

NAME
----

nutscan_free_ip_ranges - Free contents of a `nutscan_ip_range_list_t`
structure populated (and optionally created) by `nutscan_init_ip_ranges()`
and, more importantly, filled by a series of `nutscan_add_ip_range()` calls.

SYNOPSIS
--------

#include <nut-scan.h>

void nutscan_free_ip_ranges(nutscan_ip_range_list_t *irl);

DESCRIPTION
-----------

The *nutscan_free_ip_ranges()* function can free a `nutscan_ip_range_list_t`
structure. Doing so, it frees the whole linked list of `nutscan_ip_range_t`
entries, and zeroes out helper properties.

The structure itself is not freed (as it can be a statically allocated
variable on the stack), and can be re-used for a new list if needed.

The caller must free the structure object if it was allocated dynamically
(e.g. by calling `nutscan_init_ip_ranges(NULL)`).

NOTES
-----

Technically, the function is currently defined in 'nutscan-ip.h' file.

SEE ALSO
--------

linkman:nutscan_init_ip_ranges[3], linkman:nutscan_add_ip_range[3],
linkman:nutscan_cidr_to_ip[3]
41 changes: 41 additions & 0 deletions docs/man/nutscan_init_ip_ranges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
NUTSCAN_INIT_IP_RANGES(3)
=========================

NAME
----

nutscan_init_ip_ranges - Initialize contents of a `nutscan_ip_range_list_t`
structure (and optionally create one in the first place).

SYNOPSIS
--------

#include <nut-scan.h>

nutscan_ip_range_list_t * nutscan_init_ip_ranges(nutscan_ip_range_list_t *irl);

DESCRIPTION
-----------

The *nutscan_init_ip_ranges()* function can prepare a `nutscan_ip_range_list_t`
structure by zeroing out its fields. If the argument is `NULL`, the structure
is dynamically allocated. Either way, a pointer to it is returned.

A structure passed by caller is not assumed to have any valid contents to free,
as it may have garbage from stack after allocation.

The caller must free the contents of the structure after completing its use
by calling `nutscan_free_ip_ranges` (after which the structure can be re-used),
and explicitly `free()` the structure object itself if it was allocated
dynamically (e.g. by calling `nutscan_init_ip_ranges(NULL)`).

NOTES
-----

Technically, the function is currently defined in 'nutscan-ip.h' file.

SEE ALSO
--------

linkman:nutscan_free_ip_ranges[3], linkman:nutscan_add_ip_range[3],
linkman:nutscan_cidr_to_ip[3]
6 changes: 5 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 3178 utf-8
personal_ws-1.1 en 3182 utf-8
AAC
AAS
ABI
Expand All @@ -11,6 +11,7 @@ ACPresent
ADDR
ADDRCONFIG
ADDRINFO
ADDRLEN
ADELSYSTEM
ADK
ADKK
Expand Down Expand Up @@ -2090,6 +2091,7 @@ ipp
ippon
ipv
ipxe
irl
isDefault
isbmex
ish
Expand Down Expand Up @@ -2367,6 +2369,7 @@ nd
nds
netcat
netclient
netmask
netserver
netsh
netsnmp
Expand Down Expand Up @@ -2848,6 +2851,7 @@ sublicenses
submodule
submodules
subnet
subnets
subtree
sudo
suid
Expand Down
14 changes: 8 additions & 6 deletions tools/nut-scanner/nut-scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@
# ifdef HAVE_SEMAPHORE
# include <semaphore.h>
# endif
#endif

#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif

#ifdef HAVE_PTHREAD
# if (defined HAVE_PTHREAD_TRYJOIN) || (defined HAVE_SEMAPHORE)
extern size_t max_threads, curr_threads, max_threads_netxml, max_threads_oldnut, max_threads_netsnmp;
# endif
Expand All @@ -88,12 +96,6 @@ typedef struct nutscan_thread {
} nutscan_thread_t;
#endif /* HAVE_PTHREAD */

#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif

/* SNMP structure */
typedef struct nutscan_snmp {
char * community;
Expand Down
Loading
Loading