Skip to content

Commit

Permalink
[CENNSO-1706] feat: support old policy names in ipfix (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
mogaika authored Feb 27, 2024
1 parent 2740f75 commit 1d3ff3d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
58 changes: 42 additions & 16 deletions upf/upf_ipfix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions upf/upf_ipfix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions upf/upf_ipfix_templates.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 1d3ff3d

Please sign in to comment.