Skip to content

Commit

Permalink
fix dumb bug (ip6tables command switch)
Browse files Browse the repository at this point in the history
  • Loading branch information
t4lz committed Dec 30, 2024
1 parent ead74cd commit 99561ce
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion mirrord/agent/src/steal/ip_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl IPTables for IPTablesWrapper {
}
}

#[tracing::instrument(level = "trace")]
#[tracing::instrument(level = "debug", skip(self), ret, fields(table_name=%self.table_name))] // TODO: change to trace.
fn create_chain(&self, name: &str) -> Result<()> {
self.tables
.new_chain(self.table_name, name)
Expand Down Expand Up @@ -281,6 +281,7 @@ where
_ => Redirects::Mesh(MeshRedirect::create(ipt.clone(), vendor, pod_ips)?),
}
} else {
tracing::debug!(ipv6 = ipv6, "creating standard redirect"); // TODO: change to trace.
match StandardRedirect::create(ipt.clone(), pod_ips, ipv6) {
Err(err) => {
warn!("Unable to create StandardRedirect chain: {err}");
Expand Down
1 change: 1 addition & 0 deletions mirrord/agent/src/steal/ip_tables/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl<IPT> StandardRedirect<IPT>
where
IPT: IPTables,
{
#[tracing::instrument(skip(ipt), level = tracing::Level::DEBUG)]
pub fn create(ipt: Arc<IPT>, pod_ips: Option<&str>, ipv6: bool) -> Result<Self> {
let prerouting = if ipv6 {
PreroutingRedirect::create_input(ipt.clone())?
Expand Down
12 changes: 9 additions & 3 deletions mirrord/agent/src/steal/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ pub(crate) struct IptablesListener {
#[async_trait::async_trait]
impl PortRedirector for IptablesListener {
type Error = AgentError;

#[tracing::instrument(skip(self), err, level=tracing::Level::DEBUG, fields(self.ipv6 = %self.ipv6))]
async fn add_redirection(&mut self, from: Port) -> Result<(), Self::Error> {
let iptables = if let Some(iptables) = self.iptables.as_ref() {
iptables
} else {
let safe = crate::steal::ip_tables::SafeIpTables::create(
if self.ipv6 {
new_iptables().into()
} else {
new_ip6tables_wrapper()
} else {
new_iptables().into()
},
self.flush_connections || self.ipv6,
self.flush_connections,
self.pod_ips.as_deref(),
self.ipv6,
)
Expand Down Expand Up @@ -169,6 +171,7 @@ impl IpTablesRedirector {
);
tracing::debug!("pod IPv4 addresses: {pod_ips4:?}, pod IPv6 addresses: {pod_ips6:?}");

tracing::debug!("Creating IPv4 iptables redirection listener");
let listener4 = TcpListener::bind((Ipv4Addr::UNSPECIFIED, 0)).await
.inspect_err(
|err| tracing::debug!(%err, "Could not bind IPv4, continuing with IPv6 only."),
Expand All @@ -191,6 +194,7 @@ impl IpTablesRedirector {
ipv6: false,
})
});
tracing::debug!("Creating IPv6 iptables redirection listener");
let listener6 = if support_ipv6 {
TcpListener::bind((Ipv6Addr::UNSPECIFIED, 0)).await
.inspect_err(
Expand Down Expand Up @@ -265,9 +269,11 @@ impl PortRedirector for IpTablesRedirector {
async fn add_redirection(&mut self, from: Port) -> Result<(), Self::Error> {
let (ipv4_listener, ipv6_listener) = self.get_listeners_mut();
if let Some(ip4_listener) = ipv4_listener {
tracing::debug!("Adding IPv4 redirection from port {from}");
ip4_listener.add_redirection(from).await?;
}
if let Some(ip6_listener) = ipv6_listener {
tracing::debug!("Adding IPv6 redirection from port {from}");
ip6_listener.add_redirection(from).await?;
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ pub async fn run_exec(
// base_env.insert("MIRRORD_AGENT_IMAGE", "test");
base_env.insert(
"MIRRORD_AGENT_IMAGE",
"docker.io/t4lz/mirrord-agent:2024-12-23",
"docker.io/t4lz/mirrord-agent:2024-12-27_4",
);
base_env.insert("MIRRORD_AGENT_TTL", "180"); // TODO: delete
base_env.insert("MIRRORD_CHECK_VERSION", "false");
Expand Down

0 comments on commit 99561ce

Please sign in to comment.