github.phpd.cn/cilium/cilium@v1.6.12/pkg/tuple/tuple.go (about)

     1  // Copyright 2016-2019 Authors of Cilium
     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 tuple
    16  
    17  import (
    18  	"bytes"
    19  	"fmt"
    20  	"unsafe"
    21  
    22  	"github.com/cilium/cilium/pkg/bpf"
    23  )
    24  
    25  const (
    26  	TUPLE_F_OUT     = 0
    27  	TUPLE_F_IN      = 1
    28  	TUPLE_F_RELATED = 2
    29  	TUPLE_F_SERVICE = 4
    30  )
    31  
    32  // TupleKey is the interface describing keys to the conntrack and NAT maps.
    33  type TupleKey interface {
    34  	bpf.MapKey
    35  
    36  	// ToNetwork converts fields to network byte order.
    37  	ToNetwork() TupleKey
    38  
    39  	// ToHost converts fields to host byte order.
    40  	ToHost() TupleKey
    41  
    42  	// Dumps contents of key to buffer. Returns true if successful.
    43  	Dump(buffer *bytes.Buffer, reverse bool) bool
    44  
    45  	// Returns flags containing the direction of the tuple key.
    46  	GetFlags() uint8
    47  }
    48  
    49  type buff256uint8 [256]uint8
    50  
    51  // DeepCopyInto is a deepcopy function, copying the receiver, writing into out. in must be non-nil.
    52  func (in *buff256uint8) DeepCopyInto(out *buff256uint8) {
    53  	copy(out[:], in[:])
    54  	return
    55  }
    56  
    57  // TupleValStub is a dummy, unused.
    58  // +k8s:deepcopy-gen=true
    59  // +k8s:deepcopy-gen:interfaces=github.com/cilium/cilium/pkg/bpf.MapValue
    60  type TupleValStub struct {
    61  	buff buff256uint8
    62  }
    63  
    64  // GetValuePtr returns the unsafe.Pointer for s.
    65  func (t *TupleValStub) GetValuePtr() unsafe.Pointer { return unsafe.Pointer(t) }
    66  
    67  // String stub method.
    68  func (t *TupleValStub) String() string {
    69  	return fmt.Sprintf("<TupleValStub>")
    70  }