Skip to content
Snippets Groups Projects
Commit 6b02a200 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Fix loopback

parent 5bdcb832
No related branches found
No related tags found
No related merge requests found
......@@ -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];
......
......@@ -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>> {
......
......@@ -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>;
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment