mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 06:15:47 +00:00
vswitch: Use consistent representation of DSCP bits.
There are two sensible ways to represent the 6 DSCP bits of an IP packet. One could represent them as an integer in the range 0 to 63. Or one could represent them as they would appear in the tos field (0 to 63) << 2. Before this patch, OVS had used the former method for the DSCP bits in the Queue Table, and the latter for the DSCP in the Controller and Manager tables. Since the ability to set DSCP bits in the Controller and Manager tables is so new that it hasn't been released yet, this patch changes it to use the existing style employed in the Queue table. Hopefully this should make the code and configuration less confusing. Signed-off-by: Ethan Jackson <ethan@nicira.com>
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <config.h>
|
||||
#include "socket-util.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <net/if.h>
|
||||
@@ -81,6 +82,21 @@ set_nonblocking(int fd)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
set_dscp(int fd, uint8_t dscp)
|
||||
{
|
||||
if (dscp > 63) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
dscp = dscp << 2;
|
||||
if (setsockopt(fd, IPPROTO_IP, IP_TOS, &dscp, sizeof dscp)) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool
|
||||
rlim_is_finite(rlim_t limit)
|
||||
{
|
||||
@@ -546,7 +562,9 @@ exit:
|
||||
* If 'sinp' is non-null, then on success the target address is stored into
|
||||
* '*sinp'.
|
||||
*
|
||||
* 'dscp' becomes the DSCP bits in the IP headers for the new connection. */
|
||||
* 'dscp' becomes the DSCP bits in the IP headers for the new connection. It
|
||||
* should be in the range [0, 63] and will automatically be shifted to the
|
||||
* appropriately place in the IP tos field. */
|
||||
int
|
||||
inet_open_active(int style, const char *target, uint16_t default_port,
|
||||
struct sockaddr_in *sinp, int *fdp, uint8_t dscp)
|
||||
@@ -573,12 +591,12 @@ inet_open_active(int style, const char *target, uint16_t default_port,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* The socket options set here ensure that the TOS bits are set during
|
||||
* the connection establishment. If set after connect(), the handshake
|
||||
* SYN frames will be sent with a TOS of 0. */
|
||||
if (setsockopt(fd, IPPROTO_IP, IP_TOS, &dscp, sizeof dscp)) {
|
||||
VLOG_ERR("%s: socket: %s", target, strerror(errno));
|
||||
error = errno;
|
||||
/* The dscp bits must be configured before connect() to ensure that the TOS
|
||||
* field is set during the connection establishment. If set after
|
||||
* connect(), the handshake SYN frames will be sent with a TOS of 0. */
|
||||
error = set_dscp(fd, dscp);
|
||||
if (error) {
|
||||
VLOG_ERR("%s: socket: %s", target, strerror(error));
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@@ -669,7 +687,9 @@ exit:
|
||||
* If 'sinp' is non-null, then on success the bound address is stored into
|
||||
* '*sinp'.
|
||||
*
|
||||
* 'dscp' becomes the DSCP bits in the IP headers for the new connection. */
|
||||
* 'dscp' becomes the DSCP bits in the IP headers for the new connection. It
|
||||
* should be in the range [0, 63] and will automatically be shifted to the
|
||||
* appropriately place in the IP tos field. */
|
||||
int
|
||||
inet_open_passive(int style, const char *target, int default_port,
|
||||
struct sockaddr_in *sinp, uint8_t dscp)
|
||||
@@ -707,12 +727,12 @@ inet_open_passive(int style, const char *target, int default_port,
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* The socket options set here ensure that the TOS bits are set during
|
||||
* the connection establishment. If set after connect(), the handshake
|
||||
* SYN frames will be sent with a TOS of 0. */
|
||||
if (setsockopt(fd, IPPROTO_IP, IP_TOS, &dscp, sizeof dscp)) {
|
||||
VLOG_ERR("%s: socket: %s", target, strerror(errno));
|
||||
error = errno;
|
||||
/* The dscp bits must be configured before connect() to ensure that the TOS
|
||||
* field is set during the connection establishment. If set after
|
||||
* connect(), the handshake SYN frames will be sent with a TOS of 0. */
|
||||
error = set_dscp(fd, dscp);
|
||||
if (error) {
|
||||
VLOG_ERR("%s: socket: %s", target, strerror(error));
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user