From nobody Mon Feb 9 03:45:53 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1580263024765218.2945746466803; Tue, 28 Jan 2020 17:57:04 -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-7-q8JUpvBdO4ugaqtaYybdhg-1; Tue, 28 Jan 2020 20:57:01 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AA78A107ACC9; Wed, 29 Jan 2020 01:56:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8181C7C42C; Wed, 29 Jan 2020 01:56:55 +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 0D00F18089C8; Wed, 29 Jan 2020 01:56:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00T1uc2w012652 for ; Tue, 28 Jan 2020 20:56:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0229180894; Wed, 29 Jan 2020 01:56:38 +0000 (UTC) Received: from mimecast-mx01.redhat.com (mimecast01.extmail.prod.ext.phx2.redhat.com [10.5.110.50]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F01787C42C for ; Wed, 29 Jan 2020 01:56:35 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 57AC11005510 for ; Wed, 29 Jan 2020 01:56:35 +0000 (UTC) Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-169-CRjdRKpgP8WSzBdfmbkcrQ-1; Tue, 28 Jan 2020 20:54:25 -0500 Received: by mail-qv1-f68.google.com with SMTP id n8so7264489qvg.11; Tue, 28 Jan 2020 17:54:25 -0800 (PST) Received: from localhost.localdomain ([2804:431:c7cb:c3b5:59b3:4b4:e00c:2a48]) by smtp.gmail.com with ESMTPSA id t15sm198798qkg.49.2020.01.28.17.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2020 17:54:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580263023; 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=O1M8k+gbmSLWvCHXvzcmGhW9LqkgBrfykI0wV09IrNI=; b=NpXdHgkrpqiG9d0F7ZY1X+m9ZSqIiJZFwMedAwshp0VcEzB83cx5BHM0ZPWgto+tiwlYzA daU/fnE7qIqwnfjypxrDu3NvYteTfycMpSNvccd9zB2k9KOr+GVLNGkvIXR3EesiAGsmEU 5cufa5TNkiIYWGHm3JSyWCDETwp0bc4= 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=BrlWnwIpbFQngLUylsZYyiJ4B5UdaQNHWCY2R1gAjwg=; b=ooWg5nVaW1By8ehBDHJyK4VHtWqY0VS6c4GuVA6LYXFhMe3G0jbElGMzaJ2v94qcS3 zp525v+2H+8JwvR7zpE/MDqD8cVCb2vOwcUi/WXCFGQfLkwYhHrd0zzISlMZWxzU4JbH uqVsoIF/ugHnkhzegKskjZTRinE8HfM0V9/4W+LyQcyzbTDaE3RJdPSogeKhQTp7lInn K3Pr4ctCWgah+HpMsUkID5yAgHdAThVwdKI4N45kZhnB1fO02WcFeec3N67XRlE9JX8Z QsKotaZRgMJuANXtsX75FPYzsnxKsFmWP+ogkh/c2saNQxZR1jlM8E5AKRiaK/mPE8N/ MNww== X-Gm-Message-State: APjAAAWYmQ802/CalbxIfjkt0i6q+UFnfBDBNQG4n36O93kIrDiC41V0 ifAZuNSbXJ+B3gLtscUM6cGfC5Z0 X-Google-Smtp-Source: APXvYqz95fHiPSOEhdpHQBVhPDm7pXU9M/JlK7eEiIm6H6vwAnwzC3eVdltogDAvPCrZpIjjWKn96w== X-Received: by 2002:ad4:4434:: with SMTP id e20mr25819457qvt.157.1580262864602; Tue, 28 Jan 2020 17:54:24 -0800 (PST) From: Julio Faracco To: libvir-list@redhat.com Subject: [PATCH v3 2/4] lxc: add LXC version 3 network parser Date: Tue, 28 Jan 2020 22:54:09 -0300 Message-Id: <20200129015411.11701-3-jcfaracco@gmail.com> In-Reply-To: <20200129015411.11701-1-jcfaracco@gmail.com> References: <20200129015411.11701-1-jcfaracco@gmail.com> MIME-Version: 1.0 X-MC-Unique: CRjdRKpgP8WSzBdfmbkcrQ-1 X-MC-Unique: q8JUpvBdO4ugaqtaYybdhg-1 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 00T1uc2w012652 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.79 on 10.5.11.15 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..35ac05f702 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."); + g_autofree 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