MoinQ:

1. dnscache /query.c patch

1.1. additional section handling

in domain ではないAレコードは無視する。-- ToshinoriMaeno 2021-05-21 11:22:12

*** query.c.2021-521    2021-05-21 19:27:07.538163060 +0900
--- query.c     2021-05-21 20:00:19.683215972 +0900
***************
*** 649,654 ****
--- 649,655 ----
        save_finish(DNS_T_MX,t1,ttl);
      }
      else if (byte_equal(type,2,DNS_T_A)) {
+       if (!dns_domain_suffix(d, t1)) { i = j; continue; }
        save_start();
        while (i < j) {
          pos = dns_packet_skipname(buf,len,records[i]); if (!pos) goto DIE;

1.2. answer section あり

answer section があったときには、authority, additional は無視する。

%diff -c query.c* ~/djb/djbdns-1.05

*** query.c     2012-04-24 09:49:32.000000000 +0900
--- query.c.orig        2012-04-24 09:49:35.000000000 +0900
***************
*** 525,532 ****
  
  
    if (records) { alloc_free(records); records = 0; }
!   k = numanswers;
!   if (k==0)  k = numauthority + numglue;
    records = (unsigned int *) alloc(k * sizeof(unsigned int));
    if (!records) goto DIE;
  
--- 525,532 ----
  
  
    if (records) { alloc_free(records); records = 0; }
! 
!   k = numanswers + numauthority + numglue;
    records = (unsigned int *) alloc(k * sizeof(unsigned int));
    if (!records) goto DIE;

1.3. TTLを制限する

2021年現在ではもっと短くてもよさそう。3時間くらいではどうか。-- ToshinoriMaeno 2021-05-20 12:16:08

%diff -c cache.c* ~/djb/djbdns-1.05

*** cache.c     2012-06-01 08:50:12.000000000 +0900
--- cache.c.orig        2012-04-24 09:49:35.000000000 +0900
***************
*** 137,144 ****
    if (datalen > MAXDATALEN) return;
  
    if (!ttl) return;
!   if (ttl > 86400) ttl = 86400;
!   if (ttl < 600) ttl = 600;
  
    entrylen = keylen + datalen + 20;
  
--- 137,143 ----
    if (datalen > MAXDATALEN) return;
  
    if (!ttl) return;
!   if (ttl > 604800) ttl = 604800;
  
    entrylen = keylen + datalen + 20;

1.4. port 番号

port 番号を取り出すための修正

%diff -c server.c* ~/djb/djbdns-1.05

*** server.c    2012-04-24 09:49:32.000000000 +0900
--- server.c.orig       2012-04-24 09:49:35.000000000 +0900
***************
*** 14,20 ****
  
  extern char *fatal;
  extern char *starting;
! extern int respond(char *,char *,char *, uint16);
  extern void initialize(void);
  
  static char ip[4];
--- 14,20 ----
  
  extern char *fatal;
  extern char *starting;
! extern int respond(char *,char *,char *);
  extern void initialize(void);
  
  static char ip[4];
***************
*** 55,61 ****
    if (byte_equal(qtype,2,DNS_T_AXFR)) goto NOTIMP;
  
    case_lowerb(q,dns_domain_length(q));
!   if (!respond(q,qtype,ip, port)) {
      qlog(ip,port,header,q,qtype," - ");
      return 0;
    }
--- 55,61 ----
    if (byte_equal(qtype,2,DNS_T_AXFR)) goto NOTIMP;
  
    case_lowerb(q,dns_domain_length(q));
!   if (!respond(q,qtype,ip)) {
      qlog(ip,port,header,q,qtype," - ");
      return 0;
    }

1.5. fixed query port alert

問い合わせポート固定のquery には返答を変えて返事をする。(cdbに渡すパラメタフラグの変更)

%diff -c tdlookup.c tdlookup.c.orig ~/djb/djbdns-1.05

*** tdlookup.c  2012-10-27 22:32:17.000000000 +0900
--- tdlookup.c.orig     2012-04-24 09:49:35.000000000 +0900
***************
*** 225,231 ****
      }
    }
    else
!     if ((anpos == response_len) && want(control,DNS_T_NS)) {
        cdb_findstart(&c);
        while (r = find(control,0)) {
          if (r == -1) return 0;
--- 225,231 ----
      }
    }
    else
!     if (want(control,DNS_T_NS)) {
        cdb_findstart(&c);
        while (r = find(control,0)) {
          if (r == -1) return 0;
***************
*** 278,284 ****
    return 1;
  }
  
! int respond(char *q,char qtype[2],char ip[4], uint16 srcport)
  {
    int fd;
    int r;
--- 278,284 ----
    return 1;
  }
  
! int respond(char *q,char qtype[2],char ip[4])
  {
    int fd;
    int r;
***************
*** 302,312 ****
    if (r && (cdb_datalen(&c) == 2))
      if (cdb_read(&c,clientloc,2,cdb_datapos(&c)) == -1) return 0;
  
!   if (srcport < 1040 || (srcport > 32767 && srcport < 32784)) {
!       clientloc[0]='v'; clientloc[1]='v';
!       }
!   if (srcport != 53) 
!       r = doit(q,qtype);
  
    cdb_free(&c);
    close(fd);
--- 302,308 ----
    if (r && (cdb_datalen(&c) == 2))
      if (cdb_read(&c,clientloc,2,cdb_datapos(&c)) == -1) return 0;
  
!   r = doit(q,qtype);
  
    cdb_free(&c);
    close(fd);

MoinQ: djbdns/dnscache/query.c/patch (last edited 2021-06-03 02:53:27 by ToshinoriMaeno)