-# Copyright (c) 2010, 2012, 2014 Nicira, Inc.
+# Copyright (c) 2010, 2012, 2014, 2015 Nicira, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
is_addr_inet = is_valid_ipv4_address(address[0])
if is_addr_inet:
sock = socket.socket(socket.AF_INET, style, 0)
+ family = socket.AF_INET
else:
sock = socket.socket(socket.AF_INET6, style, 0)
+ family = socket.AF_INET6
except socket.error, e:
return get_exception_errno(e), None
try:
set_nonblocking(sock)
- set_dscp(sock, dscp)
+ set_dscp(sock, family, dscp)
try:
sock.connect(address)
except socket.error, e:
% os.strerror(get_exception_errno(e)))
-def set_dscp(sock, dscp):
+def set_dscp(sock, family, dscp):
if dscp > 63:
raise ValueError("Invalid dscp %d" % dscp)
+
val = dscp << 2
- sock.setsockopt(socket.IPPROTO_IP, socket.IP_TOS, val)
+ if family == socket.AF_INET:
+ try:
+ sock.setsockopt(socket.IPPROTO_IP, socket.IP_TOS, val)
+ except socket.error, e:
+ raise
+ elif family == socket.AF_INET6:
+ try:
+ sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_TCLASS, val)
+ except socket.error, e:
+ raise
+ else:
+ raise