From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <l.stechauner@proxmox.com>
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) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 1710D70C7D
 for <pve-devel@lists.proxmox.com>; Fri, 25 Jun 2021 14:30:12 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id E2B6217D63
 for <pve-devel@lists.proxmox.com>; Fri, 25 Jun 2021 14:30:11 +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) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 5831617D57
 for <pve-devel@lists.proxmox.com>; Fri, 25 Jun 2021 14:30:10 +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 E9CAE467A8
 for <pve-devel@lists.proxmox.com>; Fri, 25 Jun 2021 14:30:09 +0200 (CEST)
From: Lorenz Stechauner <l.stechauner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Fri, 25 Jun 2021 14:29:37 +0200
Message-Id: <20210625122937.2910309-1-l.stechauner@proxmox.com>
X-Mailer: git-send-email 2.30.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.672 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
 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: [pve-devel] [PATCH v2 common] fix #3153: INotify: adding comment of
 interface 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 <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Fri, 25 Jun 2021 12:30:12 -0000

Signed-off-by: Lorenz Stechauner <l.stechauner@proxmox.com>
---
changes to v1:
* using delete instead of undef
* added length check for families

 src/PVE/INotify.pm | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index 562a243..8cf4b44 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -1156,6 +1156,10 @@ sub __read_etc_network_interfaces {
 	$d->{method} = 'manual' if !$d->{method};
 	$d->{method6} = 'manual' if !$d->{method6};
 
+	if (my $comments6 = delete $d->{comments6}) {
+	    $d->{comments} = ($d->{comments} // '') . $comments6;
+	}
+
 	$d->{families} ||= ['inet'];
     }
 
@@ -1242,7 +1246,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 +1737,11 @@ NETWORKDOC
 	    }
 	}
 
+	# if 'inet6' is the only family
+	if (scalar($d->{families}->@*) == 1 && $d->{families}[0] eq 'inet6') {
+	    $d->{comments6} = delete $d->{comments};
+	}
+
 	my $i = 0; # some options should be printed only once
 	$raw .= __interface_to_string($iface, $d, $_, !$i++, $ifupdown2) foreach @{$d->{families}};
     }
-- 
2.30.2