platform: implement link_gre_add via nm_platform_link_add()
This commit is contained in:
@@ -3724,6 +3724,29 @@ _nl_msg_new_link_set_linkinfo (struct nl_msg *msg,
|
|||||||
nla_nest_end (msg, info_peer);
|
nla_nest_end (msg, info_peer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case NM_LINK_TYPE_GRE:
|
||||||
|
case NM_LINK_TYPE_GRETAP: {
|
||||||
|
const NMPlatformLnkGre *props = extra_data;
|
||||||
|
|
||||||
|
nm_assert (props);
|
||||||
|
nm_assert (props->is_tap == (link_type == NM_LINK_TYPE_GRETAP));
|
||||||
|
|
||||||
|
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_LOCAL, props->local);
|
||||||
|
NLA_PUT_U32 (msg, IFLA_GRE_REMOTE, props->remote);
|
||||||
|
NLA_PUT_U8 (msg, IFLA_GRE_TTL, props->ttl);
|
||||||
|
NLA_PUT_U8 (msg, IFLA_GRE_TOS, props->tos);
|
||||||
|
NLA_PUT_U8 (msg, IFLA_GRE_PMTUDISC, !!props->path_mtu_discovery);
|
||||||
|
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));
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
nm_assert (!extra_data);
|
nm_assert (!extra_data);
|
||||||
break;
|
break;
|
||||||
@@ -7212,53 +7235,6 @@ nla_put_failure:
|
|||||||
g_return_val_if_reached (FALSE);
|
g_return_val_if_reached (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
link_gre_add (NMPlatform *platform,
|
|
||||||
const char *name,
|
|
||||||
const NMPlatformLnkGre *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, props->is_tap ? "gretap" : "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_U16 (nlmsg, IFLA_GRE_IFLAGS, htons (props->input_flags));
|
|
||||||
NLA_PUT_U16 (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,
|
|
||||||
props->is_tap ? NM_LINK_TYPE_GRETAP : NM_LINK_TYPE_GRE,
|
|
||||||
name, nlmsg, out_link) >= 0);
|
|
||||||
nla_put_failure:
|
|
||||||
g_return_val_if_reached (FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
link_ip6tnl_add (NMPlatform *platform,
|
link_ip6tnl_add (NMPlatform *platform,
|
||||||
const char *name,
|
const char *name,
|
||||||
@@ -9340,7 +9316,6 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
|
|||||||
platform_class->wpan_set_short_addr = wpan_set_short_addr;
|
platform_class->wpan_set_short_addr = wpan_set_short_addr;
|
||||||
platform_class->wpan_set_channel = wpan_set_channel;
|
platform_class->wpan_set_channel = wpan_set_channel;
|
||||||
|
|
||||||
platform_class->link_gre_add = link_gre_add;
|
|
||||||
platform_class->link_ip6tnl_add = link_ip6tnl_add;
|
platform_class->link_ip6tnl_add = link_ip6tnl_add;
|
||||||
platform_class->link_ip6gre_add = link_ip6gre_add;
|
platform_class->link_ip6gre_add = link_ip6gre_add;
|
||||||
platform_class->link_macsec_add = link_macsec_add;
|
platform_class->link_macsec_add = link_macsec_add;
|
||||||
|
@@ -1208,17 +1208,25 @@ nm_platform_link_add (NMPlatform *self,
|
|||||||
address ? ", address: " : "",
|
address ? ", address: " : "",
|
||||||
address ? nm_utils_hwaddr_ntoa_buf (address, address_len, FALSE, addr_buf, sizeof (addr_buf)) : "",
|
address ? nm_utils_hwaddr_ntoa_buf (address, address_len, FALSE, addr_buf, sizeof (addr_buf)) : "",
|
||||||
({
|
({
|
||||||
const char *str = "";
|
char *buf_p = buf;
|
||||||
|
gsize buf_len = sizeof (buf);
|
||||||
|
|
||||||
|
buf[0] = '\0';
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case NM_LINK_TYPE_VETH:
|
case NM_LINK_TYPE_VETH:
|
||||||
str = nm_sprintf_buf (buf, ", veth-peer \"%s\"", (const char *) extra_data);
|
nm_sprintf_buf (buf, ", veth-peer \"%s\"", (const char *) extra_data);
|
||||||
break;
|
break;
|
||||||
|
case NM_LINK_TYPE_GRE:
|
||||||
|
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);
|
||||||
default:
|
default:
|
||||||
|
nm_assert (!extra_data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
str;
|
buf;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return klass->link_add (self, type, name, parent, address, address_len, extra_data, out_link);
|
return klass->link_add (self, type, name, parent, address, address_len, extra_data, out_link);
|
||||||
@@ -2696,39 +2704,6 @@ nm_platform_link_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, i
|
|||||||
return nm_platform_link_vlan_change (self, ifindex, 0, 0, FALSE, NULL, 0, FALSE, &map, 1);
|
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.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
nm_platform_link_gre_add (NMPlatform *self,
|
|
||||||
const char *name,
|
|
||||||
const NMPlatformLnkGre *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, props->is_tap ? NM_LINK_TYPE_GRETAP : NM_LINK_TYPE_GRE, out_link);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
_LOG2D ("adding link %s", nm_platform_lnk_gre_to_string (props, NULL, 0));
|
|
||||||
|
|
||||||
if (!klass->link_gre_add (self, name, props, out_link))
|
|
||||||
return -NME_UNSPEC;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_infiniband_add_add_or_delete (NMPlatform *self,
|
_infiniband_add_add_or_delete (NMPlatform *self,
|
||||||
int ifindex,
|
int ifindex,
|
||||||
|
@@ -1044,10 +1044,6 @@ typedef struct {
|
|||||||
const char *name,
|
const char *name,
|
||||||
const NMPlatformLnkVxlan *props,
|
const NMPlatformLnkVxlan *props,
|
||||||
const NMPlatformLink **out_link);
|
const NMPlatformLink **out_link);
|
||||||
gboolean (*link_gre_add) (NMPlatform *self,
|
|
||||||
const char *name,
|
|
||||||
const NMPlatformLnkGre *props,
|
|
||||||
const NMPlatformLink **out_link);
|
|
||||||
gboolean (*link_ip6tnl_add) (NMPlatform *self,
|
gboolean (*link_ip6tnl_add) (NMPlatform *self,
|
||||||
const char *name,
|
const char *name,
|
||||||
const NMPlatformLnkIp6Tnl *props,
|
const NMPlatformLnkIp6Tnl *props,
|
||||||
@@ -1425,6 +1421,17 @@ nm_platform_link_wireguard_add (NMPlatform *self,
|
|||||||
return nm_platform_link_add (self, NM_LINK_TYPE_WIREGUARD, name, 0, NULL, 0, NULL, out_link);
|
return nm_platform_link_add (self, NM_LINK_TYPE_WIREGUARD, name, 0, NULL, 0, NULL, out_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
nm_platform_link_gre_add (NMPlatform *self,
|
||||||
|
const char *name,
|
||||||
|
const NMPlatformLnkGre *props,
|
||||||
|
const NMPlatformLink **out_link)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (props, -NME_BUG);
|
||||||
|
|
||||||
|
return nm_platform_link_add (self, props->is_tap ? NM_LINK_TYPE_GRETAP : NM_LINK_TYPE_GRE, name, 0, NULL, 0, props, out_link);
|
||||||
|
}
|
||||||
|
|
||||||
gboolean nm_platform_link_delete (NMPlatform *self, int ifindex);
|
gboolean nm_platform_link_delete (NMPlatform *self, int ifindex);
|
||||||
|
|
||||||
gboolean nm_platform_link_set_netns (NMPlatform *self, int ifindex, int netns_fd);
|
gboolean nm_platform_link_set_netns (NMPlatform *self, int ifindex, int netns_fd);
|
||||||
@@ -1606,10 +1613,6 @@ const struct in6_addr *nm_platform_ip6_address_get_peer (const NMPlatformIP6Addr
|
|||||||
|
|
||||||
const NMPlatformIP4Address *nm_platform_ip4_address_get (NMPlatform *self, int ifindex, in_addr_t address, guint8 plen, in_addr_t peer_address);
|
const NMPlatformIP4Address *nm_platform_ip4_address_get (NMPlatform *self, int ifindex, in_addr_t address, guint8 plen, in_addr_t peer_address);
|
||||||
|
|
||||||
int nm_platform_link_gre_add (NMPlatform *self,
|
|
||||||
const char *name,
|
|
||||||
const NMPlatformLnkGre *props,
|
|
||||||
const NMPlatformLink **out_link);
|
|
||||||
int nm_platform_link_ip6tnl_add (NMPlatform *self,
|
int nm_platform_link_ip6tnl_add (NMPlatform *self,
|
||||||
const char *name,
|
const char *name,
|
||||||
const NMPlatformLnkIp6Tnl *props,
|
const NMPlatformLnkIp6Tnl *props,
|
||||||
|
Reference in New Issue
Block a user