platform: implement vlan properties as lnk data
This commit is contained in:
@@ -164,27 +164,28 @@ realize (NMDevice *device,
|
||||
GError **error)
|
||||
{
|
||||
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device);
|
||||
int parent_ifindex = -1, vlan_id = -1;
|
||||
NMDevice *parent;
|
||||
const NMPlatformLnkVlan *plnk;
|
||||
|
||||
g_return_val_if_fail (plink, FALSE);
|
||||
|
||||
g_assert (plink->type == NM_LINK_TYPE_VLAN);
|
||||
|
||||
if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, plink->ifindex, &parent_ifindex, &vlan_id)) {
|
||||
plnk = nm_platform_link_get_lnk_vlan (NM_PLATFORM_GET, plink->ifindex, NULL);
|
||||
if (!plnk) {
|
||||
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
|
||||
"(%s): failed to read VLAN properties", plink->name);
|
||||
"(%s): failed to get VLAN properties", plink->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (vlan_id < 0) {
|
||||
if (plnk->id < 0) {
|
||||
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
|
||||
"(%s): VLAN ID invalid", plink->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (parent_ifindex != NM_PLATFORM_LINK_OTHER_NETNS) {
|
||||
parent = nm_manager_get_device_by_ifindex (nm_manager_get (), parent_ifindex);
|
||||
if (plink->parent != NM_PLATFORM_LINK_OTHER_NETNS) {
|
||||
parent = nm_manager_get_device_by_ifindex (nm_manager_get (), plink->parent);
|
||||
if (!parent) {
|
||||
nm_log_dbg (LOGD_HW, "(%s): VLAN parent interface unknown", plink->name);
|
||||
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
|
||||
@@ -196,7 +197,7 @@ realize (NMDevice *device,
|
||||
|
||||
g_warn_if_fail (priv->parent == NULL);
|
||||
nm_device_vlan_set_parent (NM_DEVICE_VLAN (device), parent);
|
||||
priv->vlan_id = vlan_id;
|
||||
priv->vlan_id = plnk->id;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -294,7 +295,8 @@ component_added (NMDevice *device, GObject *component)
|
||||
NMDeviceVlan *self = NM_DEVICE_VLAN (device);
|
||||
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
|
||||
NMDevice *added_device;
|
||||
int parent_ifindex = -1;
|
||||
const NMPlatformLink *plink;
|
||||
const NMPlatformLnkVlan *plnk;
|
||||
|
||||
if (priv->parent)
|
||||
return FALSE;
|
||||
@@ -303,13 +305,14 @@ component_added (NMDevice *device, GObject *component)
|
||||
return FALSE;
|
||||
added_device = NM_DEVICE (component);
|
||||
|
||||
if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, nm_device_get_ifindex (device), &parent_ifindex, NULL)) {
|
||||
plnk = nm_platform_link_get_lnk_vlan (NM_PLATFORM_GET, nm_device_get_ifindex (device), &plink);
|
||||
if (!plnk) {
|
||||
_LOGW (LOGD_VLAN, "failed to get VLAN interface info while checking added component.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( parent_ifindex <= 0
|
||||
|| nm_device_get_ifindex (added_device) != parent_ifindex)
|
||||
if ( plink->parent <= 0
|
||||
|| nm_device_get_ifindex (added_device) != plink->parent)
|
||||
return FALSE;
|
||||
|
||||
nm_device_vlan_set_parent (self, added_device);
|
||||
@@ -462,30 +465,32 @@ update_connection (NMDevice *device, NMConnection *connection)
|
||||
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device);
|
||||
NMSettingVlan *s_vlan = nm_connection_get_setting_vlan (connection);
|
||||
int ifindex = nm_device_get_ifindex (device);
|
||||
int parent_ifindex = -1, vlan_id = -1;
|
||||
NMDevice *parent;
|
||||
const char *setting_parent, *new_parent;
|
||||
const NMPlatformLink *plink;
|
||||
const NMPlatformLnkVlan *plnk;
|
||||
|
||||
if (!s_vlan) {
|
||||
s_vlan = (NMSettingVlan *) nm_setting_vlan_new ();
|
||||
nm_connection_add_setting (connection, (NMSetting *) s_vlan);
|
||||
}
|
||||
|
||||
if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, ifindex, &parent_ifindex, &vlan_id)) {
|
||||
plnk = nm_platform_link_get_lnk_vlan (NM_PLATFORM_GET, ifindex, &plink);
|
||||
if (!plnk) {
|
||||
_LOGW (LOGD_VLAN, "failed to get VLAN interface info while updating connection.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (priv->vlan_id != vlan_id) {
|
||||
priv->vlan_id = vlan_id;
|
||||
if (priv->vlan_id != plnk->id) {
|
||||
priv->vlan_id = plnk->id;
|
||||
g_object_notify (G_OBJECT (device), NM_DEVICE_VLAN_ID);
|
||||
}
|
||||
|
||||
if (vlan_id != nm_setting_vlan_get_id (s_vlan))
|
||||
if (plnk->id != nm_setting_vlan_get_id (s_vlan))
|
||||
g_object_set (s_vlan, NM_SETTING_VLAN_ID, priv->vlan_id, NULL);
|
||||
|
||||
if (parent_ifindex != NM_PLATFORM_LINK_OTHER_NETNS)
|
||||
parent = nm_manager_get_device_by_ifindex (nm_manager_get (), parent_ifindex);
|
||||
if (plink->parent != NM_PLATFORM_LINK_OTHER_NETNS)
|
||||
parent = nm_manager_get_device_by_ifindex (nm_manager_get (), plink->parent);
|
||||
else
|
||||
parent = NULL;
|
||||
nm_device_vlan_set_parent (NM_DEVICE_VLAN (device), parent);
|
||||
|
@@ -130,6 +130,9 @@ typedef enum {
|
||||
NMP_OBJECT_TYPE_IP6_ADDRESS,
|
||||
NMP_OBJECT_TYPE_IP4_ROUTE,
|
||||
NMP_OBJECT_TYPE_IP6_ROUTE,
|
||||
|
||||
NMP_OBJECT_TYPE_LNK_VLAN,
|
||||
|
||||
__NMP_OBJECT_TYPE_LAST,
|
||||
NMP_OBJECT_TYPE_MAX = __NMP_OBJECT_TYPE_LAST - 1,
|
||||
} NMPObjectType;
|
||||
|
@@ -74,7 +74,7 @@ typedef struct {
|
||||
NMPlatformLink link;
|
||||
|
||||
char *udi;
|
||||
int vlan_id;
|
||||
NMPlatformLnkVlan lnk_vlan;
|
||||
int ib_p_key;
|
||||
struct in6_addr ip6_lladdr;
|
||||
} NMFakePlatformLink;
|
||||
@@ -252,6 +252,30 @@ _nm_platform_link_get_by_address (NMPlatform *platform,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gconstpointer
|
||||
link_get_lnk (NMPlatform *platform,
|
||||
int ifindex,
|
||||
NMLinkType link_type,
|
||||
const NMPlatformLink **out_link)
|
||||
{
|
||||
NMFakePlatformLink *device = link_get (platform, ifindex);
|
||||
|
||||
if (!device)
|
||||
return NULL;
|
||||
|
||||
NM_SET_OUT (out_link, &device->link);
|
||||
|
||||
if (link_type != device->link.type)
|
||||
return NULL;
|
||||
|
||||
switch (link_type) {
|
||||
case NM_LINK_TYPE_VLAN:
|
||||
return &device->lnk_vlan;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
link_add (NMPlatform *platform,
|
||||
const char *name,
|
||||
@@ -632,7 +656,7 @@ vlan_add (NMPlatform *platform, const char *name, int parent, int vlan_id, guint
|
||||
|
||||
g_return_val_if_fail (device, FALSE);
|
||||
|
||||
device->vlan_id = vlan_id;
|
||||
device->lnk_vlan.id = vlan_id;
|
||||
device->link.parent = parent;
|
||||
|
||||
if (out_link)
|
||||
@@ -640,21 +664,6 @@ vlan_add (NMPlatform *platform, const char *name, int parent, int vlan_id, guint
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
vlan_get_info (NMPlatform *platform, int ifindex, int *parent, int *vlan_id)
|
||||
{
|
||||
NMFakePlatformLink *device = link_get (platform, ifindex);
|
||||
|
||||
g_return_val_if_fail (device, FALSE);
|
||||
|
||||
if (parent)
|
||||
*parent = device->link.parent;
|
||||
if (vlan_id)
|
||||
*vlan_id = device->vlan_id;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
vlan_set_ingress_map (NMPlatform *platform, int ifindex, int from, int to)
|
||||
{
|
||||
@@ -1433,6 +1442,8 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
|
||||
platform_class->link_delete = link_delete;
|
||||
platform_class->link_get_type_name = link_get_type_name;
|
||||
|
||||
platform_class->link_get_lnk = link_get_lnk;
|
||||
|
||||
platform_class->link_get_udi = link_get_udi;
|
||||
|
||||
platform_class->link_set_up = link_set_up;
|
||||
@@ -1456,7 +1467,6 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
|
||||
platform_class->slave_get_option = slave_get_option;
|
||||
|
||||
platform_class->vlan_add = vlan_add;
|
||||
platform_class->vlan_get_info = vlan_get_info;
|
||||
platform_class->vlan_set_ingress_map = vlan_set_ingress_map;
|
||||
platform_class->vlan_set_egress_map = vlan_set_egress_map;
|
||||
|
||||
|
@@ -883,8 +883,8 @@ errout:
|
||||
/*****************************************************************************/
|
||||
|
||||
/* Copied and heavily modified from libnl3's vlan_parse() */
|
||||
static gboolean
|
||||
_parse_io_vlan (const char *kind, struct nlattr *data, guint16 *out_vlan_id)
|
||||
static NMPObject *
|
||||
_parse_lnk_vlan (const char *kind, struct nlattr *info_data)
|
||||
{
|
||||
static struct nla_policy policy[IFLA_VLAN_MAX+1] = {
|
||||
[IFLA_VLAN_ID] = { .type = NLA_U16 },
|
||||
@@ -895,24 +895,21 @@ _parse_io_vlan (const char *kind, struct nlattr *data, guint16 *out_vlan_id)
|
||||
};
|
||||
struct nlattr *tb[IFLA_VLAN_MAX+1];
|
||||
int err;
|
||||
gboolean success = FALSE;
|
||||
guint16 vlan_id;
|
||||
NMPObject *obj = NULL;
|
||||
|
||||
if (!data || g_strcmp0 (kind, "vlan"))
|
||||
goto errout;
|
||||
if (!info_data || g_strcmp0 (kind, "vlan"))
|
||||
return NULL;
|
||||
|
||||
if ((err = nla_parse_nested (tb, IFLA_VLAN_MAX, data, policy)) < 0)
|
||||
goto errout;
|
||||
if ((err = nla_parse_nested (tb, IFLA_VLAN_MAX, info_data, policy)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (!tb[IFLA_VLAN_ID])
|
||||
goto errout;
|
||||
return NULL;
|
||||
|
||||
vlan_id = nla_get_u16(tb[IFLA_VLAN_ID]);
|
||||
obj = nmp_object_new (NMP_OBJECT_TYPE_LNK_VLAN, NULL);
|
||||
obj->lnk_vlan.id = nla_get_u16(tb[IFLA_VLAN_ID]);
|
||||
|
||||
success = TRUE;
|
||||
*out_vlan_id = vlan_id;
|
||||
errout:
|
||||
return success;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -966,6 +963,7 @@ _new_from_nl_link (NMPlatform *platform, const NMPCache *cache, struct nlmsghdr
|
||||
gboolean completed_from_cache_val = FALSE;
|
||||
gboolean *completed_from_cache = cache ? &completed_from_cache_val : NULL;
|
||||
const NMPObject *link_cached = NULL;
|
||||
nm_auto_nmpobj NMPObject *lnk_data = NULL;
|
||||
|
||||
if (!nlmsg_valid_hdr (nlh, sizeof (*ifi)))
|
||||
return NULL;
|
||||
@@ -1055,21 +1053,35 @@ _new_from_nl_link (NMPlatform *platform, const NMPCache *cache, struct nlmsghdr
|
||||
if (tb[IFLA_MTU])
|
||||
obj->link.mtu = nla_get_u32 (tb[IFLA_MTU]);
|
||||
|
||||
if (obj->link.type == NM_LINK_TYPE_VLAN) {
|
||||
if (_parse_io_vlan (nl_info_kind,
|
||||
nl_info_data,
|
||||
&obj->link.vlan_id))
|
||||
goto vlan_done;
|
||||
if (completed_from_cache) {
|
||||
_lookup_cached_link (cache, obj->link.ifindex, completed_from_cache, &link_cached);
|
||||
if (link_cached)
|
||||
obj->link.vlan_id = link_cached->link.vlan_id;
|
||||
}
|
||||
vlan_done: ;
|
||||
switch (obj->link.type) {
|
||||
case NM_LINK_TYPE_VLAN:
|
||||
lnk_data = _parse_lnk_vlan (nl_info_kind, nl_info_data);
|
||||
break;
|
||||
default:
|
||||
goto no_lnk_data;
|
||||
}
|
||||
|
||||
/* We always try to look into the cache and reuse the object there.
|
||||
* We do that, because we consider the lnk object as immutable and don't
|
||||
* modify it after creating. Hence we can share it and reuse. */
|
||||
if (completed_from_cache) {
|
||||
_lookup_cached_link (cache, obj->link.ifindex, completed_from_cache, &link_cached);
|
||||
if ( link_cached
|
||||
&& link_cached->link.type == obj->link.type
|
||||
&& ( !lnk_data
|
||||
|| nmp_object_equal (lnk_data, link_cached->_link.netlink.lnk))) {
|
||||
nmp_object_unref (lnk_data);
|
||||
lnk_data = nmp_object_ref (link_cached->_link.netlink.lnk);
|
||||
}
|
||||
}
|
||||
|
||||
no_lnk_data:
|
||||
|
||||
obj->_link.netlink.is_in_netlink = TRUE;
|
||||
|
||||
obj->_link.netlink.lnk = lnk_data;
|
||||
lnk_data = NULL;
|
||||
|
||||
done:
|
||||
obj_result = obj;
|
||||
obj = NULL;
|
||||
@@ -3009,6 +3021,34 @@ _nm_platform_link_get_by_address (NMPlatform *platform,
|
||||
return obj ? &obj->link : NULL;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gconstpointer
|
||||
link_get_lnk (NMPlatform *platform, int ifindex, NMLinkType link_type, const NMPlatformLink **out_link)
|
||||
{
|
||||
const NMPObject *obj = cache_lookup_link (platform, ifindex);
|
||||
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
NM_SET_OUT (out_link, &obj->link);
|
||||
|
||||
if (link_type != obj->link.type)
|
||||
return NULL;
|
||||
|
||||
switch (link_type) {
|
||||
case NM_LINK_TYPE_VLAN:
|
||||
if (NMP_OBJECT_GET_TYPE (obj->_link.netlink.lnk) == NMP_OBJECT_TYPE_LNK_VLAN)
|
||||
return &obj->_link.netlink.lnk->lnk_vlan;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static struct nl_object *
|
||||
build_rtnl_link (int ifindex, const char *name, NMLinkType type)
|
||||
{
|
||||
@@ -3534,23 +3574,6 @@ vlan_add (NMPlatform *platform,
|
||||
return do_add_link_with_lookup (platform, name, rtnllink, NM_LINK_TYPE_VLAN, out_link);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
vlan_get_info (NMPlatform *platform, int ifindex, int *parent, int *vlan_id)
|
||||
{
|
||||
const NMPObject *obj = cache_lookup_link (platform, ifindex);
|
||||
int p = 0, v = 0;
|
||||
|
||||
if (obj) {
|
||||
p = obj->link.parent;
|
||||
v = obj->link.vlan_id;
|
||||
}
|
||||
if (parent)
|
||||
*parent = p;
|
||||
if (vlan_id)
|
||||
*vlan_id = v;
|
||||
return !!obj;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
vlan_set_ingress_map (NMPlatform *platform, int ifindex, int from, int to)
|
||||
{
|
||||
@@ -5284,6 +5307,8 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
|
||||
platform_class->link_get_type_name = link_get_type_name;
|
||||
platform_class->link_get_unmanaged = link_get_unmanaged;
|
||||
|
||||
platform_class->link_get_lnk = link_get_lnk;
|
||||
|
||||
platform_class->link_refresh = link_refresh;
|
||||
|
||||
platform_class->link_set_up = link_set_up;
|
||||
@@ -5316,7 +5341,6 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
|
||||
platform_class->slave_get_option = slave_get_option;
|
||||
|
||||
platform_class->vlan_add = vlan_add;
|
||||
platform_class->vlan_get_info = vlan_get_info;
|
||||
platform_class->vlan_set_ingress_map = vlan_set_ingress_map;
|
||||
platform_class->vlan_set_egress_map = vlan_set_egress_map;
|
||||
|
||||
|
@@ -1382,6 +1382,28 @@ nm_platform_link_get_master (NMPlatform *self, int slave)
|
||||
return pllink ? pllink->master : 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
gconstpointer
|
||||
nm_platform_link_get_lnk (NMPlatform *self, int ifindex, NMLinkType link_type, const NMPlatformLink **out_link)
|
||||
{
|
||||
_CHECK_SELF (self, klass, FALSE);
|
||||
|
||||
NM_SET_OUT (out_link, NULL);
|
||||
|
||||
g_return_val_if_fail (ifindex > 0, NULL);
|
||||
|
||||
return klass->link_get_lnk (self, ifindex, link_type, out_link);
|
||||
}
|
||||
|
||||
const NMPlatformLnkVlan *
|
||||
nm_platform_link_get_lnk_vlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link)
|
||||
{
|
||||
return nm_platform_link_get_lnk (self, ifindex, NM_LINK_TYPE_VLAN, out_link);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* nm_platform_bridge_add:
|
||||
* @self: platform instance
|
||||
@@ -1518,24 +1540,6 @@ nm_platform_slave_get_option (NMPlatform *self, int ifindex, const char *option)
|
||||
return klass->slave_get_option (self, ifindex, option);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_platform_vlan_get_info (NMPlatform *self, int ifindex, int *parent, int *vlanid)
|
||||
{
|
||||
_CHECK_SELF (self, klass, FALSE);
|
||||
|
||||
g_return_val_if_fail (klass->vlan_get_info, FALSE);
|
||||
|
||||
if (parent)
|
||||
*parent = 0;
|
||||
if (vlanid)
|
||||
*vlanid = 0;
|
||||
|
||||
if (nm_platform_link_get_type (self, ifindex) != NM_LINK_TYPE_VLAN)
|
||||
return FALSE;
|
||||
|
||||
return klass->vlan_get_info (self, ifindex, parent, vlanid);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_platform_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int to)
|
||||
{
|
||||
@@ -2458,7 +2462,6 @@ nm_platform_link_to_string (const NMPlatformLink *link, char *buf, gsize len)
|
||||
{
|
||||
char master[20];
|
||||
char parent[20];
|
||||
char str_vlan[16];
|
||||
GString *str_flags;
|
||||
char str_addrmode[30];
|
||||
gs_free char *str_addr = NULL;
|
||||
@@ -2497,11 +2500,6 @@ nm_platform_link_to_string (const NMPlatformLink *link, char *buf, gsize len)
|
||||
else
|
||||
parent[0] = 0;
|
||||
|
||||
if (link->vlan_id)
|
||||
g_snprintf (str_vlan, sizeof (str_vlan), " vlan %u", (guint) link->vlan_id);
|
||||
else
|
||||
str_vlan[0] = '\0';
|
||||
|
||||
if (link->inet6_addr_gen_mode_inv) {
|
||||
switch (_nm_platform_uint8_inv (link->inet6_addr_gen_mode_inv)) {
|
||||
case 0:
|
||||
@@ -2531,7 +2529,6 @@ nm_platform_link_to_string (const NMPlatformLink *link, char *buf, gsize len)
|
||||
" <%s>" /* flags */
|
||||
" mtu %d"
|
||||
"%s" /* master */
|
||||
"%s" /* vlan */
|
||||
" arp %u" /* arptype */
|
||||
"%s%s" /* link->type */
|
||||
"%s%s" /* kind */
|
||||
@@ -2546,7 +2543,6 @@ nm_platform_link_to_string (const NMPlatformLink *link, char *buf, gsize len)
|
||||
parent,
|
||||
str_flags->str,
|
||||
link->mtu, master,
|
||||
str_vlan,
|
||||
link->arptype,
|
||||
str_link_type ? " " : "",
|
||||
str_if_set (str_link_type, "???"),
|
||||
@@ -2564,6 +2560,16 @@ nm_platform_link_to_string (const NMPlatformLink *link, char *buf, gsize len)
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_platform_lnk_vlan_to_string (const NMPlatformLnkVlan *lnk, char *buf, gsize len)
|
||||
{
|
||||
if (!_to_string_buffer_init (lnk, &buf, &len))
|
||||
return buf;
|
||||
|
||||
g_snprintf (buf, len, "vlan %u", (guint) lnk->id);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_platform_ip4_address_to_string:
|
||||
* @route: pointer to NMPlatformIP4Address address structure
|
||||
@@ -2911,7 +2917,6 @@ nm_platform_link_cmp (const NMPlatformLink *a, const NMPlatformLink *b)
|
||||
_CMP_FIELD_STR (a, b, name);
|
||||
_CMP_FIELD (a, b, master);
|
||||
_CMP_FIELD (a, b, parent);
|
||||
_CMP_FIELD (a, b, vlan_id);
|
||||
_CMP_FIELD (a, b, flags);
|
||||
_CMP_FIELD (a, b, connected);
|
||||
_CMP_FIELD (a, b, mtu);
|
||||
@@ -2929,6 +2934,14 @@ nm_platform_link_cmp (const NMPlatformLink *a, const NMPlatformLink *b)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nm_platform_lnk_vlan_cmp (const NMPlatformLnkVlan *a, const NMPlatformLnkVlan *b)
|
||||
{
|
||||
_CMP_SELF (a, b);
|
||||
_CMP_FIELD (a, b, id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nm_platform_ip4_address_cmp (const NMPlatformIP4Address *a, const NMPlatformIP4Address *b)
|
||||
{
|
||||
|
@@ -150,9 +150,6 @@ struct _NMPlatformLink {
|
||||
* initialized with memset(0) has and unset value.*/
|
||||
guint8 inet6_addr_gen_mode_inv;
|
||||
|
||||
/* rtnl_link_vlan_get_id(), IFLA_VLAN_ID */
|
||||
guint16 vlan_id;
|
||||
|
||||
/* IFF_* flags as u32. Note that ifi_flags in 'struct ifinfomsg' is declared as 'unsigned',
|
||||
* but libnl stores the flag internally as u32. */
|
||||
guint32 flags;
|
||||
@@ -343,6 +340,11 @@ typedef struct {
|
||||
extern const NMPlatformVTableRoute nm_platform_vtable_route_v4;
|
||||
extern const NMPlatformVTableRoute nm_platform_vtable_route_v6;
|
||||
|
||||
typedef struct {
|
||||
/* rtnl_link_vlan_get_id(), IFLA_VLAN_ID */
|
||||
guint16 id;
|
||||
} NMPlatformLnkVlan;
|
||||
|
||||
typedef struct {
|
||||
int peer;
|
||||
} NMPlatformVethProperties;
|
||||
@@ -440,6 +442,8 @@ typedef struct {
|
||||
const NMPlatformLink *(*link_get_by_ifname) (NMPlatform *platform, const char *ifname);
|
||||
const NMPlatformLink *(*link_get_by_address) (NMPlatform *platform, gconstpointer address, size_t length);
|
||||
|
||||
gconstpointer (*link_get_lnk) (NMPlatform *platform, int ifindex, NMLinkType link_type, const NMPlatformLink **out_link);
|
||||
|
||||
GArray *(*link_get_all) (NMPlatform *);
|
||||
gboolean (*link_add) (NMPlatform *,
|
||||
const char *name,
|
||||
@@ -491,7 +495,6 @@ typedef struct {
|
||||
char * (*slave_get_option) (NMPlatform *, int ifindex, const char *option);
|
||||
|
||||
gboolean (*vlan_add) (NMPlatform *, const char *name, int parent, int vlanid, guint32 vlanflags, NMPlatformLink *out_link);
|
||||
gboolean (*vlan_get_info) (NMPlatform *, int ifindex, int *parent, int *vlan_id);
|
||||
gboolean (*vlan_set_ingress_map) (NMPlatform *, int ifindex, int from, int to);
|
||||
gboolean (*vlan_set_egress_map) (NMPlatform *, int ifindex, int from, int to);
|
||||
|
||||
@@ -688,8 +691,10 @@ char *nm_platform_master_get_option (NMPlatform *self, int ifindex, const char *
|
||||
gboolean nm_platform_slave_set_option (NMPlatform *self, int ifindex, const char *option, const char *value);
|
||||
char *nm_platform_slave_get_option (NMPlatform *self, int ifindex, const char *option);
|
||||
|
||||
gconstpointer nm_platform_link_get_lnk (NMPlatform *self, int ifindex, NMLinkType link_type, const NMPlatformLink **out_link);
|
||||
const NMPlatformLnkVlan *nm_platform_link_get_lnk_vlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
|
||||
|
||||
NMPlatformError nm_platform_vlan_add (NMPlatform *self, const char *name, int parent, int vlanid, guint32 vlanflags, NMPlatformLink *out_link);
|
||||
gboolean nm_platform_vlan_get_info (NMPlatform *self, int ifindex, int *parent, int *vlanid);
|
||||
gboolean nm_platform_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int to);
|
||||
gboolean nm_platform_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to);
|
||||
|
||||
@@ -766,12 +771,14 @@ gboolean nm_platform_ip6_route_delete (NMPlatform *self, int ifindex, struct in6
|
||||
extern char _nm_platform_to_string_buffer[1024];
|
||||
|
||||
const char *nm_platform_link_to_string (const NMPlatformLink *link, char *buf, gsize len);
|
||||
const char *nm_platform_lnk_vlan_to_string (const NMPlatformLnkVlan *lnk, char *buf, gsize len);
|
||||
const char *nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address, char *buf, gsize len);
|
||||
const char *nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address, char *buf, gsize len);
|
||||
const char *nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route, char *buf, gsize len);
|
||||
const char *nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route, char *buf, gsize len);
|
||||
|
||||
int nm_platform_link_cmp (const NMPlatformLink *a, const NMPlatformLink *b);
|
||||
int nm_platform_lnk_vlan_cmp (const NMPlatformLnkVlan *a, const NMPlatformLnkVlan *b);
|
||||
int nm_platform_ip4_address_cmp (const NMPlatformIP4Address *a, const NMPlatformIP4Address *b);
|
||||
int nm_platform_ip6_address_cmp (const NMPlatformIP6Address *a, const NMPlatformIP6Address *b);
|
||||
int nm_platform_ip4_route_cmp (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b);
|
||||
|
@@ -1897,5 +1897,13 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = {
|
||||
.cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_ip6_route_to_string,
|
||||
.cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_ip6_route_cmp,
|
||||
},
|
||||
[NMP_OBJECT_TYPE_LNK_VLAN - 1] = {
|
||||
.obj_type = NMP_OBJECT_TYPE_LNK_VLAN,
|
||||
.sizeof_data = sizeof (NMPObjectLnkVlan),
|
||||
.sizeof_public = sizeof (NMPlatformLnkVlan),
|
||||
.obj_type_name = "vlan",
|
||||
.cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_lnk_vlan_to_string,
|
||||
.cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_lnk_vlan_cmp,
|
||||
},
|
||||
};
|
||||
|
||||
|
@@ -157,6 +157,10 @@ typedef struct {
|
||||
} udev;
|
||||
} NMPObjectLink;
|
||||
|
||||
typedef struct {
|
||||
NMPlatformLnkVlan _public;
|
||||
} NMPObjectLnkVlan;
|
||||
|
||||
typedef struct {
|
||||
NMPlatformIP4Address _public;
|
||||
} NMPObjectIP4Address;
|
||||
@@ -183,6 +187,9 @@ struct _NMPObject {
|
||||
NMPlatformLink link;
|
||||
NMPObjectLink _link;
|
||||
|
||||
NMPlatformLnkVlan lnk_vlan;
|
||||
NMPObjectLnkVlan _lnk_vlan;
|
||||
|
||||
NMPlatformIPAddress ip_address;
|
||||
NMPlatformIPXAddress ipx_address;
|
||||
NMPlatformIP4Address ip4_address;
|
||||
|
@@ -22,10 +22,11 @@ dump_interface (NMPlatformLink *link)
|
||||
const NMPlatformIP4Route *ip4_route;
|
||||
char networkstr[INET6_ADDRSTRLEN];
|
||||
char gatewaystr[INET6_ADDRSTRLEN];
|
||||
int vlan_id, vlan_parent;
|
||||
const char *address;
|
||||
size_t addrlen;
|
||||
int i;
|
||||
const NMPlatformLink *plink_vlan;
|
||||
const NMPlatformLnkVlan *plnk;
|
||||
|
||||
g_assert (NM_FLAGS_HAS (link->flags, IFF_UP) || !link->connected);
|
||||
|
||||
@@ -45,10 +46,13 @@ dump_interface (NMPlatformLink *link)
|
||||
if (link->driver)
|
||||
printf (" driver: %s\n", link->driver);
|
||||
printf (" UDI: %s\n", nm_platform_link_get_udi (NM_PLATFORM_GET, link->ifindex));
|
||||
if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, link->ifindex, &vlan_parent, &vlan_id))
|
||||
g_assert_not_reached ();
|
||||
if (vlan_parent)
|
||||
printf (" vlan parent %d id %d\n", vlan_parent, vlan_id);
|
||||
|
||||
plnk = nm_platform_link_get_lnk_vlan (NM_PLATFORM_GET, link->ifindex, &plink_vlan);
|
||||
g_assert (plnk);
|
||||
g_assert_cmpint (link->parent, ==, plink_vlan->parent);
|
||||
|
||||
if (link->parent)
|
||||
printf (" vlan parent %d id %d\n", link->parent, plnk->id);
|
||||
|
||||
if (nm_platform_link_is_software (NM_PLATFORM_GET, link->ifindex))
|
||||
printf (" class software\n");
|
||||
|
@@ -324,13 +324,14 @@ static gboolean
|
||||
do_vlan_get_info (char **argv)
|
||||
{
|
||||
int ifindex = parse_ifindex (*argv++);
|
||||
int parent;
|
||||
int vlanid;
|
||||
const NMPlatformLink *plink;
|
||||
const NMPlatformLnkVlan *plnk;
|
||||
|
||||
if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, ifindex, &parent, &vlanid))
|
||||
plnk = nm_platform_link_get_lnk_vlan (NM_PLATFORM_GET, ifindex, &plink);
|
||||
if (!plnk)
|
||||
return FALSE;
|
||||
|
||||
printf ("%d %d\n", parent, vlanid);
|
||||
printf ("%d %d\n", plink->parent, plnk->id);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ test_bogus(void)
|
||||
g_assert (!nm_platform_link_supports_carrier_detect (NM_PLATFORM_GET, BOGUS_IFINDEX));
|
||||
g_assert (!nm_platform_link_supports_vlans (NM_PLATFORM_GET, BOGUS_IFINDEX));
|
||||
|
||||
g_assert (!nm_platform_vlan_get_info (NM_PLATFORM_GET, BOGUS_IFINDEX, NULL, NULL));
|
||||
g_assert (!nm_platform_link_get_lnk_vlan (NM_PLATFORM_GET, BOGUS_IFINDEX, NULL));
|
||||
g_assert (!nm_platform_vlan_set_ingress_map (NM_PLATFORM_GET, BOGUS_IFINDEX, 0, 0));
|
||||
g_assert (!nm_platform_vlan_set_egress_map (NM_PLATFORM_GET, BOGUS_IFINDEX, 0, 0));
|
||||
}
|
||||
@@ -305,7 +305,7 @@ test_software (NMLinkType link_type, const char *link_typename)
|
||||
{
|
||||
int ifindex;
|
||||
char *value;
|
||||
int vlan_parent, vlan_id;
|
||||
int vlan_parent = -1, vlan_id;
|
||||
|
||||
SignalData *link_added, *link_changed, *link_removed;
|
||||
|
||||
@@ -321,7 +321,15 @@ test_software (NMLinkType link_type, const char *link_typename)
|
||||
link_changed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, link_callback, ifindex);
|
||||
link_removed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, link_callback, ifindex);
|
||||
if (link_type == NM_LINK_TYPE_VLAN) {
|
||||
g_assert (nm_platform_vlan_get_info (NM_PLATFORM_GET, ifindex, &vlan_parent, &vlan_id));
|
||||
const NMPlatformLink *plink;
|
||||
const NMPlatformLnkVlan *plnk;
|
||||
|
||||
plnk = nm_platform_link_get_lnk_vlan (NM_PLATFORM_GET, ifindex, &plink);
|
||||
g_assert (plnk);
|
||||
g_assert (plink);
|
||||
|
||||
vlan_parent = plink->parent;
|
||||
vlan_id = plnk->id;
|
||||
g_assert_cmpint (vlan_parent, ==, nm_platform_link_get_ifindex (NM_PLATFORM_GET, PARENT_NAME));
|
||||
g_assert_cmpint (vlan_id, ==, VLAN_ID);
|
||||
}
|
||||
|
Reference in New Issue
Block a user