diff --git a/configuration/tcp_request_rule.go b/configuration/tcp_request_rule.go index ce326b09..fdb0d293 100644 --- a/configuration/tcp_request_rule.go +++ b/configuration/tcp_request_rule.go @@ -348,6 +348,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 @@ -395,12 +402,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 @@ -462,6 +469,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 @@ -508,11 +525,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 @@ -613,6 +625,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 @@ -626,6 +668,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 @@ -824,6 +873,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{ @@ -850,6 +918,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: @@ -888,7 +964,7 @@ 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, " ")}, @@ -896,7 +972,7 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e 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, " ")}, @@ -952,7 +1028,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, @@ -963,7 +1039,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, @@ -1000,7 +1076,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, " ")}, @@ -1024,6 +1100,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{ @@ -1087,7 +1171,7 @@ 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, @@ -1095,7 +1179,7 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e }, }, 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, @@ -1103,7 +1187,7 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e }, }, nil case models.TCPRequestRuleActionSetDashTos: - return &tcp_types.Connection{ + return &tcp_types.Content{ Action: &actions.SetTos{ Value: f.TosValue, Cond: f.Cond, @@ -1111,7 +1195,7 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e }, }, 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, @@ -1121,7 +1205,7 @@ 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, @@ -1129,7 +1213,7 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e }, }, nil case models.TCPRequestRuleActionSetDashLogDashLevel: - return &tcp_types.Connection{ + return &tcp_types.Content{ Action: &actions.SetLogLevel{ Level: f.LogLevel, Cond: f.Cond, @@ -1137,7 +1221,7 @@ func SerializeTCPRequestRule(f models.TCPRequestRule) (rule types.TCPType, err e }, }, nil case models.TCPRequestRuleActionSwitchDashMode: - return &tcp_types.Connection{ + return &tcp_types.Content{ Action: &tcp_actions.SwitchMode{ Proto: f.SwitchModeProto, Cond: f.Cond, @@ -1254,36 +1338,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.TCPRequestRuleActionScDashSetDashGpt: - idx, _ := strconv.ParseInt(f.ScIdx, 10, 64) + case models.TCPRequestRuleActionSetDashDst: return &tcp_types.Session{ - Action: &actions.ScSetGpt{ - ScID: f.ScIncID, - Idx: idx, - Int: f.ScInt, + Action: &actions.SetDst{ 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.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{ @@ -1303,6 +1414,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{ diff --git a/configuration/tcp_response_rule.go b/configuration/tcp_response_rule.go index e63e90d1..c2cfc100 100644 --- a/configuration/tcp_response_rule.go +++ b/configuration/tcp_response_rule.go @@ -375,6 +375,24 @@ func ParseTCPResponseRule(t types.TCPType) (*models.TCPResponseRule, error) { Cond: a.Cond, CondTest: a.CondTest, }, nil + case *actions.SetVar: + return &models.TCPResponseRule{ + Action: models.TCPResponseRuleActionSetDashVar, + VarScope: a.VarScope, + VarName: a.VarName, + Expr: a.Expr.String(), + Cond: a.Cond, + CondTest: a.CondTest, + }, nil + case *actions.SetVarFmt: + return &models.TCPResponseRule{ + Action: models.TCPResponseRuleActionSetDashVarDashFmt, + VarName: a.VarName, + VarFormat: strings.Join(a.Fmt.Expr, " "), + VarScope: a.VarScope, + Cond: a.Cond, + CondTest: a.CondTest, + }, nil case *actions.UnsetVar: return &models.TCPResponseRule{ Type: models.TCPResponseRuleTypeContent, @@ -389,8 +407,7 @@ func ParseTCPResponseRule(t types.TCPType) (*models.TCPResponseRule, error) { return nil, NewConfError(ErrValidationError, "invalid action") } -//nolint:maintidx -func SerializeTCPResponseRule(t models.TCPResponseRule) (types.TCPType, error) { +func SerializeTCPResponseRule(t models.TCPResponseRule) (types.TCPType, error) { //nolint:maintidx switch t.Type { case models.TCPResponseRuleTypeContent: switch t.Action { @@ -557,6 +574,26 @@ func SerializeTCPResponseRule(t models.TCPResponseRule) (types.TCPType, error) { CondTest: t.CondTest, }, }, nil + case models.TCPRequestRuleActionSetDashVarDashFmt: + return &tcp_types.Content{ + Action: &actions.SetVarFmt{ + Fmt: common.Expression{Expr: strings.Split(t.VarFormat, " ")}, + VarName: t.VarName, + VarScope: t.VarScope, + Cond: t.Cond, + CondTest: t.CondTest, + }, + }, nil + case models.TCPRequestRuleActionSetDashVar: + return &tcp_types.Content{ + Action: &actions.SetVar{ + VarName: t.VarName, + VarScope: t.VarScope, + Expr: common.Expression{Expr: strings.Split(t.Expr, " ")}, + Cond: t.Cond, + CondTest: t.CondTest, + }, + }, nil case models.TCPResponseRuleActionUnsetDashVar: return &tcp_types.Content{ Action: &actions.UnsetVar{ diff --git a/models/tcp_request_rule.go b/models/tcp_request_rule.go index 81a3229b..2e9d1bf4 100644 --- a/models/tcp_request_rule.go +++ b/models/tcp_request_rule.go @@ -38,8 +38,8 @@ import ( // swagger:model tcp_request_rule type TCPRequestRule struct { // action - // Enum: [accept attach-srv capture do-resolve expect-netscaler-cip expect-proxy lua reject sc-add-gpc sc-inc-gpc sc-inc-gpc0 sc-inc-gpc1 sc-set-gpt sc-set-gpt0 set-bandwidth-limit set-dst-port set-dst set-log-level set-mark set-nice set-priority set-src set-src-port set-tos set-var set-var-fmt send-spoe-group silent-drop switch-mode track-sc0 track-sc1 track-sc2 track-sc unset-var use-service] - // +kubebuilder:validation:Enum=accept;attach-srv;capture;do-resolve;expect-netscaler-cip;expect-proxy;lua;reject;sc-add-gpc;sc-inc-gpc;sc-inc-gpc0;sc-inc-gpc1;sc-set-gpt;sc-set-gpt0;set-bandwidth-limit;set-dst-port;set-dst;set-log-level;set-mark;set-nice;set-priority;set-src;set-src-port;set-tos;set-var;set-var-fmt;send-spoe-group;silent-drop;switch-mode;track-sc0;track-sc1;track-sc2;track-sc;unset-var;use-service; + // Enum: [accept attach-srv capture do-resolve expect-netscaler-cip expect-proxy lua reject sc-add-gpc sc-inc-gpc sc-inc-gpc0 sc-inc-gpc1 sc-set-gpt sc-set-gpt0 send-spoe-group set-bandwidth-limit set-dst-port set-dst set-log-level set-mark set-nice set-priority-class set-priority-offset set-src set-src-port set-tos set-var set-var-fmt silent-drop switch-mode track-sc0 track-sc1 track-sc2 track-sc unset-var use-service] + // +kubebuilder:validation:Enum=accept;attach-srv;capture;do-resolve;expect-netscaler-cip;expect-proxy;lua;reject;sc-add-gpc;sc-inc-gpc;sc-inc-gpc0;sc-inc-gpc1;sc-set-gpt;sc-set-gpt0;send-spoe-group;set-bandwidth-limit;set-dst-port;set-dst;set-log-level;set-mark;set-nice;set-priority-class;set-priority-offset;set-src;set-src-port;set-tos;set-var;set-var-fmt;silent-drop;switch-mode;track-sc0;track-sc1;track-sc2;track-sc;unset-var;use-service; Action string `json:"action,omitempty"` // bandwidth limit limit @@ -103,11 +103,6 @@ type TCPRequestRule struct { // +kubebuilder:validation:Minimum=-1024 NiceValue int64 `json:"nice_value,omitempty"` - // priority type - // Enum: [class offset] - // +kubebuilder:validation:Enum=class;offset; - PriorityType string `json:"priority_type,omitempty"` - // resolve protocol // Enum: [ipv4 ipv6] // +kubebuilder:validation:Enum=ipv4;ipv6; @@ -216,10 +211,6 @@ func (m *TCPRequestRule) Validate(formats strfmt.Registry) error { res = append(res, err) } - if err := m.validatePriorityType(formats); err != nil { - res = append(res, err) - } - if err := m.validateResolveProtocol(formats); err != nil { res = append(res, err) } @@ -250,7 +241,7 @@ var tcpRequestRuleTypeActionPropEnum []interface{} func init() { var res []string - if err := json.Unmarshal([]byte(`["accept","attach-srv","capture","do-resolve","expect-netscaler-cip","expect-proxy","lua","reject","sc-add-gpc","sc-inc-gpc","sc-inc-gpc0","sc-inc-gpc1","sc-set-gpt","sc-set-gpt0","set-bandwidth-limit","set-dst-port","set-dst","set-log-level","set-mark","set-nice","set-priority","set-src","set-src-port","set-tos","set-var","set-var-fmt","send-spoe-group","silent-drop","switch-mode","track-sc0","track-sc1","track-sc2","track-sc","unset-var","use-service"]`), &res); err != nil { + if err := json.Unmarshal([]byte(`["accept","attach-srv","capture","do-resolve","expect-netscaler-cip","expect-proxy","lua","reject","sc-add-gpc","sc-inc-gpc","sc-inc-gpc0","sc-inc-gpc1","sc-set-gpt","sc-set-gpt0","send-spoe-group","set-bandwidth-limit","set-dst-port","set-dst","set-log-level","set-mark","set-nice","set-priority-class","set-priority-offset","set-src","set-src-port","set-tos","set-var","set-var-fmt","silent-drop","switch-mode","track-sc0","track-sc1","track-sc2","track-sc","unset-var","use-service"]`), &res); err != nil { panic(err) } for _, v := range res { @@ -302,6 +293,9 @@ const ( // TCPRequestRuleActionScDashSetDashGpt0 captures enum value "sc-set-gpt0" TCPRequestRuleActionScDashSetDashGpt0 string = "sc-set-gpt0" + // TCPRequestRuleActionSendDashSpoeDashGroup captures enum value "send-spoe-group" + TCPRequestRuleActionSendDashSpoeDashGroup string = "send-spoe-group" + // TCPRequestRuleActionSetDashBandwidthDashLimit captures enum value "set-bandwidth-limit" TCPRequestRuleActionSetDashBandwidthDashLimit string = "set-bandwidth-limit" @@ -320,8 +314,11 @@ const ( // TCPRequestRuleActionSetDashNice captures enum value "set-nice" TCPRequestRuleActionSetDashNice string = "set-nice" - // TCPRequestRuleActionSetDashPriority captures enum value "set-priority" - TCPRequestRuleActionSetDashPriority string = "set-priority" + // TCPRequestRuleActionSetDashPriorityDashClass captures enum value "set-priority-class" + TCPRequestRuleActionSetDashPriorityDashClass string = "set-priority-class" + + // TCPRequestRuleActionSetDashPriorityDashOffset captures enum value "set-priority-offset" + TCPRequestRuleActionSetDashPriorityDashOffset string = "set-priority-offset" // TCPRequestRuleActionSetDashSrc captures enum value "set-src" TCPRequestRuleActionSetDashSrc string = "set-src" @@ -338,9 +335,6 @@ const ( // TCPRequestRuleActionSetDashVarDashFmt captures enum value "set-var-fmt" TCPRequestRuleActionSetDashVarDashFmt string = "set-var-fmt" - // TCPRequestRuleActionSendDashSpoeDashGroup captures enum value "send-spoe-group" - TCPRequestRuleActionSendDashSpoeDashGroup string = "send-spoe-group" - // TCPRequestRuleActionSilentDashDrop captures enum value "silent-drop" TCPRequestRuleActionSilentDashDrop string = "silent-drop" @@ -553,48 +547,6 @@ func (m *TCPRequestRule) validateNiceValue(formats strfmt.Registry) error { return nil } -var tcpRequestRuleTypePriorityTypePropEnum []interface{} - -func init() { - var res []string - if err := json.Unmarshal([]byte(`["class","offset"]`), &res); err != nil { - panic(err) - } - for _, v := range res { - tcpRequestRuleTypePriorityTypePropEnum = append(tcpRequestRuleTypePriorityTypePropEnum, v) - } -} - -const ( - - // TCPRequestRulePriorityTypeClass captures enum value "class" - TCPRequestRulePriorityTypeClass string = "class" - - // TCPRequestRulePriorityTypeOffset captures enum value "offset" - TCPRequestRulePriorityTypeOffset string = "offset" -) - -// prop value enum -func (m *TCPRequestRule) validatePriorityTypeEnum(path, location string, value string) error { - if err := validate.EnumCase(path, location, value, tcpRequestRuleTypePriorityTypePropEnum, true); err != nil { - return err - } - return nil -} - -func (m *TCPRequestRule) validatePriorityType(formats strfmt.Registry) error { - if swag.IsZero(m.PriorityType) { // not required - return nil - } - - // value enum - if err := m.validatePriorityTypeEnum("priority_type", "body", m.PriorityType); err != nil { - return err - } - - return nil -} - var tcpRequestRuleTypeResolveProtocolPropEnum []interface{} func init() { diff --git a/models/tcp_request_rule_compare.go b/models/tcp_request_rule_compare.go index 834505eb..b4a0980b 100644 --- a/models/tcp_request_rule_compare.go +++ b/models/tcp_request_rule_compare.go @@ -97,10 +97,6 @@ func (s TCPRequestRule) Equal(t TCPRequestRule, opts ...Options) bool { return false } - if s.PriorityType != t.PriorityType { - return false - } - if s.ResolveProtocol != t.ResolveProtocol { return false } @@ -265,10 +261,6 @@ func (s TCPRequestRule) Diff(t TCPRequestRule, opts ...Options) map[string][]int diff["NiceValue"] = []interface{}{s.NiceValue, t.NiceValue} } - if s.PriorityType != t.PriorityType { - diff["PriorityType"] = []interface{}{s.PriorityType, t.PriorityType} - } - if s.ResolveProtocol != t.ResolveProtocol { diff["ResolveProtocol"] = []interface{}{s.ResolveProtocol, t.ResolveProtocol} } diff --git a/models/tcp_request_rule_compare_test.go b/models/tcp_request_rule_compare_test.go index 03c5c0e3..c4b398ce 100644 --- a/models/tcp_request_rule_compare_test.go +++ b/models/tcp_request_rule_compare_test.go @@ -181,7 +181,7 @@ func TestTCPRequestRuleDiffFalse(t *testing.T) { for _, sample := range samples { result := sample.a.Diff(sample.b) - if len(result) != 37-1 { + if len(result) != 36-1 { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { @@ -191,7 +191,7 @@ func TestTCPRequestRuleDiffFalse(t *testing.T) { if err != nil { t.Errorf(err.Error()) } - t.Errorf("Expected TCPRequestRule to be different in 37 cases, but it is not (%d) %s %s", len(result), a, b) + t.Errorf("Expected TCPRequestRule to be different in 36 cases, but it is not (%d) %s %s", len(result), a, b) } } } diff --git a/models/tcp_response_rule.go b/models/tcp_response_rule.go index 62e8b16e..d534afb9 100644 --- a/models/tcp_response_rule.go +++ b/models/tcp_response_rule.go @@ -38,8 +38,8 @@ import ( // swagger:model tcp_response_rule type TCPResponseRule struct { // action - // Enum: [accept close lua reject sc-add-gpc sc-inc-gpc sc-inc-gpc0 sc-inc-gpc1 sc-set-gpt sc-set-gpt0 send-spoe-group set-bandwidth-limit set-log-level set-mark set-nice set-tos silent-drop unset-var] - // +kubebuilder:validation:Enum=accept;close;lua;reject;sc-add-gpc;sc-inc-gpc;sc-inc-gpc0;sc-inc-gpc1;sc-set-gpt;sc-set-gpt0;send-spoe-group;set-bandwidth-limit;set-log-level;set-mark;set-nice;set-tos;silent-drop;unset-var; + // Enum: [accept close lua reject sc-add-gpc sc-inc-gpc sc-inc-gpc0 sc-inc-gpc1 sc-set-gpt sc-set-gpt0 send-spoe-group set-bandwidth-limit set-log-level set-mark set-nice set-tos set-var set-var-fmt silent-drop unset-var] + // +kubebuilder:validation:Enum=accept;close;lua;reject;sc-add-gpc;sc-inc-gpc;sc-inc-gpc0;sc-inc-gpc1;sc-set-gpt;sc-set-gpt0;send-spoe-group;set-bandwidth-limit;set-log-level;set-mark;set-nice;set-tos;set-var;set-var-fmt;silent-drop;unset-var; Action string `json:"action,omitempty"` // bandwidth limit limit @@ -128,6 +128,9 @@ type TCPResponseRule struct { // +kubebuilder:validation:Enum=content;inspect-delay; Type string `json:"type"` + // var format + VarFormat string `json:"var_format,omitempty"` + // var name // Pattern: ^[^\s]+$ // +kubebuilder:validation:Pattern=`^[^\s]+$` @@ -205,7 +208,7 @@ var tcpResponseRuleTypeActionPropEnum []interface{} func init() { var res []string - if err := json.Unmarshal([]byte(`["accept","close","lua","reject","sc-add-gpc","sc-inc-gpc","sc-inc-gpc0","sc-inc-gpc1","sc-set-gpt","sc-set-gpt0","send-spoe-group","set-bandwidth-limit","set-log-level","set-mark","set-nice","set-tos","silent-drop","unset-var"]`), &res); err != nil { + if err := json.Unmarshal([]byte(`["accept","close","lua","reject","sc-add-gpc","sc-inc-gpc","sc-inc-gpc0","sc-inc-gpc1","sc-set-gpt","sc-set-gpt0","send-spoe-group","set-bandwidth-limit","set-log-level","set-mark","set-nice","set-tos","set-var","set-var-fmt","silent-drop","unset-var"]`), &res); err != nil { panic(err) } for _, v := range res { @@ -263,6 +266,12 @@ const ( // TCPResponseRuleActionSetDashTos captures enum value "set-tos" TCPResponseRuleActionSetDashTos string = "set-tos" + // TCPResponseRuleActionSetDashVar captures enum value "set-var" + TCPResponseRuleActionSetDashVar string = "set-var" + + // TCPResponseRuleActionSetDashVarDashFmt captures enum value "set-var-fmt" + TCPResponseRuleActionSetDashVarDashFmt string = "set-var-fmt" + // TCPResponseRuleActionSilentDashDrop captures enum value "silent-drop" TCPResponseRuleActionSilentDashDrop string = "silent-drop" diff --git a/models/tcp_response_rule_compare.go b/models/tcp_response_rule_compare.go index ff1e7a96..6a191d71 100644 --- a/models/tcp_response_rule_compare.go +++ b/models/tcp_response_rule_compare.go @@ -121,6 +121,10 @@ func (s TCPResponseRule) Equal(t TCPResponseRule, opts ...Options) bool { return false } + if s.VarFormat != t.VarFormat { + return false + } + if s.VarName != t.VarName { return false } @@ -237,6 +241,10 @@ func (s TCPResponseRule) Diff(t TCPResponseRule, opts ...Options) map[string][]i diff["Type"] = []interface{}{s.Type, t.Type} } + if s.VarFormat != t.VarFormat { + diff["VarFormat"] = []interface{}{s.VarFormat, t.VarFormat} + } + if s.VarName != t.VarName { diff["VarName"] = []interface{}{s.VarName, t.VarName} } diff --git a/models/tcp_response_rule_compare_test.go b/models/tcp_response_rule_compare_test.go index 8ae39544..68b71827 100644 --- a/models/tcp_response_rule_compare_test.go +++ b/models/tcp_response_rule_compare_test.go @@ -181,7 +181,7 @@ func TestTCPResponseRuleDiffFalse(t *testing.T) { for _, sample := range samples { result := sample.a.Diff(sample.b) - if len(result) != 24-1 { + if len(result) != 25-1 { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { @@ -191,7 +191,7 @@ func TestTCPResponseRuleDiffFalse(t *testing.T) { if err != nil { t.Errorf(err.Error()) } - t.Errorf("Expected TCPResponseRule to be different in 24 cases, but it is not (%d) %s %s", len(result), a, b) + t.Errorf("Expected TCPResponseRule to be different in 25 cases, but it is not (%d) %s %s", len(result), a, b) } } } diff --git a/specification/build/haproxy_spec.yaml b/specification/build/haproxy_spec.yaml index faa0a876..b078c7e8 100644 --- a/specification/build/haproxy_spec.yaml +++ b/specification/build/haproxy_spec.yaml @@ -5754,19 +5754,20 @@ definitions: - sc-inc-gpc1 - sc-set-gpt - sc-set-gpt0 + - send-spoe-group - set-bandwidth-limit - set-dst-port - set-dst - set-log-level - set-mark - set-nice - - set-priority + - set-priority-class + - set-priority-offset - set-src - set-src-port - set-tos - set-var - set-var-fmt - - send-spoe-group - silent-drop - switch-mode - track-sc0 @@ -5870,7 +5871,8 @@ definitions: - do-resolve - set-dst - set-dst-port - - set-priority + - set-priority-class + - set-priority-offset - set-src - set-src-port - set-var @@ -5960,18 +5962,6 @@ definitions: value: content x-display-name: Nice Value x-nullable: false - priority_type: - enum: - - class - - offset - type: string - x-dependency: - action: - required: true - value: set-priority - type: - value: - - content resolve_protocol: enum: - ipv4 @@ -6258,6 +6248,8 @@ definitions: - set-mark - set-nice - set-tos + - set-var + - set-var-fmt - silent-drop - unset-var type: string @@ -6474,6 +6466,15 @@ definitions: - inspect-delay type: string x-nullable: false + var_format: + type: string + x-dependency: + action: + required: true + value: set-var-fmt + type: + value: content + x-display-name: Var Format var_name: pattern: ^[^\s]+$ type: string diff --git a/specification/models/configuration/tcp/request.yaml b/specification/models/configuration/tcp/request.yaml index 99610630..59fc9334 100644 --- a/specification/models/configuration/tcp/request.yaml +++ b/specification/models/configuration/tcp/request.yaml @@ -31,19 +31,20 @@ tcp_request_rule: - sc-inc-gpc1 - sc-set-gpt - sc-set-gpt0 + - send-spoe-group - set-bandwidth-limit - set-dst-port - set-dst - set-log-level - set-mark - set-nice - - set-priority + - set-priority-class + - set-priority-offset - set-src - set-src-port - set-tos - set-var - set-var-fmt - - send-spoe-group - silent-drop - switch-mode - track-sc0 @@ -175,15 +176,6 @@ tcp_request_rule: type: value: [content] required: true - priority_type: - type: string - enum: [class, offset] - x-dependency: - action: - value: set-priority - required: true - type: - value: [content] var_name: type: string pattern: '^[^\s]+$' @@ -275,7 +267,8 @@ tcp_request_rule: - do-resolve - set-dst - set-dst-port - - set-priority + - set-priority-class + - set-priority-offset - set-src - set-src-port - set-var diff --git a/specification/models/configuration/tcp/response.yaml b/specification/models/configuration/tcp/response.yaml index 55d77e3f..4438a993 100644 --- a/specification/models/configuration/tcp/response.yaml +++ b/specification/models/configuration/tcp/response.yaml @@ -33,6 +33,8 @@ tcp_response_rule: - set-mark - set-nice - set-tos + - set-var + - set-var-fmt - silent-drop - unset-var x-nullable: false @@ -219,6 +221,15 @@ tcp_response_rule: value: unset-var type: value: content + var_format: + type: string + x-display-name: Var Format + x-dependency: + action: + value: set-var-fmt + required: true + type: + value: content cond: type: string x-display-name: Condition