local_event.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  12. #include <linux/module.h>
  13. #include <linux/net.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/slab.h>
  16. #include <net/sock.h>
  17. #include <net/af_rxrpc.h>
  18. #include <generated/utsrelease.h>
  19. #include "ar-internal.h"
  20. static const char rxrpc_version_string[65] = "linux-" UTS_RELEASE " AF_RXRPC";
  21. /*
  22. * Reply to a version request
  23. */
  24. static void rxrpc_send_version_request(struct rxrpc_local *local,
  25. struct rxrpc_host_header *hdr,
  26. struct sk_buff *skb)
  27. {
  28. struct rxrpc_wire_header whdr;
  29. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  30. struct sockaddr_rxrpc srx;
  31. struct msghdr msg;
  32. struct kvec iov[2];
  33. size_t len;
  34. int ret;
  35. _enter("");
  36. if (rxrpc_extract_addr_from_skb(local, &srx, skb) < 0)
  37. return;
  38. msg.msg_name = &srx.transport;
  39. msg.msg_namelen = srx.transport_len;
  40. msg.msg_control = NULL;
  41. msg.msg_controllen = 0;
  42. msg.msg_flags = 0;
  43. whdr.epoch = htonl(sp->hdr.epoch);
  44. whdr.cid = htonl(sp->hdr.cid);
  45. whdr.callNumber = htonl(sp->hdr.callNumber);
  46. whdr.seq = 0;
  47. whdr.serial = 0;
  48. whdr.type = RXRPC_PACKET_TYPE_VERSION;
  49. whdr.flags = RXRPC_LAST_PACKET | (~hdr->flags & RXRPC_CLIENT_INITIATED);
  50. whdr.userStatus = 0;
  51. whdr.securityIndex = 0;
  52. whdr._rsvd = 0;
  53. whdr.serviceId = htons(sp->hdr.serviceId);
  54. iov[0].iov_base = &whdr;
  55. iov[0].iov_len = sizeof(whdr);
  56. iov[1].iov_base = (char *)rxrpc_version_string;
  57. iov[1].iov_len = sizeof(rxrpc_version_string);
  58. len = iov[0].iov_len + iov[1].iov_len;
  59. _proto("Tx VERSION (reply)");
  60. ret = kernel_sendmsg(local->socket, &msg, iov, 2, len);
  61. if (ret < 0)
  62. trace_rxrpc_tx_fail(local->debug_id, 0, ret,
  63. rxrpc_tx_fail_version_reply);
  64. _leave("");
  65. }
  66. /*
  67. * Process event packets targetted at a local endpoint.
  68. */
  69. void rxrpc_process_local_events(struct rxrpc_local *local)
  70. {
  71. struct sk_buff *skb;
  72. char v;
  73. _enter("");
  74. skb = skb_dequeue(&local->event_queue);
  75. if (skb) {
  76. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  77. rxrpc_see_skb(skb, rxrpc_skb_rx_seen);
  78. _debug("{%d},{%u}", local->debug_id, sp->hdr.type);
  79. switch (sp->hdr.type) {
  80. case RXRPC_PACKET_TYPE_VERSION:
  81. if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header),
  82. &v, 1) < 0)
  83. return;
  84. _proto("Rx VERSION { %02x }", v);
  85. if (v == 0)
  86. rxrpc_send_version_request(local, &sp->hdr, skb);
  87. break;
  88. default:
  89. /* Just ignore anything we don't understand */
  90. break;
  91. }
  92. rxrpc_free_skb(skb, rxrpc_skb_rx_freed);
  93. }
  94. _leave("");
  95. }