Skip to content

Commit bd023e6

Browse files
authored
Merge pull request #3841 from alexandear/refactor/procnettcp
guestagent/procnettcp: remove unused, unexport funcs
2 parents ec398e6 + a83de4e commit bd023e6

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

pkg/guestagent/procnettcp/fuzz_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ func FuzzParse(f *testing.F) {
1414
if tcp6 {
1515
kind = TCP6
1616
}
17-
_, _ = Parse(bytes.NewReader(data), kind)
17+
_, _ = parse(bytes.NewReader(data), kind)
1818
})
1919
}

pkg/guestagent/procnettcp/procnettcp.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ type Entry struct {
4141
State State `json:"state"`
4242
}
4343

44-
func Parse(r io.Reader, kind Kind) ([]Entry, error) {
45-
return ParseWithEndian(r, kind, cpu.IsBigEndian)
44+
func parse(r io.Reader, kind Kind) ([]Entry, error) {
45+
return parseWithEndian(r, kind, cpu.IsBigEndian)
4646
}
4747

48-
func ParseWithEndian(r io.Reader, kind Kind, isBE bool) ([]Entry, error) {
48+
func parseWithEndian(r io.Reader, kind Kind, isBE bool) ([]Entry, error) {
4949
switch kind {
5050
case TCP, TCP6, UDP, UDP6:
5151
default:
@@ -78,7 +78,7 @@ func ParseWithEndian(r io.Reader, kind Kind, isBE bool) ([]Entry, error) {
7878
default:
7979
// localAddress is like "0100007F:053A"
8080
localAddress := fields[fieldNames["local_address"]]
81-
ip, port, err := ParseAddressWithEndian(localAddress, isBE)
81+
ip, port, err := parseAddressWithEndian(localAddress, isBE)
8282
if err != nil {
8383
return entries, err
8484
}
@@ -105,7 +105,7 @@ func ParseWithEndian(r io.Reader, kind Kind, isBE bool) ([]Entry, error) {
105105
return entries, nil
106106
}
107107

108-
// ParseAddress parses a string.
108+
// parseAddressWithEndian parses a string.
109109
//
110110
// Little endian hosts:
111111
// "0100007F:0050" (127.0.0.1:80)
@@ -118,11 +118,7 @@ func ParseWithEndian(r io.Reader, kind Kind, isBE bool) ([]Entry, error) {
118118
// "00000000000000000000000000000000:0050" (0.0.0.0:80)
119119
//
120120
// See https://serverfault.com/questions/592574/why-does-proc-net-tcp6-represents-1-as-1000
121-
func ParseAddress(s string) (net.IP, uint16, error) {
122-
return ParseAddressWithEndian(s, cpu.IsBigEndian)
123-
}
124-
125-
func ParseAddressWithEndian(s string, isBE bool) (net.IP, uint16, error) {
121+
func parseAddressWithEndian(s string, isBE bool) (net.IP, uint16, error) {
126122
split := strings.SplitN(s, ":", 2)
127123
if len(split) != 2 {
128124
return nil, 0, fmt.Errorf("unparsable address %q", s)

pkg/guestagent/procnettcp/procnettcp_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func ParseFiles() ([]Entry, error) {
2525
}
2626
return res, err
2727
}
28-
parsed, err := Parse(r, kind)
28+
parsed, err := parse(r, kind)
2929
if err != nil {
3030
_ = r.Close()
3131
return res, err

pkg/guestagent/procnettcp/procnettcp_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestParseTCP(t *testing.T) {
2121
4: 0100007F:053A 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 31430 1 0000000000000000 100 0 0 10 0
2222
5: 0B3CA8C0:0016 690AA8C0:F705 01 00000000:00000000 02:00028D8B 00000000 0 0 32989 4 0000000000000000 20 4 31 10 19
2323
`
24-
entries, err := ParseWithEndian(strings.NewReader(procNetTCP), TCP, isBE)
24+
entries, err := parseWithEndian(strings.NewReader(procNetTCP), TCP, isBE)
2525
assert.NilError(t, err)
2626
t.Log(entries)
2727

@@ -38,7 +38,7 @@ func TestParseTCP6(t *testing.T) {
3838
const isBE = false
3939
procNetTCP := ` sl local_address remote_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
4040
0: 000080FE00000000FF57A6705DC771FE:0050 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 850222 1 0000000000000000 100 0 0 10 0`
41-
entries, err := ParseWithEndian(strings.NewReader(procNetTCP), TCP6, isBE)
41+
entries, err := parseWithEndian(strings.NewReader(procNetTCP), TCP6, isBE)
4242
assert.NilError(t, err)
4343
t.Log(entries)
4444

@@ -54,7 +54,7 @@ func TestParseTCP6Zero(t *testing.T) {
5454
1: 00000000000000000000000000000000:006F 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 26772 1 0000000000000000 100 0 0 10 0
5555
2: 00000000000000000000000000000000:0050 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 1210901 1 0000000000000000 100 0 0 10 0
5656
`
57-
entries, err := ParseWithEndian(strings.NewReader(procNetTCP), TCP6, isBE)
57+
entries, err := parseWithEndian(strings.NewReader(procNetTCP), TCP6, isBE)
5858
assert.NilError(t, err)
5959
t.Log(entries)
6060

@@ -71,7 +71,7 @@ func TestParseUDP(t *testing.T) {
7171
731: 0369A8C0:0044 00000000:0000 07 00000000:00000000 00:00000000 00000000 998 0 29132 2 0000000000000000 0
7272
731: 0F05A8C0:0044 00000000:0000 07 00000000:00000000 00:00000000 00000000 998 0 4049 2 0000000000000000 0
7373
1768: 00000000:1451 00000000:0000 07 00000000:00000000 00:00000000 00000000 502 0 28364 2 0000000000000000 0 `
74-
entries, err := ParseWithEndian(strings.NewReader(procNetTCP), UDP, isBE)
74+
entries, err := parseWithEndian(strings.NewReader(procNetTCP), UDP, isBE)
7575
assert.NilError(t, err)
7676
t.Log(entries)
7777

@@ -149,7 +149,7 @@ func TestParseAddress(t *testing.T) {
149149

150150
for _, test := range tests {
151151
t.Run(test.input, func(t *testing.T) {
152-
ip, port, err := ParseAddressWithEndian(test.input, test.bigEndian)
152+
ip, port, err := parseAddressWithEndian(test.input, test.bigEndian)
153153
if test.expectedErrSubstr != "" {
154154
assert.ErrorContains(t, err, test.expectedErrSubstr)
155155
} else {

0 commit comments

Comments
 (0)