Skip to content

Commit

Permalink
fix new rust 1.82 lint errors
Browse files Browse the repository at this point in the history
Also do not specify the crate version in the Makefile, we do not need
this.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
  • Loading branch information
Luap99 committed Nov 19, 2024
1 parent 8892b7f commit 55a0f25
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 126 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ integration: $(CARGO_TARGET_DIR) examples
.PHONY: validate
validate: $(CARGO_TARGET_DIR)
$(CARGO) fmt --all -- --check
$(CARGO) clippy -p netavark@$(CRATE_VERSION) -- -D warnings
$(CARGO) clippy -p netavark -- -D warnings
$(MAKE) docs

.PHONY: vendor-tarball
Expand Down
10 changes: 5 additions & 5 deletions src/dhcp_proxy/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ mod cache_tests {
let deserialized_lease = s
.get(macaddr)
.expect("Could not get the mac address from the map")
.get(0)
.first()
.expect("Could not get lease from set of mac addresses")
.clone();
// Assure that the amount of leases added is correct amount
Expand Down Expand Up @@ -331,7 +331,7 @@ mod cache_tests {
let deserialized_lease = s
.get(macaddr)
.expect("Could not get the mac address from the map")
.get(0)
.first()
.expect("Could not get lease from set of mac addresses")
.clone();
// Assure that the amount of leases added is correct amount
Expand All @@ -354,7 +354,7 @@ mod cache_tests {
let deserialized_lease = s
.get(macaddr)
.expect("Could not get the mac address from the map")
.get(0)
.first()
.expect("Could not get lease from set of mac addresses")
.clone();

Expand Down Expand Up @@ -418,7 +418,7 @@ mod cache_tests {
let deserialized_lease = s
.get(macaddr)
.expect("Could not get the mac address from the map")
.get(0)
.first()
.expect("Could not get lease from set of mac addresses")
.clone();
// Assure that the amount of leases added is correct amount
Expand Down Expand Up @@ -450,7 +450,7 @@ mod cache_tests {
let deserialized_updated_lease = s
.get(macaddr)
.expect("Could not get lease from deserialized map")
.get(0)
.first()
.expect("Could not find lease in set of multi-homing leases");

assert_eq!(deserialized_updated_lease, &new_lease);
Expand Down
27 changes: 12 additions & 15 deletions src/firewall/firewalld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,22 @@ impl firewall::FirewallDriver for FirewallD {
// prevention - if two ports end up mapped to different containers,
// that is not detected, and firewalld will allow it to happen.
// Only one of them will win and be active, though.
match setup_portfw.port_mappings {
Some(ports) => {
for port in ports {
if !port.host_ip.is_empty() {
if let Some(ports) = setup_portfw.port_mappings {
for port in ports {
if !port.host_ip.is_empty() {
port_forwarding_rules
.append(Value::new(make_port_tuple(port, &port.host_ip)))?;
} else {
if let Some(v4) = setup_portfw.container_ip_v4 {
port_forwarding_rules
.append(Value::new(make_port_tuple(port, &port.host_ip)))?;
} else {
if let Some(v4) = setup_portfw.container_ip_v4 {
port_forwarding_rules
.append(Value::new(make_port_tuple(port, &v4.to_string())))?;
}
if let Some(v6) = setup_portfw.container_ip_v6 {
port_forwarding_rules
.append(Value::new(make_port_tuple(port, &v6.to_string())))?;
}
.append(Value::new(make_port_tuple(port, &v4.to_string())))?;
}
if let Some(v6) = setup_portfw.container_ip_v6 {
port_forwarding_rules
.append(Value::new(make_port_tuple(port, &v6.to_string())))?;
}
}
}
None => {}
};

// dns port forwarding requires rich rules as we also want to match destination ip
Expand Down
11 changes: 3 additions & 8 deletions src/firewall/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,9 @@ mod tests {
let res = remove_fw_config(config_dir, network_id, container_id, true);
assert!(res.is_ok(), "remove_fw_config failed");

assert_eq!(
paths.net_conf_file.exists(),
false,
"net conf should not exists"
);
assert_eq!(
paths.port_conf_file.exists(),
false,
assert!(!paths.net_conf_file.exists(), "net conf should not exists");
assert!(
!paths.port_conf_file.exists(),
"port conf should not exists"
);

Expand Down
181 changes: 89 additions & 92 deletions src/firewall/varktables/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,110 +538,107 @@ pub fn get_port_forwarding_chains<'a>(
}
}

match pfwd.port_mappings {
Some(ports) => {
for i in ports {
let host_ip = if i.host_ip.is_empty() {
None
} else {
match i.host_ip.parse() {
Ok(ip) => match ip {
IpAddr::V4(v4) => {
if is_ipv6 {
continue;
}
if !v4.is_unspecified() {
Some(IpAddr::V4(v4))
} else {
None
}
if let Some(ports) = pfwd.port_mappings {
for i in ports {
let host_ip = if i.host_ip.is_empty() {
None
} else {
match i.host_ip.parse() {
Ok(ip) => match ip {
IpAddr::V4(v4) => {
if is_ipv6 {
continue;
}
IpAddr::V6(v6) => {
if !is_ipv6 {
continue;
}
if !v6.is_unspecified() {
Some(IpAddr::V6(v6))
} else {
None
}
if !v4.is_unspecified() {
Some(IpAddr::V4(v4))
} else {
None
}
},
Err(_) => {
return Err(NetavarkError::msg(format!(
"invalid host ip \"{}\" provided for port {}",
i.host_ip, i.host_port,
)));
}
IpAddr::V6(v6) => {
if !is_ipv6 {
continue;
}
if !v6.is_unspecified() {
Some(IpAddr::V6(v6))
} else {
None
}
}
},
Err(_) => {
return Err(NetavarkError::msg(format!(
"invalid host ip \"{}\" provided for port {}",
i.host_ip, i.host_port,
)));
}
};

// hostport dnat
let is_range = i.range > 1;
let mut host_port = i.host_port.to_string();
if is_range {
host_port = format!("{}:{}", i.host_port, (i.host_port + (i.range - 1)))
}
netavark_hostport_dn_chain.build_rule(VarkRule::new(
format!(
// I'm leaving this commented code for now in the case
// we need to revert.
// "-j {} -p {} -m multiport --destination-ports {} {}",
"-j {} -p {} --dport {} {}",
network_dn_chain_name, i.protocol, &host_port, comment_dn_network_cid
),
None,
));

let mut dn_setmark_rule_localhost = format!(
"-j {} -s {} -p {} --dport {}",
NETAVARK_HOSTPORT_SETMARK, network_address, i.protocol, &host_port
);

let mut dn_setmark_rule_subnet = format!(
"-j {} -s {} -p {} --dport {}",
NETAVARK_HOSTPORT_SETMARK, localhost_ip, i.protocol, &host_port
);
};

// if a destination ip address is provided, we need to alter
// the rule a bit
if let Some(host_ip) = host_ip {
dn_setmark_rule_localhost = format!("{dn_setmark_rule_localhost} -d {host_ip}");
dn_setmark_rule_subnet = format!("{dn_setmark_rule_subnet} -d {host_ip}");
}
// hostport dnat
let is_range = i.range > 1;
let mut host_port = i.host_port.to_string();
if is_range {
host_port = format!("{}:{}", i.host_port, (i.host_port + (i.range - 1)))
}
netavark_hostport_dn_chain.build_rule(VarkRule::new(
format!(
// I'm leaving this commented code for now in the case
// we need to revert.
// "-j {} -p {} -m multiport --destination-ports {} {}",
"-j {} -p {} --dport {} {}",
network_dn_chain_name, i.protocol, &host_port, comment_dn_network_cid
),
None,
));

let mut dn_setmark_rule_localhost = format!(
"-j {} -s {} -p {} --dport {}",
NETAVARK_HOSTPORT_SETMARK, network_address, i.protocol, &host_port
);

let mut dn_setmark_rule_subnet = format!(
"-j {} -s {} -p {} --dport {}",
NETAVARK_HOSTPORT_SETMARK, localhost_ip, i.protocol, &host_port
);

// if a destination ip address is provided, we need to alter
// the rule a bit
if let Some(host_ip) = host_ip {
dn_setmark_rule_localhost = format!("{dn_setmark_rule_localhost} -d {host_ip}");
dn_setmark_rule_subnet = format!("{dn_setmark_rule_subnet} -d {host_ip}");
}

// dn container (the actual port usages)
netavark_hashed_dn_chain.build_rule(VarkRule::new(dn_setmark_rule_localhost, None));
// dn container (the actual port usages)
netavark_hashed_dn_chain.build_rule(VarkRule::new(dn_setmark_rule_localhost, None));

netavark_hashed_dn_chain.build_rule(VarkRule::new(dn_setmark_rule_subnet, None));
netavark_hashed_dn_chain.build_rule(VarkRule::new(dn_setmark_rule_subnet, None));

let mut container_ip_value = container_ip.to_string();
if is_ipv6 {
container_ip_value = format!("[{container_ip_value}]")
}
let mut container_port = i.container_port.to_string();
if is_range {
container_port = format!(
"{}-{}/{}",
i.container_port,
(i.container_port + (i.range - 1)),
i.host_port
);
}
let mut dnat_rule = format!(
"-j {} -p {} --to-destination {}:{} --destination-port {}",
DNAT, i.protocol, container_ip_value, container_port, &host_port
let mut container_ip_value = container_ip.to_string();
if is_ipv6 {
container_ip_value = format!("[{container_ip_value}]")
}
let mut container_port = i.container_port.to_string();
if is_range {
container_port = format!(
"{}-{}/{}",
i.container_port,
(i.container_port + (i.range - 1)),
i.host_port
);

// if a destination ip address is provided, we need to alter
// the rule a bit
if let Some(host_ip) = host_ip {
dnat_rule = format!("{dnat_rule} -d {host_ip}")
}
netavark_hashed_dn_chain.build_rule(VarkRule::new(dnat_rule, None));
}
let mut dnat_rule = format!(
"-j {} -p {} --to-destination {}:{} --destination-port {}",
DNAT, i.protocol, container_ip_value, container_port, &host_port
);

// if a destination ip address is provided, we need to alter
// the rule a bit
if let Some(host_ip) = host_ip {
dnat_rule = format!("{dnat_rule} -d {host_ip}")
}
netavark_hashed_dn_chain.build_rule(VarkRule::new(dnat_rule, None));
}
None => {}
};

// The order is important here. Be certain before changing it
Expand Down
7 changes: 2 additions & 5 deletions src/network/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,8 @@ impl driver::NetworkDriver for Bridge<'_> {
}
}
let mut names = vec![self.info.container_name.to_string()];
match &self.info.per_network_opts.aliases {
Some(n) => {
names.extend(n.clone());
}
None => {}
if let Some(n) = &self.info.per_network_opts.aliases {
names.extend(n.clone());
}

let gw = data
Expand Down

0 comments on commit 55a0f25

Please sign in to comment.