neels has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-upf/+/28239 )


Change subject: implement OSMO_LOG_PFCP_MSG_SRC as va function
......................................................................

implement OSMO_LOG_PFCP_MSG_SRC as va function

This was requested by code review.

Change-Id: I1713868ebb9583c67f0a4ecc9558263f6888a24d
---
M include/osmocom/pfcp/pfcp_msg.h
M src/libosmo-pfcp/pfcp_msg.c
2 files changed, 45 insertions(+), 20 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-upf refs/changes/39/28239/1

diff --git a/include/osmocom/pfcp/pfcp_msg.h b/include/osmocom/pfcp/pfcp_msg.h
index 949800e..7db6f3f 100644
--- a/include/osmocom/pfcp/pfcp_msg.h
+++ b/include/osmocom/pfcp/pfcp_msg.h
@@ -42,26 +42,8 @@

 #define OSMO_PFCP_MSGB_ALLOC_SIZE 2048

-#define OSMO_LOG_PFCP_MSG_SRC(M, LEVEL, file, line, FMT, ARGS...) do { \
-               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 ((M)->h.seid_present) { \
-                       LOGPFSMSLSRC(_fi, DLPFCP, LEVEL, file, line, \
-                                    "%s%s PFCP seq-%u SEID-0x%"PRIx64" %s%s%s: 
" FMT, \
-                                    _fi ? "" : 
osmo_sockaddr_to_str_c(OTC_SELECT, &(M)->remote_addr), \
-                                    (M)->rx ? "-rx->" : "<-tx-", 
(M)->h.sequence_nr, \
-                                    (M)->h.seid, \
-                                    
osmo_pfcp_message_type_str((M)->h.message_type), cause ? ": " : "", \
-                                    cause ? osmo_pfcp_cause_str(*cause) : "", 
##ARGS); \
-               } else { \
-                       LOGPFSMSLSRC(_fi, DLPFCP, LEVEL, file, line, \
-                                    "%s%s PFCP seq-%u %s%s%s: " FMT, \
-                                    _fi ? "" : 
osmo_sockaddr_to_str_c(OTC_SELECT, &(M)->remote_addr), \
-                                    (M)->rx ? "-rx->" : "<-tx-", 
(M)->h.sequence_nr, \
-                                    
osmo_pfcp_message_type_str((M)->h.message_type), cause ? ": " : "", \
-                                    cause ? osmo_pfcp_cause_str(*cause) : "", 
##ARGS); \
-               } \
-       } while (0)
+#define OSMO_LOG_PFCP_MSG_SRC(M, LEVEL, file, line, FMT, ARGS...) \
+       osmo_log_pfcp_msg_src(M, LEVEL, file, line, FMT, ##ARGS)

 #define OSMO_LOG_PFCP_MSG(M, LEVEL, FMT, ARGS...) \
        OSMO_LOG_PFCP_MSG_SRC(M, LEVEL, __FILE__, __LINE__, FMT, ##ARGS)
@@ -195,3 +177,6 @@

 int osmo_pfcp_msg_to_str_buf(char *buf, size_t buflen, const struct 
osmo_pfcp_msg *m);
 char *osmo_pfcp_msg_to_str_c(void *ctx, const struct osmo_pfcp_msg *m);
+
+void osmo_log_pfcp_msg_src(const struct osmo_pfcp_msg *m, unsigned int level, 
const char *file, int line,
+                          const char *fmt, ...);
diff --git a/src/libosmo-pfcp/pfcp_msg.c b/src/libosmo-pfcp/pfcp_msg.c
index 9d65efc..60038f7 100644
--- a/src/libosmo-pfcp/pfcp_msg.c
+++ b/src/libosmo-pfcp/pfcp_msg.c
@@ -538,3 +538,43 @@
 {
        OSMO_NAME_C_IMPL(ctx, 256, "ERROR", osmo_pfcp_msg_to_str_buf, m)
 }
+
+void osmo_log_pfcp_msg_src(const struct osmo_pfcp_msg *m, unsigned int level, 
const char *file, int line,
+                          const char *fmt, ...)
+{
+       va_list ap;
+       struct osmo_fsm_inst *fi;
+       enum osmo_pfcp_cause *cause;
+       char *msg;
+
+       if (!log_check_level(DLPFCP, level))
+               return;
+
+       fi = m ? (m->ctx.session_fi ?: m->ctx.peer_fi) : NULL;
+       cause = osmo_pfcp_msg_cause(m);
+
+       va_start(ap, fmt);
+       msg = talloc_vasprintf(m, fmt, ap);
+       va_end(ap);
+
+       if (m->h.seid_present) {
+               LOGPFSMSLSRC(fi, DLPFCP, level, file, line,
+                            "%s%s PFCP seq-%u SEID-0x%"PRIx64" %s%s%s: %s",
+                            fi ? "" : osmo_sockaddr_to_str_c(OTC_SELECT, 
&m->remote_addr),
+                            m->rx ? "-rx->" : "<-tx-", m->h.sequence_nr,
+                            m->h.seid,
+                            osmo_pfcp_message_type_str(m->h.message_type), 
cause ? ": " : "",
+                            cause ? osmo_pfcp_cause_str(*cause) : "",
+                            msg);
+       } else {
+               LOGPFSMSLSRC(fi, DLPFCP, level, file, line,
+                            "%s%s PFCP seq-%u %s%s%s: %s",
+                            fi ? "" : osmo_sockaddr_to_str_c(OTC_SELECT, 
&m->remote_addr),
+                            m->rx ? "-rx->" : "<-tx-", m->h.sequence_nr,
+                            osmo_pfcp_message_type_str(m->h.message_type), 
cause ? ": " : "",
+                            cause ? osmo_pfcp_cause_str(*cause) : "",
+                            msg);
+       }
+
+       talloc_free(msg);
+}

--
To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/28239
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-upf
Gerrit-Branch: master
Gerrit-Change-Id: I1713868ebb9583c67f0a4ecc9558263f6888a24d
Gerrit-Change-Number: 28239
Gerrit-PatchSet: 1
Gerrit-Owner: neels <[email protected]>
Gerrit-MessageType: newchange

Reply via email to