MCPcopy Index your code
hub / github.com/cloudflare/cloudflared / Decode

Method Decode

packet/decoder.go:78–94  ·  view source on GitHub ↗
(packet RawPacket)

Source from the content-addressed store, hash-verified

76}
77
78func (pd *IPDecoder) Decode(packet RawPacket) (*IP, error) {
79 // Should decode to IP layer
80 decoded, err := pd.decodeByVersion(packet.Data)
81 if err != nil {
82 return nil, err
83 }
84
85 for _, layerType := range decoded {
86 switch layerType {
87 case layers.LayerTypeIPv4:
88 return newIPv4(pd.ipv4)
89 case layers.LayerTypeIPv6:
90 return newIPv6(pd.ipv6)
91 }
92 }
93 return nil, fmt.Errorf("no ip layer is decoded")
94}
95
96func (pd *IPDecoder) decodeByVersion(packet []byte) ([]gopacket.LayerType, error) {
97 version, err := FindIPVersion(packet)

Callers 15

TestDecodeIPFunction · 0.95
TestDecodeICMPFunction · 0.95
TestDecodeBadPacketsFunction · 0.95
FuzzIPDecoderFunction · 0.95
decodeOriginCertFunction · 0.45
DeserializeHeadersFunction · 0.45
WriteMethod · 0.45
handlePacketMethod · 0.45
handleFullPacketMethod · 0.45

Calls 4

decodeByVersionMethod · 0.95
newIPv4Function · 0.85
newIPv6Function · 0.85
ErrorfMethod · 0.80

Tested by 11

TestDecodeIPFunction · 0.76
TestDecodeICMPFunction · 0.76
TestDecodeBadPacketsFunction · 0.76
FuzzIPDecoderFunction · 0.76
mockRequestFunction · 0.36
TestSystemHandlerFunction · 0.36
TestTunnelStateHandlerFunction · 0.36
TestConfigurationHandlerFunction · 0.36
TestDecodeFunction · 0.36
TestDecodeFunction · 0.36
testRequestFunction · 0.36