/* * Called everytime new data is read from any of the connections * that are part of a pipe. */ static int ktunnel_pipe_data(struct netbuf *nb) { struct connection *src = nb->owner; struct connection *dst = src->hdlr_extra; printf("received %d bytes on pipe %p (-> %p)\n", nb->s_off, src, dst); net_send_queue(dst, nb->buf, nb->s_off, NULL, NETBUF_LAST_CHAIN); net_send_flush(dst); net_recv_reset(src, NETBUF_SEND_PAYLOAD_MAX, ktunnel_pipe_data); return (KORE_RESULT_OK); }
/* * Called whenever data is available that must be piped through * to the paired connection. (client<>backend or backend<>client). */ int pipe_data(struct netbuf *nb) { struct connection *src = nb->owner; struct connection *dst = src->hdlr_extra; /* Flush data out towards destination. */ net_send_queue(dst, nb->buf, nb->s_off); net_send_flush(dst); /* Reset read for source. */ net_recv_reset(src, NETBUF_SEND_PAYLOAD_MAX, pipe_data); return (KORE_RESULT_OK); }
void db_results(struct kore_pgsql *pgsql, struct connection *c) { char *name; int i, rows; rows = kore_pgsql_ntuples(pgsql); for (i = 0; i < rows; i++) { name = kore_pgsql_getvalue(pgsql, i, 0); net_send_queue(c, name, strlen(name)); } net_send_flush(c); kore_pgsql_continue(pgsql); }
/* * This function is called everytime we get up to 128 bytes of data. * The connection can be found under nb->owner. * The data received can be found under nb->buf. * The length of the received data can be found under s_off. */ int connection_recv_data(struct netbuf *nb) { struct connection *c = (struct connection *)nb->owner; kore_log(LOG_NOTICE, "%p: received %u bytes", c, nb->s_off); /* We will just dump these back to the client. */ net_send_queue(c, nb->buf, nb->s_off); net_send_flush(c); /* Now reset the receive command for the next one. */ net_recv_reset(c, 128, connection_recv_data); return (KORE_RESULT_OK); }
int kore_connection_handle(struct connection *c) { int r; u_int32_t len; const u_char *data; kore_debug("kore_connection_handle(%p)", c); if (c->proto != CONN_PROTO_SPDY) kore_connection_stop_idletimer(c); switch (c->state) { case CONN_STATE_SSL_SHAKE: if (c->ssl == NULL) { c->ssl = SSL_new(primary_dom->ssl_ctx); if (c->ssl == NULL) { kore_debug("SSL_new(): %s", ssl_errno_s); return (KORE_RESULT_ERROR); } SSL_set_fd(c->ssl, c->fd); SSL_set_accept_state(c->ssl); } r = SSL_accept(c->ssl); if (r <= 0) { r = SSL_get_error(c->ssl, r); switch (r) { case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_WRITE: return (KORE_RESULT_OK); default: kore_debug("SSL_accept(): %s", ssl_errno_s); return (KORE_RESULT_ERROR); } } r = SSL_get_verify_result(c->ssl); if (r != X509_V_OK) { kore_debug("SSL_get_verify_result(): %s", ssl_errno_s); return (KORE_RESULT_ERROR); } SSL_get0_next_proto_negotiated(c->ssl, &data, &len); if (data) { if (!memcmp(data, "spdy/3", MIN(6, len))) { c->proto = CONN_PROTO_SPDY; net_recv_queue(c, SPDY_FRAME_SIZE, 0, NULL, spdy_frame_recv); } else if (!memcmp(data, "http/1.1", MIN(8, len))) { c->proto = CONN_PROTO_HTTP; net_recv_queue(c, HTTP_HEADER_MAX_LEN, NETBUF_CALL_CB_ALWAYS, NULL, http_header_recv); } else { kore_debug("npn: received unknown protocol"); } } else { c->proto = CONN_PROTO_HTTP; net_recv_queue(c, HTTP_HEADER_MAX_LEN, NETBUF_CALL_CB_ALWAYS, NULL, http_header_recv); } c->state = CONN_STATE_ESTABLISHED; /* FALLTHROUGH */ case CONN_STATE_ESTABLISHED: if (c->flags & CONN_READ_POSSIBLE) { if (!net_recv_flush(c)) return (KORE_RESULT_ERROR); } if (c->flags & CONN_WRITE_POSSIBLE) { if (!net_send_flush(c)) return (KORE_RESULT_ERROR); } break; case CONN_STATE_DISCONNECTING: break; default: kore_debug("unknown state on %d (%d)", c->fd, c->state); break; } if (c->proto != CONN_PROTO_SPDY) kore_connection_start_idletimer(c); return (KORE_RESULT_OK); }