As pointed out in issue #368 [1], C++ officially forbids aggregate
initialization for non-aggegrates. This change therefore introduces
a template function coap_make_str_const() that creates and initializes
an automatic variable that is moved to the caller on exit.
Note that at least -std=c++14 is required.
Fixes#368.
[1] https://github.com/obgm/libcoap/issues/368
In coap_split_uri(), the manual conversion of a URI port may run into
an integer overflow for values greater than UINT16_MAX (i.e., 65535).
Although the subsequent typecast into a uint16_t limits possible
damage, a wrong port may be used when exceeding the positive integer
range. This fix adds an additional check to trigger error -4 before
this happens.
Fixes OSS-Fuzz 16115. [1]
[1] https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=16115
hnd_put() creates a new string object for the request's URI path.
When the permittwed number of dynamic resources was exceeded, this
object must be released manually.
This fixed CID 1483553 reported by Coverity scan.
examples/client.c
man/coap-client.txt.in
Update information for the -O option to indicate that a leading 0x causes
the hex text to be included as binary data.
When a subscription is canceled, coap_cancel() iterates through the
resources and deletes the observer. In addition, all outstanding
messages for this observer are removed from the send queue.
With commit 5b1a8f67, the session object associated with the deleted
observer may be automatically released by coap_delete_observer().
Therefore, coap_cancel_all_messages() must be invoked on the session
before deletion.
Fixes CID 1484386 found by Coverity scan.
When an idle server (D)TLS session times out, no event is reported to a
defined event handler. COAP_EVENT_DTLS_CLOSED is reported whenever there is
a read / write issue, and this fix also reports the event COAP_EVENT_DTLS_CLOSED
when the (D)TLS session is closed.
Some extra code had to be added in to prevent event COAP_EVENT_DTLS_CLOSED
being reported twice.
src/coap_gnutls.c:
src/coap_openssl.c:
src/coap_tinydtls.c:
Report event COAP_EVENT_DTLS_CLOSED when coap_dtls_free_session() and
coap_tls_free_session() are called.
src/coap_session.c:
Do not log spurious (D)TLS Alert packets received after session is closed.
Make endpoint->sessions and context->sessions a hashed chain of sessions
based on a key comprising of local and remote addresses and ports instead of
a linked list that has to be linearly searched.
include/coap2/coap_io.h:
include/coap2/coap_session.h:
Create a new struct coap_addr_tuple_t for the local and remote addresses/ports
to be used as the hash key. Update coap_packet_t and coap_session_t
appropriately.
Create SESSIONS_* macros to Add, Delete, Find and Iterate through the hashed
chain.
examples/coap-rd.c:
src/coap_io.c:
src/coap_io_lwip.c:
src/coap_openssl.c:
src/coap_session.c:
src/coap_tinydtls.c:
src/net.c:
src/resource.c:
Update with the new struct element names and replace the LL_* functions with
SESSIONS_* as appropriate.
Update coap_endpoint_get_session() to use SESSIONS_FIND() for fast lookup.
Future work is to review all the SESSIONS_ITER* and see if they can be sped up
as well.
This change enables option values to be entered as byte sequences in
hexadecimal encoding. The value string is interpreted a hex sequence
when prefixed with "0x", e.g.:
-O 23,0x0004
Will set the option Block1 (23) to { 0x00, 0x04 }.
Fixes#377. [1]
[1] https://github.com/obgm/libcoap/issues/377
As COAP_NACK_RST is used for
1. ICMP Port Unreachable message is received
2. CoAP reply RST message.
there needs to be a way to differentiate between these conditions.
If there is detected to be an ICMP response issue to sending a UDP
packet, report this as COAP_NACK_ICMP_ISSUE instead of COAP_NACK_RST.
If the reported issue to coap_session_disconnected() is COAP_NACK_ICMP_ISSUE,
then make sure that the packet (plain or DTLS) gets re-transmitted.
As hinted in #131 discussion, retry of the packet should be attempted,
(as per https://tools.ietf.org/html/rfc7252#section-4.2 ICMP Unreachable)
this fix will cause the plain packet to get retransmitted up to the maximum
retry count if type CON.
Likewise, DTLS will get restarted up to the maximum retry count if type CON.
examples/client.c:
Include COAP_NACK_ICMP_ISSUE in the nack_handler.
include/coap2/coap_io.h:
Add in COAP_NACK_ICMP_ISSUE to coap_nack_reason_t.
src/coap_session.c:
Update coap_session_disconnected() so that plain/DTLS can restart.
src/net.c:
Fix coap_wait_ack() to exponentially back off the re-transmit times.
Update coap_read_session() to report COAP_NACK_ICMP_ISSUE instead of
COAP_NACK_RST.
man/coap_handler.txt.in:
Update documentation
Add in support for both reliable and unreliable sessions when calling
coap_context_set_keepalive().
include/coap2/coap_session.h:
Track the last ping mid in coap_session_t.
src/coap_io.c:
src/coap_session.c:
Support both reliable and unreliable sending of pings in coap_write().
src/net.c:
Determine whether RST packet response is associated with a CoAP Empty Ping
that was sent and handle accordingly.
configure.ac:
examples/client.c:
include/coap2/net.h:
man/Makefile.am:
man/coap-client.txt.in:
man/coap.txt.in:
man/coap_handler.txt.in:
man/coap_keepalive.txt.in: (New)
man/coap_observe.txt.in:
Add in a new man page (coap_keepalive).
Update documentation to remove references to TCP and reliable only.
This is done by calling prng_init() with a non-zero value in coap_startup().
Change 7fb4ace2b7 modified the parameter to
prng_init() from a computed value to 0 when the code was re-organized.
This change uses the current time in microseconds as the seed to prng_init().
include/coap2/coap_time.h:
Add in coap_ticks_to_rt_us() support for lwIP and Contiki
src/net.c:
Update call to prng_init() in coap_startup() to use time in microsecs as the
seed parameter
See #373 where the issue was raised.
With
define Q(frac,fval) ((coap_tick_t)(((1 << (frac)) * (fval))))
and
tmp = SHR_FP(tv.tv_nsec * Q(FRAC, (COAP_TICKS_PER_SECOND/1000000000.0)), FRAC);
The Q function always returns 0 in error - e.g.
(gdb) p ((coap_tick_t)(((1 << (FRAC))*((COAP_TICKS_PER_SECOND/1000000000.0)))))
$6 = 0
(gdb) p ((((1 << (FRAC))*((COAP_TICKS_PER_SECOND/1000000000.0)))))
$7 = 0.001024
whereas we need the value 0.001024 to multiple with tv_nsec.
This change fixes this by moving the coap_tick_t from Q to SHR_FP.
Found when debugging #374
examples/coap-server.c:
Only call coap_resource_notify() whenever a PUT is done to a created dynamic
resource, instead of once a second.
Issue found by Andy Ryan.
If a CoAP client using GnuTLS does not have PSK or PKI security defined
but communicatioes with coaps:// with a CoAP server that has PKI defined,
then there is a memory leak when the session is closed down.
src/coap_gnutls.c:
Free off PKI credentials if a client and PSK or PKI was not explicitly
defined in coap_dtls_free_gnutls_env().
Issue introduced by OpenSSL 1.1.1c causes valgrind errors to be reported. See
https://www.mail-archive.com/openssl-commits@openssl.org/msg21701.html and
https://github.com/openssl/openssl/pull/8606 which did not make 1.1.1c
scripts/build.sh:
tests/valgrind_suppression:
Temporarily suppress valgrind errors when SSL_CTS_new() is called when running
the tests.
Note: This suppression will also need to be applied when running valgrind
against other CoAP executables using OpenSSL 1.1.1c to prevent the valgrind
errors getting reported.
src/coap_openssl.c:
memset cookie_secret to 0 to stop valgrind warning.
As per https://tools.ietf.org/html/rfc7959#section-4
...
Implementation Notes:
o As a quality of implementation consideration, block-wise transfers
for which the total size considerably exceeds the size of one
block are expected to include size indications, whenever those can
be provided without undue effort (preferably with the first block
exchanged)
...
examples/client.c:
Include SIZE1 Option when sending data using BLOCK1 Option.
GnuTLS currently does not retry to send the Client Hello packets if there was
no (Server Hello) response. This was never correctly implemented.
src/coap_gnutls.c:
Fix receive_timout() so that it differentiates between DTLS and TLS.
If DTLS, if data has already been read in, indicate this.
if this is a coap_dtls_handle_timeout() call, only check readfds
(writefds will always be true, causing confusion).
Set DTLS timeouts where appropriate.
Update coap_dtls_*_timeout() functions to return the correct values.
include/coap2/coap_dtls.h:
src/coap_gnutls.c:
src/coap_io.c:
src/coap_notls.c:
src/coap_openssl.c:
src/coap_tinydtls.c:
Add in coap_tick_t now parameter to coap_dtls_get_timeout() for better
accuracy.
include/coap2/libcoap.h:
Simplify COAP_DEPRECATED definition to generically handle Windows
or other builds when setting the define for COAP_DEPRECATED.
Fixes#363
src/net.c:
Corect the length for the final block size.
Add in an ETAG and SIZE2 option into the response as suggested by RFC7959.
examples/client.c:
Warn if URI path is too long for internal buffer (found when testing that
a large WellKnown response triggered sending BLOCK2 correctly).
Increase internal buffersize to allow longer URIs.
To reproduce issue
coap-client -b 256 coap://127.0.0.1/.well-known/core
As reported by Zafi Ramarosandratana. See #360 which this fixes.
As the field value in struct dynamic_resource_t may be NULL,
hnd_get() must check before accessing resource_entry->value->length
and resource_entry->value->s.
This bug was detected by Andy Ryan doing a GET after a PUT with
an empty payload to unknown_put/something.
Once a ICMP Port Unreachable message is received, the session is
disconnected by a call to coap_session_disconnect(). However if the session
is of type CON, the logic currently tries to retransmit the packet, but
nothing gets sent out.
src/coap_session.c:
Make sure that any entries on the context->sendqueue for the disconnected
session are removed.
examples/client.c:
Add in a Nack handler so that the client immediately exits on the session
disconnect. Additionally this also tidies up the exit after transmission
retries.
src/coap_openssl.c:
Give the function that abstracts the Subject Alternative Name (SAN),
or the CN= if SAN is not available, a better descriptive name to prevent
possible confusion.