]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proto: define dedicated protocol for active reverse connect
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 1 Aug 2023 15:27:06 +0000 (17:27 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 24 Aug 2023 15:02:37 +0000 (17:02 +0200)
A new protocol named "reverse_connect" is created. This will be used to
instantiate connections that are opened by a reverse bind.

For the moment, only a minimal set of callbacks are defined with no real
work. This will be extended along the next patches.

Makefile
include/haproxy/proto_reverse_connect.h [new file with mode: 0644]
include/haproxy/protocol-t.h
src/proto_reverse_connect.c [new file with mode: 0644]
src/tools.c

index d17f17e94339ececd472761153ba596e5f0588cc..1f6adc46f51b22d69b8c5a1032a337fa32e4c4bf 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -947,7 +947,8 @@ OBJS += src/mux_h2.o src/mux_fcgi.o src/mux_h1.o src/tcpcheck.o               \
         src/base64.o src/auth.o src/uri_auth.o src/time.o src/ebistree.o      \
         src/dynbuf.o src/wdt.o src/pipe.o src/init.o src/http_acl.o           \
         src/hpack-huff.o src/hpack-enc.o src/dict.o src/freq_ctr.o            \
-        src/ebtree.o src/hash.o src/dgram.o src/version.o
+        src/ebtree.o src/hash.o src/dgram.o src/version.o                     \
+        src/proto_reverse_connect.o
 
 ifneq ($(TRACE),)
   OBJS += src/calltrace.o
diff --git a/include/haproxy/proto_reverse_connect.h b/include/haproxy/proto_reverse_connect.h
new file mode 100644 (file)
index 0000000..31edbb7
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef _HAPROXY_PROTO_REVERSE_CONNECT_H
+#define _HAPROXY_PROTO_REVERSE_CONNECT_H
+
+#include <haproxy/listener-t.h>
+#include <haproxy/receiver-t.h>
+
+int rev_bind_receiver(struct receiver *rx, char **errmsg);
+
+int rev_bind_listener(struct listener *listener, char *errmsg, int errlen);
+
+int rev_accepting_conn(const struct receiver *rx);
+
+#endif /* _HAPROXY_PROTO_REVERSE_CONNECT_H */
index 47df36641c4a20bfac01eeb31bec441a8d9479e0..7846fd5b832b072b0e8d534b67f9051b3b653117 100644 (file)
@@ -39,7 +39,8 @@ struct connection;
  */
 #define AF_CUST_EXISTING_FD  (AF_MAX + 1)
 #define AF_CUST_SOCKPAIR     (AF_MAX + 2)
-#define AF_CUST_MAX          (AF_MAX + 3)
+#define AF_CUST_REV_SRV      (AF_MAX + 3)
+#define AF_CUST_MAX          (AF_MAX + 4)
 
 /*
  * Test in case AF_CUST_MAX overflows the sa_family_t (unsigned int)
diff --git a/src/proto_reverse_connect.c b/src/proto_reverse_connect.c
new file mode 100644 (file)
index 0000000..621f328
--- /dev/null
@@ -0,0 +1,49 @@
+#include <haproxy/api.h>
+#include <haproxy/errors.h>
+#include <haproxy/list.h>
+#include <haproxy/listener.h>
+#include <haproxy/protocol.h>
+
+#include <haproxy/proto_reverse_connect.h>
+
+struct proto_fam proto_fam_reverse_connect = {
+       .name = "reverse_connect",
+       .sock_domain = AF_CUST_REV_SRV,
+       .sock_family = AF_INET,
+       .bind = rev_bind_receiver,
+};
+
+struct protocol proto_reverse_connect = {
+       .name = "rev",
+
+       /* connection layer */
+       .listen  = rev_bind_listener,
+       .add     = default_add_listener,
+
+       /* address family */
+       .fam  = &proto_fam_reverse_connect,
+
+       /* socket layer */
+       .proto_type     = PROTO_TYPE_STREAM,
+       .sock_type      = SOCK_STREAM,
+       .sock_prot      = IPPROTO_TCP,
+       .rx_listening   = rev_accepting_conn,
+       .receivers      = LIST_HEAD_INIT(proto_reverse_connect.receivers),
+};
+
+int rev_bind_receiver(struct receiver *rx, char **errmsg)
+{
+       return ERR_NONE;
+}
+
+int rev_bind_listener(struct listener *listener, char *errmsg, int errlen)
+{
+       return ERR_NONE;
+}
+
+int rev_accepting_conn(const struct receiver *rx)
+{
+       return 1;
+}
+
+INITCALL1(STG_REGISTER, protocol_register, &proto_reverse_connect);
index 7e75e74a8fd92542f0107bf407f8ee84a91fdacb..a9a114bca2b7a1f49ca7fc74e3887274e10ae561 100644 (file)
@@ -1101,6 +1101,10 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
                str2 += 9;
                ss.ss_family = AF_CUST_SOCKPAIR;
        }
+       else if (strncmp(str2, "rev@", 3) == 0) {
+               str2 += 4;
+               ss.ss_family = AF_CUST_REV_SRV;
+       }
        else if (*str2 == '/') {
                ss.ss_family = AF_UNIX;
        }
@@ -1188,6 +1192,9 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
                        memcpy(un->sun_path, pfx, prefix_path_len);
                memcpy(un->sun_path + prefix_path_len + abstract, str2, adr_len + 1 - abstract);
        }
+       else if (ss.ss_family == AF_CUST_REV_SRV) {
+               /* Nothing to do here. */
+       }
        else { /* IPv4 and IPv6 */
                char *end = str2 + strlen(str2);
                char *chr;