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
commit18609971e38a2df53db987884dd3e22c5f73efe4 (patch)
tree290e873cf078eaf41d7db36ab8286d637f1a3440
parent04b34db9f2ac8112e180dbf549f0ab0716f32026 (diff)
downloadNetworkManager-th/dbus-byte-ordering-rh1584584.tar.gz
squash! all: expose EndianMagicU32 on D-Bus for detecting endianness issuesth/dbus-byte-ordering-rh1584584
>>>========================================================== Rethinking, maybe this is better than the NM_ENDIAN_MAGIC_U32 because the entire feature is rather obscure and only needed in very specific circumstances. While EndianMagicU32 seems slightly more convenient to use (to me), it has more overhead by adding a new D-Bus property. <<<========================================================== 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 deprecated for good, or the API was extended to expose the values also as strings and agnostic to byte ordering. Anyway. Add a capability that allows to detect the servers endianness of the server. 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.h24
-rw-r--r--src/nm-manager.c28
-rw-r--r--src/nm-manager.h1
4 files changed, 19 insertions, 47 deletions
diff --git a/introspection/org.freedesktop.NetworkManager.xml b/introspection/org.freedesktop.NetworkManager.xml
index e7b9ab810d..6c6ec282a6 100644
--- a/introspection/org.freedesktop.NetworkManager.xml
+++ b/introspection/org.freedesktop.NetworkManager.xml
@@ -273,19 +273,6 @@
</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 4d4ace2566..82408c9bd3 100644
--- a/libnm-core/nm-dbus-interface.h
+++ b/libnm-core/nm-dbus-interface.h
@@ -97,21 +97,15 @@
#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
+ * @NM_CAPABILITY_SERVER_BYTE_ORDER_BIG_ENDIAN: the server natively has big endian
+ * byte order. Since: 1.14.
+ * @NM_CAPABILITY_SERVER_BYTE_ORDER_LITTLE_ENDIAN: the server natively has little endian
+ * byte order. Obviously, @NM_CAPABILITY_SERVER_BYTE_ORDER_BIG_ENDIAN and
+ * @NM_CAPABILITY_SERVER_BYTE_ORDER_LITTLE_ENDIAN are never set at the same time.
+ * These flags can be used to correct for endianness, as NetworkManager's
+ * D-Bus API exposes some IPv4 addresses in network byte order. Since: 1.14.
*
* #NMCapability names the numbers in the Capabilities property.
* Capabilities are positive numbers. They are part of stable API
@@ -122,7 +116,9 @@
* extensions.
*/
typedef enum {
- NM_CAPABILITY_TEAM = 1,
+ NM_CAPABILITY_TEAM = 1,
+ NM_CAPABILITY_SERVER_BYTE_ORDER_BIG_ENDIAN = 2,
+ NM_CAPABILITY_SERVER_BYTE_ORDER_LITTLE_ENDIAN = 3,
} NMCapability;
/**
diff --git a/src/nm-manager.c b/src/nm-manager.c
index a8e879cef6..c1e2d03fe8 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -116,7 +116,6 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
NM_GOBJECT_PROPERTIES_DEFINE (NMManager,
- PROP_ENDIAN_MAGIC_U32,
PROP_VERSION,
PROP_CAPABILITIES,
PROP_STATE,
@@ -173,8 +172,6 @@ typedef struct {
CList link_cb_lst;
- GVariant *endian_magic_u32;
-
NMCheckpointManager *checkpoint_mgr;
NMSettings *settings;
@@ -6734,7 +6731,7 @@ nm_manager_set_capability (NMManager *self,
gssize idx;
g_return_if_fail (NM_IS_MANAGER (self));
- if (cap < 1 || cap > NM_CAPABILITY_TEAM)
+ if (cap < 1 || cap > NM_CAPABILITY_SERVER_BYTE_ORDER_LITTLE_ENDIAN)
g_return_if_reached ();
cap_i = (guint32) cap;
@@ -6871,8 +6868,6 @@ 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);
@@ -6883,6 +6878,14 @@ nm_manager_init (NMManager *self)
priv->capabilities = g_array_new (FALSE, FALSE, sizeof (guint32));
+#if __BYTE_ORDER == __BIG_ENDIAN
+ nm_manager_set_capability (self, NM_CAPABILITY_SERVER_BYTE_ORDER_BIG_ENDIAN);
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+ nm_manager_set_capability (self, NM_CAPABILITY_SERVER_BYTE_ORDER_LITTLE_ENDIAN);
+#else
+#error Undefined __BYTE_ORDER
+#endif
+
/* Initialize rfkill structures and states */
memset (priv->radio_states, 0, sizeof (priv->radio_states));
@@ -6958,9 +6961,6 @@ 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;
@@ -7244,8 +7244,6 @@ 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 (
@@ -7473,7 +7471,6 @@ 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),
@@ -7517,13 +7514,6 @@ 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 64cbbc971f..5a46284675 100644
--- a/src/nm-manager.h
+++ b/src/nm-manager.h
@@ -33,7 +33,6 @@
#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"