pptp-conntrack for 2.6 from Mandrake
Subsystems (2)
PATCH 1/1 pptp-conntrack for 2.6 from Mandrake
Hi all,
The Mandrake development branch 2.6 kernel contains a ported pptp-conntrack. I have extracted the code related to the conntrack and created a patch against linux 2.6.8.1 vanilla.
Everything compiles just fine, but I haven't tested whether it works or not, and I am not a kernel developer so I don't know if this patch is any good.
Credits to Mandrake for porting and Jason Opperisano from the general list for pointing out that it existed.
Sincerly,
Laurens
include/linux/netfilter_ipv4/ip_conntrack_tuple.h +19 -5
@@ -14,7 +14,7 @@union ip_conntrack_manip_proto {/* Add other protocols here. */ -u_int16_t all; +u_int32_t all;struct {u_int16_t port;
@@ -25,6 +25,9 @@struct {u_int16_t id; } icmp; +struct { +u_int32_t key; + } gre; };/* The manipulable part of the tuple. */
@@ -44,7 +47,7 @@u_int32_t ip;union {/* Add other protocols here. */ -u_int16_t all; +u_int64_t all;struct {u_int16_t port;
@@ -55,6 +58,11 @@struct {u_int8_t type, code; } icmp; +struct { +u_int16_t protocol; +u_int8_t version; +u_int32_t key; + } gre; } u;/* The protocol. */
@@ -80,10 +88,16 @@#ifdef __KERNEL__#define DUMP_TUPLE (tp) \ -DEBUGP("tuple %p: %u %u.%u.%u.%u:%hu -> %u.%u.%u.%u:%hu\n", \ +DEBUGP("tuple %p: %u %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u\n", \ (tp), (tp)->dst.protonum, \ - NIPQUAD((tp)->src.ip), ntohs((tp)->src.u.all), \ - NIPQUAD((tp)->dst.ip), ntohs((tp)->dst.u.all)) + NIPQUAD((tp)->src.ip), ntohl((tp)->src.u.all), \ + NIPQUAD((tp)->dst.ip), ntohl((tp)->dst.u.all)) + +#define DUMP_TUPLE_RAW (x) \ + DEBUGP("tuple %p: %u %u.%u.%u.%u:0x%08x -> %u.%u.%u.%u:0x%08x\n",\ + (x), (x)->dst.protonum, \ + NIPQUAD((x)->src.ip), ntohl((x)->src.u.all), \ + NIPQUAD((x)->dst.ip), ntohl((x)->dst.u.all))#define CTINFO2DIR (ctinfo) ((ctinfo) >= IP_CT_IS_REPLY ? IP_CT_DIR_REPLY : IP_CT_DIR_ORIGINAL)
include/linux/netfilter_ipv4/ip_conntrack.h +8 -0
@@ -51,19 +51,23 @@#include <linux/netfilter_ipv4/ip_conntrack_tcp.h> #include <linux/netfilter_ipv4/ip_conntrack_icmp.h> +#include <linux/netfilter_ipv4/ip_conntrack_proto_gre.h> /* per conntrack: protocol private data */ union ip_conntrack_proto {/* insert conntrack proto private data here */ +struct ip_ct_gre gre;struct ip_ct_tcp tcp;struct ip_ct_icmp icmp; };union ip_conntrack_expect_proto {/* insert expect proto private data here */ +struct ip_ct_gre_expect gre; };/* Add protocol helper include file here */ +#include <linux/netfilter_ipv4/ip_conntrack_pptp.h> #include <linux/netfilter_ipv4/ip_conntrack_amanda.h> #include <linux/netfilter_ipv4/ip_conntrack_ftp.h> #include <linux/netfilter_ipv4/ip_conntrack_irc.h>
@@ -71,6 +76,7 @@/* per expectation: application helper private data */ union ip_conntrack_expect_help {/* insert conntrack helper private data (expect) here */ +struct ip_ct_pptp_expect exp_pptp_info;struct ip_ct_amanda_expect exp_amanda_info;struct ip_ct_ftp_expect exp_ftp_info;struct ip_ct_irc_expect exp_irc_info;
@@ -85,16 +92,19 @@/* per conntrack: application helper private data */ union ip_conntrack_help {/* insert conntrack helper private data (master) here */ +struct ip_ct_pptp_master ct_pptp_info;struct ip_ct_ftp_master ct_ftp_info;struct ip_ct_irc_master ct_irc_info; };#ifdef CONFIG_IP_NF_NAT_NEEDED #include <linux/netfilter_ipv4/ip_nat.h> +#include <linux/netfilter_ipv4/ip_nat_pptp.h> /* per conntrack: nat application helper private data */ union ip_conntrack_nat_help {/* insert nat helper private data here */ +struct ip_nat_pptp nat_pptp_info; };#endif
net/ipv4/netfilter/ip_nat_core.c +3 -3
@@ -438,7 +438,7 @@ *tuple = *orig_tuple;while ((rptr =find_best_ips_proto_fast (tuple, mr, conntrack, hooknum)) !=NULL ) { -DEBUGP ("Found best for " );DUMP_TUPLE (tuple); +DEBUGP ("Found best for " );DUMP_TUPLE_RAW (tuple);/* 3) The per-protocol part of the manip is made to map into the range to make a unique tuple. */
@@ -580,9 +580,9 @@HOOK2MANIP (hooknum)==IP_NAT_MANIP_SRC ?"SRC" :"DST" , conntrack);DEBUGP ("Original: " ); -DUMP_TUPLE (&orig_tp); +DUMP_TUPLE_RAW (&orig_tp);DEBUGP ("New: " ); -DUMP_TUPLE (&new_tuple); +DUMP_TUPLE_RAW (&new_tuple);#endif /* We now have two tuples (SRCIP/SRCPT/DSTIP/DSTPT):
net/ipv4/netfilter/ip_conntrack_core.c +9 -7
@@ -143,6 +143,7 @@ tuple->src.ip = iph->saddr; tuple->dst.ip = iph->daddr; tuple->dst.protonum = iph->protocol; + tuple->src.u.all = tuple->dst.u.all =0 ;return protocol->pkt_to_tuple (skb, dataoff, tuple); }
@@ -156,6 +157,8 @@ inverse->dst.ip = orig->src.ip; inverse->dst.protonum = orig->dst.protonum; + inverse->src.u.all = inverse->dst.u.all =0 ; +return protocol->invert_tuple (inverse, orig); }
@@ -974,8 +980,8 @@* so there is no need to use the tuple lock too */ DEBUGP ("ip_conntrack_expect_related %p\n" , related_to); -DEBUGP ("tuple: " );DUMP_TUPLE (&expect->tuple); -DEBUGP ("mask: " );DUMP_TUPLE (&expect->mask); +DEBUGP ("tuple: " );DUMP_TUPLE_RAW (&expect->tuple); +DEBUGP ("mask: " );DUMP_TUPLE_RAW (&expect->mask); old = LIST_FIND(&ip_conntrack_expect_list, resent_expect, struct ip_conntrack_expect *, &expect->tuple,
@@ -1068,15 +1074,14 @@MUST_BE_READ_LOCKED (&ip_conntrack_lock);WRITE_LOCK (&ip_conntrack_expect_tuple_lock); -DEBUGP ("change_expect:\n" ); -DEBUGP ("exp tuple: " );DUMP_TUPLE (&expect->tuple); -DEBUGP ("exp mask: " );DUMP_TUPLE (&expect->mask); -DEBUGP ("newtuple: " );DUMP_TUPLE (newtuple); +DEBUGP ("exp tuple: " );DUMP_TUPLE_RAW (&expect->tuple); +DEBUGP ("exp mask: " );DUMP_TUPLE_RAW (&expect->mask); +DEBUGP ("newtuple: " );DUMP_TUPLE_RAW (newtuple);if (expect->ct_tuple.dst.protonum ==0 ) {/* Never seen before */ DEBUGP ("change expect: never seen before\n" ); -if (!ip_ct_tuple_equal (&expect->tuple, newtuple) +if (!ip_ct_tuple_mask_cmp (&expect->tuple, newtuple, &expect->mask) &&LIST_FIND (&ip_conntrack_expect_list, expect_clash, struct ip_conntrack_expect *, newtuple, &expect->mask)) {/* Force NAT to find an unused tuple */
net/ipv4/netfilter/ip_conntrack_pptp.c +637 -0
637 lines not on this page · raw message
net/ipv4/netfilter/ip_conntrack_pptp_priv.h +24 -0
@@ -0,0 +1,24 @@ +#ifndef _IP_CT_PPTP_PRIV_H +#define _IP_CT_PPTP_PRIV_H + +/* PptpControlMessageType names */ +static const char *strMName[] = { +"UNKNOWN_MESSAGE" , +"START_SESSION_REQUEST" , +"START_SESSION_REPLY" , +"STOP_SESSION_REQUEST" , +"STOP_SESSION_REPLY" , +"ECHO_REQUEST" , +"ECHO_REPLY" , +"OUT_CALL_REQUEST" , +"OUT_CALL_REPLY" , +"IN_CALL_REQUEST" , +"IN_CALL_REPLY" , +"IN_CALL_CONNECT" , +"CALL_CLEAR_REQUEST" , +"CALL_DISCONNECT_NOTIFY" , +"WAN_ERROR_NOTIFY" , +"SET_LINK_INFO" +}; + +#endif
net/ipv4/netfilter/ip_conntrack_proto_gre.c +354 -0
354 lines not on this page · raw message
net/ipv4/netfilter/ip_nat_pptp.c +475 -0
475 lines not on this page · raw message
net/ipv4/netfilter/ip_nat_proto_gre.c +225 -0
225 lines not on this page · raw message
net/ipv4/netfilter/Kconfig +8 -0
@@ -628,5 +632,13 @@ If you want to compile it as a module, say M here and read Documentation/modules.txt. If unsure, say `N'. +config IP_NF_CT_PROTO_GRE + tristate ' GRE protocol support' + depends on IP_NF_CONNTRACK +config IP_NF_PPTP + tristate 'PPTP protocol support' + depends on IP_NF_CT_PROTO_GRE + help + endmenu
net/ipv4/netfilter/Makefile +8 -0
@@ -19,13 +19,21 @@ # connection tracking obj-$(CONFIG_IP_NF_CONNTRACK) += ip_conntrack.o +# connection tracking protocol helpers +obj-$(CONFIG_IP_NF_CT_PROTO_GRE) += ip_conntrack_proto_gre.o + +# NAT protocol helpers +obj-$(CONFIG_IP_NF_NAT_PROTO_GRE) += ip_nat_proto_gre.o + # connection tracking helpers +obj-$(CONFIG_IP_NF_PPTP) += ip_conntrack_pptp.o obj-$(CONFIG_IP_NF_AMANDA) += ip_conntrack_amanda.o obj-$(CONFIG_IP_NF_TFTP) += ip_conntrack_tftp.o obj-$(CONFIG_IP_NF_FTP) += ip_conntrack_ftp.o obj-$(CONFIG_IP_NF_IRC) += ip_conntrack_irc.o # NAT helpers +obj-$(CONFIG_IP_NF_NAT_PPTP) += ip_nat_pptp.o obj-$(CONFIG_IP_NF_NAT_AMANDA) += ip_nat_amanda.o obj-$(CONFIG_IP_NF_NAT_TFTP) += ip_nat_tftp.o obj-$(CONFIG_IP_NF_NAT_FTP) += ip_nat_ftp.o
include/linux/netfilter_ipv4/ip_conntrack_pptp.h +313 -0
313 lines not on this page · raw message
include/linux/netfilter_ipv4/ip_conntrack_proto_gre.h +123 -0
123 lines not on this page · raw message
include/linux/netfilter_ipv4/ip_nat_pptp.h +11 -0
@@ -0,0 +1,11 @@ +/* PPTP constants and structs */ +#ifndef _NAT_PPTP_H +#define _NAT_PPTP_H + +/* conntrack private data */ +struct ip_nat_pptp { +u_int16_t pns_call_id;/* NAT'ed PNS call id */ +u_int16_t pac_call_id;/* NAT'ed PAC call id */ +}; + +#endif /* _NAT_PPTP_H */
Quoted 3 lines · Laurens Blankers
Everything compiles just fine, but I haven't tested whether it works or not, and I am not a kernel developer so I don't know if this patch is any good.
First of all, thanks for passing on this patch. I somehow missed your original posting but was recently pointed at it.
Unfortunately that 'port' is way from being complete. Thoughout the ip_conntrack_pptp and ip_nat_pptp code there are assumptions about linearized skbs :(
Interestingly, the ip_conntrack_proto_gre/ip_nat_proto_gre part is fixed accordingly, so maybe this was done by two different developers?
I'm in the process of re-working that whole port, but due to it's extensive nature I'm almost sure I'll introduce new bug(s), and thus it will need extensive testing before going into 2.6.x mainline.
Quoted 2 lines
Sincerly,
Laurens
Signature · 5 lines
- Harald Welte <[email protected]> http://www.netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie