[systemd-commits] 3 commits - Makefile.am src/libsystemd src/libsystemd-network src/network units/systemd-networkd.service.in

Tom Gundersen tomegun at kemper.freedesktop.org
Mon May 12 08:51:18 PDT 2014


 Makefile.am                               |   10 +
 src/libsystemd-network/network-internal.c |   35 +++++
 src/libsystemd-network/network-internal.h |    3 
 src/libsystemd/sd-rtnl/rtnl-types.c       |    4 
 src/network/networkd-link.c               |   26 +++-
 src/network/networkd-manager.c            |    6 
 src/network/networkd-netdev-gperf.gperf   |    5 
 src/network/networkd-netdev.c             |   53 +++++++-
 src/network/networkd-network-gperf.gperf  |    1 
 src/network/networkd-network.c            |   39 ++++++
 src/network/networkd-tunnel.c             |  192 ++++++++++++++++++++++++++++++
 src/network/networkd.h                    |   34 +++++
 units/systemd-networkd.service.in         |    2 
 13 files changed, 401 insertions(+), 9 deletions(-)

New commits:
commit 0b44d8c3d7dfadb60b30c9339b18c4cc1617b51b
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon May 12 17:11:13 2014 +0200

    networkd: manager - don't leak kmod context
    
    Also, keep the kmod_new internal to networkd-manager.c

diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c
index cf577e5..f3dc42f 100644
--- a/src/libsystemd-network/network-internal.c
+++ b/src/libsystemd-network/network-internal.c
@@ -353,6 +353,8 @@ int load_module(struct kmod_ctx *ctx, const char *mod_name) {
                         log_error("Failed to insert '%s': %s", kmod_module_get_name(mod),
                                   strerror(-r));
                 }
+
+                kmod_module_unref(mod);
         }
 
         kmod_module_unref_list(modlist);
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index cfa3a99..cc55f9a 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -118,6 +118,10 @@ int manager_new(Manager **ret) {
                         return -ENOMEM;
         }
 
+        m->kmod_ctx = kmod_new(NULL, NULL);
+        if (!m->kmod_ctx)
+                return -ENOMEM;
+
         m->links = hashmap_new(uint64_hash_func, uint64_compare_func);
         if (!m->links)
                 return -ENOMEM;
@@ -144,6 +148,7 @@ void manager_free(Manager *m) {
 
         free(m->state_file);
 
+        kmod_unref(m->kmod_ctx);
         udev_monitor_unref(m->udev_monitor);
         udev_unref(m->udev);
         sd_bus_unref(m->bus);
@@ -552,18 +557,3 @@ finish:
 
         return r;
 }
-
-int manager_init_kmod_ctx(Manager *m) {
-        struct kmod_ctx *ctx;
-
-        assert(m);
-
-        ctx = kmod_new(NULL, NULL);
-        if (!ctx) {
-                return -ENOMEM;
-        }
-
-        m->kmod_ctx = ctx;
-
-        return 0;
-}
diff --git a/src/network/networkd.c b/src/network/networkd.c
index 39e1b2a..6b3bf12 100644
--- a/src/network/networkd.c
+++ b/src/network/networkd.c
@@ -87,12 +87,6 @@ int main(int argc, char *argv[]) {
                 goto out;
         }
 
