diff options
author | Thomas Haller <thaller@redhat.com> | 2015-10-12 15:15:21 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-11-01 17:28:09 +0100 |
commit | 3d3762cee318777f931c56d0264fdd45fade182a (patch) | |
tree | daf00ade7fbbcc110c9c7ddd1e0cacce9cf0066a /src | |
parent | 4ab3d71d70fac095aeb407d7752e6ba9bf3666a9 (diff) | |
download | NetworkManager-3d3762cee318777f931c56d0264fdd45fade182a.tar.gz |
platform: implement vxlan properties as lnk data
Diffstat (limited to 'src')
-rw-r--r-- | src/devices/nm-device-vxlan.c | 47 | ||||
-rw-r--r-- | src/nm-types.h | 1 | ||||
-rw-r--r-- | src/platform/nm-fake-platform.c | 7 | ||||
-rw-r--r-- | src/platform/nm-linux-platform.c | 263 | ||||
-rw-r--r-- | src/platform/nm-platform.c | 129 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 7 | ||||
-rw-r--r-- | src/platform/nmp-object.c | 8 | ||||
-rw-r--r-- | src/platform/nmp-object.h | 7 | ||||
-rw-r--r-- | src/platform/tests/platform.c | 49 |
9 files changed, 316 insertions, 202 deletions
diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c index b66f2368fb..7fb55f2086 100644 --- a/src/devices/nm-device-vxlan.c +++ b/src/devices/nm-device-vxlan.c @@ -40,7 +40,7 @@ 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 { - NMPlatformVxlanProperties props; + NMPlatformLnkVxlan props; } NMDeviceVxlanPrivate; enum { @@ -73,53 +73,54 @@ update_properties (NMDevice *device) NMDeviceVxlan *self = NM_DEVICE_VXLAN (device); NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE (device); GObject *object = G_OBJECT (device); - NMPlatformVxlanProperties props; + const NMPlatformLnkVxlan *props; - if (!nm_platform_vxlan_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &props)) { - _LOGW (LOGD_HW, "could not read vxlan properties"); + props = nm_platform_link_get_lnk_vxlan (NM_PLATFORM_GET, nm_device_get_ifindex (device), NULL); + if (!props) { + _LOGW (LOGD_HW, "could not get vxlan properties"); return; } g_object_freeze_notify (object); - if (priv->props.parent_ifindex != props.parent_ifindex) + if (priv->props.parent_ifindex != props->parent_ifindex) g_object_notify (object, NM_DEVICE_VXLAN_PARENT); - if (priv->props.id != props.id) + if (priv->props.id != props->id) g_object_notify (object, NM_DEVICE_VXLAN_ID); - if (priv->props.group != props.group) + if (priv->props.group != props->group) g_object_notify (object, NM_DEVICE_VXLAN_GROUP); - if (priv->props.local != props.local) + if (priv->props.local != props->local) g_object_notify (object, NM_DEVICE_VXLAN_LOCAL); - if (memcmp (&priv->props.group6, &props.group6, sizeof (props.group6)) != 0) + if (memcmp (&priv->props.group6, &props->group6, sizeof (props->group6)) != 0) g_object_notify (object, NM_DEVICE_VXLAN_GROUP); - if (memcmp (&priv->props.local6, &props.local6, sizeof (props.local6)) != 0) + if (memcmp (&priv->props.local6, &props->local6, sizeof (props->local6)) != 0) g_object_notify (object, NM_DEVICE_VXLAN_LOCAL); - if (priv->props.tos != props.tos) + if (priv->props.tos != props->tos) g_object_notify (object, NM_DEVICE_VXLAN_TOS); - if (priv->props.ttl != props.ttl) + if (priv->props.ttl != props->ttl) g_object_notify (object, NM_DEVICE_VXLAN_TTL); - if (priv->props.learning != props.learning) + if (priv->props.learning != props->learning) g_object_notify (object, NM_DEVICE_VXLAN_LEARNING); - if (priv->props.ageing != props.ageing) + if (priv->props.ageing != props->ageing) g_object_notify (object, NM_DEVICE_VXLAN_AGEING); - if (priv->props.limit != props.limit) + if (priv->props.limit != props->limit) g_object_notify (object, NM_DEVICE_VXLAN_LIMIT); - if (priv->props.dst_port != props.dst_port) + if (priv->props.dst_port != props->dst_port) g_object_notify (object, NM_DEVICE_VXLAN_DST_PORT); - if (priv->props.src_port_min != props.src_port_min) + if (priv->props.src_port_min != props->src_port_min) g_object_notify (object, NM_DEVICE_VXLAN_SRC_PORT_MIN); - if (priv->props.src_port_max != props.src_port_max) + if (priv->props.src_port_max != props->src_port_max) g_object_notify (object, NM_DEVICE_VXLAN_SRC_PORT_MAX); - if (priv->props.proxy != props.proxy) + if (priv->props.proxy != props->proxy) g_object_notify (object, NM_DEVICE_VXLAN_PROXY); - if (priv->props.rsc != props.rsc) + if (priv->props.rsc != props->rsc) g_object_notify (object, NM_DEVICE_VXLAN_RSC); - if (priv->props.l2miss != props.l2miss) + if (priv->props.l2miss != props->l2miss) g_object_notify (object, NM_DEVICE_VXLAN_L2MISS); - if (priv->props.l3miss != props.l3miss) + if (priv->props.l3miss != props->l3miss) g_object_notify (object, NM_DEVICE_VXLAN_L3MISS); - memcpy (&priv->props, &props, sizeof (NMPlatformVxlanProperties)); + priv->props = *props; g_object_thaw_notify (object); } diff --git a/src/nm-types.h b/src/nm-types.h index 8088262572..fdcc4dbd6c 100644 --- a/src/nm-types.h +++ b/src/nm-types.h @@ -133,6 +133,7 @@ typedef enum { NMP_OBJECT_TYPE_LNK_GRE, NMP_OBJECT_TYPE_LNK_VLAN, + NMP_OBJECT_TYPE_LNK_VXLAN, __NMP_OBJECT_TYPE_LAST, NMP_OBJECT_TYPE_MAX = __NMP_OBJECT_TYPE_LAST - 1, diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index 3bdbc1cf72..ba7f0694d6 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -730,12 +730,6 @@ macvlan_get_properties (NMPlatform *platform, int ifindex, NMPlatformMacvlanProp } static gboolean -vxlan_get_properties (NMPlatform *platform, int ifindex, NMPlatformVxlanProperties *props) -{ - return FALSE; -} - -static gboolean wifi_get_capabilities (NMPlatform *platform, int ifindex, NMDeviceWifiCapabilities *caps) { NMFakePlatformLink *device = link_get (platform, ifindex); @@ -1469,7 +1463,6 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass) platform_class->veth_get_properties = veth_get_properties; platform_class->macvlan_get_properties = macvlan_get_properties; - platform_class->vxlan_get_properties = vxlan_get_properties; platform_class->wifi_get_capabilities = wifi_get_capabilities; platform_class->wifi_get_bssid = wifi_get_bssid; diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 9649b50903..0336cdcec9 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -960,6 +960,128 @@ _parse_lnk_vlan (const char *kind, struct nlattr *info_data) /*****************************************************************************/ +/* The installed kernel headers might not have VXLAN stuff at all, or + * they might have the original properties, but not PORT, GROUP6, or LOCAL6. + * So until we depend on kernel >= 3.11, we just ignore the actual enum + * in if_link.h and define the values ourselves. + */ +#define IFLA_VXLAN_UNSPEC 0 +#define IFLA_VXLAN_ID 1 +#define IFLA_VXLAN_GROUP 2 +#define IFLA_VXLAN_LINK 3 +#define IFLA_VXLAN_LOCAL 4 +#define IFLA_VXLAN_TTL 5 +#define IFLA_VXLAN_TOS 6 +#define IFLA_VXLAN_LEARNING 7 +#define IFLA_VXLAN_AGEING 8 +#define IFLA_VXLAN_LIMIT 9 +#define IFLA_VXLAN_PORT_RANGE 10 +#define IFLA_VXLAN_PROXY 11 +#define IFLA_VXLAN_RSC 12 +#define IFLA_VXLAN_L2MISS 13 +#define IFLA_VXLAN_L3MISS 14 +#define IFLA_VXLAN_PORT 15 +#define IFLA_VXLAN_GROUP6 16 +#define IFLA_VXLAN_LOCAL6 17 +#undef IFLA_VXLAN_MAX +#define IFLA_VXLAN_MAX IFLA_VXLAN_LOCAL6 + +/* older kernel header might not contain 'struct ifla_vxlan_port_range'. + * Redefine it. */ +struct nm_ifla_vxlan_port_range { + guint16 low; + guint16 high; +}; + +static NMPObject * +_parse_lnk_vxlan (const char *kind, struct nlattr *info_data) +{ + static struct nla_policy policy[IFLA_VXLAN_MAX + 1] = { + [IFLA_VXLAN_ID] = { .type = NLA_U32 }, + [IFLA_VXLAN_GROUP] = { .type = NLA_U32 }, + [IFLA_VXLAN_GROUP6] = { .type = NLA_UNSPEC, + .minlen = sizeof (struct in6_addr) }, + [IFLA_VXLAN_LINK] = { .type = NLA_U32 }, + [IFLA_VXLAN_LOCAL] = { .type = NLA_U32 }, + [IFLA_VXLAN_LOCAL6] = { .type = NLA_UNSPEC, + .minlen = sizeof (struct in6_addr) }, + [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 nm_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 }, + [IFLA_VXLAN_PORT] = { .type = NLA_U16 }, + }; + NMPlatformLnkVxlan *props; + struct nlattr *tb[IFLA_VXLAN_MAX + 1]; + struct nm_ifla_vxlan_port_range *range; + int err; + NMPObject *obj; + + if (!info_data || g_strcmp0 (kind, "vxlan")) + return NULL; + + err = nla_parse_nested (tb, IFLA_VXLAN_MAX, info_data, policy); + if (err < 0) + return NULL; + + obj = nmp_object_new (NMP_OBJECT_TYPE_LNK_VXLAN, NULL); + + props = &obj->lnk_vxlan; + + if (tb[IFLA_VXLAN_LINK]) + props->parent_ifindex = nla_get_u32 (tb[IFLA_VXLAN_LINK]); + if (tb[IFLA_VXLAN_ID]) + props->id = nla_get_u32 (tb[IFLA_VXLAN_ID]); + if (tb[IFLA_VXLAN_GROUP]) + props->group = nla_get_u32 (tb[IFLA_VXLAN_GROUP]); + if (tb[IFLA_VXLAN_LOCAL]) + props->local = nla_get_u32 (tb[IFLA_VXLAN_LOCAL]); + if (tb[IFLA_VXLAN_GROUP6]) + memcpy (&props->group6, nla_data (tb[IFLA_VXLAN_GROUP6]), sizeof (props->group6)); + if (tb[IFLA_VXLAN_LOCAL6]) + memcpy (&props->local6, nla_data (tb[IFLA_VXLAN_LOCAL6]), sizeof (props->local6)); + + if (tb[IFLA_VXLAN_AGEING]) + props->ageing = nla_get_u32 (tb[IFLA_VXLAN_AGEING]); + if (tb[IFLA_VXLAN_LIMIT]) + props->limit = nla_get_u32 (tb[IFLA_VXLAN_LIMIT]); + if (tb[IFLA_VXLAN_TOS]) + props->tos = nla_get_u8 (tb[IFLA_VXLAN_TOS]); + if (tb[IFLA_VXLAN_TTL]) + props->ttl = nla_get_u8 (tb[IFLA_VXLAN_TTL]); + + if (tb[IFLA_VXLAN_PORT]) + props->dst_port = ntohs (nla_get_u16 (tb[IFLA_VXLAN_PORT])); + + if (tb[IFLA_VXLAN_PORT_RANGE]) { + range = nla_data (tb[IFLA_VXLAN_PORT_RANGE]); + props->src_port_min = ntohs (range->low); + props->src_port_max = ntohs (range->high); + } + + if (tb[IFLA_VXLAN_LEARNING]) + props->learning = !!nla_get_u8 (tb[IFLA_VXLAN_LEARNING]); + if (tb[IFLA_VXLAN_PROXY]) + props->proxy = !!nla_get_u8 (tb[IFLA_VXLAN_PROXY]); + if (tb[IFLA_VXLAN_RSC]) + props->rsc = !!nla_get_u8 (tb[IFLA_VXLAN_RSC]); + if (tb[IFLA_VXLAN_L2MISS]) + props->l2miss = !!nla_get_u8 (tb[IFLA_VXLAN_L2MISS]); + if (tb[IFLA_VXLAN_L3MISS]) + props->l3miss = !!nla_get_u8 (tb[IFLA_VXLAN_L3MISS]); + + return obj; +} + +/*****************************************************************************/ + /* Copied and heavily modified from libnl3's link_msg_parser(). */ static NMPObject * _new_from_nl_link (NMPlatform *platform, const NMPCache *cache, struct nlmsghdr *nlh, gboolean id_only) @@ -1106,6 +1228,9 @@ _new_from_nl_link (NMPlatform *platform, const NMPCache *cache, struct nlmsghdr case NM_LINK_TYPE_VLAN: lnk_data = _parse_lnk_vlan (nl_info_kind, nl_info_data); break; + case NM_LINK_TYPE_VXLAN: + lnk_data = _parse_lnk_vxlan (nl_info_kind, nl_info_data); + break; default: goto no_lnk_data; } @@ -3094,6 +3219,10 @@ link_get_lnk (NMPlatform *platform, int ifindex, NMLinkType link_type, const NMP if (NMP_OBJECT_GET_TYPE (obj->_link.netlink.lnk) == NMP_OBJECT_TYPE_LNK_VLAN) return &obj->_link.netlink.lnk->lnk_vlan; break; + case NM_LINK_TYPE_VXLAN: + if (NMP_OBJECT_GET_TYPE (obj->_link.netlink.lnk) == NMP_OBJECT_TYPE_LNK_VXLAN) + return &obj->_link.netlink.lnk->lnk_vxlan; + break; default: break; } @@ -3983,139 +4112,6 @@ macvlan_get_properties (NMPlatform *platform, int ifindex, NMPlatformMacvlanProp /******************************************************************/ -/* The installed kernel headers might not have VXLAN stuff at all, or - * they might have the original properties, but not PORT, GROUP6, or LOCAL6. - * So until we depend on kernel >= 3.11, we just ignore the actual enum - * in if_link.h and define the values ourselves. - */ -#define IFLA_VXLAN_UNSPEC 0 -#define IFLA_VXLAN_ID 1 -#define IFLA_VXLAN_GROUP 2 -#define IFLA_VXLAN_LINK 3 -#define IFLA_VXLAN_LOCAL 4 -#define IFLA_VXLAN_TTL 5 -#define IFLA_VXLAN_TOS 6 -#define IFLA_VXLAN_LEARNING 7 -#define IFLA_VXLAN_AGEING 8 -#define IFLA_VXLAN_LIMIT 9 -#define IFLA_VXLAN_PORT_RANGE 10 -#define IFLA_VXLAN_PROXY 11 -#define IFLA_VXLAN_RSC 12 -#define IFLA_VXLAN_L2MISS 13 -#define IFLA_VXLAN_L3MISS 14 -#define IFLA_VXLAN_PORT 15 -#define IFLA_VXLAN_GROUP6 16 -#define IFLA_VXLAN_LOCAL6 17 -#undef IFLA_VXLAN_MAX -#define IFLA_VXLAN_MAX IFLA_VXLAN_LOCAL6 - -/* older kernel header might not contain 'struct ifla_vxlan_port_range'. - * Redefine it. */ -struct nm_ifla_vxlan_port_range { - guint16 low; - guint16 high; -}; - -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_GROUP6] = { .type = NLA_UNSPEC, - .minlen = sizeof (struct in6_addr) }, - [IFLA_VXLAN_LINK] = { .type = NLA_U32 }, - [IFLA_VXLAN_LOCAL] = { .type = NLA_U32 }, - [IFLA_VXLAN_LOCAL6] = { .type = NLA_UNSPEC, - .minlen = sizeof (struct in6_addr) }, - [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 nm_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 }, - [IFLA_VXLAN_PORT] = { .type = NLA_U16 }, -}; - -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 nm_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; - - memset (props, 0, sizeof (*props)); - - if (tb[IFLA_VXLAN_LINK]) - props->parent_ifindex = nla_get_u32 (tb[IFLA_VXLAN_LINK]); - if (tb[IFLA_VXLAN_ID]) - props->id = nla_get_u32 (tb[IFLA_VXLAN_ID]); - if (tb[IFLA_VXLAN_GROUP]) - props->group = nla_get_u32 (tb[IFLA_VXLAN_GROUP]); - if (tb[IFLA_VXLAN_LOCAL]) - props->local = nla_get_u32 (tb[IFLA_VXLAN_LOCAL]); - if (tb[IFLA_VXLAN_GROUP6]) - memcpy (&props->group6, nla_data (tb[IFLA_VXLAN_GROUP6]), sizeof (props->group6)); - if (tb[IFLA_VXLAN_LOCAL6]) - memcpy (&props->local6, nla_data (tb[IFLA_VXLAN_LOCAL6]), sizeof (props->local6)); - - if (tb[IFLA_VXLAN_AGEING]) - props->ageing = nla_get_u32 (tb[IFLA_VXLAN_AGEING]); - if (tb[IFLA_VXLAN_LIMIT]) - props->limit = nla_get_u32 (tb[IFLA_VXLAN_LIMIT]); - if (tb[IFLA_VXLAN_TOS]) - props->tos = nla_get_u8 (tb[IFLA_VXLAN_TOS]); - if (tb[IFLA_VXLAN_TTL]) - props->ttl = nla_get_u8 (tb[IFLA_VXLAN_TTL]); - - if (tb[IFLA_VXLAN_PORT]) - props->dst_port = ntohs (nla_get_u16 (tb[IFLA_VXLAN_PORT])); - - if (tb[IFLA_VXLAN_PORT_RANGE]) { - range = nla_data (tb[IFLA_VXLAN_PORT_RANGE]); - props->src_port_min = ntohs (range->low); - props->src_port_max = ntohs (range->high); - } - - if (tb[IFLA_VXLAN_LEARNING]) - props->learning = !!nla_get_u8 (tb[IFLA_VXLAN_LEARNING]); - if (tb[IFLA_VXLAN_PROXY]) - props->proxy = !!nla_get_u8 (tb[IFLA_VXLAN_PROXY]); - if (tb[IFLA_VXLAN_RSC]) - props->rsc = !!nla_get_u8 (tb[IFLA_VXLAN_RSC]); - if (tb[IFLA_VXLAN_L2MISS]) - props->l2miss = !!nla_get_u8 (tb[IFLA_VXLAN_L2MISS]); - if (tb[IFLA_VXLAN_L3MISS]) - 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 = _nl_link_parse_info_data (priv->nlh, ifindex, - vxlan_info_data_parser, props); - if (err != 0) { - _LOGW ("(%s) could not read vxlan properties: %s", - nm_platform_link_get_name (platform, ifindex), nl_geterror (err)); - } - return (err == 0); -} - -/******************************************************************/ - static WifiData * wifi_get_wifi_data (NMPlatform *platform, int ifindex) { @@ -5346,7 +5342,6 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass) platform_class->veth_get_properties = veth_get_properties; platform_class->macvlan_get_properties = macvlan_get_properties; - platform_class->vxlan_get_properties = vxlan_get_properties; platform_class->wifi_get_capabilities = wifi_get_capabilities; platform_class->wifi_get_bssid = wifi_get_bssid; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index c3f55b4ab3..42c93ab65e 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1412,6 +1412,12 @@ nm_platform_link_get_lnk_vlan (NMPlatform *self, int ifindex, const NMPlatformLi return nm_platform_link_get_lnk (self, ifindex, NM_LINK_TYPE_VLAN, out_link); } +const NMPlatformLnkVxlan * +nm_platform_link_get_lnk_vxlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link) +{ + return nm_platform_link_get_lnk (self, ifindex, NM_LINK_TYPE_VXLAN, out_link); +} + /*****************************************************************************/ /** @@ -1715,17 +1721,6 @@ nm_platform_macvlan_get_properties (NMPlatform *self, int ifindex, NMPlatformMac } gboolean -nm_platform_vxlan_get_properties (NMPlatform *self, int ifindex, NMPlatformVxlanProperties *props) -{ - _CHECK_SELF (self, klass, FALSE); - - g_return_val_if_fail (ifindex > 0, FALSE); - g_return_val_if_fail (props != NULL, FALSE); - - return klass->vxlan_get_properties (self, ifindex, props); -} - -gboolean nm_platform_wifi_get_capabilities (NMPlatform *self, int ifindex, NMDeviceWifiCapabilities *caps) { _CHECK_SELF (self, klass, FALSE); @@ -2615,6 +2610,93 @@ nm_platform_lnk_vlan_to_string (const NMPlatformLnkVlan *lnk, char *buf, gsize l return buf; } +const char * +nm_platform_lnk_vxlan_to_string (const NMPlatformLnkVxlan *lnk, char *buf, gsize len) +{ + char str_group[100]; + char str_group6[100]; + char str_local[100]; + char str_local6[100]; + char str_dev[25]; + char str_limit[25]; + char str_src_port[35]; + char str_dst_port[25]; + char str_tos[25]; + char str_ttl[25]; + + if (!_to_string_buffer_init (lnk, &buf, &len)) + return buf; + + if (lnk->group == 0) + str_group[0] = '\0'; + else { + g_snprintf (str_group, sizeof (str_group), + " %s %s", + IN_MULTICAST (ntohl (lnk->group)) ? "group" : "remote", + nm_utils_inet4_ntop (lnk->group, NULL)); + } + if (IN6_IS_ADDR_UNSPECIFIED (&lnk->group6)) + str_group6[0] = '\0'; + else { + g_snprintf (str_group6, sizeof (str_group6), + " %s%s %s", + IN6_IS_ADDR_MULTICAST (&lnk->group6) ? "group" : "remote", + str_group[0] ? "6" : "", /* usually, a vxlan has either v4 or v6 only. */ + nm_utils_inet6_ntop (&lnk->group6, NULL)); + } + + if (lnk->local == 0) + str_local[0] = '\0'; + else { + g_snprintf (str_local, sizeof (str_local), + " local %s", + nm_utils_inet4_ntop (lnk->local, NULL)); + } + if (IN6_IS_ADDR_UNSPECIFIED (&lnk->local6)) + str_local6[0] = '\0'; + else { + g_snprintf (str_local6, sizeof (str_local6), + " local%s %s", + str_local[0] ? "6" : "", /* usually, a vxlan has either v4 or v6 only. */ + nm_utils_inet6_ntop (&lnk->local6, NULL)); + } + + g_snprintf (buf, len, + "vxlan" + " id %u" /* id */ + "%s%s" /* group/group6 */ + "%s%s" /* local/local6 */ + "%s" /* dev */ + "%s" /* src_port_min/src_port_max */ + "%s" /* dst_port */ + "%s" /* learning */ + "%s" /* proxy */ + "%s" /* rsc */ + "%s" /* l2miss */ + "%s" /* l3miss */ + "%s" /* tos */ + "%s" /* ttl */ + " ageing %u" /* ageing */ + "%s" /* limit */ + "", + (guint) lnk->id, + str_group, str_group6, + str_local, str_local6, + lnk->parent_ifindex ? nm_sprintf_buf (str_dev, " dev %d", lnk->parent_ifindex) : "", + lnk->src_port_min || lnk->src_port_max ? nm_sprintf_buf (str_src_port, " srcport %u %u", lnk->src_port_min, lnk->src_port_max) : "", + lnk->dst_port ? nm_sprintf_buf (str_dst_port, " dstport %u", lnk->dst_port) : "", + !lnk->learning ? " nolearning" : "", + lnk->proxy ? " proxy" : "", + lnk->rsc ? " rsc" : "", + lnk->l2miss ? " l2miss" : "", + lnk->l3miss ? " l3miss" : "", + lnk->tos == 1 ? " tos inherit" : nm_sprintf_buf (str_tos, " tos %#x", lnk->tos), + lnk->ttl ? nm_sprintf_buf (str_ttl, " ttl %u", lnk->ttl) : "", + lnk->ageing, + lnk->limit ? nm_sprintf_buf (str_limit, " maxaddr %u", lnk->limit) : ""); + return buf; +} + /** * nm_platform_ip4_address_to_string: * @route: pointer to NMPlatformIP4Address address structure @@ -3005,6 +3087,31 @@ nm_platform_lnk_vlan_cmp (const NMPlatformLnkVlan *a, const NMPlatformLnkVlan *b } int +nm_platform_lnk_vxlan_cmp (const NMPlatformLnkVxlan *a, const NMPlatformLnkVxlan *b) +{ + _CMP_SELF (a, b); + _CMP_FIELD (a, b, parent_ifindex); + _CMP_FIELD (a, b, id); + _CMP_FIELD (a, b, group); + _CMP_FIELD (a, b, local); + _CMP_FIELD_MEMCMP (a, b, group6); + _CMP_FIELD_MEMCMP (a, b, local6); + _CMP_FIELD (a, b, tos); + _CMP_FIELD (a, b, ttl); + _CMP_FIELD_BOOL (a, b, learning); + _CMP_FIELD (a, b, ageing); + _CMP_FIELD (a, b, limit); + _CMP_FIELD (a, b, dst_port); + _CMP_FIELD (a, b, src_port_min); + _CMP_FIELD (a, b, src_port_max); + _CMP_FIELD_BOOL (a, b, proxy); + _CMP_FIELD_BOOL (a, b, rsc); + _CMP_FIELD_BOOL (a, b, l2miss); + _CMP_FIELD_BOOL (a, b, l3miss); + return 0; +} + +int nm_platform_ip4_address_cmp (const NMPlatformIP4Address *a, const NMPlatformIP4Address *b) { in_addr_t p_a, p_b; diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index b171035bab..f3ff8be029 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -383,7 +383,7 @@ typedef struct { gboolean rsc; gboolean l2miss; gboolean l3miss; -} NMPlatformVxlanProperties; +} NMPlatformLnkVxlan; typedef struct { int parent_ifindex; @@ -507,7 +507,6 @@ typedef struct { gboolean (*veth_get_properties) (NMPlatform *, int ifindex, NMPlatformVethProperties *properties); gboolean (*macvlan_get_properties) (NMPlatform *, int ifindex, NMPlatformMacvlanProperties *props); - gboolean (*vxlan_get_properties) (NMPlatform *, int ifindex, NMPlatformVxlanProperties *props); gboolean (*wifi_get_capabilities) (NMPlatform *, int ifindex, NMDeviceWifiCapabilities *caps); gboolean (*wifi_get_bssid) (NMPlatform *, int ifindex, guint8 *bssid); @@ -693,6 +692,7 @@ char *nm_platform_slave_get_option (NMPlatform *self, int ifindex, const char *o gconstpointer nm_platform_link_get_lnk (NMPlatform *self, int ifindex, NMLinkType link_type, const NMPlatformLink **out_link); const NMPlatformLnkGre *nm_platform_link_get_lnk_gre (NMPlatform *self, int ifindex, const NMPlatformLink **out_link); const NMPlatformLnkVlan *nm_platform_link_get_lnk_vlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link); +const NMPlatformLnkVxlan *nm_platform_link_get_lnk_vxlan (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_set_ingress_map (NMPlatform *self, int ifindex, int from, int to); @@ -704,7 +704,6 @@ gboolean nm_platform_infiniband_get_info (NMPlatform *self, int ifindex, int *pa gboolean nm_platform_veth_get_properties (NMPlatform *self, int ifindex, NMPlatformVethProperties *properties); gboolean nm_platform_tun_get_properties (NMPlatform *self, int ifindex, NMPlatformTunProperties *properties); gboolean nm_platform_macvlan_get_properties (NMPlatform *self, int ifindex, NMPlatformMacvlanProperties *props); -gboolean nm_platform_vxlan_get_properties (NMPlatform *self, int ifindex, NMPlatformVxlanProperties *props); gboolean nm_platform_tun_get_properties_ifname (NMPlatform *platform, const char *ifname, NMPlatformTunProperties *props); @@ -772,6 +771,7 @@ 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_gre_to_string (const NMPlatformLnkGre *lnk, char *buf, gsize len); const char *nm_platform_lnk_vlan_to_string (const NMPlatformLnkVlan *lnk, char *buf, gsize len); +const char *nm_platform_lnk_vxlan_to_string (const NMPlatformLnkVxlan *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); @@ -780,6 +780,7 @@ const char *nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route, ch int nm_platform_link_cmp (const NMPlatformLink *a, const NMPlatformLink *b); int nm_platform_lnk_gre_cmp (const NMPlatformLnkGre *a, const NMPlatformLnkGre *b); int nm_platform_lnk_vlan_cmp (const NMPlatformLnkVlan *a, const NMPlatformLnkVlan *b); +int nm_platform_lnk_vxlan_cmp (const NMPlatformLnkVxlan *a, const NMPlatformLnkVxlan *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); diff --git a/src/platform/nmp-object.c b/src/platform/nmp-object.c index 79688c162e..bce94dc7eb 100644 --- a/src/platform/nmp-object.c +++ b/src/platform/nmp-object.c @@ -1913,5 +1913,13 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .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, }, + [NMP_OBJECT_TYPE_LNK_VXLAN - 1] = { + .obj_type = NMP_OBJECT_TYPE_LNK_VXLAN, + .sizeof_data = sizeof (NMPObjectLnkVxlan), + .sizeof_public = sizeof (NMPlatformLnkVxlan), + .obj_type_name = "vxlan", + .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_lnk_vxlan_to_string, + .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_lnk_vxlan_cmp, + }, }; diff --git a/src/platform/nmp-object.h b/src/platform/nmp-object.h index 2cc81d1920..157d335c4e 100644 --- a/src/platform/nmp-object.h +++ b/src/platform/nmp-object.h @@ -166,6 +166,10 @@ typedef struct { } NMPObjectLnkVlan; typedef struct { + NMPlatformLnkVxlan _public; +} NMPObjectLnkVxlan; + +typedef struct { NMPlatformIP4Address _public; } NMPObjectIP4Address; @@ -197,6 +201,9 @@ struct _NMPObject { NMPlatformLnkVlan lnk_vlan; NMPObjectLnkVlan _lnk_vlan; + NMPlatformLnkVxlan lnk_vxlan; + NMPObjectLnkVxlan _lnk_vxlan; + NMPlatformIPAddress ip_address; NMPlatformIPXAddress ipx_address; NMPlatformIP4Address ip4_address; diff --git a/src/platform/tests/platform.c b/src/platform/tests/platform.c index 5a1f5f56a6..7868e3cbc0 100644 --- a/src/platform/tests/platform.c +++ b/src/platform/tests/platform.c @@ -418,45 +418,46 @@ static gboolean do_vxlan_get_properties (char **argv) { int ifindex = parse_ifindex (*argv++); - NMPlatformVxlanProperties props; + const NMPlatformLnkVxlan *props; char addrstr[INET6_ADDRSTRLEN]; - if (!nm_platform_vxlan_get_properties (NM_PLATFORM_GET, ifindex, &props)) + props = nm_platform_link_get_lnk_vxlan (NM_PLATFORM_GET, ifindex, NULL); + if (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 if (props.group6.s6_addr[0]) - inet_ntop (AF_INET6, &props.group6, addrstr, sizeof (addrstr)); + 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 if (props->group6.s6_addr[0]) + inet_ntop (AF_INET6, &props->group6, addrstr, sizeof (addrstr)); else strcpy (addrstr, "-"); printf ("group: %s\n", addrstr); - if (props.local) - inet_ntop (AF_INET, &props.local, addrstr, sizeof (addrstr)); - else if (props.local6.s6_addr[0]) - inet_ntop (AF_INET6, &props.local6, addrstr, sizeof (addrstr)); + if (props->local) + inet_ntop (AF_INET, &props->local, addrstr, sizeof (addrstr)); + else if (props->local6.s6_addr[0]) + inet_ntop (AF_INET6, &props->local6, addrstr, sizeof (addrstr)); else strcpy (addrstr, "-"); printf ("local: %s\n", addrstr); - printf ("tos: %u\n", props.tos); - printf ("ttl: %u\n", props.ttl); + 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 ("dst-port: %u\n", props.dst_port); - printf ("src-port-min: %u\n", props.src_port_min); - printf ("src-port-max: %u\n", props.src_port_max); + print_boolean (props->learning); + printf ("ageing: %u\n", props->ageing); + printf ("limit: %u\n", props->limit); + printf ("dst-port: %u\n", props->dst_port); + printf ("src-port-min: %u\n", props->src_port_min); + printf ("src-port-max: %u\n", props->src_port_max); printf ("proxy: "); - print_boolean (props.proxy); + print_boolean (props->proxy); printf ("rsc: "); - print_boolean (props.rsc); + print_boolean (props->rsc); printf ("l2miss: "); - print_boolean (props.l2miss); + print_boolean (props->l2miss); printf ("l3miss: "); - print_boolean (props.l3miss); + print_boolean (props->l3miss); return TRUE; } |