diff --git a/controller.c b/controller.c index 1c32b19429d5dd0db363e1ff62d2568631ba9ae5..ca144b0136df40854afb877db58e1eecffc4aa32 100644 --- a/controller.c +++ b/controller.c @@ -257,8 +257,10 @@ int connection_create(uint8_t intf1_id, uint16_t cport1_id, uint8_t intf2_id, uint16_t cport2_id) { + int ret; struct interface *intf; struct connection *conn; + struct controller *ctrl; intf = get_interface(intf2_id); if (!intf) @@ -271,22 +273,44 @@ connection_create(uint8_t intf1_id, uint16_t cport1_id, conn->intf = intf; conn->cport1_id = cport1_id; conn->cport2_id = cport2_id; + + ctrl = intf->ctrl; + if (ctrl->connection_create) { + ret = ctrl->connection_create(conn); + if (ret) + goto err_free_conn; + } + TAILQ_INSERT_TAIL(&connections, conn, node); return 0; + +err_free_conn: + free(conn); + return ret; } int connection_destroy(uint8_t intf1_id, uint16_t cport1_id, uint8_t intf2_id, uint16_t cport2_id) { + struct interface *intf; struct connection *conn; + struct controller *ctrl; + + intf = get_interface(intf2_id); + if (!intf) + return -EINVAL; conn = hd_cport_id_to_connection(cport1_id); if (!conn) { return -EINVAL; } + ctrl = intf->ctrl; + if (ctrl->connection_destroy) + ctrl->connection_destroy(conn); + TAILQ_REMOVE(&connections, conn, node); free(conn); diff --git a/controller.h b/controller.h index 037552055880782f903f9f9ca76e00c6d7b0b30d..d655f9ed329561defa963e37f0a6377028c65b8a 100644 --- a/controller.h +++ b/controller.h @@ -28,6 +28,9 @@ struct connection { uint16_t cport1_id; uint16_t cport2_id; struct interface *intf; + + void *priv; + TAILQ_ENTRY(connection) node; }; @@ -55,6 +58,8 @@ struct controller { int (*interface_create) (struct interface * intf); void (*interface_destroy) (struct interface * intf); + int (*connection_create) (struct connection * conn); + int (*connection_destroy) (struct connection * conn); int (*write) (struct connection * conn, void *data, size_t len); int (*read) (struct connection * conn, void *data, size_t len);