summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-07-15 10:24:43 +0200
committerThomas Haller <thaller@redhat.com>2018-07-25 17:26:30 +0200
commit04b34db9f2ac8112e180dbf549f0ab0716f32026 (patch)
treeade6c8ec2bc1da0e5136b80beb2707a10c53d90e
parent189f0e02ce6bebde0307a2b83aebcd3f942a441b (diff)
downloadNetworkManager-04b34db9f2ac8112e180dbf549f0ab0716f32026.tar.gz
all: expose EndianMagicU32 on D-Bus for detecting endianness issues
In NetworkManager's D-Bus API, some IPv4 addresses are exposed in network order (big endian). Note that in the meantime, all these properties are either entirely deprecated, or the API was extended to expose the values also as strings, agnostic to byte ordering. Anyway. Add a property that allows to detect the servers endianness of the server. The server will always set this property to the magic value 0x12345678 in network order. On the client side, you can detect byte ordering issues via: dbus_endian_magic_u32 = g_variant_get_uint32 (variant); if (dbus_endian_magic_u32 != htonl (NM_ENDIAN_MAGIC_U32)) { /* values in network-order got scrambled. Needs correction. */ } https://bugzilla.redhat.com/show_bug.cgi?id=1153559 https://bugzilla.redhat.com/show_bug.cgi?id=1584584
-rw-r--r--introspection/org.freedesktop.NetworkManager.xml13
-rw-r--r--libnm-core/nm-dbus-interface.h13
-rw-r--r--src/nm-manager.c18
-rw-r--r--src/nm-manager.h1
4 files changed, 45 insertions, 0 deletions
diff --git a/introspection/org.freedesktop.NetworkManager.xml b/introspection/org.freedesktop.NetworkManager.xml
index 6c6ec282a6..e7b9ab810d 100644
--- a/introspection/org.freedesktop.NetworkManager.xml
+++ b/introspection/org.freedesktop.NetworkManager.xml
@@ -273,6 +273,19 @@
</method>
<!--
+ EndianMagicU32:
+
+ Some properties in NetworkManager's D-Bus API are in network byte
+ order (big endian). When remoting D-Bus, it might be necessary to
+ correct for endianness. This property will give the number 0x12345678
+ (%NM_ENDIAN_MAGIC_U32) in network order. It can be used to detect whether
+ correction is necessary.
+
+ Since: 1.14
+ -->
+ <property name="EndianMagicU32" type="u" access="read"/>
+
+ <!--
Devices:
The list of realized network devices. Realized devices are those which
diff --git a/libnm-core/nm-dbus-interface.h b/libnm-core/nm-dbus-interface.h
index 388898dd96..4d4ace2566 100644
--- a/libnm-core/nm-dbus-interface.h
+++ b/libnm-core/nm-dbus-interface.h
@@ -97,6 +97,19 @@
#define NM_DBUS_PATH_DNS_MANAGER "/org/freedesktop/NetworkManager/DnsManager"
/**
+ * NM_ENDIAN_MAGIC_U32:
+ *
+ * Value of "EndianMagicU32" property. The value is exposed by NetworkManager
+ * in network order. When remoting D-Bus and receiving the magic value scrambled
+ * it means you must correct for endianness. This is important, because some
+ * properties in NetworkManager's D-Bus API are in network order (IPv4 addresses)
+ * and these addresses will need the same correct.
+ *
+ * Since: 1.14
+ */
+#define NM_ENDIAN_MAGIC_U32 0x12345678u
+
+/**
* NMCapability:
* @NM_CAPABILITY_TEAM: Teams can be managed
*
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 630180963a..a8e879cef6 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -116,6 +116,7 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
NM_GOBJECT_PROPERTIES_DEFINE (NMManager,
+ PROP_ENDIAN_MAGIC_U32,
PROP_VERSION,
PROP_CAPABILITIES,
PROP_STATE,
@@ -172,6 +173,8 @@ typedef struct {
CList link_cb_lst;
+ GVariant *endian_magic_u32;
+
NMCheckpointManager *checkpoint_mgr;
NMSettings *settings;
@@ -6868,6 +6871,8 @@ nm_manager_init (NMManager *self)
guint i;
GFile *file;
+ priv->endian_magic_u32 = g_variant_ref_sink (g_variant_new_uint32 (htonl (NM_ENDIAN_MAGIC_U32)));
+
c_list_init (&priv->link_cb_lst);
c_list_init (&priv->devices_lst_head);
c_list_init (&priv->active_connections_lst_head);
@@ -6953,6 +6958,9 @@ get_property (GObject *object, guint prop_id,
GPtrArray *ptrarr;
switch (prop_id) {
+ case PROP_ENDIAN_MAGIC_U32:
+ g_value_set_variant (value, priv->endian_magic_u32);
+ break;
case PROP_VERSION:
g_value_set_string (value, VERSION);
break;
@@ -7236,6 +7244,8 @@ finalize (GObject *object)
G_OBJECT_CLASS (nm_manager_parent_class)->finalize (object);
g_object_unref (priv->platform);
+
+ g_variant_unref (priv->endian_magic_u32);
}
static const GDBusSignalInfo signal_info_check_permissions = NM_DEFINE_GDBUS_SIGNAL_INFO_INIT (
@@ -7463,6 +7473,7 @@ static const NMDBusInterfaceInfoExtended interface_info_manager = {
&signal_info_device_removed,
),
.properties = NM_DEFINE_GDBUS_PROPERTY_INFOS (
+ NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE ("EndianMagicU32", "u", NM_MANAGER_ENDIAN_MAGIC_U32),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Devices", "ao", NM_MANAGER_DEVICES),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("AllDevices", "ao", NM_MANAGER_ALL_DEVICES),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Checkpoints", "ao", NM_MANAGER_CHECKPOINTS),
@@ -7506,6 +7517,13 @@ nm_manager_class_init (NMManagerClass *manager_class)
object_class->dispose = dispose;
object_class->finalize = finalize;
+ obj_properties[PROP_ENDIAN_MAGIC_U32] =
+ g_param_spec_variant (NM_MANAGER_ENDIAN_MAGIC_U32, "", "",
+ G_VARIANT_TYPE ("u"),
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS);
+
obj_properties[PROP_VERSION] =
g_param_spec_string (NM_MANAGER_VERSION, "", "",
NULL,
diff --git a/src/nm-manager.h b/src/nm-manager.h
index 5a46284675..64cbbc971f 100644
--- a/src/nm-manager.h
+++ b/src/nm-manager.h
@@ -33,6 +33,7 @@
#define NM_IS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_MANAGER))
#define NM_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MANAGER, NMManagerClass))
+#define NM_MANAGER_ENDIAN_MAGIC_U32 "endian-magic-u32"
#define NM_MANAGER_VERSION "version"
#define NM_MANAGER_CAPABILITIES "capabilities"
#define NM_MANAGER_STATE "state"