fn assign_ip(&self, ip: IpAddr, mask: u8) -> Result<(), TunError> {
        tracing::debug!("assigning ip {}/{} to tun device", ip, mask);
        let mut socket = self.open_netlink_socket(&[])?;

        // set ip on device
        let msg = Ifaddrmsg {
            ifa_family: match ip {
                IpAddr::V4(_) => RtAddrFamily::Inet,
                IpAddr::V6(_) => RtAddrFamily::Inet6,
            },
            ifa_prefixlen: mask,
            ifa_flags: IfaFFlags::new(&[IfaF::Permanent]),
            ifa_scope: RtScope::Universe.into(),
            ifa_index: self.index,
            rtattrs: {
                let mut attrs = RtBuffer::new();
                attrs.push(match ip {
                    IpAddr::V4(ip) => Rtattr::new(None, Ifa::Address, &ip.octets()[..])?,
                    IpAddr::V6(ip) => Rtattr::new(None, Ifa::Address, &ip.octets()[..])?,
                });
                attrs.push(match ip {
                    IpAddr::V4(ip) => Rtattr::new(None, Ifa::Local, &ip.octets()[..])?,
                    IpAddr::V6(ip) => Rtattr::new(None, Ifa::Local, &ip.octets()[..])?,
                });
                attrs
            },
        };

        let hdr = {
            let len = None;
            let nl_type = Rtm::Newaddr;
            let flags = NlmFFlags::new(&[NlmF::Request, NlmF::Create, NlmF::Excl]);
            let seq = None;
            let pid = None;
            let payload = msg;
            Nlmsghdr::new(len, nl_type, flags, seq, pid, NlPayload::Payload(payload))
        };

        socket.send(hdr)?;

        Ok(())
    }
/// Assign an IP address to the tunnel
///
/// # Arguments
/// * `ip` - IP Address to assign (e.g., `192.168.70.100`)
/// * `mask` - CIDR / subnet mask (e.g., `24`)
///
/// # Errors
/// * I/O if the netlink socket fails to open
/// * If the ip address is invalid
/// * If the subnet mask is inappropriate for the ip address
///     * i.e., >32 for IPv4 or >128 for IPv6
/// * If the netlink message fails to send properly
Assign an IP address to the tunnel
Assign an IP address to the tunnel
fn assign_ip(&self, ip: IpAddr, mask: u8) -> Result<(), TunError> {
        tracing::debug!("assigning ip {}/{} to tun device", ip, mask);
        let mut socket = self.open_netlink_socket(&[])?;
        // set ip on device
        let msg = Ifaddrmsg {
            ifa_family: match ip {
                IpAddr::V4(_) => RtAddrFamily::Inet,
                IpAddr::V6(_) => RtAddrFamily::Inet6,
            },
            ifa_prefixlen: mask,
            ifa_flags: IfaFFlags::new(&[IfaF::Permanent]),
            ifa_scope: RtScope::Universe.into(),
            ifa_index: self.index,
            rtattrs: {
                let mut attrs = RtBuffer::new();
                attrs.push(match ip {
                    IpAddr::V4(ip) => Rtattr::new(None, Ifa::Address, &ip.octets()[..])?,
                    IpAddr::V6(ip) => Rtattr::new(None, Ifa::Address, &ip.octets()[..])?,
                });
                attrs.push(match ip {
                    IpAddr::V4(ip) => Rtattr::new(None, Ifa::Local, &ip.octets()[..])?,
                    IpAddr::V6(ip) => Rtattr::new(None, Ifa::Local, &ip.octets()[..])?,
                });
                attrs
            },
        };
        let hdr = {
            let len = None;
            let nl_type = Rtm::Newaddr;
            let flags = NlmFFlags::new(&[NlmF::Request, NlmF::Create, NlmF::Excl]);
            let seq = None;
            let pid = None;
            let payload = msg;
            Nlmsghdr::new(len, nl_type, flags, seq, pid, NlPayload::Payload(payload))
        };
        socket.send(hdr)?;
        Ok(())
    }
fn assign_ip ( & self , ip : IpAddr , mask : u8 ) -> Result < ( ) , TunError > { tracing :: debug ! ( " " ip mask ) ; let mut socket = self . open_netlink_socket ( & [ ] ) ? ; // set ip on device let msg = Ifaddrmsg { ifa_family : match ip { IpAddr :: V4 ( _ ) => RtAddrFamily :: Inet , IpAddr :: V6 ( _ ) => RtAddrFamily :: Inet6 , } , ifa_prefixlen : mask , ifa_flags : IfaFFlags :: new ( & [ IfaF :: Permanent ] ) , ifa_scope : RtScope :: Universe . into ( ) , ifa_index : self . index , rtattrs : { let mut attrs = RtBuffer :: new ( ) ; attrs . push ( match ip { IpAddr :: V4 ( ip ) => Rtattr :: new ( None , Ifa :: Address , & ip . octets ( ) [ .. ] ) ? , IpAddr :: V6 ( ip ) => Rtattr :: new ( None , Ifa :: Address , & ip . octets ( ) [ .. ] ) ? , } ) ; attrs . push ( match ip { IpAddr :: V4 ( ip ) => Rtattr :: new ( None , Ifa :: Local , & ip . octets ( ) [ .. ] ) ? , IpAddr :: V6 ( ip ) => Rtattr :: new ( None , Ifa :: Local , & ip . octets ( ) [ .. ] ) ? , } ) ; attrs } , } ; let hdr = { let len = None ; let nl_type = Rtm :: Newaddr ; let flags = NlmFFlags :: new ( & [ NlmF :: Request , NlmF :: Create , NlmF :: Excl ] ) ; let seq = None ; let pid = None ; let payload = msg ; Nlmsghdr :: new ( len , nl_type , flags , seq , pid , NlPayload :: Payload ( payload ) ) } ; socket . send ( hdr ) ? ; Ok ( ( ) ) }
Assign an IP address to the tunnel
Assign an IP address to the tunnel
&self
ip
IpAddr
mask
u8
&self
ip
IpAddr
mask
u8
errors
I/O if the netlink socket fails to open
If the ip address is invalid
If the subnet mask is inappropriate for the ip address
i.e., >32 for IPv4 or >128 for IPv6
If the netlink message fails to send properly
I / O if the netlink socket fails to open If the ip address is invalid If the subnet mask is inappropriate for the ip address i . e . > 32 for IPv4 or > 128 for IPv6 If the netlink message fails to send properly