Skip to content

Added GTPv2 Support to gopacket (New Layer)#94

Merged
mosajjal merged 6 commits intogopacket:masterfrom
vagabundor:features
Aug 11, 2025
Merged

Added GTPv2 Support to gopacket (New Layer)#94
mosajjal merged 6 commits intogopacket:masterfrom
vagabundor:features

Conversation

@vagabundor
Copy link
Copy Markdown
Contributor

Description:
This pull request introduces support for the GTPv2 protocol in the gopacket library by adding a new dedicated layer.
Motivation:
The addition of GTPv2 support expands the capabilities of the gopacket library to handle network traffic analysis involving GTPv2, which is widely used in mobile and telecommunications networks.
Testing:
All implemented features have been thoroughly tested with unit tests and verified against real-world GTPv2 traffic captures.

@mosajjal mosajjal self-assigned this May 30, 2025
@mosajjal mosajjal requested a review from Copilot May 30, 2025 20:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds full GTPv2 protocol support in gopacket by registering a new layer, implementing decoding logic, and providing unit tests.

  • Registered a new LayerTypeGTPv2 in layertypes.go
  • Implemented GTPv2 struct with DecodeFromBytes, metadata methods, and decoder in gtp2.go
  • Added gtp2_test.go to validate decoding against a sample GTPv2 packet

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
layers/layertypes.go Register new LayerTypeGTPv2 constant
layers/gtp2.go Define GTPv2 layer, decoding logic, helper(s)
layers/gtp2_test.go Unit test for GTPv2 decoding and validation
Comments suppressed due to low confidence (4)

layers/layertypes.go:134

  • [nitpick] Formatting in the layer registration is inconsistent—add a space after the comma before Decoder and align with surrounding entries to match project style.
LayerTypeGTPv2                          = gopacket.RegisterLayerType(1010, gopacket.LayerTypeMetadata{Name: "GTPv2",Decoder: gopacket.DecodeFunc(decodeGTPv2)})

layers/gtp2.go:42

  • [nitpick] Error message could include the expected minimum size to aid debugging, e.g., expected at least %d bytes, got %d bytes.
return fmt.Errorf("GTP packet too small: %d bytes", dLen)

layers/gtp2.go:10

  • [nitpick] Constant name gtp2MinimumSizeInBytes is generic; consider renaming to GTPv2HeaderBaseSize or similar to clarify its purpose.
const gtp2MinimumSizeInBytes int = 4

layers/gtp2_test.go:43

  • The expected TEID value does not match the raw packet bytes (should be 0x1FA384B5 / 530744501). Update the test to the correct value.
TEID:             1779326497,

@mosajjal mosajjal merged commit c51bcbe into gopacket:master Aug 11, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants