-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
flow.go
46 lines (41 loc) · 1.08 KB
/
flow.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
// SPDX-License-Identifier: Apache-2.0
// Copyright 2019 Authors of Hubble
package v1
import (
pb "github.com/cilium/cilium/api/v1/flow"
monitorAPI "github.com/cilium/cilium/pkg/monitor/api"
)
// FlowProtocol returns the protocol best describing the flow. If available,
// this is the L7 protocol name, then the L4 protocol name.
func FlowProtocol(flow *pb.Flow) string {
switch flow.GetEventType().Type {
case monitorAPI.MessageTypeAccessLog:
if l7 := flow.GetL7(); l7 != nil {
switch {
case l7.GetDns() != nil:
return "DNS"
case l7.GetHttp() != nil:
return "HTTP"
case l7.GetKafka() != nil:
return "Kafka"
}
}
return "Unknown L7"
case monitorAPI.MessageTypeDrop, monitorAPI.MessageTypeTrace,
monitorAPI.MessageTypePolicyVerdict, monitorAPI.MessageTypeCapture:
if l4 := flow.GetL4(); l4 != nil {
switch {
case l4.GetTCP() != nil:
return "TCP"
case l4.GetUDP() != nil:
return "UDP"
case l4.GetICMPv4() != nil:
return "ICMPv4"
case l4.GetICMPv6() != nil:
return "ICMPv6"
}
}
return "Unknown L4"
}
return "Unknown flow"
}