Modern VPN Protocol Deep-Dive Series

🔐 How OpenVPN Works Internally from a "Top 1%" Perspective — Why Encrypting IP Packets with TLS Becomes a VPN Connection

Introduction

This article is part of the Top 1% Series’ full article guide.

Prerequisites

Getting the Big Picture

In a Nutshell

Between “encrypting IP packets with TLS” and “a VPN connection is actually established,” there are, in fact, three necessary stages. (1) In the first place, how does OpenVPN even get its hands on “the IP packets that should be sent through the tunnel” from the OS (the TUN device)? (2) Within a single encrypted TLS connection, how does it distinguish control exchanges like key negotiation from actual payload data (the separation of the Control Channel and Data Channel)? (3) After the connection is up, how does the client learn the IP address and route information it needs in order to actually start sending packets toward the tunnel (the Push mechanism)? Only once all three pieces are in place does mere “encrypted TLS traffic” become a “VPN connection.”

graph TB
    OS["OS (client)"] -->|"① Captures the IP packets to be sent<br/>via the TUN device"| OpenVPN["OpenVPN process"]
    OpenVPN -->|"② Encrypts and sends over the Data Channel<br/>(multiplexed separately from the Control Channel)"| Server["OpenVPN server"]
    Server -->|"③ Push: delivers the virtual IP and route info<br/>over the Control Channel"| OpenVPN
    OpenVPN -->|"Configures the TUN device and<br/>routing table with the delivered info"| OS

Fundamentals, Thoroughly Explained

① The TUN Device: How Does It Receive “the Packets That Should Go Through the Tunnel”?

The first thing OpenVPN does is create a TUN device (a virtual network interface) on the OS. Once this TUN device is registered in the OS’s routing table as a network interface, the routing rule “packets addressed to the remote VPN segment should go out through this TUN device” becomes active, and only the packets an application sends that match that rule get handed to the OpenVPN process. OpenVPN encrypts them as-is and sends them over the actual physical network to the VPN server (the detailed mechanics of how a TUN device hands packets to a user-space program are covered in User Space, Kernel Space, and TUN/TAP Devices).

Looked at from this stage alone, “traffic encrypted with TLS” is no different from a web browser’s HTTPS traffic. The only difference is what’s being poured into that TLS connection: not data a specific application wants to send (an HTTP request, say), but arbitrary IP packets handed over via the TUN device based purely on the OS’s routing decision.

② Separating the Control Channel from the Data Channel

Internally, OpenVPN splits into two logical channels with different jobs.

graph LR
    subgraph Single["A single UDP/TCP connection"]
        CC["Control Channel<br/>(TLS handshake, Push delivery)"]
        DC["Data Channel<br/>(encrypted IP packet payload)"]
    end
    CC -.hands off key-exchange results.-> DC
Aside: In UDP mode, the control channel needs its own reliability layer

A TLS handshake is designed on the assumption that it runs over a reliable transport, like TCP — one that guarantees packet ordering and retransmission. Yet OpenVPN’s standard recommendation, for performance reasons, is to run over UDP (covered in more depth in the “TCP-over-TCP meltdown” section of Comparing L2TP/IPsec to Modern VPN Protocols). Since UDP has no built-in acknowledgment, retransmission, or ordering guarantees, OpenVPN implements its own lightweight reliability layer, specifically for the Control Channel (acknowledgment packets and retransmission). This reliability layer applies only to Control Channel messages (the individual stages of the TLS handshake) — not to the actual IP packets flowing through the Data Channel. Retransmission of the IP packets themselves is left to whatever is riding inside the tunnel (the user’s own TCP stack, if it’s TCP traffic) — if the tunnel layer also tried to retransmit on top of that, it would reintroduce exactly the same kind of problem as the “TCP-over-TCP meltdown.”

Because the Control Channel and Data Channel are separated, OpenVPN can renegotiate keys periodically (rotating the Data Channel’s keys) purely on the Control Channel side, without ever interrupting traffic on the Data Channel.

③ The Push Mechanism: Telling the Client “Send Traffic to This Tunnel”

Just creating a TUN device and establishing an encrypted channel isn’t enough — the client-side OS still doesn’t know which destinations’ packets should go out through that TUN device. That’s where the Push mechanism comes in.

