]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: Allow tunnels to be created without .network (#6701)
authorSusant Sahani <ssahani@users.noreply.github.com>
Thu, 31 Aug 2017 16:51:03 +0000 (16:51 +0000)
committerLennart Poettering <lennart@poettering.net>
Thu, 31 Aug 2017 16:51:03 +0000 (18:51 +0200)
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

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

index 1040562202c20e19caceedb7b7c6b197bddc1d12..9c4015e621aad28c3f4c39dd8684d7e884b0d1eb 100644 (file)
           </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>
index ab28caf05dac882ed3e61a7621079ff193d751bd..230dc1b885fc6ef4959906c29985f71c7b9b487e 100644 (file)
@@ -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)
index 43884581caf81ab9ae7099ce4aeb2967bc21b6b1..1cf72bf6d29d4418a8857315c4963cdcc786e084 100644 (file)
@@ -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;
index 67f4fab40026e90af80325e4040cae3b55435de4..64d87e5e07a2d1b034683f8b14ea4dfc8b8cda5d 100644 (file)
@@ -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) {
index d78c6135eee4a8a0edaf1da5e62d7dc6e0f8c020..53690d907524444ff9448451c62187c96e3f8301 100644 (file)
@@ -60,6 +60,7 @@ typedef struct Tunnel {
 
         bool pmtudisc;
         bool copy_dscp;
+        bool independent;
 } Tunnel;
 
 DEFINE_NETDEV_CAST(IPIP, Tunnel);