23 |
|
*/ |
24 |
|
|
25 |
|
#include "stdinc.h" |
26 |
– |
#ifndef _WIN32 |
26 |
|
#include <netinet/in_systm.h> |
27 |
|
#include <netinet/ip.h> |
28 |
|
#include <netinet/tcp.h> |
30 |
– |
#endif |
29 |
|
#include "fdlist.h" |
30 |
|
#include "s_bsd.h" |
31 |
|
#include "client.h" |
47 |
|
#include "s_conf.h" |
48 |
|
#include "s_log.h" |
49 |
|
#include "s_serv.h" |
52 |
– |
#include "s_stats.h" |
50 |
|
#include "send.h" |
51 |
|
#include "memory.h" |
52 |
|
#include "s_user.h" |
60 |
|
|
61 |
|
static void comm_connect_callback(fde_t *fd, int status); |
62 |
|
static PF comm_connect_timeout; |
63 |
< |
static void comm_connect_dns_callback(void *vptr, struct DNSReply *reply); |
63 |
> |
static void comm_connect_dns_callback(void *, const struct irc_ssaddr *, const char *); |
64 |
|
static PF comm_connect_tryconnect; |
65 |
|
|
69 |
– |
extern void init_netio(void); |
66 |
|
|
67 |
|
/* check_can_use_v6() |
68 |
|
* Check if the system can open AF_INET6 sockets |
78 |
|
else |
79 |
|
{ |
80 |
|
ServerInfo.can_use_v6 = 1; |
85 |
– |
#ifdef _WIN32 |
86 |
– |
closesocket(v6); |
87 |
– |
#else |
81 |
|
close(v6); |
89 |
– |
#endif |
82 |
|
} |
83 |
|
#else |
84 |
|
ServerInfo.can_use_v6 = 0; |
94 |
|
int |
95 |
|
get_sockerr(int fd) |
96 |
|
{ |
105 |
– |
#ifndef _WIN32 |
97 |
|
int errtmp = errno; |
107 |
– |
#else |
108 |
– |
int errtmp = WSAGetLastError(); |
109 |
– |
#endif |
98 |
|
#ifdef SO_ERROR |
99 |
|
int err = 0; |
100 |
|
socklen_t len = sizeof(err); |
101 |
|
|
102 |
< |
if (-1 < fd && !getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*) &err, (socklen_t *)&len)) |
102 |
> |
if (-1 < fd && !getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len)) |
103 |
|
{ |
104 |
|
if (err) |
105 |
|
errtmp = err; |
149 |
|
int fd = va_arg(args, int); |
150 |
|
int opt = 1; |
151 |
|
|
152 |
< |
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &opt, sizeof(opt)); |
152 |
> |
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)); |
153 |
|
|
154 |
|
#ifdef IPTOS_LOWDELAY |
155 |
|
opt = IPTOS_LOWDELAY; |
156 |
< |
setsockopt(fd, IPPROTO_IP, IP_TOS, (char *) &opt, sizeof(opt)); |
156 |
> |
setsockopt(fd, IPPROTO_IP, IP_TOS, &opt, sizeof(opt)); |
157 |
|
#endif |
158 |
|
|
171 |
– |
#ifndef _WIN32 |
159 |
|
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK); |
173 |
– |
#endif |
160 |
|
|
161 |
|
return NULL; |
162 |
|
} |
200 |
|
|
201 |
|
if (IsServer(client_p)) |
202 |
|
{ |
203 |
< |
ServerStats->is_sv++; |
204 |
< |
ServerStats->is_sbs += client_p->localClient->send.bytes; |
205 |
< |
ServerStats->is_sbr += client_p->localClient->recv.bytes; |
206 |
< |
ServerStats->is_sti += CurrentTime - client_p->firsttime; |
203 |
> |
++ServerStats.is_sv; |
204 |
> |
ServerStats.is_sbs += client_p->localClient->send.bytes; |
205 |
> |
ServerStats.is_sbr += client_p->localClient->recv.bytes; |
206 |
> |
ServerStats.is_sti += CurrentTime - client_p->firsttime; |
207 |
|
|
208 |
|
/* XXX Does this even make any sense at all anymore? |
209 |
|
* scheduling a 'quick' reconnect could cause a pile of |
234 |
|
} |
235 |
|
else if (IsClient(client_p)) |
236 |
|
{ |
237 |
< |
ServerStats->is_cl++; |
238 |
< |
ServerStats->is_cbs += client_p->localClient->send.bytes; |
239 |
< |
ServerStats->is_cbr += client_p->localClient->recv.bytes; |
240 |
< |
ServerStats->is_cti += CurrentTime - client_p->firsttime; |
237 |
> |
++ServerStats.is_cl; |
238 |
> |
ServerStats.is_cbs += client_p->localClient->send.bytes; |
239 |
> |
ServerStats.is_cbr += client_p->localClient->recv.bytes; |
240 |
> |
ServerStats.is_cti += CurrentTime - client_p->firsttime; |
241 |
|
} |
242 |
|
else |
243 |
< |
ServerStats->is_ni++; |
243 |
> |
++ServerStats.is_ni; |
244 |
|
|
245 |
|
#ifdef HAVE_LIBCRYPTO |
246 |
|
if (client_p->localClient->fd.ssl) |
344 |
|
#endif |
345 |
|
strlcat(new_client->host, new_client->sockhost,HOSTLEN+1); |
346 |
|
|
361 |
– |
new_client->connect_id = ++connect_id; |
347 |
|
new_client->localClient->listener = listener; |
348 |
|
++listener->ref_count; |
349 |
|
|
350 |
|
#ifdef HAVE_LIBCRYPTO |
351 |
|
if (listener->flags & LISTENER_SSL) |
352 |
|
{ |
353 |
< |
if ((new_client->localClient->fd.ssl = SSL_new(ServerInfo.ctx)) == NULL) |
353 |
> |
if ((new_client->localClient->fd.ssl = SSL_new(ServerInfo.server_ctx)) == NULL) |
354 |
|
{ |
355 |
|
ilog(L_CRIT, "SSL_new() ERROR! -- %s", |
356 |
|
ERR_error_string(ERR_get_error(), NULL)); |
495 |
|
void *data, int aftype, int timeout) |
496 |
|
{ |
497 |
|
struct addrinfo hints, *res; |
498 |
< |
char portname[PORTNAMELEN+1]; |
498 |
> |
char portname[PORTNAMELEN + 1]; |
499 |
|
|
500 |
|
assert(callback); |
501 |
|
fd->connect.callback = callback; |
527 |
|
hints.ai_socktype = SOCK_STREAM; |
528 |
|
hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; |
529 |
|
|
530 |
< |
snprintf(portname, PORTNAMELEN, "%d", port); |
530 |
> |
snprintf(portname, sizeof(portname), "%d", port); |
531 |
|
|
532 |
|
if (irc_getaddrinfo(host, portname, &hints, &res)) |
533 |
|
{ |
534 |
|
/* 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; |
535 |
|
if (aftype == AF_INET6) |
536 |
< |
gethost_byname_type(host, fd->dns_query, T_AAAA); |
536 |
> |
gethost_byname_type(comm_connect_dns_callback, fd, host, T_AAAA); |
537 |
|
else |
538 |
< |
gethost_byname_type(host, fd->dns_query, T_A); |
538 |
> |
gethost_byname_type(comm_connect_dns_callback, fd, host, T_A); |
539 |
|
} |
540 |
|
else |
541 |
|
{ |
593 |
|
* otherwise we initiate the connect() |
594 |
|
*/ |
595 |
|
static void |
596 |
< |
comm_connect_dns_callback(void *vptr, struct DNSReply *reply) |
596 |
> |
comm_connect_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name) |
597 |
|
{ |
598 |
|
fde_t *F = vptr; |
599 |
|
|
600 |
< |
if (reply == NULL) |
600 |
> |
if (name == NULL) |
601 |
|
{ |
620 |
– |
MyFree(F->dns_query); |
621 |
– |
F->dns_query = NULL; |
602 |
|
comm_connect_callback(F, COMM_ERR_DNS); |
603 |
|
return; |
604 |
|
} |
612 |
|
* the DNS record around, and the DNS cache is gone anyway.. |
613 |
|
* -- adrian |
614 |
|
*/ |
615 |
< |
memcpy(&F->connect.hostaddr, &reply->addr, reply->addr.ss_len); |
615 |
> |
memcpy(&F->connect.hostaddr, addr, addr->ss_len); |
616 |
|
/* The cast is hacky, but safe - port offset is same on v4 and v6 */ |
617 |
|
((struct sockaddr_in *) &F->connect.hostaddr)->sin_port = |
618 |
|
F->connect.hostaddr.ss_port; |
619 |
< |
F->connect.hostaddr.ss_len = reply->addr.ss_len; |
619 |
> |
F->connect.hostaddr.ss_len = addr->ss_len; |
620 |
|
|
621 |
|
/* Now, call the tryconnect() routine to try a connect() */ |
642 |
– |
MyFree(F->dns_query); |
643 |
– |
F->dns_query = NULL; |
622 |
|
comm_connect_tryconnect(F, NULL); |
623 |
|
} |
624 |
|
|
646 |
|
/* Error? */ |
647 |
|
if (retval < 0) |
648 |
|
{ |
671 |
– |
#ifdef _WIN32 |
672 |
– |
errno = WSAGetLastError(); |
673 |
– |
#endif |
649 |
|
/* |
650 |
|
* If we get EISCONN, then we've already connect()ed the socket, |
651 |
|
* which is a good thing. |
704 |
|
*/ |
705 |
|
fd = socket(family, sock_type, proto); |
706 |
|
if (fd < 0) |
732 |
– |
{ |
733 |
– |
#ifdef _WIN32 |
734 |
– |
errno = WSAGetLastError(); |
735 |
– |
#endif |
707 |
|
return -1; /* errno will be passed through, yay.. */ |
737 |
– |
} |
708 |
|
|
709 |
|
execute_callback(setup_socket_cb, fd); |
710 |
|
|
739 |
|
*/ |
740 |
|
newfd = accept(lptr->fd.fd, (struct sockaddr *)pn, (socklen_t *)&addrlen); |
741 |
|
if (newfd < 0) |
772 |
– |
{ |
773 |
– |
#ifdef _WIN32 |
774 |
– |
errno = WSAGetLastError(); |
775 |
– |
#endif |
742 |
|
return -1; |
777 |
– |
} |
743 |
|
|
744 |
|
#ifdef IPV6 |
745 |
|
remove_ipv6_mapping(pn); |