aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-11-29 11:17:50 +0000
committerRoy Marples <roy@marples.name>2007-11-29 11:17:50 +0000
commit50161bef0e27ca235d876b888ae5abcafbec2ac7 (patch)
treea765b218d2e7ec7f9435411dbf0ec0fbe582ecda
parentf0aa06b58626626729f8d7af6f6a9edf08c807f4 (diff)
Allow space separated configs to work for CIDR address styles
-rw-r--r--conf.d.BSD/net.example20
-rw-r--r--conf.d.Linux/net.example42
-rwxr-xr-xsh/net.sh20
3 files changed, 29 insertions, 53 deletions
diff --git a/conf.d.BSD/net.example b/conf.d.BSD/net.example
index 9dae1035..1cd31e61 100644
--- a/conf.d.BSD/net.example
+++ b/conf.d.BSD/net.example
@@ -40,21 +40,13 @@
# INTERFACE HANDLERS
# For a static configuration, use something like this
-# (They all do exactly the same thing btw)
#config_eth0="192.168.0.2/24"
-#config_eth0="192.168.0.2 netmask 255.255.255.0"
-
-# We can also specify a broadcast
-#config_eth0="192.168.0.2/24 brd 192.168.0.255"
-#config_eth0="192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255"
# If you need more than one address, you can use something like this
# NOTE: ifconfig creates an aliased device for each extra IPv4 address
# (eth0:1, eth0:2, etc)
# iproute2 does not do this as there is no need to
-#config_eth0="192.168.0.2/24
-#192.168.0.3/24
-#192.168.0.4/24'"
+#config_eth0="192.168.0.2/24 192.168.0.3/24 192.168.0.4/24"
# Or you can use sequence expressions
#config_eth0="192.168.0.{2..4}/24" FIXME - may not work with baselayout2
# which does the same as above. Be careful though as if you use this and
@@ -63,17 +55,14 @@
# You can also use IPv6 addresses
# (you should always specify a prefix length with IPv6 here)
-#config_eth0="192.168.0.2/24
-#4321:0:1:2:3:4:567:89ab/64
-#4321:0:1:2:3:4:567:89ac/64"
+#config_eth0="192.168.0.2/24 4321:0:1:2:3:4:567:89ab/64 4321:0:1:2:3:4:567:89ac/64"
# If you wish to keep existing addresses + routing and the interface is up,
# you can specify a noop (no operation). If the interface is down or there
# are no addresses assigned, then we move onto the next step (default dhcp)
# This is useful when configuring your interface with a kernel command line
# or similar
-#config_eth0="noop
-#192.168.0.2/24"
+#config_eth0="noop 192.168.0.2/24"
# If you don't want ANY address (only useful when calling for advanced stuff)
#config_eth0="null"
@@ -120,8 +109,7 @@
# Most users will just need to set the following options
# key_SSID1="s:yourkeyhere enc open" # s: means a text key
# key_SSID2="aaaa-bbbb-cccc-dd" # no s: means a hex key
-# preferred_aps="SSID 1
-#SSID 2"
+# preferred_aps="SSID1 SSID2"
#
# Clear? Good. Now configure your wireless network below
diff --git a/conf.d.Linux/net.example b/conf.d.Linux/net.example
index 74bdbfdc..53e71679 100644
--- a/conf.d.Linux/net.example
+++ b/conf.d.Linux/net.example
@@ -19,25 +19,6 @@
##############################################################################
-# VARIABLES
-#
-# We've changed from using arrays to evaluated strings.
-# This has the benefit of being slightly more readable but more importantly it
-# works across all shells.
-# OLD
-# config_eth0=( "192.168.0.24 netmask 255.255.255.0" "192.168.0.25/24" )
-# NEW
-# config_eth0="192.168.0.24 netmask 255.255.255.0
-# 192.168.0.25/24"
-# INVALID
-# config_eth0="192.168.0.24 netmask 255.255.255.0 192.168.0.25/24"
-# INVALID
-# config_eth0="192.168.0.24 netmask 255.255.255.0 \n 192.168.0.25/24"
-#
-# Basically if array elements may need spaces in their values then we separate
-# on a hard coded new line.
-
-##############################################################################
# MODULES
#
# We now support modular networking scripts which means we can easily
@@ -83,17 +64,12 @@
#config_eth0="192.168.0.2/24"
#config_eth0="192.168.0.2 netmask 255.255.255.0"
-# We can also specify a broadcast
-#config_eth0="192.168.0.2/24 brd 192.168.0.255"
-#config_eth0="192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255"
-
# If you need more than one address, you can use something like this
# NOTE: ifconfig creates an aliased device for each extra IPv4 address
# (eth0:1, eth0:2, etc)
# iproute2 does not do this as there is no need to
-#config_eth0="192.168.0.2/24
-#192.168.0.3/24
-#192.168.0.4/24"
+#config_eth0="192.168.0.2/24 192.168.0.3/24 192.168.0.4/24"
+# However, that only works with CIDR addresses, so you can't use netmask.
# Or you can use sequence expressions
#config_eth0="192.168.0.{2..4}/24"
# which does the same as above. Be careful though as if you use this and
@@ -102,18 +78,14 @@
# You can also use IPv6 addresses
# (you should always specify a prefix length with IPv6 here)
-#config_eth0="192.168.0.2/24
-#4321:0:1:2:3:4:567:89ab/64
-#4321:0:1:2:3:4:567:89ac/64"
-#)
+#config_eth0="192.168.0.2/24 4321:0:1:2:3:4:567:89ab/64 4321:0:1:2:3:4:567:89ac/64"
# If you wish to keep existing addresses + routing and the interface is up,
# you can specify a noop (no operation). If the interface is down or there
# are no addresses assigned, then we move onto the next step (default dhcp)
# This is useful when configuring your interface with a kernel command line
# or similar
-#config_eth0="noop
-#192.168.0.2/24"
+#config_eth0="noop 192.168.0.2/24"
# If you don't want ANY address (only useful when calling for advanced stuff)
#config_eth0="null"
@@ -126,7 +98,7 @@
# If a specified module fails (like dhcp - see below), you can specify a
# fallback like so
-#fallback_eth0="192.168.0.2 netmask 255.255.255.0"
+#fallback_eth0="192.168.0.2/24"
#fallback_route_eth0="default via 192.168.0.1"
# NOTE: fallback entry must match the entry location in config_eth0
@@ -570,8 +542,8 @@
#vconfig_eth0="set_name_type VLAN_PLUS_VID_NO_PAD"
#vconfig_vlan1="set_flag 1
#set_egress_map 2 6"
-#config_vlan1="172.16.3.1 netmask 255.255.254.0"
-#config_vlan2="172.16.2.1 netmask 255.255.254.0"
+#config_vlan1="172.16.3.1/23"
+#config_vlan2="172.16.2.1/23"
# NOTE: Vlans can be configured with a . in their interface names
# When configuring vlans with this name type, you need to replace . with a _
diff --git a/sh/net.sh b/sh/net.sh
index f5535b8f..992eacf9 100755
--- a/sh/net.sh
+++ b/sh/net.sh
@@ -410,11 +410,27 @@ ${config}"
fi
fi
+ config_index=0
+ local IFS="$__IFS"
+ set -- ${config}
+
+ # We should support a space separated array for cidr configs
+ if [ $# = 1 ]; then
+ unset IFS
+ set -- ${config}
+ # Of course, we may have a single address added old style.
+ case "$2" in
+ netmask|broadcast|brd|brd+)
+ local IFS="$__IFS"
+ set -- ${config}
+ ;;
+ esac
+ fi
+
# We store our config in an array like vars
# so modules can influence it
config_index=0
- local IFS="$__IFS"
- for cmd in ${config}; do
+ for cmd; do
eval config_${config_index}="'${cmd}'"
config_index=$((${config_index} + 1))
done