From fa59a04b4daaa8d75e1fb0e875ed6ed5fb6d1304 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Fri, 29 Sep 2017 01:18:25 +0100 Subject: [PATCH] svc/conntrack.in (kickpeers): Refactor and reformat the search loop. The `ip' variable wasn't doing anything except remembering whether we'd found a match, so replace it with a flag. This frees up the `ip' name, so give that to the bizarrely named `ipq' variable which holds the discovered local address. --- svc/conntrack.in | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/svc/conntrack.in b/svc/conntrack.in index 99491b1c..261cf642 100644 --- a/svc/conntrack.in +++ b/svc/conntrack.in @@ -360,27 +360,23 @@ def kickpeers(): if T._debug: print '# check group %s' % g ## Find out which peer in the group ought to be active. - ip = None statemap = {} want = None + matchp = False for t, p, n in pp: - if p is None or not upness: - ipq = addr - else: - ipq = localaddr(p) + if p is None or not upness: ip = addr + else: ip = localaddr(p) if T._debug: info = 'peer=%s; target=%s; net=%s; local=%s' % ( - t, p or '(default)', n, straddr(ipq)) - if upness and ip is None and \ - ipq is not None and ipq.withinp(n): + t, p or '(default)', n, straddr(ip)) + if upness and not matchp and \ + ip is not None and ip.withinp(n): if T._debug: print '# %s: SELECTED' % info statemap[t] = 'up' select.append('%s=%s' % (g, t)) - if t == 'down' or t.startswith('down/'): - want = None - else: - want = t - ip = ipq + if t == 'down' or t.startswith('down/'): want = None + else: want = t + matchp = True else: statemap[t] = 'down' if T._debug: print '# %s: skipped' % info -- 2.11.0