Commit Graph
2440 Commits
Author SHA1 Message Date
Jon Shallow fe51d3335e lwip: Fix minor issues
Increase MEMP_LEN_COAPSTRING to handle example server .wellknown/core request.

If session cannot be generated, check for NULL pointer.
2022-06-21 10:26:40 +01:00
Jon Shallow 6046dcbd55 net.c: Fix broken client only build
Comment out specific server code in coap_start().
2022-06-17 16:42:45 +02:00
Jon Shallow 20f15a17d6 Large Observes: Prevent server sending new response if active response
If the response is large, it can take time to transfer over the body.  If
the server then initiates a new unsolicited response during the existing
transfer, then overflow / retry issues start to occur, compounded if multiple
unsolicited responses are triggerred during an existing transfer.

Hold back the notify of the new unsolicited response(s) until the
existing response has completed (or failed for another reason).

Other code has been tightened up incase the server or client are
not libcoap based and also exhibit this behavior, so to have a better chance
of recovery.
2022-06-17 13:02:45 +02:00
Jon Shallow 5a10ce4890 Congestion Control: add in RFC7252 configuration flexibility
Create where appropriate default values for the Congestion control base
values and update the derived CC values accordingly.

Move derived value #define to coap_session_internal.h.

Update coap_session_t to hold the new CC values.

Update documentation for the new CC functions that update / get the
appropriate values.

NOTE: PROBING_WAIT is not currently checked in the code.
2022-06-17 12:15:19 +02:00
Jon Shallow 41afb92141 net.c: Update .well-known/core handling to use common logic
This removes a lot of code duplication by creating a pseudo resource
for .well-known/core that is not included in the .well-known/core output.
In particular specific Block2 option handling is no longer required.

Updated tests which now include checking that queries work.
2022-06-17 12:12:45 +02:00
Jon Shallow 6b32ed3de2 coap_io.c: Track ICMP Host Administravely Prohibited error
Add in tracking for EHOSTUNREACH in coap_network_read().
2022-06-17 12:00:49 +02:00
Jon Shallow 279755b1df coap_send: Make error checks for coap_send() more rigorous
Always delete PDUs on error before return from coap_send() (aligning with
previous documentation).

Check that the socket is still available before continuing with the PDU
transmission in coap_send().

Update documentation to be clearer on non-usage of PDU on return from
coap_send().

Trap coap_send() errors in coap-client.

Move event handlers setup code to earlier in coap-client to trap events
early on in the CoAP setup process.
2022-06-17 11:34:41 +02:00
Olaf Bergmann 925d39fd8c coap-server.c: Cleanup misplaced comment
Fix comment that has been left at the wrong place by a previous change.
2022-06-17 11:25:08 +02:00
Jon Shallow c771767147 coap_gnutls.c: Handle another error in do_gnutls_handshake()
Treat GNUTLS_E_UNEXPECTED_PACKET as a reason for DTLS closure.

To test, gnutls server and client with different PSK keys and coaps://

