]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Implement DSCP for ToS according to RFC2474 / RFC4594
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 25 May 2013 14:08:53 +0000 (14:08 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 25 May 2013 14:08:53 +0000 (14:08 +0000)
From: Merlijn Hofstra <merlijn@Merlijns-MacBook-Air.local>

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11951 d7cf8633-e32d-0410-b094-e92efae38249

lhnet.c
lhnet.h
netconn.c

diff --git a/lhnet.c b/lhnet.c
index fc1acf2b056724cc983cc8bbbb4be46bd332fd1c..e3bc6b712186f54dd511fd4165ddfc2f54fa3c88 100644 (file)
--- 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 518ccdf91566a5bda09fa5fe27776b7ed7d5a40f..e66e5a5d8f9ca8068d037a00ae943a51edf573e1 100644 (file)
--- 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);
index 93f2389b2ad8c8040d02d2c9ee5f1f167591c49a..aa8bf94aeef06c1447d8fc62d5fd1c74fcb96596 100755 (executable)
--- 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);