aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeels Janosch Hofmeyr <nhofmeyr@sysmocom.de>2023-03-31 07:26:54 +0200
committerNeels Janosch Hofmeyr <nhofmeyr@sysmocom.de>2023-04-15 00:19:34 +0200
commite6ff99d7acbe270ed8f271daeaafc99e03a48176 (patch)
treedfe1ea8a5570152b978adc1c036eb0f35fe5b5dc /src
parent761e17039ab7d2e926b35feba1203b016a547f18 (diff)
pfcp_msg: refactor LOG_PFCP_MSG
It was requested during code review to make this a function and not a macro. One effective change: no longer log "NULL{fi=NULL}" when no m->ctx.session_fi or .peer_fi are set. Change-Id: Ic84090c9b1a34185577cfb2ea1efa9c07542df34
Diffstat (limited to 'src')
-rw-r--r--src/libosmo-pfcp/pfcp_msg.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/libosmo-pfcp/pfcp_msg.c b/src/libosmo-pfcp/pfcp_msg.c
index 9893cb2..74335fe 100644
--- a/src/libosmo-pfcp/pfcp_msg.c
+++ b/src/libosmo-pfcp/pfcp_msg.c
@@ -550,3 +550,32 @@ char *osmo_pfcp_msg_to_str_c(void *ctx, const struct osmo_pfcp_msg *m)
{
OSMO_NAME_C_IMPL(ctx, 256, "ERROR", osmo_pfcp_msg_to_str_buf, m)
}
+
+int osmo_pfcp_msg_log_info_buf(char *buf, size_t buflen, const struct osmo_pfcp_msg *m)
+{
+ struct osmo_strbuf sb = { .buf = buf, .len = buflen };
+ struct osmo_fsm_inst *fi = m ? (m->ctx.session_fi ?: m->ctx.peer_fi) : NULL;
+ enum osmo_pfcp_cause *cause = osmo_pfcp_msg_cause(m);
+
+ if (fi)
+ OSMO_STRBUF_PRINTF(sb, "%s{%s}: ",
+ osmo_fsm_inst_name(fi),
+ osmo_fsm_state_name(fi->fsm, fi->state));
+ else
+ OSMO_STRBUF_APPEND(sb, osmo_sockaddr_to_str_buf2, &m->remote_addr);
+ OSMO_STRBUF_PRINTF(sb, "%s PFCP seq-%u",
+ m->rx ? "-rx->" : "<-tx-",
+ m->h.sequence_nr);
+ if (m->h.seid_present)
+ OSMO_STRBUF_PRINTF(sb, " SEID-0x%"PRIx64, m->h.seid);
+
+ OSMO_STRBUF_PRINTF(sb, " %s", osmo_pfcp_message_type_str(m->h.message_type));
+ if (cause)
+ OSMO_STRBUF_PRINTF(sb, ": %s", osmo_pfcp_cause_str(*cause));
+ return sb.chars_needed;
+}
+
+char *osmo_pfcp_msg_log_info_c(void *ctx, const struct osmo_pfcp_msg *m)
+{
+ OSMO_NAME_C_IMPL(ctx, 128, "ERROR", osmo_pfcp_msg_log_info_buf, m)
+}