Skip to content

Commit 8a681c3

Browse files
committed
rxrpc: Add config to inject packet loss
Add a configuration option to inject packet loss by discarding approximately every 8th packet received and approximately every 8th DATA packet transmitted. Note that no locking is used, but it shouldn't really matter. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 71f3ca4 commit 8a681c3

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

net/rxrpc/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ config AF_RXRPC_IPV6
2626
Say Y here to allow AF_RXRPC to use IPV6 UDP as well as IPV4 UDP as
2727
its network transport.
2828

29+
config AF_RXRPC_INJECT_LOSS
30+
bool "Inject packet loss into RxRPC packet stream"
31+
depends on AF_RXRPC
32+
help
33+
Say Y here to inject packet loss by discarding some received and some
34+
transmitted packets.
35+
2936

3037
config AF_RXRPC_DEBUG
3138
bool "RxRPC dynamic debugging"

net/rxrpc/input.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,14 @@ void rxrpc_data_ready(struct sock *udp_sk)
712712
skb_orphan(skb);
713713
sp = rxrpc_skb(skb);
714714

715+
if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) {
716+
static int lose;
717+
if ((lose++ & 7) == 7) {
718+
rxrpc_lose_skb(skb, rxrpc_skb_rx_lost);
719+
return;
720+
}
721+
}
722+
715723
_net("Rx UDP packet from %08x:%04hu",
716724
ntohl(ip_hdr(skb)->saddr), ntohs(udp_hdr(skb)->source));
717725

net/rxrpc/output.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ int rxrpc_send_data_packet(struct rxrpc_connection *conn, struct sk_buff *skb)
225225
msg.msg_controllen = 0;
226226
msg.msg_flags = 0;
227227

228+
if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) {
229+
static int lose;
230+
if ((lose++ & 7) == 7) {
231+
rxrpc_lose_skb(skb, rxrpc_skb_tx_lost);
232+
_leave(" = 0 [lose]");
233+
return 0;
234+
}
235+
}
236+
228237
/* send the packet with the don't fragment bit set if we currently
229238
* think it's small enough */
230239
if (skb->len - sizeof(struct rxrpc_wire_header) < conn->params.peer->maxdata) {

0 commit comments

Comments
 (0)