From af2ef3f7a5e55c121fb7362ed410506089dee6ab Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Tue, 10 May 2022 14:59:22 -0700 Subject: [PATCH] agent-ctl: introduce handle for iptables get/set Add support for the updated agent API for iptables Signed-off-by: Eric Ernst --- src/tools/agent-ctl/src/client.rs | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/tools/agent-ctl/src/client.rs b/src/tools/agent-ctl/src/client.rs index bcaa878440..315969b87b 100644 --- a/src/tools/agent-ctl/src/client.rs +++ b/src/tools/agent-ctl/src/client.rs @@ -161,6 +161,11 @@ static AGENT_CMDS: &[AgentCmd] = &[ st: ServiceType::Agent, fp: agent_cmd_sandbox_get_guest_details, }, + AgentCmd { + name: "GetIptables", + st: ServiceType::Agent, + fp: agent_cmd_sandbox_get_ip_tables, + }, AgentCmd { name: "GetMetrics", st: ServiceType::Agent, @@ -231,6 +236,11 @@ static AGENT_CMDS: &[AgentCmd] = &[ st: ServiceType::Agent, fp: agent_cmd_sandbox_set_guest_date_time, }, + AgentCmd { + name: "SetIptables", + st: ServiceType::Agent, + fp: agent_cmd_sandbox_set_ip_tables, + }, AgentCmd { name: "SignalProcess", st: ServiceType::Agent, @@ -1219,6 +1229,29 @@ fn agent_cmd_sandbox_get_guest_details( Ok(()) } +fn agent_cmd_sandbox_get_ip_tables( + ctx: &Context, + client: &AgentServiceClient, + _health: &HealthClient, + _options: &mut Options, + args: &str, +) -> Result<()> { + let req: GetIPTablesRequest = utils::make_request(args)?; + + let ctx = clone_context(ctx); + + debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); + + let reply = client + .get_ip_tables(ctx, &req) + .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; + + info!(sl!(), "response received"; + "response" => format!("{:?}", reply)); + + Ok(()) +} + fn agent_cmd_container_wait_process( ctx: &Context, client: &AgentServiceClient, @@ -1899,6 +1932,29 @@ fn agent_cmd_sandbox_set_guest_date_time( Ok(()) } +fn agent_cmd_sandbox_set_ip_tables( + ctx: &Context, + client: &AgentServiceClient, + _health: &HealthClient, + _options: &mut Options, + args: &str, +) -> Result<()> { + let req: SetIPTablesRequest = utils::make_request(args)?; + + let ctx = clone_context(ctx); + + debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); + + let reply = client + .set_ip_tables(ctx, &req) + .map_err(|e| anyhow!(e).context(ERR_API_FAILED))?; + + info!(sl!(), "response received"; + "response" => format!("{:?}", reply)); + + Ok(()) +} + fn agent_cmd_sandbox_add_arp_neighbors( ctx: &Context, client: &AgentServiceClient,