Skip to content

Commit

Permalink
BUG/MEDIUM: tcp_request_rule: add all missing actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mjuraga authored and oliwer committed Aug 22, 2024
1 parent e9c52a1 commit 784a622
Show file tree
Hide file tree
Showing 7 changed files with 405 additions and 160 deletions.
190 changes: 165 additions & 25 deletions configuration/tcp_request_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,20 @@ func ParseTCPRequestRule(f types.TCPType) (rule *models.TCPRequestRule, err erro
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetVar:
rule.Action = models.TCPRequestRuleActionSetDashVar
rule.VarScope = a.VarScope
rule.VarName = a.VarName
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetVarFmt:
rule.Action = models.TCPRequestRuleActionSetDashVarDashFmt
rule.VarName = a.VarName
rule.VarFormat = strings.Join(a.Fmt.Expr, " ")
rule.VarScope = a.VarScope
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.UnsetVar:
rule.Action = models.TCPRequestRuleActionUnsetDashVar
rule.VarScope = a.Scope
Expand Down Expand Up @@ -380,12 +394,12 @@ func ParseTCPRequestRule(f types.TCPType) (rule *models.TCPRequestRule, err erro
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetPriorityClass:
rule.Action = "set-priority-class"
rule.Action = models.TCPRequestRuleActionSetDashPriorityDashClass
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetPriorityOffset:
rule.Action = "set-priority-offset"
rule.Action = models.TCPRequestRuleActionSetDashPriorityDashOffset
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
Expand Down Expand Up @@ -439,6 +453,16 @@ func ParseTCPRequestRule(f types.TCPType) (rule *models.TCPRequestRule, err erro
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *tcp_actions.SetSrc:
rule.Action = models.TCPRequestRuleActionSetDashSrc
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetSrcPort:
rule.Action = models.TCPRequestRuleActionSetDashSrcDashPort
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetVar:
rule.Action = models.TCPRequestRuleActionSetDashVar
rule.VarScope = a.VarScope
Expand Down Expand Up @@ -485,11 +509,6 @@ func ParseTCPRequestRule(f types.TCPType) (rule *models.TCPRequestRule, err erro
rule.MarkValue = a.Value
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetSrcPort:
rule.Action = models.TCPRequestRuleActionSetDashSrcDashPort
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetTos:
rule.Action = models.TCPRequestRuleActionSetDashTos
rule.TosValue = a.Value
Expand Down Expand Up @@ -576,6 +595,36 @@ func ParseTCPRequestRule(f types.TCPType) (rule *models.TCPRequestRule, err erro
rule.GptValue = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetDst:
rule.Action = models.TCPRequestRuleActionSetDashDst
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetDstPort:
rule.Action = models.TCPRequestRuleActionSetDashDstDashPort
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetMark:
rule.Action = models.TCPRequestRuleActionSetDashMark
rule.MarkValue = a.Value
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *tcp_actions.SetSrc:
rule.Action = models.TCPRequestRuleActionSetDashSrc
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetSrcPort:
rule.Action = models.TCPRequestRuleActionSetDashSrcDashPort
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetTos:
rule.Action = models.TCPRequestRuleActionSetDashTos
rule.TosValue = a.Value
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetVar:
rule.Action = models.TCPRequestRuleActionSetDashVar
rule.VarScope = a.VarScope
Expand All @@ -589,6 +638,13 @@ func ParseTCPRequestRule(f types.TCPType) (rule *models.TCPRequestRule, err erro
rule.VarName = a.Name
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetVarFmt:
rule.Action = models.TCPRequestRuleActionSetDashVarDashFmt
rule.VarName = a.VarName
rule.VarFormat = strings.Join(a.Fmt.Expr, " ")
rule.VarScope = a.VarScope
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SilentDrop:
rule.Action = models.TCPRequestRuleActionSilentDashDrop
rule.Cond = a.Cond
Expand Down Expand Up @@ -775,6 +831,25 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashVar:
return &tcp_types.Connection{
Action: &actions.SetVar{
VarName: f.VarName,
VarScope: f.VarScope,
Expr: common.Expression{Expr: strings.Split(f.Expr, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionUnsetDashVar:
return &tcp_types.Connection{
Action: &actions.UnsetVar{
Name: f.VarName,
Scope: f.VarScope,
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashVarDashFmt:
return &tcp_types.Connection{
Action: &actions.SetVarFmt{
Expand All @@ -801,6 +876,14 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashDstDashPort:
return &tcp_types.Connection{
Action: &actions.SetDstPort{
Expr: common.Expression{Expr: strings.Split(f.Expr, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
}
return nil, NewConfError(ErrValidationError, fmt.Sprintf("unsupported action '%s' in tcp_request_rule", f.Action))
case models.TCPRequestRuleTypeContent:
Expand Down Expand Up @@ -839,15 +922,15 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e
CondTest: f.CondTest,
},
}, nil
case "set-priority-class":
case models.TCPRequestRuleActionSetDashPriorityDashClass:
return &tcp_types.Content{
Action: &actions.SetPriorityClass{
Expr: common.Expression{Expr: strings.Split(f.Expr, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case "set-priority-offset":
case models.TCPRequestRuleActionSetDashPriorityDashOffset:
return &tcp_types.Content{
Action: &actions.SetPriorityOffset{
Expr: common.Expression{Expr: strings.Split(f.Expr, " ")},
Expand Down Expand Up @@ -903,7 +986,7 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e
},
}, nil
case models.TCPRequestRuleActionScDashAddDashGpc:
return &tcp_types.Connection{
return &tcp_types.Content{
Action: &actions.ScAddGpc{
ID: f.ScIncID,
Idx: f.ScIdx,
Expand All @@ -914,7 +997,7 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e
},
}, nil
case models.TCPRequestRuleActionScDashIncDashGpc:
return &tcp_types.Connection{
return &tcp_types.Content{
Action: &actions.ScIncGpc{
ID: f.ScIncID,
Idx: f.ScIdx,
Expand All @@ -939,7 +1022,7 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e
},
}, nil
case models.TCPRequestRuleActionScDashSetDashGpt0:
return &tcp_types.Connection{
return &tcp_types.Content{
Action: &actions.ScSetGpt0{
ID: f.ScIncID,
Expr: common.Expression{Expr: strings.Split(f.Expr, " ")},
Expand All @@ -963,6 +1046,14 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashSrc:
return &tcp_types.Content{
Action: &http_actions.SetSrc{
Expr: common.Expression{Expr: strings.Split(f.Expr, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashVar:
return &tcp_types.Content{
Action: &actions.SetVar{
Expand Down Expand Up @@ -1026,31 +1117,31 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e
},
}, nil
case models.TCPRequestRuleActionSetDashMark:
return &tcp_types.Connection{
return &tcp_types.Content{
Action: &actions.SetMark{
Value: f.MarkValue,
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashSrcDashPort:
return &tcp_types.Connection{
return &tcp_types.Content{
Action: &actions.SetSrcPort{
Expr: common.Expression{Expr: strings.Split(f.Expr, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashTos:
return &tcp_types.Connection{
return &tcp_types.Content{
Action: &actions.SetTos{
Value: f.TosValue,
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashVarDashFmt:
return &tcp_types.Connection{
return &tcp_types.Content{
Action: &actions.SetVarFmt{
Fmt: common.Expression{Expr: strings.Split(f.VarFormat, " ")},
VarName: f.VarName,
Expand All @@ -1060,23 +1151,23 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e
},
}, nil
case models.TCPRequestRuleActionSetDashNice:
return &tcp_types.Connection{
return &tcp_types.Content{
Action: &actions.SetNice{
Value: strconv.FormatInt(f.NiceValue, 10),
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashLogDashLevel:
return &tcp_types.Connection{
return &tcp_types.Content{
Action: &actions.SetLogLevel{
Level: f.LogLevel,
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSwitchDashMode:
return &tcp_types.Connection{
return &tcp_types.Content{
Action: &tcp_actions.SwitchMode{
Proto: f.SwitchModeProto,
Cond: f.Cond,
Expand Down Expand Up @@ -1184,24 +1275,63 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e
CondTest: f.CondTest,
},
}, nil
case "sc-inc-gpt0":
case models.TCPRequestRuleActionScDashSetDashGpt0:
return &tcp_types.Session{
Action: &actions.ScSetGpt0{
ID: f.ScIncID,
Expr: common.Expression{Expr: []string{f.GptValue}},
Expr: common.Expression{Expr: strings.Split(f.Expr, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionScDashSetDashGpt0:
return &tcp_types.Connection{
Action: &actions.ScSetGpt0{
ID: f.ScIncID,
case models.TCPRequestRuleActionSetDashDst:
return &tcp_types.Session{
Action: &actions.SetDst{
Expr: common.Expression{Expr: strings.Split(f.Expr, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashDstDashPort:
return &tcp_types.Session{
Action: &actions.SetDstPort{
Expr: common.Expression{Expr: strings.Split(f.Expr, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashSrc:
return &tcp_types.Session{
Action: &http_actions.SetSrc{
Expr: common.Expression{Expr: strings.Split(f.Expr, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashSrcDashPort:
return &tcp_types.Session{
Action: &actions.SetSrcPort{
Expr: common.Expression{Expr: strings.Split(f.Expr, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashMark:
return &tcp_types.Session{
Action: &actions.SetDstPort{
Expr: common.Expression{Expr: strings.Split(f.Expr, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashTos:
return &tcp_types.Session{
Action: &actions.SetTos{
Value: f.TosValue,
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashVar:
return &tcp_types.Session{
Action: &actions.SetVar{
Expand All @@ -1221,6 +1351,16 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashVarDashFmt:
return &tcp_types.Session{
Action: &actions.SetVarFmt{
Fmt: common.Expression{Expr: strings.Split(f.VarFormat, " ")},
VarName: f.VarName,
VarScope: f.VarScope,
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSilentDashDrop:
return &tcp_types.Session{
Action: &actions.SilentDrop{
Expand Down
Loading

0 comments on commit 784a622

Please sign in to comment.