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

sys/net/nanocoap: align request handling with spec #21163

Merged

Conversation

maribu
Copy link
Member

@maribu maribu commented Jan 24, 2025

Contribution description

  • Do not reply with a reset message to a reset or an ACK message
  • Reply with a reset message when not able to process a CON/NON message (not even a suitable error reply)

Testing procedure

$ sudo ip tuntap add tap0 mode tap user $(whoami)
$ sudo ip link set tap0 up
$ make BOARD=native64 -C examples/nanocoap_server -j flash term
$ cat test.py                     
import socket, aiocoap
m = aiocoap.Message()
m.code = 0
m.mid = 0
m.mtype = aiocoap.RST
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
s.connect(('fe80::9826:30ff:feb8:31f4', 5683, 0, socket.if_nametoindex('tap0')))
s.send(m.encode())
s.recv(1024)
$ python3 test.py

With master:

$ tshark -i tap0 -Y "coap"
Capturing on 'tap0'
    3 0.000397706 fe80::9826:30ff:feb8:31f3 56273 5683 fe80::9826:30ff:feb8:31f4 CoAP 66 RST, MID:0, Empty Message
    4 0.000675868 fe80::9826:30ff:feb8:31f4 5683 56273 fe80::9826:30ff:feb8:31f3 CoAP 66 RST, MID:0, Empty Message

Note the RST "reply" to the RST

With this PR:

$ tshark -i tap0 -Y "coap"
Capturing on 'tap0'
    7 3.994693734 fe80::9826:30ff:feb8:31f3 54684 5683 fe80::9826:30ff:feb8:31f4 CoAP 66 RST, MID:0, Empty Message

Note that no RST "reply" is send to the RST

Issues/PRs references

None

@maribu maribu added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch labels Jan 24, 2025
@github-actions github-actions bot added Area: network Area: Networking Area: CoAP Area: Constrained Application Protocol implementations Area: sys Area: System labels Jan 24, 2025
@maribu maribu requested a review from MrKevinWeiss January 24, 2025 21:36
@maribu maribu force-pushed the sys/net/nanocoap/better-rfc-conformance branch from 84ae67f to 6d9888a Compare January 24, 2025 21:42
- Do not reply with a reset message to a reset or an ACK message
- Reply with a reset message when not able to process a CON/NON message
  (not even a suitable error reply)
@maribu maribu force-pushed the sys/net/nanocoap/better-rfc-conformance branch from 6d9888a to 9fa2661 Compare January 24, 2025 21:42
@maribu
Copy link
Member Author

maribu commented Jan 24, 2025

Relevant parts of the RFC:

When a recipient is not at all able to process a Confirmable message
(i.e., not even able to provide a suitable error response), it
replies with a Reset message (RST) instead of an Acknowledgement
(ACK).

and

When a recipient is not able to process a
Non-confirmable message, it may reply with a Reset message (RST).

and

To avoid an implosion of error responses, when a server is aware that
a request arrived via multicast, it MUST NOT return a Reset message
in reply to a Non-confirmable message.

(The check for non-confirmable multicast message is simplified to a check for multicast, as only NON may be send as multicats anyway.)

@maribu
Copy link
Member Author

maribu commented Jan 24, 2025

CoAP Pings still work:

$  tshark -i tap0 -Y "coap"
Capturing on 'tap0'
   21 416.775256861 fe80::9826:30ff:feb8:31f3 8061 5683 fe80::9826:30ff:feb8:31f4 CoAP 66 CON, MID:24336, Empty Message
   22 416.775519804 fe80::9826:30ff:feb8:31f4 5683 8061 fe80::9826:30ff:feb8:31f3 CoAP 66 RST, MID:24336, Empty Message
   23 417.775511480 fe80::9826:30ff:feb8:31f3 8061 5683 fe80::9826:30ff:feb8:31f4 CoAP 66 CON, MID:24337, Empty Message
   24 417.775839404 fe80::9826:30ff:feb8:31f4 5683 8061 fe80::9826:30ff:feb8:31f3 CoAP 66 RST, MID:24337, Empty Message
   25 418.776392388 fe80::9826:30ff:feb8:31f3 8061 5683 fe80::9826:30ff:feb8:31f4 CoAP 66 CON, MID:24338, Empty Message
   26 418.776805843 fe80::9826:30ff:feb8:31f4 5683 8061 fe80::9826:30ff:feb8:31f3 CoAP 66 RST, MID:24338, Empty Message
   27 419.777272963 fe80::9826:30ff:feb8:31f3 8061 5683 fe80::9826:30ff:feb8:31f4 CoAP 66 CON, MID:24339, Empty Message
   28 419.777660970 fe80::9826:30ff:feb8:31f4 5683 8061 fe80::9826:30ff:feb8:31f3 CoAP 66 RST, MID:24339, Empty Message
$ coap_ping -i tap0 '[fe80::9826:30ff:feb8:31f4]'
CoAP PING: [fe80::9826:30ff:feb8:31f3]:8061 ==> [fe80::9826:30ff:feb8:31f4]:5683
RST from [fe80::9826:30ff:feb8:31f4]:5683 seq=0 rt=0 time=0.732ms (0.732ms/0.732ms/0.732ms)
RST from [fe80::9826:30ff:feb8:31f4]:5683 seq=1 rt=0 time=0.447ms (0.447ms/0.589ms/0.732ms)
RST from [fe80::9826:30ff:feb8:31f4]:5683 seq=2 rt=0 time=0.576ms (0.447ms/0.585ms/0.732ms)
RST from [fe80::9826:30ff:feb8:31f4]:5683 seq=3 rt=0 time=0.530ms (0.447ms/0.571ms/0.732ms)

@riot-ci
Copy link

riot-ci commented Jan 24, 2025

Murdock results

✔️ PASSED

9fa2661 sys/net/nanocoap: align request handling with spec

Success Failures Total Runtime
10271 0 10271 08m:57s

Artifacts

Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a straightforward fix, nicely done!

@maribu maribu added this pull request to the merge queue Jan 26, 2025
Merged via the queue into RIOT-OS:master with commit ec18e54 Jan 26, 2025
26 checks passed
@maribu maribu deleted the sys/net/nanocoap/better-rfc-conformance branch January 26, 2025 21:19
@maribu
Copy link
Member Author

maribu commented Jan 26, 2025

Thx :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: CoAP Area: Constrained Application Protocol implementations Area: network Area: Networking Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants