summaryrefslogtreecommitdiff
path: root/packet.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2011-05-15 08:43:13 +1000
committerDamien Miller <djm@mindrot.org>2011-05-15 08:43:13 +1000
commitd2ac5d74b4dd51d8e28615ea7af1ab5372a3db2b (patch)
tree2c2a027d9ce52d3d6ba7a78e7e16bf4749e53421 /packet.c
parent78c40c321bd4168bb2a17230f242d6aea684692a (diff)
- djm@cvs.openbsd.org 2011/05/06 21:14:05
[packet.c packet.h] set traffic class for IPv6 traffic as we do for IPv4 TOS; patch from lionel AT mamane.lu via Colin Watson in bz#1855; ok markus@
Diffstat (limited to 'packet.c')
-rw-r--r--packet.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/packet.c b/packet.c
index b4e01f716..f323e7eeb 100644
--- a/packet.c
+++ b/packet.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: packet.c,v 1.172 2010/11/13 23:27:50 djm Exp $ */ 1/* $OpenBSD: packet.c,v 1.173 2011/05/06 21:14:05 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -422,10 +422,8 @@ packet_set_state(int mode, u_int32_t seqnr, u_int64_t blocks, u_int32_t packets,
422 state->bytes = bytes; 422 state->bytes = bytes;
423} 423}
424 424
425/* returns 1 if connection is via ipv4 */ 425static int
426 426packet_connection_af(void)
427int
428packet_connection_is_ipv4(void)
429{ 427{
430 struct sockaddr_storage to; 428 struct sockaddr_storage to;
431 socklen_t tolen = sizeof(to); 429 socklen_t tolen = sizeof(to);
@@ -439,9 +437,9 @@ packet_connection_is_ipv4(void)
439#ifdef IPV4_IN_IPV6 437#ifdef IPV4_IN_IPV6
440 if (to.ss_family == AF_INET6 && 438 if (to.ss_family == AF_INET6 &&
441 IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)&to)->sin6_addr)) 439 IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)&to)->sin6_addr))
442 return 1; 440 return AF_INET;
443#endif 441#endif
444 return 0; 442 return to.ss_family;
445} 443}
446 444
447/* Sets the connection into non-blocking mode. */ 445/* Sets the connection into non-blocking mode. */
@@ -1752,16 +1750,30 @@ packet_not_very_much_data_to_write(void)
1752static void 1750static void
1753packet_set_tos(int tos) 1751packet_set_tos(int tos)
1754{ 1752{
1755#if defined(IP_TOS) && !defined(IP_TOS_IS_BROKEN) 1753#ifndef IP_TOS_IS_BROKEN
1756 if (!packet_connection_is_on_socket() || 1754 if (!packet_connection_is_on_socket())
1757 !packet_connection_is_ipv4())
1758 return; 1755 return;
1759 debug3("%s: set IP_TOS 0x%02x", __func__, tos); 1756 switch (packet_connection_af()) {
1760 if (setsockopt(active_state->connection_in, IPPROTO_IP, IP_TOS, &tos, 1757# ifdef IP_TOS
1761 sizeof(tos)) < 0) 1758 case AF_INET:
1762 error("setsockopt IP_TOS %d: %.100s:", 1759 debug3("%s: set IP_TOS 0x%02x", __func__, tos);
1763 tos, strerror(errno)); 1760 if (setsockopt(active_state->connection_in,
1764#endif 1761 IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0)
1762 error("setsockopt IP_TOS %d: %.100s:",
1763 tos, strerror(errno));
1764 break;
1765# endif /* IP_TOS */
1766# ifdef IPV6_TCLASS
1767 case AF_INET6:
1768 debug3("%s: set IPV6_TCLASS 0x%02x", __func__, tos);
1769 if (setsockopt(active_state->connection_in,
1770 IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos)) < 0)
1771 error("setsockopt IPV6_TCLASS %d: %.100s:",
1772 tos, strerror(errno));
1773 break;
1774 }
1775# endif /* IPV6_TCLASS */
1776#endif /* IP_TOS_IS_BROKEN */
1765} 1777}
1766 1778
1767/* Informs that the current session is interactive. Sets IP flags for that. */ 1779/* Informs that the current session is interactive. Sets IP flags for that. */