diff --git a/CONFIGURE.md b/CONFIGURE.md index 6ebca07..e7457c3 100644 --- a/CONFIGURE.md +++ b/CONFIGURE.md @@ -227,6 +227,7 @@ grep 'CONFIG-N:' `find . -type f -name "*.[ch]"`|sed 's/^.*CONFIG-.: *\(.*\)$/|\ |network_option|Method of networking between DAWN instances|0 = Broadcast; 2 = Multicast; [2 = TCP with UMDNS discovery]; 3 = TCP w/out UMDNS discovery| |server_ip|IP address when not using UMDNS|No default| |shared_key|Unused|N/A| +|tcp_ip|IP address for TCP networking|[0.0.0.0]| |tcp_port|Port for TCP networking|[1026]| |use_symm_enc|Enable encryption of network traffic|[0 = Disabled]; 1 = Enabled| diff --git a/dawn-config b/dawn-config index 011d1f5..603038b 100644 --- a/dawn-config +++ b/dawn-config @@ -5,6 +5,7 @@ config local config network option broadcast_ip '10.0.0.255' option broadcast_port '1025' + option tcp_ip '0.0.0.0' option tcp_port '1026' option network_option '2' option shared_key 'Niiiiiiiiiiiiick' diff --git a/src/include/datastorage.h b/src/include/datastorage.h index d817e59..a20d7ad 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -124,6 +124,7 @@ struct network_config_s { char broadcast_ip[MAX_IP_LENGTH + 1]; int broadcast_port; char server_ip[MAX_IP_LENGTH + 1]; + char tcp_ip[MAX_IP_LENGTH + 1]; int tcp_port; int network_option; // 0:Broadcast; 1:Multicast; 2:TCP+UMDNS; 3:TCP char shared_key[MAX_KEY_LENGTH + 1]; diff --git a/src/include/tcpsocket.h b/src/include/tcpsocket.h index 6d9cd9f..c603366 100644 --- a/src/include/tcpsocket.h +++ b/src/include/tcpsocket.h @@ -30,7 +30,7 @@ int add_tcp_connection(char *ipv4, int port); * @param port * @return */ -int run_server(int port); +int run_server(char *ipv4, int port); /** * Send message via tcp to all other hosts. diff --git a/src/network/tcpsocket.c b/src/network/tcpsocket.c index 7a86e89..ad3d8a4 100644 --- a/src/network/tcpsocket.c +++ b/src/network/tcpsocket.c @@ -247,13 +247,13 @@ static void server_cb(struct uloop_fd *fd, unsigned int events) { dawnlog_info("New connection\n"); } -int run_server(int port) { +int run_server(char *ipv4, int port) { dawnlog_debug("Adding socket!\n"); char port_str[12]; sprintf(port_str, "%d", port); // TODO: Manage buffer length server.cb = server_cb; - server.fd = usock(USOCK_TCP | USOCK_SERVER | USOCK_IPV4ONLY | USOCK_NUMERIC, INADDR_ANY, port_str); + server.fd = usock(USOCK_TCP | USOCK_SERVER | USOCK_IPV4ONLY | USOCK_NUMERIC, ipv4, port_str); if (server.fd < 0) { dawnlog_perror("usock"); return 1; diff --git a/src/utils/dawn_uci.c b/src/utils/dawn_uci.c index d9750d6..5ea0f97 100644 --- a/src/utils/dawn_uci.c +++ b/src/utils/dawn_uci.c @@ -382,6 +382,7 @@ struct network_config_s uci_get_dawn_network() { .broadcast_ip = "", .broadcast_port = 1025, .server_ip = "", + .tcp_ip = "0.0.0.0", .tcp_port = 1026, .network_option = 2, .shared_key = "Niiiiiiiiiiiiiik", @@ -424,6 +425,10 @@ struct network_config_s uci_get_dawn_network() { // CONFIG-N: network_option|Method of networking between DAWN instances|0 = Broadcast; 2 = Multicast; [2 = TCP with UMDNS discovery]; 3 = TCP w/out UMDNS discovery DAWN_SET_CONFIG_INT(ret, s, network_option); + // CONFIG-N: tcp_ip|IP address for TCP networking|[0.0.0.0] + const char* str_tcp_ip = uci_lookup_option_string(uci_ctx, s, "tcp_ip"); + if (str_tcp_ip) + strncpy(ret.tcp_ip, str_tcp_ip, MAX_IP_LENGTH); // CONFIG-N: tcp_port|Port for TCP networking|[1025] DAWN_SET_CONFIG_INT(ret, s, tcp_port); // CONFIG-N: use_symm_enc|Enable encryption of network traffic|[0 = Disabled]; 1 = Enabled diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 616e09b..5f42c41 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -801,7 +801,7 @@ int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir) { || network_config.network_option == 3) { start_tcp_con_update(); - if(run_server(network_config.tcp_port)) + if(run_server(network_config.tcp_ip, network_config.tcp_port)) uloop_timeout_set(&usock_timer, 1 * 1000); } @@ -1008,7 +1008,7 @@ void update_clients(struct uloop_timeout *t) { void run_server_update(struct uloop_timeout *t) { dawnlog_debug_func("Entering..."); - if(run_server(network_config.tcp_port)) + if(run_server(network_config.tcp_ip, network_config.tcp_port)) uloop_timeout_set(&usock_timer, 1 * 1000); }