Change in osmo-mgw[master]: Introduce log fmt helpers LOGPENDP and LOGPCONN

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Wed Apr 24 16:58:05 UTC 2019


Pau Espin Pedrol has uploaded this change for review. ( https://gerrit.osmocom.org/13773


Change subject: Introduce log fmt helpers LOGPENDP and LOGPCONN
......................................................................

Introduce log fmt helpers LOGPENDP and LOGPCONN

Let's define macro once and use it everywhere instead of passing endp
information in different ways everywhere. Furthermore, use conn whenever
appropiate to have more information.

Change-Id: I1c49b1eb16bc5f1010376da5cf407ca6e31d81f2
---
M include/osmocom/mgcp/mgcp_endp.h
M include/osmocom/mgcp/mgcp_internal.h
M src/libosmo-mgcp/mgcp_codec.c
M src/libosmo-mgcp/mgcp_conn.c
M src/libosmo-mgcp/mgcp_endp.c
M src/libosmo-mgcp/mgcp_msg.c
M src/libosmo-mgcp/mgcp_network.c
M src/libosmo-mgcp/mgcp_protocol.c
M src/libosmo-mgcp/mgcp_sdp.c
9 files changed, 339 insertions(+), 431 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/73/13773/1

diff --git a/include/osmocom/mgcp/mgcp_endp.h b/include/osmocom/mgcp/mgcp_endp.h
index a23e192..75f093d 100644
--- a/include/osmocom/mgcp/mgcp_endp.h
+++ b/include/osmocom/mgcp/mgcp_endp.h
@@ -99,4 +99,3 @@
 #define ENDPOINT_NUMBER(endp) abs((int)(endp - endp->tcfg->endpoints))
 
 void mgcp_endp_release(struct mgcp_endpoint *endp);
-
diff --git a/include/osmocom/mgcp/mgcp_internal.h b/include/osmocom/mgcp/mgcp_internal.h
index ec94584..3defc4c 100644
--- a/include/osmocom/mgcp/mgcp_internal.h
+++ b/include/osmocom/mgcp/mgcp_internal.h
@@ -335,3 +335,13 @@
 
 void mgcp_get_local_addr(char *addr, struct mgcp_conn_rtp *conn);
 void mgcp_conn_watchdog_kick(struct mgcp_conn *conn);
+
+#define LOGPENDP(endp, cat, level, fmt, args...) \
+LOGP(cat, level, "endpoint:0x%x " fmt, \
+     ENDPOINT_NUMBER(endp), \
+     ## args)
+
+#define LOGPCONN(conn, cat, level, fmt, args...) \
+LOGPENDP((conn)->endp, cat, level, "CI:%s " fmt, \
+         (conn)->id, \
+         ## args)
diff --git a/src/libosmo-mgcp/mgcp_codec.c b/src/libosmo-mgcp/mgcp_codec.c
index 933284d..8bf0564 100644
--- a/src/libosmo-mgcp/mgcp_codec.c
+++ b/src/libosmo-mgcp/mgcp_codec.c
@@ -56,8 +56,8 @@
 	endp = conn->conn->endp;
 
 	if (rtp->codecs_assigned == 0) {
-		LOGP(DLMGCP, LOGL_ERROR, "endpoint:0x%x conn:%s no codecs available\n", ENDPOINT_NUMBER(endp),
-		     mgcp_conn_dump(conn->conn));
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR, "conn:%s no codecs available\n",
+			 mgcp_conn_dump(conn->conn));
 		return;
 	}
 
@@ -65,8 +65,8 @@
 	for (i = 0; i < rtp->codecs_assigned; i++) {
 		codec = &rtp->codecs[i];
 
-		LOGP(DLMGCP, LOGL_DEBUG, "endpoint:0x%x conn:%s codecs[%u]:%s", ENDPOINT_NUMBER(endp),
-		     mgcp_conn_dump(conn->conn), i, dump_codec(codec));
+		LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "conn:%s codecs[%u]:%s",
+			 mgcp_conn_dump(conn->conn), i, dump_codec(codec));
 
 		if (codec == rtp->codec)
 			LOGPC(DLMGCP, LOGL_DEBUG, " [selected]");
diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c
index a8341d6..bfaa111 100644
--- a/src/libosmo-mgcp/mgcp_conn.c
+++ b/src/libosmo-mgcp/mgcp_conn.c
@@ -75,8 +75,7 @@
 		}
 	}
 
-	LOGP(DLMGCP, LOGL_ERROR, "endpoint:0x%x, unable to generate a unique connectionIdentifier\n",
-	     ENDPOINT_NUMBER(endp));
+	LOGPENDP(endp, DLMGCP, LOGL_ERROR, "unable to generate a unique connectionIdentifier\n");
 
 	return -1;
 }
@@ -129,7 +128,7 @@
 void mgcp_conn_watchdog_cb(void *data)
 {
 	struct mgcp_conn *conn = data;
-	LOGP(DLMGCP, LOGL_ERROR, "endpoint:0x%x CI:%s connection timed out!\n", ENDPOINT_NUMBER(conn->endp), conn->id);
+	LOGPCONN(conn, DLMGCP, LOGL_ERROR, "connection timed out!\n");
 	mgcp_conn_free(conn->endp, conn->id);
 }
 
@@ -139,7 +138,7 @@
 	if (!timeout)
 		return;
 
-	LOGP(DLMGCP, LOGL_DEBUG, "endpoint:0x%x CI:%s watchdog kicked\n", ENDPOINT_NUMBER(conn->endp), conn->id);
+	LOGPCONN(conn, DLMGCP, LOGL_DEBUG, "watchdog kicked\n");
 	osmo_timer_schedule(&conn->watchdog, timeout, 0);
 }
 
diff --git a/src/libosmo-mgcp/mgcp_endp.c b/src/libosmo-mgcp/mgcp_endp.c
index fa2dd28..eec46bf 100644
--- a/src/libosmo-mgcp/mgcp_endp.c
+++ b/src/libosmo-mgcp/mgcp_endp.c
@@ -36,8 +36,7 @@
  *  \param[in] endp endpoint to release */
 void mgcp_endp_release(struct mgcp_endpoint *endp)
 {
-	LOGP(DLMGCP, LOGL_DEBUG, "Releasing endpoint:0x%x\n",
-	     ENDPOINT_NUMBER(endp));
+	LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "Releasing endpoint\n");
 
 	/* Normally this function should only be called when
 	 * all connections have been removed already. In case
diff --git a/src/libosmo-mgcp/mgcp_msg.c b/src/libosmo-mgcp/mgcp_msg.c
index 5844d41..5dae5a2 100644
--- a/src/libosmo-mgcp/mgcp_msg.c
+++ b/src/libosmo-mgcp/mgcp_msg.c
@@ -82,9 +82,8 @@
 	int ret = 0;
 
 	if (!mode) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "endpoint:0x%x missing connection mode\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPCONN(conn, DLMGCP, LOGL_ERROR,
+			 "missing connection mode\n");
 		return -1;
 	}
 	if (!conn)
@@ -101,9 +100,8 @@
 	else if (strcmp(mode, "loopback") == 0)
 		conn->mode = MGCP_CONN_LOOPBACK;
 	else {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "endpoint:0x%x unknown connection mode: '%s'\n",
-		     ENDPOINT_NUMBER(endp), mode);
+		LOGPCONN(conn, DLMGCP, LOGL_ERROR,
+			 "unknown connection mode: '%s'\n", mode);
 		ret = -1;
 	}
 
@@ -113,18 +111,15 @@
 		    conn->mode & MGCP_CONN_SEND_ONLY ? 1 : 0;
 	}
 
-	LOGP(DLMGCP, LOGL_DEBUG,
-	     "endpoint:0x%x conn:%s\n",
-	     ENDPOINT_NUMBER(endp), mgcp_conn_dump(conn));
+	LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "conn:%s\n", mgcp_conn_dump(conn));
 
-	LOGP(DLMGCP, LOGL_DEBUG,
-	     "endpoint:0x%x connection mode '%s' %d\n",
-	     ENDPOINT_NUMBER(endp), mode, conn->mode);
+	LOGPCONN(conn, DLMGCP, LOGL_DEBUG, "connection mode '%s' %d\n",
+		 mode, conn->mode);
 
 	/* Special handling für RTP connections */
 	if (conn->type == MGCP_CONN_TYPE_RTP) {
-		LOGP(DLMGCP, LOGL_DEBUG, "endpoint:0x%x output_enabled %d\n",
-		     ENDPOINT_NUMBER(endp), conn->u.rtp.end.output_enabled);
+		LOGPCONN(conn, DLMGCP, LOGL_DEBUG, "output_enabled %d\n",
+			 conn->u.rtp.end.output_enabled);
 	}
 
 	/* The VTY might change the connection mode at any time, so we have
@@ -197,9 +192,8 @@
 	for (i = 0; i < number_endpoints; i++) {
 		if (endpoints[i].callid == NULL) {
 			endp = &endpoints[i];
-			LOGP(DLMGCP, LOGL_DEBUG,
-			     "endpoint:0x%x found free endpoint\n",
-			     ENDPOINT_NUMBER(endp));
+			LOGPENDP(endp, DLMGCP, LOGL_DEBUG,
+			     "found free endpoint\n");
 			endp->wildcarded_req = true;
 			return endp;
 		}
@@ -422,9 +416,9 @@
 		return -1;
 
 	if (strcmp(endp->callid, callid) != 0) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "endpoint:0x%x CallIDs mismatch: '%s' != '%s'\n",
-		     ENDPOINT_NUMBER(endp), endp->callid, callid);
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+			 "CallIDs mismatch: '%s' != '%s'\n",
+			 endp->callid, callid);
 		return -1;
 	}
 
@@ -443,25 +437,23 @@
 
 	/* Check for null identifiers */
 	if (!conn_id) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "endpoint:0x%x invalid ConnectionIdentifier (missing)\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+			 "invalid ConnectionIdentifier (missing)\n");
 		return 510;
 	}
 
 	/* Check for empty connection identifiers */
 	if (strlen(conn_id) == 0) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "endpoint:0x%x invalid ConnectionIdentifier (empty)\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+			 "invalid ConnectionIdentifier (empty)\n");
 		return 510;
 	}
 
 	/* Check for over long connection identifiers */
 	if (strlen(conn_id) > (MGCP_CONN_ID_MAXLEN-1)) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "endpoint:0x%x invalid ConnectionIdentifier (too long: %zu > %d) 0x%s\n",
