dnsimple / erldns

DNS server, in Erlang.
MIT License
398 stars 98 forks source link

Failed to load zones or crashes on queries #122

Open SivaKesava1 opened 3 years ago

SivaKesava1 commented 3 years ago

Hi,

I built erldns using make and then added the following file as erldns.config.

[
  {erldns,[
      {servers, [
        [{name, inet_localhost_1}, {address, "127.0.0.1"}, {port, 53}, {family, inet}]
      ]},

      {use_root_hints, false},
      {catch_exceptions, false},
      {zones, "priv/campus.json"}
    ]},
  {lager, [
      {error_logger_redirect, false}
    ]}
].

I have placed the following campus.json file in priv directory.

[
  {
    "name": "campus.edu",
    "records": [
      {
        "name": "campus.edu",
        "type": "SOA",
        "ttl": 3600,
        "data": {
          "mname": "ns1.campus.edu",
          "rname": "root.campus.edu",
          "serial": 3,
          "refresh": 86400,
          "retry": 7200,
          "expire": 604800,
          "minimum": 300
        }
      },
      {
        "name": "campus.edu",
        "type": "NS",
        "ttl": "500",
        "data": {
          "dname": "ns1.outside.edu"
        }
      },
      {
        "name": "*.e.campus.edu",
        "type": "A",
        "ttl": "500",
        "data": {
          "ip": "1.1.1.1"
        }
      },
      {
        "name": "t.e.campus.edu",
        "type": "A",
        "ttl": "500",
        "data": {
          "ip": "2.2.2.2"
        }
      }
    ]
  }
]

Then I ran ./rebar3 release . Though there were some out of date warnings, it successfully assembled it. Then I ran ./_build/default/rel/erldns/bin/erldns foreground which gave the error Failed to load zones (module: erldns_zone_loader, event: read_file_error, reason: enoent). Whatever I did and wherever I placed the file, it gave the same error. I finally tried naming the file as example.zone.json, and it successfully loaded it!! I am not sure what the problem here is, and any help would be useful.

The logs while loading the file were:

09:33:01.061 [info] Loaded zones (count: 1)
09:33:01.061 [info] Notifying servers to start
09:33:01.061 [info] Starting the UDP and TCP supervisor
09:33:01.061 [info] Starting UDP server (family: inet, address: {127,0,0,1}, port: 53)
09:33:01.061 [info] UDP server (family: inet, address: {127,0,0,1}, socket: #Port<0.10>)
09:33:01.062 [info] Starting TCP server for inet on address {127,0,0,1} port 53

Then I queried it using dig @127.0.0.1 +norecurse t.e.campus.edu, which resulted in a huge crash report message. Some parts of that message are:

=ERROR REPORT==== 5-Nov-2020::09:35:40.091530 ===
** Generic server <0.771.0> terminating
** Last message in was {process,
                           {dns_message,46922,false,0,false,false,true,false,
                               ....
** When Server state == {state}
** Reason for termination ==
** {badarg,
       [{dns,encode_message_rec,3,
           ....

=CRASH REPORT==== 5-Nov-2020::09:35:40.092258 ===
  crasher:
    initial call: erldns_worker_process:init/1
    pid: <0.771.0>
    registered_name: []
    exception error: bad argument
      in function  dns:encode_message_rec/3 (/erldns/_build/default/lib/dns_erlang/src/dns.erl, line 590)
      in call from dns:encode_message_rec_list/5 (/erldns/_build/default/lib/dns_erlang/src/dns.erl, line 557)
      in call from dns:encode_message_d_req/5 (/erldns/_build/default/lib/dns_erlang/src/dns.erl, line 423)
      in call from dns:encode_message_def

09:35:50.093 [error] Error handling UDP query (module: erldns_worker, event: handle_udp_query_error, error: {error,{exit,{{badarg,.....
{dns_message,46922,false,0,false,false,true,false,true,false,0,1,0,0,1,[{dns_query,<<"t.e.campus.edu">>,1,1}],[],[],..

System: OS: Ubuntu bionic (actually a docker image) Erlang installed using the steps mentioned here as the apt install erlang gave errors for the make.

I am not used to Erlang, so I did not try much to find the root cause. Thanks for any help in advance