ius = kcalloc(iu_num, sizeof(*ius), gfp_mask); if (!ius) return NULL; for (i = 0; i < iu_num; i++) {
iu = &ius[i];
iu->direction = dir;
iu->buf = kzalloc(size, gfp_mask); if (!iu->buf) goto err;
/* * If one of the sges has 0 size, the operation will fail with a * length error
*/ for (i = 0; i < num_sge; i++) if (WARN_ONCE(sge[i].length == 0, "sg %d is zero length\n", i)) return -EINVAL;
staticint rtrs_str_gid_to_sockaddr(constchar *addr, size_t len, short port, struct sockaddr_storage *dst)
{ struct sockaddr_ib *dst_ib = (struct sockaddr_ib *)dst; int ret;
/* * We can use some of the IPv6 functions since GID is a valid * IPv6 address format
*/
ret = in6_pton(addr, len, dst_ib->sib_addr.sib_raw, '\0', NULL); if (ret == 0) return -EINVAL;
dst_ib->sib_family = AF_IB; /* * Use the same TCP server port number as the IB service ID * on the IB port space range
*/
dst_ib->sib_sid = cpu_to_be64(RDMA_IB_IP_PS_IB | port);
dst_ib->sib_sid_mask = cpu_to_be64(0xffffffffffffffffULL);
dst_ib->sib_pkey = cpu_to_be16(0xffff);
return 0;
}
/** * rtrs_str_to_sockaddr() - Convert rtrs address string to sockaddr * @addr: String representation of an addr (IPv4, IPv6 or IB GID): * - "ip:192.168.1.1" * - "ip:fe80::200:5aee:feaa:20a2" * - "gid:fe80::200:5aee:feaa:20a2" * @len: String address length * @port: Destination port * @dst: Destination sockaddr structure * * Returns 0 if conversion successful. Non-zero on error.
*/ staticint rtrs_str_to_sockaddr(constchar *addr, size_t len,
u16 port, struct sockaddr_storage *dst)
{ if (strncmp(addr, "gid:", 4) == 0) { return rtrs_str_gid_to_sockaddr(addr + 4, len - 4, port, dst);
} elseif (strncmp(addr, "ip:", 3) == 0) { char port_str[8]; char *cpy; int err;
/** * sockaddr_to_str() - convert sockaddr to a string. * @addr: the sockadddr structure to be converted. * @buf: string containing socket addr. * @len: string length. * * The return value is the number of characters written into buf not * including the trailing '\0'. If len is == 0 the function returns 0..
*/ int sockaddr_to_str(conststruct sockaddr *addr, char *buf, size_t len)
{ switch (addr->sa_family) { case AF_IB: return scnprintf(buf, len, "gid:%pI6",
&((struct sockaddr_ib *)addr)->sib_addr.sib_raw); case AF_INET: return scnprintf(buf, len, "ip:%pI4",
&((struct sockaddr_in *)addr)->sin_addr); case AF_INET6: return scnprintf(buf, len, "ip:%pI6c",
&((struct sockaddr_in6 *)addr)->sin6_addr);
} return scnprintf(buf, len, "");
}
EXPORT_SYMBOL(sockaddr_to_str);
/** * rtrs_addr_to_str() - convert rtrs_addr to a string "src@dst" * @addr: the rtrs_addr structure to be converted * @buf: string containing source and destination addr of a path * separated by '@' I.e. "ip:1.1.1.1@ip:1.1.1.2" * "ip:1.1.1.1@ip:1.1.1.2". * @len: string length * * The return value is the number of characters written into buf not * including the trailing '\0'.
*/ int rtrs_addr_to_str(conststruct rtrs_addr *addr, char *buf, size_t len)
{ int cnt;
/** * rtrs_addr_to_sockaddr() - convert path string "src,dst" or "src@dst" * to sockaddreses * @str: string containing source and destination addr of a path * separated by ',' or '@' I.e. "ip:1.1.1.1,ip:1.1.1.2" or * "ip:1.1.1.1@ip:1.1.1.2". If str contains only one address it's * considered to be destination. * @len: string length * @port: Destination port number. * @addr: will be set to the source/destination address or to NULL * if str doesn't contain any source address. * * Returns zero if conversion successful. Non-zero otherwise.
*/ int rtrs_addr_to_sockaddr(constchar *str, size_t len, u16 port, struct rtrs_addr *addr)
{ constchar *d;
d = strchr(str, ','); if (!d)
d = strchr(str, '@'); if (d) { if (rtrs_str_to_sockaddr(str, d - str, 0, addr->src)) return -EINVAL;
d += 1;
len -= d - str;
str = d;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.