Skip to content

Commit c474076

Browse files
committed
feat(guestagent/sockets): replace /proc/net parsing with NETLINK_INET_DIAG
Replace legacy /proc/net/{tcp,udp} parsing with a netlink (NETLINK_INET_DIAG) based implementation Signed-off-by: ashwat287 <ashwatpas@gmail.com>
1 parent 633fd2b commit c474076

File tree

10 files changed

+282
-391
lines changed

10 files changed

+282
-391
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ require (
2929
github.com/lima-vm/sshocker v0.3.8 // gomodjail:unconfined
3030
github.com/mattn/go-isatty v0.0.20
3131
github.com/mattn/go-shellwords v1.0.12
32+
github.com/mdlayher/netlink v1.8.0
3233
github.com/mdlayher/vsock v1.2.1 // gomodjail:unconfined
3334
github.com/miekg/dns v1.1.68 // gomodjail:unconfined
3435
github.com/mikefarah/yq/v4 v4.47.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6T
185185
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
186186
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
187187
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
188-
github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/g=
189-
github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw=
188+
github.com/mdlayher/netlink v1.8.0 h1:e7XNIYJKD7hUct3Px04RuIGJbBxy1/c4nX7D5YyvvlM=
189+
github.com/mdlayher/netlink v1.8.0/go.mod h1:UhgKXUlDQhzb09DrCl2GuRNEglHmhYoWAHid9HK3594=
190190
github.com/mdlayher/packet v1.1.2 h1:3Up1NG6LZrsgDVn6X4L9Ge/iyRyxFEFD9o6Pr3Q1nQY=
191191
github.com/mdlayher/packet v1.1.2/go.mod h1:GEu1+n9sG5VtiRE4SydOmX5GTwyyYlteZiFU+x0kew4=
192192
github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos=

pkg/guestagent/guestagent_linux.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/lima-vm/lima/v2/pkg/guestagent/api"
2121
"github.com/lima-vm/lima/v2/pkg/guestagent/iptables"
2222
"github.com/lima-vm/lima/v2/pkg/guestagent/kubernetesservice"
23-
"github.com/lima-vm/lima/v2/pkg/guestagent/procnettcp"
23+
"github.com/lima-vm/lima/v2/pkg/guestagent/sockets"
2424
"github.com/lima-vm/lima/v2/pkg/guestagent/ticker"
2525
"github.com/lima-vm/lima/v2/pkg/guestagent/timesync"
2626
)
@@ -222,24 +222,24 @@ func (a *agent) Events(ctx context.Context, ch chan *api.Event) {
222222

223223
func (a *agent) LocalPorts(ctx context.Context) ([]*api.IPPort, error) {
224224
var res []*api.IPPort
225-
tcpParsed, err := procnettcp.ParseFiles()
225+
socketsList, err := sockets.List()
226226
if err != nil {
227227
return res, err
228228
}
229229

230-
for _, f := range tcpParsed {
230+
for _, f := range socketsList {
231231
switch f.Kind {
232-
case procnettcp.TCP, procnettcp.TCP6:
233-
if f.State == procnettcp.TCPListen {
232+
case sockets.TCP, sockets.TCP6:
233+
if f.State == sockets.TCPListen {
234234
res = append(res,
235235
&api.IPPort{
236236
Ip: f.IP.String(),
237237
Port: int32(f.Port),
238238
Protocol: "tcp",
239239
})
240240
}
241-
case procnettcp.UDP, procnettcp.UDP6:
242-
if f.State == procnettcp.UDPUnconnected {
241+
case sockets.UDP, sockets.UDP6:
242+
if f.State == sockets.UDPUnconnected {
243243
res = append(res,
244244
&api.IPPort{
245245
Ip: f.IP.String(),
@@ -274,7 +274,7 @@ func (a *agent) LocalPorts(ctx context.Context) ([]*api.IPPort, error) {
274274

275275
for _, ipt := range ipts {
276276
port := int32(ipt.AddrPort.Port())
277-
// Make sure the port isn't already listed from procnettcp
277+
// Make sure the port isn't already listed from sockets
278278
found := false
279279
for _, re := range res {
280280
if re.Port == port {

pkg/guestagent/procnettcp/fuzz_test.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

pkg/guestagent/procnettcp/procnettcp.go

Lines changed: 0 additions & 163 deletions
This file was deleted.

pkg/guestagent/procnettcp/procnettcp_linux.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)