add patch to revert condition that can set RTT=0
[linux-2.6.git] / linux-2.6-710-xidmask.patch
1 diff -Ndur linux-2.6.32-700/fs/proc/web100.c linux-2.6.32-700-xidmask/fs/proc/web100.c
2 --- linux-2.6.32-700/fs/proc/web100.c   2013-01-10 14:18:50.429337747 -0500
3 +++ linux-2.6.32-700-xidmask/fs/proc/web100.c   2013-02-06 17:36:52.308961450 -0500
4 @@ -427,10 +427,10 @@
5                 local_port = vars->LocalPort;
6                 remote_port = vars->RemPort;
7                 
8 -               len += v6addr_str(tmpbuf + len, (short *)&vars->LocalAddress.v6addr.addr);
9 -               len += sprintf(tmpbuf + len, ".%d ", local_port);
10 -               len += v6addr_str(tmpbuf + len, (short *)&vars->RemAddress.v6addr.addr);
11 -               len += sprintf(tmpbuf + len, ".%d\n", remote_port);
12 +               len += snprintf(tmpbuf + len, sizeof(tmpbuf) - len, "%pI6", &vars->LocalAddress.v6addr.addr);
13 +               len += snprintf(tmpbuf + len, sizeof(tmpbuf) - len, ".%d ", local_port);
14 +               len += snprintf(tmpbuf + len, sizeof(tmpbuf) - len, "%pI6", &vars->RemAddress.v6addr.addr);
15 +               len += snprintf(tmpbuf + len, sizeof(tmpbuf) - len, ".%d\n", remote_port);
16         } else {
17                 printk(KERN_ERR "connection_spec_ascii_read: LocalAddressType invalid\n");
18                 return 0;
19 @@ -655,7 +655,8 @@
20         
21         stats = web100stats_first;
22         while (stats && n < max) {
23 -               if (!stats->wc_dead) {
24 +               // only return readable stats
25 +               if ( 1 == vx_can_read_stats(stats) ) {
26                         if (pos <= 0)
27                                 cids[n++] = stats->wc_cid;
28                         else
29 diff -Ndur linux-2.6.32-700/include/linux/vserver/context.h linux-2.6.32-700-xidmask/include/linux/vserver/context.h
30 --- linux-2.6.32-700/include/linux/vserver/context.h    2013-01-10 14:18:49.949337361 -0500
31 +++ linux-2.6.32-700-xidmask/include/linux/vserver/context.h    2013-01-19 23:27:42.280655065 -0500
32 @@ -79,6 +79,7 @@
33  #define VXC_KTHREAD            0x01000000
34  #define VXC_NAMESPACE          0x02000000
35  
36 +#define VXC_ENABLE_WEB100      0x10000000
37  
38  #ifdef __KERNEL__
39  
40 diff -Ndur linux-2.6.32-700/include/net/tcp.h linux-2.6.32-700-xidmask/include/net/tcp.h
41 --- linux-2.6.32-700/include/net/tcp.h  2013-01-10 14:18:49.880337393 -0500
42 +++ linux-2.6.32-700-xidmask/include/net/tcp.h  2013-01-19 15:41:28.218337671 -0500
43 @@ -251,6 +251,7 @@
44  #ifdef CONFIG_WEB100_STATS
45  extern int sysctl_web100_fperms;
46  extern int sysctl_web100_gid;
47 +extern int sysctl_web100_sidestream_xid;
48  #endif
49  
50  extern atomic_t tcp_memory_allocated;
51 diff -Ndur linux-2.6.32-700/include/net/web100.h linux-2.6.32-700-xidmask/include/net/web100.h
52 --- linux-2.6.32-700/include/net/web100.h       2013-01-10 14:18:49.874218972 -0500
53 +++ linux-2.6.32-700-xidmask/include/net/web100.h       2013-01-19 23:44:09.561660368 -0500
54 @@ -46,7 +46,9 @@
55  extern rwlock_t web100_linkage_lock;
56  
57  /* For /proc/web100 */
58 -extern struct web100stats *web100stats_lookup(int cid);
59 +extern int vx_can_read_stats(struct web100stats *stats);
60 +extern struct web100stats *vx_web100stats_lookup(int cid, int vx_filter);
61 +#define web100stats_lookup(cid) vx_web100stats_lookup(cid, 1)
62  
63  /* For the TCP code */
64  extern int  web100_stats_create(struct sock *sk);
65 diff -Ndur linux-2.6.32-700/net/ipv4/sysctl_net_ipv4.c linux-2.6.32-700-xidmask/net/ipv4/sysctl_net_ipv4.c
66 --- linux-2.6.32-700/net/ipv4/sysctl_net_ipv4.c 2013-01-10 14:18:50.233320698 -0500
67 +++ linux-2.6.32-700-xidmask/net/ipv4/sysctl_net_ipv4.c 2013-01-19 15:41:52.767269242 -0500
68 @@ -754,6 +754,14 @@
69                 .mode           = 0644,
70                 .proc_handler   = &web100_proc_dointvec_update,
71         },
72 +       {
73 +               .ctl_name       = CTL_UNNUMBERED,
74 +               .procname       = "web100_sidestream_xid",
75 +               .data           = &sysctl_web100_sidestream_xid,
76 +               .maxlen         = sizeof(int),
77 +               .mode           = 0644,
78 +               .proc_handler   = &web100_proc_dointvec_update,
79 +       },
80  #endif
81         {
82                 .ctl_name       = CTL_UNNUMBERED,
83 diff -Ndur linux-2.6.32-700/net/ipv4/tcp.c linux-2.6.32-700-xidmask/net/ipv4/tcp.c
84 --- linux-2.6.32-700/net/ipv4/tcp.c     2013-01-10 14:18:50.234322447 -0500
85 +++ linux-2.6.32-700-xidmask/net/ipv4/tcp.c     2013-01-19 15:42:50.975214376 -0500
86 @@ -297,6 +297,7 @@
87  #ifdef CONFIG_WEB100_STATS
88  int sysctl_web100_fperms = CONFIG_WEB100_FPERMS;
89  int sysctl_web100_gid = CONFIG_WEB100_GID;
90 +int sysctl_web100_sidestream_xid = -1;
91  #endif
92  
93  atomic_t tcp_memory_allocated; /* Current allocated memory. */
94 @@ -848,7 +849,7 @@
95                 if (copied) {
96                         tcp_push(sk, flags & ~MSG_MORE, mss_now, TCP_NAGLE_PUSH);
97  #ifdef CONFIG_WEB100_STATS
98 -                       web100_update_writeq(sk);
99 +                       WEB100_UPDATE_FUNC(tcp_sk(sk), web100_update_writeq(sk));
100  #endif
101                 }
102  
103 @@ -1101,7 +1102,7 @@
104                         if (copied) {
105                                 tcp_push(sk, flags & ~MSG_MORE, mss_now, TCP_NAGLE_PUSH);
106  #ifdef CONFIG_WEB100_STATS
107 -                               web100_update_writeq(sk);
108 +                               WEB100_UPDATE_FUNC(tcp_sk(sk), web100_update_writeq(sk));
109  #endif
110                         }
111  
112 @@ -1471,7 +1472,7 @@
113                                         tp->rcv_nxt, flags);
114                 }
115  #ifdef CONFIG_WEB100_STATS
116 -               web100_update_recvq(sk);
117 +               WEB100_UPDATE_FUNC(tcp_sk(sk), web100_update_recvq(sk));
118  #endif
119  
120                 /* Well, if we have backlog, try to process it now yet. */
121 diff -Ndur linux-2.6.32-700/net/ipv4/tcp_input.c linux-2.6.32-700-xidmask/net/ipv4/tcp_input.c
122 --- linux-2.6.32-700/net/ipv4/tcp_input.c       2013-01-10 14:18:50.232318345 -0500
123 +++ linux-2.6.32-700-xidmask/net/ipv4/tcp_input.c       2013-01-10 14:21:16.371337187 -0500
124 @@ -3177,7 +3177,7 @@
125         }
126         
127  #ifdef CONFIG_WEB100_NET100
128 -       if (vars->WAD_NoAI) {
129 +       if (stats != NULL && vars->WAD_NoAI) {
130                 tp->snd_cwnd += vars->WAD_CwndAdjust;
131                 vars->WAD_CwndAdjust = 0;
132                 tp->snd_cwnd_stamp = tcp_time_stamp;
133 @@ -4426,7 +4426,7 @@
134                 tcp_fast_path_check(sk);
135  
136  #ifdef CONFIG_WEB100_STATS
137 -               web100_update_recvq(sk);
138 +               WEB100_UPDATE_FUNC(tcp_sk(sk), web100_update_recvq(sk));
139  #endif
140  
141                 if (eaten > 0)
142 @@ -4484,7 +4484,7 @@
143                    tp->rcv_nxt, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq);
144  
145  #ifdef CONFIG_WEB100_STATS
146 -       web100_update_recvq(sk);
147 +       WEB100_UPDATE_FUNC(tcp_sk(sk), web100_update_recvq(sk));
148  #endif
149         skb_set_owner_r(skb, sk);
150  
151 @@ -5372,7 +5372,7 @@
152                         }
153  
154  #ifdef CONFIG_WEB100_STATS
155 -                       web100_update_recvq(sk);
156 +                       WEB100_UPDATE_FUNC(tcp_sk(sk), web100_update_recvq(sk));
157  #endif
158                         tcp_event_data_recv(sk, skb);
159  
160 diff -Ndur linux-2.6.32-700/net/ipv4/tcp_ipv4.c linux-2.6.32-700-xidmask/net/ipv4/tcp_ipv4.c
161 --- linux-2.6.32-700/net/ipv4/tcp_ipv4.c        2013-01-10 14:18:50.235319018 -0500
162 +++ linux-2.6.32-700-xidmask/net/ipv4/tcp_ipv4.c        2013-01-10 14:21:16.372284450 -0500
163 @@ -1383,7 +1383,9 @@
164                 sk_free(newsk);
165                 goto exit;
166         }
167 -       tcp_sk(newsk)->tcp_stats->wc_vars.LocalAddressType = WC_ADDRTYPE_IPV4;
168 +       if ( tcp_sk(newsk)->tcp_stats != NULL ) {
169 +               tcp_sk(newsk)->tcp_stats->wc_vars.LocalAddressType = WC_ADDRTYPE_IPV4;
170 +       }
171  #endif
172  
173         newsk->sk_gso_type = SKB_GSO_TCPV4;
174 @@ -1857,7 +1859,9 @@
175                 if ((err = web100_stats_create(sk))) {
176                         return err;
177                 }
178 -               tcp_sk(sk)->tcp_stats->wc_vars.LocalAddressType = WC_ADDRTYPE_IPV4;
179 +               if ( tcp_sk(sk)->tcp_stats != NULL ) {
180 +                       tcp_sk(sk)->tcp_stats->wc_vars.LocalAddressType = WC_ADDRTYPE_IPV4;
181 +               }
182         }
183  #endif
184  
185 diff -Ndur linux-2.6.32-700/net/ipv4/web100_stats.c linux-2.6.32-700-xidmask/net/ipv4/web100_stats.c
186 --- linux-2.6.32-700/net/ipv4/web100_stats.c    2013-01-10 14:18:50.231318735 -0500
187 +++ linux-2.6.32-700-xidmask/net/ipv4/web100_stats.c    2013-02-06 22:25:11.711402213 -0500
188 @@ -72,7 +72,99 @@
189         return cid % web100stats_htsize;
190  }
191  
192 -struct web100stats *web100stats_lookup(int cid)
193 +/*
194 + * Determine if the given socket should have web100 stats structure.
195 + *
196 + * Args:
197 + *             sk -- socket pointer
198 + * Returns:
199 + *             0 -- false, do not create the web100 stats struct
200 + *             1 -- true, create the web100 stats structure
201 + */
202 +int vx_can_create_stats(struct sock *sk) {
203 +       struct vx_info *vxi=NULL;
204 +
205 +       if ( NULL == sk ) { 
206 +               return 0; 
207 +       }
208 +
209 +       if ( 0 != sk->sk_xid ) {
210 +               vxi = lookup_vx_info(sk->sk_xid);
211 +               if ( NULL != vxi && !vx_info_ccaps(vxi, VXC_ENABLE_WEB100) ) {
212 +                       /* do not create stats struct */
213 +                       return 0;
214 +               } 
215 +       }
216 +       /* create stats struct */
217 +       return 1;
218 +}
219 +
220 +/* 
221 + * Determine if the current task has permission to read given stats struct. The 
222 + * reader's identity is taken as the current task.  If the current task 
223 + * has permission, then the function returns TRUE. Otherwise, FALSE.
224 + * 
225 + * At least one condition must be satisfied for the function to return TRUE:
226 + *      xid == 0  -- reader is the root context of the system.
227 + *      xid == stats->wc_sk->sk_xid -- reader created the stats object 
228 + *      xid == web100_sidestream_xid -- reader can see all stats
229 + *
230 + * Args:
231 + *      stats - the web100 stats structure to read.
232 + *
233 + * Returns:
234 + *      0 - FALSE, read permission should be denied.
235 + *      1 - TRUE, current task has read permission
236 + */
237 +int vx_can_read_stats(struct web100stats *stats) {
238 +       struct vx_info *vxi=NULL;
239 +       struct sock *sk = NULL;
240 +
241 +       if ( NULL == stats || stats->wc_dead ) {
242 +               return 0; 
243 +       }
244 +
245 +       if ( 0 == vx_current_xid() ) {
246 +               // always ok for xid=0 (root context)
247 +               return 1;
248 +       }
249 +
250 +       vxi = current_vx_info(); 
251 +       if ( NULL == vxi ) {
252 +               /* non-root context is missing vx_info; cannot check access flags */
253 +               return 0;
254 +       }
255 +
256 +       if ( vx_current_xid() == sysctl_web100_sidestream_xid ) { 
257 +               /* the sidestream xid can view all stats. */
258 +               return 1;
259 +       }
260 +
261 +       sk = stats->wc_sk;
262 +       if ( vx_current_xid() == sk->sk_xid ) {
263 +               /* the xid is the socket owner so can see it's own connections */
264 +               return 1;
265 +       }
266 +
267 +       /* all checks have failed, so deny read permission. */
268 +       return 0;
269 +}
270 +
271 +/*
272 + * Based on the connection ID, return the web100stats structure.
273 + * Optionally, when vx_filter=1, filter the result by the 
274 + * read-permission of the current task. When vx_filter=0, do not perform
275 + * filtering.
276 + *
277 + * Args:
278 + *  cid       -- connection id
279 + *  vx_filter -- 1 or 0, filter the returned stats or not
280 + *
281 + * Returns:
282 + *  If the cid is found, a pointer to a web100stats struct;
283 + *  If the cid is not found or filtered, NULL is returned.
284 + */
285 +struct web100stats *vx_web100stats_lookup(int cid, int vx_filter)
286  {
287         struct web100stats *stats;
288         
289 @@ -83,7 +175,10 @@
290         stats = web100stats_ht[web100stats_hash(cid)];
291         while (stats && stats->wc_cid != cid)
292                 stats = stats->wc_hash_next;
293 -       return stats;
294 +       if ( 0 == vx_filter || 1 == vx_can_read_stats(stats) ) {
295 +               return stats;
296 +       } 
297 +       return NULL;
298  }
299  
300  /* This will get really slow as the cid space fills.  This can be done
301 @@ -99,7 +194,8 @@
302         
303         i = web100stats_next_cid;
304         do {
305 -               if (web100stats_lookup(i) == NULL)
306 +               /* use vx sensitive version *without* filtering */
307 +               if (vx_web100stats_lookup(i,0) == NULL)
308                         break;
309                 i = (i + 1) % WEB100_MAX_CONNS;
310         } while (i != web100stats_next_cid);
311 @@ -252,6 +348,12 @@
312         struct web100directs *vars;
313         struct tcp_sock *tp = tcp_sk(sk);
314         struct timeval tv;
315 +
316 +       if ( 0 == vx_can_create_stats(sk) ) {
317 +               /* do not create web100 stats for this socket */
318 +               tp->tcp_stats = NULL;
319 +               return 0;
320 +       }
321         
322         if ((stats = kmalloc(sizeof (struct web100stats), gfp_any())) == NULL)
323                 return -ENOMEM;
324 @@ -294,6 +396,9 @@
325  
326  void web100_stats_destroy(struct web100stats *stats)
327  {
328 +       if ( NULL == stats ) {
329 +               return;
330 +       }
331         /* Attribute final sndlim time. */
332         web100_update_sndlim(tcp_sk(stats->wc_sk), stats->wc_limstate);
333         
334 diff -Ndur linux-2.6.32-700/net/ipv6/tcp_ipv6.c linux-2.6.32-700-xidmask/net/ipv6/tcp_ipv6.c
335 --- linux-2.6.32-700/net/ipv6/tcp_ipv6.c        2013-01-10 14:18:50.219284269 -0500
336 +++ linux-2.6.32-700-xidmask/net/ipv6/tcp_ipv6.c        2013-01-10 14:21:16.373337472 -0500
337 @@ -1380,7 +1380,9 @@
338                 sk_free(newsk);
339                 goto out;
340         }
341 -       tcp_sk(newsk)->tcp_stats->wc_vars.LocalAddressType = WC_ADDRTYPE_IPV6;
342 +       if ( tcp_sk(newsk)->tcp_stats != NULL ) {
343 +               tcp_sk(newsk)->tcp_stats->wc_vars.LocalAddressType = WC_ADDRTYPE_IPV6;
344 +       }
345  #endif
346  
347         /*
348 @@ -1901,7 +1903,9 @@
349                 if ((err = web100_stats_create(sk))) {
350                         return err;
351                 }
352 -               tcp_sk(sk)->tcp_stats->wc_vars.LocalAddressType = WC_ADDRTYPE_IPV6;
353 +               if ( tcp_sk(sk)->tcp_stats != NULL ) {
354 +                       tcp_sk(sk)->tcp_stats->wc_vars.LocalAddressType = WC_ADDRTYPE_IPV6;
355 +               }
356         }
357  #endif
358