Commit Graph
2086 Commits
Author SHA1 Message Date
Jon Shallow a34228c80f multicast: Add in IPv4 and update IPv6 multicast support
include/coap2/net.h:
src/net.c:

Update code using #587 as a base to fix potential issues.

Fixes CID 1502429

CMakeLists.txt:
cmake_coap_config.h.in:

Test for <net/if.h>

examples/coap-rd.c:
examples/coap-server.c:
man/coap-rd.txt.in:
man/coap-server.txt.in:

Add in -G option to support specifying interface to use for multicasting.
Otherwise, the interface allocated by the O/S is used depending on the
address (if any) bound to.

man/Makefile.am:
man/coap_context.txt.in:

Document the coap_join_mcast_group_intf() function.

src/coap_debug.c:

Make sure that coap_print_addr() returns a NULL terminated buffer.
2021-03-17 17:43:14 +00:00
Szabolcs Szekelyi 42b2f03470 Allow network interface name to be specified when joining multicast group
This change renames `coap_join_mcast_group` to `coap_join_mcast_group_intf`
and adds an extra `const char *ifname` parameter to specify the interface
name.

A `coap_join_mcast_group` macro is defined to maintain backwards API
compatibility.

`coap_is_mcast` has been modified to recognize IPv6-mapped IPv4 multicast
addresses. Without this `coap_network_send` treats these addresses as
unicast which makes `semdmsg` fail with EINVAL.

Examples have been updated to use the new call.
2021-03-17 17:25:31 +00:00
obgm 1d300a6275 Merge pull request #615 from mrdeep1/block2_fix
Block2: Fix ordering issue when calling coap_add_data_large_response()
2021-03-17 17:48:41 +01:00
obgm d3cb5f4990 Merge pull request #618 from mrdeep1/nit_fixes
General: Fix minor issues
2021-03-17 17:41:13 +01:00
obgm a713c4029b Merge pull request #614 from mrdeep1/coverity_2
Coverity: Fix scan issues
2021-03-17 17:39:52 +01:00
Jon Shallow 74342abe4d Coverity: Fix scan issues
Fixes

CID 1502435:
CID 1502432:
CID 1502423:

False Positives

CID 1502434:  Cant see why code is not reached
CID 1502433:  Could make blk_size uint8_t:3 I guess.
CID 1502430:  Dont know why it is complaining
CID 1502427:
CID 1502426:  Code looks fine to me - context->session could be set.
CID 1502424:

Fixed by other PRs

CID 1502422: #610
CID 1502431: #610
CID 1502428: #610
CID 1502429: #587 with my additional fixes
2021-03-17 11:17:18 +00:00
Jon Shallow 7b8bd139d0 General: Fix minor issues
src/coap_tinydtls.c:

Replace UNUSED with COAP_UNUSED that got missed from a merge.

man/examples-code-check.c:
src/pdu.c:
tests/oss-fuzz/pdu_parse_target.c:

Fix trailing white space.

win32/libcoap.vcxproj:
win32/testdriver/testdriver.vcxproj:

Correct include/coap2 paths.
2021-03-15 16:01:21 +00:00
Jon Shallow 48a680359d Block2: Fix ordering issue when calling coap_add_data_large_response()
If the response code was set after calling coap_add_data_large_response(),
the continuing blocks were sent with code 0.00.

Now check following call to response handler that the correct code is held
within the lg_xmit information.
2021-03-10 13:12:45 +00:00
obgm ae752e9e7a Merge pull request #612 from mrdeep1/coap_unused
COAP_UNUSED: Remove UNUSED and UNUSED_PARAM and use COAP_UNUSED instead
2021-03-08 18:43:45 +01:00
obgm 301f6e10c0 Merge pull request #606 from mrdeep1/refactor_headers
include: Move header files into libcoap namespace
2021-03-08 18:39:01 +01:00
obgm 6965d404e2 Merge pull request #610 from mrdeep1/large_block_fix
RFC7959: Handle both Block1 and Block2 for same request/response
2021-03-08 18:34:17 +01:00
Jon Shallow 0c031d7904 include: Move header files into libcoap namespace
I.E. '#include "mem.h"' becomes '#include "coap2/mem.h"'

This prevents header name clashes.

