smoltcp-rs / smoltcp

a smol tcp/ip stack
BSD Zero Clause License
3.75k stars 421 forks source link

Check IPv6 address after processing HBH #861

Closed thvdveld closed 9 months ago

thvdveld commented 10 months ago

Now, the destination address of the IP packet is checked if it is part of the interface addresses or the multicast addresses, only after processing the hop-by-hop header, as this header must be processed by every node.

  1. I modified the has_multicast_group function to also check IPv6 multicast addresses, such as the ALL_NODES, ALL_RPL_NODES (only when using RPL) and the IPv6 solicited address.
  2. For some HBH options, an ICMPv6 parameter problem must be transmitted RFC2460 Section 4.2. In some cases even when the destination address is a multicast address. Therefore also did point (3).
  3. ICMPv6 messages were not transmitted when the destination address was a multicast address. I am not sure why we did it like that. When the destination address is multicast, I use the first IPv6 address from the interface. The selection of the correct IPv6 source address is something that still needs work in smoltcp.

RFC8200 Section 4 says the following about hop-by-hop headers:

Extension headers (except for the Hop-by-Hop Options header) are not processed, inserted, or deleted by any node along a packet's delivery path, until the packet reaches the node (or each of the set of nodes, in the case of multicast) identified in the Destination Address field of the IPv6 header.

Therefore, when an hop-by-hop extension is present, we should process it. Then we check if the packet reached its destination. If not, we discard the packet if we are not using a routing protocol. In case of RPL, we route the packet to the correct next node.

codecov[bot] commented 10 months ago

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (8a86a5a) 79.74% compared to head (1001586) 79.74%.

Files Patch % Lines
src/iface/interface/ipv6.rs 86.66% 10 Missing :warning:
src/iface/interface/mod.rs 93.33% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #861 +/- ## ========================================== - Coverage 79.74% 79.74% -0.01% ========================================== Files 78 78 Lines 28131 28165 +34 ========================================== + Hits 22433 22459 +26 - Misses 5698 5706 +8 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

whitequark commented 10 months ago

@thvdveld Unfortunately this PR deals squarely with the bits of IPv6 I do not have a good understanding of.

thvdveld commented 10 months ago

@whitequark no problem!