From nobody Sat Feb 7 06:35:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1580230161884204.26746255346222; Tue, 28 Jan 2020 08:49:21 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-302-gXeIgpT0MeGfBDs52cLsvA-1; Tue, 28 Jan 2020 11:49:18 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F35E3107ACCD; Tue, 28 Jan 2020 16:49:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C88831001B23; Tue, 28 Jan 2020 16:49:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7B41F85797; Tue, 28 Jan 2020 16:49:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00SGn6tT028298 for ; Tue, 28 Jan 2020 11:49:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id 81D7C63A70; Tue, 28 Jan 2020 16:49:06 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D7AAD1E80 for ; Tue, 28 Jan 2020 16:49:06 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5ED36185B0D2 for ; Tue, 28 Jan 2020 16:49:06 +0000 (UTC) Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-392-b9qgCLd0PHGFXkzxxPqeMw-1; Tue, 28 Jan 2020 11:49:03 -0500 Received: by mail-qt1-f194.google.com with SMTP id c24so10792668qtp.5; Tue, 28 Jan 2020 08:49:03 -0800 (PST) Received: from localhost.localdomain ([2804:431:c7cb:a9a6:59b3:4b4:e00c:2a48]) by smtp.gmail.com with ESMTPSA id n132sm13013505qke.58.2020.01.28.08.49.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2020 08:49:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580230160; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=8j5nitdM4cP9ppuiXkQWPKTRL6r55MrYA+Ey/IHEW9M=; b=ccEW3IzHQMZnxUeP6h8JV1eQedkusc4HfqoAz5Cw8FAfUWlSPNY195JJuXAFdTxiJLucKo GR6kUw3PkkQOfaN4KpPCwYINd3sGuhtKouT4odmbom5kWWomEsbE6rsNi75r5EMhn7op/n Btv4BF9pJFZfHO2qK2VGHGkhXW1HpRo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sJw+q3iP37EtjK2JK50+rML0PlQyFf6l8IZCqXwIBUk=; b=UerQFRckfv0aWND6NV6ZicQ1DjJGslVN/8wOP9DxnPkbxThHTEvPGEs6vKEA8ysXsQ ZsaSlFo6xujQgq3iZFTEOHqVPH6iH8B6pgs2Qs1yl/HQDEmLUATRufy/PmkpwdsjkYKk stcmzJgpCw+VBK1/XWNpPkymXm6v+SvkCVODB7wxR261EkPZz7K/Awc6ZLlKszU9Zitu kHmSEQgo0JDhi++ldtULJxPuTQvzdy1exTFo9ODO6TjhyDqG1DycCrgRuPUtB0Ft1g0Y lkK33UkhW7xa4FTe5s7YcBABDyCWBWxjOG1zPlZBsO+cxwpvo41mRK6jRijIkjXybLpn U1zA== X-Gm-Message-State: APjAAAXSaLVfmW96f7b76ZqtWYWxXQcgb4bMvbdHZfOhMlq5ax+AG1yE XFR/RsayPi1PKvaGQ2VFOUn7oWyf X-Google-Smtp-Source: APXvYqxnAzhuGyvWJnjuQi1MjP6gEFDciT2ivUrlUCBIluy2Lu1xm4Us+MzPig9+SNHGvXNzgHBD2g== X-Received: by 2002:ac8:704:: with SMTP id g4mr22624173qth.197.1580230142325; Tue, 28 Jan 2020 08:49:02 -0800 (PST) From: Julio Faracco To: libvir-list@redhat.com Subject: [PATCH v2 2/4] lxc: add LXC version 3 network parser Date: Tue, 28 Jan 2020 13:48:22 -0300 Message-Id: <20200128164822.32047-3-jcfaracco@gmail.com> In-Reply-To: <20200128164822.32047-1-jcfaracco@gmail.com> References: <20200128164822.32047-1-jcfaracco@gmail.com> MIME-Version: 1.0 X-MC-Unique: b9qgCLd0PHGFXkzxxPqeMw-1 X-MC-Unique: gXeIgpT0MeGfBDs52cLsvA-1 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 00SGn6tT028298 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" LXC version 3 or higher introduced indexes for network interfaces. Libvirt should be able to parse entries like `lxc.net.2.KEY`. This commit adds functions to parse this type of field. That's why array structures are so important this time. Signed-off-by: Julio Faracco --- src/lxc/lxc_native.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index b101848c09..15be33c9f1 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -649,6 +649,55 @@ lxcNetworkParseDataSuffix(const char *entry, } =20 =20 +static lxcNetworkParseDataPtr +lxcNetworkGetParseDataByIndex(lxcNetworkParseDataArray *networks, + unsigned int index) +{ + size_t ndata =3D networks->ndata; + size_t i; + + for (i =3D 0; i < ndata; i++) { + if (networks->parseData[i]->index =3D=3D index) + return networks->parseData[i]; + } + + /* Index was not found. So, it is time to add new * + * interface and return this last position. */ + if (VIR_EXPAND_N(networks->parseData, networks->ndata, 1) < 0) + return NULL; + + networks->parseData[ndata] =3D g_new0(lxcNetworkParseData, 1); + networks->parseData[ndata]->index =3D index; + + return networks->parseData[ndata]; +} + + +static int +lxcNetworkParseDataEntry(const char *name, + virConfValuePtr value, + lxcNetworkParseDataArray *networks) +{ + lxcNetworkParseData *parseData; + const char *suffix_tmp =3D STRSKIP(name, "lxc.net."); + char *suffix =3D NULL; + unsigned long long index; + + if (virStrToLong_ull(suffix_tmp, &suffix, 10, &index) < 0) + return -1; + + if (suffix[0] !=3D '.') + return -1; + + suffix++; + + if (!(parseData =3D lxcNetworkGetParseDataByIndex(networks, index))) + return -1; + + return lxcNetworkParseDataSuffix(suffix, value, parseData); +} + + static lxcNetworkParseDataPtr lxcNetworkGetParseDataByIndexLegacy(lxcNetworkParseDataArray *networks, const char *entry) @@ -695,6 +744,8 @@ lxcNetworkWalkCallback(const char *name, virConfValuePt= r value, void *data) =20 if (STRPREFIX(name, "lxc.network.")) return lxcNetworkParseDataEntryLegacy(name, value, networks); + if (STRPREFIX(name, "lxc.net.")) + return lxcNetworkParseDataEntry(name, value, networks); =20 return 0; } --=20 2.20.1