]> git.decadent.org.uk Git - odhcp6c.git/commitdiff
Pass ICMP configuration to user-space instead of directly applying it
authorSteven Barth <steven@midlink.org>
Fri, 10 Apr 2015 11:19:44 +0000 (13:19 +0200)
committerSteven Barth <steven@midlink.org>
Fri, 10 Apr 2015 11:19:44 +0000 (13:19 +0200)
README
src/odhcp6c.h
src/ra.c
src/script.c

diff --git a/README b/README
index 8c66ffa7c49ba149a45768c64cfdacff26c21f3f..9b56b200f1077ce8e01240fb2a0f430eaef2e9a6 100644 (file)
--- a/README
+++ b/README
@@ -29,8 +29,7 @@ especially routers. It compiles to only about 35 KB (-Os -s).
        h) Configurable SOL_MAX_RT
        i) DS-Lite AFTR-Name Option
        j) Softwire address and port mapped clients (MAP, LW4over6)
        h) Configurable SOL_MAX_RT
        i) DS-Lite AFTR-Name Option
        j) Softwire address and port mapped clients (MAP, LW4over6)
-       k) Prefix Class (experimental)
-       l) CER-ID (experimental)
+       j) CER-ID (experimental)
 
 4. Support for requesting and parsing Router Advertisements
        a) parsing of prefixes, routes, MTU and RDNSS options
 
 4. Support for requesting and parsing Router Advertisements
        a) parsing of prefixes, routes, MTU and RDNSS options
@@ -78,5 +77,9 @@ Environment:
 * RA_ROUTES            A space-separated list of routes from the RA
                                Format: <address>/<length>,gateway,valid,metric
 * RA_DNS               A space-separated list of recursive DNS servers from the RA
 * RA_ROUTES            A space-separated list of routes from the RA
                                Format: <address>/<length>,gateway,valid,metric
 * RA_DNS               A space-separated list of recursive DNS servers from the RA
+* RA_HOPLIMIT  Highest hop-limit received in RAs
+* RA_MTU               MTU-value received in RA
+* RA_REACHABLE ND Reachability time
+* RA_RETRANSMIT        ND Retransmit time
 * AFTR                 The DS-Lite AFTR domain name
 * MAPE / MAPT / LW4O6  Softwire rules for MAPE, MAPT and LW4O6
 * AFTR                 The DS-Lite AFTR domain name
 * MAPE / MAPT / LW4O6  Softwire rules for MAPE, MAPT and LW4O6
index 3e2713ea25bd19e31f272820851939b9d1c8035e..ff5b9e45467045f89c11685740c66706f12096c8 100644 (file)
@@ -319,6 +319,11 @@ int init_rtnetlink(void);
 int set_rtnetlink_addr(int ifindex, const struct in6_addr *addr,
                uint32_t pref, uint32_t valid);
 
 int set_rtnetlink_addr(int ifindex, const struct in6_addr *addr,
                uint32_t pref, uint32_t valid);
 
+int ra_conf_hoplimit(int newvalue);
+int ra_conf_mtu(int newvalue);
+int ra_conf_reachable(int newvalue);
+int ra_conf_retransmit(int newvalue);
+
 int script_init(const char *path, const char *ifname);
 ssize_t script_unhexlify(uint8_t *dst, size_t len, const char *src);
 void script_call(const char *status);
 int script_init(const char *path, const char *ifname);
 ssize_t script_unhexlify(uint8_t *dst, size_t len, const char *src);
 void script_call(const char *status);
index 09d5c1d9ce5985dd6300c4dca3d53ff3c0d60849..04764c7386ddea8327c65fa5ce7c36c12c6963cc 100644 (file)
--- a/src/ra.c
+++ b/src/ra.c
@@ -165,19 +165,6 @@ static int16_t pref_to_priority(uint8_t flags)
 }
 
 
 }
 
 
