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 committed Mar 26, 2024
1 parent 7199b3c commit 6c71a36
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 131 deletions.
183 changes: 158 additions & 25 deletions configuration/tcp_request_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,13 @@ 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
Expand Down Expand Up @@ -397,12 +404,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 @@ -456,6 +463,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 @@ -522,11 +539,6 @@ 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.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 @@ -619,6 +631,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.SetFcMark:
rule.Action = models.TCPRequestRuleActionSetDashFcDashMark
rule.Expr = a.Expr.String()
Expand All @@ -642,6 +684,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 @@ -828,6 +877,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 @@ -854,6 +922,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
case models.TCPRequestRuleActionSetDashFcDashMark:
return &tcp_types.Connection{
Action: &actions.SetFcMark{
Expand Down Expand Up @@ -908,15 +984,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 @@ -972,7 +1048,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 @@ -983,7 +1059,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 @@ -1008,7 +1084,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 @@ -1032,6 +1108,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 @@ -1095,31 +1179,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 @@ -1129,23 +1213,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 @@ -1294,24 +1378,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 @@ -1331,6 +1454,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 6c71a36

Please sign in to comment.