16 $path =~ s{(^.*)/[^/]+$}{$1};
17 mkdir $path unless -d $path;
21 sub mac_path { $server::conf . '/mac/' . $_[0] }
22 sub ip_path { $server::conf . '/ip/' . join('/', @_) }
27 $value = readlink $path;
28 $value =~ s{.*/([^/]+)$}{$1};
29 } elsif ( -f $path ) {
30 $value = read_file $path;
32 confess "$path not file or symlink";
40 my ( $default, $value );
43 } elsif ( $#_ == 1 && $_[0] eq 'default' ) {
47 my $path = ip_path $ip;
48 mkdir $path unless -d $path;
51 if ( defined $value ) {
53 write_file $path, $value;
54 warn "update $path = $value";
55 } elsif ( ! -e $path && defined $default ) {
57 write_file $path, $default;
58 warn "default $path = $default";
60 } elsif ( -f $path ) {
61 $value = read_file $path;
71 my $p = Net::Ping->new;
73 my $prefix = $server::ip;
74 $prefix =~ s{\.\d+$}{.};
75 my $addr = $server::ip_from || die;
76 my $ip = $prefix . $addr;
78 while ( -e ip_path($ip) || $p->ping( $ip, 0.7 ) ) {
79 $ip = $prefix . $addr++;
80 die "all addresses allocated!" if $addr == $server::ip_to;
88 my $mac_path = mac_path($mac);
89 unlink $mac_path if -e $mac_path; # XXX audit?
90 symlink ip_path($ip), $mac_path;
91 write_file ip_path($ip,'mac'), $mac;
103 my $mac_path = mac_path $mac;
104 return unless -e $mac_path;
108 if ( -f $mac_path ) {
109 $ip = read_file $mac_path;
111 symlink ip_path($ip), $mac_path;
112 warn "I: upgrade to mac symlink $mac_path\n";
113 } elsif ( -l $mac_path ) {
114 $ip = conf_value $mac_path;
116 die "$mac_path not file or symlink";
124 conf_value ip_path($ip, 'mac');
128 my ($old, $new) = @_;
129 my $mac = mac_from_ip($old);
130 rename ip_path($old), ip_path($new);
131 unlink mac_path($mac);
132 symlink ip_path($new), mac_path($mac);