@@ -111,6 +111,7 @@ static unsigned int force_nodelay = 0, nodelay;
111111static unsigned long long bw_limit_per_socket = 0 ;
112112static unsigned int force_flowinfo = 0 , flowinfo ;
113113static unsigned int force_fwmark = 0 , fwmark ;
114+ static unsigned int force_prio = 0 , prio ;
114115static struct private bw_global ;
115116static struct info fdinfo ;
116117static 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 ;
0 commit comments