GNUTLS_E_UNEXPECTED_PACKET raised if alert sent by server in the
middle of the setup handshaking.
2022-06-17 08:59:00 +02:00
Jon Shallow 801e5492f2 CSM: Move coap_client_delay_first() to later in code processing
Commit 069a0786ce (#833) introduced the concept
of delaying PDU building until the CSM message had been received from server
so that PDUs could be correctly sized.

However, this meant that the functions coap_new_client_session*() would not
complete until the CSM was in for reliable protocols.  Some applications need
the returned session to handle / differentiate between different events.

CSM can update
session->mtu
session->csm_block_supported
session->csm_bert_rem_support

coap_client_delay_first() is now called in coap_add_data_large_request()
and coap_session_max_pdu_size() (not coap_session_max_pdu_rcv_size() as
this is for receiving PDUs).

coap_client_delay_first() has been updated to catch recursive requests as well
as using more of the common code for the LwIP specifics.
2022-06-17 08:49:09 +02:00
mrdeep1 4cad453197 Merge pull request #778 from mrdeep1/coap_io_prepare_io
coap_io_prepare_io: Re-order function code for correctly updating sockets[]
2022-06-14 10:22:06 +01:00
mrdeep1 ee863e4509 Merge pull request #863 from mrdeep1/update_block
block.c: Correctly preset updated_block variable
2022-06-13 16:54:52 +01:00
mrdeep1 f2de7098ce Merge pull request #862 from mrdeep1/white_space_1
async.c: Remove white space
2022-06-13 16:48:19 +01:00
Jon Shallow 346a831cd6 block.c: Correctly preset updated_block variable 2022-06-13 13:42:18 +01:00
Jon Shallow 56db248dab async.c: Remove white space 2022-06-13 13:35:15 +01:00
mrdeep1 df99212fac Merge pull request #850 from mrdeep1/sigpipe
TLS SIGPIPE: Stop programs exiting with code 141 (128 + 13:SIGPIPE)
2022-06-09 10:27:57 +01:00
Jon Shallow 256a758e02 TLS SIGPIPE: Stop programs exiting with code 141 (128 + 13:SIGPIPE)
The example coap-client application was setting the SIGPIPE signal to
SIG_IGN too late.

For applications that do not handle SIGPIPE, set MSG_NOSIGNAL in send() flags
to stop SIGPIPE being generated (but send() still returns EPIPE).

Drop the logging level when a client session cannot be extablished.

Can be reproduced when server requires certificates, but client does not
provide any certificate when using coaps+tcp:// and Mbed TLS.

Window 1
$ coap-server -c server.pem -C ca.pem
Window 2
$ coap-client coaps+tcp://127.0.0.1
$ echo $?
2022-06-09 09:21:14 +01:00
mrdeep1 c74b3efcb4 Merge pull request #744 from mrdeep1/cache_caution
Caching: Highlight requirements ignoring certain CoAP Options
2022-06-07 20:28:34 +01:00
mrdeep1 8b05aa5211 Merge pull request #848 from mrdeep1/bert
BERT: Support block BERT szx of 7 for reliable protocols
2022-06-07 16:07:35 +01:00
mrdeep1 573d3abc55 Merge pull request #851 from mrdeep1/multicast_log
CMakeLists.txt: Correctly determine cmsghdr support for determining addresses
2022-06-07 15:56:12 +01:00
mrdeep1 2449c1ee06 Merge pull request #857 from kkrentz/net-pr
net.c: fix null pointer exception
2022-06-07 15:53:31 +01:00
mrdeep1 05384551af Merge pull request #853 from mrdeep1/mbedtls_3_1
coap_mbedtls.c: Fix coap_rng() return for 3.x code
2022-06-07 15:41:35 +01:00
mrdeep1 5a2e45e745 Merge pull request #856 from mrdeep1/rfc7390
RFC7390: Update support for RFC7390
2022-06-07 15:38:24 +01:00
kkrentz 6649bdef39 net.c: fix null pointer exception 2022-06-07 16:22:37 +02:00
Jon Shallow 03a9059439 BERT: Support block BERT szx of 7 for reliable protocols
Add in new coap_block_b_t structure that tracks BERT usage, and
use new functions coap_*block_b_* that are in addition to the old
coap_*block_* functions that use coap_block_b_t.
2022-05-31 19:45:29 +01:00
Jon Shallow 445a9481de RFC7390: Update support for RFC7390
Update documentation and add in missing content-format.
2022-05-26 21:10:29 +01:00
Jon Shallow 428f759659 coap_mbedtls.c: Fix coap_rng() return for 3.x code
coap_rng() needs to return 0 on success, and negative error on failure.

Corrected some logging function names.

Corrected the return value in coap_prng_default() to be always 1 on success
and 0 on failure to be consistent with coap_rand_func_t.

Updated coap_prng() to return 0 if an error in the used random function.
2022-05-24 10:36:18 +01:00
Jon Shallow 1b2668f562 CMakeLists.txt: Correctly determine cmsghdr support for determining addresses
check_symbol_exists() only works for defines etc., not struct, so look for
CMSG_FIRSTHDR instead.

Make sure _GNU_SOURCE is defined to pick up the in6_pktinfo definition needed
for the logic using cmsghdr.
2022-05-22 16:03:03 +01:00
Jon Shallow 21fd838dc7 coap_io_prepare_io: Re-order function code for correctly updating sockets[]
Two cases for not updating active sockets[] with file descriptors from a
session (non epoll code)
  coap_retransmit() can release a session
  coap_dtls_handle_timeout() can disconnect a session

Move the restransmit test code to before any updates to socket[].

Update coap_dtls_handle_timeout() to return a value indicating a DTLS timeout
has occurred.  At the same time move the coap_dtls_handle_timeout() checks
into the first sessions iteration loop, removing having to iterate through the
sessions twice if DTLS.
2022-05-20 11:10:32 +01:00
obgm 50128de191 Merge pull request #847 from mrdeep1/async_con
net.c: Make sure separate response is CON for CON requests
2022-05-11 15:07:45 +02:00
Olaf Bergmann cfbf3ab617 doc/main.md: Update copyright year 2022-05-11 13:03:51 +02:00
Jon Shallow f28044303a net.c: Make sure separate response is CON for CON requests 2022-05-10 15:25:16 +01:00
obgm abbe3edd5a Merge pull request #795 from mrdeep1/async_fix
async: Handle changes to delay when using epoll
2022-05-06 14:47:39 +02:00
obgm 7404ee172f Merge pull request #833 from mrdeep1/csm_message_size
CSM: Support different XMT and RCV Max-Message-Size
2022-05-06 13:28:27 +02:00
obgm 13f53368c3 Merge pull request #844 from mrdeep1/mutex_fix
recursive mutex: Stop recursive Mutex when doing handler callbacks
2022-05-06 12:10:20 +02:00
Jon Shallow 069a0786ce CSM: Support different XMT and RCV Max-Message-Size
Track the RCV mtu size separately from the XMT mtu, so that sufficiently
large PDUs can be built for receiving incoming data.

Wait until reliable session is complete and the initial CSM have been exchanged
before building any new PDUs for transmission so that they can hold the
appropriate amount of Max-Message-Size data.

Add in support into coap-server and coap-client for defining the
Max-Message-Size to use by adding in 2 new functions
coap_context_set_csm_max_message_size() and
coap_context_get_csm_max_message_size().

Add in flexibility into coap-server to control the initial example_data size.

Requires #844 to prevent recursive mutex locking when initiating proxy ongoing
session to upstream server.
2022-05-04 10:01:37 +01:00
Jon Shallow 9cbe5757cb recursive mutex: Stop recursive Mutex when doing handler callbacks
Move around some of the COAP_CONSTRAINED_STACK mutex locking to prevent
recursive locking (issue when a proxy initiates an ongoing reliable client
connection).
2022-05-04 09:57:34 +01:00
obgm 0691f4ff5d Merge pull request #839 from namib-project/server_session_events
Add events for server session state management
2022-04-29 10:57:15 +02:00
Hugo Hakim Damer d9c19c378f event.h: Add events for server session state management
This commit adds two new events (`COAP_EVENT_SERVER_SESSION_NEW`
and `COAP_EVENT_SERVER_SESSION_DEL`), which are triggered when the
IO loop creates or deletes server-side sessions.
2022-04-29 09:18:51 +02:00
obgm d9fbdba7ec Merge pull request #842 from mrdeep1/sessions_balance
coap_session.c: Balance SESSIONS_ADD and SESSIONS_DELETE usage
2022-04-29 08:58:26 +02:00
obgm a53a026e29 Merge pull request #802 from namib-project/non_vendored_tinydtls
Allow usage of a non-vendored TinyDTLS version when using autotools
2022-04-27 10:23:13 +02:00
Jon Shallow 7e20aa9ef1 coap_session.c: Balance SESSIONS_ADD and SESSIONS_DELETE usage 2022-04-22 13:23:22 +01:00
Hugo Hakim Damer 806861359b configure.ac: Allow using non-vendored TinyDTLS with autotools build
This commit allows using a system-provided version of TinyDTLS when
building libcoap.
To do so, some potentially backwards-incompatible changes to the way
TinyDTLS is handled in the configure-script were made:
- The argument `--with-submodule-tinydtls` is added. If it is set to
  yes, the configure-script will use the TinyDTLS git submodule for
  DTLS functionality (assuming `--with-tinydtls` is also set).
- The configure-script will prefer using the system-provided version
  of TinyDTLS as long as `--with-submodule-tinydtls` is not explicitly
  set to yes.
- It will however fall back to the vendored version by default if no
  system-provided version could be found and if
  `--without-submodule-tinydtls` is not explicitly set.
- If a system-provided version of TinyDTLS was found, it will be used
  automatically if no DTLS backend was selected explicitly (with the
  lowest priority compared to the other DTLS libraries). However,
  the submodule will *never* be used automatically, even if
  `--with-submodule-tinydtls` is set (i.e., to use the submodule,
  `--with-tinydtls` must be set as well).

If TinyDTLS is not installed system-wide (or if the installed version
is too old to contain a pkg-config file), the behaviour should be
identical to older versions.
Otherwise, use the `--with-submodule-tinydtls` option to force usage
of the git submodule version if required.
2022-04-11 19:18:13 +02:00
Hugo Hakim Damer 6c8b76d534 tinydtls: Update to latest version
Update the tinydtls submodule to commit fbf2bd8.
2022-04-11 14:58:42 +02:00
Jon Shallow aa391b5b76 async: Handle changes to delay when using epoll
Add in new function coap_async_trigger() to immediately release an async
session, rather than using coap_async_set_delay(async, 1).

Add new internal function coap_update_epoll_timer() to reduce code
duplication and use it for the async logic.

Move doing coap_io_prepare_epoll() for every epoll event to just doing it once
outside of the loop.

Update documentation.
2022-04-07 13:14:49 +01:00
obgm 20eac7bd2f Merge pull request #773 from mrdeep1/client_repeat_delay
coap-client.c: Delay sending each request using -G by 1 second
2022-04-07 13:58:12 +02:00
obgm f188ae57d8 Merge pull request #840 from mrdeep1/add_data_leak
block.c: Fix data leak in coap_add_data_large_internal
2022-04-07 13:57:22 +02:00
Jon Shallow 65cba25cc7 coap-client.c: Delay sending each request using -G by 1 second
This then allows any (D)TLS to be set up between sending off the requests and
better demonstrates how this can be done in user code.

Allocate separate data for each post/put PDU.

Hold off on starting timer for next transmission until after response has
been received from the server (handles relatively slow DTLS startup).
2022-04-07 09:45:28 +01:00
Jon Shallow d57d44aa14 block.c: Fix data leak in coap_add_data_large_internal 2022-04-07 09:42:27 +01:00
Olaf Bergmann eb7656850f pdu.h: Add Content-Format for application/ace+cbor
RFC 9200 defines the new media type application/ace+cbor for
Authentication and Authorization in Constrained Environments.  The
CoAP Content-Format value for this media type is registered as value
19.
2022-03-15 13:01:04 +01:00