summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/conn.go11
-rw-r--r--src/device.go2
-rw-r--r--src/tun.go6
-rw-r--r--src/uapi.go2
4 files changed, 11 insertions, 10 deletions
diff --git a/src/conn.go b/src/conn.go
index 5b40a23..b17ac70 100644
--- a/src/conn.go
+++ b/src/conn.go
@@ -54,7 +54,7 @@ func parseEndpoint(s string) (*net.UDPAddr, error) {
/* Must hold device and net lock
*/
-func unsafeCloseUDPListener(device *Device) error {
+func unsafeCloseBind(device *Device) error {
var err error
netc := &device.net
if netc.bind != nil {
@@ -64,8 +64,7 @@ func unsafeCloseUDPListener(device *Device) error {
return err
}
-// must inform all listeners
-func UpdateUDPListener(device *Device) error {
+func updateBind(device *Device) error {
device.mutex.Lock()
defer device.mutex.Unlock()
@@ -75,7 +74,7 @@ func UpdateUDPListener(device *Device) error {
// close existing sockets
- if err := unsafeCloseUDPListener(device); err != nil {
+ if err := unsafeCloseBind(device); err != nil {
return err
}
@@ -124,10 +123,10 @@ func UpdateUDPListener(device *Device) error {
return nil
}
-func CloseUDPListener(device *Device) error {
+func closeBind(device *Device) error {
device.mutex.Lock()
device.net.mutex.Lock()
- err := unsafeCloseUDPListener(device)
+ err := unsafeCloseBind(device)
device.net.mutex.Unlock()
device.mutex.Unlock()
return err
diff --git a/src/device.go b/src/device.go
index 76235bd..ecffd9e 100644
--- a/src/device.go
+++ b/src/device.go
@@ -210,7 +210,7 @@ func (device *Device) Close() {
device.log.Info.Println("Closing device")
device.RemoveAllPeers()
close(device.signal.stop)
- CloseUDPListener(device)
+ closeBind(device)
device.tun.device.Close()
}
diff --git a/src/tun.go b/src/tun.go
index 5bdac0e..215022c 100644
--- a/src/tun.go
+++ b/src/tun.go
@@ -47,17 +47,19 @@ func (device *Device) RoutineTUNEventReader() {
if event&TUNEventUp != 0 {
if !device.tun.isUp.Get() {
+ // begin listening for incomming datagrams
logInfo.Println("Interface set up")
device.tun.isUp.Set(true)
- UpdateUDPListener(device)
+ updateBind(device)
}
}
if event&TUNEventDown != 0 {
if device.tun.isUp.Get() {
+ // stop listening for incomming datagrams
logInfo.Println("Interface set down")
device.tun.isUp.Set(false)
- CloseUDPListener(device)
+ closeBind(device)
}
}
}
diff --git a/src/uapi.go b/src/uapi.go
index dc8be66..7ab3c4a 100644
--- a/src/uapi.go
+++ b/src/uapi.go
@@ -139,7 +139,7 @@ func ipcSetOperation(device *Device, socket *bufio.ReadWriter) *IPCError {
return &IPCError{Code: ipcErrorInvalid}
}
device.net.port = uint16(port)
- if err := UpdateUDPListener(device); err != nil {
+ if err := updateBind(device); err != nil {
logError.Println("Failed to set listen_port:", err)
return &IPCError{Code: ipcErrorPortInUse}
}