Changeset df67b48 for irc_commands.c


Ignore:
Timestamp:
2017-04-03T20:55:50Z (7 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
b1b9453
Parents:
c39cd8e
Message:

Add PROXY command. Not actually an IRC protocol command, it's a HAProxy
trick supported by stunnel to indicate where the connection originally
came from. Looks a little better on public servers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc_commands.c

    rc39cd8e rdf67b48  
    5757                irc_check_login(irc);
    5858        }
     59}
     60
     61/* http://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
     62
     63   This isn't actually IRC, it's used by for example stunnel4 to indicate
     64   the origin of the secured counterpart of the connection. It'll go wrong
     65   with arguments starting with : like for example "::1" but I guess I'm
     66   okay with that. */
     67static void irc_cmd_proxy(irc_t *irc, char **cmd)
     68{
     69        struct addrinfo hints, *ai;
     70        struct sockaddr_storage sock;
     71        socklen_t socklen = sizeof(sock);
     72
     73        if (getpeername(irc->fd, (struct sockaddr*) &sock, &socklen) != 0) {
     74                return;
     75        }
     76
     77        ipv64_normalise_mapped(&sock, &socklen);
     78
     79        /* Only accept PROXY "command" on localhost sockets. */
     80        if (!((sock.ss_family == AF_INET &&
     81               ntohl(((struct sockaddr_in*)&sock)->sin_addr.s_addr) == INADDR_LOOPBACK) ||
     82              (sock.ss_family == AF_INET6 &&
     83               IN6_IS_ADDR_LOOPBACK(&((struct sockaddr_in6*)&sock)->sin6_addr)))) {
     84                return;
     85        }
     86
     87        /* And only once. Do this with a pretty dumb regex-match for
     88           now, maybe better to use some sort of flag.. */
     89        if (!g_regex_match_simple("^(ip6-)?localhost(.(localdomain.?)?)?$", irc->user->host, 0, 0)) {
     90                return;
     91        }
     92       
     93        memset(&hints, 0, sizeof(hints));
     94        hints.ai_flags = AI_NUMERICHOST;
     95        if (getaddrinfo(cmd[2], NULL, &hints, &ai) != 0) {
     96                return;
     97        }
     98       
     99        irc_set_hosts(irc, ai->ai_addr, ai->ai_addrlen);
     100        freeaddrinfo(ai);
    59101}
    60102
     
    808850        { "cap",         1, irc_cmd_cap,         0 },
    809851        { "pass",        1, irc_cmd_pass,        0 },
     852        { "proxy",       5, irc_cmd_proxy,       IRC_CMD_PRE_LOGIN },
    810853        { "user",        4, irc_cmd_user,        IRC_CMD_PRE_LOGIN },
    811854        { "nick",        1, irc_cmd_nick,        0 },
Note: See TracChangeset for help on using the changeset viewer.