Skip to content

Commit

Permalink
dnsmasq: clean sources of 2.80, add patches instead
Browse files Browse the repository at this point in the history
- Support TCP DNS, e.g. server=/google.com/8.8.8.8~53 (hanwckf#418)
- Support load gfwlist.txt (equals to add with --server and --ipset one by one) (hanwckf#419)
- Fix TCP DNS crash in dnsmasq 2.8 (hanwckf#754)
  • Loading branch information
Yh793 committed Jan 1, 2023
1 parent 3f39224 commit 43ea70f
Show file tree
Hide file tree
Showing 9 changed files with 345 additions and 161 deletions.
4 changes: 4 additions & 0 deletions trunk/user/dnsmasq/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ endif
ifneq ($(CONFIG_FIRMWARE_INCLUDE_IPSET),y)
COPTS += -DNO_IPSET
endif
ifeq ($(CONFIG_FIRMWARE_INCLUDE_WING),y)
patch -d $(SRC_NAME) -p1 -i ../patchs/101-support-tcp-dns.patch; \
patch -d $(SRC_NAME) -p1 -i ../patchs/102-support-load-gfwlist; \
endif

all:
$(MAKE) -j$(HOST_NCPU) -C $(SRC_NAME) COPTS="$(COPTS)"
Expand Down
2 changes: 1 addition & 1 deletion trunk/user/dnsmasq/dnsmasq-2.8x/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ objs = cache.o rfc1035.o util.o option.o forward.o network.o \
helper.o tftp.o log.o conntrack.o dhcp6.o rfc3315.o \
dhcp-common.o outpacket.o radv.o slaac.o auth.o ipset.o \
domain.o dnssec.o blockdata.o tables.o loop.o inotify.o \
poll.o rrfilter.o edns0.o arp.o tcpdns.o crypto.o dump.o \
poll.o rrfilter.o edns0.o arp.o crypto.o dump.o \
ubus.o metrics.o hash_questions.o

hdrs = dnsmasq.h config.h dhcp-protocol.h dhcp6-protocol.h \
Expand Down
1 change: 0 additions & 1 deletion trunk/user/dnsmasq/dnsmasq-2.8x/src/dnsmasq.h
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ union mysockaddr {
#define SERV_LOOP 8192 /* server causes forwarding loop */
#define SERV_DO_DNSSEC 16384 /* Validate DNSSEC when using this server */
#define SERV_GOT_TCP 32768 /* Got some data from the TCP connection */
#define SERV_IS_TCP 65536 /* Is TCP server */

struct serverfd {
int fd;
Expand Down
11 changes: 3 additions & 8 deletions trunk/user/dnsmasq/dnsmasq-2.8x/src/forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,7 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
}
#endif

ssize_t tcpdns_sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
ssize_t (*sendto_ptr)(int, const void *, size_t, int, const struct sockaddr *, socklen_t) = (start->flags & SERV_IS_TCP) ? tcpdns_sendto : sendto;
if (retry_send(sendto_ptr(fd, (char *)header, plen, 0,
if (retry_send(sendto(fd, (char *)header, plen, 0,
&start->addr.sa,
sa_len(&start->addr))))
continue;
Expand Down Expand Up @@ -815,13 +813,10 @@ void reply_query(int fd, time_t now)
break;

if (!server)
{
if (serveraddr.sa.sa_family == AF_INET ? (serveraddr.in.sin_addr.s_addr != INADDR_ANY && htonl(serveraddr.in.sin_addr.s_addr) != INADDR_LOOPBACK) : (memcmp(&serveraddr.in6.sin6_addr, &in6addr_any, sizeof(in6addr_any)) && memcmp(&serveraddr.in6.sin6_addr, &in6addr_loopback, sizeof(in6addr_loopback))))
return;
}
return;

/* If sufficient time has elapsed, try and expand UDP buffer size again. */
else if (difftime(now, server->pktsz_reduced) > UDP_TEST_TIME)
if (difftime(now, server->pktsz_reduced) > UDP_TEST_TIME)
server->edns_pktsz = daemon->edns_pktsz;

hash = hash_questions(header, n, daemon->namebuff);
Expand Down
11 changes: 5 additions & 6 deletions trunk/user/dnsmasq/dnsmasq-2.8x/src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ void check_servers(void)
}

/* Do we need a socket set? */
if (!serv->sfd && !(serv->flags & SERV_IS_TCP) &&
if (!serv->sfd &&
!(serv->sfd = allocate_sfd(&serv->source_addr, serv->interface, serv->ifindex)) &&
errno != 0)
{
Expand All @@ -1694,7 +1694,6 @@ void check_servers(void)
if (++count > SERVERS_LOGGED)
continue;

char is_tcp = (serv->flags & SERV_IS_TCP) ? '~' : '#';
if (serv->flags & (SERV_HAS_DOMAIN | SERV_FOR_NODOTS | SERV_USE_RESOLV))
{
char *s1, *s2, *s3 = "";
Expand All @@ -1718,16 +1717,16 @@ void check_servers(void)
else if (serv->flags & SERV_USE_RESOLV)
my_syslog(LOG_INFO, _("using standard nameservers for %s %s"), s1, s2);
else
my_syslog(LOG_INFO, _("using nameserver %s%c%d for %s %s %s"), daemon->namebuff, is_tcp, port, s1, s2, s3);
my_syslog(LOG_INFO, _("using nameserver %s#%d for %s %s %s"), daemon->namebuff, port, s1, s2, s3);
}
#ifdef HAVE_LOOP
else if (serv->flags & SERV_LOOP)
my_syslog(LOG_INFO, _("NOT using nameserver %s%c%d - query loop detected"), daemon->namebuff, is_tcp, port);
my_syslog(LOG_INFO, _("NOT using nameserver %s#%d - query loop detected"), daemon->namebuff, port);
#endif
else if (serv->interface[0] != 0)
my_syslog(LOG_INFO, _("using nameserver %s%c%d(via %s)"), daemon->namebuff, is_tcp, port, serv->interface);
my_syslog(LOG_INFO, _("using nameserver %s#%d(via %s)"), daemon->namebuff, port, serv->interface);
else
my_syslog(LOG_INFO, _("using nameserver %s%c%d"), daemon->namebuff, is_tcp, port);
my_syslog(LOG_INFO, _("using nameserver %s#%d"), daemon->namebuff, port);
}
}

Expand Down
87 changes: 2 additions & 85 deletions trunk/user/dnsmasq/dnsmasq-2.8x/src/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ struct myoption {
#define LOPT_NAME_MATCH 355
#define LOPT_CAA 356
#define LOPT_FILTER_AAAA 357
#define LOPT_GFWLIST 358
#define LOPT_DHCP_TO_HOST 359

#ifdef HAVE_GETOPT_LONG
Expand Down Expand Up @@ -343,7 +342,6 @@ static const struct myoption opts[] =
{ "dumpfile", 1, 0, LOPT_DUMPFILE },
{ "dumpmask", 1, 0, LOPT_DUMPMASK },
{ "filter-aaaa", 0, 0, LOPT_FILTER_AAAA },
{ "gfwlist", 1, 0, LOPT_GFWLIST },
{ "dhcp-to-host", 0, 0, LOPT_DHCP_TO_HOST },
{ NULL, 0, 0, 0 }
};
Expand Down Expand Up @@ -525,7 +523,6 @@ static struct {
{ LOPT_DUMPFILE, ARG_ONE, "<path>", gettext_noop("Path to debug packet dump file"), NULL },
{ LOPT_DUMPMASK, ARG_ONE, "<hex>", gettext_noop("Mask which packets to dump"), NULL },
{ LOPT_FILTER_AAAA, OPT_FILTER_AAAA, NULL, gettext_noop("Filter all AAAA requests."), NULL },
{ LOPT_GFWLIST, ARG_DUP, "<path|domain>[@server][^ipset]", gettext_noop("Gfwlist path or domain to special server (default 8.8.8.8~53) and ipset (default gfwlist, pass ^ only to skip default ipset)"), NULL },
{ LOPT_DHCP_TO_HOST, OPT_DHCP_TO_HOST, NULL, gettext_noop("Keep DHCP hostname valid at all times."), NULL },
{ 0, 0, NULL, NULL, NULL }
};
Expand Down Expand Up @@ -807,14 +804,8 @@ char *parse_server(char *arg, union mysockaddr *addr, union mysockaddr *source_a
!atoi_check16(portno, &source_port))
return _("bad port");

portno = split_chr(arg, '#'); /* is there a port no. */
if (portno == NULL) {
portno = split_chr(arg, '~'); /* is there a TCP port no. */
if (portno) {
*flags |= SERV_IS_TCP;
}
}
if (portno && !atoi_check16(portno, &serv_port))
if ((portno = split_chr(arg, '#')) && /* is there a port no. */
!atoi_check16(portno, &serv_port))
return _("bad port");

scope_id = split_chr(arg, '%');
Expand Down Expand Up @@ -1933,13 +1924,6 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
case LOPT_SERVERS_FILE:
daemon->servers_file = opt_string_alloc(arg);
break;

case LOPT_GFWLIST:
{
void load_gfwlist(char *gfwlist);
load_gfwlist(arg);
}
break;

case 'm': /* --mx-host */
{
Expand Down Expand Up @@ -4823,73 +4807,6 @@ void read_servers_file(void)

read_file(daemon->servers_file, f, LOPT_REV_SERV);
}

void add_gfwline(char *gfwline, const char *server, const char *ipset)
{
char *end = gfwline + 1;
while (*end && *end != '#' && *end != '\n' && *end != '\r') end++;
for (char *buf = end; buf >= gfwline; buf--) {
if (*buf == ',' || buf == gfwline) {
if (buf + 1 < end) {
*buf = '/';
*end++ = '/';

#ifdef HAVE_IPSET
if (*ipset) {
strcpy(end, ipset);
one_opt(LOPT_IPSET, buf, _("gfwlist"), _("error"), 0, 0);
end[-1] = '/';
}
#endif
strcpy(end, server);
one_opt('S', buf, _("gfwlist"), _("error"), 0, 0);
}
end = buf;
}
}
}

void load_gfwlist(char *gfwlist)
{
char *cfg_server = NULL, *cfg_ipset = NULL;
for (char *p = gfwlist; *p; p++) {
if (*p == '@') cfg_server = p;
else if (*p == '^') cfg_ipset = p;
}

const char *server, *ipset;
if (cfg_server) {
*cfg_server = 0;
server = cfg_server + 1;
} else {
server = "8.8.8.8~53";
}
if (cfg_ipset) {
*cfg_ipset = 0;
ipset = cfg_ipset + 1;
} else {
ipset = "gfwlist";
}

FILE *f = NULL;
do {
if (*gfwlist == '/') {
if (!(f = fopen(gfwlist, "r"))) {
my_syslog(LOG_ERR, _("cannot read %s: %s"), gfwlist, strerror(errno));
break;
}
for (char buf[MAXDNAME]; fgets(buf+ 1, MAXDNAME - 1, f); add_gfwline(buf, server, ipset));
} else {
char old = gfwlist[-1];
add_gfwline(gfwlist - 1, server, ipset);
gfwlist[-1] = old;
}
} while (0);

if (f) fclose(f);
if (cfg_server) *cfg_server = '@';
if (cfg_ipset) *cfg_ipset = '^';
}

#ifdef HAVE_DHCP
static void clear_dynamic_conf(void)
Expand Down
60 changes: 0 additions & 60 deletions trunk/user/dnsmasq/dnsmasq-2.8x/src/tcpdns.c

This file was deleted.

Loading

0 comments on commit 43ea70f

Please sign in to comment.