Skip to content

Commit

Permalink
Look for NLM_F_DUMP_INTR in more places
Browse files Browse the repository at this point in the history
linkSubscribeAt, neighSubscribeAt, routeSubscribeAt
- can do an initial dump, which may report inconsistent results
-> if there's an error callback, call it with ErrNlmFDumpIntr

socketDiagXDPExecutor
- makes an NLM_F_DUMP request, without using Execute()
-> give it the same behaviour as functions that do use Execute()

Signed-off-by: Rob Murray <[email protected]>
  • Loading branch information
robmry committed Sep 9, 2024
1 parent cf56f66 commit f04458f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2441,6 +2441,9 @@ func linkSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- LinkUpdate, done <-c
continue
}
for _, m := range msgs {
if m.Header.Flags&unix.NLM_F_DUMP_INTR != 0 && cberr != nil {
cberr(ErrNlmFDumpIntr)
}
if m.Header.Type == unix.NLMSG_DONE {
continue
}
Expand Down
3 changes: 3 additions & 0 deletions neigh_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ func neighSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- NeighUpdate, done <
continue
}
for _, m := range msgs {
if m.Header.Flags&unix.NLM_F_DUMP_INTR != 0 && cberr != nil {
cberr(ErrNlmFDumpIntr)
}
if m.Header.Type == unix.NLMSG_DONE {
if listExisting {
// This will be called after handling AF_UNSPEC
Expand Down
3 changes: 3 additions & 0 deletions route_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,9 @@ func routeSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- RouteUpdate, done <
continue
}
for _, m := range msgs {
if m.Header.Flags&unix.NLM_F_DUMP_INTR != 0 && cberr != nil {
cberr(ErrNlmFDumpIntr)
}
if m.Header.Type == unix.NLMSG_DONE {
continue
}
Expand Down
11 changes: 9 additions & 2 deletions socket_xdp_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ func SocketDiagXDP() ([]*XDPDiagInfoResp, error) {
result = append(result, res)
return nil
})
if err != nil {
if err != nil && !errors.Is(err, ErrNlmFDumpIntr) {
return nil, err
}
return result, nil
return result, err
}

// socketDiagXDPExecutor requests XDP_DIAG_INFO for XDP family sockets.
Expand All @@ -128,6 +128,7 @@ func socketDiagXDPExecutor(receiver func(syscall.NetlinkMessage) error) error {
return err
}

dumpIntr := false
loop:
for {
msgs, from, err := s.Receive()
Expand All @@ -142,6 +143,9 @@ loop:
}

for _, m := range msgs {
if m.Header.Flags&unix.NLM_F_DUMP_INTR != 0 {
dumpIntr = true
}
switch m.Header.Type {
case unix.NLMSG_DONE:
break loop
Expand All @@ -154,6 +158,9 @@ loop:
}
}
}
if dumpIntr {
return ErrNlmFDumpIntr
}
return nil
}

Expand Down

0 comments on commit f04458f

Please sign in to comment.