Skip to content

Commit 34c5e71

Browse files
https-record: add noech (#2132)
1 parent 3c4f280 commit 34c5e71

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

etc/smartdns/smartdns.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ log-level info
321321
# srv-record /_ldap._tcp.example.com/
322322

323323
# https-record /domain/[target=][,port=][,priority=][,alph=][,ech=][,ipv4hint=][,ipv6hint=]
324-
# https-record noipv4hint,noipv6hint
324+
# https-record noipv4hint,noipv6hint,noech
325325
# https-record /www.example.com/ipv4hint=192.168.1.2
326326

327327
# enable DNS64 feature

src/dns_conf/https_record.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ int _conf_domain_rule_https_record(const char *domain, const char *host)
108108
https_record_rule->filter.no_ipv4hint = 1;
109109
} else if (strncmp(key, "noipv6hint", sizeof("noipv6hint")) == 0) {
110110
https_record_rule->filter.no_ipv6hint = 1;
111+
} else if (strncmp(key, "noech", sizeof("noech")) == 0) {
112+
https_record_rule->filter.no_ech = 1;
111113
} else {
112114
mode_type = 1;
113115
https_record_rule->record.enable = 1;

src/dns_server/answer.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,7 @@ static int _dns_server_process_answer_HTTPS(struct dns_rrs *rrs, struct dns_requ
240240
struct dns_https_param *p = NULL;
241241
int priority = 0;
242242
struct dns_request_https *https_svcb;
243-
int no_ipv4 = 0;
244-
int no_ipv6 = 0;
245243
struct dns_https_record_rule *https_record_rule = _dns_server_get_dns_rule(request, DOMAIN_RULE_HTTPS);
246-
if (https_record_rule) {
247-
if (https_record_rule->filter.no_ipv4hint) {
248-
no_ipv4 = 1;
249-
}
250-
251-
if (https_record_rule->filter.no_ipv6hint) {
252-
no_ipv6 = 1;
253-
}
254-
}
255244

256245
ret = dns_get_HTTPS_svcparm_start(rrs, &p, name, DNS_MAX_CNAME_LEN, &ttl, &priority, target, DNS_MAX_CNAME_LEN);
257246
if (ret != 0) {
@@ -290,7 +279,7 @@ static int _dns_server_process_answer_HTTPS(struct dns_rrs *rrs, struct dns_requ
290279
} break;
291280
case DNS_HTTPS_T_IPV4HINT: {
292281
struct dns_rule_address_IPV4 *address_ipv4 = NULL;
293-
if (_dns_server_is_return_soa_qtype(request, DNS_T_A) || no_ipv4 == 1) {
282+
if (_dns_server_is_return_soa_qtype(request, DNS_T_A) || (https_record_rule && https_record_rule->filter.no_ipv4hint)) {
294283
break;
295284
}
296285

@@ -311,6 +300,10 @@ static int _dns_server_process_answer_HTTPS(struct dns_rrs *rrs, struct dns_requ
311300
}
312301
} break;
313302
case DNS_HTTPS_T_ECH: {
303+
if (https_record_rule && https_record_rule->filter.no_ech) {
304+
break;
305+
}
306+
314307
if (p->len > sizeof(https_svcb->ech)) {
315308
tlog(TLOG_WARN, "ech too long");
316309
break;
@@ -321,7 +314,7 @@ static int _dns_server_process_answer_HTTPS(struct dns_rrs *rrs, struct dns_requ
321314
case DNS_HTTPS_T_IPV6HINT: {
322315
struct dns_rule_address_IPV6 *address_ipv6 = NULL;
323316

324-
if (_dns_server_is_return_soa_qtype(request, DNS_T_AAAA) || no_ipv6 == 1) {
317+
if (_dns_server_is_return_soa_qtype(request, DNS_T_AAAA) || (https_record_rule && https_record_rule->filter.no_ipv6hint)) {
325318
break;
326319
}
327320

src/include/smartdns/dns_conf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ struct dns_https_record {
312312
struct dns_https_filter {
313313
int no_ipv4hint;
314314
int no_ipv6hint;
315+
int no_ech;
315316
};
316317

317318
struct dns_https_record_rule {

test/cases/test-https.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ server 127.0.0.1:61053
427427
log-console yes
428428
dualstack-ip-selection no
429429
force-qtype-SOA 65
430-
https-record /a.com/noipv4hint,noipv6hint
430+
https-record /a.com/noipv4hint,noipv6hint,noech
431431
log-level debug
432432
cache-persist no)""");
433433
smartdns::Client client;
@@ -451,7 +451,7 @@ cache-persist no)""");
451451
EXPECT_EQ(client.GetStatus(), "NOERROR");
452452
EXPECT_EQ(client.GetAnswer()[0].GetName(), "a.com");
453453
EXPECT_EQ(client.GetAnswer()[0].GetType(), "HTTPS");
454-
EXPECT_EQ(client.GetAnswer()[0].GetData(), "1 a.com. alpn=\"h2,h3-19\" port=443 ech=AEX+DQA=");
454+
EXPECT_EQ(client.GetAnswer()[0].GetData(), "1 a.com. alpn=\"h2,h3-19\" port=443");
455455
}
456456

457457
TEST_F(HTTPS, HTTPS_DOMAIN_RULE_IGN)
@@ -659,7 +659,7 @@ TEST_F(HTTPS, multi_not_support)
659659
server 127.0.0.1:61053
660660
log-console yes
661661
dualstack-ip-selection no
662-
https-record noipv4hint,noipv6hint
662+
https-record noipv4hint,noipv6hint,noech
663663
log-level debug
664664
cache-persist no)""");
665665
smartdns::Client client;

0 commit comments

Comments
 (0)