google / gopacket

Provides packet processing capabilities for Go
BSD 3-Clause "New" or "Revised" License
6.26k stars 1.12k forks source link

problem: get inner ip in GRE or IPoverIP #699

Open gongjw123 opened 5 years ago

gongjw123 commented 5 years ago

use "ipLayer := packet.Layer(layers.LayerTypeIPv4)" i can get outer ip, but i want to know how to get inner IP in GRE or IPIP Thanks~

negbie commented 5 years ago

Mby something like DecodeLayers(gre.Payload[8:], &decodedLayers) and check LayerTypeIPv4, LayerTypeIPv6 again?

jjunqueira commented 3 years ago

I am having a similar issue, it seems like go packet caches the IPv4 layer or something. In the GRE packets that I am seeing there are 2 IPv4 layers but both of them have the same IPs. If I collect the layers and print them out it shows that there are additional layers after GRE but printing out the details of the IPv4 layer just print the same thing twice. For example:

Layers - Ethernet,Dot1Q,IPv4,GRE,IPv4,UDP,Payload First IPv4Layer - layer: IPv4, proto: 47, srcip: 1.2.3.4, dstip: 1.2.3.5 Second IPv4Layer - layer: IPv4, proto: 47, srcip: 1.2.3.4, dstip: 1.2.3.5

I changed the IPs but the point is the first IPv4 layer and second IPv4 layer are the same. You can't seem to get the inner IP information.

redstar9451 commented 1 year ago

gre := packet.Layer(layers.LayerTypeGRE).(layers.GRE) innerPacket = gopacket.NewPacket(gre.Payload, gre.NextLayerType(), gopacket.Default) innerPacket.Layer(layers.LayerTypeIPv4).(layers.IPv4)

  1. get gre layer
  2. make a new packet with gre payload
  3. then you could get any layer in gre payload