Replacement for #487
2021-03-08 16:45:02 +00:00
Jon Shallow 4a264b2b4c COAP_UNUSED: Remove UNUSED and UNUSED_PARAM and use COAP_UNUSED instead
Remove the UNUSED and UNUSED_PARAM definitions and use a single definition
of COAP_UNUSED as defined in libcoap.h

Replace all UNUSED / UNUSED_PARAM usages with COAP_UNUSED.
2021-03-05 11:49:34 +00:00
Jon Shallow e2c8df147b RFC7959: Handle both Block1 and Block2 for same request/response
Correctly track the tokens so that the token that application sees in the
response is the same token as used in the initial request.

Update coap-server so that response data can be sent back to echo the data
that was in the request.

Fixes
CID 1502431
CID 1502428
CID 1502422
2021-03-04 15:31:20 +00:00
obgm 4efb04d4d4 Merge pull request #609 from mrdeep1/vs_sizing
variables: Remove size changing warnings when using Visual Studio
2021-03-04 09:01:52 +01:00
Jon Shallow 640bb4e667 variables: Remove size changing warnings when using Visual Studio
Change some of the types of variables, and cast change sizes where known to
be safe.

There still are some C4116 warning and a couple of C4090 warning which are OK,
so disabled by a #pragma.
2021-03-03 12:23:25 +00:00
obgm 0044c61fab Merge pull request #601 from mrdeep1/verify_depth
cert_chain_verify_depth: Handle value of 0
2021-03-03 10:26:23 +01:00
obgm b1ababec35 Merge pull request #607 from mrdeep1/ubuntu_20_4
Ubuntu 20.4: Fix builds as Ubuntu 20.4 will be used by github workflows
2021-03-01 18:26:16 +01:00
Olaf Bergmann f930b0ad5b pdu.c: Fix length check in write_{prefix,char}
Fix length check in two helper functions that have been introduced in
commit 757ca19c.

Fixes OSS-Fuzz issue 31479 [1]

[1] https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31479
2021-03-01 18:18:09 +01:00
Olaf Bergmann 25db7412c5 Revert "pdu.c: Fix length check in write_{prefix,char}"
This reverts commit 34b8484a0c.
2021-03-01 18:15:44 +01:00
Olaf Bergmann 34b8484a0c pdu.c: Fix length check in write_{prefix,char}
Fix length check in two helper functions that have been introduced in
commit 757ca19c.

Fixes OSS-Fuzz issue 31479 [1]

[1] https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31479
2021-03-01 18:07:37 +01:00
Olaf Bergmann dc888cb6c2 ut{hash,list}.h: Updated to uthash version 2.3.0 2021-03-01 18:07:37 +01:00
Jon Shallow c8ab318e48 Ubuntu 20.4: Fix builds as Ubuntu 20.4 will be used by github workflows
.github/workflows/main.yml:

Build all the cmake TLS variants.

CMakeLists.txt:

Add in missing file.

examples/tiny.c:
include/coap2/encode.h:

Move COAP_PSEUDOFP_ENCODE_8_4 functions from encode.h to tiny.c.
Fix COAP_PSEUDOFP_ENCODE_8_4_DOWN 'ls' ordering complaint.

man/examples-code-check.c:

Fix compile warning, allow 'Unused but set variables' in examples and set
-Werror when compling the examples.

examples/lwip/Makefile:

Remove  compilation option -fpack-struct
2021-03-01 15:47:55 +00:00
obgm 236005847f Merge pull request #605 from mrdeep1/ack_response_fix
net.c: Fix side effect from merging 2 PRs
2021-03-01 16:17:19 +01:00
Jon Shallow 7c7b15f6f0 net.c: Fix side effect from merging 2 PRs
Merging #552 and #554 into develop caused Observe CON 2.05 initial block
response not to get an ACK from the client and so the Observe response kept
getting re-transmitted and caused other CON traffic to get queued up.

Troubleshooting highlighted an issue when a PUT/POST was updating the contents
of a resource and an Observe was active sending many payloads in a body.

src/net.c:

Make sure that an ACK is sent (if appropriate) when working with a block based
response.

examples/coap-server.c:

