--- lib/PXElator/client.pm 2009/08/28 16:41:46 322 +++ lib/PXElator/client.pm 2009/08/28 21:55:41 329 @@ -6,6 +6,7 @@ use File::Slurp; use Net::Ping; +use Data::Dump qw/dump/; use server; use format; @@ -105,13 +106,14 @@ sub save_ip_mac { my ($ip,$mac) = @_; $mac = format::mac($mac); + return if $mac eq '00:00:00:00:00:00'; mkdir ip_path($ip) unless -e ip_path($ip); my $mac_path = mac_path($mac); unlink $mac_path if -l $mac_path; # XXX audit? symlink ip_path($ip), $mac_path; - write_file ip_path($ip,'mac'), $mac; + write_file( ip_path($ip,'mac'), $mac ); } sub ip_from_mac($) { @@ -144,10 +146,12 @@ sub change_ip($$) { my ($old, $new) = @_; - my $mac = mac_from_ip($old); + return if $old eq $new; + my $mac = mac_from_ip($old) || die "no mac for $old"; rename ip_path($old), ip_path($new); unlink mac_path($mac); symlink ip_path($new), mac_path($mac); + return $new; } sub all_ips { @@ -159,4 +163,29 @@ } glob("$server::conf/ip/*") } +sub remove { + my $ip = shift; + unlink $_ foreach grep { -e $_ } ( glob "$server::conf/ip/$ip/*" ); + if ( my $mac = mac_from_ip $ip ) { + unlink "$server::conf/mac/$mac"; + } + rmdir "$server::conf/ip/$ip"; +} + +sub arp_mac_dev { + my $arp = { + map { + my @c = split(/\s+/,$_); + if ( $#c == 5 ) { + client::save_ip_mac( $c[0], $c[3] ); + ( uc $c[3] => $c[5] ) + } else { + } + } read_file('/proc/net/arp') + }; + + warn "# arp ",dump( $arp ); + return $arp; +} + 1;