0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark AndrewsCopyright (C) 2013, 2016 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark AndrewsThis Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark AndrewsLicense, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrewsfile, You can obtain one at http://mozilla.org/MPL/2.0/.
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt Differentiate Services Code Point Support
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt$Id: dscp,v 1.1.2.1 2012/02/24 05:20:36 marka Exp $
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntDifferentiate Services Code Point (DSCP) is implemented in IPv4 using the
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntTOS octet and in IPv6 using the TCLASS octet.
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntRFC 3542 defines the api to manipulate the TCLASS octet as part of
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntthe advanced socket API. TCLASS is settable on both a socket and
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntpacket basis (setsockopt/sendmsg) and the sent value can be retrieved
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntusing recvmsg over UDP. Retrieval is undefined for TCP.
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntThe Advanced socket API was not incorporated into the POSIX socket
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntAPI for IPv6 and may not be completely implemented in any OS.
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntFor TOS setsockopt() supports setting of the field on a persocket
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntbasis. TOS may also be set on a per packet basis on some OS using
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntsendmsg. If it is not supported the sendmsg call reports a error.
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntSupport can only be determined by attempted to send a packet with
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntthe option set. Retrieval of the sent TOS value is retrievable on
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntLinux. This can be determined at compile time.
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntDSCP values need to be compatible with TOS values as it is a re-use
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntof the field.
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntWe will need to be able to probe for the level of DSCP support. We
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntneed to know if we can set it at the socket level, packet level and
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntif we can retrieve the DSCP value sent. This needs to be done
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntindependently for IPv4 and IPv6.
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#define ISC_NET_DSCPRECVV4 0x01 /* Can receive sent DSCP value IPv4 */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#define ISC_NET_DSCPRECVV6 0x02 /* Can receive sent DSCP value IPv6 */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#define ISC_NET_DSCPSETV4 0x04 /* Can set DSCP on socket IPv4 */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#define ISC_NET_DSCPSETV6 0x08 /* Can set DSCP on socket IPv6 */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#define ISC_NET_DSCPPKTV4 0x10 /* Can set DSCP on per packet IPv4 */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#define ISC_NET_DSCPPKTV6 0x20 /* Can set DSCP on per packet IPv6 */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#define ISC_NET_DSCPALL 0x3f /* All valid flags */
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntisc_net_probedscp(void);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt * Probe the level of DSCP support.
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntWe also need to be able to set DSCP values on a per socket basis, per packet
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntbasis and to retrieve dscp values from received packet.
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntSetting dscp on a per socket basis shall be done using isc_socket_dscp.
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntisc_socket_dscp(isc_socket_t *sock, unsigned int dscp);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt *\li 'sock' is a valid socket.
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntisc_socketevent shall be extended to support the sending of and retrieval
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntof DSCP values. If ISC_SOCKEVENTATTR_DSCP is set then isc_socket_sendto2
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntshall set the DSCP value. isc_socket_recv shall set ISC_SOCKEVENTATTR_DSCP
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntand the dscp element if the OS returns the value via recvmsg.
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#define ISC_SOCKEVENTATTR_DSCP 0x00040000U /* public */
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntstruct isc_socketevent {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt ISC_EVENT_COMMON(isc_socketevent_t);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc_result_t result; /*%< OK, EOF, whatever else */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt unsigned int minimum; /*%< minimum i/o for event */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt unsigned int n; /*%< bytes read or written */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt unsigned int offset; /*%< offset into buffer list */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc_region_t region; /*%< for single-buffer i/o */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc_bufferlist_t bufferlist; /*%< list of buffers */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc_sockaddr_t address; /*%< source address */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc_time_t timestamp; /*%< timestamp of packet recv */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt struct in6_pktinfo pktinfo; /*%< ipv6 pktinfo */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc_uint32_t attributes; /*%< see below */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc_eventdestructor_t destroy; /*%< original destructor */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt unsigned int dscp; /*%< UDP dscp value */
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntA convience function will be provided to allocate and intialize the structure.
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntisc_socketevent_t *
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntisc_socket_socketevent(isc_socket_t *sock0, isc_eventtype_t eventtype,
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc_taskaction_t action, const void *arg)
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntNamed needs to be able to set the DSCP value of sent traffic. We should
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntbe able to set DSCP for all TCP connections.
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntFor UDP we should have a default DSCP value for when we can't set this on
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunta per packet basis with the ability to override for specific destinations.
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunttcp-dscp <value>;
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntudp-dscp <value>;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunthttp://bogpeople.com/networking/dscp.shtml list a set of TOS compatible
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntvalues (below).
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntDSCP Name DS Field Value IP Precedence
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt Binary Decimal
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntCS0 000 000 0 0
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntCS1 001 000 8 1
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntAF11 001 010 10 1
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntAF12 001 100 12 1
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntAF13 001 110 14 1
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntCS2 010 000 16 2
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntAF21 010 010 18 2
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntAF22 010 100 20 2
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntAF23 010 110 22 2
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntCS3 011 000 24 3
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntAF31 011 010 26 3
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntAF32 011 100 28 3
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntAF33 011 110 30 3
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntCS4 100 000 32 4
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntAF41 100 010 34 4
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntAF42 100 100 36 4
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntAF43 100 110 38 4
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntCS5 101 000 40 5
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntEF 101 110 46 5
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntCS6 110 000 48 6
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntCS7 111 000 56 7
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntCS Class Selector (RFC 2474)
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntAFxy Assured Forwarding (x=class, y=drop precedence) (RFC2597)
67adc03ef81fb610f8df093b17f55275ee816754Evan HuntEF Expedited Forwarding (RFC 3246)
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntvalue should be one of these or a numeric 0..63. The default value is 0.