func (f *DefaultConnFactory) Build(options ConnectionOptions) ConnectionInterface { conn := Connection{ packetCount: 0, ConnectionOptions: options, attackDetected: false, state: TCP_UNKNOWN, skipHijackDetectionCount: FIRST_FEW_PACKETS, clientNextSeq: types.InvalidSequence, serverNextSeq: types.InvalidSequence, ClientStreamRing: types.NewRing(options.MaxRingPackets), ServerStreamRing: types.NewRing(options.MaxRingPackets), clientFlow: &types.TcpIpFlow{}, serverFlow: &types.TcpIpFlow{}, } conn.ClientCoalesce = NewOrderedCoalesce(conn.AttackLogger, conn.clientFlow, conn.PageCache, conn.ClientStreamRing, conn.MaxBufferedPagesTotal, conn.MaxBufferedPagesPerConnection/2, conn.DetectCoalesceInjection) conn.ServerCoalesce = NewOrderedCoalesce(conn.AttackLogger, conn.serverFlow, conn.PageCache, conn.ServerStreamRing, conn.MaxBufferedPagesTotal, conn.MaxBufferedPagesPerConnection/2, conn.DetectCoalesceInjection) return &conn }
func TestGetRingSlicePanic3(t *testing.T) { defer func() { if r := recover(); r == nil { t.Error("failed to panic") t.Fail() } }() head := types.NewRing(3) head.Reassembly = &types.Reassembly{ Seq: types.Sequence(2), Bytes: []byte{1, 2, 3, 4, 5}, } tail := types.NewRing(3) tail.Reassembly = &types.Reassembly{ Seq: types.Sequence(2), Bytes: []byte{1, 2, 3, 4, 5}, } _ = getRingSlice(head, tail, 0, 6) }
func TestOrderedCoalesceUsedPages(t *testing.T) { maxBufferedPagesTotal := 1024 maxBufferedPagesPerFlow := 1024 streamRing := types.NewRing(40) PageCache := newPageCache() ipFlow, _ := gopacket.FlowFromEndpoints(layers.NewIPEndpoint(net.IPv4(1, 2, 3, 4)), layers.NewIPEndpoint(net.IPv4(2, 3, 4, 5))) tcpFlow, _ := gopacket.FlowFromEndpoints(layers.NewTCPPortEndpoint(layers.TCPPort(1)), layers.NewTCPPortEndpoint(layers.TCPPort(2))) flow := types.NewTcpIpFlowFromFlows(ipFlow, tcpFlow) var nextSeq types.Sequence = types.Sequence(1) coalesce := NewOrderedCoalesce(nil, flow, PageCache, streamRing, maxBufferedPagesTotal, maxBufferedPagesPerFlow, false) ip := layers.IPv4{ SrcIP: net.IP{1, 2, 3, 4}, DstIP: net.IP{2, 3, 4, 5}, Version: 4, TTL: 64, Protocol: layers.IPProtocolTCP, } tcp := layers.TCP{ Seq: 3, SYN: false, SrcPort: 1, DstPort: 2, } p := types.PacketManifest{ Timestamp: time.Now(), Flow: flow, IP: ip, TCP: tcp, Payload: []byte{1, 2, 3, 4, 5, 6, 7}, } coalesce.insert(&p, nextSeq) if coalesce.PageCache.used != 1 { t.Errorf("coalesce.pager.Used() not equal to 1\n") t.Fail() } coalesce.Close() }
func TestGetStartSequence(t *testing.T) { var start types.Sequence = 4 var head *types.Ring = types.NewRing(10) head.Reassembly = &types.Reassembly{ Seq: 3, Bytes: []byte{1, 2, 3, 4, 5, 6, 7}, } startSeq := getStartSequence(head, start) if startSeq.Difference(start) != 0 { t.Errorf("startSeq %d != start %d\n", startSeq, start) t.Fail() } start = 2 startSeq = getStartSequence(head, start) if startSeq != start.Add(1) { t.Errorf("startSeq %d != start %d\n", startSeq, start.Add(1)) t.Fail() } }