-
Notifications
You must be signed in to change notification settings - Fork 15
/
001-regex-server.patch
655 lines (618 loc) · 19 KB
/
001-regex-server.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
diff --git a/Makefile b/Makefile
index 253ebb9..d561799 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,11 @@ MANDIR = $(PREFIX)/share/man
LOCALEDIR = $(PREFIX)/share/locale
BUILDDIR = $(SRC)
DESTDIR =
+ifndef BUILD_DEBUG
CFLAGS = -Wall -W -O2
+else
+CFLAGS = -Wall -W -g
+endif
LDFLAGS =
COPTS =
RPM_OPT_FLAGS =
@@ -66,6 +70,8 @@ lua_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CON
nettle_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --cflags 'nettle hogweed'`
nettle_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --libs 'nettle hogweed'`
gmp_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC NO_GMP --copy -lgmp`
+regex_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_REGEX $(PKG_CONFIG) --cflags libpcre`
+regex_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_REGEX $(PKG_CONFIG) --libs libpcre`
sunos_libs = `if uname | grep SunOS >/dev/null 2>&1; then echo -lsocket -lnsl -lposix4; fi`
nft_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_NFTSET $(PKG_CONFIG) --cflags libnftables`
nft_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_NFTSET $(PKG_CONFIG) --libs libnftables`
@@ -89,8 +95,8 @@ hdrs = dnsmasq.h config.h dhcp-protocol.h dhcp6-protocol.h \
all : $(BUILDDIR)
@cd $(BUILDDIR) && $(MAKE) \
top="$(top)" \
- build_cflags="$(version) $(dbus_cflags) $(idn2_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags) $(nft_cflags)" \
- build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs) $(ubus_libs) $(nft_libs)" \
+ build_cflags="$(version) $(dbus_cflags) $(idn2_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags) $(nft_cflags) $(regex_cflags)" \
+ build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs) $(ubus_libs) $(nft_libs) $(regex_libs)" \
-f $(top)/Makefile dnsmasq
mostly_clean :
@@ -114,8 +120,8 @@ all-i18n : $(BUILDDIR)
@cd $(BUILDDIR) && $(MAKE) \
top="$(top)" \
i18n=-DLOCALEDIR=\'\"$(LOCALEDIR)\"\' \
- build_cflags="$(version) $(dbus_cflags) $(idn2_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags) $(nft_cflags)" \
- build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs) $(ubus_libs) $(nft_libs)" \
+ build_cflags="$(version) $(dbus_cflags) $(idn2_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags) $(nft_cflags) $(regex_cflags)" \
+ build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs) $(ubus_libs) $(nft_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 5e65df6..0aed8d7 100644
--- a/src/config.h
+++ b/src/config.h
@@ -199,6 +199,7 @@ RESOLVFILE
/* #define HAVE_CONNTRACK */
/* #define HAVE_DNSSEC */
/* #define HAVE_NFTSET */
+/* #define HAVE_REGEX */
/* Default locations for important system files. */
@@ -388,6 +389,10 @@ static char *compile_opts =
"no-"
#endif
"i18n "
+#ifndef HAVE_REGEX
+"no-"
+#endif
+"regex "
#if defined(HAVE_LIBIDN2)
"IDN2 "
#else
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index a9ac815..d3ae714 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -162,6 +162,10 @@ extern int capget(cap_user_header_t header, cap_user_data_t data);
/* daemon is function in the C library.... */
#define daemon dnsmasq_daemon
+#ifdef HAVE_REGEX
+#include <pcre.h>
+#endif
+
#define ADDRSTRLEN INET6_ADDRSTRLEN
/* Async event queue */
@@ -592,6 +596,10 @@ struct randfd_list {
struct server {
u16 flags, domain_len;
char *domain;
+#ifdef HAVE_REGEX
+ pcre *regex;
+ pcre_extra *pextra;
+#endif
struct server *next;
int serial, arrayposn;
int last_server;
@@ -613,6 +621,10 @@ struct server {
struct serv_addr4 {
u16 flags, domain_len;
char *domain;
+#ifdef HAVE_REGEX
+ pcre *regex;
+ pcre_extra *pextra;
+#endif
struct server *next;
struct in_addr addr;
};
@@ -620,6 +632,10 @@ struct serv_addr4 {
struct serv_addr6 {
u16 flags, domain_len;
char *domain;
+#ifdef HAVE_REGEX
+ pcre *regex;
+ pcre_extra *pextra;
+#endif
struct server *next;
struct in6_addr addr;
};
@@ -627,6 +643,10 @@ struct serv_addr6 {
struct serv_local {
u16 flags, domain_len;
char *domain;
+#ifdef HAVE_REGEX
+ pcre *regex;
+ pcre_extra *pextra;
+#endif
struct server *next;
};
@@ -1180,6 +1200,9 @@ extern struct daemon {
struct rebind_domain *no_rebind;
int server_has_wildcard;
int serverarraysz, serverarrayhwm;
+#ifdef HAVE_REGEX
+ int regexserverarraysz, regexlocaldomainarraysz;
+#endif
struct ipsets *ipsets, *nftsets;
u32 allowlist_mask;
struct allowlist *allowlists;
@@ -1898,6 +1921,12 @@ void dump_packet_icmp(int mask, void *packet, size_t len, union mysockaddr *src,
#endif
/* domain-match.c */
+#ifdef HAVE_REGEX
+int is_local_regex_answer(const char *domain, int *first, int *last);
+int find_regex_server(const char* domain, int is_local, int *arraypos);
+int match_regex(const pcre *regex, const pcre_extra *pextra, const char *str, size_t len);
+const char *parse_regex_option(const char *arg, pcre **regex, pcre_extra **pextra);
+#endif
void build_server_array(void);
int lookup_domain(char *qdomain, int flags, int *lowout, int *highout);
int filter_servers(int seed, int flags, int *lowout, int *highout);
diff --git a/src/domain-match.c b/src/domain-match.c
index 642db2a..f143074 100644
--- a/src/domain-match.c
+++ b/src/domain-match.c
@@ -27,47 +27,90 @@ void build_server_array(void)
{
struct server *serv;
int count = 0;
+#ifdef HAVE_REGEX
+ int regexserverarrayidx = 0;
+ int regexlocaldomainarrayidx = 0;
+ int regexserverarraysz = 0;
+ int regexlocaldomainarraysz = 0;
+#endif
- for (serv = daemon->servers; serv; serv = serv->next)
+ for (serv = daemon->servers; serv; serv = serv->next){
#ifdef HAVE_LOOP
if (!(serv->flags & SERV_LOOP))
+#endif
+ {
+#ifdef HAVE_REGEX
+ if(serv->regex)
+ ++regexserverarraysz;
+ else
#endif
{
count++;
if (serv->flags & SERV_WILDCARD)
daemon->server_has_wildcard = 1;
}
+ }
+ }
- for (serv = daemon->local_domains; serv; serv = serv->next)
+ for (serv = daemon->local_domains; serv; serv = serv->next){
+#ifdef HAVE_REGEX
+ if(serv->regex)
+ ++regexlocaldomainarraysz;
+ else
+#endif
{
count++;
if (serv->flags & SERV_WILDCARD)
daemon->server_has_wildcard = 1;
}
+ }
daemon->serverarraysz = count;
+#ifdef HAVE_REGEX
+ if (count > daemon->serverarrayhwm || (regexserverarraysz + regexlocaldomainarraysz) > (daemon->regexserverarraysz + daemon->regexlocaldomainarraysz))
+#else
if (count > daemon->serverarrayhwm)
+#endif
{
struct server **new;
count += 10; /* A few extra without re-allocating. */
+#ifdef HAVE_REGEX
+ if ((new = whine_malloc((count + regexserverarraysz + regexlocaldomainarraysz) * sizeof(struct server *))))
+#else
if ((new = whine_malloc(count * sizeof(struct server *))))
+#endif
{
if (daemon->serverarray)
free(daemon->serverarray);
daemon->serverarray = new;
daemon->serverarrayhwm = count;
+#ifdef HAVE_REGEX
+ daemon->regexserverarraysz = regexserverarraysz;
+ daemon->regexlocaldomainarraysz = regexlocaldomainarraysz;
+#endif
}
}
count = 0;
+#ifdef HAVE_REGEX
+ regexserverarrayidx = daemon->serverarrayhwm;
+ regexlocaldomainarrayidx = regexserverarrayidx + daemon->regexserverarraysz;
+#endif
- for (serv = daemon->servers; serv; serv = serv->next)
+ for (serv = daemon->servers; serv; serv = serv->next){
#ifdef HAVE_LOOP
if (!(serv->flags & SERV_LOOP))
+#endif
+ {
+#ifdef HAVE_REGEX
+ if(serv->regex){
+ daemon->serverarray[regexserverarrayidx++]=serv;
+ continue;
+ }else
#endif
{
daemon->serverarray[count] = serv;
@@ -75,9 +118,18 @@ void build_server_array(void)
serv->last_server = -1;
count++;
}
-
- for (serv = daemon->local_domains; serv; serv = serv->next, count++)
- daemon->serverarray[count] = serv;
+ }
+ }
+
+ for (serv = daemon->local_domains; serv; serv = serv->next){
+#ifdef HAVE_REGEX
+ if(serv->regex){
+ daemon->serverarray[regexlocaldomainarrayidx++]=serv;
+ continue;
+ }else
+#endif
+ daemon->serverarray[count++] = serv;
+ }
qsort(daemon->serverarray, daemon->serverarraysz, sizeof(struct server *), order_qsort);
@@ -86,6 +138,20 @@ void build_server_array(void)
for (count = 0; count < daemon->serverarraysz; count++)
if (!(daemon->serverarray[count]->flags & SERV_IS_LOCAL))
daemon->serverarray[count]->arrayposn = count;
+
+#ifdef HAVE_REGEX
+ for (count = daemon->serverarrayhwm; count < daemon->serverarrayhwm + daemon->regexserverarraysz; ++count)
+ daemon->serverarray[count]->arrayposn = count;
+#endif
+
+#if 0 // print the whole array, for debug only
+ for(count=0; count < daemon->serverarrayhwm + daemon->regexserverarraysz + daemon->regexlocaldomainarraysz; ++count){
+ struct server* sv= daemon->serverarray[count];
+ if(sv)
+ printf("i = %d, flag=%u, p=%p, nextP=%p, domain = %s, sfd=%p\n",
+ count, sv->flags, sv, sv->next, sv->domain, sv->sfd);
+ }
+#endif
}
/* we're looking for the server whose domain is the longest exact match
@@ -103,6 +169,11 @@ void build_server_array(void)
*/
int lookup_domain(char *domain, int flags, int *lowout, int *highout)
{
+#ifdef HAVE_REGEX
+ int needsearchregex = 1;
+ const char* originaldomain = domain;
+#endif
+ int founddomain = 0;
int rc, crop_query, nodots;
ssize_t qlen;
int try, high, low = 0;
@@ -111,7 +182,7 @@ int lookup_domain(char *domain, int flags, int *lowout, int *highout)
/* may be no configured servers. */
if (daemon->serverarraysz == 0)
- return 0;
+ goto search_regex;
/* find query length and presence of '.' */
for (cp = qdomain, nodots = 1, qlen = 0; *cp; qlen++, cp++)
@@ -255,9 +326,42 @@ int lookup_domain(char *domain, int flags, int *lowout, int *highout)
/* qlen == -1 when we failed to match even an empty query, if there are no default servers. */
if (nlow == nhigh || qlen == -1)
- return 0;
-
- return 1;
+ goto search_regex;
+
+ founddomain = 1;
+
+search_regex:
+#ifdef HAVE_REGEX
+ if (founddomain){
+ if (daemon->serverarray[nlow]->domain_len > 0) // have found a valid upstream
+ needsearchregex = 0;
+ }
+
+ if (needsearchregex){
+ int found_regex = find_regex_server(originaldomain, 0, &low);
+
+ if(!found_regex && find_regex_server(originaldomain, 1, &low)){
+ found_regex=1;
+
+ // special step for parse "server=/:xxx:/#"
+ if(daemon->serverarray[low]->flags & SERV_USE_RESOLV){
+ if(filter_servers(try, F_SERVER, &nlow, &nhigh)){
+ low=nlow;
+ }
+ }
+ }
+
+ if(found_regex){
+ if (lowout)
+ *lowout = low;
+ if (highout)
+ *highout = low + 1;
+
+ founddomain = 1;
+ }
+ }
+#endif
+ return founddomain;
}
/* Return first server in group of equivalent servers; this is the "master" record. */
@@ -270,6 +374,14 @@ int filter_servers(int seed, int flags, int *lowout, int *highout)
{
int nlow = seed, nhigh = seed;
int i;
+
+#ifdef HAVE_REGEX
+ if(nlow >= daemon->serverarrayhwm){
+ *lowout = nlow;
+ *highout = nlow+1;
+ return 1;
+ }
+#endif
/* expand nlow and nhigh to cover all the records with the same domain
nlow is the first, nhigh - 1 is the last. nlow=nhigh means no servers,
@@ -366,6 +478,89 @@ int filter_servers(int seed, int flags, int *lowout, int *highout)
return (nlow != nhigh);
}
+#ifdef HAVE_REGEX
+// return flags, or 0 if not found
+// if argument domain is NULL, check the 'first' server is local answer, make sure 'first' is valid
+int is_local_regex_answer(const char *domain, int *first, int *last)
+{
+ int flags = 0;
+ int rc = 0;
+ int arraypos = 0;
+ int found = 1;
+
+ if(domain){
+ found = find_regex_server(domain, 1, &arraypos);
+ if(found){
+ *first = arraypos;
+ *last = *first + 1;
+ }
+ }else
+ arraypos = *first;
+
+ if(found){
+ struct server *r = daemon->serverarray[arraypos];
+
+ flags = r->flags;
+ if (flags & SERV_4ADDR)
+ rc = F_IPV4;
+ else if (flags & SERV_6ADDR)
+ rc = F_IPV6;
+ else if (flags & SERV_ALL_ZEROS)
+ rc = F_IPV4 | F_IPV6;
+ }
+ return rc;
+}
+
+// return 0 if failed to find
+int find_regex_server(const char* domain, int is_local, int *arraypos)
+{
+ int iFirst = daemon->serverarrayhwm;
+ int iLast = daemon->serverarrayhwm + daemon->regexserverarraysz;
+ const size_t domainLength = strlen(domain);
+
+ if (is_local){
+ iFirst = iLast;
+ iLast += daemon->regexlocaldomainarraysz;
+ }
+
+ while(iFirst < iLast){
+ struct server* r = daemon->serverarray[iFirst];
+ if (match_regex(r->regex, r->pextra, domain, domainLength)){
+ *arraypos=iFirst;
+ return 1;
+ }
+ ++iFirst;
+ }
+
+ return 0;
+}
+
+// return 0 if failed to match
+int match_regex(const pcre *regex, const pcre_extra *pextra, const char *str, size_t len)
+{
+ int captcount = 0;
+ int ret = 0;
+ if (pcre_fullinfo(regex, pextra, PCRE_INFO_CAPTURECOUNT, &captcount) == 0)
+ {
+ /* C99 dyn-array, or alloca must be used */
+ int ovect[(captcount + 1) * 3];
+ ret = pcre_exec(regex, pextra, str, len, 0, 0, ovect, (captcount + 1) * 3) > 0;
+ }
+ return ret;
+}
+
+const char *parse_regex_option(const char *arg, pcre **regex, pcre_extra **pextra)
+{
+ const char *error;
+ int erroff;
+ *regex = pcre_compile(arg, 0, &error, &erroff, NULL);
+ if(NULL == *regex)
+ return error;
+ *pextra = pcre_study(*regex, 0, &error);
+ return NULL;
+}
+#endif
+
int is_local_answer(time_t now, int first, char *name)
{
int flags = 0;
@@ -519,6 +714,9 @@ static int order(char *qdomain, size_t qlen, struct server *serv)
static int order_servers(struct server *s1, struct server *s2)
{
int rc;
+#ifdef HAVE_REGEX
+ if(!s1) return -1;
+#endif
/* need full comparison of dotless servers in
order_qsort() and filter_servers() */
@@ -640,6 +838,9 @@ int add_update_server(int flags,
const char *domain,
union all_addr *local_addr)
{
+#ifdef HAVE_REGEX
+ const char* regex = NULL;
+#endif
struct server *serv = NULL;
char *alloc_domain;
@@ -655,10 +856,32 @@ int add_update_server(int flags,
if (*domain != 0)
flags |= SERV_WILDCARD;
}
-
+#ifdef HAVE_REGEX
+ else{
+ size_t domainLen=strlen(domain);
+ char* regex_end=(char*)domain+domainLen-1;
+ if (domainLen > 2 && *domain == ':' && *regex_end == ':'){
+ const char* err = NULL;
+
+ ++domain; // skip leading ':'
+ --domainLen; // skip leading ':'
+
+ *regex_end = '\0'; // skip tailing ':'
+ regex = domain;
+
+ // call whine_malloc() instead of canonicalise()
+ if ((alloc_domain = whine_malloc(domainLen)))
+ memcpy(alloc_domain, domain, domainLen);
+ }
+ }
+#endif
+
if (*domain == 0)
alloc_domain = whine_malloc(1);
else
+#ifdef HAVE_REGEX
+ if(!regex)
+#endif
alloc_domain = canonicalise((char *)domain, NULL);
if (!alloc_domain)
@@ -760,6 +983,16 @@ int add_update_server(int flags,
serv->flags = flags;
serv->domain = alloc_domain;
serv->domain_len = strlen(alloc_domain);
+
+#ifdef HAVE_REGEX
+ if (regex){
+ const char* err = NULL;
+ if ((err = (char *)parse_regex_option(regex, &serv->regex, &serv->pextra))){
+ printf("parse_regex_option: %s\n", err);
+ return 0;
+ }
+ }
+#endif
return 1;
}
diff --git a/src/forward.c b/src/forward.c
index fa696e5..71b4016 100644
--- a/src/forward.c
+++ b/src/forward.c
@@ -314,6 +314,11 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
/* Configured answer. */
if (flags || ede == EDE_NOT_READY)
goto reply;
+
+#ifdef HAVE_REGEX
+ if ((flags = is_local_regex_answer(NULL, &first, &last)))
+ goto reply;
+#endif
if (!(forward = get_new_frec(now, master, 0)))
goto reply;
@@ -392,6 +397,9 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
forward->forwardall = 1;
}
else
+#ifdef HAVE_REGEX
+ if(!master->regex)
+#endif
start = master->last_server;
}
}
@@ -428,7 +436,14 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
forward->sentto->failed_queries++;
else
forward->sentto->retrys++;
-
+
+#ifdef HAVE_REGEX
+ if(forward->sentto->regex){
+ start = first = forward->sentto->arrayposn;
+ last = first + 1;
+ forward->forwardall = 0;
+ }else
+#endif
if (!filter_servers(forward->sentto->arrayposn, F_SERVER, &first, &last))
goto reply;
@@ -478,8 +493,13 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
while (1)
{
int fd;
- struct server *srv = daemon->serverarray[start];
-
+
+ struct server *srv = daemon->serverarray[start];
+#ifdef HAVE_REGEX
+ if (srv->regex)
+ forward->forwardall = 0; // make it send only once
+#endif
+
if ((fd = allocate_rfd(&forward->rfds, srv)) != -1)
{
@@ -2416,8 +2436,17 @@ unsigned char *tcp_request(int confd, time_t now,
no_cache_dnssec = 1;
if (lookup_domain(daemon->namebuff, gotname, &first, &last))
+ {
flags = is_local_answer(now, first, daemon->namebuff);
+#ifdef HAVE_REGEX
+ if(!flags)
+ flags = is_local_regex_answer(NULL, &first, &last);
+#endif
+ }
else
+#ifdef HAVE_REGEX
+ if(!(flags = is_local_regex_answer(daemon->namebuff, &first, &last)))
+#endif
ede = EDE_NOT_READY;
if (!flags && ede == EDE_UNSET)
@@ -2432,7 +2461,11 @@ unsigned char *tcp_request(int confd, time_t now,
{
master = daemon->serverarray[first];
+#ifdef HAVE_REGEX
+ if (option_bool(OPT_ORDER) || master->last_server == -1 || master->regex)
+#else
if (option_bool(OPT_ORDER) || master->last_server == -1)
+#endif
start = first;
else
start = master->last_server;
diff --git a/src/network.c b/src/network.c
index 36d9262..eb5f08b 100644
--- a/src/network.c
+++ b/src/network.c
@@ -1667,6 +1667,10 @@ void check_servers(int no_loop_check)
s1 = _("unqualified"), s2 = _("names");
else if (strlen(serv->domain) == 0)
s1 = _("default"), s2 = "";
+#ifdef HAVE_REGEX
+ else if (serv->regex)
+ s1 = _("regex domain"), s2 = serv->domain;
+#endif
else
s1 = _("domain"), s2 = serv->domain, s4 = (serv->flags & SERV_WILDCARD) ? "*" : "";
@@ -1696,8 +1700,14 @@ void check_servers(int no_loop_check)
if (++locals <= LOCALS_LOGGED)
my_syslog(LOG_INFO, _("using only locally-known addresses for %s"), serv->domain);
}
- else if (serv->flags & SERV_USE_RESOLV)
+ else if (serv->flags & SERV_USE_RESOLV){
+#ifdef HAVE_REGEX
+ if (serv->regex)
+ my_syslog(LOG_INFO, _("using standard nameservers for regex domain %s"), serv->domain);
+ else
+#endif
my_syslog(LOG_INFO, _("using standard nameservers for %s"), serv->domain);
+ }
}
if (locals > LOCALS_LOGGED)