Change /ifconfig so that it uses the ipconfig binary. If /bin/ipconfig exists and the IP address of the machine is known, use ipconfig to configure the interface with the given IP address, gateway and netmask.
If /bin/ipconfig exists and the IP address of the machine is NOT known, then run ipconfig and try to get a DHCP lease. If /bin/ipconfig does NOT exist and the IP address is known, then configure the interface manually. If /bin/ipconfig does not exist and the IP address, don't configure networking except for the loopback interface. Use ipconfig for the loopback interface if it exists. Also clean up the script in several ways: 1. Be consisent with quotes: use single quotes pretty uniformly throughout as opposed to a mixture of quotes and \-escaping #'s. Use double quotes when interpolating a variable into a string, of course. 2. Remove some old cruft and outdated comments. It appeared that some of the comments dated from e.g. inferno or an earlier version of the system. 3. Move the 'default' configuration for network directly into /ifconfig. Tested: Booting in various configurations. Change-Id: I11aadb6f571c04c692d46a4794957245feb23d20 Signed-off-by: Dan Cross <[email protected]> --- kern/kfs/etc/network/default | 9 ---- kern/kfs/ifconfig | 108 +++++++++++++++++++++---------------------- 2 files changed, 52 insertions(+), 65 deletions(-) diff --git a/kern/kfs/etc/network/default b/kern/kfs/etc/network/default index 568208d..44d9c76 100755 --- a/kern/kfs/etc/network/default +++ b/kern/kfs/etc/network/default @@ -12,15 +12,6 @@ tower3MAC=00032d196d46 tower4MAC=00032d196db0 tower5MAC=00032d196daa -# qemu is the default -me=10.0.2.15 -mask=255.255.255.0 -# brho: i don't know what exactly 'remote' is supposed to be, but that is -# the third argument processed by adding to an ipifc. if we pass nothing, -# it'll build 'remote' by masking me & mask. -remote=10.0.2.0 -route=10.0.2.2 - if [ "$MAC" = "$qemuMAC" ] then echo "Welcome to QEMU!" diff --git a/kern/kfs/ifconfig b/kern/kfs/ifconfig index ff964d7..1fa971e 100755 --- a/kern/kfs/ifconfig +++ b/kern/kfs/ifconfig @@ -1,15 +1,7 @@ #!/bin/ash -MAC=`cat '#ether/ether0/addr'` - -#bind -a '#ip' /net -#bind -a '#ether.0' /net -#cat /net/ipifc/clone -## bind the ether0 to it -#echo 'bind ether /net/ether0' > /net/ipifc/0/ctl -#exit - -# ifconfig it +NIC='0' +MAC=`cat "#ether/ether$NIC/addr"` export cputype=amd64 export objtype=$cputype @@ -19,28 +11,21 @@ export rootdir=/root export rootspec='' export rootsrv=boot -NIC="0" -#authentication='nvram=/boot/adm/nvram auth/factotum -sfactotum -S' # -a ... -# test xyzip=(0 0 0 104.9.33) -# test fsaddr='tcp!135.$xyzip(4)^!564' -# (me network server server-addr -# wrong addresses. - -if [ -f '/etc/network/default' ] +if [ -f /etc/network/default ] then source /etc/network/default else echo '/etc/network/default not found' fi -if [ -f '/etc/network/local' ] +if [ -f /etc/network/local ] then source /etc/network/local else echo '/etc/network/local not found' fi -if [ -d '/etc/network/local.d' ] +if [ -d /etc/network/local.d ] then for cfg in /etc/network/local.d/* do @@ -51,62 +36,73 @@ else fi # -# Post the read-only filesystem in #s/$beetroot -# and mount it on /boot so the commands in /boot/$cputype/bin -# are available to create the namespace (namespaces like to -# mount #s/boot on / and that should not be the read-only -# filesystem). -# Must set hostowner to be that of the owner of the nvram file -# before paqfs starts otherwise factotum will not be able to -# open it. +# Set up the initial namespace for starting networking. # -#/boot/echo -n sys > '#c/hostowner' -#/boot/paqfs -p -S $beetroot -m /boot -q /boot/$beetroot -#cd /boot/$cputype/bin bind -b '#cons' /dev bind -b '#random' /dev #bind '#d' /fd #bind -c '#e' /env bind -b '#proc' /proc -#bind -b -c '#srv' /srv bind -b '#srv' /srv # # Configure the networks. # bind -a '#ip' /net -bind -a \#ether.$NIC /net - -# note: dhcp is possible, just not done yet. -#get an instance of a network stack -i=`cat /net/ipifc/clone` -# bind the ether0 to it -# the kernel sets errno, though it doesn't return -1 or anything. but our bb -# hacks doesn't know any better, and echo will think it was an error -echo "bind ether /net/ether$NIC " > /net/ipifc/$i/ctl 2> /dev/null -# ifconfig it -echo "add $me $mask $remote" > /net/ipifc/$i/ctl -echo "add 0 0 $route" > /net/iproute -echo I am $me, default route $route +bind -a '#ether'.$NIC /net -i=`cat /net/ipifc/clone` -echo "bind loopback /dev/null " > /net/ipifc/$i/ctl -echo "add 127.0.0.1 255.0.0.0 127.0.0.0 " > /net/ipifc/$i/ctl +if [ -x /bin/ipconfig ] +then + if [ ! -z "$me" ] + then + ipconfig -g $route ether /net/ether$NIC $me $mask + else + # No explicit configuration; use DHCP. + ipconfig ether /net/ether$NIC + fi + ipconfig loopback /dev/null 127.0.0.1 +else + i=`cat /net/ipifc/clone` + if [ -z "$me" ] + then + # Default to qemu. + me="10.0.2.15" + mask="255.255.255.0" + remote="10.0.2.0" + route="10.0.2.2" + fi + # get an instance of a network stack + # bind ether$NIC to it + # The kernel sets errno, though it doesn't return -1 or + # anything. our bb hacks doesn't know any better, and + # echo will think it was an error. + echo "bind ether /net/ether$NIC" >/net/ipifc/$i/ctl 2>/dev/null + # ifconfig it + echo "add $me $mask $remote" > /net/ipifc/$i/ctl + echo "add 0 0 $route" > /net/iproute + echo "I am $me, default route $route" + # + # Configure the loopback interface. + # + i=`cat /net/ipifc/clone` + echo 'bind loopback /dev/null' > /net/ipifc/$i/ctl + echo 'add 127.0.0.1 255.0.0.0 127.0.0.0' > /net/ipifc/$i/ctl +fi -cs& -if [ ! -e "#srv/cs" ] +cs & +if [ ! -e '#srv/cs' ] then - echo "cs hasn't created #srv/cs yet, sleeping until it does..." - until [ -e "#srv/cs" ] + echo 'cs has not created #srv/cs yet, spinning until it does....' + until [ -e '#srv/cs' ] do usleep 1000 done fi -mount -a \#srv/cs /net +mount -a '#srv/cs' /net -# this is noisy, so it is off by default. +# This is noisy, so it is off by default. #echo debug > /net/cs -bind -a \#kprof /prof/ +bind -a '#kprof' /prof -echo "ifconfig complete" +echo 'ifconfig complete' -- 2.8.0.rc3.226.g39d4020 -- You received this message because you are subscribed to the Google Groups "Akaros" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/d/optout.
