aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2016-09-02 17:39:45 -0400
committerDavid Howells <dhowells@redhat.com>2016-09-04 16:41:39 -0400
commit5f2d9c44389e7cd9fe192570f6f20199bc861eb8 (patch)
tree1339480e8cf3b2efaa3f1543e7504e3eb0602408
parentaf338a9ea60acc6337fe9fcdcf664aec2520e541 (diff)
rxrpc: Randomise epoch and starting client conn ID values
Create a random epoch value rather than a time-based one on startup and set the top bit to indicate that this is the case. Also create a random starting client connection ID value. This will be incremented from here as new client connections are created. Signed-off-by: David Howells <dhowells@redhat.com>
-rw-r--r--include/rxrpc/packet.h1
-rw-r--r--net/rxrpc/af_rxrpc.c9
2 files changed, 9 insertions, 1 deletions
diff --git a/include/rxrpc/packet.h b/include/rxrpc/packet.h
index b2017440b765..3c6128e1fdbe 100644
--- a/include/rxrpc/packet.h
+++ b/include/rxrpc/packet.h
@@ -24,6 +24,7 @@ typedef __be32 rxrpc_serial_net_t; /* on-the-wire Rx message serial number */
24 */ 24 */
25struct rxrpc_wire_header { 25struct rxrpc_wire_header {
26 __be32 epoch; /* client boot timestamp */ 26 __be32 epoch; /* client boot timestamp */
27#define RXRPC_RANDOM_EPOCH 0x80000000 /* Random if set, date-based if not */
27 28
28 __be32 cid; /* connection and channel ID */ 29 __be32 cid; /* connection and channel ID */
29#define RXRPC_MAXCALLS 4 /* max active calls per conn */ 30#define RXRPC_MAXCALLS 4 /* max active calls per conn */
diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
index 32d544995dda..b66a9e6f8d04 100644
--- a/net/rxrpc/af_rxrpc.c
+++ b/net/rxrpc/af_rxrpc.c
@@ -16,6 +16,7 @@
16#include <linux/net.h> 16#include <linux/net.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/skbuff.h> 18#include <linux/skbuff.h>
19#include <linux/random.h>
19#include <linux/poll.h> 20#include <linux/poll.h>
20#include <linux/proc_fs.h> 21#include <linux/proc_fs.h>
21#include <linux/key-type.h> 22#include <linux/key-type.h>
@@ -700,7 +701,13 @@ static int __init af_rxrpc_init(void)
700 701
701 BUILD_BUG_ON(sizeof(struct rxrpc_skb_priv) > FIELD_SIZEOF(struct sk_buff, cb)); 702 BUILD_BUG_ON(sizeof(struct rxrpc_skb_priv) > FIELD_SIZEOF(struct sk_buff, cb));
702 703
703 rxrpc_epoch = get_seconds(); 704 get_random_bytes(&rxrpc_epoch, sizeof(rxrpc_epoch));
705 rxrpc_epoch |= RXRPC_RANDOM_EPOCH;
706 get_random_bytes(&rxrpc_client_conn_ids.cur,
707 sizeof(rxrpc_client_conn_ids.cur));
708 rxrpc_client_conn_ids.cur &= 0x3fffffff;
709 if (rxrpc_client_conn_ids.cur == 0)
710 rxrpc_client_conn_ids.cur = 1;
704 711
705 ret = -ENOMEM; 712 ret = -ENOMEM;
706 rxrpc_call_jar = kmem_cache_create( 713 rxrpc_call_jar = kmem_cache_create(