Skip to content

Conversation

smagnani96
Copy link
Contributor

Before this patch, the IPSecAH and IPSecESP layer would not fully implement DecodingLayer. This would prevent them to be added as a DecodingLayer to gopacket.NewDecodingLayerParser():

cannot use &IPSecAH{} (value of type *IPSecAH) as gopacket.DecodingLayer value in argument to gopacket.NewDecodingLayerParser: *IPSecAH does not implement gopacket.DecodingLayer (missing method CanDecode)

This patch implements (*IPSecAH).CanDecode() and (*IPSecESP).CanDecode() and a test to ensure they can be used as a DecodingLayer.

Before this patch, the IPSecAH and IPSecESP layer would not fully implement
DecodingLayer. This would prevent them to be added as a DecodingLayer
to gopacket.NewDecodingLayerParser():

    cannot use &IPSecAH{} (value of type *IPSecAH) as gopacket.DecodingLayer value in argument to gopacket.NewDecodingLayerParser: *IPSecAH does not implement gopacket.DecodingLayer (missing method CanDecode)

This patch implements (*IPSecAH).CanDecode() and (*IPSecESP).CanDecode()
and a test to ensure they can be used as a DecodingLayer.

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit to cilium/cilium that referenced this pull request May 7, 2025
This patch adds some extra info to our monitor output making use of the
IsIPSec()/IsWireguard() flags added in the previous patch. While doing so,
cleanup some unused and unreachable code in decoding layers (IPSecAH/IPSecESP),
given we do not provide those layers from our cache. In case we change our
mind (ex want to dump additional esp-related info such as SPI), we'd need:

1. wait for gopacket/gopacket#117 to be merged
2. update our vendor
3. add esp (ah we can ignore) in our monitor cache and decoding layers list

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit to cilium/cilium that referenced this pull request May 7, 2025
This patch adds some extra info to our monitor output making use of the
IsIPSec()/IsWireguard() flags added in the previous patch. While doing so,
cleanup some unused and unreachable code in decoding layers (IPSecAH/IPSecESP),
given we do not provide those layers from our cache. In case we change our
mind (ex want to dump additional esp-related info such as SPI), we'd need:

1. wait for gopacket/gopacket#117 to be merged
2. update our vendor
3. add esp (ah we can ignore) in our monitor cache and decoding layers list

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit to cilium/cilium that referenced this pull request May 8, 2025
In this patch, we cleanup some unused and unreachable code in decoding layers
(IPSecAH/IPSecESP), given we do not provide those layers from our cache.
In case we change our mind (ex want to dump additional esp-related info
such as SPI), we'd need:

1. wait for gopacket/gopacket#117 to be merged
2. update our vendor
3. add esp (ah we can ignore) in our monitor cache and decoding layers list

Given the previous commit, we can now tell from Monitor whether a packet
is IPSec/WireGuard, thanks to the datapath flag.

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
@smagnani96 smagnani96 marked this pull request as ready for review May 27, 2025 17:11
@mosajjal mosajjal self-assigned this May 30, 2025
@mosajjal mosajjal requested a review from Copilot May 30, 2025 20:15
Copy link
Contributor

@Copilot 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

The patch fully implements the gopacket.DecodingLayer interface for IPSec AH and ESP by adding CanDecode/NextLayerType methods, updating the decode logic to use the shared helper, and adding minimal tests.

  • Added CanDecode and NextLayerType for both IPSecAH and IPSecESP
  • Refactored decodeIPSecAH/decodeIPSecESP to delegate to decodingLayerDecoder
  • Introduced basic tests to ensure IPSecAH and IPSecESP satisfy the DecodingLayer interface

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
layers/ipsec.go Implemented CanDecode/NextLayerType, updated DecodeFromBytes & decode functions
layers/ipsec_test.go Added TestIPSecAHAsDecodingLayer and TestIPSecESPAsDecodingLayer
Comments suppressed due to low confidence (2)

layers/ipsec_test.go:120

  • The test only creates the parser but doesn't verify decoding behavior. Consider adding a minimal valid AH packet parse and asserting on decoded fields.
func TestIPSecAHAsDecodingLayer(t *testing.T) {

layers/ipsec_test.go:164

  • Similarly, this test should exercise DecodeFromBytes for ESP and validate the parsed SPI, Seq, and payload.
func TestIPSecESPAsDecodingLayer(t *testing.T) {

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mosajjal mosajjal merged commit 1b6e82a into gopacket:master Aug 1, 2025
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.

2 participants