-static int update_proc(const char *sect, const char *opt, uint32_t value)
-{
-       char buf[64];
-       snprintf(buf, sizeof(buf), "/proc/sys/net/ipv6/%s/%s/%s", sect, if_name, opt);
-
-       int fd = open(buf, O_WRONLY);
-       int ret = write(fd, buf, snprintf(buf, sizeof(buf), "%u", value));
-       close(fd);
-
-       return ret;
-}
-
-
 bool ra_link_up(void)
 {
        static bool firstcall = true;
 bool ra_link_up(void)
 {
        static bool firstcall = true;
@@ -249,6 +236,38 @@ static bool ra_icmpv6_valid(struct sockaddr_in6 *source, int hlim, uint8_t *data
        return opt == end;
 }
 
        return opt == end;
 }
 
+int ra_conf_hoplimit(int newvalue)
+{
+       static int value = 0;
+       if (newvalue > value)
+               value = newvalue;
+       return value;
+}
+
+int ra_conf_mtu(int newvalue)
+{
+       static int value = 0;
+       if (newvalue >= 1280 && newvalue <= 65535)
+               value = newvalue;
+       return value;
+}
+
+int ra_conf_reachable(int newvalue)
+{
+       static int value = 0;
+       if (newvalue > 0 && newvalue <= 3600000)
+               value = newvalue;
+       return value;
+}
+
+int ra_conf_retransmit(int newvalue)
+{
+       static int value = 0;
+       if (newvalue > 0 && newvalue <= 60000)
+               value = newvalue;
+       return value;
+}
+
 bool ra_process(void)
 {
        bool found = false;
 bool ra_process(void)
 {
        bool found = false;
@@ -324,26 +343,18 @@ bool ra_process(void)
                changed |= odhcp6c_update_entry(STATE_RA_ROUTE, &entry, 0, true);
 
                // Parse hoplimit
                changed |= odhcp6c_update_entry(STATE_RA_ROUTE, &entry, 0, true);
 
                // Parse hoplimit
-               if (adv->nd_ra_curhoplimit)
-                       update_proc("conf", "hop_limit", adv->nd_ra_curhoplimit);
+               ra_conf_hoplimit(adv->nd_ra_curhoplimit);
 
                // Parse ND parameters
 
                // Parse ND parameters
-               uint32_t reachable = ntohl(adv->nd_ra_reachable);
-               if (reachable > 0 && reachable <= 3600000)
-                       update_proc("neigh", "base_reachable_time_ms", reachable);
-
-               uint32_t retransmit = ntohl(adv->nd_ra_retransmit);
-               if (retransmit > 0 && retransmit <= 60000)
-                       update_proc("neigh", "retrans_time_ms", retransmit);
-
+               ra_conf_reachable(ntohl(adv->nd_ra_reachable));
+               ra_conf_retransmit(ntohl(adv->nd_ra_retransmit));
 
                // Evaluate options
                struct icmpv6_opt *opt;
                icmpv6_for_each_option(opt, &adv[1], &buf[len]) {
                        if (opt->type == ND_OPT_MTU) {
                                uint32_t *mtu = (uint32_t*)&opt->data[2];
 
                // Evaluate options
                struct icmpv6_opt *opt;
                icmpv6_for_each_option(opt, &adv[1], &buf[len]) {
                        if (opt->type == ND_OPT_MTU) {
                                uint32_t *mtu = (uint32_t*)&opt->data[2];
-                               if (ntohl(*mtu) >= 1280 && ntohl(*mtu) <= 65535)
-                                       update_proc("conf", "mtu", ntohl(*mtu));
+                               ra_conf_mtu(ntohl(*mtu));
                        } else if (opt->type == ND_OPT_ROUTE_INFORMATION && opt->len <= 3) {
                                entry.router = from.sin6_addr;
                                entry.target = any;
                        } else if (opt->type == ND_OPT_ROUTE_INFORMATION && opt->len <= 3) {
                                entry.router = from.sin6_addr;
                                entry.target = any;
index d99327721d6575fafad0b0d5fb73ba745d67c50a..2c342163b364f014bd99e1af5fb5bb8b8a7e3ebc 100644 (file)
@@ -184,6 +184,15 @@ static void entry_to_env(const char *name, const void *data, size_t len, enum en
 }
 
 
 }
 
 
+static void int_to_env(const char *name, int value)
+{
+       size_t len = 12 + strlen(name);
+       char *buf = realloc(NULL, len);
+       snprintf(buf, len, "%s=%d", name, value);
+       putenv(buf);
+}
+
+
 static void s46_to_env_portparams(const uint8_t *data, size_t len, FILE *fp)
 {
        uint8_t *odata;
 static void s46_to_env_portparams(const uint8_t *data, size_t len, FILE *fp)
 {
        uint8_t *odata;
@@ -366,6 +375,11 @@ void script_call(const char *status)
                entry_to_env("RA_ROUTES", ra_route, ra_route_len, ENTRY_ROUTE);
                entry_to_env("RA_DNS", ra_dns, ra_dns_len, ENTRY_HOST);
 
                entry_to_env("RA_ROUTES", ra_route, ra_route_len, ENTRY_ROUTE);
                entry_to_env("RA_DNS", ra_dns, ra_dns_len, ENTRY_HOST);
 
+               int_to_env("RA_HOPLIMIT", ra_conf_hoplimit(0));
+               int_to_env("RA_MTU", ra_conf_mtu(0));
+               int_to_env("RA_REACHABLE", ra_conf_reachable(0));
+               int_to_env("RA_RETRANSMIT", ra_conf_retransmit(0));
+
                char *buf = malloc(10 + passthru_len * 2);
                strncpy(buf, "PASSTHRU=", 10);
                script_hexlify(&buf[9], passthru, passthru_len);
                char *buf = malloc(10 + passthru_len * 2);
                strncpy(buf, "PASSTHRU=", 10);
                script_hexlify(&buf[9], passthru, passthru_len);