Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: sferna1 <santhosh.fernandes@gmail.com>
  • Loading branch information
sanfern committed Aug 26, 2023
2 parents 282801f + 01e566c commit b3232a9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Default Code Owners

* @sanfern @charleskbliu0 @jniesz @dthaler @ajayR006
* @sanfern @charleskbliu0 @jniesz @dthaler @ajayR006 @dalalkaran @binojrajan
43 changes: 28 additions & 15 deletions kf/bpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ type BPF struct {
ProgMapCollection *ebpf.Collection `json:"_"` // eBPF Collection reference
ProgMapID ebpf.MapID
hostConfig *config.Config
TCFilter *tc.Filter
TCFilter *tc.Filter `json:"-"` // handle to tc filter
XDPLink link.Link `json:"-"` // handle xdp link object
}

func NewBpfProgram(ctx context.Context, program models.BPFProgram, conf *config.Config) *BPF {
Expand Down Expand Up @@ -118,6 +119,7 @@ func LoadRootProgram(ifaceName string, direction string, progType string, conf *
PrevMapNamePath: "",
hostConfig: conf,
MapNamePath: filepath.Join(conf.BpfMapDefaultPath, conf.XDPRootMapName),
XDPLink: nil,
}
case models.TCType:
rootProgBPF = &BPF{
Expand Down Expand Up @@ -1121,56 +1123,67 @@ func (b *BPF) LoadXDPAttachProgram(ifaceName string, eBPFProgram *BPF) error {
bpfRootMap := CollectionRef.Maps[eBPFProgram.Program.MapName]

// Pinning root map
rootArrayMapFileName := filepath.Join(b.hostConfig.BpfMapDefaultPath, eBPFProgram.Program.MapName)
if err := bpfRootMap.Pin(rootArrayMapFileName); err != nil {
return fmt.Errorf("%s:failed to pin the map", rootArrayMapFileName)
if b.hostConfig.BpfChainingEnabled {
rootArrayMapFileName := filepath.Join(b.hostConfig.BpfMapDefaultPath, eBPFProgram.Program.MapName)
if err := bpfRootMap.Pin(rootArrayMapFileName); err != nil {
return fmt.Errorf("%s:failed to pin the map", rootArrayMapFileName)
}
}

_, err = link.AttachXDP(link.XDPOptions{
b.XDPLink, err = link.AttachXDP(link.XDPOptions{
Program: bpfRootProg,
Interface: iface.Index,
})

if err != nil {
return fmt.Errorf("could not attach XDP program: %s", err)
return fmt.Errorf("could not attach xdp program %s to interface %s : %v", b.Program.Name, ifaceName, err)
}

progInfo, err := bpfRootProg.Info()
if err != nil {
return fmt.Errorf("could not get program info of xdp root program: %s", err)
return fmt.Errorf("could not get program info of %s to interface %s : %v", b.Program.Name, ifaceName, err)
}

ok := false
b.ProgID, ok = progInfo.ID()
if !ok {
return fmt.Errorf("failed to fetch the xdp root Program ID")
return fmt.Errorf("failed to fetch the xdp program %s to interface %s : %v", b.Program.Name, ifaceName, err)
}

ebpfInfo, err := bpfRootMap.Info()
if err != nil {
return fmt.Errorf("fetching map info failed %v", err)
return fmt.Errorf("fetching map info failed for xdp program %s to interface %s : %v", b.Program.Name, ifaceName, err)
}

b.ProgMapID, ok = ebpfInfo.ID()
if !ok {
return fmt.Errorf("fetching map id failed %v", err)
return fmt.Errorf("fetching map id failed for xdp program %s to interface %s : %v", b.Program.Name, ifaceName, err)
}

return nil
}

// UnLoadProgram - Unload the program
// UnLoadProgram - Unload or detach the program from the interface and close all the program resources
// TODO: Before unloading make sure user program is stopped to avoid any errors
func (b *BPF) UnLoadProgram(ifaceName, direction string) error {
_, err := net.InterfaceByName(ifaceName)
if err != nil {
log.Fatal().Msgf("lookup network iface %q: %s", ifaceName, err)
}

if b.Program.ProgType == models.TCType {
if err := b.UnLoadTCProgram(ifaceName, direction); err != nil {
log.Warn().Msgf("UnloadTC program failed iface %q direction %s error - %v", ifaceName, direction, err)
// Verifying program attached to the interface.
// SeqID will be 0 for root program or any other program without chaining
if b.Program.SeqID == 0 {
if b.Program.ProgType == models.TCType {
if err := b.UnLoadTCProgram(ifaceName, direction); err != nil {
log.Warn().Msgf("removing tc filter failed iface %q direction %s error - %v", ifaceName, direction, err)
}
} else if b.Program.ProgType == models.XDPType {
if err := b.XDPLink.Close(); err != nil {
log.Warn().Msgf("removing xdp attached program failed iface %q direction %s error - %v", ifaceName, direction, err)
}
}
}

if b.ProgMapCollection != nil {
b.ProgMapCollection.Close()
}
Expand Down
2 changes: 1 addition & 1 deletion kf/kf_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (b *BPF) UnLoadTCProgram(ifaceName, direction string) error {

// Detaching / Deleting filter
if err := b.TCFilter.Delete(&filter); err != nil {
return fmt.Errorf("could not dettach filter : %v", err)
return fmt.Errorf("could not dettach tc filter for interface %s : %v", ifaceName, err)
}

return nil
Expand Down
12 changes: 6 additions & 6 deletions kf/nfconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,32 +828,32 @@ func (c *NFConfigs) RemoveMissingNetIfacesNBPFProgsInConfig(bpfProgCfgs []models
_, ok := c.IngressXDPBpfs[ifaceName]
if ok {
wg.Add(1)
go func() {
go func(bpfProg models.L3afBPFPrograms) {
defer wg.Done()
if err := c.RemoveMissingBPFProgramsInConfig(bpfProg, ifaceName, models.XDPIngressType); err != nil {
log.Error().Err(err).Msgf("Failed to stop missing program for network interface %s direction Ingress", ifaceName)
}
}()
}(bpfProg)
}
_, ok = c.IngressTCBpfs[ifaceName]
if ok {
wg.Add(1)
go func() {
go func(bpfProg models.L3afBPFPrograms) {
defer wg.Done()
if err := c.RemoveMissingBPFProgramsInConfig(bpfProg, ifaceName, models.IngressType); err != nil {
log.Error().Err(err).Msgf("Failed to stop missing program for network interface %s direction Ingress", ifaceName)
}
}()
}(bpfProg)
}
_, ok = c.EgressTCBpfs[ifaceName]
if ok {
wg.Add(1)
go func() {
go func(bpfProg models.L3afBPFPrograms) {
defer wg.Done()
if err := c.RemoveMissingBPFProgramsInConfig(bpfProg, ifaceName, models.EgressType); err != nil {
log.Error().Err(err).Msgf("Failed to stop missing program for network interface %s direction Ingress", ifaceName)
}
}()
}(bpfProg)
}
}
}
Expand Down

0 comments on commit b3232a9

Please sign in to comment.