pxe: fix ip_ok()
authorH. Peter Anvin <hpa@zytor.com>
Fri, 25 Jun 2010 03:55:43 +0000 (20:55 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Fri, 25 Jun 2010 03:55:43 +0000 (20:55 -0700)
Make it easier to read, but fix the address for the loopback network
(127, not 255).

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
core/fs/pxe/pxe.c
core/fs/pxe/pxe.h

index e2bd29c..231c4e5 100644 (file)
@@ -172,15 +172,17 @@ static int hexbyte(const char *p)
  * assignable unicast addresses in the near future.
  *
  */
-int ip_ok(uint32_t ip)
+bool ip_ok(uint32_t ip)
 {
-    if (ip == -1 ||            /* Refuse the all-one address */
-        (ip & 0xff) == 0 ||    /* Refuse network zero */
-        (ip & 0xff) == 0xff || /* Refuse loopback */
-        (ip & 0xf0) == 0xe0 )  /* Refuse class D */
-        return 0;
+    uint8_t ip_hi = (uint8_t)ip; /* First octet of the ip address */
+
+    if (ip == 0xffffffff ||    /* Refuse the all-ones address */
+       ip_hi == 0 ||           /* Refuse network zero */
+       ip_hi == 127 ||         /* Refuse the loopback network */
+       (ip_hi & 240) == 224)   /* Refuse class D */
+       return false;
 
-    return 1;
+    return true;
 }
 
 
index cad6350..0541bf0 100644 (file)
@@ -232,7 +232,7 @@ static inline uint32_t gateway(uint32_t ip)
  */
 
 /* pxe.c */
-int ip_ok(uint32_t);
+bool ip_ok(uint32_t);
 int pxe_call(int, void *);
 
 /* dhcp_options.c */