Skip to content

Commit

Permalink
change license and rollback smoltcp version
Browse files Browse the repository at this point in the history
  • Loading branch information
lhw2002426 committed Jun 17, 2024
1 parent f0d8d9b commit ac58ac2
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 234 deletions.
42 changes: 4 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion apps/c/httpserver/features.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
alloc
paging
net
multitask
2 changes: 1 addition & 1 deletion crates/lwip_rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"
authors = ["HaoWen Liu <[email protected]>"]
description = "Rust wrapper of lwip net stack"
license = "GPL-3.0-or-later OR Apache-2.0"
license = "Mulan PSL v2"
homepage = "https://github.com/syswonder/ruxos"
repository = "https://github.com/syswonder/ruxos/tree/main/crates/lwip_rust"

Expand Down
4 changes: 0 additions & 4 deletions crates/lwip_rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,10 @@ fn compile_lwip() {
.file("depend/lwip/src/core/ipv4/ip4_frag.c")
.file("depend/lwip/src/core/ipv4/ip4.c")
.file("depend/lwip/src/core/ipv4/ip4_addr.c")
.file("depend/lwip/src/core/ipv6/dhcp6.c")
.file("depend/lwip/src/core/ipv6/ethip6.c")
.file("depend/lwip/src/core/ipv6/icmp6.c")
.file("depend/lwip/src/core/ipv6/inet6.c")
.file("depend/lwip/src/core/ipv6/ip6.c")
.file("depend/lwip/src/core/ipv6/ip6_addr.c")
.file("depend/lwip/src/core/ipv6/ip6_frag.c")
.file("depend/lwip/src/core/ipv6/mld6.c")
.file("depend/lwip/src/core/ipv6/nd6.c")
.file("depend/lwip/src/netif/ethernet.c")
.file("custom/custom_pool.c");
Expand Down
9 changes: 1 addition & 8 deletions crates/lwip_rust/custom/arch/cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,14 @@ typedef long ssize_t;
#define SSIZE_MAX INT_MAX
#define LWIP_NO_UNISTD_H 1

extern int lwip_print(const char *fmt, ...);
extern void lwip_abort(void);
extern unsigned int lwip_rand_u32(void);

#define LWIP_PLATFORM_DIAG(x) \
do { \
lwip_print x; \
} while (0)

#define LWIP_PLATFORM_ASSERT(x) \
do { \
lwip_print("Assert \"%s\" failed at line %d in %s\n", x, __LINE__, __FILE__); \
lwip_abort(); \
} while (0)

#define LWIP_RAND() (lwip_rand_u32())
#define LWIP_RAND() (0)

#endif /* __ARCH_CC_H__ */
9 changes: 0 additions & 9 deletions crates/lwip_rust/custom/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
#define LWIP_SOCKET 0
#define PPP_SUPPORT 0
#define LWIP_IPV4 1
#define LWIP_IPV6 1
#define LWIP_IPV6_MLD 0
#define LWIP_IPV6_AUTOCONFIG 1

// Enable SO_REUSEADDR
#define SO_REUSE 1
Expand Down Expand Up @@ -74,10 +71,6 @@
#define LWIP_CHECKSUM_ON_COPY 1
#define SYS_LIGHTWEIGHT_PROT 0

// needed on 64-bit systems, enable it always so that the same configuration
// is used regardless of the platform
#define IPV6_FRAG_COPYHEADER 1

/*
------------------------------------
---------- Debug options ----------
Expand Down Expand Up @@ -120,8 +113,6 @@
#define AUTOIP_DEBUG LWIP_DBG_ON
#define ACD_DEBUG LWIP_DBG_ON
#define DNS_DEBUG LWIP_DBG_ON
#define IP6_DEBUG LWIP_DBG_ON
#define DHCP6_DEBUG LWIP_DBG_ON

#define LWIP_STATS 0
#define LWIP_STATS_DISPLAY 0
Expand Down
1 change: 0 additions & 1 deletion crates/lwip_rust/wrapper.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "depend/lwip/src/include/lwip/def.h"
#include "depend/lwip/src/include/lwip/dns.h"
#include "depend/lwip/src/include/lwip/etharp.h"
#include "depend/lwip/src/include/lwip/ethip6.h"
#include "depend/lwip/src/include/lwip/init.h"
#include "depend/lwip/src/include/lwip/ip4_addr.h"
#include "depend/lwip/src/include/lwip/ip_addr.h"
Expand Down
4 changes: 2 additions & 2 deletions modules/axnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ cty = { version = "0.2.2", optional = true }
axio = { path = "../../crates/axio" }

[dependencies.smoltcp]
git = "https://github.com/smoltcp-rs/smoltcp"
rev = "ce42011"
git = "https://github.com/rcore-os/smoltcp.git"
rev = "2ade274"
default-features = false
features = [
"alloc", "log", # no std
Expand Down
103 changes: 9 additions & 94 deletions modules/axnet/src/lwip_impl/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use core::{
};

use lwip_rust::bindings::{
ip4_addr_t, ip6_addr_t, ip_addr__bindgen_ty_1, ip_addr_t, lwip_ip_addr_type_IPADDR_TYPE_V4,
lwip_ip_addr_type_IPADDR_TYPE_V6,
ip4_addr_t, ip_addr_t, lwip_ip_addr_type_IPADDR_TYPE_V4, lwip_ip_addr_type_IPADDR_TYPE_V6,
};

use core::net::{
Expand Down Expand Up @@ -75,9 +74,7 @@ impl IpAddr {
pub fn as_bytes(&self) -> &[u8] {
match self {
IpAddr::Ipv4(Ipv4Addr(addr)) => unsafe { &*(addr as *const u32 as *const [u8; 4]) },
IpAddr::Ipv6(Ipv6Addr { addr, .. }) => unsafe {
&*(addr as *const u32 as *const [u8; 16])
},
_ => panic!("IPv6 not supported"),
}
}
}
Expand Down Expand Up @@ -112,43 +109,24 @@ impl FromStr for IpAddr {
impl From<IpAddr> for ip_addr_t {
fn from(val: IpAddr) -> Self {
match val {
IpAddr::Ipv4(Ipv4Addr(addr)) => ip_addr_t {
u_addr: ip_addr__bindgen_ty_1 {
ip4: ip4_addr_t { addr },
},
type_: lwip_ip_addr_type_IPADDR_TYPE_V4 as u8,
},
IpAddr::Ipv6(Ipv6Addr { addr, zone }) => ip_addr_t {
u_addr: ip_addr__bindgen_ty_1 {
ip6: ip6_addr_t { addr, zone },
},
type_: lwip_ip_addr_type_IPADDR_TYPE_V6 as u8,
},
IpAddr::Ipv4(Ipv4Addr(addr)) => ip_addr_t { addr: addr },
_ => panic!("IPv6 not supported"),
}
}
}

impl From<ip_addr_t> for IpAddr {
#[allow(non_upper_case_globals)]
fn from(addr: ip_addr_t) -> IpAddr {
match addr.type_ as u32 {
lwip_ip_addr_type_IPADDR_TYPE_V4 => {
IpAddr::Ipv4(Ipv4Addr(unsafe { addr.u_addr.ip4.addr }))
}
lwip_ip_addr_type_IPADDR_TYPE_V6 => IpAddr::Ipv6(Ipv6Addr {
addr: unsafe { addr.u_addr.ip6.addr },
zone: unsafe { addr.u_addr.ip6.zone },
}),
_ => panic!("unsupported ip type"),
}
IpAddr::Ipv4(Ipv4Addr(unsafe { addr.addr }))
}
}

impl fmt::Display for IpAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
IpAddr::Ipv4(ipv4_addr) => write!(f, "{ipv4_addr}"),
IpAddr::Ipv6(ipv6_addr) => write!(f, "{ipv6_addr}"),
_ => panic!("IPv6 not supported"),
}
}
}
Expand Down Expand Up @@ -246,34 +224,7 @@ impl From<SocketAddr> for CoreSocketAddr {
let std_ipv4 = CoreIpv4Addr::new(octets[0], octets[1], octets[2], octets[3]);
CoreSocketAddr::V4(SocketAddrV4::new(std_ipv4, socket_addr.port))
}
IpAddr::Ipv6(ipv6_addr) => {
let segments = [
(ipv6_addr.addr[0] >> 16) as u16,
(ipv6_addr.addr[0] & 0xFFFF) as u16,
(ipv6_addr.addr[1] >> 16) as u16,
(ipv6_addr.addr[1] & 0xFFFF) as u16,
(ipv6_addr.addr[2] >> 16) as u16,
(ipv6_addr.addr[2] & 0xFFFF) as u16,
(ipv6_addr.addr[3] >> 16) as u16,
(ipv6_addr.addr[3] & 0xFFFF) as u16,
];
let std_ipv6 = CoreIpv6Addr::new(
segments[0],
segments[1],
segments[2],
segments[3],
segments[4],
segments[5],
segments[6],
segments[7],
);
CoreSocketAddr::V6(SocketAddrV6::new(
std_ipv6,
socket_addr.port,
0,
ipv6_addr.zone.into(),
))
}
_ => panic!("IPv6 not supported"),
}
}
}
Expand All @@ -289,22 +240,7 @@ impl From<CoreSocketAddr> for SocketAddr {
port: v4_addr.port(),
}
}
CoreSocketAddr::V6(v6_addr) => {
let segments = v6_addr.ip().segments();
let ipv6_addr = Ipv6Addr {
addr: [
((segments[0] as u32) << 16) | (segments[1] as u32),
((segments[2] as u32) << 16) | (segments[3] as u32),
((segments[4] as u32) << 16) | (segments[5] as u32),
((segments[6] as u32) << 16) | (segments[7] as u32),
],
zone: v6_addr.scope_id() as u8,
};
SocketAddr {
addr: IpAddr::Ipv6(ipv6_addr),
port: v6_addr.port(),
}
}
_ => panic!("IPv6 not supported"),
}
}
}
Expand Down Expand Up @@ -373,27 +309,6 @@ pub fn mask_to_prefix(mask: IpAddr) -> Result<u8, Error> {
Ok(prefix)
}
}
IpAddr::Ipv6(Ipv6Addr { addr, .. }) => {
let mut prefix = 0;
let mut finish = false;
for mask in &addr {
let mut mask = mask.swap_bytes();
for _ in 0..32 {
if finish {
if mask != 0 {
return Err(Error);
} else {
break;
}
} else if mask & (1 << 31) != 0 {
prefix += 1;
} else {
finish = true;
}
mask <<= 1;
}
}
Ok(prefix)
}
_ => panic!("IPv6 not supported"),
}
}
Loading

0 comments on commit ac58ac2

Please sign in to comment.