Give dynamic data associated with a resource a reference count, and only free
off the data when the reference count has dropped to 0.
2021-03-01 13:17:21 +00:00
obgm f5def1aca2 Merge pull request #603 from mrdeep1/more_rigorous_examples
examples-code-check.c: Add in function checking as well
2021-02-26 18:14:07 +01:00
obgm a7adacead4 Merge pull request #506 from mrdeep1/rename_client
coap-client: Rename client.c to coap-client.c
2021-02-26 15:26:07 +01:00
Jon Shallow a31dcba587 coap-client: Rename client.c to coap-client.c
Keep the examples source names and executables in the same form
for consistency.
2021-02-26 14:21:12 +00:00
obgm 8770152571 Merge pull request #552 from mrdeep1/ack_response
net.c: Delay sending ACK until after response_handler() is called
2021-02-26 15:15:20 +01:00
obgm 25eda91e2f Merge pull request #596 from mrdeep1/no_respond
net.c: Stop reliable sessions returning ACK 0.00
2021-02-26 13:31:20 +01:00
Jon Shallow d89c0140df net.c: Stop reliable sessions returning ACK 0.00
The ACK 0.00 is being returned by the server for reliable conections and the
client is then reporting that CON 0.00 is invalid (CON, NON, ACK and RST are
all resported as CON in a received reliable PDU).

coap-client coap+tcp://127.0.0.1/async?1 -v9

demonstrates the issue.

src/net.c:

Update no_response() to return RESPONSE_DROP for both reliable and
non-confirmable if the application handler returns with the response code set
to 0.00 in the PDU. This then generally simplifies the code around when
calling no_response().

Check for valid multicast responses.

If the response is confirmable and piggybacked and being dropped, convert the
response to an empty ACK so the client does not continue to retry sending the
request.
2021-02-26 11:36:26 +00:00
obgm 1652108d78 Merge pull request #604 from mrdeep1/write_char_inlining
pdu.c: Remove inline expansion warnings for write_char()
2021-02-26 11:40:01 +01:00
Jon Shallow 9b9f6c85c6 pdu.c: Remove inline expansion warnings for write_char()
Just make write_char() and write_prefix() static functions.
2021-02-26 10:22:48 +00:00
obgm 4bbdcc87b2 Merge pull request #584 from mrdeep1/option_strict_aliasing
coap_opt_filter_t: Make it a proper structure
2021-02-26 11:12:26 +01:00
Jon Shallow e2e783033c coap_opt_filter_t: Make it a proper structure
Update coap_opt_filter_t to be a structure rather than a 16bit array that is
aliased with the real structure format.

Update code to use pointers where appropriate.
2021-02-26 09:24:34 +00:00
Jon Shallow b2233810c2 examples-code-check.c: Add in function checking as well
Build dummy functions based on the SYNOPSIS definitions for further checking.
Note: COAP_STATIC_INLINE functions have to be excepted.
2021-02-26 08:59:42 +00:00
obgm 486f97f8d4 Merge pull request #599 from mrdeep1/option_encoding
pdu.c: Output debug information for broken CoAP Options
2021-02-26 09:37:15 +01:00
obgm 85c6e0038c Merge pull request #602 from mrdeep1/fix_rebase
resource.h: Remove function definitions that are duplicated
2021-02-26 09:16:43 +01:00
Jon Shallow 757ca19cd0 pdu.c: Output debug information for broken CoAP Options
Refactor coap_pdu_parse_opt() to additionally output the block options in
hex for debugging if there is an error.

Fix the two tests that are now reported with the updated code.
[Other PDU test are reporting information, but only at LOG_DEBUG which is
not output]
2021-02-26 08:13:43 +00:00
obgm 9f1d96a829 Merge pull request #600 from mrdeep1/github_workflows
workflow: Add in distribution and CMake checks
2021-02-26 08:46:53 +01:00
Jon Shallow 669400665d resource.h: Remove function definitions that are duplicated
Result of a rebase confusion.

include/coap2/resource.h:

Remove duplicates that are also in coap_subscriber_internal.h.

libcoap-2.map:
libcoap-2.sym:

Remove the now internal only functions.
2021-02-25 16:35:59 +00:00
Jon Shallow 6225fc7542 cert_chain_verify_depth: Handle value of 0
If cert_chain_verify_depth is 0 and cert_chain_validation is set in
coap_dtls_pki_t, then a Cert + its signing CA should be valid (no intermediary
CAs).

src/coap_gnutls.c:
src/coap_mbedtls.c:
src/coap_openssl.c:

Correct set and check cert_chain_verify_depth.

src/coap_openssl.c:

Fix building on openssl-1.1.0
2021-02-25 10:28:58 +00:00
Jon Shallow dc6c5e6b00 workflow: Add in distribution and CMake checks
.github/workflows/main.yml:

