Fix loopback

This commit is contained in:
Jeremy Soller 2016-11-28 14:45:30 -07:00
parent 5bdcb832c0
commit 6b02a20028
4 changed files with 11 additions and 4 deletions

View file

@ -37,6 +37,10 @@ impl Interface for EthernetInterface {
self.ip
}
fn routable(&self, dst: Ipv4Addr) -> bool {
dst != Ipv4Addr::LOOPBACK
}
fn arp_event(&mut self) -> Result<()> {
loop {
let mut bytes = [0; 65536];

View file

@ -4,14 +4,12 @@ use std::io::Result;
use interface::Interface;
pub struct LoopbackInterface {
ip: Ipv4Addr,
packets: Vec<Ipv4>
}
impl LoopbackInterface {
pub fn new() -> Self {
LoopbackInterface {
ip: Ipv4Addr::LOOPBACK,
packets: Vec::new()
}
}
@ -19,7 +17,11 @@ impl LoopbackInterface {
impl Interface for LoopbackInterface {
fn ip(&self) -> Ipv4Addr {
self.ip
Ipv4Addr::LOOPBACK
}
fn routable(&self, dst: Ipv4Addr) -> bool {
dst == Ipv4Addr::LOOPBACK
}
fn recv(&mut self) -> Result<Vec<Ipv4>> {

View file

@ -9,6 +9,7 @@ mod loopback;
pub trait Interface {
fn ip(&self) -> Ipv4Addr;
fn routable(&self, dst: Ipv4Addr) -> bool;
fn recv(&mut self) -> Result<Vec<Ipv4>>;
fn send(&mut self, ip: Ipv4) -> Result<usize>;

View file

@ -194,7 +194,7 @@ impl SchemeMut for Ipd {
if let Some(mut ip) = Ipv4::from_bytes(buf) {
for mut interface in self.interfaces.iter_mut() {
let if_ip = interface.ip();
if ip.header.src == if_ip || ip.header.src == Ipv4Addr::NULL {
if ip.header.src == if_ip || (ip.header.src == Ipv4Addr::NULL && interface.routable(ip.header.dst)) {
ip.header.src = if_ip;
ip.header.proto = handle.proto;