summaryrefslogtreecommitdiffstats
path: root/src/net/netdevice.c
diff options
context:
space:
mode:
authorMichael Brown2015-07-22 03:56:49 +0200
committerMichael Brown2015-07-22 22:17:47 +0200
commitd0325b1da64c8ff611cd4c3151e266dd2685c462 (patch)
treeaa8daf27408752e2c88cba632fe8443682922b50 /src/net/netdevice.c
parent[tcp] Ensure FIN is actually sent if connection is closed while idle (diff)
downloadipxe-d0325b1da64c8ff611cd4c3151e266dd2685c462.tar.gz
ipxe-d0325b1da64c8ff611cd4c3151e266dd2685c462.tar.xz
ipxe-d0325b1da64c8ff611cd4c3151e266dd2685c462.zip
[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>
Diffstat (limited to 'src/net/netdevice.c')
-rw-r--r--src/net/netdevice.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/net/netdevice.c b/src/net/netdevice.c
index f2821efe..889b00c1 100644
--- a/src/net/netdevice.c
+++ b/src/net/netdevice.c
@@ -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;
}