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

Multiping! #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Multiping! #56

wants to merge 2 commits into from

Conversation

cron2
Copy link
Contributor

@cron2 cron2 commented Jun 1, 2020

Here's the PR as discussed in issue #52

I have rewritten it to add "-a", keep the calling convention for ping_host_add() and update the .pod documentation.

I'm not particularily attached to implementation details - this is a suggested way to implement it, which works for me :-) - but I can rewrite it (options, names, functions, ...) to better suit the project style.

If it were my decision, I would make "-a" the default, because that is what I use - "ping that thing, with whatever you have, all of it!". So there could be an option, like "-1", to turn it off and return to "only the first hit is pinged". But this is really fine tuning. Having the default "behaviour as before" with an extra "-a" to get "all targets" also works for me (and there's good arguments for not changing user visible behaviour).

As to the patch itself: there is two commits in the branch, one is the "multiping" functionality. The second one is something I find useful: if I have two hosts "heise.de" in the noping output, it's not easy to see whether v4 or or v6 ping is failing, so I modify the hostname in the liboping obj and attach a "/v4" or "/v6" to it, so it is more easily seen. This is totally independent, and the multiping change does not need it.

cron2 added 2 commits June 1, 2020 17:58
This renames the ping_host_add() function to ping_host_add_multi() and
adds an extra argument to it, specifying how many addresses to add from
what getaddrinfo() returns.  ping_host_add() is now a small wrapper
that calls "ping_host_add_multi()" with "max = 1" to get the previous
behaviour.

The callers (oping/noping) default to "max = 1" unless a new option,
"-a" is specified.  In that case, all IPv4+IPv6 addresses returned by
getaddrinfo() are added (-4 / -6 restricts this to "all IPv4 / IPv6
addresses", respectively).

Technically, the change is fairly straightforward:

ping_host_add() (now ping_host_add_multi()):
 - new argument "max_hosts"
 - move the allocation of "ph" to inside the "for (ai_ptr...)" loop
 - move adding of the found object to the "obj->" chain inside the loop
 - do not exit the loop until "enough" hosts have been found
   (or the list of results is exhausted)
 - return the number of hosts added (0..N)

the callers need to be adjusted to learn the number added, because
otherwise the graphical display in "noping" does not get extra lines.

Signed-off-by: Gert Doering <[email protected]>
With the "multiping" patch, you end up seeing a hostname multiple times
in the "noping" graphical display, and it's not easy to see right away
whether the IPv4 or IPv6 address has loss.  So, extend hostnames with
"/v4" or "/v6" to make this visible.

No option to turn this on or off has been implemented so far, but it
could be made dependant on "-4"/"-6" (no suffix needed) or on an extra
option.

Signed-off-by: Gert Doering <[email protected]>
@xtaran
Copy link

xtaran commented Sep 29, 2020

@cron2:

if I have two hosts "heise.de" in the noping output, it's not easy to see whether v4 or or v6 ping is failing, so I modify the hostname in the liboping obj and attach a "/v4" or "/v6" to it, so it is more easily seen.

Cool idea! One nitpick though:

This works for the common 1×A and 1× AAAA records. There are though cases like e.g. weebly.com with two A records:

$ host -t A weebly.com
weebly.com has address 74.115.50.109
weebly.com has address 74.115.50.110

In such cases, I suggest to directly add a slash and then the actual IP address instead of just /v4 or /v6.

Not sure if it makes sense to always directly add the IP address if multiple A and/or AAAA records are present as /v4 and especially /v6 is much shorter an according IP address and hence also way easier to read and recognize.

@octo: Any news on this? I'd really would like to see this in the next Debian release. See https://release.debian.org/bullseye/freeze_policy.html for the planned freeze dates and migration delays.

@cron2
Copy link
Contributor Author

cron2 commented Sep 29, 2020

@xtaran

One nitpick though:

This works for the common 1×A and 1× AAAA records. There are though cases like e.g. weebly.com with two A records:

Good point. In a "normal" terminal, there's definitely sufficient space to fully append the IPv4/IPv6 address(es) to the hostname, and it's not hard to do.

Not sure if it makes sense to always directly add the IP address if multiple A and/or AAAA records are present as /v4 and especially /v6 is much shorter an according IP address and hence also way easier to read and recognize.

Yeah. So either another option (which I do not like so much), or "if there is only a single v4/v6 address, append literal /v4, and if there is more than one, append the whole address". This is a bit more complicated to implement (you need two passes through the addrinfo to first get the number, and then create the hostnames). Mmmh. I need to play with this... :-)

@octo: Any news on this? I'd really would like to see this in the next Debian release. See https://release.debian.org/bullseye/freeze_policy.html for the planned freeze dates and migration delays.

yeah, some feedback from @octo on what he would like to merge would help me to decide what to code...

@barak
Copy link

barak commented Sep 29, 2020

image

Copy link
Owner

@octo octo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi all, sorry for the silence!

I'm quite happy with this code, thank you @cron2! I'm a bit unsure about the API, specifically how useful it is to specify the number of hosts. In most cases, I'd expect users to either want one or "all". That leads to the two most common cases being 1 and 0, where "multi(1)" means "not actually multi" and "multi(0)" means "all hosts". I find this a bit unintuitive.

I suggest to change the new ping_host_add_multi function to always add all IPs. Internally, we can continue to use the "number of entries" API, which should keep the required changes to a minimum. Does that sound reasonable?

Thanks again and best regards,
—octo

@@ -855,6 +856,10 @@ static int read_options (int argc, char **argv) /* {{{ */
break;
}

case 'a':
opt_max_hosts = -1; /* all */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation specifies "all" as zero, this code here uses -1.

@cron2
Copy link
Contributor Author

cron2 commented Sep 30, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants