]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: protocol: use a custom AF_MAX to help protocol parser
authorWilliam Lallemand <wlallemand@haproxy.com>
Tue, 11 Sep 2018 14:51:28 +0000 (16:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 12 Sep 2018 05:12:27 +0000 (07:12 +0200)
It's possible to have several protocols per family which is a problem
with the current way the protocols are stored.

This allows to register a new protocol in HAProxy which is not a
protocol in the strict socket definition. It will be used to register a
SOCK_STREAM protocol using socketpair().

include/proto/protocol.h
include/types/protocol.h
src/protocol.c

index 13a3c0a61bf3880bdf4e13bbcae739985495252c..857f9e6922b34c5079203fe065c5b9a0cde79d4b 100644 (file)
@@ -25,7 +25,7 @@
 #include <sys/socket.h>
 #include <types/protocol.h>
 
-extern struct protocol *__protocol_by_family[AF_MAX];
+extern struct protocol *__protocol_by_family[AF_CUST_MAX];
 
 /* Registers the protocol <proto> */
 void protocol_register(struct protocol *proto);
@@ -56,7 +56,7 @@ int protocol_enable_all(void);
 /* returns the protocol associated to family <family> or NULL if not found */
 static inline struct protocol *protocol_by_family(int family)
 {
-       if (family >= 0 && family < AF_MAX)
+       if (family >= 0 && family < AF_CUST_MAX)
                return __protocol_by_family[family];
        return NULL;
 }
index 9480c186907fe1114b8df736209f5dbd537f8f1e..378e2b0e165eaac0662f64c2f0928c41f8cb27ba 100644 (file)
 struct listener;
 struct connection;
 
+/*
+ * Custom network family for str2sa parsing.  Should be ok to do this since
+ * sa_family_t is standardized as an unsigned integer
+ */
+
+#define AF_CUST_SOCKPAIR     (AF_MAX + 1)
+#define AF_CUST_MAX          (AF_MAX + 2)
+
+/*
+ * Test in case AF_CUST_MAX overflows the sa_family_t (unsigned int)
+ */
+#if (AF_CUST_MAX < AF_MAX)
+# error "Can't build on the target system, AF_CUST_MAX overflow"
+#endif
+
+
+
 /* max length of a protcol name, including trailing zero */
 #define PROTO_NAME_LEN 16
 
index 7884ef7340982f9cb0018cc08071c42f1e61e65d..96e01c82787190823f9cd68c1a584713aa85afe1 100644 (file)
 
 /* List head of all registered protocols */
 static struct list protocols = LIST_HEAD_INIT(protocols);
-struct protocol *__protocol_by_family[AF_MAX] = { };
+struct protocol *__protocol_by_family[AF_CUST_MAX] = { };
 
 /* Registers the protocol <proto> */
 void protocol_register(struct protocol *proto)
 {
        LIST_ADDQ(&protocols, &proto->list);
-       if (proto->sock_domain >= 0 && proto->sock_domain < AF_MAX)
+       if (proto->sock_domain >= 0 && proto->sock_domain < AF_CUST_MAX)
                __protocol_by_family[proto->sock_domain] = proto;
 }