github.com/cilium/cilium@v1.16.2/pkg/hubble/api/v1/flow.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Hubble
     3  
     4  package v1
     5  
     6  import (
     7  	pb "github.com/cilium/cilium/api/v1/flow"
     8  	monitorAPI "github.com/cilium/cilium/pkg/monitor/api"
     9  )
    10  
    11  // FlowProtocol returns the protocol best describing the flow. If available,
    12  // this is the L7 protocol name, then the L4 protocol name.
    13  func FlowProtocol(flow *pb.Flow) string {
    14  	switch flow.GetEventType().GetType() {
    15  	case monitorAPI.MessageTypeAccessLog:
    16  		if l7 := flow.GetL7(); l7 != nil {
    17  			switch {
    18  			case l7.GetDns() != nil:
    19  				return "DNS"
    20  			case l7.GetHttp() != nil:
    21  				return "HTTP"
    22  			case l7.GetKafka() != nil:
    23  				return "Kafka"
    24  			}
    25  		}
    26  		return "Unknown L7"
    27  
    28  	case monitorAPI.MessageTypeDrop, monitorAPI.MessageTypeTrace,
    29  		monitorAPI.MessageTypePolicyVerdict, monitorAPI.MessageTypeCapture:
    30  		if l4 := flow.GetL4(); l4 != nil {
    31  			switch {
    32  			case l4.GetTCP() != nil:
    33  				return "TCP"
    34  			case l4.GetUDP() != nil:
    35  				return "UDP"
    36  			case l4.GetICMPv4() != nil:
    37  				return "ICMPv4"
    38  			case l4.GetICMPv6() != nil:
    39  				return "ICMPv6"
    40  			case l4.GetSCTP() != nil:
    41  				return "SCTP"
    42  			}
    43  		}
    44  		return "Unknown L4"
    45  	}
    46  
    47  	return "Unknown flow"
    48  }