From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id EB1271FF37F for ; Thu, 18 Apr 2024 22:49:50 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 00D4033BAD; Thu, 18 Apr 2024 22:49:48 +0200 (CEST) To: pve-devel@lists.proxmox.com Date: Thu, 18 Apr 2024 22:49:33 +0200 In-Reply-To: <20240418204933.58521-1-jcdra1@gmail.com> References: <20240418204933.58521-1-jcdra1@gmail.com> MIME-Version: 1.0 Message-ID: List-Id: Proxmox VE development discussion List-Post: From: Johannes Cornelis Draaijer via pve-devel Precedence: list Cc: Johannes Cornelis Draaijer X-Mailman-Version: 2.1.29 X-BeenThere: pve-devel@lists.proxmox.com List-Subscribe: , List-Unsubscribe: , List-Archive: Reply-To: Proxmox VE development discussion List-Help: Subject: [pve-devel] [PATCH pve-container 2/2] fix #5339: api: lxc: ip: add 'all' option so that all addresses can be returned. Content-Type: multipart/mixed; boundary="===============3323346243150531874==" Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" --===============3323346243150531874== Content-Type: message/rfc822 Content-Disposition: inline Return-Path: X-Original-To: pve-devel@lists.proxmox.com Delivered-To: pve-devel@lists.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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id B1D1799C8C for ; Thu, 18 Apr 2024 22:49:46 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 890073383A for ; Thu, 18 Apr 2024 22:49:46 +0200 (CEST) Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 18 Apr 2024 22:49:46 +0200 (CEST) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2da08b07157so17699871fa.1 for ; Thu, 18 Apr 2024 13:49:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713473379; x=1714078179; darn=lists.proxmox.com; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7BCnLVEWYo8tJCdMgR/vLoAw9F2reET/IoFkB7jndLw=; b=Kw1cgu6VdXkAPyufJys1UOP4kkgsu1tPMhA51ZTBk1ri3ILs0uzjFTpCklArQJ6wVw lgiXhLidJfwrFMjoJn1zQEFuBlSWb0eLwIQ8bXbm6P6E5Hq4PLZRLdC2iuUVjSb+NaYQ uhQlCo1En3fzp3jx2wqa76YHgQXSDCi7x95e2hfOdY+4rLjQPnvzZ32EwCNlWfiIlR6S AWMF87niYmzVbvMcAftr1jh+pUHtnN9EtEB80VDm7/8KuUaqM/UtNSFTm9BLJaoEkYw6 +KfYg3kA563ZQs8PNYkdhdsi+2DD72ShnqZrp8WUTHiNIF2lLfSz3WRyCjFValVKnZm0 KJCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713473379; x=1714078179; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7BCnLVEWYo8tJCdMgR/vLoAw9F2reET/IoFkB7jndLw=; b=VhdbI1yJtvOw3fUGty3kOiu1djiKZrd+crqB0flp+5fdav9dvDZN8sDDkpJweUd15F pYc3YLbzK5B3EqNhhMgCLpTYiWNo1ELzTexoCER/CYTCwM2JDa+gB5Ek97cI3s/GwTMT fL2X1O8J23OhbxFphZZR0efpu0Lar+uRfOQ+8VtixOCCG6hZnDaF+iJA52P7rdfcyR8H jhpkbRfrPttQDAYY3V9lPBW++nkEALFNzptizy6ONhN40PNHUzVL5UV2J5ysC2OMS8BK zNbEZ/Sj04KbLHYEuMLjntZtZ0gtglyNhvDVcAaKy/gme58X6jDaz9YnSDexzw1l0TXJ Ws1Q== X-Gm-Message-State: AOJu0Yw+uyrxhQjVYSyszyoKXwhPBXII9TZvAcPIWRqYodwuh8vxn6ob awjm6VxMX5SMCJH5on04XGlBCpHwV3T28i2iyGzY14lyb8LNcstpHmIRkA== X-Google-Smtp-Source: AGHT+IHByqgjyvmnJAmmf9jO1Jlwsybv/+ws60mw6VdwfkT4nUjvL8JL1EN4Hi1ac5YXLTQX60wbLQ== X-Received: by 2002:a2e:9c56:0:b0:2d8:39cf:5368 with SMTP id t22-20020a2e9c56000000b002d839cf5368mr63566ljj.29.1713473378799; Thu, 18 Apr 2024 13:49:38 -0700 (PDT) Received: from desktop.lan ([2a01:799:1817:b300::ec5]) by smtp.gmail.com with ESMTPSA id t9-20020a2e8e69000000b002dbb1a5d7f4sm254602ljk.1.2024.04.18.13.49.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 13:49:38 -0700 (PDT) From: Johannes Cornelis Draaijer To: pve-devel@lists.proxmox.com Subject: [PATCH pve-container 2/2] fix #5339: api: lxc: ip: add 'all' option so that all addresses can be returned. Date: Thu, 18 Apr 2024 22:49:33 +0200 Message-Id: <20240418204933.58521-3-jcdra1@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240418204933.58521-1-jcdra1@gmail.com> References: <20240418204933.58521-1-jcdra1@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain DMARC_PASS -0.1 DMARC pass policy FREEMAIL_ENVFROM_END_DIGIT 0.25 Envelope-from freemail username ends in digit FREEMAIL_FROM 0.001 Sender email is commonly abused enduser mail provider RCVD_IN_DNSWL_NONE -0.0001 Sender listed at https://www.dnswl.org/, no trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Signed-off-by: Johannes Cornelis Draaijer --- src/PVE/API2/LXC.pm | 16 +++++++++++++--- src/PVE/LXC.pm | 9 +++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm index 89ba64c..3561317 100644 --- a/src/PVE/API2/LXC.pm +++ b/src/PVE/API2/LXC.pm @@ -2533,6 +2533,12 @@ __PACKAGE__->register_method({ properties => { node => get_standard_option('pve-node'), vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }), + all => { + type => 'boolean', + default => 0, + optional => 1, + description => 'Return all adresses of each interface instead of only one', + } }, }, returns => { @@ -2552,12 +2558,14 @@ __PACKAGE__->register_method({ }, inet => { type => 'string', - description => 'The IPv4 address of the interface', + format => 'CIDRv4-list', + description => 'A list of IPv4 CIDRs. This will only contain a single address if \'all\' is not set to true', optional => 1, }, inet6 => { type => 'string', - description => 'The IPv6 address of the interface', + format => 'CIDRv6-list', + description => 'A list of IPv6 CIDRs. This will only contain a single address if \'all\' is not set to true', optional => 1, }, } @@ -2565,8 +2573,10 @@ __PACKAGE__->register_method({ }, code => sub { my ($param) = @_; + my $vmid = extract_param($param, 'vmid'); + my $alladdrs = extract_param($param, 'all') // 0; - return PVE::LXC::get_interfaces($param->{vmid}); + return PVE::LXC::get_interfaces($vmid, $alladdrs); }}); __PACKAGE__->register_method({ diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index 7883cfb..6d00141 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -1088,7 +1088,7 @@ sub hotplug_net { } sub get_interfaces { - my ($vmid) = @_; + my ($vmid, $alladdrs) = @_; my $pid = eval { find_lxc_pid($vmid); }; return if $@; @@ -1104,7 +1104,12 @@ sub get_interfaces { for my $interface ($config->@*) { my $obj = { name => $interface->{ifname} }; for my $ip ($interface->{addr_info}->@*) { - $obj->{$ip->{family}} = $ip->{local} . "/" . $ip->{prefixlen}; + my $cidr = $ip->{local} . "/" . $ip->{prefixlen}; + if ($alladdrs eq 1) { + push(@{$obj->{$ip->{family}}}, $cidr); + } else { + $obj->{$ip->{family}} = $cidr; + } } $obj->{hwaddr} = $interface->{address}; push @$res, $obj -- 2.34.1 --===============3323346243150531874== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel --===============3323346243150531874==--