Commit 2b6021e4 authored by Carlos Neira's avatar Carlos Neira

added check for taken ip

parent 17fea9c9
...@@ -370,6 +370,14 @@ impl JailConfig { ...@@ -370,6 +370,14 @@ impl JailConfig {
"Invalid gateway", "Invalid gateway",
)) ))
} }
if checkip(nic.ip.as_str()) {
errors.push(ValidationError::new(
format!("nic[{}]", i).as_str(),
"ip address already taken",
))
}
if !MAC_RE.is_match(nic.mac.as_str()) { if !MAC_RE.is_match(nic.mac.as_str()) {
errors.push(ValidationError::new( errors.push(ValidationError::new(
format!("nic[{}]", i).as_str(), format!("nic[{}]", i).as_str(),
...@@ -489,3 +497,13 @@ fn new_mac() -> String { ...@@ -489,3 +497,13 @@ fn new_mac() -> String {
rng.gen::<u8>() rng.gen::<u8>()
) )
} }
fn checkip(ipaddr: &str) -> bool {
debug!("Checking if ip address {} is used up ",ipaddr);
let output = Command::new("ping")
.args(&["-o","-c 1",ipaddr])
.output()
.expect("failed to ping");
output.status.success()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment