]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/tunnel: make sit and ipip tunnel support Mode= setting
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 16 Jun 2025 07:47:49 +0000 (16:47 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 16 Jun 2025 08:01:20 +0000 (17:01 +0900)
Closing #37377.

man/systemd.netdev.xml
src/network/netdev/tunnel.c
src/network/netdev/tunnel.h

index a3f62e157c8cb69b0f38d7b1ccc1423bb4b384fc..65812aca51ffaee50a12dc71fe7c6cc982cebf49 100644 (file)
@@ -1671,6 +1671,28 @@ Ports=eth2</programlisting>
                 </row>
               </thead>
               <tbody>
+                <row>
+                  <entry morerows="1"><literal>ipip</literal></entry>
+                  <entry><literal>ipip</literal></entry>
+                  <entry>IPv4 over IPv4 (default)</entry>
+                </row>
+                <row>
+                  <entry><literal>any</literal></entry>
+                  <entry>both IPv4 and IPv6 over IPv4</entry>
+                </row>
+                <row>
+                  <entry morerows="2"><literal>sit</literal></entry>
+                  <entry><literal>ipip</literal></entry>
+                  <entry>IPv4 over IPv4</entry>
+                </row>
+                <row>
+                  <entry><literal>ip6ip</literal></entry>
+                  <entry>IPv6 over IPv4 (default)</entry>
+                </row>
+                <row>
+                  <entry><literal>any</literal></entry>
+                  <entry>both IPv4 and IPv6 over IPv4</entry>
+                </row>
                 <row>
                   <entry morerows="2"><literal>ip6tnl</literal></entry>
                   <entry><literal>ipip6</literal></entry>
index aaad0f32c1696e6e2fa4e950f3ee8206b58f9365..29f353d84904f18ffc32e02668351f69bf8c5932 100644 (file)
 
 static const uint8_t tunnel_mode_to_proto[_TUNNEL_MODE_MAX] = {
         [TUNNEL_MODE_ANY]    = 0,
+        [TUNNEL_MODE_IPIP]   = IPPROTO_IPIP,
+        [TUNNEL_MODE_IP6IP]  = IPPROTO_IPV6,
         [TUNNEL_MODE_IPIP6]  = IPPROTO_IPIP,
         [TUNNEL_MODE_IP6IP6] = IPPROTO_IPV6,
 };
 
 static const char* const tunnel_mode_table[_TUNNEL_MODE_MAX] = {
         [TUNNEL_MODE_ANY]    = "any",
+        [TUNNEL_MODE_IPIP]   = "ipip",
+        [TUNNEL_MODE_IP6IP]  = "ip6ip",
         [TUNNEL_MODE_IPIP6]  = "ipip6",
         [TUNNEL_MODE_IP6IP6] = "ip6ip6",
 };
@@ -201,6 +205,12 @@ static int netdev_ipip_sit_fill_message_create(NetDev *netdev, Link *link, sd_ne
         Tunnel *t = ASSERT_PTR(netdev)->kind == NETDEV_KIND_IPIP ? IPIP(netdev) : SIT(netdev);
         int r;
 
+        if (t->mode >= 0) {
+                r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PROTO, tunnel_mode_to_proto[t->mode]);
+                if (r < 0)
+                        return r;
+        }
+
         if (t->external) {
                 r = sd_netlink_message_append_flag(m, IFLA_IPTUN_COLLECT_METADATA);
                 if (r < 0)
@@ -697,6 +707,18 @@ static int netdev_tunnel_verify(NetDev *netdev, const char *filename) {
 
         if (t->mode >= 0)
                 switch (netdev->kind) {
+                case NETDEV_KIND_IPIP:
+                        if (!IN_SET(t->mode, TUNNEL_MODE_ANY, TUNNEL_MODE_IPIP))
+                                return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
+                                                                "Specified unsupported tunnel mode %s, ignoring.",
+                                                                tunnel_mode_to_string(t->mode));
+                        break;
+                case NETDEV_KIND_SIT:
+                        if (!IN_SET(t->mode, TUNNEL_MODE_ANY, TUNNEL_MODE_IPIP, TUNNEL_MODE_IP6IP))
+                                return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
+                                                                "Specified unsupported tunnel mode %s, ignoring.",
+                                                                tunnel_mode_to_string(t->mode));
+                        break;
                 case NETDEV_KIND_IP6TNL:
                         if (!IN_SET(t->mode, TUNNEL_MODE_ANY, TUNNEL_MODE_IPIP6, TUNNEL_MODE_IP6IP6))
                                 return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
index 5c96161b24c05a3a9df793cc9a8310f52d388927..0f3af1efde1338faa172d277458a2f5317352e04 100644 (file)
@@ -9,6 +9,8 @@
 /* For IFLA_IPTUN_PROTO attribute */
 typedef enum TunnelMode {
         TUNNEL_MODE_ANY,    /* 0, "any" */
+        TUNNEL_MODE_IPIP,   /* IPPROTO_IPIP, "ipip", for ipip and sit */
+        TUNNEL_MODE_IP6IP,  /* IPPROTO_IPV6, "ip6ip", for sit */
         TUNNEL_MODE_IPIP6,  /* IPPROTO_IPIP, "ipip6", for ip6tnl */
         TUNNEL_MODE_IP6IP6, /* IPPROTO_IPV6, "ip6ip6", for ip6tnl */
         _TUNNEL_MODE_MAX,