aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2016-03-04 10:53:46 -0500
committerDavid Howells <dhowells@redhat.com>2016-03-04 10:53:46 -0500
commit0d12f8a4027d021c9cc942f09f38d28288020c5d (patch)
tree751f54f93f15d9c0146cf2e4243dbfc25fd1cc6d
parent4c198ad17a7253cc8ef3ff39bfe73d6b5e65ceef (diff)
rxrpc: Keep the skb private record of the Rx header in host byte order
Currently, a copy of the Rx packet header is copied into the the sk_buff private data so that we can advance the pointer into the buffer, potentially discarding the original. At the moment, this copy is held in network byte order, but this means we're doing a lot of unnecessary translations. The reasons it was done this way are that we need the values in network byte order occasionally and we can use the copy, slightly modified, as part of an iov array when sending an ack or an abort packet. However, it seems more reasonable on review that it would be better kept in host byte order and that we make up a new header when we want to send another packet. To this end, rename the original header struct to rxrpc_wire_header (with BE fields) and institute a variant called rxrpc_host_header that has host order fields. Change the struct in the sk_buff private data into an rxrpc_host_header and translate the values when filling it in. This further allows us to keep values kept in various structures in host byte order rather than network byte order and allows removal of some fields that are byteswapped duplicates. Signed-off-by: David Howells <dhowells@redhat.com>
-rw-r--r--include/rxrpc/packet.h4
-rw-r--r--net/rxrpc/af_rxrpc.c20
-rw-r--r--net/rxrpc/ar-accept.c40
-rw-r--r--net/rxrpc/ar-ack.c108
-rw-r--r--net/rxrpc/ar-call.c68
-rw-r--r--net/rxrpc/ar-connection.c83
-rw-r--r--net/rxrpc/ar-connevent.c73
-rw-r--r--net/rxrpc/ar-input.c95
-rw-r--r--net/rxrpc/ar-internal.h65
-rw-r--r--net/rxrpc/ar-local.c29
-rw-r--r--net/rxrpc/ar-output.c54
-rw-r--r--net/rxrpc/ar-peer.c2
-rw-r--r--net/rxrpc/ar-proc.c10
-rw-r--r--net/rxrpc/ar-recvmsg.c18
-rw-r--r--net/rxrpc/ar-security.c4
-rw-r--r--net/rxrpc/ar-skbuff.c4
-rw-r--r--net/rxrpc/ar-transport.c1
-rw-r--r--net/rxrpc/rxkad.c138
18 files changed, 432 insertions, 384 deletions
diff --git a/include/rxrpc/packet.h b/include/rxrpc/packet.h
index 4dce116bfd80..de1e67988ada 100644
--- a/include/rxrpc/packet.h
+++ b/include/rxrpc/packet.h
@@ -22,7 +22,7 @@ typedef __be32 rxrpc_serial_net_t; /* on-the-wire Rx message serial number */
22 * on-the-wire Rx packet header 22 * on-the-wire Rx packet header
23 * - all multibyte fields should be in network byte order 23 * - all multibyte fields should be in network byte order
24 */ 24 */
25struct rxrpc_header { 25struct rxrpc_wire_header {
26 __be32 epoch; /* client boot timestamp */ 26 __be32 epoch; /* client boot timestamp */
27 27
28 __be32 cid; /* connection and channel ID */ 28 __be32 cid; /* connection and channel ID */
@@ -68,8 +68,6 @@ struct rxrpc_header {
68 68
69} __packed; 69} __packed;
70 70
71#define __rxrpc_header_off(X) offsetof(struct rxrpc_header,X)
72
73extern const char *rxrpc_pkts[]; 71extern const char *rxrpc_pkts[];
74 72
75/*****************************************************************************/ 73/*****************************************************************************/
diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
index 7e2d1057d8bc..7bb5cca0ae32 100644
--- a/net/rxrpc/af_rxrpc.c
+++ b/net/rxrpc/af_rxrpc.c
@@ -37,7 +37,7 @@ static struct proto rxrpc_proto;
37static const struct proto_ops rxrpc_rpc_ops; 37static const struct proto_ops rxrpc_rpc_ops;
38 38
39/* local epoch for detecting local-end reset */ 39/* local epoch for detecting local-end reset */
40__be32 rxrpc_epoch; 40u32 rxrpc_epoch;
41 41
42/* current debugging ID */ 42/* current debugging ID */
43atomic_t rxrpc_debug_id; 43atomic_t rxrpc_debug_id;
@@ -125,7 +125,6 @@ static int rxrpc_bind(struct socket *sock, struct sockaddr *saddr, int len)
125 struct sock *sk = sock->sk; 125 struct sock *sk = sock->sk;
126 struct rxrpc_local *local; 126 struct rxrpc_local *local;
127 struct rxrpc_sock *rx = rxrpc_sk(sk), *prx; 127 struct rxrpc_sock *rx = rxrpc_sk(sk), *prx;
128 __be16 service_id;
129 int ret; 128 int ret;
130 129
131 _enter("%p,%p,%d", rx, saddr, len); 130 _enter("%p,%p,%d", rx, saddr, len);
@@ -152,14 +151,12 @@ static int rxrpc_bind(struct socket *sock, struct sockaddr *saddr, int len)
152 151
153 rx->local = local; 152 rx->local = local;
154 if (srx->srx_service) { 153 if (srx->srx_service) {
155 service_id = htons(srx->srx_service);
156 write_lock_bh(&local->services_lock); 154 write_lock_bh(&local->services_lock);
157 list_for_each_entry(prx, &local->services, listen_link) { 155 list_for_each_entry(prx, &local->services, listen_link) {
158 if (prx->service_id == service_id) 156 if (prx->srx.srx_service == srx->srx_service)
159 goto service_in_use; 157 goto service_in_use;
160 } 158 }
161 159
162 rx->service_id = service_id;
163 list_add_tail(&rx->listen_link, &local->services); 160 list_add_tail(&rx->listen_link, &local->services);
164 write_unlock_bh(&local->services_lock); 161 write_unlock_bh(&local->services_lock);
165 162
@@ -276,7 +273,6 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
276 struct rxrpc_transport *trans; 273 struct rxrpc_transport *trans;
277 struct rxrpc_call *call; 274 struct rxrpc_call *call;
278 struct rxrpc_sock *rx = rxrpc_sk(sock->sk); 275 struct rxrpc_sock *rx = rxrpc_sk(sock->sk);
279 __be16 service_id;
280 276
281 _enter(",,%x,%lx", key_serial(key), user_call_ID); 277 _enter(",,%x,%lx", key_serial(key), user_call_ID);
282 278
@@ -299,16 +295,15 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
299 atomic_inc(&trans->usage); 295 atomic_inc(&trans->usage);
300 } 296 }
301 297
302 service_id = rx->service_id; 298 if (!srx)
303 if (srx) 299 srx = &rx->srx;
304 service_id = htons(srx->srx_service);
305 300
306 if (!key) 301 if (!key)
307 key = rx->key; 302 key = rx->key;
308 if (key && !key->payload.data[0]) 303 if (key && !key->payload.data[0])
309 key = NULL; /* a no-security key */ 304 key = NULL; /* a no-security key */
310 305
311 bundle = rxrpc_get_bundle(rx, trans, key, service_id, gfp); 306 bundle = rxrpc_get_bundle(rx, trans, key, srx->srx_service, gfp);
312 if (IS_ERR(bundle)) { 307 if (IS_ERR(bundle)) {
313 call = ERR_CAST(bundle); 308 call = ERR_CAST(bundle);
314 goto out; 309 goto out;
@@ -425,7 +420,6 @@ static int rxrpc_connect(struct socket *sock, struct sockaddr *addr,
425 } 420 }
426 421
427 rx->trans = trans; 422 rx->trans = trans;
428 rx->service_id = htons(srx->srx_service);
429 rx->sk.sk_state = RXRPC_CLIENT_CONNECTED; 423 rx->sk.sk_state = RXRPC_CLIENT_CONNECTED;
430 424
431 release_sock(&rx->sk); 425 release_sock(&rx->sk);
@@ -778,7 +772,7 @@ static struct proto rxrpc_proto = {
778 .name = "RXRPC", 772 .name = "RXRPC",
779 .owner = THIS_MODULE, 773 .owner = THIS_MODULE,
780 .obj_size = sizeof(struct rxrpc_sock), 774 .obj_size = sizeof(struct rxrpc_sock),
781 .max_header = sizeof(struct rxrpc_header), 775 .max_header = sizeof(struct rxrpc_wire_header),
782}; 776};
783 777
784static const struct net_proto_family rxrpc_family_ops = { 778static const struct net_proto_family rxrpc_family_ops = {
@@ -796,7 +790,7 @@ static int __init af_rxrpc_init(void)
796 790
797 BUILD_BUG_ON(sizeof(struct rxrpc_skb_priv) > FIELD_SIZEOF(struct sk_buff, cb)); 791 BUILD_BUG_ON(sizeof(struct rxrpc_skb_priv) > FIELD_SIZEOF(struct sk_buff, cb));
798 792
799 rxrpc_epoch = htonl(get_seconds()); 793 rxrpc_epoch = get_seconds();
800 794
801 ret = -ENOMEM; 795 ret = -ENOMEM;
802 rxrpc_call_jar = kmem_cache_create( 796 rxrpc_call_jar = kmem_cache_create(
diff --git a/net/rxrpc/ar-accept.c b/net/rxrpc/ar-accept.c
index 9a49f32e9e1e..73c905416271 100644
--- a/net/rxrpc/ar-accept.c
+++ b/net/rxrpc/ar-accept.c
@@ -27,7 +27,7 @@
27 * generate a connection-level abort 27 * generate a connection-level abort
28 */ 28 */
29static int rxrpc_busy(struct rxrpc_local *local, struct sockaddr_rxrpc *srx, 29static int rxrpc_busy(struct rxrpc_local *local, struct sockaddr_rxrpc *srx,
30 struct rxrpc_header *hdr) 30 struct rxrpc_wire_header *whdr)
31{ 31{
32 struct msghdr msg; 32 struct msghdr msg;
33 struct kvec iov[1]; 33 struct kvec iov[1];
@@ -36,25 +36,21 @@ static int rxrpc_busy(struct rxrpc_local *local, struct sockaddr_rxrpc *srx,
36 36
37 _enter("%d,,", local->debug_id); 37 _enter("%d,,", local->debug_id);
38 38
39 whdr->type = RXRPC_PACKET_TYPE_BUSY;
40 whdr->serial = htonl(1);
41
39 msg.msg_name = &srx->transport.sin; 42 msg.msg_name = &srx->transport.sin;
40 msg.msg_namelen = sizeof(srx->transport.sin); 43 msg.msg_namelen = sizeof(srx->transport.sin);
41 msg.msg_control = NULL; 44 msg.msg_control = NULL;
42 msg.msg_controllen = 0; 45 msg.msg_controllen = 0;
43 msg.msg_flags = 0; 46 msg.msg_flags = 0;
44 47
45 hdr->seq = 0; 48 iov[0].iov_base = whdr;
46 hdr->type = RXRPC_PACKET_TYPE_BUSY; 49 iov[0].iov_len = sizeof(*whdr);
47 hdr->flags = 0;
48 hdr->userStatus = 0;
49 hdr->_rsvd = 0;
50
51 iov[0].iov_base = hdr;
52 iov[0].iov_len = sizeof(*hdr);
53 50
54 len = iov[0].iov_len; 51 len = iov[0].iov_len;
55 52
56 hdr->serial = htonl(1); 53 _proto("Tx BUSY %%1");
57 _proto("Tx BUSY %%%u", ntohl(hdr->serial));
58 54
59 ret = kernel_sendmsg(local->socket, &msg, iov, 1, len); 55 ret = kernel_sendmsg(local->socket, &msg, iov, 1, len);
60 if (ret < 0) { 56 if (ret < 0) {
@@ -211,8 +207,8 @@ void rxrpc_accept_incoming_calls(struct work_struct *work)
211 struct rxrpc_skb_priv *sp; 207 struct rxrpc_skb_priv *sp;
212 struct sockaddr_rxrpc srx; 208 struct sockaddr_rxrpc srx;
213 struct rxrpc_sock *rx; 209 struct rxrpc_sock *rx;
210 struct rxrpc_wire_header whdr;
214 struct sk_buff *skb; 211 struct sk_buff *skb;
215 __be16 service_id;
216 int ret; 212 int ret;
217 213
218 _enter("%d", local->debug_id); 214 _enter("%d", local->debug_id);
@@ -240,6 +236,19 @@ process_next_packet:
240 236
241 sp = rxrpc_skb(skb); 237 sp = rxrpc_skb(skb);
242 238
239 /* Set up a response packet header in case we need it */
240 whdr.epoch = htonl(sp->hdr.epoch);
241 whdr.cid = htonl(sp->hdr.cid);
242 whdr.callNumber = htonl(sp->hdr.callNumber);
243 whdr.seq = htonl(sp->hdr.seq);
244 whdr.serial = 0;
245 whdr.flags = 0;
246 whdr.type = 0;
247 whdr.userStatus = 0;
248 whdr.securityIndex = sp->hdr.securityIndex;
249 whdr._rsvd = 0;
250 whdr.serviceId = htons(sp->hdr.serviceId);
251
243 /* determine the remote address */ 252 /* determine the remote address */
244 memset(&srx, 0, sizeof(srx)); 253 memset(&srx, 0, sizeof(srx));
245 srx.srx_family = AF_RXRPC; 254 srx.srx_family = AF_RXRPC;
@@ -256,10 +265,9 @@ process_next_packet:
256 } 265 }
257 266
258 /* get the socket providing the service */ 267 /* get the socket providing the service */
259 service_id = sp->hdr.serviceId;
260 read_lock_bh(&local->services_lock); 268 read_lock_bh(&local->services_lock);
261 list_for_each_entry(rx, &local->services, listen_link) { 269 list_for_each_entry(rx, &local->services, listen_link) {
262 if (rx->service_id == service_id && 270 if (rx->srx.srx_service == sp->hdr.serviceId &&
263 rx->sk.sk_state != RXRPC_CLOSE) 271 rx->sk.sk_state != RXRPC_CLOSE)
264 goto found_service; 272 goto found_service;
265 } 273 }
@@ -267,7 +275,7 @@ process_next_packet:
267 goto invalid_service; 275 goto invalid_service;
268 276
269found_service: 277found_service:
270 _debug("found service %hd", ntohs(rx->service_id)); 278 _debug("found service %hd", rx->srx.srx_service);
271 if (sk_acceptq_is_full(&rx->sk)) 279 if (sk_acceptq_is_full(&rx->sk))
272 goto backlog_full; 280 goto backlog_full;
273 sk_acceptq_added(&rx->sk); 281 sk_acceptq_added(&rx->sk);
@@ -296,7 +304,7 @@ found_service:
296backlog_full: 304backlog_full:
297 read_unlock_bh(&local->services_lock); 305 read_unlock_bh(&local->services_lock);
298busy: 306busy:
299 rxrpc_busy(local, &srx, &sp->hdr); 307 rxrpc_busy(local, &srx, &whdr);
300 rxrpc_free_skb(skb); 308 rxrpc_free_skb(skb);
301 goto process_next_packet; 309 goto process_next_packet;
302 310
diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
index 9183da740600..20f3f001694e 100644
--- a/net/rxrpc/ar-ack.c
+++ b/net/rxrpc/ar-ack.c
@@ -91,7 +91,7 @@ static const s8 rxrpc_ack_priority[] = {
91 * propose an ACK be sent 91 * propose an ACK be sent
92 */ 92 */
93void __rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason, 93void __rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason,
94 __be32 serial, bool immediate) 94 u32 serial, bool immediate)
95{ 95{
96 unsigned long expiry; 96 unsigned long expiry;
97 s8 prior = rxrpc_ack_priority[ack_reason]; 97 s8 prior = rxrpc_ack_priority[ack_reason];
@@ -99,8 +99,7 @@ void __rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason,
99 ASSERTCMP(prior, >, 0); 99 ASSERTCMP(prior, >, 0);
100 100
101 _enter("{%d},%s,%%%x,%u", 101 _enter("{%d},%s,%%%x,%u",
102 call->debug_id, rxrpc_acks(ack_reason), ntohl(serial), 102 call->debug_id, rxrpc_acks(ack_reason), serial, immediate);
103 immediate);
104 103
105 if (prior < rxrpc_ack_priority[call->ackr_reason]) { 104 if (prior < rxrpc_ack_priority[call->ackr_reason]) {
106 if (immediate) 105 if (immediate)
@@ -139,7 +138,7 @@ void __rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason,
139 expiry = rxrpc_requested_ack_delay; 138 expiry = rxrpc_requested_ack_delay;
140 if (!expiry) 139 if (!expiry)
141 goto cancel_timer; 140 goto cancel_timer;
142 if (!immediate || serial == cpu_to_be32(1)) { 141 if (!immediate || serial == 1) {
143 _debug("run defer timer"); 142 _debug("run defer timer");
144 goto run_timer; 143 goto run_timer;
145 } 144 }
@@ -157,7 +156,7 @@ run_timer:
157 return; 156 return;
158 157
159cancel_timer: 158cancel_timer:
160 _debug("cancel timer %%%u", ntohl(serial)); 159 _debug("cancel timer %%%u", serial);
161 try_to_del_timer_sync(&call->ack_timer); 160 try_to_del_timer_sync(&call->ack_timer);
162 read_lock_bh(&call->state_lock); 161 read_lock_bh(&call->state_lock);
163 if (call->state <= RXRPC_CALL_COMPLETE && 162 if (call->state <= RXRPC_CALL_COMPLETE &&
@@ -170,7 +169,7 @@ cancel_timer:
170 * propose an ACK be sent, locking the call structure 169 * propose an ACK be sent, locking the call structure
171 */ 170 */
172void rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason, 171void rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason,
173 __be32 serial, bool immediate) 172 u32 serial, bool immediate)
174{ 173{
175 s8 prior = rxrpc_ack_priority[ack_reason]; 174 s8 prior = rxrpc_ack_priority[ack_reason];
176 175
@@ -214,8 +213,8 @@ static void rxrpc_set_resend(struct rxrpc_call *call, u8 resend,
214 */ 213 */
215static void rxrpc_resend(struct rxrpc_call *call) 214static void rxrpc_resend(struct rxrpc_call *call)
216{ 215{
216 struct rxrpc_wire_header *whdr;
217 struct rxrpc_skb_priv *sp; 217 struct rxrpc_skb_priv *sp;
218 struct rxrpc_header *hdr;
219 struct sk_buff *txb; 218 struct sk_buff *txb;
220 unsigned long *p_txb, resend_at; 219 unsigned long *p_txb, resend_at;
221 bool stop; 220 bool stop;
@@ -247,14 +246,13 @@ static void rxrpc_resend(struct rxrpc_call *call)
247 sp->need_resend = false; 246 sp->need_resend = false;
248 247
249 /* each Tx packet has a new serial number */ 248 /* each Tx packet has a new serial number */
250 sp->hdr.serial = 249 sp->hdr.serial = atomic_inc_return(&call->conn->serial);
251 htonl(atomic_inc_return(&call->conn->serial));
252 250
253 hdr = (struct rxrpc_header *) txb->head; 251 whdr = (struct rxrpc_wire_header *)txb->head;
254 hdr->serial = sp->hdr.serial; 252 whdr->serial = htonl(sp->hdr.serial);
255 253
256 _proto("Tx DATA %%%u { #%d }", 254 _proto("Tx DATA %%%u { #%d }",
257 ntohl(sp->hdr.serial), ntohl(sp->hdr.seq)); 255 sp->hdr.serial, sp->hdr.seq);
258 if (rxrpc_send_packet(call->conn->trans, txb) < 0) { 256 if (rxrpc_send_packet(call->conn->trans, txb) < 0) {
259 stop = true; 257 stop = true;
260 sp->resend_at = jiffies + 3; 258 sp->resend_at = jiffies + 3;
@@ -428,7 +426,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
428 int tail = call->acks_tail, old_tail; 426 int tail = call->acks_tail, old_tail;
429 int win = CIRC_CNT(call->acks_head, tail, call->acks_winsz); 427 int win = CIRC_CNT(call->acks_head, tail, call->acks_winsz);
430 428
431 _enter("{%u,%u},%u", call->acks_hard, win, hard); 429 kenter("{%u,%u},%u", call->acks_hard, win, hard);
432 430
433 ASSERTCMP(hard - call->acks_hard, <=, win); 431 ASSERTCMP(hard - call->acks_hard, <=, win);
434 432
@@ -478,11 +476,11 @@ static int rxrpc_drain_rx_oos_queue(struct rxrpc_call *call)
478 sp = rxrpc_skb(skb); 476 sp = rxrpc_skb(skb);
479 477
480 _debug("drain OOS packet %d [%d]", 478 _debug("drain OOS packet %d [%d]",
481 ntohl(sp->hdr.seq), call->rx_first_oos); 479 sp->hdr.seq, call->rx_first_oos);
482 480
483 if (ntohl(sp->hdr.seq) != call->rx_first_oos) { 481 if (sp->hdr.seq != call->rx_first_oos) {
484 skb_queue_head(&call->rx_oos_queue, skb); 482 skb_queue_head(&call->rx_oos_queue, skb);
485 call->rx_first_oos = ntohl(rxrpc_skb(skb)->hdr.seq); 483 call->rx_first_oos = rxrpc_skb(skb)->hdr.seq;
486 _debug("requeue %p {%u}", skb, call->rx_first_oos); 484 _debug("requeue %p {%u}", skb, call->rx_first_oos);
487 } else { 485 } else {
488 skb->mark = RXRPC_SKB_MARK_DATA; 486 skb->mark = RXRPC_SKB_MARK_DATA;
@@ -496,8 +494,7 @@ static int rxrpc_drain_rx_oos_queue(struct rxrpc_call *call)
496 /* find out what the next packet is */ 494 /* find out what the next packet is */
497 skb = skb_peek(&call->rx_oos_queue); 495 skb = skb_peek(&call->rx_oos_queue);
498 if (skb) 496 if (skb)
499 call->rx_first_oos = 497 call->rx_first_oos = rxrpc_skb(skb)->hdr.seq;
500 ntohl(rxrpc_skb(skb)->hdr.seq);
501 else 498 else
502 call->rx_first_oos = 0; 499 call->rx_first_oos = 0;
503 _debug("peek %p {%u}", skb, call->rx_first_oos); 500 _debug("peek %p {%u}", skb, call->rx_first_oos);
@@ -522,7 +519,7 @@ static void rxrpc_insert_oos_packet(struct rxrpc_call *call,
522 u32 seq; 519 u32 seq;
523 520
524 sp = rxrpc_skb(skb); 521 sp = rxrpc_skb(skb);
525 seq = ntohl(sp->hdr.seq); 522 seq = sp->hdr.seq;
526 _enter(",,{%u}", seq); 523 _enter(",,{%u}", seq);
527 524
528 skb->destructor = rxrpc_packet_destructor; 525 skb->destructor = rxrpc_packet_destructor;
@@ -535,9 +532,8 @@ static void rxrpc_insert_oos_packet(struct rxrpc_call *call,
535 532
536 skb_queue_walk(&call->rx_oos_queue, p) { 533 skb_queue_walk(&call->rx_oos_queue, p) {
537 psp = rxrpc_skb(p); 534 psp = rxrpc_skb(p);
538 if (ntohl(psp->hdr.seq) > seq) { 535 if (psp->hdr.seq > seq) {
539 _debug("insert oos #%u before #%u", 536 _debug("insert oos #%u before #%u", seq, psp->hdr.seq);
540 seq, ntohl(psp->hdr.seq));
541 skb_insert(p, skb, &call->rx_oos_queue); 537 skb_insert(p, skb, &call->rx_oos_queue);
542 goto inserted; 538 goto inserted;
543 } 539 }
@@ -586,7 +582,7 @@ static void rxrpc_zap_tx_window(struct rxrpc_call *call)
586 582
587 skb = (struct sk_buff *) _skb; 583 skb = (struct sk_buff *) _skb;
588 sp = rxrpc_skb(skb); 584 sp = rxrpc_skb(skb);
589 _debug("+++ clear Tx %u", ntohl(sp->hdr.seq)); 585 _debug("+++ clear Tx %u", sp->hdr.seq);
590 rxrpc_free_skb(skb); 586 rxrpc_free_skb(skb);
591 } 587 }
592 588
@@ -657,8 +653,7 @@ process_further:
657 /* data packets that wind up here have been received out of 653 /* data packets that wind up here have been received out of
658 * order, need security processing or are jumbo packets */ 654 * order, need security processing or are jumbo packets */
659 case RXRPC_PACKET_TYPE_DATA: 655 case RXRPC_PACKET_TYPE_DATA:
660 _proto("OOSQ DATA %%%u { #%u }", 656 _proto("OOSQ DATA %%%u { #%u }", sp->hdr.serial, sp->hdr.seq);
661 ntohl(sp->hdr.serial), ntohl(sp->hdr.seq));
662 657
663 /* secured packets must be verified and possibly decrypted */ 658 /* secured packets must be verified and possibly decrypted */
664 if (rxrpc_verify_packet(call, skb, _abort_code) < 0) 659 if (rxrpc_verify_packet(call, skb, _abort_code) < 0)
@@ -676,7 +671,7 @@ process_further:
676 if (!skb_pull(skb, sizeof(ack))) 671 if (!skb_pull(skb, sizeof(ack)))
677 BUG(); 672 BUG();
678 673
679 latest = ntohl(sp->hdr.serial); 674 latest = sp->hdr.serial;
680 hard = ntohl(ack.firstPacket); 675 hard = ntohl(ack.firstPacket);
681 tx = atomic_read(&call->sequence); 676 tx = atomic_read(&call->sequence);
682 677
@@ -881,9 +876,9 @@ void rxrpc_process_call(struct work_struct *work)
881{ 876{
882 struct rxrpc_call *call = 877 struct rxrpc_call *call =
883 container_of(work, struct rxrpc_call, processor); 878 container_of(work, struct rxrpc_call, processor);
879 struct rxrpc_wire_header whdr;
884 struct rxrpc_ackpacket ack; 880 struct rxrpc_ackpacket ack;
885 struct rxrpc_ackinfo ackinfo; 881 struct rxrpc_ackinfo ackinfo;
886 struct rxrpc_header hdr;
887 struct msghdr msg; 882 struct msghdr msg;
888 struct kvec iov[5]; 883 struct kvec iov[5];
889 enum rxrpc_call_event genbit; 884 enum rxrpc_call_event genbit;
@@ -891,7 +886,7 @@ void rxrpc_process_call(struct work_struct *work)
891 __be32 data, pad; 886 __be32 data, pad;
892 size_t len; 887 size_t len;
893 int loop, nbit, ioc, ret, mtu; 888 int loop, nbit, ioc, ret, mtu;
894 u32 abort_code = RX_PROTOCOL_ERROR; 889 u32 serial, abort_code = RX_PROTOCOL_ERROR;
895 u8 *acks = NULL; 890 u8 *acks = NULL;
896 891
897 //printk("\n--------------------\n"); 892 //printk("\n--------------------\n");
@@ -912,20 +907,20 @@ void rxrpc_process_call(struct work_struct *work)
912 msg.msg_controllen = 0; 907 msg.msg_controllen = 0;
913 msg.msg_flags = 0; 908 msg.msg_flags = 0;
914 909
915 hdr.epoch = call->conn->epoch; 910 whdr.epoch = htonl(call->conn->epoch);
916 hdr.cid = call->cid; 911 whdr.cid = htonl(call->cid);
917 hdr.callNumber = call->call_id; 912 whdr.callNumber = htonl(call->call_id);
918 hdr.seq = 0; 913 whdr.seq = 0;
919 hdr.type = RXRPC_PACKET_TYPE_ACK; 914 whdr.type = RXRPC_PACKET_TYPE_ACK;
920 hdr.flags = call->conn->out_clientflag; 915 whdr.flags = call->conn->out_clientflag;
921 hdr.userStatus = 0; 916 whdr.userStatus = 0;
922 hdr.securityIndex = call->conn->security_ix; 917 whdr.securityIndex = call->conn->security_ix;
923 hdr._rsvd = 0; 918 whdr._rsvd = 0;
924 hdr.serviceId = call->conn->service_id; 919 whdr.serviceId = htons(call->service_id);
925 920
926 memset(iov, 0, sizeof(iov)); 921 memset(iov, 0, sizeof(iov));
927 iov[0].iov_base = &hdr; 922 iov[0].iov_base = &whdr;
928 iov[0].iov_len = sizeof(hdr); 923 iov[0].iov_len = sizeof(whdr);
929 924
930 /* deal with events of a final nature */ 925 /* deal with events of a final nature */
931 if (test_bit(RXRPC_CALL_EV_RELEASE, &call->events)) { 926 if (test_bit(RXRPC_CALL_EV_RELEASE, &call->events)) {
@@ -966,7 +961,7 @@ void rxrpc_process_call(struct work_struct *work)
966 } 961 }
967 962
968 if (test_bit(RXRPC_CALL_EV_REJECT_BUSY, &call->events)) { 963 if (test_bit(RXRPC_CALL_EV_REJECT_BUSY, &call->events)) {
969 hdr.type = RXRPC_PACKET_TYPE_BUSY; 964 whdr.type = RXRPC_PACKET_TYPE_BUSY;
970 genbit = RXRPC_CALL_EV_REJECT_BUSY; 965 genbit = RXRPC_CALL_EV_REJECT_BUSY;
971 goto send_message; 966 goto send_message;
972 } 967 }
@@ -977,7 +972,7 @@ void rxrpc_process_call(struct work_struct *work)
977 if (rxrpc_post_message(call, RXRPC_SKB_MARK_LOCAL_ERROR, 972 if (rxrpc_post_message(call, RXRPC_SKB_MARK_LOCAL_ERROR,
978 ECONNABORTED, true) < 0) 973 ECONNABORTED, true) < 0)
979 goto no_mem; 974 goto no_mem;
980 hdr.type = RXRPC_PACKET_TYPE_ABORT; 975 whdr.type = RXRPC_PACKET_TYPE_ABORT;
981 data = htonl(call->abort_code); 976 data = htonl(call->abort_code);
982 iov[1].iov_base = &data; 977 iov[1].iov_base = &data;
983 iov[1].iov_len = sizeof(data); 978 iov[1].iov_len = sizeof(data);
@@ -996,9 +991,9 @@ void rxrpc_process_call(struct work_struct *work)
996 call->ackr_reason = 0; 991 call->ackr_reason = 0;
997 992
998 spin_lock_bh(&call->lock); 993 spin_lock_bh(&call->lock);
999 ack.serial = call->ackr_serial; 994 ack.serial = htonl(call->ackr_serial);
1000 ack.previousPacket = call->ackr_prev_seq; 995 ack.previousPacket = htonl(call->ackr_prev_seq);
1001 ack.firstPacket = htonl(call->rx_data_eaten + 1); 996 ack.firstPacket = htonl(call->rx_data_eaten + 1);
1002 spin_unlock_bh(&call->lock); 997 spin_unlock_bh(&call->lock);
1003 998
1004 pad = 0; 999 pad = 0;
@@ -1100,13 +1095,11 @@ void rxrpc_process_call(struct work_struct *work)
1100 //hdr.flags = RXRPC_SLOW_START_OK; 1095 //hdr.flags = RXRPC_SLOW_START_OK;
1101 ack.bufferSpace = htons(8); 1096 ack.bufferSpace = htons(8);
1102 ack.maxSkew = 0; 1097 ack.maxSkew = 0;
1103 ack.serial = 0;
1104 ack.reason = 0;
1105 1098
1106 spin_lock_bh(&call->lock); 1099 spin_lock_bh(&call->lock);
1107 ack.reason = call->ackr_reason; 1100 ack.reason = call->ackr_reason;
1108 ack.serial = call->ackr_serial; 1101 ack.serial = htonl(call->ackr_serial);
1109 ack.previousPacket = call->ackr_prev_seq; 1102 ack.previousPacket = htonl(call->ackr_prev_seq);
1110 ack.firstPacket = htonl(call->rx_data_eaten + 1); 1103 ack.firstPacket = htonl(call->rx_data_eaten + 1);
1111 1104
1112 ack.nAcks = 0; 1105 ack.nAcks = 0;
@@ -1225,9 +1218,10 @@ send_ACK:
1225 ackinfo.rxMTU = htonl(rxrpc_rx_mtu); 1218 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
1226 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max); 1219 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
1227 1220
1228 hdr.serial = htonl(atomic_inc_return(&call->conn->serial)); 1221 serial = atomic_inc_return(&call->conn->serial);
1222 whdr.serial = htonl(serial);
1229 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }", 1223 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
1230 ntohl(hdr.serial), 1224 serial,
1231 ntohs(ack.maxSkew), 1225 ntohs(ack.maxSkew),
1232 ntohl(ack.firstPacket), 1226 ntohl(ack.firstPacket),
1233 ntohl(ack.previousPacket), 1227 ntohl(ack.previousPacket),
@@ -1243,8 +1237,9 @@ send_ACK:
1243send_message: 1237send_message:
1244 _debug("send message"); 1238 _debug("send message");
1245 1239
1246 hdr.serial = htonl(atomic_inc_return(&call->conn->serial)); 1240 serial = atomic_inc_return(&call->conn->serial);
1247 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial)); 1241 whdr.serial = htonl(serial);
1242 _proto("Tx %s %%%u", rxrpc_pkts[whdr.type], serial);
1248send_message_2: 1243send_message_2:
1249 1244
1250 len = iov[0].iov_len; 1245 len = iov[0].iov_len;
@@ -1327,8 +1322,7 @@ maybe_reschedule:
1327 if (call->state >= RXRPC_CALL_COMPLETE && 1322 if (call->state >= RXRPC_CALL_COMPLETE &&
1328 !list_empty(&call->accept_link)) { 1323 !list_empty(&call->accept_link)) {
1329 _debug("X unlinking once-pending call %p { e=%lx f=%lx c=%x }", 1324 _debug("X unlinking once-pending call %p { e=%lx f=%lx c=%x }",
1330 call, call->events, call->flags, 1325 call, call->events, call->flags, call->conn->cid);
1331 ntohl(call->conn->cid));
1332 1326
1333 read_lock_bh(&call->state_lock); 1327 read_lock_bh(&call->state_lock);
1334 if (!test_bit(RXRPC_CALL_RELEASED, &call->flags) && 1328 if (!test_bit(RXRPC_CALL_RELEASED, &call->flags) &&
@@ -1346,7 +1340,7 @@ error:
1346 * this means there's a race between clearing the flag and setting the 1340 * this means there's a race between clearing the flag and setting the
1347 * work pending bit and the work item being processed again */ 1341 * work pending bit and the work item being processed again */
1348 if (call->events && !work_pending(&call->processor)) { 1342 if (call->events && !work_pending(&call->processor)) {
1349 _debug("jumpstart %x", ntohl(call->conn->cid)); 1343 _debug("jumpstart %x", call->conn->cid);
1350 rxrpc_queue_call(call); 1344 rxrpc_queue_call(call);
1351 } 1345 }
1352 1346
diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
index 3468a0705ab7..4a499e0100f1 100644
--- a/net/rxrpc/ar-call.c
+++ b/net/rxrpc/ar-call.c
@@ -64,11 +64,11 @@ static DEFINE_HASHTABLE(rxrpc_call_hash, 10);
64 * Hash function for rxrpc_call_hash 64 * Hash function for rxrpc_call_hash
65 */ 65 */
66static unsigned long rxrpc_call_hashfunc( 66static unsigned long rxrpc_call_hashfunc(
67 u8 clientflag, 67 u8 in_clientflag,
68 __be32 cid, 68 u32 cid,
69 __be32 call_id, 69 u32 call_id,
70 __be32 epoch, 70 u32 epoch,
71 __be16 service_id, 71 u16 service_id,
72 sa_family_t proto, 72 sa_family_t proto,
73 void *localptr, 73 void *localptr,
74 unsigned int addr_size, 74 unsigned int addr_size,
@@ -77,7 +77,6 @@ static unsigned long rxrpc_call_hashfunc(
77 const u16 *p; 77 const u16 *p;
78 unsigned int i; 78 unsigned int i;
79 unsigned long key; 79 unsigned long key;
80 u32 hcid = ntohl(cid);
81 80
82 _enter(""); 81 _enter("");
83 82
@@ -85,12 +84,12 @@ static unsigned long rxrpc_call_hashfunc(
85 /* We just want to add up the __be32 values, so forcing the 84 /* We just want to add up the __be32 values, so forcing the
86 * cast should be okay. 85 * cast should be okay.
87 */ 86 */
88 key += (__force u32)epoch; 87 key += epoch;
89 key += (__force u16)service_id; 88 key += service_id;
90 key += (__force u32)call_id; 89 key += call_id;
91 key += (hcid & RXRPC_CIDMASK) >> RXRPC_CIDSHIFT; 90 key += (cid & RXRPC_CIDMASK) >> RXRPC_CIDSHIFT;
92 key += hcid & RXRPC_CHANNELMASK; 91 key += cid & RXRPC_CHANNELMASK;
93 key += clientflag; 92 key += in_clientflag;
94 key += proto; 93 key += proto;
95 /* Step through the peer address in 16-bit portions for speed */ 94 /* Step through the peer address in 16-bit portions for speed */
96 for (i = 0, p = (const u16 *)peer_addr; i < addr_size >> 1; i++, p++) 95 for (i = 0, p = (const u16 *)peer_addr; i < addr_size >> 1; i++, p++)
@@ -148,19 +147,16 @@ static void rxrpc_call_hash_del(struct rxrpc_call *call)
148 * isn't there. 147 * isn't there.
149 */ 148 */
150struct rxrpc_call *rxrpc_find_call_hash( 149struct rxrpc_call *rxrpc_find_call_hash(
151 u8 clientflag, 150 struct rxrpc_host_header *hdr,
152 __be32 cid,
153 __be32 call_id,
154 __be32 epoch,
155 __be16 service_id,
156 void *localptr, 151 void *localptr,
157 sa_family_t proto, 152 sa_family_t proto,
158 const u8 *peer_addr) 153 const void *peer_addr)
159{ 154{
160 unsigned long key; 155 unsigned long key;
161 unsigned int addr_size = 0; 156 unsigned int addr_size = 0;
162 struct rxrpc_call *call = NULL; 157 struct rxrpc_call *call = NULL;
163 struct rxrpc_call *ret = NULL; 158 struct rxrpc_call *ret = NULL;
159 u8 in_clientflag = hdr->flags & RXRPC_CLIENT_INITIATED;
164 160
165 _enter(""); 161 _enter("");
166 switch (proto) { 162 switch (proto) {
@@ -174,20 +170,21 @@ struct rxrpc_call *rxrpc_find_call_hash(
174 break; 170 break;
175 } 171 }
176 172
177 key = rxrpc_call_hashfunc(clientflag, cid, call_id, epoch, 173 key = rxrpc_call_hashfunc(in_clientflag, hdr->cid, hdr->callNumber,
178 service_id, proto, localptr, addr_size, 174 hdr->epoch, hdr->serviceId,
175 proto, localptr, addr_size,
179 peer_addr); 176 peer_addr);
180 hash_for_each_possible_rcu(rxrpc_call_hash, call, hash_node, key) { 177 hash_for_each_possible_rcu(rxrpc_call_hash, call, hash_node, key) {
181 if (call->hash_key == key && 178 if (call->hash_key == key &&
182 call->call_id == call_id && 179 call->call_id == hdr->callNumber &&
183 call->cid == cid && 180 call->cid == hdr->cid &&
184 call->in_clientflag == clientflag && 181 call->in_clientflag == in_clientflag &&
185 call->service_id == service_id && 182 call->service_id == hdr->serviceId &&
186 call->proto == proto && 183 call->proto == proto &&
187 call->local == localptr && 184 call->local == localptr &&
188 memcmp(call->peer_ip.ipv6_addr, peer_addr, 185 memcmp(call->peer_ip.ipv6_addr, peer_addr,
189 addr_size) == 0 && 186 addr_size) == 0 &&
190 call->epoch == epoch) { 187 call->epoch == hdr->epoch) {
191 ret = call; 188 ret = call;
192 break; 189 break;
193 } 190 }
@@ -414,12 +411,12 @@ found_extant_second:
414 */ 411 */
415struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *rx, 412struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *rx,
416 struct rxrpc_connection *conn, 413 struct rxrpc_connection *conn,
417 struct rxrpc_header *hdr, 414 struct rxrpc_host_header *hdr,
418 gfp_t gfp) 415 gfp_t gfp)
419{ 416{
420 struct rxrpc_call *call, *candidate; 417 struct rxrpc_call *call, *candidate;
421 struct rb_node **p, *parent; 418 struct rb_node **p, *parent;
422 __be32 call_id; 419 u32 call_id;
423 420
424 _enter(",%d,,%x", conn->debug_id, gfp); 421 _enter(",%d,,%x", conn->debug_id, gfp);
425 422
@@ -433,7 +430,7 @@ struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *rx,
433 candidate->conn = conn; 430 candidate->conn = conn;
434 candidate->cid = hdr->cid; 431 candidate->cid = hdr->cid;
435 candidate->call_id = hdr->callNumber; 432 candidate->call_id = hdr->callNumber;
436 candidate->channel = ntohl(hdr->cid) & RXRPC_CHANNELMASK; 433 candidate->channel = hdr->cid & RXRPC_CHANNELMASK;
437 candidate->rx_data_post = 0; 434 candidate->rx_data_post = 0;
438 candidate->state = RXRPC_CALL_SERVER_ACCEPTING; 435 candidate->state = RXRPC_CALL_SERVER_ACCEPTING;
439 if (conn->security_ix > 0) 436 if (conn->security_ix > 0)
@@ -492,9 +489,9 @@ struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *rx,
492 /* The tree is sorted in order of the __be32 value without 489 /* The tree is sorted in order of the __be32 value without
493 * turning it into host order. 490 * turning it into host order.
494 */ 491 */
495 if ((__force u32)call_id < (__force u32)call->call_id) 492 if (call_id < call->call_id)
496 p = &(*p)->rb_left; 493 p = &(*p)->rb_left;
497 else if ((__force u32)call_id > (__force u32)call->call_id) 494 else if (call_id > call->call_id)
498 p = &(*p)->rb_right; 495 p = &(*p)->rb_right;
499 else 496 else
500 goto old_call; 497 goto old_call;
@@ -714,8 +711,7 @@ void rxrpc_release_call(struct rxrpc_call *call)
714 711
715 _debug("- zap %s %%%u #%u", 712 _debug("- zap %s %%%u #%u",
716 rxrpc_pkts[sp->hdr.type], 713 rxrpc_pkts[sp->hdr.type],
717 ntohl(sp->hdr.serial), 714 sp->hdr.serial, sp->hdr.seq);
718 ntohl(sp->hdr.seq));
719 rxrpc_free_skb(skb); 715 rxrpc_free_skb(skb);
720 spin_lock_bh(&call->lock); 716 spin_lock_bh(&call->lock);
721 } 717 }
@@ -873,9 +869,9 @@ static void rxrpc_cleanup_call(struct rxrpc_call *call)
873 unsigned long _skb; 869 unsigned long _skb;
874 870
875 _skb = call->acks_window[call->acks_tail] & ~1; 871 _skb = call->acks_window[call->acks_tail] & ~1;
876 sp = rxrpc_skb((struct sk_buff *) _skb); 872 sp = rxrpc_skb((struct sk_buff *)_skb);
877 _debug("+++ clear Tx %u", ntohl(sp->hdr.seq)); 873 _debug("+++ clear Tx %u", sp->hdr.seq);
878 rxrpc_free_skb((struct sk_buff *) _skb); 874 rxrpc_free_skb((struct sk_buff *)_skb);
879 call->acks_tail = 875 call->acks_tail =
880 (call->acks_tail + 1) & (call->acks_winsz - 1); 876 (call->acks_tail + 1) & (call->acks_winsz - 1);
881 } 877 }
diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
index 6c71ed1caf16..53df14cb8d25 100644
--- a/net/rxrpc/ar-connection.c
+++ b/net/rxrpc/ar-connection.c
@@ -57,10 +57,10 @@ static struct rxrpc_conn_bundle *rxrpc_alloc_bundle(gfp_t gfp)
57 */ 57 */
58static inline 58static inline
59int rxrpc_cmp_bundle(const struct rxrpc_conn_bundle *bundle, 59int rxrpc_cmp_bundle(const struct rxrpc_conn_bundle *bundle,
60 struct key *key, __be16 service_id) 60 struct key *key, u16 service_id)
61{ 61{
62 return (bundle->service_id - service_id) ?: 62 return (bundle->service_id - service_id) ?:
63 ((unsigned long) bundle->key - (unsigned long) key); 63 ((unsigned long)bundle->key - (unsigned long)key);
64} 64}
65 65
66/* 66/*
@@ -69,14 +69,14 @@ int rxrpc_cmp_bundle(const struct rxrpc_conn_bundle *bundle,
69struct rxrpc_conn_bundle *rxrpc_get_bundle(struct rxrpc_sock *rx, 69struct rxrpc_conn_bundle *rxrpc_get_bundle(struct rxrpc_sock *rx,
70 struct rxrpc_transport *trans, 70 struct rxrpc_transport *trans,
71 struct key *key, 71 struct key *key,
72 __be16 service_id, 72 u16 service_id,
73 gfp_t gfp) 73 gfp_t gfp)
74{ 74{
75 struct rxrpc_conn_bundle *bundle, *candidate; 75 struct rxrpc_conn_bundle *bundle, *candidate;
76 struct rb_node *p, *parent, **pp; 76 struct rb_node *p, *parent, **pp;
77 77
78 _enter("%p{%x},%x,%hx,", 78 _enter("%p{%x},%x,%hx,",
79 rx, key_serial(key), trans->debug_id, ntohs(service_id)); 79 rx, key_serial(key), trans->debug_id, service_id);
80 80
81 if (rx->trans == trans && rx->bundle) { 81 if (rx->trans == trans && rx->bundle) {
82 atomic_inc(&rx->bundle->usage); 82 atomic_inc(&rx->bundle->usage);
@@ -213,7 +213,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
213 conn->debug_id = atomic_inc_return(&rxrpc_debug_id); 213 conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
214 conn->avail_calls = RXRPC_MAXCALLS; 214 conn->avail_calls = RXRPC_MAXCALLS;
215 conn->size_align = 4; 215 conn->size_align = 4;
216 conn->header_size = sizeof(struct rxrpc_header); 216 conn->header_size = sizeof(struct rxrpc_wire_header);
217 } 217 }
218 218
219 _leave(" = %p{%d}", conn, conn ? conn->debug_id : 0); 219 _leave(" = %p{%d}", conn, conn ? conn->debug_id : 0);
@@ -230,7 +230,7 @@ static void rxrpc_assign_connection_id(struct rxrpc_connection *conn)
230 struct rxrpc_connection *xconn; 230 struct rxrpc_connection *xconn;
231 struct rb_node *parent, **p; 231 struct rb_node *parent, **p;
232 __be32 epoch; 232 __be32 epoch;
233 u32 real_conn_id; 233 u32 cid;
234 234
235 _enter(""); 235 _enter("");
236 236
@@ -241,7 +241,7 @@ static void rxrpc_assign_connection_id(struct rxrpc_connection *conn)
241 conn->trans->conn_idcounter += RXRPC_CID_INC; 241 conn->trans->conn_idcounter += RXRPC_CID_INC;
242 if (conn->trans->conn_idcounter < RXRPC_CID_INC) 242 if (conn->trans->conn_idcounter < RXRPC_CID_INC)
243 conn->trans->conn_idcounter = RXRPC_CID_INC; 243 conn->trans->conn_idcounter = RXRPC_CID_INC;
244 real_conn_id = conn->trans->conn_idcounter; 244 cid = conn->trans->conn_idcounter;
245 245
246attempt_insertion: 246attempt_insertion:
247 parent = NULL; 247 parent = NULL;
@@ -255,9 +255,9 @@ attempt_insertion:
255 p = &(*p)->rb_left; 255 p = &(*p)->rb_left;
256 else if (epoch > xconn->epoch) 256 else if (epoch > xconn->epoch)
257 p = &(*p)->rb_right; 257 p = &(*p)->rb_right;
258 else if (real_conn_id < xconn->real_conn_id) 258 else if (cid < xconn->cid)
259 p = &(*p)->rb_left; 259 p = &(*p)->rb_left;
260 else if (real_conn_id > xconn->real_conn_id) 260 else if (cid > xconn->cid)
261 p = &(*p)->rb_right; 261 p = &(*p)->rb_right;
262 else 262 else
263 goto id_exists; 263 goto id_exists;
@@ -268,20 +268,19 @@ attempt_insertion:
268 rb_link_node(&conn->node, parent, p); 268 rb_link_node(&conn->node, parent, p);
269 rb_insert_color(&conn->node, &conn->trans->client_conns); 269 rb_insert_color(&conn->node, &conn->trans->client_conns);
270 270
271 conn->real_conn_id = real_conn_id; 271 conn->cid = cid;
272 conn->cid = htonl(real_conn_id);
273 write_unlock_bh(&conn->trans->conn_lock); 272 write_unlock_bh(&conn->trans->conn_lock);
274 _leave(" [CONNID %x CID %x]", real_conn_id, ntohl(conn->cid)); 273 _leave(" [CID %x]", cid);
275 return; 274 return;
276 275
277 /* we found a connection with the proposed ID - walk the tree from that 276 /* we found a connection with the proposed ID - walk the tree from that
278 * point looking for the next unused ID */ 277 * point looking for the next unused ID */
279id_exists: 278id_exists:
280 for (;;) { 279 for (;;) {
281 real_conn_id += RXRPC_CID_INC; 280 cid += RXRPC_CID_INC;
282 if (real_conn_id < RXRPC_CID_INC) { 281 if (cid < RXRPC_CID_INC) {
283 real_conn_id = RXRPC_CID_INC; 282 cid = RXRPC_CID_INC;
284 conn->trans->conn_idcounter = real_conn_id; 283 conn->trans->conn_idcounter = cid;
285 goto attempt_insertion; 284 goto attempt_insertion;
286 } 285 }
287 286
@@ -291,7 +290,7 @@ id_exists:
291 290
292 xconn = rb_entry(parent, struct rxrpc_connection, node); 291 xconn = rb_entry(parent, struct rxrpc_connection, node);
293 if (epoch < xconn->epoch || 292 if (epoch < xconn->epoch ||
294 real_conn_id < xconn->real_conn_id) 293 cid < xconn->cid)
295 goto attempt_insertion; 294 goto attempt_insertion;
296 } 295 }
297} 296}
@@ -334,7 +333,7 @@ static void rxrpc_add_call_ID_to_conn(struct rxrpc_connection *conn,
334 */ 333 */
335static int rxrpc_connect_exclusive(struct rxrpc_sock *rx, 334static int rxrpc_connect_exclusive(struct rxrpc_sock *rx,
336 struct rxrpc_transport *trans, 335 struct rxrpc_transport *trans,
337 __be16 service_id, 336 u16 service_id,
338 struct rxrpc_call *call, 337 struct rxrpc_call *call,
339 gfp_t gfp) 338 gfp_t gfp)
340{ 339{
@@ -404,11 +403,11 @@ found_channel:
404 conn->channels[chan] = call; 403 conn->channels[chan] = call;
405 call->conn = conn; 404 call->conn = conn;
406 call->channel = chan; 405 call->channel = chan;
407 call->cid = conn->cid | htonl(chan); 406 call->cid = conn->cid | chan;
408 call->call_id = htonl(++conn->call_counter); 407 call->call_id = ++conn->call_counter;
409 408
410 _net("CONNECT client on conn %d chan %d as call %x", 409 _net("CONNECT client on conn %d chan %d as call %x",
411 conn->debug_id, chan, ntohl(call->call_id)); 410 conn->debug_id, chan, call->call_id);
412 411
413 spin_unlock(&trans->client_lock); 412 spin_unlock(&trans->client_lock);
414 413
@@ -593,11 +592,11 @@ found_channel:
593 conn->channels[chan] = call; 592 conn->channels[chan] = call;
594 call->conn = conn; 593 call->conn = conn;
595 call->channel = chan; 594 call->channel = chan;
596 call->cid = conn->cid | htonl(chan); 595 call->cid = conn->cid | chan;
597 call->call_id = htonl(++conn->call_counter); 596 call->call_id = ++conn->call_counter;
598 597
599 _net("CONNECT client on conn %d chan %d as call %x", 598 _net("CONNECT client on conn %d chan %d as call %x",
600 conn->debug_id, chan, ntohl(call->call_id)); 599 conn->debug_id, chan, call->call_id);
601 600
602 ASSERTCMP(conn->avail_calls, <, RXRPC_MAXCALLS); 601 ASSERTCMP(conn->avail_calls, <, RXRPC_MAXCALLS);
603 spin_unlock(&trans->client_lock); 602 spin_unlock(&trans->client_lock);
@@ -620,21 +619,21 @@ interrupted:
620 */ 619 */
621struct rxrpc_connection * 620struct rxrpc_connection *
622rxrpc_incoming_connection(struct rxrpc_transport *trans, 621rxrpc_incoming_connection(struct rxrpc_transport *trans,
623 struct rxrpc_header *hdr, 622 struct rxrpc_host_header *hdr,
624 gfp_t gfp) 623 gfp_t gfp)
625{ 624{
626 struct rxrpc_connection *conn, *candidate = NULL; 625 struct rxrpc_connection *conn, *candidate = NULL;
627 struct rb_node *p, **pp; 626 struct rb_node *p, **pp;
628 const char *new = "old"; 627 const char *new = "old";
629 __be32 epoch; 628 __be32 epoch;
630 u32 conn_id; 629 u32 cid;
631 630
632 _enter(""); 631 _enter("");
633 632
634 ASSERT(hdr->flags & RXRPC_CLIENT_INITIATED); 633 ASSERT(hdr->flags & RXRPC_CLIENT_INITIATED);
635 634
636 epoch = hdr->epoch; 635 epoch = hdr->epoch;
637 conn_id = ntohl(hdr->cid) & RXRPC_CIDMASK; 636 cid = hdr->cid & RXRPC_CIDMASK;
638 637
639 /* search the connection list first */ 638 /* search the connection list first */
640 read_lock_bh(&trans->conn_lock); 639 read_lock_bh(&trans->conn_lock);
@@ -643,15 +642,15 @@ rxrpc_incoming_connection(struct rxrpc_transport *trans,
643 while (p) { 642 while (p) {
644 conn = rb_entry(p, struct rxrpc_connection, node); 643 conn = rb_entry(p, struct rxrpc_connection, node);
645 644
646 _debug("maybe %x", conn->real_conn_id); 645 _debug("maybe %x", conn->cid);
647 646
648 if (epoch < conn->epoch) 647 if (epoch < conn->epoch)
649 p = p->rb_left; 648 p = p->rb_left;
650 else if (epoch > conn->epoch) 649 else if (epoch > conn->epoch)
651 p = p->rb_right; 650 p = p->rb_right;
652 else if (conn_id < conn->real_conn_id) 651 else if (cid < conn->cid)
653 p = p->rb_left; 652 p = p->rb_left;
654 else if (conn_id > conn->real_conn_id) 653 else if (cid > conn->cid)
655 p = p->rb_right; 654 p = p->rb_right;
656 else 655 else
657 goto found_extant_connection; 656 goto found_extant_connection;
@@ -668,12 +667,11 @@ rxrpc_incoming_connection(struct rxrpc_transport *trans,
668 667
669 candidate->trans = trans; 668 candidate->trans = trans;
670 candidate->epoch = hdr->epoch; 669 candidate->epoch = hdr->epoch;
671 candidate->cid = hdr->cid & cpu_to_be32(RXRPC_CIDMASK); 670 candidate->cid = hdr->cid & RXRPC_CIDMASK;
672 candidate->service_id = hdr->serviceId; 671 candidate->service_id = hdr->serviceId;
673 candidate->security_ix = hdr->securityIndex; 672 candidate->security_ix = hdr->securityIndex;
674 candidate->in_clientflag = RXRPC_CLIENT_INITIATED; 673 candidate->in_clientflag = RXRPC_CLIENT_INITIATED;
675 candidate->out_clientflag = 0; 674 candidate->out_clientflag = 0;
676 candidate->real_conn_id = conn_id;
677 candidate->state = RXRPC_CONN_SERVER; 675 candidate->state = RXRPC_CONN_SERVER;
678 if (candidate->service_id) 676 if (candidate->service_id)
679 candidate->state = RXRPC_CONN_SERVER_UNSECURED; 677 candidate->state = RXRPC_CONN_SERVER_UNSECURED;
@@ -690,9 +688,9 @@ rxrpc_incoming_connection(struct rxrpc_transport *trans,
690 pp = &(*pp)->rb_left; 688 pp = &(*pp)->rb_left;
691 else if (epoch > conn->epoch) 689 else if (epoch > conn->epoch)
692 pp = &(*pp)->rb_right; 690 pp = &(*pp)->rb_right;
693 else if (conn_id < conn->real_conn_id) 691 else if (cid < conn->cid)
694 pp = &(*pp)->rb_left; 692 pp = &(*pp)->rb_left;
695 else if (conn_id > conn->real_conn_id) 693 else if (cid > conn->cid)
696 pp = &(*pp)->rb_right; 694 pp = &(*pp)->rb_right;
697 else 695 else
698 goto found_extant_second; 696 goto found_extant_second;
@@ -714,7 +712,7 @@ rxrpc_incoming_connection(struct rxrpc_transport *trans,
714 new = "new"; 712 new = "new";
715 713
716success: 714success:
717 _net("CONNECTION %s %d {%x}", new, conn->debug_id, conn->real_conn_id); 715 _net("CONNECTION %s %d {%x}", new, conn->debug_id, conn->cid);
718 716
719 _leave(" = %p {u=%d}", conn, atomic_read(&conn->usage)); 717 _leave(" = %p {u=%d}", conn, atomic_read(&conn->usage));
720 return conn; 718 return conn;
@@ -751,18 +749,17 @@ security_mismatch:
751 * packet 749 * packet
752 */ 750 */
753struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_transport *trans, 751struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_transport *trans,
754 struct rxrpc_header *hdr) 752 struct rxrpc_host_header *hdr)
755{ 753{
756 struct rxrpc_connection *conn; 754 struct rxrpc_connection *conn;
757 struct rb_node *p; 755 struct rb_node *p;
758 __be32 epoch; 756 u32 epoch, cid;
759 u32 conn_id;
760 757
761 _enter(",{%x,%x}", ntohl(hdr->cid), hdr->flags); 758 _enter(",{%x,%x}", hdr->cid, hdr->flags);
762 759
763 read_lock_bh(&trans->conn_lock); 760 read_lock_bh(&trans->conn_lock);
764 761
765 conn_id = ntohl(hdr->cid) & RXRPC_CIDMASK; 762 cid = hdr->cid & RXRPC_CIDMASK;
766 epoch = hdr->epoch; 763 epoch = hdr->epoch;
767 764
768 if (hdr->flags & RXRPC_CLIENT_INITIATED) 765 if (hdr->flags & RXRPC_CLIENT_INITIATED)
@@ -773,15 +770,15 @@ struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_transport *trans,
773 while (p) { 770 while (p) {
774 conn = rb_entry(p, struct rxrpc_connection, node); 771 conn = rb_entry(p, struct rxrpc_connection, node);
775 772
776 _debug("maybe %x", conn->real_conn_id); 773 _debug("maybe %x", conn->cid);
777 774
778 if (epoch < conn->epoch) 775 if (epoch < conn->epoch)
779 p = p->rb_left; 776 p = p->rb_left;
780 else if (epoch > conn->epoch) 777 else if (epoch > conn->epoch)
781 p = p->rb_right; 778 p = p->rb_right;
782 else if (conn_id < conn->real_conn_id) 779 else if (cid < conn->cid)
783 p = p->rb_left; 780 p = p->rb_left;
784 else if (conn_id > conn->real_conn_id) 781 else if (cid > conn->cid)
785 p = p->rb_right; 782 p = p->rb_right;
786 else 783 else
787 goto found; 784 goto found;
diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
index 45e81b7e96ae..1bdaaed8cdc4 100644
--- a/net/rxrpc/ar-connevent.c
+++ b/net/rxrpc/ar-connevent.c
@@ -60,11 +60,12 @@ static void rxrpc_abort_calls(struct rxrpc_connection *conn, int state,
60static int rxrpc_abort_connection(struct rxrpc_connection *conn, 60static int rxrpc_abort_connection(struct rxrpc_connection *conn,
61 u32 error, u32 abort_code) 61 u32 error, u32 abort_code)
62{ 62{
63 struct rxrpc_header hdr; 63 struct rxrpc_wire_header whdr;
64 struct msghdr msg; 64 struct msghdr msg;
65 struct kvec iov[2]; 65 struct kvec iov[2];
66 __be32 word; 66 __be32 word;
67 size_t len; 67 size_t len;
68 u32 serial;
68 int ret; 69 int ret;
69 70
70 _enter("%d,,%u,%u", conn->debug_id, error, abort_code); 71 _enter("%d,,%u,%u", conn->debug_id, error, abort_code);
@@ -89,28 +90,29 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
89 msg.msg_controllen = 0; 90 msg.msg_controllen = 0;
90 msg.msg_flags = 0; 91 msg.msg_flags = 0;
91 92
92 hdr.epoch = conn->epoch; 93 whdr.epoch = htonl(conn->epoch);
93 hdr.cid = conn->cid; 94 whdr.cid = htonl(conn->cid);
94 hdr.callNumber = 0; 95 whdr.callNumber = 0;
95 hdr.seq = 0; 96 whdr.seq = 0;
96 hdr.type = RXRPC_PACKET_TYPE_ABORT; 97 whdr.type = RXRPC_PACKET_TYPE_ABORT;
97 hdr.flags = conn->out_clientflag; 98 whdr.flags = conn->out_clientflag;
98 hdr.userStatus = 0; 99 whdr.userStatus = 0;
99 hdr.securityIndex = conn->security_ix; 100 whdr.securityIndex = conn->security_ix;
100 hdr._rsvd = 0; 101 whdr._rsvd = 0;
101 hdr.serviceId = conn->service_id; 102 whdr.serviceId = htons(conn->service_id);
102 103
103 word = htonl(abort_code); 104 word = htonl(abort_code);
104 105
105 iov[0].iov_base = &hdr; 106 iov[0].iov_base = &whdr;
106 iov[0].iov_len = sizeof(hdr); 107 iov[0].iov_len = sizeof(whdr);
107 iov[1].iov_base = &word; 108 iov[1].iov_base = &word;
108 iov[1].iov_len = sizeof(word); 109 iov[1].iov_len = sizeof(word);
109 110
110 len = iov[0].iov_len + iov[1].iov_len; 111 len = iov[0].iov_len + iov[1].iov_len;
111 112
112 hdr.serial = htonl(atomic_inc_return(&conn->serial)); 113 serial = atomic_inc_return(&conn->serial);
113 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code); 114 whdr.serial = htonl(serial);
115 _proto("Tx CONN ABORT %%%u { %d }", serial, abort_code);
114 116
115 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len); 117 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
116 if (ret < 0) { 118 if (ret < 0) {
@@ -146,8 +148,8 @@ static int rxrpc_process_event(struct rxrpc_connection *conn,
146 u32 *_abort_code) 148 u32 *_abort_code)
147{ 149{
148 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 150 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
149 __be32 tmp; 151 __be32 wtmp;
150 u32 serial; 152 u32 abort_code;
151 int loop, ret; 153 int loop, ret;
152 154
153 if (conn->state >= RXRPC_CONN_REMOTELY_ABORTED) { 155 if (conn->state >= RXRPC_CONN_REMOTELY_ABORTED) {
@@ -155,19 +157,18 @@ static int rxrpc_process_event(struct rxrpc_connection *conn,
155 return -ECONNABORTED; 157 return -ECONNABORTED;
156 } 158 }
157 159
158 serial = ntohl(sp->hdr.serial); 160 _enter("{%d},{%u,%%%u},", conn->debug_id, sp->hdr.type, sp->hdr.serial);
159
160 _enter("{%d},{%u,%%%u},", conn->debug_id, sp->hdr.type, serial);
161 161
162 switch (sp->hdr.type) { 162 switch (sp->hdr.type) {
163 case RXRPC_PACKET_TYPE_ABORT: 163 case RXRPC_PACKET_TYPE_ABORT:
164 if (skb_copy_bits(skb, 0, &tmp, sizeof(tmp)) < 0) 164 if (skb_copy_bits(skb, 0, &wtmp, sizeof(wtmp)) < 0)
165 return -EPROTO; 165 return -EPROTO;
166 _proto("Rx ABORT %%%u { ac=%d }", serial, ntohl(tmp)); 166 abort_code = ntohl(wtmp);
167 _proto("Rx ABORT %%%u { ac=%d }", sp->hdr.serial, abort_code);
167 168
168 conn->state = RXRPC_CONN_REMOTELY_ABORTED; 169 conn->state = RXRPC_CONN_REMOTELY_ABORTED;
169 rxrpc_abort_calls(conn, RXRPC_CALL_REMOTELY_ABORTED, 170 rxrpc_abort_calls(conn, RXRPC_CALL_REMOTELY_ABORTED,
170 ntohl(tmp)); 171 abort_code);
171 return -ECONNABORTED; 172 return -ECONNABORTED;
172 173
173 case RXRPC_PACKET_TYPE_CHALLENGE: 174 case RXRPC_PACKET_TYPE_CHALLENGE:
@@ -335,7 +336,7 @@ void rxrpc_reject_packets(struct work_struct *work)
335 struct sockaddr_in sin; 336 struct sockaddr_in sin;
336 } sa; 337 } sa;
337 struct rxrpc_skb_priv *sp; 338 struct rxrpc_skb_priv *sp;
338 struct rxrpc_header hdr; 339 struct rxrpc_wire_header whdr;
339 struct rxrpc_local *local; 340 struct rxrpc_local *local;
340 struct sk_buff *skb; 341 struct sk_buff *skb;
341 struct msghdr msg; 342 struct msghdr msg;
@@ -348,11 +349,11 @@ void rxrpc_reject_packets(struct work_struct *work)
348 349
349 _enter("%d", local->debug_id); 350 _enter("%d", local->debug_id);
350 351
351 iov[0].iov_base = &hdr; 352 iov[0].iov_base = &whdr;
352 iov[0].iov_len = sizeof(hdr); 353 iov[0].iov_len = sizeof(whdr);
353 iov[1].iov_base = &code; 354 iov[1].iov_base = &code;
354 iov[1].iov_len = sizeof(code); 355 iov[1].iov_len = sizeof(code);
355 size = sizeof(hdr) + sizeof(code); 356 size = sizeof(whdr) + sizeof(code);
356 357
357 msg.msg_name = &sa; 358 msg.msg_name = &sa;
358 msg.msg_control = NULL; 359 msg.msg_control = NULL;
@@ -370,8 +371,8 @@ void rxrpc_reject_packets(struct work_struct *work)
370 break; 371 break;
371 } 372 }
372 373
373 memset(&hdr, 0, sizeof(hdr)); 374 memset(&whdr, 0, sizeof(whdr));
374 hdr.type = RXRPC_PACKET_TYPE_ABORT; 375 whdr.type = RXRPC_PACKET_TYPE_ABORT;
375 376
376 while ((skb = skb_dequeue(&local->reject_queue))) { 377 while ((skb = skb_dequeue(&local->reject_queue))) {
377 sp = rxrpc_skb(skb); 378 sp = rxrpc_skb(skb);
@@ -381,13 +382,13 @@ void rxrpc_reject_packets(struct work_struct *work)
381 sa.sin.sin_addr.s_addr = ip_hdr(skb)->saddr; 382 sa.sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
382 code = htonl(skb->priority); 383 code = htonl(skb->priority);
383 384
384 hdr.epoch = sp->hdr.epoch; 385 whdr.epoch = htonl(sp->hdr.epoch);
385 hdr.cid = sp->hdr.cid; 386 whdr.cid = htonl(sp->hdr.cid);
386 hdr.callNumber = sp->hdr.callNumber; 387 whdr.callNumber = htonl(sp->hdr.callNumber);
387 hdr.serviceId = sp->hdr.serviceId; 388 whdr.serviceId = htons(sp->hdr.serviceId);
388 hdr.flags = sp->hdr.flags; 389 whdr.flags = sp->hdr.flags;
389 hdr.flags ^= RXRPC_CLIENT_INITIATED; 390 whdr.flags ^= RXRPC_CLIENT_INITIATED;
390 hdr.flags &= RXRPC_CLIENT_INITIATED; 391 whdr.flags &= RXRPC_CLIENT_INITIATED;
391 392
392 kernel_sendmsg(local->socket, &msg, iov, 2, size); 393 kernel_sendmsg(local->socket, &msg, iov, 2, size);
393 break; 394 break;
diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
index 9185535af5f5..e6396a8c969f 100644
--- a/net/rxrpc/ar-input.c
+++ b/net/rxrpc/ar-input.c
@@ -310,8 +310,8 @@ static void rxrpc_assume_implicit_ackall(struct rxrpc_call *call, u32 serial)
310void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb) 310void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
311{ 311{
312 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 312 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
313 __be32 _abort_code; 313 __be32 wtmp;
314 u32 serial, hi_serial, seq, abort_code; 314 u32 hi_serial, abort_code;
315 315
316 _enter("%p,%p", call, skb); 316 _enter("%p,%p", call, skb);
317 317
@@ -330,16 +330,15 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
330 330
331 /* track the latest serial number on this connection for ACK packet 331 /* track the latest serial number on this connection for ACK packet
332 * information */ 332 * information */
333 serial = ntohl(sp->hdr.serial);
334 hi_serial = atomic_read(&call->conn->hi_serial); 333 hi_serial = atomic_read(&call->conn->hi_serial);
335 while (serial > hi_serial) 334 while (sp->hdr.serial > hi_serial)
336 hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial, 335 hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
337 serial); 336 sp->hdr.serial);
338 337
339 /* request ACK generation for any ACK or DATA packet that requests 338 /* request ACK generation for any ACK or DATA packet that requests
340 * it */ 339 * it */
341 if (sp->hdr.flags & RXRPC_REQUEST_ACK) { 340 if (sp->hdr.flags & RXRPC_REQUEST_ACK) {
342 _proto("ACK Requested on %%%u", serial); 341 _proto("ACK Requested on %%%u", sp->hdr.serial);
343 rxrpc_propose_ACK(call, RXRPC_ACK_REQUESTED, sp->hdr.serial, false); 342 rxrpc_propose_ACK(call, RXRPC_ACK_REQUESTED, sp->hdr.serial, false);
344 } 343 }
345 344
@@ -347,12 +346,11 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
347 case RXRPC_PACKET_TYPE_ABORT: 346 case RXRPC_PACKET_TYPE_ABORT:
348 _debug("abort"); 347 _debug("abort");
349 348
350 if (skb_copy_bits(skb, 0, &_abort_code, 349 if (skb_copy_bits(skb, 0, &wtmp, sizeof(wtmp)) < 0)
351 sizeof(_abort_code)) < 0)
352 goto protocol_error; 350 goto protocol_error;
353 351
354 abort_code = ntohl(_abort_code); 352 abort_code = ntohl(wtmp);
355 _proto("Rx ABORT %%%u { %x }", serial, abort_code); 353 _proto("Rx ABORT %%%u { %x }", sp->hdr.serial, abort_code);
356 354
357 write_lock_bh(&call->state_lock); 355 write_lock_bh(&call->state_lock);
358 if (call->state < RXRPC_CALL_COMPLETE) { 356 if (call->state < RXRPC_CALL_COMPLETE) {
@@ -364,7 +362,7 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
364 goto free_packet_unlock; 362 goto free_packet_unlock;
365 363
366 case RXRPC_PACKET_TYPE_BUSY: 364 case RXRPC_PACKET_TYPE_BUSY:
367 _proto("Rx BUSY %%%u", serial); 365 _proto("Rx BUSY %%%u", sp->hdr.serial);
368 366
369 if (call->conn->out_clientflag) 367 if (call->conn->out_clientflag)
370 goto protocol_error; 368 goto protocol_error;
@@ -382,15 +380,13 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
382 } 380 }
383 381
384 default: 382 default:
385 _proto("Rx %s %%%u", rxrpc_pkts[sp->hdr.type], serial); 383 _proto("Rx %s %%%u", rxrpc_pkts[sp->hdr.type], sp->hdr.serial);
386 goto protocol_error; 384 goto protocol_error;
387 385
388 case RXRPC_PACKET_TYPE_DATA: 386 case RXRPC_PACKET_TYPE_DATA:
389 seq = ntohl(sp->hdr.seq); 387 _proto("Rx DATA %%%u { #%u }", sp->hdr.serial, sp->hdr.seq);
390 388
391 _proto("Rx DATA %%%u { #%u }", serial, seq); 389 if (sp->hdr.seq == 0)
392
393 if (seq == 0)
394 goto protocol_error; 390 goto protocol_error;
395 391
396 call->ackr_prev_seq = sp->hdr.seq; 392 call->ackr_prev_seq = sp->hdr.seq;
@@ -398,9 +394,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
398 /* received data implicitly ACKs all of the request packets we 394 /* received data implicitly ACKs all of the request packets we
399 * sent when we're acting as a client */ 395 * sent when we're acting as a client */
400 if (call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY) 396 if (call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY)
401 rxrpc_assume_implicit_ackall(call, serial); 397 rxrpc_assume_implicit_ackall(call, sp->hdr.serial);
402 398
403 switch (rxrpc_fast_process_data(call, skb, seq)) { 399 switch (rxrpc_fast_process_data(call, skb, sp->hdr.seq)) {
404 case 0: 400 case 0:
405 skb = NULL; 401 skb = NULL;
406 goto done; 402 goto done;
@@ -481,12 +477,12 @@ static void rxrpc_process_jumbo_packet(struct rxrpc_call *call,
481 if (!pskb_pull(jumbo, sizeof(jhdr))) 477 if (!pskb_pull(jumbo, sizeof(jhdr)))
482 BUG(); 478 BUG();
483 479
484 sp->hdr.seq = htonl(ntohl(sp->hdr.seq) + 1); 480 sp->hdr.seq += 1;
485 sp->hdr.serial = htonl(ntohl(sp->hdr.serial) + 1); 481 sp->hdr.serial += 1;
486 sp->hdr.flags = jhdr.flags; 482 sp->hdr.flags = jhdr.flags;
487 sp->hdr._rsvd = jhdr._rsvd; 483 sp->hdr._rsvd = jhdr._rsvd;
488 484
489 _proto("Rx DATA Jumbo %%%u", ntohl(sp->hdr.serial) - 1); 485 _proto("Rx DATA Jumbo %%%u", sp->hdr.serial - 1);
490 486
491 rxrpc_fast_process_packet(call, part); 487 rxrpc_fast_process_packet(call, part);
492 part = NULL; 488 part = NULL;
@@ -607,6 +603,35 @@ static void rxrpc_post_packet_to_local(struct rxrpc_local *local,
607 rxrpc_queue_work(&local->event_processor); 603 rxrpc_queue_work(&local->event_processor);
608} 604}
609 605
606/*
607 * Extract the wire header from a packet and translate the byte order.
608 */
609static noinline
610int rxrpc_extract_header(struct rxrpc_skb_priv *sp, struct sk_buff *skb)
611{
612 struct rxrpc_wire_header whdr;
613
614 /* dig out the RxRPC connection details */
615 if (skb_copy_bits(skb, sizeof(struct udphdr), &whdr, sizeof(whdr)) < 0)
616 return -EBADMSG;
617 if (!pskb_pull(skb, sizeof(struct udphdr) + sizeof(whdr)))
618 BUG();
619
620 memset(sp, 0, sizeof(*sp));
621 sp->hdr.epoch = ntohl(whdr.epoch);
622 sp->hdr.cid = ntohl(whdr.cid);
623 sp->hdr.callNumber = ntohl(whdr.callNumber);
624 sp->hdr.seq = ntohl(whdr.seq);
625 sp->hdr.serial = ntohl(whdr.serial);
626 sp->hdr.flags = whdr.flags;
627 sp->hdr.type = whdr.type;
628 sp->hdr.userStatus = whdr.userStatus;
629 sp->hdr.securityIndex = whdr.securityIndex;
630 sp->hdr._rsvd = ntohs(whdr._rsvd);
631 sp->hdr.serviceId = ntohs(whdr.serviceId);
632 return 0;
633}
634
610static struct rxrpc_connection *rxrpc_conn_from_local(struct rxrpc_local *local, 635static struct rxrpc_connection *rxrpc_conn_from_local(struct rxrpc_local *local,
611 struct sk_buff *skb, 636 struct sk_buff *skb,
612 struct rxrpc_skb_priv *sp) 637 struct rxrpc_skb_priv *sp)
@@ -686,27 +711,22 @@ void rxrpc_data_ready(struct sock *sk)
686 711
687 UDP_INC_STATS_BH(&init_net, UDP_MIB_INDATAGRAMS, 0); 712 UDP_INC_STATS_BH(&init_net, UDP_MIB_INDATAGRAMS, 0);
688 713
689 /* the socket buffer we have is owned by UDP, with UDP's data all over 714 /* The socket buffer we have is owned by UDP, with UDP's data all over
690 * it, but we really want our own */ 715 * it, but we really want our own data there.
716 */
691 skb_orphan(skb); 717 skb_orphan(skb);
692 sp = rxrpc_skb(skb); 718 sp = rxrpc_skb(skb);
693 memset(sp, 0, sizeof(*sp));
694 719
695 _net("Rx UDP packet from %08x:%04hu", 720 _net("Rx UDP packet from %08x:%04hu",
696 ntohl(ip_hdr(skb)->saddr), ntohs(udp_hdr(skb)->source)); 721 ntohl(ip_hdr(skb)->saddr), ntohs(udp_hdr(skb)->source));
697 722
698 /* dig out the RxRPC connection details */ 723 /* dig out the RxRPC connection details */
699 if (skb_copy_bits(skb, sizeof(struct udphdr), &sp->hdr, 724 if (rxrpc_extract_header(sp, skb) < 0)
700 sizeof(sp->hdr)) < 0)
701 goto bad_message; 725 goto bad_message;
702 if (!pskb_pull(skb, sizeof(struct udphdr) + sizeof(sp->hdr)))
703 BUG();
704 726
705 _net("Rx RxRPC %s ep=%x call=%x:%x", 727 _net("Rx RxRPC %s ep=%x call=%x:%x",
706 sp->hdr.flags & RXRPC_CLIENT_INITIATED ? "ToServer" : "ToClient", 728 sp->hdr.flags & RXRPC_CLIENT_INITIATED ? "ToServer" : "ToClient",
707 ntohl(sp->hdr.epoch), 729 sp->hdr.epoch, sp->hdr.cid, sp->hdr.callNumber);
708 ntohl(sp->hdr.cid),
709 ntohl(sp->hdr.callNumber));
710 730
711 if (sp->hdr.type == 0 || sp->hdr.type >= RXRPC_N_PACKET_TYPES) { 731 if (sp->hdr.type == 0 || sp->hdr.type >= RXRPC_N_PACKET_TYPES) {
712 _proto("Rx Bad Packet Type %u", sp->hdr.type); 732 _proto("Rx Bad Packet Type %u", sp->hdr.type);
@@ -737,14 +757,9 @@ void rxrpc_data_ready(struct sock *sk)
737 rxrpc_put_connection(conn); 757 rxrpc_put_connection(conn);
738 } else { 758 } else {
739 struct rxrpc_call *call; 759 struct rxrpc_call *call;
740 u8 in_clientflag = 0; 760
741 761 call = rxrpc_find_call_hash(&sp->hdr, local,
742 if (sp->hdr.flags & RXRPC_CLIENT_INITIATED) 762 AF_INET, &ip_hdr(skb)->saddr);
743 in_clientflag = RXRPC_CLIENT_INITIATED;
744 call = rxrpc_find_call_hash(in_clientflag, sp->hdr.cid,
745 sp->hdr.callNumber, sp->hdr.epoch,
746 sp->hdr.serviceId, local, AF_INET,
747 (u8 *)&ip_hdr(skb)->saddr);
748 if (call) 763 if (call)
749 rxrpc_post_packet_to_call(call, skb); 764 rxrpc_post_packet_to_call(call, skb);
750 else 765 else
@@ -759,7 +774,7 @@ cant_route_call:
759 _debug("can't route call"); 774 _debug("can't route call");
760 if (sp->hdr.flags & RXRPC_CLIENT_INITIATED && 775 if (sp->hdr.flags & RXRPC_CLIENT_INITIATED &&
761 sp->hdr.type == RXRPC_PACKET_TYPE_DATA) { 776 sp->hdr.type == RXRPC_PACKET_TYPE_DATA) {
762 if (sp->hdr.seq == cpu_to_be32(1)) { 777 if (sp->hdr.seq == 1) {
763 _debug("first packet"); 778 _debug("first packet");
764 skb_queue_tail(&local->accept_queue, skb); 779 skb_queue_tail(&local->accept_queue, skb);
765 rxrpc_queue_work(&local->acceptor); 780 rxrpc_queue_work(&local->acceptor);
diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
index 3f2940626569..06bf5abd920d 100644
--- a/net/rxrpc/ar-internal.h
+++ b/net/rxrpc/ar-internal.h
@@ -70,12 +70,31 @@ struct rxrpc_sock {
70#define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT 70#define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT
71 struct sockaddr_rxrpc srx; /* local address */ 71 struct sockaddr_rxrpc srx; /* local address */
72 sa_family_t proto; /* protocol created with */ 72 sa_family_t proto; /* protocol created with */
73 __be16 service_id; /* service ID of local/remote service */
74}; 73};
75 74
76#define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk) 75#define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
77 76
78/* 77/*
78 * CPU-byteorder normalised Rx packet header.
79 */
80struct rxrpc_host_header {
81 u32 epoch; /* client boot timestamp */
82 u32 cid; /* connection and channel ID */
83 u32 callNumber; /* call ID (0 for connection-level packets) */
84 u32 seq; /* sequence number of pkt in call stream */
85 u32 serial; /* serial number of pkt sent to network */
86 u8 type; /* packet type */
87 u8 flags; /* packet flags */
88 u8 userStatus; /* app-layer defined status */
89 u8 securityIndex; /* security protocol ID */
90 union {
91 u16 _rsvd; /* reserved */
92 u16 cksum; /* kerberos security checksum */
93 };
94 u16 serviceId; /* service ID */
95} __packed;
96
97/*
79 * RxRPC socket buffer private variables 98 * RxRPC socket buffer private variables
80 * - max 48 bytes (struct sk_buff::cb) 99 * - max 48 bytes (struct sk_buff::cb)
81 */ 100 */
@@ -89,7 +108,7 @@ struct rxrpc_skb_priv {
89 bool need_resend; /* T if needs resending */ 108 bool need_resend; /* T if needs resending */
90 }; 109 };
91 110
92 struct rxrpc_header hdr; /* RxRPC packet header from this packet */ 111 struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */
93}; 112};
94 113
95#define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb) 114#define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
@@ -230,7 +249,7 @@ struct rxrpc_conn_bundle {
230 atomic_t usage; 249 atomic_t usage;
231 int debug_id; /* debug ID for printks */ 250 int debug_id; /* debug ID for printks */
232 unsigned short num_conns; /* number of connections in this bundle */ 251 unsigned short num_conns; /* number of connections in this bundle */
233 __be16 service_id; /* service ID */ 252 u16 service_id; /* Service ID for this bundle */
234 u8 security_ix; /* security type */ 253 u8 security_ix; /* security type */
235}; 254};
236 255
@@ -260,7 +279,6 @@ struct rxrpc_connection {
260 rwlock_t lock; /* access lock */ 279 rwlock_t lock; /* access lock */
261 spinlock_t state_lock; /* state-change lock */ 280 spinlock_t state_lock; /* state-change lock */
262 atomic_t usage; 281 atomic_t usage;
263 u32 real_conn_id; /* connection ID (host-endian) */
264 enum { /* current state of connection */ 282 enum { /* current state of connection */
265 RXRPC_CONN_UNUSED, /* - connection not yet attempted */ 283 RXRPC_CONN_UNUSED, /* - connection not yet attempted */
266 RXRPC_CONN_CLIENT, /* - client connection */ 284 RXRPC_CONN_CLIENT, /* - client connection */
@@ -282,11 +300,9 @@ struct rxrpc_connection {
282 u8 security_size; /* security header size */ 300 u8 security_size; /* security header size */
283 u32 security_level; /* security level negotiated */ 301 u32 security_level; /* security level negotiated */
284 u32 security_nonce; /* response re-use preventer */ 302 u32 security_nonce; /* response re-use preventer */
285 303 u32 epoch; /* epoch of this connection */
286 /* the following are all in net order */ 304 u32 cid; /* connection ID */
287 __be32 epoch; /* epoch of this connection */ 305 u16 service_id; /* service ID for this connection */
288 __be32 cid; /* connection ID */
289 __be16 service_id; /* service ID */
290 u8 security_ix; /* security type */ 306 u8 security_ix; /* security type */
291 u8 in_clientflag; /* RXRPC_CLIENT_INITIATED if we are server */ 307 u8 in_clientflag; /* RXRPC_CLIENT_INITIATED if we are server */
292 u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */ 308 u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */
@@ -406,9 +422,9 @@ struct rxrpc_call {
406 rxrpc_seq_t rx_data_eaten; /* last data seq ID consumed by recvmsg */ 422 rxrpc_seq_t rx_data_eaten; /* last data seq ID consumed by recvmsg */
407 rxrpc_seq_t rx_first_oos; /* first packet in rx_oos_queue (or 0) */ 423 rxrpc_seq_t rx_first_oos; /* first packet in rx_oos_queue (or 0) */
408 rxrpc_seq_t ackr_win_top; /* top of ACK window (rx_data_eaten is bottom) */ 424 rxrpc_seq_t ackr_win_top; /* top of ACK window (rx_data_eaten is bottom) */
409 rxrpc_seq_net_t ackr_prev_seq; /* previous sequence number received */ 425 rxrpc_seq_t ackr_prev_seq; /* previous sequence number received */
410 u8 ackr_reason; /* reason to ACK */ 426 u8 ackr_reason; /* reason to ACK */
411 __be32 ackr_serial; /* serial of packet being ACK'd */ 427 rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */
412 atomic_t ackr_not_idle; /* number of packets in Rx queue */ 428 atomic_t ackr_not_idle; /* number of packets in Rx queue */
413 429
414 /* received packet records, 1 bit per record */ 430 /* received packet records, 1 bit per record */
@@ -420,11 +436,10 @@ struct rxrpc_call {
420 u8 in_clientflag; /* Copy of conn->in_clientflag for hashing */ 436 u8 in_clientflag; /* Copy of conn->in_clientflag for hashing */
421 struct rxrpc_local *local; /* Local endpoint. Used for hashing. */ 437 struct rxrpc_local *local; /* Local endpoint. Used for hashing. */
422 sa_family_t proto; /* Frame protocol */ 438 sa_family_t proto; /* Frame protocol */
423 /* the following should all be in net order */ 439 u32 call_id; /* call ID on connection */
424 __be32 cid; /* connection ID + channel index */ 440 u32 cid; /* connection ID plus channel index */
425 __be32 call_id; /* call ID on connection */ 441 u32 epoch; /* epoch of this connection */
426 __be32 epoch; /* epoch of this connection */ 442 u16 service_id; /* service ID */
427 __be16 service_id; /* service ID */
428 union { /* Peer IP address for hashing */ 443 union { /* Peer IP address for hashing */
429 __be32 ipv4_addr; 444 __be32 ipv4_addr;
430 __u8 ipv6_addr[16]; /* Anticipates eventual IPv6 support */ 445 __u8 ipv6_addr[16]; /* Anticipates eventual IPv6 support */
@@ -449,7 +464,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
449 * af_rxrpc.c 464 * af_rxrpc.c
450 */ 465 */
451extern atomic_t rxrpc_n_skbs; 466extern atomic_t rxrpc_n_skbs;
452extern __be32 rxrpc_epoch; 467extern u32 rxrpc_epoch;
453extern atomic_t rxrpc_debug_id; 468extern atomic_t rxrpc_debug_id;
454extern struct workqueue_struct *rxrpc_workqueue; 469extern struct workqueue_struct *rxrpc_workqueue;
455 470
@@ -470,8 +485,8 @@ extern unsigned rxrpc_rx_window_size;
470extern unsigned rxrpc_rx_mtu; 485extern unsigned rxrpc_rx_mtu;
471extern unsigned rxrpc_rx_jumbo_max; 486extern unsigned rxrpc_rx_jumbo_max;
472 487
473void __rxrpc_propose_ACK(struct rxrpc_call *, u8, __be32, bool); 488void __rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool);
474void rxrpc_propose_ACK(struct rxrpc_call *, u8, __be32, bool); 489void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool);
475void rxrpc_process_call(struct work_struct *); 490void rxrpc_process_call(struct work_struct *);
476 491
477/* 492/*
@@ -483,15 +498,15 @@ extern struct kmem_cache *rxrpc_call_jar;
483extern struct list_head rxrpc_calls; 498extern struct list_head rxrpc_calls;
484extern rwlock_t rxrpc_call_lock; 499extern rwlock_t rxrpc_call_lock;
485 500
486struct rxrpc_call *rxrpc_find_call_hash(u8, __be32, __be32, __be32, 501struct rxrpc_call *rxrpc_find_call_hash(struct rxrpc_host_header *,
487 __be16, void *, sa_family_t, const u8 *); 502 void *, sa_family_t, const void *);
488struct rxrpc_call *rxrpc_get_client_call(struct rxrpc_sock *, 503struct rxrpc_call *rxrpc_get_client_call(struct rxrpc_sock *,
489 struct rxrpc_transport *, 504 struct rxrpc_transport *,
490 struct rxrpc_conn_bundle *, 505 struct rxrpc_conn_bundle *,
491 unsigned long, int, gfp_t); 506 unsigned long, int, gfp_t);
492struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *, 507struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *,
493 struct rxrpc_connection *, 508 struct rxrpc_connection *,
494 struct rxrpc_header *, gfp_t); 509 struct rxrpc_host_header *, gfp_t);
495struct rxrpc_call *rxrpc_find_server_call(struct rxrpc_sock *, unsigned long); 510struct rxrpc_call *rxrpc_find_server_call(struct rxrpc_sock *, unsigned long);
496void rxrpc_release_call(struct rxrpc_call *); 511void rxrpc_release_call(struct rxrpc_call *);
497void rxrpc_release_calls_on_socket(struct rxrpc_sock *); 512void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
@@ -507,16 +522,16 @@ extern rwlock_t rxrpc_connection_lock;
507 522
508struct rxrpc_conn_bundle *rxrpc_get_bundle(struct rxrpc_sock *, 523struct rxrpc_conn_bundle *rxrpc_get_bundle(struct rxrpc_sock *,
509 struct rxrpc_transport *, 524 struct rxrpc_transport *,
510 struct key *, __be16, gfp_t); 525 struct key *, u16, gfp_t);
511void rxrpc_put_bundle(struct rxrpc_transport *, struct rxrpc_conn_bundle *); 526void rxrpc_put_bundle(struct rxrpc_transport *, struct rxrpc_conn_bundle *);
512int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_transport *, 527int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_transport *,
513 struct rxrpc_conn_bundle *, struct rxrpc_call *, gfp_t); 528 struct rxrpc_conn_bundle *, struct rxrpc_call *, gfp_t);
514void rxrpc_put_connection(struct rxrpc_connection *); 529void rxrpc_put_connection(struct rxrpc_connection *);
515void __exit rxrpc_destroy_all_connections(void); 530void __exit rxrpc_destroy_all_connections(void);
516struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_transport *, 531struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_transport *,
517 struct rxrpc_header *); 532 struct rxrpc_host_header *);
518extern struct rxrpc_connection * 533extern struct rxrpc_connection *
519rxrpc_incoming_connection(struct rxrpc_transport *, struct rxrpc_header *, 534rxrpc_incoming_connection(struct rxrpc_transport *, struct rxrpc_host_header *,
520 gfp_t); 535 gfp_t);
521 536
522/* 537/*
diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
index 78483b4602bf..4e1e6db0050b 100644
--- a/net/rxrpc/ar-local.c
+++ b/net/rxrpc/ar-local.c
@@ -323,9 +323,11 @@ void __exit rxrpc_destroy_all_locals(void)
323 * Reply to a version request 323 * Reply to a version request
324 */ 324 */
325static void rxrpc_send_version_request(struct rxrpc_local *local, 325static void rxrpc_send_version_request(struct rxrpc_local *local,
326 struct rxrpc_header *hdr, 326 struct rxrpc_host_header *hdr,
327 struct sk_buff *skb) 327 struct sk_buff *skb)
328{ 328{
329 struct rxrpc_wire_header whdr;
330 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
329 struct sockaddr_in sin; 331 struct sockaddr_in sin;
330 struct msghdr msg; 332 struct msghdr msg;
331 struct kvec iov[2]; 333 struct kvec iov[2];
@@ -344,15 +346,20 @@ static void rxrpc_send_version_request(struct rxrpc_local *local,
344 msg.msg_controllen = 0; 346 msg.msg_controllen = 0;
345 msg.msg_flags = 0; 347 msg.msg_flags = 0;
346 348
347 hdr->seq = 0; 349 whdr.epoch = htonl(sp->hdr.epoch);
348 hdr->serial = 0; 350 whdr.cid = htonl(sp->hdr.cid);
349 hdr->type = RXRPC_PACKET_TYPE_VERSION; 351 whdr.callNumber = htonl(sp->hdr.callNumber);
350 hdr->flags = RXRPC_LAST_PACKET | (~hdr->flags & RXRPC_CLIENT_INITIATED); 352 whdr.seq = 0;
351 hdr->userStatus = 0; 353 whdr.serial = 0;
352 hdr->_rsvd = 0; 354 whdr.type = RXRPC_PACKET_TYPE_VERSION;
353 355 whdr.flags = RXRPC_LAST_PACKET | (~hdr->flags & RXRPC_CLIENT_INITIATED);
354 iov[0].iov_base = hdr; 356 whdr.userStatus = 0;
355 iov[0].iov_len = sizeof(*hdr); 357 whdr.securityIndex = 0;
358 whdr._rsvd = 0;
359 whdr.serviceId = htons(sp->hdr.serviceId);
360
361 iov[0].iov_base = &whdr;
362 iov[0].iov_len = sizeof(whdr);
356 iov[1].iov_base = (char *)rxrpc_version_string; 363 iov[1].iov_base = (char *)rxrpc_version_string;
357 iov[1].iov_len = sizeof(rxrpc_version_string); 364 iov[1].iov_len = sizeof(rxrpc_version_string);
358 365
@@ -383,7 +390,7 @@ static void rxrpc_process_local_events(struct work_struct *work)
383 while ((skb = skb_dequeue(&local->event_queue))) { 390 while ((skb = skb_dequeue(&local->event_queue))) {
384 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 391 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
385 392
386 kdebug("{%d},{%u}", local->debug_id, sp->hdr.type); 393 _debug("{%d},{%u}", local->debug_id, sp->hdr.type);
387 394
388 switch (sp->hdr.type) { 395 switch (sp->hdr.type) {
389 case RXRPC_PACKET_TYPE_VERSION: 396 case RXRPC_PACKET_TYPE_VERSION:
diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
index 9e1527a6d026..353f5c9141ea 100644
--- a/net/rxrpc/ar-output.c
+++ b/net/rxrpc/ar-output.c
@@ -136,7 +136,7 @@ int rxrpc_client_sendmsg(struct rxrpc_sock *rx, struct rxrpc_transport *trans,
136 struct rxrpc_call *call; 136 struct rxrpc_call *call;
137 unsigned long user_call_ID = 0; 137 unsigned long user_call_ID = 0;
138 struct key *key; 138 struct key *key;
139 __be16 service_id; 139 u16 service_id;
140 u32 abort_code = 0; 140 u32 abort_code = 0;
141 int ret; 141 int ret;
142 142
@@ -151,11 +151,11 @@ int rxrpc_client_sendmsg(struct rxrpc_sock *rx, struct rxrpc_transport *trans,
151 151
152 bundle = NULL; 152 bundle = NULL;
153 if (trans) { 153 if (trans) {
154 service_id = rx->service_id; 154 service_id = rx->srx.srx_service;
155 if (msg->msg_name) { 155 if (msg->msg_name) {
156 DECLARE_SOCKADDR(struct sockaddr_rxrpc *, srx, 156 DECLARE_SOCKADDR(struct sockaddr_rxrpc *, srx,
157 msg->msg_name); 157 msg->msg_name);
158 service_id = htons(srx->srx_service); 158 service_id = srx->srx_service;
159 } 159 }
160 key = rx->key; 160 key = rx->key;
161 if (key && !rx->key->payload.data[0]) 161 if (key && !rx->key->payload.data[0])
@@ -348,7 +348,7 @@ int rxrpc_send_packet(struct rxrpc_transport *trans, struct sk_buff *skb)
348 348
349 /* send the packet with the don't fragment bit set if we currently 349 /* send the packet with the don't fragment bit set if we currently
350 * think it's small enough */ 350 * think it's small enough */
351 if (skb->len - sizeof(struct rxrpc_header) < trans->peer->maxdata) { 351 if (skb->len - sizeof(struct rxrpc_wire_header) < trans->peer->maxdata) {
352 down_read(&trans->local->defrag_sem); 352 down_read(&trans->local->defrag_sem);
353 /* send the packet by UDP 353 /* send the packet by UDP
354 * - returns -EMSGSIZE if UDP would have to fragment the packet 354 * - returns -EMSGSIZE if UDP would have to fragment the packet
@@ -480,8 +480,7 @@ static void rxrpc_queue_packet(struct rxrpc_call *call, struct sk_buff *skb,
480 write_unlock_bh(&call->state_lock); 480 write_unlock_bh(&call->state_lock);
481 } 481 }
482 482
483 _proto("Tx DATA %%%u { #%u }", 483 _proto("Tx DATA %%%u { #%u }", sp->hdr.serial, sp->hdr.seq);
484 ntohl(sp->hdr.serial), ntohl(sp->hdr.seq));
485 484
486 sp->need_resend = false; 485 sp->need_resend = false;
487 sp->resend_at = jiffies + rxrpc_resend_timeout; 486 sp->resend_at = jiffies + rxrpc_resend_timeout;
@@ -513,6 +512,29 @@ static void rxrpc_queue_packet(struct rxrpc_call *call, struct sk_buff *skb,
513} 512}
514 513
515/* 514/*
515 * Convert a host-endian header into a network-endian header.
516 */
517static void rxrpc_insert_header(struct sk_buff *skb)
518{
519 struct rxrpc_wire_header whdr;
520 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
521
522 whdr.epoch = htonl(sp->hdr.epoch);
523 whdr.cid = htonl(sp->hdr.cid);
524 whdr.callNumber = htonl(sp->hdr.callNumber);
525 whdr.seq = htonl(sp->hdr.seq);
526 whdr.serial = htonl(sp->hdr.serial);
527 whdr.type = sp->hdr.type;
528 whdr.flags = sp->hdr.flags;
529 whdr.userStatus = sp->hdr.userStatus;
530 whdr.securityIndex = sp->hdr.securityIndex;
531 whdr._rsvd = htons(sp->hdr._rsvd);
532 whdr.serviceId = htons(sp->hdr.serviceId);
533
534 memcpy(skb->head, &whdr, sizeof(whdr));
535}
536
537/*
516 * send data through a socket 538 * send data through a socket
517 * - must be called in process context 539 * - must be called in process context
518 * - caller holds the socket locked 540 * - caller holds the socket locked
@@ -650,17 +672,16 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
650 672
651 seq = atomic_inc_return(&call->sequence); 673 seq = atomic_inc_return(&call->sequence);
652 674
653 sp->hdr.epoch = conn->epoch; 675 sp->hdr.epoch = conn->epoch;
654 sp->hdr.cid = call->cid; 676 sp->hdr.cid = call->cid;
655 sp->hdr.callNumber = call->call_id; 677 sp->hdr.callNumber = call->call_id;
656 sp->hdr.seq = htonl(seq); 678 sp->hdr.seq = seq;
657 sp->hdr.serial = 679 sp->hdr.serial = atomic_inc_return(&conn->serial);
658 htonl(atomic_inc_return(&conn->serial)); 680 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
659 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
660 sp->hdr.userStatus = 0; 681 sp->hdr.userStatus = 0;
661 sp->hdr.securityIndex = conn->security_ix; 682 sp->hdr.securityIndex = conn->security_ix;
662 sp->hdr._rsvd = 0; 683 sp->hdr._rsvd = 0;
663 sp->hdr.serviceId = conn->service_id; 684 sp->hdr.serviceId = call->service_id;
664 685
665 sp->hdr.flags = conn->out_clientflag; 686 sp->hdr.flags = conn->out_clientflag;
666 if (msg_data_left(msg) == 0 && !more) 687 if (msg_data_left(msg) == 0 && !more)
@@ -673,12 +694,11 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
673 694
674 ret = rxrpc_secure_packet( 695 ret = rxrpc_secure_packet(
675 call, skb, skb->mark, 696 call, skb, skb->mark,
676 skb->head + sizeof(struct rxrpc_header)); 697 skb->head + sizeof(struct rxrpc_wire_header));
677 if (ret < 0) 698 if (ret < 0)
678 goto out; 699 goto out;
679 700
680 memcpy(skb->head, &sp->hdr, 701 rxrpc_insert_header(skb);
681 sizeof(struct rxrpc_header));
682 rxrpc_queue_packet(call, skb, !msg_data_left(msg) && !more); 702 rxrpc_queue_packet(call, skb, !msg_data_left(msg) && !more);
683 skb = NULL; 703 skb = NULL;
684 } 704 }
diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
index bebaa43484bc..dc089b1976aa 100644
--- a/net/rxrpc/ar-peer.c
+++ b/net/rxrpc/ar-peer.c
@@ -92,7 +92,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
92 BUG(); 92 BUG();
93 } 93 }
94 94
95 peer->hdrsize += sizeof(struct rxrpc_header); 95 peer->hdrsize += sizeof(struct rxrpc_wire_header);
96 peer->maxdata = peer->mtu - peer->hdrsize; 96 peer->maxdata = peer->mtu - peer->hdrsize;
97 } 97 }
98 98
diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
index 38047f713f2c..525b2ba5a8f4 100644
--- a/net/rxrpc/ar-proc.c
+++ b/net/rxrpc/ar-proc.c
@@ -74,9 +74,9 @@ static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
74 " %-8.8s %08x %lx\n", 74 " %-8.8s %08x %lx\n",
75 lbuff, 75 lbuff,
76 rbuff, 76 rbuff,
77 ntohs(call->conn->service_id), 77 call->conn->service_id,
78 ntohl(call->conn->cid), 78 call->cid,
79 ntohl(call->call_id), 79 call->call_id,
80 call->conn->in_clientflag ? "Svc" : "Clt", 80 call->conn->in_clientflag ? "Svc" : "Clt",
81 atomic_read(&call->usage), 81 atomic_read(&call->usage),
82 rxrpc_call_states[call->state], 82 rxrpc_call_states[call->state],
@@ -157,8 +157,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
157 " %s %08x %08x %08x\n", 157 " %s %08x %08x %08x\n",
158 lbuff, 158 lbuff,
159 rbuff, 159 rbuff,
160 ntohs(conn->service_id), 160 conn->service_id,
161 ntohl(conn->cid), 161 conn->cid,
162 conn->call_counter, 162 conn->call_counter,
163 conn->in_clientflag ? "Svc" : "Clt", 163 conn->in_clientflag ? "Svc" : "Clt",
164 atomic_read(&conn->usage), 164 atomic_read(&conn->usage),
diff --git a/net/rxrpc/ar-recvmsg.c b/net/rxrpc/ar-recvmsg.c
index 70f47033ff2f..64facba24a45 100644
--- a/net/rxrpc/ar-recvmsg.c
+++ b/net/rxrpc/ar-recvmsg.c
@@ -158,7 +158,7 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
158 goto receive_non_data_message; 158 goto receive_non_data_message;
159 159
160 _debug("recvmsg DATA #%u { %d, %d }", 160 _debug("recvmsg DATA #%u { %d, %d }",
161 ntohl(sp->hdr.seq), skb->len, sp->offset); 161 sp->hdr.seq, skb->len, sp->offset);
162 162
163 if (!continue_call) { 163 if (!continue_call) {
164 /* only set the control data once per recvmsg() */ 164 /* only set the control data once per recvmsg() */
@@ -169,11 +169,11 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
169 ASSERT(test_bit(RXRPC_CALL_HAS_USERID, &call->flags)); 169 ASSERT(test_bit(RXRPC_CALL_HAS_USERID, &call->flags));
170 } 170 }
171 171
172 ASSERTCMP(ntohl(sp->hdr.seq), >=, call->rx_data_recv); 172 ASSERTCMP(sp->hdr.seq, >=, call->rx_data_recv);
173 ASSERTCMP(ntohl(sp->hdr.seq), <=, call->rx_data_recv + 1); 173 ASSERTCMP(sp->hdr.seq, <=, call->rx_data_recv + 1);
174 call->rx_data_recv = ntohl(sp->hdr.seq); 174 call->rx_data_recv = sp->hdr.seq;
175 175
176 ASSERTCMP(ntohl(sp->hdr.seq), >, call->rx_data_eaten); 176 ASSERTCMP(sp->hdr.seq, >, call->rx_data_eaten);
177 177
178 offset = sp->offset; 178 offset = sp->offset;
179 copy = skb->len - offset; 179 copy = skb->len - offset;
@@ -364,11 +364,11 @@ void rxrpc_kernel_data_delivered(struct sk_buff *skb)
364 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 364 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
365 struct rxrpc_call *call = sp->call; 365 struct rxrpc_call *call = sp->call;
366 366
367 ASSERTCMP(ntohl(sp->hdr.seq), >=, call->rx_data_recv); 367 ASSERTCMP(sp->hdr.seq, >=, call->rx_data_recv);
368 ASSERTCMP(ntohl(sp->hdr.seq), <=, call->rx_data_recv + 1); 368 ASSERTCMP(sp->hdr.seq, <=, call->rx_data_recv + 1);
369 call->rx_data_recv = ntohl(sp->hdr.seq); 369 call->rx_data_recv = sp->hdr.seq;
370 370
371 ASSERTCMP(ntohl(sp->hdr.seq), >, call->rx_data_eaten); 371 ASSERTCMP(sp->hdr.seq, >, call->rx_data_eaten);
372 rxrpc_free_skb(skb); 372 rxrpc_free_skb(skb);
373} 373}
374 374
diff --git a/net/rxrpc/ar-security.c b/net/rxrpc/ar-security.c
index 8334474eb26c..e2f4c49a9246 100644
--- a/net/rxrpc/ar-security.c
+++ b/net/rxrpc/ar-security.c
@@ -171,7 +171,7 @@ int rxrpc_init_server_conn_security(struct rxrpc_connection *conn)
171 171
172 _enter(""); 172 _enter("");
173 173
174 sprintf(kdesc, "%u:%u", ntohs(conn->service_id), conn->security_ix); 174 sprintf(kdesc, "%u:%u", conn->service_id, conn->security_ix);
175 175
176 sec = rxrpc_security_lookup(conn->security_ix); 176 sec = rxrpc_security_lookup(conn->security_ix);
177 if (!sec) { 177 if (!sec) {
@@ -182,7 +182,7 @@ int rxrpc_init_server_conn_security(struct rxrpc_connection *conn)
182 /* find the service */ 182 /* find the service */
183 read_lock_bh(&local->services_lock); 183 read_lock_bh(&local->services_lock);
184 list_for_each_entry(rx, &local->services, listen_link) { 184 list_for_each_entry(rx, &local->services, listen_link) {
185 if (rx->service_id == conn->service_id) 185 if (rx->srx.srx_service == conn->service_id)
186 goto found_service; 186 goto found_service;
187 } 187 }
188 188
diff --git a/net/rxrpc/ar-skbuff.c b/net/rxrpc/ar-skbuff.c
index 81f3c0238b9a..ae9f93f94ed2 100644
--- a/net/rxrpc/ar-skbuff.c
+++ b/net/rxrpc/ar-skbuff.c
@@ -59,7 +59,7 @@ static void rxrpc_hard_ACK_data(struct rxrpc_call *call,
59 59
60 spin_lock_bh(&call->lock); 60 spin_lock_bh(&call->lock);
61 61
62 _debug("hard ACK #%u", ntohl(sp->hdr.seq)); 62 _debug("hard ACK #%u", sp->hdr.seq);
63 63
64 for (loop = 0; loop < RXRPC_ACKR_WINDOW_ASZ; loop++) { 64 for (loop = 0; loop < RXRPC_ACKR_WINDOW_ASZ; loop++) {
65 call->ackr_window[loop] >>= 1; 65 call->ackr_window[loop] >>= 1;
@@ -67,7 +67,7 @@ static void rxrpc_hard_ACK_data(struct rxrpc_call *call,
67 call->ackr_window[loop + 1] << (BITS_PER_LONG - 1); 67 call->ackr_window[loop + 1] << (BITS_PER_LONG - 1);
68 } 68 }
69 69
70 seq = ntohl(sp->hdr.seq); 70 seq = sp->hdr.seq;
71 ASSERTCMP(seq, ==, call->rx_data_eaten + 1); 71 ASSERTCMP(seq, ==, call->rx_data_eaten + 1);
72 call->rx_data_eaten = seq; 72 call->rx_data_eaten = seq;
73 73
diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
index 9946467f16b4..5f9b9d462f53 100644
--- a/net/rxrpc/ar-transport.c
+++ b/net/rxrpc/ar-transport.c
@@ -51,6 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
51 spin_lock_init(&trans->client_lock); 51 spin_lock_init(&trans->client_lock);
52 rwlock_init(&trans->conn_lock); 52 rwlock_init(&trans->conn_lock);
53 atomic_set(&trans->usage, 1); 53 atomic_set(&trans->usage, 1);
54 trans->conn_idcounter = peer->srx.srx_service << 16;
54 trans->debug_id = atomic_inc_return(&rxrpc_debug_id); 55 trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
55 56
56 if (peer->srx.transport.family == AF_INET) { 57 if (peer->srx.transport.family == AF_INET) {
diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
index d7a9ab5a9d9c..160480221224 100644
--- a/net/rxrpc/rxkad.c
+++ b/net/rxrpc/rxkad.c
@@ -132,8 +132,8 @@ static void rxkad_prime_packet_security(struct rxrpc_connection *conn)
132 desc.info = iv.x; 132 desc.info = iv.x;
133 desc.flags = 0; 133 desc.flags = 0;
134 134
135 tmpbuf.x[0] = conn->epoch; 135 tmpbuf.x[0] = htonl(conn->epoch);
136 tmpbuf.x[1] = conn->cid; 136 tmpbuf.x[1] = htonl(conn->cid);
137 tmpbuf.x[2] = 0; 137 tmpbuf.x[2] = 0;
138 tmpbuf.x[3] = htonl(conn->security_ix); 138 tmpbuf.x[3] = htonl(conn->security_ix);
139 139
@@ -169,8 +169,8 @@ static int rxkad_secure_packet_auth(const struct rxrpc_call *call,
169 169
170 _enter(""); 170 _enter("");
171 171
172 check = ntohl(sp->hdr.seq ^ sp->hdr.callNumber); 172 check = sp->hdr.seq ^ sp->hdr.callNumber;
173 data_size |= (u32) check << 16; 173 data_size |= (u32)check << 16;
174 174
175 tmpbuf.hdr.data_size = htonl(data_size); 175 tmpbuf.hdr.data_size = htonl(data_size);
176 memcpy(&tmpbuf.first, sechdr + 4, sizeof(tmpbuf.first)); 176 memcpy(&tmpbuf.first, sechdr + 4, sizeof(tmpbuf.first));
@@ -215,9 +215,9 @@ static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call,
215 215
216 _enter(""); 216 _enter("");
217 217
218 check = ntohl(sp->hdr.seq ^ sp->hdr.callNumber); 218 check = sp->hdr.seq ^ sp->hdr.callNumber;
219 219
220 rxkhdr.data_size = htonl(data_size | (u32) check << 16); 220 rxkhdr.data_size = htonl(data_size | (u32)check << 16);
221 rxkhdr.checksum = 0; 221 rxkhdr.checksum = 0;
222 222
223 /* encrypt from the session key */ 223 /* encrypt from the session key */
@@ -262,14 +262,13 @@ static int rxkad_secure_packet(const struct rxrpc_call *call,
262 struct { 262 struct {
263 __be32 x[2]; 263 __be32 x[2];
264 } tmpbuf __attribute__((aligned(8))); /* must all be in same page */ 264 } tmpbuf __attribute__((aligned(8))); /* must all be in same page */
265 __be32 x; 265 u32 x, y;
266 u32 y;
267 int ret; 266 int ret;
268 267
269 sp = rxrpc_skb(skb); 268 sp = rxrpc_skb(skb);
270 269
271 _enter("{%d{%x}},{#%u},%zu,", 270 _enter("{%d{%x}},{#%u},%zu,",
272 call->debug_id, key_serial(call->conn->key), ntohl(sp->hdr.seq), 271 call->debug_id, key_serial(call->conn->key), sp->hdr.seq,
273 data_size); 272 data_size);
274 273
275 if (!call->conn->cipher) 274 if (!call->conn->cipher)
@@ -286,10 +285,10 @@ static int rxkad_secure_packet(const struct rxrpc_call *call,
286 desc.flags = 0; 285 desc.flags = 0;
287 286
288 /* calculate the security checksum */ 287 /* calculate the security checksum */
289 x = htonl(call->channel << (32 - RXRPC_CIDSHIFT)); 288 x = call->channel << (32 - RXRPC_CIDSHIFT);
290 x |= sp->hdr.seq & cpu_to_be32(0x3fffffff); 289 x |= sp->hdr.seq & 0x3fffffff;
291 tmpbuf.x[0] = sp->hdr.callNumber; 290 tmpbuf.x[0] = htonl(sp->hdr.callNumber);
292 tmpbuf.x[1] = x; 291 tmpbuf.x[1] = htonl(x);
293 292
294 sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf)); 293 sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf));
295 sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf)); 294 sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf));
@@ -299,7 +298,7 @@ static int rxkad_secure_packet(const struct rxrpc_call *call,
299 y = (y >> 16) & 0xffff; 298 y = (y >> 16) & 0xffff;
300 if (y == 0) 299 if (y == 0)
301 y = 1; /* zero checksums are not permitted */ 300 y = 1; /* zero checksums are not permitted */
302 sp->hdr.cksum = htons(y); 301 sp->hdr.cksum = y;
303 302
304 switch (call->conn->security_level) { 303 switch (call->conn->security_level) {
305 case RXRPC_SECURITY_PLAIN: 304 case RXRPC_SECURITY_PLAIN:
@@ -368,7 +367,7 @@ static int rxkad_verify_packet_auth(const struct rxrpc_call *call,
368 data_size = buf & 0xffff; 367 data_size = buf & 0xffff;
369 368
370 check = buf >> 16; 369 check = buf >> 16;
371 check ^= ntohl(sp->hdr.seq ^ sp->hdr.callNumber); 370 check ^= sp->hdr.seq ^ sp->hdr.callNumber;
372 check &= 0xffff; 371 check &= 0xffff;
373 if (check != 0) { 372 if (check != 0) {
374 *_abort_code = RXKADSEALEDINCON; 373 *_abort_code = RXKADSEALEDINCON;
@@ -453,7 +452,7 @@ static int rxkad_verify_packet_encrypt(const struct rxrpc_call *call,
453 data_size = buf & 0xffff; 452 data_size = buf & 0xffff;
454 453
455 check = buf >> 16; 454 check = buf >> 16;
456 check ^= ntohl(sp->hdr.seq ^ sp->hdr.callNumber); 455 check ^= sp->hdr.seq ^ sp->hdr.callNumber;
457 check &= 0xffff; 456 check &= 0xffff;
458 if (check != 0) { 457 if (check != 0) {
459 *_abort_code = RXKADSEALEDINCON; 458 *_abort_code = RXKADSEALEDINCON;
@@ -494,16 +493,14 @@ static int rxkad_verify_packet(const struct rxrpc_call *call,
494 struct { 493 struct {
495 __be32 x[2]; 494 __be32 x[2];
496 } tmpbuf __attribute__((aligned(8))); /* must all be in same page */ 495 } tmpbuf __attribute__((aligned(8))); /* must all be in same page */
497 __be32 x; 496 u16 cksum;
498 __be16 cksum; 497 u32 x, y;
499 u32 y;
500 int ret; 498 int ret;
501 499
502 sp = rxrpc_skb(skb); 500 sp = rxrpc_skb(skb);
503 501
504 _enter("{%d{%x}},{#%u}", 502 _enter("{%d{%x}},{#%u}",
505 call->debug_id, key_serial(call->conn->key), 503 call->debug_id, key_serial(call->conn->key), sp->hdr.seq);
506 ntohl(sp->hdr.seq));
507 504
508 if (!call->conn->cipher) 505 if (!call->conn->cipher)
509 return 0; 506 return 0;
@@ -521,21 +518,20 @@ static int rxkad_verify_packet(const struct rxrpc_call *call,
521 desc.flags = 0; 518 desc.flags = 0;
522 519
523 /* validate the security checksum */ 520 /* validate the security checksum */
524 x = htonl(call->channel << (32 - RXRPC_CIDSHIFT)); 521 x = call->channel << (32 - RXRPC_CIDSHIFT);
525 x |= sp->hdr.seq & cpu_to_be32(0x3fffffff); 522 x |= sp->hdr.seq & 0x3fffffff;
526 tmpbuf.x[0] = call->call_id; 523 tmpbuf.x[0] = htonl(call->call_id);
527 tmpbuf.x[1] = x; 524 tmpbuf.x[1] = htonl(x);
528 525
529 sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf)); 526 sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf));
530 sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf)); 527 sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf));
531 crypto_blkcipher_encrypt_iv(&desc, &sg[0], &sg[1], sizeof(tmpbuf)); 528 crypto_blkcipher_encrypt_iv(&desc, &sg[0], &sg[1], sizeof(tmpbuf));
532 529
533 y = ntohl(tmpbuf.x[1]); 530 y = ntohl(tmpbuf.x[1]);
534 y = (y >> 16) & 0xffff; 531 cksum = (y >> 16) & 0xffff;
535 if (y == 0) 532 if (cksum == 0)
536 y = 1; /* zero checksums are not permitted */ 533 cksum = 1; /* zero checksums are not permitted */
537 534
538 cksum = htons(y);
539 if (sp->hdr.cksum != cksum) { 535 if (sp->hdr.cksum != cksum) {
540 *_abort_code = RXKADSEALEDINCON; 536 *_abort_code = RXKADSEALEDINCON;
541 _leave(" = -EPROTO [csum failed]"); 537 _leave(" = -EPROTO [csum failed]");
@@ -567,10 +563,11 @@ static int rxkad_verify_packet(const struct rxrpc_call *call,
567static int rxkad_issue_challenge(struct rxrpc_connection *conn) 563static int rxkad_issue_challenge(struct rxrpc_connection *conn)
568{ 564{
569 struct rxkad_challenge challenge; 565 struct rxkad_challenge challenge;
570 struct rxrpc_header hdr; 566 struct rxrpc_wire_header whdr;
571 struct msghdr msg; 567 struct msghdr msg;
572 struct kvec iov[2]; 568 struct kvec iov[2];
573 size_t len; 569 size_t len;
570 u32 serial;
574 int ret; 571 int ret;
575 572
576 _enter("{%d,%x}", conn->debug_id, key_serial(conn->key)); 573 _enter("{%d,%x}", conn->debug_id, key_serial(conn->key));
@@ -592,26 +589,27 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
592 msg.msg_controllen = 0; 589 msg.msg_controllen = 0;
593 msg.msg_flags = 0; 590 msg.msg_flags = 0;
594 591
595 hdr.epoch = conn->epoch; 592 whdr.epoch = htonl(conn->epoch);
596 hdr.cid = conn->cid; 593 whdr.cid = htonl(conn->cid);
597 hdr.callNumber = 0; 594 whdr.callNumber = 0;
598 hdr.seq = 0; 595 whdr.seq = 0;
599 hdr.type = RXRPC_PACKET_TYPE_CHALLENGE; 596 whdr.type = RXRPC_PACKET_TYPE_CHALLENGE;
600 hdr.flags = conn->out_clientflag; 597 whdr.flags = conn->out_clientflag;
601 hdr.userStatus = 0; 598 whdr.userStatus = 0;
602 hdr.securityIndex = conn->security_ix; 599 whdr.securityIndex = conn->security_ix;
603 hdr._rsvd = 0; 600 whdr._rsvd = 0;
604 hdr.serviceId = conn->service_id; 601 whdr.serviceId = htons(conn->service_id);
605 602
606 iov[0].iov_base = &hdr; 603 iov[0].iov_base = &whdr;
607 iov[0].iov_len = sizeof(hdr); 604 iov[0].iov_len = sizeof(whdr);
608 iov[1].iov_base = &challenge; 605 iov[1].iov_base = &challenge;
609 iov[1].iov_len = sizeof(challenge); 606 iov[1].iov_len = sizeof(challenge);
610 607
611 len = iov[0].iov_len + iov[1].iov_len; 608 len = iov[0].iov_len + iov[1].iov_len;
612 609
613 hdr.serial = htonl(atomic_inc_return(&conn->serial)); 610 serial = atomic_inc_return(&conn->serial);
614 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial)); 611 whdr.serial = htonl(serial);
612 _proto("Tx CHALLENGE %%%u", serial);
615 613
616 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len); 614 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
617 if (ret < 0) { 615 if (ret < 0) {
@@ -627,13 +625,15 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
627 * send a Kerberos security response 625 * send a Kerberos security response
628 */ 626 */
629static int rxkad_send_response(struct rxrpc_connection *conn, 627static int rxkad_send_response(struct rxrpc_connection *conn,
630 struct rxrpc_header *hdr, 628 struct rxrpc_host_header *hdr,
631 struct rxkad_response *resp, 629 struct rxkad_response *resp,
632 const struct rxkad_key *s2) 630 const struct rxkad_key *s2)
633{ 631{
632 struct rxrpc_wire_header whdr;
634 struct msghdr msg; 633 struct msghdr msg;
635 struct kvec iov[3]; 634 struct kvec iov[3];
636 size_t len; 635 size_t len;
636 u32 serial;
637 int ret; 637 int ret;
638 638
639 _enter(""); 639 _enter("");
@@ -644,24 +644,26 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
644 msg.msg_controllen = 0; 644 msg.msg_controllen = 0;
645 msg.msg_flags = 0; 645 msg.msg_flags = 0;
646 646
647 hdr->epoch = conn->epoch; 647 memset(&whdr, 0, sizeof(whdr));
648 hdr->seq = 0; 648 whdr.epoch = htonl(hdr->epoch);
649 hdr->type = RXRPC_PACKET_TYPE_RESPONSE; 649 whdr.cid = htonl(hdr->cid);
650 hdr->flags = conn->out_clientflag; 650 whdr.type = RXRPC_PACKET_TYPE_RESPONSE;
651 hdr->userStatus = 0; 651 whdr.flags = conn->out_clientflag;
652 hdr->_rsvd = 0; 652 whdr.securityIndex = hdr->securityIndex;
653 whdr.serviceId = htons(hdr->serviceId);
653 654
654 iov[0].iov_base = hdr; 655 iov[0].iov_base = &whdr;
655 iov[0].iov_len = sizeof(*hdr); 656 iov[0].iov_len = sizeof(whdr);
656 iov[1].iov_base = resp; 657 iov[1].iov_base = resp;
657 iov[1].iov_len = sizeof(*resp); 658 iov[1].iov_len = sizeof(*resp);
658 iov[2].iov_base = (void *) s2->ticket; 659 iov[2].iov_base = (void *)s2->ticket;
659 iov[2].iov_len = s2->ticket_len; 660 iov[2].iov_len = s2->ticket_len;
660 661
661 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len; 662 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
662 663
663 hdr->serial = htonl(atomic_inc_return(&conn->serial)); 664 serial = atomic_inc_return(&conn->serial);
664 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial)); 665 whdr.serial = htonl(serial);
666 _proto("Tx RESPONSE %%%u", serial);
665 667
666 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len); 668 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
667 if (ret < 0) { 669 if (ret < 0) {
@@ -770,7 +772,7 @@ static int rxkad_respond_to_challenge(struct rxrpc_connection *conn,
770 min_level = ntohl(challenge.min_level); 772 min_level = ntohl(challenge.min_level);
771 773
772 _proto("Rx CHALLENGE %%%u { v=%u n=%u ml=%u }", 774 _proto("Rx CHALLENGE %%%u { v=%u n=%u ml=%u }",
773 ntohl(sp->hdr.serial), version, nonce, min_level); 775 sp->hdr.serial, version, nonce, min_level);
774 776
775 abort_code = RXKADINCONSISTENCY; 777 abort_code = RXKADINCONSISTENCY;
776 if (version != RXKAD_VERSION) 778 if (version != RXKAD_VERSION)
@@ -786,17 +788,17 @@ static int rxkad_respond_to_challenge(struct rxrpc_connection *conn,
786 memset(&resp, 0, sizeof(resp)); 788 memset(&resp, 0, sizeof(resp));
787 789
788 resp.version = RXKAD_VERSION; 790 resp.version = RXKAD_VERSION;
789 resp.encrypted.epoch = conn->epoch; 791 resp.encrypted.epoch = htonl(conn->epoch);
790 resp.encrypted.cid = conn->cid; 792 resp.encrypted.cid = htonl(conn->cid);
791 resp.encrypted.securityIndex = htonl(conn->security_ix); 793 resp.encrypted.securityIndex = htonl(conn->security_ix);
792 resp.encrypted.call_id[0] = 794 resp.encrypted.call_id[0] =
793 (conn->channels[0] ? conn->channels[0]->call_id : 0); 795 htonl(conn->channels[0] ? conn->channels[0]->call_id : 0);
794 resp.encrypted.call_id[1] = 796 resp.encrypted.call_id[1] =
795 (conn->channels[1] ? conn->channels[1]->call_id : 0); 797 htonl(conn->channels[1] ? conn->channels[1]->call_id : 0);
796 resp.encrypted.call_id[2] = 798 resp.encrypted.call_id[2] =
797 (conn->channels[2] ? conn->channels[2]->call_id : 0); 799 htonl(conn->channels[2] ? conn->channels[2]->call_id : 0);
798 resp.encrypted.call_id[3] = 800 resp.encrypted.call_id[3] =
799 (conn->channels[3] ? conn->channels[3]->call_id : 0); 801 htonl(conn->channels[3] ? conn->channels[3]->call_id : 0);
800 resp.encrypted.inc_nonce = htonl(nonce + 1); 802 resp.encrypted.inc_nonce = htonl(nonce + 1);
801 resp.encrypted.level = htonl(conn->security_level); 803 resp.encrypted.level = htonl(conn->security_level);
802 resp.kvno = htonl(token->kad->kvno); 804 resp.kvno = htonl(token->kad->kvno);
@@ -1022,7 +1024,7 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
1022 kvno = ntohl(response.kvno); 1024 kvno = ntohl(response.kvno);
1023 sp = rxrpc_skb(skb); 1025 sp = rxrpc_skb(skb);
1024 _proto("Rx RESPONSE %%%u { v=%u kv=%u tl=%u }", 1026 _proto("Rx RESPONSE %%%u { v=%u kv=%u tl=%u }",
1025 ntohl(sp->hdr.serial), version, kvno, ticket_len); 1027 sp->hdr.serial, version, kvno, ticket_len);
1026 1028
1027 abort_code = RXKADINCONSISTENCY; 1029 abort_code = RXKADINCONSISTENCY;
1028 if (version != RXKAD_VERSION) 1030 if (version != RXKAD_VERSION)
@@ -1058,9 +1060,9 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
1058 rxkad_decrypt_response(conn, &response, &session_key); 1060 rxkad_decrypt_response(conn, &response, &session_key);
1059 1061
1060 abort_code = RXKADSEALEDINCON; 1062 abort_code = RXKADSEALEDINCON;
1061 if (response.encrypted.epoch != conn->epoch) 1063 if (ntohl(response.encrypted.epoch) != conn->epoch)
1062 goto protocol_error_free; 1064 goto protocol_error_free;
1063 if (response.encrypted.cid != conn->cid) 1065 if (ntohl(response.encrypted.cid) != conn->cid)
1064 goto protocol_error_free; 1066 goto protocol_error_free;
1065 if (ntohl(response.encrypted.securityIndex) != conn->security_ix) 1067 if (ntohl(response.encrypted.securityIndex) != conn->security_ix)
1066 goto protocol_error_free; 1068 goto protocol_error_free;
@@ -1077,7 +1079,7 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
1077 goto protocol_error_free; 1079 goto protocol_error_free;
1078 1080
1079 abort_code = RXKADOUTOFSEQUENCE; 1081 abort_code = RXKADOUTOFSEQUENCE;
1080 if (response.encrypted.inc_nonce != htonl(conn->security_nonce + 1)) 1082 if (ntohl(response.encrypted.inc_nonce) != conn->security_nonce + 1)
1081 goto protocol_error_free; 1083 goto protocol_error_free;
1082 1084
1083 abort_code = RXKADLEVELFAIL; 1085 abort_code = RXKADLEVELFAIL;