diff --git a/README.md b/README.md index 84d9ae7..1d5d525 100644 --- a/README.md +++ b/README.md @@ -241,6 +241,10 @@ Available flags: - `--threads=` 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=` 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. diff --git a/args.c b/args.c index 04559b6..17a73d9 100644 --- a/args.c +++ b/args.c @@ -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 @@ -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 @@ -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'}, @@ -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}, @@ -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"); @@ -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; diff --git a/config.h b/config.h index 05b7a18..b209f93 100644 --- a/config.h +++ b/config.h @@ -64,7 +64,6 @@ struct section_config_t { #define SNI_DETECTION_BRUTE 1 int sni_detection; - }; #define MAX_CONFIGLIST_LEN 64 @@ -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 diff --git a/youtubeUnblock.c b/youtubeUnblock.c index 216688a..67de5cf 100644 --- a/youtubeUnblock.c +++ b/youtubeUnblock.c @@ -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); @@ -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) {