diff options
author | Michael Brown <mcb30@etherboot.org> | 2008-03-21 00:01:27 +0000 |
---|---|---|
committer | Michael Brown <mcb30@etherboot.org> | 2008-03-21 00:01:27 +0000 |
commit | aec9b8a41b6cad1b257c4e3a7f043f35871aafd0 (patch) | |
tree | d75b982ed496f3f5142f5b6c02fcbd3cea868f6e /src/net | |
parent | eae6ac3d0bdb5f25193af9584db4eec9dd5226c9 (diff) | |
download | ipxe-aec9b8a41b6cad1b257c4e3a7f043f35871aafd0.zip ipxe-aec9b8a41b6cad1b257c4e3a7f043f35871aafd0.tar.gz ipxe-aec9b8a41b6cad1b257c4e3a7f043f35871aafd0.tar.bz2 |
[Settings] Use a settings applicator to configure IPv4 routes.
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/ipv4.c | 68 | ||||
-rw-r--r-- | src/net/netdevice.c | 7 | ||||
-rw-r--r-- | src/net/udp/dhcp.c | 43 |
3 files changed, 40 insertions, 78 deletions
diff --git a/src/net/ipv4.c b/src/net/ipv4.c index f86c71e..ee88dd8 100644 --- a/src/net/ipv4.c +++ b/src/net/ipv4.c @@ -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; - - /* Clear any existing address for this net device */ - del_ipv4_address ( netdev ); - - /* Add new miniroute */ - miniroute = add_ipv4_miniroute ( netdev, address, netmask, gateway ); - if ( ! miniroute ) - return -ENOMEM; + 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 }; + + /* Delete all existing routes */ + list_for_each_entry_safe ( miniroute, tmp, &ipv4_miniroutes, list ) + del_ipv4_miniroute ( miniroute ); + + /* 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 diff --git a/src/net/netdevice.c b/src/net/netdevice.c index 323e910..6875b3b 100644 --- a/src/net/netdevice.c +++ b/src/net/netdevice.c @@ -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 ); diff --git a/src/net/udp/dhcp.c b/src/net/udp/dhcp.c index 2cb258e..1beabb9 100644 --- a/src/net/udp/dhcp.c +++ b/src/net/udp/dhcp.c @@ -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; -} |