mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-16 06:05:50 +08:00
Some checks are pending
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Waiting to run
Datagrams on a TCP connection, each with a two byte length in network order in front of it, which is how udptunnel (the rfc1036 one) and ProxyGuard (eduVPN) put them there, the framing alone or after a handshake: udptunnel's 32 bytes, or ProxyGuard's HTTP Upgrade for UoTLV/1 answered with 101 Switching Protocols. tcptoudp takes the connections, a UDP socket of its own to the target for each, the handshake a client speaks recognised by its first bytes and answered; a parent the ACL gives is a SOCKS5 UDP relay, as for udppm. udptotcp takes the datagrams, each client a session of the service's with a TCP connection of its own, connected as the service's loop sees it writable (dnspr asks a name server over TCP the same way); -m sends udptunnel's handshake to the target, -m2 ProxyGuard's, -m0 (the default) none, so both ends of either tool are stood in for. The service names take two places of the string table, the default configuration path moving two later (stringtable[27]). Built by the Makefiles and CMake, with the standalone binaries, and installed by them; a case of the test suite speaks all three handshakes.
70 lines
2.2 KiB
C
70 lines
2.2 KiB
C
/*
|
|
3APA3A simplest proxy server
|
|
(c) 2002-2026 by Vladimir Dubrovin <vlad@3proxy.org>
|
|
|
|
please read License Agreement
|
|
|
|
*/
|
|
|
|
/* What the tunnels between TCP and UDP speak, tcptoudp and udptotcp:
|
|
datagrams on a TCP connection, each with its length, in network
|
|
order, in front of it. udptunnel (the rfc1036 one) and ProxyGuard's
|
|
UoTLV/1 (eduVPN) put datagrams on a connection the same way; what
|
|
they differ in is what comes first:
|
|
|
|
- nothing: the framing alone;
|
|
- udptunnel's handshake: 32 bytes beginning "udptunnel by ", which
|
|
the client sends and no answer follows;
|
|
- ProxyGuard's: an HTTP Upgrade, the client asking with "GET",
|
|
"Connection: Upgrade" and "Upgrade: UoTLV/1", the server answering
|
|
"101 Switching Protocols" before the framing begins.
|
|
|
|
Which of these a connection speaks is told by its first bytes, "GET"
|
|
or "udptunnel by ", so tcptoudp takes any of them from a client;
|
|
udptotcp sends the one it was configured to (-m: udptunnel's, -m2:
|
|
ProxyGuard's, -m0: none). */
|
|
|
|
#ifndef _UDPTUNNEL_H
|
|
#define _UDPTUNNEL_H
|
|
|
|
#include <ctype.h>
|
|
|
|
/* the length of the prefix a datagram carries on the connection */
|
|
#define UDPTUN_HDR 2
|
|
/* udptunnel's handshake: "udptunnel by md." of the rfc1036 udptunnel,
|
|
followed by zeroes and a counting sequence; any 32 bytes beginning
|
|
with the prefix are taken, the original Columbia one included */
|
|
#define UDPTUN_MAGIC_LEN 32
|
|
#define UDPTUN_PREFIX "udptunnel by "
|
|
#define UDPTUN_PREFIX_LEN 13
|
|
/* ProxyGuard's protocol, as the Upgrade: header names it */
|
|
#define UDPTUN_PROTO "UoTLV/1"
|
|
/* a header of a handshake is not longer */
|
|
#define UDPTUN_MAXHDR 2048
|
|
|
|
/* the length a datagram's prefix tells */
|
|
static int udptunget(const unsigned char *p){
|
|
return (p[0] << 8) | p[1];
|
|
}
|
|
|
|
/* the prefix of a datagram of this length */
|
|
static void udptunput(unsigned char *p, int n){
|
|
p[0] = (unsigned char)(n >> 8);
|
|
p[1] = (unsigned char)n;
|
|
}
|
|
|
|
/* whether the bytes of a handshake name the protocol, whatever the
|
|
case of the letters */
|
|
static int udptunprotoin(const unsigned char *b, int len){
|
|
int i, j;
|
|
|
|
for(i = 0; i + 7 <= len; i++){
|
|
for(j = 0; j < 7; j++)
|
|
if(tolower(b[i + j]) != tolower((unsigned char)UDPTUN_PROTO[j])) break;
|
|
if(j == 7) return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#endif
|