mirror of
https://github.com/bol-van/zapret.git
synced 2025-05-09 15:22:57 +03:00
tpws: ipcache socks hostname
This commit is contained in:
parent
6eae2b0e71
commit
ed0bb4c106
@ -12,6 +12,7 @@
|
||||
// this saves memory. sockaddr_storage is larger than required. it can be 128 bytes. sockaddr_in6 is 28 bytes.
|
||||
typedef union
|
||||
{
|
||||
sa_family_t sa_family;
|
||||
struct sockaddr_in sa4; // size 16
|
||||
struct sockaddr_in6 sa6; // size 28
|
||||
} sockaddr_in46;
|
||||
|
@ -91,7 +91,7 @@ static void TLSDebug(const uint8_t *tls,size_t sz)
|
||||
TLSDebugHandshake(tls+5,sz-5);
|
||||
}
|
||||
|
||||
static bool ipcache_put_hostname(const struct in_addr *a4, const struct in6_addr *a6, const char *hostname)
|
||||
bool ipcache_put_hostname(const struct in_addr *a4, const struct in6_addr *a6, const char *hostname)
|
||||
{
|
||||
if (!params.cache_hostname) return true;
|
||||
|
||||
@ -101,13 +101,16 @@ static bool ipcache_put_hostname(const struct in_addr *a4, const struct in6_addr
|
||||
DLOG_ERR("ipcache_put_hostname: out of memory\n");
|
||||
return false;
|
||||
}
|
||||
free(ipc->hostname);
|
||||
if (!(ipc->hostname = strdup(hostname)))
|
||||
if (!ipc->hostname || strcmp(ipc->hostname,hostname))
|
||||
{
|
||||
DLOG_ERR("ipcache_put_hostname: out of memory\n");
|
||||
return false;
|
||||
free(ipc->hostname);
|
||||
if (!(ipc->hostname = strdup(hostname)))
|
||||
{
|
||||
DLOG_ERR("ipcache_put_hostname: out of memory\n");
|
||||
return false;
|
||||
}
|
||||
VPRINT("hostname cached: %s\n", hostname);
|
||||
}
|
||||
VPRINT("hostname cached: %s\n", hostname);
|
||||
return true;
|
||||
}
|
||||
static bool ipcache_get_hostname(const struct in_addr *a4, const struct in6_addr *a6, char *hostname, size_t hostname_buf_len)
|
||||
|
@ -21,6 +21,7 @@ typedef struct
|
||||
} t_ctrack;
|
||||
|
||||
void apply_desync_profile(t_ctrack *ctrack, const struct sockaddr *dest);
|
||||
bool ipcache_put_hostname(const struct in_addr *a4, const struct in6_addr *a6, const char *hostname);
|
||||
|
||||
void tamper_out(t_ctrack *ctrack, const struct sockaddr *dest, uint8_t *segment,size_t segment_buffer_size,size_t *size, size_t *multisplit_pos, int *multisplit_count, uint8_t *split_flags);
|
||||
void tamper_in(t_ctrack *ctrack, const struct sockaddr *client, uint8_t *segment,size_t segment_buffer_size,size_t *size);
|
||||
|
@ -494,6 +494,9 @@ static bool connect_remote_conn(tproxy_conn_t *conn)
|
||||
{
|
||||
int mss=0;
|
||||
|
||||
if (conn->track.hostname)
|
||||
if (!ipcache_put_hostname(conn->dest.sa_family==AF_INET ? &((struct sockaddr_in*)&conn->dest)->sin_addr : NULL, conn->dest.sa_family==AF_INET6 ? &((struct sockaddr_in6*)&conn->dest)->sin6_addr : NULL , conn->track.hostname))
|
||||
DLOG_ERR("ipcache_put_hostname: out of memory");
|
||||
apply_desync_profile(&conn->track, (struct sockaddr *)&conn->dest);
|
||||
|
||||
if (conn->track.dp && conn->track.dp->mss)
|
||||
@ -1087,7 +1090,8 @@ static bool resolve_complete(struct resolve_item *ri, struct tailhead *conn_list
|
||||
if (!conn->track.hostname)
|
||||
{
|
||||
DBGPRINT("resolve_complete put hostname : %s\n", ri->dom);
|
||||
conn->track.hostname = strdup(ri->dom);
|
||||
if (!(conn->track.hostname = strdup(ri->dom)))
|
||||
DLOG_ERR("dup hostname: out of memory\n");
|
||||
}
|
||||
sa46copy(&conn->dest, (struct sockaddr *)&ri->ss);
|
||||
return proxy_mode_connect_remote(conn,conn_list);
|
||||
|
Loading…
x
Reference in New Issue
Block a user