sequenceDiagram
    participant C as Client
    participant S as OpenVPN Server

    C->>S: TLS handshake (certificate authentication)
    S-->>C: Authentication succeeds
    C->>S: PUSH_REQUEST (requests configuration info)
    S-->>C: PUSH_REPLY (virtual IP address, subnet mask,<br/>route info, DNS server, etc.)
    Note over C: Uses the received info to assign an IP<br/>to the TUN device and update the routing table
    C->>S: From this point on, packets to the target<br/>destination(s) start flowing through the TUN device

Once a client’s TLS handshake authentication succeeds, the server sends it a message called PUSH_REPLY over the Control Channel. This includes the virtual IP address and subnet mask to assign to the client’s TUN device, route information — which networks’ traffic should go through this tunnel (an option like redirect-gateway can route all traffic through the tunnel, or a narrower setting can route only specific subnets) — and the DNS server address, among other things. Only at this exact moment does the client-side OpenVPN process take the actions of assigning an IP address to its own TUN device and adding routes to the OS’s routing table, based on this delivered information.

Only once all three of these stages are in place does “traffic encrypted with TLS” become “a VPN connection.” Without the TUN device, there’s no IP packet to carry in the first place. Without separating the Control Channel from the Data Channel, key exchange and payload data couldn’t be safely multiplexed together. And without the Push mechanism, the client would have no way of ever learning what it’s actually supposed to send through the tunnel.

The View from the Top 1% (What Experts See)

The Server Can Decide “What Goes Through the Tunnel” After the Fact

The important consequence of the Push mechanism is that “what the client sends over the VPN” isn’t fixed in a pre-connection configuration file — the server can dynamically dictate it at connection time, every time. Configuring it to route all traffic through the VPN (redirect-gateway) achieves what’s called a full tunnel — every packet from a remote device gets funneled through the VPN before going out. Configuring it to push only routes for internal-network subnets instead achieves a split tunnel — everything else (ordinary web browsing, for instance) goes straight out over the client’s local connection unchanged. The fact that this switch can be made purely by changing the server-side Push configuration, with no client-side config file edit required, is the source of a lot of operational flexibility.

Why OpenVPN’s Implementation Tends to Have More Code Than IPsec’s

OpenVPN has this characteristic: the TLS handshake, its own custom reliability layer, option delivery via the Push mechanism, TUN/TAP device control — it implements, at the application layer, functionality that isn’t part of the TLS specification on its own. This is a different kind of complexity from the one L2TP/IPsec carries by combining separate standards (IKE, L2TP, PPP). Where IPsec integrates network-layer encryption directly into the OS kernel, OpenVPN, as a user-space application, implements “everything needed to function as a VPN” itself from scratch — which is why its implementation tends to end up with a larger codebase than IPsec-family implementations.

Common Misconceptions and Pitfalls

Troubleshooting Perspective

Troubleshooting an OpenVPN connection issue starts with isolating whether the problem is at the TLS handshake stage, or at the stage after Push delivers configuration.

  1. The TLS handshake itself fails: Typical causes include an expired certificate, a mismatched CA certificate, or the UDP/TCP port being blocked by a firewall. Check both the server’s and client’s logs to see exactly which stage of the handshake (certificate validation, key exchange) is failing.
  2. The handshake succeeds, but traffic through the tunnel doesn’t work: Check whether the PUSH_REPLY contents (route information) actually got reflected in the client’s routing table. It helps to check the OS’s routing table display command (route or ip route) to confirm a route to the TUN device has actually been added.
  3. Only some destinations are unreachable: Check the scope of the routes the server is pushing (full tunnel vs. split tunnel). A common cause is a configuration mistake where the destination you expected wasn’t included in the pushed routes.

Prevention and Long-Term Countermeasures

Summary

Things to Keep in Mind Starting Today

  1. When you hit an OpenVPN connection problem, start by isolating whether it’s at the TLS-handshake stage or the post-Push stage, and check the logs and configuration appropriate to that stage.
  2. When designing full-tunnel vs. split-tunnel behavior, keep in mind that it’s the server’s Push configuration — not the client — that actually determines the behavior.

References

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).