Skip to content

Commit

Permalink
Merge pull request #110 from vlevigneron/fix-issue-zonemaster-cli-38
Browse files Browse the repository at this point in the history
Fix for --sourceaddr bad behaviour
  • Loading branch information
vlevigneron authored Jan 12, 2021
2 parents 873015e + f01f486 commit beae6f0
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 5 deletions.
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,
'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
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/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

0 comments on commit beae6f0

Please sign in to comment.