In coap_run_once(), incoming packets are checked if they are UDP
datagrams with a destination address and port that match either
one of the existing sessions or the bind address of an endpoint.
Packets that do not match these criteria are dropped.
The layout of struct coap_address_t is platform-dependent. This
change introduces getter/setter functions to retrieve and modify
the port component:
uint16_t coap_address_get_port(const coap_address_t *addr)
void coap_address_set_port(coap_address_t *addr, uint16_t port)
The respective port is given in host byte order and will be
converted to/from network byte order automatically.
To ensure that the arenas for static memory allocation are initialized
properly, coap_memory_init() now is called directly from
coap_startup() for all platforms.
coap_malloc_type() and coap_free_type() now use static memarray_t
arenas on RIOT when module memarray is in use. Otherwise, these
functions are mapped to malloc() and free(), respectively.
A RIOT-specific version of the function coap_network_read() is
now included in the new file coap_io_riot.c. This function requires
the received gnrc_pktsnip_t structure to be passed with the
coap_socket_t structure.
The buffer szSession for storing a textual representation of the
session structure has been trimmed down to 2 * (INET6_ADDRSTRLEN + 8)
+ 24, allowing two IPv6 address references, port numbers, some
structuring text and about eight characters for the interface index.
Background: coap_print_addr() calls inet_ntop() for address output
which on RIOT is mapped to ipv6_addr_to_str(). As the length parameter
of ipv6_addr_to_str() is a uint8_t, only the lower eight bits of
szSession's size are effectively used. The previous value of 256 then
always lead no ENOSPC because 256 & 0xff == 0.
RIOT lacks support of the ancillary interface and various ioctls
therefore basic sendto() and recvfrom() are used instead.
coap_io.c: Fix mismatching #elif
This change fixes a mismatching #elif introduced during git rebase
conflict resolution.
As of gcc 10, -fno-common is default to check for multiple
definitions of global variables at link time. This change makes
the global variables in the unit test files static to avoid
error messages caused by this.
Fixes#464
Replace COAP_RUN_BLOCK with COAP_IO_WAIT and COAP_RUN_NOBLOCK with
COAP_IO_NO_WAIT for naming clarity.
Instead of COAP_IO_NO_WAIT being 1, make it -1 to fix 1ms busy loop.
Handle the case when coap_io_prepare_io returns 0 to prevent indefinite
select() wait.
include/coap2/net.h:
Make the timeout_ms parameter uint32_t in coap_io_process*() functions to
make sure special case of COAP_IO_NO_BLOCK is correctly handled on different
architectures.
Update COAP_IO_NO_BLOCK to -1.
src/coap_io.c:
Fix the 1ms busy loop and potential infinite wait in the non epoll case.
man/coap_io.txt.in:
Update documentation to reflect the changes.
examples/coap-server.c:
examples/contiki/server.c:
Update to use COAP_IO WAIT and COAP_IO_NO_WAIT as appropriate.
In theory, print_timestamp() could omit the terminating null byte when
the buffer passed as argument is too small or if snprintf() returns -1.
To make coap_log_impl() more robust against unforeseen out-of-bounds
access, the length returned by print_timestamp() now is passed to
fprintf() explicitly.
In the same way that coap_split_uri() allows coaps:// scheme even if DTLS is
not available, it should allow coap+tcp:// and coaps+tcp:// scheme and let
other functions check whether TCP/TLS is available or not.
examples/client.c:
Verify if TCP is supported for scheme coap+tcp://.
src/coap_session.c:
Verify that the underlying CoAP transport protocol is supported in
coap_session_create_client().
Add verify for TCP protocol in coap_new_endpoint(), as well as always check
if TLS is supported.
src/uri.c:
Always allow coap+tcp:// and coaps+tcp:// in coap_split_uri() as a parsed
scheme in same way that coaps:// is always allowed.
Makefile.libcoap:
Include coap_tcp.c to include coap_tcp_is_supported() function.
examples/lwip/Makefile:
Include coap_tcp.o to include coap_tcp_is_supported() function.
The # COAP_RESPONSE_nnn entries were introduced to handle a response change
introduced by draft-ietf-core-coap-04 in 2011. These are no longer used
and can cause confusion - e.g.
define COAP_RESPONSE_304 COAP_RESPONSE_CODE(203) /* 2.03 Valid */
as raised in #456. Entries now removed.
Eliminate the matrix description which overides the jobs.
If both keywords are present, matrix takes precedence. This made
subsequent stages specified in the jobs section to be ignored.
Fixes#452
When libcoap config allows self-signed certificates (*) the library should
also accept self-signed certificates at depth 0. This is achieved by allowing
X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT [1].
(*) coap_dtls_pki_t.allow_self_signed == 1
[1] https://www.openssl.org/docs/man1.1.0/man3/X509_STORE_CTX_get_error_depth.html
coap_read(), coap_write() and coap_run_once() are confusing in their names
and do not really describe what they do.
For example, coap_read() does both reading and writing, coap_write() may
do some writing, but primarily is used to determine what should be monitored
and for how long to wait in the following select() or epoll_wait() calls.
coap_run_once() implies that the code is only to be run once - again confusing.
By renaming coap_read() to coap_io_do_io(), this better describes what this
function does.
By renaming coap_write() to coap_io_prepare_io() this better describes what this
function does.
By renaming coap_run_once() to coap_io_process(), this better describes what
this function does.
By renaming coap_io_do_events() to coap_io_do_epoll(), this better describes what
this function does and is associated with.
A wrapper function coap_io_prepare_epoll() has been created, using
coap_io_prepare_io() with some preset values to simplify function usage.
include/coap2/net.h:
Update with the new function names, and deprecate the old functions. Also
document the fact that coap_io_prepare_io(), coap_io_do_io(),
coap_io_prepare_epoll(), and coap_io_do_epoll() are really internal functions.
Create app_io module for Doxygen.
libcoap-2.map:
libcoap-2.sym:
Expose the new functions to applications.
examples/client.c:
examples/coap-rd.c:
examples/coap-server.c:
examples/contiki/coap-observer.c:
examples/contiki/server.c:
examples/etsi_iot_01.c:
man/coap_io.txt.in:
man/coap_observe.txt.in:
src/coap_io.c:
src/coap_io_lwip.c:
src/net.c:
src/pdu.c:
Update using the new function names.
Setting the etimer has been moved out of coap_io_process() into
coap_io_do_epoll(), making the logic easier for applications to use
coap_io_do_epoll() should they need to. This also gets rid of a
potential timing window where a pending etimer event gets missed.
coap_io_do_epoll() now calls coap_io_prepare_epoll() if the etimer has
triggered removing the need for applications using coap_io_do_epoll() to
set up their own loops if etimer is triggered.
get_context() creates a new context object and adds coap_endpoint_t
objects for all listen addresses. The function now clears the
context object and returns NULL when no endpoint was created,
causing the server to exit immediately.
`coap-server(1)` segfaults when invoked as:
$ coap-server -A '2001:db8::1'
Feb 09 18:28:49 WARN coap_socket_bind_udp: bind: Address not available
Segmentation fault
In this case, the `ep->context->endpoint` is NULL but
`coap_free_endpoint` still attempts to access it. To prevent this
invocation from causing a segmentation fault, check if
`ep->context->endpoint` is NULL before accessing it.