Skip to content

nanocoap_server: use zero-copy network buffer for parsing request#21652

Merged
crasbe merged 2 commits intoRIOT-OS:masterfrom
benpicco:nanocoap_server/buf
Sep 4, 2025
Merged

nanocoap_server: use zero-copy network buffer for parsing request#21652
crasbe merged 2 commits intoRIOT-OS:masterfrom
benpicco:nanocoap_server/buf

Conversation

@benpicco
Copy link
Copy Markdown
Contributor

@benpicco benpicco commented Aug 7, 2025

Contribution description

Requests larger than CONFIG_NANOCOAP_SERVER_BUF_SIZE were previously silently ignored.
But we can do better: With sock_udp_recv_buf_aux() we don't need to copy the request into a separate buffer but can just use the buffer allocated by the network stack.

We still need CONFIG_NANOCOAP_SERVER_BUF_SIZE for the response as otherwise the size of the request packet would be the limit for the response packet. But this is now both in control of the server, a good server implementation can only use this for the header and keep the payload in a separate buffer.

The only problem is that several CoAP handler functions (e.g. _sha256_handler()) expect pkt->hdr to point to the response buffer and use pkt->hdr and buf interchangeably.

As a workaround, this also sets pkt->hdr = rbuf in coap_build_reply() to accommodate those handler functions.

Testing procedure

Issues/PRs references

@github-actions github-actions bot added Area: network Area: Networking Area: CoAP Area: Constrained Application Protocol implementations Area: sys Area: System labels Aug 7, 2025
@benpicco benpicco requested a review from maribu August 7, 2025 15:44
@crasbe crasbe added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Aug 7, 2025
@riot-ci
Copy link
Copy Markdown

riot-ci commented Aug 7, 2025

Murdock results

✔️ PASSED

ec00a16 nanocoap: ensure pkt->hdr equals rbuf in coap_build_reply()

Success Failures Total Runtime
10559 0 10560 11m:58s

Artifacts

@crasbe crasbe added this pull request to the merge queue Sep 4, 2025
Merged via the queue into RIOT-OS:master with commit 7c44b06 Sep 4, 2025
28 checks passed
@benpicco benpicco deleted the nanocoap_server/buf branch September 5, 2025 07:53
@benpicco benpicco added this to the Release 2025.10 milestone Dec 3, 2025
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 Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants