summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2015-09-01 22:11:47 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2015-12-01 17:39:41 +0100
commit91bf0efaa7dbfed84954192a449f6770d20105c1 (patch)
treec3a4e2c5e9a31613dadc889b9b714f52f7c04c68
parentb614a5ec6174bd6dce1ea9593160dd7164fdbd57 (diff)
downloadNetworkManager-91bf0efaa7dbfed84954192a449f6770d20105c1.tar.gz
platform: add GRE links creation support
-rw-r--r--src/platform/nm-linux-platform.c67
-rw-r--r--src/platform/nm-platform.c41
-rw-r--r--src/platform/nm-platform.h10
3 files changed, 114 insertions, 4 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index b79aa76767..27d04d1772 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -118,6 +118,8 @@
} \
} G_STMT_END
+#define LOG_FMT_IP_TUNNEL "adding %s '%s' parent %u local %s remote %s"
+
/******************************************************************
* Forward declarations and enums
******************************************************************/
@@ -821,10 +823,10 @@ _parse_lnk_gre (const char *kind, struct nlattr *info_data)
props = &obj->lnk_gre;
props->parent_ifindex = tb[IFLA_GRE_LINK] ? nla_get_u32 (tb[IFLA_GRE_LINK]) : 0;
- props->input_flags = tb[IFLA_GRE_IFLAGS] ? nla_get_u16 (tb[IFLA_GRE_IFLAGS]) : 0;
- props->output_flags = tb[IFLA_GRE_OFLAGS] ? nla_get_u16 (tb[IFLA_GRE_OFLAGS]) : 0;
- props->input_key = (props->input_flags & GRE_KEY) && tb[IFLA_GRE_IKEY] ? nla_get_u32 (tb[IFLA_GRE_IKEY]) : 0;
- props->output_key = (props->output_flags & GRE_KEY) && tb[IFLA_GRE_OKEY] ? nla_get_u32 (tb[IFLA_GRE_OKEY]) : 0;
+ props->input_flags = tb[IFLA_GRE_IFLAGS] ? ntohs (nla_get_u16 (tb[IFLA_GRE_IFLAGS])) : 0;
+ props->output_flags = tb[IFLA_GRE_OFLAGS] ? ntohs (nla_get_u16 (tb[IFLA_GRE_OFLAGS])) : 0;
+ props->input_key = tb[IFLA_GRE_IKEY] ? ntohl (nla_get_u32 (tb[IFLA_GRE_IKEY])) : 0;
+ props->output_key = tb[IFLA_GRE_OKEY] ? ntohl (nla_get_u32 (tb[IFLA_GRE_OKEY])) : 0;
props->local = tb[IFLA_GRE_LOCAL] ? nla_get_u32 (tb[IFLA_GRE_LOCAL]) : 0;
props->remote = tb[IFLA_GRE_REMOTE] ? nla_get_u32 (tb[IFLA_GRE_REMOTE]) : 0;
props->tos = tb[IFLA_GRE_TOS] ? nla_get_u8 (tb[IFLA_GRE_TOS]) : 0;
@@ -4034,6 +4036,61 @@ nla_put_failure:
g_return_val_if_reached (FALSE);
}
+static int
+link_gre_add (NMPlatform *platform,
+ const char *name,
+ NMPlatformLnkGre *props,
+ NMPlatformLink *out_link)
+{
+ nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
+ struct nlattr *info;
+ struct nlattr *data;
+ char buffer[INET_ADDRSTRLEN];
+
+ _LOGD (LOG_FMT_IP_TUNNEL,
+ "gre",
+ name,
+ props->parent_ifindex,
+ nm_utils_inet4_ntop (props->local, NULL),
+ nm_utils_inet4_ntop (props->remote, buffer));
+
+ 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, "gre");
+
+ if (!(data = nla_nest_start (nlmsg, IFLA_INFO_DATA)))
+ goto nla_put_failure;
+
+ if (props->parent_ifindex)
+ NLA_PUT_U32 (nlmsg, IFLA_GRE_LINK, props->parent_ifindex);
+ NLA_PUT_U32 (nlmsg, IFLA_GRE_LOCAL, props->local);
+ NLA_PUT_U32 (nlmsg, IFLA_GRE_REMOTE, props->remote);
+ NLA_PUT_U8 (nlmsg, IFLA_GRE_TTL, props->ttl);
+ NLA_PUT_U8 (nlmsg, IFLA_GRE_TOS, props->tos);
+ NLA_PUT_U8 (nlmsg, IFLA_GRE_PMTUDISC, !!props->path_mtu_discovery);
+ NLA_PUT_U32 (nlmsg, IFLA_GRE_IKEY, htonl (props->input_key));
+ NLA_PUT_U32 (nlmsg, IFLA_GRE_OKEY, htonl (props->output_key));
+ NLA_PUT_U32 (nlmsg, IFLA_GRE_IFLAGS, htons (props->input_flags));
+ NLA_PUT_U32 (nlmsg, IFLA_GRE_OFLAGS, htons (props->output_flags));
+
+ nla_nest_end (nlmsg, data);
+ nla_nest_end (nlmsg, info);
+
+ return do_add_link_with_lookup (platform, NM_LINK_TYPE_GRE, 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,
@@ -5487,6 +5544,8 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->mesh_set_channel = mesh_set_channel;
platform_class->mesh_set_ssid = mesh_set_ssid;
+ platform_class->link_gre_add = link_gre_add;
+
platform_class->ip4_address_get = ip4_address_get;
platform_class->ip6_address_get = ip6_address_get;
platform_class->ip4_address_get_all = ip4_address_get_all;
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index bb82ab0959..fb8924ef2a 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -71,6 +71,8 @@ G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPRoute, network_ptr) == G_STRUCT_OF
} \
} G_STMT_END
+#define LOG_FMT_IP_TUNNEL "adding %s '%s' parent %u local %s remote %s"
+
/*****************************************************************************/
#define NM_PLATFORM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PLATFORM, NMPlatformPrivate))
@@ -1709,6 +1711,45 @@ nm_platform_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to
return nm_platform_link_vlan_change (self, ifindex, 0, 0, FALSE, NULL, 0, FALSE, &map, 1);
}
+/**
+ * nm_platform_link_gre_add:
+ * @self: platform instance
+ * @name: name of the new interface
+ * @props: interface properties
+ * @out_link: on success, the link object
+ *
+ * Create a software GRE device.
+ */
+NMPlatformError
+nm_platform_link_gre_add (NMPlatform *self,
+ const char *name,
+ NMPlatformLnkGre *props,
+ NMPlatformLink *out_link)
+{
+ NMPlatformError plerr;
+ char buffer[INET_ADDRSTRLEN];
+
+ _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+
+ g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
+
+ plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_GRE, out_link);
+ if (plerr != NM_PLATFORM_ERROR_SUCCESS)
+ return plerr;
+
+ _LOGD (LOG_FMT_IP_TUNNEL,
+ "gre",
+ name,
+ props->parent_ifindex,
+ nm_utils_inet4_ntop (props->local, NULL),
+ nm_utils_inet4_ntop (props->remote, buffer));
+
+ if (!klass->link_gre_add (self, name, props, out_link))
+ return NM_PLATFORM_ERROR_UNSPECIFIED;
+ return NM_PLATFORM_ERROR_SUCCESS;
+}
+
NMPlatformError
nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, NMPlatformLink *out_link)
{
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 00029b3aeb..432c29c150 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -63,6 +63,9 @@ typedef struct _NMPlatform NMPlatform;
#define NM_IFF_MULTI_QUEUE 0x0100 /* IFF_MULTI_QUEUE */
+/* Redefine this in host's endianness */
+#define NM_GRE_KEY 0x2000
+
typedef enum { /*< skip >*/
/* dummy value, to enforce that the enum type is signed and has a size
@@ -524,6 +527,9 @@ typedef struct {
const NMVlanQosMapping *egress_map,
gsize n_egress_map);
+ gboolean (*link_gre_add) (NMPlatform *, const char *name, NMPlatformLnkGre *props,
+ NMPlatformLink *out_link);
+
gboolean (*infiniband_partition_add) (NMPlatform *, int parent, int p_key, NMPlatformLink *out_link);
gboolean (*tun_add) (NMPlatform *platform, const char *name, gboolean tap, gint64 owner, gint64 group, gboolean pi,
@@ -762,6 +768,10 @@ void nm_platform_ip4_address_set_addr (NMPlatformIP4Address *a
const struct in6_addr *nm_platform_ip6_address_get_peer (const NMPlatformIP6Address *addr);
const NMPlatformIP4Address *nm_platform_ip4_address_get (NMPlatform *self, int ifindex, in_addr_t address, int plen, in_addr_t peer_address);
+
+NMPlatformError nm_platform_link_gre_add (NMPlatform *self, const char *name, NMPlatformLnkGre *props,
+ NMPlatformLink *out_link);
+
const NMPlatformIP6Address *nm_platform_ip6_address_get (NMPlatform *self, int ifindex, struct in6_addr address, int plen);
GArray *nm_platform_ip4_address_get_all (NMPlatform *self, int ifindex);
GArray *nm_platform_ip6_address_get_all (NMPlatform *self, int ifindex);