remove dummy mode
authorFelix Fietkau <nbd@nbd.name>
Mon, 1 Aug 2022 05:48:39 +0000 (07:48 +0200)
committerFelix Fietkau <nbd@nbd.name>
Tue, 2 Aug 2022 16:53:49 +0000 (18:53 +0200)
Signed-off-by: Felix Fietkau <nbd@nbd.name>
CMakeLists.txt
main.c
pex.c
unetd.h
wg-dummy.c [deleted file]
wg.c
wg.h

index b51fc4481a56d1dbd482c2a5bc783164c91525f2..492f1b7a6cec4eb92a17d939b8532921f579a12e 100644 (file)
@@ -5,7 +5,7 @@ PROJECT(unetd C)
 
 SET(SOURCES
        main.c network.c host.c service.c pex.c utils.c
-       wg.c wg-dummy.c wg-user.c
+       wg.c wg-user.c
 )
 
 SET(RUNSTATEDIR /var/run)
diff --git a/main.c b/main.c
index 3bd774471b8fd8baf3d4917b61de59a548dc566f..cd398438f253e4bea8bfa00fa5ce6389d4954f90 100644 (file)
--- a/main.c
+++ b/main.c
@@ -17,7 +17,6 @@ struct cmdline_network {
 static struct cmdline_network *cmd_nets;
 static const char *hosts_file;
 const char *mssfix_path = UNETD_MSS_BPF_PATH;
-bool dummy_mode;
 bool debug;
 
 static void
@@ -98,14 +97,11 @@ int main(int argc, char **argv)
        struct cmdline_network *net;
        int ch;
 
-       while ((ch = getopt(argc, argv, "Ddh:M:N:")) != -1) {
+       while ((ch = getopt(argc, argv, "dh:M:N:")) != -1) {
                switch (ch) {
                case 'd':
                        debug = true;
                        break;
-               case 'D':
-                       dummy_mode = true;
-                       break;
                case 'h':
                        hosts_file = optarg;
                        break;
diff --git a/pex.c b/pex.c
index 381f6b60e6401a33af760a8bb4f12a0edc6d7d09..23ee57c4bb0d5901ab1c187666b6ff4a1c930d30 100644 (file)
--- a/pex.c
+++ b/pex.c
@@ -469,7 +469,7 @@ int network_pex_open(struct network *net)
        int yes = 1;
        int fd;
 
-       if (dummy_mode || !local || !net->net_config.pex_port)
+       if (!local || !net->net_config.pex_port)
                return 0;
 
        fd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
diff --git a/unetd.h b/unetd.h
index 799bff72873d2e7b28467f9b0e486515d26cf74b..56d88c4bf75d30551b57c4f2e2413ba9d08b246a 100644 (file)
--- a/unetd.h
+++ b/unetd.h
@@ -20,7 +20,6 @@
 #include "ubus.h"
 
 extern const char *mssfix_path;
-extern bool dummy_mode;
 extern bool debug;
 
 #define D(format, ...)                                                         \
diff --git a/wg-dummy.c b/wg-dummy.c
deleted file mode 100644 (file)
index d378272..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright (C) 2022 Felix Fietkau <nbd@nbd.name>
- */
-#include <arpa/inet.h>
-#include "unetd.h"
-
-static int
-wg_dummy_init(struct network *net)
-{
-       char key[B64_ENCODE_LEN(CURVE25519_KEY_SIZE)];
-
-       fprintf(stderr, "Create wireguard interface %s\n", network_name(net));
-       b64_encode(net->config.key, sizeof(net->config.key), key, sizeof(key));
-       fprintf(stderr, "key=%s\n", key);
-       b64_encode(net->config.pubkey, sizeof(net->config.pubkey), key, sizeof(key));
-       fprintf(stderr, "pubkey=%s\n", key);
-       fprintf(stderr, "\n");
-
-       return 0;
-}
-
-static void
-wg_dummy_cleanup(struct network *net)
-{
-       fprintf(stderr, "Remove wireguard interface %s\n", network_name(net));
-}
-
-static int
-wg_dummy_init_local(struct network *net, struct network_peer *peer)
-{
-       char addr[INET6_ADDRSTRLEN];
-
-       fprintf(stderr, "local node %s, port: %d\n", network_peer_name(peer), peer->port);
-
-       fprintf(stderr, "default addr: %s\n",
-               inet_ntop(AF_INET6, &peer->local_addr.in6, addr, sizeof(addr)));
-
-       fprintf(stderr, "\n");
-
-       return 0;
-}
-
-static int
-wg_dummy_peer_update(struct network *net, struct network_peer *peer, enum wg_update_cmd cmd)
-{
-       static const char * const cmds[] = {
-               [WG_PEER_CREATE] = "create",
-               [WG_PEER_UPDATE] = "update",
-               [WG_PEER_DELETE] = "delete",
-       };
-       char key[B64_ENCODE_LEN(CURVE25519_KEY_SIZE)];
-       char addr[INET6_ADDRSTRLEN];
-       struct blob_attr *cur;
-       int rem;
-
-       b64_encode(peer->key, sizeof(peer->key), key, sizeof(key));
-       fprintf(stderr, "%s peer %s: %s\n", cmds[cmd], network_peer_name(peer), key);
-
-       if (cmd == WG_PEER_DELETE)
-               return 0;
-
-       fprintf(stderr, "default addr: %s\n",
-               inet_ntop(AF_INET6, &peer->local_addr.in6, addr, sizeof(addr)));
-
-       blobmsg_for_each_attr(cur, peer->ipaddr, rem) {
-               fprintf(stderr, "peer addr: %s\n", blobmsg_get_string(cur));
-       }
-       blobmsg_for_each_attr(cur, peer->subnet, rem) {
-               fprintf(stderr, "peer subnet: %s\n", blobmsg_get_string(cur));
-       }
-       fprintf(stderr, "\n");
-       return 0;
-}
-
-static int
-wg_dummy_peer_refresh(struct network *net)
-{
-       struct network_host *host;
-
-       avl_for_each_element(&net->hosts, host, node) {
-               struct network_peer *peer = &host->peer;
-
-               if (peer->state.endpoint.in.sin_family)
-                       peer->state.connected = true;
-       }
-
-       return 0;
-}
-
-static int
-wg_dummy_peer_connect(struct network *net, struct network_peer *peer,
-                     union network_endpoint *ep)
-{
-       char addr[INET6_ADDRSTRLEN];
-       void *ip;
-
-       if (ep->in.sin_family == AF_INET6)
-               ip = &ep->in6.sin6_addr;
-       else
-               ip = &ep->in.sin_addr;
-
-       fprintf(stderr, "connect to host %s at %s:%d\n", network_peer_name(peer),
-               inet_ntop(ep->in.sin_family, ip, addr, sizeof(addr)), ntohs(ep->in.sin_port));
-       memcpy(&peer->state.endpoint, ep, sizeof(peer->state.endpoint));
-
-       return 0;
-}
-
-const struct wg_ops wg_dummy_ops = {
-       .name = "dummy",
-       .init = wg_dummy_init,
-       .cleanup = wg_dummy_cleanup,
-       .init_local = wg_dummy_init_local,
-       .peer_update = wg_dummy_peer_update,
-       .peer_refresh = wg_dummy_peer_refresh,
-       .peer_connect = wg_dummy_peer_connect,
-};
diff --git a/wg.c b/wg.c
index ea519906c2a4c2c1432e28686690a07b8f34a896..5245536eeed1538323e7e4935fb3f565f6d85bcc 100644 (file)
--- a/wg.c
+++ b/wg.c
@@ -6,9 +6,6 @@
 
 static const struct wg_ops *wg_get_ops(struct network *net)
 {
-       if (dummy_mode)
-               return &wg_dummy_ops;
-
        if (wg_user_ops.check(net))
                return &wg_user_ops;
 
diff --git a/wg.h b/wg.h
index 5a7aac1b847315449da1a7cebca7b50ddecbdbe2..06a9df57b4b4ca5c9dfed2d738d914ce68fa607a 100644 (file)
--- a/wg.h
+++ b/wg.h
@@ -37,7 +37,6 @@ struct wg {
        const struct wg_ops *ops;
 };
 
-extern const struct wg_ops wg_dummy_ops;
 extern const struct wg_ops wg_user_ops;
 extern const struct wg_ops wg_linux_ops;