Fix Ping Input plugin for FreeBSD's ping6 #7861
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
FreeBSD has separate ping binaries for IPv4 and IPv6,
ping(8)
andping6(8)
.Both have differently named options (or sometimes even with the same name but different function...),
and differently formatted outputs.
When using the
exec
method, the ping plugin, searches for attl=
string to get the remaining TTL of the echo response, howeverping6
has a different output format and returns the TTL ashlim=<integer>
. Thus the plugin throws this error:Furthermore the ping plugin isn't aware of the different command options and always tries to use the arguments for the IPv4
ping
command, which fails:ping
's-W
is called-x
forping6
ping
's-t
is called-X
forping6
Changes
processPingOutput()
searches for bothttl=
andhlim=
in the returned lines. The regex ingetTTL()
is updated accordingly, to match both cases.p.args()
now checks whether the binary string containsping6
and if the system / GOOS isfreebsd
, and if yes, adds the arguments needed forping6
.This effectively will result in the following default command lines:
Unit tests
I've also added tests for this. I had to duplicate
TestArgs()
, since the expected result now also depends on other factors (p.Binary
) besides the system.With
iputils-ping
on Linuxping6
is a symlink toping
, so the options are the same. Don't know forinetuitls-ping
, but it isn't supported by this plugin anyways.The test also assumes that "anything else" uses the same args for ping and ping6, since that is basically what's implemented now.
PR testing
I have tested this myself on OPNsense 20.1.8 / FreeBSD 11.2-RELEASE-p21-HBSD
Here's an example config excerpt to reproduce the problem and to test the changes of this PR:
Required for all PRs: