From 9dee363ad4abbc3c9a4a24a9f1e33363e224b111 Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Fri, 29 Jul 2016 08:59:42 -0700 Subject: [PATCH] Fix bug in xfrmStateGetOrDelete (#155) - It fails if source address attribute is passed in 4 byte notation Signed-off-by: Alessandro Boch --- xfrm_state_linux.go | 2 +- xfrm_state_test.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/xfrm_state_linux.go b/xfrm_state_linux.go index b100f71b..7b0b2e75 100644 --- a/xfrm_state_linux.go +++ b/xfrm_state_linux.go @@ -213,7 +213,7 @@ func (h *Handle) xfrmStateGetOrDelete(state *XfrmState, nlProto int) (*XfrmState req.AddData(out) } if state.Src != nil { - out := nl.NewRtAttr(nl.XFRMA_SRCADDR, state.Src) + out := nl.NewRtAttr(nl.XFRMA_SRCADDR, state.Src.To16()) req.AddData(out) } diff --git a/xfrm_state_test.go b/xfrm_state_test.go index 954fcbe6..9a199f0c 100644 --- a/xfrm_state_test.go +++ b/xfrm_state_test.go @@ -160,8 +160,9 @@ func TestXfrmStateUpdateLimits(t *testing.T) { func getBaseState() *XfrmState { return &XfrmState{ - Src: net.ParseIP("127.0.0.1"), - Dst: net.ParseIP("127.0.0.2"), + // Force 4 byte notation for the IPv4 addresses + Src: net.ParseIP("127.0.0.1").To4(), + Dst: net.ParseIP("127.0.0.2").To4(), Proto: XFRM_PROTO_ESP, Mode: XFRM_MODE_TUNNEL, Spi: 1, @@ -184,6 +185,7 @@ func getAeadState() *XfrmState { // 128 key bits + 32 salt bits k, _ := hex.DecodeString("d0562776bf0e75830ba3f7f8eb6c09b555aa1177") return &XfrmState{ + // Leave IPv4 addresses in Ipv4 in IPv6 notation Src: net.ParseIP("192.168.1.1"), Dst: net.ParseIP("192.168.2.2"), Proto: XFRM_PROTO_ESP,