summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancesco Giudici <fgiudici@redhat.com>2019-06-18 15:57:59 +0200
committerFrancesco Giudici <fgiudici@redhat.com>2019-07-05 15:17:04 +0200
commitb3a5541111abaee748415b0c859eb259becb4dab (patch)
treec802a778b88dff980fba33a6730ce25950d16dad
parentb2915e20d11563dc16ed7648f02ddeeb12c7822a (diff)
downloadNetworkManager-fg/dhcp_options2env-rh1663253.tar.gz
dispatcher: add MS Azure endpoint env var expected by cloud-initfg/dhcp_options2env-rh1663253
Some linux distros (e.g., RHEL, CentOS and Fedora) ship a dispatcher script with their dhclient package in order to run user dhclient hook scripts also when connections are run by NetworkManager. The scripts convert the var names in the environment to the ones expected in the dhclient hook scripts. This feature is currently use by cloud-init to retrieve the MS Azure server endpoint address, which is sent in the private dhcp option 245. We just redefined the default dhclient var names for the private options from "unknown_xyz" to "private_xyz". In order to let current cloud-init version to be able to retrieve the Azure server endpoint address, add the legacy var name "unknown_245" to the dispatcher script environment.
-rw-r--r--dispatcher/nm-dispatcher-utils.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/dispatcher/nm-dispatcher-utils.c b/dispatcher/nm-dispatcher-utils.c
index fcd88de69f..c09b8c8a1a 100644
--- a/dispatcher/nm-dispatcher-utils.c
+++ b/dispatcher/nm-dispatcher-utils.c
@@ -381,6 +381,8 @@ construct_device_dhcp_items (GPtrArray *items, int addr_family, GVariant *dhcp_c
const char *key;
GVariant *val;
char four_or_six;
+ gboolean found_unknown_245 = FALSE;
+ gs_unref_variant GVariant *private_245_val = NULL;
if (!dhcp_config)
return;
@@ -402,10 +404,43 @@ construct_device_dhcp_items (GPtrArray *items, int addr_family, GVariant *dhcp_c
four_or_six,
ucased,
g_variant_get_string (val, NULL));
+
+ /* MS Azure sends the server endpoint in the dhcp private
+ * option 245. cloud-init searches the Azure server endpoint
+ * value looking for the standard dhclient label used for
+ * that option, which is "unknown_245".
+ * The 11-dhclient script shipped with Fedora and RHEL dhcp
+ * package converts our dispatcher environment vars to the
+ * dhclient ones (new_<some_option>) and calls dhclient hook
+ * scripts.
+ * Let's make cloud-init happy and let's duplicate the dhcp
+ * option 245 with the legacy name of the default dhclient
+ * label also when using the internal client.
+ * Note however that the dhclient plugin will have unknown_
+ * labels represented as ascii string when possible, falling
+ * back to hex string otherwise.
+ * private_ labels instead are always in hex string format.
+ * This shouldn't affect the MS Azure server endpoint value,
+ * as it usually belongs to the 240.0.0.0/4 network and so
+ * is always represented as an hex string. Moreover, cloudinit
+ * code checks just for an hex value in unknown_245.
+ */
+ if (addr_family == AF_INET) {
+ if (nm_streq (key, "private_245"))
+ private_245_val = g_variant_ref (val);
+ else if (nm_streq (key, "unknown_245"))
+ found_unknown_245 = true;
+ }
}
}
g_variant_unref (val);
}
+
+ if (private_245_val != NULL && !found_unknown_245) {
+ _items_add_printf (items,
+ "DHCP4_UNKNOWN_245=%s",
+ g_variant_get_string (private_245_val, NULL));
+ }
}
/*****************************************************************************/