Debian Codegraph @

routing/tables.go

raw symbols SCIP
1 package routing
2
3 import "sync"
4
5 var (
6 lock = sync.RWMutex{}
7 table = make([]Route, 0)
8 )
9
10 func Table() []Route {
11 lock.RLock()
12 defer lock.RUnlock()
13 return table
14 }
15
16 func Update() ([]Route, error) {
17 lock.Lock()
18 defer lock.Unlock()
19 return update()
20 }
21
22 func Gateway(ip RouteType, device string) (string, error) {
23 Update()
24
25 lock.RLock()
26 defer lock.RUnlock()
27
28 for _, r := range table {
29 if r.Type == ip {
30 if device == "" || r.Device == device || r.Device == "" /* windows case */ {
31 if r.Default {
32 return r.Gateway, nil
33 }
34 }
35 }
36 }
37
38 return "", nil
39 }