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

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