egress-pin: say a vb- veth on the bridge that has no link_index
parse_ports drops a bridge port whose listing has no numeric link_index without a line, and the unenslaved check cannot see it because it is on the bridge. A sweep now names such a veth after the usual 60 s grace, keyed by its ifindex so a restart is a new finding. Diagnostics only: no binding changes. Refs #6646
This commit is contained in:
parent
1a31a4cd5a
commit
9237948c2c
2 changed files with 94 additions and 2 deletions
|
|
@ -1026,18 +1026,25 @@ fn report(resolution: &Resolution, which: Report<'_>) {
|
|||
/// nothing, and a failure here is a warning: the pass has already bound what it
|
||||
/// could.
|
||||
fn diagnose(bridge: &str, survey: &Survey) {
|
||||
let unenslaved = output_of("ip", &["-j", "link", "show", "type", "veth"])
|
||||
.and_then(|json| egress_diag::parse_unenslaved(&json, bridge))
|
||||
let listing = output_of("ip", &["-j", "link", "show", "type", "veth"]);
|
||||
let unenslaved = listing
|
||||
.as_ref()
|
||||
.map_err(|e| anyhow::anyhow!("{e:#}"))
|
||||
.and_then(|json| egress_diag::parse_unenslaved(json, bridge))
|
||||
.unwrap_or_else(|e| {
|
||||
eprintln!("{PIN}: list the veths: {e:#}");
|
||||
Vec::new()
|
||||
});
|
||||
let peerless = listing
|
||||
.and_then(|json| egress_diag::parse_peerless(&json, bridge))
|
||||
.unwrap_or_default();
|
||||
let findings = egress_diag::findings(&egress_diag::Pass {
|
||||
bridge,
|
||||
ports: &survey.ports,
|
||||
unbound: &survey.resolution.unbound,
|
||||
machines: &survey.machines,
|
||||
unenslaved: &unenslaved,
|
||||
peerless: &peerless,
|
||||
});
|
||||
egress_diag::say(&findings, &format!("{}.diag", state_path()), now_secs());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
//!
|
||||
//! - a port that stays unbound, with the links it was matched against;
|
||||
//! - a `vb-` veth that is not on the bridge, which no pass can see;
|
||||
//! - a `vb-` veth on the bridge with no usable `link_index`, which the port
|
||||
//! listing drops, so no pass can see it either;
|
||||
//! - a registered machine the pass could not read, with the reason.
|
||||
//!
|
||||
//! A port is unbound for a moment at every container start, so a finding is
|
||||
|
|
@ -60,6 +62,40 @@ pub(crate) fn parse_unenslaved(json: &str, bridge: &str) -> Result<Vec<Unenslave
|
|||
.collect())
|
||||
}
|
||||
|
||||
/// A `vb-` veth on the bridge whose `link_index`, the index of its peer, the
|
||||
/// listing lacks or gives as something other than a number. A port like that
|
||||
/// is not read as a bridge port, so no pass binds it.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub(crate) struct Peerless {
|
||||
name: String,
|
||||
ifindex: Option<u64>,
|
||||
}
|
||||
|
||||
/// The `vb-` veths of an `ip -j link show type veth` listing that are on
|
||||
/// `bridge` and have no usable `link_index`.
|
||||
pub(crate) fn parse_peerless(json: &str, bridge: &str) -> Result<Vec<Peerless>> {
|
||||
let value: serde_json::Value = serde_json::from_str(json).context("parse ip -j link")?;
|
||||
let Some(items) = value.as_array() else {
|
||||
bail!("ip -j link did not print a list");
|
||||
};
|
||||
Ok(items
|
||||
.iter()
|
||||
.filter_map(|item| {
|
||||
let name = item.get("ifname")?.as_str()?;
|
||||
let on_bridge = item.get("master").and_then(serde_json::Value::as_str) == Some(bridge);
|
||||
let has_peer = item
|
||||
.get("link_index")
|
||||
.is_some_and(serde_json::Value::is_u64);
|
||||
(name.starts_with(VETH_PREFIX) && is_plain_name(name) && on_bridge && !has_peer).then(
|
||||
|| Peerless {
|
||||
name: name.to_string(),
|
||||
ifindex: item.get("ifindex").and_then(serde_json::Value::as_u64),
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// What a sweep looked at.
|
||||
pub(crate) struct Pass<'a> {
|
||||
pub(crate) bridge: &'a str,
|
||||
|
|
@ -68,6 +104,7 @@ pub(crate) struct Pass<'a> {
|
|||
pub(crate) unbound: &'a [(String, String)],
|
||||
pub(crate) machines: &'a Machines,
|
||||
pub(crate) unenslaved: &'a [Unenslaved],
|
||||
pub(crate) peerless: &'a [Peerless],
|
||||
}
|
||||
|
||||
/// One thing a sweep can say.
|
||||
|
|
@ -149,6 +186,13 @@ pub(crate) fn findings(pass: &Pass<'_>) -> Vec<Finding> {
|
|||
line,
|
||||
});
|
||||
}
|
||||
for veth in pass.peerless {
|
||||
let ifindex = veth.ifindex.map_or("-".to_string(), |i| i.to_string());
|
||||
found.push(Finding {
|
||||
key: format!("peerless {} {ifindex}", veth.name),
|
||||
line: format!("{} is on {} but has no link_index", veth.name, pass.bridge),
|
||||
});
|
||||
}
|
||||
found
|
||||
}
|
||||
|
||||
|
|
@ -279,6 +323,7 @@ mod tests {
|
|||
unbound: &unbound,
|
||||
machines: &machines,
|
||||
unenslaved: &[],
|
||||
peerless: &[],
|
||||
});
|
||||
assert_eq!(
|
||||
lines(&found),
|
||||
|
|
@ -298,6 +343,7 @@ mod tests {
|
|||
unbound: &unbound,
|
||||
machines: &Machines::default(),
|
||||
unenslaved: &[],
|
||||
peerless: &[],
|
||||
});
|
||||
assert_eq!(
|
||||
lines(&found),
|
||||
|
|
@ -322,6 +368,7 @@ mod tests {
|
|||
unbound: &unbound,
|
||||
machines: &machines,
|
||||
unenslaved: &[],
|
||||
peerless: &[],
|
||||
});
|
||||
assert_eq!(
|
||||
lines(&found),
|
||||
|
|
@ -353,6 +400,7 @@ mod tests {
|
|||
unbound: &[],
|
||||
machines: &machines,
|
||||
unenslaved: &[],
|
||||
peerless: &[],
|
||||
});
|
||||
assert_eq!(
|
||||
lines(&found),
|
||||
|
|
@ -384,6 +432,7 @@ mod tests {
|
|||
unbound: &[],
|
||||
machines: &Machines::default(),
|
||||
unenslaved: &off,
|
||||
peerless: &[],
|
||||
});
|
||||
assert_eq!(
|
||||
lines(&found),
|
||||
|
|
@ -393,6 +442,42 @@ mod tests {
|
|||
assert!(parse_unenslaved("{}", "hive-br0").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_bridge_port_with_no_peer_index_is_named_and_keyed_by_its_ifindex() {
|
||||
let listing = r#"[
|
||||
{"ifindex":10,"ifname":"vb-a","master":"hive-br0","link_index":2},
|
||||
{"ifindex":11,"ifname":"vb-b","master":"hive-br0"},
|
||||
{"ifindex":12,"ifname":"vb-c","master":"hive-br0","link_index":"x"},
|
||||
{"ifindex":13,"ifname":"vb-d","master":"virbr0"},
|
||||
{"ifindex":14,"ifname":"vb-e"},
|
||||
{"ifindex":15,"ifname":"ve-f","master":"hive-br0"},
|
||||
{"ifindex":16,"ifname":"vb-g\"x","master":"hive-br0"},
|
||||
{"ifname":"vb-h","master":"hive-br0"}
|
||||
]"#;
|
||||
let none = parse_peerless(listing, "hive-br0").unwrap();
|
||||
let found = findings(&Pass {
|
||||
bridge: "hive-br0",
|
||||
ports: &[],
|
||||
unbound: &[],
|
||||
machines: &Machines::default(),
|
||||
unenslaved: &[],
|
||||
peerless: &none,
|
||||
});
|
||||
assert_eq!(
|
||||
lines(&found),
|
||||
[
|
||||
"vb-b is on hive-br0 but has no link_index",
|
||||
"vb-c is on hive-br0 but has no link_index",
|
||||
"vb-h is on hive-br0 but has no link_index"
|
||||
]
|
||||
);
|
||||
// A restart gives the port a new ifindex, so the new port is a new
|
||||
// finding that is said again.
|
||||
assert_eq!(found[0].key, "peerless vb-b 11");
|
||||
assert_eq!(found[2].key, "peerless vb-h -");
|
||||
assert!(parse_peerless("{}", "hive-br0").is_err());
|
||||
}
|
||||
|
||||
fn finding(key: &str) -> Finding {
|
||||
Finding {
|
||||
key: key.into(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue