sock: Update the spdk_sock_getaddr function.
Purpose: We need to get the port info in other applications (e.g., NVMe-oF TCP/IP transport) Change-Id: I3a4636e764e44425436bb064cb0062c6f3e44035 Signed-off-by: Ziye Yang <optimistyzy@gmail.com> Reviewed-on: https://review.gerrithub.io/428313 Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Tomasz Kulasek <tomaszx.kulasek@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
parent
5d5181db70
commit
5c263046db
@ -103,6 +103,12 @@ scripts/config_converter.py. Example how this script can be used:
|
||||
cat old_format.ini | scripts/config_converter.py > new_json_format.json
|
||||
~~~
|
||||
|
||||
### Sock
|
||||
|
||||
Two additional parameters were added to spdk_sock_get_addr() for the server
|
||||
port and client port. These parameters are named "sport" and "cport"
|
||||
respectively.
|
||||
|
||||
## v18.07:
|
||||
|
||||
### bdev
|
||||
|
@ -190,6 +190,7 @@ hello_sock_connect(struct hello_context_t *ctx)
|
||||
{
|
||||
int rc;
|
||||
char saddr[ADDR_STR_LEN], caddr[ADDR_STR_LEN];
|
||||
uint16_t cport, sport;
|
||||
|
||||
SPDK_NOTICELOG("Connecting to the server on %s:%d\n", ctx->host, ctx->port);
|
||||
|
||||
@ -199,14 +200,14 @@ hello_sock_connect(struct hello_context_t *ctx)
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = spdk_sock_getaddr(ctx->sock, saddr, sizeof(saddr), caddr, sizeof(caddr));
|
||||
rc = spdk_sock_getaddr(ctx->sock, saddr, sizeof(saddr), &sport, caddr, sizeof(caddr), &cport);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("Cannot get connection addresses\n");
|
||||
spdk_sock_close(&ctx->sock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SPDK_NOTICELOG("Connection accepted from %s to %s\n", caddr, saddr);
|
||||
SPDK_NOTICELOG("Connection accepted from (%s, %hu) to (%s, %hu)\n", caddr, cport, saddr, sport);
|
||||
|
||||
fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL) | O_NONBLOCK);
|
||||
|
||||
@ -262,6 +263,7 @@ hello_sock_accept_poll(void *arg)
|
||||
int rc;
|
||||
int count = 0;
|
||||
char saddr[ADDR_STR_LEN], caddr[ADDR_STR_LEN];
|
||||
uint16_t cport, sport;
|
||||
|
||||
if (!g_is_running) {
|
||||
spdk_poller_unregister(&ctx->poller_in);
|
||||
@ -275,11 +277,10 @@ hello_sock_accept_poll(void *arg)
|
||||
while (1) {
|
||||
sock = spdk_sock_accept(ctx->sock);
|
||||
if (sock != NULL) {
|
||||
spdk_sock_getaddr(sock, saddr, sizeof(saddr), &sport, caddr, sizeof(caddr), &cport);
|
||||
|
||||
spdk_sock_getaddr(sock, saddr, sizeof(saddr), caddr, sizeof(caddr));
|
||||
|
||||
SPDK_NOTICELOG("Accepting a new connection from %s to %s\n",
|
||||
caddr, saddr);
|
||||
SPDK_NOTICELOG("Accepting a new connection from (%s, %hu) to (%s, %hu)\n",
|
||||
caddr, cport, saddr, sport);
|
||||
|
||||
rc = spdk_sock_group_add_sock(ctx->group, sock,
|
||||
hello_sock_cb, ctx);
|
||||
|
@ -53,12 +53,15 @@ struct spdk_sock_group;
|
||||
* \param sock Socket to get address.
|
||||
* \param saddr A pointer to the buffer to hold the address of server.
|
||||
* \param slen Length of the buffer 'saddr'.
|
||||
* \param sport A pointer(May be NULL) to the buffer to hold the port info of server.
|
||||
* \param caddr A pointer to the buffer to hold the address of client.
|
||||
* \param clen Length of the buffer 'caddr'.
|
||||
* \param cport A pointer(May be NULL) to the buffer to hold the port info of server.
|
||||
*
|
||||
* \return 0 on success, -1 on failure.
|
||||
*/
|
||||
int spdk_sock_getaddr(struct spdk_sock *sock, char *saddr, int slen, char *caddr, int clen);
|
||||
int spdk_sock_getaddr(struct spdk_sock *sock, char *saddr, int slen, uint16_t *sport,
|
||||
char *caddr, int clen, uint16_t *cport);
|
||||
|
||||
/**
|
||||
* Create a socket, connect the socket to the specified address and port (of the
|
||||
|
@ -68,7 +68,8 @@ struct spdk_sock_group_impl {
|
||||
struct spdk_net_impl {
|
||||
const char *name;
|
||||
|
||||
int (*getaddr)(struct spdk_sock *sock, char *saddr, int slen, char *caddr, int clen);
|
||||
int (*getaddr)(struct spdk_sock *sock, char *saddr, int slen, uint16_t *sport, char *caddr,
|
||||
int clen, uint16_t *cport);
|
||||
struct spdk_sock *(*connect)(const char *ip, int port);
|
||||
struct spdk_sock *(*listen)(const char *ip, int port);
|
||||
struct spdk_sock *(*accept)(struct spdk_sock *sock);
|
||||
|
@ -297,9 +297,8 @@ spdk_iscsi_conn_construct(struct spdk_iscsi_portal *portal,
|
||||
TAILQ_INIT(&conn->queued_datain_tasks);
|
||||
memset(&conn->open_lun_descs, 0, sizeof(conn->open_lun_descs));
|
||||
|
||||
rc = spdk_sock_getaddr(sock, conn->target_addr,
|
||||
sizeof conn->target_addr,
|
||||
conn->initiator_addr, sizeof conn->initiator_addr);
|
||||
rc = spdk_sock_getaddr(sock, conn->target_addr, sizeof conn->target_addr, NULL,
|
||||
conn->initiator_addr, sizeof conn->initiator_addr, NULL);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("spdk_sock_getaddr() failed\n");
|
||||
goto error_return;
|
||||
|
@ -89,7 +89,8 @@ get_addr_str(struct sockaddr *sa, char *host, size_t hlen)
|
||||
#define __posix_group_impl(group) (struct spdk_posix_sock_group_impl *)group
|
||||
|
||||
static int
|
||||
spdk_posix_sock_getaddr(struct spdk_sock *_sock, char *saddr, int slen, char *caddr, int clen)
|
||||
spdk_posix_sock_getaddr(struct spdk_sock *_sock, char *saddr, int slen, uint16_t *sport,
|
||||
char *caddr, int clen, uint16_t *cport)
|
||||
{
|
||||
struct spdk_posix_sock *sock = __posix_sock(_sock);
|
||||
struct sockaddr_storage sa;
|
||||
@ -125,6 +126,14 @@ spdk_posix_sock_getaddr(struct spdk_sock *_sock, char *saddr, int slen, char *ca
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sport) {
|
||||
if (sa.ss_family == AF_INET) {
|
||||
*sport = ntohs(((struct sockaddr_in *) &sa)->sin_port);
|
||||
} else if (sa.ss_family == AF_INET6) {
|
||||
*sport = ntohs(((struct sockaddr_in6 *) &sa)->sin6_port);
|
||||
}
|
||||
}
|
||||
|
||||
memset(&sa, 0, sizeof sa);
|
||||
salen = sizeof sa;
|
||||
rc = getpeername(sock->fd, (struct sockaddr *) &sa, &salen);
|
||||
@ -139,6 +148,14 @@ spdk_posix_sock_getaddr(struct spdk_sock *_sock, char *saddr, int slen, char *ca
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cport) {
|
||||
if (sa.ss_family == AF_INET) {
|
||||
*cport = ntohs(((struct sockaddr_in *) &sa)->sin_port);
|
||||
} else if (sa.ss_family == AF_INET6) {
|
||||
*cport = ntohs(((struct sockaddr_in6 *) &sa)->sin6_port);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -41,9 +41,10 @@
|
||||
static STAILQ_HEAD(, spdk_net_impl) g_net_impls = STAILQ_HEAD_INITIALIZER(g_net_impls);
|
||||
|
||||
int
|
||||
spdk_sock_getaddr(struct spdk_sock *sock, char *saddr, int slen, char *caddr, int clen)
|
||||
spdk_sock_getaddr(struct spdk_sock *sock, char *saddr, int slen, uint16_t *sport,
|
||||
char *caddr, int clen, uint16_t *cport)
|
||||
{
|
||||
return sock->net_impl->getaddr(sock, saddr, slen, caddr, clen);
|
||||
return sock->net_impl->getaddr(sock, saddr, slen, sport, caddr, clen, cport);
|
||||
}
|
||||
|
||||
struct spdk_sock *
|
||||
|
@ -160,7 +160,8 @@ getpeername_vpp(int sock, struct sockaddr *addr, socklen_t *len)
|
||||
}
|
||||
|
||||
static int
|
||||
spdk_vpp_sock_getaddr(struct spdk_sock *_sock, char *saddr, int slen, char *caddr, int clen)
|
||||
spdk_vpp_sock_getaddr(struct spdk_sock *_sock, char *saddr, int slen, uint16_t *sport,
|
||||
char *caddr, int clen, uint16_t *cport)
|
||||
{
|
||||
struct spdk_vpp_sock *sock = __vpp_sock(_sock);
|
||||
struct sockaddr sa;
|
||||
@ -186,6 +187,14 @@ spdk_vpp_sock_getaddr(struct spdk_sock *_sock, char *saddr, int slen, char *cadd
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sport) {
|
||||
if (sa.ss_family == AF_INET) {
|
||||
*sport = ntohs(((struct sockaddr_in *) &sa)->sin_port);
|
||||
} else if (sa.ss_family == AF_INET6) {
|
||||
*sport = ntohs(((struct sockaddr_in6 *) &sa)->sin6_port);
|
||||
}
|
||||
}
|
||||
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
salen = sizeof(sa);
|
||||
rc = getpeername_vpp(sock->fd, &sa, &salen);
|
||||
@ -202,6 +211,14 @@ spdk_vpp_sock_getaddr(struct spdk_sock *_sock, char *saddr, int slen, char *cadd
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cport) {
|
||||
if (sa.ss_family == AF_INET) {
|
||||
*cport = ntohs(((struct sockaddr_in *) &sa)->sin_port);
|
||||
} else if (sa.ss_family == AF_INET6) {
|
||||
*cport = ntohs(((struct sockaddr_in6 *) &sa)->sin6_port);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,8 @@ spdk_event_call(struct spdk_event *event)
|
||||
}
|
||||
|
||||
int
|
||||
spdk_sock_getaddr(struct spdk_sock *sock, char *saddr, int slen, char *caddr, int clen)
|
||||
spdk_sock_getaddr(struct spdk_sock *sock, char *saddr, int slen, uint16_t *sport,
|
||||
char *caddr, int clen, uint16_t *cport)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -66,7 +66,8 @@ struct spdk_ut_sock_group_impl {
|
||||
#define __ut_group(group) (struct spdk_ut_sock_group_impl *)group
|
||||
|
||||
static int
|
||||
spdk_ut_sock_getaddr(struct spdk_sock *_sock, char *saddr, int slen, char *caddr, int clen)
|
||||
spdk_ut_sock_getaddr(struct spdk_sock *_sock, char *saddr, int slen, uint16_t *sport,
|
||||
char *caddr, int clen, uint16_t *cport)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user