From: divverent Date: Sat, 25 May 2013 14:08:53 +0000 (+0000) Subject: Implement DSCP for ToS according to RFC2474 / RFC4594 X-Git-Tag: xonotic-v0.8.0~96^2~89 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3368a3b1dd0e71f33bc40c8fe47ad5b2a0255d2f;p=xonotic%2Fdarkplaces.git Implement DSCP for ToS according to RFC2474 / RFC4594 From: Merlijn Hofstra git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11951 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/lhnet.c b/lhnet.c index fc1acf2b..e3bc6b71 100644 --- a/lhnet.c +++ b/lhnet.c @@ -723,6 +723,7 @@ lhnetpacket_t; static int lhnet_active; static lhnetsocket_t lhnet_socketlist; static lhnetpacket_t lhnet_packetlist; +static int lhnet_default_dscp = 0; #ifdef WIN32 static int lhnet_didWSAStartup = 0; static WSADATA lhnet_winsockdata; @@ -742,6 +743,18 @@ void LHNET_Init(void) #endif } +int LHNET_DefaultDSCP(int dscp) +{ +#ifdef IP_TOS + int prev = lhnet_default_dscp; + if(dscp >= 0) + lhnet_default_dscp = dscp; + return prev; +#else + return -1; +#endif +} + void LHNET_Shutdown(void) { lhnetpacket_t *p; @@ -980,6 +993,13 @@ lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address) int i = 1; // enable broadcast on this socket setsockopt(lhnetsocket->inetsocket, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof(i)); +#ifdef IP_TOS + { + // enable DSCP for ToS support + int tos = lhnet_default_dscp << 2; + setsockopt(lhnetsocket->inetsocket, IPPROTO_IP, IP_TOS, (char *) &tos, sizeof(tos)); + } +#endif lhnetsocket->next = &lhnet_socketlist; lhnetsocket->prev = lhnetsocket->next->prev; lhnetsocket->next->prev = lhnetsocket; diff --git a/lhnet.h b/lhnet.h index 518ccdf9..e66e5a5d 100644 --- a/lhnet.h +++ b/lhnet.h @@ -40,6 +40,7 @@ lhnetsocket_t; void LHNET_Init(void); void LHNET_Shutdown(void); +int LHNET_DefaultDSCP(int dscp); // < 0: query; >= 0: set (returns previous value) void LHNET_SleepUntilPacket_Microseconds(int microseconds); lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address); void LHNET_CloseSocket(lhnetsocket_t *lhnetsocket); diff --git a/netconn.c b/netconn.c index 93f2389b..aa8bf94a 100755 --- a/netconn.c +++ b/netconn.c @@ -93,6 +93,7 @@ static cvar_t net_slist_timeout = {0, "net_slist_timeout", "4", "how long to lis static cvar_t net_slist_pause = {0, "net_slist_pause", "0", "when set to 1, the server list won't update until it is set back to 0"}; static cvar_t net_slist_maxtries = {0, "net_slist_maxtries", "3", "how many times to ask the same server for information (more times gives better ping reports but takes longer)"}; static cvar_t net_slist_favorites = {CVAR_SAVE | CVAR_NQUSERINFOHACK, "net_slist_favorites", "", "contains a list of IP addresses and ports to always query explicitly"}; +static cvar_t net_tos_dscp = {CVAR_SAVE, "net_tos_dscp", "32", "DiffServ Codepoint for network sockets (may need game restart to apply)"}; static cvar_t gameversion = {0, "gameversion", "0", "version of game data (mod-specific) to be sent to querying clients"}; static cvar_t gameversion_min = {0, "gameversion_min", "-1", "minimum version of game data (mod-specific), when client and server gameversion mismatch in the server browser the server is shown as incompatible; if -1, gameversion is used alone"}; static cvar_t gameversion_max = {0, "gameversion_max", "-1", "maximum version of game data (mod-specific), when client and server gameversion mismatch in the server browser the server is shown as incompatible; if -1, gameversion is used alone"}; @@ -1094,6 +1095,9 @@ void NetConn_UpdateSockets(void) { int i, j; + // TODO add logic to automatically close sockets if needed + LHNET_DefaultDSCP(net_tos_dscp.integer); + if (cls.state != ca_dedicated) { if (clientport2 != cl_netport.integer) @@ -3686,6 +3690,8 @@ void NetConn_Init(void) Cvar_RegisterVariable(&net_slist_maxtries); Cvar_RegisterVariable(&net_slist_favorites); Cvar_RegisterVariable(&net_slist_pause); + if(LHNET_DefaultDSCP(-1) >= 0) // register cvar only if supported + Cvar_RegisterVariable(&net_tos_dscp); Cvar_RegisterVariable(&net_messagetimeout); Cvar_RegisterVariable(&net_connecttimeout); Cvar_RegisterVariable(&net_connectfloodblockingtimeout);