diff options
author | Hans Dedecker <hans.dedecker@technicolor.com> | 2013-12-10 09:46:56 +0100 |
---|---|---|
committer | Hans Dedecker <hans.dedecker@technicolor.com> | 2013-12-10 09:46:56 +0100 |
commit | 3f417e55d5208df5b91aa9b101657bbc7a461614 (patch) | |
tree | e7841f18874a861d492d863790b79d71f6f7ac13 /src | |
parent | f5877367522aad0b27d138e4a56d01be3bd33f2d (diff) |
Router Advertisement/Solicitation sanity check
Sanity checks according to RFC4861 paragraphs 6.1.1 and 6.1.2
Diffstat (limited to 'src')
-rw-r--r-- | src/router.c | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/src/router.c b/src/router.c index 0b01a77..a213c84 100644 --- a/src/router.c +++ b/src/router.c @@ -130,12 +130,66 @@ static void sigusr1_refresh(_unused int signal) uloop_timeout_set(&iface->timer_rs, 1000); } +static int router_icmpv6_valid(struct sockaddr_in6 *source, uint8_t *data, size_t len) +{ + struct icmp6_hdr *hdr = (struct icmp6_hdr *)data; + struct icmpv6_opt *opt; + size_t optlen = len - sizeof(*hdr); + + /* Hoplimit is already checked in odhcpd_receive_packets */ + if (len < sizeof(*hdr)) + return 0; + + if (hdr->icmp6_code) + return 0; + + switch (hdr->icmp6_type) { + case ND_ROUTER_ADVERT: + if (!IN6_IS_ADDR_LINKLOCAL(&source->sin6_addr)) + return 0; + + opt = (struct icmpv6_opt *)((struct nd_router_advert *)data + 1); + break; + + case ND_ROUTER_SOLICIT: + opt = (struct icmpv6_opt *)((struct nd_router_solicit *)data + 1); + break; + + default: + return 0; + } + + while (optlen > 0) { + size_t l = opt->len << 3; + + if (optlen < sizeof(*opt)) + return 0; + + if (l > optlen || l == 0) + return 0; + + if (opt->type == ND_OPT_SOURCE_LINKADDR && IN6_IS_ADDR_UNSPECIFIED(&source->sin6_addr) && + hdr->icmp6_type == ND_ROUTER_SOLICIT) { + return 0; + } + + opt = (struct icmpv6_opt *)(((uint8_t *)opt) + l); + + optlen -= l; + } + + return 1; +} // Event handler for incoming ICMPv6 packets -static void handle_icmpv6(_unused void *addr, void *data, size_t len, +static void handle_icmpv6(void *addr, void *data, size_t len, struct interface *iface) { struct icmp6_hdr *hdr = data; + + if (!router_icmpv6_valid(addr, data, len)) + return; + if ((iface->ra == RELAYD_SERVER && !iface->master)) { // Server mode if (hdr->icmp6_type == ND_ROUTER_SOLICIT) send_router_advert(&iface->timer_rs); |