From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 140D570C9A for ; Fri, 25 Jun 2021 13:19:16 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 00F13176AE for ; Fri, 25 Jun 2021 13:18:46 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id CC7451769E for ; Fri, 25 Jun 2021 13:18:44 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 941F346773 for ; Fri, 25 Jun 2021 13:18:44 +0200 (CEST) Message-ID: Date: Fri, 25 Jun 2021 13:18:33 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:90.0) Gecko/20100101 Thunderbird/90.0 Content-Language: en-US To: Proxmox VE development discussion , Lorenz Stechauner References: <20210625104837.913605-1-l.stechauner@proxmox.com> From: Thomas Lamprecht In-Reply-To: <20210625104837.913605-1-l.stechauner@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.620 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.001 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [inotify.pm] Subject: Re: [pve-devel] [PATCH common] fix #3153: INotify: adding interface comment to inet6 section when this is the only section X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Jun 2021 11:19:16 -0000 On 25.06.21 12:48, Lorenz Stechauner wrote: > Signed-off-by: Lorenz Stechauner > --- > src/PVE/INotify.pm | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm > index 562a243..ce1efd1 100644 > --- a/src/PVE/INotify.pm > +++ b/src/PVE/INotify.pm > @@ -1156,6 +1156,12 @@ sub __read_etc_network_interfaces { > $d->{method} = 'manual' if !$d->{method}; > $d->{method6} = 'manual' if !$d->{method6}; > > + if ($d->{comments6}) { > + $d->{comments} = '' if !defined($d->{comments}); > + $d->{comments} .= $d->{comments6}; > + $d->{comments6} = undef; rather than setting it to `undef`, in which case the hash element still exists, use `delete`, which also returns the value. So this could be: if (my $comments6 = delete $d->{comments6}) { $d->{comments} = ($d->{comments}) // '') . $comments6; } Shorter and also more correct/robust. > + } > + > $d->{families} ||= ['inet']; > } > > @@ -1242,7 +1248,7 @@ sub __interface_to_string { > my $done = { type => 1, priority => 1, method => 1, active => 1, exists => 1, > comments => 1, autostart => 1, options => 1, > address => 1, netmask => 1, gateway => 1, broadcast => 1, > - method6 => 1, families => 1, options6 => 1, > + method6 => 1, families => 1, options6 => 1, comments6 => 1, > address6 => 1, netmask6 => 1, gateway6 => 1, broadcast6 => 1, 'uplink-id' => 1 }; > > if (!$first_block) { > @@ -1733,6 +1739,12 @@ NETWORKDOC > } > } > > + # if 'inet6' is the only family or is at least a family in use > + if ($d->{families}[0] eq 'inet6') { shouldn't that include a length check like `scalar($d->{families}->@*) == 0` to be more safe/robust, as else inet6 could be just be first by chance (did not really checked the context though) > + $d->{comments6} = $d->{comments}; > + $d->{comments} = undef; see above regarding use of delete > + } > + > my $i = 0; # some options should be printed only once > $raw .= __interface_to_string($iface, $d, $_, !$i++, $ifupdown2) foreach @{$d->{families}}; > } >