Pārlūkot izejas kodu

[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 15 gadus atpakaļ
vecāks
revīzija
55d23b19a2
1 mainītis faili ar 11 papildinājumiem un 11 dzēšanām
  1. 11
    11
      src/net/ipv4.c

+ 11
- 11
src/net/ipv4.c Parādīt failu

600
 		fetch_ipv4_setting ( settings, &ip_setting, &address );
600
 		fetch_ipv4_setting ( settings, &ip_setting, &address );
601
 		if ( ! address.s_addr )
601
 		if ( ! address.s_addr )
602
 			continue;
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
 		fetch_ipv4_setting ( settings, &netmask_setting, &netmask );
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
 		/* Get default gateway, if present */
615
 		/* Get default gateway, if present */
616
 		fetch_ipv4_setting ( settings, &gateway_setting, &gateway );
616
 		fetch_ipv4_setting ( settings, &gateway_setting, &gateway );
617
 		/* Configure route */
617
 		/* Configure route */

Notiek ielāde…
Atcelt
Saglabāt