Commit e98a3463 authored by Daniele Lacamera's avatar Daniele Lacamera

Fix IPv6 routing: do not look for routes on link-local addresses

parent fb9ba14d
......@@ -352,6 +352,9 @@ static struct pico_ipv6_route *pico_ipv6_route_find(const struct pico_ip6 *addr)
struct pico_tree_node *index = NULL;
int i = 0;
if (pico_ipv6_is_linklocal(addr->addr) || pico_ipv6_is_multicast(addr->addr) || pico_ipv6_is_sitelocal(addr->addr))
return NULL;
pico_tree_foreach_reverse(index, &IPV6Routes)
{
r = index->keyValue;
......@@ -958,12 +961,22 @@ static inline void ipv6_push_hdr_adjust(struct pico_frame *f, struct pico_ipv6_l
icmp6_hdr->crc = short_be(pico_icmp6_checksum(f));
break;
}
#ifdef PICO_SUPPORT_UDP
case PICO_PROTO_UDP:
{
struct pico_udp_hdr *udp_hdr = (struct pico_udp_hdr *) f->transport_hdr;
udp_hdr->crc = pico_udp_checksum_ipv6(f);
break;
}
#endif
#ifdef PICO_SUPPORT_TCP
case PICO_PROTO_TCP:
{
struct pico_tcp_hdr *tcp_hdr = (struct pico_tcp_hdr *) f->transport_hdr;
tcp_hdr->crc = pico_tcp_checksum_ipv6(f);
break;
}
#endif
default:
break;
......@@ -1092,6 +1105,7 @@ static inline struct pico_ipv6_route *ipv6_route_add_link(struct pico_ip6 gatewa
return NULL;
}
return r;
}
......@@ -1134,12 +1148,17 @@ int pico_ipv6_route_add(struct pico_ip6 address, struct pico_ip6 netmask, struct
new->link = r->link;
}
if (new->link && (!pico_ipv6_is_global(new->link->address.addr))) {
new->link = pico_ipv6_global_get(new->link->dev);
}
if (!new->link) {
pico_err = PICO_ERR_EINVAL;
PICO_FREE(new);
return -1;
}
pico_tree_insert(&IPV6Routes, new);
pico_ipv6_dbg_route();
return 0;
......@@ -1455,6 +1474,16 @@ struct pico_ipv6_link *pico_ipv6_linklocal_get(struct pico_device *dev)
return link;
}
struct pico_ipv6_link *pico_ipv6_global_get(struct pico_device *dev)
{
struct pico_ipv6_link *link = pico_ipv6_link_by_dev(dev);
while (link && !pico_ipv6_is_global(link->address.addr)) {
link = pico_ipv6_link_by_dev_next(dev, link);
}
return link;
}
int pico_ipv6_dev_routing_enable(struct pico_device *dev)
{
......
......@@ -122,6 +122,8 @@ struct pico_ip6 *pico_ipv6_source_find(const struct pico_ip6 *dst);
struct pico_device *pico_ipv6_source_dev_find(const struct pico_ip6 *dst);
struct pico_ipv6_link *pico_ipv6_link_by_dev(struct pico_device *dev);
struct pico_ipv6_link *pico_ipv6_link_by_dev_next(struct pico_device *dev, struct pico_ipv6_link *last);
struct pico_ipv6_link *pico_ipv6_global_get(struct pico_device *dev);
struct pico_ipv6_link *pico_ipv6_linklocal_get(struct pico_device *dev);
int pico_ipv6_dev_routing_enable(struct pico_device *dev);
int pico_ipv6_dev_routing_disable(struct pico_device *dev);
#endif
......@@ -493,7 +493,7 @@ static int radv_process(struct pico_frame *f)
(struct pico_icmp6_opt_prefix *) nxtopt;
if (prefix->val_lifetime > 0) {
if (prefix->prefix_len == 64) {
pico_ipv6_route_add(prefix->prefix, netmask, ipv6_hdr->src, 1, NULL);
pico_ipv6_route_add(prefix->prefix, netmask, ipv6_hdr->src, 10, NULL);
} else {
pico_icmp6_parameter_problem(f, PICO_ICMP6_PARAMPROB_IPV6OPT,
(uint32_t)sizeof(struct pico_ipv6_hdr) + (uint32_t)PICO_ICMP6HDR_ROUTER_ADV_SIZE + (uint32_t)(nxtopt - opt_start));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment