Skip to content

Commit 63b0aa2

Browse files
committed
fix: add missing route for WireGuard CIDR in userspace implementation
- Added route for entire CIDR range (10.100.0.0/24) through WireGuard interface - Fixes issue where userspace WireGuard doesn't automatically add kernel routes - Server can now properly route return traffic to WireGuard clients - Resolves 'dial tcp 10.100.0.3:7777: i/o timeout' errors
1 parent dfb9976 commit 63b0aa2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

internal/tunnel/tunnel.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ func New(opts PeerOpts) (*Tunnel, error) {
8787
return nil, fmt.Errorf("error bringing up the link: %w", err)
8888
}
8989

90+
// Add route for the entire CIDR range through this interface.
91+
// This is needed for userspace WireGuard since kernel doesn't automatically
92+
// add routes like it does for kernel WireGuard.
93+
route := &netlink.Route{
94+
Dst: cidrNet, // 10.100.0.0/24
95+
LinkIndex: link.Attrs().Index, // wg0 interface
96+
}
97+
if err = netlink.RouteAdd(route); err != nil {
98+
return nil, fmt.Errorf("error adding route for CIDR %s: %w", opts.CIDR, err)
99+
}
100+
90101
// Decode the private key.
91102
pk, err := encodeBase64ToHex(opts.PrivateKey)
92103
if err != nil {

0 commit comments

Comments
 (0)