Skip to content

Commit

Permalink
fixup! net: Rework neighbours
Browse files Browse the repository at this point in the history
  • Loading branch information
heatd committed Nov 29, 2024
1 parent 943c94b commit 6ad7b8a
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions kernel/kernel/net/ipv6/ipv6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,13 @@ expected<inet_route, int> route_from_routing_table(const inet_sock_address &to,
* If the result = r.dest, we can use this interface.
*/
int mask_bits;
const auto masked = dest & r->mask;
#if 0
print_v6_addr(dest);
print_v6_addr(r->mask);
print_v6_addr(r->dest);
#endif
if ((dest & r->mask) != r->dest)
if (masked != r->dest)
continue;

if (required_netif && r->nif != required_netif)
Expand All @@ -247,14 +248,16 @@ expected<inet_route, int> route_from_routing_table(const inet_sock_address &to,
printk("%s is good\n", r->nif->name);
printk("is loopback set %u\n", r->nif->flags & NETIF_LOOPBACK);
#endif
/* TODO: This can and should be computed beforehand */
mask_bits = count_bits(r->mask.__in6_union.__s6_addr32[0]) +
count_bits(r->mask.__in6_union.__s6_addr32[1]) +
count_bits(r->mask.__in6_union.__s6_addr32[2]) +
count_bits(r->mask.__in6_union.__s6_addr32[3]);

/* TODO: This can and should be computed beforehand */
mask_bits = count_bits(r->mask);

#if 0
pr_warn("dest %pI6 mask %pI6 route dest %pI6 mask_bits %d\n", &dest, &r->mask, &r->dest,
mask_bits);
#endif
if (mask_bits > longest_prefix ||
(longest_prefix == mask_bits && r->metric > highest_metric))
{
Expand Down Expand Up @@ -517,6 +520,16 @@ int inet_socket::setsockopt_inet6(int level, int opt, const void *optval, sockle
this->ttl = ttl;
return 0;
}

case IPV6_V6ONLY: {
auto ex = get_socket_option<int>(optval, len);

if (ex.has_error())
return ex.error();

ipv6_only = ex.value() ? 1 : 0;
return 0;
}
}

return -ENOPROTOOPT;
Expand All @@ -529,6 +542,10 @@ int inet_socket::getsockopt_inet6(int level, int opt, void *optval, socklen_t *l
case IPV6_MULTICAST_HOPS:
case IPV6_UNICAST_HOPS:
return put_option(ttl, optval, len);
case IPV6_V6ONLY: {
int val = ipv6_only;
return put_option(val, optval, len);
}
}

return -ENOPROTOOPT;
Expand Down

0 comments on commit 6ad7b8a

Please sign in to comment.