diff --git a/include/coap3/coap_proxy.h b/include/coap3/coap_proxy.h index 08143e3d..6a87ac86 100644 --- a/include/coap3/coap_proxy.h +++ b/include/coap3/coap_proxy.h @@ -29,25 +29,45 @@ extern "C" { */ /** - * coap_proxy_type_t Proxy definitions. + * coap_proxy_t Proxy definitions. + * + * 0x00000007 Old 4.3.5 mappings for backward compatability. + * 0x00000038 New type mappings. + * 0xffffffc0 Bitwise optional actions. * * Three types of proxy. * reverse Traffic forward to internal set of servers. * forward-static Traffic forwarded to defined set of servers. * forward-dynamic Traffic forwarded to host defined by * Proxy-Uri / Proxy-Scheme options. - * Operations for each proxy type. + * Additional options for each proxy type. * strip Remove Proxy-Uri and/or Proxy-Scheme options. * mcast Support forward-dynamic traffic to multicast addresses. */ typedef enum { - /* Missing initial 'hole' is for the old style proxy mappings */ + /* Old entries, now updated for flexibility */ + COAP_PROXY_REVERSE, /**< Old - do not use - Act as a reverse proxy */ + COAP_PROXY_REVERSE_STRIP, /**< Old - do not use - Act as a reverse proxy, + strip out proxy options */ + COAP_PROXY_FORWARD, /**< Old - do not use - Act as a forward-static proxy */ + COAP_PROXY_FORWARD_STRIP, /**< Old - do not use - Act as a forward-static proxy, + strip out proxy options */ + COAP_PROXY_DIRECT, /**< Old - do not use - Act as a forward-dynamic proxy */ + COAP_PROXY_DIRECT_STRIP, /**< Old - do not use - Act as a forward-dynamic proxy, + strip out proxy options */ + COAP_PROXY_FORWARD_DYNAMIC = COAP_PROXY_DIRECT, + /**< Old - do not use - Act as a forward-dynamic proxy */ + COAP_PROXY_FORWARD_DYNAMIC_STRIP = COAP_PROXY_DIRECT_STRIP, + /**< Old - do not use - Act as a forward-dynamic proxy, strip out proxy options */ + + + /* New style Proxy types */ COAP_PROXY_REV = (1 << 3), /**< reverse proxy. */ COAP_PROXY_FWD_STATIC = (2 << 3), /**< forward-static proxy. */ COAP_PROXY_FWD_DYNAMIC = (3 << 3), /**< forward-dynamic proxy. */ - /* Start of bit mask mapping */ + /* Start of additional optional bit mask mapping */ COAP_PROXY_BIT_STRIP = (1 << 6), /**< * If COAP_PROXY_BIT_STRIP set, then remove any Proxy-Uri or Proxy-Scheme, @@ -59,31 +79,10 @@ typedef enum { * else only unicast. * [ Ignored if not COAP_PROXY_FWD_DYNAMIC ] */ -} coap_proxy_type_t; +} coap_proxy_t; -#define COAP_PROXY_OLD_MASK 0x07 /**< Space used in coap_proxy_type_t for old types */ -#define COAP_PROXY_NEW_MASK 0x38 /**< Space used in coap_proxy_type_t for new types */ - -/** - * Old Mappings (4.3.5) that map into the first 3 bits of coap_proxy_type_t - */ -typedef enum { - COAP_PROXY_REVERSE, /**< Act as a reverse proxy */ - COAP_PROXY_REVERSE_STRIP, /**< Act as a reverse proxy, - strip out proxy options */ - COAP_PROXY_FORWARD, /**< Act as a forward-static proxy */ - COAP_PROXY_FORWARD_STRIP, /**< Act as a forward-static proxy, - strip out proxy options */ - COAP_PROXY_DIRECT, /**< Act as a forward-dynamic proxy */ - COAP_PROXY_DIRECT_STRIP, /**< Act as a forward-dynamic proxy, - strip out proxy options */ - COAP_PROXY_FORWARD_DYNAMIC = COAP_PROXY_DIRECT, - /**< Act as a forward-dynamic proxy */ - COAP_PROXY_FORWARD_DYNAMIC_STRIP = COAP_PROXY_DIRECT_STRIP, - /**< Act as a forward-dynamic proxy, strip out proxy options */ -} coap_proxy_old_t; - -typedef coap_proxy_old_t coap_proxy_t; +#define COAP_PROXY_OLD_MASK 0x07 /**< Space used in coap_proxy_t for old types */ +#define COAP_PROXY_NEW_MASK 0x38 /**< Space used in coap_proxy_t for new types */ typedef struct coap_proxy_server_t { coap_uri_t uri; /**< host and port define the server, scheme method */ @@ -96,7 +95,8 @@ typedef struct coap_proxy_server_list_t { coap_proxy_server_t *entry; /**< Set of servers to connect to */ size_t entry_count; /**< The number of servers in entry list */ size_t next_entry; /**< Next server to use (% entry_count) */ - coap_proxy_type_t type; /**< The proxy type */ + coap_proxy_t type; /**< The proxy type and option controlling bits + (if old type used, will get mapped into new + bits */ int track_client_session; /**< If 1, track individual connections to upstream server, else 0 for all clients to be multiplexed over the same upstream session */ diff --git a/man/coap_proxy.txt.in b/man/coap_proxy.txt.in index ebcd03b6..62f2a597 100644 --- a/man/coap_proxy.txt.in +++ b/man/coap_proxy.txt.in @@ -131,10 +131,10 @@ FUNCTIONS [source, c] ---- /* - * coap_proxy_type_t Proxy definitions. - * 0x0007 Old 4.3.5 mappings for backward compatability. - * 0x0038 New type mappings. - * 0xffc0 Bitwise actions. + * coap_proxy_t Proxy definitions. + * 0x00000007 Old 4.3.5 mappings for backward compatability. + * 0x00000038 New type mappings. + * 0xffffffc0 Bitwise optional actions. * * Three types of proxy. * reverse Traffic forward to internal set of servers. @@ -147,12 +147,14 @@ FUNCTIONS */ typedef enum { - /* Missing initial 'hole' is for the old style proxy mappings */ - COAP_PROXY_REV = (1 << 3), /**< reverse proxy. */ - COAP_PROXY_FWD_STATIC = (2 << 3), /**< forward-static proxy. */ - COAP_PROXY_FWD_DYNAMIC = (3 << 3), /**< forward-dynamic proxy. */ + /* Reserved space for Old style Proxy types */ - /* Start of bit mask mapping */ + /* New style Proxy types */ + COAP_PROXY_REV = (1 << 3), /* reverse proxy. */ + COAP_PROXY_FWD_STATIC = (2 << 3), /* forward-static proxy. */ + COAP_PROXY_FWD_DYNAMIC = (3 << 3), /* forward-dynamic proxy. */ + + /* Start of additional optional bit mask mapping */ COAP_PROXY_BIT_STRIP = (1 << 6), /**< * If COAP_PROXY_BIT_STRIP set, then remove any Proxy-Uri or Proxy-Scheme, @@ -164,7 +166,7 @@ typedef enum { * else only unicast. * [ Ignored if not COAP_PROXY_FWD_DYNAMIC ] */ -} coap_proxy_type_t; +} coap_proxy_t; typedef struct coap_proxy_server_t { coap_uri_t uri; /* host and port define the server, scheme method */ @@ -177,7 +179,8 @@ typedef struct coap_proxy_server_list_t { coap_proxy_server_t *entry; /* Set of servers to connect to */ size_t entry_count; /* The number of servers in entry list */ size_t next_entry; /* Next server to use (% entry_count) */ - coap_proxy_type_t type; /* The proxy type - COAP_PROXY_* definitions */ + coap_proxy_t type; /* The proxy type and option controlling bits + (if old type used, will get mapped into new + bits */ int track_client_session; /* If 1, track individual connections to upstream server, else 0 for all clients to be multiplexed over the same upstream session */ diff --git a/src/coap_proxy.c b/src/coap_proxy.c index 3359f80c..5e0e928e 100644 --- a/src/coap_proxy.c +++ b/src/coap_proxy.c @@ -317,11 +317,11 @@ coap_verify_proxy_scheme_supported(coap_uri_scheme_t scheme) { return 1; } -static coap_proxy_type_t -coap_proxy_map_type(coap_proxy_type_t proxy_type) { +static coap_proxy_t +coap_proxy_map_type(coap_proxy_t proxy_type) { if ((proxy_type & COAP_PROXY_NEW_MASK) == 0) { /* Old version - update to bitwise version */ - switch ((coap_proxy_old_t)proxy_type) { + switch ((int)proxy_type) { case COAP_PROXY_REVERSE: proxy_type = COAP_PROXY_REV; break; @@ -363,7 +363,7 @@ coap_proxy_get_session(coap_session_t *session, const coap_pdu_t *request, coap_opt_iterator_t opt_iter; coap_opt_t *proxy_scheme; coap_opt_t *proxy_uri; - coap_proxy_type_t proxy_type; + coap_proxy_t proxy_type; *proxy_entry_created = 0; @@ -593,7 +593,7 @@ coap_proxy_get_ongoing_session(coap_session_t *session, memcpy(&dst, &info_list->addr, sizeof(dst)); coap_free_address_info(info_list); if (coap_is_mcast(&dst)) { - coap_proxy_type_t proxy_type = coap_proxy_map_type(server_list->type); + coap_proxy_t proxy_type = coap_proxy_map_type(server_list->type); if ((proxy_type & COAP_PROXY_NEW_MASK) == COAP_PROXY_FWD_DYNAMIC && (proxy_type & COAP_PROXY_BIT_MCAST) == 0) { @@ -917,7 +917,7 @@ coap_proxy_forward_request_lkd(coap_session_t *session, COAP_OPTION_OBSERVE, &opt_iter); coap_proxy_cache_t *proxy_cache = NULL; - coap_proxy_type_t proxy_type; + coap_proxy_t proxy_type; /* Set up ongoing session (if not already done) */ proxy_entry = coap_proxy_get_ongoing_session(session, request, response,