Basic ethernet setup with minibase
I posted a couple of days ago about minibase, created by Alex Suykov:
http://bkhome.org/news/201902/minibase-super-tiny-static-system.html
Since then, I have been learning how it works, and posting questions:
https://github.com/arsv/minibase/issues
...to which he has patiently and helpfully replied.
Initially, I have explored ethernet network connection, as this is
one of the areas in EasyOS (and Quirky and Puppy) that has issues. When I
introduced NetworkManager to EasyOS, the ethernet connection problems
went away. Basically, NetworkManager automatically detects which
ethernet interface is "alive" and connected to a router/modem, and you
can turn off the router, turn it back on, change cable to a different
ethernet socket on the PC, and NetworkManager automatically adjusts.
I think that Puppy Forum member Jemimah originally created Frisbee
network manager with this kind of flexibility in mind (project now
maintained by rerwin), but I don't know to what extent that flexibility
was achieved.
Anyway, fast-forward to now, testing minibase, and yippee, it has the
same automatic flexibility as NetworkManager. Note, NetworkManager is
no longer in Easy, as posted yesterday, I removed it:
http://bkhome.org/news/201902/networkmanager-removed-from-easyos.html
The rest of this post will be a mini-tutorial, explaining how I have
setup minibase, or rather, just the utilities concerned with ethernet
networking. There are these networking utilites, in /sbin:
dhcp ifctl ifmon ip4addr ip4info wifi wsupp
Actually, Alex places 'ifmon' and 'wsupp' in /sbin/service. 'wifi' and 'wsupp' are for wifi, so will leave those out of the discussion for now. Note, the total size of these utilities is 100KB and they are statically-linked.
'ifmon' is a daemon, that is intended to be started at bootup. To easily show output, I have started it in a terminal. I deliberately left the network cable unplugged:
# mkdir /run/ctrl
# ifmon
+++ identify eth0
+++ identify eth1
+++ identify wlan0
+++ mode-lan0 eth0
+++ mode-lan1 eth1
I then plugged in the network cable (between PC and router):
+++ conf-request eth0
+++ dhcp-gw 192.168.1.1
+++ dhcp-dns 192.168.43.1 168.126.63.2
Unplugged the cable:
+++ conf-cancel eth0
Plugged it in again:
+++ conf-request eth0
+++ dhcp-gw 192.168.1.1
+++ dhcp-dns 192.168.43.1 168.126.63.2
The network connection went up when I plugged in the cable, down,
then back up when I replugged the cable. The network_tray icon
faithfully showed the status.
Technical note:
"aliveness" detection is not done by a polling loop. It is done efficiently by a netlink socket, waiting on notifications from the kernel.
This is great, exactly what I want. Now, some explanation about the messages that 'ifmon' puts out. 'ifmon' relies upon scripts to do any real action. Those scripts are in /etc/net:
conf-cancel conf-request dhcp-gw identify mode-wifi
conf-renew dhcp-dns dhcp-ntp mode-lan wifi-wpa
At startup, 'ifmon' calls /etc/net/identify, for each interface that
it discovers, passing the interface name, as you can see above. This is
what I put into 'identify':
#!/bin/sh
echo "+++ identify $1"
IF="$1"
IDflg=""; NET='lan'
[ -d /sys/class/net/${IF}/wireless ] && NET='wifi'
#test if id already assigned...
[ -s /var/local/interfaces ] && IDflg="$(ifctl | grep "${IF}: ${NET}")"
#if not, assign it...
if [ ! "$IDflg" ];then
NUM="${IF/*[a-z]/}"
if [ ! -f /etc/net/mode-${NET}${NUM} ];then
cp -a /etc/net/mode-${NET} /etc/net/mode-${NET}${NUM}
sed -i -e "s%\+\+\+ mode-${NET} %+++ mode-${NET}${NUM} %" /etc/net/mode-${NET}${NUM}
fi
ifctl ${IF} mode ${NET}${NUM}
fi
ifctl $IF identify
I won't spend much time explaining this. Minibase determines a
persistent name for the interface, independent whether the actual
interface name "eth0", "eth1" or whatever, changes. This persistent name
is assigned to a script. What I have done in the above script is assign
eth0 to script /etc/net/mode-lan0 --which will get called even if the
name assigned to that interface changes. In other words, script
'mode-lan0' is locked to that physical interface.
Technical note:
"eth0", "eth1" etc., are the names assigned by the linux kernel. Most linux distributions rename these, or rather, udev does, to a name unique to each physical interface. I do not like this, and EasyOS does not have this renaming (it is simply a matter of removing a certain rules file from the udev (or systemd) package). The method employed by Alex, is, I think, much more intelligent, and we get to keep the kernel-assigned names.
If you look above, you will see that next, /etc/net/mode-lan0 got
called, with the kernel-assigned name (in this case "eth0") passed in.
This is the content of 'mode-lan0':
#!/bin/sh
echo "+++ mode-lan0 $1"
ifconfig $1 up
ifctl $1 auto-dhcp
Then, after plugging in the ethernet cable, /etc/net/conf-request got called:
#!/bin/sh
echo "+++ conf-request $1"
dhcp $1 request
The 'dhcp' utility responds by obtaining a lease from the DHCP server
on the router. Note, 'dhcp' is just a client. It is
tightly integrated with the other utilities.
When the lease is obtained, 'ifmon' calls /etc/net/dhcp-dns, passing
in the nameserver IP addresses, as you can see above. This is the
content of 'dhcp-dns':
#!/bin/sh
echo "+++ dhcp-dns $@"
[ "$1" == "" ] && exit
echo "#written by /etc/net/dhcp-dns" > /etc/resolv.conf
for aIF in $@
do
echo "nameserver ${aIF}" >> /etc/resolv.conf
done
...I had to do that, as apps such as the browser need that info in /etc/resolv.conf for Internet access.
When I unplugged the cable, 'conf-cancel' got called:
#!/bin/shSo, the only thing that we need to do is run 'ifmon' at bootup. Which I will be integrating into EasyOS.
echo "+++ conf-cancel $1"
dhcp $1 cancel
EDIT: Alex has read this blog post, and responded here:
https://github.com/arsv/minibase/issues/5#issuecomment-461873169
I have not got onto wifi yet, and that is most exciting, as Alex has written the utilities from scratch. There is 'wsupp' which replaces 'wpa_supplicant'. The latter has been troublesome, and I am eagerly anticipating what is coming...
Tags: easy