summaryrefslogtreecommitdiff
path: root/scripts/vyatta-static-dhcp.pl
blob: 2bec6043d0a226b863f02b89e24ef4ebdb6e7c35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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");
}