From d58ea68e07ac987e642947ceabe3dd87ecdb22ad Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Thu, 26 Jun 2008 16:34:42 +0000 Subject: => Modified VyattaConfig.pm function 'returnOrigValues()' to return empty array when no value is configured => Modified VyattaConfigLoad.pm to give a higher ranking to 'system host-name' than 'interface' so that during boot-up if host is using dhcp client to get an ip for an interface, it can send the host-name if configured => Modified vyatta-interfaces.pl: 1. to request only for dhcp options 'subnet-nask', 'broadcast address', 'routers', 'domain-name-servers' when an interface is configured to get an ip using dhcp. 2. ask for a domain-name only if domain-name is not configured in our CLI 3. do not request dhcp options: 'time-offset', 'interface-mtu' and 'host-name' that were being requested before 4. Update /etc/resolv.conf to remove domain-name and name-server options received from dhcp server for the particular interface that releases dhcp lease either from op-mode or cfg-mode --- scripts/VyattaConfig.pm | 5 ++++- scripts/VyattaConfigLoad.pm | 1 + scripts/vyatta-interfaces.pl | 27 ++++++++++++++++++++++----- 3 files changed, 27 insertions(+), 6 deletions(-) (limited to 'scripts') diff --git a/scripts/VyattaConfig.pm b/scripts/VyattaConfig.pm index 941bb63..9ddc8ef 100755 --- a/scripts/VyattaConfig.pm +++ b/scripts/VyattaConfig.pm @@ -262,7 +262,10 @@ sub returnValues { # node is relative sub returnOrigValues { my $val = returnOrigValue(@_); - my @values = split("\n", $val); + my @values = (); + if (defined($val)) { + @values = split("\n", $val); + } return @values; } diff --git a/scripts/VyattaConfigLoad.pm b/scripts/VyattaConfigLoad.pm index 1a7f26e..71203be 100755 --- a/scripts/VyattaConfigLoad.pm +++ b/scripts/VyattaConfigLoad.pm @@ -32,6 +32,7 @@ my %config_rank = ( 'qos-policy' => 1100, 'firewall' => 1020, 'service nat' => 1010, + 'system host-name' => 1005, 'interfaces' => 1000, 'interfaces bridge' => 990, 'interfaces ethernet' => 980, diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index 1511c12..5424b64 100644 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -111,9 +111,6 @@ sub dhcp_conf_header { my $date = `date`; chomp $date; $output = "#\n# autogenerated by vyatta-interfaces.pl on $date\n#\n"; - $output .= "request subnet-mask, broadcast-address, time-offset, routers,\n"; - $output .= "\tdomain-name, domain-name-servers, host-name,\n"; - $output .= "\tinterface-mtu;\n\n"; return $output; } @@ -179,6 +176,15 @@ sub get_hostname { return $hostname; } +sub is_domain_name_set { + my $config = new VyattaConfig; + $config->setLevel("system"); + my $domainname = undef; + $domainname = $config->returnValue("domain-name"); + return $domainname; +} + + sub dhcp_update_config { my ($conf_file, $intf) = @_; @@ -189,6 +195,14 @@ sub dhcp_update_config { if (defined($hostname)) { $output .= "\tsend host-name \"$hostname\";\n"; } + $output .= "\trequest subnet-mask, broadcast-address, routers, domain-name-servers"; + my $domainname = is_domain_name_set(); + if (!defined($domainname)) { + $output .= ", domain-name;\n"; + } else { + $output .= ";\n"; + } + $output .= "}\n\n"; dhcp_write_file($conf_file, $output); @@ -240,10 +254,13 @@ sub run_dhclient { sub stop_dhclient { my $intf = shift; + my $new_resolv_conf = "/etc/resolv.conf.dhclient-new-$intf"; my ($intf_config_file, $intf_process_id_file, $intf_leases_file) = generate_dhclient_intf_files($intf); - my $cmd = "$dhcp_daemon -q -cf $intf_config_file -pf $intf_process_id_file -lf $intf_leases_file -r $intf 2> /dev/null"; - system ($cmd); + 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); + my $update_resolv_conf_cmd = "rm -f $new_resolv_conf; echo \" \" > $new_resolv_conf; /opt/vyatta/sbin/vyatta_update_resolv.pl --dhclient-script 1"; + system($update_resolv_conf_cmd); system ("rm -f $intf_config_file"); } -- cgit v1.2.3