scripts/update-cmd.pl: run update two times
[project/unetd.git] / main.c
diff --git a/main.c b/main.c
index 74fe9648d3acf3a2272ac6f4192e9712cd0e4e2d..e4e93317fcfe212a5c02b46a81eb73f03f231525 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) 2022 Felix Fietkau <nbd@nbd.name>
  */
@@ -16,7 +16,9 @@ struct cmdline_network {
 
 static struct cmdline_network *cmd_nets;
 static const char *hosts_file;
-bool dummy_mode;
+const char *mssfix_path = UNETD_MSS_BPF_PATH;
+const char *data_dir = UNETD_DATA_DIR;
+int global_pex_port = UNETD_GLOBAL_PEX_PORT;
 bool debug;
 
 static void
@@ -30,7 +32,9 @@ network_write_hosts(struct network *net, FILE *f)
 
        avl_for_each_element(&net->hosts, host, node) {
                inet_ntop(AF_INET6, &host->peer.local_addr, ip, sizeof(ip));
-               fprintf(f, "%s\t%s\n", ip, network_host_name(host));
+               fprintf(f, "%s\t%s%s%s\n", ip, network_host_name(host),
+                       net->config.domain ? "." : "",
+                       net->config.domain ? net->config.domain : "");
        }
 }
 
@@ -44,7 +48,9 @@ void unetd_write_hosts(void)
        if (!hosts_file)
                return;
 
-       asprintf(&tmpfile, "%s.XXXXXXXX", hosts_file);
+       if (asprintf(&tmpfile, "%s.XXXXXXXX", hosts_file) < 0)
+               return;
+
        fd = mkstemp(tmpfile);
        if (fd < 0) {
                perror("mkstemp");
@@ -97,14 +103,14 @@ int main(int argc, char **argv)
        struct cmdline_network *net;
        int ch;
 
-       while ((ch = getopt(argc, argv, "Ddh:N:")) != -1) {
+       while ((ch = getopt(argc, argv, "D:dh:M:N:P:")) != -1) {
                switch (ch) {
+               case 'D':
+                       data_dir = optarg;
+                       break;
                case 'd':
                        debug = true;
                        break;
-               case 'D':
-                       dummy_mode = true;
-                       break;
                case 'h':
                        hosts_file = optarg;
                        break;
@@ -114,14 +120,22 @@ int main(int argc, char **argv)
                        net->data = optarg;
                        cmd_nets = net;
                        break;
+               case 'M':
+                       mssfix_path = optarg;
+                       break;
+               case 'P':
+                       global_pex_port = atoi(optarg);
+                       break;
                }
        }
 
        uloop_init();
        unetd_ubus_init();
        unetd_write_hosts();
+       global_pex_open();
        add_networks();
        uloop_run();
+       pex_close();
        network_free_all();
        uloop_done();