aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/session/application_interface.c
diff options
context:
space:
mode:
authorAdrian Villin <avillin@cisco.com>2025-02-27 15:04:56 +0100
committerFlorin Coras <florin.coras@gmail.com>2025-03-03 19:20:46 +0000
commite1d40bf585ef23e24145bee1cd89ae0ab8bc303d (patch)
tree7a9bbcf1773f4fc5cdb4f3d992f4842ea202df75 /src/vnet/session/application_interface.c
parent9c948e4d2a71269acffa634b3c6b2741d558cee0 (diff)
session: uri parsing improvements
- It is now possible to use "proto://ip4:port/target" or "proto://[ip6]:port/target" format. - Updated http_client and related tests to use the new format Type: improvement Change-Id: Ic6afd8c66eddca2ab1d7afc034e193441c34f8ee Signed-off-by: Adrian Villin <avillin@cisco.com>
Diffstat (limited to 'src/vnet/session/application_interface.c')
-rw-r--r--src/vnet/session/application_interface.c91
1 files changed, 89 insertions, 2 deletions
diff --git a/src/vnet/session/application_interface.c b/src/vnet/session/application_interface.c
index a62f914d43a..e2f9a6883fe 100644
--- a/src/vnet/session/application_interface.c
+++ b/src/vnet/session/application_interface.c
@@ -38,12 +38,12 @@
*
*/
uword
-unformat_vnet_uri (unformat_input_t * input, va_list * args)
+unformat_vnet_uri (unformat_input_t *input, va_list *args)
{
session_endpoint_cfg_t *sep = va_arg (*args, session_endpoint_cfg_t *);
u32 transport_proto = 0, port;
- if (unformat (input, "%U://%U/%d", unformat_transport_proto,
+ if (unformat (input, "%U://%U:%d", unformat_transport_proto,
&transport_proto, unformat_ip4_address, &sep->ip.ip4, &port))
{
sep->transport_proto = transport_proto;
@@ -52,6 +52,54 @@ unformat_vnet_uri (unformat_input_t * input, va_list * args)
return 1;
}
else if (unformat (input, "%U://%U/%d", unformat_transport_proto,
+ &transport_proto, unformat_ip4_address, &sep->ip.ip4,
+ &port))
+ {
+ sep->transport_proto = transport_proto;
+ sep->port = clib_host_to_net_u16 (port);
+ sep->is_ip4 = 1;
+ return 1;
+ }
+ else if (unformat (input, "%U://%U", unformat_transport_proto,
+ &transport_proto, unformat_ip4_address, &sep->ip.ip4))
+ {
+ sep->transport_proto = transport_proto;
+ if (sep->transport_proto == TRANSPORT_PROTO_HTTP)
+ port = 80;
+ else if (sep->transport_proto == TRANSPORT_PROTO_TLS)
+ port = 443;
+ else
+ return 0;
+
+ sep->port = clib_host_to_net_u16 (port);
+ sep->is_ip4 = 1;
+ return 1;
+ }
+ else if (unformat (input, "%U://[%U]:%d", unformat_transport_proto,
+ &transport_proto, unformat_ip6_address, &sep->ip.ip6,
+ &port))
+ {
+ sep->transport_proto = transport_proto;
+ sep->port = clib_host_to_net_u16 (port);
+ sep->is_ip4 = 0;
+ return 1;
+ }
+ else if (unformat (input, "%U://[%U]", unformat_transport_proto,
+ &transport_proto, unformat_ip6_address, &sep->ip.ip6))
+ {
+ sep->transport_proto = transport_proto;
+ if (sep->transport_proto == TRANSPORT_PROTO_HTTP)
+ port = 80;
+ else if (sep->transport_proto == TRANSPORT_PROTO_TLS)
+ port = 443;
+ else
+ return 0;
+
+ sep->port = clib_host_to_net_u16 (port);
+ sep->is_ip4 = 0;
+ return 1;
+ }
+ else if (unformat (input, "%U://%U/%d", unformat_transport_proto,
&transport_proto, unformat_ip6_address, &sep->ip.ip6,
&port))
{
@@ -106,6 +154,45 @@ parse_uri (char *uri, session_endpoint_cfg_t *sep)
return 0;
}
+/* Use before 'parse_uri()'. Removes target from URI and copies it to 'char
+ * **target'. char **target is resized automatically.
+ */
+session_error_t
+parse_target (char **uri, char **target)
+{
+ u8 counter = 0;
+
+ for (u32 i = 0; i < (u32) strlen (*uri); i++)
+ {
+ if ((*uri)[i] == '/')
+ counter++;
+
+ if (counter == 3)
+ {
+ /* resize and make space for NULL terminator */
+ if (vec_len (*target) < strlen (*uri) - i + 2)
+ vec_resize (*target, strlen (*uri) - i + 2);
+
+ strncpy (*target, *uri + i, strlen (*uri) - i);
+ (*uri)[i + 1] = '\0';
+ break;
+ }
+ }
+
+ if (!*target)
+ {
+ vec_resize (*target, 2);
+ **target = '/';
+ }
+
+ vec_terminate_c_string (*target);
+
+ if (!*target)
+ return SESSION_E_INVALID;
+
+ return 0;
+}
+
session_error_t
vnet_bind_uri (vnet_listen_args_t *a)
{