forked from SagerNet/sing-tun
-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathstack_mipstack_linux_test.go
More file actions
30 lines (26 loc) · 1.03 KB
/
Copy pathstack_mipstack_linux_test.go
File metadata and controls
30 lines (26 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//go:build linux
package tun
import (
"context"
"net/netip"
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestMipsLinuxGROMergesOutput(t *testing.T) {
file, err := os.CreateTemp(t.TempDir(), "tun-output")
require.NoError(t, err)
defer file.Close()
device := &NativeTun{tunFile: file, vnetHdr: true, tcpGROTable: newTCPGROTable(), udpGROTable: newUDPGROTable()}
s := &Mipstack{ctx: context.Background(), tun: device}
source, target := netip.MustParseAddr("8.8.8.8"), netip.MustParseAddr("198.18.0.2")
first := tcpPacket(source, target, 100, 200, 16, []byte("abcd"))
second := tcpPacket(source, target, 104, 200, 16, []byte("efgh"))
require.NoError(t, s.writePackets([][]byte{first, second}, 0))
data, err := os.ReadFile(file.Name())
require.NoError(t, err)
// A single virtio/IP/TCP header followed by both payloads proves that the
// batch survived the wrapper and had enough writable tailroom for GRO.
require.Len(t, data, virtioNetHdrLen+40+8)
require.Equal(t, "abcdefgh", string(data[virtioNetHdrLen+40:]))
}