Clarify the link rejection message for unauthorized hubs.
authorMichael Poole <mdpoole@troilus.org>
Tue, 9 Mar 2010 03:05:38 +0000 (03:05 +0000)
committerMichael Poole <mdpoole@troilus.org>
Tue, 9 Mar 2010 03:05:38 +0000 (03:05 +0000)
Make the function that makes that decision a little more maintainable.

git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/branches/u2_10_12_branch@1946 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
ircd/m_server.c

index ac780e3f8ceb85f9423f3d1cbeca6fa12fc727f7..45bdb19d5891283581a7399ff9a735a6da77dc95 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-03-08  Michael Poole <mdpoole@troilus.org>
+
+       * ircd/m_server.c (enum lh_type): New type.
+       (check_loop_and_lh): Use the enum instead of magic integers.
+       Make the error message a little clearer when neither "hub" nor
+       "maxhops" is specified for a server.  Clean up the control flow
+       when we decide to reject the link.
+
 2010-03-08  Michael Poole <mdpoole@troilus.org>
 
        * ircd/test/ircd_match_t.c (_SC_PAGE_SIZE): Default to
index 1e38d39746079a768573c3e51e432d62175c62a0..a38b7b8463625d7f730fbc1507db2d423c75be20 100644 (file)
@@ -96,6 +96,14 @@ parse_protocol(const char *proto)
   return prot;
 }
 
+/** Reason not to accept a server's new announcement. */
+enum lh_type {
+  ALLOWED, /**< The new server link is accepted. */
+  MAX_HOPS_EXCEEDED, /**< The path to the server is too long. */
+  NOT_ALLOWED_TO_HUB, /**< My peer is not allowed to hub for the server. */
+  I_AM_NOT_HUB /**< I have another active server link but not FEAT_HUB. */
+};
+
 /** Check whether the introduction of a new server would cause a loop
  * or be disallowed by leaf and hub configuration directives.
  * @param[in] cptr Neighbor who sent the message.
@@ -115,7 +123,8 @@ check_loop_and_lh(struct Client* cptr, struct Client *sptr, time_t *ghost, const
   struct Client* acptr;
   struct Client* LHcptr = NULL;
   struct ConfItem* lhconf;
-  int active_lh_line = 0, ii;
+  enum lh_type active_lh_line = ALLOWED;
+  int ii;
 
   if (ghost)
     *ghost = 0;
@@ -130,18 +139,22 @@ check_loop_and_lh(struct Client* cptr, struct Client *sptr, time_t *ghost, const
     if (!feature_bool(FEAT_HUB))
       for (ii = 0; ii <= HighestFd; ii++)
         if (LocalClientArray[ii] && IsServer(LocalClientArray[ii])) {
-          active_lh_line = 3;
+          active_lh_line = I_AM_NOT_HUB;
           break;
         }
   }
   else if (hop > lhconf->maximum)
   {
-    active_lh_line = 1;
+    /* Because "maximum" should be 0 for non-hub links, check whether
+     * there is a hub mask -- if not, complain that the server isn't
+     * allowed to hub.
+     */
+    active_lh_line = lhconf->hub_limit ? MAX_HOPS_EXCEEDED : NOT_ALLOWED_TO_HUB;
   }
   else if (lhconf->hub_limit && match(lhconf->hub_limit, host))
   {
     struct Client *ac3ptr;
-    active_lh_line = 2;
+    active_lh_line = NOT_ALLOWED_TO_HUB;
     if (junction)
       for (ac3ptr = sptr; ac3ptr != &me; ac3ptr = cli_serv(ac3ptr)->up)
         if (IsJunction(ac3ptr)) {
@@ -192,7 +205,7 @@ check_loop_and_lh(struct Client* cptr, struct Client *sptr, time_t *ghost, const
      */
     if (IsConnecting(acptr))
     {
-      if (!active_lh_line && exit_client(cptr, acptr, &me,
+      if (active_lh_line == ALLOWED && exit_client(cptr, acptr, &me,
           "Just connected via another link") == CPTR_KILLED)
         return CPTR_KILLED;
       /*
@@ -319,7 +332,7 @@ check_loop_and_lh(struct Client* cptr, struct Client *sptr, time_t *ghost, const
       else if (cli_from(c2ptr) == cptr || IsServer(sptr))
       {
         struct Client *killedptrfrom = cli_from(c2ptr);
-        if (active_lh_line)
+        if (active_lh_line != ALLOWED)
         {
           /*
            * If the L: or H: line also gets rid of this link,
@@ -332,7 +345,7 @@ check_loop_and_lh(struct Client* cptr, struct Client *sptr, time_t *ghost, const
            * line problem, we don't squit that.
            */
           if (cli_from(c2ptr) == cptr || (LHcptr && a_kills_b_too(c2ptr, LHcptr)))
-            active_lh_line = 0;
+            active_lh_line = ALLOWED;
           else
           {
             /*
@@ -369,12 +382,12 @@ check_loop_and_lh(struct Client* cptr, struct Client *sptr, time_t *ghost, const
       }
       else
       {
-        if (active_lh_line)
+        if (active_lh_line != ALLOWED)
         {
           if (LHcptr && a_kills_b_too(LHcptr, acptr))
             break;
           if (cli_from(acptr) == cptr || (LHcptr && a_kills_b_too(acptr, LHcptr)))
-            active_lh_line = 0;
+            active_lh_line = ALLOWED;
           else
           {
             LHcptr = 0;
@@ -397,35 +410,27 @@ check_loop_and_lh(struct Client* cptr, struct Client *sptr, time_t *ghost, const
     }
   }
 
-  if (active_lh_line)
+  if (active_lh_line != ALLOWED)
   {
-    int killed = 0;
-    if (LHcptr)
-      killed = a_kills_b_too(LHcptr, sptr);
-    else
+    if (!LHcptr)
       LHcptr = sptr;
-    if (active_lh_line == 1)
+    if (active_lh_line == MAX_HOPS_EXCEEDED)
     {
-      if (exit_client_msg(cptr, LHcptr, &me,
-                          "Maximum hops exceeded for %s at %s",
-                          cli_name(cptr), host) == CPTR_KILLED)
-        return CPTR_KILLED;
+      return exit_client_msg(cptr, LHcptr, &me,
+                             "Maximum hops exceeded for %s at %s",
+                             cli_name(cptr), host);
     }
-    else if (active_lh_line == 2)
+    else if (active_lh_line == NOT_ALLOWED_TO_HUB)
     {
-      if (exit_client_msg(cptr, LHcptr, &me,
-                          "%s is not allowed to hub for %s",
-                          cli_name(cptr), host) == CPTR_KILLED)
-        return CPTR_KILLED;
+      return exit_client_msg(cptr, LHcptr, &me,
+                             "%s is not allowed to hub for %s",
+                             cli_name(cptr), host);
     }
-    else
+    else /* I_AM_NOT_HUB */
     {
       ServerStats->is_ref++;
-      if (exit_client(cptr, LHcptr, &me, "I'm a leaf, define HUB") == CPTR_KILLED)
-        return CPTR_KILLED;
+      return exit_client(cptr, LHcptr, &me, "I'm a leaf, define HUB");
     }
-    /* We just squit somebody, and it wasn't cptr. */
-    return 0;
   }
 
   return 1;