^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* AF_RXRPC local endpoint management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <net/af_rxrpc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <generated/utsrelease.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "ar-internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static const char rxrpc_version_string[65] = "linux-" UTS_RELEASE " AF_RXRPC";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Reply to a version request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static void rxrpc_send_version_request(struct rxrpc_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct rxrpc_host_header *hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct rxrpc_wire_header whdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct sockaddr_rxrpc srx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct msghdr msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct kvec iov[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) _enter("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (rxrpc_extract_addr_from_skb(&srx, skb) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) msg.msg_name = &srx.transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) msg.msg_namelen = srx.transport_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) msg.msg_control = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) msg.msg_controllen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) msg.msg_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) whdr.epoch = htonl(sp->hdr.epoch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) whdr.cid = htonl(sp->hdr.cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) whdr.callNumber = htonl(sp->hdr.callNumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) whdr.seq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) whdr.serial = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) whdr.type = RXRPC_PACKET_TYPE_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) whdr.flags = RXRPC_LAST_PACKET | (~hdr->flags & RXRPC_CLIENT_INITIATED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) whdr.userStatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) whdr.securityIndex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) whdr._rsvd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) whdr.serviceId = htons(sp->hdr.serviceId);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) iov[0].iov_base = &whdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) iov[0].iov_len = sizeof(whdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) iov[1].iov_base = (char *)rxrpc_version_string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) iov[1].iov_len = sizeof(rxrpc_version_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) len = iov[0].iov_len + iov[1].iov_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) _proto("Tx VERSION (reply)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ret = kernel_sendmsg(local->socket, &msg, iov, 2, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) trace_rxrpc_tx_fail(local->debug_id, 0, ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) rxrpc_tx_point_version_reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) trace_rxrpc_tx_packet(local->debug_id, &whdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) rxrpc_tx_point_version_reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) _leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * Process event packets targetted at a local endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) void rxrpc_process_local_events(struct rxrpc_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) char v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) _enter("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) skb = skb_dequeue(&local->event_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) rxrpc_see_skb(skb, rxrpc_skb_seen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) _debug("{%d},{%u}", local->debug_id, sp->hdr.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) switch (sp->hdr.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) case RXRPC_PACKET_TYPE_VERSION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) &v, 1) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) _proto("Rx VERSION { %02x }", v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (v == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) rxrpc_send_version_request(local, &sp->hdr, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* Just ignore anything we don't understand */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) rxrpc_free_skb(skb, rxrpc_skb_freed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) _leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }