Add route() function to display routing table.
This commit is contained in:
parent
78ded6604a
commit
d9ba8f790b
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <ip.h>
|
#include <ip.h>
|
||||||
#include <gpxe/retry.h>
|
#include <gpxe/retry.h>
|
||||||
|
#include <gpxe/hotplug.h>
|
||||||
|
|
||||||
/* IP constants */
|
/* IP constants */
|
||||||
|
|
||||||
|
@ -36,6 +37,24 @@ struct ipv4_pseudo_header {
|
||||||
uint16_t len;
|
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 */
|
/* Fragment reassembly buffer */
|
||||||
struct frag_buffer {
|
struct frag_buffer {
|
||||||
/* Identification number */
|
/* Identification number */
|
||||||
|
@ -57,6 +76,8 @@ struct net_device;
|
||||||
struct net_protocol;
|
struct net_protocol;
|
||||||
struct tcpip_protocol;
|
struct tcpip_protocol;
|
||||||
|
|
||||||
|
extern struct list_head ipv4_miniroutes;
|
||||||
|
|
||||||
extern struct net_protocol ipv4_protocol;
|
extern struct net_protocol ipv4_protocol;
|
||||||
|
|
||||||
extern int add_ipv4_address ( struct net_device *netdev,
|
extern int add_ipv4_address ( struct net_device *netdev,
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef _USR_ROUTE_H
|
||||||
|
#define _USR_ROUTE_H
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
*
|
||||||
|
* Routing table management
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern void route ( void );
|
||||||
|
|
||||||
|
#endif /* _USR_ROUTE_H */
|
|
@ -17,11 +17,6 @@
|
||||||
*
|
*
|
||||||
* IPv4 protocol
|
* 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 */
|
/* Unique IP datagram identification number */
|
||||||
|
@ -29,26 +24,8 @@ static uint16_t next_ident = 0;
|
||||||
|
|
||||||
struct net_protocol ipv4_protocol;
|
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 */
|
/** List of IPv4 miniroutes */
|
||||||
static LIST_HEAD ( miniroutes );
|
struct list_head ipv4_miniroutes = LIST_HEAD_INIT ( ipv4_miniroutes );
|
||||||
|
|
||||||
/** List of fragment reassembly buffers */
|
/** List of fragment reassembly buffers */
|
||||||
static LIST_HEAD ( frag_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.
|
* to start of list.
|
||||||
*/
|
*/
|
||||||
if ( gateway.s_addr != INADDR_NONE ) {
|
if ( gateway.s_addr != INADDR_NONE ) {
|
||||||
list_add_tail ( &miniroute->list, &miniroutes );
|
list_add_tail ( &miniroute->list, &ipv4_miniroutes );
|
||||||
} else {
|
} else {
|
||||||
list_add ( &miniroute->list, &miniroutes );
|
list_add ( &miniroute->list, &ipv4_miniroutes );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Record reference to net_device */
|
/* 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 ) {
|
void del_ipv4_address ( struct net_device *netdev ) {
|
||||||
struct ipv4_miniroute *miniroute;
|
struct ipv4_miniroute *miniroute;
|
||||||
|
|
||||||
list_for_each_entry ( miniroute, &miniroutes, list ) {
|
list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
|
||||||
if ( miniroute->netdev == netdev ) {
|
if ( miniroute->netdev == netdev ) {
|
||||||
del_ipv4_miniroute ( miniroute );
|
del_ipv4_miniroute ( miniroute );
|
||||||
break;
|
break;
|
||||||
|
@ -186,7 +163,7 @@ static struct ipv4_miniroute * ipv4_route ( struct in_addr *dest ) {
|
||||||
int local;
|
int local;
|
||||||
int has_gw;
|
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 )
|
local = ( ( ( dest->s_addr ^ miniroute->address.s_addr )
|
||||||
& miniroute->netmask.s_addr ) == 0 );
|
& miniroute->netmask.s_addr ) == 0 );
|
||||||
has_gw = ( miniroute->gateway.s_addr != INADDR_NONE );
|
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;
|
const struct in_addr *address = net_addr;
|
||||||
struct ipv4_miniroute *miniroute;
|
struct ipv4_miniroute *miniroute;
|
||||||
|
|
||||||
list_for_each_entry ( miniroute, &miniroutes, list ) {
|
list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
|
||||||
if ( ( miniroute->netdev == netdev ) &&
|
if ( ( miniroute->netdev == netdev ) &&
|
||||||
( miniroute->address.s_addr == address->s_addr ) ) {
|
( miniroute->address.s_addr == address->s_addr ) ) {
|
||||||
/* Found matching address */
|
/* Found matching address */
|
||||||
|
|
|
@ -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_SUBNET_MASK, &netmask );
|
||||||
find_global_dhcp_ipv4_option ( DHCP_ROUTERS, &gateway );
|
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 ),
|
dhcp_snprintf ( filename, sizeof ( filename ),
|
||||||
find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
|
find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
|
||||||
|
|
||||||
|
@ -251,6 +247,8 @@ int test_dhcp ( struct net_device *netdev ) {
|
||||||
gateway ) ) != 0 )
|
gateway ) ) != 0 )
|
||||||
goto out_no_del_ipv4;
|
goto out_no_del_ipv4;
|
||||||
|
|
||||||
|
route();
|
||||||
|
|
||||||
/* Test boot */
|
/* Test boot */
|
||||||
if ( ( rc = test_dhcp_boot ( netdev, filename ) ) != 0 ) {
|
if ( ( rc = test_dhcp_boot ( netdev, filename ) ) != 0 ) {
|
||||||
printf ( "Boot failed\n" );
|
printf ( "Boot failed\n" );
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <vsprintf.h>
|
#include <vsprintf.h>
|
||||||
#include <gpxe/netdevice.h>
|
#include <gpxe/netdevice.h>
|
||||||
#include <usr/ifmgmt.h>
|
#include <usr/ifmgmt.h>
|
||||||
|
#include <usr/route.h>
|
||||||
#include <usr/autoboot.h>
|
#include <usr/autoboot.h>
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
|
@ -81,6 +82,8 @@ void netboot ( struct net_device *netdev ) {
|
||||||
ifstat ( netdev );
|
ifstat ( netdev );
|
||||||
|
|
||||||
test_dhcp ( netdev );
|
test_dhcp ( netdev );
|
||||||
|
|
||||||
|
route();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
|
||||||
|
*
|
||||||
|
* 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 <vsprintf.h>
|
||||||
|
#include <gpxe/netdevice.h>
|
||||||
|
#include <gpxe/ip.h>
|
||||||
|
#include <usr/route.h>
|
||||||
|
|
||||||
|
/** @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" );
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue