Documentation ¶
Overview ¶
Package header provides the implementation of the encoding and decoding of network protocol headers.
Index ¶
- Constants
- func AddTCPOptionPadding(options []byte, offset int) int
- func Checksum(buf []byte, initial uint16) uint16
- func ChecksumCombine(a, b uint16) uint16
- func EncodeMSSOption(mss uint32, b []byte) int
- func EncodeNOP(b []byte) int
- func EncodeSACKBlocks(sackBlocks []SACKBlock, b []byte) int
- func EncodeSACKPermittedOption(b []byte) int
- func EncodeTSOption(tsVal, tsEcr uint32, b []byte) int
- func EncodeWSOption(ws int, b []byte) int
- func IPVersion(b []byte) int
- func IsV4MappedAddress(addr tcpip.Address) bool
- func IsV4MulticastAddress(addr tcpip.Address) bool
- func IsV6MulticastAddress(addr tcpip.Address) bool
- func LinkLocalAddr(linkAddr tcpip.LinkAddress) tcpip.Address
- func PseudoHeaderChecksum(protocol tcpip.TransportProtocolNumber, srcAddr tcpip.Address, ...) uint16
- func SolicitedNodeAddr(addr tcpip.Address) tcpip.Address
- type ARP
- type ARPOp
- type DNS
- func (d DNS) GetANCount() uint16
- func (d DNS) GetARCount() uint16
- func (d DNS) GetAnswer() *[]DNSResource
- func (d DNS) GetDomainLen() (rs int)
- func (d DNS) GetId() uint16
- func (d DNS) GetNSCount() uint16
- func (d DNS) GetQDCount() uint16
- func (d DNS) SetCount(qd, an, ns, qa uint16)
- func (d *DNS) SetQuestion(domain string, qtype, qclass uint16)
- func (d DNS) Setheader(id uint16)
- type DNSQuestion
- type DNSResource
- type DNSResourceType
- type Ethernet
- type EthernetFields
- type ICMPv4
- func (b ICMPv4) Checksum() uint16
- func (b ICMPv4) Code() byte
- func (ICMPv4) DestinationPort() uint16
- func (b ICMPv4) Payload() []byte
- func (b ICMPv4) SetChecksum(checksum uint16)
- func (b ICMPv4) SetCode(c byte)
- func (ICMPv4) SetDestinationPort(uint16)
- func (ICMPv4) SetSourcePort(uint16)
- func (b ICMPv4) SetType(t ICMPv4Type)
- func (ICMPv4) SourcePort() uint16
- func (b ICMPv4) Type() ICMPv4Type
- type ICMPv4Type
- type ICMPv6
- func (b ICMPv6) Checksum() uint16
- func (b ICMPv6) Code() byte
- func (ICMPv6) DestinationPort() uint16
- func (b ICMPv6) Payload() []byte
- func (b ICMPv6) SetChecksum(checksum uint16)
- func (b ICMPv6) SetCode(c byte)
- func (ICMPv6) SetDestinationPort(uint16)
- func (ICMPv6) SetSourcePort(uint16)
- func (b ICMPv6) SetType(t ICMPv6Type)
- func (ICMPv6) SourcePort() uint16
- func (b ICMPv6) Type() ICMPv6Type
- type ICMPv6Type
- type IPv4
- func (b IPv4) CalculateChecksum() uint16
- func (b IPv4) Checksum() uint16
- func (b IPv4) DestinationAddress() tcpip.Address
- func (b IPv4) Encode(i *IPv4Fields)
- func (b IPv4) EncodePartial(partialChecksum, totalLength uint16)
- func (b IPv4) Flags() uint8
- func (b IPv4) FragmentOffset() uint16
- func (b IPv4) HeaderLength() uint8
- func (b IPv4) ID() uint16
- func (b IPv4) IsValid(pktSize int) bool
- func (b IPv4) Payload() []byte
- func (b IPv4) PayloadLength() uint16
- func (b IPv4) Protocol() uint8
- func (b IPv4) SetChecksum(v uint16)
- func (b IPv4) SetDestinationAddress(addr tcpip.Address)
- func (b IPv4) SetFlagsFragmentOffset(flags uint8, offset uint16)
- func (b IPv4) SetSourceAddress(addr tcpip.Address)
- func (b IPv4) SetTOS(v uint8, _ uint32)
- func (b IPv4) SetTotalLength(totalLength uint16)
- func (b IPv4) SourceAddress() tcpip.Address
- func (b IPv4) TOS() (uint8, uint32)
- func (b IPv4) TTL() uint8
- func (b IPv4) TotalLength() uint16
- func (b IPv4) TransportProtocol() tcpip.TransportProtocolNumber
- type IPv4Fields
- type IPv6
- func (IPv6) Checksum() uint16
- func (b IPv6) DestinationAddress() tcpip.Address
- func (b IPv6) Encode(i *IPv6Fields)
- func (b IPv6) HopLimit() uint8
- func (b IPv6) IsValid(pktSize int) bool
- func (b IPv6) NextHeader() uint8
- func (b IPv6) Payload() []byte
- func (b IPv6) PayloadLength() uint16
- func (IPv6) SetChecksum(uint16)
- func (b IPv6) SetDestinationAddress(addr tcpip.Address)
- func (b IPv6) SetNextHeader(v uint8)
- func (b IPv6) SetPayloadLength(payloadLength uint16)
- func (b IPv6) SetSourceAddress(addr tcpip.Address)
- func (b IPv6) SetTOS(t uint8, l uint32)
- func (b IPv6) SourceAddress() tcpip.Address
- func (b IPv6) TOS() (uint8, uint32)
- func (b IPv6) TransportProtocol() tcpip.TransportProtocolNumber
- type IPv6Fields
- type IPv6Fragment
- func (b IPv6Fragment) Checksum() uint16
- func (b IPv6Fragment) DestinationAddress() tcpip.Address
- func (b IPv6Fragment) Encode(i *IPv6FragmentFields)
- func (b IPv6Fragment) FragmentOffset() uint16
- func (b IPv6Fragment) ID() uint32
- func (b IPv6Fragment) IsValid() bool
- func (b IPv6Fragment) More() bool
- func (b IPv6Fragment) NextHeader() uint8
- func (b IPv6Fragment) Payload() []byte
- func (b IPv6Fragment) SetChecksum(uint16)
- func (b IPv6Fragment) SetDestinationAddress(tcpip.Address)
- func (b IPv6Fragment) SetSourceAddress(tcpip.Address)
- func (b IPv6Fragment) SetTOS(t uint8, l uint32)
- func (b IPv6Fragment) SourceAddress() tcpip.Address
- func (b IPv6Fragment) TOS() (uint8, uint32)
- func (b IPv6Fragment) TransportProtocol() tcpip.TransportProtocolNumber
- type IPv6FragmentFields
- type Network
- type SACKBlock
- type TCP
- func (b TCP) AckNumber() uint32
- func (b TCP) CalculateChecksum(partialChecksum uint16, totalLen uint16) uint16
- func (b TCP) Checksum() uint16
- func (b TCP) DataOffset() uint8
- func (b TCP) DestinationPort() uint16
- func (b TCP) Encode(t *TCPFields)
- func (b TCP) EncodePartial(partialChecksum, length uint16, seqnum, acknum uint32, flags byte, ...)
- func (b TCP) Flags() uint8
- func (b TCP) Options() []byte
- func (b TCP) ParsedOptions() TCPOptions
- func (b TCP) Payload() []byte
- func (b TCP) SequenceNumber() uint32
- func (b TCP) SetChecksum(checksum uint16)
- func (b TCP) SetDestinationPort(port uint16)
- func (b TCP) SetSourcePort(port uint16)
- func (b TCP) SourcePort() uint16
- func (b TCP) WindowSize() uint16
- type TCPFields
- type TCPOptions
- type TCPSynOptions
- type Transport
- type UDP
- func (b UDP) CalculateChecksum(partialChecksum uint16, totalLen uint16) uint16
- func (b UDP) Checksum() uint16
- func (b UDP) DestinationPort() uint16
- func (b UDP) Encode(u *UDPFields)
- func (b UDP) Length() uint16
- func (b UDP) Payload() []byte
- func (b UDP) SetChecksum(checksum uint16)
- func (b UDP) SetDestinationPort(port uint16)
- func (b UDP) SetSourcePort(port uint16)
- func (b UDP) SourcePort() uint16
- type UDPFields
Constants ¶
const ( //ARPProtocolnumber是arp协议号 为0x0806 ARPProtocolNumber tcpip.NetworkProtocolNumber = 0x0806 //arpsize是arp报文在ipv4网络下的长度 ARPSize = 2 + 2 + 1 + 1 + 2 + 2*6 + 2*4 )
const ( ID = 0 OP = 2 QDCOUNT = 4 ANCOUNT = 6 NSCOUNT = 8 ARCOUNT = 10 DOMAIN = 12 )
const ( //EthernetMinimusize 以太网帧最小的长度 EtheernetMinimumsize = 14 //EthernetAddressSize 以太网地址的长度 EthernetAddressSize = 6 )
const ( // ICMPv4MinimumSize is the minimum size of a valid ICMP packet. ICMPv4MinimumSize = 4 // ICMPv4EchoMinimumSize is the minimum size of a valid ICMP echo packet. ICMPv4EchoMinimumSize = 6 // ICMPv4DstUnreachableMinimumSize is the minimum size of a valid ICMP // destination unreachable packet. ICMPv4DstUnreachableMinimumSize = ICMPv4MinimumSize + 4 // ICMPv4ProtocolNumber is the ICMP transport protocol number. ICMPv4ProtocolNumber tcpip.TransportProtocolNumber = 1 )
const ( ICMPv4PortUnreachable = 3 ICMPv4FragmentationNeeded = 4 )
Values for ICMP code as defined in RFC 792.
const ( // ICMPv6MinimumSize is the minimum size of a valid ICMP packet. ICMPv6MinimumSize = 4 // ICMPv6ProtocolNumber is the ICMP transport protocol number. ICMPv6ProtocolNumber tcpip.TransportProtocolNumber = 58 // ICMPv6NeighborSolicitMinimumSize is the minimum size of a // neighbor solicitation packet. ICMPv6NeighborSolicitMinimumSize = ICMPv6MinimumSize + 4 + 16 // ICMPv6NeighborAdvertSize is size of a neighbor advertisement. ICMPv6NeighborAdvertSize = 32 // ICMPv6EchoMinimumSize is the minimum size of a valid ICMP echo packet. ICMPv6EchoMinimumSize = 8 // ICMPv6DstUnreachableMinimumSize is the minimum size of a valid ICMP // destination unreachable packet. ICMPv6DstUnreachableMinimumSize = ICMPv6MinimumSize + 4 // ICMPv6PacketTooBigMinimumSize is the minimum size of a valid ICMP // packet-too-big packet. ICMPv6PacketTooBigMinimumSize = ICMPv6MinimumSize + 4 )
const ( // IPv4MinimumSize is the minimum size of a valid IPv4 packet. IPv4MinimumSize = 20 // IPv4MaximumHeaderSize is the maximum size of an IPv4 header. Given // that there are only 4 bits to represents the header length in 32-bit // units, the header cannot exceed 15*4 = 60 bytes. IPv4MaximumHeaderSize = 60 // IPv4AddressSize is the size, in bytes, of an IPv4 address. IPv4AddressSize = 4 // IPv4ProtocolNumber is IPv4's network protocol number. IPv4ProtocolNumber tcpip.NetworkProtocolNumber = 0x0800 // IPv4Version is the version of the ipv4 protocol. IPv4Version = 4 // IPv4Broadcast is the broadcast address of the IPv4 procotol. IPv4Broadcast tcpip.Address = "\xff\xff\xff\xff" // IPv4Any is the non-routable IPv4 "any" meta address. IPv4Any tcpip.Address = "\x00\x00\x00\x00" )
const ( IPv4FlagMoreFragments = 1 << iota IPv4FlagDontFragment )
Flags that may be set in an IPv4 packet.
const ( // IPv6MinimumSize is the minimum size of a valid IPv6 packet. IPv6MinimumSize = 40 // IPv6AddressSize is the size, in bytes, of an IPv6 address. IPv6AddressSize = 16 // IPv6ProtocolNumber is IPv6's network protocol number. IPv6ProtocolNumber tcpip.NetworkProtocolNumber = 0x86dd // IPv6Version is the version of the ipv6 protocol. IPv6Version = 6 // IPv6MinimumMTU is the minimum MTU required by IPv6, per RFC 2460, // section 5. IPv6MinimumMTU = 1280 )
const ( // IPv6FragmentHeader header is the number used to specify that the next // header is a fragment header, per RFC 2460. IPv6FragmentHeader = 44 // IPv6FragmentHeaderSize is the size of the fragment header. IPv6FragmentHeaderSize = 8 )
const ( // MaxWndScale is maximum allowed window scaling, as described in // RFC 1323, section 2.3, page 11. MaxWndScale = 14 // TCPMaxSACKBlocks is the maximum number of SACK blocks that can // be encoded in a TCP option field. TCPMaxSACKBlocks = 4 )
const ( TCPFlagFin = 1 << iota TCPFlagSyn TCPFlagRst TCPFlagPsh TCPFlagAck TCPFlagUrg )
Flags that may be set in a TCP segment.
const ( TCPOptionEOL = 0 TCPOptionNOP = 1 TCPOptionMSS = 2 TCPOptionWS = 3 TCPOptionTS = 8 TCPOptionSACKPermitted = 4 TCPOptionSACK = 5 )
Options that may be present in a TCP segment.
const ( // TCPMinimumSize is the minimum size of a valid TCP packet. TCPMinimumSize = 20 // TCPProtocolNumber is TCP's transport protocol number. TCPProtocolNumber tcpip.TransportProtocolNumber = 6 )
const ( // UDPMinimumSize is the minimum size of a valid UDP packet. UDPMinimumSize = 8 // UDPProtocolNumber is UDP's transport protocol number. UDPProtocolNumber tcpip.TransportProtocolNumber = 17 )
const (
ICMPv6PortUnreachable = 4
)
Values for ICMP code as defined in RFC 4443.
const ( // MaxIPPacketSize is the maximum supported IP packet size, excluding // jumbograms. The maximum IPv4 packet size is 64k-1 (total size must fit // in 16 bits). For IPv6, the payload max size (excluding jumbograms) is // 64k-1 (also needs to fit in 16 bits). So we use 64k - 1 + 2 * m, where // m is the minimum IPv6 header size; we leave room for some potential // IP options. MaxIPPacketSize = 0xffff + 2*IPv6MinimumSize )
Variables ¶
This section is empty.
Functions ¶
func AddTCPOptionPadding ¶
AddTCPOptionPadding adds the required number of TCPOptionNOP to quad align the option buffer. It adds padding bytes after the offset specified and returns the number of padding bytes added. The passed in options slice must have space for the padding bytes.
func Checksum ¶
Checksum calculates the checksum (as defined in RFC 1071) of the bytes in the given byte array. 校验和的计算
func ChecksumCombine ¶
ChecksumCombine combines the two uint16 to form their checksum. This is done by adding them and the carry.
func EncodeMSSOption ¶
EncodeMSSOption encodes the MSS TCP option with the provided MSS values in the supplied buffer. If the provided buffer is not large enough then it just returns without encoding anything. It returns the number of bytes written to the provided buffer.
func EncodeSACKBlocks ¶
EncodeSACKBlocks encodes the provided SACK blocks as a TCP SACK option block in the provided slice. It tries to fit in as many blocks as possible based on number of bytes available in the provided buffer. It returns the number of bytes written to the provided buffer.
func EncodeSACKPermittedOption ¶
EncodeSACKPermittedOption encodes a SACKPermitted option into the provided buffer. If the buffer is smaller than required it just returns without encoding anything. It returns the number of bytes written to the provided buffer.
func EncodeTSOption ¶
EncodeTSOption encodes the provided tsVal and tsEcr values as a TCP timestamp option into the provided buffer. If the buffer is smaller than expected it just returns without encoding anything. It returns the number of bytes written to the provided buffer.
func EncodeWSOption ¶
EncodeWSOption encodes the WS TCP option with the WS value in the provided buffer. If the provided buffer is not large enough then it just returns without encoding anything. It returns the number of bytes written to the provided buffer.
func IPVersion ¶
IPVersion returns the version of IP used in the given packet. It returns -1 if the packet is not large enough to contain the version field.
func IsV4MappedAddress ¶
IsV4MappedAddress determines if the provided address is an IPv4 mapped address by checking if its prefix is 0:0:0:0:0:ffff::/96.
func IsV4MulticastAddress ¶
IsV4MulticastAddress determines if the provided address is an IPv4 multicast address (range 224.0.0.0 to 239.255.255.255). The four most significant bits will be 1110 = 0xe0.
func IsV6MulticastAddress ¶
IsV6MulticastAddress determines if the provided address is an IPv6 multicast address (anything starting with FF).
func LinkLocalAddr ¶
func LinkLocalAddr(linkAddr tcpip.LinkAddress) tcpip.Address
LinkLocalAddr computes the default IPv6 link-local address from a link-layer (MAC) address.
func PseudoHeaderChecksum ¶
func PseudoHeaderChecksum(protocol tcpip.TransportProtocolNumber, srcAddr tcpip.Address, dstAddr tcpip.Address) uint16
PseudoHeaderChecksum calculates the pseudo-header checksum for the given destination protocol and network address, ignoring the length field. Pseudo-headers are needed by transport layers when calculating their own checksum.
Types ¶
type ARP ¶
type ARP []byte
ARP报文的封装
func (ARP) HardwareAddressSender ¶
HardwareAddressSender 从报文中得到arp发送方的硬件地址
func (ARP) HardwareAddressTarget ¶
HardwareAddressTarget从报文中得到arp目的方硬件地址
func (ARP) ProtocolAddressSender ¶
ProtocolAddressDender 从报文中得到arp发送方的协议地址,为ipv4地址
func (ARP) ProtocolAddressTarget ¶
ProtocolAddressTarget从报文中得到ar目的方的协议地址,为ipv4地址
func (ARP) SetIpv4OverEthernet ¶
func (a ARP) SetIpv4OverEthernet()
SetIpv4overethernet 设置ipv4网络在以太网中arp报文的硬件和协议信息
type DNS ¶
type DNS []byte
DNS 报文的封装
func (*DNS) SetQuestion ¶
SetQuestion query field domain url qtype type qclass class
type DNSResource ¶
type DNSResource struct { Name uint16 Type DNSResourceType Class uint16 TTL uint32 RDlen uint16 RData []byte Address string }
DNSResource ansower,authority,additional
type DNSResourceType ¶
type DNSResourceType uint16
DNSResourceType resource type 表示资源类型
const ( A DNSResourceType = iota + 1 // name = hostname value = ipaddress NS //name = ,value = dns hostname MD MF CNAME //name = hostname SOA MB MG MR NULL WKS PTR HINFO MINFO MX )
type Ethernet ¶
type Ethernet []byte
Ethernet 以太网数据包的封装
func (Ethernet) DestinationAddress ¶
func (b Ethernet) DestinationAddress() tcpip.LinkAddress
DestinationAddress 从帧 头部中得到目的地址
func (Ethernet) Encode ¶
func (b Ethernet) Encode(e *EthernetFields)
Encode 根据传入的帧头部信息编码成Ethernet二进制形式,注意Ethernet应先分配好内存
func (Ethernet) SourceAddress ¶
func (b Ethernet) SourceAddress() tcpip.LinkAddress
SourceAddress 从帧投不中得到源地址
type EthernetFields ¶
type EthernetFields struct { //源地址 (string) SrcAddr tcpip.LinkAddress //目的地址 DstAddr tcpip.LinkAddress //协议类型 Type tcpip.NetworkProtocolNumber }
EthernetFields 表示链路层以太网帧的头部
type ICMPv4 ¶
type ICMPv4 []byte
ICMPv4 represents an ICMPv4 header stored in a byte array.
func (ICMPv4) DestinationPort ¶
DestinationPort implements Transport.DestinationPort.
func (ICMPv4) SetChecksum ¶
SetChecksum sets the ICMP checksum field.
func (ICMPv4) SetDestinationPort ¶
SetDestinationPort implements Transport.SetDestinationPort.
func (ICMPv4) SetSourcePort ¶
SetSourcePort implements Transport.SetSourcePort.
func (ICMPv4) SourcePort ¶
SourcePort implements Transport.SourcePort.
type ICMPv4Type ¶
type ICMPv4Type byte
ICMPv4Type is the ICMP type field described in RFC 792.
const ( ICMPv4EchoReply ICMPv4Type = 0 ICMPv4DstUnreachable ICMPv4Type = 3 ICMPv4SrcQuench ICMPv4Type = 4 ICMPv4Redirect ICMPv4Type = 5 ICMPv4Echo ICMPv4Type = 8 ICMPv4TimeExceeded ICMPv4Type = 11 ICMPv4ParamProblem ICMPv4Type = 12 ICMPv4Timestamp ICMPv4Type = 13 ICMPv4TimestampReply ICMPv4Type = 14 ICMPv4InfoRequest ICMPv4Type = 15 ICMPv4InfoReply ICMPv4Type = 16 )
Typical values of ICMPv4Type defined in RFC 792.
type ICMPv6 ¶
type ICMPv6 []byte
ICMPv6 represents an ICMPv6 header stored in a byte array.
func (ICMPv6) DestinationPort ¶
DestinationPort implements Transport.DestinationPort.
func (ICMPv6) SetChecksum ¶
SetChecksum calculates and sets the ICMP checksum field.
func (ICMPv6) SetDestinationPort ¶
SetDestinationPort implements Transport.SetDestinationPort.
func (ICMPv6) SetSourcePort ¶
SetSourcePort implements Transport.SetSourcePort.
func (ICMPv6) SourcePort ¶
SourcePort implements Transport.SourcePort.
type ICMPv6Type ¶
type ICMPv6Type byte
ICMPv6Type is the ICMP type field described in RFC 4443 and friends.
const ( ICMPv6DstUnreachable ICMPv6Type = 1 ICMPv6PacketTooBig ICMPv6Type = 2 ICMPv6TimeExceeded ICMPv6Type = 3 ICMPv6ParamProblem ICMPv6Type = 4 ICMPv6EchoRequest ICMPv6Type = 128 ICMPv6EchoReply ICMPv6Type = 129 ICMPv6RouterSolicit ICMPv6Type = 133 ICMPv6RouterAdvert ICMPv6Type = 134 ICMPv6NeighborSolicit ICMPv6Type = 135 ICMPv6NeighborAdvert ICMPv6Type = 136 ICMPv6RedirectMsg ICMPv6Type = 137 )
Typical values of ICMPv6Type defined in RFC 4443.
type IPv4 ¶
type IPv4 []byte
IPv4 represents an ipv4 header stored in a byte array. Most of the methods of IPv4 access to the underlying slice without checking the boundaries and could panic because of 'index out of range'. Always call IsValid() to validate an instance of IPv4 before using other methods.
func (IPv4) CalculateChecksum ¶
CalculateChecksum calculates the checksum of the ipv4 header.
func (IPv4) DestinationAddress ¶
DestinationAddress returns the "destination address" field of the ipv4 header.
func (IPv4) Encode ¶
func (b IPv4) Encode(i *IPv4Fields)
Encode encodes all the fields of the ipv4 header.
func (IPv4) EncodePartial ¶
EncodePartial updates the total length and checksum fields of ipv4 header, taking in the partial checksum, which is the checksum of the header without the total length and checksum fields. It is useful in cases when similar packets are produced.
func (IPv4) FragmentOffset ¶
FragmentOffset returns the "fragment offset" field of the ipv4 header.
func (IPv4) HeaderLength ¶
HeaderLength returns the value of the "header length" field of the ipv4 header.
func (IPv4) PayloadLength ¶
PayloadLength returns the length of the payload portion of the ipv4 packet.
func (IPv4) SetChecksum ¶
SetChecksum sets the checksum field of the ipv4 header.
func (IPv4) SetDestinationAddress ¶
SetDestinationAddress sets the "destination address" field of the ipv4 header.
func (IPv4) SetFlagsFragmentOffset ¶
SetFlagsFragmentOffset sets the "flags" and "fragment offset" fields of the ipv4 header.
func (IPv4) SetSourceAddress ¶
SetSourceAddress sets the "source address" field of the ipv4 header.
func (IPv4) SetTotalLength ¶
SetTotalLength sets the "total length" field of the ipv4 header.
func (IPv4) SourceAddress ¶
SourceAddress returns the "source address" field of the ipv4 header.
func (IPv4) TotalLength ¶
TotalLength returns the "total length" field of the ipv4 header.
func (IPv4) TransportProtocol ¶
func (b IPv4) TransportProtocol() tcpip.TransportProtocolNumber
TransportProtocol implements Network.TransportProtocol.
type IPv4Fields ¶
type IPv4Fields struct { // IHL is the "internet header length" field of an IPv4 packet. // 头部长度 IHL uint8 // TOS is the "type of service" field of an IPv4 packet. // 服务区分的表示 TOS uint8 // TotalLength is the "total length" field of an IPv4 packet. // 数据报文总长 TotalLength uint16 // ID is the "identification" field of an IPv4 packet. // 标识符 ID uint16 // Flags is the "flags" field of an IPv4 packet. // 标签 Flags uint8 // FragmentOffset is the "fragment offset" field of an IPv4 packet. // 分片偏移 FragmentOffset uint16 // TTL is the "time to live" field of an IPv4 packet. // 存活时间 TTL uint8 // Protocol is the "protocol" field of an IPv4 packet. // 表示的传输层协议 Protocol uint8 // Checksum is the "checksum" field of an IPv4 packet. // 首部校验和 Checksum uint16 // SrcAddr is the "source ip address" of an IPv4 packet. // 源IP地址 SrcAddr tcpip.Address // DstAddr is the "destination ip address" of an IPv4 packet. // 目的IP地址 DstAddr tcpip.Address }
IPv4Fields contains the fields of an IPv4 packet. It is used to describe the fields of a packet that needs to be encoded. 表示IPv4头部信息的结构体
type IPv6 ¶
type IPv6 []byte
IPv6 represents an ipv6 header stored in a byte array. Most of the methods of IPv6 access to the underlying slice without checking the boundaries and could panic because of 'index out of range'. Always call IsValid() to validate an instance of IPv6 before using other methods.
func (IPv6) Checksum ¶
Checksum implements Network.Checksum. Given that IPv6 doesn't have a checksum, it just returns 0.
func (IPv6) DestinationAddress ¶
DestinationAddress returns the "destination address" field of the ipv6 header.
func (IPv6) Encode ¶
func (b IPv6) Encode(i *IPv6Fields)
Encode encodes all the fields of the ipv6 header.
func (IPv6) NextHeader ¶
NextHeader returns the value of the "next header" field of the ipv6 header.
func (IPv6) PayloadLength ¶
PayloadLength returns the value of the "payload length" field of the ipv6 header.
func (IPv6) SetChecksum ¶
SetChecksum implements Network.SetChecksum. Given that IPv6 doesn't have a checksum, it is empty.
func (IPv6) SetDestinationAddress ¶
SetDestinationAddress sets the "destination address" field of the ipv6 header.
func (IPv6) SetNextHeader ¶
SetNextHeader sets the value of the "next header" field of the ipv6 header.
func (IPv6) SetPayloadLength ¶
SetPayloadLength sets the "payload length" field of the ipv6 header.
func (IPv6) SetSourceAddress ¶
SetSourceAddress sets the "source address" field of the ipv6 header.
func (IPv6) SourceAddress ¶
SourceAddress returns the "source address" field of the ipv6 header.
func (IPv6) TransportProtocol ¶
func (b IPv6) TransportProtocol() tcpip.TransportProtocolNumber
TransportProtocol implements Network.TransportProtocol.
type IPv6Fields ¶
type IPv6Fields struct { // TrafficClass is the "traffic class" field of an IPv6 packet. TrafficClass uint8 // FlowLabel is the "flow label" field of an IPv6 packet. FlowLabel uint32 // PayloadLength is the "payload length" field of an IPv6 packet. PayloadLength uint16 // NextHeader is the "next header" field of an IPv6 packet. NextHeader uint8 // HopLimit is the "hop limit" field of an IPv6 packet. HopLimit uint8 // SrcAddr is the "source ip address" of an IPv6 packet. SrcAddr tcpip.Address // DstAddr is the "destination ip address" of an IPv6 packet. DstAddr tcpip.Address }
IPv6Fields contains the fields of an IPv6 packet. It is used to describe the fields of a packet that needs to be encoded.
type IPv6Fragment ¶
type IPv6Fragment []byte
IPv6Fragment represents an ipv6 fragment header stored in a byte array. Most of the methods of IPv6Fragment access to the underlying slice without checking the boundaries and could panic because of 'index out of range'. Always call IsValid() to validate an instance of IPv6Fragment before using other methods.
func (IPv6Fragment) Checksum ¶
func (b IPv6Fragment) Checksum() uint16
Checksum is not supported by IPv6Fragment.
func (IPv6Fragment) DestinationAddress ¶
func (b IPv6Fragment) DestinationAddress() tcpip.Address
DestinationAddress is not supported by IPv6Fragment.
func (IPv6Fragment) Encode ¶
func (b IPv6Fragment) Encode(i *IPv6FragmentFields)
Encode encodes all the fields of the ipv6 fragment.
func (IPv6Fragment) FragmentOffset ¶
func (b IPv6Fragment) FragmentOffset() uint16
FragmentOffset returns the "fragment offset" field of the ipv6 fragment.
func (IPv6Fragment) ID ¶
func (b IPv6Fragment) ID() uint32
ID returns the value of the identifier field of the ipv6 fragment.
func (IPv6Fragment) IsValid ¶
func (b IPv6Fragment) IsValid() bool
IsValid performs basic validation on the fragment header.
func (IPv6Fragment) More ¶
func (b IPv6Fragment) More() bool
More returns the "more" field of the ipv6 fragment.
func (IPv6Fragment) NextHeader ¶
func (b IPv6Fragment) NextHeader() uint8
NextHeader returns the value of the "next header" field of the ipv6 fragment.
func (IPv6Fragment) Payload ¶
func (b IPv6Fragment) Payload() []byte
Payload implements Network.Payload.
func (IPv6Fragment) SetChecksum ¶
func (b IPv6Fragment) SetChecksum(uint16)
SetChecksum is not supported by IPv6Fragment.
func (IPv6Fragment) SetDestinationAddress ¶
func (b IPv6Fragment) SetDestinationAddress(tcpip.Address)
SetDestinationAddress is not supported by IPv6Fragment.
func (IPv6Fragment) SetSourceAddress ¶
func (b IPv6Fragment) SetSourceAddress(tcpip.Address)
SetSourceAddress is not supported by IPv6Fragment.
func (IPv6Fragment) SetTOS ¶
func (b IPv6Fragment) SetTOS(t uint8, l uint32)
SetTOS is not supported by IPv6Fragment.
func (IPv6Fragment) SourceAddress ¶
func (b IPv6Fragment) SourceAddress() tcpip.Address
SourceAddress is not supported by IPv6Fragment.
func (IPv6Fragment) TOS ¶
func (b IPv6Fragment) TOS() (uint8, uint32)
TOS is not supported by IPv6Fragment.
func (IPv6Fragment) TransportProtocol ¶
func (b IPv6Fragment) TransportProtocol() tcpip.TransportProtocolNumber
TransportProtocol implements Network.TransportProtocol.
type IPv6FragmentFields ¶
type IPv6FragmentFields struct { // NextHeader is the "next header" field of an IPv6 fragment. NextHeader uint8 // FragmentOffset is the "fragment offset" field of an IPv6 fragment. FragmentOffset uint16 // M is the "more" field of an IPv6 fragment. M bool // Identification is the "identification" field of an IPv6 fragment. Identification uint32 }
IPv6FragmentFields contains the fields of an IPv6 fragment. It is used to describe the fields of a packet that needs to be encoded.
type Network ¶
type Network interface { // SourceAddress returns the value of the "source address" field. SourceAddress() tcpip.Address // DestinationAddress returns the value of the "destination address" // field. DestinationAddress() tcpip.Address // Checksum returns the value of the "checksum" field. Checksum() uint16 // SetSourceAddress sets the value of the "source address" field. SetSourceAddress(tcpip.Address) // SetDestinationAddress sets the value of the "destination address" // field. SetDestinationAddress(tcpip.Address) // SetChecksum sets the value of the "checksum" field. SetChecksum(uint16) // TransportProtocol returns the number of the transport protocol // stored in the payload. TransportProtocol() tcpip.TransportProtocolNumber // Payload returns a byte slice containing the payload of the network // packet. Payload() []byte // TOS returns the values of the "type of service" and "flow label" fields. TOS() (uint8, uint32) // SetTOS sets the values of the "type of service" and "flow label" fields. SetTOS(t uint8, l uint32) }
Network offers generic methods to query and/or update the fields of the header of a network protocol buffer.
type SACKBlock ¶
type SACKBlock struct { // Start indicates the lowest sequence number in the block. Start seqnum.Value // End indicates the sequence number immediately following the last // sequence number of this block. End seqnum.Value }
SACKBlock represents a single contiguous SACK block.
+stateify savable 表示 sack 块的结构体
type TCP ¶
type TCP []byte
TCP represents a TCP header stored in a byte array.
func (TCP) CalculateChecksum ¶
CalculateChecksum calculates the checksum of the tcp segment given the totalLen and partialChecksum(descriptions below) totalLen is the total length of the segment partialChecksum is the checksum of the network-layer pseudo-header (excluding the total length) and the checksum of the segment data.
func (TCP) DataOffset ¶
DataOffset returns the "data offset" field of the tcp header.
func (TCP) DestinationPort ¶
DestinationPort returns the "destination port" field of the tcp header.
func (TCP) EncodePartial ¶
func (b TCP) EncodePartial(partialChecksum, length uint16, seqnum, acknum uint32, flags byte, rcvwnd uint16)
EncodePartial updates a subset of the fields of the tcp header. It is useful in cases when similar segments are produced.
func (TCP) ParsedOptions ¶
func (b TCP) ParsedOptions() TCPOptions
ParsedOptions returns a TCPOptions structure which parses and caches the TCP option values in the TCP segment. NOTE: Invoking this function repeatedly is expensive as it reparses the options on each invocation.
func (TCP) SequenceNumber ¶
SequenceNumber returns the "sequence number" field of the tcp header.
func (TCP) SetChecksum ¶
SetChecksum sets the checksum field of the tcp header.
func (TCP) SetDestinationPort ¶
SetDestinationPort sets the "destination port" field of the tcp header.
func (TCP) SetSourcePort ¶
SetSourcePort sets the "source port" field of the tcp header.
func (TCP) SourcePort ¶
SourcePort returns the "source port" field of the tcp header.
func (TCP) WindowSize ¶
WindowSize returns the "window size" field of the tcp header.
type TCPFields ¶
type TCPFields struct { // SrcPort is the "source port" field of a TCP packet. SrcPort uint16 // DstPort is the "destination port" field of a TCP packet. DstPort uint16 // SeqNum is the "sequence number" field of a TCP packet. SeqNum uint32 // AckNum is the "acknowledgement number" field of a TCP packet. AckNum uint32 // DataOffset is the "data offset" field of a TCP packet. DataOffset uint8 // Flags is the "flags" field of a TCP packet. Flags uint8 // WindowSize is the "window size" field of a TCP packet. WindowSize uint16 // Checksum is the "checksum" field of a TCP packet. Checksum uint16 // UrgentPointer is the "urgent pointer" field of a TCP packet. UrgentPointer uint16 }
TCPFields contains the fields of a TCP packet. It is used to describe the fields of a packet that needs to be encoded. tcp首部字段
type TCPOptions ¶
type TCPOptions struct { // TS is true if the TimeStamp option is enabled. TS bool // TSVal is the value in the TSVal field of the segment. TSVal uint32 // TSEcr is the value in the TSEcr field of the segment. TSEcr uint32 // SACKBlocks are the SACK blocks specified in the segment. SACKBlocks []SACKBlock }
TCPOptions are used to parse and cache the TCP segment options for a non syn/syn-ack segment.
+stateify savable tcp选项结构,这个结构不表示 syn/syn-ack 报文
func ParseTCPOptions ¶
func ParseTCPOptions(b []byte) TCPOptions
ParseTCPOptions extracts and stores all known options in the provided byte slice in a TCPOptions structure.
type TCPSynOptions ¶
type TCPSynOptions struct { // MSS is the maximum segment size provided by the peer in the SYN. MSS uint16 // WS is the window scale option provided by the peer in the SYN. // // Set to -1 if no window scale option was provided. WS int // TS is true if the timestamp option was provided in the syn/syn-ack. TS bool // TSVal is the value of the TSVal field in the timestamp option. TSVal uint32 // TSEcr is the value of the TSEcr field in the timestamp option. TSEcr uint32 // SACKPermitted is true if the SACK option was provided in the SYN/SYN-ACK. SACKPermitted bool }
TCPSynOptions is used to return the parsed TCP Options in a syn segment. syn 报文的选项
func ParseSynOptions ¶
func ParseSynOptions(opts []byte, isAck bool) TCPSynOptions
ParseSynOptions parses the options received in a SYN segment and returns the relevant ones. opts should point to the option part of the TCP Header.
type Transport ¶
type Transport interface { // SourcePort returns the value of the "source port" field. SourcePort() uint16 // Destination returns the value of the "destination port" field. DestinationPort() uint16 // Checksum returns the value of the "checksum" field. Checksum() uint16 // SetSourcePort sets the value of the "source port" field. SetSourcePort(uint16) // SetDestinationPort sets the value of the "destination port" field. SetDestinationPort(uint16) // SetChecksum sets the value of the "checksum" field. SetChecksum(uint16) // Payload returns the data carried in the transport buffer. Payload() []byte }
Transport offers generic methods to query and/or update the fields of the header of a transport protocol buffer.
type UDP ¶
type UDP []byte
UDP represents a UDP header stored in a byte array.
func (UDP) CalculateChecksum ¶
CalculateChecksum calculates the checksum of the udp packet, given the total length of the packet and the checksum of the network-layer pseudo-header (excluding the total length) and the checksum of the payload.
func (UDP) DestinationPort ¶
DestinationPort returns the "destination port" field of the udp header.
func (UDP) SetChecksum ¶
SetChecksum sets the "checksum" field of the udp header.
func (UDP) SetDestinationPort ¶
SetDestinationPort sets the "destination port" field of the udp header.
func (UDP) SetSourcePort ¶
SetSourcePort sets the "source port" field of the udp header.
func (UDP) SourcePort ¶
SourcePort returns the "source port" field of the udp header.
type UDPFields ¶
type UDPFields struct { // SrcPort is the "source port" field of a UDP packet. SrcPort uint16 // DstPort is the "destination port" field of a UDP packet. DstPort uint16 // Length is the "length" field of a UDP packet. Length uint16 // Checksum is the "checksum" field of a UDP packet. Checksum uint16 }
UDPFields contains the fields of a UDP packet. It is used to describe the fields of a packet that needs to be encoded. udp 首部字段