Forward port SOCKSENDBUF, SOCKRECVBUF features from 2.10.11.
[ircu2.10.12-pk.git] / ircd / s_bsd.c
index 282bb5eaebfcc7e1212f23b9b42df31acf1db08f..27d66901f0418abc6de1a29c78445a1bcca98b61 100644 (file)
@@ -27,6 +27,7 @@
 #include "channel.h"
 #include "class.h"
 #include "hash.h"
+#include "ircd_alloc.h"
 #include "ircd_log.h"
 #include "ircd_features.h"
 #include "ircd_osdep.h"
@@ -176,13 +177,15 @@ void report_error(const char* text, const char* who, int err)
  * a non-null pointer, otherwise reply will be null.
  * if successful start the connection, otherwise notify opers
  */
-static void connect_dns_callback(void* vptr, struct DNSReply* reply)
+static void connect_dns_callback(void* vptr, struct hostent* hp)
 {
   struct ConfItem* aconf = (struct ConfItem*) vptr;
+  assert(aconf);
   aconf->dns_pending = 0;
-  if (reply) {
-    memcpy(&aconf->ipnum, reply->hp->h_addr, sizeof(struct in_addr));
-    connect_server(aconf, 0, reply);
+  if (hp) {
+    memcpy(&aconf->ipnum, hp->h_addr, sizeof(struct in_addr));
+    MyFree(hp);
+    connect_server(aconf, 0);
   }
   else
     sendto_opmask_butone(0, SNO_OLDSNO, "Connect to %s failed: host lookup",
@@ -196,12 +199,10 @@ static void connect_dns_callback(void* vptr, struct DNSReply* reply)
 void close_connections(int close_stderr)
 {
   int i;
-#if 0
   close(0);
   close(1);
   if (close_stderr)
     close(2);
-#endif
   for (i = 3; i < MAXCONNECTIONS; ++i)
     close(i);
 }
@@ -289,7 +290,7 @@ static int connect_inet(struct ConfItem* aconf, struct Client* cptr)
   /*
    * we want a big buffer for server connections
    */
-  if (!os_set_sockbufs(cli_fd(cptr), SERVER_TCP_WINDOW)) {
+  if (!os_set_sockbufs(cli_fd(cptr), feature_int(FEAT_SOCKSENDBUF), feature_int(FEAT_SOCKRECVBUF))) {
     cli_error(cptr) = errno;
     report_error(SETBUFS_ERROR_MSG, cli_name(cptr), errno);
     close(cli_fd(cptr));
@@ -395,8 +396,7 @@ void release_dns_reply(struct Client* cptr)
   assert(MyConnect(cptr));
 
   if (cli_dns_reply(cptr)) {
-    assert(0 < cli_dns_reply(cptr)->ref_count);
-    --(cli_dns_reply(cptr))->ref_count;
+    MyFree(cli_dns_reply(cptr));
     cli_dns_reply(cptr) = 0;
   }
 }
@@ -727,11 +727,9 @@ static int read_packet(struct Client *cptr, int socket_ready)
    * For server connections, we process as many as we can without
    * worrying about the time of day or anything :)
    */
-  if (length <= 0)
-    ;
-  else if (IsServer(cptr))
+  if (length > 0 && IsServer(cptr))
     return server_dopacket(cptr, readbuf, length);
-  else if (IsConnecting(cptr)  || IsHandshake(cptr))
+  else if (length > 0 && (IsHandshake(cptr) || IsConnecting(cptr)))
     return connect_dopacket(cptr, readbuf, length);
   else
   {
@@ -740,9 +738,10 @@ static int read_packet(struct Client *cptr, int socket_ready)
      * it on the end of the receive queue and do it when its
      * turn comes around.
      */
-    if (dbuf_put(&(cli_recvQ(cptr)), readbuf, length) == 0)
+    if (length > 0 && dbuf_put(&(cli_recvQ(cptr)), readbuf, length) == 0)
       return exit_client(cptr, cptr, &me, "dbuf_put fail");
-    else if (DBufLength(&(cli_recvQ(cptr))) > feature_int(FEAT_CLIENT_FLOOD))
+
+    if (DBufLength(&(cli_recvQ(cptr))) > feature_int(FEAT_CLIENT_FLOOD))
       return exit_client(cptr, cptr, &me, "Excess Flood");
 
     while (DBufLength(&(cli_recvQ(cptr))) && !NoNewLine(cptr) && 
@@ -819,8 +818,7 @@ static int read_packet(struct Client *cptr, int socket_ready)
  * be done, we loose the information about who started the connection and
  * it's considered an auto connect.
  */
-int connect_server(struct ConfItem* aconf, struct Client* by,
-                   struct DNSReply* reply)
+int connect_server(struct ConfItem* aconf, struct Client* by)
 {
   struct Client*   cptr = 0;
   assert(0 != aconf);
@@ -856,9 +854,8 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
    * not a ip# string, then try and find the appropriate host record.
    */
   if (INADDR_NONE == aconf->ipnum.s_addr) {
-    char buf[HOSTLEN + 1];
-    assert(0 == reply);
     if (INADDR_NONE == (aconf->ipnum.s_addr = inet_addr(aconf->host))) {
+      char buf[HOSTLEN + 1];
       struct DNSQuery  query;
 
       query.vptr     = aconf;
@@ -866,19 +863,12 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
       host_from_uh(buf, aconf->host, HOSTLEN);
       buf[HOSTLEN] = '\0';
 
-      reply = gethost_byname(buf, &query);
-
-      if (!reply) {
-        aconf->dns_pending = 1;
-        return 0;
-      }
-      memcpy(&aconf->ipnum, reply->hp->h_addr, sizeof(struct in_addr));
+      gethost_byname(buf, &query);
+      aconf->dns_pending = 1;
     }
+    return 0;
   }
   cptr = make_client(NULL, STAT_UNKNOWN_SERVER);
-  if (reply)
-    ++reply->ref_count;
-  cli_dns_reply(cptr) = reply;
 
   /*
    * Copy these in so we have something for error detection.
@@ -993,7 +983,7 @@ static void client_sock_callback(struct Event* ev)
   assert(0 != ev_socket(ev));
   assert(0 != s_data(ev_socket(ev)));
 
-  con = s_data(ev_socket(ev));
+  con = (struct Connection*) s_data(ev_socket(ev));
 
   assert(0 != con_client(con) || ev_type(ev) == ET_DESTROY);
 
@@ -1081,7 +1071,7 @@ static void client_timer_callback(struct Event* ev)
   assert(0 != t_data(ev_timer(ev)));
   assert(ET_DESTROY == ev_type(ev) || ET_EXPIRE == ev_type(ev));
 
-  con = t_data(ev_timer(ev));
+  con = (struct Connection*) t_data(ev_timer(ev));
 
   assert(0 != con_client(con) || ev_type(ev) == ET_DESTROY);