Allow to change default mark

Related to #96
This commit is contained in:
Vadim Vetrov
2024-08-29 09:09:57 +03:00
parent c101adcd07
commit 491d485260
4 changed files with 22 additions and 6 deletions

View File

@@ -187,6 +187,8 @@ Available flags:
- `--threads=<threads number>` Specifies the amount of threads you want to be running for your program. This defaults to **1** and shouldn't be edited for normal use. If you have performance issues, consult [performance chaptr](https://github.com/Waujito/youtubeUnblock?tab=readme-ov-file#performance)
- `--packet-mark=<mark>` Use this option if youtubeUnblock conflicts with other systems rely on packet mark. Note that you may want to change accept rule for iptables to follow the mark.
## Troubleshooting
If you got troubles with some sites and you sure that they are blocked by SNI (youtube for example), use may play around with [flags](#flags) and their combinations. At first it is recommended to try `--faking-strategy` flag and `--frag-sni-faked=1`.

15
args.c
View File

@@ -22,6 +22,7 @@ struct config_t config = {
.frag_sni_pos = 2,
.use_ipv6 = 1,
.fakeseq_offset = 10000,
.mark = DEFAULT_RAWSOCKET_MARK,
.sni_detection = SNI_DETECTION_PARSE,
@@ -67,13 +68,14 @@ struct config_t config = {
#define OPT_SNI_DETECTION 17
#define OPT_NO_IPV6 20
#define OPT_FAKE_SEQ_OFFSET 21
#define OPT_PACKET_MARK 22
#define OPT_SEG2DELAY 5
#define OPT_THREADS 6
#define OPT_SILENT 7
#define OPT_NO_GSO 8
#define OPT_QUEUE_NUM 9
#define OPT_MAX OPT_FAKE_SEQ_OFFSET
#define OPT_MAX OPT_PACKET_MARK
static struct option long_opt[] = {
{"help", 0, 0, 'h'},
@@ -99,6 +101,7 @@ static struct option long_opt[] = {
{"no-gso", 0, 0, OPT_NO_GSO},
{"no-ipv6", 0, 0, OPT_NO_IPV6},
{"queue-num", 1, 0, OPT_QUEUE_NUM},
{"packet-mark", 1, 0, OPT_PACKET_MARK},
{0,0,0,0}
};
@@ -148,6 +151,7 @@ void print_usage(const char *argv0) {
printf("\t--sni-detection={parse|brute}\n");
printf("\t--seg2delay=<delay>\n");
printf("\t--threads=<threads number>\n");
printf("\t--packet-mark=<mark>\n");
printf("\t--silent\n");
printf("\t--trace\n");
printf("\t--no-gso\n");
@@ -331,6 +335,15 @@ int parse_args(int argc, char *argv[]) {
config.queue_start_num = num;
break;
case OPT_PACKET_MARK:
num = parse_numeric_option(optarg);
if (errno != 0 || num < 0) {
goto invalid_opt;
}
config.mark = num;
break;
default:
goto error;
}

View File

@@ -45,6 +45,7 @@ struct config_t {
unsigned int fake_sni_pkt_sz;
unsigned int fk_winsize;
unsigned int fakeseq_offset;
unsigned int mark;
};
extern struct config_t config;
@@ -71,7 +72,7 @@ extern struct config_t config;
#define FRAGMENTATION_STRATEGY FRAG_STRAT_TCP
#endif
#define RAWSOCKET_MARK (1 << 15)
#define DEFAULT_RAWSOCKET_MARK (1 << 15)
#ifdef USE_SEG2_DELAY
#define SEG2_DELAY 100

View File

@@ -87,7 +87,7 @@ static int open_raw_socket(void) {
return -1;
}
int mark = RAWSOCKET_MARK;
int mark = config.mark;
if (setsockopt(rawsocket, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)) < 0)
{
fprintf(stderr, "setsockopt(SO_MARK, %d) failed\n", mark);
@@ -139,7 +139,7 @@ static int open_raw6_socket(void) {
return -1;
}
int mark = RAWSOCKET_MARK;
int mark = config.mark;
if (setsockopt(raw6socket, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)) < 0)
{
fprintf(stderr, "setsockopt(SO_MARK, %d) failed\n", mark);
@@ -424,8 +424,8 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data) {
if (attr[NFQA_MARK] != NULL) {
// Skip packets sent by rawsocket to escape infinity loop.
if ((ntohl(mnl_attr_get_u32(attr[NFQA_MARK])) & RAWSOCKET_MARK) ==
RAWSOCKET_MARK) {
if ((ntohl(mnl_attr_get_u32(attr[NFQA_MARK])) & config.mark) ==
config.mark) {
return fallback_accept_packet(packet.id, *qdata);
}
}