فهرست منبع

* Cleanup DCC/Telnet listening so bot only listens on IPV6 if it was specifically given an IPV6 IP.

Bryan Drewery 16 سال پیش
والد
کامیت
e84178f84d
6فایلهای تغییر یافته به همراه38 افزوده شده و 31 حذف شده
  1. 2 0
      doc/UPDATES
  2. 1 1
      src/chanprog.c
  3. 31 26
      src/dccutil.c
  4. 1 1
      src/dccutil.h
  5. 1 1
      src/main.c
  6. 2 2
      src/mod/ctcp.mod/ctcp.c

+ 2 - 0
doc/UPDATES

@@ -1,3 +1,5 @@
+* Cleanup DCC/Telnet listening so bot only listens on IPV6 if it was specifically given an IPV6 IP.
+
 1.3 - http://wraith.botpack.net/milestone/1.3
 * Binary / shell / startup changes
   * Binary error messages are no longer obscure numbers or fake segfaults. (Compile with OBSCURE_ERRORS to re-enable)

+ 1 - 1
src/chanprog.c

@@ -587,7 +587,7 @@ void rehash_ip() {
 
   if (conf.bot->hub) {
     struct bot_addr *bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, conf.bot->u);
-    listen_all(bi->telnet_port, 0);
+    listen_all(bi->telnet_port, 0, 1);
     my_port = bi->telnet_port;
   } else if (conf.bot->localhub) {
     // If not listening on the domain socket, open it up

+ 31 - 26
src/dccutil.c

@@ -828,15 +828,15 @@ do_boot(int idx, const char *by, const char *reason)
 }
 
 int
-listen_all(port_t lport, bool off)
+listen_all(port_t lport, bool off, bool should_v6)
 {
   int idx = -1;
   port_t port, realport;
 
 #ifdef USE_IPV6
-  int i6 = 0;
+  int i6 = -1;
 #endif /* USE_IPV6 */
-  int i = 0, ii = 0;
+  int i = -1;
   struct portmap *pmap = NULL, *pold = NULL;
 
   port = realport = lport;
@@ -849,7 +849,8 @@ listen_all(port_t lport, bool off)
       }
   }
 
