Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UDP: Store local and use local address in metadata #904

Merged
merged 3 commits into from Apr 19, 2024

Conversation

chrysn
Copy link
Contributor

@chrysn chrysn commented Feb 2, 2024

Closes: #903

As discussed there, this is a breaking change, and no feature flag is set for it right now.

I'm surprised that things were this easy. So far, my only tests were whether this builds, thus leaving this as a draft PR. I expect to test this with code that would resolve embassy-rs/embassy#2516, at which point I'll mark it as ready.

src/socket/udp.rs Outdated Show resolved Hide resolved
@chrysn
Copy link
Contributor Author

chrysn commented Feb 2, 2024

I'm having trouble finding the tests that need updating b/c they cover Debug output -- where do the test cases live? I failed to find anything matching case_3_ieee802154 in the sources.

@thvdveld
Copy link
Contributor

thvdveld commented Feb 2, 2024

We test the same test function for different cases by using a proc-macro. The name of the test is before ::case_something.

@thvdveld
Copy link
Contributor

thvdveld commented Feb 2, 2024

Tests are failing because the local_addr in the Meta is None when calling .into() on it, which is probably not what you want in the test cases.

@chrysn
Copy link
Contributor Author

chrysn commented Feb 2, 2024

Tests are now updated and should pass.

Copy link

codecov bot commented Feb 2, 2024

Codecov Report

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

Comparison is base (5eced2a) 79.92% compared to head (dc60300) 79.93%.

Files Patch % Lines
src/socket/udp.rs 70.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #904      +/-   ##
==========================================
+ Coverage   79.92%   79.93%   +0.01%     
==========================================
  Files          80       80              
  Lines       28234    28255      +21     
==========================================
+ Hits        22566    22586      +20     
- Misses       5668     5669       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chrysn
Copy link
Contributor Author

chrysn commented Feb 2, 2024

The coverage report rightfully complains lines in my change that are not covered. I've added a test that does set an explicit correct source address -- so the coverage should be better now.

We could have a second test on the topic of unadressability, but that first needs a decision: what if an application sends an invalid (eg. the unspecified) address as a source address? If we just let it pass, there are some protocol violating outcomes of this (like the unspecified address), and some questionable outcomes (if an IP address's lease time expired between accepting a request and sending a response, can I still send from that address?), but in practice that'd need either deliberate crafting of such a message, or keeping an address for overly long (and yes the application can't know what "overly long" is, but usually it will be fine).

Thus, my recommendation is that we accept whatever the application sets as a source address -- after all, smoltcp AIU doesn't limit applications' privileges, and the application could just send odd data through raw sockets. The stack may still start checking at a later point, and then consider the datagrams unaddressable. For tests, that means that while we could add a test like

diff --git a/src/socket/udp.rs b/src/socket/udp.rs
index c1313aa..d64ff18 100644
--- a/src/socket/udp.rs
+++ b/src/socket/udp.rs
@@ -740,6 +740,16 @@ mod test {
             ),
             Err(SendError::Unaddressable)
         );
+        assert_eq!(
+            socket.send_slice(
+                b"abcdef",
+                UdpMetadata {
+                    local_address: Some(IpvXAddress::UNSPECIFIED.into()),
+                    ..REMOTE_END.into()
+                }
+            ),
+            Ok(())
+        );
         assert_eq!(socket.send_slice(b"abcdef", REMOTE_END), Ok(()));
     }

it would just test the current behavior that is not guaranteed, and thus doesn't really add value.

[edit: Sorry for the force pushes, didn't have cargo fmt checks in my pre-commit hooks; thankfully git absorb came in handy cleaning that up in all the individual commits]

@chrysn chrysn marked this pull request as ready for review February 2, 2024 22:37
@chrysn
Copy link
Contributor Author

chrysn commented Feb 2, 2024

I've now run this with some tests all the way to an embedded-nal-async application through embassy-rs/embassy#2519. Can't claim I've covered every edge case (that will come as I extend those applications), but I'm confident enough with the current state to mark it as ready for review.

@ivmarkov
Copy link

@Dirbaio @chrysn Is there anything outstanding in this PR prohibiting merging?

@chrysn
Copy link
Contributor Author

chrysn commented Feb 12, 2024

From my PoV this is ready for final review -- especially if my recommendation of #904 (comment) is what we go with, but also if not (because even then the signatures would not change, and merely behavior of applications whose input violates the UDP/IP protocol may change between sending an erroneous packet vs. reporting an error).

@thvdveld
Copy link
Contributor

Let's merge this!

@thvdveld thvdveld added this pull request to the merge queue Apr 19, 2024
Merged via the queue into smoltcp-rs:main with commit 125773e Apr 19, 2024
11 checks passed
@chrysn chrysn deleted the pktinfo branch April 19, 2024 13:02
chrysn added a commit to chrysn-pull-requests/RIOT-rs that referenced this pull request Apr 22, 2024
chrysn added a commit to chrysn-pull-requests/RIOT-rs that referenced this pull request Apr 26, 2024
github-merge-queue bot pushed a commit to future-proof-iot/RIOT-rs that referenced this pull request Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants