blob: 540d3955c1bcc11652879c7e80630978513cc16e [file] [log] [blame]
David Howells87563612016-04-04 14:00:34 +01001/* 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
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
14#include <linux/module.h>
15#include <linux/net.h>
16#include <linux/skbuff.h>
17#include <linux/slab.h>
David Howells87563612016-04-04 14:00:34 +010018#include <net/sock.h>
19#include <net/af_rxrpc.h>
20#include <generated/utsrelease.h>
21#include "ar-internal.h"
22
23static const char rxrpc_version_string[65] = "linux-" UTS_RELEASE " AF_RXRPC";
24
25/*
26 * Reply to a version request
27 */
28static 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);
David Howells1c2bc7b2016-09-13 08:49:05 +010034 struct sockaddr_rxrpc srx;
David Howells87563612016-04-04 14:00:34 +010035 struct msghdr msg;
36 struct kvec iov[2];
37 size_t len;
38 int ret;
39
40 _enter("");
41
David Howells1c2bc7b2016-09-13 08:49:05 +010042 if (rxrpc_extract_addr_from_skb(&srx, skb) < 0)
43 return;
David Howells87563612016-04-04 14:00:34 +010044
David Howells1c2bc7b2016-09-13 08:49:05 +010045 msg.msg_name = &srx.transport;
46 msg.msg_namelen = srx.transport_len;
David Howells87563612016-04-04 14:00:34 +010047 msg.msg_control = NULL;
48 msg.msg_controllen = 0;
49 msg.msg_flags = 0;
50
51 whdr.epoch = htonl(sp->hdr.epoch);
52 whdr.cid = htonl(sp->hdr.cid);
53 whdr.callNumber = htonl(sp->hdr.callNumber);
54 whdr.seq = 0;
55 whdr.serial = 0;
56 whdr.type = RXRPC_PACKET_TYPE_VERSION;
57 whdr.flags = RXRPC_LAST_PACKET | (~hdr->flags & RXRPC_CLIENT_INITIATED);
58 whdr.userStatus = 0;
59 whdr.securityIndex = 0;
60 whdr._rsvd = 0;
61 whdr.serviceId = htons(sp->hdr.serviceId);
62
63 iov[0].iov_base = &whdr;
64 iov[0].iov_len = sizeof(whdr);
65 iov[1].iov_base = (char *)rxrpc_version_string;
66 iov[1].iov_len = sizeof(rxrpc_version_string);
67
68 len = iov[0].iov_len + iov[1].iov_len;
69
70 _proto("Tx VERSION (reply)");
71
72 ret = kernel_sendmsg(local->socket, &msg, iov, 2, len);
73 if (ret < 0)
74 _debug("sendmsg failed: %d", ret);
75
76 _leave("");
77}
78
79/*
80 * Process event packets targetted at a local endpoint.
81 */
David Howells4f95dd72016-04-04 14:00:35 +010082void rxrpc_process_local_events(struct rxrpc_local *local)
David Howells87563612016-04-04 14:00:34 +010083{
David Howells87563612016-04-04 14:00:34 +010084 struct sk_buff *skb;
85 char v;
86
87 _enter("");
88
David Howells4f95dd72016-04-04 14:00:35 +010089 skb = skb_dequeue(&local->event_queue);
90 if (skb) {
David Howells87563612016-04-04 14:00:34 +010091 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
92
David Howells71f3ca42016-09-17 10:49:14 +010093 rxrpc_see_skb(skb, rxrpc_skb_rx_seen);
David Howells87563612016-04-04 14:00:34 +010094 _debug("{%d},{%u}", local->debug_id, sp->hdr.type);
95
96 switch (sp->hdr.type) {
97 case RXRPC_PACKET_TYPE_VERSION:
David Howells775e5b72016-09-30 13:26:03 +010098 if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header),
99 &v, 1) < 0)
David Howells87563612016-04-04 14:00:34 +0100100 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 Howells71f3ca42016-09-17 10:49:14 +0100111 rxrpc_free_skb(skb, rxrpc_skb_rx_freed);
David Howells87563612016-04-04 14:00:34 +0100112 }
113
David Howells87563612016-04-04 14:00:34 +0100114 _leave("");
115}