1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-24 21:34:08 +03:00

networkd: Allow tunnels to be created without .network (#6701)

Now we don't support tunnels to be created without a .network file
that is we need a interface index.

This work allows tunnel to be created without a ifindex.

Closes #6695
This commit is contained in:
Susant Sahani 2017-08-31 16:51:03 +00:00 committed by Lennart Poettering
parent 99f5f8e256
commit 4d7fa6de3b
5 changed files with 88 additions and 30 deletions

View File

@ -847,6 +847,14 @@
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><varname>Independent=</varname></term>
<listitem>
<para>A boolean. When true tunnel does not require .network file. Created as "tunnel@NONE".
Defaults to <literal>false</literal>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>
<refsect1> <refsect1>

View File

@ -56,6 +56,7 @@ Tunnel.Mode, config_parse_ip6tnl_mode, 0,
Tunnel.IPv6FlowLabel, config_parse_ipv6_flowlabel, 0, offsetof(Tunnel, ipv6_flowlabel) Tunnel.IPv6FlowLabel, config_parse_ipv6_flowlabel, 0, offsetof(Tunnel, ipv6_flowlabel)
Tunnel.CopyDSCP, config_parse_bool, 0, offsetof(Tunnel, copy_dscp) Tunnel.CopyDSCP, config_parse_bool, 0, offsetof(Tunnel, copy_dscp)
Tunnel.EncapsulationLimit, config_parse_encap_limit, 0, offsetof(Tunnel, encap_limit) Tunnel.EncapsulationLimit, config_parse_encap_limit, 0, offsetof(Tunnel, encap_limit)
Tunnel.Independent, config_parse_bool, 0, offsetof(Tunnel, independent)
Peer.Name, config_parse_ifname, 0, offsetof(Veth, ifname_peer) Peer.Name, config_parse_ifname, 0, offsetof(Veth, ifname_peer)
Peer.MACAddress, config_parse_hwaddr, 0, offsetof(Veth, mac_peer) Peer.MACAddress, config_parse_hwaddr, 0, offsetof(Veth, mac_peer)
VXLAN.Id, config_parse_uint64, 0, offsetof(VxLan, id) VXLAN.Id, config_parse_uint64, 0, offsetof(VxLan, id)

View File

@ -601,6 +601,7 @@ static int netdev_load_one(Manager *manager, const char *filename) {
_cleanup_free_ NetDev *netdev_raw = NULL; _cleanup_free_ NetDev *netdev_raw = NULL;
_cleanup_fclose_ FILE *file = NULL; _cleanup_fclose_ FILE *file = NULL;
const char *dropin_dirname; const char *dropin_dirname;
bool independent = false;
int r; int r;
assert(manager); assert(manager);
@ -704,13 +705,51 @@ static int netdev_load_one(Manager *manager, const char *filename) {
case NETDEV_CREATE_INDEPENDENT: case NETDEV_CREATE_INDEPENDENT:
r = netdev_create(netdev, NULL, NULL); r = netdev_create(netdev, NULL, NULL);
if (r < 0) if (r < 0)
return 0; return r;
break; break;
default: default:
break; break;
} }
switch (netdev->kind) {
case NETDEV_KIND_IPIP:
independent = IPIP(netdev)->independent;
break;
case NETDEV_KIND_GRE:
independent = GRE(netdev)->independent;
break;
case NETDEV_KIND_GRETAP:
independent = GRETAP(netdev)->independent;
break;
case NETDEV_KIND_IP6GRE:
independent = IP6GRE(netdev)->independent;
break;
case NETDEV_KIND_IP6GRETAP:
independent = IP6GRETAP(netdev)->independent;
break;
case NETDEV_KIND_SIT:
independent = SIT(netdev)->independent;
break;
case NETDEV_KIND_VTI:
independent = VTI(netdev)->independent;
break;
case NETDEV_KIND_VTI6:
independent = VTI6(netdev)->independent;
break;
case NETDEV_KIND_IP6TNL:
independent = IP6TNL(netdev)->independent;
break;
default:
break;
}
if (independent) {
r = netdev_create(netdev, NULL, NULL);
if (r < 0)
return r;
}
netdev = NULL; netdev = NULL;
return 0; return 0;

View File

@ -51,14 +51,16 @@ static int netdev_ipip_fill_message_create(NetDev *netdev, Link *link, sd_netlin
int r; int r;
assert(netdev); assert(netdev);
assert(link);
assert(m); assert(m);
assert(t); assert(t);
assert(IN_SET(t->family, AF_INET, AF_UNSPEC)); assert(IN_SET(t->family, AF_INET, AF_UNSPEC));
r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex); if (link) {
if (r < 0) r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
}
r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in); r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in);
if (r < 0) if (r < 0)
@ -84,14 +86,16 @@ static int netdev_sit_fill_message_create(NetDev *netdev, Link *link, sd_netlink
int r; int r;
assert(netdev); assert(netdev);
assert(link);
assert(m); assert(m);
assert(t); assert(t);
assert(IN_SET(t->family, AF_INET, AF_UNSPEC)); assert(IN_SET(t->family, AF_INET, AF_UNSPEC));
r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex); if (link) {
if (r < 0) r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
}
r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in); r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in);
if (r < 0) if (r < 0)
@ -125,12 +129,13 @@ static int netdev_gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink
assert(t); assert(t);
assert(IN_SET(t->family, AF_INET, AF_UNSPEC)); assert(IN_SET(t->family, AF_INET, AF_UNSPEC));
assert(link);
assert(m); assert(m);
r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex); if (link) {
if (r < 0) r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex);
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m"); if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m");
}
r = sd_netlink_message_append_in_addr(m, IFLA_GRE_LOCAL, &t->local.in); r = sd_netlink_message_append_in_addr(m, IFLA_GRE_LOCAL, &t->local.in);
if (r < 0) if (r < 0)
@ -168,12 +173,13 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netl
assert(t); assert(t);
assert(t->family == AF_INET6); assert(t->family == AF_INET6);
assert(link);
assert(m); assert(m);
r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex); if (link) {
if (r < 0) r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex);
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m"); if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m");
}
r = sd_netlink_message_append_in6_addr(m, IFLA_GRE_LOCAL, &t->local.in6); r = sd_netlink_message_append_in6_addr(m, IFLA_GRE_LOCAL, &t->local.in6);
if (r < 0) if (r < 0)
@ -205,7 +211,6 @@ static int netdev_vti_fill_message_key(NetDev *netdev, Link *link, sd_netlink_me
Tunnel *t; Tunnel *t;
int r; int r;
assert(link);
assert(m); assert(m);
if (netdev->kind == NETDEV_KIND_VTI) if (netdev->kind == NETDEV_KIND_VTI)
@ -243,9 +248,11 @@ static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink
assert(t); assert(t);
assert(t->family == AF_INET); assert(t->family == AF_INET);
r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex); if (link) {
if (r < 0) r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex);
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
}
r = netdev_vti_fill_message_key(netdev, link, m); r = netdev_vti_fill_message_key(netdev, link, m);
if (r < 0) if (r < 0)
@ -267,14 +274,15 @@ static int netdev_vti6_fill_message_create(NetDev *netdev, Link *link, sd_netlin
int r; int r;
assert(netdev); assert(netdev);
assert(link);
assert(m); assert(m);
assert(t); assert(t);
assert(t->family == AF_INET6); assert(t->family == AF_INET6);
r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex); if (link) {
if (r < 0) r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex);
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
}
r = netdev_vti_fill_message_key(netdev, link, m); r = netdev_vti_fill_message_key(netdev, link, m);
if (r < 0) if (r < 0)
@ -297,14 +305,15 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netl
int r; int r;
assert(netdev); assert(netdev);
assert(link);
assert(m); assert(m);
assert(t); assert(t);
assert(t->family == AF_INET6); assert(t->family == AF_INET6);
r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex); if (link) {
if (r < 0) r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
}
r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_LOCAL, &t->local.in6); r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_LOCAL, &t->local.in6);
if (r < 0) if (r < 0)
@ -568,7 +577,7 @@ int config_parse_encap_limit(const char* unit,
const char *section, const char *section,
unsigned section_line, unsigned section_line,
const char *lvalue, const char *lvalue,
int ltype, int ltype,
const char *rvalue, const char *rvalue,
void *data, void *data,
void *userdata) { void *userdata) {

View File

@ -60,6 +60,7 @@ typedef struct Tunnel {
bool pmtudisc; bool pmtudisc;
bool copy_dscp; bool copy_dscp;
bool independent;
} Tunnel; } Tunnel;
DEFINE_NETDEV_CAST(IPIP, Tunnel); DEFINE_NETDEV_CAST(IPIP, Tunnel);