summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-12-31 11:21:00 +0100
committerThomas Haller <thaller@redhat.com>2020-01-09 10:42:31 +0100
commit4029f9cd2ec63abb67e48636587c4defc22f5b5e (patch)
tree5385e61ca6429bc67ca05e4bf253d3db3cead79c
parent385764398ebe2ca0209ed96fc4d6cf5d99e8efed (diff)
downloadNetworkManager-4029f9cd2ec63abb67e48636587c4defc22f5b5e.tar.gz
platform: implement link_sit_add via nm_platform_link_add()
-rw-r--r--src/platform/nm-linux-platform.c59
-rw-r--r--src/platform/nm-platform.c38
-rw-r--r--src/platform/nm-platform.h13
3 files changed, 31 insertions, 79 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index a23f265ecc..205e98d06f 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -3747,6 +3747,23 @@ _nl_msg_new_link_set_linkinfo (struct nl_msg *msg,
NLA_PUT_U16 (msg, IFLA_GRE_OFLAGS, htons (props->output_flags));
break;
}
+ case NM_LINK_TYPE_SIT: {
+ const NMPlatformLnkSit *props = extra_data;
+
+ nm_assert (props);
+
+ if (!(data = nla_nest_start (msg, IFLA_INFO_DATA)))
+ goto nla_put_failure;
+
+ if (props->parent_ifindex)
+ NLA_PUT_U32 (msg, IFLA_IPTUN_LINK, props->parent_ifindex);
+ NLA_PUT_U32 (msg, IFLA_IPTUN_LOCAL, props->local);
+ NLA_PUT_U32 (msg, IFLA_IPTUN_REMOTE, props->remote);
+ NLA_PUT_U8 (msg, IFLA_IPTUN_TTL, props->ttl);
+ NLA_PUT_U8 (msg, IFLA_IPTUN_TOS, props->tos);
+ NLA_PUT_U8 (msg, IFLA_IPTUN_PMTUDISC, !!props->path_mtu_discovery);
+ break;
+ }
default:
nm_assert (!extra_data);
break;
@@ -7487,47 +7504,6 @@ nla_put_failure:
}
static gboolean
-link_sit_add (NMPlatform *platform,
- const char *name,
- const NMPlatformLnkSit *props,
- const NMPlatformLink **out_link)
-{
- nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
- struct nlattr *info;
- struct nlattr *data;
-
- nlmsg = _nl_msg_new_link (RTM_NEWLINK,
- NLM_F_CREATE | NLM_F_EXCL,
- 0,
- name);
- if (!nlmsg)
- return FALSE;
-
- if (!(info = nla_nest_start (nlmsg, IFLA_LINKINFO)))
- goto nla_put_failure;
-
- NLA_PUT_STRING (nlmsg, IFLA_INFO_KIND, "sit");
-
- if (!(data = nla_nest_start (nlmsg, IFLA_INFO_DATA)))
- goto nla_put_failure;
-
- if (props->parent_ifindex)
- NLA_PUT_U32 (nlmsg, IFLA_IPTUN_LINK, props->parent_ifindex);
- NLA_PUT_U32 (nlmsg, IFLA_IPTUN_LOCAL, props->local);
- NLA_PUT_U32 (nlmsg, IFLA_IPTUN_REMOTE, props->remote);
- NLA_PUT_U8 (nlmsg, IFLA_IPTUN_TTL, props->ttl);
- NLA_PUT_U8 (nlmsg, IFLA_IPTUN_TOS, props->tos);
- NLA_PUT_U8 (nlmsg, IFLA_IPTUN_PMTUDISC, !!props->path_mtu_discovery);
-
- nla_nest_end (nlmsg, data);
- nla_nest_end (nlmsg, info);
-
- return (do_add_link_with_lookup (platform, NM_LINK_TYPE_SIT, name, nlmsg, out_link) >= 0);
-nla_put_failure:
- g_return_val_if_reached (FALSE);
-}
-
-static gboolean
link_tun_add (NMPlatform *platform,
const char *name,
const NMPlatformLnkTun *props,
@@ -9321,7 +9297,6 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->link_macsec_add = link_macsec_add;
platform_class->link_macvlan_add = link_macvlan_add;
platform_class->link_ipip_add = link_ipip_add;
- platform_class->link_sit_add = link_sit_add;
platform_class->link_tun_add = link_tun_add;
platform_class->link_6lowpan_add = link_6lowpan_add;
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 34527d3f73..28c3353aed 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -1221,6 +1221,11 @@ nm_platform_link_add (NMPlatform *self,
case NM_LINK_TYPE_GRETAP:
nm_utils_strbuf_append_str (&buf_p, &buf_len, ", ");
nm_platform_lnk_gre_to_string ((const NMPlatformLnkGre *) extra_data, buf_p, buf_len);
+ break;
+ case NM_LINK_TYPE_SIT:
+ nm_utils_strbuf_append_str (&buf_p, &buf_len, ", ");
+ nm_platform_lnk_sit_to_string ((const NMPlatformLnkSit *) extra_data, buf_p, buf_len);
+ break;
default:
nm_assert (!extra_data);
break;
@@ -3006,39 +3011,6 @@ nm_platform_link_macvlan_add (NMPlatform *self,
return 0;
}
-/**
- * nm_platform_sit_add:
- * @self: platform instance
- * @name: name of the new interface
- * @props: interface properties
- * @out_link: on success, the link object
- *
- * Create a software SIT device.
- */
-int
-nm_platform_link_sit_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkSit *props,
- const NMPlatformLink **out_link)
-{
- int r;
-
- _CHECK_SELF (self, klass, -NME_BUG);
-
- g_return_val_if_fail (props, -NME_BUG);
- g_return_val_if_fail (name, -NME_BUG);
-
- r = _link_add_check_existing (self, name, NM_LINK_TYPE_SIT, out_link);
- if (r < 0)
- return r;
-
- _LOG2D ("adding link %s", nm_platform_lnk_sit_to_string (props, NULL, 0));
-
- if (!klass->link_sit_add (self, name, props, out_link))
- return -NME_UNSPEC;
- return 0;
-}
-
gboolean
nm_platform_link_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_ifindex)
{
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 3cde600084..9c01ba44e1 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -1066,10 +1066,6 @@ typedef struct {
int parent,
const NMPlatformLnkMacvlan *props,
const NMPlatformLink **out_link);
- gboolean (*link_sit_add) (NMPlatform *self,
- const char *name,
- const NMPlatformLnkSit *props,
- const NMPlatformLink **out_link);
gboolean (*link_tun_add) (NMPlatform *self,
const char *name,
const NMPlatformLnkTun *props,
@@ -1432,6 +1428,15 @@ nm_platform_link_gre_add (NMPlatform *self,
return nm_platform_link_add (self, props->is_tap ? NM_LINK_TYPE_GRETAP : NM_LINK_TYPE_GRE, name, 0, NULL, 0, props, out_link);
}
+static inline int
+nm_platform_link_sit_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLnkSit *props,
+ const NMPlatformLink **out_link)
+{
+ return nm_platform_link_add (self, NM_LINK_TYPE_SIT, name, 0, NULL, 0, props, out_link);
+}
+
gboolean nm_platform_link_delete (NMPlatform *self, int ifindex);
gboolean nm_platform_link_set_netns (NMPlatform *self, int ifindex, int netns_fd);