初版功能完成
ci / Go checks (ubuntu-latest) (push) Has been cancelled
ci / Go checks (windows-latest) (push) Has been cancelled

This commit is contained in:
qsc
2026-08-29 13:12:17 +08:00
commit 142e5dc7d6
217 changed files with 21313 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
// Package serverwg creates and configures the Linux kernel WireGuard hub.
package serverwg
import (
"errors"
"fmt"
"net/netip"
)
const DefaultInterfaceName = "wg0"
// Config contains kernel interface and host-forwarding settings.
type Config struct {
InterfaceName string
Address netip.Prefix
ListenPort int
PrivateKeyPath string
EnableForwarding bool
IPTablesPath string
}
func (c Config) validate() error {
if c.InterfaceName == "" {
return errors.New("WireGuard interface name must not be empty")
}
if !c.Address.Addr().Is4() || c.Address.Bits() > 30 {
return errors.New("WireGuard address must be an IPv4 interface prefix")
}
if c.Address.Addr() == c.Address.Masked().Addr() {
return errors.New("WireGuard address must be a usable host address, not its network address")
}
if c.ListenPort < 1 || c.ListenPort > 65535 {
return fmt.Errorf("WireGuard listen port %d is outside 1..65535", c.ListenPort)
}
if c.PrivateKeyPath == "" {
return errors.New("Server private key path must not be empty")
}
return nil
}
// Peer is one Node's cryptokey-routing entry.
type Peer struct {
PublicKey string
Address netip.Addr
}