From nobody Thu Dec 26 18:28:48 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 1707142688906612.4270956725891; Mon, 5 Feb 2024 06:18:08 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id C72301DC4; Mon, 5 Feb 2024 09:18:07 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id EA0B31C9F; Mon, 5 Feb 2024 09:14:50 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 5342B187E; Mon, 5 Feb 2024 09:14:22 -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 6A08E187A for ; Mon, 5 Feb 2024 09:14: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-444-AS2yOqdDPMWHkWil-Vzg4Q-1; Mon, 05 Feb 2024 09:14:19 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 542A738562C8 for ; Mon, 5 Feb 2024 14:14:19 +0000 (UTC) Received: from orkuz (unknown [10.43.3.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 183C31121312 for ; Mon, 5 Feb 2024 14:14:18 +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: AS2yOqdDPMWHkWil-Vzg4Q-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [libvirt PATCH v2 1/7] util: Unify virSystemdHas{Machined,Logind} Date: Mon, 5 Feb 2024 15:14:08 +0100 Message-ID: <7b1f6f9972dd48e2476bb4960e15d5c841c68068.1707142194.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 3YJXP3CYNMYDUG3N4J2J3DHRREOQGGBU X-Message-ID-Hash: 3YJXP3CYNMYDUG3N4J2J3DHRREOQGGBU 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: 1707142689272100001 When checking for machined we do not really care whether systemd itself is running, we just need machined to be either running or socket activated by systemd. That is, exactly the same we do for logind. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/util/virsystemd.c | 74 ++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 40 deletions(-) diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index cd4de0eef8..36820e81fe 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -141,57 +141,35 @@ 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 = is + * running or will be started on demand by a running systemd1 service. + * + * Returns + * -2 when service is not supported on this machine + * -1 on error + * 0 when service is available */ -int -virSystemdHasMachined(void) -{ - int ret; - int val; - - val =3D g_atomic_int_get(&virSystemdHasMachinedCachedValue); - if (val !=3D -1) - return val; - - if ((ret =3D virGDBusIsServiceEnabled("org.freedesktop.machine1")) < 0= ) { - if (ret =3D=3D -2) - g_atomic_int_set(&virSystemdHasMachinedCachedValue, -2); - return ret; - } - - if ((ret =3D virGDBusIsServiceRegistered("org.freedesktop.systemd1")) = =3D=3D -1) - return ret; - g_atomic_int_set(&virSystemdHasMachinedCachedValue, ret); - return ret; -} - -int -virSystemdHasLogind(void) +static int +virSystemdHasService(const char *service, + int *cached) { int ret; int val; =20 - val =3D g_atomic_int_get(&virSystemdHasLogindCachedValue); + val =3D g_atomic_int_get(cached); if (val !=3D -1) return val; =20 - ret =3D virGDBusIsServiceEnabled("org.freedesktop.login1"); - if (ret < 0) { + if ((ret =3D virGDBusIsServiceEnabled(service)) < 0) { if (ret =3D=3D -2) - g_atomic_int_set(&virSystemdHasLogindCachedValue, -2); + g_atomic_int_set(cached, -2); return ret; } =20 - /* - * 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) + if ((ret =3D virGDBusIsServiceRegistered(service)) =3D=3D -1) return ret; =20 if (ret =3D=3D -2) { @@ -199,11 +177,27 @@ virSystemdHasLogind(void) return ret; } =20 - g_atomic_int_set(&virSystemdHasLogindCachedValue, ret); + g_atomic_int_set(cached, ret); return ret; } =20 =20 +int +virSystemdHasMachined(void) +{ + return virSystemdHasService("org.freedesktop.machine1", + &virSystemdHasMachinedCachedValue); +} + + +int +virSystemdHasLogind(void) +{ + return virSystemdHasService("org.freedesktop.login1", + &virSystemdHasLogindCachedValue); +} + + /** * virSystemdGetMachineByPID: * @conn: dbus connection --=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 18:28:48 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 1707142796558856.7567032703238; Mon, 5 Feb 2024 06:19:56 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 7347A1DA3; Mon, 5 Feb 2024 09:19:55 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 653771DED; Mon, 5 Feb 2024 09:15:13 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4352C1B44; Mon, 5 Feb 2024 09:14:23 -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 9FB2A185C for ; Mon, 5 Feb 2024 09:14:22 -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-587-AJ8YNq6HMg-_ft-uZLZkpg-1; Mon, 05 Feb 2024 09:14:20 -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 4736B185A780 for ; Mon, 5 Feb 2024 14:14:20 +0000 (UTC) Received: from orkuz (unknown [10.43.3.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B7AE1C060AF for ; Mon, 5 Feb 2024 14:14: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_H2,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: AJ8YNq6HMg-_ft-uZLZkpg-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [libvirt PATCH v2 2/7] util: Introduce virSystemdHasResolved Date: Mon, 5 Feb 2024 15:14:09 +0100 Message-ID: <33c9ca790930a1638f389a95c0d6bc9d3e8bdf77.1707142194.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: IQ7TQYWZ2UTTV34CF2BPL4J6WTDYF4Y5 X-Message-ID-Hash: IQ7TQYWZ2UTTV34CF2BPL4J6WTDYF4Y5 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: 1707142797810100001 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 c398371734..c336d06fb3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3489,6 +3489,8 @@ virSystemdHasLogind; virSystemdHasLogindResetCachedValue; virSystemdHasMachined; virSystemdHasMachinedResetCachedValue; +virSystemdHasResolved; +virSystemdHasResolvedResetCachedValue; virSystemdMakeScopeName; virSystemdMakeSliceName; virSystemdNotifyStartup; diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 36820e81fe..fd2b1db3ee 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: @@ -198,6 +205,14 @@ virSystemdHasLogind(void) } =20 =20 +int +virSystemdHasResolved(void) +{ + return virSystemdHasService("org.freedesktop.resolve1", + &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 18:28:48 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 1707143321961813.6479233016937; Mon, 5 Feb 2024 06:28:41 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id E57161BA6; Mon, 5 Feb 2024 09:28: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 AD792187E; Mon, 5 Feb 2024 09:16:34 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 7877F187A; Mon, 5 Feb 2024 09:14:27 -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 3F0F41B44 for ; Mon, 5 Feb 2024 09:14:26 -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-104-9PG5lUDZO4awkTwEb4mphg-1; Mon, 05 Feb 2024 09:14:23 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 3A0331013664 for ; Mon, 5 Feb 2024 14:14:21 +0000 (UTC) Received: from orkuz (unknown [10.43.3.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1767492BF0 for ; Mon, 5 Feb 2024 14:14:20 +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: 9PG5lUDZO4awkTwEb4mphg-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [libvirt PATCH v2 3/7] util: Introduce virSocketAddrBytes Date: Mon, 5 Feb 2024 15:14:10 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 5FPWKP4FSSDXWQX37UMCXNGL3U4KO45Q X-Message-ID-Hash: 5FPWKP4FSSDXWQX37UMCXNGL3U4KO45Q 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: 1707143322827100001 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 c336d06fb3..5fe7ebe9d2 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3378,6 +3378,7 @@ virSocketSendMsgWithFDs; # 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 18:28:48 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 1707142958251210.18397582529565; Mon, 5 Feb 2024 06:22:38 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 17B741DAB; Mon, 5 Feb 2024 09:22:37 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id CE8381C43; Mon, 5 Feb 2024 09:15:33 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id BBA1A185C; Mon, 5 Feb 2024 09:14:24 -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 0F00C187A for ; Mon, 5 Feb 2024 09:14:24 -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-134-Ey7LtLUNP4GI9M3mR4I3RQ-1; Mon, 05 Feb 2024 09:14:22 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 2D65E85A589 for ; Mon, 5 Feb 2024 14:14:22 +0000 (UTC) Received: from orkuz (unknown [10.43.3.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4E5151D5 for ; Mon, 5 Feb 2024 14:14:21 +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: Ey7LtLUNP4GI9M3mR4I3RQ-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [libvirt PATCH v2 4/7] util: Introduce virSystemdResolvedRegisterNameServer Date: Mon, 5 Feb 2024 15:14:11 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 32NVESMIO6SFYZEWBYIRTW65O57KRGRB X-Message-ID-Hash: 32NVESMIO6SFYZEWBYIRTW65O57KRGRB 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: 1707142958801100001 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 5fe7ebe9d2..396bd80844 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3495,6 +3495,7 @@ virSystemdHasResolvedResetCachedValue; virSystemdMakeScopeName; virSystemdMakeSliceName; virSystemdNotifyStartup; +virSystemdResolvedRegisterNameServer; virSystemdTerminateMachine; =20 =20 diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index fd2b1db3ee..5b772e29dd 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 @@ -1040,3 +1039,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 18:28:48 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 1707143097312639.8404575555592; Mon, 5 Feb 2024 06:24:57 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 046EC1D91; Mon, 5 Feb 2024 09:24:55 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 79C391D68; Mon, 5 Feb 2024 09:15:54 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id C5C8C187A; Mon, 5 Feb 2024 09:14:25 -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 06741185C for ; Mon, 5 Feb 2024 09:14:25 -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-190-UWfqJwmVMayzrgAqj-HYJg-1; Mon, 05 Feb 2024 09:14:23 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 03E4C84AF83 for ; Mon, 5 Feb 2024 14:14:23 +0000 (UTC) Received: from orkuz (unknown [10.43.3.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7B771121312 for ; Mon, 5 Feb 2024 14:14:22 +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: UWfqJwmVMayzrgAqj-HYJg-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [libvirt PATCH v2 5/7] tests: Add tests for virSystemdResolvedRegisterNameServer Date: Mon, 5 Feb 2024 15:14:12 +0100 Message-ID: <25c83018d4e92b8c8a0c9aa0db9eb8bf6b803bcd.1707142194.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: H2CS6PT6467IYC2RFX5YCWHTDCV7LZ72 X-Message-ID-Hash: H2CS6PT6467IYC2RFX5YCWHTDCV7LZ72 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: 1707143099400100001 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 18:28:48 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 170714323008839.4246703941144; Mon, 5 Feb 2024 06:27:10 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 08DC11DB1; Mon, 5 Feb 2024 09:27:09 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id A71E21E01; Mon, 5 Feb 2024 09:16:15 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2884B1C4E; Mon, 5 Feb 2024 09:14:27 -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 07BCD187A for ; Mon, 5 Feb 2024 09:14:26 -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-274-t5SLvFWkOQm6L0htRqojsQ-1; Mon, 05 Feb 2024 09:14:24 -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 2B0C8835140 for ; Mon, 5 Feb 2024 14:14:24 +0000 (UTC) Received: from orkuz (unknown [10.43.3.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2A9D1C060AF for ; Mon, 5 Feb 2024 14:14:23 +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: t5SLvFWkOQm6L0htRqojsQ-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [libvirt PATCH v2 6/7] network: Make virtual domains resolvable from the host Date: Mon, 5 Feb 2024 15:14:13 +0100 Message-ID: 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: V4WIE6YI7MQQ4EUSO33SJZYFWIZD3E5F X-Message-ID-Hash: V4WIE6YI7MQQ4EUSO33SJZYFWIZD3E5F 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: 1707143230580100001 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 18:28:48 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 1707143396134317.4617021946568; Mon, 5 Feb 2024 06:29:56 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1A0F91D87; Mon, 5 Feb 2024 09:29:55 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 113481D95; Mon, 5 Feb 2024 09:16:52 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id CE6F7185C; Mon, 5 Feb 2024 09:14:27 -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 CB0101C3C for ; Mon, 5 Feb 2024 09:14:26 -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-314-gL1jhFrLNGO76borB7JwmA-1; Mon, 05 Feb 2024 09:14:25 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 01D9884AF86 for ; Mon, 5 Feb 2024 14:14:25 +0000 (UTC) Received: from orkuz (unknown [10.43.3.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id D615A1121312 for ; Mon, 5 Feb 2024 14:14: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: gL1jhFrLNGO76borB7JwmA-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [libvirt PATCH v2 7/7] NEWS: Mention systemd-resolved support in network driver Date: Mon, 5 Feb 2024 15:14:14 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: GQADXCEMETJKU7TGNJSVEQDPYVITDR3Y X-Message-ID-Hash: GQADXCEMETJKU7TGNJSVEQDPYVITDR3Y 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: 1707143397164100001 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