Merge "Don't crash when receiving an RTM_DELNEIGH or NUD_FAILED." am: 941a53ce91 am: 81dd21611d

Change-Id: Ie7060e6408acd73f1a5d2456d030a1958df32847
This commit is contained in:
Lorenzo Colitti
2020-04-14 09:21:19 +00:00
committed by Automerger Merge Worker
2 changed files with 12 additions and 5 deletions

View File

@@ -122,6 +122,8 @@ public class IpServer extends StateMachine {
// TODO: have this configurable // TODO: have this configurable
private static final int DHCP_LEASE_TIME_SECS = 3600; private static final int DHCP_LEASE_TIME_SECS = 3600;
private static final MacAddress NULL_MAC_ADDRESS = MacAddress.fromString("00:00:00:00:00:00");
private static final String TAG = "IpServer"; private static final String TAG = "IpServer";
private static final boolean DBG = false; private static final boolean DBG = false;
private static final boolean VDBG = false; private static final boolean VDBG = false;
@@ -902,9 +904,12 @@ public class IpServer extends StateMachine {
return; return;
} }
// When deleting rules, we still need to pass a non-null MAC, even though it's ignored.
// Do this here instead of in the Ipv6ForwardingRule constructor to ensure that we never
// add rules with a null MAC, only delete them.
MacAddress dstMac = e.isValid() ? e.macAddr : NULL_MAC_ADDRESS;
Ipv6ForwardingRule rule = new Ipv6ForwardingRule(upstreamIfindex, Ipv6ForwardingRule rule = new Ipv6ForwardingRule(upstreamIfindex,
mInterfaceParams.index, (Inet6Address) e.ip, mInterfaceParams.macAddr, mInterfaceParams.index, (Inet6Address) e.ip, mInterfaceParams.macAddr, dstMac);
e.macAddr);
if (e.isValid()) { if (e.isValid()) {
addIpv6ForwardingRule(rule); addIpv6ForwardingRule(rule);
} else { } else {

View File

@@ -587,6 +587,7 @@ public class IpServerTest {
final InetAddress neighB = InetAddresses.parseNumericAddress("2001:db8::2"); final InetAddress neighB = InetAddresses.parseNumericAddress("2001:db8::2");
final InetAddress neighLL = InetAddresses.parseNumericAddress("fe80::1"); final InetAddress neighLL = InetAddresses.parseNumericAddress("fe80::1");
final InetAddress neighMC = InetAddresses.parseNumericAddress("ff02::1234"); final InetAddress neighMC = InetAddresses.parseNumericAddress("ff02::1234");
final MacAddress macNull = MacAddress.fromString("00:00:00:00:00:00");
final MacAddress macA = MacAddress.fromString("00:00:00:00:00:0a"); final MacAddress macA = MacAddress.fromString("00:00:00:00:00:0a");
final MacAddress macB = MacAddress.fromString("11:22:33:00:00:0b"); final MacAddress macB = MacAddress.fromString("11:22:33:00:00:0b");
@@ -612,13 +613,14 @@ public class IpServerTest {
verifyNoMoreInteractions(mNetd); verifyNoMoreInteractions(mNetd);
// A neighbor that is no longer valid causes the rule to be removed. // A neighbor that is no longer valid causes the rule to be removed.
recvNewNeigh(myIfindex, neighA, NUD_FAILED, macA); // NUD_FAILED events do not have a MAC address.
verify(mNetd).tetherOffloadRuleRemove(matches(UPSTREAM_IFINDEX, neighA, macA)); recvNewNeigh(myIfindex, neighA, NUD_FAILED, null);
verify(mNetd).tetherOffloadRuleRemove(matches(UPSTREAM_IFINDEX, neighA, macNull));
reset(mNetd); reset(mNetd);
// A neighbor that is deleted causes the rule to be removed. // A neighbor that is deleted causes the rule to be removed.
recvDelNeigh(myIfindex, neighB, NUD_STALE, macB); recvDelNeigh(myIfindex, neighB, NUD_STALE, macB);
verify(mNetd).tetherOffloadRuleRemove(matches(UPSTREAM_IFINDEX, neighB, macB)); verify(mNetd).tetherOffloadRuleRemove(matches(UPSTREAM_IFINDEX, neighB, macNull));
reset(mNetd); reset(mNetd);
// Upstream changes result in deleting and re-adding the rules. // Upstream changes result in deleting and re-adding the rules.