|  | #!/bin/ash | 
|  |  | 
|  | /bin/bind -b '#cons' /dev | 
|  |  | 
|  | NIC=0 | 
|  | while true; do | 
|  | cat "#ether.$NIC" 2>&1 > /dev/null | 
|  |  | 
|  | # cat will fail if there is no device.  We can only tell by trying | 
|  | if [ $? -ne 0 ]; then | 
|  | break | 
|  | fi | 
|  |  | 
|  | # the cfg files ID machines by the MAC of their preferred NIC | 
|  | MAC=`cat "#ether.$NIC/ether$NIC/addr"` | 
|  | if [ -d /etc/network/local.d ] | 
|  | then | 
|  | for cfg in /etc/network/local.d/* | 
|  | do | 
|  | source $cfg | 
|  | done | 
|  | fi | 
|  |  | 
|  | # cfg files set $me when they have a match | 
|  | if [ "x$me" != "x" ]; then | 
|  | break; | 
|  | fi | 
|  |  | 
|  | let NIC=$NIC+1 | 
|  | done | 
|  |  | 
|  | # Default back to ether.0 when we didn't find anything | 
|  | if [ "x$me" == "x" ]; then | 
|  | NIC=0 | 
|  | fi | 
|  |  | 
|  | MAC=`cat "#ether.$NIC/ether$NIC/addr"` | 
|  |  | 
|  | export cputype=amd64 | 
|  | export objtype=$cputype | 
|  | export service=cpu | 
|  | export authid=bootes | 
|  | export rootdir=/root | 
|  | export rootspec='' | 
|  | export rootsrv=boot | 
|  |  | 
|  | if [ -d /etc/network/local.d ] | 
|  | then | 
|  | for cfg in /etc/network/local.d/* | 
|  | do | 
|  | source $cfg | 
|  | done | 
|  | fi | 
|  |  | 
|  | # | 
|  | # Set up the initial namespace for starting networking. | 
|  | # | 
|  | /bin/bind -b '#random' /dev | 
|  | /bin/bind -a '#capability' /dev | 
|  | /bin/bind -a '#sd' /dev | 
|  | #/bin/bind '#d' /fd | 
|  | #/bin/bind -c '#e' /env | 
|  | /bin/bind -b '#proc' /proc | 
|  | /bin/bind -b '#srv' /srv | 
|  |  | 
|  | # | 
|  | # Configure the network mount point. | 
|  | # | 
|  | /bin/bind -a '#ip' /net | 
|  | /bin/bind -a '#ether'.$NIC /net | 
|  |  | 
|  | # Need to set /dev/sysname before ipconfig.  ipconfig will grab this and put it | 
|  | # in ndb. | 
|  | if [ "x$HOST" != "x" ] | 
|  | then | 
|  | echo "$HOST" > /dev/sysname | 
|  | fi | 
|  |  | 
|  | if [ -x /bin/ipconfig ] | 
|  | then | 
|  | if [ -n "$me" ] | 
|  | then | 
|  | ipconfig -g $route ether /net/ether$NIC $me $mask | 
|  | else | 
|  | # No explicit configuration; use DHCP. | 
|  | daemonize /bin/ipconfig -S ether /net/ether$NIC | 
|  | fi | 
|  | ipconfig -P loopback /dev/null 127.0.0.1 | 
|  | else | 
|  | if [ ! -n "$me" ] | 
|  | then | 
|  | # By default, configure for QEMU. | 
|  | # We only use qemu's setting when we don't have ipconfig so that we can | 
|  | # test ipconfig + DHCP with qemu. | 
|  | me='10.0.2.15' | 
|  | mask='255.255.255.0' | 
|  | remote='10.0.2.0' | 
|  | route='10.0.2.2' | 
|  | dns='10.0.2.3' | 
|  | fi | 
|  | # | 
|  | # Get an instance of an IP stack and bind ether$NIC to it. | 
|  | # The kernel sets errno but 'echo' doesn't return any sort of | 
|  | # error indicator.  Our busybox hacks doesn't know any better | 
|  | # and will think it was an error so direct stderr to /dev/null. | 
|  | # | 
|  | i=`cat /net/ipifc/clone` | 
|  | echo "bind ether /net/ether$NIC" >/net/ipifc/$i/ctl 2>/dev/null | 
|  | # | 
|  | # Configure the stack. | 
|  | # | 
|  | 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 | 
|  |  | 
|  | ######### DNS Config ############# | 
|  |  | 
|  | # If we used some form of static configuration, /net/ndb doesn't know about our | 
|  | # DNS server.  This assumes the last contents of ndb is the IP block | 
|  | if [ -n "$me" ] | 
|  | then | 
|  | echo -e "\tdns=$dns" >> /net/ndb | 
|  | fi | 
|  | # Either way, we have DNS in ndb now, but some apps want it in resolv.conf | 
|  | DNS=`grep "dns=" /net/ndb | cut -f 2 -d'='` | 
|  | echo "nameserver $DNS" >> /etc/resolv.conf | 
|  | # And we may have some additional search paths for resolv.conf | 
|  | if [ -n "$me" ] | 
|  | then | 
|  | echo "search $search" >> /etc/resolv.conf | 
|  | fi | 
|  | # We also can provide an etc hosts file for loopback | 
|  | echo "127.0.0.1 localhost" >> /etc/hosts | 
|  | # You can set HOST and then you may set FQDN, and we'll add it to etc hosts | 
|  | if [ "x$HOST" != "x" ] | 
|  | then | 
|  | IP=`cat /net/ipifc/0/local | cut -f 1 -d ' '` | 
|  | echo "$IP $FQDN $HOST" >> /etc/hosts | 
|  | fi | 
|  |  | 
|  | daemonize /bin/cs -S | 
|  | mount -a '#srv/cs' /net | 
|  |  | 
|  | # This is noisy, so it is off by default. | 
|  | #echo debug > /net/cs | 
|  |  | 
|  | /bin/bind -a '#kprof' /prof | 
|  |  | 
|  | echo 'ifconfig complete' |