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
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ before_install:
# Install Zonemaster Engine
- git clone --depth=1 --branch=$TRAVIS_BRANCH https://github.com/zonemaster/zonemaster-engine.git
- ( cd zonemaster-engine && cpanm --verbose --notest . ) && rm -rf zonemaster-engine

# Fix Header files location issue
- if [[ ! -e /usr/include/sys/ ]]; then sudo mkdir /usr/include/sys/; fi
- if [[ ! -e /usr/include/bits/ && -e /usr/include/x86_64-linux-gnu/bits/ ]]; then sudo ln -s /usr/include/x86_64-linux-gnu/bits/ /usr/include/bits; fi
- if [[ ! -e /usr/include/sys/socket.h ]]; then sudo ln -s /usr/include/bits/socket.h /usr/include/sys/socket.h; fi
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tests_recursive( 't' );
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' => 4.0,
Expand Down
6 changes: 3 additions & 3 deletions docs/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ This instruction covers the following operating systems:
2) Install dependencies from CPAN:

```sh
sudo cpanm Locale::Msgfmt Locale::TextDomain MooseX::Getopt Text::Reflow
sudo cpanm Locale::Msgfmt Locale::TextDomain MooseX::Getopt Text::Reflow Net::Interface
```

3) Install Zonemaster::CLI
Expand Down Expand Up @@ -77,7 +77,7 @@ This instruction covers the following operating systems:
2) Install dependencies:

```sh
sudo apt-get install libmoosex-getopt-perl libtext-reflow-perl libmodule-install-perl
sudo apt-get install libmoosex-getopt-perl libtext-reflow-perl libmodule-install-perl libnet-interface-perl
```

3) Install Zonemaster::CLI:
Expand All @@ -97,7 +97,7 @@ This instruction covers the following operating systems:
2) Install dependencies available from binary packages:

```sh
pkg install devel/gmake p5-JSON-XS p5-Locale-libintl p5-MooseX-Getopt p5-Text-Reflow
pkg install devel/gmake p5-JSON-XS p5-Locale-libintl p5-MooseX-Getopt p5-Text-Reflow p5-Net-Interface
```

3) Install Zonemaster::CLI:
Expand Down
38 changes: 36 additions & 2 deletions lib/Zonemaster/CLI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use 5.014002;
use strict;
use warnings;

use version; our $VERSION = version->declare( "v3.0.1" );
use version; our $VERSION = version->declare( "v3.0.3" );

use Locale::TextDomain 'Zonemaster-CLI';
use Moose;
Expand All @@ -23,6 +23,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 @@ -31,6 +32,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 @@ -318,7 +321,12 @@ sub run {
}

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 __x( "Address {address} cannot be used as source address for DNS queries.\n", address => $self->sourceaddr );
}
}

# Filehandle for diagnostics output
Expand Down Expand Up @@ -581,6 +589,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));
}
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
4 changes: 4 additions & 0 deletions share/da.po
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ msgid ""
"Local IP address that the test engine should try to send its requests from."
msgstr "Lokal IP-adresse som test-motoren skal sende sin foresgpørgsler fra."

#, perl-brace-format
msgid "Address {address} cannot be used as source address for DNS queries.\n"
msgstr "Address {address} cannot be used as source address for DNS queries.\n"

Copy link
Member

Choose a reason for hiding this comment

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

I'm sorry I didn't spot this earlier, but I don't think this should be included. It only makes it difficult for the Danish translators to notice that there is something new for them to translate.

#, perl-brace-format
msgid "Loading policy from {path}."
msgstr "Indlæser policy fra {path}."
Expand Down
6 changes: 6 additions & 0 deletions share/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ msgstr ""
msgid "Must give the name of a domain to test.\n"
msgstr "Il est nécessaire d'indiquer un nom de domaine pour lancer le test.\n"

#, perl-brace-format
msgid "Address {address} cannot be used as source address for DNS queries.\n"
msgstr ""
"L'adresse {address} ne peut pas être utilisée comme adresse source pour les "
"requêtes DNS.\n"

#, perl-brace-format
msgid "Loading policy from {path}."
msgstr "Chargement de la politique de tests depuis le fichier {path}."
Expand Down
4 changes: 4 additions & 0 deletions share/nb.po
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ msgstr ""
"installert på dette system?\n"
"\n"

#, perl-brace-format
msgid "Address {address} cannot be used as source address for DNS queries.\n"
msgstr "Address {address} cannot be used as source address for DNS queries.\n"

Copy link
Member

Choose a reason for hiding this comment

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

This should also be excluded for the same reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@matsduf As you asked for something different (but it was a long time ago), do you think that @mattias-p proposal is reasonable ?

Copy link
Contributor

Choose a reason for hiding this comment

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

That is fine. I am not sure if it should be empty or non-existent, but at least the latter will mean that msgid will shown, and then when you translate you will be prompted.

#, perl-brace-format
msgid "Loading profile from {path}."
msgstr "Laster profil fra {path}."
Expand Down
4 changes: 4 additions & 0 deletions share/sv.po
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ msgstr ""
"'%s' (finns den installerad på det här systemet?).\n"
"\n"

#, perl-brace-format
msgid "Address {address} cannot be used as source address for DNS queries.\n"
msgstr "IP-adress {address} kan inte användas som källadress för DNS-frågor.\n"

#, perl-brace-format
msgid "Loading profile from {path}."
msgstr "Laddar profil från {path}."
Expand Down