summaryrefslogtreecommitdiff
path: root/src/ra.c
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2015-04-10 13:19:44 +0200
committerSteven Barth <steven@midlink.org>2015-04-10 13:19:44 +0200
commit2bf5f3ad1ce6d386938c39d1569f2635300eca6e (patch)
tree7f3aa414baf857444354ce5ee6d28e1f7cbede0e /src/ra.c
parent5d19cd6e4fece1301608b975dd639d751faa1b94 (diff)
downloadodhcp6c-2bf5f3ad1ce6d386938c39d1569f2635300eca6e.tar.gz
Pass ICMP configuration to user-space instead of directly applying it
Diffstat (limited to 'src/ra.c')
-rw-r--r--src/ra.c61
1 files changed, 36 insertions, 25 deletions
diff --git a/src/ra.c b/src/ra.c
index 09d5c1d..04764c7 100644
--- 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;
@@ -249,6 +236,38 @@ static bool ra_icmpv6_valid(struct sockaddr_in6 *source, int hlim, uint8_t *data
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;
@@ -324,26 +343,18 @@ bool ra_process(void)
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
- 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];
- 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;