Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Inode field into netIPSocketLine structure #373

Merged
merged 1 commit into from Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions net_ip_socket.go
Expand Up @@ -65,6 +65,7 @@ type (
TxQueue uint64
RxQueue uint64
UID uint64
Inode uint64
}
)

Expand Down Expand Up @@ -150,9 +151,9 @@ func parseIP(hexIP string) (net.IP, error) {
// parseNetIPSocketLine parses a single line, represented by a list of fields.
func parseNetIPSocketLine(fields []string) (*netIPSocketLine, error) {
line := &netIPSocketLine{}
if len(fields) < 8 {
if len(fields) < 10 {
return nil, fmt.Errorf(
"cannot parse net socket line as it has less then 8 columns %q",
"cannot parse net socket line as it has less then 10 columns %q",
strings.Join(fields, " "),
)
}
Expand Down Expand Up @@ -216,5 +217,10 @@ func parseNetIPSocketLine(fields []string) (*netIPSocketLine, error) {
return nil, fmt.Errorf("cannot parse uid value in socket line: %w", err)
}

// inode
if line.Inode, err = strconv.ParseUint(fields[9], 0, 64); err != nil {
return nil, fmt.Errorf("cannot parse inode value in socket line: %w", err)
}

return line, nil
}
27 changes: 17 additions & 10 deletions net_ip_socket_test.go
Expand Up @@ -28,7 +28,7 @@ func Test_parseNetIPSocketLine(t *testing.T) {
}{
{
name: "reading valid lines, no issue should happened",
fields: []string{"11:", "00000000:0000", "00000000:0000", "0A", "00000017:0000002A", "0:0", "0", "1000"},
fields: []string{"11:", "00000000:0000", "00000000:0000", "0A", "00000017:0000002A", "0:0", "0", "1000", "0", "39309"},
want: &netIPSocketLine{
Sl: 11,
LocalAddr: net.IP{0, 0, 0, 0},
Expand All @@ -39,53 +39,60 @@ func Test_parseNetIPSocketLine(t *testing.T) {
TxQueue: 23,
RxQueue: 42,
UID: 1000,
Inode: 39309,
},
},
{
name: "error case - invalid line - number of fields/columns < 8",
fields: []string{"1:", "00000000:0000", "00000000:0000", "07", "0:0", "0"},
name: "error case - invalid line - number of fields/columns < 10",
fields: []string{"1:", "00000000:0000", "00000000:0000", "07", "0:0", "0", "0"},
want: nil,
wantErr: true,
},
{
name: "error case - parse sl - not a valid uint",
fields: []string{"a:", "00000000:0000", "00000000:0000", "07", "00000000:00000001", "0:0", "0", "0"},
fields: []string{"a:", "00000000:0000", "00000000:0000", "07", "00000000:00000001", "0:0", "0", "0", "0", "39309"},
want: nil,
wantErr: true,
},
{
name: "error case - parse local_address - not a valid hex",
fields: []string{"1:", "0000000O:0000", "00000000:0000", "07", "00000000:00000001", "0:0", "0", "0"},
fields: []string{"1:", "0000000O:0000", "00000000:0000", "07", "00000000:00000001", "0:0", "0", "0", "0", "39309"},
want: nil,
wantErr: true,
},
{
name: "error case - parse rem_address - not a valid hex",
fields: []string{"1:", "00000000:0000", "0000000O:0000", "07", "00000000:00000001", "0:0", "0", "0"},
fields: []string{"1:", "00000000:0000", "0000000O:0000", "07", "00000000:00000001", "0:0", "0", "0", "0", "39309"},
want: nil,
wantErr: true,
},
{
name: "error case - cannot parse line - missing colon",
fields: []string{"1:", "00000000:0000", "00000000:0000", "07", "0000000000000001", "0:0", "0", "0"},
fields: []string{"1:", "00000000:0000", "00000000:0000", "07", "0000000000000001", "0:0", "0", "0", "0", "39309"},
want: nil,
wantErr: true,
},
{
name: "error case - parse tx_queue - not a valid hex",
fields: []string{"1:", "00000000:0000", "00000000:0000", "07", "DEADCODE:00000001", "0:0", "0", "0"},
fields: []string{"1:", "00000000:0000", "00000000:0000", "07", "DEADCODE:00000001", "0:0", "0", "0", "0", "39309"},
want: nil,
wantErr: true,
},
{
name: "error case - parse rx_queue - not a valid hex",
fields: []string{"1:", "00000000:0000", "00000000:0000", "07", "00000000:FEEDCODE", "0:0", "0", "0"},
fields: []string{"1:", "00000000:0000", "00000000:0000", "07", "00000000:FEEDCODE", "0:0", "0", "0", "0", "39309"},
want: nil,
wantErr: true,
},
{
name: "error case - parse UID - not a valid uint",
fields: []string{"1:", "00000000:0000", "00000000:0000", "07", "00000000:00000001", "0:0", "0", "-10"},
fields: []string{"1:", "00000000:0000", "00000000:0000", "07", "00000000:00000001", "0:0", "0", "-10", "0", "39309"},
want: nil,
wantErr: true,
},
{
name: "error case - parse Inode - not a valid uint",
fields: []string{"1:", "00000000:0000", "00000000:0000", "07", "00000000:00000001", "0:0", "0", "-10", "0", "-39309"},
want: nil,
wantErr: true,
},
Expand Down
5 changes: 5 additions & 0 deletions net_tcp_test.go
Expand Up @@ -40,6 +40,7 @@ func Test_newNetTCP(t *testing.T) {
TxQueue: 0,
RxQueue: 1,
UID: 0,
Inode: 2740,
},
&netIPSocketLine{
Sl: 1,
Expand All @@ -51,6 +52,7 @@ func Test_newNetTCP(t *testing.T) {
TxQueue: 1,
RxQueue: 0,
UID: 0,
Inode: 2740,
},
&netIPSocketLine{
Sl: 2,
Expand All @@ -62,6 +64,7 @@ func Test_newNetTCP(t *testing.T) {
TxQueue: 1,
RxQueue: 1,
UID: 0,
Inode: 2740,
},
},
wantErr: false,
Expand All @@ -80,6 +83,7 @@ func Test_newNetTCP(t *testing.T) {
TxQueue: 0,
RxQueue: 0,
UID: 981,
Inode: 21040,
},
&netIPSocketLine{
Sl: 6073,
Expand All @@ -91,6 +95,7 @@ func Test_newNetTCP(t *testing.T) {
TxQueue: 0,
RxQueue: 0,
UID: 1000,
Inode: 11337031,
},
},
wantErr: false,
Expand Down
5 changes: 5 additions & 0 deletions net_udp_test.go
Expand Up @@ -40,6 +40,7 @@ func Test_newNetUDP(t *testing.T) {
TxQueue: 0,
RxQueue: 1,
UID: 0,
Inode: 2740,
},
&netIPSocketLine{
Sl: 1,
Expand All @@ -51,6 +52,7 @@ func Test_newNetUDP(t *testing.T) {
TxQueue: 1,
RxQueue: 0,
UID: 0,
Inode: 2740,
},
&netIPSocketLine{
Sl: 2,
Expand All @@ -62,6 +64,7 @@ func Test_newNetUDP(t *testing.T) {
TxQueue: 1,
RxQueue: 1,
UID: 0,
Inode: 2740,
},
},
wantErr: false,
Expand All @@ -80,6 +83,7 @@ func Test_newNetUDP(t *testing.T) {
TxQueue: 0,
RxQueue: 0,
UID: 981,
Inode: 21040,
},
&netIPSocketLine{
Sl: 6073,
Expand All @@ -91,6 +95,7 @@ func Test_newNetUDP(t *testing.T) {
TxQueue: 0,
RxQueue: 0,
UID: 1000,
Inode: 11337031,
},
},
wantErr: false,
Expand Down