rxrpc: Add config to inject packet loss
authorDavid Howells <dhowells@redhat.com>
Sat, 17 Sep 2016 09:49:15 +0000 (10:49 +0100)
committerDavid Howells <dhowells@redhat.com>
Sat, 17 Sep 2016 10:24:04 +0000 (11:24 +0100)
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>
net/rxrpc/Kconfig
net/rxrpc/input.c
net/rxrpc/output.c

index 13396c74b5c12c7b875f7ff292baa472a61fe0d6..86f8853a038c50b14b5fbb5f36d77bea2fd17183 100644 (file)
@@ -26,6 +26,13 @@ config AF_RXRPC_IPV6
          Say Y here to allow AF_RXRPC to use IPV6 UDP as well as IPV4 UDP as
          its network transport.
 
+config AF_RXRPC_INJECT_LOSS
+       bool "Inject packet loss into RxRPC packet stream"
+       depends on AF_RXRPC
+       help
+         Say Y here to inject packet loss by discarding some received and some
+         transmitted packets.
+
 
 config AF_RXRPC_DEBUG
        bool "RxRPC dynamic debugging"
index 84bb16d47b85f40594ca15e5acebc2bb66e74a7b..7ac1edf3aac70f0da2c0ab9745e77371e476e1eb 100644 (file)
@@ -712,6 +712,14 @@ void rxrpc_data_ready(struct sock *udp_sk)
        skb_orphan(skb);
        sp = rxrpc_skb(skb);
 
+       if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) {
+               static int lose;
+               if ((lose++ & 7) == 7) {
+                       rxrpc_lose_skb(skb, rxrpc_skb_rx_lost);
+                       return;
+               }
+       }
+
        _net("Rx UDP packet from %08x:%04hu",
             ntohl(ip_hdr(skb)->saddr), ntohs(udp_hdr(skb)->source));
 
index a2cad5ce741693e937ae103295903830dba25701..16e18a94ffa61a05029629ad416bf14977ffeb07 100644 (file)
@@ -225,6 +225,15 @@ int rxrpc_send_data_packet(struct rxrpc_connection *conn, struct sk_buff *skb)
        msg.msg_controllen = 0;
        msg.msg_flags = 0;
 
+       if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) {
+               static int lose;
+               if ((lose++ & 7) == 7) {
+                       rxrpc_lose_skb(skb, rxrpc_skb_tx_lost);
+                       _leave(" = 0 [lose]");
+                       return 0;
+               }
+       }
+
        /* send the packet with the don't fragment bit set if we currently
         * think it's small enough */
        if (skb->len - sizeof(struct rxrpc_wire_header) < conn->params.peer->maxdata) {