From d9ba8f790b2b0ad7e22b96e46dc5e0946815e512 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 10 Jan 2007 20:38:20 +0000 Subject: [PATCH] Add route() function to display routing table. --- src/include/gpxe/ip.h | 21 +++++++++++++++++++++ src/include/usr/route.h | 12 ++++++++++++ src/net/ipv4.c | 35 ++++++----------------------------- src/tests/dhcptest.c | 6 ++---- src/usr/autoboot.c | 3 +++ src/usr/route.c | 41 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 85 insertions(+), 33 deletions(-) create mode 100644 src/include/usr/route.h create mode 100644 src/usr/route.c diff --git a/src/include/gpxe/ip.h b/src/include/gpxe/ip.h index 352cf643..d212b3ef 100644 --- a/src/include/gpxe/ip.h +++ b/src/include/gpxe/ip.h @@ -9,6 +9,7 @@ #include #include +#include /* IP constants */ @@ -36,6 +37,24 @@ struct ipv4_pseudo_header { uint16_t len; }; +/** An IPv4 address/routing table entry */ +struct ipv4_miniroute { + /** List of miniroutes */ + struct list_head list; + + /** Network device */ + struct net_device *netdev; + /** Reference to network device */ + struct reference netdev_ref; + + /** IPv4 address */ + struct in_addr address; + /** Subnet mask */ + struct in_addr netmask; + /** Gateway address */ + struct in_addr gateway; +}; + /* Fragment reassembly buffer */ struct frag_buffer { /* Identification number */ @@ -57,6 +76,8 @@ struct net_device; struct net_protocol; struct tcpip_protocol; +extern struct list_head ipv4_miniroutes; + extern struct net_protocol ipv4_protocol; extern int add_ipv4_address ( struct net_device *netdev, diff --git a/src/include/usr/route.h b/src/include/usr/route.h new file mode 100644 index 00000000..fc855892 --- /dev/null +++ b/src/include/usr/route.h @@ -0,0 +1,12 @@ +#ifndef _USR_ROUTE_H +#define _USR_ROUTE_H + +/** @file + * + * Routing table management + * + */ + +extern void route ( void ); + +#endif /* _USR_ROUTE_H */ diff --git a/src/net/ipv4.c b/src/net/ipv4.c index 9d972608..1155ad90 100644 --- a/src/net/ipv4.c +++ b/src/net/ipv4.c @@ -17,11 +17,6 @@ * * IPv4 protocol * - * The gPXE IP stack is currently implemented on top of the uIP - * protocol stack. This file provides wrappers around uIP so that - * higher-level protocol implementations do not need to talk directly - * to uIP (which has a somewhat baroque API). - * */ /* Unique IP datagram identification number */ @@ -29,26 +24,8 @@ static uint16_t next_ident = 0; struct net_protocol ipv4_protocol; -/** An IPv4 address/routing table entry */ -struct ipv4_miniroute { - /** List of miniroutes */ - struct list_head list; - - /** Network device */ - struct net_device *netdev; - /** Reference to network device */ - struct reference netdev_ref; - - /** IPv4 address */ - struct in_addr address; - /** Subnet mask */ - struct in_addr netmask; - /** Gateway address */ - struct in_addr gateway; -}; - /** List of IPv4 miniroutes */ -static LIST_HEAD ( miniroutes ); +struct list_head ipv4_miniroutes = LIST_HEAD_INIT ( ipv4_miniroutes ); /** List of fragment reassembly buffers */ static LIST_HEAD ( frag_buffers ); @@ -90,9 +67,9 @@ static struct ipv4_miniroute * add_ipv4_miniroute ( struct net_device *netdev, * to start of list. */ if ( gateway.s_addr != INADDR_NONE ) { - list_add_tail ( &miniroute->list, &miniroutes ); + list_add_tail ( &miniroute->list, &ipv4_miniroutes ); } else { - list_add ( &miniroute->list, &miniroutes ); + list_add ( &miniroute->list, &ipv4_miniroutes ); } /* Record reference to net_device */ @@ -166,7 +143,7 @@ int add_ipv4_address ( struct net_device *netdev, struct in_addr address, void del_ipv4_address ( struct net_device *netdev ) { struct ipv4_miniroute *miniroute; - list_for_each_entry ( miniroute, &miniroutes, list ) { + list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) { if ( miniroute->netdev == netdev ) { del_ipv4_miniroute ( miniroute ); break; @@ -186,7 +163,7 @@ static struct ipv4_miniroute * ipv4_route ( struct in_addr *dest ) { int local; int has_gw; - list_for_each_entry ( miniroute, &miniroutes, list ) { + 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 ); @@ -547,7 +524,7 @@ static int ipv4_arp_check ( struct net_device *netdev, const void *net_addr ) { const struct in_addr *address = net_addr; struct ipv4_miniroute *miniroute; - list_for_each_entry ( miniroute, &miniroutes, list ) { + list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) { if ( ( miniroute->netdev == netdev ) && ( miniroute->address.s_addr == address->s_addr ) ) { /* Found matching address */ diff --git a/src/tests/dhcptest.c b/src/tests/dhcptest.c index 525c1073..318ce5e8 100644 --- a/src/tests/dhcptest.c +++ b/src/tests/dhcptest.c @@ -236,10 +236,6 @@ int test_dhcp ( struct net_device *netdev ) { find_global_dhcp_ipv4_option ( DHCP_SUBNET_MASK, &netmask ); find_global_dhcp_ipv4_option ( DHCP_ROUTERS, &gateway ); - printf ( "IP %s", inet_ntoa ( address ) ); - printf ( " netmask %s", inet_ntoa ( netmask ) ); - printf ( " gateway %s\n", inet_ntoa ( gateway ) ); - dhcp_snprintf ( filename, sizeof ( filename ), find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) ); @@ -251,6 +247,8 @@ int test_dhcp ( struct net_device *netdev ) { gateway ) ) != 0 ) goto out_no_del_ipv4; + route(); + /* Test boot */ if ( ( rc = test_dhcp_boot ( netdev, filename ) ) != 0 ) { printf ( "Boot failed\n" ); diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c index 45b3b6e7..97024ee3 100644 --- a/src/usr/autoboot.c +++ b/src/usr/autoboot.c @@ -21,6 +21,7 @@ #include #include #include +#include #include /** @file @@ -81,6 +82,8 @@ void netboot ( struct net_device *netdev ) { ifstat ( netdev ); test_dhcp ( netdev ); + + route(); } /** diff --git a/src/usr/route.c b/src/usr/route.c new file mode 100644 index 00000000..b2804ce7 --- /dev/null +++ b/src/usr/route.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2007 Michael Brown . + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include + +/** @file + * + * Routing table management + * + */ + +void route ( void ) { + struct ipv4_miniroute *miniroute; + + list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) { + printf ( "%s: %s/", miniroute->netdev->name, + inet_ntoa ( miniroute->address ) ); + printf ( "%s", inet_ntoa ( miniroute->netmask ) ); + if ( miniroute->gateway.s_addr != INADDR_NONE ) + printf ( " gw %s", inet_ntoa ( miniroute->gateway ) ); + printf ( "\n" ); + } +}