diff --git a/contrib/aws/common.py b/contrib/aws/common.py index 82d6ff5..e9aa736 100644 --- a/contrib/aws/common.py +++ b/contrib/aws/common.py @@ -120,7 +120,7 @@ def find_ami(region, owner, name_pattern, arch='x86_64'): class EC2Environment: - def __init__(self, vpncloud_version, region, node_count, instance_type, vpncloud_file=None, use_spot=True, max_price=0.1, ami=('amazon', 'amzn2-ami-hvm-*'), username="ec2-user", subnet=CREATE, keyname=CREATE, privatekey=CREATE, tag="vpncloud", cluster_nodes=False): + def __init__(self, vpncloud_version, region, node_count, instance_type, vpncloud_file=None, use_spot=True, max_price=0.1, ami=('amazon', 'al2023-ami-*-hvm-*'), username="ec2-user", subnet=CREATE, keyname=CREATE, privatekey=CREATE, tag="vpncloud", cluster_nodes=False): self.region = region self.node_count = node_count self.instance_type = instance_type @@ -249,7 +249,6 @@ runcmd: "Ebs": { "DeleteOnTermination": True, "VolumeType": "gp2", - "VolumeSize": 8, } } ], diff --git a/contrib/aws/performance.py b/contrib/aws/performance.py index 565421b..4f716c6 100755 --- a/contrib/aws/performance.py +++ b/contrib/aws/performance.py @@ -8,7 +8,7 @@ from datetime import date # Note: this script will run for ~8 minutes and incur costs of about $ 0.02 FILE = "../../target/release/vpncloud" -VERSION = "2.3.0" +VERSION = "2.4.0" REGION = "eu-central-1" env = EC2Environment( diff --git a/src/device.rs b/src/device.rs index e712aa6..e76bb01 100644 --- a/src/device.rs +++ b/src/device.rs @@ -10,20 +10,27 @@ use std::{ fs::{self, File}, io::{self, BufRead, BufReader, Cursor, Error as IoError, Read, Write}, net::{Ipv4Addr, UdpSocket}, - os::unix::io::{AsRawFd, RawFd}, + os::{unix::io::AsRawFd, fd::RawFd}, str, - str::FromStr, + str::FromStr }; use crate::{crypto, error::Error, util::MsgBuffer}; static TUNSETIFF: libc::c_ulong = 1074025674; +#[repr(C)] +#[derive(Copy, Clone)] +struct IfReqDataAddr { + af: libc::c_int, + addr: Ipv4Addr +} + #[repr(C)] union IfReqData { flags: libc::c_short, value: libc::c_int, - addr: (libc::c_short, Ipv4Addr), + addr: IfReqDataAddr, _dummy: [u8; 24], } @@ -392,11 +399,11 @@ fn get_device_addr(ifname: &str) -> io::Result { let res = unsafe { libc::ioctl(sock.as_raw_fd(), libc::SIOCGIFADDR.try_into().unwrap(), &mut ifreq) }; match res { 0 => { - let af = unsafe { ifreq.data.addr.0 }; + let af = unsafe { ifreq.data.addr.af }; if af as libc::c_int != libc::AF_INET { return Err(io::Error::new(io::ErrorKind::AddrNotAvailable, "Invalid address family".to_owned())); } - let ip = unsafe { ifreq.data.addr.1 }; + let ip = unsafe { ifreq.data.addr.addr }; Ok(ip) } _ => Err(IoError::last_os_error()), @@ -407,7 +414,8 @@ fn get_device_addr(ifname: &str) -> io::Result { fn set_device_addr(ifname: &str, addr: Ipv4Addr) -> io::Result<()> { let sock = UdpSocket::bind("0.0.0.0:0")?; let mut ifreq = IfReq::new(ifname); - ifreq.data.addr = (libc::AF_INET as libc::c_short, addr); + ifreq.data.addr.af = libc::AF_INET as libc::c_int; + ifreq.data.addr.addr = addr; let res = unsafe { libc::ioctl(sock.as_raw_fd(), libc::SIOCSIFADDR.try_into().unwrap(), &mut ifreq) }; match res { 0 => Ok(()), @@ -423,11 +431,11 @@ fn get_device_netmask(ifname: &str) -> io::Result { let res = unsafe { libc::ioctl(sock.as_raw_fd(), libc::SIOCGIFNETMASK.try_into().unwrap(), &mut ifreq) }; match res { 0 => { - let af = unsafe { ifreq.data.addr.0 }; + let af = unsafe { ifreq.data.addr.af }; if af as libc::c_int != libc::AF_INET { return Err(io::Error::new(io::ErrorKind::AddrNotAvailable, "Invalid address family".to_owned())); } - let ip = unsafe { ifreq.data.addr.1 }; + let ip = unsafe { ifreq.data.addr.addr }; Ok(ip) } _ => Err(IoError::last_os_error()), @@ -438,7 +446,8 @@ fn get_device_netmask(ifname: &str) -> io::Result { fn set_device_netmask(ifname: &str, addr: Ipv4Addr) -> io::Result<()> { let sock = UdpSocket::bind("0.0.0.0:0")?; let mut ifreq = IfReq::new(ifname); - ifreq.data.addr = (libc::AF_INET as libc::c_short, addr); + ifreq.data.addr.af = libc::AF_INET as libc::c_int; + ifreq.data.addr.addr = addr; let res = unsafe { libc::ioctl(sock.as_raw_fd(), libc::SIOCSIFNETMASK.try_into().unwrap(), &mut ifreq) }; match res { 0 => Ok(()),