1 | /* $Id: proxy_pollmgr.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * NAT Network - poll manager, definitions and declarations.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef VBOX_INCLUDED_SRC_NAT_proxy_pollmgr_h
|
---|
29 | #define VBOX_INCLUDED_SRC_NAT_proxy_pollmgr_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #ifndef RT_OS_WINDOWS
|
---|
35 | # include <unistd.h> /* for ssize_t */
|
---|
36 | #endif
|
---|
37 | #include "lwip/sys.h"
|
---|
38 |
|
---|
39 | enum pollmgr_slot_t {
|
---|
40 | POLLMGR_CHAN_PXTCP_ADD, /* new proxy tcp connection from guest */
|
---|
41 | POLLMGR_CHAN_PXTCP_POLLIN, /* free space in ringbuf, may POLLIN */
|
---|
42 | POLLMGR_CHAN_PXTCP_POLLOUT, /* schedule one-shot POLLOUT callback */
|
---|
43 | POLLMGR_CHAN_PXTCP_DEL, /* delete pxtcp */
|
---|
44 | POLLMGR_CHAN_PXTCP_RESET, /* send RST and delete pxtcp */
|
---|
45 |
|
---|
46 | POLLMGR_CHAN_PXUDP_ADD, /* new proxy udp conversation from guest */
|
---|
47 | POLLMGR_CHAN_PXUDP_DEL, /* delete pxudp from pollmgr */
|
---|
48 |
|
---|
49 | POLLMGR_CHAN_PORTFWD, /* add/remove port forwarding rules */
|
---|
50 |
|
---|
51 | POLLMGR_CHAN_COUNT
|
---|
52 | };
|
---|
53 |
|
---|
54 |
|
---|
55 | struct pollmgr_handler; /* forward */
|
---|
56 | typedef int (*pollmgr_callback)(struct pollmgr_handler *, SOCKET, int);
|
---|
57 |
|
---|
58 | struct pollmgr_handler {
|
---|
59 | pollmgr_callback callback;
|
---|
60 | void *data;
|
---|
61 | int slot;
|
---|
62 | };
|
---|
63 |
|
---|
64 | struct pollmgr_refptr {
|
---|
65 | struct pollmgr_handler *ptr;
|
---|
66 | sys_mutex_t lock;
|
---|
67 | size_t strong;
|
---|
68 | size_t weak;
|
---|
69 | };
|
---|
70 |
|
---|
71 | int pollmgr_init(void);
|
---|
72 |
|
---|
73 | /* static named slots (aka "channels") */
|
---|
74 | SOCKET pollmgr_add_chan(int, struct pollmgr_handler *);
|
---|
75 | ssize_t pollmgr_chan_send(int, void *buf, size_t nbytes);
|
---|
76 | void *pollmgr_chan_recv_ptr(struct pollmgr_handler *, SOCKET, int);
|
---|
77 |
|
---|
78 | /* dynamic slots */
|
---|
79 | int pollmgr_add(struct pollmgr_handler *, SOCKET, int);
|
---|
80 |
|
---|
81 | /* special-purpose strong/weak references */
|
---|
82 | struct pollmgr_refptr *pollmgr_refptr_create(struct pollmgr_handler *);
|
---|
83 | void pollmgr_refptr_weak_ref(struct pollmgr_refptr *);
|
---|
84 | struct pollmgr_handler *pollmgr_refptr_get(struct pollmgr_refptr *);
|
---|
85 | void pollmgr_refptr_unref(struct pollmgr_refptr *);
|
---|
86 |
|
---|
87 | void pollmgr_update_events(int, int);
|
---|
88 | void pollmgr_del_slot(int);
|
---|
89 |
|
---|
90 | void pollmgr_thread(void *);
|
---|
91 |
|
---|
92 | /* buffer for callbacks to receive udp without worrying about truncation */
|
---|
93 | extern u8_t pollmgr_udpbuf[64 * 1024];
|
---|
94 |
|
---|
95 | #endif /* !VBOX_INCLUDED_SRC_NAT_proxy_pollmgr_h */
|
---|