diff -urN kernel/Makefile kernel-2.4/Makefile --- kernel/Makefile Tue Nov 28 21:00:56 2006 +++ kernel-2.4/Makefile Sat Jan 6 17:12:26 2007 @@ -1,13 +1,16 @@ # Makefile for tcp_splice module. # Alexandre Cassen, +# kernel 2.4 version by Willy Tarreau + +O_TARGET := tcp_splice.o +obj-m := $(O_TARGET) +obj-y := tcp_splice_core.o tcp_splice_conn.o tcp_splice_ctl.o tcp_splice_xmit.o +export-objs := tcp_splice_ctl.o -obj-m := tcp_splice.o -tcp_splice-objs := tcp_splice_core.o tcp_splice_conn.o tcp_splice_ctl.o \ - tcp_splice_xmit.o KDIR := /lib/modules/$(shell uname -r)/build MDIR := /lib/modules/$(shell uname -r)/kernel/net/ipv4 PWD := $(shell pwd) -MOD := tcp_splice.ko +MOD := $(O_TARGET) default: $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules @@ -21,5 +24,8 @@ rmmod -f tcp_splice clean: - rm -rf *.o *.mod.c .tcp_splice*.o.cmd *.ko .tcp_splice*.ko.cmd \ - Module.symvers .tmp_versions + rm -f *.o .*.flags + +ifneq ($(TOPDIR),) +include $(TOPDIR)/Rules.make +endif diff -urN kernel/compat26.h kernel-2.4/compat26.h --- kernel/compat26.h Thu Jan 1 01:00:00 1970 +++ kernel-2.4/compat26.h Sat Jan 6 17:04:39 2007 @@ -0,0 +1,25 @@ +#define sk_err err +#define sk_state state + +#define sockfd_put(sock) fput(sock->file) + +#define inet_sock sock +#undef inet_sk +#define inet_sk(s) (s) + +#define tcp_sock tcp_opt +#define tcp_sk(s) &(s->tp_pinfo.af_tcp) + +#define tcp_splice_use_count_inc() MOD_INC_USE_COUNT +#define tcp_splice_use_count_dec() MOD_DEC_USE_COUNT + +/* Output packet to network from transport. */ +static inline int dst_output(struct sk_buff *skb) +{ + return skb->dst->output(skb); +} + +static inline int dst_mtu(struct dst_entry *dst) +{ + return dst->pmtu; +} diff -urN kernel/tcp_splice_conn.c kernel-2.4/tcp_splice_conn.c --- kernel/tcp_splice_conn.c Sun Dec 10 23:57:10 2006 +++ kernel-2.4/tcp_splice_conn.c Sat Jan 6 17:05:48 2007 @@ -33,6 +33,7 @@ #include #include "tcp_splice.h" +#include "compat26.h" /* SLAB cache for tcp splice connections */ @@ -487,9 +488,9 @@ c->splice_iss = tp->snd_nxt; c->splice_irs = tp->rcv_nxt; - c->splice_tsv = tp->rx_opt.rcv_tsval; - c->splice_tse = tp->rx_opt.rcv_tsecr; - c->timestamp_ok = tp->rx_opt.tstamp_ok; + c->splice_tsv = tp->rcv_tsval; + c->splice_tse = tp->rcv_tsecr; + c->timestamp_ok = tp->tstamp_ok; } static void @@ -592,13 +593,13 @@ /* MSS playground */ lock_sock(sock2->sk); - tp2->rx_opt.user_mss = tp1->rx_opt.mss_clamp; + tp2->user_mss = tp1->mss_clamp; release_sock(sock2->sk); TCP_SPLICE_DBG(5, "sock1: user_mss:%u mss_clamp:%u\n", - tp1->rx_opt.user_mss, tp1->rx_opt.mss_clamp); + tp1->user_mss, tp1->mss_clamp); TCP_SPLICE_DBG(5, "sock2: user_mss:%u mss_clamp:%u\n", - tp2->rx_opt.user_mss, tp2->rx_opt.mss_clamp); + tp2->user_mss, tp2->mss_clamp); return 0; } diff -urN kernel/tcp_splice_core.c kernel-2.4/tcp_splice_core.c --- kernel/tcp_splice_core.c Sun Dec 10 23:57:12 2006 +++ kernel-2.4/tcp_splice_core.c Sat Jan 6 14:40:30 2007 @@ -115,7 +115,6 @@ */ static struct nf_hook_ops tcp_splice_in_ops = { .hook = tcp_splice_in, - .owner = THIS_MODULE, .pf = PF_INET, .hooknum = NF_IP_LOCAL_IN, .priority = 100, diff -urN kernel/tcp_splice_ctl.c kernel-2.4/tcp_splice_ctl.c --- kernel/tcp_splice_ctl.c Sun Dec 10 23:57:18 2006 +++ kernel-2.4/tcp_splice_ctl.c Sat Jan 6 16:55:03 2007 @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -34,7 +33,6 @@ #include #include -#include #include #include @@ -43,6 +41,7 @@ #include #include "tcp_splice.h" +#include "compat26.h" /* semaphore for TCP SPLICE sockopts. And, [gs]etsockopt may sleep. */ @@ -201,6 +200,7 @@ static struct ctl_table_header * sysctl_header; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) /* * Module count helpers */ @@ -215,6 +215,7 @@ { module_put(THIS_MODULE); } +#endif /* diff -urN kernel/tcp_splice_xmit.c kernel-2.4/tcp_splice_xmit.c --- kernel/tcp_splice_xmit.c Sat Jan 6 17:15:01 2007 +++ kernel-2.4/tcp_splice_xmit.c Sat Jan 6 17:08:22 2007 @@ -18,6 +18,7 @@ * Copyright (C) 2006 Alexandre Cassen, */ +#include #include #include #include @@ -34,6 +35,7 @@ #include #include "tcp_splice.h" +#include "compat26.h" /* @@ -69,8 +71,11 @@ sk->sk_err = ECONNRESET; +#if 0 + /* FIXME: is there any equivalent in 2.4 ? */ if (!sock_flag(sk, SOCK_DEAD)) sk->sk_error_report(sk); +#endif tcp_done(sk); } @@ -197,16 +202,14 @@ spin_lock(&ctx->dst_lock); if (!(rt = (struct rtable *) __tcp_splice_dst_check(ctx, rtos, 0))) { - struct flowi fl = { + struct rt_key key = { .oif = 0, - .nl_u = { - .ip4_u = { - .daddr = ctx->raddr, - .saddr = 0, - .tos = 0, } }, + .dst = ctx->raddr, + .src = 0, + .tos = 0, }; - if (ip_route_output_key(&rt, &fl)) { + if (ip_route_output_key(&rt, &key)) { spin_unlock(&ctx->dst_lock); TCP_SPLICE_DBG_RL("__tcp_splice_get_out_rt(): error routing " "dest: %u.%u.%u.%u\n", @@ -261,8 +264,11 @@ dst_release(skb->dst); skb->dst = &rt->u.dst; +#if 0 + /* FIXME: is there any equivalent in 2.4 ? */ /* avoid icmp_send in ip_fragment */ skb->local_df = 1; +#endif TCP_SPLICE_XMIT(skb, rt); @@ -358,7 +364,11 @@ /* Add incremental checksum update later? */ /* full checksum check here now */ if (skb_is_nonlinear(skb)) { +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) + if (skb_linearize(skb, GFP_ATOMIC) != 0) +#else if (skb_linearize(skb) != 0) +#endif return NF_DROP; iph = skb->nh.iph; th = (void *)iph + ihl; @@ -366,7 +376,15 @@ switch (skb->ip_summed) { case CHECKSUM_NONE: skb->csum = csum_partial((void *)th, datalen, 0); +#if defined(CHECKSUM_COMPLETE) + /* kernel 2.6.19+ */ case CHECKSUM_COMPLETE: +#elif defined(CHECKSUM_HW) + /* kernel <2.6.19 */ + case CHECKSUM_HW: +#else +#error "Neither CHECKSUM_COMPLETE nor CHECKSUM_HW are defined. Check your kernel headers !" +#endif if (csum_tcpudp_magic(iph->saddr, iph->daddr, datalen, IPPROTO_TCP, skb->csum)) { TCP_SPLICE_DBG_RL("Incoming failed checksum "