chiark / gitweb /
server: Repurpose the flags in `peerspec'.
[tripe] / server / peer.c
index 3cb12ea2b1f48fcdafc93679fa118cc14dd6cf93..ec89f771c35f627d4d65c07ef4b265329c0f0c50 100644 (file)
@@ -737,28 +737,30 @@ 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;
   memset(&p->st, 0, sizeof(stats));
   p->st.t_start = time(0);
-  if (!tops->open)
+  if (!(tops->flags & TUNF_PRIVOPEN))
     fd = -1;
-  else if ((fd = tops->open(&p->ifname)) < 0)
+  else if ((fd = ps_tunfd(tops, &p->ifname)) < 0)
     goto tidy_2;
   if ((p->t = tops->create(p, fd, &p->ifname)) == 0)
     goto tidy_3;
   T( trace(T_TUNNEL, "peer: attached interface %s to peer `%s'",
           p->ifname, p_name(p)); )
   p_setkatimer(p);
-  if (kx_init(&p->kx, p, &p->ks, p->spec.kxf))
+  if (kx_init(&p->kx, p, &p->ks, p->spec.f & PSF_KXMASK))
     goto tidy_4;
   a_notify("ADD",
           "?PEER", p,
           "%s", p->ifname,
           "?ADDR", &p->spec.sa,
           A_END);
-  if (!(p->spec.kxf & KXF_CORK)) {
+  if (!(p->spec.f & KXF_CORK)) {
     a_notify("KXSTART", "?PEER", p, A_END);
     /* Couldn't tell anyone before */
   }
@@ -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);