diff options
author | H. Peter Anvin <hpa@zytor.com> | 2010-06-24 20:55:43 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2010-06-24 20:55:43 -0700 |
commit | 1b1d3fa2adac6215bd0fbe3d7a5ba5ecb8ba8eac (patch) | |
tree | 666a707a9e5b28bee8b6af9ea4145defd13cd456 | |
parent | 921f578e03c2b19f1b4e7b14d4e69e988b47e2cc (diff) | |
download | syslinux-1b1d3fa2adac6215bd0fbe3d7a5ba5ecb8ba8eac.tar.gz |
pxe: fix ip_ok()
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>
-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 */ |