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

Fix for --sourceaddr bad behaviour #110

Merged
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ build_requires( 'Test::More' => 0, );
requires(
'JSON::XS' => 0,
'Locale::TextDomain' => 1.23,
'Net::Interface' => 0,
Copy link
Member

Choose a reason for hiding this comment

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

I can't find a binary package for this on CentOS. Have you checked for alternatives?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mattias-p I only found Net::Interface that can handle with IPv4 and IPv6. IO::Interface for example does not work with IPv6. Any advices for an alternate library ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to https://rt.cpan.org/Public/Bug/Display.html?id=124582, me should add this somewhere in travis.yml
mkdir /usr/include/sys/; ln -s /usr/include/bits/socket.h /usr/include/sys/socket.h to prevent the fail on Travis.

Copy link
Member

Choose a reason for hiding this comment

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

@vlevigneron Thanks for the clarification regarding the choice of library. And no, I don't have any alternatives up my sleeve.

'MooseX::Getopt' => 0,
'Text::Reflow' => 0,
'Zonemaster::Engine' => 3.0,
Expand Down
38 changes: 36 additions & 2 deletions lib/Zonemaster/CLI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extends 'Zonemaster::Engine::Exception';
# The actual interesting module.
package Zonemaster::CLI;

use version; our $VERSION = version->declare("v2.0.2");
use version; our $VERSION = version->declare("v2.0.4");

use 5.014002;
use warnings;
Expand All @@ -21,6 +21,7 @@ use Zonemaster::Engine::Translator;
use Zonemaster::Engine::Util qw[pod_extract_for];
use Zonemaster::Engine::Exception;
use Zonemaster::Engine::Zone;
use Zonemaster::Engine::Net::IP;
use Scalar::Util qw[blessed];
use Encode;
use Zonemaster::LDNS;
Expand All @@ -29,6 +30,8 @@ use List::Util qw[max];
use Text::Reflow qw[reflow_string];
use JSON::XS;
use File::Slurp;
use Net::Interface;
use Socket qw[AF_INET AF_INET6];

our %numeric = Zonemaster::Engine::Logger::Entry->levels;
our $JSON = JSON::XS->new->allow_blessed->convert_blessed->canonical;
Expand Down Expand Up @@ -312,7 +315,12 @@ sub run {
Zonemaster::Engine::Profile->effective->set( q{net.ipv6}, 0+$self->ipv6 );

if ($self->sourceaddr) {
Zonemaster::Engine::Profile->effective->set( q{resolver.source}, $self->sourceaddr );
if ($self->check_sourceaddress_exists ) {
Zonemaster::Engine::Profile->effective->set( q{resolver.source}, $self->sourceaddr );
}
else {
die __( "Address '" ) . $self->sourceaddr . __("' cannot be used as source address for DNS queries.") . "\n";
vlevigneron marked this conversation as resolved.
Show resolved Hide resolved
}
}

# Filehandle for diagnostics output
Expand Down Expand Up @@ -554,6 +562,32 @@ sub run {
return;
} ## end sub run

sub check_sourceaddress_exists {
my ( $self ) = @_;
my $address = Zonemaster::Engine::Net::IP->new($self->sourceaddr);
my $exists = 0;
foreach my $if ( Net::Interface->interfaces() ) {
foreach my $family ( AF_INET, AF_INET6 ) {
foreach my $ifaddr ( $if->address($family) ) {
my $zm_ifaddr;
if ( $family == AF_INET ) {
$zm_ifaddr = Zonemaster::Engine::Net::IP->new(Net::Interface::inet_ntoa($ifaddr));
}
vlevigneron marked this conversation as resolved.
Show resolved Hide resolved
elsif ( $family == AF_INET6 ) {
$zm_ifaddr = Zonemaster::Engine::Net::IP->new(Net::Interface::inet_ntop($ifaddr));
}
if ( $address->short eq $zm_ifaddr->short ) {
$exists = 1;
last;
}
}
last if $exists;
}
last if $exists;
}
return $exists;
}

sub add_fake_delegation {
my ( $self, $domain ) = @_;
my @ns_with_no_ip;
Expand Down
5 changes: 5 additions & 0 deletions share/da.po
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,8 @@ msgstr "Print the effective policy used in JSON format, then exit. (DEPRECATED)"
msgid "Local IP address that the test engine should try to send its requests from."
msgstr "Local IP address that the test engine should try to send its requests from."

msgid "Address '"
msgstr "Address '"

msgid "' cannot be used as source address for DNS queries."
msgstr "' cannot be used as source address for DNS queries."
5 changes: 5 additions & 0 deletions share/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,8 @@ msgstr "Print the effective policy used in JSON format, then exit. (DEPRECATED)"
msgid "Local IP address that the test engine should try to send its requests from."
msgstr "Local IP address that the test engine should try to send its requests from."

msgid "Address '"
msgstr "Address '"

msgid "' cannot be used as source address for DNS queries."
msgstr "' cannot be used as source address for DNS queries."
5 changes: 5 additions & 0 deletions share/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,9 @@ msgstr "Affichage de la configuration réellement utilisé au format JSON. (DEPR
msgid "Print the effective policy used in JSON format, then exit. (DEPRECATED)"
msgstr "Affichage de la politique réellement utilisé au format JSON. (DEPRECATED)"

msgid "Address '"
msgstr "L'adresse '"

msgid "' cannot be used as source address for DNS queries."
msgstr "' ne peut pas être utilisée comme adresse source pour les requêtes DNS."

5 changes: 5 additions & 0 deletions share/sv.po
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,8 @@ msgstr "Skriv ut den effektiva policyn i JSON-format, sedan avsluta. (DEPRECATED
msgid "Local IP address that the test engine should try to send its requests from."
msgstr "Lokal IP adress som testmotorn skall skicka sin trafik från."

msgid "Address '"
msgstr "IP-adress '"

msgid "' cannot be used as source address for DNS queries."
msgstr "' kan inte användas som källadress för DNS-frågor."