summaryrefslogtreecommitdiff
path: root/lib/Vyatta/IpTables/IpSet.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Vyatta/IpTables/IpSet.pm')
-rwxr-xr-xlib/Vyatta/IpTables/IpSet.pm20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/Vyatta/IpTables/IpSet.pm b/lib/Vyatta/IpTables/IpSet.pm
index 25cf74a..5f68950 100755
--- a/lib/Vyatta/IpTables/IpSet.pm
+++ b/lib/Vyatta/IpTables/IpSet.pm
@@ -300,39 +300,41 @@ sub member_exists {
}
sub add_member_range {
- my ($self, $start, $stop) = @_;
+ my ($self, $start, $stop, $alias) = @_;
if ($self->{_type} eq 'port') {
foreach my $member ($start .. $stop) {
- my $rc = $self->add_member($member);
+ my $rc = $self->add_member($member, $alias);
return $rc if defined $rc;
}
} elsif ($self->{_type} eq 'address') {
# $start_ip++ won't work if it doesn't know the
# prefix, so we'll make a big range.
- my $wrap_mask = $addr_range_mask - 1;
- my $start_ip = new NetAddr::IP("$start/$wrap_mask");
- my $stop_ip = new NetAddr::IP($stop);
+ my $start_ip = new NetAddr::IP("$start/$addr_range_mask");
+ my $stop_ip = new NetAddr::IP("$stop/$addr_range_mask");
for (; $start_ip <= $stop_ip; $start_ip++) {
- my $rc = $self->add_member($start_ip->addr());
+ my $rc = $self->add_member($start_ip->addr(), $alias);
return $rc if defined $rc;
+ last if $start_ip->cidr() eq $start_ip->broadcast();
}
}
return;
}
sub add_member {
- my ($self, $member) = @_;
+ my ($self, $member, $alias) = @_;
return "Error: undefined group name" if ! defined $self->{_name};
return "Error: group [$self->{_name}] doesn't exists\n" if !$self->exists();
if ($member =~ /^([^-]+)-([^-]+)$/) {
- return $self->add_member_range($1, $2);
+ return $self->add_member_range($1, $2, $alias);
}
if ($self->member_exists($member)) {
- return "Error: member [$member] already exists in [$self->{_name}]\n";
+ my $set_name = $alias;
+ $set_name = $self->{_name} if ! defined $set_name;
+ return "Error: member [$member] already exists in [$set_name]\n";
}
my $cmd = "ipset -A $self->{_name} $member";
my $rc = $self->run_cmd($cmd);