/
passer.go
48 lines (39 loc) · 1.05 KB
/
passer.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: Apache-2.0
// Copyright 2018 Authors of Cilium
package testparsers
import (
. "github.com/cilium/cilium/proxylib/proxylib"
log "github.com/sirupsen/logrus"
)
type PasserParserFactory struct{}
func init() {
log.Debug("init(): Registering PasserParserFactory")
RegisterParserFactory("test.passer", &PasserParserFactory{})
}
type PasserParser struct{}
func (p *PasserParserFactory) Create(connection *Connection) interface{} {
// Reject invalid policy name for testing purposes
if connection.PolicyName == "invalid-policy" {
return nil
}
log.Debugf("PasserParserFactory: Create: %v", connection)
return &PasserParser{}
}
//
// This simply passes all data in either direction.
//
func (p *PasserParser) OnData(reply, endStream bool, data [][]byte) (OpType, int) {
n_bytes := 0
for _, s := range data {
n_bytes += len(s)
}
if n_bytes == 0 {
return NOP, 0
}
if !reply {
log.Debugf("PasserParser: Request: %d bytes", n_bytes)
} else {
log.Debugf("PasserParser: Response: %d bytes", n_bytes)
}
return PASS, n_bytes
}