-		     ENDPOINT_NUMBER(endp), strlen(conn_id), MGCP_CONN_ID_MAXLEN-1, conn_id);
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+			"invalid ConnectionIdentifier (too long: %zu > %d) 0x%s\n",
+			 strlen(conn_id), MGCP_CONN_ID_MAXLEN-1, conn_id);
 		return 510;
 	}
 
@@ -469,9 +461,8 @@
 	if (mgcp_conn_get(endp, conn_id))
 		return 0;
 
-	LOGP(DLMGCP, LOGL_ERROR,
-	     "endpoint:0x%x no connection found under ConnectionIdentifier 0x%s\n",
-	     ENDPOINT_NUMBER(endp), conn_id);
+	LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+	     "no connection found under ConnectionIdentifier 0x%s\n", conn_id);
 
 	/* When the conn_id was not found, return error code 515 "The transaction refers to an incorrect
 	 * connection-id (may have been already deleted)." */
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index 2c6c571..4d92051 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -76,14 +76,12 @@
 	if (endp->cfg->net_ports.bind_addr_probe && conn->end.addr.s_addr != 0) {
 		rc = osmo_sock_local_ip(addr, inet_ntoa(conn->end.addr));
 		if (rc < 0)
-			LOGP(DRTP, LOGL_ERROR,
-			     "endpoint:0x%x CI:%s local interface auto detection failed, using configured addresses...\n",
-			     ENDPOINT_NUMBER(endp), conn->conn->id);
+			LOGPCONN(conn->conn, DRTP, LOGL_ERROR,
+				 "local interface auto detection failed, using configured addresses...\n");
 		else {
-			LOGP(DRTP, LOGL_DEBUG,
-			     "endpoint:0x%x CI:%s selected local rtp bind ip %s by probing using remote ip %s\n",
-			     ENDPOINT_NUMBER(endp), conn->conn->id, addr,
-			     inet_ntoa(conn->end.addr));
+			LOGPCONN(conn->conn, DRTP, LOGL_DEBUG,
+				 "selected local rtp bind ip %s by probing using remote ip %s\n",
+				 addr, inet_ntoa(conn->end.addr));
 			return;
 		}
 	}
@@ -93,17 +91,16 @@
 		/* Check there is a bind IP for the RTP traffic configured,
 		 * if so, use that IP-Address */
 		osmo_strlcpy(addr, endp->cfg->net_ports.bind_addr, INET_ADDRSTRLEN);
-		LOGP(DRTP, LOGL_DEBUG,
-		     "endpoint:0x%x CI:%s using configured rtp bind ip as local bind ip %s\n",
-		     ENDPOINT_NUMBER(endp), conn->conn->id, addr);
+		LOGPCONN(conn->conn, DRTP, LOGL_DEBUG,
+			 "using configured rtp bind ip as local bind ip %s\n",
+			 addr);
 	} else {
 		/* No specific bind IP is configured for the RTP traffic, so
 		 * assume the IP where we listen for incoming MGCP messages
 		 * as bind IP */
 		osmo_strlcpy(addr, endp->cfg->source_addr, INET_ADDRSTRLEN);
-		LOGP(DRTP, LOGL_DEBUG,
-		     "endpoint:0x%x CI:%s using mgcp bind ip as local rtp bind ip: %s\n",
-		     ENDPOINT_NUMBER(endp), conn->conn->id, addr);
+		LOGPCONN(conn->conn, DRTP, LOGL_DEBUG,
+			"using mgcp bind ip as local rtp bind ip: %s\n", addr);
 	}
 }
 
@@ -165,10 +162,8 @@
 	OSMO_ASSERT(endp);
 	OSMO_ASSERT(conn);
 
-	LOGP(DRTP, LOGL_DEBUG,
-	     "endpoint:0x%x sending dummy packet...\n", ENDPOINT_NUMBER(endp));
-	LOGP(DRTP, LOGL_DEBUG, "endpoint:0x%x conn:%s\n",
-	     ENDPOINT_NUMBER(endp), mgcp_conn_dump(conn->conn));
+	LOGPCONN(conn->conn, DRTP, LOGL_DEBUG,"sending dummy packet... %s\n",
+		 mgcp_conn_dump(conn->conn));
 
 	rc = mgcp_udp_send(conn->end.rtp.fd, &conn->end.addr,
 			   conn->end.rtp_port, buf, 1);
@@ -187,9 +182,9 @@
 		return rc;
 
 failed:
-	LOGP(DRTP, LOGL_ERROR,
-	     "endpoint:0x%x Failed to send dummy %s packet.\n",
-	     ENDPOINT_NUMBER(endp), was_rtcp ? "RTCP" : "RTP");
+	LOGPCONN(conn->conn, DRTP, LOGL_ERROR,
+		 "Failed to send dummy %s packet.\n",
+		 was_rtcp ? "RTCP" : "RTP");
 
 	return -1;
 }
