]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
global: begin modularization
authorJason A. Donenfeld <Jason@zx2c4.com>
Sun, 3 Mar 2019 03:04:41 +0000 (04:04 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sun, 3 Mar 2019 04:00:40 +0000 (05:00 +0100)
44 files changed:
Makefile
device/allowedips.go [moved from allowedips.go with 99% similarity]
device/allowedips_rand_test.go [moved from allowedips_rand_test.go with 99% similarity]
device/allowedips_test.go [moved from allowedips_test.go with 99% similarity]
device/bind_test.go [moved from bind_test.go with 98% similarity]
device/conn.go [moved from conn.go with 99% similarity]
device/conn_default.go [moved from conn_default.go with 99% similarity]
device/conn_linux.go [moved from conn_linux.go with 99% similarity]
device/constants.go [moved from constants.go with 98% similarity]
device/cookie.go [moved from cookie.go with 99% similarity]
device/cookie_test.go [moved from cookie_test.go with 99% similarity]
device/device.go [moved from device.go with 99% similarity]
device/device_test.go [moved from device_test.go with 98% similarity]
device/endpoint_test.go [moved from endpoint_test.go with 98% similarity]
device/indextable.go [moved from indextable.go with 99% similarity]
device/ip.go [moved from ip.go with 96% similarity]
device/kdf_test.go [moved from kdf_test.go with 99% similarity]
device/keypair.go [moved from keypair.go with 98% similarity]
device/logger.go [moved from logger.go with 98% similarity]
device/mark_default.go [moved from mark_default.go with 93% similarity]
device/mark_unix.go [moved from mark_unix.go with 98% similarity]
device/misc.go [moved from misc.go with 97% similarity]
device/noise-helpers.go [moved from noise-helpers.go with 99% similarity]
device/noise-protocol.go [moved from noise-protocol.go with 99% similarity]
device/noise-types.go [moved from noise-types.go with 99% similarity]
device/noise_test.go [moved from noise_test.go with 99% similarity]
device/peer.go [moved from peer.go with 99% similarity]
device/pools.go [moved from pools.go with 99% similarity]
device/queueconstants.go [moved from queueconstants.go with 96% similarity]
device/receive.go [moved from receive.go with 99% similarity]
device/send.go [moved from send.go with 99% similarity]
device/timers.go [moved from timers.go with 99% similarity]
device/tun.go [moved from tun.go with 98% similarity]
device/uapi.go [moved from uapi.go with 87% similarity]
device/version.go [new file with mode: 0644]
go.mod
go.sum
ipc/uapi_bsd.go [moved from uapi_bsd.go with 95% similarity]
ipc/uapi_linux.go [moved from uapi_linux.go with 94% similarity]
ipc/uapi_windows.go [moved from uapi_windows.go with 90% similarity]
main.go
main_windows.go
tun/helper_test.go [moved from helper_test.go with 99% similarity]
tun/tun_windows.go

index cff8a7fdefaa43d6359b645f542f6c488e9a0688..69a81003ef62452cdf44710532ed8c19d1876a0a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -24,10 +24,10 @@ MAKEFLAGS += --no-print-directory
 generate-version-and-build:
        @export GIT_CEILING_DIRECTORIES="$(realpath $(CURDIR)/..)" && \
        tag="$$(git describe --dirty 2>/dev/null)" && \
-       ver="$$(printf 'package main\nconst WireGuardGoVersion = "%s"\n' "$$tag")" && \
-       [ "$$(cat version.go 2>/dev/null)" != "$$ver" ] && \
-       echo "$$ver" > version.go && \
-       git update-index --assume-unchanged version.go || true
+       ver="$$(printf 'package device\nconst WireGuardGoVersion = "%s"\n' "$$tag")" && \
+       [ "$$(cat device/version.go 2>/dev/null)" != "$$ver" ] && \
+       echo "$$ver" > device/version.go && \
+       git update-index --assume-unchanged device/version.go || true
        @$(MAKE) wireguard-go
 
 wireguard-go: $(wildcard *.go) $(wildcard */*.go)
similarity index 99%
rename from allowedips.go
rename to device/allowedips.go
index 2c4f6017402806bcaf39f210eaf5e40a1d20a550..efc27c00978477bcafc5cf9ff9819b40aebd9f26 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "errors"
similarity index 99%
rename from allowedips_rand_test.go
rename to device/allowedips_rand_test.go
index 56a31c418a25f86014dc8e8913502828605197c0..59c10f7a51a89d6b64f6f1e3da4b5ea634b33cc8 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "math/rand"
similarity index 99%
rename from allowedips_test.go
rename to device/allowedips_test.go
index ca694abb494d202fb68f55bb583915de802530f3..075ff0690e4dcfc1a14a874c16d82206d6f6b981 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "math/rand"
similarity index 98%
rename from bind_test.go
rename to device/bind_test.go
index c5346461237b4b6367bcfdaa06798327111d4a8d..0c2e2cfd282433f9e29303aabb85513ae66b1cc2 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import "errors"
 
similarity index 99%
rename from conn.go
rename to device/conn.go
index b19a9c2eaa2ebb39b41142a0c4181becae230a30..25946800e86dfeb14dd2bf91556c9e48704e78e9 100644 (file)
--- a/conn.go
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "errors"
@@ -177,4 +177,4 @@ func (device *Device) BindClose() error {
        err := unsafeCloseBind(device)
        device.net.Unlock()
        return err
-}
+}
\ No newline at end of file
similarity index 99%
rename from conn_default.go
rename to device/conn_default.go
index 6f17de5b61f191f927ff4b4f637840b6ca53c0fe..8a86719a3ad1dd734079932aa42a153b31d1f27a 100644 (file)
@@ -5,7 +5,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "net"
similarity index 99%
rename from conn_linux.go
rename to device/conn_linux.go
index d3dbb9889af2e8890b67798dc16e4b3a8c26068d..49949d575e59dcdb2a51a3c3f2bcb4b7c1bd9b65 100644 (file)
@@ -14,7 +14,7 @@
  * So this code is remains platform dependent.
  */
 
-package main
+package device
 
 import (
        "errors"
similarity index 98%
rename from constants.go
rename to device/constants.go
index ab93e5fdcd815c87a7d532d0914a44d126e3398b..27d910f11818ddf33306ae43408b8cfb2f7645a0 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "time"
similarity index 99%
rename from cookie.go
rename to device/cookie.go
index c648bf1c4c3e6dfa53e529bf1349e6a43ee7a9cd..2f210679e701afcb9c9546381071f180c3fd0f27 100644 (file)
--- a/cookie.go
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "crypto/hmac"
similarity index 99%
rename from cookie_test.go
rename to device/cookie_test.go
index 05862601c380ebc7e7d03e928b8bd7bfbe0c8449..79a6a86c58a05109d7c0a194fc6882340cefaed6 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "testing"
similarity index 99%
rename from device.go
rename to device/device.go
index 18e1138cd01c3ff41edb4201d96b5fa3a85ece65..d6c96d6905c28e8c8c7ae44552f835d6bd4991d7 100644 (file)
--- a/device.go
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "golang.zx2c4.com/wireguard/ratelimiter"
similarity index 98%
rename from device_test.go
rename to device/device_test.go
index df0ba69b903b0a1daf708bb8430eabc87df980d9..db5a3c04429bbac038fb400eacb5c9a973e26c61 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 /* Create two device instances and simulate full WireGuard interaction
  * without network dependencies
similarity index 98%
rename from endpoint_test.go
rename to device/endpoint_test.go
index fe6677c093f87c4129dea1120e236e9f81c485e7..1896790360b64287018fae86d1ebc27f969211f2 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "math/rand"
similarity index 99%
rename from indextable.go
rename to device/indextable.go
index 046113c111601fb408ead5b9c2db34016f609328..4cba97013c43e3f3529855a6dcd1e0feeaef6fce 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "crypto/rand"
similarity index 96%
rename from ip.go
rename to device/ip.go
index e2e0ff38758aa39b480d87e91ed31feb403f424a..9d4fb746ad687b5f96966b9ba6912d756e52351c 100644 (file)
--- a/ip.go
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "net"
similarity index 99%
rename from kdf_test.go
rename to device/kdf_test.go
index 3b9a8bef9b833a26dc189feb953f494c905cb5b3..11ea8d5ec790c5fcaa55055b4381d51831688806 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "encoding/hex"
similarity index 98%
rename from keypair.go
rename to device/keypair.go
index af10a58987472684fc56850cbb4aaf28f97bf2ef..a9fbfce92cdf032bac316e13298234b375573268 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "crypto/cipher"
similarity index 98%
rename from logger.go
rename to device/logger.go
index 00b1c7d80ce8e7a8f73a9284bd3d160304d26b04..7c8b704300ebb0b01a87f6ba26a7b8d03a61d367 100644 (file)
--- a/logger.go
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "io"
similarity index 93%
rename from mark_default.go
rename to device/mark_default.go
index 7149d691aab3158a2ff5be33ad839cafdf29146e..76b101554e3eb0a8979db7534123e4602ee6ce86 100644 (file)
@@ -5,7 +5,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 func (bind *NativeBind) SetMark(mark uint32) error {
        return nil
similarity index 98%
rename from mark_unix.go
rename to device/mark_unix.go
index 0ae62b7af864c5725d80ccf6424bcb449886a32c..ee64cc9facb351e8b94af6d45206bfec9111a33f 100644 (file)
@@ -5,7 +5,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "golang.org/x/sys/unix"
similarity index 97%
rename from misc.go
rename to device/misc.go
index 6786cb5633cc95cd19644e58f59d9aa1494fb48b..a38d1c1003bb428173aa0f59d032808e108ded7e 100644 (file)
--- a/misc.go
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "sync/atomic"
similarity index 99%
rename from noise-helpers.go
rename to device/noise-helpers.go
index af11f0995f41261a569d7bccf008523017abd921..4b09bf36cb4dcda6293e2cc90c9a239140f91683 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "crypto/hmac"
similarity index 99%
rename from noise-protocol.go
rename to device/noise-protocol.go
index fb4341369748588e0d35fe2b528058166bce5d0a..73826e15bc31e3d40d771c86fd6d253cf59c5823 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "errors"
similarity index 99%
rename from noise-types.go
rename to device/noise-types.go
index 902905e640f81e8d362176d57570470365deb2a8..82b12c1cc61922103515590de2af58eade8a3b5f 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "crypto/subtle"
similarity index 99%
rename from noise_test.go
rename to device/noise_test.go
index 116057ad0242c5ab0c67478311d8cfba17462b21..6ba3f2e6246e39a1293c69e5cf598fd35ad7a359 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "bytes"
similarity index 99%
rename from peer.go
rename to device/peer.go
index f0215657c0555adae8cbb81853c05bd643f16a0a..af3ef9d726520a3e68ed63a296b5d15b24736701 100644 (file)
--- a/peer.go
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "encoding/base64"
similarity index 99%
rename from pools.go
rename to device/pools.go
index 8a9af0b70dd48bd6b2e5ce20b0116f764669def7..98f4ef1764cb04ee1452e7b60adb0f1af9c5482e 100644 (file)
--- a/pools.go
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import "sync"
 
similarity index 96%
rename from queueconstants.go
rename to device/queueconstants.go
index 0dcdd33cff875579b02cd69a19c40b21e1a5eb00..3e94b7fc2d47be07cd55a88270443ef2ef0f774e 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 /* Implementation specific constants */
 
similarity index 99%
rename from receive.go
rename to device/receive.go
index fb848eb064d7d44466dd97099c2efc91c96c46b8..5c837c1d37c4431404c367c2f0624e182170b1e4 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "bytes"
similarity index 99%
rename from send.go
rename to device/send.go
index b7cac04701385825988a31e105c23ec491f3a112..b4e23c7fddf8567d8523d8eddbb8d61b0f9451ae 100644 (file)
--- a/send.go
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "bytes"
similarity index 99%
rename from timers.go
rename to device/timers.go
index 9c16f1315e19d5102eb7042d2dae3b3d6752e9e7..5f28fcce068dccce4298078f53cb310a91c08810 100644 (file)
--- a/timers.go
@@ -5,7 +5,7 @@
  * This is based heavily on timers.c from the kernel implementation.
  */
 
-package main
+package device
 
 import (
        "math/rand"
similarity index 98%
rename from tun.go
rename to device/tun.go
index 52bfb68198a41a6f9dbbc15161558d38ea3f2e9c..bc5f1f1da6872a84b0bc4afa1405ba65056a1b38 100644 (file)
--- a/tun.go
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "golang.zx2c4.com/wireguard/tun"
similarity index 87%
rename from uapi.go
rename to device/uapi.go
index 4a370b3acb3119db075d330ac7fa82c2688f84d6..5c65917f9061c7086a6659b272f265fbefb595cd 100644 (file)
--- a/uapi.go
@@ -3,11 +3,12 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package device
 
 import (
        "bufio"
        "fmt"
+       "golang.zx2c4.com/wireguard/ipc"
        "io"
        "net"
        "strconv"
@@ -28,7 +29,7 @@ func (s *IPCError) ErrorCode() int64 {
        return s.int64
 }
 
-func ipcGetOperation(device *Device, socket *bufio.Writer) *IPCError {
+func (device *Device) IpcGetOperation(socket *bufio.Writer) *IPCError {
 
        device.log.Debug.Println("UAPI: Processing get operation")
 
@@ -101,14 +102,14 @@ func ipcGetOperation(device *Device, socket *bufio.Writer) *IPCError {
        for _, line := range lines {
                _, err := socket.WriteString(line + "\n")
                if err != nil {
-                       return &IPCError{ipcErrorIO}
+                       return &IPCError{ipc.IpcErrorIO}
                }
        }
 
        return nil
 }
 
-func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
+func (device *Device) IpcSetOperation(socket *bufio.Reader) *IPCError {
        scanner := bufio.NewScanner(socket)
        logError := device.log.Error
        logDebug := device.log.Debug
@@ -128,7 +129,7 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
                }
                parts := strings.Split(line, "=")
                if len(parts) != 2 {
-                       return &IPCError{ipcErrorProtocol}
+                       return &IPCError{ipc.IpcErrorProtocol}
                }
                key := parts[0]
                value := parts[1]
@@ -143,7 +144,7 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
                                err := sk.FromHex(value)
                                if err != nil {
                                        logError.Println("Failed to set private_key:", err)
-                                       return &IPCError{ipcErrorInvalid}
+                                       return &IPCError{ipc.IpcErrorInvalid}
                                }
                                logDebug.Println("UAPI: Updating private key")
                                device.SetPrivateKey(sk)
@@ -155,7 +156,7 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
                                port, err := strconv.ParseUint(value, 10, 16)
                                if err != nil {
                                        logError.Println("Failed to parse listen_port:", err)
-                                       return &IPCError{ipcErrorInvalid}
+                                       return &IPCError{ipc.IpcErrorInvalid}
                                }
 
                                // update port and rebind
@@ -168,7 +169,7 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
 
                                if err := device.BindUpdate(); err != nil {
                                        logError.Println("Failed to set listen_port:", err)
-                                       return &IPCError{ipcErrorPortInUse}
+                                       return &IPCError{ipc.IpcErrorPortInUse}
                                }
 
                        case "fwmark":
@@ -185,14 +186,14 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
 
                                if err != nil {
                                        logError.Println("Invalid fwmark", err)
-                                       return &IPCError{ipcErrorInvalid}
+                                       return &IPCError{ipc.IpcErrorInvalid}
                                }
 
                                logDebug.Println("UAPI: Updating fwmark")
 
                                if err := device.BindSetMark(uint32(fwmark)); err != nil {
                                        logError.Println("Failed to update fwmark:", err)
-                                       return &IPCError{ipcErrorPortInUse}
+                                       return &IPCError{ipc.IpcErrorPortInUse}
                                }
 
                        case "public_key":
@@ -203,14 +204,14 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
                        case "replace_peers":
                                if value != "true" {
                                        logError.Println("Failed to set replace_peers, invalid value:", value)
-                                       return &IPCError{ipcErrorInvalid}
+                                       return &IPCError{ipc.IpcErrorInvalid}
                                }
                                logDebug.Println("UAPI: Removing all peers")
                                device.RemoveAllPeers()
 
                        default:
                                logError.Println("Invalid UAPI device key:", key)
-                               return &IPCError{ipcErrorInvalid}
+                               return &IPCError{ipc.IpcErrorInvalid}
                        }
                }
 
@@ -225,7 +226,7 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
                                err := publicKey.FromHex(value)
                                if err != nil {
                                        logError.Println("Failed to get peer by public key:", err)
-                                       return &IPCError{ipcErrorInvalid}
+                                       return &IPCError{ipc.IpcErrorInvalid}
                                }
 
                                // ignore peer with public key of device
@@ -244,7 +245,7 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
                                        peer, err = device.NewPeer(publicKey)
                                        if err != nil {
                                                logError.Println("Failed to create new peer:", err)
-                                               return &IPCError{ipcErrorInvalid}
+                                               return &IPCError{ipc.IpcErrorInvalid}
                                        }
                                        logDebug.Println(peer, "- UAPI: Created")
                                }
@@ -255,7 +256,7 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
 
                                if value != "true" {
                                        logError.Println("Failed to set remove, invalid value:", value)
-                                       return &IPCError{ipcErrorInvalid}
+                                       return &IPCError{ipc.IpcErrorInvalid}
                                }
                                if !dummy {
                                        logDebug.Println(peer, "- UAPI: Removing")
@@ -276,7 +277,7 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
 
                                if err != nil {
                                        logError.Println("Failed to set preshared key:", err)
-                                       return &IPCError{ipcErrorInvalid}
+                                       return &IPCError{ipc.IpcErrorInvalid}
                                }
 
                        case "endpoint":
@@ -298,7 +299,7 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
 
                                if err != nil {
                                        logError.Println("Failed to set endpoint:", value)
-                                       return &IPCError{ipcErrorInvalid}
+                                       return &IPCError{ipc.IpcErrorInvalid}
                                }
 
                        case "persistent_keepalive_interval":
@@ -310,7 +311,7 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
                                secs, err := strconv.ParseUint(value, 10, 16)
                                if err != nil {
                                        logError.Println("Failed to set persistent keepalive interval:", err)
-                                       return &IPCError{ipcErrorInvalid}
+                                       return &IPCError{ipc.IpcErrorInvalid}
                                }
 
                                old := peer.persistentKeepaliveInterval
@@ -321,7 +322,7 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
                                if old == 0 && secs != 0 {
                                        if err != nil {
                                                logError.Println("Failed to get tun device status:", err)
-                                               return &IPCError{ipcErrorIO}
+                                               return &IPCError{ipc.IpcErrorIO}
                                        }
                                        if device.isUp.Get() && !dummy {
                                                peer.SendKeepalive()
@@ -334,7 +335,7 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
 
                                if value != "true" {
                                        logError.Println("Failed to replace allowedips, invalid value:", value)
-                                       return &IPCError{ipcErrorInvalid}
+                                       return &IPCError{ipc.IpcErrorInvalid}
                                }
 
                                if dummy {
@@ -350,7 +351,7 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
                                _, network, err := net.ParseCIDR(value)
                                if err != nil {
                                        logError.Println("Failed to set allowed ip:", err)
-                                       return &IPCError{ipcErrorInvalid}
+                                       return &IPCError{ipc.IpcErrorInvalid}
                                }
 
                                if dummy {
@@ -364,12 +365,12 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
 
                                if value != "1" {
                                        logError.Println("Invalid protocol version:", value)
-                                       return &IPCError{ipcErrorInvalid}
+                                       return &IPCError{ipc.IpcErrorInvalid}
                                }
 
                        default:
                                logError.Println("Invalid UAPI peer key:", key)
-                               return &IPCError{ipcErrorInvalid}
+                               return &IPCError{ipc.IpcErrorInvalid}
                        }
                }
        }
@@ -377,7 +378,7 @@ func ipcSetOperation(device *Device, socket *bufio.Reader) *IPCError {
        return nil
 }
 
-func ipcHandle(device *Device, socket net.Conn) {
+func (device *Device) IpcHandle(socket net.Conn) {
 
        // create buffered read/writer
 
@@ -403,11 +404,11 @@ func ipcHandle(device *Device, socket net.Conn) {
        switch op {
        case "set=1\n":
                device.log.Debug.Println("UAPI: Set operation")
-               status = ipcSetOperation(device, buffered.Reader)
+               status = device.IpcSetOperation(buffered.Reader)
 
        case "get=1\n":
                device.log.Debug.Println("UAPI: Get operation")
-               status = ipcGetOperation(device, buffered.Writer)
+               status = device.IpcGetOperation(buffered.Writer)
 
        default:
                device.log.Error.Println("Invalid UAPI operation:", op)
diff --git a/device/version.go b/device/version.go
new file mode 100644 (file)
index 0000000..9077cdc
--- /dev/null
@@ -0,0 +1,3 @@
+package device
+
+const WireGuardGoVersion = "0.0.20181222"
diff --git a/go.mod b/go.mod
index cfff5b63c36e3e8decf132be28a2a9f6a0dfd4a5..49076a61d40aa8ba75b95d24b4dbdf5f02e3ad50 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -2,7 +2,7 @@ module golang.zx2c4.com/wireguard
 
 require (
        github.com/Microsoft/go-winio v0.4.11
-       golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67
-       golang.org/x/net v0.0.0-20190213061140-3a22650c66bd
-       golang.org/x/sys v0.0.0-20190213121743-983097b1a8a3
+       golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25
+       golang.org/x/net v0.0.0-20190301231341-16b79f2e4e95
+       golang.org/x/sys v0.0.0-20190302025703-b6889370fb10
 )
diff --git a/go.sum b/go.sum
index c1adf8069c59bb50197dd1cb0a4df98718d2747a..76c5f0881f660536caf8cd9c6547bae6bc061977 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -1,8 +1,9 @@
 github.com/Microsoft/go-winio v0.4.11 h1:zoIOcVf0xPN1tnMVbTtEdI+P8OofVk3NObnwOQ6nK2Q=
 github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
-golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
-golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
-golang.org/x/net v0.0.0-20190213061140-3a22650c66bd h1:HuTn7WObtcDo9uEEU7rEqL0jYthdXAmZ6PP+meazmaU=
-golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/sys v0.0.0-20190213121743-983097b1a8a3 h1:+KlxhGbYkFs8lMfwKn+2ojry1ID5eBSMXprS2u/wqCE=
-golang.org/x/sys v0.0.0-20190213121743-983097b1a8a3/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25 h1:jsG6UpNLt9iAsb0S2AGW28DveNzzgmbXR+ENoPjUeIU=
+golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/net v0.0.0-20190301231341-16b79f2e4e95 h1:fY7Dsw114eJN4boqzVSbpVHO6rTdhq6/GnXeu+PKnzU=
+golang.org/x/net v0.0.0-20190301231341-16b79f2e4e95/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190302025703-b6889370fb10 h1:xQJI9OEiErEQ++DoXOHqEpzsGMrAv2Q2jyCpi7DmfpQ=
+golang.org/x/sys v0.0.0-20190302025703-b6889370fb10/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
similarity index 95%
rename from uapi_bsd.go
rename to ipc/uapi_bsd.go
index d75f4f24304fe7ffab15454ff5112cbc3a363368..f66c3864638d667dd474c6d0eea8d2eddf6e2583 100644 (file)
@@ -5,7 +5,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package ipc
 
 import (
        "errors"
@@ -20,10 +20,10 @@ import (
 var socketDirectory = "/var/run/wireguard"
 
 const (
-       ipcErrorIO        = -int64(unix.EIO)
-       ipcErrorProtocol  = -int64(unix.EPROTO)
-       ipcErrorInvalid   = -int64(unix.EINVAL)
-       ipcErrorPortInUse = -int64(unix.EADDRINUSE)
+       IpcErrorIO        = -int64(unix.EIO)
+       IpcErrorProtocol  = -int64(unix.EPROTO)
+       IpcErrorInvalid   = -int64(unix.EINVAL)
+       IpcErrorPortInUse = -int64(unix.EADDRINUSE)
        socketName        = "%s.sock"
 )
 
similarity index 94%
rename from uapi_linux.go
rename to ipc/uapi_linux.go
index d4b89fcdb1054fbe87db012124d1619dde481dcf..8af3d8ceb861a2d56e68888cc24c8a6087312cdb 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package ipc
 
 import (
        "errors"
@@ -18,10 +18,10 @@ import (
 var socketDirectory = "/var/run/wireguard"
 
 const (
-       ipcErrorIO        = -int64(unix.EIO)
-       ipcErrorProtocol  = -int64(unix.EPROTO)
-       ipcErrorInvalid   = -int64(unix.EINVAL)
-       ipcErrorPortInUse = -int64(unix.EADDRINUSE)
+       IpcErrorIO        = -int64(unix.EIO)
+       IpcErrorProtocol  = -int64(unix.EPROTO)
+       IpcErrorInvalid   = -int64(unix.EINVAL)
+       IpcErrorPortInUse = -int64(unix.EADDRINUSE)
        socketName        = "%s.sock"
 )
 
similarity index 90%
rename from uapi_windows.go
rename to ipc/uapi_windows.go
index 64917f5ad5672bf78b673af5aa79601d3d4c8d56..209d0d2592130b827ef261ff419901971f5df406 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package ipc
 
 import (
        "github.com/Microsoft/go-winio"
@@ -12,10 +12,10 @@ import (
 
 //TODO: replace these with actual standard windows error numbers from the win package
 const (
-       ipcErrorIO        = -int64(5)
-       ipcErrorProtocol  = -int64(71)
-       ipcErrorInvalid   = -int64(22)
-       ipcErrorPortInUse = -int64(98)
+       IpcErrorIO        = -int64(5)
+       IpcErrorProtocol  = -int64(71)
+       IpcErrorInvalid   = -int64(22)
+       IpcErrorPortInUse = -int64(98)
 )
 
 type UAPIListener struct {
diff --git a/main.go b/main.go
index 08f8cc6a45ae56f45869fd041731f97875ef4760..a3a04b838ca8caf906654dbdede222cecead1a58 100644 (file)
--- a/main.go
+++ b/main.go
@@ -9,6 +9,8 @@ package main
 
 import (
        "fmt"
+       "golang.zx2c4.com/wireguard/device"
+       "golang.zx2c4.com/wireguard/ipc"
        "golang.zx2c4.com/wireguard/tun"
        "os"
        "os/signal"
@@ -76,7 +78,7 @@ func warning() {
 
 func main() {
        if len(os.Args) == 2 && os.Args[1] == "--version" {
-               fmt.Printf("wireguard-go v%s\n\nUserspace WireGuard daemon for %s-%s.\nInformation available at https://www.wireguard.com.\nCopyright (C) Jason A. Donenfeld <Jason@zx2c4.com>.\n", WireGuardGoVersion, runtime.GOOS, runtime.GOARCH)
+               fmt.Printf("wireguard-go v%s\n\nUserspace WireGuard daemon for %s-%s.\nInformation available at https://www.wireguard.com.\nCopyright (C) Jason A. Donenfeld <Jason@zx2c4.com>.\n", device.WireGuardGoVersion, runtime.GOOS, runtime.GOARCH)
                return
        }
 
@@ -119,15 +121,15 @@ func main() {
        logLevel := func() int {
                switch os.Getenv("LOG_LEVEL") {
                case "debug":
-                       return LogLevelDebug
+                       return device.LogLevelDebug
                case "info":
-                       return LogLevelInfo
+                       return device.LogLevelInfo
                case "error":
-                       return LogLevelError
+                       return device.LogLevelError
                case "silent":
-                       return LogLevelSilent
+                       return device.LogLevelSilent
                }
-               return LogLevelInfo
+               return device.LogLevelInfo
        }()
 
        // open TUN device (or use supplied fd)
@@ -135,7 +137,7 @@ func main() {
        tun, err := func() (tun.TUNDevice, error) {
                tunFdStr := os.Getenv(ENV_WG_TUN_FD)
                if tunFdStr == "" {
-                       return tun.CreateTUN(interfaceName, DefaultMTU)
+                       return tun.CreateTUN(interfaceName, device.DefaultMTU)
                }
 
                // construct tun device from supplied fd
@@ -151,7 +153,7 @@ func main() {
                }
 
                file := os.NewFile(uintptr(fd), "")
-               return tun.CreateTUNFromFile(file, DefaultMTU)
+               return tun.CreateTUNFromFile(file, device.DefaultMTU)
        }()
 
        if err == nil {
@@ -161,12 +163,12 @@ func main() {
                }
        }
 
-       logger := NewLogger(
+       logger := device.NewLogger(
                logLevel,
                fmt.Sprintf("(%s) ", interfaceName),
        )
 
-       logger.Info.Println("Starting wireguard-go version", WireGuardGoVersion)
+       logger.Info.Println("Starting wireguard-go version", device.WireGuardGoVersion)
 
        logger.Debug.Println("Debug log enabled")
 
@@ -180,7 +182,7 @@ func main() {
        fileUAPI, err := func() (*os.File, error) {
                uapiFdStr := os.Getenv(ENV_WG_UAPI_FD)
                if uapiFdStr == "" {
-                       return UAPIOpen(interfaceName)
+                       return ipc.UAPIOpen(interfaceName)
                }
 
                // use supplied fd
@@ -206,7 +208,7 @@ func main() {
                env = append(env, fmt.Sprintf("%s=4", ENV_WG_UAPI_FD))
                env = append(env, fmt.Sprintf("%s=1", ENV_WG_PROCESS_FOREGROUND))
                files := [3]*os.File{}
-               if os.Getenv("LOG_LEVEL") != "" && logLevel != LogLevelSilent {
+               if os.Getenv("LOG_LEVEL") != "" && logLevel != device.LogLevelSilent {
                        files[0], _ = os.Open(os.DevNull)
                        files[1] = os.Stdout
                        files[2] = os.Stderr
@@ -246,14 +248,14 @@ func main() {
                return
        }
 
-       device := NewDevice(tun, logger)
+       device := device.NewDevice(tun, logger)
 
        logger.Info.Println("Device started")
 
        errs := make(chan error)
        term := make(chan os.Signal, 1)
 
-       uapi, err := UAPIListen(interfaceName, fileUAPI)
+       uapi, err := ipc.UAPIListen(interfaceName, fileUAPI)
        if err != nil {
                logger.Error.Println("Failed to listen on uapi socket:", err)
                os.Exit(ExitSetupFailed)
@@ -266,7 +268,7 @@ func main() {
                                errs <- err
                                return
                        }
-                       go ipcHandle(device, conn)
+                       go device.IpcHandle(conn)
                }
        }()
 
index 7104a204d81b8ffa1148762e9ff8b3ceccae4174..39cdead0d3c76bea52e12c408c3c1fba13055246 100644 (file)
@@ -7,6 +7,8 @@ package main
 
 import (
        "fmt"
+       "golang.zx2c4.com/wireguard/device"
+       "golang.zx2c4.com/wireguard/ipc"
        "os"
        "os/signal"
        "syscall"
@@ -25,8 +27,8 @@ func main() {
        }
        interfaceName := os.Args[1]
 
-       logger := NewLogger(
-               LogLevelDebug,
+       logger := device.NewLogger(
+               device.LogLevelDebug,
                fmt.Sprintf("(%s) ", interfaceName),
        )
        logger.Info.Println("Starting wireguard-go version", WireGuardGoVersion)
@@ -43,11 +45,11 @@ func main() {
                os.Exit(ExitSetupFailed)
        }
 
-       device := NewDevice(tun, logger)
+       device := device.NewDevice(tun, logger)
        device.Up()
        logger.Info.Println("Device started")
 
-       uapi, err := UAPIListen(interfaceName)
+       uapi, err := ipc.UAPIListen(interfaceName)
        if err != nil {
                logger.Error.Println("Failed to listen on uapi socket:", err)
                os.Exit(ExitSetupFailed)
@@ -63,7 +65,7 @@ func main() {
                                errs <- err
                                return
                        }
-                       go ipcHandle(device, conn)
+                       go device.IpcHandle(conn)
                }
        }()
        logger.Info.Println("UAPI listener started")
similarity index 99%
rename from helper_test.go
rename to tun/helper_test.go
index 3705c97abde019ecdfbdfd36f8c5c6d6646ac0cb..3e86fc8b3fcd33316e523fc9fbfcc9928c021ce2 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  */
 
-package main
+package tun
 
 import (
        "bytes"
index 94efe48bcadc1ed3bbdbdb0e585c0936ee36d42c..d767d794ea035eff9e3b9d183624c28722a884dc 100644 (file)
@@ -353,4 +353,4 @@ func (tun *NativeTun) Write(buff []byte, offset int) (int, error) {
 
 func (tun *NativeTun) GUID() windows.GUID {
        return *(*windows.GUID)(tun.wt)
-}
\ No newline at end of file
+}