diff options
author | zsdc <taras@sentrium.io> | 2019-06-19 22:24:41 +0300 |
---|---|---|
committer | zsdc <taras@sentrium.io> | 2019-06-19 22:24:41 +0300 |
commit | 835304e5aaa252e8b0bcf4651629cd089e670147 (patch) | |
tree | 010c075af7ddacf908d1a5cf314f36b463bd9fb4 /lib | |
parent | 342cb9864d5964c7fdd8de46d166bd7cd26df923 (diff) | |
download | vyatta-cfg-firewall-835304e5aaa252e8b0bcf4651629cd089e670147.tar.gz vyatta-cfg-firewall-835304e5aaa252e8b0bcf4651629cd089e670147.zip |
[ipset] T1456: Add check for duplicate items in port-group before commit
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Vyatta/IpTables/IpSet.pm | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/Vyatta/IpTables/IpSet.pm b/lib/Vyatta/IpTables/IpSet.pm index 276b845..d7a014a 100755 --- a/lib/Vyatta/IpTables/IpSet.pm +++ b/lib/Vyatta/IpTables/IpSet.pm @@ -410,11 +410,25 @@ sub check_member { sub member_exists { my ($self, $member) = @_; - my $cmd = "ipset -T $self->{_name} $member -q"; - my $rc = $self->run_cmd($cmd); - return $rc ? 0 : 1; + # check if a member is a port range and roll through all members it is + if ($member =~ /([\d]+)-([\d]+)/) { + foreach my $port ($1..$2) { + # test port with ipset + my $cmd = "ipset -T $self->{_name} $port -q"; + my $rc = $self->run_cmd($cmd); + # return true if port was found + return 1 if !$rc; + } + # return false if ports was not found in set + return 0; + } else { + my $cmd = "ipset -T $self->{_name} $member -q"; + my $rc = $self->run_cmd($cmd); + return $rc ? 0 : 1; + } } + sub add_member { my ($self, $member, $alias, $hyphenated_port) = @_; |