summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Byington <carl@five-ten-sg.com>2015-01-08 16:28:11 -0800
committerDaniil Baturin <daniil@baturin.org>2015-05-03 19:16:22 +0200
commit3ec3f2e3576b887d2c15ef548f28e087885cb801 (patch)
tree000355235760117e0e9f211f6d6e1ec906468b1d
parentd22cda1ad0ba9c14efb62f2f8f8c3ed43a08099d (diff)
downloadvyatta-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>
-rw-r--r--Makefile.am4
-rwxr-xr-xscripts/vyatta-static-dhcp.pl32
-rwxr-xr-xscripts/vyatta-update-static-route.pl29
-rw-r--r--templates/protocols/static/route/node.def6
-rw-r--r--templates/protocols/static/route/node.tag/dhcp-interface/node.def23
-rw-r--r--templates/protocols/static/route/node.tag/next-hop/node.def8
-rw-r--r--templates/protocols/static/table/node.tag/route/node.def6
-rw-r--r--templates/protocols/static/table/node.tag/route/node.tag/dhcp-interface/node.def26
-rw-r--r--templates/protocols/static/table/node.tag/route/node.tag/next-hop/node.def2
9 files changed, 127 insertions, 9 deletions
diff --git a/Makefile.am b/Makefile.am
index 9dfe6451..8686c2f8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,6 @@
share_perl5dir = /opt/vyatta/share/perl5/Vyatta/Quagga
cfgdir = $(datadir)/vyatta-cfg/templates
+bin_sudo_usersdir = $(bindir)/sudo-users
curverdir = $(sysconfdir)/config-migrate/current
gentmpdir = generated-templates
@@ -11,6 +12,9 @@ sbin_SCRIPTS += scripts/vyatta-policy-action-verify.pl
sbin_SCRIPTS += scripts/vyatta-gateway-static_route-check.pl
sbin_SCRIPTS += scripts/vyatta-link-detect
sbin_SCRIPTS += scripts/vyatta-next-hop-check
+sbin_SCRIPTS += scripts/vyatta-update-static-route.pl
+
+bin_sudo_users_SCRIPTS += scripts/vyatta-static-dhcp.pl
sbin_PROGRAMS = src/check_prefix_boundary
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;
+
diff --git a/templates/protocols/static/route/node.def b/templates/protocols/static/route/node.def
index 682ca944..e86812db 100644
--- a/templates/protocols/static/route/node.def
+++ b/templates/protocols/static/route/node.def
@@ -3,5 +3,7 @@ type: ipv4net
help: Static route
syntax:expression: exec "${vyatta_sbindir}/check_prefix_boundary $VAR(@)"
-commit:expression: $VAR(./next-hop/) != "" || $VAR(./blackhole/) != ""; \
- "Must add either a next-hop or blackhole for route $VAR(@)"
+commit:expression: $VAR(./next-hop/) != "" || $VAR(./blackhole/) != "" || $VAR(./dhcp-interface/) != ""; \
+ "Must add either a next-hop or blackhole or dhcp-interface for route $VAR(@)"
+commit:expression: $VAR(./next-hop/) == "" || $VAR(./dhcp-interface/) == ""; \
+ "Must configure only one of next-hop or dhcp-interface for route $VAR(@)"
diff --git a/templates/protocols/static/route/node.tag/dhcp-interface/node.def b/templates/protocols/static/route/node.tag/dhcp-interface/node.def
new file mode 100644
index 00000000..4942bf5f
--- /dev/null
+++ b/templates/protocols/static/route/node.tag/dhcp-interface/node.def
@@ -0,0 +1,23 @@
+type: txt
+help: DHCP interface that supplies the next-hop IP address for this static route
+allowed:
+ local -a array ;
+ array=( /var/lib/dhcp3/eth* /var/lib/dhcp3/br* /var/lib/dhcp3/bond* ) ;
+ echo -n ${array[@]##*/}
+create:
+ sudo /opt/vyatta/sbin/vyatta-update-static-route.pl --interface=$VAR(@) --route=$VAR(../@) --table=main --option=create
+ RIP=$(/opt/vyatta/sbin/vyatta-dhcp-helper.pl --interface=$VAR(@) --want=router)
+ vtysh -c "configure terminal" \
+ -c "ip route $VAR(../@) $RIP"
+update:
+ sudo /opt/vyatta/sbin/vyatta-update-static-route.pl --interface=$VAR(@) --route=$VAR(../@) --table=main --option=create
+ RIP=$(/opt/vyatta/sbin/vyatta-dhcp-helper.pl --interface=$VAR(@) --want=router)
+ vtysh -c "configure terminal" \
+ -c "ip route $VAR(../@) $RIP"
+delete:
+ sudo /opt/vyatta/sbin/vyatta-update-static-route.pl --interface=$VAR(@) --route=$VAR(../@) --table=main --option=delete
+ RIP=$(/opt/vyatta/sbin/vyatta-dhcp-helper.pl --interface=$VAR(@) --want=router)
+ if [ "$RIP" != "127.0.0.1" ]; then
+ vtysh -c "configure terminal" \
+ -c "no ip route $VAR(../@) $RIP"
+ fi
diff --git a/templates/protocols/static/route/node.tag/next-hop/node.def b/templates/protocols/static/route/node.tag/next-hop/node.def
index f5d5d417..e5106b02 100644
--- a/templates/protocols/static/route/node.tag/next-hop/node.def
+++ b/templates/protocols/static/route/node.tag/next-hop/node.def
@@ -1,17 +1,17 @@
tag:
type: ipv4
-help: Next-hop router [REQUIRED]
+help: Next-hop router
end:
if [[ -z "$VAR(./disable)" ]]
- then
+ then
if [[ ${COMMIT_ACTION} = 'DELETE' ]]
- then
+ then
if ! ${vyatta_sbindir}/vyatta-next-hop-check $VAR(../@) ipv4 address; then
exit 1;
fi
if ${vyatta_sbindir}/vyatta-gateway-static_route-check.pl \
"$VAR(../@)" "$VAR(@)"
- then
+ then
vtysh -c "configure terminal" \
-c "no ip route $VAR(../@) $VAR(@)"
fi
diff --git a/templates/protocols/static/table/node.tag/route/node.def b/templates/protocols/static/table/node.tag/route/node.def
index 682ca944..e86812db 100644
--- a/templates/protocols/static/table/node.tag/route/node.def
+++ b/templates/protocols/static/table/node.tag/route/node.def
@@ -3,5 +3,7 @@ type: ipv4net
help: Static route
syntax:expression: exec "${vyatta_sbindir}/check_prefix_boundary $VAR(@)"
-commit:expression: $VAR(./next-hop/) != "" || $VAR(./blackhole/) != ""; \
- "Must add either a next-hop or blackhole for route $VAR(@)"
+commit:expression: $VAR(./next-hop/) != "" || $VAR(./blackhole/) != "" || $VAR(./dhcp-interface/) != ""; \
+ "Must add either a next-hop or blackhole or dhcp-interface for route $VAR(@)"
+commit:expression: $VAR(./next-hop/) == "" || $VAR(./dhcp-interface/) == ""; \
+ "Must configure only one of next-hop or dhcp-interface for route $VAR(@)"
diff --git a/templates/protocols/static/table/node.tag/route/node.tag/dhcp-interface/node.def b/templates/protocols/static/table/node.tag/route/node.tag/dhcp-interface/node.def
new file mode 100644
index 00000000..177d153a
--- /dev/null
+++ b/templates/protocols/static/table/node.tag/route/node.tag/dhcp-interface/node.def
@@ -0,0 +1,26 @@
+type: txt
+help: DHCP interface that supplies the next-hop IP address for this static route
+allowed:
+ local -a array ;
+ array=( /var/lib/dhcp3/eth* /var/lib/dhcp3/br* /var/lib/dhcp3/bond* ) ;
+ echo -n ${array[@]##*/}
+create:
+ [ -n "$VAR(../../../table/@)" ] && table="table $VAR(../../../table/@)"
+ sudo /opt/vyatta/sbin/vyatta-update-static-route.pl --interface=$VAR(@) --route=$VAR(../@) --table=$VAR(../../@) --option=create
+ RIP=$(/opt/vyatta/sbin/vyatta-dhcp-helper.pl --interface=$VAR(@) --want=router)
+ vtysh -c "configure terminal" \
+ -c "ip route $VAR(../@) $RIP $table"
+update:
+ [ -n "$VAR(../../../table/@)" ] && table="table $VAR(../../../table/@)"
+ sudo /opt/vyatta/sbin/vyatta-update-static-route.pl --interface=$VAR(@) --route=$VAR(../@) --table=$VAR(../../@) --option=create
+ RIP=$(/opt/vyatta/sbin/vyatta-dhcp-helper.pl --interface=$VAR(@) --want=router)
+ vtysh -c "configure terminal" \
+ -c "ip route $VAR(../@) $RIP $table"
+delete:
+ [ -n "$VAR(../../../table/@)" ] && table="table $VAR(../../../table/@)"
+ sudo /opt/vyatta/sbin/vyatta-update-static-route.pl --interface=$VAR(@) --route=$VAR(../@) --table=$VAR(../../@) --option=delete
+ RIP=$(/opt/vyatta/sbin/vyatta-dhcp-helper.pl --interface=$VAR(@) --want=router)
+ if [ "$RIP" != "127.0.0.1" ]; then
+ vtysh -c "configure terminal" \
+ -c "no ip route $VAR(../@) $RIP $table"
+ fi \ No newline at end of file
diff --git a/templates/protocols/static/table/node.tag/route/node.tag/next-hop/node.def b/templates/protocols/static/table/node.tag/route/node.tag/next-hop/node.def
index 5fb54a8b..17f1f0dc 100644
--- a/templates/protocols/static/table/node.tag/route/node.tag/next-hop/node.def
+++ b/templates/protocols/static/table/node.tag/route/node.tag/next-hop/node.def
@@ -1,6 +1,6 @@
tag:
type: ipv4
-help: Next-hop router [REQUIRED]
+help: Next-hop router
end:
if [[ -n "$VAR(../../../table/@)" ]]
then