@@ -228,16 +223,16 @@
 	if (seq == sstate->last_seq) {
 		if (timestamp != sstate->last_timestamp) {
 			rate_ctr_inc(sstate->err_ts_ctr);
-			LOGP(DRTP, LOGL_ERROR,
-			     "The %s timestamp delta is != 0 but the sequence "
-			     "number %d is the same, "
-			     "TS offset: %d, SeqNo offset: %d "
-			     "on 0x%x SSRC: %u timestamp: %u "
-			     "from %s:%d\n",
-			     text, seq,
-			     state->patch.timestamp_offset, state->patch.seq_offset,
-			     ENDPOINT_NUMBER(endp), sstate->ssrc, timestamp,
-			     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
+			LOGPENDP(endp, DRTP, LOGL_ERROR,
+				 "The %s timestamp delta is != 0 but the sequence "
+				 "number %d is the same, "
+				 "TS offset: %d, SeqNo offset: %d "
+				 "on SSRC: %u timestamp: %u "
+				 "from %s:%d\n",
+				 text, seq,
+				 state->patch.timestamp_offset, state->patch.seq_offset,
+				 sstate->ssrc, timestamp, inet_ntoa(addr->sin_addr),
+				 ntohs(addr->sin_port));
 		}
 		return 0;
 	}
@@ -248,25 +243,25 @@
 
 	if (tsdelta == 0) {
 		/* Don't update *tsdelta_out */
-		LOGP(DRTP, LOGL_NOTICE,
-		     "The %s timestamp delta is %d "
-		     "on 0x%x SSRC: %u timestamp: %u "
-		     "from %s:%d\n",
-		     text, tsdelta,
-		     ENDPOINT_NUMBER(endp), sstate->ssrc, timestamp,
-		     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
+		LOGPENDP(endp, DRTP, LOGL_NOTICE,
+			 "The %s timestamp delta is %d "
+			 "on SSRC: %u timestamp: %u "
+			 "from %s:%d\n",
+			 text, tsdelta,
+			 sstate->ssrc, timestamp,
+			 inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 
 		return 0;
 	}
 
 	if (sstate->last_tsdelta != tsdelta) {
 		if (sstate->last_tsdelta) {
-			LOGP(DRTP, LOGL_INFO,
-			     "The %s timestamp delta changes from %d to %d "
-			     "on 0x%x SSRC: %u timestamp: %u from %s:%d\n",
-			     text, sstate->last_tsdelta, tsdelta,
-			     ENDPOINT_NUMBER(endp), sstate->ssrc, timestamp,
-			     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
+			LOGPENDP(endp, DRTP, LOGL_INFO,
+				 "The %s timestamp delta changes from %d to %d "
+				 "on SSRC: %u timestamp: %u from %s:%d\n",
+				 text, sstate->last_tsdelta, tsdelta,
+				 sstate->ssrc, timestamp,
+				 inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 		}
 	}
 
@@ -278,18 +273,18 @@
 
 	if (timestamp_error) {
 		rate_ctr_inc(sstate->err_ts_ctr);
-		LOGP(DRTP, LOGL_NOTICE,
-		     "The %s timestamp has an alignment error of %d "
-		     "on 0x%x SSRC: %u "
-		     "SeqNo delta: %d, TS delta: %d, dTS/dSeq: %d "
-		     "from %s:%d. ptime: %d\n",
-		     text, timestamp_error,
-		     ENDPOINT_NUMBER(endp), sstate->ssrc,
-		     (int16_t)(seq - sstate->last_seq),
-		     (int32_t)(timestamp - sstate->last_timestamp),
-		     tsdelta,
-		     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port),
-		     state->packet_duration);
+		LOGPENDP(endp, DRTP, LOGL_NOTICE,
+			 "The %s timestamp has an alignment error of %d "
+			 "on SSRC: %u "
+			 "SeqNo delta: %d, TS delta: %d, dTS/dSeq: %d "
+			 "from %s:%d. ptime: %d\n",
+			 text, timestamp_error,
+			 sstate->ssrc,
+			 (int16_t)(seq - sstate->last_seq),
+			 (int32_t)(timestamp - sstate->last_timestamp),
+			 tsdelta,
+			 inet_ntoa(addr->sin_addr), ntohs(addr->sin_port),
+			 state->packet_duration);
 	}
 	return 1;
 }
@@ -308,21 +303,19 @@
 	if (tsdelta == 0) {
 		tsdelta = state->out_stream.last_tsdelta;
 		if (tsdelta != 0) {
-			LOGP(DRTP, LOGL_NOTICE,
-			     "A fixed packet duration is not available on 0x%x, "
-			     "using last output timestamp delta instead: %d "
-			     "from %s:%d\n",
-			     ENDPOINT_NUMBER(endp), tsdelta,
-			     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
+			LOGPENDP(endp, DRTP, LOGL_NOTICE,
+				 "A fixed packet duration is not available, "
+				 "using last output timestamp delta instead: %d "
+				 "from %s:%d\n", tsdelta,
+				 inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 		} else {
 			tsdelta = rtp_end->codec->rate * 20 / 1000;
-			LOGP(DRTP, LOGL_NOTICE,
-			     "Fixed packet duration and last timestamp delta "
-			     "are not available on 0x%x, "
-			     "using fixed 20ms instead: %d "
-			     "from %s:%d\n",
-			     ENDPOINT_NUMBER(endp), tsdelta,
-			     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
+			LOGPENDP(endp, DRTP, LOGL_NOTICE,
+				 "Fixed packet duration and last timestamp delta "
+				 "are not available, "
+				 "using fixed 20ms instead: %d "
+				 "from %s:%d\n", tsdelta,
+				 inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 		}
 	}
 
@@ -332,13 +325,12 @@
 	if (state->patch.timestamp_offset != timestamp_offset) {
 		state->patch.timestamp_offset = timestamp_offset;
 
-		LOGP(DRTP, LOGL_NOTICE,
-		     "Timestamp offset change on 0x%x SSRC: %u "
-		     "SeqNo delta: %d, TS offset: %d, "
-		     "from %s:%d\n",
-		     ENDPOINT_NUMBER(endp), state->in_stream.ssrc,
-		     delta_seq, state->patch.timestamp_offset,
-		     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
+		LOGPENDP(endp, DRTP, LOGL_NOTICE,
+			 "Timestamp offset change on SSRC: %u "
+			 "SeqNo delta: %d, TS offset: %d, "
+			 "from %s:%d\n", state->in_stream.ssrc,
+			 delta_seq, state->patch.timestamp_offset,
+			 inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 	}
 
 	return timestamp_offset;
@@ -364,14 +356,13 @@
 	if (ts_error) {
 		state->patch.timestamp_offset += ptime - ts_error;
 
-		LOGP(DRTP, LOGL_NOTICE,
-		     "Corrected timestamp alignment error of %d on 0x%x SSRC: %u "
-		     "new TS offset: %d, "
-		     "from %s:%d\n",
-		     ts_error,
-		     ENDPOINT_NUMBER(endp), state->in_stream.ssrc,
-		     state->patch.timestamp_offset, inet_ntoa(addr->sin_addr),
-		     ntohs(addr->sin_port));
+		LOGPENDP(endp, DRTP, LOGL_NOTICE,
+			 "Corrected timestamp alignment error of %d on SSRC: %u "
+			 "new TS offset: %d, "
+			 "from %s:%d\n",
+			 ts_error, state->in_stream.ssrc,
+			 state->patch.timestamp_offset, inet_ntoa(addr->sin_addr),
+			 ntohs(addr->sin_port));
 	}
 
 	/* Check we really managed to compensate the timestamp
@@ -397,8 +388,7 @@
 				struct mgcp_rtp_end *dst_end,
 				char *data, int *len, int buf_size)
 {
-	LOGP(DRTP, LOGL_DEBUG, "endpoint:0x%x transcoding disabled\n",
-	     ENDPOINT_NUMBER(endp));
+	LOGPENDP(endp, DRTP, LOGL_DEBUG, "transcoding disabled\n");
 	return 0;
 }
 
@@ -411,8 +401,7 @@
 				      struct mgcp_conn_rtp *conn_dst,
 				      struct mgcp_conn_rtp *conn_src)
 {
-	LOGP(DRTP, LOGL_DEBUG, "endpoint:0x%x transcoding disabled\n",
-	     ENDPOINT_NUMBER(endp));
+	LOGPENDP(endp, DRTP, LOGL_DEBUG, "transcoding disabled\n");
 	return 0;
 }
 
@@ -421,9 +410,8 @@
 					  const char **fmtp_extra,
 					  struct mgcp_conn_rtp *conn)
 {
-	LOGP(DRTP, LOGL_DEBUG,
-	     "endpoint:0x%x conn:%s using format defaults\n",
-	     ENDPOINT_NUMBER(endp), mgcp_conn_dump(conn->conn));
+	LOGPENDP(endp, DRTP, LOGL_DEBUG, "conn:%s using format defaults\n",
+		 mgcp_conn_dump(conn->conn));
 
 	*codec = conn->end.codec;
 	*fmtp_extra = conn->end.fmtp_extra;
@@ -459,9 +447,9 @@
 			if (seq < state->stats.max_seq)
 				state->stats.cycles += RTP_SEQ_MOD;
 		} else if (udelta <= RTP_SEQ_MOD - RTP_MAX_MISORDER) {
-			LOGP(DRTP, LOGL_NOTICE,
-			     "RTP seqno made a very large jump on 0x%x delta: %u\n",
-			     ENDPOINT_NUMBER(endp), udelta);
+			LOGPENDP(endp, DRTP, LOGL_NOTICE,
+				 "RTP seqno made a very large jump on delta: %u\n",
+				 udelta);
 		}
 	}
 
@@ -541,28 +529,27 @@
 		state->out_stream.last_tsdelta = 0;
 		state->out_stream.last_timestamp = timestamp;
 		state->out_stream.ssrc = ssrc - 1;	/* force output SSRC change */
-		LOGP(DRTP, LOGL_INFO,
-		     "endpoint:0x%x initializing stream, SSRC: %u timestamp: %u "
-		     "pkt-duration: %d, from %s:%d\n",
-		     ENDPOINT_NUMBER(endp), state->in_stream.ssrc,
-		     state->patch.seq_offset, state->packet_duration,
-		     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
+		LOGPENDP(endp, DRTP, LOGL_INFO,
+			 "initializing stream, SSRC: %u timestamp: %u "
+			 "pkt-duration: %d, from %s:%d\n",
+			 state->in_stream.ssrc,
+			 state->patch.seq_offset, state->packet_duration,
+			 inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 		if (state->packet_duration == 0) {
 			state->packet_duration =
 			    rtp_end->codec->rate * 20 / 1000;
-			LOGP(DRTP, LOGL_NOTICE,
-			     "endpoint:0x%x fixed packet duration is not available, "
-			     "using fixed 20ms instead: %d from %s:%d\n",
-			     ENDPOINT_NUMBER(endp), state->packet_duration,
-			     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
+			LOGPENDP(endp, DRTP, LOGL_NOTICE,
+				 "fixed packet duration is not available, "
+				 "using fixed 20ms instead: %d from %s:%d\n",
+				 state->packet_duration,
+				 inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 		}
 	} else if (state->in_stream.ssrc != ssrc) {
-		LOGP(DRTP, LOGL_NOTICE,
-		     "endpoint:0x%x SSRC changed: %u -> %u  "
-		     "from %s:%d\n",
-		     ENDPOINT_NUMBER(endp),
-		     state->in_stream.ssrc, rtp_hdr->ssrc,
-		     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
+		LOGPENDP(endp, DRTP, LOGL_NOTICE,
+			 "SSRC changed: %u -> %u  "
+			 "from %s:%d\n",
+			 state->in_stream.ssrc, rtp_hdr->ssrc,
+			 inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 
 		state->in_stream.ssrc = ssrc;
 		if (rtp_end->force_constant_ssrc) {
@@ -586,13 +573,12 @@
 			if (rtp_end->force_constant_ssrc != -1)
 				rtp_end->force_constant_ssrc -= 1;
 
-			LOGP(DRTP, LOGL_NOTICE,
-			     "endpoint:0x%x SSRC patching enabled, SSRC: %u "
-			     "SeqNo offset: %d, TS offset: %d "
-			     "from %s:%d\n",
-			     ENDPOINT_NUMBER(endp), state->in_stream.ssrc,
-			     state->patch.seq_offset, state->patch.timestamp_offset,
-			     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
+			LOGPENDP(endp, DRTP, LOGL_NOTICE,
+				 "SSRC patching enabled, SSRC: %u "
+				 "SeqNo offset: %d, TS offset: %d "
+				 "from %s:%d\n", state->in_stream.ssrc,
+				 state->patch.seq_offset, state->patch.timestamp_offset,
+				 inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 		}
 
 		state->in_stream.last_tsdelta = 0;
@@ -679,9 +665,8 @@
 	} else {
 		/* It is possible that multiple payloads occur in one RTP
 		 * packet. This is not supported yet. */
-		LOGP(DRTP, LOGL_ERROR,
-		     "endpoint:0x%x cannot figure out how to convert RTP packet\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DRTP, LOGL_ERROR,
+			 "cannot figure out how to convert RTP packet\n");
 	}
 }
 
@@ -726,9 +711,8 @@
 			rc = payload_len;
 	}
 	if (rc < 0) {
-		LOGP(DRTP, LOGL_ERROR,
-		     "endpoint:0x%x AMR RTP packet conversion failed\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DRTP, LOGL_ERROR,
+			 "AMR RTP packet conversion failed\n");
 		return -EINVAL;
 	}
 
@@ -810,19 +794,14 @@
 	OSMO_ASSERT(conn_dst);
 
 	if (is_rtp) {
-		LOGP(DRTP, LOGL_DEBUG,
-		     "endpoint:0x%x delivering RTP packet...\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DRTP, LOGL_DEBUG, "delivering RTP packet...\n");
 	} else {
-		LOGP(DRTP, LOGL_DEBUG,
-		     "endpoint:0x%x delivering RTCP packet...\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DRTP, LOGL_DEBUG, "delivering RTCP packet...\n");
 	}
 
-	LOGP(DRTP, LOGL_DEBUG,
-	     "endpoint:0x%x loop:%d, mode:%d%s\n",
-	     ENDPOINT_NUMBER(endp), tcfg->audio_loop, conn_src->conn->mode,
-	     conn_src->conn->mode == MGCP_CONN_LOOPBACK ? " (loopback)" : "");
+	LOGPENDP(endp, DRTP, LOGL_DEBUG, "loop:%d, mode:%d%s\n",
+		 tcfg->audio_loop, conn_src->conn->mode,
+		 conn_src->conn->mode == MGCP_CONN_LOOPBACK ? " (loopback)" : "");
 
 	/* FIXME: It is legal that the payload type on the egress connection is
 	 * different from the payload type that has been negotiated on the
@@ -835,9 +814,8 @@
 	if (is_rtp) {
 		rc = mgcp_patch_pt(conn_src, conn_dst, buf, len);
 		if (rc < 0) {
-			LOGP(DRTP, LOGL_DEBUG,
-			     "endpoint:0x%x can not patch PT because no suitable egress codec was found.\n",
-			     ENDPOINT_NUMBER(endp));
+			LOGPENDP(endp, DRTP, LOGL_DEBUG,
+				 "can not patch PT because no suitable egress codec was found.\n");
 		}
 	}
 
@@ -849,13 +827,12 @@
 
 	if (!rtp_end->output_enabled) {
 		rate_ctr_inc(&conn_dst->rate_ctr_group->ctr[RTP_DROPPED_PACKETS_CTR]);
-		LOGP(DRTP, LOGL_DEBUG,
-		     "endpoint:0x%x output disabled, drop to %s %s "
-		     "rtp_port:%u rtcp_port:%u\n",
-		     ENDPOINT_NUMBER(endp),
-		     dest_name,
-		     inet_ntoa(rtp_end->addr),
-		     ntohs(rtp_end->rtp_port), ntohs(rtp_end->rtcp_port)
+		LOGPENDP(endp, DRTP, LOGL_DEBUG,
+			 "output disabled, drop to %s %s "
+			 "rtp_port:%u rtcp_port:%u\n",
+			 dest_name,
+			 inet_ntoa(rtp_end->addr),
+			 ntohs(rtp_end->rtp_port), ntohs(rtp_end->rtcp_port)
 		    );
 	} else if (is_rtp) {
 		int cont;
@@ -882,13 +859,12 @@
 				      "GSM-HR-08") == 0)
 				rfc5993_hr_convert(endp, buf, &buflen);
 
-			LOGP(DRTP, LOGL_DEBUG,
-			     "endpoint:0x%x process/send to %s %s "
-			     "rtp_port:%u rtcp_port:%u\n",
-			     ENDPOINT_NUMBER(endp), dest_name,
-			     inet_ntoa(rtp_end->addr), ntohs(rtp_end->rtp_port),
-			     ntohs(rtp_end->rtcp_port)
-			    );
+			LOGPENDP(endp, DRTP, LOGL_DEBUG,
+				 "process/send to %s %s "
+				 "rtp_port:%u rtcp_port:%u\n",
+				 dest_name, inet_ntoa(rtp_end->addr),
+				 ntohs(rtp_end->rtp_port), ntohs(rtp_end->rtcp_port)
+				);
 
 			/* Forward a copy of the RTP data to a debug ip/port */
 			forward_data(rtp_end->rtp.fd, &conn_src->tap_out,
@@ -906,10 +882,9 @@
 					data[0] = 0xe4;
 					data[1] = 0x00;
 					rtp_state->patched_first_rtp_payload = true;
-					LOGP(DRTP, LOGL_DEBUG,
-					     "endpoint:0x%x Patching over first two bytes"
-					     " to fake an IuUP Initialization Ack\n",
-					     ENDPOINT_NUMBER(endp));
+					LOGPENDP(endp, DRTP, LOGL_DEBUG,
+						 "Patching over first two bytes"
+						 " to fake an IuUP Initialization Ack\n");
 				}
 			}
 
@@ -928,13 +903,11 @@
 		} while (buflen > 0);
 		return nbytes;
 	} else if (!tcfg->omit_rtcp) {
-		LOGP(DRTP, LOGL_DEBUG,
-		     "endpoint:0x%x send to %s %s rtp_port:%u rtcp_port:%u\n",
-		     ENDPOINT_NUMBER(endp),
-		     dest_name,
-		     inet_ntoa(rtp_end->addr),
-		     ntohs(rtp_end->rtp_port), ntohs(rtp_end->rtcp_port)
-		    );
+		LOGPENDP(endp, DRTP, LOGL_DEBUG,
+			 "send to %s %s rtp_port:%u rtcp_port:%u\n",
+			 dest_name, inet_ntoa(rtp_end->addr),
+			 ntohs(rtp_end->rtp_port), ntohs(rtp_end->rtcp_port)
+			);
 
 		len = mgcp_udp_send(rtp_end->rtcp.fd,
 				    &rtp_end->addr,
@@ -970,20 +943,19 @@
 
 	rc = recvfrom(fd, buf, bufsize, 0, (struct sockaddr *)addr, &slen);
 
-	LOGP(DRTP, LOGL_DEBUG,
+	LOGPENDP(endp, DRTP, LOGL_DEBUG,
 	     "receiving %u bytes length packet from %s:%u ...\n",
 	     rc, inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 
 	if (rc < 0) {
-		LOGP(DRTP, LOGL_ERROR,
-		     "endpoint:0x%x failed to receive packet, errno: %d/%s\n",
-		     ENDPOINT_NUMBER(endp), errno, strerror(errno));
+		LOGPENDP(endp, DRTP, LOGL_ERROR,
+			 "failed to receive packet, errno: %d/%s\n",
+			 errno, strerror(errno));
 		return -1;
 	}
 
 	if (tossed) {
-		LOGP(DRTP, LOGL_ERROR, "endpoint:0x%x packet tossed\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DRTP, LOGL_ERROR, "packet tossed\n");
 	}
 
 	return rc;
@@ -994,9 +966,6 @@
 static int check_rtp_origin(struct mgcp_conn_rtp *conn,
 			    struct sockaddr_in *addr)
 {
-	struct mgcp_endpoint *endp;
-	endp = conn->conn->endp;
-
 	if (conn->end.addr.s_addr == 0) {
 		switch (conn->conn->mode) {
 		case MGCP_CONN_LOOPBACK:
@@ -1007,20 +976,18 @@
 			 * Response is received, but the nano3G expects an IuUP Initialization Ack before it even
 			 * sends the RAB Assignment Response. Hence, if the remote address is 0.0.0.0 and the
 			 * MGCP port is in loopback mode, allow looping back the packet to any source. */
-			LOGP(DRTP, LOGL_ERROR,
-			     "endpoint:0x%x In loopback mode and remote address not set:"
-			     " allowing data from address: %s\n",
-			     ENDPOINT_NUMBER(endp), inet_ntoa(addr->sin_addr));
+			LOGPCONN(conn->conn, DRTP, LOGL_ERROR,
+				 "In loopback mode and remote address not set:"
+				 " allowing data from address: %s\n", inet_ntoa(addr->sin_addr));
 			return 0;
 
 		default:
 			/* Receiving early media before the endpoint is configured. Instead of logging
 			 * this as an error that occurs on every call, keep it more low profile to not
 			 * confuse humans with expected errors. */
-			LOGP(DRTP, LOGL_INFO,
-			     "endpoint:0x%x I:%s Rx RTP from %s, but remote address not set:"
-			     " dropping early media\n",
-			     ENDPOINT_NUMBER(endp), conn->conn->id, inet_ntoa(addr->sin_addr));
+			LOGPCONN(conn->conn, DRTP, LOGL_INFO,
+				 "Rx RTP from %s, but remote address not set:"
+				 " dropping early media\n", inet_ntoa(addr->sin_addr));
 			return -1;
 		}
 	}
@@ -1028,13 +995,11 @@
 	/* Note: Check if the inbound RTP data comes from the same host to
 	 * which we send our outgoing RTP traffic. */
 	if (conn->end.addr.s_addr != addr->sin_addr.s_addr) {
-		LOGP(DRTP, LOGL_ERROR,
-		     "endpoint:0x%x data from wrong address: %s, ",
-		     ENDPOINT_NUMBER(endp), inet_ntoa(addr->sin_addr));
+		LOGPCONN(conn->conn, DRTP, LOGL_ERROR,
+			 "data from wrong address: %s, ", inet_ntoa(addr->sin_addr));
 		LOGPC(DRTP, LOGL_ERROR, "expected: %s\n",
 		      inet_ntoa(conn->end.addr));
-		LOGP(DRTP, LOGL_ERROR, "endpoint:0x%x packet tossed\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPCONN(conn->conn, DRTP, LOGL_ERROR, "packet tossed\n");
 		return -1;
 	}
 
@@ -1044,14 +1009,12 @@
 	 * plausibility. */
 	if (conn->end.rtp_port != addr->sin_port &&
 	    conn->end.rtcp_port != addr->sin_port) {
-		LOGP(DRTP, LOGL_ERROR,
-		     "endpoint:0x%x data from wrong source port: %d, ",
-		     ENDPOINT_NUMBER(endp), ntohs(addr->sin_port));
+		LOGPCONN(conn->conn, DRTP, LOGL_ERROR,
+			 "data from wrong source port: %d, ", ntohs(addr->sin_port));
 		LOGPC(DRTP, LOGL_ERROR,
 		      "expected: %d for RTP or %d for RTCP\n",
 		      ntohs(conn->end.rtp_port), ntohs(conn->end.rtcp_port));
-		LOGP(DRTP, LOGL_ERROR, "endpoint:0x%x packet tossed\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPCONN(conn->conn, DRTP, LOGL_ERROR, "packet tossed\n");
 		return -1;
 	}
 
@@ -1062,29 +1025,26 @@
  * makes sense */
 static int check_rtp_destin(struct mgcp_conn_rtp *conn)
 {
-	struct mgcp_endpoint *endp;
-	endp = conn->conn->endp;
-
 	/* Note: it is legal to create a connection but never setting a port
 	 * and IP-address for outgoing data. */
 	if (strcmp(inet_ntoa(conn->end.addr), "0.0.0.0") == 0 && conn->end.rtp_port == 0) {
-		LOGP(DRTP, LOGL_DEBUG,
-		     "endpoint:0x%x destination IP-address and rtp port is (not yet) known (%s:%u)\n",
-		     ENDPOINT_NUMBER(endp), inet_ntoa(conn->end.addr), conn->end.rtp_port);
+		LOGPCONN(conn->conn, DRTP, LOGL_DEBUG,
+			 "destination IP-address and rtp port is (not yet) known (%s:%u)\n",
+			 inet_ntoa(conn->end.addr), conn->end.rtp_port);
 		return -1;
 	}
 
 	if (strcmp(inet_ntoa(conn->end.addr), "0.0.0.0") == 0) {
-		LOGP(DRTP, LOGL_ERROR,
-		     "endpoint:0x%x destination IP-address is invalid (%s:%u)\n",
-		     ENDPOINT_NUMBER(endp), inet_ntoa(conn->end.addr), conn->end.rtp_port);
+		LOGPCONN(conn->conn, DRTP, LOGL_ERROR,
+			 "destination IP-address is invalid (%s:%u)\n",
+			 inet_ntoa(conn->end.addr), conn->end.rtp_port);
 		return -1;
 	}
 
 	if (conn->end.rtp_port == 0) {
-		LOGP(DRTP, LOGL_ERROR,
-		     "endpoint:0x%x destination rtp port is invalid (%s:%u)\n",
-		     ENDPOINT_NUMBER(endp), inet_ntoa(conn->end.addr), conn->end.rtp_port);
+		LOGPCONN(conn->conn, DRTP, LOGL_ERROR,
+			 "destination rtp port is invalid (%s:%u)\n",
+			 inet_ntoa(conn->end.addr), conn->end.rtp_port);
 		return -1;
 	}
 
@@ -1152,8 +1112,7 @@
 	endp = conn->conn->endp;
 	tcfg = endp->tcfg;
 
-	LOGP(DRTP, LOGL_DEBUG, "endpoint:0x%x receiving RTP/RTCP packet...\n",
-	     ENDPOINT_NUMBER(endp));
+	LOGPCONN(conn->conn, DRTP, LOGL_DEBUG, "receiving RTP/RTCP packet...\n");
 
 	rc = receive_from(endp, fd->fd, addr, buf, buf_size);
 	if (rc <= 0)
@@ -1167,26 +1126,23 @@
 
 	if (*proto == MGCP_PROTO_RTP) {
 		if (check_rtp(buf, rc) < 0) {
-			LOGP(DRTP, LOGL_ERROR,
-			     "endpoint:0x%x invalid RTP packet received -- packet tossed\n",
-			     ENDPOINT_NUMBER(endp));
+			LOGPCONN(conn->conn, DRTP, LOGL_ERROR,
+				 "invalid RTP packet received -- packet tossed\n");
 			return -1;
 		}
 	} else if (*proto == MGCP_PROTO_RTCP) {
 		if (check_rtcp(buf, rc) < 0) {
-			LOGP(DRTP, LOGL_ERROR,
-			     "endpoint:0x%x invalid RTCP packet received -- packet tossed\n",
-			     ENDPOINT_NUMBER(endp));
+			LOGPCONN(conn->conn, DRTP, LOGL_ERROR,
+				 "invalid RTCP packet received -- packet tossed\n");
 			return -1;
 		}
 	}
 
-	LOGP(DRTP, LOGL_DEBUG, "endpoint:0x%x ", ENDPOINT_NUMBER(endp));
+	LOGPCONN(conn->conn, DRTP, LOGL_DEBUG, "");
 	LOGPC(DRTP, LOGL_DEBUG, "receiving from %s %s %d\n",
 	      conn->conn->name, inet_ntoa(addr->sin_addr),
 	      ntohs(addr->sin_port));
-	LOGP(DRTP, LOGL_DEBUG, "endpoint:0x%x conn:%s\n", ENDPOINT_NUMBER(endp),
-	     mgcp_conn_dump(conn->conn));
+	LOGPENDP(endp, DRTP, LOGL_DEBUG, "conn:%s\n", mgcp_conn_dump(conn->conn));
 
 	/* Check if the origin of the RTP packet seems plausible */
 	if (tcfg->rtp_accept_all == 0) {
@@ -1196,11 +1152,10 @@
 
 	/* Filter out dummy message */
 	if (rc == 1 && buf[0] == MGCP_DUMMY_LOAD) {
-		LOGP(DRTP, LOGL_NOTICE,
-		     "endpoint:0x%x dummy message received\n",
-		     ENDPOINT_NUMBER(endp));
-		LOGP(DRTP, LOGL_ERROR,
-		     "endpoint:0x%x packet tossed\n", ENDPOINT_NUMBER(endp));
+		LOGPCONN(conn->conn, DRTP, LOGL_NOTICE,
+			 "dummy message received\n");
+		LOGPCONN(conn->conn, DRTP, LOGL_ERROR,
+			 "packet tossed\n");
 		return 0;
 	}
 
@@ -1224,8 +1179,8 @@
 	struct mgcp_endpoint *endp;
 	endp = conn_src->conn->endp;
 
-	LOGP(DRTP, LOGL_DEBUG, "endpoint:0x%x destin conn:%s\n",
-	     ENDPOINT_NUMBER(endp), mgcp_conn_dump(conn_dst->conn));
+	LOGPENDP(endp, DRTP, LOGL_DEBUG, "destin conn:%s\n",
+		 mgcp_conn_dump(conn_dst->conn));
 
 	/* Before we try to deliver the packet, we check if the destination
 	 * port and IP-Address make sense at all. If not, we will be unable
@@ -1237,27 +1192,23 @@
 	 * destination connection. */
 	switch (conn_dst->type) {
 	case MGCP_RTP_DEFAULT:
-		LOGP(DRTP, LOGL_DEBUG,
-		     "endpoint:0x%x endpoint type is MGCP_RTP_DEFAULT, "
-		     "using mgcp_send() to forward data directly\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DRTP, LOGL_DEBUG,
+			 "endpoint type is MGCP_RTP_DEFAULT, "
+			 "using mgcp_send() to forward data directly\n");
 		return mgcp_send(endp, proto == MGCP_PROTO_RTP,
 				 addr, buf, buf_size, conn_src, conn_dst);
 	case MGCP_OSMUX_BSC_NAT:
 	case MGCP_OSMUX_BSC:
-		LOGP(DRTP, LOGL_DEBUG,
-		     "endpoint:0x%x endpoint type is MGCP_OSMUX_BSC_NAT, "
-		     "using osmux_xfrm_to_osmux() to forward data through OSMUX\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DRTP, LOGL_DEBUG,
+			 "endpoint type is MGCP_OSMUX_BSC_NAT, "
+			 "using osmux_xfrm_to_osmux() to forward data through OSMUX\n");
 		return osmux_xfrm_to_osmux(buf, buf_size, conn_dst);
 	}
 
 	/* If the data has not been handled/forwarded until here, it will
 	 * be discarded, this should not happen, normally the MGCP type
 	 * should be properly set */
-	LOGP(DRTP, LOGL_ERROR,
-	     "endpoint:0x%x bad MGCP type -- data discarded!\n",
-	     ENDPOINT_NUMBER(endp));
+	LOGPENDP(endp, DRTP, LOGL_ERROR, "bad MGCP type -- data discarded!\n");
 
 	return -1;
 }
@@ -1273,8 +1224,6 @@
 				unsigned int buf_size, struct mgcp_conn *conn)
 {
 	struct mgcp_conn *conn_dst;
-	struct mgcp_endpoint *endp;
-	endp = conn->endp;
 
 	/*! NOTE: This callback function implements the endpoint specific
 	 *  dispatch bahviour of an rtp bridge/proxy endpoint. It is assumed
@@ -1300,17 +1249,15 @@
 
 	/* There is no destination conn, stop here */
 	if (!conn_dst) {
-		LOGP(DRTP, LOGL_ERROR,
-		     "endpoint:0x%x unable to find destination conn\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPCONN(conn, DRTP, LOGL_ERROR,
+			 "unable to find destination conn\n");
 		return -1;
 	}
 
 	/* The destination conn is not an RTP connection */
 	if (conn_dst->type != MGCP_CONN_TYPE_RTP) {
-		LOGP(DRTP, LOGL_ERROR,
-		     "endpoint:0x%x unable to find suitable destination conn\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPCONN(conn, DRTP, LOGL_ERROR,
+			 "unable to find suitable destination conn\n");
 		return -1;
 	}
 
@@ -1362,8 +1309,8 @@
 	endp = conn_src->conn->endp;
 	OSMO_ASSERT(endp);
 
-	LOGP(DRTP, LOGL_DEBUG, "endpoint:0x%x source conn:%s\n",
-	     ENDPOINT_NUMBER(endp), mgcp_conn_dump(conn_src->conn));
+	LOGPENDP(endp, DRTP, LOGL_DEBUG, "source conn:%s\n",
+		 mgcp_conn_dump(conn_src->conn));
 
 	/* Receive packet */
 	len = mgcp_recv(&proto, &addr, buf, sizeof(buf), fd);
@@ -1444,20 +1391,21 @@
 {
 	/* NOTE: The port that is used for RTCP is the RTP port incremented by one
 	 * (e.g. RTP-Port = 16000 ==> RTCP-Port = 16001) */
+	 struct mgcp_endpoint *endp = &cfg->trunk.endpoints[endpno];
 
 	if (mgcp_create_bind(source_addr, &rtp_end->rtp,
 			     rtp_end->local_port) != 0) {
-		LOGP(DRTP, LOGL_ERROR,
-		     "endpoint:0x%x failed to create RTP port: %s:%d\n", endpno,
-		     source_addr, rtp_end->local_port);
+		LOGPENDP(endp, DRTP, LOGL_ERROR,
+			 "failed to create RTP port: %s:%d\n",
+			 source_addr, rtp_end->local_port);
 		goto cleanup0;
 	}
 
 	if (mgcp_create_bind(source_addr, &rtp_end->rtcp,
 			     rtp_end->local_port + 1) != 0) {
-		LOGP(DRTP, LOGL_ERROR,
-		     "endpoint:0x%x failed to create RTCP port: %s:%d\n", endpno,
-		     source_addr, rtp_end->local_port + 1);
+		LOGPENDP(endp, DRTP, LOGL_ERROR,
+			 "failed to create RTCP port: %s:%d\n",
+			 source_addr, rtp_end->local_port + 1);
 		goto cleanup1;
 	}
 
@@ -1467,17 +1415,17 @@
 
 	rtp_end->rtp.when = BSC_FD_READ;
 	if (osmo_fd_register(&rtp_end->rtp) != 0) {
-		LOGP(DRTP, LOGL_ERROR,
-		     "endpoint:0x%x failed to register RTP port %d\n", endpno,
-		     rtp_end->local_port);
+		LOGPENDP(endp, DRTP, LOGL_ERROR,
+			 "failed to register RTP port %d\n",
+			 rtp_end->local_port);
 		goto cleanup2;
 	}
 
 	rtp_end->rtcp.when = BSC_FD_READ;
 	if (osmo_fd_register(&rtp_end->rtcp) != 0) {
-		LOGP(DRTP, LOGL_ERROR,
-		     "endpoint:0x%x failed to register RTCP port %d\n", endpno,
-		     rtp_end->local_port + 1);
+		LOGPENDP(endp, DRTP, LOGL_ERROR,
+			 "failed to register RTCP port %d\n",
+			 rtp_end->local_port + 1);
 		goto cleanup3;
 	}
 
@@ -1511,10 +1459,8 @@
 	end = &conn->end;
 
 	if (end->rtp.fd != -1 || end->rtcp.fd != -1) {
-		LOGP(DRTP, LOGL_ERROR,
-		     "endpoint:0x%x %u was already bound on conn:%s\n",
-		     ENDPOINT_NUMBER(endp), rtp_port,
-		     mgcp_conn_dump(conn->conn));
+		LOGPENDP(endp, DRTP, LOGL_ERROR, "%u was already bound on conn:%s\n",
+			 rtp_port, mgcp_conn_dump(conn->conn));
 
 		/* Double bindings should never occour! Since we always allocate
 		 * connections dynamically and free them when they are not
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index 9be4eda..be161ad 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -148,16 +148,14 @@
 	struct mgcp_conn *_conn;
 
 	if (conn->type != MGCP_RTP_DEFAULT) {
-		LOGP(DLMGCP, LOGL_NOTICE,
-		     "endpoint:%x RTP-setup: Endpoint is not configured as RTP default, stopping here!\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DLMGCP, LOGL_NOTICE,
+			 "RTP-setup: Endpoint is not configured as RTP default, stopping here!\n");
 		return 0;
 	}
 
 	if (conn->conn->mode == MGCP_CONN_LOOPBACK) {
-		LOGP(DLMGCP, LOGL_NOTICE,
-		     "endpoint:%x RTP-setup: Endpoint is in loopback mode, stopping here!\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DLMGCP, LOGL_NOTICE,
+			 "RTP-setup: Endpoint is in loopback mode, stopping here!\n");
 		return 0;
 	}
 
@@ -225,13 +223,13 @@
 	len = snprintf((char *)res->data, 2048, "%d %s%s%s\r\n%s",
 		       code, trans, txt, param ? param : "", sdp ? sdp : "");
 	if (len < 0) {
-		LOGP(DLMGCP, LOGL_ERROR, "Failed to sprintf MGCP response.\n");
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR, "Failed to sprintf MGCP response.\n");
 		msgb_free(res);
 		return NULL;
 	}
 
 	res->l2h = msgb_put(res, len);
-	LOGP(DLMGCP, LOGL_DEBUG, "Generated response: code=%d\n", code);
+	LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "Generated response: code=%d\n", code);
 	mgcp_disp_msg(res->l2h, msgb_l2len(res), "Generated response");
 
 	/*
@@ -430,7 +428,7 @@
 /* AUEP command handler, processes the received command */
 static struct msgb *handle_audit_endpoint(struct mgcp_parse_data *p)
 {
-	LOGP(DLMGCP, LOGL_NOTICE, "AUEP: auditing endpoint ...\n");
+	LOGPENDP(p->endp, DLMGCP, LOGL_NOTICE, "AUEP: auditing endpoint ...\n");
 	return create_ok_response(p->endp, 200, "AUEP", p->trans);
 }
 
@@ -469,9 +467,9 @@
 
 	}
 
-	LOGP(DLMGCP, LOGL_ERROR,
-	     "Allocating a RTP/RTCP port failed %u times 0x%x.\n",
-	     tries, ENDPOINT_NUMBER(endp));
+	LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+	     "Allocating a RTP/RTCP port failed %u times.\n",
+	     tries);
 	return -1;
 }
 
@@ -654,11 +652,11 @@
 	rtp->force_constant_ssrc = patch_ssrc ? 1 : 0;
 	rtp->rfc5993_hr_convert = tcfg->rfc5993_hr_convert;
 
-	LOGP(DLMGCP, LOGL_DEBUG,
-	     "Configuring RTP endpoint: local port %d%s%s\n",
-	     ntohs(rtp->rtp_port),
-	     rtp->force_aligned_timing ? ", force constant timing" : "",
-	     rtp->force_constant_ssrc ? ", force constant ssrc" : "");
+	LOGPENDP(endp, DLMGCP, LOGL_DEBUG,
+		 "Configuring RTP endpoint: local port %d%s%s\n",
+		 ntohs(rtp->rtp_port),
+		 rtp->force_aligned_timing ? ", force constant timing" : "",
+		 rtp->force_constant_ssrc ? ", force constant ssrc" : "");
 }
 
 uint32_t mgcp_rtp_packet_duration(struct mgcp_endpoint *endp,
@@ -684,10 +682,10 @@
 {
 	if (!endp->cfg->osmux_init) {
 		if (osmux_init(OSMUX_ROLE_BSC, endp->cfg) < 0) {
-			LOGP(DLMGCP, LOGL_ERROR, "Cannot init OSMUX\n");
+			LOGPENDP(endp, DLMGCP, LOGL_ERROR, "Cannot init OSMUX\n");
 			return -1;
 		}
-		LOGP(DLMGCP, LOGL_NOTICE, "OSMUX socket has been set up\n");
+		LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "OSMUX socket has been set up\n");
 	}
 
 	return mgcp_parse_osmux_cid(line);
@@ -713,9 +711,8 @@
 		mgcp_codec_reset_all(conn);
 		rc = mgcp_parse_sdp_data(endp, conn, p);
 		if (rc != 0) {
-			LOGP(DLMGCP, LOGL_ERROR,
-			     "%s: endpoint:%x sdp not parseable\n", cmd,
-			     ENDPOINT_NUMBER(endp));
+			LOGPCONN(conn->conn, DLMGCP,  LOGL_ERROR,
+				 "%s: sdp not parseable\n", cmd);
 
 			/* See also RFC 3661: Protocol error */
 			return 510;
@@ -747,9 +744,8 @@
 	return 0;
 
 error:
-	LOGP(DLMGCP, LOGL_ERROR,
-	     "%s: endpoint:0x%x codec negotiation failure\n", cmd,
-	     ENDPOINT_NUMBER(endp));
+	LOGPCONN(conn->conn, DLMGCP, LOGL_ERROR,
+	     "%s: codec negotiation failure\n", cmd);
 
 	/* See also RFC 3661: Codec negotiation failure */
 	return 534;
@@ -772,8 +768,7 @@
 		if (!strcmp(token, "C"))
 			endp->x_osmo_ign |= MGCP_X_OSMO_IGN_CALLID;
 		else
-			LOGP(DLMGCP, LOGL_ERROR, "endpoint 0x%x: received unknown X-Osmo-IGN item '%s'\n",
-			     ENDPOINT_NUMBER(endp), token);
+			LOGPENDP(endp, DLMGCP, LOGL_ERROR, "received unknown X-Osmo-IGN item '%s'\n", token);
 	}
 
 	return true;
@@ -796,7 +791,7 @@
 	char conn_name[512];
 	int rc;
 
-	LOGP(DLMGCP, LOGL_NOTICE, "CRCX: creating new connection ...\n");
+	LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "CRCX: creating new connection ...\n");
 
 	/* parse CallID C: and LocalParameters L: */
 	for_each_line(line, p->save) {
@@ -838,9 +833,8 @@
 			have_sdp = 1;
 			goto mgcp_header_done;
 		default:
-			LOGP(DLMGCP, LOGL_NOTICE,
-			     "CRCX: endpoint:%x unhandled option: '%c'/%d\n",
-			     ENDPOINT_NUMBER(endp), *line, *line);
+			LOGPENDP(endp, DLMGCP, LOGL_NOTICE,
+				 "CRCX: unhandled option: '%c'/%d\n", *line, *line);
 			rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_UNHANDLED_PARAM]);
 			return create_err_response(NULL, 539, "CRCX", p->trans);
 			break;
@@ -850,26 +844,24 @@
 mgcp_header_done:
 	/* Check parameters */
 	if (!callid) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "CRCX: endpoint:%x insufficient parameters, missing callid\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+			 "CRCX: insufficient parameters, missing callid\n");
 		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_MISSING_CALLID]);
 		return create_err_response(endp, 516, "CRCX", p->trans);
 	}
 
 	if (!mode) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "CRCX: endpoint:%x insufficient parameters, missing mode\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+			 "CRCX: insufficient parameters, missing mode\n");
 		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_INVALID_MODE]);
 		return create_err_response(endp, 517, "CRCX", p->trans);
 	}
 
 	/* Check if we are able to accept the creation of another connection */
 	if (llist_count(&endp->conns) >= endp->type->max_conns) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "CRCX: endpoint:%x endpoint full, max. %i connections allowed!\n",
-		     endp->type->max_conns, ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+			"CRCX: endpoint full, max. %i connections allowed!\n",
+			endp->type->max_conns);
 		if (tcfg->force_realloc) {
 			/* There is no more room for a connection, make some
 			 * room by blindly tossing the oldest of the two two
@@ -886,9 +878,9 @@
 	/* Check if this endpoint already serves a call, if so, check if the
 	 * callids match up so that we are sure that this is our call */
 	if (endp->callid && mgcp_verify_call_id(endp, callid)) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "CRCX: endpoint:0x%x allready seized by other call (%s)\n",
-		     ENDPOINT_NUMBER(endp), endp->callid);
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+			 "CRCX: already seized by other call (%s)\n",
+			 endp->callid);
 		if (tcfg->force_realloc)
 			/* This is not our call, toss everything by releasing
 			 * the entire endpoint. (rude!) */
@@ -909,9 +901,8 @@
 	snprintf(conn_name, sizeof(conn_name), "%s", callid);
 	_conn = mgcp_conn_alloc(NULL, endp, MGCP_CONN_TYPE_RTP, conn_name);
 	if (!_conn) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "CRCX: endpoint:0x%x unable to allocate RTP connection\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+			 "CRCX: unable to allocate RTP connection\n");
 		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_ALLOC_CONN]);
 		goto error2;
 
@@ -932,9 +923,8 @@
 		conn->osmux.cid = osmux_cid;
 		conn->osmux.state = OSMUX_STATE_NEGOTIATING;
 	} else if (endp->cfg->osmux == OSMUX_USAGE_ONLY) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "CRCX: endpoint:0x%x osmux only and no osmux offered\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPCONN(_conn, DLMGCP, LOGL_ERROR,
+			 "CRCX: osmux only and no osmux offered\n");
 		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_NO_OSMUX]);
 		goto error2;
 	}
@@ -944,9 +934,8 @@
 		rc = set_local_cx_options(endp->tcfg->endpoints,
 					  &endp->local_options, local_options);
 		if (rc != 0) {
-			LOGP(DLMGCP, LOGL_ERROR,
-			     "CRCX: endpoint:%x inavlid local connection options!\n",
-			     ENDPOINT_NUMBER(endp));
+			LOGPCONN(_conn, DLMGCP, LOGL_ERROR,
+				 "CRCX: inavlid local connection options!\n");
 			error_code = rc;
 			rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_INVALID_CONN_OPTIONS]);
 			goto error2;
@@ -976,9 +965,8 @@
 	if (conn->conn->mode != MGCP_CONN_LOOPBACK
 	    && conn->conn->mode != MGCP_CONN_RECV_ONLY
 	    && conn->end.rtp_port == 0) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "CRCX: endpoint:%x selected connection mode type requires an opposite end!\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPCONN(_conn, DLMGCP, LOGL_ERROR,
+			 "CRCX: selected connection mode type requires an opposite end!\n");
 		error_code = 527;
 		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_NO_REMOTE_CONN_DESC]);
 		goto error2;
