|
@@ -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;
|