Skip to content

Commit

Permalink
pkg/selectors: fix incorrect action case
Browse files Browse the repository at this point in the history
Previously, there was no custom resource validation on the agent side so
we could use FollowFD or followfd indifferently. Now it's no longer the
case and the actionTypeStringTable is more useful if we don't need to
convert everything ToLowerCase all the time.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
  • Loading branch information
mtardy committed Jun 14, 2024
1 parent 6765233 commit e4ca9a3
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions pkg/selectors/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,35 @@ const (
)

var actionTypeTable = map[string]uint32{
"post": ActionTypePost,
"followfd": ActionTypeFollowFd,
"unfollowfd": ActionTypeUnfollowFd,
"sigkill": ActionTypeSigKill,
"override": ActionTypeOverride,
"copyfd": ActionTypeCopyFd,
"geturl": ActionTypeGetUrl,
"dnslookup": ActionTypeDnsLookup,
"nopost": ActionTypeNoPost,
"signal": ActionTypeSignal,
"tracksock": ActionTypeTrackSock,
"untracksock": ActionTypeUntrackSock,
"notifyenforcer": ActionTypeNotifyEnforcer,
"Post": ActionTypePost,
"FollowFD": ActionTypeFollowFd,
"UnfollowFD": ActionTypeUnfollowFd,
"Sigkill": ActionTypeSigKill,
"Override": ActionTypeOverride,
"CopyFD": ActionTypeCopyFd,
"GetUrl": ActionTypeGetUrl,
"DnsLookup": ActionTypeDnsLookup,
"NoPost": ActionTypeNoPost,
"Signal": ActionTypeSignal,
"TrackSock": ActionTypeTrackSock,
"UntrackSock": ActionTypeUntrackSock,
"NotifyEnforcer": ActionTypeNotifyEnforcer,
}

var actionTypeStringTable = map[uint32]string{
ActionTypePost: "post",
ActionTypeFollowFd: "followfd",
ActionTypeUnfollowFd: "unfollowfd",
ActionTypeSigKill: "sigkill",
ActionTypeOverride: "override",
ActionTypeCopyFd: "copyfd",
ActionTypeGetUrl: "geturl",
ActionTypeDnsLookup: "dnslookup",
ActionTypeNoPost: "nopost",
ActionTypeSignal: "signal",
ActionTypeTrackSock: "tracksock",
ActionTypeUntrackSock: "untracksock",
ActionTypeNotifyEnforcer: "notifyenforcer",
ActionTypePost: "Post",
ActionTypeFollowFd: "FollowFD",
ActionTypeUnfollowFd: "UnfollowFD",
ActionTypeSigKill: "Sigkill",
ActionTypeOverride: "Override",
ActionTypeCopyFd: "CopyFD",
ActionTypeGetUrl: "GetUrl",
ActionTypeDnsLookup: "DnsLookup",
ActionTypeNoPost: "NoPost",
ActionTypeSignal: "Signal",
ActionTypeTrackSock: "TrackSock",
ActionTypeUntrackSock: "UntrackSock",
ActionTypeNotifyEnforcer: "NotifyEnforcer",
}

const (
Expand Down Expand Up @@ -108,7 +108,7 @@ func MatchActionSigKill(spec interface{}) bool {

for _, s := range sels {
for _, act := range s.MatchActions {
if strings.ToLower(act.Action) == actionTypeStringTable[ActionTypeSigKill] {
if act.Action == actionTypeStringTable[ActionTypeSigKill] {
return true
}
}
Expand Down Expand Up @@ -342,7 +342,7 @@ func ParseMatchPids(k *KernelSelectorState, matchPids []v1alpha1.PIDSelector) er
}

func ActionTypeFromString(action string) int32 {
act, ok := actionTypeTable[strings.ToLower(action)]
act, ok := actionTypeTable[action]
if !ok {
return ActionTypeInvalid
}
Expand Down Expand Up @@ -894,7 +894,7 @@ func parseRateLimit(str string, scopeStr string) (uint32, uint32, error) {
}

func ParseMatchAction(k *KernelSelectorState, action *v1alpha1.ActionSelector, actionArgTable *idtable.Table) error {
act, ok := actionTypeTable[strings.ToLower(action.Action)]
act, ok := actionTypeTable[action.Action]
if !ok {
return fmt.Errorf("parseMatchAction: ActionType %s unknown", action.Action)
}
Expand Down Expand Up @@ -1343,7 +1343,7 @@ func InitKernelReturnSelectorState(selectors []v1alpha1.KProbeSelector, returnAr
func HasOverride(spec *v1alpha1.KProbeSpec) bool {
for _, s := range spec.Selectors {
for _, action := range s.MatchActions {
act := actionTypeTable[strings.ToLower(action.Action)]
act := actionTypeTable[action.Action]
if act == ActionTypeOverride {
return true
}
Expand Down

0 comments on commit e4ca9a3

Please sign in to comment.