@@ -990,9 +978,8 @@
 	}
 
 	if (setup_rtp_processing(endp, conn) != 0) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "CRCX: endpoint:0x%x could not start RTP processing!\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPCONN(_conn, DLMGCP, LOGL_ERROR,
+			 "CRCX: could not start RTP processing!\n");
 		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_START_RTP]);
 		goto error2;
 	}
@@ -1004,9 +991,8 @@
 				       MGCP_ENDP_CRCX, p->trans);
 		switch (rc) {
 		case MGCP_POLICY_REJECT:
-			LOGP(DLMGCP, LOGL_NOTICE,
-			     "CRCX: endpoint:0x%x CRCX rejected by policy\n",
-			     ENDPOINT_NUMBER(endp));
+			LOGPCONN(_conn, DLMGCP, LOGL_NOTICE,
+				 "CRCX: CRCX rejected by policy\n");
 			mgcp_endp_release(endp);
 			rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_REJECTED_BY_POLICY]);
 			return create_err_response(endp, 400, "CRCX", p->trans);
@@ -1021,9 +1007,8 @@
 		}
 	}
 
-	LOGP(DLMGCP, LOGL_DEBUG,
-	     "CRCX: endpoint:0x%x Creating connection: CI: %s port: %u\n",
-	     ENDPOINT_NUMBER(endp), conn->conn->id, conn->end.local_port);
+	LOGPCONN(conn->conn, DLMGCP, LOGL_DEBUG,
+		 "CRCX: Creating connection: port: %u\n", conn->end.local_port);
 	if (p->cfg->change_cb)
 		p->cfg->change_cb(tcfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_CRCX);
 
