From e76ca5cda9077a22cb85018284c549aebd036916 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Wed, 23 Dec 2020 22:07:23 +0000 Subject: Allow interfaces to be Deprecated resolvconf -C interface.* This will deprecate all matching interfaces. resolvconf -c interface.* This will re-activate all matching interfaces. Generally some OS's support the concept of persisting the IP address when the carrier drops (NetBSD) or wireless roaming (Linux). In this situation, resolvconf needs to persist the DNS as well but it needs to ensure that any active interface then takes precedence. --- resolvconf.8.in | 15 ++++++++++- resolvconf.in | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 91 insertions(+), 8 deletions(-) diff --git a/resolvconf.8.in b/resolvconf.8.in index 12387bb..39020e9 100644 --- a/resolvconf.8.in +++ b/resolvconf.8.in @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd November 29, 2016 +.Dd December 23, 2016 .Dt RESOLVCONF 8 .Os .Sh NAME @@ -38,6 +38,10 @@ .Fl a Ar interface Ns Op Ar .protocol .No < Ns Pa file .Nm +.Fl C Ar pattern +.Nm +.Fl c Ar pattern +.Nm .Op Fl f .Fl d Ar interface Ns Op Ar .protocol .Nm @@ -126,6 +130,15 @@ file(s) for all the .Ar protocols on the .Ar interface . +For systems that support the concept of persisting configuration when +the carrier goes down, then it should instead call +.Nm +with +.Fl C Ar interface.* +arguments to deprecate the matching interfaces and +.Fl c Ar interface.* +to activate the matching interfaces when the carrier comes up. +This only affects the order in which interfaces are processed. .Pp Here are some options for the above commands:- .Bl -tag -width pattern_opt diff --git a/resolvconf.in b/resolvconf.in index e7b0ffe..d1ec074 100644 --- a/resolvconf.in +++ b/resolvconf.in @@ -64,6 +64,7 @@ IFACEDIR="$VARDIR/interfaces" METRICDIR="$VARDIR/metrics" PRIVATEDIR="$VARDIR/private" EXCLUSIVEDIR="$VARDIR/exclusive" +INACTIVEDIR="$VARDIR/inactive" LOCKDIR="$VARDIR/lock" _PWD="$PWD" @@ -88,6 +89,8 @@ usage() Commands: -a \$INTERFACE Add DNS information to the specified interface (DNS supplied via stdin in resolv.conf format) + -C \$PATTERN Deprecate DNS information for matched interfaces + -c \$PATTERN Configure DNS information for matched interfaces -d \$INTERFACE Delete DNS information from the specified interface -h Show this help cruft -i [\$PATTERN] Show interfaces that have supplied DNS information @@ -407,6 +410,22 @@ echo_resolv() IFS="$OIFS" } +inactive_interface() +{ + [ -d "$INACTIVEDIR" ] || return 1 + + cd "$INACTIVEDIR" + for ia; do + for iaf in *; do + [ -f "$iaf" ] || continue + case "$ia" in + $iaf) return 0;; + esac + done + done + return 1 +} + list_resolv() { [ -d "$IFACEDIR" ] || return 0 @@ -474,12 +493,25 @@ list_resolv() list="$list $i" fi done + if [ -d "$METRICDIR" ]; then cd "$METRICDIR" for i in *; do [ -f "$i" ] && list="$list ${i#* }" done fi + + # Move inactive interfaces to the back + active= + inactive= + for i in $list; do + if inactive_interface "$i"; then + inactive="$inactive $i" + else + active="$active $i" + fi + done + list="$active $inactive" fi cd "$IFACEDIR" @@ -678,7 +710,7 @@ make_vars() force=false VFLAG= -while getopts a:Dd:fhIilm:pRruvVx OPT; do +while getopts a:C:c:Dd:fhIilm:pRruvVx OPT; do case "$OPT" in f) force=true;; h) usage;; @@ -693,7 +725,7 @@ while getopts a:Dd:fhIilm:pRruvVx OPT; do fi ;; x) IF_EXCLUSIVE=1;; - '?') ;; + '?') exit 1;; *) cmd="$OPT"; iface="$OPTARG";; esac done @@ -742,14 +774,20 @@ if [ "$cmd" = v ] || [ -n "$VFLAG" ]; then fi # Test that we have valid options -if [ "$cmd" = a ] || [ "$cmd" = d ]; then +case "$cmd" in +a|d|C|c) if [ -z "$iface" ]; then - usage "Interface not specified" + error_exit "Interface not specified" + fi + ;; +u) ;; +*) + if [ -n "$cmd" ] && [ "$cmd" != h ]; then + error_exit "Unknown option $cmd" fi -elif [ "$cmd" != u ]; then - [ -n "$cmd" ] && [ "$cmd" != h ] && usage "Unknown option $cmd" usage -fi + ;; +esac if [ "$cmd" = a ]; then for x in '/' \\ ' ' '*'; do @@ -945,6 +983,7 @@ d) "$PRIVATEDIR/$i" \ "$EXCLUSIVEDIR/"*" $i" || exit $? done + if ! $changed; then # Set the return code based on the forced flag $force @@ -952,6 +991,37 @@ d) fi unset changed i ;; + +C) + # Mark interface as inactive + [ ! -d "$INACTIVEDIR" ] && mkdir "$INACTIVEDIR" + cd "$INACTIVEDIR" + changed=false + for i in $args; do + if [ ! -e "$i" ]; then + changed=true + echo " " >"$i" || exit $? + fi + done + $changed || exit 0 + unset changed i + ;; + +c) + # Mark interface as active + if [ -d "$INACTIVEDIR" ]; then + cd "$INACTIVEDIR" + changed=false + for i in $args; do + if [ -e "$i" ]; then + changed=true + rm "$i" || exit $? + fi + done + $changed || exit 0 + unset changed i + fi + ;; esac case "${resolvconf:-YES}" in -- cgit v1.2.3