mirror of
https://github.com/safing/portmaster
synced 2025-09-02 02:29:12 +00:00
Expose network system state table to api
This commit is contained in:
parent
ad93b19968
commit
3f9876fc09
2 changed files with 59 additions and 7 deletions
|
@ -5,6 +5,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/safing/portmaster/network/state"
|
||||||
|
|
||||||
"github.com/safing/portbase/database"
|
"github.com/safing/portbase/database"
|
||||||
"github.com/safing/portbase/database/iterator"
|
"github.com/safing/portbase/database/iterator"
|
||||||
"github.com/safing/portbase/database/query"
|
"github.com/safing/portbase/database/query"
|
||||||
|
@ -57,13 +59,13 @@ func (s *StorageInterface) Get(key string) (record.Record, error) {
|
||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// case "system":
|
case "system":
|
||||||
// if len(splitted) >= 2 {
|
if len(splitted) >= 2 {
|
||||||
// switch splitted[1] {
|
switch splitted[1] {
|
||||||
// case "":
|
case "state":
|
||||||
// process.Get
|
return state.GetStateInfo(), nil
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, storage.ErrNotFound
|
return nil, storage.ErrNotFound
|
||||||
|
|
50
network/state/info.go
Normal file
50
network/state/info.go
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package state
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/safing/portbase/database/record"
|
||||||
|
|
||||||
|
"github.com/safing/portmaster/network/socket"
|
||||||
|
)
|
||||||
|
|
||||||
|
type StateInfo struct {
|
||||||
|
record.Base
|
||||||
|
sync.Mutex
|
||||||
|
|
||||||
|
TCP4Connections []*socket.ConnectionInfo
|
||||||
|
TCP4Listeners []*socket.BindInfo
|
||||||
|
TCP6Connections []*socket.ConnectionInfo
|
||||||
|
TCP6Listeners []*socket.BindInfo
|
||||||
|
UDP4Binds []*socket.BindInfo
|
||||||
|
UDP6Binds []*socket.BindInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetStateInfo() *StateInfo {
|
||||||
|
info := &StateInfo{}
|
||||||
|
|
||||||
|
tcp4Lock.Lock()
|
||||||
|
updateTCP4Tables()
|
||||||
|
info.TCP4Connections = tcp4Connections
|
||||||
|
info.TCP4Listeners = tcp4Listeners
|
||||||
|
tcp4Lock.Unlock()
|
||||||
|
|
||||||
|
tcp6Lock.Lock()
|
||||||
|
updateTCP6Tables()
|
||||||
|
info.TCP6Connections = tcp6Connections
|
||||||
|
info.TCP6Listeners = tcp6Listeners
|
||||||
|
tcp6Lock.Unlock()
|
||||||
|
|
||||||
|
udp4Lock.Lock()
|
||||||
|
updateUDP4Table()
|
||||||
|
info.UDP4Binds = udp4Binds
|
||||||
|
udp4Lock.Unlock()
|
||||||
|
|
||||||
|
udp6Lock.Lock()
|
||||||
|
updateUDP6Table()
|
||||||
|
info.UDP6Binds = udp6Binds
|
||||||
|
udp6Lock.Unlock()
|
||||||
|
|
||||||
|
info.UpdateMeta()
|
||||||
|
return info
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue