summaryrefslogtreecommitdiffstats
path: root/src/net/ipv4.c
diff options
context:
space:
mode:
authorMichael Brown2009-11-14 03:28:16 +0100
committerMichael Brown2009-11-16 23:11:53 +0100
commit55d23b19a270b2caeb4dcd9435a91bc9c55383e2 (patch)
tree2f5657c70beff1605012f2c95cdab2fb0c778021 /src/net/ipv4.c
parent[ipv4] Use a zero address to indicate "no gateway", rather than INADDR_NONE (diff)
downloadipxe-55d23b19a270b2caeb4dcd9435a91bc9c55383e2.tar.gz
ipxe-55d23b19a270b2caeb4dcd9435a91bc9c55383e2.tar.xz
ipxe-55d23b19a270b2caeb4dcd9435a91bc9c55383e2.zip
[ipv4] Allow calculation of default subnet mask
ipv4.c calculates the default subnet mask before calling fetch_ipv4_setting() to retrieve the configured subnet mask (if any). However, as of commit 612f4e7 "[settings] Avoid returning uninitialised data on error in fetch_xxx_setting()", fetch_ipv4_setting() will zero the IP address if the setting does not exist, rather than leaving it unaltered. Fix by fetching the setting first and calculating the default subnet mask only if necessary.
Diffstat (limited to 'src/net/ipv4.c')
-rw-r--r--src/net/ipv4.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/net/ipv4.c b/src/net/ipv4.c
index 25cc7ffa..6b78ad77 100644
--- a/src/net/ipv4.c
+++ b/src/net/ipv4.c
@@ -600,18 +600,18 @@ static int ipv4_create_routes ( void ) {
fetch_ipv4_setting ( settings, &ip_setting, &address );
if ( ! address.s_addr )
continue;
- /* Calculate default netmask */
- if ( IN_CLASSA ( ntohl ( address.s_addr ) ) ) {
- netmask.s_addr = htonl ( IN_CLASSA_NET );
- } else if ( IN_CLASSB ( ntohl ( address.s_addr ) ) ) {
- netmask.s_addr = htonl ( IN_CLASSB_NET );
- } else if ( IN_CLASSC ( ntohl ( address.s_addr ) ) ) {
- netmask.s_addr = htonl ( IN_CLASSC_NET );
- } else {
- netmask.s_addr = 0;
- }
- /* Override with subnet mask, if present */
+ /* Get subnet mask */
fetch_ipv4_setting ( settings, &netmask_setting, &netmask );
+ /* Calculate default netmask, if necessary */
+ if ( ! netmask.s_addr ) {
+ if ( IN_CLASSA ( ntohl ( address.s_addr ) ) ) {
+ netmask.s_addr = htonl ( IN_CLASSA_NET );
+ } else if ( IN_CLASSB ( ntohl ( address.s_addr ) ) ) {
+ netmask.s_addr = htonl ( IN_CLASSB_NET );
+ } else if ( IN_CLASSC ( ntohl ( address.s_addr ) ) ) {
+ netmask.s_addr = htonl ( IN_CLASSC_NET );
+ }
+ }
/* Get default gateway, if present */
fetch_ipv4_setting ( settings, &gateway_setting, &gateway );
/* Configure route */