diff options
author | Stig Thormodsrud <stig@io.vyatta.com> | 2009-02-03 12:49:43 -0800 |
---|---|---|
committer | Stig Thormodsrud <stig@io.vyatta.com> | 2009-02-03 12:49:43 -0800 |
commit | afa429c44242f8674b00a412c95743b9cb775021 (patch) | |
tree | 562f1908734ced23421a30dae9ea50e2db0f92e4 /lib/Vyatta/IpTables | |
parent | 418b13ab1e72d8e3eb6afb2c65946e26bbaa1a65 (diff) | |
download | vyatta-cfg-firewall-afa429c44242f8674b00a412c95743b9cb775021.tar.gz vyatta-cfg-firewall-afa429c44242f8674b00a412c95743b9cb775021.zip |
Reduce duplicate code in setup/setupOrig.
Diffstat (limited to 'lib/Vyatta/IpTables')
-rwxr-xr-x | lib/Vyatta/IpTables/AddressFilter.pm | 74 |
1 files changed, 24 insertions, 50 deletions
diff --git a/lib/Vyatta/IpTables/AddressFilter.pm b/lib/Vyatta/IpTables/AddressFilter.pm index 279ab77..7bf6f70 100755 --- a/lib/Vyatta/IpTables/AddressFilter.pm +++ b/lib/Vyatta/IpTables/AddressFilter.pm @@ -68,81 +68,55 @@ sub set_ip_version { $self->{_ip_version} = $ip_version; } -sub setup { - my ($self, $level) = @_; +sub setup_base { + my ($self, $level, $func) = @_; my $config = new Vyatta::Config; $config->setLevel("$level"); # Default to IPv4. - $self->{_ip_version} = "ipv4"; + $self->{_ip_version} = "ipv4"; # setup needed parent nodes $self->{_srcdst} = $config->returnParent(".."); - $self->{_protocol} = $config->returnValue(".. protocol"); + $self->{_protocol} = $config->$func(".. protocol"); # setup address filter nodes - $self->{_address} = $config->returnValue("address"); - $self->{_network} = undef; - $self->{_range_start} = undef; - $self->{_range_stop} = undef; + $self->{_address} = $config->$func("address"); + $self->{_network} = undef; + $self->{_range_start} = undef; + $self->{_range_stop} = undef; if (defined($self->{_address})) { if ($self->{_address} =~ /\//) { - $self->{_network} = $self->{_address}; - $self->{_address} = undef; + $self->{_network} = $self->{_address}; + $self->{_address} = undef; } elsif ($self->{_address} =~ /^([^-]+)-([^-]+)$/) { $self->{_range_start} = $1; - $self->{_range_stop} = $2; - $self->{_address} = undef; + $self->{_range_stop} = $2; + $self->{_address} = undef; } } - $self->{_port} = $config->returnValue("port"); - $self->{_src_mac} = $config->returnValue("mac-address"); - - $self->{_address_group} = $config->returnValue("group address-group"); - $self->{_network_group} = $config->returnValue("group network-group"); - $self->{_port_group} = $config->returnValue("group port-group"); + $self->{_port} = $config->$func("port"); + $self->{_src_mac} = $config->$func("mac-address"); + $self->{_address_group} = $config->$func("group address-group"); + $self->{_network_group} = $config->$func("group network-group"); + $self->{_port_group} = $config->$func("group port-group"); return 0; } -sub setupOrig { +sub setup { my ($self, $level) = @_; - my $config = new Vyatta::Config; - - $config->setLevel("$level"); - - # Default to IPv4. - $self->{_ip_version} = "ipv4"; - - # setup needed parent nodes - $self->{_srcdst} = $config->returnParent(".."); - $self->{_protocol} = $config->returnOrigValue(".. protocol"); - # setup address filter nodes - $self->{_address} = $config->returnOrigValue("address"); - $self->{_network} = undef; - $self->{_range_start} = undef; - $self->{_range_stop} = undef; - if (defined($self->{_address})) { - if ($self->{_address} =~ /\//) { - $self->{_network} = $self->{_address}; - $self->{_address} = undef; - } elsif ($self->{_address} =~ /^([^-]+)-([^-]+)$/) { - $self->{_range_start} = $1; - $self->{_range_stop} = $2; - $self->{_address} = undef; - } - } - - $self->{_port} = $config->returnOrigValue("port"); - $self->{_src_mac} = $config->returnOrigValue("mac-address"); + $self->setup_base($level, 'returnValue'); + return 0; +} - $self->{_address_group} = $config->returnOrigValue("group address-group"); - $self->{_network_group} = $config->returnOrigValue("group network-group"); - $self->{_port_group} = $config->returnOrigValue("group port-group"); +sub setupOrig { + my ($self, $level) = @_; + $self->setup_base($level, 'returnOrigValue'); return 0; } |