Skip to content

Commit

Permalink
fix: stopping service with API issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mojtaba-esk committed Nov 30, 2023
1 parent f71de74 commit 46e3d67
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion xdp/bandwidth/bandwidth.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func (b *Bandwidth) Start(ctx context.Context, logger *zap.Logger) {
<-ctx.Done()

// Update the map with a rate of 0 to disable the bandwidth limiter.
err = x.BpfObjs.BandwidthLimitMap.Update(key, 0, ebpf.UpdateAny)
zero := int64(0)
err = x.BpfObjs.BandwidthLimitMap.Update(key, zero, ebpf.UpdateAny)
if err != nil {
logger.Error(fmt.Sprintf("could not update bandwidth limit rate to zero: %v", err))
return
Expand Down
3 changes: 2 additions & 1 deletion xdp/packetloss/packetloss.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func (p *PacketLoss) Start(ctx context.Context, logger *zap.Logger) {
<-ctx.Done()

// Update the map with a rate of 0 to disable the packetloss.
err = x.BpfObjs.PacketlossRateMap.Update(key, 0, ebpf.UpdateAny)
zero := int32(0)
err = x.BpfObjs.PacketlossRateMap.Update(key, zero, ebpf.UpdateAny)
if err != nil {
logger.Error(fmt.Sprintf("could not update packetloss drop rate to zero: %v", err))
return
Expand Down
13 changes: 8 additions & 5 deletions xdp/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ type XdpLoader interface {
}

type XdpObject struct {
BpfObjs bpfObjects
Link link.Link
totalServices int32
mu sync.Mutex
BpfObjs bpfObjects
Link link.Link
totalServices int32
mu sync.Mutex
netInterfaceIndex int
}

var xdpObject XdpObject
Expand All @@ -33,9 +34,11 @@ func GetPreparedXdpObject(netInterfaceIndex int) (*XdpObject, error) {
// We add this once, so we know how many services are using this object.
xdpObject.totalServices++

if xdpObject.Link != nil {
if xdpObject.Link != nil && xdpObject.netInterfaceIndex == netInterfaceIndex {
return &xdpObject, nil
}
xdpObject.netInterfaceIndex = netInterfaceIndex

// Load pre-compiled programs into the kernel.
err := loadBpfObjects(&xdpObject.BpfObjs, nil)
if err != nil {
Expand Down

0 comments on commit 46e3d67

Please sign in to comment.