6a696e03e7
* migrate to golang.zx2c4.com/wireguard/wgctrl This commit introduces the usage of wgctrl. It avoids the usage of exec calls of the wg command and parsing the output of `wg show`. Signed-off-by: leonnicolas <leonloechner@gmx.de> * vendor wgctrl Signed-off-by: leonnicolas <leonloechner@gmx.de> * apply suggestions from code review Remove wireguard.Enpoint struct and use net.UDPAddr for the resolved endpoint and addr string (dnsanme:port) if a DN was supplied. Signed-off-by: leonnicolas <leonloechner@gmx.de> * pkg/*: use wireguard.Enpoint This commit introduces the wireguard.Enpoint struct. It encapsulates a DN name with port and a net.UPDAddr. The fields are private and only accessible over exported Methods to avoid accidental modification. Also iptables.GetProtocol is improved to avoid ipv4 rules being applied by `ip6tables`. Signed-off-by: leonnicolas <leonloechner@gmx.de> * pkg/wireguard/conf_test.go: add tests for Endpoint Signed-off-by: leonnicolas <leonloechner@gmx.de> * cmd/kg/main.go: validate port range Signed-off-by: leonnicolas <leonloechner@gmx.de> * add suggestions from review Signed-off-by: leonnicolas <leonloechner@gmx.de> * pkg/mesh/mesh.go: use Equal func Implement an Equal func for Enpoint and use it instead of comparing strings. Signed-off-by: leonnicolas <leonloechner@gmx.de> * cmd/kgctl/main.go: check port range Signed-off-by: leonnicolas <leonloechner@gmx.de> * vendor Signed-off-by: leonnicolas <leonloechner@gmx.de>
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
// Copyright 2021 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
//go:build (darwin && !ios) || linux
|
|
// +build darwin,!ios linux
|
|
|
|
package unix
|
|
|
|
import (
|
|
"unsafe"
|
|
|
|
"golang.org/x/sys/internal/unsafeheader"
|
|
)
|
|
|
|
// SysvShmAttach attaches the Sysv shared memory segment associated with the
|
|
// shared memory identifier id.
|
|
func SysvShmAttach(id int, addr uintptr, flag int) ([]byte, error) {
|
|
addr, errno := shmat(id, addr, flag)
|
|
if errno != nil {
|
|
return nil, errno
|
|
}
|
|
|
|
// Retrieve the size of the shared memory to enable slice creation
|
|
var info SysvShmDesc
|
|
|
|
_, err := SysvShmCtl(id, IPC_STAT, &info)
|
|
if err != nil {
|
|
// release the shared memory if we can't find the size
|
|
|
|
// ignoring error from shmdt as there's nothing sensible to return here
|
|
shmdt(addr)
|
|
return nil, err
|
|
}
|
|
|
|
// Use unsafe to convert addr into a []byte.
|
|
// TODO: convert to unsafe.Slice once we can assume Go 1.17
|
|
var b []byte
|
|
hdr := (*unsafeheader.Slice)(unsafe.Pointer(&b))
|
|
hdr.Data = unsafe.Pointer(addr)
|
|
hdr.Cap = int(info.Segsz)
|
|
hdr.Len = int(info.Segsz)
|
|
return b, nil
|
|
}
|
|
|
|
// SysvShmDetach unmaps the shared memory slice returned from SysvShmAttach.
|
|
//
|
|
// It is not safe to use the slice after calling this function.
|
|
func SysvShmDetach(data []byte) error {
|
|
if len(data) == 0 {
|
|
return EINVAL
|
|
}
|
|
|
|
return shmdt(uintptr(unsafe.Pointer(&data[0])))
|
|
}
|
|
|
|
// SysvShmGet returns the Sysv shared memory identifier associated with key.
|
|
// If the IPC_CREAT flag is specified a new segment is created.
|
|
func SysvShmGet(key, size, flag int) (id int, err error) {
|
|
return shmget(key, size, flag)
|
|
}
|