summaryrefslogtreecommitdiffstats
path: root/release
diff options
context:
space:
mode:
authorluigi <luigi@FreeBSD.org>2001-10-04 00:46:44 +0000
committerluigi <luigi@FreeBSD.org>2001-10-04 00:46:44 +0000
commit0a6d2bba3acb2eb785d51046ff48c6dc45019374 (patch)
treecfbb1d123984eb23ac67ce98cf3713ea95388bed /release
parent800c8cb93d17ad949ee5e2198c803e702be8188d (diff)
downloadFreeBSD-src-0a6d2bba3acb2eb785d51046ff48c6dc45019374.zip
FreeBSD-src-0a6d2bba3acb2eb785d51046ff48c6dc45019374.tar.gz
Add functions to lookup in /etc/networks and set interface
addresses, invoke them from /etc/rc
Diffstat (limited to 'release')
-rw-r--r--release/picobsd/floppy.tree/etc/rc2
-rw-r--r--release/picobsd/floppy.tree/etc/rc.conf91
2 files changed, 77 insertions, 16 deletions
diff --git a/release/picobsd/floppy.tree/etc/rc b/release/picobsd/floppy.tree/etc/rc
index 84c0fb8..b461e6e 100644
--- a/release/picobsd/floppy.tree/etc/rc
+++ b/release/picobsd/floppy.tree/etc/rc
@@ -24,6 +24,8 @@ done
if [ -f /etc/rc.conf ]; then
. /etc/rc.conf
+ set_main_interface
+ set_all_interfaces
fi
rm -f /var/run/*
if [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then
diff --git a/release/picobsd/floppy.tree/etc/rc.conf b/release/picobsd/floppy.tree/etc/rc.conf
index 1e854f6..67477bd 100644
--- a/release/picobsd/floppy.tree/etc/rc.conf
+++ b/release/picobsd/floppy.tree/etc/rc.conf
@@ -26,7 +26,7 @@ defaultrouter="NO" # Set to default gateway (or NO).
static_routes="" # Set to static route list (or leave empty).
gateway_enable="NO" # Set to YES if this host will be a gateway.
arpproxy_all="" # replaces obsolete kernel option ARP_PROXYALL.
-mask="0xffffff00"
+default_mask="0xffffff00"
}
# the following lets the user specify a name and ip for his system
@@ -41,32 +41,91 @@ read_address() {
fi
}
-rc_conf_set_defaults
+# set "ether" using $1 (interface name) as search key
+get_ether() {
+ local key
+ key=$1
+ ether=""
+ set `ifconfig ${key}`
+ while [ "$1" != "" ] ; do
+ if [ "$1" = "ether" ] ; then
+ ether=$2
+ break
+ else
+ shift
+ fi
+ done
+}
-hostname=""
-while read a b c ; do
+# set "hostname" using $1 (ethernet address) as search key in /etc/hosts
+fetch_hostname() {
+ local a b c key
+ key=$1 # search key
+ hostname=""
+ while read a b c ; do
if [ "$a" = "#ethertable" ] ; then
- hostname="."
+ hostname="."
elif [ "X$hostname" = "X." -a "X$a" = "X#" ] ; then
- case X${main_ether} in
+ case X${key} in
X${b} ) # so we can use wildcards
hostname=$c
break
;;
esac
fi
-done < /etc/hosts
-if [ "X$hostname" = "X" -o "X$hostname" = "X." ] ; then
- if [ "X$main_ether" = "X" ] ; then
- echo "No ethernets found, using localhost"
- hostname=localhost
- else
- read_address
+ done < /etc/hosts
+}
+
+# sets "mask" using $1 (netmask name) as the search key in /etc/networks
+fetch_mask() {
+ local a b c key
+ key=$1 # search key, typically hostname-netmask
+ mask=""
+ while read a b c; do # key mask otherstuff
+ case X${key} in
+ X${a} ) # we can use wildcards
+ mask=$b
+ break
+ ;;
+ esac
+ done < /etc/networks
+}
+
+
+set_main_interface() {
+ fetch_hostname ${main_ether}
+
+ if [ "X$hostname" = "X" -o "X$hostname" = "X." ] ; then
+ if [ "X$main_ether" = "X" ] ; then
+ echo "No ethernets found, using localhost"
+ hostname=localhost
+ else
+ read_address
+ fi
+ fi
+ fetch_mask ${hostname}-netmask
+ if [ "${mask}" = "" ] ; then
+ mask=${default_mask}
fi
-fi
-eval ifconfig_${main_if}=\" \$hostname netmask \$mask\"
-network_interfaces=`ifconfig -l`
+ eval ifconfig_${main_if}=\" \${hostname} netmask \${mask}\"
+ network_interfaces=`ifconfig -l`
+}
+
+set_all_interfaces() {
+ local i ether hostname mask
+
+ for i in `ifconfig -l` ; do
+ get_ether $i
+ fetch_hostname ${ether}
+ fetch_mask ${hostname}-netmask
+ if [ "${ether}" != "" -a "${hostname}" != "" ] ; then
+ eval ifconfig_${i}=\" \${hostname} netmask \${mask}\"
+ fi
+ done
+}
+
+rc_conf_set_defaults
### Allow local configuration override at the very end here ##
### can make use of a case statement to set per-host things.
OpenPOWER on IntegriCloud