Merge pull request #37 from zabbius/kern_mod

Commandline options
This commit is contained in:
Vadim Vetrov 2024-08-07 10:37:10 -07:00 committed by GitHub
commit eac78de701
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 370 additions and 189 deletions

View File

@ -1,3 +1,17 @@
struct config_t {
unsigned int queue_start_num;
int rawsocket;
int threads;
int use_gso;
int fragmentation_strategy;
unsigned char fake_sni_ttl;
int fake_sni_strategy;
int verbose;
unsigned int seg2_delay;
};
extern struct config_t config;
#define MAX_THREADS 16 #define MAX_THREADS 16
#ifndef THREADS_NUM #ifndef THREADS_NUM
@ -20,31 +34,26 @@
#define FRAGMENTATION_STRATEGY FRAG_STRAT_TCP #define FRAGMENTATION_STRATEGY FRAG_STRAT_TCP
#endif #endif
#if FRAGMENTATION_STRATEGY == FRAG_STRAT_TCP
#define USE_TCP_SEGMENTATION
#elif FRAGMENTATION_STRATEGY == FRAG_STRAT_IP
#define USE_IP_FRAGMENTATION
#elif FRAGMENTATION_STRATEGY == FRAG_STRAT_NONE
#define USE_NO_FRAGMENTATION
#endif
#define RAWSOCKET_MARK (1 << 15) #define RAWSOCKET_MARK (1 << 15)
#ifdef USE_SEG2_DELAY #ifdef USE_SEG2_DELAY
#define SEG2_DELAY 100 #define SEG2_DELAY 100
#endif #endif
#ifndef NO_FAKE_SNI
#define FAKE_SNI
#endif
#define FAKE_SNI_TTL 8 #define FAKE_SNI_TTL 8
// No fake SNI
#define FKSN_STRAT_NONE 0
// Will invalidate fake client hello by out-of-ack_seq out-of-seq request // Will invalidate fake client hello by out-of-ack_seq out-of-seq request
#define FKSN_STRAT_ACK_SEQ 0 #define FKSN_STRAT_ACK_SEQ 1
// Will assume that GGC server is located further than FAKE_SNI_TTL // Will assume that GGC server is located further than FAKE_SNI_TTL
// Thus, Fake Client Hello will be eliminated automatically. // Thus, Fake Client Hello will be eliminated automatically.
#define FKSN_STRAT_TTL 1 #define FKSN_STRAT_TTL 2
#ifdef NO_FAKE_SNI
#define FAKE_SNI_STRATEGY FKSN_STRAT_NONE
#endif
#ifndef FAKE_SNI_STRATEGY #ifndef FAKE_SNI_STRATEGY
#define FAKE_SNI_STRATEGY FKSN_STRAT_ACK_SEQ #define FAKE_SNI_STRATEGY FKSN_STRAT_ACK_SEQ

View File

