| 49 |
|
#include "s_conf.h" |
| 50 |
|
#include "s_log.h" |
| 51 |
|
#include "s_serv.h" |
| 52 |
– |
#include "s_stats.h" |
| 52 |
|
#include "send.h" |
| 53 |
|
#include "memory.h" |
| 54 |
|
#include "s_user.h" |
| 62 |
|
|
| 63 |
|
static void comm_connect_callback(fde_t *fd, int status); |
| 64 |
|
static PF comm_connect_timeout; |
| 65 |
< |
static void comm_connect_dns_callback(void *vptr, struct DNSReply *reply); |
| 65 |
> |
static void comm_connect_dns_callback(void *, const struct irc_ssaddr *, const char *); |
| 66 |
|
static PF comm_connect_tryconnect; |
| 67 |
|
|
| 69 |
– |
extern void init_netio(void); |
| 68 |
|
|
| 69 |
|
/* check_can_use_v6() |
| 70 |
|
* Check if the system can open AF_INET6 sockets |
| 109 |
|
int err = 0; |
| 110 |
|
socklen_t len = sizeof(err); |
| 111 |
|
|
| 112 |
< |
if (-1 < fd && !getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*) &err, (socklen_t *)&len)) |
| 112 |
> |
if (-1 < fd && !getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len)) |
| 113 |
|
{ |
| 114 |
|
if (err) |
| 115 |
|
errtmp = err; |
| 159 |
|
int fd = va_arg(args, int); |
| 160 |
|
int opt = 1; |
| 161 |
|
|
| 162 |
< |
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &opt, sizeof(opt)); |
| 162 |
> |
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)); |
| 163 |
|
|
| 164 |
|
#ifdef IPTOS_LOWDELAY |
| 165 |
|
opt = IPTOS_LOWDELAY; |
| 166 |
< |
setsockopt(fd, IPPROTO_IP, IP_TOS, (char *) &opt, sizeof(opt)); |
| 166 |
> |
setsockopt(fd, IPPROTO_IP, IP_TOS, &opt, sizeof(opt)); |
| 167 |
|
#endif |
| 168 |
|
|
| 169 |
|
#ifndef _WIN32 |
| 212 |
|
|
| 213 |
|
if (IsServer(client_p)) |
| 214 |
|
{ |
| 215 |
< |
ServerStats->is_sv++; |
| 216 |
< |
ServerStats->is_sbs += client_p->localClient->send.bytes; |
| 217 |
< |
ServerStats->is_sbr += client_p->localClient->recv.bytes; |
| 218 |
< |
ServerStats->is_sti += CurrentTime - client_p->firsttime; |
| 215 |
> |
++ServerStats.is_sv; |
| 216 |
> |
ServerStats.is_sbs += client_p->localClient->send.bytes; |
| 217 |
> |
ServerStats.is_sbr += client_p->localClient->recv.bytes; |
| 218 |
> |
ServerStats.is_sti += CurrentTime - client_p->firsttime; |
| 219 |
|
|
| 220 |
|
/* XXX Does this even make any sense at all anymore? |
| 221 |
|
* scheduling a 'quick' reconnect could cause a pile of |
| 246 |
|
} |
| 247 |
|
else if (IsClient(client_p)) |
| 248 |
|
{ |
| 249 |
< |
ServerStats->is_cl++; |
| 250 |
< |
ServerStats->is_cbs += client_p->localClient->send.bytes; |
| 251 |
< |
ServerStats->is_cbr += client_p->localClient->recv.bytes; |
| 252 |
< |
ServerStats->is_cti += CurrentTime - client_p->firsttime; |
| 249 |
> |
++ServerStats.is_cl; |
| 250 |
> |
ServerStats.is_cbs += client_p->localClient->send.bytes; |
| 251 |
> |
ServerStats.is_cbr += client_p->localClient->recv.bytes; |
| 252 |
> |
ServerStats.is_cti += CurrentTime - client_p->firsttime; |
| 253 |
|
} |
| 254 |
|
else |
| 255 |
< |
ServerStats->is_ni++; |
| 255 |
> |
++ServerStats.is_ni; |
| 256 |
|
|
| 257 |
|
#ifdef HAVE_LIBCRYPTO |
| 258 |
|
if (client_p->localClient->fd.ssl) |
| 356 |
|
#endif |
| 357 |
|
strlcat(new_client->host, new_client->sockhost,HOSTLEN+1); |
| 358 |
|
|
| 361 |
– |
new_client->connect_id = ++connect_id; |
| 359 |
|
new_client->localClient->listener = listener; |
| 360 |
|
++listener->ref_count; |
| 361 |
|
|
| 362 |
|
#ifdef HAVE_LIBCRYPTO |
| 363 |
|
if (listener->flags & LISTENER_SSL) |
| 364 |
|
{ |
| 365 |
< |
if ((new_client->localClient->fd.ssl = SSL_new(ServerInfo.ctx)) == NULL) |
| 365 |
> |
if ((new_client->localClient->fd.ssl = SSL_new(ServerInfo.server_ctx)) == NULL) |
| 366 |
|
{ |
| 367 |
|
ilog(L_CRIT, "SSL_new() ERROR! -- %s", |
| 368 |
|
ERR_error_string(ERR_get_error(), NULL)); |
| 507 |
|
void *data, int aftype, int timeout) |
| 508 |
|
{ |
| 509 |
|
struct addrinfo hints, *res; |
| 510 |
< |
char portname[PORTNAMELEN+1]; |
| 510 |
> |
char portname[PORTNAMELEN + 1]; |
| 511 |
|
|
| 512 |
|
assert(callback); |
| 513 |
|
fd->connect.callback = callback; |
| 539 |
|
hints.ai_socktype = SOCK_STREAM; |
| 540 |
|
hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; |
| 541 |
|
|
| 542 |
< |
snprintf(portname, PORTNAMELEN, "%d", port); |
| 542 |
> |
snprintf(portname, sizeof(portname), "%d", port); |
| 543 |
|
|
| 544 |
|
if (irc_getaddrinfo(host, portname, &hints, &res)) |
| 545 |
|
{ |
| 546 |
|
/* Send the DNS request, for the next level */ |
| 550 |
– |
fd->dns_query = MyMalloc(sizeof(struct DNSQuery)); |
| 551 |
– |
fd->dns_query->ptr = fd; |
| 552 |
– |
fd->dns_query->callback = comm_connect_dns_callback; |
| 547 |
|
if (aftype == AF_INET6) |
| 548 |
< |
gethost_byname_type(host, fd->dns_query, T_AAAA); |
| 548 |
> |
gethost_byname_type(comm_connect_dns_callback, fd, host, T_AAAA); |
| 549 |
|
else |
| 550 |
< |
gethost_byname_type(host, fd->dns_query, T_A); |
| 550 |
> |
gethost_byname_type(comm_connect_dns_callback, fd, host, T_A); |
| 551 |
|
} |
| 552 |
|
else |
| 553 |
|
{ |
| 605 |
|
* otherwise we initiate the connect() |
| 606 |
|
*/ |
| 607 |
|
static void |
| 608 |
< |
comm_connect_dns_callback(void *vptr, struct DNSReply *reply) |
| 608 |
> |
comm_connect_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name) |
| 609 |
|
{ |
| 610 |
|
fde_t *F = vptr; |
| 611 |
|
|
| 612 |
< |
if (reply == NULL) |
| 612 |
> |
if (name == NULL) |
| 613 |
|
{ |
| 620 |
– |
MyFree(F->dns_query); |
| 621 |
– |
F->dns_query = NULL; |
| 614 |
|
comm_connect_callback(F, COMM_ERR_DNS); |
| 615 |
|
return; |
| 616 |
|
} |
| 624 |
|
* the DNS record around, and the DNS cache is gone anyway.. |
| 625 |
|
* -- adrian |
| 626 |
|
*/ |
| 627 |
< |
memcpy(&F->connect.hostaddr, &reply->addr, reply->addr.ss_len); |
| 627 |
> |
memcpy(&F->connect.hostaddr, addr, addr->ss_len); |
| 628 |
|
/* The cast is hacky, but safe - port offset is same on v4 and v6 */ |
| 629 |
|
((struct sockaddr_in *) &F->connect.hostaddr)->sin_port = |
| 630 |
|
F->connect.hostaddr.ss_port; |
| 631 |
< |
F->connect.hostaddr.ss_len = reply->addr.ss_len; |
| 631 |
> |
F->connect.hostaddr.ss_len = addr->ss_len; |
| 632 |
|
|
| 633 |
|
/* Now, call the tryconnect() routine to try a connect() */ |
| 642 |
– |
MyFree(F->dns_query); |
| 643 |
– |
F->dns_query = NULL; |
| 634 |
|
comm_connect_tryconnect(F, NULL); |
| 635 |
|
} |
| 636 |
|
|