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: |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 67 | if (clcm->path != SMC_TYPE_R && clcm->path != 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; |
| 70 | if ((clcm->path == SMC_TYPE_R && |
| 71 | ntohs(clc->hdr.length) != SMCR_CLC_ACCEPT_CONFIRM_LEN) || |
| 72 | (clcm->path == SMC_TYPE_D && |
| 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 | fb4f792 | 2020-07-08 17:05:15 +0200 | [diff] [blame] | 330 | if (clcm->type == SMC_CLC_PROPOSAL && clcm->path == SMC_TYPE_N) |
| 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 | bfbedfd | 2017-09-21 09:16:32 +0200 | [diff] [blame] | 368 | if (((struct smc_clc_msg_decline *)buf)->hdr.flag) { |
Karsten Graul | 517c300 | 2018-05-15 17:05:03 +0200 | [diff] [blame] | 369 | smc->conn.lgr->sync_err = 1; |
Karsten Graul | 5f78fe9 | 2020-02-17 16:24:54 +0100 | [diff] [blame] | 370 | smc_lgr_terminate_sched(smc->conn.lgr); |
Ursula Braun | bfbedfd | 2017-09-21 09:16:32 +0200 | [diff] [blame] | 371 | } |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 372 | } |
| 373 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 374 | out: |
Ursula Braun | 2b59f58 | 2018-11-22 10:26:39 +0100 | [diff] [blame] | 375 | clc_sk->sk_rcvtimeo = rcvtimeo; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 376 | return reason_code; |
| 377 | } |
| 378 | |
| 379 | /* send CLC DECLINE message across internal TCP socket */ |
Ursula Braun | bfbedfd | 2017-09-21 09:16:32 +0200 | [diff] [blame] | 380 | 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] | 381 | { |
| 382 | struct smc_clc_msg_decline dclc; |
| 383 | struct msghdr msg; |
| 384 | struct kvec vec; |
| 385 | int len; |
| 386 | |
| 387 | memset(&dclc, 0, sizeof(dclc)); |
| 388 | memcpy(dclc.hdr.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
| 389 | dclc.hdr.type = SMC_CLC_DECLINE; |
| 390 | dclc.hdr.length = htons(sizeof(struct smc_clc_msg_decline)); |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 391 | dclc.hdr.version = SMC_V1; |
Ursula Braun | bfbedfd | 2017-09-21 09:16:32 +0200 | [diff] [blame] | 392 | dclc.hdr.flag = (peer_diag_info == SMC_CLC_DECL_SYNCERR) ? 1 : 0; |
Hans Wippel | a082ec8 | 2020-02-25 22:41:22 +0100 | [diff] [blame] | 393 | if ((!smc->conn.lgr || !smc->conn.lgr->is_smcd) && |
| 394 | smc_ib_is_valid_local_systemid()) |
Ursula Braun | 369537c | 2020-02-14 08:59:00 +0100 | [diff] [blame] | 395 | memcpy(dclc.id_for_peer, local_systemid, |
| 396 | sizeof(local_systemid)); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 397 | dclc.peer_diagnosis = htonl(peer_diag_info); |
| 398 | memcpy(dclc.trl.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
| 399 | |
| 400 | memset(&msg, 0, sizeof(msg)); |
| 401 | vec.iov_base = &dclc; |
| 402 | vec.iov_len = sizeof(struct smc_clc_msg_decline); |
| 403 | len = kernel_sendmsg(smc->clcsock, &msg, &vec, 1, |
| 404 | sizeof(struct smc_clc_msg_decline)); |
Ursula Braun | 14d22d4 | 2019-01-30 18:51:00 +0100 | [diff] [blame] | 405 | if (len < 0 || len < sizeof(struct smc_clc_msg_decline)) |
Ursula Braun | 6ae36bf | 2018-11-22 10:26:36 +0100 | [diff] [blame] | 406 | len = -EPROTO; |
| 407 | return len > 0 ? 0 : len; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /* send CLC PROPOSAL message across internal TCP socket */ |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 411 | int smc_clc_send_proposal(struct smc_sock *smc, int smc_type, |
Karsten Graul | bc36d2f | 2019-04-12 12:57:26 +0200 | [diff] [blame] | 412 | struct smc_init_info *ini) |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 413 | { |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 414 | struct smc_clc_msg_proposal_prefix *pclc_prfx; |
| 415 | struct smc_clc_msg_proposal *pclc_base; |
| 416 | struct smc_clc_msg_proposal_area *pclc; |
| 417 | struct smc_clc_ipv6_prefix *ipv6_prfx; |
| 418 | struct smc_clc_msg_smcd *pclc_smcd; |
| 419 | struct smc_clc_msg_trail *trl; |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 420 | int len, i, plen, rc; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 421 | int reason_code = 0; |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 422 | struct kvec vec[5]; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 423 | struct msghdr msg; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 424 | |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 425 | pclc = kzalloc(sizeof(*pclc), GFP_KERNEL); |
| 426 | if (!pclc) |
| 427 | return -ENOMEM; |
| 428 | |
| 429 | pclc_base = &pclc->pclc_base; |
| 430 | pclc_smcd = &pclc->pclc_smcd; |
| 431 | pclc_prfx = &pclc->pclc_prfx; |
| 432 | ipv6_prfx = pclc->pclc_prfx_ipv6; |
| 433 | trl = &pclc->pclc_trl; |
| 434 | |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 435 | /* retrieve ip prefixes for CLC proposal msg */ |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 436 | rc = smc_clc_prfx_set(smc->clcsock, pclc_prfx, ipv6_prfx); |
| 437 | if (rc) { |
| 438 | kfree(pclc); |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 439 | return SMC_CLC_DECL_CNFERR; /* configuration error */ |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 440 | } |
Karsten Graul | c246d94 | 2018-03-16 15:06:39 +0100 | [diff] [blame] | 441 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 442 | /* send SMC Proposal CLC message */ |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 443 | plen = sizeof(*pclc_base) + sizeof(*pclc_prfx) + |
| 444 | (pclc_prfx->ipv6_prefixes_cnt * sizeof(ipv6_prfx[0])) + |
| 445 | sizeof(*trl); |
| 446 | memcpy(pclc_base->hdr.eyecatcher, SMC_EYECATCHER, |
| 447 | sizeof(SMC_EYECATCHER)); |
| 448 | pclc_base->hdr.type = SMC_CLC_PROPOSAL; |
| 449 | pclc_base->hdr.version = SMC_V1; /* SMC version */ |
| 450 | pclc_base->hdr.path = smc_type; |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 451 | if (smc_type == SMC_TYPE_R || smc_type == SMC_TYPE_B) { |
| 452 | /* add SMC-R specifics */ |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 453 | memcpy(pclc_base->lcl.id_for_peer, local_systemid, |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 454 | sizeof(local_systemid)); |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 455 | memcpy(pclc_base->lcl.gid, ini->ib_gid, SMC_GID_SIZE); |
| 456 | 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] | 457 | ETH_ALEN); |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 458 | pclc_base->iparea_offset = htons(0); |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 459 | } |
| 460 | if (smc_type == SMC_TYPE_D || smc_type == SMC_TYPE_B) { |
| 461 | /* add SMC-D specifics */ |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 462 | plen += sizeof(*pclc_smcd); |
| 463 | pclc_base->iparea_offset = htons(sizeof(*pclc_smcd)); |
| 464 | pclc_smcd->gid = ini->ism_dev->local_gid; |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 465 | } |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 466 | pclc_base->hdr.length = htons(plen); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 467 | |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 468 | memcpy(trl->eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 469 | memset(&msg, 0, sizeof(msg)); |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 470 | i = 0; |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 471 | vec[i].iov_base = pclc_base; |
| 472 | vec[i++].iov_len = sizeof(*pclc_base); |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 473 | if (smc_type == SMC_TYPE_D || smc_type == SMC_TYPE_B) { |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 474 | vec[i].iov_base = pclc_smcd; |
| 475 | vec[i++].iov_len = sizeof(*pclc_smcd); |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 476 | } |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 477 | vec[i].iov_base = pclc_prfx; |
| 478 | vec[i++].iov_len = sizeof(*pclc_prfx); |
| 479 | if (pclc_prfx->ipv6_prefixes_cnt > 0) { |
| 480 | vec[i].iov_base = ipv6_prfx; |
| 481 | vec[i++].iov_len = pclc_prfx->ipv6_prefixes_cnt * |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 482 | sizeof(ipv6_prfx[0]); |
| 483 | } |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 484 | vec[i].iov_base = trl; |
| 485 | vec[i++].iov_len = sizeof(*trl); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 486 | /* due to the few bytes needed for clc-handshake this cannot block */ |
Karsten Graul | 1a26d02 | 2018-03-16 15:06:40 +0100 | [diff] [blame] | 487 | len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen); |
YueHaibing | 3818977 | 2018-09-18 15:46:38 +0200 | [diff] [blame] | 488 | if (len < 0) { |
| 489 | smc->sk.sk_err = smc->clcsock->sk->sk_err; |
| 490 | reason_code = -smc->sk.sk_err; |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 491 | } else if (len < ntohs(pclc_base->hdr.length)) { |
YueHaibing | 3818977 | 2018-09-18 15:46:38 +0200 | [diff] [blame] | 492 | reason_code = -ENETUNREACH; |
| 493 | smc->sk.sk_err = -reason_code; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 494 | } |
| 495 | |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 496 | kfree(pclc); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 497 | return reason_code; |
| 498 | } |
| 499 | |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame^] | 500 | /* build and send CLC CONFIRM / ACCEPT message */ |
| 501 | static int smc_clc_send_confirm_accept(struct smc_sock *smc, |
| 502 | struct smc_clc_msg_accept_confirm *clc, |
| 503 | int first_contact) |
| 504 | { |
| 505 | struct smc_connection *conn = &smc->conn; |
| 506 | struct msghdr msg; |
| 507 | struct kvec vec; |
| 508 | |
| 509 | /* send SMC Confirm CLC msg */ |
| 510 | clc->hdr.version = SMC_V1; /* SMC version */ |
| 511 | if (first_contact) |
| 512 | clc->hdr.flag = 1; |
| 513 | if (conn->lgr->is_smcd) { |
| 514 | /* SMC-D specific settings */ |
| 515 | memcpy(clc->hdr.eyecatcher, SMCD_EYECATCHER, |
| 516 | sizeof(SMCD_EYECATCHER)); |
| 517 | clc->hdr.path = SMC_TYPE_D; |
| 518 | clc->hdr.length = htons(SMCD_CLC_ACCEPT_CONFIRM_LEN); |
| 519 | clc->d0.gid = conn->lgr->smcd->local_gid; |
| 520 | clc->d0.token = conn->rmb_desc->token; |
| 521 | clc->d0.dmbe_size = conn->rmbe_size_short; |
| 522 | clc->d0.dmbe_idx = 0; |
| 523 | memcpy(&clc->d0.linkid, conn->lgr->id, SMC_LGR_ID_SIZE); |
| 524 | memcpy(clc->d0.smcd_trl.eyecatcher, SMCD_EYECATCHER, |
| 525 | sizeof(SMCD_EYECATCHER)); |
| 526 | } else { |
| 527 | struct smc_link *link = conn->lnk; |
| 528 | |
| 529 | /* SMC-R specific settings */ |
| 530 | link = conn->lnk; |
| 531 | memcpy(clc->hdr.eyecatcher, SMC_EYECATCHER, |
| 532 | sizeof(SMC_EYECATCHER)); |
| 533 | clc->hdr.path = SMC_TYPE_R; |
| 534 | clc->hdr.length = htons(SMCR_CLC_ACCEPT_CONFIRM_LEN); |
| 535 | memcpy(clc->r0.lcl.id_for_peer, local_systemid, |
| 536 | sizeof(local_systemid)); |
| 537 | memcpy(&clc->r0.lcl.gid, link->gid, SMC_GID_SIZE); |
| 538 | memcpy(&clc->r0.lcl.mac, &link->smcibdev->mac[link->ibport - 1], |
| 539 | ETH_ALEN); |
| 540 | hton24(clc->r0.qpn, link->roce_qp->qp_num); |
| 541 | clc->r0.rmb_rkey = |
| 542 | htonl(conn->rmb_desc->mr_rx[link->link_idx]->rkey); |
| 543 | clc->r0.rmbe_idx = 1; /* for now: 1 RMB = 1 RMBE */ |
| 544 | clc->r0.rmbe_alert_token = htonl(conn->alert_token_local); |
| 545 | switch (clc->hdr.type) { |
| 546 | case SMC_CLC_ACCEPT: |
| 547 | clc->r0.qp_mtu = link->path_mtu; |
| 548 | break; |
| 549 | case SMC_CLC_CONFIRM: |
| 550 | clc->r0.qp_mtu = min(link->path_mtu, link->peer_mtu); |
| 551 | break; |
| 552 | } |
| 553 | clc->r0.rmbe_size = conn->rmbe_size_short; |
| 554 | clc->r0.rmb_dma_addr = cpu_to_be64((u64)sg_dma_address |
| 555 | (conn->rmb_desc->sgt[link->link_idx].sgl)); |
| 556 | hton24(clc->r0.psn, link->psn_initial); |
| 557 | memcpy(clc->r0.smcr_trl.eyecatcher, SMC_EYECATCHER, |
| 558 | sizeof(SMC_EYECATCHER)); |
| 559 | } |
| 560 | |
| 561 | memset(&msg, 0, sizeof(msg)); |
| 562 | vec.iov_base = clc; |
| 563 | vec.iov_len = ntohs(clc->hdr.length); |
| 564 | return kernel_sendmsg(smc->clcsock, &msg, &vec, 1, |
| 565 | ntohs(clc->hdr.length)); |
| 566 | } |
| 567 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 568 | /* send CLC CONFIRM message across internal TCP socket */ |
| 569 | int smc_clc_send_confirm(struct smc_sock *smc) |
| 570 | { |
| 571 | struct smc_clc_msg_accept_confirm cclc; |
| 572 | int reason_code = 0; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 573 | int len; |
| 574 | |
| 575 | /* send SMC Confirm CLC msg */ |
| 576 | memset(&cclc, 0, sizeof(cclc)); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 577 | cclc.hdr.type = SMC_CLC_CONFIRM; |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame^] | 578 | len = smc_clc_send_confirm_accept(smc, &cclc, 0); |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 579 | if (len < ntohs(cclc.hdr.length)) { |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 580 | if (len >= 0) { |
| 581 | reason_code = -ENETUNREACH; |
| 582 | smc->sk.sk_err = -reason_code; |
| 583 | } else { |
| 584 | smc->sk.sk_err = smc->clcsock->sk->sk_err; |
| 585 | reason_code = -smc->sk.sk_err; |
| 586 | } |
| 587 | } |
| 588 | return reason_code; |
| 589 | } |
| 590 | |
| 591 | /* send CLC ACCEPT message across internal TCP socket */ |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 592 | 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] | 593 | { |
| 594 | struct smc_clc_msg_accept_confirm aclc; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 595 | int len; |
| 596 | |
| 597 | memset(&aclc, 0, sizeof(aclc)); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 598 | aclc.hdr.type = SMC_CLC_ACCEPT; |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame^] | 599 | len = smc_clc_send_confirm_accept(new_smc, &aclc, srv_first_contact); |
Ursula Braun | 6ae36bf | 2018-11-22 10:26:36 +0100 | [diff] [blame] | 600 | if (len < ntohs(aclc.hdr.length)) |
| 601 | len = len >= 0 ? -EPROTO : -new_smc->clcsock->sk->sk_err; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 602 | |
Ursula Braun | 6ae36bf | 2018-11-22 10:26:36 +0100 | [diff] [blame] | 603 | return len > 0 ? 0 : len; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 604 | } |