local_event.c 2.7 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(&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. _debug("sendmsg failed: %d", ret);
  63. _leave("");
  64. }
  65. /*
  66. * Process event packets targetted at a local endpoint.
  67. */
  68. void rxrpc_process_local_events(struct rxrpc_local *local)
  69. {
  70. struct sk_buff *skb;
  71. char v;
  72. _enter("");
  73. skb = skb_dequeue(&local->event_queue);
  74. if (skb) {
  75. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  76. rxrpc_see_skb(skb, rxrpc_skb_rx_seen);
  77. _debug("{%d},{%u}", local->debug_id, sp->hdr.type);
  78. switch (sp->hdr.type) {
  79. case RXRPC_PACKET_TYPE_VERSION:
  80. if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header),
  81. &v, 1) < 0)
  82. return;
  83. _proto("Rx VERSION { %02x }", v);
  84. if (v == 0)
  85. rxrpc_send_version_request(local, &sp->hdr, skb);
  86. break;
  87. default:
  88. /* Just ignore anything we don't understand */
  89. break;
  90. }
  91. rxrpc_free_skb(skb, rxrpc_skb_rx_freed);
  92. }
  93. _leave("");
  94. }