Skip to content

Feature: Add configurable interface and route metrics #62

@FIL033

Description

@FIL033

Problem

Currently, interface and route metrics are hardcoded in the TUN implementation:

  • Windows: Interface metric is set to 0 when AutoRoute is enabled
  • Routes: Always use metric 0 (highest priority)

This creates issues when users need different routing priorities on different devices while using the same configuration file.

Proposed Solution

Add two new fields to the Options struct:

  • InterfaceMetric uint32 - Sets the metric for the TUN interface (Windows only)
  • RouteMetric uint32 - Sets the metric for routes through the TUN interface (Windows and Linux)

Behavior:

  • InterfaceMetric = 0 (default):
    • When AutoRoute=true: metric is set to 0 (highest priority)
    • When AutoRoute=false: Windows automatic metric is used
  • InterfaceMetric > 0: Explicitly specified metric (lower value = higher priority)
  • RouteMetric = 0 (default): Metric 0 (highest priority)
  • RouteMetric > 0: Explicitly specified metric
  • On Linux, RouteMetric maps to the Priority field in netlink routes

Implementation

Changes required in:

  • tun.go: Add InterfaceMetric and RouteMetric fields to Options
  • tun_windows.go: Implement interface metric logic for IPv4/IPv6, update route metric
  • tun_linux.go: Map RouteMetric to Priority field

Backward Compatibility

Fully backward compatible - when both fields are 0 (default), behavior remains unchanged.

Use Case

Users running the same configuration on multiple devices (e.g., desktop and mobile) can now set different routing priorities without maintaining separate config files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions