Skip to content

Commit

Permalink
Fixes with DAITA integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
acb-mv committed Aug 14, 2024
1 parent fec8420 commit c6d191d
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions Sources/WireGuardKitGo/api-apple.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func addTunnelFromDevice(dev *device.Device, entryDev *device.Device, settings s

// Enable DAITA if DAITA parameters are passed through
if maybeNotMachines != nil {
returnValue := configureDaita(entryDev, entryConfigString, C.GoString(maybeNotMachines), maybeNotMaxEvents, maybeNotMaxActions)
returnValue := configureDaita(entryDev, entrySettings, C.GoString(maybeNotMachines), maybeNotMaxEvents, maybeNotMaxActions)
if returnValue != 0 {
return returnValue
}
Expand Down Expand Up @@ -254,26 +254,6 @@ func wgTurnOnMultihopInner(tun tun.Device, exitSettings *C.char, entrySettings *
return addTunnelFromDevice(exitDev, entryDev, exitConfigString, entryConfigString, nil, logger, maybeNotMachines, maybeNotMaxEvents, maybeNotMaxActions)
}

func parseFirstPubkeyFromConfig(config string) *device.NoisePublicKey {
scanner := bufio.NewScanner(strings.NewReader(config))
for scanner.Scan() {
line := scanner.Text()
key, value, ok := strings.Cut(line, "=")
if !ok {
continue
}

if key == "public_key" {
pubkey, err := hex.DecodeString(value)
if err == nil {
key := device.NoisePublicKey(pubkey)
return &key
}
}
}
return nil
}

//export wgTurnOnMultihop
func wgTurnOnMultihop(exitSettings *C.char, entrySettings *C.char, privateIp *C.char, tunFd int32, maybenotMachines *C.char, maybeNotMaxEvents uint32, maybeNotMaxActons uint32) int32 {
logger := &device.Logger{
Expand Down Expand Up @@ -309,10 +289,10 @@ func wgTurnOn(settings *C.char, tunFd int32, maybeNotMachines *C.char, maybeNotM
logger.Verbosef("Attaching to interface")
dev := device.NewDevice(tun, conn.NewStdNetBind(), logger)

return addTunnelFromDevice(dev, nil, C.GoString(settings), "", nil, logger)
return addTunnelFromDevice(dev, nil, C.GoString(settings), "", nil, logger, maybeNotMachines, maybeNotMaxEvents, maybeNotMaxActions)
}

func wgTurnOnIANFromExistingTunnel(tun tun.Device, settings string, privateAddr netip.Addr) int32 {
func wgTurnOnIANFromExistingTunnel(tun tun.Device, settings string, privateAddr netip.Addr, maybeNotMachines *C.char, maybeNotMaxEvents uint32, maybeNotMaxActions uint32) int32 {
logger := &device.Logger{
Verbosef: CLogger(0).Printf,
Errorf: CLogger(1).Printf,
Expand All @@ -336,11 +316,11 @@ func wgTurnOnIANFromExistingTunnel(tun tun.Device, settings string, privateAddr
logger.Verbosef("Attaching to interface")
dev := device.NewDevice(&wrapper, conn.NewStdNetBind(), logger)

return addTunnelFromDevice(dev, nil, settings, "", virtualNet, logger) // FIXME
return addTunnelFromDevice(dev, nil, settings, "", virtualNet, logger, maybeNotMachines, maybeNotMaxEvents, maybeNotMaxActions) // FIXME
}

//export wgTurnOnIAN
func wgTurnOnIAN(settings *C.char, tunFd int32, privateIP *C.char) int32 {
func wgTurnOnIAN(settings *C.char, tunFd int32, privateIP *C.char, maybeNotMachines *C.char, maybeNotMaxEvents uint32, maybeNotMaxActions uint32) int32 {
logger := &device.Logger{
Verbosef: CLogger(0).Printf,
Errorf: CLogger(1).Printf,
Expand All @@ -358,7 +338,7 @@ func wgTurnOnIAN(settings *C.char, tunFd int32, privateIP *C.char) int32 {
return errCode
}

return wgTurnOnIANFromExistingTunnel(tun, C.GoString(settings), privateAddr)
return wgTurnOnIANFromExistingTunnel(tun, C.GoString(settings), privateAddr, maybeNotMachines, maybeNotMaxEvents, maybeNotMaxActions)
}

//export wgTurnOff
Expand Down

0 comments on commit c6d191d

Please sign in to comment.