#include "struct.h"
#include "support.h"
#include "sys.h"
+#include "uping.h"
#include "version.h"
#include <arpa/inet.h>
#include <sys/poll.h>
#endif /* USE_POLL */
-#ifndef IN_LOOPBACKNET
-#define IN_LOOPBACKNET 0x7f
-#endif
-
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff
#endif
struct Client* LocalClientArray[MAXCONNECTIONS];
int HighestFd = -1;
-static struct sockaddr_in virtualHost;
+struct sockaddr_in VirtualHost;
static char readbuf[SERVER_TCP_WINDOW];
-static int running_in_background;
/*
* report_error text constants
const char* const SETBUFS_ERROR_MSG = "error setting buffer size for %s: %s";
const char* const SOCKET_ERROR_MSG = "error creating socket for %s: %s";
-#ifdef VIRTUAL_HOST
-struct sockaddr_in vserv;
-#endif
#ifdef GODMODE
#ifndef NODNS
if (!errmsg)
errmsg = "Unknown error";
- if (!who)
+ if (EmptyString(who))
who = "unknown";
if (last_notice + 20 < CurrentTime) {
sendto_ops(text, who, errmsg);
last_notice = CurrentTime;
}
-
ircd_log(L_ERROR, text, who, errmsg);
-
- if (!running_in_background) {
- fprintf(stderr, text, who, errmsg);
- fprintf(stderr, "\n");
- }
errno = errtmp;
}
sendto_ops("Connect to %s failed: host lookup", aconf->name);
}
+/*
+ * close_connections - closes all connections
+ * close stderr if specified
+ */
+void close_connections(int close_stderr)
+{
+ int i;
+ close(0);
+ close(1);
+ if (close_stderr)
+ close(2);
+ for (i = 3; i < MAXCONNECTIONS; ++i)
+ close(i);
+}
+
+/*
+ * init_connection_limits - initialize process fd limit to
+ * MAXCONNECTIONS
+ */
+int init_connection_limits(void)
+{
+ int limit = os_set_fdlimit(MAXCONNECTIONS);
+ if (0 == limit)
+ return 1;
+ if (limit < 0) {
+ fprintf(stderr, "error setting max fd's to %d\n", limit);
+ }
+ else if (limit > 0) {
+ fprintf(stderr, "ircd fd table too big\nHard Limit: %d IRC max: %d\n",
+ limit, MAXCONNECTIONS);
+ fprintf(stderr, "set MAXCONNECTIONS to a smaller value");
+ }
+ return 0;
+}
/*
* connect_inet - set up address and port and make a connection
* explicitly bind it, it will default to IN_ADDR_ANY and we lose
* due to the other server not allowing our base IP --smg
*/
- if (bind(cptr->fd, (struct sockaddr*) &virtualHost, sizeof(virtualHost))) {
+ if (bind(cptr->fd, (struct sockaddr*) &VirtualHost, sizeof(VirtualHost))) {
report_error(BIND_ERROR_MSG, cptr->name, errno);
return 0;
}
return bytes_written;
}
-/*
- * init_sys
- */
-void init_sys(void)
-{
- int fd;
- int limit = os_set_fdlimit(MAXCONNECTIONS);
- if (limit < 0) {
- fprintf(stderr, "error setting max fd's to %d\n", limit);
- exit(2);
- }
- else if (limit > 0) {
- fprintf(stderr, "ircd fd table too big\nHard Limit: %d IRC max: %d\n",
- limit, MAXCONNECTIONS);
- fprintf(stderr, "set MAXCONNECTIONS to a smaller value");
- exit(2);
- }
-
- for (fd = 3; fd < MAXCONNECTIONS; ++fd)
- {
- close(fd);
- LocalClientArray[fd] = NULL;
- }
- LocalClientArray[2] = 0;
- LocalClientArray[1] = 0;
- LocalClientArray[0] = 0;
- close(1);
- close(0);
-
- if (bootopt & BOOT_TTY) {
- /* debugging is going to a tty */
- init_resolver();
- return;
- }
- if (!(bootopt & BOOT_DEBUG))
- close(2);
-
- if (fork())
- exit(0);
- running_in_background = 1;
-#ifdef TIOCNOTTY
- if ((fd = open("/dev/tty", O_RDWR)) > -1) {
- ioctl(fd, TIOCNOTTY, 0);
- close(fd);
- }
-#endif
- setsid();
- init_resolver();
-}
void release_dns_reply(struct Client* cptr)
{
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);
+ get_client_name(source, HIDE_IP));
exit_client(source, cptr, &me, "Oper Closing");
++count;
}
close(fd);
return;
}
- /*
- * XXX - do we really want to do this? is it needed?
- */
- os_disable_options(fd);
-
/*
* Add this local client to the IPcheck registry.
* If it is a connection to a user port and if the site has been throttled,
int read_message(time_t delay)
{
struct pollfd poll_fds[MAXCONNECTIONS + 1];
- struct Client* cptr;
- struct Listener* listener = 0;
- struct AuthRequest* auth = 0;
- struct AuthRequest* auth_next = 0;
- int nfds;
+ struct Client* cptr;
+ struct Listener* listener = 0;
+ struct AuthRequest* auth = 0;
+ struct AuthRequest* auth_next = 0;
+ struct UPing* uping = 0;
+ struct UPing* uping_next = 0;
time_t delay2 = delay;
+ int nfds;
int length;
int i;
int res = 0;
- int pfd_count = 0;
- struct pollfd* pfd = 0;
- struct pollfd* res_pfd = 0;
+ int pfd_count;
+ struct pollfd* pfd;
+ struct pollfd* res_pfd;
+ struct pollfd* uping_pfd;
int read_ready;
int write_ready;
pfd_count = 0;
pfd = poll_fds;
res_pfd = 0;
+ uping_pfd = 0;
pfd->fd = -1;
if (-1 < ResolverFileDescriptor) {
PFD_SETR(ResolverFileDescriptor);
res_pfd = pfd;
}
+ if (-1 < UPingFileDescriptor) {
+ PFD_SETR(UPingFileDescriptor);
+ uping_pfd = pfd;
+ }
+ /*
+ * add uping descriptors
+ */
+ for (uping = uping_begin(); uping; uping = uping_next) {
+ uping_next = uping->next;
+ if (uping->active) {
+ delay2 = 1;
+ if (uping->lastsent && CurrentTime > uping->timeout) {
+ uping_end(uping);
+ continue;
+ }
+ uping->index = pfd_count;
+ PFD_SETR(uping->fd);
+ }
+ }
/*
* add auth file descriptors
*/
CurrentTime = time(0);
}
+ if (uping_pfd && (uping_pfd->revents & (POLLREADFLAGS | POLLERRORS))) {
+ uping_echo();
+ --nfds;
+ }
+ /*
+ * check uping replies
+ */
+ for (uping = uping_begin(); uping; uping = uping_next) {
+ uping_next = uping->next;
+ if (uping->active) {
+ assert(-1 < uping->index);
+ if (poll_fds[uping->index].revents) {
+ uping_read(uping);
+ if (0 == --nfds)
+ break;
+ }
+ else if (CurrentTime > uping->lastsent) {
+ uping->lastsent = CurrentTime;
+ uping_send(uping);
+ }
+ }
+ }
+
if (res_pfd && (res_pfd->revents & (POLLREADFLAGS | POLLERRORS))) {
resolver_read();
--nfds;
}
if (write_ready) {
if (!on_write_unblocked(cptr) || IsDead(cptr)) {
- const char* msg = (cptr->error) ? strerror(cptr->error) : LastDeadComment(cptr);
+ const char* msg = (cptr->error) ? strerror(cptr->error) : cptr->info;
if (!msg)
msg = "Unknown error";
- exit_client(cptr, cptr, &me, (char*) msg);
+ exit_client(cptr, cptr, &me, msg);
continue;
}
}
flush_connections(poll_cptr[i]);
#endif
if (IsDead(cptr)) {
- const char* msg = (cptr->error) ? strerror(cptr->error) : LastDeadComment(cptr);
+ const char* msg = (cptr->error) ? strerror(cptr->error) : cptr->info;
if (!msg)
msg = "Unknown error";
exit_client(cptr, cptr, &me, (char*) 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;
{
struct Client* cptr;
struct Listener* listener;
+ struct AuthRequest* auth = 0;
+ struct AuthRequest* auth_next = 0;
+ struct UPing* uping;
+ struct UPing* uping_next;
int nfds;
struct timeval wait;
time_t delay2 = delay;
int res = 0;
int length;
int i;
- struct AuthRequest* auth = 0;
- struct AuthRequest* auth_next = 0;
int read_ready;
fd_set read_set;
fd_set write_set;
if (-1 < ResolverFileDescriptor)
FD_SET(ResolverFileDescriptor, &read_set);
+ if (-1 < UPingFileDescriptor)
+ FD_SET(UPingFileDescriptor, &read_set);
+ /*
+ * set up uping file descriptors
+ */
+ for (uping = uping_begin(); uping; uping = uping_next) {
+ uping_next = uping->next;
+ if (uping->active) {
+ delay2 = 1;
+ if (uping->lastsent && CurrentTime > uping->timeout) {
+ uping_end(uping);
+ continue;
+ }
+ assert(-1 < uping->fd);
+ FD_SET(uping->fd, &read_set);
+ }
+ }
/*
* set auth file descriptors
*/
CurrentTime = time(0);
}
- if (-1 < ResolverFileDescriptor &&
- FD_ISSET(ResolverFileDescriptor, &read_set)) {
+ if (-1 < UPingFileDescriptor && FD_ISSET(UPingFileDescriptor, &read_set)) {
+ uping_echo();
+ --nfds;
+ }
+ for (uping = uping_begin(); uping; uping = uping_next) {
+ uping_next = uping->next;
+ if (uping->active) {
+ assert(-1 < uping->fd);
+ if (FD_ISSET(uping->fd, &read_set)) {
+ uping_read(uping);
+ if (0 == --nfds)
+ break;
+ }
+ else if (CurrentTime > uping->lastsent) {
+ uping->lastsent = CurrentTime;
+ uping_send(uping);
+ }
+ }
+ }
+ if (-1 < ResolverFileDescriptor && FD_ISSET(ResolverFileDescriptor, &read_set)) {
resolver_read();
--nfds;
}
if (FD_ISSET(i, &write_set)) {
--nfds;
if (!on_write_unblocked(cptr) || IsDead(cptr)) {
- const char* msg = (cptr->error) ? strerror(cptr->error) : LastDeadComment(cptr);
+ const char* msg = (cptr->error) ? strerror(cptr->error) : cptr->info;
if (!msg)
msg = "Unknown error";
if (FD_ISSET(i, &read_set))
flush_connections(LocalClientArray[i]);
#endif
if (IsDead(cptr)) {
- const char* msg = (cptr->error) ? strerror(cptr->error) : LastDeadComment(cptr);
+ const char* msg = (cptr->error) ? strerror(cptr->error) : cptr->info;
if (!msg)
msg = "Unknown error";
exit_client(cptr, cptr, &me, 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 != conf);
- memset(&virtualHost, 0, sizeof(virtualHost));
- virtualHost.sin_family = AF_INET;
- virtualHost.sin_addr.s_addr = INADDR_ANY;
+ memset(&VirtualHost, 0, sizeof(VirtualHost));
+ VirtualHost.sin_family = AF_INET;
+ VirtualHost.sin_addr.s_addr = INADDR_ANY;
if (EmptyString(conf->passwd) || 0 == strcmp(conf->passwd, "*"))
return;
- virtualHost.sin_addr.s_addr = inet_addr(conf->passwd);
+ VirtualHost.sin_addr.s_addr = inet_addr(conf->passwd);
- if (INADDR_NONE == virtualHost.sin_addr.s_addr)
- virtualHost.sin_addr.s_addr = INADDR_ANY;
+ if (INADDR_NONE == VirtualHost.sin_addr.s_addr)
+ VirtualHost.sin_addr.s_addr = INADDR_ANY;
}
/*