schweikert / fping

High performance ping tool
https://fping.org
Other
1.01k stars 250 forks source link

Inconsistent limits for address generation via `-g`, `--generator` using either range or CIDR #299

Closed auerswal closed 1 month ago

auerswal commented 6 months ago

When using fping -g with a range, the number of addresses that may be generated is limited (via the MAX_GENERATE constant in src/fping.c):

$ fping -q --stats -g 127.0.0.1 127.1.255.254
./src/fping: -g parameter generates too many addresses

But this limit is not applied when using CIDR notation:

$ ipcalc 127.0.0.0/15 | grep 'HostM[ai][nx]'
HostMin:      127.0.0.1
HostMax:      127.1.255.254
$ fping -q --stats -g 127.0.0.0/15

  131070 targets
  131070 alive
       0 unreachable
       0 unknown addresses

       0 timeouts (waiting for response)
  131070 ICMP Echos sent
  131070 ICMP Echo Replies received
       0 other ICMP received

 0.005 ms (min round trip time)
 0.033 ms (avg round trip time)
 0.166 ms (max round trip time)
     1328.103 sec (elapsed real time)

I have mentioned this in a comment on issue #59, because I think that applying a consistent limit to address generation is a prerequisite for expanding -g functionality to include IPv6, but I'd prefer to track this issue independently.

I can refresh my respective patches that have been part of the IPv6 generator pull request #254 and submit them as a new pull request. Just let me know if this desired.

auerswal commented 3 months ago

To collect relevant information in one place:

auerswal commented 3 months ago

Another point to consider: Using --generate with a large CIDR subnet can result in problems, e.g., using too much memory:

$ ./src/fping -q -s -g 127.0.0.0/8
Killed
$ dmesg -t | grep -E '^(oom-kill|Out of memory)'
oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/user.slice/user-1000.slice/user@1000.service,task=fping,pid=10558,uid=1000
Out of memory: Killed process 10558 (fping) total-vm:5346240kB, anon-rss:5343568kB, file-rss:172kB, shmem-rss:0kB, UID:1000 pgtables:10504kB oom_score_adj:0

Therefore I'd say that having a limit is useful.

gsnw commented 2 months ago

Have you found a solution to the problem? If not I would try to help

auerswal commented 2 months ago

Yes, I already have a (partial) solution to this as part of an older, now closed, pull request. I'll try to find the time to adapt it to the current fping code, and add the missing pieces (adjust the limit to a power of two to better fit CIDR notation and document the limit in the man page (i.e., fping.pod)).