mirror of
https://github.com/whyvl/wireproxy.git
synced 2025-04-29 19:01:42 +02:00
fix multi-value fields
This commit is contained in:
parent
06dfef794f
commit
68b99e2c17
2 changed files with 27 additions and 20 deletions
43
config.go
43
config.go
|
@ -14,7 +14,7 @@ import (
|
||||||
|
|
||||||
type DeviceConfig struct {
|
type DeviceConfig struct {
|
||||||
SelfSecretKey string
|
SelfSecretKey string
|
||||||
SelfEndpoint *netip.Addr
|
SelfEndpoint []netip.Addr
|
||||||
PeerPublicKey string
|
PeerPublicKey string
|
||||||
PeerEndpoint string
|
PeerEndpoint string
|
||||||
DNS []netip.Addr
|
DNS []netip.Addr
|
||||||
|
@ -102,14 +102,14 @@ func encodeBase64ToHex(key string) (string, error) {
|
||||||
return hex.EncodeToString(decoded), nil
|
return hex.EncodeToString(decoded), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCommaSeperatedNetIP(section *ini.Section, keyName string) ([]netip.Addr, error) {
|
func parseNetIP(section *ini.Section, keyName string) ([]netip.Addr, error) {
|
||||||
key := section.Key(keyName)
|
key := section.Key(keyName)
|
||||||
if key == nil {
|
if key == nil {
|
||||||
return []netip.Addr{}, nil
|
return []netip.Addr{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ips := []netip.Addr{}
|
ips := []netip.Addr{}
|
||||||
for _, str := range strings.Split(key.String(), ",") {
|
for _, str := range key.StringsWithShadows(",") {
|
||||||
str = strings.TrimSpace(str)
|
str = strings.TrimSpace(str)
|
||||||
ip, err := netip.ParseAddr(str)
|
ip, err := netip.ParseAddr(str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -120,23 +120,27 @@ func parseCommaSeperatedNetIP(section *ini.Section, keyName string) ([]netip.Add
|
||||||
return ips, nil
|
return ips, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCIDRNetIP(section *ini.Section, keyName string) (*netip.Addr, error) {
|
func parseCIDRNetIP(section *ini.Section, keyName string) ([]netip.Addr, error) {
|
||||||
prefixString, err := parseString(section, keyName)
|
key := section.Key(keyName)
|
||||||
if err != nil {
|
if key == nil {
|
||||||
return nil, err
|
return []netip.Addr{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
prefix, err := netip.ParsePrefix(prefixString)
|
ips := []netip.Addr{}
|
||||||
if err != nil {
|
for _, str := range key.StringsWithShadows(",") {
|
||||||
return nil, err
|
prefix, err := netip.ParsePrefix(str)
|
||||||
}
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
addr := prefix.Addr()
|
addr := prefix.Addr()
|
||||||
if prefix.Bits() != addr.BitLen() {
|
if prefix.Bits() != addr.BitLen() {
|
||||||
return nil, errors.New("interface address subnet should be /32 for IPv4 and /128 for IPv6")
|
return nil, errors.New("interface address subnet should be /32 for IPv4 and /128 for IPv6")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &addr, nil
|
ips = append(ips, addr)
|
||||||
|
}
|
||||||
|
return ips, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveIP(ip string) (*net.IPAddr, error) {
|
func resolveIP(ip string) (*net.IPAddr, error) {
|
||||||
|
@ -176,7 +180,7 @@ func ParseInterface(cfg *ini.File, device *DeviceConfig) error {
|
||||||
}
|
}
|
||||||
device.SelfSecretKey = privKey
|
device.SelfSecretKey = privKey
|
||||||
|
|
||||||
dns, err := parseCommaSeperatedNetIP(section, "DNS")
|
dns, err := parseNetIP(section, "DNS")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -343,7 +347,10 @@ func ParseSocks5Config(cfg *ini.File) ([]Socks5Config, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseConfig(path string) (*Configuration, error) {
|
func ParseConfig(path string) (*Configuration, error) {
|
||||||
cfg, err := ini.InsensitiveLoad(path)
|
cfg, err := ini.LoadSources(ini.LoadOptions{
|
||||||
|
Insensitive: true,
|
||||||
|
AllowShadows: true,
|
||||||
|
}, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
type DeviceSetting struct {
|
type DeviceSetting struct {
|
||||||
ipcRequest string
|
ipcRequest string
|
||||||
dns []netip.Addr
|
dns []netip.Addr
|
||||||
deviceAddr *netip.Addr
|
deviceAddr []netip.Addr
|
||||||
mtu int
|
mtu int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ func StartWireguard(conf *DeviceConfig) (*netstack.Net, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
tun, tnet, err := netstack.CreateNetTUN([]netip.Addr{*(setting.deviceAddr)}, setting.dns, setting.mtu)
|
tun, tnet, err := netstack.CreateNetTUN(setting.deviceAddr, setting.dns, setting.mtu)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue