Skip to content

Commit

Permalink
Improved ekr_loop logging (#334)
Browse files Browse the repository at this point in the history
* be more verbose (#312)

* Improve and of ICMP messages on Windows.

When an ICMP message is received on Windows 10 for a UDP socket,
WSAECONNRESET is reported as an error. In this case, just read
again.

Thanks to nxrighthere for reporting the issue and helping to
nail it down.

This fixes #309.

* Fix broken links, Make URLs' protocols consistent (#315)

Two Links missed leading `http(s)://` and were broken.
All links to `tools.ietf.org` now consistently use https.

* Backport https://svnweb.freebsd.org/base?view=revision&revision=340783

* Improve input validation for the IPPROTO_SCTP level socket options
SCTP_CONNECT_X and SCTP_CONNECT_X_DELAYED.

* Allow sending on demand SCTP HEARTBEATS only in the ESTABLISHED state.

* Fix cross-build linux->mingw (#320)

* ekr_loop* allowed to specify ports

* Buildbot trigger

* Update ekr_loop.c

* Update ekr_loop.c

* Update ekr_loop.c

* Update ekr_loop.c

* revert changes

* test

* Revert changes

* sync

* sync

* sync

* sync

* sync

* sync

* fix: i=1 --> i=0
  • Loading branch information
weinrank authored and tuexen committed Aug 1, 2019
1 parent 6251106 commit 2f51608
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions programs/ekr_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ static int
receive_cb(struct socket *sock, union sctp_sockstore addr, void *data,
size_t datalen, struct sctp_rcvinfo rcv, int flags, void *ulp_info)
{
printf("Message %p received on sock = %p.\n", data, (void *)sock);
debug_printf("MSG RCV: %p received on sock = %p.\n", data, (void *)sock);
if (data) {
if ((flags & MSG_NOTIFICATION) == 0) {
printf("Messsage of length %d received via %p:%u on stream %u with SSN %u and TSN %u, PPID %u, context %u, flags %x.\n",
debug_printf("MSG RCV: length %d, addr %p:%u, stream %u, SSN %u, TSN %u, PPID %u, context %u, %s%s.\n",
(int)datalen,
addr.sconn.sconn_addr,
ntohs(addr.sconn.sconn_port),
Expand All @@ -143,7 +143,8 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data,
rcv.rcv_tsn,
ntohl(rcv.rcv_ppid),
rcv.rcv_context,
flags);
(rcv.rcv_flags & SCTP_UNORDERED) ? "unordered" : "ordered",
(flags & MSG_EOR) ? ", EOR" : "");
}
free(data);
} else {
Expand Down Expand Up @@ -172,7 +173,7 @@ print_addresses(struct socket *sock)

sin = (struct sockaddr_in *)addr;
name = inet_ntop(AF_INET, &sin->sin_addr, buf, INET_ADDRSTRLEN);
printf("%s:%d", name, ntohs(sin->sin_port));
debug_printf("%s:%d", name, ntohs(sin->sin_port));
break;
}
case AF_INET6:
Expand All @@ -183,30 +184,30 @@ print_addresses(struct socket *sock)

sin6 = (struct sockaddr_in6 *)addr;
name = inet_ntop(AF_INET6, &sin6->sin6_addr, buf, INET6_ADDRSTRLEN);
printf("%s:%d", name, ntohs(sin6->sin6_port));
debug_printf("%s:%d", name, ntohs(sin6->sin6_port));
break;
}
case AF_CONN:
{
struct sockaddr_conn *sconn;

sconn = (struct sockaddr_conn *)addr;
printf("%p:%d", sconn->sconn_addr, ntohs(sconn->sconn_port));
debug_printf("%p:%d", sconn->sconn_addr, ntohs(sconn->sconn_port));
break;
}
default:
printf("Unknown family: %d", addr->sa_family);
debug_printf("Unknown family: %d", addr->sa_family);
break;
}
addr = (struct sockaddr *)((caddr_t)addr + addr->sa_len);
if (i != n - 1) {
printf(",");
debug_printf(",");
}
}
if (n > 0) {
usrsctp_freeladdrs(addrs);
}
printf("<->");
debug_printf("<->");
n = usrsctp_getpaddrs(sock, 0, &addrs);
addr = addrs;
for (i = 0; i < n; i++) {
Expand All @@ -219,7 +220,7 @@ print_addresses(struct socket *sock)

sin = (struct sockaddr_in *)addr;
name = inet_ntop(AF_INET, &sin->sin_addr, buf, INET_ADDRSTRLEN);
printf("%s:%d", name, ntohs(sin->sin_port));
debug_printf("%s:%d", name, ntohs(sin->sin_port));
break;
}
case AF_INET6:
Expand All @@ -230,30 +231,30 @@ print_addresses(struct socket *sock)

sin6 = (struct sockaddr_in6 *)addr;
name = inet_ntop(AF_INET6, &sin6->sin6_addr, buf, INET6_ADDRSTRLEN);
printf("%s:%d", name, ntohs(sin6->sin6_port));
debug_printf("%s:%d", name, ntohs(sin6->sin6_port));
break;
}
case AF_CONN:
{
struct sockaddr_conn *sconn;

sconn = (struct sockaddr_conn *)addr;
printf("%p:%d", sconn->sconn_addr, ntohs(sconn->sconn_port));
debug_printf("%p:%d", sconn->sconn_addr, ntohs(sconn->sconn_port));
break;
}
default:
printf("Unknown family: %d", addr->sa_family);
debug_printf("Unknown family: %d", addr->sa_family);
break;
}
addr = (struct sockaddr *)((caddr_t)addr + addr->sa_len);
if (i != n - 1) {
printf(",");
debug_printf(",");
}
}
if (n > 0) {
usrsctp_freepaddrs(addrs);
}
printf("\n");
debug_printf("\n");
}
#endif

Expand All @@ -273,7 +274,7 @@ main(int argc, char *argv[])
#else
pthread_t tid_c, tid_s;
#endif
int i, cur_buf_size, snd_buf_size, rcv_buf_size;
int i, j, cur_buf_size, snd_buf_size, rcv_buf_size;
socklen_t opt_len;
struct sctp_sndinfo sndinfo;
char *line;
Expand All @@ -288,6 +289,8 @@ main(int argc, char *argv[])
server_port = atoi(argv[2]);
}

debug_printf("starting program\n");

#ifdef _WIN32
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
printf("WSAStartup failed\n");
Expand Down Expand Up @@ -350,11 +353,11 @@ main(int argc, char *argv[])
#endif
#ifdef _WIN32
if (connect(fd_c, (struct sockaddr *)&sin_s, sizeof(struct sockaddr_in)) == SOCKET_ERROR) {
printf("connect() failed with error: %d\n", WSAGetLastError());
debug_printf("connect() failed with error: %d\n", WSAGetLastError());
exit(EXIT_FAILURE);
}
if (connect(fd_s, (struct sockaddr *)&sin_c, sizeof(struct sockaddr_in)) == SOCKET_ERROR) {
printf("connect() failed with error: %d\n", WSAGetLastError());
debug_printf("connect() failed with error: %d\n", WSAGetLastError());
exit(EXIT_FAILURE);
}
#else
Expand Down Expand Up @@ -397,7 +400,7 @@ main(int argc, char *argv[])
perror("usrsctp_getsockopt");
exit(EXIT_FAILURE);
}
printf("Change send socket buffer size from %d ", cur_buf_size);
debug_printf("Change send socket buffer size from %d ", cur_buf_size);
snd_buf_size = 1<<22; /* 4 MB */
if (usrsctp_setsockopt(s_c, SOL_SOCKET, SO_SNDBUF, &snd_buf_size, sizeof(int)) < 0) {
perror("usrsctp_setsockopt");
Expand All @@ -409,7 +412,7 @@ main(int argc, char *argv[])
perror("usrsctp_getsockopt");
exit(EXIT_FAILURE);
}
printf("to %d.\n", cur_buf_size);
debug_printf("to %d.\n", cur_buf_size);
if ((s_l = usrsctp_socket(AF_CONN, SOCK_STREAM, IPPROTO_SCTP, receive_cb, NULL, 0, &fd_s)) == NULL) {
perror("usrsctp_socket");
exit(EXIT_FAILURE);
Expand All @@ -420,7 +423,7 @@ main(int argc, char *argv[])
perror("usrsctp_getsockopt");
exit(EXIT_FAILURE);
}
printf("Change receive socket buffer size from %d ", cur_buf_size);
debug_printf("Change receive socket buffer size from %d ", cur_buf_size);
rcv_buf_size = 1<<16; /* 64 KB */
if (usrsctp_setsockopt(s_l, SOL_SOCKET, SO_RCVBUF, &rcv_buf_size, sizeof(int)) < 0) {
perror("usrsctp_setsockopt");
Expand All @@ -432,7 +435,7 @@ main(int argc, char *argv[])
perror("usrsctp_getsockopt");
exit(EXIT_FAILURE);
}
printf("to %d.\n", cur_buf_size);
debug_printf("to %d.\n", cur_buf_size);
/* Bind the client side. */
memset(&sconn, 0, sizeof(struct sockaddr_conn));
sconn.sconn_family = AF_CONN;
Expand Down Expand Up @@ -487,24 +490,29 @@ main(int argc, char *argv[])
sndinfo.snd_ppid = htonl(DISCARD_PPID);
sndinfo.snd_context = 0;
sndinfo.snd_assoc_id = 0;
for (i = 1; i < NUMBER_OF_STEPS; i++) {

for (i = 0; i < NUMBER_OF_STEPS; i++) {
j = 0;
if (i % 2) {
sndinfo.snd_flags = SCTP_UNORDERED;
} else {
sndinfo.snd_flags = 0;
}
/* Send a 1 MB ordered message */
/* Send a 1 MB message */
debug_printf("usrscp_sendv - step %d - call %d flags %x\n", i, ++j, sndinfo.snd_flags);
if (usrsctp_sendv(s_c, line, LINE_LENGTH, NULL, 0, (void *)&sndinfo,
(socklen_t)sizeof(struct sctp_sndinfo), SCTP_SENDV_SNDINFO, 0) < 0) {
perror("usrsctp_sendv");
exit(EXIT_FAILURE);
}
/* Send a 1 MB ordered message */
/* Send a 1 MB message */
debug_printf("usrscp_sendv - step %d - call %d flags %x\n", i, ++j, sndinfo.snd_flags);
if (usrsctp_sendv(s_c, line, LINE_LENGTH, NULL, 0, (void *)&sndinfo,
(socklen_t)sizeof(struct sctp_sndinfo), SCTP_SENDV_SNDINFO, 0) < 0) {
perror("usrsctp_sendv");
exit(EXIT_FAILURE);
}
debug_printf("Sending done, sleeping\n");
#ifdef _WIN32
Sleep(1000);
#else
Expand All @@ -527,11 +535,11 @@ main(int argc, char *argv[])
TerminateThread(tid_s, 0);
WaitForSingleObject(tid_s, INFINITE);
if (closesocket(fd_c) == SOCKET_ERROR) {
printf("closesocket() failed with error: %d\n", WSAGetLastError());
debug_printf("closesocket() failed with error: %d\n", WSAGetLastError());
exit(EXIT_FAILURE);
}
if (closesocket(fd_s) == SOCKET_ERROR) {
printf("closesocket() failed with error: %d\n", WSAGetLastError());
debug_printf("closesocket() failed with error: %d\n", WSAGetLastError());
exit(EXIT_FAILURE);
}
WSACleanup();
Expand Down

0 comments on commit 2f51608

Please sign in to comment.