1 From: Dave Taht <d@taht.net>
3 In the bufferbloat age, anything that can make for a kinder, gentler bulk
4 transfer protocol seems desirable.
6 This add support for user and server selectable congestion control algorithms.
9 --congestion-alg=lp # For the tcp-lp algorithm on the command line
12 --diffserv=8 for setting the CS1 bit
14 Also available in rsync daemon modules:
17 congestion alg = westwood # for a wireless connection
20 This could be improved by being able to specify a list of congestion algorithms
21 to try, symbolic names for diffserv (CS1), a better name than 'congestion-alg',
22 and some error checking.
24 To use this patch, run these commands for a successful build:
26 patch -p1 <patches/congestion.diff
27 ./configure (optional if already run)
30 based-on: f3873b3d88b61167b106e7b9227a20147f8f6197
31 diff --git a/loadparm.c b/loadparm.c
34 @@ -109,6 +109,7 @@ typedef struct {
38 + char *congestion_alg;
42 @@ -134,6 +135,7 @@ typedef struct {
43 /* NOTE: update this macro if the last char* variable changes! */
44 #define LOCAL_STRING_COUNT() (offsetof(local_vars, uid) / sizeof (char*) + 1)
50 @@ -185,6 +187,7 @@ static const all_vars Defaults = {
51 /* auth_users; */ NULL,
54 + /* congestion_alg; */ NULL,
55 /* dont_compress; */ DEFAULT_DONT_COMPRESS,
57 /* exclude_from; */ NULL,
58 @@ -208,6 +211,7 @@ static const all_vars Defaults = {
63 /* max_connections; */ 0,
64 /* max_verbosity; */ 1,
65 /* syslog_facility; */ LOG_DAEMON,
66 @@ -322,6 +326,8 @@ static struct parm_struct parm_table[] =
67 {"auth users", P_STRING, P_LOCAL, &Vars.l.auth_users, NULL,0},
68 {"charset", P_STRING, P_LOCAL, &Vars.l.charset, NULL,0},
69 {"comment", P_STRING, P_LOCAL, &Vars.l.comment, NULL,0},
70 + {"congestion alg", P_STRING, P_LOCAL, &Vars.l.congestion_alg, NULL,0},
71 + {"diffserv", P_INTEGER,P_LOCAL, &Vars.l.diffserv, NULL,0},
72 {"dont compress", P_STRING, P_LOCAL, &Vars.l.dont_compress, NULL,0},
73 {"exclude from", P_STRING, P_LOCAL, &Vars.l.exclude_from, NULL,0},
74 {"exclude", P_STRING, P_LOCAL, &Vars.l.exclude, NULL,0},
75 @@ -454,6 +460,7 @@ FN_GLOBAL_INTEGER(lp_rsync_port, &Vars.g.rsync_port)
76 FN_LOCAL_STRING(lp_auth_users, auth_users)
77 FN_LOCAL_STRING(lp_charset, charset)
78 FN_LOCAL_STRING(lp_comment, comment)
79 +FN_LOCAL_STRING(lp_congestion_alg, congestion_alg)
80 FN_LOCAL_STRING(lp_dont_compress, dont_compress)
81 FN_LOCAL_STRING(lp_exclude, exclude)
82 FN_LOCAL_STRING(lp_exclude_from, exclude_from)
83 @@ -477,6 +484,7 @@ FN_LOCAL_STRING(lp_secrets_file, secrets_file)
84 FN_LOCAL_STRING(lp_temp_dir, temp_dir)
85 FN_LOCAL_STRING(lp_uid, uid)
87 +FN_LOCAL_INTEGER(lp_diffserv, diffserv)
88 FN_LOCAL_INTEGER(lp_max_connections, max_connections)
89 FN_LOCAL_INTEGER(lp_max_verbosity, max_verbosity)
90 FN_LOCAL_INTEGER(lp_syslog_facility, syslog_facility)
91 diff --git a/options.c b/options.c
94 @@ -71,6 +71,8 @@ int delete_during = 0;
95 int delete_before = 0;
97 int delete_excluded = 0;
99 +char *congestion_alg = NULL;
100 int remove_source_files = 0;
101 int one_file_system = 0;
102 int protocol_version = PROTOCOL_VERSION;
103 @@ -780,6 +782,8 @@ void usage(enum logcode F)
104 rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n");
105 rprintf(F," --port=PORT specify double-colon alternate port number\n");
106 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
107 + rprintf(F," --diffserv=[0-63] specify diffserv setting \n");
108 + rprintf(F," --congestion-alg=STRING choose a congestion algo\n");
109 rprintf(F," --blocking-io use blocking I/O for the remote shell\n");
110 rprintf(F," --stats give some file-transfer stats\n");
111 rprintf(F," -8, --8-bit-output leave high-bit chars unescaped in output\n");
112 @@ -1041,6 +1045,8 @@ static struct poptOption long_options[] = {
114 {"remote-option", 'M', POPT_ARG_STRING, 0, 'M', 0, 0 },
115 {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
116 + {"congestion-alg", 0, POPT_ARG_STRING, &congestion_alg, 0, 0, 0 },
117 + {"diffserv", 0, POPT_ARG_INT, &diffserv, 0, 0, 0 },
118 {"checksum-seed", 0, POPT_ARG_INT, &checksum_seed, 0, 0, 0 },
119 {"server", 0, POPT_ARG_NONE, 0, OPT_SERVER, 0, 0 },
120 {"sender", 0, POPT_ARG_NONE, 0, OPT_SENDER, 0, 0 },
121 @@ -1068,6 +1074,8 @@ static void daemon_usage(enum logcode F)
122 rprintf(F," --log-file=FILE override the \"log file\" setting\n");
123 rprintf(F," --log-file-format=FMT override the \"log format\" setting\n");
124 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
125 + rprintf(F," --diffserv=[0-63] specify diffserv setting \n");
126 + rprintf(F," --congestion-alg=STRING choose a congestion algo\n");
127 rprintf(F," -v, --verbose increase verbosity\n");
128 rprintf(F," -4, --ipv4 prefer IPv4\n");
129 rprintf(F," -6, --ipv6 prefer IPv6\n");
130 diff --git a/socket.c b/socket.c
133 @@ -38,6 +38,8 @@ extern char *bind_address;
134 extern char *sockopts;
135 extern int default_af_hint;
136 extern int connect_timeout;
137 +extern int diffserv;
138 +extern char *congestion_alg;
140 #ifdef HAVE_SIGACTION
141 static struct sigaction sigact;
142 @@ -166,6 +168,37 @@ static void contimeout_handler(UNUSED(int val))
143 connect_timeout = -1;
146 +/* Set special socket options
148 + * Diffserv is a value in the range of 0-63, and needs to be shifted left
149 + * 2 places AND treated differently for ipv4 and ipv6.
150 + * Setting TCP congestion control is rather Linux specific (at the moment)
151 + * and sends a varying length string to setsockopt rather than an integer
155 +void set_special_sockopts(int s)
157 +#if defined(TCP_CONGESTION)
158 + if (congestion_alg) {
159 + if (setsockopt(s, SOL_TCP, TCP_CONGESTION, congestion_alg, strlen(congestion_alg)) == -1)
160 + rprintf(FINFO, "Couldn't set %s congestion algorithm\n", congestion_alg);
164 +/* setting the diffserv/tos bits is different on ipv6 and
165 + * ipv4, so we just hammer down on both and ignore the result
166 + * And ipv6 demands an int for v. I didn't write the spec.
169 + int v = (diffserv & 63) <<2;
170 + setsockopt(s,IPPROTO_IP, IP_TOS, &v, sizeof(v));
171 +#if defined(IPV6_TCLASS)
172 + setsockopt(s,IPPROTO_IPV6, IPV6_TCLASS, &v, sizeof(v));
177 /* Open a socket to a tcp remote host with the specified port.
179 * Based on code from Warren. Proxy support by Stephen Rothwell.
180 @@ -275,6 +308,7 @@ int open_socket_out(char *host, int port, const char *bind_addr,
181 alarm(connect_timeout);
184 + set_special_sockopts(s);
185 set_socket_options(s, sockopts);
186 while (connect(s, res->ai_addr, res->ai_addrlen) < 0) {
187 if (connect_timeout < 0)
188 @@ -449,6 +483,7 @@ static int *open_socket_in(int type, int port, const char *bind_addr,
192 + set_special_sockopts(s);
193 setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
194 (char *)&one, sizeof one);