# mullvad/win-split-tunnel architecture

> Architecture diagram of the GitHub repository mullvad/win-split-tunnel, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mullvad/win-split-tunnel
- Repository: https://github.com/mullvad/win-split-tunnel

## Overview

##### Main Components
- Kernel-mode driver (the core of the system)
- Contains several subsystems: Firewall, Process Management, Eventing, and supporting data structures (Process Registry and Registered Image).
- User Mode Agent
- Though not implemented fully in this repository (only example code is in the ‘testing’ directory), it is critical. It supplies configuration data (list of excluded process paths, tunnel IP addresses, etc.) and listens for events from the driver.
- Windows OS & Networking Subsystems
- Integration with Windows Filtering Platform (WFP) is an essential part of the architecture.
- Interaction with network interfaces, dealing with IP addresses, and handling of socket binds (including redirections for excluded applications).

##### Components’ Relationships and Interactions
- The user mode agent communicates with the driver through specific IOCTL commands. Illustrate this as a two-way communication channel:
- The agent sends configuration updates (e.g., register/exclude process paths, set IP addresses).
- The driver sends events back (such as process state changes or warnings about potential leaks).
- Internally, the driver’s subsystems interact:
- The Firewall subsystem intercepts and directs network traffic using WFP policies.
- The Process Management subsystem tracks process lifecycle events (arrival/departure) and propagates exclusions.
- The Eventing subsystem ensures asynchronous notifications are sent to the user mode agent.
- Shared data structures like the Process Registry and Registered Image hold state information that is used by various subsystems.

##### Architectural Patterns and Design Principles
- Modularity – Each subsystem (Firewall, Process Management, Eventing) is encapsulated, with clearly defined responsibilities.
- State Management – The driver must follow a strict state-transitions model from load to active engagement.
- Transactional Updates – Particularly within the firewall subsystem when modifying WFP settings to avoid race conditions.
- Inverted Call Model for Eventing – Events flow asynchronously back to the agent.
- Separation of concerns between kernel-mode operations (which enforce policies) and user mode configuration and monitoring.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-level User Mode Agent
    UM("User Mode Agent"):::user

    %% External Systems
    WFP("Windows Filtering Platform"):::external
    Net("Network Interfaces"):::external

    %% Kernel-Mode Driver Subgraph
    subgraph "Kernel-Mode Driver"
        IOCTL("IOCTL & State Management"):::kernel
        Core("Kernel Driver Core"):::kernel

        %% Firewall Subsystem
        subgraph "Firewall Subsystem"
            FW("Firewall: firewall.cpp"):::kernel
            AppFilt("Firewall: appfilters.cpp"):::kernel
            Callouts("Firewall: callouts.cpp"):::kernel
            Classify("Firewall: classify.cpp"):::kernel
            Filters("Firewall: filters.cpp"):::kernel
            WFPInt("Firewall: wfp.h"):::kernel
        end

        %% Process Management Subsystem
        subgraph "Process Management Subsystem"
            PM("Process Mgmt: procmgmt.cpp"):::kernel
            ProcReg("Process Registry"):::kernel
            RegImg("Registered Image"):::kernel
        end

        %% Eventing Subsystem
        subgraph "Eventing Subsystem"
            Event("Eventing: eventing.cpp"):::kernel
            EBuilder("Event Builder: builder.cpp"):::kernel
        end
    end

    %% Connections between User Mode Agent and Kernel-Mode Driver
    UM -->|"IOCTL_ST_SET_CONFIGURATION"| IOCTL
    IOCTL -->|"StateTransition"| Core

    %% Connections within Kernel-Mode Driver
    Core -->|"Init_Firewall"| FW
    Core -->|"Init_ProcessMgmt"| PM
    Core -->|"Trigger_Events"| Event

    PM -->|"Update_Registry"| ProcReg
    PM -->|"Update_Image"| RegImg

    FW -->|"WFP_TransactionalUpdate"| WFP
    FW -->|"Redirect_Traffic"| Net

    Event -->|"Event_Notifications"| UM

    %% Internal Firewall subsystem relationships
    FW --- AppFilt
    AppFilt --- Callouts
    Callouts --- Classify
    Classify --- Filters
    Filters --- WFPInt

    %% Click Events for Kernel-Mode Driver components
    click Core "https://github.com/mullvad/win-split-tunnel/blob/master/src/driverentry.cpp"
    click IOCTL "https://github.com/mullvad/win-split-tunnel/blob/master/src/defs/ioctl.h"
    click FW "https://github.com/mullvad/win-split-tunnel/blob/master/src/firewall/firewall.cpp"
    click AppFilt "https://github.com/mullvad/win-split-tunnel/blob/master/src/firewall/appfilters.cpp"
    click Callouts "https://github.com/mullvad/win-split-tunnel/blob/master/src/firewall/callouts.cpp"
    click Classify "https://github.com/mullvad/win-split-tunnel/blob/master/src/firewall/classify.cpp"
    click Filters "https://github.com/mullvad/win-split-tunnel/blob/master/src/firewall/filters.cpp"
    click WFPInt "https://github.com/mullvad/win-split-tunnel/blob/master/src/firewall/wfp.h"
    click PM "https://github.com/mullvad/win-split-tunnel/blob/master/src/procmgmt/procmgmt.cpp"
    click ProcReg "https://github.com/mullvad/win-split-tunnel/blob/master/src/containers/procregistry.cpp"
    click RegImg "https://github.com/mullvad/win-split-tunnel/blob/master/src/containers/registeredimage.cpp"
    click Event "https://github.com/mullvad/win-split-tunnel/blob/master/src/eventing/eventing.cpp"
    click EBuilder "https://github.com/mullvad/win-split-tunnel/blob/master/src/eventing/builder.cpp"
    click UM "https://github.com/mullvad/win-split-tunnel/blob/master/testing/stconsole.cpp"

    %% Style Definitions
    classDef kernel fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef user fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#000,stroke-width:2px;
```
