Skip to content

Refactor vpn.rs to support multiple vpn types#311

Merged
cachebag merged 8 commits intocachebag:dev-openvpnfrom
stoutes:refactor-vpn.rs-to-support-multiple-vpn-types
Mar 30, 2026
Merged

Refactor vpn.rs to support multiple vpn types#311
cachebag merged 8 commits intocachebag:dev-openvpnfrom
stoutes:refactor-vpn.rs-to-support-multiple-vpn-types

Conversation

@stoutes
Copy link
Copy Markdown
Collaborator

@stoutes stoutes commented Mar 26, 2026

Summary

Part of #288, closes #293.

Refactors core/vpn.rs to replace hardcoded WireGuard type checks with a
shared detect_vpn_type() helper that understands both WireGuard and OpenVPN
connection types, making each function ready to handle multiple VPN backends.

Changes

api/models/vpn.rs

  • Added OpenVpn variant to VpnType enum

core/vpn.rs

  • Added detect_vpn_type() helper — detects WireGuard (connection.type == "wireguard")
    and OpenVPN (connection.type == "vpn" + vpn.service-type == "org.freedesktop.NetworkManager.openvpn")
    from a settings map, replacing all scattered inline string checks
  • connect_vpn: dispatches on creds.vpn_type to build_wireguard_connection or returns
    VpnFailed for unsupported types — full impl VpnConfig signature blocked on VpnConfig
    trait from openvpn support #288
  • disconnect_vpn: replaced hardcoded connection.type == "wireguard" check with detect_vpn_type
  • list_vpn_connections: expanded active and saved connection filters to detect both types via
    detect_vpn_type; vpn_type on returned VpnConnection now reflects actual detected type
    instead of always being VpnType::WireGuard
  • get_vpn_info: replaced hardcoded type check with detect_vpn_type; gateway extraction
    branches on vpn_type — WireGuard reads from wireguard.peers, OpenVPN reads from
    vpn.data["remote"]; IP config extraction unchanged
  • forget_vpn: replaced hardcoded type check with detect_vpn_type, flattened
    if let Some(conn_sec) nesting

api/network_manager.rs

  • Simplified connect_vpn to delegate fully to core::vpn::connect_vpn, removed redundant
    build_wireguard_connection call and unused opts parameter

Blocked on #288

  • build_openvpn_connection — OpenVPN connections will hit the VpnFailed stub until this lands
  • VpnConfig trait — connect_vpn signature cannot be updated to impl VpnConfig until the
    trait exists

@cachebag cachebag changed the base branch from master to dev-openvpn March 26, 2026 22:08
@stoutes stoutes marked this pull request as ready for review March 26, 2026 22:28
@cachebag cachebag force-pushed the refactor-vpn.rs-to-support-multiple-vpn-types branch from c1441b6 to b158730 Compare March 27, 2026 02:30
Copy link
Copy Markdown
Owner

@cachebag cachebag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stoutes Could you please drop these other commits from the branch? I'd prefer you just keep the changes you made. It looks like you branched off of master when it should have been off of dev-openvpn.

Additionally, please clean up your commit messages. This is not ideal

Image

@cachebag cachebag added feature New feature or request nmrs Changes to nmrs refactor Change or improve code vpn Changes to VPN surface labels Mar 27, 2026
@stoutes stoutes force-pushed the refactor-vpn.rs-to-support-multiple-vpn-types branch from b158730 to 1cd575f Compare March 27, 2026 02:42
@cachebag cachebag marked this pull request as draft March 27, 2026 13:13
@cachebag
Copy link
Copy Markdown
Owner

@stoutes You're gonna want to run git rebase -i HEAD~11 and drop the 6 commits that come before yours.

@stoutes stoutes force-pushed the refactor-vpn.rs-to-support-multiple-vpn-types branch 2 times, most recently from 8ecf984 to 0f7eff1 Compare March 27, 2026 13:26
@stoutes
Copy link
Copy Markdown
Collaborator Author

stoutes commented Mar 27, 2026

@stoutes You're gonna want to run git rebase -i HEAD~11 and drop the 6 commits that come before yours.

Yeah not sure how that happened....weird

@stoutes stoutes marked this pull request as ready for review March 27, 2026 13:27
Copy link
Copy Markdown
Owner

@cachebag cachebag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job, really appreciate your help on this!

@cachebag
Copy link
Copy Markdown
Owner

Just to note @stoutes for the conflcits, accept all incoming changes. We don't want gateway in our VpnConfig trait

@stoutes stoutes force-pushed the refactor-vpn.rs-to-support-multiple-vpn-types branch from a0fabe3 to 26f0985 Compare March 28, 2026 21:14
@stoutes stoutes requested a review from cachebag March 30, 2026 00:03
Copy link
Copy Markdown
Owner

@cachebag cachebag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cachebag cachebag merged commit 88d5865 into cachebag:dev-openvpn Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request nmrs Changes to nmrs refactor Change or improve code vpn Changes to VPN surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor core/vpn.rs to support multiple vpn types

2 participants