1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- use strict;
- my $gateway = undef;
- open (ENI, "< /etc/network/interfaces")
- or die "Failed to open '/etc/network/interfaces': $!\n";
- while (my $line = <ENI>) {
- chomp $line;
- # New interface stanza
- if ($line =~ /^iface (.*)/) {
- $gateway = undef;
- }
- # gateway set?
- elsif ($line =~ m/gateway\s+([0-9.]+)$/) {
- $gateway = $1;
- }
- # Interface part of vrf_external
- elsif ($line =~ m/vrf vrf_external/) {
- last;
- }
- }
- close (ENI);
- if (not defined $gateway) {
- exit (0);
- }
- my $default_route_active = undef;
- open (ROUTE, "ip -4 route show table 1023 | grep ^default |")
- or die "Failed to read default route from table 1023: $!\n";
- while (my $line = <ROUTE>) {
- if ($line =~ m/^default via ([0-9.]+)/) {
- $default_route_active = $1;
- }
- }
- close (ROUTE);
- if (not defined $default_route_active) {
- system ("ip route add default via $gateway table 1023");
- }
|