aboutsummaryrefslogtreecommitdiffstats
path: root/device
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--device/allowedips.go (renamed from allowedips.go)2
-rw-r--r--device/allowedips_rand_test.go (renamed from allowedips_rand_test.go)2
-rw-r--r--device/allowedips_test.go (renamed from allowedips_test.go)2
-rw-r--r--device/bind_test.go (renamed from bind_test.go)2
-rw-r--r--device/conn.go (renamed from conn.go)4
-rw-r--r--device/conn_default.go (renamed from conn_default.go)2
-rw-r--r--device/conn_linux.go (renamed from conn_linux.go)2
-rw-r--r--device/constants.go (renamed from constants.go)2
-rw-r--r--device/cookie.go (renamed from cookie.go)2
-rw-r--r--device/cookie_test.go (renamed from cookie_test.go)2
-rw-r--r--device/device.go (renamed from device.go)2
-rw-r--r--device/device_test.go (renamed from device_test.go)2
-rw-r--r--device/endpoint_test.go (renamed from endpoint_test.go)2
-rw-r--r--device/indextable.go (renamed from indextable.go)2
-rw-r--r--device/ip.go (renamed from ip.go)2
-rw-r--r--device/kdf_test.go (renamed from kdf_test.go)2
-rw-r--r--device/keypair.go (renamed from keypair.go)2
-rw-r--r--device/logger.go (renamed from logger.go)2
-rw-r--r--device/mark_default.go (renamed from mark_default.go)2
-rw-r--r--device/mark_unix.go (renamed from mark_unix.go)2
-rw-r--r--device/misc.go (renamed from misc.go)2
-rw-r--r--device/noise-helpers.go (renamed from noise-helpers.go)2
-rw-r--r--device/noise-protocol.go (renamed from noise-protocol.go)2
-rw-r--r--device/noise-types.go (renamed from noise-types.go)2
-rw-r--r--device/noise_test.go (renamed from noise_test.go)2
-rw-r--r--device/peer.go (renamed from peer.go)2
-rw-r--r--device/pools.go (renamed from pools.go)2
-rw-r--r--device/queueconstants.go (renamed from queueconstants.go)2
-rw-r--r--device/receive.go (renamed from receive.go)2
-rw-r--r--device/send.go (renamed from send.go)2
-rw-r--r--device/timers.go (renamed from timers.go)2
-rw-r--r--device/tun.go (renamed from tun.go)2
-rw-r--r--device/uapi.go (renamed from uapi.go)53
-rw-r--r--device/version.go3
34 files changed, 63 insertions, 59 deletions
diff --git a/allowedips.go b/device/allowedips.go
index 2c4f601..efc27c0 100644
--- a/allowedips.go
+++ b/device/allowedips.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"errors"
diff --git a/allowedips_rand_test.go b/device/allowedips_rand_test.go
index 56a31c4..59c10f7 100644
--- a/allowedips_rand_test.go
+++ b/device/allowedips_rand_test.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"math/rand"
diff --git a/allowedips_test.go b/device/allowedips_test.go
index ca694ab..075ff06 100644
--- a/allowedips_test.go
+++ b/device/allowedips_test.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"math/rand"
diff --git a/bind_test.go b/device/bind_test.go
index c534646..0c2e2cf 100644
--- a/bind_test.go
+++ b/device/bind_test.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import "errors"
diff --git a/conn.go b/device/conn.go
index b19a9c2..2594680 100644
--- a/conn.go
+++ b/device/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
diff --git a/conn_default.go b/device/conn_default.go
index 6f17de5..8a86719 100644
--- a/conn_default.go
+++ b/device/conn_default.go
@@ -5,7 +5,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"net"
diff --git a/conn_linux.go b/device/conn_linux.go
index d3dbb98..49949d5 100644
--- a/conn_linux.go
+++ b/device/conn_linux.go
@@ -14,7 +14,7 @@
* So this code is remains platform dependent.
*/
-package main
+package device
import (
"errors"
diff --git a/constants.go b/device/constants.go
index ab93e5f..27d910f 100644
--- a/constants.go
+++ b/device/constants.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"time"
diff --git a/cookie.go b/device/cookie.go
index c648bf1..2f21067 100644
--- a/cookie.go
+++ b/device/cookie.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"crypto/hmac"
diff --git a/cookie_test.go b/device/cookie_test.go
index 0586260..79a6a86 100644
--- a/cookie_test.go
+++ b/device/cookie_test.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"testing"
diff --git a/device.go b/device/device.go
index 18e1138..d6c96d6 100644
--- a/device.go
+++ b/device/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"
diff --git a/device_test.go b/device/device_test.go
index df0ba69..db5a3c0 100644
--- a/device_test.go
+++ b/device/device_test.go
@@ -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
diff --git a/endpoint_test.go b/device/endpoint_test.go
index fe6677c..1896790 100644
--- a/endpoint_test.go
+++ b/device/endpoint_test.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"math/rand"
diff --git a/indextable.go b/device/indextable.go
index 046113c..4cba970 100644
--- a/indextable.go
+++ b/device/indextable.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"crypto/rand"
diff --git a/ip.go b/device/ip.go
index e2e0ff3..9d4fb74 100644
--- a/ip.go
+++ b/device/ip.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"net"
diff --git a/kdf_test.go b/device/kdf_test.go
index 3b9a8be..11ea8d5 100644
--- a/kdf_test.go
+++ b/device/kdf_test.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"encoding/hex"
diff --git a/keypair.go b/device/keypair.go
index af10a58..a9fbfce 100644
--- a/keypair.go
+++ b/device/keypair.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"crypto/cipher"
diff --git a/logger.go b/device/logger.go
index 00b1c7d..7c8b704 100644
--- a/logger.go
+++ b/device/logger.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"io"
diff --git a/mark_default.go b/device/mark_default.go
index 7149d69..76b1015 100644
--- a/mark_default.go
+++ b/device/mark_default.go
@@ -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
diff --git a/mark_unix.go b/device/mark_unix.go
index 0ae62b7..ee64cc9 100644
--- a/mark_unix.go
+++ b/device/mark_unix.go
@@ -5,7 +5,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"golang.org/x/sys/unix"
diff --git a/misc.go b/device/misc.go
index 6786cb5..a38d1c1 100644
--- a/misc.go
+++ b/device/misc.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"sync/atomic"
diff --git a/noise-helpers.go b/device/noise-helpers.go
index af11f09..4b09bf3 100644
--- a/noise-helpers.go
+++ b/device/noise-helpers.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"crypto/hmac"
diff --git a/noise-protocol.go b/device/noise-protocol.go
index fb43413..73826e1 100644
--- a/noise-protocol.go
+++ b/device/noise-protocol.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"errors"
diff --git a/noise-types.go b/device/noise-types.go
index 902905e..82b12c1 100644
--- a/noise-types.go
+++ b/device/noise-types.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"crypto/subtle"
diff --git a/noise_test.go b/device/noise_test.go
index 116057a..6ba3f2e 100644
--- a/noise_test.go
+++ b/device/noise_test.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"bytes"
diff --git a/peer.go b/device/peer.go
index f021565..af3ef9d 100644
--- a/peer.go
+++ b/device/peer.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"encoding/base64"
diff --git a/pools.go b/device/pools.go
index 8a9af0b..98f4ef1 100644
--- a/pools.go
+++ b/device/pools.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import "sync"
diff --git a/queueconstants.go b/device/queueconstants.go
index 0dcdd33..3e94b7f 100644
--- a/queueconstants.go
+++ b/device/queueconstants.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
/* Implementation specific constants */
diff --git a/receive.go b/device/receive.go
index fb848eb..5c837c1 100644
--- a/receive.go
+++ b/device/receive.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"bytes"
diff --git a/send.go b/device/send.go
index b7cac04..b4e23c7 100644
--- a/send.go
+++ b/device/send.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package main
+package device
import (
"bytes"
diff --git a/timers.go b/device/timers.go
index 9c16f13..5f28fcc 100644
--- a/timers.go
+++ b/device/timers.go
@@ -5,7 +5,7 @@
* This is based heavily on timers.c from the kernel implementation.
*/
-package main
+package device
import (
"math/rand"
diff --git a/tun.go b/device/tun.go
index 52bfb68..bc5f1f1 100644
--- a/tun.go
+++ b/device/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"
diff --git a/uapi.go b/device/uapi.go
index 4a370b3..5c65917 100644
--- a/uapi.go
+++ b/device/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
index 0000000..9077cdc
--- /dev/null
+++ b/device/version.go
@@ -0,0 +1,3 @@
+package device
+
+const WireGuardGoVersion = "0.0.20181222"