-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
types.go
116 lines (93 loc) · 3.22 KB
/
types.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
// SPDX-License-Identifier: Apache-2.0
// Copyright 2019 Authors of Cilium
package nat
import (
"strings"
"unsafe"
"github.com/cilium/cilium/pkg/bpf"
"github.com/cilium/cilium/pkg/tuple"
"github.com/cilium/cilium/pkg/u8proto"
)
type NatKey interface {
bpf.MapKey
// ToNetwork converts fields to network byte order.
ToNetwork() NatKey
// ToHost converts fields to host byte order.
ToHost() NatKey
// Dump contents of key to sb. Returns true if successful.
Dump(sb *strings.Builder, reverse bool) bool
// GetFlags flags containing the direction of the TupleKey.
GetFlags() uint8
// GetNextHeader returns the proto of the NatKey
GetNextHeader() u8proto.U8proto
}
// NatKey4 is needed to provide NatEntry type to Lookup values
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=github.com/cilium/cilium/pkg/bpf.MapKey
type NatKey4 struct {
tuple.TupleKey4Global
}
// SizeofNatKey4 is the size of the NatKey4 type in bytes.
const SizeofNatKey4 = int(unsafe.Sizeof(NatKey4{}))
// NewValue creates a new bpf.MapValue.
func (k *NatKey4) NewValue() bpf.MapValue { return &NatEntry4{} }
// ToNetwork converts ports to network byte order.
//
// This is necessary to prevent callers from implicitly converting
// the NatKey4 type here into a local key type in the nested
// TupleKey4Global field.
func (k *NatKey4) ToNetwork() NatKey {
return &NatKey4{
TupleKey4Global: *k.TupleKey4Global.ToNetwork().(*tuple.TupleKey4Global),
}
}
// ToHost converts ports to host byte order.
//
// This is necessary to prevent callers from implicitly converting
// the NatKey4 type here into a local key type in the nested
// TupleKey4Global field.
func (k *NatKey4) ToHost() NatKey {
return &NatKey4{
TupleKey4Global: *k.TupleKey4Global.ToHost().(*tuple.TupleKey4Global),
}
}
// GetKeyPtr returns the unsafe.Pointer for k.
func (k *NatKey4) GetKeyPtr() unsafe.Pointer { return unsafe.Pointer(k) }
func (k *NatKey4) GetNextHeader() u8proto.U8proto {
return k.NextHeader
}
// NatKey6 is needed to provide NatEntry type to Lookup values
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=github.com/cilium/cilium/pkg/bpf.MapKey
type NatKey6 struct {
tuple.TupleKey6Global
}
// SizeofNatKey6 is the size of the NatKey6 type in bytes.
const SizeofNatKey6 = int(unsafe.Sizeof(NatKey6{}))
// NewValue creates a new bpf.MapValue.
func (k *NatKey6) NewValue() bpf.MapValue { return &NatEntry6{} }
// ToNetwork converts ports to network byte order.
//
// This is necessary to prevent callers from implicitly converting
// the NatKey6 type here into a local key type in the nested
// TupleKey6Global field.
func (k *NatKey6) ToNetwork() NatKey {
return &NatKey6{
TupleKey6Global: *k.TupleKey6Global.ToNetwork().(*tuple.TupleKey6Global),
}
}
// ToHost converts ports to host byte order.
//
// This is necessary to prevent callers from implicitly converting
// the NatKey6 type here into a local key type in the nested
// TupleKey6Global field.
func (k *NatKey6) ToHost() NatKey {
return &NatKey6{
TupleKey6Global: *k.TupleKey6Global.ToHost().(*tuple.TupleKey6Global),
}
}
// GetKeyPtr returns the unsafe.Pointer for k.
func (k *NatKey6) GetKeyPtr() unsafe.Pointer { return unsafe.Pointer(k) }
func (k *NatKey6) GetNextHeader() u8proto.U8proto {
return k.NextHeader
}