network: add AssignToLoopback= setting to [Tunnel] section

networkd does not manage loopback interface lo. So, previously, we have
no way to assign tunnel devices to lo.
This commit is contained in:
Yu Watanabe 2019-07-10 23:49:17 +09:00
parent 3140e8a55a
commit 8c9c703c55
5 changed files with 20 additions and 10 deletions

View file

@ -1215,6 +1215,13 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>AssignToLoopback=</varname></term>
<listitem>
<para>Takes a boolean. If set to <literal>yes</literal>, the loopback interface <literal>lo</literal>
is used as the underlying device of the tunnel interface. Defaults to <literal>no</literal>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>AllowLocalRemote=</varname></term>
<listitem>

View file

@ -70,6 +70,7 @@ Tunnel.IPv6FlowLabel, config_parse_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)
Tunnel.AssignToLoopback, config_parse_bool, 0, offsetof(Tunnel, assign_to_loopback)
Tunnel.AllowLocalRemote, config_parse_tristate, 0, offsetof(Tunnel, allow_localremote)
Tunnel.FooOverUDP, config_parse_bool, 0, offsetof(Tunnel, fou_tunnel)
Tunnel.FOUDestinationPort, config_parse_ip_port, 0, offsetof(Tunnel, fou_destination_port)

View file

@ -46,8 +46,8 @@ static int netdev_ipip_sit_fill_message_create(NetDev *netdev, Link *link, sd_ne
assert(t);
assert(t->family == AF_INET);
if (link) {
r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
if (link || t->assign_to_loopback) {
r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link ? link->ifindex : LOOPBACK_IFINDEX);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
}
@ -138,8 +138,8 @@ static int netdev_gre_erspan_fill_message_create(NetDev *netdev, Link *link, sd_
assert(t);
assert(t->family == AF_INET);
if (link) {
r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex);
if (link || t->assign_to_loopback) {
r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link ? link->ifindex : LOOPBACK_IFINDEX);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m");
}
@ -242,8 +242,8 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netl
assert(t->family == AF_INET6);
assert(m);
if (link) {
r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex);
if (link || t->assign_to_loopback) {
r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link ? link->ifindex : LOOPBACK_IFINDEX);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m");
}
@ -290,8 +290,8 @@ static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink
assert((netdev->kind == NETDEV_KIND_VTI && t->family == AF_INET) ||
(netdev->kind == NETDEV_KIND_VTI6 && t->family == AF_INET6));
if (link) {
r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex);
if (link || t->assign_to_loopback) {
r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link ? link->ifindex : LOOPBACK_IFINDEX);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VTI_LINK attribute: %m");
}
@ -332,8 +332,8 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netl
assert(t);
assert(t->family == AF_INET6);
if (link) {
r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
if (link || t->assign_to_loopback) {
r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link ? link->ifindex : LOOPBACK_IFINDEX);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
}

View file

@ -51,6 +51,7 @@ typedef struct Tunnel {
bool copy_dscp;
bool independent;
bool fou_tunnel;
bool assign_to_loopback;
uint16_t encap_src_port;
uint16_t fou_destination_port;

View file

@ -66,6 +66,7 @@ AllowLocalRemote=
Local=
TOS=
Independent=
AssignToLoopback=
Key=
InputKey=
Encapsulation=