github.com/cilium/cilium@v1.16.2/pkg/maps/fragmap/fragmap.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package fragmap 5 6 import ( 7 "fmt" 8 9 "github.com/cilium/ebpf" 10 11 "github.com/cilium/cilium/pkg/bpf" 12 "github.com/cilium/cilium/pkg/option" 13 "github.com/cilium/cilium/pkg/types" 14 ) 15 16 const ( 17 // MapName is the name of the map used to retrieve L4 ports associated 18 // to the datagram to which an IPv4 belongs. 19 MapName = "cilium_ipv4_frag_datagrams" 20 ) 21 22 // FragmentKey must match 'struct ipv4_frag_id' in "bpf/lib/ipv4.h". 23 type FragmentKey struct { 24 destAddr types.IPv4 `align:"daddr"` 25 sourceAddr types.IPv4 `align:"saddr"` 26 id uint16 `align:"id"` 27 proto uint8 `align:"proto"` 28 _ uint8 29 } 30 31 // FragmentValue must match 'struct ipv4_frag_l4ports' in "bpf/lib/ipv4.h". 32 type FragmentValue struct { 33 sourcePort uint16 `align:"sport"` 34 destPort uint16 `align:"dport"` 35 } 36 37 // String converts the key into a human readable string format. 38 func (k *FragmentKey) String() string { 39 return fmt.Sprintf("%s --> %s, %d, %d", k.sourceAddr, k.destAddr, k.proto, k.id) 40 } 41 42 func (k *FragmentKey) New() bpf.MapKey { return &FragmentKey{} } 43 44 // String converts the value into a human readable string format. 45 func (v *FragmentValue) String() string { 46 return fmt.Sprintf("%d, %d", v.destPort, v.sourcePort) 47 } 48 49 func (v *FragmentValue) New() bpf.MapValue { return &FragmentValue{} } 50 51 // InitMap creates the signal map in the kernel. 52 func InitMap(mapEntries int) error { 53 fragMap := bpf.NewMap(MapName, 54 ebpf.LRUHash, 55 &FragmentKey{}, 56 &FragmentValue{}, 57 mapEntries, 58 0, 59 ).WithEvents(option.Config.GetEventBufferConfig(MapName)) 60 return fragMap.Create() 61 }