clarify comments and naming around PDR+FAR classification

No functional change.

Rename forw_to_core to access_to_core.
Rename forw_from_core to core_to_access.

Rename add_gtp_action_endecaps to add_gtp_action_tunend.
Rename add_gtp_action_forw to add_gtp_action_tunmap.

Add assertions to clearly indicate expected PDR and reverse PDR
directions.

Tweak various comments and log messages.

Fix some comments that have Access / Core flipped.

Change-Id: Ia199bb6944476eff6af89b5ab015a9a2f8ce330e
This commit is contained in:
Neels Hofmeyr 2022-12-05 04:15:46 +01:00 committed by neels
parent 8e842b890c
commit e68eca0e8f
2 changed files with 53 additions and 46 deletions

View File

@ -94,8 +94,8 @@ struct pdr {
bool rx_decaps;
bool forw_encaps;
bool forw_to_core;
bool forw_from_core;
bool access_to_core;
bool core_to_access;
struct pdr *reverse_pdr;
bool active;

View File

@ -994,8 +994,8 @@ static void pdr_classify(struct pdr *pdr)
{
pdr->rx_decaps = false;
pdr->forw_encaps = false;
pdr->forw_to_core = false;
pdr->forw_from_core = false;
pdr->access_to_core = false;
pdr->core_to_access = false;
if (!pdr->far)
return;
@ -1007,10 +1007,10 @@ static void pdr_classify(struct pdr *pdr)
if (!action_is_forw(&pdr->far->desc.apply_action))
return;
pdr->forw_to_core = (pdr->desc.pdi.source_iface == OSMO_PFCP_SOURCE_IFACE_ACCESS
&& pdr->far->desc.forw_params.destination_iface == OSMO_PFCP_DEST_IFACE_CORE);
pdr->access_to_core = (pdr->desc.pdi.source_iface == OSMO_PFCP_SOURCE_IFACE_ACCESS
&& pdr->far->desc.forw_params.destination_iface == OSMO_PFCP_DEST_IFACE_CORE);
pdr->forw_from_core = (pdr->desc.pdi.source_iface == OSMO_PFCP_SOURCE_IFACE_CORE
pdr->core_to_access = (pdr->desc.pdi.source_iface == OSMO_PFCP_SOURCE_IFACE_CORE
&& pdr->far->desc.forw_params.destination_iface == OSMO_PFCP_DEST_IFACE_ACCESS);
}
@ -1030,6 +1030,11 @@ void pdr_reverse_unset(struct pdr *pdr)
pdr->reverse_pdr = NULL;
}
/* Log that a PDR (and its reverse-PDR) is inactive.
* \param pdr The Access-to-Core PDR.
* \param desc Why it is inactive.
* \param pdr_to_str The PDR that desc describes, can be pdr or the reverse Core-to-Access PDR.
*/
static void log_inactive_pdr_set(struct pdr *pdr, const char *desc, const struct pdr *pdr_to_str)
{
struct pdr *rpdr = pdr->reverse_pdr;
@ -1055,7 +1060,7 @@ static void log_inactive_pdr_set(struct pdr *pdr, const char *desc, const struct
* Its reverse-PDR's FAR must have an outer-header creation with a remote TEID.
* \param pdr A rule detecting packets on Access, where pdr->reverse_pdr detects packets on Core.
*/
static void add_gtp_action_endecaps(void *ctx, struct llist_head *dst, struct pdr *pdr)
static void add_gtp_action_tunend(void *ctx, struct llist_head *dst, struct pdr *pdr)
{
struct up_session *session = pdr->session;
struct up_gtp_action *a;
@ -1066,18 +1071,20 @@ static void add_gtp_action_endecaps(void *ctx, struct llist_head *dst, struct pd
OSMO_ASSERT(pdr->far);
OSMO_ASSERT(pdr->reverse_pdr);
OSMO_ASSERT(pdr->reverse_pdr->far);
/* To decaps, we need to have a local TEID assigned for which to receive GTP packets. */
if (!pdr->local_f_teid || pdr->local_f_teid->choose_flag) {
log_inactive_pdr_set(pdr, "missing local TEID", pdr);
return;
}
/* To encaps, we need to have a remote TEID assigned to send out in GTP packets, and we need to know where to
* send GTP to. */
rpdr = pdr->reverse_pdr;
rfar = rpdr->far;
rfar_forw = &rfar->desc.forw_params;
OSMO_ASSERT(pdr->access_to_core);
OSMO_ASSERT(rpdr->core_to_access);
/* To decaps incoming on Access, we need to have a local F-TEID assigned for which to receive GTP packets. */
if (!pdr->local_f_teid || pdr->local_f_teid->choose_flag) {
log_inactive_pdr_set(pdr, "missing local F-TEID", pdr);
return;
}
/* To encaps outgoing on Access, we need to have a remote F-TEID assigned to send out in GTP packets */
if (!rfar->desc.forw_params_present) {
log_inactive_pdr_set(pdr, "missing FAR Forwarding Parameters", rpdr);
return;
@ -1095,8 +1102,7 @@ static void add_gtp_action_endecaps(void *ctx, struct llist_head *dst, struct pd
return;
}
/* To receive packets to be encapsulated, we need to know the assigned IP address for the UE, which receives the
* IP packets that should be placed into GTP. */
/* To receive IP packets incoming on Core, we need to know the assigned IP address for the UE */
if (!rpdr->desc.pdi.ue_ip_address_present) {
log_inactive_pdr_set(pdr, "missing UE IP Address in PDI", rpdr);
return;
@ -1149,7 +1155,7 @@ static void add_gtp_action_endecaps(void *ctx, struct llist_head *dst, struct pd
* Both FARs must have an outer-header creation with a remote F-TEID.
* \param pdr A rule detecting packets on Access, where pdr->reverse_pdr detects packets on Core.
*/
static void add_gtp_action_forw(void *ctx, struct llist_head *dst, struct pdr *pdr)
static void add_gtp_action_tunmap(void *ctx, struct llist_head *dst, struct pdr *pdr)
{
struct up_session *session = pdr->session;
struct up_gtp_action *a;
@ -1169,52 +1175,53 @@ static void add_gtp_action_forw(void *ctx, struct llist_head *dst, struct pdr *p
rfar = rpdr->far;
rfar_forw = &rfar->desc.forw_params;
/* To decaps, we need to have a local TEID assigned for which to receive GTP packets. */
/* decaps from CORE */
OSMO_ASSERT(pdr->access_to_core);
OSMO_ASSERT(rpdr->core_to_access);
/* To decaps incoming on Access, we need to have a local F-TEID assigned for which to receive GTP packets. */
if (!pdr->local_f_teid || pdr->local_f_teid->choose_flag) {
log_inactive_pdr_set(pdr, "missing local TEID (CORE side)", pdr);
log_inactive_pdr_set(pdr, "missing local F-TEID (Access side)", pdr);
return;
}
/* decaps from ACCESS */
/* To decaps incoming on Core, we need to have a local F-TEID assigned for which to receive GTP packets. */
if (!rpdr->local_f_teid || rpdr->local_f_teid->choose_flag) {
log_inactive_pdr_set(pdr, "missing local TEID (ACCESS side)", pdr);
log_inactive_pdr_set(pdr, "missing local F-TEID (Core side)", pdr);
return;
}
/* To encaps, we need to have a remote TEID assigned to send out in GTP packets, and we need to know where to
* send GTP to. */
/* encaps towards ACCESS */
/* To encaps outgoing on Core, we need to have a remote F-TEID assigned to send out in GTP packets */
if (!far->desc.forw_params_present) {
log_inactive_pdr_set(pdr, "missing FAR Forwarding Parameters", pdr);
log_inactive_pdr_set(pdr, "missing FAR Forwarding Parameters (Access side)", pdr);
return;
}
if (!far_forw->outer_header_creation_present) {
log_inactive_pdr_set(pdr, "missing FAR Outer Header Creation", pdr);
log_inactive_pdr_set(pdr, "missing FAR Outer Header Creation (Access side)", pdr);
return;
}
if (!far_forw->outer_header_creation.teid_present) {
log_inactive_pdr_set(pdr, "missing TEID in FAR Outer Header Creation", pdr);
log_inactive_pdr_set(pdr, "missing TEID in FAR Outer Header Creation (Access side)", pdr);
return;
}
if (!far_forw->outer_header_creation.ip_addr.v4_present) {
log_inactive_pdr_set(pdr, "missing IPv4 in FAR Outer Header Creation", pdr);
log_inactive_pdr_set(pdr, "missing IPv4 in FAR Outer Header Creation (Access side)", pdr);
return;
}
/* encaps towards CORE */
/* To encaps outgoing on Access, we need to have a remote F-TEID assigned to send out in GTP packets */
if (!rfar->desc.forw_params_present) {
log_inactive_pdr_set(pdr, "missing FAR Forwarding Parameters", rpdr);
log_inactive_pdr_set(pdr, "missing FAR Forwarding Parameters (Access side)", rpdr);
return;
}
if (!rfar_forw->outer_header_creation_present) {
log_inactive_pdr_set(pdr, "missing FAR Outer Header Creation", rpdr);
log_inactive_pdr_set(pdr, "missing FAR Outer Header Creation (Access side)", rpdr);
return;
}
if (!rfar_forw->outer_header_creation.teid_present) {
log_inactive_pdr_set(pdr, "missing TEID in FAR Outer Header Creation", rpdr);
log_inactive_pdr_set(pdr, "missing TEID in FAR Outer Header Creation (Access side)", rpdr);
return;
}
if (!rfar_forw->outer_header_creation.ip_addr.v4_present) {
log_inactive_pdr_set(pdr, "missing IPv4 in FAR Outer Header Creation", rpdr);
log_inactive_pdr_set(pdr, "missing IPv4 in FAR Outer Header Creation (Access side)", rpdr);
return;
}
@ -1278,13 +1285,13 @@ static enum osmo_pfcp_cause find_gtp_actions(void *ctx, struct llist_head *dst,
if (pdr->reverse_pdr)
continue;
/* In this outer loop, only follow the forw_to_core directed PDRs, in the inner loop find the matching
* forw_from_core PDR. i.e. we are looking only at PDRs detecting packets on the Access side, pairing up
/* In this outer loop, only follow the access_to_core directed PDRs, in the inner loop find the matching
* core_to_access PDR. i.e. we are looking only at PDRs detecting packets on the Access side, pairing up
* with "reverse PDRs" detecting packets on the Core side. */
if (!pdr->forw_to_core)
if (!pdr->access_to_core)
continue;
/* If a required TEID is not known, we cannot pair this PDR up */
/* If a required local addr + TEID is not known, we cannot pair this PDR up */
if (pdr->rx_decaps && !pdr->local_f_teid)
continue;
@ -1295,7 +1302,7 @@ static enum osmo_pfcp_cause find_gtp_actions(void *ctx, struct llist_head *dst,
continue;
/* Looking for a PDR facing the other way */
if (!other->forw_from_core)
if (!other->core_to_access)
continue;
/* GTP header-ness must match, in reverse. */
if (pdr->rx_decaps != other->forw_encaps
@ -1318,14 +1325,14 @@ static enum osmo_pfcp_cause find_gtp_actions(void *ctx, struct llist_head *dst,
continue;
}
/* Iterate in direction to-Core, where pdr->reverse_pdr will be the from-Core counterpart. */
if (!pdr->forw_to_core)
/* Iterate in direction Access-to-Core, where pdr->reverse_pdr will be the Core-to-Access counterpart. */
if (!pdr->access_to_core)
continue;
if (pdr->rx_decaps && !pdr->forw_encaps)
add_gtp_action_endecaps(ctx, dst, pdr);
add_gtp_action_tunend(ctx, dst, pdr);
else if (pdr->rx_decaps && pdr->forw_encaps)
add_gtp_action_forw(ctx, dst, pdr);
add_gtp_action_tunmap(ctx, dst, pdr);
else {
/* log the details of both PDRs in two separate log lines */
log_inactive_pdr_set(pdr, "not implemented", pdr);