github.com/cilium/cilium@v1.16.2/pkg/maps/recorder/recorder.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package recorder 5 6 import ( 7 "strings" 8 9 "github.com/cilium/cilium/pkg/bpf" 10 ) 11 12 const ( 13 // MapNameWcard4 represents IPv4 capture wildcard table. 14 MapNameWcard4 = "cilium_capture4_rules" 15 // MapNameWcard6 represents IPv6 capture wildcard table. 16 MapNameWcard6 = "cilium_capture6_rules" 17 // MapSize is the default size of the v4 and v6 maps 18 MapSize = 16384 19 ) 20 21 type CaptureRule struct { 22 RuleId uint16 `align:"rule_id"` 23 Reserved uint16 `align:"reserved"` 24 CapLen uint32 `align:"cap_len"` 25 } 26 27 type CaptureMap interface { 28 Open() error 29 Close() error 30 Path() (string, error) 31 DumpEntries() (string, error) 32 DumpWithCallback(bpf.DumpCallback) error 33 } 34 35 type Map struct { 36 bpf.Map 37 v4 bool 38 } 39 40 type RecorderKey interface { 41 bpf.MapKey 42 ToHost() RecorderKey 43 Dump(sb *strings.Builder) 44 Map() *bpf.Map 45 } 46 47 type RecorderEntry interface { 48 bpf.MapValue 49 Dump(sb *strings.Builder) 50 } 51 52 type MapRecord struct { 53 Key RecorderKey 54 Value RecorderEntry 55 } 56 57 func (m *Map) DumpEntries() (string, error) { 58 var sb strings.Builder 59 60 cb := func(k bpf.MapKey, v bpf.MapValue) { 61 key := k.(RecorderKey) 62 key.ToHost().Dump(&sb) 63 val := v.(RecorderEntry) 64 val.Dump(&sb) 65 } 66 err := m.DumpWithCallback(cb) 67 return sb.String(), err 68 }