mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +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:
parent
99f5f8e256
commit
4d7fa6de3b
@ -847,6 +847,14 @@
|
||||
</para>
|
||||
</listitem>
|
||||
</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>
|
||||
</refsect1>
|
||||
<refsect1>
|
||||
|
@ -56,6 +56,7 @@ Tunnel.Mode, config_parse_ip6tnl_mode, 0,
|
||||
Tunnel.IPv6FlowLabel, config_parse_ipv6_flowlabel, 0, offsetof(Tunnel, ipv6_flowlabel)
|
||||
Tunnel.CopyDSCP, config_parse_bool, 0, offsetof(Tunnel, copy_dscp)
|
||||
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.MACAddress, config_parse_hwaddr, 0, offsetof(Veth, mac_peer)
|
||||
VXLAN.Id, config_parse_uint64, 0, offsetof(VxLan, id)
|
||||
|
@ -601,6 +601,7 @@ static int netdev_load_one(Manager *manager, const char *filename) {
|
||||
_cleanup_free_ NetDev *netdev_raw = NULL;
|
||||
_cleanup_fclose_ FILE *file = NULL;
|
||||
const char *dropin_dirname;
|
||||
bool independent = false;
|
||||
int r;
|
||||
|
||||
assert(manager);
|
||||
@ -704,13 +705,51 @@ static int netdev_load_one(Manager *manager, const char *filename) {
|
||||
case NETDEV_CREATE_INDEPENDENT:
|
||||
r = netdev_create(netdev, NULL, NULL);
|
||||
if (r < 0)
|
||||
return 0;
|
||||
return r;
|
||||
|
||||
break;
|
||||
default:
|
||||
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;
|
||||
|
||||
return 0;
|
||||
|
@ -51,14 +51,16 @@ static int netdev_ipip_fill_message_create(NetDev *netdev, Link *link, sd_netlin
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
assert(link);
|
||||
assert(m);
|
||||
assert(t);
|
||||
assert(IN_SET(t->family, AF_INET, AF_UNSPEC));
|
||||
|
||||
r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
|
||||
if (link) {
|
||||
r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
|
||||
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);
|
||||
if (r < 0)
|
||||
@ -84,14 +86,16 @@ static int netdev_sit_fill_message_create(NetDev *netdev, Link *link, sd_netlink
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
assert(link);
|
||||
assert(m);
|
||||
assert(t);
|
||||
assert(IN_SET(t->family, AF_INET, AF_UNSPEC));
|
||||
|
||||
r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
|
||||
if (link) {
|
||||
r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
|
||||
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);
|
||||
if (r < 0)
|
||||
@ -125,12 +129,13 @@ static int netdev_gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink
|
||||
|
||||
assert(t);
|
||||
assert(IN_SET(t->family, AF_INET, AF_UNSPEC));
|
||||
assert(link);
|
||||
assert(m);
|
||||
|
||||
r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m");
|
||||
if (link) {
|
||||
r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex);
|
||||
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);
|
||||
if (r < 0)
|
||||
@ -168,12 +173,13 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netl
|
||||
|
||||
assert(t);
|
||||
assert(t->family == AF_INET6);
|
||||
assert(link);
|
||||
assert(m);
|
||||
|
||||
r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m");
|
||||
if (link) {
|
||||
r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex);
|
||||
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);
|
||||
if (r < 0)
|
||||
@ -205,7 +211,6 @@ static int netdev_vti_fill_message_key(NetDev *netdev, Link *link, sd_netlink_me
|
||||
Tunnel *t;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
assert(m);
|
||||
|
||||
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->family == AF_INET);
|
||||
|
||||
r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
|
||||
if (link) {
|
||||
r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex);
|
||||
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);
|
||||
if (r < 0)
|
||||
@ -267,14 +274,15 @@ static int netdev_vti6_fill_message_create(NetDev *netdev, Link *link, sd_netlin
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
assert(link);
|
||||
assert(m);
|
||||
assert(t);
|
||||
assert(t->family == AF_INET6);
|
||||
|
||||
r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
|
||||
if (link) {
|
||||
r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex);
|
||||
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);
|
||||
if (r < 0)
|
||||
@ -297,14 +305,15 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netl
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
assert(link);
|
||||
assert(m);
|
||||
assert(t);
|
||||
assert(t->family == AF_INET6);
|
||||
|
||||
r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
|
||||
if (link) {
|
||||
r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
|
||||
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);
|
||||
if (r < 0)
|
||||
@ -568,7 +577,7 @@ int config_parse_encap_limit(const char* unit,
|
||||
const char *section,
|
||||
unsigned section_line,
|
||||
const char *lvalue,
|
||||
int ltype,
|
||||
int ltype,
|
||||
const char *rvalue,
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
@ -60,6 +60,7 @@ typedef struct Tunnel {
|
||||
|
||||
bool pmtudisc;
|
||||
bool copy_dscp;
|
||||
bool independent;
|
||||
} Tunnel;
|
||||
|
||||
DEFINE_NETDEV_CAST(IPIP, Tunnel);
|
||||
|
Loading…
Reference in New Issue
Block a user