platform: implement link_ip6gre_add via nm_platform_link_add()

This commit is contained in:
Thomas Haller
2019-12-31 13:44:08 +01:00
parent bfd74974dc
commit 16fd8ddf95
3 changed files with 48 additions and 108 deletions

View File

@@ -3858,6 +3858,40 @@ _nl_msg_new_link_set_linkinfo (struct nl_msg *msg,
NLA_PUT_U32 (msg, IFLA_IPTUN_FLAGS, props->flags);
break;
}
case NM_LINK_TYPE_IP6GRE:
case NM_LINK_TYPE_IP6GRETAP: {
const NMPlatformLnkIp6Tnl *props = extra_data;
guint32 flowinfo;
nm_assert (props);
nm_assert (props->is_gre);
if (!(data = nla_nest_start (msg, IFLA_INFO_DATA)))
goto nla_put_failure;
if (props->parent_ifindex)
NLA_PUT_U32 (msg, IFLA_GRE_LINK, props->parent_ifindex);
NLA_PUT_U32 (msg, IFLA_GRE_IKEY, htonl (props->input_key));
NLA_PUT_U32 (msg, IFLA_GRE_OKEY, htonl (props->output_key));
NLA_PUT_U16 (msg, IFLA_GRE_IFLAGS, htons (props->input_flags));
NLA_PUT_U16 (msg, IFLA_GRE_OFLAGS, htons (props->output_flags));
if (memcmp (&props->local, &in6addr_any, sizeof (in6addr_any)))
NLA_PUT (msg, IFLA_GRE_LOCAL, sizeof (props->local), &props->local);
if (memcmp (&props->remote, &in6addr_any, sizeof (in6addr_any)))
NLA_PUT (msg, IFLA_GRE_REMOTE, sizeof (props->remote), &props->remote);
NLA_PUT_U8 (msg, IFLA_GRE_TTL, props->ttl);
NLA_PUT_U8 (msg, IFLA_GRE_ENCAP_LIMIT, props->encap_limit);
flowinfo = props->flow_label & IP6_FLOWINFO_FLOWLABEL_MASK;
flowinfo |= (props->tclass << IP6_FLOWINFO_TCLASS_SHIFT)
& IP6_FLOWINFO_TCLASS_MASK;
NLA_PUT_U32 (msg, IFLA_GRE_FLOWINFO, htonl (flowinfo));
NLA_PUT_U32 (msg, IFLA_GRE_FLAGS, props->flags);
break;
}
default:
nm_assert (!extra_data);
break;
@@ -7311,66 +7345,6 @@ link_get_dev_id (NMPlatform *platform, int ifindex)
16, 0, G_MAXUINT16, 0);
}
static gboolean
link_ip6gre_add (NMPlatform *platform,
const char *name,
const NMPlatformLnkIp6Tnl *props,
const NMPlatformLink **out_link)
{
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
struct nlattr *info;
struct nlattr *data;
guint32 flowinfo;
g_return_val_if_fail (props->is_gre, FALSE);
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, props->is_tap ? "ip6gretap" : "ip6gre");
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_IKEY, htonl (props->input_key));
NLA_PUT_U32 (nlmsg, IFLA_GRE_OKEY, htonl (props->output_key));
NLA_PUT_U16 (nlmsg, IFLA_GRE_IFLAGS, htons (props->input_flags));
NLA_PUT_U16 (nlmsg, IFLA_GRE_OFLAGS, htons (props->output_flags));
if (memcmp (&props->local, &in6addr_any, sizeof (in6addr_any)))
NLA_PUT (nlmsg, IFLA_GRE_LOCAL, sizeof (props->local), &props->local);
if (memcmp (&props->remote, &in6addr_any, sizeof (in6addr_any)))
NLA_PUT (nlmsg, IFLA_GRE_REMOTE, sizeof (props->remote), &props->remote);
NLA_PUT_U8 (nlmsg, IFLA_GRE_TTL, props->ttl);
NLA_PUT_U8 (nlmsg, IFLA_GRE_ENCAP_LIMIT, props->encap_limit);
flowinfo = props->flow_label & IP6_FLOWINFO_FLOWLABEL_MASK;
flowinfo |= (props->tclass << IP6_FLOWINFO_TCLASS_SHIFT)
& IP6_FLOWINFO_TCLASS_MASK;
NLA_PUT_U32 (nlmsg, IFLA_GRE_FLOWINFO, htonl (flowinfo));
NLA_PUT_U32 (nlmsg, IFLA_GRE_FLAGS, props->flags);
nla_nest_end (nlmsg, data);
nla_nest_end (nlmsg, info);
return (do_add_link_with_lookup (platform,
props->is_tap ? NM_LINK_TYPE_IP6GRETAP : NM_LINK_TYPE_IP6GRE,
name, nlmsg, out_link) >= 0);
nla_put_failure:
g_return_val_if_reached (FALSE);
}
static gboolean
link_ipip_add (NMPlatform *platform,
const char *name,
@@ -9194,7 +9168,6 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->wpan_set_short_addr = wpan_set_short_addr;
platform_class->wpan_set_channel = wpan_set_channel;
platform_class->link_ip6gre_add = link_ip6gre_add;
platform_class->link_macsec_add = link_macsec_add;
platform_class->link_macvlan_add = link_macvlan_add;
platform_class->link_ipip_add = link_ipip_add;