From: Felix Fietkau Date: Mon, 1 Aug 2022 05:48:39 +0000 (+0200) Subject: remove dummy mode X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=2ceaeba6351cef0212fee556d17c9ccfa6921786;p=project%2Funetd.git remove dummy mode Signed-off-by: Felix Fietkau --- diff --git a/CMakeLists.txt b/CMakeLists.txt index b51fc44..492f1b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 3bd7744..cd39843 100644 --- 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 381f6b6..23ee57c 100644 --- 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 799bff7..56d88c4 100644 --- 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 index d378272..0000000 --- a/wg-dummy.c +++ /dev/null @@ -1,118 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (C) 2022 Felix Fietkau - */ -#include -#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 ea51990..5245536 100644 --- 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 5a7aac1..06a9df5 100644 --- 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;