if (!p) goto unexp;
p_rxupdstats(p, n);
buf_put(p_txstart(p, MSG_MISC | MISC_PONG), BCUR(&b), BLEFT(&b));
if (!p) goto unexp;
p_rxupdstats(p, n);
buf_put(p_txstart(p, MSG_MISC | MISC_PONG), BCUR(&b), BLEFT(&b));
buf_flip(&bb);
p_encrypt(p, MSG_MISC | MISC_EPONG, &bb,
p_txstart(p, MSG_MISC | MISC_EPONG));
buf_flip(&bb);
p_encrypt(p, MSG_MISC | MISC_EPONG, &bb,
p_txstart(p, MSG_MISC | MISC_EPONG));
p_encrypt(p, MSG_MISC | MISC_EPING, &bb, b);
if (!BOK(b))
return (-1);
p_encrypt(p, MSG_MISC | MISC_EPING, &bb, b);
if (!BOK(b))
return (-1);
if ((fd = socket(ai->ai_family, SOCK_DGRAM, 0)) < 0) {
a_warn("PEER", "-", "udp-socket", "%s", aftab[i].name,
"create-failed", "?ERRNO", A_END);
if ((fd = socket(ai->ai_family, SOCK_DGRAM, 0)) < 0) {
a_warn("PEER", "-", "udp-socket", "%s", aftab[i].name,
"create-failed", "?ERRNO", A_END);
}
if (i == AFIX_INET6 &&
setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof(yes))) {
a_warn("PEER", "-", "udp-socket", "%s", aftab[i].name,
"set-v6only-failed", "?ERRNO", A_END);
}
if (i == AFIX_INET6 &&
setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof(yes))) {
a_warn("PEER", "-", "udp-socket", "%s", aftab[i].name,
"set-v6only-failed", "?ERRNO", A_END);
}
assert(ai->ai_addrlen <= sizeof(a));
memcpy(&a, ai->ai_addr, ai->ai_addrlen);
}
assert(ai->ai_addrlen <= sizeof(a));
memcpy(&a, ai->ai_addr, ai->ai_addrlen);
if (bind(fd, &a.sa, addrsz(&a))) {
a_warn("PEER", "-", "udp-socket", "%s", aftab[i].name,
"bind-failed", "?ERRNO", A_END);
if (bind(fd, &a.sa, addrsz(&a))) {
a_warn("PEER", "-", "udp-socket", "%s", aftab[i].name,
"bind-failed", "?ERRNO", A_END);
}
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &len, sizeof(len)) ||
setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &len, sizeof(len))) {
a_warn("PEER", "-", "udp-socket", "%s", aftab[i].name,
"set-buffers-failed", "?ERRNO", A_END);
}
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &len, sizeof(len)) ||
setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &len, sizeof(len))) {
a_warn("PEER", "-", "udp-socket", "%s", aftab[i].name,
"set-buffers-failed", "?ERRNO", A_END);
}
fdflags(fd, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC);
if (port)
}
fdflags(fd, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC);
if (port)
if (getsockname(fd, &a.sa, &sz)) {
a_warn("PEER", "-", "udp-socket", "%s", aftab[i].name,
"read-local-address-failed", "?ERRNO", A_END);
if (getsockname(fd, &a.sa, &sz)) {
a_warn("PEER", "-", "udp-socket", "%s", aftab[i].name,
"read-local-address-failed", "?ERRNO", A_END);
}
udpsock[i].port = lastport = getport(&a);
}
T( trace(T_PEER, "peer: created %s socket", aftab[i].name); )
sel_initfile(&sel, &udpsock[i].sf, fd, SEL_READ, p_read, 0);
sel_addfile(&udpsock[i].sf);
}
udpsock[i].port = lastport = getport(&a);
}
T( trace(T_PEER, "peer: created %s socket", aftab[i].name); )
sel_initfile(&sel, &udpsock[i].sf, fd, SEL_READ, p_read, 0);
sel_addfile(&udpsock[i].sf);
- * 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.
+ * Use: Adds a tunnel class to the list of known classes, if it
+ * initializes properly. 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.
*/
*
* 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.
*/
tn = CREATE(struct tunnel_node);
tn->next = 0; tn->tops = tops;
*tunnels_tail = tn; tunnels_tail = &tn->next;
if (!dflttun) dflttun = tops;
tn = CREATE(struct tunnel_node);
tn->next = 0; tn->tops = tops;
*tunnels_tail = tn; tunnels_tail = &tn->next;
if (!dflttun) dflttun = tops;
b = p_txstart(p, MSG_MISC | MISC_BYE);
buf_init(&bb, buf_t, sizeof(buf_t));
assert(BOK(&bb)); buf_flip(&bb);
p_encrypt(p, MSG_MISC | MISC_BYE, &bb, b);
b = p_txstart(p, MSG_MISC | MISC_BYE);
buf_init(&bb, buf_t, sizeof(buf_t));
assert(BOK(&bb)); buf_flip(&bb);
p_encrypt(p, MSG_MISC | MISC_BYE, &bb, b);
}
a_notify("KILL", "%s", p->spec.name, A_END);
}
a_notify("KILL", "%s", p->spec.name, A_END);