Mercurial > dropbear
comparison packet.c @ 1032:0da8ba489c23 fastopen
Move generic network routines to netio.c
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 20 Feb 2015 23:16:38 +0800 |
parents | daf21fd50abf |
children | 4d7b4c5526c5 |
comparison
equal
deleted
inserted
replaced
1031:64c0aa01e2b6 | 1032:0da8ba489c23 |
---|---|
32 #include "kex.h" | 32 #include "kex.h" |
33 #include "dbrandom.h" | 33 #include "dbrandom.h" |
34 #include "service.h" | 34 #include "service.h" |
35 #include "auth.h" | 35 #include "auth.h" |
36 #include "channel.h" | 36 #include "channel.h" |
37 #include "netio.h" | |
37 | 38 |
38 static int read_packet_init(); | 39 static int read_packet_init(); |
39 static void make_mac(unsigned int seqno, const struct key_context_directional * key_state, | 40 static void make_mac(unsigned int seqno, const struct key_context_directional * key_state, |
40 buffer * clear_buf, unsigned int clear_len, | 41 buffer * clear_buf, unsigned int clear_len, |
41 unsigned char *output_mac); | 42 unsigned char *output_mac); |
50 #ifndef DISABLE_ZLIB | 51 #ifndef DISABLE_ZLIB |
51 static buffer* buf_decompress(buffer* buf, unsigned int len); | 52 static buffer* buf_decompress(buffer* buf, unsigned int len); |
52 static void buf_compress(buffer * dest, buffer * src, unsigned int len); | 53 static void buf_compress(buffer * dest, buffer * src, unsigned int len); |
53 #endif | 54 #endif |
54 | 55 |
55 struct iovec * packet_queue_to_iovec(struct Queue *queue, int *ret_iov_count) { | |
56 struct iovec *iov = NULL; | |
57 struct Link *l; | |
58 unsigned int i, packet_type; | |
59 int len; | |
60 buffer *writebuf; | |
61 | |
62 #ifndef IOV_MAX | |
63 #define IOV_MAX UIO_MAXIOV | |
64 #endif | |
65 | |
66 *ret_iov_count = MIN(queue->count, IOV_MAX); | |
67 | |
68 iov = m_malloc(sizeof(*iov) * *ret_iov_count); | |
69 for (l = queue->head, i = 0; l; l = l->link, i++) | |
70 { | |
71 writebuf = (buffer*)l->item; | |
72 packet_type = writebuf->data[writebuf->len-1]; | |
73 len = writebuf->len - 1 - writebuf->pos; | |
74 dropbear_assert(len > 0); | |
75 TRACE2(("write_packet writev #%d type %d len %d/%d", i, packet_type, | |
76 len, writebuf->len-1)) | |
77 iov[i].iov_base = buf_getptr(writebuf, len); | |
78 iov[i].iov_len = len; | |
79 } | |
80 | |
81 return iov; | |
82 } | |
83 | |
84 void packet_queue_consume(struct Queue *queue, ssize_t written) { | |
85 buffer *writebuf; | |
86 int len; | |
87 while (written > 0) { | |
88 writebuf = (buffer*)examine(queue); | |
89 len = writebuf->len - 1 - writebuf->pos; | |
90 if (len > written) { | |
91 /* partial buffer write */ | |
92 buf_incrpos(writebuf, written); | |
93 written = 0; | |
94 } else { | |
95 written -= len; | |
96 dequeue(queue); | |
97 buf_free(writebuf); | |
98 } | |
99 } | |
100 } | |
101 | |
102 /* non-blocking function writing out a current encrypted packet */ | 56 /* non-blocking function writing out a current encrypted packet */ |
103 void write_packet() { | 57 void write_packet() { |
104 | 58 |
105 ssize_t written; | 59 ssize_t written; |
106 int len; | |
107 buffer * writebuf = NULL; | |
108 unsigned packet_type; | |
109 #ifdef HAVE_WRITEV | 60 #ifdef HAVE_WRITEV |
110 struct iovec *iov = NULL; | 61 struct iovec *iov = NULL; |
111 int iov_count; | 62 int iov_count; |
112 #endif | 63 #endif |
113 | 64 |