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 bd347ef0f..3e2d1249d 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"
@@ -564,7 +564,7 @@ set_newkeys(int mode)
564 CipherContext *cc; 564 CipherContext *cc;
565 int encrypt; 565 int encrypt;
566 566
567 debug("newkeys: mode %d", mode); 567 debug2("set_newkeys: mode %d", mode);
568 568
569 if (mode == MODE_OUT) { 569 if (mode == MODE_OUT) {
570 cc = &send_context; 570 cc = &send_context;
@@ -574,7 +574,7 @@ set_newkeys(int mode)
574 encrypt = CIPHER_DECRYPT; 574 encrypt = CIPHER_DECRYPT;
575 } 575 }
576 if (newkeys[mode] != NULL) { 576 if (newkeys[mode] != NULL) {
577 debug("newkeys: rekeying"); 577 debug("set_newkeys: rekeying");
578 cipher_cleanup(cc); 578 cipher_cleanup(cc);
579 enc = &newkeys[mode]->enc; 579 enc = &newkeys[mode]->enc;
580 mac = &newkeys[mode]->mac; 580 mac = &newkeys[mode]->mac;
@@ -840,7 +840,7 @@ packet_read_poll1(void)
840 cp = buffer_ptr(&input); 840 cp = buffer_ptr(&input);
841 len = GET_32BIT(cp); 841 len = GET_32BIT(cp);
842 if (len < 1 + 2 + 2 || len > 256 * 1024) 842 if (len < 1 + 2 + 2 || len > 256 * 1024)
843 packet_disconnect("Bad packet length %d.", len); 843 packet_disconnect("Bad packet length %u.", len);
844 padded_len = (len + 8) & ~7; 844 padded_len = (len + 8) & ~7;
845 845
846 /* Check if the packet has been entirely received. */ 846 /* Check if the packet has been entirely received. */
@@ -936,9 +936,9 @@ packet_read_poll2(u_int32_t *seqnr_p)
936 packet_length = GET_32BIT(cp); 936 packet_length = GET_32BIT(cp);
937 if (packet_length < 1 + 4 || packet_length > 256 * 1024) { 937 if (packet_length < 1 + 4 || packet_length > 256 * 1024) {
938 buffer_dump(&incoming_packet); 938 buffer_dump(&incoming_packet);
939 packet_disconnect("Bad packet length %d.", packet_length); 939 packet_disconnect("Bad packet length %u.", packet_length);
940 } 940 }
941 DBG(debug("input: packet len %d", packet_length+4)); 941 DBG(debug("input: packet len %u", packet_length+4));
942 buffer_consume(&input, block_size); 942 buffer_consume(&input, block_size);
943 } 943 }
944 /* we have a partial packet of block_size bytes */ 944 /* we have a partial packet of block_size bytes */
@@ -1226,6 +1226,9 @@ packet_disconnect(const char *fmt,...)
1226 vsnprintf(buf, sizeof(buf), fmt, args); 1226 vsnprintf(buf, sizeof(buf), fmt, args);
1227 va_end(args); 1227 va_end(args);
1228 1228
1229 /* Display the error locally */
1230 log("Disconnecting: %.100s", buf);
1231
1229 /* Send the disconnect message to the other side, and wait for it to get sent. */ 1232 /* Send the disconnect message to the other side, and wait for it to get sent. */
1230 if (compat20) { 1233 if (compat20) {
1231 packet_start(SSH2_MSG_DISCONNECT); 1234 packet_start(SSH2_MSG_DISCONNECT);
@@ -1245,8 +1248,6 @@ packet_disconnect(const char *fmt,...)
1245 /* Close the connection. */ 1248 /* Close the connection. */
1246 packet_close(); 1249 packet_close();
1247 1250
1248 /* Display the error locally and exit. */
1249 log("Disconnecting: %.100s", buf);
1250 fatal_cleanup(); 1251 fatal_cleanup();
1251} 1252}
1252 1253
@@ -1313,16 +1314,26 @@ packet_not_very_much_data_to_write(void)
1313 return buffer_len(&output) < 128 * 1024; 1314 return buffer_len(&output) < 128 * 1024;
1314} 1315}
1315 1316
1317static void
1318packet_set_tos(int interactive)
1319{
1320 int tos = interactive ? IPTOS_LOWDELAY : IPTOS_THROUGHPUT;
1321
1322 if (!packet_connection_is_on_socket() ||
1323 !packet_connection_is_ipv4())
1324 return;
1325 if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, &tos,
1326 sizeof(tos)) < 0)
1327 error("setsockopt IP_TOS %d: %.100s:",
1328 tos, strerror(errno));
1329}
1330
1316/* Informs that the current session is interactive. Sets IP flags for that. */ 1331/* Informs that the current session is interactive. Sets IP flags for that. */
1317 1332
1318void 1333void
1319packet_set_interactive(int interactive) 1334packet_set_interactive(int interactive)
1320{ 1335{
1321 static int called = 0; 1336 static int called = 0;
1322#if defined(IP_TOS) && !defined(IP_TOS_IS_BROKEN)
1323 int lowdelay = IPTOS_LOWDELAY;
1324 int throughput = IPTOS_THROUGHPUT;
1325#endif
1326 1337
1327 if (called) 1338 if (called)
1328 return; 1339 return;
@@ -1333,35 +1344,12 @@ packet_set_interactive(int interactive)
1333 1344
1334 /* Only set socket options if using a socket. */ 1345 /* Only set socket options if using a socket. */
1335 if (!packet_connection_is_on_socket()) 1346 if (!packet_connection_is_on_socket())
1336 return; 1347 if (interactive)
1337 /*
1338 * IPTOS_LOWDELAY and IPTOS_THROUGHPUT are IPv4 only
1339 */
1340 if (interactive) {
1341 /*
1342 * Set IP options for an interactive connection. Use
1343 * IPTOS_LOWDELAY and TCP_NODELAY.
1344 */
1345#if defined(IP_TOS) && !defined(IP_TOS_IS_BROKEN)
1346 if (packet_connection_is_ipv4()) {
1347 if (setsockopt(connection_in, IPPROTO_IP, IP_TOS,
1348 &lowdelay, sizeof(lowdelay)) < 0)
1349 error("setsockopt IPTOS_LOWDELAY: %.100s",
1350 strerror(errno));
1351 }
1352#endif
1353 set_nodelay(connection_in); 1348 set_nodelay(connection_in);
1354 } else if (packet_connection_is_ipv4()) {
1355 /*
1356 * Set IP options for a non-interactive connection. Use
1357 * IPTOS_THROUGHPUT.
1358 */
1359#if defined(IP_TOS) && !defined(IP_TOS_IS_BROKEN) 1349#if defined(IP_TOS) && !defined(IP_TOS_IS_BROKEN)
1360 if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, &throughput, 1350 packet_set_tos(interactive);
1361 sizeof(throughput)) < 0)
1362 error("setsockopt IPTOS_THROUGHPUT: %.100s", strerror(errno));
1363#endif 1351#endif
1364 } 1352
1365} 1353}
1366 1354
1367/* Returns true if the current connection is interactive. */ 1355/* Returns true if the current connection is interactive. */