Skip to content

Commit 9b4b2a6

Browse files
author
Catalin(ux) M. BOIE
committed
Added possibility to force skb priority field (SO_PRIORITY).
1 parent 648b09b commit 9b4b2a6

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

README

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ Examples:
9393
export LD_PRELOAD=${LD_PRELOAD}:/usr/lib/force_bind.so
9494
your_program_here
9595

96+
14: Force priority (between 0 and 6 for non-root users). You can
97+
use 'tc' command from iproute to set-up 'prio' qdisc and to
98+
assign prio to queues:
99+
export FORCE_NET_VERBOSE=1
100+
export FORCE_NET_PRIO=2
101+
export LD_PRELOAD=${LD_PRELOAD}:/usr/lib/force_bind.so
102+
your_program_here
103+
96104
Installation:
97105
- ./configure
98106
- make

force_bind.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ static unsigned int force_nodelay = 0, nodelay;
111111
static unsigned long long bw_limit_per_socket = 0;
112112
static unsigned int force_flowinfo = 0, flowinfo;
113113
static unsigned int force_fwmark = 0, fwmark;
114+
static unsigned int force_prio = 0, prio;
114115
static struct private bw_global;
115116
static struct info fdinfo;
116117
static unsigned int verbose = 0;
@@ -386,6 +387,15 @@ static void init(void)
386387
fwmark);
387388
}
388389

390+
/* prio */
391+
x = getenv("FORCE_NET_PRIO");
392+
if (x != NULL) {
393+
force_prio = 1;
394+
prio = strtoul(x, NULL, 0);
395+
my_syslog(LOG_INFO, "force_bind: Force prio to %u.\n",
396+
prio);
397+
}
398+
389399

390400
old_bind = dlsym(RTLD_NEXT, "bind");
391401
if (old_bind == NULL) {
@@ -603,6 +613,20 @@ static int set_fwmark(int sockfd)
603613
return ret;
604614
}
605615

616+
static int set_prio(int sockfd)
617+
{
618+
int ret;
619+
620+
if (force_prio == 0)
621+
return 0;
622+
623+
ret = old_setsockopt(sockfd, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio));
624+
my_syslog(LOG_INFO, "force_bind: changing fwmark to 0x%x (ret=%d(%s)) [%d].\n",
625+
prio, ret, strerror(errno), sockfd);
626+
627+
return ret;
628+
}
629+
606630
/*
607631
* Alters a struct sockaddr, based on environment variables
608632
*/
@@ -753,6 +777,8 @@ int setsockopt(int sockfd, int level, int optname, const void *optval,
753777
return set_reuseaddr(sockfd);
754778
if (optname == SO_MARK)
755779
return set_fwmark(sockfd);
780+
if (optname == SO_PRIORITY)
781+
return set_prio(sockfd);
756782
}
757783

758784
if (level == IPPROTO_IP) {
@@ -808,6 +834,7 @@ void socket_create_callback(const int sockfd, int domain, int type)
808834
set_reuseaddr(sockfd);
809835
set_nodelay(sockfd);
810836
set_fwmark(sockfd);
837+
set_prio(sockfd);
811838

812839
p.domain = domain;
813840
p.type = type;

test_client3.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
export FORCE_NET_VERBOSE=1
4+
export FORCE_NET_PRIO=2
5+
6+
export LD_PRELOAD="${LD_PRELOAD}:./force_bind.so"
7+
8+
strace -o ${0}.strace -f -s100 ./test_client "$@"

0 commit comments

Comments
 (0)