Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | 8756361 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 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) |
David Howells | 8756361 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 9 | |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/net.h> |
| 12 | #include <linux/skbuff.h> |
| 13 | #include <linux/slab.h> |
David Howells | 8756361 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 14 | #include <net/sock.h> |
| 15 | #include <net/af_rxrpc.h> |
| 16 | #include <generated/utsrelease.h> |
| 17 | #include "ar-internal.h" |
| 18 | |
| 19 | static const char rxrpc_version_string[65] = "linux-" UTS_RELEASE " AF_RXRPC"; |
| 20 | |
| 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); |
David Howells | 1c2bc7b | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 30 | struct sockaddr_rxrpc srx; |
David Howells | 8756361 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 31 | struct msghdr msg; |
| 32 | struct kvec iov[2]; |
| 33 | size_t len; |
| 34 | int ret; |
| 35 | |
| 36 | _enter(""); |
| 37 | |
David Howells | 5a790b7 | 2018-10-04 09:32:28 +0100 | [diff] [blame] | 38 | if (rxrpc_extract_addr_from_skb(&srx, skb) < 0) |
David Howells | 1c2bc7b | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 39 | return; |
David Howells | 8756361 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 40 | |
David Howells | 1c2bc7b | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 41 | msg.msg_name = &srx.transport; |
| 42 | msg.msg_namelen = srx.transport_len; |
David Howells | 8756361 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 43 | msg.msg_control = NULL; |
| 44 | msg.msg_controllen = 0; |
| 45 | msg.msg_flags = 0; |
| 46 | |
| 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 | |
| 59 | iov[0].iov_base = &whdr; |
| 60 | iov[0].iov_len = sizeof(whdr); |
| 61 | iov[1].iov_base = (char *)rxrpc_version_string; |
| 62 | iov[1].iov_len = sizeof(rxrpc_version_string); |
| 63 | |
| 64 | len = iov[0].iov_len + iov[1].iov_len; |
| 65 | |
| 66 | _proto("Tx VERSION (reply)"); |
| 67 | |
| 68 | ret = kernel_sendmsg(local->socket, &msg, iov, 2, len); |
| 69 | if (ret < 0) |
David Howells | 6b47fe1 | 2018-05-10 23:26:01 +0100 | [diff] [blame] | 70 | trace_rxrpc_tx_fail(local->debug_id, 0, ret, |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 71 | rxrpc_tx_point_version_reply); |
| 72 | else |
| 73 | trace_rxrpc_tx_packet(local->debug_id, &whdr, |
| 74 | rxrpc_tx_point_version_reply); |
David Howells | 8756361 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 75 | |
| 76 | _leave(""); |
| 77 | } |
| 78 | |
| 79 | /* |
Zheng Yongjun | fe6c026 | 2021-06-02 14:55:08 +0800 | [diff] [blame] | 80 | * Process event packets targeted at a local endpoint. |
David Howells | 8756361 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 81 | */ |
David Howells | 4f95dd7 | 2016-04-04 14:00:35 +0100 | [diff] [blame] | 82 | void rxrpc_process_local_events(struct rxrpc_local *local) |
David Howells | 8756361 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 83 | { |
David Howells | 8756361 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 84 | struct sk_buff *skb; |
| 85 | char v; |
| 86 | |
| 87 | _enter(""); |
| 88 | |
David Howells | 4f95dd7 | 2016-04-04 14:00:35 +0100 | [diff] [blame] | 89 | skb = skb_dequeue(&local->event_queue); |
| 90 | if (skb) { |
David Howells | 8756361 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 91 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
| 92 | |
David Howells | 987db9f | 2019-08-19 09:25:38 +0100 | [diff] [blame] | 93 | rxrpc_see_skb(skb, rxrpc_skb_seen); |
David Howells | 8756361 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 94 | _debug("{%d},{%u}", local->debug_id, sp->hdr.type); |
| 95 | |
| 96 | switch (sp->hdr.type) { |
| 97 | case RXRPC_PACKET_TYPE_VERSION: |
David Howells | 775e5b7 | 2016-09-30 13:26:03 +0100 | [diff] [blame] | 98 | if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header), |
| 99 | &v, 1) < 0) |
David Howells | 8756361 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 100 | return; |
| 101 | _proto("Rx VERSION { %02x }", v); |
| 102 | if (v == 0) |
| 103 | rxrpc_send_version_request(local, &sp->hdr, skb); |
| 104 | break; |
| 105 | |
| 106 | default: |
| 107 | /* Just ignore anything we don't understand */ |
| 108 | break; |
| 109 | } |
| 110 | |
David Howells | 987db9f | 2019-08-19 09:25:38 +0100 | [diff] [blame] | 111 | rxrpc_free_skb(skb, rxrpc_skb_freed); |
David Howells | 8756361 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 112 | } |
| 113 | |
David Howells | 8756361 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 114 | _leave(""); |
| 115 | } |