From 58626d9ea4429dc86d18cfe3971936cb071566e8 Mon Sep 17 00:00:00 2001 From: Mikhail Zakharov Date: Thu, 28 Sep 2023 12:57:58 +0200 Subject: [PATCH] `NS-Warp` roll-back to stable --- CHANGELOG.md | 3 ++- ns/Makefile | 10 ++++---- ns/dns.c | 5 ++-- ns/ns-warp.c | 60 +++++++++++------------------------------------- ns/ns-warp.h | 4 +--- ns/ns-warp.sh.in | 2 +- 6 files changed, 25 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6618b43..9e60320 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # CHANGELOG -* 2023.09.26 Current +* 2023.09.28 Current + * `NS-Warp` roll-back to stable * MacOS GUI-WARP app: remove references to CLI configuration * ACT in `GUI-Warp` macOS port * `gui-warp.py`: ACT tab introduced; minor ACT pipe fixes diff --git a/ns/Makefile b/ns/Makefile index 4c2513e..b29faf9 100644 --- a/ns/Makefile +++ b/ns/Makefile @@ -1,6 +1,6 @@ -# -------------------------------------------------------------------------------------------------------------------- # -# NS-Warp - DNS responder/proxy # -# -------------------------------------------------------------------------------------------------------------------- # +# ---------------------------------------------------------------------------------------------------------------------- +# NS-Warp - DNS responder/proxy +# ---------------------------------------------------------------------------------------------------------------------- # Copyright (c) 2022-2023, Mikhail Zakharov # @@ -25,8 +25,8 @@ # ---------------------------------------------------------------------------------------------------------------------- PREFIX ?= /usr/local -CC = cc -CFLAGS = -O3 -Wall -I ../ +CC = cc -O3 +CFLAGS = -Wall -I ../ OBJECTS = ns-warp.o ns-inifile.o dns.o ../network.o ../utility.o ../logfile.o ../pidfile.o .PHONY: all clean install diff --git a/ns/dns.c b/ns/dns.c index 6e6c225..f9eb123 100644 --- a/ns/dns.c +++ b/ns/dns.c @@ -164,16 +164,17 @@ int dns_reply_a(unsigned int id, unsigned char *dnsq_raw, int dnsq_siz, struct s dnsa->ttl = 0x00000000; dnsa->rdlength = 0x0400; - void *rdata; if (SA_FAMILY(*ip) == AF_INET) { in_addr_t *rdata = (in_addr_t *)(rbuf + sizeof(dns_header) + dnsq_siz + sizeof(dns_answer_ref)); *rdata = S4_ADDR(*ip); + return sizeof(dns_header) + dnsq_siz + sizeof(dns_answer_ref) + sizeof(*rdata); } else { char *rdata = (char *)(rbuf + sizeof(dns_header) + dnsq_siz + sizeof(dns_answer_ref)); memcpy(rdata, S6_ADDR(*ip), 16); + return sizeof(dns_header) + dnsq_siz + sizeof(dns_answer_ref) + sizeof(*rdata); } - return sizeof(dns_header) + dnsq_siz + sizeof(dns_answer_ref) + sizeof(*rdata); + return 0; } /* ------------------------------------------------------------------------------------------------------------------ */ diff --git a/ns/ns-warp.c b/ns/ns-warp.c index 00c1c25..7b80da2 100644 --- a/ns/ns-warp.c +++ b/ns/ns-warp.c @@ -39,12 +39,12 @@ #include #include +#include "utility.h" #include "dns.h" +#include "ns-warp.h" #include "logfile.h" #include "pidfile.h" -#include "utility.h" #include "network.h" -#include "ns-warp.h" #include "ns-inifile.h" /* ------------------------------------------------------------------------------------------------------------------ */ @@ -308,30 +308,19 @@ int main (int argc, char* argv[]) { case 0: printl(LOG_VERB, "Found the Name: [%s] in NIT has the IP: [%s]", dnsq.name, inet2str(&q_ip, str_buf)); - rec = dns_reply_a(dnsh->id, dnsq_raw, dnsq_siz, &q_ip, dns_buf); - - /* Forward the message to the client */ - snd = sendto(isock, dns_buf, rec, 0, (struct sockaddr *)&caddr, sizeof(struct sockaddr)); - if (snd == -1) printl(LOG_CRIT, "Error forwarding data to the client"); - printl(rec != snd ? LOG_CRIT : LOG_VERB, "S:[%d] -> C:[%d] bytes", rec, snd); + if (!(rec = dns_reply_a(dnsh->id, dnsq_raw, dnsq_siz, &q_ip, dns_buf))) + continue; free(dnsq.name); free(dnsq_raw); - return 0; + goto snd_client; break; - case 2: printl(LOG_VERB, "[%s] is found in NIT but not in IPv4 range", dnsq.name); rec = dns_reply_nfound(dnsh->id, htons(dnsq.type), dnsq_raw, dnsq_siz, dns_buf); - - /* Forward the message to the client */ - snd = sendto(isock, dns_buf, rec, 0, (struct sockaddr *)&caddr, sizeof(struct sockaddr)); - if (snd == -1) printl(LOG_CRIT, "Error forwarding data to the client"); - printl(rec != snd ? LOG_CRIT : LOG_VERB, "S:[%d] -> C:[%d] bytes", rec, snd); free(dnsq.name); free(dnsq_raw); - return 0; + goto snd_client; break; - case 1: default: printl(LOG_VERB, "[%s] is not found in NIT", dnsq.name); @@ -345,30 +334,19 @@ int main (int argc, char* argv[]) { printl(LOG_VERB, "Found the Name: [%s] in NIT has the IP: [%s]", dnsq.name, inet2str(&q_ip, str_buf)); - rec = dns_reply_a(dnsh->id, dnsq_raw, dnsq_siz, &q_ip, dns_buf); - - /* Forward the message to the client */ - snd = sendto(isock, dns_buf, rec, 0, (struct sockaddr *)&caddr, sizeof(struct sockaddr)); - if (snd == -1) printl(LOG_CRIT, "Error forwarding data to the client"); - printl(rec != snd ? LOG_CRIT : LOG_VERB, "S:[%d] -> C:[%d] bytes", rec, snd); + if (!(rec = dns_reply_a(dnsh->id, dnsq_raw, dnsq_siz, &q_ip, dns_buf))) + continue; free(dnsq.name); free(dnsq_raw); - return 0; + goto snd_client; break; - case 2: printl(LOG_VERB, "[%s] is found in NIT but not in IPv6 range", dnsq.name); rec = dns_reply_nfound(dnsh->id, htons(dnsq.type), dnsq_raw, dnsq_siz, dns_buf); - - /* Forward the message to the client */ - snd = sendto(isock, dns_buf, rec, 0, (struct sockaddr *)&caddr, sizeof(struct sockaddr)); - if (snd == -1) printl(LOG_CRIT, "Error forwarding data to the client"); - printl(rec != snd ? LOG_CRIT : LOG_VERB, "S:[%d] -> C:[%d] bytes", rec, snd); free(dnsq.name); free(dnsq_raw); - return 0; + goto snd_client; break; - case 1: default: printl(LOG_VERB, "The name: [%s] is not found in NIT", dnsq.name); @@ -383,29 +361,17 @@ int main (int argc, char* argv[]) { printl(LOG_VERB, "Found the Name: [%s] in NIT has the IP: [%s]", q_name, inet2str(&q_ip, str_buf)); rec = dns_reply_ptr(dnsh->id, dnsq_raw, dnsq_siz, q_name, dns_buf); - - /* Forward the message to the client */ - snd = sendto(isock, dns_buf, rec, 0, (struct sockaddr *)&caddr, sizeof(struct sockaddr)); - if (snd == -1) printl(LOG_CRIT, "Error forwarding data to the client"); - printl(rec != snd ? LOG_CRIT : LOG_VERB, "S:[%d] -> C:[%d] bytes", rec, snd); free(dnsq.name); free(dnsq_raw); - return 0; + goto snd_client; break; - case 2: printl(LOG_VERB, "The name: [%s] is not (yet) registered with NIT", dnsq.name); rec = dns_reply_nfound(dnsh->id, htons(dnsq.type), dnsq_raw, dnsq_siz, dns_buf); - - /* Forward the message to the client */ - snd = sendto(isock, dns_buf, rec, 0, (struct sockaddr *)&caddr, sizeof(struct sockaddr)); - if (snd == -1) printl(LOG_CRIT, "Error forwarding data to the client"); - printl(rec != snd ? LOG_CRIT : LOG_VERB, "S:[%d] -> C:[%d] bytes", rec, snd); free(dnsq.name); free(dnsq_raw); - return 0; + goto snd_client; break; - case 1: default: printl(LOG_VERB, "The name: [%s] is not found in NIT", dnsq.name); @@ -451,7 +417,7 @@ int main (int argc, char* argv[]) { inet2str((struct sockaddr_storage *)sres->ai_addr, str_buf)); continue; } - +snd_client: /* Everything is OK, just forward the message to the client */ snd = sendto(isock, dns_buf, rec, 0, (struct sockaddr *)&caddr, sizeof(struct sockaddr)); if (snd == -1) { diff --git a/ns/ns-warp.h b/ns/ns-warp.h index cb393b6..884aa6d 100644 --- a/ns/ns-warp.h +++ b/ns/ns-warp.h @@ -40,14 +40,12 @@ #define NS_LISTEN_PORT "5353" /* This is our UDP port */ #define DNS_PORT "53" /* That is remote DNS server port */ -#define STR_SIZE 255 - #define RUNAS_USER "nobody" /* Program name and version */ #define NS_PROG_NAME "NS-Warp" #define NS_PROG_NAME_SHORT "NSW" -#define NS_PROG_VERSION "1.0.5" +#define NS_PROG_VERSION "1.0.6" /* -- Function prototypes ------------------------------------------------------------------------------------------- */ void trap_signal(int sig); diff --git a/ns/ns-warp.sh.in b/ns/ns-warp.sh.in index 08af711..a559542 100644 --- a/ns/ns-warp.sh.in +++ b/ns/ns-warp.sh.in @@ -34,7 +34,7 @@ # ---------------------------------------------------------------------------- # -# ---------------------------------------------------------------------------- # +# -- CONFIGURATION VARIABLES ------------------------------------------------- # nswarp_prefix="/usr/local" nswarp_inifile="$nswarp_prefix/etc/ts-warp.ini" nswarp_logfile="$nswarp_prefix/var/log/ns-warp.log"