From nobody Thu Dec 26 19:38:13 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706821557997784.3185452405161; Thu, 1 Feb 2024 13:05:57 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id E1A811D10; Thu, 1 Feb 2024 16:05:56 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 0F9C71D66; Thu, 1 Feb 2024 16:03:46 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id E2F101D48; Thu, 1 Feb 2024 16:03:34 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 40C7A1D0D for ; Thu, 1 Feb 2024 16:03:03 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-bDylM7-3OIez5On0_GAgvw-1; Thu, 01 Feb 2024 16:03:01 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3FC6C28B6ABC for ; Thu, 1 Feb 2024 21:03:00 +0000 (UTC) Received: from orkuz (unknown [10.45.226.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00C9EC259DD for ; Thu, 1 Feb 2024 21:02:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: bDylM7-3OIez5On0_GAgvw-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [libvirt PATCH 1/7] util: Refactor virSystemdHas{Machined,Logind} Date: Thu, 1 Feb 2024 22:02:43 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: LVDEZCRESL4JKD4WWK2UQS2PXGUR2T44 X-Message-ID-Hash: LVDEZCRESL4JKD4WWK2UQS2PXGUR2T44 X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706821559300100001 To reduce code duplication both function now use a common virSystemdHasService helper. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/util/virsystemd.c | 76 ++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index cd4de0eef8..21892aca02 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -141,66 +141,62 @@ void virSystemdHasLogindResetCachedValue(void) } =20 =20 -/* -2 =3D machine1 is not supported on this machine - * -1 =3D error - * 0 =3D machine1 is available +/** + * virSystemdHasService: + * + * Check whether a DBus @service is enabled and either the service itself = or + * systemd1 service is registered. If @requireSystemd =3D=3D true, the sys= temd1 + * service has to be registered even if @service is registered. + * + * Returns + * -2 when service is not supported on this machine + * -1 on error + * 0 when service is available */ -int -virSystemdHasMachined(void) +static int +virSystemdHasService(const char *service, + bool requireSystemd, + int *cached) { int ret; int val; =20 - val =3D g_atomic_int_get(&virSystemdHasMachinedCachedValue); + val =3D g_atomic_int_get(cached); if (val !=3D -1) return val; =20 - if ((ret =3D virGDBusIsServiceEnabled("org.freedesktop.machine1")) < 0= ) { + if ((ret =3D virGDBusIsServiceEnabled(service)) < 0) { if (ret =3D=3D -2) - g_atomic_int_set(&virSystemdHasMachinedCachedValue, -2); + g_atomic_int_set(cached, -2); return ret; } =20 - if ((ret =3D virGDBusIsServiceRegistered("org.freedesktop.systemd1")) = =3D=3D -1) + if ((ret =3D virGDBusIsServiceRegistered(service)) =3D=3D -1) return ret; - g_atomic_int_set(&virSystemdHasMachinedCachedValue, ret); + + if (requireSystemd || ret =3D=3D -2) { + if ((ret =3D virGDBusIsServiceRegistered("org.freedesktop.systemd1= ")) =3D=3D -1) + return ret; + } + + g_atomic_int_set(cached, ret); return ret; } =20 + int -virSystemdHasLogind(void) +virSystemdHasMachined(void) { - int ret; - int val; - - val =3D g_atomic_int_get(&virSystemdHasLogindCachedValue); - if (val !=3D -1) - return val; - - ret =3D virGDBusIsServiceEnabled("org.freedesktop.login1"); - if (ret < 0) { - if (ret =3D=3D -2) - g_atomic_int_set(&virSystemdHasLogindCachedValue, -2); - return ret; - } - - /* - * Want to use logind if: - * - logind is already running - * Or - * - logind is not running, but this is a systemd host - * (rely on dbus activation) - */ - if ((ret =3D virGDBusIsServiceRegistered("org.freedesktop.login1")) = =3D=3D -1) - return ret; + return virSystemdHasService("org.freedesktop.machine1", true, + &virSystemdHasMachinedCachedValue); +} =20 - if (ret =3D=3D -2) { - if ((ret =3D virGDBusIsServiceRegistered("org.freedesktop.systemd1= ")) =3D=3D -1) - return ret; - } =20 - g_atomic_int_set(&virSystemdHasLogindCachedValue, ret); - return ret; +int +virSystemdHasLogind(void) +{ + return virSystemdHasService("org.freedesktop.login1", false, + &virSystemdHasLogindCachedValue); } =20 =20 --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu Dec 26 19:38:13 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706821651720296.5797758523055; Thu, 1 Feb 2024 13:07:31 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 645321CD3; Thu, 1 Feb 2024 16:07:30 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2B0111CEC; Thu, 1 Feb 2024 16:03:54 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3623E1C98; Thu, 1 Feb 2024 16:03:37 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 879961D60 for ; Thu, 1 Feb 2024 16:03:07 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-398-U_N6IdWwNlmKFLs5kMcPHw-1; Thu, 01 Feb 2024 16:03:05 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5DF36101A526 for ; Thu, 1 Feb 2024 21:03:05 +0000 (UTC) Received: from orkuz (unknown [10.45.226.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 200232166B34 for ; Thu, 1 Feb 2024 21:03:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: U_N6IdWwNlmKFLs5kMcPHw-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [libvirt PATCH 2/7] util: Introduce virSystemdHasResolved Date: Thu, 1 Feb 2024 22:02:44 +0100 Message-ID: <95552f3ef82923dd8e14cbb62c363c4accad6504.1706821238.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: NWA6EZW3IF56NN4YAU5QXN42IDK6SBEY X-Message-ID-Hash: NWA6EZW3IF56NN4YAU5QXN42IDK6SBEY X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706821653717100001 Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 2 ++ src/util/virsystemd.c | 15 +++++++++++++++ src/util/virsystemd.h | 2 ++ src/util/virsystemdpriv.h | 1 + 4 files changed, 20 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2ebc0de212..6b4fe17e20 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3479,6 +3479,8 @@ virSystemdHasLogind; virSystemdHasLogindResetCachedValue; virSystemdHasMachined; virSystemdHasMachinedResetCachedValue; +virSystemdHasResolved; +virSystemdHasResolvedResetCachedValue; virSystemdMakeScopeName; virSystemdMakeSliceName; virSystemdNotifyStartup; diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 21892aca02..0dfc4398d0 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -127,6 +127,7 @@ char *virSystemdMakeSliceName(const char *partition) =20 static int virSystemdHasMachinedCachedValue =3D -1; static int virSystemdHasLogindCachedValue =3D -1; +static int virSystemdHasResolvedCachedValue =3D -1; =20 /* Reset the cache from tests for testing the underlying dbus calls * as well */ @@ -140,6 +141,12 @@ void virSystemdHasLogindResetCachedValue(void) virSystemdHasLogindCachedValue =3D -1; } =20 +void +virSystemdHasResolvedResetCachedValue(void) +{ + virSystemdHasResolvedCachedValue =3D -1; +} + =20 /** * virSystemdHasService: @@ -200,6 +207,14 @@ virSystemdHasLogind(void) } =20 =20 +int +virSystemdHasResolved(void) +{ + return virSystemdHasService("org.freedesktop.resolve1", false, + &virSystemdHasResolvedCachedValue); +} + + /** * virSystemdGetMachineByPID: * @conn: dbus connection diff --git a/src/util/virsystemd.h b/src/util/virsystemd.h index 19fb714132..65add8b5b9 100644 --- a/src/util/virsystemd.h +++ b/src/util/virsystemd.h @@ -49,6 +49,8 @@ int virSystemdHasMachined(void); =20 int virSystemdHasLogind(void); =20 +int virSystemdHasResolved(void); + int virSystemdCanSuspend(bool *result); =20 int virSystemdCanHibernate(bool *result); diff --git a/src/util/virsystemdpriv.h b/src/util/virsystemdpriv.h index 736c53d3fa..1f1dda456c 100644 --- a/src/util/virsystemdpriv.h +++ b/src/util/virsystemdpriv.h @@ -29,3 +29,4 @@ =20 void virSystemdHasMachinedResetCachedValue(void); void virSystemdHasLogindResetCachedValue(void); +void virSystemdHasResolvedResetCachedValue(void); --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu Dec 26 19:38:13 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706821754573110.78417088107585; Thu, 1 Feb 2024 13:09:14 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8AC5D1D0C; Thu, 1 Feb 2024 16:09:13 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 7DD4B1DA7; Thu, 1 Feb 2024 16:04:03 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id B385D1CAA; Thu, 1 Feb 2024 16:03:48 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id D79E51C9A for ; Thu, 1 Feb 2024 16:03:12 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-128-NEjKMZGWOHCb3VmHRjYytA-1; Thu, 01 Feb 2024 16:03:10 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 89F4B85A588 for ; Thu, 1 Feb 2024 21:03:10 +0000 (UTC) Received: from orkuz (unknown [10.45.226.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4290D1C060B1 for ; Thu, 1 Feb 2024 21:03:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: NEjKMZGWOHCb3VmHRjYytA-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [libvirt PATCH 3/7] util: Introduce virSocketAddrBytes Date: Thu, 1 Feb 2024 22:02:45 +0100 Message-ID: <8114954ba25f31db5160dc42c077162ea9691d66.1706821238.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: TUWK3AR3HZVTIMIDUBBISCIXQWU67IEZ X-Message-ID-Hash: TUWK3AR3HZVTIMIDUBBISCIXQWU67IEZ X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706821756018100001 Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 + src/util/virsocketaddr.c | 63 ++++++++++++++++++++++++++++++++++++++++ src/util/virsocketaddr.h | 4 +++ 3 files changed, 68 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6b4fe17e20..0be273511d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3368,6 +3368,7 @@ virSocketSendFD; # util/virsocketaddr.h virSocketAddrBroadcast; virSocketAddrBroadcastByPrefix; +virSocketAddrBytes; virSocketAddrCheckNetmask; virSocketAddrEqual; virSocketAddrFormat; diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index fbda858cfe..0a1ae1ac5f 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -30,6 +30,7 @@ */ typedef unsigned char virSocketAddrIPv4[4]; typedef unsigned short virSocketAddrIPv6[8]; +typedef unsigned char virSocketAddrIPv6Bytes[16]; typedef unsigned char virSocketAddrIPv6Nibbles[32]; =20 static int @@ -68,6 +69,23 @@ virSocketAddrGetIPv6Addr(const virSocketAddr *addr, virS= ocketAddrIPv6 *tab) return 0; } =20 + +static int +virSocketAddrGetIPv6Bytes(const virSocketAddr *addr, + virSocketAddrIPv6Bytes *tab) +{ + size_t i; + + if (!addr || !tab || addr->data.stor.ss_family !=3D AF_INET6) + return -1; + + for (i =3D 0; i < 16; i++) + (*tab)[i] =3D addr->data.inet6.sin6_addr.s6_addr[i]; + + return 0; +} + + static int virSocketAddrGetIPv6Nibbles(const virSocketAddr *addr, virSocketAddrIPv6Nibbles *tab) @@ -1331,6 +1349,51 @@ virSocketAddrPTRDomain(const virSocketAddr *addr, return 0; } =20 + +/** + * virSocketAddrBytes: + * @addr: address to convert to byte array + * @bytes: a preallocated array to store the address bytes to + * @maxBytes: the size of @bytes + * + * Extracts individual bytes of an IPv4 or IPv6 address in the provided @b= ytes + * array, which should be large enough to store 16 bytes (the size of an I= Pv6 + * address). Bytes are stored in network order. + * + * Returns the number of bytes stored in @bytes on success or 0 when @bytes + * array is not big enough or @addr is not IPv4 or IPv6. + */ +int +virSocketAddrBytes(const virSocketAddr *addr, + unsigned char *bytes, + int maxBytes) +{ + if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET6)) { + virSocketAddrIPv6Bytes ip; + + if (maxBytes < sizeof(ip)) + return 0; + + virSocketAddrGetIPv6Bytes(addr, &ip); + memcpy(bytes, ip, sizeof(ip)); + return sizeof(ip); + } + + if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET)) { + virSocketAddrIPv4 ip; + + if (maxBytes < sizeof(ip)) + return 0; + + virSocketAddrGetIPv4Addr(addr, &ip); + memcpy(bytes, ip, sizeof(ip)); + return sizeof(ip); + } + + return 0; +} + + void virSocketAddrFree(virSocketAddr *addr) { diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h index ec265d6e44..47b8effa85 100644 --- a/src/util/virsocketaddr.h +++ b/src/util/virsocketaddr.h @@ -143,6 +143,10 @@ int virSocketAddrPTRDomain(const virSocketAddr *addr, char **ptr) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); =20 +int virSocketAddrBytes(const virSocketAddr *addr, + unsigned char *bytes, + int maxBytes); + void virSocketAddrFree(virSocketAddr *addr); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSocketAddr, virSocketAddrFree); --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu Dec 26 19:38:13 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706821858385455.8344804409128; Thu, 1 Feb 2024 13:10:58 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1BC9A1DDB; Thu, 1 Feb 2024 16:10:57 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5A2FB1D92; Thu, 1 Feb 2024 16:04:12 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2271D1D0F; Thu, 1 Feb 2024 16:03:57 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 48EE01CFD for ; Thu, 1 Feb 2024 16:03:18 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-eyXVpcUvOiCwV7a_WXRqRg-1; Thu, 01 Feb 2024 16:03:16 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id AB23F28B6AB4 for ; Thu, 1 Feb 2024 21:03:15 +0000 (UTC) Received: from orkuz (unknown [10.45.226.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D8B8C259DD for ; Thu, 1 Feb 2024 21:03:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: eyXVpcUvOiCwV7a_WXRqRg-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [libvirt PATCH 4/7] util: Introduce virSystemdResolvedRegisterNameServer Date: Thu, 1 Feb 2024 22:02:46 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: WRTOHXRF7GGR6B67BUINAR5QVGVQ5BTK X-Message-ID-Hash: WRTOHXRF7GGR6B67BUINAR5QVGVQ5BTK X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706821860559100001 Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 + src/util/virsystemd.c | 79 +++++++++++++++++++++++++++++++++++++++- src/util/virsystemd.h | 5 +++ 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0be273511d..d8c566b458 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3485,6 +3485,7 @@ virSystemdHasResolvedResetCachedValue; virSystemdMakeScopeName; virSystemdMakeSliceName; virSystemdNotifyStartup; +virSystemdResolvedRegisterNameServer; virSystemdTerminateMachine; =20 =20 diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 0dfc4398d0..68699929d3 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -34,7 +34,6 @@ #include "virerror.h" #include "virfile.h" #include "virhash.h" -#include "virsocketaddr.h" =20 #define VIR_FROM_THIS VIR_FROM_SYSTEMD =20 @@ -1042,3 +1041,81 @@ virSystemdActivationFree(virSystemdActivation *act) =20 g_free(act); } + + +/** + * virSystemdResolvedRegisterNameServer: + * @link: network interface ID + * @domain: registered domain + * @addr: address the DNS server is listening on + * + * Talk to systemd-resolved and register a DNS server listening on @addr + * as a resolver for @domain. This configuration is bound to @link interfa= ce + * and automatically dropped when the interface goes away. + * + * Returns -2 when systemd-resolved is unavailable, + * -1 on error, + * 0 on success. + */ +int +virSystemdResolvedRegisterNameServer(int link, + const char *domain, + virSocketAddr *addr) +{ + int rc; + GDBusConnection *conn; + GVariant *params; + GVariant *byteArray; + unsigned char addrBytes[16]; + int nBytes; + + if ((rc =3D virSystemdHasResolved()) < 0) + return rc; + + if (!(conn =3D virGDBusGetSystemBus())) + return -1; + + /* + * SetLinkDomains(in i ifindex, + * in a(sb) domains); + */ + params =3D g_variant_new_parsed("(%i, [(%s, true)])", + (gint32) link, + domain); + + rc =3D virGDBusCallMethod(conn, NULL, NULL, NULL, + "org.freedesktop.resolve1", + "/org/freedesktop/resolve1", + "org.freedesktop.resolve1.Manager", + "SetLinkDomains", + params); + g_variant_unref(params); + + if (rc < 0) + return -1; + + /* + * SetLinkDNS(in i ifindex, + * in a(iay) addresses); + */ + nBytes =3D virSocketAddrBytes(addr, addrBytes, sizeof(addrBytes)); + byteArray =3D g_variant_new_fixed_array(G_VARIANT_TYPE("y"), + addrBytes, nBytes, 1); + params =3D g_variant_new_parsed("(%i, [(%i, %@ay)])", + (gint32) link, + VIR_SOCKET_ADDR_FAMILY(addr), + byteArray); + + rc =3D virGDBusCallMethod(conn, NULL, NULL, NULL, + "org.freedesktop.resolve1", + "/org/freedesktop/resolve1", + "org.freedesktop.resolve1.Manager", + "SetLinkDNS", + params); + g_variant_unref(params); + + if (rc < 0) + return -1; + + return 0; +} diff --git a/src/util/virsystemd.h b/src/util/virsystemd.h index 65add8b5b9..b7fdaf67df 100644 --- a/src/util/virsystemd.h +++ b/src/util/virsystemd.h @@ -22,6 +22,7 @@ #pragma once =20 #include "internal.h" +#include "virsocketaddr.h" =20 typedef struct _virSystemdActivation virSystemdActivation; =20 @@ -76,3 +77,7 @@ void virSystemdActivationClaimFDs(virSystemdActivation *a= ct, void virSystemdActivationFree(virSystemdActivation *act); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSystemdActivation, virSystemdActivationFr= ee); + +int virSystemdResolvedRegisterNameServer(int link, + const char *domain, + virSocketAddr *addr); --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu Dec 26 19:38:13 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706822014321674.5762287269645; Thu, 1 Feb 2024 13:13:34 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 450481D22; Thu, 1 Feb 2024 16:13:33 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 6328C1DB8; Thu, 1 Feb 2024 16:04:32 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2EDFF1D0C; Thu, 1 Feb 2024 16:04:20 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id CFA631CF3 for ; Thu, 1 Feb 2024 16:03:21 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-284-qJRnNlwWMJ24cnL-tRi_0w-1; Thu, 01 Feb 2024 16:03:20 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id C65503C0BE4D for ; Thu, 1 Feb 2024 21:03:19 +0000 (UTC) Received: from orkuz (unknown [10.45.226.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8804F2026D66 for ; Thu, 1 Feb 2024 21:03:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: qJRnNlwWMJ24cnL-tRi_0w-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [libvirt PATCH 5/7] tests: Add tests for virSystemdResolvedRegisterNameServer Date: Thu, 1 Feb 2024 22:02:47 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: JVSEDT5SESIVIGVGZNUMFBP7G356EO2U X-Message-ID-Hash: JVSEDT5SESIVIGVGZNUMFBP7G356EO2U X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706822015069100001 Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- tests/virsystemdtest.c | 147 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index fcd76514e1..004b0549ce 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -87,6 +87,34 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, reply =3D g_variant_new("()"); } } + } else if (STREQ(bus_name, "org.freedesktop.resolve1")) { + g_autofree char *actual =3D NULL; + + if (getenv("FAIL_BAD_SERVICE")) { + *error =3D g_dbus_error_new_for_dbus_error("org.freedesktop.sy= stemd.badthing", + "Contacting resolved = failed"); + } else if (STREQ(method_name, "SetLinkDomains")) { + const char *expected =3D getenv("TEST_RESOLVED_LINK_DOMAINS"); + actual =3D g_variant_print(params, FALSE); + + if (virTestCompareToString(expected, actual) < 0) + *error =3D g_dbus_error_new_for_dbus_error("org.freedeskto= p.systemd.badthing", + "Unexpected param= s to SetLinkDomains"); + else + reply =3D g_variant_new("()"); + } else if (STREQ(method_name, "SetLinkDNS")) { + const char *expected =3D getenv("TEST_RESOLVED_LINK_DNS"); + actual =3D g_variant_print(params, FALSE); + + if (virTestCompareToString(expected, actual) < 0) + *error =3D g_dbus_error_new_for_dbus_error("org.freedeskto= p.systemd.badthing", + "Unexpected param= s to SetLinkDNS"); + else + reply =3D g_variant_new("()"); + } else { + *error =3D g_dbus_error_new_for_dbus_error("org.freedesktop.sy= stemd.badthing", + "Unknown resolved met= hod"); + } } else if (STREQ(bus_name, "org.freedesktop.login1")) { reply =3D g_variant_new("(s)", getenv("RESULT_SUPPORT")); } else if (STREQ(bus_name, "org.freedesktop.DBus") && @@ -100,6 +128,7 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, if (!getenv("FAIL_NO_SERVICE")) { g_variant_builder_add(&builder, "s", "org.freedesktop.machine1= "); g_variant_builder_add(&builder, "s", "org.freedesktop.login1"); + g_variant_builder_add(&builder, "s", "org.freedesktop.resolve1= "); } =20 reply =3D g_variant_new("(@as)", g_variant_builder_end(&builder)); @@ -114,6 +143,7 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, if (!getenv("FAIL_NO_SERVICE") && !getenv("FAIL_NOT_REGISTERED")) { g_variant_builder_add(&builder, "s", "org.freedesktop.systemd1= "); g_variant_builder_add(&builder, "s", "org.freedesktop.login1"); + g_variant_builder_add(&builder, "s", "org.freedesktop.resolve1= "); } =20 reply =3D g_variant_new("(@as)", g_variant_builder_end(&builder)); @@ -613,6 +643,83 @@ testActivationEmpty(const void *opaque G_GNUC_UNUSED) return 0; } =20 + +struct testResolvedData { + int link; + const char *env; + const char *dom; + const char *addr; + const char *expDomains; + const char *expDNS; +}; + + +static int +testResolvedFailed(const void *opaque) +{ + const struct testResolvedData *data =3D opaque; + virSocketAddr addr =3D {0}; + int ret =3D -1; + int expected =3D -2; + int rv; + + if (!data->env) { + fprintf(stderr, "%s", + "testResolvedFailed called without environment variable na= me"); + return -1; + } + + if (data->addr && + virSocketAddrParse(&addr, data->addr, AF_UNSPEC) < 0) + return -1; + + if (STREQ(data->env, "FAIL_BAD_SERVICE")) + expected =3D -1; + + g_setenv(data->env, "1", TRUE); + + rv =3D virSystemdResolvedRegisterNameServer(data->link, data->dom, &ad= dr); + + if (rv =3D=3D 0) + fprintf(stderr, "%s", "Updating resolved succeeded unexpectedly\n"= ); + else if (rv !=3D expected) + fprintf(stderr, "%s", "Updating resolved failed unexpectedly\n"); + else + ret =3D 0; + + g_unsetenv(data->env); + return ret; +} + + +static int +testResolved(const void *opaque) +{ + const struct testResolvedData *data =3D opaque; + virSocketAddr addr =3D {0}; + int ret =3D -1; + + if (data->addr && + virSocketAddrParse(&addr, data->addr, AF_UNSPEC) < 0) + return -1; + + g_setenv("TEST_RESOLVED_LINK_DOMAINS", data->expDomains, TRUE); + g_setenv("TEST_RESOLVED_LINK_DNS", data->expDNS, TRUE); + + if (virSystemdResolvedRegisterNameServer(data->link, data->dom, &addr)= < 0) { + fprintf(stderr, "%s", "Updating resolved failed unexpectedly\n"); + goto cleanup; + } + + ret =3D 0; + + cleanup: + g_unsetenv("TEST_RESOLVED_LINK_DOMAINS"); + g_unsetenv("TEST_RESOLVED_LINK_DNS"); + return ret; +} + + static int mymain(void) { @@ -732,6 +839,46 @@ mymain(void) VIR_INFO("Skipping activation tests as FD 3/4/5 is open"); } =20 +# define TEST_RESOLVED_HELPER(name, func, linkId, variable, domain, ip, \ + expectedDomains, expectedDNS) \ + do { \ + struct testResolvedData data =3D { \ + .link =3D linkId, \ + .env =3D variable, \ + .dom =3D domain, \ + .addr =3D ip, \ + .expDomains =3D expectedDomains, \ + .expDNS =3D expectedDNS, \ + }; \ + if (virTestRun("Test resolved " name, func, &data) < 0) \ + ret =3D -1; \ + virSystemdHasResolvedResetCachedValue(); \ + } while (0) + +# define TEST_RESOLVED_FAILURE(name, variable, ip) \ + TEST_RESOLVED_HELPER(name, testResolvedFailed, 42, variable, "virt", i= p, NULL, NULL) + +# define TEST_RESOLVED_EXP(name, linkId, domain, ip, ipFamily, ipBytes) \ + TEST_RESOLVED_HELPER(name, testResolved, linkId, NULL, domain, ip, \ + "(" #linkId ", [('" domain "', true)])", \ + "(" #linkId ", [(" #ipFamily ", [" ipBytes "])])") + +# define TEST_RESOLVED(name, linkId, domain, ip, ipFamily, ipBytes) \ + TEST_RESOLVED_EXP(name, linkId, domain, ip, ipFamily, ipBytes) + + TEST_RESOLVED_FAILURE("not enabled", "FAIL_NO_SERVICE", NULL); + TEST_RESOLVED_FAILURE("not registered", "FAIL_NOT_REGISTERED", NULL); + TEST_RESOLVED_FAILURE("bad service", "FAIL_BAD_SERVICE", "1.2.3.4"); + + TEST_RESOLVED("IPv4", 84, "private", + "172.17.18.19", AF_INET, + "0xac, 0x11, 0x12, 0x13"); + + TEST_RESOLVED("IPv6", 21, "virt.local", + "e8f7:ae03:b089:d4e1:764a:53ec:658b:2547", AF_INET6, + "0xe8, 0xf7, 0xae, 0x03, 0xb0, 0x89, 0xd4, 0xe1, " + "0x76, 0x4a, 0x53, 0xec, 0x65, 0x8b, 0x25, 0x47"); + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu Dec 26 19:38:13 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 170682213758323.600431685871854; Thu, 1 Feb 2024 13:15:37 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 7471FAD3; Thu, 1 Feb 2024 16:15:36 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 90A7E1DB7; Thu, 1 Feb 2024 16:04:41 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 58ADC1D0C; Thu, 1 Feb 2024 16:04:20 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id A07D61D2F for ; Thu, 1 Feb 2024 16:03:26 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-440-RaE_9xKlN-izWQqliXBPYg-1; Thu, 01 Feb 2024 16:03:25 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id C27921C54021 for ; Thu, 1 Feb 2024 21:03:24 +0000 (UTC) Received: from orkuz (unknown [10.45.226.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 859AE1C060AF for ; Thu, 1 Feb 2024 21:03:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: RaE_9xKlN-izWQqliXBPYg-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [libvirt PATCH 6/7] network: Make virtual domains resolvable from the host Date: Thu, 1 Feb 2024 22:02:48 +0100 Message-ID: <7041571b31781ad1d4623d5c3fd4f8c16a2c6798.1706821238.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: SVZ4N7ZNEFIZCG47MDEJXCGXALVLFGYG X-Message-ID-Hash: SVZ4N7ZNEFIZCG47MDEJXCGXALVLFGYG X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706822138228100001 This patch adds a new attribute "register" to the element. If set to "yes", the DNS server created for the virtual network is registered with systemd-resolved as a name server for the associated domain. The names known to the dnsmasq process serving DNS and DHCP requests for the virtual network will then be resolvable from the host by appending the domain name to them. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- docs/formatnetwork.rst | 9 ++++++++- src/conf/network_conf.c | 18 ++++++++++++++++++ src/conf/network_conf.h | 1 + src/conf/schemas/network.rng | 3 +++ src/network/bridge_driver.c | 32 +++++++++++++++++++++++++++++++- 5 files changed, 61 insertions(+), 2 deletions(-) diff --git a/docs/formatnetwork.rst b/docs/formatnetwork.rst index 16e81246fa..dcdaf1e5a5 100644 --- a/docs/formatnetwork.rst +++ b/docs/formatnetwork.rst @@ -88,7 +88,7 @@ to the physical LAN (if at all). ... - + ... =20 @@ -162,6 +162,13 @@ to the physical LAN (if at all). DNS server. If ``localOnly`` is "no", and by default, unresolved reques= ts **will** be forwarded. :since:`Since 1.2.12` =20 + :since:`Since 10.1.0` the optional ``register`` attribute can be used to + request registering the DNS server for resolving this domain with the h= ost's + DNS resolver. When set to "yes", the host resolver will forward all req= uests + for domain names from this domain to the DNS server created for this vi= rtual + network. To avoid DNS loops ``localOnly`` has to be set to "yes" as wel= l. + This feature requires ``systemd-resolved`` to be running on the host. + ``forward`` Inclusion of the ``forward`` element indicates that the virtual network= is to be connected to the physical LAN. :since:`Since 0.3.0.` The ``mode`` diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index ef3415cd89..cc92ed0b03 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1582,6 +1582,19 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt, &def->domainLocalOnly) < 0) return NULL; =20 + if (virXMLPropTristateBool(domain_node, "register", + VIR_XML_PROP_NONE, + &def->domainRegister) < 0) + return NULL; + + if (def->domainRegister =3D=3D VIR_TRISTATE_BOOL_YES && + def->domainLocalOnly !=3D VIR_TRISTATE_BOOL_YES) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("attribute 'register=3Dyes' in element r= equires 'localOnly=3Dyes' in network %1$s"), + def->name); + return NULL; + } + if ((bandwidthNode =3D virXPathNode("./bandwidth", ctxt)) && virNetDevBandwidthParse(&def->bandwidth, NULL, bandwidthNode, fals= e) < 0) return NULL; @@ -2405,6 +2418,11 @@ virNetworkDefFormatBuf(virBuffer *buf, virBufferAsprintf(buf, " localOnly=3D'%s'", local); } =20 + if (def->domainRegister) { + virBufferAsprintf(buf, " register=3D'%s'", + virTristateBoolTypeToString(def->domainRegis= ter)); + } + virBufferAddLit(buf, "/>\n"); } =20 diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 1d7fd3ab6a..c2a4198abc 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -245,6 +245,7 @@ struct _virNetworkDef { int macTableManager; /* enum virNetworkBridgeMACTableManager */ char *domain; virTristateBool domainLocalOnly; /* yes disables dns forwarding */ + virTristateBool domainRegister; unsigned long delay; /* Bridge forward delay (ms) */ bool stp; /* Spanning tree protocol */ unsigned int mtu; /* MTU for bridge, 0 means "default" i.e. unset in c= onfig */ diff --git a/src/conf/schemas/network.rng b/src/conf/schemas/network.rng index e56e07d130..b7c8551fad 100644 --- a/src/conf/schemas/network.rng +++ b/src/conf/schemas/network.rng @@ -258,6 +258,9 @@ + + + =20 diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 9921c7cd14..d89700c6ee 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -63,7 +63,7 @@ #include "virjson.h" #include "virnetworkportdef.h" #include "virutil.h" - +#include "virsystemd.h" #include "netdev_bandwidth_conf.h" =20 #define VIR_FROM_THIS VIR_FROM_NETWORK @@ -1902,6 +1902,7 @@ networkStartNetworkVirtual(virNetworkDriverState *dri= ver, bool dnsmasqStarted =3D false; bool devOnline =3D false; bool firewalRulesAdded =3D false; + virSocketAddr *dnsServer =3D NULL; =20 /* Check to see if any network IP collides with an existing route */ if (networkCheckRouteCollision(def) < 0) @@ -1958,6 +1959,9 @@ networkStartNetworkVirtual(virNetworkDriverState *dri= ver, if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET6)) v6present =3D true; =20 + if (!dnsServer) + dnsServer =3D &ipdef->address; + /* Add the IP address/netmask to the bridge */ if (networkAddAddrToBridge(obj, ipdef) < 0) goto error; @@ -2011,6 +2015,32 @@ networkStartNetworkVirtual(virNetworkDriverState *dr= iver, goto error; =20 dnsmasqStarted =3D true; + + if (def->domain && def->domainRegister && dnsServer) { + unsigned int link; + int rc; + + if ((link =3D if_nametoindex(def->bridge)) =3D=3D 0) { + virReportSystemError(ENODEV, + _("unable to get interface index for = %1$s"), + def->bridge); + goto error; + } + + rc =3D virSystemdResolvedRegisterNameServer(link, def->domain, + dnsServer); + if (rc =3D=3D -2) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("failed to register name server: systemd-= resolved is not available")); + goto error; + } + + if (rc < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to register name server")); + goto error; + } + } } =20 if (virNetDevBandwidthSet(def->bridge, def->bandwidth, true, true) < 0) --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu Dec 26 19:38:13 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706822201377216.94242851196623; Thu, 1 Feb 2024 13:16:41 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3CC111D63; Thu, 1 Feb 2024 16:16:40 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 7102C1D29; Thu, 1 Feb 2024 16:04:50 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9E8201D5E; Thu, 1 Feb 2024 16:04:34 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id D12411D4C for ; Thu, 1 Feb 2024 16:03:30 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-34-aXrmeqZ9OQeqpRBMfswRdA-1; Thu, 01 Feb 2024 16:03:29 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id D95F2887127 for ; Thu, 1 Feb 2024 21:03:28 +0000 (UTC) Received: from orkuz (unknown [10.45.226.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C0232026D66 for ; Thu, 1 Feb 2024 21:03:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: aXrmeqZ9OQeqpRBMfswRdA-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [libvirt PATCH 7/7] NEWS: Mention systemd-resolved support in network driver Date: Thu, 1 Feb 2024 22:02:49 +0100 Message-ID: <0f92e108a22a83a9d5fee360e766efdf97090035.1706821238.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: P4OF7J5VCXGSY26TF7ZQ7WBRGXYISLNP X-Message-ID-Hash: P4OF7J5VCXGSY26TF7ZQ7WBRGXYISLNP X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706822202134100001 Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- NEWS.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index e2796fd8b2..15b0da31b6 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -23,6 +23,13 @@ v10.1.0 (unreleased) Additionally, if CPU clusters are present in the host topology, they w= ill be reported as part of the capabilities XML. =20 + * network: Make virtual domains resolvable from the host + + When starting a virtual network with a new ``register=3D'yes'`` attrib= ute + in the ```` element, libvirt will configure ``systemd-resolved= `` + to resolve names of the connected guests using the name server started + for this network. + * **Improvements** =20 * **Bug fixes** --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org