Support /proc/net/dev
This proc file reports the stats of interfaces. We could use ifconfig command to check the result. Signed-off-by: Jianfeng Tan <henry.tjf@antfin.com> Change-Id: Ia7c1e637f5c76c30791ffda68ee61e861b6ef827 COPYBARA_INTEGRATE_REVIEW=https://gvisor-review.googlesource.com/c/gvisor/+/18282/ PiperOrigin-RevId: 258303936
This commit is contained in:
parent
6a8ff6daef
commit
cf4fc510fd
|
@ -155,37 +155,40 @@ func (n *netDev) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]se
|
|||
contents[1] = " face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed\n"
|
||||
|
||||
for _, i := range interfaces {
|
||||
// TODO(b/71872867): Collect stats from each inet.Stack
|
||||
// implementation (hostinet, epsocket, and rpcinet).
|
||||
|
||||
// Implements the same format as
|
||||
// net/core/net-procfs.c:dev_seq_printf_stats.
|
||||
l := fmt.Sprintf("%6s: %7d %7d %4d %4d %4d %5d %10d %9d %8d %7d %4d %4d %4d %5d %7d %10d\n",
|
||||
var stats inet.StatDev
|
||||
if err := n.s.Statistics(&stats, i.Name); err != nil {
|
||||
log.Warningf("Failed to retrieve interface statistics for %v: %v", i.Name, err)
|
||||
continue
|
||||
}
|
||||
l := fmt.Sprintf(
|
||||
"%6s: %7d %7d %4d %4d %4d %5d %10d %9d %8d %7d %4d %4d %4d %5d %7d %10d\n",
|
||||
i.Name,
|
||||
// Received
|
||||
0, // bytes
|
||||
0, // packets
|
||||
0, // errors
|
||||
0, // dropped
|
||||
0, // fifo
|
||||
0, // frame
|
||||
0, // compressed
|
||||
0, // multicast
|
||||
stats[0], // bytes
|
||||
stats[1], // packets
|
||||
stats[2], // errors
|
||||
stats[3], // dropped
|
||||
stats[4], // fifo
|
||||
stats[5], // frame
|
||||
stats[6], // compressed
|
||||
stats[7], // multicast
|
||||
// Transmitted
|
||||
0, // bytes
|
||||
0, // packets
|
||||
0, // errors
|
||||
0, // dropped
|
||||
0, // fifo
|
||||
0, // frame
|
||||
0, // compressed
|
||||
0) // multicast
|
||||
stats[8], // bytes
|
||||
stats[9], // packets
|
||||
stats[10], // errors
|
||||
stats[11], // dropped
|
||||
stats[12], // fifo
|
||||
stats[13], // frame
|
||||
stats[14], // compressed
|
||||
stats[15]) // multicast
|
||||
contents = append(contents, l)
|
||||
}
|
||||
|
||||
var data []seqfile.SeqData
|
||||
for _, l := range contents {
|
||||
data = append(data, seqfile.SeqData{Buf: []byte(l), Handle: (*ifinet6)(nil)})
|
||||
data = append(data, seqfile.SeqData{Buf: []byte(l), Handle: (*netDev)(nil)})
|
||||
}
|
||||
|
||||
return data, 0
|
||||
|
|
|
@ -49,6 +49,9 @@ type Stack interface {
|
|||
// SetTCPSACKEnabled attempts to change TCP selective acknowledgement
|
||||
// settings.
|
||||
SetTCPSACKEnabled(enabled bool) error
|
||||
|
||||
// Statistics reports stack statistics.
|
||||
Statistics(stat interface{}, arg string) error
|
||||
}
|
||||
|
||||
// Interface contains information about a network interface.
|
||||
|
@ -102,3 +105,7 @@ type TCPBufferSize struct {
|
|||
// Max is the maximum size.
|
||||
Max int
|
||||
}
|
||||
|
||||
// StatDev describes one line of /proc/net/dev, i.e., stats for one network
|
||||
// interface.
|
||||
type StatDev [16]uint64
|
||||
|
|
|
@ -81,3 +81,8 @@ func (s *TestStack) SetTCPSACKEnabled(enabled bool) error {
|
|||
s.TCPSACKFlag = enabled
|
||||
return nil
|
||||
}
|
||||
|
||||
// Statistics implements inet.Stack.Statistics.
|
||||
func (s *TestStack) Statistics(stat interface{}, arg string) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -138,3 +138,8 @@ func (s *Stack) TCPSACKEnabled() (bool, error) {
|
|||
func (s *Stack) SetTCPSACKEnabled(enabled bool) error {
|
||||
return syserr.TranslateNetstackError(s.Stack.SetTransportProtocolOption(tcp.ProtocolNumber, tcp.SACKEnabled(enabled))).ToError()
|
||||
}
|
||||
|
||||
// Statistics implements inet.Stack.Statistics.
|
||||
func (s *Stack) Statistics(stat interface{}, arg string) error {
|
||||
return syserr.ErrEndpointOperation.ToError()
|
||||
}
|
||||
|
|
|
@ -244,3 +244,8 @@ func (s *Stack) TCPSACKEnabled() (bool, error) {
|
|||
func (s *Stack) SetTCPSACKEnabled(enabled bool) error {
|
||||
return syserror.EACCES
|
||||
}
|
||||
|
||||
// Statistics implements inet.Stack.Statistics.
|
||||
func (s *Stack) Statistics(stat interface{}, arg string) error {
|
||||
return syserror.EOPNOTSUPP
|
||||
}
|
||||
|
|
|
@ -133,3 +133,8 @@ func (s *Stack) TCPSACKEnabled() (bool, error) {
|
|||
func (s *Stack) SetTCPSACKEnabled(enabled bool) error {
|
||||
panic("rpcinet handles procfs directly this method should not be called")
|
||||
}
|
||||
|
||||
// Statistics implements inet.Stack.Statistics.
|
||||
func (s *Stack) Statistics(stat interface{}, arg string) error {
|
||||
return syserr.ErrEndpointOperation.ToError()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue