comparison packet.c @ 1577:399d8eb961b5

get rid of unused packet_type in encrypted write queue
author Matt Johnston <matt@ucc.asn.au>
date Sun, 04 Mar 2018 14:57:18 +0800
parents 92c93b4a3646
children 8f7b6f75aa58
comparison
equal deleted inserted replaced
1576:0c8c2552b2f2 1577:399d8eb961b5
63 unsigned int iov_count = 50; 63 unsigned int iov_count = 50;
64 struct iovec iov[50]; 64 struct iovec iov[50];
65 #else 65 #else
66 int len; 66 int len;
67 buffer* writebuf; 67 buffer* writebuf;
68 int packet_type;
69 #endif 68 #endif
70 69
71 TRACE2(("enter write_packet")) 70 TRACE2(("enter write_packet"))
72 dropbear_assert(!isempty(&ses.writequeue)); 71 dropbear_assert(!isempty(&ses.writequeue));
73 72
111 /* Get the next buffer in the queue of encrypted packets to write*/ 110 /* Get the next buffer in the queue of encrypted packets to write*/
112 writebuf = (buffer*)examine(&ses.writequeue); 111 writebuf = (buffer*)examine(&ses.writequeue);
113 112
114 /* The last byte of the buffer is not to be transmitted, but is 113 /* The last byte of the buffer is not to be transmitted, but is
115 * a cleartext packet_type indicator */ 114 * a cleartext packet_type indicator */
116 packet_type = writebuf->data[writebuf->len-1]; 115 len = writebuf->len - writebuf->pos;
117 len = writebuf->len - 1 - writebuf->pos;
118 TRACE2(("write_packet type %d len %d/%d", packet_type,
119 len, writebuf->len-1))
120 dropbear_assert(len > 0); 116 dropbear_assert(len > 0);
121 /* Try to write as much as possible */ 117 /* Try to write as much as possible */
122 written = write(ses.sock_out, buf_getptr(writebuf, len), len); 118 written = write(ses.sock_out, buf_getptr(writebuf, len), len);
123 119
124 if (written < 0) { 120 if (written < 0) {
602 buf_putbytes(writebuf, mac_bytes, mac_size); 598 buf_putbytes(writebuf, mac_bytes, mac_size);
603 599
604 /* Update counts */ 600 /* Update counts */
605 ses.kexstate.datatrans += writebuf->len; 601 ses.kexstate.datatrans += writebuf->len;
606 602
607 writebuf_enqueue(writebuf, packet_type); 603 writebuf_enqueue(writebuf);
608 604
609 /* Update counts */ 605 /* Update counts */
610 ses.transseq++; 606 ses.transseq++;
611 607
612 now = monotonic_now(); 608 now = monotonic_now();
622 } 618 }
623 619
624 TRACE2(("leave encrypt_packet()")) 620 TRACE2(("leave encrypt_packet()"))
625 } 621 }
626 622
627 void writebuf_enqueue(buffer * writebuf, unsigned char packet_type) { 623 void writebuf_enqueue(buffer * writebuf) {
628 /* The last byte of the buffer stores the cleartext packet_type. It is not
629 * transmitted but is used for transmit timeout purposes */
630 buf_putbyte(writebuf, packet_type);
631 /* enqueue the packet for sending. It will get freed after transmission. */ 624 /* enqueue the packet for sending. It will get freed after transmission. */
632 buf_setpos(writebuf, 0); 625 buf_setpos(writebuf, 0);
633 enqueue(&ses.writequeue, (void*)writebuf); 626 enqueue(&ses.writequeue, (void*)writebuf);
634 ses.writequeue_len += writebuf->len-1; 627 ses.writequeue_len += writebuf->len;
635 } 628 }
636 629
637 630
638 /* Create the packet mac, and append H(seqno|clearbuf) to the output */ 631 /* Create the packet mac, and append H(seqno|clearbuf) to the output */
639 /* output_mac must have ses.keys->trans.algo_mac->hashsize bytes. */ 632 /* output_mac must have ses.keys->trans.algo_mac->hashsize bytes. */