修复根据fd创建stream addr时源目的地址颠倒的问题。修复HTTP业务层IP扫描不命中问题。

This commit is contained in:
zhengchao
2018-09-30 11:55:50 +08:00
parent 966d36b526
commit 5a014f796e
5 changed files with 53 additions and 26 deletions

View File

@@ -21,11 +21,6 @@ enum tfe_app_proto
APP_PROTO_QUIC //QUIC is a protocol that cross session layer and application layer.
};
enum tfe_conn_dir
{
CONN_DIR_DOWNSTREAM = 0, //From client to proxy, aka client-side.
CONN_DIR_UPSTREAM //From proxy to server, aka server-side.
};
enum tfe_conn_status
{

View File

@@ -8,6 +8,11 @@
#include <netinet/in.h> //defines struct in_addr
#include <arpa/inet.h>
enum tfe_conn_dir
{
CONN_DIR_DOWNSTREAM = 0, //From client to proxy, aka client-side.
CONN_DIR_UPSTREAM //From proxy to server, aka server-side.
};
/* network-order */
struct tfe_stream_addr_tuple4_v4
@@ -181,7 +186,7 @@ static inline void tfe_stream_addr_free(struct tfe_stream_addr *addr)
free(addr);
return;
}
static inline struct tfe_stream_addr * tfe_stream_addr_create_by_fd(int fd)
static inline struct tfe_stream_addr * tfe_stream_addr_create_by_fd(int fd, enum tfe_conn_dir dir)
{
struct tfe_stream_addr * __stream_addr = NULL;
@@ -192,17 +197,33 @@ static inline struct tfe_stream_addr * tfe_stream_addr_create_by_fd(int fd)
struct sockaddr_storage sk_dst_storage{};
struct sockaddr * sk_dst_ptr = (struct sockaddr *) &sk_dst_storage;
socklen_t sk_dst_len = sizeof(sk_dst_storage);
int ret = getsockname(fd, sk_src_ptr, &sk_src_len);
if (ret < 0)
if(dir==CONN_DIR_UPSTREAM)
{
goto __errout;
int ret = getsockname(fd, sk_src_ptr, &sk_src_len);
if (ret < 0)
{
goto __errout;
}
ret = getpeername(fd, sk_dst_ptr, &sk_dst_len);
if (ret < 0)
{
goto __errout;
}
}
ret = getpeername(fd, sk_dst_ptr, &sk_dst_len);
if (ret < 0)
else
{
goto __errout;
int ret = getsockname(fd, sk_dst_ptr, &sk_dst_len);
if (ret < 0)
{
goto __errout;
}
ret = getpeername(fd, sk_src_ptr, &sk_src_len);
if (ret < 0)
{
goto __errout;
}
}
assert(sk_src_ptr->sa_family == sk_dst_ptr->sa_family);