diff --git a/README.md b/README.md index c4ca601..19c3bba 100644 --- a/README.md +++ b/README.md @@ -69,8 +69,8 @@ ciadpi --fake -1 --ttl 8 Таймаут ожидания первого ответа от сервера в секундах В Linux переводится в миллисекунды, поэтому можно указать дробное число --K, --proto - Белый список протоколов: tls,http,udp +-K, --proto + Белый список протоколов: tls,http,udp,ipv4 -H, --hosts Ограничить область действия параметров списком доменов diff --git a/extend.c b/extend.c index b23da79..99f5978 100644 --- a/extend.c +++ b/extend.c @@ -117,13 +117,6 @@ static int cache_add(const struct sockaddr_ina *dst, int m) } -static inline bool check_port(const uint16_t *p, const struct sockaddr_in6 *dst) -{ - return (dst->sin6_port >= p[0] - && dst->sin6_port <= p[1]); -} - - int connect_hook(struct poolhd *pool, struct eval *val, const struct sockaddr_ina *dst, int next) { @@ -195,10 +188,10 @@ static bool check_host( return 0; } - + static bool check_proto_tcp(int proto, const char *buffer, ssize_t n) { - if (proto & IS_TCP) { + if (!(proto & ~IS_IPV4)) { return 1; } else if ((proto & IS_HTTP) && @@ -213,6 +206,27 @@ static bool check_proto_tcp(int proto, const char *buffer, ssize_t n) } +static bool check_l34(int proto, const uint16_t *pf, int st, const struct sockaddr_in6 *dst) +{ + if ((proto & IS_UDP) && (st != SOCK_DGRAM)) { + return 0; + } + if (proto & IS_IPV4) { + static const char *pat = "\0\0\0\0\0\0\0\0\0\0\xff\xff"; + + if (dst->sin6_family != AF_INET + && memcmp(&dst->sin6_addr, pat, 12)) { + return 0; + } + } + if (pf[0] && + (dst->sin6_port < pf[0] || dst->sin6_port > pf[1])) { + return 0; + } + return 1; +} + + static bool check_round(const int *nr, int r) { return (!nr[1] && r <= 1) || (r >= nr[0] && r <= nr[1]); @@ -325,10 +339,10 @@ static int setup_conn(struct eval *client, const char *buffer, ssize_t n) if (!m) for (; m < params.dp_count; m++) { struct desync_params *dp = ¶ms.dp[m]; - if (!dp->detect && - (!dp->pf[0] || check_port(dp->pf, &client->pair->in6)) && - (!dp->proto || check_proto_tcp(dp->proto, buffer, n)) && - (!dp->hosts || check_host(dp->hosts, buffer, n))) { + if (!dp->detect + && (check_l34(dp->proto, dp->pf, SOCK_STREAM, &client->pair->in6) + && check_proto_tcp(dp->proto, buffer, n)) + && (!dp->hosts || check_host(dp->hosts, buffer, n))) { break; } } @@ -528,9 +542,8 @@ ssize_t udp_hook(struct eval *val, if (!m) { for (; m < params.dp_count; m++) { struct desync_params *dp = ¶ms.dp[m]; - if (!dp->detect && - (!dp->proto || (dp->proto & IS_UDP)) && - (!dp->pf[0] || check_port(dp->pf, &dst->in6))) { + if (!dp->detect + && check_l34(dp->proto, dp->pf, SOCK_DGRAM, &dst->in6)) { break; } } diff --git a/main.c b/main.c index c0cefdc..71ccbba 100644 --- a/main.c +++ b/main.c @@ -83,7 +83,7 @@ const static char help_text[] = { #ifdef TIMEOUT_SUPPORT " -T, --timeout Timeout waiting for response, after which trigger auto\n" #endif - " -K, --proto Protocol whitelist: tls,http,udp\n" + " -K, --proto Protocol whitelist: tls,http,udp,ipv4\n" " -H, --hosts Hosts whitelist, filename or :string\n" " -V, --pf Ports range whitelist\n" " -R, --round Number of request to which desync will be applied\n" @@ -687,6 +687,9 @@ int main(int argc, char **argv) case 'u': dp->proto |= IS_UDP; break; + case 'i': + dp->proto |= IS_IPV4; + break; default: invalid = 1; continue; diff --git a/packets.h b/packets.h index e2ddb42..48ab133 100644 --- a/packets.h +++ b/packets.h @@ -10,8 +10,9 @@ #define IS_UDP 2 #define IS_HTTP 4 #define IS_HTTPS 8 -//#define IS_QUIC 16 -//#define IS_DNS 32 +#define IS_IPV4 16 +//#define IS_QUIC 64 +//#define IS_DNS 128 #define MH_HMIX 1 #define MH_SPACE 2