Commit Graph
754 Commits
Author SHA1 Message Date
Jon Shallow fcbd803828 Q-Block: Better recovery for lossy networks
Following the principles laid out in RFC9177.
2026-09-02 08:50:49 +01:00
Michiel De WitteandClaude Fable 5 091f189e7a Restore the request's local address when a triggered async fires
Server sessions are keyed on (remote address, local port) only, and
session->addr_info.local is overwritten by the destination of every
received packet. When a unicast CON request is parked in a coap_async_t
for a separate response and a multicast packet from the same peer
arrives before the async fires, the re-invoked handle_request() sees a
multicast local address, drops the CON per RFC7252 8.1 ("Invalid
multicast packet received"), and coap_check_async() frees the async:
the response is silently never sent.

Snapshot the local address in coap_register_async() and restore it on
the session before the async fires, so the deferred request is handled
(and its response source selected) against the address it actually
arrived on.

Seen in the field with a CoAP remote control whose GET /endpoint was
answered via the async path while it also multicast periodic
announcements from the same source port: the device received the empty
ACK and then never got the response.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-24 16:35:51 +01:00
Jon Shallow ea841dd0c7 coap_mutex_internal.h: Fix LwIP coap_mutex_destroy 2026-08-20 10:31:27 +01:00
Jon Shallow 850748ca14 Recovery: Support dropping incoming packets for testing 2026-08-20 09:56:09 +01:00
Jon Shallow dfd55459d7 NoTLS: Use SHA1 for digest computations
Removed:
include/coap3/coap_hashkey_internal.h
src/coap_hashkey.c
2026-08-15 15:20:12 +01:00
Jon Shallow 7c456246c9 coap_resource.c: Make Observe deregistration more rigorous 2026-08-15 15:18:46 +01:00
Jon Shallow a5803ff733 OSCORE: Boundary check OSCORE option creation 2026-08-08 13:27:40 +01:00
Jon Shallow 98805f70a5 Documentation tidy up
Add in codespell to pre-commit to help fix documentation errors.
2026-08-08 12:05:03 +01:00
Jon Shallow d4f78cd560 ICMP: Treat genuine ICMP diagnostic PDU for UDP as failure
Posix support only for unicast client requests.

ICMP disgnostic messages are ignored on server sessions.
2026-07-28 16:42:41 +01:00
Jon Shallow 1122bf9fb9 Proxy: Report 5.04 on proxy gateway timeout
Timeout is set to MAX_TRANSMIT_WAIT for CON Non-Reliable requests.

If request is active, idle timeout is ignored.
2026-07-16 11:03:01 +01:00
Mario Kicherer 12b7e99225 add coap_endpoint_join_mcast_group_intf 2026-07-15 10:17:05 +01:00
Jon Shallow 94bacc8939 Duplicate MIDs: If repeat MID request, send back previous response
Clean up duplicate MID handling, and just send back last response if MID
matches.

Removed COAP_BLOCK_CACHE_RESPONSE as no longer required for duplicate MID
handling, and so no need to send an Empty ACK response for a subsequent
Separate response as a referenced copy of the last PDU respponse is now kept
for a session.

Note that if a request is sent by a proxy to an upstream server, this always
converts the upstream server's response into a Separate response back to the
client as the upstream server may take time to respond, do any error recovery
etc.
2026-07-14 09:56:34 +01:00
Jon Shallow 72978e9fc6 PKI: Add in PKI wildcard and multiple SANs support 2026-07-11 10:28:31 +01:00
Jon Shallow ce032db273 oscore_cbor.c: Fix handling large negative integers
Exclude OSS-FUZZ seed corpus files from pre-commit hooks.
2026-07-02 19:54:48 +01:00
Jon Shallow 6c5a0bcb4f TLS: Support client checking sent SNI to received server's PKI CN
For coap-client, if either -R or -C options are specified, then allowing
self-signed certificates is now disabled.
2026-06-27 12:20:00 +01:00
tlhc aa68d5f7e3 feat: add openHiTLS backend support
- Add openHiTLS DTLS/TLS backend
- Integrate openHiTLS crypto into libcoap (D)TLS and OSCORE paths.
- Extend TLS tests and add interop validation script.
2026-06-27 11:18:22 +01:00
Jon Shallow 2e995218f3 SendQueue: Match Mid and Token (if given) to remove entry from queue
For Empty ACK and RST do not do a token match.
2026-06-22 13:48:44 +01:00
Jon Shallow 46e34175b8 RIOT: Fix build against latest version 2026-06-12 17:21:21 +01:00
Jon Shallow 888ba34ece Q-Block: Better timing / recovering when rate limiting
Make use of an outstanding list of blocks to transmit to remove duplicates
and only send one at a time if rate-limiting.
2026-06-10 12:01:10 +01:00
Jon Shallow 193ec26ead Proxy: Check for non-safe options
Generally re-organize option handling, making use of enums etc.

This also updates critical options checks, and well as repeatable options.
2026-06-05 15:22:38 +01:00
Michiel De Witte b4de71ee24 Fix data race in coap_resolve_address_info() 2026-06-02 09:57:30 +01:00
Jon Shallow c4e651ae70 LwIP: Allocate semaphores per context for NO_SYS == 0
Each LwIP coap_context_t must now periodically call coap_io_process().
2026-06-01 09:55:31 +01:00
Jon Shallow d32d298333 coap_oscore.c: Fix replay protection 2026-06-01 09:18:10 +01:00
Jon Shallow 7370fcf6ad LwIP: Add in support for MEM_USE_POOLS for COAP_STRING malloc()s
If both MEMP_USE_CUSTOM_POOLS and MEM_USE_POOLS are defined in
lwipopts.h and there is a suitable
LWIP_MALLOC_MEMPOOL_START .. LWIP_MALLOC_MEMPOOL_END
definition in lwippools.h, then any coap_malloc_type(COAP_STRING, ..) will
make use of the defined pools.

A new src/coap_mem_lwip.c file has been added.
2026-05-27 06:32:11 +01:00
Lucien Zuercher 855d53ef10 oscore: enable external credential storage and safe recipient cleanup
Add reference counting to recipient contexts so they can be safely removed
while still in use by active sessions. Expose callback hooks for credential
lookup, echo, and sequence storage to allow custom backends.
Expand example server to demonstrate the external storage via a simple
file based database. Expand coap_oscore_rcp_conf_t to enable settings
preconfigured echo value, sequence counter and window value as uint64
Enable temporary credentials returned by the find function and are destroyed
after use.
2026-05-20 13:09:24 +01:00
Jon Shallow 9f14450a7e coap_subscribe.c: Fix issue found by oss-fuzz 2026-05-14 15:51:32 +01:00
Jon Shallow 13139e7be9 Options: Check Uri-Path and Location-Path options for . or ..
Check incoming Uri-Path and Location-Path options for just . or .. (or %2e
hex encoded variants) and treat as being invalid.

Stop insertion of Uri-Path and Location-Path options that contain just
. or .. (or %2e hex encoded variants).
2026-05-11 19:41:17 +01:00
Jon Shallow df90dfd7b1 coap_subscribe.c: Sanity check persist startup logic 2026-05-11 18:08:55 +01:00
Magdalena Szumny a77c2c64fe Use Zephyr allocators for Zephyr targets 2026-05-06 13:52:06 +01:00
Jon Shallow de54053789 Q-Block: Reference track coap_lg_srcv_t and coap_lg_crcv_t 2026-05-04 17:46:59 +01:00
Jon Shallow 783b5317ca Uri-Path-Abbrev: Initial IETF Draft support
https://datatracker.ietf.org/doc/html/draft-ietf-core-uri-path-abbrev-04
2026-04-18 12:05:48 +01:00
Jon Shallow edc146d9f1 KeepAlive: Make sure sessions timeout after ping failures
Currently set to 3 concurrent ping failures.
2026-04-18 10:44:44 +01:00
Ernestas Kulik 766b852849 Implement support for LLC sockets
Useful in embedded contexts, where devices might only have a link-layer
connection, but still need to exchange information.
2026-04-18 09:11:19 +01:00
Jon Shallow 3f4d08f964 RateLimit: Support rate limiting NON packets
New coap_context_rate_limit_ppm() function added.

Useful for 6TiSCH type environments.
2026-04-16 13:11:27 +01:00
Jon Shallow 77929465d3 OSCORE: Support complex sender and recipient configurations
Also supports silent_server configuration for recipient definitions.
2026-04-14 10:42:41 +01:00
Jon Shallow 414900ecc3 coap_threadsafe.c: Support multiple use of coap_io_process_configure_threads()
Support for multiple libcoap contexts.
2026-04-08 16:00:01 +01:00
Jon Shallow 5010974814 coap_io_posix.c: Make coap_io_process_remove_threads() thread protected.
Don't report

WARN coap_socket_accept_tcp: accept: Resource temporarily unavailable

when multiple threads are trying to process the same incoming TCP connection.
2026-04-01 15:58:42 +01:00
Jon Shallow 84560ef825 Sanitizer: Fix issues raised by ASan and UBSan when testing 2026-03-24 14:22:45 +00:00
Jon Shallow 39b79e23b4 multi-threading: Lock resource structure when calling request handlers
If an app request call-back modifies any data associated with a resource,
then multiple threads can attempt to unsafely modify the data at the same time.

Lock the resource when calling the app request handler (as global_lock is
unlocked) to prevent concurrent changes to the resource information.

If the app request handler is definately known to not modify the resource
information, then COAP_RESOURCE_SAFE_REQUEST_HANDLER can be set in the flags
for coap_resource_init().  Usually if there is a PUT, POST, PATCH or IPATCH
handler it is unsafe to set this. Setting this will reduce lock contention.
2026-03-23 19:01:53 +00:00
Jon Shallow e817ec85dd coap_resource.c: Fix 2 threads doing a DELETE on the same resource 2026-03-20 13:47:55 +00:00
Jon Shallow 21b7a9a0eb Debugging: Add coap_debug_set_packet_fail() for testing network failures
This is similar to coap_debug_set_packet_loss() which drops packets that are
to be sent, but emulates network reported errors by reporting ECONNREFUSED.
2026-03-20 09:13:41 +00:00
Jon Shallow 40502ffebb oss-fuzz: Fix undefined-behavior
Analyzer run time does not like A -= B or A +=B even if A and B are uint32_t as there is potential
for overflow.

Analyzer run time does not like overflow when doing coap_tick_t - coap_tick_t.

Analyzer run time does not like (uint8_t << 24) as uint8_t is promoted as int, not u_int.

Analyzer run time does not like while(A--) {} even if A is uint32_t, as A is always decremented on
the test, even if the value of A is 0.

Fix potential overflow when analyzing an asn.1 tag.

Fix potential overflow when doing decode_segment() on a % hex value.
2026-03-10 11:09:10 +00:00
Jon Shallow 210cbf378a ASN1: Check for buffer overflows when determining tags and length
Include oss-fuzzer checks.
2026-03-03 10:36:46 +00:00
Florek, Bartlomiej a4d7c29313 fix(config): enhance Zephyr configuration for libcoap 2026-03-03 10:35:36 +00:00
Carl Elgstrom e24ce7a6b3 coap_mem: fix -Werror=return-type in coap_malloc() lwIP stub 2026-02-27 16:32:56 +00:00
Magdalena Szumny e80fe9edd2 API for checking session encryption 2026-02-17 09:57:28 +00:00
Magdalena Szumny f79eaba9b9 Add sorting of optlist 2026-02-16 10:34:48 +00:00
Jon Shallow 152f6a8a58 Includes: Remove unnecessary include files
Include common system header files in coap_internal.h based on HAVE_*H
definitions.

Remove these system header files from include/*/*.h.

Add in system header files where appropriate in various apps.
2026-02-02 10:09:17 +00:00
Jon Shallow c9a4b716c4 binary/strings: Check for size overflows when allocating
Includes a check in coap_block_build_body().
2026-02-02 09:52:55 +00:00
Jon Shallow 07c7a7aa57 body_size: Support configuration of max supported body size for RFC7959
Function coap_context_set_max_body_size() added.

For servers, if body size is too large, a 4.13 response is generated.

For clients, if the body size is too large, the server gets a RST and
no date is passed to the application.  A new event COAP_EVENT_BLOCK_ISSUE
is generated.
2026-01-29 09:53:52 +00:00