aboutsummaryrefslogtreecommitdiffstats
path: root/src/uapi.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-09-21 03:09:57 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-09-21 03:10:03 +0200
commitc545d63bb93b8192dfdc7037952fc2661dd1222b (patch)
tree02313ddc69501e8cbcb7e0fe562e3bd7efdd9126 /src/uapi.go
parentAdded last_minute_handshake_guard (diff)
downloadwireguard-go-c545d63bb93b8192dfdc7037952fc2661dd1222b.tar.xz
wireguard-go-c545d63bb93b8192dfdc7037952fc2661dd1222b.zip
Fix up fwmark handling
Diffstat (limited to '')
-rw-r--r--src/uapi.go40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/uapi.go b/src/uapi.go
index 871232c..428b173 100644
--- a/src/uapi.go
+++ b/src/uapi.go
@@ -42,6 +42,9 @@ func ipcGetOperation(device *Device, socket *bufio.ReadWriter) *IPCError {
if device.net.addr != nil {
send(fmt.Sprintf("listen_port=%d", device.net.addr.Port))
}
+ if device.net.fwmark != 0 {
+ send(fmt.Sprintf("fwmark=%d", device.net.fwmark))
+ }
for _, peer := range device.peers {
func() {
@@ -158,25 +161,32 @@ func ipcSetOperation(device *Device, socket *bufio.ReadWriter) *IPCError {
// TODO: Clear source address of all peers
case "fwmark":
- fwmark, err := strconv.ParseInt(value, 10, 32)
- if err != nil {
- logError.Println("Invalid fwmark", err)
- return &IPCError{Code: ipcErrorInvalid}
+ var fwmark uint64 = 0
+ if value != "" {
+ var err error
+ fwmark, err = strconv.ParseUint(value, 10, 32)
+ if err != nil {
+ logError.Println("Invalid fwmark", err)
+ return &IPCError{Code: ipcErrorInvalid}
+ }
}
device.net.mutex.Lock()
- device.net.fwmark = int(fwmark)
- err = setMark(
- device.net.conn,
- device.net.fwmark,
- )
- device.net.mutex.Unlock()
- if err != nil {
- logError.Println("Failed to set fwmark:", err)
- return &IPCError{Code: ipcErrorIO}
- }
+ if fwmark > 0 || device.net.fwmark > 0 {
+ device.net.fwmark = uint32(fwmark)
+ err := setMark(
+ device.net.conn,
+ device.net.fwmark,
+ )
+ if err != nil {
+ logError.Println("Failed to set fwmark:", err)
+ device.net.mutex.Unlock()
+ return &IPCError{Code: ipcErrorIO}
+ }
- // TODO: Clear source address of all peers
+ // TODO: Clear source address of all peers
+ }
+ device.net.mutex.Unlock()
case "public_key":