diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2015-12-03 15:44:33 +0100 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2015-12-09 14:30:07 +0100 |
commit | c1be9856bf36f0287349d745f360ba615834d4d7 (patch) | |
tree | 4f714e5c7f1470bb1d531f62d52518c63dd5aa1d | |
parent | 783b3642d08eab71146aaee267d41d71e611b7bf (diff) | |
download | NetworkManager-c1be9856bf36f0287349d745f360ba615834d4d7.tar.gz |
platform: return the macvlan mode as integer
It's easier to handle it as an integer than as a string.
-rw-r--r-- | src/devices/nm-device-macvlan.c | 21 | ||||
-rw-r--r-- | src/platform/nm-linux-platform.c | 20 | ||||
-rw-r--r-- | src/platform/nm-platform.c | 9 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 3 | ||||
-rw-r--r-- | src/platform/tests/test-link.c | 2 |
5 files changed, 27 insertions, 28 deletions
diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index ab650acab7..f9e29ec8ec 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -56,6 +56,23 @@ enum { /**************************************************************/ +static const char * +macvlan_mode_to_string (guint mode) +{ + switch (mode) { + case MACVLAN_MODE_PRIVATE: + return "private"; + case MACVLAN_MODE_VEPA: + return "vepa"; + case MACVLAN_MODE_BRIDGE: + return "bridge"; + case MACVLAN_MODE_PASSTHRU: + return "passthru"; + default: + return "unknown"; + } +} + static void update_properties (NMDevice *device) { @@ -75,7 +92,7 @@ update_properties (NMDevice *device) if (priv->parent_ifindex != plink->parent) g_object_notify (object, NM_DEVICE_MACVLAN_PARENT); - if (g_strcmp0 (priv->props.mode, props->mode) != 0) + if (priv->props.mode != props->mode) g_object_notify (object, NM_DEVICE_MACVLAN_MODE); if (priv->props.no_promisc != props->no_promisc) g_object_notify (object, NM_DEVICE_MACVLAN_NO_PROMISC); @@ -124,7 +141,7 @@ get_property (GObject *object, guint prop_id, nm_utils_g_value_set_object_path (value, parent); break; case PROP_MODE: - g_value_set_string (value, priv->props.mode); + g_value_set_string (value, macvlan_mode_to_string (priv->props.mode)); break; case PROP_NO_PROMISC: g_value_set_boolean (value, priv->props.no_promisc); diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 354641fee8..6434be1a1c 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -1026,7 +1026,6 @@ _parse_lnk_macvlan (const char *kind, struct nlattr *info_data) struct nlattr *tb[IFLA_MACVLAN_MAX + 1]; int err; NMPObject *obj; - const char *mode; if (!info_data || g_strcmp0 (kind, "macvlan")) return NULL; @@ -1038,26 +1037,9 @@ _parse_lnk_macvlan (const char *kind, struct nlattr *info_data) if (!tb[IFLA_MACVLAN_MODE]) return NULL; - switch (nla_get_u32 (tb[IFLA_MACVLAN_MODE])) { - case MACVLAN_MODE_PRIVATE: - mode = "private"; - break; - case MACVLAN_MODE_VEPA: - mode = "vepa"; - break; - case MACVLAN_MODE_BRIDGE: - mode = "bridge"; - break; - case MACVLAN_MODE_PASSTHRU: - mode = "passthru"; - break; - default: - return NULL; - } - obj = nmp_object_new (NMP_OBJECT_TYPE_LNK_MACVLAN, NULL); props = &obj->lnk_macvlan; - props->mode = mode; + props->mode = nla_get_u32 (tb[IFLA_MACVLAN_MODE]); if (tb[IFLA_MACVLAN_FLAGS]) props->no_promisc = NM_FLAGS_HAS (nla_get_u16 (tb[IFLA_MACVLAN_FLAGS]), MACVLAN_FLAG_NOPROMISC); diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 623ba2edd0..5d82f76fd0 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -3059,10 +3059,9 @@ nm_platform_lnk_macvlan_to_string (const NMPlatformLnkMacvlan *lnk, char *buf, g return buf; g_snprintf (buf, len, - "macvlan%s%s%s", - lnk->mode ? " mode " : "", - lnk->mode ?: "", - lnk->no_promisc ? " not-promisc" : " promisc"); + "macvlan mode %u %s", + lnk->mode, + lnk->no_promisc ? "not-promisc" : "promisc"); return buf; } @@ -3667,7 +3666,7 @@ int nm_platform_lnk_macvlan_cmp (const NMPlatformLnkMacvlan *a, const NMPlatformLnkMacvlan *b) { _CMP_SELF (a, b); - _CMP_FIELD_STR_INTERNED (a, b, mode); + _CMP_FIELD (a, b, mode); _CMP_FIELD_BOOL (a, b, no_promisc); return 0; } diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 5eb042cf78..4866654445 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -24,6 +24,7 @@ #include <netinet/in.h> #include <linux/if.h> #include <linux/if_addr.h> +#include <linux/if_link.h> #include "nm-dbus-interface.h" #include "nm-default.h" @@ -399,7 +400,7 @@ typedef struct { } NMPlatformLnkIpIp; typedef struct { - const char *mode; + guint mode; gboolean no_promisc; } NMPlatformLnkMacvlan; diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index 6655259bb9..c1d2ce7adc 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -867,7 +867,7 @@ test_software_detect (gconstpointer user_data) g_assert (plnk == nm_platform_link_get_lnk_macvlan (NM_PLATFORM_GET, ifindex, NULL)); g_assert_cmpint (plnk->no_promisc, ==, FALSE); - g_assert_cmpstr (plnk->mode, ==, "vepa"); + g_assert_cmpint (plnk->mode, ==, MACVLAN_MODE_VEPA); break; } case NM_LINK_TYPE_SIT: { |