Subdomain, logs

This commit is contained in:
ruti 2024-07-18 23:59:44 +03:00
parent c732673c76
commit 4d965ebff3
3 changed files with 47 additions and 12 deletions

View File

@ -64,4 +64,11 @@ static inline const int unie(int e)
#define LOG(s, str, ...) \ #define LOG(s, str, ...) \
if (params.debug >= s) \ if (params.debug >= s) \
fprintf(stderr, str, ##__VA_ARGS__) fprintf(stderr, str, ##__VA_ARGS__)
#endif #endif
#define INIT_ADDR_STR(dst) \
char ADDR_STR[INET_ADDRSTRLEN + 1]; \
if (dst.sa.sa_family == AF_INET) \
inet_ntop(AF_INET, &dst.in.sin_addr, ADDR_STR, sizeof(ADDR_STR)); \
else \
inet_ntop(AF_INET6, &dst.in6.sin6_addr, ADDR_STR, sizeof(ADDR_STR));

View File

@ -128,7 +128,19 @@ bool check_host(struct mphdr *hosts, struct eval *val)
len = parse_http(val->buff.data, val->buff.size, &host, 0); len = parse_http(val->buff.data, val->buff.size, &host, 0);
} }
assert(len == 0 || host != 0); assert(len == 0 || host != 0);
return (len > 0) && mem_get(hosts, host, len) != 0; if (len <= 0) {
return 0;
}
char *e = host + len;
for (; host < e; host++) {
if (mem_get(hosts, host, e - host)) {
return 1;
}
if (!(host = memchr(host, '.', e - host))) {
return 0;
}
}
return 0;
} }
@ -259,13 +271,15 @@ int on_tunnel_check(struct poolhd *pool, struct eval *val,
if (!pair->cache) { if (!pair->cache) {
return 0; return 0;
} }
struct sockaddr_ina *addr = (struct sockaddr_ina *)&val->in6;
if (m == 0) { if (m == 0) {
LOG(LOG_S, "delete ip: m=%d\n", m); LOG(LOG_S, "delete ip: m=%d\n", m);
} else { } else {
LOG(LOG_S, "save ip: m=%d\n", m); INIT_ADDR_STR((*addr));
LOG(LOG_S, "save ip: %s, m=%d\n", ADDR_STR, m);
} }
return mode_add_get( return mode_add_get(addr, m);
(struct sockaddr_ina *)&val->in6, m);
} }

28
proxy.c
View File

@ -505,6 +505,7 @@ static inline int on_accept(struct poolhd *pool, struct eval *val)
uniperror("accept"); uniperror("accept");
return -1; return -1;
} }
LOG(LOG_L, "accept: fd=%d\n", c);
#ifndef __linux__ #ifndef __linux__
#ifdef _WIN32 #ifdef _WIN32
unsigned long mode = 1; unsigned long mode = 1;
@ -753,8 +754,14 @@ static inline int on_request(struct poolhd *pool, struct eval *val,
int en = get_e(); int en = get_e();
if (resp_error(val->fd, en ? en : error, val->flag) < 0) if (resp_error(val->fd, en ? en : error, val->flag) < 0)
uniperror("send"); uniperror("send");
LOG(LOG_S, "ss error: %d\n", en);
return -1; return -1;
} }
if (params.debug) {
INIT_ADDR_STR(dst);
LOG(LOG_L, "new conn: fd=%d, addr=%s:%d\n",
val->pair->fd, ADDR_STR, ntohs(dst.in.sin_port));
}
return 0; return 0;
} }
@ -787,6 +794,13 @@ static inline int on_connect(struct poolhd *pool, struct eval *val, int e)
} }
void close_conn(struct poolhd *pool, struct eval *val)
{
LOG(LOG_L, "close: fds=%d,%d\n", val->fd, val->pair ? val->pair->fd : -1);
del_event(pool, val);
}
int event_loop(int srvfd) int event_loop(int srvfd)
{ {
size_t bfsize = params.bfsize; size_t bfsize = params.bfsize;
@ -835,39 +849,39 @@ int event_loop(int srvfd)
case EV_REQUEST: case EV_REQUEST:
if ((etype & POLLHUP) || if ((etype & POLLHUP) ||
on_request(pool, val, buffer, bfsize)) on_request(pool, val, buffer, bfsize))
del_event(pool, val); close_conn(pool, val);
continue; continue;
case EV_PRE_TUNNEL: case EV_PRE_TUNNEL:
if (on_tunnel_check(pool, val, if (on_tunnel_check(pool, val,
buffer, bfsize, etype & POLLOUT)) buffer, bfsize, etype & POLLOUT))
del_event(pool, val); close_conn(pool, val);
continue; continue;
case EV_TUNNEL: case EV_TUNNEL:
if (on_tunnel(pool, val, buffer, bfsize, etype)) if (on_tunnel(pool, val, buffer, bfsize, etype))
del_event(pool, val); close_conn(pool, val);
continue; continue;
case EV_UDP_TUNNEL: case EV_UDP_TUNNEL:
if (on_udp_tunnel(val, buffer, bfsize)) if (on_udp_tunnel(val, buffer, bfsize))
del_event(pool, val); close_conn(pool, val);
continue; continue;
case EV_CONNECT: case EV_CONNECT:
if (on_connect(pool, val, etype & POLLERR)) if (on_connect(pool, val, etype & POLLERR))
del_event(pool, val); close_conn(pool, val);
continue; continue;
case EV_DESYNC: case EV_DESYNC:
if (on_desync(pool, val, if (on_desync(pool, val,
buffer, bfsize, etype & POLLOUT)) buffer, bfsize, etype & POLLOUT))
del_event(pool, val); close_conn(pool, val);
continue; continue;
case EV_IGNORE: case EV_IGNORE:
if (etype & (POLLHUP | POLLERR | POLLRDHUP)) if (etype & (POLLHUP | POLLERR | POLLRDHUP))
del_event(pool, val); close_conn(pool, val);
continue; continue;
default: default: