OTP25: issue in inet_res:lookup (in gen_smtp)

Hi,

In gen_smtp I encounter a problem when testing on OTP 25:

6> inet_res:lookup("10.0.0.1", in, mx).  
** exception error: no function clause matching inet_res:lookup_filter("1.0.0.10.in-addr.arpa",in,mx) (inet_res.erl, line 188)
7> inet_res:lookup({127,0,0,1}, in, mx).
** exception error: no function clause matching inet_res:lookup_filter("1.0.0.127.in-addr.arpa",in,mx) (inet_res.erl, line 188)
8> inet_res:lookup("erlang.org", in, mx).
[{10,"hel.cslab.ericsson.net"}]

This works well in OTP 24:

3>  inet_res:lookup("127.0.0.1", in, mx).
[]
4> inet_res:lookup({127,0,0,1}, in, mx).
[]

To me this seems to be a problem in inet_res:resolve on OTP 25, which returns an illegal return value on an input that looks like an IP address.

Compare resolve with OTP24:

6>  inet_res:resolve("127.0.0.1", in, a).    
{ok,#dns_rec{header = #dns_header{id = 3,qr = true,
                                  opcode = query,aa = false,tc = false,rd = true,ra = true,
                                  pr = false,rcode = 0},
             qdlist = [#dns_query{domain = "1.0.0.127.IN-ADDR.ARPA",
                                  type = a,class = in}],
             anlist = [],nslist = [],arlist = []}}

And on OTP25:

2>  inet_res:resolve("127.0.0.1", in, a).    
"1.0.0.127.in-addr.arpa"

Cheers, Marc

2 Likes

Looking at the inet_res test suite. If this is broken, than other dns related things must also be broken.

2 Likes

Filed a bug with OTP on Github: OTP 25: Illegal return value from inet_res:resolve/3 · Issue #6015 · erlang/otp · GitHub

3 Likes

Why are you doing an MX lookup for an IP?

MX records should, afaik, only ever be associated with domains/subdomains and only point to A and CNAME records (the latter seems to be a “recent” change).

What appears to be happening from what you’ve posted is a PTR format of the IP is being returned for the special lochalhost127.0.0.1 case.

Edit:
Should note that PTR records should also only point to A records.

2 Likes

The gen_smtp library does a generic lookup for the domain part of an email address.
The domain could be an IP address.

Besides that, the inet_res:resolve/3 lookup should never return a string, as its spec is:

-spec resolve(Name, Class, Type) -> {ok, dns_msg()} | Error when
      Name :: dns_name() | inet:ip_address(),
      Class :: dns_class(),
      Type :: dns_rr_type(),
      Error :: {error, Reason} | {error,{Reason,dns_msg()}},
      Reason :: inet:posix() | res_error().
4 Likes