local_event.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* AF_RXRPC local endpoint management
  3. *
  4. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. */
  7. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  8. #include <linux/module.h>
  9. #include <linux/net.h>
  10. #include <linux/skbuff.h>
  11. #include <linux/slab.h>
  12. #include <net/sock.h>
  13. #include <net/af_rxrpc.h>
  14. #include <generated/utsrelease.h>
  15. #include "ar-internal.h"
  16. static char rxrpc_version_string[65]; // "linux-" UTS_RELEASE " AF_RXRPC";
  17. /*
  18. * Generate the VERSION packet string.
  19. */
  20. void rxrpc_gen_version_string(void)
  21. {
  22. snprintf(rxrpc_version_string, sizeof(rxrpc_version_string),
  23. "linux-%.49s AF_RXRPC", UTS_RELEASE);
  24. }
  25. /*
  26. * Reply to a version request
  27. */
  28. void rxrpc_send_version_request(struct rxrpc_local *local,
  29. struct rxrpc_host_header *hdr,
  30. struct sk_buff *skb)
  31. {
  32. struct rxrpc_wire_header whdr;
  33. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  34. struct sockaddr_rxrpc srx;
  35. struct msghdr msg;
  36. struct kvec iov[2];
  37. size_t len;
  38. int ret;
  39. _enter("");
  40. if (rxrpc_extract_addr_from_skb(&srx, skb) < 0)
  41. return;
  42. msg.msg_name = &srx.transport;
  43. msg.msg_namelen = srx.transport_len;
  44. msg.msg_control = NULL;
  45. msg.msg_controllen = 0;
  46. msg.msg_flags = 0;
  47. whdr.epoch = htonl(sp->hdr.epoch);
  48. whdr.cid = htonl(sp->hdr.cid);
  49. whdr.callNumber = htonl(sp->hdr.callNumber);
  50. whdr.seq = 0;
  51. whdr.serial = 0;
  52. whdr.type = RXRPC_PACKET_TYPE_VERSION;
  53. whdr.flags = RXRPC_LAST_PACKET | (~hdr->flags & RXRPC_CLIENT_INITIATED);
  54. whdr.userStatus = 0;
  55. whdr.securityIndex = 0;
  56. whdr._rsvd = 0;
  57. whdr.serviceId = htons(sp->hdr.serviceId);
  58. iov[0].iov_base = &whdr;
  59. iov[0].iov_len = sizeof(whdr);
  60. iov[1].iov_base = (char *)rxrpc_version_string;
  61. iov[1].iov_len = sizeof(rxrpc_version_string);
  62. len = iov[0].iov_len + iov[1].iov_len;
  63. ret = kernel_sendmsg(local->socket, &msg, iov, 2, len);
  64. if (ret < 0)
  65. trace_rxrpc_tx_fail(local->debug_id, 0, ret,
  66. rxrpc_tx_point_version_reply);
  67. else
  68. trace_rxrpc_tx_packet(local->debug_id, &whdr,
  69. rxrpc_tx_point_version_reply);
  70. _leave("");
  71. }