From patchwork Fri May 7 13:01:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jouke Witteveen X-Patchwork-Id: 1919 Return-Path: Delivered-To: patchwork@archlinux.org Received: from mail.archlinux.org [95.216.189.61] by patchwork.archlinux.org with IMAP (fetchmail-6.4.19) for (single-drop); Fri, 07 May 2021 13:01:47 +0000 (UTC) Received: from mail.archlinux.org by mail.archlinux.org with LMTP id KH4LDTs6lWAm/wIAK+/4rw (envelope-from ) for ; Fri, 07 May 2021 13:01:47 +0000 Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by mail.archlinux.org (Postfix) with ESMTPS id 5B627579BF0; Fri, 7 May 2021 13:01:46 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id EF56B2C84E; Fri, 7 May 2021 13:01:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.archlinux.org; s=luna; t=1620392506; bh=su7a68EdKK6YMwhFxBwVArl/92dJzfvq3WjQZzAWJ3g=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc; b=KqABTPT86tSw9zg2l+zca4nqcqLJOtwJb6ahlHXaTqXOOYkxwHNyAby9Y6PL+Xw0t iViB5DHbhiwkntmwOpIeJSCto0koPg40HH1nvZl27ihrsRNb9GPLh0IPA/11Jbk9Al nLLyCbIPhFvx642Z4o7KP6UtXUqz+ROZoDvV/PvcHBPmx9ISNJpm2I6taT/J35PQnO hHWCEGNFxAMY0VPbKS2korrJoJb3wsMtZJOUXFJZxc2heLG56wzbKqhpFlKXqFld+V s+aWMN+/y/Nol1tl7IwF/QUWQa1RArHVmbYeTDlergGCDyeal43lbcBKYPdMOj0Gk3 cGPC5uEoUtn8IkoZxkENzCx8BPu9Eh0i2q/olbUBvhK6JTrKagei3xCatiwyOn0lrf mdL8SD8QqG+8pa1XQTiUe1XTGrdhRBqgrc8QjvFgZrJ3rfCLzN/qAx1S6wUsKMvcRu eIdJ/Pwp/zbS5udJEZ3m8yXicStEv+/4cSCH9Sp10BGRf79dowDPuTa98mlpV+uS2z 6T/0uLVMLmvPP41C3aM4qd2EWjZHlR/n77KNKqf3/NgcAJ9UY9+sqPkUTfEPbcqPOX 7mQG4Uay+AcLb04B8jrOEIgS9qIjXY4x0zijEfdOrwmmDent6XxtnbzW+zfPqy2phH Dwk64DM3R9l2Xyap40m9Xd6E= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id CFCC42C84C for ; Fri, 7 May 2021 13:01:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on luna.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=DKIM_SIGNED=0.1, DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,FREEMAIL_FROM=0.5, RCVD_IN_DNSWL_MED=-2.3,RCVD_IN_MSPIKE_H4=0.001,RCVD_IN_MSPIKE_WL=0.001, T_DMARC_POLICY_NONE=0.01,T_DMARC_SIMPLE_DKIM=0.01 autolearn=failed autolearn_force=no version=3.4.6 X-Spam-BL-Results: [127.0.0.19] [127.0.9.2] Received: from mail.archlinux.org (mail.archlinux.org [95.216.189.61]) by luna.archlinux.org (Postfix) with ESMTPS for ; Fri, 7 May 2021 13:01:40 +0000 (UTC) Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.archlinux.org (Postfix) with ESMTPS id 070CE579BEF for ; Fri, 7 May 2021 13:01:39 +0000 (UTC) Received: by mail-ej1-x633.google.com with SMTP id t4so13557658ejo.0 for ; Fri, 07 May 2021 06:01:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition; bh=Em/qJSx3Jsc1uOYEvcvjHvU9S8ORKbh1uO2Iz5Bnu9I=; b=oO0CxY1jZ9QulbR4JjKMF6inG/PkZqRMF/T0UGLoKSzbkuzMyBU8pq2I44CcBpJ+ki MHvWxA4pQ8xYMHELUj9++s/KKGSNLotW2gdhQ91uw904R+4fzJ2hsnRHHPW8On8rhUXw 77tEMrUtNMsXaOb1CqlsaSV5+AG+3mg0C1zZpZXsaW7RV355FuRq7oauTRjKUwhWC8it 6kcIwKNLkibvsF2vBvpZmeJT0kbAUE+bkfiFIm2Ztyt3vb4q5mK+MBzMxyn4Jm2jvJuA g7g/Z2cttrUFsZ5BsqmYugXrcNsidoYS9yat8vXqNe+yR8QkI4zDAMsi1NA8hyqc+HKn R8VQ== X-Gm-Message-State: AOAM533jPu8WYt4A2hRKodij1g4o/BlwM5f8t6ENq52w9dIrB4ypiWYe ZbWcIIMHFs4djmgAeZpaVKfLfa6y7o/8MQ== X-Google-Smtp-Source: ABdhPJzuCXDA0Xa43tOiJjEAxX6Vwaynqbjse8+zFNZzJVwpzmFzsEWRzDfnk/4U1X9nXOOazN3Vpw== X-Received: by 2002:a17:906:82cb:: with SMTP id a11mr9999049ejy.213.1620392497620; Fri, 07 May 2021 06:01:37 -0700 (PDT) Received: from Mindship-03 (252-168-166-62.ftth.glasoperator.nl. [62.166.168.252]) by smtp.gmail.com with ESMTPSA id w2sm1957198edl.53.2021.05.07.06.01.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 06:01:37 -0700 (PDT) Date: Fri, 7 May 2021 15:01:33 +0200 To: arch-projects@archlinux.org Message-ID: MIME-Version: 1.0 Content-Disposition: inline Subject: [arch-projects] [netctl][PATCH] More uniform profile loading and filtering X-BeenThere: arch-projects@lists.archlinux.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Arch Linux projects development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jouke Witteveen via arch-projects From: Jouke Witteveen Reply-To: Arch Linux projects development discussion Cc: Jouke Witteveen Errors-To: arch-projects-bounces@lists.archlinux.org Sender: "arch-projects" Authentication-Results: mail.archlinux.org; dkim=pass header.d=lists.archlinux.org header.s=luna header.b=KqABTPT8; dmarc=pass (policy=none) header.from=archlinux.org; spf=pass (mail.archlinux.org: domain of arch-projects-bounces@lists.archlinux.org designates 2a01:4f8:160:3033::2 as permitted sender) smtp.mailfrom=arch-projects-bounces@lists.archlinux.org X-Rspamd-Queue-Id: 5B627579BF0 X-Spamd-Result: default: False [-3.61 / 15.00]; HAS_REPLYTO(0.00)[arch-projects@lists.archlinux.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2a01:4f8:160:3033::2:c]; REPLYTO_ADDR_EQ_FROM(0.00)[]; RCVD_DKIM_ARC_DNSWL_MED(-0.50)[]; RCVD_IN_DNSWL_MED(-0.40)[2a01:4f8:160:3033::2:from,95.216.189.61:received]; DKIM_TRACE(0.00)[lists.archlinux.org:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[archlinux.org,none]; MAILLIST(-0.20)[mailman]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:24940, ipnet:2a01:4f8::/32, country:DE]; FROM_NEQ_ENVFROM(0.00)[arch-projects@lists.archlinux.org,arch-projects-bounces@lists.archlinux.org]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[lists.archlinux.org:s=luna]; FROM_HAS_DN(0.00)[]; DWL_DNSWL_MED(-2.00)[archlinux.org:dkim]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::633:received]; NEURAL_HAM(-0.00)[-1.000]; MID_RHS_NOT_FQDN(0.50)[]; FREEMAIL_CC(0.00)[gmail.com]; RCVD_COUNT_SEVEN(0.00)[7]; FORGED_SENDER_MAILLIST(0.00)[] X-Rspamd-Server: mail.archlinux.org Hooks and interface scripts are now sourced more systematically. Settings of wireless profiles that depend on hooks are now picked up correctly by netctl-auto. Suggested by: Vitor Sakaguti --- Inspired by a report on GitHub: https://github.com/joukewitteveen/netctl/issues/185 src/ifplugd.action | 5 ++-- src/lib/auto.action | 3 --- src/lib/globals | 56 ++++++++++++++++++++++++++++++++++----------- src/lib/interface | 9 -------- src/lib/network | 1 - src/netctl-auto | 6 ++--- src/netctl.in | 11 +++------ 7 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/ifplugd.action b/src/ifplugd.action index c1f0e7d..0cebb34 100755 --- a/src/ifplugd.action +++ b/src/ifplugd.action @@ -14,11 +14,10 @@ case "$2" in printf '%s' "$profile" > "$PROFILE_FILE" exit 0 fi - done < <(list_profiles | while IFS= read -r profile; do + done < <(filter_profiles "$1" ethernet | while IFS= read -r profile; do report_debug "Examining profile '$profile'" ( - source "$PROFILE_DIR/$profile" > /dev/null - [[ $Interface == "$1" && $Connection == "ethernet" ]] || exit + load_profile "$profile" > /dev/null # Prioritize dhcp based profiles as they can outright fail, whereas # it is difficult to tell if a profile with a static address fails if [[ $IP == "dhcp" || $IP6 == dhcp* ]]; then diff --git a/src/lib/auto.action b/src/lib/auto.action index 6c13651..717d205 100755 --- a/src/lib/auto.action +++ b/src/lib/auto.action @@ -1,7 +1,6 @@ #! /bin/bash . /usr/lib/netctl/globals -. "$SUBR_DIR/interface" . "$SUBR_DIR/ip" export INTERFACE="$1" @@ -11,7 +10,6 @@ PROFILE_FILE="$STATE_DIR/netctl-auto-$INTERFACE.profile" case $ACTION in CONNECTED) load_profile "$WPA_ID_STR" - load_interface_config "$INTERFACE" DhcpcdOptions+=" -K -L" ip_set || exit 1 mkdir -p "$(dirname "$PROFILE_FILE")" @@ -26,7 +24,6 @@ case $ACTION in DISCONNECTED) if [[ -s "$PROFILE_FILE" ]]; then load_profile "$(< "$PROFILE_FILE")" - load_interface_config "$INTERFACE" rm -f "$PROFILE_FILE" # Sandbox the eval if ! ( do_debug eval "$ExecDownPre" ); then diff --git a/src/lib/globals b/src/lib/globals index 32a1802..3d2c50d 100644 --- a/src/lib/globals +++ b/src/lib/globals @@ -103,41 +103,71 @@ timeout_wait() { ### Profile management -## List all acceptable profiles names separated by newlines -list_profiles() { - # Follow aliases with -L, skip forbidden/reserved names - find -L "$PROFILE_DIR/" -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name $'*\n*' -not -name '*.action' -not -name '*.conf' -not -name '*.service' -printf '%f\n' +## Load all available hooks +load_hooks() { + local hook + while IFS= read -r hook; do + source "$hook" + done < <(find -L "$PROFILE_DIR/hooks" -maxdepth 1 -type f -executable -not -name '.*' -not -name '*~' -not -name $'*\n*' | sort) } -## Exit if a profile file is not syntactically correct -# $1: profile name -verify_profile() { - /bin/bash -n "$PROFILE_DIR/$1" || exit 1 +## Load interface configuration, if present +# $1: interface name +load_interface_config() { + local config_file="$PROFILE_DIR/interfaces/$1" + if [[ -x $config_file ]]; then + source "$config_file" + fi } ## Sources all hooks and a profile (but no interface configuration) # $1: profile name load_profile() { - local hook # Expose the profile name Profile=$1 if [[ -z $Profile || ! -r "$PROFILE_DIR/$Profile" ]]; then exit_error "Profile '$Profile' does not exist or is not readable" fi - while IFS= read -r hook; do - source "$hook" - done < <(find -L "$PROFILE_DIR/hooks" -maxdepth 1 -type f -executable -not -name '.*' -not -name '*~' -not -name $'*\n*' | sort -u) - unset hook + load_hooks source "$PROFILE_DIR/$Profile" if [[ -z $Interface ]]; then exit_error "Profile '$Profile' does not specify an interface" fi + load_interface_config "$Interface" if [[ ! -r "${Connection:+$SUBR_DIR/connections/$Connection}" ]]; then exit_error "Profile '$Profile' does not specify a valid connection" fi source "$SUBR_DIR/connections/$Connection" } +## List all acceptable profiles names separated by newlines +list_profiles() { + # Follow aliases with -L, skip forbidden/reserved names + find -L "$PROFILE_DIR/" -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name $'*\n*' -not -name '*.action' -not -name '*.conf' -not -name '*.service' -printf '%f\n' +} + +## List names of profiles for a given interface and/or connection +# $1: interface (optional) +# $2: connection (optional) +filter_profiles() { + list_profiles | while IFS= read -r Profile; do + if ( + source "$PROFILE_DIR/$Profile" || exit + [[ -z $1 || $1 == "$Interface" ]] || exit + load_interface_config "$Interface" + [[ -z $2 || $2 == "$Connection" ]] || exit + ); then + printf '%s\n' "$Profile" + fi + done +} + +## Exit if a profile file is not syntactically correct +# $1: profile name +verify_profile() { + /bin/bash -n "$PROFILE_DIR/$1" || exit 1 +} + ## Wrapper around systemctl converting profile names to unit names # $1: systemctl command # $2...: profile names diff --git a/src/lib/interface b/src/lib/interface index 1a51c07..8504191 100644 --- a/src/lib/interface +++ b/src/lib/interface @@ -1,15 +1,6 @@ ## /usr/lib/netctl/globals needs to be sourced before this file -## Load interface configuration, if present -# $1: interface name -load_interface_config() { - local config_file="$PROFILE_DIR/interfaces/$1" - if [[ -x $config_file ]]; then - source "$config_file" - fi -} - ## Check if a string represents a network interface # $1: potential interface name is_interface() { diff --git a/src/lib/network b/src/lib/network index b6926e3..cb79b77 100755 --- a/src/lib/network +++ b/src/lib/network @@ -88,7 +88,6 @@ elif [[ $# -eq 2 && $1 == @(start|stop) ]]; then # Expose the command Command=$1 load_profile "$2" - load_interface_config "$Interface" "network_$1" else exit_error "Usage: $0 {start|stop|wait-online} [profile]" diff --git a/src/netctl-auto b/src/netctl-auto index ec3f7a2..720949e 100755 --- a/src/netctl-auto +++ b/src/netctl-auto @@ -211,12 +211,10 @@ start() { # Disable p2p to prevent wpa_supplicant from creating another control interface echo "p2p_disabled=1" >> "$WPAConfigFile" - local profile - list_profiles | while IFS= read -r profile; do + filter_profiles "$interface" wireless | while IFS= read -r profile; do report_debug "Examining profile '$profile'" ( - source "$PROFILE_DIR/$profile" - [[ $Interface == "$interface" && $Connection == "wireless" ]] || exit + load_profile "$profile" is_yes "${ExcludeAuto:-no}" && exit # Set default and exclude wpa-config as it does not fit this scheme [[ ${Security:=none} != "wpa-config" ]] || exit diff --git a/src/netctl.in b/src/netctl.in index 929eb1e..3a96f12 100644 --- a/src/netctl.in +++ b/src/netctl.in @@ -71,16 +71,11 @@ stop_all() { } switch_to() { - cd "$PROFILE_DIR" - # We assume interface names are not quoted - # Using read removes leading whitespace - read InterfaceLine < \ - <(grep -om1 '^[[:space:]]*Interface=[[:alnum:]:._-]\+' "$1") - if [[ -z $InterfaceLine ]]; then + Interface=$(. "$PROFILE_DIR/$1" >/dev/null; printf '%s' "$Interface") + if [[ -z $Interface ]]; then exit_error "Profile '$1' does not specify an interface" fi - mapfile -t AllProfiles < <(list_profiles) - mapfile -t Profiles < <(grep -Fl "$InterfaceLine" "${AllProfiles[@]}") + mapfile -t Profiles < <(filter_profiles "$Interface") if (( ${#Profiles[@]} )); then do_debug sd_call stop "${Profiles[@]}" 2> >(grep -Fv 'not loaded' >&2) fi