Skip to content

Commit d75e826

Browse files
Merge pull request #252 from ejohnstown/window
Window
2 parents 2c710dc + 6457cfa commit d75e826

9 files changed

Lines changed: 33 additions & 109 deletions

File tree

ide/Renesas/cs+/common/wolfssh_csplus_usersettings.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
*/
2121

2222
#define RENESAS_CSPLUS
23-
#define WIOCTL ws_Ioctl
2423
//#define DEBUG_WOLFSSH
2524
#define WOLFSSH_NO_TIMESTAMP
2625
#define WOLFSSH_USER_IO
27-
#define FIONREAD 1
2826
#define WOLFSSH_THREAD

src/internal.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,6 @@ const char* GetErrorString(int err)
245245
case WS_INVALID_EXTDATA:
246246
return "invalid extended data type";
247247

248-
case WS_CHAN_PENDING:
249-
return "channel open pending";
250-
251248
case WS_SFTP_BAD_REQ_ID:
252249
return "sftp bad request id";
253250

@@ -284,9 +281,15 @@ const char* GetErrorString(int err)
284281
case WS_CHANNEL_NOT_CONF:
285282
return "channel open not confirmed";
286283

287-
case WC_CHANGE_AUTH_E:
284+
case WS_CHANGE_AUTH_E:
288285
return "changing auth type attempt";
289286

287+
case WS_WINDOW_FULL:
288+
return "peer's channel window full";
289+
290+
case WS_MISSING_CALLBACK:
291+
return "missing a callback function";
292+
290293
default:
291294
return "Unknown error code";
292295
}
@@ -8180,6 +8183,13 @@ int SendChannelData(WOLFSSH* ssh, word32 peerChannel,
81808183
}
81818184
}
81828185

8186+
if (ret == WS_SUCCESS) {
8187+
if (channel->peerWindowSz == 0) {
8188+
WLOG(WS_LOG_DEBUG, "channel window is full");
8189+
ret = WS_WINDOW_FULL;
8190+
}
8191+
}
8192+
81838193
if (ret == WS_SUCCESS) {
81848194
word32 bound = min(channel->peerWindowSz, channel->peerMaxPacketSz);
81858195

src/ssh.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,41 +1645,6 @@ int wolfSSH_ChannelGetEof(WOLFSSH_CHANNEL* channel)
16451645
}
16461646

16471647

1648-
/* Protocols that have loops over wolfSSH_stream_send without doing any reads
1649-
* will run into the issue of not checking for a peer window adjustment packet.
1650-
* This function allows for checking for a peer window adjustment packet without
1651-
* requiring a read buffer and call to wolfSSH_stream_read.
1652-
*
1653-
* Data that is read and is not related to packet headers is stored in the
1654-
* WOLFSSH input buffer and can be gotten with a call to wolfSSH_stream_read. If
1655-
* more data is stored then MAX_PACKET_SZ then no more window adjustment packets
1656-
* are searched for.
1657-
*/
1658-
void wolfSSH_CheckReceivePending(WOLFSSH* ssh)
1659-
{
1660-
int bytes = 0;
1661-
Buffer* inputBuffer;
1662-
1663-
WLOG(WS_LOG_DEBUG, "Entering wolfSSH_CheckReceivePending()");
1664-
1665-
if (ssh == NULL)
1666-
return;
1667-
1668-
inputBuffer = &ssh->channelList->inputBuffer;
1669-
WIOCTL(wolfSSH_get_fd(ssh), WFIONREAD, &bytes);
1670-
while (bytes > 0) { /* there is something to read off the wire */
1671-
if (inputBuffer->length - inputBuffer->idx > MAX_PACKET_SZ) {
1672-
WLOG(WS_LOG_DEBUG, "Application data to be read");
1673-
break; /* too much application data! */
1674-
}
1675-
if (DoReceive(ssh) < 0) {
1676-
WLOG(WS_LOG_ERROR, "Error trying to read potential window adjust");
1677-
}
1678-
WIOCTL(wolfSSH_get_fd(ssh), WFIONREAD, &bytes);
1679-
}
1680-
}
1681-
1682-
16831648
#ifdef WOLFSSH_SHOW_SIZES
16841649

16851650
void wolfSSH_ShowSizes(void)

src/wolfscp.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,11 @@ int DoScpSource(WOLFSSH* ssh)
574574

575575
ret = wolfSSH_stream_send(ssh, ssh->scpFileBuffer,
576576
ssh->scpBufferedSz);
577-
wolfSSH_CheckReceivePending(ssh); /*check for adjust window packet*/
577+
if (ret == WS_WINDOW_FULL) {
578+
ret = wolfSSH_worker(ssh, NULL);
579+
if (ret == WS_SUCCESS)
580+
continue;
581+
}
578582
if (ret < 0) {
579583
WLOG(WS_LOG_ERROR, scpError, "failed to send file", ret);
580584
break;
@@ -1575,7 +1579,7 @@ static int wolfSSH_SCP_cmd(WOLFSSH* ssh, const char* localName,
15751579
else {
15761580
WLOG(WS_LOG_SCP, "Cannot build scp command");
15771581
ssh->error = WS_MEMORY_E;
1578-
ret = WS_FATAL_ERROR;
1582+
ret = WS_ERROR;
15791583
}
15801584

15811585
return ret;

src/wolfsftp.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,8 @@ int wolfSSH_SFTP_read(WOLFSSH* ssh)
12051205
state->sz - state->idx);
12061206
if (ret < 0) {
12071207
if (ssh->error != WS_WANT_READ &&
1208-
ssh->error != WS_WANT_WRITE)
1208+
ssh->error != WS_WANT_WRITE &&
1209+
ssh->error != WS_WINDOW_FULL)
12091210
wolfSSH_SFTP_ClearState(ssh, STATE_ID_RECV);
12101211
return WS_FATAL_ERROR;
12111212
}
@@ -1217,7 +1218,7 @@ int wolfSSH_SFTP_read(WOLFSSH* ssh)
12171218
state->toSend = 1;
12181219

12191220
if ((int)state->idx < state->sz) {
1220-
wolfSSH_CheckReceivePending(ssh);
1221+
ret = wolfSSH_worker(ssh, NULL);
12211222
if (ssh->error == WS_WANT_READ) {
12221223
/* was something there to read, try again */
12231224
state->toSend = 2;
@@ -4607,7 +4608,8 @@ int SendPacketType(WOLFSSH* ssh, byte type, byte* buf, word32 bufSz)
46074608

46084609
/* check for adjust window packet */
46094610
err = wolfSSH_get_error(ssh);
4610-
wolfSSH_CheckReceivePending(ssh);
4611+
if (err == WS_WINDOW_FULL)
4612+
ret = wolfSSH_worker(ssh, NULL);
46114613
ssh->error = err; /* don't save potential want read here */
46124614
if (ret > 0)
46134615
state->idx += (word32)ret;
@@ -7672,7 +7674,8 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume,
76727674
state->r, state->rSz);
76737675
if (sz <= 0) {
76747676
if (ssh->error == WS_WANT_READ ||
7675-
ssh->error == WS_WANT_WRITE)
7677+
ssh->error == WS_WANT_WRITE ||
7678+
ssh->error == WS_WINDOW_FULL)
76767679
return WS_FATAL_ERROR;
76777680
}
76787681
else {
@@ -7686,8 +7689,6 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume,
76867689
statusCb(ssh, state->pOfst, from);
76877690
}
76887691
}
7689-
/* check for adjust window packet */
7690-
wolfSSH_CheckReceivePending(ssh);
76917692
} while (sz > 0 && ssh->sftpInt == 0);
76927693

76937694
if (ssh->sftpInt) {

tests/unit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,13 +420,13 @@ static int test_Errors(void)
420420
#else
421421
int i, j = 0;
422422
/* Values that are not or no longer error codes. */
423-
int missing[] = { 0 };
423+
int missing[] = { -1059 };
424424
int missingSz = (int)sizeof(missing)/sizeof(missing[0]);
425425

426426
/* Check that all errors have a string and it's the same through the two
427427
* APIs. Check that the values that are not errors map to the unknown
428428
* string. */
429-
for (i = WS_FATAL_ERROR; i >= WS_LAST_E; i--) {
429+
for (i = WS_ERROR; i >= WS_LAST_E; i--) {
430430
errStr = wolfSSH_ErrorToName(i);
431431

432432
if (j < missingSz && i == missing[j]) {

wolfssh/error.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ enum WS_ErrorCodes {
9797
WS_NEXT_ERROR = -1056, /* Getting next value/state is error */
9898
WS_CHAN_RXD = -1057, /* Status that channel data received. */
9999
WS_INVALID_EXTDATA = -1058, /* invalid Channel Extended Data Type */
100-
WS_CHAN_PENDING = -1059, /* peer hasn't confirmed channel open */
101100
WS_SFTP_BAD_REQ_ID = -1060, /* SFTP Bad request ID */
102101
WS_SFTP_BAD_REQ_TYPE = -1061, /* SFTP Bad request ID */
103102
WS_SFTP_STATUS_NOT_OK = -1062, /* SFTP Status not OK */
@@ -110,9 +109,11 @@ enum WS_ErrorCodes {
110109
WS_SSH_NULL_E = -1069, /* SSH was null */
111110
WS_SSH_CTX_NULL_E = -1070, /* SSH_CTX was null */
112111
WS_CHANNEL_NOT_CONF = -1071, /* Channel open not confirmed. */
113-
WC_CHANGE_AUTH_E = -1072, /* Changing auth type attempt */
112+
WS_CHANGE_AUTH_E = -1072, /* Changing auth type attempt */
113+
WS_WINDOW_FULL = -1073,
114+
WS_MISSING_CALLBACK = -1074, /* Callback is missing */
114115

115-
WS_LAST_E = -1072 /* Update this to indicate last error */
116+
WS_LAST_E = -1074 /* Update this to indicate last error */
116117
};
117118

118119

wolfssh/port.h

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,60 +1078,6 @@ extern "C" {
10781078
#define FALL_THROUGH
10791079
#endif
10801080

1081-
/* used for checking bytes on wire for window adjust packet read */
1082-
#ifndef WIOCTL
1083-
#ifdef WOLFSSL_NUCLEUS
1084-
#include "nucleus.h"
1085-
#include "networking/nu_networking.h"
1086-
#define WFIONREAD FIONREAD
1087-
static inline void ws_Ioctl(int fd, int flag, int* ret)
1088-
{
1089-
SCK_IOCTL_OPTION op;
1090-
op.s_optval = (unsigned char*)&fd;
1091-
if (NU_Ioctl(flag, &op, sizeof(op)) != NU_SUCCESS) {
1092-
*ret = 0;
1093-
}
1094-
else {
1095-
*ret = op.s_ret.sck_bytes_pending;
1096-
}
1097-
}
1098-
#define WIOCTL ws_Ioctl
1099-
#elif defined(FREESCALE_MQX)
1100-
/* MQX does not have FIONREAD, use SO_RCVNUM with getsockopt() instead */
1101-
#include <ioctl.h>
1102-
#include <rtcs.h>
1103-
#define WFIONREAD SO_RCVNUM
1104-
static inline void ws_Ioctl(int fd, int flag, int* ret)
1105-
{
1106-
int status;
1107-
uint32_t bytesSz;
1108-
1109-
bytesSz = sizeof(*ret);
1110-
status = getsockopt(fd, SOL_SOCKET, SO_RCVNUM, ret, &bytesSz);
1111-
if (status != RTCS_OK) {
1112-
WLOG(WS_LOG_ERROR, "Error calling getsockopt()");
1113-
*ret = 0;
1114-
}
1115-
}
1116-
#define WIOCTL ws_Ioctl
1117-
#elif defined(USE_WINDOWS_API)
1118-
#define WFIONREAD FIONREAD
1119-
#define WIOCTL ioctlsocket
1120-
#elif defined(WOLFSSL_VXWORKS)
1121-
#include "ioLib.h"
1122-
#include <sys/ioctl.h>
1123-
#define WIOCTL ioctl
1124-
#else
1125-
#if defined(__CYGWIN__) && !defined(FIONREAD)
1126-
/* Cygwin defines FIONREAD in socket.h instead of ioctl.h */
1127-
#include <sys/socket.h>
1128-
#endif
1129-
#include <sys/ioctl.h>
1130-
#define WFIONREAD FIONREAD
1131-
#define WIOCTL ioctl
1132-
#endif
1133-
#endif /* WIOCTL */
1134-
11351081

11361082
#if defined(USE_WINDOWS_API)
11371083
#define WS_SOCKET_T SOCKET

wolfssh/ssh.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ typedef enum {
218218
WOLFSSH_API WS_SessionType wolfSSH_GetSessionType(const WOLFSSH*);
219219
WOLFSSH_API const char* wolfSSH_GetSessionCommand(const WOLFSSH*);
220220
WOLFSSH_API int wolfSSH_SetChannelType(WOLFSSH*, byte, byte*, word32);
221-
WOLFSSH_API void wolfSSH_CheckReceivePending(WOLFSSH* ssh);
222221

223222

224223
enum WS_HighwaterSide {

0 commit comments

Comments
 (0)