@@ -1033,16 +1018,14 @@
 	    && tcfg->keepalive_interval != MGCP_KEEPALIVE_NEVER)
 		send_dummy(endp, conn);
 
-	LOGP(DLMGCP, LOGL_NOTICE,
-	     "CRCX: endpoint:0x%x connection successfully created\n",
-	     ENDPOINT_NUMBER(endp));
+	LOGPCONN(_conn, DLMGCP, LOGL_NOTICE,
+		 "CRCX: connection successfully created\n");
 	rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_SUCCESS]);
 	return create_response_with_sdp(endp, conn, "CRCX", p->trans, true);
 error2:
 	mgcp_endp_release(endp);
-	LOGP(DLMGCP, LOGL_NOTICE,
-	     "CRCX: endpoint:0x%x unable to create connection\n",
-	     ENDPOINT_NUMBER(endp));
+	LOGPENDP(endp, DLMGCP, LOGL_NOTICE,
+		 "CRCX: unable to create connection\n");
 	return create_err_response(endp, error_code, "CRCX", p->trans);
 }
 
@@ -1066,21 +1049,19 @@
         const char *conn_id = NULL;
 	int rc;
 
-	LOGP(DLMGCP, LOGL_NOTICE, "MDCX: modifying existing connection ...\n");
+	LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "MDCX: modifying existing connection ...\n");
 
 	/* Prohibit wildcarded requests */
 	if (endp->wildcarded_req) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "MDCX: endpoint:0x%x wildcarded endpoint names not supported.\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+			 "MDCX: wildcarded endpoint names not supported.\n");
 		rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_WILDCARD]);
 		return create_err_response(endp, 507, "MDCX", p->trans);
 	}
 
 	if (llist_count(&endp->conns) <= 0) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "MDCX: endpoint:0x%x endpoint is not holding a connection.\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+			 "MDCX: endpoint is not holding a connection.\n");
 		rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_NO_CONN]);
 		return create_err_response(endp, 400, "MDCX", p->trans);
 	}
