diff options
Diffstat (limited to 'net/rxrpc/ar-local.c')
-rw-r--r-- | net/rxrpc/ar-local.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c index 87f7135d238b..ca904ed5400a 100644 --- a/net/rxrpc/ar-local.c +++ b/net/rxrpc/ar-local.c | |||
@@ -13,16 +13,22 @@ | |||
13 | #include <linux/net.h> | 13 | #include <linux/net.h> |
14 | #include <linux/skbuff.h> | 14 | #include <linux/skbuff.h> |
15 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
16 | #include <linux/udp.h> | ||
17 | #include <linux/ip.h> | ||
16 | #include <net/sock.h> | 18 | #include <net/sock.h> |
17 | #include <net/af_rxrpc.h> | 19 | #include <net/af_rxrpc.h> |
20 | #include <generated/utsrelease.h> | ||
18 | #include "ar-internal.h" | 21 | #include "ar-internal.h" |
19 | 22 | ||
23 | static const char rxrpc_version_string[65] = "linux-" UTS_RELEASE " AF_RXRPC"; | ||
24 | |||
20 | static LIST_HEAD(rxrpc_locals); | 25 | static LIST_HEAD(rxrpc_locals); |
21 | DEFINE_RWLOCK(rxrpc_local_lock); | 26 | DEFINE_RWLOCK(rxrpc_local_lock); |
22 | static DECLARE_RWSEM(rxrpc_local_sem); | 27 | static DECLARE_RWSEM(rxrpc_local_sem); |
23 | static DECLARE_WAIT_QUEUE_HEAD(rxrpc_local_wq); | 28 | static DECLARE_WAIT_QUEUE_HEAD(rxrpc_local_wq); |
24 | 29 | ||
25 | static void rxrpc_destroy_local(struct work_struct *work); | 30 | static void rxrpc_destroy_local(struct work_struct *work); |
31 | static void rxrpc_process_local_events(struct work_struct *work); | ||
26 | 32 | ||
27 | /* | 33 | /* |
28 | * allocate a new local | 34 | * allocate a new local |
@@ -37,11 +43,13 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx) | |||
37 | INIT_WORK(&local->destroyer, &rxrpc_destroy_local); | 43 | INIT_WORK(&local->destroyer, &rxrpc_destroy_local); |
38 | INIT_WORK(&local->acceptor, &rxrpc_accept_incoming_calls); | 44 | INIT_WORK(&local->acceptor, &rxrpc_accept_incoming_calls); |
39 | INIT_WORK(&local->rejecter, &rxrpc_reject_packets); | 45 | INIT_WORK(&local->rejecter, &rxrpc_reject_packets); |
46 | INIT_WORK(&local->event_processor, &rxrpc_process_local_events); | ||
40 | INIT_LIST_HEAD(&local->services); | 47 | INIT_LIST_HEAD(&local->services); |
41 | INIT_LIST_HEAD(&local->link); | 48 | INIT_LIST_HEAD(&local->link); |
42 | init_rwsem(&local->defrag_sem); | 49 | init_rwsem(&local->defrag_sem); |
43 | skb_queue_head_init(&local->accept_queue); | 50 | skb_queue_head_init(&local->accept_queue); |
44 | skb_queue_head_init(&local->reject_queue); | 51 | skb_queue_head_init(&local->reject_queue); |
52 | skb_queue_head_init(&local->event_queue); | ||
45 | spin_lock_init(&local->lock); | 53 | spin_lock_init(&local->lock); |
46 | rwlock_init(&local->services_lock); | 54 | rwlock_init(&local->services_lock); |
47 | atomic_set(&local->usage, 1); | 55 | atomic_set(&local->usage, 1); |
@@ -264,10 +272,12 @@ static void rxrpc_destroy_local(struct work_struct *work) | |||
264 | ASSERT(list_empty(&local->services)); | 272 | ASSERT(list_empty(&local->services)); |
265 | ASSERT(!work_pending(&local->acceptor)); | 273 | ASSERT(!work_pending(&local->acceptor)); |
266 | ASSERT(!work_pending(&local->rejecter)); | 274 | ASSERT(!work_pending(&local->rejecter)); |
275 | ASSERT(!work_pending(&local->event_processor)); | ||
267 | 276 | ||
268 | /* finish cleaning up the local descriptor */ | 277 | /* finish cleaning up the local descriptor */ |
269 | rxrpc_purge_queue(&local->accept_queue); | 278 | rxrpc_purge_queue(&local->accept_queue); |
270 | rxrpc_purge_queue(&local->reject_queue); | 279 | rxrpc_purge_queue(&local->reject_queue); |
280 | rxrpc_purge_queue(&local->event_queue); | ||
271 | kernel_sock_shutdown(local->socket, SHUT_RDWR); | 281 | kernel_sock_shutdown(local->socket, SHUT_RDWR); |
272 | sock_release(local->socket); | 282 | sock_release(local->socket); |
273 | 283 | ||
@@ -308,3 +318,91 @@ void __exit rxrpc_destroy_all_locals(void) | |||
308 | 318 | ||
309 | _leave(""); | 319 | _leave(""); |
310 | } | 320 | } |
321 | |||
322 | /* | ||
323 | * Reply to a version request | ||
324 | */ | ||
325 | static void rxrpc_send_version_request(struct rxrpc_local *local, | ||
326 | struct rxrpc_header *hdr, | ||
327 | struct sk_buff *skb) | ||
328 | { | ||
329 | struct sockaddr_in sin; | ||
330 | struct msghdr msg; | ||
331 | struct kvec iov[2]; | ||
332 | size_t len; | ||
333 | int ret; | ||
334 | |||
335 | _enter(""); | ||
336 | |||
337 | sin.sin_family = AF_INET; | ||
338 | sin.sin_port = udp_hdr(skb)->source; | ||
339 | sin.sin_addr.s_addr = ip_hdr(skb)->saddr; | ||
340 | |||
341 | msg.msg_name = &sin; | ||
342 | msg.msg_namelen = sizeof(sin); | ||
343 | msg.msg_control = NULL; | ||
344 | msg.msg_controllen = 0; | ||
345 | msg.msg_flags = 0; | ||
346 | |||
347 | hdr->seq = 0; | ||
348 | hdr->serial = 0; | ||
349 | hdr->type = RXRPC_PACKET_TYPE_VERSION; | ||
350 | hdr->flags = RXRPC_LAST_PACKET | (~hdr->flags & RXRPC_CLIENT_INITIATED); | ||
351 | hdr->userStatus = 0; | ||
352 | hdr->_rsvd = 0; | ||
353 | |||
354 | iov[0].iov_base = hdr; | ||
355 | iov[0].iov_len = sizeof(*hdr); | ||
356 | iov[1].iov_base = (char *)rxrpc_version_string; | ||
357 | iov[1].iov_len = sizeof(rxrpc_version_string); | ||
358 | |||
359 | len = iov[0].iov_len + iov[1].iov_len; | ||
360 | |||
361 | _proto("Tx VERSION (reply)"); | ||
362 | |||
363 | ret = kernel_sendmsg(local->socket, &msg, iov, 2, len); | ||
364 | if (ret < 0) | ||
365 | _debug("sendmsg failed: %d", ret); | ||
366 | |||
367 | _leave(""); | ||
368 | } | ||
369 | |||
370 | /* | ||
371 | * Process event packets targetted at a local endpoint. | ||
372 | */ | ||
373 | static void rxrpc_process_local_events(struct work_struct *work) | ||
374 | { | ||
375 | struct rxrpc_local *local = container_of(work, struct rxrpc_local, event_processor); | ||
376 | struct sk_buff *skb; | ||
377 | char v; | ||
378 | |||
379 | _enter(""); | ||
380 | |||
381 | atomic_inc(&local->usage); | ||
382 | |||
383 | while ((skb = skb_dequeue(&local->event_queue))) { | ||
384 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); | ||
385 | |||
386 | kdebug("{%d},{%u}", local->debug_id, sp->hdr.type); | ||
387 | |||
388 | switch (sp->hdr.type) { | ||
389 | case RXRPC_PACKET_TYPE_VERSION: | ||
390 | if (skb_copy_bits(skb, 0, &v, 1) < 0) | ||
391 | return; | ||
392 | _proto("Rx VERSION { %02x }", v); | ||
393 | if (v == 0) | ||
394 | rxrpc_send_version_request(local, &sp->hdr, skb); | ||
395 | break; | ||
396 | |||
397 | default: | ||
398 | /* Just ignore anything we don't understand */ | ||
399 | break; | ||
400 | } | ||
401 | |||
402 | rxrpc_put_local(local); | ||
403 | rxrpc_free_skb(skb); | ||
404 | } | ||
405 | |||
406 | rxrpc_put_local(local); | ||
407 | _leave(""); | ||
408 | } | ||