sk: Added address family as inargument in sk_set_priority

Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
master
Anders Selhammer 2018-10-24 13:07:06 +00:00 committed by Richard Cochran
parent d88b4ff229
commit 80b1d25dfd
4 changed files with 25 additions and 11 deletions

21
sk.c
View File

@ -406,13 +406,26 @@ int sk_receive(int fd, void *buf, int buflen,
return cnt; return cnt;
} }
int sk_set_priority(int fd, uint8_t dscp) int sk_set_priority(int fd, int family, uint8_t dscp)
{ {
int tos; int level, optname, tos;
socklen_t tos_len; socklen_t tos_len;
switch (family) {
case AF_INET:
level = IPPROTO_IP;
optname = IP_TOS;
break;
case AF_INET6:
level = IPPROTO_IPV6;
optname = IPV6_TCLASS;
break;
default:
return -1;
}
tos_len = sizeof(tos); tos_len = sizeof(tos);
if (getsockopt(fd, SOL_IP, IP_TOS, &tos, &tos_len) < 0) { if (getsockopt(fd, level, optname, &tos, &tos_len) < 0) {
tos = 0; tos = 0;
} }
@ -422,7 +435,7 @@ int sk_set_priority(int fd, uint8_t dscp)
/* set new DSCP value */ /* set new DSCP value */
tos |= dscp<<2; tos |= dscp<<2;
tos_len = sizeof(tos); tos_len = sizeof(tos);
if (setsockopt(fd, SOL_IP, IP_TOS, &tos, tos_len) < 0) { if (setsockopt(fd, level, optname, &tos, tos_len) < 0) {
return -1; return -1;
} }

7
sk.h
View File

@ -111,11 +111,12 @@ int sk_receive(int fd, void *buf, int buflen,
/** /**
* Set DSCP value for socket. * Set DSCP value for socket.
* @param fd An open socket. * @param fd An open socket.
* @param dscp The desired DSCP code. * @param family The address family in use: AF_INET or AF_INET6
* @param dscp The desired DSCP code.
* @return Zero on success, negative on failure * @return Zero on success, negative on failure
*/ */
int sk_set_priority(int fd, uint8_t dscp); int sk_set_priority(int fd, int family, uint8_t dscp);
/** /**
* Enable time stamping on a given network interface. * Enable time stamping on a given network interface.

4
udp.c
View File

@ -188,10 +188,10 @@ static int udp_open(struct transport *t, struct interface *iface,
event_dscp = config_get_int(t->cfg, NULL, "dscp_event"); event_dscp = config_get_int(t->cfg, NULL, "dscp_event");
general_dscp = config_get_int(t->cfg, NULL, "dscp_general"); general_dscp = config_get_int(t->cfg, NULL, "dscp_general");
if (event_dscp && sk_set_priority(efd, event_dscp)) { if (event_dscp && sk_set_priority(efd, AF_INET, event_dscp)) {
pr_warning("Failed to set event DSCP priority."); pr_warning("Failed to set event DSCP priority.");
} }
if (general_dscp && sk_set_priority(gfd, general_dscp)) { if (general_dscp && sk_set_priority(gfd, AF_INET, general_dscp)) {
pr_warning("Failed to set general DSCP priority."); pr_warning("Failed to set general DSCP priority.");
} }

4
udp6.c
View File

@ -199,10 +199,10 @@ static int udp6_open(struct transport *t, struct interface *iface,
event_dscp = config_get_int(t->cfg, NULL, "dscp_event"); event_dscp = config_get_int(t->cfg, NULL, "dscp_event");
general_dscp = config_get_int(t->cfg, NULL, "dscp_general"); general_dscp = config_get_int(t->cfg, NULL, "dscp_general");
if (event_dscp && sk_set_priority(efd, event_dscp)) { if (event_dscp && sk_set_priority(efd, AF_INET6, event_dscp)) {
pr_warning("Failed to set event DSCP priority."); pr_warning("Failed to set event DSCP priority.");
} }
if (general_dscp && sk_set_priority(gfd, general_dscp)) { if (general_dscp && sk_set_priority(gfd, AF_INET6, general_dscp)) {
pr_warning("Failed to set general DSCP priority."); pr_warning("Failed to set general DSCP priority.");
} }