@@ -1118,9 +1099,9 @@
 			goto mgcp_header_done;
 			break;
 		default:
-			LOGP(DLMGCP, LOGL_NOTICE,
-			     "MDCX: endpoint:0x%x Unhandled MGCP option: '%c'/%d\n",
-			     ENDPOINT_NUMBER(endp), line[0], line[0]);
+			LOGPENDP(endp, DLMGCP, LOGL_NOTICE,
+				 "MDCX: Unhandled MGCP option: '%c'/%d\n",
+				 line[0], line[0]);
 			rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_UNHANDLED_PARAM]);
 			return create_err_response(NULL, 539, "MDCX", p->trans);
 			break;
@@ -1129,9 +1110,8 @@
 
 mgcp_header_done:
 	if (!conn_id) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "MDCX: endpoint:0x%x insufficient parameters, missing ci (connectionIdentifier)\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+			 "MDCX: insufficient parameters, missing ci (connectionIdentifier)\n");
 		rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_NO_CONNID]);
 		return create_err_response(endp, 515, "MDCX", p->trans);
 	}
@@ -1158,9 +1138,8 @@
 		rc = set_local_cx_options(endp->tcfg->endpoints,
 					  &endp->local_options, local_options);
 		if (rc != 0) {
-			LOGP(DLMGCP, LOGL_ERROR,
-			     "MDCX: endpoint:%x invalid local connection options!\n",
-			     ENDPOINT_NUMBER(endp));
+			LOGPCONN(conn->conn, DLMGCP, LOGL_ERROR,
+				 "MDCX: invalid local connection options!\n");
 			error_code = rc;
 			rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_INVALID_CONN_OPTIONS]);
 			goto error3;
