Skip to content

Commit

Permalink
Be able to use other network device in iptables
Browse files Browse the repository at this point in the history
In `net/iptables`, it uses the network device `eth0` for network
operations. But the network device may be different on some machines. So
create a function to accept a network device parameter.
  • Loading branch information
wb14123 committed Oct 29, 2024
1 parent 0a73dfb commit 63735f0
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions jepsen/src/jepsen/net.clj
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@
(fast! [net test])
(shape! [net test nodes behavior])))

(def iptables
"Default iptables (assumes we control everything)."
(defn iptables-with-dev
"Default iptables (assumes we control everything). Take network device as parameter."
[dev]
(reify Net
(drop! [net test src dest]
(on-nodes test [dest]
Expand All @@ -185,32 +186,33 @@
(with-test-nodes test
(su
(exec :iptables :-F :-w)
(exec :iptables :-X :-w))))
; (exec :iptables :-X :-w)
)))

(slow! [net test]
(with-test-nodes test
(su (exec tc :qdisc :add :dev :eth0 :root :netem :delay :50ms
(su (exec tc :qdisc :add :dev dev :root :netem :delay :50ms
:10ms :distribution :normal))))

(slow! [net test {:keys [mean variance distribution]
:or {mean 50
variance 10
distribution :normal}}]
(with-test-nodes test
(su (exec tc :qdisc :add :dev :eth0 :root :netem :delay
(su (exec tc :qdisc :add :dev dev :root :netem :delay
(str mean "ms")
(str variance "ms")
:distribution distribution))))

(flaky! [net test]
(with-test-nodes test
(su (exec tc :qdisc :add :dev :eth0 :root :netem :loss "20%"
(su (exec tc :qdisc :add :dev dev :root :netem :loss "20%"
"75%"))))

(fast! [net test]
(with-test-nodes test
(try
(su (exec tc :qdisc :del :dev :eth0 :root))
(su (exec tc :qdisc :del :dev dev :root))
(catch RuntimeException e
(if (re-find #"Error: Cannot delete qdisc with handle of zero."
(.getMessage e))
Expand All @@ -232,6 +234,10 @@
(str/join ","))
:-j :DROP :-w))))))))

(def iptables
"Default iptables. Use eth0 as network device."
(iptables-with-dev :eth0))

(def ipfilter
"IPFilter rules"
(reify Net
Expand Down

0 comments on commit 63735f0

Please sign in to comment.