ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/src/s_bsd.c
(Generate patch)

Comparing:
ircd-hybrid-7.2/src/s_bsd.c (file contents), Revision 992 by michael, Mon Aug 17 19:19:16 2009 UTC vs.
ircd-hybrid/src/s_bsd.c (file contents), Revision 1155 by michael, Tue Aug 9 20:27:45 2011 UTC

# Line 23 | Line 23
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>
29 < #endif
29 > #include "list.h"
30   #include "fdlist.h"
31   #include "s_bsd.h"
32   #include "client.h"
# Line 35 | Line 34
34   #include "dbuf.h"
35   #include "event.h"
36   #include "irc_string.h"
38 #include "irc_getnameinfo.h"
39 #include "irc_getaddrinfo.h"
37   #include "ircd.h"
41 #include "list.h"
38   #include "listener.h"
39   #include "numeric.h"
40   #include "packet.h"
41   #include "irc_res.h"
46 #include "inet_misc.h"
42   #include "restart.h"
43   #include "s_auth.h"
44   #include "s_conf.h"
# Line 60 | Line 55 | static const char *comm_err_str[] = { "C
55  
56   struct Callback *setup_socket_cb = NULL;
57  
58 < static void comm_connect_callback(fde_t *fd, int status);
58 > static void comm_connect_callback(fde_t *, int);
59   static PF comm_connect_timeout;
60   static void comm_connect_dns_callback(void *, const struct irc_ssaddr *, const char *);
61   static PF comm_connect_tryconnect;
# Line 80 | Line 75 | check_can_use_v6(void)
75    else
76    {
77      ServerInfo.can_use_v6 = 1;
83 #ifdef _WIN32
84    closesocket(v6);
85 #else
78      close(v6);
87 #endif
79    }
80   #else
81    ServerInfo.can_use_v6 = 0;
# Line 100 | Line 91 | check_can_use_v6(void)
91   int
92   get_sockerr(int fd)
93   {
103 #ifndef _WIN32
94    int errtmp = errno;
105 #else
106  int errtmp = WSAGetLastError();
107 #endif
95   #ifdef SO_ERROR
96    int err = 0;
97    socklen_t len = sizeof(err);
# Line 166 | Line 153 | setup_socket(va_list args)
153    setsockopt(fd, IPPROTO_IP, IP_TOS, &opt, sizeof(opt));
154   #endif
155  
169 #ifndef _WIN32
156    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
171 #endif
157  
158    return NULL;
159   }
# Line 210 | Line 195 | close_connection(struct Client *client_p
195      send_queued_write(client_p);
196    }
197  
198 <  if (IsServer(client_p))
198 >  if (IsClient(client_p))
199 >  {
200 >    ++ServerStats.is_cl;
201 >    ServerStats.is_cbs += client_p->localClient->send.bytes;
202 >    ServerStats.is_cbr += client_p->localClient->recv.bytes;
203 >    ServerStats.is_cti += CurrentTime - client_p->firsttime;
204 >  }
205 >  else if (IsServer(client_p))
206    {
207      ++ServerStats.is_sv;
208      ServerStats.is_sbs += client_p->localClient->send.bytes;
# Line 225 | Line 217 | close_connection(struct Client *client_p
217       * If the connection has been up for a long amount of time, schedule
218       * a 'quick' reconnect, else reset the next-connect cycle.
219       */
220 <    if ((conf = find_conf_exact(SERVER_TYPE,
221 <                                  client_p->name, client_p->username,
230 <                                  client_p->host)))
220 >    if ((conf = find_conf_exact(SERVER_TYPE, client_p->name,
221 >                                client_p->username, client_p->host)))
222      {
223        /*
224         * Reschedule a faster reconnect, if this was a automatically
# Line 235 | Line 226 | close_connection(struct Client *client_p
226         * a rehash in between, the status has been changed to
227         * CONF_ILLEGAL). But only do this if it was a "good" link.
228         */
229 <      aconf = (struct AccessItem *)map_to_conf(conf);
230 <      aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
229 >      aconf  = map_to_conf(conf);
230 >      aclass = map_to_conf(aconf->class_ptr);
231        aconf->hold = time(NULL);
232        aconf->hold += (aconf->hold - client_p->since > HANGONGOODLINK) ?
233          HANGONRETRYDELAY : ConFreq(aclass);
243      if (nextconnect > aconf->hold)
244        nextconnect = aconf->hold;
234      }
235    }
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;
253  }
236    else
237      ++ServerStats.is_ni;
238  
# Line 322 | Line 304 | ssl_handshake(int fd, struct Client *cli
304   void
305   add_connection(struct Listener *listener, struct irc_ssaddr *irn, int fd)
306   {
307 <  struct Client *new_client;
326 <
327 <  assert(NULL != listener);
328 <
329 <  new_client = make_client(NULL);
307 >  struct Client *new_client = make_client(NULL);
308  
309    fd_open(&new_client->localClient->fd, fd, 1,
310            (listener->flags & LISTENER_SSL) ?
311            "Incoming SSL connection" : "Incoming connection");
312  
313 <  /*
313 >  /*
314     * copy address to 'sockhost' as a string, copy it to host too
315     * so we have something valid to put into error messages...
316     */
317    memcpy(&new_client->localClient->ip, irn, sizeof(struct irc_ssaddr));
318  
319 <  irc_getnameinfo((struct sockaddr*)&new_client->localClient->ip,
320 <        new_client->localClient->ip.ss_len,  new_client->sockhost,
321 <        HOSTIPLEN, NULL, 0, NI_NUMERICHOST);
319 >  getnameinfo((struct sockaddr *)&new_client->localClient->ip,
320 >              new_client->localClient->ip.ss_len, new_client->sockhost,
321 >              sizeof(new_client->sockhost), NULL, 0, NI_NUMERICHOST);
322    new_client->localClient->aftype = new_client->localClient->ip.ss.ss_family;
345 #ifdef IPV6
346  if (new_client->sockhost[0] == ':')
347    strlcat(new_client->host, "0", HOSTLEN+1);
323  
324 <  if (new_client->localClient->aftype == AF_INET6 &&
350 <      ConfigFileEntry.dot_in_ip6_addr == 1)
324 >  if (new_client->sockhost[0] == ':' && new_client->sockhost[1] == ':')
325    {
326 <    strlcat(new_client->host, new_client->sockhost,HOSTLEN+1);
327 <    strlcat(new_client->host, ".", HOSTLEN+1);
326 >    strlcpy(new_client->host, "0", sizeof(new_client->host));
327 >    strlcpy(new_client->host+1, new_client->sockhost, sizeof(new_client->host)-1);
328 >    memmove(new_client->sockhost+1, new_client->sockhost, sizeof(new_client->sockhost)-1);
329 >    new_client->sockhost[0] = '0';
330    }
331    else
332 < #endif
357 <    strlcat(new_client->host, new_client->sockhost,HOSTLEN+1);
332 >    strlcpy(new_client->host, new_client->sockhost, sizeof(new_client->host));
333  
334    new_client->localClient->listener = listener;
335    ++listener->ref_count;
# Line 541 | Line 516 | comm_connect_tcp(fde_t *fd, const char *
516  
517    snprintf(portname, sizeof(portname), "%d", port);
518  
519 <  if (irc_getaddrinfo(host, portname, &hints, &res))
519 >  if (getaddrinfo(host, portname, &hints, &res))
520    {
521      /* Send the DNS request, for the next level */
522      if (aftype == AF_INET6)
# Line 557 | Line 532 | comm_connect_tcp(fde_t *fd, const char *
532      memcpy(&fd->connect.hostaddr, res->ai_addr, res->ai_addrlen);
533      fd->connect.hostaddr.ss_len = res->ai_addrlen;
534      fd->connect.hostaddr.ss.ss_family = res->ai_family;
535 <    irc_freeaddrinfo(res);
535 >    freeaddrinfo(res);
536      comm_settimeout(fd, timeout*1000, comm_connect_timeout, NULL);
537      comm_connect_tryconnect(fd, NULL);
538    }
# Line 658 | Line 633 | comm_connect_tryconnect(fde_t *fd, void
633    /* Error? */
634    if (retval < 0)
635    {
661 #ifdef _WIN32
662    errno = WSAGetLastError();
663 #endif
636      /*
637       * If we get EISCONN, then we've already connect()ed the socket,
638       * which is a good thing.
# Line 719 | Line 691 | comm_open(fde_t *F, int family, int sock
691     */
692    fd = socket(family, sock_type, proto);
693    if (fd < 0)
722  {
723 #ifdef _WIN32
724    errno = WSAGetLastError();
725 #endif
694      return -1; /* errno will be passed through, yay.. */
727  }
695  
696    execute_callback(setup_socket_cb, fd);
697  
# Line 757 | Line 724 | comm_accept(struct Listener *lptr, struc
724     * reserved fd limit, but we can deal with that when comm_open()
725     * also does it. XXX -- adrian
726     */
727 <  newfd = accept(lptr->fd.fd, (struct sockaddr *)pn, (socklen_t *)&addrlen);
727 >  newfd = accept(lptr->fd.fd, (struct sockaddr *)pn, &addrlen);
728    if (newfd < 0)
762  {
763 #ifdef _WIN32
764    errno = WSAGetLastError();
765 #endif
729      return -1;
767  }
730  
731   #ifdef IPV6
732    remove_ipv6_mapping(pn);
# Line 780 | Line 742 | comm_accept(struct Listener *lptr, struc
742  
743   /*
744   * remove_ipv6_mapping() - Removes IPv4-In-IPv6 mapping from an address
745 < * This function should really inspect the struct itself rather than relying
784 < * on inet_pton and inet_ntop.  OSes with IPv6 mapping listening on both
745 > * OSes with IPv6 mapping listening on both
746   * AF_INET and AF_INET6 map AF_INET connections inside AF_INET6 structures
747   *
748   */
# Line 791 | Line 752 | remove_ipv6_mapping(struct irc_ssaddr *a
752   {
753    if (addr->ss.ss_family == AF_INET6)
754    {
755 <    struct sockaddr_in6 *v6;
795 <
796 <    v6 = (struct sockaddr_in6*)addr;
797 <    if (IN6_IS_ADDR_V4MAPPED(&v6->sin6_addr))
755 >    if (IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)addr)->sin6_addr))
756      {
757 <      char v4ip[HOSTIPLEN];
758 <      struct sockaddr_in *v4 = (struct sockaddr_in*)addr;
759 <      inetntop(AF_INET6, &v6->sin6_addr, v4ip, HOSTIPLEN);
760 <      inet_pton(AF_INET, v4ip, &v4->sin_addr);
757 >      struct sockaddr_in6 v6;
758 >      struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
759 >
760 >      memcpy(&v6, addr, sizeof(v6));
761 >      memset(v4, 0, sizeof(struct sockaddr_in));
762 >      memcpy(&v4->sin_addr, &v6.sin6_addr.s6_addr[12], sizeof(v4->sin_addr));
763 >
764        addr->ss.ss_family = AF_INET;
765        addr->ss_len = sizeof(struct sockaddr_in);
766      }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)