summaryrefslogtreecommitdiff
path: root/packet.c
diff options
context:
space:
mode:
Diffstat (limited to 'packet.c')
-rw-r--r--packet.c64
1 files changed, 26 insertions, 38 deletions
diff --git a/packet.c b/packet.c
index dbd3791d2..17673f920 100644
--- a/packet.c
+++ b/packet.c
@@ -37,7 +37,7 @@
37 */ 37 */
38 38
39#include "includes.h" 39#include "includes.h"
40RCSID("$OpenBSD: packet.c,v 1.97 2002/07/04 08:12:15 deraadt Exp $"); 40RCSID("$OpenBSD: packet.c,v 1.102 2002/12/10 19:47:14 markus Exp $");
41 41
42#include "xmalloc.h" 42#include "xmalloc.h"
43#include "buffer.h" 43#include "buffer.h"
@@ -567,7 +567,7 @@ set_newkeys(int mode)
567 CipherContext *cc; 567 CipherContext *cc;
568 int encrypt; 568 int encrypt;
569 569
570 debug("newkeys: mode %d", mode); 570 debug2("set_newkeys: mode %d", mode);
571 571
572 if (mode == MODE_OUT) { 572 if (mode == MODE_OUT) {
573 cc = &send_context; 573 cc = &send_context;
@@ -577,7 +577,7 @@ set_newkeys(int mode)
577 encrypt = CIPHER_DECRYPT; 577 encrypt = CIPHER_DECRYPT;
578 } 578 }
579 if (newkeys[mode] != NULL) { 579 if (newkeys[mode] != NULL) {
580 debug("newkeys: rekeying"); 580 debug("set_newkeys: rekeying");
581 cipher_cleanup(cc); 581 cipher_cleanup(cc);
582 enc = &newkeys[mode]->enc; 582 enc = &newkeys[mode]->enc;
583 mac = &newkeys[mode]->mac; 583 mac = &newkeys[mode]->mac;
@@ -854,7 +854,7 @@ packet_read_poll1(void)
854 cp = buffer_ptr(&input); 854 cp = buffer_ptr(&input);
855 len = GET_32BIT(cp); 855 len = GET_32BIT(cp);
856 if (len < 1 + 2 + 2 || len > 256 * 1024) 856 if (len < 1 + 2 + 2 || len > 256 * 1024)
857 packet_disconnect("Bad packet length %d.", len); 857 packet_disconnect("Bad packet length %u.", len);
858 padded_len = (len + 8) & ~7; 858 padded_len = (len + 8) & ~7;
859 859
860 /* Check if the packet has been entirely received. */ 860 /* Check if the packet has been entirely received. */
@@ -950,9 +950,9 @@ packet_read_poll2(u_int32_t *seqnr_p)
950 packet_length = GET_32BIT(cp); 950 packet_length = GET_32BIT(cp);
951 if (packet_length < 1 + 4 || packet_length > 256 * 1024) { 951 if (packet_length < 1 + 4 || packet_length > 256 * 1024) {
952 buffer_dump(&incoming_packet); 952 buffer_dump(&incoming_packet);
953 packet_disconnect("Bad packet length %d.", packet_length); 953 packet_disconnect("Bad packet length %u.", packet_length);
954 } 954 }
955 DBG(debug("input: packet len %d", packet_length+4)); 955 DBG(debug("input: packet len %u", packet_length+4));
956 buffer_consume(&input, block_size); 956 buffer_consume(&input, block_size);
957 } 957 }
958 /* we have a partial packet of block_size bytes */ 958 /* we have a partial packet of block_size bytes */
@@ -1240,6 +1240,9 @@ packet_disconnect(const char *fmt,...)
1240 vsnprintf(buf, sizeof(buf), fmt, args); 1240 vsnprintf(buf, sizeof(buf), fmt, args);
1241 va_end(args); 1241 va_end(args);
1242 1242
1243 /* Display the error locally */
1244 log("Disconnecting: %.100s", buf);
1245
1243 /* Send the disconnect message to the other side, and wait for it to get sent. */ 1246 /* Send the disconnect message to the other side, and wait for it to get sent. */
1244 if (compat20) { 1247 if (compat20) {
1245 packet_start(SSH2_MSG_DISCONNECT); 1248 packet_start(SSH2_MSG_DISCONNECT);
@@ -1259,8 +1262,6 @@ packet_disconnect(const char *fmt,...)
1259 /* Close the connection. */ 1262 /* Close the connection. */
1260 packet_close(); 1263 packet_close();
1261 1264
1262 /* Display the error locally and exit. */
1263 log("Disconnecting: %.100s", buf);
1264 fatal_cleanup(); 1265 fatal_cleanup();
1265} 1266}
1266 1267
@@ -1327,16 +1328,26 @@ packet_not_very_much_data_to_write(void)
1327 return buffer_len(&output) < 128 * 1024; 1328 return buffer_len(&output) < 128 * 1024;
1328} 1329}
1329 1330
1331static void
1332packet_set_tos(int interactive)
1333{
1334 int tos = interactive ? IPTOS_LOWDELAY : IPTOS_THROUGHPUT;
1335
1336 if (!packet_connection_is_on_socket() ||
1337 !packet_connection_is_ipv4())
1338 return;
1339 if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, &tos,
1340 sizeof(tos)) < 0)
1341 error("setsockopt IP_TOS %d: %.100s:",
1342 tos, strerror(errno));
1343}
1344
1330/* Informs that the current session is interactive. Sets IP flags for that. */ 1345/* Informs that the current session is interactive. Sets IP flags for that. */
1331 1346
1332void 1347void
1333packet_set_interactive(int interactive) 1348packet_set_interactive(int interactive)
1334{ 1349{
1335 static int called = 0; 1350 static int called = 0;
1336#if defined(IP_TOS) && !defined(IP_TOS_IS_BROKEN)
1337 int lowdelay = IPTOS_LOWDELAY;
1338 int throughput = IPTOS_THROUGHPUT;
1339#endif
1340 1351
1341 if (called) 1352 if (called)
1342 return; 1353 return;
@@ -1347,35 +1358,12 @@ packet_set_interactive(int interactive)
1347 1358
1348 /* Only set socket options if using a socket. */ 1359 /* Only set socket options if using a socket. */
1349 if (!packet_connection_is_on_socket()) 1360 if (!packet_connection_is_on_socket())
1350 return; 1361 if (interactive)
1351 /*
1352 * IPTOS_LOWDELAY and IPTOS_THROUGHPUT are IPv4 only
1353 */
1354 if (interactive) {
1355 /*
1356 * Set IP options for an interactive connection. Use
1357 * IPTOS_LOWDELAY and TCP_NODELAY.
1358 */
1359#if defined(IP_TOS) && !defined(IP_TOS_IS_BROKEN)
1360 if (packet_connection_is_ipv4()) {
1361 if (setsockopt(connection_in, IPPROTO_IP, IP_TOS,
1362 &lowdelay, sizeof(lowdelay)) < 0)
1363 error("setsockopt IPTOS_LOWDELAY: %.100s",
1364 strerror(errno));
1365 }
1366#endif
1367 set_nodelay(connection_in); 1362 set_nodelay(connection_in);
1368 } else if (packet_connection_is_ipv4()) {
1369 /*
1370 * Set IP options for a non-interactive connection. Use
1371 * IPTOS_THROUGHPUT.
1372 */
1373#if defined(IP_TOS) && !defined(IP_TOS_IS_BROKEN) 1363#if defined(IP_TOS) && !defined(IP_TOS_IS_BROKEN)
1374 if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, &throughput, 1364 packet_set_tos(interactive);
1375 sizeof(throughput)) < 0)
1376 error("setsockopt IPTOS_THROUGHPUT: %.100s", strerror(errno));
1377#endif 1365#endif
1378 } 1366
1379} 1367}
1380 1368
1381/* Returns true if the current connection is interactive. */ 1369/* Returns true if the current connection is interactive. */