Skip to content

Commit

Permalink
make Net::Netmask optional
Browse files Browse the repository at this point in the history
git-svn-id: http://code.sixapart.com/svn/perlbal/trunk@316 6caf28e9-730f-0410-b62b-a31386fe13fb
  • Loading branch information
bradfitz committed Jul 20, 2005
1 parent b8d5138 commit fa06801
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGES
@@ -1,3 +1,5 @@
-- make Net::Netmask optional

-- byte range support for both webserver mode and reproxy-file mode
Giao Phan <giao@guba.com>. so clients can resume large transfers.

Expand Down
4 changes: 1 addition & 3 deletions Makefile.PL
Expand Up @@ -24,10 +24,8 @@ WriteMakefile(
),

PREREQ_PM => {
'Linux::AIO' => '1.3',
'Danga::Socket' => '1.36',
'Danga::Socket' => '1.43',
'BSD::Resource' => 0,
'Net::Netmask' => 0,
'Test::More' => 0,
'File::Find' => 0,
},
Expand Down
6 changes: 1 addition & 5 deletions lib/Perlbal/BackendHTTP.pm
Expand Up @@ -176,11 +176,7 @@ sub assign_client {
$hds->header("X-Proxy-Capabilities", "reproxy-file");

# decide whether we trust the upstream or not
my $trust = $self->{service}->{always_trusted}; # set to default auto-trust level
if ($self->{service} && $self->{service}->{trusted_upstreams}) {
$trust = 1
if $self->{service}->{trusted_upstreams}->match($client->peer_ip_string);
}
my $trust = $self->{service}->trusted_ip($client->peer_ip_string);

# if we're not going to trust the upstream, reset these for security reasons
unless ($trust) {
Expand Down
20 changes: 18 additions & 2 deletions lib/Perlbal/Service.pm
Expand Up @@ -6,8 +6,6 @@ package Perlbal::Service;
use strict;
use warnings;

use Net::Netmask;

use Perlbal::BackendHTTP;

use fields (
Expand Down Expand Up @@ -552,6 +550,21 @@ sub role {
return $self->{role};
}

# called by BackendHTTP to ask if a client's IP is in our trusted list
sub trusted_ip {
my Perlbal::Service $self = shift;
my $ip = shift;

return 1 if $self->{'always_trusted'};

my $tmap = $self->{trusted_upstreams};
return 0 unless $tmap;

# try to use it as a Net::Netmask object
return 1 if eval { $tmap->match($ip); };
return 0;
}

# manage some header stuff
sub header_management {
my Perlbal::Service $self = shift;
Expand Down Expand Up @@ -646,6 +659,9 @@ sub set {
};

if ($key eq 'trusted_upstream_proxies') {
my $loaded = eval { require Net::Netmask; 1; };
return $err->("Net::Netmask not installed") unless $loaded;

if ($self->{trusted_upstreams} = Net::Netmask->new2($val)) {
# set, all good
return $ok->();
Expand Down

0 comments on commit fa06801

Please sign in to comment.