mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
Tc bits (#617)
* middleware/erratic: allow TC bit to be set Add `truncate` as an option. Fixes #593
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user