HevSocks5Tunnel Documentation

repository·main·Indexed 19 days ago

https://github.com/alananisimov/olcbox

A lightweight, high-performance tun2socks tunnel that redirects TCP and UDP traffic over a SOCKS5 proxy. It supports dual-stack IPv4/IPv6 and is cross-platform, compatible with Linux, Android, iOS, macOS, and Windows. The project includes HevSocks5Core, a SOCKS5 library supporting standard commands and a proprietary UDP-in-TCP extension, and HevTaskSystem, a lightweight coroutine-based multi-tasking system.

Tokens
8.6K
Snippets
27
Records
38
Agent score
65%

What's inside HevSocks5Tunnel

  1. Overview of Olcbox

    main
    Olcbox is an olcrtc configurator built using Kotlin Multiplatform and Compose. It provides a graphical interface to manage tunnel connections, connection profiles, and network settings across multiple platforms. It supports various providers (Jazz, Telemost, WB Stream, Jitsi) and transports (DataChannel, VP8, SEI).
  2. Overview of HevSocks5Core

    main

    HevSocks5Core is a lightweight SOCKS5 library supporting dual-stack IPv4/IPv6. It implements standard SOCKS5 commands including CONNECT and UDP ASSOCIATE, and includes a proprietary extension for FWD UDP (UDP in TCP) to forward UDP packets within a TCP stream. It also supports multiple username/password authentication methods.

    Dependencies:

  3. What is HevTaskSystem?

    main

    HevTaskSystem is a lightweight multi-tasking system (coroutines) designed to run within a native process or thread. It allows you to create numerous tasks that share the same memory space, file descriptors, and other resources.

    When a task yields or is blocked by I/O, the scheduler automatically switches to another suitable task from the running list. Each task maintains its own private #HevTask structure and a standalone stack located in the process heap. Within a task, you can perform heap memory allocation, read/write to the stack, and execute I/O operations in a synchronized manner.

  4. Platform support and modes

    main

    Olcbox supports different networking modes depending on the platform:

    • Android: Supports TUN and proxy modes using VpnService, hev-socks5-tunnel, or local olcrtc SOCKS5.
    • iOS: Supports Proxy mode using local olcrtc SOCKS5 hosted by a Swift shell.
    • macOS: Supports Proxy mode using local olcrtc SOCKS5 with OS PAC settings.
    • Windows: Supports TUN mode using local olcrtc SOCKS5, hev-socks5-tunnel, and Wintun (requires UAC elevation).
    • Linux: Supports TUN mode using local olcrtc SOCKS5, hev-socks5-tunnel, and policy routes (requires iproute2, /dev/net/tun, and root/Polkit/sudo privileges).
  5. Understand the UDP in TCP Protocol Extension

    main

    The FWD UDP command is a proprietary extension of RFC 1928 that forwards UDP packets within a SOCKS5 TCP stream.

    SOCKS5 Request Format

    When requesting UDP in TCP, the CMD field is set to X'05'.

    FieldValue
    VER1
    CMDX'05' (UDP IN TCP)
    RSVX'00'
    ATYP1
    DST.ADDRVariable
    DST.PORT2 bytes

    UDP Relay Message Format

    Relay messages follow this structure:

    FieldSize
    MSGLEN2 bytes (Total length of message: [MSGLEN, DATA])
    HDRLEN1 byte (Header length: [MSGLEN, DST.PORT])
    ATYP1 byte
    DST.ADDRVariable
    DST.PORT2 bytes
    DATAVariable
  6. Integrate Wintun into a C/C++ project

    main

    Wintun is used as a dynamic library. To integrate it:

    1. Include wintun.h in your project.
    2. Dynamically load wintun.dll using the Windows API LoadLibraryEx().
    3. Resolve each function using GetProcAddress(), utilizing the typedefs provided in wintun.h.

    For a ready-to-use implementation of the initialization logic, you can copy the InitializeWintun function from the official example.c source.

  7. Build HevTaskSystem for Unix

    main

    To build HevTaskSystem on Unix-like systems, clone the repository and use make. You can pass specific flags to customize the build for your environment or requirements:

    • Link with librt: Required for glibc versions older than 2.17.
    • Disable stack overflow detection: Use ENABLE_STACK_OVERFLOW_DETECTION=0.
    • Set stack backend to heap: Recommended for 32-bit systems; use CONFIG_STACK_BACKEND=STACK_HEAP.
    • Disable sliced memory allocator: Use ENABLE_MEMALLOC_SLICE=0.
    • Disable I/O splice: For older Linux kernels that do not support the splice syscall, use ENABLE_IO_SPLICE_SYSCALL=0.

    To build demonstration applications, use make apps. To run tests, use make tests.

    git clone https://gitlab.com/hev/hev-task-system
    cd hev-task-system
    make
    
    # Example: Build for 32-bit with heap stack
    make CONFIG_STACK_BACKEND=STACK_HEAP
    
    # Example: Build for old Linux kernel
    make ENABLE_IO_SPLICE_SYSCALL=0