Gnus development mailing list
 help / color / mirror / Atom feed
* dns.el: forget DNS servers in new network
@ 2013-09-10 21:02 Magnus Henoch
  2013-11-03 11:22 ` Ted Zlatanov
  2014-01-31 23:53 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 6+ messages in thread
From: Magnus Henoch @ 2013-09-10 21:02 UTC (permalink / raw)
  To: ding

[-- Attachment #1: Type: text/plain, Size: 696 bytes --]

Hi all,

I'm using Gnus' dns.el to look up SRV records for Jabber servers in
jabber.el.  It works fine except when I move my laptop from one network
to another, because dns.el caches the list of DNS servers (obtained from
/etc/resolv.conf) in the variable dns-servers, but sometimes those DNS
servers aren't appropriate/reachable for the new network.

Thus the patch below.  It checks whether the names and IP addresses of
all network interfaces have changed, and if so, rereads /etc/resolv.conf
instead of using the value of dns-servers.  What do you think about it?

(I'm calling fboundp for network-interface-list as I'm not sure if the
relevant XEmacs versions support it.)

Regards,
Magnus


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dns-servers-up-to-date-p.patch --]
[-- Type: text/x-patch, Size: 1992 bytes --]

diff --git a/lisp/dns.el b/lisp/dns.el
index 1c456eb..ccf0617 100644
--- a/lisp/dns.el
+++ b/lisp/dns.el
@@ -31,6 +31,12 @@
   "List of DNS servers to query.
 If nil, /etc/resolv.conf and nslookup will be consulted.")
 
+(defvar dns-servers-valid-for-interfaces nil
+  "The return value of `network-interface-list' when `dns-servers' was set.
+If the set of network interfaces and/or their IP addresses
+change, then presumably the list of DNS servers needs to be
+updated.  Set this variable to t to disable the check.")
+
 ;;; Internal code:
 
 (defvar dns-query-types
@@ -297,6 +303,15 @@ If TCP-P, the first two bytes of the package with be the length field."
            (t string)))
       (goto-char point))))
 
