demux-daemon: Add support for loopback messages

If a demux client sends a message addressed to the local EID, loop it
back to other clients.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Change-Id: I6ae4720688d6ad3e50793f1d74aa50259797649e
diff --git a/utils/mctp-demux-daemon.c b/utils/mctp-demux-daemon.c
index ca814f1..151d915 100644
--- a/utils/mctp-demux-daemon.c
+++ b/utils/mctp-demux-daemon.c
@@ -281,7 +281,7 @@
 static int client_process_recv(struct ctx *ctx, int idx)
 {
 	struct client *client = &ctx->clients[idx];
-	uint8_t buf[4096];
+	uint8_t eid, buf[4096];
 	int rc;
 
 	/* are we waiting for a type message? */
@@ -309,20 +309,22 @@
 		goto out_close;
 	}
 
-	if (rc == 0) {
+	if (rc <= 0) {
 		rc = -1;
 		goto out_close;
 	}
 
-	if (rc > 0) {
-		uint8_t eid = buf[0];
-		if (ctx->verbose)
-			fprintf(stderr,
-				"client[%d] sent message: dest 0x%02x len %d\n",
-				idx, eid, rc - 1);
+	if (ctx->verbose)
+		fprintf(stderr,
+			"client[%d] sent message: dest 0x%02x len %d\n",
+			idx, eid, rc - 1);
 
+	eid = buf[0];
+
+	if (eid == ctx->local_eid)
+		rx_message(eid, ctx, buf + 1, rc - 1);
+	else
 		tx_message(ctx, eid, buf + 1, rc - 1);
-	}
 
 	return 0;