Browse Source

Revert "Refine ip initialization"

This reverts commit 9a56155513.
pull/2135/merge
Max Lv 6 years ago
parent
commit
fad3ca59e7
1 changed files with 17 additions and 21 deletions
  1. 38
      src/local.c

38
src/local.c

@ -358,7 +358,6 @@ server_handshake(EV_P_ ev_io *w, buffer_t *buf)
} }
char host[257], ip[INET6_ADDRSTRLEN], port[16]; char host[257], ip[INET6_ADDRSTRLEN], port[16];
int resolved = 0;
buffer_t *abuf = server->abuf; buffer_t *abuf = server->abuf;
abuf->idx = 0; abuf->idx = 0;
@ -382,7 +381,6 @@ server_handshake(EV_P_ ev_io *w, buffer_t *buf)
inet_ntop(AF_INET, (const void *)(buf->data + request_len), inet_ntop(AF_INET, (const void *)(buf->data + request_len),
ip, INET_ADDRSTRLEN); ip, INET_ADDRSTRLEN);
sprintf(port, "%d", p); sprintf(port, "%d", p);
resolved = 1;
} }
} else if (atyp == 3) { } else if (atyp == 3) {
// Domain name // Domain name
@ -415,7 +413,6 @@ server_handshake(EV_P_ ev_io *w, buffer_t *buf)
inet_ntop(AF_INET6, (const void *)(buf->data + request_len), inet_ntop(AF_INET6, (const void *)(buf->data + request_len),
ip, INET6_ADDRSTRLEN); ip, INET6_ADDRSTRLEN);
sprintf(port, "%d", p); sprintf(port, "%d", p);
resolved = 1;
} }
} else { } else {
LOGE("unsupported addrtype: %d", request->atyp); LOGE("unsupported addrtype: %d", request->atyp);
@ -474,6 +471,9 @@ server_handshake(EV_P_ ev_io *w, buffer_t *buf)
#endif #endif
) { ) {
int bypass = 0; int bypass = 0;
#ifndef __ANDROID__
int resolved = 0;
#endif
struct sockaddr_storage storage; struct sockaddr_storage storage;
memset(&storage, 0, sizeof(struct sockaddr_storage)); memset(&storage, 0, sizeof(struct sockaddr_storage));
int err; int err;
@ -491,19 +491,18 @@ server_handshake(EV_P_ ev_io *w, buffer_t *buf)
if (atyp == 3) { // resolve domain so we can bypass domain with geoip if (atyp == 3) { // resolve domain so we can bypass domain with geoip
err = get_sockaddr(host, port, &storage, 0, ipv6first); err = get_sockaddr(host, port, &storage, 0, ipv6first);
if (err != -1) { if (err != -1) {
resolved = 1;
switch (((struct sockaddr *)&storage)->sa_family) { switch (((struct sockaddr *)&storage)->sa_family) {
case AF_INET: case AF_INET:
{ {
struct sockaddr_in *addr_in = (struct sockaddr_in *)&storage; struct sockaddr_in *addr_in = (struct sockaddr_in *)&storage;
inet_ntop(AF_INET, &(addr_in->sin_addr), ip, INET_ADDRSTRLEN); inet_ntop(AF_INET, &(addr_in->sin_addr), ip, INET_ADDRSTRLEN);
resolved = 1;
break; break;
} }
case AF_INET6: case AF_INET6:
{ {
struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)&storage; struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)&storage;
inet_ntop(AF_INET6, &(addr_in6->sin6_addr), ip, INET6_ADDRSTRLEN); inet_ntop(AF_INET6, &(addr_in6->sin6_addr), ip, INET6_ADDRSTRLEN);
resolved = 1;
break; break;
} }
default: default:
@ -512,19 +511,17 @@ server_handshake(EV_P_ ev_io *w, buffer_t *buf)
} }
} }
#endif #endif
if (resolved) {
int ip_match = acl_match_host(ip);
switch (get_acl_mode()) {
case BLACK_LIST:
if (ip_match > 0)
bypass = 1; // bypass IPs in black list
break;
case WHITE_LIST:
bypass = 1;
if (ip_match < 0)
bypass = 0; // proxy IPs in white list
break;
}
int ip_match = acl_match_host(ip);
switch (get_acl_mode()) {
case BLACK_LIST:
if (ip_match > 0)
bypass = 1; // bypass IPs in black list
break;
case WHITE_LIST:
bypass = 1;
if (ip_match < 0)
bypass = 0; // proxy IPs in white list
break;
} }
} }
@ -538,12 +535,11 @@ server_handshake(EV_P_ ev_io *w, buffer_t *buf)
LOGI("bypass [%s]:%s", ip, port); LOGI("bypass [%s]:%s", ip, port);
} }
#ifndef __ANDROID__ #ifndef __ANDROID__
if (atyp == 3 && !resolved)
if (atyp == 3 && resolved != 1)
err = get_sockaddr(host, port, &storage, 0, ipv6first); err = get_sockaddr(host, port, &storage, 0, ipv6first);
else else
#endif #endif
if (resolved)
err = get_sockaddr(ip, port, &storage, 0, ipv6first);
err = get_sockaddr(ip, port, &storage, 0, ipv6first);
if (err != -1) { if (err != -1) {
remote = create_remote(server->listener, (struct sockaddr *)&storage); remote = create_remote(server->listener, (struct sockaddr *)&storage);
if (remote != NULL) if (remote != NULL)

Loading…
Cancel
Save