The tunnel mtu parameter can be configured in UCI but the setting was not 
applied 
on tunnel interfaces.The patch also adds functionality to configure the don't 
fragment
bit of tunnel interfaces via UCI.

Signed-off-by: Hans Dedecker <dedec...@gmail.com>
---
 device.c       |   12 ++++++------
 device.h       |    2 +-
 system-linux.c |   15 ++++++++++-----
 system.c       |   16 +++++++++-------
 system.h       |    2 ++
 tunnel.c       |   24 +++++++++++++++++++++++-
 6 files changed, 51 insertions(+), 20 deletions(-)

diff --git a/device.c b/device.c
index c30650a..56fc3f7 100644
--- a/device.c
+++ b/device.c
@@ -31,12 +31,12 @@
 static struct avl_tree devices;
 
 static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = {
-       [DEV_ATTR_TYPE] = { "type", BLOBMSG_TYPE_STRING },
-       [DEV_ATTR_IFNAME] = { "ifname", BLOBMSG_TYPE_ARRAY },
-       [DEV_ATTR_MTU] = { "mtu", BLOBMSG_TYPE_INT32 },
-       [DEV_ATTR_MACADDR] = { "macaddr", BLOBMSG_TYPE_STRING },
-       [DEV_ATTR_TXQUEUELEN] = { "txqueuelen", BLOBMSG_TYPE_INT32 },
-       [DEV_ATTR_ENABLED] = { "enabled", BLOBMSG_TYPE_BOOL },
+       [DEV_ATTR_TYPE] = { .name = "type", .type = BLOBMSG_TYPE_STRING },
+       [DEV_ATTR_IFNAME] = { .name = "ifname", .type = BLOBMSG_TYPE_ARRAY },
+       [DEV_ATTR_MTU] = { .name = "mtu", .type = BLOBMSG_TYPE_INT32 },
+       [DEV_ATTR_MACADDR] = { .name = "macaddr", .type = BLOBMSG_TYPE_STRING },
+       [DEV_ATTR_TXQUEUELEN] = { .name = "txqueuelen", .type = 
BLOBMSG_TYPE_INT32 },
+       [DEV_ATTR_ENABLED] = { .name = "enabled", .type = BLOBMSG_TYPE_BOOL },
 };
 
 const struct uci_blob_param_list device_attr_list = {
diff --git a/device.h b/device.h
index dbcaf77..d63ffe3 100644
--- a/device.h
+++ b/device.h
@@ -59,7 +59,7 @@ struct device_type {
 enum {
        DEV_OPT_MTU             = (1 << 0),
        DEV_OPT_MACADDR         = (1 << 1),
-       DEV_OPT_TXQUEUELEN      = (1 << 2)
+       DEV_OPT_TXQUEUELEN      = (1 << 2),
 };
 
 /* events broadcasted to all users of a device */
diff --git a/system-linux.c b/system-linux.c
index d01d7e3..dae98b0 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -1418,11 +1418,11 @@ out:
        return ret;
 }
 
-
 int system_add_ip_tunnel(const char *name, struct blob_attr *attr)
 {
        struct blob_attr *tb[__TUNNEL_ATTR_MAX];
        struct blob_attr *cur;
+       bool set_df = true;
        const char *str;
 
        system_del_ip_tunnel(name);
@@ -1434,9 +1434,15 @@ int system_add_ip_tunnel(const char *name, struct 
blob_attr *attr)
                return -EINVAL;
        str = blobmsg_data(cur);
 
+       if ((cur = tb[TUNNEL_ATTR_DF]))
+               set_df = blobmsg_get_bool(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 || (!set_df && ttl))
+                       return -EINVAL;
+       }
 
        unsigned int link = 0;
        if ((cur = tb[TUNNEL_ATTR_LINK])) {
@@ -1448,14 +1454,13 @@ int system_add_ip_tunnel(const char *name, struct 
blob_attr *attr)
                        link = iface->l3_dev.dev->ifindex;
        }
 
-
        if (!strcmp(str, "sit")) {
                struct ip_tunnel_parm p = {
                        .link = link,
                        .iph = {
                                .version = 4,
                                .ihl = 5,
-                               .frag_off = htons(IP_DF),
+                               .frag_off = set_df ? htons(IP_DF) : 0,
                                .protocol = IPPROTO_IPV6,
                                .ttl = ttl
                        }
diff --git a/system.c b/system.c
index 8e866da..3dd90b4 100644
--- a/system.c
+++ b/system.c
@@ -16,13 +16,15 @@
 #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_DF] = { .name = "df", .type = BLOBMSG_TYPE_BOOL },
+       [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 = {
diff --git a/system.h b/system.h
index ad74156..ff83a1c 100644
--- a/system.h
+++ b/system.h
@@ -25,6 +25,8 @@ enum tunnel_param {
        TUNNEL_ATTR_TYPE,
        TUNNEL_ATTR_REMOTE,
        TUNNEL_ATTR_LOCAL,
+       TUNNEL_ATTR_MTU,
+       TUNNEL_ATTR_DF,
        TUNNEL_ATTR_TTL,
        TUNNEL_ATTR_6RD_PREFIX,
        TUNNEL_ATTR_6RD_RELAY_PREFIX,
diff --git a/tunnel.c b/tunnel.c
index 3ef5086..aa60019 100644
--- 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,
 };
-- 
1.7.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to