summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouke Witteveen <j.witteveen@gmail.com>2013-06-16 12:15:15 +0200
committerJouke Witteveen <j.witteveen@gmail.com>2013-06-16 12:15:15 +0200
commit4d8cb707b1fc1947030e312c66c73fd012038c20 (patch)
treec5844e77a1c456b5539d54a2dd60587becb72026
parent277b1cf277e0d6c6cc439d0684954503f6b2ed14 (diff)
downloadnetctl-4d8cb707b1fc1947030e312c66c73fd012038c20.tar.gz
netctl-4d8cb707b1fc1947030e312c66c73fd012038c20.tar.xz
Ordering improvements in IP configuration
- Add static routes prior to setting the default IP4 gateway (github/pull/43) - Set sysctl property net.ipv6.conf.<interface>.accept_ra earlier (FS#35788)
-rw-r--r--src/lib/ip63
1 files changed, 30 insertions, 33 deletions
diff --git a/src/lib/ip b/src/lib/ip
index 8dd2d63..e0629ec 100644
--- a/src/lib/ip
+++ b/src/lib/ip
@@ -23,6 +23,24 @@ ip_set() {
return 1
fi
+ # Load ipv6 module if necessary
+ case "$IP6" in
+ dhcp*|stateless|static)
+ [[ -d "/proc/sys/net/ipv6" ]] || modprobe ipv6
+ [[ $IP6 == "static" ]]
+ sysctl -q -w "net.ipv6.conf.$interface_sysctl.accept_ra=$?"
+ ;;
+ no)
+ [[ -d "/proc/sys/net/ipv6" ]] && sysctl -q -w "net.ipv6.conf.$interface_sysctl.accept_ra=0"
+ ;;
+ "") # undefined IP6 does not prevent RA's from being received -> nop
+ ;;
+ *)
+ report_error "IP6 must be 'dhcp', 'dhcp-noaddr', 'stateless', 'static' or 'no'"
+ return 1
+ ;;
+ esac
+
case $IP in
dhcp)
case ${DHCPClient:-dhcpcd} in
@@ -57,12 +75,6 @@ ip_set() {
return 1
fi
done
- if [[ $Gateway ]]; then
- if ! do_debug ip route add default via "$Gateway" dev "$Interface"; then
- report_error "Could not set gateway '$Gateway' on interface '$Interface'"
- return 1
- fi
- fi
;;
""|no)
;;
@@ -80,23 +92,15 @@ ip_set() {
return 1
fi
done
- fi
- # Load ipv6 module if necessary
- case "$IP6" in
- dhcp*|stateless|static)
- [[ -d "/proc/sys/net/ipv6" ]] || modprobe ipv6
- ;;
- no)
- [[ -d "/proc/sys/net/ipv6" ]] && sysctl -q -w "net.ipv6.conf.$interface_sysctl.accept_ra=0"
- ;;
- "") # undefined IP6 does not prevent RA's from being received -> nop
- ;;
- *)
- report_error "IP6 must be 'dhcp', 'dhcp-noaddr', 'stateless', 'static' or 'no'"
- return 1
- ;;
- esac
+ # Set a custom gateway after static routes are added
+ if [[ $IP == "static" && $Gateway ]]; then
+ if ! do_debug ip route add default via "$Gateway" dev "$Interface"; then
+ report_error "Could not set gateway '$Gateway' on interface '$Interface'"
+ return 1
+ fi
+ fi
+ fi
case "$IP6" in
dhcp*)
@@ -104,7 +108,6 @@ ip_set() {
report_error "You need to install dhclient to use DHCPv6"
return 1
fi
- sysctl -q -w "net.ipv6.conf.$interface_sysctl.accept_ra=1"
[[ $IP6 == "dhcp-noaddr" ]] && DhclientOptions6+=" -S"
rm -f "/run/dhclient6-${Interface}.pid"
if ! do_debug dhclient -6 -q -e "TIMEOUT=${TimeoutDHCP:-10}" -pf "/run/dhclient6-${Interface}.pid" $DhclientOptions6 "$Interface"; then
@@ -112,12 +115,6 @@ ip_set() {
return 1
fi
;;
- stateless)
- sysctl -q -w "net.ipv6.conf.$interface_sysctl.accept_ra=1"
- ;;&
- static)
- sysctl -q -w "net.ipv6.conf.$interface_sysctl.accept_ra=0"
- ;;&
stateless|static)
for addr in "${Address6[@]}"; do
if ! do_debug ip -6 addr add $addr dev "$Interface"; then
@@ -134,7 +131,7 @@ ip_set() {
return 1
fi
- # Add static IPv6 routes
+ # Add static IPv6 routes after DAD has finished
for route in "${Routes6[@]}"; do
if ! do_debug ip -6 route add $route dev "$Interface"; then
report_error "Could not add route '$route' to interface '$Interface'"
@@ -142,7 +139,7 @@ ip_set() {
fi
done
- # Set a custom gateway after DAD has finished
+ # Set a custom gateway after static routes are added
if [[ $IP6 == @(stateless|static) && $Gateway6 ]]; then
if ! do_debug ip -6 route replace default via "$Gateway6" dev "$Interface"; then
report_error "Could not set gateway '$Gateway6' on interface '$Interface'"
@@ -180,7 +177,7 @@ ip_set() {
# $IP: type of IPv4 configuration
# $IP6: type of IPv6 configuration
ip_unset() {
- if [[ "$IP" == "dhcp" ]]; then
+ if [[ $IP == "dhcp" ]]; then
case ${DHCPClient:-dhcpcd} in
dhcpcd)
if [[ -f "/run/dhcpcd-$Interface.pid" ]]; then
@@ -195,7 +192,7 @@ ip_unset() {
;;
esac
fi
- if [[ "$IP6" == dhcp* ]]; then
+ if [[ $IP6 == dhcp* ]]; then
if [[ -f "/run/dhclient6-$Interface.pid" ]]; then
do_debug dhclient -6 -q -x "$Interface" -pf "/run/dhclient6-$Interface.pid" >/dev/null
fi