-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
100 lines (85 loc) · 1.89 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"flag"
"github.com/RobinUS2/teecp/forwarder"
"log"
)
var device *string
var bpfFilter *string
var verbose *bool
var layerStr *string
var outputTcp *string
var statsPrinter *bool
var statsHealthCheck *bool
var prefixHeader *bool
func init() {
{
str := ""
device = &str
}
flag.StringVar(device, "device", "", "device")
{
str := ""
bpfFilter = &str
}
flag.StringVar(bpfFilter, "bpf", "icmp", "BPF filter (e.g. tcp port 1234)")
{
str := ""
layerStr = &str
}
flag.StringVar(layerStr, "layers", forwarder.DefaultLayers, "layers comma separated - 44 = TCP, 45 = UDP https://github.com/google/gopacket/blob/master/layers/layertypes.go")
{
str := ""
outputTcp = &str
}
flag.StringVar(outputTcp, "output-tcp", "", "TCP output configuration (e.g. your-host:1234")
{
b := false
verbose = &b
}
flag.BoolVar(verbose, "verbose", false, "verbose logging")
{
b := false
statsPrinter = &b
}
flag.BoolVar(statsPrinter, "stats", true, "print stats")
{
b := false
statsHealthCheck = &b
}
flag.BoolVar(statsHealthCheck, "health-check", true, "health check")
{
b := false
prefixHeader = &b
}
flag.BoolVar(prefixHeader, "prefix-header", false, "prefix header (include payload size, src, src port, dst, dst port)")
// parse
flag.Parse()
}
func main() {
opts := forwarder.NewOpts()
opts.Device = *device
opts.Output = "tcp" + forwarder.ConfSeparator + *outputTcp
opts.BpfFilter = *bpfFilter
opts.Verbose = *verbose
opts.StatsPrinter = *statsPrinter
opts.StatsHealthCheck = *statsHealthCheck
opts.PrefixHeader = *prefixHeader
opts.ParseLayers(*layerStr)
// prevent usage of non opts
unsetLocal()
// start
server := forwarder.NewServer(opts)
err := server.Start()
if err != nil {
log.Fatalf("failed to start: %s", err)
}
}
func unsetLocal() {
device = nil
bpfFilter = nil
layerStr = nil
outputTcp = nil
verbose = nil
statsPrinter = nil
}