Skip to content

ConfigureDevice erasing peers, but not adding it on windows #146

@WebV5

Description

@WebV5

Hello, got some problems with device configuration via wgctrl
Here is my code:

privateKey, err := wgtypes.ParseKey(data.PrivateKey)
if err != nil {
    i.log.Error(err)
    return err
}
publicKey, err := wgtypes.ParseKey(data.PublicKey)
if err != nil {
    i.log.Error(err)
    return err
}
endpointIpPort, err := netip.ParseAddrPort(data.Endpoint)
if err != nil {
    i.log.Error(err)
    return err
}
endpoint := net.UDPAddrFromAddrPort(endpointIpPort)
if endpoint == nil {
    i.log.Error("endpoint was not provided")
    return errors.New("endpoint was not provided")
}

keepalive := time.Duration(data.KeepaliveInterval) * time.Second
_, allowedIps, _ := net.ParseCIDR("0.0.0.0/1")
i.log.Debugf("setup peer %s", publicKey.String())
peers := make([]wgtypes.PeerConfig, 0)
peers = append(peers, wgtypes.PeerConfig{
    PublicKey:                   publicKey,
    Endpoint:                    endpoint,
    ReplaceAllowedIPs:           true,
    PersistentKeepaliveInterval: &keepalive,
    AllowedIPs:                  []net.IPNet{*allowedIps},
})
config := wgtypes.Config{
    ReplacePeers: true,
    PrivateKey:   &privateKey,
    ListenPort:   &data.ListenPort,
    Peers:        peers,
}
i.log.Debugf("%+v", config)
err = i.client.ConfigureDevice(i.tun.GetInterfaceName(), config)
if err != nil {
    i.log.Error(err)
    return err
}

Some context: i'm using wireguard-go to create userspace network device
and wgctrl to add/delete peers; versions:

[golang.zx2c4.com/wireguard](http://golang.zx2c4.com/wireguard) v0.0.0-20231211153847-12269c276173
[golang.zx2c4.com/wireguard/wgctrl](http://golang.zx2c4.com/wireguard/wgctrl) v0.0.0-20230429144221-925a1e7659e6

System: Windows 10 Enterprise / amd64

Here is sample config structure from debug log:

"{
    PrivateKey:sCf8HRn1x2N1Lq6wrHyGYBs6Ydp/48KF74u6ok7LNlk=
    ListenPort:0xc0001dc040
    FirewallMark:<nil>
    ReplacePeers:true
    Peers:[
        {
            PublicKey:VWpriu6779/kWXjdeKDNwcKP0wgIAtA6/2/rNSmuDyE=
            Remove:false
            UpdateOnly:false
            PresharedKey:<nil>
            Endpoint:????:8030
            PersistentKeepaliveInterval:15s
            ReplaceAllowedIPs:true
            AllowedIPs:[{IP:0.0.0.0 Mask:80000000}]
        }
    ]
}

Peer list is always empty after executing ConfigureDevice

Here is log samples:

time="2024-04-11T15:58:36+03:00" level=trace msg="UAPI: Updating private key"
time="2024-04-11T15:58:36+03:00" level=trace msg="UAPI: Updating listen port"
time="2024-04-11T15:58:36+03:00" level=trace msg="Routine: receive incoming v4 - stopped"
time="2024-04-11T15:58:36+03:00" level=trace msg="Routine: receive incoming v6 - stopped"
time="2024-04-11T15:58:36+03:00" level=trace msg="UDP bind has been updated"
time="2024-04-11T15:58:36+03:00" level=trace msg="UAPI: Removing all peers"
time="2024-04-11T15:58:36+03:00" level=trace msg="Routine: receive incoming v4 - started"
time="2024-04-11T15:58:36+03:00" level=trace msg="peer(AAAA…AAAA) - UAPI: Updating endpoint"
time="2024-04-11T15:58:36+03:00" level=trace msg="Routine: receive incoming v6 - started"
time="2024-04-11T15:58:36+03:00" level=trace msg="peer(AAAA…AAAA) - UAPI: Updating persistent keepalive interval"
time="2024-04-11T15:58:36+03:00" level=trace msg="peer(AAAA…AAAA) - UAPI: Removing all allowedips"
time="2024-04-11T15:58:36+03:00" level=trace msg="peer(AAAA…AAAA) - UAPI: Adding allowedip"

Notice: peer(AAAA…AAAA) after added peer via ConfigureDevice

Facing this problem only on windows, linux/macos tests are successful

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