diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gpxe/dhcp.h | 3 | ||||
-rw-r--r-- | src/include/gpxe/ip.h | 5 | ||||
-rw-r--r-- | src/include/gpxe/netdevice.h | 11 | ||||
-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 | ||||
-rw-r--r-- | src/usr/dhcpmgmt.c | 4 |
7 files changed, 53 insertions, 88 deletions
diff --git a/src/include/gpxe/dhcp.h b/src/include/gpxe/dhcp.h index a8fa811..de10cc9 100644 --- a/src/include/gpxe/dhcp.h +++ b/src/include/gpxe/dhcp.h @@ -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 */ diff --git a/src/include/gpxe/ip.h b/src/include/gpxe/ip.h index a684409..0a23565 100644 --- a/src/include/gpxe/ip.h +++ b/src/include/gpxe/ip.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 */ diff --git a/src/include/gpxe/netdevice.h b/src/include/gpxe/netdevice.h index 6f5c06f..4abada7 100644 --- a/src/include/gpxe/netdevice.h +++ b/src/include/gpxe/netdevice.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 ); 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; -} diff --git a/src/usr/dhcpmgmt.c b/src/usr/dhcpmgmt.c index 0c6b458..39fe920 100644 --- a/src/usr/dhcpmgmt.c +++ b/src/usr/dhcpmgmt.c @@ -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 ) { |