svc/tripe-ifup.in: Bring up the interface before adding routes.
[tripe] / svc / conntrack.in
index b80f92e..78141e6 100644 (file)
@@ -214,7 +214,6 @@ def localaddr(peer):
 
 _kick = T.Queue()
 def kickpeers():
-  lastip = {}
   while True:
     upness, reason = _kick.get()
 
@@ -253,7 +252,10 @@ def kickpeers():
         if upness and ip is None and \
               ipq is not None and (ipq & m) == a:
           map[t] = 'up'
-          want = t
+          if t == 'down' or t.startswith('down/'):
+            want = None
+          else:
+            want = t
           ip = ipq
         else:
           map[t] = 'down'
@@ -265,13 +267,25 @@ def kickpeers():
         if what == 'up':
           found = True
         elif what == 'down':
-          changes.append(lambda p=p: SM.kill(p))
+          def _(p = p):
+            try:
+              SM.kill(p)
+            except T.TripeError, exc:
+              if exc.args[0] == 'unknown-peer':
+                ## Inherently racy; don't worry about this.
+                pass
+              else:
+                raise
+          changes.append(_)
 
       ## Start the right one if necessary.
-      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
+      if want is not None and not found:
+        def _(want = want):
+          try:
+            SM.svcsubmit('connect', 'active', want)
+          except T.TripeError, exc:
+            SM.warn('conntrack', 'connect-failed', want, *exc.args)
+        changes.append(_)
 
     ## Commit the changes.
     if changes: