ソースを参照

fixup! Bot linking: Try each IP returned from DNS.

Bryan Drewery 5 ヶ月 前
コミット
210d10867b
2 ファイル変更31 行追加10 行削除
  1. 2 1
      src/botnet.cc
  2. 29 9
      src/dcc.cc

+ 2 - 1
src/botnet.cc

@@ -1148,7 +1148,7 @@ static void botlink_dns_callback(int id, void *client_data, const char *host,
 void
 botlink_next_ip(int i)
 {
-  assert(dcc[i].type == &DCC_FORK_BOT);
+  assert(dcc[i].type == &DCC_DNSWAIT);
   struct dns_info *di = dcc[i].u.dns;
   assert(di->ips->size() > 0);
   if (di->ip_from_dns_idx == -1 && di->no_more_ipv6 == true) {
@@ -1184,6 +1184,7 @@ retries_exhausted:
 
 static void botlink_real(int i)
 {
+  assert(dcc[i].type == &DCC_DNSWAIT);
   int idx = dcc[i].u.dns->caller_idx;
 
   /* Take ownership of the dns_info struct. */

+ 29 - 9
src/dcc.cc

@@ -365,9 +365,35 @@ bot_version(int idx, char *par)
   dprintf(idx, "el\n");
 }
 
+/*
+ * Try next DNS result.
+ * Switch back to DCC_DNSWAIT for retry.
+ */
+static bool
+link_try_next_dns_result(int idx)
+{
+  assert(dcc[idx].type == &DCC_FORK_BOT);
+  struct dns_info *di = dcc[idx].u.bot->di;
+  if (di == NULL || di->ips == NULL)
+    return false;
+  if (di->ip_from_dns_idx == -1 && di->no_more_ipv6 == true) {
+    putlog(LOG_BOTS, "*", "Could not link to %s (DNS retries exhausted).\n",
+        dcc[idx].nick);
+    return false;
+  }
+  dcc[idx].u.bot->di = NULL;
+  dcc[idx].type = &DCC_DNSWAIT;
+  dcc[idx].u.dns = di;
+  botlink_next_ip(idx);
+  return true;
+}
+
 void
 failed_link(int idx)
 {
+  assert(dcc[idx].type == &DCC_FORK_BOT);
+  if (link_try_next_dns_result(idx))
+    return;
   char nick[NICKLEN] = "", s1[NICKLEN + 17 + 1] = "";
 
   if (dcc[idx].u.bot->linker[0]) {
@@ -593,16 +619,10 @@ struct dcc_table DCC_BOT = {
 static void
 fork_bot_eof(int i)
 {
-  struct dns_info *di = dcc[i].u.dns;
-  /* unix socket won't have ips set, but otherwise wait until exhaustion. */
-  if (di->ips == NULL ||
-      (di->ip_from_dns_idx == -1 && di->no_more_ipv6 == true)) {
-    failed_link(i);
+  assert(dcc[i].type == &DCC_FORK_BOT);
+  if (link_try_next_dns_result(i))
     return;
-  }
-  if (di->ips != NULL) {
-    botlink_next_ip(i);
-  }
+  failed_link(i);
 }
 
 struct dcc_table DCC_FORK_BOT = {