X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fodhcpd.git;a=blobdiff_plain;f=src%2Frouter.c;h=b29e531ef48aa07f3a92842e18312e7a12b4bbc3;hp=907011aa29d83ad4835796d7d6eea3fed83d3906;hb=79d005edf35a363e2d254e37ca2edcd743c2b4f6;hpb=e9a21fdb43c9f94762a724db1a043b376f745ae3;ds=sidebyside diff --git a/src/router.c b/src/router.c index 907011a..b29e531 100644 --- a/src/router.c +++ b/src/router.c @@ -186,20 +186,6 @@ static void handle_icmpv6(void *addr, void *data, size_t len, } -static bool match_route(const struct odhcpd_ipaddr *n, const struct in6_addr *addr) -{ - if (n->prefix <= 32) - return ntohl(n->addr.s6_addr32[0]) >> (32 - n->prefix) == - ntohl(addr->s6_addr32[0]) >> (32 - n->prefix); - - if (n->addr.s6_addr32[0] != addr->s6_addr32[0]) - return false; - - return ntohl(n->addr.s6_addr32[1]) >> (64 - n->prefix) == - ntohl(addr->s6_addr32[1]) >> (64 - n->prefix); -} - - // Detect whether a default route exists, also find the source prefixes static bool parse_routes(struct odhcpd_ipaddr *n, ssize_t len) { @@ -207,7 +193,7 @@ static bool parse_routes(struct odhcpd_ipaddr *n, ssize_t len) char line[512], ifname[16]; bool found_default = false; - struct odhcpd_ipaddr p = {IN6ADDR_ANY_INIT, 0, false, 0, 0, 0}; + struct odhcpd_ipaddr p = {IN6ADDR_ANY_INIT, 0, 0, false, 0, 0, 0}; while (fgets(line, sizeof(line), fp_route)) { uint32_t rflags; if (sscanf(line, "00000000000000000000000000000000 00 " @@ -224,8 +210,8 @@ static bool parse_routes(struct odhcpd_ipaddr *n, ssize_t len) for (ssize_t i = 0; i < len; ++i) { if (n[i].prefix <= 64 && n[i].prefix >= p.prefix && - match_route(&p, &n[i].addr)) { - n[i].prefix = p.prefix; + !odhcpd_bmemcmp(&p.addr, &n[i].addr, p.prefix)) { + n[i].dprefix = p.prefix; break; } } @@ -421,18 +407,18 @@ static void send_router_advert(struct uloop_timeout *event) for (ssize_t i = 0; i < ipcnt; ++i) { struct odhcpd_ipaddr *addr = &addrs[i]; - if (addr->prefix > 64 || addr->prefix == 0) { + if (addr->dprefix > 64 || addr->dprefix == 0) { continue; // Address not suitable - } else if (addr->prefix > 32) { - addr->addr.s6_addr32[1] &= htonl(~((1U << (64 - addr->prefix)) - 1)); - } else if (addr->prefix <= 32) { - addr->addr.s6_addr32[0] &= htonl(~((1U << (32 - addr->prefix)) - 1)); + } else if (addr->dprefix > 32) { + addr->addr.s6_addr32[1] &= htonl(~((1U << (64 - addr->dprefix)) - 1)); + } else if (addr->dprefix <= 32) { + addr->addr.s6_addr32[0] &= htonl(~((1U << (32 - addr->dprefix)) - 1)); addr->addr.s6_addr32[1] = 0; } routes[routes_cnt].type = ND_OPT_ROUTE_INFO; routes[routes_cnt].len = sizeof(*routes) / 8; - routes[routes_cnt].prefix = addr->prefix; + routes[routes_cnt].prefix = addr->dprefix; routes[routes_cnt].flags = 0; if (iface->route_preference < 0) routes[routes_cnt].flags |= ND_RA_PREF_LOW;