Commit Graph
1193 Commits
Author SHA1 Message Date
Jon Shallow d88b0bb7fe Makefile.am: Drop building coap hash functions
As "coap_key_t key" is no longer used as the key for hashing resources onto
the hashlist which gave the potential for coap hashes clashing for the
resource Uri, "str uri" being used instead, so disable the building of the
coap_hash functions.

In addition, the .sym and .map file information now has duplicate
entries removed.
2018-03-14 09:32:58 +00:00
Jon Shallow be0c6616c6 libcoap-1.map & libcoap-1.sym: Add in coap_resource_unknown_init
Expose the new functions
coap_resource_unknown_init()
coap_get_uri_path()
coap_get_resource_from_uri_path()

Drop the functions as old hashed key is no longer supported
coap_get_resource_from_key()
coap_hash_*()
2018-03-14 09:32:58 +00:00
Jon Shallow e907596473 net.c: Update handle_request() to support unknown resource handler
Update handle_request() to call context->unknown_resource handler (if defined)
to support "RFC7252: 5.8.3.  PUT" requirements.

Allow only handlers defined for unknown_resource

Update handle_request() to return 2.02 for an unknown resource (and
context->unknown_resource is not defined) for a DELETE request
"RFC7252: 5.8.4.  DELETE"

Update code to use resource's uri_path not key as the item to hash for lookups

Make use of the new function coap_string_equal() when checking for
COAP_DEFAULT_URI_WELLKNOWN resource request.

Remove now obsolete hashed key code for is_wkc().
2018-03-14 09:32:45 +00:00
Jon Shallow 5aa31d010c resource.h: Add coap_add_resource_unknown() and hash resource on uri_path
Need to support
"RFC7252: 5.8.3.  PUT
 If no resource exists, then the server MAY create a new resource with that
 URI, resulting in a 2.01 (Created) Response Code."

Add in the function definition for the coap_add_resource_unknown().
Add in 'is_unknown' flag into coap_resource_t.

Make the resource uri_path be the hash lookup key, not the old hashed key, to
stop hash lookup clashes.

*API Change* Update coap_delete_resource() to not use the old hashed key.
Remove coap_get_resource_from_key() function and replace it with
coap_get_resource_from_uri_path().

Make the coap_resource_set_mode() more robust against bad parameters.

Remove #ifdef COAP_RESOURCES_NOHASH logic as no longer required
2018-03-13 14:49:22 +00:00
Jon Shallow cfe82719d3 net.h: Add in unknown_resource to coap_context_t
Needed to handle
"RFC7252: 5.8.3.  PUT
 If no resource exists, then the server MAY create a new resource with that
 URI, resulting in a 2.01 (Created) Response Code."

Needed for support of PUT requests to an unknown resource.

Remove structure coap_mid_cache_t as it is not used and refers to the now
obsolete coap_key_t.
2018-03-10 16:02:56 +00:00
obgm a674334afc Merge pull request #146 from mrdeep1/COAP_SOCKET_CONNECTED_issue
coap_io.c: Set COAP_SOCKET_CONNECTED before connect() for TCP
2018-03-09 17:44:57 +01:00
Jon Shallow f453902425 src/net.c: Support RFC8323 for empty messages and rate limit RSTs
Do not send back a RST is there is receipt of an empty message and using
TCP.

Otherwise, rate limit RST packets to 4 a second when receiving empty
messages
2018-03-09 15:08:14 +00:00
Jon Shallow c4bd74040c coap_session.h: Add in last_tx_rst to coap_session_t for RST ratelimiting 2018-03-09 14:53:32 +00:00
Jon Shallow 45a95c776d examples/coap-client.txt.in: Add in coap+tcp to the documentation 2018-03-09 14:52:14 +00:00
Olaf Bergmann d02ab4d0ab libcoap-1.{sym,map}: updated map files
The function coap_calc_timeout() was missing from the symbol mappings.
2018-03-06 16:56:51 +01:00
Olaf Bergmann 8f9ca22e05 tests: add unit tests for session handling
This change adds an initial set of unit tests for sessions:

* reference counting and release
* timeout calculation
2018-03-06 16:45:28 +01:00
obgm bf43c3af6c Merge pull request #137 from mrdeep1/session-retries
Require support for configuring session recovery parameters
2018-03-06 16:43:51 +01:00
Jon Shallow 7b2a7bca36 libcoap-1.map & libcoap-1.sym: Expose the new functions
Add in the new functions
coap_session_set_max_retransmit()
coap_session_set_ack_timeout()
coap_session_set_ack_random_factor()
coap_session_get_max_transmit()
coap_session_get_ack_timeout()
coap_session_get_ack_random_factor()
2018-03-05 16:12:25 +00:00
Jon Shallow 9c6c72565e net.c: Remove 'cc Rate Control', update code to use session recovery parameters
Remove 'cc Rate Control' which is now in coap_session.h.

Update Q, ACK_TIMEOUT and ACK_RANDOM_FACTOR #defines to include session's
recovery parameters, now in coap_fixed_point_t.

