do not store boradcast addresses in ARP table, store only local addresses, fix comparing with broadcast addr
Stefan Schuermans

Stefan Schuermans commited on 2012-04-04 22:24:19
Showing 1 changed files, with 27 additions and 1 deletions.

... ...
@@ -110,7 +110,12 @@ void arp_recv(void *ptr, unsigned int sz)
110 110
     return;
111 111
 
112 112
   // source MAC is broadcast MAC -> broken packet / attac -> get lost
113
-  if (mac_eq(arp_pack->arp_hdr.src_mac, "\xFF\xFF\xFF\xFF\xFF\xFF"))
113
+  if (arp_pack->arp_hdr.src_mac[0] == 0xFF &&
114
+      arp_pack->arp_hdr.src_mac[1] == 0xFF &&
115
+      arp_pack->arp_hdr.src_mac[2] == 0xFF &&
116
+      arp_pack->arp_hdr.src_mac[3] == 0xFF &&
117
+      arp_pack->arp_hdr.src_mac[4] == 0xFF &&
118
+      arp_pack->arp_hdr.src_mac[5] == 0xFF)
114 119
     return;
115 120
 
116 121
   // ARP request for own IP address
... ...
@@ -222,6 +227,27 @@ void arp_store(unsigned char ip[4], unsigned char mac[6])
222 227
 {
223 228
   unsigned int i, j;
224 229
 
230
+  // do not store broadcast MAC
231
+  if (mac[0] == 0xFF && mac[1] == 0xFF && mac[2] == 0xFF &&
232
+      mac[3] == 0xFF && mac[4] == 0xFF && mac[5] == 0xFF)
233
+    return;
234
+
235
+  // do not store link-local broadcast IP
236
+  if (ip[0] == 0xFF && ip[1] == 0xFF && ip[2] == 0xFF && ip[3] == 0xFF)
237
+    return;
238
+  // do not store non-local IPs
239
+  if ((ip[0] & config_ip.mask[0]) != (config_ip.ip[0] & config_ip.mask[0]) ||
240
+      (ip[1] & config_ip.mask[1]) != (config_ip.ip[1] & config_ip.mask[1]) ||
241
+      (ip[2] & config_ip.mask[2]) != (config_ip.ip[2] & config_ip.mask[2]) ||
242
+      (ip[3] & config_ip.mask[3]) != (config_ip.ip[3] & config_ip.mask[3]))
243
+    return;
244
+  // do not store broadcast IP
245
+  if (ip[0] == (config_ip.ip[0] | ~config_ip.mask[0]) &&
246
+      ip[1] == (config_ip.ip[1] | ~config_ip.mask[1]) &&
247
+      ip[2] == (config_ip.ip[2] | ~config_ip.mask[2]) &&
248
+      ip[3] == (config_ip.ip[3] | ~config_ip.mask[3]))
249
+    return;
250
+
225 251
   // search IP in ARP table
226 252
   for (i = 0; i < count(arp_tab); ++i) {
227 253
     if ((arp_tab[i].flags & ARP_TAB_FLAG_IN_USE) &&
228 254