Skip to content

Commit

Permalink
MINOR: Add support for set-fc-mark, set-fc-tos
Browse files Browse the repository at this point in the history
And also set-bc-mark and set-bc-tos. Those actions reaplce
set-mark and set-tos, which are now deprecated in HAProxy.
  • Loading branch information
oliwer committed Feb 23, 2024
1 parent c4a4d20 commit cac55e0
Show file tree
Hide file tree
Showing 22 changed files with 468 additions and 31 deletions.
52 changes: 52 additions & 0 deletions configuration/http_request_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,34 @@ func ParseHTTPRequestRule(f types.Action) (rule *models.HTTPRequestRule, err err
Cond: v.Cond,
CondTest: v.CondTest,
}
case *actions.SetBcMark:
rule = &models.HTTPRequestRule{
Type: models.HTTPRequestRuleTypeSetDashBcDashMark,
Expr: v.Expr.String(),
Cond: v.Cond,
CondTest: v.CondTest,
}
case *actions.SetBcTos:
rule = &models.HTTPRequestRule{
Type: models.HTTPRequestRuleTypeSetDashBcDashTos,
Expr: v.Expr.String(),
Cond: v.Cond,
CondTest: v.CondTest,
}
case *actions.SetFcMark:
rule = &models.HTTPRequestRule{
Type: models.HTTPRequestRuleTypeSetDashFcDashMark,
Expr: v.Expr.String(),
Cond: v.Cond,
CondTest: v.CondTest,
}
case *actions.SetFcTos:
rule = &models.HTTPRequestRule{
Type: models.HTTPRequestRuleTypeSetDashFcDashTos,
Expr: v.Expr.String(),
Cond: v.Cond,
CondTest: v.CondTest,
}
}

return rule, err
Expand Down Expand Up @@ -1191,6 +1219,30 @@ func SerializeHTTPRequestRule(f models.HTTPRequestRule) (rule types.Action, err
Cond: f.Cond,
CondTest: f.CondTest,
}
case "set-bc-mark":
rule = &actions.SetBcMark{
Expr: common.Expression{Expr: strings.Split(f.Expr+f.MarkValue, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
}
case "set-bc-tos":
rule = &actions.SetBcTos{
Expr: common.Expression{Expr: strings.Split(f.Expr+f.TosValue, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
}
case "set-fc-mark":
rule = &actions.SetFcMark{
Expr: common.Expression{Expr: strings.Split(f.Expr+f.MarkValue, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
}
case "set-fc-tos":
rule = &actions.SetFcTos{
Expr: common.Expression{Expr: strings.Split(f.Expr+f.TosValue, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
}
}

return rule, err
Expand Down
26 changes: 26 additions & 0 deletions configuration/http_response_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,20 @@ func ParseHTTPResponseRule(f types.Action) *models.HTTPResponseRule { //nolint:m
Cond: v.Cond,
CondTest: v.CondTest,
}
case *actions.SetFcMark:
return &models.HTTPResponseRule{
Type: models.HTTPResponseRuleTypeSetDashFcDashMark,
Expr: v.Expr.String(),
Cond: v.Cond,
CondTest: v.CondTest,
}
case *actions.SetFcTos:
return &models.HTTPResponseRule{
Type: models.HTTPResponseRuleTypeSetDashFcDashTos,
Expr: v.Expr.String(),
Cond: v.Cond,
CondTest: v.CondTest,
}
}
return nil
}
Expand Down Expand Up @@ -855,6 +869,18 @@ func SerializeHTTPResponseRule(f models.HTTPResponseRule) (rule types.Action, er
Cond: f.Cond,
CondTest: f.CondTest,
}
case "set-fc-mark":
rule = &actions.SetFcMark{
Expr: common.Expression{Expr: strings.Split(f.Expr+f.MarkValue, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
}
case "set-fc-tos":
rule = &actions.SetFcTos{
Expr: common.Expression{Expr: strings.Split(f.Expr+f.TosValue, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
}
}
return rule, err
}
104 changes: 104 additions & 0 deletions configuration/tcp_request_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,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 *actions.SetFcMark:
rule.Action = models.TCPRequestRuleActionSetDashFcDashMark
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetFcTos:
rule.Action = models.TCPRequestRuleActionSetDashFcDashTos
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()
Expand Down Expand Up @@ -485,6 +495,26 @@ func ParseTCPRequestRule(f types.TCPType) (rule *models.TCPRequestRule, err erro
rule.MarkValue = a.Value
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetBcMark:
rule.Action = models.TCPRequestRuleActionSetDashBcDashMark
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetBcTos:
rule.Action = models.TCPRequestRuleActionSetDashBcDashTos
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetFcMark:
rule.Action = models.TCPRequestRuleActionSetDashFcDashMark
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetFcTos:
rule.Action = models.TCPRequestRuleActionSetDashFcDashTos
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()
Expand Down Expand Up @@ -582,6 +612,16 @@ 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.SetFcMark:
rule.Action = models.TCPRequestRuleActionSetDashFcDashMark
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetFcTos:
rule.Action = models.TCPRequestRuleActionSetDashFcDashTos
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 @@ -807,6 +847,22 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashFcDashMark:
return &tcp_types.Connection{
Action: &actions.SetFcMark{
Expr: common.Expression{Expr: strings.Split(f.Expr+f.MarkValue, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashFcDashTos:
return &tcp_types.Connection{
Action: &actions.SetFcTos{
Expr: common.Expression{Expr: strings.Split(f.Expr+f.TosValue, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
}
return nil, NewConfError(ErrValidationError, fmt.Sprintf("unsupported action '%T' in tcp_request_rule", f.Action))
case models.TCPRequestRuleTypeContent:
Expand Down Expand Up @@ -1089,6 +1145,38 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashBcDashMark:
return &tcp_types.Content{
Action: &actions.SetBcMark{
Expr: common.Expression{Expr: strings.Split(f.Expr+f.MarkValue, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashBcDashTos:
return &tcp_types.Content{
Action: &actions.SetBcTos{
Expr: common.Expression{Expr: strings.Split(f.Expr+f.TosValue, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashFcDashMark:
return &tcp_types.Content{
Action: &actions.SetFcMark{
Expr: common.Expression{Expr: strings.Split(f.Expr+f.MarkValue, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashFcDashTos:
return &tcp_types.Content{
Action: &actions.SetFcTos{
Expr: common.Expression{Expr: strings.Split(f.Expr+f.TosValue, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
}
return nil, NewConfError(ErrValidationError, fmt.Sprintf("unsupported action '%T' in tcp_request_rule", f.Action))
case models.TCPRequestRuleTypeSession:
Expand Down Expand Up @@ -1243,6 +1331,22 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashFcDashMark:
return &tcp_types.Session{
Action: &actions.SetFcMark{
Expr: common.Expression{Expr: strings.Split(f.Expr+f.MarkValue, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
case models.TCPRequestRuleActionSetDashFcDashTos:
return &tcp_types.Session{
Action: &actions.SetFcTos{
Expr: common.Expression{Expr: strings.Split(f.Expr+f.TosValue, " ")},
Cond: f.Cond,
CondTest: f.CondTest,
},
}, nil
}
return nil, NewConfError(ErrValidationError, fmt.Sprintf("unsupported action '%T' in tcp_request_rule", f.Action))
case models.TCPRequestRuleTypeInspectDashDelay:
Expand Down
33 changes: 33 additions & 0 deletions configuration/tcp_response_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func ParseTCPResponseRules(backend string, p parser.Parser) (models.TCPResponseR
return tcpResRules, nil
}

//nolint:maintidx
func ParseTCPResponseRule(t types.TCPType) (*models.TCPResponseRule, error) {
switch v := t.(type) {
case *tcp_types.InspectDelay:
Expand Down Expand Up @@ -346,6 +347,22 @@ func ParseTCPResponseRule(t types.TCPType) (*models.TCPResponseRule, error) {
Cond: a.Cond,
CondTest: a.CondTest,
}, nil
case *actions.SetFcMark:
return &models.TCPResponseRule{
Type: models.TCPResponseRuleTypeContent,
Action: models.TCPResponseRuleActionSetDashFcDashMark,
Expr: a.Expr.String(),
Cond: a.Cond,
CondTest: a.CondTest,
}, nil
case *actions.SetFcTos:
return &models.TCPResponseRule{
Type: models.TCPResponseRuleTypeContent,
Action: models.TCPResponseRuleActionSetDashFcDashTos,
Expr: a.Expr.String(),
Cond: a.Cond,
CondTest: a.CondTest,
}, nil
case *actions.SilentDrop:
return &models.TCPResponseRule{
Type: models.TCPResponseRuleTypeContent,
Expand Down Expand Up @@ -526,6 +543,22 @@ func SerializeTCPResponseRule(t models.TCPResponseRule) (types.TCPType, error) {
CondTest: t.CondTest,
},
}, nil
case models.TCPResponseRuleActionSetDashFcDashMark:
return &tcp_types.Content{
Action: &actions.SetFcMark{
Expr: common.Expression{Expr: strings.Split(t.Expr+t.MarkValue, " ")},
Cond: t.Cond,
CondTest: t.CondTest,
},
}, nil
case models.TCPResponseRuleActionSetDashFcDashTos:
return &tcp_types.Content{
Action: &actions.SetFcTos{
Expr: common.Expression{Expr: strings.Split(t.Expr+t.TosValue, " ")},
Cond: t.Cond,
CondTest: t.CondTest,
},
}, nil
}
case models.TCPResponseRuleTypeInspectDashDelay:
if t.Timeout != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/google/go-cmp v0.6.0
github.com/google/renameio v1.0.1
github.com/google/uuid v1.6.0
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240221073837-5b782186def2
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240223102144-ffe6142ca8e4
github.com/json-iterator/go v1.1.12
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/mitchellh/mapstructure v1.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ github.com/google/renameio v1.0.1 h1:Lh/jXZmvZxb0BBeSY5VKEfidcbcbenKjZFzM/q0fSeU
github.com/google/renameio v1.0.1/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWUAweKUpk=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240221073837-5b782186def2 h1:YXI/15X8xJPrnyO8brmiNaFhOD17Ib9nszHRrlEtuIw=
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240221073837-5b782186def2/go.mod h1:iy8nBB1eopwYbyeh3FQpjxZUxfcIDyTV9bW0F1t+cVA=
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240223102144-ffe6142ca8e4 h1:Iszl0fMqYG34rNmNskZVEoFvuN2RZ626y98kvmxqgaQ=
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240223102144-ffe6142ca8e4/go.mod h1:iy8nBB1eopwYbyeh3FQpjxZUxfcIDyTV9bW0F1t+cVA=
github.com/haproxytech/go-logger v1.1.0 h1:HgGtYaI1ApkvbQdsm7f9AzQQoxTB7w37criTflh7IQE=
github.com/haproxytech/go-logger v1.1.0/go.mod h1:OekUd8HCb7ubxMplzHUPBTHNxZmddOWfOjWclZsqIeM=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand Down
18 changes: 15 additions & 3 deletions models/http_request_rule.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cac55e0

Please sign in to comment.