@mark1russell7/harness 0.16.2 → 0.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/build/index.d.ts +4 -2
- package/build/index.js.map +1 -1
- package/image/native/src/bin/inject.rs +38 -11
- package/package.json +1 -1
|
@@ -22,9 +22,11 @@
|
|
|
22
22
|
//! retransmitting. By default it acts on TCP from the peer (`in`). `out` answers each packet that
|
|
23
23
|
//! goes to the peer, and `--protocol all` each protocol: at a router, as a host that is down
|
|
24
24
|
//! behind it.
|
|
25
|
-
//! - `mtu PEER --above N` / `clear-mtu PEER --above N`: each
|
|
26
|
-
//! bytes drops, as a path MTU black hole does, in the
|
|
27
|
-
//!
|
|
25
|
+
//! - `mtu PEER --above N [--protocol tcp|udp|icmp|all]` / `clear-mtu PEER --above N […]`: each
|
|
26
|
+
//! packet from the peer longer than N bytes drops, as a path MTU black hole does, in the
|
|
27
|
+
//! namespace that receives it. By default it acts on TCP. `--protocol all` drops each protocol,
|
|
28
|
+
//! as a real black hole does. Thus a path-MTU search with ping also sees it. It acts on segments
|
|
29
|
+
//! only when the sender's TSO and GSO and the receiver's GRO are off (`offload`).
|
|
28
30
|
//! - `fin-ack PEER` / `clear-fin-ack PEER`: the first ACK of each FIN that this end sends to the
|
|
29
31
|
//! peer drops. The FIN goes again when its retransmission timer fires, and the ACK of the second
|
|
30
32
|
//! FIN passes. Thus a connection that this end closes second stays in `LAST_ACK` until its timer
|
|
@@ -196,9 +198,10 @@ fn rules(action: &str, peer: Ipv4Addr, opts: &Options) -> Result<String, Box<dyn
|
|
|
196
198
|
None => (format!("INPUT -s {peer}/32"), format!("OUTPUT -d {peer}/32")),
|
|
197
199
|
Some(dev) => (format!("FORWARD -i {dev} -s {peer}/32"), format!("FORWARD -o {dev} -d {peer}/32")),
|
|
198
200
|
};
|
|
199
|
-
// a protocol limits only a black hole and
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
// a protocol limits only a black hole, a reject and an MTU drop: the other rules match TCP by
|
|
202
|
+
// their nature
|
|
203
|
+
if opts.protocol.is_some() && !matches!(action, "blackhole" | "clear" | "reject" | "clear-reject" | "mtu" | "clear-mtu") {
|
|
204
|
+
return Err(format!("--protocol acts on a blackhole, a reject or an mtu, not on {action}").into());
|
|
202
205
|
}
|
|
203
206
|
if opts.handshake.is_some() && !matches!(action, "rst" | "clear-rst") {
|
|
204
207
|
return Err(format!("--handshake acts on a rst, not on {action}").into());
|
|
@@ -239,12 +242,13 @@ fn rules(action: &str, peer: Ipv4Addr, opts: &Options) -> Result<String, Box<dyn
|
|
|
239
242
|
format!("{op} {to}{p} -j REJECT --reject-with {with}\n"),
|
|
240
243
|
)?
|
|
241
244
|
}
|
|
242
|
-
// the long
|
|
243
|
-
// fails its sends with EPERM, and it does not lose them on the way
|
|
245
|
+
// the long packets drop where they arrive. In the namespace of the sender, an OUTPUT drop
|
|
246
|
+
// fails its sends with EPERM, and it does not lose them on the way. By default, TCP only
|
|
244
247
|
"mtu" | "clear-mtu" => {
|
|
245
248
|
let op = op("mtu");
|
|
246
249
|
let above = opts.above.ok_or("--above N")?;
|
|
247
|
-
|
|
250
|
+
let p = protocol_match(opts.protocol.as_deref().unwrap_or("tcp"))?;
|
|
251
|
+
format!("{op} {from}{p} -m length --length {}:65535 -j DROP\n", above + 1)
|
|
248
252
|
}
|
|
249
253
|
// the mark of the connection counts the FINs that this end sent: 1 after the first FIN, 2
|
|
250
254
|
// after the second. A pure ACK from the peer drops at mark 1. Each -I goes to the top of
|
|
@@ -760,14 +764,37 @@ mod tests {
|
|
|
760
764
|
-D OUTPUT -d 10.0.0.2/32 -p udp -j REJECT --reject-with icmp-host-unreachable\n"
|
|
761
765
|
);
|
|
762
766
|
assert!(rules("reject", peer, &with(Some("up"), None)).is_err());
|
|
763
|
-
// a protocol is one of four words, and only a black hole
|
|
767
|
+
// a protocol is one of four words, and only a black hole, a reject or an MTU drop takes it
|
|
764
768
|
assert!(options(&["--protocol".into(), "sctp".into()]).is_err());
|
|
765
769
|
assert!(options(&["--protocol".into(), "tcp;x".into()]).is_err());
|
|
766
770
|
assert_eq!(options(&["--protocol".into(), "all".into()]).unwrap().protocol.as_deref(), Some("all"));
|
|
767
771
|
let tcp = Options { protocol: Some("tcp".into()), above: Some(1200), ..Options::default() };
|
|
768
|
-
for action in ["rst", "clear-rst", "
|
|
772
|
+
for action in ["rst", "clear-rst", "fin-ack"] {
|
|
769
773
|
assert!(rules(action, peer, &tcp).is_err(), "{action}");
|
|
770
774
|
}
|
|
775
|
+
assert!(rules("mtu", peer, &tcp).is_ok());
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
#[test]
|
|
779
|
+
fn an_mtu_drop_takes_a_protocol_and_its_lift_deletes_the_same_rule() {
|
|
780
|
+
let peer: Ipv4Addr = "10.0.0.2".parse().unwrap();
|
|
781
|
+
let with = |protocol: Option<&str>| Options { protocol: protocol.map(Into::into), above: Some(1200), ..Options::default() };
|
|
782
|
+
// the default keeps the rule from before the option: TCP only
|
|
783
|
+
assert_eq!(rules("mtu", peer, &with(None)).unwrap(), rules("mtu", peer, &with(Some("tcp"))).unwrap());
|
|
784
|
+
for (protocol, rule) in [
|
|
785
|
+
("tcp", "-I INPUT -s 10.0.0.2/32 -p tcp -m length --length 1201:65535 -j DROP\n"),
|
|
786
|
+
("udp", "-I INPUT -s 10.0.0.2/32 -p udp -m length --length 1201:65535 -j DROP\n"),
|
|
787
|
+
("icmp", "-I INPUT -s 10.0.0.2/32 -p icmp -m length --length 1201:65535 -j DROP\n"),
|
|
788
|
+
("all", "-I INPUT -s 10.0.0.2/32 -m length --length 1201:65535 -j DROP\n"),
|
|
789
|
+
] {
|
|
790
|
+
assert_eq!(rules("mtu", peer, &with(Some(protocol))).unwrap(), rule, "{protocol}");
|
|
791
|
+
assert_eq!(rules("clear-mtu", peer, &with(Some(protocol))).unwrap(), rule.replace("-I ", "-D "), "{protocol}");
|
|
792
|
+
}
|
|
793
|
+
let via = Options { protocol: Some("all".into()), above: Some(1200), via: Some("eth0".into()), ..Options::default() };
|
|
794
|
+
assert_eq!(
|
|
795
|
+
rules("mtu", peer, &via).unwrap(),
|
|
796
|
+
"-I FORWARD -i eth0 -s 10.0.0.2/32 -m length --length 1201:65535 -j DROP\n"
|
|
797
|
+
);
|
|
771
798
|
}
|
|
772
799
|
|
|
773
800
|
#[test]
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/harness",
|
|
4
|
-
"version": "0.16.
|
|
4
|
+
"version": "0.16.3",
|
|
5
5
|
"description": "Network labs in Docker, declared as data. A cell builds a topology of networks, routers and proxies around a stock target. It injects a fault at layer 3 or 4 from a NET_ADMIN sidecar, measures the records of the kernel and judges a prediction. The faults are black holes, resets, ICMP unreachable, one-way and MTU drops, tc netem, the toxics of Toxiproxy and frozen processes. Its replicated groups are Redis with Sentinels, MongoDB replica sets, PostgreSQL standbys, Kafka, RabbitMQ and BGP fabrics with BFD. A lab can also operate in a QEMU guest. Its first use is connection timers: keep-alive, TCP retransmission, heartbeats and reconnects.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"fault-injection",
|