From c830c15551a95ddadc54c4b2ab17cecefe53610c Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Tue, 28 May 2024 16:46:03 +0100 Subject: [PATCH] proxy: Handle Uri-Host correctly when using Proxy-Scheme Updated documentation at the same time. --- examples/coap-client.c | 4 +++- examples/coap-server.c | 12 +++++++++++- man/coap-client.txt.in | 9 ++++++++- man/coap-server.txt.in | 18 +++++++++++++++++- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/examples/coap-client.c b/examples/coap-client.c index ddff7d79..6f3bfdd1 100644 --- a/examples/coap-client.c +++ b/examples/coap-client.c @@ -567,7 +567,8 @@ usage(const char *program, const char *version) { "\t \t\tScheme, address and optional port to define how to\n" "\t \t\tconnect to a CoAP proxy (automatically adds Proxy-Uri\n" "\t \t\toption to request) to forward the request to.\n" - "\t \t\tScheme is one of coap, coaps, coap+tcp and coaps+tcp\n" + "\t \t\tScheme is one of coap, coaps, coap+tcp, coaps+tcp,\n" + "\t \t\tcoap+ws, and coaps+ws\n" "\t-T token\tDefine the initial starting token (up to 24 characters)\n" "\t-U \t\tNever include Uri-Host or Uri-Port options\n" "\t-V num \t\tVerbosity level (default 3, maximum is 7) for (D)TLS\n" @@ -641,6 +642,7 @@ usage(const char *program, const char *version) { "\tcoap-client -m get coaps://%%2Funix%%2Fdomain%%2Fpath%%2Fdtls/.well-known/core\n" "\tcoap-client -m get coaps+tcp://%%2Funix%%2Fdomain%%2Fpath%%2Ftls/.well-known/core\n" "\tcoap-client -m get -T cafe coap://[::1]/time\n" + "\tcoap-client -m get -T cafe -P coap://upstream-proxy coap://[::1]/time\n" "\techo -n 1000 | coap-client -m put -T cafe coap://[::1]/time -f -\n" ); } diff --git a/examples/coap-server.c b/examples/coap-server.c index b2acc65f..1da093a5 100644 --- a/examples/coap-server.c +++ b/examples/coap-server.c @@ -674,6 +674,14 @@ get_uri_proxy_scheme_info(const coap_pdu_t *request, strncasecmp(opt_val, "coap", 4) == 0) { uri->scheme = COAP_URI_SCHEME_COAP; uri->port = COAP_DEFAULT_PORT; + } else if (opt_len == 7 && + strncasecmp(opt_val, "coap+ws", 7) == 0) { + uri->scheme = COAP_URI_SCHEME_COAP_WS; + uri->port = 80; + } else if (opt_len == 8 && + strncasecmp(opt_val, "coaps+ws", 8) == 0) { + uri->scheme = COAP_URI_SCHEME_COAPS_WS; + uri->port = 443; } else { coap_log_warn("Unsupported Proxy Scheme '%*.*s'\n", opt_len, opt_len, opt_val); @@ -1123,6 +1131,7 @@ hnd_proxy_uri(coap_resource_t *resource COAP_UNUSED, case COAP_OPTION_PROXY_SCHEME: case COAP_OPTION_URI_PATH: case COAP_OPTION_URI_PORT: + case COAP_OPTION_URI_HOST: case COAP_OPTION_URI_QUERY: if (proxy_scheme_option) { /* Need to add back in */ @@ -2210,7 +2219,8 @@ usage(const char *program, const char *version) { "\t \t\tfinal endpoint. If scheme://address[:port] is not\n" "\t \t\tdefined before the leading , (comma) of the first name,\n" "\t \t\tthen the ongoing connection will be a direct connection.\n" - "\t \t\tScheme is one of coap, coaps, coap+tcp and coaps+tcp\n" + "\t \t\tScheme is one of coap, coaps, coap+tcp, coaps+tcp,\n" + "\t \t\tcoap+ws, and coaps+ws. http(s) is not currently supported\n" "\t-T max_token_length\tSet the maximum token length (8-65804)\n" "\t-U type\t\tTreat address defined by -A as a Unix socket address.\n" "\t \t\ttype is 'coap', 'coaps', 'coap+tcp' or 'coaps+tcp'\n" diff --git a/man/coap-client.txt.in b/man/coap-client.txt.in index bb889128..a3efdb64 100644 --- a/man/coap-client.txt.in +++ b/man/coap-client.txt.in @@ -179,7 +179,7 @@ OPTIONS - General *-P* scheme://addr[:port]:: Scheme, address and optional port to define how to connect to a CoAP proxy (automatically adds Proxy-Uri option to request) to forward the request to. - Scheme is one of coap, coaps, coap+tcp and coaps+tcp. + Scheme is one of coap, coaps, coap+tcp, coaps+tcp, coap+ws, and coaps+ws. *-T* token:: Define the initial starting 'token' for the request (up to 24 characters). @@ -279,6 +279,13 @@ coap-client -m get coap://[::1]/ Query the resource '/' on localhost using the 'GET' method to get back the summary information. +* Example +---- +coap-client -m get -P coap://upstream-proxy coap://[::1]/ +---- +Query the resource '/' on 'upstream-proxy' using the 'GET' method to get back +the summary information. + * Example ---- coap-client -m get coap://%2Fsome%2Funix%2Fdomain%2Fpath/time diff --git a/man/coap-server.txt.in b/man/coap-server.txt.in index a7911e9f..82c9d0db 100644 --- a/man/coap-server.txt.in +++ b/man/coap-server.txt.in @@ -138,7 +138,8 @@ OPTIONS - General then this server is considered to be the final endpoint. If scheme://address[:port] is not defined before the leading , (comma) of the first name, then the ongoing connection will be a direct connection. - Scheme is one of coap, coaps, coap+tcp and coaps+tcp. + Scheme is one of coap, coaps, coap+tcp, coaps+tcp, coap+ws, and coaps+ws. + http and https not currently supported. *-T* max_token_size:: Set the maximum token length (8-65804). @@ -293,6 +294,21 @@ coap-server -A 2001:db8:81a8:0:6ef0:dead:feed:beef -g FF02::FD Set listening address to '2001:db8:81a8:0:6ef0:dead:feed:beef' and join the All CoAP Nodes multicast group 'FF02::FD'. +* Example +---- +coap-server -P, -A ::1 +---- +Let the server listen on localhost (port '5683') for UDP/TCP, as well as +accept any CoAP proxy requests and directly respond to them. + +* Example +---- +coap-server -P coap://upstream-proxy, -A ::1 +---- +Let the server listen on localhost (port '5683') for UDP/TCP, and then +open an upstream coap session to 'upstream-proxy' for proxying onwards +the CoAP client's request. + FILES ------ There are no configuration files.