platform: return the macvlan mode as integer
It's easier to handle it as an integer than as a string.
This commit is contained in:
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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: {
|
||||
|
Reference in New Issue
Block a user