@ -112,6 +112,7 @@ type userspaceEngine struct {
mu sync . Mutex // guards following; see lock order comment below
mu sync . Mutex // guards following; see lock order comment below
closing bool // Close was called (even if we're still closing)
closing bool // Close was called (even if we're still closing)
statusCallback StatusCallback
statusCallback StatusCallback
linkChangeCallback func ( major bool , newState * interfaces . State )
peerSequence [ ] wgcfg . Key
peerSequence [ ] wgcfg . Key
endpoints [ ] string
endpoints [ ] string
pingers map [ wgcfg . Key ] * pinger // legacy pingers for pre-discovery peers
pingers map [ wgcfg . Key ] * pinger // legacy pingers for pre-discovery peers
@ -1110,15 +1111,15 @@ func (e *userspaceEngine) Wait() {
<- e . waitCh
<- e . waitCh
}
}
func ( e * userspaceEngine ) setLinkState ( st * interfaces . State ) ( changed bool ) {
func ( e * userspaceEngine ) setLinkState ( st * interfaces . State ) ( changed bool , cb func ( major bool , newState * interfaces . State ) ) {
if st == nil {
if st == nil {
return false
return false , nil
}
}
e . mu . Lock ( )
e . mu . Lock ( )
defer e . mu . Unlock ( )
defer e . mu . Unlock ( )
changed = e . linkState == nil || ! st . Equal ( e . linkState )
changed = e . linkState == nil || ! st . Equal ( e . linkState )
e . linkState = st
e . linkState = st
return changed
return changed , e . linkChangeCallback
}
}
func ( e * userspaceEngine ) LinkChange ( isExpensive bool ) {
func ( e * userspaceEngine ) LinkChange ( isExpensive bool ) {
@ -1128,7 +1129,7 @@ func (e *userspaceEngine) LinkChange(isExpensive bool) {
return
return
}
}
cur . IsExpensive = isExpensive
cur . IsExpensive = isExpensive
needRebind := e . setLinkState ( cur )
needRebind , linkChangeCallback := e . setLinkState ( cur )
if needRebind {
if needRebind {
e . logf ( "LinkChange: major, rebinding. New state: %+v" , cur )
e . logf ( "LinkChange: major, rebinding. New state: %+v" , cur )
@ -1142,6 +1143,15 @@ func (e *userspaceEngine) LinkChange(isExpensive bool) {
e . magicConn . Rebind ( )
e . magicConn . Rebind ( )
}
}
e . magicConn . ReSTUN ( why )
e . magicConn . ReSTUN ( why )
if linkChangeCallback != nil {
go linkChangeCallback ( needRebind , cur )
}
}
func ( e * userspaceEngine ) SetLinkChangeCallback ( cb func ( major bool , newState * interfaces . State ) ) {
e . mu . Lock ( )
defer e . mu . Unlock ( )
e . linkChangeCallback = cb
}
}
func getLinkState ( ) ( * interfaces . State , error ) {
func getLinkState ( ) ( * interfaces . State , error ) {