From dfe3ac877a538e753945e63a6a852a0f8c54ed5f Mon Sep 17 00:00:00 2001 From: Niklas Kuhrmeyer Date: Fri, 30 Oct 2020 12:16:28 +0100 Subject: [PATCH 1/3] added gateway --- src/main.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main.rs b/src/main.rs index 9e0c0ff..0f4b347 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,6 +36,8 @@ use stm32h7xx_hal::prelude::*; use embedded_hal::digital::v2::{InputPin, OutputPin}; use smoltcp as net; +use smoltcp::wire::Ipv4Address; +use smoltcp::iface::Routes; use stm32h7_ethernet as ethernet; use heapless::{consts::*, String}; @@ -76,6 +78,7 @@ mod build_info { pub struct NetStorage { ip_addrs: [net::wire::IpCidr; 1], neighbor_cache: [Option<(net::wire::IpAddress, net::iface::Neighbor)>; 8], + routes_storage: [Option<(smoltcp::wire::IpCidr, smoltcp::iface::Route)>; 2], } static mut NET_STORE: NetStorage = NetStorage { @@ -85,6 +88,8 @@ static mut NET_STORE: NetStorage = NetStorage { )], neighbor_cache: [None; 8], + + routes_storage: [None; 2], }; const SCALE: f32 = ((1 << 15) - 1) as f32; @@ -617,6 +622,10 @@ const APP: () = { 24, ); + let default_v4_gw = Ipv4Address::new(10,0,16,1); + let mut routes = Routes::new(&mut store.routes_storage[..]); + routes.add_default_ipv4_route(default_v4_gw).unwrap(); + let neighbor_cache = net::iface::NeighborCache::new(&mut store.neighbor_cache[..]); @@ -624,6 +633,7 @@ const APP: () = { .ethernet_addr(mac_addr) .neighbor_cache(neighbor_cache) .ip_addrs(&mut store.ip_addrs[..]) + .routes(routes) .finalize(); (interface, eth_mac) From 32d5e4dfe14161de6046792b5180e9565cc8b563 Mon Sep 17 00:00:00 2001 From: Niklas Kuhrmeyer Date: Fri, 30 Oct 2020 13:32:47 +0100 Subject: [PATCH 2/3] format --- src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0f4b347..62ed019 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,8 +36,9 @@ use stm32h7xx_hal::prelude::*; use embedded_hal::digital::v2::{InputPin, OutputPin}; use smoltcp as net; -use smoltcp::wire::Ipv4Address; use smoltcp::iface::Routes; +use smoltcp::wire::Ipv4Address; + use stm32h7_ethernet as ethernet; use heapless::{consts::*, String}; @@ -622,7 +623,7 @@ const APP: () = { 24, ); - let default_v4_gw = Ipv4Address::new(10,0,16,1); + let default_v4_gw = Ipv4Address::new(10, 0, 16, 1); let mut routes = Routes::new(&mut store.routes_storage[..]); routes.add_default_ipv4_route(default_v4_gw).unwrap(); From 2f5d26aeaa7dd40a979918203a56e5791b40f9cd Mon Sep 17 00:00:00 2001 From: Niklas Kuhrmeyer Date: Fri, 30 Oct 2020 13:33:59 +0100 Subject: [PATCH 3/3] decreased routes_storage --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 62ed019..658bbd5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -79,7 +79,7 @@ mod build_info { pub struct NetStorage { ip_addrs: [net::wire::IpCidr; 1], neighbor_cache: [Option<(net::wire::IpAddress, net::iface::Neighbor)>; 8], - routes_storage: [Option<(smoltcp::wire::IpCidr, smoltcp::iface::Route)>; 2], + routes_storage: [Option<(smoltcp::wire::IpCidr, smoltcp::iface::Route)>; 1], } static mut NET_STORE: NetStorage = NetStorage { @@ -90,7 +90,7 @@ static mut NET_STORE: NetStorage = NetStorage { neighbor_cache: [None; 8], - routes_storage: [None; 2], + routes_storage: [None; 1], }; const SCALE: f32 = ((1 << 15) - 1) as f32;