diff options
author | Carl Byington <carl@five-ten-sg.com> | 2015-01-12 16:28:40 -0800 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2015-05-03 19:16:23 +0200 |
commit | 9655fecdaaafe5887617d6f3d97a76a24e00e413 (patch) | |
tree | 7fec88617aac6a3eafa1b21db141f7f276d58cd6 | |
parent | 3f28021c87ecc1c9849925efe6e87627b4ef8b62 (diff) | |
download | vyatta-cfg-quagga-9655fecdaaafe5887617d6f3d97a76a24e00e413.tar.gz vyatta-cfg-quagga-9655fecdaaafe5887617d6f3d97a76a24e00e413.zip |
allow dhcp-interface for the next-hop on static routes
Signed-off-by: Daniil Baturin <daniil@baturin.org>
-rwxr-xr-x | scripts/vyatta-static-dhcp.pl | 22 | ||||
-rwxr-xr-x | scripts/vyatta-update-static-route.pl | 2 | ||||
-rw-r--r-- | templates/protocols/static/table/node.tag/route/node.tag/dhcp-interface/node.def | 49 |
3 files changed, 53 insertions, 20 deletions
diff --git a/scripts/vyatta-static-dhcp.pl b/scripts/vyatta-static-dhcp.pl index 2bec6043..91a4696d 100755 --- a/scripts/vyatta-static-dhcp.pl +++ b/scripts/vyatta-static-dhcp.pl @@ -2,25 +2,35 @@ use Getopt::Long; use strict; -my ($iface, $dhcp, $route, $table, $nip, $oip, $reason); +my ($iface, $dhcp, $route, $table, $nip, $oip, $nrouters, $orouters, $reason); GetOptions("interface=s" => \$iface, "dhcp=s" => \$dhcp, "route=s" => \$route, "table=s" => \$table, + "new_ip=s" => \$nip, + "old_ip=s" => \$oip, "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."); +exit(0) if (($iface ne $dhcp) || (($oip eq $nip) && ($orouters eq $nrouters)) || ($reason ne "BOUND")); +logger("DHCP address on $iface updated to $nip,$nrouters from $oip,$orouters: Updating static route $route in table $table."); +my $tab; if ($table eq "main") { - $table = ""; + $tab = ""; } else { - $table = "table $table"; + $tab = "table $table"; +} +if ($orouters ne $nrouters) { + system("vtysh -c 'configure terminal' -c 'ip route $route $nrouters $tab' "); +} +if (($oip ne $nip) && ($table ne "main") && ($route eq "0.0.0.0/0")) { + my $mark = 0x7ffffff + $table; + system("sudo /sbin/iptables -t mangle -D OUTPUT -s $oip/32 -j MARK --set-mark $mark"); + system("sudo /sbin/iptables -t mangle -A OUTPUT -s $nip/32 -j MARK --set-mark $mark"); } -system("vtysh -c 'configure terminal' -c 'ip route $route $nrouters $table' "); sub logger { my $msg = pop(@_); diff --git a/scripts/vyatta-update-static-route.pl b/scripts/vyatta-update-static-route.pl index 5ac98fcd..557b2011 100755 --- a/scripts/vyatta-update-static-route.pl +++ b/scripts/vyatta-update-static-route.pl @@ -17,7 +17,7 @@ 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\" +/opt/vyatta/bin/sudo-users/vyatta-static-dhcp.pl --interface=\"\$interface\" --dhcp=\"$iface\" --route=\"$route\" --table=\"$table\" --new_ip=\"\$new_ip_address\" --old_ip=\"\$old_ip_address\" --new_routers=\"\$new_routers\" --old_routers=\"\$old_routers\" --reason=\"\$reason\" EOS } 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 index 177d153a..a1b1d08c 100644 --- 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 @@ -5,22 +5,45 @@ allowed: 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) + ifc="$VAR(@)" + route="$VAR(../@)" + table="$VAR(../../@)" + sudo /opt/vyatta/sbin/vyatta-update-static-route.pl --interface=$ifc --route=$route --table=$table --option=create + RIP=$(/opt/vyatta/sbin/vyatta-dhcp-helper.pl --interface=$ifc --want=router) vtysh -c "configure terminal" \ - -c "ip route $VAR(../@) $RIP $table" + -c "ip route $route $RIP table $table" + if [ "$route" == "0.0.0.0/0" ]; then + LIP=$(/opt/vyatta/sbin/vyatta-dhcp-helper.pl --interface=$ifc --want=local) + MARK=$(dc 0x7fffffff $table + p) + sudo /sbin/iptables -t mangle -A OUTPUT -s $LIP/32 -j MARK --set-mark $MARK + fi 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) + ifc="$VAR(@)" + route="$VAR(../@)" + table="$VAR(../../@)" + sudo /opt/vyatta/sbin/vyatta-update-static-route.pl --interface=$ifc --route=$route --table=$table --option=create + RIP=$(/opt/vyatta/sbin/vyatta-dhcp-helper.pl --interface=$ifc --want=router) vtysh -c "configure terminal" \ - -c "ip route $VAR(../@) $RIP $table" + -c "ip route $route $RIP table $table" + if [ "$route" == "0.0.0.0/0" ]; then + LIP=$(/opt/vyatta/sbin/vyatta-dhcp-helper.pl --interface=$ifc --want=local) + MARK=$(dc 0x7fffffff $table + p) + sudo /sbin/iptables -t mangle -A OUTPUT -s $LIP/32 -j MARK --set-mark $MARK + fi 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) + ifc="$VAR(@)" + route="$VAR(../@)" + table="$VAR(../../@)" + sudo /opt/vyatta/sbin/vyatta-update-static-route.pl --interface=$ifc --route=$route --table=$table --option=delete + RIP=$(/opt/vyatta/sbin/vyatta-dhcp-helper.pl --interface=$ifc --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 + -c "no ip route $route $RIP table $table" + fi + if [ "$route" == "0.0.0.0/0" ]; then + LIP=$(/opt/vyatta/sbin/vyatta-dhcp-helper.pl --interface=$ifc --want=local) + if [ "$LIP" != "127.0.0.1" ]; then + MARK=$(dc 0x7fffffff $table + p) + sudo /sbin/iptables -t mangle -D OUTPUT -s $LIP/32 -j MARK --set-mark $MARK + fi + fi |