diff options
author | Mohit Mehta <mohit.mehta@vyatta.com> | 2008-11-17 14:06:50 -0800 |
---|---|---|
committer | Mohit Mehta <mohit.mehta@vyatta.com> | 2008-11-17 14:06:50 -0800 |
commit | 9e936dd974391ae8c694e9e04bf5393b8a68e477 (patch) | |
tree | 163857424ee9e6ab2df4aa819687e2beffb9d14b /scripts/vyatta-interfaces.pl | |
parent | 396f9ee97a867b549ac2696a9320a9bb0a21608d (diff) | |
download | vyatta-cfg-9e936dd974391ae8c694e9e04bf5393b8a68e477.tar.gz vyatta-cfg-9e936dd974391ae8c694e9e04bf5393b8a68e477.zip |
move submodules to VyattaMisc.pm so that they can be used elsewhere as well
Diffstat (limited to 'scripts/vyatta-interfaces.pl')
-rw-r--r-- | scripts/vyatta-interfaces.pl | 55 |
1 files changed, 5 insertions, 50 deletions
diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index b5d38af..6ece6c0 100644 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -43,7 +43,6 @@ use strict; use warnings; my $dhcp_daemon = '/sbin/dhclient'; -my $dhclient_dir = '/var/lib/dhcp3/'; my ($eth_update, $eth_delete, $addr, $dev, $mac, $mac_update, $op_dhclient); @@ -123,39 +122,6 @@ sub dhcp_conf_header { return $output; } -sub is_dhcp_enabled { - my $intf = shift; - - my $config = new VyattaConfig; - - # FIXME: this is wrong and depends on name of interface -> type - # which is not dependable - if ($intf =~ m/^eth/) { - if ($intf =~ m/(\w+)\.(\d+)/) { - $config->setLevel("interfaces ethernet $1 vif $2"); - } else { - $config->setLevel("interfaces ethernet $intf"); - } - } elsif ($intf =~ m/^br/) { - $config->setLevel("interfaces bridge $intf"); - } elsif ($intf =~ m/^bond/) { - $config->setLevel("interfaces bonding $intf"); - } else { - # - # FIXME: currently we only support dhcp on ethernet - # and bridge interfaces (what about wireles, ...???) - # - return 0; - } - my @addrs = $config->returnOrigValues("address"); - foreach my $addr (@addrs) { - if (defined $addr && $addr eq "dhcp") { - return 1; - } - } - return 0; -} - sub is_address_enabled { my $intf = shift; @@ -240,21 +206,10 @@ sub dhcp_update_config { dhcp_write_file($conf_file, $output); } -sub generate_dhclient_intf_files { - my $intf = shift; - - $intf =~ s/\./_/g; - my $intf_config_file = $dhclient_dir . 'dhclient_' . $intf . '.conf'; - my $intf_process_id_file = $dhclient_dir . 'dhclient_' . $intf . '.pid'; - my $intf_leases_file = $dhclient_dir . 'dhclient_' . $intf . '.leases'; - return ($intf_config_file, $intf_process_id_file, $intf_leases_file); - -} - sub run_dhclient { my $intf = shift; - my ($intf_config_file, $intf_process_id_file, $intf_leases_file) = generate_dhclient_intf_files($intf); + my ($intf_config_file, $intf_process_id_file, $intf_leases_file) = VyattaMisc::generate_dhclient_intf_files($intf); dhcp_update_config($intf_config_file, $intf); my $cmd = "$dhcp_daemon -q -nw -cf $intf_config_file -pf $intf_process_id_file -lf $intf_leases_file $intf 2> /dev/null &"; # adding & at the end to make the process into a daemon immediately @@ -265,7 +220,7 @@ sub run_dhclient { sub stop_dhclient { my $intf = shift; - my ($intf_config_file, $intf_process_id_file, $intf_leases_file) = generate_dhclient_intf_files($intf); + my ($intf_config_file, $intf_process_id_file, $intf_leases_file) = VyattaMisc::generate_dhclient_intf_files($intf); my $release_cmd = "$dhcp_daemon -q -cf $intf_config_file -pf $intf_process_id_file -lf $intf_leases_file -r $intf 2> /dev/null"; system ($release_cmd) == 0 or warn "stop $dhcp_daemon failed: $?\n"; @@ -393,7 +348,7 @@ sub is_valid_addr { print "Error: can't use dhcp client on loopback interface\n"; exit 1; } - if (is_dhcp_enabled($intf)) { + if (VyattaMisc::is_dhcp_enabled($intf)) { print "Error: dhcp already configured for $intf\n"; exit 1; } @@ -439,7 +394,7 @@ sub is_valid_addr { } } - if (is_dhcp_enabled($intf)) { + if (VyattaMisc::is_dhcp_enabled($intf)) { print "Error: remove dhcp before adding static addresses for $intf\n"; exit 1; } @@ -465,7 +420,7 @@ sub is_valid_addr { sub op_dhcp_command { my ($op_command, $intf) = @_; - if (!is_dhcp_enabled($intf)) { + if (!VyattaMisc::is_dhcp_enabled($intf)) { print "$intf is not using DHCP to get an IP address\n"; exit 1; } |