chiark / gitweb /
Merge branch 'master' of metalzone.distorted.org.uk:~mdw/public-git/tripe 1.0.0pre9maemo1
authorMark Wooding <mdw@distorted.org.uk>
Mon, 17 May 2010 23:25:52 +0000 (00:25 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 17 May 2010 23:25:52 +0000 (00:25 +0100)
* 'master' of metalzone.distorted.org.uk:~mdw/public-git/tripe:
  debian/changelog: Another version.
  Disassociate public key tags from peer names.
  svc/conntrack: Make the kickpeers coroutine more robust.
  svc/conntrack.8.in: Document the D-Bus connection state notifications.
  peerdb/peers.in.5.in: Fix formatting.

Conflicts:
debian/changelog

13 files changed:
debian/changelog
peerdb/peers.in.5.in
py/tripe.py.in
server/admin.c
server/keyexch.c
server/peer.c
server/tests.at
server/tripe-admin.5.in
server/tripe.h
svc/connect.8.in
svc/connect.in
svc/conntrack.8.in
svc/conntrack.in

index e2cc8d21e728ee86cb59d165226bed4cd65164d1..03aa001467f812ab039170636c4991644b0a8fc3 100644 (file)
@@ -1,3 +1,10 @@
+tripe (1.0.0pre9maemo1) experimental; urgency=low
+
+  * Make conntrack rather more robust against errors.
+  * Logically separate key tags from peer names.
+
+ -- Mark Wooding <mdw@distorted.org.uk>  Mon, 17 May 2010 20:27:33 +0100
+
 tripe (1.0.0pre8.1maemo1) experimental; urgency=low
 
   * Maemo-specific hacking: remove GUI stuff and Wireshark integration;
index fbc7c5c55e976616ab257367df503d4715348de6..ad7faeda0fb3087e742978cab4b84df15d2303bb 100644 (file)
@@ -110,8 +110,7 @@ example, given the sections
 [parent]
 detail = in parent
 blurb = expand $(detail)
-
-.PP
+.VE
 Apart from its effect on lookups, as just described, the
 .B @inherits
 key is entirely ignored.  In particular, it is never written to the
@@ -167,6 +166,10 @@ Local address for the tunnel interface to the peer.  Used by
 Interval for sending keepalive pings.  Used by
 .BR connect (8).
 .TP
+.B key
+Key tag to use to authenticate the peer.  Used by
+.BR connect (8).
+.TP
 .B mtu
 Maximum transmission unit for the tunnel interface.  Used by
 .BR tripe-ifup (8).
index f556bae53f424ecbd8d3f130040abfcff5aa6c5f..37de5a404de6aff7f87037aee85ff742db52cb39 100644 (file)
@@ -830,7 +830,8 @@ class TripeCommandDispatcher (TripeConnection):
   def add(me, peer, *addr, **kw):
     return _simple(me.command(bg = True,
                               *['ADD'] +
-                              _kwopts(kw, ['tunnel', 'keepalive', 'cork']) +
+                              _kwopts(kw, ['tunnel', 'keepalive',
+                                           'key', 'cork']) +
                               [peer] +
                               list(addr)))
   def addr(me, peer):
index a62bbe2243821a077725f71c7f3d1f88eb8e7b52..a339167c6374c0a649e37e6d654c21789247e4a1 100644 (file)
@@ -1205,6 +1205,7 @@ static void a_doadd(admin_resop *r, int rc)
       a_bgok(&add->r.bg);
   }
 
+  if (add->peer.tag) xfree(add->peer.tag);
   xfree(add->peer.name);
 }
 
@@ -1228,6 +1229,7 @@ static void acmd_add(admin *a, unsigned ac, char *av[])
 
   add = xmalloc(sizeof(*add));
   add->peer.name = 0;
+  add->peer.tag = 0;
   add->peer.t_ka = 0;
   add->peer.tops = tun_default;
   add->peer.kxf = 0;
@@ -1251,6 +1253,11 @@ static void acmd_add(admin *a, unsigned ac, char *av[])
     })
     OPTTIME("-keepalive", t, { add->peer.t_ka = t; })
     OPT("-cork", { add->peer.kxf |= KXF_CORK; })
+    OPTARG("-key", arg, {
+      if (add->peer.tag)
+       xfree(add->peer.tag);
+      add->peer.tag = xstrdup(arg);
+    })
   });
 
   /* --- Make sure someone's not got there already --- */
@@ -1275,6 +1282,7 @@ bad_syntax:
   a_fail(a, "bad-syntax", "add", "[OPTIONS] PEER ADDR ...", A_END);
 fail:
   if (add->peer.name) xfree(add->peer.name);
+  if (add->peer.tag) xfree(add->peer.tag);
   xfree(add);
   return;
 }
@@ -1785,6 +1793,7 @@ static void acmd_peerinfo(admin *a, unsigned ac, char *av[])
   if ((p = a_findpeer(a, av[0])) != 0) {
     ps = p_spec(p);
     a_info(a, "tunnel=%s", ps->tops->name, A_END);
+    a_info(a, "key=%s", ps->tag, A_END);
     a_info(a, "keepalive=%lu", ps->t_ka, A_END);
     a_ok(a);
   }
index 6490dd7358adc118dc055ec62fffc7976f68cd0c..d007a434ef98e5973d0882cbeeb59a203987e3ab 100644 (file)
@@ -1235,7 +1235,7 @@ void kx_free(keyexch *kx)
 
 void kx_newkeys(keyexch *kx)
 {
-  if (km_getpubkey(p_name(kx->p), kx->kpub, &kx->texp_kpub))
+  if (km_getpubkey(p_tag(kx->p), kx->kpub, &kx->texp_kpub))
     return;
   kx->f |= KXF_PUBKEY;
   if ((kx->f & KXF_DEAD) || kx->s != KXS_SWITCH) {
@@ -1266,7 +1266,7 @@ int kx_init(keyexch *kx, peer *p, keyset **ks, unsigned f)
   kx->ks = ks;
   kx->p = p;
   kx->kpub = G_CREATE(gg);
-  if (km_getpubkey(p_name(p), kx->kpub, &kx->texp_kpub)) {
+  if (km_getpubkey(p_tag(p), kx->kpub, &kx->texp_kpub)) {
     G_DESTROY(gg, kx->kpub);
     return (-1);
   }
index 4bb2c82c6b0f80b07da5f42ab928d7d61532270d..456efd7789da91677516d75c0c1d18578477cd58 100644 (file)
@@ -737,6 +737,8 @@ peer *p_create(peerspec *spec)
   T( trace(T_PEER, "peer: creating new peer `%s'", spec->name); )
   p->spec = *spec;
   p->spec.name = (/*unconst*/ char *)SYM_NAME(p->byname);
+  if (spec->tag)
+    p->spec.tag = xstrdup(spec->tag);
   p->ks = 0;
   p->pings = 0;
   p->ifname = 0;
@@ -773,6 +775,7 @@ tidy_3:
   if (fd >= 0) close(fd);
 tidy_2:
   am_remove(&byaddr, p->byaddr);
+  if (p->spec.tag) xfree(p->spec.tag);
 tidy_1:
   sym_remove(&byname, p->byname);
 tidy_0:
@@ -789,6 +792,16 @@ tidy_0:
 
 const char *p_name(peer *p) { return (p->spec.name); }
 
+/* --- @p_tag@ --- *
+ *
+ * Arguments:  @peer *p@ = pointer to a peer block
+ *
+ * Returns:    A pointer to the peer's public key tag.
+ */
+
+const char *p_tag(peer *p)
+  { return (p->spec.tag ? p->spec.tag : p->spec.name); }
+
 /* --- @p_spec@ --- *
  *
  * Arguments:  @peer *p@ = pointer to a peer block
@@ -853,6 +866,8 @@ void p_destroy(peer *p)
   kx_free(&p->kx);
   if (p->ifname)
     xfree(p->ifname);
+  if (p->spec.tag)
+    xfree(p->spec.tag);
   p->t->ops->destroy(p->t);
   if (p->spec.t_ka)
     sel_rmtimer(&p->tka);
index 393a6616f9523d84976046336c2b83224d15c8d3..38961e1dc40c0322d7d2c9f6f8bcdefc5924b6d6 100644 (file)
@@ -224,24 +224,25 @@ WITH_2TRIPES([alice], [bob], [-nslip], [-talice], [-tbob], [
   AT_CHECK([TRIPECTL -dalice ADD bob INET 127.0.0.1 $(cat bob/port)])
   echo >>bob/expected-server-output \
     "WARN PEER - unexpected-source INET 127.0.0.1 $(cat alice/port)"
-  AT_CHECK([TRIPECTL -dbob ADD alice INET 127.0.0.1 $(cat alice/port)])
+  AT_CHECK([TRIPECTL -dbob ADD -key alice not-alice \
+                              INET 127.0.0.1 $(cat alice/port)])
 
   ## Check transport pinging.
   AT_CHECK([TRIPECTL -dalice PING bob],, [ignore])
-  AT_CHECK([TRIPECTL -dbob PING alice],, [ignore])
+  AT_CHECK([TRIPECTL -dbob PING not-alice],, [ignore])
 
   ## Wait for the completion announcement.
   wait
 
   ## Check encrypted pinging.
   AT_CHECK([TRIPECTL -dalice EPING bob],, [ignore])
-  AT_CHECK([TRIPECTL -dbob EPING alice],, [ignore])
+  AT_CHECK([TRIPECTL -dbob EPING not-alice],, [ignore])
 
   ## Check that packets can flow from one to the other.
   AT_CHECK([echo "from alice" | USLIP -p alice/bob])
-  AT_CHECK([USLIP -g bob/alice],, [from alice[]nl])
+  AT_CHECK([USLIP -g bob/not-alice],, [from alice[]nl])
 
-  AT_CHECK([echo "from bob" | USLIP -p bob/alice])
+  AT_CHECK([echo "from bob" | USLIP -p bob/not-alice])
   AT_CHECK([USLIP -g alice/bob],, [from bob[]nl])
 ])
 
index 826d0f44704d4ed241e7e72b3c5a730ba0b2ea2d..e921cfcf276e64c220f50c2ca63205373a1105ee 100644 (file)
@@ -348,6 +348,12 @@ or
 for days, hours, minutes, or seconds respectively; if no suffix is
 given, seconds are assumed.
 .TP
+.BI "\-key " tag
+Use the public key
+.I tag
+to authenticate the peer.  The default is to use the key tagged
+.IR peer .
+.TP
 .BI "\-tunnel " tunnel
 Use the named tunnel driver, rather than the default.
 .\"-opts
@@ -523,6 +529,12 @@ The tunnel driver used for this peer.
 .B keepalive
 The keepalive interval, in seconds, or zero if no keepalives are to be
 sent.
+.TP
+.B key
+The key tag being used for the peer, as passed to the
+.B ADD
+command.  (You don't get a full key-id, since that might change while
+the daemon's running.)
 .RE
 .SP
 .BI "PING \fR[" options "\fR] " peer
index 2b6f950a8a2c679f027d3f62bbab227abaa588ac..a210e5261e9188ab30afd1e5046f5128e04f0d89 100644 (file)
@@ -333,6 +333,7 @@ typedef struct stats {
 
 typedef struct peerspec {
   char *name;                          /* Peer's name */
+  char *tag;                           /* Public key tag */
   const tunnel_ops *tops;              /* Tunnel operations */
   unsigned long t_ka;                  /* Keep alive interval */
   addr sa;                             /* Socket address to speak to */
@@ -1249,6 +1250,15 @@ extern peer *p_create(peerspec */*spec*/);
 
 extern const char *p_name(peer */*p*/);
 
+/* --- @p_tag@ --- *
+ *
+ * Arguments:  @peer *p@ = pointer to a peer block
+ *
+ * Returns:    A pointer to the peer's public key tag.
+ */
+
+extern const char *p_tag(peer */*p*/);
+
 /* --- @p_spec@ --- *
  *
  * Arguments:  @peer *p@ = pointer to a peer block
index 77357f52ff6427c8056c1b31b082262ac57e6844..ddd2636b0ce6716d4bcc5b70db5d60ef1340cccb 100644 (file)
@@ -172,6 +172,8 @@ The service will submit the command
 .RB [ \-cork ]
 .RB [ \-keepalive
 .IR time ]
+.RB [ \-key
+.IR tag ]
 .RB [ \-tunnel
 .IR driver ]
 .I address
@@ -200,6 +202,15 @@ to the
 key.
 .hP \*o
 The option
+.B \-key
+.I tag
+is provided if the database record assigns a value
+.I tag
+to the
+.B key
+key.
+.hP \*o
+The option
 .B \-tunnel
 .I driver
 is provided if the database record assigns a value
index dae116208dc105fb4875ab4a59ef9893afa587ed..37241bbce9fcd2b37c231b6b03b190b8df562800 100644 (file)
@@ -90,6 +90,7 @@ def addpeer(peer, addr):
     S.add(peer.name,
           tunnel = peer.get('tunnel', None),
           keepalive = peer.get('keepalive', None),
+          key = peer.get('key', None),
           cork = peer.get('cork', 'nil') in ['t', 'true', 'y', 'yes', 'on'],
           *addr)
   except T.TripeError, exc:
index 9c0fe1be5226d7cbb7e3f761d786b9f89b375d85..3e4fc72521c35b05a33d557bfa289d0d294a68e2 100644 (file)
@@ -181,6 +181,24 @@ All notifications issued by
 begin with the tokens
 .BR "USER conntrack" .
 .SP
+.BI "USER conntrack dbus-connection " status
+The service's connection to D-Bus has changed state.  The
+.I status
+is one of the following.
+.RS
+.TP
+.B startup
+Initially trying to connect.
+.TP
+.B connected
+Successfully established a connection to the bus.
+.TP
+.B lost
+A connection has been lost.
+.TP
+.BI state= label
+The service's internal state machine is confused.
+.SP
 .BI "USER conntrack " up \fR| down " " reason\fR...
 The network connection has apparently gone up or down, and
 .B conntrack
@@ -251,6 +269,12 @@ The configuration file is invalid.  The
 token names a Python exception; the
 .I error-text
 describes the problem encountered, though it may not be very useful.
+.SP
+.BI "USER conntrack connect-failed " peer " " tokens\fR...
+An attempt to connect the named
+.I peer
+failed; the error message is given by the
+.IR tokens .
 .
 .\"--------------------------------------------------------------------------
 .SH "SUMMARY"
index b80f92edc0a4e88cc2ca8c99fad12bac14f6614d..827598fe211e20b1e8123c5f0fbffb63efb53393 100644 (file)
@@ -265,12 +265,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)))
+        def _(want = want):
+          try:
+            SM.svcsubmit('connect', 'active', want)
+          except T.TripeError, exc:
+            SM.warn('conntrack', 'connect-failed', want, *exc.args)
+        changes.append(_)
       lastip[g] = ip
 
     ## Commit the changes.