aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2016-04-04 09:00:34 -0400
committerDavid Howells <dhowells@redhat.com>2016-06-15 10:37:12 -0400
commit875636163b4e694c092625ed98b17e10d582b3ca (patch)
treea369edf401991df10a8d6ce2952f23de97b7f054
parentf66d7490196055cb9fb058f8936d19111a6231b9 (diff)
rxrpc: Separate local endpoint event handling out into its own file
Separate local endpoint event handling out into its own file preparatory to overhauling the object management aspect (which remains in the original file). Signed-off-by: David Howells <dhowells@redhat.com>
-rw-r--r--net/rxrpc/Makefile1
-rw-r--r--net/rxrpc/ar-internal.h5
-rw-r--r--net/rxrpc/local_event.c120
-rw-r--r--net/rxrpc/local_object.c105
4 files changed, 129 insertions, 102 deletions
diff --git a/net/rxrpc/Makefile b/net/rxrpc/Makefile
index a6f6f21d8a59..b005027f80cf 100644
--- a/net/rxrpc/Makefile
+++ b/net/rxrpc/Makefile
@@ -12,6 +12,7 @@ af-rxrpc-y := \
12 input.o \ 12 input.o \
13 insecure.o \ 13 insecure.o \
14 key.o \ 14 key.o \
15 local_event.o \
15 local_object.o \ 16 local_object.o \
16 misc.o \ 17 misc.o \
17 output.o \ 18 output.o \
diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
index a63bb7518fb5..fa50b09eaa63 100644
--- a/net/rxrpc/ar-internal.h
+++ b/net/rxrpc/ar-internal.h
@@ -573,6 +573,11 @@ int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t,
573 u32); 573 u32);
574 574
575/* 575/*
576 * local_event.c
577 */
578extern void rxrpc_process_local_events(struct work_struct *);
579
580/*
576 * local_object.c 581 * local_object.c
577 */ 582 */
578extern rwlock_t rxrpc_local_lock; 583extern rwlock_t rxrpc_local_lock;
diff --git a/net/rxrpc/local_event.c b/net/rxrpc/local_event.c
new file mode 100644
index 000000000000..194db2e6d548
--- /dev/null
+++ b/net/rxrpc/local_event.c
@@ -0,0 +1,120 @@
1/* AF_RXRPC local endpoint management
2 *
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
14#include <linux/module.h>
15#include <linux/net.h>
16#include <linux/skbuff.h>
17#include <linux/slab.h>
18#include <linux/udp.h>
19#include <linux/ip.h>
20#include <net/sock.h>
21#include <net/af_rxrpc.h>
22#include <generated/utsrelease.h>
23#include "ar-internal.h"
24
25static const char rxrpc_version_string[65] = "linux-" UTS_RELEASE " AF_RXRPC";
26
27/*
28 * Reply to a version request
29 */
30static void rxrpc_send_version_request(struct rxrpc_local *local,
31 struct rxrpc_host_header *hdr,
32 struct sk_buff *skb)
33{
34 struct rxrpc_wire_header whdr;
35 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
36 struct sockaddr_in sin;
37 struct msghdr msg;
38 struct kvec iov[2];
39 size_t len;
40 int ret;
41
42 _enter("");
43
44 sin.sin_family = AF_INET;
45 sin.sin_port = udp_hdr(skb)->source;
46 sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
47
48 msg.msg_name = &sin;
49 msg.msg_namelen = sizeof(sin);
50 msg.msg_control = NULL;
51 msg.msg_controllen = 0;
52 msg.msg_flags = 0;
53
54 whdr.epoch = htonl(sp->hdr.epoch);
55 whdr.cid = htonl(sp->hdr.cid);
56 whdr.callNumber = htonl(sp->hdr.callNumber);
57 whdr.seq = 0;
58 whdr.serial = 0;
59 whdr.type = RXRPC_PACKET_TYPE_VERSION;
60 whdr.flags = RXRPC_LAST_PACKET | (~hdr->flags & RXRPC_CLIENT_INITIATED);
61 whdr.userStatus = 0;
62 whdr.securityIndex = 0;
63 whdr._rsvd = 0;
64 whdr.serviceId = htons(sp->hdr.serviceId);
65
66 iov[0].iov_base = &whdr;
67 iov[0].iov_len = sizeof(whdr);
68 iov[1].iov_base = (char *)rxrpc_version_string;
69 iov[1].iov_len = sizeof(rxrpc_version_string);
70
71 len = iov[0].iov_len + iov[1].iov_len;
72
73 _proto("Tx VERSION (reply)");
74
75 ret = kernel_sendmsg(local->socket, &msg, iov, 2, len);
76 if (ret < 0)
77 _debug("sendmsg failed: %d", ret);
78
79 _leave("");
80}
81
82/*
83 * Process event packets targetted at a local endpoint.
84 */
85void rxrpc_process_local_events(struct work_struct *work)
86{
87 struct rxrpc_local *local = container_of(work, struct rxrpc_local, event_processor);
88 struct sk_buff *skb;
89 char v;
90
91 _enter("");
92
93 atomic_inc(&local->usage);
94
95 while ((skb = skb_dequeue(&local->event_queue))) {
96 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
97
98 _debug("{%d},{%u}", local->debug_id, sp->hdr.type);
99
100 switch (sp->hdr.type) {
101 case RXRPC_PACKET_TYPE_VERSION:
102 if (skb_copy_bits(skb, 0, &v, 1) < 0)
103 return;
104 _proto("Rx VERSION { %02x }", v);
105 if (v == 0)
106 rxrpc_send_version_request(local, &sp->hdr, skb);
107 break;
108
109 default:
110 /* Just ignore anything we don't understand */
111 break;
112 }
113
114 rxrpc_put_local(local);
115 rxrpc_free_skb(skb);
116 }
117
118 rxrpc_put_local(local);
119 _leave("");
120}
diff --git a/net/rxrpc/local_object.c b/net/rxrpc/local_object.c
index 28f9efb3118f..c1b8d745bf5e 100644
--- a/net/rxrpc/local_object.c
+++ b/net/rxrpc/local_object.c
@@ -1,12 +1,12 @@
1/* AF_RXRPC local endpoint management 1/* Local endpoint object management
2 * 2 *
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com) 4 * Written by David Howells (dhowells@redhat.com)
5 * 5 *
6 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version 8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version. 9 * 2 of the Licence, or (at your option) any later version.
10 */ 10 */
11 11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -19,18 +19,14 @@
19#include <linux/ip.h> 19#include <linux/ip.h>
20#include <net/sock.h> 20#include <net/sock.h>
21#include <net/af_rxrpc.h> 21#include <net/af_rxrpc.h>
22#include <generated/utsrelease.h>
23#include "ar-internal.h" 22#include "ar-internal.h"
24 23
25static const char rxrpc_version_string[65] = "linux-" UTS_RELEASE " AF_RXRPC";
26
27static LIST_HEAD(rxrpc_locals); 24static LIST_HEAD(rxrpc_locals);
28DEFINE_RWLOCK(rxrpc_local_lock); 25DEFINE_RWLOCK(rxrpc_local_lock);
29static DECLARE_RWSEM(rxrpc_local_sem); 26static DECLARE_RWSEM(rxrpc_local_sem);
30static DECLARE_WAIT_QUEUE_HEAD(rxrpc_local_wq); 27static DECLARE_WAIT_QUEUE_HEAD(rxrpc_local_wq);
31 28
32static void rxrpc_destroy_local(struct work_struct *work); 29static void rxrpc_destroy_local(struct work_struct *work);
33static void rxrpc_process_local_events(struct work_struct *work);
34 30
35/* 31/*
36 * allocate a new local 32 * allocate a new local
@@ -320,98 +316,3 @@ void __exit rxrpc_destroy_all_locals(void)
320 316
321 _leave(""); 317 _leave("");
322} 318}
323
324/*
325 * Reply to a version request
326 */
327static void rxrpc_send_version_request(struct rxrpc_local *local,
328 struct rxrpc_host_header *hdr,
329 struct sk_buff *skb)
330{
331 struct rxrpc_wire_header whdr;
332 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
333 struct sockaddr_in sin;
334 struct msghdr msg;
335 struct kvec iov[2];
336 size_t len;
337 int ret;
338
339 _enter("");
340
341 sin.sin_family = AF_INET;
342 sin.sin_port = udp_hdr(skb)->source;
343 sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
344
345 msg.msg_name = &sin;
346 msg.msg_namelen = sizeof(sin);
347 msg.msg_control = NULL;
348 msg.msg_controllen = 0;
349 msg.msg_flags = 0;
350
351 whdr.epoch = htonl(sp->hdr.epoch);
352 whdr.cid = htonl(sp->hdr.cid);
353 whdr.callNumber = htonl(sp->hdr.callNumber);
354 whdr.seq = 0;
355 whdr.serial = 0;
356 whdr.type = RXRPC_PACKET_TYPE_VERSION;
357 whdr.flags = RXRPC_LAST_PACKET | (~hdr->flags & RXRPC_CLIENT_INITIATED);
358 whdr.userStatus = 0;
359 whdr.securityIndex = 0;
360 whdr._rsvd = 0;
361 whdr.serviceId = htons(sp->hdr.serviceId);
362
363 iov[0].iov_base = &whdr;
364 iov[0].iov_len = sizeof(whdr);
365 iov[1].iov_base = (char *)rxrpc_version_string;
366 iov[1].iov_len = sizeof(rxrpc_version_string);
367
368 len = iov[0].iov_len + iov[1].iov_len;
369
370 _proto("Tx VERSION (reply)");
371
372 ret = kernel_sendmsg(local->socket, &msg, iov, 2, len);
373 if (ret < 0)
374 _debug("sendmsg failed: %d", ret);
375
376 _leave("");
377}
378
379/*
380 * Process event packets targetted at a local endpoint.
381 */
382static void rxrpc_process_local_events(struct work_struct *work)
383{
384 struct rxrpc_local *local = container_of(work, struct rxrpc_local, event_processor);
385 struct sk_buff *skb;
386 char v;
387
388 _enter("");
389
390 atomic_inc(&local->usage);
391
392 while ((skb = skb_dequeue(&local->event_queue))) {
393 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
394
395 _debug("{%d},{%u}", local->debug_id, sp->hdr.type);
396
397 switch (sp->hdr.type) {
398 case RXRPC_PACKET_TYPE_VERSION:
399 if (skb_copy_bits(skb, 0, &v, 1) < 0)
400 return;
401 _proto("Rx VERSION { %02x }", v);
402 if (v == 0)
403 rxrpc_send_version_request(local, &sp->hdr, skb);
404 break;
405
406 default:
407 /* Just ignore anything we don't understand */
408 break;
409 }
410
411 rxrpc_put_local(local);
412 rxrpc_free_skb(skb);
413 }
414
415 rxrpc_put_local(local);
416 _leave("");
417}