Skip to content

Commit

Permalink
reverse-proxy: Add in reverse proxy support to coap-server
Browse files Browse the repository at this point in the history
Tidy up the general proxy logic by moving common functionality
into libcoap.

New functions coap_proxy_forward_request(), coap_proxy_forward_response()
and coap_proxy_is_supported() added.

New --enable-proxy-code support added to configure.

New ENABLE_PROXY_CODE support added to CMakeLists.txt.

Support for common shared connection to next hop.

Support for round-robin balancing across multiple next hops.
  • Loading branch information
mrdeep1 committed Aug 7, 2024
1 parent af024f9 commit f8c69b0
Show file tree
Hide file tree
Showing 31 changed files with 1,651 additions and 731 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ option(
ENABLE_SERVER_MODE
"compile with support for server mode code"
ON)
option(
ENABLE_PROXY_CODE
"compile with support for proxy code"
ON)
option(
ENABLE_OSCORE
"compile with support for OSCORE"
Expand Down Expand Up @@ -322,6 +326,13 @@ else()
message(STATUS "compiling without server support")
endif()

if(${ENABLE_PROXY_CODE})
set(COAP_PROXY_SUPPORT "1")
message(STATUS "compiling with proxy support")
else()
message(STATUS "compiling without proxy support")
endif()

if(${ENABLE_OSCORE})
set(COAP_OSCORE_SUPPORT "1")
message(STATUS "compiling with OSCORE support")
Expand Down Expand Up @@ -741,6 +752,7 @@ target_sources(
${CMAKE_CURRENT_LIST_DIR}/src/coap_oscore.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_pdu.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_prng.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_proxy.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_resource.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_session.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_sha1.c
Expand Down Expand Up @@ -780,6 +792,7 @@ target_sources(
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_option.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_pdu.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_prng.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_proxy.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_resource.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_session.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_str.h
Expand Down
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ EXTRA_DIST = \
include/coap$(LIBCOAP_API_VERSION)/coap_oscore_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_pdu_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_prng_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_proxy_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_resource_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_session_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_sha1_internal.h \
Expand Down Expand Up @@ -208,6 +209,7 @@ libcoap_@LIBCOAP_NAME_SUFFIX@_la_SOURCES = \
src/coap_option.c \
src/coap_oscore.c \
src/coap_pdu.c \
src/coap_proxy.c \
src/coap_prng.c \
src/coap_resource.c \
src/coap_session.c \
Expand Down Expand Up @@ -257,6 +259,7 @@ libcoap_include_HEADERS = \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_oscore.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_pdu.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_prng.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_proxy.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_resource.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_session.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_str.h \
Expand Down
3 changes: 3 additions & 0 deletions cmake_coap_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
/* Define to 1 if the library has server support. */
#cmakedefine COAP_SERVER_SUPPORT @COAP_SERVER_SUPPORT@

/* Define to 1 if the library has proxy support. */
#cmakedefine COAP_PROXY_SUPPORT @COAP_PROXY_SUPPORT@

/* Define to 1 if the library is to have observe persistence. */
#cmakedefine COAP_WITH_OBSERVE_PERSIST @COAP_WITH_OBSERVE_PERSIST@

Expand Down
22 changes: 22 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,22 @@ if test "x$enable_server_mode" != "xyes" -a "x$enable_client_mode" != "xyes" ; t
AC_MSG_ERROR([==> One or both of '--enable-server-mode' and '--enable-client-mode' need to be set!])
fi

AC_ARG_ENABLE([proxy-code],
[AS_HELP_STRING([--enable-proxy-code],
[Enable CoAP proxy supporting code [default=yes]])],
[enable_proxy_code="$enableval"],
[enable_proxy_code="yes"])

if test "x$enable_proxy_code" = "xyes"; then
if test "x$enable_server_mode" != "xyes" -o "x$enable_client_mode" != "xyes" ; then
AC_MSG_WARN([==> Both of '--enable-server-mode' and '--enable-client-mode' need to be set for --enable-proxy-code!])
enable_proxy_code="no"
fi
fi
if test "x$enable_proxy_code" = "xyes"; then
AC_DEFINE(COAP_PROXY_SUPPORT, 1, [Define to 1 if libcoap supports proxy code.])
fi

AC_ARG_ENABLE([max-logging-level],
[AS_HELP_STRING([--enable-max-logging-level],
[Only build logging code up to and including the specified logging level [default=8]])],
Expand Down Expand Up @@ -1337,6 +1353,7 @@ man/coap_oscore.txt
man/coap_pdu_access.txt
man/coap_pdu_setup.txt
man/coap_persist.txt
man/coap_proxy.txt
man/coap_recovery.txt
man/coap_resource.txt
man/coap_session.txt
Expand Down Expand Up @@ -1383,6 +1400,11 @@ if test "x$enable_client_mode" = "xyes"; then
else
AC_MSG_RESULT([ build with client support : "no"])
fi
if test "x$enable_client_mode" = "xyes"; then
AC_MSG_RESULT([ build with proxy support : "yes"])
else
AC_MSG_RESULT([ build with proxy support : "no"])
fi
if test "x$build_ipv4" != "xno"; then
AC_MSG_RESULT([ build with IPv4 support : "yes"])
else
Expand Down
Loading

0 comments on commit f8c69b0

Please sign in to comment.