upgrade to linux 2.6.10-1.12_FC2
[linux-2.6.git] / include / net / tux.h
1 #ifndef _NET_TUX_H
2 #define _NET_TUX_H
3
4 /*
5  * TUX - Integrated Application Protocols Layer and Object Cache
6  *
7  * Copyright (C) 2000, 2001, Ingo Molnar <mingo@redhat.com>
8  *
9  * tux.h: main structure definitions and function prototypes
10  */
11
12 #define __KERNEL_SYSCALLS__
13
14 #include <linux/mm.h>
15 #include <linux/net.h>
16 #include <linux/wait.h>
17 #include <linux/namei.h>
18 #include <linux/file.h>
19 #include <linux/mman.h>
20 #include <linux/swap.h>
21 #include <linux/ctype.h>
22 #include <linux/config.h>
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/unistd.h>
26 #include <linux/sysctl.h>
27 #include <linux/proc_fs.h>
28 #include <linux/pagemap.h>
29 #include <linux/vmalloc.h>
30 #include <linux/utsname.h>
31 #include <linux/smp_lock.h>
32 #include <linux/kernel_stat.h>
33 #include <linux/kernel_stat.h>
34 #include <linux/time.h>
35 #include <asm/div64.h>
36 #include <asm/unaligned.h>
37 #include <linux/compiler.h>
38 #include <linux/mount.h>
39 #include <linux/zlib.h>
40 #include <linux/syscalls.h>
41 #include <linux/cpumask.h>
42
43 #include <net/tcp.h>
44 #include <net/tux_u.h>
45
46 /* Maximum number of threads: */
47 #define CONFIG_TUX_NUMTHREADS 16
48
49 /* Number of cachemiss/IO threads: */
50 #define NR_IO_THREADS 64
51
52 /* Maximum number of listen sockets per thread: */
53 #define CONFIG_TUX_NUMSOCKETS 16
54
55 extern spinlock_t tux_module_lock;
56 extern struct module *tux_module;
57 extern asmlinkage long (*sys_tux_ptr) (unsigned int action, user_req_t *u_info);
58
59 #undef Dprintk
60
61 extern int tux_TDprintk;
62 extern int tux_Dprintk;
63
64 #define TUX_DEBUG CONFIG_TUX_DEBUG
65 #if CONFIG_TUX_DEBUG
66 # define TUX_BUG() BUG()
67
68 # define TUX_DPRINTK 1
69 # define TDprintk(x...) do { if (tux_TDprintk) { printk("<%ld:%s:%d>: ", jiffies, __FILE__, __LINE__); printk(x); } } while (0)
70 # define Dprintk(x...) do { if (tux_Dprintk == 1) TDprintk(x); } while (0)
71 #else
72 # define TUX_DPRINTK 0
73 # define Dprintk(x...) do { } while (0)
74 # define TDprintk(x...) do { } while (0)
75 //# define TUX_BUG() BUG()
76 # define TUX_BUG() do { } while (0)
77 #endif
78
79 #if 1
80 # define INC_STAT(x) do { } while (0)
81 # define DEC_STAT(x) do { } while (0)
82 # define ADD_STAT(x,y) do { } while (0)
83 # define SUB_STAT(x,y) do { } while (0)
84 #else
85 # define INC_STAT(x) atomic_inc((atomic_t *)&kstat.x)
86 # define DEC_STAT(x) atomic_dec((atomic_t *)&kstat.x)
87 # define ADD_STAT(y,x) atomic_add(y,(atomic_t *)&kstat.x)
88 # define SUB_STAT(y,x) atomic_sub(y,(atomic_t *)&kstat.x)
89 #endif
90
91 // lru needs this:
92
93 # define DEBUG_DEL_LIST(x...) do { INIT_LIST_HEAD((x)); } while (0)
94
95
96 #define LOG_LEN (8*1024*1024UL)
97
98 struct tux_req_struct;
99 typedef struct tux_req_struct tux_req_t;
100 typedef struct tux_threadinfo threadinfo_t;
101
102 extern struct address_space_operations url_aops;
103
104 typedef struct tcapi_template_s {
105         char *vfs_name;
106         struct list_head modules;
107         int (*query) (tux_req_t *req);
108         struct module *mod;
109         unsigned int userspace_id;
110 } tcapi_template_t;
111
112 typedef struct mimetype_s {
113         struct list_head list;
114
115         char *ext;
116         unsigned int ext_len;
117         char *type;
118         unsigned int type_len;
119         char *expire_str;
120         unsigned int expire_str_len;
121
122         unsigned int special;
123 } mimetype_t;
124
125 typedef struct tux_attribute_s {
126         mimetype_t *mime;
127         tcapi_template_t *tcapi;
128 } tux_attribute_t;
129
130 #define MAX_TUX_ATOMS 8
131
132 typedef void (atom_func_t)(tux_req_t *req, int cachemiss);
133
134 typedef struct tux_proto_s
135 {
136         unsigned int defer_accept;
137         unsigned int can_redirect;
138         void (*got_request) (tux_req_t *req);
139         int (*parse_message) (tux_req_t *req, const int total_len);
140         atom_func_t *illegal_request;
141         atom_func_t *request_timeout;
142         void (*pre_log) (tux_req_t *req);
143         int (*check_req_err) (tux_req_t *req, int cachemiss);
144         char * (*print_dir_line) (tux_req_t *req, char *tmp, char *d_name, int d_len, int d_type, struct dentry *dentry, struct inode *inode);
145         const char *name;
146         struct nameidata main_docroot;
147 } tux_proto_t;
148
149 typedef struct tux_socket_s {
150         tux_proto_t *proto;
151         unsigned int ip;
152         unsigned short port;
153         struct proc_dir_entry *entry;
154 } tux_socket_t;
155
156 extern tux_socket_t tux_listen [CONFIG_TUX_NUMTHREADS][CONFIG_TUX_NUMSOCKETS];
157
158
159 typedef struct abuf_s {
160         struct page *page;
161         char *buf;
162         unsigned int size;
163         unsigned int max_len;
164         unsigned int offset;
165         unsigned int left;
166         unsigned long flags;
167 } abuf_t;
168
169 struct linux_dirent64 {
170         u64             d_ino;
171         s64             d_off;
172         unsigned short  d_reclen;
173         unsigned char   d_type;
174         char            d_name[0];
175 };
176
177 struct getdents_callback64 {
178         struct linux_dirent64 * current_dir;
179         struct linux_dirent64 * previous;
180         int count;
181         int error;
182 };
183
184 #define TUX_MAGIC 0x12457801
185
186 #define MAX_TUX_ATOMS 8
187
188 struct tux_req_struct
189 {
190         tux_proto_t *proto;
191
192         int atom_idx;
193         atom_func_t *atoms [MAX_TUX_ATOMS];
194         struct list_head work;
195
196         struct list_head all;
197         struct list_head free;
198         struct list_head lru;
199
200         unsigned long idle_input;
201         unsigned long wait_output_space;
202
203         struct socket *sock;
204         struct dentry *dentry;
205         struct vfsmount *mnt;
206         struct dentry *docroot_dentry;
207         struct vfsmount *docroot_mnt;
208         struct dentry *cwd_dentry;
209         struct vfsmount *cwd_mnt;
210
211         struct file *in_file;
212         int fd;
213         read_descriptor_t desc;
214         u32 client_addr;
215         u32 client_port;
216         unsigned int virtual;
217
218         loff_t total_file_len;
219         unsigned int lendigits;
220         loff_t offset_start;
221         loff_t offset_end;
222         loff_t output_len;
223
224         loff_t ftp_offset_start;
225
226         time_t mtime;
227         unsigned int etaglen;
228         char etag [40];
229
230         char usermode;
231         unsigned int usermodule_idx;
232         struct dentry *module_dentry;
233         struct vfsmount *module_mnt;
234         char *userbuf;
235         unsigned int userlen;
236
237         tux_attribute_t *attr;
238
239         threadinfo_t *ti;
240         wait_queue_t sleep;
241         wait_queue_t ftp_sleep;
242
243         abuf_t abuf;
244         /*
245          * Parsed request fields. In-line strings are zero-delimited.
246          */
247         const char *headers;
248         unsigned int headers_len;
249
250         unsigned int parsed_len;
251
252         // FTP part
253         ftp_command_t ftp_command;
254         u32 ftp_user_addr;
255         u16 ftp_user_port;
256
257         struct socket *data_sock;
258         unsigned int prev_pos;
259
260         // ls handing:
261         struct linux_dirent64 *dirp0;
262         unsigned int curroff, total;
263
264 #define MAX_USERNAME_LEN 16
265         char username[MAX_USERNAME_LEN];
266         unsigned int username_len;
267
268         // HTTP part
269         http_method_t method;
270         const char *method_str;
271         unsigned int method_len;
272
273         http_version_t version;
274         const char *version_str;
275         unsigned int version_len;
276
277         /* requested URI: */
278
279         const char *uri_str;
280         unsigned int uri_len;
281
282         /* Objectname (filename/scriptname) this URI refers to: */
283
284 #define MAX_OBJECTNAME_LEN 256
285         char objectname[MAX_OBJECTNAME_LEN + 4]; // space for .gz as well
286         unsigned int objectname_len;
287
288         /* Query string within the URI: */
289
290         const char *query_str;
291         unsigned int query_len;
292
293         /* Cookies: */
294
295         const char *cookies_str;
296         unsigned int cookies_len;
297         unsigned int parse_cookies;
298
299         /* Content-TYpe */
300         const char *content_type_str;
301         unsigned int content_type_len;
302
303         /* Content-Length: */
304
305         const char *contentlen_str;
306         unsigned int contentlen_len;
307         unsigned int content_len;
308
309         /* User-Agent: */
310
311         const char *user_agent_str;
312         unsigned int user_agent_len;
313
314         /* Accept: */
315
316         const char *accept_str;
317         unsigned int accept_len;
318
319         /* Accept-Charset: */
320
321         const char *accept_charset_str;
322         unsigned int accept_charset_len;
323
324         /* Accept-Language: */
325
326         const char *accept_language_str;
327         unsigned int accept_language_len;
328
329         /* Cache-Control: */
330
331         const char *cache_control_str;
332         unsigned int cache_control_len;
333
334         /* If-Modified-Since: */
335
336         const char *if_modified_since_str;
337         unsigned int if_modified_since_len;
338
339         /* If-None-Match: */
340         const char *if_none_match_str;
341         unsigned int if_none_match_len;
342
343         /* If-Range: */
344
345         const char *if_range_str;
346         unsigned int if_range_len;
347
348         /* Negotiate: */
349
350         const char *negotiate_str;
351         unsigned int negotiate_len;
352
353         /* Pragma: */
354
355         const char *pragma_str;
356         unsigned int pragma_len;
357
358         /* Referer: */
359
360         const char *referer_str;
361         unsigned int referer_len;
362
363         /* Accept-Encoding: */
364
365         const char *accept_encoding_str;
366         unsigned int accept_encoding_len;
367         unsigned int may_send_gzip;
368         unsigned int content_gzipped;
369
370         /* Host */
371
372 #define MAX_HOST_LEN 128
373         char host[MAX_HOST_LEN];
374         unsigned int host_len;
375
376         /* POSTed data: */
377
378         const char *post_data_str;
379         unsigned int post_data_len;
380
381         unsigned int status;
382
383         /* the file being sent */
384
385         unsigned int bytes_sent;
386 #if CONFIG_TUX_DEBUG
387         unsigned int bytes_expected;
388 #endif
389         unsigned long first_timestamp;
390         unsigned int body_len;
391
392         unsigned int user_error;
393
394         char error;
395         char postponed;
396
397         char had_cachemiss;
398         char lookup_dir;
399         char lookup_404;
400
401         char keep_alive;
402         struct timer_list keepalive_timer;
403         unsigned int total_bytes;
404         struct timer_list output_timer;
405
406         unsigned int nr_keepalives;
407
408         unsigned int event;
409         u64 private;
410
411         unsigned int magic;
412         void (*real_data_ready)(struct sock *sk, int space);
413         void (*real_state_change)(struct sock *sk);
414         void (*real_write_space)(struct sock *sk);
415         void (*real_error_report)(struct sock *sk);
416         void (*real_destruct)(struct sock *sk);
417
418         void (*ftp_real_data_ready)(struct sock *sk, int space);
419         void (*ftp_real_state_change)(struct sock *sk);
420         void (*ftp_real_write_space)(struct sock *sk);
421         void (*ftp_real_error_report)(struct sock *sk);
422         void (*ftp_real_create_child)(struct sock *sk, struct sock *newsk);
423         void (*ftp_real_destruct)(struct sock *sk);
424
425 #if CONFIG_TUX_EXTENDED_LOG
426         unsigned long accept_timestamp;
427         unsigned long parse_timestamp;
428         unsigned long output_timestamp;
429         unsigned long flush_timestamp;
430 # define SET_TIMESTAMP(x) do { (x) = jiffies; } while (0)
431 #else
432 # define SET_TIMESTAMP(x) do { } while (0)
433 #endif
434
435 };
436
437 extern void add_tux_atom (tux_req_t *req, atom_func_t *event_done);
438 extern void del_tux_atom (tux_req_t *req);
439 extern void tux_schedule_atom (tux_req_t *req, int cachemiss);
440 extern void add_req_to_workqueue (tux_req_t *req);
441
442
443 typedef struct iothread_s
444 {
445         spinlock_t async_lock;
446         threadinfo_t *ti;
447         struct list_head async_queue;
448         wait_queue_head_t async_sleep;
449         unsigned int nr_async_pending;
450         unsigned int threads;
451         unsigned int shutdown;
452         wait_queue_head_t wait_shutdown;
453 } iothread_t;
454
455 typedef struct tux_listen_s
456 {
457         tux_proto_t *proto;
458         struct socket *sock;
459         unsigned int cloned;
460 } tux_listen_t;
461
462 struct tux_threadinfo
463 {
464         tux_req_t *userspace_req;
465         unsigned int started;
466         struct task_struct *thread;
467         iothread_t *iot;
468         wait_queue_t wait_event [CONFIG_TUX_NUMSOCKETS];
469         wait_queue_t stop;
470         unsigned int pid;
471
472         struct page *header_cache;
473         unsigned int header_offset;
474
475         unsigned int nr_requests;
476         struct list_head all_requests;
477
478         unsigned int nr_free_requests;
479         spinlock_t free_requests_lock;
480         struct list_head free_requests;
481
482         spinlock_t work_lock;
483         struct list_head work_pending;
484         struct list_head lru;
485         unsigned int nr_lru;
486
487         unsigned int listen_error;
488         tux_listen_t listen[CONFIG_TUX_NUMSOCKETS];
489
490         struct semaphore gzip_sem;
491         z_stream gzip_state;
492
493         unsigned int cpu;
494         unsigned int __padding[16];
495 };
496
497 typedef enum special_mimetypes {
498         NORMAL_MIME_TYPE,
499         MIME_TYPE_REDIRECT,
500         MIME_TYPE_CGI,
501         MIME_TYPE_MODULE,
502 } special_mimetypes_t;
503
504 #if CONFIG_TUX_DEBUG
505 #if 0
506 extern inline void url_hist_hit (int size)
507 {
508         unsigned int idx = size/1024;
509
510         if (idx >= URL_HIST_SIZE)
511                 idx = URL_HIST_SIZE-1;
512         kstat.url_hist_hits[idx]++;
513 }
514 extern inline void url_hist_miss (int size)
515 {
516         unsigned int idx = size/1024;
517  
518         if (idx >= URL_HIST_SIZE)
519                 idx = URL_HIST_SIZE-1;
520         kstat.url_hist_misses[idx]++;
521 }
522 #endif
523 extern void __check_req_list (tux_req_t *req, struct list_head *list);
524 # define check_req_list __check_req_list
525 #else
526 # define check_req_list(req, list) do { } while (0)
527 #endif
528
529 #define url_hist_hit(size) do { } while (0)
530 #define url_hist_miss(size) do { } while (0)
531
532 extern char tux_common_docroot[200];
533 extern char tux_http_subdocroot[200];
534 extern char tux_ftp_subdocroot[200];
535 extern char tux_logfile[200];
536 extern char tux_cgiroot[200];
537 extern char tux_404_page[200];
538 extern char tux_default_vhost[200];
539 extern char tux_extra_html_header[600];
540 extern unsigned int tux_extra_html_header_size;
541 extern int tux_cgi_uid;
542 extern int tux_cgi_gid;
543 extern unsigned int tux_clientport;
544 extern unsigned int tux_logging;
545 extern unsigned int tux_threads;
546 extern unsigned int tux_keepalive_timeout;
547 extern unsigned int tux_max_output_bandwidth;
548 extern unsigned int tux_max_backlog;
549 extern unsigned int tux_max_connect;
550 extern unsigned int tux_mode_forbidden;
551 extern unsigned int tux_mode_allowed;
552 extern unsigned int tux_logentry_align_order;
553 extern unsigned int tux_nonagle;
554 extern unsigned int tux_ack_pingpong;
555 extern unsigned int tux_push_all;
556 extern unsigned int tux_zerocopy_parse;
557 extern unsigned int tux_generate_etags;
558 extern unsigned int tux_generate_last_mod;
559 extern unsigned int tux_generate_cache_control;
560 extern unsigned int tux_ip_logging;
561 extern unsigned int tux_ftp_wait_close;
562 extern unsigned int tux_ftp_log_retr_only;
563 extern unsigned int tux_hide_unreadable;
564
565 typedef enum virtual_server {
566         TUX_VHOST_NONE,
567         TUX_VHOST_HOST,
568         TUX_VHOST_IP,
569         TUX_VHOST_IP_HOST,
570 } virtual_server_t;
571
572 extern unsigned int tux_virtual_server;
573 extern unsigned int mass_hosting_hash;
574 extern unsigned int strip_host_tail;
575 extern unsigned int tux_ftp_virtual_server;
576
577 extern unsigned int tux_max_object_size;
578 extern unsigned int tux_max_free_requests;
579 extern unsigned int tux_defer_accept;
580
581 extern struct socket * start_listening(tux_socket_t *listen, int nr);
582 extern void stop_listening(struct socket **sock);
583 extern void start_sysctl(void);
584 extern void end_sysctl(void);
585 extern void flush_request (tux_req_t *req, int cachemiss);
586 extern void unlink_tux_socket (tux_req_t *req);
587 extern void unlink_tux_data_socket (tux_req_t *req);
588 extern void unlink_tux_listen_socket (tux_req_t *req);
589 extern void link_tux_ftp_accept_socket (tux_req_t *req, struct socket *sock);
590 extern void link_tux_data_socket (tux_req_t *req, struct socket *sock);
591 extern void tux_push_req (tux_req_t *req);
592 extern int send_sync_buf (tux_req_t *req, struct socket *sock, const char *buf, const size_t length, unsigned long flags);
593 extern void __send_async_message (tux_req_t *req, const char *message, int status, unsigned int size, int push);
594 #define send_async_message(req,str,status,push) \
595                 __send_async_message(req,str,status,strlen(str),push)
596
597 extern void send_success (tux_req_t *req, struct socket *sock);
598 extern void send_async_err_not_found (tux_req_t *req);
599 extern void send_async_timed_out (tux_req_t *req);
600
601 extern void kfree_req (tux_req_t *req);
602 extern int accept_requests (threadinfo_t *ti);
603 extern int process_requests (threadinfo_t *ti, tux_req_t **user_req);
604 extern int flush_freequeue (threadinfo_t * ti);
605 extern int tux_flush_workqueue (threadinfo_t *ti);
606 extern tux_req_t * pick_userspace_req (threadinfo_t *ti);
607 extern atom_func_t redirect_request;
608 extern atom_func_t parse_request;
609 extern void queue_cachemiss (tux_req_t *req);
610 extern int start_cachemiss_threads (threadinfo_t *ti);
611 extern void stop_cachemiss_threads (threadinfo_t *ti);
612 struct file * tux_open_file(char *filename, int mode);
613 extern void start_log_thread (void);
614 extern void stop_log_thread (void);
615 extern void add_mimetype (char *new_ext, char *new_type, char *new_expire);
616 extern void free_mimetypes (void);
617 extern int lookup_object (tux_req_t *req, const unsigned int flag);
618 extern int handle_gzip_req (tux_req_t *req, unsigned int flags);
619 extern struct dentry * tux_lookup (tux_req_t *req, const char *filename, const unsigned int flag, struct vfsmount **mnt);
620 extern tcapi_template_t * lookup_tuxmodule (const char *filename);
621 extern int register_tuxmodule (tcapi_template_t *tcapi);
622 extern tcapi_template_t * unregister_tuxmodule (char *vfs_name);
623 extern tcapi_template_t * get_first_usermodule (void);
624 extern int user_register_module (user_req_t *u_info);
625 extern int user_unregister_module (user_req_t *u_info);
626 extern void unregister_all_tuxmodules (void);
627
628 typedef struct exec_param_s {
629         char *command;
630         char **argv;
631         char **envp;
632         unsigned int pipe_fds;
633 } exec_param_t;
634
635 extern pid_t tux_exec_process (char *command, char **argv, char **envp, int pipe_fds, exec_param_t *param, int wait);
636
637 extern void start_external_cgi (tux_req_t *req);
638 extern tcapi_template_t extcgi_tcapi;
639
640 extern void queue_output_req (tux_req_t *req, threadinfo_t *ti);
641 extern void queue_userspace_req (tux_req_t *req, threadinfo_t *ti);
642
643
644 extern void __log_request (tux_req_t *req);
645 extern inline void log_request (tux_req_t *req)
646 {
647         if (tux_logging)
648                 __log_request(req);
649 }
650
651 extern int __connection_too_fast (tux_req_t *req);
652
653 #define connection_too_fast(req)                                \
654         ({                                                      \
655                 int __ret = 1;                                  \
656                 if (unlikely(tux_max_output_bandwidth))         \
657                         __ret = __connection_too_fast(req);     \
658                 __ret;                                          \
659         })
660
661 extern void trunc_headers (tux_req_t *req);
662 extern int generic_send_file (tux_req_t *req, struct socket *sock, int cachemiss);
663 extern int tux_fetch_file (tux_req_t *req, int nonblock);
664
665 extern void postpone_request (tux_req_t *req);
666 extern int continue_request (int fd);
667 extern void tux_push_pending (struct sock *sk);
668 extern void zap_request (tux_req_t *req, int cachemiss);
669 extern int add_output_space_event (tux_req_t *req, struct socket *sock);
670
671 extern void reap_kids (void);
672 extern void unuse_frag (struct sk_buff *skb, skb_frag_t *frag);
673 extern skb_frag_t * build_dynbuf_frag (tux_req_t *req, unsigned int size);
674 extern int tux_permission (struct inode *inode);
675 extern void flush_all_signals (void);
676
677 #define D() Dprintk("{%s:%d}\n", __FILE__, __LINE__)
678
679 extern int nr_async_io_pending (void);
680
681 extern void __add_keepalive_timer (tux_req_t *req);
682 #define add_keepalive_timer(req)                                        \
683 do {                                                                    \
684         if (tux_keepalive_timeout) {                                    \
685                 Dprintk("add_keepalive_timer(%p).\n", (req));           \
686                 __add_keepalive_timer(req);                             \
687         }                                                               \
688 } while (0)
689 extern void __del_keepalive_timer (tux_req_t *req);
690 #define del_keepalive_timer(req)                                        \
691 do {                                                                    \
692         if (tux_keepalive_timeout) {                                    \
693                 Dprintk("del_keepalive_timer(%p).\n", (req));           \
694                 __del_keepalive_timer(req);                             \
695         }                                                               \
696 } while (0)
697
698 extern void del_output_timer (tux_req_t *req);
699 extern void output_timeout (tux_req_t *req);
700
701 extern void print_req (tux_req_t *req);
702
703 extern char tux_date [DATE_LEN];
704
705
706 extern int nr_async_io_pending (void);
707 extern void tux_exit (void);
708 extern char * get_abuf (tux_req_t *req, unsigned int max_size);
709 extern void send_abuf (tux_req_t *req, unsigned int size, unsigned long flags);
710
711
712 extern int idle_event (tux_req_t *req);
713 extern int output_space_event (tux_req_t *req);
714 extern cpumask_t tux_log_cpu_mask;
715 extern unsigned int tux_compression;
716 extern unsigned int tux_noid;
717 extern unsigned int tux_cgi_inherit_cpu;
718 extern unsigned int tux_zerocopy_header;
719 extern unsigned int tux_zerocopy_sendfile;
720 extern cpumask_t tux_cgi_cpu_mask;
721 extern tux_proto_t tux_proto_http;
722 extern tux_proto_t tux_proto_ftp;
723 extern unsigned int tux_all_userspace;
724 extern unsigned int tux_ignore_query;
725 extern unsigned int tux_redirect_logging;
726 extern unsigned int tux_referer_logging;
727 extern unsigned int tux_log_incomplete;
728 extern unsigned int tux_max_header_len;
729 extern unsigned int tux_cpu_offset;
730 extern unsigned int tux_ftp_login_message;
731
732 extern void drop_permissions (void);
733 extern int query_extcgi (tux_req_t *req);
734 extern int tux_chroot (char *dir);
735
736 extern void install_req_dentry (tux_req_t *req, struct dentry *dentry, struct vfsmount *mnt);
737 extern void release_req_dentry (tux_req_t *req);
738 extern void unidle_req (tux_req_t *req);
739 extern int nr_requests_used (void);
740
741 #define req_err(req) do { (req)->error = 1; Dprintk("request %p error at %s:%d.\n", req, __FILE__, __LINE__); } while (0)
742
743 #define enough_wspace(sk) (sk_stream_wspace(sk) >= sk_stream_min_wspace(sk))
744 #define clear_keepalive(req) do { (req)->keep_alive = 0; Dprintk("keepalive cleared for req %p.\n", req); } while (0)
745
746 extern int print_all_requests (threadinfo_t *ti);
747 extern unsigned int tux_max_keepalives;
748 extern int time_unix2ls (time_t zulu, char *buf);
749 extern void last_mod_time(char * curr, const time_t t);
750 extern int mdtm_time(char * curr, const time_t t);
751 extern time_t parse_time(const char *str, const int str_len);
752
753 extern unsigned int nr_tux_threads;
754 extern threadinfo_t threadinfo[CONFIG_TUX_NUMTHREADS];
755
756 #define switch_docroot(req) do { if (((req)->docroot_dentry != current->fs->root) || ((req)->docroot_mnt != current->fs->rootmnt)) __switch_docroot(req); } while (0)
757 extern void __switch_docroot(tux_req_t *req);
758 extern void list_directory (tux_req_t *req, int cachemiss);
759 extern char * tux_print_path (tux_req_t *req, struct dentry *dentry, struct vfsmount *mnt, char *buf, unsigned int max_len);
760
761 extern unsigned int tux_http_dir_indexing;
762
763 int tux_gzip_compress (tux_req_t *req, unsigned char *data_in, unsigned char *data_out, __u32 *in_len, __u32 *out_len);
764
765 struct dentry * __tux_lookup (tux_req_t *req, const char *filename,
766                          struct nameidata *base, struct vfsmount **mnt);
767
768 /* error codes for req->error */
769 #define TUX_ERROR_REDIRECT     1
770 #define TUX_ERROR_UNUSED       2
771 #define TUX_ERROR_CONN_CLOSE   3
772 #define TUX_ERROR_CONN_TIMEOUT 4
773
774 extern void __put_data_sock (tux_req_t *req);
775
776 static inline void put_data_sock (tux_req_t *req)
777 {
778         if (req->data_sock)
779                 __put_data_sock(req);
780 }
781
782 #define socket_input(sock) \
783         (!skb_queue_empty(&(sock)->sk->sk_receive_queue) || \
784                 !skb_queue_empty(&(sock)->sk->sk_error_queue))
785
786 #define tux_kmalloc(size)                                               \
787 ({                                                                      \
788         void *__ptr;                                                    \
789                                                                         \
790         while (!(__ptr = kmalloc(size, GFP_KERNEL))) {                  \
791                 if (net_ratelimit())                                    \
792                         printk(KERN_WARNING "tux: OOM at %s:%d (%d bytes).\n", \
793                                 __FILE__, __LINE__, size);              \
794                 current->state = TASK_UNINTERRUPTIBLE;                  \
795                 schedule_timeout(1);                                    \
796         }                                                               \
797         __ptr;                                                          \
798 })
799
800 #define tux_close(fd) sys_close(fd)
801
802 #endif