diff options
-rw-r--r-- | core/fs/pxe/pxe.c | 16 | ||||
-rw-r--r-- | core/fs/pxe/pxe.h | 2 |
2 files changed, 10 insertions, 8 deletions
diff --git a/core/fs/pxe/pxe.c b/core/fs/pxe/pxe.c index e2bd29ce..231c4e5b 100644 --- a/core/fs/pxe/pxe.c +++ b/core/fs/pxe/pxe.c @@ -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; } diff --git a/core/fs/pxe/pxe.h b/core/fs/pxe/pxe.h index cad63507..0541bf09 100644 --- a/core/fs/pxe/pxe.h +++ b/core/fs/pxe/pxe.h @@ -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 */ |