Skip to content

Commit

Permalink
BUG/MINOR: add missing rst-ttl option to relevant keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
amelhusic committed Sep 23, 2024
1 parent 2b1ad86 commit 21c538d
Show file tree
Hide file tree
Showing 10 changed files with 455 additions and 268 deletions.
23 changes: 20 additions & 3 deletions parsers/actions/silent-drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ limitations under the License.
package actions

import (
"fmt"
stderrors "errors"
"strconv"
"strings"

"github.com/haproxytech/config-parser/v5/common"
"github.com/haproxytech/config-parser/v5/errors"
"github.com/haproxytech/config-parser/v5/types"
)

type SilentDrop struct {
RstTTL int64
Cond string
CondTest string
Comment string
Expand All @@ -35,7 +38,7 @@ func (f *SilentDrop) Parse(parts []string, parserType types.ParserType, comment
f.Comment = comment
}
if len(parts) < 2 {
return fmt.Errorf("not enough params")
return stderrors.New("not enough params")
}
var command []string
switch parserType {
Expand All @@ -44,17 +47,31 @@ func (f *SilentDrop) Parse(parts []string, parserType types.ParserType, comment
case types.TCP:
command = parts[3:]
}
_, condition := common.SplitRequest(command)
command, condition := common.SplitRequest(command)
if len(condition) > 1 {
f.Cond = condition[0]
f.CondTest = strings.Join(condition[1:], " ")
}
if len(command) > 0 && command[0] == "rst-ttl" {
if len(command) <= 1 {
return stderrors.New("missing rst-ttl value")
}
rstTTL, err := strconv.ParseInt(command[1], 10, 64)
if err != nil {
return &errors.ParseError{Parser: "SilentDrop", Message: err.Error()}
}
f.RstTTL = rstTTL
}
return nil
}

func (f *SilentDrop) String() string {
var result strings.Builder
result.WriteString("silent-drop")
if f.RstTTL > 0 {
result.WriteString(" rst-ttl ")
result.WriteString(strconv.FormatInt(f.RstTTL, 10))
}
if f.Cond != "" {
result.WriteString(" ")
result.WriteString(f.Cond)
Expand Down
40 changes: 40 additions & 0 deletions tests/configs/haproxy_generated.cfg.go

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

Loading

0 comments on commit 21c538d

Please sign in to comment.