chiark / gitweb /
networkd-ipip-tunnel: add support ttl
[elogind.git] / src / network / networkd-netdev.c
index c7bec74aa36fd5a8a875eb259bd30ea53767312b..62e1a3e26d9438ee2e96fda61ab7e59fd976d937 100644 (file)
@@ -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);
@@ -114,6 +117,8 @@ void netdev_drop(NetDev *netdev) {
 
         netdev->state = NETDEV_STATE_LINGER;
 
+        log_debug_netdev(netdev, "netdev removed");
+
         netdev_cancel_callbacks(netdev);
 
         netdev_unref(netdev);
@@ -217,8 +222,8 @@ static int netdev_create_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userda
         if (r == -EEXIST)
                 log_debug_netdev(netdev, "netdev exists, using existing");
         else if (r < 0) {
-                log_warning_netdev(netdev, "netdev failed: %s", strerror(-r));
-                netdev_enter_failed(netdev);
+                log_warning_netdev(netdev, "netdev could not be greated: %s", strerror(-r));
+                netdev_drop(netdev);
 
                 return 1;
         }
@@ -226,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;
@@ -264,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,
@@ -345,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)
@@ -494,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) {
@@ -547,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;