-
-
Notifications
You must be signed in to change notification settings - Fork 89
ipsec: implement DecodingLayer #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ipsec: implement DecodingLayer #117
Conversation
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>
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>
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>
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>
There was a problem hiding this 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
andNextLayerType
for both IPSecAH and IPSecESP - Refactored
decodeIPSecAH
/decodeIPSecESP
to delegate todecodingLayerDecoder
- Introduced basic tests to ensure
IPSecAH
andIPSecESP
satisfy theDecodingLayer
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>
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():
This patch implements (*IPSecAH).CanDecode() and (*IPSecESP).CanDecode() and a test to ensure they can be used as a DecodingLayer.