-  for (ii = 0; ii < dcc_total; ii++) {
+  // Look for an existing open port and close if requested
+  for (int ii = 0; ii < dcc_total; ii++) {
     if (dcc[ii].type && (dcc[ii].type == &DCC_TELNET) && (dcc[ii].port == port) &&
            (!strcmp(dcc[ii].nick, "(telnet)") || !strcmp(dcc[ii].nick, "(telnet6)"))) {
       idx = ii;
@@ -881,35 +882,39 @@ listen_all(port_t lport, bool off)
     if (dcc_total >= max_dcc) {
       putlog(LOG_ERRORS, "*", "Can't open listening port - no more DCC Slots");
     } else {
+      if (should_v6 && (conf.bot->net.ip6 || conf.bot->net.host6)) {
 #ifdef USE_IPV6
-      i6 = open_listen_by_af(&port, AF_INET6);
-      if (i6 < 0) {
-        putlog(LOG_ERRORS, "*", "Can't open IPv6 listening port %d - %s", port,
-               i6 == -1 ? "it's taken." : "couldn't assign ip.");
-      } else {
-        /* now setup ipv4/ipv6 listening port */
-        idx = new_dcc(&DCC_TELNET, 0);
-        dcc[idx].addr = 0L;
-        strlcpy(dcc[idx].host6, myipstr(AF_INET6), sizeof(dcc[idx].host6));
-        dcc[idx].port = port;
-        dcc[idx].sock = i6;
-        dcc[idx].timeval = now;
-        strlcpy(dcc[idx].nick, "(telnet6)", NICKLEN);
-        strlcpy(dcc[idx].host, "*", UHOSTLEN);
-        putlog(LOG_DEBUG, "*", "Listening on IPv6 at telnet port %d", port);
+        i6 = open_listen_by_af(&port, AF_INET6);
+        if (i6 < 0) {
+          putlog(LOG_ERRORS, "*", "Can't open IPv6 listening port %d - %s", port,
+              i6 == -1 ? "it's taken." : "couldn't assign ip.");
+        } else {
+          /* now setup ipv4/ipv6 listening port */
+          idx = new_dcc(&DCC_TELNET, 0);
+          dcc[idx].addr = 0L;
+          strlcpy(dcc[idx].host6, myipstr(AF_INET6), sizeof(dcc[idx].host6));
+          dcc[idx].port = port;
+          dcc[idx].sock = i6;
+          dcc[idx].timeval = now;
+          strlcpy(dcc[idx].nick, "(telnet6)", NICKLEN);
+          strlcpy(dcc[idx].host, "*", UHOSTLEN);
+          putlog(LOG_DEBUG, "*", "Listening on IPv6 at telnet port %d", port);
+        }
+#endif
+        if (i6 < 0)
+          putlog(LOG_ERRORS, "*", "Can't open IPv6 listening port %d - %s", port, i6 == -1 ? "it's taken." : "couldn't assign ip.");
       }
+
+      /* now setup ipv4 listening port */
+#ifdef USE_IPV6
       i = open_listen_by_af(&port, AF_INET);
 #else
       i = open_listen(&port);
 #endif /* USE_IPV6 */
+
       if (i < 0) {
-#ifdef USE_IPV6
-        if (i6 < 0)
-#endif /* USE_IPV6 */
-          putlog(LOG_ERRORS, "*", "Can't open IPv4 listening port %d - %s", port,
-                 i == -1 ? "it's taken." : "couldn't assign ip.");
+        putlog(LOG_ERRORS, "*", "Can't open IPv4 listening port %d - %s", port, i == -1 ? "it's taken." : "couldn't assign ip.");
       } else {
-        /* now setup ipv4 listening port */
         idx = new_dcc(&DCC_TELNET, 0);
         dcc[idx].addr = iptolong(getmyip());
         dcc[idx].port = port;
@@ -923,7 +928,7 @@ listen_all(port_t lport, bool off)
       // If was asked for a random listen, save it in a mapping
       if (lport == 0) {
 #ifdef USE_IPV6
-        if (i > 0 || i6 > 0) {
+        if (i > 0 || (should_v6 && i6 > 0)) {
 #else
           if (i > 0) {
 #endif /* USE_IPV6 */

+ 1 - 1
src/dccutil.h

@@ -57,7 +57,7 @@ void do_boot(int, const char *, const char *);
 int detect_dcc_flood(time_t *, struct chat_info *, int);
 void identd_open(const char * = NULL, const char * = NULL, int identd = 1);
 void identd_close();
-int listen_all(port_t, bool);
+int listen_all(port_t, bool, bool);
 bool valid_idx(int);
 int dcc_read(bd::Stream&);
 void dcc_write(bd::Stream&, int);

+ 1 - 1
src/main.c

@@ -190,7 +190,7 @@ void fatal(const char *s, int recoverable)
 /*  flushlogs(); */
 
   if (my_port)
-    listen_all(my_port, 1); /* close the listening port... */
+    listen_all(my_port, 1, 1); /* close the listening port... */
 
   if (conf.bot && conf.bot->localhub)
     unlink(conf.localhub_socket);

+ 2 - 2
src/mod/ctcp.mod/ctcp.c

@@ -387,7 +387,7 @@ static void ctcp_minutely()
   }
 
   if (listen_time <= 0) {
-    listen_all(0, 1);
+    listen_all(0, 1, 0);
   } else
     listen_time--;
 }
@@ -616,7 +616,7 @@ static int ctcp_CHAT(char *nick, char *uhost, struct userrec *u, char *object, c
       if (dcc[i].type && (dcc[i].type->flags & DCT_LISTEN) && (!strcmp(dcc[i].nick, "(telnet)")))
         ix = i;
     }
-    if (dcc_total == max_dcc || (ix < 0 && (ix = listen_all(0, 0)) < 0))
+    if (dcc_total == max_dcc || (ix < 0 && (ix = listen_all(0, 0, 0)) < 0))
       strlcat(ctcp_reply, "\001ERROR no telnet port\001", sizeof(ctcp_reply));
     else {
       if (listen_time <= 2)