mirror of https://github.com/jgoerzen/xbnet.git
more fixes
This commit is contained in:
parent
1a6705f92b
commit
e48a3985fb
12
src/main.rs
12
src/main.rs
|
@ -191,16 +191,12 @@ fn main() {
|
|||
Command::Tun {
|
||||
broadcast_everything,
|
||||
iface_name,
|
||||
max_ip_cache
|
||||
max_ip_cache,
|
||||
} => {
|
||||
let max_ip_cache = Duration::from_secs(max_ip_cache);
|
||||
let tun_reader = tun::XBTun::new_tun(
|
||||
xb.mymac,
|
||||
broadcast_everything,
|
||||
iface_name,
|
||||
max_ip_cache,
|
||||
)
|
||||
.expect("Failure initializing tun");
|
||||
let tun_reader =
|
||||
tun::XBTun::new_tun(xb.mymac, broadcast_everything, iface_name, max_ip_cache)
|
||||
.expect("Failure initializing tun");
|
||||
let tun_writer = tun_reader.clone();
|
||||
let maxpacketsize = xb.maxpacketsize;
|
||||
thread::spawn(move || {
|
||||
|
|
28
src/tun.rs
28
src/tun.rs
|
@ -82,7 +82,7 @@ impl XBTun {
|
|||
// Broadcast if we don't know it
|
||||
None => XB_BROADCAST,
|
||||
Some((dest, expiration)) => {
|
||||
if Instant::now() >= *expiration {
|
||||
if Instant::now() >= *expiration {
|
||||
// Broadcast it if the cache entry has expired
|
||||
XB_BROADCAST
|
||||
} else {
|
||||
|
@ -109,7 +109,12 @@ impl XBTun {
|
|||
let ips = extract_ips(&packet);
|
||||
if let Some((source, destination)) = ips {
|
||||
let destxbmac = self.get_xb_dest_mac(&destination);
|
||||
trace!("TAPIN: Packet {} -> {} (MAC {:x})", source, destination, destxbmac);
|
||||
trace!(
|
||||
"TAPIN: Packet {} -> {} (MAC {:x})",
|
||||
source,
|
||||
destination,
|
||||
destxbmac
|
||||
);
|
||||
let res = sender.try_send(XBTX::TXData(
|
||||
XBDestAddr::U64(destxbmac),
|
||||
Bytes::copy_from_slice(tundata),
|
||||
|
@ -162,7 +167,12 @@ impl XBTun {
|
|||
}
|
||||
}
|
||||
|
||||
self.tun.send(&payload)?;
|
||||
match self.tun.send(&payload) {
|
||||
Ok(_) => (),
|
||||
Err(e) => {
|
||||
warn!("Failure to send packet to tun interface; have you given it an IP? Error: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -170,10 +180,14 @@ impl XBTun {
|
|||
/// Returns the source and destination IPs
|
||||
pub fn extract_ips<'a>(packet: &SlicedPacket<'a>) -> Option<(IpAddr, IpAddr)> {
|
||||
match &packet.ip {
|
||||
Some(InternetSlice::Ipv4(header)) => Some((IpAddr::V4(header.source_addr()),
|
||||
IpAddr::V4(header.destination_addr()))),
|
||||
Some(InternetSlice::Ipv6(header, _)) => Some((IpAddr::V6(header.source_addr()),
|
||||
IpAddr::V6(header.destination_addr()))),
|
||||
Some(InternetSlice::Ipv4(header)) => Some((
|
||||
IpAddr::V4(header.source_addr()),
|
||||
IpAddr::V4(header.destination_addr()),
|
||||
)),
|
||||
Some(InternetSlice::Ipv6(header, _)) => Some((
|
||||
IpAddr::V6(header.source_addr()),
|
||||
IpAddr::V6(header.destination_addr()),
|
||||
)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue