core,API: Add bridge support
This change introduces a facility to bridge messages between two
bindings.
This is implemented through a new mctp_bridge_busses() API, which
applies a new routing policy, sending packets from one binding to the
other. This is in contrast to the current policy of dropping all
non-local packets.
To do this, the message context code needs to know both source and
destination EIDs, so add them to the mctp_msg_ctx_lookup() criteria.
Also, add a small test for bridge mode.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Change-Id: If532613525ddbf81df249e26d0f23825996f7bda
diff --git a/libmctp.h b/libmctp.h
index 5219a35..523891f 100644
--- a/libmctp.h
+++ b/libmctp.h
@@ -63,11 +63,24 @@
/* Register a binding to the MCTP core, and creates a bus (populating
* binding->bus).
+ *
+ * If this function is called, the MCTP stack is initialised as an 'endpoint',
+ * and will deliver local packets to a RX callback - see `mctp_set_rx_all()`
+ * below.
*/
int mctp_register_bus(struct mctp *mctp,
struct mctp_binding *binding,
mctp_eid_t eid);
+/* Create a simple bidirectional bridge between busses.
+ *
+ * In this mode, the MCTP stack is initialised as a bridge. There is no EID
+ * defined, so no packets are considered local. Instead, all messages from one
+ * binding are forwarded to the other.
+ */
+int mctp_bridge_busses(struct mctp *mctp,
+ struct mctp_binding *b1, struct mctp_binding *b2);
+
typedef void (*mctp_rx_fn)(uint8_t src_eid, void *data,
void *msg, size_t len);