platform: add vxlan support

Add a new method to the platform code to create vxlan devices.
This commit is contained in:
Beniamino Galvani
2015-10-14 10:01:48 +02:00
parent 7da440b798
commit 01e95c8c95
4 changed files with 137 additions and 1 deletions

View File

@@ -708,6 +708,31 @@ link_vlan_change (NMPlatform *platform,
return FALSE;
}
static gboolean
link_vxlan_add (NMPlatform *platform,
const char *name,
NMPlatformLnkVxlan *props,
NMPlatformLink *out_link)
{
NMFakePlatformLink *device;
if (!link_add (platform, name, NM_LINK_TYPE_VXLAN, NULL, 0, NULL))
return FALSE;
device = link_get (platform, nm_platform_link_get_ifindex (platform, name));
g_return_val_if_fail (device, FALSE);
g_return_val_if_fail (!device->lnk, FALSE);
device->lnk = nmp_object_new (NMP_OBJECT_TYPE_LNK_VXLAN, NULL);
device->lnk->lnk_vxlan = *props;
device->link.parent = props->parent_ifindex;
if (out_link)
*out_link = device->link;
return TRUE;
}
static gboolean
infiniband_partition_add (NMPlatform *platform, int parent, int p_key, NMPlatformLink *out_link)
{
@@ -1458,6 +1483,7 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
platform_class->vlan_add = vlan_add;
platform_class->link_vlan_change = link_vlan_change;
platform_class->link_vxlan_add = link_vxlan_add;
platform_class->infiniband_partition_add = infiniband_partition_add;

View File

@@ -25,6 +25,7 @@
#include <sys/ioctl.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <arpa/inet.h>
#include <netinet/icmp6.h>
#include <netinet/in.h>
#include <linux/ip.h>
@@ -4466,6 +4467,80 @@ nla_put_failure:
g_return_val_if_reached (FALSE);
}
static gboolean
link_vxlan_add (NMPlatform *platform,
const char *name,
NMPlatformLnkVxlan *props,
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);
_LOGD ("link: add vxlan '%s', parent %d, vxlan id %d",
name, props->parent_ifindex, props->id);
nlmsg = _nl_msg_new_link (RTM_NEWLINK,
NLM_F_CREATE,
0,
name,
0,
0);
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);
nla_put_failure:
g_return_val_if_reached (FALSE);
}
static void
_vlan_change_vlan_qos_mapping_create (gboolean is_ingress_map,
gboolean reset_all,
@@ -5899,6 +5974,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->vlan_add = vlan_add;
platform_class->link_vlan_change = link_vlan_change;
platform_class->link_vxlan_add = link_vxlan_add;
platform_class->tun_add = tun_add;

View File

@@ -1559,6 +1559,38 @@ nm_platform_vlan_add (NMPlatform *self,
return NM_PLATFORM_ERROR_SUCCESS;
}
/**
* 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.
*/
NMPlatformError
nm_platform_link_vxlan_add (NMPlatform *self,
const char *name,
NMPlatformLnkVxlan *props,
NMPlatformLink *out_link)
{
NMPlatformError plerr;
_CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_VXLAN, out_link);
if (plerr != NM_PLATFORM_ERROR_SUCCESS)
return plerr;
_LOGD ("link: adding vxlan '%s' parent %d id %d",
name, props->parent_ifindex, props->id);
if (!klass->link_vxlan_add (self, name, props, out_link))
return NM_PLATFORM_ERROR_UNSPECIFIED;
return NM_PLATFORM_ERROR_SUCCESS;
}
/**
* nm_platform_tun_add:
* @self: platform instance
@@ -1596,7 +1628,6 @@ nm_platform_tun_add (NMPlatform *self, const char *name, gboolean tap,
return NM_PLATFORM_ERROR_SUCCESS;
}
gboolean
nm_platform_master_set_option (NMPlatform *self, int ifindex, const char *option, const char *value)
{

View File

@@ -561,6 +561,8 @@ typedef struct {
gboolean egress_reset_all,
const NMVlanQosMapping *egress_map,
gsize n_egress_map);
gboolean (*link_vxlan_add) (NMPlatform *, const char *name, NMPlatformLnkVxlan *props,
NMPlatformLink *out_link);
gboolean (*link_gre_add) (NMPlatform *, const char *name, NMPlatformLnkGre *props,
NMPlatformLink *out_link);
@@ -785,6 +787,7 @@ gboolean nm_platform_link_vlan_change (NMPlatform *self,
const NMVlanQosMapping *egress_map,
gsize n_egress_map);
NMPlatformError nm_platform_link_vxlan_add (NMPlatform *self, const char *name, NMPlatformLnkVxlan *props, NMPlatformLink *out_link);
NMPlatformError nm_platform_tun_add (NMPlatform *self, const char *name, gboolean tap, gint64 owner, gint64 group, gboolean pi,
gboolean vnet_hdr, gboolean multi_queue, NMPlatformLink *out_link);