X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/f87966dbaeaecb7e1abbc84f7137f5ce8de07a16..37941236c18baccbf89f5842ca63aee471d79256:/peer.c diff --git a/peer.c b/peer.c index 5e4c4f9b..6b746ddb 100644 --- a/peer.c +++ b/peer.c @@ -53,17 +53,6 @@ const tunnel_ops *tunnels[] = { /*----- Main code ---------------------------------------------------------*/ -static void checktimers(void) -{ - sel_timer *t, **tt; - - tt = &sel.timers; - while (*tt) { - assert((*tt)->prev == tt); - tt = &(*tt)->next; - } -} - /* --- @p_pingtype@ --- * * * Arguments: @unsigned msg@ = message type @@ -144,7 +133,7 @@ found: static void p_read(int fd, unsigned mode, void *v) { - peer *p; + peer *p = 0; addr a; size_t sz; ssize_t n; @@ -161,6 +150,28 @@ static void p_read(int fd, unsigned mode, void *v) return; } + /* --- If the packet is a greeting, don't check peers --- */ + + if (n && buf_i[0] == (MSG_MISC | MISC_GREET)) { + IF_TRACING(T_PEER, { + trace(T_PEER, "peer: greeting received from INET %s %u", + inet_ntoa(a.sin.sin_addr), + (unsigned)ntohs(a.sin.sin_port)); + trace_block(T_PACKET, "peer: greeting contents", buf_i, n); + }) + buf_init(&b, buf_i, n); + buf_getbyte(&b); + if (c_check(&b) || BLEFT(&b)) { + a_warn("PEER - invalid-greeting"); + return; + } + a_notify("GREET %s INET %s %u", + b64_encode(buf_i + 1, n - 1), + inet_ntoa(a.sin.sin_addr), + (unsigned)ntohs(a.sin.sin_port)); + return; + } + /* --- Find the appropriate peer --- */ assert(a.sa.sa_family == AF_INET); @@ -357,7 +368,6 @@ void p_pingdone(ping *p, int rc) if (rc != PING_TIMEOUT) sel_rmtimer(&p->t); T( trace(T_PEER, "peer: ping 0x%08lx done (rc = %d)", (unsigned long)p->id, rc); ) -checktimers(); if (rc >= 0) p->func(rc, p->arg); } @@ -435,12 +445,29 @@ int p_pingsend(peer *p, ping *pg, unsigned type, gettimeofday(&tv, 0); tv.tv_sec += timeout; sel_addtimer(&sel, &pg->t, &tv, p_pingtimeout, pg); -checktimers(); T( trace(T_PEER, "peer: send %s 0x%08lx to %s", p_pingtype(type), (unsigned long)pg->id, p->spec.name); ) return (0); } +/* --- @p_greet@ --- * + * + * Arguments: @peer *p@ = peer to send to + * @const void *c@ = pointer to challenge + * @size_t sz@ = size of challenge + * + * Returns: --- + * + * Use: Sends a greeting packet. + */ + +void p_greet(peer *p, const void *c, size_t sz) +{ + buf *b = p_txstart(p, MSG_MISC | MISC_GREET); + buf_put(b, c, sz); + p_txend(p); +} + /* --- @p_tun@ --- * * * Arguments: @peer *p@ = pointer to peer block