-
-static void
-accept_connection(int pfd, void *data)
-{
- static time_t last_oper_notice = 0;
- struct irc_sockaddr_storage sai;
- socklen_t addrlen = sizeof(sai);
- int fd;
- listener_t *listener = data;
- struct ConfItem *aconf;
- char buf[BUFSIZE];
-
- s_assert(listener != NULL);
- if(listener == NULL)
- return;
- /*
- * There may be many reasons for error return, but
- * in otherwise correctly working environment the
- * probable cause is running out of file descriptors
- * (EMFILE, ENFILE or others?). The man pages for
- * accept don't seem to list these as possible,
- * although it's obvious that it may happen here.
- * Thus no specific errors are tested at this
- * point, just assume that connections cannot
- * be accepted until some old is closed first.
- */
-
- fd = comm_accept(listener->fd, (struct sockaddr *)&sai, &addrlen);
- if(fd < 0)
- {
- /* Re-register a new IO request for the next accept .. */
- comm_setselect(listener->fd, FDLIST_SERVICE,
- COMM_SELECT_READ, accept_connection, listener, 0);
- return;
- }
-
- /* This needs to be done here, otherwise we break dlines */
- mangle_mapped_sockaddr((struct sockaddr *)&sai);
-
- /*
- * check for connection limit
- * TBD: this is stupid... either we have a socket or we don't. -nenolod
- */
- if((comm_get_maxconnections() - 10) < fd)
- {
- ++ServerStats->is_ref;
- /*
- * slow down the whining to opers bit
- */
- if((last_oper_notice + 20) <= CurrentTime)
- {
- sendto_realops_snomask(SNO_GENERAL, L_ALL,
- "All connections in use. (%s)",
- get_listener_name(listener));
- last_oper_notice = CurrentTime;
- }
-
- write(fd, "ERROR :All connections in use\r\n", 32);
- comm_close(fd);
- /* Re-register a new IO request for the next accept .. */
- comm_setselect(listener->fd, FDLIST_SERVICE,
- COMM_SELECT_READ, accept_connection, listener, 0);
- return;
- }
-
- /* Do an initial check we aren't connecting too fast or with too many
- * from this IP... */
- aconf = find_dline((struct sockaddr *) &sai, sai.ss_family);
- /* check it wasn't an exempt */
- if (aconf != NULL && (aconf->status & CONF_EXEMPTDLINE) == 0)
- {
- ServerStats->is_ref++;
-
- if(ConfigFileEntry.dline_with_reason)
- {
- if (ircsnprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", aconf->passwd) >= (sizeof(buf)-1))
- {
- buf[sizeof(buf) - 3] = '\r';
- buf[sizeof(buf) - 2] = '\n';
- buf[sizeof(buf) - 1] = '\0';
- }
- }
- else
- ircsprintf(buf, "ERROR :You have been D-lined.\r\n");
-
- write(fd, buf, strlen(buf));
- comm_close(fd);
-
- /* Re-register a new IO request for the next accept .. */
- comm_setselect(listener->fd, FDLIST_SERVICE,
- COMM_SELECT_READ, accept_connection, listener, 0);
- return;
- }
-
- ServerStats->is_ac++;
- add_connection(listener, fd, (struct sockaddr *)&sai, aconf ? 1 : 0);
-
- /* Re-register a new IO request for the next accept .. */
- comm_setselect(listener->fd, FDLIST_SERVICE, COMM_SELECT_READ,
- accept_connection, listener, 0);
+static int\r
+accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data)\r
+{\r
+ struct Listener *listener = (struct Listener *)data;\r
+ char buf[BUFSIZE];\r
+ struct ConfItem *aconf;\r
+ static time_t last_oper_notice = 0;\r
+\r
+ if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus */\r
+ {\r
+ ++ServerStats->is_ref;\r
+ /*\r
+ * slow down the whining to opers bit\r
+ */\r
+ if((last_oper_notice + 20) <= rb_current_time())\r
+ {\r
+ sendto_realops_flags(SNO_GENERAL, L_ALL,\r
+ "All connections in use. (%s)",\r
+ get_listener_name(listener));\r
+ last_oper_notice = rb_current_time();\r
+ }\r
+ \r
+ rb_write(F, "ERROR :All connections in use\r\n", 32);\r
+ rb_close(F);\r
+ /* Re-register a new IO request for the next accept .. */\r
+ return 0;\r
+ }\r
+\r
+ aconf = find_dline(addr, addr.ss_family);\r
+ if(aconf != NULL && (aconf->status & CONF_EXEMPTDLINE))\r
+ return 1;\r
+ \r
+ /* Do an initial check we aren't connecting too fast or with too many\r
+ * from this IP... */\r
+ if(aconf != NULL)\r
+ {\r
+ ServerStats->is_ref++;\r
+ \r
+ if(ConfigFileEntry.dline_with_reason)\r
+ {\r
+ if (rb_snprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", aconf->passwd) >= (int)(sizeof(buf)-1))\r
+ {\r
+ buf[sizeof(buf) - 3] = '\r';\r
+ buf[sizeof(buf) - 2] = '\n';\r
+ buf[sizeof(buf) - 1] = '\0';\r
+ }\r
+ }\r
+ else\r
+ strcpy(buf, "ERROR :You have been D-lined.\r\n");\r
+ \r
+ rb_write(F, buf, strlen(buf));\r
+ rb_close(F);\r
+ return 0;\r
+ }\r
+\r
+ return 1;\r
+}\r
+\r
+static void\r
+accept_callback(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t addrlen, void *data)\r
+{\r
+ struct Listener *listener = data;\r
+ struct rb_sockaddr_storage lip;\r
+ unsigned int locallen = sizeof(struct rb_sockaddr_storage);\r
+ \r
+ ServerStats->is_ac++;\r
+\r
+ if(getsockname(rb_get_fd(F), (struct sockaddr *) &lip, &locallen) < 0)\r
+ {\r
+ /* this shouldn't fail so... */\r
+ /* XXX add logging of this */\r
+ rb_close(F);\r
+ }\r
+ \r
+ add_connection(listener, F, addr, (struct sockaddr *)&lip, 1);\r