Skip to content

Commit 21c538d

Browse files
committed
BUG/MINOR: add missing rst-ttl option to relevant keywords
1 parent 2b1ad86 commit 21c538d

10 files changed

+455
-268
lines changed

parsers/actions/silent-drop.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ limitations under the License.
1717
package actions
1818

1919
import (
20-
"fmt"
20+
stderrors "errors"
21+
"strconv"
2122
"strings"
2223

2324
"github.com/haproxytech/config-parser/v5/common"
25+
"github.com/haproxytech/config-parser/v5/errors"
2426
"github.com/haproxytech/config-parser/v5/types"
2527
)
2628

2729
type SilentDrop struct {
30+
RstTTL int64
2831
Cond string
2932
CondTest string
3033
Comment string
@@ -35,7 +38,7 @@ func (f *SilentDrop) Parse(parts []string, parserType types.ParserType, comment
3538
f.Comment = comment
3639
}
3740
if len(parts) < 2 {
38-
return fmt.Errorf("not enough params")
41+
return stderrors.New("not enough params")
3942
}
4043
var command []string
4144
switch parserType {
@@ -44,17 +47,31 @@ func (f *SilentDrop) Parse(parts []string, parserType types.ParserType, comment
4447
case types.TCP:
4548
command = parts[3:]
4649
}
47-
_, condition := common.SplitRequest(command)
50+
command, condition := common.SplitRequest(command)
4851
if len(condition) > 1 {
4952
f.Cond = condition[0]
5053
f.CondTest = strings.Join(condition[1:], " ")
5154
}
55+
if len(command) > 0 && command[0] == "rst-ttl" {
56+
if len(command) <= 1 {
57+
return stderrors.New("missing rst-ttl value")
58+
}
59+
rstTTL, err := strconv.ParseInt(command[1], 10, 64)
60+
if err != nil {
61+
return &errors.ParseError{Parser: "SilentDrop", Message: err.Error()}
62+
}
63+
f.RstTTL = rstTTL
64+
}
5265
return nil
5366
}
5467

5568
func (f *SilentDrop) String() string {
5669
var result strings.Builder
5770
result.WriteString("silent-drop")
71+
if f.RstTTL > 0 {
72+
result.WriteString(" rst-ttl ")
73+
result.WriteString(strconv.FormatInt(f.RstTTL, 10))
74+
}
5875
if f.Cond != "" {
5976
result.WriteString(" ")
6077
result.WriteString(f.Cond)

tests/configs/haproxy_generated.cfg.go

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)