@@ -1179,9 +1158,8 @@
 	if (conn->conn->mode != MGCP_CONN_LOOPBACK
 	    && conn->conn->mode != MGCP_CONN_RECV_ONLY
 	    && conn->end.rtp_port == 0) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "MDCX: endpoint:%x selected connection mode type requires an opposite end!\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPCONN(conn->conn, DLMGCP, LOGL_ERROR,
+			 "MDCX: selected connection mode type requires an opposite end!\n");
 		error_code = 527;
 		rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_NO_REMOTE_CONN_DESC]);
 		goto error3;
@@ -1201,9 +1179,8 @@
 				       MGCP_ENDP_MDCX, p->trans);
 		switch (rc) {
 		case MGCP_POLICY_REJECT:
-			LOGP(DLMGCP, LOGL_NOTICE,
-			     "MDCX: endpoint:0x%x rejected by policy\n",
-			     ENDPOINT_NUMBER(endp));
+			LOGPCONN(conn->conn, DLMGCP, LOGL_NOTICE,
+				 "MDCX: rejected by policy\n");
 			rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_REJECTED_BY_POLICY]);
 			if (silent)
 				goto out_silent;
@@ -1211,9 +1188,8 @@
 			break;
 		case MGCP_POLICY_DEFER:
 			/* stop processing */
