Browse Source

[IPv4] Use default netmasks when no subnet mask is specified.

tags/v0.9.4
Michael Brown 17 years ago
parent
commit
978865da2f
2 changed files with 27 additions and 8 deletions
  1. 7
    1
      src/include/gpxe/in.h
  2. 20
    7
      src/net/ipv4.c

+ 7
- 1
src/include/gpxe/in.h View File

@@ -18,7 +18,13 @@
18 18
 
19 19
 #define INADDR_BROADCAST 0xffffffff
20 20
 
21
-#define IN_MULTICAST(addr) ( ( (addr) & 0xf0000000 ) == 0xe0000000 )
21
+#define	IN_CLASSA(addr)		( ( (addr) & 0x80000000 ) == 0x00000000 )
22
+#define	IN_CLASSA_NET		0xff000000
23
+#define	IN_CLASSB(addr)		( ( (addr) & 0xc0000000 ) == 0x80000000 )
24
+#define	IN_CLASSB_NET		0xffff0000
25
+#define	IN_CLASSC(addr)		( ( (addr) & 0xe0000000 ) == 0xc0000000 )
26
+#define	IN_CLASSC_NET		0xffffff00
27
+#define IN_MULTICAST(addr)	( ( (addr) & 0xf0000000 ) == 0xe0000000 )
22 28
 
23 29
 /**
24 30
  * IP address structure

+ 20
- 7
src/net/ipv4.c View File

@@ -116,18 +116,31 @@ static int ipv4_create_routes ( void ) {
116 116
 	/* Create a route for each configured network device */
117 117
 	for_each_netdev ( netdev ) {
118 118
 		settings = netdev_settings ( netdev );
119
+		/* Get IPv4 address */
119 120
 		address.s_addr = 0;
120 121
 		fetch_ipv4_setting ( settings, DHCP_EB_YIADDR, &address );
121
-		netmask.s_addr = 0;
122
+		if ( ! address.s_addr )
123
+			continue;
124
+		/* Calculate default netmask */
125
+		if ( IN_CLASSA ( ntohl ( address.s_addr ) ) ) {
126
+			netmask.s_addr = htonl ( IN_CLASSA_NET );
127
+		} else if ( IN_CLASSB ( ntohl ( address.s_addr ) ) ) {
128
+			netmask.s_addr = htonl ( IN_CLASSB_NET );
129
+		} else if ( IN_CLASSC ( ntohl ( address.s_addr ) ) ) {
130
+			netmask.s_addr = htonl ( IN_CLASSC_NET );
131
+		} else {
132
+			netmask.s_addr = 0;
133
+		}
134
+		/* Override with subnet mask, if present */
122 135
 		fetch_ipv4_setting ( settings, DHCP_SUBNET_MASK, &netmask );
136
+		/* Get default gateway, if present */
123 137
 		gateway.s_addr = INADDR_NONE;
124 138
 		fetch_ipv4_setting ( settings, DHCP_ROUTERS, &gateway );
125
-		if ( address.s_addr ) {
126
-			miniroute = add_ipv4_miniroute ( netdev, address,
127
-							 netmask, gateway );
128
-			if ( ! miniroute )
129
-				return -ENOMEM;
130
-		}
139
+		/* Configure route */
140
+		miniroute = add_ipv4_miniroute ( netdev, address,
141
+						 netmask, gateway );
142
+		if ( ! miniroute )
143
+			return -ENOMEM;
131 144
 	}
132 145
 
133 146
 	return 0;

Loading…
Cancel
Save