src/config/network/parser.rs: parse MTU settings
This commit is contained in:
@ -30,6 +30,8 @@ impl Interface {
|
||||
gateway_v4: None,
|
||||
cidr_v6: None,
|
||||
gateway_v6: None,
|
||||
mtu_v4: None,
|
||||
mtu_v6: None,
|
||||
options_v4: Vec::new(),
|
||||
options_v6: Vec::new(),
|
||||
}
|
||||
@ -107,6 +109,10 @@ impl Interface {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(mtu) = &self.mtu_v4 {
|
||||
writeln!(w, " mtu {}", mtu)?;
|
||||
}
|
||||
|
||||
for option in &self.options_v4 {
|
||||
writeln!(w, " {}", option)?;
|
||||
}
|
||||
@ -124,6 +130,10 @@ impl Interface {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(mtu) = &self.mtu_v6 {
|
||||
writeln!(w, " mtu {}", mtu)?;
|
||||
}
|
||||
|
||||
for option in &self.options_v6 {
|
||||
writeln!(w, " {}", option)?;
|
||||
}
|
||||
@ -148,7 +158,10 @@ impl Interface {
|
||||
writeln!(w, "auto {}", self.name)?;
|
||||
}
|
||||
|
||||
if self.method_v4 == self.method_v6 {
|
||||
if self.method_v4 == self.method_v6
|
||||
&& self.mtu_v4 == self.mtu_v6
|
||||
&& self.options_v4.is_empty() == self.options_v6.is_empty()
|
||||
{
|
||||
if let Some(method) = self.method_v4 {
|
||||
writeln!(w, "iface {} {}", self.name, method_to_str(method))?;
|
||||
self.write_iface_attributes_v4(w, method)?;
|
||||
|
@ -21,6 +21,7 @@ pub enum Token {
|
||||
Netmask,
|
||||
Static,
|
||||
Attribute,
|
||||
MTU,
|
||||
EOF,
|
||||
}
|
||||
|
||||
@ -38,6 +39,7 @@ lazy_static! {
|
||||
map.insert("manual", Token::Manual);
|
||||
map.insert("netmask", Token::Netmask);
|
||||
map.insert("static", Token::Static);
|
||||
map.insert("mtu", Token::MTU);
|
||||
map
|
||||
};
|
||||
}
|
||||
|
@ -121,6 +121,22 @@ impl <R: BufRead> NetworkParser<R> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_iface_mtu(&mut self) -> Result<u64, Error> {
|
||||
self.eat(Token::MTU)?;
|
||||
|
||||
let mtu = self.next_text()?;
|
||||
let mtu = match u64::from_str_radix(&mtu, 10) {
|
||||
Ok(mtu) => mtu,
|
||||
Err(err) => {
|
||||
bail!("unable to parse mtu value '{}' - {}", mtu, err);
|
||||
}
|
||||
};
|
||||
|
||||
self.eat(Token::Newline)?;
|
||||
|
||||
Ok(mtu)
|
||||
}
|
||||
|
||||
fn parse_to_eol(&mut self) -> Result<String, Error> {
|
||||
let mut line = String::new();
|
||||
loop {
|
||||
@ -140,7 +156,7 @@ impl <R: BufRead> NetworkParser<R> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_iface_attributes(&mut self, interface: &mut Interface) -> Result<(), Error> {
|
||||
fn parse_iface_attributes(&mut self, interface: &mut Interface, family_v4: bool, family_v6: bool) -> Result<(), Error> {
|
||||
|
||||
loop {
|
||||
match self.peek()? {
|
||||
@ -152,6 +168,11 @@ impl <R: BufRead> NetworkParser<R> {
|
||||
match self.peek()? {
|
||||
Token::Address => self.parse_iface_address(interface)?,
|
||||
Token::Gateway => self.parse_iface_gateway(interface)?,
|
||||
Token::MTU => {
|
||||
let mtu = self.parse_iface_mtu()?;
|
||||
if family_v4 { interface.mtu_v4 = Some(mtu); }
|
||||
if family_v6 { interface.mtu_v6 = Some(mtu); }
|
||||
}
|
||||
Token::Netmask => bail!("netmask is deprecated and no longer supported"),
|
||||
_ => {
|
||||
self.parse_iface_addon_attribute(interface)?;
|
||||
@ -200,7 +221,7 @@ impl <R: BufRead> NetworkParser<R> {
|
||||
interface.set_method_v6(config_method)?;
|
||||
}
|
||||
|
||||
if has_attributes { self.parse_iface_attributes(&mut interface)?; }
|
||||
if has_attributes { self.parse_iface_attributes(&mut interface, address_family_v4, address_family_v6)?; }
|
||||
} else {
|
||||
let mut interface = Interface::new(iface.clone());
|
||||
if address_family_v4 {
|
||||
@ -210,7 +231,7 @@ impl <R: BufRead> NetworkParser<R> {
|
||||
interface.set_method_v6(config_method)?;
|
||||
}
|
||||
|
||||
if has_attributes { self.parse_iface_attributes(&mut interface)?; }
|
||||
if has_attributes { self.parse_iface_attributes(&mut interface, address_family_v4, address_family_v6)?; }
|
||||
|
||||
config.interfaces.insert(interface.name.clone(), interface);
|
||||
|
||||
|
Reference in New Issue
Block a user