Merge lp:~mpontillo/maas/fix-bogus-mac-in-moved-event--bug-1609194 into lp:~maas-committers/maas/trunk

Proposed by Mike Pontillo
Status: Merged
Approved by: Mike Pontillo
Approved revision: no longer in the source branch.
Merged at revision: 5292
Proposed branch: lp:~mpontillo/maas/fix-bogus-mac-in-moved-event--bug-1609194
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 69 lines (+38/-3)
2 files modified
src/provisioningserver/utils/arp.py (+6/-3)
src/provisioningserver/utils/tests/test_arp.py (+32/-0)
To merge this branch: bzr merge lp:~mpontillo/maas/fix-bogus-mac-in-moved-event--bug-1609194
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+303879@code.launchpad.net

Commit message

Fix bug where ARP parser considers the all-zeroes MAC address to be valid.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) :
review: Needs Information
Revision history for this message
Mike Pontillo (mpontillo) :
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Sounds good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/provisioningserver/utils/arp.py'
--- src/provisioningserver/utils/arp.py 2016-08-09 00:14:06 +0000
+++ src/provisioningserver/utils/arp.py 2016-08-25 16:11:01 +0000
@@ -183,17 +183,20 @@
183 # This is an ARP request.183 # This is an ARP request.
184 # We can find a binding in the (source_eui, source_ip)184 # We can find a binding in the (source_eui, source_ip)
185 source_ip = self.source_ip185 source_ip = self.source_ip
186 if int(source_ip) != 0:186 source_eui = self.source_eui
187 if int(source_ip) != 0 and int(source_eui) != 0:
187 yield (source_ip, self.source_eui)188 yield (source_ip, self.source_eui)
188 elif self.operation == 2:189 elif self.operation == 2:
189 # This is an ARP reply.190 # This is an ARP reply.
190 # We can find a binding in both the (source_eui, source_ip) and191 # We can find a binding in both the (source_eui, source_ip) and
191 # the (target_eui, target_ip).192 # the (target_eui, target_ip).
192 source_ip = self.source_ip193 source_ip = self.source_ip
194 source_eui = self.source_eui
193 target_ip = self.target_ip195 target_ip = self.target_ip
194 if int(source_ip) != 0:196 target_eui = self.target_eui
197 if int(source_ip) != 0 and int(source_eui) != 0:
195 yield (source_ip, self.source_eui)198 yield (source_ip, self.source_eui)
196 if int(target_ip) != 0:199 if int(target_ip) != 0 and int(target_eui) != 0:
197 yield (target_ip, self.target_eui)200 yield (target_ip, self.target_eui)
198201
199 def write(self, out=sys.stdout):202 def write(self, out=sys.stdout):
200203
=== modified file 'src/provisioningserver/utils/tests/test_arp.py'
--- src/provisioningserver/utils/tests/test_arp.py 2016-08-09 00:14:06 +0000
+++ src/provisioningserver/utils/tests/test_arp.py 2016-08-25 16:11:01 +0000
@@ -217,6 +217,38 @@
217 self.assertItemsEqual(217 self.assertItemsEqual(
218 arp.bindings(), [(IPAddress(pkt_sender_ip), EUI(pkt_sender_mac))])218 arp.bindings(), [(IPAddress(pkt_sender_ip), EUI(pkt_sender_mac))])
219219
220 def test__bindings__skips_null_source_eui_for_request(self):
221 pkt_sender_mac = '00:00:00:00:00:00'
222 pkt_sender_ip = '192.168.0.1'
223 pkt_target_ip = '192.168.0.2'
224 pkt_target_mac = '00:00:00:00:00:00'
225 arp = ARP(make_arp_packet(
226 pkt_sender_ip, pkt_sender_mac, pkt_target_ip, pkt_target_mac,
227 op=ARP_OPERATION.REQUEST))
228 self.assertItemsEqual(arp.bindings(), [])
229
230 def test__bindings__skips_null_source_eui_in_reply(self):
231 pkt_sender_mac = '00:00:00:00:00:00'
232 pkt_sender_ip = '192.168.0.1'
233 pkt_target_ip = '192.168.0.2'
234 pkt_target_mac = '02:03:04:05:06:07'
235 arp = ARP(make_arp_packet(
236 pkt_sender_ip, pkt_sender_mac, pkt_target_ip, pkt_target_mac,
237 op=ARP_OPERATION.REPLY))
238 self.assertItemsEqual(
239 arp.bindings(), [(IPAddress(pkt_target_ip), EUI(pkt_target_mac))])
240
241 def test__bindings__skips_null_target_eui_in_reply(self):
242 pkt_sender_mac = '01:02:03:04:05:06'
243 pkt_sender_ip = '192.168.0.1'
244 pkt_target_ip = '192.168.0.2'
245 pkt_target_mac = '00:00:00:00:00:00'
246 arp = ARP(make_arp_packet(
247 pkt_sender_ip, pkt_sender_mac, pkt_target_ip, pkt_target_mac,
248 op=ARP_OPERATION.REPLY))
249 self.assertItemsEqual(
250 arp.bindings(), [(IPAddress(pkt_sender_ip), EUI(pkt_sender_mac))])
251
220252
221class TestUpdateBindingsAndGetEvent(MAASTestCase):253class TestUpdateBindingsAndGetEvent(MAASTestCase):
222254