david/ipxe
Archived
1
0

[netdevice] Make all net_driver methods optional

Most network upper-layer drivers do not implement all three methods
(probe, notify, and remove).  Save code by making all methods
optional.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2013-10-31 14:09:43 +00:00
parent 5e1fa5cd40
commit 5c11ff6304
6 changed files with 13 additions and 72 deletions

View File

@ -159,30 +159,8 @@ static int cachedhcp_probe ( struct net_device *netdev ) {
return 0;
}
/**
* Handle network device link state change
*
* @v netdev Network device
*/
static void cachedhcp_notify ( struct net_device *netdev __unused ) {
/* Nothing to do */
}
/**
* Handle network device removal
*
* @v netdev Network device
*/
static void cachedhcp_remove ( struct net_device *netdev __unused ) {
/* Nothing to do */
}
/** Cached DHCP packet network device driver */
struct net_driver cachedhcp_driver __net_driver = {
.name = "cachedhcp",
.probe = cachedhcp_probe,
.notify = cachedhcp_notify,
.remove = cachedhcp_remove,
};

View File

@ -243,15 +243,6 @@ static int guestinfo_net_probe ( struct net_device *netdev ) {
return rc;
}
/**
* Handle network device or link state change
*
* @v netdev Network device
*/
static void guestinfo_net_notify ( struct net_device *netdev __unused ) {
/* Nothing to do */
}
/**
* Remove per-netdevice GuestInfo settings
*
@ -276,6 +267,5 @@ static void guestinfo_net_remove ( struct net_device *netdev ) {
struct net_driver guestinfo_net_driver __net_driver = {
.name = "GuestInfo",
.probe = guestinfo_net_probe,
.notify = guestinfo_net_notify,
.remove = guestinfo_net_remove,
};

View File

@ -943,16 +943,6 @@ static int ipv6_probe ( struct net_device *netdev ) {
return 0;
}
/**
* Handle IPv6 network device or link state change
*
* @v netdev Network device
*/
static void ipv6_notify ( struct net_device *netdev __unused ) {
/* Nothing to do */
}
/**
* Destroy IPv6 network device
*
@ -973,7 +963,6 @@ static void ipv6_remove ( struct net_device *netdev ) {
struct net_driver ipv6_driver __net_driver = {
.name = "IPv6",
.probe = ipv6_probe,
.notify = ipv6_notify,
.remove = ipv6_remove,
};

View File

@ -375,16 +375,6 @@ int neighbour_define ( struct net_device *netdev,
return 0;
}
/**
* Update neighbour cache on network device creation
*
* @v netdev Network device
*/
static int neighbour_probe ( struct net_device *netdev __unused ) {
/* Nothing to do */
return 0;
}
/**
* Update neighbour cache on network device state change or removal
*
@ -404,7 +394,6 @@ static void neighbour_flush ( struct net_device *netdev ) {
/** Neighbour driver (for net device notifications) */
struct net_driver neighbour_net_driver __net_driver = {
.name = "Neighbour",
.probe = neighbour_probe,
.notify = neighbour_flush,
.remove = neighbour_flush,
};

View File

@ -90,8 +90,10 @@ static int netdev_has_ll_addr ( struct net_device *netdev ) {
static void netdev_notify ( struct net_device *netdev ) {
struct net_driver *driver;
for_each_table_entry ( driver, NET_DRIVERS )
for_each_table_entry ( driver, NET_DRIVERS ) {
if ( driver->notify )
driver->notify ( netdev );
}
}
/**
@ -535,7 +537,7 @@ int register_netdev ( struct net_device *netdev ) {
/* Probe device */
for_each_table_entry ( driver, NET_DRIVERS ) {
if ( ( rc = driver->probe ( netdev ) ) != 0 ) {
if ( driver->probe && ( rc = driver->probe ( netdev ) ) != 0 ) {
DBGC ( netdev, "NETDEV %s could not add %s device: "
"%s\n", netdev->name, driver->name,
strerror ( rc ) );
@ -546,8 +548,10 @@ int register_netdev ( struct net_device *netdev ) {
return 0;
err_probe:
for_each_table_entry_continue_reverse ( driver, NET_DRIVERS )
for_each_table_entry_continue_reverse ( driver, NET_DRIVERS ) {
if ( driver->remove )
driver->remove ( netdev );
}
clear_settings ( netdev_settings ( netdev ) );
unregister_settings ( netdev_settings ( netdev ) );
err_register_settings:
@ -629,8 +633,10 @@ void unregister_netdev ( struct net_device *netdev ) {
netdev_close ( netdev );
/* Remove device */
for_each_table_entry_reverse ( driver, NET_DRIVERS )
for_each_table_entry_reverse ( driver, NET_DRIVERS ) {
if ( driver->remove )
driver->remove ( netdev );
}
/* Unregister per-netdev configuration settings */
clear_settings ( netdev_settings ( netdev ) );

View File

@ -439,16 +439,6 @@ int vlan_destroy ( struct net_device *netdev ) {
return 0;
}
/**
* Do nothing
*
* @v trunk Trunk network device
* @ret rc Return status code
*/
static int vlan_probe ( struct net_device *trunk __unused ) {
return 0;
}
/**
* Handle trunk network device link state change
*
@ -505,7 +495,6 @@ static void vlan_remove ( struct net_device *trunk ) {
/** VLAN driver */
struct net_driver vlan_driver __net_driver = {
.name = "VLAN",
.probe = vlan_probe,
.notify = vlan_notify,
.remove = vlan_remove,
};