]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: add a minimal transport layer registration system
authorWilly Tarreau <w@1wt.eu>
Thu, 22 Dec 2016 19:25:26 +0000 (20:25 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 22 Dec 2016 22:26:38 +0000 (23:26 +0100)
There are still a lot of #ifdef USE_OPENSSL in the code (still 43
occurences) because we never know if we can directly access ssl_sock
or not. This patch attacks the problem differently by providing a
way for transport layers to register themselves and for users to
retrieve the pointer. Unregistered transport layers will point to NULL
so it will be easy to check if SSL is registered or not. The mechanism
is very inexpensive as it relies on a two-entries array of pointers,
so the performance will not be affected.

include/proto/connection.h
include/types/connection.h
src/connection.c
src/raw_sock.c
src/ssl_sock.c

index 6a24dec1ec50492b3e6cc1c4fb0bbf6e05984834..2380bb8118dde245d2eb668271eae1e16aab2f9e 100644 (file)
@@ -30,6 +30,7 @@
 #include <proto/obj_type.h>
 
 extern struct pool_head *pool2_connection;
+extern struct xprt_ops *registered_xprt[XPRT_ENTRIES];
 
 /* perform minimal intializations, report 0 in case of error, 1 if OK. */
 int init_connection();
@@ -633,6 +634,21 @@ static inline const char *conn_get_data_name(const struct connection *conn)
        return conn->data->name;
 }
 
+/* registers pointer to transport layer <id> (XPRT_*) */
+static inline void xprt_register(int id, struct xprt_ops *xprt)
+{
+       if (id >= XPRT_ENTRIES)
+               return;
+       registered_xprt[id] = xprt;
+}
+
+/* returns pointer to transport layer <id> (XPRT_*) or NULL if not registered */
+static inline struct xprt_ops *xprt_get(int id)
+{
+       if (id >= XPRT_ENTRIES)
+               return NULL;
+       return registered_xprt[id];
+}
 
 #endif /* _PROTO_CONNECTION_H */
 
index 6da213841f0cd8b5296a05798d505170129a5370..904bef6a6ed290e96d98058060d1a69a068af514 100644 (file)
@@ -199,6 +199,13 @@ enum {
        CO_SFL_STREAMER    = 0x0002,    /* Producer is continuously streaming data */
 };
 
+/* known transport layers (for ease of lookup) */
+enum {
+       XPRT_RAW = 0,
+       XPRT_SSL = 1,
+       XPRT_ENTRIES /* must be last one */
+};
+
 /* xprt_ops describes transport-layer operations for a connection. They
  * generally run over a socket-based control layer, but not always. Some
  * of them are used for data transfer with the upper layer (rcv_*, snd_*)
index 7a9f3913ca74589a8a5f2d0a1c4e135652ce01d1..093b8a963e0006f0ddf3ad87b9035530f6c449fb 100644 (file)
@@ -27,6 +27,7 @@
 #endif
 
 struct pool_head *pool2_connection;
+struct xprt_ops *registered_xprt[XPRT_ENTRIES] = { NULL, };
 
 /* perform minimal intializations, report 0 in case of error, 1 if OK. */
 int init_connection()
index 0883c57a6a4535ffdd727cf48b5f0bc9058b3848..78cb8a2a6ff948bd5428196521567850857aa2d5 100644 (file)
@@ -419,6 +419,13 @@ struct xprt_ops raw_sock = {
        .name     = "RAW",
 };
 
+
+__attribute__((constructor))
+static void __ssl_sock_deinit(void)
+{
+       xprt_register(XPRT_RAW, &raw_sock);
+}
+
 /*
  * Local variables:
  *  c-indent-level: 8
index ae821e007728d6bdec4e01278a8731af5de464a1..101f7f34239d50d7e086f75813e5dccfa2b3e163 100644 (file)
@@ -6694,6 +6694,7 @@ static void __ssl_sock_init(void)
        global.listen_default_ssloptions = BC_SSL_O_NONE;
        global.connect_default_ssloptions = SRV_SSL_O_NONE;
 
+       xprt_register(XPRT_SSL, &ssl_sock);
        SSL_library_init();
        cm = SSL_COMP_get_compression_methods();
        sk_SSL_COMP_zero(cm);