mirror of
https://github.com/ipxe/ipxe
synced 2025-12-31 06:49:20 +03:00
[fault] Generalise NETDEV_DISCARD_RATE fault injection mechanism
Provide a generic inject_fault() function that can be used to inject random faults with configurable probabilities. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -39,6 +39,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
#include <ipxe/device.h>
|
||||
#include <ipxe/errortab.h>
|
||||
#include <ipxe/profile.h>
|
||||
#include <ipxe/fault.h>
|
||||
#include <ipxe/vlan.h>
|
||||
#include <ipxe/netdevice.h>
|
||||
|
||||
@@ -303,11 +304,8 @@ int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf ) {
|
||||
}
|
||||
|
||||
/* Discard packet (for test purposes) if applicable */
|
||||
if ( ( NETDEV_DISCARD_RATE > 0 ) &&
|
||||
( ( random() % NETDEV_DISCARD_RATE ) == 0 ) ) {
|
||||
rc = -EAGAIN;
|
||||
if ( ( rc = inject_fault ( NETDEV_DISCARD_RATE ) ) != 0 )
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Transmit packet */
|
||||
if ( ( rc = netdev->op->transmit ( netdev, iobuf ) ) != 0 )
|
||||
@@ -457,14 +455,14 @@ static void netdev_tx_flush ( struct net_device *netdev ) {
|
||||
* function takes ownership of the I/O buffer.
|
||||
*/
|
||||
void netdev_rx ( struct net_device *netdev, struct io_buffer *iobuf ) {
|
||||
int rc;
|
||||
|
||||
DBGC2 ( netdev, "NETDEV %s received %p (%p+%zx)\n",
|
||||
netdev->name, iobuf, iobuf->data, iob_len ( iobuf ) );
|
||||
|
||||
/* Discard packet (for test purposes) if applicable */
|
||||
if ( ( NETDEV_DISCARD_RATE > 0 ) &&
|
||||
( ( random() % NETDEV_DISCARD_RATE ) == 0 ) ) {
|
||||
netdev_rx_err ( netdev, iobuf, -EAGAIN );
|
||||
if ( ( rc = inject_fault ( NETDEV_DISCARD_RATE ) ) != 0 ) {
|
||||
netdev_rx_err ( netdev, iobuf, rc );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user