46 |
|
|
47 |
sub check ($$;$) { |
sub check ($$;$) { |
48 |
my ($self, $name, $port) = @_; |
my ($self, $name, $port) = @_; |
49 |
my ($name, undef, undef, undef, $addr) = gethostbyname ($name); |
return 0 unless defined $name; |
50 |
|
my $addr; |
51 |
|
($name, undef, undef, undef, $addr) = gethostbyname ($name); |
52 |
return 0 if !$name && !$addr; |
return 0 if !$name && !$addr; |
53 |
for my $rule (@{$self->{rule}}) { |
for my $rule (@{$self->{rule}}) { |
54 |
if ($rule->{-host}) { |
if ($rule->{-host}) { |
96 |
sub match_ipv4 ($$$) { |
sub match_ipv4 ($$$) { |
97 |
my ($self, $pattern, $addr) = @_; |
my ($self, $pattern, $addr) = @_; |
98 |
if (length ($addr) != 4) { |
if (length ($addr) != 4) { |
99 |
$addr =~ /([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/; |
$addr =~ /([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/ or return 0; |
100 |
$addr = pack 'C4', $1, $2, $3, $4; |
$addr = pack 'C4', $1, $2, $3, $4; |
101 |
} |
} |
102 |
my $mask = pack 'C4', 255, 255, 255, 255; |
my $mask = pack 'C4', 255, 255, 255, 255; |
103 |
if (length ($pattern) != 4) { |
if (length ($pattern) != 4) { |
104 |
$pattern =~ m!([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)(?:/([0-9]+))?!; |
$pattern =~ m!([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)(?:/([0-9]+))?! |
105 |
|
or return 0; |
106 |
$pattern = pack 'C4', $1, $2, $3, $4; |
$pattern = pack 'C4', $1, $2, $3, $4; |
107 |
my $m = $5; $m = 32 if $m > 32; |
my $m = $5; |
108 |
if (defined $m) { |
if (defined $m) { |
109 |
|
$m = $m > 32 ? 32 : $m + 0; |
110 |
$mask = pack 'C4', (($m > 24) ? (255, 255, 255, (2**($m-24)-1) << (32-$m)) : |
$mask = pack 'C4', (($m > 24) ? (255, 255, 255, (2**($m-24)-1) << (32-$m)) : |
111 |
($m > 16) ? (255, 255, (2**($m-16)-1) << (24-$m), 0) : |
($m > 16) ? (255, 255, (2**($m-16)-1) << (24-$m), 0) : |
112 |
($m > 8) ? (255, (2**($m-8)-1) << (16-$m), 0, 0) : |
($m > 8) ? (255, (2**($m-8)-1) << (16-$m), 0, 0) : |