@@ -17,14 +17,17 @@ limitations under the License.
17
17
package actions
18
18
19
19
import (
20
- "fmt"
20
+ stderrors "errors"
21
+ "strconv"
21
22
"strings"
22
23
23
24
"github.com/haproxytech/config-parser/v5/common"
25
+ "github.com/haproxytech/config-parser/v5/errors"
24
26
"github.com/haproxytech/config-parser/v5/types"
25
27
)
26
28
27
29
type SilentDrop struct {
30
+ RstTTL int64
28
31
Cond string
29
32
CondTest string
30
33
Comment string
@@ -35,7 +38,7 @@ func (f *SilentDrop) Parse(parts []string, parserType types.ParserType, comment
35
38
f .Comment = comment
36
39
}
37
40
if len (parts ) < 2 {
38
- return fmt . Errorf ("not enough params" )
41
+ return stderrors . New ("not enough params" )
39
42
}
40
43
var command []string
41
44
switch parserType {
@@ -44,17 +47,31 @@ func (f *SilentDrop) Parse(parts []string, parserType types.ParserType, comment
44
47
case types .TCP :
45
48
command = parts [3 :]
46
49
}
47
- _ , condition := common .SplitRequest (command )
50
+ command , condition := common .SplitRequest (command )
48
51
if len (condition ) > 1 {
49
52
f .Cond = condition [0 ]
50
53
f .CondTest = strings .Join (condition [1 :], " " )
51
54
}
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
+ }
52
65
return nil
53
66
}
54
67
55
68
func (f * SilentDrop ) String () string {
56
69
var result strings.Builder
57
70
result .WriteString ("silent-drop" )
71
+ if f .RstTTL > 0 {
72
+ result .WriteString (" rst-ttl " )
73
+ result .WriteString (strconv .FormatInt (f .RstTTL , 10 ))
74
+ }
58
75
if f .Cond != "" {
59
76
result .WriteString (" " )
60
77
result .WriteString (f .Cond )
0 commit comments