]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
Fix up fwmark handling
authorJason A. Donenfeld <Jason@zx2c4.com>
Thu, 21 Sep 2017 01:09:57 +0000 (03:09 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 21 Sep 2017 01:10:03 +0000 (03:10 +0200)
src/conn_default.go
src/conn_linux.go
src/device.go
src/uapi.go

index 5ef2659a57e113f62b05c87739f1a1497673a3fe..e7c60a8cc3ee906949bdd849b9cc9fae163f57be 100644 (file)
@@ -6,6 +6,6 @@ import (
        "net"
 )
 
-func setMark(conn *net.UDPConn, value int) error {
+func setMark(conn *net.UDPConn, value uint32) error {
        return nil
 }
index b04471c22cd98c00c360beff300ae0514891fe8c..e973b25eee91dea8f7dcb5c837c81ac547a5d455 100644 (file)
@@ -5,8 +5,8 @@ import (
        "net"
 )
 
-func setMark(conn *net.UDPConn, value int) error {
-       if conn == nil || value == 0 {
+func setMark(conn *net.UDPConn, value uint32) error {
+       if conn == nil {
                return nil
        }
 
@@ -19,6 +19,6 @@ func setMark(conn *net.UDPConn, value int) error {
                int(file.Fd()),
                unix.SOL_SOCKET,
                unix.SO_MARK,
-               value,
+               int(value),
        )
 }
index 2ead76895ca2ecafe86cb2d616947b1642d810fd..61c87bc99d7fda370384906c7e76a6fcbe67781c 100644 (file)
@@ -24,7 +24,7 @@ type Device struct {
                mutex  sync.RWMutex
                addr   *net.UDPAddr // UDP source address
                conn   *net.UDPConn // UDP "connection"
-               fwmark int
+               fwmark uint32
        }
        mutex        sync.RWMutex
        privateKey   NoisePrivateKey
index 871232cd24371d04fe925f71d259bd094af0dd64..428b17399cd84978b1630e2cc83c1f260be79b4f 100644 (file)
@@ -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":