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 <linux/udp.h>
  17. #include <linux/ip.h>
  18. #include <net/sock.h>
  19. #include <net/af_rxrpc.h>
  20. #include <generated/utsrelease.h>
  21. #include "ar-internal.h"
  22. static const char rxrpc_version_string[65] = "linux-" UTS_RELEASE " AF_RXRPC";
  23. /*
  24. * Reply to a version request
  25. */
  26. static void rxrpc_send_version_request(struct rxrpc_local *local,
  27. struct rxrpc_host_header *hdr,
  28. struct sk_buff *skb)
  29. {
  30. struct rxrpc_wire_header whdr;
  31. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  32. struct sockaddr_in sin;
  33. struct msghdr msg;
  34. struct kvec iov[2];
  35. size_t len;
  36. int ret;
  37. _enter("");
  38. sin.sin_family = AF_INET;
  39. sin.sin_port = udp_hdr(skb)->source;
  40. sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
  41. msg.msg_name = &sin;
  42. msg.msg_namelen = sizeof(sin);
  43. msg.msg_control = NULL;
  44. msg.msg_controllen = 0;
  45. msg.msg_flags = 0;
  46. whdr.epoch = htonl(sp->hdr.epoch);
  47. whdr.cid = htonl(sp->hdr.cid);
  48. whdr.callNumber = htonl(sp->hdr.callNumber);
  49. whdr.seq = 0;
  50. whdr.serial = 0;
  51. whdr.type = RXRPC_PACKET_TYPE_VERSION;
  52. whdr.flags = RXRPC_LAST_PACKET | (~hdr->flags & RXRPC_CLIENT_INITIATED);
  53. whdr.userStatus = 0;
  54. whdr.securityIndex = 0;
  55. whdr._rsvd = 0;
  56. whdr.serviceId = htons(sp->hdr.serviceId);
  57. iov[0].iov_base = &whdr;
  58. iov[0].iov_len = sizeof(whdr);
  59. iov[1].iov_base = (char *)rxrpc_version_string;
  60. iov[1].iov_len = sizeof(rxrpc_version_string);
  61. len = iov[0].iov_len + iov[1].iov_len;
  62. _proto("Tx VERSION (reply)");
  63. ret = kernel_sendmsg(local->socket, &msg, iov, 2, len);
  64. if (ret < 0)
  65. _debug("sendmsg failed: %d", ret);
  66. _leave("");
  67. }
  68. /*
  69. * Process event packets targetted at a local endpoint.
  70. */
  71. void rxrpc_process_local_events(struct rxrpc_local *local)
  72. {
  73. struct sk_buff *skb;
  74. char v;
  75. _enter("");
  76. skb = skb_dequeue(&local->event_queue);
  77. if (skb) {
  78. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  79. _debug("{%d},{%u}", local->debug_id, sp->hdr.type);
  80. switch (sp->hdr.type) {
  81. case RXRPC_PACKET_TYPE_VERSION:
  82. if (skb_copy_bits(skb, 0, &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);
  93. }
  94. _leave("");
  95. }