While trying to assign an address from his framed /29 route to the internal side of his Linksys AM300 router, Phillip S. received an unexpected "Local IP Address is not valid" error.

Being a web script error, Phillip correctly figured that he could dig into what condition would make the address come up as invalid. Turns out, his problem was that the router considers any IP address starting with 115 to be invalid, but Phillip found that there were a few other instances of hard coding and magic number abuse. On a positive note, at least it's not device-side code.

/* IANA Reserved IP */
if (((sub_addr[0] >= 0) && (sub_addr[0] <= 2)) || sub_addr[0] == 5 || sub_addr[0] == 7 ||
  sub_addr[0] == 23 || sub_addr[0] == 27 || sub_addr[0] == 31 || sub_addr[0] == 36 ||
  sub_addr[0] == 37 || sub_addr[0] == 39 || sub_addr[0] == 42 ||
  ((sub_addr[0] >=92) && (sub_addr[0] <= 120)) || sub_addr[0] == 127 ||
  ((sub_addr[0] >= 173) && (sub_addr[0] <= 187)) || sub_addr[0] == 197 || sub_addr[0] >= 223)
    return false;

if(sub_addr[0] < 128) /* A class */
{
  if(sub_addr[0] == 0 || sub_addr[0] == 127)
    return false;
  host_id = sub_addr[1] * 0x10000 + sub_addr[2] * 0x100 + sub_addr[3] * 0x1;
  if(host_id == 0 || host_id == 0xffffff)
    return false;
}
else if(sub_addr[0] < 192) /* B class */
{
  host_id = sub_addr[2] * 0x100 + sub_addr[3] * 0x1;
  if(host_id == 0 || host_id == 0xffff)
    return false;
}
else if(sub_addr[0] < 224) /* C class */
{
  host_id = sub_addr[3] * 0x1;
  if(host_id == 0 || host_id == 0xff)
    return false;
}
else /* Limit broadcast, Multicast net */
{
  return false;
}