static sym_table byname;
static addrmap byaddr;
static unsigned nmobile;
-
-/*----- Tunnel table ------------------------------------------------------*/
-
-const tunnel_ops *tunnels[] = {
-#ifdef TUN_LINUX
- &tun_linux,
-#endif
-#ifdef TUN_BSD
- &tun_bsd,
-#endif
-#ifdef TUN_UNET
- &tun_unet,
-#endif
- &tun_slip,
- 0
-}, *tun_default;
+static struct tunnel_node {
+ struct tunnel_node *next;
+ const tunnel_ops *tops;
+} *tunnels, **tunnels_tail = &tunnels;
+const tunnel_ops *dflttun;
/*----- Main code ---------------------------------------------------------*/
}
+/* --- @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: ---
am_create(&byaddr);
}
+/* --- @p_addtun@ --- *
+ *
+ * Arguments: @const tunnel_ops *tops@ = tunnel ops to add
+ *
+ * Returns: ---
+ *
+ * Use: Adds a tunnel class to the list of known classes. If there
+ * is no current default tunnel, then this one is made the
+ * default.
+ *
+ * Does nothing if the tunnel class is already known. So adding
+ * a bunch of tunnels takes quadratic time, but there will be
+ * too few to care about.
+ */
+
+void p_addtun(const tunnel_ops *tops)
+{
+ struct tunnel_node *tn;
+
+ for (tn = tunnels; tn; tn = tn->next)
+ if (tn->tops == tops) return;
+ tops->init();
+ tn = CREATE(struct tunnel_node);
+ tn->next = 0; tn->tops = tops;
+ *tunnels_tail = tn; tunnels_tail = &tn->next;
+ if (!dflttun) dflttun = tops;
+}
+
+/* --- @p_setdflttun@ --- *
+ *
+ * Arguments: @const tunnel_ops *tops@ = tunnel ops to set
+ *
+ * Returns: ---
+ *
+ * Use: Sets the default tunnel. It must already be registered. The
+ * old default is forgotten.
+ */
+
+void p_setdflttun(const tunnel_ops *tops)
+ { dflttun = tops; }
+
+/* --- @p_dflttun@ --- *
+ *
+ * Arguments: ---
+ *
+ * Returns: A pointer to the current default tunnel operations, or null
+ * if no tunnels are defined.
+ */
+
+const tunnel_ops *p_dflttun(void) { return (dflttun); }
+
+/* --- @p_findtun@ --- *
+ *
+ * Arguments: @const char *name@ = tunnel name
+ *
+ * Returns: Pointer to the tunnel operations, or null.
+ *
+ * Use: Finds the operations for a named tunnel class.
+ */
+
+const tunnel_ops *p_findtun(const char *name)
+{
+ const struct tunnel_node *tn;
+
+ for (tn = tunnels; tn; tn = tn->next)
+ if (mystrieq(tn->tops->name, name) == 0) return (tn->tops);
+ return (0);
+}
+
+/* --- @p_mktuniter@ --- *
+ *
+ * Arguments: @tuniter *i@ = pointer to iterator to initialize
+ *
+ * Returns: ---
+ *
+ * Use: Initializes a tunnel iterator.
+ */
+
+void p_mktuniter(tun_iter *i) { i->next = tunnels; }
+
+/* --- @p_nexttun@ --- *
+ *
+ * Arguments: @tuniter *i@ = pointer to iterator
+ *
+ * Returns: Pointer to the next tunnel's operations, or null.
+ */
+
+const tunnel_ops *p_nexttun(tun_iter *i)
+{
+ const struct tunnel_node *tn = i->next;
+
+ if (!tn) return (0);
+ else { i->next = tn->next; return (tn->tops); }
+}
+
/* --- @p_keepalive@ --- *
*
* Arguments: @struct timeval *now@ = the current time
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