mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-12-29 08:58:49 +01:00
Seperated fwmark update code into function
This commit is contained in:
parent
8f1d1b8c54
commit
9de17e6c9c
31
conn.go
31
conn.go
@ -64,6 +64,32 @@ func unsafeCloseBind(device *Device) error {
|
|||||||
return err
|
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 {
|
func (device *Device) BindUpdate() error {
|
||||||
|
|
||||||
device.net.mutex.Lock()
|
device.net.mutex.Lock()
|
||||||
@ -89,15 +115,18 @@ func (device *Device) BindUpdate() error {
|
|||||||
netc.bind, netc.port, err = CreateBind(netc.port)
|
netc.bind, netc.port, err = CreateBind(netc.port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
netc.bind = nil
|
netc.bind = nil
|
||||||
|
netc.port = 0
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// set mark
|
// set fwmark
|
||||||
|
|
||||||
|
if netc.fwmark != 0 {
|
||||||
err = netc.bind.SetMark(netc.fwmark)
|
err = netc.bind.SetMark(netc.fwmark)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// clear cached source addresses
|
// clear cached source addresses
|
||||||
|
|
||||||
|
6
uapi.go
6
uapi.go
@ -191,11 +191,7 @@ func ipcSetOperation(device *Device, socket *bufio.ReadWriter) *IPCError {
|
|||||||
|
|
||||||
logDebug.Println("UAPI: Updating fwmark")
|
logDebug.Println("UAPI: Updating fwmark")
|
||||||
|
|
||||||
device.net.mutex.Lock()
|
if err := device.BindSetMark(uint32(fwmark)); err != nil {
|
||||||
device.net.fwmark = uint32(fwmark)
|
|
||||||
device.net.mutex.Unlock()
|
|
||||||
|
|
||||||
if err := device.BindUpdate(); err != nil {
|
|
||||||
logError.Println("Failed to update fwmark:", err)
|
logError.Println("Failed to update fwmark:", err)
|
||||||
return &IPCError{Code: ipcErrorPortInUse}
|
return &IPCError{Code: ipcErrorPortInUse}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user