-        r = manager_init_kmod_ctx(m);
-        if (r < 0) {
-                log_error("Could not init kmod context: %s", strerror(-r));
-                goto out;
-        }
-
         r = manager_rtnl_enumerate_links(m);
         if (r < 0) {
                 log_error("Could not enumerate links: %s", strerror(-r));
diff --git a/src/network/networkd.h b/src/network/networkd.h
index e32cf5d..11d0056 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -277,7 +277,6 @@ int manager_bus_listen(Manager *m);
 
 int manager_update_resolv_conf(Manager *m);
 int manager_save(Manager *m);
-int manager_init_kmod_ctx(Manager *m);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
 #define _cleanup_manager_free_ _cleanup_(manager_freep)

commit 7c8ec321e7b6fd97a6eb4b9a3daa16c51b97a74a
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon May 12 17:37:52 2014 +0200

    networkd: unit - add cap to load modules
    
    Remember to drop this when the kernel gains autoloading for all netdev kinds.

diff --git a/units/systemd-networkd.service.in b/units/systemd-networkd.service.in
index 8dd37ff..f0df671 100644
--- a/units/systemd-networkd.service.in
+++ b/units/systemd-networkd.service.in
@@ -19,7 +19,7 @@ Type=notify
 Restart=always
 RestartSec=0
 ExecStart=@rootlibexecdir@/systemd-networkd
-CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW CAP_SYS_PTRACE
+CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW CAP_SYS_PTRACE CAP_SYS_MODULE
 WatchdogSec=1min
 
 [Install]

commit 7951dea20911969287878e6897b3eca348721ade
Author: Susant Sahani <susant at redhat.com>
Date:   Mon May 12 10:48:24 2014 +0530

    networkd: introduce ipip tunnel
    
    This patch enables basic ipip tunnel support.
    It works with kernel module ipip
    
    example conf:
    
    file: ipip.netdev
    
    [NetDev]
    Name=ipip-tun
    Kind=ipip
    MTUBytes=1480
    
    [Tunnel]
    Local=192.168.223.238
    Remote=192.169.224.239
    TTL=64
    
    file: ipip.network
    
    [Match]
    Name=em1
    
    [Network]
    Tunnel=ipip-tun
    
    [tomegun:
             - drop unused variable
             - take ref when enslaving]

diff --git a/Makefile.am b/Makefile.am
index 637f5e1..c54d357 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4171,7 +4171,8 @@ systemd_networkd_SOURCES = \
 	src/network/networkd.c
 
 systemd_networkd_LDADD = \
-	libsystemd-networkd-core.la
+	libsystemd-networkd-core.la \
+	-lkmod
 
 noinst_LTLIBRARIES += \
 	libsystemd-networkd-core.la
@@ -4181,6 +4182,7 @@ libsystemd_networkd_core_la_SOURCES = \
 	src/network/networkd.h \
 	src/network/networkd-link.c \
 	src/network/networkd-netdev.c \
+	src/network/networkd-tunnel.c \
 	src/network/networkd-network.c \
 	src/network/networkd-address.c \
 	src/network/networkd-route.c \
@@ -4217,13 +4219,15 @@ systemd_networkd_wait_online_LDADD = \
 	libsystemd-network.la \
 	libudev-internal.la \
 	libsystemd-internal.la \
-	libsystemd-shared.la
+	libsystemd-shared.la \
+	libsystemd-network.la
 
 test_network_SOURCES = \
 	src/network/test-network.c
 
 test_network_LDADD = \
-	libsystemd-networkd-core.la
+	libsystemd-networkd-core.la \
+	-lkmod
 
 tests += \
 	test-network
diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c
index 52e614c..cf577e5 100644
--- a/src/libsystemd-network/network-internal.c
+++ b/src/libsystemd-network/network-internal.c
@@ -326,3 +326,36 @@ int net_parse_inaddr(const char *address, unsigned char *family, void *dst) {
 
         return 0;
 }
+
+int load_module(struct kmod_ctx *ctx, const char *mod_name) {
+        struct kmod_list *modlist = NULL, *l;
+        int r;
+
+        assert(ctx);
+        assert(mod_name);
+
+        r = kmod_module_new_from_lookup(ctx, mod_name, &modlist);
+        if (r < 0)
+                return r;
+
+        if (!modlist) {
+                log_error("Failed to find module '%s'", mod_name);
+                return -ENOENT;
+        }
+
+        kmod_list_foreach(l, modlist) {
+                struct kmod_module *mod = kmod_module_get_module(l);
+
+                r = kmod_module_probe_insert_module(mod, 0, NULL, NULL, NULL, NULL);
+                if (r == 0)
+                        log_info("Inserted module '%s'", kmod_module_get_name(mod));
+                else {
+                        log_error("Failed to insert '%s': %s", kmod_module_get_name(mod),
+                                  strerror(-r));
+                }
+        }
+
+        kmod_module_unref_list(modlist);
+
+        return r;
+}
diff --git a/src/libsystemd-network/network-internal.h b/src/libsystemd-network/network-internal.h
index 836472a..1c77d33 100644
--- a/src/libsystemd-network/network-internal.h
+++ b/src/libsystemd-network/network-internal.h
@@ -24,6 +24,7 @@
 #include <netinet/ether.h>
 #include <netinet/in.h>
 #include <stdbool.h>
+#include <libkmod.h>
 
 #include "udev.h"
 #include "condition-util.h"
@@ -65,3 +66,5 @@ int config_parse_ifalias(const char *unit, const char *filename, unsigned line,
 int net_parse_inaddr(const char *address, unsigned char *family, void *dst);
 
 int net_get_unique_predictable_data(struct udev_device *device, uint8_t result[8]);
+
+int load_module(struct kmod_ctx *ctx, const char *mod_name);
diff --git a/src/libsystemd/sd-rtnl/rtnl-types.c b/src/libsystemd/sd-rtnl/rtnl-types.c
index 44ac5ec..96467a3 100644
--- a/src/libsystemd/sd-rtnl/rtnl-types.c
+++ b/src/libsystemd/sd-rtnl/rtnl-types.c
@@ -104,8 +104,8 @@ static const NLType rtnl_link_info_data_bond_types[IFLA_BOND_MAX + 1] = {
 
 static const NLType rtnl_link_info_data_iptun_types[IFLA_IPTUN_MAX + 1] = {
         [IFLA_IPTUN_LINK]                = { .type = NLA_U32 },
-        [IFLA_IPTUN_LOCAL]               = { .type = NLA_U32 },
-        [IFLA_IPTUN_REMOTE]              = { .type = NLA_U32 },
+        [IFLA_IPTUN_LOCAL]               = { .type = NLA_IN_ADDR },
+        [IFLA_IPTUN_REMOTE]              = { .type = NLA_IN_ADDR },
         [IFLA_IPTUN_TTL]                 = { .type = NLA_U8 },
         [IFLA_IPTUN_TOS]                 = { .type = NLA_U8 },
         [IFLA_IPTUN_PMTUDISC]            = { .type = NLA_U8 },
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index d07cc30..77c505f 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1466,7 +1466,9 @@ static int link_enter_enslave(Link *link) {
 
         link_save(link);
 
-        if (!link->network->bridge && !link->network->bond &&
+        if (!link->network->bridge &&
+            !link->network->bond &&
+            !link->network->tunnel &&
             hashmap_isempty(link->network->vlans) &&
             hashmap_isempty(link->network->macvlans))
                 return link_enslaved(link);
@@ -1515,6 +1517,28 @@ static int link_enter_enslave(Link *link) {
                 link->enslaving ++;
         }
 
+        if (link->network->tunnel) {
+                log_struct_link(LOG_DEBUG, link,
+                                "MESSAGE=%s: enslaving by '%s'",
+                                link->ifname, link->network->tunnel->name,
+                                NETDEV(link->network->tunnel),
+                                NULL);
+
+                r = netdev_enslave(link->network->tunnel, link, &enslave_handler);
+                if (r < 0) {
+                        log_struct_link(LOG_WARNING, link,
+                                        "MESSAGE=%s: could not enslave by '%s': %s",
+                                        link->ifname, link->network->tunnel->name, strerror(-r),
+                                        NETDEV(link->network->tunnel),
+                                        NULL);
+                        link_enter_failed(link);
+                        return r;
+                }
+
+                link_ref(link);
+                link->enslaving ++;
+        }
+
         HASHMAP_FOREACH(vlan, link->network->vlans, i) {
                 log_struct_link(LOG_DEBUG, link,
                                 "MESSAGE=%s: enslaving by '%s'",
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 8bdc60f..cfa3a99 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -21,6 +21,7 @@
 
 #include <resolv.h>
 #include <linux/if.h>
+#include <libkmod.h>
 
 #include "path-util.h"
 #include "networkd.h"
@@ -551,3 +552,18 @@ finish:
 
         return r;
 }
+
+int manager_init_kmod_ctx(Manager *m) {
+        struct kmod_ctx *ctx;
+
+        assert(m);
+
+        ctx = kmod_new(NULL, NULL);
+        if (!ctx) {
+                return -ENOMEM;
+        }
+
+        m->kmod_ctx = ctx;
+
+        return 0;
+}
diff --git a/src/network/networkd-netdev-gperf.gperf b/src/network/networkd-netdev-gperf.gperf
index ea7ba57..7e6b885 100644
--- a/src/network/networkd-netdev-gperf.gperf
+++ b/src/network/networkd-netdev-gperf.gperf
@@ -22,5 +22,10 @@ Match.Architecture,      config_parse_net_condition,         CONDITION_ARCHITECT
 NetDev.Description,      config_parse_string,                0,                             offsetof(NetDev, description)
 NetDev.Name,             config_parse_ifname,                0,                             offsetof(NetDev, name)
 NetDev.Kind,             config_parse_netdev_kind,           0,                             offsetof(NetDev, kind)
+NetDev.MTUBytes,         config_parse_iec_size,              0,                             offsetof(NetDev, mtu)
 VLAN.Id,                 config_parse_uint64,                0,                             offsetof(NetDev, vlanid)
 MACVLAN.Mode,            config_parse_macvlan_mode,          0,                             offsetof(NetDev, macvlan_mode)
+Tunnel.Local,            config_parse_tunnel_address,        0,                             offsetof(NetDev, tunnel_local)
+Tunnel.Remote,           config_parse_tunnel_address,        0,                             offsetof(NetDev, tunnel_remote)
+Tunnel.TOS,              config_parse_unsigned,              0,                             offsetof(NetDev, tunnel_tos)
+Tunnel.TTL,              config_parse_unsigned,              0,                             offsetof(NetDev, tunnel_ttl)
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index f742e39..62e1a3e 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -33,6 +33,9 @@ static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
         [NETDEV_KIND_BOND] = "bond",
         [NETDEV_KIND_VLAN] = "vlan",
         [NETDEV_KIND_MACVLAN] = "macvlan",
+        [NETDEV_KIND_IPIP] = "ipip",
+        [NETDEV_KIND_GRE] = "gre",
+        [NETDEV_KIND_SIT] = "sit",
 };
 
 DEFINE_STRING_TABLE_LOOKUP(netdev_kind, NetDevKind);
@@ -228,6 +231,34 @@ static int netdev_create_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userda
         return 1;
 }
 
+int config_parse_tunnel_address(const char *unit,
+                                const char *filename,
+                                unsigned line,
+                                const char *section,
+                                unsigned section_line,
+                                const char *lvalue,
+                                int ltype,
+                                const char *rvalue,
+                                void *data,
+                                void *userdata) {
+        NetDev *n = data;
+        unsigned char family = AF_INET;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        r = net_parse_inaddr(rvalue, &family, n);
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "Tunnel address is invalid, ignoring assignment: %s", rvalue);
+                return 0;
+        }
+       return 0;
+}
+
 static int netdev_create(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback) {
         _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
         const char *kind;
@@ -266,6 +297,16 @@ static int netdev_create(NetDev *netdev, Link *link, sd_rtnl_message_handler_t c
                 return r;
         }
 
+        if(netdev->mtu) {
+                r = sd_rtnl_message_append_u32(req, IFLA_MTU, netdev->mtu);
+                if (r < 0) {
+                        log_error_netdev(netdev,
+                                         "Could not append IFLA_MTU attribute: %s",
+                                         strerror(-r));
+                        return r;
+                }
+        }
+
         r = sd_rtnl_message_open_container(req, IFLA_LINKINFO);
         if (r < 0) {
                 log_error_netdev(netdev,
@@ -347,6 +388,11 @@ int netdev_enslave(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callbac
         if (netdev->kind == NETDEV_KIND_VLAN || netdev->kind == NETDEV_KIND_MACVLAN)
                 return netdev_create(netdev, link, callback);
 
+        if(netdev->kind == NETDEV_KIND_IPIP ||
+           netdev->kind == NETDEV_KIND_GRE ||
+           netdev->kind ==  NETDEV_KIND_SIT)
+                return netdev_create_tunnel(link, netdev_create_handler);
+
         if (netdev->state == NETDEV_STATE_READY) {
                 r = netdev_enslave_ready(netdev, link, callback);
                 if (r < 0)
@@ -496,7 +542,7 @@ static int netdev_load_one(Manager *manager, const char *filename) {
         netdev->macvlan_mode = _NETDEV_MACVLAN_MODE_INVALID;
         netdev->vlanid = VLANID_MAX + 1;
 
-        r = config_parse(NULL, filename, file, "Match\0NetDev\0VLAN\0MACVLAN\0",
+        r = config_parse(NULL, filename, file, "Match\0NetDev\0VLAN\0MACVLAN\0Tunnel\0",
                          config_item_perf_lookup, (void*) network_netdev_gperf_lookup,
                          false, false, netdev);
         if (r < 0) {
@@ -549,7 +595,10 @@ static int netdev_load_one(Manager *manager, const char *filename) {
         LIST_HEAD_INIT(netdev->callbacks);
 
         if (netdev->kind != NETDEV_KIND_VLAN &&
-            netdev->kind != NETDEV_KIND_MACVLAN) {
+            netdev->kind != NETDEV_KIND_MACVLAN &&
+            netdev->kind != NETDEV_KIND_IPIP &&
+            netdev->kind != NETDEV_KIND_GRE &&
+            netdev->kind != NETDEV_KIND_SIT) {
                 r = netdev_create(netdev, NULL, NULL);
                 if (r < 0)
                         return r;
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index bfe44e0..4bb8425 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -34,6 +34,7 @@ Network.IPv4LL,              config_parse_bool,                  0,
 Network.Address,             config_parse_address,               0,                             0
 Network.Gateway,             config_parse_gateway,               0,                             0
 Network.DNS,                 config_parse_dns,                   0,                             offsetof(Network, dns)
+Network.Tunnel,              config_parse_tunnel,                0,                             offsetof(Network, tunnel)
 Address.Address,             config_parse_address,               0,                             0
 Address.Broadcast,           config_parse_broadcast,             0,                             0
 Address.Label,               config_parse_label,                 0,                             0
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 5d7ce1c..d6b06e8 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -331,3 +331,42 @@ int config_parse_netdev(const char *unit,
 
         return 0;
 }
+
+int config_parse_tunnel(const char *unit,
+                        const char *filename,
+                        unsigned line,
+                        const char *section,
+                        unsigned section_line,
+                        const char *lvalue,
+                        int ltype,
+                        const char *rvalue,
+                        void *data,
+                        void *userdata) {
+        Network *network = userdata;
+        NetDev *netdev;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        r = netdev_get(network->manager, rvalue, &netdev);
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "Tunnel is invalid, ignoring assignment: %s", rvalue);
+                return 0;
+        }
+
+        if (netdev->kind != NETDEV_KIND_IPIP &&
+            netdev->kind != NETDEV_KIND_SIT &&
+            netdev->kind != NETDEV_KIND_GRE) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "NetDev is not a tunnel, ignoring assignment: %s", rvalue);
+                return 0;
+        }
+
+        network->tunnel = netdev;
+
+        return 0;
+}
diff --git a/src/network/networkd-tunnel.c b/src/network/networkd-tunnel.c
new file mode 100644
index 0000000..49a4975
--- /dev/null
+++ b/src/network/networkd-tunnel.c
@@ -0,0 +1,192 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+    This file is part of systemd.
+
+    Copyright 2014 Susant Sahani <susant at redhat.com>
+
+    systemd is free software; you can redistribute it and/or modify it
+    under the terms of the GNU Lesser General Public License as published by
+    the Free Software Foundation; either version 2.1 of the License, or
+    (at your option) any later version.
+
+    systemd is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public License
+    along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <netinet/ether.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+#include <linux/ip.h>
+#include <linux/if_tunnel.h>
+#include <libkmod.h>
+
+#include "sd-rtnl.h"
+#include "networkd.h"
+#include "network-internal.h"
+#include "util.h"
+
+
+static int netdev_fill_ipip_rtnl_message(Link *link, sd_rtnl_message *m) {
+        NetDev *netdev;
+        int r;
+
+        assert(link);
+        assert(link->network);
+        assert(link->network->tunnel);
+        assert(m);
+
+        netdev = link->network->tunnel;
+
+        r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->name);
+        if (r < 0) {
+                log_error_netdev(netdev,
+                                 "Could not append IFLA_IFNAME, attribute: %s",
+                                 strerror(-r));
+                return r;
+        }
+
+        if(netdev->mtu) {
+                r = sd_rtnl_message_append_u32(m, IFLA_MTU, netdev->mtu);
+                if (r < 0) {
+                        log_error_netdev(netdev,
+                                         "Could not append IFLA_MTU attribute: %s",
+                                         strerror(-r));
+                        return r;
+                }
+        }
+
+        r = sd_rtnl_message_open_container(m, IFLA_LINKINFO);
+        if (r < 0) {
+                log_error_netdev(netdev,
+                                 "Could not append IFLA_LINKINFO attribute: %s",
+                                 strerror(-r));
+                return r;
+        }
+
+        r = sd_rtnl_message_open_container_union(m, IFLA_INFO_DATA,
+                                                 netdev_kind_to_string(netdev->kind));
+        if (r < 0) {
+                log_error_netdev(netdev,
+                                 "Could not append IFLA_INFO_DATA attribute: %s",
+                                 strerror(-r));
+                return r;
+        }
+
+        r = sd_rtnl_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
+        if (r < 0) {
+                log_error_netdev(netdev,
+                                 "Could not append IFLA_IPTUN_LINK attribute: %s",
+                                 strerror(-r));
+                return r;
+        }
+
+        r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &netdev->tunnel_local);
+        if (r < 0) {
+                log_error_netdev(netdev,
+                                 "Could not append IFLA_IPTUN_LOCAL attribute: %s",
+                                 strerror(-r));
+                return r;
+        }
+
+        r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &netdev->tunnel_remote);
+        if (r < 0) {
+                log_error_netdev(netdev,
+                                 "Could not append IFLA_IPTUN_REMOTE attribute: %s",
+                                 strerror(-r));
+                return r;
+        }
+
+        r = sd_rtnl_message_close_container(m);
+        if (r < 0) {
+                log_error_netdev(netdev,
+                                 "Could not append IFLA_INFO_DATA attribute: %s",
+                                 strerror(-r));
+                return r;
+        }
+
+        r = sd_rtnl_message_close_container(m);
+        if (r < 0) {
+                log_error_netdev(netdev,
+                                 "Could not append IFLA_LINKINFO attribute: %s",
+                                 strerror(-r));
+                return r;
+        }
+
+        return r;
+}
+
+int netdev_create_tunnel(Link *link, sd_rtnl_message_handler_t callback) {
+        _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
+        NetDev *netdev;
+        int r;
+
+        assert(link);
+        assert(link->network);
+        assert(link->network->tunnel);
+
+        netdev = link->network->tunnel;
+
+        assert(netdev);
+        assert(netdev->name);
+        assert(netdev->manager);
+        assert(netdev->manager->rtnl);
+        assert(netdev->manager->kmod_ctx);
+
+        /* Load kernel module first */
+        switch(netdev->kind) {
+        case NETDEV_KIND_IPIP:
+        case NETDEV_KIND_GRE:
+        case NETDEV_KIND_SIT:
+                r = load_module(netdev->manager->kmod_ctx,
+                                netdev_kind_to_string(netdev->kind));
+                if (r < 0) {
+                        log_error_netdev(netdev,
+                                         "Could not load Kernel module: %s . Ignoring",
+                                         netdev_kind_to_string(netdev->kind));
+                        return r;
+                }
+                break;
+        default:
+                return -ENOTSUP;
+        }
+
+        r = sd_rtnl_message_new_link(netdev->manager->rtnl, &m, RTM_NEWLINK, 0);
+        if (r < 0) {
+                log_error_netdev(netdev,
+                                 "Could not allocate RTM_NEWLINK message: %s",
+                                 strerror(-r));
+                return r;
+        }
+
+        switch(netdev->kind) {
+        case NETDEV_KIND_IPIP:
+                r = netdev_fill_ipip_rtnl_message(link, m);
+                if(r < 0)
+                        return r;
+                break;
+        case NETDEV_KIND_GRE:
+        case NETDEV_KIND_SIT:
+        default:
+                return -ENOTSUP;
+        }
+
+        r = sd_rtnl_call_async(netdev->manager->rtnl, m, callback, netdev, 0, NULL);
+        if (r < 0) {
+                log_error_netdev(netdev,
+                                 "Could not send rtnetlink message: %s", strerror(-r));
+                return r;
+        }
+
+        log_debug_netdev(netdev, "Creating tunnel netdev: %s",
+                         netdev_kind_to_string(netdev->kind));
+
+        netdev->state = NETDEV_STATE_CREATING;
+
+        return 0;
+}
diff --git a/src/network/networkd.c b/src/network/networkd.c
index 6b3bf12..39e1b2a 100644
--- a/src/network/networkd.c
+++ b/src/network/networkd.c
@@ -87,6 +87,12 @@ int main(int argc, char *argv[]) {
                 goto out;
         }
 
+        r = manager_init_kmod_ctx(m);
+        if (r < 0) {
+                log_error("Could not init kmod context: %s", strerror(-r));
+                goto out;
+        }
+
         r = manager_rtnl_enumerate_links(m);
         if (r < 0) {
                 log_error("Could not enumerate links: %s", strerror(-r));
diff --git a/src/network/networkd.h b/src/network/networkd.h
index ec2e111..e32cf5d 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -68,6 +68,9 @@ typedef enum NetDevKind {
         NETDEV_KIND_BOND,
         NETDEV_KIND_VLAN,
         NETDEV_KIND_MACVLAN,
+        NETDEV_KIND_IPIP,
+        NETDEV_KIND_GRE,
+        NETDEV_KIND_SIT,
         _NETDEV_KIND_MAX,
         _NETDEV_KIND_INVALID = -1
 } NetDevKind;
@@ -95,6 +98,7 @@ struct NetDev {
 
         char *description;
         char *name;
+        size_t mtu;
         NetDevKind kind;
 
         uint64_t vlanid;
@@ -103,6 +107,11 @@ struct NetDev {
         int ifindex;
         NetDevState state;
 
+        unsigned tunnel_ttl;
+        unsigned tunnel_tos;
+        struct in_addr tunnel_local;
+        struct in_addr tunnel_remote;
+
         LIST_HEAD(netdev_enslave_callback, callbacks);
 };
 
@@ -124,6 +133,7 @@ struct Network {
         char *description;
         NetDev *bridge;
         NetDev *bond;
+        NetDev *tunnel;
         Hashmap *vlans;
         Hashmap *macvlans;
         bool dhcp;
@@ -246,6 +256,7 @@ struct Manager {
         LIST_HEAD(Network, networks);
 
         usec_t network_dirs_ts_usec;
+        struct kmod_ctx *kmod_ctx;
 };
 
 extern const char* const network_dirs[];
@@ -266,6 +277,7 @@ int manager_bus_listen(Manager *m);
 
 int manager_update_resolv_conf(Manager *m);
 int manager_save(Manager *m);
+int manager_init_kmod_ctx(Manager *m);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
 #define _cleanup_manager_free_ _cleanup_(manager_freep)
@@ -284,6 +296,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(NetDev*, netdev_unref);
 int netdev_get(Manager *manager, const char *name, NetDev **ret);
 int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *newlink);
 int netdev_enslave(NetDev *netdev, Link *link, sd_rtnl_message_handler_t cb);
+int netdev_create_tunnel(Link *link, sd_rtnl_message_handler_t callback);
 
 const char *netdev_kind_to_string(NetDevKind d) _const_;
 NetDevKind netdev_kind_from_string(const char *d) _pure_;
@@ -316,6 +329,28 @@ int config_parse_netdev(const char *unit, const char *filename, unsigned line,
                         const char *section, unsigned section_line, const char *lvalue,
                         int ltype, const char *rvalue, void *data, void *userdata);
 
+int config_parse_tunnel(const char *unit,
+                        const char *filename,
+                        unsigned line,
+                        const char *section,
+                        unsigned section_line,
+                        const char *lvalue,
+                        int ltype,
+                        const char *rvalue,
+                        void *data,
+                        void *userdata);
+
+int config_parse_tunnel_address(const char *unit,
+                                const char *filename,
+                                unsigned line,
+                                const char *section,
+                                unsigned section_line,
+                                const char *lvalue,
+                                int ltype,
+                                const char *rvalue,
+                                void *data,
+                                void *userdata);
+
 /* gperf */
 const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, unsigned length);
 



More information about the systemd-commits mailing list