Move network config blocks out of ifconfig
authorXiao Jia <stfairy@gmail.com>
Tue, 29 Sep 2015 19:48:48 +0000 (12:48 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 8 Oct 2015 14:35:55 +0000 (10:35 -0400)
Existing "known good" sections and qemu default are moved to
/etc/network/default.  Users can write their own config blocks in
/etc/network/local which is not under version control.  Users can
also put individual custom stuff under /etc/network/local.d/ which
will be picked up by the ifconfig script.

Signed-off-by: Xiao Jia <stfairy@gmail.com>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/kfs/etc/network/default [new file with mode: 0755]
kern/kfs/etc/network/local.d/README [new file with mode: 0644]
kern/kfs/ifconfig

diff --git a/kern/kfs/etc/network/default b/kern/kfs/etc/network/default
new file mode 100755 (executable)
index 0000000..568208d
--- /dev/null
@@ -0,0 +1,94 @@
+#!/bin/ash
+
+# known good.
+hossinMAC=00241d1054e1
+c89MAC=001e67652333
+c99MAC=001e67c2f479
+altdraMAC=525400b0c2ec
+qemuMAC=525400123456
+tower1MAC=00032d196d88
+tower2MAC=00032d196ddd
+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!"
+fi
+
+# the tower of ... tower
+# all defaults are fine.
+if [ "$MAC" = "$tower1MAC" ]
+then
+    me=10.0.2.15
+fi
+if [ "$MAC" = "$tower2MAC" ]
+then
+    me=10.0.2.16
+fi
+if [ "$MAC" = "$tower3MAC" ]
+then
+    me=10.0.2.17
+fi
+if [ "$MAC" = "$tower4MAC" ]
+then
+    me=10.0.2.18
+fi
+if [ "$MAC" = "$tower5MAC" ]
+then
+    me=10.0.2.19
+fi
+
+if [ "$MAC" = "$c89MAC" ]
+then
+       # c89's config.  use c96 for eth0 (.196).
+       # $ cat /9/net/ipifc/clone (get e.g. 2)
+       # $ echo "add 169.229.49.196 255.255.255.0" > /9/net/ipifc/2/ctl
+       me=169.229.49.196
+       mask=255.255.255.0
+       remote=169.229.49.0
+       route=169.229.49.1
+       # the i350 NIC that is plugged in is the first NIC
+       NIC="0"
+fi
+
+if [ "$MAC" = "$c99MAC" ]
+then
+       # c99's config.  use c95 for eth0 (.195).
+       # $ cat /9/net/ipifc/clone (get e.g. 2)
+       # $ echo "add 169.229.49.195 255.255.255.0" > /9/net/ipifc/2/ctl
+       me=169.229.49.195
+       mask=255.255.255.0
+       remote=169.229.49.0
+       route=169.229.49.1
+       # the i350 NIC that is plugged in is the first NIC
+       NIC="0"
+fi
+
+if [ "$MAC" = "$altdraMAC" ]
+then
+       # yuzhu's soda hall bridged vm
+       me=128.32.37.37
+       mask=255.255.255.0
+       remote=128.32.37.0
+       route=128.32.37.1
+fi
+
+if [ "$MAC" = "$hossinMAC" ]
+then
+       # brho's soda hall desktop
+       me=128.32.37.46
+       mask=255.255.255.0
+       remote=128.32.37.0
+       route=128.32.37.1
+fi
diff --git a/kern/kfs/etc/network/local.d/README b/kern/kfs/etc/network/local.d/README
new file mode 100644 (file)
index 0000000..7859173
--- /dev/null
@@ -0,0 +1,2 @@
+# Put your own custom suff in this directory.
+# They will be picked up by the ifconfig script.
index 1a3f574..b1ac698 100755 (executable)
@@ -1,17 +1,5 @@
 #!/bin/ash
 
-# known good.
-hossinMAC=00241d1054e1
-c89MAC=001e67652333
-c99MAC=001e67c2f479
-altdraMAC=525400b0c2ec
-qemuMAC=525400123456
-tower1MAC=00032d196d88
-tower2MAC=00032d196ddd
-tower3MAC=00032d196d46
-tower4MAC=00032d196db0
-tower5MAC=00032d196daa
-
 MAC=`cat '#ether/ether0/addr'`
 
 #bind -a '#ip' /net
@@ -38,86 +26,30 @@ NIC="0"
 # (me network server server-addr
 # wrong addresses.
 
-# 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!"
-fi
-
-# the tower of ... tower
-# all defaults are fine.
-if [ "$MAC" = "$tower1MAC" ]
-then
-    me=10.0.2.15
-fi
-if [ "$MAC" = "$tower2MAC" ]
-then
-    me=10.0.2.16
-fi
-if [ "$MAC" = "$tower3MAC" ]
-then
-    me=10.0.2.17
-fi
-if [ "$MAC" = "$tower4MAC" ]
-then
-    me=10.0.2.18
-fi
-if [ "$MAC" = "$tower5MAC" ]
-then
-    me=10.0.2.19
-fi
-
-if [ "$MAC" = "$c89MAC" ]
+if [ -f '/etc/network/default' ]
 then
-       # c89's config.  use c96 for eth0 (.196).
-       # $ cat /9/net/ipifc/clone (get e.g. 2)
-       # $ echo "add 169.229.49.196 255.255.255.0" > /9/net/ipifc/2/ctl
-       me=169.229.49.196
-       mask=255.255.255.0
-       remote=169.229.49.0
-       route=169.229.49.1
-       # the i350 NIC that is plugged in is the first NIC
-       NIC="0"
+       source /etc/network/default
+else
+       echo '/etc/network/default not found'
 fi
 
-if [ "$MAC" = "$c99MAC" ]
+if [ -f '/etc/network/local' ]
 then
-       # c99's config.  use c95 for eth0 (.195).
-       # $ cat /9/net/ipifc/clone (get e.g. 2)
-       # $ echo "add 169.229.49.195 255.255.255.0" > /9/net/ipifc/2/ctl
-       me=169.229.49.195
-       mask=255.255.255.0
-       remote=169.229.49.0
-       route=169.229.49.1
-       # the i350 NIC that is plugged in is the first NIC
-       NIC="0"
+       source /etc/network/local
+else
+       echo '/etc/network/local not found'
 fi
 
-if [ "$MAC" = "$altdraMAC" ]
+if [ -d '/etc/network/local.d' ]
 then
-       # yuzhu's soda hall bridged vm
-       me=128.32.37.37
-       mask=255.255.255.0
-       remote=128.32.37.0
-       route=128.32.37.1
+       for cfg in /etc/network/local.d/*
+       do
+               source $cfg
+       done
+else
+       echo '/etc/network/local.d not found'
 fi
 
-if [ "$MAC" = "$hossinMAC" ]
-then
-       # brho's soda hall desktop
-       me=128.32.37.46
-       mask=255.255.255.0
-       remote=128.32.37.0
-       route=128.32.37.1
-fi
 #
 # Post the read-only filesystem in #s/$beetroot
 # and mount it on /boot so the commands in /boot/$cputype/bin