-
Notifications
You must be signed in to change notification settings - Fork 22
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
Updates the ipv4 and ipv6 command line options #185
Updates the ipv4 and ipv6 command line options #185
Conversation
Makes the ipv4 and ipv6 options undefined unless explicitly set on the command line. Changes so that the ip setting is only changed if the option is explicitly set on the command line.
lib/Zonemaster/CLI.pm
Outdated
Zonemaster::Engine::Profile->effective->set( q{net.ipv4}, 0+$self->ipv4 ) if defined ($self->ipv4); | ||
Zonemaster::Engine::Profile->effective->set( q{net.ipv6}, 0+$self->ipv6 ) if defined ($self->ipv6); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update this to use if (...) { ... }
syntax? This is in line with the rest of the code. Also, the structure of the code is more apparent to the reader that way.
I do realize there are a couple of instances of trailing if statements in this file, but adding more of them is a mistake from a readability point of view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that only your personal opinion that trailing "if" is always less readable, or do you know of any studies of that supports that? In that case we get three lines, instead of one, and more separators. And the condition is short.
lib/Zonemaster/CLI.pm
Outdated
# to override the profile setting | ||
Zonemaster::Engine::Profile->effective->set( q{net.ipv4}, 0+$self->ipv4 ); | ||
Zonemaster::Engine::Profile->effective->set( q{net.ipv6}, 0+$self->ipv6 ); | ||
# to override the profile setting, but only if selected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the control flow is apparent from the syntax (like I suggest below), this added clarification is unnecessary and distracting. And it's better to remove it.
@@ -147,15 +147,13 @@ has 'restore' => ( | |||
has 'ipv4' => ( | |||
is => 'ro', | |||
isa => 'Bool', | |||
default => 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This default behavior is not moved into the code. I mean, before the change if you do not have the net
stanza in the profile file and you just run the CLI, IPv4 and IPv6 will be enabled by default.
Here with the current changes, removing the stanza from the profile file gives a CRITICAL message :
0.01 CRITICAL Both IPv4 and IPv6 are disabled.
I feel an else
statement is needed in the code to enable IPv4 and IPv6 by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I had to remove that "default" to make it possible to detect if the option had been actively set or not. It is more complex than I thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I see what you mean. If the default profile.json does not have any IPv4 or IPv6 enabled, then there will no network enabled. -- In Backend both are enabled if both are disabled.
You will get the same effect if you run
# zonemaster-cli --level INFO --test basic iis.se --no-ipv6 --no-ipv4
Should CLI be helpful in that case?
lib/Zonemaster/CLI.pm
Outdated
Zonemaster::Engine::Profile->effective->set( q{net.ipv4}, 0+$self->ipv4 ); | ||
Zonemaster::Engine::Profile->effective->set( q{net.ipv6}, 0+$self->ipv6 ); | ||
# to override the profile setting, but only if selected. | ||
Zonemaster::Engine::Profile->effective->set( q{net.ipv4}, 0+$self->ipv4 ) if defined ($self->ipv4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The else
statement I see :
else {
Zonemaster::Engine::Profile->effective->set( q{net.ipv4}, 1 );
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That "else" should first check if any of ipv4/ipv6 is enabled, if not set both. Otherwise we will, again, override the setting in any selected config file.
I will check and come with an updated version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes I didn't see that it was as twisted as that.
I think this cumbersome code covers every cases (maybe some perl magic might make it lighter)
if ( defined ($self->ipv4) ) {
Zonemaster::Engine::Profile->effective->set( q{net.ipv4}, $self->ipv4 );
} else {
if ( ! defined ($self->ipv6) ) {
Zonemaster::Engine::Profile->effective->set( q{net.ipv4}, 1 );
}
}
if ( defined ($self->ipv6) ) {
Zonemaster::Engine::Profile->effective->set( q{net.ipv6}, $self->ipv6 );
} else {
if ( ! defined ($self->ipv4) ) {
Zonemaster::Engine::Profile->effective->set( q{net.ipv6}, 1 );
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will also be wrong, because if you have selected a profile where IPv6 has been disabled, then your suggestion will enable IPv6 unless you explicitly have selected --no-ipv6.
I will proved an update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really twisted ^^. I'll let you find a solution ;)
@mattias-p and @PNAX, should CLI be "helpful" and enable both IPv4 and IPv6 if both are disabled? I do not think so. I think it is better that the user gets the message rather than adding that magic. When could that happen?
|
I don't think we should support modifying the default profile. If a user specifies a profile with both IPv4 and IPv6 disabled but forgets to override either one on the command line, it seems reasonable to just let them know that nothing can be done because both IPv4 and IPv6 are disabled. Maybe it would be better to give the user feedback in the form of an input validation error than in the form of a message tag. |
I agree.
That would be beyond the scope of this PR for fixing the bug late in the release cycle. I suggest a issue to do that update in next release. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my point of view, if IPv4 and/or IPv6 are explicitly disabled, then the CLI should comply with this choice.
However, I think this does not solve a specific case. From my understanding the net
stanza in the profile is not mandatory. Hence if the profile.json file do not have the net
stanza (because the user forgot to add it, because it was shipped without it...) then there is no default fallback. I think the CLI should use IPv4 and IPv6 by default in this specific case.
Or maybe this stanza is already mandatory and I missed this.
Is there any documentation about the precedence between the CLI --(no)ipvx
options and the profile.json entries ?
lib/Zonemaster/CLI.pm
Outdated
} | ||
if defined ($self->ipv6) { | ||
Zonemaster::Engine::Profile->effective->set( q{net.ipv6}, 0+$self->ipv6 ); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary trailing semicolon
And I think that the 0+
can be removed as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I think that the 0+ can be removed as well.
That's correct. It's in the contract of the Profile properties to always return the correct data type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concerning "0+" I also looked at that, but I wanted to change as little as possible since this is a bug fix late in the cycle.
The trailing semicolon it not needed. When I started with Perl 1996 I think it was recommended, or maybe even mandatory in Perl 4, so I have a habit of writing them. It does not harm anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate the historical note :)
If you select a profile with "--profile" and that has disabled both or you have disable by "--no-ipv4 --no-ipv6" then I think we can say that the user has explicitly disabled both.
The If you choose another profile by "--profile" then first the default
It is not mandatory, but is is included in the default
No, not explicitly. |
@PNAX I feel there's a misunderstanding here. The Profile module was designed to never have any undefined properties in the default profile, nor in the effective profile. They always start out with a valid default value - in particular the default value that is specified in the documentation (i.e. true for both net.ipv4 and net.ipv6). If users modify the default profile, they're breaking the Profile contract and all bets are off. Users should be able to override the default profile with --profile and other arguments. So the only way to get to no-IPv4 and no-IPv6 should be to specify that on the command line. Lastly, no, I don't think we have any documentation on precedence. We should have that. |
Indeed this is not the logic I had in mind. Thank you for your insights. |
@mattias-p and @PNAX, is this good enough? Can you approve? |
lib/Zonemaster/CLI.pm
Outdated
if defined ($self->ipv4) { | ||
Zonemaster::Engine::Profile->effective->set( q{net.ipv4}, 0+$self->ipv4 ); | ||
} | ||
if defined ($self->ipv6) { | ||
Zonemaster::Engine::Profile->effective->set( q{net.ipv6}, 0+$self->ipv6 ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested it, and it looks like the parentheses usage in the if statement makes perl complain.
the following solves the complaint
if ( defined (...) ) {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have kept the first version... Fix in a minute.
@matsduf Yeah, just fix the syntax errors and I'll approve. |
I have verified that the code works after my last commit. @mattias-p and @PNAX, please review. |
Makes the ipv4 and ipv6 options undefined unless explicitly set on the command line. Changes so that the ip setting is only changed if the option is explicitly set on the command line.
This resolves a bug that appeared after #182 was fixed by #183.
The bug is described in #182 (comment).