简体   繁体   English

如何将 TCP 端口/套接字路由到 QEMU 内部?

[英]How to route TCP ports/sockets internal to QEMU?

I am attempting to run the FreeRTOS+TCP demo (release 10.1.1):我正在尝试运行FreeRTOS+TCP 演示(版本 10.1.1):

The code is written for the Windows Simulator, but I am attempting to target the Xilinx Zynq, emulated by QEMU (version 4.2.0).该代码是为 Windows 模拟器编写的,但我试图以 Xilinx Zynq 为目标,由QEMU (4.2.0 版)模拟。 The host machine is Ubuntu 16.04.主机为 Ubuntu 16.04。 There exists a Network Interface port for the TCP part of FreeRTOS+TCP , so this should be possible. FreeRTOS+TCPTCP部分存在一个网络接口端口,所以这应该是可能的。

One of the obvious modifications to the demo is changing the way messages are printed, and removing calls to the Windows Sleep function.对演示的明显修改之一是更改消息的打印方式,并删除对 Windows Sleep function 的调用。 Also, I am using ARM semihosting to view the output of the print statements.另外,我正在使用ARM 半主机来查看打印语句的 output。

Besides these changes, what changes will I need to make to the command line call?除了这些更改之外,我还需要对命令行调用进行哪些更改? The demo creates a TCP echo server and client.该演示创建了一个 TCP 回显服务器和客户端。 If these are tied together, then no traffic should need to go to the host, right?如果这些都捆绑在一起,那么应该没有流量需要到 go 到主机,对吧? Is there anything special I would need to do to get this to work?有什么特别的事情我需要做才能让它工作吗? I don't have a ton of experience with networking.我没有大量的网络经验。

Since this is technically a baremetal application, CLI options like -nic user,hostfwd=tcp::5022-:22 give the warning qemu-system-arm: warning: nic cadence_gem.1 has no peer.因为这在技术上是一个裸机应用程序,所以像-nic user,hostfwd=tcp::5022-:22这样的 CLI 选项会给出警告qemu-system-arm: warning: nic cadence_gem.1 has no peer. (Found at How to replace `qemu-system -redir` command argument? ). (在如何替换 `qemu-system -redir` 命令参数? )。

If I ever did want to send traffic between the host and guest (like having a ncat echo server, instead of in FreeRTOS), how would I go about doing that?如果我确实想在主机和来宾之间发送流量(比如拥有一个ncat回显服务器,而不是在 FreeRTOS 中),我将如何 go 这样做?

Here is a related problem, with no solution: Running LWIP TCP/IP Stack with QEMU这是一个相关的问题,没有解决方案: Running LWIP TCP/IP Stack with QEMU

Current command line arguments:当前命令行 arguments:

qemu-system-arm -semihosting --semihosting-config enable=on,target=native -nographic -serial mon:stdio -machine xilinx-zynq-a9 -m 512M -cpu cortex-a9 -nic user,hostfwd=tcp::12346-:7 -kernel build/rtos_demo_tcp/rtos_demo_tcp.elf

Current output (I enabled extra debug messages):当前 output(我启用了额外的调试消息):

qemu-system-arm: warning: nic cadence_gem.1 has no peer
Seed for randomiser: 1591112953
Random numbers: 00001294 00001925 000022D0 00005CC3
FreeRTOS_IPInit
vTaskStartScheduler
prvIPTask started
Network buffers: 30 lowest 30


IP Address: 10.2.118.223
Subnet Mask: 255.255.255.0
Gateway Address: 10.2.118.1
DNS Server Address: 208.67.222.222


Socket 7 -> 0ip:0 State eCLOSED->eTCP_LISTEN

Then this next bit repeats indefinitely, with a different socket number each time:然后下一位无限重复,每次使用不同的套接字号:

FreeRTOS_connect: 14207 to a0276dfip:7
Socket 14207 -> a0276dfip:7 State eCLOSED->eCONNECT_SYN
ARP for a0276dfip (using a0276dfip): rc=0 00:00:00 00:00:00
Network buffers: 30 lowest 29
Connect[a0276dfip:7]: next timeout 1: 500 ms
ARP for a0276dfip (using a0276dfip): rc=0 00:00:00 00:00:00
Connect[a0276dfip:7]: next timeout 2: 500 ms
ARP for a0276dfip (using a0276dfip): rc=0 00:00:00 00:00:00
Connect[a0276dfip:7]: next timeout 3: 500 ms
Connect: giving up a0276dfip:7
Socket 14207 -> a0276dfip:7 State eCONNECT_SYN->eCLOSE_WAIT
FreeRTOS_closesocket[14207 to a0276dfip:7]: buffers 30 socks 1

Summary: How do I change the way I am calling QEMU so that the TCP client and server can connect to each other?总结:如何改变我调用QEMU的方式,让TCP客户端和服务器可以互相连接?

I would recommend trying out all of the options enumerated in the qemu networking guide :我建议尝试qemu 网络指南中列举的所有选项:
- SLIRP : -netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9 - SLIRP : -netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9
- TAP : -netdev tap,id=mynet0 - TAP-netdev tap,id=mynet0
- SOCKET : -netdev socket,id=mynet0,listen=:1234 and -netdev socket,id=mynet0,connect=:1234 - SOCKET-netdev socket,id=mynet0,listen=:1234-netdev socket,id=mynet0,connect=:1234

And there is much more in the guide.指南中还有更多内容。 Something you might also consider is that it might be difficult for you to port-forward directly from the VM you care about to the host, and it might be easier to connect that VM to another VM and port-forward from that second VM to your host.您可能还考虑的是,您可能很难直接从您关心的 VM 端口转发到主机,并且可能更容易将该 VM 连接到另一个 VM并将第二个 VM 端口转发到您的主持人。

Sounds a bit odd, but that's something I've needed to do before.听起来有点奇怪,但这是我以前需要做的事情。 To talk between two VM's I find sockets to be the best method.在两个 VM 之间进行交谈,我发现sockets是最好的方法。 They work sort of like a "virtual crossover cable".它们的工作方式有点像“虚拟交叉电缆”。

This VM to VM method would allow you to simply have to set up corresponding static IP's and subnets on each VM and then ncat 's would work between them.这种 VM 到 VM 方法将允许您只需要在每个 VM 上设置相应的 static IP 和子网,然后ncat就可以在它们之间工作。 Do away with all of the complexity of a DHCP server and any sort of port-forwarding.消除 DHCP 服务器的所有复杂性和任何类型的端口转发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM