Networking
with SLIP and Qemu
The
tcp/ip communication is implemented via serial lines using the
slip protocol. This works as long as there are serial ports
available with the PCs used. You can connect ELKS via a „point
to point“ slip connection with a different Linux system and
configure that as a gateway for the ELKS PC. This way ELKS can
connect to the internet, provided the gateway itself is connected
to that. Since there is no name resolution implemented with ELKS
you need to know the IP address required.
If
you do not want to use a cross-over cable between your ELKS PC and
a different Linux PC, you can run ELKS using Qemu on your host and
configure a serial connection with Qemu to that host. This way you
can connect your host and the ELKS system running within Qemu via
a SLIP connection.
To
enable a serial connection from Qemu to your host, start Qemu with
these parameters:
qemu-system-i386 \
-chardev pty,id=chardev1 \
-device isa-serial,chardev=chardev1,id=serial1 \
-fda full3
Qemu will report e.g. "char
device redirected to /dev/pts/4 (label chardev1)" after
loading. Make a note of this pty since you will need that for the
host configuration.
You
could also simply specifiy the „-serial pty“ parameter
but if you use „-chardev pty“ instead you can specify
that this serial device (with the id=chardev1) will emulate an isa
bus serial card so you get the interrupt and i/o address required
for direct hardware access.
After
ELKS has booted, login with "root" and check that ktcp
is running with the command "ps". Then use vi to look at
the "/etc/rc.d/rc.sysinit" file and check the ttybaud
and localip entries in there.
This
is my setting in the file rc.sysinit:
#
# Network initialization
#
localip=192.168.1.10
sliptty=/dev/ttyS0
ttybaud=9600
If you want to change these
settings, modify this file in "elkscmd/rootfs_template/etc/rc.d"
and compile ELKS again. Or modify the file in ELKS and enter the
"reboot" command. This is all that is required on the
ELKS side of the slip connection.
Now
on the host check the presence
of
the new PTY: "ls -l /dev/pts".
Then
use the slattach command to start slip on your host. Slattach can
be used to put a normal terminal ("serial") line into
one of several "network" modes, thus allowing you to
use
it for point-to-point links to other computers.
I
have made the following script to start the slip interface on the
host. Run this script with „sudo“. It takes the number
of the PTY generated by Qemu as a parameter (using $1 in the
script):
slattach -p slip -L -s 9600 /dev/pts/$1 &
ps
ifconfig -a
ifconfig sl0 192.168.1.9 pointopoint 192.168.1.10 netmask 255.255.255.0 mtu 296
ifconfig -a
route add 192.168.1.10 sl0
route -n
The first command is the mentioned
slattach command. Since this does not return you have to run that
in the background with "&" or you cannot continue on
your command line.
The
parameters used with slattach are: "-p slip" which
selects the slip protocol, "-L" enables 3 wire
operation, i.e. no hardware flow control, "-s 9600"
specifies the line speed of 9600 baud and finally the PTY
generated by Qemu is specified.
Now
the script checks if slattach is running in the background:
sudo ps
and if the network interface has
been generated:
ifconfig -a
You will see a new interface called
"sl0". The interface name is "sl" for serial
plus a zero.
Now
we have to assign an IP address to this serial interface.
ifconfig sl0 192.168.1.9 pointopoint 192.168.1.10 netmask 255.255.255.0 mtu 296
Here 192.168.1.9 is the address we
will assign to the serial interface, next we establish a
pointopoint connection, 192.168.1.10 is the ip address of the ELKS
system within Qemu and ELKS uses an mtu of 296 for slip.
Now
„ifconfig -a“ will tell us that the sl0 interface got
the ip address 192.168.1.9 and
it
has a point to point connection to the ip address 192.168.1.10,
which is ip address for ELKS that we configured.
Next
we have to tell the host that it can reach the address
192.168.1.10 via the address of the serial inferface. So we
configure a static route for this:
route add 192.168.1.10 sl0
„route
-n“ shows this routing table:
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eno1
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eno1
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 sl0
192.168.1.10 0.0.0.0 255.255.255.255 UH 0 0 0 sl0
Now you have to disable or
configure the firewall on your host system so that it will not
drop the packets from ELKS for security reasons. Usually you will
have a firewall running and that will not accept data from ELKS.
If
you then enter "ping 192.168.1.10" now, it will report a
response from the ELKS system.
In
case you have to restart ELKS you can remove the slattach process
on the host with „sudo pkill -f slattach“. This
releases the PTY generated by Qemu.
However,
in case ELKS does not respond to the ping request, this is what
you can do to debug the slip connection.
First
check if you have a working serial connection to the host. For
that stop ktcp to have that release the serial port on ELKS.
Determine with the „ps“ command the process number
assigned to ktcp and enter e.g. „kill 5 &“ if the
PID is 5. Then enter „cat /dev/ttyS0“. If you then
start „ping 192.168.1.10“ on your host, you should see
the slip packets from the host on the screen.
Then
you can check if you can send slip packets from ELKS to the host.
I use cutecom on the host and open the device „/dev/pts/2“
provided Qemu generated the PTY 2. If you then enter on ELKS
„urlget http://192.168.1.7“, provided the host has the
ip address 192.168.1.7, the slip packets from ELKS can be seen
with cutecom.
If
this works, you can use „tcpdump“ on the host to
monitor the tcp/ip traffic between the host and ELKS. Enter
„tcpdump -n -i sl0“ to monitor the traffic via the
slip interface „sl0“.
You
will see that the host sends icmp requests to ELKS and receives
them from there.
4th
of March 2017 Georg Potthast
|