platform: implement link_vxlan_add via nm_platform_link_add()
This commit is contained in:
@@ -323,6 +323,14 @@ link_add (NMPlatform *platform,
|
||||
dev_lnk = nmp_object_new (NMP_OBJECT_TYPE_LNK_VLAN, props);
|
||||
break;
|
||||
}
|
||||
case NM_LINK_TYPE_VXLAN: {
|
||||
const NMPlatformLnkVxlan *props = extra_data;
|
||||
|
||||
g_assert (props);
|
||||
|
||||
dev_lnk = nmp_object_new (NMP_OBJECT_TYPE_LNK_VXLAN, props);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
g_assert (!extra_data);
|
||||
break;
|
||||
@@ -756,35 +764,6 @@ link_vlan_change (NMPlatform *platform,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
_vxlan_add_prepare (NMPlatform *platform,
|
||||
NMFakePlatformLink *device,
|
||||
gconstpointer user_data)
|
||||
{
|
||||
const NMPlatformLnkVxlan *props = user_data;
|
||||
NMPObject *obj_tmp;
|
||||
NMPObject *lnk;
|
||||
|
||||
obj_tmp = (NMPObject *) device->obj;
|
||||
|
||||
lnk = nmp_object_new (NMP_OBJECT_TYPE_LNK_VXLAN, NULL);
|
||||
lnk->lnk_vxlan = *props;
|
||||
|
||||
obj_tmp->link.parent = props->parent_ifindex;
|
||||
obj_tmp->_link.netlink.lnk = lnk;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
link_vxlan_add (NMPlatform *platform,
|
||||
const char *name,
|
||||
const NMPlatformLnkVxlan *props,
|
||||
const NMPlatformLink **out_link)
|
||||
{
|
||||
link_add_one (platform, name, NM_LINK_TYPE_VXLAN,
|
||||
_vxlan_add_prepare, props, out_link);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
struct infiniband_add_data {
|
||||
int parent;
|
||||
int p_key;
|
||||
@@ -1408,7 +1387,6 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
|
||||
platform_class->link_release = link_release;
|
||||
|
||||
platform_class->link_vlan_change = link_vlan_change;
|
||||
platform_class->link_vxlan_add = link_vxlan_add;
|
||||
|
||||
platform_class->infiniband_partition_add = infiniband_partition_add;
|
||||
platform_class->infiniband_partition_delete = infiniband_partition_delete;
|
||||
|
@@ -3727,6 +3727,51 @@ _nl_msg_new_link_set_linkinfo (struct nl_msg *msg,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NM_LINK_TYPE_VXLAN: {
|
||||
const NMPlatformLnkVxlan *props = extra_data;
|
||||
|
||||
nm_assert (extra_data);
|
||||
|
||||
if (!(data = nla_nest_start (msg, IFLA_INFO_DATA)))
|
||||
goto nla_put_failure;
|
||||
|
||||
NLA_PUT_U32 (msg, IFLA_VXLAN_ID, props->id);
|
||||
|
||||
if (props->group)
|
||||
NLA_PUT (msg, IFLA_VXLAN_GROUP, sizeof (props->group), &props->group);
|
||||
else if (memcmp (&props->group6, &in6addr_any, sizeof (in6addr_any)))
|
||||
NLA_PUT (msg, IFLA_VXLAN_GROUP6, sizeof (props->group6), &props->group6);
|
||||
|
||||
if (props->local)
|
||||
NLA_PUT (msg, IFLA_VXLAN_LOCAL, sizeof (props->local), &props->local);
|
||||
else if (memcmp (&props->local6, &in6addr_any, sizeof (in6addr_any)))
|
||||
NLA_PUT (msg, IFLA_VXLAN_LOCAL6, sizeof (props->local6), &props->local6);
|
||||
|
||||
if (props->parent_ifindex >= 0)
|
||||
NLA_PUT_U32 (msg, IFLA_VXLAN_LINK, props->parent_ifindex);
|
||||
|
||||
if ( props->src_port_min
|
||||
|| props->src_port_max) {
|
||||
struct nm_ifla_vxlan_port_range port_range = {
|
||||
.low = htons (props->src_port_min),
|
||||
.high = htons (props->src_port_max),
|
||||
};
|
||||
|
||||
NLA_PUT (msg, IFLA_VXLAN_PORT_RANGE, sizeof (port_range), &port_range);
|
||||
}
|
||||
|
||||
NLA_PUT_U16 (msg, IFLA_VXLAN_PORT, htons (props->dst_port));
|
||||
NLA_PUT_U8 (msg, IFLA_VXLAN_TOS, props->tos);
|
||||
NLA_PUT_U8 (msg, IFLA_VXLAN_TTL, props->ttl);
|
||||
NLA_PUT_U32 (msg, IFLA_VXLAN_AGEING, props->ageing);
|
||||
NLA_PUT_U32 (msg, IFLA_VXLAN_LIMIT, props->limit);
|
||||
NLA_PUT_U8 (msg, IFLA_VXLAN_LEARNING, !!props->learning);
|
||||
NLA_PUT_U8 (msg, IFLA_VXLAN_PROXY, !!props->proxy);
|
||||
NLA_PUT_U8 (msg, IFLA_VXLAN_RSC, !!props->rsc);
|
||||
NLA_PUT_U8 (msg, IFLA_VXLAN_L2MISS, !!props->l2miss);
|
||||
NLA_PUT_U8 (msg, IFLA_VXLAN_L3MISS, !!props->l3miss);
|
||||
break;
|
||||
}
|
||||
case NM_LINK_TYPE_VETH: {
|
||||
const char *veth_peer = extra_data;
|
||||
const struct ifinfomsg ifi = { };
|
||||
@@ -7544,74 +7589,6 @@ link_tun_add (NMPlatform *platform,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
link_vxlan_add (NMPlatform *platform,
|
||||
const char *name,
|
||||
const NMPlatformLnkVxlan *props,
|
||||
const NMPlatformLink **out_link)
|
||||
{
|
||||
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
|
||||
struct nlattr *info;
|
||||
struct nlattr *data;
|
||||
struct nm_ifla_vxlan_port_range port_range;
|
||||
|
||||
g_return_val_if_fail (props, FALSE);
|
||||
|
||||
nlmsg = _nl_msg_new_link (RTM_NEWLINK,
|
||||
NLM_F_CREATE | NLM_F_EXCL,
|
||||
0,
|
||||
name);
|
||||
if (!nlmsg)
|
||||
return FALSE;
|
||||
|
||||
if (!(info = nla_nest_start (nlmsg, IFLA_LINKINFO)))
|
||||
goto nla_put_failure;
|
||||
|
||||
NLA_PUT_STRING (nlmsg, IFLA_INFO_KIND, "vxlan");
|
||||
|
||||
if (!(data = nla_nest_start (nlmsg, IFLA_INFO_DATA)))
|
||||
goto nla_put_failure;
|
||||
|
||||
NLA_PUT_U32 (nlmsg, IFLA_VXLAN_ID, props->id);
|
||||
|
||||
if (props->group)
|
||||
NLA_PUT (nlmsg, IFLA_VXLAN_GROUP, sizeof (props->group), &props->group);
|
||||
else if (memcmp (&props->group6, &in6addr_any, sizeof (in6addr_any)))
|
||||
NLA_PUT (nlmsg, IFLA_VXLAN_GROUP6, sizeof (props->group6), &props->group6);
|
||||
|
||||
if (props->local)
|
||||
NLA_PUT (nlmsg, IFLA_VXLAN_LOCAL, sizeof (props->local), &props->local);
|
||||
else if (memcmp (&props->local6, &in6addr_any, sizeof (in6addr_any)))
|
||||
NLA_PUT (nlmsg, IFLA_VXLAN_LOCAL6, sizeof (props->local6), &props->local6);
|
||||
|
||||
if (props->parent_ifindex >= 0)
|
||||
NLA_PUT_U32 (nlmsg, IFLA_VXLAN_LINK, props->parent_ifindex);
|
||||
|
||||
if (props->src_port_min || props->src_port_max) {
|
||||
port_range.low = htons (props->src_port_min);
|
||||
port_range.high = htons (props->src_port_max);
|
||||
NLA_PUT (nlmsg, IFLA_VXLAN_PORT_RANGE, sizeof (port_range), &port_range);
|
||||
}
|
||||
|
||||
NLA_PUT_U16 (nlmsg, IFLA_VXLAN_PORT, htons (props->dst_port));
|
||||
NLA_PUT_U8 (nlmsg, IFLA_VXLAN_TOS, props->tos);
|
||||
NLA_PUT_U8 (nlmsg, IFLA_VXLAN_TTL, props->ttl);
|
||||
NLA_PUT_U32 (nlmsg, IFLA_VXLAN_AGEING, props->ageing);
|
||||
NLA_PUT_U32 (nlmsg, IFLA_VXLAN_LIMIT, props->limit);
|
||||
NLA_PUT_U8 (nlmsg, IFLA_VXLAN_LEARNING, !!props->learning);
|
||||
NLA_PUT_U8 (nlmsg, IFLA_VXLAN_PROXY, !!props->proxy);
|
||||
NLA_PUT_U8 (nlmsg, IFLA_VXLAN_RSC, !!props->rsc);
|
||||
NLA_PUT_U8 (nlmsg, IFLA_VXLAN_L2MISS, !!props->l2miss);
|
||||
NLA_PUT_U8 (nlmsg, IFLA_VXLAN_L3MISS, !!props->l3miss);
|
||||
|
||||
nla_nest_end (nlmsg, data);
|
||||
nla_nest_end (nlmsg, info);
|
||||
|
||||
return (do_add_link_with_lookup (platform, NM_LINK_TYPE_VXLAN, name, nlmsg, out_link) >= 0);
|
||||
nla_put_failure:
|
||||
g_return_val_if_reached (FALSE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
link_6lowpan_add (NMPlatform *platform,
|
||||
const char *name,
|
||||
@@ -9248,7 +9225,6 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
|
||||
|
||||
platform_class->link_vlan_change = link_vlan_change;
|
||||
platform_class->link_wireguard_change = link_wireguard_change;
|
||||
platform_class->link_vxlan_add = link_vxlan_add;
|
||||
|
||||
platform_class->infiniband_partition_add = infiniband_partition_add;
|
||||
platform_class->infiniband_partition_delete = infiniband_partition_delete;
|
||||
|
@@ -1218,6 +1218,10 @@ nm_platform_link_add (NMPlatform *self,
|
||||
nm_utils_strbuf_append_str (&buf_p, &buf_len, ", ");
|
||||
nm_platform_lnk_vlan_to_string ((const NMPlatformLnkVlan *) extra_data, buf_p, buf_len);
|
||||
break;
|
||||
case NM_LINK_TYPE_VXLAN:
|
||||
nm_utils_strbuf_append_str (&buf_p, &buf_len, ", ");
|
||||
nm_platform_lnk_vxlan_to_string ((const NMPlatformLnkVxlan *) extra_data, buf_p, buf_len);
|
||||
break;
|
||||
case NM_LINK_TYPE_VETH:
|
||||
nm_sprintf_buf (buf, ", veth-peer \"%s\"", (const char *) extra_data);
|
||||
break;
|
||||
@@ -2319,38 +2323,6 @@ nm_platform_link_wireguard_change (NMPlatform *self,
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* nm_platform_link_vxlan_add:
|
||||
* @self: platform instance
|
||||
* @name: New interface name
|
||||
* @props: properties of the new link
|
||||
* @out_link: on success, the link object
|
||||
*
|
||||
* Create a VXLAN device.
|
||||
*/
|
||||
int
|
||||
nm_platform_link_vxlan_add (NMPlatform *self,
|
||||
const char *name,
|
||||
const NMPlatformLnkVxlan *props,
|
||||
const NMPlatformLink **out_link)
|
||||
{
|
||||
int r;
|
||||
|
||||
_CHECK_SELF (self, klass, -NME_BUG);
|
||||
|
||||
g_return_val_if_fail (props, -NME_BUG);
|
||||
|
||||
r = _link_add_check_existing (self, name, NM_LINK_TYPE_VXLAN, out_link);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
_LOG2D ("link: adding link %s", nm_platform_lnk_vxlan_to_string (props, NULL, 0));
|
||||
|
||||
if (!klass->link_vxlan_add (self, name, props, out_link))
|
||||
return -NME_UNSPEC;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_platform_link_tun_add:
|
||||
* @self: platform instance
|
||||
|
@@ -1039,10 +1039,6 @@ typedef struct {
|
||||
gboolean egress_reset_all,
|
||||
const NMVlanQosMapping *egress_map,
|
||||
gsize n_egress_map);
|
||||
gboolean (*link_vxlan_add) (NMPlatform *self,
|
||||
const char *name,
|
||||
const NMPlatformLnkVxlan *props,
|
||||
const NMPlatformLink **out_link);
|
||||
gboolean (*link_ip6tnl_add) (NMPlatform *self,
|
||||
const char *name,
|
||||
const NMPlatformLnkIp6Tnl *props,
|
||||
@@ -1460,6 +1456,15 @@ nm_platform_link_vlan_add (NMPlatform *self,
|
||||
out_link);
|
||||
}
|
||||
|
||||
static inline int
|
||||
nm_platform_link_vxlan_add (NMPlatform *self,
|
||||
const char *name,
|
||||
const NMPlatformLnkVxlan *props,
|
||||
const NMPlatformLink **out_link)
|
||||
{
|
||||
return nm_platform_link_add (self, NM_LINK_TYPE_VXLAN, name, 0, NULL, 0, props, out_link);
|
||||
}
|
||||
|
||||
gboolean nm_platform_link_delete (NMPlatform *self, int ifindex);
|
||||
|
||||
gboolean nm_platform_link_set_netns (NMPlatform *self, int ifindex, int netns_fd);
|
||||
@@ -1588,11 +1593,6 @@ gboolean nm_platform_link_vlan_change (NMPlatform *self,
|
||||
const NMVlanQosMapping *egress_map,
|
||||
gsize n_egress_map);
|
||||
|
||||
int nm_platform_link_vxlan_add (NMPlatform *self,
|
||||
const char *name,
|
||||
const NMPlatformLnkVxlan *props,
|
||||
const NMPlatformLink **out_link);
|
||||
|
||||
int nm_platform_link_infiniband_add (NMPlatform *self,
|
||||
int parent,
|
||||
int p_key,
|
||||
|
Reference in New Issue
Block a user