Skip to content

Commit

Permalink
style: prefix types and functions related to pfcp for consistency (#373)
Browse files Browse the repository at this point in the history
Done to clarify usage, to avoid confusion and to not poison global namespace with conflicting names.

Not all kinds of names renamed, since PR already quite large and it would be easy to miss error.
No changes in logic, only renames. Except typedef u32 pfcp_timer_t; was removed, since it was a leftover and proper type was pfcp_timer_ie_t which is now named pfcp_ie_timer_t for consistency.
  • Loading branch information
mogaika authored Jan 9, 2024
1 parent f3b6ee7 commit 996e0c4
Show file tree
Hide file tree
Showing 17 changed files with 3,133 additions and 3,087 deletions.
3,419 changes: 1,721 additions & 1,698 deletions upf/pfcp.c

Large diffs are not rendered by default.

1,951 changes: 979 additions & 972 deletions upf/pfcp.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion upf/unittest.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ tbcd_test()
int res = 0;
u8 sample_value[] = { 0x09, 0x09, 0x60, 0x00, 0xa2, 0xcb, 0xed, 0xf9 };
u8 * expected = "909006002*#abc9";
u8 * actual = format(0, "%U", format_tbcd, sample_value, sizeof(sample_value));
u8 * actual = format(0, "%U", format_pfcp_tbcd, sample_value, sizeof(sample_value));

UPF_TEST (vec_len (actual) == strlen (expected) &&
!memcmp (actual, expected, strlen(expected)),
Expand Down
12 changes: 6 additions & 6 deletions upf/upf.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,16 @@ upf_tdf_ul_lookup_add_i (u32 tdf_ul_fib_index, const fib_prefix_t *pfx,
}

int
vnet_upf_node_id_set (const pfcp_node_id_t *node_id)
vnet_upf_node_id_set (const pfcp_ie_node_id_t *node_id)
{
upf_main_t *gtm = &upf_main;

switch (node_id->type)
{
case NID_IPv4:
case NID_IPv6:
case NID_FQDN:
free_node_id (&gtm->node_id);
case PFCP_NID_IPv4:
case PFCP_NID_IPv6:
case PFCP_NID_FQDN:
free_pfcp_ie_node_id (&gtm->node_id);
gtm->node_id = *node_id;
return 0;
}
Expand Down Expand Up @@ -635,7 +635,7 @@ upf_init (vlib_main_t *vm)
vlib_zero_simple_counter (&sm->upf_simple_counters[UPF_##E], 0);
foreach_upf_counter_name
#undef _
sm->node_id.type = NID_FQDN;
sm->node_id.type = PFCP_NID_FQDN;
sm->node_id.fqdn = format (0, (char *) "\x03upg");

sm->nat_pool_index_by_name =
Expand Down
30 changes: 15 additions & 15 deletions upf/upf.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ typedef struct
/* Packet Detection Information */
typedef struct
{
pfcp_source_interface_t src_intf;
pfcp_ie_source_interface_t src_intf;
u32 nwi_index;

u32 fields;
Expand All @@ -466,8 +466,8 @@ typedef struct
#define F_PDI_SDF_FILTER 0x0008
#define F_PDI_APPLICATION_ID 0x0010

pfcp_f_teid_t teid;
pfcp_ue_ip_address_t ue_addr;
pfcp_ie_f_teid_t teid;
pfcp_ie_ue_ip_address_t ue_addr;
acl_rule_t *acl;
adr_rule_t adr;
} upf_pdi_t;
Expand All @@ -493,13 +493,13 @@ typedef struct
#define FAR_F_OUTER_HEADER_CREATION BIT (1)
#define FAR_F_FORWARDING_POLICY BIT (2)

pfcp_destination_interface_t dst_intf;
pfcp_ie_destination_interface_t dst_intf;
u32 dst_sw_if_index;
u32 nwi_index;

pfcp_redirect_information_t redirect_information;
pfcp_outer_header_creation_t outer_header_creation;
pfcp_forwarding_policy_t forwarding_policy;
pfcp_ie_redirect_information_t redirect_information;
pfcp_ie_outer_header_creation_t outer_header_creation;
pfcp_ie_forwarding_policy_t forwarding_policy;

uword fp_pool_index;
u32 peer_idx;
Expand Down Expand Up @@ -711,7 +711,7 @@ typedef struct
uword *traffic_by_ue;
urr_time_t traffic_timer;

pfcp_linked_urr_id_t *linked_urr_ids;
pfcp_ie_linked_urr_id_t *linked_urr_ids;
uword *liusa_bitmap;
} upf_urr_t;

Expand All @@ -724,7 +724,7 @@ typedef struct
policer_t policer[UPF_DIRECTION_MAX];

u64 ref_cnt;
pfcp_mbr_t mbr;
pfcp_ie_mbr_t mbr;
} upf_qer_policer_t;

typedef struct
Expand All @@ -736,7 +736,7 @@ typedef struct

u8 gate_status[UPF_DIRECTION_MAX];

pfcp_mbr_t mbr;
pfcp_ie_mbr_t mbr;
clib_bihash_kv_8_8_t policer;
} upf_qer_t;

Expand Down Expand Up @@ -823,7 +823,7 @@ typedef struct

f64 unix_time_start;

pfcp_user_id_t user_id;
pfcp_ie_user_id_t user_id;

session_flows_list_t flows;

Expand Down Expand Up @@ -912,8 +912,8 @@ typedef struct
/* Required for pool_get_aligned */
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);

pfcp_node_id_t node_id;
pfcp_recovery_time_stamp_t recovery_time_stamp;
pfcp_ie_node_id_t node_id;
pfcp_ie_recovery_time_stamp_t recovery_time_stamp;

session_handle_t session_handle;
ip46_address_t rmt_addr;
Expand Down Expand Up @@ -1090,7 +1090,7 @@ typedef struct
u32 pfcp_spec_version;
u32 rand_base;

pfcp_node_id_t node_id;
pfcp_ie_node_id_t node_id;

upf_nat_pool_t *nat_pools;
uword *nat_pool_index_by_name;
Expand Down Expand Up @@ -1159,7 +1159,7 @@ int vnet_upf_tdf_ul_enable_disable (fib_protocol_t fproto, u32 sw_if_index,
int vnet_upf_tdf_ul_table_add_del (u32 vrf, fib_protocol_t fproto,
u32 table_id, u8 add);

int vnet_upf_node_id_set (const pfcp_node_id_t *node_id);
int vnet_upf_node_id_set (const pfcp_ie_node_id_t *node_id);

int vnet_upf_pfcp_heartbeat_config (u32 timeout, u32 retires);

Expand Down
14 changes: 8 additions & 6 deletions upf/upf_adf.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,15 @@ app_scan_for_uri (u8 *uri, flow_entry_t *flow, struct rules *active,

addr =
&flow->key.ip[direction ^ flow->is_reverse ^
!!(pdr->pdi.ue_addr.flags & IE_UE_IP_ADDRESS_SD)];
!!(pdr->pdi.ue_addr.flags & PFCP_UE_IP_ADDRESS_SD)];
upf_debug ("Using %U as UE IP, S/D: %u", format_ip46_address, addr,
IP46_TYPE_ANY,
!!(pdr->pdi.ue_addr.flags & IE_UE_IP_ADDRESS_SD));
!!(pdr->pdi.ue_addr.flags & PFCP_UE_IP_ADDRESS_SD));

if (ip46_address_is_ip4 (addr))
{

if (!(pdr->pdi.ue_addr.flags & IE_UE_IP_ADDRESS_V4))
if (!(pdr->pdi.ue_addr.flags & PFCP_UE_IP_ADDRESS_V4))
{
adf_debug ("skip PDR %u for no UE IPv4 address\n", pdr->id);
continue;
Expand All @@ -315,15 +315,16 @@ app_scan_for_uri (u8 *uri, flow_entry_t *flow, struct rules *active,
{
adf_debug (
"skip PDR %u for UE IPv4 mismatch, S/D: %u, %U != %U\n",
pdr->id, !!(pdr->pdi.ue_addr.flags & IE_UE_IP_ADDRESS_SD),
pdr->id,
!!(pdr->pdi.ue_addr.flags & PFCP_UE_IP_ADDRESS_SD),
format_ip4_address, &pdr->pdi.ue_addr.ip4,
format_ip46_address, addr, IP46_TYPE_ANY);
continue;
}
}
else
{
if (!(pdr->pdi.ue_addr.flags & IE_UE_IP_ADDRESS_V6))
if (!(pdr->pdi.ue_addr.flags & PFCP_UE_IP_ADDRESS_V6))
{
adf_debug ("skip PDR %u for no UE IPv6 address\n", pdr->id);
continue;
Expand All @@ -334,7 +335,8 @@ app_scan_for_uri (u8 *uri, flow_entry_t *flow, struct rules *active,
{
adf_debug (
"skip PDR %u for UE IPv6 mismatch, S/D: %u, %U != %U\n",
pdr->id, !!(pdr->pdi.ue_addr.flags & IE_UE_IP_ADDRESS_SD),
pdr->id,
!!(pdr->pdi.ue_addr.flags & PFCP_UE_IP_ADDRESS_SD),
format_ip6_address, &pdr->pdi.ue_addr.ip6,
format_ip46_address, addr, IP46_TYPE_ANY);
continue;
Expand Down
28 changes: 14 additions & 14 deletions upf/upf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ vl_api_upf_pfcp_reencode_t_handler (vl_api_upf_pfcp_reencode_t *mp)
upf_main_t *sm = &upf_main;
vl_api_upf_pfcp_reencode_reply_t *rmp;
pfcp_decoded_msg_t dmsg;
pfcp_offending_ie_t *err = 0;
pfcp_ie_offending_ie_t *err = 0;
u8 *reply_data = 0;
int rv = 0;
int data_len = 0, packet_len = clib_net_to_host_u32 (mp->packet_len);

if ((rv = pfcp_decode_msg (mp->packet, packet_len, &dmsg, &err)) != 0)
{
pfcp_offending_ie_t *cur_err;
pfcp_ie_offending_ie_t *cur_err;
vec_foreach (cur_err, err)
{
clib_warning ("offending IE: %d", *cur_err);
Expand Down Expand Up @@ -294,15 +294,15 @@ vl_api_upf_pfcp_format_t_handler (vl_api_upf_pfcp_reencode_t *mp)
upf_main_t *sm = &upf_main;
vl_api_upf_pfcp_format_reply_t *rmp;
pfcp_decoded_msg_t dmsg;
pfcp_offending_ie_t *err = 0;
pfcp_ie_offending_ie_t *err = 0;
u8 *s;
/* pfcp_offending_ie_t *err = NULL; */
/* pfcp_ie_offending_ie_t *err = NULL; */
int rv = 0;
int text_len = 0, packet_len = clib_net_to_host_u32 (mp->packet_len);

if ((rv = pfcp_decode_msg (mp->packet, packet_len, &dmsg, &err)) != 0)
{
pfcp_offending_ie_t *cur_err;
pfcp_ie_offending_ie_t *cur_err;
vec_foreach (cur_err, err)
{
clib_warning ("offending IE: %d", *cur_err);
Expand All @@ -312,7 +312,7 @@ vl_api_upf_pfcp_format_t_handler (vl_api_upf_pfcp_reencode_t *mp)
goto reply;
}

s = format (0, "%U\n", format_dmsg, &dmsg);
s = format (0, "%U\n", format_pfcp_dmsg, &dmsg);

text_len = vec_len (s);

Expand Down Expand Up @@ -894,17 +894,17 @@ vl_api_upf_set_node_id_t_handler (vl_api_upf_set_node_id_t *mp)
upf_main_t *sm = &upf_main;
vl_api_upf_set_node_id_reply_t *rmp = NULL;

pfcp_node_id_t node_id = { 0 };
pfcp_ie_node_id_t node_id = { 0 };
node_id.type = mp->type;

switch (mp->type)
{
case NID_IPv4:
case NID_IPv6:
case PFCP_NID_IPv4:
case PFCP_NID_IPv6:
ip_address_decode (&mp->ip, &node_id.ip);
break;

case NID_FQDN:
case PFCP_NID_FQDN:
vec_validate (node_id.fqdn, mp->fqdn_len);
memcpy (node_id.fqdn, mp->fqdn, mp->fqdn_len);
break;
Expand Down Expand Up @@ -932,20 +932,20 @@ vl_api_upf_get_node_id_t_handler (vl_api_upf_get_node_id_t *mp)

vl_api_upf_get_node_id_reply_t *rmp = NULL;
upf_main_t *sm = &upf_main;
pfcp_node_id_t *node = &sm->node_id;
pfcp_ie_node_id_t *node = &sm->node_id;

switch (node->type)
{
case NID_IPv4:
case NID_IPv6:
case PFCP_NID_IPv4:
case PFCP_NID_IPv6:
{
rmp = vl_msg_api_alloc (sizeof (*rmp));
clib_memset (rmp, 0, sizeof (*rmp));

ip_address_encode (&ip_addr_46 (node), IP46_TYPE_ANY, &rmp->ip);
break;
}
case NID_FQDN:
case PFCP_NID_FQDN:
{
u8 len;
len = strlen (node->fqdn);
Expand Down
29 changes: 15 additions & 14 deletions upf/upf_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ upf_show_nwi_command_fn (vlib_main_t *vm, unformat_input_t *main_input,
vlib_cli_output (vm,
"%U, ip4-table-id %u, ip6-table-id %u, ipfix-policy "
"%U, ipfix-collector-ip %U\n",
format_dns_labels, nwi->name, fib4->hash.table_id,
format_pfcp_dns_labels, nwi->name, fib4->hash.table_id,
fib6->table_id, format_upf_ipfix_policy,
nwi->ipfix_policy, format_ip_address,
&nwi->ipfix_collector_ip);
Expand Down Expand Up @@ -854,7 +854,7 @@ upf_node_id_command_fn (vlib_main_t *vm, unformat_input_t *main_input,
unformat_input_t _line_input, *line_input = &_line_input;
clib_error_t *error = NULL;
u8 *fqdn = 0;
pfcp_node_id_t node_id = { .type = (u8) ~0 };
pfcp_ie_node_id_t node_id = { .type = (u8) ~0 };

if (!unformat_user (main_input, unformat_line_input, line_input))
return 0;
Expand All @@ -863,19 +863,19 @@ upf_node_id_command_fn (vlib_main_t *vm, unformat_input_t *main_input,
{
if (unformat (line_input, "fqdn %_%v%_", &fqdn))
{
node_id.type = NID_FQDN;
node_id.type = PFCP_NID_FQDN;
node_id.fqdn = upf_name_to_labels (fqdn);
vec_free (fqdn);
}
else if (unformat (line_input, "ip4 %U", unformat_ip46_address,
&node_id.ip, IP46_TYPE_ANY))
{
node_id.type = NID_IPv4;
node_id.type = PFCP_NID_IPv4;
}
else if (unformat (line_input, "ip6 %U", unformat_ip46_address,
&node_id.ip, IP46_TYPE_ANY))
{
node_id.type = NID_IPv6;
node_id.type = PFCP_NID_IPv6;
}
else
{
Expand Down Expand Up @@ -905,7 +905,7 @@ upf_show_node_id_command_fn (vlib_main_t *vm, unformat_input_t *main_input,
vlib_cli_command_t *cmd)
{
upf_main_t *gtm = &upf_main;
vlib_cli_output (vm, "Node ID: %U", format_node_id, &gtm->node_id);
vlib_cli_output (vm, "Node ID: %U", format_pfcp_ie_node_id, &gtm->node_id);
return NULL;
}

Expand Down Expand Up @@ -955,18 +955,18 @@ upf_gtpu_endpoint_add_del_command_fn (vlib_main_t *vm,
vec_free (s);
}
else if (unformat (line_input, "intf access"))
intf = SRC_INTF_ACCESS;
intf = PFCP_SRC_INTF_ACCESS;
else if (unformat (line_input, "intf core"))
intf = SRC_INTF_CORE;
intf = PFCP_SRC_INTF_CORE;
else if (unformat (line_input, "intf sgi"))
/*
* WTF: the specification does permit that,
* but what does that mean in terms
* of the UPIP IE?
*/
intf = SRC_INTF_SGI_LAN;
intf = PFCP_SRC_INTF_SGI_LAN;
else if (unformat (line_input, "intf cp"))
intf = SRC_INTF_CP;
intf = PFCP_SRC_INTF_CP;
else if (unformat (line_input, "teid %u/%u", &teid, &teidri))
{
if (teidri > 7)
Expand Down Expand Up @@ -1282,22 +1282,23 @@ upf_show_assoc_command_fn (vlib_main_t *vm, unformat_input_t *main_input,

if (has_ip && has_fqdn)
{
pfcp_node_id_t node_id;
pfcp_ie_node_id_t node_id;

if (has_ip)
{
node_id.type = ip46_address_is_ip4 (&node_ip) ? NID_IPv4 : NID_IPv6;
node_id.type =
ip46_address_is_ip4 (&node_ip) ? PFCP_NID_IPv4 : PFCP_NID_IPv6;
node_id.ip = node_ip;
}
if (has_fqdn)
{
node_id.type = NID_FQDN;
node_id.type = PFCP_NID_FQDN;
node_id.fqdn = upf_name_to_labels (fqdn);
}

node = pfcp_get_association (&node_id);

if (node_id.type == NID_FQDN)
if (node_id.type == PFCP_NID_FQDN)
vec_free (node_id.fqdn);

if (!node)
Expand Down
Loading

0 comments on commit 996e0c4

Please sign in to comment.