From 3bbbf0dbd367fd8611f9f390a2c6e31a89ce08a9 Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Tue, 19 Nov 2019 17:23:22 -0800 Subject: session: fix transport proto unformat Type: fix Change-Id: I38a5cbd53b278c21142bac4ee1bbe5dc8bcaaac9 Signed-off-by: Florin Coras --- src/vnet/session/transport.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'src/vnet/session/transport.c') diff --git a/src/vnet/session/transport.c b/src/vnet/session/transport.c index 3160a48d37d..902c7400af9 100644 --- a/src/vnet/session/transport.c +++ b/src/vnet/session/transport.c @@ -136,20 +136,49 @@ format_transport_half_open_connection (u8 * s, va_list * args) return s; } +static u8 +unformat_transport_str_match (unformat_input_t * input, const char *str) +{ + int i; + + if (strlen (str) > vec_len (input->buffer) - input->index) + return 0; + + for (i = 0; i < strlen (str); i++) + { + if (input->buffer[i + input->index] != str[i]) + return 0; + } + return 1; +} + uword unformat_transport_proto (unformat_input_t * input, va_list * args) { u32 *proto = va_arg (*args, u32 *); + u8 longest_match = 0, match; + char *str_match = 0; #define _(sym, str, sstr) \ - if (unformat (input, str)) \ + if (unformat_transport_str_match (input, str)) \ { \ - *proto = TRANSPORT_PROTO_ ## sym; \ - return 1; \ + match = strlen (str); \ + if (match > longest_match) \ + { \ + *proto = TRANSPORT_PROTO_ ## sym; \ + longest_match = match; \ + str_match = str; \ + } \ } foreach_transport_proto #undef _ - return 0; + if (longest_match) + { + unformat (input, str_match); + return 1; + } + + return 0; } u32 -- cgit 1.2.3-korg