aboutsummaryrefslogtreecommitdiffstats
path: root/conn.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2018-02-18 20:49:03 +0100
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2018-02-18 20:49:03 +0100
commit9de17e6c9c90f3bf3ec3eb709a92c9e1295a6d67 (patch)
tree3bfc156930ea8b57e91e5ff7ca62409adc427de8 /conn.go
parentMPLv2 for App Store (diff)
downloadwireguard-go-9de17e6c9c90f3bf3ec3eb709a92c9e1295a6d67.tar.xz
wireguard-go-9de17e6c9c90f3bf3ec3eb709a92c9e1295a6d67.zip
Seperated fwmark update code into function
Diffstat (limited to 'conn.go')
-rw-r--r--conn.go37
1 files changed, 33 insertions, 4 deletions
diff --git a/conn.go b/conn.go
index fb30ec2..6bb262c 100644
--- a/conn.go
+++ b/conn.go
@@ -64,6 +64,32 @@ func unsafeCloseBind(device *Device) error {
return err
}
+func (device *Device) BindSetMark(mark uint32) error {
+
+ device.net.mutex.Lock()
+ defer device.net.mutex.Unlock()
+
+ device.peers.mutex.Lock()
+ defer device.peers.mutex.Unlock()
+
+ // check if modified
+
+ if device.net.fwmark == mark {
+ return nil
+ }
+
+ // update fwmark on existing bind
+
+ device.net.fwmark = mark
+ if device.isUp.Get() && device.net.bind != nil {
+ if err := device.net.bind.SetMark(mark); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
func (device *Device) BindUpdate() error {
device.net.mutex.Lock()
@@ -89,14 +115,17 @@ func (device *Device) BindUpdate() error {
netc.bind, netc.port, err = CreateBind(netc.port)
if err != nil {
netc.bind = nil
+ netc.port = 0
return err
}
- // set mark
+ // set fwmark
- err = netc.bind.SetMark(netc.fwmark)
- if err != nil {
- return err
+ if netc.fwmark != 0 {
+ err = netc.bind.SetMark(netc.fwmark)
+ if err != nil {
+ return err
+ }
}
// clear cached source addresses