mirror of
https://github.com/yrutschle/sslh.git
synced 2025-04-17 17:32:20 +03:00
code cleanup
This commit is contained in:
parent
2f111b6b8d
commit
416a82fcc6
2
common.c
2
common.c
@ -498,7 +498,7 @@ void connect_addr(struct connection *cnx, int fd_from, connect_blocking blocking
|
|||||||
cnx->q[1].fd = fd;
|
cnx->q[1].fd = fd;
|
||||||
|
|
||||||
if (cnx->proto->proxyprotocol_is_present) {
|
if (cnx->proto->proxyprotocol_is_present) {
|
||||||
int res = pp_write_header(cnx->proto->proxyprotocol, cnx);
|
pp_write_header(cnx->proto->proxyprotocol, cnx);
|
||||||
/* If pp_write_header() fails, it already logs a message and there is
|
/* If pp_write_header() fails, it already logs a message and there is
|
||||||
* nothing much we can do. The server side will probably close the
|
* nothing much we can do. The server side will probably close the
|
||||||
* connection */
|
* connection */
|
||||||
|
@ -44,6 +44,32 @@ static int family_to_pp(int af_family)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef char libpp_addr[108];
|
||||||
|
|
||||||
|
/* Fills *addr, *host and *serv with the connection information corresponding
|
||||||
|
* to fd. *host is the IP address as string and *serv is the service (port)
|
||||||
|
* */
|
||||||
|
static int get_info(int fd, struct addrinfo* addr, libpp_addr* host, uint16_t* serv)
|
||||||
|
{
|
||||||
|
char serv_str[NI_MAXSERV];
|
||||||
|
int res;
|
||||||
|
|
||||||
|
res = getpeername(fd, addr->ai_addr, &addr->ai_addrlen);
|
||||||
|
CHECK_RES_RETURN(res, "getpeername", -1);
|
||||||
|
|
||||||
|
res = getnameinfo(addr->ai_addr, addr->ai_addrlen,
|
||||||
|
(char*)host, sizeof(*host),
|
||||||
|
serv_str, sizeof(serv_str),
|
||||||
|
NI_NUMERICHOST | NI_NUMERICSERV );
|
||||||
|
CHECK_RES_RETURN(res, "getnameinfo", -1);
|
||||||
|
|
||||||
|
*serv = atoi(serv_str);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int pp_write_header(int pp_version, struct connection* cnx)
|
int pp_write_header(int pp_version, struct connection* cnx)
|
||||||
{
|
{
|
||||||
pp_info_t pp_info_in_v1 = {
|
pp_info_t pp_info_in_v1 = {
|
||||||
@ -54,28 +80,24 @@ int pp_write_header(int pp_version, struct connection* cnx)
|
|||||||
|
|
||||||
struct sockaddr_storage ss;
|
struct sockaddr_storage ss;
|
||||||
struct addrinfo addr;
|
struct addrinfo addr;
|
||||||
char host[NI_MAXHOST], serv[NI_MAXSERV];
|
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
addr.ai_addr = (struct sockaddr*)&ss;
|
addr.ai_addr = (struct sockaddr*)&ss;
|
||||||
addr.ai_addrlen = sizeof(ss);
|
addr.ai_addrlen = sizeof(ss);
|
||||||
|
|
||||||
res = getpeername(cnx->q[0].fd, addr.ai_addr, &addr.ai_addrlen);
|
res = get_info(cnx->q[0].fd,
|
||||||
res = getnameinfo(addr.ai_addr, addr.ai_addrlen,
|
&addr,
|
||||||
host, sizeof(host),
|
&pp_info_in_v1.src_addr,
|
||||||
serv, sizeof(serv),
|
&pp_info_in_v1.src_port);
|
||||||
NI_NUMERICHOST | NI_NUMERICSERV );
|
if (res == -1) return -1;
|
||||||
memcpy(pp_info_in_v1.src_addr, host, sizeof(pp_info_in_v1.src_addr));
|
|
||||||
pp_info_in_v1.src_port = atoi(serv);
|
|
||||||
pp_info_in_v1.address_family = family_to_pp(addr.ai_addr->sa_family);
|
pp_info_in_v1.address_family = family_to_pp(addr.ai_addr->sa_family);
|
||||||
|
|
||||||
res = getpeername(cnx->q[1].fd, addr.ai_addr, &addr.ai_addrlen);
|
res = get_info(cnx->q[1].fd,
|
||||||
res = getnameinfo(addr.ai_addr, addr.ai_addrlen,
|
&addr,
|
||||||
host, sizeof(host),
|
&pp_info_in_v1.dst_addr,
|
||||||
serv, sizeof(serv),
|
&pp_info_in_v1.dst_port
|
||||||
NI_NUMERICHOST | NI_NUMERICSERV );
|
);
|
||||||
memcpy(pp_info_in_v1.dst_addr, host, sizeof(pp_info_in_v1.dst_addr));
|
if (res == -1) return -1;
|
||||||
pp_info_in_v1.dst_port = atoi(serv);
|
|
||||||
|
|
||||||
uint8_t *pp1_hdr = pp_create_hdr(pp_version, &pp_info_in_v1, &pp1_hdr_len, &error);
|
uint8_t *pp1_hdr = pp_create_hdr(pp_version, &pp_info_in_v1, &pp1_hdr_len, &error);
|
||||||
|
|
||||||
|
2
test.cfg
2
test.cfg
@ -45,7 +45,7 @@ protocols:
|
|||||||
(
|
(
|
||||||
{ name: "ssh"; host: "localhost"; port: "9000"; fork: true; transparent: true; resolve_on_forward: true; },
|
{ name: "ssh"; host: "localhost"; port: "9000"; fork: true; transparent: true; resolve_on_forward: true; },
|
||||||
{ name: "socks5"; host: "localhost"; port: "9001"; },
|
{ name: "socks5"; host: "localhost"; port: "9001"; },
|
||||||
{ name: "http"; host: "www.lemonde.fr"; port: "80"; proxyprotocol: 1; },
|
{ name: "http"; host: "localhost"; port: "80"; proxyprotocol: 1; },
|
||||||
{ name: "tinc"; host: "localhost"; port: "9003"; },
|
{ name: "tinc"; host: "localhost"; port: "9003"; },
|
||||||
{ name: "openvpn"; host: "localhost"; port: "9004"; },
|
{ name: "openvpn"; host: "localhost"; port: "9004"; },
|
||||||
{ name: "xmpp"; host: "localhost"; port: "9009"; },
|
{ name: "xmpp"; host: "localhost"; port: "9009"; },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user