1
0
mirror of https://git.zx2c4.com/wireguard-go synced 2024-11-15 01:05:15 +01:00

Fix up errors and paths

This commit is contained in:
Jason A. Donenfeld 2019-02-05 22:06:25 +09:00
parent f7f63765d1
commit c599bf9497
3 changed files with 12 additions and 10 deletions

View File

@ -7,9 +7,10 @@ package main
import ( import (
"fmt" "fmt"
"git.zx2c4.com/wireguard-go/tun"
"os" "os"
"os/signal" "os/signal"
"git.zx2c4.com/wireguard-go/tun"
) )
const ( const (
@ -18,8 +19,7 @@ const (
) )
func main() { func main() {
if len(os.Args) != 2 {
if len(os.Args) != 1 {
os.Exit(ExitSetupFailed) os.Exit(ExitSetupFailed)
} }
//configFile := os.Args[1] //configFile := os.Args[1]
@ -44,6 +44,7 @@ func main() {
} }
device := NewDevice(tun, logger) device := NewDevice(tun, logger)
device.Up()
logger.Info.Println("Device started") logger.Info.Println("Device started")
uapi, err := UAPIListen(interfaceName) uapi, err := UAPIListen(interfaceName)

View File

@ -53,7 +53,7 @@ type nativeTun struct {
} }
func CreateTUN(ifname string) (TUNDevice, error) { func CreateTUN(ifname string) (TUNDevice, error) {
signalNameUTF16, err := windows.UTF16PtrFromString(fmt.Sprintf("Global\\TUN_EVENT_%s", ifname)) signalNameUTF16, err := windows.UTF16PtrFromString(fmt.Sprintf("Global\\WINTUN_EVENT_%s", ifname))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -61,7 +61,7 @@ func CreateTUN(ifname string) (TUNDevice, error) {
// Create instance. // Create instance.
tun := &nativeTun{ tun := &nativeTun{
ifname: ifname, ifname: ifname,
tunName: fmt.Sprintf("\\\\.\\Global\\TUN_%s_DEVICE", ifname), tunName: fmt.Sprintf("\\\\.\\Global\\WINTUN_DEVICE_%s", ifname),
signalName: signalNameUTF16, signalName: signalNameUTF16,
events: make(chan TUNEvent, 10), events: make(chan TUNEvent, 10),
errors: make(chan error, 1), errors: make(chan error, 1),
@ -90,7 +90,7 @@ func (tun *nativeTun) openTUN() error {
case windows.WAIT_TIMEOUT: case windows.WAIT_TIMEOUT:
continue continue
default: default:
return fmt.Errorf("unexpected result from WaitForSingleObject:", e) return errors.New("Unexpected result from WaitForSingleObject: " + e.Error())
} }
} }
@ -98,7 +98,7 @@ func (tun *nativeTun) openTUN() error {
event, err := windows.OpenEvent(windows.SYNCHRONIZE, false, tun.signalName) event, err := windows.OpenEvent(windows.SYNCHRONIZE, false, tun.signalName)
if err != nil { if err != nil {
file.Close() file.Close()
return fmt.Errorf("opening interface data ready event failed:", err) return errors.New("Opening interface data ready event failed: " + err.Error())
} }
tun.tunFile = file tun.tunFile = file
@ -198,7 +198,7 @@ func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
// Buffer was not full. Wait for the interface data or user close. // Buffer was not full. Wait for the interface data or user close.
r, err := windows.WaitForMultipleObjects(tun.signals[:], false, windows.INFINITE) r, err := windows.WaitForMultipleObjects(tun.signals[:], false, windows.INFINITE)
if err != nil { if err != nil {
return 0, fmt.Errorf("waiting for data failed:", err) return 0, errors.New("Waiting for data failed: " + err.Error())
} }
switch r { switch r {
case windows.WAIT_OBJECT_0 + TUN_SIGNAL_DATA_AVAIL: case windows.WAIT_OBJECT_0 + TUN_SIGNAL_DATA_AVAIL:
@ -250,10 +250,10 @@ func (tun *nativeTun) flush() error {
func (tun *nativeTun) putTunPacket(buff []byte) error { func (tun *nativeTun) putTunPacket(buff []byte) error {
size := len(buff) size := len(buff)
if size == 0 { if size == 0 {
return errors.New("empty packet") return errors.New("Empty packet")
} }
if size > TUN_MAX_PACKET_SIZE { if size > TUN_MAX_PACKET_SIZE {
return errors.New("packet too big") return errors.New("Packet too big")
} }
if tun.wrBuff.numPackets >= TUN_MAX_PACKET_EXCHANGE { if tun.wrBuff.numPackets >= TUN_MAX_PACKET_EXCHANGE {

View File

@ -1,2 +1,3 @@
package main package main
const WireGuardGoVersion = "0.0.20181222" const WireGuardGoVersion = "0.0.20181222"