Charles Chan
Committed by Gerrit Code Review

Fix possible concurrency flaws in ArpHandler

Change-Id: I7e869453aefa580246af593c211aa98fb417f5cc
...@@ -88,7 +88,6 @@ public class ArpHandler { ...@@ -88,7 +88,6 @@ public class ArpHandler {
88 } 88 }
89 89
90 private void handleArpRequest(DeviceId deviceId, ConnectPoint inPort, Ethernet payload) { 90 private void handleArpRequest(DeviceId deviceId, ConnectPoint inPort, Ethernet payload) {
91 -
92 ARP arpRequest = (ARP) payload.getPayload(); 91 ARP arpRequest = (ARP) payload.getPayload();
93 HostId targetHostId = HostId.hostId(MacAddress.valueOf( 92 HostId targetHostId = HostId.hostId(MacAddress.valueOf(
94 arpRequest.getTargetHardwareAddress())); 93 arpRequest.getTargetHardwareAddress()));
...@@ -98,14 +97,16 @@ public class ArpHandler { ...@@ -98,14 +97,16 @@ public class ArpHandler {
98 Ip4Address targetAddress = Ip4Address.valueOf(arpRequest.getTargetProtocolAddress()); 97 Ip4Address targetAddress = Ip4Address.valueOf(arpRequest.getTargetProtocolAddress());
99 98
100 sendArpResponse(arpRequest, config.getRouterMacForAGatewayIp(targetAddress)); 99 sendArpResponse(arpRequest, config.getRouterMacForAGatewayIp(targetAddress));
101 - // ARP request for known hosts 100 + } else {
102 - } else if (srManager.hostService.getHost(targetHostId) != null) { 101 + Host targetHost = srManager.hostService.getHost(targetHostId);
103 - MacAddress targetMac = srManager.hostService.getHost(targetHostId).mac(); 102 + // ARP request for known hosts
104 - sendArpResponse(arpRequest, targetMac); 103 + if (targetHost != null) {
105 - 104 + sendArpResponse(arpRequest, targetHost.mac());
106 - // ARP request for unknown host in the subnet 105 +
107 - } else if (isArpReqForSubnet(deviceId, arpRequest)) { 106 + // ARP request for unknown host in the subnet
108 - flood(payload, inPort); 107 + } else if (isArpReqForSubnet(deviceId, arpRequest)) {
108 + flood(payload, inPort);
109 + }
109 } 110 }
110 } 111 }
111 112
......