1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
18 #include "socketengine.h"
21 #include "commands/cmd_whowas.h"
23 /* XXX: Used for speeding up WriteCommon operations */
24 unsigned long uniq_id = 1;
26 static unsigned long* already_sent = NULL;
28 LocalIntExt User::NICKForced("NICKForced", NULL);
29 LocalStringExt User::OperQuit("OperQuit", NULL);
31 void InitializeAlreadySent(SocketEngine* SE)
33 already_sent = new unsigned long[SE->GetMaxFds()];
34 memset(already_sent, 0, SE->GetMaxFds() * sizeof(unsigned long));
37 std::string User::ProcessNoticeMasks(const char *sm)
39 bool adding = true, oldadding = false;
54 for (unsigned char d = 'A'; d <= 'z'; d++)
56 if (ServerInstance->SNO->IsEnabled(d))
58 if ((!IsNoticeMaskSet(d) && adding) || (IsNoticeMaskSet(d) && !adding))
60 if ((oldadding != adding) || (!output.length()))
61 output += (adding ? '+' : '-');
63 this->SetNoticeMask(d, adding);
72 if ((*c >= 'A') && (*c <= 'z') && (ServerInstance->SNO->IsEnabled(*c)))
74 if ((!IsNoticeMaskSet(*c) && adding) || (IsNoticeMaskSet(*c) && !adding))
76 if ((oldadding != adding) || (!output.length()))
77 output += (adding ? '+' : '-');
79 this->SetNoticeMask(*c, adding);
85 this->WriteNumeric(ERR_UNKNOWNSNOMASK, "%s %c :is unknown snomask char to me", this->nick.c_str(), *c);
94 std::string s = this->FormatNoticeMasks();
97 this->modes[UM_SNOMASK] = false;
103 void User::StartDNSLookup()
108 const char* sip = this->GetIPString();
109 UserResolver *res_reverse;
111 QueryType resolvtype = this->client_sa.sa.sa_family == AF_INET6 ? DNS_QUERY_PTR6 : DNS_QUERY_PTR4;
112 res_reverse = new UserResolver(this, sip, resolvtype, cached);
114 ServerInstance->AddResolver(res_reverse, cached);
116 catch (CoreException& e)
118 ServerInstance->Logs->Log("USERS", DEBUG,"Error in resolver: %s",e.GetReason());
122 bool User::IsNoticeMaskSet(unsigned char sm)
126 return (snomasks[sm-65]);
129 void User::SetNoticeMask(unsigned char sm, bool value)
133 snomasks[sm-65] = value;
136 const char* User::FormatNoticeMasks()
138 static char data[MAXBUF];
141 for (int n = 0; n < 64; n++)
144 data[offset++] = n+65;
151 bool User::IsModeSet(unsigned char m)
155 return (modes[m-65]);
158 void User::SetMode(unsigned char m, bool value)
165 const char* User::FormatModes(bool showparameters)
167 static char data[MAXBUF];
171 for (unsigned char n = 0; n < 64; n++)
175 data[offset++] = n + 65;
176 ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_USER);
177 if (showparameters && mh && mh->GetNumParams(true))
179 std::string p = mh->GetUserParameter(this);
181 params.append(" ").append(p);
186 strlcat(data, params.c_str(), MAXBUF);
190 void User::DecrementModes()
192 ServerInstance->Logs->Log("USERS", DEBUG, "DecrementModes()");
193 for (unsigned char n = 'A'; n <= 'z'; n++)
197 ServerInstance->Logs->Log("USERS", DEBUG,"DecrementModes() found mode %c", n);
198 ModeHandler* mh = ServerInstance->Modes->FindMode(n, MODETYPE_USER);
201 ServerInstance->Logs->Log("USERS", DEBUG,"Found handler %c and call ChangeCount", n);
208 User::User(const std::string &uid)
210 server = ServerInstance->FindServerNamePtr(ServerInstance->Config->ServerName);
211 age = ServerInstance->Time();
213 lastping = signon = idle_lastmsg = nping = registered = 0;
214 bytes_in = bytes_out = cmds_in = cmds_out = 0;
215 quietquit = quitting = exempt = haspassed = dns_done = false;
217 server_sa.sa.sa_family = AF_UNSPEC;
218 client_sa.sa.sa_family = AF_UNSPEC;
220 AllowedPrivs = AllowedOperCommands = NULL;
223 uuid.assign(ServerInstance->GetUID(), 0, UUID_LENGTH - 1);
225 uuid.assign(uid, 0, UUID_LENGTH - 1);
227 ServerInstance->Logs->Log("USERS", DEBUG,"New UUID for user: %s (%s)", uuid.c_str(), uid.empty() ? "allocated new" : "used remote");
229 user_hash::iterator finduuid = ServerInstance->Users->uuidlist->find(uuid);
230 if (finduuid == ServerInstance->Users->uuidlist->end())
231 (*ServerInstance->Users->uuidlist)[uuid] = this;
233 throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
238 ServerInstance->Logs->Log("USERS", DEBUG, "User destructor for %s", uuid.c_str());
239 /* NULL for remote users :) */
242 this->MyClass->RefCount--;
243 ServerInstance->Logs->Log("USERS", DEBUG, "User destructor -- connect refcount now: %lu", this->MyClass->RefCount);
244 if (MyClass->RefCount == 0)
248 if (this->AllowedOperCommands)
250 delete AllowedOperCommands;
251 AllowedOperCommands = NULL;
254 if (this->AllowedPrivs)
260 this->InvalidateCache();
261 this->DecrementModes();
263 if (client_sa.sa.sa_family != AF_UNSPEC)
264 ServerInstance->Users->RemoveCloneCounts(this);
266 ServerInstance->Users->uuidlist->erase(uuid);
269 const std::string& User::MakeHost()
271 if (!this->cached_makehost.empty())
272 return this->cached_makehost;
275 /* This is much faster than snprintf */
277 for(const char* n = ident.c_str(); *n; n++)
280 for(const char* n = host.c_str(); *n; n++)
284 this->cached_makehost.assign(nhost);
286 return this->cached_makehost;
289 const std::string& User::MakeHostIP()
291 if (!this->cached_hostip.empty())
292 return this->cached_hostip;
295 /* This is much faster than snprintf */
297 for(const char* n = ident.c_str(); *n; n++)
300 for(const char* n = this->GetIPString(); *n; n++)
304 this->cached_hostip = ihost;
306 return this->cached_hostip;
309 const std::string User::GetFullHost()
311 if (!this->cached_fullhost.empty())
312 return this->cached_fullhost;
316 for(const char* n = nick.c_str(); *n; n++)
319 for(const char* n = ident.c_str(); *n; n++)
322 for(const char* n = dhost.c_str(); *n; n++)
326 this->cached_fullhost = result;
328 return this->cached_fullhost;
331 char* User::MakeWildHost()
333 static char nresult[MAXBUF];
335 *t++ = '*'; *t++ = '!';
336 *t++ = '*'; *t++ = '@';
337 for(const char* n = dhost.c_str(); *n; n++)
343 const std::string User::GetFullRealHost()
345 if (!this->cached_fullrealhost.empty())
346 return this->cached_fullrealhost;
348 char fresult[MAXBUF];
350 for(const char* n = nick.c_str(); *n; n++)
353 for(const char* n = ident.c_str(); *n; n++)
356 for(const char* n = host.c_str(); *n; n++)
360 this->cached_fullrealhost = fresult;
362 return this->cached_fullrealhost;
365 bool User::IsInvited(const irc::string &channel)
367 time_t now = ServerInstance->Time();
368 InvitedList::iterator safei;
369 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
371 if (channel == i->first)
373 if (i->second != 0 && now > i->second)
375 /* Expired invite, remove it. */
378 invites.erase(safei);
387 InvitedList* User::GetInviteList()
389 time_t now = ServerInstance->Time();
390 /* Weed out expired invites here. */
391 InvitedList::iterator safei;
392 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
394 if (i->second != 0 && now > i->second)
396 /* Expired invite, remove it. */
399 invites.erase(safei);
405 void User::InviteTo(const irc::string &channel, time_t invtimeout)
407 time_t now = ServerInstance->Time();
408 if (invtimeout != 0 && now > invtimeout) return; /* Don't add invites that are expired from the get-go. */
409 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
411 if (channel == i->first)
413 if (i->second != 0 && invtimeout > i->second)
415 i->second = invtimeout;
421 invites.push_back(std::make_pair(channel, invtimeout));
424 void User::RemoveInvite(const irc::string &channel)
426 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
428 if (channel == i->first)
436 bool User::HasModePermission(unsigned char mode, ModeType type)
444 if (mode < 'A' || mode > ('A' + 64)) return false;
446 return ((type == MODETYPE_USER ? AllowedUserModes : AllowedChanModes))[(mode - 'A')];
450 bool User::HasPermission(const std::string &command)
453 * users on remote servers can completely bypass all permissions based checks.
454 * This prevents desyncs when one server has different type/class tags to another.
455 * That having been said, this does open things up to the possibility of source changes
456 * allowing remote kills, etc - but if they have access to the src, they most likely have
457 * access to the conf - so it's an end to a means either way.
462 // are they even an oper at all?
468 if (!AllowedOperCommands)
471 if (AllowedOperCommands->find(command) != AllowedOperCommands->end())
473 else if (AllowedOperCommands->find("*") != AllowedOperCommands->end())
480 bool User::HasPrivPermission(const std::string &privstr, bool noisy)
484 ServerInstance->Logs->Log("PRIVS", DEBUG, "Remote (yes)");
491 this->WriteServ("NOTICE %s :You are not an oper", this->nick.c_str());
498 this->WriteServ("NOTICE %s :Privset empty(!?)", this->nick.c_str());
502 if (AllowedPrivs->find(privstr) != AllowedPrivs->end())
506 else if (AllowedPrivs->find("*") != AllowedPrivs->end())
512 this->WriteServ("NOTICE %s :Oper type %s does not have access to priv %s", this->nick.c_str(), this->oper.c_str(), privstr.c_str());
516 void User::OnDataReady()
521 if (MyClass && recvq.length() > MyClass->GetRecvqMax() && !HasPrivPermission("users/flood/increased-buffers"))
523 ServerInstance->Users->QuitUser(this, "RecvQ exceeded");
524 ServerInstance->SNO->WriteToSnoMask('a', "User %s RecvQ of %lu exceeds connect class maximum of %lu",
525 nick.c_str(), (unsigned long)recvq.length(), MyClass->GetRecvqMax());
527 unsigned long sendqmax = ULONG_MAX;
528 if (MyClass && !HasPrivPermission("users/flood/increased-buffers"))
529 sendqmax = MyClass->GetSendqSoftMax();
531 while (Penalty < 10 && getSendQSize() < sendqmax)
534 line.reserve(MAXBUF);
535 std::string::size_type qpos = 0;
536 while (qpos < recvq.length())
538 char c = recvq[qpos++];
549 if (line.length() < MAXBUF - 2)
552 // if we got here, the recvq ran out before we found a newline
555 // just found a newline. Terminate the string, and pull it out of recvq
556 recvq = recvq.substr(qpos);
558 // TODO should this be moved to when it was inserted in recvq?
559 ServerInstance->stats->statsRecv += qpos;
560 this->bytes_in += qpos;
563 ServerInstance->Parser->ProcessBuffer(line, this);
565 // Add pseudo-penalty so that we continue processing after sendq recedes
566 if (Penalty == 0 && getSendQSize() >= sendqmax)
570 void User::AddWriteBuf(const std::string &data)
572 // Don't bother sending text to remote users!
575 if (!quitting && MyClass && getSendQSize() + data.length() > MyClass->GetSendqHardMax() && !HasPrivPermission("users/flood/increased-buffers"))
578 * Quit the user FIRST, because otherwise we could recurse
579 * here and hit the same limit.
581 ServerInstance->Users->QuitUser(this, "SendQ exceeded");
582 ServerInstance->SNO->WriteToSnoMask('a', "User %s SendQ exceeds connect class maximum of %lu",
583 nick.c_str(), MyClass->GetSendqHardMax());
587 // We still want to append data to the sendq of a quitting user,
588 // e.g. their ERROR message that says 'closing link'
593 void User::OnError(BufferedSocketError)
595 ServerInstance->Users->QuitUser(this, getError());
601 ServerInstance->Users->QuitUser(this, "Culled without QuitUser");
607 std::vector<User*>::iterator x = find(ServerInstance->Users->local_users.begin(),ServerInstance->Users->local_users.end(),this);
608 if (x != ServerInstance->Users->local_users.end())
609 ServerInstance->Users->local_users.erase(x);
611 ServerInstance->Logs->Log("USERS", DEBUG, "Failed to remove user from vector");
615 void User::Oper(const std::string &opertype, const std::string &opername)
617 if (this->IsModeSet('o'))
620 this->modes[UM_OPERATOR] = 1;
621 this->WriteServ("MODE %s :+o", this->nick.c_str());
622 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
624 ServerInstance->SNO->WriteToSnoMask('o',"%s (%s@%s) is now an IRC operator of type %s (using oper '%s')", this->nick.c_str(), this->ident.c_str(), this->host.c_str(), irc::Spacify(opertype.c_str()), opername.c_str());
625 this->WriteNumeric(381, "%s :You are now %s %s", this->nick.c_str(), strchr("aeiouAEIOU", *opertype.c_str()) ? "an" : "a", irc::Spacify(opertype.c_str()));
627 ServerInstance->Logs->Log("OPER", DEFAULT, "%s!%s@%s opered as type: %s", this->nick.c_str(), this->ident.c_str(), this->host.c_str(), opertype.c_str());
628 this->oper.assign(opertype, 0, 512);
629 ServerInstance->Users->all_opers.push_back(this);
632 * This might look like it's in the wrong place.
635 * For multi-network servers, we may not have the opertypes of the remote server, but we still want to mark the user as an oper of that type.
638 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper.c_str());
639 if (iter_opertype != ServerInstance->Config->opertypes.end())
641 if (AllowedOperCommands)
642 AllowedOperCommands->clear();
644 AllowedOperCommands = new std::set<std::string>;
647 AllowedPrivs->clear();
649 AllowedPrivs = new std::set<std::string>;
651 AllowedUserModes.reset();
652 AllowedChanModes.reset();
653 this->AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want.
655 std::string myclass, mycmd, mypriv;
656 irc::spacesepstream Classes(iter_opertype->second.c_str());
657 while (Classes.GetToken(myclass))
659 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass.c_str());
660 if (iter_operclass != ServerInstance->Config->operclass.end())
662 /* Process commands */
663 irc::spacesepstream CommandList(iter_operclass->second.commandlist);
664 while (CommandList.GetToken(mycmd))
666 this->AllowedOperCommands->insert(mycmd);
669 irc::spacesepstream PrivList(iter_operclass->second.privs);
670 while (PrivList.GetToken(mypriv))
672 this->AllowedPrivs->insert(mypriv);
675 for (unsigned char* c = (unsigned char*)iter_operclass->second.umodelist.c_str(); *c; ++c)
679 this->AllowedUserModes.set();
683 this->AllowedUserModes[*c - 'A'] = true;
687 for (unsigned char* c = (unsigned char*)iter_operclass->second.cmodelist.c_str(); *c; ++c)
691 this->AllowedChanModes.set();
695 this->AllowedChanModes[*c - 'A'] = true;
702 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype, opername));
710 * unset their oper type (what IS_OPER checks).
711 * note, order is important - this must come before modes as -o attempts
712 * to call UnOper. -- w00t
717 /* Remove all oper only modes from the user when the deoper - Bug #466*/
718 std::string moderemove("-");
720 for (unsigned char letter = 'A'; letter <= 'z'; letter++)
722 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER);
723 if (mh && mh->NeedsOper())
724 moderemove += letter;
728 std::vector<std::string> parameters;
729 parameters.push_back(this->nick);
730 parameters.push_back(moderemove);
732 ServerInstance->Parser->CallHandler("MODE", parameters, this);
734 /* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */
735 ServerInstance->Users->all_opers.remove(this);
737 if (AllowedOperCommands)
739 delete AllowedOperCommands;
740 AllowedOperCommands = NULL;
749 AllowedUserModes.reset();
750 AllowedChanModes.reset();
751 this->modes[UM_OPERATOR] = 0;
755 /* adds or updates an entry in the whowas list */
756 void User::AddToWhoWas()
758 Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so");
761 WhowasRequest req(NULL, whowas, WhowasRequest::WHOWAS_ADD);
768 * Check class restrictions
770 void User::CheckClass()
772 ConnectClass* a = this->MyClass;
774 if ((!a) || (a->type == CC_DENY))
776 ServerInstance->Users->QuitUser(this, "Unauthorised connection");
779 else if ((a->GetMaxLocal()) && (ServerInstance->Users->LocalCloneCount(this) > a->GetMaxLocal()))
781 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (local)");
782 ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
785 else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
787 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (global)");
788 ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
792 this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
795 bool User::CheckLines(bool doZline)
797 const char* check[] = { "G" , "K", (doZline) ? "Z" : NULL, NULL };
801 for (int n = 0; check[n]; ++n)
803 XLine *r = ServerInstance->XLines->MatchesLine(check[n], this);
816 void User::FullConnect()
818 ServerInstance->stats->statsConnects++;
819 this->idle_lastmsg = ServerInstance->Time();
822 * You may be thinking "wtf, we checked this in User::AddClient!" - and yes, we did, BUT.
823 * At the time AddClient is called, we don't have a resolved host, by here we probably do - which
824 * may put the user into a totally seperate class with different restrictions! so we *must* check again.
825 * Don't remove this! -- w00t
829 /* Check the password, if one is required by the user's connect class.
830 * This CANNOT be in CheckClass(), because that is called prior to PASS as well!
832 if (this->MyClass && !this->MyClass->GetPass().empty() && !this->haspassed)
834 ServerInstance->Users->QuitUser(this, "Invalid password");
838 if (this->CheckLines())
841 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
842 this->WriteNumeric(RPL_WELCOME, "%s :Welcome to the %s IRC Network %s!%s@%s",this->nick.c_str(), ServerInstance->Config->Network, this->nick.c_str(), this->ident.c_str(), this->host.c_str());
843 this->WriteNumeric(RPL_YOURHOSTIS, "%s :Your host is %s, running version InspIRCd-2.0",this->nick.c_str(),ServerInstance->Config->ServerName);
844 this->WriteNumeric(RPL_SERVERCREATED, "%s :This server was created %s %s", this->nick.c_str(), __TIME__, __DATE__);
845 this->WriteNumeric(RPL_SERVERVERSION, "%s %s InspIRCd-2.0 %s %s %s", this->nick.c_str(), ServerInstance->Config->ServerName, ServerInstance->Modes->UserModeList().c_str(), ServerInstance->Modes->ChannelModeList().c_str(), ServerInstance->Modes->ParaModeList().c_str());
847 ServerInstance->Config->Send005(this);
848 this->WriteNumeric(RPL_YOURUUID, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str());
854 if (ServerInstance->Users->unregistered_count)
855 ServerInstance->Users->unregistered_count--;
857 /* Trigger LUSERS output, give modules a chance too */
858 ModResult MOD_RESULT;
859 std::string command("LUSERS");
860 std::vector<std::string> parameters;
861 FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true, "LUSERS"));
863 ServerInstance->CallCommandHandler(command, parameters, this);
866 * We don't set REG_ALL until triggering OnUserConnect, so some module events don't spew out stuff
867 * for a user that doesn't exist yet.
869 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
871 this->registered = REG_ALL;
873 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
875 ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s] [%s]",
876 this->GetServerPort(), this->nick.c_str(), this->ident.c_str(), this->host.c_str(), this->GetIPString(), this->fullname.c_str());
877 ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Adding NEGATIVE hit for %s", this->GetIPString());
878 ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
881 /** User::UpdateNick()
882 * re-allocates a nick in the user_hash after they change nicknames,
883 * returns a pointer to the new user as it may have moved
885 User* User::UpdateNickHash(const char* New)
887 //user_hash::iterator newnick;
888 user_hash::iterator oldnick = ServerInstance->Users->clientlist->find(this->nick);
890 if (!irc::string(this->nick.c_str()).compare(New))
891 return oldnick->second;
893 if (oldnick == ServerInstance->Users->clientlist->end())
894 return NULL; /* doesnt exist */
896 User* olduser = oldnick->second;
897 ServerInstance->Users->clientlist->erase(oldnick);
898 (*(ServerInstance->Users->clientlist))[New] = olduser;
902 void User::InvalidateCache()
904 /* Invalidate cache */
905 cached_fullhost.clear();
906 cached_hostip.clear();
907 cached_makehost.clear();
908 cached_fullrealhost.clear();
911 bool User::ForceNickChange(const char* newnick)
913 ModResult MOD_RESULT;
915 this->InvalidateCache();
917 NICKForced.set(this, 1);
918 FIRST_MOD_RESULT(OnUserPreNick, MOD_RESULT, (this, newnick));
919 NICKForced.set(this, 0);
921 if (MOD_RESULT == MOD_RES_DENY)
923 ServerInstance->stats->statsCollisions++;
927 std::deque<classbase*> dummy;
928 Command* nickhandler = ServerInstance->Parser->GetHandler("NICK");
929 if (nickhandler) // wtfbbq, when would this not be here
931 std::vector<std::string> parameters;
932 parameters.push_back(newnick);
933 NICKForced.set(this, 1);
934 bool result = (ServerInstance->Parser->CallHandler("NICK", parameters, this) == CMD_SUCCESS);
935 NICKForced.set(this, 0);
939 // Unreachable, we hope
943 int User::GetServerPort()
945 switch (this->server_sa.sa.sa_family)
948 return htons(this->server_sa.in6.sin6_port);
950 return htons(this->server_sa.in4.sin_port);
955 const char* User::GetCIDRMask(int range)
960 throw "Negative range, sorry, no.";
963 * Original code written by Oliver Lupton (Om).
964 * Integrated by me. Thanks. :) -- w00t
966 switch (this->client_sa.sa.sa_family)
970 /* unsigned char s6_addr[16]; */
972 int i, bytestozero, extrabits;
976 throw "CIDR mask width greater than address width (IPv6, 128 bit)";
978 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
979 * to zero. This means the last (128 - range) bits of the address must be set to zero.
980 * Hence this number divided by 8 is the number of whole bytes from the end of the address
981 * which must be set to zero.
983 bytestozero = (128 - range) / 8;
985 /* Some of the least significant bits of the next most significant byte may also have to
986 * be zeroed. The number of bits is the remainder of the above division.
988 extrabits = (128 - range) % 8;
990 /* Populate our working struct with the parts of the user's IP which are required in the
991 * final CIDR mask. Set all the subsequent bytes to zero.
992 * (16 - bytestozero) is the number of bytes which must be populated with actual IP data.
994 for(i = 0; i < (16 - bytestozero); i++)
996 v6.s6_addr[i] = client_sa.in6.sin6_addr.s6_addr[i];
999 /* And zero all the remaining bytes in the IP. */
1005 /* And finally, zero the extra bits required. */
1006 v6.s6_addr[15 - bytestozero] = (v6.s6_addr[15 - bytestozero] >> extrabits) << extrabits;
1008 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET6, &v6, buffer, 40), range);
1018 throw "CIDR mask width greater than address width (IPv4, 32 bit)";
1020 /* Users already have a sockaddr* pointer (User::ip) which contains either a v4 or v6 structure */
1021 v4.s_addr = client_sa.in4.sin_addr.s_addr;
1023 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1024 * to zero. This means the last (32 - range) bits of the address must be set to zero.
1025 * This is done by shifting the value right and then back left by (32 - range) bits.
1029 v4.s_addr = ntohl(v4.s_addr);
1030 v4.s_addr = (v4.s_addr >> (32 - range)) << (32 - range);
1031 v4.s_addr = htonl(v4.s_addr);
1035 /* a range of zero would cause a 32 bit value to be shifted by 32 bits.
1036 * this has undefined behaviour, but for CIDR purposes the resulting mask
1037 * from a.b.c.d/0 is 0.0.0.0/0
1042 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET, &v4, buffer, 16), range);
1048 return ""; // unused, but oh well
1051 std::string User::GetServerIP()
1055 irc::sockets::satoap(&server_sa, ip, port);
1059 const char* User::GetIPString()
1062 if (cachedip.empty())
1064 irc::sockets::satoap(&client_sa, cachedip, port);
1065 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1066 if (cachedip.c_str()[0] == ':')
1067 cachedip.insert(0,1,'0');
1070 return cachedip.c_str();
1073 bool User::SetClientIP(const char* sip)
1075 this->cachedip = "";
1076 return irc::sockets::aptosa(sip, 0, &client_sa);
1079 static std::string wide_newline("\r\n");
1081 void User::Write(const std::string& text)
1083 if (!ServerInstance->SE->BoundsCheckFd(this))
1086 if (text.length() > MAXBUF - 2)
1088 // this should happen rarely or never. Crop the string at 512 and try again.
1089 std::string try_again = text.substr(0, MAXBUF - 2);
1094 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
1096 this->AddWriteBuf(text);
1097 this->AddWriteBuf(wide_newline);
1099 ServerInstance->stats->statsSent += text.length() + 2;
1100 this->bytes_out += text.length() + 2;
1106 void User::Write(const char *text, ...)
1109 char textbuffer[MAXBUF];
1111 va_start(argsPtr, text);
1112 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1115 this->Write(std::string(textbuffer));
1118 void User::WriteServ(const std::string& text)
1120 this->Write(":%s %s",ServerInstance->Config->ServerName,text.c_str());
1124 * Same as Write(), except `text' is prefixed with `:server.name '.
1126 void User::WriteServ(const char* text, ...)
1129 char textbuffer[MAXBUF];
1131 va_start(argsPtr, text);
1132 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1135 this->WriteServ(std::string(textbuffer));
1139 void User::WriteNumeric(unsigned int numeric, const char* text, ...)
1142 char textbuffer[MAXBUF];
1144 va_start(argsPtr, text);
1145 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1148 this->WriteNumeric(numeric, std::string(textbuffer));
1151 void User::WriteNumeric(unsigned int numeric, const std::string &text)
1153 char textbuffer[MAXBUF];
1154 ModResult MOD_RESULT;
1156 FIRST_MOD_RESULT(OnNumeric, MOD_RESULT, (this, numeric, text));
1158 if (MOD_RESULT == MOD_RES_DENY)
1161 snprintf(textbuffer,MAXBUF,":%s %03u %s",ServerInstance->Config->ServerName, numeric, text.c_str());
1162 this->Write(std::string(textbuffer));
1165 void User::WriteFrom(User *user, const std::string &text)
1169 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost().c_str(),text.c_str());
1171 this->Write(std::string(tb));
1175 /* write text from an originating user to originating user */
1177 void User::WriteFrom(User *user, const char* text, ...)
1180 char textbuffer[MAXBUF];
1182 va_start(argsPtr, text);
1183 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1186 this->WriteFrom(user, std::string(textbuffer));
1190 /* write text to an destination user from a source user (e.g. user privmsg) */
1192 void User::WriteTo(User *dest, const char *data, ...)
1194 char textbuffer[MAXBUF];
1197 va_start(argsPtr, data);
1198 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1201 this->WriteTo(dest, std::string(textbuffer));
1204 void User::WriteTo(User *dest, const std::string &data)
1206 dest->WriteFrom(this, data);
1210 void User::WriteCommon(const char* text, ...)
1212 char textbuffer[MAXBUF];
1215 if (this->registered != REG_ALL)
1218 va_start(argsPtr, text);
1219 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1222 this->WriteCommon(std::string(textbuffer));
1225 void User::WriteCommon(const std::string &text)
1227 bool sent_to_at_least_one = false;
1230 if (this->registered != REG_ALL)
1236 InitializeAlreadySent(ServerInstance->SE);
1238 /* We dont want to be doing this n times, just once */
1239 snprintf(tb,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1240 std::string out = tb;
1242 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1244 const UserMembList* ulist = (*v)->GetUsers();
1245 for (UserMembList::const_iterator i = ulist->begin(); i != ulist->end(); i++)
1247 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1249 already_sent[i->first->fd] = uniq_id;
1250 i->first->Write(out);
1251 sent_to_at_least_one = true;
1257 * if the user was not in any channels, no users will receive the text. Make sure the user
1258 * receives their OWN message for WriteCommon
1260 if (!sent_to_at_least_one)
1262 this->Write(std::string(tb));
1267 /* write a formatted string to all users who share at least one common
1268 * channel, NOT including the source user e.g. for use in QUIT
1271 void User::WriteCommonExcept(const char* text, ...)
1273 char textbuffer[MAXBUF];
1276 va_start(argsPtr, text);
1277 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1280 this->WriteCommonExcept(std::string(textbuffer));
1283 void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
1288 if (this->registered != REG_ALL)
1294 InitializeAlreadySent(ServerInstance->SE);
1296 snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),normal_text.c_str());
1297 snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),oper_text.c_str());
1298 std::string out1 = tb1;
1299 std::string out2 = tb2;
1301 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1303 const UserMembList* ulist = (*v)->GetUsers();
1304 for (UserMembList::const_iterator i = ulist->begin(); i != ulist->end(); i++)
1306 if (this != i->first)
1308 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1310 already_sent[i->first->fd] = uniq_id;
1311 i->first->Write(IS_OPER(i->first) ? out2 : out1);
1318 void User::WriteCommonExcept(const std::string &text)
1323 if (this->registered != REG_ALL)
1329 InitializeAlreadySent(ServerInstance->SE);
1331 snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1334 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1336 const UserMembList* ulist = (*v)->GetUsers();
1337 for (UserMembList::const_iterator i = ulist->begin(); i != ulist->end(); i++)
1339 if (this != i->first)
1341 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1343 already_sent[i->first->fd] = uniq_id;
1344 i->first->Write(out1);
1352 void User::WriteWallOps(const std::string &text)
1354 std::string wallop("WALLOPS :");
1355 wallop.append(text);
1357 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1360 if (t->IsModeSet('w'))
1361 this->WriteTo(t,wallop);
1365 void User::WriteWallOps(const char* text, ...)
1367 if (!IS_LOCAL(this))
1370 char textbuffer[MAXBUF];
1373 va_start(argsPtr, text);
1374 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1377 this->WriteWallOps(std::string(textbuffer));
1380 /* return 0 or 1 depending if users u and u2 share one or more common channels
1381 * (used by QUIT, NICK etc which arent channel specific notices)
1383 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1384 * the first users channels then the second users channels within the outer loop,
1385 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1386 * all possible iterations). However this new function instead checks against the
1387 * channel's userlist in the inner loop which is a std::map<User*,User*>
1388 * and saves us time as we already know what pointer value we are after.
1389 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1390 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1392 bool User::SharesChannelWith(User *other)
1394 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1398 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1400 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1401 * by replacing it with a map::find which *should* be more efficient
1403 if ((*i)->HasUser(other))
1409 bool User::ChangeName(const char* gecos)
1411 if (!this->fullname.compare(gecos))
1416 ModResult MOD_RESULT;
1417 FIRST_MOD_RESULT(OnChangeLocalUserGECOS, MOD_RESULT, (this,gecos));
1418 if (MOD_RESULT == MOD_RES_DENY)
1420 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1422 this->fullname.assign(gecos, 0, ServerInstance->Config->Limits.MaxGecos);
1427 void User::DoHostCycle(const std::string &quitline)
1429 char buffer[MAXBUF];
1431 ModResult result = MOD_RES_PASSTHRU;
1432 FIRST_MOD_RESULT(OnHostCycle, result, (this));
1434 if (result == MOD_RES_DENY)
1436 if (result == MOD_RES_PASSTHRU && !ServerInstance->Config->CycleHosts)
1442 InitializeAlreadySent(ServerInstance->SE);
1444 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1447 snprintf(buffer, MAXBUF, ":%s JOIN %s", GetFullHost().c_str(), c->name.c_str());
1448 std::string joinline(buffer);
1449 std::string modeline = ServerInstance->Modes->ModeString(this, c);
1450 if (modeline.length() > 0)
1452 snprintf(buffer, MAXBUF, ":%s MODE %s +%s", GetFullHost().c_str(), c->name.c_str(), modeline.c_str());
1456 const UserMembList *ulist = c->GetUsers();
1457 for (UserMembList::const_iterator i = ulist->begin(); i != ulist->end(); i++)
1460 if (u == this || !IS_LOCAL(u))
1463 if (already_sent[i->first->fd] != uniq_id)
1466 already_sent[i->first->fd] = uniq_id;
1469 if (modeline.length() > 0)
1475 bool User::ChangeDisplayedHost(const char* shost)
1482 ModResult MOD_RESULT;
1483 FIRST_MOD_RESULT(OnChangeLocalUserHost, MOD_RESULT, (this,shost));
1484 if (MOD_RESULT == MOD_RES_DENY)
1488 FOREACH_MOD(I_OnChangeHost, OnChangeHost(this,shost));
1490 std::string quitstr = ":" + GetFullHost() + " QUIT :Changing host";
1492 /* Fix by Om: User::dhost is 65 long, this was truncating some long hosts */
1493 this->dhost.assign(shost, 0, 64);
1495 this->InvalidateCache();
1497 this->DoHostCycle(quitstr);
1500 this->WriteNumeric(RPL_YOURDISPLAYEDHOST, "%s %s :is now your displayed host",this->nick.c_str(),this->dhost.c_str());
1505 bool User::ChangeIdent(const char* newident)
1507 if (this->ident == newident)
1510 FOREACH_MOD(I_OnChangeIdent, OnChangeIdent(this,newident));
1512 std::string quitstr = ":" + GetFullHost() + " QUIT :Changing ident";
1514 this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax + 1);
1516 this->InvalidateCache();
1518 this->DoHostCycle(quitstr);
1523 void User::SendAll(const char* command, const char* text, ...)
1525 char textbuffer[MAXBUF];
1526 char formatbuffer[MAXBUF];
1529 va_start(argsPtr, text);
1530 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1533 snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost().c_str(), command, textbuffer);
1534 std::string fmt = formatbuffer;
1536 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1543 std::string User::ChannelList(User* source, bool spy)
1547 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1550 /* If the target is the sender, neither +p nor +s is set, or
1551 * the channel contains the user, it is not a spy channel
1553 if (spy != (source == this || !(c->IsModeSet('p') || c->IsModeSet('s')) || c->HasUser(source)))
1554 list.append(c->GetPrefixChar(this)).append(c->name).append(" ");
1560 void User::SplitChanList(User* dest, const std::string &cl)
1563 std::ostringstream prefix;
1564 std::string::size_type start, pos, length;
1566 prefix << this->nick << " " << dest->nick << " :";
1567 line = prefix.str();
1568 int namelen = strlen(ServerInstance->Config->ServerName) + 6;
1570 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1572 length = (pos == std::string::npos) ? cl.length() : pos;
1574 if (line.length() + namelen + length - start > 510)
1576 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1577 line = prefix.str();
1580 if(pos == std::string::npos)
1582 line.append(cl.substr(start, length - start));
1587 line.append(cl.substr(start, length - start + 1));
1593 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1598 * Sets a user's connection class.
1599 * If the class name is provided, it will be used. Otherwise, the class will be guessed using host/ip/ident/etc.
1600 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1601 * then their ip will be taken as 'priority' anyway, so for example,
1602 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1604 ConnectClass* User::SetClass(const std::string &explicit_name)
1606 ConnectClass *found = NULL;
1608 if (!IS_LOCAL(this))
1611 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Setting connect class for UID %s", this->uuid.c_str());
1613 if (!explicit_name.empty())
1615 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1617 ConnectClass* c = *i;
1619 if (explicit_name == c->name)
1621 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Explicitly set to %s", explicit_name.c_str());
1628 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1630 ConnectClass* c = *i;
1632 if (c->type == CC_ALLOW)
1634 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "ALLOW %s %d %s", c->host.c_str(), c->GetPort(), c->GetName().c_str());
1638 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "DENY %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
1641 /* check if host matches.. */
1642 if (c->GetHost().length() && !InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) &&
1643 !InspIRCd::MatchCIDR(this->host, c->GetHost(), NULL))
1645 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "No host match (for %s)", c->GetHost().c_str());
1650 * deny change if change will take class over the limit check it HERE, not after we found a matching class,
1651 * because we should attempt to find another class if this one doesn't match us. -- w00t
1653 if (c->limit && (c->RefCount >= c->limit))
1655 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "OOPS: Connect class limit (%lu) hit, denying", c->limit);
1659 /* if it requires a port ... */
1662 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Requires port (%d)", c->GetPort());
1664 /* and our port doesn't match, fail. */
1665 if (this->GetServerPort() != c->GetPort())
1667 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Port match failed (%d)", this->GetServerPort());
1672 /* we stop at the first class that meets ALL critera. */
1679 * Okay, assuming we found a class that matches.. switch us into that class, keeping refcounts up to date.
1683 /* only fiddle with refcounts if they are already in a class .. */
1686 if (found == this->MyClass) // no point changing this shit :P
1687 return this->MyClass;
1688 this->MyClass->RefCount--;
1689 ServerInstance->Logs->Log("USERS", DEBUG, "Untying user from connect class -- refcount: %lu", this->MyClass->RefCount);
1690 if (MyClass->RefCount == 0)
1694 this->MyClass = found;
1695 this->MyClass->RefCount++;
1696 ServerInstance->Logs->Log("USERS", DEBUG, "User tied to new class -- connect refcount now: %lu", this->MyClass->RefCount);
1699 return this->MyClass;
1702 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1703 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1704 * then their ip will be taken as 'priority' anyway, so for example,
1705 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1707 ConnectClass* User::GetClass()
1709 return this->MyClass;
1712 void User::PurgeEmptyChannels()
1714 std::vector<Channel*> to_delete;
1716 // firstly decrement the count on each channel
1717 for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
1720 c->RemoveAllPrefixes(this);
1721 if (c->DelUser(this) == 0)
1723 /* No users left in here, mark it for deletion */
1726 to_delete.push_back(c);
1730 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::PurgeEmptyChannels to_delete.push_back()");
1735 for (std::vector<Channel*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1737 Channel* thischan = *n;
1738 chan_hash::iterator i2 = ServerInstance->chanlist->find(thischan->name);
1739 if (i2 != ServerInstance->chanlist->end())
1741 ModResult MOD_RESULT;
1742 FIRST_MOD_RESULT(OnChannelPreDelete, MOD_RESULT, (i2->second));
1743 if (MOD_RESULT == MOD_RES_DENY)
1744 continue; // delete halted by module
1745 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1747 ServerInstance->chanlist->erase(i2);
1748 this->chans.erase(*n);
1755 void User::ShowMOTD()
1757 if (!ServerInstance->Config->MOTD.size())
1759 this->WriteNumeric(ERR_NOMOTD, "%s :Message of the day file is missing.",this->nick.c_str());
1762 this->WriteNumeric(RPL_MOTDSTART, "%s :%s message of the day", this->nick.c_str(), ServerInstance->Config->ServerName);
1764 for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
1765 this->WriteNumeric(RPL_MOTD, "%s :- %s",this->nick.c_str(),i->c_str());
1767 this->WriteNumeric(RPL_ENDOFMOTD, "%s :End of message of the day.", this->nick.c_str());
1770 void User::ShowRULES()
1772 if (!ServerInstance->Config->RULES.size())
1774 this->WriteNumeric(ERR_NORULES, "%s :RULES File is missing",this->nick.c_str());
1778 this->WriteNumeric(RPL_RULESTART, "%s :- %s Server Rules -",this->nick.c_str(),ServerInstance->Config->ServerName);
1780 for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
1781 this->WriteNumeric(RPL_RULES, "%s :- %s",this->nick.c_str(),i->c_str());
1783 this->WriteNumeric(RPL_RULESEND, "%s :End of RULES command.",this->nick.c_str());
1786 void User::IncreasePenalty(int increase)
1788 this->Penalty += increase;
1791 void User::DecreasePenalty(int decrease)
1793 this->Penalty -= decrease;
1796 void FakeUser::SetFakeServer(std::string name)
1799 this->server = nick.c_str();
1802 const std::string FakeUser::GetFullHost()
1804 if (*ServerInstance->Config->HideWhoisServer)
1805 return ServerInstance->Config->HideWhoisServer;
1809 const std::string FakeUser::GetFullRealHost()
1811 if (*ServerInstance->Config->HideWhoisServer)
1812 return ServerInstance->Config->HideWhoisServer;
1816 ConnectClass::ConnectClass(char t, const std::string& mask)
1817 : type(t), name("unnamed"), registration_timeout(0), host(mask),
1818 pingtime(0), pass(""), hash(""), softsendqmax(0), hardsendqmax(0),
1819 recvqmax(0), maxlocal(0), maxglobal(0), maxchans(0), port(0), limit(0),
1824 ConnectClass::ConnectClass(char t, const std::string& mask, const ConnectClass& parent)
1825 : type(t), name("unnamed"),
1826 registration_timeout(parent.registration_timeout), host(mask),
1827 pingtime(parent.pingtime), pass(parent.pass), hash(parent.hash),
1828 softsendqmax(parent.softsendqmax), hardsendqmax(parent.hardsendqmax),
1829 recvqmax(parent.recvqmax), maxlocal(parent.maxlocal),
1830 maxglobal(parent.maxglobal), maxchans(parent.maxchans),
1831 port(parent.port), limit(parent.limit), RefCount(1)
1835 void ConnectClass::Update(const ConnectClass* src)
1838 registration_timeout = src->registration_timeout;
1840 pingtime = src->pingtime;
1843 softsendqmax = src->softsendqmax;
1844 hardsendqmax = src->hardsendqmax;
1845 recvqmax = src->recvqmax;
1846 maxlocal = src->maxlocal;
1847 maxglobal = src->maxglobal;