@@ -17,14 +17,17 @@ limitations under the License.
1717package actions
1818
1919import (
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
2729type 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
5568func (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 )
0 commit comments