From b10a8c3d8ffee143a0da007377fe641c24761782 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sat, 15 May 2010 19:41:07 +0100 Subject: [PATCH] svc/conntrack.in: Force reconnection on local IP address changes. Organization: Straylight/Edgeware From: Mark Wooding ICd or NetworkManager might roam to a new network, and tell us about it; but if we decided that we wanted to stick with the same peer specification then our peer will continue with the wrong IP address until watch gets a ping timeout. Of course, this doesn't trap other reasons we might change IP addresses without anyone noticing, such as roaming to a different 3G NAT thingummy. --- svc/conntrack.in | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/svc/conntrack.in b/svc/conntrack.in index 47f66f4d..b80f92ed 100644 --- a/svc/conntrack.in +++ b/svc/conntrack.in @@ -214,6 +214,7 @@ def localaddr(peer): _kick = T.Queue() def kickpeers(): + lastip = {} while True: upness, reason = _kick.get() @@ -233,35 +234,44 @@ def kickpeers(): addr = localaddr(CF.testaddr) if addr is None: upness = False + else: + addr = None ## Now decide what to do. changes = [] for g, pp in CF.groups: ## Find out which peer in the group ought to be active. - want = None # unequal to any string - if upness: - for t, p, a, m in pp: - if p is None: - aq = addr - else: - aq = localaddr(p) - if aq is not None and (aq & m) == a: - want = t - break + ip = None + map = {} + want = None + for t, p, a, m in pp: + if p is None or not upness: + ipq = addr + else: + ipq = localaddr(p) + if upness and ip is None and \ + ipq is not None and (ipq & m) == a: + map[t] = 'up' + want = t + ip = ipq + else: + map[t] = 'down' ## Shut down the wrong ones. found = False for p in peers: - if p == want: + what = map.get(p, 'leave') + if what == 'up': found = True - elif p.startswith(g) and p != want: + elif what == 'down': changes.append(lambda p=p: SM.kill(p)) ## Start the right one if necessary. - if want is not None and not found: + if want is not None and (not found or ip != lastip.get(g, None)): changes.append(lambda: T._simple(SM.svcsubmit('connect', 'active', want))) + lastip[g] = ip ## Commit the changes. if changes: -- [mdw]