netcfg adds/set method
This commit is contained in:
@@ -67,10 +67,8 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe
|
|||||||
if let Some(ip) = *cur_value {
|
if let Some(ip) = *cur_value {
|
||||||
dns_config.borrow_mut().name_server = ip;
|
dns_config.borrow_mut().name_server = ip;
|
||||||
notifier.borrow_mut().schedule_notify("resolv/nameserver");
|
notifier.borrow_mut().schedule_notify("resolv/nameserver");
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(SyscallError::new(syscall::EINVAL))
|
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -161,15 +159,14 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe
|
|||||||
if let Some(mac) = *cur_value {
|
if let Some(mac) = *cur_value {
|
||||||
iface.borrow_mut().set_ethernet_addr(mac);
|
iface.borrow_mut().set_ethernet_addr(mac);
|
||||||
notifier.borrow_mut().schedule_notify("ifaces/eth0/mac");
|
notifier.borrow_mut().schedule_notify("ifaces/eth0/mac");
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(SyscallError::new(syscall::EINVAL))
|
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"addr" => {
|
"addr" => {
|
||||||
"list" => {
|
"list" => {
|
||||||
ro [iface] || {
|
ro [iface]
|
||||||
|
|| {
|
||||||
let mut ips = String::new();
|
let mut ips = String::new();
|
||||||
for cidr in iface.borrow().ip_addrs() {
|
for cidr in iface.borrow().ip_addrs() {
|
||||||
ips += &format!("{}\n", cidr);
|
ips += &format!("{}\n", cidr);
|
||||||
@@ -177,6 +174,30 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe
|
|||||||
ips
|
ips
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"set" => {
|
||||||
|
wo [iface, notifier] (Vec<IpCidr>, Vec::new())
|
||||||
|
|cur_value, line| {
|
||||||
|
let cidr = IpCidr::from_str(line)
|
||||||
|
.map_err(|_| SyscallError::new(syscall::EINVAL))?;
|
||||||
|
if !cidr.address().is_unicast() {
|
||||||
|
return Err(SyscallError::new(syscall::EINVAL));
|
||||||
|
}
|
||||||
|
cur_value.push(cidr);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|cur_value| {
|
||||||
|
if !cur_value.is_empty() {
|
||||||
|
let mut iface = iface.borrow_mut();
|
||||||
|
let mut cidrs = vec![];
|
||||||
|
mem::swap(cur_value, &mut cidrs);
|
||||||
|
iface.update_ip_addrs(|s| {
|
||||||
|
*s = From::from(cidrs);
|
||||||
|
});
|
||||||
|
notifier.borrow_mut().schedule_notify("ifaces/eth0/addr/list");
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
},
|
||||||
"add" => {
|
"add" => {
|
||||||
wo [iface, notifier] (Vec<IpCidr>, Vec::new())
|
wo [iface, notifier] (Vec<IpCidr>, Vec::new())
|
||||||
|cur_value, line| {
|
|cur_value, line| {
|
||||||
@@ -270,7 +291,8 @@ impl NetCfgFile {
|
|||||||
|
|
||||||
fn consume_lines(&mut self) -> SyscallResult<()> {
|
fn consume_lines(&mut self) -> SyscallResult<()> {
|
||||||
if let Some(ref mut node_writer) = self.node_writer {
|
if let Some(ref mut node_writer) = self.node_writer {
|
||||||
let mut swap_with = {
|
let mut swap_with = None;
|
||||||
|
{
|
||||||
let mut lines = self.write_buf.split(|&c| c == b'\n');
|
let mut lines = self.write_buf.split(|&c| c == b'\n');
|
||||||
if let Some(mut cur_line) = lines.next() {
|
if let Some(mut cur_line) = lines.next() {
|
||||||
let mut consumed = false;
|
let mut consumed = false;
|
||||||
@@ -283,14 +305,10 @@ impl NetCfgFile {
|
|||||||
consumed = true;
|
consumed = true;
|
||||||
}
|
}
|
||||||
if consumed {
|
if consumed {
|
||||||
Some(From::from(cur_line))
|
swap_with = Some(From::from(cur_line))
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
if let Some(ref mut new_vec) = swap_with {
|
if let Some(ref mut new_vec) = swap_with {
|
||||||
mem::swap(&mut self.write_buf, new_vec);
|
mem::swap(&mut self.write_buf, new_vec);
|
||||||
}
|
}
|
||||||
@@ -389,7 +407,7 @@ impl SchemeMut for NetCfgScheme {
|
|||||||
if !file.done {
|
if !file.done {
|
||||||
file.commit().map(|_| 0)
|
file.commit().map(|_| 0)
|
||||||
} else {
|
} else {
|
||||||
Err(SyscallError::new(syscall::EBADF))
|
Ok(0)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(SyscallError::new(syscall::EBADF))
|
Err(SyscallError::new(syscall::EBADF))
|
||||||
|
|||||||
Reference in New Issue
Block a user