-
Notifications
You must be signed in to change notification settings - Fork 51
/
constants.go
171 lines (134 loc) · 4.26 KB
/
constants.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
package packet
const (
// minIPPacketLen is the min ip packet size for TCP packet
minTCPIPPacketLen = 20
// minIPPacketLen is the min ip packet size for UDP packet
minUDPIPPacketLen = 8
// minIPHdrSize
minIPv4HdrSize = 20
)
// IP Header field position constants
const (
// ipHdrLenPos is location of IP (entire packet) length
ipv4HdrLenPos = 0
// ipLengthPos is location of IP (entire packet) length
ipv4LengthPos = 2
// ipIDPos is location of IP Identifier
ipv4IDPos = 4
// ipProtoPos is the location of the IP Protocol
ipv4ProtoPos = 9
// ipChecksumPos is location of IP checksum
ipv4ChecksumPos = 10
// ipSourceAddrPos is location of source IP address
ipv4SourceAddrPos = 12
// ipDestAddrPos is location of destination IP address
ipv4DestAddrPos = 16
)
const (
// ipv6HeaderLen is the length of the ipv6 header
ipv6HeaderLen = 40
// ipv6PayloadLenPos is the position in the buffer where the size of the payload is stored
ipv6PayloadLenPos = 4
// ipv6ProtoPos is the position in the buffer where the protocol(tcp/udp) is stored
ipv6ProtoPos = 6
// ipv6SourceAddrPos is the position in the buffer where ipv6 source address is stored
ipv6SourceAddrPos = 8
// ipv6DestAddrPos is the position in the buffer where ipv6 dest address is stored
ipv6DestAddrPos = 24
)
// IP Protocol numbers
const (
// IPProtocolTCP defines the constant for TCP protocol number
IPProtocolTCP = 6
// IPProtocolUDP defines the constant for UDP protocol number
IPProtocolUDP = 17
// IPProtocolICMP defines the constants for ICMP protocol number
IPProtocolICMP = 1
)
// IP Header masks
const (
ipv4HdrLenMask = 0x0F
ipv4ProtoMask = 0xF0
)
// TCP Header field position constants
const (
// tcpSourcePortPos is the location of source port
tcpSourcePortPos = 0
// tcpDestPortPos is the location of destination port
tcpDestPortPos = 2
// tcpSeqPos is the location of seq
tcpSeqPos = 4
// tcpAckPos is the location of seq
tcpAckPos = 8
// tcpDataOffsetPos is the location of the TCP data offset
tcpDataOffsetPos = 12
//tcpFlagsOfsetPos is the location of the TCP flags
tcpFlagsOffsetPos = 13
// TCPChecksumPos is the location of TCP checksum
tcpChecksumPos = 16
)
// TCP Header masks
const (
// tcpDataOffsetMask is a mask for TCP data offset field
tcpDataOffsetMask = 0xF0
// TCPSynMask is a mask for the TCP Syn flags
TCPSynMask = 0x2
// TCPSynAckMask mask idenitifies a TCP SYN-ACK packet
TCPSynAckMask = 0x12
// TCPRstMask mask that identifies RST packets
TCPRstMask = 0x4
// TCPAckMask mask that identifies ACK packets
TCPAckMask = 0x10
// TCPFinMask mask that identifies FIN packets
TCPFinMask = 0x1
// TCPPshMask = 0x8 mask that identifies PSH packets
TCPPshMask = 0x8
)
// TCP Options Related constants
const (
// TCPAuthenticationOption is the option number will be using
TCPAuthenticationOption = uint8(34)
// TCPMssOption is the type for MSS option
TCPMssOption = uint8(2)
// TCPMssOptionLen is the type for MSS option
TCPMssOptionLen = uint8(4)
)
// UDP related constants.
const (
// udpSourcePortPos is the location of source port
udpSourcePortPos = 0
// udpDestPortPos is the location of destination port
udpDestPortPos = 2
// UDPLengthPos is the location of UDP length
udpLengthPos = 4
// UDPChecksumPos is the location of UDP checksum
udpChecksumPos = 6
// UDPDataPos is the location of UDP data
UDPDataPos = 8
// UDPSynMask is a mask for the UDP Syn flags
UDPSynMask = 0x10
// UDPSynAckMask mask idenitifies a UDP SYN-ACK packet
UDPSynAckMask = 0x20
// UDPAckMask mask that identifies ACK packets.
UDPAckMask = 0x30
// UDPFinAckMask mask that identifies the FinAck packets
UDPFinAckMask = 0x40
// UDPDataPacket is a simple data packet
UDPDataPacket = 0x80
// UDPPacketMask identifies type of UDP packet.
UDPPacketMask = 0xF0
)
const (
// UDPAuthMarker is 18 byte Aporeto signature for UDP
UDPAuthMarker = "n30njxq7bmiwr6dtxq"
// UDPAuthMarkerLen is the length of UDP marker.
UDPAuthMarkerLen = 18
// UDPSignatureLen is the length of signature on UDP control packet.
UDPSignatureLen = 20
// UDPAuthMarkerOffset is the beginning of UDPAuthMarker
udpAuthMarkerOffset = 10
// UDPSignatureEnd is the end of UDPSignature.
udpSignatureEnd = UDPDataPos + UDPSignatureLen
// UDPJwtTokenOffset is beginning of Jwt Token.
udpJwtTokenOffset = 28
)