diff options
Diffstat (limited to 'roaming_common.c')
-rw-r--r-- | roaming_common.c | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/roaming_common.c b/roaming_common.c index 73db09d79..9adbe56fc 100644 --- a/roaming_common.c +++ b/roaming_common.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: roaming_common.c,v 1.5 2009/06/27 09:32:43 andreas Exp $ */ | 1 | /* $OpenBSD: roaming_common.c,v 1.8 2010/01/12 00:59:29 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2004-2009 AppGate Network Security AB | 3 | * Copyright (c) 2004-2009 AppGate Network Security AB |
4 | * | 4 | * |
@@ -52,9 +52,9 @@ int | |||
52 | get_snd_buf_size() | 52 | get_snd_buf_size() |
53 | { | 53 | { |
54 | int fd = packet_get_connection_out(); | 54 | int fd = packet_get_connection_out(); |
55 | int optval, optvallen; | 55 | int optval; |
56 | socklen_t optvallen = sizeof(optval); | ||
56 | 57 | ||
57 | optvallen = sizeof(optval); | ||
58 | if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &optval, &optvallen) != 0) | 58 | if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &optval, &optvallen) != 0) |
59 | optval = DEFAULT_ROAMBUF; | 59 | optval = DEFAULT_ROAMBUF; |
60 | return optval; | 60 | return optval; |
@@ -64,9 +64,9 @@ int | |||
64 | get_recv_buf_size() | 64 | get_recv_buf_size() |
65 | { | 65 | { |
66 | int fd = packet_get_connection_in(); | 66 | int fd = packet_get_connection_in(); |
67 | int optval, optvallen; | 67 | int optval; |
68 | socklen_t optvallen = sizeof(optval); | ||
68 | 69 | ||
69 | optvallen = sizeof(optval); | ||
70 | if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &optval, &optvallen) != 0) | 70 | if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &optval, &optvallen) != 0) |
71 | optval = DEFAULT_ROAMBUF; | 71 | optval = DEFAULT_ROAMBUF; |
72 | return optval; | 72 | return optval; |
@@ -145,8 +145,16 @@ roaming_write(int fd, const void *buf, size_t count, int *cont) | |||
145 | if (out_buf_size > 0) | 145 | if (out_buf_size > 0) |
146 | buf_append(buf, ret); | 146 | buf_append(buf, ret); |
147 | } | 147 | } |
148 | debug3("Wrote %ld bytes for a total of %llu", (long)ret, | 148 | if (out_buf_size > 0 && |
149 | (unsigned long long)write_bytes); | 149 | (ret == 0 || (ret == -1 && errno == EPIPE))) { |
150 | if (wait_for_roaming_reconnect() != 0) { | ||
151 | ret = 0; | ||
152 | *cont = 1; | ||
153 | } else { | ||
154 | ret = -1; | ||
155 | errno = EAGAIN; | ||
156 | } | ||
157 | } | ||
150 | return ret; | 158 | return ret; |
151 | } | 159 | } |
152 | 160 | ||
@@ -158,6 +166,15 @@ roaming_read(int fd, void *buf, size_t count, int *cont) | |||
158 | if (!resume_in_progress) { | 166 | if (!resume_in_progress) { |
159 | read_bytes += ret; | 167 | read_bytes += ret; |
160 | } | 168 | } |
169 | } else if (out_buf_size > 0 && | ||
170 | (ret == 0 || (ret == -1 && (errno == ECONNRESET | ||
171 | || errno == ECONNABORTED || errno == ETIMEDOUT | ||
172 | || errno == EHOSTUNREACH)))) { | ||
173 | debug("roaming_read failed for %d ret=%ld errno=%d", | ||
174 | fd, (long)ret, errno); | ||
175 | ret = 0; | ||
176 | if (wait_for_roaming_reconnect() == 0) | ||
177 | *cont = 1; | ||
161 | } | 178 | } |
162 | return ret; | 179 | return ret; |
163 | } | 180 | } |
@@ -199,3 +216,29 @@ resend_bytes(int fd, u_int64_t *offset) | |||
199 | atomicio(vwrite, fd, out_buf + (out_last - needed), needed); | 216 | atomicio(vwrite, fd, out_buf + (out_last - needed), needed); |
200 | } | 217 | } |
201 | } | 218 | } |
219 | |||
220 | /* | ||
221 | * Caclulate a new key after a reconnect | ||
222 | */ | ||
223 | void | ||
224 | calculate_new_key(u_int64_t *key, u_int64_t cookie, u_int64_t challenge) | ||
225 | { | ||
226 | const EVP_MD *md = EVP_sha1(); | ||
227 | EVP_MD_CTX ctx; | ||
228 | char hash[EVP_MAX_MD_SIZE]; | ||
229 | Buffer b; | ||
230 | |||
231 | buffer_init(&b); | ||
232 | buffer_put_int64(&b, *key); | ||
233 | buffer_put_int64(&b, cookie); | ||
234 | buffer_put_int64(&b, challenge); | ||
235 | |||
236 | EVP_DigestInit(&ctx, md); | ||
237 | EVP_DigestUpdate(&ctx, buffer_ptr(&b), buffer_len(&b)); | ||
238 | EVP_DigestFinal(&ctx, hash, NULL); | ||
239 | |||
240 | buffer_clear(&b); | ||
241 | buffer_append(&b, hash, EVP_MD_size(md)); | ||
242 | *key = buffer_get_int64(&b); | ||
243 | buffer_free(&b); | ||
244 | } | ||