diff options
-rw-r--r-- | dhcp.c | 2 | ||||
-rwxr-xr-x | dhcpcd-hooks/25-static-routes.conf | 61 | ||||
-rw-r--r-- | dhcpcd_test.cpp | 6 | ||||
-rw-r--r-- | if-options.h | 2 |
4 files changed, 65 insertions, 6 deletions
@@ -1382,7 +1382,6 @@ ssize_t configure_env(char **env, const char *prefix, const struct dhcp_message *dhcp, const struct if_options *ifo) { - unsigned int i; const uint8_t *p; int pl; struct in_addr addr; @@ -1425,7 +1424,6 @@ configure_env(char **env, const char *prefix, const struct dhcp_message *dhcp, net.s_addr = get_netmask(addr.s_addr); setvar(&ep, prefix, "subnet_mask", inet_ntoa(net)); } - i = inet_ntocidr(net); snprintf(cidr, sizeof(cidr), "%d", inet_ntocidr(net)); setvar(&ep, prefix, "subnet_cidr", cidr); if (get_option_addr(&brd, dhcp, DHO_BROADCAST) == -1) { diff --git a/dhcpcd-hooks/25-static-routes.conf b/dhcpcd-hooks/25-static-routes.conf new file mode 100755 index 0000000..c6b7c4a --- /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 diff --git a/dhcpcd_test.cpp b/dhcpcd_test.cpp index 1fa829f..a254d4d 100644 --- a/dhcpcd_test.cpp +++ b/dhcpcd_test.cpp @@ -97,9 +97,9 @@ class DhcpcdGetOptionTest : public ::testing::Test { } struct dhcp_message dhcpmsgs[2]; - size_t type_index; - size_t length_index; - size_t value_index; + volatile size_t type_index; + volatile size_t length_index; + volatile size_t value_index; }; TEST_F(DhcpcdGetOptionTest, OptionNotPresent) { diff --git a/if-options.h b/if-options.h index 0e9d103..45fac33 100644 --- a/if-options.h +++ b/if-options.h @@ -39,7 +39,7 @@ * compatibility with getopt */ #define IF_OPTS "abc:de:f:gh:i:kl:m:no:pqr:s:t:u:v:wxy:z:ABC:DEF:GHI:JKLO:Q:S:TUVW:X:Z:" -#define DEFAULT_TIMEOUT 30 +#define DEFAULT_TIMEOUT 0 /* keep retrying forever... */ #define DEFAULT_REBOOT 5 #define HOSTNAME_MAX_LEN 250 /* 255 - 3 (FQDN) - 2 (DNS enc) */ |