MCPcopy
hub / github.com/cloudflare/cloudflared / NewIPDecoder

Function NewIPDecoder

packet/decoder.go:53–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

51}
52
53func NewIPDecoder() *IPDecoder {
54 var (
55 ipv4 layers.IPv4
56 ipv6 layers.IPv6
57 )
58 dlpv4 := gopacket.NewDecodingLayerParser(layers.LayerTypeIPv4)
59 dlpv4.SetDecodingLayerContainer(gopacket.DecodingLayerSparse(nil))
60 dlpv4.AddDecodingLayer(&ipv4)
61 // Stop parsing when it encounter a layer that it doesn't have a parser
62 dlpv4.IgnoreUnsupported = true
63
64 dlpv6 := gopacket.NewDecodingLayerParser(layers.LayerTypeIPv6)
65 dlpv6.SetDecodingLayerContainer(gopacket.DecodingLayerSparse(nil))
66 dlpv6.AddDecodingLayer(&ipv6)
67 dlpv6.IgnoreUnsupported = true
68
69 return &IPDecoder{
70 ipv4: &ipv4,
71 ipv6: &ipv6,
72 layers: 1,
73 v4parser: dlpv4,
74 v6parser: dlpv6,
75 }
76}
77
78func (pd *IPDecoder) Decode(packet RawPacket) (*IP, error) {
79 // Should decode to IP layer

Callers 5

NewICMPDecoderFunction · 0.85
TestDecodeIPFunction · 0.85
TestDecodeICMPFunction · 0.85
TestDecodeBadPacketsFunction · 0.85
FuzzIPDecoderFunction · 0.85

Calls

no outgoing calls

Tested by 4

TestDecodeIPFunction · 0.68
TestDecodeICMPFunction · 0.68
TestDecodeBadPacketsFunction · 0.68
FuzzIPDecoderFunction · 0.68