Skip to content

Commit

Permalink
Merge pull request #471 from Luap99/ipv6-error
Browse files Browse the repository at this point in the history
netlink: return better error if ipv6 is disabled
  • Loading branch information
openshift-merge-robot authored Oct 27, 2022
2 parents fba6bf6 + 72c42b6 commit 279be6e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/network/netlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,25 @@ impl Socket {

pub fn add_addr(&mut self, link_id: u32, addr: &ipnet::IpNet) -> NetavarkResult<()> {
let msg = Self::create_addr_msg(link_id, addr);
let result = self.make_netlink_request(
let result = match self.make_netlink_request(
RtnlMessage::NewAddress(msg),
NLM_F_ACK | NLM_F_EXCL | NLM_F_CREATE,
)?;
) {
Ok(result) => result,
Err(err) => match err {
// kernel returns EACCES when we try to add an ipv6 but ipv6 is disabled in the kernel
NetavarkError::Netlink(ref e) if -e.code == libc::EACCES => match addr {
ipnet::IpNet::V6(_) => {
return Err(NetavarkError::wrap(
"failed to add ipv6 address, is ipv6 enabled in the kernel?",
err,
));
}
_ => return Err(err),
},
err => return Err(err),
},
};
expect_netlink_result!(result, 0);

Ok(())
Expand Down
8 changes: 8 additions & 0 deletions test/100-bridge-iptables.bats
Original file line number Diff line number Diff line change
Expand Up @@ -629,3 +629,11 @@ EOF
assert "$output" !~ "10.89.1.0/24" "eth0 subnet should not exist"
assert "$output" !~ "10.89.2.0/24" "eth1 subnet should not exist"
}

@test "$fw_driver - ipv6 disabled error message" {
# disable ipv6 in the netns
run_in_host_netns sysctl net.ipv6.conf.all.disable_ipv6=1

expected_rc=1 run_netavark --file ${TESTSDIR}/testfiles/ipv6-bridge.json setup $(get_container_netns_path)
assert '{"error":"add ip addr to bridge: failed to add ipv6 address, is ipv6 enabled in the kernel?: Netlink error: Permission denied (os error 13)"}' "error message"
}

0 comments on commit 279be6e

Please sign in to comment.