mirror of
https://github.com/xcat2/xNBA.git
synced 2024-11-26 03:09:12 +00:00
[Settings] Use a settings applicator to configure IPv4 routes.
This commit is contained in:
parent
eae6ac3d0b
commit
aec9b8a41b
@ -557,7 +557,4 @@ extern int create_dhcp_response ( struct net_device *netdev, int msgtype,
|
||||
extern int start_dhcp ( struct job_interface *job, struct net_device *netdev,
|
||||
int (*register_options) ( struct net_device *,
|
||||
struct dhcp_option_block * ));
|
||||
extern int dhcp_configure_netdev ( struct net_device *netdev,
|
||||
struct dhcp_option_block *options );
|
||||
|
||||
#endif /* _GPXE_DHCP_H */
|
||||
|
@ -77,9 +77,4 @@ extern struct list_head ipv4_miniroutes;
|
||||
|
||||
extern struct net_protocol ipv4_protocol;
|
||||
|
||||
extern int add_ipv4_address ( struct net_device *netdev,
|
||||
struct in_addr address, struct in_addr netmask,
|
||||
struct in_addr gateway );
|
||||
extern void del_ipv4_address ( struct net_device *netdev );
|
||||
|
||||
#endif /* _GPXE_IP_H */
|
||||
|
@ -341,6 +341,17 @@ netdev_priv ( struct net_device *netdev ) {
|
||||
return netdev->priv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get per-netdevice configuration settings block
|
||||
*
|
||||
* @v netdev Network device
|
||||
* @ret settings Settings block
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) struct settings *
|
||||
netdev_settings ( struct net_device *netdev ) {
|
||||
return &netdev->settings;
|
||||
}
|
||||
|
||||
extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf );
|
||||
extern void netdev_tx_complete_err ( struct net_device *netdev,
|
||||
struct io_buffer *iobuf, int rc );
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include <gpxe/netdevice.h>
|
||||
#include <gpxe/ip.h>
|
||||
#include <gpxe/tcpip.h>
|
||||
#include <gpxe/dhcp.h>
|
||||
#include <gpxe/settings.h>
|
||||
|
||||
/** @file
|
||||
*
|
||||
@ -94,45 +96,47 @@ static void del_ipv4_miniroute ( struct ipv4_miniroute *miniroute ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add IPv4 interface
|
||||
*
|
||||
* @v netdev Network device
|
||||
* @v address IPv4 address
|
||||
* @v netmask Subnet mask
|
||||
* @v gateway Gateway address (or @c INADDR_NONE for no gateway)
|
||||
* @ret rc Return status code
|
||||
* Create IPv4 routing table
|
||||
*
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int add_ipv4_address ( struct net_device *netdev, struct in_addr address,
|
||||
struct in_addr netmask, struct in_addr gateway ) {
|
||||
static int ipv4_create_routes ( void ) {
|
||||
struct ipv4_miniroute *miniroute;
|
||||
struct ipv4_miniroute *tmp;
|
||||
struct net_device *netdev;
|
||||
struct settings *settings;
|
||||
struct in_addr address = { 0 };
|
||||
struct in_addr netmask = { 0 };
|
||||
struct in_addr gateway = { INADDR_NONE };
|
||||
|
||||
/* Clear any existing address for this net device */
|
||||
del_ipv4_address ( netdev );
|
||||
/* Delete all existing routes */
|
||||
list_for_each_entry_safe ( miniroute, tmp, &ipv4_miniroutes, list )
|
||||
del_ipv4_miniroute ( miniroute );
|
||||
|
||||
/* Add new miniroute */
|
||||
miniroute = add_ipv4_miniroute ( netdev, address, netmask, gateway );
|
||||
if ( ! miniroute )
|
||||
return -ENOMEM;
|
||||
/* Create a route for each configured network device */
|
||||
for_each_netdev ( netdev ) {
|
||||
settings = netdev_settings ( netdev );
|
||||
address.s_addr = 0;
|
||||
fetch_ipv4_setting ( settings, DHCP_EB_YIADDR, &address );
|
||||
netmask.s_addr = 0;
|
||||
fetch_ipv4_setting ( settings, DHCP_SUBNET_MASK, &netmask );
|
||||
gateway.s_addr = INADDR_NONE;
|
||||
fetch_ipv4_setting ( settings, DHCP_ROUTERS, &gateway );
|
||||
if ( address.s_addr ) {
|
||||
miniroute = add_ipv4_miniroute ( netdev, address,
|
||||
netmask, gateway );
|
||||
if ( ! miniroute )
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove IPv4 interface
|
||||
*
|
||||
* @v netdev Network device
|
||||
*/
|
||||
void del_ipv4_address ( struct net_device *netdev ) {
|
||||
struct ipv4_miniroute *miniroute;
|
||||
|
||||
list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
|
||||
if ( miniroute->netdev == netdev ) {
|
||||
del_ipv4_miniroute ( miniroute );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/** IPv4 settings applicator */
|
||||
struct settings_applicator ipv4_settings_applicator __settings_applicator = {
|
||||
.apply = ipv4_create_routes,
|
||||
};
|
||||
|
||||
/**
|
||||
* Perform IPv4 routing
|
||||
|
@ -266,7 +266,7 @@ struct net_device * alloc_netdev ( size_t priv_size ) {
|
||||
netdev->refcnt.free = free_netdev;
|
||||
INIT_LIST_HEAD ( &netdev->tx_queue );
|
||||
INIT_LIST_HEAD ( &netdev->rx_queue );
|
||||
settings_init ( &netdev->settings,
|
||||
settings_init ( netdev_settings ( netdev ),
|
||||
&netdev_settings_operations, &netdev->refcnt,
|
||||
netdev->name );
|
||||
netdev->priv = ( ( ( void * ) netdev ) + sizeof ( *netdev ) );
|
||||
@ -292,7 +292,8 @@ int register_netdev ( struct net_device *netdev ) {
|
||||
ifindex++ );
|
||||
|
||||
/* Register per-netdev configuration settings */
|
||||
if ( ( rc = register_settings ( &netdev->settings, NULL ) ) != 0 ) {
|
||||
if ( ( rc = register_settings ( netdev_settings ( netdev ),
|
||||
NULL ) ) != 0 ) {
|
||||
DBGC ( netdev, "NETDEV %p could not register settings: %s\n",
|
||||
netdev, strerror ( rc ) );
|
||||
return rc;
|
||||
@ -369,7 +370,7 @@ void unregister_netdev ( struct net_device *netdev ) {
|
||||
netdev_close ( netdev );
|
||||
|
||||
/* Unregister per-netdev configuration settings */
|
||||
unregister_settings ( &netdev->settings );
|
||||
unregister_settings ( netdev_settings ( netdev ) );
|
||||
|
||||
/* Remove from device list */
|
||||
list_del ( &netdev->list );
|
||||
|
@ -1025,46 +1025,3 @@ int start_dhcp ( struct job_interface *job, struct net_device *netdev,
|
||||
ref_put ( &dhcp->refcnt );
|
||||
return rc;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Network device configurator
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Configure network device from DHCP options
|
||||
*
|
||||
* @v netdev Network device
|
||||
* @v options DHCP options block
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int dhcp_configure_netdev ( struct net_device *netdev,
|
||||
struct dhcp_option_block *options ) {
|
||||
struct in_addr address = { 0 };
|
||||
struct in_addr netmask = { 0 };
|
||||
struct in_addr gateway = { INADDR_NONE };
|
||||
int rc;
|
||||
|
||||
/* Retrieve IP address configuration */
|
||||
find_dhcp_ipv4_option ( options, DHCP_EB_YIADDR, &address );
|
||||
find_dhcp_ipv4_option ( options, DHCP_SUBNET_MASK, &netmask );
|
||||
find_dhcp_ipv4_option ( options, DHCP_ROUTERS, &gateway );
|
||||
|
||||
/* Do nothing unless we have at least an IP address to use */
|
||||
if ( ! address.s_addr )
|
||||
return 0;
|
||||
|
||||
/* Clear any existing routing table entry */
|
||||
del_ipv4_address ( netdev );
|
||||
|
||||
/* Set up new IP address configuration */
|
||||
if ( ( rc = add_ipv4_address ( netdev, address, netmask,
|
||||
gateway ) ) != 0 ) {
|
||||
DBG ( "Could not configure %s with DHCP results: %s\n",
|
||||
netdev->name, strerror ( rc ) );
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -32,11 +32,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
static int dhcp_success ( struct net_device *netdev,
|
||||
static int dhcp_success ( struct net_device *netdev __unused,
|
||||
struct dhcp_option_block *options ) {
|
||||
DBGC ( options, "DHCP client registering options %p\n", options );
|
||||
register_dhcp_options ( options );
|
||||
return dhcp_configure_netdev ( netdev, options );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dhcp ( struct net_device *netdev ) {
|
||||
|
Loading…
Reference in New Issue
Block a user