diff options
author | Stig Thormodsrud <stig@io.vyatta.com> | 2009-02-03 10:03:25 -0800 |
---|---|---|
committer | Stig Thormodsrud <stig@io.vyatta.com> | 2009-02-03 10:03:25 -0800 |
commit | 418b13ab1e72d8e3eb6afb2c65946e26bbaa1a65 (patch) | |
tree | 4e8e63863116c3037db0c8702cfde524aa8e4b83 /lib/Vyatta/IpTables | |
parent | 6c298dca8b2a877c5aa43587b32f6c70951f6aa8 (diff) | |
download | vyatta-cfg-firewall-418b13ab1e72d8e3eb6afb2c65946e26bbaa1a65.tar.gz vyatta-cfg-firewall-418b13ab1e72d8e3eb6afb2c65946e26bbaa1a65.zip |
Reduce duplicate code.
Diffstat (limited to 'lib/Vyatta/IpTables')
-rwxr-xr-x | lib/Vyatta/IpTables/AddressFilter.pm | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/lib/Vyatta/IpTables/AddressFilter.pm b/lib/Vyatta/IpTables/AddressFilter.pm index 5b9768b..279ab77 100755 --- a/lib/Vyatta/IpTables/AddressFilter.pm +++ b/lib/Vyatta/IpTables/AddressFilter.pm @@ -237,26 +237,15 @@ sub rule { } # so far ipset only supports IPv4 if ($self->{_ip_version} eq "ipv4") { - if (defined($self->{_address_group})) { - my $name = $self->{_address_group}; - my $group = new Vyatta::IpTables::IpSet($name, 'address'); - my ($set_rule, $err_str) = $group->rule($self->{_srcdst}); - return ($err_str, ) if ! defined $set_rule; - $rule .= $set_rule; - } - if (defined($self->{_network_group})) { - my $name = $self->{_network_group}; - my $group = new Vyatta::IpTables::IpSet($name, 'network'); - my ($set_rule, $err_str) = $group->rule($self->{_srcdst}); - return ($err_str, ) if ! defined $set_rule; - $rule .= $set_rule; - } - if (defined($self->{_port_group})) { - my $name = $self->{_port_group}; - my $group = new Vyatta::IpTables::IpSet($name, 'port'); - my ($set_rule, $err_str) = $group->rule($self->{_srcdst}); - return ($err_str, ) if ! defined $set_rule; - $rule .= $set_rule; + foreach my $group_type ('address', 'network', 'port') { + my $var_name = '_' . $group_type . '_group'; + if (defined($self->{$var_name})) { + my $name = $self->{$var_name}; + my $group = new Vyatta::IpTables::IpSet($name, $group_type); + my ($set_rule, $err_str) = $group->rule($self->{_srcdst}); + return ($err_str, ) if ! defined $set_rule; + $rule .= $set_rule; + } } } |