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:
@@ -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