summaryrefslogtreecommitdiff
path: root/scripts/vyatta-tunnel-dhcp.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/vyatta-tunnel-dhcp.pl')
-rw-r--r--scripts/vyatta-tunnel-dhcp.pl25
1 files changed, 25 insertions, 0 deletions
diff --git a/scripts/vyatta-tunnel-dhcp.pl b/scripts/vyatta-tunnel-dhcp.pl
new file mode 100644
index 00000000..4283b30a
--- /dev/null
+++ b/scripts/vyatta-tunnel-dhcp.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+use Getopt::Long;
+use strict;
+
+my ($iface, $dhcp, $tunnel, $nip, $oip, $reason);
+GetOptions("interface=s" => \$iface,
+ "dhcp=s" => \$dhcp,
+ "tunnel=s" => \$tunnel,
+ "new_ip=s" => \$nip,
+ "old_ip=s" => \$oip,
+ "reason=s" => \$reason);
+
+# check if an update is needed
+exit(0) if (($iface ne $dhcp) || ($oip eq $nip) || ($reason ne "BOUND"));
+logger("DHCP address on $iface updated to $nip from $oip: Updating tunnel $tunnel configuration.");
+system("sudo ip tunnel change $tunnel local $nip");
+
+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");
+}