|
|
@ -53,15 +53,21 @@ type InterfaceAddr struct {
|
|
|
|
Addr string `json:"addr"`
|
|
|
|
Addr string `json:"addr"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// InterfaceAddrList is a list of InterfaceAddr
|
|
|
|
|
|
|
|
type InterfaceAddrList []InterfaceAddr
|
|
|
|
|
|
|
|
|
|
|
|
type InterfaceStat struct {
|
|
|
|
type InterfaceStat struct {
|
|
|
|
Index int `json:"index"`
|
|
|
|
Index int `json:"index"`
|
|
|
|
MTU int `json:"mtu"` // maximum transmission unit
|
|
|
|
MTU int `json:"mtu"` // maximum transmission unit
|
|
|
|
Name string `json:"name"` // e.g., "en0", "lo0", "eth0.100"
|
|
|
|
Name string `json:"name"` // e.g., "en0", "lo0", "eth0.100"
|
|
|
|
HardwareAddr string `json:"hardwareAddr"` // IEEE MAC-48, EUI-48 and EUI-64 form
|
|
|
|
HardwareAddr string `json:"hardwareAddr"` // IEEE MAC-48, EUI-48 and EUI-64 form
|
|
|
|
Flags []string `json:"flags"` // e.g., FlagUp, FlagLoopback, FlagMulticast
|
|
|
|
Flags []string `json:"flags"` // e.g., FlagUp, FlagLoopback, FlagMulticast
|
|
|
|
Addrs []InterfaceAddr `json:"addrs"`
|
|
|
|
Addrs InterfaceAddrList `json:"addrs"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// InterfaceStatList is a list of InterfaceStat
|
|
|
|
|
|
|
|
type InterfaceStatList []InterfaceStat
|
|
|
|
|
|
|
|
|
|
|
|
type FilterStat struct {
|
|
|
|
type FilterStat struct {
|
|
|
|
ConnTrackCount int64 `json:"connTrackCount"`
|
|
|
|
ConnTrackCount int64 `json:"connTrackCount"`
|
|
|
|
ConnTrackMax int64 `json:"connTrackMax"`
|
|
|
|
ConnTrackMax int64 `json:"connTrackMax"`
|
|
|
@ -182,6 +188,11 @@ func (n InterfaceStat) String() string {
|
|
|
|
return string(s)
|
|
|
|
return string(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (l InterfaceStatList) String() string {
|
|
|
|
|
|
|
|
s, _ := json.Marshal(l)
|
|
|
|
|
|
|
|
return string(s)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (n InterfaceAddr) String() string {
|
|
|
|
func (n InterfaceAddr) String() string {
|
|
|
|
s, _ := json.Marshal(n)
|
|
|
|
s, _ := json.Marshal(n)
|
|
|
|
return string(s)
|
|
|
|
return string(s)
|
|
|
@ -192,16 +203,16 @@ func (n ConntrackStat) String() string {
|
|
|
|
return string(s)
|
|
|
|
return string(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Interfaces() ([]InterfaceStat, error) {
|
|
|
|
func Interfaces() (InterfaceStatList, error) {
|
|
|
|
return InterfacesWithContext(context.Background())
|
|
|
|
return InterfacesWithContext(context.Background())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func InterfacesWithContext(ctx context.Context) ([]InterfaceStat, error) {
|
|
|
|
func InterfacesWithContext(ctx context.Context) (InterfaceStatList, error) {
|
|
|
|
is, err := net.Interfaces()
|
|
|
|
is, err := net.Interfaces()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret := make([]InterfaceStat, 0, len(is))
|
|
|
|
ret := make(InterfaceStatList, 0, len(is))
|
|
|
|
for _, ifi := range is {
|
|
|
|
for _, ifi := range is {
|
|
|
|
|
|
|
|
|
|
|
|
var flags []string
|
|
|
|
var flags []string
|
|
|
@ -230,7 +241,7 @@ func InterfacesWithContext(ctx context.Context) ([]InterfaceStat, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addrs, err := ifi.Addrs()
|
|
|
|
addrs, err := ifi.Addrs()
|
|
|
|
if err == nil {
|
|
|
|
if err == nil {
|
|
|
|
r.Addrs = make([]InterfaceAddr, 0, len(addrs))
|
|
|
|
r.Addrs = make(InterfaceAddrList, 0, len(addrs))
|
|
|
|
for _, addr := range addrs {
|
|
|
|
for _, addr := range addrs {
|
|
|
|
r.Addrs = append(r.Addrs, InterfaceAddr{
|
|
|
|
r.Addrs = append(r.Addrs, InterfaceAddr{
|
|
|
|
Addr: addr.String(),
|
|
|
|
Addr: addr.String(),
|
|
|
|