github.com/castai/kvisor@v1.7.1-0.20240516114728-b3572a2607b5/pkg/ebpftracer/types/types.go (about) 1 package types 2 3 import ( 4 "net/netip" 5 6 castpb "github.com/castai/kvisor/api/v1/runtime" 7 "github.com/castai/kvisor/pkg/bucketcache" 8 "github.com/castai/kvisor/pkg/containers" 9 "github.com/castai/kvisor/pkg/proc" 10 ) 11 12 type Event struct { 13 Context *EventContext 14 Container *containers.Container 15 Args Args 16 } 17 18 type AddrTuple struct { 19 Src netip.AddrPort 20 Dst netip.AddrPort 21 } 22 23 type ProtoDNS = castpb.DNS 24 25 type PIDsPerNamespace = bucketcache.BucketCache[proc.NamespaceID, proc.PID] 26 27 func namespaceHash(ns proc.NamespaceID) uint32 { 28 return uint32(ns) 29 } 30 31 func NewPIDsPerNamespaceCache(size, maxBucketSize uint32) (*PIDsPerNamespace, error) { 32 result, err := bucketcache.New[proc.NamespaceID, proc.PID](size, maxBucketSize, namespaceHash) 33 if err != nil { 34 return nil, err 35 } 36 37 return (*PIDsPerNamespace)(result), nil 38 } 39 40 type FlowDirection uint8 41 42 const ( 43 FlowDirectionUnknown FlowDirection = iota 44 FlowDirectionIngress 45 FlowDirectionEgress 46 ) 47 48 var flowDirectionNames = map[FlowDirection]string{ 49 FlowDirectionIngress: "INGRESS", 50 FlowDirectionEgress: "EGRESS", 51 } 52 53 func (f FlowDirection) String() string { 54 if name, found := flowDirectionNames[f]; found { 55 return name 56 } 57 58 return "UNKNOWN" 59 } 60 61 type NetflowType uint8 62 63 const ( 64 NetflowTypeUnknown NetflowType = iota 65 NetflowTypeTCPBegin 66 NetflowTypeTCPSample 67 NetflowTypeTCPEnd 68 ) 69 70 func (f NetflowType) String() string { 71 if name, found := flowTypesNames[f]; found { 72 return name 73 } 74 75 return "UNKNOWN" 76 } 77 78 var flowTypesNames = map[NetflowType]string{ 79 NetflowTypeTCPBegin: "TCP_BEGIN", 80 NetflowTypeTCPSample: "TCP_SAMPLE", 81 NetflowTypeTCPEnd: "TCP_END", 82 }