summaryrefslogtreecommitdiff
path: root/network
diff options
context:
space:
mode:
Diffstat (limited to 'network')
-rwxr-xr-xnetwork34
1 files changed, 22 insertions, 12 deletions
diff --git a/network b/network
index c2ad9ba..b94d170 100755
--- a/network
+++ b/network
@@ -9,7 +9,8 @@ done
# helper function to determine if legacy network support is needed
need_legacy() {
- if [[ -z $interface ]]; then
+ # complain when `interface' is unset and `INTERFACES' has profiles enabled
+ if [[ -z $interface && ${INTERFACES[@]##!*} ]]; then
return 0 # need legacy
fi
@@ -17,33 +18,42 @@ need_legacy() {
}
deprecated() {
- printf "${C_FAIL}Warning:${C_CLEAR} This functionality is deprecated.\n"
+ printf "${C_FAIL}Warning:${C_CLEAR} Your network settings are deprecated.\n"
printf " Please refer to /etc/rc.conf on how to define a single wired\n"
printf " connection, or use a utility such as netcfg.\n"
}
+have_interface() {
+ if [[ -z $1 ]]; then
+ printf "\n${C_FAIL}Error:${C_CLEAR} \`interface' is undefined in /etc/rc.conf\n"
+ return 1
+ fi
+
+ if [[ ! -d /sys/class/net/$1 ]]; then
+ printf "\n${C_FAIL}Error:${C_CLEAR} unknown interface in /etc/rc.conf: \`%s'\n" "$1"
+ return 1
+ fi
+}
+
network_up() {
+ have_interface "$interface" || return 1
+
ip link set dev $interface up || return 1
if [[ $address ]]; then
- for var in netmask gateway; do
- if [[ -z ${!var} ]]; then
- printf "${C_FAIL}Error: static address defined without $var!\n"
- return 1
- fi
- done
- ip addr add $address/$netmask broadcast ${broadcast:-+} dev $interface || return 1
- ip route add default via $gateway || return 1
+ ip addr add $address/${netmask:-24} broadcast ${broadcast:-+} dev $interface || return 1
+ [[ $gateway ]] && { ip route add default via $gateway || return 1; }
else
dhcpcd $DHCPCD_ARGS $interface || return 1
fi
}
network_down() {
+ have_interface "$interface" || return 1
+
if [[ -f /var/run/dhcpcd-$interface.pid ]]; then
dhcpcd -k $interface || return 1
else
- ip route del default || return 1
ip addr flush dev $interface || return 1
fi
@@ -299,7 +309,7 @@ case "$1" in
;;
ifup|ifdown|iflist|rtup|rtdown|rtlist)
# deprecation check
- need_legacy && deprecated
+ deprecated
$1 $2
;;
*)