diff --git a/man/systemd.netdev.xml b/man/systemd.netdev.xml index 3cce776cc22..ff37f26990c 100644 --- a/man/systemd.netdev.xml +++ b/man/systemd.netdev.xml @@ -1215,6 +1215,13 @@ + + AssignToLoopback= + + Takes a boolean. If set to yes, the loopback interface lo + is used as the underlying device of the tunnel interface. Defaults to no. + + AllowLocalRemote= diff --git a/src/network/netdev/netdev-gperf.gperf b/src/network/netdev/netdev-gperf.gperf index 33f7b3058d5..8641d18026b 100644 --- a/src/network/netdev/netdev-gperf.gperf +++ b/src/network/netdev/netdev-gperf.gperf @@ -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) diff --git a/src/network/netdev/tunnel.c b/src/network/netdev/tunnel.c index a59d18d5d90..9ea4d19a2e0 100644 --- a/src/network/netdev/tunnel.c +++ b/src/network/netdev/tunnel.c @@ -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"); } diff --git a/src/network/netdev/tunnel.h b/src/network/netdev/tunnel.h index 3637e4f3772..681e80b0159 100644 --- a/src/network/netdev/tunnel.h +++ b/src/network/netdev/tunnel.h @@ -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; diff --git a/test/fuzz/fuzz-netdev-parser/directives.netdev b/test/fuzz/fuzz-netdev-parser/directives.netdev index 07e54d9e44f..874c3e5f8ff 100644 --- a/test/fuzz/fuzz-netdev-parser/directives.netdev +++ b/test/fuzz/fuzz-netdev-parser/directives.netdev @@ -66,6 +66,7 @@ AllowLocalRemote= Local= TOS= Independent= +AssignToLoopback= Key= InputKey= Encapsulation=