From: Olivier Houchard Date: Wed, 13 Sep 2017 16:30:23 +0000 (+0200) Subject: MINOR: connection: introduce conn_stream X-Git-Tag: v1.8-rc1~93 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e2b40b9eabdc36fabaeacfc1a075427be8062b7f;p=thirdparty%2Fhaproxy.git MINOR: connection: introduce conn_stream This patch introduces a new struct conn_stream. It's the stream-side of a multiplexed connection. A pool is created and destroyed on exit. For now the conn_streams are not used at all. --- diff --git a/include/proto/connection.h b/include/proto/connection.h index 8ba4fc632a..800937247f 100644 --- a/include/proto/connection.h +++ b/include/proto/connection.h @@ -31,6 +31,7 @@ #include extern struct pool_head *pool2_connection; +extern struct pool_head *pool2_connstream; extern struct xprt_ops *registered_xprt[XPRT_ENTRIES]; extern struct alpn_mux_list alpn_mux_list; @@ -552,6 +553,11 @@ static inline void conn_free(struct connection *conn) pool_free2(pool2_connection, conn); } +/* Returns the conn from a cs. If cs is NULL, returns NULL */ +static inline struct connection *cs_conn(const struct conn_stream *cs) +{ + return cs ? cs->conn : NULL; +} /* Retrieves the connection's source address */ static inline void conn_get_from_addr(struct connection *conn) diff --git a/include/proto/obj_type.h b/include/proto/obj_type.h index 60265b5e13..617464ce34 100644 --- a/include/proto/obj_type.h +++ b/include/proto/obj_type.h @@ -119,6 +119,18 @@ static inline struct appctx *objt_appctx(enum obj_type *t) return __objt_appctx(t); } +static inline struct conn_stream *__objt_cs(enum obj_type *t) +{ + return (container_of(t, struct conn_stream, obj_type)); +} + +static inline struct conn_stream *objt_cs(enum obj_type *t) +{ + if (!t || *t != OBJ_TYPE_CS) + return NULL; + return __objt_cs(t); +} + static inline struct connection *__objt_conn(enum obj_type *t) { return container_of(t, struct connection, obj_type); @@ -152,6 +164,7 @@ static inline void *obj_base_ptr(enum obj_type *t) case OBJ_TYPE_APPLET: return __objt_applet(t); case OBJ_TYPE_APPCTX: return __objt_appctx(t); case OBJ_TYPE_CONN: return __objt_conn(t); + case OBJ_TYPE_CS: return __objt_cs(t); default: return NULL; } } diff --git a/include/types/connection.h b/include/types/connection.h index b925f65ff6..9561406eb1 100644 --- a/include/types/connection.h +++ b/include/types/connection.h @@ -39,6 +39,7 @@ /* referenced below */ struct connection; +struct conn_stream; struct buffer; struct server; struct pipe; @@ -51,6 +52,15 @@ union conn_handle { int fd; /* file descriptor, for regular sockets */ }; +/* conn_stream flags */ +enum { + CS_FL_NONE = 0x00000000, /* Just for initialization purposes */ + CS_FL_DATA_RD_ENA = 0x00000001, /* receiving data is allowed */ + CS_FL_DATA_WR_ENA = 0x00000002, /* sending data is desired */ + + CS_FL_ERROR = 0x00000100, /* a fatal error was reported */ + CS_FL_EOS = 0x00001000, /* End of stream */ +}; /* For each direction, we have a CO_FL_{SOCK,DATA}__ENA flag, which * indicates if read or write is desired in that direction for the respective @@ -297,6 +307,18 @@ struct conn_src { #endif }; +/* + * This structure describes the elements of a connection relevant to a stream + */ +struct conn_stream { + enum obj_type obj_type; /* differentiates connection from applet context */ + struct connection *conn; /* xprt-level connection */ + unsigned int flags; /* CS_FL_* */ + void *data; /* pointer to upper layer's entity (eg: stream interface) */ + const struct data_cb *data_cb; /* data layer callbacks. Must be set before xprt->init() */ + void *ctx; /* mux-specific context */ +}; + /* This structure describes a connection with its methods and data. * A connection may be performed to proxy or server via a local or remote * socket, and can also be made to an internal applet. It can support diff --git a/include/types/obj_type.h b/include/types/obj_type.h index a6310cfc0d..e141d69e55 100644 --- a/include/types/obj_type.h +++ b/include/types/obj_type.h @@ -40,6 +40,7 @@ enum obj_type { OBJ_TYPE_APPCTX, /* object is a struct appctx */ OBJ_TYPE_CONN, /* object is a struct connection */ OBJ_TYPE_SRVRQ, /* object is a struct dns_srvrq */ + OBJ_TYPE_CS, /* object is a struct conn_stream */ OBJ_TYPE_ENTRIES /* last one : number of entries */ } __attribute__((packed)) ; diff --git a/src/connection.c b/src/connection.c index b61a9dd847..2e081d8ac9 100644 --- a/src/connection.c +++ b/src/connection.c @@ -28,6 +28,7 @@ #endif struct pool_head *pool2_connection; +struct pool_head *pool2_connstream; struct xprt_ops *registered_xprt[XPRT_ENTRIES] = { NULL, }; /* List head of all known muxes for ALPN */ @@ -39,7 +40,19 @@ struct alpn_mux_list alpn_mux_list = { int init_connection() { pool2_connection = create_pool("connection", sizeof (struct connection), MEM_F_SHARED); - return pool2_connection != NULL; + if (!pool2_connection) + goto fail_conn; + + pool2_connstream = create_pool("conn_stream", sizeof(struct conn_stream), MEM_F_SHARED); + if (!pool2_connstream) + goto fail_cs; + + return 1; + fail_cs: + pool_destroy2(pool2_connection); + pool2_connection = NULL; + fail_conn: + return 0; } /* I/O callback for fd-based connections. It calls the read/write handlers diff --git a/src/haproxy.c b/src/haproxy.c index ed6c8ba8df..d3db264ee5 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2189,6 +2189,7 @@ void deinit(void) pool_destroy2(pool2_stream); pool_destroy2(pool2_session); pool_destroy2(pool2_connection); + pool_destroy2(pool2_connstream); pool_destroy2(pool2_requri); pool_destroy2(pool2_task); pool_destroy2(pool2_capture);