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

Updates the ipv4 and ipv6 command line options #185

Merged
merged 4 commits into from
Jan 20, 2021
Merged
Changes from 1 commit
Commits
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
8 changes: 3 additions & 5 deletions lib/Zonemaster/CLI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,13 @@ has 'restore' => (
has 'ipv4' => (
is => 'ro',
isa => 'Bool',
default => 1,
Copy link

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.

Copy link
Contributor Author

@matsduf matsduf Jan 20, 2021

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.

Copy link
Contributor Author

@matsduf matsduf Jan 20, 2021

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?

documentation =>
__( 'Flag to permit or deny queries being sent via IPv4. --ipv4 permits IPv4 traffic, --no-ipv4 forbids it.' ),
);

has 'ipv6' => (
is => 'ro',
isa => 'Bool',
default => 1,
documentation =>
__( 'Flag to permit or deny queries being sent via IPv6. --ipv6 permits IPv6 traffic, --no-ipv6 forbids it.' ),
);
Expand Down Expand Up @@ -358,9 +356,9 @@ sub run {
}

# These two must come after any profile from command line has been loaded
# 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.
Copy link
Member

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.

Zonemaster::Engine::Profile->effective->set( q{net.ipv4}, 0+$self->ipv4 ) if defined ($self->ipv4);
Copy link

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 );
}

Copy link
Contributor Author

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.

Copy link

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 );
        }
    }

Copy link
Contributor Author

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.

Copy link

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 ;)

Zonemaster::Engine::Profile->effective->set( q{net.ipv6}, 0+$self->ipv6 ) if defined ($self->ipv6);
Copy link
Member

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.

Copy link
Contributor Author

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.



if ( $self->dump_profile ) {
Expand Down