@ -190,9 +190,8 @@ int ip4_frag(const __u8 *pkt, __u32 buflen, __u32 payload_offset,
f2_hdr->tot_len = htons(f2_dlen); f2_hdr->tot_len = htons(f2_dlen);
#if defined(DEBUG) if (config.verbose)
printf("Packet split in portion %u %u\n", f1_plen, f2_plen); printf("Packet split in portion %u %u\n", f1_plen, f2_plen);
#endif
ip4_set_checksum(f1_hdr); ip4_set_checksum(f1_hdr);
ip4_set_checksum(f2_hdr); ip4_set_checksum(f2_hdr);
@ -272,9 +271,8 @@ int tcp4_frag(const __u8 *pkt, __u32 buflen, __u32 payload_offset,
s2_tcph->seq = htonl(ntohl(s2_tcph->seq) + payload_offset); s2_tcph->seq = htonl(ntohl(s2_tcph->seq) + payload_offset);
#if defined(DEBUG) if (config.verbose)
printf("Packet split in portion %u %u\n", s1_plen, s2_plen); printf("Packet split in portion %u %u\n", s1_plen, s2_plen);
#endif
tcp4_set_checksum(s1_tcph, s1_hdr); tcp4_set_checksum(s1_tcph, s1_hdr);
tcp4_set_checksum(s2_tcph, s2_hdr); tcp4_set_checksum(s2_tcph, s2_hdr);

View File

@ -1,6 +1,9 @@
#!/bin/sh /etc/rc.common #!/bin/sh /etc/rc.common
USE_PROCD=1 USE_PROCD=1
START=50
STOP=50
# Openwrt procd script: https://openwrt.org/docs/guide-developer/procd-init-script-example # Openwrt procd script: https://openwrt.org/docs/guide-developer/procd-init-script-example
# The program should be put into /usr/bin/ # The program should be put into /usr/bin/
# This file should be put into /etc/init.d/ # This file should be put into /etc/init.d/

View File

@ -29,34 +29,196 @@
#include "config.h" #include "config.h"
#include "mangle.h" #include "mangle.h"
static struct { pthread_mutex_t rawsocket_lock;
uint32_t queue_start_num;
int rawsocket; struct config_t config = {
pthread_mutex_t rawsocket_lock; .rawsocket = -2,
int threads; .threads = THREADS_NUM,
} config = { .fragmentation_strategy = FRAGMENTATION_STRATEGY,
.rawsocket = -2, .fake_sni_strategy = FAKE_SNI_STRATEGY,
.threads = THREADS_NUM .fake_sni_ttl = FAKE_SNI_TTL,
#ifdef SEG2_DELAY
.seg2_delay = SEG2_DELAY,
#else
.seg2_delay = 0,
#endif
#ifdef USE_GSO
.use_gso = true,
#else
.use_gso = false,
#endif
#ifdef DEBUG
.verbose = true,
#else
.verbose = false,
#endif
}; };
const char* get_value(const char *option, const char *prefix)
{
errno = 0;
size_t prefix_len = strlen(prefix);
size_t option_len = strlen(option);
if (option_len <= prefix_len || strncmp(prefix, option, prefix_len)) {
return NULL;
}
return option + prefix_len;
}
int parse_bool_option(const char *value) {
errno = 0;
if (strcmp(value, "1") == 0) {
return 1;
}
else if (strcmp(value, "0") == 0) {
return 0;
}
errno = EINVAL;
return -1;
}
long parse_numeric_option(const char* value) {
errno = 0;
char* end;
long result = strtol(value, &end, 10);
if (*end != '\0') {
errno = EINVAL;
return 0;
}
return result;
}
int parse_option(const char* option) {
const char* value;
int ret;
if (!strcmp(option, "--no-gso")) {
config.use_gso = 0;
goto out;
}
if (!strcmp(option, "--silent")) {
config.verbose = 0;
goto out;
}
if ((value = get_value(option, "--frag=")) != 0) {
if (!value) {
goto err;
}
if (strcmp(value, "tcp") == 0) {
config.fragmentation_strategy = FRAG_STRAT_TCP;
} else if (strcmp(value, "ip") == 0) {
config.fragmentation_strategy = FRAG_STRAT_IP;
} else if (strcmp(value, "none") == 0) {
config.fragmentation_strategy = FRAG_STRAT_NONE;
} else {
goto err;
}
goto out;
}
if ((value = get_value(option, "--fake-sni=")) != 0) {
if (strcmp(value, "ack") == 0) {
config.fake_sni_strategy = FKSN_STRAT_ACK_SEQ;
} else if (strcmp(value, "ttl") == 0) {
config.fake_sni_strategy = FKSN_STRAT_TTL;
}
else if (strcmp(value, "none") == 0) {
config.fake_sni_strategy = FKSN_STRAT_NONE;
} else {
goto err;
}
goto out;
}
if ((value = get_value(option, "--seg2delay=")) != 0) {
long num = parse_numeric_option(value);
if (errno != 0 ||
num < 0)
goto err;
config.seg2_delay = num;
goto out;
}
if ((value = get_value(option, "--threads=")) != 0) {
long num = parse_numeric_option(value);
if (errno != 0 ||
num < 0 ||
num > MAX_THREADS) {
errno = EINVAL;
goto err;
}
config.threads = num;
goto out;
}
if ((value = get_value(option, "--fake-sni-ttl=")) != 0) {
long num = parse_numeric_option(value);
if (errno != 0 ||
num < 0 ||
num > 255) {
goto err;
}
config.fake_sni_ttl = num;
goto out;
}
err:
errno = EINVAL;
return -1;
out:
errno = 0;
return 0;
}
static int parse_args(int argc, const char *argv[]) { static int parse_args(int argc, const char *argv[]) {
int err; int err;
char *end; char *end;
if (argc != 2) { if (argc < 2) {
errno = EINVAL; errno = EINVAL;
goto errormsg_help; goto errormsg_help;
} }
uint32_t queue_num = strtoul(argv[1], &end, 10); config.queue_start_num = parse_numeric_option(argv[1]);
if (errno != 0 || *end != '\0') goto errormsg_help; if (errno != 0) goto errormsg_help;
for (int i = 2; i < argc; i++) {
if (parse_option(argv[i])) {
printf("Invalid option %s\n", argv[i]);
goto errormsg_help;
}
}
config.queue_start_num = queue_num;
return 0; return 0;
errormsg_help: errormsg_help:
err = errno; err = errno;
printf("Usage: %s [queue_num]\n", argv[0]); printf("Usage: %s <queue_num> [OPTIONS]\n", argv[0]);
printf("Options:\n");
printf("\t--fake-sni={ack,ttl,none}\n");
printf("\t--fake-sni-ttl=<ttl>\n");
printf("\t--frag={tcp,ip,none}\n");
printf("\t--seg2delay=<delay>\n");
printf("\t--threads=<threads number>\n");
printf("\t--silent\n");
printf("\t--no-gso\n");
errno = err; errno = err;
if (errno == 0) errno = EINVAL; if (errno == 0) errno = EINVAL;
@ -117,7 +279,7 @@ static int open_raw_socket(void) {
return -1; return -1;
} }
int mst = pthread_mutex_init(&config.rawsocket_lock, NULL); int mst = pthread_mutex_init(&rawsocket_lock, NULL);
if (mst) { if (mst) {
fprintf(stderr, "Mutex err: %d\n", mst); fprintf(stderr, "Mutex err: %d\n", mst);
close(config.rawsocket); close(config.rawsocket);
@ -139,11 +301,11 @@ static int close_raw_socket(void) {
if (close(config.rawsocket)) { if (close(config.rawsocket)) {
perror("Unable to close raw socket"); perror("Unable to close raw socket");
pthread_mutex_destroy(&config.rawsocket_lock); pthread_mutex_destroy(&rawsocket_lock);
return -1; return -1;
} }
pthread_mutex_destroy(&config.rawsocket_lock); pthread_mutex_destroy(&rawsocket_lock);
config.rawsocket = -2; config.rawsocket = -2;
return 0; return 0;
@ -154,36 +316,36 @@ static int send_raw_socket(const uint8_t *pkt, uint32_t pktlen) {
int ret; int ret;
if (pktlen > AVAILABLE_MTU) { if (pktlen > AVAILABLE_MTU) {
#ifdef DEBUG if (config.verbose)
printf("Split packet!\n"); printf("Split packet!\n");
#endif
uint8_t buff1[MNL_SOCKET_BUFFER_SIZE]; uint8_t buff1[MNL_SOCKET_BUFFER_SIZE];
uint32_t buff1_size = MNL_SOCKET_BUFFER_SIZE; uint32_t buff1_size = MNL_SOCKET_BUFFER_SIZE;
uint8_t buff2[MNL_SOCKET_BUFFER_SIZE]; uint8_t buff2[MNL_SOCKET_BUFFER_SIZE];
uint32_t buff2_size = MNL_SOCKET_BUFFER_SIZE; uint32_t buff2_size = MNL_SOCKET_BUFFER_SIZE;
#if defined(USE_TCP_SEGMENTATION) || defined(RAWSOCK_TCP_FSTRAT) switch (config.fragmentation_strategy) {
if ((ret = tcp4_frag(pkt, pktlen, AVAILABLE_MTU-128, case FRAG_STRAT_TCP:
buff1, &buff1_size, buff2, &buff2_size)) < 0) { if ((ret = tcp4_frag(pkt, pktlen, AVAILABLE_MTU-128,
buff1, &buff1_size, buff2, &buff2_size)) < 0) {
errno = -ret; errno = -ret;
return ret; return ret;
} }
#elif defined(USE_IP_FRAGMENTATION) || defined(RAWSOCK_IP_FSTRAT) break;
if ((ret = ip4_frag(pkt, pktlen, AVAILABLE_MTU-128, case FRAG_STRAT_IP:
buff1, &buff1_size, buff2, &buff2_size)) < 0) { if ((ret = ip4_frag(pkt, pktlen, AVAILABLE_MTU-128,
buff1, &buff1_size, buff2, &buff2_size)) < 0) {
errno = -ret; errno = -ret;
return ret; return ret;
}
break;
default:
errno = EINVAL;
printf("send_raw_socket: Packet is too big but fragmentation is disabled!\n");
return -EINVAL;
} }
#else
errno = EINVAL;
printf("send_raw_socket: Packet is too big but fragmentation is disabled! "
"Pass -DRAWSOCK_TCP_FSTRAT or -DRAWSOCK_IP_FSTRAT as CFLAGS "
"To enable it only for raw socket\n");
return -EINVAL;
#endif
int sent = 0; int sent = 0;
int status = send_raw_socket(buff1, buff1_size); int status = send_raw_socket(buff1, buff1_size);
@ -220,13 +382,13 @@ static int send_raw_socket(const uint8_t *pkt, uint32_t pktlen) {
} }
}; };
pthread_mutex_lock(&config.rawsocket_lock); pthread_mutex_lock(&rawsocket_lock);
int sent = sendto(config.rawsocket, int sent = sendto(config.rawsocket,
pkt, pktlen, 0, pkt, pktlen, 0,
(struct sockaddr *)&daddr, sizeof(daddr)); (struct sockaddr *)&daddr, sizeof(daddr));
pthread_mutex_unlock(&config.rawsocket_lock); pthread_mutex_unlock(&rawsocket_lock);
/* The function will return -errno on error as well as errno value set itself */ /* The function will return -errno on error as well as errno value set itself */
if (sent < 0) sent = -errno; if (sent < 0) sent = -errno;
@ -332,21 +494,14 @@ static int process_packet(const struct packet_data packet, struct queue_data qda
nfq_nlmsg_verdict_put(verdnlh, packet.id, NF_ACCEPT); nfq_nlmsg_verdict_put(verdnlh, packet.id, NF_ACCEPT);
if (vrd.gvideo_hello) { if (vrd.gvideo_hello) {
#ifdef DEBUG if (config.verbose)
printf("Google video!\n"); printf("Google video!\n");
#endif
if (dlen > 1480) { if (dlen > 1480) {
#ifdef DEBUG if (config.verbose)
fprintf(stderr, "WARNING! Google video packet is too big and may cause issues!\n"); fprintf(stderr, "WARNING! Google video packet is too big and may cause issues!\n");
#endif
} }
#ifdef FAKE_SNI
uint8_t fake_sni[MNL_SOCKET_BUFFER_SIZE];
uint32_t fsn_len = MNL_SOCKET_BUFFER_SIZE;
#endif
uint8_t frag1[MNL_SOCKET_BUFFER_SIZE]; uint8_t frag1[MNL_SOCKET_BUFFER_SIZE];
uint8_t frag2[MNL_SOCKET_BUFFER_SIZE]; uint8_t frag2[MNL_SOCKET_BUFFER_SIZE];
uint32_t f1len = MNL_SOCKET_BUFFER_SIZE; uint32_t f1len = MNL_SOCKET_BUFFER_SIZE;
@ -358,54 +513,64 @@ static int process_packet(const struct packet_data packet, struct queue_data qda
nfq_tcp_compute_checksum_ipv4( nfq_tcp_compute_checksum_ipv4(
(struct tcphdr *)tcph, (struct iphdr *)iph); (struct tcphdr *)tcph, (struct iphdr *)iph);
#ifdef FAKE_SNI if (config.fake_sni_strategy != FKSN_STRAT_NONE) {
ret = gen_fake_sni(iph, tcph, fake_sni, &fsn_len); uint8_t fake_sni[MNL_SOCKET_BUFFER_SIZE];
if (ret < 0) { uint32_t fsn_len = MNL_SOCKET_BUFFER_SIZE;
errno = -ret;
perror("gen_fake_sni"); ret = gen_fake_sni(iph, tcph, fake_sni, &fsn_len);
goto fallback; if (ret < 0) {
errno = -ret;
perror("gen_fake_sni");
goto fallback;
}
ret = send_raw_socket(fake_sni, fsn_len);
if (ret < 0) {
errno = -ret;
perror("send fake sni");
goto fallback;
}
} }
ret = send_raw_socket(fake_sni, fsn_len); size_t ipd_offset;
if (ret < 0) { size_t mid_offset;
errno = -ret;
perror("send fake sni"); switch (config.fragmentation_strategy) {
goto fallback; case FRAG_STRAT_TCP:
ipd_offset = vrd.sni_offset;
mid_offset = ipd_offset + vrd.sni_len / 2;
if ((ret = tcp4_frag(raw_payload, raw_payload_len,
mid_offset, frag1, &f1len, frag2, &f2len)) < 0) {
errno = -ret;
perror("tcp4_frag");
goto fallback;
}
break;
case FRAG_STRAT_IP:
ipd_offset = ((char *)data - (char *)tcph) + vrd.sni_offset;
mid_offset = ipd_offset + vrd.sni_len / 2;
mid_offset += 8 - mid_offset % 8;
if ((ret = ip4_frag(raw_payload, raw_payload_len,
mid_offset, frag1, &f1len, frag2, &f2len)) < 0) {
errno = -ret;
perror("ip4_frag");
goto fallback;
}
break;
default:
ret = send_raw_socket(raw_payload, raw_payload_len);
if (ret < 0) {
errno = -ret;
perror("raw pack send");
}
goto fallback;
} }
#endif
#if defined(USE_TCP_SEGMENTATION)
size_t ipd_offset = vrd.sni_offset;
size_t mid_offset = ipd_offset + vrd.sni_len / 2;
if ((ret = tcp4_frag(raw_payload, raw_payload_len,
mid_offset, frag1, &f1len, frag2, &f2len)) < 0) {
errno = -ret;
perror("tcp4_frag");
goto fallback;
}
#elif defined(USE_IP_FRAGMENTATION)
size_t ipd_offset = ((char *)data - (char *)tcph) + vrd.sni_offset;
size_t mid_offset = ipd_offset + vrd.sni_len / 2;
mid_offset += 8 - mid_offset % 8;
if ((ret = ip4_frag(raw_payload, raw_payload_len,
mid_offset, frag1, &f1len, frag2, &f2len)) < 0) {
errno = -ret;
perror("ip4_frag");
goto fallback;
}
#else
ret = send_raw_socket(raw_payload, raw_payload_len);
if (ret < 0) {
errno = -ret;
perror("raw pack send");
}
goto fallback;
#endif
ret = send_raw_socket(frag2, f2len); ret = send_raw_socket(frag2, f2len);
if (ret < 0) { if (ret < 0) {
@ -414,35 +579,34 @@ static int process_packet(const struct packet_data packet, struct queue_data qda
goto fallback; goto fallback;
} }
#ifdef SEG2_DELAY
struct dps_t *dpdt = malloc(sizeof(struct dps_t));
dpdt->pkt = malloc(f1len);
memcpy(dpdt->pkt, frag1, f1len);
dpdt->pktlen = f1len;
dpdt->timer = SEG2_DELAY;
pthread_t thr;
pthread_create(&thr, NULL, delay_packet_send, dpdt);
pthread_detach(thr);
#else
ret = send_raw_socket(frag1, f1len);
if (ret < 0) {
errno = -ret;
perror("raw frags send: frag1");
goto fallback; if (config.seg2_delay) {
struct dps_t *dpdt = malloc(sizeof(struct dps_t));
dpdt->pkt = malloc(f1len);
memcpy(dpdt->pkt, frag1, f1len);
dpdt->pktlen = f1len;
dpdt->timer = config.seg2_delay;
pthread_t thr;
pthread_create(&thr, NULL, delay_packet_send, dpdt);
pthread_detach(thr);
} else {
ret = send_raw_socket(frag1, f1len);
if (ret < 0) {
errno = -ret;
perror("raw frags send: frag1");
goto fallback;
}
} }
#endif
} }
/* /*
if (pktb_mangled(pktb)) { if (pktb_mangled(pktb)) {
#ifdef DEBUG if (config.versose)
printf("Mangled!\n"); printf("Mangled!\n");
#endif
nfq_nlmsg_verdict_put_pkt( nfq_nlmsg_verdict_put_pkt(
verdnlh, pktb_data(pktb), pktb_len(pktb)); verdnlh, pktb_data(pktb), pktb_len(pktb));
} }
@ -533,10 +697,10 @@ int init_queue(int queue_num) {
nlh = nfq_nlmsg_put(buf, NFQNL_MSG_CONFIG, queue_num); nlh = nfq_nlmsg_put(buf, NFQNL_MSG_CONFIG, queue_num);
nfq_nlmsg_cfg_put_params(nlh, NFQNL_COPY_PACKET, 0xffff); nfq_nlmsg_cfg_put_params(nlh, NFQNL_COPY_PACKET, 0xffff);
#ifdef USE_GSO if (config.use_gso) {
mnl_attr_put_u32(nlh, NFQA_CFG_FLAGS, htonl(NFQA_CFG_F_GSO)); mnl_attr_put_u32(nlh, NFQA_CFG_FLAGS, htonl(NFQA_CFG_F_GSO));
mnl_attr_put_u32(nlh, NFQA_CFG_MASK, htonl(NFQA_CFG_F_GSO)); mnl_attr_put_u32(nlh, NFQA_CFG_MASK, htonl(NFQA_CFG_F_GSO));
#endif }
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
perror("mnl_socket_send"); perror("mnl_socket_send");
@ -589,6 +753,7 @@ struct queue_conf {
struct queue_res { struct queue_res {
int status; int status;
}; };
static struct queue_res defqres = {0};
static struct queue_res threads_reses[MAX_THREADS]; static struct queue_res threads_reses[MAX_THREADS];
@ -609,69 +774,75 @@ int main(int argc, const char *argv[]) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#if defined(USE_TCP_SEGMENTATION) switch (config.fragmentation_strategy) {
printf("Using TCP segmentation\n"); case FRAG_STRAT_TCP:
#elif defined(USE_IP_FRAGMENTATION) printf("Using TCP segmentation\n");
printf("Using IP fragmentation\n"); break;
#else case FRAG_STRAT_IP:
printf("SNI fragmentation is disabled\n"); printf("Using IP fragmentation\n");
#endif break;
default:
printf("SNI fragmentation is disabled\n");
break;
}
#ifdef SEG2_DELAY if (config.seg2_delay) {
printf("Some outgoing googlevideo request segments will be delayed for %d ms as of SEG2_DELAY define\n", SEG2_DELAY); printf("Some outgoing googlevideo request segments will be delayed for %d ms as of seg2_delay define\n", config.seg2_delay);
#endif }
#ifdef FAKE_SNI switch (config.fake_sni_strategy) {
printf("Fake SNI will be sent before each googlevideo request\n"); case FKSN_STRAT_TTL:
printf("Fake SNI will be sent before each googlevideo request, TTL strategy will be used with TTL %d\n", config.fake_sni_ttl);
break;
case FRAG_STRAT_IP:
printf("Fake SNI will be sent before each googlevideo request, Ack-Seq strategy will be used\n");
break;
default:
printf("SNI fragmentation is disabled\n");
break;
}
printf("Fake SNI will use strategy: " if (config.use_gso) {
#if FAKE_SNI_STRATEGY == FKSN_STRAT_TTL printf("GSO is enabled\n");
"TTL" }
#else
"Ack-Seq"
#endif
"\n");
#endif
#ifdef USE_GSO
printf("GSO is enabled!\n");
#endif
if (open_raw_socket() < 0) { if (open_raw_socket() < 0) {
perror("Unable to open raw socket"); perror("Unable to open raw socket");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
struct queue_res *qres = &defqres;
if (config.threads == 1) {
struct queue_conf tconf = {
.i = 0,
.queue_num = config.queue_start_num
};
#if THREADS_NUM == 1 qres = init_queue_wrapper(&tconf);
struct queue_conf tconf = {
.i = 0,
.queue_num = config.queue_start_num
};
struct queue_res *qres = init_queue_wrapper(&tconf);
#else
struct queue_conf thread_confs[MAX_THREADS];
pthread_t threads[MAX_THREADS];
for (int i = 0; i < config.threads; i++) {
struct queue_conf *tconf = thread_confs + i;
pthread_t *thr = threads + i;
tconf->queue_num = config.queue_start_num + i;
tconf->i = i;
pthread_create(thr, NULL, init_queue_wrapper, tconf);
} }
else {
printf("%d threads wil be used\n", config.threads);
void *res; struct queue_conf thread_confs[MAX_THREADS];
struct queue_res *qres pthread_t threads[MAX_THREADS];
for (int i = 0; i < config.threads; i++) { for (int i = 0; i < config.threads; i++) {
pthread_join(threads[i], &res); struct queue_conf *tconf = thread_confs + i;
pthread_t *thr = threads + i;
qres = res; tconf->queue_num = config.queue_start_num + i;
tconf->i = i;
pthread_create(thr, NULL, init_queue_wrapper, tconf);
}
void *res;
for (int i = 0; i < config.threads; i++) {
pthread_join(threads[i], &res);
qres = res;
}
} }
#endif
if (close_raw_socket() < 0) { if (close_raw_socket() < 0) {
perror("Unable to close raw socket"); perror("Unable to close raw socket");