Skip to content

Commit

Permalink
NS-Warp roll-back to stable
Browse files Browse the repository at this point in the history
  • Loading branch information
mezantrop committed Sep 28, 2023
1 parent 1adb206 commit 58626d9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 59 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions ns/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -------------------------------------------------------------------------------------------------------------------- #
# NS-Warp - DNS responder/proxy #
# -------------------------------------------------------------------------------------------------------------------- #
# ----------------------------------------------------------------------------------------------------------------------
# NS-Warp - DNS responder/proxy
# ----------------------------------------------------------------------------------------------------------------------

# Copyright (c) 2022-2023, Mikhail Zakharov <zmey20000@yahoo.com>
#
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions ns/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/* ------------------------------------------------------------------------------------------------------------------ */
Expand Down
60 changes: 13 additions & 47 deletions ns/ns-warp.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
#include <netdb.h>
#include <pwd.h>

#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"

/* ------------------------------------------------------------------------------------------------------------------ */
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions ns/ns-warp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ns/ns-warp.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 58626d9

Please sign in to comment.