sudo ifup tap0
rm conf/server.ip ; ln -sf 172.16.10.1 conf/server.ip
+./bin/start-split.sh &
+
+#sudo tshark -i tap0 &
+
vdeq kvm -m 512 -net nic,vlan=1,macaddr=52:54:00:12:01:00 \
-net vde,vlan=1,sock=/var/run/vde2/tap0.ctl \
-boot n
sessionname PXElator
split
-screen -t dhcpd sudo ./bin/dhcpd.pl
+screen -t dhcpd sudo perl -Ilib/PXElator -Ilib -Mdhcpd -e start
logfile /tmp/pxelator.dhcpd.log
log on
focus down
-screen -t tftpd sudo ./bin/tftpd.pl
+screen -t tftpd sudo perl -Ilib/PXElator -Ilib -Mtftpd -e tftpd::start
logfile /tmp/pxelator.tftp.log
log on
screen="screen -R PXElator -c /tmp/screenrc"
-test ! -z "$DISPLAY" && xterm -e $screen || $screen
+test ! -z "$DISPLAY" && xterm -e $screen
return $v ? 0 : 1;
}
+warn "loaded";
+
1;
use Net::DHCP::Constants 0.67;
use server;
+use pxe;
my $debug = 1;
-our ( $file, $gpxe_file );
-our ( $ip_from, $ip_to ) = ( 10, 100 );
-
if ( ! $server::ip ) {
my $server_ip = `/sbin/ifconfig`;
$server_ip =~ s/^.+?addr:([\d\.]+).*$/$1/gs;
$server::ip = $server_ip;
}
-warn "server ip $server::ip\n";
+warn "server ip $server::ip file: $pxe::file range: $server::ip_from - $server::ip_to\n";
-my $addr = $ip_from;
+my $addr = $server::ip_from;
sub client_ip {
my ( $mac ) = @_;
my $ip = $prefix . $addr;
while ( -e "conf/ip/$ip" || $p->ping( $ip ) ) {
$ip = $prefix . $addr++;
- die "all addresses allocated!" if $addr == $ip_to;
+ die "all addresses allocated!" if $addr == $server::ip_to;
}
write_file "$conf/mac/$mac", $ip;
Siaddr => $server::ip,
Giaddr => $dhcp->giaddr(),
Chaddr => $dhcp->chaddr(),
- File => $file,
+ File => $pxe::file,
};
my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE());
warn "$messagetype igored (bootp?)";
}
- warn ">> $mac == $ip server: $server::ip", $file ? " file: $file\n" : "\n";
+ warn ">> $mac == $ip server: $server::ip", $pxe::file ? " pxe file: $pxe::file\n" : "\n";
$packet = new Net::DHCP::Packet( %$packet );
warn "## ",$packet->toString(),"\n" if $debug;
}
}
+warn "loaded";
+
1;
$html .= qq{</tr>\n</table>};
}
+warn "loaded";
+
1;
die "server died";
}
+warn "loaded";
+
1;
--- /dev/null
+package pxe;
+
+use warnings;
+use strict;
+
+use File::Slurp;
+
+use server;
+use tftpd;
+
+our $file = 'gpxelinux.0';
+my $path = "$tftpd::dir/$file";
+symlink '/usr/lib/syslinux/gpxelinux.0', $path unless -l $path;
+warn "file $path ", -s $path;
+
+my $url = "http://$server::ip/pxelator/debian-live/";
+my $squash = tftpd::path('debian-live/*squashfs');
+
+
+my $config = "$ftpd::dir/pxelinux.cfg/default";
+
+write_file $config, qq{
+
+default linux
+label linux
+ kernel $url/vmlinuz1
+ append initrd=$url/initrd1.img boot=live union=aufs noswap noprompt vga=normal fetch=$url/$squash
+
+};
+
+warn "config $config ", -s $config;
+
+warn "loaded";
+
+1;
our $ip = '172.16.10.1';
+our ( $ip_from, $ip_to ) = ( 10, 100 );
+
+warn "loaded";
--- /dev/null
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use autodie;
+
+use Test::More tests => 2;
+
+use_ok 'dhcpd';
+
+ok( ! $dhcpd::transaction, 'transaction' );
--- /dev/null
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use autodie;
+
+use Test::More tests => 2;
+
+use_ok 'pxe';
+
+ok( my $file = $pxe::file, 'file' );
+diag $file;
--- /dev/null
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use autodie;
+
+use Test::More tests => 2;
+
+use_ok 'tftpd';
+
+ok( my $path = tftpd::path('*'), 'path' );
+diag $path;
--- /dev/null
+package tftpd;
+
+use warnings;
+use strict;
+
+use Net::TFTPd 0.03 qw(%OPCODES);
+use Data::Dump qw/dump/;
+
+our $dir = '/home/dpavlin/llin/pxelator/tftp';
+
+sub path {
+ my $glob = shift;
+ my $path = glob("$dir/$glob");
+ die "can't find anything for $dir/$glob" unless $path;
+warn $path;
+ $path =~ s{^$dir}{};
+ return $path;
+}
+
+sub transfer_status {
+ my $req = shift;
+ if( $req->{'_REQUEST_'}{'OPCODE'} eq $OPCODES{'RRQ'} ) {
+ printf "RRQ %u\/%u\r", $req->{'_REQUEST_'}{'LASTACK'}, $req->{'_REQUEST_'}{'LASTBLK'};
+ } elsif ( $req->{'_REQUEST_'}{'OPCODE'} eq $OPCODES{'WRQ'} ) {
+ die "WRQ disabled";
+ printf "WRQ: %u\/%u\n", $req->{'_REQUEST_'}{'LASTBLK'}, $req->{'_REQUEST_'}{'LASTACK'};
+ } else {
+ warn "IGNORED: ", dump( $req );
+ }
+}
+
+sub tftp_request {
+ my $request = shift;
+
+ if ( $request->{RootDir} ne $dir ) {
+ $request->{RootDir} = $dir;
+ warn "new root: $dir";
+ }
+
+ # received request
+ printf "Received a %s for file '%s'\n", $OPCODES{$request->{'_REQUEST_'}{'OPCODE'}}, $request->{'_REQUEST_'}{'FileName'};
+
+ # process the request
+ if( $request->processRQ() ) {
+ print "OK, transfer completed successfully\n";
+ } else {
+ warn Net::TFTPd->error;
+ $request->processRQ();
+ }
+
+}
+
+use server;
+
+sub start {
+
+ warn 'start';
+
+ my $listener = Net::TFTPd->new(
+ RootDir => $dir,
+ Writable => 0,
+ Timeout => 3600,
+ CallBack => \&transfer_status,
+# LocalAddr => $server::ip,
+# BlkSize => 8192,
+# BlkSize => 512,
+ BlkSize => 1456, # IBM GE seems to be picky
+ Debug => 99,
+ ) || die Net::TFTPd->error;
+
+ warn 'listener: ',dump( $listener );
+
+ while(1) {
+
+ printf "TFTP listen %s:%d timeout: %d dir: $dir\n",
+ $listener->{LocalAddr},
+ $listener->{LocalPort},
+ $listener->{Timeout};
+
+ # wait for any request (RRQ or WRQ)
+ if(my $request = $listener->waitRQ()) {
+ tftp_request $request;
+ } else {
+ warn Net::TFTPd->error;
+ }
+
+ }
+
+}
+
+warn "loaded";
+
+1;