container2wasm icon indicating copy to clipboard operation
container2wasm copied to clipboard

internal network communication

Open giper45 opened this issue 2 months ago • 2 comments

Hi, thank for the awesome project. I was asking if it is possible to have an internal network communication between two wasm modules. I was trying to achieve this: Wasm 1:

 $ c2w-net --invoke alpine-base.wasm --net=socket 
waiting for NW initialization
/ # ^[[23;5R ip a
 ip a
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 02:00:00:00:00:01 brd ff:ff:ff:ff:ff:ff
    inet 192.168.127.3/24 brd 192.168.127.255 scope global eth0
       valid_lft forever preferred_lft forever
/ # nc -lnvp 9999
nc -lnvp 9999
Listening on 0.0.0.0 9999

Module two:

 $ c2w-net --invoke --wasi-addr=127.0.0.1:1235 --mac 02:00:00:00:00:02  alpine-base.wasm  --net=socket
waiting for NW initialization
ip a/ # ^[[11;9R
ip a
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 02:00:00:00:00:01 brd ff:ff:ff:ff:ff:ff
    inet 192.168.127.2/24 brd 192.168.127.255 scope global eth0
       valid_lft forever preferred_lft forever

/ # ^[[11;5Rnc 192.168.127.3 9999
nc 192.168.127.3 9999


it seems that modules take ip address in the 192.168.127.0/24 network, different mac addresses, but no able to communicate. Do you have any suggestion about this?

Thank you!

giper45 avatar Oct 17 '25 04:10 giper45

@giper45 Hi, thanks for trying this.

192.168.127.0/24 network

This is a virtual network created using gvisor-tap-vsock library.

https://github.com/container2wasm/container2wasm/blob/255b65008ab07b7981c5462046c30d7b891f1adc/cmd/c2w-net/main.go#L81

As of now, multiple c2w-net invocations don't connect each other's network so these modules can't communicate each other. One of the solutions would be to modify c2w-net to spawn those modules from the same c2w-net process with connecting them into a single virtual network using the AcceptQemu mothod. https://github.com/container2wasm/container2wasm/blob/255b65008ab07b7981c5462046c30d7b891f1adc/cmd/c2w-net/main.go#L102

ktock avatar Oct 17 '25 05:10 ktock

Thank you @ktock, I supposed was related to the gvisor-tap. I am looking for studying the library, thank you very much!

giper45 avatar Oct 17 '25 09:10 giper45