Skip to content

Commit

Permalink
Daemonize youtubeUnblock with flags, without any overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
Waujito committed Nov 26, 2024
1 parent 438a3c1 commit d408a7b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ 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. But if you really want multiple queue instances of youtubeUnblock, note that you should change --queue-num to --queue balance. For example, with 4 threads, use `--queue-balance 537:540` on iptables and `queue num 537-540` on nftables.

- `--daemonize` Daemonizes the youtubeUnblock (forks and detaches it from the shell). Terminate the program with `killall youtubeUnblock`.

- `--noclose` Usable only with `--daemonize`. Will not redirect io streams to /dev/null.

- `--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.

- `--fbegin` and `--fend` flags: youtubeUnblock supports multiple sets of strategies for specific filters. You may want to initiate a new set after the default one, like: `--sni-domains=googlevideo.com --faking-strategy=md5sum --fbegin --sni-domains=youtube.com --faking-strategy=tcp_check --fend --fbegin --sni-domains=l.google.com --faking-strategy=pastseq --fend`. Note, that the priority of these sets goes backwards: last is first, default (one that does not start with --fbegin) is last. If you start the new section, the default settings are implemented just like youtubeUnblock without any parameters. Note that the config above is just an example and won't work for you.
Expand Down
19 changes: 17 additions & 2 deletions args.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ struct config_t config = {
.use_gso = true,

.default_config = default_section_config,
.custom_configs_len = 0
.custom_configs_len = 0,

.daemonize = 0,
.noclose = 0
};

#define OPT_SNI_DOMAINS 1
Expand All @@ -34,6 +37,8 @@ struct config_t config = {
#define OPT_FAKE_CUSTOM_PAYLOAD 28
#define OPT_START_SECTION 29
#define OPT_END_SECTION 30
#define OPT_DAEMONIZE 31
#define OPT_NOCLOSE 32
#define OPT_FRAG 4
#define OPT_FRAG_SNI_REVERSE 12
#define OPT_FRAG_SNI_FAKED 13
Expand All @@ -54,7 +59,7 @@ struct config_t config = {
#define OPT_NO_GSO 8
#define OPT_QUEUE_NUM 9

#define OPT_MAX OPT_END_SECTION
#define OPT_MAX OPT_NOCLOSE

static struct option long_opt[] = {
{"help", 0, 0, 'h'},
Expand Down Expand Up @@ -84,6 +89,8 @@ static struct option long_opt[] = {
{"trace", 0, 0, OPT_TRACE},
{"no-gso", 0, 0, OPT_NO_GSO},
{"no-ipv6", 0, 0, OPT_NO_IPV6},
{"daemonize", 0, 0, OPT_DAEMONIZE},
{"noclose", 0, 0, OPT_NOCLOSE},
{"queue-num", 1, 0, OPT_QUEUE_NUM},
{"packet-mark", 1, 0, OPT_PACKET_MARK},
{"fbegin", 0, 0, OPT_START_SECTION},
Expand Down Expand Up @@ -152,6 +159,8 @@ void print_usage(const char *argv0) {
printf("\t--trace\n");
printf("\t--no-gso\n");
printf("\t--no-ipv6\n");
printf("\t--daemonize\n");
printf("\t--noclose\n");
printf("\t--fbegin\n");
printf("\t--fend\n");
printf("\n");
Expand Down Expand Up @@ -202,6 +211,12 @@ int parse_args(int argc, char *argv[]) {

config.use_ipv6 = 0;
break;
case OPT_DAEMONIZE:
config.daemonize = 1;
break;
case OPT_NOCLOSE:
config.noclose = 1;
break;
case OPT_THREADS:
if (section_iter != SECT_ITER_DEFAULT)
goto invalid_opt;
Expand Down
4 changes: 3 additions & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ struct section_config_t {
#define SNI_DETECTION_BRUTE 1
int sni_detection;


};

#define MAX_CONFIGLIST_LEN 64
Expand All @@ -75,6 +74,9 @@ struct config_t {
int use_gso;
int use_ipv6;
unsigned int mark;
int daemonize;
// Same as daemon() noclose
int noclose;

#define VERBOSE_INFO 0
#define VERBOSE_DEBUG 1
Expand Down
5 changes: 5 additions & 0 deletions youtubeUnblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ int main(int argc, char *argv[]) {
print_version();
print_welcome();


if (open_raw_socket() < 0) {
perror("Unable to open raw socket");
exit(EXIT_FAILURE);
Expand All @@ -638,6 +639,10 @@ int main(int argc, char *argv[]) {
}
}

if (config.daemonize) {
daemon(0, config.noclose);
}

struct queue_res *qres = &defqres;

if (config.threads == 1) {
Expand Down

0 comments on commit d408a7b

Please sign in to comment.