From 3ec3f2e3576b887d2c15ef548f28e087885cb801 Mon Sep 17 00:00:00 2001 From: Carl Byington Date: Thu, 8 Jan 2015 16:28:11 -0800 Subject: allow dhcp-interface for the next-hop on static routes Signed-off-by: Daniil Baturin --- scripts/vyatta-static-dhcp.pl | 32 ++++++++++++++++++++++++++++++++ scripts/vyatta-update-static-route.pl | 29 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100755 scripts/vyatta-static-dhcp.pl create mode 100755 scripts/vyatta-update-static-route.pl (limited to 'scripts') diff --git a/scripts/vyatta-static-dhcp.pl b/scripts/vyatta-static-dhcp.pl new file mode 100755 index 00000000..2bec6043 --- /dev/null +++ b/scripts/vyatta-static-dhcp.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl +use Getopt::Long; +use strict; + +my ($iface, $dhcp, $route, $table, $nip, $oip, $reason); +GetOptions("interface=s" => \$iface, + "dhcp=s" => \$dhcp, + "route=s" => \$route, + "table=s" => \$table, + "new_routers=s" => \$nrouters, + "old_routers=s" => \$orouters, + "reason=s" => \$reason); + +# check if an update is needed +exit(0) if (($iface ne $dhcp) || ($orouters eq $nrouters) || ($reason ne "BOUND")); +logger("DHCP address on $iface updated to $nip from $oip: Updating static route $route in table $table."); +if ($table eq "main") { + $table = ""; +} +else { + $table = "table $table"; +} +system("vtysh -c 'configure terminal' -c 'ip route $route $nrouters $table' "); + +sub logger { + my $msg = pop(@_); + my $FACILITY = "daemon"; + my $LEVEL = "notice"; + my $TAG = "tunnel-dhclient-hook"; + my $LOGCMD = "logger -t $TAG -p $FACILITY.$LEVEL"; + system("$LOGCMD $msg"); +} diff --git a/scripts/vyatta-update-static-route.pl b/scripts/vyatta-update-static-route.pl new file mode 100755 index 00000000..5ac98fcd --- /dev/null +++ b/scripts/vyatta-update-static-route.pl @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +use Getopt::Long; +use strict; +use lib "/opt/vyatta/share/perl5"; +use Vyatta::Config; + +my ($iface, $route, $table, $option); +GetOptions("interface=s" => \$iface, + "route=s" => \$route, + "table=s" => \$table, + "option=s" => \$option + ); +my $hash = `echo $iface $route $table | md5sum | cut -c1-10`; +my $FILE_DHCP_HOOK = "/etc/dhcp3/dhclient-exit-hooks.d/static-route-$hash"; +my $dhcp_hook = ''; +if ($option eq 'create') { + $dhcp_hook =<', $FILE_DHCP_HOOK + or die "cannot open $FILE_DHCP_HOOK"; +print ${dhcp_hook_file} $dhcp_hook; +close $dhcp_hook_file; +exit 0; + -- cgit v1.2.3