Blame


1 cfe57149 2022-07-30 op /*
2 cfe57149 2022-07-30 op * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
3 cfe57149 2022-07-30 op *
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.
7 cfe57149 2022-07-30 op *
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.
15 cfe57149 2022-07-30 op */
16 cfe57149 2022-07-30 op
17 cfe57149 2022-07-30 op #include "config.h"
18 cfe57149 2022-07-30 op
19 cfe57149 2022-07-30 op #if HAVE_SO_SPLICE
20 cfe57149 2022-07-30 op
21 cfe57149 2022-07-30 op #include <sys/socket.h>
22 cfe57149 2022-07-30 op
23 cfe57149 2022-07-30 op #include "log.h"
24 cfe57149 2022-07-30 op #include "lstun.h"
25 cfe57149 2022-07-30 op
26 cfe57149 2022-07-30 op static void
27 cfe57149 2022-07-30 op splice_done(int fd, short ev, void *data)
28 cfe57149 2022-07-30 op {
29 cfe57149 2022-07-30 op struct conn *c = data;
30 cfe57149 2022-07-30 op
31 cfe57149 2022-07-30 op log_info("closing connection (event=%x)", ev);
32 cfe57149 2022-07-30 op conn_free(c);
33 cfe57149 2022-07-30 op }
34 cfe57149 2022-07-30 op
35 cfe57149 2022-07-30 op int
36 cfe57149 2022-07-30 op conn_splice(struct conn *c)
37 cfe57149 2022-07-30 op {
38 cfe57149 2022-07-30 op if (setsockopt(c->source, SOL_SOCKET, SO_SPLICE, &c->to, sizeof(int))
39 cfe57149 2022-07-30 op == -1)
40 cfe57149 2022-07-30 op return -1;
41 cfe57149 2022-07-30 op if (setsockopt(c->to, SOL_SOCKET, SO_SPLICE, &c->source, sizeof(int))
42 cfe57149 2022-07-30 op == -1)
43 cfe57149 2022-07-30 op return -1;
44 cfe57149 2022-07-30 op
45 cfe57149 2022-07-30 op event_once(c->source, EV_READ, splice_done, c, NULL);
46 cfe57149 2022-07-30 op return 0;
47 cfe57149 2022-07-30 op }
48 cfe57149 2022-07-30 op
49 cfe57149 2022-07-30 op #endif /* HAVE_SO_SPLICE */