netifd: Apply tunnel MTU
authorHans Dedecker <dedeckeh@gmail.com>
Tue, 19 Nov 2013 11:17:05 +0000 (12:17 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 8 Dec 2013 17:43:51 +0000 (18:43 +0100)
Tunnel MTU is applied according to the tunnel MTU UCI parameter

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
system-linux.c
system.c
system.h
tunnel.c

index d01d7e31d754ebfb93028ed5ce8dee4035320bb3..58210a6d3d519a27a8c55eaf6e95f3786d8e7ca2 100644 (file)
@@ -1435,8 +1435,11 @@ int system_add_ip_tunnel(const char *name, struct blob_attr *attr)
        str = blobmsg_data(cur);
 
        unsigned int ttl = 0;
-       if ((cur = tb[TUNNEL_ATTR_TTL]) && (ttl = blobmsg_get_u32(cur)) > 255)
-               return -EINVAL;
+       if ((cur = tb[TUNNEL_ATTR_TTL])) {
+               ttl = blobmsg_get_u32(cur);
+               if (ttl > 255)
+                       return -EINVAL;
+       }
 
        unsigned int link = 0;
        if ((cur = tb[TUNNEL_ATTR_LINK])) {
index 8e866daea8e8a380d9c7d32f29b0fc644c433f7e..1452f059b54b0e27b927f2673b6dbe22506dcfcb 100644 (file)
--- a/system.c
+++ b/system.c
 #include <fcntl.h>
 
 static const struct blobmsg_policy tunnel_attrs[__TUNNEL_ATTR_MAX] = {
-       [TUNNEL_ATTR_TYPE] = { "mode", BLOBMSG_TYPE_STRING },
-       [TUNNEL_ATTR_LOCAL] = { "local", BLOBMSG_TYPE_STRING },
-       [TUNNEL_ATTR_REMOTE] = { "remote", BLOBMSG_TYPE_STRING },
-       [TUNNEL_ATTR_TTL] = { "ttl", BLOBMSG_TYPE_INT32 },
-       [TUNNEL_ATTR_6RD_PREFIX] = { "6rd-prefix", BLOBMSG_TYPE_STRING },
-       [TUNNEL_ATTR_6RD_RELAY_PREFIX] = { "6rd-relay-prefix", BLOBMSG_TYPE_STRING },
-       [TUNNEL_ATTR_LINK] = { "link", BLOBMSG_TYPE_STRING },
+       [TUNNEL_ATTR_TYPE] = { .name = "mode", .type = BLOBMSG_TYPE_STRING },
+       [TUNNEL_ATTR_LOCAL] = { .name = "local", .type = BLOBMSG_TYPE_STRING },
+       [TUNNEL_ATTR_REMOTE] = { .name = "remote", .type = BLOBMSG_TYPE_STRING },
+       [TUNNEL_ATTR_MTU] = { .name = "mtu", .type = BLOBMSG_TYPE_INT32 },
+       [TUNNEL_ATTR_TTL] = { .name = "ttl", .type = BLOBMSG_TYPE_INT32 },
+       [TUNNEL_ATTR_6RD_PREFIX] = {.name =  "6rd-prefix", .type = BLOBMSG_TYPE_STRING },
+       [TUNNEL_ATTR_6RD_RELAY_PREFIX] = { .name = "6rd-relay-prefix", .type = BLOBMSG_TYPE_STRING },
+       [TUNNEL_ATTR_LINK] = { .name = "link", .type = BLOBMSG_TYPE_STRING },
 };
 
 const struct uci_blob_param_list tunnel_attr_list = {
index ad7415635c74c2236bdd41f2720ed2248b2cd60e..e1d35c9206477ab418a5d811c8bdb33a6864e27c 100644 (file)
--- a/system.h
+++ b/system.h
@@ -25,6 +25,7 @@ enum tunnel_param {
        TUNNEL_ATTR_TYPE,
        TUNNEL_ATTR_REMOTE,
        TUNNEL_ATTR_LOCAL,
+       TUNNEL_ATTR_MTU,
        TUNNEL_ATTR_TTL,
        TUNNEL_ATTR_6RD_PREFIX,
        TUNNEL_ATTR_6RD_RELAY_PREFIX,
index 3ef5086b48395e71d04e9f6cbd867a4f2acb1a40..aa60019c18102046bc6cad4f1202aecf29b33701 100644 (file)
--- a/tunnel.c
+++ b/tunnel.c
@@ -40,6 +40,27 @@ tunnel_set_state(struct device *dev, bool up)
        return ret;
 }
 
+static enum dev_change_type
+tunnel_reload(struct device *dev, struct blob_attr *attr)
+{
+       struct blob_attr *tb_dev[__DEV_ATTR_MAX];
+       const struct uci_blob_param_list *cfg = dev->type->config_params;
+
+       if (uci_blob_check_equal(dev->config, attr, cfg))
+               return DEV_CONFIG_NO_CHANGE;
+
+       if (attr) {
+               memset(tb_dev, 0, sizeof(tb_dev));
+
+               blobmsg_parse(device_attr_list.params, __DEV_ATTR_MAX, tb_dev,
+                       blob_data(attr), blob_len(attr));
+       }
+
+       device_init_settings(dev, tb_dev);
+
+       return DEV_CONFIG_RESTART;
+}
+
 static struct device *
 tunnel_create(const char *name, struct blob_attr *attr)
 {
@@ -51,6 +72,7 @@ tunnel_create(const char *name, struct blob_attr *attr)
        device_init(dev, &tunnel_device_type, name);
        tun->set_state = dev->set_state;
        dev->set_state = tunnel_set_state;
+       device_set_config(dev, &tunnel_device_type, attr);
        device_set_present(dev, true);
 
        return dev;
@@ -67,7 +89,7 @@ tunnel_free(struct device *dev)
 const struct device_type tunnel_device_type = {
        .name = "IP tunnel",
        .config_params = &tunnel_attr_list,
-
+       .reload = tunnel_reload,
        .create = tunnel_create,
        .free = tunnel_free,
 };