diff --git a/staticlibs/device/com/android/net/module/util/netlink/RtNetlinkRouteMessage.java b/staticlibs/device/com/android/net/module/util/netlink/RtNetlinkRouteMessage.java index c21e25fcf6c987bb7b1f713d65bdd968c889dbf6..b2b1e9302aa9655ab9c72bfb3ccf0b008b9c88ea 100644 --- a/staticlibs/device/com/android/net/module/util/netlink/RtNetlinkRouteMessage.java +++ b/staticlibs/device/com/android/net/module/util/netlink/RtNetlinkRouteMessage.java @@ -98,6 +98,13 @@ public class RtNetlinkRouteMessage extends NetlinkMessage { mSinceLastUseMillis = -1; } + /** + * Returns the rtnetlink family. + */ + public short getRtmFamily() { + return mRtmsg.family; + } + /** * Returns if the route is resolved. This is always true for unicast, * and may be false only for multicast routes. diff --git a/staticlibs/tests/unit/src/com/android/net/module/util/netlink/RtNetlinkRouteMessageTest.java b/staticlibs/tests/unit/src/com/android/net/module/util/netlink/RtNetlinkRouteMessageTest.java index ca407d3fc043f64eccf31ccc206f922f77079e9f..50b827815004c8931a2b277598898a7e856bb6c1 100644 --- a/staticlibs/tests/unit/src/com/android/net/module/util/netlink/RtNetlinkRouteMessageTest.java +++ b/staticlibs/tests/unit/src/com/android/net/module/util/netlink/RtNetlinkRouteMessageTest.java @@ -16,7 +16,9 @@ package com.android.net.module.util.netlink; +import static android.system.OsConstants.AF_INET6; import static android.system.OsConstants.NETLINK_ROUTE; +import static com.android.net.module.util.netlink.NetlinkConstants.RTNL_FAMILY_IP6MR; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -342,4 +344,24 @@ public class RtNetlinkRouteMessageTest { + "}"; assertEquals(expected, routeMsg.toString()); } + + @Test + public void testGetRtmFamily_RTNL_FAMILY_IP6MR() { + final ByteBuffer byteBuffer = toByteBuffer(RTM_NEWROUTE_MULTICAST_IPV6_HEX); + byteBuffer.order(ByteOrder.LITTLE_ENDIAN); // For testing. + final NetlinkMessage msg = NetlinkMessage.parse(byteBuffer, NETLINK_ROUTE); + final RtNetlinkRouteMessage routeMsg = (RtNetlinkRouteMessage) msg; + + assertEquals(RTNL_FAMILY_IP6MR, routeMsg.getRtmFamily()); + } + + @Test + public void testGetRtmFamily_AF_INET6() { + final ByteBuffer byteBuffer = toByteBuffer(RTM_NEWROUTE_HEX); + byteBuffer.order(ByteOrder.LITTLE_ENDIAN); // For testing. + final NetlinkMessage msg = NetlinkMessage.parse(byteBuffer, NETLINK_ROUTE); + final RtNetlinkRouteMessage routeMsg = (RtNetlinkRouteMessage) msg; + + assertEquals(AF_INET6, routeMsg.getRtmFamily()); + } }