Skip to content

Commit

Permalink
update to dnsmasq v2.81
Browse files Browse the repository at this point in the history
  • Loading branch information
lixingcong committed Apr 12, 2020
1 parent db08d19 commit b3ddae2
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 49 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## dnsmasq with regex support
## Dnsmasq with regex support

Lastest version: 2.80
Lastest version: 2.81

patches:
- [001-regex-server.patch](/patches/001-regex-server.patch)
Expand Down Expand Up @@ -60,6 +60,6 @@ DNSMASQ_COPTS="-DHAVE_REGEX"

Tips: A simple script to generate domains configurations: [my-gfwlist](https://github.com/lixingcong/my-gfwlist)

## Openwrt/LEDE package
## OpenWrt/LEDE package

Please check this page: [dnsmasq-regex-openwrt](https://github.com/lixingcong/dnsmasq-regex-openwrt)
2 changes: 1 addition & 1 deletion dnsmasq
Submodule dnsmasq updated from 91421c to 7ddb99
8 changes: 4 additions & 4 deletions dnsmasq_regex_example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ server=/:.*github.*:/8.8.8.8
server=/:.*google.*:/8.8.8.8
server=/:.*youtube.*:/8.8.8.8

# Tips: You need to manually create ipset 'test' first
# Tips: You need to manually create ipset 'test' first:
# sudo ipset create test hash:ip
# and run dnsmasq with root(to modify this set)

ipset=/:.*google.*:/test
ipset=/:.*youtube.*:/test
ipset=/fb.me/test
Expand All @@ -27,6 +30,3 @@ server=8.8.8.8
no-resolv
# do not re-read /etc/resolv.conf when file was changed by ISP
no-poll

cache-size=15000
min-cache-ttl=600
56 changes: 28 additions & 28 deletions patches/001-regex-server.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/Makefile b/Makefile
index e71cf86..fd43bac 100644
index 78e25f0..31b2c0f 100644
--- a/Makefile
+++ b/Makefile
@@ -65,6 +65,8 @@ lua_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CON
Expand Down Expand Up @@ -27,17 +27,17 @@ index e71cf86..fd43bac 100644
top="$(top)" \
i18n=-DLOCALEDIR=\'\"$(LOCALEDIR)\"\' \
- build_cflags="$(version) $(dbus_cflags) $(idn2_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags)" \
- build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs)" \
- build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs) $(ubus_libs)" \
+ build_cflags="$(version) $(dbus_cflags) $(idn2_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags) $(regex_cflags)" \
+ build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs) $(regex_libs)" \
+ build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs) $(ubus_libs) $(regex_libs)" \
-f $(top)/Makefile dnsmasq
for f in `cd $(PO); echo *.po`; do \
cd $(top) && cd $(BUILDDIR) && $(MAKE) top="$(top)" -f $(top)/Makefile $${f%.po}.mo; \
diff --git a/src/config.h b/src/config.h
index 762c49b..633f38a 100644
index 7d08f7d..2f156eb 100644
--- a/src/config.h
+++ b/src/config.h
@@ -129,6 +129,10 @@ HAVE_LOOP
@@ -130,6 +130,10 @@ HAVE_LOOP
HAVE_INOTIFY
use the Linux inotify facility to efficiently re-read configuration files.

Expand All @@ -47,7 +47,7 @@ index 762c49b..633f38a 100644
+
NO_ID
Don't report *.bind CHAOS info to clients, forward such requests upstream instead.
NO_IPV6
NO_TFTP
@@ -186,6 +190,7 @@ RESOLVFILE
/* #define HAVE_LIBIDN2 */
/* #define HAVE_CONNTRACK */
Expand All @@ -56,7 +56,7 @@ index 762c49b..633f38a 100644


/* Default locations for important system files. */
@@ -407,6 +412,10 @@ static char *compile_opts =
@@ -376,6 +381,10 @@ static char *compile_opts =
"no-"
#endif
"i18n "
Expand All @@ -68,10 +68,10 @@ index 762c49b..633f38a 100644
"IDN2 "
#else
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index f53e9a5..940b212 100644
index 68e6287..cafd250 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -152,6 +152,10 @@ extern int capget(cap_user_header_t header, cap_user_data_t data);
@@ -157,6 +157,10 @@ extern int capget(cap_user_header_t header, cap_user_data_t data);
#include <priv.h>
#endif

Expand All @@ -82,15 +82,15 @@ index f53e9a5..940b212 100644
#ifdef HAVE_DNSSEC
# include <nettle/nettle-meta.h>
#endif
@@ -524,6 +528,7 @@ union mysockaddr {
@@ -529,6 +533,7 @@ 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_REGEX 65536 /* server entry is a regex */

struct serverfd {
int fd;
@@ -550,6 +555,10 @@ struct server {
@@ -555,6 +560,10 @@ struct server {
u32 uid;
#endif
struct server *next;
Expand All @@ -102,10 +102,10 @@ index f53e9a5..940b212 100644

struct ipsets {
diff --git a/src/forward.c b/src/forward.c
index 3dd8633..d328b77 100644
index fde554d..f903e5b 100644
--- a/src/forward.c
+++ b/src/forward.c
@@ -155,11 +155,38 @@ static unsigned int search_servers(time_t now, struct all_addr **addrpp, unsigne
@@ -155,11 +155,38 @@ static unsigned int search_servers(time_t now, union all_addr **addrpp, unsigned
}
else if (serv->flags & SERV_HAS_DOMAIN)
{
Expand Down Expand Up @@ -149,7 +149,7 @@ index 3dd8633..d328b77 100644
{
if ((serv->flags & SERV_NO_REBIND) && norebind)
*norebind = 1;
@@ -186,6 +213,11 @@ static unsigned int search_servers(time_t now, struct all_addr **addrpp, unsigne
@@ -186,6 +213,11 @@ static unsigned int search_servers(time_t now, union all_addr **addrpp, unsigned
if (domainlen >= matchlen)
{
*type = serv->flags & (SERV_HAS_DOMAIN | SERV_USE_RESOLV | SERV_NO_REBIND | SERV_DO_DNSSEC);
Expand All @@ -161,7 +161,7 @@ index 3dd8633..d328b77 100644
*domain = serv->domain;
matchlen = domainlen;
if (serv->flags & SERV_NO_ADDR)
@@ -250,6 +282,27 @@ static unsigned int search_servers(time_t now, struct all_addr **addrpp, unsigne
@@ -246,6 +278,27 @@ static unsigned int search_servers(time_t now, union all_addr **addrpp, unsigned
return flags;
}

Expand All @@ -187,9 +187,9 @@ index 3dd8633..d328b77 100644
+}
+
static int forward_query(int udpfd, union mysockaddr *udpaddr,
struct all_addr *dst_addr, unsigned int dst_iface,
union all_addr *dst_addr, unsigned int dst_iface,
struct dns_header *header, size_t plen, time_t now,
@@ -328,7 +381,12 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
@@ -321,7 +374,12 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
#endif

/* retry on existing query, send to all available servers */
Expand All @@ -203,7 +203,7 @@ index 3dd8633..d328b77 100644
forward->sentto->failed_queries++;
if (!option_bool(OPT_ORDER))
{
@@ -465,7 +523,7 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
@@ -458,7 +516,7 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
must be NULL also. */

if (type == (start->flags & SERV_TYPE) &&
Expand All @@ -212,7 +212,7 @@ index 3dd8633..d328b77 100644
!(start->flags & (SERV_LITERAL_ADDRESS | SERV_LOOP)))
{
int fd;
@@ -2016,7 +2074,7 @@ unsigned char *tcp_request(int confd, time_t now,
@@ -1998,7 +2056,7 @@ unsigned char *tcp_request(int confd, time_t now,

/* server for wrong domain */
if (type != (last_server->flags & SERV_TYPE) ||
Expand All @@ -222,10 +222,10 @@ index 3dd8633..d328b77 100644
continue;

diff --git a/src/network.c b/src/network.c
index 8ae7a70..2e9e7b7 100644
index 4bada37..dcca1be 100644
--- a/src/network.c
+++ b/src/network.c
@@ -1553,7 +1553,7 @@ void check_servers(void)
@@ -1520,7 +1520,7 @@ void check_servers(void)
serv->sfd->used = 1;
}

Expand All @@ -235,10 +235,10 @@ index 8ae7a70..2e9e7b7 100644
if (++count > SERVERS_LOGGED)
continue;
diff --git a/src/option.c b/src/option.c
index 44b1dc5..d48088f 100644
index 1f698da..a039b40 100644
--- a/src/option.c
+++ b/src/option.c
@@ -2417,6 +2417,12 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
@@ -2559,6 +2559,12 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
while (rebind || (end = split_chr(arg, '/')))
{
char *domain = NULL;
Expand All @@ -251,7 +251,7 @@ index 44b1dc5..d48088f 100644
/* elide leading dots - they are implied in the search algorithm */
while (*arg == '.') arg++;
/* # matches everything and becomes a zero length domain string */
@@ -2424,12 +2430,27 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
@@ -2566,12 +2572,27 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
domain = "";
else if (strlen (arg) != 0 && !(domain = canonicalise_opt(arg)))
ret_err(gen_err);
Expand Down Expand Up @@ -281,10 +281,10 @@ index 44b1dc5..d48088f 100644
if (rebind)
break;
diff --git a/src/rfc1035.c b/src/rfc1035.c
index 6290f22..a25ece1 100644
index fefe63d..331ad89 100644
--- a/src/rfc1035.c
+++ b/src/rfc1035.c
@@ -1538,6 +1538,8 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
@@ -1629,6 +1629,8 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,

if ((serv->flags & (SERV_HAS_DOMAIN | SERV_NO_ADDR)) != SERV_HAS_DOMAIN)
continue;
Expand All @@ -294,10 +294,10 @@ index 6290f22..a25ece1 100644
domainlen = strlen(serv->domain);
if (domainlen == 0 || domainlen > namelen)
diff --git a/src/util.c b/src/util.c
index a947008..2e527b9 100644
index 5f13027..1a5c04e 100644
--- a/src/util.c
+++ b/src/util.c
@@ -350,6 +350,8 @@ int hostname_isequal(const char *a, const char *b)
@@ -351,6 +351,8 @@ int hostname_isequal(const char *a, const char *b)
{
unsigned int c1, c2;

Expand Down
26 changes: 13 additions & 13 deletions patches/002-regex-ipset.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/src/config.h b/src/config.h
index 633f38a..3eabd7f 100644
index 2f156eb..5799175 100644
--- a/src/config.h
+++ b/src/config.h
@@ -133,6 +133,10 @@ HAVE_REGEX
@@ -134,6 +134,10 @@ HAVE_REGEX
Define this if you want to link against lib pcre to get regex
support in "address=" matches

Expand All @@ -12,7 +12,7 @@ index 633f38a..3eabd7f 100644
+
NO_ID
Don't report *.bind CHAOS info to clients, forward such requests upstream instead.
NO_IPV6
NO_TFTP
@@ -191,6 +195,7 @@ RESOLVFILE
/* #define HAVE_CONNTRACK */
/* #define HAVE_DNSSEC */
Expand All @@ -21,7 +21,7 @@ index 633f38a..3eabd7f 100644


/* Default locations for important system files. */
@@ -415,7 +420,12 @@ static char *compile_opts =
@@ -384,7 +389,12 @@ static char *compile_opts =
#ifndef HAVE_REGEX
"no-"
#endif
Expand All @@ -36,10 +36,10 @@ index 633f38a..3eabd7f 100644
"IDN2 "
#else
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 940b212..9036df7 100644
index cafd250..d55e8ff 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -561,10 +561,24 @@ struct server {
@@ -566,10 +566,24 @@ struct server {
#endif
};

Expand All @@ -65,10 +65,10 @@ index 940b212..9036df7 100644

struct irec {
diff --git a/src/forward.c b/src/forward.c
index cb3aeb8..ad436e4 100644
index f903e5b..06ae9c6 100644
--- a/src/forward.c
+++ b/src/forward.c
@@ -663,6 +663,21 @@ static size_t process_reply(struct dns_header *header, time_t now, struct server
@@ -652,6 +652,21 @@ static size_t process_reply(struct dns_header *header, time_t now, struct server
unsigned int matchlen = 0;
for (ipset_pos = daemon->ipsets; ipset_pos; ipset_pos = ipset_pos->next)
{
Expand All @@ -90,7 +90,7 @@ index cb3aeb8..ad436e4 100644
unsigned int domainlen = strlen(ipset_pos->domain);
char *matchstart = daemon->namebuff + namelen - domainlen;
if (namelen >= domainlen && hostname_isequal(matchstart, ipset_pos->domain) &&
@@ -672,6 +687,11 @@ static size_t process_reply(struct dns_header *header, time_t now, struct server
@@ -661,6 +676,11 @@ static size_t process_reply(struct dns_header *header, time_t now, struct server
matchlen = domainlen;
sets = ipset_pos->sets;
}
Expand All @@ -103,10 +103,10 @@ index cb3aeb8..ad436e4 100644
}
#endif
diff --git a/src/option.c b/src/option.c
index d48088f..62287da 100644
index a039b40..f28f5ff 100644
--- a/src/option.c
+++ b/src/option.c
@@ -2565,6 +2565,30 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
@@ -2714,6 +2714,30 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
while ((end = split_chr(arg, '/')))
{
char *domain = NULL;
Expand Down Expand Up @@ -137,7 +137,7 @@ index d48088f..62287da 100644
/* elide leading dots - they are implied in the search algorithm */
while (*arg == '.')
arg++;
@@ -2577,6 +2601,12 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
@@ -2726,6 +2750,12 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
ipsets = ipsets->next;
memset(ipsets, 0, sizeof(struct ipsets));
ipsets->domain = domain;
Expand All @@ -150,7 +150,7 @@ index d48088f..62287da 100644
arg = end;
}
}
@@ -2585,6 +2615,11 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
@@ -2734,6 +2764,11 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
ipsets->next = opt_malloc(sizeof(struct ipsets));
ipsets = ipsets->next;
memset(ipsets, 0, sizeof(struct ipsets));
Expand Down

0 comments on commit b3ddae2

Please sign in to comment.