summaryrefslogtreecommitdiffstats
path: root/src/net/ipv4.c
diff options
context:
space:
mode:
authorMichael Brown2009-11-14 03:21:13 +0100
committerMichael Brown2009-11-16 23:09:23 +0100
commit2ce0d8f08be9172e8a2b267e3073c1ed0b54afae (patch)
treeaaeac490a1af934678bad2d77dff63c832a37f8c /src/net/ipv4.c
parent[libc] Use only generic errortab entries to match generic errors (diff)
downloadipxe-2ce0d8f08be9172e8a2b267e3073c1ed0b54afae.tar.gz
ipxe-2ce0d8f08be9172e8a2b267e3073c1ed0b54afae.tar.xz
ipxe-2ce0d8f08be9172e8a2b267e3073c1ed0b54afae.zip
[ipv4] Use a zero address to indicate "no gateway", rather than INADDR_NONE
ipv4.c uses a gateway address of INADDR_NONE to represent "no gateway". It initialises the gateway address to INADDR_NONE before calling fetch_ipv4_setting() to retrieve the configured gateway address (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 using a zero IP address to indicate "no gateway", so that a non-existent gateway address setting will be treated as such.
Diffstat (limited to 'src/net/ipv4.c')
-rw-r--r--src/net/ipv4.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/net/ipv4.c b/src/net/ipv4.c
index 64d294e5..25cc7ffa 100644
--- a/src/net/ipv4.c
+++ b/src/net/ipv4.c
@@ -40,7 +40,7 @@ static LIST_HEAD ( frag_buffers );
* @v netdev Network device
* @v address IPv4 address
* @v netmask Subnet mask
- * @v gateway Gateway address (or @c INADDR_NONE for no gateway)
+ * @v gateway Gateway address (if any)
* @ret miniroute Routing table entry, or NULL
*/
static struct ipv4_miniroute * __malloc
@@ -50,7 +50,7 @@ add_ipv4_miniroute ( struct net_device *netdev, struct in_addr address,
DBG ( "IPv4 add %s", inet_ntoa ( address ) );
DBG ( "/%s ", inet_ntoa ( netmask ) );
- if ( gateway.s_addr != INADDR_NONE )
+ if ( gateway.s_addr )
DBG ( "gw %s ", inet_ntoa ( gateway ) );
DBG ( "via %s\n", netdev->name );
@@ -70,7 +70,7 @@ add_ipv4_miniroute ( struct net_device *netdev, struct in_addr address,
/* Add to end of list if we have a gateway, otherwise
* to start of list.
*/
- if ( gateway.s_addr != INADDR_NONE ) {
+ if ( gateway.s_addr ) {
list_add_tail ( &miniroute->list, &ipv4_miniroutes );
} else {
list_add ( &miniroute->list, &ipv4_miniroutes );
@@ -88,7 +88,7 @@ static void del_ipv4_miniroute ( struct ipv4_miniroute *miniroute ) {
DBG ( "IPv4 del %s", inet_ntoa ( miniroute->address ) );
DBG ( "/%s ", inet_ntoa ( miniroute->netmask ) );
- if ( miniroute->gateway.s_addr != INADDR_NONE )
+ if ( miniroute->gateway.s_addr )
DBG ( "gw %s ", inet_ntoa ( miniroute->gateway ) );
DBG ( "via %s\n", miniroute->netdev->name );
@@ -120,7 +120,7 @@ static struct ipv4_miniroute * ipv4_route ( struct in_addr *dest ) {
list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
local = ( ( ( dest->s_addr ^ miniroute->address.s_addr )
& miniroute->netmask.s_addr ) == 0 );
- has_gw = ( miniroute->gateway.s_addr != INADDR_NONE );
+ has_gw = ( miniroute->gateway.s_addr );
if ( local || has_gw ) {
if ( ! local )
*dest = miniroute->gateway;
@@ -586,7 +586,7 @@ static int ipv4_create_routes ( void ) {
struct settings *settings;
struct in_addr address = { 0 };
struct in_addr netmask = { 0 };
- struct in_addr gateway = { INADDR_NONE };
+ struct in_addr gateway = { 0 };
/* Delete all existing routes */
list_for_each_entry_safe ( miniroute, tmp, &ipv4_miniroutes, list )
@@ -613,7 +613,6 @@ static int ipv4_create_routes ( void ) {
/* Override with subnet mask, if present */
fetch_ipv4_setting ( settings, &netmask_setting, &netmask );
/* Get default gateway, if present */
- gateway.s_addr = INADDR_NONE;
fetch_ipv4_setting ( settings, &gateway_setting, &gateway );
/* Configure route */
miniroute = add_ipv4_miniroute ( netdev, address,