buglwIP - A Lightweight TCP/IP stack - Bugs: bug #58571, DNS host list is global even for...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #58571: DNS host list is global even for multiple netifs

Submitted by:  Ashley Duncan <ashesman>
Submitted on:  Sun 14 Jun 2020 11:03:31 PM UTC  
 
Category:  DNS Severity:  3 - Normal
Item Group:  Change Request Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open Planned Release:  None
lwIP version:  2.1.1

( Jump to the original submission)

Mon 26 Oct 2020 02:40:31 PM UTC, comment #9: 

Too many spaces between the option name and default value in opt.h (;

I'm uploading updated version.

(file #50109)

Freddie Chopin <freddie_chopin>
Mon 26 Oct 2020 02:22:34 PM UTC, comment #8: 

As I've stumbled into exactly the same problem, I've taken the liberty to take the patch posted earlier by Ashley and update it to the latest lwIP master. It should now apply easily, with no errors or rejects. I've also allowed myself to improve it slightly:
- I've renamed the option from LWIP_DNS_SERVER_PER_NETIF to LWIP_DNS_SERVERS_PER_NETIF, as this seems more correct
- I've added the new option along with a (rather long) description to opt.h
- I've modified the few remaining dns_{get,set}server() calls which were left by the original patch (if I remember correctly - one in dns_init(), one in dhcp6.c and a few in nd6.c)
- couple of minor things

Please let me know what can be done to merge this patch, as I would really prefer NOT to keep working with a forked submodule (; I'm open to suggestions how to further improve it or even change it into some other method for solving this not-so-common issue.

(file #50107)

Freddie Chopin <freddie_chopin>
Wed 24 Jun 2020 11:06:15 PM UTC, comment #7: 

I have attached the patch file below.  The patch is for STABLE-2.1.2 release.

Sorry, I have not been allowed time to spend on implementing the patch on the current master head.

The patch does not include any changes that may be required to default projects, tests or lwipopts.h sample files.  LWIP_DNS_SERVER_PER_NETIF must be set to 1 in lwipopts.h for this patch to be effective, otherwise code should compile pretty much as it did before the patch.

I am interested in hearing thoughts or anything I may have messed up.  I am not overly familiar with lwIP so  may have easily missed an important detail or use case.

Regards

Ashley

(file #49370)

Ashley Duncan <ashesman>
Wed 24 Jun 2020 05:21:43 AM UTC, comment #6: 

> What is the process for submitting this patch?


Just attach the patch file to this bug (see bottom of this page). Ideally, you'd provide a 'git format-patch -1 HEAD' like patch to have one commit from our current git master HEAD.

Simon Goldschmidt <goldsimon>
Project Administrator
Wed 24 Jun 2020 05:17:57 AM UTC, comment #5: 

I have made what I think is a simple solution to this issue by allowing (as an option) separate DNS servers per netif.  Minimal code changes were required.  When the option is turned off, there are no actual code changes outside of dns.c/h.  When turned on the changes to external modules are minor.  The changes to dns.c are also minor.

I have tested the code and would like to submit a patch for review so that this change may be considered for inclusion in lwIP or at least be a reference for other people who come up against this situation.

What is the process for submitting this patch?

Ashley Duncan <ashesman>
Wed 17 Jun 2020 10:27:06 PM UTC, comment #4: 

Windows allows manually or automatically setting two DNS servers per network interface.  No idea what linux/unix does.

Cheers

Ashley

Ashley Duncan <ashesman>
Wed 17 Jun 2020 09:52:16 PM UTC, comment #3: 

Hi,

I am with Ashley here. Having per netif DNS server storage and using DNS servers of the current default interface would be very nice.

I had a similar setup with wired Ethernet (default) and PPP (GPRS backup) and we had to write a DNS server switch outside lwIP. Basically interface UP hooks to copy negotiated DNS servers from DHCP and/or PPP outside lwIP to keep track of them, and something very ugly to enforce using the DNS servers list from the current default interface. I can't remember the outcome exactly but I was not very happy writing it :-)

Today's DNS servers handling in OSes is MUCH MORE complicated than just overwriting /etc/resolv.conf or equivalent. With systemd-networkd or NetworkManager, and last time I had to deal with that on Windows with VPN clients it was much better than a naive overwrite of the previous DNS servers list.

Sylvain

Sylvain Rochet <gradator>
Project Member
Wed 17 Jun 2020 08:43:00 PM UTC, comment #2: 

The netif is a PPP connection to a u-Blox W152 WiFi module.  When the PPP connection is established to the module, it appears to negotiate a DNS address and set it.  The DNS address is actually just the IP address of the module on the PPP connection.  However, the module has no internet connection to the outside world until you send it commands (on a UDP port over the PPP link) to tell it to make the WiFi link.  Additionally the module is also a Bluetooth device which is controlled over the same UDP port.  Sometimes we wish to only use it for Bluetooth and never enable the WiFi.

So, to lwIP, the PPP connection appears as a valid outside world connection, which is fair enough, but it is not.  In fact, while the WiFi link is not enabled, the netif is set to link down.

But a DNS resolution on another netif still uses the DNS address supplied by the PPP connection even though it is in link down state.  Because it was the last netif to call dns_setserver.  But the DNS address is the local address of the module on the PPP link, not an outside world address.

The other situation is when you have two netifs (e.g. ethernet and wifi), both have gateways that have a preferred DNS address which is supplied upon DHCP resolution, maybe even offering a local cache or service.  Should the preferred DNS address not be used for each netif rather than just whatever the last supplied was?

There appears to be no hooks or way to manage the receive of DNS addresses to manage them yourself.  Auto assigning by DHCP can be disabled, but not by PPP.   The received DNS address is not stored anywhere for later access, except overwrites the global array (in dns_setserver).

Without deep investigation, it seems to me that if dns_setserver took a netif pointer and all reads of DNS addresses were through dns_getserver (rather than direct array access) and had a netif pointer, and these functions could be hooked or overridden.  Then you could manually manage your own DNS addresses.

In fact, it seems I have no option but to make this change in my situation?

Furthermore, there appears to be no way to manually set a DNS address without risk of it being overwritten by DHCP or PPP. 

Hope that helps explain.

Cheers

Ashley

Ashley Duncan <ashesman>
Wed 17 Jun 2020 07:59:22 PM UTC, comment #1: 

The list of DNS servers is global in other OSes, too. Why does your netif add DNS servers without being connected to the internet at all?

Simon Goldschmidt <goldsimon>
Project Administrator
Sun 14 Jun 2020 11:03:31 PM UTC, original submission:  

I have stumbled across a problem today where DNS resolution was failing when using multiple netifs.  I tracked it down to the use of a global dns_servers array that is updated by the last netif that gets given a DNS address, even if that netif has no internet connection.  Other netifs can then not perform DNS resolution even though they have a valid internet connection.

Could the dns_servers array not be part of netif so that the correct dns server address can be fetched from the current default netif?  Other sending activities default to using the default netif.

Use case:

In this instance there is a DHCP capable ethernet interface and a PPP wifi interface.  Both of these interfaces set the dns_servers array while negotiating IP address.  Depending on which netif sets the dns_servers array last sets the IP address used for DNS resolution.

Typically Ethernet is set as the default netif and has a valid internet connection.  It comes up first and sets a DNS  address given by DHCP.

The PPP interface is always up, even if the wifi module has no link, which it often doesn't.  It comes up second setting dns_servers to the PPP given values, overwriting the ethernet dns address.

If I try to use DNS resolution on ethernet, it uses the PPP dns_server values which of course fails.  If I unplug ethernet, plug it back in.  dns_servers are updated by the Ethernets DHCP, then then DNS resolution can be used.

Ashley Duncan <ashesman>

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by freddie_chopin (Updated the item)
  • -email is unavailable- added by gradator (Posted a comment)
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by ashesman (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

     

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-10-26 freddie_chopin Attached File- => Added 0001-Introduce-LWIP_DNS_SERVERS_PER_NETIF-option.patch, #50109
    2020-10-26 freddie_chopin Attached File- => Added 0001-Introduce-LWIP_DNS_SERVERS_PER_NETIF-option.patch, #50107
    2020-06-24 ashesman Attached File- => Added dnsserverpernetif.patch, #49370

    Back to the top


    Powered by Savane 3.6