diff options
author | Greg Hartman <ghartman@google.com> | 2014-12-12 14:06:04 -0800 |
---|---|---|
committer | Greg Hartman <ghartman@google.com> | 2014-12-12 23:21:54 +0000 |
commit | e3e9615ee77a5997667026ab184c21b669a0cab3 (patch) | |
tree | 76a570998d8ca1e8edcff592e79f6e201bb4b941 | |
parent | 745a9a07ebb9c174c7258d77e822046d66fcae10 (diff) | |
download | android_external_dhcpcd-e3e9615ee77a5997667026ab184c21b669a0cab3.tar.gz android_external_dhcpcd-e3e9615ee77a5997667026ab184c21b669a0cab3.tar.bz2 android_external_dhcpcd-e3e9615ee77a5997667026ab184c21b669a0cab3.zip |
Add a script to save static route configuration in properties.
I'm intentionally keeping this out of the default configuration.
Change-Id: Ic1152aedbf54e11c3a3a7c985ade6a47dffc07ae
-rwxr-xr-x | dhcpcd-hooks/25-static-routes.conf | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/dhcpcd-hooks/25-static-routes.conf b/dhcpcd-hooks/25-static-routes.conf new file mode 100755 index 0000000..2f6869e --- /dev/null +++ b/dhcpcd-hooks/25-static-routes.conf @@ -0,0 +1,61 @@ +# Set dhcp.<iface>.routeN.dest and dhcp.<iface>.routeN.via properties with +# the static routes provided by the DHCP server. + +# CAUTION +# +# Placing this in the hooks directory will allow DHCP servers to push static +# routes to ALL of the interfaces that use the directory. +# +# To avoid this, create separate dhcpcd configurations, one for the interfaces +# that should accept static routes and another for the interfaces that should +# not accept static routes routes. + +# Add this script in the hooks directory only for the interfaces that should +# accept static routes. +# +# Add "nooption classless_static_routes, static_routes" to the dhcpcd.conf +# file for the interfaces that should not accept static routes. Do not add the +# script to the hooks directory. + +next_set_interface=1 + +set_route_props_from_list() +{ + while [[ $# -ge 2 ]]; do + setprop dhcp.${interface}.route${next_set_interface}.dest $1 + shift + setprop dhcp.${interface}.route${next_set_interface}.via $1 + shift + next_set_interface=$(($next_set_interface + 1)) + done +} + +unset_route_props() +{ + next_clear_interface=1 + while [[ ! -z "$(getprop dhcp.${interface}.route${next_clear_interface}.dest)" ]]; do + setprop dhcp.${interface}.route${next_clear_interface}.dest "" + setprop dhcp.${interface}.route${next_clear_interface}.via "" + next_clear_interface=$(($next_clear_interface + 1)) + done + while [[ ! -z "$(getprop dhcp.${interface}.route${next_clear_interface}.via)" ]]; do + setprop dhcp.${interface}.route${next_clear_interface}.dest "" + setprop dhcp.${interface}.route${next_clear_interface}.via "" + next_clear_interface=$(($next_clear_interface + 1)) + done +} + +set_route_props() +{ + unset_route_props + if [[ ! -z "${new_classless_static_routes}" ]]; then + set_route_props_from_list ${new_classless_static_routes} + else + set_route_props_from_list ${new_static_routes} + fi +} + +case "${reason}" in +BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) set_route_props;; +EXPIRE|FAIL|IPV4LL|RELEASE|STOP) unset_route_props;; +esac |