Created
July 25, 2010 06:21
-
-
Save dlundquist/489358 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# $Id$ | |
# This script enables IPv6 proxy arp for each address assigned to a container | |
# on this host. It also enables the nessacary sysctls for neighbor | |
# advertisments to be sent for container addresses. | |
# | |
# Written by Dustin Lundquist <[email protected]> | |
use warnings; | |
use strict; | |
my @ipv6_addresses; | |
my @ipv4_addresses; | |
my @sysctls = ( | |
'/proc/sys/net/ipv6/conf/all/forwarding', | |
'/proc/sys/net/ipv6/conf/default/forwarding', | |
'/proc/sys/net/ipv6/conf/all/proxy_ndp', | |
'/proc/sys/net/ipv6/conf/default/proxy_ndp', | |
); | |
open(VEINFO, '/proc/vz/veinfo') | |
or die "Unable to open /proc/vz/veinfo: $1"; | |
while(my $line = <VEINFO>) { | |
$line =~ s/^\s+//; | |
my ($veid, $class_id, $proc_num, @ips) = split (/\s+/, $line); | |
foreach my $ip (@ips) { | |
if ($ip =~ m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { | |
push @ipv4_addresses, $ip; | |
} else { | |
push @ipv6_addresses, $ip; | |
} | |
} | |
} | |
close(VEINFO); | |
foreach my $sysctl (@sysctls) { | |
my $value = undef; | |
open (SYSCTL, $sysctl) | |
or die "Unable to open $sysctl: $!"; | |
$value = <SYSCTL>; | |
chomp($value); | |
close (SYSCTL); | |
next if ($value eq '1'); | |
open (SYSCTL, '>>', $sysctl) | |
or die "Unable to open $sysctl: $!"; | |
print SYSCTL "1\n"; | |
close (SYSCTL); | |
print "$sysctl = 0 -> 1\n"; | |
} | |
foreach my $ip (@ipv6_addresses) { | |
print "/sbin/ip -6 neigh add proxy $ip dev eth0\n"; | |
system('/sbin/ip', '-6', 'neigh', 'add', 'proxy', $ip, 'dev', 'eth0'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment