nRF9160 - mfw 1.3.7 - NCS 3.2.4 - DNS lookup fails with some SIM cards using cloudflare

nRF9160 - mfw 1.3.7 - NCS 3.2.4

In my experience, DNS lookup fails with some SIM cards using cloudflare as primary DNS.

I wrote to the SIM card provider about that issue and get the following answer:
##########################################################
The reason for the issue you are seeing is a different behavior of DNS resolution services of Cloudflare (1.1.1.1) and Google (8.8.8.8).  Cloudflare is the primary DNS, and Google is the secondary DNS server provided to the modem by our SIM card.  The response from Cloudflare is longer and not supported by NRF9160, resulting in the Truncated response flag being set to 1 by Cloudflare.  Google response is shorter and is not truncated.
The "other" SIM uses Google as a primary DNS resolution server that is compatible with the modem.
Our SIM sets Cloudflare as a primary DNS resolution server.  The expected behavior from the modem is that it would retry DNS resolution using TCP after initial UDP attempt fails.  Unfortunately, your modem does not support the TCP retry option.
The way to eliminate this issue is to have your application try Cloudflare first and if it fails, then try Google second.  Alternatively, you can manually re-configure DNS servers on the Nordic device to use Google (8.8.8.8) first and either 8.8.4.4 or 1.1.1.1 secondary.
##########################################################

The pain here is:
Though the getaddrinfo is offloaded to the modem, I'm not able to exchange the dns server.
Using LTE_LC_DNS_FALLBACK_ADDRESS ends up in calling nrf_setdnsaddr and the docu there says

"The fallback DNS address is used only when the network-provided DNS addresses are
 missing or unreachable. The fallback DNS does not override the network-provided DNS."
 
Though the SIm card sets the "1.1.1.1", a LTE_LC_DNS_FALLBACK_ADDRESS "8.8.8.8" will
not get effective.
 
Are there any other options?

To be frank: in rare cases using that SIM, cloudflare answers the modem's request with a message of 86 bytes. I'm not sure, if their explanation with "longer" really fits.   

  • Follow up question:

    Is it possible, to not use the "off-loading" just for the  getaddrinfo?

  • Hi,

    Thanks for detailed description. Your understanding of the fallback DNS is correct and since your SIM actively provides 1.1.1.1 as the primary DNS, setting CONFIG_LTE_LC_DNS_FALLBACK_ADDRESS="8.8.8.8" will have no effect on normal lookups, as it applies when the network provided DNS is missing. There seems no supported API to replace operator provided DNS servers while using the modem's offloaded getaddrinfo(). However you may try following options:

    • Try sending a raw DNS query over UDP directly to 8.8.8.8 using a normal offloaded UDP socket, bypassing the modem's DNS client entirely. This does not require disabling socket offloading and avoids the truncation issue. You can implement a retry, try 1.1.1.1 first and fall back to 8.8.8.8 if it fails.
    • Moreover it could be possible to use Zephyr's native DNS resolver with a specific server in principle but may it will not be a straight forward or a recommended option.

    And it seems logical that a 86 byte response would not normally trigger truncation. To check what happens on failure, can you share modem trace. Thanks

    Best Regards,
    Syed Maysum

Related