Skip to content

Commit

Permalink
Fix bug in xfrmStateGetOrDelete (#155)
Browse files Browse the repository at this point in the history
- It fails if source address attribute
  is passed in 4 byte notation

Signed-off-by: Alessandro Boch <aboch@docker.com>
  • Loading branch information
aboch authored and vishvananda committed Jul 29, 2016
1 parent 4e67e44 commit 9dee363
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion xfrm_state_linux.go
Expand Up @@ -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)
}

Expand Down
6 changes: 4 additions & 2 deletions xfrm_state_test.go
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 9dee363

Please sign in to comment.