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

Update eBPF config cache and local l3af-config-store file for a deleted interface #374

Merged
merged 10 commits into from
Apr 27, 2024

Conversation

jaysheth2
Copy link
Contributor

  • When an interface is deleted on the fly, and a delete/remove call is received for the that interface, all the programs associated with that interface should be deleted. Hence, in the PR, on receiving a delete call for an unloaded-interface, the local copy of the programs stored in go-interface and the l3af-config-store file is deleted for cleanup

@jaysheth2 jaysheth2 marked this pull request as ready for review April 21, 2024 22:43
kf/nfconfig.go Outdated
@@ -1312,6 +1323,9 @@ func (c *NFConfigs) DeleteEbpfPrograms(bpfProgs []models.L3afBPFProgramNames) er
if err := c.SaveConfigsToConfigStore(); err != nil {
return fmt.Errorf("SaveConfigsToConfigStore failed to save configs %w", err)
}
//if err := c.SaveConfigsToConfigStore(); err != nil {
// return fmt.Errorf("SaveConfigsToConfigStore failed to save configs %w", err)
//}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

charleskbliu0
charleskbliu0 previously approved these changes Apr 22, 2024
Copy link

@charleskbliu0 charleskbliu0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

kf/nfconfig.go Outdated
errOut := fmt.Errorf("%s interface name not found in the host", ifaceName)
errOut := fmt.Errorf("%s interface name not found in the host, and deleting all EBPF programs associated to ", ifaceName)
if c.EgressTCBpfs[ifaceName] != nil {
c.EgressTCBpfs[ifaceName] = nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sets the lists to nil, are there any additional cleanups that need to happen or is this enough to remove the reference counts and allow the garbage collector to lazily clean up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the interface is deleted, all the programs associated with will automatically be deleted by the kernel.
I have added a separate function for cleanup all the L3AFd related parameters and information related to the deleted interface.

Signed-off-by: Jay Sheth <[email protected]>
pmoroney
pmoroney previously approved these changes Apr 24, 2024
Copy link

@pmoroney pmoroney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Signed-off-by: Jay Sheth <[email protected]>
Signed-off-by: Jay Sheth <[email protected]>
Signed-off-by: Jay Sheth <[email protected]>
kf/bpf.go Outdated
if err := b.UnloadProgram(ifaceName, direction); err != nil {
return fmt.Errorf("BPFProgram %s unload failed on interface %s with error: %w", b.Program.Name, ifaceName, err)
allInterfaces, _ := getHostInterfaces()
for iface := range allInterfaces {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should fetch interface from map and avoid for loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

kf/nfconfig.go Outdated
Comment on lines 685 to 690
for e := bpfList.Front(); e != nil; e = e.Next() {
data := e.Value.(*BPF)
if err := data.Stop(ifaceName, models.XDPIngressType, c.HostConfig.BpfChainingEnabled); err != nil {
log.Error().Err(err).Msgf("failed to remove map file for program %s => %s", ifaceName, data.Program.Name)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for e := bpfList.Front(); e != nil; e = e.Next() {
data := e.Value.(*BPF)
if err := data.Stop(ifaceName, models.XDPIngressType, c.HostConfig.BpfChainingEnabled); err != nil {
log.Error().Err(err).Msgf("failed to remove map file for program %s => %s", ifaceName, data.Program.Name)
}
}
c.StopNRemoveAllBPFPrograms(ifaceName, models.XDPIngressType)

kf/nfconfig.go Outdated
Comment on lines 675 to 680
for e := bpfList.Front(); e != nil; e = e.Next() {
data := e.Value.(*BPF)
if err := data.Stop(ifaceName, models.IngressType, c.HostConfig.BpfChainingEnabled); err != nil {
log.Error().Err(err).Msgf("failed to remove map file for program %s => %s", ifaceName, data.Program.Name)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for e := bpfList.Front(); e != nil; e = e.Next() {
data := e.Value.(*BPF)
if err := data.Stop(ifaceName, models.IngressType, c.HostConfig.BpfChainingEnabled); err != nil {
log.Error().Err(err).Msgf("failed to remove map file for program %s => %s", ifaceName, data.Program.Name)
}
}
c.StopNRemoveAllBPFPrograms(ifaceName, models.IngressType)

kf/nfconfig.go Outdated
Comment on lines 665 to 670
for e := bpfList.Front(); e != nil; e = e.Next() {
data := e.Value.(*BPF)
if err := data.Stop(ifaceName, models.EgressType, c.HostConfig.BpfChainingEnabled); err != nil {
log.Error().Err(err).Msgf("failed to remove map file for program %s => %s", ifaceName, data.Program.Name)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for e := bpfList.Front(); e != nil; e = e.Next() {
data := e.Value.(*BPF)
if err := data.Stop(ifaceName, models.EgressType, c.HostConfig.BpfChainingEnabled); err != nil {
log.Error().Err(err).Msgf("failed to remove map file for program %s => %s", ifaceName, data.Program.Name)
}
}
c.StopNRemoveAllBPFPrograms(ifaceName, models.EgressType)

kf/nfconfig.go Outdated
Comment on lines 1247 to 1262
if c.IngressXDPBpfs[ifaceName] != nil {
if err := c.StopNRemoveAllBPFPrograms(ifaceName, models.XDPIngressType); err != nil {
log.Warn().Err(err).Msg("failed to Close Ingress XDP BPF Program")
}
}
if c.IngressTCBpfs[ifaceName] != nil {
if err := c.StopNRemoveAllBPFPrograms(ifaceName, models.IngressType); err != nil {
log.Warn().Err(err).Msg("failed to Close Ingress XDP BPF Program")
}
}
if c.EgressTCBpfs[ifaceName] != nil {
if err := c.StopNRemoveAllBPFPrograms(ifaceName, models.EgressType); err != nil {
log.Warn().Err(err).Msg("failed to Close Ingress XDP BPF Program")
}
}
errOut := fmt.Errorf("%s interface name not found in the host, Stop called ", ifaceName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this code block into member function and call both the places.

Copy link
Contributor

@sanfern sanfern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

@charleskbliu0 charleskbliu0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@sanfern sanfern merged commit 57b9b25 into main Apr 27, 2024
8 checks passed
@sanfern sanfern added the bug Something isn't working label Apr 27, 2024
@jaysheth2 jaysheth2 deleted the jay-hv-del-fix branch June 12, 2024 06:16
@sanfern sanfern changed the title Fix for clearing up NF config stored withing the interface and the l3af-config-store file Update eBPF config cache and local l3af-config-store file for a deleted interface Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Delete L3AFD - related information once a network interface is deleted on-the-fly
4 participants