Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Shared Memory Communications over RDMA (SMC-R) and RoCE |
| 4 | * |
| 5 | * CLC (connection layer control) handshake over initial TCP socket to |
| 6 | * prepare for RDMA traffic |
| 7 | * |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 8 | * Copyright IBM Corp. 2016, 2018 |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 9 | * |
| 10 | * Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com> |
| 11 | */ |
| 12 | |
| 13 | #include <linux/in.h> |
Karsten Graul | 696cd30 | 2018-03-01 13:51:27 +0100 | [diff] [blame] | 14 | #include <linux/inetdevice.h> |
Ursula Braun | 143c017 | 2017-01-12 14:57:15 +0100 | [diff] [blame] | 15 | #include <linux/if_ether.h> |
Ingo Molnar | c3edc40 | 2017-02-02 08:35:14 +0100 | [diff] [blame] | 16 | #include <linux/sched/signal.h> |
| 17 | |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 18 | #include <net/addrconf.h> |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 19 | #include <net/sock.h> |
| 20 | #include <net/tcp.h> |
| 21 | |
| 22 | #include "smc.h" |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 23 | #include "smc_core.h" |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 24 | #include "smc_clc.h" |
| 25 | #include "smc_ib.h" |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 26 | #include "smc_ism.h" |
| 27 | |
| 28 | #define SMCR_CLC_ACCEPT_CONFIRM_LEN 68 |
| 29 | #define SMCD_CLC_ACCEPT_CONFIRM_LEN 48 |
Ursula Braun | fb4f792 | 2020-07-08 17:05:15 +0200 | [diff] [blame] | 30 | #define SMC_CLC_RECV_BUF_LEN 100 |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 31 | |
Stefan Raspl | 0f62712 | 2018-03-01 13:51:26 +0100 | [diff] [blame] | 32 | /* eye catcher "SMCR" EBCDIC for CLC messages */ |
| 33 | static const char SMC_EYECATCHER[4] = {'\xe2', '\xd4', '\xc3', '\xd9'}; |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 34 | /* eye catcher "SMCD" EBCDIC for CLC messages */ |
| 35 | static const char SMCD_EYECATCHER[4] = {'\xe2', '\xd4', '\xc3', '\xc4'}; |
Stefan Raspl | 0f62712 | 2018-03-01 13:51:26 +0100 | [diff] [blame] | 36 | |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 37 | /* check if received message has a correct header length and contains valid |
| 38 | * heading and trailing eyecatchers |
| 39 | */ |
Ursula Braun | fb4f792 | 2020-07-08 17:05:15 +0200 | [diff] [blame] | 40 | static bool smc_clc_msg_hdr_valid(struct smc_clc_msg_hdr *clcm, bool check_trl) |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 41 | { |
| 42 | struct smc_clc_msg_proposal_prefix *pclc_prfx; |
| 43 | struct smc_clc_msg_accept_confirm *clc; |
| 44 | struct smc_clc_msg_proposal *pclc; |
| 45 | struct smc_clc_msg_decline *dclc; |
| 46 | struct smc_clc_msg_trail *trl; |
| 47 | |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 48 | if (memcmp(clcm->eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)) && |
| 49 | memcmp(clcm->eyecatcher, SMCD_EYECATCHER, sizeof(SMCD_EYECATCHER))) |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 50 | return false; |
| 51 | switch (clcm->type) { |
| 52 | case SMC_CLC_PROPOSAL: |
| 53 | pclc = (struct smc_clc_msg_proposal *)clcm; |
| 54 | pclc_prfx = smc_clc_proposal_get_prefix(pclc); |
Ursula Braun | fb4f792 | 2020-07-08 17:05:15 +0200 | [diff] [blame] | 55 | if (ntohs(pclc->hdr.length) < |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 56 | sizeof(*pclc) + ntohs(pclc->iparea_offset) + |
| 57 | sizeof(*pclc_prfx) + |
| 58 | pclc_prfx->ipv6_prefixes_cnt * |
| 59 | sizeof(struct smc_clc_ipv6_prefix) + |
| 60 | sizeof(*trl)) |
| 61 | return false; |
| 62 | trl = (struct smc_clc_msg_trail *) |
| 63 | ((u8 *)pclc + ntohs(pclc->hdr.length) - sizeof(*trl)); |
| 64 | break; |
| 65 | case SMC_CLC_ACCEPT: |
| 66 | case SMC_CLC_CONFIRM: |
Ursula Braun | f1eb02f | 2020-09-26 12:44:20 +0200 | [diff] [blame] | 67 | if (clcm->typev1 != SMC_TYPE_R && clcm->typev1 != SMC_TYPE_D) |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 68 | return false; |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 69 | clc = (struct smc_clc_msg_accept_confirm *)clcm; |
Ursula Braun | f1eb02f | 2020-09-26 12:44:20 +0200 | [diff] [blame] | 70 | if ((clcm->typev1 == SMC_TYPE_R && |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 71 | ntohs(clc->hdr.length) != SMCR_CLC_ACCEPT_CONFIRM_LEN) || |
Ursula Braun | f1eb02f | 2020-09-26 12:44:20 +0200 | [diff] [blame] | 72 | (clcm->typev1 == SMC_TYPE_D && |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 73 | ntohs(clc->hdr.length) != SMCD_CLC_ACCEPT_CONFIRM_LEN)) |
| 74 | return false; |
| 75 | trl = (struct smc_clc_msg_trail *) |
| 76 | ((u8 *)clc + ntohs(clc->hdr.length) - sizeof(*trl)); |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 77 | break; |
| 78 | case SMC_CLC_DECLINE: |
| 79 | dclc = (struct smc_clc_msg_decline *)clcm; |
| 80 | if (ntohs(dclc->hdr.length) != sizeof(*dclc)) |
| 81 | return false; |
| 82 | trl = &dclc->trl; |
| 83 | break; |
| 84 | default: |
| 85 | return false; |
| 86 | } |
Ursula Braun | fb4f792 | 2020-07-08 17:05:15 +0200 | [diff] [blame] | 87 | if (check_trl && |
| 88 | memcmp(trl->eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)) && |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 89 | memcmp(trl->eyecatcher, SMCD_EYECATCHER, sizeof(SMCD_EYECATCHER))) |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 90 | return false; |
| 91 | return true; |
| 92 | } |
| 93 | |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 94 | /* find ipv4 addr on device and get the prefix len, fill CLC proposal msg */ |
| 95 | static int smc_clc_prfx_set4_rcu(struct dst_entry *dst, __be32 ipv4, |
| 96 | struct smc_clc_msg_proposal_prefix *prop) |
| 97 | { |
| 98 | struct in_device *in_dev = __in_dev_get_rcu(dst->dev); |
Florian Westphal | cd5a411 | 2019-05-31 18:27:07 +0200 | [diff] [blame] | 99 | const struct in_ifaddr *ifa; |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 100 | |
| 101 | if (!in_dev) |
| 102 | return -ENODEV; |
Florian Westphal | cd5a411 | 2019-05-31 18:27:07 +0200 | [diff] [blame] | 103 | |
| 104 | in_dev_for_each_ifa_rcu(ifa, in_dev) { |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 105 | if (!inet_ifa_match(ipv4, ifa)) |
| 106 | continue; |
| 107 | prop->prefix_len = inet_mask_len(ifa->ifa_mask); |
| 108 | prop->outgoing_subnet = ifa->ifa_address & ifa->ifa_mask; |
| 109 | /* prop->ipv6_prefixes_cnt = 0; already done by memset before */ |
| 110 | return 0; |
Florian Westphal | cd5a411 | 2019-05-31 18:27:07 +0200 | [diff] [blame] | 111 | } |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 112 | return -ENOENT; |
| 113 | } |
| 114 | |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 115 | /* fill CLC proposal msg with ipv6 prefixes from device */ |
| 116 | static int smc_clc_prfx_set6_rcu(struct dst_entry *dst, |
| 117 | struct smc_clc_msg_proposal_prefix *prop, |
| 118 | struct smc_clc_ipv6_prefix *ipv6_prfx) |
| 119 | { |
| 120 | #if IS_ENABLED(CONFIG_IPV6) |
| 121 | struct inet6_dev *in6_dev = __in6_dev_get(dst->dev); |
| 122 | struct inet6_ifaddr *ifa; |
| 123 | int cnt = 0; |
| 124 | |
| 125 | if (!in6_dev) |
| 126 | return -ENODEV; |
| 127 | /* use a maximum of 8 IPv6 prefixes from device */ |
| 128 | list_for_each_entry(ifa, &in6_dev->addr_list, if_list) { |
| 129 | if (ipv6_addr_type(&ifa->addr) & IPV6_ADDR_LINKLOCAL) |
| 130 | continue; |
| 131 | ipv6_addr_prefix(&ipv6_prfx[cnt].prefix, |
| 132 | &ifa->addr, ifa->prefix_len); |
| 133 | ipv6_prfx[cnt].prefix_len = ifa->prefix_len; |
| 134 | cnt++; |
| 135 | if (cnt == SMC_CLC_MAX_V6_PREFIX) |
| 136 | break; |
| 137 | } |
| 138 | prop->ipv6_prefixes_cnt = cnt; |
| 139 | if (cnt) |
| 140 | return 0; |
| 141 | #endif |
| 142 | return -ENOENT; |
| 143 | } |
| 144 | |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 145 | /* retrieve and set prefixes in CLC proposal msg */ |
| 146 | static int smc_clc_prfx_set(struct socket *clcsock, |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 147 | struct smc_clc_msg_proposal_prefix *prop, |
| 148 | struct smc_clc_ipv6_prefix *ipv6_prfx) |
Karsten Graul | 696cd30 | 2018-03-01 13:51:27 +0100 | [diff] [blame] | 149 | { |
| 150 | struct dst_entry *dst = sk_dst_get(clcsock->sk); |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 151 | struct sockaddr_storage addrs; |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 152 | struct sockaddr_in6 *addr6; |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 153 | struct sockaddr_in *addr; |
| 154 | int rc = -ENOENT; |
| 155 | |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 156 | if (!dst) { |
| 157 | rc = -ENOTCONN; |
| 158 | goto out; |
| 159 | } |
| 160 | if (!dst->dev) { |
| 161 | rc = -ENODEV; |
| 162 | goto out_rel; |
| 163 | } |
| 164 | /* get address to which the internal TCP socket is bound */ |
| 165 | kernel_getsockname(clcsock, (struct sockaddr *)&addrs); |
| 166 | /* analyze IP specific data of net_device belonging to TCP socket */ |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 167 | addr6 = (struct sockaddr_in6 *)&addrs; |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 168 | rcu_read_lock(); |
| 169 | if (addrs.ss_family == PF_INET) { |
| 170 | /* IPv4 */ |
| 171 | addr = (struct sockaddr_in *)&addrs; |
| 172 | rc = smc_clc_prfx_set4_rcu(dst, addr->sin_addr.s_addr, prop); |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 173 | } else if (ipv6_addr_v4mapped(&addr6->sin6_addr)) { |
| 174 | /* mapped IPv4 address - peer is IPv4 only */ |
| 175 | rc = smc_clc_prfx_set4_rcu(dst, addr6->sin6_addr.s6_addr32[3], |
| 176 | prop); |
| 177 | } else { |
| 178 | /* IPv6 */ |
| 179 | rc = smc_clc_prfx_set6_rcu(dst, prop, ipv6_prfx); |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 180 | } |
| 181 | rcu_read_unlock(); |
| 182 | out_rel: |
| 183 | dst_release(dst); |
| 184 | out: |
| 185 | return rc; |
| 186 | } |
| 187 | |
| 188 | /* match ipv4 addrs of dev against addr in CLC proposal */ |
| 189 | static int smc_clc_prfx_match4_rcu(struct net_device *dev, |
| 190 | struct smc_clc_msg_proposal_prefix *prop) |
| 191 | { |
| 192 | struct in_device *in_dev = __in_dev_get_rcu(dev); |
Florian Westphal | cd5a411 | 2019-05-31 18:27:07 +0200 | [diff] [blame] | 193 | const struct in_ifaddr *ifa; |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 194 | |
| 195 | if (!in_dev) |
| 196 | return -ENODEV; |
Florian Westphal | cd5a411 | 2019-05-31 18:27:07 +0200 | [diff] [blame] | 197 | in_dev_for_each_ifa_rcu(ifa, in_dev) { |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 198 | if (prop->prefix_len == inet_mask_len(ifa->ifa_mask) && |
| 199 | inet_ifa_match(prop->outgoing_subnet, ifa)) |
| 200 | return 0; |
Florian Westphal | cd5a411 | 2019-05-31 18:27:07 +0200 | [diff] [blame] | 201 | } |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 202 | |
| 203 | return -ENOENT; |
| 204 | } |
| 205 | |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 206 | /* match ipv6 addrs of dev against addrs in CLC proposal */ |
| 207 | static int smc_clc_prfx_match6_rcu(struct net_device *dev, |
| 208 | struct smc_clc_msg_proposal_prefix *prop) |
| 209 | { |
| 210 | #if IS_ENABLED(CONFIG_IPV6) |
| 211 | struct inet6_dev *in6_dev = __in6_dev_get(dev); |
| 212 | struct smc_clc_ipv6_prefix *ipv6_prfx; |
| 213 | struct inet6_ifaddr *ifa; |
| 214 | int i, max; |
| 215 | |
| 216 | if (!in6_dev) |
| 217 | return -ENODEV; |
| 218 | /* ipv6 prefix list starts behind smc_clc_msg_proposal_prefix */ |
| 219 | ipv6_prfx = (struct smc_clc_ipv6_prefix *)((u8 *)prop + sizeof(*prop)); |
| 220 | max = min_t(u8, prop->ipv6_prefixes_cnt, SMC_CLC_MAX_V6_PREFIX); |
| 221 | list_for_each_entry(ifa, &in6_dev->addr_list, if_list) { |
| 222 | if (ipv6_addr_type(&ifa->addr) & IPV6_ADDR_LINKLOCAL) |
| 223 | continue; |
| 224 | for (i = 0; i < max; i++) { |
| 225 | if (ifa->prefix_len == ipv6_prfx[i].prefix_len && |
| 226 | ipv6_prefix_equal(&ifa->addr, &ipv6_prfx[i].prefix, |
| 227 | ifa->prefix_len)) |
| 228 | return 0; |
| 229 | } |
| 230 | } |
| 231 | #endif |
| 232 | return -ENOENT; |
| 233 | } |
| 234 | |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 235 | /* check if proposed prefixes match one of our device prefixes */ |
| 236 | int smc_clc_prfx_match(struct socket *clcsock, |
| 237 | struct smc_clc_msg_proposal_prefix *prop) |
| 238 | { |
| 239 | struct dst_entry *dst = sk_dst_get(clcsock->sk); |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 240 | int rc; |
Karsten Graul | 696cd30 | 2018-03-01 13:51:27 +0100 | [diff] [blame] | 241 | |
| 242 | if (!dst) { |
| 243 | rc = -ENOTCONN; |
| 244 | goto out; |
| 245 | } |
| 246 | if (!dst->dev) { |
| 247 | rc = -ENODEV; |
| 248 | goto out_rel; |
| 249 | } |
Karsten Graul | 696cd30 | 2018-03-01 13:51:27 +0100 | [diff] [blame] | 250 | rcu_read_lock(); |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 251 | if (!prop->ipv6_prefixes_cnt) |
| 252 | rc = smc_clc_prfx_match4_rcu(dst->dev, prop); |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 253 | else |
| 254 | rc = smc_clc_prfx_match6_rcu(dst->dev, prop); |
Karsten Graul | 696cd30 | 2018-03-01 13:51:27 +0100 | [diff] [blame] | 255 | rcu_read_unlock(); |
Karsten Graul | 696cd30 | 2018-03-01 13:51:27 +0100 | [diff] [blame] | 256 | out_rel: |
| 257 | dst_release(dst); |
| 258 | out: |
| 259 | return rc; |
| 260 | } |
| 261 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 262 | /* Wait for data on the tcp-socket, analyze received data |
| 263 | * Returns: |
| 264 | * 0 if success and it was not a decline that we received. |
| 265 | * SMC_CLC_DECL_REPLY if decline received for fallback w/o another decl send. |
| 266 | * clcsock error, -EINTR, -ECONNRESET, -EPROTO otherwise. |
| 267 | */ |
| 268 | int smc_clc_wait_msg(struct smc_sock *smc, void *buf, int buflen, |
Ursula Braun | 2b59f58 | 2018-11-22 10:26:39 +0100 | [diff] [blame] | 269 | u8 expected_type, unsigned long timeout) |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 270 | { |
Karsten Graul | f6bdc42 | 2018-07-18 15:22:51 +0200 | [diff] [blame] | 271 | long rcvtimeo = smc->clcsock->sk->sk_rcvtimeo; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 272 | struct sock *clc_sk = smc->clcsock->sk; |
| 273 | struct smc_clc_msg_hdr *clcm = buf; |
| 274 | struct msghdr msg = {NULL, 0}; |
| 275 | int reason_code = 0; |
Al Viro | d63d271 | 2017-09-20 20:21:22 -0400 | [diff] [blame] | 276 | struct kvec vec = {buf, buflen}; |
Ursula Braun | fb4f792 | 2020-07-08 17:05:15 +0200 | [diff] [blame] | 277 | int len, datlen, recvlen; |
| 278 | bool check_trl = true; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 279 | int krflags; |
| 280 | |
| 281 | /* peek the first few bytes to determine length of data to receive |
| 282 | * so we don't consume any subsequent CLC message or payload data |
| 283 | * in the TCP byte stream |
| 284 | */ |
Al Viro | d63d271 | 2017-09-20 20:21:22 -0400 | [diff] [blame] | 285 | /* |
| 286 | * Caller must make sure that buflen is no less than |
| 287 | * sizeof(struct smc_clc_msg_hdr) |
| 288 | */ |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 289 | krflags = MSG_PEEK | MSG_WAITALL; |
Ursula Braun | 2b59f58 | 2018-11-22 10:26:39 +0100 | [diff] [blame] | 290 | clc_sk->sk_rcvtimeo = timeout; |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 291 | iov_iter_kvec(&msg.msg_iter, READ, &vec, 1, |
Al Viro | d63d271 | 2017-09-20 20:21:22 -0400 | [diff] [blame] | 292 | sizeof(struct smc_clc_msg_hdr)); |
| 293 | len = sock_recvmsg(smc->clcsock, &msg, krflags); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 294 | if (signal_pending(current)) { |
| 295 | reason_code = -EINTR; |
| 296 | clc_sk->sk_err = EINTR; |
| 297 | smc->sk.sk_err = EINTR; |
| 298 | goto out; |
| 299 | } |
| 300 | if (clc_sk->sk_err) { |
| 301 | reason_code = -clc_sk->sk_err; |
Ursula Braun | 9ed2855 | 2018-11-22 10:26:37 +0100 | [diff] [blame] | 302 | if (clc_sk->sk_err == EAGAIN && |
| 303 | expected_type == SMC_CLC_DECLINE) |
| 304 | clc_sk->sk_err = 0; /* reset for fallback usage */ |
| 305 | else |
| 306 | smc->sk.sk_err = clc_sk->sk_err; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 307 | goto out; |
| 308 | } |
| 309 | if (!len) { /* peer has performed orderly shutdown */ |
| 310 | smc->sk.sk_err = ECONNRESET; |
| 311 | reason_code = -ECONNRESET; |
| 312 | goto out; |
| 313 | } |
| 314 | if (len < 0) { |
Ursula Braun | 9ed2855 | 2018-11-22 10:26:37 +0100 | [diff] [blame] | 315 | if (len != -EAGAIN || expected_type != SMC_CLC_DECLINE) |
| 316 | smc->sk.sk_err = -len; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 317 | reason_code = len; |
| 318 | goto out; |
| 319 | } |
| 320 | datlen = ntohs(clcm->length); |
| 321 | if ((len < sizeof(struct smc_clc_msg_hdr)) || |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 322 | (clcm->version < SMC_V1) || |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 323 | ((clcm->type != SMC_CLC_DECLINE) && |
| 324 | (clcm->type != expected_type))) { |
| 325 | smc->sk.sk_err = EPROTO; |
| 326 | reason_code = -EPROTO; |
| 327 | goto out; |
| 328 | } |
| 329 | |
Ursula Braun | f1eb02f | 2020-09-26 12:44:20 +0200 | [diff] [blame] | 330 | if (clcm->type == SMC_CLC_PROPOSAL && clcm->typev1 == SMC_TYPE_N) |
Ursula Braun | fb4f792 | 2020-07-08 17:05:15 +0200 | [diff] [blame] | 331 | reason_code = SMC_CLC_DECL_VERSMISMAT; /* just V2 offered */ |
| 332 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 333 | /* receive the complete CLC message */ |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 334 | memset(&msg, 0, sizeof(struct msghdr)); |
Ursula Braun | fb4f792 | 2020-07-08 17:05:15 +0200 | [diff] [blame] | 335 | if (datlen > buflen) { |
| 336 | check_trl = false; |
| 337 | recvlen = buflen; |
| 338 | } else { |
| 339 | recvlen = datlen; |
| 340 | } |
| 341 | iov_iter_kvec(&msg.msg_iter, READ, &vec, 1, recvlen); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 342 | krflags = MSG_WAITALL; |
Al Viro | d63d271 | 2017-09-20 20:21:22 -0400 | [diff] [blame] | 343 | len = sock_recvmsg(smc->clcsock, &msg, krflags); |
Ursula Braun | fb4f792 | 2020-07-08 17:05:15 +0200 | [diff] [blame] | 344 | if (len < recvlen || !smc_clc_msg_hdr_valid(clcm, check_trl)) { |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 345 | smc->sk.sk_err = EPROTO; |
| 346 | reason_code = -EPROTO; |
| 347 | goto out; |
| 348 | } |
Ursula Braun | fb4f792 | 2020-07-08 17:05:15 +0200 | [diff] [blame] | 349 | datlen -= len; |
| 350 | while (datlen) { |
| 351 | u8 tmp[SMC_CLC_RECV_BUF_LEN]; |
| 352 | |
| 353 | vec.iov_base = &tmp; |
| 354 | vec.iov_len = SMC_CLC_RECV_BUF_LEN; |
| 355 | /* receive remaining proposal message */ |
| 356 | recvlen = datlen > SMC_CLC_RECV_BUF_LEN ? |
| 357 | SMC_CLC_RECV_BUF_LEN : datlen; |
| 358 | iov_iter_kvec(&msg.msg_iter, READ, &vec, 1, recvlen); |
| 359 | len = sock_recvmsg(smc->clcsock, &msg, krflags); |
| 360 | datlen -= len; |
| 361 | } |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 362 | if (clcm->type == SMC_CLC_DECLINE) { |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 363 | struct smc_clc_msg_decline *dclc; |
| 364 | |
| 365 | dclc = (struct smc_clc_msg_decline *)clcm; |
| 366 | reason_code = SMC_CLC_DECL_PEERDECL; |
| 367 | smc->peer_diagnosis = ntohl(dclc->peer_diagnosis); |
Ursula Braun | f1eb02f | 2020-09-26 12:44:20 +0200 | [diff] [blame] | 368 | if (((struct smc_clc_msg_decline *)buf)->hdr.typev2 & |
| 369 | SMC_FIRST_CONTACT_MASK) { |
Karsten Graul | 517c300 | 2018-05-15 17:05:03 +0200 | [diff] [blame] | 370 | smc->conn.lgr->sync_err = 1; |
Karsten Graul | 5f78fe9 | 2020-02-17 16:24:54 +0100 | [diff] [blame] | 371 | smc_lgr_terminate_sched(smc->conn.lgr); |
Ursula Braun | bfbedfd | 2017-09-21 09:16:32 +0200 | [diff] [blame] | 372 | } |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 373 | } |
| 374 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 375 | out: |
Ursula Braun | 2b59f58 | 2018-11-22 10:26:39 +0100 | [diff] [blame] | 376 | clc_sk->sk_rcvtimeo = rcvtimeo; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 377 | return reason_code; |
| 378 | } |
| 379 | |
| 380 | /* send CLC DECLINE message across internal TCP socket */ |
Ursula Braun | bfbedfd | 2017-09-21 09:16:32 +0200 | [diff] [blame] | 381 | int smc_clc_send_decline(struct smc_sock *smc, u32 peer_diag_info) |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 382 | { |
| 383 | struct smc_clc_msg_decline dclc; |
| 384 | struct msghdr msg; |
| 385 | struct kvec vec; |
| 386 | int len; |
| 387 | |
| 388 | memset(&dclc, 0, sizeof(dclc)); |
| 389 | memcpy(dclc.hdr.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
| 390 | dclc.hdr.type = SMC_CLC_DECLINE; |
| 391 | dclc.hdr.length = htons(sizeof(struct smc_clc_msg_decline)); |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 392 | dclc.hdr.version = SMC_V1; |
Ursula Braun | f1eb02f | 2020-09-26 12:44:20 +0200 | [diff] [blame] | 393 | dclc.hdr.typev2 = (peer_diag_info == SMC_CLC_DECL_SYNCERR) ? |
| 394 | SMC_FIRST_CONTACT_MASK : 0; |
Hans Wippel | a082ec8 | 2020-02-25 22:41:22 +0100 | [diff] [blame] | 395 | if ((!smc->conn.lgr || !smc->conn.lgr->is_smcd) && |
| 396 | smc_ib_is_valid_local_systemid()) |
Ursula Braun | 369537c | 2020-02-14 08:59:00 +0100 | [diff] [blame] | 397 | memcpy(dclc.id_for_peer, local_systemid, |
| 398 | sizeof(local_systemid)); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 399 | dclc.peer_diagnosis = htonl(peer_diag_info); |
| 400 | memcpy(dclc.trl.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
| 401 | |
| 402 | memset(&msg, 0, sizeof(msg)); |
| 403 | vec.iov_base = &dclc; |
| 404 | vec.iov_len = sizeof(struct smc_clc_msg_decline); |
| 405 | len = kernel_sendmsg(smc->clcsock, &msg, &vec, 1, |
| 406 | sizeof(struct smc_clc_msg_decline)); |
Ursula Braun | 14d22d4 | 2019-01-30 18:51:00 +0100 | [diff] [blame] | 407 | if (len < 0 || len < sizeof(struct smc_clc_msg_decline)) |
Ursula Braun | 6ae36bf | 2018-11-22 10:26:36 +0100 | [diff] [blame] | 408 | len = -EPROTO; |
| 409 | return len > 0 ? 0 : len; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | /* send CLC PROPOSAL message across internal TCP socket */ |
Ursula Braun | d70bf4f | 2020-09-26 12:44:27 +0200 | [diff] [blame^] | 413 | int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini) |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 414 | { |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 415 | struct smc_clc_msg_proposal_prefix *pclc_prfx; |
| 416 | struct smc_clc_msg_proposal *pclc_base; |
| 417 | struct smc_clc_msg_proposal_area *pclc; |
| 418 | struct smc_clc_ipv6_prefix *ipv6_prfx; |
| 419 | struct smc_clc_msg_smcd *pclc_smcd; |
| 420 | struct smc_clc_msg_trail *trl; |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 421 | int len, i, plen, rc; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 422 | int reason_code = 0; |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 423 | struct kvec vec[5]; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 424 | struct msghdr msg; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 425 | |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 426 | pclc = kzalloc(sizeof(*pclc), GFP_KERNEL); |
| 427 | if (!pclc) |
| 428 | return -ENOMEM; |
| 429 | |
| 430 | pclc_base = &pclc->pclc_base; |
| 431 | pclc_smcd = &pclc->pclc_smcd; |
| 432 | pclc_prfx = &pclc->pclc_prfx; |
| 433 | ipv6_prfx = pclc->pclc_prfx_ipv6; |
| 434 | trl = &pclc->pclc_trl; |
| 435 | |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 436 | /* retrieve ip prefixes for CLC proposal msg */ |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 437 | rc = smc_clc_prfx_set(smc->clcsock, pclc_prfx, ipv6_prfx); |
| 438 | if (rc) { |
| 439 | kfree(pclc); |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 440 | return SMC_CLC_DECL_CNFERR; /* configuration error */ |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 441 | } |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 442 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 443 | /* send SMC Proposal CLC message */ |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 444 | plen = sizeof(*pclc_base) + sizeof(*pclc_prfx) + |
| 445 | (pclc_prfx->ipv6_prefixes_cnt * sizeof(ipv6_prfx[0])) + |
| 446 | sizeof(*trl); |
| 447 | memcpy(pclc_base->hdr.eyecatcher, SMC_EYECATCHER, |
| 448 | sizeof(SMC_EYECATCHER)); |
| 449 | pclc_base->hdr.type = SMC_CLC_PROPOSAL; |
| 450 | pclc_base->hdr.version = SMC_V1; /* SMC version */ |
Ursula Braun | d70bf4f | 2020-09-26 12:44:27 +0200 | [diff] [blame^] | 451 | pclc_base->hdr.typev1 = ini->smc_type_v1; |
| 452 | if (smcr_indicated(ini->smc_type_v1)) { |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 453 | /* add SMC-R specifics */ |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 454 | memcpy(pclc_base->lcl.id_for_peer, local_systemid, |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 455 | sizeof(local_systemid)); |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 456 | memcpy(pclc_base->lcl.gid, ini->ib_gid, SMC_GID_SIZE); |
| 457 | memcpy(pclc_base->lcl.mac, &ini->ib_dev->mac[ini->ib_port - 1], |
Karsten Graul | bc36d2f | 2019-04-12 12:57:26 +0200 | [diff] [blame] | 458 | ETH_ALEN); |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 459 | pclc_base->iparea_offset = htons(0); |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 460 | } |
Ursula Braun | d70bf4f | 2020-09-26 12:44:27 +0200 | [diff] [blame^] | 461 | if (smcd_indicated(ini->smc_type_v1)) { |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 462 | /* add SMC-D specifics */ |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 463 | plen += sizeof(*pclc_smcd); |
| 464 | pclc_base->iparea_offset = htons(sizeof(*pclc_smcd)); |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 465 | pclc_smcd->gid = ini->ism_dev[0]->local_gid; |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 466 | } |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 467 | pclc_base->hdr.length = htons(plen); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 468 | |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 469 | memcpy(trl->eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 470 | memset(&msg, 0, sizeof(msg)); |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 471 | i = 0; |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 472 | vec[i].iov_base = pclc_base; |
| 473 | vec[i++].iov_len = sizeof(*pclc_base); |
Ursula Braun | d70bf4f | 2020-09-26 12:44:27 +0200 | [diff] [blame^] | 474 | if (smcd_indicated(ini->smc_type_v1)) { |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 475 | vec[i].iov_base = pclc_smcd; |
| 476 | vec[i++].iov_len = sizeof(*pclc_smcd); |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 477 | } |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 478 | vec[i].iov_base = pclc_prfx; |
| 479 | vec[i++].iov_len = sizeof(*pclc_prfx); |
| 480 | if (pclc_prfx->ipv6_prefixes_cnt > 0) { |
| 481 | vec[i].iov_base = ipv6_prfx; |
| 482 | vec[i++].iov_len = pclc_prfx->ipv6_prefixes_cnt * |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 483 | sizeof(ipv6_prfx[0]); |
| 484 | } |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 485 | vec[i].iov_base = trl; |
| 486 | vec[i++].iov_len = sizeof(*trl); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 487 | /* due to the few bytes needed for clc-handshake this cannot block */ |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 488 | len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen); |
YueHaibing | 3818977 | 2018-09-18 15:46:38 +0200 | [diff] [blame] | 489 | if (len < 0) { |
| 490 | smc->sk.sk_err = smc->clcsock->sk->sk_err; |
| 491 | reason_code = -smc->sk.sk_err; |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 492 | } else if (len < ntohs(pclc_base->hdr.length)) { |
YueHaibing | 3818977 | 2018-09-18 15:46:38 +0200 | [diff] [blame] | 493 | reason_code = -ENETUNREACH; |
| 494 | smc->sk.sk_err = -reason_code; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 495 | } |
| 496 | |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 497 | kfree(pclc); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 498 | return reason_code; |
| 499 | } |
| 500 | |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 501 | /* build and send CLC CONFIRM / ACCEPT message */ |
| 502 | static int smc_clc_send_confirm_accept(struct smc_sock *smc, |
| 503 | struct smc_clc_msg_accept_confirm *clc, |
| 504 | int first_contact) |
| 505 | { |
| 506 | struct smc_connection *conn = &smc->conn; |
Ursula Braun | e15c6c4 | 2020-09-26 12:44:22 +0200 | [diff] [blame] | 507 | struct smc_clc_msg_trail trl; |
| 508 | struct kvec vec[2]; |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 509 | struct msghdr msg; |
Ursula Braun | e15c6c4 | 2020-09-26 12:44:22 +0200 | [diff] [blame] | 510 | int i; |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 511 | |
| 512 | /* send SMC Confirm CLC msg */ |
| 513 | clc->hdr.version = SMC_V1; /* SMC version */ |
| 514 | if (first_contact) |
Ursula Braun | f1eb02f | 2020-09-26 12:44:20 +0200 | [diff] [blame] | 515 | clc->hdr.typev2 |= SMC_FIRST_CONTACT_MASK; |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 516 | if (conn->lgr->is_smcd) { |
| 517 | /* SMC-D specific settings */ |
| 518 | memcpy(clc->hdr.eyecatcher, SMCD_EYECATCHER, |
| 519 | sizeof(SMCD_EYECATCHER)); |
Ursula Braun | f1eb02f | 2020-09-26 12:44:20 +0200 | [diff] [blame] | 520 | clc->hdr.typev1 = SMC_TYPE_D; |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 521 | clc->hdr.length = htons(SMCD_CLC_ACCEPT_CONFIRM_LEN); |
| 522 | clc->d0.gid = conn->lgr->smcd->local_gid; |
| 523 | clc->d0.token = conn->rmb_desc->token; |
| 524 | clc->d0.dmbe_size = conn->rmbe_size_short; |
| 525 | clc->d0.dmbe_idx = 0; |
| 526 | memcpy(&clc->d0.linkid, conn->lgr->id, SMC_LGR_ID_SIZE); |
Ursula Braun | e15c6c4 | 2020-09-26 12:44:22 +0200 | [diff] [blame] | 527 | memcpy(trl.eyecatcher, SMCD_EYECATCHER, |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 528 | sizeof(SMCD_EYECATCHER)); |
| 529 | } else { |
| 530 | struct smc_link *link = conn->lnk; |
| 531 | |
| 532 | /* SMC-R specific settings */ |
| 533 | link = conn->lnk; |
| 534 | memcpy(clc->hdr.eyecatcher, SMC_EYECATCHER, |
| 535 | sizeof(SMC_EYECATCHER)); |
Ursula Braun | f1eb02f | 2020-09-26 12:44:20 +0200 | [diff] [blame] | 536 | clc->hdr.typev1 = SMC_TYPE_R; |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 537 | clc->hdr.length = htons(SMCR_CLC_ACCEPT_CONFIRM_LEN); |
| 538 | memcpy(clc->r0.lcl.id_for_peer, local_systemid, |
| 539 | sizeof(local_systemid)); |
| 540 | memcpy(&clc->r0.lcl.gid, link->gid, SMC_GID_SIZE); |
| 541 | memcpy(&clc->r0.lcl.mac, &link->smcibdev->mac[link->ibport - 1], |
| 542 | ETH_ALEN); |
| 543 | hton24(clc->r0.qpn, link->roce_qp->qp_num); |
| 544 | clc->r0.rmb_rkey = |
| 545 | htonl(conn->rmb_desc->mr_rx[link->link_idx]->rkey); |
| 546 | clc->r0.rmbe_idx = 1; /* for now: 1 RMB = 1 RMBE */ |
| 547 | clc->r0.rmbe_alert_token = htonl(conn->alert_token_local); |
| 548 | switch (clc->hdr.type) { |
| 549 | case SMC_CLC_ACCEPT: |
| 550 | clc->r0.qp_mtu = link->path_mtu; |
| 551 | break; |
| 552 | case SMC_CLC_CONFIRM: |
| 553 | clc->r0.qp_mtu = min(link->path_mtu, link->peer_mtu); |
| 554 | break; |
| 555 | } |
| 556 | clc->r0.rmbe_size = conn->rmbe_size_short; |
| 557 | clc->r0.rmb_dma_addr = cpu_to_be64((u64)sg_dma_address |
| 558 | (conn->rmb_desc->sgt[link->link_idx].sgl)); |
| 559 | hton24(clc->r0.psn, link->psn_initial); |
Ursula Braun | e15c6c4 | 2020-09-26 12:44:22 +0200 | [diff] [blame] | 560 | memcpy(trl.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | memset(&msg, 0, sizeof(msg)); |
Ursula Braun | e15c6c4 | 2020-09-26 12:44:22 +0200 | [diff] [blame] | 564 | i = 0; |
| 565 | vec[i].iov_base = clc; |
| 566 | vec[i++].iov_len = (clc->hdr.typev1 == SMC_TYPE_D ? |
| 567 | SMCD_CLC_ACCEPT_CONFIRM_LEN : |
| 568 | SMCR_CLC_ACCEPT_CONFIRM_LEN) - |
| 569 | sizeof(trl); |
| 570 | vec[i].iov_base = &trl; |
| 571 | vec[i++].iov_len = sizeof(trl); |
| 572 | return kernel_sendmsg(smc->clcsock, &msg, vec, 1, |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 573 | ntohs(clc->hdr.length)); |
| 574 | } |
| 575 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 576 | /* send CLC CONFIRM message across internal TCP socket */ |
| 577 | int smc_clc_send_confirm(struct smc_sock *smc) |
| 578 | { |
| 579 | struct smc_clc_msg_accept_confirm cclc; |
| 580 | int reason_code = 0; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 581 | int len; |
| 582 | |
| 583 | /* send SMC Confirm CLC msg */ |
| 584 | memset(&cclc, 0, sizeof(cclc)); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 585 | cclc.hdr.type = SMC_CLC_CONFIRM; |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 586 | len = smc_clc_send_confirm_accept(smc, &cclc, 0); |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 587 | if (len < ntohs(cclc.hdr.length)) { |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 588 | if (len >= 0) { |
| 589 | reason_code = -ENETUNREACH; |
| 590 | smc->sk.sk_err = -reason_code; |
| 591 | } else { |
| 592 | smc->sk.sk_err = smc->clcsock->sk->sk_err; |
| 593 | reason_code = -smc->sk.sk_err; |
| 594 | } |
| 595 | } |
| 596 | return reason_code; |
| 597 | } |
| 598 | |
| 599 | /* send CLC ACCEPT message across internal TCP socket */ |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 600 | int smc_clc_send_accept(struct smc_sock *new_smc, bool srv_first_contact) |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 601 | { |
| 602 | struct smc_clc_msg_accept_confirm aclc; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 603 | int len; |
| 604 | |
| 605 | memset(&aclc, 0, sizeof(aclc)); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 606 | aclc.hdr.type = SMC_CLC_ACCEPT; |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 607 | len = smc_clc_send_confirm_accept(new_smc, &aclc, srv_first_contact); |
Ursula Braun | 6ae36bf | 2018-11-22 10:26:36 +0100 | [diff] [blame] | 608 | if (len < ntohs(aclc.hdr.length)) |
| 609 | len = len >= 0 ? -EPROTO : -new_smc->clcsock->sk->sk_err; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 610 | |
Ursula Braun | 6ae36bf | 2018-11-22 10:26:36 +0100 | [diff] [blame] | 611 | return len > 0 ? 0 : len; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 612 | } |