diff options
Diffstat (limited to 'dhcpcd-run-hooks.in')
-rw-r--r-- | dhcpcd-run-hooks.in | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/dhcpcd-run-hooks.in b/dhcpcd-run-hooks.in index cb897b4..2125f9a 100644 --- a/dhcpcd-run-hooks.in +++ b/dhcpcd-run-hooks.in @@ -2,25 +2,25 @@ # dhcpcd client configuration script # Handy variables and functions for our hooks to use +if [ "$reason" = ROUTERADVERT ]; then + ifsuffix=":ra" +else + ifsuffix= +fi +ifname="$interface$ifsuffix" + from=from signature_base="# Generated by dhcpcd" -signature="$signature_base $from $interface" +signature="$signature_base $from $ifname" signature_base_end="# End of dhcpcd" -signature_end="$signature_base_end $from $interface" +signature_end="$signature_base_end $from $ifname" state_dir=/var/run/dhcpcd -if_up=false -if_down=false -case "$reason" in -BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) if_up=true;; -PREINIT|EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP) if_down=true;; -esac - # Ensure that all arguments are unique uniqify() { local result= i= - for i; do + for i do case " $result " in *" $i "*);; *) result="$result $i";; @@ -62,7 +62,7 @@ key_get_value() if type sed >/dev/null 2>&1; then sed -n "s/^$key//p" $@ else - for x; do + for x do while read line; do case "$line" in "$key"*) echo "${line##$key}";; @@ -82,7 +82,7 @@ remove_markers() if type sed >/dev/null 2>&1; then sed "/^$m1/,/^$m2/d" $@ else - for x; do + for x do while read line; do case "$line" in "$m1"*) in_marker=1;; @@ -142,11 +142,51 @@ syslog() [ -n "$lvl" ] && shift if [ -n "$*" ]; then if type logger >/dev/null 2>&1; then - logger -t dhcpcd -p daemon."$lvl" -s "$*" + logger -t dhcpcd -p daemon."$lvl" -is "$interface: $*" fi fi } +# Check for a valid domain name as per RFC1123 with the exception of +# allowing - and _ as they seem to be widely used. +valid_domainname() +{ + local name="$1" label + + [ -z "$name" -o ${#name} -gt 255 ] && return 1 + + while [ -n "$name" ]; do + label="${name%%.*}" + [ -z "$label" -o ${#label} -gt 63 ] && return 1 + case "$label" in + -*|_*|*-|*_) return 1;; + *[![:alnum:]-_]*) return 1;; + esac + [ "$name" = "${name#*.}" ] && break + name="${name#*.}" + done + return 0 +} + +valid_domainname_list() +{ + local name + + for name do + valid_domainname "$name" || return $? + done + return 0 +} + +# Check for a valid path +valid_path() +{ + case "$@" in + *[![:alnum:]#%+-_:\.,@~\\/\[\]=\ ]*) return 1;; + esac + return 0 +} + # Check a system service exists service_exists() { |