-			LOGP(DLMGCP, LOGL_DEBUG,
-			     "MDCX: endpoint:0x%x deferred by policy\n",
-			     ENDPOINT_NUMBER(endp));
+			LOGPCONN(conn->conn, DLMGCP, LOGL_DEBUG,
+				 "MDCX: deferred by policy\n");
 			rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_DEFERRED_BY_POLICY]);
 			return NULL;
 			break;
@@ -1226,9 +1202,8 @@
 	mgcp_rtp_end_config(endp, 1, &conn->end);
 
 	/* modify */
-	LOGP(DLMGCP, LOGL_DEBUG,
-	     "MDCX: endpoint:0x%x modified conn:%s\n",
-	     ENDPOINT_NUMBER(endp), mgcp_conn_dump(conn->conn));
+	LOGPCONN(conn->conn, DLMGCP, LOGL_DEBUG,
+		 "MDCX: modified conn:%s\n", mgcp_conn_dump(conn->conn));
 	if (p->cfg->change_cb)
 		p->cfg->change_cb(endp->tcfg, ENDPOINT_NUMBER(endp),
 				  MGCP_ENDP_MDCX);
@@ -1243,16 +1218,14 @@
 	if (silent)
 		goto out_silent;
 
-	LOGP(DLMGCP, LOGL_NOTICE,
-	     "MDCX: endpoint:0x%x connection successfully modified\n",
-	     ENDPOINT_NUMBER(endp));
+	LOGPCONN(conn->conn, DLMGCP, LOGL_NOTICE,
+		 "MDCX: connection successfully modified\n");
 	return create_response_with_sdp(endp, conn, "MDCX", p->trans, false);
 error3:
 	return create_err_response(endp, error_code, "MDCX", p->trans);
 
 out_silent:
-	LOGP(DLMGCP, LOGL_DEBUG, "MDCX: endpoint:0x%x silent exit\n",
-	     ENDPOINT_NUMBER(endp));
+	LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "MDCX: silent exit\n");
 	return NULL;
 }
 
@@ -1269,23 +1242,20 @@
 	const char *conn_id = NULL;
 	struct mgcp_conn_rtp *conn = NULL;
 
-	LOGP(DLMGCP, LOGL_NOTICE,
-	     "DLCX: endpoint:0x%x deleting connection ...\n",
-	     ENDPOINT_NUMBER(endp));
+	LOGPENDP(endp, DLMGCP, LOGL_NOTICE,
+		 "DLCX: deleting connection ...\n");
 
 	/* Prohibit wildcarded requests */
 	if (endp->wildcarded_req) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "DLCX: endpoint:0x%x wildcarded endpoint names not supported.\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+			 "DLCX: wildcarded endpoint names not supported.\n");
 		rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_WILDCARD]);
 		return create_err_response(endp, 507, "DLCX", p->trans);
 	}
 
 	if (llist_count(&endp->conns) <= 0) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "DLCX: endpoint:0x%x endpoint is not holding a connection.\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
+			 "DLCX: endpoint is not holding a connection.\n");
 		rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_NO_CONN]);
 		return create_err_response(endp, 515, "DLCX", p->trans);
 	}
@@ -1313,9 +1283,9 @@
 			silent = strcmp("noanswer", line + 3) == 0;
 			break;
 		default:
-			LOGP(DLMGCP, LOGL_NOTICE,
-			     "DLCX: endpoint:0x%x Unhandled MGCP option: '%c'/%d\n",
-			     ENDPOINT_NUMBER(endp), line[0], line[0]);
+			LOGPENDP(endp, DLMGCP, LOGL_NOTICE,
+				 "DLCX: Unhandled MGCP option: '%c'/%d\n",
+				 line[0], line[0]);
 			rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_UNHANDLED_PARAM]);
 			return create_err_response(NULL, 539, "DLCX", p->trans);
 			break;
@@ -1329,9 +1299,7 @@
 				       MGCP_ENDP_DLCX, p->trans);
 		switch (rc) {
 		case MGCP_POLICY_REJECT:
-			LOGP(DLMGCP, LOGL_NOTICE,
-			     "DLCX: endpoint:0x%x rejected by policy\n",
-			     ENDPOINT_NUMBER(endp));
+			LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "DLCX: rejected by policy\n");
 			rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_REJECTED_BY_POLICY]);
 			if (silent)
 				goto out_silent;
@@ -1353,9 +1321,9 @@
 	 * RFC3435 Section F.7) */
 	if (!conn_id) {
 		int num_conns = llist_count(&endp->conns);
-		LOGP(DLMGCP, LOGL_NOTICE,
-		     "DLCX: endpoint:0x%x missing ci (connectionIdentifier), will remove all connections (%d total) at once\n",
-		     num_conns, ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DLMGCP, LOGL_NOTICE,
+			 "DLCX: missing ci (connectionIdentifier), will remove all connections (%d total) at once\n",
+			 num_conns);
 
 		if (num_conns > 0)
 			rate_ctr_add(&rate_ctrs->ctr[MGCP_DLCX_SUCCESS], num_conns);
@@ -1378,20 +1346,17 @@
 	mgcp_format_stats(stats, sizeof(stats), conn->conn);
 
 	/* delete connection */
-	LOGP(DLMGCP, LOGL_DEBUG, "DLCX: endpoint:0x%x deleting conn:%s\n",
-	     ENDPOINT_NUMBER(endp), mgcp_conn_dump(conn->conn));
+	LOGPCONN(conn->conn, DLMGCP, LOGL_DEBUG, "DLCX: deleting conn:%s\n",
+		 mgcp_conn_dump(conn->conn));
 	mgcp_conn_free(endp, conn_id);
-	LOGP(DLMGCP, LOGL_NOTICE,
-	     "DLCX: endpoint:0x%x connection successfully deleted\n",
-	     ENDPOINT_NUMBER(endp));
+	LOGPENDP(endp, DLMGCP, LOGL_NOTICE,
+		 "DLCX: connection successfully deleted\n");
 
 	/* When all connections are closed, the endpoint will be released
 	 * in order to be ready to be used by another call. */
 	if (llist_count(&endp->conns) <= 0) {
 		mgcp_endp_release(endp);
-		LOGP(DLMGCP, LOGL_DEBUG,
-		     "DLCX: endpoint:0x%x endpoint released\n",
-		     ENDPOINT_NUMBER(endp));
+		LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "DLCX: endpoint released\n");
 	}
 
 	if (p->cfg->change_cb)
@@ -1407,8 +1372,7 @@
 	return create_err_response(endp, error_code, "DLCX", p->trans);
 
 out_silent:
-	LOGP(DLMGCP, LOGL_DEBUG, "DLCX: endpoint:0x%x silent exit\n",
-	     ENDPOINT_NUMBER(endp));
+	LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "DLCX: silent exit\n");
 	return NULL;
 }
 
diff --git a/src/libosmo-mgcp/mgcp_sdp.c b/src/libosmo-mgcp/mgcp_sdp.c
index 02b9695..6b41f50 100644
--- a/src/libosmo-mgcp/mgcp_sdp.c
+++ b/src/libosmo-mgcp/mgcp_sdp.c
@@ -376,7 +376,7 @@
 
 	talloc_free(tmp_ctx);
 
-	LOGP(DLMGCP, LOGL_NOTICE,
+	LOGPCONN(conn->conn, DLMGCP, LOGL_NOTICE,
 	     "Got media info via SDP: port:%d, addr:%s, duration:%d, payload-types:",
 	     ntohs(rtp->rtp_port), inet_ntoa(rtp->addr),
 	     rtp->packet_duration_ms);
@@ -571,6 +571,6 @@
 	return 0;
 
 buffer_too_small:
-	LOGP(DLMGCP, LOGL_ERROR, "SDP messagebuffer too small\n");
+	LOGPCONN(conn->conn, DLMGCP, LOGL_ERROR, "SDP messagebuffer too small\n");
 	return -1;
 }

-- 
To view, visit https://gerrit.osmocom.org/13773
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1c49b1eb16bc5f1010376da5cf407ca6e31d81f2
Gerrit-Change-Number: 13773
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190424/554fe4b7/attachment.htm>


More information about the gerrit-log mailing list