summaryrefslogtreecommitdiff
path: root/packet.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2015-03-20 23:36:42 +0800
committerMatt Johnston <matt@ucc.asn.au>2015-03-20 23:36:42 +0800
commite6a9ce5c55e7ec72dc4636135b5c6f9f49cafdda (patch)
treed753becf83fa3e5cb8a05b681b9ca1f3ee014ab1 /packet.c
parent1d23c9f31363ac8195733e40d45e4b7fa78140c3 (diff)
downloaddropbear-e6a9ce5c55e7ec72dc4636135b5c6f9f49cafdda.tar.gz
Make main socket nonblocking. Limit writequeue size.
Diffstat (limited to 'packet.c')
-rw-r--r--packet.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/packet.c b/packet.c
index 19abe6a..1d1be84 100644
--- a/packet.c
+++ b/packet.c
@@ -59,7 +59,7 @@ void write_packet() {
ssize_t written;
#ifdef HAVE_WRITEV
/* 50 is somewhat arbitrary */
- int iov_count = 50;
+ unsigned int iov_count = 50;
struct iovec iov[50];
#endif
@@ -83,6 +83,7 @@ void write_packet() {
}
packet_queue_consume(&ses.writequeue, written);
+ ses.writequeue_len -= written;
if (written == 0) {
ses.remoteclosed();
@@ -113,6 +114,8 @@ void write_packet() {
ses.remoteclosed();
}
+ ses.writequeue_len -= written;
+
if (written == len) {
/* We've finished with the packet, free it */
dequeue(&ses.writequeue);
@@ -570,15 +573,12 @@ void encrypt_packet() {
/* stick the MAC on it */
buf_putbytes(writebuf, mac_bytes, mac_size);
- /* The last byte of the buffer stores the cleartext packet_type. It is not
- * transmitted but is used for transmit timeout purposes */
- buf_putbyte(writebuf, packet_type);
- /* enqueue the packet for sending. It will get freed after transmission. */
- buf_setpos(writebuf, 0);
- enqueue(&ses.writequeue, (void*)writebuf);
-
/* Update counts */
ses.kexstate.datatrans += writebuf->len;
+
+ writebuf_enqueue(writebuf, packet_type);
+
+ /* Update counts */
ses.transseq++;
now = monotonic_now();
@@ -596,6 +596,16 @@ void encrypt_packet() {
TRACE2(("leave encrypt_packet()"))
}
+void writebuf_enqueue(buffer * writebuf, unsigned char packet_type) {
+ /* The last byte of the buffer stores the cleartext packet_type. It is not
+ * transmitted but is used for transmit timeout purposes */
+ buf_putbyte(writebuf, packet_type);
+ /* enqueue the packet for sending. It will get freed after transmission. */
+ buf_setpos(writebuf, 0);
+ enqueue(&ses.writequeue, (void*)writebuf);
+ ses.writequeue_len += writebuf->len-1;
+}
+
/* Create the packet mac, and append H(seqno|clearbuf) to the output */
/* output_mac must have ses.keys->trans.algo_mac->hashsize bytes. */