#include "hash.h"
#include "ircd_log.h"
#include "ircd_osdep.h"
+#include "ircd_reply.h"
#include "ircd_string.h"
#include "ircd.h"
#include "list.h"
#include "listener.h"
+#include "msg.h"
#include "numeric.h"
#include "numnicks.h"
#include "packet.h"
/*
* pace error messages so opers don't get flooded by transients
*/
- sendto_ops(text, who, errmsg);
+ sendto_opmask_butone(0, SNO_OLDSNO, text, who, errmsg);
last_notice = CurrentTime;
}
ircd_log(L_ERROR, text, who, errmsg);
connect_server(aconf, 0, reply);
}
else
- sendto_ops("Connect to %s failed: host lookup", aconf->name);
+ sendto_opmask_butone(0, SNO_OLDSNO, "Connect to %s failed: host lookup",
+ aconf->name);
}
/*
const char* msg = strerror(cptr->error);
if (!msg)
msg = "Unknown error";
- sendto_ops("Connection failed to %s: %s", cptr->name, msg);
+ sendto_opmask_butone(0, SNO_OLDSNO, "Connection failed to %s: %s",
+ cptr->name, msg);
return 0;
}
if (!(aconf = find_conf_byname(cptr->confs, cptr->name, CONF_SERVER))) {
- sendto_ops("Lost Server Line for %s", cptr->name);
+ sendto_opmask_butone(0, SNO_OLDSNO, "Lost Server Line for %s", cptr->name);
return 0;
}
+
if (!EmptyString(aconf->passwd))
- sendto_one(cptr, "PASS :%s", aconf->passwd);
+ sendrawto_one(cptr, MSG_PASS " :%s", aconf->passwd);
#if 0
/* dead code, already done in connect_server */
*/
cptr->lasttime = CurrentTime;
cptr->flags |= FLAGS_PINGSENT;
- sendto_one(cptr, "SERVER %s 1 " TIME_T_FMT " " TIME_T_FMT " J%s %s%s :%s",
- me.name, me.serv->timestamp, newts, MAJOR_PROTOCOL,
- NumServCap(&me), me.info);
+
+ sendrawto_one(cptr, MSG_SERVER " %s 1 %Tu %Tu J%s %s%s :%s",
+ me.name, me.serv->timestamp, newts, MAJOR_PROTOCOL,
+ NumServCap(&me), me.info);
return (IsDead(cptr)) ? 0 : 1;
}
if (-1 < cptr->fd) {
flush_connections(cptr);
+ ip_registry_local_disconnect(cptr);
LocalClientArray[cptr->fd] = 0;
close(cptr->fd);
cptr->fd = -1;
for (i = HighestFd; i > 0; --i) {
if ((cptr = LocalClientArray[i]) && !IsRegistered(cptr)) {
- sendto_one(source, rpl_str(RPL_CLOSING), me.name, source->name,
- get_client_name(source, HIDE_IP), cptr->status);
+ send_reply(source, RPL_CLOSING, get_client_name(source, HIDE_IP));
exit_client(source, cptr, &me, "Oper Closing");
++count;
}
return count;
}
-/*
+/*----------------------------------------------------------------------------
+ * add_connection
+ *
* Creates a client which has just connected to us on the given fd.
* The sockhost field is initialized with the ip# of the host.
* The client is not added to the linked list of clients, it is
* passed off to the auth handler for dns and ident queries.
- */
-void add_connection(struct Listener* listener, int fd)
-{
+ *--------------------------------------------------------------------------*/
+void add_connection(struct Listener* listener, int fd) {
struct sockaddr_in addr;
- struct Client* new_client;
+ struct Client *new_client;
time_t next_target = 0;
+
const char* const throttle_message =
- "ERROR: Your host is trying to (re)connect too fast -- throttled\r\n";
+ "ERROR :Your host is trying to (re)connect too fast -- throttled\r\n";
/* 12345678901234567890123456789012345679012345678901234567890123456 */
assert(0 != listener);
+
+
/*
- * Removed preliminary access check. Full check is performed in
- * m_server and m_user instead. Also connection time out help to
- * get rid of unwanted connections.
+ * Removed preliminary access check. Full check is performed in m_server and
+ * m_user instead. Also connection time out help to get rid of unwanted
+ * connections.
*/
if (!os_get_peername(fd, &addr) || !os_set_nonblocking(fd)) {
++ServerStats->is_ref;
close(fd);
return;
}
+
/*
* Add this local client to the IPcheck registry.
- * If it is a connection to a user port and if the site has been throttled,
- * reject the user.
+ *
+ * If they're throttled, murder them, but tell them why first.
*/
- if (!IPcheck_local_connect(addr.sin_addr, &next_target) && !listener->server) {
- ++ServerStats->is_ref;
- /*
- * strlen(throttle_message) == 66
- */
- send(fd, throttle_message, 66, 0);
- close(fd);
- return;
+ if ( !ip_registry_check_local(addr.sin_addr.s_addr,&next_target) ) {
+ ++ServerStats->is_ref;
+ write(fd,throttle_message,strlen(throttle_message));
+ close(fd);
+ return;
}
- new_client = make_client(NULL,
- (listener->server) ? STAT_UNKNOWN_SERVER : STAT_UNKNOWN_USER);
+ new_client = make_client(0, ((listener->server) ?
+ STAT_UNKNOWN_SERVER : STAT_UNKNOWN_USER));
+
/*
- * Copy ascii address to 'sockhost' just in case. Then we
- * have something valid to put into error messages...
+ * Copy ascii address to 'sockhost' just in case. Then we have something
+ * valid to put into error messages...
*/
ircd_ntoa_r(new_client->sock_ip, (const char*) &addr.sin_addr);
strcpy(new_client->sockhost, new_client->sock_ip);
new_client->nexttarget = next_target;
new_client->fd = fd;
-
- if (!listener->server)
- SetIPChecked(new_client);
new_client->listener = listener;
++listener->ref_count;
Count_newunknown(UserStats);
- /*
- * if we've made it this far we can put the client on the auth query pile
- */
+ ip_registry_connect_succeeded(new_client);
+ /* if we've made it this far we can put the client on the auth query pile */
start_auth(new_client);
}
+
/*
* read_packet
*
const char* msg = (cptr->error) ? strerror(cptr->error) : "EOF from client";
if (!msg)
msg = "Unknown error";
- exit_client_msg(cptr, cptr, &me, "Read error to %s: %s",
- get_client_name(cptr, HIDE_IP), msg);
+ exit_client_msg(cptr, cptr, &me, "Read error: %s",
+ msg);
}
}
return 0;
if (CPTR_KILLED == (length = read_packet(cptr, read_ready)))
continue;
}
-#if 0
- /* Bullshit, why would we want to flush sockets while using non-blocking?
- * This uses > 4% cpu! --Run */
- if (length > 0)
- flush_connections(LocalClientArray[i]);
-#endif
if (IsDead(cptr)) {
const char* msg = (cptr->error) ? strerror(cptr->error) : cptr->info;
if (!msg)
const char* msg = (cptr->error) ? strerror(cptr->error) : "EOF from client";
if (!msg)
msg = "Unknown error";
- exit_client_msg(cptr, cptr, &me, "Read error to %s: %s",
- get_client_name(cptr, HIDE_IP), msg);
+ exit_client_msg(cptr, cptr, &me, "Read error: %s",
+ msg);
}
}
return 0;
assert(0 != aconf);
if (aconf->dns_pending) {
- sendto_ops("Server %s connect DNS pending");
+ sendto_opmask_butone(0, SNO_OLDSNO, "Server %s connect DNS pending",
+ aconf->name);
return 0;
}
Debug((DEBUG_NOTICE, "Connect to %s[@%s]", aconf->name,
if ((cptr = FindClient(aconf->name))) {
if (IsServer(cptr) || IsMe(cptr)) {
- sendto_ops("Server %s already present from %s",
- aconf->name, cptr->from->name);
+ sendto_opmask_butone(0, SNO_OLDSNO, "Server %s already present from %s",
+ aconf->name, cptr->from->name);
if (by && IsUser(by) && !MyUser(by)) {
- sendto_one(by, "%s NOTICE %s%s :Server %s already present from %s",
- NumServ(&me), NumNick(by), aconf->name, cptr->from->name);
+ sendcmdto_one(&me, CMD_NOTICE, by, "%C :Server %s already present "
+ "from %s", by, aconf->name, cptr->from->name);
}
return 0;
}
else if (IsHandshake(cptr) || IsConnecting(cptr)) {
if (by && IsUser(by)) {
- if (MyUser(by))
- sendto_one(by, ":%s NOTICE %s :Connection to %s already in progress",
- me.name, by->name, cptr->name);
- else
- sendto_one(by, "%s NOTICE %s%s :Connection to %s already in progress",
- NumServ(&me), NumNick(by), cptr->name);
+ sendcmdto_one(&me, CMD_NOTICE, by, "%C :Connection to %s already in "
+ "progress", by, cptr->name);
}
return 0;
}
attach_confs_byhost(cptr, aconf->host, CONF_SERVER);
if (!find_conf_byhost(cptr->confs, aconf->host, CONF_SERVER)) {
- sendto_ops("Host %s is not enabled for connecting: no C-line", aconf->name);
+ sendto_opmask_butone(0, SNO_OLDSNO, "Host %s is not enabled for "
+ "connecting: no C-line", aconf->name);
if (by && IsUser(by) && !MyUser(by)) {
- sendto_one(by, "%s NOTICE %s%s :Connect to host %s failed: no C-line",
- NumServ(&me), NumNick(by), aconf->name);
+ sendcmdto_one(&me, CMD_NOTICE, by, "%C :Connect to host %s failed: no "
+ "C-line", by, aconf->name);
}
det_confs_butmask(cptr, 0);
free_client(cptr);
*/
if (!connect_inet(aconf, cptr)) {
if (by && IsUser(by) && !MyUser(by)) {
- sendto_one(by, "%s NOTICE %s%s :Couldn't connect to %s",
- NumServ(&me), NumNick(by), cptr->name);
+ sendcmdto_one(&me, CMD_NOTICE, by, "%C :Couldn't connect to %s", by,
+ cptr->name);
}
det_confs_butmask(cptr, 0);
free_client(cptr);
if (cptr->fd > HighestFd)
HighestFd = cptr->fd;
+
+
LocalClientArray[cptr->fd] = cptr;
Count_newunknown(UserStats);
+ ip_registry_add_local(aconf->ipnum.s_addr);
+ /* Actually we lie, the connect hasn't succeeded yet, but we have a valid
+ * cptr, so we register it now.
+ * Maybe these two calls should be merged.
+ */
+ ip_registry_connect_succeeded(cptr);
add_client_to_list(cptr);
hAddClient(cptr);
nextping = CurrentTime;