|
@@ -5,7 +5,7 @@
|
5
|
5
|
***********************************************
|
6
|
6
|
******* BEGIN 3/2006 ********
|
7
|
7
|
*************************************************************************
|
8
|
|
-* *
|
|
8
|
+* *
|
9
|
9
|
* This program is free software; you can redistribute it and/or modify *
|
10
|
10
|
* it under the terms of the GNU General Public License as published by *
|
11
|
11
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
@@ -131,19 +131,19 @@ int collect_resolv_conf(char *resolve_conf)
|
131
|
131
|
while ((crow=fgets(buf,512,erc)) && _andns_ns_count_<MAXNSSERVERS) {
|
132
|
132
|
if (!(crow=strstr(buf,"nameserver "))) /* is a good line? */
|
133
|
133
|
continue;
|
134
|
|
-
|
|
134
|
+
|
135
|
135
|
/* Skip if the line is commented */
|
136
|
136
|
*crow=0;
|
137
|
137
|
if(strchr(buf, '#'))
|
138
|
138
|
continue;
|
139
|
|
-
|
|
139
|
+
|
140
|
140
|
crow+=11;
|
141
|
|
-
|
|
141
|
+
|
142
|
142
|
/* remove unwanted chars */
|
143
|
143
|
strip_char(crow, '\t');
|
144
|
144
|
strip_char(crow, ' ');
|
145
|
145
|
strip_char(crow, '\n');
|
146
|
|
-
|
|
146
|
+
|
147
|
147
|
store_ns(crow); /* finally store nameserver */
|
148
|
148
|
}
|
149
|
149
|
if (fclose(erc)!=0) {
|
|
@@ -151,7 +151,7 @@ int collect_resolv_conf(char *resolve_conf)
|
151
|
151
|
"resolv.conf -> %s",strerror(errno));
|
152
|
152
|
err_ret(ERR_RSLERC,-1);
|
153
|
153
|
}
|
154
|
|
- if (!_andns_ns_count_)
|
|
154
|
+ if (!_andns_ns_count_)
|
155
|
155
|
err_ret(ERR_RSLNNS,-1);
|
156
|
156
|
return _andns_ns_count_;
|
157
|
157
|
}
|
|
@@ -418,10 +418,10 @@ int is_prefixed(dns_pkt *dp)
|
418
|
418
|
}
|
419
|
419
|
|
420
|
420
|
/*
|
421
|
|
- * A very stupid function that converts
|
|
421
|
+ * A very stupid function that converts
|
422
|
422
|
* ANDNS code to DNS code.
|
423
|
423
|
*/
|
424
|
|
-int qtype_a_to_d(andns_pkt *ap)
|
|
424
|
+int qtype_a_to_d(andns_pkt *ap)
|
425
|
425
|
{
|
426
|
426
|
switch (ap->qtype) {
|
427
|
427
|
case AT_PTR:
|
|
@@ -431,7 +431,7 @@ int qtype_a_to_d(andns_pkt *ap)
|
431
|
431
|
return T_MX;
|
432
|
432
|
else if (!ap->service)
|
433
|
433
|
return T_A;
|
434
|
|
- else
|
|
434
|
+ else
|
435
|
435
|
return -1;
|
436
|
436
|
default:
|
437
|
437
|
return -1;
|
|
@@ -456,7 +456,7 @@ int apqsttodpqst(andns_pkt *ap,dns_pkt **dpsrc)
|
456
|
456
|
|
457
|
457
|
if (qt==T_A || qt==T_MX) {
|
458
|
458
|
qlen=strlen(ap->qstdata);
|
459
|
|
- if (qlen>DNS_MAX_HNAME_LEN)
|
|
459
|
+ if (qlen>DNS_MAX_HNAME_LEN)
|
460
|
460
|
goto incomp_err;
|
461
|
461
|
strcpy(dpq->qname,ap->qstdata);
|
462
|
462
|
}
|
|
@@ -475,13 +475,13 @@ int apqsttodpqst(andns_pkt *ap,dns_pkt **dpsrc)
|
475
|
475
|
goto incomp_err;
|
476
|
476
|
}
|
477
|
477
|
res=swapped_straddr_pref(temp,
|
478
|
|
- dpq->qname,family);
|
|
478
|
+ dpq->qname,family);
|
479
|
479
|
if (res==-1) {
|
480
|
480
|
debug(DBG_INSANE,err_str);
|
481
|
481
|
goto incomp_err;
|
482
|
482
|
}
|
483
|
483
|
}
|
484
|
|
- else
|
|
484
|
+ else
|
485
|
485
|
goto incomp_err;
|
486
|
486
|
dph->id=ap->id;
|
487
|
487
|
dph->rd=1;
|
|
@@ -503,14 +503,14 @@ int dpanswtoapansw(dns_pkt *dp,andns_pkt *ap)
|
503
|
503
|
rcode=DNS_GET_RCODE(dp);
|
504
|
504
|
ap->rcode=rcode;
|
505
|
505
|
ap->qr=1;
|
506
|
|
-
|
507
|
|
- if (rcode!=DNS_RCODE_NOERR)
|
|
506
|
+
|
|
507
|
+ if (rcode!=DNS_RCODE_NOERR)
|
508
|
508
|
return 0;
|
509
|
509
|
|
510
|
510
|
qt=dp->pkt_qst->qtype;
|
511
|
511
|
dpa=dp->pkt_answ;
|
512
|
512
|
for (i=0;i<ancount;i++) {
|
513
|
|
- if (!dpa)
|
|
513
|
+ if (!dpa)
|
514
|
514
|
break;
|
515
|
515
|
apd=andns_add_answ(ap);
|
516
|
516
|
if (qt==T_A) {
|
|
@@ -518,7 +518,7 @@ int dpanswtoapansw(dns_pkt *dp,andns_pkt *ap)
|
518
|
518
|
APD_ALIGN(apd);
|
519
|
519
|
memcpy(apd->rdata,dpa->rdata,_ip_len_);
|
520
|
520
|
nan++;
|
521
|
|
- }
|
|
521
|
+ }
|
522
|
522
|
else if (qt==T_PTR ) {
|
523
|
523
|
apd->rdlength=strlen(dpa->rdata);
|
524
|
524
|
APD_ALIGN(apd);
|
|
@@ -543,7 +543,7 @@ int dpanswtoapansw(dns_pkt *dp,andns_pkt *ap)
|
543
|
543
|
// memcpy(&(apd->prio),dpa->rdata,sizeof(uint16_t));
|
544
|
544
|
nan++;
|
545
|
545
|
}
|
546
|
|
- else
|
|
546
|
+ else
|
547
|
547
|
andns_del_answ(ap);
|
548
|
548
|
dpa=dpa->next;
|
549
|
549
|
}
|
|
@@ -603,6 +603,8 @@ int andns_gethostbyname(char *hname, inet_prefix *ip)
|
603
|
603
|
error(err_str);
|
604
|
604
|
err_ret(ERR_RSLRSL,-1);
|
605
|
605
|
}
|
|
606
|
+ fprintf(stderr, "Addr is %p, rdata is %p\n", (void*)addr, (void*) dp->pkt_answ->rdata);
|
|
607
|
+ if ((dp == NULL) || (dp->pkt_answ == NULL) || (dp->pkt_answ->rdata == NULL)) return -1;
|
606
|
608
|
memcpy(&addr, dp->pkt_answ->rdata, sizeof(uint32_t));
|
607
|
609
|
addr=ntohl(addr);
|
608
|
610
|
if ((res=inet_setip_raw(ip,&addr, AF_INET))==-1) {
|
|
@@ -615,15 +617,15 @@ int andns_gethostbyname(char *hname, inet_prefix *ip)
|
615
|
617
|
|
616
|
618
|
|
617
|
619
|
/* There is a DNS query, internet realm.
|
618
|
|
- * I'm going to forward it, but first I have
|
|
620
|
+ * I'm going to forward it, but first I have
|
619
|
621
|
* to control suffix presence.
|
620
|
|
- *
|
621
|
|
- * After this function, `answer` is the answer to be
|
|
622
|
+ *
|
|
623
|
+ * After this function, `answer` is the answer to be
|
622
|
624
|
* sent to the client.
|
623
|
625
|
*
|
624
|
626
|
* Returns:
|
625
|
627
|
* answer len
|
626
|
|
- */
|
|
628
|
+ */
|
627
|
629
|
int dns_forward(dns_pkt *dp,char *msg,int msglen,char* answer)
|
628
|
630
|
{
|
629
|
631
|
dns_pkt *dp_forward;
|
|
@@ -684,7 +686,7 @@ failing:
|
684
|
686
|
*
|
685
|
687
|
* I'm going to resolve it in ANDNA.
|
686
|
688
|
*
|
687
|
|
- * After this function, `answer` is the answer to be
|
|
689
|
+ * After this function, `answer` is the answer to be
|
688
|
690
|
* sent to the client.
|
689
|
691
|
*
|
690
|
692
|
* Returns:
|
|
@@ -720,7 +722,7 @@ int inet_rslv(dns_pkt *dp,char *msg,int msglen,char *answer)
|
720
|
722
|
} else if (qt==T_PTR) {
|
721
|
723
|
char tomp[DNS_MAX_HNAME_LEN];
|
722
|
724
|
lcl_cache *lc;
|
723
|
|
-
|
|
725
|
+
|
724
|
726
|
res=swapped_straddr(temp,tomp);
|
725
|
727
|
if (res==-1) {
|
726
|
728
|
rcode=RCODE_EINTRPRT;
|
|
@@ -757,14 +759,14 @@ return_rcode:
|
757
|
759
|
ANDNS_SET_QR(answer);
|
758
|
760
|
return msglen;
|
759
|
761
|
}
|
760
|
|
-
|
|
762
|
+
|
761
|
763
|
int nk_rslv(andns_pkt *ap,char *msg,int msglen,char *answer)
|
762
|
764
|
{
|
763
|
765
|
int qt,res,rcode,records;
|
764
|
766
|
inet_prefix ipres;
|
765
|
767
|
uint8_t recs;
|
766
|
768
|
uint16_t s;
|
767
|
|
-
|
|
769
|
+
|
768
|
770
|
qt=ap->qtype;
|
769
|
771
|
if (qt==AT_A) {
|
770
|
772
|
snsd_service *ss;
|
|
@@ -783,11 +785,11 @@ int nk_rslv(andns_pkt *ap,char *msg,int msglen,char *answer)
|
783
|
785
|
goto safe_return_rcode;
|
784
|
786
|
}
|
785
|
787
|
snsd_service_llist_del(&ss);
|
786
|
|
- }
|
|
788
|
+ }
|
787
|
789
|
else if (qt==AT_PTR) {
|
788
|
790
|
lcl_cache *lc;
|
789
|
791
|
int family;
|
790
|
|
-
|
|
792
|
+
|
791
|
793
|
family=ap->qstlength==4?AF_INET:AF_INET6;
|
792
|
794
|
res=inet_setip_raw(&ipres,(u_int*)ap->qstdata,family);
|
793
|
795
|
if (res==-1) {
|
|
@@ -802,7 +804,7 @@ int nk_rslv(andns_pkt *ap,char *msg,int msglen,char *answer)
|
802
|
804
|
goto safe_return_rcode;
|
803
|
805
|
}
|
804
|
806
|
res=lcl_cache_to_aansws(answer+msglen,lc,&records); /* destroys lc */
|
805
|
|
- }
|
|
807
|
+ }
|
806
|
808
|
else if (qt==AT_G) {
|
807
|
809
|
snsd_service *ss;
|
808
|
810
|
ss=andna_resolve_hash((u_int *)ap->qstdata,
|
|
@@ -914,7 +916,7 @@ char *andns_rslv(char *msg, int msglen,char *answer, int *answ_len)
|
914
|
916
|
andns_pkt *ap;
|
915
|
917
|
|
916
|
918
|
proto=GET_NK_BIT(msg);
|
917
|
|
- if (proto==NK_DNS)
|
|
919
|
+ if (proto==NK_DNS)
|
918
|
920
|
res=d_u(msg,msglen,&dp);
|
919
|
921
|
else if (proto==NK_INET || proto==NK_NTK)
|
920
|
922
|
res=a_u(msg,msglen,&ap);
|
|
@@ -923,10 +925,10 @@ char *andns_rslv(char *msg, int msglen,char *answer, int *answ_len)
|
923
|
925
|
"Which language are you speaking?");
|
924
|
926
|
return NULL;
|
925
|
927
|
}
|
926
|
|
- if (res==0)
|
|
928
|
+ if (res==0)
|
927
|
929
|
goto discard;
|
928
|
930
|
memset(answer, 0, ANDNS_MAX_SZ);
|
929
|
|
- if (res==-1)
|
|
931
|
+ if (res==-1)
|
930
|
932
|
goto intrprt;
|
931
|
933
|
if (proto==NK_DNS) {
|
932
|
934
|
r=andns_realm(dp->pkt_qst,NULL);
|
|
@@ -934,7 +936,7 @@ char *andns_rslv(char *msg, int msglen,char *answer, int *answ_len)
|
934
|
936
|
res=dns_forward(dp,msg,msglen,answer);
|
935
|
937
|
else
|
936
|
938
|
res=inet_rslv(dp,msg,msglen,answer);
|
937
|
|
- }
|
|
939
|
+ }
|
938
|
940
|
else if (proto==NK_NTK)
|
939
|
941
|
res=nk_rslv(ap,msg,msglen,answer);
|
940
|
942
|
else if (proto==NK_INET)
|