47 |
|
|
48 |
if ( -e "$conf/mac/$mac" ) { |
if ( -e "$conf/mac/$mac" ) { |
49 |
my $ip = read_file "$conf/mac/$mac"; |
my $ip = read_file "$conf/mac/$mac"; |
50 |
print "$mac old $ip\n"; |
print "RENEW $mac $ip\n"; |
51 |
return $ip; |
return $ip; |
52 |
} |
} |
53 |
|
|
85 |
my $size = 'empty'; |
my $size = 'empty'; |
86 |
$size = length($buf) . ' bytes' if defined $buf; |
$size = length($buf) . ' bytes' if defined $buf; |
87 |
|
|
88 |
print "packet from ",$sock->peerhost,":",$sock->peerport," $size\n"; |
print "packet from ",$sock->peerhost,":",$sock->peerport," $size\n" if $debug; |
89 |
return unless $buf; |
return unless $buf; |
90 |
|
|
91 |
my $dhcp = Net::DHCP::Packet->new($buf); |
my $dhcp = Net::DHCP::Packet->new($buf); |
126 |
my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE()); |
my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE()); |
127 |
|
|
128 |
if ($messagetype eq DHCPDISCOVER()) { |
if ($messagetype eq DHCPDISCOVER()) { |
129 |
warn "DHCP DISCOVER"; |
log::mac $mac, "DHCP DISCOVER"; |
130 |
$packet->{Comment} = $dhcp->comment(); |
$packet->{Comment} = $dhcp->comment(); |
131 |
$packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPOFFER(); |
$packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPOFFER(); |
132 |
} elsif ($messagetype eq DHCPREQUEST()) { |
} elsif ($messagetype eq DHCPREQUEST()) { |
133 |
my $requested_ip = $dhcp->getOptionValue(DHO_DHCP_REQUESTED_ADDRESS()); |
my $requested_ip = $dhcp->getOptionValue(DHO_DHCP_REQUESTED_ADDRESS()); |
134 |
warn "DHCP REQUEST $requested_ip"; |
log::mac $mac, "DHCP REQUEST $requested_ip $ip $pxe::file"; |
135 |
if ( $ip eq $requested_ip ) { |
if ( $ip eq $requested_ip ) { |
136 |
$packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPACK(); |
$packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPACK(); |
137 |
$packet->{DHO_DHCP_LEASE_TIME()} = 5 * 60; # 5 min |
$packet->{DHO_DHCP_LEASE_TIME()} = 5 * 60; # 5 min |
146 |
$packet->{DHO_DHCP_MESSAGE()} = "Bad request, expected $ip"; |
$packet->{DHO_DHCP_MESSAGE()} = "Bad request, expected $ip"; |
147 |
} |
} |
148 |
} elsif ($messagetype eq DHCPINFORM()) { |
} elsif ($messagetype eq DHCPINFORM()) { |
149 |
warn "DHCP INFORM ignored"; |
log::mac $mac, "DHCP INFORM ignored"; |
150 |
} else { |
} else { |
151 |
warn "$messagetype igored (bootp?)"; |
log::mac $mac, "$messagetype igored (bootp?)"; |
152 |
} |
} |
153 |
|
|
154 |
warn ">> $mac == $ip server: $server::ip", $pxe::file ? " pxe file: $pxe::file\n" : "\n"; |
warn ">> $mac == $ip server: $server::ip", $pxe::file ? " pxe file: $pxe::file\n" : "\n" if $debug; |
155 |
|
|
156 |
$packet = new Net::DHCP::Packet( %$packet ); |
$packet = new Net::DHCP::Packet( %$packet ); |
157 |
warn "send ",$packet->toString() if $debug; |
warn "send ",$packet->toString() if $debug; |