Navigation Menu

Skip to content

Commit

Permalink
Make sure passing no ips applies rules as a wildcard
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanhs committed Sep 16, 2017
1 parent 1d74635 commit 92d7d27
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions throttler/tc.go
Expand Up @@ -131,6 +131,15 @@ func addNetemRule(cfg *Config, c commander) error {

func addIptablesRules(cfg *Config, c commander) error {
var err error
if len(cfg.TargetIps) == 0 && len(cfg.TargetIps6) == 0 {
if err == nil {
err = addIptablesRulesForAddrs(cfg, c, ip4Tables, cfg.TargetIps)
}
if err == nil {
err = addIptablesRulesForAddrs(cfg, c, ip6Tables, cfg.TargetIps6)
}
return err
}
if err == nil && len(cfg.TargetIps) > 0 {
err = addIptablesRulesForAddrs(cfg, c, ip4Tables, cfg.TargetIps)
}
Expand Down
19 changes: 19 additions & 0 deletions throttler/tc_test.go
Expand Up @@ -84,6 +84,25 @@ func TestTcPacketLossSetup(t *testing.T) {
})
}

func TestTcWildcardIps(t *testing.T) {
r := newCmdRecorder()
th := &tcThrottler{r}
cfg := defaultTestConfig
cfg.TargetIps = []string{}
cfg.TargetPorts = []string{}
cfg.TargetProtos = []string{}
cfg.PacketLoss = -1
th.setup(&cfg)
r.verifyCommands(t, []string{
"sudo tc qdisc add dev eth0 handle 10: root htb default 1",
"sudo tc class add dev eth0 parent 10: classid 10:1 htb rate 20000kbit",
"sudo tc class add dev eth0 parent 10: classid 10:10 htb rate 1000000kbit",
"sudo tc qdisc add dev eth0 parent 10:10 handle 100: netem",
"sudo iptables -A POSTROUTING -t mangle -j CLASSIFY --set-class 10:10",
"sudo ip6tables -A POSTROUTING -t mangle -j CLASSIFY --set-class 10:10",
})
}

func TestTcMultiplePortsAndIps(t *testing.T) {
r := newCmdRecorder()
th := &tcThrottler{r}
Expand Down

0 comments on commit 92d7d27

Please sign in to comment.