Add mtu option

This commit is contained in:
Dennis Schwerdel 2021-03-26 13:20:35 +01:00
parent 49945568ce
commit da9befe235
3 changed files with 21 additions and 2 deletions

View File

@ -23,6 +23,7 @@ pub struct Config {
pub device_type: Type, pub device_type: Type,
pub device_name: String, pub device_name: String,
pub device_path: Option<String>, pub device_path: Option<String>,
pub device_mtu: Option<usize>,
pub fix_rp_filter: bool, pub fix_rp_filter: bool,
pub ip: Option<String>, pub ip: Option<String>,
@ -61,6 +62,7 @@ impl Default for Config {
device_type: Type::Tun, device_type: Type::Tun,
device_name: "vpncloud%d".to_string(), device_name: "vpncloud%d".to_string(),
device_path: None, device_path: None,
device_mtu: None,
fix_rp_filter: false, fix_rp_filter: false,
ip: None, ip: None,
ifup: None, ifup: None,
@ -105,6 +107,9 @@ impl Config {
if let Some(val) = device.path { if let Some(val) = device.path {
self.device_path = Some(val); self.device_path = Some(val);
} }
if let Some(val) = device.mtu {
self.device_mtu = Some(val);
}
if let Some(val) = device.fix_rp_filter { if let Some(val) = device.fix_rp_filter {
self.fix_rp_filter = val; self.fix_rp_filter = val;
} }
@ -210,6 +215,9 @@ impl Config {
if let Some(val) = args.device_path { if let Some(val) = args.device_path {
self.device_path = Some(val); self.device_path = Some(val);
} }
if let Some(val) = args.device_mtu {
self.device_mtu = Some(val);
}
if args.fix_rp_filter { if args.fix_rp_filter {
self.fix_rp_filter = true; self.fix_rp_filter = true;
} }
@ -316,6 +324,7 @@ impl Config {
device: Some(ConfigFileDevice { device: Some(ConfigFileDevice {
name: Some(self.device_name), name: Some(self.device_name),
path: self.device_path, path: self.device_path,
mtu: self.device_mtu,
type_: Some(self.device_type), type_: Some(self.device_type),
fix_rp_filter: Some(self.fix_rp_filter) fix_rp_filter: Some(self.fix_rp_filter)
}), }),
@ -417,6 +426,10 @@ pub struct Args {
#[structopt(long)] #[structopt(long)]
pub device_path: Option<String>, pub device_path: Option<String>,
/// Set the mtu og the device
#[structopt(long)]
pub device_mtu: Option<usize>,
/// Fix the rp_filter settings on the host /// Fix the rp_filter settings on the host
#[structopt(long)] #[structopt(long)]
pub fix_rp_filter: bool, pub fix_rp_filter: bool,
@ -619,6 +632,7 @@ pub struct ConfigFileDevice {
pub type_: Option<Type>, pub type_: Option<Type>,
pub name: Option<String>, pub name: Option<String>,
pub path: Option<String>, pub path: Option<String>,
pub mtu: Option<usize>,
pub fix_rp_filter: Option<bool>, pub fix_rp_filter: Option<bool>,
} }
@ -675,6 +689,7 @@ device:
type: tun type: tun
name: vpncloud%d name: vpncloud%d
path: /dev/net/tun path: /dev/net/tun
mtu: 1400
ip: 10.0.1.1/16 ip: 10.0.1.1/16
ifup: ifconfig $IFNAME 10.0.1.1/16 mtu 1400 up ifup: ifconfig $IFNAME 10.0.1.1/16 mtu 1400 up
ifdown: 'true' ifdown: 'true'
@ -708,6 +723,7 @@ statsd:
type_: Some(Type::Tun), type_: Some(Type::Tun),
name: Some("vpncloud%d".to_string()), name: Some("vpncloud%d".to_string()),
path: Some("/dev/net/tun".to_string()), path: Some("/dev/net/tun".to_string()),
mtu: Some(1400),
fix_rp_filter: None fix_rp_filter: None
}), }),
ip: Some("10.0.1.1/16".to_string()), ip: Some("10.0.1.1/16".to_string()),
@ -756,6 +772,7 @@ async fn config_merge() {
type_: Some(Type::Tun), type_: Some(Type::Tun),
name: Some("vpncloud%d".to_string()), name: Some("vpncloud%d".to_string()),
path: None, path: None,
mtu: None,
fix_rp_filter: None, fix_rp_filter: None,
}), }),
ip: None, ip: None,
@ -847,6 +864,7 @@ async fn config_merge() {
device_type: Type::Tap, device_type: Type::Tap,
device_name: "vpncloud0".to_string(), device_name: "vpncloud0".to_string(),
device_path: Some("/dev/null".to_string()), device_path: Some("/dev/null".to_string()),
device_mtu: None,
fix_rp_filter: false, fix_rp_filter: false,
ip: None, ip: None,
ifup: Some("ifconfig $IFNAME 10.0.1.2/16 mtu 1400 up".to_string()), ifup: Some("ifconfig $IFNAME 10.0.1.2/16 mtu 1400 up".to_string()),

View File

@ -144,8 +144,8 @@ async fn setup_device(config: &Config) -> TunTapDevice {
); );
info!("Opened device {}", device.ifname()); info!("Opened device {}", device.ifname());
config.call_hook("device_setup", vec![("IFNAME", device.ifname())], true); config.call_hook("device_setup", vec![("IFNAME", device.ifname())], true);
if let Err(err) = device.set_mtu(None).await { if let Err(err) = device.set_mtu(config.device_mtu).await {
error!("Error setting optimal MTU on {}: {}", device.ifname(), err); error!("Error setting MTU on {}: {}", device.ifname(), err);
} }
if let Some(ip) = &config.ip { if let Some(ip) = &config.ip {
let (ip, netmask) = try_fail!(parse_ip_netmask(ip), "Invalid ip address given: {}"); let (ip, netmask) = try_fail!(parse_ip_netmask(ip), "Invalid ip address given: {}");

View File

@ -103,6 +103,7 @@ impl OldConfigFile {
fix_rp_filter: None, fix_rp_filter: None,
name: self.device_name, name: self.device_name,
path: self.device_path, path: self.device_path,
mtu: None,
type_: self.device_type type_: self.device_type
}), }),
group: self.group, group: self.group,