2 cfe57149 2022-07-30 op * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
4 cfe57149 2022-07-30 op * Permission to use, copy, modify, and distribute this software for any
5 cfe57149 2022-07-30 op * purpose with or without fee is hereby granted, provided that the above
6 cfe57149 2022-07-30 op * copyright notice and this permission notice appear in all copies.
8 cfe57149 2022-07-30 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 cfe57149 2022-07-30 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 cfe57149 2022-07-30 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 cfe57149 2022-07-30 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 cfe57149 2022-07-30 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 cfe57149 2022-07-30 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 cfe57149 2022-07-30 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 cfe57149 2022-07-30 op #include "config.h"
19 cfe57149 2022-07-30 op #if !HAVE_SO_SPLICE
21 cfe57149 2022-07-30 op #include <sys/socket.h>
23 cfe57149 2022-07-30 op #include "log.h"
24 cfe57149 2022-07-30 op #include "lstun.h"
27 cfe57149 2022-07-30 op nopcb(struct bufferevent *bev, void *d)
33 cfe57149 2022-07-30 op sreadcb(struct bufferevent *bev, void *d)
35 cfe57149 2022-07-30 op struct conn *c = d;
37 cfe57149 2022-07-30 op bufferevent_write_buffer(c->tobev, EVBUFFER_INPUT(bev));
41 cfe57149 2022-07-30 op treadcb(struct bufferevent *bev, void *d)
43 cfe57149 2022-07-30 op struct conn *c = d;
45 cfe57149 2022-07-30 op bufferevent_write_buffer(c->sourcebev, EVBUFFER_INPUT(bev));
49 cfe57149 2022-07-30 op errcb(struct bufferevent *bev, short event, void *d)
51 cfe57149 2022-07-30 op struct conn *c = d;
53 cfe57149 2022-07-30 op log_info("closing connection (event=%x)", event);
58 cfe57149 2022-07-30 op conn_splice(struct conn *c)
60 cfe57149 2022-07-30 op c->sourcebev = bufferevent_new(c->source, sreadcb, nopcb, errcb, c);
61 cfe57149 2022-07-30 op c->tobev = bufferevent_new(c->to, treadcb, nopcb, errcb, c);
63 cfe57149 2022-07-30 op if (c->sourcebev == NULL || c->tobev == NULL) {
64 cfe57149 2022-07-30 op log_warn("bufferevent_new");
68 cfe57149 2022-07-30 op bufferevent_enable(c->sourcebev, EV_READ|EV_WRITE);
69 cfe57149 2022-07-30 op bufferevent_enable(c->tobev, EV_READ|EV_WRITE);
73 cfe57149 2022-07-30 op #endif /* !HAVE_SO_SPLICE */