[netdevice] Add generic concept of a network device configurator

iPXE supports multiple mechanisms for network device configuration:
DHCPv4 for IPv4, FIP for FCoE, and SLAAC for IPv6.  At present, DHCPv4
requires an explicit action (e.g. a "dhcp" command), FIP is initiated
implicitly upon opening a network device, and SLAAC takes place
whenever a RA happens to be received.

Add a generic concept of a network device configurator, which provides
a common interface to triggering configuration and to reporting the
result of the configuration process.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2013-10-31 15:37:52 +00:00
parent 55e85ad1ee
commit f2bc138391
2 changed files with 282 additions and 5 deletions

View File

@@ -14,6 +14,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/tables.h>
#include <ipxe/refcnt.h>
#include <ipxe/settings.h>
#include <ipxe/interface.h>
struct io_buffer;
struct net_device;
@@ -292,6 +293,45 @@ struct net_device_stats {
struct net_device_error errors[NETDEV_MAX_UNIQUE_ERRORS];
};
/** A network device configuration */
struct net_device_configuration {
/** Network device */
struct net_device *netdev;
/** Network device configurator */
struct net_device_configurator *configurator;
/** Configuration status */
int rc;
/** Job control interface */
struct interface job;
};
/** A network device configurator */
struct net_device_configurator {
/** Name */
const char *name;
/** Check applicability of configurator
*
* @v netdev Network device
* @ret applies Configurator applies to this network device
*/
int ( * applies ) ( struct net_device *netdev );
/** Start configuring network device
*
* @v job Job control interface
* @v netdev Network device
* @ret rc Return status code
*/
int ( * start ) ( struct interface *job, struct net_device *netdev );
};
/** Network device configurator table */
#define NET_DEVICE_CONFIGURATORS \
__table ( struct net_device_configurator, "net_device_configurators" )
/** Declare a network device configurator */
#define __net_device_configurator \
__table_entry ( NET_DEVICE_CONFIGURATORS, 01 )
/** Maximum length of a network device name */
#define NETDEV_NAME_LEN 12
@@ -374,6 +414,9 @@ struct net_device {
/** Driver private data */
void *priv;
/** Network device configurations (variable length) */
struct net_device_configuration configs[0];
};
/** Network device is open */
@@ -531,6 +574,35 @@ netdev_settings_init ( struct net_device *netdev ) {
netdev->settings.settings.op = &netdev_settings_operations;
}
/**
* Get network device configuration
*
* @v netdev Network device
* @v configurator Network device configurator
* @ret config Network device configuration
*/
static inline struct net_device_configuration *
netdev_configuration ( struct net_device *netdev,
struct net_device_configurator *configurator ) {
return &netdev->configs[ table_index ( NET_DEVICE_CONFIGURATORS,
configurator ) ];
}
/**
* Check if configurator applies to network device
*
* @v netdev Network device
* @v configurator Network device configurator
* @ret applies Configurator applies to network device
*/
static inline int
netdev_configurator_applies ( struct net_device *netdev,
struct net_device_configurator *configurator ) {
return ( ( configurator->applies == NULL ) ||
configurator->applies ( netdev ) );
}
/**
* Check link state of network device
*
@@ -619,6 +691,13 @@ extern int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
uint16_t net_proto, const void *ll_dest,
const void *ll_source, unsigned int flags );
extern void net_poll ( void );
extern struct net_device_configurator *
find_netdev_configurator ( const char *name );
extern int netdev_configure ( struct net_device *netdev,
struct net_device_configurator *configurator );
extern int netdev_configure_all ( struct net_device *netdev );
extern int netdev_configuration_in_progress ( struct net_device *netdev );
extern int netdev_configuration_ok ( struct net_device *netdev );
/**
* Complete network transmission