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

Method Decode

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

Source from the content-addressed store, hash-verified

140}
141
142func (pd *ICMPDecoder) Decode(packet RawPacket) (*ICMP, error) {
143 // Should decode to IP and optionally ICMP layer
144 decoded, err := pd.decodeByVersion(packet.Data)
145 if err != nil {
146 return nil, err
147 }
148
149 for _, layerType := range decoded {
150 switch layerType {
151 case layers.LayerTypeICMPv4:
152 ipv4, err := newIPv4(pd.ipv4)
153 if err != nil {
154 return nil, err
155 }
156 msg, err := icmp.ParseMessage(int(layers.IPProtocolICMPv4), append(pd.icmpv4.Contents, pd.icmpv4.Payload...))
157 if err != nil {
158 return nil, errors.Wrap(err, "failed to parse ICMPv4 message")
159 }
160 return &ICMP{
161 IP: ipv4,
162 Message: msg,
163 }, nil
164 case layers.LayerTypeICMPv6:
165 ipv6, err := newIPv6(pd.ipv6)
166 if err != nil {
167 return nil, err
168 }
169 msg, err := icmp.ParseMessage(int(layers.IPProtocolICMPv6), append(pd.icmpv6.Contents, pd.icmpv6.Payload...))
170 if err != nil {
171 return nil, errors.Wrap(err, "failed to parse ICMPv6")
172 }
173 return &ICMP{
174 IP: ipv6,
175 Message: msg,
176 }, nil
177 }
178 }
179 layers := make([]string, len(decoded))
180 for i, l := range decoded {
181 layers[i] = l.String()
182 }
183 return nil, fmt.Errorf("Expect to decode IP and ICMP layers, got %s", layers)
184}

Callers 11

validateEchoFlowFunction · 0.95
assertTTLExceedFunction · 0.95
validateIPPacketFunction · 0.95
assertTTLExceedPacketFunction · 0.95
TestChecksumFunction · 0.95
TestDecodeIPFunction · 0.95
TestDecodeICMPFunction · 0.95
TestDecodeBadPacketsFunction · 0.95
FuzzICMPDecoderFunction · 0.95

Calls 5

newIPv4Function · 0.85
newIPv6Function · 0.85
decodeByVersionMethod · 0.80
ErrorfMethod · 0.80
StringMethod · 0.65

Tested by 11

validateEchoFlowFunction · 0.76
assertTTLExceedFunction · 0.76
validateIPPacketFunction · 0.76
assertTTLExceedPacketFunction · 0.76
TestChecksumFunction · 0.76
TestDecodeIPFunction · 0.76
TestDecodeICMPFunction · 0.76
TestDecodeBadPacketsFunction · 0.76
FuzzICMPDecoderFunction · 0.76