From: Michael Poole Date: Tue, 9 Mar 2010 03:05:38 +0000 (+0000) Subject: Clarify the link rejection message for unauthorized hubs. X-Git-Url: http://git.pk910.de/?p=ircu2.10.12-pk.git;a=commitdiff_plain;h=069994dd27f04b493855949e0d06fce06f210cfe Clarify the link rejection message for unauthorized hubs. 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 --- diff --git a/ChangeLog b/ChangeLog index ac780e3..45bdb19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-03-08 Michael Poole + + * 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 * ircd/test/ircd_match_t.c (_SC_PAGE_SIZE): Default to diff --git a/ircd/m_server.c b/ircd/m_server.c index 1e38d39..a38b7b8 100644 --- a/ircd/m_server.c +++ b/ircd/m_server.c @@ -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;