hostinet: fix parsing route netlink message

We wrongly parses output interface as gateway address.
The fix is straightforward.

Fixes #638

Signed-off-by: Jianfeng Tan <henry.tjf@antfin.com>
Change-Id: Ia4bab31f3c238b0278ea57ab22590fad00eaf061
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/gvisor/pull/684 from tanjianfeng:fix-638 b940e810367ad1273519bfa594f4371bdd293e83
PiperOrigin-RevId: 264211336
This commit is contained in:
Jianfeng Tan 2019-08-19 12:09:08 -07:00 committed by gVisor bot
parent bd826092fe
commit a63f88855f
1 changed files with 7 additions and 1 deletions

View File

@ -203,8 +203,14 @@ func ExtractHostRoutes(routeMsgs []syscall.NetlinkMessage) ([]inet.Route, error)
inetRoute.DstAddr = attr.Value
case syscall.RTA_SRC:
inetRoute.SrcAddr = attr.Value
case syscall.RTA_OIF:
case syscall.RTA_GATEWAY:
inetRoute.GatewayAddr = attr.Value
case syscall.RTA_OIF:
expected := int(binary.Size(inetRoute.OutputInterface))
if len(attr.Value) != expected {
return nil, fmt.Errorf("RTM_GETROUTE returned RTM_NEWROUTE message with invalid attribute data length (%d bytes, expected %d bytes)", len(attr.Value), expected)
}
binary.Unmarshal(attr.Value, usermem.ByteOrder, &inetRoute.OutputInterface)
}
}