aboutsummaryrefslogtreecommitdiff
path: root/middleware/erratic/setup.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2017-04-16 07:49:13 +0100
committerGravatar GitHub <noreply@github.com> 2017-04-16 07:49:13 +0100
commit73397e4667fbb070b29888900dc1c1d91a21fa51 (patch)
tree7d8be8a39394e7bdcec8e178a60660b8c4f76144 /middleware/erratic/setup.go
parenta83d97a5c446481da3b9efc8f017e6a6ea34b7b0 (diff)
downloadcoredns-73397e4667fbb070b29888900dc1c1d91a21fa51.tar.gz
coredns-73397e4667fbb070b29888900dc1c1d91a21fa51.tar.zst
coredns-73397e4667fbb070b29888900dc1c1d91a21fa51.zip
Tc bits (#617)
* middleware/erratic: allow TC bit to be set Add `truncate` as an option. Fixes #593
Diffstat (limited to 'middleware/erratic/setup.go')
-rw-r--r--middleware/erratic/setup.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/middleware/erratic/setup.go b/middleware/erratic/setup.go
index a642b6ff3..714fc309b 100644
--- a/middleware/erratic/setup.go
+++ b/middleware/erratic/setup.go
@@ -33,6 +33,8 @@ func setupErratic(c *caddy.Controller) error {
func parseErratic(c *caddy.Controller) (*Erratic, error) {
e := &Erratic{drop: 2}
+ drop := false // true if we've seen the drop keyword
+
for c.Next() { // 'erratic'
for c.NextBlock() {
switch c.Val() {
@@ -54,6 +56,7 @@ func parseErratic(c *caddy.Controller) (*Erratic, error) {
return nil, fmt.Errorf("illegal amount value given %q", args[0])
}
e.drop = uint64(amount)
+ drop = true
case "delay":
args := c.RemainingArgs()
if len(args) > 2 {
@@ -83,8 +86,30 @@ func parseErratic(c *caddy.Controller) (*Erratic, error) {
}
e.duration = duration
}
+ case "truncate":
+ args := c.RemainingArgs()
+ if len(args) > 1 {
+ return nil, c.ArgErr()
+ }
+
+ if len(args) == 0 {
+ continue
+ }
+
+ amount, err := strconv.ParseInt(args[0], 10, 32)
+ if err != nil {
+ return nil, err
+ }
+ if amount < 0 {
+ return nil, fmt.Errorf("illegal amount value given %q", args[0])
+ }
+ e.truncate = uint64(amount)
}
}
}
+ if (e.delay > 0 || e.truncate > 0) && !drop { // delay is set, but we've haven't seen a drop keyword, remove default drop stuff
+ e.drop = 0
+ }
+
return e, nil
}