X-Git-Url: https://git.decadent.org.uk/gitweb/?p=odhcp6c.git;a=blobdiff_plain;f=src%2Fra.c;h=122f99eea4a1701f814a0d7c62e229777a94075e;hp=54cf086d11356501bcba02c5cd0cc1bd4aa52f95;hb=c3bbeced0f204b6b9571148ae84227105baaf179;hpb=a3bffff7f3e6411c8737454381ac21dcf62a6dcd diff --git a/src/ra.c b/src/ra.c index 54cf086..122f99e 100644 --- a/src/ra.c +++ b/src/ra.c @@ -160,19 +160,8 @@ static void ra_send_rs(int signal __attribute__((unused))) static int16_t pref_to_priority(uint8_t flags) { flags = (flags >> 3) & 0x03; - return (flags == 0x0) ? 1024 : (flags == 0x1) ? 512 : - (flags == 0x3) ? 2048 : -1; -} - - -static void 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); - write(fd, buf, snprintf(buf, sizeof(buf), "%u", value)); - close(fd); + return (flags == 0x0) ? 512 : (flags == 0x1) ? 384 : + (flags == 0x3) ? 640 : -1; } @@ -247,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 > 0) + 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; @@ -271,8 +292,15 @@ bool ra_process(void) while (true) { struct sockaddr_in6 from; struct iovec iov = {buf, sizeof(buf)}; - struct msghdr msg = {&from, sizeof(from), &iov, 1, - cmsg_buf, sizeof(cmsg_buf), 0}; + struct msghdr msg = { + .msg_name = (void *) &from, + .msg_namelen = sizeof(from), + .msg_iov = &iov, + .msg_iovlen = 1, + .msg_control = cmsg_buf, + .msg_controllen = sizeof(cmsg_buf), + .msg_flags = 0 + }; ssize_t len = recvmsg(sock, &msg, MSG_DONTWAIT); if (len <= 0) @@ -315,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;