github.com/aporeto-inc/trireme-lib@v10.358.0+incompatible/controller/pkg/packet/constants.go (about)

     1  package packet
     2  
     3  const (
     4  	// minIPPacketLen is the min ip packet size for TCP packet
     5  	minTCPIPPacketLen = 20
     6  
     7  	// minIPPacketLen is the min ip packet size for UDP packet
     8  	minUDPIPPacketLen = 8
     9  
    10  	// minICMPPacketLen is the min ip packet size for ICMP packet
    11  	minICMPIPPacketLen = 8
    12  
    13  	// minIPHdrSize
    14  	minIPv4HdrSize = 20
    15  
    16  	// minTCPHeaderLen is the min TCP header length
    17  	minTCPHeaderLen = 20
    18  )
    19  
    20  // IP Header field position constants
    21  const (
    22  	// ipHdrLenPos is location of IP (entire packet) length
    23  	ipv4HdrLenPos = 0
    24  
    25  	// ipLengthPos is location of IP (entire packet) length
    26  	ipv4LengthPos = 2
    27  
    28  	// ipIDPos is location of IP Identifier
    29  	ipv4IDPos = 4
    30  
    31  	// ipProtoPos is the location of the IP Protocol
    32  	ipv4ProtoPos = 9
    33  
    34  	// ipChecksumPos is location of IP checksum
    35  	ipv4ChecksumPos = 10
    36  
    37  	// ipSourceAddrPos is location of source IP address
    38  	ipv4SourceAddrPos = 12
    39  
    40  	// ipDestAddrPos is location of destination IP address
    41  	ipv4DestAddrPos = 16
    42  )
    43  
    44  const (
    45  	// ipv6HeaderLen is the length of the ipv6 header
    46  	ipv6HeaderLen = 40
    47  
    48  	// ipv6VersionPos is the position in the buffer where the version is stored
    49  	ipv6VersionPos = 0
    50  
    51  	// ipv6PayloadLenPos is the position in the buffer where the size of the payload is stored
    52  	ipv6PayloadLenPos = 4
    53  
    54  	// ipv6ProtoPos is the position in the buffer where the protocol(tcp/udp) is stored
    55  	ipv6ProtoPos = 6
    56  
    57  	// ipv6SourceAddrPos is the position in the buffer where ipv6 source address is stored
    58  	ipv6SourceAddrPos = 8
    59  
    60  	// ipv6DestAddrPos is the position in the buffer where ipv6 dest address is stored
    61  	ipv6DestAddrPos = 24
    62  )
    63  
    64  // IP Protocol numbers
    65  const (
    66  	// IPProtocolTCP defines the constant for TCP protocol number
    67  	IPProtocolTCP = 6
    68  
    69  	// IPProtocolUDP defines the constant for UDP protocol number
    70  	IPProtocolUDP = 17
    71  
    72  	// IPProtocolICMP defines the constants for ICMP protocol number
    73  	IPProtocolICMP = 1
    74  )
    75  
    76  // IP Header masks
    77  const (
    78  	ipv4HdrLenMask = 0x0F
    79  	ipv4ProtoMask  = 0xF0
    80  )
    81  
    82  // TCP Header field position constants
    83  const (
    84  	// tcpSourcePortPos is the location of source port
    85  	tcpSourcePortPos = 0
    86  
    87  	// tcpDestPortPos is the location of destination port
    88  	tcpDestPortPos = 2
    89  
    90  	// tcpSeqPos is the location of seq
    91  	tcpSeqPos = 4
    92  
    93  	// tcpAckPos is the location of seq
    94  	tcpAckPos = 8
    95  
    96  	// tcpDataOffsetPos is the location of the TCP data offset
    97  	tcpDataOffsetPos = 12
    98  
    99  	//tcpFlagsOfsetPos is the location of the TCP flags
   100  	tcpFlagsOffsetPos = 13
   101  
   102  	// TCPChecksumPos is the location of TCP checksum
   103  	tcpChecksumPos = 16
   104  )
   105  
   106  // TCP Header masks
   107  const (
   108  	// tcpDataOffsetMask is a mask for TCP data offset field
   109  	tcpDataOffsetMask = 0xF0
   110  
   111  	// TCPSynMask is a mask for the TCP Syn flags
   112  	TCPSynMask = 0x2
   113  
   114  	// TCPSynAckMask  mask idenitifies a TCP SYN-ACK packet
   115  	TCPSynAckMask = 0x12
   116  
   117  	// TCPRstMask mask that identifies RST packets
   118  	TCPRstMask = 0x4
   119  
   120  	// TCPAckMask mask that identifies ACK packets
   121  	TCPAckMask = 0x10
   122  
   123  	// TCPFinMask mask that identifies FIN packets
   124  	TCPFinMask = 0x1
   125  
   126  	// TCPPshMask = 0x8 mask that identifies PSH packets
   127  	TCPPshMask = 0x8
   128  )
   129  
   130  // TCP Options Related constants
   131  const (
   132  	// TCPAuthenticationOption is the option number will be using
   133  	TCPAuthenticationOption = uint8(34)
   134  
   135  	// TCPMssOption is the type for MSS option
   136  	TCPMssOption = uint8(2)
   137  
   138  	// TCPMssOptionLen is the type for MSS option
   139  	TCPMssOptionLen = uint8(4)
   140  )
   141  
   142  // UDP related constants.
   143  const (
   144  	// udpSourcePortPos is the location of source port
   145  	udpSourcePortPos = 0
   146  	// udpDestPortPos is the location of destination port
   147  	udpDestPortPos = 2
   148  	// UDPLengthPos is the location of UDP length
   149  	udpLengthPos = 4
   150  	// UDPChecksumPos is the location of UDP checksum
   151  	udpChecksumPos = 6
   152  	// UDPDataPos is the location of UDP data
   153  	UDPDataPos = 8
   154  	// UDPSynMask is a mask for the UDP Syn flags
   155  	UDPSynMask = 0x10
   156  	// UDPSynAckMask  mask idenitifies a UDP SYN-ACK packet
   157  	UDPSynAckMask = 0x20
   158  	// UDPAckMask mask that identifies ACK packets.
   159  	UDPAckMask = 0x30
   160  	// UDPFinAckMask mask that identifies the FinAck packets
   161  	UDPFinAckMask = 0x40
   162  	// UDPPolicyRejectMask mask that identifies a policy reject info from the remote end
   163  	UDPPolicyRejectMask = 0x50
   164  	// UDPDataPacket is a simple data packet
   165  	UDPDataPacket = 0x80
   166  	// UDPPacketMask identifies type of UDP packet.
   167  	UDPPacketMask = 0xF0
   168  )
   169  
   170  const (
   171  	// UDPAuthMarker is 18 byte Aporeto signature for UDP
   172  	UDPAuthMarker = "n30njxq7bmiwr6dtxq"
   173  	// UDPAuthMarkerLen is the length of UDP marker.
   174  	UDPAuthMarkerLen = 18
   175  	// UDPSignatureLen is the length of signature on UDP control packet.
   176  	UDPSignatureLen = 20
   177  	// UDPAuthMarkerOffset is the beginning of UDPAuthMarker
   178  	udpAuthMarkerOffset = 10
   179  	// UDPSignatureEnd is the end of UDPSignature.
   180  	udpSignatureEnd = UDPDataPos + UDPSignatureLen
   181  )
   182  
   183  const (
   184  	// UDPAporetoOption is the option kind for Aporeto option
   185  	UDPAporetoOption = uint8(34)
   186  	// UDPAporetoOptionLengthFirstByte is the first if length is greater than 255
   187  	UDPAporetoOptionLengthFirstByte = uint8(0xff)
   188  	// UDPAporetoOptionShortLength is the length of the option header if payload length is less than UDPAporetoOptionLengthFirstByte
   189  	UDPAporetoOptionShortLength = 2
   190  	// UDPAporetoOptionLongLength is the length of the option header if payload length is greater than UDPAporetoOptionLengthFirstByte
   191  	UDPAporetoOptionLongLength = 6
   192  )