config: make RA mtu configurable via UCI
authorHans Dedecker <dedeckeh@gmail.com>
Thu, 11 May 2017 13:34:27 +0000 (15:34 +0200)
committerHans Dedecker <dedeckeh@gmail.com>
Thu, 11 May 2017 14:11:55 +0000 (16:11 +0200)
Allow to specify the router advertisement mtu via the uci parameter
ra_mtu. In case the config parameter is not set the MTU is taken from
the interface as before.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
README
src/config.c
src/odhcpd.h
src/router.c

diff --git a/README b/README
index 9119071792c2b89736bfdccaac4f3f7f63afbf27..3ad17f90b5e4b661a9d58668d0be8831aa20d34b 100644 (file)
--- a/README
+++ b/README
@@ -116,6 +116,8 @@ ra_lifetime integer 1800                    Value to be placed in Router
 ra_useleasetime        bool    0                       Use configured leasetime as
                                                limit for the preferred and
                                                valid lifetime of a prefix
+ra_mtu         integer 0                       MTU to be advertised in
+                                               RA messages
 ndproxy_routing        bool    1                       Learn routes from NDP
 ndproxy_slave  bool    0                       NDProxy external slave
 
index acf30de75a2d4efea7a9bb4f6c2b2ba626c15949..d6b4e81ab027e8cdbfa1d0784837f4f71afbcb88 100644 (file)
@@ -50,6 +50,7 @@ enum {
        IFACE_ATTR_RA_MAXINTERVAL,
        IFACE_ATTR_RA_LIFETIME,
        IFACE_ATTR_RA_USELEASETIME,
+       IFACE_ATTR_RA_MTU,
        IFACE_ATTR_PD_MANAGER,
        IFACE_ATTR_PD_CER,
        IFACE_ATTR_NDPROXY_ROUTING,
@@ -88,6 +89,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
        [IFACE_ATTR_RA_MAXINTERVAL] = { .name = "ra_maxinterval", .type = BLOBMSG_TYPE_INT32 },
        [IFACE_ATTR_RA_LIFETIME] = { .name = "ra_lifetime", .type = BLOBMSG_TYPE_INT32 },
        [IFACE_ATTR_RA_USELEASETIME] = { .name = "ra_useleasetime", .type = BLOBMSG_TYPE_BOOL },
+       [IFACE_ATTR_RA_MTU] = { .name = "ra_mtu", .type = BLOBMSG_TYPE_INT32 },
        [IFACE_ATTR_NDPROXY_ROUTING] = { .name = "ndproxy_routing", .type = BLOBMSG_TYPE_BOOL },
        [IFACE_ATTR_NDPROXY_SLAVE] = { .name = "ndproxy_slave", .type = BLOBMSG_TYPE_BOOL },
 };
@@ -594,6 +596,12 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
        if ((c = tb[IFACE_ATTR_RA_MANAGEMENT]))
                iface->managed = blobmsg_get_u32(c);
 
+       if ((c = tb[IFACE_ATTR_RA_MTU])) {
+               iface->ra_mtu = blobmsg_get_u32(c);
+               if (iface->ra_mtu < 1280)
+                       goto err;
+       }
+
        if ((c = tb[IFACE_ATTR_RA_OFFLINK]))
                iface->ra_not_onlink = blobmsg_get_bool(c);
 
index 334276ed39c8f07dbec43249fbc92e4724709cd0..50827a4d1af0a9969199aee4106856921f768ffc 100644 (file)
@@ -162,6 +162,7 @@ struct interface {
        int ra_maxinterval;
        int ra_mininterval;
        int ra_lifetime;
+       uint32_t ra_mtu;
 
        // DHCPv4
        struct in_addr dhcpv4_start;
index feae5c7e1b28516f28e483645ffffdfade974418..a31bf4e0f2584b8bb8b6febc535410ad67a36867 100644 (file)
@@ -259,9 +259,12 @@ static uint16_t calc_ra_lifetime(struct interface *iface, uint32_t maxival)
 static uint64_t send_router_advert(struct interface *iface, const struct in6_addr *from)
 {
        time_t now = odhcpd_time();
-       int mtu = odhcpd_get_interface_config(iface->ifname, "mtu");
+       uint32_t mtu = iface->ra_mtu;
        int hlim = odhcpd_get_interface_config(iface->ifname, "hop_limit");
 
+       if (mtu == 0)
+                mtu = odhcpd_get_interface_config(iface->ifname, "mtu");
+
        if (mtu < 1280)
                mtu = 1280;