Do a 'make check' for matrix builds.
Move documentation into separate job to reduce matrix build times
Add in CMake job.
Add in distribution job.
Add in tinydtls job.
Add in contiki/lwip job.

scripts/github_dist.sh:

Do the distribution checks using a script.

examples/etsi_iot_01.c:
examples/tiny.c:

Fix include coap.h directory in old examples.

README.md:

Update status badges to get only the branch actions and remove CMake
status badge.
2021-02-24 18:15:25 +00:00
obgm cea89718e9 Merge pull request #582 from mrdeep1/obfuscate_resource
coap_resource_t: Obfuscate coap_resource_t from applications.
2021-02-24 17:53:29 +01:00
Jon Shallow da18643702 coap_resource_t: Obfuscate coap_resource_t from applications.
Create a new include/coap2/coap_resource_internal.h to hold all the information
not available to applications.

Makefile.am:

Include coap_resource_internal.h in EXTRA_DIST.
Remove functions no longer visible from CTAGS_IGNORE.

examples/coap-rd.c:
examples/contiki/server.c:
examples/etsi_iot_01.c:
tests/test_wellknown.c

Replace direct access to coap_resource_t variables with functions as
appropriate.

include/coap2/resource.h:
include/coap2/subscribe.h:
include/coap2/coap_resource_internal.h: (New)
include/coap2/coap_subscribe_internal.h:

Move coap_resource_t, coap_addr_t, non API #defines and non API functions from
resource.h into coap_resource_internal.h, coap_subscribe_internal.h and
subscribe.h.

Replace inline functions accessing coap_resource_t with actual function
definitions.

Add new functions coap_resource_release_userdata_handler() and
coap_attr_get_value().

include/coap2/block.h:

Use coap_resource_t typedef.

include/coap2/coap_forward_decls.h:

Include coap_resource_t and coap_addr_t typedefs.  Also typedef coap_context_t
to get rid of #include circular requirements.

include/coap2/coap_internal.h:
win32/libcoap.vcxproj:
win32/libcoap.vcxproj.filters:

Include coap_resource_internal.h.

include/coap2/net.h:

Remove "typedef struct coap_context_t" and do this in coap_forward_decls.h.

src/resource.c:

Update with the replaced inline functions. Add in the new functions
coap_resource_release_userdata_handler() and coap_attr_get_value().

libcoap-2.map:
libcoap-2.sym:

Update with new function visibility.

man/Makefile.am:
man/coap_attribute.txt.in:
man/coap_observe.txt.in:
man/coap_resource.txt.in:

Update with the new coap_resource_t and coap_attr_t usage.
2021-02-24 16:34:27 +00:00
Jon Shallow 14e75a54b8 net.c: Delay sending ACK until after response_handler() is called
In handle_response() the ACK is sent before calling ctx->response_handler() so
if the response_handler() wants to send RST the server ignores it as the ACK
has already been received.

By updating coap_response_handler_t to return a value, this can be used to
send the ACK (return of COAP_RESPONSE_OK) or a RST (return of COAP_RESPONSE_FAIL)
after ctx->response_handler() is called.

include/coap2/net.h:
man/coap_handler.txt.in:

Create a new enum coap_response_t for use as the return value for
coap_response_handler_t.
Update coap_response_handler_t and associated documentation.

src/net.c:

Send CoAP ACK or RST depending on return value of ctx->response_handler().

examples/client.c:

Update message_handler() to use the new coap_response_handler_t return values
(coap_response_t).
2021-02-24 09:37:32 +00:00
obgm b0e47d71d0 Merge pull request #580 from mrdeep1/with_observe
Observe: Remove WITHOUT_OBSERVE conditional statements in the library.
2021-02-24 09:52:33 +01:00
obgm 8724c0c372 Merge pull request #578 from mrdeep1/icmp_issue_nack_handler
ICMP reporting: Call nack handler when ICMP unreachable is received
2021-02-24 09:22:57 +01:00
obgm 35dbc32708 Merge pull request #577 from mrdeep1/observer_fix
Observe: Fix coap_free_context() assert when active observe
2021-02-24 09:14:42 +01:00
obgm 7c54bd748f Merge pull request #554 from mrdeep1/add_data_large
RFC7641: Move block handling logic down into libcoap
2021-02-24 09:09:01 +01:00