From 6752b96fad72936bea66e38b4d275fbdd315165a Mon Sep 17 00:00:00 2001 From: Vladimir Zhigulin Date: Sat, 24 Feb 2024 11:46:17 +0100 Subject: [PATCH] [CENNSO-1706] feat: support old policy names in ipfix --- upf/upf_ipfix.c | 58 ++++++++++++++++++++++++++++----------- upf/upf_ipfix.h | 1 + upf/upf_ipfix_templates.c | 2 ++ 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/upf/upf_ipfix.c b/upf/upf_ipfix.c index 1bb2551..5693a06 100644 --- a/upf/upf_ipfix.c +++ b/upf/upf_ipfix.c @@ -728,37 +728,63 @@ upf_ipfix_init (vlib_main_t *vm) return error; } +static bool +compare_cstr_vec (const char *cstr, u8 *vstr) +{ + u32 cl = strlen (cstr); + u32 vl = vec_len (vstr); + + if (cl == vl) + if (0 == memcmp (cstr, vstr, cl)) + return true; + return false; +} + upf_ipfix_policy_t upf_ipfix_lookup_policy (u8 *name, bool *ok) { - upf_ipfix_policy_t policy; - u32 name_len = vec_len (name); + upf_ipfix_policy_t policy, result = UPF_IPFIX_POLICY_UNSPECIFIED; + u32 name_len = vec_len (name); if (!name_len) { - if (ok) - *ok = true; - return UPF_IPFIX_POLICY_NONE; + result = UPF_IPFIX_POLICY_NONE; + goto _return; } - else if (ok) - *ok = false; for (policy = UPF_IPFIX_POLICY_NONE; policy < UPF_IPFIX_N_POLICIES; policy++) { - u32 l = strlen (upf_ipfix_templates[policy].name); - if (l == name_len && !memcmp (name, upf_ipfix_templates[policy].name, l)) + if (compare_cstr_vec (upf_ipfix_templates[policy].name, name)) { - if (ok) - *ok = true; - return policy; + result = policy; + goto _return; } + + if (upf_ipfix_templates[policy].alt_name) + if (compare_cstr_vec (upf_ipfix_templates[policy].alt_name, name)) + { + result = policy; + goto _return; + } } - /* avoid silently ignoring the error */ - if (!ok) - clib_warning ("Bad IPFIX policy: %v", name); +_return: + if (result == UPF_IPFIX_POLICY_UNSPECIFIED) + { + if (ok) + *ok = false; - return UPF_IPFIX_POLICY_NONE; + /* avoid silently ignoring the error */ + clib_warning ("Bad IPFIX policy: %v", name); + return UPF_IPFIX_POLICY_NONE; + } + else + { + if (ok) + *ok = true; + + return result; + } } uword diff --git a/upf/upf_ipfix.h b/upf/upf_ipfix.h index 7422e47..27d22e2 100644 --- a/upf/upf_ipfix.h +++ b/upf/upf_ipfix.h @@ -93,6 +93,7 @@ typedef struct typedef struct { char *name; + char *alt_name; upf_ipfix_template_proto_t per_ip[FIB_PROTOCOL_IP_MAX]; } upf_ipfix_template_t; diff --git a/upf/upf_ipfix_templates.c b/upf/upf_ipfix_templates.c index 64c0654..265d652 100644 --- a/upf/upf_ipfix_templates.c +++ b/upf/upf_ipfix_templates.c @@ -171,6 +171,7 @@ upf_ipfix_template_t upf_ipfix_templates[UPF_IPFIX_N_POLICIES] = { }, [UPF_IPFIX_POLICY_NAT_EVENT] = { .name = "NatEvent", + .alt_name = "default", .per_ip={ [FIB_PROTOCOL_IP4] = { .field_count = IPFIX_TEMPLATE_COUNT (IPFIX_TEMPLATE_NAT_EVENT_IPV4, @@ -188,6 +189,7 @@ upf_ipfix_template_t upf_ipfix_templates[UPF_IPFIX_N_POLICIES] = { }, [UPF_IPFIX_POLICY_FLOW_USAGE] = { .name = "FlowUsage", + .alt_name = "dest", .per_ip={ [FIB_PROTOCOL_IP4] = { .field_count = IPFIX_TEMPLATE_COUNT (IPFIX_TEMPLATE_FLOW_USAGE_IPV4,