summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2015-09-01 22:11:47 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2015-11-12 17:12:32 +0100
commit162d5216ea66e39f0ee7dc8a898a87f89a773153 (patch)
tree965d5cf9919fa9d0fb98019a5dd31e54dfb5a6a9
parentc36f2aa86155f7f7ac3f6eef0f1566af0b619885 (diff)
downloadNetworkManager-162d5216ea66e39f0ee7dc8a898a87f89a773153.tar.gz
platform: add GRE link creation support
-rw-r--r--src/platform/nm-linux-platform.c53
-rw-r--r--src/platform/nm-platform.c38
-rw-r--r--src/platform/nm-platform.h7
3 files changed, 98 insertions, 0 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 31c8f26cba..f03ab575b2 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -4062,6 +4062,57 @@ vlan_add (NMPlatform *platform,
return do_add_link_with_lookup (platform, NM_LINK_TYPE_VLAN, name, nlmsg, out_link);
nla_put_failure:
+g_return_val_if_reached (FALSE);
+}
+
+static int
+gre_add (NMPlatform *platform,
+ const char *name,
+ NMPlatformLnkGre *lnk_gre,
+ NMPlatformLink *out_link)
+{
+ nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
+ struct nlattr *info;
+ struct nlattr *data;
+ char buffer[INET_ADDRSTRLEN];
+
+ _LOGD ("link: add gre '%s', local %s, remote %s",
+ name,
+ nm_utils_inet4_ntop (lnk_gre->local, NULL),
+ nm_utils_inet4_ntop (lnk_gre->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;
+
+ NLA_PUT_U32 (nlmsg, IFLA_GRE_LOCAL, lnk_gre->local);
+ NLA_PUT_U32 (nlmsg, IFLA_GRE_REMOTE, lnk_gre->remote);
+ NLA_PUT_U8 (nlmsg, IFLA_GRE_TTL, lnk_gre->ttl);
+ NLA_PUT_U8 (nlmsg, IFLA_GRE_TOS, lnk_gre->tos);
+ NLA_PUT_U8 (nlmsg, IFLA_GRE_PMTUDISC, !!lnk_gre->path_mtu_discovery);
+ NLA_PUT_U32 (nlmsg, IFLA_GRE_IKEY, lnk_gre->input_key);
+ NLA_PUT_U32 (nlmsg, IFLA_GRE_OKEY, lnk_gre->output_key);
+ NLA_PUT_U32 (nlmsg, IFLA_GRE_IFLAGS, lnk_gre->input_flags);
+ NLA_PUT_U32 (nlmsg, IFLA_GRE_OFLAGS, lnk_gre->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);
}
@@ -5461,6 +5512,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->gre_add = 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 5124db6147..ceef133373 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -1669,6 +1669,44 @@ 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_gre_add:
+ * @self: platform instance
+ * @name: name of the new interface
+ * @lnk_gre: interface properties
+ * @out_link: on success, the link object
+ *
+ * Create a software GRE device.
+ */
+NMPlatformError
+nm_platform_gre_add (NMPlatform *self,
+ const char *name,
+ NMPlatformLnkGre *lnk_gre,
+ NMPlatformLink *out_link)
+{
+ NMPlatformError plerr;
+ char buffer[INET_ADDRSTRLEN];
+
+ _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+
+ g_return_val_if_fail (lnk_gre, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (klass->gre_add, 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 ("link: adding gre '%s' local %s remote %s",
+ name,
+ nm_utils_inet4_ntop (lnk_gre->local, NULL),
+ nm_utils_inet4_ntop (lnk_gre->remote, buffer));
+
+ if (!klass->gre_add (self, name, lnk_gre, 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 42c3b79390..77fc10b328 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -523,6 +523,9 @@ typedef struct {
const NMVlanQosMapping *egress_map,
gsize n_egress_map);
+ gboolean (*gre_add) (NMPlatform *, const char *name, NMPlatformLnkGre *lnk_gre,
+ NMPlatformLink *out_link);
+
gboolean (*infiniband_partition_add) (NMPlatform *, int parent, int p_key, NMPlatformLink *out_link);
gboolean (*wifi_get_capabilities) (NMPlatform *, int ifindex, NMDeviceWifiCapabilities *caps);
@@ -755,6 +758,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_gre_add (NMPlatform *self, const char *name, NMPlatformLnkGre *lnk_gre,
+ 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);