Commit ea1aa3cd authored by Heinz N. Gies's avatar Heinz N. Gies

Merge branch 'test' into 'test'

added check for taken ip

See merge request !56
parents 17fea9c9 2b6021e4
Pipeline #14071484 canceled with stage
......@@ -370,6 +370,14 @@ impl JailConfig {
"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()) {
errors.push(ValidationError::new(
format!("nic[{}]", i).as_str(),
......@@ -489,3 +497,13 @@ fn new_mac() -> String {
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