Skip to content

Commit 08bb16a

Browse files
authored
Merge pull request #132 from cgwalters/sysctl-asref
Use `AsRef<str>` for sysctl bits
2 parents 0296f0e + c7a7aff commit 08bb16a

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/firewall/iptables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl firewall::FirewallDriver for IptablesDriver {
106106
None => {}
107107
Some(i) => {
108108
let localnet_path = format!("net.ipv4.conf.{}.route_localnet", i);
109-
CoreUtils::apply_sysctl_value(localnet_path.as_str(), "1")?;
109+
CoreUtils::apply_sysctl_value(localnet_path, "1")?;
110110
}
111111
}
112112
// let container_network_address = setup_portfw.network_address.subnet;

src/network/core_utils.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,8 @@ impl CoreUtils {
866866
}
867867
if ipv6_enabled {
868868
// Do not accept Router Advertisements if ipv6 is enabled
869-
let k = format!("net/ipv6/conf/{}/accept_ra", ifname);
870-
match CoreUtils::apply_sysctl_value(&k, "0") {
869+
match CoreUtils::apply_sysctl_value(format!("net/ipv6/conf/{}/accept_ra", ifname), "0")
870+
{
871871
Ok(_) => {}
872872
Err(err) => {
873873
return Err(std::io::Error::new(
@@ -1265,8 +1265,13 @@ impl CoreUtils {
12651265
ctl.value_string()
12661266
}
12671267

1268-
// set a sysctl value by value's namespace
1269-
pub fn apply_sysctl_value(ns_value: &str, val: &str) -> Result<String, SysctlError> {
1268+
/// Set a sysctl value by value's namespace.
1269+
pub fn apply_sysctl_value(
1270+
ns_value: impl AsRef<str>,
1271+
val: impl AsRef<str>,
1272+
) -> Result<String, SysctlError> {
1273+
let ns_value = ns_value.as_ref();
1274+
let val = val.as_ref();
12701275
debug!("Setting sysctl value for {} to {}", ns_value, val);
12711276
let ctl = sysctl::Ctl::new(ns_value)?;
12721277
ctl.set_value_string(val)

0 commit comments

Comments
 (0)