Skip to content

Commit 8587f90

Browse files
kderdarlubos
authored andcommitted
[nrf fromlist] net: ipv6: routing: move checking for an own source address
When IPv6 packet is received, there is a check of the packet's source address to verify that it is not interface's non-tentative address. This commit moves this check to the later stages of processing as packets that can be routed are dropped in the early stage otherwise. Upstream PR: zephyrproject-rtos/zephyr#76150 Signed-off-by: Konrad Derda <[email protected]>
1 parent 8968b02 commit 8587f90

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

subsys/net/ip/ipv6.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,18 @@ static uint8_t extension_to_bitmap(uint8_t header, uint8_t ext_bitmap)
449449
}
450450
}
451451

452+
static inline bool is_src_non_tentative_itself(struct in6_addr *src)
453+
{
454+
struct net_if_addr *ifaddr;
455+
456+
ifaddr = net_if_ipv6_addr_lookup(src, NULL);
457+
if (ifaddr != NULL && ifaddr->addr_state != NET_ADDR_TENTATIVE) {
458+
return true;
459+
}
460+
461+
return false;
462+
}
463+
452464
enum net_verdict net_ipv6_input(struct net_pkt *pkt, bool is_loopback)
453465
{
454466
NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(ipv6_access, struct net_ipv6_hdr);
@@ -505,8 +517,6 @@ enum net_verdict net_ipv6_input(struct net_pkt *pkt, bool is_loopback)
505517
}
506518

507519
if (!is_loopback) {
508-
struct net_if_addr *ifaddr;
509-
510520
if (net_ipv6_is_addr_loopback((struct in6_addr *)hdr->dst) ||
511521
net_ipv6_is_addr_loopback((struct in6_addr *)hdr->src)) {
512522
NET_DBG("DROP: ::1 packet");
@@ -526,9 +536,10 @@ enum net_verdict net_ipv6_input(struct net_pkt *pkt, bool is_loopback)
526536
/* We need to pass the packet through in case our address is
527537
* tentative, as receiving a packet with a tentative address as
528538
* source means that duplicate address has been detected.
539+
* This check is done later on if routing features are enabled.
529540
*/
530-
ifaddr = net_if_ipv6_addr_lookup((struct in6_addr *)hdr->src, NULL);
531-
if (ifaddr != NULL && ifaddr->addr_state != NET_ADDR_TENTATIVE) {
541+
if (!IS_ENABLED(CONFIG_NET_ROUTING) && !IS_ENABLED(CONFIG_NET_ROUTE_MCAST) &&
542+
is_src_non_tentative_itself((struct in6_addr *)hdr->src)) {
532543
NET_DBG("DROP: src addr is %s", "mine");
533544
goto drop;
534545
}
@@ -593,6 +604,12 @@ enum net_verdict net_ipv6_input(struct net_pkt *pkt, bool is_loopback)
593604
}
594605
}
595606

607+
if ((IS_ENABLED(CONFIG_NET_ROUTING) || IS_ENABLED(CONFIG_NET_ROUTE_MCAST)) &&
608+
!is_loopback && is_src_non_tentative_itself((struct in6_addr *)hdr->src)) {
609+
NET_DBG("DROP: src addr is %s", "mine");
610+
goto drop;
611+
}
612+
596613
if (net_ipv6_is_addr_mcast((struct in6_addr *)hdr->dst) &&
597614
!(net_ipv6_is_addr_mcast_iface((struct in6_addr *)hdr->dst) ||
598615
net_ipv6_is_addr_mcast_link_all_nodes((struct in6_addr *)hdr->dst))) {

0 commit comments

Comments
 (0)