+(defun dns-servers-up-to-date-p ()
+  "Return false if we need to recheck the list of DNS servers."
+  (and dns-servers
+       (or (eq dns-servers-valid-for-interfaces t)
+	   ;; `network-interface-list' was introduced in Emacs 22.1.
+	   (not (fboundp 'network-interface-list))
+	   (equal dns-servers-valid-for-interfaces
+		  (network-interface-list)))))
+
 (defun dns-set-servers ()
   "Set `dns-servers' to a list of DNS servers or nil if none are found.
 Parses \"/etc/resolv.conf\" or calls \"nslookup\"."
@@ -314,7 +329,9 @@ Parses \"/etc/resolv.conf\" or calls \"nslookup\"."
 	  (goto-char (point-min))
 	  (re-search-forward
 	   "^Address:[ \t]*\\([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\)" nil t)
-	  (setq dns-servers (list (match-string 1)))))))
+	  (setq dns-servers (list (match-string 1))))))
+  (when (fboundp 'network-interface-list)
+    (setq dns-servers-valid-for-interfaces (network-interface-list))))
 
 (defun dns-read-txt (string)
   (if (> (length string) 1)
@@ -378,7 +395,7 @@ Parses \"/etc/resolv.conf\" or calls \"nslookup\"."
 If FULLP, return the entire record returned.
 If REVERSEP, look up an IP address."
   (setq type (or type 'A))
-  (unless dns-servers
+  (unless (dns-servers-up-to-date-p)
     (dns-set-servers))
 
   (when reversep

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: dns.el: forget DNS servers in new network
  2013-09-10 21:02 dns.el: forget DNS servers in new network Magnus Henoch
@ 2013-11-03 11:22 ` Ted Zlatanov
  2014-01-30 22:19   ` Lars Ingebrigtsen
  2014-01-31 23:53 ` Lars Ingebrigtsen
  1 sibling, 1 reply; 6+ messages in thread
From: Ted Zlatanov @ 2013-11-03 11:22 UTC (permalink / raw)
  To: ding

On Tue, 10 Sep 2013 22:02:39 +0100 Magnus Henoch <magnus.henoch@gmail.com> wrote: 

MH> Thus the patch below.  It checks whether the names and IP addresses of
MH> all network interfaces have changed, and if so, rereads /etc/resolv.conf
MH> instead of using the value of dns-servers.  What do you think about it?

I like it.  I wonder if it can be used more generally to find out if the
network has changed, a pretty common mobile case that can produce
connection timeouts.

Ted




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: dns.el: forget DNS servers in new network
  2013-11-03 11:22 ` Ted Zlatanov
@ 2014-01-30 22:19   ` Lars Ingebrigtsen
  2014-02-02 21:56     ` Leonidas Tsampros
  0 siblings, 1 reply; 6+ messages in thread
From: Lars Ingebrigtsen @ 2014-01-30 22:19 UTC (permalink / raw)
  To: ding; +Cc: Magnus Henoch

Ted Zlatanov <tzz@lifelogs.com> writes:

> MH> Thus the patch below.  It checks whether the names and IP addresses of
> MH> all network interfaces have changed, and if so, rereads /etc/resolv.conf
> MH> instead of using the value of dns-servers.  What do you think about it?
>
> I like it.  I wonder if it can be used more generally to find out if the
> network has changed, a pretty common mobile case that can produce
> connection timeouts.

Yeah, it's a good idea.  Gnus should kill off all network connections
when the IP address changes.

It's not a 100% solution (you may be tethered behind a device that
changes address, and they you won't discover the situation because your
own IP address doesn't change), but it's better than nothing.

However, I wonder whether this could be done more generally?  That is,
allow functions to "register" actions to be done when the IP address
changes, so that we don't have to duplicate this code in several
packages... 

-- 
(domestic pets only, the antidote for overdose, milk.)
  bloggy blog http://lars.ingebrigtsen.no/



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: dns.el: forget DNS servers in new network
  2013-09-10 21:02 dns.el: forget DNS servers in new network Magnus Henoch
  2013-11-03 11:22 ` Ted Zlatanov
@ 2014-01-31 23:53 ` Lars Ingebrigtsen
  1 sibling, 0 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2014-01-31 23:53 UTC (permalink / raw)
  To: Magnus Henoch; +Cc: ding

Magnus Henoch <magnus.henoch@gmail.com> writes:

> Thus the patch below.  It checks whether the names and IP addresses of
> all network interfaces have changed, and if so, rereads /etc/resolv.conf
> instead of using the value of dns-servers.  What do you think about it?

Looks good.  I've now applied it to Ma Gnus 0.10.

We can factor out the relevant functions to a more general place (if
needed) to reuse this in Gnus proper (to reconnect server connections).
Or perhaps just keep it in dns.el...

-- 
(domestic pets only, the antidote for overdose, milk.)
  bloggy blog http://lars.ingebrigtsen.no/



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: dns.el: forget DNS servers in new network
  2014-01-30 22:19   ` Lars Ingebrigtsen
@ 2014-02-02 21:56     ` Leonidas Tsampros
  2014-02-02 22:17       ` Julien Danjou
  0 siblings, 1 reply; 6+ messages in thread
From: Leonidas Tsampros @ 2014-02-02 21:56 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: ding, Magnus Henoch

Lars Ingebrigtsen <larsi@gnus.org> writes:
> Ted Zlatanov <tzz@lifelogs.com> writes:
>
>> MHf> Thus the patch below.  It checks whether the names and IP addresses of
>> MH> all network interfaces have changed, and if so, rereads /etc/resolv.conf
>> MH> instead of using the value of dns-servers.  What do you think about it?
>>
>> I like it.  I wonder if it can be used more generally to find out if the
>> network has changed, a pretty common mobile case that can produce
>> connection timeouts.
>
> Yeah, it's a good idea.  Gnus should kill off all network connections
> when the IP address changes.
>
> It's not a 100% solution (you may be tethered behind a device that
> changes address, and they you won't discover the situation because your
> own IP address doesn't change), but it's better than nothing.
>
> However, I wonder whether this could be done more generally?  That is,
> allow functions to "register" actions to be done when the IP address
> changes, so that we don't have to duplicate this code in several
> packages...

I really like this too!

Having a device change a network, for example from work to home or more
imporantly from work to a public hotspot (e.g. airport, starbucks,
cofeehouses, libraries etc), can lead to "information leaking".

For example, I do not want my Gnus to try connect to my job's mail server
when at the home network.

I was thinking that a regural DNS /etc/resolv.conf polling of the
"search" parameter would be nice. So if we see "search corporation.com"
you know I'm at WORK (so kill connection X and don't try and reconnect
to server Y) but if it is set to "search home.lan" hey i'm at home now
kill connections BLABLA and don't try to connect on server KOKO.

I know that I'm talking about a different problem here, but IP changes
usually comes from changing networks and I want my mail reader to be
"location aware" since ip readdressing is not an everyday task.

I hope I'm making sense :).



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: dns.el: forget DNS servers in new network
  2014-02-02 21:56     ` Leonidas Tsampros
@ 2014-02-02 22:17       ` Julien Danjou
  0 siblings, 0 replies; 6+ messages in thread
From: Julien Danjou @ 2014-02-02 22:17 UTC (permalink / raw)
  To: Leonidas Tsampros; +Cc: Lars Ingebrigtsen, ding, Magnus Henoch

[-- Attachment #1: Type: text/plain, Size: 1224 bytes --]

On Sun, Feb 02 2014, Leonidas Tsampros wrote:

> Having a device change a network, for example from work to home or more
> imporantly from work to a public hotspot (e.g. airport, starbucks,
> cofeehouses, libraries etc), can lead to "information leaking".
>
> For example, I do not want my Gnus to try connect to my job's mail server
> when at the home network.
>
> I was thinking that a regural DNS /etc/resolv.conf polling of the
> "search" parameter would be nice. So if we see "search corporation.com"
> you know I'm at WORK (so kill connection X and don't try and reconnect
> to server Y) but if it is set to "search home.lan" hey i'm at home now
> kill connections BLABLA and don't try to connect on server KOKO.
>
> I know that I'm talking about a different problem here, but IP changes
> usually comes from changing networks and I want my mail reader to be
> "location aware" since ip readdressing is not an everyday task.
>
> I hope I'm making sense :).

Yes, but as you point out this is totaly unrelated, and you can already
script that easily in elisp. I did that few years ago already.

-- 
Julien Danjou
;; Free Software hacker ; independent consultant
;; http://julien.danjou.info

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-02-02 22:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-10 21:02 dns.el: forget DNS servers in new network Magnus Henoch
2013-11-03 11:22 ` Ted Zlatanov
2014-01-30 22:19   ` Lars Ingebrigtsen
2014-02-02 21:56     ` Leonidas Tsampros
2014-02-02 22:17       ` Julien Danjou
2014-01-31 23:53 ` Lars Ingebrigtsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).