server/peer.c, server/tripe.c: Add `p_unbind' to tear down the UDP sockets.
[tripe] / server / peer.c
index fb01616..f723ccc 100644 (file)
@@ -894,6 +894,32 @@ void p_bind(struct addrinfo *ailist)
 
 }
 
+/* --- @p_unbind@ --- *
+ *
+ * Arguments:  ---
+ *
+ * Returns:    ---
+ *
+ * Use:                Unbinds the UDP sockets.  There must not be any active peers,
+ *             and none can be created until the sockets are rebound.
+ */
+
+void p_unbind(void)
+{
+  int i;
+
+#ifndef NDEBUG
+  { peer_iter it; p_mkiter(&it); assert(!p_next(&it)); }
+#endif
+
+  for (i = 0; i < NADDRFAM; i++) {
+    if (udpsock[i].sf.fd == -1) continue;
+    sel_rmfile(&udpsock[i].sf);
+    close(udpsock[i].sf.fd);
+    udpsock[i].sf.fd = -1;
+  }
+}
+
 /* --- @p_init@ --- *
  *
  * Arguments:  ---
@@ -992,6 +1018,7 @@ peer *p_create(peerspec *spec)
   T( trace(T_TUNNEL, "peer: attached interface %s to peer `%s'",
           p->ifname, p_name(p)); )
   p_setkatimer(p);
+  iv_addreason();
   if (kx_setup(&p->kx, p, &p->ks, p->spec.f & PSF_KXMASK))
     goto tidy_4;
   a_notify("ADD",
@@ -1010,6 +1037,7 @@ tidy_4:
   if (spec->t_ka) sel_rmtimer(&p->tka);
   xfree(p->ifname);
   p->t->ops->destroy(p->t);
+  iv_rmreason();
 tidy_3:
   if (fd >= 0) close(fd);
 tidy_2:
@@ -1141,9 +1169,21 @@ void p_destroy(peer *p, int bye)
   }
   sym_remove(&byname, p->byname);
   am_remove(&byaddr, p->byaddr);
+  iv_rmreason();
   DESTROY(p);
 }
 
+/* --- @p_destroyall@ --- *
+ *
+ * Arguments:  ---
+ *
+ * Returns:    ---
+ *
+ * Use:                Destroys all of the peers, saying goodbye.
+ */
+
+void p_destroyall(void) { FOREACH_PEER(p, { p_destroy(p, 1); }); }
+
 /* --- @p_mkiter@ --- *
  *
  * Arguments:  @peer_iter *i@ = pointer to an iterator