/
tracerecord.go
187 lines (135 loc) · 5.75 KB
/
tracerecord.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package gaia
import (
"fmt"
"time"
"github.com/mitchellh/copystructure"
"go.aporeto.io/elemental"
)
// TraceRecord represents the model of a tracerecord
type TraceRecord struct {
// The time to live (TTL) value of the packet.
TTL int `json:"TTL" msgpack:"TTL" bson:"ttl" mapstructure:"TTL,omitempty"`
// Chain that the trace was collected from.
Chain string `json:"chain" msgpack:"chain" bson:"chain" mapstructure:"chain,omitempty"`
// The destination IP.
DestinationIP string `json:"destinationIP" msgpack:"destinationIP" bson:"destinationip" mapstructure:"destinationIP,omitempty"`
// The destination interface of the packet.
DestinationInterface string `json:"destinationInterface" msgpack:"destinationInterface" bson:"destinationinterface" mapstructure:"destinationInterface,omitempty"`
// The destination UPD or TCP port of the packet.
DestinationPort int `json:"destinationPort" msgpack:"destinationPort" bson:"destinationport" mapstructure:"destinationPort,omitempty"`
// Length of the observed packet.
Length int `json:"length" msgpack:"length" bson:"length" mapstructure:"length,omitempty"`
// The IP packet header ID.
PacketID int `json:"packetID" msgpack:"packetID" bson:"packetid" mapstructure:"packetID,omitempty"`
// The protocol of the packet.
Protocol int `json:"protocol" msgpack:"protocol" bson:"protocol" mapstructure:"protocol,omitempty"`
// Priority index of the iptables entry that was hit.
RuleID int `json:"ruleID" msgpack:"ruleID" bson:"ruleid" mapstructure:"ruleID,omitempty"`
// Source IP of the packet.
SourceIP string `json:"sourceIP" msgpack:"sourceIP" bson:"sourceip" mapstructure:"sourceIP,omitempty"`
// Source interface of the packet.
SourceInterface string `json:"sourceInterface" msgpack:"sourceInterface" bson:"sourceinterface" mapstructure:"sourceInterface,omitempty"`
// Source TCP or UDP port of the packet.
SourcePort int `json:"sourcePort" msgpack:"sourcePort" bson:"sourceport" mapstructure:"sourcePort,omitempty"`
// The iptables name that the trace collected.
TableName string `json:"tableName" msgpack:"tableName" bson:"tablename" mapstructure:"tableName,omitempty"`
// The time-date stamp of the report.
Timestamp time.Time `json:"timestamp" msgpack:"timestamp" bson:"-" mapstructure:"timestamp,omitempty"`
ModelVersion int `json:"-" msgpack:"-" bson:"_modelversion"`
}
// NewTraceRecord returns a new *TraceRecord
func NewTraceRecord() *TraceRecord {
return &TraceRecord{
ModelVersion: 1,
}
}
// BleveType implements the bleve.Classifier Interface.
func (o *TraceRecord) BleveType() string {
return "tracerecord"
}
// DeepCopy returns a deep copy if the TraceRecord.
func (o *TraceRecord) DeepCopy() *TraceRecord {
if o == nil {
return nil
}
out := &TraceRecord{}
o.DeepCopyInto(out)
return out
}
// DeepCopyInto copies the receiver into the given *TraceRecord.
func (o *TraceRecord) DeepCopyInto(out *TraceRecord) {
target, err := copystructure.Copy(o)
if err != nil {
panic(fmt.Sprintf("Unable to deepcopy TraceRecord: %s", err))
}
*out = *target.(*TraceRecord)
}
// Validate valides the current information stored into the structure.
func (o *TraceRecord) Validate() error {
errors := elemental.Errors{}
requiredErrors := elemental.Errors{}
if err := elemental.ValidateRequiredInt("TTL", o.TTL); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if err := elemental.ValidateMaximumInt("TTL", o.TTL, int(255), false); err != nil {
errors = errors.Append(err)
}
if err := elemental.ValidateRequiredString("chain", o.Chain); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if err := elemental.ValidateRequiredString("destinationIP", o.DestinationIP); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if err := elemental.ValidateRequiredInt("destinationPort", o.DestinationPort); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if err := elemental.ValidateMaximumInt("destinationPort", o.DestinationPort, int(65536), false); err != nil {
errors = errors.Append(err)
}
if err := elemental.ValidateMinimumInt("destinationPort", o.DestinationPort, int(1), false); err != nil {
errors = errors.Append(err)
}
if err := elemental.ValidateRequiredInt("length", o.Length); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if err := elemental.ValidateMaximumInt("length", o.Length, int(65536), false); err != nil {
errors = errors.Append(err)
}
if err := elemental.ValidateRequiredInt("packetID", o.PacketID); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if err := elemental.ValidateRequiredInt("protocol", o.Protocol); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if err := elemental.ValidateMaximumInt("protocol", o.Protocol, int(65536), false); err != nil {
errors = errors.Append(err)
}
if err := elemental.ValidateRequiredInt("ruleID", o.RuleID); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if err := elemental.ValidateRequiredString("sourceIP", o.SourceIP); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if err := elemental.ValidateRequiredInt("sourcePort", o.SourcePort); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if err := elemental.ValidateMaximumInt("sourcePort", o.SourcePort, int(65536), false); err != nil {
errors = errors.Append(err)
}
if err := elemental.ValidateMinimumInt("sourcePort", o.SourcePort, int(1), false); err != nil {
errors = errors.Append(err)
}
if err := elemental.ValidateRequiredString("tableName", o.TableName); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if err := elemental.ValidateRequiredTime("timestamp", o.Timestamp); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if len(requiredErrors) > 0 {
return requiredErrors
}
if len(errors) > 0 {
return errors
}
return nil
}