Skip to content

Commit

Permalink
Merge pull request #5 from pymumu/master
Browse files Browse the repository at this point in the history
Fork Sync
  • Loading branch information
PikuZheng authored Jul 4, 2022
2 parents 643c489 + 092b4ed commit b540101
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
30 changes: 27 additions & 3 deletions src/dns_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,7 @@ int _dns_server_reply_all_pending_list(struct dns_request *request, struct dns_s
context_pending.do_reply = context->do_reply;
context_pending.do_force_soa = context->do_force_soa;
context_pending.do_ipset = 0;
context_pending.reply_ttl = request->ip_ttl;
_dns_server_reply_passthrouth(&context_pending);

req->request_pending_list = NULL;
Expand Down Expand Up @@ -1753,6 +1754,11 @@ static void _dns_server_complete_with_multi_ipaddress(struct dns_request *reques
{
struct dns_server_post_context context;
int do_reply = 0;

if (request->passthrough) {
return;
}

if (request->ip_map_num > 0) {
request->has_soa = 0;
}
Expand Down Expand Up @@ -1780,16 +1786,17 @@ static void _dns_server_request_release_complete(struct dns_request *request, in
struct hlist_node *tmp;
int bucket = 0;

pthread_mutex_lock(&server.request_list_lock);
int refcnt = atomic_dec_return(&request->refcnt);
if (refcnt) {
pthread_mutex_unlock(&server.request_list_lock);
if (refcnt < 0) {
tlog(TLOG_ERROR, "BUG: refcnt is %d, domain %s, qtype %d", refcnt, request->domain, request->qtype);
abort();
}
return;
}

pthread_mutex_lock(&server.request_list_lock);
list_del_init(&request->list);
pthread_mutex_unlock(&server.request_list_lock);

Expand Down Expand Up @@ -2536,11 +2543,20 @@ static int _dns_server_get_answer(struct dns_server_post_context *context)

/* get A result */
dns_get_A(rrs, name, DNS_MAX_CNAME_LEN, &ttl, addr);
if (_dns_ip_address_check_add(request, name, addr, DNS_T_A) != 0) {
continue;
}

context->ip_num++;
if (request->has_ip == 1) {
continue;
}

memcpy(request->ip_addr, addr, DNS_RR_A_LEN);
/* add this ip to reqeust */
request->ip_ttl = _dns_server_get_conf_ttl(ttl);
request->has_ip = 1;
request->rcode = packet->head.rcode;
context->ip_num++;
} break;
case DNS_T_AAAA: {
unsigned char addr[16];
Expand All @@ -2551,11 +2567,19 @@ static int _dns_server_get_answer(struct dns_server_post_context *context)
continue;
}
dns_get_AAAA(rrs, name, DNS_MAX_CNAME_LEN, &ttl, addr);
if (_dns_ip_address_check_add(request, name, addr, DNS_T_AAAA) != 0) {
continue;
}

context->ip_num++;
if (request->has_ip == 1) {
continue;
}

memcpy(request->ip_addr, addr, DNS_RR_AAAA_LEN);
request->ip_ttl = _dns_server_get_conf_ttl(ttl);
request->has_ip = 1;
request->rcode = packet->head.rcode;
context->ip_num++;
} break;
case DNS_T_NS: {
char cname[DNS_MAX_CNAME_LEN];
Expand Down
7 changes: 4 additions & 3 deletions src/smartdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ int drop_root_privilege(void)
header.pid = 0;
int uid;
int gid;
int unused __attribute__((unused));

if (get_uid_gid(&uid, &gid) != 0) {
return -1;
Expand All @@ -113,8 +114,8 @@ int drop_root_privilege(void)
prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
cap.effective |= (1 << CAP_NET_RAW | 1 << CAP_NET_ADMIN);
cap.permitted |= (1 << CAP_NET_RAW | 1 << CAP_NET_ADMIN);
setuid(uid);
setgid(gid);
unused = setuid(uid);
unused = setgid(gid);
if (capset(&header, &cap) < 0) {
return -1;
}
Expand Down Expand Up @@ -476,7 +477,7 @@ int main(int argc, char *argv[])

/* patch for Asus router: unblock all signal*/
sigemptyset(&empty_sigblock);
sigprocmask(SIG_SETMASK, &empty_sigblock, NULL);
sigprocmask(SIG_SETMASK, &empty_sigblock, NULL);

while ((opt = getopt(argc, argv, "fhc:p:Svx")) != -1) {
switch (opt) {
Expand Down

0 comments on commit b540101

Please sign in to comment.