Browse Source

[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.
tags/v1.0.0-rc1
Michael Brown 14 years ago
parent
commit
55d23b19a2
1 changed files with 11 additions and 11 deletions
  1. 11
    11
      src/net/ipv4.c

+ 11
- 11
src/net/ipv4.c View File

@@ -600,18 +600,18 @@ static int ipv4_create_routes ( void ) {
600 600
 		fetch_ipv4_setting ( settings, &ip_setting, &address );
601 601
 		if ( ! address.s_addr )
602 602
 			continue;
603
-		/* Calculate default netmask */
604
-		if ( IN_CLASSA ( ntohl ( address.s_addr ) ) ) {
605
-			netmask.s_addr = htonl ( IN_CLASSA_NET );
606
-		} else if ( IN_CLASSB ( ntohl ( address.s_addr ) ) ) {
607
-			netmask.s_addr = htonl ( IN_CLASSB_NET );
608
-		} else if ( IN_CLASSC ( ntohl ( address.s_addr ) ) ) {
609
-			netmask.s_addr = htonl ( IN_CLASSC_NET );
610
-		} else {
611
-			netmask.s_addr = 0;
612
-		}
613
-		/* Override with subnet mask, if present */
603
+		/* Get subnet mask */
614 604
 		fetch_ipv4_setting ( settings, &netmask_setting, &netmask );
605
+		/* Calculate default netmask, if necessary */
606
+		if ( ! netmask.s_addr ) {
607
+			if ( IN_CLASSA ( ntohl ( address.s_addr ) ) ) {
608
+				netmask.s_addr = htonl ( IN_CLASSA_NET );
609
+			} else if ( IN_CLASSB ( ntohl ( address.s_addr ) ) ) {
610
+				netmask.s_addr = htonl ( IN_CLASSB_NET );
611
+			} else if ( IN_CLASSC ( ntohl ( address.s_addr ) ) ) {
612
+				netmask.s_addr = htonl ( IN_CLASSC_NET );
613
+			}
614
+		}
615 615
 		/* Get default gateway, if present */
616 616
 		fetch_ipv4_setting ( settings, &gateway_setting, &gateway );
617 617
 		/* Configure route */

Loading…
Cancel
Save