diff --git a/include/NetworkManager.h b/include/NetworkManager.h index 496612033d..f90199d3da 100644 --- a/include/NetworkManager.h +++ b/include/NetworkManager.h @@ -57,6 +57,7 @@ #define NM_DBUS_INTERFACE_DEVICE_VETH NM_DBUS_INTERFACE_DEVICE ".Veth" #define NM_DBUS_INTERFACE_DEVICE_TUN NM_DBUS_INTERFACE_DEVICE ".Tun" #define NM_DBUS_INTERFACE_DEVICE_MACVLAN NM_DBUS_INTERFACE_DEVICE ".Macvlan" +#define NM_DBUS_INTERFACE_DEVICE_VXLAN NM_DBUS_INTERFACE_DEVICE ".Vxlan" #define NM_DBUS_IFACE_SETTINGS "org.freedesktop.NetworkManager.Settings" diff --git a/introspection/Makefile.am b/introspection/Makefile.am index 0f337ce57f..6fb9bd11c7 100644 --- a/introspection/Makefile.am +++ b/introspection/Makefile.am @@ -19,6 +19,7 @@ EXTRA_DIST = \ nm-device-veth.xml \ nm-device-tun.xml \ nm-device-macvlan.xml \ + nm-device-vxlan.xml \ nm-device.xml \ nm-ip4-config.xml \ nm-ip6-config.xml \ diff --git a/introspection/nm-device-vxlan.xml b/introspection/nm-device-vxlan.xml new file mode 100644 index 0000000000..d0c84bdb93 --- /dev/null +++ b/introspection/nm-device-vxlan.xml @@ -0,0 +1,116 @@ + + + + + + + + The object path of the parent device (if the VXLAN is not + purely internal to this host). + + + + + + The VXLAN Network Identifier (VNI). + + + + + + The IP multicast group used to communicate with other physical + hosts on this VXLAN. + + + + + + The local address to use when sending VXLAN packets to other + physical hosts. + + + + + + The value to use in the IP ToS field for VXLAN packets sent to + other physical hosts. + + + + + + The value to use in the IP TTL field for VXLAN packets sent to + other physical hosts. + + + + + + True if the VXLAN dynamically learns remote IP addresses. + + + + + + The interval at which the kernel purges stale cached addresses + (in kernel jiffies, ie, centiseconds). + + + + + + The maximum number of entries that can be added to the VXLAN's + forwarding table. + + + + + + The lowest port number to use for outgoing VXLAN packets. + + + + + + The highest port number to use for outgoing VXLAN packets. + + + + + + True if the VXLAN is implementing DOVE ARP proxying for remote + clients. + + + + + + True if the VXLAN is implementing DOVE route short-circuiting + of known remote IP addresses. + + + + + + True if the VXLAN will emit netlink notifications of L2 switch + misses. + + + + + + True if the VXLAN will emit netlink notifications of L3 switch + misses. + + + + + + + A dictionary mapping property names to variant boxed values + + + + + + diff --git a/src/Makefile.am b/src/Makefile.am index c50612b967..a339e131f2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -91,6 +91,8 @@ nm_sources = \ devices/nm-device-veth.h \ devices/nm-device-vlan.c \ devices/nm-device-vlan.h \ + devices/nm-device-vxlan.c \ + devices/nm-device-vxlan.h \ devices/nm-device-wifi.c \ devices/nm-device-wifi.h \ \ @@ -321,6 +323,7 @@ glue_sources = \ nm-device-tun-glue.h \ nm-device-veth-glue.h \ nm-device-vlan-glue.h \ + nm-device-vxlan-glue.h \ nm-device-wifi-glue.h \ nm-dhcp4-config-glue.h \ nm-dhcp6-config-glue.h \ diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c new file mode 100644 index 0000000000..8bf5528c22 --- /dev/null +++ b/src/devices/nm-device-vxlan.c @@ -0,0 +1,350 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2013 Red Hat, Inc. + */ + +#include "config.h" + +#include + +#include "nm-device-vxlan.h" +#include "nm-dbus-manager.h" +#include "nm-logging.h" +#include "nm-manager.h" +#include "nm-platform.h" + +#include "nm-device-vxlan-glue.h" + +G_DEFINE_TYPE (NMDeviceVxlan, nm_device_vxlan, NM_TYPE_DEVICE_GENERIC) + +#define NM_DEVICE_VXLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_VXLAN, NMDeviceVxlanPrivate)) + +typedef struct { + NMDevice *parent; + NMPlatformVxlanProperties props; +} NMDeviceVxlanPrivate; + +enum { + PROP_0, + PROP_PARENT, + PROP_ID, + PROP_GROUP, + PROP_LOCAL, + PROP_TOS, + PROP_TTL, + PROP_LEARNING, + PROP_AGEING, + PROP_LIMIT, + PROP_PORT_MIN, + PROP_PORT_MAX, + PROP_PROXY, + PROP_RSC, + PROP_L2MISS, + PROP_L3MISS, + + LAST_PROP +}; + +/**************************************************************/ + +static void +link_changed (NMDevice *device) +{ + NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE (device); + GObject *object = G_OBJECT (device); + NMPlatformVxlanProperties props; + + if (!nm_platform_vxlan_get_properties (nm_device_get_ifindex (device), &props)) { + nm_log_warn (LOGD_HW, "(%s): could not read vxlan properties", + nm_device_get_iface (device)); + return; + } + + g_object_freeze_notify (object); + + if (priv->props.parent_ifindex != props.parent_ifindex) { + g_object_notify (object, NM_DEVICE_VXLAN_PARENT); + if (priv->parent) + g_object_remove_weak_pointer (G_OBJECT (priv->parent), (gpointer *) &priv->parent); + priv->parent = nm_manager_get_device_by_ifindex (nm_manager_get (), props.parent_ifindex); + if (priv->parent) + g_object_add_weak_pointer (G_OBJECT (priv->parent), (gpointer *) &priv->parent); + } + + if (priv->props.id != props.id) + g_object_notify (object, NM_DEVICE_VXLAN_ID); + if (priv->props.group != props.group) + g_object_notify (object, NM_DEVICE_VXLAN_GROUP); + if (priv->props.local != props.local) + g_object_notify (object, NM_DEVICE_VXLAN_LOCAL); + if (priv->props.tos != props.tos) + g_object_notify (object, NM_DEVICE_VXLAN_TOS); + if (priv->props.ttl != props.ttl) + g_object_notify (object, NM_DEVICE_VXLAN_TTL); + if (priv->props.learning != props.learning) + g_object_notify (object, NM_DEVICE_VXLAN_LEARNING); + if (priv->props.ageing != props.ageing) + g_object_notify (object, NM_DEVICE_VXLAN_AGEING); + if (priv->props.limit != props.limit) + g_object_notify (object, NM_DEVICE_VXLAN_LIMIT); + if (priv->props.port_min != props.port_min) + g_object_notify (object, NM_DEVICE_VXLAN_PORT_MIN); + if (priv->props.port_max != props.port_max) + g_object_notify (object, NM_DEVICE_VXLAN_PORT_MAX); + if (priv->props.proxy != props.proxy) + g_object_notify (object, NM_DEVICE_VXLAN_PROXY); + if (priv->props.rsc != props.rsc) + g_object_notify (object, NM_DEVICE_VXLAN_RSC); + if (priv->props.l2miss != props.l2miss) + g_object_notify (object, NM_DEVICE_VXLAN_L2MISS); + if (priv->props.l3miss != props.l3miss) + g_object_notify (object, NM_DEVICE_VXLAN_L3MISS); + + memcpy (&priv->props, &props, sizeof (NMPlatformVxlanProperties)); + + g_object_thaw_notify (object); +} + +/**************************************************************/ + +NMDevice * +nm_device_vxlan_new (const char *udi, + const char *iface, + const char *driver) +{ + g_return_val_if_fail (udi != NULL, NULL); + + return (NMDevice *) g_object_new (NM_TYPE_DEVICE_VXLAN, + NM_DEVICE_UDI, udi, + NM_DEVICE_IFACE, iface, + NM_DEVICE_DRIVER, driver, + NM_DEVICE_TYPE_DESC, "Vxlan", + NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC, + NULL); +} + +static void +nm_device_vxlan_init (NMDeviceVxlan *self) +{ +} + +static void +constructed (GObject *object) +{ + link_changed (NM_DEVICE (object)); + + G_OBJECT_CLASS (nm_device_vxlan_parent_class)->constructed (object); +} + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE (object); + char buf[INET_ADDRSTRLEN]; + + switch (prop_id) { + case PROP_PARENT: + g_value_set_boxed (value, priv->parent ? nm_device_get_path (priv->parent) : "/"); + break; + case PROP_ID: + g_value_set_uint (value, priv->props.id); + break; + case PROP_GROUP: + g_value_set_string (value, inet_ntop (AF_INET, &priv->props.group, buf, sizeof (buf))); + break; + case PROP_LOCAL: + g_value_set_string (value, inet_ntop (AF_INET, &priv->props.local, buf, sizeof (buf))); + break; + case PROP_TOS: + g_value_set_uchar (value, priv->props.tos); + break; + case PROP_TTL: + g_value_set_uchar (value, priv->props.ttl); + break; + case PROP_LEARNING: + g_value_set_boolean (value, priv->props.learning); + break; + case PROP_AGEING: + g_value_set_uint (value, priv->props.ageing); + break; + case PROP_LIMIT: + g_value_set_uint (value, priv->props.limit); + break; + case PROP_PORT_MIN: + g_value_set_uint (value, priv->props.port_min); + break; + case PROP_PORT_MAX: + g_value_set_uint (value, priv->props.port_max); + break; + case PROP_PROXY: + g_value_set_uint (value, priv->props.proxy); + break; + case PROP_RSC: + g_value_set_boolean (value, priv->props.rsc); + break; + case PROP_L2MISS: + g_value_set_boolean (value, priv->props.l2miss); + break; + case PROP_L3MISS: + g_value_set_boolean (value, priv->props.l3miss); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +nm_device_vxlan_class_init (NMDeviceVxlanClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); + + g_type_class_add_private (klass, sizeof (NMDeviceVxlanPrivate)); + + object_class->constructed = constructed; + object_class->get_property = get_property; + + device_class->link_changed = link_changed; + + /* properties */ + g_object_class_install_property + (object_class, PROP_PARENT, + g_param_spec_boxed (NM_DEVICE_VXLAN_PARENT, + "Parent", + "Parent device", + DBUS_TYPE_G_OBJECT_PATH, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_ID, + g_param_spec_uint (NM_DEVICE_VXLAN_ID, + "Id", + "Id", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_GROUP, + g_param_spec_string (NM_DEVICE_VXLAN_GROUP, + "Group", + "Group", + NULL, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_LOCAL, + g_param_spec_string (NM_DEVICE_VXLAN_LOCAL, + "Local", + "Local", + NULL, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_TOS, + g_param_spec_uchar (NM_DEVICE_VXLAN_TOS, + "ToS", + "ToS", + 0, 255, 0, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_TTL, + g_param_spec_uchar (NM_DEVICE_VXLAN_TTL, + "TTL", + "TTL", + 0, 255, 0, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_LEARNING, + g_param_spec_boolean (NM_DEVICE_VXLAN_LEARNING, + "Learning", + "Learning", + FALSE, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_AGEING, + g_param_spec_uint (NM_DEVICE_VXLAN_AGEING, + "Ageing", + "Ageing", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_LIMIT, + g_param_spec_uint (NM_DEVICE_VXLAN_LIMIT, + "Limit", + "Limit", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_PORT_MIN, + g_param_spec_uint (NM_DEVICE_VXLAN_PORT_MIN, + "Port min", + "Port min", + 0, 65535, 0, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_PORT_MAX, + g_param_spec_uint (NM_DEVICE_VXLAN_PORT_MAX, + "Port max", + "Port max", + 0, 65535, 0, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_PROXY, + g_param_spec_boolean (NM_DEVICE_VXLAN_PROXY, + "Proxy", + "Proxy", + FALSE, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_RSC, + g_param_spec_boolean (NM_DEVICE_VXLAN_RSC, + "RSC", + "RSC", + FALSE, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_L2MISS, + g_param_spec_boolean (NM_DEVICE_VXLAN_L2MISS, + "L2miss", + "L2miss", + FALSE, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_L3MISS, + g_param_spec_boolean (NM_DEVICE_VXLAN_L3MISS, + "L3miss", + "L3miss", + FALSE, + G_PARAM_READABLE)); + + nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), + G_TYPE_FROM_CLASS (klass), + &dbus_glib_nm_device_vxlan_object_info); +} diff --git a/src/devices/nm-device-vxlan.h b/src/devices/nm-device-vxlan.h new file mode 100644 index 0000000000..734ca07c1c --- /dev/null +++ b/src/devices/nm-device-vxlan.h @@ -0,0 +1,70 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2013 Red Hat, Inc. + */ + +#ifndef NM_DEVICE_VXLAN_H +#define NM_DEVICE_VXLAN_H + +#include + +#include "nm-device-generic.h" + +G_BEGIN_DECLS + +#define NM_TYPE_DEVICE_VXLAN (nm_device_vxlan_get_type ()) +#define NM_DEVICE_VXLAN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_VXLAN, NMDeviceVxlan)) +#define NM_DEVICE_VXLAN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_VXLAN, NMDeviceVxlanClass)) +#define NM_IS_DEVICE_VXLAN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_VXLAN)) +#define NM_IS_DEVICE_VXLAN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_VXLAN)) +#define NM_DEVICE_VXLAN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_VXLAN, NMDeviceVxlanClass)) + +#define NM_DEVICE_VXLAN_PARENT "parent" +#define NM_DEVICE_VXLAN_ID "id" +#define NM_DEVICE_VXLAN_GROUP "group" +#define NM_DEVICE_VXLAN_LOCAL "local" +#define NM_DEVICE_VXLAN_TOS "tos" +#define NM_DEVICE_VXLAN_TTL "ttl" +#define NM_DEVICE_VXLAN_LEARNING "learning" +#define NM_DEVICE_VXLAN_AGEING "ageing" +#define NM_DEVICE_VXLAN_LIMIT "limit" +#define NM_DEVICE_VXLAN_PORT_MIN "port_min" +#define NM_DEVICE_VXLAN_PORT_MAX "port_max" +#define NM_DEVICE_VXLAN_PROXY "proxy" +#define NM_DEVICE_VXLAN_RSC "rsc" +#define NM_DEVICE_VXLAN_L2MISS "l2miss" +#define NM_DEVICE_VXLAN_L3MISS "l3miss" + +typedef struct { + NMDeviceGeneric parent; +} NMDeviceVxlan; + +typedef struct { + NMDeviceGenericClass parent; + +} NMDeviceVxlanClass; + +GType nm_device_vxlan_get_type (void); + +NMDevice *nm_device_vxlan_new (const char *udi, + const char *iface, + const char *driver); + +G_END_DECLS + +#endif /* NM_DEVICE_VXLAN_H */ diff --git a/src/nm-manager.c b/src/nm-manager.c index 625341d67d..5af2301110 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -55,6 +55,7 @@ #include "nm-device-veth.h" #include "nm-device-tun.h" #include "nm-device-macvlan.h" +#include "nm-device-vxlan.h" #include "nm-system.h" #include "nm-setting-bluetooth.h" #include "nm-setting-connection.h" @@ -2302,6 +2303,9 @@ udev_device_added_cb (NMUdevManager *udev_mgr, case NM_LINK_TYPE_MACVTAP: device = nm_device_macvlan_new (sysfs_path, iface, driver); break; + case NM_LINK_TYPE_VXLAN: + device = nm_device_vxlan_new (sysfs_path, iface, driver); + break; default: device = nm_device_generic_new (sysfs_path, iface, driver); diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index 2a18168c4e..727561cdb1 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -576,6 +576,12 @@ macvlan_get_properties (NMPlatform *platform, int ifindex, NMPlatformMacvlanProp return FALSE; } +static gboolean +vxlan_get_properties (NMPlatform *platform, int ifindex, NMPlatformVxlanProperties *props) +{ + return FALSE; +} + /******************************************************************/ static GArray * @@ -1036,6 +1042,7 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass) platform_class->veth_get_properties = veth_get_properties; platform_class->tun_get_properties = tun_get_properties; platform_class->macvlan_get_properties = macvlan_get_properties; + platform_class->vxlan_get_properties = vxlan_get_properties; platform_class->ip4_address_get_all = ip4_address_get_all; platform_class->ip6_address_get_all = ip6_address_get_all; diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index d4643ffa23..a260732801 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -367,6 +367,8 @@ type_to_string (NMLinkType type) return "veth"; case NM_LINK_TYPE_VLAN: return "vlan"; + case NM_LINK_TYPE_VXLAN: + return "vxlan"; case NM_LINK_TYPE_BRIDGE: return "bridge"; case NM_LINK_TYPE_BOND: @@ -436,6 +438,8 @@ link_extract_type (struct rtnl_link *rtnllink, const char **out_name) return_type (NM_LINK_TYPE_VETH, "veth"); else if (!strcmp (type, "vlan")) return_type (NM_LINK_TYPE_VLAN, "vlan"); + else if (!strcmp (type, "vxlan")) + return_type (NM_LINK_TYPE_VXLAN, "vxlan"); else if (!strcmp (type, "bridge")) return_type (NM_LINK_TYPE_BRIDGE, "bridge"); else if (!strcmp (type, "bond")) @@ -1636,6 +1640,69 @@ macvlan_get_properties (NMPlatform *platform, int ifindex, NMPlatformMacvlanProp return (err == 0); } +static const struct nla_policy vxlan_info_policy[IFLA_VXLAN_MAX + 1] = { + [IFLA_VXLAN_ID] = { .type = NLA_U32 }, + [IFLA_VXLAN_GROUP] = { .type = NLA_U32 }, + [IFLA_VXLAN_LINK] = { .type = NLA_U32 }, + [IFLA_VXLAN_LOCAL] = { .type = NLA_U32 }, + [IFLA_VXLAN_TOS] = { .type = NLA_U8 }, + [IFLA_VXLAN_TTL] = { .type = NLA_U8 }, + [IFLA_VXLAN_LEARNING] = { .type = NLA_U8 }, + [IFLA_VXLAN_AGEING] = { .type = NLA_U32 }, + [IFLA_VXLAN_LIMIT] = { .type = NLA_U32 }, + [IFLA_VXLAN_PORT_RANGE] = { .type = NLA_UNSPEC, .minlen = sizeof (struct ifla_vxlan_port_range), .maxlen = sizeof (struct ifla_vxlan_port_range) }, + [IFLA_VXLAN_PROXY] = { .type = NLA_U8 }, + [IFLA_VXLAN_RSC] = { .type = NLA_U8 }, + [IFLA_VXLAN_L2MISS] = { .type = NLA_U8 }, + [IFLA_VXLAN_L3MISS] = { .type = NLA_U8 }, +}; + +static int +vxlan_info_data_parser (struct nlattr *info_data, gpointer parser_data) +{ + NMPlatformVxlanProperties *props = parser_data; + struct nlattr *tb[IFLA_VXLAN_MAX + 1]; + struct ifla_vxlan_port_range *range; + int err; + + err = nla_parse_nested (tb, IFLA_VXLAN_MAX, info_data, + (struct nla_policy *) vxlan_info_policy); + if (err < 0) + return err; + + props->parent_ifindex = tb[IFLA_VXLAN_LINK] ? nla_get_u32 (tb[IFLA_VXLAN_LINK]) : 0; + props->id = nla_get_u32 (tb[IFLA_VXLAN_ID]); + props->group = tb[IFLA_VXLAN_GROUP] ? nla_get_u32 (tb[IFLA_VXLAN_GROUP]) : 0; + props->local = tb[IFLA_VXLAN_LOCAL] ? nla_get_u32 (tb[IFLA_VXLAN_LOCAL]) : 0; + props->ageing = nla_get_u32 (tb[IFLA_VXLAN_AGEING]); + props->limit = nla_get_u32 (tb[IFLA_VXLAN_LIMIT]); + props->tos = nla_get_u8 (tb[IFLA_VXLAN_TOS]); + props->ttl = nla_get_u8 (tb[IFLA_VXLAN_TTL]); + + range = nla_data (tb[IFLA_VXLAN_TTL]); + props->port_min = range->low; + props->port_max = range->high; + + props->learning = nla_get_u8 (tb[IFLA_VXLAN_LEARNING]); + props->proxy = nla_get_u8 (tb[IFLA_VXLAN_PROXY]); + props->rsc = nla_get_u8 (tb[IFLA_VXLAN_RSC]); + props->l2miss = nla_get_u8 (tb[IFLA_VXLAN_L2MISS]); + props->l3miss = nla_get_u8 (tb[IFLA_VXLAN_L3MISS]); + + return 0; +} + +static gboolean +vxlan_get_properties (NMPlatform *platform, int ifindex, NMPlatformVxlanProperties *props) +{ + NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform); + int err; + + err = nm_rtnl_link_parse_info_data (priv->nlh, ifindex, + vxlan_info_data_parser, props); + return (err == 0); +} + /******************************************************************/ static int @@ -2121,6 +2188,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass) platform_class->veth_get_properties = veth_get_properties; platform_class->tun_get_properties = tun_get_properties; platform_class->macvlan_get_properties = macvlan_get_properties; + platform_class->vxlan_get_properties = vxlan_get_properties; platform_class->ip4_address_get_all = ip4_address_get_all; platform_class->ip6_address_get_all = ip6_address_get_all; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index f030b85f9d..2a47d541b5 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -934,6 +934,17 @@ nm_platform_macvlan_get_properties (int ifindex, NMPlatformMacvlanProperties *pr return klass->macvlan_get_properties (platform, ifindex, props); } +gboolean +nm_platform_vxlan_get_properties (int ifindex, NMPlatformVxlanProperties *props) +{ + reset_error (); + + g_return_val_if_fail (ifindex > 0, FALSE); + g_return_val_if_fail (props != NULL, FALSE); + + return klass->vxlan_get_properties (platform, ifindex, props); +} + /******************************************************************/ GArray * diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 826856b9ed..02d8413352 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -65,6 +65,7 @@ typedef enum { NM_LINK_TYPE_TUN, NM_LINK_TYPE_VETH, NM_LINK_TYPE_VLAN, + NM_LINK_TYPE_VXLAN, /* Virtual types with slaves */ NM_LINK_TYPE_BRIDGE, @@ -134,6 +135,24 @@ typedef struct { gboolean no_promisc; } NMPlatformMacvlanProperties; +typedef struct { + int parent_ifindex; + guint32 id; + in_addr_t group; + in_addr_t local; + guint8 tos; + guint8 ttl; + gboolean learning; + guint32 ageing; + guint32 limit; + guint16 port_min; + guint16 port_max; + gboolean proxy; + gboolean rsc; + gboolean l2miss; + gboolean l3miss; +} NMPlatformVxlanProperties; + /******************************************************************/ /* NMPlatform abstract class and its implementations provide a layer between @@ -218,6 +237,7 @@ typedef struct { gboolean (*veth_get_properties) (NMPlatform *, int ifindex, NMPlatformVethProperties *properties); gboolean (*tun_get_properties) (NMPlatform *, int ifindex, NMPlatformTunProperties *properties); gboolean (*macvlan_get_properties) (NMPlatform *, int ifindex, NMPlatformMacvlanProperties *props); + gboolean (*vxlan_get_properties) (NMPlatform *, int ifindex, NMPlatformVxlanProperties *props); GArray * (*ip4_address_get_all) (NMPlatform *, int ifindex); GArray * (*ip6_address_get_all) (NMPlatform *, int ifindex); @@ -329,6 +349,7 @@ gboolean nm_platform_vlan_set_egress_map (int ifindex, int from, int to); gboolean nm_platform_veth_get_properties (int ifindex, NMPlatformVethProperties *properties); gboolean nm_platform_tun_get_properties (int ifindex, NMPlatformTunProperties *properties); gboolean nm_platform_macvlan_get_properties (int ifindex, NMPlatformMacvlanProperties *props); +gboolean nm_platform_vxlan_get_properties (int ifindex, NMPlatformVxlanProperties *props); GArray *nm_platform_ip4_address_get_all (int ifindex); GArray *nm_platform_ip6_address_get_all (int ifindex); diff --git a/src/platform/tests/platform.c b/src/platform/tests/platform.c index 6661fe1abc..821b62f701 100644 --- a/src/platform/tests/platform.c +++ b/src/platform/tests/platform.c @@ -400,6 +400,48 @@ do_macvlan_get_properties (char **argv) return TRUE; } +static gboolean +do_vxlan_get_properties (char **argv) +{ + int ifindex = parse_ifindex (*argv++); + NMPlatformVxlanProperties props; + char addrstr[INET_ADDRSTRLEN]; + + if (!nm_platform_vxlan_get_properties (ifindex, &props)) + return FALSE; + + printf ("parent-ifindex: %u\n", props.parent_ifindex); + printf ("id: %u\n", props.id); + if (props.group) + inet_ntop (AF_INET, &props.group, addrstr, sizeof (addrstr)); + else + strcpy (addrstr, "-"); + printf ("group: %s\n", addrstr); + if (props.local) + inet_ntop (AF_INET, &props.local, addrstr, sizeof (addrstr)); + else + strcpy (addrstr, "-"); + printf ("local: %s\n", addrstr); + printf ("tos: %u\n", props.tos); + printf ("ttl: %u\n", props.ttl); + printf ("learning: "); + print_boolean (props.learning); + printf ("ageing: %u\n", props.ageing); + printf ("limit: %u\n", props.limit); + printf ("port-min: %u\n", props.port_min); + printf ("port-max: %u\n", props.port_max); + printf ("proxy: "); + print_boolean (props.proxy); + printf ("rsc: "); + print_boolean (props.rsc); + printf ("l2miss: "); + print_boolean (props.l2miss); + printf ("l3miss: "); + print_boolean (props.l3miss); + + return TRUE; +} + static gboolean do_ip4_address_get_all (char **argv) { @@ -690,6 +732,8 @@ static const command_t commands[] = { "" }, { "macvlan-get-properties", "get macvlan properties", do_macvlan_get_properties, 1, "" }, + { "vxlan-get-properties", "get vxlan properties", do_vxlan_get_properties, 1, + "" }, { "ip4-address-get-all", "print all IPv4 addresses", do_ip4_address_get_all, 1, "" }, { "ip6-address-get-all", "print all IPv6 addresses", do_ip6_address_get_all, 1, "" }, { "ip4-address-add", "add IPv4 address", do_ip4_address_add, 2, "
/" },