Implementing TCP in Rust
https://www.youtube.com/watch?v=bzja9fQWzdA&list=PLqbS7AVVErFivDY3iKAQk3_VAm8SXwt1X
TCP性能評価システムDBSの構築
emulate a network inside of the user interface
https://scrapbox.io/files/62b7ad46fe13b7001d1137d0.png
https://scrapbox.io/files/62b7ad4a1888720020f63dd8.png
CAP_NET_ADMIN
code: zsh
Caused by:
process didn't exit successfully: /Users/wafuwafu13/Desktop/trust/target/release/build/tun-tap-37872de873711b12/build-script-build (exit status: 1)
--- stdout
TARGET = Some("aarch64-apple-darwin")
OPT_LEVEL = Some("3")
HOST = Some("aarch64-apple-darwin")
CC_aarch64-apple-darwin = None
CC_aarch64_apple_darwin = None
HOST_CC = None
CC = None
CFLAGS_aarch64-apple-darwin = None
CFLAGS_aarch64_apple_darwin = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("aes,crc,dit,dotprod,dpb,dpb2,fcma,fhm,flagm,fp16,frintts,jsconv,lor,lse,neon,paca,pacg,pan,pmuv3,ras,rcpc,rcpc2,rdm,sb,sha2,sha3,ssbs,vh")
running: "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-arch" "arm64" "-Wall" "-Wextra" "-o" "/Users/wafuwafu13/Desktop/trust/target/release/build/tun-tap-25adbd4aa26f021b/out/src/tuntap.o" "-c" "src/tuntap.c"
cargo:warning=src/tuntap.c:11:10: fatal error: 'linux/if.h' file not found
cargo:warning=#include <linux/if.h>
cargo:warning= ^~~~~~~~~~~~
cargo:warning=1 error generated.
exit status: 1
--- stderr
error occurred: Command "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-arch" "arm64" "-Wall" "-Wextra" "-o" "/Users/wafuwafu13/Desktop/trust/target/release/build/tun-tap-25adbd4aa26f021b/out/src/tuntap.o" "-c" "src/tuntap.c" with args "cc" did not execute successfully (status code exit status: 1).
code: zsh
$ sudo setcap cap_net_admin=eip ~/desktop/trust/target/release/trust
code: zsh
$ ~/desktop/trust/target/release/trust
code: zsh
$ ip addr
4: tun0: <POINTOPOINT,MULTICAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 500
link/none
code: zsh
$ sudo ip addr add 192.168.0.1/24 dev tun0
4: tun0: <POINTOPOINT,MULTICAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 500
link/none
inet 192.168.0.1/24 scope global tun0
valid_lft forever preferred_lft forever
code: zsh
$ sudo ip link set up dev tun0
$ ~/desktop/trust/target/release/trust
read 52 bytes: 0, 0, 86, dd, 60, 0, 0, 0, 0, 8, 3a, ff, fe, 80, 0, 0, 0, 0, 0, 0, d2, fa, cc, 61, 19, 32, 11, b8, ff, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 85, 0, b2, f0, 0, 0, 0, 0 code:zsh
$ sudo tshark -i tun0
Make sure the buffer is large enough. It is MTU of the interface (usually 1500, unless reconfigured) + 4 for the header in case that packet info is prepended, MTU + size of ethernet frame (38 bytes, unless VLan tags are enabled).
code: git
3.2 Frame format
----------------
If flag IFF_NO_PI is not set each frame format is::
Raw protocol(IP, IPv6, etc) frame.
0x86DD Internet Protocol Version 6 (IPv6)
0x0800 Internet Protocol version 4 (IPv4)
code: zsh
ping -I tun0 192.168.0.2
1 ICMP Internet Control Message
code:zsh
$ nc 192.168.0.2 80
192.168.0.1 -> 192.168.0.2 40b of protocol 6
Figure 6
CLOSED is fictional because it represents the state when there is no TCB, and therefore, no connection.
https://scrapbox.io/files/62c1140e3e2bf1001de725b1.png
Sequence Number: 32 bits
The sequence number of the first data octet in this segment (except
when SYN is present). If SYN is present the sequence number is the
initial sequence number (ISN) and the first data octet is ISN+1.
Acknowledgment Number: 32 bits
If the ACK control bit is set this field contains the value of the
next sequence number the sender of the segment is expecting to
receive. Once a connection is established this is always sent.
Before we can discuss very much about the operation of the TCP we need
to introduce some detailed terminology
p.25, p.27
https://scrapbox.io/files/62db51110cef3e0022c35844.png
p.36