Update calc_timeout() to include session (now called coap_calc_timeout()).

Update coap_retransmit() to use session's max_retransmit.
2018-03-05 16:12:18 +00:00
Jon Shallow fb626df651 coap_session.c: Add in new functions, set the defaults and update calc_timeout
Add in the new functions
coap_session_set_max_retransmit()
coap_session_set_ack_timeout()
coap_session_set_ack_random_factor()
coap_session_get_max_transmit()
coap_session_get_ack_timeout()
coap_session_get_ack_random_factor()

Add in the default values in coap_make_session()

Update coap_calc_timeout() in coap_session_delay_pdu()
2018-03-05 16:12:18 +00:00
Jon Shallow ecf3321c67 net.h: Update and document coap_calc_timeout() function
Include session as one of the parameters to coap_calc_timeout() as it is now
per session, which is renamed from calc_timeout() as it is now a public
function.
2018-03-05 16:12:07 +00:00
Jon Shallow b105a7dea2 coap_session.h: Add definitions/functions to configure session retransmissions
Support is required (RFC7252: 4.8.1.  Changing the Parameters) to support
changing max_retransmit, ack_timeout and ack_random_factor values per
session instead of just using the default values.

Define struct coap_fixed_point_t to handle fixed point parameters

Added functions
coap_session_set_max_retransmit()
coap_session_set_ack_timeout()
coap_session_set_ack_random_factor()
coap_session_get_max_transmit()
coap_session_get_ack_timeout()
coap_session_get_ack_random_factor()

'cc Rate Control' moved from net.c into coap_session.h and updated to use
coap_fixed_point_t values where appropriate.
2018-03-05 12:09:45 +00:00
Jon Shallow 5969ae7633 coap_io.c: Set COAP_SOCKET_CONNECTED if connect does not complete for TCP
If the non-blocking connect() does not immediately complete, when the main i/o
processing loop runs and coap_read is called, coap_read_session() will assert if
COAP_SOCKET_CONNECTED is not set as there will be some TLS level packets to
process.

If WSAEWOULDBLOCK/EINPROGRESS is returned from the connect() set
COAP_SOCKET_CONNECTED in the socket flags.
2018-03-02 10:47:44 +00:00
obgm 3870bfc809 Merge pull request #142 from mrdeep1/coap-write-missing-tls
coap_write can assert if s->tls is not set when determining next to resend packet
2018-03-01 13:13:19 +01:00
Olaf Bergmann 7872a80fb4 network I/O: fixed socket creation for multicast communication
This bugfix allows clients to send datagrams to IP multicast groups.
After introducing the concept of client sessions, datagram sockets
have been connected to their remote peer in coap_socket_connect_udp().
As this operation fails for multicast addresses, sending to multicast
groups was not possible anymore.

coap_socket_connect_udp() now checks whether the given server address
is a multicast address. If this is the case, connect() is not called
and the flag COAP_SOCKET_MULTICAST is set in the coap_socket_t
structure while COAP_SOCKET_CONNECTED is cleared.

The flag COAP_SOCKET_CONNECTED is now set by coap_socket_connect_udp()
and coap_socket_connect_tcp1().

coap_read_session() now allows reading from sockets that have either
the flag COAP_SOCKET_CONNECTED or COAP_SOCKET_MULTICAST set.
2018-02-28 15:44:32 +01:00
obgm b6f6cb274c Merge pull request #141 from mrdeep1/coap-log-syntax
Add in GNU compiler checking of parameter syntax for coap_log() functions
2018-02-26 17:35:10 +01:00
obgm 4885d87f6d Merge pull request #140 from mrdeep1/coap-server-pki-fix
coap-server: Re-order code (move fill_keystore) to support PKI
2018-02-26 17:25:44 +01:00
Olaf Bergmann 9b9b39a3cd Merge branch 'develop' of github.com:obgm/libcoap into develop 2018-02-26 17:18:43 +01:00
obgm fafd4745b7 Merge pull request #136 from mrdeep1/ping-pong-handlers
Ping Pong handlers: Need for applications to see ping requests / pong responses
2018-02-26 17:17:54 +01:00
Olaf Bergmann 46c908af8f coap_session.c: fix session release
coap_session_t uses reference counting hence client sessions must be
released by coap_session_release() instead of directly calling
coap_session_free().
2018-02-20 13:55:25 +01:00
obgm 08f7f5c2ce Merge pull request #131 from mrdeep1/fd-close-leak
coap_io.c: Fix file descriptor leaks when "connections" fail
2018-02-20 13:53:11 +01:00
obgm 63cac59c62 Merge pull request #132 from mrdeep1/coap_session_send-assert
coap_openssl.c: client assert error if DTLS error closed socket
2018-02-20 13:52:56 +01:00
Olaf Bergmann 90d90232c4 .travis.yml: minimize build matrix 2018-02-16 10:43:28 +01:00
Olaf Bergmann 67291e397b tests: revert commit a3da53d to re-enable IPv6 in unit tests 2018-02-15 20:05:01 +01:00
Olaf Bergmann e40c6ea799 .travis.yml: enable IPv6 on travis docker
This workaround has been suggested [1] to fix the recent IPv6 issue
in travis docker containers.

[1] https://github.com/travis-ci/travis-ci/issues/8711
2018-02-15 20:03:40 +01:00
John Carter c7936acf71 coap_io.c: fix apparently uninitialized buffer in syscall param
Valgrind reports Syscall param  sendmsg(msg.msg_control) points to
uninitialised byte(s) due alignment padding in the CMSG macros
leaving uninitialized gaps in struct sent to the sendmsg system call.

This issue was reported including this patch on the libcoap-developers
mailing list [1].

[1] https://sourceforge.net/p/libcoap/mailman/message/36141279/

Signed-off-by: Olaf Bergmann <bergmann@tzi.org>
2018-02-15 19:38:42 +01:00
Olaf Bergmann c46de196e5 .travis.yml: added tinydtls build to POSIX test matrix 2018-02-15 12:14:16 +01:00
obgm 1b97885ec8 Merge pull request #138 from mrdeep1/pki-support
Addition of PKI support
2018-02-15 12:03:50 +01:00
Jon Shallow eb84476fd1 coap_io.c: remove coap_socket_close() added in error to this fix
Reverting out this part of the change.  This should be managed and done at
the application layer.
2018-02-15 09:51:05 +00:00
Jon Shallow 47b46d6907 coap_io.c: Fix file descriptor leaks when "connections" fail
If a TCP connection connection fails, or a an ICMP Unreachable is received
for a UDP packet, then the file descriptor is not closed off.  Eventually
all fails when no more file descriptors are allowed.
2018-02-15 09:51:05 +00:00
Jon Shallow 137789fbc7 coap_openssl.c: Fix dtls typo should be tls in coap_dtls_new_context()
Correct parameter typo to SSL_CTX_set_cipher_list() from original TLS merge
2018-02-14 23:07:08 +00:00
Jon Shallow 675edad34c coap_notls.c, coap_tinydtls.c: Fix stub functions coap_dtls_context_set_pki() 2018-02-14 21:59:21 +00:00
Jon Shallow 0704792698 net.c: Update coap_context_set_pki() parameters
Remove setup_callback parameter
2018-02-14 21:04:47 +00:00
Jon Shallow 2a99d04648 coap_session.c: Update coap_new_client_session_pki() parameters
Remove setup_callback parameter
2018-02-14 21:03:37 +00:00
Jon Shallow 969cdcb457 coap_openssl.c: Update with coap_dtls_pki_t changes and asn1 private key types
Move coap_dtls_security_setup_t into coap_dtls_pki_t

Map COAP_ASN1_PKEY_* into EVP_PKEY_* for call SSL_CTX_use_PrivateKey_ASN1()
2018-02-14 21:00:20 +00:00
Jon Shallow b8b1c18ffd net.h: Update coap_context_set_pki() definition 2018-02-14 20:58:15 +00:00
Jon Shallow f820857315 coap_session.h: Move coap_new_client_session_pki() def from coap_dtls.h
Moving coap_dtls_security_setup_t into coap_dtls_pki_t helped with the previous
into its logical place.
2018-02-14 20:54:21 +00:00
Jon Shallow fa6f292997 coap_dtls.h: Move coap_dtls_security_setup_t into coap_dtls_pki_t
Update functions appropriately.
Move coap_new_client_session_pki() back into coap_session.h (its correct place)
Add in enum coap_asn1_privatekey_type_t
2018-02-14 20:50:43 +00:00
Jon Shallow 047c9fb082 Fix coap_notls.c, coap_tinydtls.c: after update merge from obgm/develop
Conficts created by Pull request #134
2018-02-14 19:24:58 +00:00
Olaf Bergmann 0d2922a45b .travis.yml: enable unit tests for openssl builds
This change sets TESTS=yes for the TLS=openssl build
2018-02-14 17:43:33 +01:00
Olaf Bergmann c74e1da5a9 tests: add unit test boilerplate for (D)TLS
A simple structure for (D)TLS-specific unit tests has been added.
Currently, only general support and the version number as reported
by coap_get_tls_library_version() are checked.
2018-02-14 17:28:37 +01:00
Olaf Bergmann b1943714ad Merge branch 'mrdeep1-tls-supported' into develop
Close PR #134 [1]

[1] https://github.com/obgm/libcoap/pull/134
2018-02-14 17:25:53 +01:00
Olaf Bergmann 16685d7736 Merge branch 'tls-supported' of https://github.com/mrdeep1/libcoap into mrdeep1-tls-supported 2018-02-14 16:21:27 +01:00
Olaf Bergmann a3da53d5e3 tests: use IPv4 in unit tests for robustness
As unit tests with IPv6 addresses keep failing on docker-based
travis CI, this changes reverts to IPv4 usage in following files:

    test_wellknown.c
    test_sendqueue.c
2018-02-14 16:06:52 +01:00
Jon Shallow c4729fa801 libcoap-1.map, libcoap-1.sym: Expose coap_get_tls_library_version() 2018-02-14 09:55:53 +00:00