dnsproxy: Remove DNS servers of disconnected/idle service

This addresses the issue of having changing interface indexes with,
e.g., VPNs that causes the DNS servers to accumulate in the list when
the index of a VPN changes but the service and DNS server addresses
remain the same. Reason for this is how find_server() behaves when
adding new DNS servers.

VPNs can change interface index more rapidly as they can be connected
when the previous VPN connection is still disconnecting or cleaning up
and the previous interface is up so new interface for the new VPN
connection is brought up. The service, however, is still the same and so
are the DNS servers.

When such thing happens and the DNS servers do not change,
"src/dnsproxy.c:ns_resolv() Cannot send message to server 8.8.8.8 sock
47 protocol 17 (Invalid argument/22)" is given as error. If there are
no new DNS servers set by the new VPN connection DNS does not work until
there is some other change triggering. Reason for this is that connected
UDP sockets are used and when the error happens "netstat -un" displays
bunch of connections with IP different to what is currently used.

By adding this service state listener enabling removal of the DNS
servers of the disconnecting/idle service the issue described is
eliminated. Removal of the DNS servers is done using the index of the
disconnecting service, allowing to remove the DNS servers of a service
that has begun its disconnection process. As a result the DNS server
list keeps clean and when the VPN is re-connected with new interface the
DNS servers are added again but they have correct interfaces set and
further DNS requests can be sent.
1 file changed