فهرست منبع

* Bot no longer connects to IRC over IPv6 if it was specifically given an IPv4 IP.

Bryan Drewery 16 سال پیش
والد
کامیت
09bc389e36
4فایلهای تغییر یافته به همراه37 افزوده شده و 17 حذف شده
  1. 3 1
      doc/UPDATES
  2. 9 0
      src/adns.c
  3. 1 0
      src/adns.h
  4. 24 16
      src/mod/server.mod/servmsg.c

+ 3 - 1
doc/UPDATES

@@ -1,4 +1,6 @@
-1.2.17 - http://wraith.botpack.net/milestone/1.2.17
+* Bot no longer connects to IRC over IPv6 if it was specifically given an IPv4 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)
   * Binary pass prompt has been changed to not be an obscure 'bash$' prompt anymore.

+ 9 - 0
src/adns.c

@@ -1176,4 +1176,13 @@ bool valid_dns_id(int idx, int id)
   sdprintf("dns_id: %d is not associated with dead idx: %d", id, idx);
   return 0;
 }
+
+bd::String dns_find_ip(bd::Array<bd::String> ips, int af_type) {
+    for (size_t i = 0; i < ips.size(); ++i) {
+      if (is_dotted_ip(bd::String(ips[i]).c_str()) == af_type) {
+        return ips[i];
+      }
+    }
+	return bd::String();
+}
 /* vim: set sts=4 sw=4 ts=4 noet: */

+ 1 - 0
src/adns.h

@@ -56,6 +56,7 @@ void tell_dnsdebug(int);
 void dns_cache_flush();
 bool valid_dns_id(int, int);
 int reverse_ip(const char *host, char *reverse);
+bd::String dns_find_ip(bd::Array<bd::String> ips, int af_type);
 
 extern int		dns_sock, dns_idx;
 extern const char	*dns_ip;

+ 24 - 16
src/mod/server.mod/servmsg.c

@@ -1715,28 +1715,28 @@ static void server_dns_callback(int id, void *client_data, const char *host, bd:
 
   my_addr_t addr;
   char *ip = NULL;
+  const char* dns_type = NULL;
+  bd::String ip_from_dns;
 
-  /* FIXME: this is a temporary hack to stop bots from connecting over ipv4 when they should be on ipv6
-   * eventually will handle this in open_telnet(ips);
-   */
 #ifdef USE_IPV6
+  /* If IPv6 is wanted, ensure we are connecting to an IPv6 server, otherwise skip it */
   if (conf.bot->net.v6) {
-    size_t i = 0;
-    for (i = 0; i < ips.size(); ++i) {
-      if (is_dotted_ip(bd::String(ips[i]).c_str()) == AF_INET6) {
-        ip = strdup(bd::String(ips[i]).c_str());
-        break;
-      }
-    }
-    if (!ip) {
-      putlog(LOG_SERV, "*", "Failed connect to %s (Could not DNS as IPV6)", host);
-      trying_server = 0;
-      lostdcc(idx);
-      return;
+    ip_from_dns = dns_find_ip(ips, AF_INET6);
+    if (!ip_from_dns.length()) {
+      dns_type = "IPv6";
+      goto fatal_dns;
     }
   } else
 #endif /* USE_IPV6 */
-    ip = strdup(bd::String(ips[0]).c_str());
+  {
+    /* If IPv4 is wanted, don't connect to IPv6! */
+    ip_from_dns = dns_find_ip(ips, AF_INET);
+    if (!ip_from_dns.length()) {
+      dns_type = "IPv4";
+      goto fatal_dns;
+    }
+  }
+  ip = strdup(ip_from_dns.c_str());
 
   get_addr(ip, &addr);
  
@@ -1782,5 +1782,13 @@ static void server_dns_callback(int id, void *client_data, const char *host, bd:
     dprintf(DP_MODE, "USER %s localhost %s :%s\n", botuser, dcc[idx].host, replace_vars(botrealname));
     /* Wait for async result now */
   }
+
   free(ip);
+  return;
+
+fatal_dns:
+  putlog(LOG_SERV, "*", "Failed connect to %s (Could not DNS as %s)", host, dns_type);
+  trying_server = 0;
+  lostdcc(idx);
+  return;
 }