Blob


1 /*
2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #include <sys/mman.h>
18 #include <sys/stat.h>
20 #include <netdb.h>
22 #include <assert.h>
23 #include <errno.h>
24 #include <fcntl.h>
25 #include <fnmatch.h>
26 #include <limits.h>
27 #include <string.h>
29 #include "gmid.h"
31 int connected_clients;
33 const char *
34 vhost_lang(struct vhost *v, const char *path)
35 {
36 struct location *loc;
38 if (v == NULL || path == NULL)
39 return NULL;
41 for (loc = &v->locations[1]; loc->match != NULL; ++loc) {
42 if (!fnmatch(loc->match, path, 0)) {
43 if (loc->lang != NULL)
44 return loc->lang;
45 }
46 }
48 return v->locations[0].lang;
49 }
51 const char *
52 vhost_default_mime(struct vhost *v, const char *path)
53 {
54 struct location *loc;
55 const char *default_mime = "application/octet-stream";
57 if (v == NULL || path == NULL)
58 return default_mime;
60 for (loc = &v->locations[1]; loc->match != NULL; ++loc) {
61 if (!fnmatch(loc->match, path, 0)) {
62 if (loc->default_mime != NULL)
63 return loc->default_mime;
64 }
65 }
67 if (v->locations[0].default_mime != NULL)
68 return v->locations[0].default_mime;
69 return default_mime;
70 }
72 const char *
73 vhost_index(struct vhost *v, const char *path)
74 {
75 struct location *loc;
76 const char *index = "index.gmi";
78 if (v == NULL || path == NULL)
79 return index;
81 for (loc = &v->locations[1]; loc->match != NULL; ++loc) {
82 if (!fnmatch(loc->match, path, 0)) {
83 if (loc->index != NULL)
84 return loc->index;
85 }
86 }
88 if (v->locations[0].index != NULL)
89 return v->locations[0].index;
90 return index;
91 }
93 int
94 vhost_auto_index(struct vhost *v, const char *path)
95 {
96 struct location *loc;
98 if (v == NULL || path == NULL)
99 return 0;
101 for (loc = v->locations; loc->match != NULL; ++loc) {
102 if (!fnmatch(loc->match, path, 0)) {
103 if (loc->auto_index != 0)
104 return loc->auto_index == 1;
108 return v->locations[0].auto_index == 1;
111 int
112 check_path(struct client *c, const char *path, int *fd)
114 struct stat sb;
115 const char *p;
116 int flags;
118 assert(path != NULL);
120 if (*path == '\0')
121 p = ".";
122 else if (*path == '/')
123 /* in send_dir we add an initial / (to be
124 * redirect-friendly), but here we want to skip it */
125 p = path+1;
126 else
127 p = path;
129 flags = O_RDONLY | O_NOFOLLOW;
131 if (*fd == -1 && (*fd = openat(c->host->dirfd, p, flags)) == -1)
132 return FILE_MISSING;
134 if (fstat(*fd, &sb) == -1) {
135 LOGN(c, "failed stat for %s: %s", path, strerror(errno));
136 return FILE_MISSING;
139 if (S_ISDIR(sb.st_mode))
140 return FILE_DIRECTORY;
142 if (sb.st_mode & S_IXUSR)
143 return FILE_EXECUTABLE;
145 return FILE_EXISTS;
148 void
149 open_file(struct pollfd *fds, struct client *c)
151 switch (check_path(c, c->iri.path, &c->fd)) {
152 case FILE_EXECUTABLE:
153 if (starts_with(c->iri.path, c->host->cgi)) {
154 start_cgi(c->iri.path, "", fds, c);
155 return;
158 /* fallthrough */
160 case FILE_EXISTS:
161 load_file(fds, c);
162 return;
164 case FILE_DIRECTORY:
165 open_dir(fds, c);
166 return;
168 case FILE_MISSING:
169 if (c->host->cgi != NULL && starts_with(c->iri.path, c->host->cgi)) {
170 check_for_cgi(fds, c);
171 return;
173 start_reply(fds, c, NOT_FOUND, "not found");
174 return;
176 default:
177 /* unreachable */
178 abort();
182 void
183 load_file(struct pollfd *fds, struct client *c)
185 if ((c->len = filesize(c->fd)) == -1) {
186 LOGE(c, "failed to get file size for %s", c->iri.path);
187 start_reply(fds, c, TEMP_FAILURE, "internal server error");
188 return;
191 if ((c->buf = mmap(NULL, c->len, PROT_READ, MAP_PRIVATE,
192 c->fd, 0)) == MAP_FAILED) {
193 LOGW(c, "mmap: %s: %s", c->iri.path, strerror(errno));
194 start_reply(fds, c, TEMP_FAILURE, "internal server error");
195 return;
197 c->i = c->buf;
198 c->next = send_file;
199 start_reply(fds, c, SUCCESS, mime(c->host, c->iri.path));
202 /*
203 * the inverse of this algorithm, i.e. starting from the start of the
204 * path + strlen(cgi), and checking if each component, should be
205 * faster. But it's tedious to write. This does the opposite: starts
206 * from the end and strip one component at a time, until either an
207 * executable is found or we emptied the path.
208 */
209 void
210 check_for_cgi(struct pollfd *fds, struct client *c)
212 char path[PATH_MAX];
213 char *end;
215 strlcpy(path, c->iri.path, sizeof(path));
216 end = strchr(path, '\0');
218 /* NB: assume CGI is enabled and path matches cgi */
220 while (end > path) {
221 /* go up one level. UNIX paths are simple and POSIX
222 * dirname, with its ambiguities on if the given path
223 * is changed or not, gives me headaches. */
224 while (*end != '/')
225 end--;
226 *end = '\0';
228 switch (check_path(c, path, &c->fd)) {
229 case FILE_EXECUTABLE:
230 start_cgi(path, end+1, fds, c);
231 return;
232 case FILE_MISSING:
233 break;
234 default:
235 goto err;
238 *end = '/';
239 end--;
242 err:
243 start_reply(fds, c, NOT_FOUND, "not found");
244 return;
247 void
248 mark_nonblock(int fd)
250 int flags;
252 if ((flags = fcntl(fd, F_GETFL)) == -1)
253 fatal("fcntl(F_GETFL): %s", strerror(errno));
254 if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
255 fatal("fcntl(F_SETFL): %s", strerror(errno));
258 void
259 handle_handshake(struct pollfd *fds, struct client *c)
261 struct vhost *h;
262 const char *servname;
263 const char *parse_err = "unknown error";
265 switch (tls_handshake(c->ctx)) {
266 case 0: /* success */
267 case -1: /* already handshaked */
268 break;
269 case TLS_WANT_POLLIN:
270 fds->events = POLLIN;
271 return;
272 case TLS_WANT_POLLOUT:
273 fds->events = POLLOUT;
274 return;
275 default:
276 /* unreachable */
277 abort();
280 servname = tls_conn_servername(c->ctx);
281 if (!puny_decode(servname, c->domain, sizeof(c->domain), &parse_err)) {
282 LOGI(c, "%s", parse_err);
283 goto err;
286 for (h = hosts; h->domain != NULL; ++h) {
287 if (!fnmatch(h->domain, c->domain, 0))
288 break;
291 /* LOGD(c, "handshake: SNI: \"%s\"; decoded: \"%s\"; matched: \"%s\"", */
292 /* servname != NULL ? servname : "(null)", */
293 /* c->domain, */
294 /* h->domain != NULL ? h->domain : "(null)"); */
296 if (h->domain != NULL) {
297 c->host = h;
298 c->state = handle_open_conn;
299 c->state(fds, c);
300 return;
303 err:
304 if (servname != NULL)
305 strncpy(c->req, servname, sizeof(c->req));
306 else
307 strncpy(c->req, "null", sizeof(c->req));
309 start_reply(fds, c, BAD_REQUEST, "Wrong/malformed host or missing SNI");
312 void
313 handle_open_conn(struct pollfd *fds, struct client *c)
315 const char *parse_err = "invalid request";
316 char decoded[DOMAIN_NAME_LEN];
318 bzero(c->req, sizeof(c->req));
319 bzero(&c->iri, sizeof(c->iri));
321 switch (tls_read(c->ctx, c->req, sizeof(c->req)-1)) {
322 case -1:
323 LOGE(c, "tls_read: %s", tls_error(c->ctx));
324 close_conn(fds, c);
325 return;
327 case TLS_WANT_POLLIN:
328 fds->events = POLLIN;
329 return;
331 case TLS_WANT_POLLOUT:
332 fds->events = POLLOUT;
333 return;
336 if (!trim_req_iri(c->req, &parse_err)
337 || !parse_iri(c->req, &c->iri, &parse_err)
338 || !puny_decode(c->iri.host, decoded, sizeof(decoded), &parse_err)) {
339 LOGI(c, "iri parse error: %s", parse_err);
340 start_reply(fds, c, BAD_REQUEST, "invalid request");
341 return;
344 if (c->iri.port_no != conf.port
345 || strcmp(c->iri.schema, "gemini")
346 || strcmp(decoded, c->domain)) {
347 start_reply(fds, c, PROXY_REFUSED, "won't proxy request");
348 return;
351 open_file(fds, c);
354 void
355 start_reply(struct pollfd *pfd, struct client *c, int code, const char *meta)
357 c->code = code;
358 c->meta = meta;
359 c->state = handle_start_reply;
360 c->state(pfd, c);
363 void
364 handle_start_reply(struct pollfd *pfd, struct client *c)
366 char buf[1030]; /* status + ' ' + max reply len + \r\n\0 */
367 const char *lang;
368 size_t len;
370 lang = vhost_lang(c->host, c->iri.path);
372 snprintf(buf, sizeof(buf), "%d ", c->code);
373 strlcat(buf, c->meta, sizeof(buf));
374 if (!strcmp(c->meta, "text/gemini") && lang != NULL) {
375 strlcat(buf, "; lang=", sizeof(buf));
376 strlcat(buf, lang, sizeof(buf));
379 len = strlcat(buf, "\r\n", sizeof(buf));
380 assert(len < sizeof(buf));
382 switch (tls_write(c->ctx, buf, len)) {
383 case -1:
384 close_conn(pfd, c);
385 return;
386 case TLS_WANT_POLLIN:
387 pfd->events = POLLIN;
388 return;
389 case TLS_WANT_POLLOUT:
390 pfd->events = POLLOUT;
391 return;
394 log_request(c, buf, sizeof(buf));
396 /* we don't need a body */
397 if (c->code != SUCCESS) {
398 close_conn(pfd, c);
399 return;
402 /* advance the state machine */
403 c->state = c->next;
404 c->state(pfd, c);
407 void
408 start_cgi(const char *spath, const char *relpath,
409 struct pollfd *fds, struct client *c)
411 char addr[NI_MAXHOST];
412 const char *ruser, *cissuer, *chash;
413 int e;
415 e = getnameinfo((struct sockaddr*)&c->addr, sizeof(c->addr),
416 addr, sizeof(addr),
417 NULL, 0,
418 NI_NUMERICHOST);
419 if (e != 0)
420 goto err;
422 if (tls_peer_cert_provided(c->ctx)) {
423 ruser = tls_peer_cert_subject(c->ctx);
424 cissuer = tls_peer_cert_issuer(c->ctx);
425 chash = tls_peer_cert_hash(c->ctx);
426 } else {
427 ruser = NULL;
428 cissuer = NULL;
429 chash = NULL;
432 if (!send_iri(exfd, &c->iri)
433 || !send_string(exfd, spath)
434 || !send_string(exfd, relpath)
435 || !send_string(exfd, addr)
436 || !send_string(exfd, ruser)
437 || !send_string(exfd, cissuer)
438 || !send_string(exfd, chash)
439 || !send_vhost(exfd, c->host))
440 goto err;
442 close(c->fd);
443 if ((c->fd = recv_fd(exfd)) == -1) {
444 start_reply(fds, c, TEMP_FAILURE, "internal server error");
445 return;
448 cgi_poll_on_child(fds, c);
449 c->state = handle_cgi_reply;
450 return;
452 err:
453 /* fatal("cannot talk to the executor process: %s", strerror(errno)); */
454 fatal("cannot talk to the executor process");
457 void
458 send_file(struct pollfd *fds, struct client *c)
460 ssize_t ret, len;
462 len = (c->buf + c->len) - c->i;
464 while (len > 0) {
465 switch (ret = tls_write(c->ctx, c->i, len)) {
466 case -1:
467 LOGE(c, "tls_write: %s", tls_error(c->ctx));
468 close_conn(fds, c);
469 return;
471 case TLS_WANT_POLLIN:
472 fds->events = POLLIN;
473 return;
475 case TLS_WANT_POLLOUT:
476 fds->events = POLLOUT;
477 return;
479 default:
480 c->i += ret;
481 len -= ret;
482 break;
486 close_conn(fds, c);
489 void
490 open_dir(struct pollfd *fds, struct client *c)
492 size_t len;
493 int dirfd;
494 char *before_file;
496 len = strlen(c->iri.path);
497 if (len > 0 && !ends_with(c->iri.path, "/")) {
498 redirect_canonical_dir(fds, c);
499 return;
502 strlcpy(c->sbuf, "/", sizeof(c->sbuf));
503 strlcat(c->sbuf, c->iri.path, sizeof(c->sbuf));
504 if (!ends_with(c->sbuf, "/"))
505 strlcat(c->sbuf, "/", sizeof(c->sbuf));
506 before_file = strchr(c->sbuf, '\0');
507 len = strlcat(c->sbuf, vhost_index(c->host, c->iri.path),
508 sizeof(c->sbuf));
509 if (len >= sizeof(c->sbuf)) {
510 start_reply(fds, c, TEMP_FAILURE, "internal server error");
511 return;
514 c->iri.path = c->sbuf;
516 /* close later unless we have to generate the dir listing */
517 dirfd = c->fd;
518 c->fd = -1;
520 switch (check_path(c, c->iri.path, &c->fd)) {
521 case FILE_EXECUTABLE:
522 if (starts_with(c->iri.path, c->host->cgi)) {
523 start_cgi(c->iri.path, "", fds, c);
524 break;
527 /* fallthrough */
529 case FILE_EXISTS:
530 load_file(fds, c);
531 break;
533 case FILE_DIRECTORY:
534 start_reply(fds, c, TEMP_REDIRECT, c->sbuf);
535 break;
537 case FILE_MISSING:
538 *before_file = '\0';
540 if (!vhost_auto_index(c->host, c->iri.path)) {
541 start_reply(fds, c, NOT_FOUND, "not found");
542 break;
545 c->fd = dirfd;
546 c->next = enter_handle_dirlist;
548 if ((c->dir = fdopendir(c->fd)) == NULL) {
549 LOGE(c, "can't fdopendir(%d) (vhost:%s) %s: %s",
550 c->fd, c->host->domain, c->iri.path, strerror(errno));
551 start_reply(fds, c, TEMP_FAILURE, "internal server error");
552 return;
554 c->off = 0;
556 start_reply(fds, c, SUCCESS, "text/gemini");
557 return;
559 default:
560 /* unreachable */
561 abort();
564 close(dirfd);
567 void
568 redirect_canonical_dir(struct pollfd *fds, struct client *c)
570 size_t len;
572 strlcpy(c->sbuf, "/", sizeof(c->sbuf));
573 strlcat(c->sbuf, c->iri.path, sizeof(c->sbuf));
574 len = strlcat(c->sbuf, "/", sizeof(c->sbuf));
576 if (len >= sizeof(c->sbuf)) {
577 start_reply(fds, c, TEMP_FAILURE, "internal server error");
578 return;
581 start_reply(fds, c, TEMP_REDIRECT, c->sbuf);
584 void
585 enter_handle_dirlist(struct pollfd *fds, struct client *c)
587 char b[PATH_MAX];
588 size_t l;
590 strlcpy(b, c->iri.path, sizeof(b));
591 l = snprintf(c->sbuf, sizeof(c->sbuf),
592 "# Index of %s\n\n", b);
593 if (l >= sizeof(c->sbuf)) {
594 /* this is impossible, given that we have enough space
595 * in c->sbuf to hold the ancilliary string plus the
596 * full path; but it wouldn't read nice without some
597 * error checking, and I'd like to avoid a strlen. */
598 close_conn(fds, c);
599 return;
601 c->len = l;
603 c->state = handle_dirlist;
604 handle_dirlist(fds, c);
607 void
608 handle_dirlist(struct pollfd *fds, struct client *c)
610 ssize_t r;
612 while (c->len > 0) {
613 switch (r = tls_write(c->ctx, c->sbuf + c->off, c->len)) {
614 case -1:
615 close_conn(fds, c);
616 return;
617 case TLS_WANT_POLLOUT:
618 fds->events = POLLOUT;
619 return;
620 case TLS_WANT_POLLIN:
621 fds->events = POLLIN;
622 return;
623 default:
624 c->off += r;
625 c->len -= r;
629 c->state = send_directory_listing;
630 send_directory_listing(fds, c);
633 int
634 read_next_dir_entry(struct client *c)
636 struct dirent *d;
638 do {
639 errno = 0;
640 if ((d = readdir(c->dir)) == NULL) {
641 if (errno != 0)
642 LOGE(c, "readdir: %s", strerror(errno));
643 return 0;
645 } while (!strcmp(d->d_name, "."));
647 /* XXX: url escape */
648 snprintf(c->sbuf, sizeof(c->sbuf), "=> %s %s\n",
649 d->d_name, d->d_name);
650 c->len = strlen(c->sbuf);
651 c->off = 0;
653 return 1;
656 void
657 send_directory_listing(struct pollfd *fds, struct client *c)
659 ssize_t r;
661 while (1) {
662 if (c->len == 0) {
663 if (!read_next_dir_entry(c))
664 goto end;
667 while (c->len > 0) {
668 switch (r = tls_write(c->ctx, c->sbuf + c->off, c->len)) {
669 case -1:
670 goto end;
672 case TLS_WANT_POLLOUT:
673 fds->events = POLLOUT;
674 return;
676 case TLS_WANT_POLLIN:
677 fds->events = POLLIN;
678 return;
680 default:
681 c->off += r;
682 c->len -= r;
683 break;
688 end:
689 close_conn(fds, c);
692 void
693 cgi_poll_on_child(struct pollfd *fds, struct client *c)
695 int fd;
697 if (c->waiting_on_child)
698 return;
699 c->waiting_on_child = 1;
701 fds->events = POLLIN;
703 fd = fds->fd;
704 fds->fd = c->fd;
705 c->fd = fd;
708 void
709 cgi_poll_on_client(struct pollfd *fds, struct client *c)
711 int fd;
713 if (!c->waiting_on_child)
714 return;
715 c->waiting_on_child = 0;
717 fd = fds->fd;
718 fds->fd = c->fd;
719 c->fd = fd;
722 /* accumulate the meta line from the cgi script. */
723 void
724 handle_cgi_reply(struct pollfd *fds, struct client *c)
726 void *buf, *e;
727 size_t len;
728 ssize_t r;
730 buf = c->sbuf + c->len;
731 len = sizeof(c->sbuf) - c->len;
733 /* we're polling on the child! */
734 r = read(fds->fd, buf, len);
735 if (r == 0 || r == -1) {
736 cgi_poll_on_client(fds, c);
737 start_reply(fds, c, CGI_ERROR, "CGI error");
738 return;
741 c->len += r;
743 /* TODO: error if the CGI script don't reply correctly */
744 e = strchr(c->sbuf, '\n');
745 if (e != NULL || c->len == sizeof(c->sbuf)) {
746 log_request(c, c->sbuf, c->len);
748 c->off = 0;
749 c->state = handle_cgi;
750 c->state(fds, c);
751 return;
755 void
756 handle_cgi(struct pollfd *fds, struct client *c)
758 ssize_t r;
760 /* ensure c->fd is the child and fds->fd the client */
761 cgi_poll_on_client(fds, c);
763 while (1) {
764 if (c->len == 0) {
765 switch (r = read(c->fd, c->sbuf, sizeof(c->sbuf))) {
766 case 0:
767 goto end;
768 case -1:
769 if (errno == EAGAIN || errno == EWOULDBLOCK) {
770 cgi_poll_on_child(fds, c);
771 return;
773 goto end;
774 default:
775 c->len = r;
776 c->off = 0;
780 while (c->len > 0) {
781 switch (r = tls_write(c->ctx, c->sbuf + c->off, c->len)) {
782 case -1:
783 goto end;
785 case TLS_WANT_POLLOUT:
786 fds->events = POLLOUT;
787 return;
789 case TLS_WANT_POLLIN:
790 fds->events = POLLIN;
791 return;
793 default:
794 c->off += r;
795 c->len -= r;
796 break;
801 end:
802 close_conn(fds, c);
805 void
806 close_conn(struct pollfd *pfd, struct client *c)
808 c->state = close_conn;
810 switch (tls_close(c->ctx)) {
811 case TLS_WANT_POLLIN:
812 pfd->events = POLLIN;
813 return;
814 case TLS_WANT_POLLOUT:
815 pfd->events = POLLOUT;
816 return;
819 connected_clients--;
821 tls_free(c->ctx);
822 c->ctx = NULL;
824 if (c->buf != MAP_FAILED)
825 munmap(c->buf, c->len);
827 if (c->fd != -1)
828 close(c->fd);
830 if (c->dir != NULL)
831 closedir(c->dir);
833 close(pfd->fd);
834 pfd->fd = -1;
837 void
838 do_accept(int sock, struct tls *ctx, struct pollfd *fds, struct client *clients)
840 int i, fd;
841 struct sockaddr_storage addr;
842 socklen_t len;
844 len = sizeof(addr);
845 if ((fd = accept(sock, (struct sockaddr*)&addr, &len)) == -1) {
846 if (errno == EWOULDBLOCK)
847 return;
848 fatal("accept: %s", strerror(errno));
851 mark_nonblock(fd);
853 for (i = 0; i < MAX_USERS; ++i) {
854 if (fds[i].fd == -1) {
855 bzero(&clients[i], sizeof(struct client));
856 if (tls_accept_socket(ctx, &clients[i].ctx, fd) == -1)
857 break; /* goodbye fd! */
859 fds[i].fd = fd;
860 fds[i].events = POLLIN;
862 clients[i].state = handle_handshake;
863 clients[i].next = send_file;
864 clients[i].fd = -1;
865 clients[i].waiting_on_child = 0;
866 clients[i].buf = MAP_FAILED;
867 clients[i].dir = NULL;
868 clients[i].addr = addr;
870 connected_clients++;
871 return;
875 close(fd);
878 void
879 loop(struct tls *ctx, int sock4, int sock6)
881 int i;
882 struct client clients[MAX_USERS];
883 struct pollfd fds[MAX_USERS];
885 connected_clients = 0;
887 for (i = 0; i < MAX_USERS; ++i) {
888 fds[i].fd = -1;
889 fds[i].events = POLLIN;
890 bzero(&clients[i], sizeof(struct client));
893 fds[0].fd = sock4;
894 fds[1].fd = sock6;
896 for (;;) {
897 if (poll(fds, MAX_USERS, INFTIM) == -1) {
898 if (errno == EINTR) {
899 fprintf(stderr, "connected clients: %d\n",
900 connected_clients);
901 continue;
903 fatal("poll: %s", strerror(errno));
906 for (i = 0; i < MAX_USERS; i++) {
907 if (fds[i].revents == 0)
908 continue;
910 if (fds[i].revents & (POLLERR|POLLNVAL))
911 fatal("bad fd %d: %s", fds[i].fd,
912 strerror(errno));
914 if (fds[i].revents & POLLHUP) {
915 /* fds[i] may be the fd of the stdin
916 * of a cgi script that has exited. */
917 if (!clients[i].waiting_on_child) {
918 close_conn(&fds[i], &clients[i]);
919 continue;
923 if (fds[i].fd == sock4)
924 do_accept(sock4, ctx, fds, clients);
925 else if (fds[i].fd == sock6)
926 do_accept(sock6, ctx, fds, clients);
927 else
928 clients[i].state(&fds[i], &clients[i]);