Tomo-9925 / cnet

Controlling and logging communication of process in Docker container
2 stars 0 forks source link

remoteAddrが0000ポートであってもinodeを返すように #15

Closed masibw closed 3 years ago

masibw commented 3 years ago

タイトル通りです。このブランチの状態で想定通り通信ができることを確認しました。

とりあえず動くもののこれでデグレしてないかは気になります

動作確認

nginx_testというコンテナを建てた状態で以下のことを行いました policy.ymlには以下のように記載しています.

policies:
- container:
        name: "nginx_test"
    communications:
        - processes:
                - path: "/usr/sbin/nginx"
            sockets:
                - protocol: "tcp"
                    local_port: 80
                - protocol: "tcp"
                    local_port: 443

手元のPC(VPN接続済み)からnginx_test上で動いているNginxへcurl

~/cnet (feature/get_inode_when_remote0000) [127]> curl 略:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

サーバーの出力ログ(一時的なprintlnとかも出力されてしまっていますが..)

~/g/s/g/T/cnet (feature/fix_socket_equal)> sudo ./main
[sudo] password for k624125:
DEBU[2020-11-13T07:39:12Z] Cnet initialized                              containers="[0xc0003e8440]" logfile="<nil>" policies="[0xc0003ddc00]"
DEBU[2020-11-13T07:39:18Z] packet received                               packet="{PACKET: 64 bytes\n- Layer 1 (20 bytes) = IPv4\t{Contents=[..20..] Payload=[..44..] Version=4 IHL=5 TOS=0 Length=64 Id=0 Flags=DF FragOffset=0 TTL=62 Protocol=TCP Checksum=32161 SrcIP=10.1.9.3 DstIP=172.17.0.2 Options=[] Padding=[]}\n- Layer 2 (44 bytes) = TCP\t{Contents=[..44..] Payload=[] SrcPort=56692 DstPort=80(http) Seq=1543732441 Ack=0 DataOffset=11 FIN=false SYN=true RST=false PSH=false ACK=false URG=false ECE=true CWR=true NS=false Window=65535 Checksum=2364 Urgent=0 Options=[..8..] Padding=[0]}\n 0xc000434480}"
SearchInodeFromNetOfPid
in case 9-1 1923707440DEBU[2020-11-13T07:39:18Z] packet accepted                               container="&{11a664b1f62bd36d4817afeb8f4dd52d1fbfc9bd26c56691103cee3a6b24afe5 172.17.0.2 /nginx_test 19331}" process="&{19331 nginx /usr/sbin/nginx}" socket="&{TCP 172.17.0.2 10.1.9.3 80 56692}"
Dropping, unexpectedly due to no recv, idx=3601593578
DEBU[2020-11-13T07:39:19Z] packet received                               packet="{PACKET: 60 bytes\n- Layer 1 (20 bytes) = IPv4\t{Contents=[..20..] Payload=[..40..] Version=4 IHL=5 TOS=0 Length=60 Id=0 Flags=DF FragOffset=0 TTL=63 Protocol=TCP Checksum=31909 SrcIP=172.17.0.2 DstIP=10.1.9.3 Options=[] Padding=[]}\n- Layer 2 (40 bytes) = TCP\t{Contents=[..40..] Payload=[] SrcPort=80(http) DstPort=56692 Seq=2926252440 Ack=1543732442 DataOffset=10 FIN=false SYN=true RST=false PSH=false ACK=true URG=false ECE=true CWR=false NS=false Window=65160 Checksum=27565 Urgent=0 Options=[..5..] Padding=[]}\n 0xc000094540}"
SearchInodeFromNetOfPid
in case 9-1 1923707440DEBU[2020-11-13T07:39:19Z] packet accepted                               container="&{11a664b1f62bd36d4817afeb8f4dd52d1fbfc9bd26c56691103cee3a6b24afe5 172.17.0.2 /nginx_test 19331}" process="&{19331 nginx /usr/sbin/nginx}" socket="&{TCP 172.17.0.2 10.1.9.3 80 56692}"
DEBU[2020-11-13T07:39:19Z] packet received                               packet="{PACKET: 64 bytes\n- Layer 1 (20 bytes) = IPv4\t{Contents=[..20..] Payload=[..44..] Version=4 IHL=5 TOS=0 Length=64 Id=0 Flags=DF FragOffset=0 TTL=62 Protocol=TCP Checksum=32161 SrcIP=10.1.9.3 DstIP=172.17.0.2 Options=[] Padding=[]}\n- Layer 2 (44 bytes) = TCP\t{Contents=[..44..] Payload=[] SrcPort=56692 DstPort=80(http) Seq=1543732441 Ack=0 DataOffset=11 FIN=false SYN=true RST=false PSH=false ACK=false URG=false ECE=false CWR=false NS=false Window=65535 Checksum=1556 Urgent=0 Options=[..8..] Padding=[0]}\n 0xc000094660}"
SearchInodeFromNetOfPid
masibw commented 3 years ago

動作確認を追記しました