]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: add AssignToLoopback= setting to [Tunnel] section
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 10 Jul 2019 14:49:17 +0000 (23:49 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 11 Jul 2019 00:59:06 +0000 (09:59 +0900)
networkd does not manage loopback interface lo. So, previously, we have
no way to assign tunnel devices to lo.

man/systemd.netdev.xml
src/network/netdev/netdev-gperf.gperf
src/network/netdev/tunnel.c
src/network/netdev/tunnel.h
test/fuzz/fuzz-netdev-parser/directives.netdev

index 3cce776cc226b1f7f74dbcd5d826e3a86719de3a..ff37f26990cfb3de8648a2575efbc15e51c8c583 100644 (file)
           </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>
index 33f7b3058d5ed8dcfb3df660db17499eb8c2c657..8641d18026be4a9d494770796ede9f93ce4afe1d 100644 (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)
index a59d18d5d90188e201bf4f6267ac724b4250e190..9ea4d19a2e0e03a8264aca3563552469117f627e 100644 (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");
         }
index 3637e4f377256c2655aa1daf21a927d070fb38bc..681e80b0159d752011d74f6b36a82f4c472e996d 100644 (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;
index 07e54d9e44f5d0c201c47407ccc981aad4a4d7af..874c3e5f8ff22ae3521402a2e4dcdbc92d2fe915 100644 (file)
@@ -66,6 +66,7 @@ AllowLocalRemote=
 Local=
 TOS=
 Independent=
+AssignToLoopback=
 Key=
 InputKey=
 Encapsulation=