Blame SOURCES/0005-lib-extract-NETWORK_ADDRESS-and-NETWORK_PREFIX-as-ma.patch

a7e38b
From 80899629519139a7eb86842942a9471d05eb4112 Mon Sep 17 00:00:00 2001
a7e38b
From: Laszlo Ersek <lersek@redhat.com>
a7e38b
Date: Thu, 23 Dec 2021 11:37:00 +0100
a7e38b
Subject: [PATCH] lib: extract NETWORK_ADDRESS and NETWORK_PREFIX as macros
a7e38b
a7e38b
The 169.254.0.0/16 network specification (for the appliance) is currently
a7e38b
duplicated between the direct backend and the libvirt backend. In a
a7e38b
subsequent patch, we're going to need the network specification in yet
a7e38b
another spot; extract it now to the NETWORK_ADDRESS and NETWORK_PREFIX
a7e38b
macros (simply as strings).
a7e38b
a7e38b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2034160
a7e38b
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
a7e38b
Message-Id: <20211223103701.12702-3-lersek@redhat.com>
a7e38b
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
a7e38b
Tested-by: Richard W.M. Jones <rjones@redhat.com>
a7e38b
(cherry picked from commit 216de164e091a5c36403f24901698044a43ae0d9)
a7e38b
---
a7e38b
 lib/guestfs-internal.h | 6 ++++++
a7e38b
 lib/launch-direct.c    | 2 +-
a7e38b
 lib/launch-libvirt.c   | 3 ++-
a7e38b
 3 files changed, 9 insertions(+), 2 deletions(-)
a7e38b
a7e38b
diff --git a/lib/guestfs-internal.h b/lib/guestfs-internal.h
a7e38b
index 8eb2dd3ad..e24d570f5 100644
a7e38b
--- a/lib/guestfs-internal.h
a7e38b
+++ b/lib/guestfs-internal.h
a7e38b
@@ -183,6 +183,12 @@ cleanup_mutex_unlock (pthread_mutex_t **ptr)
a7e38b
 #endif
a7e38b
 #endif
a7e38b
 
a7e38b
+/* Network address and network mask (expressed as address prefix) that the
a7e38b
+ * appliance will see (if networking is enabled).
a7e38b
+ */
a7e38b
+#define NETWORK_ADDRESS "169.254.0.0"
a7e38b
+#define NETWORK_PREFIX  "16"
a7e38b
+
a7e38b
 /* Guestfs handle and associated structures. */
a7e38b
 
a7e38b
 /* State. */
a7e38b
diff --git a/lib/launch-direct.c b/lib/launch-direct.c
a7e38b
index e5b9a5611..4f038f4f0 100644
a7e38b
--- a/lib/launch-direct.c
a7e38b
+++ b/lib/launch-direct.c
a7e38b
@@ -689,7 +689,7 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
a7e38b
     start_list ("-netdev") {
a7e38b
       append_list ("user");
a7e38b
       append_list ("id=usernet");
a7e38b
-      append_list ("net=169.254.0.0/16");
a7e38b
+      append_list ("net=" NETWORK_ADDRESS "/" NETWORK_PREFIX);
a7e38b
     } end_list ();
a7e38b
     start_list ("-device") {
a7e38b
       append_list (VIRTIO_DEVICE_NAME ("virtio-net"));
a7e38b
diff --git a/lib/launch-libvirt.c b/lib/launch-libvirt.c
a7e38b
index 9e8336938..266d88824 100644
a7e38b
--- a/lib/launch-libvirt.c
a7e38b
+++ b/lib/launch-libvirt.c
a7e38b
@@ -1843,7 +1843,8 @@ construct_libvirt_xml_qemu_cmdline (guestfs_h *g,
a7e38b
       } end_element ();
a7e38b
 
a7e38b
       start_element ("qemu:arg") {
a7e38b
-        attribute ("value", "user,id=usernet,net=169.254.0.0/16");
a7e38b
+        attribute ("value",
a7e38b
+                   "user,id=usernet,net=" NETWORK_ADDRESS "/" NETWORK_PREFIX);
a7e38b
       } end_element ();
a7e38b
 
a7e38b
       start_element ("qemu:arg") {
a7e38b
-- 
a7e38b
2.31.1
a7e38b