Closed apognu closed 5 years ago
I don't believe this is the actual problem; when spelunking through wg code, I noticed it was making a system call ("getnameinfo"? IIRC) to resolve the endpoint address in some way. I forgot to look into it further, but this issue is a good reminder to do so.
However it's totally possible that I missed something, and maybe my unsafe cast isn't quite right.
wg is not the only tool reporting the wrong port. My own tools (in Python and Go) do as well.
And the issue appeared as soon as I migrated from directly using genetlink to wireguardctrl.
I'll take a look today, but PRs welcome if you find it first. This sounds like an endianness issue.
I think you're reversing the two bytes of the port number.
10000 is 00100111 00010000 in binary. 4135 is 00010000 00100111
So yes, endianness issue probably. I'll look if I can find the issue.
Should be fixed as of #16.
Seems to work as expected now:
cfg := wgtypes.Config{
ReplacePeers: true,
Peers: []wgtypes.PeerConfig{{
PublicKey: priv.PublicKey(),
Endpoint: &net.UDPAddr{
IP: net.IPv4(192, 168, 1, 4),
Port: 58575,
},
}},
}
if err := c.ConfigureDevice(d.Name, cfg); err != nil {
log.Fatalf("failed to configure: %v", err)
}
$ sudo ./wgctrl
interface: wg0
public key: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
private key: (hidden)
listening port: 0
peer: R65jHoT6fhrk8OFS/L2KiDEP/O/+XrCGfOGzUG3x1j0=
endpoint: 192.168.1.4:58575
allowed ips:
latest handshake: 1969-12-31 19:00:00 -0500 EST
transfer: 0 B received, 0 B sent
Yes, everything's good on my end as well.
Hi,
The port of a peer endpoint seems to be transmitted incorrectly to netlink, here are the values set in the
PeerConfig
(left) struct and the resulting value as reported bywg
(right) after callingConfigureDevice
: