Skip to content

Commit 3679c1f

Browse files
committed
feat: alloc 127.0.0.2 ~ 127.0.0.8 to loopback device
1 parent 436618d commit 3679c1f

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

kernel/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ linkme = "=0.3.27"
4646
num = { version = "=0.4.0", default-features = false }
4747
num-derive = "=0.3"
4848
num-traits = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/num-traits.git", rev="1597c1c", default-features = false }
49-
smoltcp = { version = "=0.11.0", default-features = false, features = ["log", "alloc", "socket-raw", "socket-udp", "socket-tcp", "socket-icmp", "socket-dhcpv4", "socket-dns", "proto-ipv4", "proto-ipv6"]}
49+
smoltcp = { version = "=0.11.0", default-features = false, features = ["log", "alloc", "socket-raw", "socket-udp", "socket-tcp", "socket-icmp", "socket-dhcpv4", "socket-dns", "proto-ipv4", "proto-ipv6", "iface-max-addr-count-8"]}
5050
system_error = { path = "crates/system_error" }
5151
unified-init = { path = "crates/unified-init" }
5252
virtio-drivers = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/virtio-drivers", rev = "f91c807965" }

kernel/src/driver/net/loopback.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,11 @@ impl LoopbackInterface {
264264
smoltcp::iface::Interface::new(iface_config, &mut driver, Instant::now().into());
265265
//设置网卡地址为127.0.0.1
266266
iface.update_ip_addrs(|ip_addrs| {
267-
ip_addrs
268-
.push(IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8))
269-
.unwrap();
267+
for i in 1..=8 {
268+
ip_addrs
269+
.push(IpCidr::new(IpAddress::v4(127, 0, 0, i), 8))
270+
.expect("Push ipCidr failed: full");
271+
}
270272
});
271273
let driver = LoopbackDriverWapper(UnsafeCell::new(driver));
272274
Arc::new(LoopbackInterface {

user/apps/test_lo/src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ use std::net::UdpSocket;
22
use std::str;
33

44
fn main() -> std::io::Result<()> {
5-
let socket = UdpSocket::bind("127.0.0.1:34254")?;
6-
socket.connect("127.0.0.1:34254")?;
5+
let socket = UdpSocket::bind("10.0.2.15:34254")?;
6+
socket.connect("127.0.0.2:34255")?;
7+
8+
let listener = UdpSocket::bind("127.0.0.2:34255")?;
79

810
let msg = "Hello, loopback!";
911
socket.send(msg.as_bytes())?;
1012

1113
let mut buf = [0; 1024];
12-
let (amt, _src) = socket.recv_from(&mut buf)?;
14+
let (amt, _src) = listener.recv_from(&mut buf)?;
1315

1416
let received_msg = str::from_utf8(&buf[..amt]).expect("Could not read buffer as UTF-8");
1517

0 commit comments

Comments
 (0)