chiark / gitweb /
Allow different peer associations to use different private keys.
[tripe] / server / peer.c
index 308ab1d1cb32c8145d4bd7d44cb4e89046a77b38..75f7acba6fb8bfd2f760d93d4cbc81faee05e800 100644 (file)
@@ -820,6 +820,7 @@ unsigned p_port(void)
 static void p_keepalive(struct timeval *now, void *pv)
 {
   peer *p = pv;
+
   p_txstart(p, MSG_MISC | MISC_NOP); p_dotxend(p);
   T( trace(T_PEER, "peer: sent keepalive to %s", p->spec.name); )
   p_setkatimer(p);
@@ -871,8 +872,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);
+  if (spec->tag) p->spec.tag = xstrdup(spec->tag);
+  if (spec->privtag) p->spec.privtag = xstrdup(spec->privtag);
   p->ks = 0;
   p->pings = 0;
   p->ifname = 0;
@@ -902,8 +903,7 @@ peer *p_create(peerspec *spec)
   return (p);
 
 tidy_4:
-  if (spec->t_ka)
-    sel_rmtimer(&p->tka);
+  if (spec->t_ka) sel_rmtimer(&p->tka);
   xfree(p->ifname);
   p->t->ops->destroy(p->t);
 tidy_3:
@@ -911,6 +911,7 @@ tidy_3:
 tidy_2:
   am_remove(&byaddr, p->byaddr);
   if (p->spec.tag) xfree(p->spec.tag);
+  if (p->spec.privtag) xfree(p->spec.privtag);
 tidy_1:
   sym_remove(&byname, p->byname);
 tidy_0:
@@ -938,6 +939,16 @@ const char *p_name(peer *p)
 const char *p_tag(peer *p)
   { return (p->spec.tag ? p->spec.tag : p->spec.name); }
 
+/* --- @p_privtag@ --- *
+ *
+ * Arguments:  @peer *p@ = pointer to a peer block
+ *
+ * Returns:    A pointer to the peer's private key tag.
+ */
+
+const char *p_privtag(peer *p)
+  { return (p->spec.privtag ? p->spec.privtag : tag_priv); }
+
 /* --- @p_spec@ --- *
  *
  * Arguments:  @peer *p@ = pointer to a peer block
@@ -1002,15 +1013,12 @@ void p_destroy(peer *p)
   a_notify("KILL", "%s", p->spec.name, A_END);
   ksl_free(&p->ks);
   kx_free(&p->kx);
-  if (p->spec.f & PSF_MOBILE)
-    nmobile--;
-  if (p->ifname)
-    xfree(p->ifname);
-  if (p->spec.tag)
-    xfree(p->spec.tag);
+  if (p->spec.f & PSF_MOBILE) nmobile--;
+  if (p->ifname) xfree(p->ifname);
+  if (p->spec.tag) xfree(p->spec.tag);
+  if (p->spec.privtag) xfree(p->spec.privtag);
   p->t->ops->destroy(p->t);
-  if (p->spec.t_ka)
-    sel_rmtimer(&p->tka);
+  if (p->spec.t_ka) sel_rmtimer(&p->tka);
   for (pg = p->pings; pg; pg = ppg) {
     ppg = pg->next;
     p_pingdone(pg, PING_PEERDIED);