diff options
author | Carl Byington <carl@five-ten-sg.com> | 2015-01-08 16:28:11 -0800 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2015-05-03 19:16:22 +0200 |
commit | 3ec3f2e3576b887d2c15ef548f28e087885cb801 (patch) | |
tree | 000355235760117e0e9f211f6d6e1ec906468b1d /scripts | |
parent | d22cda1ad0ba9c14efb62f2f8f8c3ed43a08099d (diff) | |
download | vyatta-cfg-quagga-3ec3f2e3576b887d2c15ef548f28e087885cb801.tar.gz vyatta-cfg-quagga-3ec3f2e3576b887d2c15ef548f28e087885cb801.zip |
allow dhcp-interface for the next-hop on static routes
Signed-off-by: Daniil Baturin <daniil@baturin.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/vyatta-static-dhcp.pl | 32 | ||||
-rwxr-xr-x | scripts/vyatta-update-static-route.pl | 29 |
2 files changed, 61 insertions, 0 deletions
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 =<<EOS; +#!/bin/sh +/opt/vyatta/bin/sudo-users/vyatta-static-dhcp.pl --interface=\"\$interface\" --dhcp=\"$iface\" --route=\"$route\" --table=\"$table\" --new_routers=\"\$new_routers\" --old_routers=\"\$old_routers\" --reason=\"\$reason\" +EOS +} + +open my $dhcp_hook_file, '>', $FILE_DHCP_HOOK + or die "cannot open $FILE_DHCP_HOOK"; +print ${dhcp_hook_file} $dhcp_hook; +close $dhcp_hook_file; +exit 0; + |