Skip to content

Commit 5885a85

Browse files
Fix duplicate address detection
1 parent ae8f62d commit 5885a85

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/firejail/arp.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,26 @@ int arp_check(const char *dev, uint32_t destaddr) {
230230
if (framerx[12] != (ETH_P_ARP / 256) || framerx[13] != (ETH_P_ARP % 256))
231231
continue;
232232
memcpy(&hdr, framerx + 14, sizeof(ArpHdr));
233-
if (hdr.opcode == htons(1))
234-
continue;
235-
if (hdr.opcode == htons(2)) {
236-
// check my mac and my address
237-
if (memcmp(ifr.ifr_hwaddr.sa_data, hdr.target_mac, 6) != 0)
238-
continue;
233+
if (hdr.opcode == htons(1)) {
234+
// request, check if someone else is probing the same IP
235+
if (memcmp(ifr.ifr_hwaddr.sa_data, hdr.sender_mac, 6) == 0)
236+
continue; // it was our own probe, ignore it
237+
239238
uint32_t ip;
240239
memcpy(&ip, hdr.target_ip, 4);
241-
if (ip != srcaddr) {
240+
if (ip != destaddr) {
241+
continue;
242+
}
243+
close(sock);
244+
return -1;
245+
}
246+
if (hdr.opcode == htons(2)) {
247+
// reply, check if someone else has the address we are probing for
248+
/*if (memcmp(ifr.ifr_hwaddr.sa_data, hdr.target_mac, 6) != 0)
249+
continue;*/
250+
uint32_t ip;
251+
memcpy(&ip, hdr.sender_ip, 4);
252+
if (ip != destaddr) {
242253
continue;
243254
}
244255
close(sock);

0 commit comments

Comments
 (0)