Added GTPv2 Support to gopacket (New Layer)#94
Merged
mosajjal merged 6 commits intogopacket:masterfrom Aug 11, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
GTPv2struct withDecodeFromBytes, metadata methods, and decoder ingtp2.go - Added
gtp2_test.goto 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
Decoderand 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
gtp2MinimumSizeInBytesis generic; consider renaming toGTPv2HeaderBaseSizeor 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,
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.