Hello.

The list appears to be somewhat silent, but I will write in anyway.

I'm trying to add IPv6 support into nsca-ng client by using
BIO_new_socket instead of BIO_new_connect and creating the socket by hand.
Looks like I'm in need for some help with libev.
Here is the main part of the current code: https://rurz.us/p/b6J

@@ -259,14 +262,51 @@ tls_connect(tls_client_state *ctx,

        tls_on_timeout(tls, handle_timeout);

-       if ((tls->bio = BIO_new_connect((char *)server)) == NULL)
-               log_tls_message(die, "Cannot create BIO object");
+       struct addrinfo req;
+       struct addrinfo *res;
+       memset(&req, 0, sizeof(struct addrinfo)); // Don't forget to free it
+
+       if (ip_ver == 6) {
+         req.ai_family = AF_INET6;
+       } else if (ip_ver == 4) {
+         req.ai_family = AF_INET;
+       } else {
+         req.ai_family = AF_UNSPEC;
+       }
+       req.ai_socktype = SOCK_STREAM;
+       req.ai_flags = AI_NUMERICSERV;
+       req.ai_protocol = IPPROTO_TCP;
+
+       int gai_rc = getaddrinfo((char *)server, port, &req, &res);
+       if (gai_rc != 0) {
+         char *errstr;
+         sprintf(errstr, "gai_error: %s", gai_strerror(gai_rc));
+         log_tls_message(die, errstr);
+       }
+       int sfd = socket(res->ai_family, res->ai_socktype,
res->ai_protocol);
+       // add connection loop
+       connect(sfd, res->ai_addr, res->ai_addrlen); // check for
connection errors here
+       freeaddrinfo(res); // Don't need it anymore
+
+       if ((tls->bio = BIO_new_socket(sfd, BIO_CLOSE)) == NULL) {
+         log_tls_message(die, "Cannot create BIO object");
+       }
        (void)BIO_set_nbio(tls->bio, 1);

The client is able to connect to dual-stack nsca-ng server and finish
the TLS handshake using both ipv6 and ipv4 (I've added -6 and -4 command
line options), but it never actually sends MOIN 1. From the logs and
straces from both the client and server it looks like the write callback
on the socket BIO buffer never fires.
Here is the log: https://rurz.us/p/b4c

send_nsca: [DEBUG] send_nsca 1.4-4-g329e76c-dirty (OpenSSL 1.0.2d, libev
4.19 with epoll) starting up
send_nsca: [DEBUG] Starting TLS client
send_nsca: [DEBUG] Initializing connection context
send_nsca: [DEBUG] Creating buffer (address: 0x2106a80)
send_nsca: [DEBUG] Creating buffer (address: 0x2107cf0)
send_nsca: [DEBUG] TLS connection established
send_nsca: [INFO] catty.int.bakka.su (ID: wTMCAalU) C: MOIN 1 wTMCAalU
send_nsca: [DEBUG] Queueing 15 byte(s) for catty.int.bakka.su (ID: wTMCAalU)
send_nsca: [DEBUG] Writing 15 bytes to buffer (address: 0x2107cf0)
send_nsca: [DEBUG] Adding buffer block (buffer: 0x2107cf0, block: 0x211a6c0)
send_nsca: [DEBUG] Queueing 2 byte(s) for catty.int.bakka.su (ID: wTMCAalU)
send_nsca: [DEBUG] Writing 2 bytes to buffer (address: 0x2107cf0)
send_nsca: [DEBUG] Waiting for a line from catty.int.bakka.su (ID: wTMCAalU)
send_nsca: [DEBUG] Resetting output watcher state for catty.int.bakka.su
(ID: wTMCAalU)
--- A long time-out occurs here.
send_nsca: [DEBUG] Buffered 27 bytes from catty.int.bakka.su (ID: wTMCAalU)
send_nsca: [DEBUG] Writing 27 bytes to buffer (address: 0x2106a80)
send_nsca: [DEBUG] Adding buffer block (buffer: 0x2106a80, block: 0x211adb0)
send_nsca: [DEBUG] Detaching buffer block (buffer: 0x2106a80, block:
0x211adb0)
send_nsca: [DEBUG] Received complete line from catty.int.bakka.su (ID:
wTMCAalU)
send_nsca: [INFO] catty.int.bakka.su (ID: wTMCAalU) S: BAIL Connection
timed out
send_nsca: [DEBUG] Stopping TLS client
send_nsca: [FATAL] Server said: BAIL Connection timed out
send_nsca: [DEBUG] Detaching buffer block (buffer: 0x2107cf0, block:
0x211a6c0)
send_nsca: [DEBUG] Sent 17 bytes to catty.int.bakka.su (ID: wTMCAalU),
as requested
send_nsca: [DEBUG] Initiating shutdown of connection to
catty.int.bakka.su (ID: wTMCAalU)
send_nsca: [DEBUG] Sent TLS `close notify' alert to catty.int.bakka.su
(ID: wTMCAalU)
send_nsca: [DEBUG] TLS shutdown with catty.int.bakka.su (ID: wTMCAalU)
successful
send_nsca: [DEBUG] Destroying connection context
send_nsca: [DEBUG] Destroying buffer (address: 0x2106a80)
send_nsca: [DEBUG] Destroying buffer (address: 0x2107cf0)
send_nsca: [DEBUG] Destroying configuration context

Reply via email to