Skip to content

Commit 8569131

Browse files
committed
Unmap 4in6 addresses to maintain previous compatibility
Signed-off-by: MrMelon54 <[email protected]>
1 parent 73d5b38 commit 8569131

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

internal/wglinux/configure_linux.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,15 @@ func encodeSockaddr(endpoint net.UDPAddr) func() ([]byte, error) {
220220
return nil, fmt.Errorf("wglinux: invalid endpoint IP: %s", endpoint.IP.String())
221221
}
222222

223+
// Unmap 4in6 addresses to maintain previous compatibility
224+
addr := addrPort.Addr().Unmap()
225+
223226
// Is this an IPv6 address?
224-
if addrPort.Addr().Is6() {
227+
if addr.Is6() {
225228
sa := unix.RawSockaddrInet6{
226229
Family: unix.AF_INET6,
227230
Port: sockaddrPort(endpoint.Port),
228-
Addr: addrPort.Addr().As16(),
231+
Addr: addr.As16(),
229232
}
230233

231234
return (*(*[unix.SizeofSockaddrInet6]byte)(unsafe.Pointer(&sa)))[:], nil
@@ -234,7 +237,7 @@ func encodeSockaddr(endpoint net.UDPAddr) func() ([]byte, error) {
234237
sa := unix.RawSockaddrInet4{
235238
Family: unix.AF_INET,
236239
Port: sockaddrPort(endpoint.Port),
237-
Addr: addrPort.Addr().As4(),
240+
Addr: addr.As4(),
238241
}
239242

240243
return (*(*[unix.SizeofSockaddrInet4]byte)(unsafe.Pointer(&sa)))[:], nil
@@ -249,16 +252,19 @@ func encodeAllowedIPs(ipns []netip.Prefix) func(ae *netlink.AttributeEncoder) er
249252
return fmt.Errorf("wglinux: invalid allowed IP: %s", ipn.Addr())
250253
}
251254

255+
// Unmap 4in6 addresses to maintain previous compatibility
256+
addr := ipn.Addr().Unmap()
257+
252258
family := uint16(unix.AF_INET6)
253-
if ipn.Addr().Is4() {
259+
if addr.Is4() {
254260
// Make sure address is 4 bytes if IPv4.
255261
family = unix.AF_INET
256262
}
257263

258264
// Netlink arrays use type as an array index.
259265
ae.Nested(uint16(i), func(nae *netlink.AttributeEncoder) error {
260266
nae.Uint16(unix.WGALLOWEDIP_A_FAMILY, family)
261-
nae.Bytes(unix.WGALLOWEDIP_A_IPADDR, ipn.Addr().AsSlice())
267+
nae.Bytes(unix.WGALLOWEDIP_A_IPADDR, addr.AsSlice())
262268

263269
ones := ipn.Bits()
264270
nae.Uint8(unix.WGALLOWEDIP_A_CIDR_MASK, uint8(ones))

0 commit comments

Comments
 (0)