github.com/google/netstack@v0.0.0-20191123085552-55fcc16cd0eb/tcpip/header/interfaces.go (about)

     1  // Copyright 2018 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package header
    16  
    17  import (
    18  	"github.com/google/netstack/tcpip"
    19  )
    20  
    21  const (
    22  	// MaxIPPacketSize is the maximum supported IP packet size, excluding
    23  	// jumbograms. The maximum IPv4 packet size is 64k-1 (total size must fit
    24  	// in 16 bits). For IPv6, the payload max size (excluding jumbograms) is
    25  	// 64k-1 (also needs to fit in 16 bits). So we use 64k - 1 + 2 * m, where
    26  	// m is the minimum IPv6 header size; we leave room for some potential
    27  	// IP options.
    28  	MaxIPPacketSize = 0xffff + 2*IPv6MinimumSize
    29  )
    30  
    31  // Transport offers generic methods to query and/or update the fields of the
    32  // header of a transport protocol buffer.
    33  type Transport interface {
    34  	// SourcePort returns the value of the "source port" field.
    35  	SourcePort() uint16
    36  
    37  	// Destination returns the value of the "destination port" field.
    38  	DestinationPort() uint16
    39  
    40  	// Checksum returns the value of the "checksum" field.
    41  	Checksum() uint16
    42  
    43  	// SetSourcePort sets the value of the "source port" field.
    44  	SetSourcePort(uint16)
    45  
    46  	// SetDestinationPort sets the value of the "destination port" field.
    47  	SetDestinationPort(uint16)
    48  
    49  	// SetChecksum sets the value of the "checksum" field.
    50  	SetChecksum(uint16)
    51  
    52  	// Payload returns the data carried in the transport buffer.
    53  	Payload() []byte
    54  }
    55  
    56  // Network offers generic methods to query and/or update the fields of the
    57  // header of a network protocol buffer.
    58  type Network interface {
    59  	// SourceAddress returns the value of the "source address" field.
    60  	SourceAddress() tcpip.Address
    61  
    62  	// DestinationAddress returns the value of the "destination address"
    63  	// field.
    64  	DestinationAddress() tcpip.Address
    65  
    66  	// Checksum returns the value of the "checksum" field.
    67  	Checksum() uint16
    68  
    69  	// SetSourceAddress sets the value of the "source address" field.
    70  	SetSourceAddress(tcpip.Address)
    71  
    72  	// SetDestinationAddress sets the value of the "destination address"
    73  	// field.
    74  	SetDestinationAddress(tcpip.Address)
    75  
    76  	// SetChecksum sets the value of the "checksum" field.
    77  	SetChecksum(uint16)
    78  
    79  	// TransportProtocol returns the number of the transport protocol
    80  	// stored in the payload.
    81  	TransportProtocol() tcpip.TransportProtocolNumber
    82  
    83  	// Payload returns a byte slice containing the payload of the network
    84  	// packet.
    85  	Payload() []byte
    86  
    87  	// TOS returns the values of the "type of service" and "flow label" fields.
    88  	TOS() (uint8, uint32)
    89  
    90  	// SetTOS sets the values of the "type of service" and "flow label" fields.
    91  	SetTOS(t uint8, l uint32)
    92  }