mirror of
https://github.com/bettercap/bettercap
synced 2025-07-11 15:46:59 -07:00
fix: refactored routing logic (fixes #701)
This commit is contained in:
parent
88a83192ef
commit
43a93fd866
11 changed files with 202 additions and 80 deletions
39
routing/tables.go
Normal file
39
routing/tables.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package routing
|
||||
|
||||
import "sync"
|
||||
|
||||
var (
|
||||
lock = sync.RWMutex{}
|
||||
table = make([]Route, 0)
|
||||
)
|
||||
|
||||
func Table() []Route {
|
||||
lock.RLock()
|
||||
defer lock.RUnlock()
|
||||
return table
|
||||
}
|
||||
|
||||
func Update() ([]Route, error) {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
return update()
|
||||
}
|
||||
|
||||
func Gateway(ip RouteType, device string) (string, error) {
|
||||
Update()
|
||||
|
||||
lock.RLock()
|
||||
defer lock.RUnlock()
|
||||
|
||||
for _, r := range table {
|
||||
if r.Type == ip {
|
||||
if device == "" || r.Device == device || r.Device == "" /* windows case */ {
|
||||
if r.Default {
|
||||
return r.Gateway, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue