X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/6227ed01af8a2e5d805bef74a91152d26fb5add7..1d39b466d4ddd974674c9397589d45935c746ed0:/src/packet.c diff --git a/src/packet.c b/src/packet.c index f1d87cd..1434f2c 100644 --- a/src/packet.c +++ b/src/packet.c @@ -165,63 +165,63 @@ flood_endgrace(struct Client *client_p) client_p->localClient->sent_parsed = 0; } -/* - * flood_recalc - * - * recalculate the number of allowed flood lines. this should be called - * once a second on any given client. We then attempt to flush some data. - */ -void -flood_recalc(void *unused) -{ - rb_dlink_node *ptr, *next; - struct Client *client_p; - - RB_DLINK_FOREACH_SAFE(ptr, next, lclient_list.head) - { - client_p = ptr->data; - - if(unlikely(IsMe(client_p))) - continue; - - if(unlikely(client_p->localClient == NULL)) - continue; - - if(IsFloodDone(client_p)) - client_p->localClient->sent_parsed -= 2; - else - client_p->localClient->sent_parsed = 0; - - if(client_p->localClient->sent_parsed < 0) - client_p->localClient->sent_parsed = 0; - - if(--client_p->localClient->actually_read < 0) - client_p->localClient->actually_read = 0; - - parse_client_queued(client_p); - - if(unlikely(IsAnyDead(client_p))) - continue; - - } - - RB_DLINK_FOREACH_SAFE(ptr, next, unknown_list.head) - { - client_p = ptr->data; - - if(client_p->localClient == NULL) - continue; - - client_p->localClient->sent_parsed--; - - if(client_p->localClient->sent_parsed < 0) - client_p->localClient->sent_parsed = 0; - - if(--client_p->localClient->actually_read < 0) - client_p->localClient->actually_read = 0; - - parse_client_queued(client_p); - } +/* + * flood_recalc + * + * recalculate the number of allowed flood lines. this should be called + * once a second on any given client. We then attempt to flush some data. + */ +void +flood_recalc(void *unused) +{ + rb_dlink_node *ptr, *next; + struct Client *client_p; + + RB_DLINK_FOREACH_SAFE(ptr, next, lclient_list.head) + { + client_p = ptr->data; + + if(unlikely(IsMe(client_p))) + continue; + + if(unlikely(client_p->localClient == NULL)) + continue; + + if(IsFloodDone(client_p)) + client_p->localClient->sent_parsed -= 2; + else + client_p->localClient->sent_parsed = 0; + + if(client_p->localClient->sent_parsed < 0) + client_p->localClient->sent_parsed = 0; + + if(--client_p->localClient->actually_read < 0) + client_p->localClient->actually_read = 0; + + parse_client_queued(client_p); + + if(unlikely(IsAnyDead(client_p))) + continue; + + } + + RB_DLINK_FOREACH_SAFE(ptr, next, unknown_list.head) + { + client_p = ptr->data; + + if(client_p->localClient == NULL) + continue; + + client_p->localClient->sent_parsed--; + + if(client_p->localClient->sent_parsed < 0) + client_p->localClient->sent_parsed = 0; + + if(--client_p->localClient->actually_read < 0) + client_p->localClient->actually_read = 0; + + parse_client_queued(client_p); + } } /* @@ -229,7 +229,7 @@ flood_recalc(void *unused) * link and process it. */ void -read_ctrl_packet(int fd, void *data) +read_ctrl_packet(rb_fde_t *F, void *data) { struct Client *server = data; struct LocalUser *lserver = server->localClient; @@ -255,11 +255,11 @@ read_ctrl_packet(int fd, void *data) reply->readdata = 0; reply->data = NULL; - length = read(fd, tmp, 1); + length = rb_read(F, tmp, 1); if(length <= 0) { - if((length == -1) && ignoreErrno(errno)) + if((length == -1) && rb_ignore_errno(errno)) goto nodata; error_exit_client(server, length); return; @@ -281,10 +281,10 @@ read_ctrl_packet(int fd, void *data) if((replydef->flags & SLINKRPL_FLAG_DATA) && (reply->gotdatalen < 2)) { /* we need a datalen u16 which we don't have yet... */ - length = read(fd, len, (2 - reply->gotdatalen)); + length = rb_read(F, len, (2 - reply->gotdatalen)); if(length <= 0) { - if((length == -1) && ignoreErrno(errno)) + if((length == -1) && rb_ignore_errno(errno)) goto nodata; error_exit_client(server, length); return; @@ -311,11 +311,11 @@ read_ctrl_packet(int fd, void *data) if(reply->readdata < reply->datalen) /* try to get any remaining data */ { - length = read(fd, (reply->data + reply->readdata), + length = rb_read(F, (reply->data + reply->readdata), (reply->datalen - reply->readdata)); if(length <= 0) { - if((length == -1) && ignoreErrno(errno)) + if((length == -1) && rb_ignore_errno(errno)) goto nodata; error_exit_client(server, length); return; @@ -347,14 +347,14 @@ read_ctrl_packet(int fd, void *data) nodata: /* If we get here, we need to register for another COMM_SELECT_READ */ - rb_setselect(fd, FDLIST_SERVER, COMM_SELECT_READ, read_ctrl_packet, server, 0); + rb_setselect(F, RB_SELECT_READ, read_ctrl_packet, server); } /* * read_packet - Read a 'packet' of data from a connection and process it. */ void -read_packet(int fd, void *data) +read_packet(rb_fde_t * F, void *data) { struct Client *client_p = data; struct LocalUser *lclient_p = client_p->localClient; @@ -365,81 +365,83 @@ read_packet(int fd, void *data) #ifdef USE_IODEBUG_HOOKS hook_data_int hdata; #endif - if(IsAnyDead(client_p)) - return; - /* - * Read some data. We *used to* do anti-flood protection here, but - * I personally think it makes the code too hairy to make sane. - * -- adrian - */ - length = client_p->localClient->F->read_impl(client_p->localClient->F, readBuf, READBUF_SIZE); - - if(length <= 0) + while(1) { - if((length == -1) && ignoreErrno(errno)) + if(IsAnyDead(client_p)) + return; + + /* + * Read some data. We *used to* do anti-flood protection here, but + * I personally think it makes the code too hairy to make sane. + * -- adrian + */ + length = rb_read(client_p->localClient->F, readBuf, READBUF_SIZE); + + if(length < 0) { - rb_setselect(client_p->localClient->F->fd, FDLIST_IDLECLIENT, - COMM_SELECT_READ, read_packet, client_p, 0); + if(rb_ignore_errno(errno)) + rb_setselect(client_p->localClient->F, + RB_SELECT_READ, read_packet, client_p); + else + error_exit_client(client_p, length); + return; + } + else if(length == 0) + { + error_exit_client(client_p, length); return; } - error_exit_client(client_p, length); - return; - } #ifdef USE_IODEBUG_HOOKS - hdata.client = client_p; - hdata.arg1 = readBuf; - hdata.arg2 = length; - call_hook(h_iorecv_id, &hdata); + hdata.client = client_p; + hdata.arg1 = readBuf; + hdata.arg2 = length; + call_hook(h_iorecv_id, &hdata); #endif - if(client_p->localClient->lasttime < rb_current_time()) - client_p->localClient->lasttime = rb_current_time(); - client_p->flags &= ~FLAGS_PINGSENT; + if(client_p->localClient->lasttime < rb_current_time()) + client_p->localClient->lasttime = rb_current_time(); + client_p->flags &= ~FLAGS_PINGSENT; - /* - * Before we even think of parsing what we just read, stick - * it on the end of the receive queue and do it when its - * turn comes around. - */ - if(IsHandshake(client_p) || IsUnknown(client_p)) - binary = 1; + /* + * Before we even think of parsing what we just read, stick + * it on the end of the receive queue and do it when its + * turn comes around. + */ + if(IsHandshake(client_p) || IsUnknown(client_p)) + binary = 1; - lbuf_len = rb_linebuf_parse(&client_p->localClient->buf_recvq, readBuf, length, binary); + lbuf_len = rb_linebuf_parse(&client_p->localClient->buf_recvq, readBuf, length, binary); - lclient_p->actually_read += lbuf_len; + lclient_p->actually_read += lbuf_len; - if(IsAnyDead(client_p)) - return; - - /* Attempt to parse what we have */ - parse_client_queued(client_p); + if(IsAnyDead(client_p)) + return; + + /* Attempt to parse what we have */ + parse_client_queued(client_p); - if(IsAnyDead(client_p)) - return; - - /* Check to make sure we're not flooding */ - if(!IsAnyServer(client_p) && - (rb_linebuf_alloclen(&client_p->localClient->buf_recvq) > ConfigFileEntry.client_flood)) - { - if(!(ConfigFileEntry.no_oper_flood && IsOper(client_p))) - { - exit_client(client_p, client_p, client_p, "Excess Flood"); + if(IsAnyDead(client_p)) return; + + /* Check to make sure we're not flooding */ + if(!IsAnyServer(client_p) && + (rb_linebuf_alloclen(&client_p->localClient->buf_recvq) > ConfigFileEntry.client_flood)) + { + if(!(ConfigFileEntry.no_oper_flood && IsOper(client_p))) + { + exit_client(client_p, client_p, client_p, "Excess Flood"); + return; + } } - } - /* If we get here, we need to register for another COMM_SELECT_READ */ - if(PARSE_AS_SERVER(client_p)) - { - rb_setselect(client_p->localClient->F->fd, FDLIST_SERVER, COMM_SELECT_READ, - read_packet, client_p, 0); - } - else - { - rb_setselect(client_p->localClient->F->fd, FDLIST_IDLECLIENT, - COMM_SELECT_READ, read_packet, client_p, 0); + /* bail if short read */ + if(length < READBUF_SIZE) + { + rb_setselect(client_p->localClient->F, RB_SELECT_READ, read_packet, client_p); + return; + } } }