mirror of
https://github.com/xcat2/xNBA.git
synced 2024-12-14 23:31:39 +00:00
Add route() function to display routing table.
This commit is contained in:
parent
78ded6604a
commit
d9ba8f790b
@ -9,6 +9,7 @@
|
||||
|
||||
#include <ip.h>
|
||||
#include <gpxe/retry.h>
|
||||
#include <gpxe/hotplug.h>
|
||||
|
||||
/* 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,
|
||||
|
12
src/include/usr/route.h
Normal file
12
src/include/usr/route.h
Normal file
@ -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
|
||||
*
|
||||
* 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 */
|
||||
|
@ -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" );
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <vsprintf.h>
|
||||
#include <gpxe/netdevice.h>
|
||||
#include <usr/ifmgmt.h>
|
||||
#include <usr/route.h>
|
||||
#include <usr/autoboot.h>
|
||||
|
||||
/** @file
|
||||
@ -81,6 +82,8 @@ void netboot ( struct net_device *netdev ) {
|
||||
ifstat ( netdev );
|
||||
|
||||
test_dhcp ( netdev );
|
||||
|
||||
route();
|
||||
}
|
||||
|
||||
/**
|
||||
|
41
src/usr/route.c
Normal file
41
src/usr/route.c
Normal file
@ -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" );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user