Now we can set the address via command line.
main.go
2. New endpoint-type
Add two new endpoint-type sock-server and sock-clientmain.go
sock-server
sock-server mode will listen a socket until someone connected, then continue following routines.
With this mode, we can easily connect slirpnetstack to other programs like user-mode-linux
Slirpnetstack will listen on $HOME/slirpnetstack.sock with protocol unixpacket
Setup user-mode-linux
Now we can move on user-mode-linux part:
# build user-mode-linux
cd ~
git clone --depth 1 https://github.com/KusakabeSi/UML-Config UML-Config
cd ~
git clone -b linux-5.10.y --single-branch --depth 1 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
cd linux
cp ~/UML-Config/5.10.config .config
make linux ARCH=um SUBARCH=x86_64 -j $(nproc)
# Run user-mode-linux
mkdir -p /tmp/uml
export TEMP=/tmp/uml
./linux \
root=/dev/root rootfstype=hostfs hostfs=/ \
con=fd:0,fd:1 \
vec0:transport=bess,dst=$HOME/slirpnetstack.sock,depth=128,gro=1 \
rw mem=64M init=/bin/bash quiet
# Now we should be in the user-mode-linux shell, setup the network vec0
ip addr add 192.168.42.2/24 dev vec0
ip link set dev vec0 address 02:42:ac:10:00:03
ip link set vec0 up
ip route add default via 192.168.42.1
# Check network, should output some html
wget -O- http://www.google.com
sock-client
sock-client mode will connect to somewhere by gosocket
3. Endpoint close detection
Now, if the endpoint closed(fd closed or tap device removed by system admin), our program will also exit
main.go
4. IPPortRangeSlice alias
add alias all for IPPortRangeSlice, it ,means udp://0.0.0.0/0:0-65535,udp://[::]/0:0-65535,tcp://0.0.0.0/0:0-65535,tcp://[::]/0:0-65535addr.go
So that we can use all instead of a long string to allow all connection
Although golang has backwards compatibility, but gvisor@v0.0.0-20201204040109-0ba39926c86f preventing it compile at golang 1.17 explicitly.
So I upgrade it to gvisor@v0.0.0-20211008224438-0927c63f8ea7 to make this slirpnetstack compatible with golang 1.17.
If there is any problem with it, just revert the commit 0b88429feda6d8c7d6a181a160c2c577437d7a54.
Four new features.
1. Customizable address
Now we can set the address via command line.
main.go
2. New endpoint-type
Add two new endpoint-type
sock-server
andsock-client
main.go
sock-server
sock-server mode will listen a socket until someone connected, then continue following routines. With this mode, we can easily connect slirpnetstack to other programs like user-mode-linux
Setup slirpnetstack
Slirpnetstack will listen on
$HOME/slirpnetstack.sock
with protocolunixpacket
Setup user-mode-linux
Now we can move on user-mode-linux part:
sock-client
sock-client mode will connect to somewhere by gosocket
3. Endpoint close detection
Now, if the endpoint closed(fd closed or tap device removed by system admin), our program will also exit
main.go
4. IPPortRangeSlice alias
add alias
all
for IPPortRangeSlice, it ,meansudp://0.0.0.0/0:0-65535,udp://[::]/0:0-65535,tcp://0.0.0.0/0:0-65535,tcp://[::]/0:0-65535
addr.go
So that we can use
all
instead of a long string to allow all connectionSupport go1.17
Although golang has backwards compatibility, but gvisor@v0.0.0-20201204040109-0ba39926c86f preventing it compile at golang 1.17 explicitly.
So I upgrade it to gvisor@v0.0.0-20211008224438-0927c63f8ea7 to make this slirpnetstack compatible with golang 1.17.
If there is any problem with it, just revert the commit 0b88429feda6d8c7d6a181a160c2c577437d7a54.